From: Rajiv Malhotra <rajiv@india.hp.com>
To: pgsql-interfaces@postgresql.org
Subject: using Version-1 style coding how to access varchar arrays from C function
Date: Wed, 5 Nov 2003 14:19:08 +0530
Message-ID: <016101c3a379$afd92600$6a604c0f@india.hp.com> (raw)
HI ,
I have written a small C function that should access the varchar array data type .
Here is the function
Line Num 1 Datum evman_verify(PG_FUNCTION_ARGS ) {
Line Num 2 TupleTableSlot *t = (TupleTableSlot *) PG_GETARG_POINTER(0);
Line Num 3 VarChar* val = (VarChar*)PG_GETARG_VARCHAR_P(1);
Line Num 4 bool isnull;
Line Num 5 VarChar** pr = (VarChar**) (GetAttributeByName(t,"propsa",&isnull)); // I think this typecasting is wrong as there is no macro to get array data or is there any that I don't know
Line Num 6 PG_RETURN_VARCHAR_P(*pr); //to return first VarChar*
}
Schema of table is
CREATE TABLE f_test( props VARCHAR(100) , propsa VARCHAR(100)[]);
the linking from pg-sql looks like this
CREATE FUNCTION gettext(f_test,varchar) return varchar as 'MYROOT/sharedlib' , 'evman_verify' LANGUAGE C;
where sharedlib the library made after compilation..
I able to acces all the basic types but not the array as in line num 5. The function returns NULL value while accessed from query . The query I am using look like
Insert into f_test values ( 'hello' , '{"hi","bye"}'); // values in table
select gettext(f_test,props) from f_test;
I am expecting the result as "hi"
Regards ,
Rajiv Malhotra
HP - ISO Bangalore
Office Number : 2051265
Mobile Number : 9886124097
Mail -id rajiv@india.hp.com
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 using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: rajiv@india.hp.com
Subject: Re: using Version-1 style coding how to access varchar arrays from C function
In-Reply-To: <016101c3a379$afd92600$6a604c0f@india.hp.com>
* 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