control structure in a transaction block?

Поиск
Список
Период
Сортировка
От Wei Weng
Тема control structure in a transaction block?
Дата
Msg-id 993489595.11290.1.camel@Monet
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Foreign key problem
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Problems using a rule with the WHERE clause