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?
Topics
asked 4 months ago6 views
1 Answers
1
Accepted Answer
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.
answered 4 months ago
Relevant questions
RDS Postgresql migrate to Aurora Postgresql. Not showing "Aurora read replica" & "Migrate snapshot" options.
Accepted Answerasked 4 months agoChoosing RDS PostgreSQL over Aurora PostgreSQL
asked a month agoMigrate snapshot option disabled
asked a year agoChanges to connection handling with Aurora Postgres?
Accepted Answerasked 3 years agoUse PostgreSQL LIKE % wildcards with RDS Data API?
Accepted Answerasked 4 months agoPostGIS and Aurora compatibility: experience feedback
Accepted AnswerPostgreSQL "to_timestamp" function in RDS Data Service command batchExecuteStatement
asked 3 months agoInvoke lamda async from Aurora PostgreSQL
Accepted Answerasked 2 years agoMigrating RDS PostgreSQL to Aurora PostgreSQL in a different account
Accepted AnswerMove RDS postgresql database to Aurora Serverless
Accepted Answerasked 3 years ago
Worked like a charm! It also inspired me to try adding the %s to the parameter itself which also works
{ stringValue: '%' + variableFromUserInput + '%'}