klahnakoski / mo-sql-parsing

Let's make a SQL parser so we can provide a familiar interface to non-sql datastores!
Mozilla Public License 2.0
255 stars 58 forks source link

Column alias in single quotation marks results in ParseException #247

Closed a1ea321 closed 6 days ago

a1ea321 commented 1 month ago
from mo_sql_parsing import parse_sqlserver as parse
parse('select 42 "my_col_alias"') # This works.
parse("select 42 'my_column_alias'") # This gives ParseException.

select 42 'my_col_alias' works on our instance of MS SQL Server. One of our systems is old and uses this single quotation syntax as well.

pip show mo-sql-parsing says: Version: 10.652.24214

a1ea321 commented 1 month ago

Due to the apparent simplicity, I tried once again to create a patch. After finding myself digging through your other libraries, I decided to stop trying. I can at least send the test to save you one minute:

    def test_issue247(self):
        sql = "select 42 'some_alias'"
        result = parse(sql)
        expected = {'select': {'name': 'some_alias', 'value': 42}}
        self.assertEqual(result, expected)
klahnakoski commented 4 weeks ago

Let me think about this more. I can not find any reference to allowing single-quotes to define column aliases.

klahnakoski commented 6 days ago

https://github.com/klahnakoski/mo-sql-parsing/commit/ea6e21c598673bcbc6a7c28bc98e662130425e24

klahnakoski commented 6 days ago

@a1ea321 my apologies for taking so long on this. Thank you very much for this submission!

https://pypi.org/project/mo-sql-parsing/10.655.24251/