diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 78b0f43..90dbf52 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -4467,7 +4467,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid) " attname, " " format_type(atttypid, atttypmod), " " attnotnull, " - " pg_get_expr(adbin, adrelid), " + " pg_get_expr(adbin, 0), " " collname, " " collnsp.nspname " "FROM pg_class c " @@ -4488,7 +4488,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid) " attname, " " format_type(atttypid, atttypmod), " " attnotnull, " - " pg_get_expr(adbin, adrelid), " + " pg_get_expr(adbin, 0), " " NULL, NULL " "FROM pg_class c " " JOIN pg_namespace n ON " diff --git a/src/backend/catalog/information_schema.sql b/src/backend/catalog/information_schema.sql index f4e69f4..23b552c 100644 --- a/src/backend/catalog/information_schema.sql +++ b/src/backend/catalog/information_schema.sql @@ -299,7 +299,7 @@ CREATE VIEW attributes AS CAST(c.relname AS sql_identifier) AS udt_name, CAST(a.attname AS sql_identifier) AS attribute_name, CAST(a.attnum AS cardinal_number) AS ordinal_position, - CAST(pg_get_expr(ad.adbin, ad.adrelid) AS character_data) AS attribute_default, + CAST(pg_get_expr(ad.adbin, 0) AS character_data) AS attribute_default, CAST(CASE WHEN a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) THEN 'NO' ELSE 'YES' END AS yes_or_no) AS is_nullable, -- This column was apparently removed between SQL:2003 and SQL:2008. @@ -656,7 +656,7 @@ CREATE VIEW columns AS CAST(c.relname AS sql_identifier) AS table_name, CAST(a.attname AS sql_identifier) AS column_name, CAST(a.attnum AS cardinal_number) AS ordinal_position, - CAST(pg_get_expr(ad.adbin, ad.adrelid) AS character_data) AS column_default, + CAST(pg_get_expr(ad.adbin, 0) AS character_data) AS column_default, CAST(CASE WHEN a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) THEN 'NO' ELSE 'YES' END AS yes_or_no) AS is_nullable, diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index ea2f022..f1db915 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -8331,11 +8331,23 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.name); - printfPQExpBuffer(q, "SELECT tableoid, oid, adnum, " - "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc " - "FROM pg_catalog.pg_attrdef " - "WHERE adrelid = '%u'::pg_catalog.oid", - tbinfo->dobj.catId.oid); + if (fout->remoteVersion >= 80400) + { + printfPQExpBuffer(q, "SELECT tableoid, oid, adnum, " + "pg_catalog.pg_get_expr(adbin, 0) AS adsrc " + "FROM pg_catalog.pg_attrdef " + "WHERE adrelid = '%u'::pg_catalog.oid", + tbinfo->dobj.catId.oid); + } + else + { + /* Before 8.4, pg_get_expr does not allow 0 for its second arg */ + printfPQExpBuffer(q, "SELECT tableoid, oid, adnum, " + "pg_catalog.pg_get_expr(adbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS adsrc " + "FROM pg_catalog.pg_attrdef " + "WHERE adrelid = '%u'::pg_catalog.oid", + tbinfo->dobj.catId.oid); + } res = ExecuteSqlQuery(fout, q->data, PGRES_TUPLES_OK); diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index e5b3c1e..5a57db5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1728,7 +1728,7 @@ describeOneTableDetails(const char *schemaname, */ printfPQExpBuffer(&buf, "SELECT a.attname,"); appendPQExpBufferStr(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod)," - "\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)" + "\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, 0) for 128)" "\n FROM pg_catalog.pg_attrdef d" "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)," "\n a.attnotnull, a.attnum,");