Hallo, I am new here and hoping I am at the right place. If not would you please redirect me? I am having troubles with user defined types. I create very simple type "complex" from the postgres tutorial, even make it much more simple, so I can be pretty sure there is not any memory leak: (see attachment - try_this.c) Then I compile it: g++ -c try_this.cc g++ -shared -o try_this.so try_this.o -lgcc Then I define in postgres types and functions. (see attachment - create) following create table pok3 (co complex, jmeno varchar); insert into pok3 (co,jmeno) values ('pok','pok'); select * from pok3; At this point it stops responding and I have to kill the session. Can anyone tell me what I am doing wrong? Any help will be highly appreciated. Petr (I have postgresql-6.4.2, so the problem is not in a version.)
CREATE FUNCTION complex_in(opaque) RETURNS complex AS '/.../try_this.so' LANGUAGE 'c'; CREATE FUNCTION complex_out(opaque) RETURNS opaque AS '/.../try_this.so' LANGUAGE 'c'; CREATE TYPE complex ( internallength = 16, input = complex_in, output = complex_out ); create table pok3 (co complex, jmeno varchar); insert into pok3 (co,jmeno) values ('pok','pok'); select * from pok3;
#include <string.h> #include <stdio.h> extern "C" { typedef struct Complex { double x; double y; } Complex; Complex * complex_in(char *str) { Complex *result = new (Complex); result->x = 1; result->y = 2; return (result); } char * complex_out(Complex *complex) { char *result = strdup ("(2,3)"); return(result); } }