Re: A couple of newbie questions ...
От | Shane Ambler |
---|---|
Тема | Re: A couple of newbie questions ... |
Дата | |
Msg-id | 488754AD.2000204@Sheeky.Biz обсуждение исходный текст |
Ответ на | Re: A couple of newbie questions ... (Raymond O'Donnell <rod@iol.ie>) |
Ответы |
Re: A couple of newbie questions ...
|
Список | pgsql-general |
Raymond O'Donnell wrote: >> 1. Is a SEQUENCE what I use instead of auto_increment? > > Yes. The easiest thing is to define the column as type SERIAL - this > will create the sequence for you and associate it with the column. > Alternatively, you can create the sequence by hand, create the column > as an integer type, and then set the default for the column as > nextval('<sequence name>'). Have a look in the docs for the gory > details: > > http://www.postgresql.org/docs/8.3/static/datatype-numeric.html#DATATYPE-SERIAL > Of sorts - the correct definition would be the sequence is where the auto_increment equivalent gets the next value. A straight conversion would be replace auto_increment with DEFAULT nextval('this_table_seq') after creating the sequence definition but these steps are automated by using a data type of serial. >> 3. Does this work in PostgreSQL: >> >> INSERT INTO table VALUES ('','y','z') >> >> where the empty first item is intended for an >> auto_increment/SEQUENCE id field? > > No - this will try to stuff a string value (here, an empty string) > into an integer column, which will cause an error. > > INSERT INTO table (fld_y, fld_z) VALUES ('y', 'z'); Another way is INSERT INTO table VALUES (NULL,'y','z') -- Shane Ambler pgSQL (at) Sheeky (dot) Biz Get Sheeky @ http://Sheeky.Biz -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
В списке pgsql-general по дате отправления: