Apparently when inserting an empty string (''
) in a VARCHAR column Sybase (tested in ASE 15.7) inserts a single space character instead. Experimenting I verified that the option ansinull
has no bearing on this behavior either way:
> set ansinull on
> create table a (a1 varchar(1))
> insert into a(a1) values ('')
> select a1, len(a1) as 'len(a1)', datalength(a1) as 'datalength(a1)',
ascii(a1) as 'ascii(a1)', char_length(a1) as 'char_length(a1)'
from a
> go
(1 row affected)
a1 len(a1) datalength(a1) ascii(a1) char_length(a1)
-- ----------- -------------- ----------- ---------------
1 1 32 1
(1 row affected)
>
>
> drop table a
> go
> set ansinull off
> create table a (a1 varchar(1))
> insert into a(a1) values ('')
> select a1, len(a1) as 'len(a1)', datalength(a1) as 'datalength(a1)',
ascii(a1) as 'ascii(a1)', char_length(a1) as 'char_length(a1)'
from a
> go
(1 row affected)
a1 len(a1) datalength(a1) ascii(a1) char_length(a1)
-- ----------- -------------- ----------- ---------------
1 1 32 1
(1 row affected)
Is there any justification / reasoning for this behavior and how can I disable this "feature"? Is this behavior inherited in the SQL Server codebase?
I was bitten by this as my test logic failed since I was doing a .equals()
comparison (in the client-side Java code that's using JDBC to read from the database and make certain assertions).