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

Jess Robinson castaway at desert-island.me.uk
Thu Mar 12 13:19:58 GMT 2009


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?

Jess




More information about the DBIx-Class mailing list