Forum OpenACS Q&A: Re: Running the psql COPY command from db_dml

Thank you all for your answers.
Even though the copy works when I run it in psql, when I try to run it using db_dml or db_exec_plsql I get errors:

db_dml:
Database operation "dml" failed
ERROR: syntax error at or near "\" at character 1
SQL: \copy ml_import_records ( record ) from '/tmp/file1sySZZ'

db_exec_plsql:
Database operation "0or1row" failed (exception NSDB, "Query was not a statement returning rows.")
while executing
"ns_db 0or1row $db "select $function_name ()""
invoked from within
"db_exec_plpgsql $db $full_statement_name $sql $statement_name"
invoked from within
"if {[regexp -nocase -- {^\s*select} $test_sql match]} {
ns_log Debug "PLPGSQL: bypassed anon function"
set selection [..."
("uplevel" body line 6)
invoked from within
"uplevel 1 $code_block "
invoked from within
"db_with_handle -dbn $dbn db {
# plsql calls that are simple selects bypass the plpgsql
# mechanism for creating anonymous fun..."
(procedure "db_exec_plsql" line 57)
invoked from within
"db_exec_plsql import_to_db "\\copy ml_import_records ( record ) from '$temp_filename'""