Abstract Syntax Tree parsers and compilers by DWH.dev 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",
        }
      ]
    }
  

We support the Snowflake dialect for parsing and compiling SQL queries.

To access the API, please write to [email protected]