How to execute .sql file inside a postgres schema

Started by Daulat Ramalmost 7 years ago3 messagesgeneral
Jump to latest
#1Daulat Ram
Daulat.Ram@exponential.com

Hello team,

I have a database name "kbdb" that is having a schema "kb" and I want to execute the test.sql file inside this schema,

Please help how we can do that.

Regards,
Daulat

#2Daniel Westermann (DWE)
daniel.westermann@dbi-services.com
In reply to: Daulat Ram (#1)
Re: How to execute .sql file inside a postgres schema

I have a database name “kbdb” that is having a schema “kb” and I want to execute the test.sql file inside >>this schema,

set schema 'your_schema';

Cheers,

Daniel

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Daulat Ram (#1)
Re: How to execute .sql file inside a postgres schema

On 4/29/19 7:02 AM, Daulat Ram wrote:

Hello team,

I have a database name �kbdb� that is having a schema �kb� and I want to
execute the test.sql file inside this schema,

Please help how we can do that.

You can do as Daniel suggested but be aware that it is equivalent to:

https://www.postgresql.org/docs/11/sql-set.html
SET search_path TO value

That means if you have objects in the script that are not schema
qualified and need to point to other schemas then things will fail. A
longer term solution would to schema qualify the objects in your script.
This is assuming that the script is not generic and is meant to 'float'
from schema to schema.

Regards,

Daulat

--
Adrian Klaver
adrian.klaver@aklaver.com