From: Ines.Klimann@liafa.jussieu.fr
To: pgsql-sql@postgresql.org
Subject: How to insert values with a new type ?
Date: Mon, 19 Feb 2001 15:20:37 +0100
Message-ID: <20010219152037.A12963@liafa0.liafa.jussieu.fr> (raw)
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: Ines.Klimann@liafa.jussieu.fr
Subject: Re: How to insert values with a new type ?
In-Reply-To: <20010219152037.A12963@liafa0.liafa.jussieu.fr>
References: <20010219152037.A12963@liafa0.liafa.jussieu.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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