control structure in a transaction block? - Mailing list pgsql-sql

From Wei Weng
Subject control structure in a transaction block?
Date
Msg-id 993489595.11290.1.camel@Monet
Whole thread Raw
List 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.




pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Foreign key problem
Next
From: Tom Lane
Date:
Subject: Re: Problems using a rule with the WHERE clause