openGauss=# CREATE TABLE creditcard_info (id_number int, name text encrypted with (column_encryption_key = ImgCEK, encryption_type = DETERMINISTIC),
credit_card varchar(19) encrypted with (column_encryption_key = ImgCEK1, encryption_type = DETERMINISTIC));
NOTICE: The 'DISTRIBUTE BY' clause is not specified. Using 'id_number' as the distribution column by default.
HINT: Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
CREATE TABLE
查询表的详细信息如下,Modifiers值为encrypted则表示该列是加密列。
openGauss=# \d creditcard_info
Table "public.creditcard_info"
Column | Type | Modifiers
-------------+-------------------+------------
id_number | integer |
name | text | encrypted
credit_card | character varying | encrypted
向加密表插入数据并进行等值查询。
openGauss=# INSERT INTO creditcard_info VALUES (1,'joe','6217986500001288393');
INSERT 0 1
openGauss=# INSERT INTO creditcard_info VALUES (2, 'joy','6219985678349800033');
INSERT 0 1
openGauss=# select * from creditcard_info where name = 'joe';
id_number | name | credit_card
-----------+------+---------------------
1 | joe | 6217986500001288393
(1 row)
注意:使用非密态客户端查看该加密表数据时是密文
openGauss=# select id_number,name from creditcard_info;
id_number | name
-----------+------------------------------------------------------------------------------------------------------------------------------------------------------
1 | \x011aefabd754ded0a536a96664790622487c4d366d313aecd5839e410a46d29cba96a60e4831000000ee79056a114c9a6c041bb552b78052e912a8b730609142074c63791abebd0d38
2 | \x011aefabd76853108eb406c0f90e7c773b71648fa6e2b8028cf634b49aec65b4fcfb376f3531000000f7471c8686682de215d09aa87113f6fb03884be2031ef4dd967afc6f7901646b
(2 rows)
(可选)对加密表进行alter和update操作。
openGauss=# ALTER TABLE creditcard_info ADD COLUMN age int ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = ImgCEK, ENCRYPTION_TYPE = DETERMINISTIC);
ALTER TABLE
openGauss=# \d creditcard_info
Table "public.creditcard_info"
Column | Type | Modifiers
-------------+-------------------+------------
id_number | integer |
name | text | encrypted
credit_card | character varying | encrypted
age | integer | encrypted
openGauss=# ALTER TABLE creditcard_info DROP COLUMN age;
ALTER TABLE
openGauss=# update creditcard_info set credit_card = '80000000011111111' where name = 'joy';
UPDATE 1
openGauss=# select * from creditcard_info where name = 'joy';
id_number | name | credit_card
-----------+------+-------------------
2 | joy | 80000000011111111
(1 row)