Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNKNOWN type in an INSERT #762

Closed
michelmetran opened this issue Jan 31, 2024 · 1 comment
Closed

UNKNOWN type in an INSERT #762

michelmetran opened this issue Jan 31, 2024 · 1 comment
Milestone

Comments

@michelmetran
Copy link

Describe the bug

When I'm using an "INSERT" preceded by "USE dbname; GO;", typically used in SQL Server, the first INSERT gives an error, being recognized as UNKNOWN .

Example code follows.

import sqlparse

sql = """
USE ESTAGIARIO
GO

INSERT INTO estagiario.dbo.Tab_Geral (Promo_Atual, Naturalidade, Dt_Nascimento) values ('PJ CRIMINAL DE OSASCO', 'Piracicaba', '2002-5-7');
INSERT INTO estagiario.dbo.Tab_Geral (Promo_Atual, Naturalidade, Dt_Nascimento) values ('PJ DE LENÇÓIS PAULISTA', 'São Paulo', '2002-5-7');
INSERT INTO estagiario.dbo.Tab_Geral (Promo_Atual, Naturalidade, Dt_Nascimento) values ('3ª PROMOTORIA DE JUSTIÇA CRIMINAL DA CAPITAL', 'Santos', '2002-5-7');
"""

for text in sqlparse.parse(sql):    
    print(text.normalized)
    print(text.get_type())

Output....

USE ESTAGIARIO
GO

INSERT INTO estagiario.dbo.Tab_Geral (Promo_Atual, Naturalidade, Dt_Nascimento) values ('PJ CRIMINAL DE OSASCO', 'Piracicaba', '2002-5-7');
***UNKNOWN***

INSERT INTO estagiario.dbo.Tab_Geral (Promo_Atual, Naturalidade, Dt_Nascimento) values ('PJ DE LENÇÓIS PAULISTA', 'São Paulo', '2002-5-7');
***INSERT***

INSERT INTO estagiario.dbo.Tab_Geral (Promo_Atual, Naturalidade, Dt_Nascimento) values ('3ª PROMOTORIA DE JUSTIÇA CRIMINAL DA CAPITAL', 'Santos', '2002-5-7');
***INSERT***

Expected behavior
I understand that there is a problem when the INSERT is preceded by tags not recognized by sqlparser (USE, GO)


Versions (please complete the following information):

  • Python: 3.11
  • sqlparse: 0.4.4

Additional context
Maybe this problem is also related to the issue #727

@andialbrecht
Copy link
Owner

Documentation of GO: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-go?view=sql-server-ver16

This looks interesting... GO acts as a statement terminator, but according to the docs a semicolon after GO shouldn't be used. I think that's why the parser is a bit confused here ;)

@andialbrecht andialbrecht added this to the 0.5.0 milestone Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants