.. _kdb_tinyint:

============
kdb_tinyint
============


插件kdb_tinyint简介
-----------------------------

插件kdb_tinyint是初始化内置，基本类型，支持tinyint类型。

- 插件名为 kdb_tinyint

- 插件版本 V1.0


插件kdb_tinyint加载方式
-----------------------------

默认已经创建，如果没有创建，需要在命令行执行create extension kdb_tinyint;

示例：

.. code::

    create extension kdb_tinyint;


插件kdb_tinyint的参数配置
-----------------------------

无需配置任何参数。


插件kdb_tinyint的使用方法
-----------------------------

加载插件kdb_tinyint后，按照如下方式使用相应功能。


conversion functions support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

支持tinyint类型和数值及字符类型之间转换。

**语法**

.. code::

    create cast (int4 as tinyint) with function tinyint(int4) as assignment;
    create cast (tinyint as int4) with function int4(tinyint) as implicit;
    create cast (bool as tinyint) with function tinyint(bool) as assignment;
    create cast (tinyint as bool) with function bool(tinyint) as assignment;
    create cast (int2 as tinyint) with function tinyint(int2) as assignment;
    create cast (tinyint as int2) with function int2(tinyint) as implicit;
    create cast (int8 as tinyint) with function tinyint(int8) as assignment;
    create cast (tinyint as int8) with function int8(tinyint) as implicit;
    create cast (float4 as tinyint) with function tinyint(float4) as assignment;
    create cast (tinyint as float4) with function float4(tinyint) as implicit;
    create cast (float8 as tinyint) with function tinyint(float8) as assignment;
    create cast (tinyint as float8) with function float8(tinyint) as implicit;
    create cast (numeric as tinyint) with function tinyint(numeric) as assignment;
    create cast (tinyint as numeric) with function tinyinttonumeric(tinyint) as implicit;
    create cast (bpchar as tinyint) with function tinyint(bpchar) as implicit;
    create cast (tinyint as bpchar) with function text(tinyint) as assignment;
    create cast (varchar as tinyint) with function tinyint(varchar) as implicit;
    create cast (tinyint as varchar) with function text(tinyint) as assignment;
    create cast (bpcharbyte as tinyint) with function tinyint(bpcharbyte) as implicit;
    create cast (tinyint as bpcharbyte) with function text(tinyint) as assignment;
    create cast (varcharbyte as tinyint) with function tinyint(varcharbyte) as implicit;
    create cast (tinyint as varcharbyte) with function text(tinyint) as assignment;
    create cast (text as tinyint) with function tinyint(text) as implicit;
    create cast (tinyint as text) with function text(tinyint) as implicit;


**示例**

.. code::

    select '127'::tinyint::int2 as result;
    result
    --------
    127

    select '127'::tinyint::int4 as result;
    result
    --------
    127

    select '127'::tinyint::int8 as result;
    result
    --------
    127


operator functions support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tinyint类型和tinyint、int2、int4、int8之间支持算术操作符+-*/和比较操作符=、<>、<、<=、>、>=操作。
支持tinyint类型和money之间*操作。


**示例**

.. code::

    select tinyint '8' + int2 '5' as result;
    result
    --------
    13

    select tinyint '8' - tinyint '5' as result;
    result
    --------
    3

    select tinyint '8' * tinyint '5' as result;
    result
    --------
    40

    select tinyint '8' / tinyint '5' as result;
    result
    --------
    1.6



index suppor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tinyint类型支持btree、bitmap、hash、gin、brin类型索引。


**示例**

.. code::

    create table tinyint_ind(a tinyint);
    CREATE TABLE

    insert into tinyint_ind values(generate_series(-128, 127));
    INSERT 0 256

    create index btree_index on tinyint_ind using btree(a);
    CREATE INDEX


mathematics functions support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tinyint类型支持支持mod、abs、and、or、xor、shl、shr、not、um、up函数。


**示例**

.. code::

    select mod(20::tinyint,3);
    mod
    -----
    2



插件kdb_tinyint卸载方法
-----------------------------

系统启动自带插件，无法卸载。


插件kdb_tinyint升级方法
-----------------------------

kdb_tinyint扩展插件通常随着KingbaseES安装包一并升级。通常情况下用户无须单独升级些插件。
