-
-
Notifications
You must be signed in to change notification settings - Fork 440
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
Support the ltree
data type
#389
Comments
|
The rust-postgres/tokio-postgres/src/proto/client.rs Lines 302 to 315 in d884298
The sixth argument ( |
I get hit for this too. I try to run a select and get: DbError { severity: \"ERROR\", parsed_severity: Some(Error), code: SqlState(\"42883\"), message: \"no binary output function available for type ltree\", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some(\"lsyscache.c\"), line: Some(2759), routine: Some(\"getTypeBinaryOutputInfo\") } I'm able to use it with other languages. A workaround is to cast with ::TEXT but this not work if is required to just run a sql directly (SELECT *...) like for making a REPL. |
Any thoughts on this. I am using ltree extensively, and it is forcing me to write pgpsql functions to handle the issue. A pain to optimize. |
The bug is still not fixed. As ad-hoc solution, you may try changing the https://www.postgresql.org/docs/12/sql-createtype.html#id-1.9.3.94.6
|
Any sample in how alter the type with the workaround? |
But after that I got another error:
|
I've got it working (mostly)! Cargo.toml [package]
name = "demo"
version = "0.1.0"
edition = "2018"
[dependencies]
postgres = "*"
postgres-types = "*"
postgres-protocol = "*" src/main.rs use postgres::{Client, NoTls};
use postgres_protocol::types;
use postgres_types::{FromSql, Type};
use std::error::Error;
struct Ltree<'a>(&'a str);
impl<'a> FromSql<'a> for Ltree<'a> {
fn from_sql(_: &Type, raw: &'a [u8]) -> Result<Ltree<'a>, Box<dyn Error + Sync + Send>> {
let t = types::text_from_sql(raw)?;
Ok(Ltree(t))
}
fn accepts(ty: &Type) -> bool {
ty.name() == "ltree"
}
}
fn main() {
let mut client = Client::connect("host=localhost user=postgres dbname=demo", NoTls).unwrap();
// create table t(p ltree);
for row in client.query("SELECT p FROM t", &[]).unwrap() {
let path: Ltree = row.get(0);
println!("{}", path.0); // BUG: dots missed here! Seems need to customize receive/send functions somehow
}
} |
Has almost same issue with columns in pg_catalog.pg_type table (and many functions in pg_catalog). Example
@sfackler Is acceptable to add to |
I've been thinking about doing something like that, yeah. On the On the |
According to patch notes ltree got binary support in postgres 13:
https://www.postgresql.org/docs/13/release-13.html So all that remains is to add the type for this to work? |
I've looked into taking this to the finish line and there are a couple issues, however I have a working prototype that I'll create a PR for soon.
|
@halfmatthalfcat I can confirm both points. See: https://github.com/LLFourn/olivia/blob/4d1181d995d9cb6bf15734b20593cc1d612e1d7d/olivia/src/db/postgres.rs#L36 for what you have to do as an application to use this as is. |
Looks like upgrading to postgres 13 fixed the binary output problem |
The result should be just
String
.https://www.postgresql.org/docs/9.1/ltree.html
The text was updated successfully, but these errors were encountered: