goqu
goqu copied to clipboard
How to SELECT "col" IS NOT NULL AS "alias" ?
Is there a way to alias a boolean expression in the select column list?
I think what I want is basically:
db.From("foo").Select(goqu.I("foo.bar").IsNotNull().As("have_bar")
But type exp.BooleanExpression does not implement As(). I can work around it using a functional expression. This generates the correct SQL, though with extra parenthesis:
Select(goqu.Func("", goqu.I("foo.bar").IsNotNull()).As("have_bar"))
...but I'm hoping there's prettier way that doesn't involve abusing Func()
...
@makholm hi, try this
goqu.From("foo").Select(
goqu.L(`foo.bar IS NOT NULL`).As("some_field"),
)