Re: Emitting JSON to file using COPY TO

Поиск
Список
Период
Сортировка
От Davin Shearer
Тема Re: Emitting JSON to file using COPY TO
Дата
Msg-id CALvfUkDxgTppjy-Q_i2znakMFp2vrJdPUEJNyGTL2LcZBOWV6A@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Emitting JSON to file using COPY TO  (Andrew Dunstan <andrew@dunslane.net>)
Ответы Re: Emitting JSON to file using COPY TO
Re: Emitting JSON to file using COPY TO
Список pgsql-hackers
Sorry about the top posting / top quoting... the link you sent me gives me a 404.  I'm not exactly sure what top quoting / posting means and Googling those terms wasn't helpful for me, but I've removed the quoting that my mail client is automatically "helpfully" adding to my emails.  I mean no offense.

Okay, digging in more...

If the value contains text that has BOMs [footnote 1] in it, it must be preserved (the database doesn't need to interpret them or do anything special with them - just store it and fetch it).  There are however a few characters that need to be escaped (per https://www.w3docs.com/snippets/java/how-should-i-escape-strings-in-json.html) so that the JSON format isn't broken.  They are:

  1. " (double quote)
  2. \ (backslash)
  3. / (forward slash)
  4. \b (backspace)
  5. \f (form feed)
  6. \n (new line)
  7. \r (carriage return)
  8. \t (horizontal tab)

These characters should be represented in the test cases to see how the escaping behaves and to ensure that the escaping is done properly per JSON requirements.  Forward slash comes as a bit of a surprise to me, but `jq` handles it either way:


➜ echo '{"key": "this / is a forward slash"}' | jq .
{
  "key": "this / is a forward slash"
}
➜ echo '{"key": "this \/ is a forward slash"}' | jq .
{
  "key": "this / is a forward slash"
}

Hope it helps, and thank you!

1. I don't disagree that BOMs shouldn't be used for UTF-8, but I'm also processing UTF-16{BE,LE} and UTF-32{BE,LE} (as well as other textural formats that are neither ASCII or Unicode).  I don't have the luxury of changing the data that is given.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: Remove MSVC scripts from the tree
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: PATCH: Add REINDEX tag to event triggers