Skip to content

pg_copy_from no longer accepts linefeed #18148

Closed
@rperske

Description

@rperske

Description

After creating a PostgreSQL table with:

create table ttt ( aaa integer, bbb text );

The following code:

<?php
  $db = pg_connect( ".....")  or die( "Could not connect" );
  pg_copy_from( $db, 'ttt', [ "1\tone\n" ] ) or die( pg_last_error( $db ) );
?>

Resulted in this output:

PHP Warning:  pg_copy_from(): Copy command failed: ERROR:  22P02: invalid input syntax for type integer: ""
CONTEXT:  COPY ttt, line 2, column id: ""
LOCATION:  pg_strtoint32, numutils.c:320 in /...../...../......php on line 3
ERROR:  22P02: invalid input syntax for type integer: ""
CONTEXT:  COPY ttt, line 2, column id: ""
LOCATION:  pg_strtoint32, numutils.c:32

But I expected no output instead.

As the error messages indicates: Although I have given only one row of data, PostgreSQL sees two rows.

The following code, however (note the missing linefeed in the array element), applied to the same database:

<?php
  $db = pg_connect( "....." ) or die( "Could not connect" );
  pg_copy_from( $db, 'ttt', [ "1\tone" ] ) or die( pg_last_error( $db ) );
?>

Resulted in no output, as expected.

According to the documentation of the parameter rows of the function pg_copy_from: "Values should be linefeed terminated." So the first code block should be accepted.

With PHP 8.1, both code blocks produce no output as expected.
I have not tested PHP 8.2 and PHP 8.3.
With PHP 8.4, the error above appears as a regression.

PHP Version

PHP 8.4.5

Operating System

Alma Linux 9

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions