diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f8ada225..4181805ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #2120, Fix reading database configuration properly when `=` is present in value - @wolfgangwalther - #1771, Fix silently ignoring filter on a non-existent embedded resource - @steve-chavez - #2135, Remove trigger functions from schema cache and OpenAPI output, because they can't be called directly anyway. - @wolfgangwalther + - #2101, Remove aggregates, procedures and window functions from the schema cache and OpenAPI output. - @wolfgangwalther - #2145, Fix accessing json array fields with -> and ->> in ?select= and ?order=. - @wolfgangwalther - #2153, Fix --dump-schema running with a wrong PG version. - @wolfgangwalther diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index a2d84fe22..14af71940 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -469,7 +469,7 @@ handleOpenApi headersOnly tSchema (RequestContext conf@AppConfig{..} dbStructure OAFollowPriv -> OpenAPI.encode conf dbStructure <$> SQL.statement tSchema (DbStructure.accessibleTables ctxPgVersion configDbPreparedStatements) - <*> SQL.statement tSchema (DbStructure.accessibleProcs configDbPreparedStatements) + <*> SQL.statement tSchema (DbStructure.accessibleProcs ctxPgVersion configDbPreparedStatements) <*> SQL.statement tSchema (DbStructure.schemaDescription configDbPreparedStatements) OAIgnorePriv -> OpenAPI.encode conf dbStructure diff --git a/src/PostgREST/DbStructure.hs b/src/PostgREST/DbStructure.hs index 44199a1ee..1caee31f9 100644 --- a/src/PostgREST/DbStructure.hs +++ b/src/PostgREST/DbStructure.hs @@ -42,7 +42,8 @@ import Data.Text (split) import Text.InterpolatedString.Perl6 (q) import PostgREST.Config.Database (pgVersionStatement) -import PostgREST.Config.PgVersion (PgVersion, pgVersion100) +import PostgREST.Config.PgVersion (PgVersion, pgVersion100, + pgVersion110) import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..), Schema, TableName) import PostgREST.DbStructure.Proc (PgType (..), @@ -93,7 +94,7 @@ queryDbStructure schemas extraSearchPath prepared = do srcCols <- SQL.statement (schemas, extraSearchPath) $ pfkSourceColumns cols prepared m2oRels <- SQL.statement mempty $ allM2ORels tabs cols prepared keys <- SQL.statement mempty $ allPrimaryKeys tabs prepared - procs <- SQL.statement schemas $ allProcs prepared + procs <- SQL.statement schemas $ allProcs pgVer prepared let rels = addO2MRels . addM2MRels $ addViewM2ORels srcCols m2oRels keys' = addViewPrimaryKeys srcCols keys @@ -226,18 +227,18 @@ decodeProcs = | v == 's' = Stable | otherwise = Volatile -- only 'v' can happen here -allProcs :: Bool -> SQL.Statement [Schema] ProcsMap -allProcs = SQL.Statement sql (arrayParam HE.text) decodeProcs +allProcs :: PgVersion -> Bool -> SQL.Statement [Schema] ProcsMap +allProcs pgVer = SQL.Statement sql (arrayParam HE.text) decodeProcs where - sql = procsSqlQuery <> " AND pn.nspname = ANY($1)" + sql = procsSqlQuery pgVer <> " AND pn.nspname = ANY($1)" -accessibleProcs :: Bool -> SQL.Statement Schema ProcsMap -accessibleProcs = SQL.Statement sql (param HE.text) decodeProcs +accessibleProcs :: PgVersion -> Bool -> SQL.Statement Schema ProcsMap +accessibleProcs pgVer = SQL.Statement sql (param HE.text) decodeProcs where - sql = procsSqlQuery <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')" + sql = procsSqlQuery pgVer <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')" -procsSqlQuery :: SqlQuery -procsSqlQuery = [q| +procsSqlQuery :: PgVersion -> SqlQuery +procsSqlQuery pgVer = [q| -- Recursively get the base types of domains WITH base_types AS ( @@ -300,7 +301,7 @@ procsSqlQuery = [q| LEFT JOIN pg_class comp ON comp.oid = t.typrelid LEFT JOIN pg_catalog.pg_description as d ON d.objoid = p.oid WHERE t.oid <> 'pg_catalog.trigger'::regtype -|] +|] <> (if pgVer >= pgVersion110 then "AND prokind = 'f'" else "AND NOT (proisagg OR proiswindow)") schemaDescription :: Bool -> SQL.Statement Schema (Maybe Text) schemaDescription = diff --git a/test/spec/fixtures/schema.sql b/test/spec/fixtures/schema.sql index eb25c6cc0..88a6d3b18 100644 --- a/test/spec/fixtures/schema.sql +++ b/test/spec/fixtures/schema.sql @@ -2427,3 +2427,21 @@ BEGIN END IF; END $do$; + +-- This procedure is to confirm that procedures don't show up in the OpenAPI output right now. +-- Procedures are not supported, yet. +do $do$begin + if (select current_setting('server_version_num')::int >= 110000) then + CREATE PROCEDURE test.unsupported_proc () + LANGUAGE SQL AS ''; + end if; +end $do$; + +CREATE FUNCTION public.dummy(int) RETURNS int +LANGUAGE SQL AS $$ SELECT 1 $$; + +-- This aggregate is to confirm that aggregates don't show up in the OpenAPI output. +CREATE AGGREGATE test.unsupported_agg (*) ( + SFUNC = public.dummy, + STYPE = int +);