Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

371
Views
Postgres "column $3 does not exist" when using parameters

I am running into an error when trying to use parameters as part of my query.

Noteworthy parts of my schema are:

name_tokens tsvector

cards.rarity card_rarity which is a custom enum created from: create type card_rarity as enum ('C', 'T', 'R', 'S', 'M', 'L', 'F', 'P');

The troublesome query is:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery("$1"::text)) AND
(cards.rarity = "$2"::card_rarity)
      ORDER BY cards.id;

with input of:

[ 'absorb & in', 'L' ]

When I run this, the error states:

UnhandledPromiseRejectionWarning: error: column "$3" does not exist.

When I run this query without parameters it works fine, ie:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery('absorb & in') AND
(cards.rarity = 'L')
      ORDER BY cards.id;

I would like to be able to utilize parameters as throwing user strings into a query directly can be dangerous.

Any ideas on why I'm getting this error? I'm assuming it's some incorrect formatting or use of quotes when I shouldn't or something. Any help is appreciated :)

Edit: It was suggested that I tried:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery($1::text)) AND
(cards.rarity = $2::card_rarity)
ORDER BY cards.id;

But when I do this, I get the following error: UnhandledPromiseRejectionWarning: error: could not determine data type of parameter $1

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

PostgreSQL uses double quotes for identifiers (such as table and column names) so this:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery("$1"::text)) AND
(cards.rarity = "$2"::card_rarity)
      ORDER BY cards.id;

contains two quoted identifiers "$1" and "$2" but no numbered placeholders.

If you want to use numbered placeholders, drop the double quotes:

SELECT cards.* FROM cards WHERE
(name_tokens @@ to_tsquery($1::text)) AND
(cards.rarity = $2::card_rarity)
      ORDER BY cards.id;

I'm not sure where it is getting "$3" from though, I'd guess that the error is coming from a different query with a similar quoting error.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!