Bug: trailing comma syntax error in postgres_fdw fetch_attstats()

Started by SATYANARAYANA NARLAPURAM18 days ago3 messageshackers
Jump to latest
#1SATYANARAYANA NARLAPURAM
satyanarlapuram@gmail.com

Hi Hackers,

When importing statistics from a remote server running PostgreSQL < 17,
fetch_attstats() emits three NULL placeholders for the range statistics
columns that don't exist on older servers. The string literal included a
trailing
comma after the last NULL, producing invalid SQL:

SELECT ... NULL, NULL, NULL, FROM pg_catalog.pg_stats ...

This fails ANALYZE or IMPORT STATISTICS on a foreign table backed
by a pre-v17 remote server with a syntax error.

Thanks,
Satya

Attachments:

v1-0001-postgres_fdw-fix-trailing-comma.patchapplication/octet-stream; name=v1-0001-postgres_fdw-fix-trailing-comma.patchDownload+1-1
#2Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: SATYANARAYANA NARLAPURAM (#1)
Re: Bug: trailing comma syntax error in postgres_fdw fetch_attstats()

On Sun, Apr 12, 2026 at 10:45 AM SATYANARAYANA NARLAPURAM
<satyanarlapuram@gmail.com> wrote:

When importing statistics from a remote server running PostgreSQL < 17,
fetch_attstats() emits three NULL placeholders for the range statistics
columns that don't exist on older servers. The string literal included a trailing
comma after the last NULL, producing invalid SQL:

SELECT ... NULL, NULL, NULL, FROM pg_catalog.pg_stats ...

This fails ANALYZE or IMPORT STATISTICS on a foreign table backed
by a pre-v17 remote server with a syntax error.

My bad, I will take care of this. I added it to the open item.

Thanks for the report and patch!

Best regards,
Etsuro Fujita

#3Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Etsuro Fujita (#2)
Re: Bug: trailing comma syntax error in postgres_fdw fetch_attstats()

On Sun, Apr 12, 2026 at 3:40 PM Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

On Sun, Apr 12, 2026 at 10:45 AM SATYANARAYANA NARLAPURAM
<satyanarlapuram@gmail.com> wrote:

When importing statistics from a remote server running PostgreSQL < 17,
fetch_attstats() emits three NULL placeholders for the range statistics
columns that don't exist on older servers. The string literal included a trailing
comma after the last NULL, producing invalid SQL:

SELECT ... NULL, NULL, NULL, FROM pg_catalog.pg_stats ...

This fails ANALYZE or IMPORT STATISTICS on a foreign table backed
by a pre-v17 remote server with a syntax error.

My bad, I will take care of this.

The patch looks good to me. I will push it if there are no objections.

Best regards,
Etsuro Fujita