{"question": "Write the DDL statement from PostgreSQL regression test 'update' (example 214).", "schema": null, "sql": "CREATE TABLE list_parted (\n\ta text,\n\tb int\n) PARTITION BY list (a);", "explanation": "DDL from PostgreSQL core regression test for Update.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 67, "num_statements": 1} {"question": "pgTAP test for Hastap (assertion 40).", "schema": null, "sql": "SELECT * FROM check_test(\n hasnt_table( '__SDFSDFD__', 'lol'::name ),\n true,\n 'hasnt_table(non-existent schema, tab)',\n 'Table \"__SDFSDFD__\".lol should not exist',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Hastap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 185, "num_statements": 1} {"question": "PostgreSQL regression test 'xml': Write the SELECT query (example 186).", "schema": null, "sql": "SELECT COUNT(id) FROM xmltest, query WHERE xmlexists(expr PASSING BY REF data);", "explanation": "Regression test for Xml in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT COUNT(id) FROM xmltest, query WHERE xmlexists(expr PASSING BY REF data)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 79, "num_statements": 1} {"question": "PostgreSQL regression test 'float4': Write the SELECT query (example 35).", "schema": null, "sql": "SELECT ' -INFINiTY '::float4;", "explanation": "Regression test for Float4 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT ' -INFINiTY '::float4) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 40, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'incremental_sort' (example 124).", "schema": null, "sql": "insert into prt_tbl select i%200, i from generate_series(1,1000)i;", "explanation": "DML from PostgreSQL core regression test for Incremental Sort.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 66, "num_statements": 1} {"question": "PostgreSQL regression test 'privileges': Write the SELECT query (example 152).", "schema": null, "sql": "SELECT * FROM atest2 WHERE ( col1 IN ( SELECT b FROM atest1 ) );", "explanation": "Regression test for Privileges in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM atest2 WHERE ( col1 IN ( SELECT b FROM atest1 ) )) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 64, "num_statements": 1} {"question": "PL/pgSQL test: Plpgsql Domain (example 31).", "schema": null, "sql": "SELECT * FROM test_argresult_array_domain(ARRAY[0, 100]::ordered_pair_domain);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpgsql Domain.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 78, "num_statements": 1} {"question": "PostgreSQL regression test 'foreign_key': Write the SELECT query (example 505).", "schema": null, "sql": "select conname from pg_constraint where conrelid = 'fktable2'::regclass order by conname;", "explanation": "Regression test for Foreign Key in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select conname from pg_constraint where conrelid = 'fktable2'::regclass order by conname) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 89, "num_statements": 1} {"question": "PL/pgSQL test: Pltcl Setup (example 4).", "schema": null, "sql": "create function tcl_argisnull(text) returns bool as '\n argisnull 1\n' language pltcl;", "explanation": "PL/pgSQL example from PostgreSQL source test for Pltcl Setup.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 87, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'sequence' (example 38).", "schema": null, "sql": "INSERT INTO serialTest2 (f1, f6)\n VALUES ('bogus', -9223372036854775809);", "explanation": "DML from PostgreSQL core regression test for Sequence.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 74, "num_statements": 1} {"question": "pgTAP test for Resultset (assertion 93).", "schema": null, "sql": "INSERT INTO names (name) VALUES ('Makayla');", "explanation": "SQL assertion from pgTAP test suite for Resultset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "PostgreSQL regression test 'horology': Write the SELECT query (example 364).", "schema": null, "sql": "SELECT to_date('-100000000', 'CC');", "explanation": "Regression test for Horology in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT to_date('-100000000', 'CC')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'sequence' (example 4).", "schema": null, "sql": "CREATE SEQUENCE sequence_testx INCREMENT BY -1 START 10;", "explanation": "DDL from PostgreSQL core regression test for Sequence.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 56, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'create_misc' (example 19).", "schema": null, "sql": "INSERT INTO d_star (class, a, b, c)\n VALUES ('d', 8, 'stumble'::text, 'hi koko'::name);", "explanation": "DML from PostgreSQL core regression test for Create Misc.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 89, "num_statements": 1} {"question": "PostgreSQL regression test 'errors': Write the SELECT query (example 10).", "schema": null, "sql": "select null from pg_database group by grouping sets (()) for update;", "explanation": "Regression test for Errors in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select null from pg_database group by grouping sets (()) for update) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_aggregation", "is_postgresql_specific": true, "sql_length": 68, "num_statements": 1} {"question": "pgTAP test for Aretap (assertion 108).", "schema": null, "sql": "SELECT * FROM check_test(\n languages_are( array_append(___mylangs(''), 'plomgwtf'), 'whatever' ),\n false,\n 'languages_are(languages, desc) missing',\n 'whatever',\n ' Missing languages:\n plomgwtf'\n);", "explanation": "SQL assertion from pgTAP test suite for Aretap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 222, "num_statements": 1} {"question": "PL/pgSQL test: Plpgsql Simple (example 5).", "schema": null, "sql": "create function simple1.simpletarget(int) returns int language plpgsql\nas $$begin return $1; end$$;\n\ncreate function simpletarget(int) returns int language plpgsql\nas $$begin return $1 + 100; end$$;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpgsql Simple.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 198, "num_statements": 4} {"question": "PostgreSQL regression test 'rowsecurity': Write the SELECT query (example 830).", "schema": null, "sql": "SELECT attname, most_common_vals FROM pg_stats\n WHERE tablename = 'current_check'\n ORDER BY 1;", "explanation": "Regression test for Rowsecurity in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT attname, most_common_vals FROM pg_stats\n WHERE tablename = 'current_check'\n ORDER BY 1) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 96, "num_statements": 1} {"question": "PostgreSQL regression test 'arrays': Write the SELECT query (example 327).", "schema": null, "sql": "select array_fill('juhu'::text, array[3,3]);", "explanation": "Regression test for Arrays in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select array_fill('juhu'::text, array[3,3])) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 44, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'timestamptz' (example 38).", "schema": null, "sql": "INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997-02-10 17:32:01-08');", "explanation": "DML from PostgreSQL core regression test for Timestamptz.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 62, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'ltree' (example 195).", "schema": null, "sql": "SELECT 'a.b.c.d.e'::ltree ~ 'a{,}.!a{,}';", "explanation": "Example query from the 'ltree' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 41, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'triggers' (example 49).", "schema": null, "sql": "begin\n\tnew.description = 'updated in trigger';", "explanation": "PL/pgSQL object from PostgreSQL core test for Triggers.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 46, "num_statements": 1} {"question": "PostgreSQL regression test 'int8': Write the SELECT query (example 139).", "schema": null, "sql": "SELECT (-9223372036854775808)::int8 / (-1)::int2;", "explanation": "Regression test for Int8 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT (-9223372036854775808)::int8 / (-1)::int2) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 193).", "schema": null, "sql": "SELECT JSON_QUERY(jsonb 'null', '$ts' PASSING timestamptz '2018-02-21 12:34:56 +10' AS ts RETURNING json);", "explanation": "Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_QUERY(jsonb 'null', '$ts' PASSING timestamptz '2018-02-21 12:34:56 +10' AS ts RETURNING json)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 106, "num_statements": 1} {"question": "pgTAP test for Functap (assertion 275).", "schema": null, "sql": "SELECT * FROM check_test(\n isnt_window( 'pg_catalog', 'dense_rank', '{}'::name[] ),\n false,\n 'isnt_window(schema, win, noargs)',\n 'Function pg_catalog.dense_rank() should not be a window function',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": true, "sql_length": 219, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'constraints' (example 199).", "schema": null, "sql": "CREATE TABLE parted_uniq_tbl_2 PARTITION OF parted_uniq_tbl FOR VALUES FROM (20) TO (30);", "explanation": "DDL from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 89, "num_statements": 1} {"question": "pgTAP test for Aretap (assertion 122).", "schema": null, "sql": "SELECT * FROM check_test(\n rules_are( 'public', 'fou', ARRAY['ins_me', 'upd_me'] ),\n true,\n 'rules_are(schema, table, rules)',\n 'Relation public.fou should have the correct rules',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Aretap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 202, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 741).", "schema": null, "sql": "select jsonb_path_query_tz(\n\t'[\"2017-03-10 12:34:00\", \"2017-03-10 12:35:00\", \"2017-03-10 12:36:00\", \"2017-03-10 12:35:00+01\", \"2017-03-10 13:35:00+01\", \"2017-03-10 12:35:00-01\", \"2017-03-10\", \"2017-03-11\", \"12:34:56\", \"12:34:56+01\"]',\n\t'$[*].datetime() ? (@ >= \"10.03.2017 12:35\".datetime(\"dd.mm.yyyy HH24:MI\"))');", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb_path_query_tz(\n\t'[\"2017-03-10 12:34:00\", \"2017-03-10 12:35:00\", \"2017-03-10 12:36:00\", \"2017-03-10 12:35:00+01\", \"2017-03-10 13:35:00+01\", \"2017-03-10 12:35:00-01\", \"2017-03-10\", \"2017-03-11\", \"12:34:56\", \"12:34:56+01\"]',\n\t'$[*].datetime() ? (@ >= \"10.03.2017 12:35\".datetime(\"dd.mm.yyyy HH24:MI\"))')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": false, "sql_length": 314, "num_statements": 1} {"question": "PostgreSQL regression test 'subselect': Write the SELECT query (example 9).", "schema": null, "sql": "SELECT ((SELECT 2) UNION SELECT 2);", "explanation": "Regression test for Subselect in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT ((SELECT 2) UNION SELECT 2)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 132).", "schema": null, "sql": "-- Create the operator class\nCREATE OPERATOR CLASS gist_time_ops\nDEFAULT FOR TYPE time USING gist\nAS\n\tOPERATOR\t1\t< ,\n\tOPERATOR\t2\t<= ,\n\tOPERATOR\t3\t= ,\n\tOPERATOR\t4\t>= ,\n\tOPERATOR\t5\t> ,\n\tOPERATOR\t6\t<> ,\n\tOPERATOR\t15\t<-> FOR ORDER BY pg_catalog.interval_ops ,\n\tFUNCTION\t1\tgbt_time_consistent (internal, time, int2, oid, internal),\n\tFUNCTION\t2\tgbt_time_union (internal, internal),\n\tFUNCTION\t3\tgbt_time_compress (internal),\n\tFUNCTION\t4\tgbt_decompress (internal),\n\tFUNCTION\t5\tgbt_time_penalty (internal, internal, internal),\n\tFUNCTION\t6\tgbt_time_picksplit (internal, internal),\n\tFUNCTION\t7\tgbt_time_same (gbtreekey16, gbtreekey16, internal),\n\tFUNCTION\t8\tgbt_time_distance (internal, time, int2, oid, internal),\n\tFUNCTION\t9\tgbt_time_fetch (internal),\n\tFUNCTION\t11\tgbt_time_sortsupport (internal),\n\tFUNCTION\t12 (\"any\", \"any\") gist_translate_cmptype_btree (int),\n\tSTORAGE\t\tgbtreekey16;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 878, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'without_overlaps' (example 392).", "schema": null, "sql": "CREATE TABLE temporal_rng2 (\n id1 int4range,\n id2 int4range,\n valid_at daterange,\n CONSTRAINT temporal_rng2_pk PRIMARY KEY (id1, id2, valid_at WITHOUT OVERLAPS)\n);", "explanation": "DDL from PostgreSQL core regression test for Without Overlaps.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 167, "num_statements": 1} {"question": "PostgreSQL regression test 'tstypes': Write the SELECT query (example 138).", "schema": null, "sql": "SELECT ts_rank_cd(' a:1 s:2B d g'::tsvector, 'a & s');", "explanation": "Regression test for Tstypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT ts_rank_cd(' a:1 s:2B d g'::tsvector, 'a & s')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 54, "num_statements": 1} {"question": "PostgreSQL regression test 'stats': Write the SELECT query (example 248).", "schema": null, "sql": "SELECT wal_bytes > :wal_bytes_before FROM pg_stat_wal;", "explanation": "Regression test for Stats in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT wal_bytes > :wal_bytes_before FROM pg_stat_wal) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "PostgreSQL regression test 'polymorphism': Write the SELECT query (example 204).", "schema": null, "sql": "select formarray(1.1, variadic array[1.2,55.5]);", "explanation": "Regression test for Polymorphism in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select formarray(1.1, variadic array[1.2,55.5])) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 48, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'indexing' (example 459).", "schema": null, "sql": "create table pk51 partition of pk5 for values from (4000) to (4500);", "explanation": "DDL from PostgreSQL core regression test for Indexing.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 68, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'drop_if_exists' (example 68).", "schema": null, "sql": "DROP FUNCTION IF EXISTS test_function_exists(int, text, int[]);", "explanation": "PL/pgSQL object from PostgreSQL core test for Drop If Exists.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "other", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "pgTAP test for Ownership (assertion 59).", "schema": null, "sql": "SELECT * FROM check_test(\n view_owner_is('public', '__not__someview', current_user, 'mumble'),\n\tfalse,\n 'view_owner_is(sch, non-view, user)',\n 'mumble',\n ' View public.__not__someview does not exist'\n);", "explanation": "SQL assertion from pgTAP test suite for Ownership.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 217, "num_statements": 1} {"question": "Show a SQL definition from the zombodb project (_mappings, item 6).", "schema": null, "sql": "CREATE TABLE zdb.type_mappings\n(\n type_name regtype NOT NULL PRIMARY KEY,\n definition jsonb DEFAULT NULL,\n is_default boolean DEFAULT false NOT NULL,\n funcid regproc DEFAULT null\n);", "explanation": "SQL definition from the open-source zombodb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 214, "num_statements": 1} {"question": "PostgreSQL regression test 'truncate': Write the SELECT query (example 151).", "schema": null, "sql": "select tp_ins_data();", "explanation": "Regression test for Truncate in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select tp_ins_data()) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 21, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 204).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (4,8,'7874342.4119');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 52, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'earthdistance' (example 18).", "schema": null, "sql": "SELECT gc_to_sec(1000)::numeric(20,5);", "explanation": "Example query from the 'earthdistance' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 38, "num_statements": 1} {"question": "pgTAP test for Hastap (assertion 207).", "schema": null, "sql": "SELECT * FROM check_test(\n has_leftop( '+', 'text', 'inte', 'desc' ),\n false,\n 'has_leftop( name, right, result, desc ) fail',\n 'desc',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Hastap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 147, "num_statements": 1} {"question": "PostgreSQL regression test 'tstypes': Write the SELECT query (example 188).", "schema": null, "sql": "SELECT setweight('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567'::tsvector, 'c');", "explanation": "Regression test for Tstypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT setweight('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567'::tsvector, 'c')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 79, "num_statements": 1} {"question": "PostgreSQL regression test 'name': Write the SELECT query (example 19).", "schema": null, "sql": "SELECT c.f1 FROM NAME_TBL c WHERE c.f1 !~ '.*';", "explanation": "Regression test for Name in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT c.f1 FROM NAME_TBL c WHERE c.f1 !~ '.*') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 47, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_merge' (example 118).", "schema": null, "sql": "CREATE TABLE sales_apr2022_10_20 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-10') TO ('2022-04-20');", "explanation": "DDL from PostgreSQL core regression test for Partition Merge.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 109, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gin' (example 3).", "schema": null, "sql": "INSERT INTO test_timestamptz VALUES\n\t( '2004-10-26 03:55:08' ),\n\t( '2004-10-26 04:55:08' ),\n\t( '2004-10-26 05:55:08' ),\n\t( '2004-10-26 08:55:08' ),\n\t( '2004-10-27 09:55:08' ),\n\t( '2004-10-27 10:55:08' )\n;", "explanation": "Example query from the 'btree_gin' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 204, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 1).", "schema": null, "sql": "/* contrib/btree_gin/btree_gin--1.0.sql */\n\n-- complain if script is sourced in psql, rather than via CREATE EXTENSION\n\\echo Use \"CREATE EXTENSION btree_gin\" to load this file. \\quit\n\nCREATE FUNCTION gin_btree_consistent(internal, int2, anyelement, int4, internal, internal)\nRETURNS bool\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT IMMUTABLE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 337, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 165).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION _ckeys ( NAME, CHAR );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 57, "num_statements": 1} {"question": "PostgreSQL regression test 'stats': Write the SELECT query (example 381).", "schema": null, "sql": "SELECT sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + sum(writes) + sum(writebacks) + sum(hits) AS my_io_stats_post_reset\n FROM pg_stat_get_backend_io(pg_backend_pid()) \\gset\n-- pg_stat_reset_shared() did not reset backend IO stats\nSELECT :my_io_stats_pre_reset <= :my_io_stats_post_reset;", "explanation": "Regression test for Stats in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + sum(writes) + sum(writebacks) + sum(hits) AS my_io_stats_post_reset\n FROM pg_stat_get_backend_io(pg_backend_pid()) \\gset\n-- pg_stat_reset_shared() did not reset backend IO stats\nSELECT :my_io_stats_pre_reset <= :my_io_stats_post_reset) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 316, "num_statements": 1} {"question": "PostgreSQL regression test 'money': Write the SELECT query (example 90).", "schema": null, "sql": "SELECT (-12345678901234567)::money;", "explanation": "Regression test for Money in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT (-12345678901234567)::money) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'constraints' (example 379).", "schema": null, "sql": "CREATE TABLE notnull_tbl4_cld () INHERITS (notnull_tbl4);", "explanation": "DDL from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 57, "num_statements": 1} {"question": "PostgreSQL regression test 'pg_ndistinct': Write the SELECT query (example 18).", "schema": null, "sql": "SELECT * FROM pg_input_error_info('[{\"attributes\" : [2,3], \"ndistinct\" : 4, \"ndistinct\" : 4}]', 'pg_ndistinct');", "explanation": "Regression test for Pg Ndistinct in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM pg_input_error_info('[{\"attributes\" : [2,3], \"ndistinct\" : 4, \"ndistinct\" : 4}]', 'pg_ndistinct')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 112, "num_statements": 1} {"question": "PostgreSQL regression test 'arrays': Write the SELECT query (example 435).", "schema": null, "sql": "select unnest('11 22 33'::oidvector);", "explanation": "Regression test for Arrays in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select unnest('11 22 33'::oidvector)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 37, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'intarray' (example 24).", "schema": null, "sql": "SELECT '{123,623,445}'::int[] | '{1623,623}';", "explanation": "Example query from the 'intarray' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 45, "num_statements": 1} {"question": "PostgreSQL Plpgsql: show example 48.", "schema": null, "sql": "DECLARE curs1 refcursor; curs2 CURSOR FOR SELECT * FROM tenk1; curs3 CURSOR (key integer) FOR SELECT * FROM tenk1 WHERE unique1 = key;", "explanation": "Example from PostgreSQL documentation on Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "plpgsql", "is_postgresql_specific": false, "sql_length": 134, "num_statements": 3} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'plpgsql' (example 680).", "schema": null, "sql": "drop function inner_func(int);", "explanation": "PL/pgSQL object from PostgreSQL core test for Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 30, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 806).", "schema": null, "sql": "select ('{\"a\": 1, \"b\": \"c\", \"d\": [1, 2, 3]}'::jsonb)['d'];", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select ('{\"a\": 1, \"b\": \"c\", \"d\": [1, 2, 3]}'::jsonb)['d']) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 58, "num_statements": 1} {"question": "pgTAP test for Index (assertion 109).", "schema": null, "sql": "SELECT * FROM check_test(\n is_indexed( 'public', 'sometab'::name, 'myint'::name ),\n false,\n 'is_indexed( schema, table, column ) fail',\n 'Should have an index on public.sometab(myint)',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Index.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 207, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 486).", "schema": null, "sql": "select jsonb_path_query('[]', '$.number()');", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb_path_query('[]', '$.number()')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 1).", "schema": null, "sql": "/* contrib/ltree/ltree--1.1.sql */\n\n-- complain if script is sourced in psql, rather than via CREATE EXTENSION\n\\echo Use \"CREATE EXTENSION ltree\" to load this file. \\quit\n\nCREATE FUNCTION ltree_in(cstring)\nRETURNS ltree\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 283, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'stats_ext' (example 525).", "schema": null, "sql": "CREATE STATISTICS mcv_lists_stats_3 ON (mod(c,5)) FROM mcv_lists;", "explanation": "DDL from PostgreSQL core regression test for Stats Ext.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 361).", "schema": null, "sql": "INSERT INTO num_exp_sub VALUES (8,7,'83103366');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 48, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 22).", "schema": null, "sql": "SELECT test_json ->> 'field4' FROM test_jsonb WHERE json_type = 'object';", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT test_json ->> 'field4' FROM test_jsonb WHERE json_type = 'object') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 73, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'intarray' (example 66).", "schema": null, "sql": "SELECT '1&(2&(4&(5|6)))'::query_int;", "explanation": "Example query from the 'intarray' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 36, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 191).", "schema": null, "sql": "CREATE FUNCTION isnle(upc, upc)\n\tRETURNS boolean\n\tAS 'int8le'\n\tLANGUAGE 'internal'\n\tIMMUTABLE STRICT\n\tPARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 116, "num_statements": 1} {"question": "PostgreSQL Ddl: show example 2.", "schema": null, "sql": "CREATE TABLE products ( product_no integer, name text, price numeric );", "explanation": "Example from PostgreSQL documentation on Ddl.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 71, "num_statements": 1} {"question": "PostgreSQL regression test 'xml': Write the SELECT query (example 74).", "schema": null, "sql": "SELECT xmlroot(xml '', version no value, standalone yes);", "explanation": "Regression test for Xml in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT xmlroot(xml '', version no value, standalone yes)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'psql' (example 214).", "schema": null, "sql": "create table child_20_30 partition of parent_tab\n for values from (20) to (30);", "explanation": "DDL from PostgreSQL core regression test for Psql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 80, "num_statements": 1} {"question": "pgTAP test for Enumtap (assertion 31).", "schema": null, "sql": "SELECT * FROM check_test(\n enums_are( 'public', ARRAY['freddy'], 'whatever' ),\n false,\n 'enums_are(schema, enums, desc) fail',\n 'whatever',\n ' Extra types:\n bug_status\n Missing types:\n freddy'\n);", "explanation": "SQL assertion from pgTAP test suite for Enumtap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 230, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_table' (example 139).", "schema": null, "sql": "CREATE TABLE fail_part PARTITION OF hash_parted FOR VALUES WITH (MODULUS 150, REMAINDER 3);", "explanation": "DDL from PostgreSQL core regression test for Create Table.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 91, "num_statements": 1} {"question": "pgTAP test for Pgtap--0.91.0--0.92.0 (assertion 96).", "schema": null, "sql": "-- language_privs_are ( lang, user, privileges[] )\nCREATE OR REPLACE FUNCTION language_privs_are ( NAME, NAME, NAME[] )\nRETURNS TEXT AS $$\n SELECT language_privs_are(\n $1, $2, $3,\n 'Role ' || quote_ident($2) || ' should be granted '\n || CASE WHEN $3[1] IS NULL THEN 'no privileges' ELSE array_to_string($3, ', ') END\n || ' on language ' || quote_ident($1)\n );\n$$ LANGUAGE SQL;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--0.91.0--0.92.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 418, "num_statements": 2} {"question": "Write the DDL statement from PostgreSQL regression test 'brin_bloom' (example 62).", "schema": null, "sql": "CREATE INDEX brin_summarize_bloom_idx ON brin_summarize_bloom USING brin (value) WITH (pages_per_range=2);", "explanation": "DDL from PostgreSQL core regression test for Brin Bloom.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 106, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'numeric_big' (example 16).", "schema": null, "sql": "CREATE TABLE num_exp_sqrt (id int4, expected numeric(1000,800));", "explanation": "DDL from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 64, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pgstattuple' (example 75).", "schema": null, "sql": "select pgstatginindex('test_sequence');", "explanation": "Example query from the 'pgstattuple' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 39, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric_big' (example 370).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (8,7,'-818934531574859518.35936275646834493832011429282408849567717761204690035294074716714939441961175772404289860039233415598996234758590850206505669201200');", "explanation": "DML from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 191, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'generated_stored' (example 115).", "schema": null, "sql": "INSERT INTO gtest_varlena (a) VALUES('01234567890123456789');", "explanation": "DML from PostgreSQL core regression test for Generated Stored.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 61, "num_statements": 1} {"question": "PostgreSQL regression test 'interval': Write the SELECT query (example 137).", "schema": null, "sql": "SELECT interval '1 2:03:04.5678' hour to second(2);", "explanation": "Regression test for Interval in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT interval '1 2:03:04.5678' hour to second(2)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 51, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 128).", "schema": null, "sql": "CREATE FUNCTION isngt(ismn13, ismn)\n\tRETURNS boolean\n\tAS 'int8gt'\n\tLANGUAGE 'internal'\n\tIMMUTABLE STRICT\n\tPARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 120, "num_statements": 1} {"question": "PostgreSQL regression test 'groupingsets': Write the SELECT query (example 23).", "schema": null, "sql": "select sum(c) from gstest2\n group by grouping sets(grouping sets((a, (b))))\n order by 1 desc;", "explanation": "Regression test for Groupingsets in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select sum(c) from gstest2\n group by grouping sets(grouping sets((a, (b))))\n order by 1 desc) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_aggregation", "is_postgresql_specific": true, "sql_length": 95, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'float8' (example 132).", "schema": null, "sql": "-- error functions\n-- we run these with extra_float_digits = -1, to get consistently rounded\n-- results on all platforms.\nSET extra_float_digits = -1;", "explanation": "PL/pgSQL object from PostgreSQL core test for Float8.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 150, "num_statements": 1} {"question": "PostgreSQL Textsearch: show example 40.", "schema": null, "sql": "SELECT plainto_tsquery('english', 'The Fat Rats'); plainto_tsquery ----------------- 'fat' & 'rat';", "explanation": "Example from PostgreSQL documentation on Textsearch.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 99, "num_statements": 2} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 176).", "schema": null, "sql": "SELECT jsonb_object_agg_unique_strict(i, null) OVER (ORDER BY i)\n FROM generate_series(1, 10) g(i);", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT jsonb_object_agg_unique_strict(i, null) OVER (ORDER BY i)\n FROM generate_series(1, 10) g(i)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_window_function", "is_postgresql_specific": true, "sql_length": 100, "num_statements": 1} {"question": "PostgreSQL regression test 'float4': Write the SELECT query (example 84).", "schema": null, "sql": "SELECT float4send('887745e-11'::float4);", "explanation": "Regression test for Float4 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT float4send('887745e-11'::float4)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 40, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'float4' (example 5).", "schema": null, "sql": "INSERT INTO FLOAT4_TBL(f1) VALUES ('1.2345678901234e+20');", "explanation": "DML from PostgreSQL core regression test for Float4.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "Show an example of PostgreSQL CREATE PUBLICATION (example 5).", "schema": null, "sql": "CREATE PUBLICATION production_publication FOR TABLE users, departments, TABLES IN SCHEMA production;", "explanation": "PostgreSQL CREATE PUBLICATION command.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 100, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rowsecurity' (example 29).", "schema": null, "sql": "INSERT INTO rls_test_src VALUES (1, 'src a');", "explanation": "DML from PostgreSQL core regression test for Rowsecurity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 45, "num_statements": 1} {"question": "pgTAP test for Pktap (assertion 33).", "schema": null, "sql": "SELECT * FROM check_test(\n col_is_pk( 'argh', ARRAY['id', 'name'], 'id + name should be a pk' ),\n true,\n 'col_is_pk( table, column[], description )',\n 'id + name should be a pk',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Pktap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 200, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric_big' (example 279).", "schema": null, "sql": "INSERT INTO num_exp_sub VALUES (6,4,'-5329378275943663322215245.20238058768123314540388318253964726313120648232235700755866801918195710344138369800874235399515094124581615597720798385015942389765692769739983054442503547211560297249686289665792078548480268091496050883021187158502798880896590227542729659940394038802461081290690995869705131152889309663639310553909874081663091069118126221594338242710530718836025225507189149221049928936955230868771875644038572888630664890573507822342998964954667474300944699078658989010257103569231493090050659723450626338923049035040974032671138430612839043269997482582763267536489504794826476836323549796385028155416935072959933315468068930689064483178204550825728947252440604703474049780550458442808479096492346910001692358508618202898514895453589357');", "explanation": "DML from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 789, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'triggers' (example 158).", "schema": null, "sql": "create function trigger_nothing() returns trigger\n language plpgsql as $$ begin end; $$;\ncreate trigger failed instead of update on parted_trig\n for each row execute procedure trigger_nothing();\ncreate trigger failed after update on parted_trig\n referencing old table as old_table\n for each row execute procedure trigger_nothing();\ndrop table parted_trig;\n\n--\n-- Verify trigger creation for partitioned tables, and drop behavior\n--\ncreate table trigpart (a int, b int) partition by range (a);\ncreate table trigpart1 partition of trigpart for values from (0) to (1000);\ncreate trigger trg1 after insert on trigpart for each row execute procedure trigger_nothing();\ncreate table trigpart2 partition of trigpart for values from (1000) to (2000);\ncreate table trigpart3 (like trigpart);\nalter table trigpart attach partition trigpart3 for values from (2000) to (3000);\ncreate table trigpart4 partition of trigpart for values from (3000) to (4000) partition by range (a);\ncreate table trigpart41 partition of trigpart4 for values from (3000) to (3500);\ncreate table trigpart42 (like trigpart);\nalter table trigpart4 attach partition trigpart42 for values from (3500) to (4000);\nselect tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger\n where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text;\ndrop trigger trg1 on trigpart1;\t-- fail\ndrop trigger trg1 on trigpart2;\t-- fail\ndrop trigger trg1 on trigpart3;\t-- fail\ndrop table trigpart2;\t\t\t-- ok, trigger should be gone in that partition\nselect tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger\n where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text;\ndrop trigger trg1 on trigpart;\t\t-- ok, all gone\nselect tgrelid::regclass, tgname, tgfoid::regproc from pg_trigger\n where tgrelid::regclass::text like 'trigpart%' order by tgrelid::regclass::text;\n\n-- check detach behavior\ncreate trigger trg1 after insert on trigpart for each row execute procedure trigger_nothing();\n\\d trigpart3\nalter table trigpart detach partition trigpart3;\ndrop trigger trg1 on trigpart3; -- fail due to \"does not exist\"\nalter table trigpart detach partition trigpart4;\ndrop trigger trg1 on trigpart41; -- fail due to \"does not exist\"\ndrop table trigpart4;\nalter table trigpart attach partition trigpart3 for values from (2000) to (3000);\nalter table trigpart detach partition trigpart3;\nalter table trigpart attach partition trigpart3 for values from (2000) to (3000);\ndrop table trigpart3;\n\nselect tgrelid::regclass::text, tgname, tgfoid::regproc, tgenabled, tgisinternal from pg_trigger\n where tgname ~ '^trg1' order by 1;\ncreate table trigpart3 (like trigpart);\ncreate trigger trg1 after insert on trigpart3 for each row execute procedure trigger_nothing();\n\\d trigpart3\nalter table trigpart attach partition trigpart3 FOR VALUES FROM (2000) to (3000); -- fail\ndrop table trigpart3;\n\n-- check display of unrelated triggers\ncreate trigger samename after delete on trigpart execute function trigger_nothing();\ncreate trigger samename after delete on trigpart1 execute function trigger_nothing();\n\\d trigpart1\n\ndrop table trigpart;\ndrop function trigger_nothing();\n\n--\n-- Verify that triggers are fired for partitioned tables\n--\ncreate table parted_stmt_trig (a int) partition by list (a);\ncreate table parted_stmt_trig1 partition of parted_stmt_trig for values in (1);\ncreate table parted_stmt_trig2 partition of parted_stmt_trig for values in (2);\n\ncreate table parted2_stmt_trig (a int) partition by list (a);\ncreate table parted2_stmt_trig1 partition of parted2_stmt_trig for values in (1);\ncreate table parted2_stmt_trig2 partition of parted2_stmt_trig for values in (2);\n\ncreate or replace function trigger_notice() returns trigger as $$\n begin\n raise notice 'trigger % on % % % for %', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL;", "explanation": "DDL from PostgreSQL core regression test for Triggers.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 3838, "num_statements": 49} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 5).", "schema": null, "sql": "INSERT INTO timetzcmp (r_id,a) SELECT 2,count(*) FROM timetztmp WHERE a <= '07:46:45 GMT+3';", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 93, "num_statements": 1} {"question": "pgTAP test for Functap (assertion 107).", "schema": null, "sql": "/****************************************************************************/\n-- Test is_definer() isnt_definer().\nSELECT * FROM check_test(\n is_definer( 'public', 'yay', '{}'::name[], 'whatever' ),\n true,\n 'is_definer(schema, func, 0 args, desc)',\n 'whatever',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 284, "num_statements": 1} {"question": "PostgreSQL Textsearch: show example 7.", "schema": null, "sql": "SELECT title FROM pgweb WHERE to_tsvector('english', body) @@ to_tsquery('english', 'friend');", "explanation": "Example from PostgreSQL documentation on Textsearch.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": false, "sql_length": 94, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'foreign_data' (example 7).", "schema": null, "sql": "CREATE ROLE regress_test_role;", "explanation": "DDL from PostgreSQL core regression test for Foreign Data.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 30, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 164).", "schema": null, "sql": "SELECT jsonb_build_array('a', NULL); -- ok\nSELECT jsonb_build_array(VARIADIC NULL::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{}'::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{a,b,c}'::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC ARRAY['a', NULL]::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{1,2,3,4}'::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{1,2,3,4}'::int[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{{1,4},{2,5},{3,6}}'::int[][]); -- ok\n\nSELECT jsonb_build_object('a',1,'b',1.2,'c',true,'d',null,'e',json '{\"x\": 3, \"y\": [1,2,3]}');", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT jsonb_build_array('a', NULL); -- ok\nSELECT jsonb_build_array(VARIADIC NULL::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{}'::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{a,b,c}'::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC ARRAY['a', NULL]::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{1,2,3,4}'::text[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{1,2,3,4}'::int[]); -- ok\nSELECT jsonb_build_array(VARIADIC '{{1,4},{2,5},{3,6}}'::int[][]); -- ok\n\nSELECT jsonb_build_object('a',1,'b',1.2,'c',true,'d',null,'e',json '{\"x\": 3, \"y\": [1,2,3]}')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 570, "num_statements": 9} {"question": "Show a query using PostgreSQL contrib extension 'test_decoding' (example 29).", "schema": null, "sql": "INSERT INTO replication_example(somedata, text) VALUES (1, 5);", "explanation": "Example query from the 'test_decoding' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 62, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 2).", "schema": null, "sql": "CREATE FUNCTION postgres_fdw_disconnect (text)\nRETURNS bool\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT PARALLEL RESTRICTED;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "other", "is_postgresql_specific": false, "sql_length": 119, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'memoize' (example 45).", "schema": null, "sql": "CREATE TABLE prt_p2 PARTITION OF prt FOR VALUES FROM (10) TO (20);", "explanation": "DDL from PostgreSQL core regression test for Memoize.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 66, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_view' (example 60).", "schema": null, "sql": "CREATE SCHEMA testviewschm2;", "explanation": "DDL from PostgreSQL core regression test for Create View.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 28, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Types (example 42).", "schema": null, "sql": "CREATE FUNCTION test_type_conversion_float8(x float8) RETURNS float8 AS $$\nplpy.info(x, type(x))\nreturn x\n$$ LANGUAGE plpython3u;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Types.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 129, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Spi (example 6).", "schema": null, "sql": "CREATE FUNCTION spi_prepared_plan_test_nested(a text) RETURNS text\n\tAS\n'if \"myplan\" not in SD:\n\tq = \"SELECT spi_prepared_plan_test_one(''%s'') as count\" % a\n\tSD[\"myplan\"] = plpy.prepare(q)\ntry:\n\trv = plpy.execute(SD[\"myplan\"])\n\tif len(rv):\n\t\treturn rv[0][\"count\"]\nexcept Exception as ex:\n\tplpy.error(str(ex))\nreturn None\n'\n\tLANGUAGE plpython3u;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Spi.", "validation_query": null, "source": "plpgsql_source", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 344, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 412).", "schema": null, "sql": "select * from jsonb_to_recordset('[{\"a\":1,\"b\":\"foo\",\"d\":false},{\"a\":2,\"b\":\"bar\",\"c\":true}]')\n as x(a int, b text, c boolean);", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from jsonb_to_recordset('[{\"a\":1,\"b\":\"foo\",\"d\":false},{\"a\":2,\"b\":\"bar\",\"c\":true}]')\n as x(a int, b text, c boolean)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 128, "num_statements": 1} {"question": "PostgreSQL regression test 'strings': Write the SELECT query (example 188).", "schema": null, "sql": "SELECT regexp_substr('abcabcabc', 'a.c', 2);", "explanation": "Regression test for Strings in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT regexp_substr('abcabcabc', 'a.c', 2)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "PostgreSQL regression test 'rules': Write the SELECT query (example 317).", "schema": null, "sql": "SELECT * FROM shoelace_log;", "explanation": "Regression test for Rules in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM shoelace_log) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 27, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_table' (example 100).", "schema": null, "sql": "CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN ((1+1) collate \"POSIX\");", "explanation": "DDL from PostgreSQL core regression test for Create Table.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 97, "num_statements": 1} {"question": "PostgreSQL regression test 'numeric': Write the SELECT query (example 757).", "schema": null, "sql": "SELECT to_number('CLXC', 'RN');", "explanation": "Regression test for Numeric in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT to_number('CLXC', 'RN')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 31, "num_statements": 1} {"question": "PostgreSQL regression test 'subselect': Write the SELECT query (example 252).", "schema": null, "sql": "select nextval('ts1');", "explanation": "Regression test for Subselect in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select nextval('ts1')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 22, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 169).", "schema": null, "sql": "INSERT INTO num_exp_sub VALUES (3,9,'24926808.355047420');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'indexing' (example 315).", "schema": null, "sql": "create table idxpart (a int4range, b int4range) partition by range (a);", "explanation": "DDL from PostgreSQL core regression test for Indexing.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 71, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 192).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (4,5,'7815858.450391');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "PostgreSQL regression test 'xml': Write the SELECT query (example 147).", "schema": null, "sql": "SELECT xpath(NULL, NULL) IS NULL FROM xmltest;", "explanation": "Regression test for Xml in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT xpath(NULL, NULL) IS NULL FROM xmltest) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 46, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'aggregates' (example 181).", "schema": null, "sql": "insert into minmaxtest values(11), (12);", "explanation": "DML from PostgreSQL core regression test for Aggregates.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 40, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 725).", "schema": null, "sql": "select jsonb_set('{\"n\":null, \"a\":1, \"b\":[1,2], \"c\":{\"1\":2}, \"d\":{\"1\":[2,3]}}'::jsonb, '{d,1,0}', '{\"1\": 2}');", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb_set('{\"n\":null, \"a\":1, \"b\":[1,2], \"c\":{\"1\":2}, \"d\":{\"1\":[2,3]}}'::jsonb, '{d,1,0}', '{\"1\": 2}')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 109, "num_statements": 1} {"question": "PostgreSQL Textsearch: show example 6.", "schema": null, "sql": "SELECT phraseto_tsquery('cats ate rats'); phraseto_tsquery ------------------------------- 'cat' <-> 'ate' <-> 'rat' SELECT phraseto_tsquery('the cats ate the rats'); phraseto_tsquery ------------------------------- 'cat' <-> 'ate' <2> 'rat';", "explanation": "Example from PostgreSQL documentation on Textsearch.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 242, "num_statements": 3} {"question": "pgTAP test for Aretap (assertion 11).", "schema": null, "sql": "CREATE VIEW public.vou AS SELECT * FROM fou;", "explanation": "SQL assertion from pgTAP test suite for Aretap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'indexing' (example 520).", "schema": null, "sql": "create table parted_replica_tab_1 partition of parted_replica_tab\n for values from (1) to (10) partition by range (id);", "explanation": "DDL from PostgreSQL core regression test for Indexing.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 120, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'identity' (example 77).", "schema": null, "sql": "INSERT INTO itestv11 VALUES (10, 'xyz');", "explanation": "DML from PostgreSQL core regression test for Identity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 40, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'test_decoding' (example 17).", "schema": null, "sql": "SELECT pg_stat_reset_replication_slot('do-not-exist');", "explanation": "Example query from the 'test_decoding' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'foreign_data' (example 20).", "schema": null, "sql": "CREATE FOREIGN DATA WRAPPER foo OPTIONS (testing '1');", "explanation": "DDL from PostgreSQL core regression test for Foreign Data.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "PostgreSQL regression test 'xml': Write the SELECT query (example 175).", "schema": null, "sql": "SELECT COUNT(id) FROM xmltest WHERE xmlexists('/menu/beer' PASSING BY REF data BY REF);", "explanation": "Regression test for Xml in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT COUNT(id) FROM xmltest WHERE xmlexists('/menu/beer' PASSING BY REF data BY REF)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 87, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Populate (example 9).", "schema": null, "sql": "INSERT INTO entry (accession, txid) VALUES ('A00002', '1') ;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Populate.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 38).", "schema": null, "sql": "CREATE FUNCTION seg_lower(seg)\nRETURNS float4\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 109, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 520).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION _definer ( NAME, NAME[] );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 61, "num_statements": 1} {"question": "PostgreSQL regression test 'stats_import': Write the SELECT query (example 232).", "schema": null, "sql": "SELECT replace(e.n_distinct, '}, ', E'},\\n') AS n_distinct,\n replace(e.dependencies, '}, ', E'},\\n') AS dependencies,\n replace(e.most_common_vals::text, '},', E'},\\n ') AS mcvs,\n e.most_common_val_nulls,\n e.most_common_freqs, e.most_common_base_freqs\nFROM pg_stats_ext AS e\nWHERE e.statistics_schemaname = 'stats_import' AND\n e.statistics_name = 'test_mr_stat' AND\n e.inherited = false\n\\gx\n\n-- Test the ability of pg_restore_extended_stats() to import all of the\n-- statistic values from an extended statistic object that has been\n-- populated via a regular ANALYZE. This checks after the statistics\n-- kinds supported by pg_restore_extended_stats().\n--\n-- Note: Keep this test at the bottom of the file, so as the amount of\n-- statistics data handled is maximized.\nANALYZE stats_import.test;", "explanation": "Regression test for Stats Import in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT replace(e.n_distinct, '}, ', E'},\\n') AS n_distinct,\n replace(e.dependencies, '}, ', E'},\\n') AS dependencies,\n replace(e.most_common_vals::text, '},', E'},\\n ') AS mcvs,\n e.most_common_val_nulls,\n e.most_common_freqs, e.most_common_base_freqs\nFROM pg_stats_ext AS e\nWHERE e.statistics_schemaname = 'stats_import' AND\n e.statistics_name = 'test_mr_stat' AND\n e.inherited = false\n\\gx\n\n-- Test the ability of pg_restore_extended_stats() to import all of the\n-- statistic values from an extended statistic object that has been\n-- populated via a regular ANALYZE. This checks after the statistics\n-- kinds supported by pg_restore_extended_stats().\n--\n-- Note: Keep this test at the bottom of the file, so as the amount of\n-- statistics data handled is maximized.\nANALYZE stats_import.test) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "admin_maintenance", "is_postgresql_specific": true, "sql_length": 825, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 448).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION language_is_trusted( NAME, TEXT );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 69, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'vacuum' (example 2).", "schema": null, "sql": "INSERT INTO vactst VALUES (1);", "explanation": "DML from PostgreSQL core regression test for Vacuum.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 30, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'seg' (example 129).", "schema": null, "sql": "SELECT '2'::seg >> '1'::seg AS bool;", "explanation": "Example query from the 'seg' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 36, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'domain' (example 172).", "schema": null, "sql": "insert into nulltest values ('a', 'b', 'c', 'd', 'a');", "explanation": "DML from PostgreSQL core regression test for Domain.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'interval' (example 21).", "schema": null, "sql": "INSERT INTO INTERVAL_TBL (f1) VALUES ('6 years');", "explanation": "DML from PostgreSQL core regression test for Interval.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'without_overlaps' (example 108).", "schema": null, "sql": "INSERT INTO temporal_rng3 (id, valid_at) VALUES ('[1,2)', daterange('2018-03-03', '2018-04-04'));", "explanation": "DML from PostgreSQL core regression test for Without Overlaps.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 97, "num_statements": 1} {"question": "Show a SQL definition from the zombodb project (zombodb--3000.2.4--3000.2.5, item 2).", "schema": null, "sql": "CREATE FUNCTION zdb.schema_version() RETURNS text LANGUAGE sql AS $$\nSELECT '3000.2.5 (4704c7982040b2dd33d97334d3d4743082549630)'\n$$;", "explanation": "SQL definition from the open-source zombodb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 133, "num_statements": 1} {"question": "PostgreSQL regression test 'window': Write the SELECT query (example 54).", "schema": null, "sql": "SELECT sum(unique1) over (rows between 2 preceding and 2 following),\n\tunique1, four\nFROM tenk1 WHERE unique1 < 10;", "explanation": "Regression test for Window in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT sum(unique1) over (rows between 2 preceding and 2 following),\n\tunique1, four\nFROM tenk1 WHERE unique1 < 10) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_window_function", "is_postgresql_specific": true, "sql_length": 114, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'copy' (example 5).", "schema": null, "sql": "insert into copytest values(E'esc\\\\ape',E'a\\\\r\\\\\\r\\\\\\n\\\\nb',4);", "explanation": "DML from PostgreSQL core regression test for Copy.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pageinspect' (example 24).", "schema": null, "sql": "SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 1));", "explanation": "Example query from the 'pageinspect' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'stats_ext' (example 384).", "schema": null, "sql": "-- create statistics on expressions\nCREATE STATISTICS func_deps_stat (dependencies) ON (a * 2), upper(b), (c + 1) FROM functional_dependencies;", "explanation": "PL/pgSQL object from PostgreSQL core test for Stats Ext.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 143, "num_statements": 1} {"question": "PostgreSQL regression test 'horology': Write the SELECT query (example 24).", "schema": null, "sql": "SELECT timestamp with time zone 'J2452271 04:05:06+08';", "explanation": "Regression test for Horology in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT timestamp with time zone 'J2452271 04:05:06+08') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "pgTAP test for Pgtap--1.3.0--1.3.1 (assertion 14).", "schema": null, "sql": "-- has_pk( schema, table )\nCREATE OR REPLACE FUNCTION has_pk ( NAME, NAME )\nRETURNS TEXT AS $$\n SELECT has_pk( $1, $2, 'Table ' || quote_ident($1) || '.' || quote_ident($2) || ' should have a primary key' );\n$$ LANGUAGE sql;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--1.3.0--1.3.1.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 227, "num_statements": 2} {"question": "PostgreSQL regression test 'alter_table': Write the SELECT query (example 649).", "schema": null, "sql": "SELECT coninhcount, conislocal FROM pg_constraint WHERE conrelid = 'part_3_4'::regclass AND conname = 'check_a';", "explanation": "Regression test for Alter Table in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT coninhcount, conislocal FROM pg_constraint WHERE conrelid = 'part_3_4'::regclass AND conname = 'check_a') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 112, "num_statements": 1} {"question": "PostgreSQL regression test 'int8': Write the SELECT query (example 28).", "schema": null, "sql": "SELECT * FROM INT8_TBL WHERE 123 > q1;", "explanation": "Regression test for Int8 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM INT8_TBL WHERE 123 > q1) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 38, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_prune' (example 46).", "schema": null, "sql": "create table rlp5_default partition of rlp5 default;", "explanation": "DDL from PostgreSQL core regression test for Partition Prune.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 52, "num_statements": 1} {"question": "pgTAP test for Pgtap--1.3.0--1.3.1 (assertion 4).", "schema": null, "sql": "-- col_type_is( schema, table, column, schema, type )\nCREATE OR REPLACE FUNCTION col_type_is ( NAME, NAME, NAME, NAME, TEXT )\nRETURNS TEXT AS $$\n SELECT col_type_is( $1, $2, $3, $4, $5, 'Column ' || quote_ident($1) || '.' || quote_ident($2)\n || '.' || quote_ident($3) || ' should be type ' || quote_ident($4) || '.' || $5);\n$$ LANGUAGE SQL;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--1.3.0--1.3.1.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 350, "num_statements": 2} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 5).", "schema": null, "sql": "CREATE TYPE cube (\n\tINTERNALLENGTH = variable,\n\tINPUT = cube_in,\n\tOUTPUT = cube_out,\n\tALIGNMENT = double\n);", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 107, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'indirect_toast' (example 27).", "schema": null, "sql": "DROP FUNCTION update_using_indirect();", "explanation": "PL/pgSQL object from PostgreSQL core test for Indirect Toast.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 38, "num_statements": 1} {"question": "PostgreSQL regression test 'with': Write the SELECT query (example 204).", "schema": null, "sql": "SELECT * from id_alw1;", "explanation": "Regression test for With in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * from id_alw1) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 22, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (telemetry, item 5).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION _timescaledb_internal.test_telemetry_main_conn(text, text)\nRETURNS BOOLEAN AS :MODULE_PATHNAME, 'ts_test_telemetry_main_conn' LANGUAGE C IMMUTABLE PARALLEL SAFE;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 188, "num_statements": 1} {"question": "pgTAP test for Pgtap--0.94.0--0.95.0 (assertion 22).", "schema": null, "sql": "-- hasnt_materialized_view( materialized_view )\nCREATE OR REPLACE FUNCTION hasnt_materialized_view ( NAME )\nRETURNS TEXT AS $$\n SELECT hasnt_materialized_view( $1, 'Materialized view ' || quote_ident($1) || ' should not exist' );\n$$ LANGUAGE SQL;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--0.94.0--0.95.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 249, "num_statements": 2} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_join' (example 115).", "schema": null, "sql": "CREATE TABLE prt2_m_p1 PARTITION OF prt2_m FOR VALUES FROM (0, 0) TO (250, 250);", "explanation": "DDL from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 80, "num_statements": 1} {"question": "Show a SQL definition from the zombodb project (_postgis-support, item 4).", "schema": null, "sql": "-- casting functions\n EXECUTE format('create or replace function zdb.geometry_to_json(%I.geometry, typmod integer DEFAULT -1) returns json parallel safe immutable strict language sql as $$\n SELECT CASE WHEN %I.postgis_typmod_type($2) = ''Point'' THEN\n zdb.point_to_json(%I.st_transform($1, 4326)::point)::json\n ELSE\n %I.st_asgeojson(%I.st_transform($1, 4326))::json\n END\n $$;',\n geojson_namespace, geojson_namespace, geojson_namespace, geojson_namespace, geojson_namespace);", "explanation": "SQL definition from the open-source zombodb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 570, "num_statements": 2} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 73).", "schema": null, "sql": "CREATE FUNCTION gin_extract_query_char(\"char\", internal, int2, internal, internal)\nRETURNS internal\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT IMMUTABLE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 149, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'earthdistance' (example 32).", "schema": null, "sql": "SELECT cube_ll_coord(ll_to_earth(-90,180),1)::numeric(20,5),\n cube_ll_coord(ll_to_earth(-90,180),2)::numeric(20,5),\n cube_ll_coord(ll_to_earth(-90,180),3)::numeric(20,5);", "explanation": "Example query from the 'earthdistance' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": false, "sql_length": 170, "num_statements": 1} {"question": "PostgreSQL regression test 'union': Write the SELECT query (example 24).", "schema": null, "sql": "SELECT f1 AS three FROM VARCHAR_TBL\nUNION\nSELECT CAST(f1 AS varchar) FROM CHAR_TBL\nORDER BY 1;", "explanation": "Regression test for Union in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT f1 AS three FROM VARCHAR_TBL\nUNION\nSELECT CAST(f1 AS varchar) FROM CHAR_TBL\nORDER BY 1) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 94, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'timestamptz' (example 86).", "schema": null, "sql": "INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 11 17:32:01 1997');", "explanation": "DML from PostgreSQL core regression test for Timestamptz.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "pgTAP test for Throwtap (assertion 1).", "schema": null, "sql": "\\unset ECHO\n\\i test/setup.sql\n\nSELECT plan(97);", "explanation": "SQL assertion from pgTAP test suite for Throwtap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 47, "num_statements": 1} {"question": "PL/pgSQL test: Plperl Array (example 18).", "schema": null, "sql": "select plperl_sum_row_elements(ROW(1, ARRAY[2,3,4,5,6,7,8,9,10])::rowfoo);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plperl Array.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 74, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'stats_import' (example 25).", "schema": null, "sql": "CREATE INDEX part_parent_i ON stats_import.part_parent(i);", "explanation": "DDL from PostgreSQL core regression test for Stats Import.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'indexing' (example 251).", "schema": null, "sql": "create index on idxpart2 (a) where b > 1000;", "explanation": "DDL from PostgreSQL core regression test for Indexing.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "PostgreSQL regression test 'advisory_lock': Write the SELECT query (example 12).", "schema": null, "sql": "SELECT\n\tpg_advisory_lock(1), pg_advisory_lock_shared(2),\n\tpg_advisory_lock(1, 1), pg_advisory_lock_shared(2, 2);", "explanation": "Regression test for Advisory Lock in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT\n\tpg_advisory_lock(1), pg_advisory_lock_shared(2),\n\tpg_advisory_lock(1, 1), pg_advisory_lock_shared(2, 2)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 112, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'transactions' (example 189).", "schema": null, "sql": "-- Now the same test with plpgsql (since it depends on SPI which is different)\ncreate or replace function max_xacttest() returns smallint language plpgsql as\n'begin return max(a) from xacttest; end' stable;", "explanation": "PL/pgSQL object from PostgreSQL core test for Transactions.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 206, "num_statements": 2} {"question": "Show a SQL definition from the pgaudit project (pgaudit--18.0, item 1).", "schema": null, "sql": "\\echo Use \"CREATE EXTENSION pgaudit\" to load this file.\\quit\n\nCREATE FUNCTION pgaudit_ddl_command_end()\n\tRETURNS event_trigger\n\tSECURITY DEFINER\n\tSET search_path = pg_catalog, pg_temp\n\tLANGUAGE C\n\tAS 'MODULE_PATHNAME', 'pgaudit_ddl_command_end';", "explanation": "SQL definition from the open-source pgaudit PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 245, "num_statements": 1} {"question": "Show an example of PostgreSQL INSERT (example 9).", "schema": null, "sql": "WITH upd AS ( UPDATE employees SET sales_count = sales_count + 1 WHERE id = (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation') RETURNING * ) INSERT INTO employees_log SELECT *, current_timestamp FROM upd;", "explanation": "PostgreSQL INSERT command.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 221, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'test_decoding' (example 11).", "schema": null, "sql": "INSERT INTO spill_test SELECT 'serialize-subbig--1:'||g.i FROM generate_series(1, 5000) g(i);", "explanation": "Example query from the 'test_decoding' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 93, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 220).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (5,2,'-34322095.176906047');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "PostgreSQL regression test 'text': Write the SELECT query (example 37).", "schema": null, "sql": "select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', NULL, 'Hello');", "explanation": "Regression test for Text in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', NULL, 'Hello')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 70, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'join' (example 496).", "schema": null, "sql": "CREATE TEMP TABLE parted_b1 partition of parted_b for values from (0) to (10);", "explanation": "DDL from PostgreSQL core regression test for Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 78, "num_statements": 1} {"question": "PostgreSQL regression test 'rangetypes': Write the SELECT query (example 13).", "schema": null, "sql": "select ' ( \" a \" \" a \", \" z \" \" z \" ) '::textrange;", "explanation": "Regression test for Rangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select ' ( \" a \" \" a \", \" z \" \" z \" ) '::textrange) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 52, "num_statements": 1} {"question": "PL/pgSQL test: Plpgsql Domain (example 23).", "schema": null, "sql": "SELECT * FROM test_argresult_nnint(null, 20);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpgsql Domain.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 45, "num_statements": 1} {"question": "pgTAP test for Coltap (assertion 90).", "schema": null, "sql": "-- Make sure that it works when the default is a reserved SQL expression.\nCREATE OR REPLACE FUNCTION ckreserve() RETURNS SETOF TEXT LANGUAGE PLPGSQL AS $$\nDECLARE\n funcs text[] := '{CURRENT_CATALOG,CURRENT_ROLE,CURRENT_SCHEMA,CURRENT_USER,SESSION_USER,USER,CURRENT_DATE,CURRENT_TIME,CURRENT_TIMESTAMP,LOCALTIME,LOCALTIMESTAMP}';\n cols TEXT[] := '{ccat,crole,csch,cuser,suser,auser,cdate,ctime,ctstz,ltime,ltstz}';\n exp TEXT[] := funcs;\n tap record;\n last_index INTEGER;\nBEGIN\n last_index := array_upper(funcs, 1);\n IF pg_version_num() < 100000 THEN\n -- Prior to PostgreSQL 10, these were functions rendered with paretheses or as casts.\n exp := ARRAY['current_database()','\"current_user\"()','\"current_schema\"()','\"current_user\"()','\"session_user\"()','\"current_user\"()','(''now''::text)::date','(''now''::text)::time with time zone','now()','(''now''::text)::time without time zone','(''now''::text)::timestamp without time zone'];\n END IF;\n\n FOR i IN 1..last_index LOOP\n FOR tap IN SELECT * FROM check_test(\n col_default_is( 'sometab', cols[i], exp[i], 'Test ' || funcs[i] ),\n true,\n 'col_default_is( tab, col, ' || funcs[i] || ' )',\n 'Test ' || funcs[i],\n ''\n ) AS b LOOP RETURN NEXT tap.b; END LOOP;\n END LOOP;\nEND;\n$$;", "explanation": "SQL assertion from pgTAP test suite for Coltap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 1347, "num_statements": 13} {"question": "PL/pgSQL test: Plpython Record (example 19).", "schema": null, "sql": "SELECT * FROM test_table_record_as('list', 'one', null, false);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Record.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 292).", "schema": null, "sql": "SELECT JSON_QUERY(jsonb '123', '$' RETURNING queryfuncs_char2_chk ERROR ON ERROR);", "explanation": "Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_QUERY(jsonb '123', '$' RETURNING queryfuncs_char2_chk ERROR ON ERROR)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 82, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_prune' (example 223).", "schema": null, "sql": "create table rp2 partition of rp for values from (2) to (maxvalue);", "explanation": "DDL from PostgreSQL core regression test for Partition Prune.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 67, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'insert' (example 9).", "schema": null, "sql": "insert into inserttest (col1, col2, col3) values (1, 2);", "explanation": "DML from PostgreSQL core regression test for Insert.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 56, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (compat, item 23).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION _timescaledb_internal.get_partition_hash(val anyelement) RETURNS integer LANGUAGE PLPGSQL AS $$\nBEGIN\n IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN\n RAISE WARNING 'function _timescaledb_internal.get_partition_hash(anyelement) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';\n END IF;\n RETURN _timescaledb_functions.get_partition_hash($1);\nEND$$\nSET search_path TO pg_catalog,pg_temp;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 535, "num_statements": 4} {"question": "Write the DML statement from PostgreSQL regression test 'numeric_big' (example 259).", "schema": null, "sql": "INSERT INTO num_exp_sub VALUES (5,9,'-707619110.78141098833556856308817117136192658504561165951731229431651264331543278598450117846625251667849259592530287073315399782168794294250299770032264633712037469256688885911649778714039732161560189579333758422588445749233730591792217152212229008169062714458263709952275557558931748845536759606982982654369800245696528893058665897330942472105350178781035298449067051916630343957356635391594362639819978677032855590055900561501350354631803808000307050416047072513406855040715556454205065332997338225626635780147287003130754254277103928406089109802521803537038957372612837169223905290912251006321930223154562110264217937');", "explanation": "DML from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 662, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'ltree' (example 149).", "schema": null, "sql": "SELECT 'a.b.c.d.e'::ltree ~ '!d.*';", "explanation": "Example query from the 'ltree' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_view' (example 75).", "schema": null, "sql": "CREATE TABLE tbl1 ( a int, b int);", "explanation": "DDL from PostgreSQL core regression test for Create View.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "PostgreSQL regression test 'vacuum': Write the SELECT query (example 15).", "schema": null, "sql": "SELECT count(*) FROM vactst;", "explanation": "Regression test for Vacuum in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT count(*) FROM vactst) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 28, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'merge' (example 367).", "schema": null, "sql": "CREATE TABLE part3 PARTITION OF pa_target FOR VALUES IN (3,8,9)\n WITH (autovacuum_enabled=off);", "explanation": "DDL from PostgreSQL core regression test for Merge.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 96, "num_statements": 1} {"question": "pgTAP test for Index (assertion 16).", "schema": null, "sql": "SELECT * FROM check_test(\n has_index( 'public', 'sometab', 'idx_hey', 'numb'::name ),\n true,\n 'has_index() single column no desc',\n 'Index idx_hey should exist',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Index.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 183, "num_statements": 1} {"question": "PostgreSQL Rules: show example 51.", "schema": null, "sql": "UPDATE shoelace_data SET sl_name = s.sl_name, sl_avail = s.sl_avail + shoelace_arrive.arr_quant, sl_color = s.sl_color, sl_len = s.sl_len, sl_unit = s.sl_unit FROM shoelace_arrive shoelace_arrive, shoelace_ok shoelace_ok, shoelace_ok old, shoelace_ok new, shoelace shoelace, shoelace old, shoelace new, shoelace_data shoelace_data, shoelace old, shoelace new, shoelace_data s, unit u WHERE s.sl_name = shoelace_arrive.arr_name AND shoelace_data.sl_name = s.sl_name;", "explanation": "Example from PostgreSQL documentation on Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 465, "num_statements": 1} {"question": "PostgreSQL regression test 'regproc': Write the SELECT query (example 108).", "schema": null, "sql": "SELECT to_regnamespace('foo.bar');", "explanation": "Regression test for Regproc in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT to_regnamespace('foo.bar')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "Show a SQL definition from the pg_partman project (test-time-mixed-case, item 9).", "schema": null, "sql": "CREATE TABLE \"Partman_Test\".\"FK_Test_Reference\" (\"Col2\" text unique not null);", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 78, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_am' (example 132).", "schema": null, "sql": "CREATE FOREIGN DATA WRAPPER fdw_heap2 VALIDATOR postgresql_fdw_validator;", "explanation": "DDL from PostgreSQL core regression test for Create Am.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 73, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'jsonb' (example 265).", "schema": null, "sql": "CREATE DOMAIN jsb_int_not_null AS int NOT NULL;", "explanation": "DDL from PostgreSQL core regression test for Jsonb.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 52, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rules' (example 314).", "schema": null, "sql": "CREATE TABLE shoelace_log (\n sl_name char(10), -- shoelace changed\n sl_avail integer, -- new available value\n log_who name, -- who did it\n log_when timestamp -- when\n );", "explanation": "DDL from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 235, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 54).", "schema": null, "sql": "CREATE OPERATOR ~ (\n PROCEDURE = texticregexeq,\n LEFTARG = citext,\n RIGHTARG = text,\n NEGATOR = !~,\n RESTRICT = icregexeqsel,\n JOIN = icregexeqjoinsel\n);", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 182, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'tablefunc' (example 73).", "schema": null, "sql": "SELECT * FROM connectby('connectby_int', 'keyid', 'parent_keyid', '2', 0) AS t(keyid int, parent_keyid text, level int);", "explanation": "Example query from the 'tablefunc' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 120, "num_statements": 1} {"question": "pgTAP test for Index (assertion 77).", "schema": null, "sql": "/****************************************************************************/\n-- Test index_is_partial().\nSELECT * FROM check_test(\n index_is_partial( 'public', 'sometab', 'idx_partial', 'whatever' ),\n true,\n 'index_is_partial()',\n 'whatever',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Index.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 266, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'ltree' (example 30).", "schema": null, "sql": "SELECT index('a.1.2.3.4.5.6','6');", "explanation": "Example query from the 'ltree' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 367).", "schema": null, "sql": "SELECT regexp_replace('Thomas'::citext, '.[MN]A.'::citext, 'M', 'c') = 'Thomas' AS t;", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 85, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 324).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION has_domain( NAME, TEXT );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "PostgreSQL regression test 'inet': Write the SELECT query (example 57).", "schema": null, "sql": "SELECT * FROM inet_tbl WHERE i && '192.168.1.0/24'::cidr ORDER BY i;", "explanation": "Regression test for Inet in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM inet_tbl WHERE i && '192.168.1.0/24'::cidr ORDER BY i) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 68, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (compat, item 31).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION _timescaledb_internal.policy_retention_check(config jsonb) RETURNS void LANGUAGE PLPGSQL AS $$\nBEGIN\n IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN\n RAISE WARNING 'function _timescaledb_internal.policy_retention_check(jsonb) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';\n END IF;\n PERFORM _timescaledb_functions.policy_retention_check($1);\nEND$$\nSET search_path TO pg_catalog,pg_temp;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 538, "num_statements": 4} {"question": "Write the DML statement from PostgreSQL regression test 'tuplesort' (example 4).", "schema": null, "sql": "INSERT INTO abbrev_abort_uuids (abort_increasing, abort_decreasing, noabort_increasing, noabort_decreasing)\n SELECT\n ('00000000-0000-0000-0000-'||to_char(g.i, '000000000000FM'))::uuid abort_increasing,\n ('00000000-0000-0000-0000-'||to_char(20000 - g.i, '000000000000FM'))::uuid abort_decreasing,\n (to_char(g.i % 10009, '00000000FM')||'-0000-0000-0000-'||to_char(g.i, '000000000000FM'))::uuid noabort_increasing,\n (to_char(((20000 - g.i) % 10009), '00000000FM')||'-0000-0000-0000-'||to_char(20000 - g.i, '000000000000FM'))::uuid noabort_decreasing\n FROM generate_series(0, 20000, 1) g(i);", "explanation": "DML from PostgreSQL core regression test for Tuplesort.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 621, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'plpgsql' (example 446).", "schema": null, "sql": "$$ language plpgsql;\n\nselect forc01();\n\nselect * from forc_test;\n\ndrop function forc01();\n\n-- it's okay to re-use a cursor variable name, even when bound\n\ndo $$\ndeclare cnt int := 0;", "explanation": "PL/pgSQL object from PostgreSQL core test for Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 182, "num_statements": 5} {"question": "PostgreSQL regression test 'sequence': Write the SELECT query (example 49).", "schema": null, "sql": "SELECT nextval('sequence_test'::text);", "explanation": "Regression test for Sequence in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT nextval('sequence_test'::text)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 38, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'foreign_key' (example 869).", "schema": null, "sql": "DELETE FROM pk WHERE a = 2;", "explanation": "DML from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_delete", "is_postgresql_specific": false, "sql_length": 27, "num_statements": 1} {"question": "PostgreSQL regression test 'portals': Write the SELECT query (example 161).", "schema": null, "sql": "SELECT * FROM uctest;", "explanation": "Regression test for Portals in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM uctest) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 21, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 511).", "schema": null, "sql": "INSERT INTO rem1 values(2, 'insert') RETURNING f2;", "explanation": "Example query from the 'postgres_fdw' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 50, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rowsecurity' (example 1179).", "schema": null, "sql": "CREATE POLICY p1 ON rls_tbl_force USING (c1 = 5) WITH CHECK (c1 < 5);", "explanation": "DDL from PostgreSQL core regression test for Rowsecurity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 69, "num_statements": 1} {"question": "PostgreSQL regression test 'multirangetypes': Write the SELECT query (example 96).", "schema": null, "sql": "SELECT * FROM nummultirange_test WHERE nmr > '{}';", "explanation": "Regression test for Multirangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM nummultirange_test WHERE nmr > '{}') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 50, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'triggers' (example 183).", "schema": null, "sql": "create trigger parted_trig_odd after insert on parted_irreg for each row\n when (bark(new.b) AND new.a % 2 = 1) execute procedure trigger_notice_ab();", "explanation": "DDL from PostgreSQL core regression test for Triggers.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 150, "num_statements": 1} {"question": "PostgreSQL regression test 'float8': Write the SELECT query (example 146).", "schema": null, "sql": "SELECT lgamma(float8 '1000');", "explanation": "Regression test for Float8 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT lgamma(float8 '1000')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 29, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'memoize' (example 44).", "schema": null, "sql": "CREATE TABLE prt_p1 PARTITION OF prt FOR VALUES FROM (0) TO (10);", "explanation": "DDL from PostgreSQL core regression test for Memoize.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonpath': Write the SELECT query (example 33).", "schema": null, "sql": "select '$.g ? (@ == 1)'::jsonpath;", "explanation": "Regression test for Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '$.g ? (@ == 1)'::jsonpath) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_join' (example 160).", "schema": null, "sql": "CREATE TABLE pht1_e_p2 PARTITION OF pht1_e FOR VALUES WITH (MODULUS 3, REMAINDER 1);", "explanation": "DDL from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 84, "num_statements": 1} {"question": "PostgreSQL regression test 'updatable_views': Write the SELECT query (example 129).", "schema": null, "sql": "SELECT table_name, is_updatable, is_insertable_into,\n is_trigger_updatable, is_trigger_deletable,\n is_trigger_insertable_into\n FROM information_schema.views\n WHERE table_name LIKE 'rw_view%'\n ORDER BY table_name;", "explanation": "Regression test for Updatable Views in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT table_name, is_updatable, is_insertable_into,\n is_trigger_updatable, is_trigger_deletable,\n is_trigger_insertable_into\n FROM information_schema.views\n WHERE table_name LIKE 'rw_view%'\n ORDER BY table_name) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 225, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'test_decoding' (example 64).", "schema": null, "sql": "INSERT INTO spill_test SELECT 'serialize-subbig-subsmall--2:'||g.i FROM generate_series(5001, 5001) g(i);", "explanation": "Example query from the 'test_decoding' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 105, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'constraints' (example 12).", "schema": null, "sql": "INSERT INTO DEFAULTEXPR_TBL (i2) VALUES (-4);", "explanation": "DML from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 45, "num_statements": 1} {"question": "PostgreSQL Advanced: show example 2.", "schema": null, "sql": "CREATE TABLE cities ( name varchar(80) PRIMARY KEY, location point ); CREATE TABLE weather ( city varchar(80) REFERENCES cities (name), temp_lo int, temp_hi int, prcp real, date date );", "explanation": "Example from PostgreSQL documentation on Advanced.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 185, "num_statements": 2} {"question": "Show a query using PostgreSQL contrib extension 'test_decoding' (example 67).", "schema": null, "sql": "SELECT 'tx logical msg' FROM pg_logical_emit_message(true, 'test', 'tx logical msg');", "explanation": "Example query from the 'test_decoding' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 85, "num_statements": 1} {"question": "pgTAP test for Coltap (assertion 33).", "schema": null, "sql": "-- Try interval second.\nSELECT * FROM check_test(\n col_type_is( 'public', 'sometab', 'isecd', 'pg_catalog', 'interval second(0)', 'isecd is interval second(0)' ),\n true,\n 'col_type_is( sch, tab, intsec, sch, type, desc )',\n 'isecd is interval second(0)',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Coltap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 276, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'fast_default' (example 50).", "schema": null, "sql": "INSERT INTO T VALUES (25), (26);", "explanation": "DML from PostgreSQL core regression test for Fast Default.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 32, "num_statements": 1} {"question": "pgTAP test for Pgtap--0.92.0--0.93.0 (assertion 29).", "schema": null, "sql": "-- index_owner_is ( schema, table, index, user, description )\nCREATE OR REPLACE FUNCTION index_owner_is ( NAME, NAME, NAME, NAME, TEXT )\nRETURNS TEXT AS $$\nDECLARE\n owner NAME := _get_index_owner($1, $2, $3);\nBEGIN\n -- Make sure the index exists.\n IF owner IS NULL THEN\n RETURN ok(FALSE, $5) || E'\\n' || diag(\n E' Index ' || quote_ident($3) || ' ON '\n || quote_ident($1) || '.' || quote_ident($2) || ' not found'\n );\n END IF;\n\n RETURN is(owner, $4, $5);\nEND;\n$$ LANGUAGE plpgsql;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--0.92.0--0.93.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 533, "num_statements": 6} {"question": "PostgreSQL regression test 'horology': Write the SELECT query (example 249).", "schema": null, "sql": "SELECT to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16',\n '\"My birthday-> Year:\" YYYY, \"Month:\" FMMonth, \"Day:\" DD');", "explanation": "Regression test for Horology in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT to_timestamp('My birthday-> Year: 1976, Month: May, Day: 16',\n '\"My birthday-> Year:\" YYYY, \"Month:\" FMMonth, \"Day:\" DD')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 148, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'indexing' (example 327).", "schema": null, "sql": "create table idxpart (a int4range, b int4range, c int4range) partition by range (a);", "explanation": "DDL from PostgreSQL core regression test for Indexing.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 84, "num_statements": 1} {"question": "PostgreSQL regression test 'indirect_toast': Write the SELECT query (example 13).", "schema": null, "sql": "SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest;", "explanation": "Regression test for Indirect Toast in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT substring(indtoasttest::text, 1, 200) FROM indtoasttest) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "PostgreSQL regression test 'boolean': Write the SELECT query (example 40).", "schema": null, "sql": "SELECT ' true '::text::boolean AS true,\n ' FALSE'::text::boolean AS false;", "explanation": "Regression test for Boolean in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT ' true '::text::boolean AS true,\n ' FALSE'::text::boolean AS false) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 89, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_prune' (example 301).", "schema": null, "sql": "create table ab_a3_b3 partition of ab_a3 for values in (3);", "explanation": "DDL from PostgreSQL core regression test for Partition Prune.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Show a SQL definition from the pg_partman project (pg_partman--2.2.3--2.3.0, item 13).", "schema": null, "sql": "/*\n * Apply foreign keys that exist on the given parent to the given child table\n */\nCREATE OR REPLACE FUNCTION apply_foreign_keys(p_parent_table text, p_child_table text, p_job_id bigint DEFAULT NULL, p_debug boolean DEFAULT false) RETURNS void\n LANGUAGE plpgsql\n AS $$\nDECLARE\n\nex_context text;\nex_detail text;\nex_hint text;\nex_message text;\nv_count int := 0;\nv_job_id bigint;\nv_jobmon text;\nv_jobmon_schema text;\nv_old_search_path text;\nv_parent_schema text;\nv_parent_tablename text;\nv_ref_schema text;\nv_ref_table text;\nv_row record;\nv_schemaname text;\nv_sql text;\nv_step_id bigint;\nv_tablename text;\n\nBEGIN\n\nSELECT jobmon INTO v_jobmon FROM @extschema@.part_config WHERE parent_table = p_parent_table;\n\nIF v_jobmon THEN\n SELECT nspname INTO v_jobmon_schema FROM pg_catalog.pg_namespace n, pg_catalog.pg_extension e WHERE e.extname = 'pg_jobmon' AND e.extnamespace = n.oid;\n IF v_jobmon_schema IS NOT NULL THEN\n SELECT current_setting('search_path') INTO v_old_search_path;\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', '@extschema@,'||v_jobmon_schema, 'false');\n END IF;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n IF p_job_id IS NULL THEN\n v_job_id := add_job(format('PARTMAN APPLYING FOREIGN KEYS: %s', p_parent_table));\n ELSE -- Don't create a new job, add steps into given job\n v_job_id := p_job_id;\n END IF;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, format('Applying foreign keys to %s if they exist on parent', p_child_table));\nEND IF;\n\nSELECT schemaname, tablename INTO v_parent_schema, v_parent_tablename\nFROM pg_catalog.pg_tables\nWHERE schemaname = split_part(p_parent_table, '.', 1)\nAND tablename = split_part(p_parent_table, '.', 2);\n\nSELECT schemaname, tablename INTO v_schemaname, v_tablename\nFROM pg_catalog.pg_tables\nWHERE schemaname = split_part(p_child_table, '.', 1)\nAND tablename = split_part(p_child_table, '.', 2);\n\nIF v_tablename IS NULL THEN\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'CRITICAL', format('Target child table (%s) does not exist.', p_child_table));\n PERFORM fail_job(v_job_id);\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');\n END IF;\n RAISE EXCEPTION 'Target child table (%) does not exist.', p_child_table;\n RETURN;\nEND IF;\n\nFOR v_row IN\n SELECT pg_get_constraintdef(con.oid) AS constraint_def\n FROM pg_catalog.pg_constraint con\n JOIN pg_catalog.pg_class c ON con.conrelid = c.oid\n JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid\n WHERE c.relname = v_parent_tablename\n AND n.nspname = v_parent_schema\n AND contype = 'f'\nLOOP\n v_sql := format('ALTER TABLE %I.%I ADD %s'\n , v_schemaname\n , v_tablename\n , v_row.constraint_def);\n\n IF p_debug THEN\n RAISE NOTICE 'Constraint creation query: %', v_sql;\n END IF;\n\n EXECUTE v_sql;\n\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'FK applied');\n END IF;\n v_count := v_count + 1;\n\nEND LOOP;\n\nIF v_count = 0 AND v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'No FKs found on parent');\nEND IF;\n\n\nIF v_jobmon_schema IS NOT NULL THEN\n PERFORM close_job(v_job_id);\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');\nEND IF;\n\nEXCEPTION\n WHEN OTHERS THEN\n GET STACKED DIAGNOSTICS ex_message = MESSAGE_TEXT,\n ex_context = PG_EXCEPTION_CONTEXT,\n ex_detail = PG_EXCEPTION_DETAIL,\n ex_hint = PG_EXCEPTION_HINT;\n IF v_jobmon_schema IS NOT NULL THEN\n IF v_job_id IS NULL THEN\n EXECUTE format('SELECT %I.add_job(''PARTMAN CREATE APPLYING FOREIGN KEYS: %s'')', v_jobmon_schema, p_parent_table) INTO v_job_id;\n EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before job logging started'')', v_jobmon_schema, v_job_id, p_parent_table) INTO v_step_id;\n ELSIF v_step_id IS NULL THEN\n EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before first step logged'')', v_jobmon_schema, v_job_id) INTO v_step_id;\n END IF;\n EXECUTE format('SELECT %I.update_step(%s, ''CRITICAL'', %L)', v_jobmon_schema, v_step_id, 'ERROR: '||coalesce(SQLERRM,'unknown'));\n EXECUTE format('SELECT %I.fail_job(%s)', v_jobmon_schema, v_job_id);\n END IF;\n RAISE EXCEPTION '%\nCONTEXT: %\nDETAIL: %\nHINT: %', ex_message, ex_context, ex_detail, ex_hint;\nEND\n$$;", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 4817, "num_statements": 62} {"question": "pgTAP test for Hastap (assertion 153).", "schema": null, "sql": "/****************************************************************************/\n-- Test hasnt_cast().\n\nSELECT * FROM check_test(\n hasnt_cast( 'integer', 'bigint', 'pg_catalog', 'int8', 'desc' ),\n false,\n 'hasnt_cast( src, targ, schema, func, desc)',\n 'desc',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Hastap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 279, "num_statements": 1} {"question": "PostgreSQL regression test 'interval': Write the SELECT query (example 38).", "schema": null, "sql": "SELECT * FROM INTERVAL_TBL\n WHERE INTERVAL_TBL.f1 >= interval '@ 1 month';", "explanation": "Regression test for Interval in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM INTERVAL_TBL\n WHERE INTERVAL_TBL.f1 >= interval '@ 1 month') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 76, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'sqljson_queryfuncs' (example 242).", "schema": null, "sql": "CREATE INDEX ON test_jsonb_mutability (JSON_QUERY(js, '$[1, 0 to $.a ? (@.datetime() == $x)]' PASSING '12:34'::time AS x));", "explanation": "DDL from PostgreSQL core regression test for Sqljson Queryfuncs.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 123, "num_statements": 1} {"question": "pgTAP test for Hastap (assertion 6).", "schema": null, "sql": "CREATE TYPE public.sometype AS (\n id INT,\n name TEXT\n);", "explanation": "SQL assertion from pgTAP test suite for Hastap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 65, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'create_type' (example 1).", "schema": null, "sql": "-- directory path and dlsuffix are passed to us in environment variables\n\\getenv libdir PG_LIBDIR\n\\getenv dlsuffix PG_DLSUFFIX\n\n\\set regresslib :libdir '/regress' :dlsuffix\n\n--\n-- Test the \"old style\" approach of making the I/O functions first,\n-- with no explicit shell type creation.\n--\nCREATE FUNCTION widget_in(cstring)\n RETURNS widget\n AS :'regresslib'\n LANGUAGE C STRICT IMMUTABLE;", "explanation": "PL/pgSQL object from PostgreSQL core test for Create Type.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 393, "num_statements": 1} {"question": "pgTAP test for Hastap (assertion 247).", "schema": null, "sql": "SELECT * FROM check_test(\n hasnt_opclass( 'int4_ops', 'whatever' ),\n false,\n 'hasnt_opclass( name, desc )',\n 'whatever',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Hastap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 132, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (util_time, item 2).", "schema": null, "sql": "-- Return the minimum for the type. For time types, it will be the\n-- Unix timestamp in microseconds.\nCREATE OR REPLACE FUNCTION _timescaledb_functions.get_internal_time_max(REGTYPE) RETURNS BIGINT\nAS '@MODULE_PATHNAME@', 'ts_get_internal_time_max' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 291, "num_statements": 1} {"question": "PostgreSQL regression test 'dbsize': Write the SELECT query (example 4).", "schema": null, "sql": "SELECT size, pg_size_pretty(size), pg_size_pretty(-1 * size) FROM\n (VALUES (10239::numeric), (10240::numeric),\n (10485247::numeric), (10485248::numeric),\n (10736893951::numeric), (10736893952::numeric),\n (10994579406847::numeric), (10994579406848::numeric),\n (11258449312612351::numeric), (11258449312612352::numeric),\n (11528652096115048447::numeric), (11528652096115048448::numeric)) x(size);", "explanation": "Regression test for Dbsize in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT size, pg_size_pretty(size), pg_size_pretty(-1 * size) FROM\n (VALUES (10239::numeric), (10240::numeric),\n (10485247::numeric), (10485248::numeric),\n (10736893951::numeric), (10736893952::numeric),\n (10994579406847::numeric), (10994579406848::numeric),\n (11258449312612351::numeric), (11258449312612352::numeric),\n (11528652096115048447::numeric), (11528652096115048448::numeric)) x(size)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 452, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'matview' (example 23).", "schema": null, "sql": "CREATE VIEW mvtest_tvvmv AS SELECT * FROM mvtest_tvvm;", "explanation": "DDL from PostgreSQL core regression test for Matview.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Show a SQL definition from the pg_partman project (test-time-maintenance-order, item 7).", "schema": null, "sql": "CREATE TABLE partman_test.time_taptest_table3\n (col1 int\n , col2 text default 'stuff'\n , col3 timestamptz NOT NULL DEFAULT now())\n PARTITION BY RANGE (col3);", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 177, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 464).", "schema": null, "sql": "select jsonb_path_query('\"1.23aaa\"', '$.integer()');", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb_path_query('\"1.23aaa\"', '$.integer()')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": false, "sql_length": 52, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'foreign_key' (example 130).", "schema": null, "sql": "INSERT INTO PKTABLE VALUES (2, 4, 5, 'test4');", "explanation": "DML from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 46, "num_statements": 1} {"question": "PostgreSQL regression test 'date': Write the SELECT query (example 63).", "schema": null, "sql": "SELECT date '01 08 99';", "explanation": "Regression test for Date in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT date '01 08 99') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 23, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 936).", "schema": null, "sql": "INSERT INTO tru_ptable (SELECT x FROM generate_series(11,20) x);", "explanation": "Example query from the 'postgres_fdw' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 64, "num_statements": 1} {"question": "PostgreSQL regression test 'inherit': Write the SELECT query (example 34).", "schema": null, "sql": "SELECT relname, b.* FROM ONLY b, pg_class where b.tableoid = pg_class.oid;", "explanation": "Regression test for Inherit in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT relname, b.* FROM ONLY b, pg_class where b.tableoid = pg_class.oid) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 74, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'copy2' (example 142).", "schema": null, "sql": "CREATE FUNCTION truncate_in_subxact() RETURNS VOID AS\n$$\nBEGIN\n\tTRUNCATE vistest;\nEXCEPTION\n WHEN OTHERS THEN\n\tINSERT INTO vistest VALUES ('subxact failure');\nEND;\n$$ language plpgsql;", "explanation": "DDL from PostgreSQL core regression test for Copy2.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 185, "num_statements": 4} {"question": "Write the DDL statement from PostgreSQL regression test 'polymorphism' (example 105).", "schema": null, "sql": "CREATE AGGREGATE myaggn02b(*) (SFUNC = stfnp, STYPE = anyarray,\n INITCOND = '{}');", "explanation": "DDL from PostgreSQL core regression test for Polymorphism.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 83, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Void (example 2).", "schema": null, "sql": "-- illegal: can't return non-None value in void-returning func\nCREATE FUNCTION test_void_func2() RETURNS void AS $$\nreturn 10\n$$ LANGUAGE plpython3u;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Void.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "other", "is_postgresql_specific": true, "sql_length": 149, "num_statements": 1} {"question": "PostgreSQL regression test 'timestamptz': Write the SELECT query (example 301).", "schema": null, "sql": "SELECT '2011-03-27 02:59:59'::timestamp AT TIME ZONE 'MSK';", "explanation": "Regression test for Timestamptz in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT '2011-03-27 02:59:59'::timestamp AT TIME ZONE 'MSK') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'plpgsql' (example 759).", "schema": null, "sql": "UPDATE alter_table_under_transition_tables\n SET id = id;", "explanation": "DML from PostgreSQL core regression test for Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 57, "num_statements": 1} {"question": "Show a SQL definition from the zombodb project (zombodb--3000.0.6--3000.0.7, item 2).", "schema": null, "sql": "CREATE FUNCTION zdb.schema_version() RETURNS text LANGUAGE sql AS $$\nSELECT '3000.0.7 (90d8c41590be5fb35c99f5da14c1b134b0c863b9)'\n$$;", "explanation": "SQL definition from the open-source zombodb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 133, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'ltree' (example 130).", "schema": null, "sql": "SELECT 'a.b.c.d.e'::ltree ~ 'a.*{3}.e';", "explanation": "Example query from the 'ltree' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 39, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_index' (example 625).", "schema": null, "sql": "CREATE INDEX ON table2(col2);", "explanation": "DDL from PostgreSQL core regression test for Create Index.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 29, "num_statements": 1} {"question": "pgTAP test for Resultset (assertion 199).", "schema": null, "sql": "INSERT INTO names (name) VALUES ('Molly');", "explanation": "SQL assertion from pgTAP test suite for Resultset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 42, "num_statements": 1} {"question": "pgTAP test for Pgtap--0.94.0--0.95.0 (assertion 19).", "schema": null, "sql": "-- has_materialized_view( materialized_view )\nCREATE OR REPLACE FUNCTION has_materialized_view ( NAME )\nRETURNS TEXT AS $$\n SELECT has_materialized_view( $1, 'Materialized view ' || quote_ident($1) || ' should exist' );\n$$ LANGUAGE SQL;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--0.94.0--0.95.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 239, "num_statements": 2} {"question": "Write the DML statement from PostgreSQL regression test 'temp' (example 14).", "schema": null, "sql": "INSERT INTO temptest VALUES (2.1);", "explanation": "DML from PostgreSQL core regression test for Temp.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "PostgreSQL regression test 'float4': Write the SELECT query (example 30).", "schema": null, "sql": "SELECT * FROM pg_input_error_info('1e400', 'float4');", "explanation": "Regression test for Float4 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM pg_input_error_info('1e400', 'float4')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 53, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'bit' (example 50).", "schema": null, "sql": "INSERT INTO BIT_SHIFT_TABLE SELECT b>>4 FROM BIT_SHIFT_TABLE;", "explanation": "DML from PostgreSQL core regression test for Bit.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 61, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Types (example 96).", "schema": null, "sql": "SELECT * FROM test_type_conversion_array_date(ARRAY[[['2016-09-21','2016-09-22',NULL],[NULL,'2016-10-21','2016-10-22']],\n [[NULL,'2016-11-21','2016-10-21'],['2015-09-21','2015-09-22','2014-09-21']]]::date[]);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Types.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 219, "num_statements": 1} {"question": "PostgreSQL Xfunc: show example 32.", "schema": null, "sql": "CREATE OR REPLACE FUNCTION retcomposite(IN integer, IN integer, OUT f1 integer, OUT f2 integer, OUT f3 integer) RETURNS SETOF record AS ' filename ', 'retcomposite' LANGUAGE C IMMUTABLE STRICT;", "explanation": "Example from PostgreSQL documentation on Xfunc.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 193, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 385).", "schema": null, "sql": "SELECT replace('abcdefabcdef', 'cd'::citext, 'XX') = 'abXXefabXXef' AS t;", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 73, "num_statements": 1} {"question": "PostgreSQL regression test 'union': Write the SELECT query (example 22).", "schema": null, "sql": "SELECT f1 AS five FROM FLOAT8_TBL\n WHERE f1 BETWEEN -1e6 AND 1e6\nUNION\nSELECT f1 FROM INT4_TBL\n WHERE f1 BETWEEN 0 AND 1000000\nORDER BY 1;", "explanation": "Regression test for Union in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT f1 AS five FROM FLOAT8_TBL\n WHERE f1 BETWEEN -1e6 AND 1e6\nUNION\nSELECT f1 FROM INT4_TBL\n WHERE f1 BETWEEN 0 AND 1000000\nORDER BY 1) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 140, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'timestamptz' (example 102).", "schema": null, "sql": "INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 29 17:32:01 1996');", "explanation": "DML from PostgreSQL core regression test for Timestamptz.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "PostgreSQL regression test 'matview': Write the SELECT query (example 110).", "schema": null, "sql": "SELECT * FROM mvtest_mv_v_3;", "explanation": "Regression test for Matview in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM mvtest_mv_v_3) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 28, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'spi' (example 25).", "schema": null, "sql": "insert into fkeys values (10, '1', 2);", "explanation": "Example query from the 'spi' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 38, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 135).", "schema": null, "sql": "CREATE FUNCTION gbt_date_distance(internal,date,int2,oid,internal)\nRETURNS float8\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 145, "num_statements": 1} {"question": "pgTAP test for Resultset (assertion 447).", "schema": null, "sql": "PREPARE annames_ord AS SELECT id, name FROM annames ORDER BY id;", "explanation": "SQL assertion from pgTAP test suite for Resultset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 64, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 793).", "schema": null, "sql": "INSERT INTO num_input_test(n1) VALUES ('5 . 0');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 48, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'alter_table' (example 443).", "schema": null, "sql": "INSERT INTO ataddindex(f1) VALUES ('foo'), ('a');", "explanation": "DML from PostgreSQL core regression test for Alter Table.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 1} {"question": "PostgreSQL regression test 'geometry': Write the SELECT query (example 100).", "schema": null, "sql": "SELECT f1 AS open_path, polygon( pclose(f1)) AS polygon\n FROM PATH_TBL\n WHERE isopen(f1);", "explanation": "Regression test for Geometry in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT f1 AS open_path, polygon( pclose(f1)) AS polygon\n FROM PATH_TBL\n WHERE isopen(f1)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 93, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonpath': Write the SELECT query (example 70).", "schema": null, "sql": "select '$.boolean()'::jsonpath;", "explanation": "Regression test for Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '$.boolean()'::jsonpath) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 31, "num_statements": 1} {"question": "PostgreSQL regression test 'tstypes': Write the SELECT query (example 169).", "schema": null, "sql": "SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector, ARRAY['spaceship','rebel']);", "explanation": "Regression test for Tstypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector, ARRAY['spaceship','rebel'])) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 119, "num_statements": 1} {"question": "pgTAP test for Check (assertion 18).", "schema": null, "sql": "/****************************************************************************/\n-- Test col_has_check() with an array of columns.\n\nSET LOCAL client_min_messages = warning;", "explanation": "SQL assertion from pgTAP test suite for Check.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 170, "num_statements": 1} {"question": "PostgreSQL regression test 'regproc': Write the SELECT query (example 91).", "schema": null, "sql": "SELECT to_regtype('int3');", "explanation": "Regression test for Regproc in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT to_regtype('int3')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 26, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'numeric_big' (example 19).", "schema": null, "sql": "CREATE TABLE num_exp_power_10_ln (id int4, expected numeric(1000,800));", "explanation": "DDL from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 71, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'uuid' (example 7).", "schema": null, "sql": "INSERT INTO guid1(guid_field) VALUES('{22222222-2222-2222-2222-222222222222 ');", "explanation": "DML from PostgreSQL core regression test for Uuid.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 79, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 5).", "schema": null, "sql": "SELECT count(*) FROM bittmp WHERE a = '011011000100010111011000110000100';", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 76, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 56).", "schema": null, "sql": "CREATE FUNCTION lt_q_regex(ltree,_lquery)\nRETURNS bool\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 118, "num_statements": 1} {"question": "pgTAP test for Hastap (assertion 161).", "schema": null, "sql": "SELECT * FROM check_test(\n hasnt_cast( 'integer', 'clue', 'desc' ),\n true,\n 'hasnt_cast( src, targ, desc ) fail',\n 'desc',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Hastap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 144, "num_statements": 1} {"question": "Show an example of PostgreSQL INSERT (example 3).", "schema": null, "sql": "INSERT INTO films VALUES ('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'); INSERT INTO films (code, title, did, date_prod, kind) VALUES ('T_601', 'Yojimbo', 106, DEFAULT, 'Drama');", "explanation": "PostgreSQL INSERT command.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 190, "num_statements": 2} {"question": "pgTAP test for Pgtap--0.93.0--0.94.0 (assertion 3).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION _fprivs_are ( TEXT, NAME, NAME[], TEXT )\nRETURNS TEXT AS $$\nDECLARE\n grants TEXT[] := _get_func_privs($2, $1);\nBEGIN\n IF grants[1] = 'undefined_function' THEN\n RETURN ok(FALSE, $4) || E'\\n' || diag(\n ' Function ' || $1 || ' does not exist'\n );\n ELSIF grants[1] = 'undefined_role' THEN\n RETURN ok(FALSE, $4) || E'\\n' || diag(\n ' Role ' || quote_ident($2) || ' does not exist'\n );\n END IF;\n RETURN _assets_are('privileges', grants, $3, $4);\nEND;\n$$ LANGUAGE plpgsql;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--0.93.0--0.94.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 562, "num_statements": 7} {"question": "Write the DDL statement from PostgreSQL regression test 'publication' (example 140).", "schema": null, "sql": "CREATE PUBLICATION testpub_dups FOR TABLE testpub_rf_tbl1 WHERE (a = 1), testpub_rf_tbl1 WITH (publish = 'insert');", "explanation": "DDL from PostgreSQL core regression test for Publication.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 115, "num_statements": 1} {"question": "PostgreSQL regression test 'stats': Write the SELECT query (example 301).", "schema": null, "sql": "select a from stats_test_tab1 where a = 3;", "explanation": "Regression test for Stats in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select a from stats_test_tab1 where a = 3) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 42, "num_statements": 1} {"question": "PostgreSQL regression test 'interval': Write the SELECT query (example 393).", "schema": null, "sql": "SELECT i AS interval, date_trunc('week', i)\n FROM INFINITE_INTERVAL_TBL\n WHERE NOT isfinite(i);", "explanation": "Regression test for Interval in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT i AS interval, date_trunc('week', i)\n FROM INFINITE_INTERVAL_TBL\n WHERE NOT isfinite(i)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 101, "num_statements": 1} {"question": "PostgreSQL regression test 'tidrangescan': Write the SELECT query (example 27).", "schema": null, "sql": "SELECT ctid FROM tidrangescan WHERE '(1,7)' >= ctid AND ctid > '(1,4)';", "explanation": "Regression test for Tidrangescan in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT ctid FROM tidrangescan WHERE '(1,7)' >= ctid AND ctid > '(1,4)') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 71, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 27).", "schema": null, "sql": "CREATE FUNCTION pgp_pub_decrypt_bytea(bytea, bytea)\nRETURNS bytea\nAS 'MODULE_PATHNAME', 'pgp_pub_decrypt_bytea'\nLANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 154, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (create_hypertable, item 43).", "schema": null, "sql": "-- Test add_dimension: can use interval types for TIMESTAMPTZ columns\nCREATE TABLE dim_test_time(time TIMESTAMPTZ, time2 TIMESTAMPTZ, time3 BIGINT, temp float8, device int, location int);", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 187, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'triggers' (example 474).", "schema": null, "sql": "create trigger iocdu_tt_parted_update_trig\n after update on iocdu_tt_parted referencing old table as old_table new table as new_table\n for each statement execute procedure dump_update();", "explanation": "DDL from PostgreSQL core regression test for Triggers.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "dml_update", "is_postgresql_specific": true, "sql_length": 188, "num_statements": 1} {"question": "PostgreSQL regression test 'collate': Write the SELECT query (example 59).", "schema": null, "sql": "SELECT a, b FROM collate_test2 WHERE a < 4 INTERSECT SELECT a, b FROM collate_test2 WHERE a > 1 ORDER BY 2;", "explanation": "Regression test for Collate in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT a, b FROM collate_test2 WHERE a < 4 INTERSECT SELECT a, b FROM collate_test2 WHERE a > 1 ORDER BY 2) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 107, "num_statements": 1} {"question": "PL/pgSQL test: Pltcl Subxact (example 10).", "schema": null, "sql": "-- Test subtransaction rollback\n\nCREATE FUNCTION subtransaction_ctx_test(what_error text = NULL) RETURNS void\nAS $$\n spi_exec \"INSERT INTO subtransaction_tbl VALUES (1)\"\n subtransaction {\n spi_exec \"INSERT INTO subtransaction_tbl VALUES (2)\"\n if {$1 == \"SPI\"} {\n spi_exec \"INSERT INTO subtransaction_tbl VALUES ('oops')\"\n } elseif { $1 == \"Tcl\"} {\n elog ERROR \"Tcl error\"\n }\n }\n$$ LANGUAGE pltcl;", "explanation": "PL/pgSQL example from PostgreSQL source test for Pltcl Subxact.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 455, "num_statements": 1} {"question": "Show a SQL definition from the pg_partman project (pg_partman--2.2.0--2.2.1, item 1).", "schema": null, "sql": "/*\n * Function to manage pre-creation of the next partitions in a set.\n * Also manages dropping old partitions if the retention option is set.\n * If p_parent_table is passed, will only run run_maintenance() on that one table (no matter what the configuration table may have set for it)\n * Otherwise, will run on all tables in the config table with p_run_maintenance() set to true.\n * For large partition sets, running analyze can cause maintenance to take longer than expected. Can set p_analyze to false to avoid a forced analyze run.\n * Be aware that constraint exclusion may not work properly until an analyze on the partition set is run.\n */\nCREATE OR REPLACE FUNCTION run_maintenance(p_parent_table text DEFAULT NULL, p_analyze boolean DEFAULT true, p_jobmon boolean DEFAULT true, p_debug boolean DEFAULT false) RETURNS void\n LANGUAGE plpgsql SECURITY DEFINER\n AS $$\nDECLARE\n\nex_context text;\nex_detail text;\nex_hint text;\nex_message text;\nv_adv_lock boolean;\nv_check_subpart int;\nv_create_count int := 0;\nv_current_partition text;\nv_current_partition_id bigint;\nv_current_partition_timestamp timestamp;\nv_datetime_string text;\nv_drop_count int := 0;\nv_id_position int;\nv_job_id bigint;\nv_jobmon boolean;\nv_jobmon_schema text;\nv_last_partition text;\nv_last_partition_created boolean;\nv_last_partition_id bigint;\nv_last_partition_timestamp timestamp;\nv_max_id_parent bigint;\nv_max_time_parent timestamp;\nv_next_partition_id bigint;\nv_next_partition_timestamp timestamp;\nv_parent_schema text;\nv_parent_tablename text;\nv_premade_count int;\nv_premake_id_max bigint;\nv_premake_id_min bigint;\nv_premake_timestamp_min timestamp;\nv_premake_timestamp_max timestamp;\nv_quarter text;\nv_row record;\nv_row_max_id record;\nv_row_max_time record;\nv_row_sub record;\nv_skip_maint boolean;\nv_step_id bigint;\nv_step_overflow_id bigint;\nv_step_serial_id bigint;\nv_sub_id_max bigint;\nv_sub_id_max_suffix bigint;\nv_sub_id_min bigint;\nv_sub_parent text;\nv_sub_timestamp_max timestamp;\nv_sub_timestamp_max_suffix timestamp;\nv_sub_timestamp_min timestamp;\nv_tablename text;\nv_tables_list_sql text;\nv_time_position int;\nv_year text;\n\nBEGIN\n\nv_adv_lock := pg_try_advisory_xact_lock(hashtext('pg_partman run_maintenance'));\nIF v_adv_lock = 'false' THEN\n RAISE NOTICE 'Partman maintenance already running.';\n RETURN;\nEND IF;\n\nIF p_jobmon THEN\n SELECT nspname INTO v_jobmon_schema FROM pg_catalog.pg_namespace n, pg_catalog.pg_extension e WHERE e.extname = 'pg_jobmon' AND e.extnamespace = n.oid;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n EXECUTE format('SELECT %I.add_job(%L)', v_jobmon_schema, 'PARTMAN RUN MAINTENANCE') INTO v_job_id;\n EXECUTE format('SELECT %I.add_step(%L, %L)', v_jobmon_schema, v_job_id, 'Running maintenance loop') INTO v_step_id;\nEND IF;\n\n-- Check for consistent data in part_config_sub table. Was unable to get this working properly as either a constraint or trigger.\n-- Would either delay raising an error until the next write (which I cannot predict) or disallow future edits to update a sub-partition set's configuration.\n-- This way at least provides a consistent way to check that I know will run. If anyone can get a working constraint/trigger, please help!\n-- Don't have to worry about this in the serial trigger maintenance since subpartitioning requires run_maintenance().\nFOR v_row IN\n SELECT sub_parent FROM @extschema@.part_config_sub\nLOOP\n SELECT count(*) INTO v_check_subpart FROM @extschema@.check_subpart_sameconfig(v_row.sub_parent);\n IF v_check_subpart > 1 THEN\n RAISE EXCEPTION 'Inconsistent data in part_config_sub table. Sub-partition tables that are themselves sub-partitions cannot have differing configuration values among their siblings.\n Run this query: \"SELECT * FROM @extschema@.check_subpart_sameconfig(''%'');\" This should only return a single row or nothing.\n If multiple rows are returned, results are all children of the given parent. Update the differing values to be consistent for your desired values.', v_row.sub_parent;\n END IF;\nEND LOOP;\n\nv_row := NULL; -- Ensure it's reset\n\n\nv_tables_list_sql := 'SELECT parent_table\n , partition_type\n , partition_interval\n , control\n , premake\n , datetime_string\n , undo_in_progress\n , sub_partition_set_full\n , epoch\n FROM @extschema@.part_config\n WHERE sub_partition_set_full = false';\n\nIF p_parent_table IS NULL THEN\n v_tables_list_sql := v_tables_list_sql || ' AND use_run_maintenance = true';\nELSE\n v_tables_list_sql := v_tables_list_sql || format(' AND parent_table = %L', p_parent_table);\nEND IF;\n\nFOR v_row IN EXECUTE v_tables_list_sql\nLOOP\n\n CONTINUE WHEN v_row.undo_in_progress;\n v_skip_maint := true; -- reset every loop\n\n SELECT schemaname, tablename INTO v_parent_schema, v_parent_tablename FROM pg_catalog.pg_tables WHERE schemaname ||'.'|| tablename = v_row.parent_table;\n\n SELECT partition_tablename INTO v_last_partition FROM @extschema@.show_partitions(v_row.parent_table, 'DESC') LIMIT 1;\n IF p_debug THEN\n RAISE NOTICE 'run_maint: parent_table: %, v_last_partition: %', v_row.parent_table, v_last_partition;\n END IF;\n\n IF v_row.partition_type = 'time' OR v_row.partition_type = 'time-custom' THEN\n\n v_time_position := (length(v_last_partition) - position('p_' in reverse(v_last_partition))) + 2;\n IF v_row.partition_interval::interval <> '3 months' OR (v_row.partition_interval::interval = '3 months' AND v_row.partition_type = 'time-custom') THEN\n v_last_partition_timestamp := to_timestamp(substring(v_last_partition from v_time_position), v_row.datetime_string);\n ELSE\n -- to_timestamp doesn't recognize 'Q' date string formater. Handle it\n v_year := split_part(substring(v_last_partition FROM v_time_position), 'q', 1);\n v_quarter := split_part(substring(v_last_partition FROM v_time_position), 'q', 2);\n CASE\n WHEN v_quarter = '1' THEN\n v_last_partition_timestamp := to_timestamp(v_year || '-01-01', 'YYYY-MM-DD');\n WHEN v_quarter = '2' THEN\n v_last_partition_timestamp := to_timestamp(v_year || '-04-01', 'YYYY-MM-DD');\n WHEN v_quarter = '3' THEN\n v_last_partition_timestamp := to_timestamp(v_year || '-07-01', 'YYYY-MM-DD');\n WHEN v_quarter = '4' THEN\n v_last_partition_timestamp := to_timestamp(v_year || '-10-01', 'YYYY-MM-DD');\n END CASE;\n END IF;\n\n -- Loop through child tables starting from highest to get current max value in partition set\n -- Avoids doing a scan on entire partition set and/or getting any values accidentally in parent.\n FOR v_row_max_time IN\n SELECT partition_schemaname, partition_tablename FROM @extschema@.show_partitions(v_row.parent_table, 'DESC')\n LOOP\n IF v_row.epoch = false THEN\n EXECUTE format('SELECT max(%I)::text FROM %I.%I'\n , v_row.control\n , v_row_max_time.partition_schemaname\n , v_row_max_time.partition_tablename\n ) INTO v_current_partition_timestamp;\n ELSE\n EXECUTE format('SELECT to_timestamp(max(%I))::text FROM %I.%I'\n , v_row.control\n , v_row_max_time.partition_schemaname\n , v_row_max_time.partition_tablename\n ) INTO v_current_partition_timestamp;\n END IF;\n IF v_current_partition_timestamp IS NOT NULL THEN\n SELECT suffix_timestamp INTO v_current_partition_timestamp FROM @extschema@.show_partition_name(v_row.parent_table, v_current_partition_timestamp::text);\n EXIT;\n END IF;\n END LOOP;\n -- Check for values in the parent table. If they are there and greater than all child values, use that instead\n -- This allows maintenance to continue working properly if there is a large gap in data insertion. Data will remain in parent, but new tables will be created\n IF v_row.epoch = false THEN\n EXECUTE format('SELECT max(%I) FROM ONLY %I.%I', v_row.control, v_parent_schema, v_parent_tablename) INTO v_max_time_parent;\n ELSE\n EXECUTE format('SELECT to_timestamp(max(%I)) FROM ONLY %I.%I', v_row.control, v_parent_schema, v_parent_tablename) INTO v_max_time_parent;\n END IF;\n IF p_debug THEN\n RAISE NOTICE 'run_maint: v_current_partition_timestamp: %, v_max_time_parent: %', v_current_partition_timestamp, v_max_time_parent;\n END IF;\n IF v_max_time_parent > v_current_partition_timestamp THEN\n SELECT suffix_timestamp INTO v_current_partition_timestamp FROM @extschema@.show_partition_name(v_row.parent_table, v_max_time_parent::text);\n END IF;\n IF v_current_partition_timestamp IS NULL THEN\n -- Partition set is completely empty. Nothing to do\n CONTINUE;\n END IF;\n\n -- If this is a subpartition, determine if the last child table has been made. If so, mark it as full so future maintenance runs can skip it\n SELECT sub_min::timestamp, sub_max::timestamp INTO v_sub_timestamp_min, v_sub_timestamp_max FROM @extschema@.check_subpartition_limits(v_row.parent_table, 'time');\n IF v_sub_timestamp_max IS NOT NULL THEN\n SELECT suffix_timestamp INTO v_sub_timestamp_max_suffix FROM @extschema@.show_partition_name(v_row.parent_table, v_sub_timestamp_max::text);\n IF v_sub_timestamp_max_suffix = v_last_partition_timestamp THEN\n -- Final partition for this set is created. Set full and skip it\n UPDATE @extschema@.part_config SET sub_partition_set_full = true WHERE parent_table = v_row.parent_table;\n CONTINUE;\n END IF;\n END IF;\n\n -- Check and see how many premade partitions there are.\n v_premade_count = round(EXTRACT('epoch' FROM age(v_last_partition_timestamp, v_current_partition_timestamp)) / EXTRACT('epoch' FROM v_row.partition_interval::interval));\n v_next_partition_timestamp := v_last_partition_timestamp;\n IF p_debug THEN\n RAISE NOTICE 'run_maint before loop: current_partition_timestamp: %, v_premade_count: %, v_sub_timestamp_min: %, v_sub_timestamp_max: %'\n , v_current_partition_timestamp\n , v_premade_count\n , v_sub_timestamp_min\n , v_sub_timestamp_max;\n END IF;\n -- Loop premaking until config setting is met. Allows it to catch up if it fell behind or if premake changed\n WHILE (v_premade_count < v_row.premake) LOOP\n IF p_debug THEN\n RAISE NOTICE 'run_maint: parent_table: %, v_premade_count: %, v_next_partition_timestamp: %', v_row.parent_table, v_premade_count, v_next_partition_timestamp;\n END IF;\n IF v_next_partition_timestamp < v_sub_timestamp_min OR v_next_partition_timestamp > v_sub_timestamp_max THEN\n -- With subpartitioning, no need to run if the timestamp is not in the parent table's range\n EXIT;\n END IF;\n BEGIN\n v_next_partition_timestamp := v_next_partition_timestamp + v_row.partition_interval::interval;\n EXCEPTION WHEN datetime_field_overflow THEN\n v_premade_count := v_row.premake; -- do this so it can exit the premake check loop and continue in the outer for loop\n IF v_jobmon_schema IS NOT NULL THEN\n EXECUTE format('SELECT %I.add_step(%L, %L)', v_jobmon_schema, v_job_id, 'Attempted partition time interval is outside PostgreSQL''s supported time range.') INTO v_step_overflow_id;\n EXECUTE format('SELECT %I.update_step(%L, %L, %L)', v_jobmon_schema, v_step_overflow_id, 'CRITICAL', 'Child partition creation skippd for parent table '||v_partition_time);\n END IF;\n RAISE WARNING 'Attempted partition time interval is outside PostgreSQL''s supported time range. Child partition creation skipped for parent table %', v_row.parent_table;\n CONTINUE;\n END;\n v_last_partition_created := @extschema@.create_partition_time(v_row.parent_table, ARRAY[v_next_partition_timestamp], p_analyze);\n IF v_last_partition_created THEN\n v_create_count := v_create_count + 1;\n PERFORM @extschema@.create_function_time(v_row.parent_table, v_job_id);\n END IF;\n\n v_premade_count = round(EXTRACT('epoch' FROM age(v_next_partition_timestamp, v_current_partition_timestamp)) / EXTRACT('epoch' FROM v_row.partition_interval::interval));\n END LOOP;\n ELSIF v_row.partition_type = 'id' THEN\n -- Loop through child tables starting from highest to get current max value in partition set\n -- Avoids doing a scan on entire partition set and/or getting any values accidentally in parent.\n FOR v_row_max_id IN\n SELECT partition_schemaname, partition_tablename FROM @extschema@.show_partitions(v_row.parent_table, 'DESC')\n LOOP\n EXECUTE format('SELECT max(%I)::text FROM %I.%I'\n , v_row.control\n , v_row_max_id.partition_schemaname\n , v_row_max_id.partition_tablename) INTO v_current_partition_id;\n IF v_current_partition_id IS NOT NULL THEN\n SELECT suffix_id INTO v_current_partition_id FROM @extschema@.show_partition_name(v_row.parent_table, v_current_partition_id::text);\n EXIT;\n END IF;\n END LOOP;\n -- Check for values in the parent table. If they are there and greater than all child values, use that instead\n -- This allows maintenance to continue working properly if there is a large gap in data insertion. Data will remain in parent, but new tables will be created\n EXECUTE format('SELECT max(%I) FROM ONLY %I.%I', v_row.control, v_parent_schema, v_parent_tablename) INTO v_max_id_parent;\n IF v_max_id_parent > v_current_partition_id THEN\n SELECT suffix_id INTO v_current_partition_id FROM @extschema@.show_partition_name(v_row.parent_table, v_max_id_parent::text);\n END IF;\n IF v_current_partition_id IS NULL THEN\n -- Partition set is completely empty. Nothing to do\n CONTINUE;\n END IF;\n\n v_id_position := (length(v_last_partition) - position('p_' in reverse(v_last_partition))) + 2;\n v_last_partition_id = substring(v_last_partition from v_id_position)::bigint;\n -- Determine if this table is a child of a subpartition parent. If so, get limits to see if run_maintenance even needs to run for it.\n SELECT sub_min::bigint, sub_max::bigint INTO v_sub_id_min, v_sub_id_max FROM @extschema@.check_subpartition_limits(v_row.parent_table, 'id');\n IF v_sub_id_max IS NOT NULL THEN\n SELECT suffix_id INTO v_sub_id_max_suffix FROM @extschema@.show_partition_name(v_row.parent_table, v_sub_id_max::text);\n IF v_sub_id_max_suffix = v_last_partition_id THEN\n -- Final partition for this set is created. Set full and skip it\n UPDATE @extschema@.part_config SET sub_partition_set_full = true WHERE parent_table = v_row.parent_table;\n CONTINUE;\n END IF;\n END IF;\n\n v_next_partition_id := v_last_partition_id;\n v_premade_count := ((v_last_partition_id - v_current_partition_id) / v_row.partition_interval::bigint);\n -- Loop premaking until config setting is met. Allows it to catch up if it fell behind or if premake changed.\n WHILE (v_premade_count < v_row.premake) LOOP\n IF p_debug THEN\n RAISE NOTICE 'run_maint: parent_table: %, v_premade_count: %, v_next_partition_id: %', v_row.parent_table, v_premade_count, v_next_partition_id;\n END IF;\n IF v_next_partition_id < v_sub_id_min OR v_next_partition_id > v_sub_id_max THEN\n -- With subpartitioning, no need to run if the id is not in the parent table's range\n EXIT;\n END IF;\n v_next_partition_id := v_next_partition_id + v_row.partition_interval::bigint;\n v_last_partition_created := @extschema@.create_partition_id(v_row.parent_table, ARRAY[v_next_partition_id], p_analyze);\n IF v_last_partition_created THEN\n v_create_count := v_create_count + 1;\n PERFORM @extschema@.create_function_id(v_row.parent_table, v_job_id);\n END IF;\n v_premade_count := ((v_next_partition_id - v_current_partition_id) / v_row.partition_interval::bigint);\n END LOOP;\n\n END IF; -- end main IF check for time or id\n\n -- Manage additonal constraints if set\n PERFORM @extschema@.apply_constraints(p_parent_table := v_row.parent_table, p_job_id := v_job_id, p_debug := p_debug);\n\nEND LOOP; -- end of creation loop\n\n-- Manage dropping old partitions if retention option is set\nFOR v_row IN\n SELECT parent_table FROM @extschema@.part_config WHERE retention IS NOT NULL AND undo_in_progress = false AND\n (partition_type = 'time' OR partition_type = 'time-custom')\nLOOP\n IF p_parent_table IS NULL THEN\n v_drop_count := v_drop_count + @extschema@.drop_partition_time(v_row.parent_table);\n ELSE -- Only run retention on table given in parameter\n IF p_parent_table <> v_row.parent_table THEN\n CONTINUE;\n ELSE\n v_drop_count := v_drop_count + @extschema@.drop_partition_time(v_row.parent_table);\n END IF;\n END IF;\n IF v_drop_count > 0 THEN\n PERFORM @extschema@.create_function_time(v_row.parent_table, v_job_id);\n END IF;\nEND LOOP;\nFOR v_row IN\n SELECT parent_table FROM @extschema@.part_config WHERE retention IS NOT NULL AND undo_in_progress = false AND partition_type = 'id'\nLOOP\n IF p_parent_table IS NULL THEN\n v_drop_count := v_drop_count + @extschema@.drop_partition_id(v_row.parent_table);\n ELSE -- Only run retention on table given in parameter\n IF p_parent_table <> v_row.parent_table THEN\n CONTINUE;\n ELSE\n v_drop_count := v_drop_count + @extschema@.drop_partition_id(v_row.parent_table);\n END IF;\n END IF;\n IF v_drop_count > 0 THEN\n PERFORM @extschema@.create_function_id(v_row.parent_table, v_job_id);\n END IF;\nEND LOOP;\n\nIF v_jobmon_schema IS NOT NULL THEN\n EXECUTE format('SELECT %I.update_step(%L, %L, ''Partition maintenance finished. %s partitions made. %s partitions dropped.'')'\n , v_jobmon_schema\n , v_step_id\n , 'OK'\n , v_create_count\n , v_drop_count);\n IF v_step_overflow_id IS NOT NULL OR v_step_serial_id IS NOT NULL THEN\n EXECUTE format('SELECT %I.fail_job(%L)', v_jobmon_schema, v_job_id);\n ELSE\n EXECUTE format('SELECT %I.close_job(%L)', v_jobmon_schema, v_job_id);\n END IF;\nEND IF;\n\nEXCEPTION\n WHEN OTHERS THEN\n GET STACKED DIAGNOSTICS ex_message = MESSAGE_TEXT,\n ex_context = PG_EXCEPTION_CONTEXT,\n ex_detail = PG_EXCEPTION_DETAIL,\n ex_hint = PG_EXCEPTION_HINT;\n IF v_jobmon_schema IS NOT NULL THEN\n IF v_job_id IS NULL THEN\n EXECUTE format('SELECT %I.add_job(''PARTMAN RUN MAINTENANCE'')', v_jobmon_schema) INTO v_job_id;\n EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before job logging started'')', v_jobmon_schema, v_job_id, p_parent_table) INTO v_step_id;\n ELSIF v_step_id IS NULL THEN\n EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before first step logged'')', v_jobmon_schema, v_job_id) INTO v_step_id;\n END IF;\n EXECUTE format('SELECT %I.update_step(%s, ''CRITICAL'', %L)', v_jobmon_schema, v_step_id, 'ERROR: '||coalesce(SQLERRM,'unknown'));\n EXECUTE format('SELECT %I.fail_job(%s)', v_jobmon_schema, v_job_id);\n END IF;\n RAISE EXCEPTION '%\nCONTEXT: %\nDETAIL: %\nHINT: %', ex_message, ex_context, ex_detail, ex_hint;\nEND\n$$;", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 21291, "num_statements": 195} {"question": "PostgreSQL regression test 'json': Write the SELECT query (example 8).", "schema": null, "sql": "SELECT row_to_json(row((select array_agg(x) as d from generate_series(5,10) x)),false);", "explanation": "Regression test for Json in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT row_to_json(row((select array_agg(x) as d from generate_series(5,10) x)),false)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 87, "num_statements": 1} {"question": "PostgreSQL regression test 'pg_dependencies': Write the SELECT query (example 62).", "schema": null, "sql": "SELECT '[{\"attributes\" : [1,2], \"dependency\" : {}, \"degree\": 1.0}]'::pg_dependencies;", "explanation": "Regression test for Pg Dependencies in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT '[{\"attributes\" : [1,2], \"dependency\" : {}, \"degree\": 1.0}]'::pg_dependencies) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 85, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rules' (example 388).", "schema": null, "sql": "create table rule_and_refint_t2 (\n\tid2a integer,\n\tid2c integer,\n\n\tprimary key (id2a, id2c)\n);", "explanation": "DDL from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 93, "num_statements": 1} {"question": "PostgreSQL regression test 'aggregates': Write the SELECT query (example 86).", "schema": null, "sql": "SELECT corr(g, 0.09), regr_r2(g, 0.09), regr_slope(g, 0.09), regr_intercept(g, 0.09)\n FROM generate_series(1, 30) g;", "explanation": "Regression test for Aggregates in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT corr(g, 0.09), regr_r2(g, 0.09), regr_slope(g, 0.09), regr_intercept(g, 0.09)\n FROM generate_series(1, 30) g) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 117, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'hash_index' (example 48).", "schema": null, "sql": "UPDATE hash_f8_heap\n SET seqno = 20000\n WHERE hash_f8_heap.random = '488912369'::float8;", "explanation": "DML from PostgreSQL core regression test for Hash Index.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 92, "num_statements": 1} {"question": "PostgreSQL regression test 'rangetypes': Write the SELECT query (example 262).", "schema": null, "sql": "select count(*) from test_range_spgist where ir @> 10;", "explanation": "Regression test for Rangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select count(*) from test_range_spgist where ir @> 10) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 287).", "schema": null, "sql": "INSERT INTO caster (bitv) VALUES ('101'::citext);", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pg_buffercache' (example 37).", "schema": null, "sql": "SELECT * FROM pg_buffercache_mark_dirty(:max_buffers);", "explanation": "Example query from the 'pg_buffercache' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rules' (example 216).", "schema": null, "sql": "insert into rtest_nothn4 values (30, 'don''t want this');", "explanation": "DML from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 57, "num_statements": 1} {"question": "PostgreSQL regression test 'stats_import': Write the SELECT query (example 224).", "schema": null, "sql": "SELECT pg_catalog.pg_restore_extended_stats(\n 'schemaname', 'stats_import',\n 'relname', 'test',\n 'statistics_schemaname', 'stats_import',\n 'statistics_name', 'test_stat_mcv',\n 'inherited', false,\n 'most_common_vals', '{{four,NULL},\n {one,\"(1,1.1,ONE,01-01-2001,\\\"{\\\"\\\"xkey\\\"\\\": \\\"\\\"xval\\\"\\\"}\\\")\"},\n {tre,\"(3,3.3,TRE,03-03-2003,)\"},\n {two,\"(2,2.2,TWO,02-02-2002,\\\"[true, 4, \\\"\\\"six\\\"\\\"]\\\")\"}}'::text[],\n 'most_common_freqs', '{0.25,0.25,0.25,0.25}'::double precision[]);", "explanation": "Regression test for Stats Import in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT pg_catalog.pg_restore_extended_stats(\n 'schemaname', 'stats_import',\n 'relname', 'test',\n 'statistics_schemaname', 'stats_import',\n 'statistics_name', 'test_stat_mcv',\n 'inherited', false,\n 'most_common_vals', '{{four,NULL},\n {one,\"(1,1.1,ONE,01-01-2001,\\\"{\\\"\\\"xkey\\\"\\\": \\\"\\\"xval\\\"\\\"}\\\")\"},\n {tre,\"(3,3.3,TRE,03-03-2003,)\"},\n {two,\"(2,2.2,TWO,02-02-2002,\\\"[true, 4, \\\"\\\"six\\\"\\\"]\\\")\"}}'::text[],\n 'most_common_freqs', '{0.25,0.25,0.25,0.25}'::double precision[])) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 545, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'constraints' (example 185).", "schema": null, "sql": "UPDATE unique_tbl SET i = 2 WHERE i = 4 AND t = 'four';", "explanation": "DML from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 796).", "schema": null, "sql": "SELECT jsonb_path_exists('[{\"a\": 1}, {\"a\": 2}, {\"a\": 3}, {\"a\": 5}]', '$[*] ? (@.a > $min && @.a < $max)', vars => '{\"min\": 3, \"max\": 4}');", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT jsonb_path_exists('[{\"a\": 1}, {\"a\": 2}, {\"a\": 3}, {\"a\": 5}]', '$[*] ? (@.a > $min && @.a < $max)', vars => '{\"min\": 3, \"max\": 4}')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 138, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 492).", "schema": null, "sql": "DELETE FROM num_result;", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_delete", "is_postgresql_specific": false, "sql_length": 23, "num_statements": 1} {"question": "PostgreSQL regression test 'groupingsets': Write the SELECT query (example 66).", "schema": null, "sql": "select(select (select grouping(e,f) from (values (1)) v2(c)) from (values (1,2)) v1(a,b) group by (a,b)) from (values(6,7)) v3(e,f) GROUP BY ROLLUP(e,f);", "explanation": "Regression test for Groupingsets in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select(select (select grouping(e,f) from (values (1)) v2(c)) from (values (1,2)) v1(a,b) group by (a,b)) from (values(6,7)) v3(e,f) GROUP BY ROLLUP(e,f)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_aggregation", "is_postgresql_specific": true, "sql_length": 153, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pg_trgm' (example 12).", "schema": null, "sql": "select similarity('wow',' WOW ');", "explanation": "Example query from the 'pg_trgm' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 33, "num_statements": 1} {"question": "PostgreSQL regression test 'timestamp': Write the SELECT query (example 129).", "schema": null, "sql": "select date_bin('365000 days'::interval, '4400-01-01 BC'::timestamp, '4000-01-01 BC'::timestamp);", "explanation": "Regression test for Timestamp in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select date_bin('365000 days'::interval, '4400-01-01 BC'::timestamp, '4000-01-01 BC'::timestamp)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 97, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 360).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (8,7,'-82953604');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'cube' (example 82).", "schema": null, "sql": "SELECT '1'::cube < '2'::cube AS bool;", "explanation": "Example query from the 'cube' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 39, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'timestamptz' (example 58).", "schema": null, "sql": "INSERT INTO TIMESTAMPTZ_TBL VALUES ('97FEB10 5:32:01PM UTC');", "explanation": "DML from PostgreSQL core regression test for Timestamptz.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 61, "num_statements": 1} {"question": "PostgreSQL regression test 'arrays': Write the SELECT query (example 159).", "schema": null, "sql": "SELECT ARRAY[1,2] || ARRAY[3,4] AS \"{1,2,3,4}\";", "explanation": "Regression test for Arrays in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT ARRAY[1,2] || ARRAY[3,4] AS \"{1,2,3,4}\") AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 47, "num_statements": 1} {"question": "pgTAP test for Valueset (assertion 302).", "schema": null, "sql": "-- Fail with an extra record.\nSELECT * FROM check_test(\n set_eq(\n 'justnames',\n ARRAY['Andrew', 'Anna', 'Antonio', 'Angelina', 'Andrea', 'Angel' ]\n ),\n false,\n 'set_eq(prepared, array) extra record',\n '',\n ' Extra records:\n (Anthony)'\n);", "explanation": "SQL assertion from pgTAP test suite for Valueset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 279, "num_statements": 1} {"question": "PL/pgSQL test: Plpgsql Cache (example 7).", "schema": null, "sql": "$$;\n\nselect show_result_type('select 1 as a');\n-- currently this fails due to cached plan for pg_typeof expression\n-- (but if debug_discard_caches is on, it will succeed)\nselect show_result_type('select 2.0 as a');\n\n-- but it's OK if we force plan rebuilding\ndiscard plans;\nselect show_result_type('select 2.0 as a');", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpgsql Cache.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 317, "num_statements": 5} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 78).", "schema": null, "sql": "SELECT '[1,1,2]'::jsonb @> '[1,2,2]'::jsonb;", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT '[1,1,2]'::jsonb @> '[1,2,2]'::jsonb) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 44, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (size_utils, item 3).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION _timescaledb_functions.relation_approximate_size(relation REGCLASS)\nRETURNS TABLE (total_size BIGINT, heap_size BIGINT, index_size BIGINT, toast_size BIGINT)\nAS '@MODULE_PATHNAME@', 'ts_relation_approximate_size' LANGUAGE C STRICT VOLATILE;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 267, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 603).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION _do_ne( TEXT, TEXT, TEXT, TEXT );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 68, "num_statements": 1} {"question": "PostgreSQL regression test 'pg_ndistinct': Write the SELECT query (example 12).", "schema": null, "sql": "SELECT '[{\"attributes\" : [2,3], \"invalid\" : 3, \"ndistinct\" : 4}]'::pg_ndistinct;", "explanation": "Regression test for Pg Ndistinct in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT '[{\"attributes\" : [2,3], \"invalid\" : 3, \"ndistinct\" : 4}]'::pg_ndistinct) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 80, "num_statements": 1} {"question": "PostgreSQL regression test 'arrays': Write the SELECT query (example 215).", "schema": null, "sql": "select null::int = all ('{1,2,3}');", "explanation": "Regression test for Arrays in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select null::int = all ('{1,2,3}')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "PL/pgSQL test: Plpgsql Domain (example 4).", "schema": null, "sql": "SELECT * FROM test_argresult_booltrue(false, true);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpgsql Domain.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 51, "num_statements": 1} {"question": "pgTAP test for Ownership (assertion 102).", "schema": null, "sql": "/****************************************************************************/\n-- Test index_owner_is().\nSELECT * FROM check_test(\n index_owner_is('someschema', 'anothertab', 'idx_name', current_user, 'mumble'),\n\ttrue,\n 'index_owner_is(schema, table, index, user, desc)',\n 'mumble',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Ownership.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 301, "num_statements": 1} {"question": "PostgreSQL regression test 'object_address': Write the SELECT query (example 48).", "schema": null, "sql": "SELECT pg_get_object_address('schema', '{one}', '{}');", "explanation": "Regression test for Object Address in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT pg_get_object_address('schema', '{one}', '{}')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric_big' (example 263).", "schema": null, "sql": "INSERT INTO num_exp_sub VALUES (6,0,'.0469370721950711508944806393077762204079964905145503836835397203739563036579760026190241480514409364');", "explanation": "DML from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 141, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'foreign_key' (example 969).", "schema": null, "sql": "CREATE TABLE ref1_2 PARTITION OF ref FOR VALUES IN (1, 2) PARTITION BY list (f2);", "explanation": "DDL from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 81, "num_statements": 1} {"question": "pgTAP test for Policy (assertion 20).", "schema": null, "sql": "SELECT * FROM check_test(\n policies_are( 'public', 'passwd', ARRAY['root_all', 'all_view', 'user_mod', 'daemon_insert', 'daemon_delete'] ),\n true,\n 'policies_are(schema, table, policies)',\n 'Table public.passwd should have the correct policies',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Policy.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 267, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_join' (example 5).", "schema": null, "sql": "CREATE TABLE prt1_p2 PARTITION OF prt1 FOR VALUES FROM (250) TO (500);", "explanation": "DDL from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 70, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rules' (example 36).", "schema": null, "sql": "create rule rtest_t6_ins as on insert to rtest_t6\n\t\twhere new.a > 25 do instead\n\tinsert into rtest_t8 values (new.a, new.b);", "explanation": "DDL from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 124, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_split' (example 1).", "schema": null, "sql": "CREATE SCHEMA partition_split_schema;", "explanation": "DDL from PostgreSQL core regression test for Partition Split.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 37, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 286).", "schema": null, "sql": "INSERT INTO num_exp_mul VALUES (6,8,'7031444034.53149906');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_split' (example 109).", "schema": null, "sql": "CREATE TABLE sales (salesperson_id INT REFERENCES salespeople(salesperson_id), sales_amount INT, sales_date DATE);", "explanation": "DDL from PostgreSQL core regression test for Partition Split.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 114, "num_statements": 1} {"question": "PostgreSQL regression test 'create_operator': Write the SELECT query (example 21).", "schema": null, "sql": "SELECT false<=-1 BETWEEN 1 AND 1;", "explanation": "Regression test for Create Operator in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT false<=-1 BETWEEN 1 AND 1) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 33, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'replica_identity' (example 8).", "schema": null, "sql": "CREATE UNIQUE INDEX test_replica_identity_expr ON test_replica_identity (keya, keyb, (3));", "explanation": "DDL from PostgreSQL core regression test for Replica Identity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 90, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pgstattuple' (example 27).", "schema": null, "sql": "select pgstathashindex('test_ginidx');", "explanation": "Example query from the 'pgstattuple' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 38, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'arrays' (example 300).", "schema": null, "sql": "INSERT INTO arraggtest (f1, f2, f3) VALUES\n('{}','{{pink,white,blue,red,grey,orange}}','{2.1,1.87,1.4,2.2}');", "explanation": "DML from PostgreSQL core regression test for Arrays.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 109, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_view' (example 177).", "schema": null, "sql": "create view vv1 as select * from (tt5 cross join tt6) j(aa,bb,cc,dd);", "explanation": "DDL from PostgreSQL core regression test for Create View.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 69, "num_statements": 1} {"question": "PostgreSQL regression test 'tsearch': Write the SELECT query (example 219).", "schema": null, "sql": "SELECT to_tsquery('english', '1 <-> (2 <-> a)');", "explanation": "Regression test for Tsearch in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT to_tsquery('english', '1 <-> (2 <-> a)')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 48, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 69).", "schema": null, "sql": "SELECT JSON_VALUE(jsonb '1', 'strict $.a' DEFAULT 'error' ON ERROR);", "explanation": "Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_VALUE(jsonb '1', 'strict $.a' DEFAULT 'error' ON ERROR)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 68, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_join' (example 524).", "schema": null, "sql": "CREATE TABLE plt2_adv_p2 PARTITION OF plt2_adv FOR VALUES IN (NULL);", "explanation": "DDL from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 68, "num_statements": 1} {"question": "pgTAP test for Functap (assertion 325).", "schema": null, "sql": "-- Test diagnostics\nSELECT * FROM check_test(\n is_window( 'nooo' ),\n false,\n 'is_window(nowin)',\n 'Function nooo() should be a window function',\n ' Function nooo() does not exist'\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 200, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'ltree' (example 140).", "schema": null, "sql": "SELECT 'a.b.c.d.e'::ltree ~ '*{2,3}.e';", "explanation": "Example query from the 'ltree' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 39, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 85).", "schema": null, "sql": "SELECT JSON_VALUE(jsonb 'null', '$a' PASSING point ' (1, 2 )' AS a RETURNING point);", "explanation": "Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_VALUE(jsonb 'null', '$a' PASSING point ' (1, 2 )' AS a RETURNING point)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 84, "num_statements": 1} {"question": "PostgreSQL regression test 'polymorphism': Write the SELECT query (example 161).", "schema": null, "sql": "select f3, myaggn08a(f1) from t group by f3 order by f3;", "explanation": "Regression test for Polymorphism in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select f3, myaggn08a(f1) from t group by f3 order by f3) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_aggregation", "is_postgresql_specific": false, "sql_length": 56, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rowsecurity' (example 1175).", "schema": null, "sql": "CREATE POLICY p4 ON rls_tbl FOR DELETE USING (c1 <= 3);", "explanation": "DDL from PostgreSQL core regression test for Rowsecurity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_delete", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Trigger (example 127).", "schema": null, "sql": "CREATE FUNCTION transition_table_test_f() RETURNS trigger LANGUAGE plpython3u AS\n$$\n rv = plpy.execute(\"SELECT * FROM old_table\")\n assert(rv.nrows() == 1)\n plpy.info(\"old: \" + str(rv[0][\"id\"]) + \" -> \" + rv[0][\"name\"])\n rv = plpy.execute(\"SELECT * FROM new_table\")\n assert(rv.nrows() == 1)\n plpy.info(\"new: \" + str(rv[0][\"id\"]) + \" -> \" + rv[0][\"name\"])\n return None\n$$;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Trigger.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "plpgsql_trigger", "is_postgresql_specific": false, "sql_length": 391, "num_statements": 1} {"question": "PostgreSQL regression test 'pg_ndistinct': Write the SELECT query (example 37).", "schema": null, "sql": "SELECT '[{\"attributes\" : [2,3], \"ndistinct\" : null}]'::pg_ndistinct;", "explanation": "Regression test for Pg Ndistinct in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT '[{\"attributes\" : [2,3], \"ndistinct\" : null}]'::pg_ndistinct) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 68, "num_statements": 1} {"question": "pgTAP test for Functap (assertion 353).", "schema": null, "sql": "SELECT * FROM check_test(\n is_strict( 'yay', 'whatever' ),\n true,\n 'is_strict(func, desc)',\n 'whatever',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 126, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 32).", "schema": null, "sql": "--\n-- PGP key ID\n--\nCREATE FUNCTION pgp_key_id(bytea)\nRETURNS text\nAS 'MODULE_PATHNAME', 'pgp_key_id_w'\nLANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 146, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'encoding' (example 58).", "schema": null, "sql": "DROP FUNCTION test_wchars_to_text;", "explanation": "PL/pgSQL object from PostgreSQL core test for Encoding.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'update' (example 104).", "schema": null, "sql": "-- Enabling OLD TABLE capture for both DELETE as well as UPDATE stmt triggers\n-- should not cause DELETEd rows to be captured twice. Similar thing for\n-- INSERT triggers and inserted rows.\nCREATE TRIGGER trans_deletetrig\n AFTER DELETE ON range_parted REFERENCING OLD TABLE AS old_table\n FOR EACH STATEMENT EXECUTE PROCEDURE trans_updatetrigfunc();", "explanation": "PL/pgSQL object from PostgreSQL core test for Update.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 349, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 170).", "schema": null, "sql": "CREATE FUNCTION gbt_macad_union(internal, internal)\nRETURNS gbtreekey16\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "other", "is_postgresql_specific": false, "sql_length": 135, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_split' (example 190).", "schema": null, "sql": "CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Beijing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL);", "explanation": "DDL from PostgreSQL core regression test for Partition Split.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 163, "num_statements": 1} {"question": "PL/pgSQL test: Pltcl Subxact (example 5).", "schema": null, "sql": "INSERT INTO subtransaction_tbl VALUES(0);", "explanation": "PL/pgSQL example from PostgreSQL source test for Pltcl Subxact.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 41, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'hstore' (example 137).", "schema": null, "sql": "select pg_column_size(slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b','aa']))\n = pg_column_size('aa=>1, b=>2, c=>3'::hstore);", "explanation": "Example query from the 'hstore' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 133, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 7).", "schema": null, "sql": "CREATE FUNCTION gbt_ts_fetch(internal)\nRETURNS internal\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 105, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 284).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (6,8,'168782.57763026');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "PostgreSQL regression test 'tsearch': Write the SELECT query (example 2).", "schema": null, "sql": "SELECT oid, dictname\nFROM pg_ts_dict\nWHERE dictnamespace = 0 OR dictowner = 0 OR dicttemplate = 0;", "explanation": "Regression test for Tsearch in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT oid, dictname\nFROM pg_ts_dict\nWHERE dictnamespace = 0 OR dictowner = 0 OR dicttemplate = 0) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 98, "num_statements": 1} {"question": "PostgreSQL regression test 'window': Write the SELECT query (example 159).", "schema": null, "sql": "select id, f_numeric, first_value(id) over w, last_value(id) over w\nfrom numerics\nwindow w as (order by f_numeric range between\n 'inf' following and 'inf' following);", "explanation": "Regression test for Window in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select id, f_numeric, first_value(id) over w, last_value(id) over w\nfrom numerics\nwindow w as (order by f_numeric range between\n 'inf' following and 'inf' following)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 178, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 271).", "schema": null, "sql": "INSERT INTO caster (path) VALUES ('((0,0),(1,1),(2,0))'::citext);", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 74, "num_statements": 1} {"question": "Show a SQL definition from the citus project (multi_partitioning, item 9).", "schema": null, "sql": "CREATE TABLE partitioning_hash_test_0 PARTITION OF partitioning_hash_test FOR VALUES WITH (MODULUS 3, REMAINDER 0);", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 115, "num_statements": 1} {"question": "pgTAP test for Inheritance (assertion 144).", "schema": null, "sql": "SELECT * FROM check_test(\n isnt_descendent_of( 'nope', 'parent' ),\n true,\n 'isnt_descendent_of(nope, ptab)',\n 'Table nope should not be a descendent of parent',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Inheritance.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 182, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 120).", "schema": null, "sql": "--GiST support for ltree[]\nCREATE FUNCTION _ltree_consistent(internal,_ltree,int2,oid,internal)\nRETURNS bool\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 172, "num_statements": 1} {"question": "PostgreSQL regression test 'timestamptz': Write the SELECT query (example 303).", "schema": null, "sql": "SELECT '2011-03-27 03:00:01'::timestamp AT TIME ZONE 'MSK';", "explanation": "Regression test for Timestamptz in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT '2011-03-27 03:00:01'::timestamp AT TIME ZONE 'MSK') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Trigger (example 55).", "schema": null, "sql": "-- Unicode variant\n\nCREATE FUNCTION stupid3u() RETURNS trigger\nAS $$\n return \"foo\"\n$$ LANGUAGE plpython3u;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Trigger.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "plpgsql_trigger", "is_postgresql_specific": false, "sql_length": 109, "num_statements": 1} {"question": "PostgreSQL regression test 'merge': Write the SELECT query (example 507).", "schema": null, "sql": "SELECT tableoid::regclass, * FROM measurement ORDER BY city_id, logdate;", "explanation": "Regression test for Merge in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT tableoid::regclass, * FROM measurement ORDER BY city_id, logdate) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 72, "num_statements": 1} {"question": "pgTAP test for Functap (assertion 42).", "schema": null, "sql": "SELECT * FROM check_test(\n hasnt_function( 'decode', '{text,text}'::name[] ),\n false,\n 'simple function with 2 args',\n 'Function decode(text, text) should not exist',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 188, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 813).", "schema": null, "sql": "INSERT INTO num_input_test(n1) VALUES ('0x__1234');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 51, "num_statements": 1} {"question": "PostgreSQL regression test 'arrays': Write the SELECT query (example 306).", "schema": null, "sql": "select * from comptable;", "explanation": "Regression test for Arrays in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from comptable) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 24, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (compat, item 14).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION _timescaledb_internal.drop_chunk(chunk regclass) RETURNS boolean LANGUAGE PLPGSQL AS $$\nBEGIN\n IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN\n RAISE WARNING 'function _timescaledb_internal.drop_chunk(regclass) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';\n END IF;\n RETURN _timescaledb_functions.drop_chunk($1);\nEND$$\nSET search_path TO pg_catalog,pg_temp;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 509, "num_statements": 4} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 13).", "schema": null, "sql": "SELECT count(*) FROM timestamptmp WHERE a = '2004-10-26 08:55:08'::timestamp;", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 78, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 683).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION domain_type_is( NAME, TEXT, NAME, TEXT );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 76, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'insert' (example 117).", "schema": null, "sql": "insert into part_default values ('aa', 2);", "explanation": "DML from PostgreSQL core regression test for Insert.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 42, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'constraints' (example 54).", "schema": null, "sql": "INSERT INTO INSERT_TBL VALUES (7, '!check failed', -7);", "explanation": "DML from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 648).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION isa_ok( anyelement, regtype );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 647).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION isa_ok( anyelement, regtype, TEXT );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 71, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'brin_multi' (example 59).", "schema": null, "sql": "UPDATE brintest_multi SET int8col = int8col * int4col;", "explanation": "DML from PostgreSQL core regression test for Brin Multi.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "pgTAP test for Pgtap--1.0.0--1.1.0 (assertion 12).", "schema": null, "sql": "-- _keys( table, constraint_type )\nCREATE OR REPLACE FUNCTION _keys ( NAME, CHAR )\nRETURNS SETOF NAME[] AS $$\n SELECT _pg_sv_column_array(x.conrelid,x.conkey) -- name[] doesn't support collation\n FROM pg_catalog.pg_class c\n JOIN pg_catalog.pg_constraint x ON c.oid = x.conrelid\n AND c.relname = $1\n AND x.contype = $2\n WHERE pg_catalog.pg_table_is_visible(c.oid)\n ORDER BY 1\n$$ LANGUAGE sql;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--1.0.0--1.1.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 422, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'box' (example 4).", "schema": null, "sql": "INSERT INTO BOX_TBL (f1) VALUES ('((-8, 2), (-2, -10))');", "explanation": "DML from PostgreSQL core regression test for Box.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 57, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'arrays' (example 43).", "schema": null, "sql": "UPDATE arrtest\n SET c[NULL:1] = '{\"can''t assign\"}'\n WHERE array_dims(c) is not null;", "explanation": "DML from PostgreSQL core regression test for Arrays.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 87, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'join' (example 224).", "schema": null, "sql": "insert into tt3 select x, repeat('xyzzy', 100) from generate_series(1,10000) x;", "explanation": "DML from PostgreSQL core regression test for Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 79, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 240).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (5,7,'-83012087.961509');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 56, "num_statements": 1} {"question": "pgTAP test for Resultset (assertion 263).", "schema": null, "sql": "-- Handle fail with a dupe.\nSELECT * FROM check_test(\n set_ne(\n 'SELECT 1 AS a, ''Anna''::text UNION ALL SELECT 86, ''Angelina'' UNION ALL SELECT 1, ''Anna''',\n 'SELECT 1 AS a, ''Anna''::text UNION ALL SELECT 86, ''Angelina'''\n ),\n false,\n 'set_ne fail with dupe',\n '',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Resultset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 308, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'timestamp' (example 57).", "schema": null, "sql": "INSERT INTO TIMESTAMP_TBL VALUES ('97/02/10 17:32:01 UTC');", "explanation": "DML from PostgreSQL core regression test for Timestamp.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 177).", "schema": null, "sql": "CREATE FUNCTION gbt_bpchar_compress(internal)\nRETURNS internal\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 126, "num_statements": 1} {"question": "PostgreSQL regression test 'stats_ext': Write the SELECT query (example 606).", "schema": null, "sql": "SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE NOT a AND b AND NOT c');", "explanation": "Regression test for Stats Ext in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE NOT a AND b AND NOT c')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 95, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric_big' (example 91).", "schema": null, "sql": "INSERT INTO num_exp_sub VALUES (1,7,'818934540071930985.39540024977626076239847863600785982737155858270959890014613035727868293618673807776733416230953723818527101593495895350807775607346277892835514324320448949370623441059033804864158715021903312693889518990256881059434042443507529601095150710777634743301398926463888783847290873199395304998050753365215426971278237920063435565949203678024225270616295573678510929020831006146661747271783837653203039829647102027431761129518881525935216608429897041525858540380754759125150233053469999022855035');", "explanation": "DML from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 547, "num_statements": 1} {"question": "PostgreSQL regression test 'join': Write the SELECT query (example 706).", "schema": null, "sql": "select *, (select r from (select q1 as q2) x, lateral (select q2 as r) y) from int8_tbl;", "explanation": "Regression test for Join in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select *, (select r from (select q1 as q2) x, lateral (select q2 as r) y) from int8_tbl) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 88, "num_statements": 1} {"question": "PostgreSQL Xfunc: show example 53.", "schema": null, "sql": "SELECT mleast(ARRAY[10, -1, 5, 4.4]); -- doesn't work;", "explanation": "Example from PostgreSQL documentation on Xfunc.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 54, "num_statements": 2} {"question": "pgTAP test for Functap (assertion 34).", "schema": null, "sql": "SELECT * FROM check_test(\n hasnt_function( 'pg_catalog', 'now'::name ),\n false,\n 'simple schema.function',\n 'Function pg_catalog.now() should not exist',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 175, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'line' (example 21).", "schema": null, "sql": "INSERT INTO LINE_TBL VALUES (line(point '(1,0)', point '(1,0)'));", "explanation": "DML from PostgreSQL core regression test for Line.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "PostgreSQL regression test 'uuid': Write the SELECT query (example 17).", "schema": null, "sql": "SELECT guid_field FROM guid1 ORDER BY guid_field DESC;", "explanation": "Regression test for Uuid in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT guid_field FROM guid1 ORDER BY guid_field DESC) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 13).", "schema": null, "sql": "SELECT count(*) FROM moneytmp WHERE a = '22649.64'::money;", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 669).", "schema": null, "sql": "select '{\"aa\":1 , \"b\":2, \"cq\":3}'::jsonb || '{\"cq\":\"l\", \"b\":\"g\", \"fg\":false}';", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '{\"aa\":1 , \"b\":2, \"cq\":3}'::jsonb || '{\"cq\":\"l\", \"b\":\"g\", \"fg\":false}') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 78, "num_statements": 1} {"question": "Show a SQL definition from the citus project (chbenchmark_all_queries, item 14).", "schema": null, "sql": "CREATE TABLE item (\n i_id int NOT NULL,\n i_name varchar(24) NOT NULL,\n i_price decimal(5,2) NOT NULL,\n i_data varchar(50) NOT NULL,\n i_im_id int NOT NULL,\n PRIMARY KEY (i_id)\n);", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 195, "num_statements": 1} {"question": "pgTAP test for Functap (assertion 176).", "schema": null, "sql": "SELECT * FROM check_test(\n isnt_normal_function( 'public', 'tap_accum'::name ),\n true,\n 'isnt_normal_function(schema, agg)',\n 'Function public.tap_accum() should not be a normal function',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 210, "num_statements": 1} {"question": "Show a SQL definition from the citus project (multi_behavioral_analytics_create_table, item 46).", "schema": null, "sql": "CREATE INDEX is_index6 ON events_table(value_2);", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 48, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gin' (example 17).", "schema": null, "sql": "SELECT * FROM test_int8 WHERE i<1::int4 ORDER BY i;", "explanation": "Example query from the 'btree_gin' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 51, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 105).", "schema": null, "sql": "select * from jsonb_path_query('[1,\"1\",2,\"2\",null]', '$[*] ? (@ == $value)', '{\"value\" : \"1\"}');", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from jsonb_path_query('[1,\"1\",2,\"2\",null]', '$[*] ? (@ == $value)', '{\"value\" : \"1\"}')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": false, "sql_length": 96, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'rangefuncs' (example 363).", "schema": null, "sql": "-- without the \"offset 0\", this function gets optimized quite differently\n\ncreate function extractq2_2_opt(t int8_tbl) returns table(ret1 int8) as $$\n select extractq2(t)\n$$ language sql immutable;", "explanation": "PL/pgSQL object from PostgreSQL core test for Rangefuncs.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 198, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'seg' (example 63).", "schema": null, "sql": "SELECT '1.0(+-)0.005'::seg AS seg;", "explanation": "Example query from the 'seg' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "pgTAP test for Pgtap--0.94.0--0.95.0 (assertion 25).", "schema": null, "sql": "-- foreign_tables_are( tables )\nCREATE OR REPLACE FUNCTION foreign_tables_are ( NAME[] )\nRETURNS TEXT AS $$\n SELECT _are(\n 'foreign tables', _extras('f', $1), _missing('f', $1),\n 'Search path ' || pg_catalog.current_setting('search_path') || ' should have the correct foreign tables'\n );\n$$ LANGUAGE SQL;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--0.94.0--0.95.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 324, "num_statements": 2} {"question": "PostgreSQL regression test 'regproc': Write the SELECT query (example 126).", "schema": null, "sql": "SELECT * FROM pg_input_error_info('-', 'regoperator');", "explanation": "Regression test for Regproc in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM pg_input_error_info('-', 'regoperator')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'ltree' (example 320).", "schema": null, "sql": "SELECT count(*) FROM ltreetest WHERE t ~ '23.*.2';", "explanation": "Example query from the 'ltree' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 50, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rules' (example 242).", "schema": null, "sql": "insert into rtest_view1 values (2, 'item 2', 't');", "explanation": "DML from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 50, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'create_function_sql' (example 58).", "schema": null, "sql": "-- check display of function arguments in sub-SELECT\nCREATE TABLE functest1 (i int);", "explanation": "PL/pgSQL object from PostgreSQL core test for Create Function Sql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 84, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'generated_stored' (example 91).", "schema": null, "sql": "INSERT INTO gtest3a (a) VALUES ('a'), ('b'), ('c'), (NULL);", "explanation": "DML from PostgreSQL core regression test for Generated Stored.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "PostgreSQL regression test 'boolean': Write the SELECT query (example 20).", "schema": null, "sql": "SELECT bool 'on_' AS error;", "explanation": "Regression test for Boolean in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT bool 'on_' AS error) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 27, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'constraints' (example 376).", "schema": null, "sql": "CREATE TABLE notnull_tbl4_lk2 (LIKE notnull_tbl4 INCLUDING INDEXES);", "explanation": "DDL from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 68, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_join' (example 229).", "schema": null, "sql": "CREATE TABLE prt3_n_p2 PARTITION OF prt3_n FOR VALUES IN ('0001', '0002', '0008', '0010');", "explanation": "DDL from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 90, "num_statements": 1} {"question": "PostgreSQL regression test 'horology': Write the SELECT query (example 25).", "schema": null, "sql": "SELECT timestamp with time zone 'J2452271 04:05:06-08';", "explanation": "Regression test for Horology in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT timestamp with time zone 'J2452271 04:05:06-08') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "PostgreSQL regression test 'copy': Write the SELECT query (example 9).", "schema": null, "sql": "select * from copytest except select * from copytest2;", "explanation": "Regression test for Copy in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from copytest except select * from copytest2) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'test_decoding' (example 31).", "schema": null, "sql": "SELECT regexp_replace(data, '^(.{100}).*(.{100})$', '\\1..\\2') FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');", "explanation": "Example query from the 'test_decoding' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 173, "num_statements": 1} {"question": "Show an example of PostgreSQL CREATE ROLE (example 2).", "schema": null, "sql": "CREATE USER davide WITH PASSWORD 'jw8s0F4';", "explanation": "PostgreSQL CREATE ROLE command.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 43, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Spi (example 31).", "schema": null, "sql": "-- cursor objects\n\nCREATE FUNCTION simple_cursor_test() RETURNS int AS $$\nres = plpy.cursor(\"select fname, lname from users\")\ndoes = 0\nfor row in res:\n if row['lname'] == 'doe':\n does += 1\nreturn does\n$$ LANGUAGE plpython3u;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Spi.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 234, "num_statements": 1} {"question": "pgTAP test for Pgtap--0.94.0--0.95.0 (assertion 7).", "schema": null, "sql": "-- is_member_of( role, members[] )\nCREATE OR REPLACE FUNCTION is_member_of( NAME, NAME[] )\nRETURNS TEXT AS $$\n SELECT is_member_of( $1, $2, 'Should have members of role ' || quote_ident($1) );\n$$ LANGUAGE SQL;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--0.94.0--0.95.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 212, "num_statements": 2} {"question": "PostgreSQL regression test 'select_distinct': Write the SELECT query (example 75).", "schema": null, "sql": "SELECT 2 IS NOT DISTINCT FROM null as \"no\";", "explanation": "Regression test for Select Distinct in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT 2 IS NOT DISTINCT FROM null as \"no\") AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 43, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'triggers' (example 249).", "schema": null, "sql": "create trigger parted_trigger after update on parted_trigger\n for each row when (new.a % 2 = 1 and length(old.b) >= 2) execute procedure trigger_notice_ab();", "explanation": "DDL from PostgreSQL core regression test for Triggers.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "dml_update", "is_postgresql_specific": true, "sql_length": 158, "num_statements": 1} {"question": "PL/pgSQL test: Pltcl Subxact (example 2).", "schema": null, "sql": "--\n-- We use this wrapper to catch errors and return errormsg only,\n-- because values of $::errorinfo variable contain procedure name which\n-- includes OID, so it's not stable\n--\nCREATE FUNCTION pltcl_wrapper(statement text) RETURNS text\nAS $$\n if [catch {spi_exec $1} msg] {\n return \"ERROR: $msg\"\n } else {\n return \"SUCCESS: $msg\"\n }\n$$ LANGUAGE pltcl;", "explanation": "PL/pgSQL example from PostgreSQL source test for Pltcl Subxact.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 376, "num_statements": 1} {"question": "PostgreSQL regression test 'float8': Write the SELECT query (example 89).", "schema": null, "sql": "SELECT power(float8 '-inf', float8 '-3');", "explanation": "Regression test for Float8 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT power(float8 '-inf', float8 '-3')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 41, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonpath': Write the SELECT query (example 51).", "schema": null, "sql": "select '$.a[$a + 1, ($b[*]) to -($[0] * 2)]'::jsonpath;", "explanation": "Regression test for Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '$.a[$a + 1, ($b[*]) to -($[0] * 2)]'::jsonpath) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 19).", "schema": null, "sql": "CREATE FUNCTION dblink_close (text, text)\nRETURNS text\nAS 'MODULE_PATHNAME','dblink_close'\nLANGUAGE C STRICT PARALLEL RESTRICTED;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "other", "is_postgresql_specific": false, "sql_length": 129, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'tablesample' (example 52).", "schema": null, "sql": "create table parted_sample_1 partition of parted_sample for values in (1);", "explanation": "DDL from PostgreSQL core regression test for Tablesample.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 74, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 122).", "schema": null, "sql": "SELECT jsonb '{\"a\":null, \"b\":\"qq\"}' ? 'c';", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT jsonb '{\"a\":null, \"b\":\"qq\"}' ? 'c') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 42, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'arrays' (example 107).", "schema": null, "sql": "insert into arrtest_f values(2,'cat1',1.24);", "explanation": "DML from PostgreSQL core regression test for Arrays.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 14).", "schema": null, "sql": "SELECT count(*) FROM int8tmp WHERE a >= 464571291354841::int8;", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 62, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 371).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION has_cast ( NAME, NAME, NAME, NAME, TEXT );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 77, "num_statements": 1} {"question": "PostgreSQL regression test 'create_misc': Write the SELECT query (example 67).", "schema": null, "sql": "SELECT class, c FROM e_star* x WHERE x.c NOTNULL;", "explanation": "Regression test for Create Misc in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT class, c FROM e_star* x WHERE x.c NOTNULL) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 1} {"question": "PostgreSQL regression test 'expressions': Write the SELECT query (example 66).", "schema": null, "sql": "select * from inttest where a not in (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint,9::myint, null);", "explanation": "Regression test for Expressions in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from inttest where a not in (1::myint,2::myint,3::myint,4::myint,5::myint,6::myint,7::myint,8::myint,9::myint, null)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 126, "num_statements": 1} {"question": "Show a SQL definition from the citus project (multi_agg_approximate_distinct, item 22).", "schema": null, "sql": "CREATE TABLE test_count_distinct_schema.nation_hash(\n n_nationkey integer not null,\n n_name char(25) not null,\n n_regionkey integer not null,\n n_comment varchar(152)\n);", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 180, "num_statements": 1} {"question": "PostgreSQL regression test 'window': Write the SELECT query (example 7).", "schema": null, "sql": "SELECT depname, empno, salary, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary) ORDER BY rank() OVER w;", "explanation": "Regression test for Window in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT depname, empno, salary, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary) ORDER BY rank() OVER w) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 134, "num_statements": 1} {"question": "pgTAP test for Index (assertion 70).", "schema": null, "sql": "SELECT * FROM check_test(\n index_is_primary( 'sometab', 'sometab_pkey' ),\n true,\n 'index_is_primary() no schema',\n 'Index sometab_pkey should be on a primary key',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Index.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 185, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'int4' (example 6).", "schema": null, "sql": "INSERT INTO INT4_TBL(f1) VALUES ('- 1234');", "explanation": "DML from PostgreSQL core regression test for Int4.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 43, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 220).", "schema": null, "sql": "-- Create the operator class (intentionally not DEFAULT)\nCREATE OPERATOR CLASS gist_cidr_ops\nFOR TYPE cidr USING gist\nAS\n\tOPERATOR\t1\t< (inet, inet) ,\n\tOPERATOR\t2\t<= (inet, inet) ,\n\tOPERATOR\t3\t= (inet, inet) ,\n\tOPERATOR\t4\t>= (inet, inet) ,\n\tOPERATOR\t5\t> (inet, inet) ,\n\tOPERATOR\t6\t<> (inet, inet) ,\n\tFUNCTION\t1\tgbt_inet_consistent (internal, inet, int2, oid, internal),\n\tFUNCTION\t2\tgbt_inet_union (internal, internal),\n\tFUNCTION\t3\tgbt_inet_compress (internal),\n\tFUNCTION\t4\tgbt_decompress (internal),\n\tFUNCTION\t5\tgbt_inet_penalty (internal, internal, internal),\n\tFUNCTION\t6\tgbt_inet_picksplit (internal, internal),\n\tFUNCTION\t7\tgbt_inet_same (gbtreekey16, gbtreekey16, internal),\n\t-- no fetch support, the compress function is lossy\n\tFUNCTION\t11\tgbt_inet_sortsupport (internal),\n\tFUNCTION\t12 (\"any\", \"any\") gist_translate_cmptype_btree (int),\n\tSTORAGE\t\tgbtreekey16;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 865, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_view' (example 47).", "schema": null, "sql": "CREATE VIEW v6_temp AS SELECT * FROM base_table WHERE id IN (SELECT id FROM temp_table);", "explanation": "DDL from PostgreSQL core regression test for Create View.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 88, "num_statements": 1} {"question": "PL/pgSQL test: Plpgsql Domain (example 75).", "schema": null, "sql": "SELECT * FROM test_assign_ordered_named_pairs(1,2,0); -- should fail someday\n\nCREATE FUNCTION test_null_ordered_named_pair()\n RETURNS ordered_named_pair AS $$\ndeclare v ordered_named_pair;\nbegin\nreturn v;\nend\n$$ LANGUAGE plpgsql;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpgsql Domain.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 231, "num_statements": 4} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_prune' (example 292).", "schema": null, "sql": "create table ab_a2_b2 partition of ab_a2 for values in (2);", "explanation": "DDL from PostgreSQL core regression test for Partition Prune.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 352).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION _is_super( NAME );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 53, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rowtypes' (example 149).", "schema": null, "sql": "CREATE FUNCTION price_key_from_table(price) RETURNS price_key AS $$\n SELECT $1.id\n$$ LANGUAGE SQL;", "explanation": "DDL from PostgreSQL core regression test for Rowtypes.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 101, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rangetypes' (example 45).", "schema": null, "sql": "INSERT INTO numrange_test VALUES('[3,]');", "explanation": "DML from PostgreSQL core regression test for Rangetypes.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 41, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_jsontable': Write the SELECT query (example 80).", "schema": null, "sql": "SELECT * FROM JSON_TABLE(jsonb '\"world\"', '$' COLUMNS (item text FORMAT JSON PATH '$' WITH WRAPPER KEEP QUOTES));", "explanation": "Regression test for Sqljson Jsontable in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM JSON_TABLE(jsonb '\"world\"', '$' COLUMNS (item text FORMAT JSON PATH '$' WITH WRAPPER KEEP QUOTES))) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 113, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'fast_default' (example 3).", "schema": null, "sql": "CREATE TABLE m(id OID);", "explanation": "DDL from PostgreSQL core regression test for Fast Default.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 23, "num_statements": 1} {"question": "Show a SQL definition from the pg_partman project (pg_partman--2.3.2--2.3.3, item 14).", "schema": null, "sql": "/*\n * Function to create partitioning trigger on parent table\n */\nCREATE OR REPLACE FUNCTION create_trigger(p_parent_table text) RETURNS void\n LANGUAGE plpgsql SECURITY DEFINER\n AS $$\nDECLARE\n\nv_function_name text;\nv_new_length int;\nv_parent_schema text;\nv_parent_tablename text;\nv_trig_name text;\nv_trig_sql text;\n\nBEGIN\n\nSELECT schemaname, tablename INTO v_parent_schema, v_parent_tablename\nFROM pg_catalog.pg_tables\nWHERE schemaname = split_part(p_parent_table, '.', 1)::name\nAND tablename = split_part(p_parent_table, '.', 2)::name;\nv_trig_name := @extschema@.check_name_length(p_object_name := v_parent_tablename, p_suffix := '_part_trig');\n-- Ensure function name matches the naming pattern\nv_function_name := @extschema@.check_name_length(v_parent_tablename, '_part_trig_func', FALSE);\nv_trig_sql := format('CREATE TRIGGER %I BEFORE INSERT ON %I.%I FOR EACH ROW EXECUTE PROCEDURE %I.%I()'\n , v_trig_name\n , v_parent_schema\n , v_parent_tablename\n , v_parent_schema\n , v_function_name);\n\nEXECUTE v_trig_sql;\n\nEND\n$$;", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 1099, "num_statements": 12} {"question": "PostgreSQL regression test 'partition_aggregate': Write the SELECT query (example 102).", "schema": null, "sql": "SELECT a, sum(b), count(*) FROM pagg_tab_ml GROUP BY a HAVING avg(b) < 3 ORDER BY 1, 2, 3;", "explanation": "Regression test for Partition Aggregate in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT a, sum(b), count(*) FROM pagg_tab_ml GROUP BY a HAVING avg(b) < 3 ORDER BY 1, 2, 3) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_aggregation", "is_postgresql_specific": false, "sql_length": 90, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'foreign_key' (example 707).", "schema": null, "sql": "CREATE TABLE fk_partitioned_fk_2 (b int, a int,\n\tCONSTRAINT fk_part_con FOREIGN KEY (a, b) REFERENCES fk_notpartitioned_pk ON UPDATE CASCADE ON DELETE CASCADE NOT ENFORCED);", "explanation": "DDL from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 173, "num_statements": 1} {"question": "pgTAP test for Todotap (assertion 7).", "schema": null, "sql": "SELECT is(\n fail('This is a todo test' ) || '\n'\n || pass('This is a todo test that unexpectedly passes' ),\n 'not ok 6 - This is a todo test # TODO \n# Failed (TODO) test 6: \"This is a todo test\"\nok 7 - This is a todo test that unexpectedly passes # TODO ',\n 'TODO tests should display properly'\n);", "explanation": "SQL assertion from pgTAP test suite for Todotap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 309, "num_statements": 1} {"question": "PostgreSQL regression test 'polymorphism': Write the SELECT query (example 182).", "schema": null, "sql": "select first_el_agg_f8(x::float8) from generate_series(1,10) x;", "explanation": "Regression test for Polymorphism in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select first_el_agg_f8(x::float8) from generate_series(1,10) x) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pg_visibility' (example 22).", "schema": null, "sql": "select pg_visibility_map_summary('test_index');", "explanation": "Example query from the 'pg_visibility' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 47, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_aggregate' (example 40).", "schema": null, "sql": "CREATE TABLE pagg_tab1_p2 PARTITION OF pagg_tab1 FOR VALUES FROM (10) TO (20);", "explanation": "DDL from PostgreSQL core regression test for Partition Aggregate.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 78, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 221).", "schema": null, "sql": "INSERT INTO num_exp_sub VALUES (5,2,'34354889.253888047');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'lock' (example 10).", "schema": null, "sql": "CREATE VIEW lock_view6 AS SELECT * from (select * from lock_tbl1) sub;", "explanation": "DDL from PostgreSQL core regression test for Lock.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 70, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'cube' (example 131).", "schema": null, "sql": "SELECT '(-1),(1)'::cube @> '(-1),(1)'::cube AS bool;", "explanation": "Example query from the 'cube' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 77, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'aggregates' (example 299).", "schema": null, "sql": "create or replace view agg_view1 as\n select aggfns(a,b,c order by b+1)\n from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c);", "explanation": "DDL from PostgreSQL core regression test for Aggregates.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 149, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (truncate, item 13).", "schema": null, "sql": "CREATE VIEW dependent_view AS SELECT * FROM _timescaledb_internal._hyper_1_5_chunk;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 83, "num_statements": 1} {"question": "PostgreSQL regression test 'tidscan': Write the SELECT query (example 33).", "schema": null, "sql": "SELECT * FROM tidscan;", "explanation": "Regression test for Tidscan in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM tidscan) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 22, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'strings' (example 335).", "schema": null, "sql": "INSERT INTO toasttest values (repeat('1234567890',300));", "explanation": "DML from PostgreSQL core regression test for Strings.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 56, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'publication' (example 655).", "schema": null, "sql": "CREATE TABLE sch1.tbl1_part1 PARTITION OF sch1.tbl1 FOR VALUES FROM (1) to (10);", "explanation": "DDL from PostgreSQL core regression test for Publication.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 80, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 214).", "schema": null, "sql": "INSERT INTO caster (text) VALUES ('12'::int2);", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'test_decoding' (example 18).", "schema": null, "sql": "SELECT * FROM pg_stat_get_replication_slot('do-not-exist');", "explanation": "Example query from the 'test_decoding' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "PostgreSQL regression test 'name': Write the SELECT query (example 33).", "schema": null, "sql": "SELECT parse_ident(E'\"c\".X XXXX\\002XXXXXX');", "explanation": "Regression test for Name in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT parse_ident(E'\"c\".X XXXX\\002XXXXXX')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'create_operator' (example 45).", "schema": null, "sql": "-- Should fail. Procedure should be mandatorily specified\nCREATE OPERATOR #@%# (\n rightarg = int8\n);", "explanation": "PL/pgSQL object from PostgreSQL core test for Create Operator.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 102, "num_statements": 1} {"question": "PostgreSQL regression test 'interval': Write the SELECT query (example 178).", "schema": null, "sql": "select interval 'PT2562047788:00:54.775807';", "explanation": "Regression test for Interval in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select interval 'PT2562047788:00:54.775807') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_role' (example 46).", "schema": null, "sql": "CREATE DATABASE regress_nosuch_db;", "explanation": "DDL from PostgreSQL core regression test for Create Role.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 176).", "schema": null, "sql": "select jsonb '[1,2,3]' @? '$ ? (+@[*] > +2)';", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb '[1,2,3]' @? '$ ? (+@[*] > +2)') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 45, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 183).", "schema": null, "sql": "CREATE FUNCTION isnne(issn, issn13)\n\tRETURNS boolean\n\tAS 'int8ne'\n\tLANGUAGE 'internal'\n\tIMMUTABLE STRICT\n\tPARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 120, "num_statements": 1} {"question": "Show a SQL definition from the zombodb project (issue-864, item 8).", "schema": null, "sql": "CREATE OR REPLACE VIEW cake.cake_summary AS\nSELECT brand.pk_brand_id,\n brand.brand_name,\n (SELECT json_agg(row_to_json(cj.*)) AS json_agg\n FROM (SELECT flavor.pk_flavor,\n flavor.flv_name,\n flavor.flv_color\n FROM cake.flavor\n WHERE (brand.pk_brand_id = flavor.fk_flv_to_bd)) cj)::json AS flavor_data,\n cake.zdb_cake_bd_to_flavor(brand.*) AS zdb\nFROM cake.brand;", "explanation": "SQL definition from the open-source zombodb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 481, "num_statements": 1} {"question": "PostgreSQL regression test 'window': Write the SELECT query (example 69).", "schema": null, "sql": "SELECT sum(unique1) over (w range between unbounded preceding and current row exclude current row),\n\tunique1, four\nFROM tenk1 WHERE unique1 < 10 WINDOW w AS (order by four);", "explanation": "Regression test for Window in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT sum(unique1) over (w range between unbounded preceding and current row exclude current row),\n\tunique1, four\nFROM tenk1 WHERE unique1 < 10 WINDOW w AS (order by four)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_window_function", "is_postgresql_specific": true, "sql_length": 173, "num_statements": 1} {"question": "Show a SQL definition from the citus project (multi_alter_table_add_foreign_key_without_name, item 10).", "schema": null, "sql": "CREATE TABLE self_referencing_table(id int, ref_id int, PRIMARY KEY (id, ref_id));", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 82, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'equivclass' (example 7).", "schema": null, "sql": "create function int8alias2out(int8alias2) returns cstring\n strict immutable language internal as 'int8out';", "explanation": "DDL from PostgreSQL core regression test for Equivclass.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 108, "num_statements": 1} {"question": "Show a SQL definition from the pg_partman project (pg_partman--1.8.0--1.8.1, item 1).", "schema": null, "sql": "/*\n * Apply constraints managed by partman extension\n */\nCREATE OR REPLACE FUNCTION apply_constraints(p_parent_table text, p_child_table text DEFAULT NULL, p_analyze boolean DEFAULT FALSE, p_debug boolean DEFAULT FALSE) RETURNS void\n LANGUAGE plpgsql\n AS $$\nDECLARE\n\nv_child_table text;\nv_child_tablename text;\nv_col text;\nv_constraint_cols text[];\nv_constraint_col_type text;\nv_constraint_name text;\nv_datetime_string text;\nv_existing_constraint_name text;\nv_job_id bigint;\nv_jobmon boolean;\nv_jobmon_schema text;\nv_last_partition text;\nv_last_partition_id int;\nv_last_partition_timestamp timestamp;\nv_constraint_values record;\nv_old_search_path text;\nv_parent_schema text;\nv_parent_tablename text;\nv_part_interval text;\nv_partition_suffix text;\nv_premake int;\nv_sql text;\nv_step_id bigint;\nv_suffix_position int;\nv_type text;\n\nBEGIN\n\nSELECT type\n , part_interval\n , premake\n , datetime_string\n , constraint_cols\n , jobmon\nINTO v_type\n , v_part_interval\n , v_premake\n , v_datetime_string\n , v_constraint_cols\n , v_jobmon\nFROM @extschema@.part_config\nWHERE parent_table = p_parent_table;\n\nIF v_constraint_cols IS NULL THEN\n IF p_debug THEN\n RAISE NOTICE 'Given parent table (%) not set up for constraint management (constraint_cols is NULL)', p_parent_table;\n END IF;\n -- Returns silently to allow this function to be simply called by maintenance processes without having to check if config options are set.\n RETURN;\nEND IF;\n\nSELECT show_partitions INTO v_last_partition FROM @extschema@.show_partitions(p_parent_table, 'DESC') LIMIT 1;\n\nIF v_jobmon THEN\n SELECT nspname INTO v_jobmon_schema FROM pg_catalog.pg_namespace n, pg_catalog.pg_extension e WHERE e.extname = 'pg_jobmon' AND e.extnamespace = n.oid;\n IF v_jobmon_schema IS NOT NULL THEN\n SELECT current_setting('search_path') INTO v_old_search_path;\n EXECUTE 'SELECT set_config(''search_path'',''@extschema@,'||v_jobmon_schema||''',''false'')';\n END IF;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n v_job_id := add_job('PARTMAN CREATE CONSTRAINT: '||p_parent_table);\nEND IF;\n\nSELECT schemaname, tablename INTO v_parent_schema, v_parent_tablename FROM pg_tables WHERE schemaname ||'.'|| tablename = p_parent_table;\n\n-- If p_child_table is null, figure out the partition that is the one right before the premake value backwards.\nIF p_child_table IS NULL THEN\n\n IF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, 'Automatically determining most recent child on which to apply constraints');\n END IF;\n\n v_suffix_position := (length(v_last_partition) - position('p_' in reverse(v_last_partition))) + 2;\n\n IF v_type IN ('time-static', 'time-dynamic') THEN\n v_last_partition_timestamp := to_timestamp(substring(v_last_partition from v_suffix_position), v_datetime_string);\n v_partition_suffix := to_char(v_last_partition_timestamp - (v_part_interval::interval * ((v_premake * 2)+1) ), v_datetime_string);\n ELSIF v_type IN ('id-static', 'id-dynamic') THEN\n v_last_partition_id := substring(v_last_partition from v_suffix_position)::int;\n v_partition_suffix := (v_last_partition_id - (v_part_interval::int * ((v_premake * 2)+1) ))::text;\n END IF;\n\n v_child_table := @extschema@.check_name_length(v_parent_tablename, v_parent_schema, v_partition_suffix, TRUE);\n\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'Target child table: '||v_child_table);\n END IF;\nELSE\n v_child_table := p_child_table;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, 'Checking if target child table exists');\nEND IF;\n\nSELECT tablename INTO v_child_tablename FROM pg_catalog.pg_tables WHERE schemaname ||'.'|| tablename = v_child_table;\nIF v_child_tablename IS NULL THEN\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'NOTICE', 'Target child table ('||v_child_table||') does not exist. Skipping constraint creation.');\n PERFORM close_job(v_job_id);\n EXECUTE 'SELECT set_config(''search_path'','''||v_old_search_path||''',''false'')';\n END IF;\n IF p_debug THEN\n RAISE NOTICE 'Target child table (%) does not exist. Skipping constraint creation.', v_child_table;\n END IF;\n RETURN;\nELSE\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'Done');\n END IF;\nEND IF;\n\nFOREACH v_col IN ARRAY v_constraint_cols\nLOOP\n SELECT c.conname\n INTO v_existing_constraint_name\n FROM pg_catalog.pg_constraint c\n JOIN pg_catalog.pg_attribute a ON c.conrelid = a.attrelid\n WHERE conrelid = v_child_table::regclass\n AND c.conname LIKE 'partmanconstr_%'\n AND c.contype = 'c'\n AND a.attname = v_col\n AND ARRAY[a.attnum] <@ c.conkey\n AND a.attisdropped = false;\n\n IF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, 'Applying new constraint on column: '||v_col);\n END IF;\n\n IF v_existing_constraint_name IS NOT NULL THEN\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'NOTICE', 'Partman managed constraint already exists on this table ('||v_child_table||') and column ('||v_col||'). Skipping creation.');\n END IF;\n RAISE WARNING 'Partman managed constraint already exists on this table (%) and column (%). Skipping creation.', v_child_table, v_col ;\n CONTINUE;\n END IF;\n\n -- Ensure column name gets put on end of constraint name to help avoid naming conflicts\n v_constraint_name := @extschema@.check_name_length('partmanconstr_'||v_child_tablename, p_suffix := '_'||v_col);\n\n EXECUTE 'SELECT min('||v_col||')::text AS min, max('||v_col||')::text AS max FROM '||v_child_table INTO v_constraint_values;\n\n IF v_constraint_values IS NOT NULL THEN\n v_sql := concat('ALTER TABLE ', v_child_table, ' ADD CONSTRAINT ', v_constraint_name\n , ' CHECK (', v_col, ' >= ', quote_literal(v_constraint_values.min), ' AND '\n , v_col, ' <= ', quote_literal(v_constraint_values.max), ')' );\n IF p_debug THEN\n RAISE NOTICE 'Constraint creation query: %', v_sql;\n END IF;\n EXECUTE v_sql;\n\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'New constraint created: '||v_sql);\n END IF;\n ELSE\n IF p_debug THEN\n RAISE NOTICE 'Given column (%) contains all NULLs. No constraint created', v_col;\n END IF;\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'NOTICE', 'Given column ('||v_col||') contains all NULLs. No constraint created');\n END IF;\n END IF;\n\nEND LOOP;\n\nIF p_analyze THEN\n IF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, 'Running analyze on partition set: '||p_parent_table);\n END IF;\n IF p_debug THEN\n RAISE NOTICE 'Running analyze on partition set: %', p_parent_table;\n END IF;\n\n EXECUTE 'ANALYZE '||p_parent_table;\n\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'Done');\n END IF;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n PERFORM close_job(v_job_id);\n EXECUTE 'SELECT set_config(''search_path'','''||v_old_search_path||''',''false'')';\nEND IF;\n\nEXCEPTION\n WHEN OTHERS THEN\n IF v_jobmon_schema IS NOT NULL THEN\n IF v_job_id IS NULL THEN\n EXECUTE 'SELECT '||v_jobmon_schema||'.add_job(''PARTMAN CREATE CONSTRAINT: '||p_parent_table||''')' INTO v_job_id;\n EXECUTE 'SELECT '||v_jobmon_schema||'.add_step('||v_job_id||', ''EXCEPTION before job logging started'')' INTO v_step_id;\n ELSIF v_step_id IS NULL THEN\n EXECUTE 'SELECT '||v_jobmon_schema||'.add_step('||v_job_id||', ''EXCEPTION before first step logged'')' INTO v_step_id;\n END IF;\n EXECUTE 'SELECT '||v_jobmon_schema||'.update_step('||v_step_id||', ''CRITICAL'', ''ERROR: '||coalesce(SQLERRM,'unknown')||''')';\n EXECUTE 'SELECT '||v_jobmon_schema||'.fail_job('||v_job_id||')';\n END IF;\n RAISE EXCEPTION '%', SQLERRM;\nEND\n$$;", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 8579, "num_statements": 107} {"question": "Write the DML statement from PostgreSQL regression test 'truncate' (example 3).", "schema": null, "sql": "INSERT INTO truncate_a VALUES (2);", "explanation": "DML from PostgreSQL core regression test for Truncate.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'window' (example 89).", "schema": null, "sql": "CREATE OR REPLACE TEMP VIEW v_window AS\n\tSELECT i, sum(i) over (order by i groups between 1 preceding and 1 following) as sum_rows FROM generate_series(1, 10) i;", "explanation": "DDL from PostgreSQL core regression test for Window.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "query_window_function", "is_postgresql_specific": true, "sql_length": 161, "num_statements": 1} {"question": "PostgreSQL regression test 'unicode': Write the SELECT query (example 7).", "schema": null, "sql": "SELECT normalize(U&'\\0061\\0308\\24D1c', NFC) = U&'\\00E4\\24D1c' COLLATE \"C\" AS test_nfc;", "explanation": "Regression test for Unicode in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT normalize(U&'\\0061\\0308\\24D1c', NFC) = U&'\\00E4\\24D1c' COLLATE \"C\" AS test_nfc) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 86, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 14).", "schema": null, "sql": "SELECT count(*) FROM int4tmp WHERE a >= 237::int4;", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 50, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'equivclass' (example 44).", "schema": null, "sql": "create unique index ec1_expr1 on ec1((ff + 1));", "explanation": "DDL from PostgreSQL core regression test for Equivclass.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 47, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'domain' (example 155).", "schema": null, "sql": "create domain dcomptype as comptype check ((value).cf1 > 0);", "explanation": "DDL from PostgreSQL core regression test for Domain.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 60, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'foreign_key' (example 147).", "schema": null, "sql": "CREATE TABLE FKTABLE ( ftest1 int, ftest2 int, ftest3 int, ftest4 int, CONSTRAINT constrname3\n\t\t\tFOREIGN KEY(ftest1, ftest2, ftest3) REFERENCES PKTABLE (ptest1, ptest2, ptest3));", "explanation": "DDL from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 179, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_schema' (example 15).", "schema": null, "sql": "CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE\n CREATE VIEW schema_not_existing.view AS SELECT 1;", "explanation": "DDL from PostgreSQL core regression test for Create Schema.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 109, "num_statements": 1} {"question": "PostgreSQL regression test 'tablespace': Write the SELECT query (example 68).", "schema": null, "sql": "SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c\n where c.reltablespace = t.oid AND c.relname = 'foo_idx';", "explanation": "Regression test for Tablespace in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c\n where c.reltablespace = t.oid AND c.relname = 'foo_idx') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 139, "num_statements": 1} {"question": "PostgreSQL regression test 'temp': Write the SELECT query (example 101).", "schema": null, "sql": "select relname from pg_class where relname ~ '^temp_parted_oncommit_test';", "explanation": "Regression test for Temp in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select relname from pg_class where relname ~ '^temp_parted_oncommit_test') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 74, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (partitioning, item 1).", "schema": null, "sql": "-- Should expect an error when creating a hypertable from a partition\n\\set ON_ERROR_STOP 0\nCREATE TABLE partitioned_ht_create(time timestamptz, temp float, device int) PARTITION BY RANGE (time);", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 194, "num_statements": 1} {"question": "PostgreSQL Ddl: show example 81.", "schema": null, "sql": "REVOKE CREATE ON SCHEMA public FROM PUBLIC;", "explanation": "Example from PostgreSQL documentation on Ddl.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "dcl_security", "is_postgresql_specific": false, "sql_length": 43, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'window' (example 123).", "schema": null, "sql": "-- There is a syntactic ambiguity in the SQL standard. Since\n-- UNBOUNDED is a non-reserved word, it could be the name of a\n-- function parameter and be used as an expression. There is a\n-- grammar hack to resolve such cases as the keyword. The following\n-- tests record this behavior.\n\nCREATE FUNCTION unbounded_syntax_test1a(x int) RETURNS TABLE (a int, b int, c int)\nLANGUAGE SQL\nBEGIN ATOMIC\n SELECT sum(unique1) over (rows between x preceding and x following),\n unique1, four\n FROM tenk1 WHERE unique1 < 10;", "explanation": "PL/pgSQL object from PostgreSQL core test for Window.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 525, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 392).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (9,5,'-24910407.006556420');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "PostgreSQL regression test 'vacuum': Write the SELECT query (example 58).", "schema": null, "sql": "SELECT reltuples, relhassubclass\n FROM pg_class WHERE oid = 'past_inh_parent'::regclass;", "explanation": "Regression test for Vacuum in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT reltuples, relhassubclass\n FROM pg_class WHERE oid = 'past_inh_parent'::regclass) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 89, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Populate (example 19).", "schema": null, "sql": "INSERT INTO sequences (sequence, eid, product) VALUES ('ABCDEF', 5, 'env') ;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Populate.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 76, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (compat, item 2).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION _timescaledb_internal.attach_osm_table_chunk(hypertable regclass, chunk regclass) RETURNS boolean LANGUAGE PLPGSQL AS $$\nBEGIN\n IF current_setting('timescaledb.enable_deprecation_warnings', true)::bool THEN\n RAISE WARNING 'function _timescaledb_internal.attach_osm_table_chunk(regclass,regclass) is deprecated and has been moved to _timescaledb_functions schema. this compatibility function will be removed in a future version.';\n END IF;\n RETURN _timescaledb_functions.attach_osm_table_chunk($1,$2);\nEND$$\nSET search_path TO pg_catalog,pg_temp;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 578, "num_statements": 4} {"question": "pgTAP test for Functap (assertion 284).", "schema": null, "sql": "SELECT * FROM check_test(\n is_window( 'someschema', 'huh'::name, 'whatever' ),\n false,\n 'is_window(schema, func, desc)',\n 'whatever',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 155, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Populate (example 13).", "schema": null, "sql": "INSERT INTO entry (accession, txid) VALUES ('A00006', '3') ;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Populate.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 925).", "schema": null, "sql": "select jsonb_to_tsvector('english', '{\"a\": \"aaa in bbb\", \"b\": 123, \"c\": 456, \"d\": true, \"f\": false, \"g\": null}'::jsonb, '\"boolean\"');", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb_to_tsvector('english', '{\"a\": \"aaa in bbb\", \"b\": 123, \"c\": 456, \"d\": true, \"f\": false, \"g\": null}'::jsonb, '\"boolean\"')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 133, "num_statements": 1} {"question": "PostgreSQL regression test 'constraints': Write the SELECT query (example 47).", "schema": null, "sql": "SELECT * FROM INSERT_TBL;", "explanation": "Regression test for Constraints in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM INSERT_TBL) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 25, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_prune' (example 260).", "schema": null, "sql": "create table hp1 partition of hp for values with (modulus 4, remainder 1);", "explanation": "DDL from PostgreSQL core regression test for Partition Prune.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 74, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 619).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION set_hasnt( TEXT, TEXT, TEXT );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 465).", "schema": null, "sql": "SELECT count(*) FROM testjsonb WHERE j @? '$.public';", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT count(*) FROM testjsonb WHERE j @? '$.public') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 53, "num_statements": 1} {"question": "PostgreSQL regression test 'horology': Write the SELECT query (example 55).", "schema": null, "sql": "SELECT time without time zone 'T040506.07';", "explanation": "Regression test for Horology in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT time without time zone 'T040506.07') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 43, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'triggers' (example 581).", "schema": null, "sql": "$$;\nalter function whoami() owner to regress_fn_owner;\n\ncreate table defer_trig (id integer);\ngrant insert on defer_trig to public;\ncreate constraint trigger whoami after insert on defer_trig\n deferrable initially deferred\n for each row\n execute function whoami();\n\n-- deferred triggers must run as the user that queued the trigger\nbegin;\nset role regress_caller;\ninsert into defer_trig values (1);\nreset role;\nset role regress_fn_owner;\ninsert into defer_trig values (2);\nreset role;\ncommit;\n\n-- security definer functions override the user who queued the trigger\nalter function whoami() security definer;\nbegin;\nset role regress_caller;\ninsert into defer_trig values (3);\nreset role;\ncommit;\nalter function whoami() security invoker;\n\n-- make sure the current user is restored after error\ncreate or replace function whoami() returns trigger language plpgsql\nas $$\nbegin\n raise notice 'I am %', current_user;", "explanation": "PL/pgSQL object from PostgreSQL core test for Triggers.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 913, "num_statements": 21} {"question": "Write the DML statement from PostgreSQL regression test 'subselect' (example 144).", "schema": null, "sql": "insert into tb values(4,2);", "explanation": "DML from PostgreSQL core regression test for Subselect.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 27, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'jsonb' (example 431).", "schema": null, "sql": "INSERT INTO jsbpoptest\nSELECT '{\n\t\"jsa\": [1, \"2\", null, 4],\n\t\"rec\": {\"a\": \"abc\", \"c\": \"01.02.2003\", \"x\": 43.2},\n\t\"reca\": [{\"a\": \"abc\", \"b\": 456}, null, {\"c\": \"01.02.2003\", \"x\": 43.2}]\n}'::jsonb\nFROM generate_series(1, 3);", "explanation": "DML from PostgreSQL core regression test for Jsonb.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 221, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 279).", "schema": null, "sql": "INSERT INTO num_exp_div VALUES (6,6,'1.00000000000000000000');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 62, "num_statements": 1} {"question": "PostgreSQL Queries: show example 30.", "schema": null, "sql": "SELECT a + b AS sum, c FROM table1 ORDER BY sum; SELECT a, max(b) FROM table1 GROUP BY a ORDER BY 1;", "explanation": "Example from PostgreSQL documentation on Queries.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "query_aggregation", "is_postgresql_specific": false, "sql_length": 100, "num_statements": 2} {"question": "Show a SQL definition from the postgrest project (schema, item 7).", "schema": null, "sql": "CREATE TABLE items AS SELECT x AS id FROM generate_series(1,5) x;", "explanation": "SQL definition from the open-source postgrest PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "PostgreSQL regression test 'join': Write the SELECT query (example 727).", "schema": null, "sql": "select * from\n int8_tbl x left join (select q1,coalesce(q2,0) q2 from int8_tbl) y on x.q2 = y.q1,\n lateral (select x.q1,y.q1,y.q2) v(xq1,yq1,yq2);", "explanation": "Regression test for Join in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from\n int8_tbl x left join (select q1,coalesce(q2,0) q2 from int8_tbl) y on x.q2 = y.q1,\n lateral (select x.q1,y.q1,y.q2) v(xq1,yq1,yq2)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_join", "is_postgresql_specific": true, "sql_length": 148, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rowsecurity' (example 352).", "schema": null, "sql": "UPDATE t2 t2_1 SET b = t2_2.b FROM t2 t2_2\nWHERE t2_1.a = 3 AND t2_2.a = t2_1.a AND t2_2.b = t2_1.b\nAND f_leak(t2_1.b) AND f_leak(t2_2.b) RETURNING *, t2_1, t2_2;", "explanation": "DML from PostgreSQL core regression test for Rowsecurity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": true, "sql_length": 162, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 1006).", "schema": null, "sql": "SELECT count(*)\nFROM pg_foreign_server\nWHERE srvname = 'fetch101'\nAND srvoptions @> array['fetch_size=202'];", "explanation": "Example query from the 'postgres_fdw' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 108, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'cube' (example 13).", "schema": null, "sql": "SELECT '1e-300'::cube AS cube;", "explanation": "Example query from the 'cube' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 30, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'insert_conflict' (example 130).", "schema": null, "sql": "insert into insertconflictv values (1,'foo')\n on conflict (f1) do update set f2 = excluded.f2;", "explanation": "DML from PostgreSQL core regression test for Insert Conflict.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 95, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 11).", "schema": null, "sql": "SELECT count(*) FROM inettmp WHERE a <= '89.225.196.191'::inet;", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'foreign_key' (example 1044).", "schema": null, "sql": "CREATE TABLE fk (id int, a int DEFAULT 50) PARTITION BY RANGE (a);", "explanation": "DDL from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 66, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'foreign_key' (example 943).", "schema": null, "sql": "INSERT INTO fk VALUES (1);\t\t-- should fail\nBEGIN;", "explanation": "DML from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "plpgsql", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 2} {"question": "PostgreSQL regression test 'stats': Write the SELECT query (example 297).", "schema": null, "sql": "SELECT pg_stat_have_stats('database', :dboid, 0);", "explanation": "Regression test for Stats in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT pg_stat_have_stats('database', :dboid, 0)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rules' (example 166).", "schema": null, "sql": "insert into rtest_t9 values (28, 'Record should go to rtest_t4 and t8');", "explanation": "DML from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 72, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 267).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION has_index ( NAME, NAME, text );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 66, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'sqljson_queryfuncs' (example 240).", "schema": null, "sql": "CREATE INDEX ON test_jsonb_mutability (JSON_QUERY(js, '$.datetime(\"YY-MM-DD\") ? (@ == $x)' PASSING '2020-07-14'::date AS x));", "explanation": "DDL from PostgreSQL core regression test for Sqljson Queryfuncs.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 125, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'plpgsql' (example 498).", "schema": null, "sql": "$$ language plpgsql;\n\nselect raise_test();\n\ncreate or replace function raise_test() returns void as $$\nbegin\n raise division_by_zero;", "explanation": "PL/pgSQL object from PostgreSQL core test for Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 134, "num_statements": 3} {"question": "Show a SQL definition from the pg_partman project (pg_partman--2.3.1--2.3.2, item 14).", "schema": null, "sql": "/*\n * Check if parent table is a subpartition of an already existing partition set managed by pg_partman\n * If so, return the limits of what child tables can be created under the given parent table based on its own suffix\n */\nCREATE OR REPLACE FUNCTION check_subpartition_limits(p_parent_table text, p_type text, OUT sub_min text, OUT sub_max text) RETURNS record\n LANGUAGE plpgsql\n AS $$\nDECLARE\n\nv_datetime_string text;\nv_id_position int;\nv_parent_schema text;\nv_parent_tablename text;\nv_partition_interval interval;\nv_quarter text;\nv_sub_id_max bigint;\nv_sub_id_min bigint;\nv_sub_timestamp_max timestamp;\nv_sub_timestamp_min timestamp;\nv_time_position int;\nv_top_datetime_string text;\nv_top_interval text;\nv_top_parent text;\nv_top_type text;\nv_year text;\n\nBEGIN\n\nSELECT schemaname, tablename INTO v_parent_schema, v_parent_tablename\nFROM pg_catalog.pg_tables\nWHERE schemaname = split_part(p_parent_table, '.', 1)\nAND tablename = split_part(p_parent_table, '.', 2);\n\n-- CTE query is done individually for each type (time, id) because it should return NULL if the top parent is not the same type in a subpartition set (id->time or time->id)\n\nIF p_type = 'id' THEN\n\n WITH top_oid AS (\n SELECT i.inhparent AS top_parent_oid\n FROM pg_catalog.pg_class c\n JOIN pg_catalog.pg_inherits i ON c.oid = i.inhrelid\n JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n WHERE n.nspname = v_parent_schema\n AND c.relname = v_parent_tablename\n ) SELECT n.nspname||'.'||c.relname, p.datetime_string, p.partition_interval, p.partition_type\n INTO v_top_parent, v_top_datetime_string, v_top_interval, v_top_type\n FROM pg_catalog.pg_class c\n JOIN top_oid t ON c.oid = t.top_parent_oid\n JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n JOIN @extschema@.part_config p ON p.parent_table = n.nspname||'.'||c.relname\n WHERE c.oid = t.top_parent_oid\n AND p.partition_type = 'id';\n\n IF v_top_parent IS NOT NULL THEN\n SELECT child_start_id::text, child_end_id::text\n INTO sub_min, sub_max\n FROM @extschema@.show_partition_info(p_parent_table, v_top_interval, v_top_parent);\n END IF;\n\nELSIF p_type = 'time' THEN\n\n WITH top_oid AS (\n SELECT i.inhparent AS top_parent_oid\n FROM pg_catalog.pg_class c\n JOIN pg_catalog.pg_inherits i ON c.oid = i.inhrelid\n JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n WHERE n.nspname = v_parent_schema\n AND c.relname = v_parent_tablename\n ) SELECT n.nspname||'.'||c.relname, p.datetime_string, p.partition_interval, p.partition_type\n INTO v_top_parent, v_top_datetime_string, v_top_interval, v_top_type\n FROM pg_catalog.pg_class c\n JOIN top_oid t ON c.oid = t.top_parent_oid\n JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n JOIN @extschema@.part_config p ON p.parent_table = n.nspname||'.'||c.relname\n WHERE c.oid = t.top_parent_oid\n AND p.partition_type = 'time' OR p.partition_type = 'time-custom';\n\n IF v_top_parent IS NOT NULL THEN\n SELECT child_start_time::text, child_end_time::text\n INTO sub_min, sub_max\n FROM @extschema@.show_partition_info(p_parent_table, v_top_interval, v_top_parent);\n END IF;\n\nELSE\n RAISE EXCEPTION 'Invalid type given as parameter to check_subpartition_limits()';\nEND IF;\n\nRETURN;\n\nEND\n$$;", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 3523, "num_statements": 27} {"question": "pgTAP test for Hastap (assertion 121).", "schema": null, "sql": "/****************************************************************************/\n-- Test hasnt_domain().\nSELECT * FROM check_test(\n hasnt_domain( '__foobarbaz__' ),\n true,\n 'hasnt_domain(domain)',\n 'Domain __foobarbaz__ should not exist',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Hastap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 258, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 28).", "schema": null, "sql": "CREATE FUNCTION gin_extract_query_oid(oid, internal, int2, internal, internal)\nRETURNS internal\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT IMMUTABLE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 145, "num_statements": 1} {"question": "pgTAP test for Pgtap--1.2.0--1.3.0 (assertion 1).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION _runner( text[], text[], text[], text[], text[] )\nRETURNS SETOF TEXT AS $$\nDECLARE\n startup ALIAS FOR $1;\n shutdown ALIAS FOR $2;\n setup ALIAS FOR $3;\n teardown ALIAS FOR $4;\n tests ALIAS FOR $5;\n tap TEXT;\n tfaild INTEGER := 0;\n ffaild INTEGER := 0;\n tnumb INTEGER := 0;\n fnumb INTEGER := 0;\n tok BOOLEAN := TRUE;\nBEGIN\n BEGIN\n -- No plan support.\n PERFORM * FROM no_plan();\n FOR tap IN SELECT * FROM _runem(startup, false) LOOP RETURN NEXT tap; END LOOP;\n EXCEPTION\n -- Catch all exceptions and simply rethrow custom exceptions. This\n -- will roll back everything in the above block.\n WHEN raise_exception THEN RAISE EXCEPTION '%', SQLERRM;\n END;\n\n -- Record how startup tests have failed.\n tfaild := num_failed();\n\n FOR i IN 1..COALESCE(array_upper(tests, 1), 0) LOOP\n\n -- What subtest are we running?\n RETURN NEXT diag_test_name('Subtest: ' || tests[i]);\n\n -- Reset the results.\n tok := TRUE;\n tnumb := COALESCE(_get('curr_test'), 0);\n\n IF tnumb > 0 THEN\n EXECUTE 'ALTER SEQUENCE __tresults___numb_seq RESTART WITH 1';\n PERFORM _set('curr_test', 0);\n PERFORM _set('failed', 0);\n END IF;\n\n DECLARE\n errstate text;\n errmsg text;\n detail text;\n hint text;\n context text;\n schname text;\n tabname text;\n colname text;\n chkname text;\n typname text;\n BEGIN\n BEGIN\n -- Run the setup functions.\n FOR tap IN SELECT * FROM _runem(setup, false) LOOP\n RETURN NEXT regexp_replace(tap, '^', ' ', 'gn');\n END LOOP;\n\n -- Run the actual test function.\n FOR tap IN EXECUTE 'SELECT * FROM ' || tests[i] || '()' LOOP\n RETURN NEXT regexp_replace(tap, '^', ' ', 'gn');\n END LOOP;\n\n -- Run the teardown functions.\n FOR tap IN SELECT * FROM _runem(teardown, false) LOOP\n RETURN NEXT regexp_replace(tap, '^', ' ', 'gn');\n END LOOP;\n\n -- Emit the plan.\n fnumb := COALESCE(_get('curr_test'), 0);\n RETURN NEXT ' 1..' || fnumb;\n\n -- Emit any error messages.\n IF fnumb = 0 THEN\n RETURN NEXT ' # No tests run!';\n tok = false;\n ELSE\n -- Report failures.\n ffaild := num_failed();\n IF ffaild > 0 THEN\n tok := FALSE;\n RETURN NEXT ' ' || diag(\n 'Looks like you failed ' || ffaild || ' test' ||\n CASE ffaild WHEN 1 THEN '' ELSE 's' END\n || ' of ' || fnumb\n );\n END IF;\n END IF;\n\n EXCEPTION WHEN OTHERS THEN\n -- Something went wrong. Record that fact.\n errstate := SQLSTATE;\n errmsg := SQLERRM;\n GET STACKED DIAGNOSTICS\n detail = PG_EXCEPTION_DETAIL,\n hint = PG_EXCEPTION_HINT,\n context = PG_EXCEPTION_CONTEXT,\n schname = SCHEMA_NAME,\n tabname = TABLE_NAME,\n colname = COLUMN_NAME,\n chkname = CONSTRAINT_NAME,\n typname = PG_DATATYPE_NAME;\n END;\n\n -- Always raise an exception to rollback any changes.\n RAISE EXCEPTION '__TAP_ROLLBACK__';\n\n EXCEPTION WHEN raise_exception THEN\n IF errmsg IS NOT NULL THEN\n -- Something went wrong. Emit the error message.\n tok := FALSE;\n RETURN NEXT regexp_replace( diag('Test died: ' || _error_diag(\n errstate, errmsg, detail, hint, context, schname, tabname, colname, chkname, typname\n )), '^', ' ', 'gn');\n errmsg := NULL;\n END IF;\n END;\n\n -- Restore the sequence.\n EXECUTE 'ALTER SEQUENCE __tresults___numb_seq RESTART WITH ' || tnumb + 1;\n PERFORM _set('curr_test', tnumb);\n PERFORM _set('failed', tfaild);\n\n -- Record this test.\n RETURN NEXT ok(tok, tests[i]);\n IF NOT tok THEN tfaild := tfaild + 1; END IF;\n\n END LOOP;\n\n -- Run the shutdown functions.\n FOR tap IN SELECT * FROM _runem(shutdown, false) LOOP RETURN NEXT tap; END LOOP;\n\n -- Finish up.\n FOR tap IN SELECT * FROM _finish( COALESCE(_get('curr_test'), 0), 0, tfaild ) LOOP\n RETURN NEXT tap;\n END LOOP;\n\n -- Clean up and return.\n PERFORM _cleanup();\n RETURN;\nEND;\n$$ LANGUAGE plpgsql;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--1.2.0--1.3.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 4980, "num_statements": 74} {"question": "pgTAP test for Policy (assertion 62).", "schema": null, "sql": "SELECT * FROM check_test(\n policy_cmd_is( 'passwd', 'user_mod', 'all' ),\n false,\n 'policy_cmd_is(table, policy, command) for UPDATE should fail',\n 'Policy user_mod for table passwd should apply to ALL command',\n ' have: UPDATE\n want: ALL'\n);", "explanation": "SQL assertion from pgTAP test suite for Policy.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 270, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 7).", "schema": null, "sql": "SELECT count(*) FROM numerictmp WHERE a > -1890.0;", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 51, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 7).", "schema": null, "sql": "CREATE FUNCTION gbt_enum_same(gbtreekey8, gbtreekey8, internal)\nRETURNS internal\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 130, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 159).", "schema": null, "sql": "SELECT JSON_QUERY(jsonb '\"[3,4]\"', '$[*]' RETURNING bigint[] EMPTY OBJECT ON ERROR);", "explanation": "Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_QUERY(jsonb '\"[3,4]\"', '$[*]' RETURNING bigint[] EMPTY OBJECT ON ERROR)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 84, "num_statements": 1} {"question": "Show a SQL definition from the pg_partman project (pg_partman--2.3.2--2.3.3, item 4).", "schema": null, "sql": "/*\n * Apply constraints managed by partman extension\n */\nCREATE OR REPLACE FUNCTION apply_constraints(p_parent_table text, p_child_table text DEFAULT NULL, p_analyze boolean DEFAULT FALSE, p_job_id bigint DEFAULT NULL, p_debug boolean DEFAULT FALSE) RETURNS void\n LANGUAGE plpgsql\n AS $$\nDECLARE\n\nex_context text;\nex_detail text;\nex_hint text;\nex_message text;\nv_child_exists text;\nv_child_tablename text;\nv_col text;\nv_constraint_cols text[];\nv_constraint_col_type text;\nv_constraint_name text;\nv_constraint_values record;\nv_control text;\nv_datetime_string text;\nv_existing_constraint_name text;\nv_job_id bigint;\nv_jobmon boolean;\nv_jobmon_schema text;\nv_last_partition text;\nv_last_partition_id bigint;\nv_last_partition_timestamp timestamp;\nv_max_id bigint;\nv_max_timestamp timestamp;\nv_old_search_path text;\nv_optimize_constraint int;\nv_parent_schema text;\nv_parent_table text;\nv_parent_tablename text;\nv_partition_interval text;\nv_partition_suffix text;\nv_premake int;\nv_sql text;\nv_step_id bigint;\nv_suffix_position int;\nv_type text;\n\nBEGIN\n\nSELECT parent_table\n , partition_type\n , control\n , premake\n , partition_interval\n , optimize_constraint\n , datetime_string\n , constraint_cols\n , jobmon\nINTO v_parent_table\n , v_type\n , v_control\n , v_premake\n , v_partition_interval\n , v_optimize_constraint\n , v_datetime_string\n , v_constraint_cols\n , v_jobmon\nFROM @extschema@.part_config\nWHERE parent_table = p_parent_table\nAND constraint_cols IS NOT NULL;\n\nIF v_constraint_cols IS NULL THEN\n IF p_debug THEN\n RAISE NOTICE 'Given parent table (%) not set up for constraint management (constraint_cols is NULL)', p_parent_table;\n END IF;\n -- Returns silently to allow this function to be simply called by maintenance processes without having to check if config options are set.\n RETURN;\nEND IF;\n\nSELECT schemaname, tablename\nINTO v_parent_schema, v_parent_tablename\nFROM pg_catalog.pg_tables\nWHERE schemaname = split_part(v_parent_table, '.', 1)::name\nAND tablename = split_part(v_parent_table, '.', 2)::name;\n\nIF v_jobmon THEN\n SELECT nspname INTO v_jobmon_schema FROM pg_catalog.pg_namespace n, pg_catalog.pg_extension e WHERE e.extname = 'pg_jobmon' AND e.extnamespace = n.oid;\n IF v_jobmon_schema IS NOT NULL THEN\n SELECT current_setting('search_path') INTO v_old_search_path;\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', '@extschema@,'||v_jobmon_schema, 'false');\n END IF;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n IF p_job_id IS NULL THEN\n v_job_id := add_job(format('PARTMAN CREATE CONSTRAINT: %s', v_parent_table));\n ELSE\n v_job_id = p_job_id;\n END IF;\nEND IF;\n\n-- If p_child_table is null, figure out the partition that is the one right before the optimize_constraint value backwards.\nIF p_child_table IS NULL THEN\n IF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, 'Applying additional constraints: Automatically determining most recent child on which to apply constraints');\n END IF;\n\n SELECT partition_tablename INTO v_last_partition FROM @extschema@.show_partitions(v_parent_table, 'DESC') LIMIT 1;\n\n IF v_type IN ('time', 'time-custom') THEN\n SELECT child_start_time INTO v_last_partition_timestamp FROM @extschema@.show_partition_info(v_parent_schema||'.'||v_last_partition, v_partition_interval, v_parent_table);\n v_partition_suffix := to_char(v_last_partition_timestamp - (v_partition_interval::interval * (v_optimize_constraint + v_premake + 1) ), v_datetime_string);\n ELSIF v_type = 'id' THEN\n SELECT child_start_id INTO v_last_partition_id FROM @extschema@.show_partition_info(v_parent_schema||'.'||v_last_partition, v_partition_interval, v_parent_table);\n v_partition_suffix := (v_last_partition_id - (v_partition_interval::int * (v_optimize_constraint + v_premake + 1) ))::text;\n END IF;\n\n v_child_tablename := @extschema@.check_name_length(v_parent_tablename, v_partition_suffix, TRUE);\n\n IF p_debug THEN\n RAISE NOTICE 'apply_constraint: v_parent_tablename: % , v_partition_suffix: %', v_parent_tablename, v_partition_suffix;\n END IF;\n\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', format('Target child table: %s.%s', v_parent_schema, v_child_tablename));\n END IF;\nELSE\n v_child_tablename = split_part(p_child_table, '.', 2);\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, 'Applying additional constraints: Checking if target child table exists');\nEND IF;\n\nSELECT tablename FROM pg_catalog.pg_tables INTO v_child_exists WHERE schemaname = v_parent_schema::name AND tablename = v_child_tablename::name;\nIF v_child_exists IS NULL THEN\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'NOTICE', format('Target child table (%s) does not exist. Skipping constraint creation.', v_child_tablename));\n IF p_job_id IS NULL THEN\n PERFORM close_job(v_job_id);\n END IF;\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');\n END IF;\n IF p_debug THEN\n RAISE NOTICE 'Target child table (%) does not exist. Skipping constraint creation.', v_child_tablename;\n END IF;\n RETURN;\nELSE\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'Done');\n END IF;\nEND IF;\n\nFOREACH v_col IN ARRAY v_constraint_cols\nLOOP\n SELECT con.conname\n INTO v_existing_constraint_name\n FROM pg_catalog.pg_constraint con\n JOIN pg_class c ON c.oid = con.conrelid\n JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid\n JOIN pg_catalog.pg_attribute a ON con.conrelid = a.attrelid\n WHERE c.relname = v_child_tablename\n AND n.nspname = v_parent_schema\n AND con.conname LIKE 'partmanconstr_%'\n AND con.contype = 'c'\n AND a.attname = v_col\n AND ARRAY[a.attnum] OPERATOR(pg_catalog.<@) con.conkey\n AND a.attisdropped = false;\n\n IF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, format('Applying additional constraints: Applying new constraint on column: %s', v_col));\n END IF;\n\n IF v_existing_constraint_name IS NOT NULL THEN\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'NOTICE', format('Partman managed constraint already exists on this table (%s) and column (%s). Skipping creation.', v_child_tablename, v_col));\n END IF;\n IF p_debug THEN\n RAISE NOTICE 'Partman managed constraint already exists on this table (%) and column (%). Skipping creation.', v_child_tablename, v_col ;\n END IF;\n CONTINUE;\n END IF;\n\n -- Ensure column name gets put on end of constraint name to help avoid naming conflicts\n v_constraint_name := @extschema@.check_name_length('partmanconstr_'||v_child_tablename, p_suffix := '_'||v_col);\n\n EXECUTE format('SELECT min(%I)::text AS min, max(%I)::text AS max FROM %I.%I', v_col, v_col, v_parent_schema, v_child_tablename) INTO v_constraint_values;\n\n IF v_constraint_values IS NOT NULL THEN\n v_sql := format('ALTER TABLE %I.%I ADD CONSTRAINT %I CHECK (%I >= %L AND %I <= %L)'\n , v_parent_schema\n , v_child_tablename\n , v_constraint_name\n , v_col\n , v_constraint_values.min\n , v_col\n , v_constraint_values.max);\n IF p_debug THEN\n RAISE NOTICE 'Constraint creation query: %', v_sql;\n END IF;\n EXECUTE v_sql;\n\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', format('New constraint created: %s', v_sql));\n END IF;\n ELSE\n IF p_debug THEN\n RAISE NOTICE 'Given column (%) contains all NULLs. No constraint created', v_col;\n END IF;\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'NOTICE', format('Given column (%s) contains all NULLs. No constraint created', v_col));\n END IF;\n END IF;\n\nEND LOOP;\n\nIF p_analyze THEN\n IF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, format('Applying additional constraints: Running analyze on partition set: %s', v_parent_table));\n END IF;\n IF p_debug THEN\n RAISE NOTICE 'Running analyze on partition set: %', v_parent_table;\n END IF;\n\n EXECUTE format('ANALYZE %I.%I', v_parent_schema, v_parent_tablename);\n\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'Done');\n END IF;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n PERFORM close_job(v_job_id);\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');\nEND IF;\n\nEXCEPTION\n WHEN OTHERS THEN\n GET STACKED DIAGNOSTICS ex_message = MESSAGE_TEXT,\n ex_context = PG_EXCEPTION_CONTEXT,\n ex_detail = PG_EXCEPTION_DETAIL,\n ex_hint = PG_EXCEPTION_HINT;\n IF v_jobmon_schema IS NOT NULL THEN\n IF v_job_id IS NULL THEN\n EXECUTE format('SELECT %I.add_job(''PARTMAN CREATE CONSTRAINT: %s'')', v_jobmon_schema, p_parent_table) INTO v_job_id;\n EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before job logging started'')', v_jobmon_schema, v_job_id, p_parent_table) INTO v_step_id;\n ELSIF v_step_id IS NULL THEN\n EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before first step logged'')', v_jobmon_schema, v_job_id) INTO v_step_id;\n END IF;\n EXECUTE format('SELECT %I.update_step(%s, ''CRITICAL'', %L)', v_jobmon_schema, v_step_id, 'ERROR: '||coalesce(SQLERRM,'unknown'));\n EXECUTE format('SELECT %I.fail_job(%s)', v_jobmon_schema, v_job_id);\n END IF;\n RAISE EXCEPTION '%\nCONTEXT: %\nDETAIL: %\nHINT: %', ex_message, ex_context, ex_detail, ex_hint;\nEND\n$$;", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 10666, "num_statements": 122} {"question": "PostgreSQL regression test 'create_view': Write the SELECT query (example 235).", "schema": null, "sql": "select f1, f4 from tt14v;", "explanation": "Regression test for Create View in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select f1, f4 from tt14v) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 25, "num_statements": 1} {"question": "pgTAP test for Pgtap--1.1.0--1.2.0 (assertion 54).", "schema": null, "sql": "DROP FUNCTION _agg ( NAME, NAME );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--1.1.0--1.2.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'cluster' (example 13).", "schema": null, "sql": "CREATE TABLE clstr_tst_inh () INHERITS (clstr_tst);", "explanation": "DDL from PostgreSQL core regression test for Cluster.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 51, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'ltree' (example 210).", "schema": null, "sql": "SELECT 'ltree.awdfg'::ltree @ '!tree & aWdf@*'::ltxtquery;", "explanation": "Example query from the 'ltree' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "PostgreSQL regression test 'xml': Write the SELECT query (example 83).", "schema": null, "sql": "SELECT xmlserialize(document 'bad' as text);", "explanation": "Regression test for Xml in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT xmlserialize(document 'bad' as text)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "pgTAP test for Hastap (assertion 204).", "schema": null, "sql": "SELECT * FROM check_test(\n has_leftop( '+', 'int8' ),\n true,\n 'has_leftop( name, right )',\n 'Left operator +(NONE,int8) should exist',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Hastap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 146, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 954).", "schema": null, "sql": "select 'null'::jsonb::bool;", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select 'null'::jsonb::bool) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 27, "num_statements": 1} {"question": "PostgreSQL Xfunc: show example 1.", "schema": null, "sql": "INSERT INTO mytable VALUES ($1);", "explanation": "Example from PostgreSQL documentation on Xfunc.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 32, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gin' (example 30).", "schema": null, "sql": "SELECT * FROM test_int2 WHERE i<=32768::int4 ORDER BY i;", "explanation": "Example query from the 'btree_gin' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 56, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 209).", "schema": null, "sql": "SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t1.c1 OFFSET 100 LIMIT 10 FOR UPDATE;", "explanation": "Example query from the 'postgres_fdw' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "query_join", "is_postgresql_specific": true, "sql_length": 116, "num_statements": 1} {"question": "PL/pgSQL test: Plperl Trigger (example 4).", "schema": null, "sql": "CREATE TABLE trigger_test_generated (\n i int,\n j int GENERATED ALWAYS AS (i * 2) STORED,\n k int GENERATED ALWAYS AS (i * 3) VIRTUAL\n);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plperl Trigger.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 143, "num_statements": 1} {"question": "PostgreSQL regression test 'xml': Write the SELECT query (example 42).", "schema": null, "sql": "SELECT xmlelement(name foo, xmlattributes('<>&\"''' as funny, xml 'br' as funnier));", "explanation": "Regression test for Xml in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT xmlelement(name foo, xmlattributes('<>&\"''' as funny, xml 'br' as funnier))) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 87, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pageinspect' (example 40).", "schema": null, "sql": "insert into test9s values (131584);", "explanation": "Example query from the 'pageinspect' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "PostgreSQL regression test 'foreign_data': Write the SELECT query (example 243).", "schema": null, "sql": "SELECT * FROM information_schema.user_mapping_options ORDER BY lower(authorization_identifier), 2, 3, 4;", "explanation": "Regression test for Foreign Data in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM information_schema.user_mapping_options ORDER BY lower(authorization_identifier), 2, 3, 4) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 104, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'lock' (example 58).", "schema": null, "sql": "CREATE OR REPLACE VIEW lock_view2 AS SELECT * from lock_view3;", "explanation": "DDL from PostgreSQL core regression test for Lock.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 62, "num_statements": 1} {"question": "PostgreSQL regression test 'multirangetypes': Write the SELECT query (example 23).", "schema": null, "sql": "select '{[a,]}'::textmultirange;", "explanation": "Regression test for Multirangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '{[a,]}'::textmultirange) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 32, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'opr_sanity' (example 93).", "schema": null, "sql": "-- Check that all combine functions have signature\n-- combine(transtype, transtype) returns transtype\n\nSELECT a.aggfnoid, p.proname\nFROM pg_aggregate as a, pg_proc as p\nWHERE a.aggcombinefn = p.oid AND\n (p.pronargs != 2 OR\n p.prorettype != p.proargtypes[0] OR\n p.prorettype != p.proargtypes[1] OR\n NOT binary_coercible(a.aggtranstype, p.proargtypes[0]));", "explanation": "PL/pgSQL object from PostgreSQL core test for Opr Sanity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 369, "num_statements": 1} {"question": "Show an example of PostgreSQL CREATE TYPE (example 4).", "schema": null, "sql": "CREATE TYPE box; CREATE FUNCTION my_box_in_function(cstring) RETURNS box AS ... ; CREATE FUNCTION my_box_out_function(box) RETURNS cstring AS ... ; CREATE TYPE box ( INTERNALLENGTH = 16, INPUT = my_box_in_function, OUTPUT = my_box_out_function ); CREATE TABLE myboxes ( id integer, description box );", "explanation": "PostgreSQL CREATE TYPE command.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 300, "num_statements": 5} {"question": "Write the DDL statement from PostgreSQL regression test 'rowsecurity' (example 680).", "schema": null, "sql": "CREATE POLICY blog_1 ON blog USING (id % 2 = 0);", "explanation": "DDL from PostgreSQL core regression test for Rowsecurity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 48, "num_statements": 1} {"question": "PostgreSQL regression test 'plpgsql': Write the SELECT query (example 312).", "schema": null, "sql": "select 1,2 into x, y;", "explanation": "Regression test for Plpgsql in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select 1,2 into x, y) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 21, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'sequence' (example 35).", "schema": null, "sql": "INSERT INTO serialTest2 (f1, f3)\n VALUES ('bogus', 32768);", "explanation": "DML from PostgreSQL core regression test for Sequence.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 39).", "schema": null, "sql": "SELECT citext_larger( 'ab'::citext, 'ac'::citext ) = 'ac' AS t;", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "PostgreSQL regression test 'rangetypes': Write the SELECT query (example 39).", "schema": null, "sql": "select * from pg_input_error_info('[1,2147483647]', 'int4range');", "explanation": "Regression test for Rangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from pg_input_error_info('[1,2147483647]', 'int4range')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'identity' (example 35).", "schema": null, "sql": "INSERT INTO itest5 OVERRIDING USER VALUE VALUES (DEFAULT, 'ddd'), (-4, 'eee');", "explanation": "DML from PostgreSQL core regression test for Identity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 78, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 404).", "schema": null, "sql": "INSERT INTO num_exp_add VALUES (9,8,'-24851923.045047420');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'update' (example 87).", "schema": null, "sql": "INSERT into mintab VALUES (120);", "explanation": "DML from PostgreSQL core regression test for Update.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 32, "num_statements": 1} {"question": "pgTAP test for Resultset (assertion 432).", "schema": null, "sql": "-- Now when the last row is missing.\nSELECT * FROM check_test(\n results_ne(\n 'SELECT id, name FROM annames WHERE name <> ''Antonio''',\n 'nenames_ord'\n ),\n true,\n 'results_ne(select, prepared) missing last row',\n '',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Resultset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 254, "num_statements": 1} {"question": "PL/pgSQL test: Plpgsql Trap (example 35).", "schema": null, "sql": "select trap_foreign_key_2(); -- detects FK violation\ncommit;\t\t\t\t-- still fails\n\ndrop function trap_foreign_key(int);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpgsql Trap.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 117, "num_statements": 3} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 360).", "schema": null, "sql": "SELECT regexp_matches('foobarbequebaz'::citext, '(BAR)(BEQUE)'::citext, ''::citext) = ARRAY[ 'bar', 'beque' ] AS t;", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 115, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'alter_table' (example 266).", "schema": null, "sql": "insert into alter1.t1(f2) values(12);", "explanation": "DML from PostgreSQL core regression test for Alter Table.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 37, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'plpgsql' (example 681).", "schema": null, "sql": "-- access to call stack from exception\ncreate function inner_func(int)\nreturns int as $$\ndeclare\n _context text;\n sx int := 5;\nbegin\n begin\n perform sx / 0;\n exception\n when division_by_zero then\n get diagnostics _context = pg_context;\n raise notice '***%***', _context;\n end;\n\n -- lets do it again, just for fun..\n get diagnostics _context = pg_context;\n raise notice '***%***', _context;\n raise notice 'lets make sure we didnt break anything';\n return 2 * $1;\nend;\n$$ language plpgsql;", "explanation": "PL/pgSQL object from PostgreSQL core test for Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 513, "num_statements": 12} {"question": "Write the DML statement from PostgreSQL regression test 'timestamptz' (example 96).", "schema": null, "sql": "INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 1697');", "explanation": "DML from PostgreSQL core regression test for Timestamptz.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'compression_lz4' (example 39).", "schema": null, "sql": "INSERT INTO cmpart VALUES (repeat('123456789', 1004));", "explanation": "DML from PostgreSQL core regression test for Compression Lz4.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'cluster' (example 72).", "schema": null, "sql": "INSERT INTO clstr_2 VALUES (1);", "explanation": "DML from PostgreSQL core regression test for Cluster.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 31, "num_statements": 1} {"question": "pgTAP test for Pktap (assertion 37).", "schema": null, "sql": "SELECT * FROM check_test(\n col_isnt_pk( 'sometab', 'id' ),\n false,\n 'col_isnt_pk( table, column )',\n 'Column sometab(id) should not be a primary key',\n ' have: {id}\n want: anything else'\n);", "explanation": "SQL assertion from pgTAP test suite for Pktap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 218, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (util_time, item 8).", "schema": null, "sql": "-- Time can be represented in a hypertable as an int* (bigint/integer/smallint) or as a timestamp type (\n-- with or without timezones). In metatables and other internal systems all time values are stored as bigint.\n-- Converting from int* columns to internal representation is a cast to bigint.\n-- Converting from timestamps to internal representation is conversion to epoch (in microseconds).\n\nCREATE OR REPLACE FUNCTION _timescaledb_functions.interval_to_usec(\n chunk_interval INTERVAL\n)\nRETURNS BIGINT LANGUAGE SQL IMMUTABLE PARALLEL SAFE AS\n$BODY$\n SELECT (int_sec * 1000000)::bigint from extract(epoch from chunk_interval) as int_sec;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 648, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 331).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION has_enum( NAME, NAME );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_jsontable': Write the SELECT query (example 58).", "schema": null, "sql": "SELECT * FROM JSON_TABLE(jsonb '\"a\"', '$' COLUMNS (a float4 EXISTS PATH '$.a'));", "explanation": "Regression test for Sqljson Jsontable in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM JSON_TABLE(jsonb '\"a\"', '$' COLUMNS (a float4 EXISTS PATH '$.a'))) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": true, "sql_length": 80, "num_statements": 1} {"question": "Show an example of PostgreSQL DROP TSTEMPLATE (example 1).", "schema": null, "sql": "DROP TEXT SEARCH TEMPLATE thesaurus;", "explanation": "PostgreSQL DROP TSTEMPLATE command.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 36, "num_statements": 1} {"question": "PostgreSQL regression test 'multirangetypes': Write the SELECT query (example 397).", "schema": null, "sql": "select count(*) from test_multirange_gist where mr = '{}'::int4multirange;", "explanation": "Regression test for Multirangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select count(*) from test_multirange_gist where mr = '{}'::int4multirange) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 74, "num_statements": 1} {"question": "PostgreSQL regression test 'largeobject': Write the SELECT query (example 108).", "schema": null, "sql": "SELECT lo_import(:'filename');", "explanation": "Regression test for Largeobject in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT lo_import(:'filename')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 30, "num_statements": 1} {"question": "pgTAP test for Index (assertion 27).", "schema": null, "sql": "SELECT * FROM check_test(\n has_index( 'public', 'sometab', 'idx_baz'::name ),\n true,\n 'has_index() no cols no desc',\n 'Index idx_baz should exist',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Index.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 169, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonpath': Write the SELECT query (example 163).", "schema": null, "sql": "select '0.0010'::jsonpath;", "explanation": "Regression test for Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '0.0010'::jsonpath) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 26, "num_statements": 1} {"question": "Show an example of PostgreSQL ALTER ROLE (example 1).", "schema": null, "sql": "ALTER ROLE davide WITH PASSWORD 'hu8jmn3';", "explanation": "PostgreSQL ALTER ROLE command.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 42, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'hash_part' (example 24).", "schema": null, "sql": "create table text_hashp1 partition of text_hashp for values with (modulus 2, remainder 1);", "explanation": "DDL from PostgreSQL core regression test for Hash Part.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 90, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'opr_sanity' (example 4).", "schema": null, "sql": "-- proretset should only be set for normal functions\nSELECT p1.oid, p1.proname\nFROM pg_proc AS p1\nWHERE proretset AND prokind != 'f';", "explanation": "PL/pgSQL object from PostgreSQL core test for Opr Sanity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 133, "num_statements": 1} {"question": "PostgreSQL regression test 'tuplesort': Write the SELECT query (example 12).", "schema": null, "sql": "SELECT noabort_increasing, noabort_decreasing FROM abbrev_abort_uuids ORDER BY noabort_decreasing NULLS FIRST OFFSET 20000 - 4;", "explanation": "Regression test for Tuplesort in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT noabort_increasing, noabort_decreasing FROM abbrev_abort_uuids ORDER BY noabort_decreasing NULLS FIRST OFFSET 20000 - 4) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 127, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'fuzzystrmatch' (example 27).", "schema": null, "sql": "SELECT daitch_mokotoff('Golubitsa');", "explanation": "Example query from the 'fuzzystrmatch' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 36, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_jsontable': Write the SELECT query (example 73).", "schema": null, "sql": "SELECT * FROM JSON_TABLE(jsonb '\"world\"', '$' COLUMNS (item text PATH '$' OMIT QUOTES ON SCALAR STRING));", "explanation": "Regression test for Sqljson Jsontable in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM JSON_TABLE(jsonb '\"world\"', '$' COLUMNS (item text PATH '$' OMIT QUOTES ON SCALAR STRING))) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 105, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'ltree' (example 157).", "schema": null, "sql": "SELECT 'a.b.c.d.e'::ltree ~ '*.a.*.!f.*';", "explanation": "Example query from the 'ltree' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 41, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'insert_conflict' (example 1).", "schema": null, "sql": "create table insertconflicttest(key int4, fruit text);", "explanation": "DDL from PostgreSQL core regression test for Insert Conflict.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "PostgreSQL regression test 'numeric': Write the SELECT query (example 888).", "schema": null, "sql": "select (-1.0) ^ 1000000000000000;", "explanation": "Regression test for Numeric in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select (-1.0) ^ 1000000000000000) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 33, "num_statements": 1} {"question": "Show an example of PostgreSQL CREATE TRIGGER (example 5).", "schema": null, "sql": "CREATE TRIGGER view_insert INSTEAD OF INSERT ON my_view FOR EACH ROW EXECUTE FUNCTION view_insert_row();", "explanation": "PostgreSQL CREATE TRIGGER command.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 104, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'timestamp' (example 48).", "schema": null, "sql": "INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');", "explanation": "DML from PostgreSQL core regression test for Timestamp.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "pgTAP test for Throwtap (assertion 35).", "schema": null, "sql": "/****************************************************************************/\n-- Test ASSERTs\nSELECT lives_ok(\n CASE WHEN pg_version_num() < 90500 THEN $exec$\nCREATE FUNCTION check_assert(b boolean) RETURNS void LANGUAGE plpgsql AS $body$\nBEGIN\n RAISE EXCEPTION 'this code should never be called!';", "explanation": "SQL assertion from pgTAP test suite for Throwtap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 305, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'create_misc' (example 48).", "schema": null, "sql": "INSERT INTO f_star (class, a, f)\n VALUES ('f', 26, '(11111,33333),(22222,44444)'::polygon);", "explanation": "DML from PostgreSQL core regression test for Create Misc.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 93, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'gist' (example 4).", "schema": null, "sql": "create index gist_pointidx3 on gist_point_tbl using gist(p) with (buffering = off);", "explanation": "DDL from PostgreSQL core regression test for Gist.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 83, "num_statements": 1} {"question": "PostgreSQL regression test 'tstypes': Write the SELECT query (example 37).", "schema": null, "sql": "SELECT 'foo & bar'::tsquery || 'asd & fg';", "explanation": "Regression test for Tstypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT 'foo & bar'::tsquery || 'asd & fg') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 42, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_join' (example 136).", "schema": null, "sql": "CREATE TABLE plt1_e_p2 PARTITION OF plt1_e FOR VALUES IN ('0001', '0005', '0002', '0009');", "explanation": "DDL from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 90, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rowsecurity' (example 596).", "schema": null, "sql": "CREATE POLICY p2 ON x1 FOR INSERT WITH CHECK (a % 2 = 1);", "explanation": "DDL from PostgreSQL core regression test for Rowsecurity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 57, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'tuplesort' (example 11).", "schema": null, "sql": "-- plain sort not triggering abbreviated abort\nSELECT noabort_increasing, noabort_decreasing FROM abbrev_abort_uuids ORDER BY noabort_increasing OFFSET 20000 - 4;", "explanation": "PL/pgSQL object from PostgreSQL core test for Tuplesort.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 162, "num_statements": 1} {"question": "PostgreSQL regression test 'float8': Write the SELECT query (example 66).", "schema": null, "sql": "SELECT power(float8 '1', float8 'NaN');", "explanation": "Regression test for Float8 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT power(float8 '1', float8 'NaN')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 39, "num_statements": 1} {"question": "PostgreSQL regression test 'numeric': Write the SELECT query (example 629).", "schema": null, "sql": "SELECT round(5e-16383, 16382) = 1e-16382;", "explanation": "Regression test for Numeric in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT round(5e-16383, 16382) = 1e-16382) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 41, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pg_logicalinspect' (example 3).", "schema": null, "sql": "SELECT pg_get_logical_snapshot_info('0--40796E18.snap');", "explanation": "Example query from the 'pg_logicalinspect' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 56, "num_statements": 1} {"question": "Show a SQL definition from the citus project (coordinator_evaluation, item 7).", "schema": null, "sql": "CREATE TABLE coordinator_evaluation_table (key int, value int);", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'tid' (example 24).", "schema": null, "sql": "CREATE VIEW tid_view_with_ctid AS SELECT ctid, a FROM tid_tab;", "explanation": "DDL from PostgreSQL core regression test for Tid.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 62, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 201).", "schema": null, "sql": "select jsonb_path_query('{\"a\": [1, 2]}', 'lax $.a * 3');", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb_path_query('{\"a\": [1, 2]}', 'lax $.a * 3')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": false, "sql_length": 56, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'arrays' (example 291).", "schema": null, "sql": "INSERT INTO arraggtest (f1, f2, f3) VALUES\n('{1,2,3,4}','{{grey,red},{blue,blue}}','{1.6, 0.0}');", "explanation": "DML from PostgreSQL core regression test for Arrays.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 97, "num_statements": 1} {"question": "PostgreSQL regression test 'interval': Write the SELECT query (example 200).", "schema": null, "sql": "select interval 'PT2562047789';", "explanation": "Regression test for Interval in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select interval 'PT2562047789') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 31, "num_statements": 1} {"question": "PostgreSQL regression test 'multirangetypes': Write the SELECT query (example 250).", "schema": null, "sql": "SELECT nummultirange() &> nummultirange(numrange(1,2));", "explanation": "Regression test for Multirangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT nummultirange() &> nummultirange(numrange(1,2))) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "PostgreSQL regression test 'tsdicts': Write the SELECT query (example 4).", "schema": null, "sql": "SELECT ts_lexize('ispell', 'booking');", "explanation": "Regression test for Tsdicts in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT ts_lexize('ispell', 'booking')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 38, "num_statements": 1} {"question": "PostgreSQL regression test 'arrays': Write the SELECT query (example 363).", "schema": null, "sql": "select v, v is null as \"is null\" from string_to_table('1,2,3,4,,6', ',', '') g(v);", "explanation": "Regression test for Arrays in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select v, v is null as \"is null\" from string_to_table('1,2,3,4,,6', ',', '') g(v)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 82, "num_statements": 1} {"question": "PostgreSQL regression test 'aggregates': Write the SELECT query (example 162).", "schema": null, "sql": "select max(unique2) from tenk1 order by 1;", "explanation": "Regression test for Aggregates in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select max(unique2) from tenk1 order by 1) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 42, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'transactions' (example 54).", "schema": null, "sql": "CREATE TABLE trans_barbaz (a int);", "explanation": "DDL from PostgreSQL core regression test for Transactions.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 34, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 637).", "schema": null, "sql": "select jsonb_path_query('\"12:34\"', '$.datetime(\"HH24:MI\")');", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb_path_query('\"12:34\"', '$.datetime(\"HH24:MI\")')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gist' (example 26).", "schema": null, "sql": "SELECT count(*) FROM timestamptztmp WHERE a < '2018-12-18 10:59:54 GMT+2'::timestamptz;", "explanation": "Example query from the 'btree_gist' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 88, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rules' (example 57).", "schema": null, "sql": "insert into rtest_t3 values (3, 33);", "explanation": "DML from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 36, "num_statements": 1} {"question": "PostgreSQL regression test 'timetz': Write the SELECT query (example 19).", "schema": null, "sql": "SELECT f1 AS \"Seven\" FROM TIMETZ_TBL WHERE f1 > '05:06:07-07';", "explanation": "Regression test for Timetz in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT f1 AS \"Seven\" FROM TIMETZ_TBL WHERE f1 > '05:06:07-07') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 62, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 9).", "schema": null, "sql": "CREATE FUNCTION uuid_generate_v4()\nRETURNS uuid\nAS 'MODULE_PATHNAME', 'uuid_generate_v4'\nVOLATILE STRICT LANGUAGE C PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 130, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Record (example 27).", "schema": null, "sql": "SELECT * FROM test_table_record_as('obj', null, null, true);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Record.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 60, "num_statements": 1} {"question": "PostgreSQL regression test 'join': Write the SELECT query (example 316).", "schema": null, "sql": "SELECT qq, unique1\n FROM\n ( SELECT COALESCE(q1, 0) AS qq FROM int8_tbl a ) AS ss1\n FULL OUTER JOIN\n ( SELECT COALESCE(q2, -1) AS qq FROM int8_tbl b ) AS ss2\n USING (qq)\n INNER JOIN tenk1 c ON qq = unique2;", "explanation": "Regression test for Join in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT qq, unique1\n FROM\n ( SELECT COALESCE(q1, 0) AS qq FROM int8_tbl a ) AS ss1\n FULL OUTER JOIN\n ( SELECT COALESCE(q2, -1) AS qq FROM int8_tbl b ) AS ss2\n USING (qq)\n INNER JOIN tenk1 c ON qq = unique2) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_join", "is_postgresql_specific": false, "sql_length": 211, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'hash_index' (example 36).", "schema": null, "sql": "UPDATE hash_i4_heap\n SET seqno = 20000\n WHERE hash_i4_heap.random = 1492795354;", "explanation": "DML from PostgreSQL core regression test for Hash Index.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 83, "num_statements": 1} {"question": "PostgreSQL regression test 'horology': Write the SELECT query (example 210).", "schema": null, "sql": "SELECT '4714-11-24 BC'::date::timestamptz; -- fail\n\nSELECT '4714-11-24 BC'::date < '2020-10-05'::timestamptz as t;", "explanation": "Regression test for Horology in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT '4714-11-24 BC'::date::timestamptz; -- fail\n\nSELECT '4714-11-24 BC'::date < '2020-10-05'::timestamptz as t) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 115, "num_statements": 2} {"question": "Write the DML statement from PostgreSQL regression test 'float8' (example 4).", "schema": null, "sql": "INSERT INTO FLOAT8_TBL(f1) VALUES (' -34.84');", "explanation": "DML from PostgreSQL core regression test for Float8.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 48, "num_statements": 1} {"question": "PostgreSQL regression test 'pg_dependencies': Write the SELECT query (example 82).", "schema": null, "sql": "SELECT * FROM pg_input_error_info('[{\"attributes\" : [2,3], \"dependency\": 4, \"degree\": 1.000, \"degree\": 1.000}]', 'pg_dependencies');", "explanation": "Regression test for Pg Dependencies in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM pg_input_error_info('[{\"attributes\" : [2,3], \"dependency\": 4, \"degree\": 1.000, \"degree\": 1.000}]', 'pg_dependencies')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 132, "num_statements": 1} {"question": "pgTAP test for Resultset (assertion 411).", "schema": null, "sql": "INSERT INTO nord (id, name ) VALUES(183, 'Antonio');", "explanation": "SQL assertion from pgTAP test suite for Resultset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 52, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pgcrypto' (example 33).", "schema": null, "sql": "select encode(decrypt(encrypt('Lets try a longer message.', '0123456789', 'aes-cfb'), '0123456789', 'aes-cfb'), 'escape');", "explanation": "Example query from the 'pgcrypto' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 122, "num_statements": 1} {"question": "Show a SQL definition from the citus project (multi_null_minmax_value_pruning, item 9).", "schema": null, "sql": "SELECT master_create_empty_shard('lineitem') as lineitem_shardid1 \\gset\nSELECT master_create_empty_shard('lineitem') as lineitem_shardid2 \\gset\n\nCREATE TABLE orders (LIKE public.orders);", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 186, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'create_procedure' (example 49).", "schema": null, "sql": "DROP PROCEDURE ptest2;", "explanation": "PL/pgSQL object from PostgreSQL core test for Create Procedure.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 22, "num_statements": 1} {"question": "PostgreSQL regression test 'rangetypes': Write the SELECT query (example 24).", "schema": null, "sql": "select '([,z)'::textrange;", "explanation": "Regression test for Rangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '([,z)'::textrange) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 26, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 8).", "schema": null, "sql": "CREATE FUNCTION _int_contains_joinsel(internal, oid, internal, smallint, internal)\nRETURNS float8\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT STABLE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "other", "is_postgresql_specific": false, "sql_length": 144, "num_statements": 1} {"question": "pgTAP test for Pgtap--1.0.0--1.1.0 (assertion 11).", "schema": null, "sql": "-- _keys( schema, table, constraint_type )\nCREATE OR REPLACE FUNCTION _keys ( NAME, NAME, CHAR )\nRETURNS SETOF NAME[] AS $$\n SELECT _pg_sv_column_array(x.conrelid,x.conkey) -- name[] doesn't support collation\n FROM pg_catalog.pg_namespace n\n JOIN pg_catalog.pg_class c ON n.oid = c.relnamespace\n JOIN pg_catalog.pg_constraint x ON c.oid = x.conrelid\n WHERE n.nspname = $1\n AND c.relname = $2\n AND x.contype = $3\n ORDER BY 1\n$$ LANGUAGE sql;", "explanation": "SQL assertion from pgTAP test suite for Pgtap--1.0.0--1.1.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 482, "num_statements": 1} {"question": "PostgreSQL regression test 'time': Write the SELECT query (example 19).", "schema": null, "sql": "SELECT '23:59:59.9999999'::time; -- rounds up\nSELECT '23:59:60'::time; -- rounds up\nSELECT '24:00:00'::time; -- allowed\nSELECT '24:00:00.01'::time; -- not allowed\nSELECT '23:59:60.01'::time; -- not allowed\nSELECT '24:01:00'::time; -- not allowed\nSELECT '25:00:00'::time; -- not allowed\n\n-- Test non-error-throwing API\nSELECT pg_input_is_valid('12:00:00', 'time');", "explanation": "Regression test for Time in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT '23:59:59.9999999'::time; -- rounds up\nSELECT '23:59:60'::time; -- rounds up\nSELECT '24:00:00'::time; -- allowed\nSELECT '24:00:00.01'::time; -- not allowed\nSELECT '23:59:60.01'::time; -- not allowed\nSELECT '24:01:00'::time; -- not allowed\nSELECT '25:00:00'::time; -- not allowed\n\n-- Test non-error-throwing API\nSELECT pg_input_is_valid('12:00:00', 'time')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 370, "num_statements": 8} {"question": "Show a query using PostgreSQL contrib extension 'pgstattuple' (example 35).", "schema": null, "sql": "select pgstattuple_approx('test_partitioned');", "explanation": "Example query from the 'pgstattuple' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 46, "num_statements": 1} {"question": "PostgreSQL Indices: show example 39.", "schema": null, "sql": "SELECT * FROM test1c WHERE content > constant ;", "explanation": "Example from PostgreSQL documentation on Indices.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 47, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'plpgsql' (example 737).", "schema": null, "sql": "-- behave reasonably if someone tries to modify a transition table\nCREATE FUNCTION transition_table_level2_bad_usage_func()\n RETURNS TRIGGER\n LANGUAGE plpgsql\nAS $$\n BEGIN\n INSERT INTO dx VALUES (1000000, 1000000, 'x');\n RETURN NULL;\n END;\n$$;", "explanation": "PL/pgSQL object from PostgreSQL core test for Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 253, "num_statements": 4} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 7).", "schema": null, "sql": "--\n-- bt_page_items_bytea()\n--\nCREATE FUNCTION bt_page_items(IN page bytea,\n OUT itemoffset smallint,\n OUT ctid tid,\n OUT itemlen smallint,\n OUT nulls bool,\n OUT vars bool,\n OUT data text)\nRETURNS SETOF record\nAS 'MODULE_PATHNAME', 'bt_page_items_bytea'\nLANGUAGE C STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 304, "num_statements": 1} {"question": "pgTAP test for Policy (assertion 73).", "schema": null, "sql": "SELECT * FROM check_test(\n policy_cmd_is( 'passwd', 'root_all', 'all', 'whatever' ),\n true,\n 'policy_cmd_is(table, policy, command, desc) for ALL',\n 'whatever',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Policy.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 182, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_join' (example 579).", "schema": null, "sql": "CREATE TABLE beta_neg_p1 PARTITION OF beta_neg FOR VALUES FROM (100) TO (150);", "explanation": "DDL from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 78, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Composite (example 28).", "schema": null, "sql": "SELECT * FROM multiout_record_as('obj', null, null, false);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Composite.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Show a SQL definition from the timescaledb project (time_bucket, item 4).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION @extschema@.time_bucket(bucket_width INTERVAL, ts UUID) RETURNS TIMESTAMPTZ\n\tAS '@MODULE_PATHNAME@', 'ts_uuid_bucket' LANGUAGE C IMMUTABLE PARALLEL SAFE STRICT;", "explanation": "SQL definition from the open-source timescaledb PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 187, "num_statements": 1} {"question": "Show a SQL definition from the citus project (columnar_data_types, item 4).", "schema": null, "sql": "-- Test array types\nCREATE TABLE test_array_types (int_array int[], bigint_array bigint[],\n\ttext_array text[]) USING columnar;", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 126, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'foreign_key' (example 32).", "schema": null, "sql": "INSERT INTO PKTABLE VALUES (3, 6, 'Test3');", "explanation": "DML from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 43, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 8).", "schema": null, "sql": "-- Create the operator class\nCREATE OPERATOR CLASS gist_enum_ops\nDEFAULT FOR TYPE anyenum USING gist\nAS\n\tOPERATOR\t1\t< ,\n\tOPERATOR\t2\t<= ,\n\tOPERATOR\t3\t= ,\n\tOPERATOR\t4\t>= ,\n\tOPERATOR\t5\t> ,\n\tFUNCTION\t1\tgbt_enum_consistent (internal, anyenum, int2, oid, internal),\n\tFUNCTION\t2\tgbt_enum_union (internal, internal),\n\tFUNCTION\t3\tgbt_enum_compress (internal),\n\tFUNCTION\t4\tgbt_decompress (internal),\n\tFUNCTION\t5\tgbt_enum_penalty (internal, internal, internal),\n\tFUNCTION\t6\tgbt_enum_picksplit (internal, internal),\n\tFUNCTION\t7\tgbt_enum_same (gbtreekey8, gbtreekey8, internal),\n\tSTORAGE\t\tgbtreekey8;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 590, "num_statements": 1} {"question": "PostgreSQL regression test 'join': Write the SELECT query (example 517).", "schema": null, "sql": "SELECT b.* FROM b LEFT JOIN a ON (b.a_id = a.id) WHERE (a.id IS NULL OR a.id > 0);", "explanation": "Regression test for Join in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT b.* FROM b LEFT JOIN a ON (b.a_id = a.id) WHERE (a.id IS NULL OR a.id > 0)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_join", "is_postgresql_specific": false, "sql_length": 82, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'without_overlaps' (example 14).", "schema": null, "sql": "CREATE TABLE temporal_rng2 (\n CONSTRAINT temporal_rng_pk PRIMARY KEY (id, valid_at WITHOUT OVERLAPS)\n) INHERITS (temporal_rng);", "explanation": "DDL from PostgreSQL core regression test for Without Overlaps.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 128, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'foreign_key' (example 460).", "schema": null, "sql": "update selfref set a = 123 where a = 0;", "explanation": "DML from PostgreSQL core regression test for Foreign Key.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 39, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 5).", "schema": null, "sql": "SELECT 'a'::citext = 'A'::text AS f; -- text wins the discussion\nSELECT 'a'::citext = 'b'::citext AS f;", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 110, "num_statements": 2} {"question": "Write the DDL statement from PostgreSQL regression test 'bit' (example 30).", "schema": null, "sql": "CREATE TABLE varbit_table (a BIT VARYING(16), b BIT VARYING(16));", "explanation": "DDL from PostgreSQL core regression test for Bit.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "PostgreSQL regression test 'alter_table': Write the SELECT query (example 648).", "schema": null, "sql": "SELECT attinhcount, attislocal FROM pg_attribute WHERE attrelid = 'part_3_4'::regclass AND attnum > 0;", "explanation": "Regression test for Alter Table in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT attinhcount, attislocal FROM pg_attribute WHERE attrelid = 'part_3_4'::regclass AND attnum > 0) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 102, "num_statements": 1} {"question": "PostgreSQL regression test 'strings': Write the SELECT query (example 522).", "schema": null, "sql": "SELECT unistr('wrong: \\U0000db99\\U00000061');", "explanation": "Regression test for Strings in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT unistr('wrong: \\U0000db99\\U00000061')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 45, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rules' (example 262).", "schema": null, "sql": "insert into rtest_view3 select * from rtest_vview1 where a < 7;", "explanation": "DML from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'drop_if_exists' (example 75).", "schema": null, "sql": "CREATE OPERATOR @#@\n (leftarg = int8, rightarg = int8, procedure = int8xor);", "explanation": "DDL from PostgreSQL core regression test for Drop If Exists.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 83, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pg_stat_statements' (example 7).", "schema": null, "sql": "SELECT * FROM test_squash WHERE id IN (1, 2, 3);", "explanation": "Example query from the 'pg_stat_statements' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 48, "num_statements": 1} {"question": "PostgreSQL regression test 'partition_split': Write the SELECT query (example 206).", "schema": null, "sql": "SELECT * FROM sales_central WHERE sales_state = 'Warsaw';", "explanation": "Regression test for Partition Split in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM sales_central WHERE sales_state = 'Warsaw') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 57, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'memoize' (example 43).", "schema": null, "sql": "CREATE TABLE prt (a int) PARTITION BY RANGE(a);", "explanation": "DDL from PostgreSQL core regression test for Memoize.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 47, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric_big' (example 208).", "schema": null, "sql": "INSERT INTO num_exp_mul VALUES (4,6,'250145412892811547138949.592621291590152419206270097656346630226508074074623894951308487425470437268130465956063593951784820669318897182831355375451719125809800516979013437732298382708070979871283132689492336823087794373113039154669229889503700598930220858275174342776478898670277868700384853696009897221747924643343353942154528501454689084608965009561564638167714973711022212547096732831847202912862290958304510651828842182545311077713664465815992616213663619529378061133917572474298028065850515876361609671565914027186063801852554353160801534696062207299890867876199323530337336273950892723090754719547285920090419070001019943385293110663922226230169381423410428577990604776655422105400452217085311617728003688836185608912367677734364834577573255789160419371322775733777518997638403409000055707558465286469808848200141192627396502735');", "explanation": "DML from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 875, "num_statements": 1} {"question": "PostgreSQL Plpgsql: show example 23.", "schema": null, "sql": "PERFORM create_mv('cs_session_page_requests_mv', my_query);", "explanation": "Example from PostgreSQL documentation on Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql", "is_postgresql_specific": true, "sql_length": 59, "num_statements": 1} {"question": "PostgreSQL regression test 'create_index': Write the SELECT query (example 347).", "schema": null, "sql": "SELECT unique1, unique2 FROM onek_with_null\n ORDER BY unique2 DESC LIMIT 5;", "explanation": "Regression test for Create Index in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT unique1, unique2 FROM onek_with_null\n ORDER BY unique2 DESC LIMIT 5) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 76, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'sequence' (example 13).", "schema": null, "sql": "CREATE SEQUENCE sequence_test9 AS integer INCREMENT BY -1;", "explanation": "DDL from PostgreSQL core regression test for Sequence.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 53).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION fail ( text );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 1} {"question": "PostgreSQL regression test 'arrays': Write the SELECT query (example 430).", "schema": null, "sql": "select pg_typeof(array['11 22 33'::oidvector]);", "explanation": "Regression test for Arrays in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select pg_typeof(array['11 22 33'::oidvector])) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 47, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'vacuum' (example 129).", "schema": null, "sql": "INSERT INTO vac_truncate_test VALUES (1, NULL), (NULL, NULL);", "explanation": "DML from PostgreSQL core regression test for Vacuum.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 61, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rowsecurity' (example 1068).", "schema": null, "sql": "CREATE POLICY p3 ON rls_part USING (a < 0);", "explanation": "DDL from PostgreSQL core regression test for Rowsecurity.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 43, "num_statements": 1} {"question": "PostgreSQL Ddl: show example 53.", "schema": null, "sql": "ALTER TABLE products ALTER COLUMN product_no DROP NOT NULL;", "explanation": "Example from PostgreSQL documentation on Ddl.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_alter", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 278).", "schema": null, "sql": "INSERT INTO caster (text) VALUES ('((0,0),2)'::circle);", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 64, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'transactions' (example 127).", "schema": null, "sql": "INSERT INTO savepoints VALUES (13);", "explanation": "DML from PostgreSQL core regression test for Transactions.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson': Write the SELECT query (example 45).", "schema": null, "sql": "SELECT JSON_SERIALIZE('{ \"a\" : 1 } ' RETURNING varchar);", "explanation": "Regression test for Sqljson in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_SERIALIZE('{ \"a\" : 1 } ' RETURNING varchar)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 56, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric_big' (example 95).", "schema": null, "sql": "INSERT INTO num_exp_sub VALUES (1,8,'-8496900980.24523699375539429928140707116805167695126380524350074691312247557192264420150419818976723729812860582476663647913254442686555191453722107164485675679551050629376558940966195135841284978096687306110481009743118940565957556492470398904849289222365256698601073536111216152709126800604695001949246634784573028721762079936564434050796321975774729383704426321489070979168993853338252728216162346796960170352897972568238870481118474064783391570102958474141459619245240874849766946530000977144965');", "explanation": "DML from PostgreSQL core regression test for Numeric Big.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 540, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'stats' (example 104).", "schema": null, "sql": "-- check that function dropped in a subtransaction leaves no stats behind\nBEGIN;", "explanation": "PL/pgSQL object from PostgreSQL core test for Stats.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "plpgsql_function", "is_postgresql_specific": false, "sql_length": 80, "num_statements": 1} {"question": "PostgreSQL regression test 'pg_dependencies': Write the SELECT query (example 88).", "schema": null, "sql": "SELECT * FROM pg_input_error_info('[{\"attributes\" : [2,2], \"dependency\" : 4, \"degree\": 0.500}]', 'pg_dependencies');", "explanation": "Regression test for Pg Dependencies in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM pg_input_error_info('[{\"attributes\" : [2,2], \"dependency\" : 4, \"degree\": 0.500}]', 'pg_dependencies')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 116, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'postgres_fdw' (example 242).", "schema": null, "sql": "SELECT ft5, ft5.c1, ft5.c2, ft5.c3, ft4.c1, ft4.c2 FROM ft5 left join ft4 on ft5.c1 = ft4.c1 WHERE ft4.c1 BETWEEN 10 and 30 ORDER BY ft5.c1, ft4.c1;", "explanation": "Example query from the 'postgres_fdw' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "query_join", "is_postgresql_specific": false, "sql_length": 148, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'spgist' (example 7).", "schema": null, "sql": "insert into spgist_point_tbl (id, p)\nselect g+100000, point(g*10+1, g*10+1) from generate_series(1, 10000) g;", "explanation": "DML from PostgreSQL core regression test for Spgist.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 109, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 739).", "schema": null, "sql": "select '\"a\"'::jsonb #- '{a}'; -- error\nselect '{}'::jsonb #- '{a}';", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '\"a\"'::jsonb #- '{a}'; -- error\nselect '{}'::jsonb #- '{a}') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 67, "num_statements": 2} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 663).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION roles_are( NAME[] );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "PL/pgSQL test: Pltcl Queries (example 79).", "schema": null, "sql": "}\nspi_exec {select replaceme('foe') as inner}\nreturn \"fee $1 $inner\"\n$p$ language pltcl;", "explanation": "PL/pgSQL example from PostgreSQL source test for Pltcl Queries.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 88, "num_statements": 1} {"question": "PostgreSQL regression test 'rowsecurity': Write the SELECT query (example 246).", "schema": null, "sql": "SELECT * FROM part_document_satire ORDER by did;", "explanation": "Regression test for Rowsecurity in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM part_document_satire ORDER by did) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 48, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 37).", "schema": null, "sql": "CREATE FUNCTION seg_upper(seg)\nRETURNS float4\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 109, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'domain' (example 53).", "schema": null, "sql": "INSERT INTO domarrtest values ('{{2,2},{2,2}}', '{{\"a\",\"b\"}}');", "explanation": "DML from PostgreSQL core regression test for Domain.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "PostgreSQL regression test 'regproc': Write the SELECT query (example 20).", "schema": null, "sql": "SELECT regclass('pg_catalog.pg_class');", "explanation": "Regression test for Regproc in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT regclass('pg_catalog.pg_class')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 39, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'insert' (example 121).", "schema": null, "sql": "create table part_xx_yy partition of list_parted for values in ('xx', 'yy') partition by list (a);", "explanation": "DDL from PostgreSQL core regression test for Insert.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 98, "num_statements": 1} {"question": "PostgreSQL regression test 'create_index_spgist': Write the SELECT query (example 22).", "schema": null, "sql": "SELECT count(*) FROM quad_point_tbl WHERE p <<| '(5000, 4000)';", "explanation": "Regression test for Create Index Spgist in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT count(*) FROM quad_point_tbl WHERE p <<| '(5000, 4000)') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 63, "num_statements": 1} {"question": "PostgreSQL regression test 'multirangetypes': Write the SELECT query (example 115).", "schema": null, "sql": "SELECT * FROM nummultirange_test WHERE multirange_contains_range(nmr, numrange(4.0, 4.2));", "explanation": "Regression test for Multirangetypes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM nummultirange_test WHERE multirange_contains_range(nmr, numrange(4.0, 4.2))) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 90, "num_statements": 1} {"question": "PostgreSQL regression test 'partition_merge': Write the SELECT query (example 227).", "schema": null, "sql": "SELECT tablename, indexname, tablespace FROM pg_indexes\n WHERE tablename IN ('t', 'tp_0_2') AND schemaname = 'partitions_merge_schema'\n ORDER BY tablename COLLATE \"C\", indexname COLLATE \"C\", tablespace COLLATE \"C\";", "explanation": "Regression test for Partition Merge in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT tablename, indexname, tablespace FROM pg_indexes\n WHERE tablename IN ('t', 'tp_0_2') AND schemaname = 'partitions_merge_schema'\n ORDER BY tablename COLLATE \"C\", indexname COLLATE \"C\", tablespace COLLATE \"C\") AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 216, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Types (example 22).", "schema": null, "sql": "SELECT * FROM test_type_conversion_int4(null);", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Types.", "validation_query": null, "source": "plpgsql_source", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 46, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'aggregates' (example 175).", "schema": null, "sql": "create table minmaxtest2() inherits (minmaxtest);", "explanation": "DDL from PostgreSQL core regression test for Aggregates.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 49, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 18).", "schema": null, "sql": "CREATE TYPE gbtreekey_var (\n\tINTERNALLENGTH = VARIABLE,\n\tINPUT = gbtreekey_var_in,\n\tOUTPUT = gbtreekey_var_out,\n\tSTORAGE = EXTENDED\n);", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 135, "num_statements": 1} {"question": "PostgreSQL regression test 'expressions': Write the SELECT query (example 69).", "schema": null, "sql": "select * from inttest where a not in (1::myint,2::myint,3::myint,4::myint,5::myint, null);", "explanation": "Regression test for Expressions in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from inttest where a not in (1::myint,2::myint,3::myint,4::myint,5::myint, null)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 90, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'collate' (example 101).", "schema": null, "sql": "CREATE TABLE collate_test23 (f1 text collate mycoll2);", "explanation": "DDL from PostgreSQL core regression test for Collate.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 54, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'lock' (example 8).", "schema": null, "sql": "CREATE VIEW lock_view4 AS SELECT (select a from lock_tbl1a limit 1) from lock_tbl1;", "explanation": "DDL from PostgreSQL core regression test for Lock.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_view", "is_postgresql_specific": false, "sql_length": 83, "num_statements": 1} {"question": "Show a SQL definition from the citus project (citus_local_table_triggers, item 37).", "schema": null, "sql": "CREATE TABLE local_table(value int);", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 36, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'numeric' (example 454).", "schema": null, "sql": "INSERT INTO num_exp_power_10_ln VALUES (4,'7405685069594999.07733999469386277636');", "explanation": "DML from PostgreSQL core regression test for Numeric.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 83, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb_jsonpath': Write the SELECT query (example 225).", "schema": null, "sql": "select jsonb_path_match('[[1, true], [2, false]]', 'strict $[*] ? (@[0] < $x) [1]', '{\"x\": 2}');", "explanation": "Regression test for Jsonb Jsonpath in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select jsonb_path_match('[[1, true], [2, false]]', 'strict $[*] ? (@[0] < $x) [1]', '{\"x\": 2}')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 96, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 951).", "schema": null, "sql": "select ts_headline('{}'::jsonb, tsquery('aaa & bbb'));", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select ts_headline('{}'::jsonb, tsquery('aaa & bbb'))) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 54, "num_statements": 1} {"question": "Show a SQL definition from the citus project (multi_partitioning, item 33).", "schema": null, "sql": "-- 3-) Attaching non distributed table to a distributed table\nCREATE TABLE partitioning_test_2012(id int, time date);", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 117, "num_statements": 1} {"question": "pgTAP test for Coltap (assertion 24).", "schema": null, "sql": "SELECT * FROM check_test(\n col_type_is( 'public', 'sometab', 'ctstz', 'pg_catalog'::name, 'timestamptz' ),\n true,\n 'col_type_is( sch, tab, col, sch, type, desc )',\n 'Column public.sometab.ctstz should be type pg_catalog.timestamptz',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Coltap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 255, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'constraints' (example 329).", "schema": null, "sql": "CREATE TABLE ATACC1 (a int, NOT NULL a NO INHERIT) PARTITION BY LIST (a);", "explanation": "DDL from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 73, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'copy2' (example 193).", "schema": null, "sql": "CREATE ROLE regress_rls_copy_user_colperms;", "explanation": "DDL from PostgreSQL core regression test for Copy2.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 43, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 300).", "schema": null, "sql": "SELECT JSON_VALUE(jsonb '1234', '$' RETURNING queryfuncs_d_varbit3 DEFAULT '111111' ON ERROR);", "explanation": "Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_VALUE(jsonb '1234', '$' RETURNING queryfuncs_d_varbit3 DEFAULT '111111' ON ERROR)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 95, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gin' (example 21).", "schema": null, "sql": "SELECT * FROM test_int2 WHERE i>1::int8 ORDER BY i;", "explanation": "Example query from the 'btree_gin' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 51, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'test_decoding' (example 60).", "schema": null, "sql": "INSERT INTO origin_tbl(data) VALUES ('no_lsn, commit');", "explanation": "Example query from the 'test_decoding' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'partition_join' (example 433).", "schema": null, "sql": "INSERT INTO plt2_adv SELECT i, i, to_char(i % 10, 'FM0000') FROM generate_series(1, 299) i WHERE i % 10 IN (7, 9);", "explanation": "DML from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 114, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'amcheck' (example 11).", "schema": null, "sql": "INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;", "explanation": "Example query from the 'amcheck' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 77, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 15).", "schema": null, "sql": "-- gist key\nCREATE FUNCTION gtrgm_in(cstring)\nRETURNS gtrgm\nAS 'MODULE_PATHNAME'\nLANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 123, "num_statements": 1} {"question": "PostgreSQL regression test 'date': Write the SELECT query (example 163).", "schema": null, "sql": "SELECT * FROM pg_input_error_info('6874898-01-01', 'date');", "explanation": "Regression test for Date in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM pg_input_error_info('6874898-01-01', 'date')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'create_index' (example 202).", "schema": null, "sql": "INSERT INTO func_index_heap VALUES('AB','CDEFG');", "explanation": "DML from PostgreSQL core regression test for Create Index.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 49, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'psql' (example 233).", "schema": null, "sql": "$$ LANGUAGE plpgsql;\n\n\\set ON_ERROR_ROLLBACK on\n\\echo '# ON_ERROR_ROLLBACK:' :ON_ERROR_ROLLBACK\n\\echo '# AUTOCOMMIT:' :AUTOCOMMIT\n\nBEGIN;\nCREATE TABLE bla(s NO_SUCH_TYPE); -- fails\nCREATE TABLE bla(s TEXT); -- succeeds\nSELECT psql_error('oops!'); -- fails\nINSERT INTO bla VALUES ('Calvin'), ('Hobbes');\nCOMMIT;\n\nSELECT * FROM bla ORDER BY 1;\n\nBEGIN;\nINSERT INTO bla VALUES ('Susie'); -- succeeds\n-- now with combined queries\nINSERT INTO bla VALUES ('Rosalyn') \\; -- will rollback\nSELECT 'before error' AS show \\; -- will show nevertheless!\n SELECT psql_error('boum!') \\; -- failure\n SELECT 'after error' AS noshow; -- hidden by preceding error\nINSERT INTO bla(s) VALUES ('Moe') \\; -- will rollback\n SELECT psql_error('bam!');\nINSERT INTO bla VALUES ('Miss Wormwood'); -- succeeds\nCOMMIT;\nSELECT * FROM bla ORDER BY 1;\n\n-- some with autocommit off\n\\set AUTOCOMMIT off\n\\echo '# AUTOCOMMIT:' :AUTOCOMMIT\n\n-- implicit BEGIN\nINSERT INTO bla VALUES ('Dad'); -- succeeds\nSELECT psql_error('bad!'); -- implicit partial rollback\n\nINSERT INTO bla VALUES ('Mum') \\; -- will rollback\nSELECT COUNT(*) AS \"#mum\"\nFROM bla WHERE s = 'Mum' \\; -- but be counted here\nSELECT psql_error('bad!'); -- implicit partial rollback\nCOMMIT;\n\nSELECT COUNT(*) AS \"#mum\"\nFROM bla WHERE s = 'Mum' \\; -- no mum here\nSELECT * FROM bla ORDER BY 1;\nCOMMIT;\n\n-- reset all\n\\set AUTOCOMMIT on\n\\set ON_ERROR_ROLLBACK off\n\\echo '# final ON_ERROR_ROLLBACK:' :ON_ERROR_ROLLBACK\nDROP TABLE bla;\nDROP FUNCTION psql_error;\n\n-- check describing invalid multipart names\n\\dA regression.heap\n\\dA nonesuch.heap\n\\dt host.regression.pg_catalog.pg_class\n\\dt |.pg_catalog.pg_class\n\\dt nonesuch.pg_catalog.pg_class\n\\da host.regression.pg_catalog.sum\n\\da +.pg_catalog.sum\n\\da nonesuch.pg_catalog.sum\n\\dAc nonesuch.brin\n\\dAc regression.brin\n\\dAf nonesuch.brin\n\\dAf regression.brin\n\\dAo nonesuch.brin\n\\dAo regression.brin\n\\dAp nonesuch.brin\n\\dAp regression.brin\n\\db nonesuch.pg_default\n\\db regression.pg_default\n\\dc host.regression.public.conversion\n\\dc (.public.conversion\n\\dc nonesuch.public.conversion\n\\dC host.regression.pg_catalog.int8\n\\dC ).pg_catalog.int8\n\\dC nonesuch.pg_catalog.int8\n\\dd host.regression.pg_catalog.pg_class\n\\dd [.pg_catalog.pg_class\n\\dd nonesuch.pg_catalog.pg_class\n\\dD host.regression.public.gtestdomain1\n\\dD ].public.gtestdomain1\n\\dD nonesuch.public.gtestdomain1\n\\ddp host.regression.pg_catalog.pg_class\n\\ddp {.pg_catalog.pg_class\n\\ddp nonesuch.pg_catalog.pg_class\n\\dE host.regression.public.ft\n\\dE }.public.ft\n\\dE nonesuch.public.ft\n\\di host.regression.public.tenk1_hundred\n\\di ..public.tenk1_hundred\n\\di nonesuch.public.tenk1_hundred\n\\dm host.regression.public.mvtest_bb\n\\dm ^.public.mvtest_bb\n\\dm nonesuch.public.mvtest_bb\n\\ds host.regression.public.check_seq\n\\ds regression|mydb.public.check_seq\n\\ds nonesuch.public.check_seq\n\\dt host.regression.public.b_star\n\\dt regres+ion.public.b_star\n\\dt nonesuch.public.b_star\n\\dv host.regression.public.shoe\n\\dv regress(ion).public.shoe\n\\dv nonesuch.public.shoe\n\\des nonesuch.server\n\\des regression.server\n\\des nonesuch.server\n\\des regression.server\n\\des nonesuch.username\n\\des regression.username\n\\dew nonesuch.fdw\n\\dew regression.fdw\n\\df host.regression.public.namelen\n\\df regres[qrstuv]ion.public.namelen\n\\df nonesuch.public.namelen\n\\dF host.regression.pg_catalog.arabic\n\\dF regres{1,2}ion.pg_catalog.arabic\n\\dF nonesuch.pg_catalog.arabic\n\\dFd host.regression.pg_catalog.arabic_stem\n\\dFd regres?ion.pg_catalog.arabic_stem\n\\dFd nonesuch.pg_catalog.arabic_stem\n\\dFp host.regression.pg_catalog.default\n\\dFp ^regression.pg_catalog.default\n\\dFp nonesuch.pg_catalog.default\n\\dFt host.regression.pg_catalog.ispell\n\\dFt regression$.pg_catalog.ispell\n\\dFt nonesuch.pg_catalog.ispell\n\\dg nonesuch.pg_database_owner\n\\dg regression.pg_database_owner\n\\dL host.regression.plpgsql\n\\dL *.plpgsql\n\\dL nonesuch.plpgsql\n\\dn host.regression.public\n\\dn \"\"\"\".public\n\\dn nonesuch.public\n\\do host.regression.public.!=-\n\\do \"regression|mydb\".public.!=-\n\\do nonesuch.public.!=-\n\\dO host.regression.pg_catalog.POSIX\n\\dO .pg_catalog.POSIX\n\\dO nonesuch.pg_catalog.POSIX\n\\dp host.regression.public.a_star\n\\dp \"regres+ion\".public.a_star\n\\dp nonesuch.public.a_star\n\\dP host.regression.public.mlparted\n\\dP \"regres(sion)\".public.mlparted\n\\dP nonesuch.public.mlparted\n\\drds nonesuch.lc_messages\n\\drds regression.lc_messages\n\\dRp public.mypub\n\\dRp regression.mypub\n\\dRs public.mysub\n\\dRs regression.mysub\n\\dT host.regression.public.widget\n\\dT \"regression{1,2}\".public.widget\n\\dT nonesuch.public.widget\n\\dx regression.plpgsql\n\\dx nonesuch.plpgsql\n\\dX host.regression.public.func_deps_stat\n\\dX \"^regression$\".public.func_deps_stat\n\\dX nonesuch.public.func_deps_stat\n\\dy regression.myevt\n\\dy nonesuch.myevt\n\n-- check that dots within quoted name segments are not counted\n\\dA \"no.such.access.method\"\n\\dt \"no.such.table.relation\"\n\\da \"no.such.aggregate.function\"\n\\dAc \"no.such.operator.class\"\n\\dAf \"no.such.operator.family\"\n\\dAo \"no.such.operator.of.operator.family\"\n\\dAp \"no.such.operator.support.function.of.operator.family\"\n\\db \"no.such.tablespace\"\n\\dc \"no.such.conversion\"\n\\dC \"no.such.cast\"\n\\dd \"no.such.object.description\"\n\\dD \"no.such.domain\"\n\\ddp \"no.such.default.access.privilege\"\n\\di \"no.such.index.relation\"\n\\dm \"no.such.materialized.view\"\n\\ds \"no.such.relation\"\n\\dt \"no.such.relation\"\n\\dv \"no.such.relation\"\n\\des \"no.such.foreign.server\"\n\\dew \"no.such.foreign.data.wrapper\"\n\\df \"no.such.function\"\n\\dF \"no.such.text.search.configuration\"\n\\dFd \"no.such.text.search.dictionary\"\n\\dFp \"no.such.text.search.parser\"\n\\dFt \"no.such.text.search.template\"\n\\dg \"no.such.role\"\n\\dL \"no.such.language\"\n\\dn \"no.such.schema\"\n\\do \"no.such.operator\"\n\\dO \"no.such.collation\"\n\\dp \"no.such.access.privilege\"\n\\dP \"no.such.partitioned.relation\"\n\\drds \"no.such.setting\"\n\\dRp \"no.such.publication\"\n\\dRs \"no.such.subscription\"\n\\dT \"no.such.data.type\"\n\\dx \"no.such.installed.extension\"\n\\dX \"no.such.extended.statistics\"\n\\dy \"no.such.event.trigger\"\n\n-- again, but with dotted schema qualifications.\n\\dA \"no.such.schema\".\"no.such.access.method\"\n\\dt \"no.such.schema\".\"no.such.table.relation\"\n\\da \"no.such.schema\".\"no.such.aggregate.function\"\n\\dAc \"no.such.schema\".\"no.such.operator.class\"\n\\dAf \"no.such.schema\".\"no.such.operator.family\"\n\\dAo \"no.such.schema\".\"no.such.operator.of.operator.family\"\n\\dAp \"no.such.schema\".\"no.such.operator.support.function.of.operator.family\"\n\\db \"no.such.schema\".\"no.such.tablespace\"\n\\dc \"no.such.schema\".\"no.such.conversion\"\n\\dC \"no.such.schema\".\"no.such.cast\"\n\\dd \"no.such.schema\".\"no.such.object.description\"\n\\dD \"no.such.schema\".\"no.such.domain\"\n\\ddp \"no.such.schema\".\"no.such.default.access.privilege\"\n\\di \"no.such.schema\".\"no.such.index.relation\"\n\\dm \"no.such.schema\".\"no.such.materialized.view\"\n\\ds \"no.such.schema\".\"no.such.relation\"\n\\dt \"no.such.schema\".\"no.such.relation\"\n\\dv \"no.such.schema\".\"no.such.relation\"\n\\des \"no.such.schema\".\"no.such.foreign.server\"\n\\dew \"no.such.schema\".\"no.such.foreign.data.wrapper\"\n\\df \"no.such.schema\".\"no.such.function\"\n\\dF \"no.such.schema\".\"no.such.text.search.configuration\"\n\\dFd \"no.such.schema\".\"no.such.text.search.dictionary\"\n\\dFp \"no.such.schema\".\"no.such.text.search.parser\"\n\\dFt \"no.such.schema\".\"no.such.text.search.template\"\n\\dg \"no.such.schema\".\"no.such.role\"\n\\dL \"no.such.schema\".\"no.such.language\"\n\\do \"no.such.schema\".\"no.such.operator\"\n\\dO \"no.such.schema\".\"no.such.collation\"\n\\dp \"no.such.schema\".\"no.such.access.privilege\"\n\\dP \"no.such.schema\".\"no.such.partitioned.relation\"\n\\drds \"no.such.schema\".\"no.such.setting\"\n\\dRp \"no.such.schema\".\"no.such.publication\"\n\\dRs \"no.such.schema\".\"no.such.subscription\"\n\\dT \"no.such.schema\".\"no.such.data.type\"\n\\dx \"no.such.schema\".\"no.such.installed.extension\"\n\\dX \"no.such.schema\".\"no.such.extended.statistics\"\n\\dy \"no.such.schema\".\"no.such.event.trigger\"\n\n-- again, but with current database and dotted schema qualifications.\n\\dt regression.\"no.such.schema\".\"no.such.table.relation\"\n\\da regression.\"no.such.schema\".\"no.such.aggregate.function\"\n\\dc regression.\"no.such.schema\".\"no.such.conversion\"\n\\dC regression.\"no.such.schema\".\"no.such.cast\"\n\\dd regression.\"no.such.schema\".\"no.such.object.description\"\n\\dD regression.\"no.such.schema\".\"no.such.domain\"\n\\di regression.\"no.such.schema\".\"no.such.index.relation\"\n\\dm regression.\"no.such.schema\".\"no.such.materialized.view\"\n\\ds regression.\"no.such.schema\".\"no.such.relation\"\n\\dt regression.\"no.such.schema\".\"no.such.relation\"\n\\dv regression.\"no.such.schema\".\"no.such.relation\"\n\\df regression.\"no.such.schema\".\"no.such.function\"\n\\dF regression.\"no.such.schema\".\"no.such.text.search.configuration\"\n\\dFd regression.\"no.such.schema\".\"no.such.text.search.dictionary\"\n\\dFp regression.\"no.such.schema\".\"no.such.text.search.parser\"\n\\dFt regression.\"no.such.schema\".\"no.such.text.search.template\"\n\\do regression.\"no.such.schema\".\"no.such.operator\"\n\\dO regression.\"no.such.schema\".\"no.such.collation\"\n\\dp regression.\"no.such.schema\".\"no.such.access.privilege\"\n\\dP regression.\"no.such.schema\".\"no.such.partitioned.relation\"\n\\dT regression.\"no.such.schema\".\"no.such.data.type\"\n\\dX regression.\"no.such.schema\".\"no.such.extended.statistics\"\n\n-- again, but with dotted database and dotted schema qualifications.\n\\dt \"no.such.database\".\"no.such.schema\".\"no.such.table.relation\"\n\\da \"no.such.database\".\"no.such.schema\".\"no.such.aggregate.function\"\n\\dc \"no.such.database\".\"no.such.schema\".\"no.such.conversion\"\n\\dC \"no.such.database\".\"no.such.schema\".\"no.such.cast\"\n\\dd \"no.such.database\".\"no.such.schema\".\"no.such.object.description\"\n\\dD \"no.such.database\".\"no.such.schema\".\"no.such.domain\"\n\\ddp \"no.such.database\".\"no.such.schema\".\"no.such.default.access.privilege\"\n\\di \"no.such.database\".\"no.such.schema\".\"no.such.index.relation\"\n\\dm \"no.such.database\".\"no.such.schema\".\"no.such.materialized.view\"\n\\ds \"no.such.database\".\"no.such.schema\".\"no.such.relation\"\n\\dt \"no.such.database\".\"no.such.schema\".\"no.such.relation\"\n\\dv \"no.such.database\".\"no.such.schema\".\"no.such.relation\"\n\\df \"no.such.database\".\"no.such.schema\".\"no.such.function\"\n\\dF \"no.such.database\".\"no.such.schema\".\"no.such.text.search.configuration\"\n\\dFd \"no.such.database\".\"no.such.schema\".\"no.such.text.search.dictionary\"\n\\dFp \"no.such.database\".\"no.such.schema\".\"no.such.text.search.parser\"\n\\dFt \"no.such.database\".\"no.such.schema\".\"no.such.text.search.template\"\n\\do \"no.such.database\".\"no.such.schema\".\"no.such.operator\"\n\\dO \"no.such.database\".\"no.such.schema\".\"no.such.collation\"\n\\dp \"no.such.database\".\"no.such.schema\".\"no.such.access.privilege\"\n\\dP \"no.such.database\".\"no.such.schema\".\"no.such.partitioned.relation\"\n\\dT \"no.such.database\".\"no.such.schema\".\"no.such.data.type\"\n\\dX \"no.such.database\".\"no.such.schema\".\"no.such.extended.statistics\"\n\n-- check \\drg and \\du\nCREATE ROLE regress_du_role0;\nCREATE ROLE regress_du_role1;\nCREATE ROLE regress_du_role2;\nCREATE ROLE regress_du_admin;\n\nGRANT regress_du_role0 TO regress_du_admin WITH ADMIN TRUE;\nGRANT regress_du_role1 TO regress_du_admin WITH ADMIN TRUE;\nGRANT regress_du_role2 TO regress_du_admin WITH ADMIN TRUE;\n\nGRANT regress_du_role0 TO regress_du_role1 WITH ADMIN TRUE, INHERIT TRUE, SET TRUE GRANTED BY regress_du_admin;\nGRANT regress_du_role0 TO regress_du_role2 WITH ADMIN TRUE, INHERIT FALSE, SET FALSE GRANTED BY regress_du_admin;\nGRANT regress_du_role1 TO regress_du_role2 WITH ADMIN TRUE , INHERIT FALSE, SET TRUE GRANTED BY regress_du_admin;\nGRANT regress_du_role0 TO regress_du_role1 WITH ADMIN FALSE, INHERIT TRUE, SET FALSE GRANTED BY regress_du_role1;\nGRANT regress_du_role0 TO regress_du_role2 WITH ADMIN FALSE, INHERIT TRUE , SET TRUE GRANTED BY regress_du_role1;\nGRANT regress_du_role0 TO regress_du_role1 WITH ADMIN FALSE, INHERIT FALSE, SET TRUE GRANTED BY regress_du_role2;\nGRANT regress_du_role0 TO regress_du_role2 WITH ADMIN FALSE, INHERIT FALSE, SET FALSE GRANTED BY regress_du_role2;\n\n\\drg regress_du_role*\n\\du regress_du_role*\n\nDROP ROLE regress_du_role0;\nDROP ROLE regress_du_role1;\nDROP ROLE regress_du_role2;\nDROP ROLE regress_du_admin;\n\n-- Test display of empty privileges.\nBEGIN;\n-- Create an owner for tested objects because output contains owner name.\nCREATE ROLE regress_zeropriv_owner;\nSET LOCAL ROLE regress_zeropriv_owner;\n\nCREATE DOMAIN regress_zeropriv_domain AS int;\nREVOKE ALL ON DOMAIN regress_zeropriv_domain FROM CURRENT_USER, PUBLIC;\n\\dD+ regress_zeropriv_domain\n\nCREATE PROCEDURE regress_zeropriv_proc() LANGUAGE sql AS '';\nREVOKE ALL ON PROCEDURE regress_zeropriv_proc() FROM CURRENT_USER, PUBLIC;\n\\df+ regress_zeropriv_proc\n\nCREATE TABLE regress_zeropriv_tbl (a int);\nREVOKE ALL ON TABLE regress_zeropriv_tbl FROM CURRENT_USER;\n\\dp regress_zeropriv_tbl\n\nCREATE TYPE regress_zeropriv_type AS (a int);\nREVOKE ALL ON TYPE regress_zeropriv_type FROM CURRENT_USER, PUBLIC;\n\\dT+ regress_zeropriv_type\n\nROLLBACK;\n\n-- Test display of default privileges with \\pset null.\nCREATE TABLE defprivs (a int);\n\\pset null '(default)'\n\\z defprivs\n\\zx defprivs\n\\pset null ''\nDROP TABLE defprivs;", "explanation": "PL/pgSQL object from PostgreSQL core test for Psql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 13052, "num_statements": 62} {"question": "PostgreSQL regression test 'timestamptz': Write the SELECT query (example 175).", "schema": null, "sql": "SELECT to_char(d1, 'YYYY A.D. YYYY a.d. YYYY bc HH:MI:SS P.M. HH:MI:SS p.m. HH:MI:SS pm')\n FROM TIMESTAMPTZ_TBL;", "explanation": "Regression test for Timestamptz in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT to_char(d1, 'YYYY A.D. YYYY a.d. YYYY bc HH:MI:SS P.M. HH:MI:SS p.m. HH:MI:SS pm')\n FROM TIMESTAMPTZ_TBL) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 114, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'triggers' (example 126).", "schema": null, "sql": "$$;\n\ndelete from parent where aid = 1;\nselect * from parent; select * from child;\n\ndrop table parent, child;\n\ndrop function parent_upd_func();\ndrop function parent_del_func();\ndrop function child_ins_func();\ndrop function child_del_func();\n\n-- similar case, but with a self-referencing FK so that parent and child\n-- rows can be affected by a single operation\n\ncreate temp table self_ref_trigger (\n id int primary key,\n parent int references self_ref_trigger,\n data text,\n nchildren int not null default 0\n);\n\ncreate function self_ref_trigger_ins_func()\n returns trigger language plpgsql as\n$$\nbegin\n if new.parent is not null then\n update self_ref_trigger set nchildren = nchildren + 1\n where id = new.parent;", "explanation": "PL/pgSQL object from PostgreSQL core test for Triggers.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 732, "num_statements": 11} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 59).", "schema": null, "sql": "-- these are obsolete/deprecated:\nCREATE OPERATOR @ (\n\tLEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_contains,\n\tCOMMUTATOR = '~',\n\tRESTRICT = contsel, JOIN = contjoinsel\n);", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 176, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'brin' (example 84).", "schema": null, "sql": "CREATE INDEX brin_test_toast_idx ON brintest_3 USING brin (b, c);", "explanation": "DDL from PostgreSQL core regression test for Brin.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 65, "num_statements": 1} {"question": "pgTAP test for Functap (assertion 80).", "schema": null, "sql": "SELECT * FROM check_test(\n function_lang_is( 'someproc', 'sql', 'whatever' ),\n true,\n 'function_lang_is(schema, proc, desc)',\n 'whatever',\n ''\n);", "explanation": "SQL assertion from pgTAP test suite for Functap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 160, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'partition_join' (example 6).", "schema": null, "sql": "INSERT INTO prt1 SELECT i, i % 25, to_char(i, 'FM0000') FROM generate_series(0, 599) i WHERE i % 2 = 0;", "explanation": "DML from PostgreSQL core regression test for Partition Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 103, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 23).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION diag( VARIADIC text[] );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 59, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'domain' (example 3).", "schema": null, "sql": "create domain dependenttypetest domaindroptest;", "explanation": "DDL from PostgreSQL core regression test for Domain.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_advanced", "is_postgresql_specific": true, "sql_length": 47, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'stats_ext' (example 11).", "schema": null, "sql": "CREATE STATISTICS tst ON (x || 'x'), (x || 'x'), (y + 1), (x || 'x'), (x || 'x'), (y + 1), (x || 'x'), (x || 'x'), (y + 1) FROM ext_stats_test;", "explanation": "DDL from PostgreSQL core regression test for Stats Ext.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 143, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'partition_info' (example 12).", "schema": null, "sql": "CREATE TABLE ptif_test2 PARTITION OF ptif_test\n FOR VALUES FROM (100) TO (200);", "explanation": "DDL from PostgreSQL core regression test for Partition Info.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 80, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'rangefuncs' (example 18).", "schema": null, "sql": "create temporary view vw_ord as select * from (values (1)) v(n) join rows from(rngfunct(1),rngfunct(2)) with ordinality as z(a,b,c,d,ord) on (n=ord);", "explanation": "DDL from PostgreSQL core regression test for Rangefuncs.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "query_join", "is_postgresql_specific": false, "sql_length": 149, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'cube' (example 204).", "schema": null, "sql": "SELECT distance_taxicab('(1,1)'::cube, '(4,5)'::cube);", "explanation": "Example query from the 'cube' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "query_select", "is_postgresql_specific": true, "sql_length": 54, "num_statements": 1} {"question": "pgTAP test for Aretap (assertion 129).", "schema": null, "sql": "SELECT * FROM check_test(\n rules_are( 'fou', ARRAY['ins_me', 'upd_me', 'del_me'] ),\n false,\n 'rules_are(table, rules) + missing',\n 'Relation fou should have the correct rules',\n ' Missing rules:\n del_me'\n);", "explanation": "SQL assertion from pgTAP test suite for Aretap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 231, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'matview' (example 82).", "schema": null, "sql": "INSERT INTO mvtest_foo VALUES(3, 4, 5);", "explanation": "DML from PostgreSQL core regression test for Matview.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 39, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'inet' (example 16).", "schema": null, "sql": "INSERT INTO INET_TBL (c, i) VALUES ('10', '9.1.2.3/8');", "explanation": "DML from PostgreSQL core regression test for Inet.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 55, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'rules' (example 157).", "schema": null, "sql": "delete from rtest_t7;", "explanation": "DML from PostgreSQL core regression test for Rules.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_delete", "is_postgresql_specific": false, "sql_length": 21, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'domain' (example 208).", "schema": null, "sql": "update domnotnull set col1 = null;\t\t-- fails\nselect conname, pg_get_constraintdef(oid) from pg_constraint\n where contypid = 'dnotnulltest'::regtype;", "explanation": "DML from PostgreSQL core regression test for Domain.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_update", "is_postgresql_specific": false, "sql_length": 148, "num_statements": 2} {"question": "PostgreSQL regression test 'int2': Write the SELECT query (example 25).", "schema": null, "sql": "SELECT i.* FROM INT2_TBL i WHERE i.f1 <= int2 '0';", "explanation": "Regression test for Int2 in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT i.* FROM INT2_TBL i WHERE i.f1 <= int2 '0') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 50, "num_statements": 1} {"question": "PL/pgSQL test: Plpython Trigger (example 5).", "schema": null, "sql": "CREATE TRIGGER users_update_trig BEFORE UPDATE ON users FOR EACH ROW\n\tEXECUTE PROCEDURE users_update ('willem');", "explanation": "PL/pgSQL example from PostgreSQL source test for Plpython Trigger.", "validation_query": null, "source": "plpgsql_source", "difficulty": "advanced", "category": "dml_update", "is_postgresql_specific": true, "sql_length": 112, "num_statements": 1} {"question": "PostgreSQL regression test 'foreign_data': Write the SELECT query (example 268).", "schema": null, "sql": "SELECT has_server_privilege(\n (SELECT oid FROM pg_roles WHERE rolname='regress_test_role'), 's8', 'USAGE');", "explanation": "Regression test for Foreign Data in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT has_server_privilege(\n (SELECT oid FROM pg_roles WHERE rolname='regress_test_role'), 's8', 'USAGE')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 110, "num_statements": 1} {"question": "PostgreSQL regression test 'inet': Write the SELECT query (example 63).", "schema": null, "sql": "SELECT * FROM inet_tbl WHERE i >= '192.168.1.0/24'::cidr ORDER BY i;", "explanation": "Regression test for Inet in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT * FROM inet_tbl WHERE i >= '192.168.1.0/24'::cidr ORDER BY i) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 68, "num_statements": 1} {"question": "Show a SQL definition from the citus project (row_types, item 9).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION identity_returner(x anyelement)\nRETURNS anyelement\nAS $$\nBEGIN\n\tRETURN x;\nEND;\n$$ language plpgsql;", "explanation": "SQL definition from the open-source citus PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 126, "num_statements": 3} {"question": "PostgreSQL regression test 'roleattributes': Write the SELECT query (example 44).", "schema": null, "sql": "SELECT rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, rolvaliduntil FROM pg_authid WHERE rolname = 'regress_test_user_canlogin';", "explanation": "Regression test for Roleattributes in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, rolvaliduntil FROM pg_authid WHERE rolname = 'regress_test_user_canlogin') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 210, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'citext' (example 299).", "schema": null, "sql": "INSERT INTO caster (uuid) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::citext);", "explanation": "Example query from the 'citext' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 91, "num_statements": 1} {"question": "pgTAP test for Resultset (assertion 182).", "schema": null, "sql": "INSERT INTO names (name) VALUES ('Jesse');", "explanation": "SQL assertion from pgTAP test suite for Resultset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 42, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'btree_gin' (example 5).", "schema": null, "sql": "SELECT * FROM test_date WHERE i<'2004-10-26'::date ORDER BY i;", "explanation": "Example query from the 'btree_gin' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 62, "num_statements": 1} {"question": "PostgreSQL Indices: show example 1.", "schema": null, "sql": "CREATE TABLE test1 ( id integer, content varchar );", "explanation": "Example from PostgreSQL documentation on Indices.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 51, "num_statements": 1} {"question": "Show a SQL definition from the pg_partman project (pg_partman--4.6.1--4.6.2, item 12).", "schema": null, "sql": "CREATE OR REPLACE FUNCTION @extschema@.apply_foreign_keys(p_parent_table text, p_child_table text, p_job_id bigint DEFAULT NULL, p_debug boolean DEFAULT false) RETURNS void\n LANGUAGE plpgsql\n AS $$\nDECLARE\n\nex_context text;\nex_detail text;\nex_hint text;\nex_message text;\nv_count int := 0;\nv_job_id bigint;\nv_jobmon text;\nv_jobmon_schema text;\nv_new_search_path text;\nv_old_search_path text;\nv_parent_schema text;\nv_parent_tablename text;\nv_ref_schema text;\nv_ref_table text;\nv_relkind char;\nv_row record;\nv_schemaname text;\nv_sql text;\nv_step_id bigint;\nv_tablename text;\n\nBEGIN\n/*\n * Apply foreign keys that exist on the given parent to the given child table\n */\n\nSELECT jobmon INTO v_jobmon FROM @extschema@.part_config WHERE parent_table = p_parent_table;\n\nIF v_jobmon THEN\n SELECT nspname INTO v_jobmon_schema FROM pg_catalog.pg_namespace n, pg_catalog.pg_extension e WHERE e.extname = 'pg_jobmon' AND e.extnamespace = n.oid;\n IF v_jobmon_schema IS NOT NULL THEN\n SELECT current_setting('search_path') INTO v_old_search_path;\n IF length(v_old_search_path) > 0 THEN\n v_new_search_path := '@extschema@,pg_temp,'||v_old_search_path;\n ELSE\n v_new_search_path := '@extschema@,pg_temp';\n END IF;\n v_new_search_path := format('%s,%s',v_jobmon_schema, v_new_search_path);\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_new_search_path, 'false');\n END IF;\nEND IF;\n\nSELECT n.nspname, c.relname, c.relkind INTO v_parent_schema, v_parent_tablename, v_relkind\nFROM pg_catalog.pg_class c\nJOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid\nWHERE n.nspname = split_part(p_parent_table, '.', 1)::name\nAND c.relname = split_part(p_parent_table, '.', 2)::name;\n\nIF v_relkind = 'p' THEN\n RAISE EXCEPTION 'This function cannot run on natively partitioned tables';\nELSIF v_relkind IS NULL THEN\n RAISE EXCEPTION 'Unable to find given table in system catalogs: %.%', v_parent_schema, v_parent_tablename;\nEND IF;\n\nSELECT n.nspname, c.relname INTO v_schemaname, v_tablename\nFROM pg_catalog.pg_class c\nJOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid\nWHERE n.nspname = split_part(p_child_table, '.', 1)::name\nAND c.relname = split_part(p_child_table, '.', 2)::name;\n\nIF v_jobmon_schema IS NOT NULL THEN\n IF p_job_id IS NULL THEN\n v_job_id := add_job(format('PARTMAN APPLYING FOREIGN KEYS: %s', p_parent_table));\n ELSE -- Don't create a new job, add steps into given job\n v_job_id := p_job_id;\n END IF;\nEND IF;\n\nIF v_jobmon_schema IS NOT NULL THEN\n v_step_id := add_step(v_job_id, format('Applying foreign keys to %s if they exist on parent', p_child_table));\nEND IF;\n\nIF v_tablename IS NULL THEN\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'CRITICAL', format('Target child table (%s) does not exist.', p_child_table));\n PERFORM fail_job(v_job_id);\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');\n END IF;\n RAISE EXCEPTION 'Target child table (%) does not exist.', p_child_table;\n RETURN;\nEND IF;\n\nFOR v_row IN\n SELECT pg_get_constraintdef(con.oid) AS constraint_def\n FROM pg_catalog.pg_constraint con\n JOIN pg_catalog.pg_class c ON con.conrelid = c.oid\n JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid\n WHERE c.relname = v_parent_tablename\n AND n.nspname = v_parent_schema\n AND contype = 'f'\nLOOP\n v_sql := format('ALTER TABLE %I.%I ADD %s'\n , v_schemaname\n , v_tablename\n , v_row.constraint_def);\n\n IF p_debug THEN\n RAISE NOTICE 'Constraint creation query: %', v_sql;\n END IF;\n\n EXECUTE v_sql;\n\n IF v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'FK applied');\n END IF;\n v_count := v_count + 1;\n\nEND LOOP;\n\nIF v_count = 0 AND v_jobmon_schema IS NOT NULL THEN\n PERFORM update_step(v_step_id, 'OK', 'No FKs found on parent');\nEND IF;\n\n\nIF v_jobmon_schema IS NOT NULL THEN\n PERFORM close_job(v_job_id);\n EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');\nEND IF;\n\nEXCEPTION\n WHEN OTHERS THEN\n GET STACKED DIAGNOSTICS ex_message = MESSAGE_TEXT,\n ex_context = PG_EXCEPTION_CONTEXT,\n ex_detail = PG_EXCEPTION_DETAIL,\n ex_hint = PG_EXCEPTION_HINT;\n IF v_jobmon_schema IS NOT NULL THEN\n IF v_job_id IS NULL THEN\n EXECUTE format('SELECT %I.add_job(''PARTMAN CREATE APPLYING FOREIGN KEYS: %s'')', v_jobmon_schema, p_parent_table) INTO v_job_id;\n EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before job logging started'')', v_jobmon_schema, v_job_id, p_parent_table) INTO v_step_id;\n ELSIF v_step_id IS NULL THEN\n EXECUTE format('SELECT %I.add_step(%s, ''EXCEPTION before first step logged'')', v_jobmon_schema, v_job_id) INTO v_step_id;\n END IF;\n EXECUTE format('SELECT %I.update_step(%s, ''CRITICAL'', %L)', v_jobmon_schema, v_step_id, 'ERROR: '||coalesce(SQLERRM,'unknown'));\n EXECUTE format('SELECT %I.fail_job(%s)', v_jobmon_schema, v_job_id);\n END IF;\n RAISE EXCEPTION '%\nCONTEXT: %\nDETAIL: %\nHINT: %', ex_message, ex_context, ex_detail, ex_hint;\nEND\n$$;", "explanation": "SQL definition from the open-source pg_partman PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 5564, "num_statements": 71} {"question": "PostgreSQL Ddl: show example 41.", "schema": null, "sql": "CREATE TABLE products ( product_no integer, price numeric, valid_at daterange );", "explanation": "Example from PostgreSQL documentation on Ddl.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 80, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'with' (example 254).", "schema": null, "sql": "CREATE FUNCTION y_trigger() RETURNS trigger AS $$\nbegin\n raise notice 'y_trigger: a = %', new.a;\n return new;\nend;\n$$ LANGUAGE plpgsql;", "explanation": "DDL from PostgreSQL core regression test for With.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 137, "num_statements": 4} {"question": "PostgreSQL regression test 'rowsecurity': Write the SELECT query (example 839).", "schema": null, "sql": "SELECT (string_to_array(polqual, ':'))[7] AS inputcollid FROM pg_policy WHERE polrelid = 'coll_t'::regclass;", "explanation": "Regression test for Rowsecurity in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT (string_to_array(polqual, ':'))[7] AS inputcollid FROM pg_policy WHERE polrelid = 'coll_t'::regclass) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 108, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'constraints' (example 31).", "schema": null, "sql": "INSERT INTO NE_CHECK_TBL VALUES (2);", "explanation": "DML from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 36, "num_statements": 1} {"question": "PostgreSQL regression test 'updatable_views': Write the SELECT query (example 100).", "schema": null, "sql": "SELECT table_name, is_insertable_into\n FROM information_schema.tables\n WHERE table_name LIKE 'rw_view%'\n ORDER BY table_name;", "explanation": "Regression test for Updatable Views in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT table_name, is_insertable_into\n FROM information_schema.tables\n WHERE table_name LIKE 'rw_view%'\n ORDER BY table_name) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 126, "num_statements": 1} {"question": "PostgreSQL regression test 'interval': Write the SELECT query (example 374).", "schema": null, "sql": "SELECT interval 'infinity' * 'nan';", "explanation": "Regression test for Interval in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT interval 'infinity' * 'nan') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'encoding' (example 60).", "schema": null, "sql": "DROP FUNCTION test_valid_server_encoding;", "explanation": "PL/pgSQL object from PostgreSQL core test for Encoding.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 41, "num_statements": 1} {"question": "PostgreSQL regression test 'timestamptz': Write the SELECT query (example 134).", "schema": null, "sql": "SELECT d1 FROM TIMESTAMPTZ_TBL\n WHERE d1 >= timestamp with time zone '1997-01-02';", "explanation": "Regression test for Timestamptz in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT d1 FROM TIMESTAMPTZ_TBL\n WHERE d1 >= timestamp with time zone '1997-01-02') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 84, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'alter_table' (example 472).", "schema": null, "sql": "CREATE TABLE fail_part (LIKE list_parted);", "explanation": "DDL from PostgreSQL core regression test for Alter Table.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 42, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 3).", "schema": null, "sql": "-- dblink_connect_u allows non-superusers to use\n-- non-password authenticated connections, but initially\n-- privileges are revoked from public\nCREATE FUNCTION dblink_connect_u (text)\nRETURNS text\nAS 'MODULE_PATHNAME','dblink_connect'\nLANGUAGE C STRICT PARALLEL RESTRICTED SECURITY DEFINER;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "other", "is_postgresql_specific": false, "sql_length": 290, "num_statements": 1} {"question": "PostgreSQL regression test 'interval': Write the SELECT query (example 409).", "schema": null, "sql": "SELECT INTERVAL '2 minutes ago 5 days';", "explanation": "Regression test for Interval in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT INTERVAL '2 minutes ago 5 days') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 39, "num_statements": 1} {"question": "PostgreSQL regression test 'xid': Write the SELECT query (example 44).", "schema": null, "sql": "select * from pg_input_error_info('12:16:14,13', 'pg_snapshot');", "explanation": "Regression test for Xid in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from pg_input_error_info('12:16:14,13', 'pg_snapshot')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 64, "num_statements": 1} {"question": "PostgreSQL regression test 'groupingsets': Write the SELECT query (example 73).", "schema": null, "sql": "select a, b, sum(c), sum(sum(c)) over (order by a,b) as rsum\n from gstest2 group by cube (a,b) order by rsum, a, b;", "explanation": "Regression test for Groupingsets in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select a, b, sum(c), sum(sum(c)) over (order by a,b) as rsum\n from gstest2 group by cube (a,b) order by rsum, a, b) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "advanced", "category": "query_window_function", "is_postgresql_specific": true, "sql_length": 116, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 258).", "schema": null, "sql": "SELECT JSON_QUERY('\"a\"', '$.a' RETURNING queryfuncs_test_domain DEFAULT (select '\"1\"')::queryfuncs_test_domain ON ERROR);", "explanation": "Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_QUERY('\"a\"', '$.a' RETURNING queryfuncs_test_domain DEFAULT (select '\"1\"')::queryfuncs_test_domain ON ERROR)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 121, "num_statements": 1} {"question": "PostgreSQL regression test 'numeric': Write the SELECT query (example 963).", "schema": null, "sql": "select scale(numeric 'inf');", "explanation": "Regression test for Numeric in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select scale(numeric 'inf')) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 28, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'plpgsql' (example 528).", "schema": null, "sql": "$$ language plpgsql parallel safe;\n\nset debug_parallel_query to on;\n\nexplain (verbose, costs off) select error_trap_test();\nselect error_trap_test();\n\nreset debug_parallel_query;\n\ndrop function error_trap_test();\ndrop function zero_divide();\n\n-- check cases where implicit SQLSTATE variable could be confused with\n-- SQLSTATE as a keyword, cf bug #5524\ncreate or replace function raise_test() returns void as $$\nbegin\n perform 1/0;", "explanation": "PL/pgSQL object from PostgreSQL core test for Plpgsql.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 432, "num_statements": 8} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 5).", "schema": null, "sql": "CREATE FUNCTION gbt_macad8_picksplit(internal, internal)\nRETURNS internal\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 123, "num_statements": 1} {"question": "PostgreSQL Query: show example 2.", "schema": null, "sql": "CREATE TABLE cities ( name varchar(80), location point );", "explanation": "Example from PostgreSQL documentation on Query.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 57, "num_statements": 1} {"question": "Write the PL/pgSQL object from PostgreSQL regression test 'triggers' (example 107).", "schema": null, "sql": "$$;\ncreate trigger depth_b_tr before insert on depth_b\n for each row execute procedure depth_b_tf();\n\ncreate function depth_c_tf() returns trigger\n language plpgsql as $$\nbegin\n raise notice '%: depth = %', tg_name, pg_trigger_depth();", "explanation": "PL/pgSQL object from PostgreSQL core test for Triggers.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "plpgsql_trigger", "is_postgresql_specific": true, "sql_length": 238, "num_statements": 3} {"question": "Write the DDL statement from PostgreSQL regression test 'join' (example 540).", "schema": null, "sql": "create temp table t (a int unique, b int);", "explanation": "DDL from PostgreSQL core regression test for Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 42, "num_statements": 1} {"question": "PostgreSQL regression test 'case': Write the SELECT query (example 44).", "schema": null, "sql": "SELECT CASE\n (CASE vol('bar')\n WHEN 'foo' THEN 'it was foo!'\n WHEN vol(null) THEN 'null input'\n WHEN 'bar' THEN 'it was bar!' END\n )\n WHEN 'it was foo!' THEN 'foo recognized'\n WHEN 'it was bar!' THEN 'bar recognized'\n ELSE 'unrecognized' END;", "explanation": "Regression test for Case in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT CASE\n (CASE vol('bar')\n WHEN 'foo' THEN 'it was foo!'\n WHEN vol(null) THEN 'null input'\n WHEN 'bar' THEN 'it was bar!' END\n )\n WHEN 'it was foo!' THEN 'foo recognized'\n WHEN 'it was bar!' THEN 'bar recognized'\n ELSE 'unrecognized' END) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 256, "num_statements": 1} {"question": "PL/pgSQL test: Plperl Util (example 5).", "schema": null, "sql": "-- test quote_ident\n\ncreate or replace function perl_quote_ident() returns setof text language plperl as $$\n\treturn_next \"undef: \".quote_ident(undef); # generates undef warning if warnings enabled\n\treturn_next \"$_: \".quote_ident($_)\n\t\tfor q{foo}, q{a'b}, q{a\"b}, q{c''d}, q{e\\f}, q{g.h}, q{};\n\treturn undef;\n$$;", "explanation": "PL/pgSQL example from PostgreSQL source test for Plperl Util.", "validation_query": null, "source": "plpgsql_source", "difficulty": "advanced", "category": "plpgsql_function", "is_postgresql_specific": true, "sql_length": 311, "num_statements": 4} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 64).", "schema": null, "sql": "CREATE FUNCTION g_cube_penalty(internal,internal,internal)\nRETURNS internal\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "advanced", "category": "other", "is_postgresql_specific": false, "sql_length": 139, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'jsonb_plperl' (example 14).", "schema": null, "sql": "SELECT testTextToJsonbObject(NULL);", "explanation": "Example query from the 'jsonb_plperl' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pgcrypto' (example 13).", "schema": null, "sql": "select encode(decrypt(encrypt('foo', '0123456', 'aes') || '\\x00'::bytea, '0123456', 'aes'), 'escape');", "explanation": "Example query from the 'pgcrypto' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 102, "num_statements": 1} {"question": "pgTAP test for Pgtap--Unpackaged--0.91.0 (assertion 399).", "schema": null, "sql": "ALTER EXTENSION pgtap ADD FUNCTION has_leftop ( NAME, NAME, NAME );", "explanation": "SQL assertion from pgTAP test suite for Pgtap--Unpackaged--0.91.0.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 67, "num_statements": 1} {"question": "PostgreSQL regression test 'strings': Write the SELECT query (example 261).", "schema": null, "sql": "SELECT 'indio' LIKE 'in_o' AS \"false\";", "explanation": "Regression test for Strings in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT 'indio' LIKE 'in_o' AS \"false\") AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 38, "num_statements": 1} {"question": "pgTAP test for Do Tap (assertion 10).", "schema": null, "sql": "SELECT is(\n findfuncs('foo'),\n CASE WHEN pg_version_num() < 80300 THEN NULL ELSE '{}'::text[] END,\n 'findfuncs(unknown) should find no tests'\n);", "explanation": "SQL assertion from pgTAP test suite for Do Tap.", "validation_query": null, "source": "pgtap_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 153, "num_statements": 1} {"question": "PostgreSQL regression test 'regex': Write the SELECT query (example 7).", "schema": null, "sql": "select 'abc abd abc' ~ '^(\\w+)( \\1)+$' as f;", "explanation": "Regression test for Regex in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select 'abc abd abc' ~ '^(\\w+)( \\1)+$' as f) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 44, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'constraints' (example 468).", "schema": null, "sql": "INSERT INTO notnull_tbl1_upg VALUES (NULL, 1), (NULL, 2), (300, 3);", "explanation": "DML from PostgreSQL core regression test for Constraints.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 67, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'join' (example 786).", "schema": null, "sql": "create table fkest (x integer, x10 integer, x10b integer, x100 integer);", "explanation": "DDL from PostgreSQL core regression test for Join.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": false, "sql_length": 72, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 137).", "schema": null, "sql": "SELECT jsonb_exists_all('{\"a\":null, \"b\":\"qq\"}', ARRAY['a','b']);", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT jsonb_exists_all('{\"a\":null, \"b\":\"qq\"}', ARRAY['a','b'])) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "intermediate", "category": "query_select", "is_postgresql_specific": false, "sql_length": 64, "num_statements": 1} {"question": "Write the SQL definition from PostgreSQL contrib extension 'contrib' (item 112).", "schema": null, "sql": "CREATE FUNCTION gbt_tstz_compress(internal)\nRETURNS internal\nAS 'MODULE_PATHNAME'\nLANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;", "explanation": "SQL definition from the 'contrib' PostgreSQL contrib extension.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 124, "num_statements": 1} {"question": "pgTAP test for Resultset (assertion 293).", "schema": null, "sql": "CREATE table dubs (pk SERIAL PRIMARY KEY, id int, name text);", "explanation": "SQL assertion from pgTAP test suite for Resultset.", "validation_query": null, "source": "pgtap_tests", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 61, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'create_index' (example 172).", "schema": null, "sql": "CREATE INDEX unlogged_hash_index ON unlogged_hash_table USING hash (id int4_ops);", "explanation": "DDL from PostgreSQL core regression test for Create Index.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "intermediate", "category": "ddl_index", "is_postgresql_specific": false, "sql_length": 81, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 423).", "schema": null, "sql": "select * from jsonb_to_record('{\"ia2\": [[[1], [2], [3]]]}') as x(ia2 int4[][]);", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select * from jsonb_to_record('{\"ia2\": [[[1], [2], [3]]]}') as x(ia2 int4[][])) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 79, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'timestamp' (example 91).", "schema": null, "sql": "INSERT INTO TIMESTAMP_TBL VALUES ('Feb 29 17:32:01 1997');", "explanation": "DML from PostgreSQL core regression test for Timestamp.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": false, "sql_length": 58, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'pg_surgery' (example 31).", "schema": null, "sql": "select heap_force_freeze('mvw'::regclass, ARRAY['(0, 3)']::tid[]);", "explanation": "Example query from the 'pg_surgery' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 66, "num_statements": 1} {"question": "Show a query using PostgreSQL contrib extension 'xml2' (example 15).", "schema": null, "sql": "SELECT * FROM\nxpath_table('article_id',\n 'article_xml',\n 'articles',\n '/article/author|/article/pages|/article/title',\n 'date_entered > ''2003-01-01'' ')\nAS t(article_id integer, author text, page_count integer, title text);", "explanation": "Example query from the 'xml2' extension test/demo.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 268, "num_statements": 1} {"question": "Show a SQL definition from the pglogical project (pglogical--2.2.1, item 50).", "schema": null, "sql": "CREATE FUNCTION pglogical.wait_for_table_sync_complete(subscription_name name, relation regclass)\nRETURNS void RETURNS NULL ON NULL INPUT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_wait_for_table_sync_complete';", "explanation": "SQL definition from the open-source pglogical PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "other", "is_postgresql_specific": false, "sql_length": 221, "num_statements": 1} {"question": "PostgreSQL regression test 'name': Write the SELECT query (example 18).", "schema": null, "sql": "SELECT c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*';", "explanation": "Regression test for Name in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT c.f1 FROM NAME_TBL c WHERE c.f1 ~ '.*') AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 46, "num_statements": 1} {"question": "PostgreSQL regression test 'arrays': Write the SELECT query (example 265).", "schema": null, "sql": "select '[1:]={1}'::int[];", "explanation": "Regression test for Arrays in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (select '[1:]={1}'::int[]) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 25, "num_statements": 1} {"question": "Write the DML statement from PostgreSQL regression test 'domain' (example 112).", "schema": null, "sql": "insert into dcomptable values (array[row(1,2)]::dcomptypea); -- fail on uniqueness\ninsert into dcomptable (d1[1]) values(row(9,10));", "explanation": "DML from PostgreSQL core regression test for Domain.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 133, "num_statements": 2} {"question": "Show a SQL definition from the pglogical project (pglogical--2.2.1, item 39).", "schema": null, "sql": "CREATE TABLE pglogical.queue (\n queued_at timestamp with time zone NOT NULL,\n role name NOT NULL,\n replication_sets text[],\n message_type \"char\" NOT NULL,\n message json NOT NULL\n);", "explanation": "SQL definition from the open-source pglogical PostgreSQL project.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "ddl_table", "is_postgresql_specific": true, "sql_length": 195, "num_statements": 1} {"question": "PostgreSQL regression test 'jsonb': Write the SELECT query (example 150).", "schema": null, "sql": "SELECT jsonb_typeof('[]') AS array;", "explanation": "Regression test for Jsonb in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT jsonb_typeof('[]') AS array) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": false, "sql_length": 35, "num_statements": 1} {"question": "PostgreSQL regression test 'sqljson_queryfuncs': Write the SELECT query (example 145).", "schema": null, "sql": "SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING json);", "explanation": "Regression test for Sqljson Queryfuncs in PostgreSQL core test suite.", "validation_query": "SELECT count(*) FROM (SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING json)) AS _sub;", "source": "postgresql_regression_tests", "difficulty": "basic", "category": "query_select", "is_postgresql_specific": true, "sql_length": 53, "num_statements": 1} {"question": "Write the DDL statement from PostgreSQL regression test 'returning' (example 35).", "schema": null, "sql": "CREATE OR REPLACE RULE voo_i AS ON INSERT TO voo DO INSTEAD\n INSERT INTO foo VALUES(new.*, 57) RETURNING f1, f2;", "explanation": "DDL from PostgreSQL core regression test for Returning.", "validation_query": null, "source": "community_sql_datasets", "difficulty": "basic", "category": "dml_insert", "is_postgresql_specific": true, "sql_length": 113, "num_statements": 1} {"question": "PostgreSQL regression test 'tsearch': Write the SELECT query (example 286).", "schema": null, "sql": "SELECT ts_headline('english', '\n\n\n\nSea view wow foo bar qq\nYES  \nff-bg\n