[GENERAL] psql doesn't pass on exported shell environment functions - Mailing list pgsql-general

From David G. Johnston
Subject [GENERAL] psql doesn't pass on exported shell environment functions
Date
Msg-id CAKFQuwajpzdk2pMs7erCoaa422SwNX=+kWrQ5+jmzbtU6mq1rg@mail.gmail.com
Whole thread Raw
Responses Re: [GENERAL] psql doesn't pass on exported shell environmentfunctions  (Albe Laurenz <laurenz.albe@wien.gv.at>)
List pgsql-general
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.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [GENERAL] Modified rows are not marked as dead and as such vacuum is unable to clean them up
Next
From: Seamus Abshere
Date:
Subject: [GENERAL] Desired behavior for || (jsonb_concat)