pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wei Weng <wweng@kencast.com>
To: pgsql-sql@postgresql.org
Subject: control structure in a transaction block?
Date: 25 Jun 2001 13:19:45 -0400
Message-ID: <993489595.11290.1.camel@Monet> (raw)

I am using postgresql 7.1.2.

I am trying to implement the following pseudo code:

BEGIN
aid = select id from table_a where name = 'test';
if(aid != NULL) 
then
{
    update set name = 'test_test' where id = aid;
}
else
{
    insert into table_a values (nextval('table_a_id_seq'), 'test');
}
COMMIT

But as we know, you can't use control structure in a transaction block.

And I can't use a function either, because in the real application,
there are way too many parameters needed to be passed in order to do the
"insert" or "update".

Is there any tricks I can play here? 

Thanks. 

-- 
Wei Weng
Network Software Engineer
KenCast Inc.





Message-ID: <993489595.11290.1.camel@Monet>
Permalink:  ../993489595.11290.1.camel@Monet/
Also on:    postgresql.org/message-id/993489595.11290.1.camel@Monet

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: wweng@kencast.com
  Subject: Re: control structure in a transaction block?
  In-Reply-To: <993489595.11290.1.camel@Monet>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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