aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/misc.c
blob: f04152cf6d2526d508c931274c73c176a875e74f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*-------------------------------------------------------------------------
 *
 * misc.c--
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.8 1997/09/07 04:50:23 momjian Exp $
 *
 *-------------------------------------------------------------------------
 */
#include <sys/types.h>
#include <sys/file.h>
#include "postgres.h"
#include "utils/datum.h"
#include "catalog/pg_type.h"
#include "utils/builtins.h"

#include "port-protos.h"		/* For random(), sometimes */


/*-------------------------------------------------------------------------
 * Check if data is Null
 */
bool
nullvalue(Datum value, bool * isNull)
{
	if (*isNull)
	{
		*isNull = false;
		return (true);
	}
	return (false);

}

/*----------------------------------------------------------------------*
 *	   check if data is not Null										*
 *--------------------------------------------------------------------- */
bool
nonnullvalue(Datum value, bool * isNull)
{
	if (*isNull)
	{
		*isNull = false;
		return (false);
	}
	return (true);

}

/*
 * oidrand (oid o, int4 X)-
 *	  takes in an oid and a int4 X, and will return 'true'
 *	about 1/X of the time.
 *	  Useful for doing random sampling or subsetting.
 *	if X == 0, this will always return true;
 *
 * Example use:
 *	   select * from TEMP where oidrand(TEMP.oid, 10)
 * will return about 1/10 of the tuples in TEMP
 *
 */
bool
oidrand(Oid o, int32 X)
{
	bool			result;

	if (X == 0)
		return true;

	result = (random() % X == 0);
	return result;
}

/*
   oidsrand(int32 X) -
	  seeds the random number generator
	  always return true
*/
bool
oidsrand(int32 X)
{
	srand(X);
	return true;
}



int32
userfntest(int i)
{
	return (i);
}