Re: copying json data and backslashes

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: copying json data and backslashes
Date: 2022-11-22 18:15:50
Message-ID: 20221122181550.lgobhgfzvtgp7jes@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2022-11-22 17:39:04 +0000, Alastair McKinley wrote:
> > \copy footable from 'input.json' (format csv, escape '^B', delimieter '^C', quote '^E')
> >
> > where the control characters are the actual control char, not the
> > caret-letter, and it requires no escaping escapes.  I realize this
> > won't work for all
> > situations.
>
> Thanks for the suggestion, this is interesting to me to try but I am
> not quite sure how this works.
> As far as I understand, escape/quote/delimiter have to be a single
> character, and CTRL-C etc. are multiple characters.

You may have to hit several Keys[1] on your keyboard, but Ctrl-C is a
single character, just like Shift-C is (the former has code 0003, the
latter 0043).

On Unix-like systems you can usually type the control characters by
typing Ctrl-V first:

At the psql prompt, type
select ascii('
then hit V while holding the ctrl key
then hit C while holding the ctrl key
The terminal should display that as ^C
then complete the line with
');
so that it looks like
select ascii('^C');
and hit return:
╔═══════╗
║ ascii ║
╟───────╢
║ 3 ║
╚═══════╝
(1 row)

Same for the other ctrl characters.

hp

[1] There are usually four Ctrl-Characters which need only a single
key: Ctrl-I (TAB), Ctrl-M (CR), Ctrl-[ (ESC) and Ctrl-H (BS) or Ctrl-?
(DEL).

(On Unix systems CR is normally translated to LF, on Windows to CRLF)

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ted Toth 2022-11-22 19:04:22 security label and indexes
Previous Message Alastair McKinley 2022-11-22 17:39:04 Re: copying json data and backslashes