Forum OpenACS Q&A: error with \copy command

Collapse
Posted by k k on
Hi,

I am trying to copy the data into the pgsql using tcl.

set tcopy " \\copy tmp_reb_user_group from tmp.txt using delimiters \"|\" "

set selection [ns_db exec $db $tcopy]

However, there were error messages from the log file

14/Feb/2003:03:35:08][19272.11270][-conn3-] Error: dbinit:

error(localhost::tanh,ERROR:  parser: parse error at or near "\"
): ' \copy tmp_reb_user_group from tmp.txt using delimiters "|" '

I think it is because of "\" character. Although, I have try to add more \ but it doesn't work.

Could you please point out my mistake. Thank you very much

Collapse
Posted by Don Baccus on
The command's "copy" not "\copy", which is why it's complaining about the "\".
Collapse
Posted by k k on
Thank you very much for your help. I change my query to

copy tmp_reb_user_group from 'tmp.txt' using delimiter '|'

However, when I try to test with psql shell, I can not use the copy command since It display error message

You must have Postgres superuser privilege to do a COPY directly to or from a file.  Anyone can COPY to stdout or from stdin.  Psql's \copy command also works for anyone.
that why I try to use \copy in TCL.

Note the following command work fine with psql shell
--
\copy tmp_reb_user_group from tmp.txt using delimiters "|"
--

Some one suggest me to use "exec "
to exec the psql command. I have try but it doesn't work
like

psql \copy tmp_reb_user_group from tmp.txt using delimiters "|"

I think it is the problem that I pass the command incorrectly to psql shell . Could you please point out my mistake?
Thank you very much

Collapse
Posted by Don Baccus on
Try putting the command in a file and pass the file name using "-f".