sqllex icon indicating copy to clipboard operation
sqllex copied to clipboard

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

Open v1a0 opened this issue 2 years ago • 0 comments

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"')

v1a0 avatar Apr 02 '22 03:04 v1a0