[GENERAL] psql doesn't pass on exported shell environment functions

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема [GENERAL] psql doesn't pass on exported shell environment functions
Дата
Msg-id CAKFQuwajpzdk2pMs7erCoaa422SwNX=+kWrQ5+jmzbtU6mq1rg@mail.gmail.com
обсуждение исходный текст
Ответы Re: [GENERAL] psql doesn't pass on exported shell environmentfunctions
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [GENERAL] Modified rows are not marked as dead and as such vacuum is unable to clean them up
Следующее
От: Seamus Abshere
Дата:
Сообщение: [GENERAL] Desired behavior for || (jsonb_concat)