-
Notifications
You must be signed in to change notification settings - Fork 803
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
Add pg_tables and pg_views to catalog #1748
Conversation
@kyleconroy I might need your help regenerating the files. I am having a heck-uva time.
|
Very strange error message. What os / arch are you on? |
I'm on an M1 Mac, arm64 I suppose. |
I added the env var, and get this next error message.
|
@kyleconroy given this commit fixed the build, I think it has something to do with the pure size of the data or number of tables in pg_catalog. I believe since all of a sudden there are tables in the |
@@ -36743,5 +36743,36 @@ func genPGCatalog() *catalog.Schema { | |||
}, | |||
}, | |||
} | |||
|
|||
s.Tables = []*catalog.Table{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just overwrote the Tables
slice to make the output purposefully smaller - just to debug.
I'm not sure what limit we're running into, but for the meantime let's drop the pg_catalog schema before sending it to the WASM plugin.
|
e2c0a75
to
f02d6c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied the fixes, and now there is just some other problems to address, particularly percentile_* functions seems to have changed, and I'm not sure why.
internal/tools/sqlc-pg-gen/main.go
Outdated
@@ -29,7 +29,37 @@ LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace | |||
WHERE n.nspname OPERATOR(pg_catalog.~) '^(pg_catalog)$' | |||
AND p.proargmodes IS NULL | |||
AND pg_function_is_visible(p.oid) | |||
ORDER BY 1; | |||
-- The order isn't too important - just that it is stable between runs | |||
ORDER BY 1, 2, 3, 4, 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kyleconroy These columns previously weren't ordered at all, so I think the existing output in pg_catalog.go is kind of in almost 'random' order. I ordered by basically every column here, not because it is important - but to keep the output stable between runs of sqlc-pg-gen
.
@@ -34,9 +31,21 @@ func Adminpack() *catalog.Schema { | |||
{ | |||
Type: &ast.TypeName{Name: "text"}, | |||
}, | |||
{ | |||
Type: &ast.TypeName{Name: "text"}, | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a reordering of the polymorphic variants of pg_file_rename
}, | ||
ReturnType: &ast.TypeName{Name: "boolean"}, | ||
}, | ||
{ | ||
Name: "pg_file_sync", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new, but appears to be correct.
https://www.postgresql.org/docs/13/adminpack.html
@@ -361,6 +352,15 @@ func Ltree() *catalog.Schema { | |||
}, | |||
ReturnType: &ast.TypeName{Name: "ltree"}, | |||
}, | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appears to be correct:
https://www.postgresql.org/docs/13/ltree.html#id-1.11.7.30.6
@@ -16544,12 +16993,27 @@ func genPGCatalog() *catalog.Schema { | |||
Args: []*catalog.Argument{}, | |||
ReturnType: &ast.TypeName{Name: "double precision"}, | |||
}, | |||
{ | |||
Name: "percentile_cont", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kyleconroy These functions seem to have been changed. I have no idea why.
}, | ||
{ | ||
Name: "percentile_disc", | ||
Args: []*catalog.Argument{ | ||
{ | ||
Type: &ast.TypeName{Name: "double precision[]"}, | ||
}, | ||
{ | ||
Type: &ast.TypeName{Name: "anyelement"}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function definition has changed, but I am not sure why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is because there are special functions which have "normal" arguments, and "aggregated group" arguments.
https://www.postgresql.org/docs/9.4/functions-aggregate.html#FUNCTIONS-ORDEREDSET-TABLE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, I ended up writing the SQL to distinguish between the 2 types of arguments, and it does indeed fix percentile_*
functions, but now the basic aggregates are failing. (MAX, SUM, etc).
I think there needs to be more work in the compiler to treat / lookup these functions differently based on the context in the query. So not sure where to go from here.
c873256
@skabbes Something is wrong with the updated pg-gen. We should be generating two functions for {
Name: "count",
Args: []*catalog.Argument{
{
Type: &ast.TypeName{Name: "any"},
},
},
ReturnType: &ast.TypeName{Name: "bigint"},
},
{
Name: "count",
Args: []*catalog.Argument{},
ReturnType: &ast.TypeName{Name: "bigint"},
}, And here's the new definition: {
Name: "count",
Args: []*catalog.Argument{},
ReturnType: &ast.TypeName{Name: "bigint"},
},
{
Name: "count",
Args: []*catalog.Argument{},
ReturnType: &ast.TypeName{Name: "bigint"},
}, We're missing the |
No, sorry I didn't explain well. routines in Postgres can be regular functions, procedures, aggregates, and window functions. https://www.postgresql.org/docs/current/catalog-pg-proc.html If it is an aggregate, there are 2 kinds of arguments, the "direct" arguments, and the "aggregate" arguments. Previously, sqlc did not differentiate between them, and classified all of them as "direct" arguments. Most aggregate functions that are used don't have any "direct" arguments at all, so it all kinda worked out just fine. However, You can see that you manually overrode the pg_catalog just to make that work in this commit. My commit did the work to differentiate between these direct and aggregate arguments to routines. So when I said:
What I meant was we need to make "looking up a function" (actually, a routine) smarter in the sqlc internals, before this can work. Either that, or re-apply the manual workaround you did from September 2021. The reality is that the function select percentile_disc(0.5) within group (order by authors.name) @kyleconroy I think looking forward for sqlc, it needs to differentiate between them. I'd be happy to put some work into making that a reality, but just wanted to check-in and make sure you agree that's the right path. |
I honestly forgot about the manual changes I made to
Yep, I think we're on the right path. That said, we're now fixing something unrelated to the original intent of this PR (aggregate functions vs PostgreSQL internal tables / views). I'd be happy to split this up if you'd like to get the tables and views in first, but it's up to you. |
I think this: Is the first step in actually making progress here. |
I islolated the pg_* fixes in this PR: I think the "aggreagated function args vs direct args" can / should be addressed independently. |
Agreed. Going to close this PR. |
Fixes: #1747
Problem - I was unable to write a query against pg_timezone_names.
Actual failing query
This because sqlc did not know about these built-in tables / views.
Warning
I tried to
make sqlc-pg-gen
andmake regen
, but I was getting slightly different output, so in this commit I only committed the changes that affected the tables, not the existing functions (which I do not know why they were changed, perhaps a different version of postgres).