programmatically retrieve details of a custom Postgres type

From: Konstantin Izmailov <pgfizm(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: programmatically retrieve details of a custom Postgres type
Date: 2022-11-11 04:02:12
Message-ID: CAAw-Mse9DJf1wUa650jix04VKWx=r-u8OkqX=XHJBeLDo42eXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,
I was unable to find how to get column names, sizes and types for a given
composite type.

Example. For a type defines as:
CREATE TYPE inventory_item AS (
name text,
supplier_id integer,
price numeric
);

I have a plpgsql stored proc that returns SETOF inventory_item (i.e. there
is no table with a column of this type).

I looked into the pg_type table but it only contains oid and typrelid for
the inventory_item type. I need a query that returns information about
structure of the composite type, i.e.:
ColumnName | ColumnType | ColumnSize
name | text | -1
supplier_id | integer | 4
price | numeric | 16

Is this possible? I'm executing queries via libpq...

Thank you!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2022-11-11 04:09:51 Re: programmatically retrieve details of a custom Postgres type
Previous Message Brad White 2022-11-11 03:25:53 Re: Setting up replication on Windows, v9.4