Re: Support EXCEPT for ALL SEQUENCES publications

From: Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>
To: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, shveta malik <shveta(dot)malik(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Support EXCEPT for ALL SEQUENCES publications
Date: 2026-07-03 09:48:02
Message-ID: CANhcyEUmDrWf-cUe9s0OCLvAtLUSNy347nL-8FWqbax+JD4yiA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 3 Jul 2026 at 11:24, Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com> wrote:
>
> Hi,
>
> On Thu, Jul 2, 2026 at 11:53 AM Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com> wrote:
> >
> > Please find the updated v17 patch attached.
> >
>
> Thank you for the updated patches. I see that the following command
> works with your patch:
>
> CREATE PUBLICATION combined_seq_pub_1
> FOR ALL SEQUENCES
> EXCEPT (SEQUENCE ONLY s1_seq);
>
> May I know what the purpose of ONLY is here?
>
> AFAIU, for FOR ALL TABLES, ONLY was added to handle inherited tables.
> However, sequences do not have inheritance, so I am not sure what
> semantics ONLY is intended to provide for sequences. Could you please
> clarify?
It was unintentional. ONLY should not be allowed with SEQUENCE.
This happened because, in gram.y, the EXCEPT SEQUENCE production uses
relation_expr:
+PublicationExceptSeqSpec:
+ relation_expr
+ {
+ $$ = makeNode(PublicationObjSpec);
+ $$->pubobjtype = PUBLICATIONOBJ_EXCEPT_SEQUENCE;
+ $$->pubrelation = makeNode(PublicationRelation);
+ $$->pubrelation->except = true;
+ $$->pubrelation->relation = $1;
+ $$->location = @1;
+ }
+ ;
relation_expr accepts ONLY, so it inadvertently allows syntax such as
EXCEPT (SEQUENCE ONLY s1).
I think it would be better to use qualified_name instead. That's also
what CREATE SEQUENCE uses, so it would be consistent with the rest of
the grammar and would prevent ONLY from being accepted.

With this change we are now throwing syntax error:
postgres=# CREATE PUBLICATION combined_seq_pub_1
FOR ALL SEQUENCES
EXCEPT (SEQUENCE ONLY s1_seq);
ERROR: syntax error at or near "ONLY"
LINE 3: EXCEPT (SEQUENCE ONLY s1_seq);

While making the change, I also found that I missed updating the
comments in gram.y for this feature.
I have updated the same and attached the updated v18 patches.

Thanks,
Shlok Kyal

Attachment Content-Type Size
v18-0001-Support-EXCEPT-for-ALL-SEQUENCES-in-CREATE-PUBLI.patch application/octet-stream 67.1 KB
v18-0002-Support-EXCEPT-for-ALL-SEQUENCES-in-ALTER-PUBLIC.patch application/octet-stream 34.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2026-07-03 09:49:46 Re: implement CAST(expr AS type FORMAT 'template')
Previous Message Etsuro Fujita 2026-07-03 09:47:54 Re: use of SPI by postgresImportForeignStatistics