pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Theofilu <theofilu@eunet.at>
To: Michael Meskes <meskes@postgresql.org>
Cc: theofilu@eunet.at
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] ecpg and getting just assigned serial number
Date: Mon, 13 Sep 1999 14:11:24 +0200
Message-ID: <99091314342400.01664@theofilu> (raw)
References: <19990913102726.B3200@gmx.net>

Am Mo, 13 Sep 1999 schrieben Sie:
> On Sun, Sep 12, 1999 at 04:25:17PM +0200, Theofilu Andreas wrote:
> > I'm using 'ecpg' to develop my application, because it's mostly compatible
> > to Informix's 'esqlc'. However. I have a table with a field of type
> > 'serial'. Now I've no problem to insert any sentences into this table, but
> > immediately after inserting a new sentence I need the newly assigned number
> > to the serial field in the table. How can I access this number?
> > With Informix I got this number in a field of structure 'sqlca'. With
> > PostgreSQL the same field in this structure exists but contains always 0,
> > as documented.
> 
> Where exactly does Informix return it? sqlca[?].

Informix returns this number in 'sqlca.sqlerrd[1]'. Currently this field
is not used by ecpg.
  
> Also does anyone know whether the backend returns that number somewhere?

Now I know that the backend does not return this number anywhere. Instead
you need two SQL commands to insert a sentence and get the number. You can
do it with following commands:

   EXEC SQL nextval ('<sequence name>') into :variable;
   EXEC SQL insert into <table> values (:variable, ...);

Maybe ecpg can implement the first call behind the scenes and put the new
serial number into 'sqlca.sqlerrd[1]'.
In Informix I have to write:

   EXEC SQL insert into <table> values (0, ...);

The '0' increments the serial counter, who is a simple int4 field in a
system table, by one, inserts the sentence with new serial number into the
table and returns the new number in 'sqlca.sqlerrd[1]'.
It would be nice to have this feature exactly the same way with 'ecpg'.
This would make it more compatible, at least against Informix. Don't know
about Oracle.

BTW: When I insert a sentence in Informix and the serial field is not 0,
but contains a unique number and this number is higher than the current
value of the serial counter, the serial counter is set to the manualy set
number. This is important if one inserts sentences from a file. For
example when I move data between two machines/databases. With PostgreSQL
I've to set the counter into the sequence by hand, or it will not be
incremented.
--
Theofilu Andreas
http://members.eunet.at/theofilu

               -------------------------------------------------
                           Enjoy the science of Linux!
                       Genieße die Wissenschaft von Linux!
               -------------------------------------------------



view thread (13+ messages)  latest in thread

Message-ID: <99091314342400.01664@theofilu>
Permalink:  ../99091314342400.01664@theofilu/
Also on:    postgresql.org/message-id/99091314342400.01664@theofilu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: theofilu@eunet.at, meskes@postgresql.org
  Subject: Re: [INTERFACES] ecpg and getting just assigned serial number
  In-Reply-To: <99091314342400.01664@theofilu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox