我正在创建一个表,并希望导入(加载到postgres)一个制表符分隔文件,该文件对某些列有一些缺失值(空单元格)。我希望这些单元格保持为空(或者可能在执行加载时将它们转换为NULL,或者在它们之后将它们保留为空)。
我尝试过以下脚本:
CREATE TABLE Conclusive_wg_H3K9me3_dn
(
Conclusive_wg_K9me3_DN_sorter float,
Conclusive_wg_K9me3_DN_geneid character(80) NOT NULL,
Conclusive_wg_K9me3_DN_bvi_srt float,
Conclusive_wg_K9me3_DN_cbk_srt float,
Conclusive_wg_K9me3_DN_dj_srt float,
Conclusive_wg_K9me3_DN_evj_srt float,
Conclusive_wg_K9me3_DN_flv_srt float,
Conclusive_wg_K9me3_DN_ghw_srt float,
Conclusive_wg_K9me3_DN_gvz_srt float,
Conclusive_wg_K9me3_DN_srr_srt float,
Conclusive_wg_K9me3_DN_AllCount float,
Conclusive_wg_K9me3_DN_PercentAllCount float,
Conclusive_wg_K9me3_DN_DynamicCounat float,
Conclusive_wg_K9me3_DN_PercentDynamic float,
Conclusive_wg_K9me3_DN_GeneName character(80) NOT NULL,
Conclusive_wg_K9me3_DN_RankSorting float,
Conclusive_wg_K9me3_DN_NewScore float,
CONSTRAINT Conclusive_wg_K9me3_DN_geneid PRIMARY KEY (Conclusive_wg_K9me3_DN_geneid)
);
COPY Conclusive_wg_H3K9me3_dn FROM 'G:\CarrollLab\Teena\ConsolidationWithMethylationData_NoiseBelow32Removed\FromPostgreSQLdb\FigsAndTangentWholeGenes\DynamicWholeGeneValues\OutputFromPostgres\ConclusiveDynamicGenes\Conclusive_wg_H3K9me3_dn.txt' WITH (FORMAT 'csv', DELIMITER E'\t', NULL 'NULL',HEADER);
如果我使用文本分隔文件执行此脚本,其中所有行都具有所有浮点值,则导入过程可以正常工作!没有麻烦。
但是,在尝试使用带有几个空单元格的文件(缺少一些浮点值)运行它时,我遇到以下错误信息:
ERROR: invalid input syntax for type double precision: ""
CONTEXT: COPY conclusive_wg_h3k9me3_dn, line 9, column conclusive_wg_k9me3_dn_flv_srt: ""
********** Error **********
ERROR: invalid input syntax for type double precision: ""
SQL state: 22P02
Context: COPY conclusive_wg_h3k9me3_dn, line 9, column conclusive_wg_k9me3_dn_flv_srt: ""
实际上,我在txt分隔文件中的第9行在其中一列中缺少数据(空单元格)。
我是否必须首先在EXCEL(例如)中使用字符串" NULL"替换所有空表单元格。 ?... float类型会识别NULL字符串吗?
或者我可以让postgres以某种方式理解如何处理空单元格而不用其他东西替换空值?
如何解决这个问题? 谢谢! 罗伊
答案 0 :(得分:0)
好的,问题解决了!
我应该将我的NULL分类更改为' NULL'相应地:(也见底部): WITH(FORMAT' csv',DELIMITER E' \ t',NULL'',HEADER);
CREATE TABLE Conclusive_wg_H3K9me3_dn
(
Conclusive_wg_K9me3_DN_sorter float,
Conclusive_wg_K9me3_DN_geneid character(80) NOT NULL,
Conclusive_wg_K9me3_DN_bvi_srt float,
Conclusive_wg_K9me3_DN_cbk_srt float,
Conclusive_wg_K9me3_DN_dj_srt float,
Conclusive_wg_K9me3_DN_evj_srt float,
Conclusive_wg_K9me3_DN_flv_srt float,
Conclusive_wg_K9me3_DN_ghw_srt float,
Conclusive_wg_K9me3_DN_gvz_srt float,
Conclusive_wg_K9me3_DN_srr_srt float,
Conclusive_wg_K9me3_DN_AllCount float,
Conclusive_wg_K9me3_DN_PercentAllCount float,
Conclusive_wg_K9me3_DN_DynamicCounat float,
Conclusive_wg_K9me3_DN_PercentDynamic float,
Conclusive_wg_K9me3_DN_GeneName character(80) NOT NULL,
Conclusive_wg_K9me3_DN_RankSorting float,
Conclusive_wg_K9me3_DN_NewScore float,
CONSTRAINT Conclusive_wg_K9me3_DN_geneid PRIMARY KEY (Conclusive_wg_K9me3_DN_geneid)
);
COPY Conclusive_wg_H3K9me3_dn FROM 'G:\CarrollLab\Teena\ConsolidationWithMethylationData_NoiseBelow32Removed\FromPostgreSQLdb\FigsAndTangentWholeGenes\DynamicWholeGeneValues\OutputFromPostgres\ConclusiveDynamicGenes\Conclusive_wg_H3K9me3_dn.txt' WITH (FORMAT 'csv', DELIMITER E'\t', NULL '',HEADER);