psqlpy-python / psqlpy

Asynchronous Python PostgreSQL driver written in Rust
https://psqlpy-python.github.io/
MIT License
211 stars 3 forks source link

Support (BIG)SERIAL and REAL Postgres type #80

Closed paroxyste-0 closed 1 month ago

paroxyste-0 commented 1 month ago

Hello, I would like to know if the SERIAL, BIGSERIAL and REAL types are supported, created as follows:

for example :

id BIGSERIAL PRIMARY KEY,
price FLOAT(2)

the result is : image

because I can't insert price with float data in python, and not retrieve BigSerial data with an int value in python.

Thanks

chandr-andr commented 1 month ago

Hello! Thank you for the issue.

You have to do the following:

from psqlpy.extra_types import BigInt, Float32

async def main():
    psql_pool = ConnectionPool()
    await psql_pool.execute(
        "INSERT INTO issue80 (id, price) VALUES ($1, $2)",
        parameters=[BigInt(123), Float32(12.1)]
    )
    result = await psql_pool.execute(
        "SELECT * FROM issue80",
    )
    # [{'id': 123, 'price': 12.1}]

Generally, the BIGSERIAL type is just a pseudo-type for BIGINT, so you must explicitly specify it. As for Float32 - by default any float value from Python is converted to FLOAT8 value, but Float(2) is FLAOT4 type.

paroxyste-0 commented 1 month ago

Thank you so much, it works perfectly !!!!