HSQLDB: INSERT INTO ... (SELECT NULL, * FROM) 导致 "duplicate column name"
HSQLDB: INSERT INTO ... (SELECT NULL, * FROM) leads to "duplicate column name"
在 HSQLDB 中,我有两个 TEXT
tables,映射到 CSV 文件。查看项目 CSV Cruncher。
CREATE TEXT TABLE session_telephony_pins ( Op VARCHAR(4092), id ... )
我正在尝试向此 "input" table 添加一列,以便结果对每个 table.
都有一个唯一的 ID
所以这看起来很合乎逻辑:添加定义为序列的列,
CREATE TEXT TABLE output ( crunchCounter BIGINT
GENERATED BY DEFAULT AS SEQUENCE crunchCounter PRIMARY KEY, op VARCHAR(4092), ... )
然后使用null让DBselect的值为:
INSERT INTO output (SELECT NULL AS crunchCounter, * FROM apollo_session_occurrence)
-- I also tried withhout `AS ...`
但是如果失败:
SQLSyntaxErrorException duplicate column name in derived table
表和列类型:
* APOLLO_SESSION_OCCURRENCE
- OP CHARACTER VARYING
- SESSION_OCCURRENCE_ID SMALLINT
- SESSION_ID SMALLINT
- START_TIME TIMESTAMP
- END_TIME TIMESTAMP
- UID UUID
* OUTPUT
- CRUNCHCOUNTER BIGINT
- OP CHARACTER VARYING
- SESSION_OCCURRENCE_ID CHARACTER VARYING
- SESSION_ID CHARACTER VARYING
- START_TIME CHARACTER VARYING
- END_TIME CHARACTER VARYING
- UID CHARACTER VARYING
我认为在 MySQL 这会起作用,但尚未测试。
类型应该不是问题。如果我删除 crunchCounter
列并只执行 INSERT INTO output (SELECT * FROM apollo_session_occurrence)
,它工作正常。
理论上我可以使用 NEXT VALUE FOR crunchCounter
但这不会更改列元数据。当 HSQLDB 检查元数据时会发生这种情况。
这是怎么回事?而且,
我应该如何用唯一列填充 output
table?
编辑:有趣的是,它与其他 tables 和特别命名的结果列一起工作得很好:
INSERT INTO output (SELECT NULL AS crunchCounter, jobName, buildNumber, config, ar, arFile, deployDur, warmupDur, scale,
CAST(warmupDur AS DOUBLE) / CAST(deployDur AS DOUBLE) AS warmupSlower
FROM concat ORDER BY deployDur)
* CONCAT
- JOBNAME CHARACTER VARYING
- BUILDNUMBER SMALLINT
- CONFIG CHARACTER VARYING
- AR CHARACTER VARYING
- ARFILE CHARACTER VARYING
- DEPLOYDUR SMALLINT
- WARMUPDUR SMALLINT
- SCALE SMALLINT
* OUTPUT
- CRUNCHCOUNTER BIGINT
- JOBNAME CHARACTER VARYING
- BUILDNUMBER CHARACTER VARYING
- CONFIG CHARACTER VARYING
- AR CHARACTER VARYING
- ARFILE CHARACTER VARYING
- DEPLOYDUR CHARACTER VARYING
- WARMUPDUR CHARACTER VARYING
- SCALE CHARACTER VARYING
- WARMUPSLOWER CHARACTER VARYING
开始看起来像一个 HSQLDB 错误。
想通了。问题在于 HSQLDB 将 SELECT 1 AS foo, * FROM myTable
中的 *
扩展为 foo, foo, myTable.col1, ...
。
这是 IMO 的一个错误。
编辑:不是错误,但 HSQLDB 可以提供更好的错误消息。
解决方法:使用合格的通配符。
INSERT INTO output (SELECT NULL AS crunchCounter,
apollo_session_occurrence.*
FROM apollo_session_occurrence ...)
在 HSQLDB 中,我有两个 TEXT
tables,映射到 CSV 文件。查看项目 CSV Cruncher。
CREATE TEXT TABLE session_telephony_pins ( Op VARCHAR(4092), id ... )
我正在尝试向此 "input" table 添加一列,以便结果对每个 table.
都有一个唯一的 ID所以这看起来很合乎逻辑:添加定义为序列的列,
CREATE TEXT TABLE output ( crunchCounter BIGINT
GENERATED BY DEFAULT AS SEQUENCE crunchCounter PRIMARY KEY, op VARCHAR(4092), ... )
然后使用null让DBselect的值为:
INSERT INTO output (SELECT NULL AS crunchCounter, * FROM apollo_session_occurrence)
-- I also tried withhout `AS ...`
但是如果失败:
SQLSyntaxErrorException duplicate column name in derived table
表和列类型:
* APOLLO_SESSION_OCCURRENCE
- OP CHARACTER VARYING
- SESSION_OCCURRENCE_ID SMALLINT
- SESSION_ID SMALLINT
- START_TIME TIMESTAMP
- END_TIME TIMESTAMP
- UID UUID
* OUTPUT
- CRUNCHCOUNTER BIGINT
- OP CHARACTER VARYING
- SESSION_OCCURRENCE_ID CHARACTER VARYING
- SESSION_ID CHARACTER VARYING
- START_TIME CHARACTER VARYING
- END_TIME CHARACTER VARYING
- UID CHARACTER VARYING
我认为在 MySQL 这会起作用,但尚未测试。
类型应该不是问题。如果我删除 crunchCounter
列并只执行 INSERT INTO output (SELECT * FROM apollo_session_occurrence)
,它工作正常。
理论上我可以使用 NEXT VALUE FOR crunchCounter
但这不会更改列元数据。当 HSQLDB 检查元数据时会发生这种情况。
这是怎么回事?而且,
我应该如何用唯一列填充 output
table?
编辑:有趣的是,它与其他 tables 和特别命名的结果列一起工作得很好:
INSERT INTO output (SELECT NULL AS crunchCounter, jobName, buildNumber, config, ar, arFile, deployDur, warmupDur, scale,
CAST(warmupDur AS DOUBLE) / CAST(deployDur AS DOUBLE) AS warmupSlower
FROM concat ORDER BY deployDur)
* CONCAT
- JOBNAME CHARACTER VARYING
- BUILDNUMBER SMALLINT
- CONFIG CHARACTER VARYING
- AR CHARACTER VARYING
- ARFILE CHARACTER VARYING
- DEPLOYDUR SMALLINT
- WARMUPDUR SMALLINT
- SCALE SMALLINT
* OUTPUT
- CRUNCHCOUNTER BIGINT
- JOBNAME CHARACTER VARYING
- BUILDNUMBER CHARACTER VARYING
- CONFIG CHARACTER VARYING
- AR CHARACTER VARYING
- ARFILE CHARACTER VARYING
- DEPLOYDUR CHARACTER VARYING
- WARMUPDUR CHARACTER VARYING
- SCALE CHARACTER VARYING
- WARMUPSLOWER CHARACTER VARYING
开始看起来像一个 HSQLDB 错误。
想通了。问题在于 HSQLDB 将 SELECT 1 AS foo, * FROM myTable
中的 *
扩展为 foo, foo, myTable.col1, ...
。
这是 IMO 的一个错误。 编辑:不是错误,但 HSQLDB 可以提供更好的错误消息。
解决方法:使用合格的通配符。
INSERT INTO output (SELECT NULL AS crunchCounter,
apollo_session_occurrence.*
FROM apollo_session_occurrence ...)