[Dbix-class] Does DBIx::Class support postgresql arrays and ANY syntax?

Adam Witney awitney at sgul.ac.uk
Fri Mar 13 09:45:53 GMT 2009


On 12 Mar 2009, at 13:19, Jess Robinson wrote:

>
> On Wed, 18 Feb 2009, Adam Witney wrote:
>
>>
>> On 18 Feb 2009, at 11:18, Joel Bernstein wrote:
>>
>>> 2009/2/18 Joel Bernstein <joel at fysh.org>:
>>> > Why do you feel that is a hack? It seems equivalent to your  
>>> original > query..
>>> > $rs->search({ 1 => \'sql literal here', })
>>> > It's a perfectly common idiom so I'm not too sure why you feel  
>>> it's > hacky?
>>> I suppose you meant, it feels like a hack to use a SQL literal to
>>> mimic the original query, and does DBIC have a more logical way to
>>> achieve it?
>>
>> Yes, thats what i meant.
>>
>> I did manage to write my own special operator using SQL::Abstract  
>> (1.49_02) which would handle the ANY keyword, but i couldn't see  
>> how i could include this such that the DBIx::Class generated code  
>> could use it, like so:
>>
>> my $sql = SQL::Abstract->new(special_ops => [
>>   {regex => qr/^any$/i,
>>    handler => sub {
>>      my ($self, $field, $op, $arg) = @_;
>>      $arg = [$arg] if not ref $arg;
>>      my $label         = $self->_quote($field);
>>      my ($placeholder) = $self->_convert('?');
>>      my $sql           = $placeholder . " = " . $self- 
>> >_sqlcase('any') .
>>      "($label) ";
>>      my @bind = $self->_bindtype($field, @$arg);
>>      return ($sql, @bind);
>>      }
>>   },
>> ] ) ;
>>
>> my %where = (
>> 'my_array_col' => { -any => '1' }
>> );
>>
>> my($stmt, @bind) = $sql->where(\%where);
>>
>
> The newest DBIC dev release, soon to be the public one, uses the  
> features of the newest SQL::Abstract 1.50, which is also being  
> released.. Care to try this out and report back?

ok I will give this a bash and report back.

Although, I think one of the problems I was having was how to include  
the special_ops such that the DBIC code had access to it? ie how would  
i utilise the %where or $stmt variables above from within DBIC?

thanks again for your help

adam





More information about the DBIx-Class mailing list