「お金に愛されないエンジニア」第4回 コピペ用ページ
version: '3'
services:
db:
image: postgres:14
container_name: postgres
ports:
- 15432:5432
volumes:
- ./stock_db:/stock_db
- db-data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=password
volumes:
db-data:
# stock_dbというディレクトリを掘っておくこと
# docker exec -it postgres bash // コンテナへのログイン方法
ーーーー
>docker-compose start
ーーーー
>docker exec -it postgres bash
ーーーー
$ gem install csv2psql
ーーーー
CREATE TABLE stock(Date varchar(10), Open numeric, High numeric, Low numeric, Close numeric, Ave5day numeric, Ave25day numeric, Ave75day numeric, VWAP numeric, Vol numeric, Vol5day numeric, Vol25day numeric);
ーーーー
hitachi=# CREATE TABLE stock(Date varchar(10), Open int, High int, Low int, Close int, Ave5day int, Ave25day int, Ave75day int, VWA
P int, Vol int, Vol5day int, Vol25day int);
CREATE TABLE
hitachi=# \copy stock from '/stock_db/hitachi.csv' with csv delimiter ',';
COPY 245
hitachi=# select * from stock;
date | open | high | low | close | ave5day | ave25day | ave75day | vwap | vol | vol5day | vol25day
------------+------+------+------+-------+---------+----------+----------+------+----------+---------+----------
2022/6/3 | 6860 | 6897 | 6781 | 6856 | 6791 | 6492 | 6021 | 6840 | 1942500 | 2547480 | 2870752
2022/6/2 | 6795 | 6802 | 6715 | 6797 | 6752 | 6460 | 6009 | 6778 | 1654700 | 2506700 | 2903484
2022/6/1 | 6686 | 6796 | 6671 | 6796 | 6712 | 6431 | 5998 | 6752 | 1575500 | 2560260 | 2931012
2022/5/31 | 6750 | 6798 | 6706 | 6725 | 6678 | 6402 | 5986 | 6735 | 3122200 | 2775060 | 2944456