From dd97443fc585a7a466a1cb1393cf036785c6d19e Mon Sep 17 00:00:00 2001 From: Raphael Guiducci Date: Thu, 5 Jun 2025 12:19:26 +0100 Subject: [PATCH 1/2] Fix: pg_publication_tables query to account for partitioned tables --- postgresql/resource_postgresql_publication.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/postgresql/resource_postgresql_publication.go b/postgresql/resource_postgresql_publication.go index 5c653b67..ac28cff3 100644 --- a/postgresql/resource_postgresql_publication.go +++ b/postgresql/resource_postgresql_publication.go @@ -354,9 +354,15 @@ func resourcePostgreSQLPublicationReadImpl(db *DBConnection, d *schema.ResourceD return fmt.Errorf("Error reading publication info: %w", err) } - query = `SELECT CONCAT(schemaname,'.',tablename) as fulltablename ` + - `FROM pg_catalog.pg_publication_tables ` + - `WHERE pubname = $1` + query = `SELECT DISTINCT ` + + `COALESCE(parent_ns.nspname || '.' || parent_class.relname, ` + + ` pt.schemaname || '.' || pt.tablename) AS fulltablename ` + + `FROM pg_publication_tables pt ` + + `LEFT JOIN pg_class child ON pt.tablename = child.relname ` + + `LEFT JOIN pg_inherits i ON i.inhrelid = child.oid ` + + `LEFT JOIN pg_class parent_class ON i.inhparent = parent_class.oid ` + + `LEFT JOIN pg_namespace parent_ns ON parent_class.relnamespace = parent_ns.oid ` + + `WHERE pt.pubname = $1` rows, err := txn.Query(query, pqQuoteLiteral(PublicationName)) if err != nil { From da789091e58b7925d0ca0d8927a82aa1055e57a3 Mon Sep 17 00:00:00 2001 From: Raphael Guiducci Date: Thu, 5 Jun 2025 12:31:44 +0100 Subject: [PATCH 2/2] Better format query --- postgresql/resource_postgresql_publication.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgresql/resource_postgresql_publication.go b/postgresql/resource_postgresql_publication.go index ac28cff3..8d3fb8fb 100644 --- a/postgresql/resource_postgresql_publication.go +++ b/postgresql/resource_postgresql_publication.go @@ -356,7 +356,7 @@ func resourcePostgreSQLPublicationReadImpl(db *DBConnection, d *schema.ResourceD query = `SELECT DISTINCT ` + `COALESCE(parent_ns.nspname || '.' || parent_class.relname, ` + - ` pt.schemaname || '.' || pt.tablename) AS fulltablename ` + + `pt.schemaname || '.' || pt.tablename) AS fulltablename ` + `FROM pg_publication_tables pt ` + `LEFT JOIN pg_class child ON pt.tablename = child.relname ` + `LEFT JOIN pg_inherits i ON i.inhrelid = child.oid ` +