On Nov 20, 2009, at 2:30 PM, priimak wrote:

> Hi.
>
> What happened to substr function. I upgraded from 3.6.7 to 3.6.20 and
> found following difference.
>
> in 3.6.7
>
> $ sqlite3 a.db
> sqlite> create table X ( v text not null );
> sqlite> insert into X ( v ) values ( "123456789" );
> sqlite> select substr( v, 0, 5 ) from X;
> 12345

Correct syntax to get the first 5 characters of a string is substr(v, 
1,5).  Remember that SQL using 1-based indexing rather than 0-based.   
I didn't invent this - it is just the way SQL is.

So 3.6.7 is wrong.  The bug was fixed.  3.6.11 and following are  
correct.



>
>
> in 3.6.20
>
> sqlite> create table X ( v text not null );
> sqlite> insert into X ( v ) values ( "123456789" );
> sqlite> select substr( v, 0, 5 ) from X;
> 1234
>
> You can see that they behave differently with 3.6.7 doing the right  
> thing.
> I did not find any mentioning of that here
> http://www.sqlite.org/changes.html
> If that is a bug, it *is* a major one!
>
> --
> Dmitri Priimak
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

D. Richard Hipp
d...@hwaci.com



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to