【发布时间】:2020-01-05 03:57:04
【问题描述】:
寻找一种解析解决方案,该解决方案可以从 CSV 复制到我的数据库中,并生成序列 ID 的最终结果。无论是在后端,还是在复制时。照原样,复制后我的 ID 为空。
echo CREATE TABLE IF NOT EXISTS qs_facts_template (id SERIAL NOT NULL, symbol varchar(8), timestamp date, close real null, open real null, high real null, low real null, volume real null, CONSTRAINT qs_facts_template_key PRIMARY KEY (id)) WITH (OIDS=TRUE) TABLESPACE pg_default; ALTER TABLE qs_facts_template OWNER to postgres; | psql -U postgres -h %host% readyloop
echo CREATE TABLE IF NOT EXISTS qs_facts AS select * from qs_facts_template;| psql -U postgres -h %host% readyloop
echo \copy qs_facts (symbol, timestamp, close, open, high, low, volume) from PROGRAM 'cat C:\Users\user\Documents\quantshare\quotes.csv' DELIMITER ';' CSV HEADER| psql -U postgres -h %host% %dbName%
这篇文章:https://unix.stackexchange.com/questions/277080/copy-csv-data-while-simultaneously-filling-serial-column 没有解决我的问题。我使用了 Guido 提到的命令并让副本工作,但 id 都是空的。
我在想也许我可以在复制之后设置值。
【问题讨论】: