pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: KÖPFERL Robert <robert.koepferl@sonorys.at>
Cc: pgsql-sql@postgresql.org
Subject: Re: Inserting or Deleting conditionally
Date: Mon, 17 Jan 2005 16:02:46 +0000
Message-ID: <41EBE1A6.6050208@archonet.com> (raw)
In-Reply-To: <ED4E30DD9C43D5118DFB00508BBBA76EB16561@neptun.sonorys.at>
References: <ED4E30DD9C43D5118DFB00508BBBA76EB16561@neptun.sonorys.at>

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



view thread (2+ messages)

Message-ID: <41EBE1A6.6050208@archonet.com>
Permalink:  ../41EBE1A6.6050208@archonet.com/
Also on:    postgresql.org/message-id/41EBE1A6.6050208@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, robert.koepferl@sonorys.at
  Subject: Re: Inserting or Deleting conditionally
  In-Reply-To: <41EBE1A6.6050208@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox