Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DEC2C9FC3BE for ; Thu, 18 Oct 2007 20:34:40 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 87979-06 for ; Thu, 18 Oct 2007 20:34:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail63.csoft.net (leary.csoft.net [205.205.214.5]) by postgresql.org (Postfix) with SMTP id 0C56F9FC3AC for ; Thu, 18 Oct 2007 20:34:37 -0300 (ADT) Received: (qmail 3039 invoked by uid 1112); 18 Oct 2007 23:34:36 -0000 Date: Thu, 18 Oct 2007 19:34:36 -0400 (EDT) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Andrei Ilitchev cc: pgsql-jdbc@postgresql.org, Marina Vatkina Subject: Re: Fw: postgresql experts please help In-Reply-To: <011701c811ca$03cea740$4c349c0a@ca.oracle.com> Message-ID: References: <001101c81189$2f3f52d0$4c349c0a@ca.oracle.com> <00d601c811b7$47c1a6e0$4c349c0a@ca.oracle.com> <011701c811ca$03cea740$4c349c0a@ca.oracle.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/114 X-Sequence-Number: 17686 On Thu, 18 Oct 2007, Andrei Ilitchev wrote: > IMO this behaviour (if there's existing sequence create another one with the > same name but in some other place) is very wrong - be predictible, throw > exception. This is not true, but it can be confusing. A serial's sequence will always be put in the same schema as the table it's attached to. If another sequence exists with the same name in that schema, it will choose another name for the serial sequence: jurka=# create sequence t2_a_seq; CREATE SEQUENCE jurka=# create table t2 (a serial); NOTICE: CREATE TABLE will create implicit sequence "t2_a_seq1" for serial column "t2.a" CREATE TABLE Notice that it created "t2_a_seq1" to avoid the conflict with the existing "t2_a_seq" sequence. If you've got another sequence with the same name in another schema it does not conflict, but depending on your search_path you can get them mixed up. Both of these problems are solved by using pg_get_serial_sequence, which should perhaps be mentioned more prominently in the documentation. There is definitely a use for keeping multiple tables/sequences with identical names in different schemas and not having them conflict. In fact that's the primary use case for having schemas at all. Kris Jurka