Re: Data loss when '"json_populate_recorset" with long column name

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: Денис Романенко <deromanenko(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Data loss when '"json_populate_recorset" with long column name
Date: 2021-09-07 05:11:49
Message-ID: CAOBaU_az1=4u1StekruHK6axoJaAcGG7czAGdhNZrhKryWcVAw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Sep 7, 2021 at 11:27 AM Денис Романенко <deromanenko(at)gmail(dot)com> wrote:
>
> If we create a column name longer than 64 bytes, it will be truncated in PostgreSQL to max (NAMEDATALEN) length.
>
> For example: "VeryLongNameVeryLongNameVeryLongNameVeryLongNameVeryLongNameVeryLongName" will be truncated in database to "VeryLongNameVeryLongNameVeryLongNameVeryLongNameVeryLongNameVer"
>
> But in the codebase we could work with full column name - SQL functions like INSERT/UPDATE work with long names without problem, automatically searches for suitable column (thank you for it).
>
> But if we try to update it with "json_populate_recordset" using full name, it will not just ignore column with long name - data in that record will be nulled.
>
> How to reproduce:
> 1. create table wow("VeryLongNameVeryLongNameVeryLongNameVeryLongNameVeryLongNameVeryLongName" text);
> 2. select * from json_populate_recordset(null::wow,'[{"VeryLongNameVeryLongNameVeryLongNameVeryLongNameVeryLongNameVeryLongName": "haha"}]');
> 3. "VeryLongNameVeryLongNameVeryLongNameVeryLongNameVeryLongNameVer" becomes null.

Yes, that's because json identifiers have different rules from
relation identifiers. Your only option here is to use the real /
truncated identifier. Also I don't think it would be a good thing to
add a way to truncate identifiers in json objects using the
NAMEDATALEN limit, as this could easily lead to invalid json object
that should be valid.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2021-09-07 05:28:16 Re: when the startup process doesn't (logging startup delays)
Previous Message Amit Kapila 2021-09-07 05:00:18 Re: Column Filtering in Logical Replication