Re: how to get id of currently executed query?

From: Decibel! <decibel(at)decibel(dot)org>
To: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to get id of currently executed query?
Date: 2007-08-16 14:14:24
Message-ID: 20070816141424.GB54309@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Aug 16, 2007 at 01:30:11PM +0200, hubert depesz lubaczewski wrote:
> hi,
> i need something to distinguish two separate calls for some select.
>
> i tried to use c functions GetCurrentTransactionId() and
> GetCurrentCommandId(),
> but there is a problem:
> if i'll make plpgsql function, which uses GetCurrentTransactionId() and
> GetCurrentCommandId() - getCurrentCommandId changes ( sql's from
> functions also increment the command-id-counter).

Well of course, if you're running it in a separate command. If you run
the function twice from one query I'd expect both to return the same.

Of course you can easily get the same XID back from multiple commands if
you're in an explicit transaction.

BTW, it would likely be useful to others if you posted your code for
those functions somewhere. Just yesterday I was thinking of something
where it would be handy to know what your current XID is.

> so my question is - is there any way, to be able to tell "one query from
> another"?
>
> i would like to write a plpgsql function that would be able to
> differentiate somehow it's calls from one statement to another.

I think you're going to have to give a more explicit example of what
you're actually trying to do.

> i'm not sure if my description is correct - if you dont understand
> something, please let me know.

Well, I'm not following, but it's early in the morning and I didn't
sleep well, so... :)
--
Decibel!, aka Jim Nasby decibel(at)decibel(dot)org
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Decibel! 2007-08-16 14:16:33 Re: Performance question
Previous Message Trevor Talbot 2007-08-16 14:01:14 Re: Accessing tables in other databases, through functions