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

Support IS DISTINCT #217

Open
gregorymfoster opened this issue Apr 26, 2022 · 1 comment
Open

Support IS DISTINCT #217

gregorymfoster opened this issue Apr 26, 2022 · 1 comment
Labels
enhancement New feature or request needs-parser-work

Comments

@gregorymfoster
Copy link

Describe the bug

Error raised when upserting using Typeorm.

To Reproduce

typescript:

async function upsertOrgs(orgs: Organization[], connection: DataSource) {
  await connection
    .createQueryBuilder()
    .insert()
    .into(GithubOrg)
    .values(
      orgs.map((org) => {
        const orgEntity = new GithubOrg();
        orgEntity.githubId = org.id;
        orgEntity.githubLogin = org.login;
        orgEntity.name = org.name || "";
        orgEntity.avatarURL = org.avatarUrl;
        return orgEntity;
      })
    )
    .orUpdate(["name", "avatarURL", "githubLogin"], ["githubId"], {
      // typeorm's version of upsert
      skipUpdateIfNoValuesChanged: true,
    })
    .execute();
}

Error output:

     QueryFailedError: 💔 Your query failed to parse.
This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.

👉 Failed query:

    INSERT INTO "github_org"("id", "githubId", "githubLogin", "name", "avatarURL", "createdAt", "updatedAt") VALUES ('C5aR4nTlebRqTmM7agZc', '2', 'org2_login', 'org2', 'google.com', DEFAULT, DEFAULT), ('vjFuYovcIvHAk6n5dNEz', '3', 'org3_login', 'org3', 'google.com', DEFAULT, DEFAULT) ON CONFLICT ( "githubId" ) DO UPDATE SET "name" = EXCLUDED."name", "avatarURL" = EXCLUDED."avatarURL", "githubLogin" = EXCLUDED."githubLogin"  WHERE ("github_org"."name" IS DISTINCT FROM EXCLUDED."name" OR "github_org"."avatarURL" IS DISTINCT FROM EXCLUDED."avatarURL" OR "github_org"."githubLogin" IS DISTINCT FROM EXCLUDED."githubLogin")  RETURNING "createdAt", "updatedAt";

💀 Syntax error at line 1 col 455:

  INSERT INTO "github_org"("id", "githubId", "githubLogin", "name", "avatarURL", "createdAt", "updatedAt") VALUES ('C5aR4nTlebRqTmM7agZc', '2', 'org2_login', 'org2', 'google.com', DEFAULT, DEFAULT), ('vjFuYovcIvHAk6n5dNEz', '3', 'org3_login', 'org3', 'google.com', DEFAULT, DEFAULT) ON CONFLICT ( "githubId" ) DO UPDATE SET "name" = EXCLUDED."name", "avatarURL" = EXCLUDED."avatarURL", "githubLogin" = EXCLUDED."githubLogin"  WHERE ("github_org"."name" IS DISTINCT
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ^
Unexpected kw_distinct token: "distinct". Instead, I was expecting to see one of the following:

    - A "kw_null" token
    - A "kw_not" token
    - A "kw_not" token
    - A "kw_true" token
    - A "kw_false" token


      at PostgresQueryRunner.query (node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
      at async InsertQueryBuilder.execute (node_modules/typeorm/query-builder/InsertQueryBuilder.js:106:33)

pg-mem version

2.3.5

@gregorymfoster
Copy link
Author

Thanks in advance for taking a look!

@oguimbal oguimbal changed the title Unexpected kw_distinct token: "distinct" Support IS DISTINCT May 5, 2022
@oguimbal oguimbal added enhancement New feature or request needs-parser-work labels May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-parser-work
Projects
None yet
Development

No branches or pull requests

2 participants