Return-Path: Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: (qmail 36290 invoked from network); 13 Sep 2004 09:21:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 13 Sep 2004 09:21:15 -0000 Received: (qmail 19682 invoked by uid 500); 13 Sep 2004 09:21:13 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 19668 invoked by uid 500); 13 Sep 2004 09:21:13 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 19653 invoked by uid 99); 13 Sep 2004 09:21:13 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from [194.77.152.181] (HELO mail.hometree.net) (194.77.152.181) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 13 Sep 2004 02:21:10 -0700 Received: from tangens.hometree.net (IDENT:news@mail.hometree.net [194.77.152.181]) by mail.hometree.net (8.12.10/8.12.10) with ESMTP id i8D9L7Nx003363 for ; Mon, 13 Sep 2004 11:21:07 +0200 Received: (from news@localhost) by tangens.hometree.net (8.12.10/8.12.8/Submit) id i8D9L7xu003362 for torque-dev@db.apache.org; Mon, 13 Sep 2004 11:21:07 +0200 To: torque-dev@db.apache.org Path: not-for-mail From: "Henning P. Schmiedehausen" Newsgroups: hometree.jakarta.torque.dev Subject: Re: PostgreSQL ID generation Date: Mon, 13 Sep 2004 09:21:07 +0000 (UTC) Organization: INTERMETA - Gesellschaft fuer Mehrwertdienste mbH Lines: 164 Message-ID: References: <41445BE0.5040306@backstagetech.com.au> Reply-To: hps@intermeta.de NNTP-Posting-Host: forge.intermeta.de X-Trace: tangens.hometree.net 1095067267 2642 194.77.152.164 (13 Sep 2004 09:21:07 GMT) X-Complaints-To: news@intermeta.de NNTP-Posting-Date: Mon, 13 Sep 2004 09:21:07 +0000 (UTC) X-Copyright: (C) 1996-2003 Henning Schmiedehausen User-Agent: nn/6.6.5 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Scott Eade writes: > 2. PostgreSQL has a serial data type that Torque already supports to Yep. > a limited extent. IMHO we should fully embrace this by: > 1. Generating schema sql that used the SERIAL datatype rather > than "default nextval('foo_bar_seq')" (the latter with a > different sequence name structure is what PostgreSQL > maintains automatically when the SERIAL datatype is used). > 2. Leaving sequence naming (with the available override), > sequence creation and destruction (drop) to PostgreSQL. > 3. Enhancing the JDBC target to detect the use of sequences so > as to produce schema files that use SERIAL. > 4. Determine whether or not the id-method-parameter element has > any use. The problem with the torque schema and postgresql is, that there are many different ways to generate an ID here: - Using ID_TABLE: using a regular number type like INTEGER or BIGINT as index, generating the ID with Torque - Using a serial datatype: works like MySQL AUTO_INCREMENT, so the ID generator must fetch the index column after an insert - Using default nextval('foo_bar_seq'): Uses a Sequence but manages the id insert process inside the database engine, the ID generator must fetch the index column after an insert. From a database point of view, this is the same as "auto_increment". - Use a sequence and let the ID generator fetch the next value from the sequence and then insert it into the table (sequence generator) The last one is compatible to the Hibernate "sequence" scheme. > 3. The column elements autoIncrement attribute in the schema is not > clearly defined. Correct me if I am wrong, but from your comments > and your patch it appears that you interpret a combination of > idMethod="native" for the table and autoIncrement="true" on a > column to be the triggers for the use of a sequence. I actually The Sequence Generator which does "select nextval('sequence_name')" pulls the ID from the sequence and then inserts it together with the data just like the ID_TABLE generator does. So the ID column itself is just a regular number type without any special properties (like serial or default value). > thought that primaryKey="true" had something to do with it and > from the generated code this does in fact appear to be the case. > Generate the sql for the following schema (comments on the resultant > sql are included within): > > > > primaryKey="true" type="INTEGER"/> > primaryKey="false" type="INTEGER"/> > >
Yes. > > > > primaryKey="true" type="INTEGER"/> > primaryKey="false" type="INTEGER"/> > > >
> > regular number type NOT NULL (e.g. BIGINT NOT NULL) auto_increment ----> regular number type SERIAL (SERIAL is translated internally to CREATE SEQUENCE tablename_colname_seq; CREATE TABLE tablename ( colname integer DEFAULT nextval('tablename_colname_seq') NOT NULL ); according to http://www.postgresql.org/docs/7.3/static/datatype.html#DATATYPE-SERIAL) when using "sequence", we should also create the sequence in the SQL. What is left is to find out what "native" should really be. IMHO it should be equivalent "sequence" because "auto_increment" creates implicit object in the database outside user control. This is the patch that I've put on the list. There is also a note with "SERIAL": --- cut --- http://www.postgresql.org/docs/7.3/static/datatype.html#DATATYPE-SERIAL --- cut --- Note: Prior to PostgreSQL 7.3, serial implied UNIQUE. This is no longer automatic. If you wish a serial column to be UNIQUE or a PRIMARY KEY it must now be specified, just as with any other data type. --- cut --- http://www.postgresql.org/docs/7.3/static/datatype.html#DATATYPE-SERIAL --- cut --- so we might need to build a switch for pre-7.3 PostgreSQL databases. Regards Henning -- Dipl.-Inf. (Univ.) Henning P. Schmiedehausen INTERMETA GmbH hps@intermeta.de +49 9131 50 654 0 http://www.intermeta.de/ RedHat Certified Engineer -- Jakarta Turbine Development -- hero for hire Linux, Java, perl, Solaris -- Consulting, Training, Development "Fighting for one's political stand is an honorable action, but re- fusing to acknowledge that there might be weaknesses in one's position - in order to identify them so that they can be remedied - is a large enough problem with the Open Source movement that it deserves to be on this list of the top five problems." -- Michelle Levesque, "Fundamental Issues with Open Source Software Development" --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org For additional commands, e-mail: torque-dev-help@db.apache.org