Re: Support EXCEPT for ALL SEQUENCES publications - Mailing list pgsql-hackers

From Shlok Kyal
Subject Re: Support EXCEPT for ALL SEQUENCES publications
Date
Msg-id CANhcyEUmDrWf-cUe9s0OCLvAtLUSNy347nL-8FWqbax+JD4yiA@mail.gmail.com
Whole thread
In response to Re: Support EXCEPT for ALL SEQUENCES publications  (Ashutosh Sharma <ashu.coek88@gmail.com>)
Responses Re: Support EXCEPT for ALL SEQUENCES publications
List pgsql-hackers
On Fri, 3 Jul 2026 at 11:24, Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>
> Hi,
>
> On Thu, Jul 2, 2026 at 11:53 AM Shlok Kyal <shlok.kyal.oss@gmail.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

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: libpq: Process buffered SSL read bytes to support records >8kB on async API
Next
From: Robert Haas
Date:
Subject: Re: implement CAST(expr AS type FORMAT 'template')