You can inspect the internal
xmin to identify newly inserted row versions (note, that includes results from
SELECT * FROM foo_table
WHERE xmin::text = (txid_current() % (2^32)::bigint)::text;
txid_current() returns the current transaction ID. However, while the internal transaction ID type in
xmin is 32 bits wide and wraps around every 4 billion transactions,
txid_current() returns a
bigint quantity, per documentation:
that is extended with an "epoch" counter so it will not wrap around during the life of an installation.
There is a thread on pgsql-hackers with Tom Lane discussing it.
I derived the safe
WHERE condition from it.
Addressing comment: Deleted rows that were deleted in the same transaction are always invisible either way, so not included in the result.
However, this does not work with subtransactions started with
SAVEPOINT (or some other way, plpython can use subtransactions, too). Those spawn separate xids and there is currently no way to get the full list of xids belonging to the top transaction returned by
txid_current(). In my search for a solution I found this closely related thread on pgsql-hackers:
I don't currently see a reliable solution working around that limitation.