MonetDB type system

From MonetDB
Revision as of 22:08, 6 October 2015 by Stefan Manegold (talk | contribs)
Jump to navigationJump to search
  • Rule #1
    • C types long & unsigned long are evil and must NOT be used!
      While they are 32/64-bit on 32/64-bit systems under Unix, they are always 32-bit (also on 64-bit systems) under Windows.
  • Rule #2
    • monetdb_config.h must be the first #include in each .c file (not in any .h file).
MonetDB type system
semantics SQL MAL C width signed? NIL value value range format string format cast availability C example
bit / boolean
(0/1 / false/true)
BOOLEAN :bit bit 1 byte
8 bit
(yes) bit_nil ==
(bit) bte_nil
[GDK_bit_min:GDK_bit_max]
[0:1]
"%hhd" always bit x = 0;
printf("%hhd", x);
1-byte (8-bit)
signed integer
TINYINT :bte bte 1 byte
8 bit
yes bte_nil ==
GDK_bte_min
(GDK_bte_min:GDK_bte_max]
(-128:127]
(-2^7:2^7-1]
"%hhd" always bte x = 0;
printf("%hhd", x);
2-byte (16-bit)
signed integer
SMALLINT :sht sht 2 byte
16 bit
yes sht_nil ==
GDK_sht_min
(GDK_sht_min:GDK_sht_max]
(-65536:65535]
(-2^15:2^15-1]
"%hd" always sht x = 0;
printf( "%hd", x);
4-byte (32-bit)
signed integer
INT / INTEGER :int int 4 byte
32 bit
yes int_nil ==
GDK_int_min
(GDK_int_min:GDK_int_max]
(-2147483648:2147483647]
(-2^31:2^31-1]
"%d" always int x = 0;
printf( "%d", x);
8-byte (64-bit)
signed integer
BIGINT :lng lng 8 byte
64 bit
yes lng_nil ==
GDK_lng_min
(GDK_lng_min:GDK_lng_max]
(-9223372036854775808:9223372036854775807]
(-2^63:2^63-1]
LLFMT always lng x = 0;
printf(LLFMT , x);
16-byte (128-bit)
signed integer
HUGEINT :hge hge 16 byte
128 bit
yes hge_nil ==
GDK_hge_min
(GDK_hge_min:GDK_hge_max]
(-170141183460469231731687303715884105728:170141183460469231731687303715884105727]
(-2^127:2^127-1]
(none provide by compilers) if supported by compiler
(configure then defines HAVE_HGE)
#ifdef HAVE_HGE
hge x = 0;
printf("%.40g", (dbl) x);
#endif
4-byte (32-bit)
floating-point number
REAL :flt flt 4 byte
32 bit
yes flt_nil ==
GDK_flt_min
(GDK_flt_min:GDK_flt_max]
(-FLT_MAX:FLT_MAX]
"%e", "%f", "%g" always flt x = 0;
printf( "%f", x);
8-byte (64-bit)
floating-point number
FLOAT / DOUBLE :dbl dbl 8 byte
64 bit
yes dbl_nil ==
GDK_dbl_min
(GDK_dbl_min:GDK_dbl_max]
(-DBL_MAX:DBL_MAX]
"%e", "%f", "%g" always dbl x = 0;
printf( "%f", x);
object-ID / tuple-ID :oid oid 4/8 byte
32/64 bit
no oid_nil ==
2^31/2^63
[GDK_oid_min:GDK_oid_max]
[0:2147483647/9223372036854775807]
[0:2^31-1/2^63-1]
OIDFMT always oid x = 0;
printf(OIDFMT, x);
number of tuples in BAT (count) BUN 4/8 byte
32/64 bit
no BUN_NONE ==
(BUN) GDK_int/lng_max
[0:BUN_MAX == (BUN_NONE - 1)]
[0:2147483646/9223372036854775806]
[0:2^31-2/2^63-2]
BUNFMT always BUN x = 0;
printf(BUNFMT, x);
string length [byte], array size [byte], memory size [byte] size_t 4/8 byte
32/64 bit
no [0:4294967295/18446744073709551615]
[0:2^32-1/2^64-1]
SZFMT always size_t x = 0;
printf( SZFMT, x);
string length -, array size -, memory size - difference [byte] ssize_t 4/8 byte
32/64 bit
yes [-2147483648/-9223372036854775808:2147483646/9223372036854775806]
[-2^31/-2^63:2^31-1/2^63-1]
SSZFMT always ssize_t x = 0;
printf(SSZFMT, x);
pointer difference [byte] ptrdiff_t 4/8 byte
32/64 bit
yes [-2147483648/-9223372036854775808:2147483646/9223372036854775806]
[-2^31/-2^63:2^31-1/2^63-1]
PDFMT always ptrdiff_t x = 0;
printf( PDFMT, x);
BAT-ID bat 4 byte
32 bit
yes bat_nil ==
(bat) int_nil
[-2147483648:2147483646]
(-2^31:2^31-1]
"%d" always bat x = 0;
printf( "%d", x);

... to be continued ...