Fixed column expression bug

This commit is contained in:
Hein 2025-11-11 16:39:06 +02:00
parent 94f013c872
commit d9cf23b1dc
2 changed files with 3 additions and 3 deletions

View File

@ -200,7 +200,7 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
if len(options.ComputedColumns) > 0 { if len(options.ComputedColumns) > 0 {
for _, cu := range options.ComputedColumns { for _, cu := range options.ComputedColumns {
logger.Debug("Applying computed column: %s", cu.Name) logger.Debug("Applying computed column: %s", cu.Name)
query = query.ColumnExpr("(?) AS "+cu.Name, cu.Expression) query = query.ColumnExpr(fmt.Sprintf("(%s) AS %s", cu.Expression, cu.Name))
} }
} }

View File

@ -257,7 +257,7 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
if len(options.ComputedQL) > 0 { if len(options.ComputedQL) > 0 {
for colName, colExpr := range options.ComputedQL { for colName, colExpr := range options.ComputedQL {
logger.Debug("Applying computed column: %s", colName) logger.Debug("Applying computed column: %s", colName)
query = query.ColumnExpr("(?) AS "+colName, colExpr) query = query.ColumnExpr(fmt.Sprintf("(%s) AS %s", colExpr, colName))
for colIndex := range options.Columns { for colIndex := range options.Columns {
if options.Columns[colIndex] == colName { if options.Columns[colIndex] == colName {
// Remove the computed column from the selected columns to avoid duplication // Remove the computed column from the selected columns to avoid duplication
@ -271,7 +271,7 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
if len(options.ComputedColumns) > 0 { if len(options.ComputedColumns) > 0 {
for _, cu := range options.ComputedColumns { for _, cu := range options.ComputedColumns {
logger.Debug("Applying computed column: %s", cu.Name) logger.Debug("Applying computed column: %s", cu.Name)
query = query.ColumnExpr("(?) AS "+cu.Name, cu.Expression) query = query.ColumnExpr(fmt.Sprintf("(%s) AS %s", cu.Expression, cu.Name))
for colIndex := range options.Columns { for colIndex := range options.Columns {
if options.Columns[colIndex] == cu.Name { if options.Columns[colIndex] == cu.Name {
// Remove the computed column from the selected columns to avoid duplication // Remove the computed column from the selected columns to avoid duplication