Bash function from psql (v14) - Mailing list pgsql-general

From Murthy Nunna
Subject Bash function from psql (v14)
Date
Msg-id DM8PR09MB6677887ED1DA5D9494E2055CB85E2@DM8PR09MB6677.namprd09.prod.outlook.com
Whole thread Raw
Responses Re: Bash function from psql (v14)
Re: Bash function from psql (v14)
Re: Bash function from psql (v14)
List pgsql-general

Hi,

 

I am trying to code bash function and call it from psql. But it is failing. How can I get this to work. Creating a separate script instead of a function works, but I do not want to do that. I have too many variables to be passed back and forth. Any ideas?

 

#!/bin/bash

psql -d postgres  -p 5433 <<-PSQLBLOCK

\! run-bash-function                                        -- This doesn’t work

PSQLBLOCK

 

# Run the function outside PSQLBLOCK. This works!

run-bash-function

exit $?

 

# Create bash function

run-bash-function ()

{

  echo "in bash function"

}

# end of bash script

 

 

Run the above script:

./test-bash-function.sh

sh: line 1: run-bash-function: command not found

in bash function

 

pgsql-general by date:

Previous
From: ravi k
Date:
Subject: Re: Performance Issue with Hash Partition Query Execution in PostgreSQL 16
Next
From: "Efrain J. Berdecia"
Date:
Subject: Re: Bash function from psql (v14)