Received: from bugs.unl.edu.ar (bugs.unl.edu.ar [168.96.132.208]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fB5LKqm01389 for ; Wed, 5 Dec 2001 16:20:53 -0500 (EST) (envelope-from martin@bugs.unl.edu.ar) Received: from localhost (localhost [127.0.0.1]) by bugs.unl.edu.ar (Postfix) with ESMTP id 1C54DFBE0; Wed, 5 Dec 2001 18:19:13 -0300 (GMT) Received: by bugs.unl.edu.ar (Postfix, from userid 1004) id 5DCC0FA61; Wed, 5 Dec 2001 18:19:12 -0300 (GMT) Content-Type: text/plain; charset="iso-8859-1" From: =?iso-8859-1?q?Mart=EDn=20Marqu=E9s?= To: "Aasmund Midttun Godal" Subject: Re: INT OR VARCHAR Date: Wed, 5 Dec 2001 18:19:11 -0300 X-Mailer: KMail [version 1.3.2] Cc: pgsql-sql@postgresql.org References: <20011205204142.AA74CFA61@bugs.unl.edu.ar> <20011205210356.25680.qmail@213-145-170-138.dd.nextgentel.com> In-Reply-To: <20011205210356.25680.qmail@213-145-170-138.dd.nextgentel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <20011205211912.5DCC0FA61@bugs.unl.edu.ar> X-Virus-Scanned: by AMaViS snapshot-20011031 X-Archive-Number: 200112/57 X-Sequence-Number: 5880 On Mié 05 Dic 2001 18:03, Aasmund Midttun Godal wrote: > I am not sure what you are trying to do, but if you have a tree structure > you will have to use an id column e.g.: > > CREATE TABLE domain ( > id SERIAL PRIMARY KEY, > name TEXT CHECK (lower(name) ~ '[a-z0-9]([a-z0-9-]*[a-z0-9])?', > parent INTEGER REFERENCES domain, > UNIQUE (parent, name) > ); > > > If you do not have a tree structure, I would recommend using a natural > primary key in stead of serializing it. Bear in mind though - you should > always have a primary key. I would also recommend creating a couple of > functions to build a fully qualified domain name from the id. No, it's not a tree structure. The question is why not serialize it? I vote for not serializing it because when I get the data from the database, I don't have to join the 2 tables (the domain name is on both tables). CREATE TABLE domain ( name CHAR(30) PRIMARY KEY ); CREATE TABLE nodes ( id SERIAL, name CHAR(30), domain CHAR(30) REFERENCES domain ("name") ); This is a better approach then putting a SERIAL value to the domain table and making nodes.domain reference to that SERIAL? Why? Saludos... :-) -- Porqué usar una base de datos relacional cualquiera, si podés usar PostgreSQL? ----------------------------------------------------------------- Martín Marqués | mmarques@unl.edu.ar Programador, Administrador, DBA | Centro de Telematica Universidad Nacional del Litoral -----------------------------------------------------------------