dgamma3
dgamma3

Reputation: 2371

Getting attribute of type postgres

lets say I create a type like this:

CREATE TYPE books AS (
  book_id NUMERIC
, row_num NUMERIC
);

I want to write a query that returns me the attributes (book_id, row_num) of books.

I am not sure how to do this?

Upvotes: 1

Views: 457

Answers (1)

Kaushik Nayak
Kaushik Nayak

Reputation: 31648

Use this

SELECT array_agg(a.attname) 
  FROM   pg_class c JOIN pg_attribute a 
         ON c.oid = a.attrelid
WHERE  c.relname = 'books'; 

Result

     array_agg
-------------------
 {book_id,row_num}
(1 row)

Upvotes: 1

Related Questions