Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-09 Thread Peter Haworth
message. On Sat, Mar 9, 2013 at 9:00 AM, sqlite-users-requ...@sqlite.org wrote: Message: 17 Date: Fri, 8 Mar 2013 14:26:06 -0500 From: James K. Lowden jklow...@schemamania.org To: sqlite-users@sqlite.org Subject: Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-09 Thread James K. Lowden
Date: Fri, 8 Mar 2013 14:26:06 -0500 From: James K. Lowden jklow...@schemamania.org To: sqlite-users@sqlite.org Subject: Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency] Message-ID: 20130308142606.15776668.jklow...@schemamania.org Content-Type: text/plain; charset

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-09 Thread Simon Slavin
On 9 Mar 2013, at 8:01pm, James K. Lowden jklow...@schemamania.org wrote: Looking at the sources, the name of the constraint would have to be dragged from the parser through the virtual machine, where it would be associated with the generated code that enforces the constraint. You'll be glad

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-08 Thread James K. Lowden
On Thu, 7 Mar 2013 19:20:44 +0100 Petite Abeille petite.abei...@gmail.com wrote: In conclusion, if you want to allow affine type conversions on INSERT, but not disallow values that cannot be so converted, then CHECK(my_column = CAST(my_column AS TYPE)) works. And if you want to disallow

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-08 Thread James K. Lowden
On Thu, 7 Mar 2013 07:36:25 -0600 Michael Black mdblac...@yahoo.com wrote: Personally I think this behavior is horrid. ... Why is this behavior allowed now? As Zero Mostel sang: Tradition! See your handy atoi() man page. :-) I don't know if that's really why, but it's not as if there's

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-08 Thread James K. Lowden
On Thu, 7 Mar 2013 18:45:23 + Simon Slavin slav...@bigfraud.org wrote: what do you think the desired behaviour would be for CAST('0.9' AS INTEGER) I know what I want. Perhaps this can be fixed in SQLite4. Sorry, but CAST is not a math function. There's probably a language

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-08 Thread Marc L. Allen
, March 08, 2013 2:45 PM To: sqlite-users@sqlite.org Subject: Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency] On Thu, 7 Mar 2013 18:45:23 + Simon Slavin slav...@bigfraud.org wrote: what do you think the desired behaviour would be for CAST('0.9' AS INTEGER

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-08 Thread Nico Williams
On Fri, Mar 8, 2013 at 1:26 PM, James K. Lowden jklow...@schemamania.org wrote: On Thu, 7 Mar 2013 19:20:44 +0100 Petite Abeille petite.abei...@gmail.com wrote: Yeah? 'cool' is not necessarily how I would describe it? having a check constraint 'magically' coerce - change! - the inserted data

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-08 Thread Keith Medcalf
  Original message From: Nico Williams n...@cryptonector.com Date: To: General Discussion of SQLite Database sqlite-users@sqlite.org Subject: Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency] ___ sqlite-users

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Michael Black
[WAS: inner vs. outer join inconsistency] On Mar 6, 2013, at 10:49 PM, Nico Williams n...@cryptonector.com wrote: Ah, your confusion comes from the fact that type conversion still happens when the INSERT gets around to making the record. The CHECK constraint happens before the record is made

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Simon Slavin
On 7 Mar 2013, at 1:36pm, Michael Black mdblac...@yahoo.com wrote: New: select cast('2' as integer); 2 select cast('2a' as integer); 0 Sorry, but that's very bad. There is no way that the string '2a' could represent 0. I agree that interpreting '2a' as the integer 2 may be considered

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Nico Williams
On Thu, Mar 7, 2013 at 7:36 AM, Michael Black mdblac...@yahoo.com wrote: Personally I think this behavior is horrid. Is there some scenario where this wouldn't be a latent bug? I don't like it either. I also share Simon's (and yours!) opinion regarding your patch: if cast be fixed at all (and

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 9:28 AM, Simon Slavin wrote: On 7 Mar 2013, at 1:36pm, Michael Black mdblac...@yahoo.com wrote: New: select cast('2' as integer); 2 select cast('2a' as integer); 0 Sorry, but that's very bad. There is no way that the string '2a' could represent 0. I agree that interpreting

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Doug Currie
On Mar 7, 2013, at 11:07 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: That does leave the question of what to do with cast ('1.0' as integer), though. Without the prefix-based matching that would now return NULL rather than 1, even though cast(1.0 as integer) would still return 1.

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 06/03/2013 10:30 AM, Dominique Devienne wrote: On Wed, Mar 6, 2013 at 3:29 PM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: Off topic, I'd love a way to request strong typing for a column (so that attempts to store 'abc' into an int column would fail). You can emulate it with a pair of

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 11:14 AM, Doug Currie wrote: On Mar 7, 2013, at 11:07 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: That does leave the question of what to do with cast ('1.0' as integer), though. Without the prefix-based matching that would now return NULL rather than 1, even though

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Nico Williams
On Thu, Mar 7, 2013 at 11:12 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: I would argue that, if a column has type affinity, CHECK should work with the value that would actually get stored, not the one that was assigned. But then you couldn't check the value that was attempted to store.

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 12:27 PM, Nico Williams wrote: On Thu, Mar 7, 2013 at 11:12 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: I would argue that, if a column has type affinity, CHECK should work with the value that would actually get stored, not the one that was assigned. But then you couldn't

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 12:18 PM, Ryan Johnson wrote: On 07/03/2013 11:14 AM, Doug Currie wrote: On Mar 7, 2013, at 11:07 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: That does leave the question of what to do with cast ('1.0' as integer), though. Without the prefix-based matching that would now

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Nico Williams
On Thu, Mar 7, 2013 at 11:44 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: On 07/03/2013 12:27 PM, Nico Williams wrote: On Thu, Mar 7, 2013 at 11:12 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: I would argue that, if a column has type affinity, CHECK should work with the value

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Simon Slavin
On 7 Mar 2013, at 4:07pm, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: That does leave the question of what to do with cast ('1.0' as integer), though. Without the prefix-based matching that would now return NULL rather than 1, even though cast(1.0 as integer) would still return 1. Then

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 1:07 PM, Nico Williams wrote: On Thu, Mar 7, 2013 at 11:44 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: On 07/03/2013 12:27 PM, Nico Williams wrote: On Thu, Mar 7, 2013 at 11:12 AM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: I would argue that, if a column has type

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 1:15 PM, Simon Slavin wrote: On 7 Mar 2013, at 4:07pm, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: That does leave the question of what to do with cast ('1.0' as integer), though. Without the prefix-based matching that would now return NULL rather than 1, even though

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Simon Slavin
On 7 Mar 2013, at 6:27pm, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: The problem is sqlite3 doesn't cast to REAL first. It just parses the string until it hits '.' (which isn't a valid part of an integer) and then returns whatever it had accumulated so far. That breaks in creative ways

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Nico Williams
On Thu, Mar 7, 2013 at 12:20 PM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: On 07/03/2013 1:07 PM, Nico Williams wrote: You might defer checks, but not type conversions. In any case, I see no value in deferring check constraints. Anything constraining cardinality. The old example of

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Petite Abeille
On Mar 7, 2013, at 6:21 AM, Nico Williams n...@cryptonector.com wrote: In conclusion, if you want to allow affine type conversions on INSERT, but not disallow values that cannot be so converted, then CHECK(my_column = CAST(my_column AS TYPE)) works. And if you want to disallow values of

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 1:45 PM, Simon Slavin wrote: On 7 Mar 2013, at 6:27pm, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: The problem is sqlite3 doesn't cast to REAL first. It just parses the string until it hits '.' (which isn't a valid part of an integer) and then returns whatever it had

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 1:48 PM, Nico Williams wrote: On Thu, Mar 7, 2013 at 12:20 PM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: On 07/03/2013 1:07 PM, Nico Williams wrote: You might defer checks, but not type conversions. In any case, I see no value in deferring check constraints. Anything

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Petite Abeille
On Mar 7, 2013, at 7:53 PM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: Meanwhile, though, I'd be delighted if column affinity, cast(), implicit conversions performed by arithmetic operations, check(), and triggers all behaved the same way, with the current behavior of column affinity

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Nico Williams
On Thu, Mar 7, 2013 at 12:53 PM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: Meanwhile, though, I'd be delighted if column affinity, cast(), implicit conversions performed by arithmetic operations, check(), and triggers all behaved the same way, with the current behavior of column affinity

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-07 Thread Ryan Johnson
On 07/03/2013 3:14 PM, Nico Williams wrote: On Thu, Mar 7, 2013 at 12:53 PM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: Meanwhile, though, I'd be delighted if column affinity, cast(), implicit conversions performed by arithmetic operations, check(), and triggers all behaved the same way,

[sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Dominique Devienne
On Wed, Mar 6, 2013 at 3:29 PM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: Off topic, I'd love a way to request strong typing for a column (so that attempts to store 'abc' into an int column would fail). You can emulate it with a pair of before/update triggers (select raise(...) where

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Ryan Johnson
On 06/03/2013 10:30 AM, Dominique Devienne wrote: On Wed, Mar 6, 2013 at 3:29 PM, Ryan Johnson ryan.john...@cs.utoronto.ca wrote: Off topic, I'd love a way to request strong typing for a column (so that attempts to store 'abc' into an int column would fail). You can emulate it with a pair of

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Nico Williams
On Wed, Mar 6, 2013 at 9:30 AM, Dominique Devienne ddevie...@gmail.com wrote: You don't have to use triggers, you can use a check constraint instead (simpler, but also perhaps faster as well?). If you do, you loose some of the implicit type conversions SQLite does, based on type affinity, so

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Petite Abeille
On Mar 6, 2013, at 10:24 PM, Nico Williams n...@cryptonector.com wrote: CREATE TABLE toy(a INTEGER CHECK(a = CAST(a AS INTEGER))); Any idea on the cost of such check? In term of overhead? Just curious. ___ sqlite-users mailing list

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Nico Williams
On Wed, Mar 6, 2013 at 3:29 PM, Petite Abeille petite.abei...@gmail.com wrote: On Mar 6, 2013, at 10:24 PM, Nico Williams n...@cryptonector.com wrote: CREATE TABLE toy(a INTEGER CHECK(a = CAST(a AS INTEGER))); Any idea on the cost of such check? In term of overhead? Just curious. Well, it's

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Petite Abeille
On Mar 6, 2013, at 10:24 PM, Nico Williams n...@cryptonector.com wrote: Nah, use this sort of CHECK constraint: CREATE TABLE toy(a INTEGER CHECK(a = CAST(a AS INTEGER))); Hmmm… on second thought… is that an assignment in that check constraint?!? I.e. are you reassigning a to a new cast

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Nico Williams
On Wed, Mar 6, 2013 at 3:43 PM, Petite Abeille petite.abei...@gmail.com wrote: On Mar 6, 2013, at 10:24 PM, Nico Williams n...@cryptonector.com wrote: CREATE TABLE toy(a INTEGER CHECK(a = CAST(a AS INTEGER))); Hmmm… on second thought… is that an assignment in that check constraint?!? I.e.

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Petite Abeille
On Mar 6, 2013, at 10:43 PM, Petite Abeille petite.abei...@gmail.com wrote: CREATE TABLE toy(a INTEGER CHECK(a = CAST(a AS INTEGER))); Hmmm… on second thought… is that an assignment in that check constraint?!? I.e. are you reassigning a to a new cast value?!? Are not check constraint

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Nico Williams
On Wed, Mar 6, 2013 at 3:47 PM, Petite Abeille petite.abei...@gmail.com wrote: Indeed. Never mind :) Ah, your confusion comes from the fact that type conversion still happens when the INSERT gets around to making the record. The CHECK constraint happens before the record is made. See the vdbe

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Petite Abeille
On Mar 6, 2013, at 10:47 PM, Nico Williams n...@cryptonector.com wrote: Hmmm… on second thought… is that an assignment in that check constraint?!? I.e. are you reassigning a to a new cast value?!? No. The only place where = is an assignment is in UPDATE statements, in the SET clause.

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Nico Williams
On Wed, Mar 6, 2013 at 3:49 PM, Nico Williams n...@cryptonector.com wrote: On Wed, Mar 6, 2013 at 3:47 PM, Petite Abeille petite.abei...@gmail.com wrote: Indeed. Never mind :) Ah, your confusion comes from the fact that type conversion still happens when the INSERT gets around to making the

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Petite Abeille
On Mar 6, 2013, at 10:49 PM, Nico Williams n...@cryptonector.com wrote: Ah, your confusion comes from the fact that type conversion still happens when the INSERT gets around to making the record. The CHECK constraint happens before the record is made. See the vdbe that gets generated. All

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Nico Williams
On Wed, Mar 6, 2013 at 4:20 PM, Petite Abeille petite.abei...@gmail.com wrote: All good. Small sanity check though: select 2 = cast( '2' as integer ); 1 Ok… '2' is can be casted to 2… great... select 2 = cast( 'a2' as integer ); 0 Ok… 'a2' cannot really be casted to an integer…

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Petite Abeille
On Mar 6, 2013, at 11:53 PM, Nico Williams n...@cryptonector.com wrote: o k i d o k i . . . Oh. Oh.. Ew.. Never mind then! Yeah… a bit of a mind melt… nevertheless… such check should work as advertised… even handles nulls properly… perhaps too clever too... :D All magic comes with a

Re: [sqlite] SQLite strong-typing [WAS: inner vs. outer join inconsistency]

2013-03-06 Thread Nico Williams
On Wed, Mar 6, 2013 at 4:20 PM, Petite Abeille petite.abei...@gmail.com wrote: All good. Small sanity check though: select 2 = cast( '2.1' as integer ); 1 Hmmm…. select 2 = cast( '2abc' as integer ); 1 What?!? Oh… When casting a TEXT value to INTEGER, the longest possible prefix