From: | Raul Kaubi <raulkaubi(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Get rid of brackets around variable |
Date: | 2020-02-05 10:48:54 |
Message-ID: | CAO_+3-DBZ4y9Tg4AQ1ubG=WkDkjV6uCcL6CtOKmdbKpCfUCtyQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Geoff Winkless | 2020-02-05 11:10:53 | Re: Get rid of brackets around variable |
Previous Message | Peter J. Holzer | 2020-02-05 10:40:06 | Re: Restore is failing |