From: Laurenz Albe <laurenz.albe@cybertec.at>
To: hamann.w@t-online.de
To: pgsql-general@lists.postgresql.org
Subject: Re: data definition within plpgsql
Date: Mon, 28 Jan 2019 11:23:52 +0100
Message-ID: <5f10540a045ef37e7ab877fcc110e1742f34350a.camel@cybertec.at> (raw)
In-Reply-To: <wolfgang-1190128111756.A0227604@noten19.local>
References: <wolfgang-1190128111756.A0227604@noten19.local>
hamann.w@t-online.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: laurenz.albe@cybertec.at, hamann.w@t-online.de
Subject: Re: data definition within plpgsql
In-Reply-To: <5f10540a045ef37e7ab877fcc110e1742f34350a.camel@cybertec.at>
References: <wolfgang-1190128111756.A0227604@noten19.local> <5f10540a045ef37e7ab877fcc110e1742f34350a.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox