Thread: writing custom data type
Hey Guys,
I've been having trouble writing my own custom datatype for PG. when I do my `CREATE FUNCTION` call, it fails with:
resultsets=# CREATE FUNCTION fuzzytime_in(cstring)
RETURNS fuzzytime
AS 'fuzzytimetype'
LANGUAGE C IMMUTABLE STRICT;
NOTICE: return type fuzzytime is only a shell
ERROR: could not find function "fuzzytime_in" in file "/usr/lib/postgresql/9.1/lib/fuzzytimetype.so"
--
now I checked my shared lib, and surely enough, it's there
$ objdump -t /usr/lib/postgresql/9.1/lib/fuzzytimetype.so
...
00000000000018b0 g F .text 0000000000000070 fuzzytime_in
...
--
So what gives? The code has PG_MODULE_MAGIC, and I'm calling PG_FUNCTION_INFO_V1(fuzzytime_in);
I'd really appreciate any help with this.
Cheers,
Arthur Chan
Arthur Chan <achan@comprehend.com> writes: > I've been having trouble writing my own custom datatype for PG. when I do > my `CREATE FUNCTION` call, it fails with: > resultsets=# CREATE FUNCTION fuzzytime_in(cstring) > RETURNS fuzzytime > AS 'fuzzytimetype' > LANGUAGE C IMMUTABLE STRICT; > NOTICE: return type fuzzytime is only a shell > ERROR: could not find function "fuzzytime_in" in file > "/usr/lib/postgresql/9.1/lib/fuzzytimetype.so" > now I checked my shared lib, and surely enough, it's there > $ objdump -t /usr/lib/postgresql/9.1/lib/fuzzytimetype.so > ... > 00000000000018b0 g F .text 0000000000000070 fuzzytime_in > ... > So what gives? The code has PG_MODULE_MAGIC, and I'm > calling PG_FUNCTION_INFO_V1(fuzzytime_in); Huh, looks like it should work. I can think of a couple of gotchas: (1) If the library is already loaded, CREATE FUNCTION doesn't reload it. Maybe you have an old image of the .so in memory, which doesn't contain the function? Try starting a fresh psql session. (2) Maybe you compiled the function as C++, so it has a mangled name? This theory requires that objdump automatically de-mangles names, which I don't know for sure one way or the other. regards, tom lane
On Fri, Feb 1, 2013 at 3:58 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Arthur Chan <achan@comprehend.com> writes:
> I've been having trouble writing my own custom datatype for PG. when I do
> my `CREATE FUNCTION` call, it fails with:
> resultsets=# CREATE FUNCTION fuzzytime_in(cstring)
> RETURNS fuzzytime
> AS 'fuzzytimetype'
> LANGUAGE C IMMUTABLE STRICT;
> NOTICE: return type fuzzytime is only a shell
> ERROR: could not find function "fuzzytime_in" in file
> "/usr/lib/postgresql/9.1/lib/fuzzytimetype.so"> now I checked my shared lib, and surely enough, it's there
> $ objdump -t /usr/lib/postgresql/9.1/lib/fuzzytimetype.so
> ...
> 00000000000018b0 g F .text 0000000000000070 fuzzytime_in
> ...
I hope you are not offended if I ask the obvious question, but could it be a permissions problem? The lib exists, but are the user or group such that the PostgreSQL account can access it?
Good luck,
-Mike
Hey Tom,
Thanks for the help. It was what you said. I had to start a new psql session. And yea, i'm pretty sure objdump does not demangle names. It would be a nice feature if they had the demangled name in parens or something, and that'd probably require support from glibc and gcc, no?
-Arthur
On Fri, Feb 1, 2013 at 12:58 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Arthur Chan <achan@comprehend.com> writes:
> I've been having trouble writing my own custom datatype for PG. when I do
> my `CREATE FUNCTION` call, it fails with:
> resultsets=# CREATE FUNCTION fuzzytime_in(cstring)
> RETURNS fuzzytime
> AS 'fuzzytimetype'
> LANGUAGE C IMMUTABLE STRICT;
> NOTICE: return type fuzzytime is only a shell
> ERROR: could not find function "fuzzytime_in" in file
> "/usr/lib/postgresql/9.1/lib/fuzzytimetype.so"> now I checked my shared lib, and surely enough, it's there
> $ objdump -t /usr/lib/postgresql/9.1/lib/fuzzytimetype.so
> ...
> 00000000000018b0 g F .text 0000000000000070 fuzzytime_in
> ...> So what gives? The code has PG_MODULE_MAGIC, and I'mHuh, looks like it should work. I can think of a couple of gotchas:
> calling PG_FUNCTION_INFO_V1(fuzzytime_in);
(1) If the library is already loaded, CREATE FUNCTION doesn't reload it.
Maybe you have an old image of the .so in memory, which doesn't contain
the function? Try starting a fresh psql session.
(2) Maybe you compiled the function as C++, so it has a mangled name?
This theory requires that objdump automatically de-mangles names, which
I don't know for sure one way or the other.
regards, tom lane