Re: ERROR: cache lookup failed for type 0 - Mailing list pgsql-general

From Tzahi Fadida
Subject Re: ERROR: cache lookup failed for type 0
Date
Msg-id 018501c4f504$63ef7bd0$0b00a8c0@llord
Whole thread Raw
In response to Re: ERROR: cache lookup failed for type 0  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: ERROR: cache lookup failed for type 0
List pgsql-general
well, I tried the heap_deformtuple and I am getting now:
select testgetrows();
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!>

btw, as can be seen below I tried two kinds of tupledesc just in case
with the same results.
/*funcctx->tuple_desc= BlessTupleDesc(fctx->lRel->rd_att);*/
funcctx->tuple_desc=BlessTupleDesc(RelationNameGetTupleDesc("my_first_ta
ble"));

#include "postgres.h"
#include <string.h>
#include <array.h>
#include "fmgr.h"
#include "funcapi.h"
#include "access/heapam.h"

typedef struct
{
  HeapScanDesc scan;
  Relation    lRel;
} testgetrows_fctx;

PG_FUNCTION_INFO_V1(testgetrows);

Datum
testgetrows(PG_FUNCTION_ARGS)
{
     FuncCallContext     *funcctx;
     testgetrows_fctx *fctx;
     if (SRF_IS_FIRSTCALL())
     {
        MemoryContext   oldcontext;
        funcctx = SRF_FIRSTCALL_INIT();

        oldcontext =
MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
        fctx = (testgetrows_fctx *) palloc(sizeof(testgetrows_fctx));
        fctx->lRel = heap_open(17236, AccessShareLock);
        fctx->scan = heap_beginscan(fctx->lRel, SnapshotNow, 0, NULL);

        /*funcctx->tuple_desc= BlessTupleDesc(fctx->lRel->rd_att);*/

funcctx->tuple_desc=BlessTupleDesc(RelationNameGetTupleDesc("my_first_ta
ble"));

        funcctx->user_fctx = fctx;
        MemoryContextSwitchTo(oldcontext);
    }

    funcctx = SRF_PERCALL_SETUP();
    fctx = funcctx->user_fctx;

    HeapTuple    tuple;
    tuple = heap_getnext(fctx->scan, ForwardScanDirection);
    if (HeapTupleIsValid(tuple))
    {

      Datum        result;
      Datum        *values;
      HeapTuple    tupleCopy;
      HeapTuple    tupleCopy2;
      char *nulls = (char *)palloc(funcctx->tuple_desc->natts *
sizeof(char));

      tupleCopy = heap_copytuple(tuple);
      heap_deformtuple(tuple,funcctx->tuple_desc,values,nulls);
      tupleCopy2 = heap_formtuple(funcctx->tuple_desc,values,nulls);
      result = HeapTupleGetDatum(tupleCopy2);

      SRF_RETURN_NEXT(funcctx, result);

    }
    else    /* do when there is no more left */
    {
      heap_endscan(fctx->scan);
      heap_close(fctx->lRel, AccessShareLock);

      SRF_RETURN_DONE(funcctx);
    }
}
Regards,
    tzahi.

> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: Friday, January 07, 2005 10:31 PM
> To: Tzahi Fadida
> Cc: pgsql-general@postgresql.org
> Subject: Re: [GENERAL] ERROR: cache lookup failed for type 0
>
>
> Tzahi Fadida <tzahi_ml@myrealbox.com> writes:
> > It still doesn't work. btw, I am using 8rc2.
>
> Um.  The "clean" way to do this is to use BlessTupleDesc and
> then heap_formtuple.  That requires you to break down the
> original tuple into fields (see heap_deformtuple).
> Alternatively you could poke the datatype ID fields directly
> into the copied tuple.
>
>             regards, tom lane
>
>



pgsql-general by date:

Previous
From: David Fetter
Date:
Subject: Re: Problem creating trigger-function with arguments (8.0rc4)
Next
From: Jeff Davis
Date:
Subject: bgwriter