mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Do not treat \. as an EOF marker in CSV mode for COPY IN.
Since backslash is (typically) not special in CSV data, we should not be treating \. as special either. The server historically did this to keep CSV and TEXT modes more alike and to support V2 protocol; but V2 protocol is long dead, and the inconsistency with CSV standards is annoying. Remove that behavior in CopyReadLineText, and make some minor consequent code simplifications. On the client side, we need to fix psql so that it does not check for \. except when reading data from STDIN (that is, the script source). We must do that regardless of TEXT/CSV mode or there is no way to end the COPY short of script EOF. Also, be careful not to send the \. to the server in that case. This is a small compatibility break in that other applications beside psql may need similar adjustment. Also, using an older version of psql with a v18 server may result in misbehavior during CSV-mode COPY IN. Daniel Vérité, reviewed by vignesh C, Robert Haas, and myself Discussion: https://postgr.es/m/ed659f37-a9dd-42a7-82b9-0da562cc4006@manitou-mail.org
This commit is contained in:
@@ -1160,8 +1160,11 @@ CopyAttributeOutCSV(CopyToState cstate, const char *string,
|
||||
if (!use_quote)
|
||||
{
|
||||
/*
|
||||
* Because '\.' can be a data value, quote it if it appears alone on a
|
||||
* line so it is not interpreted as the end-of-data marker.
|
||||
* Quote '\.' if it appears alone on a line, so that it will not be
|
||||
* interpreted as an end-of-data marker. (PG 18 and up will not
|
||||
* interpret '\.' in CSV that way, except in embedded-in-SQL data; but
|
||||
* we want the data to be loadable by older versions too. Also, this
|
||||
* avoids breaking clients that are still using PQgetline().)
|
||||
*/
|
||||
if (single_attr && strcmp(ptr, "\\.") == 0)
|
||||
use_quote = true;
|
||||
|
||||
Reference in New Issue
Block a user