Search Postgresql Archives

set value var via execute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux