Fix RLS with COPY (col1, col2) FROM tab

Stephen Frost <sfrost@snowman.net>

Commit: 647a86e374d2eb01d8cdda2fc759a770b38cc232
Author: Stephen Frost <sfrost@snowman.net>
Date: 2016-10-03T20:23:12Z
Releases: 9.5.5
Fix RLS with COPY (col1, col2) FROM tab

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.

Patch-By: Adam Brightwell
Reviewed-By: Michael Paquier

Files

PathChange+/−
src/backend/commands/copy.c modified +51 −12
src/test/regress/expected/copy2.out modified +78 −0
src/test/regress/sql/copy2.sql modified +63 −0