© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
54 replies
jakeleventhal

How to use sql template strings

await tx.update(inventoryItems).set({
        masterProductId: sql`
        CASE
          ${chunk
            .map((update) => `WHEN id in (${update.ids.map((id) => `'${id}'`)}) THEN '${update.masterProductId}'`)
            .join('\n')}
        END
        `
      });
await tx.update(inventoryItems).set({
        masterProductId: sql`
        CASE
          ${chunk
            .map((update) => `WHEN id in (${update.ids.map((id) => `'${id}'`)}) THEN '${update.masterProductId}'`)
            .join('\n')}
        END
        `
      });

Query: update "InventoryItem" set "masterProductId" = 
        CASE
          $1
        END
         -- params: ["WHEN id in ('450a5c19-af32-4ee6-a565-2ba6b4664549','742a257d-23da-4092-bfa6-ba7d8ba6a4f8','450a5c19-af32-4ee6-a565-2ba6b4664549','742a257d-23da-4092-bfa6-ba7d8ba6a4f8','ea8ecac1-c73a-4590-8cda-7ce4344a95ca','03dca948-f970-4a42-83c8-999e1a61e2b6') THEN '1232a182-035c-4534-bc4b-402f9a00bced'"]
Jan 11, 12:09:45PM debug: req.url /api/master-products/bulk/map/save 
Jan 11, 12:09:45PM error: PostgresError: syntax error at or near "END"
Query: update "InventoryItem" set "masterProductId" = 
        CASE
          $1
        END
         -- params: ["WHEN id in ('450a5c19-af32-4ee6-a565-2ba6b4664549','742a257d-23da-4092-bfa6-ba7d8ba6a4f8','450a5c19-af32-4ee6-a565-2ba6b4664549','742a257d-23da-4092-bfa6-ba7d8ba6a4f8','ea8ecac1-c73a-4590-8cda-7ce4344a95ca','03dca948-f970-4a42-83c8-999e1a61e2b6') THEN '1232a182-035c-4534-bc4b-402f9a00bced'"]
Jan 11, 12:09:45PM debug: req.url /api/master-products/bulk/map/save 
Jan 11, 12:09:45PM error: PostgresError: syntax error at or near "END"


this should be resolving to valid sql
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

How to specify type using sql template
Drizzle TeamDTDrizzle Team / help
3y ago
Non hardcoded strings in sql()
Drizzle TeamDTDrizzle Team / help
9mo ago
sql operator with array of strings
Drizzle TeamDTDrizzle Team / help
2y ago
How to use drizzle as a sql builder?
Drizzle TeamDTDrizzle Team / help
3y ago