Repository navigation
fix(introspection): expose columns of Postgres functions returning table rows - #693
Open
officialasishkumar wants to merge 1 commit into
Conversation
…ble rows Postgres functions that return rows of a table were not queryable through GraphJin. `RETURNS TABLE (LIKE users)` was discovered as a single output column named "like", so selecting any real column failed with "field 'id' is not a column or a function; available columns: like". `RETURNS SETOF users` and `RETURNS users` were discovered with no output columns at all and were not exposed. Function discovery read row columns from information_schema.attributes, which only lists standalone composite types, never the row types of tables, views or materialized views. Read them from pg_attribute through the return type's typrelid instead. This covers tables, views, materialized views, foreign and partitioned tables and composite types, skips dropped columns, and reports column types with format_type like table discovery does. The single OUT parameter that holds the whole row is no longer reported as a column, because Postgres expands it into the row's columns. Enum and domain outputs keep their existing behaviour. Function output columns now also carry the array flag and honour the configured blocklist, so table columns such as passwords stay blocked when a function returns the same row. Function parameters with array types now use the same `[Type]` list syntax as table columns in the generated schema DDL, and the DDL parser reads it back; `Text[]` was not valid DDL and broke loading db.ddl with enable_schema. Fixes dosco#424
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #424.
Postgres functions that return rows of a table could not be queried.
RETURNS TABLE (LIKE users)was discovered as one output column namedlike, so selecting a real column failed withfield 'id' is not a column or a function; available columns: like.RETURNS SETOF usersandRETURNS userswere discovered with no output columns and were not exposed at all.The cause is in function discovery: row columns came from
information_schema.attributes, which only lists standalone composite types (CREATE TYPE ... AS (...)), never the row type of a table or view.Changes
postgres_functions.sqlreads row columns frompg_attributethrough the return type'styprelid. It covers tables, views, materialized views, foreign and partitioned tables and composite types, skips dropped columns, and usesformat_typefor column types, as table discovery does. The single OUT parameter that holds the whole row (thelikecolumn above) is not reported, because Postgres expands it into the row's columns. Enum and domainRETURNS TABLEoutputs behave as before.containswork ontext[]columns) and honour the configured blocklist. A function returningusersno longer bypasses a blocklist entry such aspassword.[Type]syntax as table columns, and the DDL parser reads them back. The oldText[]output was not valid DDL. It never showed up before because Postgres reported array parameters asARRAY. With real types it broke reloadingdb.ddlunderenable_schema(TestEnableSchema).Function names in the blocklist still decide whether a function is exposed. The function's return type does not, which matches how
RETURNS TABLE (...)functions already work.Tests
tests/postgres.sqladdsget_users_up_to(RETURNS TABLE (LIKE users)),get_products_up_to(RETURNS SETOF products) andget_user_row(RETURNS users).tests/query_pg_test.gocover each form, including an arraycontainsfilter and a blocklisted column. They fail on master and pass with this change.TestNewDBInfoFunctionOutputColumns(blocklist and array flag) andTestCreateSchemaFunctionArrayParams(DDL round trip).testssuite with-db=postgreson Postgres 15, before and after the change. The only new results are the four new examples passing. The geo tests fail in both runs because my local database had no PostGIS. I also ran the function examples andTestEnableSchemaon Postgres 12, plus thecore,sdata,qcode,introspectionandpsqlpackages.