pc2phone=# COPY * from t_prepaid_history h where to_char(h.fcall_start_time,'YYYYMMDD')='20070218' to '/home/postgres/c.txt' with csv; 
ERROR:  syntax error at or near "*" 
LINE 1: COPY * from t_prepaid_history h where to_char(h.fcall_start_... 我想将2007年2月18日的记录以csv的格式拷贝到/home/postgres/c.txt文件中,但是报错,请问错在哪里?谢谢.

解决方案 »

  1.   

    不要带 *
    直接copy from
    帮助文档上有例子,东西也很全
    COPY tablename [ ( column [, ...] ) ]
        FROM { 'filename' | STDIN }
        [ [ WITH ] 
              [ BINARY ]
              [ OIDS ]
              [ DELIMITER [ AS ] 'delimiter' ]
              [ NULL [ AS ] 'null string' ]
              [ CSV [ HEADER ]
                    [ QUOTE [ AS ] 'quote' ] 
                    [ ESCAPE [ AS ] 'escape' ]
                    [ FORCE NOT NULL column [, ...] ]COPY { tablename [ ( column [, ...] ) ] | ( query ) }
        TO { 'filename' | STDOUT }
        [ [ WITH ] 
              [ BINARY ]
              [ HEADER ]
              [ OIDS ]
              [ DELIMITER [ AS ] 'delimiter' ]
              [ NULL [ AS ] 'null string' ]
              [ CSV [ HEADER ]
                    [ QUOTE [ AS ] 'quote' ] 
                    [ ESCAPE [ AS ] 'escape' ]
                    [ FORCE QUOTE column [, ...] ]
      

  2.   

    你去掉*没有?你试过好几种方法,都把错误贴出来
    还有记得把错误贴到google上,说不定就有答案
    主动点
      

  3.   

    看你的语句试下
    copy from select * from ………………
      

  4.   

    如果是copy整张表可以使用copy 表名 to 绝对路径 with csv; 但是我想在里面加上条件就不知道怎么写了,请知道的告诉我一下,谢谢了.再者,请问postgres可以导出excel格式的文件吗?
      

  5.   

    pc2phone=# COPY from select * from t_prepaid_history where to_char(fcall_start_time,'YYYYMMDD')='20080302' to '/home/postgres/a.txt' with csv;
    ERROR:  syntax error at or near "from"
    LINE 1: COPY from select * from t_prepaid_history where to_char(fcal...
      

  6.   

    copy  (select * from road where road_class =10)  to '\\\\dddtest\\copy\\test.sql'
    我是在pgadmin上写的,所有后面文件要加斜杠
    subquery要加括号,帮助文档上都有的
    Note that parentheses are required around the query