[Dbix-class] Using Postgres JSONB operators in queries

Darren Duncan darren at darrenduncan.net
Fri Dec 19 00:12:52 GMT 2014


Keep in mind that those dollar-names are a PostgreSQL specific feature, their 
native way to refer positional routine parameters.  In your Perl code the SQL 
will have to be making those literals, eg non-interpolating dollar signs. -- 
Darren Duncan

On 2014-12-17 10:28 AM, Augustus Saunders wrote:
> Interesting, thanks for the information. I hadn't realized that you could use $1, $2 etc at the DBI/bind level. I do have queries where the same value is repeated, so that should be helpful regardless of the ? class of operators.
>
> Augustus
>
> On Dec 16, 2014, at 8:19 PM, Darren Duncan <darren at darrenduncan.net> wrote:
>
>> On 2014-12-04 3:38 PM, Augustus Saunders wrote:
>>> Hi all, I have been unable to find a way to use some of the new JSONB operators
>>> in Postgres 9.4 with DBIx::Class. A quick search for JSONB on the email archive
>>> site didn’t turn up any results, so I thought I would ask.
>>>
>>> In particular, ?, ?&, and ?| are now operators, and we run into problems with
>>> the DBI placeholder being ?. I read that putting single quotes around the
>>> question mark would allow a literal question mark in DBI, but I can’t seem to
>>> make this work from DBIx::Class. Can anybody tell me whether this is currently
>>> possible, if so how, and if not what might be involved or where in the code to
>>> look? Thanks-
>>
>> At the DBI level anyway, you can use this:
>>
>> http://search.cpan.org/dist/DBD-Pg/Pg.pm#pg_placeholder_dollaronly_(boolean)
>>
>> If you set that DBD::Pg option, then literal ? are not treated as placeholders and you instead have to use other forms like $1,$2 etc or named placeholders; on the plus side, those also let you use the same placeholder more than once in a statement rather than having to pass in the same bind value multiple times.
>>
>> This being said, I don't know if DBIx::Class is compatible with that way of using PostgreSQL, not that this can't change.
>>
>> -- Darren Duncan
>>
>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>




More information about the DBIx-Class mailing list