Question: Write the DDL statement from PostgreSQL regression test 'copydml' (example 22).

create rule qqq as on insert to copydml_test do instead (delete from copydml_test; delete from copydml_test);

Explanation: DDL from PostgreSQL core regression test for Copydml.


Question: Write the DDL statement from PostgreSQL regression test 'create_index_spgist' (example 11).

CREATE INDEX sp_radix_ind ON radix_text_tbl USING spgist (t);

Explanation: DDL from PostgreSQL core regression test for Create Index Spgist.


Question: PostgreSQL Typeconv: show example 1.

SELECT text 'Origin' AS "label", point '(0,0)' AS "value"; label | value --------+------- Origin | (0,0) (1 row);

Explanation: Example from PostgreSQL documentation on Typeconv.


Question: pgTAP test for Pgtap--1.1.0--1.2.0 (assertion 79).

-- is_window( function )
CREATE OR REPLACE FUNCTION is_window( NAME )
RETURNS TEXT AS $$
    SELECT _func_compare(
        NULL, $1, _type_func('w', $1),
        'Function ' || quote_ident($1) || '() should be a window function'
    );
$$ LANGUAGE sql;

Explanation: SQL assertion from pgTAP test suite for Pgtap--1.1.0--1.2.0.


Question: Show a query using PostgreSQL contrib extension 'sepgsql' (example 82).

SELECT f5('unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0:c0.c3');	-- OK
SELECT sepgsql_getcon();

Explanation: Example query from the 'sepgsql' extension test/demo.


Question: PostgreSQL regression test 'encoding': Write the SELECT query (example 21).

SELECT substring(with_nul, 3, 1) FROM regress_encoding;

Explanation: Regression test for Encoding in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT substring(with_nul, 3, 1) FROM regress_encoding) AS _sub;


Question: Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 1).

/* contrib/pg_prewarm/pg_prewarm--1.1--1.2.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pg_prewarm UPDATE TO '1.2'" to load this file. \quit

CREATE FUNCTION autoprewarm_start_worker()
RETURNS VOID STRICT
AS 'MODULE_PATHNAME', 'autoprewarm_start_worker'
LANGUAGE C;

Explanation: SQL definition from the 'contrib' PostgreSQL contrib extension.


Question: PostgreSQL regression test 'interval': Write the SELECT query (example 368).

SELECT timetz '11:27:42' + interval '-infinity';

Explanation: Regression test for Interval in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT timetz '11:27:42' + interval '-infinity') AS _sub;


Question: Show a query using PostgreSQL contrib extension 'earthdistance' (example 19).

Explanation: Example query from the 'earthdistance' extension test/demo.


Question: Show a SQL definition from the zombodb project (_cat-api, item 12).

CREATE OR REPLACE VIEW zdb.cat_pending_tasks AS
SELECT
    url,
    (response->>'insertOrder')::int AS "insertOrder",
    ((response->>'timeInQueue')||' milliseconds')::interval AS "timeInQueue",
    (response->>'priority') AS "priority",
    (response->>'source') AS "source"
FROM zdb._all_indices_cat_request('pending_tasks');

Explanation: SQL definition from the open-source zombodb PostgreSQL project.


Question: Show a query using PostgreSQL contrib extension 'dict_int' (example 25).

Explanation: Example query from the 'dict_int' extension test/demo.


Question: Show a SQL definition from the postgrest project (jsonschema, item 10).

CREATE OR REPLACE FUNCTION test.validate_json_schema(schema jsonb, data jsonb, root_schema jsonb DEFAULT NULL) RETURNS boolean AS $f$
DECLARE
  prop text;

Explanation: SQL definition from the open-source postgrest PostgreSQL project.


Question: Write the DDL statement from PostgreSQL regression test 'polymorphism' (example 51).

create function polyf(anymultirange) returns anyrange
as 'select range_merge($1);' language sql;

Explanation: DDL from PostgreSQL core regression test for Polymorphism.


Question: pgTAP test for Resultset (assertion 193).

INSERT INTO names (name) VALUES ('Gracie');

Explanation: SQL assertion from pgTAP test suite for Resultset.


Question: Write the DML statement from PostgreSQL regression test 'rules' (example 299).

Explanation: DML from PostgreSQL core regression test for Rules.


Question: PostgreSQL regression test 'merge': Write the SELECT query (example 374).

SELECT * FROM pa_target ORDER BY tid, val;

Explanation: Regression test for Merge in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT * FROM pa_target ORDER BY tid, val) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'amcheck' (example 11).

SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'All-Visible');

Explanation: Example query from the 'amcheck' extension test/demo.


Question: Write the DML statement from PostgreSQL regression test 'numeric_big' (example 290).

Explanation: DML from PostgreSQL core regression test for Numeric Big.


Question: Show a SQL definition from the pg_partman project (pg_partman--2.3.1--2.3.2, item 8).

CREATE FUNCTION show_partition_info(p_child_table text
    , p_partition_interval text DEFAULT NULL
    , p_parent_table text DEFAULT NULL
    , OUT child_start_time timestamp
    , OUT child_end_time timestamp
    , OUT child_start_id bigint
    , OUT child_end_id bigint
    , OUT suffix text)
RETURNS record
    LANGUAGE plpgsql SECURITY DEFINER
    AS $$
DECLARE

v_child_schema          text;
v_child_tablename       text;
v_datetime_string       text;
v_parent_table          text;
v_partition_interval    text;
v_partition_type        text;
v_quarter               text;
v_suffix                text;
v_suffix_position       int;
v_year                  text;

BEGIN

SELECT schemaname, tablename INTO v_child_schema, v_child_tablename
FROM pg_catalog.pg_tables
WHERE schemaname = split_part(p_child_table, '.', 1)
AND tablename = split_part(p_child_table, '.', 2);
IF v_child_tablename IS NULL THEN
    RAISE EXCEPTION 'Child table given does not exist (%)', p_child_table;
END IF;

IF p_parent_table IS NULL THEN
    SELECT n.nspname||'.'|| c.relname INTO v_parent_table
    FROM pg_catalog.pg_inherits h
    JOIN pg_catalog.pg_class c ON c.oid = h.inhparent
    JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
    WHERE h.inhrelid::regclass = p_child_table::regclass;
ELSE
    v_parent_table := p_parent_table;
END IF;

IF p_partition_interval IS NULL THEN
    SELECT partition_interval, partition_type, datetime_string INTO v_partition_interval, v_partition_type, v_datetime_string
    FROM @extschema@.part_config WHERE parent_table = v_parent_table;
ELSE
    v_partition_interval := p_partition_interval;
    SELECT partition_type, datetime_string INTO v_partition_type, v_datetime_string
    FROM @extschema@.part_config WHERE parent_table = v_parent_table;
END IF;

IF v_partition_type IS NULL THEN
    RAISE EXCEPTION 'Parent table of given child not managed by pg_partman: %', v_parent_table;
END IF;

v_suffix_position := (length(v_child_tablename) - position('p_' in reverse(v_child_tablename))) + 2;
v_suffix := substring(v_child_tablename from v_suffix_position);

IF v_partition_type = 'time' OR v_partition_type = 'time-custom' THEN

        IF v_partition_interval::interval <> '3 months' OR (v_partition_interval::interval = '3 months' AND v_partition_type = 'time-custom') THEN
           child_start_time := to_timestamp(v_suffix, v_datetime_string);
        ELSE
            -- to_timestamp doesn't recognize 'Q' date string formater. Handle it
            v_year := split_part(v_suffix, 'q', 1);
            v_quarter := split_part(v_suffix, 'q', 2);
            CASE
                WHEN v_quarter = '1' THEN
                    child_start_time := to_timestamp(v_year || '-01-01', 'YYYY-MM-DD');
                WHEN v_quarter = '2' THEN
                    child_start_time := to_timestamp(v_year || '-04-01', 'YYYY-MM-DD');
                WHEN v_quarter = '3' THEN
                    child_start_time := to_timestamp(v_year || '-07-01', 'YYYY-MM-DD');
                WHEN v_quarter = '4' THEN
                    child_start_time := to_timestamp(v_year || '-10-01', 'YYYY-MM-DD');
            END CASE;
        END IF;

        child_end_time := (child_start_time + v_partition_interval::interval) - '1 second'::interval;

ELSIF v_partition_type = 'id' THEN

    child_start_id := v_suffix::bigint;
    child_end_id := (child_start_id + v_partition_interval::bigint) - 1;

ELSE
    RAISE EXCEPTION 'Invalid partition type encountered in show_partition_info()';
END IF;

suffix = v_suffix;

RETURN;

END
$$;

Explanation: SQL definition from the open-source pg_partman PostgreSQL project.


Question: Write the DDL statement from PostgreSQL regression test 'partition_join' (example 382).

CREATE TABLE plt2_adv (a int, b int, c text) PARTITION BY LIST (c);

Explanation: DDL from PostgreSQL core regression test for Partition Join.


Question: Write the DDL statement from PostgreSQL regression test 'drop_operator' (example 2).

CREATE OPERATOR !== (
        PROCEDURE = int8ne,
        LEFTARG = bigint,
        RIGHTARG = bigint,
        NEGATOR = ===,
        COMMUTATOR = !==
);

Explanation: DDL from PostgreSQL core regression test for Drop Operator.


Question: Write the PL/pgSQL object from PostgreSQL regression test 'rangefuncs' (example 59).

-- nested functions
select rngfunct.rngfuncid, rngfunct.f2 from rngfunct(sin(pi()/2)::int) ORDER BY 1,2;

Explanation: PL/pgSQL object from PostgreSQL core test for Rangefuncs.


Question: Show a query using PostgreSQL contrib extension 'jsonb_plpython' (example 34).

Explanation: Example query from the 'jsonb_plpython' extension test/demo.


Question: PL/pgSQL test: Pltcl Setup (example 1).

create table T_comp1 (
    tkey	char(10),
    ref1	int4,
    ref2	char(20)
);

Explanation: PL/pgSQL example from PostgreSQL source test for Pltcl Setup.


Question: PL/pgSQL test: Plpython Composite (example 6).

CREATE FUNCTION multiout_simple_setof(n integer = 1, OUT integer, OUT integer) RETURNS SETOF record AS $$
return [(1, 2)] * n
$$ LANGUAGE plpython3u;

Explanation: PL/pgSQL example from PostgreSQL source test for Plpython Composite.


Question: PostgreSQL regression test 'sqljson': Write the SELECT query (example 207).

SELECT JSON_ARRAYAGG(('111' || i)::bytea FORMAT JSON NULL ON NULL RETURNING varchar(2)) FROM generate_series(1,1) i;

Explanation: Regression test for Sqljson in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT JSON_ARRAYAGG(('111' || i)::bytea FORMAT JSON NULL ON NULL RETURNING varchar(2)) FROM generate_series(1,1) i) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'interval' (example 50).

CREATE INDEX ON INTERVAL_TBL_OF USING btree (f1);

Explanation: DDL from PostgreSQL core regression test for Interval.


Question: Write the DDL statement from PostgreSQL regression test 'rangetypes' (example 138).

create index textrange_test_btree on textrange_test(tr);

Explanation: DDL from PostgreSQL core regression test for Rangetypes.


Question: Show a SQL definition from the zombodb project (issue-739, item 2).

CREATE TABLE testwith_vol
(
    id   SERIAL8 NOT NULL PRIMARY KEY,
    data json
);

Explanation: SQL definition from the open-source zombodb PostgreSQL project.


Question: pgTAP test for Enumtap (assertion 21).

SELECT * FROM check_test(
    hasnt_enum( 'public', 'bug_status', 'mydesc' ),
    false,
    'hasnt_enum(schema, enum, desc)',
    'mydesc',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Enumtap.


Question: pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 468).

ALTER EXTENSION pgtap ADD FUNCTION _is_instead( NAME, NAME );

Explanation: SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.


Question: Show a query using PostgreSQL contrib extension 'btree_gin' (example 3).

Explanation: Example query from the 'btree_gin' extension test/demo.


Question: Write the SQL definition from PostgreSQL contrib extension 'hstore_plperl' (item 5).

CREATE FUNCTION test1none(val hstore) RETURNS int
LANGUAGE plperlu
AS $$
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 0;
elog(INFO, Dumper($_[0]));
return scalar(keys %{$_[0]});
$$;

Explanation: SQL definition from the 'hstore_plperl' PostgreSQL contrib extension.


Question: Write the DDL statement from PostgreSQL regression test 'join' (example 454).

CREATE TEMP TABLE b (id int PRIMARY KEY, c_id int);

Explanation: DDL from PostgreSQL core regression test for Join.


Question: pgTAP test for Resultset (assertion 250).

SELECT * FROM check_test(
    bag_eq(
        'anames',
        'SELECT id, name FROM annames WHERE name NOT IN (''Anna'', ''Angelina'')'
    ),
    false,
    'bag_eq(prepared, select) fail extras',
    '',
    '    Extra records:
        [(](44,Anna|86,Angelina)[)]
        [(](44,Anna|86,Angelina)[)]',
    true
);

Explanation: SQL assertion from pgTAP test suite for Resultset.


Question: Write the DML statement from PostgreSQL regression test 'join' (example 93).

Explanation: DML from PostgreSQL core regression test for Join.


Question: PostgreSQL regression test 'tsdicts': Write the SELECT query (example 69).

Explanation: Regression test for Tsdicts in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT ts_lexize('hunspell_num', 'footballyklubber')) AS _sub;


Question: PostgreSQL regression test 'jsonb': Write the SELECT query (example 111).

Explanation: Regression test for Jsonb in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT * FROM jsonb_each('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}'::jsonb) AS q) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'polymorphism' (example 136).

Explanation: DML from PostgreSQL core regression test for Polymorphism.


Question: PostgreSQL regression test 'int4': Write the SELECT query (example 78).

Explanation: Regression test for Int4 in PostgreSQL core test suite.


Question: pgTAP test for Hastap (assertion 42).

SELECT * FROM check_test(
    hasnt_table( 'foo', '__SDFSDFD__', 'desc' ),
    true,
    'hasnt_table(sch, non-existent tab, desc)',
    'desc',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


Question: PostgreSQL Indices: show example 4.

CREATE INDEX name ON table USING HASH ( column );

Explanation: Example from PostgreSQL documentation on Indices.


Question: PostgreSQL regression test 'xid': Write the SELECT query (example 25).

Explanation: Regression test for Xid in PostgreSQL core test suite.


Question: PostgreSQL regression test 'partition_merge': Write the SELECT query (example 351).

Explanation: Regression test for Partition Merge in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT i FROM t ORDER BY i) AS _sub;


Question: PostgreSQL regression test 'pg_ndistinct': Write the SELECT query (example 39).

SELECT '[{"attributes" : [2,3], "ndistinct" : "a"}]'::pg_ndistinct;

Explanation: Regression test for Pg Ndistinct in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT '[{"attributes" : [2,3], "ndistinct" : "a"}]'::pg_ndistinct) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'btree_gist' (example 5).

SELECT count(*) FROM timestamptmp WHERE a  = '2004-10-26 08:55:08';

Explanation: Example query from the 'btree_gist' extension test/demo.


Question: Write the DML statement from PostgreSQL regression test 'numeric' (example 583).

INSERT INTO fract_only VALUES (1, '0.0');

Explanation: DML from PostgreSQL core regression test for Numeric.


Question: PostgreSQL regression test 'rangefuncs': Write the SELECT query (example 283).

select * from array_to_set(array['one', 'two']) as t(f1 point,f2 text);

Explanation: Regression test for Rangefuncs in PostgreSQL core test suite.

SELECT count(*) FROM (select * from array_to_set(array['one', 'two']) as t(f1 point,f2 text)) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'create_misc' (example 18).

INSERT INTO d_star (class, a, b, c, d)
   VALUES ('d', 7, 'grumble'::text, 'hi sunita'::name, '0.0'::float8);

Explanation: DML from PostgreSQL core regression test for Create Misc.


Question: pgTAP test for Functap (assertion 309).

SELECT * FROM check_test(
    isnt_window( 'dense_rank', '{}'::name[] ),
    false,
    'isnt_window(win, noargs, desc)',
    'Function dense_rank() should not be a window function',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


Question: PostgreSQL regression test 'multirangetypes': Write the SELECT query (example 141).

SELECT nummultirange(numrange(null,null)) @> numrange(null,2);

Explanation: Regression test for Multirangetypes in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT nummultirange(numrange(null,null)) @> numrange(null,2)) AS _sub;


Question: PostgreSQL regression test 'sequence': Write the SELECT query (example 105).

SELECT nextval('sequence_test2');  -- cycled

ALTER SEQUENCE sequence_test2 RESTART WITH -24
  NO CYCLE;

Explanation: Regression test for Sequence in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT nextval('sequence_test2');  -- cycled

ALTER SEQUENCE sequence_test2 RESTART WITH -24
  NO CYCLE) AS _sub;


Question: PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 95).

SELECT JSON_VALUE(jsonb 'null', '$ts' PASSING timestamptz '2018-02-21 12:34:56 +10' AS ts RETURNING jsonb);

Explanation: Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT JSON_VALUE(jsonb 'null', '$ts' PASSING timestamptz '2018-02-21 12:34:56 +10' AS ts RETURNING jsonb)) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'collate.linux.utf8' (example 26).

CREATE TABLE collate_test5 (
    a int,
    b testdomain_sv COLLATE "en_US"
);

Explanation: DDL from PostgreSQL core regression test for Collate.Linux.Utf8.


Question: Show a SQL definition from the pglogical project (row_filter_sampling, item 1).

SELECT * FROM pglogical_regress_variables()
\gset

\c :provider_dsn
-- testing volatile sampling function in row_filter
SELECT pglogical.replicate_ddl_command($$
	CREATE TABLE public.test_tablesample (id int primary key, name text) WITH (fillfactor=10);
$$);

Explanation: SQL definition from the open-source pglogical PostgreSQL project.


Question: pgTAP test for Privs (assertion 95).

Explanation: SQL assertion from pgTAP test suite for Privs.


Question: Write the DDL statement from PostgreSQL regression test 'partition_prune' (example 238).

create table like_op_noprune1 partition of like_op_noprune for values in ('ABC');

Explanation: DDL from PostgreSQL core regression test for Partition Prune.


Question: Write the DML statement from PostgreSQL regression test 'rowsecurity' (example 633).

INSERT INTO test_qual_pushdown VALUES ('abc'),('def');

Explanation: DML from PostgreSQL core regression test for Rowsecurity.


Question: PostgreSQL Query: show example 29.

UPDATE weather SET temp_hi = temp_hi - 2, temp_lo = temp_lo - 2 WHERE date > '1994-11-28';

Explanation: Example from PostgreSQL documentation on Query.


Question: Write the DDL statement from PostgreSQL regression test 'create_table' (example 41).

CREATE TABLE remember_create_subid (c int);

Explanation: DDL from PostgreSQL core regression test for Create Table.


Question: Write the DML statement from PostgreSQL regression test 'without_overlaps' (example 594).

UPDATE temporal_partitioned_rng SET valid_at = daterange('2016-02-01', '2016-03-01')
  WHERE id = '[5,6)' AND valid_at = daterange('2018-02-01', '2018-03-01');

Explanation: DML from PostgreSQL core regression test for Without Overlaps.


Question: Write the PL/pgSQL object from PostgreSQL regression test 'create_procedure' (example 6).

$$;

CALL ptest4a(NULL, NULL);

CREATE PROCEDURE ptest4b(INOUT b int, INOUT a int)
LANGUAGE SQL
AS $$
CALL ptest4a(a, b);  -- error, not supported
$$;

-- we used to get confused by a single output argument that is composite
CREATE PROCEDURE ptest4c(INOUT comp int8_tbl)
LANGUAGE SQL
AS $$
SELECT ROW(1, 2);

Explanation: PL/pgSQL object from PostgreSQL core test for Create Procedure.


Question: Show a query using PostgreSQL contrib extension 'hstore' (example 286).

select f2['d'], f2['x'] is null as x_isnull from test_json_agg;

Explanation: Example query from the 'hstore' extension test/demo.


Question: PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 117).

select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{2 to last}');

Explanation: Regression test for Jsonb Jsonpath in PostgreSQL core test suite.

SELECT count(*) FROM (select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{2 to last}')) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'join' (example 780).

insert into join_ut1 values (101, 101, 'y'), (2, 2, 'z');

Explanation: DML from PostgreSQL core regression test for Join.


Question: PostgreSQL regression test 'interval': Write the SELECT query (example 305).

select make_interval(years := -1, months := -2147483648);

Explanation: Regression test for Interval in PostgreSQL core test suite.

SELECT count(*) FROM (select make_interval(years := -1, months := -2147483648)) AS _sub;


Question: PostgreSQL regression test 'rangefuncs': Write the SELECT query (example 288).

select * from array_to_set(array['one', 'two']) as t(f1 numeric(4,2),f2 text);

Explanation: Regression test for Rangefuncs in PostgreSQL core test suite.

SELECT count(*) FROM (select * from array_to_set(array['one', 'two']) as t(f1 numeric(4,2),f2 text)) AS _sub;


Question: Write the PL/pgSQL object from PostgreSQL regression test 'update' (example 195).

DROP TRIGGER d1_insert_trig ON part_d_1_15;

Explanation: PL/pgSQL object from PostgreSQL core test for Update.


Question: PostgreSQL regression test 'timestamptz': Write the SELECT query (example 128).

Explanation: Regression test for Timestamptz in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT '294276-12-31 15:59:59-08'::timestamptz) AS _sub;


Question: PostgreSQL regression test 'boolean': Write the SELECT query (example 81).

SELECT isfalse AND isnul AND istrue FROM booltbl4;

Explanation: Regression test for Boolean in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT isfalse AND isnul AND istrue FROM booltbl4) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'encoding' (example 2).

CREATE FUNCTION test_text_to_bytea(text) RETURNS bytea
    AS :'regresslib' LANGUAGE C STRICT;

Explanation: DDL from PostgreSQL core regression test for Encoding.


Question: Show a query using PostgreSQL contrib extension 'tsm_system_time' (example 6).

SELECT count(*) FROM test_tablesample TABLESAMPLE system_time (100000);

Explanation: Example query from the 'tsm_system_time' extension test/demo.


Question: pgTAP test for Ownership (assertion 43).

SELECT * FROM check_test(
    relation_owner_is('someseq', current_user),
	true,
    'relation_owner_is(seq, user)',
    'Relation someseq should be owned by ' || quote_ident(current_user),
    ''
);

Explanation: SQL assertion from pgTAP test suite for Ownership.


Question: PostgreSQL regression test 'numeric': Write the SELECT query (example 699).

Explanation: Regression test for Numeric in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT to_char('1237'::float8, 'fmrn')) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'create_function_sql' (example 20).

CREATE FUNCTION functest_C_2(int) RETURNS bool LANGUAGE 'sql'
       SECURITY DEFINER AS 'SELECT $1 = 0';

Explanation: DDL from PostgreSQL core regression test for Create Function Sql.


Question: Show a query using PostgreSQL contrib extension 'intarray' (example 75).

SELECT count(*) from test__int WHERE a @> '{20,23}';

Explanation: Example query from the 'intarray' extension test/demo.


Question: Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 209).

CREATE FUNCTION gbt_varbit_sortsupport(internal)
RETURNS void
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

Explanation: SQL definition from the 'contrib' PostgreSQL contrib extension.


Question: Show an example of PostgreSQL CREATE TRIGGER (example 7).

CREATE TRIGGER paired_items_update AFTER UPDATE ON paired_items REFERENCING NEW TABLE AS newtab OLD TABLE AS oldtab FOR EACH ROW EXECUTE FUNCTION check_matching_pairs();

Explanation: PostgreSQL CREATE TRIGGER command.


Question: PostgreSQL regression test 'collate.windows.win1252': Write the SELECT query (example 37).

SELECT 'bbc' COLLATE "sv_SE" > '�bc' COLLATE "sv_SE" AS "false";

Explanation: Regression test for Collate.Windows.Win1252 in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT 'bbc' COLLATE "sv_SE" > '�bc' COLLATE "sv_SE" AS "false") AS _sub;


Question: Show a query using PostgreSQL contrib extension 'hstore' (example 189).

select v #= hstore('e', null) from testhstore1 v;


Question: Write the DDL statement from PostgreSQL regression test 'test_setup' (example 17).

CREATE TABLE INT8_TBL(q1 int8, q2 int8);

Explanation: DDL from PostgreSQL core regression test for Test Setup.


Question: Write the DDL statement from PostgreSQL regression test 'transactions' (example 23).

CREATE TEMPORARY TABLE temptest (a int);

Explanation: DDL from PostgreSQL core regression test for Transactions.


Question: PostgreSQL regression test 'polymorphism': Write the SELECT query (example 192).

Explanation: Regression test for Polymorphism in PostgreSQL core test suite.

SELECT count(*) FROM (select myleast('z'::text)) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'multirangetypes' (example 477).

Explanation: DML from PostgreSQL core regression test for Multirangetypes.


Question: Show a query using PostgreSQL contrib extension 'btree_gin' (example 23).

Explanation: Example query from the 'btree_gin' extension test/demo.


Question: PostgreSQL regression test 'partition_aggregate': Write the SELECT query (example 125).

SELECT y, sum(x), avg(x), count(*) FROM pagg_tab_para GROUP BY y HAVING avg(x) < 12 ORDER BY 1, 2, 3;

Explanation: Regression test for Partition Aggregate in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT y, sum(x), avg(x), count(*) FROM pagg_tab_para GROUP BY y HAVING avg(x) < 12 ORDER BY 1, 2, 3) AS _sub;


Question: PostgreSQL regression test 'subselect': Write the SELECT query (example 25).

SELECT f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL
  WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL);

Explanation: Regression test for Subselect in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT f1 AS "Uncorrelated Field" FROM SUBSELECT_TBL
  WHERE f1 IN (SELECT f2 FROM SUBSELECT_TBL)) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'partition_join' (example 517).

CREATE TABLE plt1_adv_p3 PARTITION OF plt1_adv FOR VALUES IN ('0003');

Explanation: DDL from PostgreSQL core regression test for Partition Join.


Question: PostgreSQL regression test 'window': Write the SELECT query (example 117).

select first_value(salary) over(order by enroll_date range between unbounded preceding and '1 year'::interval following
	exclude group),
	last_value(salary) over(order by enroll_date range between unbounded preceding and '1 year'::interval following
	exclude group),
	salary, enroll_date from empsalary;

Explanation: Regression test for Window in PostgreSQL core test suite.

SELECT count(*) FROM (select first_value(salary) over(order by enroll_date range between unbounded preceding and '1 year'::interval following
	exclude group),
	last_value(salary) over(order by enroll_date range between unbounded preceding and '1 year'::interval following
	exclude group),
	salary, enroll_date from empsalary) AS _sub;


Question: PostgreSQL regression test 'strings': Write the SELECT query (example 258).

SELECT 'indio' NOT LIKE '_ndio' AS "false";

Explanation: Regression test for Strings in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT 'indio' NOT LIKE '_ndio' AS "false") AS _sub;


Question: Show an example of PostgreSQL SELECT (example 8).

SELECT kind, sum(len) AS total FROM films GROUP BY kind; kind | total ----------+------- Action | 07:34 Comedy | 02:58 Drama | 14:28 Musical | 06:42 Romantic | 04:38;

Explanation: PostgreSQL SELECT command.


Question: PostgreSQL regression test 'create_view': Write the SELECT query (example 107).

Explanation: Regression test for Create View in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT a::varchar(3) FROM tt1) AS _sub;


Question: PL/pgSQL test: Pltcl Queries (example 1).

select tcl_composite_arg_ref1(row('tkey', 42, 'ref2'));

Explanation: PL/pgSQL example from PostgreSQL source test for Pltcl Queries.


Question: PostgreSQL regression test 'interval': Write the SELECT query (example 289).

Explanation: Regression test for Interval in PostgreSQL core test suite.


Question: PostgreSQL regression test 'subselect': Write the SELECT query (example 10).

SELECT count(*) FROM (SELECT (((SELECT 2)) UNION SELECT 2)) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'numeric' (example 147).

Explanation: DML from PostgreSQL core regression test for Numeric.


Question: Write the DDL statement from PostgreSQL regression test 'xml' (example 135).

CREATE VIEW xmlview2 AS SELECT xmlconcat('hello', 'you');

Explanation: DDL from PostgreSQL core regression test for Xml.


Question: PostgreSQL regression test 'join': Write the SELECT query (example 420).

select * from
  text_tbl t1
  left join int8_tbl i8
  on i8.q2 = 123,
  lateral (select i8.q1, t2.f1 from text_tbl t2 limit 1) as ss1,
  lateral (select ss1.* from text_tbl t3 limit 1) as ss2
where t1.f1 = ss2.f1;

Explanation: Regression test for Join in PostgreSQL core test suite.

SELECT count(*) FROM (select * from
  text_tbl t1
  left join int8_tbl i8
  on i8.q2 = 123,
  lateral (select i8.q1, t2.f1 from text_tbl t2 limit 1) as ss1,
  lateral (select ss1.* from text_tbl t3 limit 1) as ss2
where t1.f1 = ss2.f1) AS _sub;


Question: pgTAP test for Resultset (assertion 368).

/****************************************************************************/
-- Test set_eq() with an array argument.
SELECT * FROM check_test(
    set_eq(
        'SELECT name FROM names WHERE name like ''An%''',
        ARRAY['Andrew', 'Anna', 'Anthony', 'Antonio', 'Angelina', 'Andrea', 'Angel' ],
        'whatever'
    ),
    true,
    'set_eq(sql, array, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Resultset.


Question: Write the PL/pgSQL object from PostgreSQL regression test 'plpgsql' (example 663).

--
-- Test handling of expanded arrays
--

create function returns_rw_array(int) returns int[]
language plpgsql as $$
  declare r int[];
  begin r := array[$1, $1]; return r; end;
$$ stable;

Explanation: PL/pgSQL object from PostgreSQL core test for Plpgsql.


Question: Write the DDL statement from PostgreSQL regression test 'create_view' (example 95).

CREATE OR REPLACE VIEW mysecview1
       AS SELECT * FROM tbl1 WHERE a = 256;

Explanation: DDL from PostgreSQL core regression test for Create View.


Question: Write the DDL statement from PostgreSQL regression test 'index_including' (example 110).

CREATE INDEX on tbl USING rtree(c3) INCLUDE (c1, c4);

Explanation: DDL from PostgreSQL core regression test for Index Including.


Question: PostgreSQL regression test 'tablesample': Write the SELECT query (example 4).

SELECT id FROM test_tablesample TABLESAMPLE SYSTEM (100.0/11) REPEATABLE (0);

Explanation: Regression test for Tablesample in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT id FROM test_tablesample TABLESAMPLE SYSTEM (100.0/11) REPEATABLE (0)) AS _sub;


Question: PostgreSQL regression test 'timestamp': Write the SELECT query (example 156).

select make_timestamp(0, 7, 15, 12, 30, 15);

Explanation: Regression test for Timestamp in PostgreSQL core test suite.

SELECT count(*) FROM (select make_timestamp(0, 7, 15, 12, 30, 15)) AS _sub;


Question: PostgreSQL regression test 'money': Write the SELECT query (example 58).

Explanation: Regression test for Money in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT '12345678901234567'::money) AS _sub;


Question: pgTAP test for Update (assertion 3).

SELECT is(
    (SELECT extversion FROM pg_extension WHERE extname = 'pgtap')
    , :'old_ver'
    , 'Old version of pgtap correctly installed'
);

Explanation: SQL assertion from pgTAP test suite for Update.


Question: pgTAP test for Functap (assertion 292).

-- Test diagnostics
SELECT * FROM check_test(
    is_window( 'someschema', 'zilch'::name ),
    false,
    'is_window(schema, nowin)',
    'Function someschema.zilch() should be a window function',
    '    Function someschema.zilch() does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Functap.


Question: Write the DDL statement from PostgreSQL regression test 'drop_if_exists' (example 31).

CREATE domain test_domain_exists as int not null check (value > 0);

Explanation: DDL from PostgreSQL core regression test for Drop If Exists.


Question: PostgreSQL regression test 'subselect': Write the SELECT query (example 197).

select * from int8_tbl where q1 in (select c1 from inner_text);

Explanation: Regression test for Subselect in PostgreSQL core test suite.

SELECT count(*) FROM (select * from int8_tbl where q1 in (select c1 from inner_text)) AS _sub;


Question: Show a SQL definition from the pg_partman project (pg_partman--5.4.0--5.4.1, item 33).

CREATE OR REPLACE FUNCTION @extschema@.drop_partition_id(
    p_parent_table text
    , p_retention bigint DEFAULT NULL
    , p_keep_table boolean DEFAULT NULL
    , p_keep_index boolean DEFAULT NULL
    , p_retention_schema text DEFAULT NULL
)
    RETURNS int
    LANGUAGE plpgsql
    SET search_path = @extschema@, pg_catalog, pg_temp
    AS $$
DECLARE

ex_context                          text;
ex_detail                           text;
ex_hint                             text;
ex_message                          text;
v_adv_lock                          boolean;
v_control                           text;
v_control_type                      text;
v_count                             int;
v_drop_count                        int := 0;
v_index                             record;
v_job_id                            bigint;
v_jobmon                            boolean;
v_jobmon_schema                     text;
v_max                               bigint;
v_new_search_path                   text;
v_old_search_path                   text;
v_parent_schema                     text;
v_parent_tablename                  text;
v_partition_interval                bigint;
v_partition_id                      bigint;
v_pubname_row                       record;
v_retention                         bigint;
v_retention_keep_index              boolean;
v_retention_keep_table              boolean;
v_retention_keep_publication        boolean;
v_retention_schema                  text;
v_row                               record;
v_row_max_id                        record;
v_sql                               text;
v_step_id                           bigint;
v_sub_parent                        text;

BEGIN
/*
 * Function to drop child tables from an id-based partition set.
 * Options to move table to different schema or actually drop the table from the database.
 */

v_adv_lock := pg_try_advisory_xact_lock(hashtext('pg_partman drop_partition_id'));
IF v_adv_lock = 'false' THEN
    RAISE NOTICE 'drop_partition_id already running.';
    RETURN 0;
END IF;

IF p_retention IS NULL THEN
    SELECT
        partition_interval::bigint
        , control
        , retention::bigint
        , retention_keep_table
        , retention_keep_index
        , retention_keep_publication
        , retention_schema
        , jobmon
    INTO
        v_partition_interval
        , v_control
        , v_retention
        , v_retention_keep_table
        , v_retention_keep_index
        , v_retention_keep_publication
        , v_retention_schema
        , v_jobmon
    FROM @extschema@.part_config
    WHERE parent_table = p_parent_table
    AND retention IS NOT NULL;

    IF v_partition_interval IS NULL THEN
        RAISE EXCEPTION 'Configuration for given parent table with a retention period not found: %', p_parent_table;
    END IF;
ELSE -- Allow override of configuration options
     SELECT
        partition_interval::bigint
        , control
        , retention_keep_table
        , retention_keep_index
        , retention_keep_publication
        , retention_schema
        , jobmon
    INTO
        v_partition_interval
        , v_control
        , v_retention_keep_table
        , v_retention_keep_index
        , v_retention_keep_publication
        , v_retention_schema
        , v_jobmon
    FROM @extschema@.part_config
    WHERE parent_table = p_parent_table;
    v_retention := p_retention;

    IF v_partition_interval IS NULL THEN
        RAISE EXCEPTION 'Configuration for given parent table not found: %', p_parent_table;
    END IF;
END IF;

SELECT general_type INTO v_control_type FROM @extschema@.check_control_type(v_parent_schema, v_parent_tablename, v_control);
IF v_control_type <> 'id' THEN
    RAISE EXCEPTION 'Data type of control column in given partition set is not an integer type';
END IF;

IF v_jobmon THEN
    SELECT nspname INTO v_jobmon_schema FROM pg_catalog.pg_namespace n, pg_catalog.pg_extension e WHERE e.extname = 'pg_jobmon'::name AND e.extnamespace = n.oid;
    IF v_jobmon_schema IS NOT NULL THEN
        SELECT current_setting('search_path') INTO v_old_search_path;
        IF v_jobmon_schema IS NOT NULL THEN
            v_new_search_path := format('%s,%s',v_jobmon_schema, v_old_search_path);
            EXECUTE format('SET LOCAL search_path TO %s', v_new_search_path);
        END IF;
    END IF;
END IF;

IF p_keep_table IS NOT NULL THEN
    v_retention_keep_table = p_keep_table;
END IF;
IF p_keep_index IS NOT NULL THEN
    v_retention_keep_index = p_keep_index;
END IF;
IF p_retention_schema IS NOT NULL THEN
    v_retention_schema = p_retention_schema;
END IF;

SELECT schemaname, tablename INTO v_parent_schema, v_parent_tablename
FROM pg_catalog.pg_tables
WHERE schemaname = split_part(p_parent_table, '.', 1)::name
AND tablename = split_part(p_parent_table, '.', 2)::name;

-- Loop through child tables starting from highest to get current max value in partition set
-- Avoids doing a scan on entire partition set and/or getting any values accidentally in default.
FOR v_row_max_id IN
    SELECT partition_schemaname, partition_tablename FROM @extschema@.show_partitions(p_parent_table, 'DESC')
LOOP
        EXECUTE format('SELECT trunc(max(%I)) FROM %I.%I', v_control, v_row_max_id.partition_schemaname, v_row_max_id.partition_tablename) INTO v_max;
        IF v_max IS NOT NULL THEN
            EXIT;
        END IF;
END LOOP;

SELECT sub_parent INTO v_sub_parent FROM @extschema@.part_config_sub WHERE sub_parent = p_parent_table;

-- Loop through child tables of the given parent
-- Must go in ascending order to avoid dropping what may be the "last" partition in the set after dropping tables that match retention period
FOR v_row IN
    SELECT partition_schemaname, partition_tablename FROM @extschema@.show_partitions(p_parent_table, 'ASC')
LOOP
     SELECT child_start_id INTO v_partition_id FROM @extschema@.show_partition_info(v_row.partition_schemaname||'.'||v_row.partition_tablename
        , v_partition_interval::text
        , p_parent_table);

    -- Add one interval to the start of the constraint period
    RAISE DEBUG 'drop_partition_id: v_retention: %, v_max: %, v_partition_id: %, v_partition_interval: %', v_retention, v_max, v_partition_id, v_partition_interval;
    IF v_retention <= (v_max - (v_partition_id + v_partition_interval)) THEN

        -- Do not allow final partition to be dropped if it is not a sub-partition parent
        SELECT count(*) INTO v_count FROM @extschema@.show_partitions(p_parent_table);
        IF v_count = 1 AND v_sub_parent IS NULL THEN
            RAISE WARNING 'Attempt to drop final partition in partition set % as part of retention policy. If you see this message multiple times for the same table, advise reviewing retention policy and/or data entry into the partition set. Also consider setting "infinite_time_partitions = true" if there are large gaps in data insertion.', p_parent_table;
            CONTINUE;
        END IF;

        -- Only create a jobmon entry if there's actual retention work done
        IF v_jobmon_schema IS NOT NULL AND v_job_id IS NULL THEN
            v_job_id := add_job(format('PARTMAN DROP ID PARTITION: %s', p_parent_table));
        END IF;

        IF v_jobmon_schema IS NOT NULL THEN
            v_step_id := add_step(v_job_id, format('Detach/Uninherit table %s.%s from %s', v_row.partition_schemaname, v_row.partition_tablename, p_parent_table));
        END IF;

        IF v_retention_keep_table = true OR v_retention_schema IS NOT NULL THEN
            -- No need to detach partition before dropping since it's going away anyway
            -- TODO Review this to see how to handle based on recent FK issues
            -- Avoids issue of FKs not allowing detachment (Github Issue #294).
            v_sql := format('ALTER TABLE %I.%I DETACH PARTITION %I.%I'
                , v_parent_schema
                , v_parent_tablename
                , v_row.partition_schemaname
                , v_row.partition_tablename);
            EXECUTE v_sql;

            IF v_retention_keep_index = false THEN
                FOR v_index IN
                     WITH child_info AS (
                        SELECT c1.oid
                        FROM pg_catalog.pg_class c1
                        JOIN pg_catalog.pg_namespace n1 ON c1.relnamespace = n1.oid
                        WHERE c1.relname = v_row.partition_tablename::name
                        AND n1.nspname = v_row.partition_schemaname::name
                    )
                    SELECT c.relname as name
                        , con.conname
                    FROM pg_catalog.pg_index i
                    JOIN pg_catalog.pg_class c ON i.indexrelid = c.oid
                    LEFT JOIN pg_catalog.pg_constraint con ON i.indexrelid = con.conindid
                    JOIN child_info ON i.indrelid = child_info.oid
                LOOP
                    IF v_jobmon_schema IS NOT NULL THEN
                        v_step_id := add_step(v_job_id, format('Drop index %s from %s.%s'
                            , v_index.name
                            , v_row.partition_schemaname
                            , v_row.partition_tablename));
                    END IF;
                    IF v_index.conname IS NOT NULL THEN
                        EXECUTE format('ALTER TABLE %I.%I DROP CONSTRAINT %I', v_row.partition_schemaname, v_row.partition_tablename, v_index.conname);
                    ELSE
                        EXECUTE format('DROP INDEX %I.%I', v_row.partition_schemaname, v_index.name);
                    END IF;
                    IF v_jobmon_schema IS NOT NULL THEN
                        PERFORM update_step(v_step_id, 'OK', 'Done');
                    END IF;
                END LOOP;
            END IF; -- end v_retention_keep_index IF

            -- Remove table from publication(s) if desired
            IF v_retention_keep_publication = false THEN
                FOR v_pubname_row IN
                    SELECT p.pubname
                    FROM pg_catalog.pg_publication_rel pr
                    JOIN pg_catalog.pg_publication p ON p.oid = pr.prpubid
                    JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid
                    JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE n.nspname = v_row.partition_schemaname
                    AND c.relname = v_row.partition_tablename
                LOOP
                    EXECUTE format('ALTER PUBLICATION %I DROP TABLE %I.%I', v_pubname_row.pubname, v_row.partition_schemaname, v_row.partition_tablename);
                END LOOP;
            END IF;

        END IF;

        IF v_retention_schema IS NULL THEN
            IF v_retention_keep_table = false THEN
                IF v_jobmon_schema IS NOT NULL THEN
                    v_step_id := add_step(v_job_id, format('Drop table %s.%s', v_row.partition_schemaname, v_row.partition_tablename));
                END IF;
                v_sql := 'DROP TABLE %I.%I';
                EXECUTE format(v_sql, v_row.partition_schemaname, v_row.partition_tablename);
                IF v_jobmon_schema IS NOT NULL THEN
                    PERFORM update_step(v_step_id, 'OK', 'Done');
                END IF;
            END IF;
        ELSE -- Move to new schema
            IF v_jobmon_schema IS NOT NULL THEN
                v_step_id := add_step(v_job_id, format('Moving table %s.%s to schema %s'
                                                        , v_row.partition_schemaname
                                                        , v_row.partition_tablename
                                                        , v_retention_schema));
            END IF;

            EXECUTE format('ALTER TABLE %I.%I SET SCHEMA %I'
                    , v_row.partition_schemaname
                    , v_row.partition_tablename
                    , v_retention_schema);

            IF v_jobmon_schema IS NOT NULL THEN
                PERFORM update_step(v_step_id, 'OK', 'Done');
            END IF;
        END IF; -- End retention schema if

        -- If child table is a subpartition, remove it from part_config & part_config_sub (should cascade due to FK)
        DELETE FROM @extschema@.part_config WHERE parent_table = v_row.partition_schemaname ||'.'||v_row.partition_tablename;

        v_drop_count := v_drop_count + 1;
    END IF; -- End retention check IF

END LOOP; -- End child table loop

IF v_jobmon_schema IS NOT NULL THEN
    IF v_job_id IS NOT NULL THEN
        v_step_id := add_step(v_job_id, 'Finished partition drop maintenance');
        PERFORM update_step(v_step_id, 'OK', format('%s partitions dropped.', v_drop_count));
        PERFORM close_job(v_job_id);
    END IF;
END IF;

RETURN v_drop_count;

EXCEPTION
    WHEN OTHERS THEN
        GET STACKED DIAGNOSTICS ex_message = MESSAGE_TEXT,
                                ex_context = PG_EXCEPTION_CONTEXT,
                                ex_detail = PG_EXCEPTION_DETAIL,
                                ex_hint = PG_EXCEPTION_HINT;
        IF v_jobmon_schema IS NOT NULL THEN
            IF v_job_id IS NULL THEN
                EXECUTE format('SELECT %I.add_job(''PARTMAN DROP ID PARTITION: %s'')', v_jobmon_schema, p_parent_table) INTO v_job_id;
                EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before job logging started'')', v_jobmon_schema, v_job_id, p_parent_table) INTO v_step_id;
            ELSIF v_step_id IS NULL THEN
                EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before first step logged'')', v_jobmon_schema, v_job_id) INTO v_step_id;
            END IF;
            EXECUTE format('SELECT %I.update_step(%s, ''CRITICAL'', %L)', v_jobmon_schema, v_step_id, 'ERROR: '||coalesce(SQLERRM,'unknown'));
            EXECUTE format('SELECT %I.fail_job(%s)', v_jobmon_schema, v_job_id);
        END IF;
        RAISE EXCEPTION '%
CONTEXT: %
DETAIL: %
HINT: %', ex_message, ex_context, ex_detail, ex_hint;
END
$$;

Explanation: SQL definition from the open-source pg_partman PostgreSQL project.


Question: PostgreSQL regression test 'rowsecurity': Write the SELECT query (example 841).

Explanation: Regression test for Rowsecurity in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT * FROM coll_t) AS _sub;


Question: pgTAP test for Functap (assertion 148).

SELECT * FROM check_test(
    is_normal_function( 'public', 'tap_accum', ARRAY[etype()], 'whatever' ),
    false,
    'is_normal_function(schema, agg, arg, desc)',
    'whatever',
    ''
);


Question: Write the DDL statement from PostgreSQL regression test 'fast_default' (example 12).

CREATE TABLE has_volatile AS
SELECT * FROM generate_series(1,10) id;

Explanation: DDL from PostgreSQL core regression test for Fast Default.


Question: PostgreSQL regression test 'largeobject': Write the SELECT query (example 50).

SELECT lo_lseek64(fd, -10, 1) FROM lotest_stash_values;

Explanation: Regression test for Largeobject in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT lo_lseek64(fd, -10, 1) FROM lotest_stash_values) AS _sub;


Question: PL/pgSQL test: Plpython Types (example 29).

SELECT * FROM test_type_conversion_numeric(100);

Explanation: PL/pgSQL example from PostgreSQL source test for Plpython Types.


Question: pgTAP test for Hastap (assertion 168).

SELECT * FROM check_test(
    cast_context_is( 'bigint', 'smallint', 'ASS', 'desc' ),
    true,
    'cast_context_is( src, targ, ASS, desc )',
    'desc',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


Question: PostgreSQL regression test 'interval': Write the SELECT query (example 184).

Explanation: Regression test for Interval in PostgreSQL core test suite.

SELECT count(*) FROM (select interval '-2147483649 months') AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'numeric' (example 186).

Explanation: DML from PostgreSQL core regression test for Numeric.


Question: PL/pgSQL test: Plpython Subtransaction (example 50).

ALTER TABLE subtransaction_tbl ADD PRIMARY KEY (i);

Explanation: PL/pgSQL example from PostgreSQL source test for Plpython Subtransaction.


Question: Write the DDL statement from PostgreSQL regression test 'partition_join' (example 7).

Explanation: DDL from PostgreSQL core regression test for Partition Join.


Question: PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 514).

select jsonb_path_query('[]', 'strict $.string()', silent => true);

Explanation: Regression test for Jsonb Jsonpath in PostgreSQL core test suite.

SELECT count(*) FROM (select jsonb_path_query('[]', 'strict $.string()', silent => true)) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'rules' (example 221).

insert into rtest_nothn1 select * from rtest_nothn4;

Explanation: DML from PostgreSQL core regression test for Rules.


Question: Write the PL/pgSQL object from PostgreSQL regression test 'fast_default' (example 118).

-- Aggregate function
SELECT SUM(c_bigint), MAX(c_text COLLATE "C" ), MIN(c_text COLLATE "C") FROM T;

Explanation: PL/pgSQL object from PostgreSQL core test for Fast Default.


Question: PL/pgSQL test: Plpython Composite (example 55).

SELECT * FROM multiout_table_type_setof('tuple', 'f', 3);

Explanation: PL/pgSQL example from PostgreSQL source test for Plpython Composite.


Question: Write the DDL statement from PostgreSQL regression test 'domain' (example 280).

create table domain_test (a int, b int);

Explanation: DDL from PostgreSQL core regression test for Domain.


Question: PostgreSQL regression test 'sqljson': Write the SELECT query (example 33).

Explanation: Regression test for Sqljson in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT JSON_SCALAR('2020-06-07 01:02:03'::timestamp)) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'numeric' (example 458).


Question: PostgreSQL regression test 'jsonb': Write the SELECT query (example 298).

SELECT ia2 FROM jsonb_populate_record(NULL::jsbrec, '{"ia2": [1, "2", null, 4]}') q;

Explanation: Regression test for Jsonb in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT ia2 FROM jsonb_populate_record(NULL::jsbrec, '{"ia2": [1, "2", null, 4]}') q) AS _sub;


Question: pgTAP test for Resultset (assertion 175).

INSERT INTO names (name) VALUES ('Mariah');

Explanation: SQL assertion from pgTAP test suite for Resultset.


Question: Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 61).

CREATE FUNCTION gbt_int2_penalty(internal,internal,internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

Explanation: SQL definition from the 'contrib' PostgreSQL contrib extension.


Question: PostgreSQL regression test 'tsdicts': Write the SELECT query (example 117).

SELECT to_tsvector('thesaurus_tst', 'one postgres one two one two three one');

Explanation: Regression test for Tsdicts in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT to_tsvector('thesaurus_tst', 'one postgres one two one two three one')) AS _sub;


Question: PostgreSQL regression test 'multirangetypes': Write the SELECT query (example 411).

select count(*) from test_multirange_gist where mr >> '{}'::int4multirange;

Explanation: Regression test for Multirangetypes in PostgreSQL core test suite.

SELECT count(*) FROM (select count(*) from test_multirange_gist where mr >> '{}'::int4multirange) AS _sub;


Question: Show a SQL definition from the timescaledb project (create_hypertable, item 4).

create table test_schema.test_table(time BIGINT, temp float8, device_id text, device_type text, location text, id int, id2 int);

Explanation: SQL definition from the open-source timescaledb PostgreSQL project.


Question: Write the DDL statement from PostgreSQL regression test 'sqljson_queryfuncs' (example 238).

CREATE INDEX ON test_jsonb_mutability (JSON_QUERY(js, '$.datetime() < $x' PASSING '1234'::int AS x));

Explanation: DDL from PostgreSQL core regression test for Sqljson Queryfuncs.


Question: pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 211).

ALTER EXTENSION pgtap ADD FUNCTION has_check ( NAME );

Explanation: SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.


Question: Write the PL/pgSQL object from PostgreSQL regression test 'rangefuncs' (example 278).

Explanation: PL/pgSQL object from PostgreSQL core test for Rangefuncs.


Question: Write the DML statement from PostgreSQL regression test 'rules' (example 333).

insert into shoelace values ('sl9', 0, 'pink', 35.0, 'inch', 0.0);


Question: Show a query using PostgreSQL contrib extension 'pg_trgm' (example 98).

select * from test2 where t ~ '(abc)*$';

Explanation: Example query from the 'pg_trgm' extension test/demo.


Question: PostgreSQL regression test 'sysviews': Write the SELECT query (example 29).

select * from pg_timezone_abbrevs where abbrev = 'LMT';

Explanation: Regression test for Sysviews in PostgreSQL core test suite.

SELECT count(*) FROM (select * from pg_timezone_abbrevs where abbrev = 'LMT') AS _sub;


Question: Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 294).

CREATE OPERATOR = (
	PROCEDURE = isneq,
	LEFTARG = ismn13,
	RIGHTARG = ismn13,
	COMMUTATOR = =,
	NEGATOR = <>,
	RESTRICT = eqsel,
	JOIN = eqjoinsel,
	MERGES,
	HASHES);


Question: Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 1).

/* contrib/pgcrypto/pgcrypto--1.3--1.4.sql */

-- complain if script is sourced in psql, rather than via ALTER EXTENSION
\echo Use "ALTER EXTENSION pgcrypto UPDATE TO '1.4'" to load this file. \quit

CREATE FUNCTION fips_mode()
RETURNS bool
AS 'MODULE_PATHNAME', 'pg_check_fipsmode'
LANGUAGE C VOLATILE STRICT PARALLEL SAFE;


Question: Show a SQL definition from the pglogical project (pglogical_origin--1.0.0, item 1).

\echo Use "CREATE EXTENSION pglogical_origin" to load this file. \quit;

Explanation: SQL definition from the open-source pglogical PostgreSQL project.


Question: PostgreSQL regression test 'boolean': Write the SELECT query (example 37).

Explanation: Regression test for Boolean in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT bool 'f' < bool 't' AS true) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'citext' (example 349).

SELECT regexp_match('foobarbequebaz'::citext, '(BAR)(BEQUE)', '') = ARRAY[ 'bar', 'beque' ] AS t;

Explanation: Example query from the 'citext' extension test/demo.


Question: PL/pgSQL test: Pltcl Subxact (example 14).

Explanation: PL/pgSQL example from PostgreSQL source test for Pltcl Subxact.


Question: Write the DML statement from PostgreSQL regression test 'triggers' (example 390).

insert into trans_tab_parent values ('AAA1'), ('BBB1');

Explanation: DML from PostgreSQL core regression test for Triggers.