0

我是 Razor 的新手(使用 v. 6.3.29)并尝试将一些 pgAdmin 脚本改编为 Razor。数据驻留在 postgres 上。

作为 pg-script 运行时在 pgAdmin 中按需要工作的示例:

    --declare variables
    set @start_date = '2019/01/01';
    set @end_date = '2019/12/31';
    set @emp_id = '42';
    
    --query
    create temp table t1 as
    (
     select emp_id, c1, c2, c3
     from activity
     where log_date between to_date('@start_date','yyyy/mm/dd') and to_date('@end_date','yyyy/mm/dd')
     and employee_id = '@emp_id'
    )
    distributed by (emp_id);

以下适用于 Razor,在作为 SQL 语句运行时使用带有变量的提示功能:

    --query
    create temp table t1 as
    (
     select emp_id, c1, c2, c3
     from activity
     where log_date between to_date(&start_date,'yyyy/mm/dd') and to_date(&end_date,'yyyy/mm/dd')
     and employee_id = &emp_id
    )
    distributed by (emp_id);

我的问题是:Razor 能否支持脚本并避免提示输入变量?

编辑:我意识到我可以为我的变量使用一个公共表表达式,但这并不漂亮,因为我每个脚本有大约 20 个查询,其中一些有很多表连接。

4

0 回答 0