Re: Fix exclude generated columns in COPY TO with RLS

From: Ayoub Kazar <ayoub(dot)kazar(at)data-bene(dot)io>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Fix exclude generated columns in COPY TO with RLS
Date: 2026-11-05 14:52:23
Message-ID: 1936f1d8-e530-4d03-8af7-c65552153cb3@data-bene.io
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 05/11/2026 12:34, Jim Jones wrote:

> It also changes how COPY TO handles columns that the user has no select privileges on,but
> I'd argue this is an improvement:
>
> create user u login;
> create table t(a int, b int generated always as (a+40) stored, c text);
> insert into t (a,c) values (2,'foo');
> grant select (a,c) on t to u;
> alter table t enable row level security;
> create policy p on t using (true);
>
> == master ==
>
> postgres=# set role u;
> SET
> postgres=> copy t to stdout;
> ERROR: permission denied for table t
>
> == patched ==
>
> postgres=# set role u;
> SET
> postgres=> copy t to stdout;
> 2 foo
> postgres=>
>
> I guess this test could also be added to the regression tests.
You're right! Done in v2.
> BTW, is there another reason to not allow generated columns in COPY TO
> other than being consistent with COPY FROM?
I don't see a reason other than having a consistent behavior for a round
trip of COPY TO/FROM (It makes sense though...)
At least for users who insist on emitting them in output, they can still
do something like COPY (SELECT * FROM t) TO ...

Thanks for the review Jim.

Regards,
Ayoub Kazar

Attachment Content-Type Size
v2-0001-Exclude-generated-columns-in-COPY-TO-with-row-level-security.patch text/x-patch 6.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-11-05 14:57:50 Re: Fix BRIN numeric_minmax_multi_ops out of range value range merging
Previous Message Heikki Linnakangas 2026-11-05 14:41:31 Re: Unlogged bloom indexes break after crash recovery