@@ -59,6 +59,7 @@ pub const CODES: &[CodeEntry] = &[
5959 parser's message. Check the SQL at that point against Snowflake's grammar; if \
6060 Snowflake accepts the statement, SQLQuack's parser is missing the syntax and the \
6161 statement should be reported with the label.",
62+ example : r#"echo "SELECT a, FROM orders WHERE (b = 1" | sqlquack check"# ,
6263 } ,
6364 CodeEntry {
6465 code : MISSING_RULE ,
@@ -71,6 +72,7 @@ pub const CODES: &[CodeEntry] = &[
7172 the statement is refused rather than converted to SQL that might mean something \
7273 else in DuckDB. Rewrite the statement without the construct, or wait for a rule; \
7374 `sqlquack census` shows which constructs a body of SQL needs.",
75+ example : r#"echo "SELECT WEEKISO(CURRENT_DATE()) AS w" | sqlquack convert --builtin-policy"# ,
7476 } ,
7577 CodeEntry {
7678 code : TYPE_CONDITION ,
@@ -85,6 +87,7 @@ pub const CODES: &[CodeEntry] = &[
8587 determine. Declaring the relation's columns and types in the schema often lets the \
8688 types resolve; an explicit cast to a covered type also works when it keeps the \
8789 statement's meaning.",
90+ example : r#"echo "SELECT FLOOR('abc') AS f" | sqlquack convert --builtin-policy"# ,
8891 } ,
8992 CodeEntry {
9093 code : UNRESOLVED_NAME ,
@@ -98,6 +101,7 @@ pub const CODES: &[CodeEntry] = &[
98101 name refers to and what type it has. The name at the span is unknown, or resolves to \
99102 more than one column. Add the relation and its columns to the schema file, or \
100103 qualify an ambiguous column with its relation.",
104+ example : r#"echo "SELECT a FROM orders" | sqlquack convert --builtin-policy"# ,
101105 } ,
102106 CodeEntry {
103107 code : NOT_EXPRESSIBLE ,
@@ -108,6 +112,7 @@ pub const CODES: &[CodeEntry] = &[
108112 explanation : "The construct at the span has a Snowflake meaning DuckDB has no way to \
109113 reproduce, for the reason in the label. No future rule will convert it as written. \
110114 Rewrite the statement so it does not depend on that behaviour.",
115+ example : "no construct is declared inexpressible yet; one would be refused with the reason as its label" ,
111116 } ,
112117 CodeEntry {
113118 code : CONVERSION_BUDGET ,
@@ -119,6 +124,7 @@ pub const CODES: &[CodeEntry] = &[
119124 the conversion budget allows. The budget keeps a pathological input from stalling a \
120125 caller. Splitting the statement, for example into common table expressions or \
121126 separate statements, usually brings it under the budget.",
127+ example : "a statement whose conversion runs past the time budget or emits more DuckDB SQL than it allows" ,
122128 } ,
123129 CodeEntry {
124130 code : SESSION_PARAMETERS ,
@@ -130,6 +136,7 @@ pub const CODES: &[CodeEntry] = &[
130136 session parameters given match none of them, so no conversion is proven for that \
131137 session. The label names the parameters; unset parameters take Snowflake's \
132138 documented defaults.",
139+ example : r#"echo "SELECT 1 AS one" | sqlquack convert --builtin-policy --session WEEK_START=1"# ,
133140 } ,
134141 CodeEntry {
135142 code : DIVERGENCE_REFUSED ,
@@ -147,6 +154,7 @@ pub const CODES: &[CodeEntry] = &[
147154 the statement is refused. Allow it in the policy file, use a mode that allows it, \
148155 or confirm the assumption it rests on; otherwise rewrite the statement without the \
149156 construct.",
157+ example : r#"echo "SELECT HASH(1) AS h" | sqlquack convert --builtin-policy"# ,
150158 } ,
151159 CodeEntry {
152160 code : "SQ0101" ,
@@ -156,6 +164,7 @@ pub const CODES: &[CodeEntry] = &[
156164 help : Some ( "split the input into smaller files" ) ,
157165 explanation : "The parser refuses inputs beyond a fixed size so that one input cannot \
158166 exhaust memory. Split the SQL into several inputs and convert each.",
167+ example : r#"python3 -c "print('SELECT 1;' * 2000000)" | sqlquack check"# ,
159168 } ,
160169 CodeEntry {
161170 code : "SQ0102" ,
@@ -165,6 +174,7 @@ pub const CODES: &[CodeEntry] = &[
165174 help : Some ( "split the input into smaller statements or files" ) ,
166175 explanation : "The parser refuses inputs with more tokens than its budget so that \
167176 parsing time stays bounded. Split the SQL into several statements or inputs.",
177+ example : r#"python3 -c "print('SELECT 1;' * 400000)" | sqlquack check"# ,
168178 } ,
169179 CodeEntry {
170180 code : "SQ0103" ,
@@ -178,6 +188,7 @@ pub const CODES: &[CodeEntry] = &[
178188 parser's limit. The limit keeps parsing from exhausting the stack. Redundant \
179189 parentheses can be removed; deeply nested subqueries can usually become common \
180190 table expressions.",
191+ example : r#"python3 -c "print('SELECT ' + '(' * 600 + '1' + ')' * 600)" | sqlquack check"# ,
181192 } ,
182193 CodeEntry {
183194 code : "SQ0104" ,
@@ -188,6 +199,7 @@ pub const CODES: &[CodeEntry] = &[
188199 explanation : "The parser's recursion reached its depth limit at the span. The limit \
189200 keeps parsing from exhausting the stack. Restructure the deepest part of the \
190201 statement, for example with common table expressions.",
202+ example : r#"python3 -c "print('SELECT ' + 'NOT ' * 2000 + 'TRUE')" | sqlquack check"# ,
191203 } ,
192204 CodeEntry {
193205 code : "SQ0105" ,
@@ -198,6 +210,7 @@ pub const CODES: &[CodeEntry] = &[
198210 explanation : "The statement parsed, but its tree nests deeper than the limit SQLQuack \
199211 places on later analysis, which keeps conversion from exhausting the stack. \
200212 Restructure the deepest part of the statement.",
213+ example : r#"python3 -c "print('SELECT ' + 'CASE WHEN TRUE THEN ' * 600 + '1' + ' END' * 600)" | sqlquack check"# ,
201214 } ,
202215 CodeEntry {
203216 code : "SQ0106" ,
@@ -207,6 +220,7 @@ pub const CODES: &[CodeEntry] = &[
207220 help : Some ( "split the statement into smaller statements" ) ,
208221 explanation : "The statement parsed into more tree nodes than SQLQuack's budget, which \
209222 keeps conversion time and memory bounded. Split it into smaller statements.",
223+ example : "a statement that parses into more than a million tree nodes" ,
210224 } ,
211225 CodeEntry {
212226 code : "SQ0107" ,
@@ -217,6 +231,7 @@ pub const CODES: &[CodeEntry] = &[
217231 explanation : "Function calls nest inside each other deeper than SQLQuack's limit at \
218232 the span. Compute the innermost calls in a common table expression or a subquery \
219233 and refer to their results.",
234+ example : r#"python3 -c "print('SELECT ' + 'ABS(' * 300 + '1' + ')' * 300)" | sqlquack check"# ,
220235 } ,
221236 CodeEntry {
222237 code : "SQ0201" ,
@@ -229,6 +244,7 @@ pub const CODES: &[CodeEntry] = &[
229244 no Snowflake meaning to convert. Without ALL the \
230245 operators compare distinct rows; keeping duplicates needs a rewrite, for example \
231246 numbering each row with ROW_NUMBER() over all columns and comparing those pairs.",
247+ example : r#"echo "SELECT id FROM orders INTERSECT ALL SELECT id FROM returns" | sqlquack check"# ,
232248 } ,
233249 CodeEntry {
234250 code : "SQ0202" ,
@@ -239,6 +255,7 @@ pub const CODES: &[CodeEntry] = &[
239255 explanation : "FOR UPDATE WAIT n parses, but Snowflake rejects it as an unsupported \
240256 feature, so the statement never runs there. Remove the WAIT clause; Snowflake's \
241257 lock timeout comes from the LOCK_TIMEOUT session parameter instead.",
258+ example : r#"echo "SELECT order_id FROM orders FOR UPDATE WAIT 7" | sqlquack check"# ,
242259 } ,
243260 CodeEntry {
244261 code : "SQ0203" ,
@@ -253,6 +270,7 @@ pub const CODES: &[CodeEntry] = &[
253270 function (Snowflake error 992). A window function the QUALIFY condition reaches \
254271 through a SELECT-list alias counts. A condition on plain columns belongs in WHERE, \
255272 and one on aggregates in HAVING.",
273+ example : r#"echo "SELECT 1 QUALIFY TRUE" | sqlquack check"# ,
256274 } ,
257275 CodeEntry {
258276 code : "SQ0204" ,
@@ -264,5 +282,6 @@ pub const CODES: &[CodeEntry] = &[
264282 the pattern first, ignoring case, and rejects a REPLACE or RENAME of a column the \
265283 pattern did not keep (Snowflake error 1431). A name that fails the pattern ignoring \
266284 case fails it whatever the table holds, so no schema is needed to see it.",
285+ example : r#"echo "SELECT * ILIKE '%_id' REPLACE (price * 2 AS price) FROM orders" | sqlquack check"# ,
267286 } ,
268287] ;
0 commit comments