You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tableau Prep:如何在自定义SQL查询中引用参数?

在Tableau Prep Builder中引用参数到PostgreSQL自定义SQL的正确方式

场景说明

使用Tableau Prep Builder 2021.4.4连接PostgreSQL 12数据库,以自定义SQL作为数据源输入,已创建参数my_date,需要在SQL的WHERE子句中引用该参数,尝试多种写法均失败:

  • where date = ${my_date}:报syntax error at or near "$"
  • where date = $my_date:报syntax error at or near "$"
  • where date = :my_date:报syntax error at or near ":"
  • where date = (my_date)/where date = my_date:报"my_date" does not exist
  • where date = $1:报Index 0 out of bounds for length 0

正确解法

在Tableau Prep的自定义SQL中,针对PostgreSQL数据库,需要用**问号?**作为参数占位符,再手动关联已创建的参数:

  1. 编写自定义SQL语句:
select my_field
from my_table
where date = ?
  1. 点击确定后,Tableau Prep会弹出参数映射窗口,选择你已创建的my_date参数与该占位符关联,完成后即可正常运行。

失败原因说明

  • ${my_date}、:my_date这类语法是Tableau Desktop或其他工具的参数写法,Tableau Prep的自定义SQL对PostgreSQL不支持该格式
  • 直接写my_date会被PostgreSQL识别为数据表字段,而非Tableau参数
  • $1属于PostgreSQL的位置参数,但Tableau Prep不会自动关联已创建的参数,必须通过可视化界面手动映射才能生效

内容的提问来源于stack exchange,提问作者mtleis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 04:10:28