1

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?

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

@dgamma3 : You're welcome. Please check. I've simplified the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.