Skip to content
Advertisement

Go sql return multiple row from Scan

I am using Postgresql database . Here is my code block where I want to return multiple rows:

Problem is its returning last row from the table. I also tried to store result in array, but I am not succeed.

Advertisement

Answer

You are setting same struct variable for every row that’s why you are getting last row info only.

Use results := []NewsPaper{} for create empty slice and create new struct for every row. This should work, I added some comments.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement