Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How can i use ColumnExpr without it clears select command #1916

n0bode started this conversation in General
Discussion options

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.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /