From: | Tzahi Fadida <tzahi_ml(at)myrealbox(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | ERROR: cache lookup failed for type 0 |
Date: | 2005-01-07 18:35:53 |
Message-ID: | 017101c4f4e7$be262490$0b00a8c0@llord |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi, I am learning how to use the c functions and my function below works
when I do:
select testgetrows();
but when I do select * from testgetrows(); I am getting:
"ERROR: cache lookup failed for type 0"
Whats's the problem?
10x.
drop function testgetrows();
CREATE OR REPLACE FUNCTION testgetrows() RETURNS SETOF my_first_table
AS 'foo6', 'testgetrows'
LANGUAGE C IMMUTABLE STRICT;
#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->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;
result = HeapTupleGetDatum(tuple);
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.
From | Date | Subject | |
---|---|---|---|
Next Message | David Fetter | 2005-01-07 18:45:22 | Re: PostgreSQL 8.0.0 Release Candidate 4 |
Previous Message | Michael Fuhr | 2005-01-07 18:28:02 | Re: Books for experienced DB developer |