Re: database field "pointer"

From: "Aasmund Midttun Godal" <postgresql(at)envisity(dot)com>
To: list-pgsql-general(at)dynworks(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: database field "pointer"
Date: 2001-10-10 21:52:35
Message-ID: 20011010215235.25818.qmail@ns.krot.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

CREATE TABLE coworkers (
id serial PRIMARY KEY,
name varchar(63)
);

CREATE TABLE email_types (
type VARCHAR(10) PRIMARY KEY
);

INSERT INTO email_types VALUES ('home');
INSERT INTO email_types VALUES ('work');

CREATE TABLE emails (
owner INTEGER REFERENCES coworkers,
type INTEGER REFERENCES email_types, --You could have a CHECK
--instead offcourse.
email VARCHAR(127) PRIMARY KEY,
preferred BOOLEAN,
UNIQUE(owner, preferred),
UNIQUE(type, owner)
);

No guarantees, I have not run it, but I think it should work.

On Wed, 10 Oct 2001 13:39:31 -0700, Jeff Davis <list-pgsql-general(at)dynworks(dot)com> wrote:
> I was wondering is there is a good method to make a database field a
> pointer, similar to C. Here is an example I made up of why this could be
> useful:
> Suppose I have a table 'coworkers' with 2 email address fields: work_email
> and home_email. It would be useful to have another field that was something
> like 'preferered_email' that pointed to one or the other. Then, updates would
> only need to happen once, and it would be easy to change back and forth.
> Tell me if there is some better, more sensible method to accomplish this
> task.
>
> Thanks,
> Jeff Davis
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

Aasmund Midttun Godal

aasmund(at)godal(dot)com - http://www.godal.com/
+47 40 45 20 46

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Feite Brekeveld 2001-10-10 22:03:40 Re: Performance problem with 50,000,000 rows
Previous Message Aasmund Midttun Godal 2001-10-10 21:52:20 Re: Conditional Adding to a Table