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

SELECT JSON_ARRAY(SELECT i FROM (VALUES (NULL::int[]), ('{1,2}'), (NULL), (NULL), ('{3,4}'), (NULL)) foo(i) RETURNING jsonb);

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

SELECT count(*) FROM (SELECT JSON_ARRAY(SELECT i FROM (VALUES (NULL::int[]), ('{1,2}'), (NULL), (NULL), ('{3,4}'), (NULL)) foo(i) RETURNING jsonb)) AS _sub;


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

SELECT DISTINCT ON (y, x) x, y FROM (select * from distinct_on_tbl order by x, z, y) s ORDER BY y, x, z;

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

SELECT count(*) FROM (SELECT DISTINCT ON (y, x) x, y FROM (select * from distinct_on_tbl order by x, z, y) s ORDER BY y, x, z) AS _sub;


Question: pgTAP test for Index (assertion 9).

CREATE UNIQUE INDEX idx_baz ON public.sometab(LOWER(name));

Explanation: SQL assertion from pgTAP test suite for Index.


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

SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  FROM pg_class where relname = 'toasttest';

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

SELECT count(*) FROM (SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
  FROM pg_class where relname = 'toasttest') AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'polygon' (example 12).

INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');

Explanation: DML from PostgreSQL core regression test for Polygon.


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

SELECT count(*) FROM ltreetest WHERE t >= '12.3';

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


Question: pgTAP test for Hastap (assertion 273).

SELECT * FROM check_test(
    domain_type_isnt( 'public', 'us_postal_code', 'text', 'whatever'),
    false,
    'domain_type_isnt(schema, domain, type, desc) fail',
    'whatever',
    '        have: text
        want: anything else'
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

INSERT INTO num_input_test(n1) VALUES ('1.2e3__4');

Explanation: DML from PostgreSQL core regression test for Numeric.


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

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

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


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

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


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

SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext, 's') = ARRAY[ 'hello', 'world' ] AS t;

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


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

SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 RIGHT JOIN ft2 t2 ON (t1.c1 = t2.c1) FULL JOIN ft4 t3 ON (t2.c1 = t3.c1) OFFSET 10 LIMIT 10;

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


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

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

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


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

SELECT * FROM pg_get_wal_stats_till_end_of_wal('FFFFFFFF/FFFFFFFF');

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


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

insert into pparent values (1,'parent1');

Explanation: DML from PostgreSQL core regression test for Rules.


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

SELECT nummultirange() && 'empty'::numrange;

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

SELECT count(*) FROM (SELECT nummultirange() && 'empty'::numrange) AS _sub;


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

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


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


Question: PostgreSQL Queries: show example 54.

WITH RECURSIVE included_parts(sub_part, part) AS ( SELECT sub_part, part FROM parts WHERE part = 'our_product' UNION ALL SELECT p.sub_part, p.part FROM included_parts pr, parts p WHERE p.part = pr.sub_part ) DELETE FROM parts WHERE part IN (SELECT part FROM included_parts);

Explanation: Example from PostgreSQL documentation on Queries.


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

CREATE FUNCTION btismn13cmp(ismn13, ismn)
	RETURNS int4
	AS 'btint8cmp'
	LANGUAGE 'internal'
	IMMUTABLE STRICT
	PARALLEL SAFE;

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


Question: Write the DDL statement from PostgreSQL regression test 'psql' (example 230).

create function psql_df_internal (float8)
  returns float8
  language internal immutable parallel safe strict
  as 'dsin';

Explanation: DDL from PostgreSQL core regression test for Psql.


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

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

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


Question: PostgreSQL regression test 'circle': Write the SELECT query (example 19).

SELECT f1 FROM CIRCLE_TBL WHERE diameter(f1) >= 10;

SELECT count(*) FROM (SELECT f1 FROM CIRCLE_TBL WHERE diameter(f1) >= 10) AS _sub;


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

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


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


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

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


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

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

SELECT count(*) FROM (select jsonb_path_query('"1.23aaa"', '$.string()')) AS _sub;


Question: PostgreSQL Plpgsql: show example 46.

CREATE TABLE db (a INT PRIMARY KEY, b TEXT); CREATE FUNCTION merge_db(key INT, data TEXT) RETURNS VOID AS $$ BEGIN LOOP -- first try to update the key UPDATE db SET b = data WHERE a = key; IF found THEN RETURN; END IF; -- not there, so try to insert the key -- if someone else inserts the same key concurrently, -- we could get a unique-key failure BEGIN INSERT INTO db(a,b) VALUES (key, data); RETURN; EXCEPTION WHEN unique_violation THEN -- Do nothing, and loop to try the UPDATE again. END; END LOOP; END; $$ LANGUAGE plpgsql; SELECT merge_db(1, 'david'); SELECT merge_db(1, 'dennis');

Explanation: Example from PostgreSQL documentation on Plpgsql.


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

-- obsolete:
CREATE OPERATOR @ (
	LEFTARG = seg,
	RIGHTARG = seg,
	PROCEDURE = seg_contains,
	COMMUTATOR = '~',
	RESTRICT = contsel,
	JOIN = contjoinsel
);


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

PREPARE recentfilms(date) AS SELECT * FROM films WHERE date_prod > $1; CREATE TEMP TABLE films_recent ON COMMIT DROP AS EXECUTE recentfilms('2002-01-01');

Explanation: PostgreSQL CREATE TABLE AS command.


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

SELECT plainto_tsquery('english', 'foo bar') || !!plainto_tsquery('english', 'asd fg');

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

SELECT count(*) FROM (SELECT plainto_tsquery('english', 'foo bar') || !!plainto_tsquery('english', 'asd fg')) AS _sub;


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

SELECT server_name, user_name = CURRENT_USER as "user_name = CURRENT_USER",
  valid, used_in_xact, closed,
  remote_backend_pid = ANY(SELECT pid FROM pg_stat_activity
  WHERE backend_type = 'client backend' AND pid <> pg_backend_pid())
  as remote_backend_pid
  FROM postgres_fdw_get_connections() ORDER BY 1;


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

SELECT r.rngtypid, r.rngsubtype, p.proname
FROM pg_range r JOIN pg_proc p ON p.oid = r.rngmltconstruct0 JOIN pg_type t ON r.rngmultitypid = t.oid
WHERE p.pronargs != 0
    OR p.prorettype != r.rngmultitypid
    OR p.proname != t.typname OR p.prosrc != 'multirange_constructor0';

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

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


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

INSERT INTO FKTABLE VALUES (NULL, 2, 3, 2);

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


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

insert into rtest_view1 values (3, 'item 3', 't');


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

-- check that this doesn't leak a holdable portal
SELECT * FROM pg_cursors;

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


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

SELECT count(*) FROM (select jsonb_path_query('"1.23"', '$.double()')) AS _sub;


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

CREATE VIEW classv AS SELECT * FROM pg_class;

Explanation: DDL from PostgreSQL core regression test for Merge.


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

CREATE EVENT TRIGGER regress_event_trigger_report_end ON ddl_command_end
  EXECUTE PROCEDURE event_trigger_report_end();

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


Question: pgTAP test for Resultset (assertion 161).

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

Explanation: SQL assertion from pgTAP test suite for Resultset.


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

create rule rules_foorule as on insert to rules_foo where f1 < 100
do instead insert into rules_foo2 values (new.f1);

Explanation: DDL from PostgreSQL core regression test for Rules.


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

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

SELECT count(*) FROM (SELECT xmlconcat(NULL, NULL)) AS _sub;


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

INSERT INTO hats VALUES ('h8', 'white') RETURNING *;

Explanation: DML from PostgreSQL core regression test for Rules.


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

SELECT * FROM (VALUES (1),(2),(3)) v(r), generate_series(10+r,20-r) f(i);

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

SELECT count(*) FROM (SELECT * FROM (VALUES (1),(2),(3)) v(r), generate_series(10+r,20-r) f(i)) AS _sub;


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

select *
  from (values (1),(2)) v(x),
       lateral (select a, b, sum(v.x) from gstest_data(v.x) group by rollup (a,b)) s;

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

SELECT count(*) FROM (select *
  from (values (1),(2)) v(x),
       lateral (select a, b, sum(v.x) from gstest_data(v.x) group by rollup (a,b)) s) AS _sub;


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

SELECT 'Ask Bjørn Hansen'::citext <> 'Ask Bjorn Hansen'::citext AS t;

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


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

Explanation: DML from PostgreSQL core regression test for Numeric.


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

ALTER OPERATOR FAMILY alt_opf14 USING btree ADD FUNCTION 1 fn_opf14(int4);

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


Question: Show a SQL definition from the citus project (merge_repartition1, item 16).

CREATE TABLE pg_source(id int, val int, const int);

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


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

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


Question: PostgreSQL Typeconv: show example 6.

Explanation: Example from PostgreSQL documentation on Typeconv.


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

CREATE TABLE evttrig.part_10_15 PARTITION OF evttrig.part_10_20 (id)
  FOR VALUES FROM (10) TO (15);


Question: PostgreSQL Plpgsql: show example 22.

CREATE TABLE mytable (id int PRIMARY KEY, data text); INSERT INTO mytable VALUES (1,'one'), (2,'two');

Explanation: Example from PostgreSQL documentation on Plpgsql.


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

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

SELECT count(*) FROM (SELECT 37 - q1 AS minus4 FROM INT8_TBL) AS _sub;


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

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


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

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


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

Explanation: DML from PostgreSQL core regression test for Line.


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

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

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


Question: Show a SQL definition from the timescaledb project (histogram, item 6).

-- We started using CREATE OR REPLACE AGGREGATE for aggregate creation once the syntax was fully supported
-- as it is easier to support idempotent changes this way. This will allow for changes to functions supporting
-- the aggregate, and, for instance, the definition and inclusion of inverse functions for window function
-- support. However, it should still be noted that changes to the data structures used for the internal
-- state of the aggregate must be backwards compatible and the old format must be accepted by any new functions
-- in order for them to continue working with Continuous Aggregates, where old states may have been materialized.

-- This aggregate partitions the dataset into a specified number of buckets (nbuckets) ranging
-- from the inputted min to max values.
CREATE OR REPLACE AGGREGATE @extschema@.histogram (DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE PRECISION, INTEGER) (
    SFUNC = _timescaledb_functions.hist_sfunc,
    STYPE = INTERNAL,
    COMBINEFUNC = _timescaledb_functions.hist_combinefunc,
    SERIALFUNC = _timescaledb_functions.hist_serializefunc,
    DESERIALFUNC = _timescaledb_functions.hist_deserializefunc,
    PARALLEL = SAFE,
    FINALFUNC = _timescaledb_functions.hist_finalfunc,
    FINALFUNC_EXTRA
);

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


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

SELECT c.*
   FROM CHAR_TBL c
   WHERE c.f1 = 'a';

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

SELECT count(*) FROM (SELECT c.*
   FROM CHAR_TBL c
   WHERE c.f1 = 'a') AS _sub;


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

CREATE TABLE foo_part_d2 (b float8, c text, a int);

Explanation: DDL from PostgreSQL core regression test for Returning.


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

SELECT ts_delete('base hidden rebel spaceship strike'::tsvector, 'spaceship');

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

SELECT count(*) FROM (SELECT ts_delete('base hidden rebel spaceship strike'::tsvector, 'spaceship')) AS _sub;


Question: pgTAP test for Hastap (assertion 143).

-- Make sure it works with composite types.
SELECT * FROM check_test(
    hasnt_column( 'sometype', 'foobar' ),
    true,
    'hasnt_column(type, column)',
    'Column sometype.foobar should not exist',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

ALTER EXTENSION pgtap ADD FUNCTION _currtest();


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

CREATE TRIGGER rw_view1_del_trig INSTEAD OF DELETE ON rw_view1
  FOR EACH ROW EXECUTE PROCEDURE rw_view1_trig_fn();

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


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

SELECT count(*) FROM float8tmp WHERE a <= -1890.0::float8;

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


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

Explanation: DML from PostgreSQL core regression test for Arrays.


Question: pgTAP test for Pgtap--0.92.0--0.93.0 (assertion 9).

CREATE OR REPLACE FUNCTION _trig ( NAME, NAME )
RETURNS BOOLEAN AS $$
    SELECT EXISTS(
        SELECT true
          FROM pg_catalog.pg_trigger t
          JOIN pg_catalog.pg_class c     ON c.oid = t.tgrelid
         WHERE c.relname = $1
           AND t.tgname  = $2
           AND pg_catalog.pg_table_is_visible(c.oid)
    );
$$ LANGUAGE SQL;

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


Question: PL/pgSQL test: Plpgsql Varprops (example 11).

do $$
declare x constant var_record; y int;
begin
  for x.f1, y in select 1, 2 loop  -- fail
  end loop;
end$$;

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


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

SELECT * FROM bt_multi_page_stats('test2_col1_idx', 1, 2);

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


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

DROP TRIGGER trans_deletetrig ON range_parted;

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


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

select a, b, row_number() over (order by a, b nulls first)
from (values (1, 1), (2, 2)) as t (a, b) where a = b
group by grouping sets((a, b), (a));

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

SELECT count(*) FROM (select a, b, row_number() over (order by a, b nulls first)
from (values (1, 1), (2, 2)) as t (a, b) where a = b
group by grouping sets((a, b), (a))) AS _sub;


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

CREATE TABLE reloptions_test(time integer, temp float8, color integer)
WITH (fillfactor=75, autovacuum_vacuum_threshold=100);


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

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


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

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

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

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


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

select bar.*, unnamed_join.* from
  (t1 join t2 using (a) as foo) as bar, t3 as unnamed_join
  for update of bar;

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

SELECT count(*) FROM (select bar.*, unnamed_join.* from
  (t1 join t2 using (a) as foo) as bar, t3 as unnamed_join
  for update of bar) AS _sub;


Question: Show a SQL definition from the timescaledb project (test_utils, item 14).

\set ON_ERROR_STOP 1

-- error injections
--
CREATE OR REPLACE FUNCTION test_error_injection(TEXT)
RETURNS VOID
AS :MODULE_PATHNAME, 'ts_test_error_injection'
LANGUAGE C VOLATILE STRICT;


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

INSERT INTO orderstest VALUES (66, 6, false);

Explanation: DML from PostgreSQL core regression test for Subselect.


Question: Show a SQL definition from the pglogical project (parallel, item 12).

SELECT pglogical.replicate_ddl_command($$
    CREATE TABLE public.basic_dml1 (
        id serial primary key,
        other integer,
        data text,
        something interval
    );
    CREATE TABLE public.basic_dml2 (
        id serial primary key,
        other integer,
        data text,
        something interval
    );
$$);

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


Question: pgTAP test for Hastap (assertion 144).


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

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

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


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

Explanation: DML from PostgreSQL core regression test for Rowsecurity.


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

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

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


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

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


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

select jsonb_path_query('[1,"2",3]', '+$', silent => true);

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

SELECT count(*) FROM (select jsonb_path_query('[1,"2",3]', '+$', silent => true)) AS _sub;


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

create table notnull_tbl_fail (a int not null no inherit primary key);

Explanation: DDL from PostgreSQL core regression test for Constraints.


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

SELECT lower('AbCd 123 #$% ıiIİ ẞ ß Ǆǅǆ Σσς' COLLATE "tr-x-icu");

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

SELECT count(*) FROM (SELECT lower('AbCd 123 #$% ıiIİ ẞ ß Ǆǅǆ Σσς' COLLATE "tr-x-icu")) AS _sub;


Question: pgTAP test for Ownership (assertion 132).

SELECT * FROM check_test(
    type_owner_is('sometype', current_user),
	true,
    'type_owner_is(type, user)',
    'Type sometype should be owned by ' || quote_ident(current_user),
    ''
);

Explanation: SQL assertion from pgTAP test suite for Ownership.


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

CREATE FUNCTION dblink_open (text, text, text, boolean)
RETURNS text
AS 'MODULE_PATHNAME','dblink_open'
LANGUAGE C STRICT PARALLEL RESTRICTED;


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

SELECT f.* FROM FLOAT8_TBL f WHERE f.f1 <> '1004.3';

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

SELECT count(*) FROM (SELECT f.* FROM FLOAT8_TBL f WHERE f.f1 <> '1004.3') AS _sub;


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

CREATE TRIGGER check_update BEFORE UPDATE ON accounts FOR EACH ROW EXECUTE FUNCTION check_account_update();

Explanation: PostgreSQL CREATE TRIGGER command.


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

Explanation: Regression test for Brin Bloom in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT brin_summarize_range('brin_summarize_bloom_idx', 2)) AS _sub;


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

SELECT * FROM pglogical_regress_variables()
\gset

\c :provider_dsn

SELECT pglogical.replicate_ddl_command($$
	CREATE TABLE public.test_trg_data(id serial primary key, data text);
$$);


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

SELECT '( 1 , 1)'::citext::point ~= '(1,1)'::point AS t;

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


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

INSERT INTO PRIMARY_TBL VALUES (1, 'three');

Explanation: DML from PostgreSQL core regression test for Constraints.


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

SELECT count(*) FROM (select jsonb_path_query('"12:34:56 +05:30"', '$.timestamp()')) AS _sub;


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

-- test as part of prepare/execute
CREATE FUNCTION test3() RETURNS void
LANGUAGE plperlu
TRANSFORM FOR TYPE hstore
AS $$
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 0;

$rv = spi_exec_query(q{SELECT 'aa=>bb, cc=>NULL'::hstore AS col1});
elog(INFO, Dumper($rv->{rows}[0]->{col1}));

$val = {a => 1, b => 'boo', c => undef};
$plan = spi_prepare(q{SELECT $1::text AS col1}, "hstore");
$rv = spi_exec_prepared($plan, {}, $val);
elog(INFO, Dumper($rv->{rows}[0]->{col1}));
$$;

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


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

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

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


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

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

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


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

INSERT INTO num_exp_mul VALUES (5,0,'0');

Explanation: DML from PostgreSQL core regression test for Numeric.


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

SELECT JSON_QUERY(jsonb '123', '$' RETURNING queryfuncs_char2 DEFAULT '1' ON ERROR);

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

SELECT count(*) FROM (SELECT JSON_QUERY(jsonb '123', '$' RETURNING queryfuncs_char2 DEFAULT '1' ON ERROR)) AS _sub;


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

SELECT a, lower(coalesce(x, 'foo')), lower(coalesce(y, 'foo')) FROM collate_test10;

SELECT count(*) FROM (SELECT a, lower(coalesce(x, 'foo')), lower(coalesce(y, 'foo')) FROM collate_test10) AS _sub;


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

CREATE FUNCTION gin_extract_value_numeric(numeric, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;


Question: PL/pgSQL test: Plperl Util (example 12).

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


Question: Write the DDL statement from PostgreSQL regression test 'object_address' (example 16).

CREATE MATERIALIZED VIEW addr_nsp.genmatview AS SELECT * FROM addr_nsp.gentable;

Explanation: DDL from PostgreSQL core regression test for Object Address.


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

SELECT x,
       gamma(x),
       lgamma(x)
FROM (VALUES (0.5), (1), (2), (3), (4), (5),
             (float8 'infinity'), (float8 'nan')) AS t(x);

SELECT count(*) FROM (SELECT x,
       gamma(x),
       lgamma(x)
FROM (VALUES (0.5), (1), (2), (3), (4), (5),
             (float8 'infinity'), (float8 'nan')) AS t(x)) AS _sub;


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

create table chi partition of middle for values from (1) to (5);

Explanation: DDL from PostgreSQL core regression test for Triggers.


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

create table lp (a char) partition by list (a);

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


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

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


Question: Write the DDL statement from PostgreSQL regression test 'brin_multi' (example 83).

CREATE INDEX brin_test_multi_a_idx ON brin_test_multi USING brin (a) WITH (pages_per_range = 2);

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


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

select count(*) from testhstore where h ?| ARRAY['public','disabled'];

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


Question: pgTAP test for Unique (assertion 9).

SELECT * FROM check_test(
    has_unique( 'public', 'uniqueless', 'public.uniqueless should have a unique constraint' ),
    false,
    'has_unique( schema, table, description ) fail',
    'public.uniqueless should have a unique constraint',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Unique.


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

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


Question: Write the DML statement from PostgreSQL regression test 'join_hash' (example 14).

update pg_class set reltuples = 1000 where relname = 'bigger_than_it_looks';

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


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

create index idxparti2 on idxpart (b, c);

Explanation: DDL from PostgreSQL core regression test for Indexing.


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

SELECT 1 FROM xact_test FOR UPDATE LIMIT 1;

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


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

SELECT regexp_split_to_array('helloTworld'::citext, 't'::citext) = ARRAY[ 'hello', 'world' ] AS t;

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


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

CREATE COLLATION mycoll2 ( LC_COLLATE = "POSIX", LC_CTYPE = "POSIX" );

Explanation: DDL from PostgreSQL core regression test for Collate.


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

INSERT INTO tbl_include_box_pk SELECT 1, 2, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;

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


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

select * from tcl_dcomposite_result(1002);

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


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

SELECT * FROM test_int2 WHERE i>=1::int4 ORDER BY i;

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


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

SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a char(3) EXISTS PATH '$.a' ERROR ON ERROR));

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

SELECT count(*) FROM (SELECT * FROM JSON_TABLE(jsonb '"a"', '$' COLUMNS (a char(3) EXISTS PATH '$.a' ERROR ON ERROR))) AS _sub;


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

select interval '0.01 months 9223372036854775807 microseconds';

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

SELECT count(*) FROM (select interval '0.01 months 9223372036854775807 microseconds') AS _sub;


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

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


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

select (x+y)*1, sum(z)
 from (select 1 as x, 2 as y, 3 as z) s
 group by grouping sets (x+y, x);

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

SELECT count(*) FROM (select (x+y)*1, sum(z)
 from (select 1 as x, 2 as y, 3 as z) s
 group by grouping sets (x+y, x)) AS _sub;


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

INSERT INTO caster (citext)        VALUES ('08:00:2b:01:02:03'::macaddr);


Question: Show a SQL definition from the citus project (distributed_collations, item 25).

-- Test range table with collated distribution column
CREATE TABLE test_range(key text COLLATE german_phonebook, val int);

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


Question: PostgreSQL Rules: show example 33.

INSERT INTO shoelace_log VALUES ( shoelace_data.sl_name , 6 , current_user, current_timestamp ) FROM shoelace_data new, shoelace_data old, shoelace_data shoelace_data WHERE 6 <> old.sl_avail AND shoelace_data.sl_name = 'sl7';

Explanation: Example from PostgreSQL documentation on Rules.


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

CREATE TABLE pht1_p2 PARTITION OF pht1 FOR VALUES WITH (MODULUS 3, REMAINDER 1);

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


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

CREATE FUNCTION show_trgm(text)
RETURNS _text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;

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


Question: Write the DML statement from PostgreSQL regression test 'stats' (example 118).

INSERT INTO drop_stats_test_subxact DEFAULT VALUES;

Explanation: DML from PostgreSQL core regression test for Stats.


Question: Create a trigger that updates a modified_at timestamp on every UPDATE.

CREATE TABLE articles (id serial PRIMARY KEY, title text, body text, modified_at timestamptz DEFAULT now());

CREATE OR REPLACE FUNCTION update_modified_at() RETURNS trigger AS $$
BEGIN
    NEW.modified_at := now();
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_articles_modified BEFORE UPDATE ON articles FOR EACH ROW EXECUTE FUNCTION update_modified_at();

Explanation: PL/pgSQL trigger function sets NEW.modified_at to now() before each UPDATE. Trigger fires per row.


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

SELECT '2011-03-27 03:00:01 Europe/Moscow'::timestamptz;

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

SELECT count(*) FROM (SELECT '2011-03-27 03:00:01 Europe/Moscow'::timestamptz) AS _sub;


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

SELECT * FROM test_type_conversion_int8(100);

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


Question: Show a SQL definition from the zombodb project (_mappings, item 8).

CREATE TABLE zdb.type_conversions
(
    typeoid    regtype NOT NULL PRIMARY KEY,
    funcoid    regproc NOT NULL,
    is_default boolean DEFAULT false
);

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


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

Explanation: DDL from PostgreSQL core regression test for Join.


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

CREATE FUNCTION plperl_to_hstore(val internal) RETURNS hstore
LANGUAGE C STRICT IMMUTABLE
AS '$libdir/hstore_plperl';

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


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

create index nummultirange_test2_hash_idx on nummultirange_test2 using hash (nmr);

Explanation: DDL from PostgreSQL core regression test for Multirangetypes.


Question: pgTAP test for Runtests (assertion 17).

CREATE OR REPLACE FUNCTION whatever.testy() RETURNS SETOF TEXT AS $$
    SELECT fail('this test intentionally fails');
$$ LANGUAGE SQL;

Explanation: SQL assertion from pgTAP test suite for Runtests.


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

/* contrib/pgstattuple/pgstattuple--1.2--1.3.sql */

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

CREATE FUNCTION pgstattuple_approx(IN reloid regclass,
    OUT table_len BIGINT,               -- physical table length in bytes
    OUT scanned_percent FLOAT8,         -- what percentage of the table's pages was scanned
    OUT approx_tuple_count BIGINT,      -- estimated number of live tuples
    OUT approx_tuple_len BIGINT,        -- estimated total length in bytes of live tuples
    OUT approx_tuple_percent FLOAT8,    -- live tuples in % (based on estimate)
    OUT dead_tuple_count BIGINT,        -- exact number of dead tuples
    OUT dead_tuple_len BIGINT,          -- exact total length in bytes of dead tuples
    OUT dead_tuple_percent FLOAT8,      -- dead tuples in % (based on estimate)
    OUT approx_free_space BIGINT,       -- estimated free space in bytes
    OUT approx_free_percent FLOAT8)     -- free space in % (based on estimate)
AS 'MODULE_PATHNAME', 'pgstattuple_approx'
LANGUAGE C STRICT;


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

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


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

select * from mr_outparam_succeed(int4multirange(int4range(1,2)));

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

SELECT count(*) FROM (select * from mr_outparam_succeed(int4multirange(int4range(1,2)))) AS _sub;


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

CREATE FUNCTION gin_extract_value_bytea(bytea, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;


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

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

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


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

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


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

SELECT n_tup_ins, n_live_tup, n_dead_tup
  FROM pg_stat_all_tables WHERE relname = 'test_rewrite_alone_abort';

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

SELECT count(*) FROM (SELECT n_tup_ins, n_live_tup, n_dead_tup
  FROM pg_stat_all_tables WHERE relname = 'test_rewrite_alone_abort') AS _sub;


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

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


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

SELECT message FROM pg_input_error_info('<value>one</', 'xml');

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

SELECT count(*) FROM (SELECT message FROM pg_input_error_info('<value>one</', 'xml')) AS _sub;


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

Explanation: DML from PostgreSQL core regression test for Domain.


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

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

SELECT count(*) FROM (select null::int = any ('{1,2,3}')) AS _sub;


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

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


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

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

SELECT count(*) FROM (select '$a[*]'::jsonpath) AS _sub;


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

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

SELECT count(*) FROM (select pg_input_is_valid('(1,4', 'int4range')) AS _sub;


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

CREATE TABLE table_to_split (id bigserial PRIMARY KEY, value char);

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


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

CREATE VIEW bv1 WITH (security_barrier) AS SELECT * FROM b1 WHERE a > 0 WITH CHECK OPTION;

Explanation: DDL from PostgreSQL core regression test for Rowsecurity.


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

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

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


Question: Write the DML statement from PostgreSQL regression test 'macaddr' (example 8).

INSERT INTO macaddr_data VALUES (7, '08002b010203');

Explanation: DML from PostgreSQL core regression test for Macaddr.


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

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


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

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

SELECT count(*) FROM (SELECT pg_input_is_valid('50000', 'int2')) AS _sub;


Question: Show a SQL definition from the timescaledb project (c_unit_tests, item 6).

CREATE OR REPLACE FUNCTION test.jsonb_utils() RETURNS VOID
AS :MODULE_PATHNAME, 'ts_test_jsonb_utils' LANGUAGE C;

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


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

select i, left('ahoj', i), right('ahoj', i) from generate_series(-5, 5) t(i) order by i;

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

SELECT count(*) FROM (select i, left('ahoj', i), right('ahoj', i) from generate_series(-5, 5) t(i) order by i) AS _sub;


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

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


Question: Write the DDL statement from PostgreSQL regression test 'lock' (example 130).

CREATE FUNCTION test_atomic_ops()
    RETURNS bool
    AS :'regresslib'
    LANGUAGE C;

Explanation: DDL from PostgreSQL core regression test for Lock.


Question: PostgreSQL Advanced: show example 15.

SELECT name, elevation FROM cities WHERE elevation > 500;

Explanation: Example from PostgreSQL documentation on Advanced.


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

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


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

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


Question: pgTAP test for Hastap (assertion 229).

SELECT * FROM check_test(
    has_language('aoijaoisjfaoidfjaisjdfosjf'),
    false,
    'has_language(nonexistent language)',
    'Procedural language aoijaoisjfaoidfjaisjdfosjf should exist',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


Question: PostgreSQL regression test 'create_index': Write the SELECT query (example 310).

SELECT unique1, unique2 FROM onek_with_null WHERE unique1 = 500 ORDER BY unique2 DESC, unique1 DESC LIMIT 1;

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

SELECT count(*) FROM (SELECT unique1, unique2 FROM onek_with_null WHERE unique1 = 500 ORDER BY unique2 DESC, unique1 DESC LIMIT 1) AS _sub;


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

select interval '2147483647 days 1 week';

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

SELECT count(*) FROM (select interval '2147483647 days 1 week') AS _sub;


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

-- Exercise code in ExecGetTriggerResultRel() as there's been previous issues
-- with ResultRelInfos being returned with the incorrect ri_RootResultRelInfo
WITH cte AS (
  UPDATE fkpart13_t2_p1 SET part_id = part_id
) UPDATE fkpart13_t1 SET a = 2 WHERE a = 1;

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


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

CREATE FUNCTION gen_salt(text)
RETURNS text
AS 'MODULE_PATHNAME', 'pg_gen_salt'
LANGUAGE C VOLATILE STRICT PARALLEL SAFE;

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


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

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


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

SELECT JSON_VALUE(jsonb '"aaa"', '$' RETURNING json);

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

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


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

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

SELECT count(*) FROM (SELECT stddev_pop('nan'::numeric), stddev_samp('nan'::numeric)) AS _sub;


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


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

Explanation: DDL from PostgreSQL core regression test for Indexing.


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

SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', 'nomatch') AS foo;

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

SELECT count(*) FROM (SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', 'nomatch') AS foo) AS _sub;


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

create or replace function retc(int) returns two_int8s language plpgsql as
$$ declare r record; begin r := row($1::int8, 1::int8, 42); return r; end $$;
select retc(42);

-- but, for mostly historical reasons, we do convert when assigning
-- to a named-composite-type variable
create or replace function retc(int) returns two_int8s language plpgsql as
$$ declare r two_int8s; begin r := row($1::int8, 1::int8, 42); return r; end $$;

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


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

--
-- SQL-standard body
--
CREATE FUNCTION functest_S_1(a text, b date) RETURNS boolean
    LANGUAGE SQL
    RETURN a = 'abcd' AND b > '2001-01-01';

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


Question: Write the DML statement from PostgreSQL regression test 'sqljson' (example 196).

Explanation: DML from PostgreSQL core regression test for Sqljson.


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

$$;

TRUNCATE test1;

CALL cursor_fail_during_commit();

-- note that error occurs during first COMMIT, hence nothing is in test1
SELECT count(*) FROM test1;

CREATE PROCEDURE cursor_fail_during_rollback()
 LANGUAGE plpgsql
AS $$
  DECLARE id int;

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


Question: pgTAP test for Policy (assertion 53).

SELECT * FROM check_test(
    policy_cmd_is( 'passwd', 'daemon_insert', 'delete', 'whatever' ),
    false,
    'policy_cmd_is(table, policy, command, desc) for INSERT should fail',
    'whatever',
    '        have: INSERT
        want: DELETE'
);

Explanation: SQL assertion from pgTAP test suite for Policy.


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

SELECT data FROM test_float WHERE data IN ('1', '2');

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


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

SELECT * FROM test_interval WHERE i<='08:55:08'::interval ORDER BY i;

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


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

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


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

CREATE OR REPLACE FUNCTION perl_row() RETURNS testrowperl AS $$
    return undef;
$$ LANGUAGE plperl;

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


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

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

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


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

SELECT time without time zone '040506.07';

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

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


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

SELECT count(*) FROM (SELECT JSON_EXISTS(jsonb '{}', '$.a')) AS _sub;


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

SELECT d1 as "timestamp",
   date_part( 'isoyear', d1) AS isoyear, date_part( 'week', d1) AS week,
   date_part( 'isodow', d1) AS isodow, date_part( 'dow', d1) AS dow,
   date_part( 'doy', d1) AS doy
   FROM TIMESTAMP_TBL;

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

SELECT count(*) FROM (SELECT d1 as "timestamp",
   date_part( 'isoyear', d1) AS isoyear, date_part( 'week', d1) AS week,
   date_part( 'isodow', d1) AS isodow, date_part( 'dow', d1) AS dow,
   date_part( 'doy', d1) AS doy
   FROM TIMESTAMP_TBL) AS _sub;


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

CREATE TEMP TABLE quad_box_tbl_ord_idx2 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: pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 667).

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

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


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

INSERT INTO TIMESTAMP_TBL VALUES ('Feb 16 17:32:01 5097 BC');

Explanation: DML from PostgreSQL core regression test for Timestamp.


Question: pgTAP test for Hastap (assertion 278).

SELECT * FROM check_test(
    domain_type_isnt( 'us_postal_code', 'text', 'whatever'),
    false,
    'domain_type_isnt(domain, type, desc) fail',
    'whatever',
    '        have: text
        want: anything else'
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

CREATE TABLE tststats.priv_test_tbl (
    a int,
    b int
);

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


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

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

SELECT count(*) FROM (SELECT t1.*, t2.* FROM alpha t1 INNER JOIN beta t2 ON (t1.a = t2.a AND t1.c = t2.c) WHERE ((t1.b >= 100 AND t1.b < 110) OR (t1.b >= 200 AND t1.b < 210)) AND ((t2.b >= 100 AND t2.b < 110) OR (t2.b >= 200 AND t2.b < 210)) AND t1.c IN ('0004', '0009') ORDER BY t1.a, t1.b, t2.b) AS _sub;


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

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

SELECT count(*) FROM (SELECT interval '1 2:03' day to hour) AS _sub;


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

select from generate_series(1,5) intersect select from generate_series(1,3);

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

SELECT count(*) FROM (select from generate_series(1,5) intersect select from generate_series(1,3)) AS _sub;


Question: pgTAP test for Proctap (assertion 58).

SELECT * FROM check_test(
    isnt_procedure( 'argpubproc', ARRAY['integer', 'text'] ),
    false,
    'isnt_procedure(proc, args)',
    'Function argpubproc(integer, text) should not be a procedure',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Proctap.


Question: pgTAP test for Inheritance (assertion 26).

SELECT * FROM check_test(
    hasnt_inherited_tables( 'hide', 'h_child1'::name ),
    false,
    'hasnt_inherited_tables(sch, tab) fail',
    'Table hide.h_child1 should not have descendents',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Inheritance.


Question: Write the DDL statement from PostgreSQL regression test 'subscription' (example 29).

CREATE SUBSCRIPTION regress_testsub2 CONNECTION 'dbname=regress_doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = false, create_slot = true);

Explanation: DDL from PostgreSQL core regression test for Subscription.


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

SELECT * FROM bt_page_items('test1_a_idx', 1);

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


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

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


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

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


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

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

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


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

SELECT * FROM multiout_record_as('tuple', null, 2, false);

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


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

create function testpolym(a int, inout a int) returns int as $$ select 1;$$ language sql;

-- valid
create function testpolym(a int, out a int) returns int as $$ select $1;$$ language sql;

Explanation: DDL from PostgreSQL core regression test for Polymorphism.


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

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

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


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

UPDATE pk SET a = 90 WHERE a = 30 RETURNING *;

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


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

SELECT COUNT(*) FROM pg_stat_statements WHERE query LIKE '%FETCH FIRST%';

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


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

-- test with more than one reason to rewrite a single table
CREATE OR REPLACE FUNCTION test_evtrig_no_rewrite() RETURNS event_trigger
LANGUAGE plpgsql AS $$
BEGIN
  RAISE NOTICE 'Table ''%'' is being rewritten (reason = %)',
               pg_event_trigger_table_rewrite_oid()::regclass,
               pg_event_trigger_table_rewrite_reason();
END;
$$;

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


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

Explanation: DML from PostgreSQL core regression test for Tablespace.


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


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

CREATE FUNCTION _ltxtq_extract_exec(_ltree,ltxtquery)
RETURNS ltree
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;


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

SELECT sum(x::numeric), avg(x::numeric), var_pop(x::numeric)
FROM (VALUES ('1'), ('infinity')) v(x);

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

SELECT count(*) FROM (SELECT sum(x::numeric), avg(x::numeric), var_pop(x::numeric)
FROM (VALUES ('1'), ('infinity')) v(x)) AS _sub;


Question: PL/pgSQL test: Plperl Util (example 22).

create or replace function perl_encode_typed_literal() returns setof text language plperl as $$
	return_next encode_typed_literal({a => 0, b => ['PL','/','Perl']}, 'perl_foo_pos');
$$;

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


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

Explanation: DDL from PostgreSQL core regression test for Inherit.


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

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

SELECT count(*) FROM (SELECT '2012-12-12 12:00'::timestamptz) AS _sub;


Question: pgTAP test for Functap (assertion 350).

SELECT * FROM check_test(
    isnt_strict( 'oww', ARRAY['int', 'text'], 'whatever' ),
    true,
    'isnt_strict(func, args, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

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


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

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

SELECT count(*) FROM (SELECT lpad('hello', 2)) AS _sub;


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

select * from pgstathashindex('test_hashidx');

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


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

INSERT INTO department VALUES (1, 0, 'A');

Explanation: DML from PostgreSQL core regression test for With.


Question: PostgreSQL Plpgsql: show example 40.

IF v_count > 0 THEN INSERT INTO users_count (count) VALUES (v_count); RETURN 't'; ELSE RETURN 'f'; END IF;

Explanation: Example from PostgreSQL documentation on Plpgsql.


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

-- Use hand-rolled hash functions and operator classes to get predictable
-- result on different machines.  See the definitions of
-- part_test_int4_ops and part_test_text_ops in test_setup.sql.

CREATE TABLE mchash (a int, b text, c jsonb)
  PARTITION BY HASH (a part_test_int4_ops, b part_test_text_ops);

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


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

INSERT INTO fk_partitioned_fk (a,b) VALUES (1500, 1501);


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

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

SELECT count(*) FROM (select 1 ^ 'NaN'::numeric) AS _sub;


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

SELECT nextval('sequence_test_temp1');  -- ok
SELECT nextval('sequence_test2');  -- error
ROLLBACK;

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

SELECT count(*) FROM (SELECT nextval('sequence_test_temp1');  -- ok
SELECT nextval('sequence_test2');  -- error
ROLLBACK) AS _sub;


Question: Write the DML statement from PostgreSQL regression test 'predicate' (example 117).

INSERT INTO bool_tab VALUES (2, false, NULL);

Explanation: DML from PostgreSQL core regression test for Predicate.


Question: PostgreSQL Typeconv: show example 28.

SELECT NULL UNION SELECT NULL UNION SELECT 1; ERROR: UNION types text and integer cannot be matched;

Explanation: Example from PostgreSQL documentation on Typeconv.


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

SELECT server_name FROM postgres_fdw_get_connections() ORDER BY 1;

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


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

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

SELECT count(*) FROM (select jsonb_strip_nulls('null', true)) AS _sub;


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

create trigger table2_trig
  after insert on table2 referencing new table as new_table
  for each statement execute procedure dump_insert();

Explanation: DDL from PostgreSQL core regression test for Triggers.


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

UPDATE target SET balance = 0 WHERE tid = 3;

Explanation: DML from PostgreSQL core regression test for Merge.


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

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

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


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

ALTER EXTENSION pgtap ADD FUNCTION cmp_ok (anyelement, text, anyelement, text);

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


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

SELECT TRIM(LEADING FROM '  bunch o blanks  ') = 'bunch o blanks  ' AS "bunch o blanks  ";

SELECT count(*) FROM (SELECT TRIM(LEADING FROM '  bunch o blanks  ') = 'bunch o blanks  ' AS "bunch o blanks  ") AS _sub;


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

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

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


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

SELECT * FROM test_timestamp WHERE i>'4714-11-23 17:00 BC'::timestamptz ORDER BY i;

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


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

CREATE TABLE plt2_p2 PARTITION OF plt2 FOR VALUES IN ('0001', '0005', '0002', '0009');

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


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

CREATE TABLE notnull_child_upg () INHERITS (notnull_parent_upg);

Explanation: DDL from PostgreSQL core regression test for Constraints.


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

CREATE FUNCTION cursor_aborted_subxact() RETURNS int AS $$
try:
    with plpy.subtransaction():
        cur = plpy.cursor("select * from generate_series(1, 20) as gen(i)")
        cur.fetch(10);
        plpy.execute("select no_such_function()")
except plpy.SPIError:
    fetched = cur.fetch(10)
    return int(fetched[5]["i"])
return 0 # not reached
$$ LANGUAGE plpython3u;

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


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

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


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

SELECT pg_catalog.pg_clear_relation_stats(schemaname => 'stats_import', relname => 'testview');

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

SELECT count(*) FROM (SELECT pg_catalog.pg_clear_relation_stats(schemaname => 'stats_import', relname => 'testview')) AS _sub;


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

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


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

SELECT * FROM test_float4 WHERE i<='Inf'::float8 ORDER BY i;


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

SELECT count(*) FROM (SELECT jsonb_typeof('null') AS "null") AS _sub;


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

CREATE FUNCTION test_type_conversion_array_tuple() RETURNS text[] AS $$
return ('abc', 'def')
$$ LANGUAGE plpython3u;

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


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

create rule rtest_emp_ins as on insert to rtest_emp do
	insert into rtest_emplog values (new.ename, current_user,
			'hired', new.salary, '0.00');

Explanation: DDL from PostgreSQL core regression test for Rules.


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

Explanation: DML from PostgreSQL core regression test for Inherit.


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

CREATE INDEX es_idx_cake_brand on cake.brand
    USING zombodb ((brand.*))
    WITH (max_analyze_token_count='10000000', max_terms_count='2147483647');

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


Question: pgTAP test for Hastap (assertion 176).

SELECT * FROM check_test(
  has_operator( 'int4', 'pg_catalog', '<=', 'integer', 'boolean'::name ),
  true,
  'has_operator( left, schema, name, right, result )',
  'Operator pg_catalog.<=(int4,integer) RETURNS boolean should exist',
  ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs";

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

SELECT count(*) FROM (SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs") AS _sub;


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

SELECT 'init' FROM pg_create_physical_replication_slot('physical_slot');

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


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

INSERT INTO SUBSELECT_TBL VALUES (8, 9, NULL);

Explanation: DML from PostgreSQL core regression test for Subselect.


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

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


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

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

SELECT count(*) FROM (SELECT to_tsquery('english', '(asd&and)|fghj')) AS _sub;


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

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


Question: Show a SQL definition from the timescaledb project (size_utils, item 33).

CREATE OR REPLACE FUNCTION _timescaledb_functions.range_value_to_pretty(
    time_value      BIGINT,
    column_type     REGTYPE
)
    RETURNS TEXT LANGUAGE PLPGSQL STABLE AS
$BODY$
DECLARE
BEGIN
    IF NOT (time_value > (-9223372036854775808)::bigint AND
	   	    time_value < 9223372036854775807::bigint) THEN
        RETURN '';

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


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

CREATE TABLE owned_by_me (
	a int
) PARTITION BY LIST (a);

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


Question: pgTAP test for Index (assertion 67).

SELECT * FROM check_test(
    index_is_unique( 'blahblah' ),
    false,
    'index_is_unique() no such index',
    'Index blahblah should be unique',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Index.


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


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

CREATE TABLE bit_table (a BIT(16), b BIT(16));

Explanation: DDL from PostgreSQL core regression test for Bit.


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

SELECT * FROM return_record('999') AS r(val text, t integer);

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


Question: Show a SQL definition from the timescaledb project (hash, item 37).

-- Test hashing Var values
CREATE TABLE hash_test(id int, value text);


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

CREATE FUNCTION myvarcharin(cstring, oid, integer) RETURNS myvarchar
LANGUAGE internal IMMUTABLE PARALLEL SAFE STRICT AS 'varcharin';

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


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

CREATE FOREIGN DATA WRAPPER foo; -- ERROR
RESET ROLE;

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


Question: Write the DDL statement from PostgreSQL regression test 'eager_aggregate' (example 54).

CREATE TABLE eager_agg_tab2_p3 PARTITION OF eager_agg_tab2 FOR VALUES FROM (10) TO (15);

Explanation: DDL from PostgreSQL core regression test for Eager Aggregate.


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

select interval '2147483647 months 0.1 decades';

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

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


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

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

SELECT count(*) FROM (SELECT to_char(q2, 'L9999999999999999.000')  FROM INT8_TBL) AS _sub;


Question: Show a SQL definition from the timescaledb project (gapfill, item 3).

CREATE OR REPLACE FUNCTION @extschema@.time_bucket_gapfill(bucket_width BIGINT, ts BIGINT, start BIGINT=NULL, finish BIGINT=NULL) RETURNS BIGINT
	AS '@MODULE_PATHNAME@', 'ts_gapfill_int64_bucket' LANGUAGE C VOLATILE PARALLEL SAFE;


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

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

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


Question: Write the DDL statement from PostgreSQL regression test 'truncate' (example 147).

CREATE TABLE truncpart_2_d PARTITION OF truncpart_2 DEFAULT;

Explanation: DDL from PostgreSQL core regression test for Truncate.


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

create view view_of_joins_2d as select * from (tbl1 join tbl1a using (a) as x) as y;

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


Question: Write the DDL statement from PostgreSQL regression test 'sqljson' (example 177).

CREATE VIEW json_objectagg_view AS
SELECT JSON_OBJECTAGG(i: ('111' || i)::bytea FORMAT JSON WITH UNIQUE RETURNING text) FILTER (WHERE i > 3)
FROM generate_series(1,5) i;

Explanation: DDL from PostgreSQL core regression test for Sqljson.


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

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

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


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

SELECT proname, prosecdef FROM pg_proc
       WHERE oid in ('functest_C_1'::regproc,
                     'functest_C_2'::regproc,
                     'functest_C_3'::regproc) ORDER BY proname;

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

SELECT count(*) FROM (SELECT proname, prosecdef FROM pg_proc
       WHERE oid in ('functest_C_1'::regproc,
                     'functest_C_2'::regproc,
                     'functest_C_3'::regproc) ORDER BY proname) AS _sub;


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

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

SELECT count(*) FROM (SELECT xml_is_well_formed('<foo>bar</foo>')) AS _sub;


Question: Show a SQL definition from the timescaledb project (maintenance_utils, item 3).

CREATE OR REPLACE FUNCTION _timescaledb_functions.create_compressed_chunk(
    chunk REGCLASS,
    chunk_table REGCLASS,
    uncompressed_heap_size BIGINT,
    uncompressed_toast_size BIGINT,
    uncompressed_index_size BIGINT,
    compressed_heap_size BIGINT,
    compressed_toast_size BIGINT,
    compressed_index_size BIGINT,
    numrows_pre_compression BIGINT,
    numrows_post_compression BIGINT
) RETURNS REGCLASS AS '@MODULE_PATHNAME@', 'ts_create_compressed_chunk' LANGUAGE C STRICT VOLATILE;

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


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

SELECT point(f1) AS center
   FROM CIRCLE_TBL;

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

SELECT count(*) FROM (SELECT point(f1) AS center
   FROM CIRCLE_TBL) AS _sub;


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

INSERT INTO tr_sub(path) VALUES ('1-top-1-#1');

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


Question: pgTAP test for Functap (assertion 64).

SELECT * FROM check_test(
    function_lang_is( 'someschema', 'huh', 'sql', 'whatever' ),
    true,
    'function_lang_is(schema, func, sql, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Functap.


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

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


Question: Write the DDL statement from PostgreSQL regression test 'insert_conflict' (example 267).

create table parted_conflict_1 partition of parted_conflict for values from (0) to (1000) partition by range (a);

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


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

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

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


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

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


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

SELECT count(*) FROM (select interval '9223372036854.775807 seconds') AS _sub;


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

select 'aa=>b, c=>d , b=>16'::hstore->'aa';


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

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


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

ALTER EXTENSION pgtap ADD FUNCTION throws_ok ( TEXT, CHAR(5), TEXT, TEXT );

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


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

INSERT INTO fract_only VALUES (3, '1.0');	-- should fail
INSERT INTO fract_only VALUES (4, '-0.9999');

Explanation: DML from PostgreSQL core regression test for Numeric.


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

INSERT INTO d_star (class, a, c, d)
   VALUES ('d', 10, 'hi kristin'::name, '10.01'::float8);

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


Question: pgTAP test for Hastap (assertion 63).

SELECT * FROM check_test(
    has_sequence( 'foo', '__SDFSDFD__', 'desc' ),
    false,
    'has_sequence(sch, non-existent sequence, desc)',
    'desc',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Hastap.


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

SELECT count(*) from more__int WHERE a = '{73,23,20}';

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


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

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

SELECT count(*) FROM (SELECT factorial(0)) AS _sub;


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

CREATE OR REPLACE FUNCTION _ikeys( NAME, NAME, NAME)
RETURNS TEXT[] AS $$
    SELECT ARRAY(
        SELECT pg_catalog.pg_get_indexdef( ci.oid, s.i + 1, false)
          FROM pg_catalog.pg_index x
          JOIN pg_catalog.pg_class ct    ON ct.oid = x.indrelid
          JOIN pg_catalog.pg_class ci    ON ci.oid = x.indexrelid
          JOIN pg_catalog.pg_namespace n ON n.oid = ct.relnamespace
          JOIN generate_series(0, current_setting('max_index_keys')::int - 1) s(i)
            ON x.indkey[s.i] IS NOT NULL
         WHERE ct.relname = $2
           AND ci.relname = $3
           AND n.nspname  = $1
         ORDER BY s.i
    );
$$ LANGUAGE sql;

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


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

SELECT pubname, puballtables, puballsequences FROM pg_publication WHERE pubname = 'regress_pub_forallsequences1';

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

SELECT count(*) FROM (SELECT pubname, puballtables, puballsequences FROM pg_publication WHERE pubname = 'regress_pub_forallsequences1') AS _sub;


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

CREATE OPERATOR < (
        LEFTARG = ltree,
	RIGHTARG = ltree,
	PROCEDURE = ltree_lt,
        COMMUTATOR = '>',
	NEGATOR = '>=',
        RESTRICT = contsel,
	JOIN = contjoinsel
);

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


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

SELECT set_byte('\x1234567890abcdef00'::bytea, 99, 11);  -- error

--
-- conversions between bytea and integer types
--
SELECT 0x1234::int2::bytea AS "\x1234", (-0x1234)::int2::bytea AS "\xedcc";

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

SELECT count(*) FROM (SELECT set_byte('\x1234567890abcdef00'::bytea, 99, 11);  -- error

--
-- conversions between bytea and integer types
--
SELECT 0x1234::int2::bytea AS "\x1234", (-0x1234)::int2::bytea AS "\xedcc") AS _sub;


Question: pgTAP test for Ownership (assertion 31).

/****************************************************************************/
-- Test relation_owner_is() with a partition.
SELECT * FROM check_test(
    relation_owner_is('public', 'apart', current_user, 'mumble'),
	true,
    'relation_owner_is(sch, part, user, desc)',
    'mumble',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Ownership.


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

insert into part_default_p2 values ('de', 35);

Explanation: DML from PostgreSQL core regression test for Insert.


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

SELECT count(*) FROM point_tbl WHERE f1 <@ circle '<(50,50),50>';

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

SELECT count(*) FROM (SELECT count(*) FROM point_tbl WHERE f1 <@ circle '<(50,50),50>') AS _sub;


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

SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');

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


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

insert into insertconflicttest as t values (23, 'Blackberry') on conflict (key) where fruit like '%berry' and t.fruit = 'inconsequential' do nothing;

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


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

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


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

-- ensure dependencies are straight
DROP FUNCTION myvarcharsend(myvarchar);  -- fail
DROP TYPE myvarchar;  -- fail

DROP TYPE myvarchar CASCADE;

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


Question: Write the DDL statement from PostgreSQL regression test 'window' (example 292).

CREATE INDEX empsalary_salary_empno_idx ON empsalary (salary, empno);

Explanation: DDL from PostgreSQL core regression test for Window.


Question: Show a SQL definition from the timescaledb project (compat, item 28).

CREATE OR REPLACE FUNCTION _timescaledb_internal.policy_job_stat_history_retention_check(config jsonb) RETURNS void LANGUAGE PLPGSQL AS $$
BEGIN
  IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN
    RAISE WARNING 'function _timescaledb_internal.policy_job_stat_history_retention_check(jsonb) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';
  END IF;
  PERFORM _timescaledb_functions.policy_job_stat_history_retention_check($1);
END$$
SET search_path TO pg_catalog,pg_temp;

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


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

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


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

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

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


Question: Write the DDL statement from PostgreSQL regression test 'temp' (example 98).

create temp table temp_parted_oncommit_test2
  partition of temp_parted_oncommit_test
  for values in (2) on commit drop;

Explanation: DDL from PostgreSQL core regression test for Temp.


Question: pgTAP test for Resultset (assertion 281).

INSERT INTO dupes (id, name) VALUES(86, 'Angelina');

Explanation: SQL assertion from pgTAP test suite for Resultset.


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

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

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

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


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


Question: pgTAP test for Hastap (assertion 254).

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

Explanation: SQL assertion from pgTAP test suite for Hastap.


Question: pgTAP test for Index (assertion 53).

SELECT * FROM check_test(
    hasnt_index( 'sometab', 'idx_blah', 'whatever' ),
    true,
    'hasnt_index(table, non-index, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Index.


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

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


Question: PL/pgSQL test: Plperl Util (example 11).

-- test encode_array_literal

create or replace function perl_encode_array_literal() returns setof text language plperl as $$
	return_next encode_array_literal(undef);
	return_next encode_array_literal(0);
	return_next encode_array_literal(42);
	return_next encode_array_literal($_)
		for [], [0], [1..5], [[]], [[1,2,[3]],4];
	return_next encode_array_literal($_,'|')
		for [], [0], [1..5], [[]], [[1,2,[3]],4];
	return undef;
$$;

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


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

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


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

SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false";

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

SELECT count(*) FROM (SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false") AS _sub;


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

Explanation: DML from PostgreSQL core regression test for Domain.


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

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

SELECT count(*) FROM (SELECT 'NaN'::numeric::float4) AS _sub;


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

SELECT * FROM pg_input_error_info('[{"attributes_invalid" : [2,3], "ndistinct" : 4}]', 'pg_ndistinct');

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

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


Question: pgTAP test for Resultset (assertion 169).

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


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

SELECT * FROM sj j1, sj j2
WHERE j1.b = j2.b
  AND (j1.a*j1.c/3) = (random()/3 + 3)::int
  AND (random()/3 + 3)::int = (j2.a*j2.c/3);

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

SELECT count(*) FROM (SELECT * FROM sj j1, sj j2
WHERE j1.b = j2.b
  AND (j1.a*j1.c/3) = (random()/3 + 3)::int
  AND (random()/3 + 3)::int = (j2.a*j2.c/3)) AS _sub;


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

update utrtest set b = b || b from (values (1), (2)) s(x) where a = s.x
  returning *, tableoid::regclass, xmin = pg_current_xact_id()::xid as xmin_ok;

Explanation: DML from PostgreSQL core regression test for Update.


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

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

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


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

-- Sanity check on the previous table, checking that all core types are
-- included in this table.
SELECT oid, typname, typtype, typelem, typarray
  FROM pg_type t
  WHERE oid < 16384 AND
    -- Exclude pseudotypes and composite types.
    typtype NOT IN ('p', 'c') AND
    -- These reg* types cannot be pg_upgraded, so discard them.
    oid != ALL(ARRAY['regproc', 'regprocedure', 'regoper',
                     'regoperator', 'regconfig', 'regdictionary',
                     'regnamespace', 'regcollation']::regtype[]) AND
    -- Discard types that do not accept input values as these cannot be
    -- tested easily.
    -- Note: XML might be disabled at compile-time.
    oid != ALL(ARRAY['gtsvector', 'pg_node_tree',
                     'pg_ndistinct', 'pg_dependencies', 'pg_mcv_list',
                     'pg_brin_bloom_summary',
                     'pg_brin_minmax_multi_summary', 'xml']::regtype[]) AND
    -- Discard arrays.
    NOT EXISTS (SELECT 1 FROM pg_type u WHERE u.typarray = t.oid)
    -- Exclude everything from the table created above.  This checks
    -- that no in-core types are missing in tab_core_types.
    AND NOT EXISTS (SELECT 1
                    FROM pg_attribute a
                    WHERE a.atttypid=t.oid AND
                          a.attnum > 0 AND
                          a.attrelid='tab_core_types'::regclass);

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


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

CREATE OR REPLACE FUNCTION zdb.auto_date_histogram_agg(aggregate_name text, field text, buckets int8, format text DEFAULT NULL, minimum_interval zdb.intervals DEFAULT NULL, missing text DEFAULT NULL) RETURNS jsonb AS 'MODULE_PATHNAME', 'auto_date_histogram_agg_wrapper' IMMUTABLE LANGUAGE c PARALLEL SAFE;

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


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

CREATE TABLE encoding_tests (encoding text, description text, input bytea);

Explanation: DDL from PostgreSQL core regression test for Encoding.


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

CREATE TABLE quuux_default PARTITION OF quuux DEFAULT PARTITION BY LIST (b);

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


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

PREPARE fooplan (int, text, bool, numeric) AS INSERT INTO foo VALUES($1, $2, $3, $4); EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00);

Explanation: PostgreSQL PREPARE command.


Question: pgTAP test for Ruletap (assertion 36).

SELECT * FROM check_test(
    rule_is_on( 'public', 'sometab', 'upd_me', 'update', 'whatever' ),
    true,
    'rule_is_on(schema, table, rule, update, desc)',
    'whatever',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Ruletap.


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

SELECT tableoid::regclass, * FROM ONLY a;

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


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

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


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

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


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

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

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


Question: Show a SQL definition from the timescaledb project (ddl_api, item 7).

-- Drop chunks older than the given timestamp for the specific
-- hypertable or continuous aggregate.
CREATE OR REPLACE FUNCTION @extschema@.drop_chunks(
    relation               REGCLASS,
    older_than             "any" = NULL,
    newer_than             "any" = NULL,
    verbose                BOOLEAN = FALSE,
    created_before         "any" = NULL,
    created_after          "any" = NULL
) RETURNS SETOF TEXT AS '@MODULE_PATHNAME@', 'ts_chunk_drop_chunks'
LANGUAGE C VOLATILE PARALLEL UNSAFE;

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


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

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


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

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

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

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


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

CREATE TABLE shoelace_data (
	sl_name    char(10),      -- primary key
	sl_avail   integer,       -- available # of pairs
	sl_color   char(10),      -- shoelace color
	sl_len     float,         -- shoelace length
	sl_unit    char(8)        -- length unit
);

Explanation: DDL from PostgreSQL core regression test for Rules.


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

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

SELECT count(*) FROM (select jsonb '[1]' @? '$[0.5]') AS _sub;


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

SELECT count(*) FILTER (WHERE r < -1.5 OR r > 1.5) AS out_of_range,
       (count(*) FILTER (WHERE r < -1.47)) > 0 AS has_small,
       (count(*) FILTER (WHERE r > 1.47)) > 0 AS has_large
FROM (SELECT random(-1.500000000000000, 1.500000000000000) r
      FROM generate_series(1, 2000)) ss;

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

SELECT count(*) FROM (SELECT count(*) FILTER (WHERE r < -1.5 OR r > 1.5) AS out_of_range,
       (count(*) FILTER (WHERE r < -1.47)) > 0 AS has_small,
       (count(*) FILTER (WHERE r > 1.47)) > 0 AS has_large
FROM (SELECT random(-1.500000000000000, 1.500000000000000) r
      FROM generate_series(1, 2000)) ss) AS _sub;


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

insert into cities values ('Las Vegas', 2.583E+5, 2174);

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


Question: PostgreSQL regression test 'brin_multi': Write the SELECT query (example 99).

SELECT COUNT(*) FROM brin_test_multi_1 WHERE a > 71;

Explanation: Regression test for Brin Multi in PostgreSQL core test suite.

SELECT count(*) FROM (SELECT COUNT(*) FROM brin_test_multi_1 WHERE a > 71) AS _sub;


Question: PostgreSQL Ddl: show example 106.

CREATE INDEX measurement_y2006m02_logdate ON measurement_y2006m02 (logdate); CREATE INDEX measurement_y2006m03_logdate ON measurement_y2006m03 (logdate); CREATE INDEX measurement_y2007m11_logdate ON measurement_y2007m11 (logdate); CREATE INDEX measurement_y2007m12_logdate ON measurement_y2007m12 (logdate); CREATE INDEX measurement_y2008m01_logdate ON measurement_y2008m01 (logdate);

Explanation: Example from PostgreSQL documentation on Ddl.


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

SELECT ctid FROM tidrangescan WHERE ctid > '(2,8)';

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

SELECT count(*) FROM (SELECT ctid FROM tidrangescan WHERE ctid > '(2,8)') AS _sub;


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

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


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

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


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

CREATE OPERATOR @@ (
	LEFTARG = _int4,
	RIGHTARG = query_int,
	PROCEDURE = boolop,
	COMMUTATOR = '~~',
	RESTRICT = _int_matchsel,
	JOIN = contjoinsel
);

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


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

select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss;

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

SELECT count(*) FROM (select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss) AS _sub;


Question: pgTAP test for Unique (assertion 25).

SELECT * FROM check_test(
    col_is_unique( 'argh', ARRAY['id', 'name'], 'id + name should be unique' ),
    true,
    'col_is_unique( table, column[], description )',
    'id + name should be unique',
    ''
);

Explanation: SQL assertion from pgTAP test suite for Unique.


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

SELECT cube_ll_coord(earth_box(ll_to_earth(0,0),10*earth()),1)::numeric(20,5),
       cube_ll_coord(earth_box(ll_to_earth(0,0),10*earth()),2)::numeric(20,5),
       cube_ll_coord(earth_box(ll_to_earth(0,0),10*earth()),3)::numeric(20,5),
       cube_ur_coord(earth_box(ll_to_earth(0,0),10*earth()),1)::numeric(20,5),
       cube_ur_coord(earth_box(ll_to_earth(0,0),10*earth()),2)::numeric(20,5),
       cube_ur_coord(earth_box(ll_to_earth(0,0),10*earth()),3)::numeric(20,5);

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