Skip to main content

COPY - Python ODBC issue

  • May 21, 2014
  • 2 replies
  • 20 views

Jakub
Hi, I have a problem with calling COPY function from Python application. The Python code connects to the Vertica DB with ODBC.

This is my query: copy temp_table from data/Vertica_common.txt REJECTMAX 10 DELIMITER '|' DIRECT

This is what I got from my python code:  ProgrammingError('42601', '[42601] ERROR 4856:  Syntax error at or near "data" at character 34\n (4856) (SQLExecDirectW)')

Could you give me an advice how to fix that?

Thanks,
Jakub

2 replies

Forum|alt.badge.img+2
  • Participating Frequently
  • May 21, 2014
Hi Jakub,

The file path is supposed to be an absolute path; also a string literal.  Could you try something like?:

copy temp_table from '/data/Vertica_common.txt' REJECTMAX 10 DELIMITER '|' DIRECT

COPY, by default, assumes that the file is stored on the remote Vertica cluster.  If it is instead local to the client machine, you could do:

copy temp_table from local 'data/Vertica_common.txt' REJECTMAX 10 DELIMITER '|' DIRECT

(Note that relative paths are ok with "LOCAL"; that's because they have something to be relative to, ie., the current working directory of the client application.)

Note that COPY LOCAL ships the file data over the network to Vertica.  Which can be a very useful feature.  But it's a bit silly (therefore a bit slower than regular COPY, which just opens the file directly) if your client application is on the same machine as your Vertica server, so the file is already local and doesn't need to be shipped over the network.

Adam

Jakub
  • Author
  • New Participant
  • May 22, 2014
hey Adam, thanks for the whole explanation. Now it works fine.

Cheers,
Jakub