on-internet
← Community

Get types of Postgres query result without executing query

Stack Overflow ·

Given a running Postgres cluster, how do I get an array of type names for the columns of an arbitrary query result? I'd prefer to avoid executing the query since the queries might be prepared meaning I can't run the queries without specifying concrete values for the prepared expressions. Example schema CREATE TYPE book_type AS ENUM ('FICTION', 'NONFICTION'); CREATE TABLE books ( book_id SERIAL PRIMARY KEY, book_type book_type NOT NULL DEFAULT 'FICTION' ); How do I get the type names of the columns for the returned rows for the following query? SELECT book_id, book_type, 'arbitrary_column', '20

Comments

Sign in or sign up to comment and upvote.

No comments yet.