使用 CASE 的 Interbase SQL SELECT 查询

发布于 2024-08-11 06:43:15 字数 340 浏览 11 评论 0原文

我正在针对 .gdb 文件运行以下查询:

SELECT CASE USERS.USERID WHEN 1 THEN 'God' ELSE 'Somebody else' END FROM USERS;

但是,针对 .ib 文件运行基本相同的查询,我得到“第 1 行错误” 动态 SQL 错误,SQL 错误代码 = -104,令牌未知 - 第 1 行,字符 17"。它似乎无法识别 CASE USERS.USERID 部分。在 IBConsole 中,.ib 文件正在运行 SQL 方言 3,而 .gdb 文件正在运行方言 1。.ib 文件和 .gdb 文件之间有什么区别?

I'm running the following query against a .gdb-file:

SELECT CASE USERS.USERID WHEN 1 THEN 'God' ELSE 'Somebody else' END FROM USERS;

However, running essentially the same query against a .ib-file, I get "Error at line 1
Dynamic SQL Error, SQL error code = -104, Token unknown - line 1, char 17". It seems it doesn't recognize the part CASE USERS.USERID. In IBConsole, the .ib-file is running SQL dialect 3, while the .gdb-file is running dialect 1. Does this matter? What's the difference between a .ib-file and a .gdb-file?

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

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

发布评论

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

评论(1

窗影残 2024-08-18 06:43:15

.gdb.ib 只是文件扩展名。它们不会影响任何事情。

我猜这里的问题是区分大小写。根据 SQL 标准的“分隔标识符”功能,如果您在创建表时使用双引号,即:

CREATE TABLE "Users" (
    "UserId" INTEGER NOT NULL PRIMARY KEY, 
    /* ... */

...则标识符区分大小写。完成此操作后,无论何时对表执行任何操作,都必须始终使用 (1) 分隔符(双引号)和 (2) 正确的大小写。

是的,很烦人,但是 SQL 标准需要它。 SQL Dialect 3 在执行 SQL 标准方面更加严格,包括分隔标识符。

为了解决这个问题,创建表时不要使用双引号,除非您确实需要此“功能”。

.gdb and .ib are juast file extensions. They don't affect anything.

I'm guessing the problem here is case sensitivity. Per the "delimited identifier" feature of the SQL standard, if you use double quotes when you create the table, i.e.:

CREATE TABLE "Users" (
    "UserId" INTEGER NOT NULL PRIMARY KEY, 
    /* ... */

...then the identifier is case-sensitive. Having done this, you must therefore always use (1) delimiters (double quotes) and (2) the correct case whenever you do anything with the table.

Annoying, yes, but the SQL Standard requires it. SQL Dialect 3 is much more strict about enforcing the SQL Standard, including delimited identifiers.

To get around this, don't use double quotes when you create the table unless you actually want this "feature."

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