Fix RLS with COPY (col1, col2) FROM tab

Enterprise / PostgreSQL - Stephen Frost [snowman.net] - 3 October 2016 15:22 UTC

Attempting to COPY a subset of columns from a table with RLS enabled would fail due to an invalid query being constructed (using a single ColumnRef with the list of fields to exact in 'fields', but that's for the different levels of an indirection for a single column, not for specifying multiple columns).

Correct by building a ColumnRef and then RestTarget for each column being requested and then adding those to the targetList for the select query. Include regression tests to hopefully catch if this is broken again in the future.

814b9e9 Fix RLS with COPY (col1, col2) FROM tab
src/backend/commands/copy.c | 63 ++++++++++++++++++++++------
src/test/regress/expected/copy2.out | 78 +++++++++++++++++++++++++++++++++++
src/test/regress/sql/copy2.sql | 63 ++++++++++++++++++++++++++++
3 files changed, 192 insertions(+), 12 deletions(-)

Upstream: git.postgresql.org


  • Share