0

in my app I have table users that have the following column:

t.integer  "administrations", array: true

and I have code that looks like this:

User.where("administrations::int[] = ARRAY[#{administration_ids.join(',') }]::int[]")

but it is vulnerable for sql injection. I was trying to rewrite those to something like that:

User.where("administrations::int[] = ?", "ARRAY[#{administration_ids.join(',') }]::int[]")

but this not works...

It returns:

PG::InvalidTextRepresentation: ERROR:  array value must start with "{" or dimension information

2 Answers 2

1

would

User.where("administrations::int[] = ARRAY[?]::int[]", administration_ids.join(','))

work?

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately it not works :( PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "9696,9695,9694"
0

Also something like this work:

User.where(administrations: '{15,26,62,89,121}')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.