Re: plpgsql: remove a field from a record?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "Ray O'Donnell" <ray(at)rodonnell(dot)ie>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: plpgsql: remove a field from a record?
Date: 2025-12-27 16:14:04
Message-ID: CAFj8pRAKQ6qN-TkNWpFg5Gnsbkzwpo9YgnXJvUY2_GSeO1jdcA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

so 27. 12. 2025 v 17:01 odesílatel Ray O'Donnell <ray(at)rodonnell(dot)ie> napsal:

> Hi all,
>
> In a plpgsql function, is it possible to remove a field from a RECORD
> value?
>
> My specific use-case is that I have a row returned from a MERGE
> operation into a variable, declared as type RECORD, which will then be
> logged; and I want to remove some potentially sensitive stuff from it
> before it gets logged.
>
> I could manually redact the sensitive items (e.g. set them to null); but
> it'd be tidier just to remove them altogether if I can.
>
> Thanks in advance,
>

I think so it is not possible - not directly. Maybe you can use jsonb or
hstore

(2025-12-27 17:12:06) postgres=# create type t as (a int, b int);
(2025-12-27 17:12:24) postgres=# select * from
jsonb_to_record(row_to_json(row(10,20)::t)::jsonb - 'a') as (b int);
┌────┐
│ b │
╞════╡
│ 20 │
└────┘
(1 row)

Regards

Pavel

>
> Ray.
>
> --
> Ray O'Donnell // Galway // Ireland
> ray(at)rodonnell(dot)ie
>
>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ray O'Donnell 2025-12-27 16:14:52 Re: plpgsql: remove a field from a record?
Previous Message Adrian Klaver 2025-12-27 16:13:30 Re: plpgsql: remove a field from a record?