pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
sequences
7+ messages / 6 participants
[nested] [flat]

* sequences
@ 1999-04-29 18:05 Patrick Welche <prlw1@newn.cam.ac.uk>
  0 siblings, 0 replies; 7+ messages in thread

From: Patrick Welche @ 1999-04-29 18:05 UTC (permalink / raw)
  To: pgsql-interfaces

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* RE: [INTERFACES] sequences
@ 1999-04-29 19:41 Jackson, DeJuan <djackson@cpsgroup.com>
  1999-05-03 11:57 ` RE: [INTERFACES] sequences Herouth Maoz <herouth@oumail.openu.ac.il>
  0 siblings, 1 reply; 7+ messages in thread

From: Jackson, DeJuan @ 1999-04-29 19:41 UTC (permalink / raw)
  To: prlw1@cam.ac.uk; pgsql-interfaces

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* RE: [INTERFACES] sequences
  1999-04-29 19:41 RE: [INTERFACES] sequences Jackson, DeJuan <djackson@cpsgroup.com>
@ 1999-05-03 11:57 ` Herouth Maoz <herouth@oumail.openu.ac.il>
  1999-05-04 16:11   ` Re: [INTERFACES] sequences Patrick Welche <prlw1@newn.cam.ac.uk>
  0 siblings, 1 reply; 7+ messages in thread

From: Herouth Maoz @ 1999-05-03 11:57 UTC (permalink / raw)
  To: Jackson, DeJuan <djackson@cpsgroup.com>; prlw1@cam.ac.uk; pgsql-interfaces

At 22:41 +0300 on 29/04/1999, Jackson, DeJuan wrote:


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

That shouldn't make a difference. Currval's scope is the entire session,
from the last call (or implicit call) to nextval to the next call.

Now, let's see if I understand right: The query works well in psql, but not
in a program? So let me ask you this - do you run the program, perhaps, as
a different user, such as the httpd or nobody user? If so, you need to
GRANT SELECT on the sequence to be able to use the currval function.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [INTERFACES] sequences
  1999-04-29 19:41 RE: [INTERFACES] sequences Jackson, DeJuan <djackson@cpsgroup.com>
  1999-05-03 11:57 ` RE: [INTERFACES] sequences Herouth Maoz <herouth@oumail.openu.ac.il>
@ 1999-05-04 16:11   ` Patrick Welche <prlw1@newn.cam.ac.uk>
  0 siblings, 0 replies; 7+ messages in thread

From: Patrick Welche @ 1999-05-04 16:11 UTC (permalink / raw)
  To: herouth@oumail.openu.ac.il; +Cc: pgsql-interfaces

Herouth Maoz wrote:
> 
> At 22:41 +0300 on 29/04/1999, Jackson, DeJuan wrote:
> 
> 
> > You might try placing the INSERT and SELECT CURRVAL into a transaction
> > block.
> 
> That shouldn't make a difference. Currval's scope is the entire session,
> from the last call (or implicit call) to nextval to the next call.
> 
> Now, let's see if I understand right: The query works well in psql, but not
> in a program? So let me ask you this - do you run the program, perhaps, as
> a different user, such as the httpd or nobody user? If so, you need to
> GRANT SELECT on the sequence to be able to use the currval function.

Thank you!! That was it. (I had granted access to tables, not to sequences)

Cheers,

Patrick



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* sequences
@ 1999-11-02 11:01 StOo <stuart@comodo.net>
  1999-11-04 15:53 ` Re: [INTERFACES] sequences Thomas Lockhart <lockhart@alumni.caltech.edu>
  0 siblings, 1 reply; 7+ messages in thread

From: StOo @ 1999-11-02 11:01 UTC (permalink / raw)
  To: pgsql-interfaces

Hi, 
 The size of a sequence is 32bit , correct? (im pretty damn sure it is). Is
there any way I can tune this to 64bit, There is an int8 option in postgres as
I use that already.Threre is a skanky way of creating an incremenetd counter 
whilst using an int8 but I would rather up the sequence in the code. Anyone got
any ideas where to look? 
 I am aware that the int8 is signed but that doest matter currently.


+-=-=-=-=-=-=-=StOo=-=-=-=-=-=-=-+

Stuart Hodgkinson Stuart@comodo.net






^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [INTERFACES] sequences
  1999-11-02 11:01 sequences StOo <stuart@comodo.net>
@ 1999-11-04 15:53 ` Thomas Lockhart <lockhart@alumni.caltech.edu>
  0 siblings, 0 replies; 7+ messages in thread

From: Thomas Lockhart @ 1999-11-04 15:53 UTC (permalink / raw)
  To: stuart@comodo.net; +Cc: pgsql-interfaces

>  The size of a sequence is 32bit , correct? (im pretty damn sure it is). Is
> there any way I can tune this to 64bit, There is an int8 option in postgres as
> I use that already.Threre is a skanky way of creating an incremenetd counter
> whilst using an int8 but I would rather up the sequence in the code. Anyone got
> any ideas where to look?

Look in src/backend/parser/gram.y and analyze.c for where sequences
(the serial type) is handled. The code actually just embeds the
"skanky" technique to hide it from the user. A very first cut might be
to make this configurable by defining, say, SERIAL_IS_INT64. Patches
accepted ;)

                    - Thomas

-- 
Thomas Lockhart				lockhart@alumni.caltech.edu
South Pasadena, California



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* sequences
@ 1999-11-03 15:32 stuart <stuart@comodo.net>
  0 siblings, 0 replies; 7+ messages in thread

From: stuart @ 1999-11-03 15:32 UTC (permalink / raw)
  To: pgsql-interfaces

Hi,
 The size of a sequence is 32bit , correct? (im pretty damn sure it is). Is
 there any way I can tune this to 64bit, There is an int8 option in postgres
as
 I use that already.Threre is a skanky way of creating an incremenetd
counter
 whilst using an int8 but I would rather up the sequence in the code. Anyone
got
 any ideas where to look?
 I am aware that the int8 is signed but that doest matter currently

 Stuart Hodgkinson Stuart@comodo.net




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~1999-11-04 15:53 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-04-29 18:05 sequences Patrick Welche <prlw1@newn.cam.ac.uk>
1999-04-29 19:41 RE: [INTERFACES] sequences Jackson, DeJuan <djackson@cpsgroup.com>
1999-05-03 11:57 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1999-05-04 16:11   ` Patrick Welche <prlw1@newn.cam.ac.uk>
1999-11-02 11:01 sequences StOo <stuart@comodo.net>
1999-11-04 15:53 ` Thomas Lockhart <lockhart@alumni.caltech.edu>
1999-11-03 15:32 sequences stuart <stuart@comodo.net>

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