1

I have below query in perl DBI -

$query = $dbh->prepare(
    "SELECT * FROM domain WHERE domainname = ? AND servicename = ?");
$query->execute( $domain, $service );

where the servicename can be case insensitive i.e if my existing service name is 'Storage' then it should fetch the result for 'storage' also.

I tried below code -

query = $dbh->prepare(
    "SELECT * FROM domain WHERE domainname = ? AND servicename = lower(?)");
$query->execute( $domain, $service );

But it is not working for servicename = 'storage'.

Any pointer where i have missed?

CodeQuestor
  • 881
  • 1
  • 11
  • 25

2 Answers2

4

You should also use lowerfunction for the column value:

query = $dbh->prepare(
    "SELECT * FROM domain WHERE domainname = ? AND lower(servicename) = lower(?)");
$query->execute( $domain, $service );
Jens
  • 67,715
  • 15
  • 98
  • 113
3

You can use ilike function of Mysql it is case insensitive

query = $dbh->prepare(
    "SELECT * FROM domain WHERE domainname = ? AND servicename = ilike(?)"
);

$query->execute( $domain, $service );

ilike makes the comparison case insensitive.