Subject: plpgsql: remove a field from a record?

From: Ray O'Donnell <[email-masked]>
Date: Sat, 27 Dec 2025 16:01:27 +0000

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,

Ray.

-- 
Ray O'Donnell // Galway // Ireland
[email-masked]

---

From: Adrian Klaver <[email-masked]>
Date: Sat, 27 Dec 2025 08:13:30 -0800

> it'd be tidier just to remove them altogether if I can.

A record 'type' supports record_name.field_name notation. Not sure how 
many fields you want to log, but you could log only the non-sensitive 
fields explicitly e.g. record_name.fld1, record_name.fld3, 
record_name.fld4, etc.

-- 
Adrian Klaver
[email-masked]

---

From: Pavel Stehule <[email-masked]>
Date: Sat, 27 Dec 2025 17:14:04 +0100

Hi

> it'd be tidier just to remove them altogether if I can.

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