control structure in a transaction block?

From: Wei Weng <wweng(at)kencast(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: control structure in a transaction block?
Date: 2001-06-25 17:19:45
Message-ID: 993489595.11290.1.camel@Monet
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-06-25 18:01:11 Re: Problems using a rule with the WHERE clause
Previous Message Stephan Szabo 2001-06-25 16:22:56 Re: Foreign key problem