Hi,
If you are interested in the string representation, why don't you just
use varchar? It's good that you care about your use case, but there
are other uses cases to be considered.
> The real problem is that Strings are trying
> to be transformed to the Java object rather than transforming the Java
> object to String.
The rules about which type is 'higher' or 'lower' than other types is
something very basic, and I wouldn't want to change it just because it
might be a bit easier for a few cases (well, just for this case). When
types don't match, the value of the lower type is converted to the
value of the higher type. The order of types is implemented in
Value.getOrder(int type). It is roughly: null, varchar, int, double,
timestamp, object, array. If varchar would be at the very end of the
list, then the following example would not find the row in the table:
drop table test;
create table test(ts timestamp primary key);
insert into test values('2001-01-01 10:00:00');
select * from test where ts = '2001-01-01 10:00:00';
because the string representation of the timestamp is actually
'2001-01-01 10:00:00.0' (ends with '.0').
Another reason why the database tries to convert 'SomeText' to a java
object is so the database can use an index if there is an index for
the given column. So basically the database, to allow using an index,
needs to use:
where columnName = cast('SomeText' as <columnType>)
Otherwise you would end up in a table scan each time. In the same way,
for the following example, an index is used:
create table test(id int primary key);
insert into test values(1), (10), (100);
select * from test where id = '1';
It would be very strange if the database would use different
conversion rules depending on whether there is an index or not.
> This comparison would then obviously use the
> toString method of the Non-Serialized Java Object for the comparison
> with the String.
That would mean you can't use an index on that column for such
queries. For you that might be acceptable, but I think it's not.
Regards,
Thomas
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.