我有一个seq_data
如下所示的 postgres 表:
data_id | machine | run | cell | run_start | library | expected_dir | transferred | failed | cloud | csv_uploaded | last_updated
---------+---------+--------------+-------+------------+---------+---------------------------------------------------+-------------+--------+-------+--------------+-------------------------------
1 | rsii_1 | RUN001 | B01_1 | 2020-02-05 | N/A | some/dir | t | f | t | t | 2020-02-07 11:24:17.279879+00
2 | rsii_1 | RUN001 | C01_1 | 2020-02-05 | N/A | some/dir | t | f | t | t | 2020-02-07 11:24:17.279879+00
我想做的是更新列库。
如果我做:
data_monitor=> UPDATE seq_data SET failed=TRUE WHERE data_id=2;
UPDATE 1
它有效,我得到:
data_id | machine | run | cell | run_start | library | expected_dir | transferred | failed | cloud | csv_uploaded | last_updated
---------+---------+--------------+-------+------------+---------+---------------------------------------------------+-------------+--------+-------+--------------+-------------------------------
1 | rsii_1 | RUN001 | B01_1 | 2020-02-05 | N/A | some/dir | t | f | t | t | 2020-02-07 11:24:17.279879+00
2 | rsii_1 | RUN001 | C01_1 | 2020-02-05 | N/A | some/dir | t | t | t | t | 2020-02-07 11:24:17.279879+00
但是当我这样做时:
data_monitor=> UPDATE seq_data SET library=this_library WHERE data_id=1;
ERROR: column "this_library" does not exist
LINE 1: UPDATE seq_data SET library=this_library WHERE data_id=1;
我真正想做的是library
基于run
,cell
和machine
data_monitor=> UPDATE seq_data SET library=this_library WHERE machine=rsii_1 and run=RUN001 and cell=B01_1;
ERROR: column "rsii_1" does not exist
LINE 1: ...E seq_data SET library=this_library WHERE machine=rsii_1 and...
为什么会这样?
似乎在UPDATE seq_data SET library=this_library WHERE machine=rsii_1 and run=RUN001 and cell=B01_1;
跳过列时感到困惑library
,并认为列名实际上是值,this_library
版本:postgresql-11
这就是我创建表格的方式:
CREATE TABLE seq_data (
data_id serial NOT NULL,
machine varchar(10) NOT NULL,
run varchar(30) NOT NULL,
cell varchar(10) NOT NULL,
run_start date NOT NULL,
library varchar(25) NOT NULL DEFAULT 'N/A',
expected_dir varchar(100),
transferred boolean NOT NULL DEFAULT 'f',
failed boolean NOT NULL DEFAULT 'f',
cloud boolean NOT NULL DEFAULT 'f',
csv_uploaded boolean NOT NULL DEFAULT 'f',
last_updated timestamp with time zone DEFAULT now(),
PRIMARY KEY (data_id),
CONSTRAINT data_id UNIQUE (machine, run, cell)
);
更新
在 Python3.7 中使用 psycopg2
dbconn.query(
'''UPDATE seq_data
SET library=%s
WHERE run=%s and machine=%s and cell=%s;''',
(sample_name[1], run, machine, sample_name[0],), commit=True)
我将如何在 python 中将这些引号括起来?所有变量都已经是字符串。