~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/not_in.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * not_in.c
 
4
 *        Executes the "not_in" operator for any data type
 
5
 *
 
6
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
7
 * Portions Copyright (c) 1994, Regents of the University of California
 
8
 *
 
9
 *
 
10
 * IDENTIFICATION
 
11
 *        $PostgreSQL: pgsql/src/backend/utils/adt/not_in.c,v 1.42 2004-12-31 22:01:22 pgsql Exp $
 
12
 *
 
13
 *-------------------------------------------------------------------------
 
14
 */
 
15
/*
 
16
 *
 
17
 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
18
 * X HACK WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! X
 
19
 * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
20
 *
 
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!!!!!!!!!!!
 
24
 *
 
25
 */
 
26
 
 
27
#include "postgres.h"
 
28
 
 
29
#include "access/heapam.h"
 
30
#include "catalog/namespace.h"
 
31
#include "parser/parse_relation.h"
 
32
#include "utils/builtins.h"
 
33
 
 
34
 
 
35
/* ----------------------------------------------------------------
 
36
 *
 
37
 * ----------------------------------------------------------------
 
38
 */
 
39
Datum
 
40
int4notin(PG_FUNCTION_ARGS)
 
41
{
 
42
        int32           not_in_arg = PG_GETARG_INT32(0);
 
43
        text       *relation_and_attr = PG_GETARG_TEXT_P(1);
 
44
        List       *names;
 
45
        int                     nnames;
 
46
        RangeVar   *relrv;
 
47
        char       *attribute;
 
48
        Relation        relation_to_scan;
 
49
        int32           integer_value;
 
50
        HeapTuple       current_tuple;
 
51
        HeapScanDesc scan_descriptor;
 
52
        bool            isNull,
 
53
                                retval;
 
54
        int                     attrid;
 
55
        Datum           value;
 
56
 
 
57
        /* Parse the argument */
 
58
 
 
59
        names = textToQualifiedNameList(relation_and_attr, "int4notin");
 
60
        nnames = list_length(names);
 
61
        if (nnames < 2)
 
62
                ereport(ERROR,
 
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);
 
69
 
 
70
        /* Open the relation and get a relation descriptor */
 
71
        relation_to_scan = heap_openrv(relrv, AccessShareLock);
 
72
 
 
73
        /* Find the column to search */
 
74
        attrid = attnameAttNum(relation_to_scan, attribute, true);
 
75
 
 
76
        scan_descriptor = heap_beginscan(relation_to_scan, SnapshotNow,
 
77
                                                                         0, (ScanKey) NULL);
 
78
 
 
79
        retval = true;
 
80
 
 
81
        /* do a scan of the relation, and do the check */
 
82
        while ((current_tuple = heap_getnext(scan_descriptor, ForwardScanDirection)) != NULL)
 
83
        {
 
84
                value = heap_getattr(current_tuple,
 
85
                                                         (AttrNumber) attrid,
 
86
                                                         RelationGetDescr(relation_to_scan),
 
87
                                                         &isNull);
 
88
                if (isNull)
 
89
                        continue;
 
90
                integer_value = DatumGetInt32(value);
 
91
                if (not_in_arg == integer_value)
 
92
                {
 
93
                        retval = false;
 
94
                        break;                          /* can stop scanning now */
 
95
                }
 
96
        }
 
97
 
 
98
        /* close the relation */
 
99
        heap_endscan(scan_descriptor);
 
100
        heap_close(relation_to_scan, AccessShareLock);
 
101
 
 
102
        PG_RETURN_BOOL(retval);
 
103
}
 
104
 
 
105
Datum
 
106
oidnotin(PG_FUNCTION_ARGS)
 
107
{
 
108
        Oid                     the_oid = PG_GETARG_OID(0);
 
109
 
 
110
#ifdef NOT_USED
 
111
        text       *relation_and_attr = PG_GETARG_TEXT_P(1);
 
112
#endif
 
113
 
 
114
        if (the_oid == InvalidOid)
 
115
                PG_RETURN_BOOL(false);
 
116
        /* XXX assume oid maps to int4 */
 
117
        return int4notin(fcinfo);
 
118
}