0

Does anyone know how to retrieve UUID via HSQLDB.

For example when i try

SELECT UUID();

via MYSQL it works fine. But the same statement doesn't work with HSQLDB. The following methods achieve the corresponding purpose

VALUES (UUID())

CALL(UUID())

SELECT UUID() FROM (VALUES(0)) t;

Is there a way which is same for mysql and hsqldb? HSQL doc says that UUID has been activated. http://hsqldb.org/doc/guide/builtinfunctions-chapt.html

Thanks.

user2083529
  • 715
  • 3
  • 13
  • 25
  • is there any hack where statement like SELECT UUID() FROM (VALUES(0)) would also be possible to work with mysql? – user2083529 Mar 26 '18 at 15:04
  • 1
    HSQLDB requires the `FROM [table]` part... i found this question https://stackoverflow.com/questions/909702/how-to-do-select-current-timestamp-in-hsqldb but is't with current_timestamp() but i think the same method can be used for UUID() – Raymond Nijland Mar 26 '18 at 15:04
  • 1
    `SELECT UUID() FROM (SELECT 0) t` might work in both MySQL (know for sure it works in MySQL) and HSQLDB – Raymond Nijland Mar 26 '18 at 15:07
  • tried it now, it does't work when i specify table name. SELECT UUID() FROM (SELECT 0) t works only with mysql – user2083529 Mar 26 '18 at 15:08
  • "Is there a way which is same for mysql and hsqldb? " see mine answer. – Raymond Nijland Mar 26 '18 at 15:46

2 Answers2

2

Turn on the MySQL compatibility mode in HSQLDB and it will allow your SELECT statement:

http://hsqldb.org/doc/2.0/guide/compatibility-chapt.html#coc_compatibility_mysql

fredt
  • 24,044
  • 3
  • 40
  • 61
1

Is there a way which is same for mysql and hsqldb?

Only way i can think off.
Create a table DUAL in HSQLDB

CREATE TABLE DUAL (
  id INT
);

So you can use

SELECT UUID() FROM DUAL LIMIT 1;

Then the query should work the same in both MySQL and HSQLDB.
DUAL in MySQL is a non existing dummy table.

Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34