Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wCbzK-0029nn-09 for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Apr 2026 11:31:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wCbzG-00BYiA-2F for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Apr 2026 11:31:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wCbzG-00BYhZ-0v for pgsql-hackers@lists.postgresql.org; Tue, 14 Apr 2026 11:31:23 +0000 Received: from mail-yw1-x1135.google.com ([2607:f8b0:4864:20::1135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wCbzE-00000000xme-49l2 for pgsql-hackers@lists.postgresql.org; Tue, 14 Apr 2026 11:31:22 +0000 Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-79853c0f5b9so72868057b3.0 for ; Tue, 14 Apr 2026 04:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776166281; cv=none; d=google.com; s=arc-20240605; b=jSm68ZaNx3ugFNYwYCpvvhU2kqKPbbsvDvBA4BWUExzSE7ngFKI8x28D7HWh65KDlU 1UPY8kKPnjMTWLWRkjRiW7O3xWbvF8ON33gL7i3LnbocFv+BcgWKznN3GaEnmIwT0Xcr ru8xsRd/hIH9zyClLdHKzBe2qVicVGTXam3ncGnvXKAslA71PgzGxkBkQ6m4wQcnefFa r8iqdu8VrsgbyRlPWqyUWZ6+yQHoH6JjV4O7gfF2CcHgObGZslQAOyQOBRUHarDJ4PiT niXcDS0NDfwFu/x2gm9s2JNT/b1FT0wuC93MdIFFnzR/evMBL3UDoT+RsFvVJl1ch97v sbYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=UVySICeMj8NRRllPhDKLaR6tbdA5spB1PhVTnvr0iyQ=; fh=mYdvbX08B0m4k6jqdEKrAvsp+tiub7CZzhFp+rPrGQs=; b=KKXzAEQYDn+7XdjoUFH6YPPUtlvG5pJt465ej7GhAm0k6eoeDTK4RLSzsi/WwdtLgS mwo7Q3PIU8Jqj5VVXGB4Ho5oyXjuV6XAO4PnPowKn6eh86KS+p1W9zlFKcKPdB+1KNSC YV3NV4n+BxRr+mP9lXM4v65hBozjq9DqWJZ36G/TolfEdfjaixWYPCg/zkY07hLyfXh+ NUFRUTrAQDe5HL8ACUgv24+cHReEKiBU3Hltb9p/1HxwN5omHURRE/YrHe7c4x0Z8+YZ Yp2fCADXPb7e2Y1IiTv9GQMSv2dNQb4932lVey3YHzasjYCYlTiSAwxxRVE5Qur7LVBw 8jBg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776166281; x=1776771081; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=UVySICeMj8NRRllPhDKLaR6tbdA5spB1PhVTnvr0iyQ=; b=s+w/0q9x6yMUj15etNTZhDpBG4MNtC9c+t3Z7MuGYTwChUzbnqY23ZAXPCIZY86MWx W4RLhyhKQZtNT9ZvJNntHIRz3lvoCaKQEDHzMnHFCLU5mI9n7lYQv3/o0tvwXgO/0etN 0dN5yu1rfpHkIDV3Zw7ZueSb4MuN7GzBBXSUwnUPR2klCAeLXuGkBDFd2SRGE0H+CL02 r0VxhP6hOI0EE1CM1KGltA4LrwB5ZS6HQeZBs15V3nyFgaT7E0t70fZMm87R2w/VvFli 04KhbWqwsC1zXVI/6u1wwzy96FDUg2z/lz27XFKMkdboT7ronrtxHmj7BW2HwLIRIXHh 7TWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776166281; x=1776771081; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UVySICeMj8NRRllPhDKLaR6tbdA5spB1PhVTnvr0iyQ=; b=ifV76OLiA8KwdVbbZ12bhgugqyKQtX7xVpumHDriZGLKcqLf0iYeVhuNlvLmxSkrlj svwWC5vNkWGF1DsKsIGnj/fh1oOyAzpqI+gayecUHTWa2NCtt3m2damzkMvxAIqBr6ns j4AUGZn9hjDbW3NG9SMxhvfr7lMWSX/FRgavSjyyA3nZCQrI2/D8JM+f7QnC3Wp1ihD6 +nP1Bx4j3fY/Tc/WcuS/QHYs4y4D6/+ydDknDrpiO1OJlQnZzbxFlUX2MTJfL4kS3tv0 hFvC3J9NI4vizsWtESAt35tjmKUeIfJfwPKEziGqbzOdUKh2U+FAzYUSyfCUqxBTZEQM +uQA== X-Gm-Message-State: AOJu0Yx30RqoewGvxtW3VjpIdmqHedmtudlQ1R629Qx+kjctvi4jgyCo tRWqg657KcDGVlm0HagIJjqKbjsyqOqPZJXeOW4dZSOXThahE/vvBasOhAySFXLNcz8WYWsuT76 m1y53YwLX5t7WjWdXxzBxw2FqOhhAE7M= X-Gm-Gg: AeBDievHv9PmfDUeOWakm+H/Pr/qjq0KmMIp6ctYf/4ddQFclI2IlUupGJFnk/VRvV/ 134wjseJRLVHIgSiL+geUT6v6HuHjCvNIAEvcO6AzE1/jN+6Mk0J8gQyQGuIPKy+mGqULr2JKQB TeALz0bks59TOhwU5C5Zy6QWOS3o4Oya1/evJksGvSBdgULZ3KeF5/uL1wSZh07rMJxeT0BG8rf njiTy5ZBEIEcaDYo3WfsfFkrJvuSyJObOgj+3wt1iQpApLE1DbzDOB3H7NBCw5jFhiZYr0/t4fd r4MXeekFG953CioBqNm4g7pogAOZp8JFICYL04e+og== X-Received: by 2002:a05:690c:680f:b0:7a3:7ad3:3ecf with SMTP id 00721157ae682-7af714783a6mr184674647b3.26.1776166280561; Tue, 14 Apr 2026 04:31:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: vignesh C Date: Tue, 14 Apr 2026 17:01:07 +0530 X-Gm-Features: AQROBzAjEyileLsQ6i64eXpFasw7QNkSJMYwe19hfIYACh34OQLVZhnDtP5nsEM Message-ID: Subject: Re: Support EXCEPT for TABLES IN SCHEMA publications To: Nisha Moond Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 14 Apr 2026 at 12:00, Nisha Moond wrote: > > Hi hackers, > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > publications, starting this thread to extend the same capability to > schema-level publications (TABLES IN SCHEMA). > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > way to exclude a subset. Users who want to skip a few tables must > switch to an explicit FOR TABLE list, which loses the convenience of > schema-level publishing and requires ongoing maintenance as tables are > added. > > Proposed syntax: > ------------------------ > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > ambiguity and must belong to the published schema; otherwise, an error > is raised. > > Rules and behavior: > ---------------------------- > 1) TABLES IN SCHEMA can be combined with FOR TABLE, but EXCEPT applies > only to the schema clause and must appear immediately after it. > > Supported: > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), TABLE s2.t1; > CREATE PUBLICATION pub FOR TABLE s2.t1, TABLES IN SCHEMA s1 EXCEPT (s1.t1); > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), s2 > EXCEPT (s2.t1) > > Not supported: > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, TABLE s2.t1 EXCEPT (s1.t1); > > -- This same rule applies to ALTER PUBLICATION ... ADD/SET. > > 2) Conflicting definitions > Specifying the same table both in the EXCEPT clause and explicitly in > the TABLE clause results in an error, as this creates a conflicting > definition for the publication. > > 3) "ALTER PUBLICATION ... DROP TABLES IN SCHEMA" does not support > EXCEPT clause. Whereas, dropping a schema also removes any associated > entries from the EXCEPT list of the publication. > -- To only remove/update except list entries, use SET instead. > > 4) Consistency with ALL TABLES EXCEPT rules: > 4a) Excluding a partitioned root excludes all its partitions > 4b) Individual partitions cannot be excluded directly; exclude the root table. > 4c) Excluding an inheritance parent (without ONLY) also excludes its children. > > The patches are divided into three parts to simplify review: > Patch-001: Basic framework to support EXCEPT in CREATE PUBLICATION > ... TABLES IN SCHEMA > Patch-002: Extend support to ALTER PUBLICATION ... ADD TABLES IN SCHEMA > Patch-003: Extend support to ALTER PUBLICATION ... SET TABLES IN SCHEMA > > The patches are attached, feedback and suggestions are welcome. +1 for this. Few comments for the first patch: 1) This should be collected only if except relation was specified, we can skip it if it is not specified: + /* + * Collect explicit table OIDs now, before we close the relation + * list, so that except-table validation below can check for + * contradictions without relying on a catalog scan that might not + * yet see the just-inserted rows. + */ + foreach(lc, rels) + { + PublicationRelInfo *pri = (PublicationRelInfo *) lfirst(lc); + + explicitrelids = lappend_oid(explicitrelids, + RelationGetRelid(pri->relation)); + } 2) Tab completion for except table of that particular schema lists other schema, but currently specifying other schema tables is not allowed: + else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLES", "IN", "SCHEMA", MatchAny, "EXCEPT", "(")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); Can we list only the tables from the specified schema. 3) Can this check be done at parser itself, it can be done in preprocess_pubobj_list parser function to detect the error early: + /* + * For TABLES IN SCHEMA publications, require schema-qualified + * names to avoid ambiguity when multiple schemas in the + * publication have identically-named tables. + */ + foreach(lc, exceptrelations) + { + PublicationTable *t = (PublicationTable *) lfirst(lc); + + if (t->relation->schemaname == NULL) + ereport(ERROR, + errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("table \"%s\" in EXCEPT clause must be schema-qualified", + t->relation->relname)); + } 4) This error message does not seems to be conveying the correct error message: postgres=# create publication pub1 for tables in schema sch3 except ( sch3.t1 ) ; CREATE PUBLICATION postgres=# alter publication pub1 add table sch3.t1 ; ERROR: relation "t1" is already member of publication "pub1" How about an error message like: ERROR: table "sch3.t1" cannot be added explicitly because it is listed in the EXCEPT clause of schema "sch3" in publication "pub1" 5) This change is not related to this patch: @@ -5279,7 +5315,7 @@ foreach my $run (sort keys %pgdump_runs) # # Either "all_runs" should be set or there should be a "like" list, # even if it is empty. (This makes the test more self-documenting.) - if (!defined($tests{$test}->{all_runs}) + if ( !defined($tests{$test}->{all_runs}) && !defined($tests{$test}->{like})) { die "missing \"like\" in test \"$test\""; 6) There is an indentation issue here: - pub_except_obj_list opt_pub_except_clause + pub_except_obj_list pub_schema_except_obj_list + opt_pub_except_clause opt_pub_schema_except_clause Regards, Vignesh