Re: Are globally defined constants possible at all ?

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


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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-06-09 16:12:04 Re: Are globally defined constants possible at all ?
Previous Message Alan Wayne 2002-06-09 15:34:53 Re: Help with data transfer please