2

I need to pass an array of strings in a parameterized query. I tried the following but it doesn't work at all.

$params = array( array('bob','andrew','larry') );
pg_query_params($conn, 'SELECT * FROM table1 WHERE field = ANY($1)', $params)

I've seen solutions that converts the array to a string and then uses string_to_array to convert the input to an array on the database side, but as those strings are input from users this could end badly, even if I used a delimiter other than a comma. I'd rather use a cleaner solution for this, if possible.

Is there a way to keep this query parameterized and pass an array to it, without resorting to converting the data to a string?

By the way, I'm using PostgreSQL 8.3

1

1 Answer 1

1

pgsql.so is linked to libpq which does not have this capability.

Internally, it would need to serialize an array into string anyway.

libpqtypes has this capability built in, but I'm now aware of any PHP libraries using it.

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

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.