Manifest Typing question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Manifest Typing question

Tito Ciuro
Hello,

When I add text to the database, it's getting truncated because  
SQLite is converting it to a number. For example, I enter "9.0", but  
SQLite stores it as "9".

Is there a way to force the value to be inserted as string?

Thanks,

-- Tito
Reply | Threaded
Open this post in threaded view
|

Re: Manifest Typing question

D. Richard Hipp
On Tue, 2005-06-21 at 00:13 -0400, Tito Ciuro wrote:
> Hello,
>
> When I add text to the database, it's getting truncated because  
> SQLite is converting it to a number. For example, I enter "9.0", but  
> SQLite stores it as "9".
>
> Is there a way to force the value to be inserted as string?
>

Make the declared datatype of the column TEXT.

Example:

    CREATE TABLE t1(a, b INTEGER, c REAL, d TEXT);
    INSERT INTO t1 VALUES(9.0,9.0,9.0,9.0);
    SELECCT * FROM t1;

Results in:

    9|9|9|9.0

--
D. Richard Hipp <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Manifest Typing question

Tito Ciuro
Excellent!

Thank you!

-- Tito

On 21/06/2005, at 5:10, D. Richard Hipp wrote:

> On Tue, 2005-06-21 at 00:13 -0400, Tito Ciuro wrote:
>
>> Hello,
>>
>> When I add text to the database, it's getting truncated because
>> SQLite is converting it to a number. For example, I enter "9.0", but
>> SQLite stores it as "9".
>>
>> Is there a way to force the value to be inserted as string?
>>
>>
>
> Make the declared datatype of the column TEXT.
>
> Example:
>
>     CREATE TABLE t1(a, b INTEGER, c REAL, d TEXT);
>     INSERT INTO t1 VALUES(9.0,9.0,9.0,9.0);
>     SELECCT * FROM t1;
>
> Results in:
>
>     9|9|9|9.0
>
> --
> D. Richard Hipp <[hidden email]>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Manifest Typing question

Ken & Deb Allen
In reply to this post by D. Richard Hipp
Will declaring the column as VARCHAR not achieve the same thing? Does  
SQLITE not translate VARCHAR to TEXT, rather than numeric?

-ken

On 21-Jun-05, at 5:10 AM, D. Richard Hipp wrote:

> On Tue, 2005-06-21 at 00:13 -0400, Tito Ciuro wrote:
>
>> Hello,
>>
>> When I add text to the database, it's getting truncated because
>> SQLite is converting it to a number. For example, I enter "9.0", but
>> SQLite stores it as "9".
>>
>> Is there a way to force the value to be inserted as string?
>>
>>
>
> Make the declared datatype of the column TEXT.
>
> Example:
>
>     CREATE TABLE t1(a, b INTEGER, c REAL, d TEXT);
>     INSERT INTO t1 VALUES(9.0,9.0,9.0,9.0);
>     SELECCT * FROM t1;
>
> Results in:
>
>     9|9|9|9.0
>
> --
> D. Richard Hipp <[hidden email]>
>

Reply | Threaded
Open this post in threaded view
|

Re: Manifest Typing question

D. Richard Hipp
On Tue, 2005-06-21 at 06:18 -0400, Ken & Deb Allen wrote:
> Will declaring the column as VARCHAR not achieve the same thing? Does  
> SQLITE not translate VARCHAR to TEXT, rather than numeric?
>

VARCHAR, TEXT, and CLOB are all the same thing.
See http://www.sqlite.org/datatype3.html section 2.1
for details.
--
D. Richard Hipp <[hidden email]>