Re: Are globally defined constants possible at all ? - Mailing list pgsql-general

From Darren Ferguson
Subject Re: Are globally defined constants possible at all ?
Date
Msg-id Pine.LNX.4.10.10206091300050.28897-100000@thread.crystalballinc.com
Whole thread Raw
In response to Re: Are globally defined constants possible at all ?  ("Nigel J. Andrews" <nandrews@investsystems.co.uk>)
List 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@postgresql.org)
>


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Are globally defined constants possible at all ?
Next
From: Gunther Schadow
Date:
Subject: Re: Help with data transfer please