sfackler/rust-postgres-array

How to parse from string?

ronanyeah opened this issue · 2 comments

Is there a way to use this crate to parse the string result back into an array of values?

I'm currently using the sqlparser crate to do it but wondering if there is an easier way.

fn hs_decode(val: &str) -> Option<HashSet<String>> {
    let ast = sqlparser::tokenizer::Tokenizer::new(&GenericDialect, val)
        .tokenize()
        .ok()?;

    let results = sqlparser::parser::Parser::new(ast, &GenericDialect)
        .parse_identifiers()
        .ok()?;

    Some(results.iter().map(|x| x.value.clone()).collect())
}

There is not. This crate uses the Postgres binary protocol, not the text protocol.

Ok thanks.