带有“partition by”的准备好的语句 不适用于 Sybase IQ?

发布于 2024-07-26 09:56:17 字数 1416 浏览 11 评论 0原文

我在使用准备好的语句查询 Sybase IQ 时遇到问题。 当我以文本形式输入整个查询,然后在不带参数的情况下对其调用PrepareStatement 时,查询工作正常。 但是当我输入一个参数时,即使我的 sql 是正确的,我也会收到错误。 知道为什么吗?

这段代码运行得很好,并且运行我的查询:

errorquery<<"SELECT   1   as foobar \
        ,       (SUM(1) over (partition by foobar) )      as myColumn  \
        FROM spgxCube.LPCache lpcache   \
                WHERE    lpcache.CIG_OrigYear = 2001    "; 


odbc::Connection* connQuery= SpgxDBConnectionPool::getInstance().getConnection("MyServer");
PreparedStatementPtr pPrepStatement(connQuery->prepareStatement(errorquery.str()));
    pPrepStatement->executeQuery();

但这是完全相同的事情,除了我不是直接在代码中键入“2001”,而是使用参数插入它:

    errorquery<<"SELECT   1   as foobar \
        ,       (SUM(1) over (partition by foobar) )      as myColumn  \
        FROM spgxCube.LPCache lpcache   \
                WHERE    lpcache.CIG_OrigYear = ?    "; 

    odbc::Connection* connQuery = SpgxDBConnectionPool::getInstance().getConnection("MyServer");
    PreparedStatementPtr pPrepStatement(connQuery->prepareStatement(errorquery.str()));

    int intVal = 2001;
    pPrepStatement->setInt(1, intVal);

    pPrepStatement->executeQuery();

这会产生以下错误: [Sybase][ODBC 驱动程序][Adaptive Server Anywhere]'(SUM(1) over(partition by foobar)) as myColumn' 附近的表达式无效

知道为什么如果第二个失败,第一个可以工作吗? 是否不允许在插入的sql参数或类似的东西中使用“分区依据”?

I'm seeing a problem when querying Sybase IQ with a prepared statement. The query works fine when I type the entire query as text and then call PrepareStatement on it with no parameters. But when I stick in one parameter, then I get back errors, even though my sql is correct. Any idea why?

This code works perfectly fine and runs my query:

errorquery<<"SELECT   1   as foobar \
        ,       (SUM(1) over (partition by foobar) )      as myColumn  \
        FROM spgxCube.LPCache lpcache   \
                WHERE    lpcache.CIG_OrigYear = 2001    "; 


odbc::Connection* connQuery= SpgxDBConnectionPool::getInstance().getConnection("MyServer");
PreparedStatementPtr pPrepStatement(connQuery->prepareStatement(errorquery.str()));
    pPrepStatement->executeQuery();

But this is the exact same thing except instead of typing "2001" directly in the code, I insert it with a parameter:

    errorquery<<"SELECT   1   as foobar \
        ,       (SUM(1) over (partition by foobar) )      as myColumn  \
        FROM spgxCube.LPCache lpcache   \
                WHERE    lpcache.CIG_OrigYear = ?    "; 

    odbc::Connection* connQuery = SpgxDBConnectionPool::getInstance().getConnection("MyServer");
    PreparedStatementPtr pPrepStatement(connQuery->prepareStatement(errorquery.str()));

    int intVal = 2001;
    pPrepStatement->setInt(1, intVal);

    pPrepStatement->executeQuery();

That yields this error:
[Sybase][ODBC Driver][Adaptive Server Anywhere]Invalid expression near '(SUM(1) over(partition by foobar)) as myColumn'

Any idea why the first one works if the second one fails? Are you not allowed to use "partition by" with inserted sql parameters or something like that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白龙吟 2024-08-02 09:56:17

Sybase (ASA) Adaptive Server Anywhere 错误没有问题,IQ DB 中包含一个 Sybase ASA 实例,用于 SYSTEM 空间。

我不知道 Sybase IQ v12.7 之前的版本是否支持/完全支持分区依据。 我记得在 v12.6 下有问题。 在 v12.7 或更高版本下应该没问题,否则你的命令对我来说看起来不错。

The Sybase (ASA) Adaptive Server Anywhere error is fine, there is a Sybase ASA instance included in the IQ DB, used for the SYSTEM space.

I do not know if partition by is supported / fully supported in versions prior to Sybase IQ v12.7. I recall having problems with it under v12.6. Under v12.7 or better it should be fine and otherwise you command looks good to me.

与之呼应 2024-08-02 09:56:17

我对 Adaptive Server Anywhere 了解甚少,但您正在使用 Adaptive Server Anywhere 驱动程序来查询 Sybase IQ。

这真的是你想要的吗?

I know very little about Adaptive Server Anywhere, but you're using the Adaptive Server Anywhere driver to query Sybase IQ.

Is that really what you want?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文