Skip to main content
Deno 2 is finally here 🎉️
Learn more
Latest
variable columnInfoQuery
import { columnInfoQuery } from "https://deno.land/x/denogres@v4.0.1/src/queries/introspection.ts";

type

` WITH enum_table as ( select n.nspname as enum_schema, t.typname as enum_name, string_agg(e.enumlabel, ', ') as enum_value from pg_type t join pg_enum e on t.oid = e.enumtypid join pg_catalog.pg_namespace n ON n.oid = t.typnamespace group by enum_schema, enum_name ) SELECT tables.schemaname, class.relname AS table_name, attname AS column_name, --pg_type.typname AS column_type, CASE WHEN enum_name is not null THEN ('enum: '|| enum_name) ELSE pg_type.typname END AS column_type, pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid) col_default, --convert from nodeToString rep to SQL expr attr.attnotnull AS not_null, enum_value, character_maximum_length FROM pg_attribute attr INNER JOIN pg_class class on attr.attrelid = class.oid INNER JOIN pg_tables tables on class.relname = tables.tablename INNER JOIN pg_type ON attr.atttypid = pg_type.oid LEFT JOIN pg_attrdef ON attr.attrelid = pg_attrdef.adrelid AND attr.attnum = pg_attrdef.adnum -- Column default vaules LEFT JOIN enum_table ON pg_type.typname = enum_name LEFT JOIN information_schema.columns ISC ON tables.schemaname = ISC.table_schema AND tables.tablename = ISC.table_name AND attr.attname = ISC.column_name WHERE tables.schemaname NOT IN ('pg_catalog', 'information_schema') AND attr.attnum > -1 ORDER BY table_name`