X-Original-To: pgsql-odbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B77CD3A2B25 for ; Sun, 14 Nov 2004 14:24:51 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77020-07 for ; Sun, 14 Nov 2004 14:24:40 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id C78B73A4E0B for ; Sun, 14 Nov 2004 14:24:43 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id iAEEOdg5080794 for ; Sun, 14 Nov 2004 14:24:39 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id iAEEM7eB080221 for pgsql-odbc@postgresql.org; Sun, 14 Nov 2004 14:22:07 GMT From: "Sim Zacks" X-Newsgroups: comp.databases.postgresql.interfaces.odbc Subject: Re: Problem with curval Date: Sun, 14 Nov 2004 16:20:42 +0200 Organization: Hub.Org Networking Services Lines: 85 Message-ID: References: <419386D5.9060502@enter.net> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 To: pgsql-odbc@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.2 tagged_above=0.0 required=5.0 tests=DNS_FROM_RFCI_DSN, PRIORITY_NO_NAME X-Spam-Level: ** X-Archive-Number: 200411/89 X-Sequence-Number: 4703 I am using something similar to the following code in Access to get the currval: conn.Execute ("Insert into Shipments(...) values(...)") rs.Open "select currval('shipments_shipmentid_seq') as shipmentid;", conn, adOpenForwardOnly, adLockReadOnly where rs is my ADODB.RecordSet and conn is an ADODB.Connection In your case it looks like you're trying to build a function to mimic the MySQL last_insert_id function. You should not be using a loop. You only want one value. your code should look like: create or replace function last_insert_id(varchar,varchar ) returns integer as ' declare intable alias for $1; incolumn alias for $2; myvalue integer; begin select currval('''' '' || intable || ''_'' || incolumn || ''_seq'''') into myvalue; return myvalue; end ' language plpgsql; Your SQL code to retrieve it wsould be simply "select last_insert_id(var1,var2)" "Mike Fahey" wrote in message news:419386D5.9060502@enter.net... > This wont work because myvalue must be a record or row variable. > > I'm guessing its nearly impossible to get the last inserted id from > access 2003 using > postgres odbc. > > select @@IDENTITY always returns "2". > > Thoughts? > > > > > create function last_insert_id(varchar,varchar ) returns integer > as ' > declare > intable alias for $1; > incolumn alias for $2; > myvalue integer; > > BEGIN > > for myvalue in execute '' select currval('''' '' > || intable || ''_'' || incolumn > || ''_seq'''') > '' Loop > return myvalue; > > > END loop; > END; > > ' > language plpgsql; > > > > -- > With best regards, > > Mike Fahey - Systems Administration > ******************************************************************** > ENTER.NET - "The Road to the Internet Starts Here!" (tm) > (610) 437-2221 * http://www.enter.net/ * email:support@enter.net > ******************************************************************** > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >