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

How to query Postgres TimestampTZ[], Enum and TSVector datatypes? #729

Closed
elasmojs opened this issue Oct 11, 2020 · 6 comments
Closed

How to query Postgres TimestampTZ[], Enum and TSVector datatypes? #729

elasmojs opened this issue Oct 11, 2020 · 6 comments

Comments

@elasmojs
Copy link

elasmojs commented Oct 11, 2020

Hi it would be great to have an example of which Rust data type is compatible with Postgres Numeric, Text[] and TSVector datatypes.

edit: I want to use "row.try_get" to retrieve the value of the column

let res:Result<BigDecimal, Error> = row.try_get(col.name.as_str());

throws compile error

the trait 'sqlx_core::decode::Decode<'_, sqlx_core::postgres::database::Postgres>' is not implemented for 'bigdecimal::BigDecimal'

thanks

@elasmojs
Copy link
Author

Have figured this out now, one has to use sqlx::types::BigDecimal instead of bigdecimal::BigDecimal, it would be great if there can be a note for the same in the documentation or an example.

Any help with the other data types Text[], TSVector and Enum would be greatly appreciated. Thanks

@elasmojs elasmojs changed the title Any example for querying Postgres Numeric, Text[] and TSVector datatypes How to query Postgres TimestampTZ[], Enum and TSVector datatypes? Oct 13, 2020
@elasmojs
Copy link
Author

elasmojs commented Oct 13, 2020

Have figured it out for arrays now, you need to use

let res:Result<Vec<YOUR_DATATYPE>, Error> = row.try_get(col.name.as_str());

This however does not work for TimestampTZ[] for the following code, it returns an error;

let res:Result<Vec<chrono::DateTime<chrono::Utc>, Error> = row.try_get(col.name.as_str());

mismatched types; Rust type 'alloc::vec::Vec<chrono::datetime::DateTime<chrono::offset::utc::Utc>>' (as SQL type TIMESTAMP[]) is not compatible with SQL type TIMESTAMPTZ[]

thanks

@abonander
Copy link
Collaborator

@elasmojs if you get an error about bigdecimal::BigDecimal not implementing Decode, then you have the wrong version of bigdecimal; make sure it's the same as in sqlx-core/Cargo.toml. However, it looks like you found the alternative of just using our reexport.

The issue with DateTime not decoding as TimestampTZ[] has been fixed as of 0.4.0-beta.1.

Support for TSVector is not yet implemented.

@elasmojs
Copy link
Author

@abonander thank you for the response. It really helps. I am closing this now.

@OutOfBoundCats
Copy link

@abonander Any idea when TSVector will be implemented for Postgres

@abonander
Copy link
Collaborator

Feel free to open a PR.

@launchbadge launchbadge locked as resolved and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants