CREATE or replace FUNCTION test() RETURNS boolean AS $$
$filename = '/home/postgres';
if (-e $filename) { 
exec /home/postgres/test.sh &
return true; }
return false;
$$ LANGUAGE plperlu;
exec /home/postgres/test.sh & its showing syntax error. Could you please help how to call bash script into postgres funtion/procedure
Presumably, the code needs to be syntactically valid Perl. So you'll need to clean up a few bits.
CREATE or replace FUNCTION test() RETURNS boolean AS $$
  my $filename = '/home/postgres';
  if (-e $filename) { 
    system '/home/postgres/test.sh' and return 1;
  }
  return;
$$ LANGUAGE plperlu;
I've changed a few things:
$filename using mysystem instead of exec. exec replaces the current process - effectively never returning to the calling functionsystem expects to be passed a string. So I've added quotes around the commandand is usually better in flow control statements than && (and always much better than & which is for bit-flipping, not flow control)true and false, so I've replaced true with 1 (which is a true value in Perl). And I've removed the false from the other return statement - the default behaviour of return is to return a false valueI don't have a Postgresql installation to test this on. If it still doesn't work, please tell us what errors you get.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With