Skip to content

Commit 560bc45

Browse files
committed
update readme to include is_parsable
1 parent 8b24047 commit 560bc45

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ Context helps give context of where the table was used in the query:
8080

8181
## Functions
8282

83-
This extension provides one table function and two scalar functions for parsing SQL and extracting referenced tables.
83+
This extension provides one table function and three scalar functions for parsing SQL and extracting referenced tables.
84+
85+
In general, errors (e.g. Parse Exception) will not be exposed to the user, but instead will result in an empty result. This simplifies batch processing. When validity is needed, [is_parsable](#is_parsablesql_query--scalar-function) can be used.
8486

8587
### `parse_tables(sql_query)` – Table Function
8688

@@ -170,6 +172,46 @@ SELECT parse_tables('select * from MyTable t inner join Other o on o.id = t.id')
170172
[{'schema': main, 'table': MyTable, 'context': from}, {'schema': main, 'table': Other, 'context': join_right}]
171173
```
172174

175+
176+
### `is_parsable(sql_query)` – Scalar Function
177+
178+
Checks whether a given SQL string is syntactically valid (i.e. can be parsed by DuckDB).
179+
180+
#### Usage
181+
```sql
182+
SELECT is_parsable('SELECT * FROM users');
183+
-- true
184+
185+
SELECT is_parsable('SELEKT * FROM users');
186+
-- false
187+
```
188+
189+
#### Returns
190+
A boolean indicating whether the input SQL string is parsable (`true`) or not (`false`).
191+
192+
#### Example
193+
```sql
194+
SELECT query, is_parsable(query) AS valid
195+
FROM (VALUES
196+
('SELECT * FROM good_table'),
197+
('BAD SQL SELECT *'),
198+
('WITH cte AS (SELECT 1) SELECT * FROM cte')
199+
) AS t(query);
200+
```
201+
202+
##### Output
203+
```
204+
┌───────────────────────────────────────────────┬────────┐
205+
│ query │ valid │
206+
│ varchar │ boolean│
207+
├───────────────────────────────────────────────┼────────┤
208+
│ SELECT * FROM good_table │ true │
209+
│ BAD SQL SELECT * │ false │
210+
│ WITH cte AS (SELECT 1) SELECT * FROM cte │ true │
211+
└───────────────────────────────────────────────┴────────┘
212+
```
213+
214+
173215
## Development
174216

175217
### Build steps

0 commit comments

Comments
 (0)