Thread: insert values

insert values

From
Ines.Klimann@liafa.jussieu.fr
Date:
Hi,

I have the following type :
--------------------------------------------
CREATE FUNCTION entier_in(opaque)   RETURNS entier   AS '/ens/klimann/PostgreSQL/entier.o'   LANGUAGE 'c';

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

CREATE TYPE entier (   internallength = 8,   input = entier_in,   output = entier_out
);
--------------------------------------------

where entier.c is the following program :
--------------------------------------------
#include <stdio.h>

typedef struct entier {   long x;
} entier;


entier * entier_in(char *s)
{ entier *result;
 result = (entier *)malloc(sizeof(entier)); result->x = atoi(s);
 return (result);
}

char * entier_out(entier *n)
{ char *result; if (n == NULL)   return(NULL); result = (char *) malloc(60); sprintf(result, "%d", n->x);
 return(result);
}
----------------------------------------------

then I create the table entiers as follows :
----------------------------------------------
CREATE TABLE entiers (  val entier
);
----------------------------------------------

How can I insert a value in this table ?

I have tried several methods, but I can't find
a correct one.

Does someone have an idea ?


Thanks a lot,
Ines.






Re: insert values

From
Tom Lane
Date:
Ines.Klimann@liafa.jussieu.fr writes:
> I have the following type :
> ...
> How can I insert a value in this table ?

INSERT INTO entiers VALUES('1234') should work fine.

BTW, change the "malloc" calls to "palloc" if you don't want to suffer
from severe memory leakage problems.  Otherwise the code seems OK,
though I'd recommend a tad more validity checking in the input
routine...
        regards, tom lane


Re: insert values

From
Ines.Klimann@liafa.jussieu.fr
Date:
On Thu, Feb 22, 2001 at 11:01:11PM -0500, Tom Lane wrote:
> Ines.Klimann@liafa.jussieu.fr writes:
> > I have the following type :
> > ...
> > How can I insert a value in this table ?
> 
> INSERT INTO entiers VALUES('1234') should work fine.
>

I have tried and I have this message :
ex1=# insert into entiers        
ex1-# values ('1234');
ERROR:  Load of file /ens/klimann/PostgreSQL/entier.o failed: Exec format error
ex1=# 


what do you think it could be ?

Thanks,
Ines. 


Re: insert values

From
Tom Lane
Date:
Ines.Klimann@liafa.jussieu.fr writes:
> ERROR:  Load of file /ens/klimann/PostgreSQL/entier.o failed: Exec format error

.o?  Did you convert this file into a shared library?  I'd expect .so or
.sl depending on platform...
        regards, tom lane