You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2014/05/23 15:25:01 UTC

[jira] [Commented] (DERBY-6584) Comparisons between BOOLEAN and other types sometimes succeed

    [ https://issues.apache.org/jira/browse/DERBY-6584?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14007154#comment-14007154 ] 

Knut Anders Hatlen commented on DERBY-6584:
-------------------------------------------

We do allow explicit casts from string to boolean. See DERBY-4658.

Still, 'abc' cannot be cast to boolean, so 'abc' = true should fail in any case, I think.

{noformat}
ij> values cast('true' as boolean);
1    
-----
true 

1 row selected
ij> values cast('abc' as boolean);
ERROR 22018: Invalid character string format for type boolean.
ij> values 'abc' = true;
1    
-----
true 

1 row selected
{noformat}

> Comparisons between BOOLEAN and other types sometimes succeed
> -------------------------------------------------------------
>
>                 Key: DERBY-6584
>                 URL: https://issues.apache.org/jira/browse/DERBY-6584
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.10.2.0
>            Reporter: Knut Anders Hatlen
>
> I would have expected the following queries to fail because of type mismatch between CHAR and BOOLEAN:
> {noformat}
> ij> values 'abc' = true, true = 'xyz', false = 'yes';
> 1    
> -----
> true 
> true 
> false
> 3 rows selected
> ij> values 'abc' in (true, false), true in ('abc', 'def');
> 1    
> -----
> true 
> true 
> 2 rows selected
> {noformat}
> Similar queries using INTEGER values instead of CHAR values fail as expected:
> {noformat}
> ij> values 1 = true;
> ERROR 42818: Comparisons between 'INTEGER' and 'BOOLEAN' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
> ij> values true = 1;
> ERROR 42818: Comparisons between 'BOOLEAN' and 'INTEGER' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
> ij> values true in (1,2,3);
> ERROR 42818: Comparisons between 'BOOLEAN' and 'INTEGER' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
> ij> values 1 in (true, false);
> ERROR 42818: Comparisons between 'INTEGER' and 'BOOLEAN' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)