pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to insert values with a new type ?
2+ messages / 2 participants
[nested] [flat]
* How to insert values with a new type ?
@ 2001-02-19 14:20 Ines.Klimann@liafa.jussieu.fr
2001-02-19 16:09 ` Re: How to insert values with a new type ? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Ines.Klimann@liafa.jussieu.fr @ 2001-02-19 14:20 UTC (permalink / raw)
To: 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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: How to insert values with a new type ?
2001-02-19 14:20 How to insert values with a new type ? Ines.Klimann@liafa.jussieu.fr
@ 2001-02-19 16:09 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2001-02-19 16:09 UTC (permalink / raw)
To: Ines.Klimann@liafa.jussieu.fr; +Cc: pgsql-sql
Ines.Klimann@liafa.jussieu.fr writes:
> complexe * complex_in(float x, float y)
> {
> complexe *result;
> result = (complexe *)palloc(sizeof(complexe));
> result->x = x;
> result->y = y;
> return (result);
> }
A datatype's input routine has to accept a string (char *).
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-02-19 16:09 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-02-19 14:20 How to insert values with a new type ? Ines.Klimann@liafa.jussieu.fr
2001-02-19 16:09 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox