v1a0 / sqllex

The most pythonic ORM (for SQLite and PostgreSQL). Seriously, try it out!
https://v1a0.github.io/sqllex
GNU General Public License v3.0
91 stars 8 forks source link

BUG | psycopg2.errors.UndefinedColumn: CamelCase column does not exist #62

Open v1a0 opened 2 years ago

v1a0 commented 2 years ago

Code

db = PostgreSQLx(
            engine=psycopg2,
            dbname='test_sqllex',
            user='test_sqllex',
            password='test_sqllex'
)

db['employee'].select('id, firstName')

db['employee'].select('id', 'firstName')
Error
Traceback (most recent call last):
  File "some_postgresqlx.py", line 874, in test_select
    expected, self.db['employee'].select(['id', 'firstName'])
  File "sqllex\sqllex\core\entities\abc\sql_database.py", line 249, in select
    return self.db.select(
  File "sqllex\sqllex\core\entities\abc\sql_database.py", line 1553, in select
    return self.execute(script=script, values=values)
  File "sqllex\sqllex\core\entities\abc\sql_database.py", line 1018, in execute
    return self._executor(script=script, values=values, spec=1)
  File "sqllex\sqllex\core\entities\postgresqlx\postgresqlx.py", line 273, in _executor
    return middleware.execute(script=script, values=values, connection=self.connection)
  File "sqllex\sqllex\core\entities\postgresqlx\middleware.py", line 48, in execute
    return mw_executor(conn=connection, script=script, values=values)
  File "sqllex\sqllex\core\entities\postgresqlx\middleware.py", line 36, in mw_executor
    raise error
  File "sqllex\sqllex\core\entities\postgresqlx\middleware.py", line 19, in mw_executor
    cur.execute(script)
psycopg2.errors.UndefinedColumn: column "firstname" does not exist
LINE 1: SELECT id, firstName FROM "employee"
                   ^
HINT:  Perhaps you meant to reference the column "employee.firstName".

Temporary fix

use " or full column name employee."firstName"

db['employee'].select("""
id, "firstName"
""")

# OR

db['employee'].select('employee.id', 'employee."firstName"')