in node, i'm creating the following query:
let sql_query = "\
SELECT \
... \
WHERE \
FACILITY_ID = $1 \
AND (EVENT_START_TIME_UNIX_MS < $2) \
AND (EVENT_END_TIME_UNIX_MS > $3) \
AND (LOWER(DESCRIPTION_TEXT) ~* '\yden\y')"
that fourth line is doing a word boundary regex for the term "den" but i need it to be parameterized like the preceding lines. i tried the below but it doesn't work.
AND (LOWER(DESCRIPTION_TEXT) ~* '\y$4\y')
i also tried this:
AND (LOWER(DESCRIPTION_TEXT) ~* $4)
where $4 is set to '\yden\y'. but that didn't work either.
thanks for any tips.
~* $4instead and pass the full pattern as the parameter value. Parameterized queries don't use string interpolation. The parameter values never become part of the query text. The database compiles the query into a parameterized execution plan that's executed using the parameter values. That's why SQL injection and formatting errors are avoided. The parameter values remain strongly typed, outside the query itself, even when the execution plan gets executed. Unless of course you use the parameter values to construct and execute dynamic SQL inside the query text~*is case-insensitive, there's no reason to useLOWER(...). This could prevent the database from using trigram indexes to accelerate the regex search