Skip to content

Conversation

@ragchuck
Copy link

@ragchuck ragchuck commented Aug 28, 2025

Hi @xnuinside,

thank you for this parser!

In my tests, I couldn't get the "COMMENT ON" syntax to parse successfully. So, I tried to fix it by myself.
It seems to work now. I added correspondent tests. All tests have passed and pre-commit was executed.

This also solves #173 and potentially also #269 and #297

Please have look if you have time and let me know what you think.

Test:

def test_comment_on_columns(): ddl = """  CREATE TABLE users (  id SERIAL PRIMARY KEY,  name VARCHAR(100)  );   COMMENT ON COLUMN users.id IS 'Primary key for user identification';  COMMENT ON COLUMN users.name IS 'User full name';  """ parse_result = DDLParser(ddl).run() expected = [ { "columns": [ { "name": "id", "type": "SERIAL", "size": None, "references": None, "unique": False, "nullable": False, "default": None, "check": None, "comment": "Primary key for user identification", }, { "name": "name", "type": "VARCHAR", "size": 100, "references": None, "unique": False, "nullable": True, "default": None, "check": None, "comment": "User full name", }, ], "primary_key": ["id"], "alter": {}, "checks": [], "index": [], "schema": None, "partitioned_by": [], "table_name": "users", "tablespace": None, } ] assert expected == parse_result

Original error:

E simple_ddl_parser.ddl_parser.DDLParserError: Unknown statement at LexToken(COMMENT,'COMMENT',1,0) 

With this PR, the columns (and tables) get their "comment" attribute filled correctly through corresponding "COMMENT ON" statements.

@ragchuck
Copy link
Author

I did some code simplification and made it that all tests are passing. I also added tests for 'comment on' syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant