【问题标题】:Informix - Best Practice - SQL Error [42000]: A syntax error has occurredInformix - 最佳实践 - SQL 错误 [42000]:发生语法错误
【发布时间】:2023-01-21 19:17:15
【问题描述】:

我经常尝试使用数据库 informix 执行插入语句。但是,我经常收到以下错误:

SQL Error [42000]: A syntax error has occurred.

插入语句可以是:

INSERT INTO 
     example_table
             (key, value, type, description, is_active, created_at, created_by)
     VALUES
             ('output', 'C:\temp', 'string', 'location for the output', true, current, 'admin');

我在这里没有看到任何错误,但是 informix 向我显示了上述错误:

SQL Error [42000]: A syntax error has occurred.

为了完整起见,以下是上述示例中列的数据类型:

Column Column type
id serial
key char(50)
value char(256)
type char(10)
description char(512)
created_at datetime year to second
created_by char(20)

在 informix 中是否有查找此类语法错误的最佳实践?

【问题讨论】:

  • 我认为您需要 CURRENT TIMESTAMP 而不是 current

标签: sql informix


【解决方案1】:

您提供的数据类型列表不包括 is_active 列,这与语法错误有关。当从 dbaccess 的交互式会话运行时,指示错误的位置:

INSERT INTO
     example_table
             (key, value, type, description, is_active, created_at, created_by)
     VALUES
             ('output', 'C:	emp', 'string', 'location for the output', true, current, 'admin');
#                                                                       ^
#  201: A syntax error has occurred.
#

在更新表 DDL 以包含类型为布尔值的 is_active 列之后,该语句仍然会失败,因为 Informix 无法将“true”识别为布尔值。将其替换为 of 't'::boolean 或仅替换为 't' 即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    相关资源
    最近更新 更多