Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no parameter $1 #1

Closed
Khaled-Ch opened this issue Sep 27, 2021 · 1 comment
Closed

There is no parameter $1 #1

Khaled-Ch opened this issue Sep 27, 2021 · 1 comment

Comments

@Khaled-Ch
Copy link

Khaled-Ch commented Sep 27, 2021

I am using node-postgress version 0.6.2
When I am running the following query

await pool.query(
'SELECT id, email from user where name = $1',
['jone'],
);

I am getting this error

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Message {
name: 'error',
message: 'there is no parameter $1',
severity: 'ERROR',
code: '42P02',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: '/home/ec2-user/padb/src/pg/src/backend/parser/parse_expr.c',
line: '477',
routine: 'transformExpr'
})

However, If I run the same query with this format it works as expected

await pool.query(
SELECT id, email from user where name = '${username}'
);

NodeJs version is v14.17.3

@fuxingZhang
Copy link
Owner

This repository does not support Parameterized query.

You can use the best library(9.9k star +):
https://github.com/brianc/node-postgres

docs:
https://node-postgres.com/

const { Client } = require('pg')
const client = new Client()
await client.connect()
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
await client.end()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants