Re: Functions with dynamic queries
| От | Gabriel Dovalo Carril |
|---|---|
| Тема | Re: Functions with dynamic queries |
| Дата | |
| Msg-id | 3CED5594.85BF8596@terra.es обсуждение исходный текст |
| Ответ на | Functions with dynamic queries (Gabriel Dovalo Carril <dovalo@terra.es>) |
| Ответы |
Re: Functions with dynamic queries
|
| Список | pgsql-sql |
> you may not need a function at all if your case is that simple . you
> can use subselects and || operators to do many complicated things..
> can we know a bit more abt. your specific problem
Ok. I have this query:
Select sum(stocks.stkreal)::text || ',' || sum(stocks.stkpteser)::text as stock
From stocks, prendas
Where prendas.codprenda = stocks.codprenda and
prendas.codarticulo = '020720004';
And I want to create a function which receives
"codarticulo" as a parameter.
*----------------
Create Function calc_stocks(text) Returns text AS '
Declare codart ALIAS For $1; all_stocks record;
BeginExecute '' Select sum(stocks.stkreal)::text || '' || '''''' ,'''''' || '' || '' || ''sum(stocks.stkpteser)::text
asstock '' || ''into all_stocks '' || ''From stocks, prendas '' || ''Where prendas.codprenda = stocks.codprenda and ''
||''prendas.codarticulo = codart; '' Return all_stocks.stock;
End;
' language 'plpgsql';
*-----------------
gesyweb=# select calc_stocks('020220064');
ERROR: record all_stocks is unassigned yet
gesyweb=#
В списке pgsql-sql по дате отправления: