pg_typeof() (was: Mysterious Bus Error with get_fn_expr_argtype())

Started by Brendan Jurdalmost 18 years ago2 messageshackerspatches
Jump to latest
#1Brendan Jurd
direvus@gmail.com
hackerspatches

On Tue, Sep 2, 2008 at 3:31 PM, Brendan Jurd <direvus@gmail.com> wrote:

Barring any further comments/objections, I'll go ahead and prepare a
patch to add this to core.

Any opinions on where pg_typeof() should be defined? This function is
a little unusual and doesn't seem to slot nicely into any one of the
existing categories.

A few candidates:

* regproc.c - it contains functions for working with regtype.
* ruleutils.c - it contains a lot of other system information
functions, like pg_get_expr(), pg_get_userbyid(), et al.
* format_type.c - functions for presenting type information to the user.
* misc.c

Personally I'd be inclined to go with misc.c (if it's not clear where
it belongs, that probably makes it miscellany), but it's a weak
preference only.

Cheers,
BJ

#2Brendan Jurd
direvus@gmail.com
In reply to: Brendan Jurd (#1)
hackerspatches

Hi folks,

As discussed on -hackers [1]http://archives.postgresql.org/message-id/37ed240d0809012135k1a7621d5x2acf18b31c7f9281@mail.gmail.com, here is a patch to add a pg_typeof()
builtin function to core.

The function accepts one argument (type "any") and returns the regtype
of that argument. This can be helpful in various circumstances,
including troubleshooting cast/coercion behaviour in a query, or
constructing dynamic SQL statements.

It's declared in builtins.h and defined in utils/adt/misc.c.

The patch includes a small documentation update; I added pg_typeof()
to Table 9-47. System Catalog Information Functions, and a brief
descriptive paragraph underneath the table.

This didn't seem like it warranted any additional regression tests.

Added to the November commitfest.

Cheers,
BJ

doc/src/sgml/func.sgml | 15 +++++++++++++++
src/backend/utils/adt/misc.c | 9 +++++++++
src/include/catalog/catversion.h | 2 !!
src/include/catalog/pg_proc.h | 2 ++
src/include/utils/builtins.h | 1 +
5 files changed, 27 insertions(+), 2 modifications(!)

[1]: http://archives.postgresql.org/message-id/37ed240d0809012135k1a7621d5x2acf18b31c7f9281@mail.gmail.com

Attachments:

pg_typeof.diffapplication/octet-stream; name=pg_typeof.diffDownload+29-2