Ensure COPY TO on an RLS-enabled table copies no more than it should.

Tom Lane <tgl@sss.pgh.pa.us>

Commit: 6e2674d772b017f4ad4e36394aa1cf64c05b46e5
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2023-03-10T18:52:28Z
Releases: 11.20
Ensure COPY TO on an RLS-enabled table copies no more than it should.

The COPY documentation is quite clear that "COPY relation TO" copies
rows from only the named table, not any inheritance children it may
have.  However, if you enabled row-level security on the table then
this stopped being true, because the code forgot to apply the ONLY
modifier in the "SELECT ... FROM relation" query that it constructs
in order to allow RLS predicates to be attached.  Fix that.

Report and patch by Antonin Houska (comment adjustments and test case
by me).  Back-patch to all supported branches.

Discussion: https://postgr.es/m/3472.1675251957@antos

Files

Discussion