From: | Shane Ambler <pgsql(at)Sheeky(dot)Biz> |
---|---|
To: | rod(at)iol(dot)ie |
Cc: | admin <mick(at)mjhall(dot)org>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: A couple of newbie questions ... |
Date: | 2008-07-23 15:56:29 |
Message-ID: | 488754AD.2000204@Sheeky.Biz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Shane Ambler | 2008-07-23 16:00:12 | Re: A couple of newbie questions ... |
Previous Message | Francisco Reyes | 2008-07-23 15:48:25 | Any way to favor index scans, but not bitmap index scans? |