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

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

SELECT count(*) FROM (select '{(!,[)}'::textmultirange) AS _sub;


Question: PostgreSQL regression test 'create_index_spgist': Write the SELECT query (example 23).

SELECT count(*) FROM quad_point_tbl WHERE p |>> '(5000, 4000)';

Explanation: Regression test for Create Index Spgist in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT count(*) FROM quad_point_tbl WHERE p |>> '(5000, 4000)') AS _sub;


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

Explanation: DML from PostgreSQL core regression test for Triggers.


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

INSERT INTO num_exp_ln VALUES (0,'NaN');

Explanation: DML from PostgreSQL core regression test for Numeric.


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

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

SELECT count(*) FROM (SELECT nextval('sequence_test2')) AS _sub;


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

SELECT * FROM pg_partition_tree('ptif_test_view');

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

SELECT count(*) FROM (SELECT * FROM pg_partition_tree('ptif_test_view')) AS _sub;


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

-- any_column_privs_are ( table, user, privileges[], description )
CREATE OR REPLACE FUNCTION any_column_privs_are ( NAME, NAME, NAME[], TEXT )
RETURNS TEXT AS $$
DECLARE
    grants TEXT[] := _get_ac_privs( $2, quote_ident($1) );
BEGIN
    IF grants[1] = 'undefined_table' THEN
        RETURN ok(FALSE, $4) || E'\n' || diag(
            '    Table ' || quote_ident($1) || '.' || quote_ident($2) || ' does not exist'
        );
    ELSIF grants[1] = 'undefined_role' THEN
        RETURN ok(FALSE, $4) || E'\n' || diag(
            '    Role ' || quote_ident($2) || ' does not exist'
        );
    END IF;
    RETURN _assets_are('privileges', grants, $3, $4);
END;
$$ LANGUAGE plpgsql;

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


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

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

SELECT count(*) FROM (select return_int_input(1) in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1)) AS _sub;


Question: pgTAP test for Functap (assertion 302).

-- Test diagnostics
SELECT * FROM check_test(
    is_window( 'nada', ARRAY['int'], 'whatever' ),
    false,
    'is_window(nowin, arg, desc)',
    'whatever',
    '    Function nada(int) does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

CREATE SCHEMA hollywood; CREATE TABLE hollywood.films (title text, release date, awards text[]); CREATE VIEW hollywood.winners AS SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;

Explanation: PostgreSQL CREATE SCHEMA command.


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

INSERT INTO expr_key (x, t)
SELECT d1::numeric, d1::text FROM (
    SELECT round((d / pi())::numeric, 7) AS d1 FROM generate_series(1, 20) AS d
) t;

Explanation: DML from PostgreSQL core regression test for Memoize.


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

INSERT INTO INSERT_TBL(x,y) VALUES (5, 'check failed');

Explanation: DML from PostgreSQL core regression test for Constraints.


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

end$$ language plpgsql parallel safe;
CREATE TABLE fooarr(f1 text, f2 int[], f3 text);
INSERT INTO fooarr VALUES('1', ARRAY[1,2], 'one');

PREPARE pstmt(text, int[]) AS SELECT * FROM fooarr WHERE f1 = $1 AND f2 = $2;
EXPLAIN (COSTS OFF) EXECUTE pstmt('1', make_some_array(1,2));
EXECUTE pstmt('1', make_some_array(1,2));
DEALLOCATE pstmt;

-- test interaction between subquery and partial_paths
CREATE VIEW tenk1_vw_sec WITH (security_barrier) AS SELECT * FROM tenk1;
EXPLAIN (COSTS OFF)
SELECT 1 FROM tenk1_vw_sec
  WHERE (SELECT sum(f1) FROM int4_tbl WHERE f1 < unique1) < 100;

rollback;

-- test that a newly-created session role propagates to workers.
begin;
create role regress_parallel_worker;
set session authorization regress_parallel_worker;
select current_setting('session_authorization');
set debug_parallel_query = 1;
select current_setting('session_authorization');
rollback;

-- test that function option SET ROLE works in parallel workers.
create role regress_parallel_worker;

create function set_and_report_role() returns text as
  $$ select current_setting('role') $$ language sql parallel safe
  set role = regress_parallel_worker;

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


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

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


Question: PL/pgSQL test: Plpgsql Domain (example 10).

CREATE DOMAIN uint2 AS int2 CHECK (VALUE >= 0);

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


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

SELECT count(*) FROM timestamptztmp WHERE a <= '2018-12-18 10:59:54 GMT+3';

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


Question: Write the DDL statement from PostgreSQL regression test 'cluster' (example 3).

CREATE INDEX clstr_tst_b ON clstr_tst (b);

Explanation: DDL from PostgreSQL core regression test for Cluster.


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

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


Question: pgTAP test for Functap (assertion 10).

SELECT * FROM check_test(
    has_function( 'pg_catalog', 'now'::name ),
    true,
    'simple schema.function',
    'Function pg_catalog.now() should exist',
    ''
);


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

SELECT '4.0'::citext::numeric = 4.0 AS t;

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


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

SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid ORDER BY conname COLLATE "C";

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

SELECT count(*) FROM (SELECT pg_get_constraintdef(oid), conname, conkey FROM pg_constraint WHERE conrelid = 'sales_apr2022'::regclass::oid ORDER BY conname COLLATE "C") AS _sub;


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

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

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

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


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

CREATE FUNCTION tfnp(int[],int) RETURNS int[] AS
'select $1 || $2' LANGUAGE SQL;

Explanation: DDL from PostgreSQL core regression test for Polymorphism.


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

-- Create the operator class
CREATE OPERATOR CLASS gist_float4_ops
DEFAULT FOR TYPE float4 USING gist
AS
	OPERATOR	1	<  ,
	OPERATOR	2	<= ,
	OPERATOR	3	=  ,
	OPERATOR	4	>= ,
	OPERATOR	5	>  ,
	OPERATOR	6	<> ,
	OPERATOR	15	<-> FOR ORDER BY pg_catalog.float_ops ,
	FUNCTION	1	gbt_float4_consistent (internal, float4, int2, oid, internal),
	FUNCTION	2	gbt_float4_union (internal, internal),
	FUNCTION	3	gbt_float4_compress (internal),
	FUNCTION	4	gbt_decompress (internal),
	FUNCTION	5	gbt_float4_penalty (internal, internal, internal),
	FUNCTION	6	gbt_float4_picksplit (internal, internal),
	FUNCTION	7	gbt_float4_same (gbtreekey8, gbtreekey8, internal),
	FUNCTION	8	gbt_float4_distance (internal, float4, int2, oid, internal),
	FUNCTION	9	gbt_float4_fetch (internal),
	FUNCTION	11	gbt_float4_sortsupport (internal),
	FUNCTION	12 ("any", "any") gist_translate_cmptype_btree (int),
	STORAGE		gbtreekey8;

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


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

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


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

INSERT INTO notnull_tbl1 VALUES (NULL, 1), (300, 3);


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

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

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


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

INSERT INTO timetzcmp (r_id,a) SELECT 14,count(*) FROM timetztmp WHERE a >= '07:46:45 GMT+2';


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

SELECT cume_dist() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10;

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

SELECT count(*) FROM (SELECT cume_dist() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10) AS _sub;


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

-- should fail, event triggers cannot have declared arguments
create function test_event_trigger_arg(name text)
returns event_trigger as $$ BEGIN RETURN 1; END $$ language plpgsql;

-- should fail, SQL functions cannot be event triggers
create function test_event_trigger_sql() returns event_trigger as $$
SELECT 1 $$ language sql;

-- should fail, no elephant_bootstrap entry point
create event trigger regress_event_trigger on elephant_bootstrap
   execute procedure test_event_trigger();

-- OK
create event trigger regress_event_trigger on ddl_command_start
   execute procedure test_event_trigger();

-- OK
create event trigger regress_event_trigger_end on ddl_command_end
   execute function test_event_trigger();

-- should fail, food is not a valid filter variable
create event trigger regress_event_trigger2 on ddl_command_start
   when food in ('sandwich')
   execute procedure test_event_trigger();

-- should fail, sandwich is not a valid command tag
create event trigger regress_event_trigger2 on ddl_command_start
   when tag in ('sandwich')
   execute procedure test_event_trigger();

-- should fail, create skunkcabbage is not a valid command tag
create event trigger regress_event_trigger2 on ddl_command_start
   when tag in ('create table', 'create skunkcabbage')
   execute procedure test_event_trigger();

-- should fail, can't have event triggers on event triggers
create event trigger regress_event_trigger2 on ddl_command_start
   when tag in ('DROP EVENT TRIGGER')
   execute procedure test_event_trigger();

-- should fail, can't have event triggers on global objects
create event trigger regress_event_trigger2 on ddl_command_start
   when tag in ('CREATE ROLE')
   execute procedure test_event_trigger();

-- should fail, can't have event triggers on global objects
create event trigger regress_event_trigger2 on ddl_command_start
   when tag in ('CREATE DATABASE')
   execute procedure test_event_trigger();

-- should fail, can't have event triggers on global objects
create event trigger regress_event_trigger2 on ddl_command_start
   when tag in ('CREATE TABLESPACE')
   execute procedure test_event_trigger();

-- should fail, can't have same filter variable twice
create event trigger regress_event_trigger2 on ddl_command_start
   when tag in ('create table') and tag in ('CREATE FUNCTION')
   execute procedure test_event_trigger();

-- should fail, can't have arguments
create event trigger regress_event_trigger2 on ddl_command_start
   execute procedure test_event_trigger('argument not allowed');

-- OK
create event trigger regress_event_trigger2 on ddl_command_start
   when tag in ('create table', 'CREATE FUNCTION')
   execute procedure test_event_trigger();

-- OK
comment on event trigger regress_event_trigger is 'test comment';

-- drop as non-superuser should fail
create role regress_evt_user;
set role regress_evt_user;
create event trigger regress_event_trigger_noperms on ddl_command_start
   execute procedure test_event_trigger();
reset role;

-- test enabling and disabling
alter event trigger regress_event_trigger disable;
-- fires _trigger2 and _trigger_end should fire, but not _trigger
create table event_trigger_fire1 (a int);
alter event trigger regress_event_trigger enable;
set session_replication_role = replica;
-- fires nothing
create table event_trigger_fire2 (a int);
alter event trigger regress_event_trigger enable replica;
-- fires only _trigger
create table event_trigger_fire3 (a int);
alter event trigger regress_event_trigger enable always;
-- fires only _trigger
create table event_trigger_fire4 (a int);
reset session_replication_role;
-- fires all three
create table event_trigger_fire5 (a int);
-- non-top-level command
create function f1() returns int
language plpgsql
as $$
begin
  create table event_trigger_fire6 (a int);

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


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

CREATE OPERATOR CLASS alt_opc2 FOR TYPE macaddr USING hash AS STORAGE macaddr;

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


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

create index on t_gin_test_tbl using gin (i, j);

Explanation: DDL from PostgreSQL core regression test for Gin.


Question: Write the DDL statement from PostgreSQL regression test 'jsonb' (example 468).

CREATE INDEX jidx ON testjsonb USING gin (j);

Explanation: DDL from PostgreSQL core regression test for Jsonb.


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

select count(*) from test_range_gist where ir @> 10;

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

SELECT count(*) FROM (select count(*) from test_range_gist where ir @> 10) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'pgcrypto' (example 18).

select pgp_pub_decrypt(dearmor(data), dearmor(seckey))
from keytbl, encdata where keytbl.id=6 and encdata.id=4;

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


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

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


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

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


Question: Show an example of PostgreSQL VALUES (example 4).

SELECT f.* FROM films f, (VALUES('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind) WHERE f.studio = t.studio AND f.kind = t.kind; UPDATE employees SET salary = salary * v.increase FROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase) WHERE employees.depno = v.depno AND employees.sales >= v.target;

Explanation: PostgreSQL VALUES command.


Question: Show a SQL definition from the pg_partman project (pg_partman--4.5.0--4.5.1, item 2).

CREATE OR REPLACE FUNCTION @extschema@.check_name_length (p_object_name text, p_suffix text DEFAULT NULL, p_table_partition boolean DEFAULT FALSE) RETURNS text
    LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER
    SET search_path TO pg_catalog, pg_temp
    AS $$
DECLARE
    v_new_length    int;
    v_new_name      text;
BEGIN
/*
 * Truncate the name of the given object if it is greater than the postgres default max (63 characters).
 * Also appends given suffix and schema if given and truncates the name so that the entire suffix will fit.
 * Returns original name (with suffix if given) if it doesn't require truncation
 * Retains SECURITY DEFINER since it is called by trigger functions and did not want to break installations prior to 4.0.0
 */

IF p_table_partition IS TRUE AND (p_suffix IS NULL) THEN
    RAISE EXCEPTION 'Table partition name requires a suffix value';
END IF;

IF p_table_partition THEN  -- 61 characters to account for _p in partition name
    IF char_length(p_object_name) + char_length(p_suffix) >= 61 THEN
        v_new_length := 61 - char_length(p_suffix);
        v_new_name := substring(p_object_name from 1 for v_new_length) || '_p' || p_suffix;
    ELSE
        v_new_name := p_object_name||'_p'||p_suffix;
    END IF;
ELSE
    IF char_length(p_object_name) + char_length(COALESCE(p_suffix, '')) >= 63 THEN
        v_new_length := 63 - char_length(COALESCE(p_suffix, ''));
        v_new_name := substring(p_object_name from 1 for v_new_length) || COALESCE(p_suffix, '');
    ELSE
        v_new_name := p_object_name||COALESCE(p_suffix, '');
    END IF;
END IF;

RETURN v_new_name;

END
$$;

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


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

CREATE FUNCTION zdb.schema_version() RETURNS text LANGUAGE sql AS $$
SELECT '3000.0.8 (c11743812075d06c3caa219343ae7f0ca6c1ee27)'
$$;

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


Question: pgTAP test for Aretap (assertion 96).

SELECT * FROM check_test(
    users_are( ___myusers(current_user), 'whatever' ),
    false,
    'users_are(users, desc) extras',
    'whatever',
    '    Extra users:
        ' || quote_ident(current_user)
);

Explanation: SQL assertion from pgTAP test suite for Aretap.


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

SELECT JSON_QUERY(jsonb '"123.1"', '$' RETURNING int8 error on error);

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

SELECT count(*) FROM (SELECT JSON_QUERY(jsonb '"123.1"', '$' RETURNING int8 error on error)) AS _sub;


Question: pgTAP test for Resultset (assertion 126).

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

Explanation: SQL assertion from pgTAP test suite for Resultset.


Question: Write the DML statement from PostgreSQL regression test 'arrays' (example 98).

Explanation: DML from PostgreSQL core regression test for Arrays.


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

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


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

--
-- bt_index_parent_check()
--
CREATE FUNCTION bt_index_parent_check(index regclass)
RETURNS VOID
AS 'MODULE_PATHNAME', 'bt_index_parent_check'
LANGUAGE C STRICT PARALLEL RESTRICTED;

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


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

-- is_window( schema, function, args[] )
CREATE OR REPLACE FUNCTION is_window( NAME, NAME, NAME[] )
RETURNS TEXT AS $$
    SELECT _func_compare(
        $1, $2, $3, _type_func('w', $1, $2, $3),
        'Function ' || quote_ident($1) || '.' || quote_ident($2) || '(' ||
        array_to_string($3, ', ') || ') should be a window function'
    );
$$ LANGUAGE sql;

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


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

CREATE FUNCTION autoprewarm_dump_now()
RETURNS pg_catalog.int8 STRICT
AS 'MODULE_PATHNAME', 'autoprewarm_dump_now'
LANGUAGE C;


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

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

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


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

SELECT d1 AS european_postgres FROM TIMESTAMP_TBL;

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

SELECT count(*) FROM (SELECT d1 AS european_postgres FROM TIMESTAMP_TBL) AS _sub;


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

ALTER EXTENSION pgtap ADD FUNCTION col_has_check ( NAME, NAME[], TEXT );

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


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

Explanation: DML from PostgreSQL core regression test for Domain.


Question: Write the DDL statement from PostgreSQL regression test 'macaddr' (example 15).

CREATE INDEX macaddr_data_btree ON macaddr_data USING btree (b);

Explanation: DDL from PostgreSQL core regression test for Macaddr.


Question: PL/pgSQL test: Plpython Record (example 38).

SELECT * FROM test_type_record_as('list', null, null, false);

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


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

CREATE FUNCTION text_w_default_in(cstring)
   RETURNS text_w_default
   AS 'textin'
   LANGUAGE internal STRICT IMMUTABLE;

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


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

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

SELECT count(*) FROM (SELECT ts_lexize('hunspell_long', 'ex-machina')) AS _sub;


Question: Show a SQL definition from the pg_partman project (test-id-1-bigint-list, item 6).

CREATE TABLE partman_test.id_taptest_table
    (col1 bigint
        , col2 bigint NOT NULL
        , col3 timestamptz DEFAULT now()
        , col4 text)
    PARTITION BY LIST (col2);


Question: pgTAP test for Inheritance (assertion 57).

SELECT * FROM check_test(
    is_ancestor_of( 'parent', 'nope', 1 ),
    false,
    'is_ancestor_of(ptab, nope, 1)',
    'Table parent should be ancestor 1 of nope',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Inheritance.


Question: pgTAP test for Fktap (assertion 58).

SELECT * FROM check_test(
    fk_ok( 'fk', 'pk_id', 'pk', 'id', 'WHATEVER' ),
    true,
    'basic fk_ok noschema',
    'WHATEVER'
);

Explanation: SQL assertion from pgTAP test suite for Fktap.


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

SELECT * FROM test_date WHERE i <= '2004-10-25 00:00:01'::timestamptz ORDER BY i;


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

SELECT * FROM test_float4 WHERE i > 1e-300::float8 ORDER BY i;


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

select generate_series(timestamp '1995-08-06 12:12:12', timestamp '1996-08-06 12:12:12', interval 'infinity');

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

SELECT count(*) FROM (select generate_series(timestamp '1995-08-06 12:12:12', timestamp '1996-08-06 12:12:12', interval 'infinity')) AS _sub;


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

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

SELECT count(*) FROM (SELECT int8 '0x8000000000000000') AS _sub;


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

INSERT INTO t1p (SELECT x, md5(x::text) FROM generate_series(0,99) x);

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


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

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

SELECT count(*) FROM (SELECT float4send('985e15'::float4)) AS _sub;


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

SELECT i, to_timestamp('2018-11-02 12:34:56.123456', 'YYYY-MM-DD HH24:MI:SS.FF' || i) FROM generate_series(1, 6) i;

SELECT count(*) FROM (SELECT i, to_timestamp('2018-11-02 12:34:56.123456', 'YYYY-MM-DD HH24:MI:SS.FF' || i) FROM generate_series(1, 6) i) AS _sub;


Question: PostgreSQL regression test 'partition_split': Write the SELECT query (example 332).

SELECT tableoid::regclass, * FROM t ORDER BY tableoid::regclass::text COLLATE "C", b;

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

SELECT count(*) FROM (SELECT tableoid::regclass, * FROM t ORDER BY tableoid::regclass::text COLLATE "C", b) AS _sub;


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

CREATE TABLE FKTABLE (ftest1 int, ftest2 inet, FOREIGN KEY(ftest1, ftest2) REFERENCES pktable(ptest2, ptest1));

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


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

CREATE COLLATION french (locale = 'fr_FR.utf8');

Explanation: PostgreSQL CREATE COLLATION command.


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

--
-- ISMN13 operators:
--
---------------------------------------------------
CREATE OPERATOR < (
	PROCEDURE = isnlt,
	LEFTARG = ismn13,
	RIGHTARG = ismn13,
	COMMUTATOR = >,
	NEGATOR = >=,
	RESTRICT = scalarltsel,
	JOIN = scalarltjoinsel);

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


Question: Write the DDL statement from PostgreSQL regression test 'merge' (example 440).

CREATE TABLE part_m02 PARTITION OF pa_target
	FOR VALUES FROM ('2017-02-01') TO ('2017-03-01')
	PARTITION BY LIST (tid);

Explanation: DDL from PostgreSQL core regression test for Merge.


Question: Show a SQL definition from the citus project (pg13, item 8).

CREATE INDEX name_index on dist_table(name);

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


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

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

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


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

CREATE TABLE films_recent AS SELECT * FROM films WHERE date_prod >= '2002-01-01';

Explanation: PostgreSQL CREATE TABLE AS command.


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

SELECT timestamptz(date '1994-01-01', time with time zone '10:00-8') AS "Jan_01_1994_10am";

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

SELECT count(*) FROM (SELECT timestamptz(date '1994-01-01', time with time zone '10:00-8') AS "Jan_01_1994_10am") AS _sub;


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

SELECT * FROM INT8_TBL WHERE '123'::int2 > q1;

SELECT count(*) FROM (SELECT * FROM INT8_TBL WHERE '123'::int2 > q1) AS _sub;


Question: PL/pgSQL test: Plperl Setup (example 2).

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


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

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

SELECT count(*) FROM (SELECT to_number('qiv', 'RN')) AS _sub;


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

CREATE TABLE prt1_l_p2_p1 PARTITION OF prt1_l_p2 FOR VALUES IN ('0000', '0001');

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


Question: Show a SQL definition from the zombodb project (zombodb--3000.1.3--3000.1.4, item 16).

CREATE OR REPLACE FUNCTION dsl.link_options(options text[], query pg_catalog.zdbquery) RETURNS pg_catalog.zdbquery AS 'MODULE_PATHNAME', 'link_options_wrapper' IMMUTABLE LANGUAGE c PARALLEL SAFE;

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


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

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

SELECT count(*) FROM (SELECT regexp_count('123123123123', '123', 33)) AS _sub;


Question: pgTAP test for Functap (assertion 152).

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

Explanation: SQL assertion from pgTAP test suite for Functap.


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

CREATE TABLE plt2_adv_p4 PARTITION OF plt2_adv FOR VALUES IN ('0004', '0005');


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

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


Question: Write the DML statement from PostgreSQL regression test 'timestamp' (example 61).

INSERT INTO TIMESTAMP_TBL VALUES ('19970710 173201 America/Does_not_exist');

Explanation: DML from PostgreSQL core regression test for Timestamp.


Question: Write the DML statement from PostgreSQL regression test 'insert_conflict' (example 261).

insert into parted_conflict_test (a, b) values (2, 'n') on conflict (a) do select where parted_conflict_test.b = 'x' returning *;

Explanation: DML from PostgreSQL core regression test for Insert Conflict.


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

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


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

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

SELECT count(*) FROM (select '"foo"'::jsonb #>> '{}') AS _sub;


Question: pgTAP test for Fktap (assertion 65).

SELECT * FROM check_test(
    fk_ok( 'fk', ARRAY['pk_id'], 'ok', ARRAY['fid'], 'WHATEVER' ),
    false,
    'fk_ok bad PK test',
    'WHATEVER',
    '        have: fk(pk_id) REFERENCES pk(id)
        want: fk(pk_id) REFERENCES ok(fid)'
);

Explanation: SQL assertion from pgTAP test suite for Fktap.


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

SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE proallargtypes IS NOT NULL AND proargmodes IS NOT NULL AND
    array_length(proallargtypes,1) <> array_length(proargmodes,1);

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

SELECT count(*) FROM (SELECT p1.oid, p1.proname
FROM pg_proc as p1
WHERE proallargtypes IS NOT NULL AND proargmodes IS NOT NULL AND
    array_length(proallargtypes,1) <> array_length(proargmodes,1)) AS _sub;


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

select cume_dist(3) within group (order by x)
from (values (1),(1),(2),(2),(3),(3),(4)) v(x);

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

SELECT count(*) FROM (select cume_dist(3) within group (order by x)
from (values (1),(1),(2),(2),(3),(3),(4)) v(x)) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'timestamptz' (example 108).

INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 29 17:32:01 1997');

Explanation: DML from PostgreSQL core regression test for Timestamptz.


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

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


Question: pgTAP test for Enumtap (assertion 1).

\unset ECHO
\i test/setup.sql

SELECT plan(108);

Explanation: SQL assertion from pgTAP test suite for Enumtap.


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

Explanation: DML from PostgreSQL core regression test for Domain.


Question: Write the DDL statement from PostgreSQL regression test 'create_role' (example 37).

CREATE ROLE regress_password_null PASSWORD NULL;

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


Question: pgTAP test for Index (assertion 37).

SELECT * FROM check_test(
    has_index( 'sometab', 'idx_baz' ),
    true,
    'has_index() no schema or cols or desc',
    'Index idx_baz should exist',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Index.


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

INSERT INTO plt1_adv VALUES (-1, -1, NULL);

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


Question: PostgreSQL regression test 'groupingsets': Write the SELECT query (example 74).

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


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

create table idxpart3 (b int not null, a int not null);

Explanation: DDL from PostgreSQL core regression test for Indexing.


Question: Write the DML statement from PostgreSQL regression test 'jsonb' (example 840).

update test_jsonb_subscript set test_json[0] = '1';

Explanation: DML from PostgreSQL core regression test for Jsonb.


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

CREATE INDEX comment_test_index ON comment_test(indexed_col);

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


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

create index j2_id1_idx on j2 (id1) where id1 % 1000 = 1;

Explanation: DDL from PostgreSQL core regression test for Join.


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

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

SELECT count(*) FROM (SELECT regdatabase('Nonexistent')) AS _sub;


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

INSERT INTO caster (citext)        VALUES ('1999-01-08 04:05:06'::timestamptz);

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


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

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

SELECT count(*) FROM (select jsonb_path_query('"2017-03-10T12:34:56.789Z"', '$.datetime()')) AS _sub;


Question: PostgreSQL regression test 'rules': Write the SELECT query (example 526).

SELECT * FROM hat_data WHERE hat_name = 'h8';

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

SELECT count(*) FROM (SELECT * FROM hat_data WHERE hat_name = 'h8') AS _sub;


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

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

SELECT count(*) FROM (select make_interval(secs := -1e18)) AS _sub;


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

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


Question: pgTAP test for Resultset (assertion 343).

INSERT INTO folk (id, name) VALUES ( 44, 'Larry' );

Explanation: SQL assertion from pgTAP test suite for Resultset.


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

CREATE FUNCTION dblink_get_notify(
    conname TEXT,
    OUT notify_name TEXT,
    OUT be_pid INT4,
    OUT extra TEXT
)
RETURNS setof record
AS 'MODULE_PATHNAME', 'dblink_get_notify'
LANGUAGE C STRICT PARALLEL RESTRICTED;

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


Question: Write the DML statement from PostgreSQL regression test 'insert_conflict' (example 253).

insert into parted_conflict_test (a, b) values (1, 'a'), (2, 'a'), (4, 'a') on conflict (a) do update set b = excluded.b where excluded.b = 'b';

Explanation: DML from PostgreSQL core regression test for Insert Conflict.


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

CREATE OPERATOR -> (
	LEFTARG = hstore,
	RIGHTARG = text[],
	PROCEDURE = slice_array
);


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

INSERT INTO temporal_rng3 (id, valid_at) VALUES ('[3,4)', daterange('2018-01-01', NULL));

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


Question: Write the DDL statement from PostgreSQL regression test 'btree_index' (example 89).

CREATE UNIQUE INDEX dedup_unique ON dedup_unique_test_table (a) WITH (deduplicate_items=on);

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


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

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


Question: Show an example of PostgreSQL ALTER AGGREGATE (example 4).

ALTER AGGREGATE mypercentile(float8, integer) SET SCHEMA myschema;

Explanation: PostgreSQL ALTER AGGREGATE command.


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

select relname, relkind from pg_class where relname like 'idxpart%' order by relname;

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

SELECT count(*) FROM (select relname, relkind from pg_class where relname like 'idxpart%' order by relname) AS _sub;


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

SELECT count(*) FROM (SELECT to_regtypemod('timestamp(4)')) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'tsearch' (example 33).

create index wowidx on test_tsvector using gist (a);

Explanation: DDL from PostgreSQL core regression test for Tsearch.


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

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


Question: Write the DML statement from PostgreSQL regression test 'arrays' (example 113).

insert into arrtest_f values(8,'cat2',1.32);

Explanation: DML from PostgreSQL core regression test for Arrays.


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

-- Triggers on leaf partition part_c_1_100
CREATE TRIGGER c1_delete_trig
  AFTER DELETE ON part_c_1_100 for each statement execute procedure trigfunc();

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


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

Explanation: DML from PostgreSQL core regression test for Subselect.


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

select * from testrngfunc(); -- fail

drop function testrngfunc();

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

SELECT count(*) FROM (select * from testrngfunc(); -- fail

drop function testrngfunc()) AS _sub;


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

Explanation: DML from PostgreSQL core regression test for Numeric.


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

SELECT width_bucket(0, -1e100::numeric, 1, 10);

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

SELECT count(*) FROM (SELECT width_bucket(0, -1e100::numeric, 1, 10)) AS _sub;


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

INSERT INTO gin_check_text_array select array_agg(sha256(round(random()*300 + 300)::text::bytea)::text) from generate_series(1, 10000) as i group by i % 100;

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


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

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

SELECT count(*) FROM (select '{"a":1 , "b":2, "c":3}'::jsonb - '{}'::text[]) AS _sub;


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

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


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

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


Question: Show a SQL definition from the timescaledb project (partitioned_hypertable, item 17).

\set ON_ERROR_STOP 0
CREATE TABLE part_col_specified(time TIMESTAMPTZ, device TEXT) PARTITION BY RANGE (time) WITH (timescaledb.hypertable, timescaledb.partition_column='time');

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


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

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

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


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

CREATE TABLE fk_partitioned_fk_1 PARTITION OF fk_partitioned_fk FOR VALUES IN (NULL,500,501,502);

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


Question: Write the DDL statement from PostgreSQL regression test 'identity' (example 145).

CREATE TABLE pitest1_p1 PARTITION OF pitest1 FOR VALUES FROM ('2016-07-01') TO ('2016-08-01');

Explanation: DDL from PostgreSQL core regression test for Identity.


Question: pgTAP test for Ruletap (assertion 45).

SELECT * FROM check_test(
    rule_is_on( 'public', 'sometab', 'foo_me'::name, 'u' ),
    false,
    'rule_is_on(schema, table, invalid rule, u, desc)',
    'Rule foo_me should be on UPDATE to public.sometab',
    '    Rule foo_me does not exist on public.sometab'
);

Explanation: SQL assertion from pgTAP test suite for Ruletap.


Question: PostgreSQL regression test 'incremental_sort': Write the SELECT query (example 36).

select * from (select * from t order by a) s order by a, b limit 5;

Explanation: Regression test for Incremental Sort in PostgreSQL core test suite.

SELECT count(*) FROM (select * from (select * from t order by a) s order by a, b limit 5) AS _sub;


Question: pgTAP test for Hastap (assertion 256).

SELECT * FROM check_test(
    domain_type_is( 'public', 'us_postal_code', 'text', 'whatever'),
    true,
    'domain_type_is(schema, domain, type, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


Question: pgTAP test for Pgtap--1.2.0--1.3.0 (assertion 26).

CREATE OR REPLACE FUNCTION _types_are ( NAME, NAME[], TEXT, CHAR[] )
RETURNS TEXT AS $$
    SELECT _are(
        'types',
        ARRAY(
            SELECT t.typname
              FROM pg_catalog.pg_type t
              LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
             WHERE (
                     t.typrelid = 0
                 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)
             )
               AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
               AND n.nspname = $1
               AND t.typtype = ANY( COALESCE($4, ARRAY['b', 'c', 'd', 'p', 'e']) )
            EXCEPT
            SELECT _typename($2[i])
              FROM generate_series(1, array_upper($2, 1)) s(i)
        ),
        ARRAY(
            SELECT _typename($2[i])
               FROM generate_series(1, array_upper($2, 1)) s(i)
            EXCEPT
            SELECT t.typname
              FROM pg_catalog.pg_type t
              LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
             WHERE (
                     t.typrelid = 0
                 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)
             )
               AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
               AND n.nspname = $1
               AND t.typtype = ANY( COALESCE($4, ARRAY['b', 'c', 'd', 'p', 'e']) )
        ),
        $3
    );
$$ LANGUAGE SQL;

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


Question: PL/pgSQL test: Plpython Trigger (example 142).

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


Question: pgTAP test for Policy (assertion 14).

CREATE POLICY all_view ON public.passwd FOR SELECT TO root, bob, daemon USING (true);

Explanation: SQL assertion from pgTAP test suite for Policy.


Question: pgTAP test for Pktap (assertion 12).

SELECT * FROM check_test(
    has_pk( 'sometab', 'sometab should have a pk' ),
    true,
    'has_pk( table, description )',
    'sometab should have a pk',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Pktap.


Question: Show a SQL definition from the pglogical project (infofuncs, item 7).

-- test upgrades
DO $$
BEGIN
        IF version() ~ 'Postgres-XL' THEN
                CREATE EXTENSION IF NOT EXISTS pglogical;
        ELSE
                CREATE EXTENSION IF NOT EXISTS pglogical VERSION '1.0.0';
        END IF;
END;
$$;

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


Question: PostgreSQL regression test 'stats_ext': Write the SELECT query (example 693).

SELECT c0 FROM ONLY expr_stats_incompatible_test WHERE
(
  upper('x') LIKE ('x'||('[0,1]'::int4range))
  AND
  (c0 IN (0, 1) OR c1)
);

Explanation: Regression test for Stats Ext in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT c0 FROM ONLY expr_stats_incompatible_test WHERE
(
  upper('x') LIKE ('x'||('[0,1]'::int4range))
  AND
  (c0 IN (0, 1) OR c1)
)) AS _sub;


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

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

SELECT count(*) FROM (SELECT bool '1' AS true) AS _sub;


Question: Show a query using PostgreSQL contrib extension 'pageinspect' (example 47).

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


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

INSERT INTO fast_emp4000 SELECT * FROM slow_emp4000;

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


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

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


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

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

SELECT count(*) FROM (SELECT var_pop('nan'::float4), var_samp('nan'::float4)) AS _sub;


Question: pgTAP test for Pktap (assertion 24).

SELECT * FROM check_test(
    col_is_pk( 'sometab', 'id', 'sometab.id should be a pk' ),
    true,
    'col_is_pk( table, column, description )',
    'sometab.id should be a pk',
    ''
);


Question: Show an example of PostgreSQL DROP ROUTINE (example 1).

Explanation: PostgreSQL DROP ROUTINE command.


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

Explanation: DDL from PostgreSQL core regression test for Indexing.


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

SELECT numrange(6,7) <@ nummultirange(numrange(1,5), numrange(6,9));

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

SELECT count(*) FROM (SELECT numrange(6,7) <@ nummultirange(numrange(1,5), numrange(6,9))) AS _sub;


Question: pgTAP test for Inheritance (assertion 63).

SELECT * FROM check_test(
    isnt_ancestor_of( 'hide', 'h_parent', 'hide', 'h_child2', 2, 'Lookie' ),
    false,
    'isnt_ancestor_of(psch, ptab, csch, ctab, 2, desc)',
    'Lookie',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Inheritance.


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

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


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

CREATE OPERATOR ^@> (
        LEFTARG = ltree,
	RIGHTARG = _ltree,
	PROCEDURE = _ltree_r_risparent,
        COMMUTATOR = '^<@',
        RESTRICT = contsel,
	JOIN = contjoinsel
);

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


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

Explanation: DML from PostgreSQL core regression test for Rules.


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

select true as "OK"
  from explain_filter('explain (settings) select * from int8_tbl i8') ln
  where ln ~ '^ *Settings: .*plan_cache_mode = ''force_generic_plan''';

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

SELECT count(*) FROM (select true as "OK"
  from explain_filter('explain (settings) select * from int8_tbl i8') ln
  where ln ~ '^ *Settings: .*plan_cache_mode = ''force_generic_plan''') AS _sub;


Question: Show a SQL definition from the pg_partman project (test-time-gap-fill, item 5).

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

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


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

CREATE OPERATOR ~ (
	LEFTARG = _int4,
	RIGHTARG = _int4,
	PROCEDURE = _int_contained,
	COMMUTATOR = '@',
	RESTRICT = _int_contained_sel,
	JOIN = _int_contained_joinsel
);


Question: pgTAP test for Functap (assertion 23).

SELECT * FROM check_test(
    has_function( '__cat__', '{numeric}'::name[] ),
    true,
    'custom numeric function',
    'Function __cat__(numeric) should exist',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

$$ language plpgsql;

select compos();

drop function compos();

-- test: return a row expr as record.
create or replace function composrec() returns record as $$
declare
  v record;

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


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

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

SELECT count(*) FROM (select exp('-inf'::numeric)) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'insert' (example 58).

insert into inserttestb (f3.if1, f3.if2) values (1,'{foo}'), (2,'{bar}');

Explanation: DML from PostgreSQL core regression test for Insert.


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

SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true";

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

SELECT count(*) FROM (SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true") AS _sub;


Question: pgTAP test for Hastap (assertion 158).

SELECT * FROM check_test(
    hasnt_cast( 'int4', 'int8' ),
    false,
    'hasnt_cast( src, targ )',
    'Cast (int4 AS int8) should not exist',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

SELECT count(*) FROM test_tsvector WHERE a @@ '!(yh <-> pl)';

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

SELECT count(*) FROM (SELECT count(*) FROM test_tsvector WHERE a @@ '!(yh <-> pl)') AS _sub;


Question: Show a SQL definition from the pg_partman project (pg_partman--3.2.1--4.0.0, item 45).

CREATE OR REPLACE FUNCTION @extschema@.create_trigger(p_parent_table text) RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE

v_function_name         text;
v_new_search_path       text := '@extschema@,pg_temp';
v_old_search_path       text;
v_parent_schema         text;
v_parent_tablename      text;
v_relkind               char;
v_trig_name             text;
v_trig_sql              text;

BEGIN
/*
 * Function to create partitioning trigger on parent table
 */

SELECT current_setting('search_path') INTO v_old_search_path;
EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_new_search_path, 'false');

SELECT n.nspname, c.relname, c.relkind INTO v_parent_schema, v_parent_tablename, v_relkind
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_relkind = 'p' THEN
    RAISE EXCEPTION 'This function cannot run on natively partitioned tables';
ELSIF v_relkind IS NULL THEN
    RAISE EXCEPTION 'Unable to find given table in system catalogs: %.%', v_parent_schema, v_parent_tablename;
END IF;

v_trig_name := @extschema@.check_name_length(p_object_name := v_parent_tablename, p_suffix := '_part_trig');
-- Ensure function name matches the naming pattern
v_function_name := @extschema@.check_name_length(v_parent_tablename, '_part_trig_func', FALSE);
v_trig_sql := format('CREATE TRIGGER %I BEFORE INSERT ON %I.%I FOR EACH ROW EXECUTE PROCEDURE %I.%I()'
    , v_trig_name
    , v_parent_schema
    , v_parent_tablename
    , v_parent_schema
    , v_function_name);

EXECUTE v_trig_sql;

EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');

END
$$;


Question: Show a SQL definition from the pglogical project (pglogical--2.3.0, item 30).

CREATE FUNCTION pglogical.replication_set_add_sequence(set_name name, relation regclass, synchronize_data boolean DEFAULT false, nsptarget name DEFAULT NULL, reltarget name DEFAULT NULL)
RETURNS boolean VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_replication_set_add_sequence';

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


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

CREATE TYPE tststats.ty AS (a int, b int, c text);

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


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

SELECT 1.1 AS two UNION (SELECT 2 UNION ALL SELECT 2) ORDER BY 1;

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

SELECT count(*) FROM (SELECT 1.1 AS two UNION (SELECT 2 UNION ALL SELECT 2) ORDER BY 1) AS _sub;


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

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


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

end$$ language plpgsql stable;

insert into users values('user1');

select sp_id_user('user1');
select sp_id_user('userx');

create function sp_add_user(a_login text) returns int as $$
declare my_id_user int;


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

SELECT t1.id1, t1.result, t2.expected
    FROM num_result t1, num_exp_sqrt t2
    WHERE t1.id1 = t2.id
    AND t1.result != t2.expected;

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


Question: Write the DML statement from PostgreSQL regression test 'alter_table' (example 438).

INSERT INTO ataddindex VALUES (42), (43);

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


Question: Write the DML statement from PostgreSQL regression test 'transactions' (example 141).

Explanation: DML from PostgreSQL core regression test for Transactions.


Question: Write the DML statement from PostgreSQL regression test 'insert' (example 29).

insert into inserttest (f2[1], f2[2]) values (3,4), (5,6);


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

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


Question: PostgreSQL Indices: show example 5.

CREATE TABLE test2 ( major int, minor int, name varchar );

Explanation: Example from PostgreSQL documentation on Indices.


Question: pgTAP test for Fktap (assertion 22).

/****************************************************************************/
-- Test hasnt_fk().
SELECT * FROM check_test(
    hasnt_fk( 'public', 'fk', 'public.fk should not have an fk' ),
    false,
    'hasnt_fk( schema, table, description )',
    'public.fk should not have an fk'
);

Explanation: SQL assertion from pgTAP test suite for Fktap.


Question: Show a SQL definition from the postgrest project (errors, item 1).

\ir fixtures.sql

SELECT format('CREATE TABLE test.actors_%s ();', n)
FROM generate_series(1, 20000) n
\gexec

-- TODO add many function for fuzzy search (somehow this is making the loadtest start slow);

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


Question: Write the DML statement from PostgreSQL regression test 'collate.icu.utf8' (example 27).

INSERT INTO collate_test5 SELECT * FROM collate_test1;

Explanation: DML from PostgreSQL core regression test for Collate.Icu.Utf8.


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

SELECT few.id, generate_series(1,3) g FROM few ORDER BY id, generate_series(1,3) DESC;

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

SELECT count(*) FROM (SELECT few.id, generate_series(1,3) g FROM few ORDER BY id, generate_series(1,3) DESC) AS _sub;


Question: PostgreSQL regression test 'triggers': Write the SELECT query (example 5).

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

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


Question: PL/pgSQL test: Plpython Transaction (example 33).

DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
    plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x'])
    if row['x'] % 2 == 0:
        plpy.commit()
    else:
        plpy.rollback()
$$;

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


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

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


Question: Show an example of PostgreSQL CREATE SEQUENCE (example 6).

BEGIN; COPY distributors FROM 'input_file'; SELECT setval('serial', max(id)) FROM distributors; END;

Explanation: PostgreSQL CREATE SEQUENCE command.


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

ALTER EXTENSION pgtap ADD FUNCTION rules_are( NAME, NAME[], TEXT );

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


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

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

SELECT count(*) FROM (SELECT E'\\xDeAdBeEx'::bytea) AS _sub;


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

SELECT COUNT(*)
FROM pg_foreign_table
WHERE ftrelid = 'table30000'::regclass
AND ftoptions @> array['fetch_size=30000'];

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


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

ALTER EXTENSION pgtap ADD FUNCTION do_tap( text );


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

INSERT INTO caster (text)          VALUES ('( 1 , 1 ) , ( 2 , 2 )'::lseg);

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


Question: PostgreSQL regression test 'stats_ext': Write the SELECT query (example 463).

SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 OR b = ''1'' OR c = 1');

Explanation: Regression test for Stats Ext in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 OR b = ''1'' OR c = 1')) AS _sub;


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

CREATE POLICY a_temp_pol ON a_temp_tbl USING (f2 > 0);

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


Question: Show an example of PostgreSQL CREATE FUNCTION (example 4).

CREATE FUNCTION add(a integer, b integer) RETURNS integer LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT RETURN a + b;

Explanation: PostgreSQL CREATE FUNCTION command.


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

CREATE FUNCTION zdb.schema_version() RETURNS text LANGUAGE sql AS $$
SELECT '3000.1.24 (52b86eba9286300f7b517c9cca76124431bdd12f)'
$$;

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


Question: pgTAP test for Hastap (assertion 259).

SELECT * FROM check_test(
    domain_type_is( 'public', 'zip_code', 'int', 'whatever'),
    false,
    'domain_type_is(schema, nondomain, type, desc)',
    'whatever',
    '   Domain public.zip_code does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


Question: Show a SQL definition from the pg_partman project (pg_partman--2.5.1--2.6.0, item 13).

/*
 * Check for consistent data in part_config_sub table. Was unable to get this working properly as either a constraint or trigger.
 * Would either delay raising an error until the next write (which I cannot predict) or disallow future edits to update a sub-partition set's configuration.
 * This is called by run_maintainance() and at least provides a consistent way to check that I know will run.
 * If anyone can get a working constraint/trigger, please help!
*/
CREATE FUNCTION @extschema@.check_subpart_sameconfig(p_parent_table text)
    RETURNS TABLE (sub_partition_type text
        , sub_control text
        , sub_partition_interval text
        , sub_constraint_cols text[]
        , sub_premake int
        , sub_inherit_fk boolean
        , sub_retention text
        , sub_retention_schema text
        , sub_retention_keep_table boolean
        , sub_retention_keep_index boolean
        , sub_use_run_maintenance boolean
        , sub_epoch boolean
        , sub_optimize_trigger int
        , sub_optimize_constraint int
        , sub_infinite_time_partitions boolean
        , sub_jobmon boolean
        , sub_trigger_exception_handling boolean
        , sub_upsert text
        , sub_trigger_return_null boolean)
    LANGUAGE sql STABLE SECURITY DEFINER
    SET search_path = @extschema@,pg_temp
AS $$

    WITH parent_info AS (
        SELECT c1.oid
        FROM pg_catalog.pg_class c1
        JOIN pg_catalog.pg_namespace n1 ON c1.relnamespace = n1.oid
        WHERE n1.nspname = split_part(p_parent_table, '.', 1)::name
        AND c1.relname = split_part(p_parent_table, '.', 2)::name
    )
    , child_tables AS (
        SELECT n.nspname||'.'||c.relname AS tablename
        FROM pg_catalog.pg_inherits h
        JOIN pg_catalog.pg_class c ON c.oid = h.inhrelid
        JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
        JOIN parent_info pi ON h.inhparent = pi.oid
    )
    -- Column order here must match the RETURNS TABLE definition
    SELECT DISTINCT a.sub_partition_type
        , a.sub_control
        , a.sub_partition_interval
        , a.sub_constraint_cols
        , a.sub_premake
        , a.sub_inherit_fk
        , a.sub_retention
        , a.sub_retention_schema
        , a.sub_retention_keep_table
        , a.sub_retention_keep_index
        , a.sub_use_run_maintenance
        , a.sub_epoch
        , a.sub_optimize_trigger
        , a.sub_optimize_constraint
        , a.sub_infinite_time_partitions
        , a.sub_jobmon
        , a.sub_trigger_exception_handling
        , a.sub_upsert
        , a.sub_trigger_return_null
    FROM @extschema@.part_config_sub a
    JOIN child_tables b on a.sub_parent = b.tablename;
$$;

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


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

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

SELECT count(*) FROM (select interval '-2562047788.01521550222 hours') AS _sub;


Question: PostgreSQL regression test 'tstypes': Write the SELECT query (example 106).

select to_tsvector('simple', 'x y q') @@ '(!x | !y) <-> y <-> q' AS "true";

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

SELECT count(*) FROM (select to_tsvector('simple', 'x y q') @@ '(!x | !y) <-> y <-> q' AS "true") AS _sub;


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

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

SELECT count(*) FROM (SELECT time with time zone 'T0405+08') AS _sub;


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

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

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


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

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


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

-- Nested subtransactions

CREATE FUNCTION subtransaction_nested_test(swallow boolean = 'f') RETURNS text
AS $$
spi_exec "INSERT INTO subtransaction_tbl VALUES (1)"
subtransaction {
    spi_exec "INSERT INTO subtransaction_tbl VALUES (2)"
    if [catch {
        subtransaction {
            spi_exec "INSERT INTO subtransaction_tbl VALUES (3)"
            spi_exec "error"
        }
    } errormsg] {
        if {$1 != "t"} {
            error $errormsg $::errorInfo $::errorCode
        }
        elog NOTICE "Swallowed $errormsg"
    }
}
return "ok"
$$ LANGUAGE pltcl;

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


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

INSERT INTO temporal_mltrng (id, valid_at) VALUES ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) ON CONFLICT ON CONSTRAINT temporal_mltrng_pk DO UPDATE SET id = EXCLUDED.id + '[2,3)';

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


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

SELECT js FROM jsonb_populate_record(NULL::jsbrec, '{"js": [123, "123", null, {"key": "value"}]}') q;

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

SELECT count(*) FROM (SELECT js FROM jsonb_populate_record(NULL::jsbrec, '{"js": [123, "123", null, {"key": "value"}]}') q) AS _sub;


Question: Show a SQL definition from the citus project (multi_partitioning, item 5).

--
-- Distributed Partitioned Table Creation Tests
--

-- 1-) Distributing partitioned table
-- create partitioned table
CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time);

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


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

CREATE UNIQUE INDEX func_index_index on func_index_heap ((f1 || f2) text_ops);

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


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

SELECT to_json(a) AS a, JSON_OBJECTAGG(k : v ABSENT ON NULL WITH UNIQUE KEYS)
   OVER (ORDER BY k)
FROM (VALUES (1,1), (1,null), (2,2)) a(k,v);

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

SELECT count(*) FROM (SELECT to_json(a) AS a, JSON_OBJECTAGG(k : v ABSENT ON NULL WITH UNIQUE KEYS)
   OVER (ORDER BY k)
FROM (VALUES (1,1), (1,null), (2,2)) a(k,v)) AS _sub;


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

SELECT * FROM test_bpchar WHERE i='abc  ' ORDER BY i;

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


Question: pgTAP test for Functap (assertion 216).

/****************************************************************************/
-- Test is_aggregate() and isnt_aggregate().

-- is_aggregate ( NAME, NAME, NAME[], TEXT )
-- isnt_aggregate ( NAME, NAME, NAME[], TEXT )
SELECT * FROM check_test(
    is_aggregate( 'public', 'tap_accum', ARRAY[etype()], 'whatever' ),
    true,
    'is_aggregate(schema, func, arg, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

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


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

SELECT JSON_EXISTS(jsonb '{"a": 1, "b": 2}', '$.* ? (@ > $x && @ < $y)' PASSING 0 AS x, 1 AS y);

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

SELECT count(*) FROM (SELECT JSON_EXISTS(jsonb '{"a": 1, "b": 2}', '$.* ? (@ > $x && @ < $y)' PASSING 0 AS x, 1 AS y)) AS _sub;


Question: Show an example of PostgreSQL ALTER CONVERSION (example 1).

ALTER CONVERSION iso_8859_1_to_utf8 RENAME TO latin1_to_unicode;

Explanation: PostgreSQL ALTER CONVERSION command.


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

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

SELECT count(*) FROM (SELECT stddev_pop(3.0::float4), stddev_samp(4.0::float4)) AS _sub;


Question: Show a SQL definition from the citus project (multi_sql_function, item 4).

CREATE FUNCTION sql_test_no_2() RETURNS bigint AS '
	SELECT
		count(*)
	FROM
		orders, lineitem
	WHERE
		o_orderkey = l_orderkey;


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

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


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

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


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

SELECT *
FROM
	(VALUES ('1'), ('"err"')) vals(js)
		LEFT OUTER JOIN
	JSON_TABLE(vals.js::jsonb, '$' COLUMNS (a int PATH '$' ERROR ON ERROR)) jt
		ON true;

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

SELECT count(*) FROM (SELECT *
FROM
	(VALUES ('1'), ('"err"')) vals(js)
		LEFT OUTER JOIN
	JSON_TABLE(vals.js::jsonb, '$' COLUMNS (a int PATH '$' ERROR ON ERROR)) jt
		ON true) AS _sub;


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

SELECT
	JSON_OBJECTAGG(i: i),
--	JSON_OBJECTAGG(i VALUE i),
--	JSON_OBJECTAGG(KEY i VALUE i),
	JSON_OBJECTAGG(i: i RETURNING jsonb)
FROM
	generate_series(1, 5) i;

SELECT count(*) FROM (SELECT
	JSON_OBJECTAGG(i: i),
--	JSON_OBJECTAGG(i VALUE i),
--	JSON_OBJECTAGG(KEY i VALUE i),
	JSON_OBJECTAGG(i: i RETURNING jsonb)
FROM
	generate_series(1, 5) i) AS _sub;


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

SELECT '[{"attributes" : [2,3], "dependency": 4, "degree": 1.000, "degree": 1.000}]'::pg_dependencies;

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

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


Question: Write the DDL statement from PostgreSQL regression test 'create_role' (example 33).

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


Question: PostgreSQL regression test 'geometry': Write the SELECT query (example 119).

SELECT c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
   FROM CIRCLE_TBL c1, POINT_TBL p1
   WHERE (p1.f1 <-> c1.f1) > 0
   ORDER BY distance, area(c1.f1), p1.f1[0];

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

SELECT count(*) FROM (SELECT c1.f1 AS circle, p1.f1 AS point, (p1.f1 <-> c1.f1) AS distance
   FROM CIRCLE_TBL c1, POINT_TBL p1
   WHERE (p1.f1 <-> c1.f1) > 0
   ORDER BY distance, area(c1.f1), p1.f1[0]) AS _sub;


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

-- tablespace_privs_are ( tablespace, user, privileges[], description )
CREATE OR REPLACE FUNCTION tablespace_privs_are ( NAME, NAME, NAME[], TEXT )
RETURNS TEXT AS $$
DECLARE
    grants TEXT[] := _get_tablespaceprivs( $2, quote_ident($1) );
BEGIN
    IF grants[1] = 'undefined_tablespace' THEN
        RETURN ok(FALSE, $4) || E'\n' || diag(
            '    Tablespace ' || quote_ident($1) || ' does not exist'
        );
    ELSIF grants[1] = 'undefined_role' THEN
        RETURN ok(FALSE, $4) || E'\n' || diag(
            '    Role ' || quote_ident($2) || ' does not exist'
        );
    END IF;
    RETURN _assets_are('privileges', grants, $3, $4);
END;
$$ LANGUAGE plpgsql;

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


Question: Write the DML statement from PostgreSQL regression test 'update' (example 248).

UPDATE list_parted set b = c + a WHERE a = 2;

Explanation: DML from PostgreSQL core regression test for Update.


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

$$;

CALL ptest4c(NULL);

DROP PROCEDURE ptest4a, ptest4c;

-- named and default parameters

CREATE OR REPLACE PROCEDURE ptest5(a int, b text, c int default 100)
LANGUAGE SQL
AS $$
INSERT INTO cp_test VALUES(a, b);

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


Question: PostgreSQL regression test 'stats_ext': Write the SELECT query (example 577).

SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE b = ''x'' OR d = ''x''');

Explanation: Regression test for Stats Ext in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE b = ''x'' OR d = ''x''')) AS _sub;


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

DROP TRIGGER parent_update_trig ON range_parted;

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


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

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


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

SELECT citext_pattern_cmp('a'::citext, 'B'::citext) < 0 AS true;

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


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

CREATE SEQUENCE sequence_testx AS smallint MINVALUE -100000;

Explanation: DDL from PostgreSQL core regression test for Sequence.


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

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

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


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

SELECT 1 FROM postgres_fdw_disconnect('loopback2');

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


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

create view v1 as select * from tt2 natural join tt3;

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


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

Explanation: DDL from PostgreSQL core regression test for Domain.


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

create domain ddef5 numeric(8,2) NOT NULL DEFAULT '12.12';


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

$$ language plpgsql;

select compos();

-- ... but this does
create or replace function compos() returns compostype as $$
begin
  return (1, 'hello')::compostype;

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


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

DELETE FROM fk_notpartitioned_pk WHERE b = 142857;

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


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

SELECT JSON_QUERY('"a"', '$.a'  RETURNING int[] DEFAULT (SELECT '{1}')::oid[]::int[] ON ERROR);

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

SELECT count(*) FROM (SELECT JSON_QUERY('"a"', '$.a'  RETURNING int[] DEFAULT (SELECT '{1}')::oid[]::int[] ON ERROR)) AS _sub;


Question: PostgreSQL Xfunc: show example 21.

SELECT anyleast('abc'::text, 'ABC' COLLATE "C");

Explanation: Example from PostgreSQL documentation on Xfunc.


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

SELECT name, 'a' = name AS t      FROM try where name = 'a';


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

INSERT INTO measurement VALUES (1, '2006-03-27', 15, 40);

Explanation: DML from PostgreSQL core regression test for Merge.


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

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


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

CREATE TABLE FKTABLE (
  tid int, id int,
  fk_id_del_set_null int,
  fk_id_del_set_default int DEFAULT 0,
  FOREIGN KEY (tid, fk_id_del_set_null) REFERENCES PKTABLE ON DELETE SET NULL (fk_id_del_set_null),
  -- this tests handling of duplicate entries in SET DEFAULT column list
  FOREIGN KEY (tid, fk_id_del_set_default) REFERENCES PKTABLE ON DELETE SET DEFAULT (fk_id_del_set_default, fk_id_del_set_default)
);

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


Question: Write the DML statement from PostgreSQL regression test 'path' (example 5).

Explanation: DML from PostgreSQL core regression test for Path.


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

\set ON_ERROR_STOP 1

-- Test with UNIQUE index on multiple columns instead of PRIMARY KEY constraint
CREATE TABLE upsert_test_unique(time timestamp, temp float, color text);

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


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

select jsonb_path_query('[null, 1, "a\b", "a\\b", "^a\\b$"]', 'lax $[*] ? (@ like_regex "^a\\B$" flag "q")');

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

SELECT count(*) FROM (select jsonb_path_query('[null, 1, "a\b", "a\\b", "^a\\b$"]', 'lax $[*] ? (@ like_regex "^a\\B$" flag "q")')) AS _sub;


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

ALTER EXTENSION pgtap ADD FUNCTION set_eq( TEXT, TEXT, TEXT );

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


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

CREATE TRIGGER t1 BEFORE INSERT ON test1 EXECUTE PROCEDURE triggerfunc1();

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


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

select jsonb '{"a": 1, "b": [1, 2]}' @? 'lax $.keyvalue().key';

SELECT count(*) FROM (select jsonb '{"a": 1, "b": [1, 2]}' @? 'lax $.keyvalue().key') AS _sub;


Question: pgTAP test for Hastap (assertion 3).

CREATE TABLE public.sometab(
    id      INT NOT NULL PRIMARY KEY,
    name    TEXT DEFAULT '',
    numb    NUMERIC(10, 2),
    "myInt" NUMERIC(8)
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

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

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


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

SELECT to_timestamp('2015-02-11 86000', 'YYYY-MM-DD SSSSS');  -- ok
SELECT to_timestamp('2015-02-11 86400', 'YYYY-MM-DD SSSSS');

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

SELECT count(*) FROM (SELECT to_timestamp('2015-02-11 86000', 'YYYY-MM-DD SSSSS');  -- ok
SELECT to_timestamp('2015-02-11 86400', 'YYYY-MM-DD SSSSS')) AS _sub;


Question: PostgreSQL Indices: show example 33.

SELECT target FROM tests WHERE subject = 'some-subject' AND success;

Explanation: Example from PostgreSQL documentation on Indices.


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

SELECT * FROM multiout_table_type_setof('str', 'f', 7);

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


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

CREATE VIEW rw_view1 AS
  SELECT *, 'Const' AS c, (SELECT concat('b: ', b)) AS d FROM base_tbl WHERE a>0;

Explanation: DDL from PostgreSQL core regression test for Updatable Views.


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

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


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

--
-- bt_metap()
--
CREATE FUNCTION bt_metap(IN relname text,
    OUT magic int4,
    OUT version int4,
    OUT root int4,
    OUT level int4,
    OUT fastroot int4,
    OUT fastlevel int4)
AS 'MODULE_PATHNAME', 'bt_metap'
LANGUAGE C STRICT PARALLEL SAFE;


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

CREATE OPERATOR @#@ (
   rightarg = int8,		-- prefix
   procedure = factorial
);

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


Question: PostgreSQL regression test 'stats': Write the SELECT query (example 82).

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

SELECT count(*) FROM (SELECT pg_stat_get_xact_function_calls(:stats_test_func2_oid)) AS _sub;


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

\sf test1
\sf test2

-- Test %TYPE and %ROWTYPE error cases
create table misc_table(f1 int);

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


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

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


Question: pgTAP test for Functap (assertion 364).

SELECT * FROM check_test(
    volatility_is( 'public', 'pet', '{}'::name[], 'stable', 'whatever' ),
    true,
    'function_volatility(schema, func, 0 args, stable, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

CREATE INDEX brinidx_bloom ON brintest_bloom USING brin (
	byteacol bytea_bloom_ops,
	charcol char_bloom_ops,
	namecol name_bloom_ops,
	int8col int8_bloom_ops,
	int2col int2_bloom_ops,
	int4col int4_bloom_ops,
	textcol text_bloom_ops,
	oidcol oid_bloom_ops,
	float4col float4_bloom_ops,
	float8col float8_bloom_ops,
	macaddrcol macaddr_bloom_ops,
	inetcol inet_bloom_ops,
	cidrcol inet_bloom_ops,
	bpcharcol bpchar_bloom_ops,
	datecol date_bloom_ops,
	timecol time_bloom_ops,
	timestampcol timestamp_bloom_ops,
	timestamptzcol timestamptz_bloom_ops,
	intervalcol interval_bloom_ops,
	timetzcol timetz_bloom_ops,
	numericcol numeric_bloom_ops,
	uuidcol uuid_bloom_ops,
	lsncol pg_lsn_bloom_ops
) with (pages_per_range = 1);

Explanation: DDL from PostgreSQL core regression test for Brin Bloom.


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

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

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


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

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

SELECT count(*) FROM (select '[]'::jsonb || '{"a":"b"}'::jsonb) AS _sub;


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

SELECT * FROM test_int8 WHERE i<=1::int8 ORDER BY i;

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


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

CREATE VIEW temporal3 AS SELECT * FROM t1 LEFT JOIN tt ON t1.num = tt.num2;

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


Question: Write the DDL statement from PostgreSQL regression test 'cluster' (example 129).

CREATE TABLE clstrpart3 PARTITION OF clstrpart DEFAULT PARTITION BY RANGE (a);

Explanation: DDL from PostgreSQL core regression test for Cluster.


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

SELECT '[{"attributes": [1,2], "dependency": 2, "degree": 1}]' ::pg_dependencies;

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

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


Question: Write the DDL statement from PostgreSQL regression test 'triggers' (example 548).

create or replace trigger my_trig
  after insert on parted_trig_1
  for each row execute procedure funcB();  -- should fail
insert into parted_trig (a) values (50);

Explanation: DDL from PostgreSQL core regression test for Triggers.


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

$$ LANGUAGE plperl;

SELECT myfuncs();

-- make sure we can't return an array as a scalar
CREATE OR REPLACE FUNCTION text_arrayref() RETURNS text AS $$
	return ['array'];

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


Question: Show a SQL definition from the citus project (modification_correctness, item 3).

CREATE TABLE test(k int, a int, b int, c int unique, d int, e int);

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


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

CREATE TABLE stats_ext_tbl (id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, col TEXT);

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


Question: PostgreSQL regression test 'object_address': Write the SELECT query (example 63).

SELECT pg_get_object_address('event trigger', '{one,two}', '{}');

Explanation: Regression test for Object Address in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT pg_get_object_address('event trigger', '{one,two}', '{}')) AS _sub;


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

SELECT * FROM test_enum WHERE i<'g'::rainbow ORDER BY i;


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

select pct, count(unique1) from
  (values (0),(100)) v(pct),
  lateral (select * from tenk1 tablesample bernoulli (pct)) ss
  group by pct;

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

SELECT count(*) FROM (select pct, count(unique1) from
  (values (0),(100)) v(pct),
  lateral (select * from tenk1 tablesample bernoulli (pct)) ss
  group by pct) AS _sub;


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

SELECT * FROM ltreetest WHERE t ~ '23.*.2' order by t asc;

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


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

SELECT * FROM header_doesnt_match; -- ERROR

-- test multi-line header
\set filename :abs_srcdir '/data/multiline_header.csv'
CREATE FOREIGN TABLE multi_header (a int, b text) SERVER file_server
OPTIONS (format 'csv', filename :'filename', header '2');

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


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

select conname, contype, conrelid::regclass, conindid::regclass, conkey
  from pg_constraint where conrelid::regclass::text like 'idxpart%'
  order by conrelid::regclass::text, conname;

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

SELECT count(*) FROM (select conname, contype, conrelid::regclass, conindid::regclass, conkey
  from pg_constraint where conrelid::regclass::text like 'idxpart%'
  order by conrelid::regclass::text, conname) AS _sub;


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

select interval '2147483647 months 0.1 centuries';

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

SELECT count(*) FROM (select interval '2147483647 months 0.1 centuries') AS _sub;


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

create table fktable2 (d int, e int, foreign key (d, e) references pktable2);

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


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

insert into dcomptable (d1[1].r) values(11);

Explanation: DML from PostgreSQL core regression test for Domain.


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

CREATE FUNCTION fail_drop_table() RETURNS event_trigger AS $fdt$
    BEGIN
        RAISE 'illegal value';


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

INSERT INTO mcv_lists (a, b, c, filler1)
     SELECT i, i, i, i FROM generate_series(1,1000) s(i);

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


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

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

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


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

select (fn).first, substr((fn).last, 1, 20), length((fn).last) from people;

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

SELECT count(*) FROM (select (fn).first, substr((fn).last, 1, 20), length((fn).last) from people) AS _sub;


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

select websearch_to_tsquery('english', 'pg_class pg"');

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

SELECT count(*) FROM (select websearch_to_tsquery('english', 'pg_class pg"')) AS _sub;


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

SELECT is_normalized('abc', 'def');  -- run-time error;

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

SELECT count(*) FROM (SELECT is_normalized('abc', 'def');  -- run-time error) AS _sub;


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

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


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

create rule rtest_nothn_r3 as on insert to rtest_nothn2
	where new.a >= 100 do instead
	insert into rtest_nothn3 values (new.a, new.b);

Explanation: DDL from PostgreSQL core regression test for Rules.


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

INSERT INTO new_measurement VALUES (2, '2006-02-10', 20, 20);

Explanation: DML from PostgreSQL core regression test for Merge.


Question: pgTAP test for Runjusttests (assertion 11).

CREATE OR REPLACE FUNCTION whatever."test ident"() RETURNS SETOF TEXT AS $$
BEGIN
    RETURN NEXT pass( 'ident' );
    RETURN NEXT pass( 'ident 2' );
END;
$$ LANGUAGE plpgsql;

Explanation: SQL assertion from pgTAP test suite for Runjusttests.


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

SELECT count(*) FROM timestamptztmp WHERE a  = '2018-12-18 10:59:54 GMT+4'::timestamptz;

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


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

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


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

INSERT INTO a_star (class, a) VALUES ('a', 1);

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


Question: Write the DDL statement from PostgreSQL regression test 'generated_virtual' (example 14).

CREATE TABLE gtest2 (a int, b text GENERATED ALWAYS AS (a || ' sec') VIRTUAL);

Explanation: DDL from PostgreSQL core regression test for Generated Virtual.


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

SELECT to_tsquery('english', '(s <-> (a <-> 1)) <-> 2');

SELECT count(*) FROM (SELECT to_tsquery('english', '(s <-> (a <-> 1)) <-> 2')) AS _sub;


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

UPDATE arrtest
  SET a[1:2] = '{16,25}'
  WHERE NOT a = '{}'::_int2;

Explanation: DML from PostgreSQL core regression test for Arrays.


Question: Write the DML statement from PostgreSQL regression test 'with' (example 19).

INSERT INTO department VALUES (0, NULL, 'ROOT');

Explanation: DML from PostgreSQL core regression test for With.


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

SELECT rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, rolvaliduntil FROM pg_authid WHERE rolname = 'regress_test_def_createdb';

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

SELECT count(*) FROM (SELECT rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, rolvaliduntil FROM pg_authid WHERE rolname = 'regress_test_def_createdb') AS _sub;


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

select definition from pg_views where viewname='vw_ord';

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

SELECT count(*) FROM (select definition from pg_views where viewname='vw_ord') AS _sub;


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

Explanation: DML from PostgreSQL core regression test for Uuid.


Question: pgTAP test for Policy (assertion 52).

SELECT * FROM check_test(
    policy_cmd_is( 'public', 'passwd', 'daemon_insert'::NAME, 'delete' ),
    false,
    'policy_cmd_is(schema, table, policy, command) for INSERT should fail',
    'Policy daemon_insert for table public.passwd should apply to DELETE command',
    '        have: INSERT
        want: DELETE'
);

Explanation: SQL assertion from pgTAP test suite for Policy.


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

SELECT random('1979-02-08 +05'::timestamptz,'1979-02-08 +05'::timestamptz) AS random_timestamptz_empty_range;

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

SELECT count(*) FROM (SELECT random('1979-02-08 +05'::timestamptz,'1979-02-08 +05'::timestamptz) AS random_timestamptz_empty_range) AS _sub;


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

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

SELECT count(*) FROM (select jsonb_path_query('[1]', '$[last]')) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'stats' (example 20).

INSERT INTO trunc_stats_test1 DEFAULT VALUES;

Explanation: DML from PostgreSQL core regression test for Stats.


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

SELECT jsonb_exists_all('{"a":null, "b":"qq"}', ARRAY['c','a']);

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

SELECT count(*) FROM (SELECT jsonb_exists_all('{"a":null, "b":"qq"}', ARRAY['c','a'])) AS _sub;


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

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

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


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

create statistics (ndistinct) on a, b from stts_t1;

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


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

CREATE FUNCTION gin_extract_value_float4(float4, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;

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


Question: pgTAP test for Usergroup (assertion 20).

SELECT * FROM check_test(
    has_group('aoijaoisjfaoidfjaisjdfosjf', 'desc'),
    false,
    'has_group(nonexistent group, desc)',
    'desc',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Usergroup.


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

SELECT test_mblen_func('pg_mblen_range', 'UTF8', truncated, 3)
FROM regress_encoding;

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

SELECT count(*) FROM (SELECT test_mblen_func('pg_mblen_range', 'UTF8', truncated, 3)
FROM regress_encoding) AS _sub;


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

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


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

Explanation: DDL from PostgreSQL core regression test for Equivclass.


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

-- explicit spec of return type is OK
CREATE OR REPLACE FUNCTION rngfunc(in f1 int, out f2 int) RETURNS int
AS 'select $1+1' LANGUAGE sql;

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


Question: Show a SQL definition from the timescaledb project (test_tss_callbacks, item 3).

CREATE OR REPLACE FUNCTION test.teardown_tss_hook_v1() RETURNS VOID
    AS :MODULE_PATHNAME, 'ts_teardown_tss_hook_v1' LANGUAGE C VOLATILE;

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


Question: Show a query using PostgreSQL contrib extension 'unaccent' (example 17).

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


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

CREATE TRIGGER evtrg_nontemp_trig
  BEFORE INSERT ON evtrg_nontemp_table
  EXECUTE FUNCTION event_trigger_dummy_trigger();

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


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

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

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


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

SELECT '[{"attributes" : [2,3], "dependency" : "\ud83d", "degree": 0.250}]'::pg_dependencies;

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

SELECT count(*) FROM (SELECT '[{"attributes" : [2,3], "dependency" : "\ud83d", "degree": 0.250}]'::pg_dependencies) AS _sub;