Re: Use pg_current_xact_id() instead of deprecated txid_current() - Mailing list pgsql-hackers

From Shinya Kato
Subject Re: Use pg_current_xact_id() instead of deprecated txid_current()
Date
Msg-id CAOzEurQdzTDmAVecoF05FUD8_cJLrnrX384o-xgxYOp=2xTpYA@mail.gmail.com
Whole thread
In response to Re: Use pg_current_xact_id() instead of deprecated txid_current()  (Shinya Kato <shinya11.kato@gmail.com>)
List pgsql-hackers
On Mon, Feb 9, 2026 at 9:07 PM Shinya Kato <shinya11.kato@gmail.com> wrote:
>
> On Mon, Feb 9, 2026 at 1:24 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >
> > =?UTF-8?Q?=C3=81lvaro_Herrera?= <alvherre@kurilemu.de> writes:
> > > On 2026-02-08, Shinya Kato wrote:
> > >> Since pg_current_xact_id() returns xid8 which does not support
> > >> arithmetic operators, places that need "xid + 1" cast the result via
> > >> ::text::bigint first.
> >
> > > I think it may be better to add some operators, or was there a rationale for these not being there?
> >
> > I'm fairly concerned about overloading the arithmetic operators with
> > unsigned versions.  The reason we never invented SQL-level uint8 and
> > such is fear of getting a lot of "ambiguous operator" errors.  Now,
> > if we are careful not to create implicit casts between xid[8] and
> > any ordinary type, maybe it'd be okay to invent xid+int, xid8-int,
> > and a few more.
>
> Got it. I’ll give it a try, thanks.

I have added the + and - operators for the xid8 type in the v2-0001
patch. This allows for direct arithmetic and eliminates the need for
casting through text and bigint. Specifically, I implemented:

  xid8 + int8 -> xid8
  int8 + xid8 -> xid8
  xid8 - int8 -> xid8
  xid8 - xid8 -> int8

Additionally, the v2-0002 patch removes the existing ::text::bigint
casts where they are no longer necessary.

--
Best regards,
Shinya Kato
NTT OSS Center

Attachment

pgsql-hackers by date:

Previous
From: wenhui qiu
Date:
Subject: Re: Add 64-bit XIDs into PostgreSQL 15
Next
From: shveta malik
Date:
Subject: Re: Improve pg_sync_replication_slots() to wait for primary to advance