Re: [SQL] getting back autonumber just inserted

2005-07-14 Thread Bruno Wolff III
On Thu, Jul 07, 2005 at 14:47:23 -0600, Larry Meadors <[EMAIL PROTECTED]> wrote: > If you have a trigger on your table that inserts a record in a table > and shares the same sequence, what value do you get back, the > triggered curval, or the currently inserted one? Whichever one was done second

Re: [SQL] getting back autonumber just inserted

2005-07-13 Thread Larry Meadors
If you have a trigger on your table that inserts a record in a table and shares the same sequence, what value do you get back, the triggered curval, or the currently inserted one? Being a lazy bum, this is why I still prefer the "get key - insert record" approach. Less brain power required. ;-) L

Re: [SQL] getting back autonumber just inserted

2005-07-13 Thread Larry Meadors
Sounds like M$ SuckQL's @@identity value. ;-) Larry On 7/7/05, Michael Fuhr <[EMAIL PROTECTED]> wrote: > On Fri, Jul 08, 2005 at 01:56:26AM +0200, PFC wrote: > > >Do you mean with lastval()? Here's what happens: > > > > Hm, interesting, you mean the return value of lastval() also depends > > if

Re: [SQL] getting back autonumber just inserted

2005-07-13 Thread Vivek Khera
On Jul 7, 2005, at 4:14 PM, Theodore Petrosky wrote: you have to use currval inside a transaction... begin; insert something that increments the counter; select currval('sequence_name'); end; using currval inside a transaction guarantees that the value is correct for your insert statement an

Re: [SQL] getting back autonumber just inserted

2005-07-09 Thread Mischa Sandberg
Quoting "jimmy.olsen" <[EMAIL PROTECTED]>: > I don't know how to create a Global Variable in Postgres, but the > idea is > very simple: > 1. Encapsulate the NextVal function in MyNextVal > 2. Set to Global variable with NextVal of the desired sequence > 3. Inspect to value of the global variable (

Re: [SQL] getting back autonumber just inserted

2005-07-09 Thread jimmy.olsen
TECTED]> Cc: Sent: Thursday, July 07, 2005 3:03 PM Subject: Re: [SQL] getting back autonumber just inserted > On Thu, Jul 07, 2005 at 07:50:16PM +0200, mail TechEvolution wrote: > > hello > > > > i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0 > > (windows

Re: [SQL] getting back autonumber just inserted

2005-07-08 Thread Bruno Wolff III
On Fri, Jul 08, 2005 at 05:03:37 +0200, PFC <[EMAIL PROTECTED]> wrote: > > It's the first time I see a MySQLism in postgres ! This has meaning in more ways than one. > However I like it, cos it might subvert some MySQL users, and > provide easy answers to The Weekly Questio

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Michael Fuhr
On Fri, Jul 08, 2005 at 05:03:37AM +0200, PFC wrote: > >On Fri, Jul 08, 2005 at 01:56:26AM +0200, PFC wrote: > >>Hm, interesting, you mean the return value of lastval() also depends > >>if you set your constraints to deferred or immediate ? > > > >My mind's ablank trying to contrive a situation w

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread PFC
On Fri, Jul 08, 2005 at 01:56:26AM +0200, PFC wrote: >Do you mean with lastval()? Here's what happens: Hm, interesting, you mean the return value of lastval() also depends if you set your constraints to deferred or immediate ? My mind's ablank trying to contrive a situation where that wou

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Michael Fuhr
On Fri, Jul 08, 2005 at 01:56:26AM +0200, PFC wrote: > >Do you mean with lastval()? Here's what happens: > > Hm, interesting, you mean the return value of lastval() also depends > if you set your constraints to deferred or immediate ? My mind's ablank trying to contrive a situation where that

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread PFC
What happens if an INSERT trigger inserts something into another table which also has a sequence ? Using what, lastval()? The app will get very confused, because it'll get the value from the sequence used in the trigger. Using currval there is no problem, but you already kne

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread PFC
Do you mean with lastval()? Here's what happens: Hm, interesting, you mean the return value of lastval() also depends if you set your constraints to deferred or immediate ? I wond ---(end of broadcast)--- TIP 6: Have you searched our list

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Michael Fuhr
On Fri, Jul 08, 2005 at 12:26:30AM +0200, PFC wrote: > > >That's a different issue than whether currval() is subject to > >interference from other transactions. And just wait until PostgreSQL > >8.1 comes out and people start using lastval() -- then it could get > >*really* confusing which sequen

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Alvaro Herrera
On Fri, Jul 08, 2005 at 12:26:30AM +0200, PFC wrote: > > >That's a different issue than whether currval() is subject to > >interference from other transactions. And just wait until PostgreSQL > >8.1 comes out and people start using lastval() -- then it could get > >*really* confusing which sequen

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread PFC
That's a different issue than whether currval() is subject to interference from other transactions. And just wait until PostgreSQL 8.1 comes out and people start using lastval() -- then it could get *really* confusing which sequence value you're getting. What happens if an INSERT trigger ins

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Michael Fuhr
On Thu, Jul 07, 2005 at 02:47:23PM -0600, Larry Meadors wrote: > > If you have a trigger on your table that inserts a record in a table > and shares the same sequence, what value do you get back, the > triggered curval, or the currently inserted one? That's a different issue than whether currval()

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Michael Fuhr
On Thu, Jul 07, 2005 at 01:14:33PM -0700, Theodore Petrosky wrote: > > you have to use currval inside a transaction... Not true. Have you observed otherwise? > begin; > insert something that increments the counter; > select currval('sequence_name'); > end; > > using currval inside a transactio

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread mail TechEvolution
THX to all guys, it is working great !! greetZ wes ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Scott Marlowe
On Thu, 2005-07-07 at 15:14, Theodore Petrosky wrote: > you have to use currval inside a transaction... > > begin; > insert something that increments the counter; > select currval('sequence_name'); > end; > > using currval inside a transaction guarantees that the > value is correct for your inser

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Theodore Petrosky
you have to use currval inside a transaction... begin; insert something that increments the counter; select currval('sequence_name'); end; using currval inside a transaction guarantees that the value is correct for your insert statement and has not changed by another insert statement. Ted ---

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Alvaro Herrera
On Thu, Jul 07, 2005 at 08:21:12PM +0200, mail TechEvolution wrote: > hi Alvaro Herrera > > >>You use the currval() function, using the name of the involved sequence > >>as parameter. There is a pg_get_serial_sequence() function, to which > >>you give the table name and column name > > thx for t

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread mail TechEvolution
hi Alvaro Herrera You use the currval() function, using the name of the involved sequence as parameter. There is a pg_get_serial_sequence() function, to which you give the table name and column name thx for the information and is there a function i can use to get the last added autonumber wi

Re: [SQL] getting back autonumber just inserted

2005-07-07 Thread Alvaro Herrera
On Thu, Jul 07, 2005 at 07:50:16PM +0200, mail TechEvolution wrote: > hello > > i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0 > (windowsinstaller) on a xp prof platform > > i would like to get back the autonumber from the last record inserted, > for other SQL db (m$ sql db ...) i cou

[SQL] getting back autonumber just inserted

2005-07-07 Thread mail TechEvolution
hello i ame a newbie to PostGreSQL, I ame using PostGreSQL 8.0 (windowsinstaller) on a xp prof platform i would like to get back the autonumber from the last record inserted, for other SQL db (m$ sql db ...) i could use: SELECT @@ IDENTITY can someone help me by informing me what the SQL sy

Re: [SQL] getting back autonumber just inserted

2005-02-04 Thread Magnus Hagander
> I don't work with M$ DBs, but saw that "autonumber" is an M$ concept. > Purely for my own edification, how do you get the most resent > value of an autonumber in M$? I was helping someone out who > was using M$ stuff and was amazed that there was no currval function. I beleive they call it ID

Re: [SQL] getting back autonumber just inserted

2005-02-04 Thread Richard_D_Levine
: Subject: Re: [SQL] getting back autonumber just inserted [EMAIL PROTECTED]

Re: [SQL] getting back autonumber just inserted

2005-02-03 Thread Edmund Bacon
Perhaps you meant: http://www.postgresql.org/docs/8.0/interactive/functions-info.html#FUNCTIONS-INFO-SCHEMA-TABLE in particular |pg_get_serial_sequence|(table_name, column_name) Sean Davis wrote: On Feb 3, 2005, at 5:16 PM, lorid wrote: I could have sworn I kept a copy of prior emails that discus

Re: [SQL] getting back autonumber just inserted

2005-02-03 Thread Sean Davis
On Feb 3, 2005, at 5:16 PM, lorid wrote: I could have sworn I kept a copy of prior emails that discussed how to get back a value that was just inserted into a autonumber (or in postgresql case a sequence number) See here: http://www.postgresql.org/docs/8.0/interactive/functions- sequence.html

Re: [SQL] getting back autonumber just inserted

2005-02-03 Thread Scott Marlowe
On Thu, 2005-02-03 at 16:16, lorid wrote: > I could have sworn I kept a copy of prior emails that discussed how to > get back a value that was just inserted into a autonumber (or in > postgresql case a sequence number) If you know the name of the sequence the number came from you can use currva

[SQL] getting back autonumber just inserted

2005-02-03 Thread lorid
I could have sworn I kept a copy of prior emails that discussed how to get back a value that was just inserted into a autonumber (or in postgresql case a sequence number) any help will be appreciated thanks Lori ---(end of broadcast)--- TIP 5: Hav