Re: ERROR: cache lookup failed for type 0

From: Tzahi Fadida <tzahi_ml(at)myrealbox(dot)com>
To: 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ERROR: cache lookup failed for type 0
Date: 2005-01-07 22:01:02
Message-ID: 018501c4f504$63ef7bd0$0b00a8c0@llord
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)sss(dot)pgh(dot)pa(dot)us]
> Sent: Friday, January 07, 2005 10:31 PM
> To: Tzahi Fadida
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] ERROR: cache lookup failed for type 0
>
>
> Tzahi Fadida <tzahi_ml(at)myrealbox(dot)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
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2005-01-07 22:20:16 bgwriter
Previous Message David Fetter 2005-01-07 22:00:07 Re: Problem creating trigger-function with arguments (8.0rc4)