anse1 / emacs-libpq

An Emacs 25 module for accessing postgres via libpq.
GNU General Public License v3.0
22 stars 3 forks source link

progn: SQL error: "ERROR: invalid regular expression: quantifier operand invalid #26

Closed gnusupport closed 2 years ago

gnusupport commented 2 years ago

I do expect that library automatically escapes whatever is necessary when it comes to providing parameters. Here below I get error as "+" is considered quantifier. Am I supposed to escape this before providing it as parameter?

(pq:query cf-db "SELECT commlines_people FROM commlines WHERE commlines_value ~ $1 AND (SELECT addresses_people FROM addresses WHERE addresses_countries = $2) != commlines_people" "+256" 224)

progn: SQL error: "ERROR:  invalid regular expression: quantifier operand invalid
anse1 commented 2 years ago

GNU Support writes:

I do expect that library automatically escapes whatever is necessary when it comes to providing parameters.

parameters for the placeholders are transmitted seperately in the postgresql client protocol, so no escaping is needed.

Here below I get error as "+" is considered quantifier. Am I supposed to escape this before providing it as parameter?

No, but you're just supposed to provide a valid regular expression when using regular expression operators in your query :-)

Both, escaping "+" and not escaping it can yield a valid regular expression. E.g., 2+56 is valid and matches the string "222256", 2+56 is valid as well and matches the string "2+56". However, +256 is not a valid regular expression at all and that is what postgresql complains about here.

Details on regular expressions: https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-SIMILARTO-REGEXP

gnusupport commented 2 years ago

Alright, I was thinking library would handle it magically. Thanks.