2000-08-21 06:48:57 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* varbit.h
|
|
|
|
* Functions for the SQL datatypes BIT() and BIT VARYING().
|
|
|
|
*
|
|
|
|
* Code originally contributed by Adriaan Joubert.
|
|
|
|
*
|
2002-06-20 22:29:54 +02:00
|
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
2000-08-21 06:48:57 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
Extend pg_cast castimplicit column to a three-way value; this allows us
to be flexible about assignment casts without introducing ambiguity in
operator/function resolution. Introduce a well-defined promotion hierarchy
for numeric datatypes (int2->int4->int8->numeric->float4->float8).
Change make_const to initially label numeric literals as int4, int8, or
numeric (never float8 anymore).
Explicitly mark Func and RelabelType nodes to indicate whether they came
from a function call, explicit cast, or implicit cast; use this to do
reverse-listing more accurately and without so many heuristics.
Explicit casts to char, varchar, bit, varbit will truncate or pad without
raising an error (the pre-7.2 behavior), while assigning to a column without
any explicit cast will still raise an error for wrong-length data like 7.3.
This more nearly follows the SQL spec than 7.2 behavior (we should be
reporting a 'completion condition' in the explicit-cast cases, but we have
no mechanism for that, so just do silent truncation).
Fix some problems with enforcement of typmod for array elements;
it didn't work at all in 'UPDATE ... SET array[n] = foo', for example.
Provide a generalized array_length_coerce() function to replace the
specialized per-array-type functions that used to be needed (and were
missing for NUMERIC as well as all the datetime types).
Add missing conversions int8<->float4, text<->numeric, oid<->int8.
initdb forced.
2002-09-18 23:35:25 +02:00
|
|
|
* $Id: varbit.h,v 1.16 2002/09/18 21:35:25 tgl Exp $
|
2000-08-21 06:48:57 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2000-04-08 04:13:11 +02:00
|
|
|
#ifndef VARBIT_H
|
|
|
|
#define VARBIT_H
|
|
|
|
|
2000-08-21 06:48:57 +02:00
|
|
|
#include "fmgr.h"
|
2000-07-13 00:59:15 +02:00
|
|
|
|
2000-08-21 06:48:57 +02:00
|
|
|
/*
|
|
|
|
* Modeled on struct varlena from postgres.h, but data type is bits8.
|
|
|
|
*/
|
|
|
|
typedef struct
|
2000-04-08 04:13:11 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
int32 vl_len; /* standard varlena header (total size in
|
|
|
|
* bytes) */
|
2000-08-21 06:48:57 +02:00
|
|
|
int32 bit_len; /* number of valid bits */
|
|
|
|
bits8 bit_dat[1]; /* bit string, most sig. byte first */
|
|
|
|
} VarBit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fmgr interface macros
|
|
|
|
*
|
|
|
|
* BIT and BIT VARYING are toastable varlena types. They are the same
|
|
|
|
* as far as representation goes, so we just have one set of macros.
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
#define DatumGetVarBitP(X) ((VarBit *) PG_DETOAST_DATUM(X))
|
|
|
|
#define DatumGetVarBitPCopy(X) ((VarBit *) PG_DETOAST_DATUM_COPY(X))
|
|
|
|
#define VarBitPGetDatum(X) PointerGetDatum(X)
|
|
|
|
#define PG_GETARG_VARBIT_P(n) DatumGetVarBitP(PG_GETARG_DATUM(n))
|
2000-08-21 06:48:57 +02:00
|
|
|
#define PG_GETARG_VARBIT_P_COPY(n) DatumGetVarBitPCopy(PG_GETARG_DATUM(n))
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_VARBIT_P(x) return VarBitPGetDatum(x)
|
2000-04-08 04:13:11 +02:00
|
|
|
|
2000-08-21 06:48:57 +02:00
|
|
|
/* Header overhead *in addition to* VARHDRSZ */
|
|
|
|
#define VARBITHDRSZ sizeof(int32)
|
2000-04-08 04:13:11 +02:00
|
|
|
/* Number of bits in this bit string */
|
2000-08-21 06:48:57 +02:00
|
|
|
#define VARBITLEN(PTR) (((VarBit *) (PTR))->bit_len)
|
|
|
|
/* Pointer to the first byte containing bit string data */
|
|
|
|
#define VARBITS(PTR) (((VarBit *) (PTR))->bit_dat)
|
2000-04-08 04:13:11 +02:00
|
|
|
/* Number of bytes in the data section of a bit string */
|
|
|
|
#define VARBITBYTES(PTR) (VARSIZE(PTR) - VARHDRSZ - VARBITHDRSZ)
|
2000-08-21 06:48:57 +02:00
|
|
|
/* Padding of the bit string at the end (in bits) */
|
2000-08-26 23:53:44 +02:00
|
|
|
#define VARBITPAD(PTR) (VARBITBYTES(PTR)*BITS_PER_BYTE - VARBITLEN(PTR))
|
2000-04-08 04:13:11 +02:00
|
|
|
/* Number of bytes needed to store a bit string of a given length */
|
2000-08-26 23:53:44 +02:00
|
|
|
#define VARBITTOTALLEN(BITLEN) (((BITLEN) + BITS_PER_BYTE-1)/BITS_PER_BYTE + \
|
2000-08-21 06:48:57 +02:00
|
|
|
VARHDRSZ + VARBITHDRSZ)
|
2000-04-08 04:13:11 +02:00
|
|
|
/* pointer beyond the end of the bit string (like end() in STL containers) */
|
2000-08-21 06:48:57 +02:00
|
|
|
#define VARBITEND(PTR) (((bits8 *) (PTR)) + VARSIZE(PTR))
|
2000-08-26 23:53:44 +02:00
|
|
|
/* Mask that will cover exactly one byte, i.e. BITS_PER_BYTE bits */
|
2000-04-08 04:13:11 +02:00
|
|
|
#define BITMASK 0xFF
|
|
|
|
#define BITHIGH 0x80
|
|
|
|
|
|
|
|
|
2001-05-22 18:37:17 +02:00
|
|
|
extern Datum bit_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bit_out(PG_FUNCTION_ARGS);
|
2000-08-21 06:48:57 +02:00
|
|
|
extern Datum varbit_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum varbit_out(PG_FUNCTION_ARGS);
|
2001-05-22 18:37:17 +02:00
|
|
|
extern Datum bit(PG_FUNCTION_ARGS);
|
2000-08-21 06:48:57 +02:00
|
|
|
extern Datum varbit(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum biteq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitne(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitlt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitle(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitgt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitge(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitcmp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitand(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitor(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitxor(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitnot(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitshiftleft(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitshiftright(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitcat(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitsubstr(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitlength(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitoctetlength(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bitfromint4(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bittoint4(PG_FUNCTION_ARGS);
|
2002-08-04 08:33:59 +02:00
|
|
|
extern Datum bitfromint8(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum bittoint8(PG_FUNCTION_ARGS);
|
2000-10-31 11:22:13 +01:00
|
|
|
extern Datum bitposition(PG_FUNCTION_ARGS);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2000-04-08 04:13:11 +02:00
|
|
|
#endif
|