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:4
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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 08:01:29 2024 UTC