5

I was working on a golang project, I've used a postgres database to store data with some Stored Procedure.

I used github.com/jinzhu/gorm for connecting to the database.

I used below query to retrieve data. I know in postgres we are unable to use select, so I only tried insert code in SP.

db.Database.Raw("CALL mydatabase.mystoredprocedure('" + param1 + "','" + param2 + "')")

db.Database.Raw("SELECT * FROM table1").Scan(&tableValue)

But here I'm only able to call a SELECT statement, not able to call the stored procedure.

Please, can any one help me to solve this problem?

Thanks in advance

1
  • 1
    Try using functions instead of procedures because functions can be invoked with SELECT. Also your procedure call is subject to sql injection, you might want to be more careful. Commented Sep 5, 2020 at 10:20

1 Answer 1

11

db.Database.Raw(...) alone does not do anything, it needs to be chained with Scan. If you are not expecting any results, use Exec:

db.Database.Exec("CALL mydatabase.mystoredprocedure($1, $2)", param1, param2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.