Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What did this pull request do?
Add
MapColumns
method: modify the column names in the query results to facilitate align to the corresponding structural fieldsUser Case Description
I recently used gorm to do aggregation queries based on timescaledb. For example, the following query:
The result will be an error
ERROR: column "candle.t" must appear in the GROUP BY clause or be used in an aggregate function (SQLSTATE 42803)
.However, I cannot put
t
inGroup
, which will affect the correct result. So I tried usingdb = db.Group("symbol, time_bucket('5 minute', t, 'America/New_York')")
which unfortunately returns the same error.So I can only give up returning the
t
column in the result set, but then I need to customize a nested structure to supplement abucket
column, and then manually assign it toMarketCandle.T
. This is very inconvenient.So I added the
MapColumns
method. I think this may be a requirement that also exists in other scenarios, especially whenGROUP BY
is used.