in Education by
I inserted in PostgreSQL table an UUID created with go.uuid : import ( "github.com/satori/go.uuid" ) func main() { usid := uuid.Must(uuid.NewV4()) fmt.Println("usid := uuid.Must(uuid.NewV4") fmt.Println(usid.String()) res, err := stmt.Exec(cn, csn, ccn, id) if err != nil || res == nil { log.Fatal(err) } } sStmt := "insert into basicuserinfo (cn, csn, ccn, appUserAccountID ) values ($1, $2, $3, $4)" stmt, err := db.Prepare(sStmt) if err != nil { log.Fatal(err) } defer stmt.Close() fmt.Println("# Inserting values") And actually a row is inserted in the postgreSQL db: cn | csn | ccn | id | 2412fcd3-8712-4a0f-830a-d77bd4cf2195 In order to query with golang variables I tried first, to use a prepared statement. First, using db.PrepareContext : sel := "SELECT appUserAccountID FROM basicuserinfo WHERE cn = $1 AND csn = $2 AND ccn = $3" stmt, err = db.PrepareContext(ctx,sel) if err != nil { log.Fatal(err) } var utenteID string err = stmt.QueryRowContext(ctx,cn, csn, ccn).Scan(&utenteID) log.Printf("ID= %s\n", utenteID) fmt.Println("aaaaaaaaa") // Just to check that the this line gets executed Whose execution remains "idle", in stand-by, without ending and producing any output: marco@pc01:~/go/marcoGolang/goPostgres$ go run pqExample00.go # Inserting values Then I tried in this way, with db.Prepare(): stmt, err = db.Prepare(sel) if err != nil { log.Fatal(err) } res, err = stmt.Exec(cnv, csnv, ccnv) In this second case the execution seems ending successfully, but I do not know how to convert the sql.Result into a correct form which can be handled, for example simply displayed with fmt.Println() or getting other handlings. So... how to correctly query and handle a UUID created with go.uuid and inserted into PostgreSQL 11? Looking forward to your kind help. Marco JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Unless you have a reason for using PrepareContext, you could just do this? db, err := sql.Open("postgres", connectionString) sel := "SELECT appUserAccountID FROM basicuserinfo WHERE cn = $1 AND csn = $2 AND ccn = $3" var idn string err = db.QueryRow(sel, cn, csn, ccn).Scan(&idn) if err != nil { log.Fatal(err) } fmt.Printf("idn: %v\n", idn)

Related questions

0 votes
    I inserted in PostgreSQL table an UUID created with go.uuid : import ( "github.com/satori/go.uuid" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    What is the most idiomatic way to handle multiple errors in go? Should I try to wrap the error ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I'm a bit stuck on this. Basically I want to do something like the following SQL query in LINQ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    Five node splitting operations occurred when an entry is inserted into a B-tree. Then how many nodes are written? a) 14 b) 7 c) 11 d) 5...
asked Dec 23, 2020 in Technology by JackTerrance
0 votes
    I have two different source structure tables, but I want to load into single target table? How do I go about it? Explain in detail through mapping flow....
asked Mar 28, 2021 by JackTerrance
0 votes
    Following query is perfectly working in mongo shell. db.collection.find({ "_id" : UUID("87aa9ed6-8485-4517 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
0 votes
    How is SQL query created in Hibernate?...
asked Apr 14, 2021 in Technology by JackTerrance
0 votes
    Use in xml this query searchCategory1=" SELECT "$1" FROM "$2" GROUP BY "$1" ORDER BY "$1"" but ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 6, 2022 in Education by JackTerrance
0 votes
    I was reading the great article about binding and unbinding events (because I am a js beginner using jQuery ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 9, 2022 in Education by JackTerrance
0 votes
    I was reading the great article about binding and unbinding events (because I am a js beginner using jQuery ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 8, 2022 in Education by JackTerrance
0 votes
    I was reading the great article about binding and unbinding events (because I am a js beginner using jQuery ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 8, 2022 in Education by JackTerrance
0 votes
    I was reading the great article about binding and unbinding events (because I am a js beginner using jQuery ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 6, 2022 in Education by JackTerrance
0 votes
    I was reading the great article about binding and unbinding events (because I am a js beginner using jQuery ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
...