CREATE AGGREGATE extsum(integer) (
   SFUNC = int4_sum,
   STYPE = bigint,
   COMBINEFUNC = int8pl,
   MSFUNC = int4_avg_accum,
   MINVFUNC = int4_avg_accum_inv,
   MFINALFUNC = int2int4_sum,
   MSTYPE = bigint[],
   MINITCOND = '{0,0}'
);

GRANT EXECUTE ON FUNCTION extsum(integer) TO pg_read_all_stats;

CREATE COLLATION extcoll (PROVIDER = libc, LOCALE = 'C');

CREATE CONVERSION extconv FOR 'WIN1252' TO 'UTF8' FROM win_to_utf8;

CREATE DOMAIN exttext AS text NOT NULL;

GRANT USAGE ON TYPE exttext TO pg_read_all_stats;

CREATE FUNCTION extet() RETURNS event_trigger LANGUAGE plpgsql AS 'BEGIN NULL; END;';

GRANT EXECUTE ON FUNCTION extet() TO pg_read_all_stats;

CREATE EVENT TRIGGER extet ON ddl_command_start EXECUTE FUNCTION extet();

CREATE FUNCTION extfdw_handler() RETURNS fdw_handler LANGUAGE c STRICT AS '$libdir/postgres_fdw', 'postgres_fdw_validator';
CREATE FUNCTION extfdw_validator(text[], oid) RETURNS void LANGUAGE c STRICT AS '$libdir/postgres_fdw', 'postgres_fdw_validator';

CREATE FOREIGN DATA WRAPPER extfdw HANDLER extfdw_handler VALIDATOR extfdw_validator;

GRANT USAGE ON FOREIGN DATA WRAPPER extfdw TO pg_read_all_stats;

CREATE SERVER extsrv FOREIGN DATA WRAPPER extfdw OPTIONS (dbname 'quaxi');

GRANT USAGE ON FOREIGN SERVER extsrv TO pg_read_all_stats;

CREATE FOREIGN TABLE extftab (id integer) SERVER extsrv OPTIONS (table_name 'quaxi');

GRANT SELECT ON extftab TO PUBLIC;

CREATE TABLE exttab (a integer PRIMARY KEY);

CREATE STATISTICS extstat ON (a + 1) FROM exttab;

GRANT SELECT ON exttab TO PUBLIC;
GRANT UPDATE (a) ON exttab TO pg_read_all_stats;

INSERT INTO exttab VALUES (1), (2), (3);

SELECT pg_catalog.pg_extension_config_dump('exttab', 'WHERE a < 10');

CREATE FUNCTION ext_handler() RETURNS language_handler LANGUAGE c AS '$libdir/plpgsql', 'plpgsql_call_handler';
CREATE FUNCTION ext_inline_handler(internal) RETURNS void LANGUAGE c STRICT AS '$libdir/plpgsql', 'plpgsql_inline_handler';
CREATE FUNCTION ext_validator(oid) RETURNS void LANGUAGE c STRICT AS '$libdir/plpgsql', 'plpgsql_validator';

CREATE TRUSTED LANGUAGE extpl HANDLER ext_handler INLINE ext_inline_handler VALIDATOR ext_validator;

GRANT USAGE ON LANGUAGE extpl TO pg_read_all_stats;

CREATE MATERIALIZED VIEW extmv AS SELECT 42 AS col;

GRANT SELECT ON extmv TO PUBLIC;

CREATE TYPE exttype;

CREATE FUNCTION exttypein(cstring) RETURNS exttype LANGUAGE INTERNAL IMMUTABLE PARALLEL SAFE AS 'int4in';

CREATE FUNCTION exttypeout(exttype) RETURNS cstring LANGUAGE INTERNAL IMMUTABLE PARALLEL SAFE AS 'int4out';

CREATE TYPE exttype (INPUT = exttypein, OUTPUT = exttypeout);

CREATE FUNCTION exttypeeq(exttype, exttype) RETURNS boolean IMMUTABLE PARALLEL SAFE LANGUAGE INTERNAL AS 'int4eq';
CREATE OPERATOR === (LEFTARG = exttype, RIGHTARG = exttype, FUNCTION = exttypeeq);
CREATE FUNCTION exttypelt(exttype, exttype) RETURNS boolean IMMUTABLE PARALLEL SAFE LANGUAGE INTERNAL AS 'int4lt';
CREATE OPERATOR <<< (LEFTARG = exttype, RIGHTARG = exttype, FUNCTION = exttypelt);
CREATE FUNCTION exttypele(exttype, exttype) RETURNS boolean IMMUTABLE PARALLEL SAFE LANGUAGE INTERNAL AS 'int4le';
CREATE OPERATOR <<<= (LEFTARG = exttype, RIGHTARG = exttype, FUNCTION = exttypele);
CREATE FUNCTION exttypege(exttype, exttype) RETURNS boolean IMMUTABLE PARALLEL SAFE LANGUAGE INTERNAL AS 'int4ge';
CREATE OPERATOR >>>= (LEFTARG = exttype, RIGHTARG = exttype, FUNCTION = exttypege);
CREATE FUNCTION exttypegt(exttype, exttype) RETURNS boolean IMMUTABLE PARALLEL SAFE LANGUAGE INTERNAL AS 'int4gt';
CREATE OPERATOR >>> (LEFTARG = exttype, RIGHTARG = exttype, FUNCTION = exttypegt);
CREATE FUNCTION btexttypecmp(exttype, exttype) RETURNS integer LANGUAGE INTERNAL AS 'btint4cmp';

GRANT USAGE ON TYPE exttype TO pg_read_all_stats;

CREATE OPERATOR FAMILY extfam USING btree;

CREATE OPERATOR CLASS extclass DEFAULT FOR TYPE exttype USING btree FAMILY extfam AS
   OPERATOR 1 <<<(exttype,exttype),
   OPERATOR 2 <<<=(exttype,exttype),
   OPERATOR 3 ===(exttype,exttype),
   OPERATOR 4 >>>=(exttype,exttype),
   OPERATOR 5 >>>(exttype,exttype),
   FUNCTION 1 btexttypecmp(exttype, exttype);

CREATE SCHEMA extschema;

GRANT USAGE ON SCHEMA extschema TO PUBLIC;

CREATE SEQUENCE extseq;

GRANT USAGE ON SEQUENCE extseq TO PUBLIC;

CREATE TEXT SEARCH CONFIGURATION extconf (COPY = simple);

CREATE VIEW extview AS SELECT 42 AS col;

GRANT INSERT ON extview TO PUBLIC;
