Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 20069B5DBE7 for ; Sat, 11 Jun 2011 12:24:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 16007-09 for ; Sat, 11 Jun 2011 15:23:55 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail49.e.nsc.no (mail49.e.nsc.no [193.213.115.49]) by mail.postgresql.org (Postfix) with ESMTP id AC393B5DBCA for ; Sat, 11 Jun 2011 12:23:53 -0300 (ADT) Received: from balapapa.localnet (168.173.16.62.customer.cdi.no [62.16.173.168]) (authenticated bits=0) by mail49.nsc.no (8.14.4/8.14.4) with ESMTP id p5BFNqsn013593 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 11 Jun 2011 17:23:52 +0200 (MEST) From: Leif Biberg Kristensen To: pgsql-sql@postgresql.org Subject: Re: Subselects not allowed? Date: Sat, 11 Jun 2011 17:23:50 +0200 User-Agent: KMail/1.13.7 (Linux/2.6.38-gentoo-r6; KDE/4.6.2; x86_64; ; ) References: <201106111701.54145.leif@solumslekt.org> <1307804893.25444.5.camel@laptop> <15640.1307805261@sss.pgh.pa.us> In-Reply-To: <15640.1307805261@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201106111723.51057.leif@solumslekt.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/38 X-Sequence-Number: 35504 On Saturday 11. June 2011 17.14.21 Tom Lane wrote: > Guillaume Lelarge writes: > > On Sat, 2011-06-11 at 17:01 +0200, Leif Biberg Kristensen wrote: > >> Can anybody tell me why this doesn't work? > >> pgslekt=> CREATE SEQUENCE sources_source_id_seq START WITH (SELECT > >> MAX(source_id) FROM sources); > >> ERROR: syntax error at or near "(" > > > > Because it's not supported. The START clause expects a value, not a > > subquery. > > More generally, there are no "utility" statements in PG that accept > non-constant expressions in their parameters. (A utility statement is > anything other than SELECT, INSERT, UPDATE, DELETE.) > > There's been occasional speculation about changing that, but it would > take a significant amount of work I think. Thanks for the explanation, Tom. Presumably this means that I can't automatically patch a live database to use a sequence unless I build a special function for the update. With 9.x I could use the new DO syntax, but that isn't yet deployed everywhere. Unless there's a way around it? regards, Leif