我有以下代码:
@RegisterMapper(MyEntity.ResultMapper.class)
@UseStringTemplate3StatementLocator
public interface MyDao {
@Transaction(TransactionIsolationLevel.SERIALIZABLE)
@SqlBatch("INSERT INTO mySchema.myTable (" +
" id, entity_type, entity_id, flags " +
" ) VALUES " +
"(" +
" :stepId , :entityType , :entityId,parse_json(:flags) " +
")")
@BatchChunkSize(500)
Object create( @BindBean List<MyEntity> entities );
}
如您所见,我正在使用此DAO将实体列表批量插入到Snowflake表中。
问题是我无法插入标志列,这是一个变体。我尝试过to_variant(:flags)
,目前已经尝试过parse_json(:flags)
,但JDBI不断抛出以下错误:
net.snowflake.client.jdbc.SnowflakeSQLException: SQL
compilation error:
Invalid expression [PARSE_JSON(?)] in VALUES clause
[statement:"INSERT INTO mySchema.myTable ( id, entity_type,
entity_id, flags ) VALUES ( :stepId , :entityType , :entityId,
parse_json(:flags) )", located:"null", rewritten:"null",
arguments:{ positional:{}, named:{timeStamp:'null',
entityType:MYENTITY,
flags:'{"client":"myClient","flow":"myFlow"}',stepId:null,
entityId:'189643357241513', class:class myOrg.MyEntity}, finder:[]}]
我应该如何在flags列中传递值?有人尝试过吗? MyEntity中的flags
字段处于我的控制范围内,我可以将其保留为POJO或String,以帮助解决此问题的方式为准。