【已解决】doris insert into having 语法禁止写入,查询无问题

Viewed 56

版本2.0.13
异常如下

 errCode = 2, detailMessage = HAVING clause must not contain analytic expressions: row_number() OVER (PARTITION BY `biz_date` ORDER BY `qty` DESC NULLS LAST)

测试用例如下


CREATE TABLE tmp.`having_insert_t1` (
  `biz_date` date NULL COMMENT '业务日期',
  `qty` int NULL COMMENT '',
  `etl_time` datetime NULL COMMENT 'etl时间'
) ENGINE=OLAP
COMMENT 'biz_date'
DISTRIBUTED BY HASH(`biz_date`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"storage_medium" = "hdd",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false"
);




CREATE TABLE tmp.`having_insert_t2` (
  `biz_date` date NULL COMMENT '业务日期',
  `qty` int NULL COMMENT '',
  `etl_time` datetime NULL COMMENT 'etl时间'
) ENGINE=OLAP
COMMENT 'biz_date'
DISTRIBUTED BY HASH(`biz_date`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"storage_medium" = "hdd",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false"
);


数据写入
insert into  tmp.`having_insert_t1` values('2024-08-01',1,now()),('2024-08-01',3,now()),('2024-08-02',2,now()),('2024-08-02',4,now()),('2024-08-03',1,now()),('2024-08-03',5,now())

异常写入如下

insert into  tmp.`having_insert_t2`
select biz_date,qty,now() from(
select
	biz_date ,
	qty,
	row_number() over(partition by biz_date order by qty desc) as row_num
from
	tmp.`having_insert_t1`
having 
	row_num = 1
)res

此查询无问题,写入报错语法不兼容

1 Answers

设置 set global enable_nereids_dml = true 就行了