Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 9D2B39FB595 for ; Sun, 11 Mar 2007 11:47:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 54741-02 for ; Sun, 11 Mar 2007 11:47:47 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id CF50B9FB581 for ; Sun, 11 Mar 2007 11:47:47 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HQPKh-00038A-5S for pgadmin-support@postgresql.org; Sun, 11 Mar 2007 15:47:35 +0100 Received: from 85.187.136.11 ([85.187.136.11]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 11 Mar 2007 15:47:35 +0100 Received: from milen by 85.187.136.11 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 11 Mar 2007 15:47:35 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgadmin-support@postgresql.org From: "Milen A. Radev" Subject: Re: Alternative Serial Date: Sun, 11 Mar 2007 16:47:52 +0200 Lines: 64 Message-ID: References: <55c095e90703110720o78dfcfeai2b31bbadf17582b7@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 85.187.136.11 User-Agent: Mozilla Thunderbird 1.5.0.10 (Windows/20070221) In-Reply-To: <55c095e90703110720o78dfcfeai2b31bbadf17582b7@mail.gmail.com> Cc: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.862 tagged_above=0 required=5 tests=AWL, BAYES_50, RCVD_NUMERIC_HELO, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200703/42 X-Sequence-Number: 6757 Ezequias Rodrigues da Rocha написа: > Hi list, > > I know that serials must be created like this. Actually no. > Create the Serial There is no db object 'Serial' you could create independently - you probably mean 'sequence'. > > Create a field table and reffers to the pre-created serial. You could and should create a field of (pseudo-)type 'serial' and be done with it. > > Now I noticed that it is possible to use the default value. I am almost > quite sure that this is an alternative way and non polite. The old and still working way to create a field that would function as surrogate key is to create a sequence, create a field in the table, mark it integer and set its default value to be the 'nextval' of the created sequence. That was too much typing for some (I'm included) and later a syntax sugar was added - the pseudo-type 'serial'. So the following syntax: CREATE TABLE example ( example_sid SERIAL NOT NULL PRIMARY KEY, ... ) is equivalen to: CREATE SEQUENCE example_example_sid_seq; CREATE TABLE example ( example_sid INTEGER PRIMARY KEY DEFAULT NEXVAL)('example_example_sid_seq'), ... ) As you could see - very convenient for the 99.9% of the cases. > > I would like to know if I am correct and what does it means: > > nextval('mySerial_id'::regclass) > > What is regclass ? Read here about 'regclass' (there is a note about it) - http://www.postgresql.org/docs/8.2/static/functions-sequence.html, but that should not be important to you. -- Milen A. Radev