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

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

Explanation: DML from PostgreSQL core regression test for Timestamp.


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

select heap_force_freeze('mvw'::regclass, ARRAY['(0, 3)']::tid[]);

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


Question: Show a query using PostgreSQL contrib extension 'xml2' (example 15).

SELECT * FROM
xpath_table('article_id',
            'article_xml',
            'articles',
            '/article/author|/article/pages|/article/title',
            'date_entered > ''2003-01-01'' ')
AS t(article_id integer, author text, page_count integer, title text);

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


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

CREATE FUNCTION pglogical.wait_for_table_sync_complete(subscription_name name, relation regclass)
RETURNS void RETURNS NULL ON NULL INPUT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_wait_for_table_sync_complete';

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


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

SELECT c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*';

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

SELECT count(*) FROM (SELECT c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*') AS _sub;


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

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

SELECT count(*) FROM (select '[1:]={1}'::int[]) AS _sub;


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

insert into dcomptable values (array[row(1,2)]::dcomptypea);  -- fail on uniqueness
insert into dcomptable (d1[1]) values(row(9,10));

Explanation: DML from PostgreSQL core regression test for Domain.


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

CREATE TABLE pglogical.queue (
    queued_at timestamp with time zone NOT NULL,
    role name NOT NULL,
    replication_sets text[],
    message_type "char" NOT NULL,
    message json NOT NULL
);


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

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

SELECT count(*) FROM (SELECT jsonb_typeof('[]') AS array) AS _sub;


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

SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING json);

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

SELECT count(*) FROM (SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING json)) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'returning' (example 35).

CREATE OR REPLACE RULE voo_i AS ON INSERT TO voo DO INSTEAD
  INSERT INTO foo VALUES(new.*, 57) RETURNING f1, f2;

Explanation: DDL from PostgreSQL core regression test for Returning.


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

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

SELECT count(*) FROM (SELECT ts_headline('english', '

Sea view wow foo bar qq
YES
ff-bg


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

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

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


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

SELECT * FROM pg_input_error_info('1e400000', 'numeric');

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

SELECT count(*) FROM (SELECT * FROM pg_input_error_info('1e400000', 'numeric')) AS _sub;


Question: pgTAP test for Index (assertion 94).

SELECT * FROM check_test(
    is_clustered( 'idx_bar' ),
    true,
    'is_clustered() index only',
    'Table should be clustered on index idx_bar',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Index.


Question: pgTAP test for Privs (assertion 80).

SELECT * FROM check_test(
    tablespace_privs_are( 'pg_default', current_user, '{CREATE}' ),
    true,
    'tablespace_privs_are(tablespace, role, privs, desc)',
    'Role ' || quote_ident(current_user) || ' should be granted CREATE on tablespace pg_default',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Privs.


Question: PostgreSQL regression test 'alter_generic': Write the SELECT query (example 73).

SELECT nspname, opcname, amname, rolname
  FROM pg_opclass o, pg_am m, pg_namespace n, pg_authid a
  WHERE o.opcmethod = m.oid AND o.opcnamespace = n.oid AND o.opcowner = a.oid
    AND n.nspname IN ('alt_nsp1', 'alt_nsp2')
  ORDER BY nspname, opcname;

Explanation: Regression test for Alter Generic in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT nspname, opcname, amname, rolname
  FROM pg_opclass o, pg_am m, pg_namespace n, pg_authid a
  WHERE o.opcmethod = m.oid AND o.opcnamespace = n.oid AND o.opcowner = a.oid
    AND n.nspname IN ('alt_nsp1', 'alt_nsp2')
  ORDER BY nspname, opcname) AS _sub;


Question: pgTAP test for Coltap (assertion 62).

SELECT * FROM check_test(
    col_has_default( 'sometab', '__asdfasdfs__' ),
    false,
    'col_has_default( tab, col )',
    'Column sometab.__asdfasdfs__ should have a default',
    '    Column sometab.__asdfasdfs__ does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Coltap.


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

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

SELECT count(*) FROM (SELECT pg_partition_root('ptif_test3_index')) AS _sub;


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

end$$ language plpgsql;

select multi_datum_use(42);

--
-- Test STRICT limiter in both planned and EXECUTE invocations.
-- Note that a data-modifying query is quasi strict (disallow multi rows)
-- by default in the planned case, but not in EXECUTE.
--

create temp table foo (f1 int, f2 int);

insert into foo values (1,2), (3,4);

create or replace function stricttest() returns void as $$
declare x record;

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


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

CREATE FUNCTION cube(float8) RETURNS cube
AS 'MODULE_PATHNAME', 'cube_f8'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

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


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


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

CREATE TABLE quad_box_tbl_ord_seq2 AS
SELECT rank() OVER (ORDER BY b <-> point '123,456') n, b <-> point '123,456' dist, id
FROM quad_box_tbl WHERE b <@ box '((200,300),(500,600))';

Explanation: DDL from PostgreSQL core regression test for Box.


Question: Write the DDL statement from PostgreSQL regression test 'numeric' (example 6).

CREATE TABLE num_exp_sqrt (id int4, expected numeric(210,10));

Explanation: DDL from PostgreSQL core regression test for Numeric.


Question: pgTAP test for Hastap (assertion 55).

SELECT * FROM check_test(
    hasnt_view( '__SDFSDFD__', 'howdy' ),
    true,
    'hasnt_view(non-existent view, desc)',
    'howdy',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


Question: Write the DDL statement from PostgreSQL regression test 'constraints' (example 332).

CREATE TABLE ATACC3 (a int) INHERITS (ATACC2);

Explanation: DDL from PostgreSQL core regression test for Constraints.


Question: Write the DDL statement from PostgreSQL regression test 'spgist' (example 24).

create table spgist_domain_tbl (f1 spgist_text);

Explanation: DDL from PostgreSQL core regression test for Spgist.


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

DROP FUNCTION tp_ins_data(), tp_chk_data();

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


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

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


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

create rule qqq as on delete to copydml_test do also insert into copydml_test default values;

Explanation: DDL from PostgreSQL core regression test for Copydml.


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

DROP TRIGGER trig_skip_delete ON sub_part2;

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


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

select m, m is not null from makedcomp(1,2) m;

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

SELECT count(*) FROM (select m, m is not null from makedcomp(1,2) m) AS _sub;


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

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


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

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


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

SELECT a, a::bool FROM JSON_TABLE(jsonb '{"a":1}', '$' COLUMNS (a dint4_0 EXISTS PATH '$.b' TRUE ON ERROR));

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

SELECT count(*) FROM (SELECT a, a::bool FROM JSON_TABLE(jsonb '{"a":1}', '$' COLUMNS (a dint4_0 EXISTS PATH '$.b' TRUE ON ERROR))) AS _sub;


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

Explanation: DML from PostgreSQL core regression test for Int8.


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

$$ language plpgsql;

select compos();

-- this does not work currently (no implicit casting)
create or replace function compos() returns compostype as $$
begin
  return (1, 'hello');


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

SELECT * FROM test_int2 WHERE i<=(-32769)::int4 ORDER BY i;

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


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

SELECT v as value, uuid_hash(v)::bit(32) as standard,
       uuid_hash_extended(v, 0)::bit(32) as extended0,
       uuid_hash_extended(v, 1)::bit(32) as extended1
FROM   (VALUES (NULL::uuid), ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'),
        ('5a9ba4ac-8d6f-11e7-bb31-be2e44b06b34'),
        ('99c6705c-d939-461c-a3c9-1690ad64ed7b'),
        ('7deed3ca-8d6f-11e7-bb31-be2e44b06b34'),
        ('9ad46d4f-6f2a-4edd-aadb-745993928e1e')) x(v)
WHERE  uuid_hash(v)::bit(32) != uuid_hash_extended(v, 0)::bit(32)
       OR uuid_hash(v)::bit(32) = uuid_hash_extended(v, 1)::bit(32);

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

SELECT count(*) FROM (SELECT v as value, uuid_hash(v)::bit(32) as standard,
       uuid_hash_extended(v, 0)::bit(32) as extended0,
       uuid_hash_extended(v, 1)::bit(32) as extended1
FROM   (VALUES (NULL::uuid), ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'),
        ('5a9ba4ac-8d6f-11e7-bb31-be2e44b06b34'),
        ('99c6705c-d939-461c-a3c9-1690ad64ed7b'),
        ('7deed3ca-8d6f-11e7-bb31-be2e44b06b34'),
        ('9ad46d4f-6f2a-4edd-aadb-745993928e1e')) x(v)
WHERE  uuid_hash(v)::bit(32) != uuid_hash_extended(v, 0)::bit(32)
       OR uuid_hash(v)::bit(32) = uuid_hash_extended(v, 1)::bit(32)) AS _sub;


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

-- Ensure that we never choose to provide presorted input to an Aggref with
-- a volatile function in the ORDER BY / DISTINCT clause.  We want to ensure
-- these sorts are performed individually rather than at the query level.
explain (costs off)
select
  sum(unique1 order by two), sum(unique1 order by four),
  sum(unique1 order by four, two), sum(unique1 order by two, random()),
  sum(unique1 order by two, random(), random() + 1)
from tenk1
group by ten;

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


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

SELECT txid_status(1); -- BootstrapTransactionId is always committed
SELECT txid_status(2); -- FrozenTransactionId is always committed
SELECT txid_status(3); -- in regress testing FirstNormalTransactionId will always be behind oldestXmin

COMMIT;

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

SELECT count(*) FROM (SELECT txid_status(1); -- BootstrapTransactionId is always committed
SELECT txid_status(2); -- FrozenTransactionId is always committed
SELECT txid_status(3); -- in regress testing FirstNormalTransactionId will always be behind oldestXmin

COMMIT) AS _sub;


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

CREATE STATISTICS group_tbl_stat (ndistinct) ON a, b FROM group_tbl;

Explanation: DDL from PostgreSQL core regression test for Join.


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

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

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


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

SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;


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

SELECT ('\x' || repeat('@', 34))::bytea;

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

SELECT count(*) FROM (SELECT ('\x' || repeat('@', 34))::bytea) AS _sub;


Question: pgTAP test for Ownership (assertion 27).

SELECT * FROM check_test(
    relation_owner_is('public', '__not__sometab', current_user, 'mumble'),
	false,
    'relation_owner_is(sch, non-tab, user)',
    'mumble',
    '    Relation public.__not__sometab does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Ownership.


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

select a, b, count(*) from gstest2 group by grouping sets ((a, b), (a)) having a > 1 and b > 1;

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

SELECT count(*) FROM (select a, b, count(*) from gstest2 group by grouping sets ((a, b), (a)) having a > 1 and b > 1) AS _sub;


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

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


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

CREATE DOMAIN testdomain_i AS int COLLATE "sv-x-icu"; -- fails
CREATE TABLE collate_test4 (
    a int,
    b testdomain_sv
);

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


Question: pgTAP test for Hastap (assertion 84).

SELECT * FROM check_test(
    hasnt_composite( 'sometype', 'lol' ),
    false,
    'hasnt_composite(tab, desc)',
    'lol',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

CREATE POLICY p2 ON y1 FOR SELECT USING (a > 2);

Explanation: DDL from PostgreSQL core regression test for Rowsecurity.


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

SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = ANY (ARRAY[1, 2, 51, 52]) AND b = ANY (ARRAY[''1'', ''2''])');

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

SELECT count(*) FROM (SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = ANY (ARRAY[1, 2, 51, 52]) AND b = ANY (ARRAY[''1'', ''2''])')) AS _sub;


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

Explanation: DDL from PostgreSQL core regression test for Insert.


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

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

SELECT count(*) FROM (SELECT '-1'::money / 1.175494e-38::float4) AS _sub;


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

/* contrib/postgres_fdw/postgres_fdw--1.0--1.1.sql */

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

CREATE FUNCTION postgres_fdw_get_connections (OUT server_name text,
    OUT valid boolean)
RETURNS SETOF record
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT PARALLEL RESTRICTED;


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

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


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

create function alter1.same(alter1.ctype, alter1.ctype) returns boolean language sql
as 'select $1.f1 is not distinct from $2.f1 and $1.f2 is not distinct from $2.f2';

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


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

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

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


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

-- Create the operator class
CREATE OPERATOR CLASS gist_cash_ops
DEFAULT FOR TYPE money USING gist
AS
	OPERATOR	1	<  ,
	OPERATOR	2	<= ,
	OPERATOR	3	=  ,
	OPERATOR	4	>= ,
	OPERATOR	5	>  ,
	OPERATOR	6	<> ,
	OPERATOR	15	<-> FOR ORDER BY pg_catalog.money_ops ,
	FUNCTION	1	gbt_cash_consistent (internal, money, int2, oid, internal),
	FUNCTION	2	gbt_cash_union (internal, internal),
	FUNCTION	3	gbt_cash_compress (internal),
	FUNCTION	4	gbt_decompress (internal),
	FUNCTION	5	gbt_cash_penalty (internal, internal, internal),
	FUNCTION	6	gbt_cash_picksplit (internal, internal),
	FUNCTION	7	gbt_cash_same (gbtreekey16, gbtreekey16, internal),
	FUNCTION	8	gbt_cash_distance (internal, money, int2, oid, internal),
	FUNCTION	9	gbt_cash_fetch (internal),
	FUNCTION	11	gbt_cash_sortsupport (internal),
	FUNCTION	12 ("any", "any") gist_translate_cmptype_btree (int),
	STORAGE		gbtreekey16;


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

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


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

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

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


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


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

SELECT 'cleanup' FROM pg_drop_replication_slot('regression_slot');

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


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

CREATE TABLE guid2
(
	guid_field UUID,
	text_field TEXT DEFAULT(now())
);

Explanation: DDL from PostgreSQL core regression test for Uuid.


Question: Write the DML statement from PostgreSQL regression test 'gin' (example 11).

delete from gin_test_tbl where i @> array[2];

Explanation: DML from PostgreSQL core regression test for Gin.


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

select * from jsonb_to_record('{"ia2": [1, 2, 3]}') as x(ia2 int[][]);

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

SELECT count(*) FROM (select * from jsonb_to_record('{"ia2": [1, 2, 3]}') as x(ia2 int[][])) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'oid' (example 2).

INSERT INTO OID_TBL(f1) VALUES ('1234');

Explanation: DML from PostgreSQL core regression test for Oid.


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

CREATE RULE InsertRule AS
    ON INSERT TO rule_v1
    DO INSTEAD
        INSERT INTO rule_t1 VALUES(new.a);

Explanation: DDL from PostgreSQL core regression test for Rules.


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

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


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

CREATE OR REPLACE FUNCTION
perl_out_params_set(out f1 integer, out f2 text, out f3 text)
RETURNS SETOF record AS $$
    return [
        { f1 => 1, f2 => 'Hello', f3 =>  'World' },
        { f1 => 2, f2 => 'Hello', f3 =>  'PostgreSQL' },
        { f1 => 3, f2 => 'Hello', f3 =>  'PL/Perl' }
    ];
$$  LANGUAGE plperl;

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


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

SELECT strpos('high',         'gh'::citext) = 3 AS t;

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


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

select * from jsonb_populate_recordset(row(1000000000::int,50::int),'[{"b":"2"},{"a":"3"}]') q (a text, b text);

SELECT count(*) FROM (select * from jsonb_populate_recordset(row(1000000000::int,50::int),'[{"b":"2"},{"a":"3"}]') q (a text, b text)) AS _sub;


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

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

SELECT count(*) FROM (SELECT xml_is_well_formed('abc')) AS _sub;


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

SELECT ts_rewrite('moscow', 'SELECT keyword, sample FROM test_tsquery'::text );

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

SELECT count(*) FROM (SELECT ts_rewrite('moscow', 'SELECT keyword, sample FROM test_tsquery'::text )) AS _sub;


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

Explanation: DDL from PostgreSQL core regression test for Join.


Question: PostgreSQL Json: show example 8.

SELECT doc->'site_name' FROM websites WHERE doc->'tags' @> '[{"term":"paris"}, {"term":"food"}]';

Explanation: Example from PostgreSQL documentation on Json.


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

SELECT count(*) FROM varbittmp WHERE a <=  '1110100111010';

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


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

Explanation: DDL from PostgreSQL core regression test for Merge.


Question: PL/pgSQL test: Plperl Plperlu (example 14).

CREATE OR REPLACE FUNCTION use_plperl() RETURNS void LANGUAGE plperl
AS $$
use Errno;
$$;

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


Question: PL/pgSQL test: Plpython Spi (example 7).

CREATE FUNCTION join_sequences(s sequences) RETURNS text
	AS
'if not s["multipart"]:
	return s["sequence"]
q = "SELECT sequence FROM xsequences WHERE pid = ''%s''" % s["pid"]
rv = plpy.execute(q)
seq = s["sequence"]
for r in rv:
	seq = seq + r["sequence"]
return seq
'
	LANGUAGE plpython3u;

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


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

SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL');

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 IS NULL AND b IS NULL')) AS _sub;


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

CREATE FUNCTION hstore_to_jsonb_loose(hstore)
RETURNS jsonb
AS 'MODULE_PATHNAME', 'hstore_to_jsonb_loose'
LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;

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


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

select * from jsonb_to_record('{"out": {"key": 1}}') as x(out json);

SELECT count(*) FROM (select * from jsonb_to_record('{"out": {"key": 1}}') as x(out json)) AS _sub;


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

SELECT count(*) FROM cidrtmp WHERE a >  '121.111.63.82'::cidr;


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

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


Question: PL/pgSQL test: Plpgsql Array (example 17).

do $$ declare a int[];
begin a := * from onecol for update; raise notice 'a = %', a; end$$;

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


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

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

SELECT count(*) FROM (select regexp_matches('foobar', '(?<=f)b+')) AS _sub;


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

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

SELECT count(*) FROM (select '{"aa":1 , "b":2, "cq":3}'::jsonb || '{}') AS _sub;


Question: pgTAP test for Resultset (assertion 347).

SELECT * FROM check_test(
    set_hasnt( 'anames', 'others', 'whatever' ),
    true,
    'set_hasnt( prepared, prepared, description )',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Resultset.


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

$$ LANGUAGE plpgsql;
CREATE TRIGGER t1_br_insert BEFORE INSERT OR UPDATE
    ON "S 1"."T 1" FOR EACH ROW EXECUTE PROCEDURE "S 1".F_BRTRIG();

INSERT INTO ft2 (c1,c2,c3) VALUES (1208, 818, 'fff') RETURNING *;
INSERT INTO ft2 (c1,c2,c3,c6) VALUES (1218, 818, 'ggg', '(--;') RETURNING *;
UPDATE ft2 SET c2 = c2 + 600 WHERE c1 % 10 = 8 AND c1 < 1200 RETURNING *;

-- Test errors thrown on remote side during update
ALTER TABLE "S 1"."T 1" ADD CONSTRAINT c2positive CHECK (c2 >= 0);

INSERT INTO ft1(c1, c2) VALUES(11, 12);  -- duplicate key
INSERT INTO ft1(c1, c2) VALUES(11, 12) ON CONFLICT DO NOTHING; -- works
INSERT INTO ft1(c1, c2) VALUES(11, 12) ON CONFLICT (c1, c2) DO NOTHING; -- unsupported
INSERT INTO ft1(c1, c2) VALUES(11, 12) ON CONFLICT (c1, c2) DO UPDATE SET c3 = 'ffg'; -- unsupported
INSERT INTO ft1(c1, c2) VALUES(1111, -2);  -- c2positive
UPDATE ft1 SET c2 = -c2 WHERE c1 = 1;  -- c2positive

-- Test savepoint/rollback behavior
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
select c2, count(*) from "S 1"."T 1" where c2 < 500 group by 1 order by 1;
begin;
update ft2 set c2 = 42 where c2 = 0;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
savepoint s1;
update ft2 set c2 = 44 where c2 = 4;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
release savepoint s1;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
savepoint s2;
update ft2 set c2 = 46 where c2 = 6;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
rollback to savepoint s2;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
release savepoint s2;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
savepoint s3;
update ft2 set c2 = -2 where c2 = 42 and c1 = 10; -- fail on remote side
rollback to savepoint s3;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
release savepoint s3;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
-- none of the above is committed yet remotely
select c2, count(*) from "S 1"."T 1" where c2 < 500 group by 1 order by 1;
commit;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
select c2, count(*) from "S 1"."T 1" where c2 < 500 group by 1 order by 1;

VACUUM ANALYZE "S 1"."T 1";

-- Above DMLs add data with c6 as NULL in ft1, so test ORDER BY NULLS LAST and NULLs
-- FIRST behavior here.
-- ORDER BY DESC NULLS LAST options
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft1 ORDER BY c6 DESC NULLS LAST, c1 OFFSET 795 LIMIT 10;
SELECT * FROM ft1 ORDER BY c6 DESC NULLS LAST, c1 OFFSET 795  LIMIT 10;
-- ORDER BY DESC NULLS FIRST options
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft1 ORDER BY c6 DESC NULLS FIRST, c1 OFFSET 15 LIMIT 10;
SELECT * FROM ft1 ORDER BY c6 DESC NULLS FIRST, c1 OFFSET 15 LIMIT 10;
-- ORDER BY ASC NULLS FIRST options
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft1 ORDER BY c6 ASC NULLS FIRST, c1 OFFSET 15 LIMIT 10;
SELECT * FROM ft1 ORDER BY c6 ASC NULLS FIRST, c1 OFFSET 15 LIMIT 10;

-- Test ReScan code path that recreates the cursor even when no parameters
-- change (bug #17889)
CREATE TABLE loct1 (c1 int);
CREATE TABLE loct2 (c1 int, c2 text);
INSERT INTO loct1 VALUES (1001);
INSERT INTO loct1 VALUES (1002);
INSERT INTO loct2 SELECT id, to_char(id, 'FM0000') FROM generate_series(1, 1000) id;
INSERT INTO loct2 VALUES (1001, 'foo');
INSERT INTO loct2 VALUES (1002, 'bar');
CREATE FOREIGN TABLE remt2 (c1 int, c2 text) SERVER loopback OPTIONS (table_name 'loct2');
ANALYZE loct1;
ANALYZE remt2;
SET enable_mergejoin TO false;
SET enable_hashjoin TO false;
SET enable_material TO false;
EXPLAIN (VERBOSE, COSTS OFF)
UPDATE remt2 SET c2 = remt2.c2 || remt2.c2 FROM loct1 WHERE loct1.c1 = remt2.c1 RETURNING remt2.*;
UPDATE remt2 SET c2 = remt2.c2 || remt2.c2 FROM loct1 WHERE loct1.c1 = remt2.c1 RETURNING remt2.*;
RESET enable_mergejoin;
RESET enable_hashjoin;
RESET enable_material;
DROP FOREIGN TABLE remt2;
DROP TABLE loct1;
DROP TABLE loct2;

-- ===================================================================
-- test check constraints
-- ===================================================================

-- Consistent check constraints provide consistent results
ALTER FOREIGN TABLE ft1 ADD CONSTRAINT ft1_c2positive CHECK (c2 >= 0);
EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 < 0;
SELECT count(*) FROM ft1 WHERE c2 < 0;
SET constraint_exclusion = 'on';
EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 < 0;
SELECT count(*) FROM ft1 WHERE c2 < 0;
RESET constraint_exclusion;
-- check constraint is enforced on the remote side, not locally
INSERT INTO ft1(c1, c2) VALUES(1111, -2);  -- c2positive
UPDATE ft1 SET c2 = -c2 WHERE c1 = 1;  -- c2positive
ALTER FOREIGN TABLE ft1 DROP CONSTRAINT ft1_c2positive;

-- But inconsistent check constraints provide inconsistent results
ALTER FOREIGN TABLE ft1 ADD CONSTRAINT ft1_c2negative CHECK (c2 < 0);
EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 >= 0;
SELECT count(*) FROM ft1 WHERE c2 >= 0;
SET constraint_exclusion = 'on';
EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 >= 0;
SELECT count(*) FROM ft1 WHERE c2 >= 0;
RESET constraint_exclusion;
-- local check constraint is not actually enforced
INSERT INTO ft1(c1, c2) VALUES(1111, 2);
UPDATE ft1 SET c2 = c2 + 1 WHERE c1 = 1;
ALTER FOREIGN TABLE ft1 DROP CONSTRAINT ft1_c2negative;

-- ===================================================================
-- test WITH CHECK OPTION constraints
-- ===================================================================

CREATE FUNCTION row_before_insupd_trigfunc() RETURNS trigger AS $$BEGIN NEW.a := NEW.a + 10; RETURN NEW; END$$ LANGUAGE plpgsql;

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


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

Explanation: DML from PostgreSQL core regression test for Inherit.


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

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


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

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

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


Question: Write the DDL statement from PostgreSQL regression test 'constraints' (example 363).

Explanation: DDL from PostgreSQL core regression test for Constraints.


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

create table pc_list_part_def partition of pc_list_parted default;

Explanation: DDL from PostgreSQL core regression test for Plancache.


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

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

SELECT count(*) FROM (SELECT power(float8 'inf', float8 '0')) AS _sub;


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

SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')');

SELECT count(*) FROM (SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE (a = 1 OR a = 51) AND (b = ''1'' OR b = ''2'')')) AS _sub;


Question: pgTAP test for Todotap (assertion 12).

-- Test num only.
SELECT * FROM check_test(
    skip(1),
    true,
    'num only',
    '',
    'SKIP'
);

Explanation: SQL assertion from pgTAP test suite for Todotap.


Question: pgTAP test for Resultset (assertion 228).

-- Compare actual SELECT statements.
SELECT * FROM check_test(
    set_eq(
        'SELECT id, name FROM names WHERE name like ''An%''',
        'SELECT id, name FROM annames'
    ),
    true,
    'set_eq(select, select)',
    '',
    ''
);


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

INSERT INTO shoelace_arrive VALUES ('sl6', 20);

Explanation: DML from PostgreSQL core regression test for Rules.


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

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


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

SELECT * FROM test_int2 WHERE i<(-32769)::int4 ORDER BY i;

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


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

SELECT '2011-03-26 23:59:59 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow';

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

SELECT count(*) FROM (SELECT '2011-03-26 23:59:59 UTC'::timestamptz AT TIME ZONE 'Europe/Moscow') AS _sub;


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

select explain_filter('explain (analyze,buffers off,costs off) select sum(n) over(partition by m) from (SELECT n < 3 as m, n from generate_series(1,2500) a(n))');

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

SELECT count(*) FROM (select explain_filter('explain (analyze,buffers off,costs off) select sum(n) over(partition by m) from (SELECT n < 3 as m, n from generate_series(1,2500) a(n))')) AS _sub;


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

CREATE INDEX strtest_n_idx ON strtest (n);

Explanation: DDL from PostgreSQL core regression test for Memoize.


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

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

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


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

SELECT COUNT(*) FROM prt1_l t1 LEFT JOIN LATERAL
			  (SELECT t1.b AS t1b, t2.* FROM prt2_l t2) s
			  ON t1.a = s.b AND t1.b = s.a AND t1.c = s.c
			  WHERE s.t1b = s.a;

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

SELECT count(*) FROM (SELECT COUNT(*) FROM prt1_l t1 LEFT JOIN LATERAL
			  (SELECT t1.b AS t1b, t2.* FROM prt2_l t2) s
			  ON t1.a = s.b AND t1.b = s.a AND t1.c = s.c
			  WHERE s.t1b = s.a) AS _sub;


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

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


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

SELECT x,
       atand(x),
       atand(x) IN (-90,-45,0,45,90) AS atand_exact
FROM (VALUES ('-Infinity'::float8), (-1), (0), (1),
      ('Infinity'::float8)) AS t(x);

SELECT count(*) FROM (SELECT x,
       atand(x),
       atand(x) IN (-90,-45,0,45,90) AS atand_exact
FROM (VALUES ('-Infinity'::float8), (-1), (0), (1),
      ('Infinity'::float8)) AS t(x)) AS _sub;


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

INSERT INTO local_tbl VALUES (1505, 505, 'foo'), (2505, 505, 'bar');

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


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

INSERT INTO caster (chr)           VALUES ('f'::text);

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


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

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


Question: Show a SQL definition from the postgrest project (replica, item 4).

create table replica.items as select x as id from generate_series(1, 10) x;

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


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

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

SELECT count(*) FROM (SELECT to_char('100'::numeric, 'f\\"oo999')) AS _sub;


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

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


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

CREATE STATISTICS tststats.s3 ON a, b FROM tststats.s;

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


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

SELECT h.seqno AS f20000
   FROM hash_f8_heap h
   WHERE h.random = '488912369'::float8;

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

SELECT count(*) FROM (SELECT h.seqno AS f20000
   FROM hash_f8_heap h
   WHERE h.random = '488912369'::float8) AS _sub;


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

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

SELECT count(*) FROM (select max(100) from tenk1) AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'publication' (example 124).

CREATE PUBLICATION testpub_rf_no FOR TABLE testpub_rf_tbl1;

Explanation: DDL from PostgreSQL core regression test for Publication.


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

INSERT INTO s1 (SELECT x, public.fipshash(x::text) FROM generate_series(-10,10) x);

Explanation: DML from PostgreSQL core regression test for Rowsecurity.


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

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

SELECT count(*) FROM (SELECT xmlconcat(1, 2)) AS _sub;


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

SELECT ('\x' || repeat('0', 34))::bytea;

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

SELECT count(*) FROM (SELECT ('\x' || repeat('0', 34))::bytea) AS _sub;


Question: pgTAP test for Proctap (assertion 38).

SELECT * FROM check_test(
    isnt_procedure( 'procschema', 'argproc'::name ),
    false,
    'isnt_procedure(schema, proc)',
    'Function procschema.argproc() should not be a procedure',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Proctap.


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

select array_agg('{}'::int[]) from generate_series(1,2);

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

SELECT count(*) FROM (select array_agg('{}'::int[]) from generate_series(1,2)) AS _sub;


Question: Create an exclusion constraint to prevent overlapping date ranges.

CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE TABLE room_bookings (
    id serial PRIMARY KEY,
    room_id int NOT NULL,
    during tstzrange NOT NULL,
    EXCLUDE USING gist (room_id WITH =, during WITH &&)
);

Explanation: Exclusion constraint with btree_gist prevents any two rows with the same room_id from having overlapping tstzrange values (&&).


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

Explanation: DML from PostgreSQL core regression test for Arrays.


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

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


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

SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'' AND 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 AND b = ''1'' AND c = 1')) AS _sub;


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

CREATE OR REPLACE FUNCTION _timescaledb_functions.first_sfunc(internal, anyelement, "any")
RETURNS internal
AS '@MODULE_PATHNAME@', 'ts_first_sfunc'
LANGUAGE C IMMUTABLE PARALLEL SAFE;

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


Question: PL/pgSQL test: Plperl Array (example 37).

select perl_setof_array('{{1}, {2}, {3}}');

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


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

select 1 from
  int4_tbl as i4
  inner join
    ((select 42 as n from int4_tbl x1 left join int8_tbl x2 on f1 = q1) as ss1
     right join (select 1 as z) as ss2 on true)
  on false,
  lateral (select i4.f1, ss1.n from int8_tbl as i8 limit 1) as ss3;

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

SELECT count(*) FROM (select 1 from
  int4_tbl as i4
  inner join
    ((select 42 as n from int4_tbl x1 left join int8_tbl x2 on f1 = q1) as ss1
     right join (select 1 as z) as ss2 on true)
  on false,
  lateral (select i4.f1, ss1.n from int8_tbl as i8 limit 1) as ss3) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'plpgsql' (example 757).

UPDATE alter_table_under_transition_tables
  SET name = (name::text || name::text)::integer;

Explanation: DML from PostgreSQL core regression test for Plpgsql.


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

SELECT POSITION('\x33'::bytea IN '\x1122'::bytea) = 0 AS "0";

SELECT count(*) FROM (SELECT POSITION('\x33'::bytea IN '\x1122'::bytea) = 0 AS "0") AS _sub;


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

select description, inbytes, (test_conv(inbytes, 'iso8859-5', 'utf8')).* from iso8859_5_inputs;

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

SELECT count(*) FROM (select description, inbytes, (test_conv(inbytes, 'iso8859-5', 'utf8')).* from iso8859_5_inputs) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'generated_stored' (example 116).

INSERT INTO gtest_varlena (a) VALUES(NULL);

Explanation: DML from PostgreSQL core regression test for Generated Stored.


Question: PostgreSQL Extend: show example 5.

(LEFTARG = text, RIGHTARG = text, FUNCTION = pair); -- "SET search_path" is easy to get right, but qualified names perform better. CREATE FUNCTION lower(pair) RETURNS pair LANGUAGE SQL AS 'SELECT ROW(lower($1.k), lower($1.v))::@extschema@.pair;' SET search_path = pg_temp; CREATE FUNCTION pair_concat(pair, pair) RETURNS pair LANGUAGE SQL AS 'SELECT ROW($1.k OPERATOR(pg_catalog.||) $2.k, $1.v OPERATOR(pg_catalog.||) $2.v)::@extschema@.pair;'; ]]>;

Explanation: Example from PostgreSQL documentation on Extend.


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

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

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


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

-- base-case return of a composite type
create function retc(int) returns two_int8s language plpgsql as
$$ begin return row($1,1)::two_int8s; end $$;
select retc(42);

-- ok to return a matching record type
create or replace function retc(int) returns two_int8s language plpgsql as
$$ begin return row($1::int8, 1::int8); end $$;

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


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

SELECT 'a b:89  ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca:A' as "true";

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

SELECT count(*) FROM (SELECT 'a b:89  ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca:A' as "true") AS _sub;


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

SELECT INTERVAL 'infinity' AS "eternity";

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

SELECT count(*) FROM (SELECT INTERVAL 'infinity' AS "eternity") AS _sub;


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

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

SELECT count(*) FROM (select textrange(null, null)::textmultirange) AS _sub;


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

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


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

--
-- Verify prohibition of row triggers with transition triggers on
-- partitions
--
create table parent (a text, b int) partition by list (a);

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


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

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

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


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

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


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

Explanation: DML from PostgreSQL core regression test for Rowsecurity.


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

select p from gist_tbl where p <@ box(point(0,0), point(0.5, 0.5))
order by p <-> point(0.201, 0.201);

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

SELECT count(*) FROM (select p from gist_tbl where p <@ box(point(0,0), point(0.5, 0.5))
order by p <-> point(0.201, 0.201)) AS _sub;


Question: Show a SQL definition from the timescaledb project (create_table_with, item 45).

CREATE TABLE IF NOT EXISTS t9(time timestamp NOT NULL, device text, value float) WITH (tsdb.columnstore=false,tsdb.hypertable,tsdb.partition_column='time',tsdb.chunk_interval='23 days');

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


Question: PostgreSQL regression test 'collate.icu.utf8': Write the SELECT query (example 102).

SELECT array_agg(b ORDER BY b) FROM collate_test2;

Explanation: Regression test for Collate.Icu.Utf8 in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT array_agg(b ORDER BY b) FROM collate_test2) AS _sub;


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

SELECT reverse(truncated) FROM regress_encoding;

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

SELECT count(*) FROM (SELECT reverse(truncated) FROM regress_encoding) AS _sub;


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

SELECT regexp_replace('Thomas'::citext, '.[mN]a.',         'M') = 'ThM' AS t;

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


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

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


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

update voo set f1 = f1 + 1 where f2 = 'zoo2';

Explanation: DML from PostgreSQL core regression test for Returning.


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

INSERT INTO itest5 OVERRIDING SYSTEM VALUE VALUES (DEFAULT, 'dd'), (-4, 'ee');

Explanation: DML from PostgreSQL core regression test for Identity.


Question: pgTAP test for Aretap (assertion 114).

SELECT * FROM check_test(
    opclasses_are( 'public', '{}'::name[], 'whatever' ),
    false,
    'opclasses_are(schema, opclasses, desc) + extra',
    'whatever',
    '    Extra operator classes:
        goofy_ops'
);

Explanation: SQL assertion from pgTAP test suite for Aretap.


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

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


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

SELECT count(*) FROM (select textrange('a', 'c')::textmultirange) AS _sub;


Question: pgTAP test for Resultset (assertion 135).

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

Explanation: SQL assertion from pgTAP test suite for Resultset.


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

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

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


Question: pgTAP test for Functap (assertion 96).

SELECT * FROM check_test(
    function_returns( 'oww', ARRAY['int', 'text'], 'boolean' ),
    true,
    'function_returns(func, args, bool)',
    'Function oww(int, text) should return boolean',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

SELECT pg_get_object_address('language', '{one,two}', '{}');

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

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


Question: PostgreSQL regression test 'int2': Write the SELECT query (example 73).

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

SELECT count(*) FROM (SELECT int2 '0b_10_0101') AS _sub;


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

CREATE FUNCTION pglogical.create_subscription(subscription_name name, provider_dsn text,
    replication_sets text[] = '{default,default_insert_only}', synchronize_structure boolean = true,
    synchronize_data boolean = true, forward_origins text[] = '{all}')
RETURNS oid STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_create_subscription';

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


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

SELECT count(*) FROM
  (SELECT DISTINCT two, four, two FROM tenk1) ss;

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

SELECT count(*) FROM (SELECT count(*) FROM
  (SELECT DISTINCT two, four, two FROM tenk1) ss) AS _sub;


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

SELECT power(float8 'NaN', float8 'NaN');

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

SELECT count(*) FROM (SELECT power(float8 'NaN', float8 'NaN')) AS _sub;


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

SELECT count(*) FROM testjsonb WHERE j @@ '$.array[*] == "foo"';

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

SELECT count(*) FROM (SELECT count(*) FROM testjsonb WHERE j @@ '$.array[*] == "foo"') AS _sub;


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

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

SELECT count(*) FROM (SELECT 'mauve'::rainbow) AS _sub;


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

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


Question: Show a SQL definition from the timescaledb project (create_table_with, item 13).

CREATE TABLE t2(time timestamptz, device text, value float) WITH (tsdb.create_default_indexes='time');

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


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

ALTER AGGREGATE mypercentile(float8 ORDER BY integer) SET SCHEMA myschema;

Explanation: PostgreSQL ALTER AGGREGATE command.


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

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

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


Question: pgTAP test for Policy (assertion 49).

SELECT * FROM check_test(
    policy_cmd_is( 'passwd', 'daemon_insert', 'insert', 'whatever' ),
    true,
    'policy_cmd_is(table, policy, command, desc) for INSERT',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Policy.


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

select * from tt5,tt6 where tt5.f1 = tt6.f1 and tt5.f1 = tt5.f2 - tt6.f2;

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

SELECT count(*) FROM (select * from tt5,tt6 where tt5.f1 = tt6.f1 and tt5.f1 = tt5.f2 - tt6.f2) AS _sub;


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

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


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

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


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

--
-- Trigger function to force references from T_dta2 follow changes
-- in T_pkey2 or be deleted too. This must be done AFTER the changes
-- in T_pkey2 are done so the trigger for primkey check on T_dta2
-- fired on our updates will see the new key values in T_pkey2.
--
create function trig_pkey2_after() returns trigger as E'
    #
    # Prepare plans on first call
    #
    if {![info exists GD]} {
	#
	# Plan to update references from T_dta2
	#
        set GD(plan_dta2_upd) [spi_prepare			\\
	    "update T_dta2 set ref1 = \\$3, ref2 = \\$4		\\
	        where ref1 = \\$1 and ref2 = \\$2"		\\
	    {int4 bpchar int4 bpchar}]
	#
	# Plan to delete references from T_dta2
	#
        set GD(plan_dta2_del) [spi_prepare			\\
	    "delete from T_dta2 				\\
	        where ref1 = \\$1 and ref2 = \\$2"		\\
	    {int4 bpchar}]
    }

    #
    # Initialize flags
    #
    set old_ref_follow 0
    set old_ref_delete 0

    switch $TG_op {
	UPDATE {
	    #
	    # On update we must let old references follow
	    #
	    set NEW(key2) [string toupper $NEW(key2)]

	    if {[string compare $NEW(key1) $OLD(key1)] != 0} {
	        set old_ref_follow 1
	    }
	    if {[string compare $NEW(key2) $OLD(key2)] != 0} {
	        set old_ref_follow 1
	    }
	}
	DELETE {
	    #
	    # On delete we must delete references too
	    #
	    set old_ref_delete 1
	}
    }

    if {$old_ref_follow} {
	#
	# Let old references follow and fire NOTICE message if
	# there where some
	#
        set n [spi_execp $GD(plan_dta2_upd) \\
	    [list $OLD(key1) $OLD(key2) $NEW(key1) $NEW(key2)]]
	if {$n > 0} {
	    elog NOTICE \\
		"updated $n entries in T_dta2 for new key in T_pkey2"
        }
    }

    if {$old_ref_delete} {
	#
	# delete references and fire NOTICE message if
	# there where some
	#
        set n [spi_execp $GD(plan_dta2_del) \\
	    [list $OLD(key1) $OLD(key2)]]
	if {$n > 0} {
	    elog NOTICE \\
		"deleted $n entries from T_dta2"
        }
    }

    return OK
' language pltcl;

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


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

SELECT lo_truncate64(fd, 5000000000) FROM lotest_stash_values;

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

SELECT count(*) FROM (SELECT lo_truncate64(fd, 5000000000) FROM lotest_stash_values) AS _sub;


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

INSERT INTO temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) VALUES
  ('[3,4)', datemultirange(daterange('2000-01-01', '2000-02-15')), '[3,4)');

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


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

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

SELECT count(*) FROM (select fullname::text from fullname) AS _sub;


Question: PostgreSQL Ddl: show example 50.

ALTER TABLE products ADD CHECK (name <> ''); ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no); ALTER TABLE products ADD FOREIGN KEY (product_group_id) REFERENCES product_groups;

Explanation: Example from PostgreSQL documentation on Ddl.


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

SELECT pg_get_object_address('extension', '{one,two}', '{}');

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

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


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

Explanation: DML from PostgreSQL core regression test for Rules.


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

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

SELECT count(*) FROM (select scale(1.12345)) AS _sub;


Question: pgTAP test for Functap (assertion 242).

-- is_aggregate( NAME, NAME[] )
-- isnt_aggregate( NAME, NAME[] )
SELECT * FROM check_test(
    is_aggregate( 'tap_accum', ARRAY[etype()] ),
    true,
    'is_aggregate(agg, arg)',
    'Function tap_accum(' || etype() || ') should be an aggregate function',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


Question: PostgreSQL Queries: show example 15.

SELECT * FROM foo, LATERAL (SELECT * FROM bar WHERE bar.id = foo.bar_id) ss;

Explanation: Example from PostgreSQL documentation on Queries.


Question: Show a SQL definition from the citus project (multi_behavioral_analytics_create_table, item 44).

CREATE INDEX is_index4 ON events_table(event_type);

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


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

ALTER EXTENSION pgtap ADD FUNCTION language_is_trusted( NAME );

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


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

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

SELECT count(*) FROM (SELECT xmltext('foo `$_-+?=*^%!|/\()[]{}')) AS _sub;


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

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

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


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

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

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


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

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

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


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

SELECT t1.a,t2.b,t2.c FROM fprt1 t1 LEFT JOIN (SELECT * FROM fprt2 WHERE a < 10) t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a < 10 ORDER BY 1,2,3;

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


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

INSERT INTO TIME_TBL VALUES ('11:59 EDT');

Explanation: DML from PostgreSQL core regression test for Time.


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

-- window functions are not to be included in GROUP BY, either
EXPLAIN (COSTS OFF) SELECT a, COUNT(a) OVER (PARTITION BY a) FROM t1 GROUP BY ALL;

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


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

Explanation: DML from PostgreSQL core regression test for Subselect.


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

SELECT * FROM nummultirange_test WHERE nmr <= '{}';

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

SELECT count(*) FROM (SELECT * FROM nummultirange_test WHERE nmr <= '{}') AS _sub;


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

INSERT INTO shoe_data VALUES ('sh4', 3, 'brown', 40.0, 50.0, 'inch');


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

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


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

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


Question: pgTAP test for Functap (assertion 378).

SELECT * FROM check_test(
    volatility_is( 'yay'::name, 'volatile' ),
    true,
    'function_volatility(func, volatile)',
    'Function yay() should be VOLATILE',
    ''
);


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

select * from pg_get_object_address('function of access method', '{btree,integer_ops,99}', '{int4,int4}');

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

SELECT count(*) FROM (select * from pg_get_object_address('function of access method', '{btree,integer_ops,99}', '{int4,int4}')) AS _sub;


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

CREATE TABLE fk_partitioned_fk_full (x int, y int) PARTITION BY RANGE (x);

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


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

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

SELECT count(*) FROM (select jsonb_path_query('{"a": {"b": 1}}', 'lax $.**{0}.b ? (@ > 0)')) AS _sub;


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

SELECT time '11:27:42' - interval '-infinity';

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

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


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

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


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

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


Question: Show a query using PostgreSQL contrib extension 'jsonb_plperl' (example 39).

SELECT roundtrip('{"1": -1.1}', 'HASH');

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


Question: Write the DDL statement from PostgreSQL regression test 'subselect' (example 102).

create temp table float_table (float_col float8);

Explanation: DDL from PostgreSQL core regression test for Subselect.


Question: pgTAP test for Resultset (assertion 81).

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

Explanation: SQL assertion from pgTAP test suite for Resultset.


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

select jsonb_path_query('{}', '$.bigint()', silent => true);

SELECT count(*) FROM (select jsonb_path_query('{}', '$.bigint()', silent => true)) AS _sub;


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

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

SELECT count(*) FROM (SELECT ts_lexize('ispell', 'unbookings')) AS _sub;


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

create table lp_ad partition of lp for values in ('a', 'd');

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


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

select a < b and b < 3 from (values (1, 2)) t(a, b) group by rollup(a < b and b < 3) having a < b and b < 3;

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

SELECT count(*) FROM (select a < b and b < 3 from (values (1, 2)) t(a, b) group by rollup(a < b and b < 3) having a < b and b < 3) AS _sub;


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

Explanation: DDL from PostgreSQL core regression test for Domain.


Question: pgTAP test for Matching (assertion 8).

SELECT doesnt_imatch( 'foo'::text, '^o', 'doesnt_imatch() should work with a regex' );

Explanation: SQL assertion from pgTAP test suite for Matching.


Question: pgTAP test for Throwtap (assertion 23).

/****************************************************************************/
-- test throws_ilike().
SELECT * FROM check_test(
    throws_ilike( 'SELECT * FROM todo_end()', '%END() called without todo%', 'whatever' ),
    true,
    'throws_ilike(sql, pattern, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Throwtap.


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

SELECT t1.a, t1.c, t2.a, t2.c FROM plt1_adv t1 INNER JOIN plt2_adv t2 ON (t1.a = t2.a AND t1.c = t2.c) WHERE t1.c IN ('0003', '0004', '0005') AND t1.b < 10 ORDER BY t1.a;

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

SELECT count(*) FROM (SELECT t1.a, t1.c, t2.a, t2.c FROM plt1_adv t1 INNER JOIN plt2_adv t2 ON (t1.a = t2.a AND t1.c = t2.c) WHERE t1.c IN ('0003', '0004', '0005') AND t1.b < 10 ORDER BY t1.a) AS _sub;


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

--
-- Test spi_prepare/spi_query_prepared/spi_freeplan
--
CREATE OR REPLACE FUNCTION perl_spi_prepared_set(INTEGER, INTEGER) RETURNS SETOF INTEGER AS $$
  my $x = spi_prepare('SELECT $1 AS a union select $2 as a', 'INT4', 'INT4');
  my $q = spi_query_prepared( $x, 1+$_[0], 2+$_[1]);
  while (defined (my $y = spi_fetchrow($q))) {
      return_next $y->{a};
  }
  spi_freeplan($x);
  return;
$$ LANGUAGE plperl;

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


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

select '$ ? (@ like_regex "pattern" flag "")'::jsonpath;

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

SELECT count(*) FROM (select '$ ? (@ like_regex "pattern" flag "")'::jsonpath) AS _sub;


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

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

SELECT count(*) FROM (SELECT avg(four) AS avg_1 FROM onek) AS _sub;


Question: PostgreSQL Textsearch: show example 33.

SELECT * FROM ts_debug('public.pg', ' PostgreSQL, the highly scalable, SQL compliant, open source object-relational database management system, is now undergoing beta testing of the next version of our software. ');

Explanation: Example from PostgreSQL documentation on Textsearch.


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

insert into parted_conflict_1 values (40, 'cuarenta')
  on conflict (a) do update set b = excluded.b;

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


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

SELECT ks_test_uniform_random_numeric_in_range() OR
       ks_test_uniform_random_numeric_in_range() OR
       ks_test_uniform_random_numeric_in_range() AS uniform_numeric;

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

SELECT count(*) FROM (SELECT ks_test_uniform_random_numeric_in_range() OR
       ks_test_uniform_random_numeric_in_range() OR
       ks_test_uniform_random_numeric_in_range() AS uniform_numeric) AS _sub;


Question: pgTAP test for Functap (assertion 310).

SELECT * FROM check_test(
    is_window( 'yay', '{}'::name[] ),
    false,
    'is_window(func, noarg, desc)',
    'Function yay() should be a window function',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

select id, f_float8, first_value(id) over w, last_value(id) over w
from numerics
window w as (order by f_float8 range between
             1 preceding and 1.1::float8 following);

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

SELECT count(*) FROM (select id, f_float8, first_value(id) over w, last_value(id) over w
from numerics
window w as (order by f_float8 range between
             1 preceding and 1.1::float8 following)) AS _sub;


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

ALTER EXTENSION pgtap ADD FUNCTION bag_ne( TEXT, anyarray, TEXT );

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


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

INSERT INTO cj_source1 VALUES (2, 20, 300);

Explanation: DML from PostgreSQL core regression test for Merge.


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

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

SELECT count(*) FROM (SELECT power('-inf'::numeric, '0')) AS _sub;


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

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


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

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


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

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

SELECT count(*) FROM (select row(1, '(1,2)')::testtype6 < row(1, '(1,3)')::testtype6) AS _sub;


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

SELECT count(*) FROM (select '[{"b": "c"}, {"b": "cc"}]'::jsonb ->> 'z') AS _sub;


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

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


Question: Show a SQL definition from the timescaledb project (vacuum_parallel, item 13).

CREATE INDEX ON _hyper_1_3_chunk(temp2);

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


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

SELECT 'copy' FROM pg_copy_logical_replication_slot('orig_slot1', 'copied_slot1_no_change');

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


Question: pgTAP test for Inheritance (assertion 98).

SELECT * FROM check_test(
    is_descendent_of( 'hide', 'h_child2', 'hide', 'nope', 2 ),
    false,
    'is_descendent_of(csch, ctab, psch, nope, 2)',
    'Table hide.h_child2 should be descendent 2 from hide.nope',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Inheritance.


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

Explanation: DML from PostgreSQL core regression test for Insert.


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

SELECT XMLPARSE(DOCUMENT '<!DOCTYPE foo [<!ENTITY c SYSTEM "/etc/no.such.file">]><foo>&c;</foo>');

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

SELECT count(*) FROM (SELECT XMLPARSE(DOCUMENT '<!DOCTYPE foo [<!ENTITY c SYSTEM "/etc/no.such.file">]><foo>&c;</foo>')) AS _sub;


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

SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text FORMAT JSON PATH '$' KEEP QUOTES));

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

SELECT count(*) FROM (SELECT * FROM JSON_TABLE(jsonb '"world"', '$' COLUMNS (item text FORMAT JSON PATH '$' KEEP QUOTES))) AS _sub;


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

SELECT 'a'::citext ~<=~ 'A'::citext AS t;

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


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

create temp table rngfunc(f1 int8, f2 int8);

Explanation: DDL from PostgreSQL core regression test for Rangefuncs.


Question: Write the DML statement from PostgreSQL regression test 'publication' (example 210).

Explanation: DML from PostgreSQL core regression test for Publication.


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

Explanation: DML from PostgreSQL core regression test for Rules.


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

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

SELECT count(*) FROM (select '(1).type()'::jsonpath) AS _sub;


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

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


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

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

SELECT count(*) FROM (SELECT '{[1,9)}' @> '{[1,5), [6,10)}'::nummultirange) AS _sub;


Question: Show a SQL definition from the citus project (multi_behavioral_analytics_create_table, item 29).

-- same as agg_results_second
CREATE TABLE agg_results_fourth (user_id int, value_1_agg int, value_2_agg int, value_3_agg float, value_4_agg bigint, agg_time timestamp);

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


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

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

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


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

select split_part('joeuser@mydatabase','@@',2) AS "empty string";

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

SELECT count(*) FROM (select split_part('joeuser@mydatabase','@@',2) AS "empty string") AS _sub;


Question: pgTAP test for Resultset (assertion 379).

-- Fail with a missing record.
SELECT * FROM check_test(
    bag_eq(
        'SELECT name FROM names WHERE name like ''An%''',
        ARRAY['Andrew', 'Anna', 'Anthony', 'Alan', 'Antonio', 'Angelina', 'Andrea', 'Angel' ]
    ),
    false,
    'bag_eq(sql, array) missing record',
    '',
    '    Missing records:
        (Alan)'
);

Explanation: SQL assertion from pgTAP test suite for Resultset.


Question: Show a SQL definition from the timescaledb project (policy_internal, item 5).

CREATE OR REPLACE PROCEDURE _timescaledb_functions.policy_recompression(job_id INTEGER, config JSONB)
AS '@MODULE_PATHNAME@', 'ts_policy_recompression_proc'
LANGUAGE C;

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


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

/* New stuff in 1.1 begins here */

CREATE FUNCTION pgstatginindex(IN relname regclass,
    OUT version INT4,
    OUT pending_pages INT4,
    OUT pending_tuples BIGINT)
AS 'MODULE_PATHNAME', 'pgstatginindex'
LANGUAGE C STRICT PARALLEL SAFE;


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

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

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

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


Question: pgTAP test for Ownership (assertion 67).

SELECT * FROM check_test(
    sequence_owner_is('__not__public', 'someseq', current_user, 'mumble'),
	false,
    'sequence_owner_is(non-sch, sequence, user)',
    'mumble',
    '    Sequence __not__public.someseq does not exist'
);

Explanation: SQL assertion from pgTAP test suite for Ownership.


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

create function dom_check(int) returns di as $$
declare d di;
begin
  d := $1::di;
  return d;
end
$$ language plpgsql immutable;

Explanation: DDL from PostgreSQL core regression test for Domain.


Question: Write the DML statement from PostgreSQL regression test 'create_table' (example 9).

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


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

CREATE OR REPLACE FUNCTION perl_int(int) RETURNS INTEGER AS $$
return $_[0] + 1;
$$ LANGUAGE plperl;


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

-- T312 character overlay function
SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";

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


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

CREATE INDEX guid1_hash  ON guid1 USING HASH  (guid_field);

Explanation: DDL from PostgreSQL core regression test for Uuid.


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

-- try changing the return types and call functions again

ALTER TABLE table_record DROP COLUMN first;

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


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

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


Question: pgTAP test for Functap (assertion 345).

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

Explanation: SQL assertion from pgTAP test suite for Functap.


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

SELECT count(*) FROM uuidtmp WHERE a <  '55e65ca2-4136-4a4b-ba78-cd3fe4678203';

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


Question: pgTAP test for Runnotests (assertion 3).

CREATE OR REPLACE FUNCTION whatever.testthis() RETURNS SETOF TEXT AS $$
BEGIN
    -- Do nothing.
END;
$$ LANGUAGE plpgsql;

Explanation: SQL assertion from pgTAP test suite for Runnotests.


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

create index idxpart1_2c_idx on idxpart1 ((b + a)) where b > 1;

Explanation: DDL from PostgreSQL core regression test for Indexing.


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


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

CREATE OPERATOR FAMILY alt_nsp6.alt_opf6 USING btree;

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


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

CREATE TABLE invalid(time TEXT, value FLOAT) WITH (timescaledb.hypertable);


Question: pgTAP test for Hastap (assertion 240).

SELECT * FROM check_test(
  has_opclass( 'pg_catalog', 'int4_ops'::name ),
  true,
  'has_opclass( schema, name )',
  'Operator class pg_catalog.int4_ops should exist',
  ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

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

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


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

drop function anyarray_anymultirange_func(anyarray, anymultirange);

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


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

select * from pg_input_error_info('junk', 'positiveint');

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

SELECT count(*) FROM (select * from pg_input_error_info('junk', 'positiveint')) AS _sub;


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

create table Room (
    roomno	char(8),
    comment	text
);

Explanation: DDL from PostgreSQL core regression test for Plpgsql.


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

create type more_int4s as (f0 text, f1 int4, f2 int4);

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


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

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

SELECT count(*) FROM (SELECT to_char(q2, 'FM0999999999999999')     FROM INT8_TBL) AS _sub;


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

SELECT width_bucket(2.0, 3.0, '-inf', 888);

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

SELECT count(*) FROM (SELECT width_bucket(2.0, 3.0, '-inf', 888)) AS _sub;


Question: pgTAP test for Valueset (assertion 217).

-- Try some failures.
SELECT * FROM check_test(
    set_eq(
        'SELECT id, name FROM annames WHERE name <> ''Anna''',
        'expect'
    ),
    false,
    'set_eq(select, prepared) fail missing',
    '',
    '    Missing records:
        (44,Anna)'
);

Explanation: SQL assertion from pgTAP test suite for Valueset.


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

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


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

/* contrib/pgstattuple/pgstattuple--1.0--1.1.sql */

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

CREATE FUNCTION pgstatginindex(IN relname regclass,
    OUT version INT4,
    OUT pending_pages INT4,
    OUT pending_tuples BIGINT)
AS 'MODULE_PATHNAME', 'pgstatginindex'
LANGUAGE C STRICT;


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

CREATE SCHEMA AUTHORIZATION regress_create_schema_role
  CREATE INDEX ON schema_not_existing.tab (id);

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


Question: Write the DDL statement from PostgreSQL regression test 'constraints' (example 305).

create table notnull_tbl_fail (a serial, constraint foo not null a, constraint bar not null a);

Explanation: DDL from PostgreSQL core regression test for Constraints.


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

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


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

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


Question: PostgreSQL Indices: show example 37.

SELECT am.amname AS index_method, opf.opfname AS opfamily_name, amop.amopopr::regoperator AS opfamily_operator FROM pg_am am, pg_opfamily opf, pg_amop amop WHERE opf.opfmethod = am.oid AND amop.amopfamily = opf.oid ORDER BY index_method, opfamily_name, opfamily_operator;

Explanation: Example from PostgreSQL documentation on Indices.


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

CREATE VIEW vw_getrngfunc AS SELECT * FROM getrngfunc8(1) WITH ORDINALITY AS t1(v,o);

Explanation: DDL from PostgreSQL core regression test for Rangefuncs.


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

INSERT INTO stxdinh2 SELECT mod(a,100), mod(a,100) FROM generate_series(0, 999) a;

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


Question: pgTAP test for Hastap (assertion 162).


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

/* SPI errors in PL/Python functions should preserve the SQLSTATE value
 */
CREATE FUNCTION python_unique_violation() RETURNS void AS $$
plpy.execute("insert into specific values (1)")
plpy.execute("insert into specific values (1)")
$$ LANGUAGE plpython3u;

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


Question: PostgreSQL Rules: show example 3.

CREATE TABLE shoe_data ( shoename text, -- primary key sh_avail integer, -- available number of pairs slcolor text, -- preferred shoelace color slminlen real, -- minimum shoelace length slmaxlen real, -- maximum shoelace length slunit text -- length unit ); CREATE TABLE shoelace_data ( sl_name text, -- primary key sl_avail integer, -- available number of pairs sl_color text, -- shoelace color sl_len real, -- shoelace length sl_unit text -- length unit ); CREATE TABLE unit ( un_name text, -- primary key un_fact real -- factor to transform to cm );

Explanation: Example from PostgreSQL documentation on Rules.


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

CREATE FUNCTION int44in(cstring)
   RETURNS city_budget
   AS :'regresslib'
   LANGUAGE C STRICT IMMUTABLE;

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


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

SELECT * FROM test_date WHERE i<'-infinity'::timestamp ORDER BY i;

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


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

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

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


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

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

SELECT count(*) FROM (select '0:1:'::txid_snapshot) AS _sub;


Question: pgTAP test for Coltap (assertion 76).

-- Make sure it works with a NULL default.
SELECT * FROM check_test(
    col_default_is( 'sometab', 'myNum', 24 ),
    true,
    'col_default_is( tab, col, int )',
    'Column sometab."myNum" should default to ''24''',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Coltap.


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

INSERT INTO caster (text)          VALUES ('the fat cat'::tsvector);

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


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

SELECT pg_current_xact_id() AS committed \gset
COMMIT;

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

SELECT count(*) FROM (SELECT pg_current_xact_id() AS committed \gset
COMMIT) AS _sub;


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

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

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


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

DELETE FROM unique_tbl WHERE i = 5 AND t = 'five';

Explanation: DML from PostgreSQL core regression test for Constraints.


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

CREATE FUNCTION perl2undef() RETURNS bool
LANGUAGE plperlu
TRANSFORM FOR TYPE bool
AS $$
return undef;
$$;

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


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

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


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

insert into rule_and_refint_t2 values (1, 12);

Explanation: DML from PostgreSQL core regression test for Rules.


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

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

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


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

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

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

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


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

select count(*) from test_multirange_gist where mr <@ int4range(10,50);

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

SELECT count(*) FROM (select count(*) from test_multirange_gist where mr <@ int4range(10,50)) AS _sub;


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

SELECT count(*) FROM moneytmp WHERE a >= '22649.64';

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


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

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

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


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

$$;

SELECT transaction_test4();

-- proconfig settings currently disallow transaction statements
CREATE PROCEDURE transaction_test5()
LANGUAGE plpgsql
SET work_mem = 555
AS $$
BEGIN
    COMMIT;

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


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

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


Question: Show a SQL definition from the zombodb project (zombodb--3000.0.3--3000.0.4, item 23).

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

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


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

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


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

CREATE FUNCTION intarray_push_elem(_int4, int4)
RETURNS _int4
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

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


Question: PostgreSQL Rules: show example 62.

CREATE FUNCTION tricky(text, text) RETURNS bool AS $$ BEGIN RAISE NOTICE '% => %', $1, $2; RETURN true; END; $$ LANGUAGE plpgsql COST 0.0000000000000000000001; SELECT * FROM phone_number WHERE tricky(person, phone);

Explanation: Example from PostgreSQL documentation on Rules.


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

-- composite_owner_is ( schema, composite, user )
CREATE OR REPLACE FUNCTION composite_owner_is ( NAME, NAME, NAME )
RETURNS TEXT AS $$
    SELECT composite_owner_is(
        $1, $2, $3,
        'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should be owned by ' || quote_ident($3)
    );
$$ LANGUAGE sql;

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


Question: pgTAP test for Privs (assertion 70).

/****************************************************************************/
-- Test schema_privileges_are().

SELECT * FROM check_test(
    schema_privs_are( current_schema(), current_user, ARRAY['CREATE', 'USAGE'], 'whatever' ),
    true,
    'schema_privs_are(schema, role, privs, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Privs.


Question: Write the DML statement from PostgreSQL regression test 'combocid' (example 4).

INSERT INTO combocidtest SELECT 1 LIMIT 0;

Explanation: DML from PostgreSQL core regression test for Combocid.


Question: pgTAP test for Functap (assertion 18).

SELECT * FROM check_test(
    has_function( 'age', '{timestamptz,timestamptz}'::name[] ),
    true,
    'simple function with 2 args',
    'Function age(timestamptz, timestamptz) should exist',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

Explanation: DDL from PostgreSQL core regression test for Indexing.


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

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

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


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

Explanation: DDL from PostgreSQL core regression test for Join.


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

-- test jsonb null -> python None
CREATE FUNCTION test1null(val jsonb) RETURNS int
LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb
AS $$
assert(val == None)
return 1
$$;

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


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

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

SELECT count(*) FROM (select ln(9.342536355e34)) AS _sub;


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

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


Question: pgTAP test for Cmpok (assertion 4).

Explanation: SQL assertion from pgTAP test suite for Cmpok.


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

SELECT * FROM pg_partition_ancestors('ptif_test01_index');

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

SELECT count(*) FROM (SELECT * FROM pg_partition_ancestors('ptif_test01_index')) AS _sub;


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

SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a IN (1, 2, 26, 27, 51, 52, 76, 77) AND b IN (''1'', ''2'', ''26'', ''27'') AND c IN (1, 2)');

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

SELECT count(*) FROM (SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a IN (1, 2, 26, 27, 51, 52, 76, 77) AND b IN (''1'', ''2'', ''26'', ''27'') AND c IN (1, 2)')) AS _sub;


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

CREATE VIEW temp_view_test.v3_temp AS SELECT * FROM temp_table;

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


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

CREATE TABLE multiple_part_key(time TIMESTAMPTZ, time2 TIMESTAMP, device TEXT) PARTITION BY RANGE (time, time2) WITH (timescaledb.hypertable, timescaledb.partition_column='time');

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


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

SELECT t1."C 1", t2.c1, t3.c1 FROM "S 1"."T 1" t1 full join ft1 t2 full join ft2 t3 on (t2.c1 = t3.c1) on (t3.c1 = t1."C 1") OFFSET 100 LIMIT 10;

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


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

DELETE FROM temporal_mltrng WHERE id = '[5,6)';

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


Question: pgTAP test for Hastap (assertion 242).

SELECT * FROM check_test(
  has_opclass( 'int4_ops' ),
  true,
  'has_opclass( name )',
  'Operator class int4_ops should exist',
  ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

CREATE TABLE fail_part PARTITION OF list_parted2 FOR VALUES IN (null);

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


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

SELECT count(*) FROM radix_text_tbl WHERE t ^@	 'Worth';

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

SELECT count(*) FROM (SELECT count(*) FROM radix_text_tbl WHERE t ^@	 'Worth') AS _sub;


Question: Write the DDL statement from PostgreSQL regression test 'publication' (example 588).

CREATE TABLE pub_testpart2.child_parent1 partition of pub_testpart1.parent1 for values in (1);

Explanation: DDL from PostgreSQL core regression test for Publication.