Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 631CFB5DC04 for ; Sun, 12 Jun 2011 05:22:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 08427-04 for ; Sun, 12 Jun 2011 08:22:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail46.e.nsc.no (mail46.e.nsc.no [193.213.115.46]) by mail.postgresql.org (Postfix) with ESMTP id 9F29BB5DBF3 for ; Sun, 12 Jun 2011 05:22:30 -0300 (ADT) Received: from balapapa.localnet (168.173.16.62.customer.cdi.no [62.16.173.168]) (authenticated bits=0) by mail46.nsc.no (8.14.4/8.14.4) with ESMTP id p5C8MTl2007909 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sun, 12 Jun 2011 10:22:29 +0200 (MEST) From: Leif Biberg Kristensen To: pgsql-sql@postgresql.org Subject: Re: Subselects not allowed? Date: Sun, 12 Jun 2011 10:22:28 +0200 User-Agent: KMail/1.13.7 (Linux/2.6.38-gentoo-r6; KDE/4.6.3; x86_64; ; ) References: <201106111701.54145.leif@solumslekt.org> <201106112209.09813.leif@solumslekt.org> In-Reply-To: <201106112209.09813.leif@solumslekt.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201106121022.28759.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/42 X-Sequence-Number: 35508 On Saturday 11. June 2011 22.09.09 Leif Biberg Kristensen wrote: > I've written a blog post which I hope may be helpful to others in a similar > situation: > > > > Thanks to Guillaume Lelarge, Tom Lane, and Andreas Kretschmer. You guys are > great. And even better, in the first comment to the blog post, I was advised about the SETVAL() function which does exactly what I wanted in the first place. CREATE SEQUENCE persons_person_id_seq; SELECT SETVAL('persons_person_id_seq', MAX(person_id)) FROM persons; ALTER TABLE persons ALTER COLUMN person_id SET DEFAULT NEXTVAL('persons_person_id_seq'); ALTER SEQUENCE persons_person_id_seq OWNED BY persons.person_id; regards, Leif http://code.google.com/p/yggdrasil-genealogy/