Skip to content

Commit b18a219

Browse files
author
Saurabh Badenkal
committed
Improve anti-pattern #4: mention sql_select() helper, clarify SELECT * + JOIN behavior
- SELECT * with JOIN only expands first (FROM) table columns - Joined table columns are NOT included in expansion - Added sql_select()/sql_columns() as recommended alternative - Updated guardrail summary to mention all blocked patterns
1 parent a09e266 commit b18a219

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

examples/advanced/sql_examples.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,16 @@ def _run_examples(client):
11021102
BAD: SELECT * FROM account (307 columns!)
11031103
WHY: The SDK auto-expands * into all 260+ non-virtual columns.
11041104
Every column is transferred over the network.
1105+
NOTE: With JOINs, SELECT * only expands the FIRST (FROM) table's
1106+
columns -- joined table columns will NOT be included.
1107+
Example: SELECT * FROM account a JOIN contact c ON ...
1108+
expands to account columns only; contact columns are missing.
11051109
FIX: List only the columns you need: SELECT name, revenue FROM account
1110+
Or use the SDK helper:
1111+
cols = client.query.sql_select("account")
1112+
sql = f"SELECT TOP 10 {{cols}} FROM account"
1113+
For JOINs, always specify columns from each table explicitly:
1114+
SELECT a.name, c.fullname FROM account a JOIN contact c ON ...
11061115
11071116
5. DEEP JOINS WITHOUT TOP
11081117
OK: SELECT TOP 100 a.name, ... FROM account a JOIN ... (15 tables)
@@ -1111,9 +1120,14 @@ def _run_examples(client):
11111120
Without TOP, the server processes up to 5000 rows across all joins.
11121121
FIX: Always include TOP N for multi-table JOINs.
11131122
1114-
The SDK's guardrails automatically warn on patterns #1 and #2.
1115-
The server enforces a 5000-row cap on all queries (pattern #3 and #5).
1116-
Pattern #4 is handled by the SDK's SELECT * auto-expansion.
1123+
SDK guardrails:
1124+
- Patterns #1 (writes) and unsupported syntax (CROSS/RIGHT/FULL JOIN,
1125+
UNION, HAVING, CTE, subqueries) -> ValidationError (blocked).
1126+
- Pattern #2 (cartesian FROM a, b) and #4 (SELECT * + JOIN)
1127+
-> UserWarning (advisory).
1128+
- Server enforces 5000-row cap on all queries (#3, #5).
1129+
- Use sql_columns() or sql_select() to discover valid column names.
1130+
- Use sql_joins() or sql_join() to discover valid JOIN clauses.
11171131
""")
11181132

11191133
# ==============================================================

0 commit comments

Comments
 (0)