© 2026 Hedgehog Software, LLC

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

dynamic table name

how is that my code breaks:
const { tableName } = params;
const data = await dbPool.execute(sql`SELECT * FROM ${tableName}`);
const { tableName } = params;
const data = await dbPool.execute(sql`SELECT * FROM ${tableName}`);

but if i do this it works:
const data = await dbPool.execute(sql`SELECT * FROM account`);
const data = await dbPool.execute(sql`SELECT * FROM account`);


Error: Syntax error at or near "$1"
Location: 
- serverless/index.js:1336:74 (in a module at ./node_modules/.pnpm/@neondatabase+serverless@0.6.0)
- ./src/routes/(api)/api/[table]/+server.ts:13:16
- hooks.server.ts:9:10 (at ./src)

Details:
- Error Code: 42601
- Position: 15
- File: scan.l
- Line: 1188
- Routine: scanner_yyerror

Stack trace details are available in the following modules:
- @sveltejs/kit (at ./node_modules/.pnpm/@sveltejs+kit@1.24.1_svelte@4.2.0_vite@4.4.9)
- @neondatabase/serverless (at ./node_modules/.pnpm/@neondatabase+serverless@0.6.0)
Error: Syntax error at or near "$1"
Location: 
- serverless/index.js:1336:74 (in a module at ./node_modules/.pnpm/@neondatabase+serverless@0.6.0)
- ./src/routes/(api)/api/[table]/+server.ts:13:16
- hooks.server.ts:9:10 (at ./src)

Details:
- Error Code: 42601
- Position: 15
- File: scan.l
- Line: 1188
- Routine: scanner_yyerror

Stack trace details are available in the following modules:
- @sveltejs/kit (at ./node_modules/.pnpm/@sveltejs+kit@1.24.1_svelte@4.2.0_vite@4.4.9)
- @neondatabase/serverless (at ./node_modules/.pnpm/@neondatabase+serverless@0.6.0)
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

Similar Threads

Dynamic Table Names
Drizzle TeamDTDrizzle Team / help
12mo ago
Dynamic column name and insert
Drizzle TeamDTDrizzle Team / help
2y ago
How to get schema name from table name?
Drizzle TeamDTDrizzle Team / help
10mo ago
reference table name as const
Drizzle TeamDTDrizzle Team / help
11mo ago