mardi 30 octobre 2018

Laravel 5.5 - DB::statement error with \copy command (POSTGRES)

Im trying to use the \copy command from POSTGRES using laravel 5.5, to insert a large file at the DB, but im getting this error bellow.

I tried this way:

DB::statement( DB::raw("\\copy requisicoes FROM '".$file1."' WITH DELIMITER ','"));

Get this error:

SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "\" LINE 1: \copy requisicoes FROM '/srv/www/bilhetagem_logs/bilhetagem_... ^ (SQL: \copy requisicoes FROM '/srv/www/bilhetagem_logs/bilhetagem_log1_2018-10-29' WITH DELIMITER ',')

Tried this way too:

DB::statement( DB::raw('\copy requisicoes FROM \''.$file1.'\' WITH DELIMITER \',\''));

Get this error:

SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "\" LINE 1: \copy requisicoes FROM '/srv/www/bilhetagem_logs/bilhetagem_... ^ (SQL: \copy requisicoes FROM '/srv/www/bilhetagem_logs/bilhetagem_log1_2018-10-29' WITH DELIMITER ',')

If i execute the command that returns on the error above with psql line command, works fine

\copy requisicoes FROM '/srv/www/bilhetagem_logs/bilhetagem_log1_2018-10-29' WITH DELIMITER ','

Could somebody helps me? :)

I have to use \copy insted of copy becouse I dont have superuser privilege at the DB. https://www.postgresql.org/docs/9.2/static/sql-copy.html

COPY naming a file is only allowed to database superusers, since it allows reading or writing any file that the server has privileges to access.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire