-
-
Notifications
You must be signed in to change notification settings - Fork 415
Stored Procedure #1926
Answered
by
ganesh-karthick
ganesh-karthick
asked this question in
Q&A
Stored Procedure
#1926
-
Is it possible to get result of stored procedure via go pg? Example below, I would like to get to zoo
in result model
testdb=# SELECT public.foofunction('s1','s2') as SomeColumn;
SomeColumn
-------------------------------------------
zoo
(1 row)
Beta Was this translation helpful? Give feedback.
All reactions
Answered by
ganesh-karthick
Sep 17, 2021
This works
var SomeColumn []string
_, err = db.QueryOne(&SomeColumn, "SELECT foofunction(?,?) as SomeColumn", arg1,
arg2)
if err != nil {
return "",err
}
if len(SomeColumn) == 0 {
err == errors.New("empty rows")
return "",err
}
if len(SomeColumn[0]) == 0 {
err == errors.New("empty value")
return "",err
}
return SomeColumn[0],err
Replies: 1 comment
-
This works
var SomeColumn []string
_, err = db.QueryOne(&SomeColumn, "SELECT foofunction(?,?) as SomeColumn", arg1,
arg2)
if err != nil {
return "",err
}
if len(SomeColumn) == 0 {
err == errors.New("empty rows")
return "",err
}
if len(SomeColumn[0]) == 0 {
err == errors.New("empty value")
return "",err
}
return SomeColumn[0],err
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Answer selected by
ganesh-karthick
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment