Subject: execution id

From: "Voillequin, Jean-Marc" <[email-masked]>
Date: Tue, 30 Aug 2022 16:22:45 +0000

Hello guys,

Is there a kind of magical system administration function that returns a unique id each time a select/insert/update/delete statement is launched?

Assuming x is a table with several rows:

select pg_magical_exec_id() from x;

  *   returns 1 for each row

insert into x select pg_magical_exec_id() from x;

  *   pg_magical_exec_id()=2

Select 1 from x where pg_magical_exec_id()>0;

  *   pg_magical_exec_id=3

Select pg_magical_exec_id() from x;

  *   returns 4 for each row

And even, in a transaction:

Begin;
delete from x where ...;

  *   pg_magical_exec_id=5
update x set ... ;

  *   pg_magical_exec_id=6
End;

Select pg_magical_exec_id() from x;

  *   returns 7 for each row

I can understand it is a strange question!
There is a txid_current() function that could fit, but the transaction id does not change within a transaction.

----------------------------------------------------------------------
Moody's monitors email communications through its networks for regulatory compliance purposes and to protect its customers, employees and business and where allowed to do so by applicable law. The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.

---

From: "David G. Johnston" <[email-masked]>
Date: Tue, 30 Aug 2022 09:26:51 -0700

On Tue, Aug 30, 2022 at 9:23 AM Voillequin, Jean-Marc <
[email-masked]> wrote:

> Hello guys,
>
>
>
> Is there a kind of magical system administration function that returns a
> unique id each time a select/insert/update/delete statement is launched?
>
>
>

Not sure why you thought the "SQL" list was a good choice for this
question...but assuming you actually want something exposed to SQL the
answer would be no.  Internal state management (the "CommandCounter" as I
believe it is called) is an implementation artifact not exposed to the DBA.

David J.

---

From: "Voillequin, Jean-Marc" <[email-masked]>
Date: Tue, 30 Aug 2022 16:32:29 +0000

I thought it was the good list because I was looking for a sql/pqsql function.
What a pitty!
The command counter was probably what I was looking for.
Thanks David.

From: David G. Johnston <[email-masked]>
Sent: Tuesday, August 30, 2022 6:27 PM
To: Voillequin, Jean-Marc <[email-masked]>
Cc: [email-masked]
Subject: Re: execution id

On Tue, Aug 30, 2022 at 9: 23 AM Voillequin, Jean-Marc <Jean-Marc. Voillequin@ moodys. com> wrote: Hello guys,   Is there a kind of magical system administration function that returns a unique id each time a select/insert/update/delete statement
ZjQcmQRYFpfptBannerStart
This email originated from outside of Moody's
Do not click links or open attachments unless you recognize the sender and know the content is safe.
ZjQcmQRYFpfptBannerEnd
On Tue, Aug 30, 2022 at 9:23 AM Voillequin, Jean-Marc <[email-masked]<mailto:[email-masked]>> wrote:
Hello guys,

Not sure why you thought the "SQL" list was a good choice for this question...but assuming you actually want something exposed to SQL the answer would be no.  Internal state management (the "CommandCounter" as I believe it is called) is an implementation artifact not exposed to the DBA.

David J.

---

From: hubert depesz lubaczewski <[email-masked]>
Date: Tue, 30 Aug 2022 18:55:23 +0200

> Is there a kind of magical system administration function that returns a unique id each time a select/insert/update/delete statement is launched?

What is the usecase?

You can get something like this with statement_timestamp()

Best regards,

depesz