From: | Werner Echezuria <wercool(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | return HeapTuple |
Date: | 2009-08-25 13:47:55 |
Message-ID: | 2485a25e0908250647x15ac114egc0c7c0e8a0d491df@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi, I wanna return a group of rows, like when you do "SELECT columns FROM
table", but I'm getting some troubles, I don't know if I have to use
HeapTuple or Datum. I'm using bison to parse sqlf to sql this way:
-- some code
%%
query: /* empty string */
| query command
;
command: '\n'
| CreateFuzzyPredStmt
| DropFuzzyPredStmt
| SelectStmt
{
int i;
*((void **)result) = return_query(fuzzy_query[real_length-1]);
for (i=0;i<real_length;i++)
pfree(fuzzy_query[i]);
}
| error '\n' { yyerrok;}
;
-- some code
HeapTuple
return_query(char *str){
HeapTuple rettuple;
int ret, proc;
SPI_connect();
ret=SPI_execute(str,true,1);
proc=SPI_processed;
if (ret > 0 && SPI_tuptable != NULL){
SPITupleTable *tuptable = SPI_tuptable;
rettuple = tuptable->vals;
}
SPI_finish();
return rettuple;
}
This I have the function:
#include "postgres.h"
#include "fmgr.h"
#include "gram.h"
#include "utils/builtins.h"
extern Datum sqlf(PG_FUNCTION_ARGS);
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(sqlf);
Datum
sqlf(PG_FUNCTION_ARGS){
char *query = TextDatumGetCString(PG_GETARG_DATUM(0));
void *result;
yy_scan_string(query);
sqlf_yyparse(&result);
PG_RETURN_HEAPTUPLEHEADER(result);
}
regards.
Attachment | Content-Type | Size |
---|---|---|
gram2.y | application/octet-stream | 7.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-08-25 13:50:17 | Re: DELETE syntax on JOINS |
Previous Message | Tom Lane | 2009-08-25 13:33:15 | Re: setting up scan keys |