Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

375
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda