Re: Last ID Problem

Поиск
Список
Период
Сортировка
От
Тема Re: Last ID Problem
Дата
Msg-id 20050209162208.73301.qmail@web52404.mail.yahoo.com
обсуждение исходный текст
Ответ на Re: Last ID Problem  (<operationsengineer1@yahoo.com>)
Ответы Re: Last ID Problem  (<operationsengineer1@yahoo.com>)
Список pgsql-novice
> mitch and all, i've developed a simple little script
> in order to test the "last id" methodology mitch
> suggested.
>
> it looks like this...  php and adodb include
> excluded
> for brevity...
>
> -----
> $db = &ADONewConnection('postgres7');
> $db ->
> Connect($db_string,$db_owner,$db_pw,$db_name);
> $insert_id = $db->getone("select
> nextval('public.customer_cust_id_seq')");
>
> print 'The ID is ' . $insert_id;
> -----
>
> my sequence name is 'public.customer_cust_id_seq'
> (found this in pgadmin3).
>
> the last id number in my table is 65.  when i use
> nextval(), i get a result of 66 for $insert_id -
> which
> is the value that i would want to then perform and
> insert.
>
> however, when i use currval(), as recommended, i get
> no result.  i probably get an error, but i haven't
> checked for that yet.
>
> is it OK to use nextval() to get the next id value
> in
> the sequence before doing an insert?  how come
> currval() doesn't work.
>
> thanks to all for any guidance here.

mitch and all, i noticed that if i keep refreshing my
page that the $insert_id keeps growing...  66 then 67
then 68 then 69.

i guess this makes sense, after all, the "next value"
is always and icnrement higher.  this makes me a
little nervous, though.

i only want one value...  the next id i should use to
perform an insert.

i'm hoping currval() does the trick, however, i'm
getting no result.

do i need to instruct the sequence to go to it last
value before calling currval()?

tia...



__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail

В списке pgsql-novice по дате отправления:

Предыдущее
От:
Дата:
Сообщение: Re: Last ID Problem
Следующее
От:
Дата:
Сообщение: Re: Last ID Problem