php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73834 PDO PgSQL specify format for COPY FROM
Submitted: 2016-12-29 16:39 UTC Modified: -
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: disassembler at dasm dot cz Assigned:
Status: Open Package: PDO PgSQL
PHP Version: 7.1.0 OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: disassembler at dasm dot cz
New email:
PHP Version: OS:

 

 [2016-12-29 16:39 UTC] disassembler at dasm dot cz
Description:
------------
PDO::pgsqlCopyFromFile() and PDO::pgsqlCopyFromArray() currently do not allow to specify format and default to TEXT.
As of PostgreSQL 8.0, allowed formats as per documentation are TEXT, CSV or BINARY - see https://www.postgresql.org/docs/current/static/sql-copy.html. Following query is not possible to perform using PDO:

COPY temp_csv FROM STDIN DELIMITER ',' CSV;

Only possible workaround includes usage of non-PDO functions as described in example here - http://php.net/manual/en/function.pg-end-copy.php



Test script:
---------------
$conn = new PDO("pgsql:dbname=csv_db", "csv_user", "csv_pass");
$conn->pgsqlCopyFromFile("csv_table', "data.csv", ",", "\\\\N", null/*, "csv" - parameter does not exist yet*/);

Expected result:
----------------
PDO PgSQL driver executes a query using CSV format.

Actual result:
--------------
PDO PgSQL driver executes a query using default TEXT format, resulting in error.
PDOException: SQLSTATE[22P04]: Bad copy file format: 7 ERROR: literal newline found in data HINT: Use "\n" to represent newline.

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Oct 18 19:01:28 2019 UTC