crate / cratedb-sqlparse

Parsing utilities to validate and split SQL statements for CrateDB.
Apache License 2.0
4 stars 1 forks source link

Add `with_properties` and `interpolated_properties` #37

Closed surister closed 3 weeks ago

surister commented 4 weeks ago

Summary of the changes / Why this is an improvement

This PR allows for extracting properties defined by [ WITH ( parameter [= value] [, ... ] ) ] statements.

For example:

from cratedb_sqlparse import sqlparse

stmt = sqlparse("""
    CREATE TABLE doc.tbl12 (A TEXT) WITH (
      "allocation.max_retries" = 5,
      "blocks.metadata" = false
    );
""")[0]

print(stmt.metadata)
# Metadata(schema='doc', table_name='tbl12', interpolated_properties={}, with_properties={'allocation.max_retries': '5', 'blocks.metadata': 'false'})

It also handles the special case of what I call, interpolated values and #31 if you have a better name recommendation, please go ahead :P

Checklist