pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Inserting or Deleting conditionally
2+ messages / 2 participants
[nested] [flat]

* Inserting or Deleting conditionally
@ 2005-01-17 15:25 KÖPFERL Robert <robert.koepferl@sonorys.at>
  2005-01-17 16:02 ` Re: Inserting or Deleting conditionally Richard Huxton <dev@archonet.com>
  0 siblings, 1 reply; 2+ messages in thread

From: KÖPFERL Robert @ 2005-01-17 15:25 UTC (permalink / raw)
  To: ; +Cc: pgsql-sql

Hi,

coming from imperative programming paradigma, I'm currently trying to
express something like that in _SQL_:

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

LANGUAGE SQL;


How is this correctly formulated? Or is there no other way than PL/xxx?



Thanks



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Inserting or Deleting conditionally
  2005-01-17 15:25 Inserting or Deleting conditionally KÖPFERL Robert <robert.koepferl@sonorys.at>
@ 2005-01-17 16:02 ` Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Huxton @ 2005-01-17 16:02 UTC (permalink / raw)
  To: KÖPFERL Robert <robert.koepferl@sonorys.at>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-01-17 16:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-17 15:25 Inserting or Deleting conditionally KÖPFERL Robert <robert.koepferl@sonorys.at>
2005-01-17 16:02 ` Richard Huxton <dev@archonet.com>

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