1
/*-------------------------------------------------------------------------
4
* Executes the "not_in" operator for any data type
6
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7
* Portions Copyright (c) 1994, Regents of the University of California
11
* $PostgreSQL: pgsql/src/backend/utils/adt/not_in.c,v 1.42 2004-12-31 22:01:22 pgsql Exp $
13
*-------------------------------------------------------------------------
17
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
18
* X HACK WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! X
19
* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
21
* This code is the OLD not-in code that is HACKED
22
* into place until operators that can have arguments as
23
* columns are ******REALLY****** implemented!!!!!!!!!!!
29
#include "access/heapam.h"
30
#include "catalog/namespace.h"
31
#include "parser/parse_relation.h"
32
#include "utils/builtins.h"
35
/* ----------------------------------------------------------------
37
* ----------------------------------------------------------------
40
int4notin(PG_FUNCTION_ARGS)
42
int32 not_in_arg = PG_GETARG_INT32(0);
43
text *relation_and_attr = PG_GETARG_TEXT_P(1);
48
Relation relation_to_scan;
50
HeapTuple current_tuple;
51
HeapScanDesc scan_descriptor;
57
/* Parse the argument */
59
names = textToQualifiedNameList(relation_and_attr, "int4notin");
60
nnames = list_length(names);
63
(errcode(ERRCODE_INVALID_NAME),
64
errmsg("invalid name syntax"),
65
errhint("Must provide \"relationname.columnname\".")));
66
attribute = strVal(llast(names));
67
names = list_truncate(names, nnames - 1);
68
relrv = makeRangeVarFromNameList(names);
70
/* Open the relation and get a relation descriptor */
71
relation_to_scan = heap_openrv(relrv, AccessShareLock);
73
/* Find the column to search */
74
attrid = attnameAttNum(relation_to_scan, attribute, true);
76
scan_descriptor = heap_beginscan(relation_to_scan, SnapshotNow,
81
/* do a scan of the relation, and do the check */
82
while ((current_tuple = heap_getnext(scan_descriptor, ForwardScanDirection)) != NULL)
84
value = heap_getattr(current_tuple,
86
RelationGetDescr(relation_to_scan),
90
integer_value = DatumGetInt32(value);
91
if (not_in_arg == integer_value)
94
break; /* can stop scanning now */
98
/* close the relation */
99
heap_endscan(scan_descriptor);
100
heap_close(relation_to_scan, AccessShareLock);
102
PG_RETURN_BOOL(retval);
106
oidnotin(PG_FUNCTION_ARGS)
108
Oid the_oid = PG_GETARG_OID(0);
111
text *relation_and_attr = PG_GETARG_TEXT_P(1);
114
if (the_oid == InvalidOid)
115
PG_RETURN_BOOL(false);
116
/* XXX assume oid maps to int4 */
117
return int4notin(fcinfo);