syntax for copy command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyan
    New Member
    • Aug 2007
    • 54

    syntax for copy command

    hai everybody,
    I need to copy data from a text file to a table i used copy command
    like this
    [code=sql]

    copy city from 'e\ccccc.txt' with delimiter as ','
    [/code]

    it worked successfully. But now i need to copy a data from a text file which is in my system to the database in server..

    path of the file in my system is
    [code=text]
    \\ttcpl2\e\cccc c.txt
    [/code]

    if use copy command like this
    [code=sql]
    copy city from '\\Ttcpl2\e\ccc cc.txt' with delimiter as ','
    [/code]
    I got an error
    [code=text]
    WARNING: nonstandard use of \\ in a string literal
    LINE 1: copy city from '\\Ttcpl2\e\ccc cc.txt' with delimiter as ','
    ^
    HINT: Use the escape string syntax for backslashes, e.g., E'\\'.

    ERROR: could not open file "\Ttcpl2eccccc. txt" for reading: No such file or directory
    SQL state: 58P01

    [/code]
    If i use /copy command
    [code=sql]
    \COPY city FROM '\\ttcpl2\e\ccc cc.txt ' WITH DELIMITER ','
    [/code]
    [code=text]
    ERROR: syntax error at or near "\"
    SQL state: 42601
    Character: 1
    [/code]
    Please help me as soon as possible....... ...
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    Try either to double the backslashes (use \\\\ instead of \\) or replace them with forward-slashes, that is use "/" in place of "\"

    Comment

    • priyan
      New Member
      • Aug 2007
      • 54

      #3
      Originally posted by priyan
      hai everybody,
      I need to copy data from a text file to a table i used copy command
      like this
      [code=sql]

      copy city from 'e\ccccc.txt' with delimiter as ','
      [/code]

      it worked successfully. But now i need to copy a data from a text file which is in my system to the database in server..

      path of the file in my system is
      [code=text]
      \\ttcpl2\e\cccc c.txt
      [/code]

      if use copy command like this
      [code=sql]
      copy city from '\\Ttcpl2\e\ccc cc.txt' with delimiter as ','
      [/code]
      I got an error
      [code=text]
      WARNING: nonstandard use of \\ in a string literal
      LINE 1: copy city from '\\Ttcpl2\e\ccc cc.txt' with delimiter as ','
      ^
      HINT: Use the escape string syntax for backslashes, e.g., E'\\'.

      ERROR: could not open file "\Ttcpl2eccccc. txt" for reading: No such file or directory
      SQL state: 58P01

      [/code]
      If i use /copy command
      [code=sql]
      \COPY city FROM '\\ttcpl2\e\ccc cc.txt ' WITH DELIMITER ','
      [/code]
      [code=text]
      ERROR: syntax error at or near "\"
      SQL state: 42601
      Character: 1
      [/code]
      Please help me as soon as possible....... ...

      i have did as if u have said
      [code=sql]
      \COPY city FROM '//ttcpl2/e/ccccc.txt ' WITH DELIMITER ',';
      [/code]
      [code=text]
      ERROR: syntax error at or near "\"
      SQL state: 42601
      Character: 1

      [/code]

      Comment

      • michaelb
        Recognized Expert Contributor
        • Nov 2006
        • 534

        #4
        Originally posted by priyan
        i have did as if u have said
        [code=sql]
        \COPY city FROM '//ttcpl2/e/ccccc.txt ' WITH DELIMITER ',';
        [/code]
        [code=text]
        ERROR: syntax error at or near "\"
        SQL state: 42601
        Character: 1
        [/code]
        Why do you have a backslash at the beginning of your command?

        Comment

        Working...