How to insert values with a new type ? - Mailing list pgsql-sql

From Ines.Klimann@liafa.jussieu.fr
Subject How to insert values with a new type ?
Date
Msg-id 20010219152037.A12963@liafa0.liafa.jussieu.fr
Whole thread Raw
Responses Re: How to insert values with a new type ?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hi,

I have the following program :

#include <stdio.h>

typedef struct complexe {   float      x;   float      y;
} complexe;


complexe * complex_in(float x, float y)
{ complexe *result;
 result = (complexe *)palloc(sizeof(complexe));        result->x = x; result->y = y;
 return (result);
}

char * complex_out(complexe *complex)    
{ char *result;
 if (complex == NULL)   return(NULL); result = (char *) palloc(60); sprintf(result, "(%f,%f)", complex->x, complex->y);

 return(result);
}
   
(I took this from someone else...)

Now, I do these SQL commands :

CREATE FUNCTION complex_in(opaque)   RETURNS complex   AS '/ens/klimann/PostgreSQL/complexe.o'   LANGUAGE 'c';

CREATE FUNCTION complex_out(opaque)   RETURNS opaque   AS '/ens/klimann/PostgreSQL/complexe.o'   LANGUAGE 'c';

CREATE TYPE complex (   internallength = 16,       input = complex_in,   output = complex_out
);   
CREATE TABLE nombres (  val COMPLEX
);


And I want to insert values in the table nombres.
I have tried this :
INSERT INTO nombres
VALUES (complex_in(1.0, 4.0));

and this :
INSERT INTO nombres
VALUES (1.0, 4.0);

and also this :
INSERT INTO nombres
VALUES ('1.0, 4.0');

and several other possibilities, but none seems to be right.


Has someone an idea ?

Thanks,
Ines. 


pgsql-sql by date:

Previous
From: Tod McQuillin
Date:
Subject: Re: Bug? Me or PostgreSQL.
Next
From: Alexaki Sofia
Date:
Subject: COPY and UNICODE encoding