1

I am having a shell file named test.sh which is invoking other sql file 'table.sql'. 'table.sql' file will create some tables, but I want to create the tables in a particular schema 'bird'.

content of sql file.

create schema bird; --bird should not be hard coded it should be in variable
set search_path to 'bird';
create table bird.sparrow(id int, name varchar2(20));

content of shell file.

dbname=1ドル
cnport=2ドル
schemaname=3ドル
filename=4ドル
gsql -d ${dbname} -p ${cnport} -f ${filenam} #[how to give schema name here so that it can be used in table.sql without hardcoding]

I will execute my shell file like this

sh test.sh db1 9999 bird table.sql 
asked Sep 21, 2017 at 11:24

1 Answer 1

2

it is easier doing it in shell, eg:

dbname=1ドル
cnport=2ドル
schemaname=3ドル
filename=4ドル
gsql -d ${dbname} -p ${cnport} <<EOF
create schema 3ドル; --bird should not be hard coded it should be in variable
set search_path to '3ドル';
create table bird.sparrow(id int, name varchar2(20));
EOF

otherwise use psql variables

answered Sep 21, 2017 at 11:31
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.