需求:现有table t 三个字段 CREATE TABLE t ( a bigint, b bigint, c bigint, PRIMARY KEY (a) NOT ENFORCED ) WITH ( ... ); 我们的场景只想根据主键a更新部分字段b,其余的字段c保持不变, 例如mysql 支持:insert into t(a,b) select 1,2 on duplicate key update b=2; 主键重复的时候只更新字段b,字段c的值不变。但是flink sql 目前只支持全字段更新:insert into t(a,b,c) select 1,2,3 我在sql-client测试了一下:insert into t(a,b) select 1,2 on duplicate key update b=2; 会报错 不支持 on duplicate key update同时也测试了一下:insert into t(a,b) select 1,2 也会报错,字段数量不匹配;[ERROR] Could not execute SQL statement. Reason:org.apache.flink.table.api.ValidationException: Column types of query result and sink for registered table 'default_catalog.default_database.t' do not match.Cause: Different number of columns.请问这种根据主键更新部分字段的场景 使用flink sql应该怎么处理?
在 2021-08-02 14:35:04,"Shengkai Fang" <[email protected]> 写道: >Flink 暂时不支持这个功能,可能需要自己改一下 jdbc connector 相关的代码. > >但是这个报错很奇怪..你 sql 咋写的 > >Ye Chen <[email protected]> 于2021年8月2日周一 上午11:37写道: > >> 你好,我试了一下,如果表的ddl是三个字段,但是insert只指定两个字段的话,会报错: >> [ERROR] Could not execute SQL statement. Reason: >> org.apache.flink.table.api.ValidationException: Column types of query >> result and sink for registered table 'default_catalog.default_database.t' >> do not match. >> Cause: Different number of columns. >> 我们的需求是想根据主键更新部分字段 >> >> ------------------------------------- >> >> 需求:现有table >> CREATE TABLE t ( >> a bigint, >> b bigint, >> c bigint, >> PRIMARY KEY (a) NOT ENFORCED >> ) WITH ( >> ... >> ); >> 我们的场景只想根据主键a更新部分字段b,其余的字段c保持不变, >> 例如mysql 支持 insert into t(a,b,c) select '1','2','3' on duplicate key >> update b='4';主键重复的时候只更新字段b,字段c的值不变。 >> 我在官方文档中没找到这个用法,sql-client也测试了一下也不支持 on duplicate key update,会报错。 >> 请问这种根据主键更新部分字段的场景 使用flink sql应该怎么处理? >> >> >> >> >> >> >> >> 在 2021-08-02 10:47:55,"silence" <[email protected]> 写道: >> >如果只想更新部分字段的话可以试下 >> >insert into t(a,b) select a,b from xxxxx >> > >> > >> >------------------------------------------------------------------ >> >发件人:Ye Chen <[email protected]> >> >发送时间:2021年7月30日(星期五) 17:57 >> >收件人:user-zh <[email protected]> >> >主 题:场景题:Flink SQL 不支持 INSERT INTO… ON DUPLICATE KEY UPDATE ? >> > >> >现有table >> >CREATE TABLE t ( >> > a bigint, >> > b bigint, >> > c bigint, >> > PRIMARY KEY (a) NOT ENFORCED >> >) WITH ( >> >... >> >); >> > >> > >> >我们的场景只想根据主键a更新部分字段b,其余的字段保持不变,例如 >> >mysql 支持 insert into t(a,b,c) select '1','2','3' on duplicate key >> update b='4'; >> >主键重复的时候只更新字段b,字段c的值不变 >> > >> > >> >我在官方文档中没找到这个用法,sql-client也测试了一下也不支持 on duplicate key update,会报错。 >> >请问这种部分字段更新的场景 使用flink sql应该怎么处理? >> > >> > >>
