Re: Inserting or Deleting conditionally

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: Inserting or Deleting conditionally
Дата
Msg-id 41EBE1A6.6050208@archonet.com
обсуждение исходный текст
Ответ на Inserting or Deleting conditionally  (KÖPFERL Robert <robert.koepferl@sonorys.at>)
Список 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: KÖPFERL Robert
Дата:
Сообщение: Inserting or Deleting conditionally
Следующее
От: Ari Kahn
Дата:
Сообщение: plpgsql and for with integer loopvar error