0

I have a HSQLDB table in which the MAC address is stored as a varchar, which is not quite efficient. I'd like to convert it to BIGINT, but I found no conversion function from VARCHAR hex to BIGINT/INTEGER. I tried to use convert like this: convert(client_mac, BIGINT), but it fails with the first non digit encountered. Does anybody have any idea?

Thanks,

1 Answer 1

0

I've found myself a solution:

SELECT  "java.lang.Long.decode"(concat('0x',replace(client_mac,'-',''))),
FROM    user_accounting_sessions_table

This is kind of an workaround, because the first way that comes into my mind to do it was the following:

SELECT  "java.lang.Long.parseLong"(replace(client_mac,'-',''),16)
FROM    user_accounting_sessions_table

But this throws this error:

java.lang.ArrayIndexOutOfBoundsException: 1
    at org.hsqldb.Function.setArgument(Unknown Source)
    at org.hsqldb.Parser.readTerm(Unknown Source)
    at org.hsqldb.Parser.readFactor(Unknown Source)
    at org.hsqldb.Parser.readSum(Unknown Source)
    at org.hsqldb.Parser.readConcat(Unknown Source)
    at org.hsqldb.Parser.readCondition(Unknown Source)
    at org.hsqldb.Parser.readAnd(Unknown Source)
    at org.hsqldb.Parser.readOr(Unknown Source)
    at org.hsqldb.Parser.parseExpression(Unknown Source)
    at org.hsqldb.Parser.parseSelect(Unknown Source)
    at org.hsqldb.Parser.compileSelectStatement(Unknown Source)
    at org.hsqldb.DatabaseCommandInterpreter.executePart(Unknown Source)
    at org.hsqldb.DatabaseCommandInterpreter.execute(Unknown Source)
    at org.hsqldb.Session.sqlExecuteDirectNoPreChecks(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.onseven.dbvis.b.B.B.?(Z:2256)
    at com.onseven.dbvis.b.B.F$A.call(Z:2838)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

It seems that the problem is with the second parameter. However, the first one works fine.

1
  • The stack trace shows an older version of HSQLDB. There is no problem with the second query when used with a current version of HSQLDB.
    – fredt
    Nov 8, 2010 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.