Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Update as a function result
drop function if exists f(); drop table if exists t; create table t(i serial primary key, x int); insert into t(x) select random()*10 from generate_series(1,10); create function f() returns setof t language plpgsql as $$ declare r t[]; begin -- How to get result into the variable and return it with a as (update t set x = x*2 where i > 5 returning *) select array_agg(a.*) into r from a; return query select * from unnest(r); -- How to return result of update (just remove parenthesises around it) return query update t set x = x*2 where i > 5 returning *; end $$; select * from f();
run
|
edit
|
history
|
help
0
proj
2
postgresql select test
renaming JSON field
ds
jsonb handle
Black Wall
Final 2
to_char(now(), 'YYYYddd')
SQL - Unpivot Table