Derby запускает скрипт sql, перенаправляя standardIO - PullRequest
0 голосов
/ 23 июня 2018

У меня есть следующий скрипт join.sql:

connect 'jdbc:derby:barra';
show tables;
create table sp500_univ as
select a.*,b.* from (select * from LEFT_SIDE) as a
left join (select * from RIGHT_SIDE) as b
on a.cmp_flg = b.cmp_flg2;
disconnect;
exit;

, который я запускаю с помощью следующей команды:

 java org.apache.derby.tools.ij < join.sql

и получаю следующий вывод:

java org.apache.derby.tools.ij < join.sql
ij version 10.14
ij> ij> TABLE_SCHEM         |TABLE_NAME                    |REMARKS
------------------------------------------------------------------------    
APP                 |LEFT_SIDE                     |
APP                 |RIGHT_SIDE                    |

2 rows selected
ij> > > > ERROR 42X01: Syntax error: Encountered "<EOF>" at line 4, column 25.
Issue the 'help' command for general information on IJ command syntax.
Any unrecognized commands are treated as potential SQL commands and executed directly.
Consult your DBMS server reference documentation for details of the SQL syntax supported by your server.
ij> ij>

Если я запускаю этот sql прямо из командной строки в IJ, это работает.

1 Ответ

0 голосов
/ 24 июня 2018

очевидно, что при запуске из файла вы не можете создавать таблицы и загружать данные из оператора select. Вы должны добавить без данных. Опция WITH DATA еще не была реализована. Из документации Дерби:

CREATE TABLE ... AS ...
With the alternate form of the CREATE TABLE statement, the column names and/or the 
column data types can be specified by providing a query. The columns in the query 
result are used as a model for creating the columns in the new table.

If no column names are specified for the new table, then all the columns in the 
result of the query expression are used to create same-named columns in the new 
table, of the corresponding data type(s). If one or more column names are specified 
for the new table, then the same number of columns must be present in the result of 
the query expression; the data types of those columns are used for the corresponding 
columns of the new table.

The WITH NO DATA clause specifies that the data rows which result from evaluating the 
query expression are not used; only the names and data types of the columns in the 
query result are used. The WITH NO DATA clause must be specified; in a future 
release, Derby may be modified to allow the WITH DATA clause to be provided, which 
would indicate that the results of the query expression should be inserted into the 
newly-created table. In the current release, however, only the WITH NO DATA form of t 
the statement is accepted.
...