hdbc/hdbc-postgresql — Issue #20: It's not possible to escape argument substitution
Author: molysgaard
Created: 2012-02-02 09:50:37+00:00
State: open

I want to write this query for PostgreSQL in HDBC:

SELECT * FROM my_table WHERE (key_value ? 'name');

Here my_table is a table that contains a PostgreSQL HStore column: key_value.
The thing is that the '?' is a membership operator and should not be substituted for an argument.

When written in HDBC like this:

quickQuery' conn "SELECT * FROM my_table WHERE (key_value ? 'name')" []

HDBC complains that it can't substitute '?' for an argument when there are none. There should be some way to escape substitution. Would it be possible to escape substitution if a '?' is prepended by a '\'.
That would make the query look like this:

quickQuery' conn "SELECT * FROM my_table WHERE (key_value \\? 'name')" []

About HStore:
In a HStore column you can store Data.Map String String.
The '?' operator is a membership operator for the HStore column. It checks if a given key exists in the store.