RE: [PHP-DB] Postgres auto increment.
| From: | Graeme Merrall | Date: | Sat, 14 Apr 2001 05:39:28 +0000 |
| Subject: | RE: [PHP-DB] Postgres auto increment. | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-8556@lists.php.net to get a copy of this message | ||
> I've been using mysql too much lately.
>
> Can anyone tell me how to set up an auto increment in postgres? I need
> to select a row based on a user's menu selection. Requiring them to type
> in a text entry and get it right would obviously be pretty inefficient.
Either user a data type of 'serial' which will do all the thinking for you,
or create your own sequence and use that.
Serial does all the sequence creation for you and sets your primary key
field to have a default value of seq_name.nextval
Or when you insert use seq_name.nextval as the value of your primary key
field.
That should do it, my postgres is a bit rusty tho.
Cheers,
Graeme