Thursday, October 6, 2011

Postgresql get column names of a table / dblink

Postgresql get column names of a table

I'm saving this query for future reference, It might come in handy someday:

[sourcecode language="sql"]

SELECT

a.attname as "Column",

pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
FROM
pg_catalog.pg_attribute a
WHERE
a.attnum > 0
AND NOT a.attisdropped
AND a.attrelid = (
SELECT c.oid
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname ~ '^(foo)$'
AND pg_catalog.pg_table_is_visible(c.oid)
)
;
[/sourcecode]
Taken from here:


dblink

I've been looking forward to try dblink, but I haven't had the time. I found a very useful overview.

No comments:

Post a Comment