sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

CREATE TABLE wrong format

Open umbertoB67 opened this issue 3 years ago • 12 comments

Why is this statement ... image ...formatted like this? image

umbertoB67 avatar Nov 18 '22 13:11 umbertoB67

Please past your input sql code here as text so that we don't have to type your statement from a screenshot in order to test it. Also, please include details about what python version and what library version you are runing.

mrmasterplan avatar Nov 25 '22 23:11 mrmasterplan

I'm sorry for delay in answer. This is my input SQL:

CREATE TABLE `ambienti` (
    `id` INT(3) NOT NULL AUTO_INCREMENT,
    `sigla` VARCHAR(1) NOT NULL,
    `nome` VARCHAR(100) NOT NULL,
    `gruppo` CHAR(1) NOT NULL,
    `id_criticita` INT(11) DEFAULT NULL,
    `is_visible` INT(1) NOT NULL DEFAULT '1',
    `raggruppamento` VARCHAR(45) DEFAULT NULL,
    PRIMARY KEY (`id`)
)  ENGINE=INNODB AUTO_INCREMENT=11 DEFAULT CHARSET=LATIN1;

I'm using the formatter at this page: https://sqlformat.org/, but using API I got the same result:

CREATE TABLE `ambienti` (`id` INT(3) NOT NULL AUTO_INCREMENT,
                                              `sigla` VARCHAR(1) NOT NULL,
                                                                 `nome` VARCHAR(100) NOT NULL,
                                                                                     `gruppo` CHAR(1) NOT NULL,
                                                                                                      `id_criticita` INT(11) DEFAULT NULL,
                                                                                                                                     `is_visible` INT(1) NOT NULL DEFAULT '1',
                                                                                                                                                                          `raggruppamento` VARCHAR(45) DEFAULT NULL,
                                                                                                                                                                                                               PRIMARY KEY (`id`)) ENGINE=INNODB AUTO_INCREMENT=11 DEFAULT
CHARSET=LATIN1;

umbertoB67 avatar Nov 30 '22 18:11 umbertoB67

If it can be of any help I can reproduce the error using sqlparse 0.4.3 and python 3.9 using the following code:

sql = """
CREATE TABLE `ambienti` (
    `id` INT(3) NOT NULL AUTO_INCREMENT,
    `sigla` VARCHAR(1) NOT NULL,
    `nome` VARCHAR(100) NOT NULL,
    `gruppo` CHAR(1) NOT NULL,
    `id_criticita` INT(11) DEFAULT NULL,
    `is_visible` INT(1) NOT NULL DEFAULT '1',
    `raggruppamento` VARCHAR(45) DEFAULT NULL,
    PRIMARY KEY (`id`)
)  ENGINE=INNODB AUTO_INCREMENT=11 DEFAULT CHARSET=LATIN1;
"""
print(sqlparse.format(sql, reindent=True, keyword_case='upper'))

mrvaita avatar Dec 06 '22 08:12 mrvaita

Is there no solution to this problem? Does anyone know of any other free online parsers (or at Windows command-line) that expose APIs?

umbertoB67 avatar Dec 15 '22 21:12 umbertoB67

I am not a maintainer of this project. I am also looking for an open-source, python, sql parser and have not found anything better. My solution to is that I am trying to contribute to this project to make it better and more useful for a greater number of people, but ultimately we need to wait for the project owner to devote time to this.

mrmasterplan avatar Dec 15 '22 21:12 mrmasterplan

Waiting for a solution I'm using this command line tool which works very well (Poor Man's T-SQL Formatter) ==> http://architectshack.com/poormanstsqlformatter.ashx

umbertoB67 avatar Dec 27 '22 12:12 umbertoB67

Hi guys, anyone have the same problem?

umbertoB67 avatar Mar 14 '23 09:03 umbertoB67

@umbertoB67 Yeah, I do

Nickelza avatar Apr 19 '23 10:04 Nickelza

I also met this problem.

zhaojiuxiao avatar May 11 '23 08:05 zhaojiuxiao

Is there no solution to this problem?

umbertoB67 avatar Jul 17 '23 09:07 umbertoB67

Hi guys, anyone have the same problem? I also met this problem. ) :

aixiuh avatar Dec 18 '23 07:12 aixiuh