Обсуждение: about create type

Поиск
Список
Период
Сортировка

about create type

От
zhuangjifeng
Дата:
Dear Sir:
         I have tried to  create a new Type in  postgreSQL-7.2. The
example is defined in Chapter 39 of extended type. We  do follow your
defination  of "Complex" completely.But there is always an error:

     I entered :
 CREATE TYPE
complex(INPUT=complex_in,OUTPUT=complex_out(Complex),INTERNALLENGTH=16);

 but it shows
ERROR: parser:parse error at   or  near '(' ".

         Could  you  please give me a comprehensible explanation. I
expect to hear from you!
        Thank you very much!

PS: our source code is in attachment
#include "stdio.h"
#include "/usr/local/src/pgsql/src/include/postgres.h"

 typedef struct Complex{
   double x;
   double y;
 }Complex;



Complex *complex_in(char *str)
{ double x,y;
 Complex *result;
 if(sscanf(str,"(%lf,%lf)",&x,&y)!=2)
   { elog(WARN,"complex_in error")
       return NULL;
   }
 result=(Complex *)palloc(sizeof(Complex));
 result->x=x;
 result->y=y;
 return(result);}

char *complex_out(Complex *complex)
{
  char *result;
  if(complex==NULL)
    return(null);

  sprintf(result,"(%g,%g)",complex->x,complex->y);
  return(result);
}

Re: about create type

От
Tom Lane
Дата:
zhuangjifeng <zhuangjifeng@263.net> writes:
>          I have tried to  create a new Type in  postgreSQL-7.2. The
> example is defined in Chapter 39 of extended type. We  do follow your
> defination  of "Complex" completely.But there is always an error:

>  CREATE TYPE
> complex(INPUT=complex_in,OUTPUT=complex_out(Complex),INTERNALLENGTH=16);
> ERROR: parser:parse error at   or  near '(' ".

You should not put parameters with the input/output function names.
(I'm pretty sure that none of our documentation suggests you should.)

            regards, tom lane