Received: from ns.krot.org (ns.krot.org [193.212.103.165]) by postgresql.org (8.11.3/8.11.4) with SMTP id fAFNb2m62962 for ; Thu, 15 Nov 2001 18:37:02 -0500 (EST) (envelope-from postgresql@envisity.com) Received: (qmail 11901 invoked by uid 67); 15 Nov 2001 21:50:49 -0000 Message-ID: <20011115215049.14167.qmail@ns.krot.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline MIME-Version: 1.0 From: "Aasmund Midttun Godal" To: roland@astrofoto.org Cc: pgsql-docs@postgresql.org, pgsql-sql@postgresql.org Subject: Re: [SQL] PL/pgSQL examples NOT involving functions Date: Thu, 15 Nov 2001 21:50:49 GMT X-Mailer: Googley-Moogley In-Reply-To: from Roland Roberts on 15 Nov 2001 11:49:12 -0500 References: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by postgresql.org id fAG00Ln65166 X-Archive-Number: 200111/54 X-Sequence-Number: 1127 Well, to the best of my knowledge your question is a contradiction in terms: plpgsql is a procedural language to use it you must create a stored procedure or function... However you are probably able to do many of the things you may want with plain old SQL look it up in the docs especially the case structure. Regards, Aasmund. On 15 Nov 2001 11:49:12 -0500, Roland Roberts wrote: > How can I write a few lines of PL/pgSQL which do not involve creating > a function? I can find no examples of this in the docs, but say I > would like to do something like > > BEGIN > IF EXISTS (SELECT * FROM foo WHERE idx = 27) > THEN > UPDATE foo SET var='some value' WHERE idx=27; > ELSE > INSERT INTO foo (idx, var) VALUES (27, 'some value'); > END IF > END; > > roland > -- > PGP Key ID: 66 BC 3B CD > Roland B. Roberts, PhD RL Enterprises > roland@rlenter.com 76-15 113th Street, Apt 3B > roland@astrofoto.org Forest Hills, NY 11375 > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster Aasmund Midttun Godal aasmund@godal.com - http://www.godal.com/ +47 40 45 20 46