Skip to content
Discussion options

You must be logged in to vote

Hi @andreasvh-conceto 👋

One way to get the transactionId of a TransactionClient inside an interactive transaction will be to do something like

await prisma.$transaction(async (tx) => {
  const txId = await prisma.$executeRaw`SELECT txid_current()`;
  console.log('Transaction ID:', txId);
});

The output is

prisma:query BEGIN
prisma:query SELECT txid_current()
Transaction ID: 1
prisma:query COMMIT

This code uses the txid_current() function provided by PostgreSQL to get the current transaction ID. The SELECT statement is executed within the transaction context using $executeRaw(), and the resulting ID is logged to the console.

You can also open a feature request to add support for getting tr…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by andreasvh-conceto
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants