|  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: -
Avg. Score:4.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: disassembler at dasm dot cz
New email:
PHP Version: OS:


 [2016-12-29 16:39 UTC] disassembler at dasm dot cz
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 Following query is not possible to perform using PDO:


Only possible workaround includes usage of non-PDO functions as described in example here -

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.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 13:01:33 2024 UTC