sql - how to get current row value in plpgsql function -
i need create plpgsql methods use current row value without passing in parameter in update command.
i tried
create temp table test ( test text, result text ) on commit drop; insert test values ('1',''); create or replace function public.gettest() returns text $$ declare comp text := null; begin execute 'select ''current row '' ||test.test' comp; return comp; end; $$ language plpgsql strict stable; update test set result = 'result: ' || gettest();
but got exception
error: missing from-clause entry table "test" line 1: select 'current row ' ||test.test ^ query: select 'current row ' ||test.test context: pl/pgsql function gettest() line 6 @ execute statement ********** error ********** error: missing from-clause entry table "test" sql state: 42p01 context: pl/pgsql function gettest() line 6 @ execute statement
how fix ? how fix without passing vaue plpgsql method parameter ?
there no such thing "implicit current row". have pass the function whatever needs parameter. can pass complete row if want to:
create temp table test (val text, result text ) on commit drop; insert test values ('1',''); insert test values ('2',''); create or replace function gettest(p_test test) returns text $$ declare comp text := null; begin comp := 'current row '||p_test.val; return comp; end; $$ language plpgsql strict stable; update test set result = 'result: ' || gettest(test);
i had rename column test
else, otherwise call gettest(test)
refer column not whole table (=row) , didn't work.
Comments
Post a Comment