From: | "David E(dot) Wheeler" <david(at)kineticode(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Mysterious Bus Error with get_fn_expr_argtype() |
Date: | 2008-09-01 23:41:21 |
Message-ID: | 02D8BD30-688E-4A1D-A39C-92A15EFD1BFC@kineticode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Howdy,
I'm trying to write a simple function that will return a string with
the type name of a value. Unfortunately, it keeps dying on me. I don't
even get any useful debugging information with --enable-cassert, just
this:
LOG: server process (PID 96946) was terminated by signal 10: Bus error
LOG: terminating any other active server processes
LOG: all server processes terminated; reinitializing
I stuck in a few calls to elog(), and it looks like this is the line
that's choking:
typeoid = get_fn_expr_argtype(fcinfo->flinfo, 0);
But that's copied directly from enum.c. So I'm pretty mystified. Any
help would be greatly appreciated.
Here's the complete code:
#include "postgres.h"
#include "fmgr.h"
#include "utils/builtins.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
extern Datum type_of (PG_FUNCTION_ARGS);
Datum
type_of(PG_FUNCTION_ARGS)
{
Oid typeoid;
Datum result;
char *typename;
typeoid = get_fn_expr_argtype(fcinfo->flinfo, 0);
if (typeoid == InvalidOid) {
ereport(
ERROR, (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("could not determine data type of argument to
type_of()")
)
);
}
typename = format_type_be(typeoid);
result = DirectFunctionCall1(textin, CStringGetDatum(typename));
PG_RETURN_DATUM(result);
}
And I load the function like so:
CREATE OR REPLACE FUNCTION type_of(anyelement)
RETURNS text
AS '$libdir/type_of'
LANGUAGE C STRICT IMMUTABLE;
Thanks,
DAvid
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2008-09-01 23:55:13 | Re: Mysterious Bus Error with get_fn_expr_argtype() |
Previous Message | Ryan Bradetich | 2008-09-01 22:01:28 | Fwd: [Patch Review] TRUNCATE Permission |