sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.51k stars 810 forks source link

Timestamp between interaction on Python codegen #3696

Open otavioabreu27 opened 1 week ago

otavioabreu27 commented 1 week ago

Version

1.27.0

What happened?

When making a query that has a 'where timestamp between', for example:

SELECT 
    COUNT(*)
FROM 
    searches s 
JOIN
    rel_searches_availables rsa ON s.s_id = rsa.rsa_search_id
WHERE 
    s.s_search_date_timestamp BETWEEN $1 AND $2;

The code generated make both parameters have the same name, which is not valid on Python.

def count_availables_time_window(self, *, s_search_date_timestamp: datetime.datetime, s_search_date_timestamp: datetime.datetime) -> Optional[int]:
        row = self._conn.execute(sqlalchemy.text(COUNT_AVAILABLES_TIME_WINDOW), {"p1": s_search_date_timestamp, "p2": s_search_date_timestamp}).first()
        if row is None:
            return None
        return row[0]

Thus creating the error bellow:

image

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Python