1.4.200: create temporary linked table failed, where urlString is set in variable, but the same string, as set in variable, pasted into urlString is OK

29 views
Skip to first unread message

t603

unread,
Mar 2, 2020, 1:33:12 PM3/2/20
to H2 Database
Hello, 

I have a problem. I want to create temporary linked table, where urlString is set in variable before this this create command. Both databases are H2, both are file based. See example below: 

set @pathTo_applicationFolder = regexp_replace(database_path(), '(.*/)database/([a-zA-Z0-9]+)', '$1');
select @pathTo_applicationFolder;
set @pathTo_database = 'jdbc:h2:file:' || @pathTo_applicationFolder || 'database/aaa';
select @pathTo_database;


create temporary linked table
 
"SHARED_GLOBAL_STATISTICS3" (
   
'org.h2.Driver'
   
,'jdbc:h2:file:C:/Users/xxx/Desktop/APPS/bbb/database/aaa'
   
,''
   
,''
   
,'"STATISTICS"."GLOBAL_STATISTICS"'
 
)
;


create temporary linked table
 
"SHARED_GLOBAL_STATISTICS" (
   
'org.h2.Driver'
   
,@pathTo_database
   
,''
   
,''
   
,'"STATISTICS"."GLOBAL_STATISTICS"'
 
)
;

The result of "select @pathTo_database;" is "jdbc:h2:file:C:/Users/xxx/Desktop/APPS/bbb/database/aaa". 

Why the second CREATE statement fails with the error below? I do not want to have hard-coded path to the database, as in the first CREATE statement. The linked database has no username, nor password. 

Error: Syntax error in SQL statement "create temporary linked table
  ""SHARED_GLOBAL_STATISTICS"" (
    'org.h2.Driver'
    ,@pathTo_database
    ,[*]''
    ,''
    ,'""STATISTICS"".""GLOBAL_STATISTICS""'
  )"
; expected "string"; SQL statement:
create temporary linked table
 
"SHARED_GLOBAL_STATISTICS" (
   
'org.h2.Driver'
   
,@pathTo_database
   
,''
   
,''
   
,'"STATISTICS"."GLOBAL_STATISTICS"'
 
) [42001-200]
SQLState:  42001
ErrorCode: 42001


Thank You in advance for Your help. Stepan 


Evgenij Ryazanov

unread,
Mar 2, 2020, 7:38:35 PM3/2/20
to H2 Database
Hello.

DDL (data definition language) commands in H2 don't support any parameters. The SQL Standard also does not specify such support in any way.

You can construct and execute a non-query commands dynamically:
EXECUTE IMMEDIATE accepts complex string expressions.
Reply all
Reply to author
Forward
0 new messages