mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-21 20:33:23 +02:00
here is an updated version of the bit type with a bugfix and all the necessa ry SQL functions defined. This should replace what is currently in contrib. I'd appreciate any comments on what is there. Kind regards, Adriaan
75 lines
2.7 KiB
Plaintext
75 lines
2.7 KiB
Plaintext
A set of C routines to implement an SQL-compliant bitstring type.
|
|
|
|
The file varbit.c contains the c-functions to implement both BIT and
|
|
BIT VARYING. Both types are implemented in essentially the same way,
|
|
except that BIT is zero padded to a specified length. I've tried to
|
|
make this code as independent as possible of the byte length, but it
|
|
is quite possible that there may be problems on machines that don't
|
|
have 8 bits/byte (are there still any around?).
|
|
|
|
The SQL standard only defines comparison, SUBSTR and concatenation
|
|
operators, and these have been implemented. In addition all logical
|
|
operators have been implemented, i.e. ~,|,&,^,<< and >>. This is
|
|
useful if one wants to build bit masks. If the two strings are not of
|
|
the same length the longer string is truncated (truncation was the
|
|
only real option, as padding with zeros could give unintuitive results
|
|
for ^) and the result has the length of the shorter string. If there
|
|
is a requirement for any other functions, let me know, and I will have
|
|
a look.
|
|
|
|
My knowledge of postgres is not up to integrating a type, so I'm hoping
|
|
that somebody can integrate this type for me, or give me some hints as
|
|
to what needs to be done. These routines were developed outside the
|
|
postgres source tree, with a hacked version of postgres.h. The header
|
|
files probably need some ammending.
|
|
|
|
The included files are
|
|
|
|
varbit.h -- bit string header type
|
|
varbit.c -- the routines
|
|
vartest.c -- a few calls to the routines to
|
|
|
|
The following routines are available.
|
|
|
|
char * zpbitin(char *s, int dummy, int32 atttypmod);
|
|
Read in a zero padded bit string of the form X'...' or B'...'
|
|
|
|
char * zpbitout(char *s);
|
|
Print a zero padded bit string in hex X'...'
|
|
|
|
char * zpbitsout(char *s);
|
|
Print a zero padded bit string in binary B'...'
|
|
|
|
char * varbitin(char *s, int dummy, int32 atttypmod);
|
|
Read in a varying length bit string of the form X'...' or B'...'
|
|
|
|
[There is no need for separate output functions for varying bit, as
|
|
zpbitout will print them out correctly]
|
|
|
|
char * bitcat (char *arg1, char *arg2);
|
|
Bit concatenation.
|
|
|
|
char * bitsubstr (char *arg, int32 s, int32 l);
|
|
Substring of a bit string.
|
|
|
|
bool biteq (char *arg1, char *arg2);
|
|
bool bitne (char *arg1, char *arg2);
|
|
bool bitge (char *arg1, char *arg2);
|
|
bool bitgt (char *arg1, char *arg2);
|
|
bool bitle (char *arg1, char *arg2);
|
|
bool bitlt (char *arg1, char *arg2);
|
|
int bitcmp (char *arg1, char *arg2);
|
|
Comparison operators
|
|
|
|
char * bitand (char * arg1, char * arg2);
|
|
char * bitor (char * arg1, char * arg2);
|
|
char * bitxor (char * arg1, char * arg2);
|
|
char * bitnot (char * arg);
|
|
char * bitshiftright (char * arg, int shft);
|
|
char * bitshiftleft (char * arg, int shft);
|
|
Bit operations.
|
|
|
|
If anything else needs to be done, please let me know.
|
|
|
|
Adriaan (adriaan@albourne.com)
|