PostgreSQL Perl – Fix NOTICE: elseif Should be elsif

perlpostgresqlsyntax

It's not the first time I get this strange NOTICE when adding perl functions in Postgresql :

NOTICE: elseif should be elsif at line 11.

This happens at CREATE FUNCTION as well as when using the function.
Of course I tried to change with elsif but then it fails with syntax error.

Any advice would be appreciated (even if I can cope with that NOTICE)

This is my code:

CREATE FUNCTION hds_updatewebservers_products(character varying) 
   RETURNS boolean 
AS 
$_$ 
   my $product_ref = @_[0]; 
   # Launch update 
   $checkexitcode = system ("sudo -u dbliveud /home/dbliveud/scripts/maj/launch-all.sh " . $product_ref . " "); 
   if ($checkexitcode > 0) { 
     # Error while updating 
     return false; 
   } elseif { 
     # Ok update done 
     return true; 
   } 
$_$ 
LANGUAGE plperlu STRICT;

Best Answer

I can't reproduce your error, it works fine on my PostgreSQL 9.5 on Linux. What version and platform are you running?

Note that your function can be exploited really badly, e.g.

select hds_updatewebservers_products('1; rm -rf /')

Why are you using elseif? Why not just else? See perl's documentation on elseif

Finally, you can simply (and elegantly):

CREATE FUNCTION hds_updatewebservers_products(character varying) RETURNS boolean AS $_$
  my $product_ref = @_[0]; # Launch update

  $product_ref =~ /^\w$/ or die 'Invalid product ref!'; # added for safety

  $checkexitcode = system ("sudo -u dbliveud /home/dbliveud/scripts/maj/launch-all.sh " . $product_ref . " ");

  # positive value means error while updating, otherwise update done OK
  return !($checkexitcode > 0);
$_$ LANGUAGE plperlu STRICT;