xnuinside / simple-ddl-parser

Simple DDL Parser to parse SQL (HQL, TSQL, AWS Redshift, BigQuery, Snowflake and other dialects) ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc. & table properties, types, domains, etc.
MIT License
179 stars 40 forks source link

Column comments containing `''` don't parse. #208

Closed PBalsdon closed 10 months ago

PBalsdon commented 10 months ago

Describe the bug Parsing fails where column comments contain a pair of single quotes, ''. This is used for column comments in snowflake to allow a single ' to appear in the definition.

To Reproduce Parse the statement:

CREATE TABLE table (column_1 int comment 'This comment isn''t right')

Expected behavior A standard parsing output: Expected:

[{
  'alter': {},
  'checks': [],
  'clone': None,
  'columns': [{'check': None,
               'comment': "'This comment isn't right'",
               'default': None,
               'name': 'column_1',
               'nullable': True,
               'references': None,
               'size': None,
               'type': 'int',
               'unique': False}],
  'index': [],
  'partitioned_by': [],
  'primary_key': [],
  'primary_key_enforced': None,
  'schema': None,
  'table_name': 'table',
  'tablespace': None
}]

Screenshots Instead, we get the output []

Version Latest

Additional context I know this is snowflake syntax. Perhaps it is also true for other dialects, I'm not sure.

xnuinside commented 10 months ago

@PBalsdon hi! Thanks for creating the issue, I added support for this https://github.com/xnuinside/simple-ddl-parser/pull/210/ & test. It will be released in version 0.31.1 together with your PR.

xnuinside commented 10 months ago

@PBalsdon 0.31.1 was released https://pypi.org/project/simple-ddl-parser/