[Dbix-class] Fastest method to check for key existence?

Will Crawford billcrawford1970 at gmail.com
Fri Feb 13 10:32:03 GMT 2015


On 11 February 2015 at 21:58, Ekki Plicht (DF4OR) <ekki at plicht.de> wrote:
> Hi,
> I need to check a list of values if they exist in a database. The
> value is a unique key of that table. A stupid 'find' works of course,
> but returns the whole row data, where I only need a simple binary
> yes/no information if a row was found or not.

Presuming you mean that you need to get a list of them all, there's a
few answers, depending on your needs. A couple of the answers already
given are pretty useful and I'll be filing the "exists" rs method away
for future use.

Something like

    my %found = map +( $_ => 1 ),
        $rs->search_rs( { key => { -in => [ ... ] } } )->get_column('key')->all;

might do the trick (not tested for typos).



More information about the DBIx-Class mailing list