Search Postgresql Archives

psql doesn't pass on exported shell environment functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In hindsight I'm not surprised but couldn't find a ready explanation on the web and figured I'd inquire here.  In short: "export VAR" and "export -f functionname" behave differently when psql is acting as a relay.

//main-script
#!/usr/bin/env bash

function testfunction() {
    echo "Function Test"
}
export TEST_ENVVAR='Test'
export -f testfunction

psql "service=postgres" <<SQL
\! ./psql-call-bash
SQL

./psql-call-bash

//psql-call-bash script
#!/usr/bin/env bash

echo "Enter"
echo "EnvVar: $TEST_ENVVAR"
echo "Invoking Function..."

testfunction

exit

// command (after making both the above executable)

./main-script > output.txt 2>&1

//output.txt

Enter
EnvVar: Test
Invoking Function...
./psql-call-bash: line 7: testfunction: command not found
Enter
EnvVar: Test
Invoking Function...
Function Test

I was really hoping the first output block would match the second, specifically the "Function Test" line being present instead of "./psql-call-bash: line 7: testfunction: command not found"

Apparently exported variables go someplace different than exported functions :(

I don't suppose this is something that can be fixed in psql...

David J.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux