Skip to content

Is there a way to extract the DDL generated by the create_table method? #9699

Answered by cpcloud
csubhodeep asked this question in Q&A
Discussion options

You must be logged in to vote

I think we could probably add a .compile() method to our Schema object, which would get you everything between the parentheses and would probably clean up a bunch of our internals in the various create_table methods.

For example, we could likely easily get you the expressions list here:

In [1]: import sqlglot as sg

In [2]: sg.parse_one("create table t (x int, y int)")
Out[2]:
Create(
  this=Schema(
    this=Table(
      this=Identifier(this=t, quoted=False)),
    expressions=[
      ColumnDef(
        this=Identifier(this=x, quoted=False),
        kind=DataType(this=Type.INT, nested=False)),
      ColumnDef(
        this=Identifier(this=y, quoted=False),
        kind=DataType(this=Type.I…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@csubhodeep
Comment options

@csubhodeep
Comment options

@cpcloud
Comment options

Answer selected by cpcloud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants