-
-
Notifications
You must be signed in to change notification settings - Fork 415
-
Hi folks, I have a problem, i need to count amount row in table and also get each row. So, i need a field to how amount rows and the rows as results.
My First question is: Can i use tag struct as expression function to override column at runtime? like that:
type Model struct{ tableName struct{} `pg:"hobbits"` Name string `pg:"name"` Rows int `pg:"count(0) over ()" }
Second question: exists a way ColumnExpr doesn't clear the select that is using columns of model?
db.Model(Model).ColumnExpr("count(0) over () as Rows").Select()
generates this:
SELECT count(0) over () as "Rows" FROM hobbits INSTEAD OF SELECT name, count(0) over () as "Rows" FROM hobbits
I know, i can use two queries to do that. But, i think this way it is more performant than two queries, in time question.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment