You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpostgresfrom"postgres";constsql=postgres(process.env.DS_DB??"",{debug: true,});consttest=async()=>{constroleName="test_role";constpassword="test_password";constdescribeResult=awaitsql`CREATE ROLE ${sql(roleName)} WITH LOGIN PASSWORD ${password}`.describe();console.log("zz",describeResult);};test();
This produces error:
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
PostgresError: syntax error at or near "$1"
at ErrorResponse (/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:788:26)
at handle (/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:474:6)
at Socket.data (/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:315:9)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readarble:376:12)
at readableAddChunk (node:internal/streams/readable:349:9)
at Readable.push (node:internal/streams/readable:286:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at new Query (/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/query.js:35:9)
at sql (/<redacted>/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/index.js:112:11)
at test (/<redacted>/lib/dbtest.ts:11:35)
at /<redacted>/lib/dbtest.ts:18:1
at evalModule (/<redacted>/node_modules/.pnpm/[email protected]/node_modules/jiti/dist/jiti.js:1:247313)
at jiti (/<redacted>/node_modules/.pnpm/[email protected]/node_modules/jiti/dist/jiti.js:1:245241)
at Object.<anonymous> (/<redacted>/node_modules/.pnpm/[email protected]/node_modules/jiti/bin/jiti.js:16:1)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 {
severity_local: 'ERROR',
severity: 'ERROR',
code: '42601',
position: '45',
file: 'scan.l',
line: '1188',
routine: 'scanner_yyerror',
query: 'CREATE ROLE "test_role" WITH LOGIN PASSWORD $1',
parameters: [ 'test_password' ],
args: [ Identifier { value: '"test_role"' }, 'test_password' ],
types: [ 0 ]
}
But, if I do it like this:
awaitsql`CREATE ROLE ${sql(roleName)} WITH LOGIN PASSWORD ${sql.unsafe(`'${password}'`)}`;
then it works and produces valid query ..... LOGIN PASSWORD 'test_password'
Am I doing something wrong?
The text was updated successfully, but these errors were encountered:
Code:
This produces error:
But, if I do it like this:
then it works and produces valid query
..... LOGIN PASSWORD 'test_password'
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: