1

I wanted to run the alter table command using bash script. I managed to create the table, load the basemodel, create config tables and etc. The script will login to the postgres database before it is execute the alter table command. It stuck as (abcdb=> ) without proceed to the alter table command. Is there any way to make sure the alter table able to execute?

The login as

psql -h 191.169.51.10 -d abcdb -U myname



 alter table attr_config rename regexp to regexp_val;
 alter table class_action_config rename type to type_name;
 alter table funcitem_config rename type to type_name;
2
  • are the above lines part of your script? Commented Sep 7, 2016 at 7:41
  • yeah, its just a part of my script. The first line will login to the postgres database. Commented Sep 7, 2016 at 7:42

1 Answer 1

2

In order to run a script like this you need to redirect the SQL/DML (alter table statements) into the psql command. Otherwise bash won't understand what to do with them.

psql -h 191.169.51.10 -d abcdb -U myname << EOF

 alter table attr_config rename regexp to regexp_val;
 alter table class_action_config rename type to type_name;
 alter table funcitem_config rename type to type_name;
EOF

Alternatively you can put your SQL/DML into a separate file and have psql to read from that:

psql -h 191.169.51.10 -d abcdb -U myname < alter_statements.sql

Or

psql -h 191.169.51.10 -d abcdb -U myname -f alter_statements.sql
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.