0

I need to migrate from Oracle to Postgres.

In Oracle I have .sql files calling nested .sql files (with input and output parameters each one) in this way: nested sql scripts and variables

Looking for a similar solution in Postgres I found this: How to run postgres sql script from another script?

But what happens with the solution: \i other_script.sql

Can I pass input parameters to it? (and if yes, how?) Can I return parameters from it? (and if yes, how?)

Or the other_script.sql and the calling.script share variables?

Or there isn't an equivalent solution for input/output parameters. And variables are not shared between the two .sql files?

David
  • 1

1 Answers1

0

psql session variables are session based, so you can set any psql variable inside script, and you can read this variable outside script.

\set myvar some value
select :'myvar';

You can read more in psql documentation.

Pavel Stehule
  • 42,331
  • 5
  • 91
  • 94