PostgreSQL 9.0 issues with function -
PostgreSQL 9.0 issues with function -
here function working with:
create or replace function f_multiply_row(_tbl regclass , _idname text , _minid int , _maxid int) returns void $func$ begin execute ( select format('insert %1$s (%2$i, %3$s) select g.g, %3$s (select * %1$s limit 1) t ,generate_series($1, $2) g(g)'::text , _tbl , _idname , string_agg(quote_ident(attname), ', ') ) pg_attribute attrelid = _tbl , attname <> _idname -- exclude id column , not attisdropped -- no dropped (dead) columns , attnum > 0 -- no scheme columns ) using _minid, _maxid; end $func$ language plpgsql; select f_multiply_row('campaign', 'campaign_id', 50, 500);
obviously psql 9.0 not have format
method (introduced in 9.1), trying convert method work in 9.0 , having hardest time getting work.
error : error: function format(text, regclass, text, text) not exist line 2: select format('insert %1$s (%2$i, %3$s) ^ hint: no function matches given name , argument types. might need add together explicit type casts.
so, attempted rewrite in 9.0 style:
create or replace function f_multiply_row() returns void $func$ declare _tbl regclass := quote_ident('campaign'); _idname text := 'campaign_id'; _minid int := 50; _maxid int := 500; begin execute ( 'select insert ' || _tbl || ' ($1, $2) select g.g $3 (select * ' || _tbl || ' limit 1) t, generate_series($1, $2) g(g)' using _tbl, _idname, string_agg(quote_ident(attname, ', ')) pg_attribute attrelid = _tbl , attname <> _idname -- exclude id column , not attisdropped -- no dropped (dead) columns , attnum > 0 -- no scheme columns ); end $func$ language plpgsql; select f_multiply_row();
but, above causes these 2 errors:
error : error: syntax error @ or near "using" line 15: using _tbl, _idname, string_agg(quote_ident(attname, ', ')... ^
and
error : error: function f_multiply_row() not exist line 1: select f_multiply_row() ^ hint: no function matches given name , argument types. might need add together explicit type casts.
postgresql
Comments
Post a Comment