doc: \copy can get data values \. and end-of-input confused
authorBruce Momjian <[email protected]>
Fri, 3 Nov 2023 17:57:59 +0000 (13:57 -0400)
committerBruce Momjian <[email protected]>
Fri, 3 Nov 2023 17:57:59 +0000 (13:57 -0400)
Reported-by: Svante Richter
Discussion: https://postgr.es/m/fcd57e4-8f23-4c3e-a5db-2571d09208e2@beta.fastmail.com

Backpatch-through: 11

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/copy.c

index d94e3cacfcc6154857fac25353e692adec168e74..cc7d797159b41e8b63c9c610fdb5488e75306c62 100644 (file)
@@ -1119,6 +1119,10 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
         destination, because all data must pass through the client/server
         connection.  For large amounts of data the <acronym>SQL</acronym>
         command might be preferable.
+        Also, because of this pass-through method, <literal>\copy
+        ... from</literal> in <acronym>CSV</acronym> mode will erroneously
+        treat a <literal>\.</literal> data value alone on a line as an
+        end-of-input marker.
         </para>
         </tip>
 
index b3cc3d9a29069aaa8db9308e500aaa811a7d9116..dbbbdb88987d7256f2f01f7e5b4806873aa80cfd 100644 (file)
@@ -627,6 +627,8 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
                                                 * This code erroneously assumes '\.' on a line alone
                                                 * inside a quoted CSV string terminates the \copy.
                                                 * https://www.postgresql.org/message-id/[email protected]
+                                                *
+                                                * https://www.postgresql.org/message-id/[email protected]
                                                 */
                                                if ((linelen == 3 && memcmp(fgresult, "\\.\n", 3) == 0) ||
                                                        (linelen == 4 && memcmp(fgresult, "\\.\r\n", 4) == 0))