Re: INT OR VARCHAR

From: Martín Marqués <martin(at)bugs(dot)unl(dot)edu(dot)ar>
To: "Aasmund Midttun Godal" <postgresql(at)envisity(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: INT OR VARCHAR
Date: 2001-12-05 21:19:11
Message-ID: 20011205211912.5DCC0FA61@bugs.unl.edu.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)unl(dot)edu(dot)ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Wieck 2001-12-05 21:26:47 Re: PL/pgSQL examples NOT involving functions
Previous Message Stephan Szabo 2001-12-05 21:07:20 Re: Getting matching and non-matching results (long)