#Query Parameters with pg

1 messages · Page 1 of 1 (latest)

cobalt scaffold
#

Hey, I am using pg for communicating with PostgreSQL. This works normally in Node:

const newUser = await pool.query(CREATE_NEW_USER_QUERY, [
  username,
  displayName,
  email,
  hashedPassword,
]);

Where CREATE_NEW_USER_QUERY is:

export const CREATE_NEW_USER_QUERY =
  'INSERT INTO Users (username, display_name, email, password) VALUES ($1, $2, $3, $4) RETURNING *';

$1 would get replaced with the value of username in this example. But I am getting this error:

error: there is no parameter $1
 code: "42P02"
      at /home/tainted/Coding/Web/scholatarium/server/node_modules/pg-pool/index.js:45:4
      at processTicksAndRejections (:1:2602)
      at _final (node:net:326:16)
      at callFinal (node:stream:2763:44)
      at prefinish (node:stream:2786:44)
      at finishMaybe (node:stream:2793:48)
      at node:stream:2726:150
      at /home/tainted/Coding/Web/scholatarium/server/node_modules/pg/lib/connection.js:198:6
      at afterWrite (node:stream:2662:46)
      at processTicksAndRejections (:1:2602)

Implying that I did not specify the parameters. This occurs with bun run too.

#

I am using "pg": "^8.11.3", which is the latest version of pg.

crisp bridgeBOT