skip to Main Content

I am trying the following Postgresql query with Prisma’s $executeRaw function. But it is not returning the values inserted. Instead only returning the number of records inserted.

await prismaClient.$executeRaw(`
INSERT INTO table1 (name, place, animal, thing)
SELECT * FROM table2
WHERE place = 'California'
RETURNING *;
`);

It is returning

1

While I want the records inserted to be returned. How can that be done?

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to jian I got the answer

    await prismaClient.$queryRaw(`
      INSERT INTO table1 (name, place, animal, thing)
      SELECT * FROM table2
      WHERE place = 'California'
      RETURNING *;
    `);
    

  2. You are making insert and select from diferent tables. You are inserting in table1 and selecting from table2.
    It could be the problem.

    Try this.

    await prismaClient.$executeRaw(`
    INSERT INTO table1 (name, place, animal, thing)
    SELECT * FROM table1
    WHERE place = 'California';
    `);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search