pghstore-clj icon indicating copy to clipboard operation
pghstore-clj copied to clipboard

Escaping double-quotes with hstore.

Open sparkertime opened this issue 12 years ago • 2 comments

Typically a double-quote is no big deal inside of a PostgreSQL string - e.g. 'Hello "World"' is a perfectly fine value and doesn't need escaping.

However, when inserted into an hstore value, this isn't the case. Double-quotes cause a big problem.

Would a patch that substitutes these be accepted?

sparkertime avatar Nov 14 '12 19:11 sparkertime

So you'd like to single quote the hstore values instead of double quoting? I'm confused how that would help the situation, especially if you start inserting strings that contain single quotes. Am I understanding the problem correctly?

Do you have an error you can show? I'm still a little fuzzy on the problem.

blakesmith avatar Nov 14 '12 19:11 blakesmith

No, I'd just like to escape double quotes in the SQL. Currently, something like so doesn't work:

(to-hstore {:somekey "some\"value"})
; => #<PGobject "somekey"=>"some"value">
; => PostgreSQL will barf on that

Whereas this will work

(to-hstore {:somekey "some\\\"value"})
; => #<PGobject "somekey"=>"some\"value">

I just think that pghstore should do that for me, since it is a need specific to hstore columns.

sparkertime avatar Nov 14 '12 20:11 sparkertime