From: | Peter Kroon <plakroon(at)gmail(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | set value var via execute |
Date: | 2012-11-29 16:01:25 |
Message-ID: | CAOh+DOmSUiCrgW=f-42piQhndoC=9d-kZLypTtR8Rm4HnME42A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Is it possible to set the value of a var via execute?
drop table if exists __test;
create unlogged table __test(
id int
);
DO $$
DECLARE
v_holder int;
v_table text = 'table';
v_record_0 text[];
v_id int;
BEGIN
execute '
insert into __test(id)
select id from '||v_table||' order by random() limit 2
';
v_id = (select id from __test limit 1);
--begin this
fails------------------------------------------------------------------------------------------
v_holder = execute 'select id from '||v_table||' order by random()
limit 1';
--end this
fails-------------------------------------------------------------------------------------------
v_record_0 := array(
SELECT id FROM table order by random() --limit 2
);
raise notice '%', v_record_0;
END;
$$ LANGUAGE plpgsql;
From | Date | Subject | |
---|---|---|---|
Next Message | Schnabel, Robert D. | 2012-11-29 16:11:44 | When does CLUSTER occur? |
Previous Message | David Greco | 2012-11-29 15:57:35 | UPDATE syntax |