pgAdmin3:将查询结果用于COPY文件

时间:2014-12-28 22:52:30

标签: postgresql copy pgadmin

我想使用pgAdmin3(在Mac OSX 10.9.5上)将数百个文本文件复制到我的postgres数据库中。 我已经创建了一个包含所有文件名及其路径的列表,我已将其复制到数据库中名为“filenames”的表中。我正在尝试设置WHILE循环来打开每个文件:

Create NewTable (NewData varchar(255)); 
SET @i=1;
    WHILE @i<10
    BEGIN
        SET @V1=(select path_and_filename from filenames where row_number=@i);
        PRINT @V1;
        COPY NewTable FROM @V1;
        SET @i=@i+1;
    END

结果如下:

[PGSCRIPT ] ("/Volumes/WINDOWS COM/Weather ISD-lite/2013/010100-99999-2013")
[WARNING  ] COPY NewTable FROM ("/Volumes/WINDOWS COM/Weather ISD-lite/2013/010100-99999-2013")
            ERROR:  syntax error at or near "("
            LINE 1: COPY NewTable FROM ("/Volumes/WINDOWS COM/Weather ISD-lite/2...

我也尝试了以下内容:

DECLARE @R1 {@A};
SET @i=1;
WHILE @i<10
BEGIN
    SET @R1=(select path_and_filename from filenames where row_number=@i);
    SET @V1=@R1[0][0];
    PRINT @V1;

    COPY NewTable FROM @V1;

    SET @i=@i+1;
END

结果如下:

[PGSCRIPT ] /Volumes/WINDOWS COM/Weather ISD-lite/2013/010100-99999-2013
[WARNING  ] COPY NewTable FROM /Volumes/WINDOWS COM/Weather ISD-lite/2013/010100-99999-2013
            ERROR:  syntax error at or near "/"
            LINE 1: COPY NewTable FROM /Volumes/WINDOWS COM/Weather ISD-lite/201...
                                       ^

1 个答案:

答案 0 :(得分:0)

它从错误中看起来没有引用路径名,因此会产生语法错误。

尝试更改此内容:

COPY NewTable FROM @V1;

到此:

COPY NewTable FROM '@V1';