Thanks Ian, I will take your advice and use another approach, I regret this cuz it would be nice to have something already working.
Without any intent to offense or say something hard, as a client of the library it kind looks quite buggy, the parenthesis are still an issue <https://go.dev/play/p/D2vpPLT4Bz3> disregarding that the values are actually space-delimited. The error messages clearly are an invitation to see the source for deeper understanding rather than given any clues. Greetings V El mar, 25 ene 2022 a las 16:42, Ian Lance Taylor (<i...@golang.org>) escribió: > On Tue, Jan 25, 2022 at 11:35 AM Victor Giordano <vitucho3...@gmail.com> > wrote: > > > > Hi all! I'm dealing with some multi valued column in postgres, and i > have stomp into a bizzare behavoir in `fmt.Sscanf` > > > > Please take a look at the following snippet, i also leave my question > within the code and this link to the playground so you can actually try it > and see with you own eyes. > > > > ``` > > package main > > > > import "fmt" > > > > func main() { > > var a int > > var b string > > input := "(1,beto)" // doesn't like the parenthesis > > > > _, err := fmt.Sscanf(input, "(%d,%s)", &a, &b) > > if err != nil { > > fmt.Println(err) > > } else { > > fmt.Println(a, b) > > } > > > > input = "1,beto" // this works > > _, err = fmt.Sscanf(input, "%d,%s", &a, &b) > > if err != nil { > > fmt.Println(err) > > } else { > > fmt.Println(a, b) > > } > > > > input = "beto,1" // doesn't like an string at first place, > ¿¿WHAT i do?!?! > > _, err = fmt.Sscanf(input, "%s,%d", &b, &a) > > if err != nil { > > fmt.Println(err) > > } else { > > fmt.Println(a, b) > > } > > } > > ``` > > > Using %s in fmt.Sscanf will read all characters up to a space or > newline. This is documented at https://pkg.go.dev/fmt which says > "Input processed by verbs is implicitly space-delimited: the > implementation of every verb except %c starts by discarding leading > spaces from the remaining input, and the %s verb (and %v reading into > a string) stops consuming input at the first space or newline > character." > > Basically fmt.Sscanf is not the right tool for the problem you are > trying to solve. > > Ian > -- V -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAPUu9susZmAhoCBMi%2BVNkztM3AJB6H2dy5%2BxmSVOYbY6%3DNKcTg%40mail.gmail.com.