pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to tell which statement is being executed
3+ messages / 2 participants
[nested] [flat]

* How to tell which statement is being executed
@ 2023-11-03 14:58 Garfield Lewis <garfield.lewis@lzlabs.com>
  2023-11-03 16:08 ` Re: How to tell which statement is being executed Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Garfield Lewis @ 2023-11-03 14:58 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi All,

If I create a C function, is there a way from within that function for me to:


  1.  know whether it is being triggered by an INSERT or UPDATE statement
     *   I’ve done some digging and it seems you can get this information if you provide a Planner hook, however, I need to know this much later in my function not in the Planner
     *   Is there some way for me to get to the PlannedStmt (or anything else that may have the command type) from within my function?
  2.  column attribute (specifically the TYPMOD) for the affected column

BTW, is there a more appropriate Postgres list/group/blog that is specifically dedicated to these types of programming questions or is it ok to post this here?

Regards,
Garfield

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to tell which statement is being executed
  2023-11-03 14:58 How to tell which statement is being executed Garfield Lewis <garfield.lewis@lzlabs.com>
@ 2023-11-03 16:08 ` Tom Lane <tgl@sss.pgh.pa.us>
  2023-11-03 18:23   ` Re: [EXT] Re: How to tell which statement is being executed Garfield Lewis <garfield.lewis@lzlabs.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2023-11-03 16:08 UTC (permalink / raw)
  To: Garfield Lewis <garfield.lewis@lzlabs.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Garfield Lewis <garfield.lewis@lzlabs.com> writes:
> If I create a C function, is there a way from within that function for me to:
>   1.  know whether it is being triggered by an INSERT or UPDATE statement

It might not be any of those.  But if what you want is the most closely
nested SQL action, inspecting the ActivePortal might help (see
function_parse_error_transpose, which I think is the only in-core user).

>   2.  column attribute (specifically the TYPMOD) for the affected column

No.  How would you even define "affected column"?

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [EXT] Re: How to tell which statement is being executed
  2023-11-03 14:58 How to tell which statement is being executed Garfield Lewis <garfield.lewis@lzlabs.com>
  2023-11-03 16:08 ` Re: How to tell which statement is being executed Tom Lane <tgl@sss.pgh.pa.us>
@ 2023-11-03 18:23   ` Garfield Lewis <garfield.lewis@lzlabs.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Garfield Lewis @ 2023-11-03 18:23 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

> It might not be any of those.  But if what you want is the most closely
> nested SQL action, inspecting the ActivePortal might help (see
> function_parse_error_transpose, which I think is the only in-core user).

Thx, Tom… will see if this ActivePortal helps…

> No.  How would you even define "affected column"?

Not sure I just assumed that the attributes for column being processed would be saved somewhere in some structure somewhere. After all, at some point if for instance I created a CHAR(10) column and attempted to insert a CHAR(15) that is returned by my function then Postgres will need to generate a truncation warning so it must know the TYPMOD of the column to do so.

Regards
Garfield

From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Friday, November 3, 2023 at 12:08 PM
To: Garfield Lewis <garfield.lewis@lzlabs.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: [EXT] Re: How to tell which statement is being executed
Garfield Lewis <garfield.lewis@lzlabs.com> writes:
> If I create a C function, is there a way from within that function for me to:
>   1.  know whether it is being triggered by an INSERT or UPDATE statement

It might not be any of those.  But if what you want is the most closely
nested SQL action, inspecting the ActivePortal might help (see
function_parse_error_transpose, which I think is the only in-core user).

>   2.  column attribute (specifically the TYPMOD) for the affected column

No.  How would you even define "affected column"?

                        regards, tom lane

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2023-11-03 18:23 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-11-03 14:58 How to tell which statement is being executed Garfield Lewis <garfield.lewis@lzlabs.com>
2023-11-03 16:08 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-11-03 18:23   ` Garfield Lewis <garfield.lewis@lzlabs.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox