Thread: currval
Hi, I'm executing the following statements in series. insert into [tablename] values('a', 'b', 'c'); select currval('serial'); serial being the default index on [tablename] The statement works fine from the command line, however, when executing via jdbc, I'm getting no results back (null pointer). Has anyone experienced this and have a solution? Regards, Craig May Enth Dimension http://www.enthdimension.com.au
> Hi, there, Is there any way to handle exception ( such as cannot insert duplicate key on a unique index) in plpgsql function? I don't want it abort whole transaction instead I want to do something else if it happened, but I don't want to use a select stmt first to waste the time. In Orcale, in plsql we can say, declare begin do something exception do something else end; How to this exception section in plpgsql???? -- Jie LIANG Internet Products Inc. 10350 Science Center Drive Suite 100, San Diego, CA 92121 Office:(858)320-4873 jliang@ipinc.com www.ipinc.com
> Hi, there, > > Is there any way to handle exception ( such as cannot insert duplicate key on > a unique index) in > plpgsql function? > > I don't want it abort whole transaction instead I want to do something else if > it happened, > but I don't want to use a select stmt first to waste the time. Bad news: there is no such statement in PLPGSQL you like. My usual way to do this is the same you wrote (SELECT first, if no rows FOUND, do the INSERT). Zoltan
OO, That's a big disadvantage, because if the table is huge, using select stmt walking even on an index will take some time and duplicate occur not often, efficiency is a big problem. Thanks anyway. Jie LIANG Internet Products Inc. 10350 Science Center Drive Suite 100, San Diego, CA 92121 Office:(858)320-4873 jliang@ipinc.com www.ipinc.com On Tue, 12 Dec 2000, Kovacs Zoltan Sandor wrote: > > Hi, there, > > > > Is there any way to handle exception ( such as cannot insert duplicate key on > > a unique index) in > > plpgsql function? > > > > I don't want it abort whole transaction instead I want to do something else if > > it happened, > > but I don't want to use a select stmt first to waste the time. > Bad news: there is no such statement in PLPGSQL you like. My usual way to > do this is the same you wrote (SELECT first, if no rows FOUND, do the > INSERT). > > Zoltan >