postgresql - golang sql package: return INOUT from postgres procedure
问题描述
I am trying to get the value from an INOUT parameter into the invoking go code.
I see some discussion here about oracle drivers supporting this. However, I am using PostgreSQL, and I want to access my INOUT parameter.
I have a postgres procedure that has an INOUT parameter like so:
CREATE OR REPLACE PROCEDURE foo(INOUT my_variable text) LANGUAGE plpgsql ...
I am trying to get the variable by following the docs here. I am writing something like this
import "database/sql"
db, _ := sql.Open(...some connection...)
tx, err := db.Begin()
defer tx.Rollback()
var myVariable string
if _, err := tx.Exec(`call foo(?);`, sql.Named("my_variable", sql.Named("my_variable", sql.Out{Dest: &myVariable, In: true}))
This returns
sql: converting argument with name "my_variable" type: unsupported type sql.Out, a struct
Has anyone been able to make this work with PostgreSQL It seems like this should work, given that it is documented with the package. So, do the postgresql drivers not yet support this, or am I just missing some package import?
解决方案
推荐阅读
- oauth - Oath2 open Id connect - 如何用 access_token 交换 id_token
- python - Python3 导入
- javascript - 使用 c3.js 在带有组的图表中显示嵌套值
- greedy - 在 APL 中计算硬币
- android - Bouncycastle 在 android API < 21 中失败
- python - 如何在networkx / python中获得二分补图?
- regex - 用于在 ID 中捕获 4 个连续数字的正则表达式
- dos - SMBIOS - 结构表地址无效?
- java - 在 JAVA 中将 MSSQL DB 连接为不同的 Windows 用户
- google-cloud-dataflow - BeamSQL Group By查询浮点值问题