# 密态函数和操作符
- byteawithoutorderwithequalcolin(cstring) 描述：将输入转码转化成内部byteawithoutorderwithequalcol形式。
  参数类型：cstring
  返回值类型：byteawithoutorderwithequalcol
  

- byteawithoutorderwithequalcolout(byteawithoutorderwithequalcol) 描述：将内部byteawithoutorderwithequalcol类型的数据转码转化为cstring类型。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：cstring
  

- byteawithoutorderwithequalcolsend(byteawithoutorderwithequalcol) 描述：将byteawithoutorderwithequalcol类型的数据转码转化为bytea类型。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：bytea
  
- byteawithoutorderwithequalcolrecv(internal) 描述：将internal类型的数据转码转化为byteawithoutorderwithequalcol类型。
  参数类型：internal
  返回值类型：byteawithoutorderwithequalcol
  
- byteawithoutorderwithequalcoltypmodin(cstring\[\]) 描述：将cstring\[\]类型的数据转码转化为byteawithoutorderwithequalcol类型。
  参数类型：cstring\[\]
  返回值类型：int4
  
- byteawithoutorderwithequalcoltypmodout(int4) 描述：将int4类型的数据转码转化为cstring类型。
  参数类型：int4
  返回值类型：cstring
  
- byteawithoutordercolin(cstring) 描述：将输入转码转化成内部byteawithoutordercolin形式。
  参数类型：cstring
  返回值类型：byteawithoutordercol
  
- byteawithoutordercolout(byteawithoutordercol) 描述：将内部byteawithoutordercol类型的数据转码转化为cstring类型。
  参数类型：byteawithoutordercol
  返回值类型：cstring
  
- byteawithoutordercolsend(byteawithoutordercol) 描述：将byteawithoutordercol类型的数据转码转化为bytea类型。
  参数类型：byteawithoutordercol
  返回值类型：bytea
  
- byteawithoutordercolrecv(internal) 描述：将internal类型的数据转码转化为byteawithoutordercol类型。
  参数类型：internal
  返回值类型：byteawithoutordercol
  
- byteawithoutorderwithequalcolcmp(byteawithoutorderwithequalcol, byteawithoutorderwithequalcol) 描述：比较两个byteawithoutorderwithequalcol类型的数据大小，若第一个参数小于第二个参数，返回-1；若等于，返回0；若大于，则返回1。
  参数类型：byteawithoutorderwithequalcol, byteawithoutorderwithequalcol
  返回值类型：int4
  
- byteawithoutorderwithequalcolcmpbytear(byteawithoutorderwithequalcol, bytea) 描述：比较byteawithoutorderwithequalcol和bytea数据大小，若第一个参数小于第二个参数，返回-1；若等于，返回0；若大于，则返回1。
  参数类型：byteawithoutorderwithequalcol, bytea
  返回值类型：int4
  
- byteawithoutorderwithequalcolcmpbyteal(bytea, byteawithoutorderwithequalcol) 描述：比较bytea和byteawithoutorderwithequalcol数据大小，若第一个参数小于第二个参数，返回-1；若等于，返回0；若大于，则返回1。
  参数类型：bytea、byteawithoutorderwithequalcol
  返回值类型：int4
  
- byteawithoutorderwithequalcoleq(byteawithoutorderwithequalcol, byteawithoutorderwithequalcol) 描述：比较两个byteawithoutorderwithequalcol类型的数据是否相同，相同则返回true，否则返回false。
  参数类型：byteawithoutorderwithequalcol、byteawithoutorderwithequalcol
  返回值类型：bool
  
- byteawithoutorderwithequalcoleqbyteal(bytea, byteawithoutorderwithequalcol) 描述：比较bytea和byteawithoutorderwithequalcol数据是否相同，相同则返回true，否则返回false。
  参数类型：bytea，byteawithoutorderwithequalcol
  返回值类型：bool
  
- byteawithoutorderwithequalcoleqbytear(byteawithoutorderwithequalcol, bytea) 描述：比较byteawithoutorderwithequalcol和bytea数据是否相同，相同则返回true，否则返回false。
  参数类型：byteawithoutorderwithequalcol, bytea
  返回值类型：bool
  
- byteawithoutorderwithequalcolne(byteawithoutorderwithequalcol, byteawithoutorderwithequalcol) 描述：比较两个byteawithoutorderwithequalcol类型的数据是否不相同，不相同则返回true，否则返回false。
  参数类型：byteawithoutorderwithequalcol, byteawithoutorderwithequalcol
  返回值类型：bool
  
- byteawithoutorderwithequalcolnebyteal(bytea, byteawithoutorderwithequalcol) 描述：比较bytea和byteawithoutorderwithequalcol数据是否相同，相同则返回true，否则返回false。
  参数类型：bytea，byteawithoutorderwithequalcol
  返回值类型：bool
  
- byteawithoutorderwithequalcolnebytear(byteawithoutorderwithequalcol, bytea) 描述：比较byteawithoutorderwithequalcol和bytea数据是否不相同，相同则返回true，否则返回false。
  参数类型：byteawithoutorderwithequalcol, bytea
  返回值类型：bool
  
- hll_hash_byteawithoutorderwithequalcol(byteawithoutorderwithequalcol) 描述：返回byteawithoutorderwithequalcol的hll哈希值。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：hll_hashval
  
- tee_sortsupport(internal) 描述：排序辅助函数，执行排序时供内部调用，不支持用户调用。
  参数类型：internal
  返回值类型：void
  
- teegtsel(internal, oid, internal, integer) 描述：密文比较大于和大于等于选择率函数。返回默认值0.3333333333333333。不支持用户调用。
  参数类型：internal, oid, internal, integer
  返回值类型：double precision
  
- teeltsel(internal, oid, internal, integer) 描述：密文比较小于和小于等于选择率函数，返回默认值0.3333333333333333。不支持用户调用。
  参数类型：internal, oid, internal, integer
  返回值类型：double precision
  
- teelikesel(internal, oid, internal, integer) 描述：密文模糊匹配选择率函数。返回默认值0.005。不支持用户调用。
  参数类型：internal, oid, internal, integer
  返回值类型：double precision
  
- teenlikesel(internal, oid, internal, integer) 描述：密文不能模糊匹配选择率函数，返回默认值0.005。不支持用户调用。
  参数类型：internal, oid, internal, integer
  返回值类型：double precision
  
- sum(byteawithoutorderwithequalcol) 描述：密文求和聚合运算。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- avg(byteawithoutorderwithequalcol) 描述：密文求均值聚合运算。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- min(byteawithoutorderwithequalcol) 描述：密文求极小值聚合运算。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- max(byteawithoutorderwithequalcol) 描述：密文求极大值聚合运算。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- stddev_samp(byteawithoutorderwithequalcol) 描述：密文样本标准差聚合运算。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- stddev_pop(byteawithoutorderwithequalcol) 描述：密文总体标准差聚合运算。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- var_samp(byteawithoutorderwithequalcol) 描述：密文样本方差聚合运算。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- var_pop(byteawithoutorderwithequalcol) 描述：密文总体方差聚合运算。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- tee_trans(byteawithoutorderwithequalcol, byteawithoutorderwithequalcol) 描述：密文聚合运算内部处理函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- tee_collect(byteawithoutorderwithequalcol, byteawithoutorderwithequalcol) 描述：密文聚合运算内部处理函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- tee_final(byteawithoutorderwithequalcol) 描述：密文聚合运算内部处理函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(text, oid) 描述：将text类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id，当前版本暂不支持。
  参数类型：text, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(int1, oid) 描述：将int1类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：int1, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(int2, oid) 描述：将int2类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：int2, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(int4, oid) 描述：将int4类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：int4, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(int8, oid) 描述：将int8类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：int8, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(float4, oid) 描述：将float4类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：float4, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(float8, oid) 描述：将float8类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：float8, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(numeric, oid) 描述：将numeric类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：numeric, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(clob, oid) 描述：将clob类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：clob, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(varchar, oid) 描述：将varchar类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：varchar, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(nvarchar2, oid) 描述：将nvarchar2类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：nvarchar2, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(bpchar, oid) 描述：将bpchar类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：bpchar, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_deterministic(bytea, oid) 描述：将bytea类型的明文数据加密至密态等值结构的密文，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：bytea, oid
  返回值类型：byteawithoutorderwithequalcol
  
- ce_decrypt_deterministic(byteawithoutorderwithequalcol, oid) 描述：将密态等值结构的密文解密至text类型的明文数据，密钥oid为系统表gs_column_keys中的column_key_distributed_id。当前版本暂不支持。
  参数类型：byteawithoutorderwithequalcol, oid
  返回值类型：text
  
![](https://support.huaweicloud.com/distributed-ref-v10-gaussdb/public_sys-resources/note_3.0-zh-cn.png)
以下以ce_encrypt/ce_decrypt开头的函数存在于pg_catalog命名空间。
- ce_encrypt_text(text, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：text, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_varchar(varchar, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：varchar, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_nvarchar2(nvarchar2, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：nvarchar2, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_bpchar(bpchar, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：bpchar, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_int1(int1, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：int1, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_int2(int2, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：int2, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_int4(int4, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：int4, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_int8(int8, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：int8, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_float4(float4, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：float4, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_float8(float8, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：float8, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_numeric(numeric, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：numeric, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_bytea(bytea, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：bytea, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_encrypt_clob(clob, int4, boolean, int4, internal) 描述：全密态类型转换加密函数。不支持用户调用。
  参数类型：clob, int4, boolean, int4, internal
  返回值类型：byteawithoutorderwithequalcol
  
- ce_decrypt_text(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：text
  
- ce_decrypt_varchar(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：varchar
  
- ce_decrypt_nvarchar2(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：nvarchar2
  
- ce_decrypt_bpchar(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：bpchar
  
- ce_decrypt_int1(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：int1
  
- ce_decrypt_int2(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：int2
  
- ce_decrypt_int4(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：int4
  
- ce_decrypt_int8(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：int8
  
- ce_decrypt_float4(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：float4
  
- ce_decrypt_float8(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：float8
  
- ce_decrypt_numeric(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：numeric
  
- ce_decrypt_bytea(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：bytea
  
- ce_decrypt_clob(byteawithoutorderwithequalcol, int4, boolean, int4, internal) 描述：全密态类型转换解密函数。不支持用户调用。
  参数类型：byteawithoutorderwithequalcol, int4, boolean, int4, internal
  返回值类型：clob
  
#### 示例
byteawithoutorderwithequalcolin、byteawithoutorderwithequalcolout等密态等值函数为数据库内核中数据类型byteawithoutorderwithequalcol指定的in、out、send、recv等读写格式转换函数，具体可参考bytea类型的byteain、byteaout等函数，但会对本地的cek进行验证，需要密文字段中有本地存在的cekoid才能执行成功。
```
-- 例如使用密态客户端连接数据库,创建加密表int_type，int_col2为其加密列。
gaussdb=# \key_info keyType=user_token,password=********* 
gaussdb=# CREATE CLIENT MASTER KEY MyCMK WITH (KEY_STORE = user_token, ALGORITHM = AES_256_CBC);
gaussdb=# CREATE COLUMN ENCRYPTION KEY cek1 WITH VALUES (CLIENT_MASTER_KEY = MyCMK, ALGORITHM = AEAD_AES_256_CBC_HMAC_SHA256);
gaussdb=# CREATE TABLE IF NOT EXISTS int_type (
id INT, 
int_col1 TINYINT,
int_col2 smallint ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = cek1, ENCRYPTION_TYPE = DETERMINISTIC)
);
CREATE TABLE
gaussdb=# INSERT INTO int_type VALUES (2, 100, 200);
INSERT 0 1
-- 使用非密态客户端连接数据库，查询加密列密文。
gaussdb=# SELECT int_col2 FROM int_type;
                                                                       int_col2
------------------------------------------------------------------------------------------------------------------------------------------------------
 \x01c35301bf421c8edf38c34704bcc82838742917778ccb402a1b7452ad4a6ac7371acc0ac33100000035fe3424919854c86194f1aa5bb4e1ca656e8fc6d05324a1419b69f488bdc3c6
(1 row)
-- 将加密列密文当做byteawithoutorderwithequalcolin入参，格式从cstring输入转码转化成内部byteawithoutorderwithequalcol形式。
gaussdb=# SELECT byteawithoutorderwithequalcolin('\x01c35301bf421c8edf38c34704bcc82838742917778ccb402a1b7452ad4a6ac7371acc0ac33100000035fe3424919854c86194f1aa5bb4e1ca656e8fc6d05324a1419b69f488bdc3c6');
                                                           byteawithoutorderwithequalcolin
------------------------------------------------------------------------------------------------------------------------------------------------------
 \x01c35301bf421c8edf38c34704bcc82838742917778ccb402a1b7452ad4a6ac7371acc0ac33100000035fe3424919854c86194f1aa5bb4e1ca656e8fc6d05324a1419b69f488bdc3c6
(1 row)
```
由于byteawithoutorderwithequalcolin等的实现会对cek进行查找，并且判断是否为正常加密后的数据类型。
因此如果用户输入数据的格式不是加密后的数据格式，并且在本地不存在对应cek的情况下，会返回错误。
```
gaussdb=# SELECT * FROM byteawithoutorderwithequalcolsend('\x907219912381298461289346129'::byteawithoutorderwithequalcol);
ERROR:  cek with OID 596711794 not found
LINE 1: SELECT * FROM byteawithoutorderwithequalcolsend('\x907219912...
                                                        ^
gaussdb=# SELECT * FROM byteawithoutordercolout('\x90721901999999999999912381298461289346129');
ERROR:  cek with OID 2566986098 not found
LINE 1: SELECT * FROM byteawithoutordercolout('\x9072190199999999999...
   
                                           ^
gaussdb=# SELECT * FROM byteawithoutorderwithequalcolsend('\x90721901999999999999912381298461289346129'::byteawithoutorderwithequalcol);
ERROR:  cek with OID 2566986098 not found
LINE 1: SELECT * FROM byteawithoutorderwithequalcolsend('\x907219019...
                                                        ^
```
