Skip site navigation (1) Skip section navigation (2)

Re: lastval()

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Abhijit Menon-Sen <ams(at)oryx(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: lastval()
Date: 2005-05-11 03:44:38
Message-ID: 200505110344.j4B3icX03053@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Abhijit Menon-Sen wrote:
> At 2005-05-10 23:30:05 -0400, pgman(at)candle(dot)pha(dot)pa(dot)us wrote:
> >
> > > By the way, what would lastval() do if an insert trigger inserts
> > > a row into a table with another serial column?
> > 
> > It fails, just like it would fail now if the trigger inserted into
> > the same table that used the trigger, or a rule.
> 
> I don't understand what you mean. "Just like it would fail now"? It
> doesn't exist yet, how can it fail? And how would it know when to
> fail anyway, rather than return a wrong value?

Uh, if the table's sequence name is 'tab_x_seq', and you do
currval('tab_x_seq'), you will get the trigger or rule insert id in that
case.

So, currval() widens a problem we already have if the rule/trigger
inserts into the same table.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2005-05-11 04:02:34
Subject: Re: [PATCHES] Cleaning up unreferenced table files
Previous:From: Abhijit Menon-SenDate: 2005-05-11 03:35:45
Subject: Re: lastval()

pgsql-patches by date

Next:From: Bruce MomjianDate: 2005-05-11 03:45:23
Subject: Re: lastval()
Previous:From: John HansenDate: 2005-05-11 03:39:40
Subject: Re: lastval()

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group