Re: Suggestion for Enum Support Functions

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: toronto programmer <torontoprogrammer(at)yahoo(dot)ca>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Suggestion for Enum Support Functions
Date: 2007-06-20 13:38:57
Message-ID: 46792DF1.2050300@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

toronto programmer wrote:
> Dear Postgres developers,
>
> I have been working with Oracle for few years now in my work, and I
> tried some free databases for a project that I'm developing for my own
> use, I have tried H2,FireBird and postgres, and found the last to be
> the most stable and feature-rich, so thanks for all the good work.
>
> I have read the 8.3 documentation, and with reference to Enum Support
> Functions found on
> http://developer.postgresql.org/pgdocs/postgres/functions-enum.html, i
> think it is useful to add 2 functions, enum_after(anyenum) and
> enum_before(anyenum), so having :
>
> CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
> enum_after('orange'::rainbow) will return 'yellow'
> enum_after('purple'::rainbow) will return an error
> enum_before('purple'::rainbow) will return 'blue'
>
> a good to have
> function would be enum_size(anyenum) which would return 6 in the previous example
> that will be helpful in dealing with enums

You could easily create these for yourself, of course. For example:

create or replace function enum_size(anyenum)
returns int as
$$ select array_upper(enum_range($1),1) $$
language sql;

Successor and predecessor functions would be a bit more work, but not
hard. I don't think they should error out at the range extremes, though.
Perhaps returning NULL would be better.

We could look at adding these as builtins for 8.4, but it's too late now
to add them for 8.3. Besides, I think we need to see how enums are used
in the field before deciding if any extensions are needed.

cheers

andrerw

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Marko Kreen 2007-06-20 13:50:24 Re: PG-MQ?
Previous Message Jeroen T. Vermeulen 2007-06-20 13:05:57 Re: PG-MQ?