pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Carlos Peralta Ramirez <cperalta@hera.inf.ucv.cl>
To: pgsql-sql <pgsql-sql@postgresql.org>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: More problems with arrays !!!!!
Date: Tue, 11 May 1999 06:21:30 -0500
Message-ID: <373812B9.794EB6CC@hera.inf.ucv.cl> (raw)

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.




Message-ID: <373812B9.794EB6CC@hera.inf.ucv.cl>
Permalink:  ../373812B9.794EB6CC@hera.inf.ucv.cl/
Also on:    postgresql.org/message-id/373812B9.794EB6CC@hera.inf.ucv.cl

 · 

reply

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: cperalta@hera.inf.ucv.cl, pgsql-general@postgresql.org
  Subject: Re: More problems with arrays !!!!!
  In-Reply-To: <373812B9.794EB6CC@hera.inf.ucv.cl>
  References: <373812B9.794EB6CC@hera.inf.ucv.cl>

* 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