Re: Question about serial vs. int datatypes
От | nolan@celery.tssi.com |
---|---|
Тема | Re: Question about serial vs. int datatypes |
Дата | |
Msg-id | 20030608051110.16485.qmail@celery.tssi.com обсуждение исходный текст |
Ответ на | Question about serial vs. int datatypes (Lynna Landstreet <lynna@gallery44.org>) |
Список | pgsql-general |
> But... when converting an existing database that already has several hundred > records in it, I can't make that field serial in PostgreSQL, can I? I guess you haven't actually tried this yet, but if you do an insert with an explicit value for a column of type serial, it inserts that value. If you leave that column off the list of columns in the insert statement, it uses the nextval of the implicit sequence, which is the default value of the column. If you use NULL, you will get an error. You can also explicitly select the sequence value. Here's a sample table, test1. Note the two modifiers for 'keyval'. Column | Type | Modifiers ---------+------------------+---------------------------------------------- keyval | integer | not null default nextval('public.test1_keyval_seq'::text) dataval | character varying(30) INSERT into test1 values ('15','TEST'); INSERT into test1 (dataval) values ('FISH'); INSERT into test1 values (null,'MOUSE'); INSERT into test1 values (nextval('test1_keyval_seq'),'CAT'); select * from test1; keyval | dataval --------+--------- 15 | TEST 1 | FISH 2 | CAT (3 rows) -- Mike Nolan
В списке pgsql-general по дате отправления: