Received: from smtp.snet.net (smtp.snet.net [204.60.6.55]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5PGE6a04184 for ; Mon, 25 Jun 2001 12:14:06 -0400 (EDT) (envelope-from wweng@kencast.com) Received: from pop.snet.net (pop.snet.net [204.60.6.9]) by smtp.snet.net (8.11.1/8.11.1/SNET-mx-1.4/D-1.10/O-1.7) with ESMTP id f5PGE5C27189 for ; Mon, 25 Jun 2001 12:14:05 -0400 (EDT) Received: from [192.168.1.83] (167.95.252.64.snet.net [64.252.95.167]) by pop.snet.net (8.11.1/8.11.1/SNET-pop-1.5/D-1.8/O-1.6) with ESMTP id f5PGE5r20780 for ; Mon, 25 Jun 2001 12:14:05 -0400 (EDT) Subject: control structure in a transaction block? From: Wei Weng To: pgsql-sql@postgresql.org Content-Type: text/plain X-Mailer: Evolution/0.10 (Preview Release) Date: 25 Jun 2001 13:19:45 -0400 Message-Id: <993489595.11290.1.camel@Monet> Mime-Version: 1.0 X-Archive-Number: 200106/403 X-Sequence-Number: 3700 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.