Skip to content

pg_copy_from no longer accepts linefeed #18148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rperske opened this issue Mar 26, 2025 · 3 comments
Closed

pg_copy_from no longer accepts linefeed #18148

rperske opened this issue Mar 26, 2025 · 3 comments

Comments

@rperske
Copy link

rperske commented Mar 26, 2025

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

@rperske
Copy link
Author

rperske commented Mar 26, 2025

pg_copy_to() produces arrays of records that do include linefeeds.
So now pg_copy_from() cannot handle output from pg_copy_to().
Nor can it handle output from file().
So there are multiple reasons to restore the old behaviour.
Thanks in advance to everyone looking into this issue.

@devnexen
Copy link
Member

I have not tested PHP 8.2 and PHP 8.3.

Even 8.3 is probably not affected by the bug. I ll have a look later today.

@devnexen devnexen self-assigned this Mar 26, 2025
@devnexen
Copy link
Member

confirmed 8.3 is not affected.

devnexen added a commit to devnexen/php-src that referenced this issue Mar 26, 2025
@devnexen devnexen linked a pull request Mar 26, 2025 that will close this issue
devnexen added a commit to devnexen/php-src that referenced this issue Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants