Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique indexed column raise error "combination of attributes is not unique" #510

Closed
timnghg opened this issue Sep 15, 2023 · 1 comment
Closed

Comments

@timnghg
Copy link

timnghg commented Sep 15, 2023

Do you think if it is intended and unrelated to #474?

Masked GraphQL error (hash: 'Spwi2IARCeGK-TlghR5Q0EvBBtw', id: 'YVAYUTKYG2') 61 |         value: originalError.stack,
62 |         writable: true,
63 |         configurable: true,
64 |       });
65 |     } else if (Error.captureStackTrace != null) {
66 |       Error.captureStackTrace(this, GraphQLError);
          ^
GraphQLError: Attempted to call PgResource(Country).get({code}) at child field (TODO: which one?) but that combination of attributes is not unique (uniques: [{"isPrimary":true,"attributes":["id"],"extensions":{"tags":{}}}]). Did you mean to call .find() instead?
 path: "undefined"
      at new GraphQLError (~timnghg/proj1/node_modules/grafast/node_modules/graphql/error/GraphQLError.js:66:6)
      at Pe (~timnghg/proj1/node_modules/grafast/dist/index.js:238:739)
      at ~timnghg/proj1/node_modules/grafast/dist/index.js:238:207
      at compiledOutputPlan_object (:53:6)
      at compiledOutputPlan_array (:59:45)
      at compiledOutputPlan_object (:133:16)
      at compiledOutputPlan_object (:44:54)
      at ~timnghg/proj1/node_modules/grafast/dist/index.js:444:16405
      at x (~timnghg/proj1/node_modules/grafast/dist/index.js:444:64365)
      at A (~timnghg/proj1/node_modules/grafast/dist/index.js:444:71445)

image

@benjie
Copy link
Member

benjie commented Sep 15, 2023

A unique index is different from a unique constraint (The latter contains a unique index automatically). Indexes are generally optimisations, whereas constraints are something you declare about your data, so we only use constraints when determining uniqueness.

You can use the ALTER TABLE … ADD CONSTRAINT … UNIQUE USING INDEX … syntax to add a unique constraint using your existing unique index, which should be near-instant: https://www.postgresql.org/docs/current/sql-altertable.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants