-
Notifications
You must be signed in to change notification settings - Fork 888
Add support for override of calculated column type #2183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Ignoring the issue of potentially having nulls in arrays, you can make sqlc use a given type by doing a type cast in your SQL:
this will give you a []string which according to #185 it should not do, because arrays can have NULLs. However, it seems your book titles can never be null anyway, because you have a not null on books.title, so that shouldn't be a problem. (if there is some instance where you need to filter out NULLs from your aggregate, you can probably use the btw I think array_agg() will be an empty array if there are no books, so it will never be NULL and you don't need the COALESCE:
|
Hi, I'm having similar issue - override my query looks like this: -- name: GetResultsRow :many
WITH best_lap_times AS (
SELECT
ss.best_lap_time,
ROW_NUMBER() OVER (PARTITION BY s.user_id ORDER BY ss.best_lap_time ASC) AS lap_rank
FROM session_statistics AS ss
JOIN user u ON u.id = ss.user_id
WHERE s.layout_id =$1
)
SELECT
best_lap_time
FROM best_lap_times
WHERE lap_rank = 1
ORDER BY best_lap_time ASC;
type GetResultsRow struct {
BestLapTime int64 `json:"best_lap_time"`
} sqlc.yaml looks like this, version: "2"
overrides:
go:
overrides:
- db_type: "interval"
engine: "postgresql"
go_type:
import: "github.com/jackc/pgtype"
package: "pgtype"
type: "Interval" and I have error during run code: |
For what it's worth, I'd like this as well: the ability to arbitrarily override the types of columns in queries. I frequently construct ad-hoc jsonb results to efficiently query for sets of data, and would love to shift the unmarshalling of these results deeper into the stack. |
Uh oh!
There was an error while loading. Please reload this page.
What do you want to change?
At this moment, overriding the calculated column type is not possible. For example, I have the following
query.sql
:Generated
query.sql.go
looks like the following:For the calculated
book_list
column I wanted to get[]sql.NullString
, but it is givinginterface{}
. This behavior is stated on#185 which is still an open issue.
It sounds a very hacky solution, but it can be solved by allowing type override of calculated columns as well. Something like this:
And I assume
sqlc
would figure out this is an array type from thearray_agg()
function name.What database engines need to be changed?
PostgreSQL
What programming language backends need to be changed?
Go
The text was updated successfully, but these errors were encountered: