|  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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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-2023 The PHP Group
All rights reserved.
Last updated: Tue Mar 21 06:03:41 2023 UTC