Обсуждение: BUG #19403: psql fails when trying to import a file that

Поиск
Список
Период
Сортировка

BUG #19403: psql fails when trying to import a file that

От
PG Bug reporting form
Дата:
The following bug has been logged on the website:

Bug reference:      19403
Logged by:          Daniel Adeniji
Email address:      daniel_adeniji@hotmail.com
PostgreSQL version: 17.6
Operating system:   MS Windows 10 ( PostgreSQL 17.6 on x86_64-windows
Description:

Database Table
--------------------
CREATE TABLE public.codeblock
(
        id int4 NULL,
        body text NULL
);

Text File
-----------
Id,Body
1,"{}
\.
"


Command
--------------
psql.exe --host  --command "\copy public.codeblock from
'c:\tmp\codeblock.csv'  WITH (HEADER, FORMAT CSV, ENCODING 'UTF8', DELIMITER
','   )"

Error Message reads:-

ERROR:  unterminated CSV quoted field
CONTEXT:  COPY codeblock, line 4: "1,"{}
\.
"

The same data works when inserted within an insert statement:-

delete

from public.codeblock

where id = 1;

insert into public.codeblock
(
    Id,Body
)
values
(

  1
  ,'{}
\.
'
)
;

It also works when the server-side copy statement is used:-

psql.exe --host  --command "copy public.codeblock from
'c:\tmp\codeblock.csv'  WITH (HEADER, FORMAT CSV, ENCODING 'UTF8', DELIMITER
','   )"

In the example above, \copy is replaced with the copy command and file is
availed on the server.

Data file availed at

1) One Compiler

https://onecompiler.com/text/44dbtdb52

2) GitLab

https://gitlab.com/-/snippets/5933548





Re: BUG #19403: psql fails when trying to import a file that

От
Tom Lane
Дата:
PG Bug reporting form <noreply@postgresql.org> writes:
> Text File
> -----------
> Id,Body
> 1,"{}
> \.
> "

It is expected and documented that v17 (and older) psql will treat
the \. line as an end-of-data marker, CSV mode or not.

We did improve that in v18, but it was judged too much of a behavior
change to back-patch.

            regards, tom lane