Re: copying json data and backslashes - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: copying json data and backslashes
Date
Msg-id 20221122181550.lgobhgfzvtgp7jes@hjp.at
Whole thread Raw
In response to Re: copying json data and backslashes  (Alastair McKinley <a.mckinley@analyticsengines.com>)
Responses Re: copying json data and backslashes  ("pbj@cmicdo.com" <pbj@cmicdo.com>)
List 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@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

pgsql-general by date:

Previous
From: Alastair McKinley
Date:
Subject: Re: copying json data and backslashes
Next
From: Ted Toth
Date:
Subject: security label and indexes