aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/copyto.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-03-10 13:52:28 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-03-10 13:52:28 -0500
commit53a53ea332131b3d29d8d69e1dc2823f4d6ff21a (patch)
tree2667de68eec9846a477c7fc16ffe05bf27add910 /src/backend/commands/copyto.c
parentd811d74be353283a3c8282b46a0a6e75e89de5f9 (diff)
downloadpostgresql-53a53ea332131b3d29d8d69e1dc2823f4d6ff21a.tar.gz
postgresql-53a53ea332131b3d29d8d69e1dc2823f4d6ff21a.zip
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
Diffstat (limited to 'src/backend/commands/copyto.c')
-rw-r--r--src/backend/commands/copyto.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c
index b6a4b77053a..a9f422b71ce 100644
--- a/src/backend/commands/copyto.c
+++ b/src/backend/commands/copyto.c
@@ -508,8 +508,8 @@ BeginCopyTo(ParseState *pstate,
/*
* With row-level security and a user using "COPY relation TO", we
* have to convert the "COPY relation TO" to a query-based COPY (eg:
- * "COPY (SELECT * FROM relation) TO"), to allow the rewriter to add
- * in any RLS clauses.
+ * "COPY (SELECT * FROM ONLY relation) TO"), to allow the rewriter to
+ * add in any RLS clauses.
*
* When this happens, we are passed in the relid of the originally
* found relation (which we have locked). As the planner will look up