【发布时间】:2015-06-21 14:52:09
【问题描述】:
我有动态 SQL,需要在执行之前对其进行操作。基本上我通过作为字符串传递来构建查询。我终于想出了查询,但我现在的问题是如何执行所述查询。我尝试使用表输入,而 SQL 的内容只是一个“?”要在构建的字符串上替换。不幸的是,它不起作用。
我该怎么做?
以下是步骤的屏幕截图。我可能不需要“选择值”步骤,我只是为了自己的可见性而添加了它。我对pentaho水壶很陌生。但是,我希望你明白这一点。基本上我在这里所做的是一旦我进入计算器步骤,这是我制定 SQL 查询的地方,因为它是一个选择,所以想在表输入上执行它。
这是错误:
2015/04/15 21:45:09 - Table input.0 - ERROR (version 5.0.1-stable, build 1 from 2013-11-15_16-08-58 by buildguy) : Unexpected error
2015/04/15 21:45:09 - Table input.0 - ERROR (version 5.0.1-stable, build 1 from 2013-11-15_16-08-58 by buildguy) : org.pentaho.di.core.exception.KettleDatabaseException:
2015/04/15 21:45:09 - Table input.0 - An error occurred executing SQL:
2015/04/15 21:45:09 - Table input.0 - ?
2015/04/15 21:45:09 - Table input.0 - ERROR: syntax error at or near "$1"
Position: 1
2015/04/15 21:45:09 - Table input.0 -
2015/04/15 21:45:09 - Table input.0 - at org.pentaho.di.core.database.Database.openQuery(Database.java:1641)
2015/04/15 21:45:09 - Table input.0 - at org.pentaho.di.trans.steps.tableinput.TableInput.doQuery(TableInput.java:235)
2015/04/15 21:45:09 - Table input.0 - at org.pentaho.di.trans.steps.tableinput.TableInput.processRow(TableInput.java:143)
2015/04/15 21:45:09 - Table input.0 - at org.pentaho.di.trans.step.RunThread.run(RunThread.java:60)
2015/04/15 21:45:09 - Table input.0 - at java.lang.Thread.run(Unknown Source)
2015/04/15 21:45:09 - Table input.0 - Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Position: 1
2015/04/15 21:45:09 - Table input.0 - at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2101)
2015/04/15 21:45:09 - Table input.0 - at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1834)
2015/04/15 21:45:09 - Table input.0 - at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
2015/04/15 21:45:09 - Table input.0 - at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510)
2015/04/15 21:45:09 - Table input.0 - at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386)
2015/04/15 21:45:09 - Table input.0 - at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
2015/04/15 21:45:09 - Table input.0 - at org.pentaho.di.core.database.Database.openQuery(Database.java:1611)
2015/04/15 21:45:09 - Table input.0 - ... 4 more
2015/04/15 21:45:09 - getLastIncrementingPk - ERROR (version 5.0.1-stable, build 1 from 2013-11-15_16-08-58 by buildguy) : Errors detected!
2015/04/15 21:45:09 - getLastIncrementingPk - ERROR (version 5.0.1-stable, build 1 from 2013-11-15_16-08-58 by buildguy) : Errors detected!
【问题讨论】:
-
你在那里工作吗?还是来自您设置变量的同一转换?你能提供更多关于你得到的错误,你使用的步骤的信息吗?
-
我会更详细地更新帖子。但是为了回答你的问题,我使用了一个转换。变量是在先前的转换上设置的。我为这个转换所做的是“获取变量”并从那里获取。
-
这表明您保存在变量中的字符串不是一个好的 sql。记录该变量的值并在客户端(如 toad、sqlserver、squirrel 或其他)中执行该值
标签: sql pentaho kettle dynamic-queries