Thread: Obtain Serial Value

Obtain Serial Value

From
"Sistemas C.M.P."
Date:
I am using VB6+ADO+ODBC with pgSQL.
I need to obtain the value of a serial field (autogenerated) inmediatly after I do a INSERT query.  How can I do?

Re: Obtain Serial Value

From
Timothy Reed
Date:
You should try SELECT MAX( <fieldname> ) FROM <tablename>; ??

On 2/8/06, Sistemas C.M.P. <sistemascmp@redynet4.com.ar > wrote:
I am using VB6+ADO+ODBC with pgSQL.
I need to obtain the value of a serial field (autogenerated) inmediatly after I do a INSERT query.  How can I do?



--
--------
Timothy Reed

tareed@gmail.com

Re: Obtain Serial Value

From
"Trewern, Ben"
Date:
Try using SELECT currval('sequenc_name');
 
From the docs:
 
Return the value most recently obtained by nextval for this sequence in the current session. (An error is reported if nextval has never been called for this sequence in this session.) Notice that because this is returning a session-local value, it gives a predictable answer whether or not other sessions have executed nextval since the current session did.
 
This should be much faster than SELECT max(... and transaction safe.
 
Regards,

Ben

-----Original Message-----
From: pgsql-odbc-owner@postgresql.org [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Timothy Reed
Sent: 08 February 2006 14:32
To: Sistemas C.M.P.
Cc: pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Obtain Serial Value

You should try SELECT MAX( <fieldname> ) FROM <tablename>; ??

On 2/8/06, Sistemas C.M.P. <sistemascmp@redynet4.com.ar > wrote:
I am using VB6+ADO+ODBC with pgSQL.
I need to obtain the value of a serial field (autogenerated) inmediatly after I do a INSERT query.  How can I do?



--
--------
Timothy Reed

tareed@gmail.com

-------------------------------------------------------------------

This email and any attachments transmitted with it are confidential (and potentially legally privileged) and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender and do not store, copy or disclose the content to any other person.

It is the responsibility of the recipient to ensure that opening this message and/or any of its attachments will not adversely affect its systems. No responsibility is accepted by the sender.

-------------------------------------------------------------------

 

 

Antw: Obtain Serial Value

From
"Thomas Holschen"
Date:
.. or use a "stored procedure" aka function...


CREATE OR REPLACE FUNCTION hela_add_programm(pm_programmname
"varchar")
  RETURNS int4 AS
$BODY$    declare NewProgrammID integer;
Begin
select into NewProgrammID nextval('programm_idprogramm_seq');
Insert Into programm(idprogramm,programmname) values
(NewProgrammID,pm_Programmname);
Return NewProgrammID;
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;
--

_____________________________________________
Hela Gewürzwerk Hermann Laue GmbH & Co.KG
EDV
Thomas Holschen
Beimoorweg 11
22926 Ahrensburg

Tel. : +49 4102/496-381
http://www.hela-food.de
_____________________________________________

>>> "Sistemas C.M.P." <sistemascmp@redynet4.com.ar> schrieb am
Mittwoch, 8. Februar
2006 um 15:03 in Nachricht
<005601c62cb8$606b57d0$1601a8c0@pcsistemas>:
> I am using VB6+ADO+ODBC with pgSQL.
> I need to obtain the value of a serial field (autogenerated)
inmediatly
> after I do a INSERT query.  How can I do?
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn
Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben,
informieren Sie bitte den Absender und löschen Sie diese E-Mail. Das unerlaubte
Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet. Aus
Rechts- und Sicherheitsgründen ist die in dieser E-Mail gegebene Information nicht
rechtsverbindlich.

This e-mail contains confidential and/or privileged information. If you are not the
intended addressee or have received this e-mail in error please notify the sender and
delete this e-mail. Any unauthorized copying, disclosure or distribution of the material
in this e-mail is strictly forbidden. Due to legal and security reasons the information
contained in this e-mail is not legally binding.