[Dbix-class] searching decimal colum

Francisco Obispo francisco at obispo.link
Fri Aug 18 22:47:43 GMT 2017


If the underlying data type is numeric, you should really try to match 
using numeric operators:

```perl
my $foo_rs = $schema
      ->resultset('Test')
      ->search
      ({
          col1 => { '>=' => 23, '<'=>24 }
      })->count;



```

On 18 Aug 2017, at 13:29, Rajeev Prasad wrote:

> i found the solution:
>
> my $n = 33;
>
> my $foo_rs = $schema
>     ->resultset('Test')
>     ->search
>     ({
>         col1 => { like => '%.'.$n }
>     })->count;
>
>     On Friday, August 18, 2017 2:35 PM, Rajeev Prasad 
> <rp.neuli at yahoo.com> wrote:
>
>
>  before i go an do some operations. i need to know if the following 
> will work?
>
> so I have this column:
> col123.3323.4612.3310.3323.54623.11.33100.33
>
> I want to run two queries
> 1. select all rows with 23 before decimal (not *23.*, just 23.*).
> my @foo = $schema    ->resultset('Test')
>     ->search
>     ({
>         col1 => { like => 23'.%'}
>     });
>     
> print "values @foo\n";
>
> I expect:23.3323.4623.54623.1
> 2. second i want to run query to select for given value after 
> decimal.my $foo_rs = $schema->resultset('Table')->search({
>                                         
>                 col1 => { like => 23.'%' }});
> I expect:23.3312.3310.331.33100.33
>
>
> I get this error when i test:
> $ ./test.pl
> String found where operator expected at ./test.pl line 26, near 
> "23'.%'"
>         (Missing operator before '.%'?)
> Possible unintended interpolation of @foo in string at ./test.pl line 
> 29.
> syntax error at ./test.pl line 26, near "23'.%'"
> Global symbol "@foo" requires explicit package name (did you forget to 
> declare "my @foo"?) at ./test.pl line 29.
> Execution of ./test.pl aborted due to compilation errors.
>
>
>
>
>
> _______________________________________________
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20170818/b4b7a377/attachment.htm>


More information about the DBIx-Class mailing list