Postgres中嵌套的SQL脚本和变量

问题描述 投票:0回答:1

我需要从Oracle迁移到Postgres。

在Oracle中我有.sql文件以这种方式调用嵌套的.sql文件(每个输入和输出参数):nested sql scripts and variables

在Postgres中寻找类似的解决方案我发现了这个:How to run postgres sql script from another script?

但是解决方案会发生什么:\i other_script.sql

我可以将输入参数传递给它吗? (如果是,如何?)我可以从中返回参数吗? (如果是,怎么样?)

或者other_script.sql和calling.script共享变量?

或者没有输入/输出参数的等效解决方案。并且两个.sql文件之间不共享变量?

sql bash postgresql
1个回答
0
投票

psql会话变量是基于会话的,因此您可以在脚本中设置任何psql变量,并且您可以在脚本外部读取此变量。

\set myvar some value
select :'myvar';

您可以在psql documentation中阅读更多内容。

© www.soinside.com 2019 - 2024. All rights reserved.