X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 326EF3A2BA2 for ; Mon, 17 Jan 2005 16:03:37 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18565-04 for ; Mon, 17 Jan 2005 16:03:23 +0000 (GMT) Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by svr1.postgresql.org (Postfix) with ESMTP id CA6E53A3D76 for ; Mon, 17 Jan 2005 16:03:06 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-33.mail.demon.net with esmtp (Exim 4.42) id 1CqZLL-000Hqu-B6; Mon, 17 Jan 2005 16:03:05 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 3F1F516BF9; Mon, 17 Jan 2005 16:02:48 +0000 (GMT) Message-ID: <41EBE1A6.6050208@archonet.com> Date: Mon, 17 Jan 2005 16:02:46 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: =?ISO-8859-1?Q?K=D6PFERL_Robert?= Cc: pgsql-sql@postgresql.org Subject: Re: Inserting or Deleting conditionally References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.075 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200501/122 X-Sequence-Number: 19910 KÖPFERL Robert wrote: > Hi, > > coming from imperative programming paradigma, I'm currently trying to > express something like that in _SQL_: SQL is not an imperative language - each SQL statement is an expression to be evaluated. > It should be atomic and like an API for a user. I'm therefore writing > functions: > > CRETE FUNC... > > c := SELECT x,y,z FROM table_a WHERE... > IF COUNT(c)=1 then > INSERT / DELETE ... WHERE x = c.x > ENDIF Even if this was valid syntax, you've just made your query N times more expensive. Try something like: INSERT ... WHERE x IN (SELECT x FROM table_a WHERE ...) or similar. > How is this correctly formulated? Or is there no other way than PL/xxx? Sounds like you want a middle-ware layer to provide an API for your applications. Plenty of options, but it's difficult for people to make suggestions without knowing more about your situation. -- Richard Huxton Archonet Ltd