Get rid of brackets around variable - Mailing list pgsql-general

From Raul Kaubi
Subject Get rid of brackets around variable
Date
Msg-id CAO_+3-DBZ4y9Tg4AQ1ubG=WkDkjV6uCcL6CtOKmdbKpCfUCtyQ@mail.gmail.com
Whole thread Raw
Responses Re: Get rid of brackets around variable  (Geoff Winkless <pgsqladmin@geoff.dj>)
List pgsql-general
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

pgsql-general by date:

Previous
From: "Peter J. Holzer"
Date:
Subject: Re: Restore is failing
Next
From: Geoff Winkless
Date:
Subject: Re: Get rid of brackets around variable