Abstract Syntax Tree parsers and compilers as a service

Source

CREATE TABLE t ( id SERIAL, name VARCHAR(16) NOT NULL ); ALTER TABLE ONLY public.t ADD CONSTRAINT t_pk PRIMARY KEY (id); ALTER TABLE t ADD email VARCHAR(64) NOT NULL;

    CREATE TABLE t (
      id SERIAL,
      name VARCHAR(16) NOT NULL
    );
    
    ALTER TABLE ONLY public.t
      ADD CONSTRAINT t_pk PRIMARY KEY (id);
    
    ALTER TABLE t
      ADD email VARCHAR(64) NOT NULL;
  

AST

[ { "CreateStmt": { "relation": { "RangeVar": { "relname": "t", "inh": true, "relpersistence": "p", "location": 13 } }, "tableElts": [ { "ColumnDef": { "colname": "id", "typeName": { "TypeName": { "names": [ { "String": { "str": "serial" } } ], "typemod": -1, "location": 22 } }, "is_local": true, "location": 19 } }, { "ColumnDef": { "colname": "name", "typeName": { "TypeName": { "names": [ { "String": { "str": "pg_catalog" } }, { "String": { "str": "varchar" } } ], "typmods": [ { "A_Const": { "val": { "Integer": { "ival": 16 } }, "location": 45 } } ], "typemod": -1, "location": 37 } }, "is_local": true, "constraints": [ { "Constraint": { "location": 49, "contype": 1 } } ], "location": 32 } } ], "oncommit": 0 } }, { "AlterTableStmt": { "type": 237, "relation": { "RangeVar": { "schemaname": "public", "relname": "t", "relpersistence": "p", "location": 17 } }, "cmds": [ { "AlterTableCmd": { "subtype": 17, "def": { "Constraint": { "conname": "t_pk", "location": 32, "contype": 6, "keys": [ { "String": { "str": "id" } } ] } }, "behavior": 0 } } ], "relkind": 39 } }, { "AlterTableStmt": { "type": 237, "relation": { "RangeVar": { "relname": "t", "inh": true, "relpersistence": "p", "location": 12 } }, "cmds": [ { "AlterTableCmd": { "subtype": 0, "def": { "ColumnDef": { "colname": "email", "typeName": { "TypeName": { "names": [ { "String": { "str": "pg_catalog" } }, { "String": { "str": "varchar" } } ], "typmods": [ { "A_Const": { "val": { "Integer": { "ival": 64 } }, "location": 35 } } ], "typemod": -1, "location": 27 } }, "is_local": true, "constraints": [ { "Constraint": { "location": 39, "contype": 1 } } ], "location": 21 } }, "behavior": 0 } } ], "relkind": 39 } } ]

    [
      {
        "CreateStmt": {
          "relation": {
            "RangeVar": {
              "relname": "t",
              "inh": true,
              "relpersistence": "p",
              "location": 13
            }
          },
          "tableElts": [
            {
              "ColumnDef": {
                "colname": "id",
                "typeName": {
                  "TypeName": {
                    "names": [
                      {
                        "String": {
                          "str": "serial"
                        }
                      }
                    ],
                    "typemod": -1,
                    "location": 22
                  }
                },
                "is_local": true,
                "location": 19
              }
            },
            {
              "ColumnDef": {
                "colname": "name",
                "typeName": {
                  "TypeName": {
                    "names": [
                      {
                        "String": {
                          "str": "pg_catalog"
                        }
                      },
                      {
                        "String": {
                          "str": "varchar"
                        }
                      }
                    ],
                    "typmods": [
                      {
                        "A_Const": {
                          "val": {
                            "Integer": {
                              "ival": 16
                            }
                          },
                          "location": 45
                        }
                      }
                    ],
                    "typemod": -1,
                    "location": 37
                  }
                },
                "is_local": true,
                "constraints": [
                  {
                    "Constraint": {
                      "location": 49,
                      "contype": 1
                    }
                  }
                ],
                "location": 32
              }
            }
          ],
          "oncommit": 0
        }
      },
      {
        "AlterTableStmt": {
          "type": 237,
          "relation": {
            "RangeVar": {
              "schemaname": "public",
              "relname": "t",
              "relpersistence": "p",
              "location": 17
            }
          },
          "cmds": [
            {
              "AlterTableCmd": {
                "subtype": 17,
                "def": {
                  "Constraint": {
                    "conname": "t_pk",
                    "location": 32,
                    "contype": 6,
                    "keys": [
                      {
                        "String": {
                          "str": "id"
                        }
                      }
                    ]
                  }
                },
                "behavior": 0
              }
            }
          ],
          "relkind": 39
        }
      },
      {
        "AlterTableStmt": {
          "type": 237,
          "relation": {
            "RangeVar": {
              "relname": "t",
              "inh": true,
              "relpersistence": "p",
              "location": 12
            }
          },
          "cmds": [
            {
              "AlterTableCmd": {
                "subtype": 0,
                "def": {
                  "ColumnDef": {
                    "colname": "email",
                    "typeName": {
                      "TypeName": {
                        "names": [
                          {
                            "String": {
                              "str": "pg_catalog"
                            }
                          },
                          {
                            "String": {
                              "str": "varchar"
                            }
                          }
                        ],
                        "typmods": [
                          {
                            "A_Const": {
                              "val": {
                                "Integer": {
                                  "ival": 64
                                }
                              },
                              "location": 35
                            }
                          }
                        ],
                        "typemod": -1,
                        "location": 27
                      }
                    },
                    "is_local": true,
                    "constraints": [
                      {
                        "Constraint": {
                          "location": 39,
                          "contype": 1
                        }
                      }
                    ],
                    "location": 21
                  }
                },
                "behavior": 0
              }
            }
          ],
          "relkind": 39
        }
      }
    ]
  

Compiled

{ "relations": [ { "type": "TABLE", "names": { "original": { "schema": "public", "name": "t" }, "local": null }, "indexes": [ { "name": "t_pk", "relation": { "schema": "public", "name": "t" }, "method": "btree", "where": null, "unique": true, "constraint": { "name": "t_pk" }, "columnsParams": [ { "name": "id", "ordering": 0, "nulls_ordering": 0 } ], "excludeParams": null } ], "constraints": [ { "type": "CONSTR_NOTNULL", "place": "inline", "name": null, "relation": { "schema": "public", "name": "t" }, "columns": [ "name" ], "constraint": { "ast": [], "compiled": null } }, { "type": "CONSTR_PRIMARY", "place": "detached", "name": "t_pk", "columns": [ "id" ], "relation": { "schema": "public", "name": "t" }, "constraint": { "ast": null, "compiled": null } }, { "type": "CONSTR_NOTNULL", "place": "detached", "name": null, "columns": [ "email" ], "relation": { "schema": "public", "name": "t" }, "constraint": { "ast": null, "compiled": null } }, { "type": "CONSTR_NOTNULL", "place": "generated-notnull", "name": null, "relation": { "schema": "public", "name": "t" }, "columns": [ "id" ], "constraint": { "ast": null, "compiled": null } } ], "columns": [ { "names": { "original": "id", "local": null }, "type": { "schema": "pg_catalog", "name": "integer", "mods": [], "array": { "dimension": 0, "bounds": [] } }, "kind": "column", "nullable": "yes", "sequence": { "schema": "public", "name": "t_id_seq" } }, { "names": { "original": "name", "local": null }, "type": { "schema": "pg_catalog", "name": "character varying", "mods": [ 16 ], "array": { "dimension": 0, "bounds": [] } }, "kind": "column", "nullable": "no", "sequence": null }, { "names": { "original": "email", "local": null }, "type": { "schema": "pg_catalog", "name": "character varying", "mods": [ 64 ], "array": { "dimension": 0, "bounds": [] } }, "kind": "column", "nullable": "no", "sequence": null } ], "partition": null, "inherit": null, } ], "types": [], "functions": [], "operators": [], "sequences": [ { "schema": "public", "name": "t_id_seq", "nameSource": "generated", "type": { "schema": "pg_catalog", "name": "integer", "mods": [], "array": { "dimension": 0, "bounds": [ -1 ] } }, "increment": null, "start": null, "min": null, "max": null, "place": "inline", } ] }

    {
      "relations": [
        {
          "type": "TABLE",
          "names": {
            "original": {
              "schema": "public",
              "name": "t"
            },
            "local": null
          },
          "indexes": [
            {
              "name": "t_pk",
              "relation": {
                "schema": "public",
                "name": "t"
              },
              "method": "btree",
              "where": null,
              "unique": true,
              "constraint": {
                "name": "t_pk"
              },
              "columnsParams": [
                {
                  "name": "id",
                  "ordering": 0,
                  "nulls_ordering": 0
                }
              ],
              "excludeParams": null
            }
          ],
          "constraints": [
            {
              "type": "CONSTR_NOTNULL",
              "place": "inline",
              "name": null,
              "relation": {
                "schema": "public",
                "name": "t"
              },
              "columns": [
                "name"
              ],
              "constraint": {
                "ast": [],
                "compiled": null
              }
            },
            {
              "type": "CONSTR_PRIMARY",
              "place": "detached",
              "name": "t_pk",
              "columns": [
                "id"
              ],
              "relation": {
                "schema": "public",
                "name": "t"
              },
              "constraint": {
                "ast": null,
                "compiled": null
              }
            },
            {
              "type": "CONSTR_NOTNULL",
              "place": "detached",
              "name": null,
              "columns": [
                "email"
              ],
              "relation": {
                "schema": "public",
                "name": "t"
              },
              "constraint": {
                "ast": null,
                "compiled": null
              }
            },
            {
              "type": "CONSTR_NOTNULL",
              "place": "generated-notnull",
              "name": null,
              "relation": {
                "schema": "public",
                "name": "t"
              },
              "columns": [
                "id"
              ],
              "constraint": {
                "ast": null,
                "compiled": null
              }
            }
          ],
          "columns": [
            {
              "names": {
                "original": "id",
                "local": null
              },
              "type": {
                "schema": "pg_catalog",
                "name": "integer",
                "mods": [],
                "array": {
                  "dimension": 0,
                  "bounds": []
                }
              },
              "kind": "column",
              "nullable": "yes",
              "sequence": {
                "schema": "public",
                "name": "t_id_seq"
              }
            },
            {
              "names": {
                "original": "name",
                "local": null
              },
              "type": {
                "schema": "pg_catalog",
                "name": "character varying",
                "mods": [
                  16
                ],
                "array": {
                  "dimension": 0,
                  "bounds": []
                }
              },
              "kind": "column",
              "nullable": "no",
              "sequence": null
            },
            {
              "names": {
                "original": "email",
                "local": null
              },
              "type": {
                "schema": "pg_catalog",
                "name": "character varying",
                "mods": [
                  64
                ],
                "array": {
                  "dimension": 0,
                  "bounds": []
                }
              },
              "kind": "column",
              "nullable": "no",
              "sequence": null
            }
          ],
          "partition": null,
          "inherit": null,
        }
      ],
      "types": [],
      "functions": [],
      "operators": [],
      "sequences": [
        {
          "schema": "public",
          "name": "t_id_seq",
          "nameSource": "generated",
          "type": {
            "schema": "pg_catalog",
            "name": "integer",
            "mods": [],
            "array": {
              "dimension": 0,
              "bounds": [
                -1
              ]
            }
          },
          "increment": null,
          "start": null,
          "min": null,
          "max": null,
          "place": "inline",
        }
      ]
    }
  

SQL dialects

 PostgreSQLSnowflakeCypherBigQueryMysql/MariaDB
AST
dialect db version135.18oct 20208.0/10.5
status
production
alpha
production
soonsoon
originofficialcustomthird partyofficialofficial
DDL syntax coverage
DML syntax coveragewith some exceptions 1
rest syntax coverage
db-specified tree
postgres-like treesoonsoon
multi-statements
DDL statements reorderingsoonsoonsoon
DDL AST deparsersoonsoonsoonsoon
DML AST deparsersoonsoonsoonsoon
relation name normalizationsoonsoonsoonsoon
COMPILER
status
production
alpha
soonsoon
DDL
DDL behavior coveragewith some exceptions 2partialwith some exceptions 2with some exceptions 2
UD statements compiler 3soon
VIEW compilerpartial
DML
DML result fields base types partial
DML result fields UD typessoon
DML result fields nullable solver partial
DML lines count class 4soon
DML parameters typessoonsoonsoonsoon
DML parameters nullable solversoonsoonsoonsoon
Relations connections from DML 5 partial
syntax auto-recovery 6soonsoonsoonsoon
scope at position 7soonsoonsoonsoon
detailsRedshift, greenplum and others postgresql-based syntax DBs
  • some corner cases
  • some rare behavior, cant be use for strong error validation
  • parse types from user-defined function, types, special functions behavior (eg timescale)
  • none/one/one or none/many/many or none
  • list of joined relations with fields inside statement
  • parse incomplete statement
  • get scope at any cursor position

Start now!

It’s free!

Who needs it?

Developers who:

  • building database tools (i.e. data governance, database schema modelers, IDE plugins, etc.) 🛠️
  • building serverless and cloud-native applications ☁️
  • want to automate code quality control in CI/CD ✅
  • are code-generator lovers ❤️
  • need deep database insights 💡

Subscribe to updates

We'll notify you about new supported SQL dialects, new compiler features, and more.

FAQ

  • parsers.dev is a service for AST parsing and compiling different SQL dialects, supporting open-source and proprietary databases. We use both official and non-official parsers to build AST objects. After compiling DDL you'll get an object which represented the database schema with relations, functions, and other objects, after apply all CREATE, ALTER, DROP statements. After compiling DML you'll get return field types, nullability flags for each field, and rows amount class (NONE, ONE, ONE_OR_NONE, MANY, MANY_OR_NONE). All this information that you never get before, can be used for a lot of purposes - from code quality control (like we use it in holistic.dev) to building some awesome brand-new tools for developers, database administrators, and data teams! 🚀

  • It is absolutely free for now! After the test period, we'll make our service paid. We plan to make a free tier and charge for incoming data size with a minimum monthly limit. 💰

  • Everything is protected! We do not even store your DDL and DML sources, except part of statements that were not parsed by AST parsers for future

  • Soon! Subscribe for news, and we will notify you

  • We are working on it... 📝

  • All compilers are created by ourselves and cannot guarantee 100% compatibility of the results with the behavior of the original systems. This is especially true for cloud-only databases, which are updated seamlessly without notice. We make every effort to bring our results as close as possible to the behavior of real systems. But don’t use this service as the only source of truth. Check all results when in doubt. We would be grateful if you would point out problems to us in personal messages. Because this is SaaS, updates can be applied at any time, without prior notice. We will do our best to maintain backward compatibility for as long as possible.

  • Great! Please, mail us [email protected] and we'll stir up a great collaboration! 🤝