Re: SQL/JSON features for v15

From: Nikita Glukhov <n(dot)gluhov(at)postgrespro(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Amit Langote <amitlangote09(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>, John Naylor <john(dot)naylor(at)enterprisedb(dot)com>
Subject: Re: SQL/JSON features for v15
Date: 2022-08-31 20:39:31
Message-ID: 379e5365-9670-e0de-ee08-57ba61cbc976@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 31.08.2022 20:14, Tom Lane wrote:
> Robert Haas<robertmhaas(at)gmail(dot)com> writes:
>> On Wed, Aug 31, 2022 at 1:06 PM Tom Lane<tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> The currently proposed patchset hacks up a relatively small number
>>> of core datatypes to be able to do that. But it's just a hack
>>> and there's no prospect of extension types being able to join
>>> in the fun. I think where we need to start, for v16, is making
>>> an API design that will let any datatype have this functionality.
>>>
>>> (I don't say that we'd convert every datatype to do so right away;
>>> in the long run we should, but I'm content to start with just the
>>> same core types touched here.) Beside the JSON stuff, there is
>>> another even more pressing application for such behavior, namely
>>> the often-requested COPY functionality to be able to shunt bad data
>>> off somewhere without losing the entire transfer. In the COPY case
>>> I think we'd want to be able to capture the error message that
>>> would have been issued, which means the current patches are not
>>> at all appropriate as a basis for that API design: they're just
>>> returning a bool without any details.
>>>
>> I would be in favor of making more of an effort than just a few token
>> data types. The initial patch could just touch a few, but once the
>> infrastructure is in place we should really make a sweep through the
>> tree and tidy up.
> Sure, but my point is that we can do that in a time-extended fashion
> rather than having a flag day where everything must be updated.
> The initial patch just needs to update a few types as proof of concept.
>
And here is a quick POC patch with an example for COPY and float4:

=# CREATE TABLE test (i int, f float4);
CREATE TABLE

=# COPY test (f) FROM stdin WITH (null_on_error (f));
1
err
2
\.

COPY 3

=# SELECT f FROM test;
f
---
1

2
(3 rows)

=# COPY test (i) FROM stdin WITH (null_on_error (i));
ERROR: input function for datatype "integer" does not support error handling

PG_RETURN_ERROR() is a reincarnation of ereport_safe() macro for returning
ErrorData, which was present in older versions (~v18) of SQL/JSON patches.
Later it was replaced with `bool *have_error` and less magical
`if (have_error) ... else ereport(...)`.

Obviously, this needs a separate thread.

--
Nikita Glukhov
Postgres Professional:http://www.postgrespro.com
The Russian Postgres Company

Attachment Content-Type Size
0001-Introduce-PG_RETURN_ERROR-and-FuncCallError-node.patch text/x-patch 2.0 KB
0002-Introduce-pg_proc.proissafe-and-func_is_safe.patch text/x-patch 2.2 KB
0003-Use-PG_RETURN_ERROR-in-float4in.patch text/x-patch 2.3 KB
0004-Introduce-InputFunctionCallOptError.patch text/x-patch 2.8 KB
0005-Introduce-NULL_ON_ERROR-option-for-COPY-FROM.patch text/x-patch 7.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2022-08-31 20:53:38 Re: Reducing the chunk header sizes on all memory context types
Previous Message Jonathan S. Katz 2022-08-31 20:18:00 Re: SQL/JSON features for v15