Provided, I have to go through a route of
Get into docker
Get into postgreSQL database
Create table
Insert data
Which is very troublesome to do it frequently since I am testing. I want to write a bash script (.sh file) that do everything in 1 run.
Here are all my command line I need to run
docker exec -it <mycontainer> bash
psql -h localhost -p 5432 -U postgres
CREATE SCHEMA bank;
CREATE TABLE bank.holding (
holding_id int,
user_id int,
holding_stock varchar(8),
holding_quantity int,
datetime_created timestamp,
datetime_updated timestamp,
primary key(holding_id)
);
insert into bank.holding values (102100, 2, 'VFIAX', 10, now(), now());
-coption topsql. For examplepsql -h localhost -p 5432 -U postgres -c 'create schema bank;and thensql -h localhost -p 5432 -U postgres -c 'create table bank.holding ( ... );and so on. You can put all your command in a file and then use the-f(--file) option to read all commands from a file. That would likely be the better call, e.g.psql -h localhost -p 5432 -U postgres -f file-w-create.txt.sqlscrips inside/docker-entrypoint-initdb.dusing docker volumes, and it will run on database initCREATE TABLEcommands).