Hi, I am working on project where I connect through PostgreSQL for CRUD
operations and in back end I use golang.
For transaction handling , I was using simple transaction objects for
handling db operations as -
*tx, err := db.Begin()*
* handleError(ctx,err)*
* data, err := tx.Query(sqlStmt,
val[ie])*
* handleError(ctx,tx.Commit())*
As I have to execute multiple sql statements in same function for multiple
db operations like --
sqlStmt1 := `INSERT INTO
rules3(name,threshold,rule_condition,base_sql,cron,email_subject,chartio_url,rule_owner,expiration_date)
select
name,threshold,rule_condition,base_sql,cron,email_subject,chartio_url,rule_owner,expiration_date
from rules3 where id in ($1) returning id`
data1, err := tx.Query(sqlStmt1 ,val[ie])
var cloneid int64
for cldata.Next(){
cldata.Scan(&cloneid)
log.Infof(ctx,"id returning from clone query is:%d ",cloneid)
}
sqlStmt2 := fmt.Sprint("update rules3 set name = (CASE WHEN length(name) >
58 THEN replace(name,right(name,5),'_copy') ELSE concat(name,'_copy') END),
is_active = false where id in (",cloneid,");")
data2, err := tx.Query(sqlStmt2 )
sqlStmt3 := `INSERT INTO rulesuserassoc3(rule_id, user_id) SELECT (SELECT
A.id FROM rules3 A WHERE A.id in ($1)), B.user_id FROM rulesuserassoc3 B
WHERE B.rule_id in ($2)`
data3, err := tx.Query(sqlStmt3 ,cloneid,val[ie])
Problem is when I hit url of that function in postman, I get weird error ---*
"pq:
unexpected Parse response 'C'"*
I don't know what I am doing wrong in my code for which I get above error
and how to resolve this.
your help is much appreciated.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.