This message was deleted.
# prisma-client
s
This message was deleted.
m
It generates
Copy code
-- first query: upsert all Skills
        INSERT INTO "Skill"
          $1   -- columns
          VALUES ($2,$3)
          ON CONFLICT ("name") DO UPDATE SET "name"=EXCLUDED."name"
          RETURNING *;
Copy code
Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near "$1"`
a
I think the syntax for values is incorrect --
if you're entering multiple, it's generally something like:
Copy code
VALUES
('SkillName', true, 'SkillDescription'),
('SkillName', true, 'SkillDescription'),
('SkillName', true, 'SkillDescription'),
though candidly i've had a really hard time coming up with the syntax for a similar upsert need
(I believe there are a handful of open issues requesting this without having to resort to queryRaw -- I'm actually using knex in addition to Prisma when dealing with batch inserts because it's easier for batch stuff in a project of mine
m
Copy code
-- first query: upsert all Skills
        INSERT INTO "Skill"
          (name)
          VALUES $1,$2
          ON CONFLICT ("name") DO UPDATE SET "name"=EXCLUDED."name"
          RETURNING *;
Raw query failed. Code:
42601
. Message:
db error: ERROR: syntax error at or near “$1”
was trying
Copy code
const skillsUpsertResult = await this.prisma.$queryRaw<Skill[]>`
    -- first query: upsert all Skills
    INSERT INTO "Skill"
      (name)
      VALUES ${Prisma.join(skillNames.map((s) => `(${s})`))}
      ON CONFLICT ("name") DO UPDATE SET "name"=EXCLUDED."name"
      RETURNING *;`
ok I think I got that solved:
Copy code
const skillsUpsertResult = await this.prisma.$queryRaw<Skill[]>`
    -- first query: upsert all Skills
    INSERT INTO "Skill"
      (name)
      VALUES ${Prisma.join(skillNames.map((s) => Prisma.sql`(${s})`))}
      ON CONFLICT ("name") DO UPDATE SET "name"=EXCLUDED."name"
      RETURNING *;`
🙌 1