Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1go45C-0007RZ-SW for pgsql-general@arkaria.postgresql.org; Mon, 28 Jan 2019 10:24:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1go45B-0004zS-CW for pgsql-general@arkaria.postgresql.org; Mon, 28 Jan 2019 10:24:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1go45B-0004zL-1n for pgsql-general@lists.postgresql.org; Mon, 28 Jan 2019 10:24:01 +0000 Received: from mx2a.mailbox.org ([2001:67c:2050:104:0:2:25:2] helo=mx2.mailbox.org) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1go458-0008FP-FJ for pgsql-general@lists.postgresql.org; Mon, 28 Jan 2019 10:23:59 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id D1768A1845; Mon, 28 Jan 2019 11:23:55 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id P_60SFIx7nRM; Mon, 28 Jan 2019 11:23:54 +0100 (CET) Message-ID: <5f10540a045ef37e7ab877fcc110e1742f34350a.camel@cybertec.at> Subject: Re: data definition within plpgsql From: Laurenz Albe To: hamann.w@t-online.de, pgsql-general@lists.postgresql.org Date: Mon, 28 Jan 2019 11:23:52 +0100 In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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