Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT INTO with HSQLDB

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?

like image 575
Jack Avatar asked Mar 06 '14 12:03

Jack


People also ask

How to use SELECT query in HSQLDB?

HSQLDB - Select Query. The SELECT command is used to fetch the record data from HSQLDB database. Here, you need to mention the required fields list in the Select statement. Syntax. Here is the generic syntax for Select query.

How to fetch the record data from HSQLDB database?

The SELECT command is used to fetch the record data from HSQLDB database. Here, you need to mention the required fields list in the Select statement. Here is the generic syntax for Select query. SELECT field1, field2,...fieldN table_name1, table_name2...

Where can sequence generated values be used in HSQLDB?

HSQLDB does not currently enforce the SQL 200n proposed rules on where sequence generated values are allowed to be used. In general, these values can be used in insert and update statements but not in CASE statements, order by clauses, search conditions, aggregate functions, or grouped queries. Strings in HSQLDB are Unicode strings.

What is permission for HSQLDB?

Permission is granted to distribute this document without any alteration under the terms of the HSQLDB license. $Date: 2007/08/28 12:13:28 $ Table of Contents Introduction Available formats for this document 1. Running and Using Hsqldb Introduction Running Tools Running Hsqldb Server Modes Hsqldb Server Hsqldb Web Server Hsqldb Servlet


1 Answers

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

like image 172
a_horse_with_no_name Avatar answered Oct 04 '22 18:10

a_horse_with_no_name