Re: Are globally defined constants possible at all ?

From: Darren Ferguson <darren(at)crystalballinc(dot)com>
To: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
Cc: Andrew Sullivan <andrew(at)libertyrms(dot)info>, pgsql-general(at)postgresql(dot)org
Subject: Re: Are globally defined constants possible at all ?
Date: 2002-06-09 17:03:03
Message-ID: Pine.LNX.4.10.10206091300050.28897-100000@thread.crystalballinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The only way you can do this is basically say 0 is SOFTWARE and 1 is
HARDWARE. This can just be inferred or you could have a dictionary table
seperate that has

CREATE dictionary_table (
KindID integer not null default nexval('sequence_name'),
name varchar(32) not null,
....
CONSTRAINT dt_pk PRIMARY KEY(KindID),
CONSTRAINT dt_un UNIQUE(name)
);

The choice is up to yourself and you can make KindID in foo reference the
dictionary table

HTH

Darren Ferguson

On Sun, 9 Jun 2002, Nigel J. Andrews wrote:

>
> On Fri, 7 Jun 2002, Andrew Sullivan wrote:
>
> > On Fri, Jun 07, 2002 at 05:29:27PM -0400, Gregory Seidman wrote:
> > >
> > > Er, could you expand on that? Are you suggesting something like this:
> > >
> > > CREATE TABLE Foo (
> > > KindID int,
> > > ...
> > > CONSTRAINT fooenum
> > > CHECK KindID IN ('SOFTWARE', 'HARDWARE')
> > > );
> >
> > Yes. Except I think you need another set of parentheses
> >
> > check("KindID" IN ('SOFTWARE','HARDWARE'))
>
> Can this be done? What are the integers derived from the strings and is there
> any chance of them not being unique?
>
> The following message shows a what I think is a more consistent way of writing
> it but I still can't see how use of CHECK makes the mapping from a textual type
> to integer.
>
>
> Darren Ferguson wrote on Sun Jun 9 at 16:38:53 2002
> >
> >Check can be used in the following way
> >
> >status VARCHAR(32) DEFAULT 'new' NOT NULL
> > CHECK(status IN ('new','read','deleted')),
> >
> >On Fri, 7 Jun 2002, Nigel J. Andrews wrote:
> >
> >
> >> On Fri, 7 Jun 2002, Andrew Sullivan wrote:
> >> >
> >> > On Fri, Jun 07, 2002 at 02:36:35PM -0400, Gregory Seidman wrote:
> >> >
> >> > > I am in the exact same position. I have a number of things which are
> >> > > essentially enumerations. Since PostgreSQL does not support an
> enumeration
> >> > > type (MySQL does, but then it doesn't have a proper boolean type), I
> have a
> >> >
> >> > Why don't you use a CHECK contraint? That's the standard way to do
> >> > it.
> >>
> >> I wonder if you could explain how to use CHECK for this please? I'm having a
> >> little trouble thinking in that manner but then I've only seen and used the
> >> table associating name and value method before and so am a little biased.
>
>
> --
> Nigel J. Andrews
> Director
>
> ---
> Logictree Systems Limited
> Computer Consultants
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gunther Schadow 2002-06-09 17:52:04 Re: Help with data transfer please
Previous Message Tom Lane 2002-06-09 16:12:04 Re: Are globally defined constants possible at all ?