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

Collapse
Posted by Guan Yang on
Nis: That's right, but you can't run psql commands in db_dml. You'd have to write out a temporary SQL script and invoke exec psql.
in order to do that I did the following:

Old way:

db_dml import_to_db " copy ml_import_records ( record ) from :temp_filename"

the new way:
exec "$psqlpath/psql -h $host -p $port -U $user $dbname < /tmp/$file_with_sql"

Where "$file_with_sql" contains actually the following

\copy ml_import_records ( record ) from 'temp_file_name'

The First one works fine, but the second doesnt. It seems that no matter what I do, only commands like [db_dml] or [file copy] can "see" the file I am uploading (using ad_form).
Even if I try to do an "exec cp temp_file_name new_file" I get the same error:
"no such file or directory"