Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 10th, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Datum
  2. get_incidences(PG_FUNCTION_ARGS)
  3. {
  4.         text          *relname = PG_GETARG_TEXT_P(0);
  5.         RangeVar      *relrv;
  6.         Relation      rel;
  7.         Datum         result;
  8.         Buffer        *buf;
  9.         HeapTupleData tuple;
  10.         ItemPointer   itemp;
  11.         Datum         resultDatum;
  12.         bool          x;
  13.  
  14.         // open relation
  15.         relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
  16.         rel = heap_openrv(relrv, AccessShareLock);
  17.        
  18.         itemp = (ItemPointer) palloc(sizeof(ItemPointerData));
  19.         ItemPointerSet(itemp, 0, 2); // magic constants - it's will be filled from params
  20.         tuple.t_self = *itemp;
  21.        
  22.         x = heap_fetch(rel, SnapshotNow, &tuple, &buf, true, NULL);
  23.        
  24.         resultDatum = datumCopy(HeapTupleGetDatum(&tuple), false, -1);
  25.        
  26.         PG_RETURN_DATUM(resultDatum);
  27.        
  28. }