Hi
PostgreSQL 12.1
I am trying to figure out, how can I get rid of brackets for variable.
Example as follows:
DO $$
DECLARE
cur cursor for
select * from (values('logi_web'), ('logi_taustaprotsess')) as q (col1);
BEGIN
for i in cur LOOP
RAISE NOTICE 'create table %_y2020m01 PARTITION OF % FOR VALUES FROM (''2019-12-01'') TO (''2020-01-01'')', i, i;
END LOOP;
END;
$$ LANGUAGE plpgsql;
If I execute, this is the output:
NOTICE: create table (logi_web)_y2020m01 PARTITION OF (logi_web) FOR VALUES FROM ('2019-12-01') TO ('2020-01-01')
NOTICE: create table (logi_taustaprotsess)_y2020m01 PARTITION OF (logi_taustaprotsess) FOR VALUES FROM ('2019-12-01') TO ('2020-01-01')
DO
Now I have tried, even if I execute this statement:
EXECUTE 'create table '||i||'_y2020m01 PARTITION OF '||i||' FOR VALUES FROM (''2019-12-01'') TO (''2020-01-01'')';
ERROR: syntax error at or near "("
LINE 1: create table (logi_web)_y2020m01 PARTITION OF (logi_web) FOR...
^
QUERY: create table (logi_web)_y2020m01 PARTITION OF (logi_web) FOR VALUES FROM ('2019-12-01') TO ('2020-01-01')
CONTEXT: PL/pgSQL function inline_code_block line 8 at EXECUTE
Then you can see, that it still puts these brackets around variable.
Raul