Question: Show a SQL definition from the pg_partman project (test-dump-definition, item 20).

CREATE TABLE template_partman_test_declarative_objects(
  id SERIAL,
  t TEXT,
  created_at TIMESTAMP NOT NULL
);

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


Question: PostgreSQL regression test 'horology': Write the SELECT query (example 169).

SELECT CAST(time with time zone '01:02-08' AS interval) AS "+00:01";

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

SELECT count(*) FROM (SELECT CAST(time with time zone '01:02-08' AS interval) AS "+00:01") AS _sub;


Question: pgTAP test for Pgtap--0.91.0--0.92.0 (assertion 124).

-- server_privs_are ( server, user, privileges[] )
CREATE OR REPLACE FUNCTION server_privs_are ( NAME, NAME, NAME[] )
RETURNS TEXT AS $$
    SELECT server_privs_are(
        $1, $2, $3,
        'Role ' || quote_ident($2) || ' should be granted '
            || CASE WHEN $3[1] IS NULL THEN 'no privileges' ELSE array_to_string($3, ', ') END
            || ' on server ' || quote_ident($1)
    );
$$ LANGUAGE SQL;

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


Question: PostgreSQL regression test 'select': Write the SELECT query (example 34).

SELECT * FROM foo ORDER BY f1 ASC;	-- same thing
SELECT * FROM foo ORDER BY f1 NULLS FIRST;

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

SELECT count(*) FROM (SELECT * FROM foo ORDER BY f1 ASC;	-- same thing
SELECT * FROM foo ORDER BY f1 NULLS FIRST) AS _sub;


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

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

SELECT count(*) FROM (SELECT name(equipment_named_ambiguous_2a(text 'skywalking'))) AS _sub;


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

Explanation: DML from PostgreSQL core regression test for Numeric.


Question: Show a query using PostgreSQL contrib extension 'pg_stat_statements' (example 40).

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


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

Explanation: DDL from PostgreSQL core regression test for Domain.


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

SELECT scale(millions), * FROM num_typemod_test ORDER BY millions;

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

SELECT count(*) FROM (SELECT scale(millions), * FROM num_typemod_test ORDER BY millions) AS _sub;


Question: PostgreSQL regression test 'partition_info': Write the SELECT query (example 38).

SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test3') p
  JOIN pg_class c ON (p.relid = c.oid);

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

SELECT count(*) FROM (SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test3') p
  JOIN pg_class c ON (p.relid = c.oid)) AS _sub;


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

CREATE FUNCTION dearmor(text)
RETURNS bytea
AS 'MODULE_PATHNAME', 'pg_dearmor'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

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


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

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


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

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


Question: Write the DML statement from PostgreSQL regression test 'stats_rewrite' (example 156).

Explanation: DML from PostgreSQL core regression test for Stats Rewrite.


Question: pgTAP test for Functap (assertion 118).

SELECT * FROM check_test(
    isnt_definer( 'public', 'yay'::name ),
    false,
    'isnt_definer(schema, func)',
    'Function public.yay() should not be security definer',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

SELECT t1.id1, t1.id2, t1.result, t2.expected
    FROM num_result t1, num_exp_mul t2
    WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
    AND t1.result != t2.expected;

SELECT count(*) FROM (SELECT t1.id1, t1.id2, t1.result, t2.expected
    FROM num_result t1, num_exp_mul t2
    WHERE t1.id1 = t2.id1 AND t1.id2 = t2.id2
    AND t1.result != t2.expected) AS _sub;


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

CREATE FUNCTION isnne(upc, upc)
	RETURNS boolean
	AS 'int8ne'
	LANGUAGE 'internal'
	IMMUTABLE STRICT
	PARALLEL SAFE;


Question: pgTAP test for Functap (assertion 68).

SELECT * FROM check_test(
    function_lang_is( 'yay', '{}'::name[], 'sql', 'whatever' ),
    true,
    'function_lang_is(func, 0 args, sql, desc)',
    'whatever',
    ''
);


Question: PostgreSQL Ddl: show example 74.

Explanation: Example from PostgreSQL documentation on Ddl.


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

CREATE FUNCTION bt_page_stats(IN relname text, IN blkno int8,
    OUT blkno int8,
    OUT type "char",
    OUT live_items int4,
    OUT dead_items int4,
    OUT avg_item_size int4,
    OUT page_size int4,
    OUT free_size int4,
    OUT btpo_prev int8,
    OUT btpo_next int8,
    OUT btpo_level int8,
    OUT btpo_flags int4)
AS 'MODULE_PATHNAME', 'bt_page_stats_1_9'
LANGUAGE C STRICT PARALLEL SAFE;


Question: pgTAP test for Privs (assertion 79).

/****************************************************************************/
-- Test tablespace_privilege_is().

SELECT * FROM check_test(
    tablespace_privs_are( 'pg_default', current_user, '{CREATE}', 'whatever' ),
    true,
    'tablespace_privs_are(tablespace, role, privs, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Privs.


Question: Write the DML statement from PostgreSQL regression test 'circle' (example 6).

INSERT INTO CIRCLE_TBL VALUES (' ( ( 1 , 2 ) , 3 ) ');

Explanation: DML from PostgreSQL core regression test for Circle.


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

SELECT lo_from_bytea(0, lo_get(loid)) AS newloid FROM lotest_stash_values
\gset

-- Add a comment to it, as well, for pg_dump/pg_upgrade testing.
COMMENT ON LARGE OBJECT :newloid IS 'I Wandered Lonely as a Cloud';

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

SELECT count(*) FROM (SELECT lo_from_bytea(0, lo_get(loid)) AS newloid FROM lotest_stash_values
\gset

-- Add a comment to it, as well, for pg_dump/pg_upgrade testing.
COMMENT ON LARGE OBJECT :newloid IS 'I Wandered Lonely as a Cloud') AS _sub;


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

select * from
  zt2 left join zt3 on (f2 = f3)
      left join zt1 on (f3 = f1)
where f2 = 53;

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

SELECT count(*) FROM (select * from
  zt2 left join zt3 on (f2 = f3)
      left join zt1 on (f3 = f1)
where f2 = 53) AS _sub;


Question: PL/pgSQL test: Plpgsql Transaction (example 130).

DO LANGUAGE plpgsql $$
BEGIN
    ROLLBACK;
    SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
    FOR i IN 0..3 LOOP
        RAISE INFO 'transaction_isolation = %', current_setting('transaction_isolation');
        INSERT INTO test1 (a) VALUES (i);
        IF i % 2 = 0 THEN
            COMMIT AND CHAIN;
        ELSE
            ROLLBACK AND CHAIN;
        END IF;
    END LOOP;
END
$$;

Explanation: PL/pgSQL example from PostgreSQL source test for Plpgsql Transaction.


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

CREATE OPERATOR <> (
	PROCEDURE = isnne,
	LEFTARG = ean13,
	RIGHTARG = isbn13,
	COMMUTATOR = <>,
	NEGATOR = =,
	RESTRICT = neqsel,
	JOIN = neqjoinsel);


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

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


Question: Show a SQL definition from the pg_partman project (pg_partman--5.1.0--5.2.0, item 24).

CREATE OR REPLACE PROCEDURE @extschema@.reapply_constraints_proc(p_parent_table text, p_drop_constraints boolean DEFAULT false, p_apply_constraints boolean DEFAULT false, p_wait int DEFAULT 0, p_dryrun boolean DEFAULT false)
    LANGUAGE plpgsql
    AS $$
DECLARE

v_adv_lock                      boolean;
v_child_exists                  text;
v_child_stop                    text;
v_child_value                   text;
v_control                       text;
v_control_type                  text;
v_datetime_string               text;
v_epoch                         text;
v_last_partition                text;
v_last_partition_id             bigint;
v_last_partition_timestamp      timestamptz;
v_optimize_constraint           int;
v_optimize_counter              int := 0;
v_parent_schema                 text;
v_parent_tablename              text;
v_partition_interval            text;
v_partition_suffix              text;
v_premake                       int;
v_row                           record;
v_row_max_value                 record;
v_sql                           text;

BEGIN
/*
 * Procedure for reapplying additional constraints managed by pg_partman on child tables. See docs for additional info on this special constraint management.
 * Procedure can run in two distinct modes: 1) Drop all constraints  2) Apply all constraints.
 * If both modes are run in a single call, drop is run before apply.
 * Typical usage would be to run the drop mode, edit the data, then run apply mode to re-create all constraints on a partition set."
 */

v_adv_lock := pg_try_advisory_lock(hashtext('pg_partman reapply_constraints'));
IF v_adv_lock = false THEN
    RAISE NOTICE 'Partman reapply_constraints_proc already running or another session has not released its advisory lock.';
    RETURN;
END IF;

SELECT control, premake, optimize_constraint, datetime_string, epoch, partition_interval
INTO v_control, v_premake, v_optimize_constraint, v_datetime_string, v_epoch, v_partition_interval
FROM @extschema@.part_config
WHERE parent_table = p_parent_table;
IF v_premake IS NULL THEN
    RAISE EXCEPTION 'Unable to find given parent in pg_partman config: %. This procedure is only meant to be called on pg_partman managed partition sets.', p_parent_table;
END IF;

SELECT n.nspname, c.relname INTO v_parent_schema, v_parent_tablename
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = split_part(p_parent_table, '.', 1)::name
AND c.relname = split_part(p_parent_table, '.', 2)::name;
    IF v_parent_tablename IS NULL THEN
        RAISE EXCEPTION 'Unable to find given parent table in system catalogs. Ensure it is schema qualified: %', p_parent_table;
    END IF;

SELECT general_type INTO v_control_type FROM @extschema@.check_control_type(v_parent_schema, v_parent_tablename, v_control);

-- Determine child table to stop creating constraints on based on optimize_constraint value
-- Same code in apply_constraints.sql
SELECT partition_tablename INTO v_last_partition FROM @extschema@.show_partitions(p_parent_table, 'DESC', false) LIMIT 1;

FOR v_row_max_value IN
    SELECT partition_schemaname, partition_tablename FROM @extschema@.show_partitions(p_parent_table, 'DESC', false)
LOOP
    IF v_child_value IS NULL THEN
        EXECUTE format('SELECT %L::text FROM %I.%I LIMIT 1'
                            , v_control
                            , v_row_max_value.partition_schemaname
                            , v_row_max_value.partition_tablename
                        ) INTO v_child_value;

    ELSE
        v_optimize_counter := v_optimize_counter + 1;
        IF v_optimize_counter = v_optimize_constraint THEN
            v_child_stop = v_row_max_value.partition_tablename;
            EXIT;
        END IF;
    END IF;
END LOOP;

IF v_optimize_counter < v_optimize_constraint THEN
    -- No child table exists that is old enough to apply constraints
    RAISE DEBUG 'reapply_constraint: Target child stop table not found. Skipping all constraint creation.';
    RETURN;
END IF;

v_sql := format('SELECT partition_schemaname, partition_tablename FROM @extschema@.show_partitions(%L, %L)', p_parent_table, 'ASC');

RAISE DEBUG 'reapply_constraint: v_parent_tablename: % , v_partition_suffix: %, v_child_stop: %,  v_sql: %', v_parent_tablename, v_partition_suffix, v_child_stop, v_sql;

v_row := NULL;
FOR v_row IN EXECUTE v_sql LOOP
    IF p_drop_constraints THEN
        IF p_dryrun THEN
            RAISE NOTICE 'DRYRUN NOTICE: Dropping constraints on child table: %.%', v_row.partition_schemaname, v_row.partition_tablename;
        ELSE
            RAISE DEBUG 'reapply_constraint drop: %.%', v_row.partition_schemaname, v_row.partition_tablename;
            PERFORM @extschema@.drop_constraints(p_parent_table, format('%s.%s', v_row.partition_schemaname, v_row.partition_tablename)::text);
        END IF;
    END IF; -- end drop
    COMMIT;

    IF p_apply_constraints THEN
        IF p_dryrun THEN
            RAISE NOTICE 'DRYRUN NOTICE: Applying constraints on child table: %.%', v_row.partition_schemaname, v_row.partition_tablename;
        ELSE
            RAISE DEBUG 'reapply_constraint apply: %.%', v_row.partition_schemaname, v_row.partition_tablename;
            PERFORM @extschema@.apply_constraints(p_parent_table, format('%s.%s', v_row.partition_schemaname, v_row.partition_tablename)::text);
        END IF;
    END IF; -- end apply

    IF v_row.partition_tablename = v_child_stop THEN
        RAISE DEBUG 'reapply_constraint: Reached stop at %.%', v_row.partition_schemaname, v_row.partition_tablename;
        EXIT; -- stop creating constraints after optimize target is reached
    END IF;
    COMMIT;
    PERFORM pg_sleep(p_wait);
END LOOP;

EXECUTE format('ANALYZE %I.%I', v_parent_schema, v_parent_tablename);

PERFORM pg_advisory_unlock(hashtext('pg_partman reapply_constraints'));
END
$$;

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


Question: Write the DDL statement from PostgreSQL regression test 'foreign_key' (example 942).

CREATE TABLE fk (a int REFERENCES pk DEFERRABLE INITIALLY IMMEDIATE);

Explanation: DDL from PostgreSQL core regression test for Foreign Key.


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

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

SELECT count(*) FROM (select jsonb_path_query('"2023-08-15 12:34:56"', '$.time_tz()')) AS _sub;


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


Question: PL/pgSQL test: Pltcl Call (example 11).

CREATE PROCEDURE test_proc6(a int, INOUT b int, INOUT c int)
LANGUAGE pltcl
AS $$
set bb [expr $2 * $1]
set cc [expr $3 * $1]
return [list b $bb c $cc]
$$;

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


Question: Write the DDL statement from PostgreSQL regression test 'insert' (example 123).

create table part_xx_yy_defpart partition of part_xx_yy default;

Explanation: DDL from PostgreSQL core regression test for Insert.


Question: PostgreSQL regression test 'domain': Write the SELECT query (example 385).

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

SELECT count(*) FROM (select pg_basetype('mytext_child_1'::regtype)) AS _sub;


Question: PostgreSQL Textsearch: show example 42.

SELECT phraseto_tsquery('english', 'The Fat Rats'); phraseto_tsquery ------------------ 'fat' <-> 'rat';

Explanation: Example from PostgreSQL documentation on Textsearch.


Question: Show a query using PostgreSQL contrib extension 'pg_overexplain' (example 20).

SELECT explain_filter($$
EXPLAIN (DEBUG, COSTS OFF)
SELECT genus, array_agg(name ORDER BY name) FROM vegetables GROUP BY genus
$$);

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


Question: Write the DDL statement from PostgreSQL regression test 'indexing' (example 368).

create table idxpart11 (a int not null, b int primary key);

Explanation: DDL from PostgreSQL core regression test for Indexing.


Question: Write the DDL statement from PostgreSQL regression test 'plancache' (example 21).

CREATE OR REPLACE TEMP VIEW pcacheview AS
  SELECT q1, q2/2 AS q2 FROM pcachetest;

Explanation: DDL from PostgreSQL core regression test for Plancache.


Question: pgTAP test for Fktap (assertion 17).

SELECT * FROM check_test(
    has_fk( 'fk4', 'fk4 should have an fk' ),
    'true',
    'has_fk( table4, description )',
    'fk4 should have an fk'
);

Explanation: SQL assertion from pgTAP test suite for Fktap.


Question: Show a query using PostgreSQL contrib extension 'pg_stat_statements' (example 8).

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


Question: PostgreSQL regression test 'identity': Write the SELECT query (example 238).

SELECT relname, relpersistence FROM pg_class
  WHERE relname ~ '^identity_dump_' ORDER BY 1;

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

SELECT count(*) FROM (SELECT relname, relpersistence FROM pg_class
  WHERE relname ~ '^identity_dump_' ORDER BY 1) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'alter_table' (example 597).

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


Question: PostgreSQL regression test 'hash_index': Write the SELECT query (example 45).

SELECT h.seqno AS t20000
   FROM hash_txt_heap h
   WHERE h.random = '959363399'::text;

Explanation: Regression test for Hash Index in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT h.seqno AS t20000
   FROM hash_txt_heap h
   WHERE h.random = '959363399'::text) AS _sub;


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

SELECT xmlparse(content '<relativens xmlns=''relative''/>');

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

SELECT count(*) FROM (SELECT xmlparse(content '<relativens xmlns=''relative''/>')) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'merge' (example 551).

Explanation: DML from PostgreSQL core regression test for Merge.


Question: PostgreSQL regression test 'rangetypes': Write the SELECT query (example 94).

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

SELECT count(*) FROM (select numrange(1.0, 3.0,'[]') << numrange(3.0, 4.0,'[]')) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'partition_merge' (example 179).

CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);

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


Question: Write the DDL statement from PostgreSQL regression test 'without_overlaps' (example 397).

CREATE TABLE temporal_fk2_rng2rng (
  id int4range,
  valid_at daterange,
  parent_id1 int4range,
  parent_id2 int4range,
  CONSTRAINT temporal_fk2_rng2rng_pk PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)
);

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


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

$$ language plpgsql;

select raise_test();

-- Since we can't actually see the thrown SQLSTATE in default psql output,
-- test it like this; this also tests re-RAISE

create or replace function raise_test() returns void as $$
begin
  raise 'check me'
     using errcode = 'division_by_zero', detail = 'some detail info';

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


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

ALTER EXTENSION pgtap ADD FUNCTION hasnt_table ( NAME, NAME, TEXT );

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


Question: Show a query using PostgreSQL contrib extension 'tablefunc' (example 8).

SELECT * FROM crosstab2('SELECT rowid, attribute, val FROM ct where rowclass = ''group1'' ORDER BY 1,2;');

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


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

insert into self_ref values (1, null), (2, 1), (3, 2);

Explanation: DML from PostgreSQL core regression test for Triggers.


Question: Write the DML statement from PostgreSQL regression test 'domain' (example 224).

Explanation: DML from PostgreSQL core regression test for Domain.


Question: Write the DDL statement from PostgreSQL regression test 'stats_ext' (example 685).

CREATE STATISTICS expr_stats_1 (mcv) ON a, b, (b || c), (c || b) FROM expr_stats;

Explanation: DDL from PostgreSQL core regression test for Stats Ext.


Question: PL/pgSQL test: Plperl (example 88).

CREATE OR REPLACE FUNCTION perl_get_cfield(orderedfootype, text) RETURNS integer AS $$
    return $_[0]->{$_[1]};
$$ LANGUAGE plperl;

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


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

CREATE FUNCTION seg_different(seg, seg)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

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


Question: PostgreSQL Ddl: show example 26.

CREATE TABLE products ( product_no integer CONSTRAINT must_be_different UNIQUE, name text, price numeric );

Explanation: Example from PostgreSQL documentation on Ddl.


Question: pgTAP test for Resultset (assertion 291).

-- Invert that.
SELECT * FROM check_test(
    results_eq(
        'anames_ord',
        'SELECT id, name FROM annames WHERE name <> ''Antonio'''
    ),
    false,
    'results_eq(prepared, select) fail missing first row',
    '',
    '    Results differ beginning at row 7:
        have: (183,Antonio)
        want: NULL'
);

Explanation: SQL assertion from pgTAP test suite for Resultset.


Question: pgTAP test for Hastap (assertion 54).

Explanation: SQL assertion from pgTAP test suite for Hastap.


Question: Write the DDL statement from PostgreSQL regression test 'update' (example 236).

CREATE TABLE sub_part1(b int, c int8, a numeric);

Explanation: DDL from PostgreSQL core regression test for Update.


Question: PostgreSQL regression test 'int8': Write the SELECT query (example 118).

SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 <> 456;

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

SELECT count(*) FROM (SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 <> 456) AS _sub;


Question: pgTAP test for Functap (assertion 179).

-- Test diagnostics
SELECT * FROM check_test(
    is_normal_function( 'someschema', 'nonesuch'::name ),
    false,
    'is_normal_function(schema, nofunc)',
    'Function someschema.nonesuch() should be a normal function',
    '    Function someschema.nonesuch() does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

SELECT reltoastrelid::regclass AS reltoastname FROM pg_class
  WHERE oid = 'toasttest'::regclass \gset
-- There should be two values inserted in the toast relation.
SELECT count(*) FROM :reltoastname WHERE chunk_seq = 0;

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

SELECT count(*) FROM (SELECT reltoastrelid::regclass AS reltoastname FROM pg_class
  WHERE oid = 'toasttest'::regclass \gset
-- There should be two values inserted in the toast relation.
SELECT count(*) FROM :reltoastname WHERE chunk_seq = 0) AS _sub;


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

create operator @= (
		leftarg = int4,
		rightarg = int4,
		procedure = tcl_int4eq
	);

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


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

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


Question: PostgreSQL Textsearch: show example 9.

SELECT title FROM pgweb WHERE to_tsvector(title || ' ' || body) @@ to_tsquery('create & table') ORDER BY last_mod_date DESC LIMIT 10;

Explanation: Example from PostgreSQL documentation on Textsearch.


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

SELECT interval '1 2.345' day to second(2);

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

SELECT count(*) FROM (SELECT interval '1 2.345' day to second(2)) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'cube' (example 145).

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


Question: Write the DML statement from PostgreSQL regression test 'fast_default' (example 36).

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


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

Explanation: DML from PostgreSQL core regression test for Numeric.


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

$$;

CALL ptest6a(1, null);
CALL ptest6a(1.1, null);

CREATE PROCEDURE ptest6b(a anyelement, out b anyelement, out c anyarray)
LANGUAGE SQL
AS $$
SELECT $1, array[$1];

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


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

SELECT date_trunc( 'timezone', timestamp '2004-02-29 15:44:17.71393' ) AS notsupp_trunc;

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

SELECT count(*) FROM (SELECT date_trunc( 'timezone', timestamp '2004-02-29 15:44:17.71393' ) AS notsupp_trunc) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'partition_merge' (example 276).

CREATE TABLE tp1 PARTITION OF t FOR VALUES WITH (MODULUS 2, REMAINDER 0);

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


Question: pgTAP test for Istap (assertion 10).

SELECT * FROM check_test( isnt( 1, 1 ), false, 'isnt(1, 1)', '', '        have: 1
        want: anything else' );

Explanation: SQL assertion from pgTAP test suite for Istap.


Question: Write the DML statement from PostgreSQL regression test 'partition_join' (example 363).

INSERT INTO prt2_adv SELECT i % 25, i, to_char(i, 'FM0000') FROM generate_series(100, 399) i;

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


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

CREATE VIEW mysecview9 WITH (security_invoker)
       AS SELECT * FROM tbl1 WHERE a < 100;

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


Question: PostgreSQL regression test 'unicode': Write the SELECT query (example 14).

SELECT num, val,
    val IS NFC NORMALIZED AS NFC,
    val IS NFD NORMALIZED AS NFD,
    val IS NFKC NORMALIZED AS NFKC,
    val IS NFKD NORMALIZED AS NFKD
FROM
  (VALUES (1, U&'\00E4bc'),
          (2, U&'\0061\0308bc'),
          (3, U&'\00E4\24D1c'),
          (4, U&'\0061\0308\24D1c'),
          (5, '')) vals (num, val)
ORDER BY num;

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

SELECT count(*) FROM (SELECT num, val,
    val IS NFC NORMALIZED AS NFC,
    val IS NFD NORMALIZED AS NFD,
    val IS NFKC NORMALIZED AS NFKC,
    val IS NFKD NORMALIZED AS NFKD
FROM
  (VALUES (1, U&'\00E4bc'),
          (2, U&'\0061\0308bc'),
          (3, U&'\00E4\24D1c'),
          (4, U&'\0061\0308\24D1c'),
          (5, '')) vals (num, val)
ORDER BY num) AS _sub;


Question: PostgreSQL regression test 'random': Write the SELECT query (example 11).

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


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

create table lp_ef partition of lp for values in ('e', 'f');

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


Question: Write the DDL statement from PostgreSQL regression test 'plpgsql' (example 716).

CREATE TRIGGER transition_table_base_upd_trig
  AFTER UPDATE ON transition_table_base
  REFERENCING OLD TABLE AS oldtable NEW TABLE AS newtable
  FOR EACH STATEMENT
  EXECUTE PROCEDURE transition_table_base_upd_func();

Explanation: DDL from PostgreSQL core regression test for Plpgsql.


Question: PostgreSQL regression test 'oid': Write the SELECT query (example 30).

SELECT * FROM pg_input_error_info('01 9999999999', 'oidvector');

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

SELECT count(*) FROM (SELECT * FROM pg_input_error_info('01 9999999999', 'oidvector')) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'constraints' (example 75).

INSERT INTO INSERT_CHILD(x,z,cy) VALUES (7,-7,6);

Explanation: DML from PostgreSQL core regression test for Constraints.


Question: pgTAP test for Resultset (assertion 25).

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

Explanation: SQL assertion from pgTAP test suite for Resultset.


Question: Show a query using PostgreSQL contrib extension 'pgstattuple' (example 53).

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


Question: Write the DDL statement from PostgreSQL regression test 'time' (example 1).

Explanation: DDL from PostgreSQL core regression test for Time.


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

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

SELECT count(*) FROM (select jsonb_path_query('true', '$.boolean()')) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'domain' (example 371).

Explanation: DML from PostgreSQL core regression test for Domain.


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

CREATE FUNCTION plperl_to_bool(val internal) RETURNS bool
LANGUAGE C STRICT IMMUTABLE
AS 'MODULE_PATHNAME';

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


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

CREATE INDEX idxcontact_person ON contact_person USING zombodb ((contact_person.*));

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


Question: PostgreSQL regression test 'rowtypes': Write the SELECT query (example 115).

select row(1, 3)::testtype1 *>= row(1, 2)::testtype1;

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

SELECT count(*) FROM (select row(1, 3)::testtype1 *>= row(1, 2)::testtype1) AS _sub;


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

-- _type_func(type, function, args[])
CREATE OR REPLACE FUNCTION _type_func ( "char", NAME, NAME[] )
RETURNS BOOLEAN AS $$
    SELECT kind = $1
      FROM tap_funky
     WHERE name = $2
       AND args = array_to_string($3, ',')
       AND is_visible;
$$ LANGUAGE SQL;

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


Question: Write the DDL statement from PostgreSQL regression test 'partition_merge' (example 342).

CREATE TABLE tp_2 (g int GENERATED ALWAYS AS (i + tableoid::int), i int);

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


Question: PostgreSQL regression test 'rangetypes': Write the SELECT query (example 193).

select count(*) from test_range_gist where ir -|- int4range(100,500);

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

SELECT count(*) FROM (select count(*) from test_range_gist where ir -|- int4range(100,500)) AS _sub;


Question: PostgreSQL Indices: show example 29.

Explanation: Example from PostgreSQL documentation on Indices.


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

SELECT citext_pattern_gt('a'::citext, 'b'::citext) AS false;

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


Question: Write the DDL statement from PostgreSQL regression test 'indexing' (example 67).

create index idxpart1_tst3 on idxpart1 (a, b) where a > 10;

Explanation: DDL from PostgreSQL core regression test for Indexing.


Question: Write the DDL statement from PostgreSQL regression test 'replica_identity' (example 5).

CREATE UNIQUE INDEX test_replica_identity_keyab_key ON test_replica_identity (keya, keyb);

Explanation: DDL from PostgreSQL core regression test for Replica Identity.


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

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

SELECT count(*) FROM (SELECT JSON_OBJECT(json '[1]': 123)) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'pg_stat_statements' (example 137).

SELECT ((composite_f(array[1, 2, 3]))).* FROM test_composite;

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


Question: pgTAP test for Resultset (assertion 102).

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

Explanation: SQL assertion from pgTAP test suite for Resultset.


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

SELECT count(*) FROM float4tmp WHERE a <  -179.0;

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


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

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

SELECT count(*) FROM (SELECT VARIANCE(val) FROM num_data) AS _sub;


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

select jsonb_path_query('null', '$.double()', silent => true);

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

SELECT count(*) FROM (select jsonb_path_query('null', '$.double()', silent => true)) AS _sub;


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

SELECT * FROM pg_input_error_info('[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]', 'pg_ndistinct');

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

SELECT count(*) FROM (SELECT * FROM pg_input_error_info('[{"attributes" : ["\ud83d", 2], "ndistinct" : 1}]', 'pg_ndistinct')) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'misc_functions' (example 55).

Explanation: DDL from PostgreSQL core regression test for Misc Functions.


Question: PostgreSQL regression test 'foreign_key': Write the SELECT query (example 1137).

SELECT tableoid::pg_catalog.regclass, * FROM fkpart11.fk_parted;

Explanation: Regression test for Foreign Key in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT tableoid::pg_catalog.regclass, * FROM fkpart11.fk_parted) AS _sub;


Question: PostgreSQL regression test 'pg_dependencies': Write the SELECT query (example 68).

SELECT * FROM pg_input_error_info('[{"attributes": [1,2], "dependency": 2, "degree": 1}]' , 'pg_dependencies');

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

SELECT count(*) FROM (SELECT * FROM pg_input_error_info('[{"attributes": [1,2], "dependency": 2, "degree": 1}]' , 'pg_dependencies')) AS _sub;


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

SELECT * FROM test_varchar WHERE i<='abc'::varchar ORDER BY i;

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


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

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

SELECT count(*) FROM (SELECT bool 'of' AS false) AS _sub;


Question: PostgreSQL regression test 'box': Write the SELECT query (example 53).

SELECT * FROM box_temp WHERE f1 @> '(10,11),(15,16)';

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

SELECT count(*) FROM (SELECT * FROM box_temp WHERE f1 @> '(10,11),(15,16)') AS _sub;


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

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


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

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

SELECT count(*) FROM (select * from tt15v) AS _sub;


Question: PostgreSQL regression test 'plpgsql': Write the SELECT query (example 671).

select consumes_rw_array(a), a from
  (values (returns_rw_array(1)), (returns_rw_array(2))) v(a);

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

SELECT count(*) FROM (select consumes_rw_array(a), a from
  (values (returns_rw_array(1)), (returns_rw_array(2))) v(a)) AS _sub;


Question: Show an example of PostgreSQL INSERT (example 16).

INSERT INTO distributors (did, dname) VALUES (13, 'Advanced Systems') ON CONFLICT (did) DO SELECT FOR UPDATE RETURNING *;

Explanation: PostgreSQL INSERT command.


Question: Write the DDL statement from PostgreSQL regression test 'foreign_data' (example 123).

CREATE USER MAPPING FOR current_user SERVER s5;

Explanation: DDL from PostgreSQL core regression test for Foreign Data.


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

CREATE FUNCTION hashismn13(ismn13)
	RETURNS int4
	AS 'hashint8'
	LANGUAGE 'internal'
	IMMUTABLE STRICT
	PARALLEL SAFE;

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


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

SELECT JSON_VALUE(jsonb '"1.23"', '$' RETURNING numeric);

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

SELECT count(*) FROM (SELECT JSON_VALUE(jsonb '"1.23"', '$' RETURNING numeric)) AS _sub;


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

end
$$ language plpgsql;

-- not enough parameters, should throw an error at parse time
create function namedparmcursor_test6() returns void as $$
declare
  c1 cursor (p1 int, p2 int) for
    select * from tenk1 where thousand = p1 and tenthous = p2;

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


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

SELECT * FROM get_users() WITH ORDINALITY;   -- make sure ordinality copes

-- multiple functions vs. dropped columns
SELECT * FROM ROWS FROM(generate_series(10,11), get_users()) WITH ORDINALITY;

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

SELECT count(*) FROM (SELECT * FROM get_users() WITH ORDINALITY;   -- make sure ordinality copes

-- multiple functions vs. dropped columns
SELECT * FROM ROWS FROM(generate_series(10,11), get_users()) WITH ORDINALITY) AS _sub;


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

drop function anyarray_anyrange_func(anyarray, anyrange);

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


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

CREATE TABLE equipment_r (
	name 		text,
	hobby		text
);

Explanation: DDL from PostgreSQL core regression test for Misc.


Question: PostgreSQL regression test 'create_cast': Write the SELECT query (example 7).

SELECT 1234::int4::casttesttype; -- Should work now

DROP FUNCTION int4_casttesttype(int4) CASCADE;

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

SELECT count(*) FROM (SELECT 1234::int4::casttesttype; -- Should work now

DROP FUNCTION int4_casttesttype(int4) CASCADE) AS _sub;


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

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

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


Question: PostgreSQL regression test 'select': Write the SELECT query (example 40).

SELECT * FROM foo ORDER BY f1 NULLS FIRST;

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

SELECT count(*) FROM (SELECT * FROM foo ORDER BY f1 NULLS FIRST) AS _sub;


Question: PostgreSQL regression test 'regproc': Write the SELECT query (example 3).

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

SELECT count(*) FROM (SELECT regoperator('+(int4,int4)')) AS _sub;


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

-- is_normal_function( function, args[] )
CREATE OR REPLACE FUNCTION is_normal_function( NAME, NAME[] )
RETURNS TEXT AS $$
    SELECT _func_compare(
        NULL, $1, $2, _type_func('f', $1, $2),
        'Function ' || quote_ident($1) || '(' ||
        array_to_string($2, ', ') || ') should be a normal function'
    );
$$ LANGUAGE sql;


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

SELECT count(*) FROM (select pg_get_viewdef('view_of_joins_2a', true)) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'file_fdw' (example 65).

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


Question: Show a query using PostgreSQL contrib extension 'ltree' (example 173).

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


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

select t1.* from
  text_tbl t1
  left join (select *, '***'::text as d1 from int8_tbl i8b1) b1
    left join int8_tbl i8
      left join (select *, null::int as d2 from int8_tbl i8b2, int4_tbl i4b2) b2
      on (i8.q1 = b2.q1)
    on (b2.d2 = b1.q2)
  on (t1.f1 = b1.d1)
  left join int4_tbl i4
  on (i8.q2 = i4.f1);

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

SELECT count(*) FROM (select t1.* from
  text_tbl t1
  left join (select *, '***'::text as d1 from int8_tbl i8b1) b1
    left join int8_tbl i8
      left join (select *, null::int as d2 from int8_tbl i8b2, int4_tbl i4b2) b2
      on (i8.q1 = b2.q1)
    on (b2.d2 = b1.q2)
  on (t1.f1 = b1.d1)
  left join int4_tbl i4
  on (i8.q2 = i4.f1)) AS _sub;


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

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


Question: Write the DML statement from PostgreSQL regression test 'interval' (example 16).

INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 10 day');

Explanation: DML from PostgreSQL core regression test for Interval.


Question: Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 1133).

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


Question: PostgreSQL regression test 'sqljson_jsontable': Write the SELECT query (example 26).

SELECT * FROM JSON_TABLE(jsonb '{"d1": "foo"}', '$'
    COLUMNS (js1 oid[] PATH '$.d2' DEFAULT '{1}'::int[]::oid[] ON EMPTY));

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

SELECT count(*) FROM (SELECT * FROM JSON_TABLE(jsonb '{"d1": "foo"}', '$'
    COLUMNS (js1 oid[] PATH '$.d2' DEFAULT '{1}'::int[]::oid[] ON EMPTY))) AS _sub;


Question: PostgreSQL Ddl: show example 54.

ALTER TABLE products ALTER COLUMN price SET DEFAULT 7.77;

Explanation: Example from PostgreSQL documentation on Ddl.


Question: PL/pgSQL test: Plperl Trigger (example 7).

insert into trigger_test values(1,'insert', '("(1)")');

Explanation: PL/pgSQL example from PostgreSQL source test for Plperl Trigger.


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

CREATE FUNCTION citext_pattern_gt( citext, citext )
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

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


Question: pgTAP test for Ownership (assertion 44).

SELECT * FROM check_test(
    relation_owner_is('__not__someseq', current_user, 'mumble'),
	false,
    'relation_owner_is(non-seq, user)',
    'mumble',
    '    Relation __not__someseq does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Ownership.


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

-- isnt_normal_function( function, args[], description )
CREATE OR REPLACE FUNCTION isnt_normal_function ( NAME, NAME[], TEXT )
RETURNS TEXT AS $$
    SELECT _func_compare(NULL, $1, $2, NOT _type_func('f', $1, $2), $3 );
$$ LANGUAGE SQL;


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

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

SELECT count(*) FROM (SELECT '-Infinity'::numeric::int8) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'select_views' (example 10).

Explanation: DML from PostgreSQL core regression test for Select Views.


Question: pgTAP test for Index (assertion 41).

SELECT * FROM check_test(
    has_index( 'public', 'sometab', 'idx_bar', ARRAY['name', 'id'], 'whatever' ),
    false,
    'has_index() invalid',
    'whatever',
    '        have: idx_bar ON public.sometab(numb, name)
        want: idx_bar ON public.sometab(name, id)'
);

Explanation: SQL assertion from pgTAP test suite for Index.


Question: PostgreSQL Ddl: show example 90.

CREATE TABLE measurement ( city_id int not null, logdate date not null, peaktemp int, unitsales int );


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

SELECT * FROM test_text WHERE i>'abc' ORDER BY i;

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


Question: pgTAP test for Aretap (assertion 91).

SELECT * FROM check_test(
    indexes_are( 'fou', ARRAY['idx_fou_id', 'idx_fou_name', 'howdy'] ),
    false,
    'indexes_are(table, indexes) + extra & missing',
    'Table fou should have the correct indexes',
    '    Extra indexes:
        fou_pkey
    Missing indexes:
        howdy'
);

Explanation: SQL assertion from pgTAP test suite for Aretap.


Question: pgTAP test for Privs (assertion 1).

\unset ECHO
\i test/setup.sql

SELECT plan(372);

Explanation: SQL assertion from pgTAP test suite for Privs.


Question: Show a SQL definition from the timescaledb project (metadata, item 2).

-- Trigger to change INSERT into UPDATE if key already exists.
--
-- During extension installation we create 3 entries in the metadata table which are
-- included in dumps. To allow loading logical dumps we need this trigger to turn INSERTs
-- into UPDATEs if the key already exists.
CREATE OR REPLACE FUNCTION _timescaledb_functions.metadata_insert_trigger() RETURNS TRIGGER LANGUAGE PLPGSQL
AS $$
BEGIN
  IF EXISTS (SELECT FROM _timescaledb_catalog.metadata WHERE key = NEW.key) THEN
    UPDATE _timescaledb_catalog.metadata SET value = NEW.value WHERE key = NEW.key;
    RETURN NULL;
  END IF;
  RETURN NEW;
END
$$ SET search_path TO pg_catalog, pg_temp;

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


Question: Write the DDL statement from PostgreSQL regression test 'compression' (example 27).

CREATE TABLE cminh() INHERITS (cmdata, cmdata3);

Explanation: DDL from PostgreSQL core regression test for Compression.


Question: Show a query using PostgreSQL contrib extension 'fuzzystrmatch' (example 31).

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


Question: Show a query using PostgreSQL contrib extension 'spi' (example 26).

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


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

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

SELECT count(*) FROM (SELECT parse_ident('.1020')) AS _sub;


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

-- default values are not allowed for output parameters
create function dfunc(out int = 20) returns int as $$
  select 1;
$$ language sql;

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


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

Explanation: DDL from PostgreSQL core regression test for Inherit.


Question: pgTAP test for Privs (assertion 62).

SELECT * FROM check_test(
    function_privs_are(
        'public', 'function_with_a_moderate_signature',
        ARRAY['anyelement','date','text[]','boolean'],
        current_user, ARRAY['EXECUTE'], 'whatever'
    ),
    true,
    'long function signature',
    'whatever',
    ''
);


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

-- insert, parent trigger sees post-modification parent-format tuple
insert into parent values ('AAA', 42), ('BBB', 42), ('CCC', 66);

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


Question: PostgreSQL regression test 'jsonpath': Write the SELECT query (example 142).

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

SELECT count(*) FROM (select '$ ? (@.a < +10.1e-1)'::jsonpath) AS _sub;


Question: Show a SQL definition from the citus project (coordinator_shouldhaveshards, item 10).

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


Question: Write the DML statement from PostgreSQL regression test 'partition_prune' (example 263).

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


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

Explanation: DML from PostgreSQL core regression test for Numeric.


Question: Show a query using PostgreSQL contrib extension 'bloom' (example 9).

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


Question: Write the DDL statement from PostgreSQL regression test 'rangefuncs' (example 322).

create or replace function testrngfunc() returns setof rngfunc_type as $$
  select 1, 2 union select 3, 4 order by 1;
$$ language sql immutable;

Explanation: DDL from PostgreSQL core regression test for Rangefuncs.


Question: PostgreSQL regression test 'partition_join': Write the SELECT query (example 373).

SELECT t1.a, t1.c, t2.b, t2.c FROM prt1_adv t1 INNER JOIN prt2_adv t2 ON (t1.a = t2.b) WHERE t1.a >= 100 AND t1.a < 300 AND t1.b = 0 ORDER BY t1.a, t2.b;

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

SELECT count(*) FROM (SELECT t1.a, t1.c, t2.b, t2.c FROM prt1_adv t1 INNER JOIN prt2_adv t2 ON (t1.a = t2.b) WHERE t1.a >= 100 AND t1.a < 300 AND t1.b = 0 ORDER BY t1.a, t2.b) AS _sub;


Question: PostgreSQL regression test 'misc_functions': Write the SELECT query (example 20).

Explanation: Regression test for Misc Functions in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT num_nulls(VARIADIC NULL::text[])) AS _sub;


Question: pgTAP test for Index (assertion 60).

SELECT * FROM check_test(
    index_is_unique( 'public', 'sometab', 'sometab_pkey' ),
    true,
    'index_is_unique() on pk no desc',
    'Index sometab_pkey should be unique',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Index.


Question: PL/pgSQL test: Plpython Error (example 17).

/* for what it's worth catch the exception generated by
 * the typo, and reraise it as a plain error
 */
CREATE FUNCTION invalid_type_reraised(a text) RETURNS text
	AS
'if "plan" not in SD:
	q = "SELECT fname FROM users WHERE lname = $1"
	try:
		SD["plan"] = plpy.prepare(q, [ "test" ])
	except plpy.SPIError as ex:
		plpy.error(str(ex))
rv = plpy.execute(SD["plan"], [ a ])
if len(rv):
	return rv[0]["fname"]
return None
'
	LANGUAGE plpython3u;

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


Question: Write the DDL statement from PostgreSQL regression test 'memoize' (example 49).

Explanation: DDL from PostgreSQL core regression test for Memoize.


Question: PostgreSQL regression test 'tsearch': Write the SELECT query (example 430).

select websearch_to_tsquery('simple', 'fat or ');

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

SELECT count(*) FROM (select websearch_to_tsquery('simple', 'fat or ')) AS _sub;


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

CREATE FUNCTION isnle(ean13, issn)
	RETURNS boolean
	AS 'int8le'
	LANGUAGE 'internal'
	IMMUTABLE STRICT
	PARALLEL SAFE;

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


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

SELECT JSON_EXISTS(jsonb '[1, "aaa", {"a": 1}]', 'strict $.a'); -- FALSE on error
SELECT JSON_EXISTS(jsonb '[1, "aaa", {"a": 1}]', 'lax $.a');

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

SELECT count(*) FROM (SELECT JSON_EXISTS(jsonb '[1, "aaa", {"a": 1}]', 'strict $.a'); -- FALSE on error
SELECT JSON_EXISTS(jsonb '[1, "aaa", {"a": 1}]', 'lax $.a')) AS _sub;


Question: PostgreSQL Xfunc: show example 38.

CREATE FUNCTION add_em(integer, integer) RETURNS integer AS $$ SELECT $1 + $2; $$ LANGUAGE SQL; SELECT add_em(1, 2) AS answer; answer -------- 3;

Explanation: Example from PostgreSQL documentation on Xfunc.


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

$$ language plpgsql immutable strict;

select * from tftest(10);

drop function tftest(int);

create function rttest()
returns setof int as $$
declare rc int;

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


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

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

SELECT count(*) FROM (select jsonb_path_query('{}', '$.integer()')) AS _sub;


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

select count(*) from testhstore where h = 'pos=>98, line=>371, node=>CBA, indexed=>t';

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


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

-- complex numbers -> jsonb
CREATE FUNCTION testComplexNumbers() RETURNS jsonb
LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb
AS $$
x = 1 + 2j
return x
$$;

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


Question: Write the DDL statement from PostgreSQL regression test 'event_trigger' (example 65).

create table rewriteme (id serial primary key, foo float, bar timestamptz);

Explanation: DDL from PostgreSQL core regression test for Event Trigger.


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

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

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

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


Question: Write the DDL statement from PostgreSQL regression test 'rowsecurity' (example 969).

CREATE POLICY p1 ON r1 FOR SELECT USING (a < 20);

Explanation: DDL from PostgreSQL core regression test for Rowsecurity.


Question: Write the DML statement from PostgreSQL regression test 'subselect' (example 63).

Explanation: DML from PostgreSQL core regression test for Subselect.


Question: PL/pgSQL test: Plpgsql--1.0 (example 2).

CREATE FUNCTION plpgsql_inline_handler(internal) RETURNS void
  STRICT LANGUAGE c AS 'MODULE_PATHNAME';

Explanation: PL/pgSQL example from PostgreSQL source test for Plpgsql--1.0.


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

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


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

INSERT INTO temporal_fk_rng2rng (id, valid_at, parent_id) VALUES ('[4,5)', daterange('2018-01-01', '2021-01-01'), '[6,7)');

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


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

CREATE FUNCTION zdb.schema_version() RETURNS text LANGUAGE sql AS $$
SELECT '3000.1.2 (3e8ab0d2fba60cc51a84761b1fa438e6098db7bb)'
$$;

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


Question: Write the DML statement from PostgreSQL regression test 'rangetypes' (example 114).

INSERT INTO numrange_test2 VALUES(numrange(1.1, 2.2));

Explanation: DML from PostgreSQL core regression test for Rangetypes.


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

SELECT 'À'::text   =  'à'::text   AS f; -- text wins.
SELECT 'À'::citext <> 'B'::citext AS t;

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


Question: pgTAP test for Ownership (assertion 121).

SELECT * FROM check_test(
    opclass_owner_is('int4_ops', _get_opclass_owner('int4_ops'), 'mumble'),
	true,
    'opclass_owner_is(opclass, user, desc)',
    'mumble',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Ownership.


Question: PostgreSQL regression test 'indexing': Write the SELECT query (example 13).

select relname, relkind, relhassubclass, inhparent::regclass
    from pg_class left join pg_index ix on (indexrelid = oid)
	left join pg_inherits on (ix.indexrelid = inhrelid)
	where relname like 'idxpart%' order by relname;

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

SELECT count(*) FROM (select relname, relkind, relhassubclass, inhparent::regclass
    from pg_class left join pg_index ix on (indexrelid = oid)
	left join pg_inherits on (ix.indexrelid = inhrelid)
	where relname like 'idxpart%' order by relname) AS _sub;


Question: PL/pgSQL test: Plpgsql Call (example 73).

-- Check that stable functions in CALL see the correct snapshot

CREATE TABLE t_test (x int);

Explanation: PL/pgSQL example from PostgreSQL source test for Plpgsql Call.


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

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


Question: pgTAP test for Valueset (assertion 315).

-- Fail with incompatible columns.
SELECT * FROM check_test(
    set_ne(
        'justnames',
        ARRAY[1, 2, 3]
    ),
    false,
    'set_ne(sql, array) incompatible types',
    '',
    '    Columns differ between queries:
        have: (text)
        want: (integer)'
);

Explanation: SQL assertion from pgTAP test suite for Valueset.


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

SELECT * FROM verify_heapam(relation := 'heaptest', skip := 'ALL-FROZEN');

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


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

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

SELECT count(*) FROM (select jsonb '2' @@ '1') AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'returning' (example 13).

DELETE FROM foo
  USING int4_tbl i
  WHERE foo.f1 + 123455 = i.f1
  RETURNING foo.*, i.f1 as "i.f1";

Explanation: DML from PostgreSQL core regression test for Returning.


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

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


Question: PostgreSQL regression test 'xml': Write the SELECT query (example 110).

SELECT xml '<foo>bar</foo>' IS DOCUMENT;

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

SELECT count(*) FROM (SELECT xml '<foo>bar</foo>' IS DOCUMENT) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'copy' (example 107).

CREATE TABLE parted_si_p_even PARTITION OF parted_si FOR VALUES IN (0);

Explanation: DDL from PostgreSQL core regression test for Copy.


Question: Write the DDL statement from PostgreSQL regression test 'case' (example 48).

CREATE OPERATOR = (procedure = inline_eq,
                   leftarg = foodomain, rightarg = foodomain);

Explanation: DDL from PostgreSQL core regression test for Case.


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

SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd";

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

SELECT count(*) FROM (SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd") AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'foreign_key' (example 796).

create table fkpart0.fk_part_4 partition of fkpart0.fk_part for values in (4);

Explanation: DDL from PostgreSQL core regression test for Foreign Key.


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

SELECT * FROM test_numeric WHERE i>='1'::numeric ORDER BY i;

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


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

SELECT extract(epoch from '294270-01-01 00:00:00'::timestamp);

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

SELECT count(*) FROM (SELECT extract(epoch from '294270-01-01 00:00:00'::timestamp)) AS _sub;


Question: PostgreSQL regression test 'arrays': Write the SELECT query (example 186).

SELECT * FROM array_op_test WHERE t @> '{AAAAAAAA72908,AAAAAAAAAA646}' ORDER BY seqno;

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

SELECT count(*) FROM (SELECT * FROM array_op_test WHERE t @> '{AAAAAAAA72908,AAAAAAAAAA646}' ORDER BY seqno) AS _sub;


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

SELECT * FROM pg_input_error_info('[{"attributes" : [1, {"a": 1}], "ndistinct" : 1}]', 'pg_ndistinct');

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

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


Question: Write the DDL statement from PostgreSQL regression test 'create_type' (example 65).

CREATE TYPE myvarchar (
    input = myvarcharin,
    output = myvarcharout,
    alignment = integer,
    storage = main
);

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


Question: Write the DML statement from PostgreSQL regression test 'collate.windows.win1252' (example 52).

Explanation: DML from PostgreSQL core regression test for Collate.Windows.Win1252.


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

CREATE FUNCTION isnge(isbn, ean13)
	RETURNS boolean
	AS 'int8ge'
	LANGUAGE 'internal'
	IMMUTABLE STRICT
	PARALLEL SAFE;

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


Question: pgTAP test for Index (assertion 47).

Explanation: SQL assertion from pgTAP test suite for Index.


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

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


Question: PostgreSQL regression test 'jsonpath': Write the SELECT query (example 108).

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

SELECT count(*) FROM (select '$ ? (@.a < -1)'::jsonpath) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'indexing' (example 515).

create index parted_isvalid_idx on parted_isvalid_tab ((a/b));

Explanation: DDL from PostgreSQL core regression test for Indexing.


Question: PostgreSQL regression test 'inet': Write the SELECT query (example 112).

SELECT * FROM pg_input_error_info('1234', 'cidr');

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

SELECT count(*) FROM (SELECT * FROM pg_input_error_info('1234', 'cidr')) AS _sub;


Question: pgTAP test for Usergroup (assertion 34).

SELECT * FROM check_test(
    is_member_of('meanies', current_user ),
    true,
    'is_member_of(meanies, current_user)',
    'Should have members of role meanies',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Usergroup.


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

$$ language plpgsql;

select stacked_diagnostics_test();

-- fail, cannot use stacked diagnostics statement outside handler
create or replace function stacked_diagnostics_test() returns void as $$
declare _detail text;

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


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

CREATE TYPE tablefunc_crosstab_4 AS
(
	row_name TEXT,
	category_1 TEXT,
	category_2 TEXT,
	category_3 TEXT,
	category_4 TEXT
);


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

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


Question: PostgreSQL regression test 'create_function_sql': Write the SELECT query (example 83).

SELECT double_append(array_append(ARRAY[q1], q2), q3)
  FROM (VALUES(1,2,3), (4,5,6)) v(q1,q2,q3);

Explanation: Regression test for Create Function Sql in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT double_append(array_append(ARRAY[q1], q2), q3)
  FROM (VALUES(1,2,3), (4,5,6)) v(q1,q2,q3)) AS _sub;


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

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


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

ALTER EXTENSION pgtap ADD FUNCTION col_type_is ( NAME, NAME, TEXT, TEXT );

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


Question: Show a query using PostgreSQL contrib extension 'ltree' (example 201).

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


Question: PL/pgSQL test: Plpgsql Record (example 48).

Explanation: PL/pgSQL example from PostgreSQL source test for Plpgsql Record.


Question: PostgreSQL Rules: show example 53.

INSERT INTO shoelace_log SELECT s.sl_name, s.sl_avail + shoelace_arrive.arr_quant, current_user, current_timestamp FROM shoelace_arrive shoelace_arrive, shoelace_data shoelace_data, shoelace_data s WHERE s.sl_name = shoelace_arrive.arr_name AND shoelace_data.sl_name = s.sl_name AND s.sl_avail + shoelace_arrive.arr_quant <> s.sl_avail; UPDATE shoelace_data SET sl_avail = shoelace_data.sl_avail + shoelace_arrive.arr_quant FROM shoelace_arrive shoelace_arrive, shoelace_data shoelace_data, shoelace_data s WHERE s.sl_name = shoelace_arrive.sl_name AND shoelace_data.sl_name = s.sl_name;

Explanation: Example from PostgreSQL documentation on Rules.


Question: PostgreSQL regression test 'float8': Write the SELECT query (example 27).

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

SELECT count(*) FROM (SELECT 'infinity'::float8) AS _sub;


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

UPDATE  temporal_mltrng3
SET     id = '[1,2)',
        valid_at = NULL
WHERE   id IS NULL AND valid_at @> '2020-06-01'::date;

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


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

SELECT * FROM nummultirange_test WHERE nmr > '{[-1000.0, -1000.0]}';

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

SELECT count(*) FROM (SELECT * FROM nummultirange_test WHERE nmr > '{[-1000.0, -1000.0]}') AS _sub;


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

CREATE FUNCTION regexp_split_to_array( citext, citext, text ) RETURNS TEXT[] AS $$
    SELECT pg_catalog.regexp_split_to_array( $1::pg_catalog.text, $2::pg_catalog.text, CASE WHEN pg_catalog.strpos($3, 'c') = 0 THEN  $3 || 'i' ELSE $3 END );
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;

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


Question: PostgreSQL regression test 'tsearch': Write the SELECT query (example 423).

select websearch_to_tsquery('simple', 'fat or(rat');

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

SELECT count(*) FROM (select websearch_to_tsquery('simple', 'fat or(rat')) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'test_setup' (example 26).

INSERT INTO VARCHAR_TBL (f1) VALUES
  ('a'),
  ('ab'),
  ('abcd'),
  ('abcd    ');

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


Question: pgTAP test for Functap (assertion 76).

SELECT * FROM check_test(
    function_lang_is( 'yay', 'sql' ),
    true,
    'function_lang_is(func, sql)',
    'Function yay() should be written in sql',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


Question: Write the DDL statement from PostgreSQL regression test 'select_parallel' (example 77).

create table bmscantest (a int, t text);

Explanation: DDL from PostgreSQL core regression test for Select Parallel.


Question: PostgreSQL Textsearch: show example 59.

SELECT alias, description, token FROM ts_debug('http://example.com/stuff/index.html'); alias | description | token ----------+---------------+------------------------------ protocol | Protocol head | http:// url | URL | example.com/stuff/index.html host | Host | example.com url_path | URL path | /stuff/index.html;

Explanation: Example from PostgreSQL documentation on Textsearch.


Question: Write the DML statement from PostgreSQL regression test 'foreign_key' (example 467).

Explanation: DML from PostgreSQL core regression test for Foreign Key.


Question: Write the DML statement from PostgreSQL regression test 'identity' (example 48).

INSERT INTO itest2 OVERRIDING SYSTEM VALUE VALUES (20, 'xyz');

Explanation: DML from PostgreSQL core regression test for Identity.


Question: Show a SQL definition from the pg_partman project (test-time-daily, item 11).

CREATE TABLE partman_test.time_taptest_table
    (col1 int
        , col2 text default 'stuff'
        , col3 timestamptz NOT NULL DEFAULT now()
        , CONSTRAINT fk_test FOREIGN KEY (col2) REFERENCES partman_test.fk_test_reference(col2) )
    PARTITION BY RANGE (col3);

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


Question: Write the DML statement from PostgreSQL regression test 'partition_split' (example 112).

INSERT INTO salespeople VALUES
  (1,  'Poirot'),
  (10, 'May'),
  (19, 'Ivanov'),
  (20, 'Smirnoff'),
  (30, 'Ford');

Explanation: DML from PostgreSQL core regression test for Partition Split.


Question: PostgreSQL regression test 'horology': Write the SELECT query (example 61).

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

SELECT count(*) FROM (SELECT time without time zone 'T04') AS _sub;


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

CREATE TABLE sales_feb2022 PARTITION OF sales_range FOR VALUES FROM ('2022-02-01') TO ('2022-03-01');

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


Question: PostgreSQL regression test 'date': Write the SELECT query (example 166).

SELECT f1 - date 'epoch' AS "Days From Epoch" FROM DATE_TBL;

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

SELECT count(*) FROM (SELECT f1 - date 'epoch' AS "Days From Epoch" FROM DATE_TBL) AS _sub;


Question: PostgreSQL regression test 'tsrf': Write the SELECT query (example 61).

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

SELECT count(*) FROM (SELECT 1 LIMIT generate_series(1,3)) AS _sub;


Question: PostgreSQL regression test 'tsearch': Write the SELECT query (example 413).

select websearch_to_tsquery('english', 'My brand "new -smartphone"');

SELECT count(*) FROM (select websearch_to_tsquery('english', 'My brand "new -smartphone"')) AS _sub;


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

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

SELECT count(*) FROM (SELECT pg_input_is_valid('garbage', 'interval')) AS _sub;


Question: PostgreSQL Indices: show example 14.

CREATE INDEX access_log_client_ip_ix ON access_log (client_ip) WHERE NOT (client_ip > inet '192.168.100.0' AND client_ip < inet '192.168.100.255');

Explanation: Example from PostgreSQL documentation on Indices.


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

CREATE TABLE hash_name_heap (
	seqno 		int4,
	random 		name
);

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


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

INSERT INTO num_exp_sub VALUES (8,3,'74876.69');

Explanation: DML from PostgreSQL core regression test for Numeric.


Question: Show a SQL definition from the timescaledb project (multi_transaction_index, item 22).

CREATE INDEX a_hypertable_index_with_a_very_very_long_name_that_truncates_2 ON index_test (time DESC, temp ASC) WITH (timescaledb.transaction_per_chunk);

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


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

SELECT JSON_SERIALIZE('123' RETURNING sqljson_char2);

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

SELECT count(*) FROM (SELECT JSON_SERIALIZE('123' RETURNING sqljson_char2)) AS _sub;


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

ALTER EXTENSION pgtap ADD FUNCTION add_result ( bool, bool, text, text, text );

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


Question: Show a SQL definition from the timescaledb project (drop_extension, item 11).

-- Test that calling twice generates proper error
\set ON_ERROR_STOP 0
CREATE EXTENSION timescaledb;


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

INSERT INTO num_input_test(n1) VALUES ('.000_000_000_123e1_0');


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

SELECT JSON_OBJECTAGG(k: v WITH UNIQUE KEYS RETURNING jsonb)
FROM (VALUES (1, 1), (1, NULL), (2, 2)) foo(k, v);

SELECT count(*) FROM (SELECT JSON_OBJECTAGG(k: v WITH UNIQUE KEYS RETURNING jsonb)
FROM (VALUES (1, 1), (1, NULL), (2, 2)) foo(k, v)) AS _sub;


Question: Show a SQL definition from the timescaledb project (chunk_utils, item 1).

-- Set this variable to avoid using a hard-coded path each time query
-- results are compared
\set QUERY_RESULT_TEST_EQUAL_RELPATH 'include/query_result_test_equal.sql'

CREATE OR REPLACE FUNCTION dimension_get_time(
    hypertable_id INT
)
    RETURNS _timescaledb_catalog.dimension LANGUAGE SQL STABLE AS
$BODY$
    SELECT *
    FROM _timescaledb_catalog.dimension d
    WHERE d.hypertable_id = dimension_get_time.hypertable_id AND
          d.interval_length IS NOT NULL
$BODY$;


Question: PostgreSQL regression test 'type_sanity': Write the SELECT query (example 66).

SELECT r.rngtypid, r.rngsubtype, p.proname
FROM pg_range r JOIN pg_proc p ON p.oid = r.rngmltconstruct1 JOIN pg_type t ON r.rngmultitypid = t.oid
WHERE p.pronargs != 1
    OR p.proargtypes[0] != r.rngtypid
    OR p.prorettype != r.rngmultitypid
    OR p.proname != t.typname OR p.prosrc != 'multirange_constructor1';

Explanation: Regression test for Type Sanity in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT r.rngtypid, r.rngsubtype, p.proname
FROM pg_range r JOIN pg_proc p ON p.oid = r.rngmltconstruct1 JOIN pg_type t ON r.rngmultitypid = t.oid
WHERE p.pronargs != 1
    OR p.proargtypes[0] != r.rngtypid
    OR p.prorettype != r.rngmultitypid
    OR p.proname != t.typname OR p.prosrc != 'multirange_constructor1') AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'memoize' (example 25).

Explanation: DDL from PostgreSQL core regression test for Memoize.


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

SELECT id FROM test_tablesample TABLESAMPLE SYSTEM (50) REPEATABLE (NULL);

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

SELECT count(*) FROM (SELECT id FROM test_tablesample TABLESAMPLE SYSTEM (50) REPEATABLE (NULL)) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'tablesample' (example 48).

INSERT INTO test_tablesample_v1 VALUES(1);

Explanation: DML from PostgreSQL core regression test for Tablesample.


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

select q1, float8(count(*)) / (select count(*) from int8_tbl)
from int8_tbl group by q1 order by q1;

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

SELECT count(*) FROM (select q1, float8(count(*)) / (select count(*) from int8_tbl)
from int8_tbl group by q1 order by q1) AS _sub;


Question: Show a SQL definition from the citus project (multi_alter_table_add_constraints, item 50).

-- Check "UNIQUE CONSTRAINT" with append table
CREATE TABLE unique_test_table_append(id int, name varchar(20));

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


Question: pgTAP test for Functap (assertion 187).

-- test diagnostics
SELECT * FROM check_test(
    is_normal_function( 'nonesuch', '{}'::name[], 'whatever' ),
    false,
    'is_normal_function(nofunc, noargs, desc)',
    'whatever',
    '    Function nonesuch() does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Functap.


Question: PostgreSQL regression test 'sqljson_jsontable': Write the SELECT query (example 14).

SELECT * FROM JSON_TABLE(jsonb'"1.23"', 'strict $.a' COLUMNS (js2 int PATH '$'));

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

SELECT count(*) FROM (SELECT * FROM JSON_TABLE(jsonb'"1.23"', 'strict $.a' COLUMNS (js2 int PATH '$'))) AS _sub;


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

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

SELECT count(*) FROM (select dfunc(10, 20)) AS _sub;


Question: PostgreSQL regression test 'rangetypes': Write the SELECT query (example 150).

SELECT * FROM textrange_test WHERE 'e'::text <@ tr;

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

SELECT count(*) FROM (SELECT * FROM textrange_test WHERE 'e'::text <@ tr) AS _sub;


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

select row(1, 2)::testtype1 <> row(1)::testtype5;

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

SELECT count(*) FROM (select row(1, 2)::testtype1 <> row(1)::testtype5) AS _sub;


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

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

SELECT count(*) FROM (SELECT m * 2::float8 FROM money_data) AS _sub;


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

CREATE TABLE dropped_objects (
	object_type text,
	schema_name text,
	object_name text,
	object_identity text,
	address_names text[],
	address_args text[],
	is_temporary bool,
	original bool,
	normal bool
);

Explanation: DDL from PostgreSQL core regression test for Event Trigger.


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

SELECT substr('alphabet'::citext, 3)       = 'phabet' AS t;

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


Question: PostgreSQL regression test 'indexing': Write the SELECT query (example 3).

select relhassubclass from pg_class where relname = 'idxpart_idx';

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

SELECT count(*) FROM (select relhassubclass from pg_class where relname = 'idxpart_idx') AS _sub;


Question: Show an example of PostgreSQL UPDATE (example 1).

UPDATE films SET kind = 'Dramatic' WHERE kind = 'Drama';

Explanation: PostgreSQL UPDATE command.


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

CREATE FUNCTION isngt(ean13, upc)
	RETURNS boolean
	AS 'int8gt'
	LANGUAGE 'internal'
	IMMUTABLE STRICT
	PARALLEL SAFE;

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


Question: PostgreSQL regression test 'aggregates': Write the SELECT query (example 102).

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

SELECT count(*) FROM (SELECT float8_combine('{0,0,0}'::float8[], '{2,180,200}'::float8[])) AS _sub;


Question: PostgreSQL Textsearch: show example 12.

CREATE INDEX pgweb_idx ON pgweb USING GIN (to_tsvector('english', title || ' ' || body));

Explanation: Example from PostgreSQL documentation on Textsearch.


Question: PostgreSQL regression test 'jsonpath': Write the SELECT query (example 55).

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

SELECT count(*) FROM (select '$.last'::jsonpath) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'pg_stat_statements' (example 85).

SELECT WHERE 1 IN (1::int::bigint::int, 2::int::bigint::int);

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


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

CREATE INDEX tenk2_unique1 ON tenk2 USING btree(unique1 int4_ops);

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


Question: Show a query using PostgreSQL contrib extension 'test_decoding' (example 58).

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


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

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

SELECT count(*) FROM (SELECT JSON_OBJECT(1::text: 2)) AS _sub;


Question: pgTAP test for Pgtap--0.94.0--0.95.0 (assertion 17).

-- has_materialized_view( schema, materialized_view, description )
CREATE OR REPLACE FUNCTION has_materialized_view ( NAME, NAME, TEXT )
RETURNS TEXT AS $$
    SELECT ok( _rexists( 'm', $1, $2 ), $3 );
$$ LANGUAGE SQL;

Explanation: SQL assertion from pgTAP test suite for Pgtap--0.94.0--0.95.0.


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

-- create separate functional dependencies
CREATE STATISTICS functional_dependencies_multi_1 (dependencies) ON a, b FROM functional_dependencies_multi;

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


Question: Write the DDL statement from PostgreSQL regression test 'create_table_like' (example 93).

CREATE TABLE ctlt12_storage (LIKE ctlt1 INCLUDING STORAGE, LIKE ctlt2 INCLUDING STORAGE);

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


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

select jsonb_path_query('"10-03-2017 12:34 -05:20"', '$.datetime("dd-mm-yyyy HH24:MI TZH:TZM")');

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

SELECT count(*) FROM (select jsonb_path_query('"10-03-2017 12:34 -05:20"', '$.datetime("dd-mm-yyyy HH24:MI TZH:TZM")')) AS _sub;


Question: pgTAP test for Pgtap--0.91.0--0.92.0 (assertion 15).

CREATE OR REPLACE FUNCTION _get_rel_owner ( NAME, NAME )
RETURNS NAME AS $$
    SELECT pg_catalog.pg_get_userbyid(c.relowner)
      FROM pg_catalog.pg_class c
      JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
     WHERE n.nspname = $1
       AND c.relname = $2
$$ LANGUAGE SQL;

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


Question: Write the DDL statement from PostgreSQL regression test 'multirangetypes' (example 69).

CREATE INDEX nummultirange_test_btree ON nummultirange_test(nmr);

Explanation: DDL from PostgreSQL core regression test for Multirangetypes.


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

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


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

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


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

insert into parted values (1, 1, 'uno uno v6');

Explanation: DML from PostgreSQL core regression test for Triggers.


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

SELECT * FROM test_date WHERE i>'infinity'::timestamptz ORDER BY i;

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


Question: PostgreSQL regression test 'rowtypes': Write the SELECT query (example 67).

select a,b from test_table where (a,b) > ('a','a') order by a,b;

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

SELECT count(*) FROM (select a,b from test_table where (a,b) > ('a','a') order by a,b) AS _sub;


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

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


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

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


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

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


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

SELECT nummultirange(numrange(1,2), numrange(7,8)) && nummultirange(numrange(3,4));

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

SELECT count(*) FROM (SELECT nummultirange(numrange(1,2), numrange(7,8)) && nummultirange(numrange(3,4))) AS _sub;


Question: PostgreSQL regression test 'tsearch': Write the SELECT query (example 183).

SELECT count(*) FROM test_tsvector WHERE a @@ 'wr' AND a @@ '!qh';

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

SELECT count(*) FROM (SELECT count(*) FROM test_tsvector WHERE a @@ 'wr' AND a @@ '!qh') AS _sub;


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

SELECT count(*) FROM (select jsonb_path_query('1', '$.date()')) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'merge' (example 371).

INSERT INTO pa_target SELECT id, id * 100, 'initial' FROM generate_series(1,15,2) AS id;

Explanation: DML from PostgreSQL core regression test for Merge.


Question: Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 1441).

SELECT a FROM base_tbl WHERE (a, random() > 0) IN (SELECT a, random() > 0 FROM foreign_tbl);

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


Question: PostgreSQL regression test 'xmlmap': Write the SELECT query (example 8).

SELECT table_to_xml('testxmlschema.test1', false, false, '');

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

SELECT count(*) FROM (SELECT table_to_xml('testxmlschema.test1', false, false, '')) AS _sub;


Question: PostgreSQL regression test 'limit': Write the SELECT query (example 6).

SELECT ''::text AS eleven, unique1, unique2, stringu1
		FROM onek WHERE unique1 < 50
		ORDER BY unique1 DESC LIMIT 20 OFFSET 39;

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

SELECT count(*) FROM (SELECT ''::text AS eleven, unique1, unique2, stringu1
		FROM onek WHERE unique1 < 50
		ORDER BY unique1 DESC LIMIT 20 OFFSET 39) AS _sub;


Question: PostgreSQL regression test 'foreign_data': Write the SELECT query (example 269).

Explanation: Regression test for Foreign Data in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT has_server_privilege('s8', 'USAGE')) AS _sub;


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

CREATE OPERATOR <> (
	PROCEDURE = isnne,
	LEFTARG = isbn,
	RIGHTARG = isbn13,
	COMMUTATOR = <>,
	NEGATOR = =,
	RESTRICT = neqsel,
	JOIN = neqjoinsel);

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


Question: PostgreSQL regression test 'aggregates': Write the SELECT query (example 387).

select percentile_disc(array[[null,1,0.5],[0.75,0.25,null]]) within group (order by thousand)
from tenk1;

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

SELECT count(*) FROM (select percentile_disc(array[[null,1,0.5],[0.75,0.25,null]]) within group (order by thousand)
from tenk1) AS _sub;


Question: PostgreSQL regression test 'jsonpath': Write the SELECT query (example 75).

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

SELECT count(*) FROM (select '$.time(6)'::jsonpath) AS _sub;


Question: Show an example of PostgreSQL CREATE CAST (example 1).

Explanation: PostgreSQL CREATE CAST command.


Question: Show a query using PostgreSQL contrib extension 'seg' (example 120).

SELECT '0 .. 1'::seg << '1'::seg AS bool;

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


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

select numrange(3,6) >> nummultirange(numrange(3,4));

SELECT count(*) FROM (select numrange(3,6) >> nummultirange(numrange(3,4))) AS _sub;


Question: Show an example of PostgreSQL CREATE SCHEMA (example 1).

Explanation: PostgreSQL CREATE SCHEMA command.


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

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

SELECT count(*) FROM (select '["a","b","c"]'::jsonb - 0) AS _sub;


Question: pgTAP test for Proctap (assertion 65).

SELECT * FROM check_test(
    is_procedure( 'argpubfunc', 'whatever' ),
    false,
    'is_procedure(func, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Proctap.


Question: Show an example of PostgreSQL CREATEUSER (example 3).

$ createuser -h eden -p 5000 -S -D -R -e joe CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;

Explanation: PostgreSQL CREATEUSER command.


Question: PostgreSQL regression test 'horology': Write the SELECT query (example 62).

SELECT time with time zone '040506.07+08';

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

SELECT count(*) FROM (SELECT time with time zone '040506.07+08') AS _sub;


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

ALTER EXTENSION pgtap ADD FUNCTION todo_start ();

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


Question: PostgreSQL regression test 'arrays': Write the SELECT query (example 228).

select * from arr_tbl where f1 > '{1,2,3}' and f1 <= '{1,5,3}';

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

SELECT count(*) FROM (select * from arr_tbl where f1 > '{1,2,3}' and f1 <= '{1,5,3}') AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'rowsecurity' (example 267).

CREATE POLICY d1 ON dependent FOR ALL
    TO PUBLIC
    USING (x = (SELECT d.x FROM dependee d WHERE d.y = y));

Explanation: DDL from PostgreSQL core regression test for Rowsecurity.


Question: PostgreSQL regression test 'plpgsql': Write the SELECT query (example 615).

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

SELECT count(*) FROM (select * from conflict_test()) AS _sub;


Question: PL/pgSQL test: Plperl Transaction (example 17).

-- commit inside cursor loop
CREATE TABLE test2 (x int);

Explanation: PL/pgSQL example from PostgreSQL source test for Plperl Transaction.


Question: PostgreSQL regression test 'stats_ext': Write the SELECT query (example 204).

SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (2*c)');

Explanation: Regression test for Stats Ext in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (2*c)')) AS _sub;


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

SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'Europe/Moscow';

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

SELECT count(*) FROM (SELECT '2014-10-26 01:00:01'::timestamp AT TIME ZONE 'Europe/Moscow') AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'psql' (example 218).

create table child_35_40 partition of child_30_40
   for values from (35) to (40);

Explanation: DDL from PostgreSQL core regression test for Psql.


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

create table mc2p5 partition of mc2p for values from (2, maxvalue) to (maxvalue, maxvalue);

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


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

CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
AS $$
try:
    with plpy.subtransaction() as s:
        s.__exit__(None, None, None)
except ValueError as e:
    raise ValueError(e)
$$ LANGUAGE plpython3u;

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


Question: Write the DML statement from PostgreSQL regression test 'publication' (example 599).

INSERT INTO pub_testpart1.child_parent2 values(1);

Explanation: DML from PostgreSQL core regression test for Publication.


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

select range_intersect_agg(nmr) from (values ('{}'::nummultirange)) t(nmr);

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

SELECT count(*) FROM (select range_intersect_agg(nmr) from (values ('{}'::nummultirange)) t(nmr)) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 59).

SELECT * FROM ft1 ORDER BY c3, c1 OFFSET 100 LIMIT 10;

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


Question: Write the DML statement from PostgreSQL regression test 'plpgsql' (example 732).

INSERT INTO transition_table_status (level, node_no, status)
  SELECT 1, level1_no, 0 FROM transition_table_level1;

Explanation: DML from PostgreSQL core regression test for Plpgsql.


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

CREATE OPERATOR #># (
       LEFTARG = hstore,
       RIGHTARG = hstore,
       PROCEDURE = hstore_gt,
       COMMUTATOR = #<#,
       NEGATOR = #<=#,
       RESTRICT = scalargtsel,
       JOIN = scalargtjoinsel
);

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


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

SELECT d AS date, i AS interval,
       eval(format('date %L + interval %L', d, i)) AS plus,
       eval(format('date %L - interval %L', d, i)) AS minus
FROM (VALUES (date '-infinity'),
             (date '1995-08-06'),
             (date 'infinity')) AS t1(d),
     (VALUES (interval '-infinity'),
             (interval 'infinity')) AS t2(i);

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

SELECT count(*) FROM (SELECT d AS date, i AS interval,
       eval(format('date %L + interval %L', d, i)) AS plus,
       eval(format('date %L - interval %L', d, i)) AS minus
FROM (VALUES (date '-infinity'),
             (date '1995-08-06'),
             (date 'infinity')) AS t1(d),
     (VALUES (interval '-infinity'),
             (interval 'infinity')) AS t2(i)) AS _sub;


Question: pgTAP test for Pgtap--1.3.0--1.3.1 (assertion 8).

-- domain_type_is( schema, domain, type, description )
CREATE OR REPLACE FUNCTION domain_type_is( NAME, TEXT, TEXT, TEXT )
RETURNS TEXT AS $$
DECLARE
    actual_type TEXT := _get_dtype($1, $2, false);
BEGIN
    IF actual_type IS NULL THEN
        RETURN fail( $4 ) || E'\n' || diag (
            '   Domain ' || quote_ident($1) || '.' || $2
            || ' does not exist'
        );
    END IF;

    RETURN is( actual_type, _typename($3), $4 );
END;
$$ LANGUAGE plpgsql;

Explanation: SQL assertion from pgTAP test suite for Pgtap--1.3.0--1.3.1.


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

CREATE INDEX tbl_idx ON tbl (c1, (c1+0)) INCLUDE (c2);

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


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

/* contrib/pageinspect/pageinspect--1.5--1.6.sql */

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

--
-- HASH functions
--

--
-- hash_page_type()
--
CREATE FUNCTION hash_page_type(IN page bytea)
RETURNS text
AS 'MODULE_PATHNAME', 'hash_page_type'
LANGUAGE C STRICT PARALLEL SAFE;


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

-- Test subtransaction successfully committed

CREATE FUNCTION subtransaction_ctx_success() RETURNS void
AS $$
    spi_exec "INSERT INTO subtransaction_tbl VALUES(1)"
    subtransaction {
        spi_exec "INSERT INTO subtransaction_tbl VALUES(2)"
    }
$$ LANGUAGE pltcl;

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


Question: Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 1175).

SELECT COUNT(*)
FROM pg_foreign_table
WHERE ftrelid = 'table30'::regclass
AND ftoptions @> array['batch_size=40'];


Question: Show an example of PostgreSQL ALTER OPERATOR (example 2).

ALTER OPERATOR && (int[], int[]) SET (RESTRICT = _int_contsel, JOIN = _int_contjoinsel);

Explanation: PostgreSQL ALTER OPERATOR command.


Question: PostgreSQL regression test 'rules': Write the SELECT query (example 336).

SELECT * FROM shoelace_obsolete ORDER BY sl_len_cm;

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

SELECT count(*) FROM (SELECT * FROM shoelace_obsolete ORDER BY sl_len_cm) AS _sub;


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

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


Question: PostgreSQL regression test 'random': Write the SELECT query (example 41).

SELECT random_normal(mean => 1, stddev => 0.1) r FROM generate_series(1, 10);

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

SELECT count(*) FROM (SELECT random_normal(mean => 1, stddev => 0.1) r FROM generate_series(1, 10)) AS _sub;


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

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

SELECT count(*) FROM (select '["c"]' || '["a", "b"]'::jsonb) AS _sub;


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

SELECT rtrim('trimxxxx'::citext, 'x'::citext) = 'trim' AS t;

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


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

CREATE FUNCTION text2ltree(text)
RETURNS ltree
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;