0

Using PostgreSQL 9.6.9

It appears that constraints are not available when using the Postgres foreign data wrapper https://github.com/postgres/postgres/blob/e1ae40f381d0582981b1e63856bd4b060cfe2d53/src/test/regress/expected/foreign_data.out#L692-L711.

  • primary key constraints are not supported on foreign tables
  • foreign key constraints are not supported on foreign tables
  • unique constraints are not supported on foreign tables

I want to run a query that groups by a primary key and selects some other columns in the same table. The query does not work when the primary key constraint is absent. https://www.postgresql.org/docs/current/sql-select.html#SQL-GROUPBY.

A functional dependency exists if the grouped columns (or a subset thereof) are the primary key of the table containing the ungrouped column.

The easy solution would be to add the other columns to the GROUP BY but tech debt makes this another challenge.

Even if the constraint cannot be enforced, is there a way to mimic or partially enable the constraint so the query works?

1 Answer 1

1

No, you will have to add the other columns to the GROUP BY clause. I assume by "tech debt" you are referring to the need to type all the columns. Use a smart text editor!

Sign up to request clarification or add additional context in comments.

2 Comments

tech_debt == bad_orm
My condolences.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.