pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jackson, DeJuan <djackson@cpsgroup.com>
To: prlw1@cam.ac.uk
To: pgsql-interfaces@postgreSQL.org
Subject: RE: [INTERFACES] sequences
Date: Thu, 29 Apr 1999 14:41:27 -0500
Message-ID: <D05EF808F2DFD211AE4A00105AA1B5D2100474@cpsmail> (raw)

You might try placing the INSERT and SELECT CURRVAL into a transaction
block.
	-DEJ

> -----Original Message-----
> From:	Patrick Welche [SMTP:prlw1@newn.cam.ac.uk]
> Sent:	Thursday, April 29, 1999 1:05 PM
> To:	pgsql-interfaces@postgreSQL.org
> Subject:	[INTERFACES] sequences
> 
> After the interesting discussion on what is the safest way to have a
> unique
> "oid"-like value per row, I thought I would have a go, but from libpq++ I
> don't seem to be able to read the new sequence value:
> 
> Table    = person
> +----------------------------------+----------------------------------+---
> ----+
> |              Field               |              Type                |
> Length|
> +----------------------------------+----------------------------------+---
> ----+
> | id                               | int4 not null default nextval('p |
> 4 |
> | surname                          | text not null                    |
> var |
> | firstname                        | text not null                    |
> var |
> | email                            | text                             |
> var |
> | phone                            | text                             |
> var |
> | rfbdate                          | date                             |
> 4 |
> +----------------------------------+----------------------------------+---
> ----+
> Index:    person_id_key
> 
> The output from my test program is:
> 
> INSERT INTO person (surname,firstname,email,phone) VALUES
> ('Welche','Patrick','
> prlw1',null)
> SELECT currval('person_id_seq')
>    
>    Missing person id
> 
> and the relevant bit of code is:
> 
>         query<<"INSERT INTO person (surname,firstname,email,phone) VALUES
> ('"
>              <<a._surname<<"','"<<a._firstname<<"',"
>              <<ISNULL(a._email)<<','
>              <<ISNULL(a._phone)<<')'<<ends;         
>         s.send_query(query);   
>         query<<"SELECT currval('person_id_seq')"<<ends;
>         s.send_query(query);
>         if(s.Tuples()!=1)throw empty_result("Missing person id");
>         a.id(toid(s.GetValue(0,"currval")));
> 
> send_query prints the query and does a Exec(query). I suppose I don't
> understand the difference between doing things interactively in psql (the
> above INSERT and SELECT work then) and calling things from a program. Any
> tips?
> 
> Cheers,
> 
> Patrick



view thread (7+ messages)  latest in thread

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

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-interfaces@postgresql.org
  Cc: djackson@cpsgroup.com, prlw1@cam.ac.uk
  Subject: Re: [INTERFACES] sequences
  In-Reply-To: <D05EF808F2DFD211AE4A00105AA1B5D2100474@cpsmail>
  References: <D05EF808F2DFD211AE4A00105AA1B5D2100474@cpsmail>

* 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