Search Postgresql Archives

Re: A couple of newbie questions ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux