public inbox for [email protected]  
help / color / mirror / Atom feed
plpgsql: remove a field from a record?
3+ messages / 3 participants
[nested] [flat]

* plpgsql: remove a field from a record?
@ 2025-12-27 16:01  Ray O'Donnell <[email protected]>
  0 siblings, 2 replies; 3+ messages in thread

From: Ray O'Donnell @ 2025-12-27 16:01 UTC (permalink / raw)
  To: pgsql-general

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 protected]







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: plpgsql: remove a field from a record?
@ 2025-12-27 16:13  Adrian Klaver <[email protected]>
  parent: Ray O'Donnell <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: Adrian Klaver @ 2025-12-27 16:13 UTC (permalink / raw)
  To: Ray O'Donnell <[email protected]>; pgsql-general

On 12/27/25 08:01, Ray O'Donnell wrote:
> 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.

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.

> 
> Thanks in advance,
> 
> Ray.
> 


-- 
Adrian Klaver
[email protected]






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: plpgsql: remove a field from a record?
@ 2025-12-27 16:14  Pavel Stehule <[email protected]>
  parent: Ray O'Donnell <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: Pavel Stehule @ 2025-12-27 16:14 UTC (permalink / raw)
  To: Ray O'Donnell <[email protected]>; +Cc: pgsql-general

Hi

so 27. 12. 2025 v 17:01 odesílatel Ray O'Donnell <[email protected]> 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
> [email protected]
>
>
>
>


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2025-12-27 16:14 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-12-27 16:01 plpgsql: remove a field from a record? Ray O'Donnell <[email protected]>
2025-12-27 16:13 ` Adrian Klaver <[email protected]>
2025-12-27 16:14 ` Pavel Stehule <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox