postgrest-py icon indicating copy to clipboard operation
postgrest-py copied to clipboard

Can't cast columns

Open echelon-1-trade opened this issue 3 years ago • 3 comments
trafficstars

In the PostgRest documentation, it says to cast a column in query do something like...

GET /people?select=full_name,salary::text HTTP/1.1

It seems like this isn't a possibility in this wrapper, unless I am missing something.

echelon-1-trade avatar Jan 04 '22 01:01 echelon-1-trade

Can you provide an example of when this happens and the outpur you get and what you expected to get, please? 🙂

dreinon avatar Jan 04 '22 01:01 dreinon

Through the Python supabase client (which I believe leverages this package), I would do something like...

client.table("my_table").select("*").eq("col1::date", "2021-12-31")

I would expect this to cast column "col1" from its current dtype to a date type and then check the equality condition. The error message I get reflects that it looks for column "my_table"."col1::date" instead of "my_table"."col1"::date if that makes sense.

echelon-1-trade avatar Jan 06 '22 06:01 echelon-1-trade

Right, I get what you mean. Although I think you might be missunderstanding a bit how the client works.

For instance, postgrest-py, as client doesn't get all the records and then filters the data in python, but it actually requests the data filtered to the postgres db, therefore if the column is of type date, your example would work with no casting. I would understand the example if your column was of type text and you wanted to filter it as a date.

I also see this postgREST feature would work really well if you wanted to get a column of a type into a certain JSON compatible type. For instance, I have an int column I want to use in my app as text, therefore I could request the certain column casted as text instead of converting this column to text in all records.

What do you think? Thanks!

dreinon avatar Jan 08 '22 16:01 dreinon

This issue is over 2 years old with no replies. Closing this out.

silentworks avatar Mar 23 '24 13:03 silentworks