From: | Ines(dot)Klimann(at)liafa(dot)jussieu(dot)fr |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | How to insert values with a new type ? |
Date: | 2001-02-19 14:20:37 |
Message-ID: | 20010219152037.A12963@liafa0.liafa.jussieu.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Alexaki Sofia | 2001-02-19 15:35:17 | COPY and UNICODE encoding |
Previous Message | Tod McQuillin | 2001-02-19 05:47:14 | Re: Bug? Me or PostgreSQL. |