我在vertica数据库中有一个表,它的列CON_BRWR是Varchar(100)Not Null。
我正在对此列进行加密。如果此列变为空字符串,则应该拒绝该行,但由于加密,它会加密空字符串并且也会为Null加密。
为了克服这个问题,我尝试了这个解决方案
COPY myschema.CON_BIZ ( __tempCON_BRWR FILLER VARCHAR(100),
CON_BRWR as Case WHEN __tempCON_BRWR = '' THEN NULL ELSE AESEncrypt(__tempCON_BRWR,'abcdefg') end
) FROM STDIN ENCLOSED BY '"' delimiter ',' ENFORCELENGTH SKIP 1 rejected data as table ErrorTable no commit;
如果 __ tempCON_BRWR 填充符变为空字符串,则不应加密值,但无论如何
它正处于其他状态
我被困住了,任何形式的帮助都将受到赞赏!
答案 0 :(得分:1)
它正处于其他状态
您的语法对于Vertica解析器有点问题,请参阅右侧语法的示例。
注意:强> 但它不能解决你的主要问题 - >拒绝一行。
<强> DDL:强>
CREATE TABLE public.haroon
(
id int,
raw varchar(100),
encrypted varchar(100)
);
使用COPY FROM STDIN
声明填充表格:
(最重要的部分,请查看CASE
语法和副本中NULL
的定义)
copy haroon(
id,
rawdata filler varchar(100),
raw as rawdata,
encrypted as case rawdata = '' or rawdata is NULL
when TRUE then NULL
else AESEncrypt(rawdata, 'secret')
end)
from stdin ENCLOSED BY '"' NULL as '' delimiter ',' direct abort on error;
daniel=> \e
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> 1,""
>> 2,
>> 3,foo
>> \.
{column} as case {filler} = '' or {filler} is NULL when TRUE then NULL else AESEncrypt({filler}, {password})
COPY ... NULL AS ''
<强>测试强>
daniel=> select id, raw, encrypted::varchar(3), encrypted is NULL from haroon ;
id | raw | encrypted | ?column?
----+-----+-----------+----------
1 | | | t
2 | | | t
3 | foo | �� | f
(3 rows)
您可以看到2个第一行(id = [1,2])在加密列中包含NULL
,数据加载时没有任何问题。