Re: [PATCH] Fix column name escaping in postgres_fdw stats import - Mailing list pgsql-hackers

From Etsuro Fujita
Subject Re: [PATCH] Fix column name escaping in postgres_fdw stats import
Date
Msg-id CAPmGK17DFQaSGRAkZ2Hm+EsxsrEXVhKNuBzomkbh466i=TMpTg@mail.gmail.com
Whole thread
In response to Re: [PATCH] Fix column name escaping in postgres_fdw stats import  (Alex Guo <guo.alex.hengchen@gmail.com>)
Responses Re: [PATCH] Fix column name escaping in postgres_fdw stats import
List pgsql-hackers
On Tue, Apr 21, 2026 at 3:12 PM Alex Guo <guo.alex.hengchen@gmail.com> wrote:
> On 4/21/26 4:43 AM, Ayush Tiwari wrote:
> The new statistics import feature in postgres_fdw (commit 28972b6fc3d)
> builds a remote query to fetch pg_stats rows, filtering by column name
> with:
>
>   AND attname = ANY('{col1, col2}'::text[])
>
> The column names are formatted with quote_identifier(), which only
> escapes double quotes.  But since the list is embedded inside a
> single-quoted string literal, any single quote in a column name
> breaks the literal and produces a syntax error on the remote server.

> The attached patch switches to an ARRAY[] constructor with each
> element escaped by deparseStringLiteral(), matching how schemaname
> and tablename are already handled in the same function.

Thanks for the report and patch!

> It should also address the issue that was raised in [1].

The root cause of this is the same as [1], so I think you should reply
to the thread, rather than creating a new thread.

> I think the fix makes sense to me. Here, the column names are emitted as string content, thus deparseStringLiteral()
isa better fit. 

+1

> A small comment on the test:
>
> +ANALYZE VERBOSE simport_ft_quote;         -- should work, not syntax error
>
> VERBOSE seems not needed.

I think the option is needed; otherwise we cannot check that stats
import was really done in the test.

Best regards,
Etsuro Fujita



pgsql-hackers by date:

Previous
From: "Zhijie Hou (Fujitsu)"
Date:
Subject: RE: Parallel Apply
Next
From: Nikita Malakhov
Date:
Subject: Re: [(known) BUG] DELETE/UPDATE more than one row in partitioned foreign table