Re: question about access custom enum type from C

From: Dmitry Markman <dmarkman(at)mac(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: question about access custom enum type from C
Date: 2022-09-01 05:31:27
Message-ID: 607438C1-0339-4859-A5C4-B01CC232AF7C@mac.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi David

as you suggested

create type first_type as enum ('red', 'green', 'brown', 'yellow', 'blue');
SELECT oid,typname,typlen,typtype from pg_type where typname='first_type'

returns everything I was looking for

thanks again, I think I’m all set

dm

> On Sep 1, 2022, at 12:49 AM, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>
> (I think this is a better question for the general mailing list)
>
> On Thu, 1 Sept 2022 at 16:28, Dmitry Markman <dmarkman(at)mac(dot)com> wrote:
>>
>> Hi, when I’m trying to access values of my custom enum type I created with
>>
>> create type colors as enum ('red', 'green', 'brown', 'yellow', 'blue');
>>
>> I’m getting oid as 16387 and I can see it stored as a chars
>
> You might see the names if you query the table, but all that's stored
> in the table is the numerical value.
>
> https://www.postgresql.org/docs/current/datatype-enum.html states "An
> enum value occupies four bytes on disk.".
>
>> is number 16387 is always OID for enum type?
>
> I'm not sure where you got that number from. Perhaps it's the oid for
> the pg_type record? The following would show it.
>
> select oid,typname from pg_type where typname = 'colors';
>
>> if not how I can get information about type of the result if it’s custom enum type
>
> I'm not sure what you mean by "the result". Maybe pg_typeof(column)
> might be what you want? You can do: SELECT pg_typeof(myenumcol) FROM
> mytable;
>
> David

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2022-09-01 05:31:46 Re: FOR EACH ROW triggers, on partitioend tables, with indexes?
Previous Message Kyotaro Horiguchi 2022-09-01 05:17:58 Re: pg15b3: recovery fails with wal prefetch enabled