Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 97B9CB5DBC1 for ; Sat, 11 Jun 2011 12:23:51 -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 16873-07 for ; Sat, 11 Jun 2011 15:23:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mailout01.ims-firmen.de (mailout01.ims-firmen.de [213.174.32.96]) by mail.postgresql.org (Postfix) with ESMTP id 867CAB5DBE1 for ; Sat, 11 Jun 2011 12:23:43 -0300 (ADT) Received: from [192.168.1.112] (helo=mi3) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1QVQ2I-0005yJ-AS for pgsql-sql@postgresql.org; Sat, 11 Jun 2011 17:23:42 +0200 Received: from [87.170.193.229] (helo=a-kretschmer.de) by mi3 with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1QVQ2I-00071A-3h for pgsql-sql@postgresql.org; Sat, 11 Jun 2011 17:23:42 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1QVQ2G-0002j3-Id for pgsql-sql@postgresql.org; Sat, 11 Jun 2011 17:23:40 +0200 Date: Sat, 11 Jun 2011 17:23:40 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: Subselects not allowed? Message-ID: <20110611152340.GA9062@tux> References: <201106111701.54145.leif@solumslekt.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <201106111701.54145.leif@solumslekt.org> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) 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, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201106/37 X-Sequence-Number: 35503 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 "(" > LINE 1: CREATE SEQUENCE sources_source_id_seq START WITH (SELECT MAX... > ^ > pgslekt=> > > regards, Leif You can't do that, but you can do this: test=# select * from foo; i ---- 98 99 (2 rows) Time: 0,146 ms test=*# \ds seq_foo; No matching relations found. test=*# do $$ declare m int; begin select into m max(i) from foo; execute 'create sequence seq_foo start with ' || m; end; $$; DO Time: 1,115 ms test=*# \ds seq_foo; List of relations Schema | Name | Type | Owner --------+---------+----------+------------ public | seq_foo | sequence | kretschmer (1 row) test=*# select * from seq_foo; sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called ---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+----------- seq_foo | 99 | 99 | 1 | 9223372036854775807 | 1 | 1 | 1 | f | f (1 row) I'm using 9.1Beta, but it works since 9.0, see: http://www.depesz.com/index.php/2009/11/01/waiting-for-8-5-do/#more-1535 Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°