From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | psql doesn't pass on exported shell environment functions |
Date: | 2017-07-06 22:04:33 |
Message-ID: | CAKFQuwajpzdk2pMs7erCoaa422SwNX=+kWrQ5+jmzbtU6mq1rg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Seamus Abshere | 2017-07-06 22:25:24 | Desired behavior for || (jsonb_concat) |
Previous Message | Tom Lane | 2017-07-06 21:25:25 | Re: Modified rows are not marked as dead and as such vacuum is unable to clean them up |