1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* misc.c--
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1998-02-24 04:47:26 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.12 1998/02/24 03:47:26 scrappy Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-07-28 02:57:08 +02:00
|
|
|
#include <sys/types.h>
|
1996-07-09 08:22:35 +02:00
|
|
|
#include <sys/file.h>
|
|
|
|
#include "postgres.h"
|
|
|
|
#include "utils/datum.h"
|
|
|
|
#include "catalog/pg_type.h"
|
|
|
|
#include "utils/builtins.h"
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* Check if data is Null
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
bool
|
1997-09-08 23:56:23 +02:00
|
|
|
nullvalue(Datum value, bool *isNull)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
if (*isNull)
|
|
|
|
{
|
|
|
|
*isNull = false;
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
return (false);
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------*
|
1997-09-07 07:04:48 +02:00
|
|
|
* check if data is not Null *
|
1996-07-09 08:22:35 +02:00
|
|
|
*--------------------------------------------------------------------- */
|
|
|
|
bool
|
1997-09-08 23:56:23 +02:00
|
|
|
nonnullvalue(Datum value, bool *isNull)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
if (*isNull)
|
|
|
|
{
|
|
|
|
*isNull = false;
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
return (true);
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* oidrand (oid o, int4 X)-
|
1997-09-07 07:04:48 +02:00
|
|
|
* 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;
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Example use:
|
1997-09-07 07:04:48 +02:00
|
|
|
* select * from TEMP where oidrand(TEMP.oid, 10)
|
1996-07-09 08:22:35 +02:00
|
|
|
* will return about 1/10 of the tuples in TEMP
|
|
|
|
*
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
bool
|
1996-07-09 08:22:35 +02:00
|
|
|
oidrand(Oid o, int32 X)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
bool result;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (X == 0)
|
|
|
|
return true;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
result = (random() % X == 0);
|
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
oidsrand(int32 X) -
|
1997-09-07 07:04:48 +02:00
|
|
|
seeds the random number generator
|
|
|
|
always return true
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
bool
|
|
|
|
oidsrand(int32 X)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
srand(X);
|
|
|
|
return true;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32
|
|
|
|
userfntest(int i)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
return (i);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|