|
| 1 | +category = "translation" |
| 2 | +construct = "sf.expressions.data-types-logical" |
| 3 | +session_profile = "utc-v1" |
| 4 | + |
| 5 | +[[case]] |
| 6 | +id = "t001_from_text" |
| 7 | +description = "The page's twelve strings, in mixed case: the first six convert to TRUE and the last six to FALSE. Catches: only 'true' and 'false' accepted, or the match made case-sensitive" |
| 8 | +columns = [{ name = "a", type = "VARCHAR" }] |
| 9 | +rows = [ |
| 10 | + ["'true'"], |
| 11 | + ["'T'"], |
| 12 | + ["'Yes'"], |
| 13 | + ["'y'"], |
| 14 | + ["'ON'"], |
| 15 | + ["'1'"], |
| 16 | + ["'FALSE'"], |
| 17 | + ["'f'"], |
| 18 | + ["'no'"], |
| 19 | + ["'N'"], |
| 20 | + ["'Off'"], |
| 21 | + ["'0'"], |
| 22 | +] |
| 23 | +query = "SELECT ordinal, CAST(a AS BOOLEAN) AS r FROM input ORDER BY ordinal" |
| 24 | +order = "ordered" |
| 25 | +tags = ["type-combination"] |
| 26 | + |
| 27 | +[[case]] |
| 28 | +id = "t002_from_number" |
| 29 | +description = "The page: zero converts to FALSE and any non-zero value, negative or fractional, to TRUE. Catches: only 1 read as TRUE, or a fraction truncated to 0 first" |
| 30 | +columns = [{ name = "n", type = "NUMBER(10,2)" }] |
| 31 | +rows = [ |
| 32 | + ["0"], |
| 33 | + ["-2.5"], |
| 34 | + ["-0.25"], |
| 35 | + ["1"], |
| 36 | +] |
| 37 | +query = "SELECT ordinal, CAST(n AS BOOLEAN) AS b FROM input ORDER BY ordinal" |
| 38 | +order = "ordered" |
| 39 | +tags = ["type-combination"] |
| 40 | + |
| 41 | +[[case]] |
| 42 | +id = "t003_to_text_and_number" |
| 43 | +description = "The page: TRUE casts to 'true' and 1, FALSE to 'false' and 0. Catches: upper-case 'TRUE', or 't', or -1 for TRUE" |
| 44 | +columns = [{ name = "a", type = "VARCHAR" }] |
| 45 | +rows = [ |
| 46 | + ["'yes'"], |
| 47 | + ["'no'"], |
| 48 | +] |
| 49 | +query = "SELECT ordinal, CAST(CAST(a AS BOOLEAN) AS VARCHAR) AS s, CAST(CAST(a AS BOOLEAN) AS NUMBER) AS n FROM input ORDER BY ordinal" |
| 50 | +order = "ordered" |
| 51 | +tags = ["type-combination"] |
| 52 | + |
| 53 | +[[case]] |
| 54 | +id = "t004_other_text" |
| 55 | +description = "The page: other text strings can't be converted to BOOLEAN, so the cast raises. Catches: the string read as FALSE or NULL" |
| 56 | +columns = [{ name = "a", type = "VARCHAR" }] |
| 57 | +rows = [ |
| 58 | + ["'maybe'"], |
| 59 | +] |
| 60 | +query = "SELECT ordinal, CAST(a AS BOOLEAN) AS r FROM input ORDER BY ordinal" |
| 61 | +order = "ordered" |
| 62 | +tags = ["error"] |
| 63 | + |
| 64 | +[[case]] |
| 65 | +id = "t005_implicit_from_text" |
| 66 | +description = "The page: implicitly, only 'true' and 'false' convert, case-insensitively, so a VARCHAR column in AND converts without a cast. Catches: the implicit conversion refused, or done case-sensitively" |
| 67 | +columns = [{ name = "a", type = "VARCHAR" }] |
| 68 | +rows = [ |
| 69 | + ["'true'"], |
| 70 | + ["'FALSE'"], |
| 71 | + ["'True'"], |
| 72 | +] |
| 73 | +query = "SELECT ordinal, a AND TRUE AS r, NOT a AS n FROM input ORDER BY ordinal" |
| 74 | +order = "ordered" |
| 75 | +tags = ["type-combination"] |
| 76 | + |
| 77 | +[[case]] |
| 78 | +id = "t006_implicit_from_number" |
| 79 | +description = "The page: implicitly, zero converts to FALSE and any other number to TRUE. Catches: the implicit conversion refused, or only 1 read as TRUE" |
| 80 | +columns = [{ name = "n", type = "NUMBER(38,0)" }] |
| 81 | +rows = [ |
| 82 | + ["0"], |
| 83 | + ["1"], |
| 84 | + ["-3"], |
| 85 | +] |
| 86 | +query = "SELECT ordinal, n AND TRUE AS r, NOT n AS x FROM input ORDER BY ordinal" |
| 87 | +order = "ordered" |
| 88 | +tags = ["type-combination"] |
| 89 | + |
| 90 | +[[case]] |
| 91 | +id = "t007_implicit_to_text" |
| 92 | +description = "The page: a BOOLEAN column or literal concatenated with || converts to 'true' or 'false'. Catches: upper-case TRUE, 't' or 1 in the text" |
| 93 | +columns = [{ name = "b", type = "BOOLEAN" }] |
| 94 | +rows = [ |
| 95 | + ["TRUE"], |
| 96 | + ["FALSE"], |
| 97 | +] |
| 98 | +query = "SELECT ordinal, 'is ' || b AS col, 'lit ' || TRUE AS lit FROM input ORDER BY ordinal" |
| 99 | +order = "ordered" |
| 100 | +tags = ["type-combination"] |
| 101 | + |
| 102 | +[[case]] |
| 103 | +id = "t009_null" |
| 104 | +description = "NULL is the unknown BOOLEAN value, kept through the cast. Catches: NULL replaced by a value, or the cast raising for NULL" |
| 105 | +columns = [{ name = "a", type = "VARCHAR" }] |
| 106 | +rows = [ |
| 107 | + ["NULL"], |
| 108 | + ["'on'"], |
| 109 | +] |
| 110 | +query = "SELECT ordinal, CAST(a AS BOOLEAN) AS r FROM input ORDER BY ordinal" |
| 111 | +order = "ordered" |
| 112 | +tags = ["null"] |
| 113 | + |
| 114 | +[[case]] |
| 115 | +id = "t010_from_float" |
| 116 | +compile_error = true |
| 117 | +description = "The page's numeric conversion does not exclude FLOAT, but Snowflake refuses a FLOAT argument at compile time (recorded as 1007/22023, invalid type for parameter 'TO_BOOLEAN'); this case keeps that behaviour. Catches: the FLOAT converted as a number" |
| 118 | +columns = [{ name = "f", type = "FLOAT" }] |
| 119 | +rows = [ |
| 120 | + ["0"], |
| 121 | + ["0.001"], |
| 122 | +] |
| 123 | +query = "SELECT ordinal, CAST(f AS BOOLEAN) AS b FROM input ORDER BY ordinal" |
| 124 | +order = "ordered" |
| 125 | +tags = ["error"] |
0 commit comments