我想通过psql在空数据库中加载一些SQL函数:
psql -d my_database -f fuctions.sql --set ON_ERROR_STOP=1
Run Code Online (Sandbox Code Playgroud)
我使用--set ON_ERROR_STOP=1是因为如果脚本包含错误,我希望psql失败.
内容functions.sql是:
CREATE or REPLACE FUNCTION test_function() RETURNS INT AS $$
SELECT id from test_table;
$$ LANGUAGE sql;
Run Code Online (Sandbox Code Playgroud)
我的问题是,psql检查test_table加载函数时是否存在并因此错误而失败:
Run Code Online (Sandbox Code Playgroud)ERROR: relation "test_table" does not exist LINE 2: SELECT id from test_table;
但我不希望psql检查表是否存在,因为我稍后会创建此表.
以下解决方法可行,但我无法使用它们: