Hi all, I am having trouble with array slices in DBD::Pg. I'm migrating a large code base from Pg to DBD::Pg and we'd like to use ? as a placeholder as this is the accepted standard in the DBI world. Unfortunately we have some queries with array slices that are being recognized by DBD::Pg as placeholders. I can turn this off by setting pg_placeholder_dollaronly, but then we loose the ? as a placeholder. After discussing this with Greg Mullane, I sent a pull request that would allow me to turn off colon placeholders only:
https://github.com/bucardo/dbdpg/pull/2 On reflection Greg felt that it might be better to do some smarter parsing so that array slices could be used along with colon placeholders. A couple of suggestions were made: 1. a colon followed by a number /\d:\d/ would not be recognized as a placeholder 2. only colons followed by a space /\s:\d/ would be recognized as a placeholder Either way both of these would work as intended: SELECT bar[1:2] FROM foo WHERE baz = ? SELECT bar FROM foo where baz = :1 I am not fussed either way, so long as we can use an array slice and ? placeholders at the same time. I feel like the solution lest likely to break anyone's existing code is the original solution of providing an option of turning off colon place holders. Here are some queries that are problematic with a colon place holder as restricted by either 1 or 2 from above: SELECT bar[(select 1):2] FROM foo WHERE baz = ? :2 is treated incorrectly as a placeholder if option 1 above is used SELECT bar[1 :2] FROM foo WHERE baz = ? :2 would be treated incorrectly as a placeholder INSERT INTO foo (bar) VALUES (:1) :1 would be a syntax error (I think?) unless /\(:\d/ where also an exception Rudolf Lippan also chimed in pointing out that older versions of DBD::Pg correctly differentiated between array slices and colon placeholders as of at least version 1.31. This is related to rt#95173, a bug I opened last week, which can be seen here: https://rt.cpan.org/Public/Bug/Display.html?id=95173 I would like to gauge how other interested parties might feel about this. Thanks, Graham
