在HSQLDB中,我有两个TEXT
表,它们映射到CSV文件。参见项目CSV Cruncher。
CREATE TEXT TABLE session_telephony_pins ( Op VARCHAR(4092), id ... )
我正在尝试在此“输入”表中添加一列,以使结果在每个表中都具有唯一的ID。
这似乎很合乎逻辑:添加定义为序列的列
CREATE TEXT TABLE output ( crunchCounter BIGINT
GENERATED BY DEFAULT AS SEQUENCE crunchCounter PRIMARY KEY, op VARCHAR(4092), ... )
,然后使用null来让数据库选择值:
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
表?
编辑:有趣的是,它可以与其他表以及特别命名的结果列配合使用:
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错误。
答案 0 :(得分:0)
想通了。问题在于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 ...)