Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

invalid translation for arrays in prepared statements for PostgreSQL #451

Closed
olek opened this Issue · 2 comments

2 participants

Olek Poplavsky Jeremy Evans
Olek Poplavsky

If prepared statement parameter is bound to array (typical for inclusions IN/ANY query), sequel translates that to '[11,22]' string, but PostgreSQL does not understand that syntax. Instead, '{foo,bar}' should be used.

Query example:

self.where('id = ANY(?)', :"$ids__integer[]")

For now, I worked around the problem by doing array to string transformation myself, like this:

:ids => '{' + subscriptions.map(&:id).join(',') + '}'

Jeremy Evans
Owner

Well, PostgreSQL arrays aren't supported by default, so that is not surprising. My guess is ruby-pg is just calling to_s on the array (and you are using ruby 1.9). This is really something that should be done in ruby-pg, you should probably open the issue on the ruby-pg bug tracker (I'd recommend using the ARRAY[] syntax for input, it's more sane).

It's possible that the pg_array extension can include a workaround for this so it works transparently in Sequel without changes to ruby-pg, but I'll need to make the changes required by #450 first.

Jeremy Evans
Owner

I plan to commit this tomorrow after additional testing, you may want to try it in the meantime: http://pastie.org/3553187

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.