Re: [GENERAL] Last value inserted

2004-11-16 Thread Tom Lane
Jeff Eckermann <[EMAIL PROTECTED]> writes: > --- Jerry III <[EMAIL PROTECTED]> wrote: >> Which means that sometimes they do not return the >> correct value - if you >> have a trigger that inserts another record you will >> not get the right value. > If you are new to PostgreSQL, as you say, then

Re: [GENERAL] Last value inserted

2004-11-16 Thread Stephan Szabo
On Tue, 16 Nov 2004, Jeff Eckermann wrote: > --- Jerry III <[EMAIL PROTECTED]> wrote: > > > Which means that sometimes they do not return the > > correct value - if you > > have a trigger that inserts another record you will > > not get the right value. > > If you are new to PostgreSQL, as you sa

Re: [GENERAL] Last value inserted

2004-11-16 Thread Jeff Eckermann
--- Jerry III <[EMAIL PROTECTED]> wrote: > Which means that sometimes they do not return the > correct value - if you > have a trigger that inserts another record you will > not get the right value. If you are new to PostgreSQL, as you say, then why are you so sure of this? Perhaps you may pro

Re: [GENERAL] Last value inserted

2004-11-15 Thread Jerry III
Which means that sometimes they do not return the correct value - if you have a trigger that inserts another record you will not get the right value. MSSQL has @@IDENTITY and SCOPE_IDENTITY() to handle this case, I'm new to pgsql so I don't know if it has anything like that. Jerry "Richard Hux

Re: [GENERAL] Last value inserted

2004-11-11 Thread Uwe C. Schroeder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thursday 11 November 2004 10:23 am, Franco Bruno Borghesi wrote: > I think the best way would be not to use a SERIAL field, but an INTEGER > field and a sequence: a "serial" is just a convenient shortcut to an int with an automatically created seq

Re: [GENERAL] Last value inserted

2004-11-11 Thread Richard Huxton
MaRCeLO PeReiRA wrote: How can I now (for sure) with value was generated by the sequence to fill the field ID? (There is lots of users using the software at the same time, so I am not able to use the last_value() function on the sequence.) Yes you are nextval()/currval() are multi-user safe. They r

Re: [GENERAL] Last value inserted

2004-11-11 Thread Bruno Wolff III
On Thu, Nov 11, 2004 at 09:59:16 -0300, MaRCeLO PeReiRA <[EMAIL PROTECTED]> wrote: > > Well, once I do an INSERT in the parent table, how can > I know (for sure) which number id was generated by the > sequence? Use currval. ---(end of broadcast)-

Re: [GENERAL] Last value inserted

2004-11-11 Thread Uwe C. Schroeder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 option 1) use a stored procedure to create the record. Within a transaction the last value function will return the correct last value, not the one of a concurrent insert. option 2) if you know that this user uses the same connection for all his qu

Re: [GENERAL] Last value inserted

2004-11-11 Thread Robby Russell
On Thu, 2004-11-11 at 09:59 -0300, MaRCeLO PeReiRA wrote: > Hi guys, > > I am in troubles with a SERIAL field. > > I have five tables. A parent table and four child > tables. When I do the INSERT in the parent table, I > have an ID (generated) by the sequence (SERIAL field), > and I have to use t

Re: [GENERAL] Last value inserted

2004-11-11 Thread Franco Bruno Borghesi
I think the best way would be not to use a SERIAL field, but an INTEGER field and a sequence: CREATE SEQUENCE parent_seq; CREATE TABLE parent(id INTEGER, descrip CHAR(50)); So when you want to insert on the parent table, you obtain the next value from the sequence and then you insert in the pare