| From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
|---|---|
| To: | hamann(dot)w(at)t-online(dot)de, pgsql-general(at)lists(dot)postgresql(dot)org |
| Subject: | Re: data definition within plpgsql |
| Date: | 2019-01-28 10:23:52 |
| Message-ID: | 5f10540a045ef37e7ab877fcc110e1742f34350a.camel@cybertec.at |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
hamann(dot)w(at)t-online(dot)de wrote:
> I tried this code (to be inserted within a larger psql script)
>
> do $_$
> declare
> next int;
> begin
> select max(id) + 1 into next from items;
> execute 'create temp sequence tmp_ids start $1' using next;
> end
> $_$ language plpgsql;
>
> but that reports a syntax error near $1.
> What is the proper way of doing that?
You cannot use parameters with DDL statements.
This should work:
EXECUTE format('CREATE TEMP SEQUENCE tmp_ids START %s', $1);
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Pavan Teja | 2019-01-28 10:27:05 | Re: logical replication problem |
| Previous Message | Pavel Stehule | 2019-01-28 10:20:35 | Re: data definition within plpgsql |