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

Unexpected/undesirable CAST of date string to VARCHAR #1174

Open
ccrvlh opened this issue Aug 18, 2024 · 0 comments
Open

Unexpected/undesirable CAST of date string to VARCHAR #1174

ccrvlh opened this issue Aug 18, 2024 · 0 comments

Comments

@ccrvlh
Copy link

ccrvlh commented Aug 18, 2024

  • asyncpg version: 0.29.0
  • PostgreSQL version: 15.7
  • Python version: 3.11
  • Platform: macOS 13.6
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: no (poetry)
start_date = '2024-01-01'
query.where(MyTable.datetime_col >= start_date)

This will fail:

<class 'asyncpg.exceptions.UndefinedFunctionError'>: operator does not exist: timestamp without time zone >= character varying

It seems that this is being casted as VARCHAR:

SELECT * FROM my_table WHERE datetime_col >= $1::VARCHAR

This same filter is valid in Postgres

SELECT * FROM my_table WHERE datetime_col >= '2024-01-01'

It works when using the datetime object:

start_date = dt.datetime.strptime(start_date, "%Y-%m-%d")
query.where(MyTable.datetime_col >= start_date)

Wonder if this is somewhat similar to #1169 in the sense that casting/argument handling invalidates valid SQL statements.

I'd have imagined that castings were performed in obvious and non-breaking scenarios, and scenarios where casting would be necessary, but are not obvious should be handled directly by the user. Breaking valid SQL statements seems counter intuitive IMHO.

@ccrvlh ccrvlh changed the title Unexpected CAST of date string toVARCHAR Unexpected/undesirable CAST of date string to VARCHAR Aug 18, 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

1 participant