Re: PostgreSql query help....
| From: | GB Clark II | Date: | Wed, 21 Nov 2001 20:30:28 +0000 |
| Subject: | Re: PostgreSql query help.... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14516@lists.php.net to get a copy of this message | ||
On Monday 19 November 2001 20:27, Vincent Ma wrote:
> Hi everybody:
>
> I would like to ask why the error occur when retrieve current sequence
> number. Eg. "select currval('student_id_seq')" is not working, and warning
> prompt "student_id_seq.currval is not yet defined in this session".
>
> However, this is work for the "select nextval()";
>
> do anyone know how to get current sequence number, in php. Thank for your
> help
>
> Vincent Ma
Hi,
The problem here is that it looks like you have NOT inserted a record into
the DB yet, therefore, you don't have a current value to get.
currval gets the last inserted id number for this connection. nextval will
get the value that will be used next.
If you are trying to get a id number for insertion (i.e. not using the
automatic insert) that nextval is the one you should use.
NOTE: If you are using transactions and do a rollback, you will have holes
in your sequences.
Hope this helps.
GB
--
GB Clark II | Roaming FreeBSD Admin
gclarkii@VSServices.COM | General Geek
CTHULU for President - Why choose the lesser of two evils?