SELECT INTO with HSQLDB

偶尔善良 提交于 2020-05-13 05:04:17

问题


I am trying to create a new table from the result of a select. This works fine with SQL Server:

SELECT * INTO newTable FROM (SELECT col1, col2, col3 FROM oldTable) x;

Now, I want to achieve the exact same thing with HSQLDB (Version 2.2). I have tried several forms like

SELECT * INTO newTable FROM (SELECT col1, col2, col3 FROM oldTable);
SELECT INTO newTable FROM SELECT col1, col2, col3 FROM oldTable;
CREATE TABLE newTable AS SELECT col1, col2, col3 FROM oldTable;

All these variants result in some form of syntax error. How can I create a table from a select with HSQLDB?


回答1:


The manual has an example for this:

CREATE TABLE t (a, b, c) AS (SELECT * FROM atable) WITH DATA

HSQLDB requires parentheses around the select (unlike all other DBMS) and it also requires the WITH DATA clause




回答2:


Ok I found very easier way to do this.

select * into t_bckp FROM t;

Its interesting.



来源:https://stackoverflow.com/questions/22224564/select-into-with-hsqldb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!