From: | Carlos Peralta Ramirez <cperalta(at)hera(dot)inf(dot)ucv(dot)cl> |
---|---|
To: | pgsql-sql <pgsql-sql(at)postgresql(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | More problems with arrays !!!!! |
Date: | 1999-05-11 11:21:30 |
Message-ID: | 373812B9.794EB6CC@hera.inf.ucv.cl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-sql |
Hi,
I tried to create a function in C that receive an array X like
argument, and return ane element of him.
Here is the C code ->
#include <pgsql/postgres.h>
#include <stdio.h>
int4 array_1(int4 x[]){
return(x[1]);
}
int4 array_2(int4 *x){
return(x[1]);
}
int4 array_3(int4 x[]){
return(*(x+1));
}
int4 array_4(int4 *x){
return(*(x+1));
}
/* Note, this functions are tests only,*/
then I ceate this functions in Postgresql ->
testdb=> create function array_1(_int4) returns int4 as
'/var/lib/pgsql/funciones/arraystest.so' language 'c';
CREATE
testdb=> create function array_2(_int4) returns int4 as
'/var/lib/pgsql/funciones/arraystest.so' language 'c';
CREATE
testdb=> create function array_3(_int4) returns int4 as
'/var/lib/pgsql/funciones/arraystest.so' language 'c';
CREATE
testdb=> create function array_4(_int4) returns int4 as
'/var/lib/pgsql/funciones/arraystest.so' language 'c';
CREATE
Therefore I can call the functions , but I hope another results .....
testdb=> select array_1('{1,2,3,4}');
array_1
----
40
(1 row)
testdb=> select array_2('{1,2,3,4}');
array_2
----
40
(1 row)
testdb=> select array_3('{1,2,3,4}');
array_3
----
40
(1 row)
testdb=> select array_4('{1,2,3,4}');
array_4
----
40
(1 row)
This means that the four functions returns the same value
testdb=> select array_1('{1,4}');
array_1
----
32
(1 row)
testdb=> select array_1('{1,1}');
array_1
----
32
(1 row)
testdb=> select array_1('{3,2,3,3,4,5,6}');
array_1
----
52
(1 row)
testdb=> select array_1('{}');
array_1
----
12
(1 row)
testdb=> select array_1('{1}');
array_1
----
28
(1 row)
It seems to be , this functions returns the bytes asigned to them.
What can I do, for get the element (e.g. the fisrt) of the array?
Thanks ,
PD: I want to do this, to make a function that return if a element is
or not into an array.
From | Date | Subject | |
---|---|---|---|
Next Message | Jelle Ruttenberg | 1999-05-11 14:05:57 | Int8: problems |
Previous Message | darold | 1999-05-11 10:03:17 | Win32 port |
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Bouska | 1999-05-11 13:28:09 | listo of larde objects |
Previous Message | Jan Wieck | 1999-05-11 07:35:27 | Re: [SQL] plpgsql error |