pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedINT OR VARCHAR
3+ messages / 2 participants
[nested] [flat]
* INT OR VARCHAR
@ 2001-12-05 20:41 Martín Marqués <martin@bugs.unl.edu.ar>
2001-12-05 21:03 ` Re: INT OR VARCHAR Aasmund Midttun Godal <postgresql@envisity.com>
0 siblings, 1 reply; 3+ messages in thread
From: Martín Marqués @ 2001-12-05 20:41 UTC (permalink / raw)
To: pgsql-sql
I have a table that will be populated with machines of a net we have. And we
have more then 1 domain, so we thought about putting a seperate table with
the domains, and a reference in the nodes table to the apropiate domain.
The question is, should I put an SERIAL field in the domain table and use
that as the PK, and use an INT reference in the nodes table?
Or is it a good idea to just leave the domain name (a CHAR(30) field) in the
domain table and make the node.domain a CHAR(30) that references to
domain.name?
What would be the best approche?
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
-----------------------------------------------------------------
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: INT OR VARCHAR
2001-12-05 20:41 INT OR VARCHAR Martín Marqués <martin@bugs.unl.edu.ar>
@ 2001-12-05 21:03 ` Aasmund Midttun Godal <postgresql@envisity.com>
2001-12-05 21:19 ` Re: INT OR VARCHAR Martín Marqués <martin@bugs.unl.edu.ar>
0 siblings, 1 reply; 3+ messages in thread
From: Aasmund Midttun Godal @ 2001-12-05 21:03 UTC (permalink / raw)
To: martin@bugs.unl.edu.ar; +Cc: pgsql-sql
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.
Regards,
Aasmund.
On Wed, 5 Dec 2001 17:41:40 -0300, Martín Marqués <martin@bugs.unl.edu.ar> wrote:
> I have a table that will be populated with machines of a net we have. And we
> have more then 1 domain, so we thought about putting a seperate table with
> the domains, and a reference in the nodes table to the apropiate domain.
>
> The question is, should I put an SERIAL field in the domain table and use
> that as the PK, and use an INT reference in the nodes table?
> Or is it a good idea to just leave the domain name (a CHAR(30) field) in the
> domain table and make the node.domain a CHAR(30) that references to
> domain.name?
> What would be the best approche?
>
> 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
> -----------------------------------------------------------------
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
Aasmund Midttun Godal
aasmund@godal.com - http://www.godal.com/
+47 40 45 20 46
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: INT OR VARCHAR
2001-12-05 20:41 INT OR VARCHAR Martín Marqués <martin@bugs.unl.edu.ar>
2001-12-05 21:03 ` Re: INT OR VARCHAR Aasmund Midttun Godal <postgresql@envisity.com>
@ 2001-12-05 21:19 ` Martín Marqués <martin@bugs.unl.edu.ar>
0 siblings, 0 replies; 3+ messages in thread
From: Martín Marqués @ 2001-12-05 21:19 UTC (permalink / raw)
To: Aasmund Midttun Godal <postgresql@envisity.com>; +Cc: 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@unl.edu.ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-12-05 21:19 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-12-05 20:41 INT OR VARCHAR Martín Marqués <martin@bugs.unl.edu.ar>
2001-12-05 21:03 ` Aasmund Midttun Godal <postgresql@envisity.com>
2001-12-05 21:19 ` Martín Marqués <martin@bugs.unl.edu.ar>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox