Postgres 13.12: error: { error: column cnst.consrc does not exist

97 views Asked by At

I'm using AWS RDS postgres 13.12 with Node js typeorm 0.2.19.

error: { error: column cnst.consrc does not exist
query failed: SELECT "ns"."nspname" AS "table_schema", "t"."relname" AS "table_name", "cnst"."conname" AS "constraint_name", CASE "cnst"."contype" WHEN 'x' THEN pg_get_constraintdef("cnst"."oid", true) ELSE "cnst"."consrc" END AS "expression", CASE "cnst"."contype" WHEN 'p' THEN 'PRIMARY' WHEN 'u' THEN 'UNIQUE' WHEN 'c' THEN 'CHECK' WHEN 'x' THEN 'EXCLUDE' END AS "constraint_type", "a"."attname" AS "column_name" FROM "pg_constraint" "cnst" INNER JOIN "pg_class" "t" ON "t"."oid" = "cnst"."conrelid" INNER JOIN "pg_namespace" "ns" ON "ns"."oid" = "cnst"."connamespace" LEFT JOIN "pg_attribute" "a" ON "a"."attrelid" = "cnst"."conrelid" AND "a"."attnum" = ANY ("cnst"."conkey") WHERE "t"."relkind" = 'r' AND (("ns"."nspname" = 'dbname' AND "t"."relname" = 'users'))

I tried to upgrade typeorm extension to 0.2.45 and 0.3.6 as latest version is throwing error. I tried to regenerate same error in local system and it is happening while we dont have any tables inside schema that time it is throwing error with it. But in local upgrading TypeOrm extension version it resolved error. But when I tried same solution on server it throw different error like

QueryFailedError: relation "dbname.datamod" does not exist
 
      at new QueryFailedError (src/error/QueryFailedError.ts:9:9)
      at Query.callback (src/driver/postgres/PostgresQueryRunner.ts:178:30)
      at Query.handleError (node_modules/pg/lib/query.js:146:19)
      at Connection.connectedErrorMessageHandler (node_modules/pg/lib/client.js:236:17)
      at Connection.emit (node:events:513:28)
      at Connection.emit (node:domain:489:12)
      at Socket.<anonymous> (node_modules/pg/lib/connection.js:121:12)
      at Socket.emit (node:events:513:28)
      at Socket.emit (node:domain:489:12)
      at addChunk (node:internal/streams/readable:315:12)
 

Downgrading Postgres may solve this issue but issue is only on development server and same configuration is working on higher environment.

1

There are 1 answers

0
Erwin Brandstetter On

The obsolete column pg_constraint.consrc was removed from the system catalog with Postgres 12.

The obsolete reference "cnst"."consrc" would have to be replaced with ...

  • pg_get_expr(cnst.conbin, cnst.conrelid) for the expression of a CHECK constraint
  • or pg_get_constraintdef(cnst.oid) to print the whole constraint (not only CHECK).

See:

It would make sense that updating the extension silences the error, since it's reasonable to expect a current version to include that update. (The new expression also works for older Postgres versions.)