Skip site navigation (1) Skip section navigation (2)

C Function returning a tuple with a float4 array as column

From: Tim <tim(dot)child(at)comcast(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: C Function returning a tuple with a float4 array as column
Date: 2010-12-05 17:52:14
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

Anyone have any ideas what wrong  with my C code to return a tuple with 
1 column that is a float4 array. I have tested  functions returning  a 
float4 array and a row and both  work independently. When I combine the 
  code  I get  the SQL error

ERROR:  cache lookup failed for type 0

********** Error **********

ERROR: cache lookup failed for type 0
SQL state: XX000

from  the SQL  query

select  pg_backend_pid(),  getrecordarray();

The function is  defined

create or replace  function GetRecordArray() returns table (
     Param_1  real[]
       AS  .....

The C code is

     GetRecordArray  Function to return a record with  1 column as a 
Float4 array
     @returns record with a float4 array
     Datum        column[1];    /*  Columns for the record */
     bool        isNULL[1]  = { false };
     Datum        results;    /* Results tuple */
     HeapTuple    tuple;        /* Record Tuple */
     TupleDesc    tupleDesc;    /* Tuple descripton */

     float dataArray[2] = { 1.1f, 3.1e-16f };
     ArrayType * arrayType;
     Datum *datum;
     int16 typlen;
     bool typbyval;
     char typalign;

     datum = (Datum *)palloc(sizeof(Datum) * 2);

     datum[0] =  Float4GetDatum(dataArray[0]);
     datum[1] =  Float4GetDatum(dataArray[1]);

     get_typlenbyvalalign(FLOAT4OID, &typlen, &typbyval, &typalign);
     arrayType =  construct_array(datum, 2, FLOAT4OID,  typlen, 
typbyval, typalign);

     /* Create and bless the template */
     tupleDesc = CreateTemplateTupleDesc(1, false);

     TupleDescInitEntry(tupleDesc, (AttrNumber) 1, "Param_1", 

     tupleDesc = BlessTupleDesc(tupleDesc);

     /**  Set up the column Datum for the Tuple **/
     column[0] = DatumGetPointer(arrayType);

         /**  Build the tuple **/
     tuple = heap_form_tuple(tupleDesc, column, isNULL);
     results = HeapTupleGetDatum(tuple);




pgsql-novice by date

Next:From: Tom LaneDate: 2010-12-05 20:43:19
Subject: Re: C Function returning a tuple with a float4 array as column
Previous:From: Marco CraveiroDate: 2010-12-05 17:34:47
Subject: Re: Understanding the behaviour of hostname in psql

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group