2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
"""
|
|
|
|
ID: issue-2834
|
|
|
|
ISSUE: 2834
|
|
|
|
TITLE: AV preparing a query with aggregate over derived table
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-2416
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_2416
|
2022-01-21 18:49:26 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
test_script = """WITH
|
2021-04-26 20:07:00 +02:00
|
|
|
t0 AS (
|
|
|
|
SELECT 1 AS f0, date '01.03.09' AS f1, 'Event1' AS f2
|
|
|
|
FROM rdb$database
|
|
|
|
),
|
|
|
|
|
|
|
|
t1 (f1) AS (
|
|
|
|
SELECT MIN(t2.f1) AS f1 FROM t0 AS t2 WHERE t2.f0 > t3.f0 AND t2.f1 >= t3.f1 AND t2.f2 = t3.f2
|
|
|
|
)
|
|
|
|
|
|
|
|
SELECT t4.f2, t4.f1_p
|
|
|
|
FROM (SELECT t3.f0, t3.f1, t3.f2, CAST((SELECT t1.f1 FROM t1) - t3.f1 AS INTEGER) AS f1_p
|
|
|
|
FROM t0 AS t3
|
|
|
|
) AS t4
|
|
|
|
WHERE t4.f1_p IS NOT NULL
|
|
|
|
GROUP BY t4.f2, t4.f1_p;
|
|
|
|
|
|
|
|
SELECT t4.f2, t4.f1_p
|
|
|
|
FROM (SELECT t3.f0, t3.f1, t3.f2,
|
|
|
|
CAST((SELECT t1.f1 FROM (
|
|
|
|
SELECT MIN(t2.f1) AS f1 FROM (
|
|
|
|
SELECT 1 AS f0, date '01.03.09' AS f1, 'Event1' AS f2
|
|
|
|
FROM rdb$database) AS t2
|
|
|
|
WHERE t2.f0 > t3.f0 AND t2.f1 >= t3.f1 AND t2.f2 = t3.f2) as t1)
|
|
|
|
- t3.f1 AS INTEGER) AS f1_p
|
|
|
|
FROM (
|
|
|
|
SELECT 1 AS f0, date '01.03.09' AS f1, 'Event1' AS f2
|
|
|
|
FROM rdb$database) AS t3
|
|
|
|
) AS t4
|
|
|
|
WHERE t4.f1_p IS NOT NULL
|
|
|
|
GROUP BY t4.f2, t4.f1_p ;
|
|
|
|
"""
|
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
act = isql_act('db', test_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
@pytest.mark.version('>=3')
|
|
|
|
def test_1(act: Action):
|
2022-01-25 22:55:48 +01:00
|
|
|
act.execute()
|