question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres 9.4: invalid input syntax for type boolean

See original GitHub issue

Database: Postgres 9.4.24 Python: 2.7.15 64 bit SQLAlchemy: 1.3.12

SQLAlchemy is generating the following SQL (edited for clarity) which seems to be invalid on this version of Postgres:

SELECT
	project_users.id AS project_users_id,
	project_users.user_id AS project_users_user_id
FROM
	users,
	project_users
	LEFT OUTER JOIN users AS users_1 ON users_1._id = project_users.user_id
WHERE (project_users.project, users._id = project_users.user_id)
IN(('4c472b93-ead5-ee93-b56e-478cb0bc4dc5', '5b71cfa0d2255300289e4d63'))

The resultant error is:

Query 1 ERROR: ERROR:  invalid input syntax for type boolean: "5b71cfa0d2255300289e4d63"
LINE 9: IN(('4c472b93-ead5-ee93-b56e-478cb0bc4dc5', '5b71cfa0d225530...

The python code looks like:

class ProjectUser(BaseModel):
    __tablename__ = 'project_users'

    id = Column(fields.Integer, primary_key=True, autoincrement=True)
    user_id = Column(fields.UID, ForeignKey(User._id), nullable=False)
    project = Column(fields.UID, ForeignKey(Project.uid), nullable=False)
    user = relationship("User", lazy='select')

class User(BaseModel):
    __tablename__ = 'users'

    _id = Column(fields.UID, nullable=False)

with read_only_transaction() as session:
    query = session.query(ProjectUser)
    query = query.options(joinedload(ProjectUser.user))

    project_users = query.filter(tuple_(ProjectUser.project, ProjectUser.user).in_(project_user_ids)).all()

What went wrong?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
zzzeekcommented, Dec 17, 2019

the ideal is things like that would work. but the" try it and see if it works, or explodes" is actually what motivates the name “alchemy”. so dust yourself off and try again! 😃

0reactions
conartist6commented, Dec 17, 2019

Thanks for helping me catch that… It would be nice to have that support (or an error) eventually, but for now I’m unblocked and at least if anyone else makes this same typo they’ll find this issue and know what they did wrong : )

Read more comments on GitHub >

github_iconTop Results From Across the Web

invalid input syntax for type boolean - Stack Overflow
I'm trying to make a simple update query on postgresql. I don't really understand the error as ...
Read more >
PostgreSQL ERROR: invalid input syntax for type boolean
The cause of error: Invalid input syntax for type boolean is when values other than true or false are assigned to an boolean...
Read more >
Documentation: 15: 8.6. Boolean Type - PostgreSQL
Boolean constants can be represented in SQL queries by the SQL key words TRUE , FALSE , and NULL . The datatype input...
Read more >
483 PostgreSQL boolean type update fails - Adminer
ERROR : invalid input syntax for type boolean: "". in case there are fields of the boolean type set to false . ......
Read more >
'invalid input syntax for integer' when importing quoted CSV ...
Coding example for the question PG COPY error: 'invalid input syntax for integer' when importing quoted CSV file without any integers-postgresql.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found