Use PostgreSQL LIKE % wildcards with RDS Data API?

0

I'm using RDS Aurora Serverless with PostgreSQL compatibility. I'm trying to write a query that uses the PostgreSQL LIKE clause with percentage signs as wildcard operators. This is what I'm using right now:

SELECT * FROM products WHERE name LIKE '%:productName%'

and the productName gets passed into the RDS Data API through a stringValue field parameter (since it comes from user input).

{ name: 'productName', value: { stringValue: variableFromUserInput } }

This doesn't seem to be working since my query always succeeds but returns no results. Is this use case supported with the RDS Data API and am I using this correctly?

1 Antwort
1
Akzeptierte Antwort

A parameter inside the quoted value like that doesn't look right. I haven't used this API... but I have used many analogous ones.

Try a test like this:

SELECT * FROM products WHERE name LIKE '%' || :productName || '%'

That's a more typical way to reference your parameter.

beantwortet vor 2 Jahren
profile picture
EXPERTE
überprüft vor 10 Monaten
  • Worked like a charm! It also inspired me to try adding the %s to the parameter itself which also works { stringValue: '%' + variableFromUserInput + '%'}

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen