Skip to content

sqlparse seem like can't format DDL sql #805

@LatreviousYI

Description

@LatreviousYI

Describe the bug
A clear and concise description of what the bug is.

my sql

import sqlparse
    sql = """
    CREATE TABLE t_user_gs_hsakjhkj (
                    id int AUTO_INCREMENT NOT NULL COMMENT '主键',
create_time datetime NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP,
update_time datetime COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
t_user_id int NOT NULL COMMENT '用户表主键id',
occupation_id varchar(225) NOT NULL COMMENT 'occupation_id',
service_order_id varchar(225) NOT NULL COMMENT '订单id',
PRIMARY KEY (id),
UNIQUE INDEX un_t_user_idx (t_user_id)
                );
    """
    print(sqlparse.format(sql, reindent=True, keyword_case='upper'))

result

CREATE TABLE t_user_gs_hsakjhkj
  (id int AUTO_INCREMENT NOT NULL COMMENT '主键',
                                          create_time datetime NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP,
                                                                                               update_time datetime COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                                                                                                                                                                       t_user_id int NOT NULL COMMENT '用户表主
键id',
                                                                                                                                                                                                      occupation_id varchar(225) NOT NULL COMMENT 'occupation_id',

                                   service_order_id varchar(225) NOT NULL COMMENT '订单id',

                                                                                  PRIMARY KEY (id), UNIQUE INDEX un_t_user_idx (t_user_id));

To Reproduce
Steps to reproduce the behavior.
Please give code examples or concete SQL statements. Take care of not posting any sensitive information when pasting SQL statements!
What's the concrete error / traceback.

Expected behavior
A clear and concise description of what you expected to happen.

Versions (please complete the following information):

  • Python: [e.g. 3.10.7]
  • sqlparse: [e.g.0.5.3]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions