From 69b686660b662f4d56e7bcb5afbb901c1c317156 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 12 Oct 2026 15:10:49 +0000 Subject: [PATCH 1/7] fix(pretty-print): only change layout, case and redundant quoting The formatter rewrote what was written: it dropped pg_catalog qualifiers, replaced dollar-quote tags, dropped argument names from signatures, uppercased some function and privilege names, and broke lines that fit. - Function calls keep their name as qualified, SQL-standard syntax is only used for calls the parser flagged as written in it - Function and DO bodies keep their source quoting byte for byte - Signatures are printed from objfuncargs, with names and modes - Every keyword, privilege and option name follows keywordCase - Constraint, index and other names lose redundant quotes - A group stays on one line whenever it fits, broken column definitions and constraints continue one level deeper, and parenthesized lists break inside their parentheses - CREATE INDEX keeps its head, opclasses and short predicate together - End-of-line comments after a comma stay on their line - Blank lines between statements are normalized to at most one The semantic check no longer normalizes away qualifiers, argument names, function name case, SET values or function bodies, and the regression suite now also checks that formatting is idempotent. --- crates/pgls_pretty_print/src/comments.rs | 43 +- crates/pgls_pretty_print/src/emitter.rs | 89 +- crates/pgls_pretty_print/src/lib.rs | 8 +- .../src/nodes/access_priv.rs | 18 +- crates/pgls_pretty_print/src/nodes/alias.rs | 6 +- .../src/nodes/alter_fdw_stmt.rs | 6 +- .../src/nodes/alter_foreign_server_stmt.rs | 10 +- .../src/nodes/alter_operator_stmt.rs | 12 +- .../src/nodes/alter_publication_stmt.rs | 9 +- .../src/nodes/alter_subscription_stmt.rs | 5 +- .../src/nodes/alter_table_stmt.rs | 2 +- .../nodes/alter_tablespace_options_stmt.rs | 7 +- .../src/nodes/alter_type_stmt.rs | 8 +- .../src/nodes/alter_user_mapping_stmt.rs | 7 +- .../pgls_pretty_print/src/nodes/bool_expr.rs | 27 +- .../pgls_pretty_print/src/nodes/column_def.rs | 5 + .../src/nodes/common_table_expr.rs | 6 +- .../pgls_pretty_print/src/nodes/constraint.rs | 135 +- .../pgls_pretty_print/src/nodes/copy_stmt.rs | 9 +- .../src/nodes/create_enum_stmt.rs | 7 +- .../src/nodes/create_event_trig_stmt.rs | 6 +- .../src/nodes/create_fdw_stmt.rs | 7 +- .../src/nodes/create_foreign_server_stmt.rs | 10 +- .../src/nodes/create_foreign_table_stmt.rs | 5 +- .../src/nodes/create_function_stmt.rs | 18 +- .../src/nodes/create_op_class_item.rs | 15 +- .../src/nodes/create_policy_stmt.rs | 2 +- .../src/nodes/create_publication_stmt.rs | 10 +- .../src/nodes/create_role_stmt.rs | 3 +- .../src/nodes/create_schema_stmt.rs | 2 +- .../src/nodes/create_stats_stmt.rs | 6 +- .../src/nodes/create_stmt.rs | 5 +- .../src/nodes/create_subscription_stmt.rs | 5 +- .../src/nodes/create_table_as_stmt.rs | 14 +- .../src/nodes/create_table_space_stmt.rs | 5 +- .../src/nodes/create_user_mapping_stmt.rs | 7 +- .../src/nodes/createdb_stmt.rs | 2 +- .../src/nodes/declare_cursor_stmt.rs | 2 +- .../pgls_pretty_print/src/nodes/def_elem.rs | 12 +- .../src/nodes/define_stmt.rs | 8 +- crates/pgls_pretty_print/src/nodes/do_stmt.rs | 10 +- .../src/nodes/dropdb_stmt.rs | 9 +- .../src/nodes/execute_stmt.rs | 5 +- .../src/nodes/explain_stmt.rs | 3 +- .../pgls_pretty_print/src/nodes/func_call.rs | 647 ++-- .../src/nodes/grant_role_stmt.rs | 10 +- .../pgls_pretty_print/src/nodes/grant_stmt.rs | 13 +- .../src/nodes/grouping_set.rs | 13 +- .../src/nodes/import_foreign_schema_stmt.rs | 10 +- .../pgls_pretty_print/src/nodes/index_elem.rs | 19 +- .../pgls_pretty_print/src/nodes/index_stmt.rs | 59 +- .../src/nodes/infer_clause.rs | 7 +- .../src/nodes/inline_code_block.rs | 4 +- .../pgls_pretty_print/src/nodes/int_list.rs | 11 +- .../pgls_pretty_print/src/nodes/join_expr.rs | 17 +- .../src/nodes/json_value_expr.rs | 4 +- .../pgls_pretty_print/src/nodes/lock_stmt.rs | 2 +- crates/pgls_pretty_print/src/nodes/mod.rs | 5 +- .../src/nodes/named_arg_expr.rs | 2 +- .../pgls_pretty_print/src/nodes/node_list.rs | 19 +- .../src/nodes/notify_stmt.rs | 2 +- .../src/nodes/object_with_args.rs | 16 +- .../pgls_pretty_print/src/nodes/oid_list.rs | 11 +- .../src/nodes/on_conflict_expr.rs | 6 +- .../src/nodes/partition_bound_spec.rs | 18 +- .../src/nodes/partition_spec.rs | 10 +- .../src/nodes/pl_assign_stmt.rs | 2 +- .../src/nodes/prepare_stmt.rs | 7 +- .../src/nodes/publication_table.rs | 6 +- .../src/nodes/range_function.rs | 5 +- .../src/nodes/range_table_func.rs | 6 +- .../src/nodes/range_table_sample.rs | 8 +- .../src/nodes/reindex_stmt.rs | 9 +- .../src/nodes/row_compare_expr.rs | 11 +- .../pgls_pretty_print/src/nodes/row_expr.rs | 10 +- .../pgls_pretty_print/src/nodes/stats_elem.rs | 2 +- crates/pgls_pretty_print/src/nodes/string.rs | 194 +- .../src/nodes/table_like_clause.rs | 2 +- .../src/nodes/table_sample_clause.rs | 7 +- .../pgls_pretty_print/src/nodes/type_name.rs | 106 +- .../src/nodes/vacuum_relation.rs | 10 +- .../src/nodes/vacuum_stmt.rs | 7 +- .../src/nodes/variable_set_stmt.rs | 43 +- .../src/nodes/variable_show_stmt.rs | 2 +- .../pgls_pretty_print/src/nodes/view_stmt.rs | 5 +- .../pgls_pretty_print/src/nodes/xml_expr.rs | 14 +- .../src/nodes/xml_serialize.rs | 8 +- crates/pgls_pretty_print/src/normalize.rs | 266 +- crates/pgls_pretty_print/src/renderer.rs | 118 +- .../tests/postgres_regress.rs | 20 +- .../tests__20220117141359_app_schema_100.snap | 6 +- .../tests__20220117141359_app_schema_80.snap | 9 +- .../tests__20220117141507_semver_100.snap | 22 +- .../tests__20220117141507_semver_80.snap | 22 +- ...s__20220117141645_valid_name_type_100.snap | 6 +- ...ts__20220117141645_valid_name_type_80.snap | 6 +- ...0117142104_account_and_org_tables_100.snap | 70 +- ...20117142104_account_and_org_tables_80.snap | 92 +- ...ts__20220117142137_package_tables_100.snap | 83 +- ...sts__20220117142137_package_tables_80.snap | 94 +- ...s__20220117142138_developer_tools_100.snap | 6 +- ...ts__20220117142138_developer_tools_80.snap | 6 +- ...20220117142141_security_utilities_100.snap | 24 +- ..._20220117142141_security_utilities_80.snap | 24 +- ...220117142142_security_definitions_100.snap | 44 +- ...0220117142142_security_definitions_80.snap | 80 +- .../tests__20220117155720_views_100.snap | 28 +- .../multi/tests__20220117155820_rpc_100.snap | 6 +- .../multi/tests__20220117155820_rpc_80.snap | 6 +- ...0230323180034_reserved_user_accts_100.snap | 17 +- ...20230323180034_reserved_user_accts_80.snap | 17 +- ..._20230328185043_olirice_asciiplot_100.snap | 51 +- ...__20230328185043_olirice_asciiplot_80.snap | 27 +- ...ts__20230330155137_supabase_dbdev_100.snap | 28 +- ...sts__20230330155137_supabase_dbdev_80.snap | 9 +- ...30331145934_burggraf-pg_headerkit_100.snap | 19 +- ...230331145934_burggraf-pg_headerkit_80.snap | 9 +- ...30331163908_olirice-index_advisor_100.snap | 28 +- ...230331163908_olirice-index_advisor_80.snap | 9 +- ..._20230331163909_olirice-read_once_100.snap | 28 +- ...__20230331163909_olirice-read_once_80.snap | 9 +- ..._20230404162614_michelp-adminpack_100.snap | 19 +- ...__20230404162614_michelp-adminpack_80.snap | 9 +- ...0405083103_fix_auth_schema_values_100.snap | 9 +- ...30405083103_fix_auth_schema_values_80.snap | 12 +- ...20230405085810_fix_avatars_handle_100.snap | 9 +- ..._20230405085810_fix_avatars_handle_80.snap | 9 +- ...__20230405163940_download_metrics_100.snap | 72 +- ...s__20230405163940_download_metrics_80.snap | 75 +- ...ownload_metrics_computed_relation_100.snap | 6 +- ...download_metrics_computed_relation_80.snap | 6 +- ...175952_langchain-embedding_search_100.snap | 27 +- ...1175952_langchain-embedding_search_80.snap | 3 +- ...411175953_langchain-hybrid_search_100.snap | 25 +- ...0411175953_langchain-hybrid_search_80.snap | 7 +- ...3130634_popular_packages_function_100.snap | 6 +- ...13130634_popular_packages_function_80.snap | 6 +- ...413140356_update_profile_function_100.snap | 6 +- ...0413140356_update_profile_function_80.snap | 6 +- ...230417141004_dbdev_short_desc_typo_80.snap | 3 +- ..._langchain-embedding_search-1_1_0_100.snap | 18 +- ...2_langchain-embedding_search-1_1_0_80.snap | 3 +- ...953_langchain-hybrid_search-1_1_0_100.snap | 19 +- ...5953_langchain-hybrid_search-1_1_0_80.snap | 7 +- ...9_langchain_headerkit_config_dump_100.snap | 58 +- ...39_langchain_headerkit_config_dump_80.snap | 15 +- ..._dbdev_supports_multiple_versions_100.snap | 19 +- ...2_dbdev_supports_multiple_versions_80.snap | 9 +- ...83255_olirice-index_advisor-0_2_0_100.snap | 19 +- ...083255_olirice-index_advisor-0_2_0_80.snap | 9 +- ...ests__20230906110845_access_token_100.snap | 50 +- ...tests__20230906110845_access_token_80.snap | 55 +- ...s__20230906111353_publish_package_100.snap | 16 +- ...ts__20230906111353_publish_package_80.snap | 23 +- ...blishing_relocatable_and_requires_100.snap | 16 +- ...ublishing_relocatable_and_requires_80.snap | 22 +- ...0231205051816_add_default_version_100.snap | 33 +- ...20231205051816_add_default_version_80.snap | 40 +- ...09_dbdev_supports_default_version_100.snap | 19 +- ...809_dbdev_supports_default_version_80.snap | 9 +- ...__20231207071422_new_package_name_100.snap | 22 +- ...s__20231207071422_new_package_name_80.snap | 12 +- ..._dbdev_supports_new_package_names_100.snap | 19 +- ...8_dbdev_supports_new_package_names_80.snap | 9 +- ..._langchain@embedding_search-1.1.1_100.snap | 18 +- ...3_langchain@embedding_search-1.1.1_80.snap | 3 +- ...129_langchain@hybrid_search-1.1.1_100.snap | 19 +- ...2129_langchain@hybrid_search-1.1.1_80.snap | 3 +- ...207112942_michelp@adminpack-0.0.2_100.snap | 19 +- ...1207112942_michelp@adminpack-0.0.2_80.snap | 9 +- ...13329_olirice@index_advisor-0.2.1_100.snap | 19 +- ...113329_olirice@index_advisor-0.2.1_80.snap | 9 +- ...207113857_olirice@read_once-0.3.2_100.snap | 19 +- ...1207113857_olirice@read_once-0.3.2_80.snap | 9 +- ...240705083738_remove_contact_email_100.snap | 10 +- ...50106073735_jwt_secret_from_vault_100.snap | 4 +- ...250106073735_jwt_secret_from_vault_80.snap | 4 +- ...100252_restrict_accounts_and_orgs_100.snap | 20 +- ...7100252_restrict_accounts_and_orgs_80.snap | 25 +- ...emove_dbdev_from_popular_packages_100.snap | 6 +- ...remove_dbdev_from_popular_packages_80.snap | 6 +- .../multi/tests__advisory_lock_100.snap | 14 +- .../multi/tests__advisory_lock_80.snap | 59 +- .../multi/tests__aggregates_100.snap | 1317 +++------ .../snapshots/multi/tests__aggregates_80.snap | 1547 +++------- .../multi/tests__alter_generic_100.snap | 252 +- .../multi/tests__alter_generic_80.snap | 244 +- .../multi/tests__alter_operator_100.snap | 159 +- .../multi/tests__alter_operator_80.snap | 209 +- .../multi/tests__alter_table_100.snap | 357 +-- .../multi/tests__alter_table_80.snap | 349 +-- .../snapshots/multi/tests__amutils_100.snap | 129 +- .../snapshots/multi/tests__amutils_80.snap | 142 +- .../snapshots/multi/tests__arrays_100.snap | 330 +-- .../snapshots/multi/tests__arrays_80.snap | 582 +--- .../snapshots/multi/tests__async_100.snap | 7 +- .../snapshots/multi/tests__async_80.snap | 2 +- .../tests/snapshots/multi/tests__bit_100.snap | 132 +- .../tests/snapshots/multi/tests__bit_80.snap | 151 +- .../snapshots/multi/tests__bitmapops_100.snap | 12 +- .../snapshots/multi/tests__bitmapops_80.snap | 12 +- .../snapshots/multi/tests__boolean_100.snap | 114 +- .../snapshots/multi/tests__boolean_80.snap | 128 +- .../tests/snapshots/multi/tests__box_100.snap | 64 +- .../tests/snapshots/multi/tests__box_80.snap | 145 +- .../snapshots/multi/tests__brin_100.snap | 249 +- .../tests/snapshots/multi/tests__brin_80.snap | 245 +- .../multi/tests__brin_bloom_100.snap | 256 +- .../snapshots/multi/tests__brin_bloom_80.snap | 324 +- .../multi/tests__brin_multi_100.snap | 450 +-- .../snapshots/multi/tests__brin_multi_80.snap | 437 +-- .../multi/tests__btree_index_100.snap | 97 +- .../multi/tests__btree_index_80.snap | 150 +- .../snapshots/multi/tests__case_100.snap | 33 +- .../tests/snapshots/multi/tests__case_80.snap | 64 +- .../tests/snapshots/multi/tests__char_80.snap | 4 +- .../snapshots/multi/tests__cluster_100.snap | 81 +- .../snapshots/multi/tests__cluster_80.snap | 111 +- .../multi/tests__collate.icu.utf8_100.snap | 370 +-- .../multi/tests__collate.icu.utf8_80.snap | 476 +-- .../multi/tests__collate.linux.utf8_100.snap | 103 +- .../multi/tests__collate.linux.utf8_80.snap | 190 +- .../multi/tests__collate.utf8_100.snap | 22 +- .../multi/tests__collate.utf8_80.snap | 18 +- .../snapshots/multi/tests__collate_100.snap | 85 +- .../snapshots/multi/tests__collate_80.snap | 168 +- .../snapshots/multi/tests__combocid_100.snap | 2 +- .../snapshots/multi/tests__combocid_80.snap | 2 +- .../multi/tests__compression_100.snap | 13 +- .../multi/tests__compression_80.snap | 13 +- .../multi/tests__compression_lz4_100.snap | 29 +- .../multi/tests__compression_lz4_80.snap | 25 +- .../multi/tests__constraints_100.snap | 23 +- .../multi/tests__constraints_80.snap | 20 +- .../multi/tests__conversion_100.snap | 128 +- .../snapshots/multi/tests__conversion_80.snap | 307 +- .../snapshots/multi/tests__copy2_100.snap | 16 +- .../snapshots/multi/tests__copy2_80.snap | 16 +- .../snapshots/multi/tests__copy_100.snap | 64 +- .../tests/snapshots/multi/tests__copy_80.snap | 90 +- .../snapshots/multi/tests__copydml_100.snap | 6 +- .../snapshots/multi/tests__copydml_80.snap | 6 +- .../multi/tests__copyselect_100.snap | 15 +- .../snapshots/multi/tests__copyselect_80.snap | 14 +- .../multi/tests__create_aggregate_100.snap | 118 +- .../multi/tests__create_aggregate_80.snap | 130 +- .../snapshots/multi/tests__create_am_100.snap | 171 +- .../snapshots/multi/tests__create_am_80.snap | 246 +- .../multi/tests__create_cast_100.snap | 59 +- .../multi/tests__create_cast_80.snap | 67 +- .../multi/tests__create_function_c_100.snap | 8 +- .../multi/tests__create_function_c_80.snap | 8 +- .../multi/tests__create_function_sql_100.snap | 267 +- .../multi/tests__create_function_sql_80.snap | 280 +- .../multi/tests__create_index_100.snap | 931 ++---- .../multi/tests__create_index_80.snap | 1282 +++----- .../multi/tests__create_index_spgist_100.snap | 403 ++- .../multi/tests__create_index_spgist_80.snap | 465 ++- .../multi/tests__create_misc_100.snap | 166 +- .../multi/tests__create_misc_80.snap | 164 +- .../multi/tests__create_operator_100.snap | 176 +- .../multi/tests__create_operator_80.snap | 230 +- .../multi/tests__create_procedure_100.snap | 110 +- .../multi/tests__create_procedure_80.snap | 115 +- .../multi/tests__create_role_100.snap | 24 +- .../multi/tests__create_role_80.snap | 24 +- .../multi/tests__create_schema_100.snap | 12 +- .../multi/tests__create_schema_80.snap | 12 +- .../multi/tests__create_table_100.snap | 235 +- .../multi/tests__create_table_80.snap | 286 +- .../multi/tests__create_table_like_100.snap | 88 +- .../multi/tests__create_table_like_80.snap | 129 +- .../multi/tests__create_type_100.snap | 129 +- .../multi/tests__create_type_80.snap | 133 +- .../multi/tests__create_view_100.snap | 653 +--- .../multi/tests__create_view_80.snap | 696 +---- .../snapshots/multi/tests__database_100.snap | 7 +- .../snapshots/multi/tests__database_80.snap | 2 +- .../snapshots/multi/tests__date_100.snap | 140 +- .../tests/snapshots/multi/tests__date_80.snap | 143 +- .../snapshots/multi/tests__dbsize_100.snap | 18 +- .../snapshots/multi/tests__dbsize_80.snap | 8 +- .../multi/tests__dependency_100.snap | 40 +- .../snapshots/multi/tests__dependency_80.snap | 44 +- .../snapshots/multi/tests__domain_100.snap | 169 +- .../snapshots/multi/tests__domain_80.snap | 200 +- .../multi/tests__drop_if_exists_100.snap | 31 +- .../multi/tests__drop_if_exists_80.snap | 36 +- .../multi/tests__drop_operator_100.snap | 70 +- .../multi/tests__drop_operator_80.snap | 64 +- .../snapshots/multi/tests__enum_100.snap | 34 +- .../tests/snapshots/multi/tests__enum_80.snap | 58 +- .../multi/tests__equivclass_100.snap | 272 +- .../snapshots/multi/tests__equivclass_80.snap | 266 +- .../snapshots/multi/tests__errors_100.snap | 32 +- .../snapshots/multi/tests__errors_80.snap | 32 +- .../multi/tests__event_trigger_100.snap | 263 +- .../multi/tests__event_trigger_80.snap | 267 +- .../multi/tests__event_trigger_login_100.snap | 12 +- .../multi/tests__event_trigger_login_80.snap | 14 +- .../snapshots/multi/tests__explain_100.snap | 61 +- .../snapshots/multi/tests__explain_80.snap | 50 +- .../multi/tests__expressions_100.snap | 97 +- .../multi/tests__expressions_80.snap | 122 +- .../multi/tests__fast_default_100.snap | 105 +- .../multi/tests__fast_default_80.snap | 132 +- .../snapshots/multi/tests__float4_100.snap | 139 +- .../snapshots/multi/tests__float4_80.snap | 131 +- .../snapshots/multi/tests__float8_100.snap | 352 +-- .../snapshots/multi/tests__float8_80.snap | 373 +-- .../multi/tests__foreign_data_100.snap | 251 +- .../multi/tests__foreign_data_80.snap | 325 +- .../multi/tests__foreign_key_100.snap | 937 ++---- .../multi/tests__foreign_key_80.snap | 1166 +++----- .../multi/tests__functional_deps_100.snap | 101 +- .../multi/tests__functional_deps_80.snap | 120 +- .../multi/tests__generated_stored_100.snap | 145 +- .../multi/tests__generated_stored_80.snap | 226 +- .../multi/tests__generated_virtual_100.snap | 129 +- .../multi/tests__generated_virtual_80.snap | 144 +- .../snapshots/multi/tests__geometry_100.snap | 4 +- .../snapshots/multi/tests__geometry_80.snap | 23 +- .../tests/snapshots/multi/tests__gin_100.snap | 88 +- .../tests/snapshots/multi/tests__gin_80.snap | 112 +- .../snapshots/multi/tests__gist_100.snap | 128 +- .../tests/snapshots/multi/tests__gist_80.snap | 124 +- .../multi/tests__groupingsets_100.snap | 665 ++--- .../multi/tests__groupingsets_80.snap | 900 ++---- .../tests/snapshots/multi/tests__guc_100.snap | 158 +- .../tests/snapshots/multi/tests__guc_80.snap | 158 +- .../snapshots/multi/tests__hash_func_100.snap | 500 +--- .../snapshots/multi/tests__hash_func_80.snap | 653 ++-- .../multi/tests__hash_index_100.snap | 96 +- .../snapshots/multi/tests__hash_index_80.snap | 118 +- .../snapshots/multi/tests__hash_part_100.snap | 52 +- .../snapshots/multi/tests__hash_part_80.snap | 23 +- .../snapshots/multi/tests__horology_100.snap | 401 +-- .../snapshots/multi/tests__horology_80.snap | 548 +--- .../snapshots/multi/tests__identity_100.snap | 6 +- .../snapshots/multi/tests__identity_80.snap | 17 +- .../multi/tests__incremental_sort_100.snap | 107 +- .../multi/tests__incremental_sort_80.snap | 143 +- .../multi/tests__index_including_100.snap | 124 +- .../multi/tests__index_including_80.snap | 305 +- .../tests__index_including_gist_100.snap | 32 +- .../multi/tests__index_including_gist_80.snap | 82 +- .../snapshots/multi/tests__indexing_100.snap | 318 +- .../snapshots/multi/tests__indexing_80.snap | 456 +-- .../multi/tests__indirect_toast_100.snap | 102 +- .../multi/tests__indirect_toast_80.snap | 90 +- .../snapshots/multi/tests__inet_100.snap | 157 +- .../tests/snapshots/multi/tests__inet_80.snap | 198 +- .../multi/tests__infinite_recurse_100.snap | 4 +- .../multi/tests__infinite_recurse_80.snap | 4 +- .../snapshots/multi/tests__inherit_100.snap | 586 ++-- .../snapshots/multi/tests__inherit_80.snap | 691 ++--- .../multi/tests__init_privs_100.snap | 8 +- .../snapshots/multi/tests__init_privs_80.snap | 8 +- .../snapshots/multi/tests__insert_100.snap | 184 +- .../snapshots/multi/tests__insert_80.snap | 228 +- .../multi/tests__insert_conflict_100.snap | 595 +--- .../multi/tests__insert_conflict_80.snap | 685 +---- .../snapshots/multi/tests__int2_100.snap | 130 +- .../tests/snapshots/multi/tests__int2_80.snap | 144 +- .../snapshots/multi/tests__int4_100.snap | 197 +- .../tests/snapshots/multi/tests__int4_80.snap | 209 +- .../snapshots/multi/tests__int8_100.snap | 320 +- .../tests/snapshots/multi/tests__int8_80.snap | 341 +-- .../snapshots/multi/tests__interval_100.snap | 356 +-- .../snapshots/multi/tests__interval_80.snap | 480 +-- .../snapshots/multi/tests__join_100.snap | 749 +---- .../tests/snapshots/multi/tests__join_80.snap | 1045 ++----- .../snapshots/multi/tests__join_hash_100.snap | 393 +-- .../snapshots/multi/tests__join_hash_80.snap | 438 +-- .../snapshots/multi/tests__json_100.snap | 377 +-- .../tests/snapshots/multi/tests__json_80.snap | 587 +--- .../multi/tests__json_encoding_100.snap | 7 +- .../multi/tests__json_encoding_80.snap | 56 +- .../snapshots/multi/tests__jsonb_100.snap | 732 ++--- .../snapshots/multi/tests__jsonb_80.snap | 1182 +++----- .../multi/tests__jsonb_jsonpath_100.snap | 308 +- .../multi/tests__jsonb_jsonpath_80.snap | 427 +-- .../snapshots/multi/tests__jsonpath_100.snap | 6 +- .../snapshots/multi/tests__jsonpath_80.snap | 12 +- .../multi/tests__largeobject_100.snap | 33 +- .../multi/tests__largeobject_80.snap | 53 +- .../snapshots/multi/tests__limit_100.snap | 8 +- .../snapshots/multi/tests__limit_80.snap | 18 +- .../snapshots/multi/tests__line_100.snap | 8 +- .../tests/snapshots/multi/tests__line_80.snap | 24 +- .../snapshots/multi/tests__lock_100.snap | 130 +- .../tests/snapshots/multi/tests__lock_80.snap | 135 +- .../snapshots/multi/tests__macaddr8_100.snap | 4 +- .../snapshots/multi/tests__macaddr8_80.snap | 10 +- .../snapshots/multi/tests__macaddr_100.snap | 4 +- .../snapshots/multi/tests__macaddr_80.snap | 4 +- .../multi/tests__maintain_every_80.snap | 6 +- .../snapshots/multi/tests__matview_100.snap | 44 +- .../snapshots/multi/tests__matview_80.snap | 66 +- .../tests/snapshots/multi/tests__md5_100.snap | 17 +- .../tests/snapshots/multi/tests__md5_80.snap | 15 +- .../snapshots/multi/tests__memoize_100.snap | 233 +- .../snapshots/multi/tests__memoize_80.snap | 256 +- .../snapshots/multi/tests__merge_100.snap | 256 +- .../snapshots/multi/tests__merge_80.snap | 257 +- .../snapshots/multi/tests__misc_100.snap | 104 +- .../tests/snapshots/multi/tests__misc_80.snap | 96 +- .../multi/tests__misc_functions_100.snap | 299 +- .../multi/tests__misc_functions_80.snap | 291 +- .../multi/tests__misc_sanity_100.snap | 20 +- .../multi/tests__misc_sanity_80.snap | 41 +- .../snapshots/multi/tests__money_100.snap | 50 +- .../snapshots/multi/tests__money_80.snap | 50 +- .../multi/tests__multirangetypes_100.snap | 495 +--- .../multi/tests__multirangetypes_80.snap | 748 ++--- .../snapshots/multi/tests__mvcc_100.snap | 14 +- .../tests/snapshots/multi/tests__mvcc_80.snap | 26 +- .../snapshots/multi/tests__name_100.snap | 46 +- .../tests/snapshots/multi/tests__name_80.snap | 47 +- .../snapshots/multi/tests__namespace_100.snap | 72 +- .../snapshots/multi/tests__namespace_80.snap | 70 +- .../snapshots/multi/tests__numa_100.snap | 4 +- .../tests/snapshots/multi/tests__numa_80.snap | 4 +- .../snapshots/multi/tests__numeric_100.snap | 520 +--- .../snapshots/multi/tests__numeric_80.snap | 567 +--- .../multi/tests__numeric_big_100.snap | 921 ++---- .../multi/tests__numeric_big_80.snap | 1584 +++------- .../multi/tests__numerology_100.snap | 41 +- .../snapshots/multi/tests__numerology_80.snap | 63 +- .../multi/tests__object_address_100.snap | 226 +- .../multi/tests__object_address_80.snap | 416 +-- .../snapshots/multi/tests__oidjoins_100.snap | 5 +- .../snapshots/multi/tests__oidjoins_80.snap | 5 +- .../multi/tests__opr_sanity_100.snap | 486 +-- .../snapshots/multi/tests__opr_sanity_80.snap | 708 +---- .../multi/tests__ordered_set_filter_100.snap | 21 +- .../multi/tests__ordered_set_filter_80.snap | 11 +- .../multi/tests__partition_aggregate_100.snap | 341 +-- .../multi/tests__partition_aggregate_80.snap | 510 ++-- .../multi/tests__partition_info_100.snap | 60 +- .../multi/tests__partition_info_80.snap | 39 +- .../multi/tests__partition_join_100.snap | 1532 ++-------- .../multi/tests__partition_join_80.snap | 1843 +++--------- .../multi/tests__partition_prune_100.snap | 436 +-- .../multi/tests__partition_prune_80.snap | 696 ++--- .../snapshots/multi/tests__password_100.snap | 3 +- .../snapshots/multi/tests__password_80.snap | 3 +- .../snapshots/multi/tests__pg_lsn_100.snap | 5 +- .../snapshots/multi/tests__pg_lsn_80.snap | 8 +- .../snapshots/multi/tests__plancache_100.snap | 35 +- .../snapshots/multi/tests__plancache_80.snap | 37 +- .../snapshots/multi/tests__plpgsql_100.snap | 1517 +++++----- .../snapshots/multi/tests__plpgsql_80.snap | 1584 +++++----- .../snapshots/multi/tests__point_100.snap | 26 +- .../snapshots/multi/tests__point_80.snap | 41 +- .../snapshots/multi/tests__polygon_100.snap | 158 +- .../snapshots/multi/tests__polygon_80.snap | 183 +- .../multi/tests__polymorphism_100.snap | 631 ++-- .../multi/tests__polymorphism_80.snap | 706 ++--- .../snapshots/multi/tests__portals_100.snap | 50 +- .../snapshots/multi/tests__portals_80.snap | 50 +- .../multi/tests__portals_p2_100.snap | 26 +- .../snapshots/multi/tests__portals_p2_80.snap | 26 +- .../snapshots/multi/tests__predicate_100.snap | 44 +- .../snapshots/multi/tests__predicate_80.snap | 54 +- .../snapshots/multi/tests__prepare_100.snap | 36 +- .../snapshots/multi/tests__prepare_80.snap | 60 +- .../multi/tests__prepared_xacts_100.snap | 6 +- .../multi/tests__prepared_xacts_80.snap | 6 +- .../multi/tests__privileges_100.snap | 1063 +++---- .../snapshots/multi/tests__privileges_80.snap | 1381 +++------ .../multi/tests__publication_100.snap | 171 +- .../multi/tests__publication_80.snap | 307 +- .../snapshots/multi/tests__random_100.snap | 298 +- .../snapshots/multi/tests__random_80.snap | 346 +-- .../multi/tests__rangefuncs_100.snap | 619 +--- .../snapshots/multi/tests__rangefuncs_80.snap | 713 ++--- .../multi/tests__rangetypes_100.snap | 475 +-- .../snapshots/multi/tests__rangetypes_80.snap | 529 ++-- .../snapshots/multi/tests__regex_100.snap | 6 +- .../snapshots/multi/tests__regex_80.snap | 12 +- .../snapshots/multi/tests__regproc_80.snap | 6 +- .../multi/tests__reloptions_100.snap | 94 +- .../snapshots/multi/tests__reloptions_80.snap | 92 +- .../multi/tests__replica_identity_100.snap | 122 +- .../multi/tests__replica_identity_80.snap | 200 +- .../tests__reserved_keyword_idents_100.snap | 17 +- .../tests__reserved_keyword_idents_80.snap | 17 +- .../snapshots/multi/tests__returning_100.snap | 178 +- .../snapshots/multi/tests__returning_80.snap | 197 +- .../multi/tests__rowsecurity_100.snap | 378 +-- .../multi/tests__rowsecurity_80.snap | 685 +---- .../snapshots/multi/tests__rowtypes_100.snap | 176 +- .../snapshots/multi/tests__rowtypes_80.snap | 214 +- .../snapshots/multi/tests__rules_100.snap | 129 +- .../snapshots/multi/tests__rules_80.snap | 139 +- .../multi/tests__sanity_check_100.snap | 14 +- .../multi/tests__sanity_check_80.snap | 8 +- .../multi/tests__security_label_100.snap | 4 +- .../multi/tests__security_label_80.snap | 4 +- .../snapshots/multi/tests__select_100.snap | 35 +- .../snapshots/multi/tests__select_80.snap | 59 +- .../multi/tests__select_distinct_100.snap | 48 +- .../multi/tests__select_distinct_80.snap | 64 +- .../multi/tests__select_distinct_on_100.snap | 12 +- .../multi/tests__select_distinct_on_80.snap | 41 +- .../multi/tests__select_having_100.snap | 14 +- .../multi/tests__select_having_80.snap | 16 +- .../multi/tests__select_implicit_100.snap | 46 +- .../multi/tests__select_implicit_80.snap | 46 +- .../multi/tests__select_into_100.snap | 20 +- .../multi/tests__select_into_80.snap | 28 +- .../multi/tests__select_parallel_100.snap | 400 +-- .../multi/tests__select_parallel_80.snap | 425 +-- .../multi/tests__select_views_100.snap | 80 +- .../multi/tests__select_views_80.snap | 91 +- .../snapshots/multi/tests__sequence_100.snap | 18 +- .../snapshots/multi/tests__sequence_80.snap | 3 +- .../snapshots/multi/tests__spgist_100.snap | 102 +- .../snapshots/multi/tests__spgist_80.snap | 80 +- .../snapshots/multi/tests__sqljson_100.snap | 256 +- .../snapshots/multi/tests__sqljson_80.snap | 319 +- .../multi/tests__sqljson_jsontable_100.snap | 305 +- .../multi/tests__sqljson_jsontable_80.snap | 235 +- .../multi/tests__sqljson_queryfuncs_100.snap | 360 +-- .../multi/tests__sqljson_queryfuncs_80.snap | 451 +-- .../snapshots/multi/tests__stats_100.snap | 290 +- .../snapshots/multi/tests__stats_80.snap | 491 ++-- .../snapshots/multi/tests__stats_ext_100.snap | 672 ++--- .../snapshots/multi/tests__stats_ext_80.snap | 925 ++---- .../multi/tests__stats_import_100.snap | 331 +-- .../multi/tests__stats_import_80.snap | 290 +- .../snapshots/multi/tests__strings_100.snap | 342 +-- .../snapshots/multi/tests__strings_80.snap | 378 +-- .../multi/tests__subscription_100.snap | 220 +- .../multi/tests__subscription_80.snap | 230 +- .../snapshots/multi/tests__subselect_100.snap | 784 +---- .../snapshots/multi/tests__subselect_80.snap | 1041 ++----- .../snapshots/multi/tests__sysviews_100.snap | 66 +- .../snapshots/multi/tests__sysviews_80.snap | 76 +- .../multi/tests__tablesample_100.snap | 90 +- .../multi/tests__tablesample_80.snap | 106 +- .../multi/tests__tablespace_100.snap | 219 +- .../snapshots/multi/tests__tablespace_80.snap | 297 +- .../snapshots/multi/tests__temp_100.snap | 52 +- .../tests/snapshots/multi/tests__temp_80.snap | 93 +- .../multi/tests__test_setup_100.snap | 157 +- .../snapshots/multi/tests__test_setup_80.snap | 165 +- .../tests/snapshots/multi/tests__text_80.snap | 11 +- .../tests/snapshots/multi/tests__tid_100.snap | 6 +- .../tests/snapshots/multi/tests__tid_80.snap | 9 +- .../multi/tests__tidrangescan_100.snap | 41 +- .../multi/tests__tidrangescan_80.snap | 50 +- .../snapshots/multi/tests__tidscan_100.snap | 46 +- .../snapshots/multi/tests__tidscan_80.snap | 41 +- .../snapshots/multi/tests__time_100.snap | 18 +- .../tests/snapshots/multi/tests__time_80.snap | 18 +- .../snapshots/multi/tests__timestamp_100.snap | 112 +- .../snapshots/multi/tests__timestamp_80.snap | 193 +- .../multi/tests__timestamptz_100.snap | 648 ++-- .../multi/tests__timestamptz_80.snap | 977 ++---- .../snapshots/multi/tests__timetz_100.snap | 56 +- .../snapshots/multi/tests__timetz_80.snap | 68 +- .../multi/tests__transactions_100.snap | 192 +- .../multi/tests__transactions_80.snap | 201 +- .../snapshots/multi/tests__triggers_100.snap | 613 ++-- .../snapshots/multi/tests__triggers_80.snap | 685 ++--- .../snapshots/multi/tests__truncate_100.snap | 42 +- .../snapshots/multi/tests__truncate_80.snap | 43 +- .../snapshots/multi/tests__tsearch_100.snap | 683 ++--- .../snapshots/multi/tests__tsearch_80.snap | 822 ++---- .../snapshots/multi/tests__tsrf_100.snap | 116 +- .../tests/snapshots/multi/tests__tsrf_80.snap | 151 +- .../snapshots/multi/tests__tstypes_100.snap | 60 +- .../snapshots/multi/tests__tstypes_80.snap | 99 +- .../snapshots/multi/tests__tuplesort_100.snap | 165 +- .../snapshots/multi/tests__tuplesort_80.snap | 160 +- .../snapshots/multi/tests__txid_100.snap | 4 +- .../tests/snapshots/multi/tests__txid_80.snap | 7 +- .../multi/tests__type_sanity_100.snap | 309 +- .../multi/tests__type_sanity_80.snap | 387 +-- .../multi/tests__typed_table_100.snap | 10 +- .../multi/tests__typed_table_80.snap | 10 +- .../snapshots/multi/tests__unicode_100.snap | 36 +- .../snapshots/multi/tests__unicode_80.snap | 33 +- .../snapshots/multi/tests__union_100.snap | 359 +-- .../snapshots/multi/tests__union_80.snap | 529 +--- .../multi/tests__updatable_views_100.snap | 465 +-- .../multi/tests__updatable_views_80.snap | 635 +--- .../snapshots/multi/tests__update_100.snap | 201 +- .../snapshots/multi/tests__update_80.snap | 228 +- .../multi/tests__update_multi_assign_100.snap | 11 +- .../multi/tests__update_multi_assign_80.snap | 11 +- .../snapshots/multi/tests__uuid_100.snap | 76 +- .../tests/snapshots/multi/tests__uuid_80.snap | 125 +- .../snapshots/multi/tests__vacuum_100.snap | 293 +- .../snapshots/multi/tests__vacuum_80.snap | 297 +- .../multi/tests__vacuum_parallel_100.snap | 28 +- .../multi/tests__vacuum_parallel_80.snap | 33 +- .../snapshots/multi/tests__window_100.snap | 2618 ++++------------- .../snapshots/multi/tests__window_80.snap | 2076 ++++--------- .../snapshots/multi/tests__with_100.snap | 219 +- .../tests/snapshots/multi/tests__with_80.snap | 242 +- .../multi/tests__without_overlaps_100.snap | 1757 +++-------- .../multi/tests__without_overlaps_80.snap | 2128 +++----------- .../multi/tests__write_parallel_100.snap | 12 +- .../multi/tests__write_parallel_80.snap | 30 +- .../tests/snapshots/multi/tests__xid_100.snap | 16 +- .../tests/snapshots/multi/tests__xid_80.snap | 23 +- .../tests/snapshots/multi/tests__xml_100.snap | 208 +- .../tests/snapshots/multi/tests__xml_80.snap | 243 +- .../snapshots/multi/tests__xmlmap_100.snap | 8 +- .../snapshots/multi/tests__xmlmap_80.snap | 15 +- .../single/tests__a_indirection_0_100.snap | 3 +- .../single/tests__a_indirection_0_80.snap | 3 +- .../single/tests__a_indirection_2_100.snap | 10 +- .../single/tests__a_indirection_2_80.snap | 11 +- ...s__aexpr_precedence_parentheses_0_100.snap | 11 +- ...ts__aexpr_precedence_parentheses_0_80.snap | 13 +- .../snapshots/single/tests__aggref_0_100.snap | 2 +- .../snapshots/single/tests__aggref_0_80.snap | 2 +- ...__alter_default_privileges_stmt_0_100.snap | 2 +- ...s__alter_default_privileges_stmt_0_80.snap | 2 +- .../tests__alter_function_stmt_1_100.snap | 2 +- .../tests__alter_function_stmt_1_80.snap | 2 +- .../tests__alter_function_stmt_2_100.snap | 2 +- .../tests__alter_function_stmt_2_80.snap | 2 +- .../tests__alter_op_family_stmt_0_100.snap | 2 +- .../tests__alter_op_family_stmt_0_80.snap | 2 +- .../tests__alter_operator_stmt_0_100.snap | 2 +- .../tests__alter_operator_stmt_0_80.snap | 2 +- .../single/tests__alter_table_stmt_3_100.snap | 6 +- .../tests__bool_expr_parentheses_0_100.snap | 8 +- .../tests__boolean_test_bool_expr_100.snap | 8 +- .../tests__boolean_test_bool_expr_80.snap | 8 +- .../tests__cast_operator_style_100.snap | 2 +- .../single/tests__cast_operator_style_80.snap | 2 +- .../single/tests__char_type_names_0_100.snap | 2 +- .../single/tests__char_type_names_0_80.snap | 2 +- .../single/tests__coalesce_expr_1_200.snap | 7 +- .../tests__compact_clause_condition_80.snap | 3 +- .../single/tests__compact_from_clause_80.snap | 6 +- .../single/tests__complex_select_0_100.snap | 66 +- .../single/tests__complex_select_0_80.snap | 74 +- .../tests__complex_select_part_0_100.snap | 14 +- .../tests__complex_select_part_0_80.snap | 8 +- .../tests__complex_select_part_1_100.snap | 5 +- .../tests__complex_select_part_1_80.snap | 5 +- .../tests__complex_select_part_3_100.snap | 5 +- .../tests__complex_select_part_3_80.snap | 5 +- .../tests__complex_select_part_4_80.snap | 9 +- .../tests__complex_select_part_5_100.snap | 12 +- .../tests__complex_select_part_5_80.snap | 12 +- .../tests__complex_select_part_6_100.snap | 6 +- .../tests__complex_select_part_6_80.snap | 3 +- .../tests__complex_select_part_7_100.snap | 18 +- .../tests__complex_select_part_7_80.snap | 14 +- .../single/tests__constraint_0_100.snap | 2 +- .../single/tests__constraint_0_80.snap | 3 +- .../single/tests__copy_stmt_0_100.snap | 2 +- .../single/tests__copy_stmt_0_80.snap | 2 +- .../tests__create_event_trig_stmt_0_100.snap | 2 +- .../tests__create_event_trig_stmt_0_80.snap | 2 +- .../tests__create_function_stmt_0_100.snap | 4 +- .../tests__create_function_stmt_0_80.snap | 4 +- .../tests__create_function_stmt_2_100.snap | 4 +- .../tests__create_function_stmt_2_80.snap | 4 +- .../tests__create_op_class_stmt_0_100.snap | 2 +- .../tests__create_op_class_stmt_0_80.snap | 2 +- .../tests__create_range_stmt_0_100.snap | 2 +- .../single/tests__create_range_stmt_0_80.snap | 5 +- .../tests__create_schema_stmt_0_100.snap | 2 +- .../tests__create_schema_stmt_0_80.snap | 2 +- .../tests__create_stats_stmt_0_100.snap | 2 +- .../single/tests__create_stats_stmt_0_80.snap | 2 +- .../tests__create_stmt_cast_check_0_100.snap | 9 +- .../tests__create_stmt_cast_check_0_80.snap | 7 +- .../tests__create_table_as_with_cte_80.snap | 7 +- .../single/tests__createdb_stmt_0_100.snap | 2 +- .../single/tests__createdb_stmt_0_80.snap | 2 +- .../tests__declare_cursor_stmt_0_100.snap | 2 +- .../tests__declare_cursor_stmt_0_80.snap | 2 +- ...ests__delete_with_cte_returning_0_100.snap | 11 +- ...tests__delete_with_cte_returning_0_80.snap | 8 +- .../single/tests__do_stmt_0_100.snap | 6 +- .../snapshots/single/tests__do_stmt_0_80.snap | 6 +- .../tests__dollar_quoted_function_0_100.snap | 4 +- .../tests__dollar_quoted_function_0_80.snap | 4 +- ...__func_call_within_group_filter_0_100.snap | 7 +- ..._function_argument_groups_default_100.snap | 4 +- ...__function_argument_groups_default_80.snap | 5 +- .../single/tests__grant_role_stmt_0_100.snap | 2 +- .../single/tests__grant_role_stmt_0_80.snap | 2 +- .../single/tests__grant_stmt_0_100.snap | 2 +- .../single/tests__grant_stmt_0_80.snap | 2 +- ...ts__index_elem_reserved_keyword_0_100.snap | 9 +- ...sts__index_elem_reserved_keyword_0_80.snap | 14 +- .../single/tests__index_stmt_0_100.snap | 2 +- .../single/tests__index_stmt_0_80.snap | 2 +- ...tests__insert_with_cte_returning_0_80.snap | 3 +- .../single/tests__json_table_nested_0_80.snap | 3 +- .../tests__leading_boolean_operators_80.snap | 3 +- .../single/tests__lock_stmt_0_100.snap | 2 +- .../single/tests__lock_stmt_0_80.snap | 2 +- .../single/tests__merge_action_0_100.snap | 4 +- .../single/tests__merge_action_0_80.snap | 3 +- .../single/tests__merge_stmt_0_100.snap | 4 +- .../single/tests__merge_stmt_0_80.snap | 7 +- .../single/tests__merge_stmt_1_100.snap | 16 +- .../single/tests__merge_stmt_1_80.snap | 7 +- .../tests__merge_stmt_variants_0_100.snap | 8 +- .../tests__merge_stmt_variants_0_80.snap | 11 +- .../tests__merge_support_func_0_100.snap | 4 +- .../tests__merge_support_func_0_80.snap | 7 +- .../single/tests__min_max_expr_1_200.snap | 8 +- .../tests__nested_dollar_quotes_0_100.snap | 4 +- .../tests__nested_dollar_quotes_0_80.snap | 4 +- ...__nested_dollar_quotes_conflict_0_100.snap | 4 +- ...s__nested_dollar_quotes_conflict_0_80.snap | 4 +- .../single/tests__pl_assign_stmt_0_100.snap | 6 +- .../single/tests__pl_assign_stmt_0_80.snap | 6 +- .../single/tests__range_table_func_0_100.snap | 8 +- .../single/tests__return_stmt_0_100.snap | 6 +- .../single/tests__return_stmt_0_80.snap | 6 +- .../single/tests__rule_stmt_0_100.snap | 2 +- .../single/tests__rule_stmt_0_80.snap | 2 +- .../single/tests__table_func_0_100.snap | 3 +- .../single/tests__table_func_0_80.snap | 3 +- ...que_constraint_nulls_not_distinct_100.snap | 3 +- ...ique_constraint_nulls_not_distinct_80.snap | 3 +- .../tests__update_multi_assign_0_100.snap | 2 +- .../tests__update_multi_assign_0_80.snap | 2 +- ...ests__update_with_cte_returning_0_100.snap | 6 +- ...tests__update_with_cte_returning_0_80.snap | 11 +- .../tests__variable_show_stmt_0_100.snap | 2 +- .../tests__variable_show_stmt_0_80.snap | 2 +- .../single/tests__window_def_0_100.snap | 2 +- .../single/tests__window_def_0_80.snap | 2 +- .../single/tests__window_func_0_100.snap | 2 +- .../single/tests__window_func_0_80.snap | 2 +- .../tests__window_function_group_200.snap | 10 +- .../single/tests__xml_serialize_0_100.snap | 2 +- .../single/tests__xml_serialize_0_80.snap | 2 +- .../tests/source_fidelity.rs | 305 ++ crates/pgls_pretty_print/tests/tests.rs | 4 +- .../pgls_pretty_print_codegen/src/keywords.rs | 20 +- .../src/token_kind.rs | 50 +- crates/pgls_workspace/src/workspace/server.rs | 107 +- .../src/workspace/server.tests.rs | 54 + docs/features/formatting.md | 51 +- 750 files changed, 33415 insertions(+), 76775 deletions(-) create mode 100644 crates/pgls_pretty_print/tests/source_fidelity.rs diff --git a/crates/pgls_pretty_print/src/comments.rs b/crates/pgls_pretty_print/src/comments.rs index 9b087ae66..c7e996e90 100644 --- a/crates/pgls_pretty_print/src/comments.rs +++ b/crates/pgls_pretty_print/src/comments.rs @@ -16,6 +16,9 @@ pub struct Comment { /// before a closing parenthesis. They fall back to the previous node for attachment, but must /// still start on their own line rather than being appended to that node. pub own_line: bool, + /// True for a line comment written after a list comma, `a, -- note`. It stays after the comma + /// rather than moving onto the next item's line. + pub after_separator: bool, } /// Comments of a statement, indexed by the node they surround. @@ -70,10 +73,17 @@ pub fn attach_comments(sql: &str, ast: &NodeEnum) -> AttachedComments { continue; } - let leads = !source_comment.comment.line_comment - || line_prefix.trim().is_empty() - || ends_with_clause_header(line_prefix) - || ends_with_structural_separator(line_prefix); + // A line comment ending a line after a comma belongs to the item before the comma. The + // emitter holds it back until that comma is written. + source_comment.comment.after_separator = source_comment.comment.line_comment + && !source_comment.comment.own_line + && line_prefix.trim_end().ends_with(','); + + let leads = !source_comment.comment.after_separator + && (!source_comment.comment.line_comment + || line_prefix.trim().is_empty() + || ends_with_clause_header(line_prefix) + || ends_with_structural_separator(line_prefix)); let next = locations .iter() @@ -207,6 +217,7 @@ fn collect_comments(sql: &str) -> Vec { text, line_comment, own_line: false, + after_separator: false, }, }) }) @@ -313,21 +324,31 @@ mod tests { } #[test] - fn a_comment_after_a_separator_attaches_to_the_node_that_follows_it() { - let sql = "SELECT a, -- temporarily omit b\nb FROM t"; + fn a_line_comment_after_a_comma_stays_with_the_item_before_it() { + let sql = "SELECT a, -- the first column\nb FROM t"; let attached = attach_comments(sql, &parse(sql)); assert!(attached.unattached.is_empty()); - assert_eq!(attached.leading_by_location.len(), 1); - assert!(attached.trailing_by_location.is_empty()); + assert!(attached.leading_by_location.is_empty()); + assert_eq!(attached.trailing_by_location.len(), 1); let comments = attached - .leading_by_location + .trailing_by_location .values() .next() .expect("one entry"); - assert_eq!(comments[0].text, "-- temporarily omit b"); - assert!(comments[0].line_comment); + assert_eq!(comments[0].text, "-- the first column"); + assert!(comments[0].after_separator); + } + + #[test] + fn a_comment_after_an_opening_parenthesis_attaches_to_the_node_that_follows_it() { + let sql = "SELECT f( -- the argument\na) FROM t"; + let attached = attach_comments(sql, &parse(sql)); + + assert!(attached.unattached.is_empty()); + assert_eq!(attached.leading_by_location.len(), 1); + assert!(attached.trailing_by_location.is_empty()); } #[test] diff --git a/crates/pgls_pretty_print/src/emitter.rs b/crates/pgls_pretty_print/src/emitter.rs index c4328f106..223e7aa9a 100644 --- a/crates/pgls_pretty_print/src/emitter.rs +++ b/crates/pgls_pretty_print/src/emitter.rs @@ -54,6 +54,18 @@ pub struct EventEmitter { /// Boolean operands need standalone line comments to start their own line, otherwise a /// comment can join the preceding operand and drift on the next formatting pass. leading_line_comments_require_break: bool, + /// Line comments written after a list comma, waiting for the emitter to reach that comma. + comments_after_separator: Vec, + /// The text the AST was parsed from. The AST drops how a literal was quoted, so this is where + /// a function body gets its dollar-quote tag back from. + source: Option, +} + +#[derive(Debug)] +struct Source { + text: String, + /// Byte ranges of the string literals in `text`, in source order. + string_literals: Vec<(usize, usize)>, } impl EventEmitter { @@ -64,9 +76,46 @@ impl EventEmitter { leading_comments: HashMap::new(), trailing_comments: HashMap::new(), leading_line_comments_require_break: false, + comments_after_separator: Vec::new(), + source: None, } } + /// Attaches the text the AST was parsed from, so that literals keep the quoting they were + /// written with. Without it, a literal is quoted the default way. + pub fn with_source(mut self, sql: &str) -> Self { + let string_literals = pgls_query::scan(sql) + .map(|scan| { + scan.tokens + .iter() + .filter(|token| token.token == pgls_query::protobuf::Token::Sconst as i32) + .filter_map(|token| { + Some(( + usize::try_from(token.start).ok()?, + usize::try_from(token.end).ok()?, + )) + }) + .collect() + }) + .unwrap_or_default(); + self.source = Some(Source { + text: sql.to_string(), + string_literals, + }); + self + } + + /// The source text of the first string literal at or after `location`. + pub fn source_string_literal_from(&self, location: i32) -> Option<&str> { + let source = self.source.as_ref()?; + let location = usize::try_from(location).ok()?; + let index = source + .string_literals + .partition_point(|(start, _)| *start < location); + let (start, end) = *source.string_literals.get(index)?; + source.text.get(start..end) + } + // Later option PRs inspect this while deciding which layout events to emit. #[allow(dead_code)] pub fn config(&self) -> &FormatConfig { @@ -84,11 +133,26 @@ impl EventEmitter { leading_comments, trailing_comments, leading_line_comments_require_break: false, + comments_after_separator: Vec::new(), + source: None, } } pub fn token(&mut self, token: TokenKind) { - self.events.push(LayoutEvent::Token(token)); + // A comment held for a comma follows it. Other tokens closing the item before the comma, + // a parenthesis or an alias for instance, are written first. A statement never ends on a + // comma, so the terminator flushes what is left. + if self.comments_after_separator.is_empty() { + self.events.push(LayoutEvent::Token(token)); + } else if matches!(token, TokenKind::COMMA) { + self.events.push(LayoutEvent::Token(token)); + self.flush_comments_after_separator(); + } else { + if matches!(token, TokenKind::SEMICOLON) { + self.flush_comments_after_separator(); + } + self.events.push(LayoutEvent::Token(token)); + } } pub fn space(&mut self) { @@ -96,6 +160,11 @@ impl EventEmitter { } pub fn line(&mut self, line_type: LineType) { + // With leading commas, the comma follows a line break: the comment ends the item's line. + if matches!(self.config.comma_style, crate::CommaStyle::Leading) { + self.flush_comments_after_separator(); + } + if let Some(LayoutEvent::Line(previous)) = self.events.last_mut() && (matches!(&*previous, LineType::Hard) || matches!(&line_type, LineType::Hard)) { @@ -107,10 +176,22 @@ impl EventEmitter { } pub fn comment(&mut self, text: String, line_comment: bool) { + self.flush_comments_after_separator(); self.events .push(LayoutEvent::Comment { text, line_comment }); } + fn flush_comments_after_separator(&mut self) { + for comment in std::mem::take(&mut self.comments_after_separator) { + self.events.push(LayoutEvent::Space); + self.events.push(LayoutEvent::Comment { + text: comment.text, + line_comment: true, + }); + self.line(LineType::Hard); + } + } + /// Emits and consumes comments that precede `location`, if any. pub fn take_leading_comments_at(&mut self, location: i32) { let Some(comments) = self.leading_comments.remove(&location) else { @@ -167,6 +248,11 @@ impl EventEmitter { }; for comment in comments { + if comment.after_separator { + self.comments_after_separator.push(comment); + continue; + } + let line_comment = comment.line_comment; let multiline = comment.text.contains('\n'); if comment.own_line { @@ -186,6 +272,7 @@ impl EventEmitter { pub fn pending_comments(&self) -> usize { self.leading_comments.values().map(Vec::len).sum::() + self.trailing_comments.values().map(Vec::len).sum::() + + self.comments_after_separator.len() } pub fn with_leading_comment_line_break(&mut self, body: impl FnOnce(&mut EventEmitter)) { diff --git a/crates/pgls_pretty_print/src/lib.rs b/crates/pgls_pretty_print/src/lib.rs index b9f8369e1..6cae330d2 100644 --- a/crates/pgls_pretty_print/src/lib.rs +++ b/crates/pgls_pretty_print/src/lib.rs @@ -216,7 +216,7 @@ pub fn format_statement( || !attached.unattached.is_empty(); if !has_comments { - return format_statement_once(ast, config, attached); + return format_statement_once(ast, sql, config, attached); } let mut current_sql = sql.to_string(); @@ -225,7 +225,7 @@ pub fn format_statement( let mut seen_layouts = HashSet::from([current_sql.clone()]); for pass in 1..=MAX_COMMENT_FORMAT_PASSES { - let result = format_statement_once(¤t_ast, config, attached)?; + let result = format_statement_once(¤t_ast, ¤t_sql, config, attached)?; if result.formatted == current_sql { return Ok(result); } @@ -254,6 +254,7 @@ pub fn format_statement( /// Formats a statement exactly once, including semantic verification. fn format_statement_once( ast: &NodeEnum, + sql: &str, config: &FormatConfig, attached: AttachedComments, ) -> Result { @@ -269,7 +270,8 @@ fn format_statement_once( config.clone(), attached.leading_by_location, attached.trailing_by_location, - ); + ) + .with_source(sql); nodes::emit_node_enum(ast, &mut emitter); let pending = emitter.pending_comments(); if pending > 0 { diff --git a/crates/pgls_pretty_print/src/nodes/access_priv.rs b/crates/pgls_pretty_print/src/nodes/access_priv.rs index afe9d5da7..6dae90d55 100644 --- a/crates/pgls_pretty_print/src/nodes/access_priv.rs +++ b/crates/pgls_pretty_print/src/nodes/access_priv.rs @@ -2,13 +2,23 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; use pgls_query::protobuf::AccessPriv; -use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_access_priv(e: &mut EventEmitter, n: &AccessPriv) { e.group_start(GroupKind::AccessPriv); if !n.priv_name.is_empty() { - e.token(TokenKind::IDENT(n.priv_name.clone().to_uppercase())); + // Privilege names are read case-insensitively, `alter system` being the only one of two + // words, so they follow the keyword case whether or not they are keywords. + for (index, word) in n.priv_name.split(' ').enumerate() { + if index > 0 { + e.space(); + } + match TokenKind::from_keyword(word) { + Some(keyword) => e.token(keyword), + None => e.token(TokenKind::WORD(word.to_string())), + } + } } else { // Empty priv_name means ALL privileges e.token(TokenKind::ALL_KW); @@ -19,9 +29,7 @@ pub(super) fn emit_access_priv(e: &mut EventEmitter, n: &AccessPriv) { // Optional column list for column-level privileges if !n.cols.is_empty() { e.line(LineType::SoftOrSpace); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.cols, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.cols, super::emit_node); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/alias.rs b/crates/pgls_pretty_print/src/nodes/alias.rs index 0718e43a0..e3c336fde 100644 --- a/crates/pgls_pretty_print/src/nodes/alias.rs +++ b/crates/pgls_pretty_print/src/nodes/alias.rs @@ -3,7 +3,7 @@ use pgls_query::protobuf::Alias; use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; -use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_alias(e: &mut EventEmitter, n: &Alias) { e.group_start(GroupKind::Alias); @@ -20,8 +20,7 @@ pub(super) fn emit_alias(e: &mut EventEmitter, n: &Alias) { // Add column aliases if present if !n.colnames.is_empty() { e.line(LineType::SoftOrSpace); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.colnames, |node, e| { + emit_parenthesized_list(e, &n.colnames, |node, e| { // Column names in alias are String nodes if let Some(pgls_query::NodeEnum::String(s)) = node.node.as_ref() { super::emit_identifier_maybe_quoted(e, &s.sval); @@ -29,7 +28,6 @@ pub(super) fn emit_alias(e: &mut EventEmitter, n: &Alias) { super::emit_node(node, e); } }); - e.token(TokenKind::R_PAREN); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/alter_fdw_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_fdw_stmt.rs index 598424775..07d1bd0b3 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_fdw_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_fdw_stmt.rs @@ -2,7 +2,7 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; use pgls_query::protobuf::AlterFdwStmt; -use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_alter_fdw_stmt(e: &mut EventEmitter, n: &AlterFdwStmt) { e.group_start(GroupKind::AlterFdwStmt); @@ -65,12 +65,10 @@ pub(super) fn emit_alter_fdw_stmt(e: &mut EventEmitter, n: &AlterFdwStmt) { e.indent_start(); e.token(TokenKind::OPTIONS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |n, e| { + emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); - e.token(TokenKind::R_PAREN); e.indent_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/alter_foreign_server_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_foreign_server_stmt.rs index 76c158289..4c0907c38 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_foreign_server_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_foreign_server_stmt.rs @@ -2,10 +2,8 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; use pgls_query::protobuf::AlterForeignServerStmt; -use super::{ - node_list::emit_comma_separated_list, - string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}, -}; +use super::node_list::emit_parenthesized_list; +use super::string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}; pub(super) fn emit_alter_foreign_server_stmt(e: &mut EventEmitter, n: &AlterForeignServerStmt) { e.group_start(GroupKind::AlterForeignServerStmt); @@ -33,12 +31,10 @@ pub(super) fn emit_alter_foreign_server_stmt(e: &mut EventEmitter, n: &AlterFore e.indent_start(); emit_keyword(e, "OPTIONS"); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |n, e| { + emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); - e.token(TokenKind::R_PAREN); e.indent_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/alter_operator_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_operator_stmt.rs index 10b2c05b9..ae73438f7 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_operator_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_operator_stmt.rs @@ -4,9 +4,9 @@ use pgls_query::protobuf::{AlterOperatorStmt, DefElem, List, ObjectWithArgs}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, }; +use super::node_list::emit_parenthesized_list; use super::string::emit_identifier_maybe_quoted; pub(super) fn emit_alter_operator_stmt(e: &mut EventEmitter, n: &AlterOperatorStmt) { @@ -22,9 +22,7 @@ pub(super) fn emit_alter_operator_stmt(e: &mut EventEmitter, n: &AlterOperatorSt if !oper.objargs.is_empty() || !oper.args_unspecified { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &oper.objargs, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &oper.objargs, super::emit_node); } } @@ -32,13 +30,11 @@ pub(super) fn emit_alter_operator_stmt(e: &mut EventEmitter, n: &AlterOperatorSt e.line(LineType::SoftOrSpace); e.token(TokenKind::SET_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |node, emitter| { + emit_parenthesized_list(e, &n.options, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { emit_operator_option(emitter, def); } }); - e.token(TokenKind::R_PAREN); } e.token(TokenKind::SEMICOLON); @@ -83,7 +79,7 @@ fn emit_operator_option(e: &mut EventEmitter, def: &DefElem) { if let Some(ref arg) = def.arg { emit_operator_option_arg(e, arg); } else { - e.token(TokenKind::IDENT("NONE".to_string())); + e.token(TokenKind::NONE_KW); } } _ => { diff --git a/crates/pgls_pretty_print/src/nodes/alter_publication_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_publication_stmt.rs index 5cd833ae1..d5c9ea95b 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_publication_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_publication_stmt.rs @@ -3,6 +3,7 @@ use crate::emitter::{EventEmitter, GroupKind, LineType}; use pgls_query::protobuf::AlterPublicationStmt; use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_alter_publication_stmt(e: &mut EventEmitter, n: &AlterPublicationStmt) { e.group_start(GroupKind::AlterPublicationStmt); @@ -60,18 +61,14 @@ pub(super) fn emit_alter_publication_stmt(e: &mut EventEmitter, n: &AlterPublica e.line(LineType::SoftOrSpace); e.token(TokenKind::WITH_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); } } else { // Just options - use SET for setting publication options e.line(LineType::SoftOrSpace); e.token(TokenKind::SET_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/alter_subscription_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_subscription_stmt.rs index 0e73afd38..4a3f89a9f 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_subscription_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_subscription_stmt.rs @@ -1,3 +1,4 @@ +use super::node_list::emit_parenthesized_list; use super::{ node_list::emit_comma_separated_list, string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}, @@ -98,9 +99,7 @@ pub(super) fn emit_alter_subscription_stmt(e: &mut EventEmitter, n: &AlterSubscr e.token(TokenKind::WITH_KW); e.space(); } - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/alter_table_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_table_stmt.rs index ca618c74d..f4212b575 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_table_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_table_stmt.rs @@ -808,7 +808,7 @@ fn emit_alter_table_cmd_impl(e: &mut EventEmitter, cmd: &AlterTableCmd, for_type if let Some(ref def) = cmd.def && let Some(NodeEnum::Constraint(c)) = &def.node { - super::string::emit_identifier(e, &c.conname); + super::emit_identifier_maybe_quoted(e, &c.conname); // DEFERRABLE or NOT DEFERRABLE if c.deferrable { diff --git a/crates/pgls_pretty_print/src/nodes/alter_tablespace_options_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_tablespace_options_stmt.rs index a84929696..fc35df714 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_tablespace_options_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_tablespace_options_stmt.rs @@ -1,10 +1,11 @@ -use super::node_list::emit_comma_separated_list; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, }; use pgls_query::protobuf::AlterTableSpaceOptionsStmt; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_alter_tablespace_options_stmt( e: &mut EventEmitter, n: &AlterTableSpaceOptionsStmt, @@ -26,9 +27,7 @@ pub(super) fn emit_alter_tablespace_options_stmt( if !n.options.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/alter_type_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_type_stmt.rs index 48592237c..6ebc71776 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_type_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_type_stmt.rs @@ -3,9 +3,11 @@ use pgls_query::{NodeEnum, protobuf::AlterTypeStmt}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::{emit_comma_separated_list, emit_dot_separated_list}, + nodes::node_list::emit_dot_separated_list, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_alter_type_stmt(e: &mut EventEmitter, n: &AlterTypeStmt) { e.group_start(GroupKind::AlterTypeStmt); @@ -23,8 +25,7 @@ pub(super) fn emit_alter_type_stmt(e: &mut EventEmitter, n: &AlterTypeStmt) { e.line(LineType::SoftOrSpace); e.token(TokenKind::SET_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |node, emitter| { + emit_parenthesized_list(e, &n.options, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { emitter.token(TokenKind::IDENT(def.defname.clone())); if let Some(ref arg) = def.arg { @@ -35,7 +36,6 @@ pub(super) fn emit_alter_type_stmt(e: &mut EventEmitter, n: &AlterTypeStmt) { } } }); - e.token(TokenKind::R_PAREN); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/alter_user_mapping_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_user_mapping_stmt.rs index cae958097..8575692dc 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_user_mapping_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_user_mapping_stmt.rs @@ -1,10 +1,11 @@ -use super::node_list::emit_comma_separated_list; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, }; use pgls_query::protobuf::AlterUserMappingStmt; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_alter_user_mapping_stmt(e: &mut EventEmitter, n: &AlterUserMappingStmt) { e.group_start(GroupKind::AlterUserMappingStmt); @@ -34,12 +35,10 @@ pub(super) fn emit_alter_user_mapping_stmt(e: &mut EventEmitter, n: &AlterUserMa e.indent_start(); e.token(TokenKind::OPTIONS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |n, e| { + emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); - e.token(TokenKind::R_PAREN); e.indent_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/bool_expr.rs b/crates/pgls_pretty_print/src/nodes/bool_expr.rs index 2fa90ab6d..8d1827a7c 100644 --- a/crates/pgls_pretty_print/src/nodes/bool_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/bool_expr.rs @@ -20,14 +20,36 @@ pub(super) fn emit_bool_expr(e: &mut EventEmitter, n: &BoolExpr) { } fn emit_variadic_bool_expr(e: &mut EventEmitter, n: &BoolExpr, keyword: TokenKind) { + let mut is_first = true; + emit_variadic_operands(e, n, &keyword, &mut is_first); +} + +/// Emits the operands of an AND or OR chain. A nested chain of the same operator is emitted as part +/// of this one: `(a AND b) AND c` reads as `a AND b AND c`, which it means, and lays out the same +/// way it does once formatted. +fn emit_variadic_operands( + e: &mut EventEmitter, + n: &BoolExpr, + keyword: &TokenKind, + is_first: &mut bool, +) { let parent_kind = n.boolop(); let leading = matches!( e.config().logical_operator_placement, LogicalOperatorPlacement::Leading ); - for (idx, arg) in n.args.iter().enumerate() { - if idx > 0 { + for arg in &n.args { + if let Some(NodeEnum::BoolExpr(nested)) = arg.node.as_ref() + && nested.boolop() == parent_kind + { + super::emit_with_comments_at(e, nested.location, |e| { + emit_variadic_operands(e, nested, keyword, is_first); + }); + continue; + } + + if !*is_first { if leading { if let Some(location) = arg .node @@ -55,6 +77,7 @@ fn emit_variadic_bool_expr(e: &mut EventEmitter, n: &BoolExpr, keyword: TokenKin } } } + *is_first = false; emit_bool_operand(e, arg, parent_kind); } diff --git a/crates/pgls_pretty_print/src/nodes/column_def.rs b/crates/pgls_pretty_print/src/nodes/column_def.rs index bad3564be..bfceb5b5b 100644 --- a/crates/pgls_pretty_print/src/nodes/column_def.rs +++ b/crates/pgls_pretty_print/src/nodes/column_def.rs @@ -17,6 +17,10 @@ pub(super) fn emit_column_def(e: &mut EventEmitter, n: &ColumnDef) { super::emit_type_name(e, typename); } + // A broken column definition continues one level deeper, so that its clauses cannot be mistaken + // for the next column. + e.indent_start(); + // Add compression clause if specified if !n.compression.is_empty() { e.space(); @@ -81,5 +85,6 @@ pub(super) fn emit_column_def(e: &mut EventEmitter, n: &ColumnDef) { super::emit_node(constraint, e); } + e.indent_end(); e.group_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/common_table_expr.rs b/crates/pgls_pretty_print/src/nodes/common_table_expr.rs index d697665e8..a2019d1cc 100644 --- a/crates/pgls_pretty_print/src/nodes/common_table_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/common_table_expr.rs @@ -6,7 +6,7 @@ use crate::emitter::{EventEmitter, GroupKind, LineType}; use super::delete_stmt::emit_delete_stmt_no_semicolon; use super::insert_stmt::emit_insert_stmt_no_semicolon; use super::merge_stmt::emit_merge_stmt_no_semicolon; -use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; use super::select_stmt::emit_select_stmt_no_semicolon; use super::update_stmt::emit_update_stmt_no_semicolon; @@ -19,9 +19,7 @@ pub(super) fn emit_common_table_expr(e: &mut EventEmitter, n: &CommonTableExpr) // Optional column aliases if !n.aliascolnames.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.aliascolnames, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.aliascolnames, super::emit_node); } if matches!(e.config().layout, crate::Layout::Expanded) { diff --git a/crates/pgls_pretty_print/src/nodes/constraint.rs b/crates/pgls_pretty_print/src/nodes/constraint.rs index 090d97016..cc32252b7 100644 --- a/crates/pgls_pretty_print/src/nodes/constraint.rs +++ b/crates/pgls_pretty_print/src/nodes/constraint.rs @@ -6,11 +6,14 @@ use pgls_query::{ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; -use super::node_list::emit_comma_separated_list; -use super::string::emit_identifier; +use super::node_list::emit_parenthesized_list; +use super::string::emit_identifier_maybe_quoted; pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { e.group_start(GroupKind::Constraint); + // A broken constraint continues one level deeper than where it starts. The indent starts at + // the first continuation line, so a column list on the first line breaks relative to it. + let mut continued = false; match n.contype { x if x == ConstrType::ConstrNull as i32 => { @@ -21,7 +24,7 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.conname.is_empty() { e.token(TokenKind::CONSTRAINT_KW); e.space(); - emit_identifier(e, &n.conname); + emit_identifier_maybe_quoted(e, &n.conname); e.space(); } e.token(TokenKind::NOT_KW); @@ -56,7 +59,7 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.conname.is_empty() { e.token(TokenKind::CONSTRAINT_KW); e.space(); - emit_identifier(e, &n.conname); + emit_identifier_maybe_quoted(e, &n.conname); e.space(); } @@ -79,14 +82,14 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { } } - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::AS_KW); e.space(); e.token(TokenKind::IDENTITY_KW); // Add sequence options if present (e.g., START 7 INCREMENT 5) if !n.options.is_empty() { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::L_PAREN); for (idx, opt) in n.options.iter().enumerate() { if idx > 0 { @@ -123,7 +126,7 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.conname.is_empty() { e.token(TokenKind::CONSTRAINT_KW); e.space(); - emit_identifier(e, &n.conname); + emit_identifier_maybe_quoted(e, &n.conname); e.space(); } @@ -155,7 +158,7 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.conname.is_empty() { e.token(TokenKind::CONSTRAINT_KW); e.space(); - emit_identifier(e, &n.conname); + emit_identifier_maybe_quoted(e, &n.conname); e.space(); } @@ -165,25 +168,21 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.keys.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.keys, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.keys, super::emit_node); } // INCLUDE (columns) if !n.including.is_empty() { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::INCLUDE_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.including, |node, emitter| { + emit_parenthesized_list(e, &n.including, |node, emitter| { if let Some(pgls_query::NodeEnum::String(s)) = &node.node { - emit_identifier(emitter, &s.sval); + emit_identifier_maybe_quoted(emitter, &s.sval); } else { super::emit_node(node, emitter); } }); - e.token(TokenKind::R_PAREN); } if !n.indexname.is_empty() { @@ -192,29 +191,29 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { e.space(); e.token(TokenKind::INDEX_KW); e.space(); - emit_identifier(e, &n.indexname); + emit_identifier_maybe_quoted(e, &n.indexname); } // USING INDEX TABLESPACE for PRIMARY KEY if !n.indexspace.is_empty() { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::USING_KW); e.space(); e.token(TokenKind::INDEX_KW); e.space(); e.token(TokenKind::TABLESPACE_KW); e.space(); - emit_identifier(e, &n.indexspace); + emit_identifier_maybe_quoted(e, &n.indexspace); } - emit_deferrable(e, n); + emit_deferrable(e, n, &mut continued); } x if x == ConstrType::ConstrUnique as i32 => { // CONSTRAINT name UNIQUE (columns) if !n.conname.is_empty() { e.token(TokenKind::CONSTRAINT_KW); e.space(); - emit_identifier(e, &n.conname); + emit_identifier_maybe_quoted(e, &n.conname); e.space(); } @@ -234,25 +233,21 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.keys.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.keys, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.keys, super::emit_node); } // INCLUDE (columns) if !n.including.is_empty() { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::INCLUDE_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.including, |node, emitter| { + emit_parenthesized_list(e, &n.including, |node, emitter| { if let Some(pgls_query::NodeEnum::String(s)) = &node.node { - emit_identifier(emitter, &s.sval); + emit_identifier_maybe_quoted(emitter, &s.sval); } else { super::emit_node(node, emitter); } }); - e.token(TokenKind::R_PAREN); } if !n.indexname.is_empty() { @@ -261,29 +256,29 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { e.space(); e.token(TokenKind::INDEX_KW); e.space(); - emit_identifier(e, &n.indexname); + emit_identifier_maybe_quoted(e, &n.indexname); } // USING INDEX TABLESPACE for UNIQUE if !n.indexspace.is_empty() { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::USING_KW); e.space(); e.token(TokenKind::INDEX_KW); e.space(); e.token(TokenKind::TABLESPACE_KW); e.space(); - emit_identifier(e, &n.indexspace); + emit_identifier_maybe_quoted(e, &n.indexspace); } - emit_deferrable(e, n); + emit_deferrable(e, n, &mut continued); } x if x == ConstrType::ConstrExclusion as i32 => { // CONSTRAINT name EXCLUDE [USING method] (exclusion_list) [WHERE (predicate)] if !n.conname.is_empty() { e.token(TokenKind::CONSTRAINT_KW); e.space(); - emit_identifier(e, &n.conname); + emit_identifier_maybe_quoted(e, &n.conname); e.space(); } @@ -298,12 +293,15 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.exclusions.is_empty() { e.space(); + e.group_start(GroupKind::List); e.token(TokenKind::L_PAREN); + e.indent_start(); + e.line(LineType::Soft); for (idx, exclusion) in n.exclusions.iter().enumerate() { if idx > 0 { e.token(TokenKind::COMMA); - e.line(crate::emitter::LineType::SoftOrSpace); + e.line(LineType::SoftOrSpace); } let exclusion_list = assert_node_variant!(List, exclusion); @@ -333,23 +331,24 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { } } + e.indent_end(); + e.line(LineType::Soft); e.token(TokenKind::R_PAREN); + e.group_end(); } // INCLUDE (columns) if !n.including.is_empty() { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::INCLUDE_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.including, |node, emitter| { + emit_parenthesized_list(e, &n.including, |node, emitter| { if let Some(pgls_query::NodeEnum::String(s)) = &node.node { - emit_identifier(emitter, &s.sval); + emit_identifier_maybe_quoted(emitter, &s.sval); } else { super::emit_node(node, emitter); } }); - e.token(TokenKind::R_PAREN); } if let Some(ref where_clause) = n.where_clause { @@ -361,15 +360,15 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { e.token(TokenKind::R_PAREN); } - emit_deferrable(e, n); + emit_deferrable(e, n, &mut continued); } x if x == ConstrType::ConstrForeign as i32 => { // CONSTRAINT name FOREIGN KEY (fk_attrs) REFERENCES pktable (pk_attrs) [actions] if !n.conname.is_empty() { e.token(TokenKind::CONSTRAINT_KW); e.space(); - emit_identifier(e, &n.conname); - e.line(LineType::SoftOrSpace); + emit_identifier_maybe_quoted(e, &n.conname); + e.space(); } // Table-level constraint has FOREIGN KEY (...) @@ -378,11 +377,9 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { e.token(TokenKind::FOREIGN_KW); e.space(); e.token(TokenKind::KEY_KW); - e.line(LineType::SoftOrSpace); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.fk_attrs, super::emit_node); - e.token(TokenKind::R_PAREN); - e.line(LineType::SoftOrSpace); + e.space(); + emit_parenthesized_list(e, &n.fk_attrs, super::emit_node); + continue_line(e, &mut continued); } e.token(TokenKind::REFERENCES_KW); @@ -393,9 +390,7 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.pk_attrs.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.pk_attrs, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.pk_attrs, super::emit_node); } } @@ -403,13 +398,13 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.fk_matchtype.is_empty() { match n.fk_matchtype.as_str() { "f" => { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::MATCH_KW); e.space(); e.token(TokenKind::FULL_KW); } "p" => { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::MATCH_KW); e.space(); e.token(TokenKind::PARTIAL_KW); @@ -423,19 +418,19 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { // ON DELETE action - allow line break before if !n.fk_del_action.is_empty() && n.fk_del_action != "a" { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); emit_foreign_key_action(e, &n.fk_del_action, "DELETE", &n.fk_del_set_cols); } // ON UPDATE action - allow line break before if !n.fk_upd_action.is_empty() && n.fk_upd_action != "a" { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); emit_foreign_key_action(e, &n.fk_upd_action, "UPDATE", &[]); } // DEFERRABLE - allow line break before if n.deferrable { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::DEFERRABLE_KW); if n.initdeferred { @@ -452,7 +447,7 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { } if !n.initially_valid { - e.line(LineType::SoftOrSpace); + continue_line(e, &mut continued); e.token(TokenKind::NOT_KW); e.space(); e.token(TokenKind::VALID_KW); @@ -489,13 +484,25 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { } } + if continued { + e.indent_end(); + } e.group_end(); } +/// Starts a continuation line of a constraint, which is indented once whatever their number. +fn continue_line(e: &mut EventEmitter, continued: &mut bool) { + if !*continued { + e.indent_start(); + *continued = true; + } + e.line(LineType::SoftOrSpace); +} + /// `INITIALLY DEFERRED` implies `DEFERRABLE` in the AST, so emitting both round-trips either spelling. -fn emit_deferrable(e: &mut EventEmitter, n: &Constraint) { +fn emit_deferrable(e: &mut EventEmitter, n: &Constraint, continued: &mut bool) { if n.deferrable { - e.space(); + continue_line(e, continued); e.token(TokenKind::DEFERRABLE_KW); if n.initdeferred { @@ -523,7 +530,7 @@ fn emit_foreign_key_action( // Caller handles line break - we just emit the action e.token(TokenKind::ON_KW); e.space(); - e.token(TokenKind::IDENT(event.to_string())); + super::emit_word(e, event); e.space(); match action { @@ -540,9 +547,7 @@ fn emit_foreign_key_action( if !set_cols.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, set_cols, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, set_cols, super::emit_node); } } "d" => { @@ -552,9 +557,7 @@ fn emit_foreign_key_action( if !set_cols.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, set_cols, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, set_cols, super::emit_node); } } "a" => { diff --git a/crates/pgls_pretty_print/src/nodes/copy_stmt.rs b/crates/pgls_pretty_print/src/nodes/copy_stmt.rs index 212d565ba..f5f4bf55c 100644 --- a/crates/pgls_pretty_print/src/nodes/copy_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/copy_stmt.rs @@ -1,3 +1,4 @@ +use super::node_list::emit_parenthesized_list; use super::{ node_list::emit_comma_separated_list, string::{emit_keyword, emit_single_quoted_str}, @@ -114,9 +115,7 @@ pub(super) fn emit_copy_stmt(e: &mut EventEmitter, n: &CopyStmt) { fn emit_copy_option(e: &mut EventEmitter, n: &pgls_query::protobuf::DefElem) { e.group_start(GroupKind::DefElem); - // Emit the option name in uppercase - let name_upper = n.defname.to_uppercase(); - e.token(TokenKind::IDENT(name_upper.clone())); + super::emit_word(e, &n.defname); // Handle the value based on its type if let Some(ref arg) = n.arg @@ -140,9 +139,7 @@ fn emit_copy_option(e: &mut EventEmitter, n: &pgls_query::protobuf::DefElem) { NodeEnum::List(list) => { // For options like FORCE_QUOTE (column_list) e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &list.items, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &list.items, super::emit_node); } _ => { e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/create_enum_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_enum_stmt.rs index 23618aa8c..13668739e 100644 --- a/crates/pgls_pretty_print/src/nodes/create_enum_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_enum_stmt.rs @@ -3,9 +3,10 @@ use pgls_query::protobuf::CreateEnumStmt; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, - nodes::node_list::emit_comma_separated_list, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_create_enum_stmt(e: &mut EventEmitter, n: &CreateEnumStmt) { e.group_start(GroupKind::CreateEnumStmt); @@ -27,12 +28,10 @@ pub(super) fn emit_create_enum_stmt(e: &mut EventEmitter, n: &CreateEnumStmt) { // Emit the enum values list (as string literals with quotes) if !n.vals.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.vals, |n, e| { + emit_parenthesized_list(e, &n.vals, |n, e| { let s = assert_node_variant!(String, n); super::string::emit_string_literal(e, s); }); - e.token(TokenKind::R_PAREN); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/create_event_trig_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_event_trig_stmt.rs index 4d2f06ff9..3a319f28f 100644 --- a/crates/pgls_pretty_print/src/nodes/create_event_trig_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_event_trig_stmt.rs @@ -17,7 +17,7 @@ pub(super) fn emit_create_event_trig_stmt(e: &mut EventEmitter, n: &CreateEventT // Trigger name if !n.trigname.is_empty() { e.space(); - super::emit_identifier(e, &n.trigname); + super::emit_identifier_maybe_quoted(e, &n.trigname); } // ON event_name @@ -42,8 +42,8 @@ pub(super) fn emit_create_event_trig_stmt(e: &mut EventEmitter, n: &CreateEventT } // Each when clause is a DefElem with defname=tag and arg=List of values if let Some(pgls_query::NodeEnum::DefElem(def_elem)) = when.node.as_ref() { - // Emit TAG name (uppercased) - e.token(TokenKind::IDENT(def_elem.defname.to_uppercase())); + // Emit TAG name + super::emit_word(e, &def_elem.defname); e.space(); e.token(TokenKind::IN_KW); e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/create_fdw_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_fdw_stmt.rs index b00b7dd59..630580210 100644 --- a/crates/pgls_pretty_print/src/nodes/create_fdw_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_fdw_stmt.rs @@ -1,10 +1,11 @@ -use super::node_list::emit_comma_separated_list; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, }; use pgls_query::protobuf::CreateFdwStmt; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_create_fdw_stmt(e: &mut EventEmitter, n: &CreateFdwStmt) { e.group_start(GroupKind::CreateFdwStmt); @@ -64,12 +65,10 @@ pub(super) fn emit_create_fdw_stmt(e: &mut EventEmitter, n: &CreateFdwStmt) { e.indent_start(); e.token(TokenKind::OPTIONS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |n, e| { + emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); - e.token(TokenKind::R_PAREN); e.indent_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/create_foreign_server_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_foreign_server_stmt.rs index 8fb8118ce..847a87a23 100644 --- a/crates/pgls_pretty_print/src/nodes/create_foreign_server_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_foreign_server_stmt.rs @@ -4,10 +4,8 @@ use crate::{ }; use pgls_query::protobuf::CreateForeignServerStmt; -use super::{ - node_list::emit_comma_separated_list, - string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}, -}; +use super::node_list::emit_parenthesized_list; +use super::string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}; pub(super) fn emit_create_foreign_server_stmt(e: &mut EventEmitter, n: &CreateForeignServerStmt) { e.group_start(GroupKind::CreateForeignServerStmt); @@ -68,12 +66,10 @@ pub(super) fn emit_create_foreign_server_stmt(e: &mut EventEmitter, n: &CreateFo e.indent_start(); emit_keyword(e, "OPTIONS"); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |n, e| { + emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); - e.token(TokenKind::R_PAREN); e.indent_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/create_foreign_table_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_foreign_table_stmt.rs index 3c25e86b0..cacb40bc7 100644 --- a/crates/pgls_pretty_print/src/nodes/create_foreign_table_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_foreign_table_stmt.rs @@ -1,4 +1,5 @@ use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, @@ -68,12 +69,10 @@ pub(super) fn emit_create_foreign_table_stmt(e: &mut EventEmitter, n: &CreateFor e.space(); e.token(TokenKind::OPTIONS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |n, e| { + emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); - e.token(TokenKind::R_PAREN); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs index 217bd8be7..2e5e72ac9 100644 --- a/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs @@ -179,9 +179,13 @@ pub(super) fn emit_function_parameter(e: &mut EventEmitter, fp: &FunctionParamet FunctionParameterMode::Undefined => {} } - // Parameter name + // Parameter name, which the grammar spells as a function or type name if !fp.name.is_empty() { - super::emit_identifier_maybe_quoted(e, &fp.name); + if super::string::needs_quoting_as_function_or_type_name(&fp.name) { + super::emit_identifier(e, &fp.name); + } else { + super::emit_identifier_maybe_quoted(e, &fp.name); + } e.space(); } @@ -277,7 +281,7 @@ pub(super) fn format_function_option( // Single item: either library name (C) or SQL body (SQL/plpgsql) if let Some(pgls_query::NodeEnum::String(s)) = &list.items[0].node { // Use dollar quotes for function bodies (they handle embedded quotes better) - super::emit_dollar_quoted_str_with_hint(e, &s.sval, hint); + super::emit_body_literal(e, &s.sval, d.location, hint); } else { super::emit_node(&list.items[0], e); } @@ -325,7 +329,7 @@ pub(super) fn format_function_option( "IMMUTABLE" => e.token(TokenKind::IMMUTABLE_KW), "STABLE" => e.token(TokenKind::STABLE_KW), "VOLATILE" => e.token(TokenKind::VOLATILE_KW), - _ => e.token(TokenKind::IDENT(volatility)), + _ => super::emit_word(e, &s.sval), } } else { super::emit_node(arg, e); @@ -390,8 +394,7 @@ pub(super) fn format_function_option( e.space(); if let Some(ref arg) = d.arg { if let Some(pgls_query::NodeEnum::String(s)) = &arg.node { - let parallel = s.sval.to_uppercase(); - e.token(TokenKind::IDENT(parallel)); + super::emit_word(e, &s.sval); } else { super::emit_node(arg, e); } @@ -462,8 +465,7 @@ pub(super) fn format_function_option( } _ => { // Default: emit option name and value - let defname_upper = d.defname.to_uppercase(); - e.token(TokenKind::IDENT(defname_upper)); + super::emit_word(e, &d.defname); if let Some(ref arg) = d.arg { e.space(); super::emit_node(arg, e); diff --git a/crates/pgls_pretty_print/src/nodes/create_op_class_item.rs b/crates/pgls_pretty_print/src/nodes/create_op_class_item.rs index 86a515c83..f96fbec57 100644 --- a/crates/pgls_pretty_print/src/nodes/create_op_class_item.rs +++ b/crates/pgls_pretty_print/src/nodes/create_op_class_item.rs @@ -2,7 +2,8 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind}; use pgls_query::protobuf::CreateOpClassItem; -use super::node_list::{emit_comma_separated_list, emit_dot_separated_list}; +use super::node_list::emit_dot_separated_list; +use super::node_list::emit_parenthesized_list; use super::object_with_args::{emit_object_name_only, emit_object_with_args}; pub(super) fn emit_create_op_class_item(e: &mut EventEmitter, n: &CreateOpClassItem) { @@ -27,16 +28,12 @@ pub(super) fn emit_create_op_class_item(e: &mut EventEmitter, n: &CreateOpClassI if !name.objargs.is_empty() { e.space(); e.group_start(GroupKind::CreateOpClassItem); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &name.objargs, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &name.objargs, super::emit_node); e.group_end(); } } else if !n.class_args.is_empty() { // DROP case: no operator name, just emit (left_type, right_type) from class_args - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.class_args, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.class_args, super::emit_node); } // Optional FOR ORDER BY opfamily @@ -62,9 +59,7 @@ pub(super) fn emit_create_op_class_item(e: &mut EventEmitter, n: &CreateOpClassI // class_args come first (for ADD or DROP) if !n.class_args.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.class_args, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.class_args, super::emit_node); } if let Some(ref name) = n.name { diff --git a/crates/pgls_pretty_print/src/nodes/create_policy_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_policy_stmt.rs index 8d17e64fb..7e1d9f691 100644 --- a/crates/pgls_pretty_print/src/nodes/create_policy_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_policy_stmt.rs @@ -43,7 +43,7 @@ pub(super) fn emit_create_policy_stmt(e: &mut EventEmitter, n: &CreatePolicyStmt "INSERT" => e.token(TokenKind::INSERT_KW), "UPDATE" => e.token(TokenKind::UPDATE_KW), "DELETE" => e.token(TokenKind::DELETE_KW), - _ => e.token(TokenKind::IDENT(cmd_upper)), + _ => super::emit_word(e, &n.cmd_name), } } diff --git a/crates/pgls_pretty_print/src/nodes/create_publication_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_publication_stmt.rs index d132f45dc..d402105a4 100644 --- a/crates/pgls_pretty_print/src/nodes/create_publication_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_publication_stmt.rs @@ -5,6 +5,8 @@ use crate::{ }; use pgls_query::{NodeEnum, protobuf::CreatePublicationStmt}; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_create_publication_stmt(e: &mut EventEmitter, n: &CreatePublicationStmt) { e.group_start(GroupKind::CreatePublicationStmt); @@ -42,9 +44,7 @@ pub(super) fn emit_create_publication_stmt(e: &mut EventEmitter, n: &CreatePubli // Handle column list if !relation.columns.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &relation.columns, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &relation.columns, super::emit_node); } // Handle WHERE clause if let Some(ref where_clause) = relation.where_clause { @@ -89,9 +89,7 @@ pub(super) fn emit_create_publication_stmt(e: &mut EventEmitter, n: &CreatePubli e.line(LineType::SoftOrSpace); e.token(TokenKind::WITH_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/create_role_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_role_stmt.rs index 972343313..48007cc4f 100644 --- a/crates/pgls_pretty_print/src/nodes/create_role_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_role_stmt.rs @@ -199,8 +199,7 @@ fn format_role_option(e: &mut EventEmitter, d: &pgls_query::protobuf::DefElem) { } // Default formatting for other options - let defname_upper = d.defname.to_uppercase(); - e.token(TokenKind::IDENT(defname_upper)); + super::emit_word(e, &d.defname); if let Some(ref arg) = d.arg { e.space(); super::emit_node(arg, e); diff --git a/crates/pgls_pretty_print/src/nodes/create_schema_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_schema_stmt.rs index 5d009e213..aedddf56b 100644 --- a/crates/pgls_pretty_print/src/nodes/create_schema_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_schema_stmt.rs @@ -29,7 +29,7 @@ pub(super) fn emit_create_schema_stmt(e: &mut EventEmitter, n: &CreateSchemaStmt if !n.schemaname.is_empty() { e.space(); - super::emit_identifier(e, &n.schemaname); + super::emit_identifier_maybe_quoted(e, &n.schemaname); } // AUTHORIZATION clause diff --git a/crates/pgls_pretty_print/src/nodes/create_stats_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_stats_stmt.rs index 74ac995c2..294b3f5b6 100644 --- a/crates/pgls_pretty_print/src/nodes/create_stats_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_stats_stmt.rs @@ -5,6 +5,8 @@ use crate::{ }; use pgls_query::{NodeEnum, protobuf::CreateStatsStmt}; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_create_stats_stmt(e: &mut EventEmitter, n: &CreateStatsStmt) { e.group_start(GroupKind::CreateStatsStmt); @@ -29,13 +31,11 @@ pub(super) fn emit_create_stats_stmt(e: &mut EventEmitter, n: &CreateStatsStmt) // Statistics types (e.g., ndistinct, dependencies) if !n.stat_types.is_empty() { e.line(LineType::SoftOrSpace); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.stat_types, |node, e| { + emit_parenthesized_list(e, &n.stat_types, |node, e| { if let Some(NodeEnum::String(s)) = &node.node { e.token(TokenKind::IDENT(s.sval.clone())); } }); - e.token(TokenKind::R_PAREN); } e.line(LineType::SoftOrSpace); diff --git a/crates/pgls_pretty_print/src/nodes/create_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_stmt.rs index 5019e968b..039d6493c 100644 --- a/crates/pgls_pretty_print/src/nodes/create_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_stmt.rs @@ -4,6 +4,7 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; /// Emit a column override for typed tables (OF typename). /// These use the syntax: column_name WITH OPTIONS constraints @@ -234,9 +235,7 @@ fn emit_create_stmt_impl(e: &mut EventEmitter, n: &CreateStmt, with_semicolon: b e.line(LineType::Hard); e.token(TokenKind::INHERITS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.inh_relations, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.inh_relations, super::emit_node); } // Add PARTITION BY clause for regular partitioned tables diff --git a/crates/pgls_pretty_print/src/nodes/create_subscription_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_subscription_stmt.rs index b64742fc9..2d98acf39 100644 --- a/crates/pgls_pretty_print/src/nodes/create_subscription_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_subscription_stmt.rs @@ -5,6 +5,7 @@ use crate::{ }; use pgls_query::{NodeEnum, protobuf::CreateSubscriptionStmt}; +use super::node_list::emit_parenthesized_list; use super::string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}; pub(super) fn emit_create_subscription_stmt(e: &mut EventEmitter, n: &CreateSubscriptionStmt) { @@ -35,9 +36,7 @@ pub(super) fn emit_create_subscription_stmt(e: &mut EventEmitter, n: &CreateSubs e.space(); e.token(TokenKind::WITH_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/create_table_as_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_table_as_stmt.rs index 7fbec9ab7..2b191bd98 100644 --- a/crates/pgls_pretty_print/src/nodes/create_table_as_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_table_as_stmt.rs @@ -5,10 +5,8 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::{ - emit_node, node_list::emit_comma_separated_list, select_stmt::emit_select_stmt_no_semicolon, - string::emit_string, -}; +use super::node_list::emit_parenthesized_list; +use super::{emit_node, select_stmt::emit_select_stmt_no_semicolon, string::emit_string}; pub(super) fn emit_create_table_as_stmt(e: &mut EventEmitter, n: &CreateTableAsStmt) { e.group_start(GroupKind::CreateTableAsStmt); @@ -59,12 +57,10 @@ pub(super) fn emit_create_table_as_stmt(e: &mut EventEmitter, n: &CreateTableAsS if !into.col_names.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &into.col_names, |node, e| { + emit_parenthesized_list(e, &into.col_names, |node, e| { let string = assert_node_variant!(String, node); emit_string(e, string); }); - e.token(TokenKind::R_PAREN); } } @@ -81,8 +77,7 @@ pub(super) fn emit_create_table_as_stmt(e: &mut EventEmitter, n: &CreateTableAsS e.space(); e.token(TokenKind::WITH_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &into.options, |node, emitter| { + emit_parenthesized_list(e, &into.options, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { emitter.token(TokenKind::IDENT(def.defname.to_lowercase())); if let Some(ref arg) = def.arg { @@ -93,7 +88,6 @@ pub(super) fn emit_create_table_as_stmt(e: &mut EventEmitter, n: &CreateTableAsS } } }); - e.token(TokenKind::R_PAREN); } // ON COMMIT diff --git a/crates/pgls_pretty_print/src/nodes/create_table_space_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_table_space_stmt.rs index a34549deb..d95ce9f7d 100644 --- a/crates/pgls_pretty_print/src/nodes/create_table_space_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_table_space_stmt.rs @@ -5,6 +5,7 @@ use crate::{ emitter::{EventEmitter, GroupKind}, }; +use super::node_list::emit_parenthesized_list; use super::string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}; pub(super) fn emit_create_table_space_stmt(e: &mut EventEmitter, n: &CreateTableSpaceStmt) { @@ -38,9 +39,7 @@ pub(super) fn emit_create_table_space_stmt(e: &mut EventEmitter, n: &CreateTable e.space(); e.token(TokenKind::WITH_KW); e.space(); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/create_user_mapping_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_user_mapping_stmt.rs index 463cb899d..7f638db66 100644 --- a/crates/pgls_pretty_print/src/nodes/create_user_mapping_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_user_mapping_stmt.rs @@ -1,10 +1,11 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, }; use pgls_query::protobuf::CreateUserMappingStmt; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_create_user_mapping_stmt(e: &mut EventEmitter, n: &CreateUserMappingStmt) { e.group_start(GroupKind::CreateUserMappingStmt); @@ -41,12 +42,10 @@ pub(super) fn emit_create_user_mapping_stmt(e: &mut EventEmitter, n: &CreateUser e.space(); e.token(TokenKind::OPTIONS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |n, e| { + emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); - e.token(TokenKind::R_PAREN); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/createdb_stmt.rs b/crates/pgls_pretty_print/src/nodes/createdb_stmt.rs index 83d938e20..60f6bd732 100644 --- a/crates/pgls_pretty_print/src/nodes/createdb_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/createdb_stmt.rs @@ -16,7 +16,7 @@ pub(super) fn emit_createdb_stmt(e: &mut EventEmitter, n: &CreatedbStmt) { if !n.dbname.is_empty() { e.space(); - super::emit_identifier(e, &n.dbname); + super::emit_identifier_maybe_quoted(e, &n.dbname); } // Emit database options (WITH CONNECTION LIMIT, ENCODING, etc.) diff --git a/crates/pgls_pretty_print/src/nodes/declare_cursor_stmt.rs b/crates/pgls_pretty_print/src/nodes/declare_cursor_stmt.rs index 0f390436e..fa1675e44 100644 --- a/crates/pgls_pretty_print/src/nodes/declare_cursor_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/declare_cursor_stmt.rs @@ -22,7 +22,7 @@ pub(super) fn emit_declare_cursor_stmt(e: &mut EventEmitter, n: &DeclareCursorSt // Cursor name if !n.portalname.is_empty() { e.space(); - super::emit_identifier(e, &n.portalname); + super::emit_identifier_maybe_quoted(e, &n.portalname); } // Cursor options diff --git a/crates/pgls_pretty_print/src/nodes/def_elem.rs b/crates/pgls_pretty_print/src/nodes/def_elem.rs index 02899e58b..a81e403fc 100644 --- a/crates/pgls_pretty_print/src/nodes/def_elem.rs +++ b/crates/pgls_pretty_print/src/nodes/def_elem.rs @@ -122,14 +122,8 @@ pub(super) fn emit_grant_role_option(e: &mut EventEmitter, n: &DefElem) { } }); - // Emit the option name in uppercase - let opt_name = match defname { - "admin" => "ADMIN", - "inherit" => "INHERIT", - "set" => "SET", - _ => &defname.to_uppercase(), - }; - e.token(TokenKind::IDENT(opt_name.to_string())); + // Emit the option name + super::emit_word(e, defname); // Emit TRUE or FALSE if let Some(val) = is_true { @@ -299,7 +293,7 @@ pub(super) fn emit_role_option(e: &mut EventEmitter, n: &DefElem) { _ => { // Fallback for unknown role options if !n.defname.is_empty() { - e.token(TokenKind::IDENT(n.defname.to_uppercase())); + super::emit_word(e, &n.defname); } if let Some(ref arg) = n.arg { e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/define_stmt.rs b/crates/pgls_pretty_print/src/nodes/define_stmt.rs index 49a257242..9025078d7 100644 --- a/crates/pgls_pretty_print/src/nodes/define_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/define_stmt.rs @@ -1,6 +1,7 @@ use pgls_query::NodeEnum; use pgls_query::protobuf::{DefElem, DefineStmt, List, Node, ObjectType}; +use super::node_list::emit_parenthesized_list; use super::string::emit_identifier_maybe_quoted; use crate::{ TokenKind, @@ -162,15 +163,13 @@ pub(super) fn emit_define_stmt(e: &mut EventEmitter, n: &DefineStmt) { if is_operator { if !n.definition.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.definition, |node, emitter| { + emit_parenthesized_list(e, &n.definition, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { emit_operator_def_elem(emitter, def); } else { super::emit_node(node, emitter); } }); - e.token(TokenKind::R_PAREN); } } else if kind == ObjectType::ObjectCollation && !n.definition.is_empty() { emit_collation_definition(e, &n.definition); @@ -209,8 +208,7 @@ fn emit_operator_name(e: &mut EventEmitter, defnames: &[Node]) { } fn emit_operator_def_elem(e: &mut EventEmitter, def: &DefElem) { - let name = def.defname.to_ascii_uppercase(); - e.token(TokenKind::IDENT(name)); + super::emit_word(e, &def.defname); if let Some(ref arg) = def.arg { e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/do_stmt.rs b/crates/pgls_pretty_print/src/nodes/do_stmt.rs index 22e06e342..567f66b04 100644 --- a/crates/pgls_pretty_print/src/nodes/do_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/do_stmt.rs @@ -6,7 +6,7 @@ use crate::{ }; use super::string::{ - DollarQuoteHint, emit_dollar_quoted_str_with_hint, emit_identifier_maybe_quoted, emit_keyword, + DollarQuoteHint, emit_body_literal, emit_identifier_maybe_quoted, emit_keyword, }; pub(super) fn emit_do_stmt(e: &mut EventEmitter, n: &DoStmt) { @@ -71,14 +71,14 @@ pub(super) fn emit_do_stmt(e: &mut EventEmitter, n: &DoStmt) { e.space(); emit_identifier_maybe_quoted(e, lang); } - if let Some((code, _)) = &body { + if let Some((code, location)) = &body { e.line(LineType::SoftOrSpace); - emit_dollar_quoted_str_with_hint(e, code, DollarQuoteHint::Do); + emit_body_literal(e, code, *location, DollarQuoteHint::Do); } } else { - if let Some((code, _)) = &body { + if let Some((code, location)) = &body { e.line(LineType::SoftOrSpace); - emit_dollar_quoted_str_with_hint(e, code, DollarQuoteHint::Do); + emit_body_literal(e, code, *location, DollarQuoteHint::Do); } if let Some((lang, _)) = &language { e.line(LineType::SoftOrSpace); diff --git a/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs b/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs index 3c5b02773..50e41784f 100644 --- a/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs @@ -3,9 +3,10 @@ use pgls_query::{NodeEnum, protobuf::DropdbStmt}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, - nodes::node_list::emit_comma_separated_list, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_dropdb_stmt(e: &mut EventEmitter, n: &DropdbStmt) { e.group_start(GroupKind::DropdbStmt); @@ -28,14 +29,12 @@ pub(super) fn emit_dropdb_stmt(e: &mut EventEmitter, n: &DropdbStmt) { // DROP DATABASE options like (FORCE) if !n.options.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |node, emitter| { + emit_parenthesized_list(e, &n.options, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { // Options like FORCE have just the name, no value - emitter.token(TokenKind::IDENT(def.defname.to_uppercase())); + super::emit_word(emitter, &def.defname); } }); - e.token(TokenKind::R_PAREN); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/execute_stmt.rs b/crates/pgls_pretty_print/src/nodes/execute_stmt.rs index ed1047908..d8c09fd2e 100644 --- a/crates/pgls_pretty_print/src/nodes/execute_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/execute_stmt.rs @@ -6,6 +6,7 @@ use crate::{ }; use super::emit_node; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_execute_stmt(e: &mut EventEmitter, n: &ExecuteStmt) { emit_execute_stmt_impl(e, n, true); @@ -24,9 +25,7 @@ fn emit_execute_stmt_impl(e: &mut EventEmitter, n: &ExecuteStmt, with_semicolon: if !n.params.is_empty() { e.line(LineType::SoftOrSpace); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.params, emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.params, emit_node); } if with_semicolon { diff --git a/crates/pgls_pretty_print/src/nodes/explain_stmt.rs b/crates/pgls_pretty_print/src/nodes/explain_stmt.rs index 98c892984..7234f89f4 100644 --- a/crates/pgls_pretty_print/src/nodes/explain_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/explain_stmt.rs @@ -37,9 +37,8 @@ pub(super) fn emit_explain_stmt(e: &mut EventEmitter, n: &ExplainStmt) { fn emit_explain_option(e: &mut EventEmitter, node: &pgls_query::Node) { if let Some(NodeEnum::DefElem(def)) = &node.node { - // Emit the option name in uppercase if !def.defname.is_empty() { - e.token(TokenKind::IDENT(def.defname.to_uppercase())); + super::emit_word(e, &def.defname); } // Emit the option value if present (no equals sign for EXPLAIN) diff --git a/crates/pgls_pretty_print/src/nodes/func_call.rs b/crates/pgls_pretty_print/src/nodes/func_call.rs index 8b8462354..72a4d5402 100644 --- a/crates/pgls_pretty_print/src/nodes/func_call.rs +++ b/crates/pgls_pretty_print/src/nodes/func_call.rs @@ -3,7 +3,15 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, nodes::node_list::emit_comma_separated_list, }; -use pgls_query::protobuf::FuncCall; +use pgls_query::{ + Node, NodeEnum, + protobuf::{CoercionForm, FuncCall, a_const::Val}, +}; + +use super::string::{ + emit_identifier, needs_quoting, needs_quoting_as_column_name, + needs_quoting_as_function_or_type_name, needs_quoting_except_keywords, +}; /// Get the last part of the function name (the actual function name without schema) fn get_last_func_name(n: &FuncCall) -> Option<&str> { @@ -98,136 +106,15 @@ pub(super) fn emit_func_call(e: &mut EventEmitter, n: &FuncCall) { e.group_start(GroupKind::List); } - // Determine if this is a special function that needs uppercase treatment - // For normalize, we need to check if it matches the built-in pattern - let is_builtin_normalize_call = get_last_func_name(n) - .map(|name| name.to_lowercase() == "normalize" && is_builtin_normalize(n)) - .unwrap_or(false); - - // Emit function name (could be qualified like schema.func) - let mut name_parts = Vec::new(); - - for (i, node) in n.funcname.iter().enumerate() { - if let Some(pgls_query::NodeEnum::String(s)) = &node.node { - // Skip pg_catalog schema for built-in functions - if i == 0 && s.sval.to_lowercase() == "pg_catalog" { - continue; - } - - // Normalize common function names to uppercase - // For normalize, only uppercase if it matches built-in pattern - let name = match s.sval.to_lowercase().as_str() { - "now" => "NOW", - "current_timestamp" => "CURRENT_TIMESTAMP", - "current_date" => "CURRENT_DATE", - "current_time" => "CURRENT_TIME", - "localtime" => "LOCALTIME", - "localtimestamp" => "LOCALTIMESTAMP", - // Window functions - "row_number" => "ROW_NUMBER", - "rank" => "RANK", - "dense_rank" => "DENSE_RANK", - "percent_rank" => "PERCENT_RANK", - "cume_dist" => "CUME_DIST", - "ntile" => "NTILE", - "lag" => "LAG", - "lead" => "LEAD", - "first_value" => "FIRST_VALUE", - "last_value" => "LAST_VALUE", - "nth_value" => "NTH_VALUE", - // Aggregate functions - "sum" => "SUM", - "count" => "COUNT", - "avg" => "AVG", - "min" => "MIN", - "max" => "MAX", - // Special SQL functions - "extract" => "EXTRACT", - "overlay" => "OVERLAY", - "position" => "POSITION", - "substring" => "SUBSTRING", - "trim" => "TRIM", - "normalize" if is_builtin_normalize_call => "NORMALIZE", - // SQL value functions without parens - "system_user" => "SYSTEM_USER", - "session_user" => "SESSION_USER", - "current_user" => "CURRENT_USER", - "current_role" => "CURRENT_ROLE", - "current_catalog" => "CURRENT_CATALOG", - "current_schema" => "CURRENT_SCHEMA", - "user" => "USER", - _ => &s.sval, - }; - name_parts.push(name.to_string()); - } + // The grammar turns SQL-standard syntax such as `EXTRACT(year FROM d)` or `ts AT TIME ZONE z` + // into a call to a `pg_catalog` function, flagged as written in that syntax. Anything else was + // written as a call, and is written back as one with its name exactly as qualified. + let is_sql_syntax = n.funcformat == CoercionForm::CoerceSqlSyntax as i32; + if !(is_sql_syntax && emit_sql_syntax_call(e, n)) { + emit_function_name(e, &n.funcname); + emit_standard_function(e, n); } - // Check if this is a user-defined function that shadows a built-in - // These need to be quoted to avoid being interpreted as the built-in - let needs_explicit_quoting = !is_builtin_normalize_call - && get_last_func_name(n) - .map(|name| name.to_lowercase() == "normalize") - .unwrap_or(false); - - // Emit function name with dots - for (i, part) in name_parts.iter().enumerate() { - if i > 0 { - e.token(TokenKind::DOT); - } - // Quote function names that shadow built-ins - if needs_explicit_quoting && i == name_parts.len() - 1 { - super::emit_identifier(e, part); - } else { - // Emit function name directly without quoting check - // Function names are case-insensitive and we've already normalized - // to uppercase for built-ins, so just emit as-is - e.token(TokenKind::IDENT(part.clone())); - } - } - - let function_name = name_parts.last().map(|s| s.as_str()).unwrap_or(""); - - // Handle special SQL standard function syntax - match function_name.to_lowercase().as_str() { - "extract" => { - emit_extract_function(e, n); - } - "overlay" => { - emit_overlay_function(e, n); - } - "position" => { - emit_position_function(e, n); - } - "substring" => { - emit_substring_function(e, n); - } - "trim" => { - emit_trim_function(e, n); - } - "normalize" => { - // NORMALIZE has special syntax only when second arg is a valid form - // If it's a user-defined function with same name, use standard call - if is_builtin_normalize(n) { - emit_normalize_function(e, n); - } else { - // This is a user-defined function, use standard call - emit_standard_function(e, n); - } - } - "xmlexists" => { - emit_xmlexists_function(e, n); - } - // SQL value functions that don't use parentheses - "system_user" | "session_user" | "current_user" | "current_role" | "current_catalog" - | "current_schema" | "user" => { - // These SQL standard functions are called without parentheses - // Already emitted the name above, no parens needed - } - _ => { - // Standard function call with comma-separated arguments - emit_standard_function(e, n); - } - } if n.over.is_some() { e.group_end(); } @@ -355,237 +242,317 @@ fn emit_standard_function(e: &mut EventEmitter, n: &FuncCall) { e.token(TokenKind::R_PAREN); } -// EXTRACT(field FROM source) -fn emit_extract_function(e: &mut EventEmitter, n: &FuncCall) { - assert!( - n.args.len() == 2, - "EXTRACT function expects 2 arguments, got {}", - n.args.len() - ); - - e.token(TokenKind::L_PAREN); - - // First arg is the field (epoch, year, month, etc.) - super::emit_node(&n.args[0], e); - - e.space(); - e.token(TokenKind::FROM_KW); - e.space(); - // Second arg is the source expression - super::emit_node(&n.args[1], e); - - e.token(TokenKind::R_PAREN); -} - -// OVERLAY(string PLACING newstring FROM start [FOR length]) -fn emit_overlay_function(e: &mut EventEmitter, n: &FuncCall) { - assert!( - n.args.len() == 3 || n.args.len() == 4, - "OVERLAY function expects 3 or 4 arguments, got {}", - n.args.len() - ); - - e.token(TokenKind::L_PAREN); - - // First arg: string - super::emit_node(&n.args[0], e); - - e.space(); - e.token(TokenKind::PLACING_KW); - e.space(); - // Second arg: newstring - super::emit_node(&n.args[1], e); - - e.space(); - e.token(TokenKind::FROM_KW); - e.space(); - // Third arg: start position - super::emit_node(&n.args[2], e); - - if n.args.len() == 4 { - e.space(); - e.token(TokenKind::FOR_KW); - e.space(); - // Fourth arg: length - super::emit_node(&n.args[3], e); +/// Emits a function name as written. A name the grammar would read as something else unquoted, such +/// as `coalesce` or a reserved word, is quoted. +fn emit_function_name(e: &mut EventEmitter, funcname: &[Node]) { + let parts: Vec<&str> = funcname + .iter() + .filter_map(|node| match &node.node { + Some(NodeEnum::String(s)) => Some(s.sval.as_str()), + _ => None, + }) + .collect(); + + // The grammar qualifies the plain-call form of `json_object(...)` itself. + if let ["pg_catalog", "json_object"] = parts.as_slice() { + e.token(TokenKind::IDENT("json_object".to_string())); + return; } - e.token(TokenKind::R_PAREN); -} - -// POSITION(substring IN string) -// PostgreSQL stores args as: [string, substring] (reversed from syntax) -fn emit_position_function(e: &mut EventEmitter, n: &FuncCall) { - assert!( - n.args.len() == 2, - "POSITION function expects 2 arguments, got {}", - n.args.len() - ); - - e.token(TokenKind::L_PAREN); - - // First syntactic arg: substring (stored as second arg in AST) - super::emit_node(&n.args[1], e); - - e.space(); - e.token(TokenKind::IN_KW); - e.space(); - // Second syntactic arg: string (stored as first arg in AST) - super::emit_node(&n.args[0], e); - - e.token(TokenKind::R_PAREN); -} - -// SUBSTRING(string FROM start [FOR length]) -fn emit_substring_function(e: &mut EventEmitter, n: &FuncCall) { - assert!( - n.args.len() == 2 || n.args.len() == 3, - "SUBSTRING function expects 2 or 3 arguments, got {}", - n.args.len() - ); - - e.token(TokenKind::L_PAREN); - - // First arg: string - super::emit_node(&n.args[0], e); - - e.line(LineType::SoftOrSpace); - e.token(TokenKind::FROM_KW); - e.space(); - // Second arg: start position - super::emit_node(&n.args[1], e); - - if n.args.len() == 3 { - e.line(LineType::SoftOrSpace); - e.token(TokenKind::FOR_KW); - e.space(); - // Third arg: length - super::emit_node(&n.args[2], e); - } - - e.token(TokenKind::R_PAREN); -} - -// TRIM([LEADING|TRAILING|BOTH [chars] FROM] string) -fn emit_trim_function(e: &mut EventEmitter, n: &FuncCall) { - assert!( - !n.args.is_empty() && n.args.len() <= 3, - "TRIM function expects 1-3 arguments, got {}", - n.args.len() - ); + for (index, part) in parts.iter().enumerate() { + if index > 0 { + e.token(TokenKind::DOT); + } - e.token(TokenKind::L_PAREN); + let is_unqualified = parts.len() == 1; + let needs_quoting = if is_unqualified { + // `overlay(a, b)` and `substring(a, b)` have a plain-call form in the grammar that + // keeps the name unqualified. + needs_quoting_as_function_or_type_name(part) + && !matches!(*part, "overlay" | "substring") + } else if index == parts.len() - 1 { + // A qualified function name can be any word, keywords included. + needs_quoting_except_keywords(part) + } else { + needs_quoting_as_column_name(part) + }; - if n.args.len() == 1 { - // Simple TRIM(string) - super::emit_node(&n.args[0], e); - } else if n.args.len() == 2 { - // TRIM(chars FROM string) or TRIM(LEADING/TRAILING/BOTH string) - // Second arg is the string, first arg is chars or mode - super::emit_node(&n.args[0], e); - e.space(); - e.token(TokenKind::FROM_KW); - e.space(); - super::emit_node(&n.args[1], e); - } else { - // n.args.len() == 3 - // TRIM(LEADING/TRAILING/BOTH chars FROM string) - // First arg: mode (LEADING/TRAILING/BOTH) - super::emit_node(&n.args[0], e); - e.space(); - // Second arg: chars - super::emit_node(&n.args[1], e); - e.space(); - e.token(TokenKind::FROM_KW); - e.space(); - // Third arg: string - super::emit_node(&n.args[2], e); + if needs_quoting { + emit_identifier(e, part); + } else { + e.token(TokenKind::IDENT((*part).to_string())); + } } - - e.token(TokenKind::R_PAREN); } -/// Check if this is a call to the built-in NORMALIZE function -/// (as opposed to a user-defined function with the same name) -fn is_builtin_normalize(n: &FuncCall) -> bool { - // Built-in NORMALIZE takes 1 or 2 args - if n.args.is_empty() || n.args.len() > 2 { +/// Emits a call written in SQL-standard syntax. Returns false, having emitted nothing, for a shape +/// it does not know, which is then written as a call to the `pg_catalog` function it stands for. +fn emit_sql_syntax_call(e: &mut EventEmitter, n: &FuncCall) -> bool { + let name = match n.funcname.as_slice() { + [schema, name] => match (&schema.node, &name.node) { + (Some(NodeEnum::String(schema)), Some(NodeEnum::String(name))) + if schema.sval == "pg_catalog" => + { + name.sval.as_str() + } + _ => return false, + }, + _ => return false, + }; + let has_modifiers = n.agg_star + || n.agg_distinct + || n.func_variadic + || !n.agg_order.is_empty() + || n.agg_filter.is_some() + || n.over.is_some(); + if has_modifiers { return false; } - // With 2 args, second must be a known normalization form - if n.args.len() == 2 { - if let Some(pgls_query::NodeEnum::AConst(a_const)) = &n.args[1].node - && let Some(pgls_query::protobuf::a_const::Val::Sval(s)) = &a_const.val - { - return matches!(s.sval.as_str(), "NFC" | "NFD" | "NFKC" | "NFKD"); + let args = n.args.as_slice(); + match (name, args) { + ("extract", [field, source]) => { + e.token(TokenKind::EXTRACT_KW); + e.token(TokenKind::L_PAREN); + emit_word_or_literal(e, field); + e.space(); + e.token(TokenKind::FROM_KW); + e.space(); + super::emit_node(source, e); + e.token(TokenKind::R_PAREN); } - return false; - } - - // Single argument is fine for built-in - true -} - -// NORMALIZE(string [, form]) -// The form argument (NFC/NFD/NFKC/NFKD) is an identifier, not a string -fn emit_normalize_function(e: &mut EventEmitter, n: &FuncCall) { - assert!( - !n.args.is_empty() && n.args.len() <= 2, - "NORMALIZE function expects 1 or 2 arguments, got {}", - n.args.len() - ); - - e.token(TokenKind::L_PAREN); - - // First arg: string to normalize - super::emit_node(&n.args[0], e); - - if n.args.len() == 2 { - e.token(TokenKind::COMMA); - e.space(); - // Second arg: normalization form (NFC/NFD/NFKC/NFKD) - // This should be emitted as an identifier, not a string literal - // The form is stored as an AConst node with a string value - let a_const = assert_node_variant!(AConst, &n.args[1]); - if let Some(pgls_query::protobuf::a_const::Val::Sval(s)) = &a_const.val { - // Only emit as identifier if it's a known normalization form - match s.sval.as_str() { - "NFC" | "NFD" | "NFKC" | "NFKD" => { - e.token(TokenKind::IDENT(s.sval.clone())); + ("overlay", [string, replacement, start, rest @ ..]) if rest.len() <= 1 => { + e.token(TokenKind::OVERLAY_KW); + e.token(TokenKind::L_PAREN); + super::emit_node(string, e); + e.space(); + e.token(TokenKind::PLACING_KW); + e.space(); + super::emit_node(replacement, e); + e.space(); + e.token(TokenKind::FROM_KW); + e.space(); + super::emit_node(start, e); + if let [length] = rest { + e.space(); + e.token(TokenKind::FOR_KW); + e.space(); + super::emit_node(length, e); + } + e.token(TokenKind::R_PAREN); + } + // Stored as position(string, substring), written POSITION(substring IN string). Both + // operands are `b_expr`, which an operator expression is not. + ("position", [string, substring]) => { + e.token(TokenKind::POSITION_KW); + e.token(TokenKind::L_PAREN); + emit_parenthesized_unless_simple(e, substring); + e.space(); + e.token(TokenKind::IN_KW); + e.space(); + emit_parenthesized_unless_simple(e, string); + e.token(TokenKind::R_PAREN); + } + ("substring", [string, start, rest @ ..]) if rest.len() <= 1 => { + e.token(TokenKind::SUBSTRING_KW); + e.token(TokenKind::L_PAREN); + super::emit_node(string, e); + e.line(LineType::SoftOrSpace); + e.token(TokenKind::FROM_KW); + e.space(); + super::emit_node(start, e); + if let [length] = rest { + e.line(LineType::SoftOrSpace); + e.token(TokenKind::FOR_KW); + e.space(); + super::emit_node(length, e); + } + e.token(TokenKind::R_PAREN); + } + // Stored as btrim(string[, characters]), written TRIM(BOTH characters FROM string). + ("btrim" | "ltrim" | "rtrim", [string, rest @ ..]) if rest.len() <= 1 => { + e.token(TokenKind::TRIM_KW); + e.token(TokenKind::L_PAREN); + match name { + "ltrim" => { + e.token(TokenKind::LEADING_KW); + e.space(); } - _ => { - // Not a known form, emit as string literal - super::emit_node(&n.args[1], e); + "rtrim" => { + e.token(TokenKind::TRAILING_KW); + e.space(); } + _ => {} } - } else { - super::emit_node(&n.args[1], e); + if let [characters] = rest { + super::emit_node(characters, e); + e.space(); + e.token(TokenKind::FROM_KW); + e.space(); + } + super::emit_node(string, e); + e.token(TokenKind::R_PAREN); + } + ("normalize", [string, rest @ ..]) if rest.len() <= 1 => { + let form = match rest { + [form] => match normalization_form(form) { + Some(form) => Some(form), + None => return false, + }, + _ => None, + }; + e.token(TokenKind::NORMALIZE_KW); + e.token(TokenKind::L_PAREN); + super::emit_node(string, e); + if let Some(form) = form { + e.token(TokenKind::COMMA); + e.space(); + e.token(form); + } + e.token(TokenKind::R_PAREN); + } + ("is_normalized", [string, rest @ ..]) if rest.len() <= 1 => { + let form = match rest { + [form] => match normalization_form(form) { + Some(form) => Some(form), + None => return false, + }, + _ => None, + }; + e.token(TokenKind::L_PAREN); + emit_parenthesized_unless_simple(e, string); + e.space(); + e.token(TokenKind::IS_KW); + e.space(); + if let Some(form) = form { + e.token(form); + e.space(); + } + e.token(TokenKind::NORMALIZED_KW); + e.token(TokenKind::R_PAREN); } + // Stored as timezone(zone, timestamp), written `timestamp AT TIME ZONE zone`. + ("timezone", [zone, timestamp]) => { + e.token(TokenKind::L_PAREN); + emit_parenthesized_unless_simple(e, timestamp); + e.space(); + e.token(TokenKind::AT_KW); + e.space(); + e.token(TokenKind::TIME_KW); + e.space(); + e.token(TokenKind::ZONE_KW); + e.space(); + emit_parenthesized_unless_simple(e, zone); + e.token(TokenKind::R_PAREN); + } + ("timezone", [timestamp]) => { + e.token(TokenKind::L_PAREN); + emit_parenthesized_unless_simple(e, timestamp); + e.space(); + e.token(TokenKind::AT_KW); + e.space(); + e.token(TokenKind::LOCAL_KW); + e.token(TokenKind::R_PAREN); + } + ("overlaps", [start1, end1, start2, end2]) => { + e.token(TokenKind::L_PAREN); + e.token(TokenKind::L_PAREN); + super::emit_node(start1, e); + e.token(TokenKind::COMMA); + e.space(); + super::emit_node(end1, e); + e.token(TokenKind::R_PAREN); + e.space(); + e.token(TokenKind::OVERLAPS_KW); + e.space(); + e.token(TokenKind::L_PAREN); + super::emit_node(start2, e); + e.token(TokenKind::COMMA); + e.space(); + super::emit_node(end2, e); + e.token(TokenKind::R_PAREN); + e.token(TokenKind::R_PAREN); + } + ("pg_collation_for", [expr]) => { + e.token(TokenKind::COLLATION_KW); + e.space(); + e.token(TokenKind::FOR_KW); + e.space(); + e.token(TokenKind::L_PAREN); + super::emit_node(expr, e); + e.token(TokenKind::R_PAREN); + } + // The XML document is a `c_expr`. + ("xmlexists", [xpath, document]) => { + e.token(TokenKind::XMLEXISTS_KW); + e.token(TokenKind::L_PAREN); + super::emit_node(xpath, e); + e.space(); + e.token(TokenKind::PASSING_KW); + e.space(); + emit_parenthesized_unless_simple(e, document); + e.token(TokenKind::R_PAREN); + } + ("system_user", []) => e.token(TokenKind::SYSTEM_USER_KW), + _ => return false, } - e.token(TokenKind::R_PAREN); + true } -// XMLEXISTS(xpath PASSING [BY REF|VALUE] xml) -fn emit_xmlexists_function(e: &mut EventEmitter, n: &FuncCall) { - assert!( - n.args.len() == 2, - "XMLEXISTS function expects 2 arguments, got {}", - n.args.len() - ); - - e.token(TokenKind::L_PAREN); - - // First arg: xpath expression - super::emit_node(&n.args[0], e); +/// The keyword of a Unicode normalization form, stored as the string `NFC`, `NFD`, `NFKC` or `NFKD`. +fn normalization_form(node: &Node) -> Option { + let Some(NodeEnum::AConst(a_const)) = &node.node else { + return None; + }; + let Some(Val::Sval(form)) = &a_const.val else { + return None; + }; + match form.sval.as_str() { + "NFC" => Some(TokenKind::NFC_KW), + "NFD" => Some(TokenKind::NFD_KW), + "NFKC" => Some(TokenKind::NFKC_KW), + "NFKD" => Some(TokenKind::NFKD_KW), + _ => None, + } +} - e.space(); - e.token(TokenKind::PASSING_KW); - e.space(); +/// Emits the field of `EXTRACT`, stored as a string: as the word it was written as when it is one. +fn emit_word_or_literal(e: &mut EventEmitter, node: &Node) { + if let Some(NodeEnum::AConst(a_const)) = &node.node + && let Some(Val::Sval(field)) = &a_const.val + && !needs_quoting(&field.sval) + { + match TokenKind::from_keyword(&field.sval) { + Some(keyword) => e.token(keyword), + None => e.token(TokenKind::IDENT(field.sval.clone())), + } + return; + } - // Second arg: xml value - super::emit_node(&n.args[1], e); + super::emit_node(node, e); +} - e.token(TokenKind::R_PAREN); +/// Emits an operand of SQL-standard syntax, in parentheses unless it is a single term that binds +/// tighter than any operator. +fn emit_parenthesized_unless_simple(e: &mut EventEmitter, node: &Node) { + let is_simple = match &node.node { + Some(NodeEnum::ColumnRef(_) | NodeEnum::ParamRef(_) | NodeEnum::TypeCast(_)) => true, + Some(NodeEnum::FuncCall(call)) => call.funcformat != CoercionForm::CoerceSqlSyntax as i32, + Some(NodeEnum::AConst(a_const)) => match &a_const.val { + Some(Val::Ival(integer)) => integer.ival >= 0, + Some(Val::Fval(float)) => !float.fval.starts_with('-'), + Some(Val::Sval(_) | Val::Bsval(_) | Val::Boolval(_)) => true, + None => true, + }, + _ => false, + }; + + if is_simple { + super::emit_node(node, e); + } else { + e.token(TokenKind::L_PAREN); + super::emit_node(node, e); + e.token(TokenKind::R_PAREN); + } } diff --git a/crates/pgls_pretty_print/src/nodes/grant_role_stmt.rs b/crates/pgls_pretty_print/src/nodes/grant_role_stmt.rs index 9ea98b280..2d1dc65a0 100644 --- a/crates/pgls_pretty_print/src/nodes/grant_role_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/grant_role_stmt.rs @@ -22,14 +22,8 @@ pub(super) fn emit_grant_role_stmt(e: &mut EventEmitter, n: &GrantRoleStmt) { for opt in &n.opt { if let Some(NodeEnum::DefElem(def)) = opt.node.as_ref() { e.space(); - // Emit the option name as uppercase - let opt_name = match def.defname.as_str() { - "admin" => "ADMIN", - "inherit" => "INHERIT", - "set" => "SET", - _ => &def.defname.to_uppercase(), - }; - e.token(TokenKind::IDENT(opt_name.to_string())); + // Emit the option name + super::emit_word(e, &def.defname); e.space(); e.token(TokenKind::OPTION_KW); e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/grant_stmt.rs b/crates/pgls_pretty_print/src/nodes/grant_stmt.rs index 36389b643..bfc809fe2 100644 --- a/crates/pgls_pretty_print/src/nodes/grant_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/grant_stmt.rs @@ -6,6 +6,8 @@ use crate::{ nodes::node_list::emit_comma_separated_list, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_grant_stmt(e: &mut EventEmitter, n: &GrantStmt) { emit_grant_stmt_impl(e, n, true); } @@ -237,14 +239,17 @@ fn emit_access_priv(e: &mut EventEmitter, priv_node: &pgls_query::protobuf::Acce if priv_node.priv_name.is_empty() && !priv_node.cols.is_empty() { e.token(TokenKind::ALL_KW); } else if !priv_node.priv_name.is_empty() { - e.token(TokenKind::IDENT(priv_node.priv_name.to_uppercase())); + for (index, word) in priv_node.priv_name.split(' ').enumerate() { + if index > 0 { + e.space(); + } + super::emit_word(e, word); + } } // Handle column privileges if !priv_node.cols.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &priv_node.cols, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &priv_node.cols, super::emit_node); } } diff --git a/crates/pgls_pretty_print/src/nodes/grouping_set.rs b/crates/pgls_pretty_print/src/nodes/grouping_set.rs index db7d8b838..9be5eafe8 100644 --- a/crates/pgls_pretty_print/src/nodes/grouping_set.rs +++ b/crates/pgls_pretty_print/src/nodes/grouping_set.rs @@ -5,6 +5,7 @@ use crate::{ use pgls_query::protobuf::{GroupingSet, GroupingSetKind}; use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_grouping_set(e: &mut EventEmitter, n: &GroupingSet) { e.group_start(GroupKind::GroupingSet); @@ -13,25 +14,19 @@ pub(super) fn emit_grouping_set(e: &mut EventEmitter, n: &GroupingSet) { kind if kind == GroupingSetKind::GroupingSetRollup as i32 => { e.token(TokenKind::ROLLUP_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.content, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.content, super::emit_node); } kind if kind == GroupingSetKind::GroupingSetCube as i32 => { e.token(TokenKind::CUBE_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.content, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.content, super::emit_node); } kind if kind == GroupingSetKind::GroupingSetSets as i32 => { e.token(TokenKind::GROUPING_KW); e.space(); e.token(TokenKind::SETS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.content, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.content, super::emit_node); } kind if kind == GroupingSetKind::GroupingSetSimple as i32 => { // Simple grouping set: just emit the content without wrapper diff --git a/crates/pgls_pretty_print/src/nodes/import_foreign_schema_stmt.rs b/crates/pgls_pretty_print/src/nodes/import_foreign_schema_stmt.rs index 9567a5ee9..ce48a98ef 100644 --- a/crates/pgls_pretty_print/src/nodes/import_foreign_schema_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/import_foreign_schema_stmt.rs @@ -5,6 +5,8 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_import_foreign_schema_stmt(e: &mut EventEmitter, n: &ImportForeignSchemaStmt) { e.group_start(GroupKind::ImportForeignSchemaStmt); @@ -33,9 +35,7 @@ pub(super) fn emit_import_foreign_schema_stmt(e: &mut EventEmitter, n: &ImportFo e.token(TokenKind::EXCEPT_KW); } e.space(); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.table_list, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.table_list, super::emit_node); } // FROM SERVER @@ -61,12 +61,10 @@ pub(super) fn emit_import_foreign_schema_stmt(e: &mut EventEmitter, n: &ImportFo e.line(LineType::SoftOrSpace); e.token(TokenKind::OPTIONS_KW); e.space(); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.options, |n, e| { + emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); - e.token(TokenKind::R_PAREN); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/index_elem.rs b/crates/pgls_pretty_print/src/nodes/index_elem.rs index db7cdfce9..b40f4045c 100644 --- a/crates/pgls_pretty_print/src/nodes/index_elem.rs +++ b/crates/pgls_pretty_print/src/nodes/index_elem.rs @@ -2,9 +2,11 @@ use pgls_query::protobuf::{IndexElem, SortByDir, SortByNulls}; use crate::{ TokenKind, - emitter::{EventEmitter, GroupKind, LineType}, + emitter::{EventEmitter, GroupKind}, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_index_elem(e: &mut EventEmitter, n: &IndexElem) { e.group_start(GroupKind::IndexElem); @@ -18,9 +20,12 @@ pub(super) fn emit_index_elem(e: &mut EventEmitter, n: &IndexElem) { super::emit_identifier_maybe_quoted(e, &n.name); } + // The clauses after the column stay on its line: after a broken expression, they follow the + // closing parenthesis instead of reading as a column of their own. + // Optional collation if !n.collation.is_empty() { - e.line(LineType::SoftOrSpace); + e.space(); e.token(TokenKind::COLLATE_KW); e.space(); super::node_list::emit_dot_separated_list(e, &n.collation); @@ -28,13 +33,12 @@ pub(super) fn emit_index_elem(e: &mut EventEmitter, n: &IndexElem) { // Optional opclass if !n.opclass.is_empty() { - e.line(LineType::SoftOrSpace); + e.space(); super::node_list::emit_dot_separated_list(e, &n.opclass); // Optional opclass options (e.g., tsvector_ops(siglen = 1000)) if !n.opclassopts.is_empty() { - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.opclassopts, |node, emitter| { + emit_parenthesized_list(e, &n.opclassopts, |node, emitter| { if let Some(pgls_query::NodeEnum::DefElem(def)) = node.node.as_ref() { emitter.token(TokenKind::IDENT(def.defname.clone())); if let Some(ref arg) = def.arg { @@ -45,7 +49,6 @@ pub(super) fn emit_index_elem(e: &mut EventEmitter, n: &IndexElem) { } } }); - e.token(TokenKind::R_PAREN); } } @@ -65,13 +68,13 @@ pub(super) fn emit_index_elem(e: &mut EventEmitter, n: &IndexElem) { // NULLS FIRST/LAST match n.nulls_ordering() { SortByNulls::SortbyNullsFirst => { - e.line(LineType::SoftOrSpace); + e.space(); e.token(TokenKind::NULLS_KW); e.space(); e.token(TokenKind::FIRST_KW); } SortByNulls::SortbyNullsLast => { - e.line(LineType::SoftOrSpace); + e.space(); e.token(TokenKind::NULLS_KW); e.space(); e.token(TokenKind::LAST_KW); diff --git a/crates/pgls_pretty_print/src/nodes/index_stmt.rs b/crates/pgls_pretty_print/src/nodes/index_stmt.rs index b75071cd0..80ec5e9fb 100644 --- a/crates/pgls_pretty_print/src/nodes/index_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/index_stmt.rs @@ -2,10 +2,11 @@ use pgls_query::protobuf::IndexStmt; use crate::{ TokenKind, - emitter::{EventEmitter, GroupKind}, - nodes::node_list::emit_comma_separated_list, + emitter::{EventEmitter, GroupKind, LineType}, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_index_stmt(e: &mut EventEmitter, n: &IndexStmt) { emit_index_stmt_impl(e, n, true); } @@ -17,26 +18,27 @@ pub(super) fn emit_index_stmt_no_semicolon(e: &mut EventEmitter, n: &IndexStmt) fn emit_index_stmt_impl(e: &mut EventEmitter, n: &IndexStmt, with_semicolon: bool) { e.group_start(GroupKind::IndexStmt); - // Inner group for CREATE INDEX name (allows this to stay on one line) + // The head, up to the opening parenthesis of the columns, stays on one line when it fits. The + // columns break inside their parentheses, and the clauses after them each start a line when + // they do not fit. e.group_start(GroupKind::IndexStmt); - e.token(TokenKind::CREATE_KW); e.space(); if n.unique { e.token(TokenKind::UNIQUE_KW); - e.line(crate::emitter::LineType::SoftOrSpace); + e.space(); } e.token(TokenKind::INDEX_KW); if n.concurrent { - e.line(crate::emitter::LineType::SoftOrSpace); + e.space(); e.token(TokenKind::CONCURRENTLY_KW); } if n.if_not_exists { - e.line(crate::emitter::LineType::SoftOrSpace); + e.space(); e.token(TokenKind::IF_KW); e.space(); e.token(TokenKind::NOT_KW); @@ -47,14 +49,14 @@ fn emit_index_stmt_impl(e: &mut EventEmitter, n: &IndexStmt, with_semicolon: boo // Index name if !n.idxname.is_empty() { e.space(); - super::emit_identifier(e, &n.idxname); + super::emit_identifier_maybe_quoted(e, &n.idxname); } - e.group_end(); // End CREATE INDEX name group + e.indent_start(); // ON table if let Some(ref relation) = n.relation { - e.line(crate::emitter::LineType::SoftOrSpace); + e.line(LineType::SoftOrSpace); e.token(TokenKind::ON_KW); e.space(); super::emit_range_var(e, relation); @@ -62,26 +64,23 @@ fn emit_index_stmt_impl(e: &mut EventEmitter, n: &IndexStmt, with_semicolon: boo // USING access_method if !n.access_method.is_empty() { - e.line(crate::emitter::LineType::SoftOrSpace); + e.line(LineType::SoftOrSpace); e.token(TokenKind::USING_KW); e.space(); super::emit_identifier_maybe_quoted(e, &n.access_method); } + e.indent_end(); + e.group_end(); + // Index columns/expressions if !n.index_params.is_empty() { - e.line(crate::emitter::LineType::SoftOrSpace); - e.token(TokenKind::L_PAREN); - e.indent_start(); - e.line(crate::emitter::LineType::Soft); - emit_comma_separated_list(e, &n.index_params, super::emit_node); - e.indent_end(); - e.line(crate::emitter::LineType::Soft); - e.token(TokenKind::R_PAREN); + e.space(); + emit_parenthesized_list(e, &n.index_params, super::emit_node); } if n.nulls_not_distinct { - e.line(crate::emitter::LineType::SoftOrSpace); + e.line(LineType::SoftOrSpace); e.token(TokenKind::NULLS_KW); e.space(); e.token(TokenKind::NOT_KW); @@ -91,37 +90,35 @@ fn emit_index_stmt_impl(e: &mut EventEmitter, n: &IndexStmt, with_semicolon: boo // INCLUDE columns if !n.index_including_params.is_empty() { - e.line(crate::emitter::LineType::SoftOrSpace); + e.line(LineType::SoftOrSpace); e.token(TokenKind::INCLUDE_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.index_including_params, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.index_including_params, super::emit_node); } // WITH options if !n.options.is_empty() { - e.line(crate::emitter::LineType::Hard); + super::emit_layout_break(e); e.token(TokenKind::WITH_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); } // TABLESPACE if !n.table_space.is_empty() { - e.line(crate::emitter::LineType::Hard); + super::emit_layout_break(e); e.token(TokenKind::TABLESPACE_KW); e.space(); super::emit_identifier_maybe_quoted(e, &n.table_space); } - // WHERE clause (partial index) + // WHERE clause (partial index), kept on its keyword line when it fits there if let Some(ref where_clause) = n.where_clause { - e.line(crate::emitter::LineType::Hard); + super::emit_layout_break(e); + e.group_start(GroupKind::IndexStmt); e.token(TokenKind::WHERE_KW); super::emit_clause_condition(e, where_clause); + e.group_end(); } if with_semicolon { diff --git a/crates/pgls_pretty_print/src/nodes/infer_clause.rs b/crates/pgls_pretty_print/src/nodes/infer_clause.rs index ba4f379ba..5e0215ae2 100644 --- a/crates/pgls_pretty_print/src/nodes/infer_clause.rs +++ b/crates/pgls_pretty_print/src/nodes/infer_clause.rs @@ -5,7 +5,8 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::{node_list::emit_comma_separated_list, string::emit_identifier_maybe_quoted}; +use super::node_list::emit_parenthesized_list; +use super::string::emit_identifier_maybe_quoted; pub(super) fn emit_infer_clause(e: &mut EventEmitter, n: &InferClause) { e.group_start(GroupKind::InferClause); @@ -17,9 +18,7 @@ pub(super) fn emit_infer_clause(e: &mut EventEmitter, n: &InferClause) { e.space(); emit_identifier_maybe_quoted(e, &n.conname); } else if !n.index_elems.is_empty() { - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.index_elems, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.index_elems, super::emit_node); } if let Some(ref where_clause) = n.where_clause { diff --git a/crates/pgls_pretty_print/src/nodes/inline_code_block.rs b/crates/pgls_pretty_print/src/nodes/inline_code_block.rs index f0d79f493..2f1e36918 100644 --- a/crates/pgls_pretty_print/src/nodes/inline_code_block.rs +++ b/crates/pgls_pretty_print/src/nodes/inline_code_block.rs @@ -2,14 +2,14 @@ use pgls_query::protobuf::InlineCodeBlock; use crate::emitter::{EventEmitter, GroupKind}; -use super::string::{DollarQuoteHint, emit_dollar_quoted_str_with_hint}; +use super::string::{DollarQuoteHint, emit_body_literal}; pub(super) fn emit_inline_code_block(e: &mut EventEmitter, n: &InlineCodeBlock) { e.group_start(GroupKind::InlineCodeBlock); if !n.source_text.is_empty() { // InlineCodeBlock is typically used for anonymous code blocks (like DO) - emit_dollar_quoted_str_with_hint(e, &n.source_text, DollarQuoteHint::Do); + emit_body_literal(e, &n.source_text, -1, DollarQuoteHint::Do); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/int_list.rs b/crates/pgls_pretty_print/src/nodes/int_list.rs index 890789383..63c1f17c0 100644 --- a/crates/pgls_pretty_print/src/nodes/int_list.rs +++ b/crates/pgls_pretty_print/src/nodes/int_list.rs @@ -1,16 +1,13 @@ use pgls_query::protobuf::IntList; -use crate::{ - TokenKind, - emitter::{EventEmitter, GroupKind}, -}; +use crate::emitter::{EventEmitter, GroupKind}; + +use super::node_list::emit_parenthesized_list; pub(super) fn emit_int_list(e: &mut EventEmitter, n: &IntList) { e.group_start(GroupKind::IntList); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.items, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.items, super::emit_node); e.group_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/join_expr.rs b/crates/pgls_pretty_print/src/nodes/join_expr.rs index 6090354cd..491f57cbc 100644 --- a/crates/pgls_pretty_print/src/nodes/join_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/join_expr.rs @@ -4,7 +4,8 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; use super::node_list::emit_comma_separated_list; -use super::string::emit_identifier; +use super::node_list::emit_parenthesized_list; +use super::string::emit_identifier_maybe_quoted; pub(super) fn emit_join_expr(e: &mut EventEmitter, n: &JoinExpr) { e.group_start(GroupKind::JoinExpr); @@ -109,7 +110,7 @@ pub(super) fn emit_join_expr(e: &mut EventEmitter, n: &JoinExpr) { emit_comma_separated_list(e, &n.using_clause, |node, e| { // For USING clause, String nodes should be identifiers if let Some(pgls_query::NodeEnum::String(s)) = node.node.as_ref() { - emit_identifier(e, &s.sval); + emit_identifier_maybe_quoted(e, &s.sval); } else { super::emit_node(node, e); } @@ -118,7 +119,7 @@ pub(super) fn emit_join_expr(e: &mut EventEmitter, n: &JoinExpr) { } else { emit_comma_separated_list(e, &n.using_clause, |node, e| { if let Some(pgls_query::NodeEnum::String(s)) = node.node.as_ref() { - emit_identifier(e, &s.sval); + emit_identifier_maybe_quoted(e, &s.sval); } else { super::emit_node(node, e); } @@ -132,7 +133,7 @@ pub(super) fn emit_join_expr(e: &mut EventEmitter, n: &JoinExpr) { e.space(); e.token(TokenKind::AS_KW); e.space(); - emit_identifier(e, &using_alias.aliasname); + emit_identifier_maybe_quoted(e, &using_alias.aliasname); } } else if let Some(ref quals) = n.quals { e.line(LineType::SoftOrSpace); @@ -157,20 +158,18 @@ pub(super) fn emit_join_expr(e: &mut EventEmitter, n: &JoinExpr) { e.space(); e.token(TokenKind::AS_KW); e.space(); - emit_identifier(e, &alias.aliasname); + emit_identifier_maybe_quoted(e, &alias.aliasname); // Emit column aliases if present if !alias.colnames.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &alias.colnames, |node, emitter| { + emit_parenthesized_list(e, &alias.colnames, |node, emitter| { if let Some(pgls_query::NodeEnum::String(s)) = node.node.as_ref() { - emit_identifier(emitter, &s.sval); + emit_identifier_maybe_quoted(emitter, &s.sval); } else { super::emit_node(node, emitter); } }); - e.token(TokenKind::R_PAREN); } } diff --git a/crates/pgls_pretty_print/src/nodes/json_value_expr.rs b/crates/pgls_pretty_print/src/nodes/json_value_expr.rs index 7819f663e..b02a38a61 100644 --- a/crates/pgls_pretty_print/src/nodes/json_value_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/json_value_expr.rs @@ -94,7 +94,7 @@ fn emit_json_format_with_prefix(e: &mut EventEmitter, format: &JsonFormat, prefi } e.token(TokenKind::FORMAT_KW); e.space(); - e.token(TokenKind::IDENT("JSONB".to_string())); + super::emit_word(e, "jsonb"); wrote_any = true; } JsonFormatType::Undefined | JsonFormatType::JsFormatDefault => {} @@ -135,5 +135,5 @@ fn emit_encoding(e: &mut EventEmitter, label: &str, needs_space: bool) { } e.token(TokenKind::ENCODING_KW); e.space(); - e.token(TokenKind::IDENT(label.to_string())); + super::emit_word(e, label); } diff --git a/crates/pgls_pretty_print/src/nodes/lock_stmt.rs b/crates/pgls_pretty_print/src/nodes/lock_stmt.rs index 8845eb04f..dfabeb6fb 100644 --- a/crates/pgls_pretty_print/src/nodes/lock_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/lock_stmt.rs @@ -42,7 +42,7 @@ pub(super) fn emit_lock_stmt(e: &mut EventEmitter, n: &LockStmt) { 8 => "ACCESS EXCLUSIVE", _ => "ACCESS EXCLUSIVE", // default }; - e.token(TokenKind::IDENT(mode_str.to_string())); + super::emit_words(e, mode_str); e.space(); e.token(TokenKind::MODE_KW); } diff --git a/crates/pgls_pretty_print/src/nodes/mod.rs b/crates/pgls_pretty_print/src/nodes/mod.rs index 28394e48f..b2f44f645 100644 --- a/crates/pgls_pretty_print/src/nodes/mod.rs +++ b/crates/pgls_pretty_print/src/nodes/mod.rs @@ -492,8 +492,8 @@ use sort_group_clause::emit_sort_group_clause; use sql_value_function::emit_sql_value_function; use stats_elem::emit_stats_elem; use string::{ - DollarQuoteHint, emit_dollar_quoted_str_with_hint, emit_identifier, - emit_identifier_maybe_quoted, emit_string, emit_string_identifier, emit_string_literal, + DollarQuoteHint, emit_body_literal, emit_identifier, emit_identifier_maybe_quoted, emit_string, + emit_string_identifier, emit_string_literal, emit_word, emit_words, }; use sub_link::emit_sub_link; use sub_plan::{emit_alternative_sub_plan, emit_sub_plan}; @@ -937,6 +937,7 @@ mod tests { text: "-- note".to_string(), line_comment: true, own_line: true, + after_separator: false, }; let leading = HashMap::from([(7, vec![comment])]); let mut e = EventEmitter::with_comments(Default::default(), leading, HashMap::new()); diff --git a/crates/pgls_pretty_print/src/nodes/named_arg_expr.rs b/crates/pgls_pretty_print/src/nodes/named_arg_expr.rs index 7eb39c263..6aa6e3723 100644 --- a/crates/pgls_pretty_print/src/nodes/named_arg_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/named_arg_expr.rs @@ -10,7 +10,7 @@ pub(super) fn emit_named_arg_expr(e: &mut EventEmitter, n: &NamedArgExpr) { // Emit the argument name if !n.name.is_empty() { - super::emit_identifier(e, &n.name); + super::emit_identifier_maybe_quoted(e, &n.name); e.space(); e.token(TokenKind::IDENT(":=".to_string())); e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/node_list.rs b/crates/pgls_pretty_print/src/nodes/node_list.rs index 4ed9074c3..0ca39bd6c 100644 --- a/crates/pgls_pretty_print/src/nodes/node_list.rs +++ b/crates/pgls_pretty_print/src/nodes/node_list.rs @@ -1,6 +1,6 @@ use pgls_query::Node; -use crate::emitter::{EventEmitter, LineType}; +use crate::emitter::{EventEmitter, GroupKind, LineType}; use crate::{CommaStyle, TokenKind}; /// Controls the spacing behavior after separators in list helpers @@ -63,6 +63,23 @@ where emit_comma_separated_list_with_spacing(e, nodes, ListSeparatorSpacing::SoftOrSpace, render); } +/// Emits `(a, b, c)`: on one line when it fits, otherwise with each item on its own line, one level +/// deeper, and the closing parenthesis back on its own line. +pub(super) fn emit_parenthesized_list(e: &mut EventEmitter, nodes: &[Node], render: F) +where + F: Fn(&Node, &mut EventEmitter), +{ + e.group_start(GroupKind::List); + e.token(TokenKind::L_PAREN); + e.indent_start(); + e.line(LineType::Soft); + emit_comma_separated_list(e, nodes, render); + e.indent_end(); + e.line(LineType::Soft); + e.token(TokenKind::R_PAREN); + e.group_end(); +} + /// Emit a comma-separated list that packs as many items as possible on each line. pub(super) fn emit_fill_comma_separated_list(e: &mut EventEmitter, nodes: &[Node], render: F) where diff --git a/crates/pgls_pretty_print/src/nodes/notify_stmt.rs b/crates/pgls_pretty_print/src/nodes/notify_stmt.rs index abda6611e..0e721faa8 100644 --- a/crates/pgls_pretty_print/src/nodes/notify_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/notify_stmt.rs @@ -14,7 +14,7 @@ pub(super) fn emit_notify_stmt(e: &mut EventEmitter, n: &NotifyStmt) { if !n.conditionname.is_empty() { e.space(); - super::emit_identifier(e, &n.conditionname); + super::emit_identifier_maybe_quoted(e, &n.conditionname); } // Optional payload diff --git a/crates/pgls_pretty_print/src/nodes/object_with_args.rs b/crates/pgls_pretty_print/src/nodes/object_with_args.rs index 51dccf0f5..cc6529140 100644 --- a/crates/pgls_pretty_print/src/nodes/object_with_args.rs +++ b/crates/pgls_pretty_print/src/nodes/object_with_args.rs @@ -35,20 +35,26 @@ fn emit_object_with_args_impl( if with_parens { let space_before_paren = needs_space_before_paren(n); - // Function arguments (for DROP FUNCTION, etc.) - if !n.objargs.is_empty() { + // A function signature keeps its parameters as written, with their names and modes. + // `objargs` only holds their types, and is all an operator has. + let args = if n.objfuncargs.is_empty() { + &n.objargs + } else { + &n.objfuncargs + }; + if !args.is_empty() { if space_before_paren { e.space(); } e.token(TokenKind::L_PAREN); - if n.objargs.len() > 1 { + if args.len() > 1 { e.indent_start(); e.line(LineType::Soft); // For operators, NONE is represented by a Node with node: None - emit_comma_separated_list(e, &n.objargs, emit_objarg_or_none); + emit_comma_separated_list(e, args, emit_objarg_or_none); e.indent_end(); } else { - emit_comma_separated_list(e, &n.objargs, emit_objarg_or_none); + emit_comma_separated_list(e, args, emit_objarg_or_none); } e.token(TokenKind::R_PAREN); } else if !n.args_unspecified { diff --git a/crates/pgls_pretty_print/src/nodes/oid_list.rs b/crates/pgls_pretty_print/src/nodes/oid_list.rs index a11bac9f7..bdb439f52 100644 --- a/crates/pgls_pretty_print/src/nodes/oid_list.rs +++ b/crates/pgls_pretty_print/src/nodes/oid_list.rs @@ -1,16 +1,13 @@ use pgls_query::protobuf::OidList; -use crate::{ - TokenKind, - emitter::{EventEmitter, GroupKind}, -}; +use crate::emitter::{EventEmitter, GroupKind}; + +use super::node_list::emit_parenthesized_list; pub(super) fn emit_oid_list(e: &mut EventEmitter, n: &OidList) { e.group_start(GroupKind::OidList); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.items, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.items, super::emit_node); e.group_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/on_conflict_expr.rs b/crates/pgls_pretty_print/src/nodes/on_conflict_expr.rs index 5ef72561f..d9bed90a7 100644 --- a/crates/pgls_pretty_print/src/nodes/on_conflict_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/on_conflict_expr.rs @@ -4,6 +4,8 @@ use crate::{ }; use pgls_query::protobuf::{OnConflictAction, OnConflictExpr}; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_on_conflict_expr(e: &mut EventEmitter, n: &OnConflictExpr) { e.group_start(GroupKind::OnConflictExpr); @@ -13,9 +15,7 @@ pub(super) fn emit_on_conflict_expr(e: &mut EventEmitter, n: &OnConflictExpr) { if !n.arbiter_elems.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.arbiter_elems, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.arbiter_elems, super::emit_node); } if n.constraint != 0 { diff --git a/crates/pgls_pretty_print/src/nodes/partition_bound_spec.rs b/crates/pgls_pretty_print/src/nodes/partition_bound_spec.rs index 20402c46a..c1eeaee32 100644 --- a/crates/pgls_pretty_print/src/nodes/partition_bound_spec.rs +++ b/crates/pgls_pretty_print/src/nodes/partition_bound_spec.rs @@ -5,7 +5,7 @@ use crate::{ emitter::{EventEmitter, GroupKind}, }; -use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_partition_bound_spec(e: &mut EventEmitter, n: &PartitionBoundSpec) { e.group_start(GroupKind::PartitionBoundSpec); @@ -33,17 +33,13 @@ pub(super) fn emit_partition_bound_spec(e: &mut EventEmitter, n: &PartitionBound e.space(); e.token(TokenKind::FROM_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.lowerdatums, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.lowerdatums, super::emit_node); } if !n.upperdatums.is_empty() { e.space(); e.token(TokenKind::TO_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.upperdatums, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.upperdatums, super::emit_node); } } "l" => { @@ -51,9 +47,7 @@ pub(super) fn emit_partition_bound_spec(e: &mut EventEmitter, n: &PartitionBound e.space(); e.token(TokenKind::IN_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.listdatums, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.listdatums, super::emit_node); } "h" => { // HASH partition @@ -61,12 +55,12 @@ pub(super) fn emit_partition_bound_spec(e: &mut EventEmitter, n: &PartitionBound e.token(TokenKind::WITH_KW); e.space(); e.token(TokenKind::L_PAREN); - e.token(TokenKind::IDENT("MODULUS".to_string())); + super::emit_word(e, "modulus"); e.space(); e.token(TokenKind::IDENT(n.modulus.to_string())); e.token(TokenKind::COMMA); e.space(); - e.token(TokenKind::IDENT("REMAINDER".to_string())); + super::emit_word(e, "remainder"); e.space(); e.token(TokenKind::IDENT(n.remainder.to_string())); e.token(TokenKind::R_PAREN); diff --git a/crates/pgls_pretty_print/src/nodes/partition_spec.rs b/crates/pgls_pretty_print/src/nodes/partition_spec.rs index f161b743e..7f072d469 100644 --- a/crates/pgls_pretty_print/src/nodes/partition_spec.rs +++ b/crates/pgls_pretty_print/src/nodes/partition_spec.rs @@ -3,7 +3,7 @@ use pgls_query::protobuf::PartitionSpec; use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind}; -use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_partition_spec(e: &mut EventEmitter, n: &PartitionSpec) { e.group_start(GroupKind::PartitionSpec); @@ -16,17 +16,15 @@ pub(super) fn emit_partition_spec(e: &mut EventEmitter, n: &PartitionSpec) { // Emit partition strategy // PartitionStrategy: Undefined = 0, List = 1, Range = 2, Hash = 3 match n.strategy { - 1 => e.token(TokenKind::IDENT("LIST".to_string())), + 1 => super::emit_word(e, "list"), 2 => e.token(TokenKind::RANGE_KW), - 3 => e.token(TokenKind::IDENT("HASH".to_string())), + 3 => super::emit_word(e, "hash"), _ => {} } // Emit partition parameters (columns/expressions) if !n.part_params.is_empty() { - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.part_params, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.part_params, super::emit_node); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/pl_assign_stmt.rs b/crates/pgls_pretty_print/src/nodes/pl_assign_stmt.rs index 8c833061e..3050362e6 100644 --- a/crates/pgls_pretty_print/src/nodes/pl_assign_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/pl_assign_stmt.rs @@ -8,7 +8,7 @@ pub(super) fn emit_pl_assign_stmt(e: &mut EventEmitter, n: &PlAssignStmt) { e.group_start(GroupKind::PlassignStmt); if !n.name.is_empty() { - super::emit_identifier(e, &n.name); + super::emit_identifier_maybe_quoted(e, &n.name); } for indirection in &n.indirection { diff --git a/crates/pgls_pretty_print/src/nodes/prepare_stmt.rs b/crates/pgls_pretty_print/src/nodes/prepare_stmt.rs index a34d3af2e..369ae7bdf 100644 --- a/crates/pgls_pretty_print/src/nodes/prepare_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/prepare_stmt.rs @@ -3,9 +3,10 @@ use pgls_query::protobuf::PrepareStmt; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_prepare_stmt(e: &mut EventEmitter, n: &PrepareStmt) { e.group_start(GroupKind::PrepareStmt); @@ -20,9 +21,7 @@ pub(super) fn emit_prepare_stmt(e: &mut EventEmitter, n: &PrepareStmt) { // Argument types if !n.argtypes.is_empty() { e.line(LineType::SoftOrSpace); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.argtypes, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.argtypes, super::emit_node); } // AS query diff --git a/crates/pgls_pretty_print/src/nodes/publication_table.rs b/crates/pgls_pretty_print/src/nodes/publication_table.rs index 1cb3ede8c..0281db1b1 100644 --- a/crates/pgls_pretty_print/src/nodes/publication_table.rs +++ b/crates/pgls_pretty_print/src/nodes/publication_table.rs @@ -4,6 +4,8 @@ use crate::{ }; use pgls_query::protobuf::PublicationTable; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_publication_table(e: &mut EventEmitter, n: &PublicationTable) { e.group_start(GroupKind::PublicationTable); @@ -13,9 +15,7 @@ pub(super) fn emit_publication_table(e: &mut EventEmitter, n: &PublicationTable) if !n.columns.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.columns, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.columns, super::emit_node); } if let Some(ref where_clause) = n.where_clause { diff --git a/crates/pgls_pretty_print/src/nodes/range_function.rs b/crates/pgls_pretty_print/src/nodes/range_function.rs index 70f1a5c4d..1aa9875c1 100644 --- a/crates/pgls_pretty_print/src/nodes/range_function.rs +++ b/crates/pgls_pretty_print/src/nodes/range_function.rs @@ -4,6 +4,7 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; /// Emits a function of a `FROM` item. A cast there must keep the `CAST(...)` spelling. fn emit_function(e: &mut EventEmitter, node: &pgls_query::Node) { @@ -48,9 +49,7 @@ pub(super) fn emit_range_function(e: &mut EventEmitter, n: &RangeFunction) { e.space(); e.token(TokenKind::AS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &col_defs, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &col_defs, super::emit_node); } } } else { diff --git a/crates/pgls_pretty_print/src/nodes/range_table_func.rs b/crates/pgls_pretty_print/src/nodes/range_table_func.rs index 238a76703..93f730817 100644 --- a/crates/pgls_pretty_print/src/nodes/range_table_func.rs +++ b/crates/pgls_pretty_print/src/nodes/range_table_func.rs @@ -5,6 +5,8 @@ use crate::{ }; use pgls_query::{NodeEnum, protobuf::RangeTableFunc}; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_range_table_func(e: &mut EventEmitter, n: &RangeTableFunc) { e.group_start(GroupKind::RangeTableFunc); @@ -23,8 +25,7 @@ pub(super) fn emit_range_table_func(e: &mut EventEmitter, n: &RangeTableFunc) { if !n.namespaces.is_empty() { e.line(LineType::SoftOrSpace); e.token(TokenKind::XMLNAMESPACES_KW); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.namespaces, |node, emitter| { + emit_parenthesized_list(e, &n.namespaces, |node, emitter| { // Each namespace is a ResTarget with val=URI, name=prefix // If name is empty, it's a DEFAULT namespace if let Some(NodeEnum::ResTarget(rt)) = node.node.as_ref() { @@ -49,7 +50,6 @@ pub(super) fn emit_range_table_func(e: &mut EventEmitter, n: &RangeTableFunc) { super::emit_node(node, emitter); } }); - e.token(TokenKind::R_PAREN); e.token(TokenKind::COMMA); } diff --git a/crates/pgls_pretty_print/src/nodes/range_table_sample.rs b/crates/pgls_pretty_print/src/nodes/range_table_sample.rs index 3360bd57e..b926b850f 100644 --- a/crates/pgls_pretty_print/src/nodes/range_table_sample.rs +++ b/crates/pgls_pretty_print/src/nodes/range_table_sample.rs @@ -1,10 +1,12 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::{node_list::emit_comma_separated_list, node_list::emit_dot_separated_list}, + nodes::node_list::emit_dot_separated_list, }; use pgls_query::protobuf::RangeTableSample; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_range_table_sample(e: &mut EventEmitter, n: &RangeTableSample) { e.group_start(GroupKind::RangeTableSample); @@ -23,9 +25,7 @@ pub(super) fn emit_range_table_sample(e: &mut EventEmitter, n: &RangeTableSample // Arguments for the sampling method if !n.args.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.args, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.args, super::emit_node); } // REPEATABLE clause diff --git a/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs b/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs index b39d219b5..33565acb1 100644 --- a/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs @@ -3,9 +3,10 @@ use pgls_query::{NodeEnum, protobuf::ReindexStmt}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, }; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_reindex_stmt(e: &mut EventEmitter, n: &ReindexStmt) { e.group_start(GroupKind::ReindexStmt); @@ -14,11 +15,10 @@ pub(super) fn emit_reindex_stmt(e: &mut EventEmitter, n: &ReindexStmt) { // Handle options (CONCURRENTLY, VERBOSE, TABLESPACE, etc.) if !n.params.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.params, |node, emitter| { + emit_parenthesized_list(e, &n.params, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { // Emit option name - emitter.token(TokenKind::IDENT(def.defname.to_uppercase())); + super::emit_word(emitter, &def.defname); // Emit option value if present if let Some(ref arg) = def.arg { emitter.space(); @@ -28,7 +28,6 @@ pub(super) fn emit_reindex_stmt(e: &mut EventEmitter, n: &ReindexStmt) { super::emit_node(node, emitter); } }); - e.token(TokenKind::R_PAREN); } e.line(LineType::SoftOrSpace); diff --git a/crates/pgls_pretty_print/src/nodes/row_compare_expr.rs b/crates/pgls_pretty_print/src/nodes/row_compare_expr.rs index 9a4bc15d2..e4009a914 100644 --- a/crates/pgls_pretty_print/src/nodes/row_compare_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/row_compare_expr.rs @@ -1,16 +1,15 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, - nodes::node_list::emit_comma_separated_list, }; use pgls_query::protobuf::{RowCompareExpr, RowCompareType}; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_row_compare_expr(e: &mut EventEmitter, n: &RowCompareExpr) { e.group_start(GroupKind::RowCompareExpr); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.largs, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.largs, super::emit_node); e.space(); @@ -30,9 +29,7 @@ pub(super) fn emit_row_compare_expr(e: &mut EventEmitter, n: &RowCompareExpr) { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.rargs, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.rargs, super::emit_node); e.group_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/row_expr.rs b/crates/pgls_pretty_print/src/nodes/row_expr.rs index 4ce031792..bfac6fdef 100644 --- a/crates/pgls_pretty_print/src/nodes/row_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/row_expr.rs @@ -5,7 +5,7 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_row_expr(e: &mut EventEmitter, n: &RowExpr) { e.group_start(GroupKind::RowExpr); @@ -20,17 +20,13 @@ pub(super) fn emit_row_expr(e: &mut EventEmitter, n: &RowExpr) { e.token(TokenKind::ROW_KW); } - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.args, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.args, super::emit_node); if !n.colnames.is_empty() { e.line(LineType::SoftOrSpace); e.token(TokenKind::AS_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.colnames, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.colnames, super::emit_node); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/stats_elem.rs b/crates/pgls_pretty_print/src/nodes/stats_elem.rs index 4c71297c0..8daa699df 100644 --- a/crates/pgls_pretty_print/src/nodes/stats_elem.rs +++ b/crates/pgls_pretty_print/src/nodes/stats_elem.rs @@ -12,7 +12,7 @@ pub(super) fn emit_stats_elem(e: &mut EventEmitter, n: &StatsElem) { super::emit_node(expr, e); e.token(TokenKind::R_PAREN); } else if !n.name.is_empty() { - super::emit_identifier(e, &n.name); + super::emit_identifier_maybe_quoted(e, &n.name); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/string.rs b/crates/pgls_pretty_print/src/nodes/string.rs index 3a8bcf4e8..0f4838715 100644 --- a/crates/pgls_pretty_print/src/nodes/string.rs +++ b/crates/pgls_pretty_print/src/nodes/string.rs @@ -2,90 +2,10 @@ use pgls_query::protobuf::String as PgString; use crate::{ TokenKind, - emitter::{EventEmitter, GroupKind, LineType}, + codegen::token_kind::{KeywordCategory, keyword_category}, + emitter::{EventEmitter, GroupKind}, }; -const RESERVED_KEYWORDS: &[&str] = &[ - "all", - "analyse", - "analyze", - "and", - "any", - "array", - "as", - "asc", - "asymmetric", - "both", - "case", - "cast", - "check", - "collate", - "column", - "constraint", - "create", - "current_catalog", - "current_date", - "current_role", - "current_time", - "current_timestamp", - "current_user", - "default", - "deferrable", - "desc", - "distinct", - "do", - "else", - "end", - "except", - "false", - "fetch", - "for", - "foreign", - "from", - "grant", - "group", - "having", - "in", - "initially", - "intersect", - "into", - "lateral", - "leading", - "limit", - "localtime", - "localtimestamp", - "not", - "null", - "offset", - "on", - "only", - "or", - "order", - "placing", - "primary", - "references", - "returning", - "select", - "session_user", - "some", - "symmetric", - "system_user", - "table", - "then", - "to", - "trailing", - "true", - "union", - "unique", - "user", - "using", - "variadic", - "when", - "where", - "window", - "with", -]; - pub(super) fn emit_string(e: &mut EventEmitter, n: &PgString) { e.group_start(GroupKind::String); emit_identifier_maybe_quoted(e, &n.sval); @@ -122,7 +42,7 @@ pub(super) fn emit_identifier_maybe_quoted(e: &mut EventEmitter, value: &str) { return; } - if needs_quoting(value) { + if needs_quoting_as_column_name(value) { emit_identifier(e, value); } else { e.token(TokenKind::IDENT(value.to_string())); @@ -145,11 +65,25 @@ pub(super) fn emit_type_identifier_maybe_quoted(e: &mut EventEmitter, value: &st } } +/// Emits a word the grammar reads case-insensitively, such as an option name, in the keyword case. +pub(super) fn emit_word(e: &mut EventEmitter, word: &str) { + match TokenKind::from_keyword(word) { + Some(keyword) => e.token(keyword), + None => e.token(TokenKind::WORD(word.to_string())), + } +} + pub(super) fn emit_keyword(e: &mut EventEmitter, keyword: &str) { - if let Some(token) = TokenKind::from_keyword(keyword) { - e.token(token); - } else { - e.token(TokenKind::IDENT(keyword.to_string())); + emit_word(e, keyword); +} + +/// Emits words separated by spaces, such as `ACCESS EXCLUSIVE`, in the keyword case. +pub(super) fn emit_words(e: &mut EventEmitter, words: &str) { + for (index, word) in words.split(' ').enumerate() { + if index > 0 { + e.space(); + } + emit_word(e, word); } } @@ -170,24 +104,62 @@ pub enum DollarQuoteHint { Do, } -pub(super) fn emit_dollar_quoted_str_with_hint( +/// Emits a function or `DO` body, whose string literal starts at or after `location`. +/// +/// A body that still reads as it does in the source is written back exactly as it was quoted +/// there, so the tag of `$$ ... $$` and every byte in between survive formatting. A body that +/// changed, or whose source is unknown, is dollar-quoted verbatim: with the tag of the source +/// literal when the new body allows it, or with a tag picked from `hint`. +pub(super) fn emit_body_literal( e: &mut EventEmitter, value: &str, + location: i32, hint: DollarQuoteHint, ) { - let delimiter = pick_dollar_delimiter(value, hint); - // Trim leading/trailing whitespace from the body for cleaner formatting, - // then emit: delimiter, newline, body, newline, delimiter - // This puts the function body on its own lines for readability - let trimmed_body = value.trim(); + let source_literal = e.source_string_literal_from(location); + + if let Some(literal) = source_literal + && decode_literal(literal).as_deref() == Some(value) + { + e.token(TokenKind::STRING(literal.to_string())); + return; + } + + let delimiter = source_literal + .and_then(dollar_quote_tag) + .filter(|tag| can_dollar_quote(value, tag)) + .map(str::to_string) + .unwrap_or_else(|| pick_dollar_delimiter(value, hint)); e.token(TokenKind::DOLLAR_QUOTE_DELIMITER(delimiter.clone())); - e.line(LineType::Hard); - e.token(TokenKind::DOLLAR_QUOTE_BODY(trimmed_body.to_string())); - e.line(LineType::Hard); + e.token(TokenKind::DOLLAR_QUOTE_BODY(value.to_string())); e.token(TokenKind::DOLLAR_QUOTE_DELIMITER(delimiter)); } -fn needs_quoting(value: &str) -> bool { +/// The value of a plain or dollar-quoted string literal, `None` for any other form. +fn decode_literal(literal: &str) -> Option { + if let Some(tag) = dollar_quote_tag(literal) { + let body = literal.strip_prefix(tag)?.strip_suffix(tag)?; + return Some(body.to_string()); + } + + let body = literal.strip_prefix('\'')?.strip_suffix('\'')?; + Some(body.replace("''", "'")) +} + +/// The opening tag of a dollar-quoted literal, `$$` or `$tag$`. +fn dollar_quote_tag(literal: &str) -> Option<&str> { + let rest = literal.strip_prefix('$')?; + let end = rest.find('$')?; + Some(&literal[..end + 2]) +} + +/// Whether `value` can be quoted with `tag`: the first occurrence of the tag after the opening one +/// must be the closing one. +fn can_dollar_quote(value: &str, tag: &str) -> bool { + format!("{value}{tag}").find(tag) == Some(value.len()) +} + +pub(super) fn needs_quoting(value: &str) -> bool { if value.is_empty() { return true; } @@ -213,8 +185,28 @@ fn needs_quoting(value: &str) -> bool { return true; } - let lower = value.to_ascii_lowercase(); - RESERVED_KEYWORDS.binary_search(&lower.as_str()).is_ok() + keyword_category(value) == Some(KeywordCategory::Reserved) +} + +/// Whether a schema, table or column name must be quoted. The grammar spells it as `ColId`, which +/// excludes the keywords that may name a function or type. +pub(super) fn needs_quoting_as_column_name(value: &str) -> bool { + needs_quoting(value) || keyword_category(value) == Some(KeywordCategory::TypeFuncName) +} + +/// Whether a name that may be any word, keywords included, must be quoted. The grammar spells it +/// as `ColLabel`, the trailing part of a qualified function name for instance. +pub(super) fn needs_quoting_except_keywords(value: &str) -> bool { + needs_quoting(value) && keyword_category(value).is_none() +} + +/// Whether an unqualified function or type name must be quoted. +/// +/// The grammar spells such a name as `type_function_name`, which excludes column name keywords as +/// well as reserved ones: unquoted, `coalesce(a)` or `interval` would parse as the SQL construct of +/// the same name rather than as a reference to the named object. +pub(super) fn needs_quoting_as_function_or_type_name(value: &str) -> bool { + needs_quoting(value) || keyword_category(value) == Some(KeywordCategory::ColName) } /// Pick a dollar quote delimiter that doesn't conflict with the body content. @@ -255,7 +247,7 @@ fn pick_dollar_delimiter(body: &str, hint: DollarQuoteHint) -> String { }; for tag in preferred_tags { - if !body.contains(tag) { + if can_dollar_quote(body, tag) { return (*tag).to_string(); } } @@ -264,7 +256,7 @@ fn pick_dollar_delimiter(body: &str, hint: DollarQuoteHint) -> String { let mut counter = 0usize; loop { let tag = format!("$f{counter}$"); - if !body.contains(&tag) { + if can_dollar_quote(body, &tag) { return tag; } counter += 1; diff --git a/crates/pgls_pretty_print/src/nodes/table_like_clause.rs b/crates/pgls_pretty_print/src/nodes/table_like_clause.rs index 33d496186..1b9905d6c 100644 --- a/crates/pgls_pretty_print/src/nodes/table_like_clause.rs +++ b/crates/pgls_pretty_print/src/nodes/table_like_clause.rs @@ -57,7 +57,7 @@ pub(super) fn emit_table_like_clause(e: &mut EventEmitter, n: &TableLikeClause) e.line(LineType::SoftOrSpace); e.token(TokenKind::INCLUDING_KW); e.space(); - e.token(TokenKind::IDENT(name.to_string())); + super::emit_word(e, name); } } } diff --git a/crates/pgls_pretty_print/src/nodes/table_sample_clause.rs b/crates/pgls_pretty_print/src/nodes/table_sample_clause.rs index ac2dabd99..b442f35e0 100644 --- a/crates/pgls_pretty_print/src/nodes/table_sample_clause.rs +++ b/crates/pgls_pretty_print/src/nodes/table_sample_clause.rs @@ -1,10 +1,11 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, }; use pgls_query::protobuf::TableSampleClause; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_table_sample_clause(e: &mut EventEmitter, clause: &TableSampleClause) { e.group_start(GroupKind::TableSampleClause); @@ -18,9 +19,7 @@ pub(super) fn emit_table_sample_clause(e: &mut EventEmitter, clause: &TableSampl } if !clause.args.is_empty() { - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &clause.args, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &clause.args, super::emit_node); } if let Some(repeatable) = clause.repeatable.as_ref() { diff --git a/crates/pgls_pretty_print/src/nodes/type_name.rs b/crates/pgls_pretty_print/src/nodes/type_name.rs index 816288d4f..967dc8949 100644 --- a/crates/pgls_pretty_print/src/nodes/type_name.rs +++ b/crates/pgls_pretty_print/src/nodes/type_name.rs @@ -1,12 +1,13 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, - nodes::node_list::emit_comma_separated_list, }; use pgls_query::protobuf::{self, TypeName}; +use super::node_list::emit_parenthesized_list; use super::string::{ emit_identifier, emit_identifier_maybe_quoted, emit_type_identifier_maybe_quoted, + needs_quoting_as_function_or_type_name, }; const INTERVAL_MASK_MONTH: i32 = 1 << 1; @@ -134,6 +135,14 @@ fn emit_dot_separated_name(e: &mut EventEmitter, name_parts: &[String]) { } fn emit_dot_separated_type_name(e: &mut EventEmitter, name_parts: &[String]) { + if let [name] = name_parts + && needs_quoting_as_function_or_type_name(name) + { + // Unquoted, `"numeric"` would be the keyword, which means `pg_catalog.numeric`. + emit_identifier(e, name); + return; + } + for (index, part) in name_parts.iter().enumerate() { if index > 0 { e.token(TokenKind::DOT); @@ -142,43 +151,31 @@ fn emit_dot_separated_type_name(e: &mut EventEmitter, name_parts: &[String]) { } } +/// The keywords spelling a type the grammar qualifies with `pg_catalog` itself, `int` for +/// `pg_catalog.int4` for instance. +/// +/// Only these collapse to keywords. Any other name is written as it is stored: `int4` stays `int4` +/// and an explicit `pg_catalog.text` keeps its schema, since dropping it lets the search path pick +/// another type. fn builtin_type_keywords(name_parts: &[String]) -> Option<&'static [&'static str]> { - if name_parts.is_empty() { + let [schema, name] = name_parts else { return None; - } - - let base_name = match name_parts { - [name] => name, - [schema, name] if is_pg_catalog(schema) => name, - _ => return None, }; + if !is_pg_catalog(schema) { + return None; + } - let lowered = base_name.to_ascii_lowercase(); - - match lowered.as_str() { + match name.as_str() { "bool" => Some(&["boolean"]), - "bytea" => Some(&["bytea"]), - "char" | "bpchar" => Some(&["char"]), - "name" => Some(&["name"]), + "bpchar" => Some(&["char"]), "int2" => Some(&["smallint"]), "int4" => Some(&["int"]), "int8" => Some(&["bigint"]), - "oid" => Some(&["oid"]), - "tid" => Some(&["tid"]), - "xid" => Some(&["xid"]), - "cid" => Some(&["cid"]), "float4" => Some(&["real"]), "float8" => Some(&["double", "precision"]), "numeric" => Some(&["numeric"]), - "decimal" => Some(&["decimal"]), - "money" => Some(&["money"]), "varchar" => Some(&["varchar"]), - "text" => Some(&["text"]), "json" => Some(&["json"]), - "jsonb" => Some(&["jsonb"]), - "uuid" => Some(&["uuid"]), - "xml" => Some(&["xml"]), - "date" => Some(&["date"]), "time" => Some(&["time"]), "timetz" => Some(&["time", "with", "time", "zone"]), "timestamp" => Some(&["timestamp"]), @@ -186,36 +183,6 @@ fn builtin_type_keywords(name_parts: &[String]) -> Option<&'static [&'static str "interval" => Some(&["interval"]), "bit" => Some(&["bit"]), "varbit" => Some(&["bit", "varying"]), - "inet" => Some(&["inet"]), - "cidr" => Some(&["cidr"]), - "macaddr" => Some(&["macaddr"]), - "macaddr8" => Some(&["macaddr8"]), - "regclass" => Some(&["regclass"]), - "regproc" => Some(&["regproc"]), - "regprocedure" => Some(&["regprocedure"]), - "regoper" => Some(&["regoper"]), - "regoperator" => Some(&["regoperator"]), - "regtype" => Some(&["regtype"]), - "regconfig" => Some(&["regconfig"]), - "regdictionary" => Some(&["regdictionary"]), - "anyarray" => Some(&["anyarray"]), - "anyelement" => Some(&["anyelement"]), - "anynonarray" => Some(&["anynonarray"]), - "anyenum" => Some(&["anyenum"]), - "anyrange" => Some(&["anyrange"]), - "pg_lsn" => Some(&["pg_lsn"]), - "tsvector" => Some(&["tsvector"]), - "tsquery" => Some(&["tsquery"]), - "gtsvector" => Some(&["gtsvector"]), - "txid_snapshot" => Some(&["txid_snapshot"]), - "int4range" => Some(&["int4range"]), - "int8range" => Some(&["int8range"]), - "numrange" => Some(&["numrange"]), - "tsrange" => Some(&["tsrange"]), - "tstzrange" => Some(&["tstzrange"]), - "daterange" => Some(&["daterange"]), - "record" => Some(&["record"]), - "void" => Some(&["void"]), _ => None, } } @@ -236,11 +203,9 @@ fn emit_type_modifiers(e: &mut EventEmitter, n: &TypeName, name_parts: &[String] } if !n.typmods.is_empty() { - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.typmods, |node, emitter| { + emit_parenthesized_list(e, &n.typmods, |node, emitter| { super::emit_node(node, emitter) }); - e.token(TokenKind::R_PAREN); } } @@ -257,21 +222,14 @@ fn emit_array_bounds(e: &mut EventEmitter, n: &TypeName) { } fn is_interval_type(name_parts: &[String]) -> bool { - name_parts - .last() - .map(|name| name.eq_ignore_ascii_case("interval")) - .unwrap_or(false) + matches!(name_parts, [schema, name] if is_pg_catalog(schema) && name == "interval") } fn is_time_with_tz_type(name_parts: &[String]) -> bool { - let base_name = match name_parts { - [name] => name, - [schema, name] if is_pg_catalog(schema) => name, - _ => return false, - }; - - let lowered = base_name.to_ascii_lowercase(); - matches!(lowered.as_str(), "timetz" | "timestamptz") + matches!( + name_parts, + [schema, name] if is_pg_catalog(schema) && matches!(name.as_str(), "timetz" | "timestamptz") + ) } fn emit_time_with_tz_type(e: &mut EventEmitter, n: &TypeName, name_parts: &[String]) { @@ -290,11 +248,9 @@ fn emit_time_with_tz_type(e: &mut EventEmitter, n: &TypeName, name_parts: &[Stri e.token(TokenKind::TIME_KW); // Emit precision if any if !n.typmods.is_empty() { - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.typmods, |node, emitter| { + emit_parenthesized_list(e, &n.typmods, |node, emitter| { super::emit_node(node, emitter) }); - e.token(TokenKind::R_PAREN); } e.space(); e.token(TokenKind::WITH_KW); @@ -307,11 +263,9 @@ fn emit_time_with_tz_type(e: &mut EventEmitter, n: &TypeName, name_parts: &[Stri e.token(TokenKind::TIMESTAMP_KW); // Emit precision if any if !n.typmods.is_empty() { - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.typmods, |node, emitter| { + emit_parenthesized_list(e, &n.typmods, |node, emitter| { super::emit_node(node, emitter) }); - e.token(TokenKind::R_PAREN); } e.space(); e.token(TokenKind::WITH_KW); diff --git a/crates/pgls_pretty_print/src/nodes/vacuum_relation.rs b/crates/pgls_pretty_print/src/nodes/vacuum_relation.rs index 3cd6b3169..52ba40216 100644 --- a/crates/pgls_pretty_print/src/nodes/vacuum_relation.rs +++ b/crates/pgls_pretty_print/src/nodes/vacuum_relation.rs @@ -1,11 +1,9 @@ use pgls_query::protobuf::VacuumRelation; -use crate::{ - TokenKind, - emitter::{EventEmitter, GroupKind}, -}; +use crate::emitter::{EventEmitter, GroupKind}; use super::emit_node; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_vacuum_relation(e: &mut EventEmitter, n: &VacuumRelation) { e.group_start(GroupKind::VacuumRelation); @@ -17,9 +15,7 @@ pub(super) fn emit_vacuum_relation(e: &mut EventEmitter, n: &VacuumRelation) { // va_cols: specific columns to vacuum/analyze if !n.va_cols.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - super::node_list::emit_comma_separated_list(e, &n.va_cols, emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.va_cols, emit_node); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/vacuum_stmt.rs b/crates/pgls_pretty_print/src/nodes/vacuum_stmt.rs index b413e63cc..e85af0b99 100644 --- a/crates/pgls_pretty_print/src/nodes/vacuum_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/vacuum_stmt.rs @@ -6,6 +6,7 @@ use crate::{ }; use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_vacuum_stmt(e: &mut EventEmitter, n: &VacuumStmt) { e.group_start(GroupKind::VacuumStmt); @@ -19,11 +20,10 @@ pub(super) fn emit_vacuum_stmt(e: &mut EventEmitter, n: &VacuumStmt) { // Emit options if present if !n.options.is_empty() { e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, |node, emitter| { + emit_parenthesized_list(e, &n.options, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { // Emit option name - emitter.token(TokenKind::IDENT(def.defname.to_uppercase())); + super::emit_word(emitter, &def.defname); // Emit option value if present if let Some(ref arg) = def.arg { emitter.space(); @@ -33,7 +33,6 @@ pub(super) fn emit_vacuum_stmt(e: &mut EventEmitter, n: &VacuumStmt) { super::emit_node(node, emitter); } }); - e.token(TokenKind::R_PAREN); } // Relations to vacuum/analyze diff --git a/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs b/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs index 706b3c4fd..f664b9241 100644 --- a/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs @@ -34,38 +34,10 @@ fn emit_set_arg(node: &Node, e: &mut EventEmitter) { super::emit_node(node, e); } -/// Check if a string should be emitted as a simple unquoted identifier +/// Whether a string reads the same written as an unquoted word. An unquoted word is folded to +/// lowercase, so `SET datestyle = German` would set `german`. fn is_simple_identifier(s: &str) -> bool { - if s.is_empty() { - return false; - } - - // Must start with letter or underscore - let first_char = s.chars().next().unwrap(); - if !first_char.is_ascii_alphabetic() && first_char != '_' { - return false; - } - - // Rest must be alphanumeric, underscore, or dollar sign - if !s - .chars() - .all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '$') - { - return false; - } - - // Check for reserved keywords that must be quoted - // These are common SQL keywords that can't be used as unquoted values - let reserved_keywords = [ - "all", "and", "as", "asc", "between", "by", "case", "check", "create", "default", "delete", - "desc", "distinct", "drop", "else", "end", "false", "for", "from", "full", "group", - "having", "if", "in", "index", "inner", "insert", "into", "is", "join", "left", "like", - "limit", "not", "null", "offset", "on", "or", "order", "outer", "primary", "right", - "select", "set", "table", "then", "to", "true", "union", "unique", "update", "using", - "values", "when", "where", "with", "any", "some", "none", "only", - ]; - - !reserved_keywords.contains(&s.to_lowercase().as_str()) + !super::string::needs_quoting(s) } /// Emit a dot-separated variable name, quoting parts that need it @@ -254,7 +226,7 @@ fn emit_variable_set_stmt_inner(e: &mut EventEmitter, n: &VariableSetStmt) { // Special syntax: SET SESSION CHARACTERISTICS AS TRANSACTION ... e.token(TokenKind::SESSION_KW); e.space(); - e.token(TokenKind::IDENT("CHARACTERISTICS".to_string())); + super::emit_word(e, "characteristics"); e.space(); e.token(TokenKind::AS_KW); e.space(); @@ -271,14 +243,15 @@ fn emit_variable_set_stmt_inner(e: &mut EventEmitter, n: &VariableSetStmt) { // SET TRANSACTION SNAPSHOT 'snapshot_id' e.token(TokenKind::TRANSACTION_KW); e.space(); - e.token(TokenKind::IDENT("SNAPSHOT".to_string())); + super::emit_word(e, "snapshot"); e.space(); // The snapshot id is in args as a string if !n.args.is_empty() { super::emit_node(&n.args[0], e); } } else { - emit_variable_name(e, &n.name); + // SET TRANSACTION + e.token(TokenKind::TRANSACTION_KW); // Emit transaction options from args (DefElems) with soft line breaks for arg in &n.args { @@ -388,7 +361,7 @@ fn emit_transaction_option(e: &mut EventEmitter, def: &pgls_query::protobuf::Def } _ => { // Unknown transaction option - emit as identifier - e.token(TokenKind::IDENT(def.defname.to_uppercase())); + super::emit_word(e, &def.defname); if let Some(ref arg) = def.arg { e.space(); super::emit_node(arg, e); diff --git a/crates/pgls_pretty_print/src/nodes/variable_show_stmt.rs b/crates/pgls_pretty_print/src/nodes/variable_show_stmt.rs index 8cd9f27cb..6adc9d113 100644 --- a/crates/pgls_pretty_print/src/nodes/variable_show_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/variable_show_stmt.rs @@ -12,7 +12,7 @@ pub(super) fn emit_variable_show_stmt(e: &mut EventEmitter, n: &VariableShowStmt if !n.name.is_empty() { e.space(); - super::emit_identifier(e, &n.name); + super::emit_identifier_maybe_quoted(e, &n.name); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/view_stmt.rs b/crates/pgls_pretty_print/src/nodes/view_stmt.rs index eac6d3b8e..84c7734e7 100644 --- a/crates/pgls_pretty_print/src/nodes/view_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/view_stmt.rs @@ -6,6 +6,7 @@ use crate::{ }; use super::node_list::emit_comma_separated_list; +use super::node_list::emit_parenthesized_list; pub(super) fn emit_view_stmt(e: &mut EventEmitter, n: &ViewStmt) { emit_view_stmt_impl(e, n, true); @@ -69,9 +70,7 @@ fn emit_view_stmt_impl(e: &mut EventEmitter, n: &ViewStmt, with_semicolon: bool) e.indent_start(); e.token(TokenKind::WITH_KW); e.space(); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.options, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.options, super::emit_node); e.indent_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/xml_expr.rs b/crates/pgls_pretty_print/src/nodes/xml_expr.rs index aae3f14bb..00577c653 100644 --- a/crates/pgls_pretty_print/src/nodes/xml_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/xml_expr.rs @@ -5,6 +5,8 @@ use crate::{ }; use pgls_query::protobuf::{XmlExpr, XmlOptionType}; +use super::node_list::emit_parenthesized_list; + pub(super) fn emit_xml_expr(e: &mut EventEmitter, n: &XmlExpr) { e.group_start(GroupKind::XmlExpr); @@ -22,9 +24,7 @@ pub(super) fn emit_xml_expr(e: &mut EventEmitter, n: &XmlExpr) { 1 => { // XMLCONCAT e.token(TokenKind::XMLCONCAT_KW); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.args, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.args, super::emit_node); } 2 => { // XMLELEMENT @@ -40,9 +40,7 @@ pub(super) fn emit_xml_expr(e: &mut EventEmitter, n: &XmlExpr) { e.token(TokenKind::COMMA); e.space(); e.token(TokenKind::XMLATTRIBUTES_KW); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.named_args, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.named_args, super::emit_node); } // Args represent content @@ -57,9 +55,7 @@ pub(super) fn emit_xml_expr(e: &mut EventEmitter, n: &XmlExpr) { 3 => { // XMLFOREST e.token(TokenKind::XMLFOREST_KW); - e.token(TokenKind::L_PAREN); - emit_comma_separated_list(e, &n.named_args, super::emit_node); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &n.named_args, super::emit_node); } 4 => { // XMLPARSE diff --git a/crates/pgls_pretty_print/src/nodes/xml_serialize.rs b/crates/pgls_pretty_print/src/nodes/xml_serialize.rs index c34a24680..82c9ca638 100644 --- a/crates/pgls_pretty_print/src/nodes/xml_serialize.rs +++ b/crates/pgls_pretty_print/src/nodes/xml_serialize.rs @@ -7,17 +7,17 @@ use pgls_query::protobuf::{XmlOptionType, XmlSerialize}; pub(super) fn emit_xml_serialize(e: &mut EventEmitter, n: &XmlSerialize) { e.group_start(GroupKind::XmlSerialize); - e.token(TokenKind::IDENT("XMLSERIALIZE".to_string())); + super::emit_word(e, "xmlserialize"); e.token(TokenKind::L_PAREN); // XmlOptionType: XmloptionDocument=1, XmloptionContent=2 match n.xmloption() { XmlOptionType::XmloptionDocument => { - e.token(TokenKind::IDENT("DOCUMENT".to_string())); + super::emit_word(e, "document"); e.space(); } _ => { - e.token(TokenKind::IDENT("CONTENT".to_string())); + super::emit_word(e, "content"); e.space(); } } @@ -38,7 +38,7 @@ pub(super) fn emit_xml_serialize(e: &mut EventEmitter, n: &XmlSerialize) { // INDENT option if n.indent { e.space(); - e.token(TokenKind::IDENT("INDENT".to_string())); + super::emit_word(e, "indent"); } e.token(TokenKind::R_PAREN); diff --git a/crates/pgls_pretty_print/src/normalize.rs b/crates/pgls_pretty_print/src/normalize.rs index afb9f512a..ee7d0d217 100644 --- a/crates/pgls_pretty_print/src/normalize.rs +++ b/crates/pgls_pretty_print/src/normalize.rs @@ -19,11 +19,9 @@ use pgls_query::{NodeEnum, NodeMut}; pub fn normalize_ast(node: &mut NodeEnum) { clear_location(node); normalize_bool_expr_associativity(node); - normalize_object_with_args(node); normalize_foreign_table_partbound(node); normalize_merge_support_func(node); - normalize_sql_value_function(node); - normalize_function_body(node); + normalize_function_options(node); } /// Flatten nested boolean expressions which PostgreSQL represents differently @@ -135,22 +133,9 @@ fn clear_location(node: &mut NodeEnum) { } NodeMut::FuncCall(n) => { (*n).location = 0; - // Normalize funcformat to CoerceExplicitCall since we emit as regular function call + // SQL-standard syntax the printer does not know is written as a call to the same + // `pg_catalog` function, which only differs in this flag. (*n).funcformat = pgls_query::protobuf::CoercionForm::CoerceExplicitCall.into(); - // Remove pg_catalog prefix from function names - if (*n).funcname.len() == 2 - && let Some(NodeEnum::String(schema)) = - (*n).funcname.first().and_then(|node| node.node.as_ref()) - && schema.sval.eq_ignore_ascii_case("pg_catalog") - { - (*n).funcname.remove(0); - } - // Normalize function names to lowercase for case-insensitive comparison - for func_name_node in &mut (*n).funcname { - if let Some(NodeEnum::String(s)) = func_name_node.node.as_mut() { - s.sval = s.sval.to_lowercase(); - } - } } NodeMut::NamedArgExpr(n) => { (*n).location = 0; @@ -300,14 +285,6 @@ fn clear_location(node: &mut NodeEnum) { } NodeMut::TypeName(n) => { (*n).location = 0; - - if (*n).names.len() == 2 - && let Some(NodeEnum::String(schema)) = - (*n).names.first().and_then(|node| node.node.as_ref()) - && schema.sval.eq_ignore_ascii_case("pg_catalog") - { - (*n).names.remove(0); - } } NodeMut::JsonBehavior(n) => { (*n).location = 0; @@ -414,14 +391,6 @@ fn clear_location(node: &mut NodeEnum) { } } } - NodeMut::FunctionParameter(n) => { - // Normalize FunctionParameter mode to FuncParamDefault - // When emitting objargs (TypeName), reparsing creates objfuncargs (FunctionParameter) - // with potentially different modes (e.g., FuncParamVariadic vs FuncParamDefault) - (*n).mode = pgls_query::protobuf::FunctionParameterMode::FuncParamDefault as i32; - // Clear name as DROP FUNCTION can be parsed with or without param names - (*n).name.clear(); - } NodeMut::IndexElem(n) => { // Normalize DefElem args in opclassopts from TypeName to String for opt in (*n).opclassopts.iter_mut() { @@ -458,20 +427,6 @@ fn clear_location(node: &mut NodeEnum) { NodeMut::XmlExpr(n) => { (*n).location = 0; } - NodeMut::VariableSetStmt(n) => { - // SET statement values are case-insensitive in PostgreSQL - // e.g., SET xmloption = DOCUMENT vs SET xmloption = document - for arg in &mut (*n).args { - if let Some(NodeEnum::AConst(aconst)) = arg.node.as_mut() { - aconst.location = 0; - if let Some(pgls_query::protobuf::a_const::Val::Sval(s)) = - aconst.val.as_mut() - { - s.sval = s.sval.to_lowercase(); - } - } - } - } _ => {} }); @@ -481,46 +436,6 @@ fn clear_location(node: &mut NodeEnum) { } } -/// Normalize ObjectWithArgs by clearing objfuncargs. -/// -/// When we emit from objargs, the reparsed objfuncargs may differ in count -/// (e.g., OUT parameters in objfuncargs but not in objargs). -fn normalize_object_with_args(node: &mut NodeEnum) { - match node { - NodeEnum::ObjectWithArgs(owa) => { - // Clear objfuncargs - we emit from objargs only - owa.objfuncargs.clear(); - } - NodeEnum::DropStmt(ds) => { - for obj in &mut ds.objects { - if let Some(ref mut n) = obj.node { - normalize_object_with_args(n); - } - } - } - NodeEnum::AlterObjectSchemaStmt(stmt) => { - if let Some(ref mut obj) = stmt.object - && let Some(ref mut n) = obj.node - { - normalize_object_with_args(n); - } - } - NodeEnum::CommentStmt(stmt) => { - if let Some(ref mut obj) = stmt.object - && let Some(ref mut n) = obj.node - { - normalize_object_with_args(n); - } - } - NodeEnum::AlterFunctionStmt(stmt) => { - if let Some(ref mut func) = stmt.func { - func.objfuncargs.clear(); - } - } - _ => {} - } -} - /// Normalize CreateForeignTableStmt partbound. /// /// When partbound is None but inh_relations is non-empty, set a default partition bound. @@ -692,131 +607,6 @@ fn process_select_stmt_box(stmt: &mut pgls_query::protobuf::SelectStmt) { } } -/// Normalize SqlvalueFunction nodes to FuncCall for comparison. -/// -/// PostgreSQL represents CURRENT_SCHEMA, CURRENT_USER, etc. as SqlvalueFunction -/// internally, but when we emit them as functions and reparse, they become FuncCall. -fn normalize_sql_value_function(node: &mut NodeEnum) { - normalize_sql_value_function_recursive(node); -} - -fn normalize_sql_value_function_recursive(node: &mut NodeEnum) { - // First recursively process all children - match node { - NodeEnum::SelectStmt(stmt) => { - for target in &mut stmt.target_list { - if let Some(ref mut n) = target.node { - normalize_sql_value_function_recursive(n); - } - } - for from in &mut stmt.from_clause { - if let Some(ref mut n) = from.node { - normalize_sql_value_function_recursive(n); - } - } - if let Some(ref mut w) = stmt.where_clause - && let Some(ref mut n) = w.node - { - normalize_sql_value_function_recursive(n); - } - } - NodeEnum::AExpr(expr) => { - if let Some(ref mut l) = expr.lexpr - && let Some(ref mut n) = l.node - { - // Check if this is a SqlvalueFunction that needs conversion - if let NodeEnum::SqlvalueFunction(svf) = n { - if let Some(func_call) = sql_value_to_func_call(svf) { - *n = NodeEnum::FuncCall(Box::new(func_call)); - } - } else { - normalize_sql_value_function_recursive(n); - } - } - if let Some(ref mut r) = expr.rexpr - && let Some(ref mut n) = r.node - { - if let NodeEnum::SqlvalueFunction(svf) = n { - if let Some(func_call) = sql_value_to_func_call(svf) { - *n = NodeEnum::FuncCall(Box::new(func_call)); - } - } else { - normalize_sql_value_function_recursive(n); - } - } - } - NodeEnum::ResTarget(rt) => { - if let Some(ref mut v) = rt.val - && let Some(ref mut n) = v.node - { - if let NodeEnum::SqlvalueFunction(svf) = n { - if let Some(func_call) = sql_value_to_func_call(svf) { - *n = NodeEnum::FuncCall(Box::new(func_call)); - } - } else { - normalize_sql_value_function_recursive(n); - } - } - } - NodeEnum::FuncCall(fc) => { - for arg in &mut fc.args { - if let Some(ref mut n) = arg.node { - if let NodeEnum::SqlvalueFunction(svf) = n { - if let Some(func_call) = sql_value_to_func_call(svf) { - *n = NodeEnum::FuncCall(Box::new(func_call)); - } - } else { - normalize_sql_value_function_recursive(n); - } - } - } - } - _ => {} - } -} - -fn sql_value_to_func_call( - svf: &pgls_query::protobuf::SqlValueFunction, -) -> Option { - // Map SqlValueFunctionOp to function name - let func_name = match svf.op() { - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentSchema => "current_schema", - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentUser => "current_user", - pgls_query::protobuf::SqlValueFunctionOp::SvfopSessionUser => "session_user", - pgls_query::protobuf::SqlValueFunctionOp::SvfopUser => "user", - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentCatalog => "current_catalog", - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentDate => "current_date", - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentTime => "current_time", - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentTimeN => return None, // Has args - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentTimestamp => "current_timestamp", - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentTimestampN => return None, // Has args - pgls_query::protobuf::SqlValueFunctionOp::SvfopLocaltime => "localtime", - pgls_query::protobuf::SqlValueFunctionOp::SvfopLocaltimeN => return None, // Has args - pgls_query::protobuf::SqlValueFunctionOp::SvfopLocaltimestamp => "localtimestamp", - pgls_query::protobuf::SqlValueFunctionOp::SvfopLocaltimestampN => return None, // Has args - pgls_query::protobuf::SqlValueFunctionOp::SvfopCurrentRole => "current_role", - _ => return None, - }; - - Some(pgls_query::protobuf::FuncCall { - funcname: vec![pgls_query::protobuf::Node { - node: Some(NodeEnum::String(pgls_query::protobuf::String { - sval: func_name.to_string(), - })), - }], - args: vec![], - agg_order: vec![], - agg_filter: None, - over: None, - agg_within_group: false, - agg_star: false, - agg_distinct: false, - func_variadic: false, - funcformat: pgls_query::protobuf::CoercionForm::CoerceExplicitCall.into(), - location: 0, - }) -} - /// Returns the canonical order for a function option. /// Postgres's canonical order (as seen in pg_dump output) is: /// 1. LANGUAGE @@ -860,53 +650,11 @@ fn sort_function_options(options: &mut [pgls_query::protobuf::Node]) { }); } -/// Normalize function body strings by trimming whitespace. -/// -/// The formatter emits function bodies on separate lines from the dollar-quote delimiters, -/// which adds leading/trailing newlines to the body. This normalization trims these -/// so that semantically equivalent bodies compare equal. -/// -/// Also sorts function options to canonical order so that semantically equivalent -/// option orderings compare equal. -fn normalize_function_body(node: &mut NodeEnum) { +/// Sorts function options to the canonical order the printer writes them in. +fn normalize_function_options(node: &mut NodeEnum) { match node { - NodeEnum::CreateFunctionStmt(stmt) => { - // Sort options to canonical order - sort_function_options(&mut stmt.options); - - for opt in &mut stmt.options { - if let Some(NodeEnum::DefElem(def)) = opt.node.as_mut() - && def.defname.eq_ignore_ascii_case("as") - && let Some(ref mut arg) = def.arg - && let Some(NodeEnum::List(list)) = arg.node.as_mut() - { - // Trim whitespace from each string in the list (function body) - for item in &mut list.items { - if let Some(NodeEnum::String(s)) = item.node.as_mut() { - s.sval = s.sval.trim().to_string(); - } - } - } - } - } - NodeEnum::DoStmt(stmt) => { - for arg in &mut stmt.args { - if let Some(NodeEnum::DefElem(def)) = arg.node.as_mut() - && def.defname.eq_ignore_ascii_case("as") - && let Some(ref mut arg) = def.arg - && let Some(NodeEnum::String(s)) = arg.node.as_mut() - { - s.sval = s.sval.trim().to_string(); - } - } - } - NodeEnum::InlineCodeBlock(block) => { - block.source_text = block.source_text.trim().to_string(); - } - NodeEnum::AlterFunctionStmt(stmt) => { - // Sort actions to canonical order - sort_function_options(&mut stmt.actions); - } + NodeEnum::CreateFunctionStmt(stmt) => sort_function_options(&mut stmt.options), + NodeEnum::AlterFunctionStmt(stmt) => sort_function_options(&mut stmt.actions), _ => {} } } diff --git a/crates/pgls_pretty_print/src/renderer.rs b/crates/pgls_pretty_print/src/renderer.rs index 7be5da743..4edaf85b3 100644 --- a/crates/pgls_pretty_print/src/renderer.rs +++ b/crates/pgls_pretty_print/src/renderer.rs @@ -1,5 +1,5 @@ use crate::TokenKind; -use crate::emitter::{GroupKind, LayoutEvent, LineType}; +use crate::emitter::{LayoutEvent, LineType}; use std::fmt::Write; #[derive(Debug, Clone)] @@ -93,8 +93,8 @@ impl Renderer { } LayoutEvent::GroupStart { .. } => { let group_end = self.find_group_end(events, i); - let group_slice = &events[i..=group_end]; - self.render_group(group_slice)?; + let trailing_width = self.trailing_width(&events[group_end + 1..], 0); + self.render_group(&events[i..=group_end], trailing_width)?; i = group_end + 1; } LayoutEvent::GroupEnd => { @@ -113,37 +113,57 @@ impl Renderer { Ok(()) } - fn render_group(&mut self, group_events: &[LayoutEvent]) -> Result<(), std::fmt::Error> { - if let Some(single_line) = self.try_single_line(group_events) { - let would_fit = - self.effective_line_length() + single_line.len() <= self.config.max_line_length; - if would_fit { - self.write_text(&single_line)?; - return Ok(()); - } + /// Renders a group on one line when it fits, `trailing_width` included, and breaks it + /// otherwise. A nested group decides on its own, whether or not its parent broke. + fn render_group( + &mut self, + group_events: &[LayoutEvent], + trailing_width: usize, + ) -> Result<(), std::fmt::Error> { + if let Some(single_line) = self.try_single_line(group_events) + && self.fits(&single_line, trailing_width) + { + self.write_text(&single_line)?; + return Ok(()); } - self.render_events_with_breaks(group_events) + // Skip the GroupStart and GroupEnd markers. + self.render_events_with_breaks(&group_events[1..group_events.len() - 1], trailing_width) } - /// Render an inner group, allowing it to try single-line independently of parent's break status. - /// This enables nested groups to stay compact even when the parent group is breaking. - fn render_inner_group(&mut self, group_events: &[LayoutEvent]) -> Result<(), std::fmt::Error> { - // Extract inner events (skip GroupStart and GroupEnd markers) - let inner_events = &group_events[1..group_events.len() - 1]; - - // Try single-line first, independent of parent's break status - if let Some(single_line) = self.try_single_line(group_events) { - let would_fit = - self.effective_line_length() + single_line.len() <= self.config.max_line_length; - if would_fit { - self.write_text(&single_line)?; - return Ok(()); + /// Whether `text` fits on the current line, followed by `trailing_width` columns that cannot + /// move to the next line. Only the first line of a text spanning several lines, a function + /// body for instance, sits on the current one. + fn fits(&self, text: &str, trailing_width: usize) -> bool { + let width = match text.split_once('\n') { + Some((first_line, _)) => first_line.len(), + None => text.len() + trailing_width, + }; + self.effective_line_length() + width <= self.config.max_line_length + } + + /// The width of the text that follows a group without a break opportunity in between, such as + /// the comma after a list item. `outer_trailing_width` is what follows the enclosing events. + fn trailing_width(&self, events: &[LayoutEvent], outer_trailing_width: usize) -> usize { + let mut width = 0; + for event in events { + match event { + LayoutEvent::Token(token) => { + let text = token.render(&self.config); + match text.split_once('\n') { + Some((first_line, _)) => return width + first_line.len(), + None => width += text.len(), + } + } + LayoutEvent::Space => width += 1, + LayoutEvent::GroupStart { .. } + | LayoutEvent::GroupEnd + | LayoutEvent::IndentStart + | LayoutEvent::IndentEnd => {} + LayoutEvent::Line(_) | LayoutEvent::Comment { .. } => return width, } } - - // Fall back to breaking - self.render_events_with_breaks(inner_events) + width + outer_trailing_width } /// The current line length, counting the indentation that will be written when the @@ -158,7 +178,11 @@ impl Renderer { } } - fn render_events_with_breaks(&mut self, events: &[LayoutEvent]) -> Result<(), std::fmt::Error> { + fn render_events_with_breaks( + &mut self, + events: &[LayoutEvent], + trailing_width: usize, + ) -> Result<(), std::fmt::Error> { let mut i = 0; while i < events.len() { match &events[i] { @@ -194,39 +218,11 @@ impl Renderer { self.after_line_comment = *line_comment; i += 1; } - LayoutEvent::GroupStart { kind } => { + LayoutEvent::GroupStart { .. } => { let group_end = self.find_group_end(events, i); - let group_slice = &events[i..=group_end]; - - // Decide whether to try single-line for this nested group. - // We try single-line in two cases: - // 1. Followed by a Hard break (semantic boundary like RETURNS after - // function signature) - // 2. The group's single-line form is small enough to fit on its own - // (allows compact column lists, function args, etc.) - let followed_by_hard_break = events - .get(group_end + 1) - .is_some_and(|e| matches!(e, LayoutEvent::Line(LineType::Hard))); - - let try_single_line = if matches!(kind, GroupKind::FunctionArgumentGroup) - || followed_by_hard_break - { - true - } else if let Some(single_line) = self.try_single_line(group_slice) { - // Allow small groups to stay on one line even without Hard break - // This keeps column lists, function args compact - single_line.len() <= self.config.max_line_length / 2 - } else { - false - }; - - if try_single_line { - self.render_inner_group(group_slice)?; - } else { - // Force nested group to break - let inner_events = &events[i + 1..group_end]; - self.render_events_with_breaks(inner_events)?; - } + let group_trailing_width = + self.trailing_width(&events[group_end + 1..], trailing_width); + self.render_group(&events[i..=group_end], group_trailing_width)?; i = group_end + 1; } LayoutEvent::GroupEnd => { diff --git a/crates/pgls_pretty_print/tests/postgres_regress.rs b/crates/pgls_pretty_print/tests/postgres_regress.rs index 549607366..09138f359 100644 --- a/crates/pgls_pretty_print/tests/postgres_regress.rs +++ b/crates/pgls_pretty_print/tests/postgres_regress.rs @@ -1,5 +1,5 @@ //! Formats every statement Postgres accepted in its own regression suite and checks that the output -//! parses back to the same AST. +//! parses back to the same AST, and that formatting the output again changes nothing. use std::panic::{AssertUnwindSafe, catch_unwind}; @@ -71,25 +71,35 @@ fn round_trip(sql: &str) -> Result<(), String> { let mut expected = ast.clone(); normalize_ast(&mut expected); for max_line_length in LINE_WIDTHS { - let output = catch_unwind(AssertUnwindSafe(|| format(&ast, max_line_length))) + let output = catch_unwind(AssertUnwindSafe(|| format(&ast, sql, max_line_length))) .map_err(|_| format!("formatter panicked at width {max_line_length}"))?; - let mut formatted = pgls_query::parse(&output) + let reparsed = pgls_query::parse(&output) .map_err(|e| format!("output doesn't parse at width {max_line_length}: {e}\n{output}"))? .into_root() .ok_or("output has no statement")?; + let mut formatted = reparsed.clone(); normalize_ast(&mut formatted); if formatted != expected { return Err(format!( "output has a different AST at width {max_line_length}\n{output}" )); } + let reformatted = catch_unwind(AssertUnwindSafe(|| { + format(&reparsed, &output, max_line_length) + })) + .map_err(|_| format!("formatter panicked on its own output at width {max_line_length}"))?; + if reformatted != output { + return Err(format!( + "formatting is not idempotent at width {max_line_length}\n{output}\n---\n{reformatted}" + )); + } } Ok(()) } -fn format(ast: &pgls_query::NodeEnum, max_line_length: usize) -> String { +fn format(ast: &pgls_query::NodeEnum, sql: &str, max_line_length: usize) -> String { let config = FormatConfig::default(); - let mut emitter = EventEmitter::new(config.clone()); + let mut emitter = EventEmitter::new(config.clone()).with_source(sql); emit_node_enum(ast, &mut emitter); let mut output = String::new(); let config = RenderConfig { diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141359_app_schema_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141359_app_schema_100.snap index 929b8423a..c99196ee8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141359_app_schema_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141359_app_schema_100.snap @@ -2,8 +2,8 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20220117141359_app_schema.sql --- -create schema "app"; +create schema app; -grant USAGE on schema app to authenticated, anon; +grant usage on schema app to authenticated, anon; -alter default privileges in schema app grant SELECT on tables to authenticated, anon; +alter default privileges in schema app grant select on tables to authenticated, anon; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141359_app_schema_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141359_app_schema_80.snap index f3a51a785..08690a6b8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141359_app_schema_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141359_app_schema_80.snap @@ -2,13 +2,10 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20220117141359_app_schema.sql --- -create schema "app"; +create schema app; -grant USAGE on schema app to authenticated, anon; +grant usage on schema app to authenticated, anon; alter default privileges in schema app -grant SELECT -on tables -to authenticated, -anon; +grant select on tables to authenticated, anon; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141507_semver_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141507_semver_100.snap index 3a7107c0e..d030e3999 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141507_semver_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141507_semver_100.snap @@ -8,13 +8,13 @@ create or replace function app.is_valid(app.semver_struct) returns boolean language sql immutable -as $function$ -select ( +as $$ + select ( ($1).major is not null and ($1).minor is not null and ($1).patch is not null ) -$function$; +$$; create domain app.semver as app.semver_struct check (app.is_valid(value)); @@ -22,19 +22,19 @@ create function app.semver_exception(version text) returns app.semver_struct language plpgsql immutable -as $function$ +as $$ begin raise exception using errcode='22000', message=format('Invalid semver %L', version); end; -$function$; +$$; create function app.text_to_semver(text) returns app.semver_struct language sql immutable strict -as $function$ -with s(version) as ( +as $$ + with s(version) as ( select ( split_part($1, '.', 1), split_part($1, '.', 2), @@ -48,13 +48,13 @@ with s(version) as ( end from s -$function$; +$$; create or replace function app.semver_to_text(app.semver) returns text language sql immutable -as $function$ -select +as $$ + select format('%s.%s.%s', $1.major, $1.minor, $1.patch) -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141507_semver_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141507_semver_80.snap index 559008859..1234c0053 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141507_semver_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141507_semver_80.snap @@ -12,13 +12,13 @@ create or replace function app.is_valid(app.semver_struct) returns boolean language sql immutable -as $function$ -select ( +as $$ + select ( ($1).major is not null and ($1).minor is not null and ($1).patch is not null ) -$function$; +$$; create domain app.semver as app.semver_struct check (app.is_valid(value)); @@ -26,19 +26,19 @@ create function app.semver_exception(version text) returns app.semver_struct language plpgsql immutable -as $function$ +as $$ begin raise exception using errcode='22000', message=format('Invalid semver %L', version); end; -$function$; +$$; create function app.text_to_semver(text) returns app.semver_struct language sql immutable strict -as $function$ -with s(version) as ( +as $$ + with s(version) as ( select ( split_part($1, '.', 1), split_part($1, '.', 2), @@ -52,13 +52,13 @@ with s(version) as ( end from s -$function$; +$$; create or replace function app.semver_to_text(app.semver) returns text language sql immutable -as $function$ -select +as $$ + select format('%s.%s.%s', $1.major, $1.minor, $1.patch) -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141645_valid_name_type_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141645_valid_name_type_100.snap index e3dc2bcc6..5c7fe9ea8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141645_valid_name_type_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141645_valid_name_type_100.snap @@ -9,8 +9,8 @@ create domain app.valid_name as extensions.citext check (value ~ '^[A-z][A-z0-9\ create or replace function app.exception(message text) returns text language plpgsql -as $function$ -begin +as $$ + begin raise exception using errcode='22000', message=message; end; -$function$; + $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141645_valid_name_type_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141645_valid_name_type_80.snap index d683e47ed..02599ca0b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141645_valid_name_type_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117141645_valid_name_type_80.snap @@ -10,8 +10,8 @@ create domain app.valid_name as extensions.citext create or replace function app.exception(message text) returns text language plpgsql -as $function$ -begin +as $$ + begin raise exception using errcode='22000', message=message; end; -$function$; + $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142104_account_and_org_tables_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142104_account_and_org_tables_100.snap index 4d14b9ab8..ec8d59f32 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142104_account_and_org_tables_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142104_account_and_org_tables_100.snap @@ -7,39 +7,29 @@ insert into storage.buckets (id, name) values ('avatars', 'avatars'); create table app.handle_registry ( handle app.valid_name primary key not null, is_organization boolean not null, - created_at timestamp with time zone - not null - default NOW(), + created_at timestamptz not null default now(), unique (handle, is_organization) ); create table app.accounts ( id uuid primary key references auth.users (id), handle app.valid_name not null unique, - is_organization boolean - generated always as (false) stored, + is_organization boolean generated always as (false) stored, avatar_id uuid references storage.objects (id), - display_name text - check (length(display_name) <= 128), + display_name text check (length(display_name) <= 128), bio text check (length(bio) <= 512), contact_email app.email_address, - created_at timestamp with time zone - not null - default NOW(), - constraint "fk_handle_registry" - foreign key - (handle, - is_organization) - references app.handle_registry (handle, - is_organization) + created_at timestamptz not null default now(), + constraint fk_handle_registry foreign key (handle, is_organization) + references app.handle_registry (handle, is_organization) ); create or replace function app.register_account() returns trigger language plpgsql security definer -as $function$ -begin +as $$ + begin insert into app.handle_registry (handle, is_organization) values ( new.raw_user_meta_data ->> 'handle', @@ -56,7 +46,7 @@ begin ); return new; end; -$function$; + $$; create or replace trigger on_auth_user_created after insert @@ -67,38 +57,24 @@ execute function app.register_account(); create table app.organizations ( id uuid primary key default gen_random_uuid(), handle app.valid_name not null unique, - is_organization boolean - generated always as (true) stored, + is_organization boolean generated always as (true) stored, avatar_id uuid references storage.objects (id), - display_name text - check (length(display_name) <= 128), + display_name text check (length(display_name) <= 128), bio text check (length(bio) <= 512), contact_email app.email_address, - created_at timestamp with time zone - not null - default NOW(), - constraint "fk_handle_registry" - foreign key - (handle, - is_organization) - references app.handle_registry (handle, - is_organization) + created_at timestamptz not null default now(), + constraint fk_handle_registry foreign key (handle, is_organization) + references app.handle_registry (handle, is_organization) ); create type app.membership_role as enum ('maintainer'); create table app.members ( id uuid primary key default uuid_generate_v4(), - organization_id uuid - not null - references app.organizations (id), - account_id uuid - not null - references app.accounts (id), + organization_id uuid not null references app.organizations (id), + account_id uuid not null references app.accounts (id), role app.membership_role not null, - created_at timestamp with time zone - not null - default NOW(), + created_at timestamptz not null default now(), unique (organization_id, account_id) ); @@ -106,14 +82,14 @@ create or replace function app.register_organization_creator_as_member() returns trigger language plpgsql security definer -as $function$ -begin +as $$ + begin insert into app.members(organization_id, account_id, role) values (new.id, auth.uid(), 'maintainer'); return new; end; -$function$; + $$; create or replace trigger on_app_organization_created after insert @@ -125,8 +101,8 @@ create or replace function app.update_avatar_id() returns trigger language plpgsql security definer -as $function$ -declare +as $$ + declare v_handle app.valid_name; v_affected_account app.accounts := null; begin @@ -152,7 +128,7 @@ declare return new; end; -$function$; + $$; create or replace trigger on_storage_object_created after insert diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142104_account_and_org_tables_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142104_account_and_org_tables_80.snap index b409db604..ec8d59f32 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142104_account_and_org_tables_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142104_account_and_org_tables_80.snap @@ -5,46 +5,31 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20220117142104_account_and insert into storage.buckets (id, name) values ('avatars', 'avatars'); create table app.handle_registry ( - handle app.valid_name - primary key - not null, + handle app.valid_name primary key not null, is_organization boolean not null, - created_at timestamp with time zone - not null - default NOW(), + created_at timestamptz not null default now(), unique (handle, is_organization) ); create table app.accounts ( - id uuid - primary key - references auth.users (id), + id uuid primary key references auth.users (id), handle app.valid_name not null unique, - is_organization boolean - generated always as (false) stored, - avatar_id uuid - references storage.objects (id), - display_name text - check (length(display_name) <= 128), + is_organization boolean generated always as (false) stored, + avatar_id uuid references storage.objects (id), + display_name text check (length(display_name) <= 128), bio text check (length(bio) <= 512), contact_email app.email_address, - created_at timestamp with time zone - not null - default NOW(), - constraint "fk_handle_registry" - foreign key - (handle, - is_organization) - references app.handle_registry (handle, - is_organization) + created_at timestamptz not null default now(), + constraint fk_handle_registry foreign key (handle, is_organization) + references app.handle_registry (handle, is_organization) ); create or replace function app.register_account() returns trigger language plpgsql security definer -as $function$ -begin +as $$ + begin insert into app.handle_registry (handle, is_organization) values ( new.raw_user_meta_data ->> 'handle', @@ -61,7 +46,7 @@ begin ); return new; end; -$function$; + $$; create or replace trigger on_auth_user_created after insert @@ -70,45 +55,26 @@ for each row execute function app.register_account(); create table app.organizations ( - id uuid - primary key - default gen_random_uuid(), + id uuid primary key default gen_random_uuid(), handle app.valid_name not null unique, - is_organization boolean - generated always as (true) stored, - avatar_id uuid - references storage.objects (id), - display_name text - check (length(display_name) <= 128), + is_organization boolean generated always as (true) stored, + avatar_id uuid references storage.objects (id), + display_name text check (length(display_name) <= 128), bio text check (length(bio) <= 512), contact_email app.email_address, - created_at timestamp with time zone - not null - default NOW(), - constraint "fk_handle_registry" - foreign key - (handle, - is_organization) - references app.handle_registry (handle, - is_organization) + created_at timestamptz not null default now(), + constraint fk_handle_registry foreign key (handle, is_organization) + references app.handle_registry (handle, is_organization) ); create type app.membership_role as enum ('maintainer'); create table app.members ( - id uuid - primary key - default uuid_generate_v4(), - organization_id uuid - not null - references app.organizations (id), - account_id uuid - not null - references app.accounts (id), + id uuid primary key default uuid_generate_v4(), + organization_id uuid not null references app.organizations (id), + account_id uuid not null references app.accounts (id), role app.membership_role not null, - created_at timestamp with time zone - not null - default NOW(), + created_at timestamptz not null default now(), unique (organization_id, account_id) ); @@ -116,14 +82,14 @@ create or replace function app.register_organization_creator_as_member() returns trigger language plpgsql security definer -as $function$ -begin +as $$ + begin insert into app.members(organization_id, account_id, role) values (new.id, auth.uid(), 'maintainer'); return new; end; -$function$; + $$; create or replace trigger on_app_organization_created after insert @@ -135,8 +101,8 @@ create or replace function app.update_avatar_id() returns trigger language plpgsql security definer -as $function$ -declare +as $$ + declare v_handle app.valid_name; v_affected_account app.accounts := null; begin @@ -162,7 +128,7 @@ declare return new; end; -$function$; + $$; create or replace trigger on_storage_object_created after insert diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142137_package_tables_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142137_package_tables_100.snap index 2430b419a..700ac3530 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142137_package_tables_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142137_package_tables_100.snap @@ -3,102 +3,69 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20220117142137_package_tables.sql --- insert into storage.buckets (id, name) -values - ('package_versions', 'package_versions'), - ('package_upgrades', 'package_upgrades'); +values ('package_versions', 'package_versions'), ('package_upgrades', 'package_upgrades'); create function app.to_package_name(handle app.valid_name, partial_name app.valid_name) returns text language sql immutable -as $function$ -select format('%s-%s', $1, $2) -$function$; +as $$ + select format('%s-%s', $1, $2) +$$; create table app.packages ( id uuid primary key default gen_random_uuid(), - package_name text - not null - generated always as (app.to_package_name(handle, partial_name)) stored, - handle app.valid_name - not null - references app.handle_registry (handle), + package_name text not null generated always as (app.to_package_name(handle, partial_name)) stored, + handle app.valid_name not null references app.handle_registry (handle), partial_name app.valid_name not null, control_description varchar(1000), - control_relocatable boolean not null default false, - control_requires varchar(128)[] - default cast('{}' as varchar(128)[]), - created_at timestamp with time zone - not null - default NOW(), + control_relocatable bool not null default false, + control_requires varchar(128)[] default cast('{}' as varchar(128)[]), + created_at timestamptz not null default now(), unique (handle, partial_name) ); -create index "packages_partial_name_search_idx" -on app.packages -using gin -( +create index packages_partial_name_search_idx on app.packages using gin ( partial_name extensions.gin_trgm_ops ); -create index "packages_handle_search_idx" -on app.packages -using gin -( - handle extensions.gin_trgm_ops -); +create index packages_handle_search_idx on app.packages using gin (handle extensions.gin_trgm_ops); create table app.package_versions ( id uuid primary key default gen_random_uuid(), - package_id uuid - not null - references app.packages (id), + package_id uuid not null references app.packages (id), version_struct app.semver not null, - version text - not null - generated always as (app.semver_to_text(version_struct)) stored, + version text not null generated always as (app.semver_to_text(version_struct)) stored, sql varchar(250000), description_md varchar(250000), - created_at timestamp with time zone - not null - default NOW(), + created_at timestamptz not null default now(), unique (package_id, version_struct) ); create table app.package_upgrades ( id uuid primary key default gen_random_uuid(), - package_id uuid - not null - references app.packages (id), + package_id uuid not null references app.packages (id), from_version_struct app.semver not null, - from_version text - not null - generated always as (app.semver_to_text(from_version_struct)) stored, + from_version text not null generated always as (app.semver_to_text(from_version_struct)) stored, to_version_struct app.semver not null, - to_version text - not null - generated always as (app.semver_to_text(to_version_struct)) stored, + to_version text not null generated always as (app.semver_to_text(to_version_struct)) stored, sql varchar(250000), - created_at timestamp with time zone - not null - default NOW(), - unique (package_id, - from_version_struct, - to_version_struct) + created_at timestamptz not null default now(), + unique (package_id, from_version_struct, to_version_struct) ); create function app.version_text_to_handle(version text) returns app.valid_name language sql immutable -as $function$ -select split_part($1, '-', 1) -$function$; +as $$ + select split_part($1, '-', 1) +$$; create function app.version_text_to_package_partial_name(version text) returns app.valid_name language sql immutable -as $function$ -select split_part($1, '--', 2) -$function$; +as $$ + select split_part($1, '--', 2) +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142137_package_tables_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142137_package_tables_80.snap index d11509aaf..3c0b20f2d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142137_package_tables_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142137_package_tables_80.snap @@ -15,105 +15,73 @@ app.to_package_name( returns text language sql immutable -as $function$ -select format('%s-%s', $1, $2) -$function$; +as $$ + select format('%s-%s', $1, $2) +$$; create table app.packages ( - id uuid - primary key - default gen_random_uuid(), + id uuid primary key default gen_random_uuid(), package_name text - not null - generated always as (app.to_package_name( - handle, - partial_name - )) stored, - handle app.valid_name - not null - references app.handle_registry (handle), + not null + generated always as (app.to_package_name(handle, partial_name)) stored, + handle app.valid_name not null references app.handle_registry (handle), partial_name app.valid_name not null, control_description varchar(1000), - control_relocatable boolean - not null - default false, - control_requires varchar(128)[] - default cast('{}' as varchar(128)[]), - created_at timestamp with time zone - not null - default NOW(), + control_relocatable bool not null default false, + control_requires varchar(128)[] default cast('{}' as varchar(128)[]), + created_at timestamptz not null default now(), unique (handle, partial_name) ); -create index "packages_partial_name_search_idx" -on app.packages -using gin -( +create index packages_partial_name_search_idx on app.packages using gin ( partial_name extensions.gin_trgm_ops ); -create index "packages_handle_search_idx" -on app.packages -using gin -( +create index packages_handle_search_idx on app.packages using gin ( handle extensions.gin_trgm_ops ); create table app.package_versions ( - id uuid - primary key - default gen_random_uuid(), - package_id uuid - not null - references app.packages (id), + id uuid primary key default gen_random_uuid(), + package_id uuid not null references app.packages (id), version_struct app.semver not null, version text - not null - generated always as (app.semver_to_text(version_struct)) stored, + not null + generated always as (app.semver_to_text(version_struct)) stored, sql varchar(250000), description_md varchar(250000), - created_at timestamp with time zone - not null - default NOW(), + created_at timestamptz not null default now(), unique (package_id, version_struct) ); create table app.package_upgrades ( - id uuid - primary key - default gen_random_uuid(), - package_id uuid - not null - references app.packages (id), + id uuid primary key default gen_random_uuid(), + package_id uuid not null references app.packages (id), from_version_struct app.semver not null, from_version text - not null - generated always as (app.semver_to_text(from_version_struct)) stored, + not null + generated always as (app.semver_to_text(from_version_struct)) stored, to_version_struct app.semver not null, to_version text - not null - generated always as (app.semver_to_text(to_version_struct)) stored, + not null + generated always as (app.semver_to_text(to_version_struct)) stored, sql varchar(250000), - created_at timestamp with time zone - not null - default NOW(), - unique (package_id, - from_version_struct, - to_version_struct) + created_at timestamptz not null default now(), + unique (package_id, from_version_struct, to_version_struct) ); create function app.version_text_to_handle(version text) returns app.valid_name language sql immutable -as $function$ -select split_part($1, '-', 1) -$function$; +as $$ + select split_part($1, '-', 1) +$$; create function app.version_text_to_package_partial_name(version text) returns app.valid_name language sql immutable -as $function$ -select split_part($1, '--', 2) -$function$; +as $$ + select split_part($1, '--', 2) +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142138_developer_tools_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142138_developer_tools_100.snap index 0964d7649..e4d0f0218 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142138_developer_tools_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142138_developer_tools_100.snap @@ -5,8 +5,8 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20220117142138_developer_t create or replace function app.simulate_login(email citext) returns void language sql -as $function$ -/* +as $$ + /* Simulated JWT of logged in user */ @@ -29,4 +29,4 @@ as $function$ true ), set_config('role', 'authenticated', true) -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142138_developer_tools_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142138_developer_tools_80.snap index 0964d7649..e4d0f0218 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142138_developer_tools_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142138_developer_tools_80.snap @@ -5,8 +5,8 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20220117142138_developer_t create or replace function app.simulate_login(email citext) returns void language sql -as $function$ -/* +as $$ + /* Simulated JWT of logged in user */ @@ -29,4 +29,4 @@ as $function$ true ), set_config('role', 'authenticated', true) -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142141_security_utilities_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142141_security_utilities_100.snap index 264efaf5a..5b544d500 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142141_security_utilities_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142141_security_utilities_100.snap @@ -6,8 +6,8 @@ create function app.is_organization_maintainer(account_id uuid, organization_id returns boolean language sql stable -as $function$ --- Does the currently authenticated user have permission to admin orgs and org members? +as $$ + -- Does the currently authenticated user have permission to admin orgs and org members? select exists( select @@ -19,14 +19,14 @@ as $function$ and m.organization_id = $2 and m.role = 'maintainer' ) -$function$; +$$; create function app.is_handle_maintainer(account_id uuid, handle app.valid_name) returns boolean language sql stable -as $function$ -select +as $$ + select exists( select 1 @@ -48,14 +48,14 @@ select and m.account_id = $1 and o.handle = $2 ) -$function$; +$$; create function app.is_package_maintainer(account_id uuid, package_id uuid) returns boolean language sql stable -as $function$ -select +as $$ + select exists( select 1 @@ -82,17 +82,17 @@ select and m.account_id = $1 and p.id = $2 ) -$function$; +$$; create function app.is_package_version_maintainer(account_id uuid, package_version_id uuid) returns boolean language sql stable -as $function$ -select +as $$ + select app.is_package_maintainer($1, pv.package_id) from app.package_versions pv where pv.id = $2 -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142141_security_utilities_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142141_security_utilities_80.snap index a35e88350..23bd46e7d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142141_security_utilities_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142141_security_utilities_80.snap @@ -10,8 +10,8 @@ app.is_organization_maintainer( returns boolean language sql stable -as $function$ --- Does the currently authenticated user have permission to admin orgs and org members? +as $$ + -- Does the currently authenticated user have permission to admin orgs and org members? select exists( select @@ -23,14 +23,14 @@ as $function$ and m.organization_id = $2 and m.role = 'maintainer' ) -$function$; +$$; create function app.is_handle_maintainer(account_id uuid, handle app.valid_name) returns boolean language sql stable -as $function$ -select +as $$ + select exists( select 1 @@ -52,14 +52,14 @@ select and m.account_id = $1 and o.handle = $2 ) -$function$; +$$; create function app.is_package_maintainer(account_id uuid, package_id uuid) returns boolean language sql stable -as $function$ -select +as $$ + select exists( select 1 @@ -86,7 +86,7 @@ select and m.account_id = $1 and p.id = $2 ) -$function$; +$$; create function app.is_package_version_maintainer( @@ -96,11 +96,11 @@ app.is_package_version_maintainer( returns boolean language sql stable -as $function$ -select +as $$ + select app.is_package_maintainer($1, pv.package_id) from app.package_versions pv where pv.id = $2 -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142142_security_definitions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142142_security_definitions_100.snap index fd4842bcc..37cbb5638 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142142_security_definitions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142142_security_definitions_100.snap @@ -2,12 +2,12 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20220117142142_security_definitions.sql --- -grant INSERT (handle, is_organization) on table app.handle_registry to authenticated; +grant insert (handle, is_organization) on table app.handle_registry to authenticated; alter table app.accounts enable row level security; -grant UPDATE (avatar_id, display_name, bio, contact_email) on table app.accounts to authenticated; +grant update (avatar_id, display_name, bio, contact_email) on table app.accounts to authenticated; create policy accounts_update_policy on app.accounts @@ -26,18 +26,11 @@ using (true); alter table app.organizations enable row level security; -grant INSERT (handle, -avatar_id, -display_name, -bio, -contact_email) +grant insert (handle, avatar_id, display_name, bio, contact_email) on table app.organizations to authenticated; -grant UPDATE (avatar_id, -display_name, -bio, -contact_email) +grant update (avatar_id, display_name, bio, contact_email) on table app.organizations to authenticated; @@ -65,29 +58,23 @@ using (true); alter table app.members enable row level security; -grant INSERT (organization_id, account_id, role) on table app.members to authenticated; +grant insert (organization_id, account_id, role) on table app.members to authenticated; -grant DELETE on table app.members to authenticated; +grant delete on table app.members to authenticated; create policy members_insert_policy on app.members as permissive for insert to authenticated -with check (app.is_organization_maintainer( - auth.uid(), - organization_id -)); +with check (app.is_organization_maintainer(auth.uid(), organization_id)); create policy members_delete_policy on app.members as permissive for delete to authenticated -using (app.is_organization_maintainer( - auth.uid(), - organization_id -)); +using (app.is_organization_maintainer(auth.uid(), organization_id)); create policy members_select_policy on app.members @@ -99,7 +86,7 @@ using (true); alter table app.packages enable row level security; -grant INSERT (partial_name, handle) on table app.packages to authenticated; +grant insert (partial_name, handle) on table app.packages to authenticated; create policy package_insert_policy on app.packages @@ -118,10 +105,7 @@ using (true); alter table app.package_versions enable row level security; -grant INSERT (package_id, -version_struct, -sql, -description_md) +grant insert (package_id, version_struct, sql, description_md) on table app.package_versions to authenticated; @@ -149,10 +133,7 @@ using (true); alter table app.package_upgrades enable row level security; -grant INSERT (package_id, -from_version_struct, -to_version_struct, -sql) +grant insert (package_id, from_version_struct, to_version_struct, sql) on table app.package_upgrades to authenticated; @@ -184,8 +165,7 @@ for insert to authenticated with check (app.is_handle_maintainer( auth.uid(), - cast((string_to_array(name, cast('-' as text)))[1] - as app.valid_name) + cast((string_to_array(name, cast('-' as text)))[1] as app.valid_name) )); create policy storage_objects_select_policy diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142142_security_definitions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142142_security_definitions_80.snap index 39a2f7a1d..d53a5561c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142142_security_definitions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117142142_security_definitions_80.snap @@ -2,18 +2,14 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20220117142142_security_definitions.sql --- -grant INSERT (handle, -is_organization) +grant insert (handle, is_organization) on table app.handle_registry to authenticated; alter table app.accounts enable row level security; -grant UPDATE (avatar_id, -display_name, -bio, -contact_email) +grant update (avatar_id, display_name, bio, contact_email) on table app.accounts to authenticated; @@ -34,18 +30,11 @@ using (true); alter table app.organizations enable row level security; -grant INSERT (handle, -avatar_id, -display_name, -bio, -contact_email) +grant insert (handle, avatar_id, display_name, bio, contact_email) on table app.organizations to authenticated; -grant UPDATE (avatar_id, -display_name, -bio, -contact_email) +grant update (avatar_id, display_name, bio, contact_email) on table app.organizations to authenticated; @@ -61,10 +50,7 @@ on app.organizations as permissive for update to authenticated -using (app.is_organization_maintainer( - auth.uid(), - id -)); +using (app.is_organization_maintainer(auth.uid(), id)); create policy organizations_select_policy on app.organizations @@ -76,33 +62,25 @@ using (true); alter table app.members enable row level security; -grant INSERT (organization_id, -account_id, -role) +grant insert (organization_id, account_id, role) on table app.members to authenticated; -grant DELETE on table app.members to authenticated; +grant delete on table app.members to authenticated; create policy members_insert_policy on app.members as permissive for insert to authenticated -with check (app.is_organization_maintainer( - auth.uid(), - organization_id -)); +with check (app.is_organization_maintainer(auth.uid(), organization_id)); create policy members_delete_policy on app.members as permissive for delete to authenticated -using (app.is_organization_maintainer( - auth.uid(), - organization_id -)); +using (app.is_organization_maintainer(auth.uid(), organization_id)); create policy members_select_policy on app.members @@ -114,17 +92,14 @@ using (true); alter table app.packages enable row level security; -grant INSERT (partial_name, handle) on table app.packages to authenticated; +grant insert (partial_name, handle) on table app.packages to authenticated; create policy package_insert_policy on app.packages as permissive for insert to authenticated -with check (app.is_handle_maintainer( - auth.uid(), - handle -)); +with check (app.is_handle_maintainer(auth.uid(), handle)); create policy packages_select_policy on app.packages @@ -136,10 +111,7 @@ using (true); alter table app.package_versions enable row level security; -grant INSERT (package_id, -version_struct, -sql, -description_md) +grant insert (package_id, version_struct, sql, description_md) on table app.package_versions to authenticated; @@ -148,20 +120,14 @@ on app.package_versions as permissive for insert to authenticated -with check (app.is_package_maintainer( - auth.uid(), - package_id -)); +with check (app.is_package_maintainer(auth.uid(), package_id)); create policy package_versions_update_policy on app.package_versions as permissive for update to authenticated -using (app.is_package_maintainer( - auth.uid(), - package_id -)); +using (app.is_package_maintainer(auth.uid(), package_id)); create policy package_versions_select_policy on app.package_versions @@ -173,10 +139,7 @@ using (true); alter table app.package_upgrades enable row level security; -grant INSERT (package_id, -from_version_struct, -to_version_struct, -sql) +grant insert (package_id, from_version_struct, to_version_struct, sql) on table app.package_upgrades to authenticated; @@ -185,20 +148,14 @@ on app.package_upgrades as permissive for insert to authenticated -with check (app.is_package_maintainer( - auth.uid(), - package_id -)); +with check (app.is_package_maintainer(auth.uid(), package_id)); create policy package_upgrades_update_policy on app.package_upgrades as permissive for update to authenticated -using (app.is_package_maintainer( - auth.uid(), - package_id -)); +using (app.is_package_maintainer(auth.uid(), package_id)); create policy package_upgrades_select_policy on app.package_upgrades @@ -214,8 +171,7 @@ for insert to authenticated with check (app.is_handle_maintainer( auth.uid(), - cast((string_to_array(name, cast('-' as text)))[1] - as app.valid_name) + cast((string_to_array(name, cast('-' as text)))[1] as app.valid_name) )); create policy storage_objects_select_policy diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155720_views_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155720_views_100.snap index 6835dfec5..213c24b07 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155720_views_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155720_views_100.snap @@ -12,10 +12,7 @@ as select acc.contact_email, acc.created_at from - app.accounts as acc - left outer join - storage.objects as obj - on acc.avatar_id = obj.id; + app.accounts as acc left outer join storage.objects as obj on acc.avatar_id = obj.id; create view public.organizations as select @@ -27,19 +24,10 @@ as select org.contact_email, org.created_at from - app.organizations as org - left outer join - storage.objects as obj - on org.avatar_id = obj.id; + app.organizations as org left outer join storage.objects as obj on org.avatar_id = obj.id; create view public.members -as select - aio.organization_id, - aio.account_id, - aio.role, - aio.created_at -from - app.members as aio; +as select aio.organization_id, aio.account_id, aio.role, aio.created_at from app.members as aio; create view public.packages as select @@ -78,10 +66,7 @@ as select pa.control_requires, pv.created_at from - app.packages as pa - inner join - app.package_versions as pv - on pa.id = pv.package_id; + app.packages as pa inner join app.package_versions as pv on pa.id = pv.package_id; create view public.package_upgrades as select @@ -93,7 +78,4 @@ as select pu.sql, pu.created_at from - app.packages as pa - inner join - app.package_upgrades as pu - on pa.id = pu.package_id; + app.packages as pa inner join app.package_upgrades as pu on pa.id = pu.package_id; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155820_rpc_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155820_rpc_100.snap index 821d10d8a..22212ca24 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155820_rpc_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155820_rpc_100.snap @@ -10,8 +10,8 @@ public.search_packages( returns setof public.packages language sql stable -as $function$ -select * +as $$ + select * from public.packages where ($1 is null or handle <% $1 or handle ~ $1) @@ -20,4 +20,4 @@ select * order by coalesce(extensions.similarity($1, handle), 0) + coalesce(extensions.similarity($2, partial_name), 0) desc, created_at desc; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155820_rpc_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155820_rpc_80.snap index 821d10d8a..22212ca24 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155820_rpc_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20220117155820_rpc_80.snap @@ -10,8 +10,8 @@ public.search_packages( returns setof public.packages language sql stable -as $function$ -select * +as $$ + select * from public.packages where ($1 is null or handle <% $1 or handle ~ $1) @@ -20,4 +20,4 @@ select * order by coalesce(extensions.similarity($1, handle), 0) + coalesce(extensions.similarity($2, partial_name), 0) desc, created_at desc; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230323180034_reserved_user_accts_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230323180034_reserved_user_accts_100.snap index 7d9ff0b71..b9198b961 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230323180034_reserved_user_accts_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230323180034_reserved_user_accts_100.snap @@ -22,7 +22,7 @@ values 'authenticated', 'oliver@oliverrice.com', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "olirice", "display_name": "Oli", "bio": "Supabase Staff"}', false @@ -34,7 +34,7 @@ values 'authenticated', 'alaister@supabase.io', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "alaister", "display_name": "Alaister", "bio": "Supabase Staff"}', false @@ -46,7 +46,7 @@ values 'authenticated', 'copple@supabase.io', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "kiwicopple", "display_name": "Copple", "bio": "Supabase Staff"}', false @@ -58,7 +58,7 @@ values 'authenticated', 'michel@supabase.io', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "michelp", "display_name": "Michele", "bio": "Supabase Staff"}', false @@ -70,7 +70,7 @@ values 'authenticated', 'mark@supabase.io', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "burggraf", "display_name": "Mark", "bio": "Supabase Staff"}', false @@ -110,12 +110,7 @@ begin; select app.simulate_login('oliver@oliverrice.com'); insert into app.organizations (handle, display_name, bio) -values - ( - 'supabase', - 'Supabase', - 'Build in a weekend, scale to millions' - ); +values ('supabase', 'Supabase', 'Build in a weekend, scale to millions'); commit; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230323180034_reserved_user_accts_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230323180034_reserved_user_accts_80.snap index 7d9ff0b71..b9198b961 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230323180034_reserved_user_accts_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230323180034_reserved_user_accts_80.snap @@ -22,7 +22,7 @@ values 'authenticated', 'oliver@oliverrice.com', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "olirice", "display_name": "Oli", "bio": "Supabase Staff"}', false @@ -34,7 +34,7 @@ values 'authenticated', 'alaister@supabase.io', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "alaister", "display_name": "Alaister", "bio": "Supabase Staff"}', false @@ -46,7 +46,7 @@ values 'authenticated', 'copple@supabase.io', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "kiwicopple", "display_name": "Copple", "bio": "Supabase Staff"}', false @@ -58,7 +58,7 @@ values 'authenticated', 'michel@supabase.io', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "michelp", "display_name": "Michele", "bio": "Supabase Staff"}', false @@ -70,7 +70,7 @@ values 'authenticated', 'mark@supabase.io', 'TBD', - NOW(), + now(), '{"provider": "email", "providers": ["email"]}', '{"handle": "burggraf", "display_name": "Mark", "bio": "Supabase Staff"}', false @@ -110,12 +110,7 @@ begin; select app.simulate_login('oliver@oliverrice.com'); insert into app.organizations (handle, display_name, bio) -values - ( - 'supabase', - 'Supabase', - 'Build in a weekend, scale to millions' - ); +values ('supabase', 'Supabase', 'Build in a weekend, scale to millions'); commit; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230328185043_olirice_asciiplot_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230328185043_olirice_asciiplot_100.snap index c6cddcfbf..704a86c59 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230328185043_olirice_asciiplot_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230328185043_olirice_asciiplot_100.snap @@ -9,28 +9,10 @@ insert into app.packages ( control_relocatable, control_requires ) -values - ( - 'olirice', - 'asciiplot', - 'A Toy ASCII Plotting Library', - false, - '{}' - ); +values ('olirice', 'asciiplot', 'A Toy ASCII Plotting Library', false, '{}'); insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'olirice-asciiplot' - ), - (0, 0, 1), - ' +values ((select id from app.packages where package_name = 'olirice-asciiplot'), (0, 0, 1), ' CREATE TYPE scatter_state AS ( x_arr NUMERIC[], y_arr NUMERIC[], @@ -124,8 +106,7 @@ CREATE AGGREGATE scatter( comment on type scatter_state is e''internal''; -', - ' +', ' # asciiplot asciiplot is a toy library for producing ASCII scatterplots from PostgreSQL queries. @@ -164,28 +145,10 @@ from | * */ ``` -' - ); +'); -insert into app.package_upgrades ( - package_id, - from_version_struct, - to_version_struct, - sql -) +insert into app.package_upgrades (package_id, from_version_struct, to_version_struct, sql) values - ( - ( - select - id - from - app.packages - where - package_name = 'olirice-asciiplot' - ), - (0, 0, 1), - (0, 0, 2), - ' + ((select id from app.packages where package_name = 'olirice-asciiplot'), (0, 0, 1), (0, 0, 2), ' comment on type scatter_state is e''internal''; -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230328185043_olirice_asciiplot_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230328185043_olirice_asciiplot_80.snap index 4b92ffdcb..7a3a38846 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230328185043_olirice_asciiplot_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230328185043_olirice_asciiplot_80.snap @@ -9,14 +9,7 @@ insert into app.packages ( control_relocatable, control_requires ) -values - ( - 'olirice', - 'asciiplot', - 'A Toy ASCII Plotting Library', - false, - '{}' - ); +values ('olirice', 'asciiplot', 'A Toy ASCII Plotting Library', false, '{}'); insert into app.package_versions ( package_id, @@ -26,14 +19,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'olirice-asciiplot' - ), + (select id from app.packages where package_name = 'olirice-asciiplot'), (0, 0, 1), ' CREATE TYPE scatter_state AS ( @@ -180,14 +166,7 @@ insert into app.package_upgrades ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'olirice-asciiplot' - ), + (select id from app.packages where package_name = 'olirice-asciiplot'), (0, 0, 1), (0, 0, 2), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230330155137_supabase_dbdev_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230330155137_supabase_dbdev_100.snap index 6d46331e8..d173bf9df 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230330155137_supabase_dbdev_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230330155137_supabase_dbdev_100.snap @@ -9,28 +9,10 @@ insert into app.packages ( control_relocatable, control_requires ) -values - ( - 'supabase', - 'dbdev', - 'Install pacakges from the dbdev package index', - false, - '{}' - ); +values ('supabase', 'dbdev', 'Install pacakges from the dbdev package index', false, '{}'); insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'supabase-dbdev' - ), - (0, 0, 2), - ' +values ((select id from app.packages where package_name = 'supabase-dbdev'), (0, 0, 2), ' create schema dbdev; @@ -206,8 +188,7 @@ begin end; $$; -', - ' +', ' # dbdev dbdev is the SQL client for database.new and is the primary way end users interact with the package (pglet) registry. @@ -297,5 +278,4 @@ create extension "handle-package_name" schema ''public'' version ''1.2.3''; ``` -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230330155137_supabase_dbdev_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230330155137_supabase_dbdev_80.snap index 9bdbf8219..30e0dff2b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230330155137_supabase_dbdev_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230330155137_supabase_dbdev_80.snap @@ -26,14 +26,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'supabase-dbdev' - ), + (select id from app.packages where package_name = 'supabase-dbdev'), (0, 0, 2), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331145934_burggraf-pg_headerkit_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331145934_burggraf-pg_headerkit_100.snap index 56117f4f5..b5d033c90 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331145934_burggraf-pg_headerkit_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331145934_burggraf-pg_headerkit_100.snap @@ -19,18 +19,7 @@ values ); insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'burggraf-pg_headerkit' - ), - (1, 0, 0), - ' +values ((select id from app.packages where package_name = 'burggraf-pg_headerkit'), (1, 0, 0), ' CREATE SCHEMA IF NOT EXISTS hdr; CREATE TABLE IF NOT EXISTS hdr.allow_list ( @@ -231,8 +220,7 @@ CREATE OR REPLACE FUNCTION hdr.is_android() RETURNS boolean SELECT hdr.header(''user-agent'') ILIKE ''%android%'' $$; -', - ' +', ' # pg_headerkit: PostgREST Header Kit A set of functions for adding special features to your application that use PostgREST API calls to your PostgreSQL database. These functions can be used inside PostgreSQL functions that can give your application the following capabilities at the database level: @@ -273,5 +261,4 @@ See: [PostgREST Header Hacking](https://github.com/burggraf/postgrest-header-hac | hdr.is_iphone() | is iphone? | none | boolean | | hdr.is_ipad() | is ipad? | none | boolean | | hdr.is_android() | is android? | none | boolean | -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331145934_burggraf-pg_headerkit_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331145934_burggraf-pg_headerkit_80.snap index 519b0d147..3d2f1ab1e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331145934_burggraf-pg_headerkit_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331145934_burggraf-pg_headerkit_80.snap @@ -26,14 +26,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'burggraf-pg_headerkit' - ), + (select id from app.packages where package_name = 'burggraf-pg_headerkit'), (1, 0, 0), ' CREATE SCHEMA IF NOT EXISTS hdr; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163908_olirice-index_advisor_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163908_olirice-index_advisor_100.snap index da68b86e8..5ddfeb10d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163908_olirice-index_advisor_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163908_olirice-index_advisor_100.snap @@ -9,28 +9,10 @@ insert into app.packages ( control_relocatable, control_requires ) -values - ( - 'olirice', - 'index_advisor', - 'Recommend indexes for a given SQL query', - true, - '{hypopg}' - ); +values ('olirice', 'index_advisor', 'Recommend indexes for a given SQL query', true, '{hypopg}'); insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'olirice-index_advisor' - ), - (0, 1, 0), - ' +values ((select id from app.packages where package_name = 'olirice-index_advisor'), (0, 1, 0), ' -- Enforce requirements @@ -215,8 +197,7 @@ begin end; $$; -', - ' +', ' # index_advisor @@ -330,5 +311,4 @@ returns #### Description For a given *query*, searches for a set of SQL DDL `create index` statements that improve the query''s execution time; -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163908_olirice-index_advisor_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163908_olirice-index_advisor_80.snap index fb253ab4f..912874af9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163908_olirice-index_advisor_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163908_olirice-index_advisor_80.snap @@ -26,14 +26,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'olirice-index_advisor' - ), + (select id from app.packages where package_name = 'olirice-index_advisor'), (0, 1, 0), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163909_olirice-read_once_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163909_olirice-read_once_100.snap index c7b46dd26..349e45a1f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163909_olirice-read_once_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163909_olirice-read_once_100.snap @@ -9,28 +9,10 @@ insert into app.packages ( control_relocatable, control_requires ) -values - ( - 'olirice', - 'read_once', - 'Send messages that can only be read once', - false, - '{pg_cron}' - ); +values ('olirice', 'read_once', 'Send messages that can only be read once', false, '{pg_cron}'); insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'olirice-read_once' - ), - (0, 3, 1), - ' +values ((select id from app.packages where package_name = 'olirice-read_once'), (0, 3, 1), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 @@ -92,8 +74,7 @@ $$ where read_once.messages.id = $1 returning contents; $$ -', - ' +', ' # read_once @@ -168,5 +149,4 @@ create or replace function read_message( ) returns text ``` -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163909_olirice-read_once_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163909_olirice-read_once_80.snap index 002c8e806..0950da36c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163909_olirice-read_once_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230331163909_olirice-read_once_80.snap @@ -26,14 +26,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'olirice-read_once' - ), + (select id from app.packages where package_name = 'olirice-read_once'), (0, 3, 1), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230404162614_michelp-adminpack_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230404162614_michelp-adminpack_100.snap index 1f5b37208..de4510637 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230404162614_michelp-adminpack_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230404162614_michelp-adminpack_100.snap @@ -19,18 +19,7 @@ values ); insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'michelp-adminpack' - ), - (0, 0, 1), - ' +values ((select id from app.packages where package_name = 'michelp-adminpack'), (0, 0, 1), ' -- From: https://github.com/ioguix/pgsql-bloat-estimation -- Copyright (c) 2015-2019, Jehan-Guillaume (ioguix) de Rorthais @@ -1076,8 +1065,7 @@ FROM JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = ''v''; -', - ' +', ' # michelp-adminpack A Trusted Language Extension containing a variety of useful databse admin queries. @@ -1578,5 +1566,4 @@ This view shows all views in the database. | name | name | | is_updatable | boolean | | comment | text | -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230404162614_michelp-adminpack_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230404162614_michelp-adminpack_80.snap index e57df25d9..8fc7b63f9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230404162614_michelp-adminpack_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230404162614_michelp-adminpack_80.snap @@ -26,14 +26,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'michelp-adminpack' - ), + (select id from app.packages where package_name = 'michelp-adminpack'), (0, 0, 1), ' -- From: https://github.com/ioguix/pgsql-bloat-estimation diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405083103_fix_auth_schema_values_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405083103_fix_auth_schema_values_100.snap index 98e95001f..9e62f5e3b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405083103_fix_auth_schema_values_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405083103_fix_auth_schema_values_100.snap @@ -3,9 +3,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20230405083103_fix_auth_schema_values.sql --- update auth.users -set created_at = NOW(), -updated_at = NOW(), -email_confirmed_at = NOW(), +set created_at = now(), +updated_at = now(), +email_confirmed_at = now(), confirmation_token = '', recovery_token = '', email_change_token_new = '', @@ -25,8 +25,7 @@ select email, 'email' as provider, id as user_id, - jsonb_build_object('sub', id, 'email', email) - as identity_data, + jsonb_build_object('sub', id, 'email', email) as identity_data, created_at, updated_at from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405083103_fix_auth_schema_values_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405083103_fix_auth_schema_values_80.snap index 7cd722eb6..9e62f5e3b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405083103_fix_auth_schema_values_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405083103_fix_auth_schema_values_80.snap @@ -3,9 +3,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20230405083103_fix_auth_schema_values.sql --- update auth.users -set created_at = NOW(), -updated_at = NOW(), -email_confirmed_at = NOW(), +set created_at = now(), +updated_at = now(), +email_confirmed_at = now(), confirmation_token = '', recovery_token = '', email_change_token_new = '', @@ -25,11 +25,7 @@ select email, 'email' as provider, id as user_id, - jsonb_build_object( - 'sub', id, - 'email', email - ) - as identity_data, + jsonb_build_object('sub', id, 'email', email) as identity_data, created_at, updated_at from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405085810_fix_avatars_handle_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405085810_fix_avatars_handle_100.snap index fc7d786d4..86f7b33bd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405085810_fix_avatars_handle_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405085810_fix_avatars_handle_100.snap @@ -6,8 +6,8 @@ create or replace function app.update_avatar_id() returns trigger language plpgsql security definer -as $function$ -declare +as $$ + declare v_handle app.valid_name; v_affected_account app.accounts := null; begin @@ -33,12 +33,11 @@ declare return new; end; -$function$; + $$; alter policy storage_objects_insert_policy on storage.objects with check (app.is_handle_maintainer( auth.uid(), - cast((string_to_array(name, cast('/' as text)))[1] - as app.valid_name) + cast((string_to_array(name, cast('/' as text)))[1] as app.valid_name) )); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405085810_fix_avatars_handle_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405085810_fix_avatars_handle_80.snap index fc7d786d4..86f7b33bd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405085810_fix_avatars_handle_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405085810_fix_avatars_handle_80.snap @@ -6,8 +6,8 @@ create or replace function app.update_avatar_id() returns trigger language plpgsql security definer -as $function$ -declare +as $$ + declare v_handle app.valid_name; v_affected_account app.accounts := null; begin @@ -33,12 +33,11 @@ declare return new; end; -$function$; + $$; alter policy storage_objects_insert_policy on storage.objects with check (app.is_handle_maintainer( auth.uid(), - cast((string_to_array(name, cast('/' as text)))[1] - as app.valid_name) + cast((string_to_array(name, cast('/' as text)))[1] as app.valid_name) )); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405163940_download_metrics_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405163940_download_metrics_100.snap index 25d67fb34..d253bb154 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405163940_download_metrics_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405163940_download_metrics_100.snap @@ -6,89 +6,67 @@ create or replace function app.api_request_headers() returns json language sql stable -as $function$ -select coalesce(current_setting('request.headers', true)::json, '{}'::json); -$function$; +as $$ + select coalesce(current_setting('request.headers', true)::json, '{}'::json); +$$; create or replace function app.api_request_header(text) returns text language sql stable -as $function$ -select app.api_request_headers() ->> $1 -$function$; +as $$ + select app.api_request_headers() ->> $1 +$$; create or replace function app.api_request_ip() returns inet language sql stable -as $function$ -select split_part(app.api_request_header('x-forwarded-for') || ',', ',', 1)::inet -$function$; +as $$ + select split_part(app.api_request_header('x-forwarded-for') || ',', ',', 1)::inet +$$; create or replace function app.api_request_client_info() returns text language sql stable -as $function$ -select app.api_request_header('x-client-info') -$function$; +as $$ + select app.api_request_header('x-client-info') +$$; create table app.downloads ( id uuid primary key default gen_random_uuid(), - package_id uuid - not null - references app.packages (id), - ip inet - not null - default cast(app.api_request_ip() as inet), - client_info text - default app.api_request_client_info(), - created_at timestamp with time zone - not null - default NOW() + package_id uuid not null references app.packages (id), + ip inet not null default cast(app.api_request_ip() as inet), + client_info text default app.api_request_client_info(), + created_at timestamptz not null default now() ); -create index "downloads_package_id_ip" on app.downloads using btree (package_id); +create index downloads_package_id_ip on app.downloads using btree (package_id); -create index "downloads_created_at" on app.downloads using brin (created_at); +create index downloads_created_at on app.downloads using brin (created_at); create or replace function public.register_download(package_name text) returns void language sql security definer -as $function$ -insert into app.downloads(package_id) +as $$ + insert into app.downloads(package_id) select id from app.packages ap where ap.package_name = $1 -$function$; +$$; create materialized view public.download_metrics as select dl.package_id, - COUNT(dl.id) as downloads_all_time, - COUNT( - dl.id - ) - filter (where - dl.created_at > - NOW() - cast('180 days' as interval)) + count(dl.id) as downloads_all_time, + count(dl.id) filter (where dl.created_at > now() - cast('180 days' as interval)) as downloads_180_days, - COUNT( - dl.id - ) - filter (where - dl.created_at > - NOW() - cast('90 days' as interval)) + count(dl.id) filter (where dl.created_at > now() - cast('90 days' as interval)) as downloads_90_days, - COUNT( - dl.id - ) - filter (where - dl.created_at > - NOW() - cast('30 days' as interval)) + count(dl.id) filter (where dl.created_at > now() - cast('30 days' as interval)) as downloads_30_day from app.downloads as dl diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405163940_download_metrics_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405163940_download_metrics_80.snap index 339ac6435..49925ea93 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405163940_download_metrics_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230405163940_download_metrics_80.snap @@ -6,96 +6,79 @@ create or replace function app.api_request_headers() returns json language sql stable -as $function$ -select coalesce(current_setting('request.headers', true)::json, '{}'::json); -$function$; +as $$ + select coalesce(current_setting('request.headers', true)::json, '{}'::json); +$$; create or replace function app.api_request_header(text) returns text language sql stable -as $function$ -select app.api_request_headers() ->> $1 -$function$; +as $$ + select app.api_request_headers() ->> $1 +$$; create or replace function app.api_request_ip() returns inet language sql stable -as $function$ -select split_part(app.api_request_header('x-forwarded-for') || ',', ',', 1)::inet -$function$; +as $$ + select split_part(app.api_request_header('x-forwarded-for') || ',', ',', 1)::inet +$$; create or replace function app.api_request_client_info() returns text language sql stable -as $function$ -select app.api_request_header('x-client-info') -$function$; +as $$ + select app.api_request_header('x-client-info') +$$; create table app.downloads ( - id uuid - primary key - default gen_random_uuid(), - package_id uuid - not null - references app.packages (id), - ip inet - not null - default cast(app.api_request_ip() as inet), - client_info text - default app.api_request_client_info(), - created_at timestamp with time zone - not null - default NOW() + id uuid primary key default gen_random_uuid(), + package_id uuid not null references app.packages (id), + ip inet not null default cast(app.api_request_ip() as inet), + client_info text default app.api_request_client_info(), + created_at timestamptz not null default now() ); -create index "downloads_package_id_ip" -on app.downloads -using btree -( - package_id -); +create index downloads_package_id_ip on app.downloads using btree (package_id); -create index "downloads_created_at" on app.downloads using brin (created_at); +create index downloads_created_at on app.downloads using brin (created_at); create or replace function public.register_download(package_name text) returns void language sql security definer -as $function$ -insert into app.downloads(package_id) +as $$ + insert into app.downloads(package_id) select id from app.packages ap where ap.package_name = $1 -$function$; +$$; create materialized view public.download_metrics as select dl.package_id, - COUNT(dl.id) as downloads_all_time, - COUNT( + count(dl.id) as downloads_all_time, + count( dl.id ) filter (where - dl.created_at > - NOW() - cast('180 days' as interval)) + dl.created_at > now() - cast('180 days' as interval)) as downloads_180_days, - COUNT( + count( dl.id ) filter (where - dl.created_at > - NOW() - cast('90 days' as interval)) + dl.created_at > now() - cast('90 days' as interval)) as downloads_90_days, - COUNT( + count( dl.id ) filter (where - dl.created_at > - NOW() - cast('30 days' as interval)) + dl.created_at > now() - cast('30 days' as interval)) as downloads_30_day from app.downloads as dl diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411104448_download_metrics_computed_relation_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411104448_download_metrics_computed_relation_100.snap index 2d6a2884b..e33301503 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411104448_download_metrics_computed_relation_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411104448_download_metrics_computed_relation_100.snap @@ -7,8 +7,8 @@ returns setof public.download_metrics language sql stable rows 1 -as $function$ -select * +as $$ + select * from public.download_metrics dm where dm.package_id = $1.id; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411104448_download_metrics_computed_relation_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411104448_download_metrics_computed_relation_80.snap index 2d6a2884b..e33301503 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411104448_download_metrics_computed_relation_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411104448_download_metrics_computed_relation_80.snap @@ -7,8 +7,8 @@ returns setof public.download_metrics language sql stable rows 1 -as $function$ -select * +as $$ + select * from public.download_metrics dm where dm.package_id = $1.id; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175952_langchain-embedding_search_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175952_langchain-embedding_search_100.snap index a38f3e7d9..6bc47da31 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175952_langchain-embedding_search_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175952_langchain-embedding_search_100.snap @@ -9,28 +9,11 @@ insert into app.packages ( control_relocatable, control_requires ) -values - ( - 'langchain', - 'embedding_search', - 'Search document embeddings', - true, - '{pg_vector}' - ); +values ('langchain', 'embedding_search', 'Search document embeddings', true, '{pg_vector}'); insert into app.package_versions (package_id, version_struct, sql, description_md) values - ( - ( - select - id - from - app.packages - where - package_name = 'langchain-embedding_search' - ), - (1, 0, 0), - ' + ((select id from app.packages where package_name = 'langchain-embedding_search'), (1, 0, 0), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 do $$ @@ -86,8 +69,7 @@ begin end; $$; -', - ' +', ' # embedding_search [LangChain](https://js.langchain.com/docs/) is a framework for developing applications powered by language models with a plugable architecture. @@ -144,5 +126,4 @@ export const run = async () => { ``` For more details, checkout the LangChain Supabase integration docs: https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175952_langchain-embedding_search_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175952_langchain-embedding_search_80.snap index ee55c63f7..f5fcedee6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175952_langchain-embedding_search_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175952_langchain-embedding_search_80.snap @@ -32,8 +32,7 @@ values from app.packages where - package_name = - 'langchain-embedding_search' + package_name = 'langchain-embedding_search' ), (1, 0, 0), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175953_langchain-hybrid_search_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175953_langchain-hybrid_search_100.snap index 5bd9c4cd2..9241520ae 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175953_langchain-hybrid_search_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175953_langchain-hybrid_search_100.snap @@ -11,26 +11,11 @@ insert into app.packages ( ) values ( - 'langchain', - 'hybrid_search', - 'Search documents by embedding and full text', - true, - '{pg_vector}' + 'langchain', 'hybrid_search', 'Search documents by embedding and full text', true, '{pg_vector}' ); insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'langchain-hybrid_search' - ), - (1, 0, 0), - ' +values ((select id from app.packages where package_name = 'langchain-hybrid_search'), (1, 0, 0), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 do $$ @@ -108,8 +93,7 @@ using query_text, match_count; end; $$ language plpgsql; -', - ' +', ' # hybrid_search Langchain supports hybrid search with a Supabase Postgres database. The hybrid search combines the postgres pgvector extension (similarity search) and Full-Text Search (keyword search) to retrieve documents. You can add documents via SupabaseVectorStore addDocuments function. SupabaseHybridKeyWordSearch accepts embedding, supabase client, number of results for similarity search, and number of results for keyword search as parameters. The getRelevantDocuments function produces a list of documents that has duplicates removed and is sorted by relevance score. @@ -165,5 +149,4 @@ export const run = async () => { ``` For more details, checkout the LangChain Supabase Hybrid Search docs: https://js.langchain.com/docs/modules/indexes/retrievers/supabase-hybrid -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175953_langchain-hybrid_search_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175953_langchain-hybrid_search_80.snap index e822ff902..3bbe0a1c0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175953_langchain-hybrid_search_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230411175953_langchain-hybrid_search_80.snap @@ -27,12 +27,7 @@ insert into app.package_versions ( values ( ( - select - id - from - app.packages - where - package_name = 'langchain-hybrid_search' + select id from app.packages where package_name = 'langchain-hybrid_search' ), (1, 0, 0), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413130634_popular_packages_function_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413130634_popular_packages_function_100.snap index c903d23c6..263a40b90 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413130634_popular_packages_function_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413130634_popular_packages_function_100.snap @@ -6,11 +6,11 @@ create or replace function public.popular_packages() returns setof public.packages language sql stable -as $function$ -select * from public.packages p +as $$ + select * from public.packages p order by ( select (dm.downloads_30_day * 5) + (dm.downloads_90_days * 2) + dm.downloads_180_days from public.download_metrics dm where dm.package_id = p.id ) desc nulls last, p.created_at desc; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413130634_popular_packages_function_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413130634_popular_packages_function_80.snap index c903d23c6..263a40b90 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413130634_popular_packages_function_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413130634_popular_packages_function_80.snap @@ -6,11 +6,11 @@ create or replace function public.popular_packages() returns setof public.packages language sql stable -as $function$ -select * from public.packages p +as $$ + select * from public.packages p order by ( select (dm.downloads_30_day * 5) + (dm.downloads_90_days * 2) + dm.downloads_180_days from public.download_metrics dm where dm.package_id = p.id ) desc nulls last, p.created_at desc; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413140356_update_profile_function_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413140356_update_profile_function_100.snap index 71c869748..ace0e27cf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413140356_update_profile_function_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413140356_update_profile_function_100.snap @@ -10,8 +10,8 @@ public.update_profile( ) returns void language plpgsql -as $function$ -declare +as $$ + declare v_is_org boolean; begin update app.accounts a @@ -24,4 +24,4 @@ declare bio = coalesce($3, o.bio) where o.handle = $1; end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413140356_update_profile_function_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413140356_update_profile_function_80.snap index 71c869748..ace0e27cf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413140356_update_profile_function_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230413140356_update_profile_function_80.snap @@ -10,8 +10,8 @@ public.update_profile( ) returns void language plpgsql -as $function$ -declare +as $$ + declare v_is_org boolean; begin update app.accounts a @@ -24,4 +24,4 @@ declare bio = coalesce($3, o.bio) where o.handle = $1; end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230417141004_dbdev_short_desc_typo_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230417141004_dbdev_short_desc_typo_80.snap index b55a9e58c..c0879f908 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230417141004_dbdev_short_desc_typo_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230417141004_dbdev_short_desc_typo_80.snap @@ -5,5 +5,4 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20230417141004_dbdev_short update app.packages set control_description = 'Install packages from the database.dev registry' where - handle = 'supabase' and - partial_name = 'dbdev'; + handle = 'supabase' and partial_name = 'dbdev'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175952_langchain-embedding_search-1_1_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175952_langchain-embedding_search-1_1_0_100.snap index c18b7bb35..f9ad23670 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175952_langchain-embedding_search-1_1_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175952_langchain-embedding_search-1_1_0_100.snap @@ -4,17 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20230508175952_langchain-e --- insert into app.package_versions (package_id, version_struct, sql, description_md) values - ( - ( - select - id - from - app.packages - where - package_name = 'langchain-embedding_search' - ), - (1, 1, 0), - ' + ((select id from app.packages where package_name = 'langchain-embedding_search'), (1, 1, 0), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 do $$ @@ -72,8 +62,7 @@ begin end; $$; -', - ' +', ' # embedding_search [LangChain](https://js.langchain.com/docs/) is a framework for developing applications powered by language models with a plugable architecture. @@ -174,5 +163,4 @@ export const run = async () => { ``` For more details, checkout the LangChain Supabase integration docs: https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175952_langchain-embedding_search-1_1_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175952_langchain-embedding_search-1_1_0_80.snap index e27d04d07..89c8078dc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175952_langchain-embedding_search-1_1_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175952_langchain-embedding_search-1_1_0_80.snap @@ -16,8 +16,7 @@ values from app.packages where - package_name = - 'langchain-embedding_search' + package_name = 'langchain-embedding_search' ), (1, 1, 0), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175953_langchain-hybrid_search-1_1_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175953_langchain-hybrid_search-1_1_0_100.snap index 17afaf4e8..680b2244b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175953_langchain-hybrid_search-1_1_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175953_langchain-hybrid_search-1_1_0_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20230508175953_langchain-hybrid_search-1_1_0.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'langchain-hybrid_search' - ), - (1, 1, 0), - ' +values ((select id from app.packages where package_name = 'langchain-hybrid_search'), (1, 1, 0), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 do $$ @@ -94,8 +83,7 @@ using query_text, match_count; end; $$ language plpgsql; -', - ' +', ' # hybrid_search Langchain supports hybrid search with a Supabase Postgres database. The hybrid search combines the postgres pgvector extension (similarity search) and Full-Text Search (keyword search) to retrieve documents. You can add documents via SupabaseVectorStore addDocuments function. SupabaseHybridKeyWordSearch accepts embedding, supabase client, number of results for similarity search, and number of results for keyword search as parameters. The getRelevantDocuments function produces a list of documents that has duplicates removed and is sorted by relevance score. @@ -151,5 +139,4 @@ export const run = async () => { ``` For more details, checkout the LangChain Supabase Hybrid Search docs: https://js.langchain.com/docs/modules/indexes/retrievers/supabase-hybrid -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175953_langchain-hybrid_search-1_1_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175953_langchain-hybrid_search-1_1_0_80.snap index c43dc4bf6..a6ac36d6a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175953_langchain-hybrid_search-1_1_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230508175953_langchain-hybrid_search-1_1_0_80.snap @@ -11,12 +11,7 @@ insert into app.package_versions ( values ( ( - select - id - from - app.packages - where - package_name = 'langchain-hybrid_search' + select id from app.packages where package_name = 'langchain-hybrid_search' ), (1, 1, 0), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230622212339_langchain_headerkit_config_dump_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230622212339_langchain_headerkit_config_dump_100.snap index fc5a834ba..702e4f67e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230622212339_langchain_headerkit_config_dump_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230622212339_langchain_headerkit_config_dump_100.snap @@ -4,23 +4,10 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20230622212339_langchain_h --- update app.packages set control_requires = '{vector}' where handle = 'langchain'; -insert into app.package_upgrades ( - package_id, - from_version_struct, - to_version_struct, - sql -) +insert into app.package_upgrades (package_id, from_version_struct, to_version_struct, sql) values ( - ( - select - id - from - app.packages - where - handle = 'langchain' and - partial_name = 'embedding_search' - ), + (select id from app.packages where handle = 'langchain' and partial_name = 'embedding_search'), (1, 1, 0), (1, 1, 1), ' @@ -29,23 +16,10 @@ SELECT pg_extension_config_dump(''documents_id_seq'', ''''); ' ); -insert into app.package_upgrades ( - package_id, - from_version_struct, - to_version_struct, - sql -) +insert into app.package_upgrades (package_id, from_version_struct, to_version_struct, sql) values ( - ( - select - id - from - app.packages - where - handle = 'langchain' and - partial_name = 'hybrid_search' - ), + (select id from app.packages where handle = 'langchain' and partial_name = 'hybrid_search'), (1, 1, 0), (1, 1, 1), ' @@ -54,26 +28,8 @@ SELECT pg_extension_config_dump(''documents_id_seq'', ''''); ' ); -insert into app.package_upgrades ( - package_id, - from_version_struct, - to_version_struct, - sql -) -values - ( - ( - select - id - from - app.packages - where - partial_name = 'pg_headerkit' - ), - (1, 0, 0), - (1, 0, 1), - ' +insert into app.package_upgrades (package_id, from_version_struct, to_version_struct, sql) +values ((select id from app.packages where partial_name = 'pg_headerkit'), (1, 0, 0), (1, 0, 1), ' SELECT pg_extension_config_dump(''hdr.allow_list'', ''''); SELECT pg_extension_config_dump(''hdr.deny_list'', ''''); -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230622212339_langchain_headerkit_config_dump_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230622212339_langchain_headerkit_config_dump_80.snap index bad14ac03..5272623e6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230622212339_langchain_headerkit_config_dump_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230622212339_langchain_headerkit_config_dump_80.snap @@ -21,8 +21,7 @@ values from app.packages where - handle = 'langchain' and - partial_name = 'embedding_search' + handle = 'langchain' and partial_name = 'embedding_search' ), (1, 1, 0), (1, 1, 1), @@ -46,8 +45,7 @@ values from app.packages where - handle = 'langchain' and - partial_name = 'hybrid_search' + handle = 'langchain' and partial_name = 'hybrid_search' ), (1, 1, 0), (1, 1, 1), @@ -65,14 +63,7 @@ insert into app.package_upgrades ( ) values ( - ( - select - id - from - app.packages - where - partial_name = 'pg_headerkit' - ), + (select id from app.packages where partial_name = 'pg_headerkit'), (1, 0, 0), (1, 0, 1), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230623181432_dbdev_supports_multiple_versions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230623181432_dbdev_supports_multiple_versions_100.snap index 860571ff1..9f540cfe2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230623181432_dbdev_supports_multiple_versions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230623181432_dbdev_supports_multiple_versions_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20230623181432_dbdev_supports_multiple_versions.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'supabase-dbdev' - ), - (0, 0, 3), - ' +values ((select id from app.packages where package_name = 'supabase-dbdev'), (0, 0, 3), ' create schema dbdev; @@ -201,8 +190,7 @@ begin end; $$; -', - ' +', ' # dbdev dbdev is the SQL client for database.new and is the primary way end users interact with the package (pglet) registry. @@ -292,5 +280,4 @@ create extension "handle-package_name" schema ''public'' version ''1.2.3''; ``` -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230623181432_dbdev_supports_multiple_versions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230623181432_dbdev_supports_multiple_versions_80.snap index 7cdd0ef66..a2428abbe 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230623181432_dbdev_supports_multiple_versions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230623181432_dbdev_supports_multiple_versions_80.snap @@ -10,14 +10,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'supabase-dbdev' - ), + (select id from app.packages where package_name = 'supabase-dbdev'), (0, 0, 3), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230830083255_olirice-index_advisor-0_2_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230830083255_olirice-index_advisor-0_2_0_100.snap index 841d3bfcc..93e37c5c8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230830083255_olirice-index_advisor-0_2_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230830083255_olirice-index_advisor-0_2_0_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20230830083255_olirice-index_advisor-0_2_0.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'olirice-index_advisor' - ), - (0, 2, 0), - ' +values ((select id from app.packages where package_name = 'olirice-index_advisor'), (0, 2, 0), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 @@ -221,8 +210,7 @@ begin end; $$; -', - ' +', ' # index_advisor @@ -350,5 +338,4 @@ from "CREATE INDEX ON public.review USING btree (book_id)"} (3 rows) ``` -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230830083255_olirice-index_advisor-0_2_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230830083255_olirice-index_advisor-0_2_0_80.snap index 2c5aafa32..7c8778737 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230830083255_olirice-index_advisor-0_2_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230830083255_olirice-index_advisor-0_2_0_80.snap @@ -10,14 +10,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'olirice-index_advisor' - ), + (select id from app.packages where package_name = 'olirice-index_advisor'), (0, 2, 0), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906110845_access_token_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906110845_access_token_100.snap index f42c32f93..6792a8d25 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906110845_access_token_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906110845_access_token_100.snap @@ -4,30 +4,18 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20230906110845_access_toke --- create table app.access_tokens ( id uuid primary key default gen_random_uuid(), - user_id uuid - not null - references auth.users (id) on DELETE cascade, + user_id uuid not null references auth.users (id) on delete cascade, token_hash bytea not null, - token_name text - not null - check (length(token_name) <= 64), - plaintext_suffix text - not null - check (length(plaintext_suffix) = 4), - created_at timestamp with time zone - not null - default NOW() + token_name text not null check (length(token_name) <= 64), + plaintext_suffix text not null check (length(plaintext_suffix) = 4), + created_at timestamptz not null default now() ); -grant INSERT (id, -user_id, -token_hash, -token_name, -plaintext_suffix) +grant insert (id, user_id, token_hash, token_name, plaintext_suffix) on table app.access_tokens to authenticated; -grant DELETE on table app.access_tokens to authenticated; +grant delete on table app.access_tokens to authenticated; alter table app.access_tokens enable row level security; @@ -57,27 +45,27 @@ create or replace function app.base64url_encode(input bytea) returns text language plpgsql strict -as $function$ +as $$ begin return replace(replace(encode(input, 'base64'), '/', '_'), '+', '-'); end; -$function$; +$$; create or replace function app.base64url_decode(input text) returns text language plpgsql strict -as $function$ +as $$ begin return decode(replace(replace(input, '-', '+'), '_', '/'), 'base64'); end; -$function$; +$$; create or replace function public.new_access_token(token_name text) returns text language plpgsql strict -as $function$ +as $$ <> declare account app.accounts = account from app.accounts account where id = auth.uid(); @@ -99,20 +87,20 @@ begin -- String returned has a length 64 return 'dbd_' || replace(token_id::text, '-', '') || token_text; end; -$function$; +$$; create type app.access_token_struct as ( id uuid, token_name text, masked_token text, - created_at timestamp with time zone + created_at timestamptz ); create or replace function public.get_access_tokens() returns setof app.access_token_struct language plpgsql strict -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); begin @@ -126,20 +114,20 @@ begin from app.access_tokens at where at.user_id = account.id; end; -$function$; +$$; create or replace function public.delete_access_token(token_id uuid) returns void language plpgsql strict -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); begin delete from app.access_tokens at where at.user_id = account.id and at.id = token_id; end; -$function$; +$$; create type app.user_id_and_token_hash as (user_id uuid, token_hash bytea); @@ -148,7 +136,7 @@ returns text language plpgsql strict security definer -as $function$ +as $$ declare token_id uuid; token bytea; @@ -198,4 +186,4 @@ begin 'exp', expiry_at ), jwt_secret); end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906110845_access_token_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906110845_access_token_80.snap index 146b25ceb..6792a8d25 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906110845_access_token_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906110845_access_token_80.snap @@ -3,34 +3,19 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20230906110845_access_token.sql --- create table app.access_tokens ( - id uuid - primary key - default gen_random_uuid(), - user_id uuid - not null - references auth.users (id) - on DELETE cascade, + id uuid primary key default gen_random_uuid(), + user_id uuid not null references auth.users (id) on delete cascade, token_hash bytea not null, - token_name text - not null - check (length(token_name) <= 64), - plaintext_suffix text - not null - check (length(plaintext_suffix) = 4), - created_at timestamp with time zone - not null - default NOW() + token_name text not null check (length(token_name) <= 64), + plaintext_suffix text not null check (length(plaintext_suffix) = 4), + created_at timestamptz not null default now() ); -grant INSERT (id, -user_id, -token_hash, -token_name, -plaintext_suffix) +grant insert (id, user_id, token_hash, token_name, plaintext_suffix) on table app.access_tokens to authenticated; -grant DELETE on table app.access_tokens to authenticated; +grant delete on table app.access_tokens to authenticated; alter table app.access_tokens enable row level security; @@ -60,27 +45,27 @@ create or replace function app.base64url_encode(input bytea) returns text language plpgsql strict -as $function$ +as $$ begin return replace(replace(encode(input, 'base64'), '/', '_'), '+', '-'); end; -$function$; +$$; create or replace function app.base64url_decode(input text) returns text language plpgsql strict -as $function$ +as $$ begin return decode(replace(replace(input, '-', '+'), '_', '/'), 'base64'); end; -$function$; +$$; create or replace function public.new_access_token(token_name text) returns text language plpgsql strict -as $function$ +as $$ <> declare account app.accounts = account from app.accounts account where id = auth.uid(); @@ -102,20 +87,20 @@ begin -- String returned has a length 64 return 'dbd_' || replace(token_id::text, '-', '') || token_text; end; -$function$; +$$; create type app.access_token_struct as ( id uuid, token_name text, masked_token text, - created_at timestamp with time zone + created_at timestamptz ); create or replace function public.get_access_tokens() returns setof app.access_token_struct language plpgsql strict -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); begin @@ -129,20 +114,20 @@ begin from app.access_tokens at where at.user_id = account.id; end; -$function$; +$$; create or replace function public.delete_access_token(token_id uuid) returns void language plpgsql strict -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); begin delete from app.access_tokens at where at.user_id = account.id and at.id = token_id; end; -$function$; +$$; create type app.user_id_and_token_hash as (user_id uuid, token_hash bytea); @@ -151,7 +136,7 @@ returns text language plpgsql strict security definer -as $function$ +as $$ declare token_id uuid; token bytea; @@ -201,4 +186,4 @@ begin 'exp', expiry_at ), jwt_secret); end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906111353_publish_package_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906111353_publish_package_100.snap index 67908582a..8d064d24e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906111353_publish_package_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906111353_publish_package_100.snap @@ -2,9 +2,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20230906111353_publish_package.sql --- -grant INSERT (partial_name, handle, control_description) on table app.packages to authenticated; +grant insert (partial_name, handle, control_description) on table app.packages to authenticated; -grant UPDATE (control_description) on table app.packages to authenticated; +grant update (control_description) on table app.packages to authenticated; create policy packages_update_policy on app.packages @@ -20,7 +20,7 @@ public.publish_package( ) returns void language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); begin @@ -34,7 +34,7 @@ begin do update set control_description = excluded.control_description; end; -$function$; +$$; create or replace function public.publish_package_version( @@ -45,7 +45,7 @@ public.publish_package_version( ) returns uuid language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); package_id uuid; @@ -70,7 +70,7 @@ begin return null; end; end; -$function$; +$$; create or replace function public.publish_package_upgrade( @@ -81,7 +81,7 @@ public.publish_package_upgrade( ) returns uuid language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); package_id uuid; @@ -106,4 +106,4 @@ begin return null; end; end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906111353_publish_package_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906111353_publish_package_80.snap index 955df4be5..6d3c600b7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906111353_publish_package_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20230906111353_publish_package_80.snap @@ -2,23 +2,18 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20230906111353_publish_package.sql --- -grant INSERT (partial_name, -handle, -control_description) +grant insert (partial_name, handle, control_description) on table app.packages to authenticated; -grant UPDATE (control_description) on table app.packages to authenticated; +grant update (control_description) on table app.packages to authenticated; create policy packages_update_policy on app.packages as permissive for update to authenticated -using (app.is_package_maintainer( - auth.uid(), - id -)); +using (app.is_package_maintainer(auth.uid(), id)); create or replace function public.publish_package( @@ -27,7 +22,7 @@ public.publish_package( ) returns void language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); begin @@ -41,7 +36,7 @@ begin do update set control_description = excluded.control_description; end; -$function$; +$$; create or replace function public.publish_package_version( @@ -52,7 +47,7 @@ public.publish_package_version( ) returns uuid language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); package_id uuid; @@ -77,7 +72,7 @@ begin return null; end; end; -$function$; +$$; create or replace function public.publish_package_upgrade( @@ -88,7 +83,7 @@ public.publish_package_upgrade( ) returns uuid language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); package_id uuid; @@ -113,4 +108,4 @@ begin return null; end; end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231110061036_allow_publishing_relocatable_and_requires_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231110061036_allow_publishing_relocatable_and_requires_100.snap index ee5c3e8b2..3150923f0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231110061036_allow_publishing_relocatable_and_requires_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231110061036_allow_publishing_relocatable_and_requires_100.snap @@ -116,17 +116,11 @@ values ('test_parser'), ('wal2json'); -grant INSERT (partial_name, -handle, -control_description, -control_relocatable, -control_requires) +grant insert (partial_name, handle, control_description, control_relocatable, control_requires) on table app.packages to authenticated; -grant UPDATE (control_description, -control_relocatable, -control_requires) +grant update (control_description, control_relocatable, control_requires) on table app.packages to authenticated; @@ -134,12 +128,12 @@ create or replace function public.publish_package( package_name app.valid_name, package_description varchar(1000), - relocatable boolean default false, + relocatable bool default false, requires text[] default '{}' ) returns void language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); require text; @@ -168,4 +162,4 @@ begin control_relocatable = excluded.control_relocatable, control_requires = excluded.control_requires; end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231110061036_allow_publishing_relocatable_and_requires_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231110061036_allow_publishing_relocatable_and_requires_80.snap index ee5c3e8b2..91cd6309f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231110061036_allow_publishing_relocatable_and_requires_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231110061036_allow_publishing_relocatable_and_requires_80.snap @@ -116,17 +116,17 @@ values ('test_parser'), ('wal2json'); -grant INSERT (partial_name, -handle, -control_description, -control_relocatable, -control_requires) +grant insert ( + partial_name, + handle, + control_description, + control_relocatable, + control_requires +) on table app.packages to authenticated; -grant UPDATE (control_description, -control_relocatable, -control_requires) +grant update (control_description, control_relocatable, control_requires) on table app.packages to authenticated; @@ -134,12 +134,12 @@ create or replace function public.publish_package( package_name app.valid_name, package_description varchar(1000), - relocatable boolean default false, + relocatable bool default false, requires text[] default '{}' ) returns void language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); require text; @@ -168,4 +168,4 @@ begin control_relocatable = excluded.control_relocatable, control_requires = excluded.control_requires; end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205051816_add_default_version_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205051816_add_default_version_100.snap index 8701dff1e..ab699c3ee 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205051816_add_default_version_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205051816_add_default_version_100.snap @@ -3,11 +3,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20231205051816_add_default_version.sql --- alter table app.packages - add column default_version_struct app.semver - not null - default app.text_to_semver('0.0.0'), + add column default_version_struct app.semver not null default app.text_to_semver('0.0.0'), add column default_version text - generated always as (app.semver_to_text(default_version_struct)) stored; + generated always as (app.semver_to_text(default_version_struct)) stored; update app.packages set default_version_struct = app.text_to_semver(pp.latest_version) @@ -44,35 +42,34 @@ from ) as newest_ver; -grant INSERT (partial_name, -handle, -control_description, -control_relocatable, -control_requires, -default_version_struct) +grant insert ( + partial_name, + handle, + control_description, + control_relocatable, + control_requires, + default_version_struct +) on table app.packages to authenticated; -grant UPDATE (control_description, -control_relocatable, -control_requires, -default_version_struct) +grant update (control_description, control_relocatable, control_requires, default_version_struct) on table app.packages to authenticated; -drop function public.publish_package(app.valid_name, varchar, boolean, text[]); +drop function public.publish_package(app.valid_name, varchar, bool, text[]); create or replace function public.publish_package( package_name app.valid_name, package_description varchar(1000), - relocatable boolean default false, + relocatable bool default false, requires text[] default '{}', default_version text default null ) returns void language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); require text; @@ -106,4 +103,4 @@ begin control_requires = excluded.control_requires, default_version_struct = excluded.default_version_struct; end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205051816_add_default_version_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205051816_add_default_version_80.snap index b912fb710..c44819ea5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205051816_add_default_version_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205051816_add_default_version_80.snap @@ -4,12 +4,10 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20231205051816_add_default --- alter table app.packages add column default_version_struct app.semver - not null - default app.text_to_semver('0.0.0'), + not null + default app.text_to_semver('0.0.0'), add column default_version text - generated always as (app.semver_to_text( - default_version_struct - )) stored; + generated always as (app.semver_to_text(default_version_struct)) stored; update app.packages set default_version_struct = app.text_to_semver(pp.latest_version) @@ -46,35 +44,39 @@ from ) as newest_ver; -grant INSERT (partial_name, -handle, -control_description, -control_relocatable, -control_requires, -default_version_struct) +grant insert ( + partial_name, + handle, + control_description, + control_relocatable, + control_requires, + default_version_struct +) on table app.packages to authenticated; -grant UPDATE (control_description, -control_relocatable, -control_requires, -default_version_struct) +grant update ( + control_description, + control_relocatable, + control_requires, + default_version_struct +) on table app.packages to authenticated; -drop function public.publish_package(app.valid_name, varchar, boolean, text[]); +drop function public.publish_package(app.valid_name, varchar, bool, text[]); create or replace function public.publish_package( package_name app.valid_name, package_description varchar(1000), - relocatable boolean default false, + relocatable bool default false, requires text[] default '{}', default_version text default null ) returns void language plpgsql -as $function$ +as $$ declare account app.accounts = account from app.accounts account where id = auth.uid(); require text; @@ -108,4 +110,4 @@ begin control_requires = excluded.control_requires, default_version_struct = excluded.default_version_struct; end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205101809_dbdev_supports_default_version_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205101809_dbdev_supports_default_version_100.snap index 9265da409..8e4bc608b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205101809_dbdev_supports_default_version_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205101809_dbdev_supports_default_version_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20231205101809_dbdev_supports_default_version.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_name = 'supabase-dbdev' - ), - (0, 0, 4), - ' +values ((select id from app.packages where package_name = 'supabase-dbdev'), (0, 0, 4), ' create schema dbdev; @@ -252,8 +241,7 @@ begin end; $$; -', - ' +', ' # dbdev dbdev is the SQL client for database.new and is the primary way end users interact with the package (pglet) registry. @@ -343,8 +331,7 @@ create extension "handle-package_name" schema ''public'' version ''1.2.3''; ``` -' - ); +'); update app.packages set default_version_struct = app.text_to_semver('0.0.4') diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205101809_dbdev_supports_default_version_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205101809_dbdev_supports_default_version_80.snap index c70986b61..a2c058781 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205101809_dbdev_supports_default_version_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231205101809_dbdev_supports_default_version_80.snap @@ -10,14 +10,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_name = 'supabase-dbdev' - ), + (select id from app.packages where package_name = 'supabase-dbdev'), (0, 0, 4), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207071422_new_package_name_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207071422_new_package_name_100.snap index f5a8786d5..7bf3b4b93 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207071422_new_package_name_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207071422_new_package_name_100.snap @@ -6,9 +6,9 @@ create or replace function app.to_package_name(handle app.valid_name, partial_na returns text language sql immutable -as $function$ -select format('%s@%s', $1, $2) -$function$; +as $$ + select format('%s@%s', $1, $2) +$$; alter table app.packages add column package_alias text null; @@ -55,10 +55,7 @@ as select pv.created_at, pa.package_alias from - app.packages as pa - inner join - app.package_versions as pv - on pa.id = pv.package_id; + app.packages as pa inner join app.package_versions as pv on pa.id = pv.package_id; create or replace view public.package_upgrades as select @@ -71,18 +68,15 @@ as select pu.created_at, pa.package_alias from - app.packages as pa - inner join - app.package_upgrades as pu - on pa.id = pu.package_id; + app.packages as pa inner join app.package_upgrades as pu on pa.id = pu.package_id; create or replace function public.register_download(package_name text) returns void language sql security definer -as $function$ -insert into app.downloads(package_id) +as $$ + insert into app.downloads(package_id) select id from app.packages ap where ap.package_name = $1 or ap.package_alias = $1 -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207071422_new_package_name_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207071422_new_package_name_80.snap index 47fec4023..c55f2eb4d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207071422_new_package_name_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207071422_new_package_name_80.snap @@ -10,9 +10,9 @@ app.to_package_name( returns text language sql immutable -as $function$ -select format('%s@%s', $1, $2) -$function$; +as $$ + select format('%s@%s', $1, $2) +$$; alter table app.packages add column package_alias text null; @@ -84,9 +84,9 @@ create or replace function public.register_download(package_name text) returns void language sql security definer -as $function$ -insert into app.downloads(package_id) +as $$ + insert into app.downloads(package_id) select id from app.packages ap where ap.package_name = $1 or ap.package_alias = $1 -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207073048_dbdev_supports_new_package_names_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207073048_dbdev_supports_new_package_names_100.snap index 0b9b8471d..98083631f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207073048_dbdev_supports_new_package_names_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207073048_dbdev_supports_new_package_names_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20231207073048_dbdev_supports_new_package_names.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_alias = 'supabase@dbdev' - ), - (0, 0, 5), - ' +values ((select id from app.packages where package_alias = 'supabase@dbdev'), (0, 0, 5), ' create schema dbdev; @@ -251,8 +240,7 @@ begin end; $$; -', - ' +', ' # dbdev dbdev is the SQL client for database.new and is the primary way end users interact with the package registry. @@ -345,8 +333,7 @@ create extension "handle@package_name" schema ''public'' version ''1.2.3''; ``` -' - ); +'); update app.packages set default_version_struct = app.text_to_semver('0.0.5') diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207073048_dbdev_supports_new_package_names_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207073048_dbdev_supports_new_package_names_80.snap index 3dc2a4986..c15f9fca9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207073048_dbdev_supports_new_package_names_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207073048_dbdev_supports_new_package_names_80.snap @@ -10,14 +10,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_alias = 'supabase@dbdev' - ), + (select id from app.packages where package_alias = 'supabase@dbdev'), (0, 0, 5), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207111703_langchain@embedding_search-1.1.1_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207111703_langchain@embedding_search-1.1.1_100.snap index c16c8ce3b..2dee2ba4c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207111703_langchain@embedding_search-1.1.1_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207111703_langchain@embedding_search-1.1.1_100.snap @@ -4,17 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/20231207111703_langchain@e --- insert into app.package_versions (package_id, version_struct, sql, description_md) values - ( - ( - select - id - from - app.packages - where - package_alias = 'langchain@embedding_search' - ), - (1, 1, 1), - ' + ((select id from app.packages where package_alias = 'langchain@embedding_search'), (1, 1, 1), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 do $$ @@ -72,8 +62,7 @@ begin end; $$; -', - ' +', ' # embedding_search [LangChain](https://js.langchain.com/docs/) is a framework for developing applications powered by language models with a plugable architecture. @@ -174,5 +163,4 @@ export const run = async () => { ``` For more details, checkout the LangChain Supabase integration docs: https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207111703_langchain@embedding_search-1.1.1_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207111703_langchain@embedding_search-1.1.1_80.snap index fa6a75c06..3a2c9b367 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207111703_langchain@embedding_search-1.1.1_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207111703_langchain@embedding_search-1.1.1_80.snap @@ -16,8 +16,7 @@ values from app.packages where - package_alias = - 'langchain@embedding_search' + package_alias = 'langchain@embedding_search' ), (1, 1, 1), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112129_langchain@hybrid_search-1.1.1_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112129_langchain@hybrid_search-1.1.1_100.snap index 2f6dc5d6a..15485d111 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112129_langchain@hybrid_search-1.1.1_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112129_langchain@hybrid_search-1.1.1_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20231207112129_langchain@hybrid_search-1.1.1.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_alias = 'langchain@hybrid_search' - ), - (1, 1, 1), - ' +values ((select id from app.packages where package_alias = 'langchain@hybrid_search'), (1, 1, 1), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 do $$ @@ -94,8 +83,7 @@ using query_text, match_count; end; $$ language plpgsql; -', - ' +', ' # hybrid_search Langchain supports hybrid search with a Supabase Postgres database. The hybrid search combines the postgres pgvector extension (similarity search) and Full-Text Search (keyword search) to retrieve documents. You can add documents via SupabaseVectorStore addDocuments function. SupabaseHybridKeyWordSearch accepts embedding, supabase client, number of results for similarity search, and number of results for keyword search as parameters. The getRelevantDocuments function produces a list of documents that has duplicates removed and is sorted by relevance score. @@ -151,5 +139,4 @@ export const run = async () => { ``` For more details, checkout the LangChain Supabase Hybrid Search docs: https://js.langchain.com/docs/modules/indexes/retrievers/supabase-hybrid -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112129_langchain@hybrid_search-1.1.1_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112129_langchain@hybrid_search-1.1.1_80.snap index e20489156..75eff887c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112129_langchain@hybrid_search-1.1.1_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112129_langchain@hybrid_search-1.1.1_80.snap @@ -16,8 +16,7 @@ values from app.packages where - package_alias = - 'langchain@hybrid_search' + package_alias = 'langchain@hybrid_search' ), (1, 1, 1), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112942_michelp@adminpack-0.0.2_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112942_michelp@adminpack-0.0.2_100.snap index 750a27864..065b1e566 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112942_michelp@adminpack-0.0.2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112942_michelp@adminpack-0.0.2_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20231207112942_michelp@adminpack-0.0.2.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_alias = 'michelp@adminpack' - ), - (0, 0, 2), - ' +values ((select id from app.packages where package_alias = 'michelp@adminpack'), (0, 0, 2), ' -- From: https://github.com/ioguix/pgsql-bloat-estimation -- Copyright (c) 2015-2019, Jehan-Guillaume (ioguix) de Rorthais @@ -1060,8 +1049,7 @@ FROM JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = ''v''; -', - ' +', ' # michelp@adminpack A Trusted Language Extension containing a variety of useful databse admin queries. @@ -1562,5 +1550,4 @@ This view shows all views in the database. | name | name | | is_updatable | boolean | | comment | text | -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112942_michelp@adminpack-0.0.2_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112942_michelp@adminpack-0.0.2_80.snap index 510275528..63700e47f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112942_michelp@adminpack-0.0.2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207112942_michelp@adminpack-0.0.2_80.snap @@ -10,14 +10,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_alias = 'michelp@adminpack' - ), + (select id from app.packages where package_alias = 'michelp@adminpack'), (0, 0, 2), ' -- From: https://github.com/ioguix/pgsql-bloat-estimation diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113329_olirice@index_advisor-0.2.1_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113329_olirice@index_advisor-0.2.1_100.snap index 366590e41..d6ff76fbb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113329_olirice@index_advisor-0.2.1_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113329_olirice@index_advisor-0.2.1_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20231207113329_olirice@index_advisor-0.2.1.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_alias = 'olirice@index_advisor' - ), - (0, 2, 1), - ' +values ((select id from app.packages where package_alias = 'olirice@index_advisor'), (0, 2, 1), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 @@ -221,8 +210,7 @@ begin end; $$; -', - ' +', ' # index_advisor @@ -350,5 +338,4 @@ from "CREATE INDEX ON public.review USING btree (book_id)"} (3 rows) ``` -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113329_olirice@index_advisor-0.2.1_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113329_olirice@index_advisor-0.2.1_80.snap index 933c7ce38..f925c9216 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113329_olirice@index_advisor-0.2.1_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113329_olirice@index_advisor-0.2.1_80.snap @@ -10,14 +10,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_alias = 'olirice@index_advisor' - ), + (select id from app.packages where package_alias = 'olirice@index_advisor'), (0, 2, 1), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113857_olirice@read_once-0.3.2_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113857_olirice@read_once-0.3.2_100.snap index 9b00b7000..8d4520e56 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113857_olirice@read_once-0.3.2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113857_olirice@read_once-0.3.2_100.snap @@ -3,18 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/20231207113857_olirice@read_once-0.3.2.sql --- insert into app.package_versions (package_id, version_struct, sql, description_md) -values - ( - ( - select - id - from - app.packages - where - package_alias = 'olirice@read_once' - ), - (0, 3, 2), - ' +values ((select id from app.packages where package_alias = 'olirice@read_once'), (0, 3, 2), ' -- Enforce requirements -- Workaround to https://github.com/aws/pg_tle/issues/183 @@ -76,8 +65,7 @@ $$ where read_once.messages.id = $1 returning contents; $$ -', - ' +', ' # read_once @@ -152,5 +140,4 @@ create or replace function read_message( ) returns text ``` -' - ); +'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113857_olirice@read_once-0.3.2_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113857_olirice@read_once-0.3.2_80.snap index 031b97ca3..b25566ef6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113857_olirice@read_once-0.3.2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20231207113857_olirice@read_once-0.3.2_80.snap @@ -10,14 +10,7 @@ insert into app.package_versions ( ) values ( - ( - select - id - from - app.packages - where - package_alias = 'olirice@read_once' - ), + (select id from app.packages where package_alias = 'olirice@read_once'), (0, 3, 2), ' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20240705083738_remove_contact_email_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20240705083738_remove_contact_email_100.snap index 7dd751914..f3be2bfc1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20240705083738_remove_contact_email_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20240705083738_remove_contact_email_100.snap @@ -14,10 +14,7 @@ as select acc.bio, acc.created_at from - app.accounts as acc - left outer join - storage.objects as obj - on acc.avatar_id = obj.id; + app.accounts as acc left outer join storage.objects as obj on acc.avatar_id = obj.id; drop view if exists public.organizations; @@ -31,7 +28,4 @@ as select org.bio, org.created_at from - app.organizations as org - left outer join - storage.objects as obj - on org.avatar_id = obj.id; + app.organizations as org left outer join storage.objects as obj on org.avatar_id = obj.id; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250106073735_jwt_secret_from_vault_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250106073735_jwt_secret_from_vault_100.snap index 5040ab259..ec6cacee1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250106073735_jwt_secret_from_vault_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250106073735_jwt_secret_from_vault_100.snap @@ -7,7 +7,7 @@ returns text language plpgsql strict security definer -as $function$ +as $$ declare token_id uuid; token bytea; @@ -62,4 +62,4 @@ begin 'exp', expiry_at ), jwt_secret); end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250106073735_jwt_secret_from_vault_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250106073735_jwt_secret_from_vault_80.snap index 5040ab259..ec6cacee1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250106073735_jwt_secret_from_vault_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250106073735_jwt_secret_from_vault_80.snap @@ -7,7 +7,7 @@ returns text language plpgsql strict security definer -as $function$ +as $$ declare token_id uuid; token bytea; @@ -62,4 +62,4 @@ begin 'exp', expiry_at ), jwt_secret); end; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250217100252_restrict_accounts_and_orgs_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250217100252_restrict_accounts_and_orgs_100.snap index 5255a16ff..35fc7a2f6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250217100252_restrict_accounts_and_orgs_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250217100252_restrict_accounts_and_orgs_100.snap @@ -14,29 +14,29 @@ returns setof public.accounts language sql strict security definer -as $function$ -select id, handle, avatar_path, display_name, bio, created_at +as $$ + select id, handle, avatar_path, display_name, bio, created_at from public.accounts a where a.handle = get_account.handle and auth.uid() is not null; -$function$; +$$; create or replace function public.get_organization(handle text) returns setof public.organizations language sql strict security definer -as $function$ -select id, handle, avatar_path, display_name, bio, created_at +as $$ + select id, handle, avatar_path, display_name, bio, created_at from public.organizations o where o.handle = get_organization.handle and auth.uid() is not null; -$function$; +$$; -grant SELECT on table app.accounts to service_role; +grant select on table app.accounts to service_role; -grant SELECT on table app.organizations to service_role; +grant select on table app.organizations to service_role; -grant SELECT on table app.packages to service_role; +grant select on table app.packages to service_role; -grant SELECT on table app.package_versions to service_role; +grant select on table app.package_versions to service_role; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250217100252_restrict_accounts_and_orgs_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250217100252_restrict_accounts_and_orgs_80.snap index 3f147d5dc..114c5aa6d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250217100252_restrict_accounts_and_orgs_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250217100252_restrict_accounts_and_orgs_80.snap @@ -10,39 +10,36 @@ using (id = auth.uid()); alter policy organizations_select_policy on app.organizations to authenticated -using (app.is_organization_maintainer( - auth.uid(), - id -)); +using (app.is_organization_maintainer(auth.uid(), id)); create or replace function public.get_account(handle text) returns setof public.accounts language sql strict security definer -as $function$ -select id, handle, avatar_path, display_name, bio, created_at +as $$ + select id, handle, avatar_path, display_name, bio, created_at from public.accounts a where a.handle = get_account.handle and auth.uid() is not null; -$function$; +$$; create or replace function public.get_organization(handle text) returns setof public.organizations language sql strict security definer -as $function$ -select id, handle, avatar_path, display_name, bio, created_at +as $$ + select id, handle, avatar_path, display_name, bio, created_at from public.organizations o where o.handle = get_organization.handle and auth.uid() is not null; -$function$; +$$; -grant SELECT on table app.accounts to service_role; +grant select on table app.accounts to service_role; -grant SELECT on table app.organizations to service_role; +grant select on table app.organizations to service_role; -grant SELECT on table app.packages to service_role; +grant select on table app.packages to service_role; -grant SELECT on table app.package_versions to service_role; +grant select on table app.package_versions to service_role; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250804111152_remove_dbdev_from_popular_packages_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250804111152_remove_dbdev_from_popular_packages_100.snap index 86e8452ba..c8edd94e1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250804111152_remove_dbdev_from_popular_packages_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250804111152_remove_dbdev_from_popular_packages_100.snap @@ -6,12 +6,12 @@ create or replace function public.popular_packages() returns setof public.packages language sql stable -as $function$ -select * from public.packages p +as $$ + select * from public.packages p where p.package_name != 'supabase-dbdev' order by ( select (dm.downloads_30_day * 5) + (dm.downloads_90_days * 2) + dm.downloads_180_days from public.download_metrics dm where dm.package_id = p.id ) desc nulls last, p.created_at desc; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250804111152_remove_dbdev_from_popular_packages_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250804111152_remove_dbdev_from_popular_packages_80.snap index 86e8452ba..c8edd94e1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250804111152_remove_dbdev_from_popular_packages_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__20250804111152_remove_dbdev_from_popular_packages_80.snap @@ -6,12 +6,12 @@ create or replace function public.popular_packages() returns setof public.packages language sql stable -as $function$ -select * from public.packages p +as $$ + select * from public.packages p where p.package_name != 'supabase-dbdev' order by ( select (dm.downloads_30_day * 5) + (dm.downloads_90_days * 2) + dm.downloads_180_days from public.download_metrics dm where dm.package_id = p.id ) desc nulls last, p.created_at desc; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__advisory_lock_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__advisory_lock_100.snap index 65c697ab9..eefa2f8ce 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__advisory_lock_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__advisory_lock_100.snap @@ -30,7 +30,7 @@ order by classid, select pg_advisory_unlock_all(); -select COUNT(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; +select count(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; select pg_advisory_unlock(1), @@ -40,7 +40,7 @@ select commit; -select COUNT(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; +select count(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; begin; @@ -98,7 +98,7 @@ select pg_advisory_unlock_shared(2, 2), pg_advisory_unlock_shared(2, 2); -select COUNT(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; +select count(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; begin; @@ -148,7 +148,7 @@ order by classid, select pg_advisory_unlock_all(); -select COUNT(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; +select count(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; begin; @@ -179,7 +179,7 @@ order by classid, commit; -select COUNT(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; +select count(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; select pg_advisory_lock(1), @@ -216,7 +216,7 @@ select pg_advisory_unlock_shared(2, 2), pg_advisory_unlock_shared(2, 2); -select COUNT(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; +select count(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; select pg_advisory_lock(1), @@ -245,4 +245,4 @@ order by classid, select pg_advisory_unlock_all(); -select COUNT(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; +select count(*) from pg_locks where locktype = 'advisory' and database = 'datoid'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__advisory_lock_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__advisory_lock_80.snap index 9aad9c228..661bd3ec4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__advisory_lock_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__advisory_lock_80.snap @@ -23,8 +23,7 @@ select from pg_locks where - locktype = 'advisory' and - database = 'datoid' + locktype = 'advisory' and database = 'datoid' order by classid, objid, objsubid; @@ -32,12 +31,11 @@ order by classid, select pg_advisory_unlock_all(); select - COUNT(*) + count(*) from pg_locks where - locktype = 'advisory' and - database = 'datoid'; + locktype = 'advisory' and database = 'datoid'; select pg_advisory_unlock(1), @@ -48,12 +46,11 @@ select commit; select - COUNT(*) + count(*) from pg_locks where - locktype = 'advisory' and - database = 'datoid'; + locktype = 'advisory' and database = 'datoid'; begin; @@ -73,8 +70,7 @@ select from pg_locks where - locktype = 'advisory' and - database = 'datoid' + locktype = 'advisory' and database = 'datoid' order by classid, objid, objsubid; @@ -97,8 +93,7 @@ select from pg_locks where - locktype = 'advisory' and - database = 'datoid' + locktype = 'advisory' and database = 'datoid' order by classid, objid, objsubid; @@ -114,12 +109,11 @@ select pg_advisory_unlock_shared(2, 2); select - COUNT(*) + count(*) from pg_locks where - locktype = 'advisory' and - database = 'datoid'; + locktype = 'advisory' and database = 'datoid'; begin; @@ -139,8 +133,7 @@ select from pg_locks where - locktype = 'advisory' and - database = 'datoid' + locktype = 'advisory' and database = 'datoid' order by classid, objid, objsubid; @@ -163,8 +156,7 @@ select from pg_locks where - locktype = 'advisory' and - database = 'datoid' + locktype = 'advisory' and database = 'datoid' order by classid, objid, objsubid; @@ -172,12 +164,11 @@ order by classid, select pg_advisory_unlock_all(); select - COUNT(*) + count(*) from pg_locks where - locktype = 'advisory' and - database = 'datoid'; + locktype = 'advisory' and database = 'datoid'; begin; @@ -201,8 +192,7 @@ select from pg_locks where - locktype = 'advisory' and - database = 'datoid' + locktype = 'advisory' and database = 'datoid' order by classid, objid, objsubid; @@ -210,12 +200,11 @@ order by classid, commit; select - COUNT(*) + count(*) from pg_locks where - locktype = 'advisory' and - database = 'datoid'; + locktype = 'advisory' and database = 'datoid'; select pg_advisory_lock(1), @@ -237,8 +226,7 @@ select from pg_locks where - locktype = 'advisory' and - database = 'datoid' + locktype = 'advisory' and database = 'datoid' order by classid, objid, objsubid; @@ -254,12 +242,11 @@ select pg_advisory_unlock_shared(2, 2); select - COUNT(*) + count(*) from pg_locks where - locktype = 'advisory' and - database = 'datoid'; + locktype = 'advisory' and database = 'datoid'; select pg_advisory_lock(1), @@ -281,8 +268,7 @@ select from pg_locks where - locktype = 'advisory' and - database = 'datoid' + locktype = 'advisory' and database = 'datoid' order by classid, objid, objsubid; @@ -290,9 +276,8 @@ order by classid, select pg_advisory_unlock_all(); select - COUNT(*) + count(*) from pg_locks where - locktype = 'advisory' and - database = 'datoid'; + locktype = 'advisory' and database = 'datoid'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__aggregates_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__aggregates_100.snap index e201e4bf1..a0216c3bb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__aggregates_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__aggregates_100.snap @@ -5,17 +5,17 @@ input_file: crates/pgls_pretty_print/tests/data/multi/aggregates.sql set extra_float_digits = 0; create table aggtest ( - a smallint, - b real + a int2, + b float4 ); copy aggtest from 'filename'; analyze aggtest; -select AVG(four) as avg_1 from onek; +select avg(four) as avg_1 from onek; -select AVG(a) as avg_32 from aggtest where a < 100; +select avg(a) as avg_32 from aggtest where a < 100; select any_value(v) from (values (1), (2), (3)) as v (v); @@ -25,25 +25,25 @@ select any_value(v) from (values (null), (1), (2)) as v (v); select any_value(v) from (values (array['hello', 'world'])) as v (v); -select cast(AVG(b) as numeric(10, 3)) as avg_107_943 from aggtest; +select cast(avg(b) as numeric(10, 3)) as avg_107_943 from aggtest; -select AVG(gpa) as avg_3_4 from only student; +select avg(gpa) as avg_3_4 from only student; -select SUM(four) as sum_1500 from onek; +select sum(four) as sum_1500 from onek; -select SUM(a) as sum_198 from aggtest; +select sum(a) as sum_198 from aggtest; -select SUM(b) as avg_431_773 from aggtest; +select sum(b) as avg_431_773 from aggtest; -select SUM(gpa) as avg_6_8 from only student; +select sum(gpa) as avg_6_8 from only student; -select MAX(four) as max_3 from onek; +select max(four) as max_3 from onek; -select MAX(a) as max_100 from aggtest; +select max(a) as max_100 from aggtest; -select MAX(aggtest.b) as max_324_78 from aggtest; +select max(aggtest.b) as max_324_78 from aggtest; -select MAX(student.gpa) as max_3_7 from student; +select max(student.gpa) as max_3_7 from student; select stddev_pop(b) from aggtest; @@ -61,29 +61,29 @@ select var_pop(cast(b as numeric)) from aggtest; select var_samp(cast(b as numeric)) from aggtest; -select var_pop(cast(1.0 as double precision)), var_samp(cast(2.0 as double precision)); +select var_pop(cast(1.0 as float8)), var_samp(cast(2.0 as float8)); -select stddev_pop(cast(3.0 as double precision)), stddev_samp(cast(4.0 as double precision)); +select stddev_pop(cast(3.0 as float8)), stddev_samp(cast(4.0 as float8)); -select var_pop(cast('inf' as double precision)), var_samp(cast('inf' as double precision)); +select var_pop(cast('inf' as float8)), var_samp(cast('inf' as float8)); -select stddev_pop(cast('inf' as double precision)), stddev_samp(cast('inf' as double precision)); +select stddev_pop(cast('inf' as float8)), stddev_samp(cast('inf' as float8)); -select var_pop(cast('nan' as double precision)), var_samp(cast('nan' as double precision)); +select var_pop(cast('nan' as float8)), var_samp(cast('nan' as float8)); -select stddev_pop(cast('nan' as double precision)), stddev_samp(cast('nan' as double precision)); +select stddev_pop(cast('nan' as float8)), stddev_samp(cast('nan' as float8)); -select var_pop(cast(1.0 as real)), var_samp(cast(2.0 as real)); +select var_pop(cast(1.0 as float4)), var_samp(cast(2.0 as float4)); -select stddev_pop(cast(3.0 as real)), stddev_samp(cast(4.0 as real)); +select stddev_pop(cast(3.0 as float4)), stddev_samp(cast(4.0 as float4)); -select var_pop(cast('inf' as real)), var_samp(cast('inf' as real)); +select var_pop(cast('inf' as float4)), var_samp(cast('inf' as float4)); -select stddev_pop(cast('inf' as real)), stddev_samp(cast('inf' as real)); +select stddev_pop(cast('inf' as float4)), stddev_samp(cast('inf' as float4)); -select var_pop(cast('nan' as real)), var_samp(cast('nan' as real)); +select var_pop(cast('nan' as float4)), var_samp(cast('nan' as float4)); -select stddev_pop(cast('nan' as real)), stddev_samp(cast('nan' as real)); +select stddev_pop(cast('nan' as float4)), stddev_samp(cast('nan' as float4)); select var_pop(cast(1.0 as numeric)), var_samp(cast(2.0 as numeric)); @@ -97,120 +97,113 @@ select var_pop(cast('nan' as numeric)), var_samp(cast('nan' as numeric)); select stddev_pop(cast('nan' as numeric)), stddev_samp(cast('nan' as numeric)); -select MAX(row(a, b)) from aggtest; +select max(row(a, b)) from aggtest; -select MAX(row(b, a)) from aggtest; +select max(row(b, a)) from aggtest; -select MIN(row(a, b)) from aggtest; +select min(row(a, b)) from aggtest; -select MIN(row(b, a)) from aggtest; +select min(row(b, a)) from aggtest; -select SUM(cast(null as int)) from generate_series(1, 3); +select sum(cast(null as int4)) from generate_series(1, 3); -select SUM(cast(null as bigint)) from generate_series(1, 3); +select sum(cast(null as int8)) from generate_series(1, 3); -select SUM(cast(null as numeric)) from generate_series(1, 3); +select sum(cast(null as numeric)) from generate_series(1, 3); -select SUM(cast(null as double precision)) from generate_series(1, 3); +select sum(cast(null as float8)) from generate_series(1, 3); -select AVG(cast(null as int)) from generate_series(1, 3); +select avg(cast(null as int4)) from generate_series(1, 3); -select AVG(cast(null as bigint)) from generate_series(1, 3); +select avg(cast(null as int8)) from generate_series(1, 3); -select AVG(cast(null as numeric)) from generate_series(1, 3); +select avg(cast(null as numeric)) from generate_series(1, 3); -select AVG(cast(null as double precision)) from generate_series(1, 3); +select avg(cast(null as float8)) from generate_series(1, 3); -select SUM(cast('NaN' as numeric)) from generate_series(1, 3); +select sum(cast('NaN' as numeric)) from generate_series(1, 3); -select AVG(cast('NaN' as numeric)) from generate_series(1, 3); +select avg(cast('NaN' as numeric)) from generate_series(1, 3); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from (values ('1'), ('infinity')) as v (x); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from (values ('infinity'), ('1')) as v (x); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from (values ('infinity'), ('infinity')) as v (x); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from (values ('-infinity'), ('infinity')) as v (x); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from (values ('-infinity'), ('-infinity')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from (values ('1'), ('infinity')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from (values ('infinity'), ('1')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from (values ('infinity'), ('infinity')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from (values ('-infinity'), ('infinity')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from (values ('-infinity'), ('-infinity')) as v (x); select - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + avg(cast(x as float8)), + var_pop(cast(x as float8)) from - ( - values - (100000003), - (100000004), - (100000006), - (100000007) - ) - as v (x); + (values (100000003), (100000004), (100000006), (100000007)) as v (x); select - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + avg(cast(x as float8)), + var_pop(cast(x as float8)) from (values (7000000000005), (7000000000007)) as v (x); @@ -233,47 +226,29 @@ select covar_pop(b, a), covar_samp(b, a) from aggtest; select corr(b, a) from aggtest; select - covar_pop( - cast(1 as double precision), - cast(2 as double precision) - ), - covar_samp( - cast(3 as double precision), - cast(4 as double precision) - ); + covar_pop(cast(1 as float8), cast(2 as float8)), + covar_samp(cast(3 as float8), cast(4 as float8)); select - covar_pop( - cast(1 as double precision), - cast('inf' as double precision) - ), - covar_samp( - cast(3 as double precision), - cast('inf' as double precision) - ); + covar_pop(cast(1 as float8), cast('inf' as float8)), + covar_samp(cast(3 as float8), cast('inf' as float8)); select - covar_pop( - cast(1 as double precision), - cast('nan' as double precision) - ), - covar_samp( - cast(3 as double precision), - cast('nan' as double precision) - ); + covar_pop(cast(1 as float8), cast('nan' as float8)), + covar_samp(cast(3 as float8), cast('nan' as float8)); create table regr_test ( - x double precision, - y double precision + x float8, + y float8 ); insert into regr_test values (10, 150), (20, 250), (30, 350), (80, 540), (100, 200); select - COUNT(*), - SUM(x), + count(*), + sum(x), regr_sxx(y, x), - SUM(y), + sum(y), regr_syy(y, x), regr_sxy(y, x) from @@ -281,17 +256,17 @@ from where x in (10, 20, 30, 80); -select COUNT(*), SUM(x), regr_sxx(y, x), SUM(y), regr_syy(y, x), regr_sxy(y, x) from regr_test; +select count(*), sum(x), regr_sxx(y, x), sum(y), regr_syy(y, x), regr_sxy(y, x) from regr_test; -select float8_accum(cast('{4,140,2900}' as double precision[]), 100); +select float8_accum(cast('{4,140,2900}' as float8[]), 100); -select float8_regr_accum(cast('{4,140,2900,1290,83075,15050}' as double precision[]), 200, 100); +select float8_regr_accum(cast('{4,140,2900,1290,83075,15050}' as float8[]), 200, 100); select - COUNT(*), - SUM(x), + count(*), + sum(x), regr_sxx(y, x), - SUM(y), + sum(y), regr_syy(y, x), regr_sxy(y, x) from @@ -300,10 +275,10 @@ where x in (10, 20, 30); select - COUNT(*), - SUM(x), + count(*), + sum(x), regr_sxx(y, x), - SUM(y), + sum(y), regr_syy(y, x), regr_sxy(y, x) from @@ -311,55 +286,39 @@ from where x in (80, 100); -select - float8_combine( - cast('{3,60,200}' as double precision[]), - cast('{0,0,0}' as double precision[]) - ); +select float8_combine(cast('{3,60,200}' as float8[]), cast('{0,0,0}' as float8[])); -select - float8_combine( - cast('{0,0,0}' as double precision[]), - cast('{2,180,200}' as double precision[]) - ); +select float8_combine(cast('{0,0,0}' as float8[]), cast('{2,180,200}' as float8[])); -select - float8_combine( - cast('{3,60,200}' as double precision[]), - cast('{2,180,200}' as double precision[]) - ); +select float8_combine(cast('{3,60,200}' as float8[]), cast('{2,180,200}' as float8[])); select float8_regr_combine( - cast('{3,60,200,750,20000,2000}' - as double precision[]), - cast('{0,0,0,0,0,0}' as double precision[]) + cast('{3,60,200,750,20000,2000}' as float8[]), + cast('{0,0,0,0,0,0}' as float8[]) ); select float8_regr_combine( - cast('{0,0,0,0,0,0}' as double precision[]), - cast('{2,180,200,740,57800,-3400}' - as double precision[]) + cast('{0,0,0,0,0,0}' as float8[]), + cast('{2,180,200,740,57800,-3400}' as float8[]) ); select float8_regr_combine( - cast('{3,60,200,750,20000,2000}' - as double precision[]), - cast('{2,180,200,740,57800,-3400}' - as double precision[]) + cast('{3,60,200,750,20000,2000}' as float8[]), + cast('{2,180,200,740,57800,-3400}' as float8[]) ); drop table regr_test; -select COUNT(four) as cnt_1000 from onek; +select count(four) as cnt_1000 from onek; -select COUNT(distinct four) as cnt_4 from onek; +select count(distinct four) as cnt_4 from onek; -select ten, COUNT(*), SUM(four) from onek group by ten order by ten; +select ten, count(*), sum(four) from onek group by ten order by ten; -select ten, COUNT(four), SUM(distinct four) from onek group by ten order by ten; +select ten, count(four), sum(distinct four) from onek group by ten order by ten; select newavg(four) as avg_1 from onek; @@ -373,47 +332,31 @@ select oldcnt(*) as cnt_1000 from onek; select sum2(q1, q2) from int8_tbl; -select SUM(q1 + q2), SUM(q1) + SUM(q2) from int8_tbl; +select sum(q1 + q2), sum(q1) + sum(q2) from int8_tbl; -select SUM(q1 - q2), SUM(q2 - q1), SUM(q1) - SUM(q2) from int8_tbl; +select sum(q1 - q2), sum(q2 - q1), sum(q1) - sum(q2) from int8_tbl; -select SUM(q1 * 2000), SUM(-q1 * 2000), 2000 * SUM(q1) from int8_tbl; +select sum(q1 * 2000), sum(-q1 * 2000), 2000 * sum(q1) from int8_tbl; select ten, - SUM(distinct four) + sum(distinct four) from onek as a group by ten having - exists - ( - select - 1 - from - onek as b - where - SUM(distinct a.four) = b.four - ); + exists (select 1 from onek as b where sum(distinct a.four) = b.four); select ten, - SUM(distinct four) + sum(distinct four) from onek as a group by ten having - exists - ( - select - 1 - from - onek as b - where - SUM(distinct a.four + b.four) = b.four - ); + exists (select 1 from onek as b where sum(distinct a.four + b.four) = b.four); -select (select MAX((select i.unique2 from tenk1 as i where i.unique1 = o.unique1))) from tenk1 as o; +select (select max((select i.unique2 from tenk1 as i where i.unique1 = o.unique1))) from tenk1 as o; select s1, @@ -421,15 +364,7 @@ select sm from generate_series(1, 3) as s1, - lateral ( - select - s2, - SUM(s1 + s2) as sm - from - generate_series(1, 3) as s2 - group by s2 - ) - as ss + lateral (select s2, sum(s1 + s2) as sm from generate_series(1, 3) as s2 group by s2) as ss order by 1, 2; @@ -439,48 +374,26 @@ select sm from generate_series(1, 3) as s1, - lateral ( - select - s2, - SUM(s1 + s2) as sm - from - generate_series(1, 3) as s2 - group by s2 - ) - as ss + lateral (select s2, sum(s1 + s2) as sm from generate_series(1, 3) as s2 group by s2) as ss order by 1, 2; select - array( - select - SUM(x + y) as s - from - generate_series(1, 3) as y - group by y - order by s - ) + array(select sum(x + y) as s from generate_series(1, 3) as y group by y order by s) from generate_series(1, 3) as x; select - array( - select - SUM(x + y) as s - from - generate_series(1, 3) as y - group by y - order by s - ) + array(select sum(x + y) as s from generate_series(1, 3) as y group by y order by s) from generate_series(1, 3) as x; create temporary table bitwise_test ( - i2 smallint, - i4 int, - i8 bigint, + i2 int2, + i4 int4, + i8 int8, i int, - x smallint, + x int2, y bit(4) ); @@ -531,10 +444,10 @@ select not boolor_statefunc(false, false) as t; create temporary table bool_test ( - b1 boolean, - b2 boolean, - b3 boolean, - b4 boolean + b1 bool, + b2 bool, + b3 bool, + b4 bool ); select bool_and(b1) as n, bool_or(b3) as n from bool_test; @@ -569,67 +482,67 @@ select from bool_test; -select MIN(unique1) from tenk1; +select min(unique1) from tenk1; -select MIN(unique1) from tenk1; +select min(unique1) from tenk1; -select MAX(unique1) from tenk1; +select max(unique1) from tenk1; -select MAX(unique1) from tenk1; +select max(unique1) from tenk1; -select MAX(unique1) from tenk1 where unique1 < 42; +select max(unique1) from tenk1 where unique1 < 42; -select MAX(unique1) from tenk1 where unique1 < 42; +select max(unique1) from tenk1 where unique1 < 42; -select MAX(unique1) from tenk1 where unique1 > 42; +select max(unique1) from tenk1 where unique1 > 42; -select MAX(unique1) from tenk1 where unique1 > 42; +select max(unique1) from tenk1 where unique1 > 42; begin; set local max_parallel_workers_per_gather = 0; -select MAX(unique1) from tenk1 where unique1 > 42000; +select max(unique1) from tenk1 where unique1 > 42000; -select MAX(unique1) from tenk1 where unique1 > 42000; +select max(unique1) from tenk1 where unique1 > 42000; rollback; -select MAX(tenthous) from tenk1 where thousand = 33; +select max(tenthous) from tenk1 where thousand = 33; -select MAX(tenthous) from tenk1 where thousand = 33; +select max(tenthous) from tenk1 where thousand = 33; -select MIN(tenthous) from tenk1 where thousand = 33; +select min(tenthous) from tenk1 where thousand = 33; -select MIN(tenthous) from tenk1 where thousand = 33; +select min(tenthous) from tenk1 where thousand = 33; -select f1, (select MIN(unique1) from tenk1 where unique1 > f1) as gt from int4_tbl; +select f1, (select min(unique1) from tenk1 where unique1 > f1) as gt from int4_tbl; -select f1, (select MIN(unique1) from tenk1 where unique1 > f1) as gt from int4_tbl; +select f1, (select min(unique1) from tenk1 where unique1 > f1) as gt from int4_tbl; -select distinct MAX(unique2) from tenk1; +select distinct max(unique2) from tenk1; -select distinct MAX(unique2) from tenk1; +select distinct max(unique2) from tenk1; -select MAX(unique2) from tenk1 order by 1; +select max(unique2) from tenk1 order by 1; -select MAX(unique2) from tenk1 order by 1; +select max(unique2) from tenk1 order by 1; -select MAX(unique2) from tenk1 order by MAX(unique2); +select max(unique2) from tenk1 order by max(unique2); -select MAX(unique2) from tenk1 order by MAX(unique2); +select max(unique2) from tenk1 order by max(unique2); -select MAX(unique2) from tenk1 order by MAX(unique2) + 1; +select max(unique2) from tenk1 order by max(unique2) + 1; -select MAX(unique2) from tenk1 order by MAX(unique2) + 1; +select max(unique2) from tenk1 order by max(unique2) + 1; -select MAX(unique2), generate_series(1, 3) as g from tenk1 order by g desc; +select max(unique2), generate_series(1, 3) as g from tenk1 order by g desc; -select MAX(unique2), generate_series(1, 3) as g from tenk1 order by g desc; +select max(unique2), generate_series(1, 3) as g from tenk1 order by g desc; -select MAX(100) from tenk1; +select max(100) from tenk1; -select MAX(100) from tenk1; +select max(100) from tenk1; create table minmaxtest (f1 int); @@ -642,20 +555,13 @@ inherits (minmaxtest); create table minmaxtest3 () inherits (minmaxtest); -create index "minmaxtesti" on minmaxtest using btree (f1); +create index minmaxtesti on minmaxtest using btree (f1); -create index "minmaxtest1i" on minmaxtest1 using btree (f1); +create index minmaxtest1i on minmaxtest1 using btree (f1); -create index "minmaxtest2i" on minmaxtest2 using btree (f1 desc); +create index minmaxtest2i on minmaxtest2 using btree (f1 desc); -create index "minmaxtest3i" -on minmaxtest3 -using btree -( - f1 -) -where - f1 is not null; +create index minmaxtest3i on minmaxtest3 using btree (f1) where f1 is not null; insert into minmaxtest values (11), (12); @@ -665,13 +571,13 @@ insert into minmaxtest2 values (15), (16); insert into minmaxtest3 values (17), (18); -select MIN(f1), MAX(f1) from minmaxtest; +select min(f1), max(f1) from minmaxtest; -select MIN(f1), MAX(f1) from minmaxtest; +select min(f1), max(f1) from minmaxtest; -select distinct MIN(f1), MAX(f1) from minmaxtest; +select distinct min(f1), max(f1) from minmaxtest; -select distinct MIN(f1), MAX(f1) from minmaxtest; +select distinct min(f1), max(f1) from minmaxtest; drop table minmaxtest cascade; @@ -679,27 +585,18 @@ begin; set local enable_sort = off; -select f1, (select distinct MIN(t1.f1) from int4_tbl as t1 where t1.f1 = t0.f1) from int4_tbl as t0; +select f1, (select distinct min(t1.f1) from int4_tbl as t1 where t1.f1 = t0.f1) from int4_tbl as t0; -select f1, (select distinct MIN(t1.f1) from int4_tbl as t1 where t1.f1 = t0.f1) from int4_tbl as t0; +select f1, (select distinct min(t1.f1) from int4_tbl as t1 where t1.f1 = t0.f1) from int4_tbl as t0; rollback; -select MAX(MIN(unique1)) from tenk1; +select max(min(unique1)) from tenk1; -select (select MAX(MIN(unique1)) from int8_tbl) from tenk1; +select (select max(min(unique1)) from int8_tbl) from tenk1; select - AVG( - ( - select - AVG( - a1.col1 order by (select AVG(a2.col2) from tenk1 as a3) - ) - from - tenk1 as a1 (col1) - ) - ) + avg((select avg(a1.col1 order by (select avg(a2.col2) from tenk1 as a3)) from tenk1 as a1 (col1))) from tenk1 as a2 (col2); @@ -770,7 +667,7 @@ create temporary table p_t1 ( d int, primary key (a, b) ) -partition by LIST(a); +partition by list(a); create temporary table p_t1_1 partition of p_t1 for values in (1); @@ -778,7 +675,7 @@ create temporary table p_t1_2 partition of p_t1 for values in (2); select * from p_t1 group by a, b, c, d; -create unique index "t2_z_uidx" on t2 using btree (z); +create unique index t2_z_uidx on t2 using btree (z); select y, z from t2 group by y, z; @@ -793,14 +690,7 @@ select x, y, z from t2 group by z, x, y; drop index t2_z_uidx; -create index "t2_z_uidx" -on t2 -using btree -( - z -) -where - z > 0; +create index t2_z_uidx on t2 using btree (z) where z > 0; select y, z from t2 group by y, z; @@ -809,7 +699,7 @@ drop index t2_z_uidx; alter table t2 alter column z drop not null; -create unique index "t2_z_uidx" on t2 using btree (z) nulls not distinct; +create unique index t2_z_uidx on t2 using btree (z) nulls not distinct; select y, z from t2 group by y, z; @@ -831,79 +721,73 @@ create temporary table t2 ( f2 oid ); -select f1 from t1 left outer join t2 using ("f1") group by f1; +select f1 from t1 left outer join t2 using (f1) group by f1; -select f1 from t1 left outer join t2 using ("f1") group by t1.f1; +select f1 from t1 left outer join t2 using (f1) group by t1.f1; -select t1.f1 from t1 left outer join t2 using ("f1") group by t1.f1; +select t1.f1 from t1 left outer join t2 using (f1) group by t1.f1; -select t1.f1 from t1 left outer join t2 using ("f1") group by f1; +select t1.f1 from t1 left outer join t2 using (f1) group by f1; select f1, - COUNT(*) + count(*) from - t1 as x (x0, x1) - left outer join - t1 left outer join t2 using ("f1") - on x0 = 0 + t1 as x (x0, x1) left outer join t1 left outer join t2 using (f1) on x0 = 0 group by f1; select f2, - COUNT(*) + count(*) from - t1 as x (x0, x1) - left outer join - t1 left outer join t2 using ("f2") - on x0 = 0 + t1 as x (x0, x1) left outer join t1 left outer join t2 using (f2) on x0 = 0 group by f2; drop table t1, t2; -select SUM(two order by two), MAX(four order by four), MIN(four order by four) from tenk1; +select sum(two order by two), max(four order by four), min(four order by four) from tenk1; select - SUM(two order by two), - MAX(four order by four), - MIN(four order by four), - MAX(two order by two) + sum(two order by two), + max(four order by four), + min(four order by four), + max(two order by two) from tenk1; select - MAX(four order by four), - SUM(two order by two), - MIN(four order by four), - MAX(two order by two) + max(four order by four), + sum(two order by two), + min(four order by four), + max(two order by two) from tenk1; select - MAX(four order by four), - SUM(two order by two), - MIN(four order by four), - MAX(two order by two), - SUM(ten order by ten), - MIN(ten order by ten), - MAX(ten order by ten) + max(four order by four), + sum(two order by two), + min(four order by four), + max(two order by two), + sum(ten order by ten), + min(ten order by ten), + max(ten order by ten) from tenk1; select - SUM(unique1 order by ten, two), - SUM(unique1 order by four), - SUM(unique1 order by two, four) + sum(unique1 order by ten, two), + sum(unique1 order by four), + sum(unique1 order by two, four) from tenk1 group by ten; select - SUM(unique1 order by two), - SUM(unique1 order by four), - SUM(unique1 order by four, two), - SUM(unique1 order by two, random()), - SUM(unique1 order by two, random(), random() + 1) + sum(unique1 order by two), + sum(unique1 order by four), + sum(unique1 order by four, two), + sum(unique1 order by two, random()), + sum(unique1 order by two, random(), random() + 1) from tenk1 group by ten; @@ -912,21 +796,16 @@ select array_agg(distinct val) from (select null as val from generate_series(1, set enable_presorted_aggregate = off; -select SUM(two order by two) from tenk1; +select sum(two order by two) from tenk1; reset enable_presorted_aggregate; -select SUM(two order by two) filter (where two > 1) from tenk1; +select sum(two order by two) filter (where two > 1) from tenk1; select string_agg(distinct f1, ',') filter (where length(f1) > 1) from varchar_tbl; select - string_agg( - distinct cast(f1 as varchar(2)), - ',' - ) - filter (where - length(f1) > 1) + string_agg(distinct cast(f1 as varchar(2)), ',') filter (where length(f1) > 1) from varchar_tbl; @@ -952,149 +831,64 @@ from select aggfstr(a, b, c) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c); + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c); select aggfns(a, b, c) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c); + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c); select aggfstr(distinct a, b, c) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 3) as i; select aggfns(distinct a, b, c) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 3) as i; select aggfstr(distinct a, b, c order by b) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 3) as i; select aggfns(distinct a, b, c order by b) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 3) as i; select aggfns(distinct a, a, c order by c using ~<~, a) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 2) as i; select aggfns(distinct a, a, c order by c using ~<~) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 2) as i; select aggfns(distinct a, a, c order by a) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 2) as i; select - aggfns( - distinct a, - b, - c order by a, - c using ~<~, - b - ) + aggfns(distinct a, b, c order by a, c using ~<~, b) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 2) as i; select string_agg(distinct 'a', ','), - SUM( - ( - select - SUM(1) - from - (values (1)) as b (id) - where - a.id = b.id - ) - ) + sum((select sum(1) from (values (1)) as b (id) where a.id = b.id)) from unnest(array[1]) as a (id); @@ -1102,14 +896,7 @@ create view agg_view1 as select aggfns(a, b, c) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c); + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c); select * from agg_view1; @@ -1119,14 +906,7 @@ create or replace view agg_view1 as select aggfns(distinct a, b, c) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 3) as i; select * from agg_view1; @@ -1137,14 +917,7 @@ create or replace view agg_view1 as select aggfns(distinct a, b, c order by b) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 3) as i; select * from agg_view1; @@ -1155,14 +928,7 @@ create or replace view agg_view1 as select aggfns(a, b, c order by b + 1) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c); + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c); select * from agg_view1; @@ -1172,14 +938,7 @@ create or replace view agg_view1 as select aggfns(a, a, c order by b) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c); + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c); select * from agg_view1; @@ -1189,14 +948,7 @@ create or replace view agg_view1 as select aggfns(a, b, c order by c using ~<~) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c); + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c); select * from agg_view1; @@ -1204,22 +956,9 @@ select pg_get_viewdef(cast('agg_view1' as regclass)); create or replace view agg_view1 as select - aggfns( - distinct a, - b, - c order by a, - c using ~<~, - b - ) + aggfns(distinct a, b, c order by a, c using ~<~, b) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 2) as i; select * from agg_view1; @@ -1284,17 +1023,17 @@ select string_agg(v, null) from bytea_test_table; select string_agg(v, decode('ee', 'hex')) from bytea_test_table; -select MIN(v) from bytea_test_table; +select min(v) from bytea_test_table; -select MAX(v) from bytea_test_table; +select max(v) from bytea_test_table; insert into bytea_test_table values (decode('ffff', 'hex')); insert into bytea_test_table values (decode('aaaa', 'hex')); -select MIN(v) from bytea_test_table; +select min(v) from bytea_test_table; -select MAX(v) from bytea_test_table; +select max(v) from bytea_test_table; drop table bytea_test_table; @@ -1305,11 +1044,7 @@ create table pagg_test ( with (autovacuum_enabled = off); insert into pagg_test -select - case x % 4 when 1 then null else x end, - x % 10 -from - generate_series(1, 5000) as x; +select case x % 4 when 1 then null else x end, x % 10 from generate_series(1, 5000) as x; set parallel_setup_cost = 0; @@ -1326,29 +1061,24 @@ set max_parallel_workers_per_gather = 2; create view v_pagg_test as select y, - MIN(t) as tmin, - MAX(t) as tmax, - COUNT(distinct t) as tndistinct, - MIN(b) as bmin, - MAX(b) as bmax, - COUNT(distinct b) as bndistinct, - MIN(a) as amin, - MAX(a) as amax, - COUNT(distinct a) as andistinct, - MIN(aa) as aamin, - MAX(aa) as aamax, - COUNT(distinct aa) as aandistinct + min(t) as tmin, + max(t) as tmax, + count(distinct t) as tndistinct, + min(b) as bmin, + max(b) as bmax, + count(distinct b) as bndistinct, + min(a) as amin, + max(a) as amax, + count(distinct a) as andistinct, + min(aa) as aamin, + max(aa) as aamax, + count(distinct aa) as aandistinct from ( select y, - cast(unnest(regexp_split_to_array(a1.t, ',')) - as int) - as t, - unnest( - regexp_split_to_array(cast(a1.b as text), ',') - ) - as b, + cast(unnest(regexp_split_to_array(a1.t, ',')) as int) as t, + unnest(regexp_split_to_array(cast(a1.b as text), ',')) as b, unnest(a1.a) as a, unnest(a1.aa) as aa from @@ -1356,8 +1086,7 @@ from select y, string_agg(cast(x as text), ',') as t, - string_agg(cast(cast(x as text) as bytea), ',') - as b, + string_agg(cast(cast(x as text) as bytea), ',') as b, array_agg(x) as a, array_agg(array[x]) as aa from @@ -1399,83 +1128,50 @@ drop view v_pagg_test; drop table pagg_test; -select MIN(unique1) filter (where unique1 > 100) from tenk1; +select min(unique1) filter (where unique1 > 100) from tenk1; -select SUM(1 / ten) filter (where ten > 0) from tenk1; +select sum(1 / ten) filter (where ten > 0) from tenk1; select ten, - SUM( - distinct four - ) - filter (where - cast(four as text) ~ '123') + sum(distinct four) filter (where cast(four as text) ~ '123') from onek as a group by ten; select ten, - SUM(distinct four) filter (where four > 10) + sum(distinct four) filter (where four > 10) from onek as a group by ten having - exists - ( - select - 1 - from - onek as b - where - SUM(distinct a.four) = b.four - ); + exists (select 1 from onek as b where sum(distinct a.four) = b.four); select - MAX( - foo collate "C" - ) - filter (where - bar collate "POSIX" > '0') + max(foo collate "C") filter (where bar collate "POSIX" > '0') from (values ('a', 'b')) as v (foo, bar); select any_value(v) filter (where v > 2) from (values (1), (2), (3)) as v (v); -select (select COUNT(*) from (values (1)) as t0 (inner_c)) from (values (2), (3)) as t1 (outer_c); +select (select count(*) from (values (1)) as t0 (inner_c)) from (values (2), (3)) as t1 (outer_c); select - ( - select - COUNT(*) filter (where outer_c <> 0) - from - (values (1)) as t0 (inner_c) - ) + (select count(*) filter (where outer_c <> 0) from (values (1)) as t0 (inner_c)) from (values (2), (3)) as t1 (outer_c); select - ( - select - COUNT(inner_c) filter (where outer_c <> 0) - from - (values (1)) as t0 (inner_c) - ) + (select count(inner_c) filter (where outer_c <> 0) from (values (1)) as t0 (inner_c)) from (values (2), (3)) as t1 (outer_c); select ( select - MAX( - ( - select - i.unique2 - from - tenk1 as i - where - i.unique1 = o.unique1 - ) + max( + (select i.unique2 from tenk1 as i where i.unique1 = o.unique1) ) filter (where o.unique1 < 10) @@ -1484,93 +1180,43 @@ from tenk1 as o; select - SUM( - unique1 - ) - filter (where - unique1 in - ( - select unique1 from onek where unique1 < 100 - )) + sum(unique1) filter (where unique1 in (select unique1 from onek where unique1 < 100)) from tenk1; select - aggfns( - distinct a, - b, - c order by a, - c using ~<~, - b - ) - filter (where - a > 1) + aggfns(distinct a, b, c order by a, c using ~<~, b) filter (where a > 1) from - ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') - ) - as v (a, b, c), + (values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz')) as v (a, b, c), generate_series(1, 2) as i; -select MAX(0) filter (where b1) from bool_test; +select max(0) filter (where b1) from bool_test; -select (select MAX(0) filter (where b1)) from bool_test; +select (select max(0) filter (where b1)) from bool_test; -select MAX(unique1) filter (where SUM(ten) > 0) from tenk1; +select max(unique1) filter (where sum(ten) > 0) from tenk1; -select (select MAX(unique1) filter (where SUM(ten) > 0) from int8_tbl) from tenk1; +select (select max(unique1) filter (where sum(ten) > 0) from int8_tbl) from tenk1; -select MAX(unique1) filter (where bool_or(ten > 0)) from tenk1; +select max(unique1) filter (where bool_or(ten > 0)) from tenk1; -select (select MAX(unique1) filter (where bool_or(ten > 0)) from int8_tbl) from tenk1; +select (select max(unique1) filter (where bool_or(ten > 0)) from int8_tbl) from tenk1; select p, - percentile_cont( - p - ) - within group (order by cast(x as double precision)) + percentile_cont(p) within group (order by cast(x as float8)) from generate_series(1, 5) as x, - ( - values - (cast(0 as double precision)), - (0.1), - (0.25), - (0.4), - (0.5), - (0.6), - (0.75), - (0.9), - (1) - ) - as v (p) + (values (cast(0 as float8)), (0.1), (0.25), (0.4), (0.5), (0.6), (0.75), (0.9), (1)) as v (p) group by p order by p; select p, - SUM() - within group (order by cast(x as double precision)) + sum() within group (order by cast(x as float8)) from generate_series(1, 5) as x, - ( - values - (cast(0 as double precision)), - (0.1), - (0.25), - (0.4), - (0.5), - (0.6), - (0.75), - (0.9), - (1) - ) - as v (p) + (values (cast(0 as float8)), (0.1), (0.25), (0.4), (0.5), (0.6), (0.75), (0.9), (1)) as v (p) group by p order by p; @@ -1579,61 +1225,37 @@ select percentile_cont(p, p) from generate_series(1, 5) as x, - ( - values - (cast(0 as double precision)), - (0.1), - (0.25), - (0.4), - (0.5), - (0.6), - (0.75), - (0.9), - (1) - ) - as v (p) + (values (cast(0 as float8)), (0.1), (0.25), (0.4), (0.5), (0.6), (0.75), (0.9), (1)) as v (p) group by p order by p; select percentile_cont(0.5) within group (order by b) from aggtest; -select percentile_cont(0.5) within group (order by b), SUM(b) from aggtest; +select percentile_cont(0.5) within group (order by b), sum(b) from aggtest; select percentile_cont(0.5) within group (order by thousand) from tenk1; select percentile_disc(0.5) within group (order by thousand) from tenk1; -select RANK(3) within group (order by x) from (values (1), (1), (2), (2), (3), (3), (4)) as v (x); +select rank(3) within group (order by x) from (values (1), (1), (2), (2), (3), (3), (4)) as v (x); select - CUME_DIST(3) within group (order by x) + cume_dist(3) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3), (4) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4)) as v (x); select - PERCENT_RANK(3) within group (order by x) + percent_rank(3) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3), (4), (5) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4), (5)) as v (x); select - DENSE_RANK(3) within group (order by x) + dense_rank(3) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3), (4) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4)) as v (x); select - percentile_disc( - array[0, 0.1, 0.25, 0.5, 0.75, 0.9, 1] - ) - within group (order by thousand) + percentile_disc(array[0, 0.1, 0.25, 0.5, 0.75, 0.9, 1]) within group (order by thousand) from tenk1; @@ -1641,8 +1263,7 @@ select percentile_cont(array[0, 0.25, 0.5, 0.75, 1]) within group (order by thou select percentile_disc( - array[array[null, 1, 0.5], - array[0.75, 0.25, null]] + array[array[null, 1, 0.5], array[0.75, 0.25, null]] ) within group (order by thousand) from @@ -1650,17 +1271,7 @@ from select percentile_cont( - array[0, - 1, - 0.25, - 0.75, - 0.5, - 1, - 0.3, - 0.32, - 0.35, - 0.38, - 0.4] + array[0, 1, 0.25, 0.75, 0.5, 1, 0.3, 0.32, 0.35, 0.38, 0.4] ) within group (order by x) from @@ -1669,38 +1280,23 @@ from select ten, mode() within group (order by string4) from tenk1 group by ten; select - percentile_disc( - array[0.25, 0.5, 0.75] - ) - within group (order by x) + percentile_disc(array[0.25, 0.5, 0.75]) within group (order by x) from - unnest( - cast('{fred,jim,fred,jack,jill,fred,jill,jim,jim,sheila,jim,sheila}' - as text[]) - ) - as u (x); + unnest(cast('{fred,jim,fred,jack,jill,fred,jill,jim,jim,sheila,jim,sheila}' as text[])) as u (x); select - pg_collation_for( - percentile_disc( - 1 - ) - within group (order by x collate "POSIX") - ) + pg_collation_for(percentile_disc(1) within group (order by x collate "POSIX")) from (values ('fred'), ('jim')) as v (x); select test_rank(3) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3), (4) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4)) as v (x); select test_percentile_disc(0.5) within group (order by thousand) from tenk1; -select RANK(x) within group (order by x) from generate_series(1, 5) as x; +select rank(x) within group (order by x) from generate_series(1, 5) as x; select array( @@ -1713,55 +1309,34 @@ select from generate_series(1, 5) as g (x); -select RANK(SUM(x)) within group (order by x) from generate_series(1, 5) as x; +select rank(sum(x)) within group (order by x) from generate_series(1, 5) as x; -select RANK(3) within group (order by x) from (values ('fred'), ('jim')) as v (x); +select rank(3) within group (order by x) from (values ('fred'), ('jim')) as v (x); -select RANK(3) within group (order by stringu1, stringu2) from tenk1; +select rank(3) within group (order by stringu1, stringu2) from tenk1; -select RANK('fred') within group (order by x) from generate_series(1, 5) as x; +select rank('fred') within group (order by x) from generate_series(1, 5) as x; select - RANK( - cast('adam' as text) collate "C" - ) - within group (order by x collate "POSIX") + rank(cast('adam' as text) collate "C") within group (order by x collate "POSIX") from (values ('fred'), ('jim')) as v (x); select - RANK( - cast('adam' as varchar) - ) - within group (order by x) + rank(cast('adam' as varchar)) within group (order by x) from (values ('fred'), ('jim')) as v (x); -select RANK('3') within group (order by x) from generate_series(1, 5) as x; +select rank('3') within group (order by x) from generate_series(1, 5) as x; -select PERCENT_RANK(0) within group (order by x) from generate_series(1, 0) as x; +select percent_rank(0) within group (order by x) from generate_series(1, 0) as x; create view aggordview1 as select ten, - percentile_disc( - 0.5 - ) - within group (order by thousand) - as p50, - percentile_disc( - 0.5 - ) - within group (order by thousand) - filter (where - hundred = 1) - as px, - RANK( - 5, - 'AZZZZ', - 50 - ) - within group (order by hundred, string4 desc, hundred) + percentile_disc(0.5) within group (order by thousand) as p50, + percentile_disc(0.5) within group (order by thousand) filter (where hundred = 1) as px, + rank(5, 'AZZZZ', 50) within group (order by hundred, string4 desc, hundred) from tenk1 group by ten @@ -1792,7 +1367,7 @@ create type avg_state as (total bigint, count bigint); create or replace function avg_transfn(state avg_state, n int) returns avg_state language plpgsql -as $function$ +as $$ declare new_state avg_state; begin raise notice 'avg_transfn called with %', n; @@ -1811,12 +1386,12 @@ begin return null; end -$function$; +$$; create function avg_finalfn(state avg_state) -returns int +returns int4 language plpgsql -as $function$ +as $$ begin if state is null then return NULL; @@ -1824,12 +1399,12 @@ begin return state.total / state.count; end if; end -$function$; +$$; create function sum_finalfn(state avg_state) -returns int +returns int4 language plpgsql -as $function$ +as $$ begin if state is null then return NULL; @@ -1837,11 +1412,11 @@ begin return state.total; end if; end -$function$; +$$; -create aggregate my_avg (int) (stype = avg_state, sfunc = avg_transfn, finalfunc = avg_finalfn); +create aggregate my_avg (int4) (stype = avg_state, sfunc = avg_transfn, finalfunc = avg_finalfn); -create aggregate my_sum (int) (stype = avg_state, sfunc = avg_transfn, finalfunc = sum_finalfn); +create aggregate my_sum (int4) (stype = avg_state, sfunc = avg_transfn, finalfunc = sum_finalfn); select my_avg(one), my_avg(one) from (values (1), (3)) as t (one); @@ -1859,36 +1434,22 @@ select percentile_cont(0.5) within group (order by a), percentile_disc(0.5) within group (order by a) from - ( - values - (cast(1 as double precision)), - (3), - (5), - (7) - ) - as t (a); + (values (cast(1 as float8)), (3), (5), (7)) as t (a); select percentile_cont(0.25) within group (order by a), percentile_disc(0.5) within group (order by a) from - ( - values - (cast(1 as double precision)), - (3), - (5), - (7) - ) - as t (a); + (values (cast(1 as float8)), (3), (5), (7)) as t (a); select - RANK(4) within group (order by a), - DENSE_RANK(4) within group (order by a) + rank(4) within group (order by a), + dense_rank(4) within group (order by a) from (values (1), (3), (5), (7)) as t (a); create aggregate my_sum_init ( - int + int4 ) ( stype = avg_state, sfunc = avg_transfn, @@ -1897,7 +1458,7 @@ create aggregate my_sum_init ( ); create aggregate my_avg_init ( - int + int4 ) ( stype = avg_state, sfunc = avg_transfn, @@ -1906,7 +1467,7 @@ create aggregate my_avg_init ( ); create aggregate my_avg_init2 ( - int + int4 ) ( stype = avg_state, sfunc = avg_transfn, @@ -1922,10 +1483,10 @@ rollback; begin; -create or replace function sum_transfn(state int, n int) -returns int +create or replace function sum_transfn(state int4, n int4) +returns int4 language plpgsql -as $function$ +as $$ declare new_state int4; begin raise notice 'sum_transfn called with %', n; @@ -1942,12 +1503,12 @@ begin return null; end -$function$; +$$; -create function halfsum_finalfn(state int) -returns int +create function halfsum_finalfn(state int4) +returns int4 language plpgsql -as $function$ +as $$ begin if state is null then return NULL; @@ -1955,11 +1516,17 @@ begin return state / 2; end if; end -$function$; +$$; -create aggregate my_sum (int) (stype = int, sfunc = sum_transfn); +create aggregate my_sum (int4) (stype = int4, sfunc = sum_transfn); -create aggregate my_half_sum (int) (stype = int, sfunc = sum_transfn, finalfunc = halfsum_finalfn); +create aggregate my_half_sum ( + int4 +) ( + stype = int4, + sfunc = sum_transfn, + finalfunc = halfsum_finalfn +); select my_sum(one), my_half_sum(one) from (values (1), (2), (3), (4)) as t (one); @@ -1967,24 +1534,23 @@ rollback; begin; -create function balkifnull(bigint, int) -returns bigint +create function balkifnull(int8, int4) +returns int8 language plpgsql strict -as $function$ +as $$ BEGIN IF $1 IS NULL THEN RAISE 'erroneously called with NULL argument'; END IF; RETURN NULL; -END -$function$; +END$$; create aggregate balk ( - int + int4 ) ( sfunc = balkifnull(int8, int4), - stype = bigint, + stype = int8, parallel = safe, initcond = '0' ); @@ -1995,15 +1561,9 @@ rollback; create table btg as - select - i % 10 as x, - i % 10 as y, - 'abc' || i % 10 as z, - i as w - from - generate_series(1, 100) as i; + select i % 10 as x, i % 10 as y, 'abc' || i % 10 as z, i as w from generate_series(1, 100) as i; -create index "btg_x_y_idx" on btg using btree (x, y); +create index btg_x_y_idx on btg using btree (x, y); analyze btg; @@ -2011,23 +1571,20 @@ set enable_hashagg = off; set enable_seqscan = off; -select COUNT(*) from btg group by y, x; +select count(*) from btg group by y, x; -select COUNT(*) from btg group by z, y, w, x; +select count(*) from btg group by z, y, w, x; -select COUNT(*) from (select * from btg order by x, y, w, z) as q1 group by w, x, z, y; +select count(*) from (select * from btg order by x, y, w, z) as q1 group by w, x, z, y; set enable_hashjoin = off; set enable_nestloop = off; select - COUNT(*) + count(*) from - btg as t1 - inner join - btg as t2 - on t1.w = t2.w and t1.x = t2.x and t1.z = t2.z + btg as t1 inner join btg as t2 on t1.w = t2.w and t1.x = t2.x and t1.z = t2.z group by t1.w, t1.z, t1.x; @@ -2036,24 +1593,17 @@ reset enable_nestloop; reset enable_hashjoin; -select COUNT(*) from btg group by w, x, z, y order by y, x, z, w; +select count(*) from btg group by w, x, z, y order by y, x, z, w; -select COUNT(*) from btg group by w, x, y, z order by x * x, z; +select count(*) from btg group by w, x, y, z order by x * x, z; -create index "btg_y_x_w_idx" on btg using btree (y, x, w); +create index btg_y_x_w_idx on btg using btree (y, x, w); select y, x, array_agg(distinct w) from btg where y < 0 group by x, y; create table group_agg_pk as - select - i % 10 as x, - i % 2 as y, - i % 2 as z, - 2 as w, - i % 10 as f - from - generate_series(1, 100) as i; + select i % 10 as x, i % 2 as y, i % 2 as z, 2 as w, i % 10 as f from generate_series(1, 100) as i; analyze group_agg_pk; @@ -2062,22 +1612,16 @@ set enable_nestloop = off; set enable_hashjoin = off; select - AVG(c1.f order by c1.x, c1.y) + avg(c1.f order by c1.x, c1.y) from - group_agg_pk as c1 - inner join - group_agg_pk as c2 - on c1.x = c2.x + group_agg_pk as c1 inner join group_agg_pk as c2 on c1.x = c2.x group by c1.w, c1.z; select - AVG(c1.f order by c1.x, c1.y) + avg(c1.f order by c1.x, c1.y) from - group_agg_pk as c1 - inner join - group_agg_pk as c2 - on c1.x = c2.x + group_agg_pk as c1 inner join group_agg_pk as c2 on c1.x = c2.x group by c1.w, c1.z; @@ -2085,10 +1629,7 @@ select c1.y, c1.x from - group_agg_pk as c1 - inner join - group_agg_pk as c2 - on c1.x = c2.x + group_agg_pk as c1 inner join group_agg_pk as c2 on c1.x = c2.x group by c1.y, c1.x, c2.x; @@ -2097,10 +1638,7 @@ select c1.y, c1.x from - group_agg_pk as c1 - inner join - group_agg_pk as c2 - on c1.x = c2.x + group_agg_pk as c1 inner join group_agg_pk as c2 on c1.x = c2.x group by c1.y, c2.x, c1.x; @@ -2116,7 +1654,7 @@ create table agg_sort_order ( c2 int ); -create unique index "agg_sort_order_c2_idx" on agg_sort_order using btree (c2); +create unique index agg_sort_order_c2_idx on agg_sort_order using btree (c2); insert into agg_sort_order select i, i from generate_series(1, 100) as i; @@ -2134,25 +1672,24 @@ reset enable_seqscan; begin; -create function balkifnull(bigint, bigint) -returns bigint +create function balkifnull(int8, int8) +returns int8 language plpgsql strict -parallel SAFE -as $function$ +parallel safe +as $$ BEGIN IF $1 IS NULL THEN RAISE 'erroneously called with NULL argument'; END IF; RETURN NULL; -END -$function$; +END$$; create aggregate balk ( - int + int4 ) ( sfunc = int4_sum(int8, int4), - stype = bigint, + stype = int8, combinefunc = balkifnull(int8, int8), parallel = safe, initcond = '0' @@ -2177,18 +1714,18 @@ create function rwagg_sfunc(x anyarray, y anyarray) returns anyarray language plpgsql immutable -as $function$ +as $$ BEGIN RETURN array_fill(y[1], ARRAY[4]); END; -$function$; +$$; create function rwagg_finalfunc(x anyarray) returns anyarray language plpgsql immutable strict -as $function$ +as $$ DECLARE res x%TYPE; BEGIN @@ -2196,7 +1733,7 @@ BEGIN res := array_fill(x[1], ARRAY[4]); RETURN res; END; -$function$; +$$; create aggregate rwagg ( anyarray @@ -2211,12 +1748,12 @@ returns real[] language plpgsql immutable strict -as $function$ +as $$ BEGIN x[1] := x[1] + 1; RETURN x; END; -$function$; +$$; select eatarray(rwagg(array[cast(1.0 as real)])), eatarray(rwagg(array[cast(1.0 as real)])); @@ -2237,60 +1774,46 @@ set parallel_leader_participation = off; set enable_indexonlyscan = off; select - variance(cast(unique1 as int)), - SUM(cast(unique1 as bigint)), - regr_count( - cast(unique1 as double precision), - cast(unique1 as double precision) - ) + variance(cast(unique1 as int4)), + sum(cast(unique1 as int8)), + regr_count(cast(unique1 as float8), cast(unique1 as float8)) from ( - select * from tenk1 union all select * from tenk1 - union all - select * from tenk1 + select * from tenk1 union all select * from tenk1 union all select * from tenk1 union all select * from tenk1 ) as u; select - variance(cast(unique1 as int)), - SUM(cast(unique1 as bigint)), - regr_count( - cast(unique1 as double precision), - cast(unique1 as double precision) - ) + variance(cast(unique1 as int4)), + sum(cast(unique1 as int8)), + regr_count(cast(unique1 as float8), cast(unique1 as float8)) from ( - select * from tenk1 union all select * from tenk1 - union all - select * from tenk1 + select * from tenk1 union all select * from tenk1 union all select * from tenk1 union all select * from tenk1 ) as u; select - variance(cast(unique1 as bigint)), - AVG(cast(unique1 as numeric)) + variance(cast(unique1 as int8)), + avg(cast(unique1 as numeric)) from ( - select * from tenk1 union all select * from tenk1 - union all - select * from tenk1 + select * from tenk1 union all select * from tenk1 union all select * from tenk1 union all select * from tenk1 ) as u; select - variance(cast(unique1 as bigint)), - AVG(cast(unique1 as numeric)) + variance(cast(unique1 as int8)), + avg(cast(unique1 as numeric)) from ( - select * from tenk1 union all select * from tenk1 - union all - select * from tenk1 + select * from tenk1 union all select * from tenk1 union all select * from tenk1 union all select * from tenk1 ) @@ -2299,20 +1822,20 @@ from rollback; select - DENSE_RANK(x) within group (order by x) + dense_rank(x) within group (order by x) from (values (1), (1), (2), (2), (3), (3)) as v (x) group by x order by 1; -select MIN(x order by y) from (values (1, null)) as d (x, y); +select min(x order by y) from (values (1, null)) as d (x, y); -select MIN(x order by y) from (values (1, 2)) as d (x, y); +select min(x order by y) from (values (1, 2)) as d (x, y); select v || 'a', case v || 'a' when 'aa' then 1 else 0 end, - COUNT(*) + count(*) from unnest(array['a', 'b']) as u (v) group by v || 'a' @@ -2321,7 +1844,7 @@ order by 1; select v || 'a', case when v || 'a' = 'aa' then 1 else 0 end, - COUNT(*) + count(*) from unnest(array['a', 'b']) as u (v) group by v || 'a' @@ -2333,14 +1856,14 @@ set work_mem = '64kB'; select unique1, - COUNT(*), - SUM(twothousand) + count(*), + sum(twothousand) from tenk1 group by unique1 having - SUM(fivethous) > 4975 -order by SUM(twothousand); + sum(fivethous) > 4975 +order by sum(twothousand); set work_mem = default; @@ -2362,8 +1885,8 @@ set jit_above_cost = 0; select g % 10000 as c1, - SUM(cast(g as numeric)) as c2, - COUNT(*) as c3 + sum(cast(g as numeric)) as c2, + count(*) as c3 from agg_data_20k group by g % 10000; @@ -2372,8 +1895,8 @@ create table agg_group_1 as select g % 10000 as c1, - SUM(cast(g as numeric)) as c2, - COUNT(*) as c3 + sum(cast(g as numeric)) as c2, + count(*) as c3 from agg_data_20k group by g % 10000; @@ -2388,7 +1911,7 @@ as select cast(g / 2 as numeric) as c1, array_agg(cast(g as numeric)) as c2, - COUNT(*) as c3 + count(*) as c3 from agg_data_2k where @@ -2403,8 +1926,8 @@ create table agg_group_3 as select cast(g / 2 as numeric) as c1, - SUM(cast(7 as int)) as c2, - COUNT(*) as c3 + sum(cast(7 as int4)) as c2, + count(*) as c3 from agg_data_2k group by g / 2; @@ -2414,7 +1937,7 @@ as select cast(g / 2 as numeric) as c1, array_agg(cast(g as numeric)) as c2, - COUNT(*) as c3 + count(*) as c3 from agg_data_2k group by g / 2; @@ -2427,8 +1950,8 @@ set jit_above_cost = 0; select g % 10000 as c1, - SUM(cast(g as numeric)) as c2, - COUNT(*) as c3 + sum(cast(g as numeric)) as c2, + count(*) as c3 from agg_data_20k group by g % 10000; @@ -2437,8 +1960,8 @@ create table agg_hash_1 as select g % 10000 as c1, - SUM(cast(g as numeric)) as c2, - COUNT(*) as c3 + sum(cast(g as numeric)) as c2, + count(*) as c3 from agg_data_20k group by g % 10000; @@ -2453,7 +1976,7 @@ as select cast(g / 2 as numeric) as c1, array_agg(cast(g as numeric)) as c2, - COUNT(*) as c3 + count(*) as c3 from agg_data_2k where @@ -2468,8 +1991,8 @@ create table agg_hash_3 as select cast(g / 2 as numeric) as c1, - SUM(cast(7 as int)) as c2, - COUNT(*) as c3 + sum(cast(7 as int4)) as c2, + count(*) as c3 from agg_data_2k group by g / 2; @@ -2479,7 +2002,7 @@ as select cast(g / 2 as numeric) as c1, array_agg(cast(g as numeric)) as c2, - COUNT(*) as c3 + count(*) as c3 from agg_data_2k group by g / 2; @@ -2488,37 +2011,21 @@ set enable_sort = 'true'; set work_mem = default; -select * from agg_hash_1 -except -select * from agg_group_1 +select * from agg_hash_1 except select * from agg_group_1 union all -(select * from agg_group_1 -except -select * from agg_hash_1); +(select * from agg_group_1 except select * from agg_hash_1); -select * from agg_hash_2 -except -select * from agg_group_2 +select * from agg_hash_2 except select * from agg_group_2 union all -(select * from agg_group_2 -except -select * from agg_hash_2); +(select * from agg_group_2 except select * from agg_hash_2); -select * from agg_hash_3 -except -select * from agg_group_3 +select * from agg_hash_3 except select * from agg_group_3 union all -(select * from agg_group_3 -except -select * from agg_hash_3); +(select * from agg_group_3 except select * from agg_hash_3); -select * from agg_hash_4 -except -select * from agg_group_4 +select * from agg_hash_4 except select * from agg_group_4 union all -(select * from agg_group_4 -except -select * from agg_hash_4); +(select * from agg_group_4 except select * from agg_hash_4); drop table agg_group_1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__aggregates_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__aggregates_80.snap index 23242e3fb..924d0b070 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__aggregates_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__aggregates_80.snap @@ -5,17 +5,17 @@ input_file: crates/pgls_pretty_print/tests/data/multi/aggregates.sql set extra_float_digits = 0; create table aggtest ( - a smallint, - b real + a int2, + b float4 ); copy aggtest from 'filename'; analyze aggtest; -select AVG(four) as avg_1 from onek; +select avg(four) as avg_1 from onek; -select AVG(a) as avg_32 from aggtest where a < 100; +select avg(a) as avg_32 from aggtest where a < 100; select any_value(v) from (values (1), (2), (3)) as v (v); @@ -25,25 +25,25 @@ select any_value(v) from (values (null), (1), (2)) as v (v); select any_value(v) from (values (array['hello', 'world'])) as v (v); -select cast(AVG(b) as numeric(10, 3)) as avg_107_943 from aggtest; +select cast(avg(b) as numeric(10, 3)) as avg_107_943 from aggtest; -select AVG(gpa) as avg_3_4 from only student; +select avg(gpa) as avg_3_4 from only student; -select SUM(four) as sum_1500 from onek; +select sum(four) as sum_1500 from onek; -select SUM(a) as sum_198 from aggtest; +select sum(a) as sum_198 from aggtest; -select SUM(b) as avg_431_773 from aggtest; +select sum(b) as avg_431_773 from aggtest; -select SUM(gpa) as avg_6_8 from only student; +select sum(gpa) as avg_6_8 from only student; -select MAX(four) as max_3 from onek; +select max(four) as max_3 from onek; -select MAX(a) as max_100 from aggtest; +select max(a) as max_100 from aggtest; -select MAX(aggtest.b) as max_324_78 from aggtest; +select max(aggtest.b) as max_324_78 from aggtest; -select MAX(student.gpa) as max_3_7 from student; +select max(student.gpa) as max_3_7 from student; select stddev_pop(b) from aggtest; @@ -61,57 +61,29 @@ select var_pop(cast(b as numeric)) from aggtest; select var_samp(cast(b as numeric)) from aggtest; -select - var_pop(cast(1.0 as double precision)), - var_samp(cast(2.0 as double precision)); +select var_pop(cast(1.0 as float8)), var_samp(cast(2.0 as float8)); -select - stddev_pop( - cast(3.0 as double precision) - ), - stddev_samp( - cast(4.0 as double precision) - ); +select stddev_pop(cast(3.0 as float8)), stddev_samp(cast(4.0 as float8)); -select - var_pop(cast('inf' as double precision)), - var_samp( - cast('inf' as double precision) - ); +select var_pop(cast('inf' as float8)), var_samp(cast('inf' as float8)); -select - stddev_pop( - cast('inf' as double precision) - ), - stddev_samp( - cast('inf' as double precision) - ); +select stddev_pop(cast('inf' as float8)), stddev_samp(cast('inf' as float8)); -select - var_pop(cast('nan' as double precision)), - var_samp( - cast('nan' as double precision) - ); +select var_pop(cast('nan' as float8)), var_samp(cast('nan' as float8)); -select - stddev_pop( - cast('nan' as double precision) - ), - stddev_samp( - cast('nan' as double precision) - ); +select stddev_pop(cast('nan' as float8)), stddev_samp(cast('nan' as float8)); -select var_pop(cast(1.0 as real)), var_samp(cast(2.0 as real)); +select var_pop(cast(1.0 as float4)), var_samp(cast(2.0 as float4)); -select stddev_pop(cast(3.0 as real)), stddev_samp(cast(4.0 as real)); +select stddev_pop(cast(3.0 as float4)), stddev_samp(cast(4.0 as float4)); -select var_pop(cast('inf' as real)), var_samp(cast('inf' as real)); +select var_pop(cast('inf' as float4)), var_samp(cast('inf' as float4)); -select stddev_pop(cast('inf' as real)), stddev_samp(cast('inf' as real)); +select stddev_pop(cast('inf' as float4)), stddev_samp(cast('inf' as float4)); -select var_pop(cast('nan' as real)), var_samp(cast('nan' as real)); +select var_pop(cast('nan' as float4)), var_samp(cast('nan' as float4)); -select stddev_pop(cast('nan' as real)), stddev_samp(cast('nan' as real)); +select stddev_pop(cast('nan' as float4)), stddev_samp(cast('nan' as float4)); select var_pop(cast(1.0 as numeric)), var_samp(cast(2.0 as numeric)); @@ -125,143 +97,115 @@ select var_pop(cast('nan' as numeric)), var_samp(cast('nan' as numeric)); select stddev_pop(cast('nan' as numeric)), stddev_samp(cast('nan' as numeric)); -select MAX(row(a, b)) from aggtest; +select max(row(a, b)) from aggtest; -select MAX(row(b, a)) from aggtest; +select max(row(b, a)) from aggtest; -select MIN(row(a, b)) from aggtest; +select min(row(a, b)) from aggtest; -select MIN(row(b, a)) from aggtest; +select min(row(b, a)) from aggtest; -select SUM(cast(null as int)) from generate_series(1, 3); +select sum(cast(null as int4)) from generate_series(1, 3); -select SUM(cast(null as bigint)) from generate_series(1, 3); +select sum(cast(null as int8)) from generate_series(1, 3); -select SUM(cast(null as numeric)) from generate_series(1, 3); +select sum(cast(null as numeric)) from generate_series(1, 3); -select SUM(cast(null as double precision)) from generate_series(1, 3); +select sum(cast(null as float8)) from generate_series(1, 3); -select AVG(cast(null as int)) from generate_series(1, 3); +select avg(cast(null as int4)) from generate_series(1, 3); -select AVG(cast(null as bigint)) from generate_series(1, 3); +select avg(cast(null as int8)) from generate_series(1, 3); -select AVG(cast(null as numeric)) from generate_series(1, 3); +select avg(cast(null as numeric)) from generate_series(1, 3); -select AVG(cast(null as double precision)) from generate_series(1, 3); +select avg(cast(null as float8)) from generate_series(1, 3); -select SUM(cast('NaN' as numeric)) from generate_series(1, 3); +select sum(cast('NaN' as numeric)) from generate_series(1, 3); -select AVG(cast('NaN' as numeric)) from generate_series(1, 3); +select avg(cast('NaN' as numeric)) from generate_series(1, 3); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from (values ('1'), ('infinity')) as v (x); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from (values ('infinity'), ('1')) as v (x); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from - ( - values ('infinity'), ('infinity') - ) - as v (x); + (values ('infinity'), ('infinity')) as v (x); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from - ( - values ('-infinity'), ('infinity') - ) - as v (x); + (values ('-infinity'), ('infinity')) as v (x); select - SUM(cast(x as double precision)), - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + sum(cast(x as float8)), + avg(cast(x as float8)), + var_pop(cast(x as float8)) from - ( - values ('-infinity'), ('-infinity') - ) - as v (x); + (values ('-infinity'), ('-infinity')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from (values ('1'), ('infinity')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from (values ('infinity'), ('1')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from - ( - values ('infinity'), ('infinity') - ) - as v (x); + (values ('infinity'), ('infinity')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from - ( - values ('-infinity'), ('infinity') - ) - as v (x); + (values ('-infinity'), ('infinity')) as v (x); select - SUM(cast(x as numeric)), - AVG(cast(x as numeric)), + sum(cast(x as numeric)), + avg(cast(x as numeric)), var_pop(cast(x as numeric)) from - ( - values ('-infinity'), ('-infinity') - ) - as v (x); + (values ('-infinity'), ('-infinity')) as v (x); select - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + avg(cast(x as float8)), + var_pop(cast(x as float8)) from - ( - values - (100000003), - (100000004), - (100000006), - (100000007) - ) - as v (x); + (values (100000003), (100000004), (100000006), (100000007)) as v (x); select - AVG(cast(x as double precision)), - var_pop(cast(x as double precision)) + avg(cast(x as float8)), + var_pop(cast(x as float8)) from - ( - values (7000000000005), (7000000000007) - ) - as v (x); + (values (7000000000005), (7000000000007)) as v (x); select regr_count(b, a) from aggtest; @@ -282,53 +226,30 @@ select covar_pop(b, a), covar_samp(b, a) from aggtest; select corr(b, a) from aggtest; select - covar_pop( - cast(1 as double precision), - cast(2 as double precision) - ), - covar_samp( - cast(3 as double precision), - cast(4 as double precision) - ); + covar_pop(cast(1 as float8), cast(2 as float8)), + covar_samp(cast(3 as float8), cast(4 as float8)); select - covar_pop( - cast(1 as double precision), - cast('inf' as double precision) - ), - covar_samp( - cast(3 as double precision), - cast('inf' as double precision) - ); + covar_pop(cast(1 as float8), cast('inf' as float8)), + covar_samp(cast(3 as float8), cast('inf' as float8)); select - covar_pop( - cast(1 as double precision), - cast('nan' as double precision) - ), - covar_samp( - cast(3 as double precision), - cast('nan' as double precision) - ); + covar_pop(cast(1 as float8), cast('nan' as float8)), + covar_samp(cast(3 as float8), cast('nan' as float8)); create table regr_test ( - x double precision, - y double precision + x float8, + y float8 ); insert into regr_test -values - (10, 150), - (20, 250), - (30, 350), - (80, 540), - (100, 200); +values (10, 150), (20, 250), (30, 350), (80, 540), (100, 200); select - COUNT(*), - SUM(x), + count(*), + sum(x), regr_sxx(y, x), - SUM(y), + sum(y), regr_syy(y, x), regr_sxy(y, x) from @@ -337,30 +258,29 @@ where x in (10, 20, 30, 80); select - COUNT(*), - SUM(x), + count(*), + sum(x), regr_sxx(y, x), - SUM(y), + sum(y), regr_syy(y, x), regr_sxy(y, x) from regr_test; -select float8_accum(cast('{4,140,2900}' as double precision[]), 100); +select float8_accum(cast('{4,140,2900}' as float8[]), 100); select float8_regr_accum( - cast('{4,140,2900,1290,83075,15050}' - as double precision[]), + cast('{4,140,2900,1290,83075,15050}' as float8[]), 200, 100 ); select - COUNT(*), - SUM(x), + count(*), + sum(x), regr_sxx(y, x), - SUM(y), + sum(y), regr_syy(y, x), regr_sxy(y, x) from @@ -369,10 +289,10 @@ where x in (10, 20, 30); select - COUNT(*), - SUM(x), + count(*), + sum(x), regr_sxx(y, x), - SUM(y), + sum(y), regr_syy(y, x), regr_sxy(y, x) from @@ -381,58 +301,44 @@ where x in (80, 100); select - float8_combine( - cast('{3,60,200}' as double precision[]), - cast('{0,0,0}' as double precision[]) - ); + float8_combine(cast('{3,60,200}' as float8[]), cast('{0,0,0}' as float8[])); select - float8_combine( - cast('{0,0,0}' as double precision[]), - cast('{2,180,200}' - as double precision[]) - ); + float8_combine(cast('{0,0,0}' as float8[]), cast('{2,180,200}' as float8[])); select float8_combine( - cast('{3,60,200}' as double precision[]), - cast('{2,180,200}' - as double precision[]) + cast('{3,60,200}' as float8[]), + cast('{2,180,200}' as float8[]) ); select float8_regr_combine( - cast('{3,60,200,750,20000,2000}' - as double precision[]), - cast('{0,0,0,0,0,0}' - as double precision[]) + cast('{3,60,200,750,20000,2000}' as float8[]), + cast('{0,0,0,0,0,0}' as float8[]) ); select float8_regr_combine( - cast('{0,0,0,0,0,0}' - as double precision[]), - cast('{2,180,200,740,57800,-3400}' - as double precision[]) + cast('{0,0,0,0,0,0}' as float8[]), + cast('{2,180,200,740,57800,-3400}' as float8[]) ); select float8_regr_combine( - cast('{3,60,200,750,20000,2000}' - as double precision[]), - cast('{2,180,200,740,57800,-3400}' - as double precision[]) + cast('{3,60,200,750,20000,2000}' as float8[]), + cast('{2,180,200,740,57800,-3400}' as float8[]) ); drop table regr_test; -select COUNT(four) as cnt_1000 from onek; +select count(four) as cnt_1000 from onek; -select COUNT(distinct four) as cnt_4 from onek; +select count(distinct four) as cnt_4 from onek; -select ten, COUNT(*), SUM(four) from onek group by ten order by ten; +select ten, count(*), sum(four) from onek group by ten order by ten; -select ten, COUNT(four), SUM(distinct four) from onek group by ten order by ten; +select ten, count(four), sum(distinct four) from onek group by ten order by ten; select newavg(four) as avg_1 from onek; @@ -446,60 +352,32 @@ select oldcnt(*) as cnt_1000 from onek; select sum2(q1, q2) from int8_tbl; -select SUM(q1 + q2), SUM(q1) + SUM(q2) from int8_tbl; +select sum(q1 + q2), sum(q1) + sum(q2) from int8_tbl; -select SUM(q1 - q2), SUM(q2 - q1), SUM(q1) - SUM(q2) from int8_tbl; +select sum(q1 - q2), sum(q2 - q1), sum(q1) - sum(q2) from int8_tbl; -select SUM(q1 * 2000), SUM(-q1 * 2000), 2000 * SUM(q1) from int8_tbl; +select sum(q1 * 2000), sum(-q1 * 2000), 2000 * sum(q1) from int8_tbl; select ten, - SUM(distinct four) + sum(distinct four) from onek as a group by ten having - exists - ( - select - 1 - from - onek as b - where - SUM(distinct a.four) = b.four - ); + exists (select 1 from onek as b where sum(distinct a.four) = b.four); select ten, - SUM(distinct four) + sum(distinct four) from onek as a group by ten having - exists - ( - select - 1 - from - onek as b - where - SUM(distinct a.four + b.four) = b.four - ); + exists (select 1 from onek as b where sum(distinct a.four + b.four) = b.four); select - ( - select - MAX( - ( - select - i.unique2 - from - tenk1 as i - where - i.unique1 = o.unique1 - ) - ) - ) + (select max((select i.unique2 from tenk1 as i where i.unique1 = o.unique1))) from tenk1 as o; @@ -510,12 +388,7 @@ select from generate_series(1, 3) as s1, lateral ( - select - s2, - SUM(s1 + s2) as sm - from - generate_series(1, 3) as s2 - group by s2 + select s2, sum(s1 + s2) as sm from generate_series(1, 3) as s2 group by s2 ) as ss order by 1, @@ -528,12 +401,7 @@ select from generate_series(1, 3) as s1, lateral ( - select - s2, - SUM(s1 + s2) as sm - from - generate_series(1, 3) as s2 - group by s2 + select s2, sum(s1 + s2) as sm from generate_series(1, 3) as s2 group by s2 ) as ss order by 1, @@ -541,34 +409,24 @@ order by 1, select array( - select - SUM(x + y) as s - from - generate_series(1, 3) as y - group by y - order by s + select sum(x + y) as s from generate_series(1, 3) as y group by y order by s ) from generate_series(1, 3) as x; select array( - select - SUM(x + y) as s - from - generate_series(1, 3) as y - group by y - order by s + select sum(x + y) as s from generate_series(1, 3) as y group by y order by s ) from generate_series(1, 3) as x; create temporary table bitwise_test ( - i2 smallint, - i4 int, - i8 bigint, + i2 int2, + i4 int4, + i8 int8, i int, - x smallint, + x int2, y bit(4) ); @@ -602,42 +460,32 @@ from bitwise_test; select - booland_statefunc(null, null) is null - as t, - booland_statefunc(true, null) is null - as t, - booland_statefunc(false, null) is null - as t, - booland_statefunc(null, true) is null - as t, - booland_statefunc(null, false) is null - as t, + booland_statefunc(null, null) is null as t, + booland_statefunc(true, null) is null as t, + booland_statefunc(false, null) is null as t, + booland_statefunc(null, true) is null as t, + booland_statefunc(null, false) is null as t, booland_statefunc(true, true) as t, not booland_statefunc(true, false) as t, not booland_statefunc(false, true) as t, not booland_statefunc(false, false) as t; select - boolor_statefunc(null, null) is null - as t, - boolor_statefunc(true, null) is null - as t, - boolor_statefunc(false, null) is null - as t, - boolor_statefunc(null, true) is null - as t, - boolor_statefunc(null, false) is null - as t, + boolor_statefunc(null, null) is null as t, + boolor_statefunc(true, null) is null as t, + boolor_statefunc(false, null) is null as t, + boolor_statefunc(null, true) is null as t, + boolor_statefunc(null, false) is null as t, boolor_statefunc(true, true) as t, boolor_statefunc(true, false) as t, boolor_statefunc(false, true) as t, not boolor_statefunc(false, false) as t; create temporary table bool_test ( - b1 boolean, - b2 boolean, - b3 boolean, - b4 boolean + b1 bool, + b2 bool, + b3 bool, + b4 bool ); select bool_and(b1) as n, bool_or(b3) as n from bool_test; @@ -672,91 +520,75 @@ select from bool_test; -select MIN(unique1) from tenk1; +select min(unique1) from tenk1; -select MIN(unique1) from tenk1; +select min(unique1) from tenk1; -select MAX(unique1) from tenk1; +select max(unique1) from tenk1; -select MAX(unique1) from tenk1; +select max(unique1) from tenk1; -select MAX(unique1) from tenk1 where unique1 < 42; +select max(unique1) from tenk1 where unique1 < 42; -select MAX(unique1) from tenk1 where unique1 < 42; +select max(unique1) from tenk1 where unique1 < 42; -select MAX(unique1) from tenk1 where unique1 > 42; +select max(unique1) from tenk1 where unique1 > 42; -select MAX(unique1) from tenk1 where unique1 > 42; +select max(unique1) from tenk1 where unique1 > 42; begin; set local max_parallel_workers_per_gather = 0; -select MAX(unique1) from tenk1 where unique1 > 42000; +select max(unique1) from tenk1 where unique1 > 42000; -select MAX(unique1) from tenk1 where unique1 > 42000; +select max(unique1) from tenk1 where unique1 > 42000; rollback; -select MAX(tenthous) from tenk1 where thousand = 33; +select max(tenthous) from tenk1 where thousand = 33; -select MAX(tenthous) from tenk1 where thousand = 33; +select max(tenthous) from tenk1 where thousand = 33; -select MIN(tenthous) from tenk1 where thousand = 33; +select min(tenthous) from tenk1 where thousand = 33; -select MIN(tenthous) from tenk1 where thousand = 33; +select min(tenthous) from tenk1 where thousand = 33; select f1, - ( - select - MIN(unique1) - from - tenk1 - where - unique1 > f1 - ) - as gt + (select min(unique1) from tenk1 where unique1 > f1) as gt from int4_tbl; select f1, - ( - select - MIN(unique1) - from - tenk1 - where - unique1 > f1 - ) - as gt + (select min(unique1) from tenk1 where unique1 > f1) as gt from int4_tbl; -select distinct MAX(unique2) from tenk1; +select distinct max(unique2) from tenk1; -select distinct MAX(unique2) from tenk1; +select distinct max(unique2) from tenk1; -select MAX(unique2) from tenk1 order by 1; +select max(unique2) from tenk1 order by 1; -select MAX(unique2) from tenk1 order by 1; +select max(unique2) from tenk1 order by 1; -select MAX(unique2) from tenk1 order by MAX(unique2); +select max(unique2) from tenk1 order by max(unique2); -select MAX(unique2) from tenk1 order by MAX(unique2); +select max(unique2) from tenk1 order by max(unique2); -select MAX(unique2) from tenk1 order by MAX(unique2) + 1; +select max(unique2) from tenk1 order by max(unique2) + 1; -select MAX(unique2) from tenk1 order by MAX(unique2) + 1; +select max(unique2) from tenk1 order by max(unique2) + 1; -select MAX(unique2), generate_series(1, 3) as g from tenk1 order by g desc; +select max(unique2), generate_series(1, 3) as g from tenk1 order by g desc; -select MAX(unique2), generate_series(1, 3) as g from tenk1 order by g desc; +select max(unique2), generate_series(1, 3) as g from tenk1 order by g desc; -select MAX(100) from tenk1; +select max(100) from tenk1; -select MAX(100) from tenk1; +select max(100) from tenk1; create table minmaxtest (f1 int); @@ -769,20 +601,13 @@ inherits (minmaxtest); create table minmaxtest3 () inherits (minmaxtest); -create index "minmaxtesti" on minmaxtest using btree (f1); +create index minmaxtesti on minmaxtest using btree (f1); -create index "minmaxtest1i" on minmaxtest1 using btree (f1); +create index minmaxtest1i on minmaxtest1 using btree (f1); -create index "minmaxtest2i" on minmaxtest2 using btree (f1 desc); +create index minmaxtest2i on minmaxtest2 using btree (f1 desc); -create index "minmaxtest3i" -on minmaxtest3 -using btree -( - f1 -) -where - f1 is not null; +create index minmaxtest3i on minmaxtest3 using btree (f1) where f1 is not null; insert into minmaxtest values (11), (12); @@ -792,13 +617,13 @@ insert into minmaxtest2 values (15), (16); insert into minmaxtest3 values (17), (18); -select MIN(f1), MAX(f1) from minmaxtest; +select min(f1), max(f1) from minmaxtest; -select MIN(f1), MAX(f1) from minmaxtest; +select min(f1), max(f1) from minmaxtest; -select distinct MIN(f1), MAX(f1) from minmaxtest; +select distinct min(f1), max(f1) from minmaxtest; -select distinct MIN(f1), MAX(f1) from minmaxtest; +select distinct min(f1), max(f1) from minmaxtest; drop table minmaxtest cascade; @@ -808,43 +633,27 @@ set local enable_sort = off; select f1, - ( - select distinct - MIN(t1.f1) - from - int4_tbl as t1 - where - t1.f1 = t0.f1 - ) + (select distinct min(t1.f1) from int4_tbl as t1 where t1.f1 = t0.f1) from int4_tbl as t0; select f1, - ( - select distinct - MIN(t1.f1) - from - int4_tbl as t1 - where - t1.f1 = t0.f1 - ) + (select distinct min(t1.f1) from int4_tbl as t1 where t1.f1 = t0.f1) from int4_tbl as t0; rollback; -select MAX(MIN(unique1)) from tenk1; +select max(min(unique1)) from tenk1; -select (select MAX(MIN(unique1)) from int8_tbl) from tenk1; +select (select max(min(unique1)) from int8_tbl) from tenk1; select - AVG( + avg( ( select - AVG( - a1.col1 order by (select AVG(a2.col2) from tenk1 as a3) - ) + avg(a1.col1 order by (select avg(a2.col2) from tenk1 as a3)) from tenk1 as a1 (col1) ) @@ -881,10 +690,7 @@ select a, c from t1 group by a, c, d; select * from - t1 - inner join - t2 - on t1.a = t2.x and t1.b = t2.y + t1 inner join t2 on t1.a = t2.x and t1.b = t2.y group by t1.a, t1.b, t1.c, @@ -898,10 +704,7 @@ select t2.x, t2.z from - t1 - inner join - t2 - on t1.a = t2.x and t1.b = t2.y + t1 inner join t2 on t1.a = t2.x and t1.b = t2.y group by t1.a, t1.b, t1.c, @@ -925,7 +728,7 @@ create temporary table p_t1 ( d int, primary key (a, b) ) -partition by LIST(a); +partition by list(a); create temporary table p_t1_1 partition of p_t1 for values in (1); @@ -933,7 +736,7 @@ create temporary table p_t1_2 partition of p_t1 for values in (2); select * from p_t1 group by a, b, c, d; -create unique index "t2_z_uidx" on t2 using btree (z); +create unique index t2_z_uidx on t2 using btree (z); select y, z from t2 group by y, z; @@ -948,14 +751,7 @@ select x, y, z from t2 group by z, x, y; drop index t2_z_uidx; -create index "t2_z_uidx" -on t2 -using btree -( - z -) -where - z > 0; +create index t2_z_uidx on t2 using btree (z) where z > 0; select y, z from t2 group by y, z; @@ -964,7 +760,7 @@ drop index t2_z_uidx; alter table t2 alter column z drop not null; -create unique index "t2_z_uidx" on t2 using btree (z) nulls not distinct; +create unique index t2_z_uidx on t2 using btree (z) nulls not distinct; select y, z from t2 group by y, z; @@ -986,88 +782,78 @@ create temporary table t2 ( f2 oid ); -select f1 from t1 left outer join t2 using ("f1") group by f1; +select f1 from t1 left outer join t2 using (f1) group by f1; -select f1 from t1 left outer join t2 using ("f1") group by t1.f1; +select f1 from t1 left outer join t2 using (f1) group by t1.f1; -select t1.f1 from t1 left outer join t2 using ("f1") group by t1.f1; +select t1.f1 from t1 left outer join t2 using (f1) group by t1.f1; -select t1.f1 from t1 left outer join t2 using ("f1") group by f1; +select t1.f1 from t1 left outer join t2 using (f1) group by f1; select f1, - COUNT(*) + count(*) from - t1 as x (x0, x1) - left outer join - t1 left outer join t2 using ("f1") - on x0 = 0 + t1 as x (x0, x1) left outer join t1 left outer join t2 using (f1) on x0 = 0 group by f1; select f2, - COUNT(*) + count(*) from - t1 as x (x0, x1) - left outer join - t1 left outer join t2 using ("f2") - on x0 = 0 + t1 as x (x0, x1) left outer join t1 left outer join t2 using (f2) on x0 = 0 group by f2; drop table t1, t2; select - SUM(two order by two), - MAX(four order by four), - MIN(four order by four) + sum(two order by two), + max(four order by four), + min(four order by four) from tenk1; select - SUM(two order by two), - MAX(four order by four), - MIN(four order by four), - MAX(two order by two) + sum(two order by two), + max(four order by four), + min(four order by four), + max(two order by two) from tenk1; select - MAX(four order by four), - SUM(two order by two), - MIN(four order by four), - MAX(two order by two) + max(four order by four), + sum(two order by two), + min(four order by four), + max(two order by two) from tenk1; select - MAX(four order by four), - SUM(two order by two), - MIN(four order by four), - MAX(two order by two), - SUM(ten order by ten), - MIN(ten order by ten), - MAX(ten order by ten) + max(four order by four), + sum(two order by two), + min(four order by four), + max(two order by two), + sum(ten order by ten), + min(ten order by ten), + max(ten order by ten) from tenk1; select - SUM(unique1 order by ten, two), - SUM(unique1 order by four), - SUM(unique1 order by two, four) + sum(unique1 order by ten, two), + sum(unique1 order by four), + sum(unique1 order by two, four) from tenk1 group by ten; select - SUM(unique1 order by two), - SUM(unique1 order by four), - SUM(unique1 order by four, two), - SUM(unique1 order by two, random()), - SUM( - unique1 order by two, - random(), - random() + 1 - ) + sum(unique1 order by two), + sum(unique1 order by four), + sum(unique1 order by four, two), + sum(unique1 order by two, random()), + sum(unique1 order by two, random(), random() + 1) from tenk1 group by ten; @@ -1075,116 +861,71 @@ group by ten; select array_agg(distinct val) from - ( - select - null as val - from - generate_series(1, 2) - ); + (select null as val from generate_series(1, 2)); set enable_presorted_aggregate = off; -select SUM(two order by two) from tenk1; +select sum(two order by two) from tenk1; reset enable_presorted_aggregate; -select SUM(two order by two) filter (where two > 1) from tenk1; +select sum(two order by two) filter (where two > 1) from tenk1; select - string_agg( - distinct f1, - ',' - ) - filter (where - length(f1) > 1) + string_agg(distinct f1, ',') filter (where length(f1) > 1) from varchar_tbl; select - string_agg( - distinct cast(f1 as varchar(2)), - ',' - ) - filter (where - length(f1) > 1) + string_agg(distinct cast(f1 as varchar(2)), ',') filter (where length(f1) > 1) from varchar_tbl; select array_agg(a order by b) from - ( - values (1, 4), (2, 3), (3, 1), (4, 2) - ) - as v (a, b); + (values (1, 4), (2, 3), (3, 1), (4, 2)) as v (a, b); select array_agg(a order by a) from - ( - values (1, 4), (2, 3), (3, 1), (4, 2) - ) - as v (a, b); + (values (1, 4), (2, 3), (3, 1), (4, 2)) as v (a, b); select array_agg(a order by a desc) from - ( - values (1, 4), (2, 3), (3, 1), (4, 2) - ) - as v (a, b); + (values (1, 4), (2, 3), (3, 1), (4, 2)) as v (a, b); select array_agg(b order by a desc) from - ( - values (1, 4), (2, 3), (3, 1), (4, 2) - ) - as v (a, b); + (values (1, 4), (2, 3), (3, 1), (4, 2)) as v (a, b); select array_agg(distinct a) from - ( - values (1), (2), (1), (3), (null), (2) - ) - as v (a); + (values (1), (2), (1), (3), (null), (2)) as v (a); select array_agg(distinct a order by a) from - ( - values (1), (2), (1), (3), (null), (2) - ) - as v (a); + (values (1), (2), (1), (3), (null), (2)) as v (a); select array_agg(distinct a order by a desc) from - ( - values (1), (2), (1), (3), (null), (2) - ) - as v (a); + (values (1), (2), (1), (3), (null), (2)) as v (a); select - array_agg( - distinct a order by a desc nulls last - ) + array_agg(distinct a order by a desc nulls last) from - ( - values (1), (2), (1), (3), (null), (2) - ) - as v (a); + (values (1), (2), (1), (3), (null), (2)) as v (a); select aggfstr(a, b, c) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c); @@ -1192,11 +933,7 @@ select aggfns(a, b, c) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c); @@ -1204,11 +941,7 @@ select aggfstr(distinct a, b, c) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 3) as i; @@ -1217,11 +950,7 @@ select aggfns(distinct a, b, c) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 3) as i; @@ -1230,11 +959,7 @@ select aggfstr(distinct a, b, c order by b) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 3) as i; @@ -1243,46 +968,25 @@ select aggfns(distinct a, b, c order by b) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 3) as i; select - aggfns( - distinct a, - a, - c order by c using ~<~, - a - ) + aggfns(distinct a, a, c order by c using ~<~, a) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 2) as i; select - aggfns( - distinct a, - a, - c order by c using ~<~ - ) + aggfns(distinct a, a, c order by c using ~<~) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 2) as i; @@ -1291,46 +995,23 @@ select aggfns(distinct a, a, c order by a) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 2) as i; select - aggfns( - distinct a, - b, - c order by a, - c using ~<~, - b - ) + aggfns(distinct a, b, c order by a, c using ~<~, b) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 2) as i; select string_agg(distinct 'a', ','), - SUM( - ( - select - SUM(1) - from - (values (1)) as b (id) - where - a.id = b.id - ) - ) + sum((select sum(1) from (values (1)) as b (id) where a.id = b.id)) from unnest(array[1]) as a (id); @@ -1339,11 +1020,7 @@ as select aggfns(a, b, c) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c); @@ -1356,11 +1033,7 @@ as select aggfns(distinct a, b, c) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 3) as i; @@ -1374,11 +1047,7 @@ as select aggfns(distinct a, b, c order by b) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 3) as i; @@ -1392,11 +1061,7 @@ as select aggfns(a, b, c order by b + 1) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c); @@ -1409,11 +1074,7 @@ as select aggfns(a, a, c order by b) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c); @@ -1426,11 +1087,7 @@ as select aggfns(a, b, c order by c using ~<~) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c); @@ -1440,20 +1097,10 @@ select pg_get_viewdef(cast('agg_view1' as regclass)); create or replace view agg_view1 as select - aggfns( - distinct a, - b, - c order by a, - c using ~<~, - b - ) + aggfns(distinct a, b, c order by a, c using ~<~, b) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 2) as i; @@ -1471,25 +1118,13 @@ from generate_series(1, 2) as i; select - aggfns( - distinct a, - b, - c order by a, - b + 1 - ) + aggfns(distinct a, b, c order by a, b + 1) from (values (1, 1, 'foo')) as v (a, b, c), generate_series(1, 2) as i; select - aggfns( - distinct a, - b, - c order by a, - b, - i, - c - ) + aggfns(distinct a, b, c order by a, b, i, c) from (values (1, 1, 'foo')) as v (a, b, c), generate_series(1, 2) as i; @@ -1505,26 +1140,12 @@ select string_agg(a, ',') from (values ('aaaa'), ('bbbb'), ('cccc')) as g (a); select string_agg(a, ',') from - ( - values - ('aaaa'), - (null), - ('bbbb'), - ('cccc') - ) - as g (a); + (values ('aaaa'), (null), ('bbbb'), ('cccc')) as g (a); select string_agg(a, 'AB') from - ( - values - (null), - (null), - ('bbbb'), - ('cccc') - ) - as g (a); + (values (null), (null), ('bbbb'), ('cccc')) as g (a); select string_agg(a, ',') from (values (null), (null)) as g (a); @@ -1535,10 +1156,7 @@ select string_agg(distinct cast(f1 as text), ',' order by f1) from varchar_tbl; select string_agg(distinct f1, ',' order by cast(f1 as text)) from varchar_tbl; select - string_agg( - distinct cast(f1 as text), - ',' order by cast(f1 as text) - ) + string_agg(distinct cast(f1 as text), ',' order by cast(f1 as text)) from varchar_tbl; @@ -1558,17 +1176,17 @@ select string_agg(v, null) from bytea_test_table; select string_agg(v, decode('ee', 'hex')) from bytea_test_table; -select MIN(v) from bytea_test_table; +select min(v) from bytea_test_table; -select MAX(v) from bytea_test_table; +select max(v) from bytea_test_table; insert into bytea_test_table values (decode('ffff', 'hex')); insert into bytea_test_table values (decode('aaaa', 'hex')); -select MIN(v) from bytea_test_table; +select min(v) from bytea_test_table; -select MAX(v) from bytea_test_table; +select max(v) from bytea_test_table; drop table bytea_test_table; @@ -1600,32 +1218,24 @@ set max_parallel_workers_per_gather = 2; create view v_pagg_test as select y, - MIN(t) as tmin, - MAX(t) as tmax, - COUNT(distinct t) as tndistinct, - MIN(b) as bmin, - MAX(b) as bmax, - COUNT(distinct b) as bndistinct, - MIN(a) as amin, - MAX(a) as amax, - COUNT(distinct a) as andistinct, - MIN(aa) as aamin, - MAX(aa) as aamax, - COUNT(distinct aa) as aandistinct + min(t) as tmin, + max(t) as tmax, + count(distinct t) as tndistinct, + min(b) as bmin, + max(b) as bmax, + count(distinct b) as bndistinct, + min(a) as amin, + max(a) as amax, + count(distinct a) as andistinct, + min(aa) as aamin, + max(aa) as aamax, + count(distinct aa) as aandistinct from ( select y, - cast(unnest(regexp_split_to_array(a1.t, ',')) - as int) - as t, - unnest( - regexp_split_to_array( - cast(a1.b as text), - ',' - ) - ) - as b, + cast(unnest(regexp_split_to_array(a1.t, ',')) as int) as t, + unnest(regexp_split_to_array(cast(a1.b as text), ',')) as b, unnest(a1.a) as a, unnest(a1.aa) as aa from @@ -1633,11 +1243,7 @@ from select y, string_agg(cast(x as text), ',') as t, - string_agg( - cast(cast(x as text) as bytea), - ',' - ) - as b, + string_agg(cast(cast(x as text) as bytea), ',') as b, array_agg(x) as a, array_agg(array[x]) as aa from @@ -1679,67 +1285,42 @@ drop view v_pagg_test; drop table pagg_test; -select MIN(unique1) filter (where unique1 > 100) from tenk1; +select min(unique1) filter (where unique1 > 100) from tenk1; -select SUM(1 / ten) filter (where ten > 0) from tenk1; +select sum(1 / ten) filter (where ten > 0) from tenk1; select ten, - SUM( - distinct four - ) - filter (where - cast(four as text) ~ '123') + sum(distinct four) filter (where cast(four as text) ~ '123') from onek as a group by ten; select ten, - SUM( - distinct four - ) - filter (where - four > 10) + sum(distinct four) filter (where four > 10) from onek as a group by ten having - exists - ( - select - 1 - from - onek as b - where - SUM(distinct a.four) = b.four - ); + exists (select 1 from onek as b where sum(distinct a.four) = b.four); select - MAX( - foo collate "C" - ) - filter (where - bar collate "POSIX" > '0') + max(foo collate "C") filter (where bar collate "POSIX" > '0') from (values ('a', 'b')) as v (foo, bar); select any_value(v) filter (where v > 2) from (values (1), (2), (3)) as v (v); select - ( - select - COUNT(*) - from - (values (1)) as t0 (inner_c) - ) + (select count(*) from (values (1)) as t0 (inner_c)) from (values (2), (3)) as t1 (outer_c); select ( select - COUNT(*) filter (where outer_c <> 0) + count(*) filter (where outer_c <> 0) from (values (1)) as t0 (inner_c) ) @@ -1749,11 +1330,7 @@ from select ( select - COUNT( - inner_c - ) - filter (where - outer_c <> 0) + count(inner_c) filter (where outer_c <> 0) from (values (1)) as t0 (inner_c) ) @@ -1763,15 +1340,8 @@ from select ( select - MAX( - ( - select - i.unique2 - from - tenk1 as i - where - i.unique1 = o.unique1 - ) + max( + (select i.unique2 from tenk1 as i where i.unique1 = o.unique1) ) filter (where o.unique1 < 10) @@ -1780,86 +1350,49 @@ from tenk1 as o; select - SUM( + sum( unique1 ) filter (where - unique1 in - ( - select - unique1 - from - onek - where - unique1 < 100 - )) + unique1 in (select unique1 from onek where unique1 < 100)) from tenk1; select - aggfns( - distinct a, - b, - c order by a, - c using ~<~, - b - ) - filter (where - a > 1) + aggfns(distinct a, b, c order by a, c using ~<~, b) filter (where a > 1) from ( - values - (1, 3, 'foo'), - (0, null, null), - (2, 2, 'bar'), - (3, 1, 'baz') + values (1, 3, 'foo'), (0, null, null), (2, 2, 'bar'), (3, 1, 'baz') ) as v (a, b, c), generate_series(1, 2) as i; -select MAX(0) filter (where b1) from bool_test; +select max(0) filter (where b1) from bool_test; -select (select MAX(0) filter (where b1)) from bool_test; +select (select max(0) filter (where b1)) from bool_test; -select MAX(unique1) filter (where SUM(ten) > 0) from tenk1; +select max(unique1) filter (where sum(ten) > 0) from tenk1; select - ( - select - MAX(unique1) filter (where SUM(ten) > 0) - from - int8_tbl - ) + (select max(unique1) filter (where sum(ten) > 0) from int8_tbl) from tenk1; -select MAX(unique1) filter (where bool_or(ten > 0)) from tenk1; +select max(unique1) filter (where bool_or(ten > 0)) from tenk1; select - ( - select - MAX( - unique1 - ) - filter (where - bool_or(ten > 0)) - from - int8_tbl - ) + (select max(unique1) filter (where bool_or(ten > 0)) from int8_tbl) from tenk1; select p, - percentile_cont( - p - ) - within group (order by cast(x as double precision)) + percentile_cont(p) within group (order by cast(x as float8)) from generate_series(1, 5) as x, ( values - (cast(0 as double precision)), + (cast(0 as float8)), (0.1), (0.25), (0.4), @@ -1875,13 +1408,12 @@ order by p; select p, - SUM() - within group (order by cast(x as double precision)) + sum() within group (order by cast(x as float8)) from generate_series(1, 5) as x, ( values - (cast(0 as double precision)), + (cast(0 as float8)), (0.1), (0.25), (0.4), @@ -1902,7 +1434,7 @@ from generate_series(1, 5) as x, ( values - (cast(0 as double precision)), + (cast(0 as float8)), (0.1), (0.25), (0.4), @@ -1918,54 +1450,31 @@ order by p; select percentile_cont(0.5) within group (order by b) from aggtest; -select percentile_cont(0.5) within group (order by b), SUM(b) from aggtest; +select percentile_cont(0.5) within group (order by b), sum(b) from aggtest; select percentile_cont(0.5) within group (order by thousand) from tenk1; select percentile_disc(0.5) within group (order by thousand) from tenk1; select - RANK(3) within group (order by x) + rank(3) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3), (4) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4)) as v (x); select - CUME_DIST(3) within group (order by x) + cume_dist(3) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3), (4) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4)) as v (x); select - PERCENT_RANK( - 3 - ) - within group (order by x) + percent_rank(3) within group (order by x) from - ( - values - (1), - (1), - (2), - (2), - (3), - (3), - (4), - (5) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4), (5)) as v (x); select - DENSE_RANK(3) within group (order by x) + dense_rank(3) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3), (4) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4)) as v (x); select percentile_disc( @@ -1976,17 +1485,13 @@ from tenk1; select - percentile_cont( - array[0, 0.25, 0.5, 0.75, 1] - ) - within group (order by thousand) + percentile_cont(array[0, 0.25, 0.5, 0.75, 1]) within group (order by thousand) from tenk1; select percentile_disc( - array[array[null, 1, 0.5], - array[0.75, 0.25, null]] + array[array[null, 1, 0.5], array[0.75, 0.25, null]] ) within group (order by thousand) from @@ -1994,17 +1499,7 @@ from select percentile_cont( - array[0, - 1, - 0.25, - 0.75, - 0.5, - 1, - 0.3, - 0.32, - 0.35, - 0.38, - 0.4] + array[0, 1, 0.25, 0.75, 0.5, 1, 0.3, 0.32, 0.35, 0.38, 0.4] ) within group (order by x) from @@ -2013,10 +1508,7 @@ from select ten, mode() within group (order by string4) from tenk1 group by ten; select - percentile_disc( - array[0.25, 0.5, 0.75] - ) - within group (order by x) + percentile_disc(array[0.25, 0.5, 0.75]) within group (order by x) from unnest( cast('{fred,jim,fred,jack,jill,fred,jill,jim,jim,sheila,jim,sheila}' @@ -2025,34 +1517,23 @@ from as u (x); select - pg_collation_for( - percentile_disc( - 1 - ) - within group (order by x collate "POSIX") - ) + pg_collation_for(percentile_disc(1) within group (order by x collate "POSIX")) from (values ('fred'), ('jim')) as v (x); select test_rank(3) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3), (4) - ) - as v (x); + (values (1), (1), (2), (2), (3), (3), (4)) as v (x); select test_percentile_disc(0.5) within group (order by thousand) from tenk1; -select RANK(x) within group (order by x) from generate_series(1, 5) as x; +select rank(x) within group (order by x) from generate_series(1, 5) as x; select array( select - percentile_disc( - a - ) - within group (order by x) + percentile_disc(a) within group (order by x) from (values (0.3), (0.7)) as v (a) group by a @@ -2060,19 +1541,19 @@ select from generate_series(1, 5) as g (x); -select RANK(SUM(x)) within group (order by x) from generate_series(1, 5) as x; +select rank(sum(x)) within group (order by x) from generate_series(1, 5) as x; select - RANK(3) within group (order by x) + rank(3) within group (order by x) from (values ('fred'), ('jim')) as v (x); -select RANK(3) within group (order by stringu1, stringu2) from tenk1; +select rank(3) within group (order by stringu1, stringu2) from tenk1; -select RANK('fred') within group (order by x) from generate_series(1, 5) as x; +select rank('fred') within group (order by x) from generate_series(1, 5) as x; select - RANK( + rank( cast('adam' as text) collate "C" ) within group (order by x collate "POSIX") @@ -2080,31 +1561,21 @@ from (values ('fred'), ('jim')) as v (x); select - RANK( - cast('adam' as varchar) - ) - within group (order by x) + rank(cast('adam' as varchar)) within group (order by x) from (values ('fred'), ('jim')) as v (x); -select RANK('3') within group (order by x) from generate_series(1, 5) as x; +select rank('3') within group (order by x) from generate_series(1, 5) as x; select - PERCENT_RANK( - 0 - ) - within group (order by x) + percent_rank(0) within group (order by x) from generate_series(1, 0) as x; create view aggordview1 as select ten, - percentile_disc( - 0.5 - ) - within group (order by thousand) - as p50, + percentile_disc(0.5) within group (order by thousand) as p50, percentile_disc( 0.5 ) @@ -2112,16 +1583,7 @@ as select filter (where hundred = 1) as px, - RANK( - 5, - 'AZZZZ', - 50 - ) - within group ( - order by hundred, - string4 desc, - hundred - ) + rank(5, 'AZZZZ', 50) within group (order by hundred, string4 desc, hundred) from tenk1 group by ten @@ -2152,7 +1614,7 @@ create type avg_state as (total bigint, count bigint); create or replace function avg_transfn(state avg_state, n int) returns avg_state language plpgsql -as $function$ +as $$ declare new_state avg_state; begin raise notice 'avg_transfn called with %', n; @@ -2171,12 +1633,12 @@ begin return null; end -$function$; +$$; create function avg_finalfn(state avg_state) -returns int +returns int4 language plpgsql -as $function$ +as $$ begin if state is null then return NULL; @@ -2184,12 +1646,12 @@ begin return state.total / state.count; end if; end -$function$; +$$; create function sum_finalfn(state avg_state) -returns int +returns int4 language plpgsql -as $function$ +as $$ begin if state is null then return NULL; @@ -2197,10 +1659,10 @@ begin return state.total; end if; end -$function$; +$$; create aggregate my_avg ( - int + int4 ) ( stype = avg_state, sfunc = avg_transfn, @@ -2208,7 +1670,7 @@ create aggregate my_avg ( ); create aggregate my_sum ( - int + int4 ) ( stype = avg_state, sfunc = avg_transfn, @@ -2236,51 +1698,25 @@ from select my_avg(one), my_sum(two) from (values (1, 2), (3, 4)) as t (one, two); select - percentile_cont( - 0.5 - ) - within group (order by a), - percentile_disc( - 0.5 - ) - within group (order by a) + percentile_cont(0.5) within group (order by a), + percentile_disc(0.5) within group (order by a) from - ( - values - (cast(1 as double precision)), - (3), - (5), - (7) - ) - as t (a); + (values (cast(1 as float8)), (3), (5), (7)) as t (a); select - percentile_cont( - 0.25 - ) - within group (order by a), - percentile_disc( - 0.5 - ) - within group (order by a) + percentile_cont(0.25) within group (order by a), + percentile_disc(0.5) within group (order by a) from - ( - values - (cast(1 as double precision)), - (3), - (5), - (7) - ) - as t (a); + (values (cast(1 as float8)), (3), (5), (7)) as t (a); select - RANK(4) within group (order by a), - DENSE_RANK(4) within group (order by a) + rank(4) within group (order by a), + dense_rank(4) within group (order by a) from (values (1), (3), (5), (7)) as t (a); create aggregate my_sum_init ( - int + int4 ) ( stype = avg_state, sfunc = avg_transfn, @@ -2289,7 +1725,7 @@ create aggregate my_sum_init ( ); create aggregate my_avg_init ( - int + int4 ) ( stype = avg_state, sfunc = avg_transfn, @@ -2298,7 +1734,7 @@ create aggregate my_avg_init ( ); create aggregate my_avg_init2 ( - int + int4 ) ( stype = avg_state, sfunc = avg_transfn, @@ -2314,10 +1750,10 @@ rollback; begin; -create or replace function sum_transfn(state int, n int) -returns int +create or replace function sum_transfn(state int4, n int4) +returns int4 language plpgsql -as $function$ +as $$ declare new_state int4; begin raise notice 'sum_transfn called with %', n; @@ -2334,12 +1770,12 @@ begin return null; end -$function$; +$$; -create function halfsum_finalfn(state int) -returns int +create function halfsum_finalfn(state int4) +returns int4 language plpgsql -as $function$ +as $$ begin if state is null then return NULL; @@ -2347,14 +1783,14 @@ begin return state / 2; end if; end -$function$; +$$; -create aggregate my_sum (int) (stype = int, sfunc = sum_transfn); +create aggregate my_sum (int4) (stype = int4, sfunc = sum_transfn); create aggregate my_half_sum ( - int + int4 ) ( - stype = int, + stype = int4, sfunc = sum_transfn, finalfunc = halfsum_finalfn ); @@ -2369,24 +1805,23 @@ rollback; begin; -create function balkifnull(bigint, int) -returns bigint +create function balkifnull(int8, int4) +returns int8 language plpgsql strict -as $function$ +as $$ BEGIN IF $1 IS NULL THEN RAISE 'erroneously called with NULL argument'; END IF; RETURN NULL; -END -$function$; +END$$; create aggregate balk ( - int + int4 ) ( sfunc = balkifnull(int8, int4), - stype = bigint, + stype = int8, parallel = safe, initcond = '0' ); @@ -2405,7 +1840,7 @@ as from generate_series(1, 100) as i; -create index "btg_x_y_idx" on btg using btree (x, y); +create index btg_x_y_idx on btg using btree (x, y); analyze btg; @@ -2413,17 +1848,14 @@ set enable_hashagg = off; set enable_seqscan = off; -select COUNT(*) from btg group by y, x; +select count(*) from btg group by y, x; -select COUNT(*) from btg group by z, y, w, x; +select count(*) from btg group by z, y, w, x; select - COUNT(*) + count(*) from - ( - select * from btg order by x, y, w, z - ) - as q1 + (select * from btg order by x, y, w, z) as q1 group by w, x, z, @@ -2434,14 +1866,9 @@ set enable_hashjoin = off; set enable_nestloop = off; select - COUNT(*) + count(*) from - btg as t1 - inner join - btg as t2 - on t1.w = t2.w and - t1.x = t2.x and - t1.z = t2.z + btg as t1 inner join btg as t2 on t1.w = t2.w and t1.x = t2.x and t1.z = t2.z group by t1.w, t1.z, t1.x; @@ -2450,11 +1877,11 @@ reset enable_nestloop; reset enable_hashjoin; -select COUNT(*) from btg group by w, x, z, y order by y, x, z, w; +select count(*) from btg group by w, x, z, y order by y, x, z, w; -select COUNT(*) from btg group by w, x, y, z order by x * x, z; +select count(*) from btg group by w, x, y, z order by x * x, z; -create index "btg_y_x_w_idx" on btg using btree (y, x, w); +create index btg_y_x_w_idx on btg using btree (y, x, w); select y, x, array_agg(distinct w) from btg where y < 0 group by x, y; @@ -2476,22 +1903,16 @@ set enable_nestloop = off; set enable_hashjoin = off; select - AVG(c1.f order by c1.x, c1.y) + avg(c1.f order by c1.x, c1.y) from - group_agg_pk as c1 - inner join - group_agg_pk as c2 - on c1.x = c2.x + group_agg_pk as c1 inner join group_agg_pk as c2 on c1.x = c2.x group by c1.w, c1.z; select - AVG(c1.f order by c1.x, c1.y) + avg(c1.f order by c1.x, c1.y) from - group_agg_pk as c1 - inner join - group_agg_pk as c2 - on c1.x = c2.x + group_agg_pk as c1 inner join group_agg_pk as c2 on c1.x = c2.x group by c1.w, c1.z; @@ -2499,10 +1920,7 @@ select c1.y, c1.x from - group_agg_pk as c1 - inner join - group_agg_pk as c2 - on c1.x = c2.x + group_agg_pk as c1 inner join group_agg_pk as c2 on c1.x = c2.x group by c1.y, c1.x, c2.x; @@ -2511,10 +1929,7 @@ select c1.y, c1.x from - group_agg_pk as c1 - inner join - group_agg_pk as c2 - on c1.x = c2.x + group_agg_pk as c1 inner join group_agg_pk as c2 on c1.x = c2.x group by c1.y, c2.x, c1.x; @@ -2530,7 +1945,7 @@ create table agg_sort_order ( c2 int ); -create unique index "agg_sort_order_c2_idx" on agg_sort_order using btree (c2); +create unique index agg_sort_order_c2_idx on agg_sort_order using btree (c2); insert into agg_sort_order select i, i from generate_series(1, 100) as i; @@ -2556,25 +1971,24 @@ reset enable_seqscan; begin; -create function balkifnull(bigint, bigint) -returns bigint +create function balkifnull(int8, int8) +returns int8 language plpgsql strict -parallel SAFE -as $function$ +parallel safe +as $$ BEGIN IF $1 IS NULL THEN RAISE 'erroneously called with NULL argument'; END IF; RETURN NULL; -END -$function$; +END$$; create aggregate balk ( - int + int4 ) ( sfunc = int4_sum(int8, int4), - stype = bigint, + stype = int8, combinefunc = balkifnull(int8, int8), parallel = safe, initcond = '0' @@ -2599,18 +2013,18 @@ create function rwagg_sfunc(x anyarray, y anyarray) returns anyarray language plpgsql immutable -as $function$ +as $$ BEGIN RETURN array_fill(y[1], ARRAY[4]); END; -$function$; +$$; create function rwagg_finalfunc(x anyarray) returns anyarray language plpgsql immutable strict -as $function$ +as $$ DECLARE res x%TYPE; BEGIN @@ -2618,7 +2032,7 @@ BEGIN res := array_fill(x[1], ARRAY[4]); RETURN res; END; -$function$; +$$; create aggregate rwagg ( anyarray @@ -2633,20 +2047,16 @@ returns real[] language plpgsql immutable strict -as $function$ +as $$ BEGIN x[1] := x[1] + 1; RETURN x; END; -$function$; +$$; select - eatarray( - rwagg(array[cast(1.0 as real)]) - ), - eatarray( - rwagg(array[cast(1.0 as real)]) - ); + eatarray(rwagg(array[cast(1.0 as real)])), + eatarray(rwagg(array[cast(1.0 as real)])); rollback; @@ -2665,17 +2075,12 @@ set parallel_leader_participation = off; set enable_indexonlyscan = off; select - variance(cast(unique1 as int)), - SUM(cast(unique1 as bigint)), - regr_count( - cast(unique1 as double precision), - cast(unique1 as double precision) - ) + variance(cast(unique1 as int4)), + sum(cast(unique1 as int8)), + regr_count(cast(unique1 as float8), cast(unique1 as float8)) from ( - select * from tenk1 - union all - select * from tenk1 + select * from tenk1 union all select * from tenk1 union all select * from tenk1 union all @@ -2684,17 +2089,12 @@ from as u; select - variance(cast(unique1 as int)), - SUM(cast(unique1 as bigint)), - regr_count( - cast(unique1 as double precision), - cast(unique1 as double precision) - ) + variance(cast(unique1 as int4)), + sum(cast(unique1 as int8)), + regr_count(cast(unique1 as float8), cast(unique1 as float8)) from ( - select * from tenk1 - union all - select * from tenk1 + select * from tenk1 union all select * from tenk1 union all select * from tenk1 union all @@ -2703,13 +2103,11 @@ from as u; select - variance(cast(unique1 as bigint)), - AVG(cast(unique1 as numeric)) + variance(cast(unique1 as int8)), + avg(cast(unique1 as numeric)) from ( - select * from tenk1 - union all - select * from tenk1 + select * from tenk1 union all select * from tenk1 union all select * from tenk1 union all @@ -2718,13 +2116,11 @@ from as u; select - variance(cast(unique1 as bigint)), - AVG(cast(unique1 as numeric)) + variance(cast(unique1 as int8)), + avg(cast(unique1 as numeric)) from ( - select * from tenk1 - union all - select * from tenk1 + select * from tenk1 union all select * from tenk1 union all select * from tenk1 union all @@ -2735,26 +2131,20 @@ from rollback; select - DENSE_RANK(x) within group (order by x) + dense_rank(x) within group (order by x) from - ( - values (1), (1), (2), (2), (3), (3) - ) - as v (x) + (values (1), (1), (2), (2), (3), (3)) as v (x) group by x order by 1; -select MIN(x order by y) from (values (1, null)) as d (x, y); +select min(x order by y) from (values (1, null)) as d (x, y); -select MIN(x order by y) from (values (1, 2)) as d (x, y); +select min(x order by y) from (values (1, 2)) as d (x, y); select v || 'a', - case v || 'a' - when 'aa' then 1 - else 0 - end, - COUNT(*) + case v || 'a' when 'aa' then 1 else 0 end, + count(*) from unnest(array['a', 'b']) as u (v) group by v || 'a' @@ -2762,11 +2152,8 @@ order by 1; select v || 'a', - case - when v || 'a' = 'aa' then 1 - else 0 - end, - COUNT(*) + case when v || 'a' = 'aa' then 1 else 0 end, + count(*) from unnest(array['a', 'b']) as u (v) group by v || 'a' @@ -2778,14 +2165,14 @@ set work_mem = '64kB'; select unique1, - COUNT(*), - SUM(twothousand) + count(*), + sum(twothousand) from tenk1 group by unique1 having - SUM(fivethous) > 4975 -order by SUM(twothousand); + sum(fivethous) > 4975 +order by sum(twothousand); set work_mem = default; @@ -2807,8 +2194,8 @@ set jit_above_cost = 0; select g % 10000 as c1, - SUM(cast(g as numeric)) as c2, - COUNT(*) as c3 + sum(cast(g as numeric)) as c2, + count(*) as c3 from agg_data_20k group by g % 10000; @@ -2817,8 +2204,8 @@ create table agg_group_1 as select g % 10000 as c1, - SUM(cast(g as numeric)) as c2, - COUNT(*) as c3 + sum(cast(g as numeric)) as c2, + count(*) as c3 from agg_data_20k group by g % 10000; @@ -2833,7 +2220,7 @@ as select cast(g / 2 as numeric) as c1, array_agg(cast(g as numeric)) as c2, - COUNT(*) as c3 + count(*) as c3 from agg_data_2k where @@ -2848,8 +2235,8 @@ create table agg_group_3 as select cast(g / 2 as numeric) as c1, - SUM(cast(7 as int)) as c2, - COUNT(*) as c3 + sum(cast(7 as int4)) as c2, + count(*) as c3 from agg_data_2k group by g / 2; @@ -2859,7 +2246,7 @@ as select cast(g / 2 as numeric) as c1, array_agg(cast(g as numeric)) as c2, - COUNT(*) as c3 + count(*) as c3 from agg_data_2k group by g / 2; @@ -2872,8 +2259,8 @@ set jit_above_cost = 0; select g % 10000 as c1, - SUM(cast(g as numeric)) as c2, - COUNT(*) as c3 + sum(cast(g as numeric)) as c2, + count(*) as c3 from agg_data_20k group by g % 10000; @@ -2882,8 +2269,8 @@ create table agg_hash_1 as select g % 10000 as c1, - SUM(cast(g as numeric)) as c2, - COUNT(*) as c3 + sum(cast(g as numeric)) as c2, + count(*) as c3 from agg_data_20k group by g % 10000; @@ -2898,7 +2285,7 @@ as select cast(g / 2 as numeric) as c1, array_agg(cast(g as numeric)) as c2, - COUNT(*) as c3 + count(*) as c3 from agg_data_2k where @@ -2913,8 +2300,8 @@ create table agg_hash_3 as select cast(g / 2 as numeric) as c1, - SUM(cast(7 as int)) as c2, - COUNT(*) as c3 + sum(cast(7 as int4)) as c2, + count(*) as c3 from agg_data_2k group by g / 2; @@ -2924,7 +2311,7 @@ as select cast(g / 2 as numeric) as c1, array_agg(cast(g as numeric)) as c2, - COUNT(*) as c3 + count(*) as c3 from agg_data_2k group by g / 2; @@ -2933,37 +2320,21 @@ set enable_sort = 'true'; set work_mem = default; -select * from agg_hash_1 -except -select * from agg_group_1 +select * from agg_hash_1 except select * from agg_group_1 union all -(select * from agg_group_1 -except -select * from agg_hash_1); +(select * from agg_group_1 except select * from agg_hash_1); -select * from agg_hash_2 -except -select * from agg_group_2 +select * from agg_hash_2 except select * from agg_group_2 union all -(select * from agg_group_2 -except -select * from agg_hash_2); +(select * from agg_group_2 except select * from agg_hash_2); -select * from agg_hash_3 -except -select * from agg_group_3 +select * from agg_hash_3 except select * from agg_group_3 union all -(select * from agg_group_3 -except -select * from agg_hash_3); +(select * from agg_group_3 except select * from agg_hash_3); -select * from agg_hash_4 -except -select * from agg_group_4 +select * from agg_hash_4 except select * from agg_group_4 union all -(select * from agg_group_4 -except -select * from agg_hash_4); +(select * from agg_group_4 except select * from agg_hash_4); drop table agg_group_1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_100.snap index 6af80f118..1c7484c4c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_100.snap @@ -23,9 +23,9 @@ create user regress_alter_generic_user2; create user regress_alter_generic_user1 in role regress_alter_generic_user3; -create schema "alt_nsp1"; +create schema alt_nsp1; -create schema "alt_nsp2"; +create schema alt_nsp2; grant all on schema alt_nsp1, alt_nsp2 to public; @@ -36,20 +36,16 @@ set session authorization regress_alter_generic_user1; create function alt_func1(int) returns int language sql -as $function$ -SELECT $1 + 1 -$function$; +as 'SELECT $1 + 1'; create function alt_func2(int) returns int language sql -as $function$ -SELECT $1 - 1 -$function$; +as 'SELECT $1 - 1'; -create aggregate alt_agg1 (sfunc1 = int4pl, basetype = int, stype1 = int, initcond = 0); +create aggregate alt_agg1 (sfunc1 = int4pl, basetype = int4, stype1 = int4, initcond = 0); -create aggregate alt_agg2 (sfunc1 = int4mi, basetype = int, stype1 = int, initcond = 0); +create aggregate alt_agg2 (sfunc1 = int4mi, basetype = int4, stype1 = int4, initcond = 0); alter aggregate alt_func1(int) rename to alt_func3; @@ -84,20 +80,16 @@ set session authorization regress_alter_generic_user2; create function alt_func1(int) returns int language sql -as $function$ -SELECT $1 + 2 -$function$; +as 'SELECT $1 + 2'; create function alt_func2(int) returns int language sql -as $function$ -SELECT $1 - 2 -$function$; +as 'SELECT $1 - 2'; -create aggregate alt_agg1 (sfunc1 = int4pl, basetype = int, stype1 = int, initcond = 100); +create aggregate alt_agg1 (sfunc1 = int4pl, basetype = int4, stype1 = int4, initcond = 100); -create aggregate alt_agg2 (sfunc1 = int4mi, basetype = int, stype1 = int, initcond = -100); +create aggregate alt_agg2 (sfunc1 = int4mi, basetype = int4, stype1 = int4, initcond = -100); alter function alt_func3(int) rename to alt_func4; @@ -136,9 +128,7 @@ from pg_namespace as n, pg_authid as a where - p.pronamespace = n.oid and - p.proowner = a.oid and - n.nspname in ('alt_nsp1', 'alt_nsp2') + p.pronamespace = n.oid and p.proowner = a.oid and n.nspname in ('alt_nsp1', 'alt_nsp2') order by nspname, proname; @@ -187,9 +177,7 @@ from pg_namespace as n, pg_authid as a where - c.connamespace = n.oid and - c.conowner = a.oid and - n.nspname in ('alt_nsp1', 'alt_nsp2') + c.connamespace = n.oid and c.conowner = a.oid and n.nspname in ('alt_nsp1', 'alt_nsp2') order by nspname, conname; @@ -249,25 +237,25 @@ order by lanname; set session authorization regress_alter_generic_user1; -create operator @-@ (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4mi); +create operator @-@ (leftarg = int4, rightarg = int4, procedure = int4mi); -create operator @+@ (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4pl); +create operator @+@ (leftarg = int4, rightarg = int4, procedure = int4pl); -alter operator @+@ (int, int) owner to regress_alter_generic_user2; +alter operator @+@ (int4, int4) owner to regress_alter_generic_user2; -alter operator @+@ (int, int) owner to regress_alter_generic_user3; +alter operator @+@ (int4, int4) owner to regress_alter_generic_user3; -alter operator @-@ (int, int) set schema alt_nsp2; +alter operator @-@ (int4, int4) set schema alt_nsp2; set session authorization regress_alter_generic_user2; -create operator @-@ (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4mi); +create operator @-@ (leftarg = int4, rightarg = int4, procedure = int4mi); -alter operator @+@ (int, int) owner to regress_alter_generic_user2; +alter operator @+@ (int4, int4) owner to regress_alter_generic_user2; -alter operator @-@ (int, int) owner to regress_alter_generic_user3; +alter operator @-@ (int4, int4) owner to regress_alter_generic_user3; -alter operator @+@ (int, int) set schema alt_nsp2; +alter operator @+@ (int4, int4) set schema alt_nsp2; reset session_authorization; @@ -283,9 +271,7 @@ from pg_namespace as n, pg_authid as a where - o.oprnamespace = n.oid and - o.oprowner = a.oid and - n.nspname in ('alt_nsp1', 'alt_nsp2') + o.oprnamespace = n.oid and o.oprowner = a.oid and n.nspname in ('alt_nsp1', 'alt_nsp2') order by nspname, oprname; @@ -415,20 +401,20 @@ begin; create operator family alt_opf4 using btree; alter operator family alt_opf4 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2); alter operator family alt_opf4 using btree - drop operator 1 (int, smallint), - operator 2 (int, smallint), - operator 3 (int, smallint), - operator 4 (int, smallint), - operator 5 (int, smallint), - function 1 (int, smallint); + drop operator 1 (int4, int2), + operator 2 (int4, int2), + operator 3 (int4, int2), + operator 4 (int4, int2), + operator 5 (int4, int2), + function 1 (int4, int2); drop operator family alt_opf4 using btree; @@ -436,17 +422,17 @@ rollback; create operator family alt_opf4 using btree; -alter operator family alt_opf4 using invalid_index_method add operator 1 < (int, smallint); +alter operator family alt_opf4 using invalid_index_method add operator 1 < (int4, int2); -alter operator family alt_opf4 using btree add operator 6 < (int, smallint); +alter operator family alt_opf4 using btree add operator 6 < (int4, int2); -alter operator family alt_opf4 using btree add operator 0 < (int, smallint); +alter operator family alt_opf4 using btree add operator 0 < (int4, int2); alter operator family alt_opf4 using btree add operator 1 <; -alter operator family alt_opf4 using btree add function 0 btint42cmp(int, smallint); +alter operator family alt_opf4 using btree add function 0 btint42cmp(int4, int2); -alter operator family alt_opf4 using btree add function 7 btint42cmp(int, smallint); +alter operator family alt_opf4 using btree add function 7 btint42cmp(int4, int2); alter operator family alt_opf4 using btree add storage invalid_storage; @@ -461,8 +447,7 @@ create operator family alt_opf5 using btree; set role to regress_alter_generic_user5; alter operator family alt_opf5 using btree - add operator 1 < (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), function 1 btint42cmp(int4, int2); reset role; @@ -474,7 +459,7 @@ begin; create role regress_alter_generic_user6; -create schema "alt_nsp6"; +create schema alt_nsp6; revoke all on schema alt_nsp6 from regress_alter_generic_user6; @@ -482,41 +467,41 @@ create operator family alt_nsp6.alt_opf6 using btree; set role to regress_alter_generic_user6; -alter operator family alt_nsp6.alt_opf6 using btree add operator 1 < (int, smallint); +alter operator family alt_nsp6.alt_opf6 using btree add operator 1 < (int4, int2); rollback; create operator family alt_opf7 using btree; -alter operator family alt_opf7 using btree add operator 1 < (int, smallint); +alter operator family alt_opf7 using btree add operator 1 < (int4, int2); -alter operator family alt_opf7 using btree drop operator 1 (int, smallint, bigint); +alter operator family alt_opf7 using btree drop operator 1 (int4, int2, int8); drop operator family alt_opf7 using btree; create operator family alt_opf8 using btree; -alter operator family alt_opf8 using btree add operator 1 < (int, int); +alter operator family alt_opf8 using btree add operator 1 < (int4, int4); drop operator family alt_opf8 using btree; create operator family alt_opf9 using gist; -alter operator family alt_opf9 using gist add operator 1 < (int, int) for order by float_ops; +alter operator family alt_opf9 using gist add operator 1 < (int4, int4) for order by float_ops; drop operator family alt_opf9 using gist; create operator family alt_opf10 using btree; -alter operator family alt_opf10 using btree add operator 1 < (int, int) for order by float_ops; +alter operator family alt_opf10 using btree add operator 1 < (int4, int4) for order by float_ops; drop operator family alt_opf10 using btree; create operator family alt_opf11 using gist; -alter operator family alt_opf11 using gist add operator 1 < (int, int) for order by float_ops; +alter operator family alt_opf11 using gist add operator 1 < (int4, int4) for order by float_ops; -alter operator family alt_opf11 using gist drop operator 1 (int, int); +alter operator family alt_opf11 using gist drop operator 1 (int4, int4); drop operator family alt_opf11 using gist; @@ -524,14 +509,12 @@ begin; create operator family alt_opf12 using btree; -create function fn_opf12(int, smallint) +create function fn_opf12(int4, int2) returns bigint language sql -as $function$ -SELECT NULL::BIGINT; -$function$; +as 'SELECT NULL::BIGINT;'; -alter operator family alt_opf12 using btree add function 1 fn_opf12(int, smallint); +alter operator family alt_opf12 using btree add function 1 fn_opf12(int4, int2); drop operator family alt_opf12 using btree; @@ -541,14 +524,12 @@ begin; create operator family alt_opf13 using hash; -create function fn_opf13(int) +create function fn_opf13(int4) returns bigint language sql -as $function$ -SELECT NULL::BIGINT; -$function$; +as 'SELECT NULL::BIGINT;'; -alter operator family alt_opf13 using hash add function 1 fn_opf13(int); +alter operator family alt_opf13 using hash add function 1 fn_opf13(int4); drop operator family alt_opf13 using hash; @@ -558,14 +539,12 @@ begin; create operator family alt_opf14 using btree; -create function fn_opf14(int) +create function fn_opf14(int4) returns bigint language sql -as $function$ -SELECT NULL::BIGINT; -$function$; +as 'SELECT NULL::BIGINT;'; -alter operator family alt_opf14 using btree add function 1 fn_opf14(int); +alter operator family alt_opf14 using btree add function 1 fn_opf14(int4); drop operator family alt_opf14 using btree; @@ -575,14 +554,12 @@ begin; create operator family alt_opf15 using hash; -create function fn_opf15(int, smallint) +create function fn_opf15(int4, int2) returns bigint language sql -as $function$ -SELECT NULL::BIGINT; -$function$; +as 'SELECT NULL::BIGINT;'; -alter operator family alt_opf15 using hash add function 1 fn_opf15(int, smallint); +alter operator family alt_opf15 using hash add function 1 fn_opf15(int4, int2); drop operator family alt_opf15 using hash; @@ -590,85 +567,79 @@ rollback; create operator family alt_opf16 using gist; -alter operator family alt_opf16 using gist add function 1 btint42cmp(int, smallint); +alter operator family alt_opf16 using gist add function 1 btint42cmp(int4, int2); drop operator family alt_opf16 using gist; create operator family alt_opf17 using btree; -alter operator family alt_opf17 using btree add operator 1 < (int, int), operator 1 < (int, int); +alter operator family alt_opf17 using btree + add operator 1 < (int4, int4), operator 1 < (int4, int4); -alter operator family alt_opf17 using btree add operator 1 < (int, int); +alter operator family alt_opf17 using btree add operator 1 < (int4, int4); -alter operator family alt_opf17 using btree add operator 1 < (int, int); +alter operator family alt_opf17 using btree add operator 1 < (int4, int4); alter operator family alt_opf17 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2), + function 1 btint42cmp(int4, int2); alter operator family alt_opf17 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2); alter operator family alt_opf17 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2); drop operator family alt_opf17 using btree; create operator family alt_opf18 using btree; -alter operator family alt_opf18 using btree drop operator 1 (int, int); +alter operator family alt_opf18 using btree drop operator 1 (int4, int4); alter operator family alt_opf18 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2); -alter operator family alt_opf18 using btree add function 4 (int, smallint) btequalimage(oid); +alter operator family alt_opf18 using btree add function 4 (int4, int2) btequalimage(oid); -alter operator family alt_opf18 using btree - add function 6 (int, - smallint) btint4skipsupport(internal); +alter operator family alt_opf18 using btree add function 6 (int4, int2) btint4skipsupport(internal); -alter operator family alt_opf18 using btree drop function 2 (int, int); +alter operator family alt_opf18 using btree drop function 2 (int4, int4); drop operator family alt_opf18 using btree; create operator family alt_opf19 using btree; alter operator family alt_opf19 using btree - add function 5 test_opclass_options_func( - internal, - text[], - boolean); + add function 5 test_opclass_options_func(internal, text[], bool); -alter operator family alt_opf19 using btree add function 5 (int) btint42cmp(int, smallint); +alter operator family alt_opf19 using btree add function 5 (int4) btint42cmp(int4, int2); -alter operator family alt_opf19 using btree - add function 5 (int, - smallint) btint42cmp(int, smallint); +alter operator family alt_opf19 using btree add function 5 (int4, int2) btint42cmp(int4, int2); alter operator family alt_opf19 using btree - add function 5 (int) test_opclass_options_func(internal); + add function 5 (int4) test_opclass_options_func(internal); -alter operator family alt_opf19 using btree drop function 5 (int, int); +alter operator family alt_opf19 using btree drop function 5 (int4, int4); drop operator family alt_opf19 using btree; @@ -679,9 +650,9 @@ create table alt_regress_1 ( b int ); -create statistics alt_stat1 on "a", "b" from alt_regress_1; +create statistics alt_stat1 on a, b from alt_regress_1; -create statistics alt_stat2 on "a", "b" from alt_regress_1; +create statistics alt_stat2 on a, b from alt_regress_1; alter statistics alt_stat1 rename to alt_stat2; @@ -700,9 +671,9 @@ create table alt_regress_2 ( b int ); -create statistics alt_stat1 on "a", "b" from alt_regress_2; +create statistics alt_stat1 on a, b from alt_regress_2; -create statistics alt_stat2 on "a", "b" from alt_regress_2; +create statistics alt_stat2 on a, b from alt_regress_2; alter statistics alt_stat3 rename to alt_stat4; @@ -727,9 +698,7 @@ from pg_namespace as n, pg_authid as a where - s.stxnamespace = n.oid and - s.stxowner = a.oid and - n.nspname in ('alt_nsp1', 'alt_nsp2') + s.stxnamespace = n.oid and s.stxowner = a.oid and n.nspname in ('alt_nsp1', 'alt_nsp2') order by nspname, stxname; @@ -778,9 +747,7 @@ from pg_namespace as n, pg_authid as a where - t.dictnamespace = n.oid and - t.dictowner = a.oid and - n.nspname in ('alt_nsp1', 'alt_nsp2') + t.dictnamespace = n.oid and t.dictowner = a.oid and n.nspname in ('alt_nsp1', 'alt_nsp2') order by nspname, dictname; @@ -829,9 +796,7 @@ from pg_namespace as n, pg_authid as a where - t.cfgnamespace = n.oid and - t.cfgowner = a.oid and - n.nspname in ('alt_nsp1', 'alt_nsp2') + t.cfgnamespace = n.oid and t.cfgowner = a.oid and n.nspname in ('alt_nsp1', 'alt_nsp2') order by nspname, cfgname; @@ -858,8 +823,7 @@ from pg_ts_template as t, pg_namespace as n where - t.tmplnamespace = n.oid and - nspname like 'alt_nsp%' + t.tmplnamespace = n.oid and nspname like 'alt_nsp%' order by nspname, tmplname; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_80.snap index 04f731c2c..739753541 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_80.snap @@ -23,9 +23,9 @@ create user regress_alter_generic_user2; create user regress_alter_generic_user1 in role regress_alter_generic_user3; -create schema "alt_nsp1"; +create schema alt_nsp1; -create schema "alt_nsp2"; +create schema alt_nsp2; grant all on schema alt_nsp1, alt_nsp2 to public; @@ -36,28 +36,24 @@ set session authorization regress_alter_generic_user1; create function alt_func1(int) returns int language sql -as $function$ -SELECT $1 + 1 -$function$; +as 'SELECT $1 + 1'; create function alt_func2(int) returns int language sql -as $function$ -SELECT $1 - 1 -$function$; +as 'SELECT $1 - 1'; create aggregate alt_agg1 ( sfunc1 = int4pl, - basetype = int, - stype1 = int, + basetype = int4, + stype1 = int4, initcond = 0 ); create aggregate alt_agg2 ( sfunc1 = int4mi, - basetype = int, - stype1 = int, + basetype = int4, + stype1 = int4, initcond = 0 ); @@ -94,28 +90,24 @@ set session authorization regress_alter_generic_user2; create function alt_func1(int) returns int language sql -as $function$ -SELECT $1 + 2 -$function$; +as 'SELECT $1 + 2'; create function alt_func2(int) returns int language sql -as $function$ -SELECT $1 - 2 -$function$; +as 'SELECT $1 - 2'; create aggregate alt_agg1 ( sfunc1 = int4pl, - basetype = int, - stype1 = int, + basetype = int4, + stype1 = int4, initcond = 100 ); create aggregate alt_agg2 ( sfunc1 = int4mi, - basetype = int, - stype1 = int, + basetype = int4, + stype1 = int4, initcond = -100 ); @@ -264,31 +256,30 @@ from pg_language as l, pg_authid as a where - l.lanowner = a.oid and - l.lanname like 'alt_lang%' + l.lanowner = a.oid and l.lanname like 'alt_lang%' order by lanname; set session authorization regress_alter_generic_user1; -create operator @-@ (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4mi); +create operator @-@ (leftarg = int4, rightarg = int4, procedure = int4mi); -create operator @+@ (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4pl); +create operator @+@ (leftarg = int4, rightarg = int4, procedure = int4pl); -alter operator @+@ (int, int) owner to regress_alter_generic_user2; +alter operator @+@ (int4, int4) owner to regress_alter_generic_user2; -alter operator @+@ (int, int) owner to regress_alter_generic_user3; +alter operator @+@ (int4, int4) owner to regress_alter_generic_user3; -alter operator @-@ (int, int) set schema alt_nsp2; +alter operator @-@ (int4, int4) set schema alt_nsp2; set session authorization regress_alter_generic_user2; -create operator @-@ (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4mi); +create operator @-@ (leftarg = int4, rightarg = int4, procedure = int4mi); -alter operator @+@ (int, int) owner to regress_alter_generic_user2; +alter operator @+@ (int4, int4) owner to regress_alter_generic_user2; -alter operator @-@ (int, int) owner to regress_alter_generic_user3; +alter operator @-@ (int4, int4) owner to regress_alter_generic_user3; -alter operator @+@ (int, int) set schema alt_nsp2; +alter operator @+@ (int4, int4) set schema alt_nsp2; reset session_authorization; @@ -436,20 +427,20 @@ begin; create operator family alt_opf4 using btree; alter operator family alt_opf4 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2); alter operator family alt_opf4 using btree - drop operator 1 (int, smallint), - operator 2 (int, smallint), - operator 3 (int, smallint), - operator 4 (int, smallint), - operator 5 (int, smallint), - function 1 (int, smallint); + drop operator 1 (int4, int2), + operator 2 (int4, int2), + operator 3 (int4, int2), + operator 4 (int4, int2), + operator 5 (int4, int2), + function 1 (int4, int2); drop operator family alt_opf4 using btree; @@ -458,19 +449,19 @@ rollback; create operator family alt_opf4 using btree; alter operator family alt_opf4 using invalid_index_method - add operator 1 < (int, smallint); + add operator 1 < (int4, int2); -alter operator family alt_opf4 using btree add operator 6 < (int, smallint); +alter operator family alt_opf4 using btree add operator 6 < (int4, int2); -alter operator family alt_opf4 using btree add operator 0 < (int, smallint); +alter operator family alt_opf4 using btree add operator 0 < (int4, int2); alter operator family alt_opf4 using btree add operator 1 <; alter operator family alt_opf4 using btree - add function 0 btint42cmp(int, smallint); + add function 0 btint42cmp(int4, int2); alter operator family alt_opf4 using btree - add function 7 btint42cmp(int, smallint); + add function 7 btint42cmp(int4, int2); alter operator family alt_opf4 using btree add storage invalid_storage; @@ -485,8 +476,7 @@ create operator family alt_opf5 using btree; set role to regress_alter_generic_user5; alter operator family alt_opf5 using btree - add operator 1 < (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), function 1 btint42cmp(int4, int2); reset role; @@ -498,7 +488,7 @@ begin; create role regress_alter_generic_user6; -create schema "alt_nsp6"; +create schema alt_nsp6; revoke all on schema alt_nsp6 from regress_alter_generic_user6; @@ -507,45 +497,44 @@ create operator family alt_nsp6.alt_opf6 using btree; set role to regress_alter_generic_user6; alter operator family alt_nsp6.alt_opf6 using btree - add operator 1 < (int, smallint); + add operator 1 < (int4, int2); rollback; create operator family alt_opf7 using btree; -alter operator family alt_opf7 using btree add operator 1 < (int, smallint); +alter operator family alt_opf7 using btree add operator 1 < (int4, int2); -alter operator family alt_opf7 using btree - drop operator 1 (int, smallint, bigint); +alter operator family alt_opf7 using btree drop operator 1 (int4, int2, int8); drop operator family alt_opf7 using btree; create operator family alt_opf8 using btree; -alter operator family alt_opf8 using btree add operator 1 < (int, int); +alter operator family alt_opf8 using btree add operator 1 < (int4, int4); drop operator family alt_opf8 using btree; create operator family alt_opf9 using gist; alter operator family alt_opf9 using gist - add operator 1 < (int, int) for order by float_ops; + add operator 1 < (int4, int4) for order by float_ops; drop operator family alt_opf9 using gist; create operator family alt_opf10 using btree; alter operator family alt_opf10 using btree - add operator 1 < (int, int) for order by float_ops; + add operator 1 < (int4, int4) for order by float_ops; drop operator family alt_opf10 using btree; create operator family alt_opf11 using gist; alter operator family alt_opf11 using gist - add operator 1 < (int, int) for order by float_ops; + add operator 1 < (int4, int4) for order by float_ops; -alter operator family alt_opf11 using gist drop operator 1 (int, int); +alter operator family alt_opf11 using gist drop operator 1 (int4, int4); drop operator family alt_opf11 using gist; @@ -553,15 +542,12 @@ begin; create operator family alt_opf12 using btree; -create function fn_opf12(int, smallint) +create function fn_opf12(int4, int2) returns bigint language sql -as $function$ -SELECT NULL::BIGINT; -$function$; +as 'SELECT NULL::BIGINT;'; -alter operator family alt_opf12 using btree - add function 1 fn_opf12(int, smallint); +alter operator family alt_opf12 using btree add function 1 fn_opf12(int4, int2); drop operator family alt_opf12 using btree; @@ -571,14 +557,12 @@ begin; create operator family alt_opf13 using hash; -create function fn_opf13(int) +create function fn_opf13(int4) returns bigint language sql -as $function$ -SELECT NULL::BIGINT; -$function$; +as 'SELECT NULL::BIGINT;'; -alter operator family alt_opf13 using hash add function 1 fn_opf13(int); +alter operator family alt_opf13 using hash add function 1 fn_opf13(int4); drop operator family alt_opf13 using hash; @@ -588,14 +572,12 @@ begin; create operator family alt_opf14 using btree; -create function fn_opf14(int) +create function fn_opf14(int4) returns bigint language sql -as $function$ -SELECT NULL::BIGINT; -$function$; +as 'SELECT NULL::BIGINT;'; -alter operator family alt_opf14 using btree add function 1 fn_opf14(int); +alter operator family alt_opf14 using btree add function 1 fn_opf14(int4); drop operator family alt_opf14 using btree; @@ -605,15 +587,12 @@ begin; create operator family alt_opf15 using hash; -create function fn_opf15(int, smallint) +create function fn_opf15(int4, int2) returns bigint language sql -as $function$ -SELECT NULL::BIGINT; -$function$; +as 'SELECT NULL::BIGINT;'; -alter operator family alt_opf15 using hash - add function 1 fn_opf15(int, smallint); +alter operator family alt_opf15 using hash add function 1 fn_opf15(int4, int2); drop operator family alt_opf15 using hash; @@ -622,90 +601,83 @@ rollback; create operator family alt_opf16 using gist; alter operator family alt_opf16 using gist - add function 1 btint42cmp(int, smallint); + add function 1 btint42cmp(int4, int2); drop operator family alt_opf16 using gist; create operator family alt_opf17 using btree; alter operator family alt_opf17 using btree - add operator 1 < (int, int), - operator 1 < (int, int); + add operator 1 < (int4, int4), operator 1 < (int4, int4); -alter operator family alt_opf17 using btree add operator 1 < (int, int); +alter operator family alt_opf17 using btree add operator 1 < (int4, int4); -alter operator family alt_opf17 using btree add operator 1 < (int, int); +alter operator family alt_opf17 using btree add operator 1 < (int4, int4); alter operator family alt_opf17 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2), + function 1 btint42cmp(int4, int2); alter operator family alt_opf17 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2); alter operator family alt_opf17 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2); drop operator family alt_opf17 using btree; create operator family alt_opf18 using btree; -alter operator family alt_opf18 using btree drop operator 1 (int, int); +alter operator family alt_opf18 using btree drop operator 1 (int4, int4); alter operator family alt_opf18 using btree - add operator 1 < (int, smallint), - operator 2 <= (int, smallint), - operator 3 = (int, smallint), - operator 4 >= (int, smallint), - operator 5 > (int, smallint), - function 1 btint42cmp(int, smallint); + add operator 1 < (int4, int2), + operator 2 <= (int4, int2), + operator 3 = (int4, int2), + operator 4 >= (int4, int2), + operator 5 > (int4, int2), + function 1 btint42cmp(int4, int2); alter operator family alt_opf18 using btree - add function 4 (int, - smallint) btequalimage(oid); + add function 4 (int4, int2) btequalimage(oid); alter operator family alt_opf18 using btree - add function 6 (int, - smallint) btint4skipsupport(internal); + add function 6 (int4, int2) btint4skipsupport(internal); -alter operator family alt_opf18 using btree drop function 2 (int, int); +alter operator family alt_opf18 using btree drop function 2 (int4, int4); drop operator family alt_opf18 using btree; create operator family alt_opf19 using btree; alter operator family alt_opf19 using btree - add function 5 test_opclass_options_func( - internal, - text[], - boolean); + add function 5 test_opclass_options_func(internal, text[], bool); alter operator family alt_opf19 using btree - add function 5 (int) btint42cmp(int, smallint); + add function 5 (int4) btint42cmp(int4, int2); alter operator family alt_opf19 using btree - add function 5 (int, - smallint) btint42cmp(int, smallint); + add function 5 (int4, int2) btint42cmp(int4, int2); alter operator family alt_opf19 using btree - add function 5 (int) test_opclass_options_func(internal); + add function 5 (int4) test_opclass_options_func(internal); -alter operator family alt_opf19 using btree drop function 5 (int, int); +alter operator family alt_opf19 using btree drop function 5 (int4, int4); drop operator family alt_opf19 using btree; @@ -716,9 +688,9 @@ create table alt_regress_1 ( b int ); -create statistics alt_stat1 on "a", "b" from alt_regress_1; +create statistics alt_stat1 on a, b from alt_regress_1; -create statistics alt_stat2 on "a", "b" from alt_regress_1; +create statistics alt_stat2 on a, b from alt_regress_1; alter statistics alt_stat1 rename to alt_stat2; @@ -737,9 +709,9 @@ create table alt_regress_2 ( b int ); -create statistics alt_stat1 on "a", "b" from alt_regress_2; +create statistics alt_stat1 on a, b from alt_regress_2; -create statistics alt_stat2 on "a", "b" from alt_regress_2; +create statistics alt_stat2 on a, b from alt_regress_2; alter statistics alt_stat3 rename to alt_stat4; @@ -899,8 +871,7 @@ from pg_ts_template as t, pg_namespace as n where - t.tmplnamespace = n.oid and - nspname like 'alt_nsp%' + t.tmplnamespace = n.oid and nspname like 'alt_nsp%' order by nspname, tmplname; @@ -942,8 +913,7 @@ from pg_ts_parser as t, pg_namespace as n where - t.prsnamespace = n.oid and - nspname like 'alt_nsp%' + t.prsnamespace = n.oid and nspname like 'alt_nsp%' order by nspname, prsname; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_100.snap index 0fb849724..d8f03f972 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_100.snap @@ -6,47 +6,39 @@ create function alter_op_test_fn(boolean, boolean) returns boolean language sql immutable -as $function$ -SELECT NULL::BOOLEAN; -$function$; +as $$ SELECT NULL::BOOLEAN; $$; create function customcontsel(internal, oid, internal, int) -returns double precision +returns float8 language internal stable strict -as $function$ -contsel -$function$; - -create operator === (LEFTARG = boolean, -RIGHTARG = boolean, -PROCEDURE = alter_op_test_fn, -COMMUTATOR = ===, -NEGATOR = !==, -RESTRICT = customcontsel, -JOIN = contjoinsel, -HASHES, -MERGES); +as 'contsel'; + +create operator === ( + leftarg = boolean, + rightarg = boolean, + procedure = alter_op_test_fn, + commutator = ===, + negator = !==, + restrict = customcontsel, + join = contjoinsel, + hashes, + merges +); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = cast('pg_operator' as regclass) and - objid = cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and objid = cast('===(bool,bool)' as regoperator) order by 1; -alter operator === (boolean, boolean) set (restrict = NONE); +alter operator === (boolean, boolean) set (restrict = none); -alter operator === (boolean, boolean) set (join = NONE); +alter operator === (boolean, boolean) set ("join" = none); select oprrest, @@ -59,23 +51,17 @@ where oprright = cast('boolean' as regtype); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = cast('pg_operator' as regclass) and - objid = cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and objid = cast('===(bool,bool)' as regoperator) order by 1; alter operator === (boolean, boolean) set (restrict = contsel); -alter operator === (boolean, boolean) set (join = contjoinsel); +alter operator === (boolean, boolean) set ("join" = contjoinsel); select oprrest, @@ -88,21 +74,15 @@ where oprright = cast('boolean' as regtype); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = cast('pg_operator' as regclass) and - objid = cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and objid = cast('===(bool,bool)' as regoperator) order by 1; -alter operator === (boolean, boolean) set (restrict = NONE, join = NONE); +alter operator === (boolean, boolean) set (restrict = none, "join" = none); select oprrest, @@ -115,21 +95,15 @@ where oprright = cast('boolean' as regtype); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = cast('pg_operator' as regclass) and - objid = cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and objid = cast('===(bool,bool)' as regoperator) order by 1; -alter operator === (boolean, boolean) set (restrict = customcontsel, join = contjoinsel); +alter operator === (boolean, boolean) set (restrict = customcontsel, "join" = contjoinsel); select oprrest, @@ -142,23 +116,17 @@ where oprright = cast('boolean' as regtype); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = cast('pg_operator' as regclass) and - objid = cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and objid = cast('===(bool,bool)' as regoperator) order by 1; alter operator === (boolean, boolean) set (restrict = non_existent_func); -alter operator === (boolean, boolean) set (join = non_existent_func); +alter operator === (boolean, boolean) set ("join" = non_existent_func); alter operator & (bit(1), bit(1)) set ("Restrict" = _int_contsel, "Join" = _int_contjoinsel); @@ -166,7 +134,7 @@ create user regress_alter_op_user; set session authorization regress_alter_op_user; -alter operator === (boolean, boolean) set (restrict = NONE); +alter operator === (boolean, boolean) set (restrict = none); reset session_authorization; @@ -174,23 +142,19 @@ create function alter_op_test_fn_bool_real(boolean, real) returns boolean language sql immutable -as $function$ -SELECT NULL::BOOLEAN; -$function$; +as $$ SELECT NULL::BOOLEAN; $$; create function alter_op_test_fn_real_bool(real, boolean) returns boolean language sql immutable -as $function$ -SELECT NULL::BOOLEAN; -$function$; +as $$ SELECT NULL::BOOLEAN; $$; -create operator === (LEFTARG = boolean, RIGHTARG = real, PROCEDURE = alter_op_test_fn_bool_real); +create operator === (leftarg = boolean, rightarg = real, procedure = alter_op_test_fn_bool_real); -create operator ==== (LEFTARG = real, RIGHTARG = boolean, PROCEDURE = alter_op_test_fn_real_bool); +create operator ==== (leftarg = real, rightarg = boolean, procedure = alter_op_test_fn_real_bool); -create operator !==== (LEFTARG = boolean, RIGHTARG = real, PROCEDURE = alter_op_test_fn_bool_real); +create operator !==== (leftarg = boolean, rightarg = real, procedure = alter_op_test_fn_bool_real); alter operator === (boolean, real) set (merges = 'false'); @@ -206,9 +170,7 @@ select from pg_operator where - oprname = '===' and - oprleft = cast('boolean' as regtype) and - oprright = cast('real' as regtype); + oprname = '===' and oprleft = cast('boolean' as regtype) and oprright = cast('real' as regtype); alter operator === (boolean, real) set (commutator = ====); @@ -217,10 +179,7 @@ select com.oprname as commutator_name, com.oprcode as commutator_func from - pg_operator as op - inner join - pg_operator as com - on op.oid = com.oprcom and op.oprcom = com.oid + pg_operator as op inner join pg_operator as com on op.oid = com.oprcom and op.oprcom = com.oid where op.oprname = '===' and op.oprleft = cast('boolean' as regtype) and @@ -255,28 +214,16 @@ alter operator === (boolean, real) set (hashes); select oprcanmerge, oprcanhash, - pg_describe_object( - cast('pg_operator' as regclass), - oprcom, - 0 - ) - as commutator, - pg_describe_object( - cast('pg_operator' as regclass), - oprnegate, - 0 - ) - as negator + pg_describe_object(cast('pg_operator' as regclass), oprcom, 0) as commutator, + pg_describe_object(cast('pg_operator' as regclass), oprnegate, 0) as negator from pg_operator where - oprname = '===' and - oprleft = cast('boolean' as regtype) and - oprright = cast('real' as regtype); + oprname = '===' and oprleft = cast('boolean' as regtype) and oprright = cast('real' as regtype); -create operator @= (LEFTARG = real, RIGHTARG = boolean, PROCEDURE = alter_op_test_fn_real_bool); +create operator @= (leftarg = real, rightarg = boolean, procedure = alter_op_test_fn_real_bool); -create operator @!= (LEFTARG = boolean, RIGHTARG = real, PROCEDURE = alter_op_test_fn_bool_real); +create operator @!= (leftarg = boolean, rightarg = real, procedure = alter_op_test_fn_bool_real); alter operator === (boolean, real) set (commutator = @=); @@ -293,24 +240,12 @@ alter operator @!= (boolean, real) set (negator = ===); select oprcanmerge, oprcanhash, - pg_describe_object( - cast('pg_operator' as regclass), - oprcom, - 0 - ) - as commutator, - pg_describe_object( - cast('pg_operator' as regclass), - oprnegate, - 0 - ) - as negator + pg_describe_object(cast('pg_operator' as regclass), oprcom, 0) as commutator, + pg_describe_object(cast('pg_operator' as regclass), oprnegate, 0) as negator from pg_operator where - oprname = '===' and - oprleft = cast('boolean' as regtype) and - oprright = cast('real' as regtype); + oprname = '===' and oprleft = cast('boolean' as regtype) and oprright = cast('real' as regtype); drop role regress_alter_op_user; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_80.snap index 1b1da723b..114a7d065 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_80.snap @@ -6,49 +6,40 @@ create function alter_op_test_fn(boolean, boolean) returns boolean language sql immutable -as $function$ -SELECT NULL::BOOLEAN; -$function$; +as $$ SELECT NULL::BOOLEAN; $$; create function customcontsel(internal, oid, internal, int) -returns double precision +returns float8 language internal stable strict -as $function$ -contsel -$function$; - -create operator === (LEFTARG = boolean, -RIGHTARG = boolean, -PROCEDURE = alter_op_test_fn, -COMMUTATOR = ===, -NEGATOR = !==, -RESTRICT = customcontsel, -JOIN = contjoinsel, -HASHES, -MERGES); +as 'contsel'; + +create operator === ( + leftarg = boolean, + rightarg = boolean, + procedure = alter_op_test_fn, + commutator = ===, + negator = !==, + restrict = customcontsel, + join = contjoinsel, + hashes, + merges +); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = - cast('pg_operator' as regclass) and - objid = - cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and + objid = cast('===(bool,bool)' as regoperator) order by 1; -alter operator === (boolean, boolean) set (restrict = NONE); +alter operator === (boolean, boolean) set (restrict = none); -alter operator === (boolean, boolean) set (join = NONE); +alter operator === (boolean, boolean) set ("join" = none); select oprrest, @@ -61,25 +52,18 @@ where oprright = cast('boolean' as regtype); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = - cast('pg_operator' as regclass) and - objid = - cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and + objid = cast('===(bool,bool)' as regoperator) order by 1; alter operator === (boolean, boolean) set (restrict = contsel); -alter operator === (boolean, boolean) set (join = contjoinsel); +alter operator === (boolean, boolean) set ("join" = contjoinsel); select oprrest, @@ -92,23 +76,16 @@ where oprright = cast('boolean' as regtype); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = - cast('pg_operator' as regclass) and - objid = - cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and + objid = cast('===(bool,bool)' as regoperator) order by 1; -alter operator === (boolean, boolean) set (restrict = NONE, join = NONE); +alter operator === (boolean, boolean) set (restrict = none, "join" = none); select oprrest, @@ -121,26 +98,17 @@ where oprright = cast('boolean' as regtype); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = - cast('pg_operator' as regclass) and - objid = - cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and + objid = cast('===(bool,bool)' as regoperator) order by 1; -alter operator === (boolean, -boolean) -set (restrict = customcontsel, -join = contjoinsel); +alter operator === (boolean, boolean) +set (restrict = customcontsel, "join" = contjoinsel); select oprrest, @@ -153,36 +121,27 @@ where oprright = cast('boolean' as regtype); select - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as ref, + pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype from pg_depend where - classid = - cast('pg_operator' as regclass) and - objid = - cast('===(bool,bool)' as regoperator) + classid = cast('pg_operator' as regclass) and + objid = cast('===(bool,bool)' as regoperator) order by 1; alter operator === (boolean, boolean) set (restrict = non_existent_func); -alter operator === (boolean, boolean) set (join = non_existent_func); +alter operator === (boolean, boolean) set ("join" = non_existent_func); -alter operator & (bit(1), -bit(1)) -set ("Restrict" = _int_contsel, -"Join" = _int_contjoinsel); +alter operator & (bit(1), bit(1)) +set ("Restrict" = _int_contsel, "Join" = _int_contjoinsel); create user regress_alter_op_user; set session authorization regress_alter_op_user; -alter operator === (boolean, boolean) set (restrict = NONE); +alter operator === (boolean, boolean) set (restrict = none); reset session_authorization; @@ -190,29 +149,31 @@ create function alter_op_test_fn_bool_real(boolean, real) returns boolean language sql immutable -as $function$ -SELECT NULL::BOOLEAN; -$function$; +as $$ SELECT NULL::BOOLEAN; $$; create function alter_op_test_fn_real_bool(real, boolean) returns boolean language sql immutable -as $function$ -SELECT NULL::BOOLEAN; -$function$; - -create operator === (LEFTARG = boolean, -RIGHTARG = real, -PROCEDURE = alter_op_test_fn_bool_real); - -create operator ==== (LEFTARG = real, -RIGHTARG = boolean, -PROCEDURE = alter_op_test_fn_real_bool); - -create operator !==== (LEFTARG = boolean, -RIGHTARG = real, -PROCEDURE = alter_op_test_fn_bool_real); +as $$ SELECT NULL::BOOLEAN; $$; + +create operator === ( + leftarg = boolean, + rightarg = real, + procedure = alter_op_test_fn_bool_real +); + +create operator ==== ( + leftarg = real, + rightarg = boolean, + procedure = alter_op_test_fn_real_bool +); + +create operator !==== ( + leftarg = boolean, + rightarg = real, + procedure = alter_op_test_fn_bool_real +); alter operator === (boolean, real) set (merges = 'false'); @@ -242,8 +203,7 @@ from pg_operator as op inner join pg_operator as com - on op.oid = com.oprcom and - op.oprcom = com.oid + on op.oid = com.oprcom and op.oprcom = com.oid where op.oprname = '===' and op.oprleft = cast('boolean' as regtype) and @@ -261,8 +221,7 @@ from pg_operator as op inner join pg_operator as neg - on op.oid = neg.oprnegate and - op.oprnegate = neg.oid + on op.oid = neg.oprnegate and op.oprnegate = neg.oid where op.oprname = '===' and op.oprleft = cast('boolean' as regtype) and @@ -279,18 +238,8 @@ alter operator === (boolean, real) set (hashes); select oprcanmerge, oprcanhash, - pg_describe_object( - cast('pg_operator' as regclass), - oprcom, - 0 - ) - as commutator, - pg_describe_object( - cast('pg_operator' as regclass), - oprnegate, - 0 - ) - as negator + pg_describe_object(cast('pg_operator' as regclass), oprcom, 0) as commutator, + pg_describe_object(cast('pg_operator' as regclass), oprnegate, 0) as negator from pg_operator where @@ -298,13 +247,17 @@ where oprleft = cast('boolean' as regtype) and oprright = cast('real' as regtype); -create operator @= (LEFTARG = real, -RIGHTARG = boolean, -PROCEDURE = alter_op_test_fn_real_bool); +create operator @= ( + leftarg = real, + rightarg = boolean, + procedure = alter_op_test_fn_real_bool +); -create operator @!= (LEFTARG = boolean, -RIGHTARG = real, -PROCEDURE = alter_op_test_fn_bool_real); +create operator @!= ( + leftarg = boolean, + rightarg = real, + procedure = alter_op_test_fn_bool_real +); alter operator === (boolean, real) set (commutator = @=); @@ -321,18 +274,8 @@ alter operator @!= (boolean, real) set (negator = ===); select oprcanmerge, oprcanhash, - pg_describe_object( - cast('pg_operator' as regclass), - oprcom, - 0 - ) - as commutator, - pg_describe_object( - cast('pg_operator' as regclass), - oprnegate, - 0 - ) - as negator + pg_describe_object(cast('pg_operator' as regclass), oprcom, 0) as commutator, + pg_describe_object(cast('pg_operator' as regclass), oprnegate, 0) as negator from pg_operator where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_table_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_table_100.snap index 97ce2746c..af1edb37c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_table_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_table_100.snap @@ -10,7 +10,7 @@ reset client_min_messages; create user regress_alter_table_user1; -create table attmp (initial int); +create table attmp (initial int4); comment on table attmp_wrong is 'table comment'; @@ -22,7 +22,7 @@ alter table attmp add column xmin int; alter table attmp - add column a int default 3; + add column a int4 default 3; alter table attmp add column b name; @@ -31,13 +31,13 @@ alter table attmp add column c text; alter table attmp - add column d double precision; + add column d float8; alter table attmp - add column e real; + add column e float4; alter table attmp - add column f smallint; + add column f int2; alter table attmp add column g polygon; @@ -46,7 +46,7 @@ alter table attmp add column i char(1); alter table attmp - add column k int; + add column k int4; alter table attmp add column l tid; @@ -79,38 +79,15 @@ alter table attmp add column w interval; alter table attmp - add column x double precision[]; + add column x float8[]; alter table attmp - add column y real[]; + add column y float4[]; alter table attmp - add column z smallint[]; - -insert into attmp ( - a, - b, - c, - d, - e, - f, - g, - i, - k, - l, - m, - n, - p, - q, - r, - s, - t, - v, - w, - x, - y, - z -) + add column z int2[]; + +insert into attmp (a, b, c, d, e, f, g, i, k, l, m, n, p, q, r, s, t, v, w, x, y, z) values ( 4, @@ -141,10 +118,10 @@ select * from attmp; drop table attmp; -create table attmp (initial int); +create table attmp (initial int4); alter table attmp - add column a int; + add column a int4; alter table attmp add column b name; @@ -153,13 +130,13 @@ alter table attmp add column c text; alter table attmp - add column d double precision; + add column d float8; alter table attmp - add column e real; + add column e float4; alter table attmp - add column f smallint; + add column f int2; alter table attmp add column g polygon; @@ -168,7 +145,7 @@ alter table attmp add column i char(1); alter table attmp - add column k int; + add column k int4; alter table attmp add column l tid; @@ -201,38 +178,15 @@ alter table attmp add column w interval; alter table attmp - add column x double precision[]; + add column x float8[]; alter table attmp - add column y real[]; + add column y float4[]; alter table attmp - add column z smallint[]; - -insert into attmp ( - a, - b, - c, - d, - e, - f, - g, - i, - k, - l, - m, - n, - p, - q, - r, - s, - t, - v, - w, - x, - y, - z -) + add column z int2[]; + +insert into attmp (a, b, c, d, e, f, g, i, k, l, m, n, p, q, r, s, t, v, w, x, y, z) values ( 4, @@ -261,7 +215,7 @@ values select * from attmp; -create index "attmp_idx" on attmp using btree (a, (d + e), b); +create index attmp_idx on attmp using btree (a, (d + e), b); alter index attmp_idx alter column 1 set statistics 1000; @@ -373,12 +327,12 @@ reset role; create table alter_idx_rename_test (a int); -create index "alter_idx_rename_test_idx" on alter_idx_rename_test using btree (a); +create index alter_idx_rename_test_idx on alter_idx_rename_test using btree (a); create table alter_idx_rename_test_parted (a int) -partition by LIST(a); +partition by list(a); -create index "alter_idx_rename_test_parted_idx" on alter_idx_rename_test_parted using btree (a); +create index alter_idx_rename_test_parted_idx on alter_idx_rename_test_parted using btree (a); begin; @@ -470,7 +424,7 @@ alter table stud_emp rename to pg_toast_stud_emp; alter table pg_toast_stud_emp rename to stud_emp; alter table onek - add constraint "onek_unique1_constraint" unique (unique1); + add constraint onek_unique1_constraint unique (unique1); alter index onek_unique1_constraint rename to onek_unique1_constraint_foo; @@ -478,7 +432,7 @@ alter table onek drop constraint onek_unique1_constraint_foo; alter table onek - add constraint "onek_check_constraint" check (unique1 >= 0); + add constraint onek_check_constraint check (unique1 >= 0); alter table onek rename constraint onek_check_constraint to onek_check_constraint_foo; @@ -486,7 +440,7 @@ alter table onek drop constraint onek_check_constraint_foo; alter table onek - add constraint "onek_unique1_constraint" unique (unique1); + add constraint onek_unique1_constraint unique (unique1); drop index onek_unique1_constraint; @@ -498,13 +452,13 @@ alter table onek drop constraint onek_unique1_constraint_foo; create table constraint_rename_test ( - a int constraint "con1" check (a > 0), + a int constraint con1 check (a > 0), b int, c int ); create table constraint_rename_test2 ( - a int constraint "con1" check (a > 0), + a int constraint con1 check (a > 0), d int ) inherits (constraint_rename_test); @@ -516,14 +470,14 @@ alter table only constraint_rename_test rename constraint con1 to con1foo; alter table constraint_rename_test rename constraint con1 to con1foo; alter table constraint_rename_test - add constraint "con2" check (b > 0) no inherit; + add constraint con2 check (b > 0) no inherit; alter table only constraint_rename_test rename constraint con2 to con2foo; alter table constraint_rename_test rename constraint con2foo to con2bar; alter table constraint_rename_test - add constraint "con3" primary key (a); + add constraint con3 primary key (a); alter table constraint_rename_test rename constraint con3 to con3foo; @@ -534,11 +488,11 @@ drop table constraint_rename_test; alter table if exists constraint_not_exist rename constraint con3 to con3foo; alter table if exists constraint_rename_test - add constraint "con4" unique (a); + add constraint con4 unique (a); create table constraint_rename_cache ( a int, - constraint "chk_a" check (a > 0), + constraint chk_a check (a > 0), primary key (a) ); @@ -587,34 +541,18 @@ insert into attmp3 values (1, 20); insert into attmp3 values (5, 50); alter table attmp3 - add constraint "attmpconstr" - foreign key - (c) - references attmp2 - match full; + add constraint attmpconstr foreign key (c) references attmp2 match full; alter table attmp3 - add constraint "attmpconstr" - foreign key - (a) - references attmp2 (b) - match full; + add constraint attmpconstr foreign key (a) references attmp2 (b) match full; alter table attmp3 - add constraint "attmpconstr" - foreign key - (a) - references attmp2 - match full; + add constraint attmpconstr foreign key (a) references attmp2 match full; delete from attmp3 where a = 5; alter table attmp3 - add constraint "attmpconstr" - foreign key - (a) - references attmp2 - match full; + add constraint attmpconstr foreign key (a) references attmp2 match full; alter table attmp3 drop constraint attmpconstr; @@ -622,12 +560,7 @@ alter table attmp3 insert into attmp3 values (5, 50); alter table attmp3 - add constraint "attmpconstr" - foreign key - (a) - references attmp2 - match full - not valid; + add constraint attmpconstr foreign key (a) references attmp2 match full not valid; alter table attmp3 validate constraint attmpconstr; @@ -641,10 +574,10 @@ alter table attmp3 validate constraint attmpconstr; alter table attmp3 - add constraint "b_greater_than_ten" check (b > 10); + add constraint b_greater_than_ten check (b > 10); alter table attmp3 - add constraint "b_greater_than_ten" check (b > 10) not valid; + add constraint b_greater_than_ten check (b > 10) not valid; alter table attmp3 validate constraint b_greater_than_ten; @@ -671,7 +604,7 @@ inherits (attmp3); insert into attmp6 values (6, 30), (7, 16); alter table attmp3 - add constraint "b_le_20" check (b <= 20) not valid; + add constraint b_le_20 check (b <= 20) not valid; alter table attmp3 validate constraint b_le_20; @@ -686,17 +619,15 @@ returns int language plpgsql immutable strict -as $function$ -BEGIN RAISE NOTICE 'boo: %', $1; RETURN $1; END; -$function$; +as $$ BEGIN RAISE NOTICE 'boo: %', $1; RETURN $1; END; $$; insert into attmp7 values (8, 18); alter table attmp7 - add constraint "identity" check (b = boo(b)); + add constraint identity check (b = boo(b)); alter table attmp3 - add constraint "identity" check (b = boo(b)) not valid; + add constraint identity check (b = boo(b)) not valid; alter table attmp3 validate constraint identity; @@ -711,7 +642,7 @@ insert into parent_noinh_convalid values (1); insert into child_noinh_convalid values (1); alter table parent_noinh_convalid - add constraint "check_a_is_2" check (a = 2) no inherit not valid; + add constraint check_a_is_2 check (a = 2) no inherit not valid; alter table parent_noinh_convalid validate constraint check_a_is_2; @@ -726,18 +657,12 @@ select from pg_constraint where - conrelid = - cast('parent_noinh_convalid' as regclass) and - conname = 'check_a_is_2'; + conrelid = cast('parent_noinh_convalid' as regclass) and conname = 'check_a_is_2'; drop table parent_noinh_convalid, child_noinh_convalid; alter table attmp5 - add constraint "attmpconstr" - foreign key - (a) - references attmp4 (a) - match full; + add constraint attmpconstr foreign key (a) references attmp4 (a) match full; drop table attmp7; @@ -765,21 +690,15 @@ create table nv_child_2011 () inherits (nv_parent); alter table nv_child_2010 - add check (d - between cast('2010-01-01' as date) - and cast('2010-12-31' as date)) not valid; + add check (d between cast('2010-01-01' as date) and cast('2010-12-31' as date)) not valid; alter table nv_child_2011 - add check (d - between cast('2011-01-01' as date) - and cast('2011-12-31' as date)) not valid; + add check (d between cast('2011-01-01' as date) and cast('2011-12-31' as date)) not valid; select * from nv_parent where d between '2011-08-01' and '2011-08-31'; create table nv_child_2009 ( - check (d - between cast('2009-01-01' as date) - and cast('2009-12-31' as date)) + check (d between cast('2009-01-01' as date) and cast('2009-12-31' as date)) ) inherits (nv_parent); @@ -793,9 +712,7 @@ alter table nv_child_2011 select * from nv_parent where d between cast('2009-08-01' as date) and cast('2009-08-31' as date); alter table nv_parent - add check (d - between cast('2001-01-01' as date) - and cast('2099-12-31' as date)) not valid; + add check (d between cast('2001-01-01' as date) and cast('2099-12-31' as date)) not valid; create temporary table pktable (ptest1 int primary key); @@ -811,7 +728,7 @@ alter table fktable drop table fktable; -create temporary table fktable (ftest1 bigint); +create temporary table fktable (ftest1 int8); alter table fktable add foreign key (ftest1) references pktable; @@ -870,11 +787,7 @@ create temporary table fktable ( ); alter table fktable - add foreign key - (ftest1, - ftest2) - references pktable (ptest1, - ptest2); + add foreign key (ftest1, ftest2) references pktable (ptest1, ptest2); drop table fktable; @@ -884,18 +797,10 @@ create temporary table fktable ( ); alter table fktable - add foreign key - (ftest1, - ftest2) - references pktable (ptest2, - ptest1); + add foreign key (ftest1, ftest2) references pktable (ptest2, ptest1); alter table fktable - add foreign key - (ftest2, - ftest1) - references pktable (ptest1, - ptest2); + add foreign key (ftest2, ftest1) references pktable (ptest1, ptest2); drop table fktable; @@ -906,58 +811,40 @@ create temporary table pktable (ptest1 int primary key); create temporary table fktable (ftest1 int); alter table fktable - add constraint "fknd" - foreign key - (ftest1) - references pktable - on DELETE cascade; + add constraint fknd foreign key (ftest1) references pktable on delete cascade; alter table fktable - add constraint "fkdd" - foreign key - (ftest1) - references pktable - on DELETE cascade - deferrable initially deferred; + add constraint fkdd foreign key (ftest1) + references pktable + on delete cascade + deferrable initially deferred; alter table fktable - add constraint "fkdi" - foreign key - (ftest1) - references pktable - on DELETE cascade - deferrable initially immediate; + add constraint fkdi foreign key (ftest1) + references pktable + on delete cascade + deferrable initially immediate; alter table fktable - add constraint "fknd2" - foreign key - (ftest1) - references pktable - on DELETE cascade - deferrable initially deferred; + add constraint fknd2 foreign key (ftest1) + references pktable + on delete cascade + deferrable initially deferred; alter table fktable - alter constraint "fknd2" not deferrable initially immediate; + alter constraint fknd2 not deferrable initially immediate; alter table fktable - add constraint "fkdd2" - foreign key - (ftest1) - references pktable - on DELETE cascade; + add constraint fkdd2 foreign key (ftest1) references pktable on delete cascade; alter table fktable - alter constraint "fkdd2" deferrable initially deferred; + alter constraint fkdd2 deferrable initially deferred; alter table fktable - add constraint "fkdi2" - foreign key - (ftest1) - references pktable - on DELETE cascade; + add constraint fkdi2 foreign key (ftest1) references pktable on delete cascade; alter table fktable - alter constraint "fkdi2" deferrable initially immediate; + alter constraint fkdi2 deferrable initially immediate; select conname, @@ -966,10 +853,7 @@ select tgdeferrable, tginitdeferred from - pg_trigger - inner join - pg_constraint as con - on con.oid = tgconstraint + pg_trigger inner join pg_constraint as con on con.oid = tgconstraint where tgrelid = cast('pktable' as regclass) order by 1, @@ -983,10 +867,7 @@ select tgdeferrable, tginitdeferred from - pg_trigger - inner join - pg_constraint as con - on con.oid = tgconstraint + pg_trigger inner join pg_constraint as con on con.oid = tgconstraint where tgrelid = cast('fktable' as regclass) order by 1, @@ -996,7 +877,7 @@ order by 1, create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" check (test > 3); + add constraint atacc_test1 check (test > 3); insert into atacc1 (test) values (2); @@ -1009,7 +890,7 @@ create table atacc1 (test int); insert into atacc1 (test) values (2); alter table atacc1 - add constraint "atacc_test1" check (test > 3); + add constraint atacc_test1 check (test > 3); insert into atacc1 (test) values (4); @@ -1018,7 +899,7 @@ drop table atacc1; create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" check (test1 > 3); + add constraint atacc_test1 check (test1 > 3); drop table atacc1; @@ -1029,7 +910,7 @@ create table atacc1 ( ); alter table atacc1 - add constraint "atacc_test1" check (test + test2 < test3 * 4); + add constraint atacc_test1 check (test + test2 < test3 * 4); insert into atacc1 (test, test2, test3) values (4, 4, 2); @@ -1054,11 +935,10 @@ create table atacc1 (test int); create table atacc2 (test2 int); create table atacc3 (test3 int) -inherits (atacc1, -atacc2); +inherits (atacc1, atacc2); alter table atacc2 - add constraint "foo" check (test2 > 0); + add constraint foo check (test2 > 0); insert into atacc2 (test2) values (-3); @@ -1079,8 +959,7 @@ create table atacc1 (test int); create table atacc2 (test2 int); create table atacc3 (test3 int) -inherits (atacc1, -atacc2); +inherits (atacc1, atacc2); alter table atacc3 no inherit atacc2; @@ -1093,7 +972,7 @@ insert into atacc3 (test2) values (3); select test2 from atacc2; alter table atacc2 - add constraint "foo" check (test2 > 0); + add constraint foo check (test2 > 0); alter table atacc3 inherit atacc2; @@ -1104,7 +983,7 @@ alter table atacc3 inherit atacc2; alter table atacc3 - add column test2 boolean; + add column test2 bool; alter table atacc3 inherit atacc2; @@ -1118,7 +997,7 @@ alter table atacc3 update atacc3 set test2 = 4 where test2 is null; alter table atacc3 - add constraint "foo" check (test2 > 0); + add constraint foo check (test2 > 0); alter table atacc3 inherit atacc2; @@ -1144,7 +1023,7 @@ create table atacc2 (test2 int) inherits (atacc1); alter table atacc1 - add constraint "foo" check (test > 0) no inherit; + add constraint foo check (test > 0) no inherit; insert into atacc2 (test) values (-3); @@ -1153,7 +1032,7 @@ insert into atacc1 (test) values (-3); insert into atacc1 (test) values (3); alter table atacc2 - add constraint "foo" check (test > 0) no inherit; + add constraint foo check (test > 0) no inherit; drop table atacc2; @@ -1162,7 +1041,7 @@ drop table atacc1; create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" unique (test); + add constraint atacc_test1 unique (test); insert into atacc1 (test) values (2); @@ -1182,7 +1061,7 @@ insert into atacc1 (test) values (2); insert into atacc1 (test) values (2); alter table atacc1 - add constraint "atacc_test1" unique (test); + add constraint atacc_test1 unique (test); insert into atacc1 (test) values (3); @@ -1191,7 +1070,7 @@ drop table atacc1; create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" unique (test1); + add constraint atacc_test1 unique (test1); drop table atacc1; @@ -1201,7 +1080,7 @@ create table atacc1 ( ); alter table atacc1 - add constraint "atacc_test1" unique (test, test2); + add constraint atacc_test1 unique (test, test2); insert into atacc1 (test, test2) values (4, 4); @@ -1236,7 +1115,7 @@ create table atacc1 ( ); alter table atacc1 - add constraint "atacc_test1" primary key (test); + add constraint atacc_test1 primary key (test); insert into atacc1 (test) values (2); @@ -1247,13 +1126,13 @@ insert into atacc1 (test) values (4); insert into atacc1 (test) values (null); alter table atacc1 - add constraint "atacc_oid1" primary key (id); + add constraint atacc_oid1 primary key (id); alter table atacc1 drop constraint atacc_test1; alter table atacc1 - add constraint "atacc_oid1" primary key (id); + add constraint atacc_oid1 primary key (id); drop table atacc1; @@ -1264,7 +1143,7 @@ insert into atacc1 (test) values (2); insert into atacc1 (test) values (2); alter table atacc1 - add constraint "atacc_test1" primary key (test); + add constraint atacc_test1 primary key (test); insert into atacc1 (test) values (3); @@ -1275,7 +1154,7 @@ create table atacc1 (test int); insert into atacc1 (test) values (null); alter table atacc1 - add constraint "atacc_test1" primary key (test); + add constraint atacc_test1 primary key (test); insert into atacc1 (test) values (3); @@ -1284,7 +1163,7 @@ drop table atacc1; create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" primary key (test1); + add constraint atacc_test1 primary key (test1); drop table atacc1; @@ -1305,7 +1184,7 @@ create table atacc1 (a int); insert into atacc1 values (1); alter table atacc1 - add column b double precision not null default random(), + add column b float8 not null default random(), add primary key (a); drop table atacc1; @@ -1313,11 +1192,7 @@ drop table atacc1; create table atacc1 (a int primary key); alter table atacc1 - add constraint "atacc1_fkey" - foreign key - (a) - references atacc1 (a) - not valid; + add constraint atacc1_fkey foreign key (a) references atacc1 (a) not valid; alter table atacc1 validate constraint atacc1_fkey, @@ -1333,7 +1208,7 @@ create table atacc1 ( insert into atacc1 values (1, 1); alter table atacc1 - add constraint "atacc1_chk" check (b = 1) not valid; + add constraint atacc1_chk check (b = 1) not valid; alter table atacc1 validate constraint atacc1_chk, @@ -1349,7 +1224,7 @@ create table atacc1 ( insert into atacc1 values (1, 2); alter table atacc1 - add constraint "atacc1_chk" check (b = 1) not valid; + add constraint atacc1_chk check (b = 1) not valid; alter table atacc1 validate constraint atacc1_chk, @@ -1363,10 +1238,10 @@ create table atacc1 ( ); alter table atacc1 - add constraint "atacc_test1" primary key (test, test2); + add constraint atacc_test1 primary key (test, test2); alter table atacc1 - add constraint "atacc_test2" primary key (test); + add constraint atacc_test2 primary key (test); insert into atacc1 (test, test2) values (4, 4); @@ -1415,7 +1290,7 @@ alter table non_existent create table atacc1 (test int not null); alter table atacc1 - add constraint "atacc1_pkey" primary key (test); + add constraint atacc1_pkey primary key (test); alter table atacc1 alter column test drop not null; @@ -1463,7 +1338,7 @@ create table atacc1 ( insert into atacc1 values (null, 1); alter table atacc1 - add constraint "atacc1_constr_or" check (test_a is not null or test_b < 10); + add constraint atacc1_constr_or check (test_a is not null or test_b < 10); alter table atacc1 alter column test_a set not null; @@ -1472,7 +1347,7 @@ alter table atacc1 drop constraint atacc1_constr_or; alter table atacc1 - add constraint "atacc1_constr_invalid" check (test_a is not null) not valid; + add constraint atacc1_constr_invalid check (test_a is not null) not valid; alter table atacc1 alter column test_a set not null; @@ -1483,7 +1358,7 @@ alter table atacc1 update atacc1 set test_a = 1; alter table atacc1 - add constraint "atacc1_constr_a_valid" check (test_a is not null); + add constraint atacc1_constr_a_valid check (test_a is not null); alter table atacc1 alter column test_a set not null; @@ -1514,7 +1389,7 @@ alter table atacc1 alter column test_b drop not null; alter table atacc1 - add constraint "atacc1_constr_b_valid" check (test_b is not null); + add constraint atacc1_constr_b_valid check (test_b is not null); alter table atacc1 alter column test_b set not null, @@ -1526,7 +1401,7 @@ create table atnnparted ( id int, col1 int ) -partition by LIST(id); +partition by list(id); create table atnnpart1 ( col1 int, @@ -1577,7 +1452,7 @@ drop table child; drop table parent; create table def_test ( - c1 int default 5, + c1 int4 default 5, c2 text default 'initial_default' ); @@ -1644,10 +1519,10 @@ alter table nosuchtable drop column bar; create table atacc1 ( - a int not null, - b int, - c int not null, - d int + a int4 not null, + b int4, + c int4 not null, + d int4 ); insert into atacc1 values (1, 2, 3, 4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_table_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_table_80.snap index 6dc935e6b..8453406d1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_table_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_table_80.snap @@ -10,7 +10,7 @@ reset client_min_messages; create user regress_alter_table_user1; -create table attmp (initial int); +create table attmp (initial int4); comment on table attmp_wrong is 'table comment'; @@ -22,7 +22,7 @@ alter table attmp add column xmin int; alter table attmp - add column a int default 3; + add column a int4 default 3; alter table attmp add column b name; @@ -31,13 +31,13 @@ alter table attmp add column c text; alter table attmp - add column d double precision; + add column d float8; alter table attmp - add column e real; + add column e float4; alter table attmp - add column f smallint; + add column f int2; alter table attmp add column g polygon; @@ -46,7 +46,7 @@ alter table attmp add column i char(1); alter table attmp - add column k int; + add column k int4; alter table attmp add column l tid; @@ -79,13 +79,13 @@ alter table attmp add column w interval; alter table attmp - add column x double precision[]; + add column x float8[]; alter table attmp - add column y real[]; + add column y float4[]; alter table attmp - add column z smallint[]; + add column z int2[]; insert into attmp ( a, @@ -141,10 +141,10 @@ select * from attmp; drop table attmp; -create table attmp (initial int); +create table attmp (initial int4); alter table attmp - add column a int; + add column a int4; alter table attmp add column b name; @@ -153,13 +153,13 @@ alter table attmp add column c text; alter table attmp - add column d double precision; + add column d float8; alter table attmp - add column e real; + add column e float4; alter table attmp - add column f smallint; + add column f int2; alter table attmp add column g polygon; @@ -168,7 +168,7 @@ alter table attmp add column i char(1); alter table attmp - add column k int; + add column k int4; alter table attmp add column l tid; @@ -201,13 +201,13 @@ alter table attmp add column w interval; alter table attmp - add column x double precision[]; + add column x float8[]; alter table attmp - add column y real[]; + add column y float4[]; alter table attmp - add column z smallint[]; + add column z int2[]; insert into attmp ( a, @@ -261,7 +261,7 @@ values select * from attmp; -create index "attmp_idx" on attmp using btree (a, (d + e), b); +create index attmp_idx on attmp using btree (a, (d + e), b); alter index attmp_idx alter column 1 set statistics 1000; @@ -373,22 +373,14 @@ reset role; create table alter_idx_rename_test (a int); -create index "alter_idx_rename_test_idx" -on alter_idx_rename_test -using btree -( - a -); +create index alter_idx_rename_test_idx on alter_idx_rename_test using btree (a); create table alter_idx_rename_test_parted (a int) -partition by LIST(a); +partition by list(a); -create index "alter_idx_rename_test_parted_idx" -on alter_idx_rename_test_parted -using btree -( - a -); +create index alter_idx_rename_test_parted_idx + on alter_idx_rename_test_parted + using btree (a); begin; @@ -483,7 +475,7 @@ alter table stud_emp rename to pg_toast_stud_emp; alter table pg_toast_stud_emp rename to stud_emp; alter table onek - add constraint "onek_unique1_constraint" unique (unique1); + add constraint onek_unique1_constraint unique (unique1); alter index onek_unique1_constraint rename to onek_unique1_constraint_foo; @@ -491,7 +483,7 @@ alter table onek drop constraint onek_unique1_constraint_foo; alter table onek - add constraint "onek_check_constraint" check (unique1 >= 0); + add constraint onek_check_constraint check (unique1 >= 0); alter table onek rename constraint onek_check_constraint @@ -501,7 +493,7 @@ alter table onek drop constraint onek_check_constraint_foo; alter table onek - add constraint "onek_unique1_constraint" unique (unique1); + add constraint onek_unique1_constraint unique (unique1); drop index onek_unique1_constraint; @@ -515,13 +507,13 @@ alter table onek drop constraint onek_unique1_constraint_foo; create table constraint_rename_test ( - a int constraint "con1" check (a > 0), + a int constraint con1 check (a > 0), b int, c int ); create table constraint_rename_test2 ( - a int constraint "con1" check (a > 0), + a int constraint con1 check (a > 0), d int ) inherits (constraint_rename_test); @@ -533,14 +525,14 @@ alter table only constraint_rename_test rename constraint con1 to con1foo; alter table constraint_rename_test rename constraint con1 to con1foo; alter table constraint_rename_test - add constraint "con2" check (b > 0) no inherit; + add constraint con2 check (b > 0) no inherit; alter table only constraint_rename_test rename constraint con2 to con2foo; alter table constraint_rename_test rename constraint con2foo to con2bar; alter table constraint_rename_test - add constraint "con3" primary key (a); + add constraint con3 primary key (a); alter table constraint_rename_test rename constraint con3 to con3foo; @@ -551,11 +543,11 @@ drop table constraint_rename_test; alter table if exists constraint_not_exist rename constraint con3 to con3foo; alter table if exists constraint_rename_test - add constraint "con4" unique (a); + add constraint con4 unique (a); create table constraint_rename_cache ( a int, - constraint "chk_a" check (a > 0), + constraint chk_a check (a > 0), primary key (a) ); @@ -606,34 +598,18 @@ insert into attmp3 values (1, 20); insert into attmp3 values (5, 50); alter table attmp3 - add constraint "attmpconstr" - foreign key - (c) - references attmp2 - match full; + add constraint attmpconstr foreign key (c) references attmp2 match full; alter table attmp3 - add constraint "attmpconstr" - foreign key - (a) - references attmp2 (b) - match full; + add constraint attmpconstr foreign key (a) references attmp2 (b) match full; alter table attmp3 - add constraint "attmpconstr" - foreign key - (a) - references attmp2 - match full; + add constraint attmpconstr foreign key (a) references attmp2 match full; delete from attmp3 where a = 5; alter table attmp3 - add constraint "attmpconstr" - foreign key - (a) - references attmp2 - match full; + add constraint attmpconstr foreign key (a) references attmp2 match full; alter table attmp3 drop constraint attmpconstr; @@ -641,12 +617,10 @@ alter table attmp3 insert into attmp3 values (5, 50); alter table attmp3 - add constraint "attmpconstr" - foreign key - (a) - references attmp2 - match full - not valid; + add constraint attmpconstr foreign key (a) + references attmp2 + match full + not valid; alter table attmp3 validate constraint attmpconstr; @@ -660,10 +634,10 @@ alter table attmp3 validate constraint attmpconstr; alter table attmp3 - add constraint "b_greater_than_ten" check (b > 10); + add constraint b_greater_than_ten check (b > 10); alter table attmp3 - add constraint "b_greater_than_ten" check (b > 10) not valid; + add constraint b_greater_than_ten check (b > 10) not valid; alter table attmp3 validate constraint b_greater_than_ten; @@ -690,7 +664,7 @@ inherits (attmp3); insert into attmp6 values (6, 30), (7, 16); alter table attmp3 - add constraint "b_le_20" check (b <= 20) not valid; + add constraint b_le_20 check (b <= 20) not valid; alter table attmp3 validate constraint b_le_20; @@ -705,17 +679,15 @@ returns int language plpgsql immutable strict -as $function$ -BEGIN RAISE NOTICE 'boo: %', $1; RETURN $1; END; -$function$; +as $$ BEGIN RAISE NOTICE 'boo: %', $1; RETURN $1; END; $$; insert into attmp7 values (8, 18); alter table attmp7 - add constraint "identity" check (b = boo(b)); + add constraint identity check (b = boo(b)); alter table attmp3 - add constraint "identity" check (b = boo(b)) not valid; + add constraint identity check (b = boo(b)) not valid; alter table attmp3 validate constraint identity; @@ -730,7 +702,7 @@ insert into parent_noinh_convalid values (1); insert into child_noinh_convalid values (1); alter table parent_noinh_convalid - add constraint "check_a_is_2" check (a = 2) no inherit not valid; + add constraint check_a_is_2 check (a = 2) no inherit not valid; alter table parent_noinh_convalid validate constraint check_a_is_2; @@ -745,19 +717,13 @@ select from pg_constraint where - conrelid = - cast('parent_noinh_convalid' - as regclass) and + conrelid = cast('parent_noinh_convalid' as regclass) and conname = 'check_a_is_2'; drop table parent_noinh_convalid, child_noinh_convalid; alter table attmp5 - add constraint "attmpconstr" - foreign key - (a) - references attmp4 (a) - match full; + add constraint attmpconstr foreign key (a) references attmp4 (a) match full; drop table attmp7; @@ -797,9 +763,7 @@ alter table nv_child_2011 select * from nv_parent where d between '2011-08-01' and '2011-08-31'; create table nv_child_2009 ( - check (d - between cast('2009-01-01' as date) - and cast('2009-12-31' as date)) + check (d between cast('2009-01-01' as date) and cast('2009-12-31' as date)) ) inherits (nv_parent); @@ -808,18 +772,14 @@ select from nv_parent where - d - between cast('2011-08-01' as date) - and cast('2011-08-31' as date); + d between cast('2011-08-01' as date) and cast('2011-08-31' as date); select * from nv_parent where - d - between cast('2009-08-01' as date) - and cast('2009-08-31' as date); + d between cast('2009-08-01' as date) and cast('2009-08-31' as date); alter table nv_child_2011 validate constraint nv_child_2011_d_check; @@ -829,9 +789,7 @@ select from nv_parent where - d - between cast('2009-08-01' as date) - and cast('2009-08-31' as date); + d between cast('2009-08-01' as date) and cast('2009-08-31' as date); alter table nv_parent add check (d @@ -848,13 +806,11 @@ alter table fktable add foreign key (ftest1) references pktable; alter table fktable - add foreign key - (ftest1) - references pktable (ptest1); + add foreign key (ftest1) references pktable (ptest1); drop table fktable; -create temporary table fktable (ftest1 bigint); +create temporary table fktable (ftest1 int8); alter table fktable add foreign key (ftest1) references pktable; @@ -903,10 +859,7 @@ create temporary table fktable ( ); alter table fktable - add foreign key - (ftest1, - ftest2) - references pktable; + add foreign key (ftest1, ftest2) references pktable; drop table fktable; @@ -916,11 +869,7 @@ create temporary table fktable ( ); alter table fktable - add foreign key - (ftest1, - ftest2) - references pktable (ptest1, - ptest2); + add foreign key (ftest1, ftest2) references pktable (ptest1, ptest2); drop table fktable; @@ -930,18 +879,10 @@ create temporary table fktable ( ); alter table fktable - add foreign key - (ftest1, - ftest2) - references pktable (ptest2, - ptest1); + add foreign key (ftest1, ftest2) references pktable (ptest2, ptest1); alter table fktable - add foreign key - (ftest2, - ftest1) - references pktable (ptest1, - ptest2); + add foreign key (ftest2, ftest1) references pktable (ptest1, ptest2); drop table fktable; @@ -952,58 +893,44 @@ create temporary table pktable (ptest1 int primary key); create temporary table fktable (ftest1 int); alter table fktable - add constraint "fknd" - foreign key - (ftest1) - references pktable - on DELETE cascade; + add constraint fknd foreign key (ftest1) references pktable on delete cascade; alter table fktable - add constraint "fkdd" - foreign key - (ftest1) - references pktable - on DELETE cascade - deferrable initially deferred; + add constraint fkdd foreign key (ftest1) + references pktable + on delete cascade + deferrable initially deferred; alter table fktable - add constraint "fkdi" - foreign key - (ftest1) - references pktable - on DELETE cascade - deferrable initially immediate; + add constraint fkdi foreign key (ftest1) + references pktable + on delete cascade + deferrable initially immediate; alter table fktable - add constraint "fknd2" - foreign key - (ftest1) - references pktable - on DELETE cascade - deferrable initially deferred; + add constraint fknd2 foreign key (ftest1) + references pktable + on delete cascade + deferrable initially deferred; alter table fktable - alter constraint "fknd2" not deferrable initially immediate; + alter constraint fknd2 not deferrable initially immediate; alter table fktable - add constraint "fkdd2" - foreign key - (ftest1) - references pktable - on DELETE cascade; + add constraint fkdd2 foreign key (ftest1) + references pktable + on delete cascade; alter table fktable - alter constraint "fkdd2" deferrable initially deferred; + alter constraint fkdd2 deferrable initially deferred; alter table fktable - add constraint "fkdi2" - foreign key - (ftest1) - references pktable - on DELETE cascade; + add constraint fkdi2 foreign key (ftest1) + references pktable + on delete cascade; alter table fktable - alter constraint "fkdi2" deferrable initially immediate; + alter constraint fkdi2 deferrable initially immediate; select conname, @@ -1012,10 +939,7 @@ select tgdeferrable, tginitdeferred from - pg_trigger - inner join - pg_constraint as con - on con.oid = tgconstraint + pg_trigger inner join pg_constraint as con on con.oid = tgconstraint where tgrelid = cast('pktable' as regclass) order by 1, @@ -1029,10 +953,7 @@ select tgdeferrable, tginitdeferred from - pg_trigger - inner join - pg_constraint as con - on con.oid = tgconstraint + pg_trigger inner join pg_constraint as con on con.oid = tgconstraint where tgrelid = cast('fktable' as regclass) order by 1, @@ -1042,7 +963,7 @@ order by 1, create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" check (test > 3); + add constraint atacc_test1 check (test > 3); insert into atacc1 (test) values (2); @@ -1055,7 +976,7 @@ create table atacc1 (test int); insert into atacc1 (test) values (2); alter table atacc1 - add constraint "atacc_test1" check (test > 3); + add constraint atacc_test1 check (test > 3); insert into atacc1 (test) values (4); @@ -1064,7 +985,7 @@ drop table atacc1; create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" check (test1 > 3); + add constraint atacc_test1 check (test1 > 3); drop table atacc1; @@ -1075,7 +996,7 @@ create table atacc1 ( ); alter table atacc1 - add constraint "atacc_test1" check (test + test2 < test3 * 4); + add constraint atacc_test1 check (test + test2 < test3 * 4); insert into atacc1 (test, test2, test3) values (4, 4, 2); @@ -1100,11 +1021,10 @@ create table atacc1 (test int); create table atacc2 (test2 int); create table atacc3 (test3 int) -inherits (atacc1, -atacc2); +inherits (atacc1, atacc2); alter table atacc2 - add constraint "foo" check (test2 > 0); + add constraint foo check (test2 > 0); insert into atacc2 (test2) values (-3); @@ -1125,8 +1045,7 @@ create table atacc1 (test int); create table atacc2 (test2 int); create table atacc3 (test3 int) -inherits (atacc1, -atacc2); +inherits (atacc1, atacc2); alter table atacc3 no inherit atacc2; @@ -1139,7 +1058,7 @@ insert into atacc3 (test2) values (3); select test2 from atacc2; alter table atacc2 - add constraint "foo" check (test2 > 0); + add constraint foo check (test2 > 0); alter table atacc3 inherit atacc2; @@ -1150,7 +1069,7 @@ alter table atacc3 inherit atacc2; alter table atacc3 - add column test2 boolean; + add column test2 bool; alter table atacc3 inherit atacc2; @@ -1164,7 +1083,7 @@ alter table atacc3 update atacc3 set test2 = 4 where test2 is null; alter table atacc3 - add constraint "foo" check (test2 > 0); + add constraint foo check (test2 > 0); alter table atacc3 inherit atacc2; @@ -1190,7 +1109,7 @@ create table atacc2 (test2 int) inherits (atacc1); alter table atacc1 - add constraint "foo" check (test > 0) no inherit; + add constraint foo check (test > 0) no inherit; insert into atacc2 (test) values (-3); @@ -1199,7 +1118,7 @@ insert into atacc1 (test) values (-3); insert into atacc1 (test) values (3); alter table atacc2 - add constraint "foo" check (test > 0) no inherit; + add constraint foo check (test > 0) no inherit; drop table atacc2; @@ -1208,7 +1127,7 @@ drop table atacc1; create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" unique (test); + add constraint atacc_test1 unique (test); insert into atacc1 (test) values (2); @@ -1228,7 +1147,7 @@ insert into atacc1 (test) values (2); insert into atacc1 (test) values (2); alter table atacc1 - add constraint "atacc_test1" unique (test); + add constraint atacc_test1 unique (test); insert into atacc1 (test) values (3); @@ -1237,7 +1156,7 @@ drop table atacc1; create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" unique (test1); + add constraint atacc_test1 unique (test1); drop table atacc1; @@ -1247,8 +1166,7 @@ create table atacc1 ( ); alter table atacc1 - add constraint "atacc_test1" unique (test, - test2); + add constraint atacc_test1 unique (test, test2); insert into atacc1 (test, test2) values (4, 4); @@ -1283,7 +1201,7 @@ create table atacc1 ( ); alter table atacc1 - add constraint "atacc_test1" primary key (test); + add constraint atacc_test1 primary key (test); insert into atacc1 (test) values (2); @@ -1294,13 +1212,13 @@ insert into atacc1 (test) values (4); insert into atacc1 (test) values (null); alter table atacc1 - add constraint "atacc_oid1" primary key (id); + add constraint atacc_oid1 primary key (id); alter table atacc1 drop constraint atacc_test1; alter table atacc1 - add constraint "atacc_oid1" primary key (id); + add constraint atacc_oid1 primary key (id); drop table atacc1; @@ -1311,7 +1229,7 @@ insert into atacc1 (test) values (2); insert into atacc1 (test) values (2); alter table atacc1 - add constraint "atacc_test1" primary key (test); + add constraint atacc_test1 primary key (test); insert into atacc1 (test) values (3); @@ -1322,7 +1240,7 @@ create table atacc1 (test int); insert into atacc1 (test) values (null); alter table atacc1 - add constraint "atacc_test1" primary key (test); + add constraint atacc_test1 primary key (test); insert into atacc1 (test) values (3); @@ -1331,7 +1249,7 @@ drop table atacc1; create table atacc1 (test int); alter table atacc1 - add constraint "atacc_test1" primary key (test1); + add constraint atacc_test1 primary key (test1); drop table atacc1; @@ -1352,9 +1270,7 @@ create table atacc1 (a int); insert into atacc1 values (1); alter table atacc1 - add column b double precision - not null - default random(), + add column b float8 not null default random(), add primary key (a); drop table atacc1; @@ -1362,11 +1278,7 @@ drop table atacc1; create table atacc1 (a int primary key); alter table atacc1 - add constraint "atacc1_fkey" - foreign key - (a) - references atacc1 (a) - not valid; + add constraint atacc1_fkey foreign key (a) references atacc1 (a) not valid; alter table atacc1 validate constraint atacc1_fkey, @@ -1382,7 +1294,7 @@ create table atacc1 ( insert into atacc1 values (1, 1); alter table atacc1 - add constraint "atacc1_chk" check (b = 1) not valid; + add constraint atacc1_chk check (b = 1) not valid; alter table atacc1 validate constraint atacc1_chk, @@ -1398,7 +1310,7 @@ create table atacc1 ( insert into atacc1 values (1, 2); alter table atacc1 - add constraint "atacc1_chk" check (b = 1) not valid; + add constraint atacc1_chk check (b = 1) not valid; alter table atacc1 validate constraint atacc1_chk, @@ -1412,11 +1324,10 @@ create table atacc1 ( ); alter table atacc1 - add constraint "atacc_test1" primary key (test, - test2); + add constraint atacc_test1 primary key (test, test2); alter table atacc1 - add constraint "atacc_test2" primary key (test); + add constraint atacc_test2 primary key (test); insert into atacc1 (test, test2) values (4, 4); @@ -1465,7 +1376,7 @@ alter table non_existent create table atacc1 (test int not null); alter table atacc1 - add constraint "atacc1_pkey" primary key (test); + add constraint atacc1_pkey primary key (test); alter table atacc1 alter column test drop not null; @@ -1513,7 +1424,7 @@ create table atacc1 ( insert into atacc1 values (null, 1); alter table atacc1 - add constraint "atacc1_constr_or" check (test_a is not null or test_b < 10); + add constraint atacc1_constr_or check (test_a is not null or test_b < 10); alter table atacc1 alter column test_a set not null; @@ -1522,7 +1433,7 @@ alter table atacc1 drop constraint atacc1_constr_or; alter table atacc1 - add constraint "atacc1_constr_invalid" check (test_a is not null) not valid; + add constraint atacc1_constr_invalid check (test_a is not null) not valid; alter table atacc1 alter column test_a set not null; @@ -1533,7 +1444,7 @@ alter table atacc1 update atacc1 set test_a = 1; alter table atacc1 - add constraint "atacc1_constr_a_valid" check (test_a is not null); + add constraint atacc1_constr_a_valid check (test_a is not null); alter table atacc1 alter column test_a set not null; @@ -1564,7 +1475,7 @@ alter table atacc1 alter column test_b drop not null; alter table atacc1 - add constraint "atacc1_constr_b_valid" check (test_b is not null); + add constraint atacc1_constr_b_valid check (test_b is not null); alter table atacc1 alter column test_b set not null, @@ -1576,7 +1487,7 @@ create table atnnparted ( id int, col1 int ) -partition by LIST(id); +partition by list(id); create table atnnpart1 ( col1 int, @@ -1627,7 +1538,7 @@ drop table child; drop table parent; create table def_test ( - c1 int default 5, + c1 int4 default 5, c2 text default 'initial_default' ); @@ -1694,10 +1605,10 @@ alter table nosuchtable drop column bar; create table atacc1 ( - a int not null, - b int, - c int not null, - d int + a int4 not null, + b int4, + c int4 not null, + d int4 ); insert into atacc1 values (1, 2, 3, 4); @@ -1766,20 +1677,10 @@ insert into atacc1 ("........pg.dropped.1........") values (10); insert into atacc1 ("........pg.dropped.1........") values (default); -insert into atacc1 ( - "........pg.dropped.1........", - b, - c, - d -) +insert into atacc1 ("........pg.dropped.1........", b, c, d) values (10, 11, 12, 13); -insert into atacc1 ( - "........pg.dropped.1........", - b, - c, - d -) +insert into atacc1 ("........pg.dropped.1........", b, c, d) values (default, 11, 12, 13); delete from atacc1 where a = 3; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__amutils_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__amutils_100.snap index 8afc6cfcd..974df6362 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__amutils_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__amutils_100.snap @@ -6,17 +6,8 @@ snapshot_kind: text select prop, pg_indexam_has_property(a.oid, prop) as "AM", - pg_index_has_property( - cast('onek_hundred' as regclass), - prop - ) - as "Index", - pg_index_column_has_property( - cast('onek_hundred' as regclass), - 1, - prop - ) - as "Column" + pg_index_has_property(cast('onek_hundred' as regclass), prop) as "Index", + pg_index_column_has_property(cast('onek_hundred' as regclass), 1, prop) as "Column" from pg_am as a, unnest( @@ -50,17 +41,8 @@ order by ord; select prop, pg_indexam_has_property(a.oid, prop) as "AM", - pg_index_has_property( - cast('gcircleind' as regclass), - prop - ) - as "Index", - pg_index_column_has_property( - cast('gcircleind' as regclass), - 1, - prop - ) - as "Column" + pg_index_has_property(cast('gcircleind' as regclass), prop) as "Index", + pg_index_column_has_property(cast('gcircleind' as regclass), 1, prop) as "Column" from pg_am as a, unnest( @@ -93,48 +75,13 @@ order by ord; select prop, - pg_index_column_has_property( - cast('onek_hundred' as regclass), - 1, - prop - ) - as btree, - pg_index_column_has_property( - cast('hash_i4_index' as regclass), - 1, - prop - ) - as hash, - pg_index_column_has_property( - cast('gcircleind' as regclass), - 1, - prop - ) - as gist, - pg_index_column_has_property( - cast('sp_radix_ind' as regclass), - 1, - prop - ) - as spgist_radix, - pg_index_column_has_property( - cast('sp_quad_ind' as regclass), - 1, - prop - ) - as spgist_quad, - pg_index_column_has_property( - cast('botharrayidx' as regclass), - 1, - prop - ) - as gin, - pg_index_column_has_property( - cast('brinidx' as regclass), - 1, - prop - ) - as brin + pg_index_column_has_property(cast('onek_hundred' as regclass), 1, prop) as btree, + pg_index_column_has_property(cast('hash_i4_index' as regclass), 1, prop) as hash, + pg_index_column_has_property(cast('gcircleind' as regclass), 1, prop) as gist, + pg_index_column_has_property(cast('sp_radix_ind' as regclass), 1, prop) as spgist_radix, + pg_index_column_has_property(cast('sp_quad_ind' as regclass), 1, prop) as spgist_quad, + pg_index_column_has_property(cast('botharrayidx' as regclass), 1, prop) as gin, + pg_index_column_has_property(cast('brinidx' as regclass), 1, prop) as brin from unnest( cast(array['asc', @@ -155,44 +102,15 @@ order by ord; select prop, - pg_index_has_property( - cast('onek_hundred' as regclass), - prop - ) - as btree, - pg_index_has_property( - cast('hash_i4_index' as regclass), - prop - ) - as hash, - pg_index_has_property( - cast('gcircleind' as regclass), - prop - ) - as gist, - pg_index_has_property( - cast('sp_radix_ind' as regclass), - prop - ) - as spgist, - pg_index_has_property( - cast('botharrayidx' as regclass), - prop - ) - as gin, - pg_index_has_property( - cast('brinidx' as regclass), - prop - ) - as brin + pg_index_has_property(cast('onek_hundred' as regclass), prop) as btree, + pg_index_has_property(cast('hash_i4_index' as regclass), prop) as hash, + pg_index_has_property(cast('gcircleind' as regclass), prop) as gist, + pg_index_has_property(cast('sp_radix_ind' as regclass), prop) as spgist, + pg_index_has_property(cast('botharrayidx' as regclass), prop) as gin, + pg_index_has_property(cast('brinidx' as regclass), prop) as brin from unnest( - cast(array['clusterable', - 'index_scan', - 'bitmap_scan', - 'backward_scan', - 'bogus'] - as text[]) + cast(array['clusterable', 'index_scan', 'bitmap_scan', 'backward_scan', 'bogus'] as text[]) ) with ordinality as u (prop, ord) @@ -205,12 +123,7 @@ select from pg_am as a, unnest( - cast(array['can_order', - 'can_unique', - 'can_multi_col', - 'can_exclude', - 'can_include', - 'bogus'] + cast(array['can_order', 'can_unique', 'can_multi_col', 'can_exclude', 'can_include', 'bogus'] as text[]) ) with ordinality @@ -227,7 +140,7 @@ create temporary table foo ( f4 int ); -create index "fooindex" on foo using btree (f1 desc, f2 asc, f3 nulls first, f4 nulls last); +create index fooindex on foo using btree (f1 desc, f2 asc, f3 nulls first, f4 nulls last); select col, @@ -249,7 +162,7 @@ from order by col, idx; -create index "foocover" on foo using btree (f1) include (f2, f3); +create index foocover on foo using btree (f1) include (f2, f3); select col, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__amutils_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__amutils_80.snap index 7099c1846..0e3e21aff 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__amutils_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__amutils_80.snap @@ -5,18 +5,9 @@ snapshot_kind: text --- select prop, - pg_indexam_has_property(a.oid, prop) - as "AM", - pg_index_has_property( - cast('onek_hundred' as regclass), - prop - ) - as "Index", - pg_index_column_has_property( - cast('onek_hundred' as regclass), - 1, - prop - ) + pg_indexam_has_property(a.oid, prop) as "AM", + pg_index_has_property(cast('onek_hundred' as regclass), prop) as "Index", + pg_index_column_has_property(cast('onek_hundred' as regclass), 1, prop) as "Column" from pg_am as a, @@ -50,18 +41,9 @@ order by ord; select prop, - pg_indexam_has_property(a.oid, prop) - as "AM", - pg_index_has_property( - cast('gcircleind' as regclass), - prop - ) - as "Index", - pg_index_column_has_property( - cast('gcircleind' as regclass), - 1, - prop - ) + pg_indexam_has_property(a.oid, prop) as "AM", + pg_index_has_property(cast('gcircleind' as regclass), prop) as "Index", + pg_index_column_has_property(cast('gcircleind' as regclass), 1, prop) as "Column" from pg_am as a, @@ -95,48 +77,18 @@ order by ord; select prop, - pg_index_column_has_property( - cast('onek_hundred' as regclass), - 1, - prop - ) + pg_index_column_has_property(cast('onek_hundred' as regclass), 1, prop) as btree, - pg_index_column_has_property( - cast('hash_i4_index' as regclass), - 1, - prop - ) + pg_index_column_has_property(cast('hash_i4_index' as regclass), 1, prop) as hash, - pg_index_column_has_property( - cast('gcircleind' as regclass), - 1, - prop - ) - as gist, - pg_index_column_has_property( - cast('sp_radix_ind' as regclass), - 1, - prop - ) + pg_index_column_has_property(cast('gcircleind' as regclass), 1, prop) as gist, + pg_index_column_has_property(cast('sp_radix_ind' as regclass), 1, prop) as spgist_radix, - pg_index_column_has_property( - cast('sp_quad_ind' as regclass), - 1, - prop - ) + pg_index_column_has_property(cast('sp_quad_ind' as regclass), 1, prop) as spgist_quad, - pg_index_column_has_property( - cast('botharrayidx' as regclass), - 1, - prop - ) + pg_index_column_has_property(cast('botharrayidx' as regclass), 1, prop) as gin, - pg_index_column_has_property( - cast('brinidx' as regclass), - 1, - prop - ) - as brin + pg_index_column_has_property(cast('brinidx' as regclass), 1, prop) as brin from unnest( cast(array['asc', @@ -157,36 +109,12 @@ order by ord; select prop, - pg_index_has_property( - cast('onek_hundred' as regclass), - prop - ) - as btree, - pg_index_has_property( - cast('hash_i4_index' as regclass), - prop - ) - as hash, - pg_index_has_property( - cast('gcircleind' as regclass), - prop - ) - as gist, - pg_index_has_property( - cast('sp_radix_ind' as regclass), - prop - ) - as spgist, - pg_index_has_property( - cast('botharrayidx' as regclass), - prop - ) - as gin, - pg_index_has_property( - cast('brinidx' as regclass), - prop - ) - as brin + pg_index_has_property(cast('onek_hundred' as regclass), prop) as btree, + pg_index_has_property(cast('hash_i4_index' as regclass), prop) as hash, + pg_index_has_property(cast('gcircleind' as regclass), prop) as gist, + pg_index_has_property(cast('sp_radix_ind' as regclass), prop) as spgist, + pg_index_has_property(cast('botharrayidx' as regclass), prop) as gin, + pg_index_has_property(cast('brinidx' as regclass), prop) as brin from unnest( cast(array['clusterable', @@ -203,8 +131,7 @@ order by ord; select amname, prop, - pg_indexam_has_property(a.oid, prop) - as p + pg_indexam_has_property(a.oid, prop) as p from pg_am as a, unnest( @@ -230,10 +157,7 @@ create temporary table foo ( f4 int ); -create index "fooindex" -on foo -using btree -( +create index fooindex on foo using btree ( f1 desc, f2 asc, f3 nulls first, @@ -243,16 +167,9 @@ using btree select col, prop, - pg_index_column_has_property( - o, - col, - prop - ) + pg_index_column_has_property(o, col, prop) from - ( - values (cast('fooindex' as regclass)) - ) - as v1 (o), + (values (cast('fooindex' as regclass))) as v1 (o), ( values (1, 'orderable'), @@ -267,21 +184,14 @@ from order by col, idx; -create index "foocover" on foo using btree (f1) include (f2, f3); +create index foocover on foo using btree (f1) include (f2, f3); select col, prop, - pg_index_column_has_property( - o, - col, - prop - ) + pg_index_column_has_property(o, col, prop) from - ( - values (cast('foocover' as regclass)) - ) - as v1 (o), + (values (cast('foocover' as regclass))) as v1 (o), ( values (1, 'orderable'), diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__arrays_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__arrays_100.snap index cc6d81a59..3ba6aec40 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__arrays_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__arrays_100.snap @@ -3,18 +3,18 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/arrays.sql --- create table arrtest ( - a smallint[], - b int[][][], + a int2[], + b int4[][][], c name[], d text[][], - e double precision[], + e float8[], f char(5)[], g varchar(5)[] ); create table array_op_test ( - seqno int, - i int[], + seqno int4, + i int4[], t text[] ); @@ -23,15 +23,7 @@ copy array_op_test from 'filename'; analyze array_op_test; insert into arrtest (a[1:5], b[1:1][1:2][1:2], c, d, f, g) -values - ( - '{1,2,3,4,5}', - '{{{0,0},{1,2}}}', - '{}', - '{}', - '{}', - '{}' - ); +values ('{1,2,3,4,5}', '{{{0,0},{1,2}}}', '{}', '{}', '{}', '{}'); update arrtest set e[0] = '1.1'; @@ -53,9 +45,9 @@ values insert into arrtest (a, b[1:2], c, d[1:2]) values ('{}', '{3,4}', '{foo,bar}', '{bar,foo}'); -insert into arrtest (b[2]) values (NOW()); +insert into arrtest (b[2]) values (now()); -insert into arrtest (b[1:2]) values (NOW()); +insert into arrtest (b[1:2]) values (now()); select * from arrtest; @@ -129,11 +121,11 @@ update arrtest set c[null:1] = '{"can''t assign"}' where array_dims(c) is not nu update arrtest set c[1:null] = '{"can''t assign"}' where array_dims(c) is not null; -select (NOW())[1]; +select (now())[1]; create temporary table arrtest_s ( - a smallint[], - b smallint[][] + a int2[], + b int2[][] ); insert into arrtest_s values ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}'); @@ -189,23 +181,20 @@ insert into point_tbl (f1[0]) values (0) returning *; update point_tbl set f1[0] = null where - cast(f1 as text) = - cast(cast('(10,10)' as point) as text) + cast(f1 as text) = cast(cast('(10,10)' as point) as text) returning *; update point_tbl set f1[0] = -10, f1[1] = -10 where - cast(f1 as text) = - cast(cast('(10,10)' as point) as text) + cast(f1 as text) = cast(cast('(10,10)' as point) as text) returning *; update point_tbl set f1[3] = 10 where - cast(f1 as text) = - cast(cast('(-10,-10)' as point) as text) + cast(f1 as text) = cast(cast('(-10,-10)' as point) as text) returning *; create temporary table arrtest1 ( @@ -279,7 +268,7 @@ select * from arrtest1; create temporary table arrtest2 ( i int[4], - f double precision[], + f float8[], n numeric[], t text[], d timestamp[] @@ -289,22 +278,17 @@ insert into arrtest2 values ( array[array[array[113, 142], array[1, 147]]], - cast(array[1.1, 1.2, 1.3] as double precision[]), + cast(array[1.1, 1.2, 1.3] as float8[]), array[1.1, 1.2, 1.3], - array[array[array['aaa', 'aab'], - array['aba', 'abb'], - array['aca', 'acb']], - array[array['baa', 'bab'], - array['bba', 'bbb'], - array['bca', 'bcb']]], - cast(array['19620326', '19931223', '19970117'] - as timestamp[]) + array[array[array['aaa', 'aab'], array['aba', 'abb'], array['aca', 'acb']], + array[array['baa', 'bab'], array['bba', 'bbb'], array['bca', 'bcb']]], + cast(array['19620326', '19931223', '19970117'] as timestamp[]) ); create temporary table arrtest_f ( f0 int, f1 text, - f2 double precision + f2 float8 ); insert into arrtest_f values (1, 'cat1', 1.21); @@ -355,12 +339,8 @@ select from ( select - array[array[array[111, 112], - array[121, 122], - array[131, 132]], - array[array[211, 212], - array[221, 122], - array[231, 232]]] + array[array[array[111, 112], array[121, 122], array[131, 132]], + array[array[211, 212], array[221, 122], array[231, 232]]] as f ) as t; @@ -418,8 +398,7 @@ select array_positions( array( select - cast('AAAAAAAAAAAAAAAAAAAAAAAAA' as text) || - i % 10 + cast('AAAAAAAAAAAAAAAAAAAAAAAAA' as text) || i % 10 from generate_series(1, 100) as g (i) ), @@ -428,8 +407,7 @@ select 1 ); -do -$do$ +do $$ DECLARE o int; a int[] := ARRAY[1,2,3,2,3,1,2]; @@ -441,8 +419,7 @@ BEGIN o := array_position(a, 2, o + 1); END LOOP; END -$do$ -language plpgsql; +$$ language plpgsql; select array_position(cast('[2:4]={1,2,3}' as int[]), 1); @@ -452,10 +429,7 @@ select array_position(ids, (1, 1)), array_positions(ids, (1, 1)) from - ( - values (array[(0, 0), (1, 1)]), (array[(1, 1)]) - ) - as f (ids); + (values (array[(0, 0), (1, 1)]), (array[(1, 1)])) as f (ids); select a from arrtest where b = array[array[array[113, 142], array[1, 147]]]; @@ -540,32 +514,22 @@ select * from array_op_test where t && '{}' order by seqno; select * from array_op_test where t <@ '{}' order by seqno; -select cast(cast(cast(array[1, 2, 3] as text[]) as int[]) as double precision[]) as "{1,2,3}"; +select cast(cast(cast(array[1, 2, 3] as text[]) as int[]) as float8[]) as "{1,2,3}"; select - pg_typeof( - cast(cast(cast(array[1, 2, 3] as text[]) as int[]) - as double precision[]) - ) + pg_typeof(cast(cast(cast(array[1, 2, 3] as text[]) as int[]) as float8[])) as "double precision[]"; select - cast(cast(array[array['a', 'bc'], array['def', 'hijk']] - as text[]) - as varchar[]) + cast(cast(array[array['a', 'bc'], array['def', 'hijk']] as text[]) as varchar[]) as "{{a,bc},{def,hijk}}"; select - pg_typeof( - cast(cast(array[array['a', 'bc'], array['def', 'hijk']] - as text[]) - as varchar[]) - ) + pg_typeof(cast(cast(array[array['a', 'bc'], array['def', 'hijk']] as text[]) as varchar[])) as "character varying[]"; select - cast(array[array[array[array[array[array['a', 'bb', 'ccc']]]]]] - as text[]) + cast(array[array[array[array[array[array['a', 'bb', 'ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}"; select cast(cast(null as text[]) as int[]) as "NULL"; @@ -633,7 +597,7 @@ select * from arr_tbl where f1 > '{1,2,3}' and f1 <= '{1,5,3}'; select * from arr_tbl where f1 >= '{1,2,3}' and f1 < '{1,5,3}'; create temporary table arr_pk_tbl ( - pk int primary key, + pk int4 primary key, f1 int[] ); @@ -641,12 +605,7 @@ insert into arr_pk_tbl values (1, '{1,2,3}'); insert into arr_pk_tbl values (1, '{3,4,5}') -on conflict -(pk) -do -update -set f1[1] = excluded.f1[1], -f1[3] = excluded.f1[3] +on conflict (pk) do update set f1[1] = excluded.f1[1], f1[3] = excluded.f1[3] returning pk, f1; @@ -676,14 +635,11 @@ insert into arr_pk_tbl (pk, f1[0:2147483647]) values (2, '{}'); insert into arr_pk_tbl (pk, f1[-2147483648:2147483647]) values (2, '{}'); -do -$do$ -declare a int[]; +do $$ declare a int[]; begin a := '[-2147483648:-2147483647]={1,2}'::int[]; a[2147483647] := 42; -end -$do$; +end $$; select 'foo' ~~ any (array['%a', '%o']); @@ -781,18 +737,16 @@ select cast('{ { "," } , { 3 } }' as text[]); select cast(' { { " 0 second " , 0 second } }' as text[]); -select - cast('{ +select cast('{ 0 second, @ 1 hour @ 42 minutes @ 20 seconds - }' - as interval[]); + }' as interval[]); select cast(array[] as text[]); select cast('[2]={1,7}' as int[]); -select cast('[0:1]={1.1,2.2}' as double precision[]); +select cast('[0:1]={1.1,2.2}' as float8[]); select cast('[2147483646:2147483646]={1}' as int[]); @@ -808,47 +762,27 @@ insert into arraggtest (f1, f2, f3) values ('{1,2,3,4}', '{{grey,red},{blue,blue insert into arraggtest (f1, f2, f3) values ('{1,2,3}', '{{grey,red},{grey,blue}}', '{1.6}'); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; insert into arraggtest (f1, f2, f3) -values - ( - '{3,3,2,4,5,6}', - '{{white,yellow},{pink,orange}}', - '{2.1,3.3,1.8,1.7,1.6}' - ); +values ('{3,3,2,4,5,6}', '{{white,yellow},{pink,orange}}', '{2.1,3.3,1.8,1.7,1.6}'); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; insert into arraggtest (f1, f2, f3) -values - ( - '{2}', - '{{black,red},{green,orange}}', - '{1.6,2.2,2.6,0.4}' - ); +values ('{2}', '{{black,red},{green,orange}}', '{1.6,2.2,2.6,0.4}'); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; insert into arraggtest (f1, f2, f3) -values - ( - '{4,2,6,7,8,1}', - '{{red},{black},{purple},{blue},{blue}}', - null - ); +values ('{4,2,6,7,8,1}', '{{red},{black},{purple},{blue},{blue}}', null); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; insert into arraggtest (f1, f2, f3) -values - ( - '{}', - '{{pink,white,blue,red,grey,orange}}', - '{2.1,1.87,1.4,2.2}' - ); +values ('{}', '{{pink,white,blue,red,grey,orange}}', '{2.1,1.87,1.4,2.2}'); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; create type comptype as (f1 int, f2 text); @@ -858,12 +792,7 @@ create table comptable ( ); insert into comptable -values - ( - row(1, 'foo'), - array[cast(row(2, 'bar') as comptype), - cast(row(3, 'baz') as comptype)] - ); +values (row(1, 'foo'), array[cast(row(2, 'bar') as comptype), cast(row(3, 'baz') as comptype)]); create type _comptype as enum ('fooey'); @@ -881,18 +810,18 @@ create or replace function unnest1(anyarray) returns setof anyelement language sql immutable -as $function$ +as $$ select $1[s] from generate_subscripts($1,1) g(s); -$function$; +$$; create or replace function unnest2(anyarray) returns setof anyelement language sql immutable -as $function$ +as $$ select $1[s1][s2] from generate_subscripts($1,1) g1(s1), generate_subscripts($1,2) g2(s2); -$function$; +$$; select * from unnest1(array[1, 2, 3]); @@ -992,9 +921,9 @@ select v, v is null as "is null" from string_to_table('1,2,3,4,,6', ',', '') as select v, v is null as "is null" from string_to_table('1,2,3,4,*,6', ',', '*') as g (v); -select array_to_string(cast(null as int[]), ',') is null; +select array_to_string(cast(null as int4[]), ',') is null; -select array_to_string(cast('{}' as int[]), ','); +select array_to_string(cast('{}' as int4[]), ','); select array_to_string(array[1, 2, 3, 4, null, 6], ','); @@ -1033,32 +962,14 @@ select cardinality(cast('{{{1,9},{5,6}},{{2,3},{3,4}}}' as int[])); select array_agg(unique1) from - ( - select - unique1 - from - tenk1 - where - unique1 < 15 - order by unique1 - ) - as ss; + (select unique1 from tenk1 where unique1 < 15 order by unique1) as ss; select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) as ss; select array_agg(nullif(ten, 4)) from - ( - select - ten - from - tenk1 - where - unique1 < 15 - order by unique1 - ) - as ss; + (select ten from tenk1 where unique1 < 15 order by unique1) as ss; select array_agg(unique1) from tenk1 where unique1 < -15; @@ -1067,24 +978,12 @@ select array_agg(ar) from (values (cast('{1,2}' as int[])), (cast('{3,4}' as int select array_agg(distinct ar order by ar desc) from - ( - select - array[i / 2] - from - generate_series(1, 10) as a (i) - ) - as b (ar); + (select array[i / 2] from generate_series(1, 10) as a (i)) as b (ar); select array_agg(ar) from - ( - select - array_agg(array[i, i + 1, i - 1]) - from - generate_series(1, 2) as a (i) - ) - as b (ar); + (select array_agg(array[i, i + 1, i - 1]) from generate_series(1, 2) as a (i)) as b (ar); select array_agg(array[i + 1.2, i + 1.3, i + 1.4]) from generate_series(1, 3) as g (i); @@ -1102,7 +1001,7 @@ select unnest(array[1, 2, 3]); select * from unnest(array[1, 2, 3]); -select unnest(cast(array[1, 2, 3, 4.5] as double precision[])); +select unnest(cast(array[1, 2, 3, 4.5] as float8[])); select unnest(cast(array[1, 2, 3, 4.5] as numeric[])); @@ -1216,36 +1115,12 @@ drop type textandtext; select op, - width_bucket( - cast(op as numeric), - cast(array[1, 3, 5, 10.0] as numeric[]) - ) - as wb_n1, - width_bucket( - cast(op as numeric), - cast(array[0, 5.5, 9.99] as numeric[]) - ) - as wb_n2, - width_bucket( - cast(op as numeric), - cast(array[-6, -5, 2.0] as numeric[]) - ) - as wb_n3, - width_bucket( - cast(op as double precision), - cast(array[1, 3, 5, 10.0] as double precision[]) - ) - as wb_f1, - width_bucket( - cast(op as double precision), - cast(array[0, 5.5, 9.99] as double precision[]) - ) - as wb_f2, - width_bucket( - cast(op as double precision), - cast(array[-6, -5, 2.0] as double precision[]) - ) - as wb_f3 + width_bucket(cast(op as numeric), cast(array[1, 3, 5, 10.0] as numeric[])) as wb_n1, + width_bucket(cast(op as numeric), cast(array[0, 5.5, 9.99] as numeric[])) as wb_n2, + width_bucket(cast(op as numeric), cast(array[-6, -5, 2.0] as numeric[])) as wb_n3, + width_bucket(cast(op as float8), cast(array[1, 3, 5, 10.0] as float8[])) as wb_f1, + width_bucket(cast(op as float8), cast(array[0, 5.5, 9.99] as float8[])) as wb_f2, + width_bucket(cast(op as float8), cast(array[-6, -5, 2.0] as float8[])) as wb_f3 from ( values @@ -1273,30 +1148,20 @@ from select op, - width_bucket( - op, - cast(array[1, 3, 9, 'NaN', 'NaN'] - as double precision[]) - ) - as wb + width_bucket(op, cast(array[1, 3, 9, 'NaN', 'NaN'] as float8[])) as wb from ( values - (-cast(5.2 as double precision)), - (cast(4 as double precision)), - (cast(77 as double precision)), - (cast('NaN' as double precision)) + (-cast(5.2 as float8)), + (cast(4 as float8)), + (cast(77 as float8)), + (cast('NaN' as float8)) ) as v (op); select op, width_bucket(op, array[1, 3, 5, 10]) as wb_1 from generate_series(0, 11) as op; -select - width_bucket( - NOW(), - cast(array['yesterday', 'today', 'tomorrow'] - as timestamp with time zone[]) - ); +select width_bucket(now(), cast(array['yesterday', 'today', 'tomorrow'] as timestamptz[])); select width_bucket(5, array[3]); @@ -1335,12 +1200,7 @@ select array_shuffle(cast('{1,2,3,4,5,6}' as int[])) @> '{1,2,3,4,5,6}'; select array_dims(array_shuffle(cast('[-1:2][2:3]={{1,2},{3,NULL},{5,6},{7,8}}' as int[]))); select - array_dims( - array_shuffle( - cast('{{{1,2},{3,NULL}},{{5,6},{7,8}},{{9,10},{11,12}}}' - as int[]) - ) - ); + array_dims(array_shuffle(cast('{{{1,2},{3,NULL}},{{5,6},{7,8}},{{9,10},{11,12}}}' as int[]))); select array_sample(cast('{1,2,3,4,5,6}' as int[]), 3) <@ '{1,2,3,4,5,6}'; @@ -1349,13 +1209,7 @@ select array_length(array_sample(cast('{1,2,3,4,5,6}' as int[]), 3), 1); select array_dims(array_sample(cast('[-1:2][2:3]={{1,2},{3,NULL},{5,6},{7,8}}' as int[]), 3)); select - array_dims( - array_sample( - cast('{{{1,2},{3,NULL}},{{5,6},{7,8}},{{9,10},{11,12}}}' - as int[]), - 2 - ) - ); + array_dims(array_sample(cast('{{{1,2},{3,NULL}},{{5,6},{7,8}},{{9,10},{11,12}}}' as int[]), 2)); select array_sample(cast('{1,2,3,4,5,6}' as int[]), -1); @@ -1384,25 +1238,19 @@ select array_sort(cast('{foo,bar,CCC,Abc,bbc}' as text[]) collate "C"); select array_sort(cast('{foo,bar,null,CCC,Abc,bbc}' as text[]) collate "C"); select - array_sort( - array( - select cast('1 4' as int2vector) - union all - select cast('1 2' as int2vector) - ) - ); + array_sort(array(select cast('1 4' as int2vector) union all select cast('1 2' as int2vector))); -select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as double precision[]), true); +select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), true); -select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as double precision[]), false); +select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), false); -select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as double precision[]), true, true); +select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), true, true); -select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as double precision[]), true, false); +select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), true, false); -select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as double precision[]), false, true); +select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), false, true); -select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as double precision[]), false, false); +select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), false, false); select array_sort(cast('{{1}}' as int[])); @@ -1425,23 +1273,9 @@ select array_sort(a) from (values (cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' a select array_sort(a[-1:0]) from - ( - values - ( - cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' - as int[]) - ) - ) - as v (a); + (values (cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' as int[]))) as v (a); select array_sort(a[-1:0][20:20]) from - ( - values - ( - cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' - as int[]) - ) - ) - as v (a); + (values (cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' as int[]))) as v (a); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__arrays_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__arrays_80.snap index c5d80cac6..9823316ce 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__arrays_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__arrays_80.snap @@ -3,18 +3,18 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/arrays.sql --- create table arrtest ( - a smallint[], - b int[][][], + a int2[], + b int4[][][], c name[], d text[][], - e double precision[], + e float8[], f char(5)[], g varchar(5)[] ); create table array_op_test ( - seqno int, - i int[], + seqno int4, + i int4[], t text[] ); @@ -23,15 +23,7 @@ copy array_op_test from 'filename'; analyze array_op_test; insert into arrtest (a[1:5], b[1:1][1:2][1:2], c, d, f, g) -values - ( - '{1,2,3,4,5}', - '{{{0,0},{1,2}}}', - '{}', - '{}', - '{}', - '{}' - ); +values ('{1,2,3,4,5}', '{{{0,0},{1,2}}}', '{}', '{}', '{}', '{}'); update arrtest set e[0] = '1.1'; @@ -52,14 +44,11 @@ values ); insert into arrtest (a, b[1:2], c, d[1:2]) -values - ( - '{}', '{3,4}', '{foo,bar}', '{bar,foo}' - ); +values ('{}', '{3,4}', '{foo,bar}', '{bar,foo}'); -insert into arrtest (b[2]) values (NOW()); +insert into arrtest (b[2]) values (now()); -insert into arrtest (b[1:2]) values (NOW()); +insert into arrtest (b[1:2]) values (now()); select * from arrtest; @@ -154,21 +143,17 @@ set c[1:null] = '{"can''t assign"}' where array_dims(c) is not null; -select (NOW())[1]; +select (now())[1]; create temporary table arrtest_s ( - a smallint[], - b smallint[][] + a int2[], + b int2[][] ); insert into arrtest_s values ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}'); insert into arrtest_s -values - ( - '[0:4]={1,2,3,4,5}', - '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}' - ); +values ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}'); select * from arrtest_s; @@ -219,23 +204,20 @@ insert into point_tbl (f1[0]) values (0) returning *; update point_tbl set f1[0] = null where - cast(f1 as text) = - cast(cast('(10,10)' as point) as text) + cast(f1 as text) = cast(cast('(10,10)' as point) as text) returning *; update point_tbl set f1[0] = -10, f1[1] = -10 where - cast(f1 as text) = - cast(cast('(10,10)' as point) as text) + cast(f1 as text) = cast(cast('(10,10)' as point) as text) returning *; update point_tbl set f1[3] = 10 where - cast(f1 as text) = - cast(cast('(-10,-10)' as point) as text) + cast(f1 as text) = cast(cast('(-10,-10)' as point) as text) returning *; create temporary table arrtest1 ( @@ -244,11 +226,7 @@ create temporary table arrtest1 ( ); insert into arrtest1 -values - ( - array[1, 2, null, 4], - array['one', 'two', null, 'four'] - ); +values (array[1, 2, null, 4], array['one', 'two', null, 'four']); select * from arrtest1; @@ -311,11 +289,7 @@ select * from arrtest1; delete from arrtest1; insert into arrtest1 -values - ( - array[1, 2, null, 4], - array['one', 'two', null, 'four'] - ); +values (array[1, 2, null, 4], array['one', 'two', null, 'four']); select * from arrtest1; @@ -327,7 +301,7 @@ select * from arrtest1; create temporary table arrtest2 ( i int[4], - f double precision[], + f float8[], n numeric[], t text[], d timestamp[] @@ -337,25 +311,17 @@ insert into arrtest2 values ( array[array[array[113, 142], array[1, 147]]], - cast(array[1.1, 1.2, 1.3] - as double precision[]), + cast(array[1.1, 1.2, 1.3] as float8[]), array[1.1, 1.2, 1.3], - array[array[array['aaa', 'aab'], - array['aba', 'abb'], - array['aca', 'acb']], - array[array['baa', 'bab'], - array['bba', 'bbb'], - array['bca', 'bcb']]], - cast(array['19620326', - '19931223', - '19970117'] - as timestamp[]) + array[array[array['aaa', 'aab'], array['aba', 'abb'], array['aca', 'acb']], + array[array['baa', 'bab'], array['bba', 'bbb'], array['bca', 'bcb']]], + cast(array['19620326', '19931223', '19970117'] as timestamp[]) ); create temporary table arrtest_f ( f0 int, f1 text, - f2 double precision + f2 float8 ); insert into arrtest_f values (1, 'cat1', 1.21); @@ -406,12 +372,8 @@ select from ( select - array[array[array[111, 112], - array[121, 122], - array[131, 132]], - array[array[211, 212], - array[221, 122], - array[231, 232]]] + array[array[array[111, 112], array[121, 122], array[131, 132]], + array[array[211, 212], array[221, 122], array[231, 232]]] as f ) as t; @@ -433,17 +395,11 @@ select array_prepend(6, array[42]) as "{6,42}"; select array_cat(array[1, 2], array[3, 4]) as "{1,2,3,4}"; select - array_cat( - array[1, 2], - array[array[3, 4], array[5, 6]] - ) + array_cat(array[1, 2], array[array[3, 4], array[5, 6]]) as "{{1,2},{3,4},{5,6}}"; select - array_cat( - array[array[3, 4], array[5, 6]], - array[1, 2] - ) + array_cat(array[array[3, 4], array[5, 6]], array[1, 2]) as "{{3,4},{5,6},{1,2}}"; select array_position(array[1, 2, 3, 4, 5], 4); @@ -453,64 +409,23 @@ select array_position(array[5, 3, 4, 2, 1], 4); select array_position(array[array[1, 2], array[3, 4]], 3); select - array_position( - array['sun', - 'mon', - 'tue', - 'wed', - 'thu', - 'fri', - 'sat'], - 'mon' - ); + array_position(array['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'], 'mon'); select - array_position( - array['sun', - 'mon', - 'tue', - 'wed', - 'thu', - 'fri', - 'sat'], - 'sat' - ); + array_position(array['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'], 'sat'); select - array_position( - array['sun', - 'mon', - 'tue', - 'wed', - 'thu', - 'fri', - 'sat'], - null - ); + array_position(array['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'], null); select array_position( - array['sun', - 'mon', - 'tue', - 'wed', - 'thu', - null, - 'fri', - 'sat'], + array['sun', 'mon', 'tue', 'wed', 'thu', null, 'fri', 'sat'], null ); select array_position( - array['sun', - 'mon', - 'tue', - 'wed', - 'thu', - null, - 'fri', - 'sat'], + array['sun', 'mon', 'tue', 'wed', 'thu', null, 'fri', 'sat'], 'sat' ); @@ -531,9 +446,7 @@ select array_positions( array( select - cast('AAAAAAAAAAAAAAAAAAAAAAAAA' - as text) || - i % 10 + cast('AAAAAAAAAAAAAAAAAAAAAAAAA' as text) || i % 10 from generate_series(1, 100) as g (i) ), @@ -542,8 +455,7 @@ select 1 ); -do -$do$ +do $$ DECLARE o int; a int[] := ARRAY[1,2,3,2,3,1,2]; @@ -555,8 +467,7 @@ BEGIN o := array_position(a, 2, o + 1); END LOOP; END -$do$ -language plpgsql; +$$ language plpgsql; select array_position(cast('[2:4]={1,2,3}' as int[]), 1); @@ -566,12 +477,7 @@ select array_position(ids, (1, 1)), array_positions(ids, (1, 1)) from - ( - values - (array[(0, 0), (1, 1)]), - (array[(1, 1)]) - ) - as f (ids); + (values (array[(0, 0), (1, 1)]), (array[(1, 1)])) as f (ids); select a from arrtest where b = array[array[array[113, 142], array[1, 147]]]; @@ -599,18 +505,12 @@ select array[1.1] || array[2, 3, 4]; select array_agg(x) || array_agg(x) from - ( - values (row(1, 2)), (row(3, 4)) - ) - as v (x); + (values (row(1, 2)), (row(3, 4))) as v (x); select row(1, 2) || array_agg(x) from - ( - values (row(3, 4)), (row(5, 6)) - ) - as v (x); + (values (row(3, 4)), (row(5, 6))) as v (x); select * from array_op_test where i @> '{32}' order by seqno; @@ -684,38 +584,26 @@ select * from array_op_test where t && '{}' order by seqno; select * from array_op_test where t <@ '{}' order by seqno; select - cast(cast(cast(array[1, 2, 3] as text[]) - as int[]) - as double precision[]) - as "{1,2,3}"; + cast(cast(cast(array[1, 2, 3] as text[]) as int[]) as float8[]) as "{1,2,3}"; select - pg_typeof( - cast(cast(cast(array[1, 2, 3] as text[]) - as int[]) - as double precision[]) - ) + pg_typeof(cast(cast(cast(array[1, 2, 3] as text[]) as int[]) as float8[])) as "double precision[]"; select - cast(cast(array[array['a', 'bc'], - array['def', 'hijk']] - as text[]) + cast(cast(array[array['a', 'bc'], array['def', 'hijk']] as text[]) as varchar[]) as "{{a,bc},{def,hijk}}"; select pg_typeof( - cast(cast(array[array['a', 'bc'], - array['def', 'hijk']] - as text[]) + cast(cast(array[array['a', 'bc'], array['def', 'hijk']] as text[]) as varchar[]) ) as "character varying[]"; select - cast(array[array[array[array[array[array['a', 'bb', 'ccc']]]]]] - as text[]) + cast(array[array[array[array[array[array['a', 'bb', 'ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}"; select cast(cast(null as text[]) as int[]) as "NULL"; @@ -760,10 +648,7 @@ select 33 = all ('{33,null,33}'); select -1 <> all (array( - select - nullif(g.i, 900) - from - generate_series(1, 1000) as g (i) + select nullif(g.i, 900) from generate_series(1, 1000) as g (i) )); create temporary table arr_tbl (f1 int[] unique); @@ -789,7 +674,7 @@ select * from arr_tbl where f1 > '{1,2,3}' and f1 <= '{1,5,3}'; select * from arr_tbl where f1 >= '{1,2,3}' and f1 < '{1,5,3}'; create temporary table arr_pk_tbl ( - pk int primary key, + pk int4 primary key, f1 int[] ); @@ -797,12 +682,7 @@ insert into arr_pk_tbl values (1, '{1,2,3}'); insert into arr_pk_tbl values (1, '{3,4,5}') -on conflict -(pk) -do -update -set f1[1] = excluded.f1[1], -f1[3] = excluded.f1[3] +on conflict (pk) do update set f1[1] = excluded.f1[1], f1[3] = excluded.f1[3] returning pk, f1; @@ -832,14 +712,11 @@ insert into arr_pk_tbl (pk, f1[0:2147483647]) values (2, '{}'); insert into arr_pk_tbl (pk, f1[-2147483648:2147483647]) values (2, '{}'); -do -$do$ -declare a int[]; +do $$ declare a int[]; begin a := '[-2147483648:-2147483647]={1,2}'::int[]; a[2147483647] := 42; -end -$do$; +end $$; select 'foo' ~~ any (array['%a', '%o']); @@ -937,18 +814,16 @@ select cast('{ { "," } , { 3 } }' as text[]); select cast(' { { " 0 second " , 0 second } }' as text[]); -select - cast('{ +select cast('{ 0 second, @ 1 hour @ 42 minutes @ 20 seconds - }' - as interval[]); + }' as interval[]); select cast(array[] as text[]); select cast('[2]={1,7}' as int[]); -select cast('[0:1]={1.1,2.2}' as double precision[]); +select cast('[0:1]={1.1,2.2}' as float8[]); select cast('[2147483646:2147483646]={1}' as int[]); @@ -961,62 +836,33 @@ create temporary table arraggtest ( ); insert into arraggtest (f1, f2, f3) -values - ( - '{1,2,3,4}', - '{{grey,red},{blue,blue}}', - '{1.6, 0.0}' - ); +values ('{1,2,3,4}', '{{grey,red},{blue,blue}}', '{1.6, 0.0}'); insert into arraggtest (f1, f2, f3) -values - ( - '{1,2,3}', - '{{grey,red},{grey,blue}}', - '{1.6}' - ); +values ('{1,2,3}', '{{grey,red},{grey,blue}}', '{1.6}'); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; insert into arraggtest (f1, f2, f3) values - ( - '{3,3,2,4,5,6}', - '{{white,yellow},{pink,orange}}', - '{2.1,3.3,1.8,1.7,1.6}' - ); + ('{3,3,2,4,5,6}', '{{white,yellow},{pink,orange}}', '{2.1,3.3,1.8,1.7,1.6}'); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; insert into arraggtest (f1, f2, f3) -values - ( - '{2}', - '{{black,red},{green,orange}}', - '{1.6,2.2,2.6,0.4}' - ); +values ('{2}', '{{black,red},{green,orange}}', '{1.6,2.2,2.6,0.4}'); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; insert into arraggtest (f1, f2, f3) -values - ( - '{4,2,6,7,8,1}', - '{{red},{black},{purple},{blue},{blue}}', - null - ); +values ('{4,2,6,7,8,1}', '{{red},{black},{purple},{blue},{blue}}', null); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; insert into arraggtest (f1, f2, f3) -values - ( - '{}', - '{{pink,white,blue,red,grey,orange}}', - '{2.1,1.87,1.4,2.2}' - ); +values ('{}', '{{pink,white,blue,red,grey,orange}}', '{2.1,1.87,1.4,2.2}'); -select MAX(f1), MIN(f1), MAX(f2), MIN(f2), MAX(f3), MIN(f3) from arraggtest; +select max(f1), min(f1), max(f2), min(f2), max(f3), min(f3) from arraggtest; create type comptype as (f1 int, f2 text); @@ -1029,8 +875,7 @@ insert into comptable values ( row(1, 'foo'), - array[cast(row(2, 'bar') as comptype), - cast(row(3, 'baz') as comptype)] + array[cast(row(2, 'bar') as comptype), cast(row(3, 'baz') as comptype)] ); create type _comptype as enum ('fooey'); @@ -1049,18 +894,18 @@ create or replace function unnest1(anyarray) returns setof anyelement language sql immutable -as $function$ +as $$ select $1[s] from generate_subscripts($1,1) g(s); -$function$; +$$; create or replace function unnest2(anyarray) returns setof anyelement language sql immutable -as $function$ +as $$ select $1[s1][s2] from generate_subscripts($1,1) g1(s1), generate_subscripts($1,2) g2(s2); -$function$; +$$; select * from unnest1(array[1, 2, 3]); @@ -1091,10 +936,7 @@ select a = '{}' as is_eq, array_dims(a) from - ( - select array_fill(42, array[0]) as a - ) - as ss; + (select array_fill(42, array[0]) as a) as ss; select a, @@ -1108,10 +950,7 @@ select a = '{}' as is_eq, array_dims(a) from - ( - select array_fill(42, '{}', '{}') as a - ) - as ss; + (select array_fill(42, '{}', '{}') as a) as ss; select array_fill(1, null, array[2, 2]); @@ -1161,8 +1000,7 @@ select v, v is null as "is null" from - string_to_table('1||2|3||', '||') - as g (v); + string_to_table('1||2|3||', '||') as g (v); select v, v is null as "is null" from string_to_table('1|2|3', '') as g (v); @@ -1178,8 +1016,7 @@ select v, v is null as "is null" from - string_to_table('abc', '', 'abc') - as g (v); + string_to_table('abc', '', 'abc') as g (v); select v, v is null as "is null" from string_to_table('abc', ',') as g (v); @@ -1187,33 +1024,29 @@ select v, v is null as "is null" from - string_to_table('abc', ',', 'abc') - as g (v); + string_to_table('abc', ',', 'abc') as g (v); select v, v is null as "is null" from - string_to_table('1,2,3,4,,6', ',') - as g (v); + string_to_table('1,2,3,4,,6', ',') as g (v); select v, v is null as "is null" from - string_to_table('1,2,3,4,,6', ',', '') - as g (v); + string_to_table('1,2,3,4,,6', ',', '') as g (v); select v, v is null as "is null" from - string_to_table('1,2,3,4,*,6', ',', '*') - as g (v); + string_to_table('1,2,3,4,*,6', ',', '*') as g (v); -select array_to_string(cast(null as int[]), ',') is null; +select array_to_string(cast(null as int4[]), ',') is null; -select array_to_string(cast('{}' as int[]), ','); +select array_to_string(cast('{}' as int4[]), ','); select array_to_string(array[1, 2, 3, 4, null, 6], ','); @@ -1252,90 +1085,45 @@ select cardinality(cast('{{{1,9},{5,6}},{{2,3},{3,4}}}' as int[])); select array_agg(unique1) from - ( - select - unique1 - from - tenk1 - where - unique1 < 15 - order by unique1 - ) - as ss; + (select unique1 from tenk1 where unique1 < 15 order by unique1) as ss; select array_agg(ten) from - ( - select - ten - from - tenk1 - where - unique1 < 15 - order by unique1 - ) - as ss; + (select ten from tenk1 where unique1 < 15 order by unique1) as ss; select array_agg(nullif(ten, 4)) from - ( - select - ten - from - tenk1 - where - unique1 < 15 - order by unique1 - ) - as ss; + (select ten from tenk1 where unique1 < 15 order by unique1) as ss; select array_agg(unique1) from tenk1 where unique1 < -15; select array_agg(ar) from - ( - values - (cast('{1,2}' as int[])), - (cast('{3,4}' as int[])) - ) - as v (ar); + (values (cast('{1,2}' as int[])), (cast('{3,4}' as int[]))) as v (ar); select array_agg(distinct ar order by ar desc) from - ( - select - array[i / 2] - from - generate_series(1, 10) as a (i) - ) - as b (ar); + (select array[i / 2] from generate_series(1, 10) as a (i)) as b (ar); select array_agg(ar) from ( - select - array_agg(array[i, i + 1, i - 1]) - from - generate_series(1, 2) as a (i) + select array_agg(array[i, i + 1, i - 1]) from generate_series(1, 2) as a (i) ) as b (ar); select - array_agg( - array[i + 1.2, i + 1.3, i + 1.4] - ) + array_agg(array[i + 1.2, i + 1.3, i + 1.4]) from generate_series(1, 3) as g (i); select - array_agg( - array['Hello', cast(i as text)] - ) + array_agg(array['Hello', cast(i as text)]) from generate_series(9, 11) as g (i); @@ -1351,18 +1139,13 @@ select array_agg(cast(null as int[])) from generate_series(1, 2); select array_agg(ar) from - ( - values - (cast('{1,2}' as int[])), - (cast('{3}' as int[])) - ) - as v (ar); + (values (cast('{1,2}' as int[])), (cast('{3}' as int[]))) as v (ar); select unnest(array[1, 2, 3]); select * from unnest(array[1, 2, 3]); -select unnest(cast(array[1, 2, 3, 4.5] as double precision[])); +select unnest(cast(array[1, 2, 3, 4.5] as float8[])); select unnest(cast(array[1, 2, 3, 4.5] as numeric[])); @@ -1402,54 +1185,31 @@ select array(select array[i, i / 2] from generate_series(1, 5) as i); select array( - select - array['Hello', cast(i as text)] - from - generate_series(9, 11) as i + select array['Hello', cast(i as text)] from generate_series(9, 11) as i ); select pg_typeof( - array( - select - cast('11 22 33' as int2vector) - from - generate_series(1, 5) - ) + array(select cast('11 22 33' as int2vector) from generate_series(1, 5)) ); select array(select cast('11 22 33' as int2vector) from generate_series(1, 5)); select unnest( - array( - select - cast('11 22 33' as int2vector) - from - generate_series(1, 5) - ) + array(select cast('11 22 33' as int2vector) from generate_series(1, 5)) ); select pg_typeof( - array( - select - cast('11 22 33' as oidvector) - from - generate_series(1, 5) - ) + array(select cast('11 22 33' as oidvector) from generate_series(1, 5)) ); select array(select cast('11 22 33' as oidvector) from generate_series(1, 5)); select unnest( - array( - select - cast('11 22 33' as oidvector) - from - generate_series(1, 5) - ) + array(select cast('11 22 33' as oidvector) from generate_series(1, 5)) ); select pg_typeof(array[cast('11 22 33' as int2vector)]); @@ -1489,10 +1249,7 @@ select * from t1; create temporary table src (f1 text); insert into src -select - string_agg(cast(random() as text), '') -from - generate_series(1, 10000); +select string_agg(cast(random() as text), '') from generate_series(1, 10000); create type textandtext as (c1 text, c2 text); @@ -1518,38 +1275,17 @@ drop type textandtext; select op, - width_bucket( - cast(op as numeric), - cast(array[1, 3, 5, 10.0] as numeric[]) - ) + width_bucket(cast(op as numeric), cast(array[1, 3, 5, 10.0] as numeric[])) as wb_n1, - width_bucket( - cast(op as numeric), - cast(array[0, 5.5, 9.99] as numeric[]) - ) + width_bucket(cast(op as numeric), cast(array[0, 5.5, 9.99] as numeric[])) as wb_n2, - width_bucket( - cast(op as numeric), - cast(array[-6, -5, 2.0] as numeric[]) - ) + width_bucket(cast(op as numeric), cast(array[-6, -5, 2.0] as numeric[])) as wb_n3, - width_bucket( - cast(op as double precision), - cast(array[1, 3, 5, 10.0] - as double precision[]) - ) + width_bucket(cast(op as float8), cast(array[1, 3, 5, 10.0] as float8[])) as wb_f1, - width_bucket( - cast(op as double precision), - cast(array[0, 5.5, 9.99] - as double precision[]) - ) + width_bucket(cast(op as float8), cast(array[0, 5.5, 9.99] as float8[])) as wb_f2, - width_bucket( - cast(op as double precision), - cast(array[-6, -5, 2.0] - as double precision[]) - ) + width_bucket(cast(op as float8), cast(array[-6, -5, 2.0] as float8[])) as wb_f3 from ( @@ -1578,34 +1314,27 @@ from select op, - width_bucket( - op, - cast(array[1, 3, 9, 'NaN', 'NaN'] - as double precision[]) - ) - as wb + width_bucket(op, cast(array[1, 3, 9, 'NaN', 'NaN'] as float8[])) as wb from ( values - (-cast(5.2 as double precision)), - (cast(4 as double precision)), - (cast(77 as double precision)), - (cast('NaN' as double precision)) + (-cast(5.2 as float8)), + (cast(4 as float8)), + (cast(77 as float8)), + (cast('NaN' as float8)) ) as v (op); select op, - width_bucket(op, array[1, 3, 5, 10]) - as wb_1 + width_bucket(op, array[1, 3, 5, 10]) as wb_1 from generate_series(0, 11) as op; select width_bucket( - NOW(), - cast(array['yesterday', 'today', 'tomorrow'] - as timestamp with time zone[]) + now(), + cast(array['yesterday', 'today', 'tomorrow'] as timestamptz[]) ); select width_bucket(5, array[3]); @@ -1644,17 +1373,13 @@ select array_shuffle(cast('{1,2,3,4,5,6}' as int[])) @> '{1,2,3,4,5,6}'; select array_dims( - array_shuffle( - cast('[-1:2][2:3]={{1,2},{3,NULL},{5,6},{7,8}}' - as int[]) - ) + array_shuffle(cast('[-1:2][2:3]={{1,2},{3,NULL},{5,6},{7,8}}' as int[])) ); select array_dims( array_shuffle( - cast('{{{1,2},{3,NULL}},{{5,6},{7,8}},{{9,10},{11,12}}}' - as int[]) + cast('{{{1,2},{3,NULL}},{{5,6},{7,8}},{{9,10},{11,12}}}' as int[]) ) ); @@ -1664,18 +1389,13 @@ select array_length(array_sample(cast('{1,2,3,4,5,6}' as int[]), 3), 1); select array_dims( - array_sample( - cast('[-1:2][2:3]={{1,2},{3,NULL},{5,6},{7,8}}' - as int[]), - 3 - ) + array_sample(cast('[-1:2][2:3]={{1,2},{3,NULL},{5,6},{7,8}}' as int[]), 3) ); select array_dims( array_sample( - cast('{{{1,2},{3,NULL}},{{5,6},{7,8}},{{9,10},{11,12}}}' - as int[]), + cast('{{{1,2},{3,NULL}},{{5,6},{7,8}},{{9,10},{11,12}}}' as int[]), 2 ) ); @@ -1715,51 +1435,21 @@ select ) ); -select - array_sort( - cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' - as double precision[]), - true - ); +select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), true); -select - array_sort( - cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' - as double precision[]), - false - ); +select array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), false); select - array_sort( - cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' - as double precision[]), - true, - true - ); + array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), true, true); select - array_sort( - cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' - as double precision[]), - true, - false - ); + array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), true, false); select - array_sort( - cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' - as double precision[]), - false, - true - ); + array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), false, true); select - array_sort( - cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' - as double precision[]), - false, - false - ); + array_sort(cast('{1.1,3.3,5.5,2.2,null,4.4,6.6}' as float8[]), false, false); select array_sort(cast('{{1}}' as int[])); @@ -1776,49 +1466,21 @@ select array_sort(cast('{{1,2,3},{2,3,4}}' as xid[])); select array_sort(a) from - ( - values - ( - cast('[10:12][20:21]={{1,2},{10,20},{3,4}}' - as int[]) - ) - ) - as v (a); + (values (cast('[10:12][20:21]={{1,2},{10,20},{3,4}}' as int[]))) as v (a); select array_sort(a) from (values (cast('[-1:0]={7,1}' as int[]))) as v (a); select array_sort(a) from - ( - values - ( - cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' - as int[]) - ) - ) - as v (a); + (values (cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' as int[]))) as v (a); select array_sort(a[-1:0]) from - ( - values - ( - cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' - as int[]) - ) - ) - as v (a); + (values (cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' as int[]))) as v (a); select array_sort(a[-1:0][20:20]) from - ( - values - ( - cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' - as int[]) - ) - ) - as v (a); + (values (cast('[-2:0][20:21]={{1,2},{10,20},{1,-4}}' as int[]))) as v (a); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__async_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__async_100.snap index 4d659d26a..18d701693 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__async_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__async_100.snap @@ -14,12 +14,9 @@ select pg_notify('', 'sample message1'); select pg_notify(null, 'sample message1'); select - pg_notify( - 'notify_async_channel_name_too_long______________________________', - 'sample_message1' - ); + pg_notify('notify_async_channel_name_too_long______________________________', 'sample_message1'); -notify "notify_async2"; +notify notify_async2; listen notify_async2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__async_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__async_80.snap index 4d659d26a..21e396d12 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__async_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__async_80.snap @@ -19,7 +19,7 @@ select 'sample_message1' ); -notify "notify_async2"; +notify notify_async2; listen notify_async2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__bit_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__bit_100.snap index 77bc8d4f2..790805958 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__bit_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__bit_100.snap @@ -47,31 +47,31 @@ select v, length(v) as lv from varbit_table; select b, - SUBSTRING(b from 2 for 4) as sub_2_4, - SUBSTRING(b from 7 for 13) as sub_7_13, - SUBSTRING(b from 6) as sub_6 + substring(b from 2 for 4) as sub_2_4, + substring(b from 7 for 13) as sub_7_13, + substring(b from 6) as sub_6 from bit_table; select v, - SUBSTRING(v from 2 for 4) as sub_2_4, - SUBSTRING(v from 7 for 13) as sub_7_13, - SUBSTRING(v from 6) as sub_6 + substring(v from 2 for 4) as sub_2_4, + substring(v from 7 for 13) as sub_7_13, + substring(v from 6) as sub_6 from varbit_table; -select SUBSTRING(cast('01010101' as bit(8)) from 2 for 2147483646) as "1010101"; +select substring(cast('01010101' as bit(8)) from 2 for 2147483646) as "1010101"; -select SUBSTRING(cast('01010101' as bit(8)) from -10 for 2147483646) as "01010101"; +select substring(cast('01010101' as bit(8)) from -10 for 2147483646) as "01010101"; -select SUBSTRING(cast('01010101' as bit(8)) from -10 for -2147483646) as error; +select substring(cast('01010101' as bit(8)) from -10 for -2147483646) as error; -select SUBSTRING(cast('01010101' as bit varying) from 2 for 2147483646) as "1010101"; +select substring(cast('01010101' as varbit) from 2 for 2147483646) as "1010101"; -select SUBSTRING(cast('01010101' as bit varying) from -10 for 2147483646) as "01010101"; +select substring(cast('01010101' as varbit) from -10 for 2147483646) as "01010101"; -select SUBSTRING(cast('01010101' as bit varying) from -10 for -2147483646) as error; +select substring(cast('01010101' as varbit) from -10 for -2147483646) as error; drop table varbit_table; @@ -129,81 +129,81 @@ select B'0111' | B'011'; select B'0010' # B'011101'; -select POSITION(B'1010' in B'0000101'); +select position(B'1010' in B'0000101'); -select POSITION(B'1010' in B'00001010'); +select position(B'1010' in B'00001010'); -select POSITION(B'1010' in B'00000101'); +select position(B'1010' in B'00000101'); -select POSITION(B'1010' in B'000001010'); +select position(B'1010' in B'000001010'); -select POSITION(B'' in B'00001010'); +select position(B'' in B'00001010'); -select POSITION(B'0' in B''); +select position(B'0' in B''); -select POSITION(B'' in B''); +select position(B'' in B''); -select POSITION(B'101101' in B'001011011011011000'); +select position(B'101101' in B'001011011011011000'); -select POSITION(B'10110110' in B'001011011011010'); +select position(B'10110110' in B'001011011011010'); -select POSITION(B'1011011011011' in B'001011011011011'); +select position(B'1011011011011' in B'001011011011011'); -select POSITION(B'1011011011011' in B'00001011011011011'); +select position(B'1011011011011' in B'00001011011011011'); -select POSITION(B'11101011' in B'11101011'); +select position(B'11101011' in B'11101011'); -select POSITION(B'11101011' in B'011101011'); +select position(B'11101011' in B'011101011'); -select POSITION(B'11101011' in B'00011101011'); +select position(B'11101011' in B'00011101011'); -select POSITION(B'11101011' in B'0000011101011'); +select position(B'11101011' in B'0000011101011'); -select POSITION(B'111010110' in B'111010110'); +select position(B'111010110' in B'111010110'); -select POSITION(B'111010110' in B'0111010110'); +select position(B'111010110' in B'0111010110'); -select POSITION(B'111010110' in B'000111010110'); +select position(B'111010110' in B'000111010110'); -select POSITION(B'111010110' in B'00000111010110'); +select position(B'111010110' in B'00000111010110'); -select POSITION(B'111010110' in B'11101011'); +select position(B'111010110' in B'11101011'); -select POSITION(B'111010110' in B'011101011'); +select position(B'111010110' in B'011101011'); -select POSITION(B'111010110' in B'00011101011'); +select position(B'111010110' in B'00011101011'); -select POSITION(B'111010110' in B'0000011101011'); +select position(B'111010110' in B'0000011101011'); -select POSITION(B'111010110' in B'111010110'); +select position(B'111010110' in B'111010110'); -select POSITION(B'111010110' in B'0111010110'); +select position(B'111010110' in B'0111010110'); -select POSITION(B'111010110' in B'000111010110'); +select position(B'111010110' in B'000111010110'); -select POSITION(B'111010110' in B'00000111010110'); +select position(B'111010110' in B'00000111010110'); -select POSITION(B'111010110' in B'000001110101111101011'); +select position(B'111010110' in B'000001110101111101011'); -select POSITION(B'111010110' in B'0000001110101111101011'); +select position(B'111010110' in B'0000001110101111101011'); -select POSITION(B'111010110' in B'000000001110101111101011'); +select position(B'111010110' in B'000000001110101111101011'); -select POSITION(B'111010110' in B'00000000001110101111101011'); +select position(B'111010110' in B'00000000001110101111101011'); -select POSITION(B'111010110' in B'0000011101011111010110'); +select position(B'111010110' in B'0000011101011111010110'); -select POSITION(B'111010110' in B'00000011101011111010110'); +select position(B'111010110' in B'00000011101011111010110'); -select POSITION(B'111010110' in B'0000000011101011111010110'); +select position(B'111010110' in B'0000000011101011111010110'); -select POSITION(B'111010110' in B'000000000011101011111010110'); +select position(B'111010110' in B'000000000011101011111010110'); -select POSITION(B'000000000011101011111010110' in B'000000000011101011111010110'); +select position(B'000000000011101011111010110' in B'000000000011101011111010110'); -select POSITION(B'00000000011101011111010110' in B'000000000011101011111010110'); +select position(B'00000000011101011111010110' in B'000000000011101011111010110'); -select POSITION(B'0000000000011101011111010110' in B'000000000011101011111010110'); +select position(B'0000000000011101011111010110' in B'000000000011101011111010110'); create table bit_shift_table (b bit(16)); @@ -217,7 +217,7 @@ insert into bit_shift_table select b >> 4 from bit_shift_table; insert into bit_shift_table select b >> 8 from bit_shift_table; -select POSITION(B'1101' in b), POSITION(B'11011' in b), b from bit_shift_table; +select position(B'1101' in b), position(B'11011' in b), b from bit_shift_table; select b, b >> 1 as bsr, b << 1 as bsl from bit_shift_table; @@ -242,30 +242,18 @@ create table varbit_shift_table (v bit varying(20)); insert into varbit_shift_table values (B'11011'); insert into varbit_shift_table -select - cast(v || B'0' as bit varying(6)) >> 1 -from - varbit_shift_table; +select cast(v || B'0' as bit varying(6)) >> 1 from varbit_shift_table; insert into varbit_shift_table -select - cast(v || B'00' as bit varying(8)) >> 2 -from - varbit_shift_table; +select cast(v || B'00' as bit varying(8)) >> 2 from varbit_shift_table; insert into varbit_shift_table -select - cast(v || B'0000' as bit varying(12)) >> 4 -from - varbit_shift_table; +select cast(v || B'0000' as bit varying(12)) >> 4 from varbit_shift_table; insert into varbit_shift_table -select - cast(v || B'00000000' as bit varying(20)) >> 8 -from - varbit_shift_table; +select cast(v || B'00000000' as bit varying(20)) >> 8 from varbit_shift_table; -select POSITION(B'1101' in v), POSITION(B'11011' in v), v from varbit_shift_table; +select position(B'1101' in v), position(B'11011' in v), v from varbit_shift_table; select v, v >> 1 as vsr, v << 1 as vsl from varbit_shift_table; @@ -281,13 +269,13 @@ select set_bit(B'0101011000100100', 15, 1); select set_bit(B'0101011000100100', 16, 1); -select OVERLAY(B'0101011100' placing '001' from 2 for 3); +select overlay(B'0101011100' placing '001' from 2 for 3); -select OVERLAY(B'0101011100' placing '101' from 6); +select overlay(B'0101011100' placing '101' from 6); -select OVERLAY(B'0101011100' placing '001' from 11); +select overlay(B'0101011100' placing '001' from 11); -select OVERLAY(B'0101011100' placing '001' from 20); +select overlay(B'0101011100' placing '001' from 20); select bit_count(cast(B'0101011100' as bit(10))); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__bit_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__bit_80.snap index 492dea8e9..b4600303b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__bit_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__bit_80.snap @@ -47,47 +47,33 @@ select v, length(v) as lv from varbit_table; select b, - SUBSTRING(b from 2 for 4) as sub_2_4, - SUBSTRING(b from 7 for 13) as sub_7_13, - SUBSTRING(b from 6) as sub_6 + substring(b from 2 for 4) as sub_2_4, + substring(b from 7 for 13) as sub_7_13, + substring(b from 6) as sub_6 from bit_table; select v, - SUBSTRING(v from 2 for 4) as sub_2_4, - SUBSTRING(v from 7 for 13) as sub_7_13, - SUBSTRING(v from 6) as sub_6 + substring(v from 2 for 4) as sub_2_4, + substring(v from 7 for 13) as sub_7_13, + substring(v from 6) as sub_6 from varbit_table; -select SUBSTRING(cast('01010101' as bit(8)) from 2 for 2147483646) as "1010101"; +select substring(cast('01010101' as bit(8)) from 2 for 2147483646) as "1010101"; select - SUBSTRING(cast('01010101' as bit(8)) - from -10 - for 2147483646) - as "01010101"; + substring(cast('01010101' as bit(8)) from -10 for 2147483646) as "01010101"; -select SUBSTRING(cast('01010101' as bit(8)) from -10 for -2147483646) as error; +select substring(cast('01010101' as bit(8)) from -10 for -2147483646) as error; -select - SUBSTRING(cast('01010101' as bit varying) - from 2 - for 2147483646) - as "1010101"; +select substring(cast('01010101' as varbit) from 2 for 2147483646) as "1010101"; select - SUBSTRING(cast('01010101' as bit varying) - from -10 - for 2147483646) - as "01010101"; + substring(cast('01010101' as varbit) from -10 for 2147483646) as "01010101"; -select - SUBSTRING(cast('01010101' as bit varying) - from -10 - for -2147483646) - as error; +select substring(cast('01010101' as varbit) from -10 for -2147483646) as error; drop table varbit_table; @@ -161,84 +147,84 @@ select B'0111' | B'011'; select B'0010' # B'011101'; -select POSITION(B'1010' in B'0000101'); +select position(B'1010' in B'0000101'); -select POSITION(B'1010' in B'00001010'); +select position(B'1010' in B'00001010'); -select POSITION(B'1010' in B'00000101'); +select position(B'1010' in B'00000101'); -select POSITION(B'1010' in B'000001010'); +select position(B'1010' in B'000001010'); -select POSITION(B'' in B'00001010'); +select position(B'' in B'00001010'); -select POSITION(B'0' in B''); +select position(B'0' in B''); -select POSITION(B'' in B''); +select position(B'' in B''); -select POSITION(B'101101' in B'001011011011011000'); +select position(B'101101' in B'001011011011011000'); -select POSITION(B'10110110' in B'001011011011010'); +select position(B'10110110' in B'001011011011010'); -select POSITION(B'1011011011011' in B'001011011011011'); +select position(B'1011011011011' in B'001011011011011'); -select POSITION(B'1011011011011' in B'00001011011011011'); +select position(B'1011011011011' in B'00001011011011011'); -select POSITION(B'11101011' in B'11101011'); +select position(B'11101011' in B'11101011'); -select POSITION(B'11101011' in B'011101011'); +select position(B'11101011' in B'011101011'); -select POSITION(B'11101011' in B'00011101011'); +select position(B'11101011' in B'00011101011'); -select POSITION(B'11101011' in B'0000011101011'); +select position(B'11101011' in B'0000011101011'); -select POSITION(B'111010110' in B'111010110'); +select position(B'111010110' in B'111010110'); -select POSITION(B'111010110' in B'0111010110'); +select position(B'111010110' in B'0111010110'); -select POSITION(B'111010110' in B'000111010110'); +select position(B'111010110' in B'000111010110'); -select POSITION(B'111010110' in B'00000111010110'); +select position(B'111010110' in B'00000111010110'); -select POSITION(B'111010110' in B'11101011'); +select position(B'111010110' in B'11101011'); -select POSITION(B'111010110' in B'011101011'); +select position(B'111010110' in B'011101011'); -select POSITION(B'111010110' in B'00011101011'); +select position(B'111010110' in B'00011101011'); -select POSITION(B'111010110' in B'0000011101011'); +select position(B'111010110' in B'0000011101011'); -select POSITION(B'111010110' in B'111010110'); +select position(B'111010110' in B'111010110'); -select POSITION(B'111010110' in B'0111010110'); +select position(B'111010110' in B'0111010110'); -select POSITION(B'111010110' in B'000111010110'); +select position(B'111010110' in B'000111010110'); -select POSITION(B'111010110' in B'00000111010110'); +select position(B'111010110' in B'00000111010110'); -select POSITION(B'111010110' in B'000001110101111101011'); +select position(B'111010110' in B'000001110101111101011'); -select POSITION(B'111010110' in B'0000001110101111101011'); +select position(B'111010110' in B'0000001110101111101011'); -select POSITION(B'111010110' in B'000000001110101111101011'); +select position(B'111010110' in B'000000001110101111101011'); -select POSITION(B'111010110' in B'00000000001110101111101011'); +select position(B'111010110' in B'00000000001110101111101011'); -select POSITION(B'111010110' in B'0000011101011111010110'); +select position(B'111010110' in B'0000011101011111010110'); -select POSITION(B'111010110' in B'00000011101011111010110'); +select position(B'111010110' in B'00000011101011111010110'); -select POSITION(B'111010110' in B'0000000011101011111010110'); +select position(B'111010110' in B'0000000011101011111010110'); -select POSITION(B'111010110' in B'000000000011101011111010110'); +select position(B'111010110' in B'000000000011101011111010110'); select - POSITION(B'000000000011101011111010110' in B'000000000011101011111010110'); + position(B'000000000011101011111010110' in B'000000000011101011111010110'); select - POSITION(B'00000000011101011111010110' in B'000000000011101011111010110'); + position(B'00000000011101011111010110' in B'000000000011101011111010110'); select - POSITION(B'0000000000011101011111010110' in B'000000000011101011111010110'); + position(B'0000000000011101011111010110' in B'000000000011101011111010110'); create table bit_shift_table (b bit(16)); @@ -252,7 +238,7 @@ insert into bit_shift_table select b >> 4 from bit_shift_table; insert into bit_shift_table select b >> 8 from bit_shift_table; -select POSITION(B'1101' in b), POSITION(B'11011' in b), b from bit_shift_table; +select position(B'1101' in b), position(B'11011' in b), b from bit_shift_table; select b, b >> 1 as bsr, b << 1 as bsl from bit_shift_table; @@ -277,35 +263,20 @@ create table varbit_shift_table (v bit varying(20)); insert into varbit_shift_table values (B'11011'); insert into varbit_shift_table -select - cast(v || B'0' as bit varying(6)) >> 1 -from - varbit_shift_table; +select cast(v || B'0' as bit varying(6)) >> 1 from varbit_shift_table; insert into varbit_shift_table -select - cast(v || B'00' as bit varying(8)) >> 2 -from - varbit_shift_table; +select cast(v || B'00' as bit varying(8)) >> 2 from varbit_shift_table; insert into varbit_shift_table -select - cast(v || B'0000' as bit varying(12)) >> - 4 -from - varbit_shift_table; +select cast(v || B'0000' as bit varying(12)) >> 4 from varbit_shift_table; insert into varbit_shift_table -select - cast(v || B'00000000' - as bit varying(20)) >> - 8 -from - varbit_shift_table; +select cast(v || B'00000000' as bit varying(20)) >> 8 from varbit_shift_table; select - POSITION(B'1101' in v), - POSITION(B'11011' in v), + position(B'1101' in v), + position(B'11011' in v), v from varbit_shift_table; @@ -324,13 +295,13 @@ select set_bit(B'0101011000100100', 15, 1); select set_bit(B'0101011000100100', 16, 1); -select OVERLAY(B'0101011100' placing '001' from 2 for 3); +select overlay(B'0101011100' placing '001' from 2 for 3); -select OVERLAY(B'0101011100' placing '101' from 6); +select overlay(B'0101011100' placing '101' from 6); -select OVERLAY(B'0101011100' placing '001' from 11); +select overlay(B'0101011100' placing '001' from 11); -select OVERLAY(B'0101011100' placing '001' from 20); +select overlay(B'0101011100' placing '001' from 20); select bit_count(cast(B'0101011100' as bit(10))); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__bitmapops_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__bitmapops_100.snap index 01c9f3872..d3d22b3d2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__bitmapops_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__bitmapops_100.snap @@ -18,9 +18,9 @@ select from generate_series(1, 70000) as r; -create index "i_bmtest_a" on bmscantest using btree (a); +create index i_bmtest_a on bmscantest using btree (a); -create index "i_bmtest_b" on bmscantest using btree (b); +create index i_bmtest_b on bmscantest using btree (b); set enable_indexscan = 'false'; @@ -28,12 +28,12 @@ set enable_seqscan = 'false'; set work_mem = 64; -select COUNT(*) from bmscantest where a = 1 and b = 1; +select count(*) from bmscantest where a = 1 and b = 1; -vacuum (FREEZE) bmscantest; +vacuum (freeze) bmscantest; -select COUNT(*) from bmscantest where a = 1 and b = 1; +select count(*) from bmscantest where a = 1 and b = 1; -select COUNT(*) from bmscantest where a = 1 or b = 1; +select count(*) from bmscantest where a = 1 or b = 1; drop table bmscantest; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__bitmapops_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__bitmapops_80.snap index 01c9f3872..d3d22b3d2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__bitmapops_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__bitmapops_80.snap @@ -18,9 +18,9 @@ select from generate_series(1, 70000) as r; -create index "i_bmtest_a" on bmscantest using btree (a); +create index i_bmtest_a on bmscantest using btree (a); -create index "i_bmtest_b" on bmscantest using btree (b); +create index i_bmtest_b on bmscantest using btree (b); set enable_indexscan = 'false'; @@ -28,12 +28,12 @@ set enable_seqscan = 'false'; set work_mem = 64; -select COUNT(*) from bmscantest where a = 1 and b = 1; +select count(*) from bmscantest where a = 1 and b = 1; -vacuum (FREEZE) bmscantest; +vacuum (freeze) bmscantest; -select COUNT(*) from bmscantest where a = 1 and b = 1; +select count(*) from bmscantest where a = 1 and b = 1; -select COUNT(*) from bmscantest where a = 1 or b = 1; +select count(*) from bmscantest where a = 1 or b = 1; drop table bmscantest; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__boolean_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__boolean_100.snap index 709fc0f06..ee3f642b4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__boolean_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__boolean_100.snap @@ -9,51 +9,51 @@ select true as "true"; select false as "false"; -select cast('t' as boolean) as "true"; +select cast('t' as bool) as "true"; -select cast(' f ' as boolean) as "false"; +select cast(' f ' as bool) as "false"; -select cast('true' as boolean) as "true"; +select cast('true' as bool) as "true"; -select cast('test' as boolean) as error; +select cast('test' as bool) as error; -select cast('false' as boolean) as "false"; +select cast('false' as bool) as "false"; -select cast('foo' as boolean) as error; +select cast('foo' as bool) as error; -select cast('y' as boolean) as "true"; +select cast('y' as bool) as "true"; -select cast('yes' as boolean) as "true"; +select cast('yes' as bool) as "true"; -select cast('yeah' as boolean) as error; +select cast('yeah' as bool) as error; -select cast('n' as boolean) as "false"; +select cast('n' as bool) as "false"; -select cast('no' as boolean) as "false"; +select cast('no' as bool) as "false"; -select cast('nay' as boolean) as error; +select cast('nay' as bool) as error; -select cast('on' as boolean) as "true"; +select cast('on' as bool) as "true"; -select cast('off' as boolean) as "false"; +select cast('off' as bool) as "false"; -select cast('of' as boolean) as "false"; +select cast('of' as bool) as "false"; -select cast('o' as boolean) as error; +select cast('o' as bool) as error; -select cast('on_' as boolean) as error; +select cast('on_' as bool) as error; -select cast('off_' as boolean) as error; +select cast('off_' as bool) as error; -select cast('1' as boolean) as "true"; +select cast('1' as bool) as "true"; -select cast('11' as boolean) as error; +select cast('11' as bool) as error; -select cast('0' as boolean) as "false"; +select cast('0' as bool) as "false"; -select cast('000' as boolean) as error; +select cast('000' as bool) as error; -select cast('' as boolean) as error; +select cast('' as bool) as error; select pg_input_is_valid('true', 'bool'); @@ -61,33 +61,31 @@ select pg_input_is_valid('asdf', 'bool'); select * from pg_input_error_info('junk', 'bool'); -select cast('t' as boolean) or cast('f' as boolean) as "true"; +select cast('t' as bool) or cast('f' as bool) as "true"; -select cast('t' as boolean) and cast('f' as boolean) as "false"; +select cast('t' as bool) and cast('f' as bool) as "false"; -select not cast('f' as boolean) as "true"; +select not cast('f' as bool) as "true"; -select cast('t' as boolean) = cast('f' as boolean) as "false"; +select cast('t' as bool) = cast('f' as bool) as "false"; -select cast('t' as boolean) <> cast('f' as boolean) as "true"; +select cast('t' as bool) <> cast('f' as bool) as "true"; -select cast('t' as boolean) > cast('f' as boolean) as "true"; +select cast('t' as bool) > cast('f' as bool) as "true"; -select cast('t' as boolean) >= cast('f' as boolean) as "true"; +select cast('t' as bool) >= cast('f' as bool) as "true"; -select cast('f' as boolean) < cast('t' as boolean) as "true"; +select cast('f' as bool) < cast('t' as bool) as "true"; -select cast('f' as boolean) <= cast('t' as boolean) as "true"; +select cast('f' as bool) <= cast('t' as bool) as "true"; select cast(cast('TrUe' as text) as boolean) as "true", cast(cast('fAlse' as text) as boolean) as "false"; select - cast(cast(' true ' as text) as boolean) - as "true", - cast(cast(' FALSE' as text) as boolean) - as "false"; + cast(cast(' true ' as text) as boolean) as "true", + cast(cast(' FALSE' as text) as boolean) as "false"; select cast(cast(true as boolean) as text) as "true", @@ -97,37 +95,37 @@ select cast(cast(' tru e ' as text) as boolean) as invalid; select cast(cast('' as text) as boolean) as invalid; -create table booltbl1 (f1 boolean); +create table booltbl1 (f1 bool); -insert into booltbl1 (f1) values (cast('t' as boolean)); +insert into booltbl1 (f1) values (cast('t' as bool)); -insert into booltbl1 (f1) values (cast('True' as boolean)); +insert into booltbl1 (f1) values (cast('True' as bool)); -insert into booltbl1 (f1) values (cast('true' as boolean)); +insert into booltbl1 (f1) values (cast('true' as bool)); select booltbl1.* from booltbl1; -select booltbl1.* from booltbl1 where f1 = cast('true' as boolean); +select booltbl1.* from booltbl1 where f1 = cast('true' as bool); -select booltbl1.* from booltbl1 where f1 <> cast('false' as boolean); +select booltbl1.* from booltbl1 where f1 <> cast('false' as bool); -select booltbl1.* from booltbl1 where booleq(cast('false' as boolean), f1); +select booltbl1.* from booltbl1 where booleq(cast('false' as bool), f1); -insert into booltbl1 (f1) values (cast('f' as boolean)); +insert into booltbl1 (f1) values (cast('f' as bool)); -select booltbl1.* from booltbl1 where f1 = cast('false' as boolean); +select booltbl1.* from booltbl1 where f1 = cast('false' as bool); -create table booltbl2 (f1 boolean); +create table booltbl2 (f1 bool); -insert into booltbl2 (f1) values (cast('f' as boolean)); +insert into booltbl2 (f1) values (cast('f' as bool)); -insert into booltbl2 (f1) values (cast('false' as boolean)); +insert into booltbl2 (f1) values (cast('false' as bool)); -insert into booltbl2 (f1) values (cast('False' as boolean)); +insert into booltbl2 (f1) values (cast('False' as bool)); -insert into booltbl2 (f1) values (cast('FALSE' as boolean)); +insert into booltbl2 (f1) values (cast('FALSE' as bool)); -insert into booltbl2 (f1) values (cast('XXX' as boolean)); +insert into booltbl2 (f1) values (cast('XXX' as bool)); select booltbl2.* from booltbl2; @@ -142,8 +140,7 @@ from booltbl1, booltbl2 where - booltbl2.f1 = booltbl1.f1 and - booltbl1.f1 = cast('false' as boolean); + booltbl2.f1 = booltbl1.f1 and booltbl1.f1 = cast('false' as bool); select booltbl1.*, @@ -152,8 +149,7 @@ from booltbl1, booltbl2 where - booltbl2.f1 = booltbl1.f1 or - booltbl1.f1 = cast('true' as boolean) + booltbl2.f1 = booltbl1.f1 or booltbl1.f1 = cast('true' as bool) order by booltbl1.f1, booltbl2.f1; @@ -175,7 +171,7 @@ select f1 from booltbl2 where f1 is not true; create table booltbl3 ( d text, - b boolean, + b bool, o int ); @@ -198,9 +194,9 @@ from order by o; create table booltbl4 ( - isfalse boolean, - istrue boolean, - isnul boolean + isfalse bool, + istrue bool, + isnul bool ); insert into booltbl4 values (false, true, null); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__boolean_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__boolean_80.snap index 9fc85e714..d72cd1bc5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__boolean_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__boolean_80.snap @@ -9,51 +9,51 @@ select true as "true"; select false as "false"; -select cast('t' as boolean) as "true"; +select cast('t' as bool) as "true"; -select cast(' f ' as boolean) as "false"; +select cast(' f ' as bool) as "false"; -select cast('true' as boolean) as "true"; +select cast('true' as bool) as "true"; -select cast('test' as boolean) as error; +select cast('test' as bool) as error; -select cast('false' as boolean) as "false"; +select cast('false' as bool) as "false"; -select cast('foo' as boolean) as error; +select cast('foo' as bool) as error; -select cast('y' as boolean) as "true"; +select cast('y' as bool) as "true"; -select cast('yes' as boolean) as "true"; +select cast('yes' as bool) as "true"; -select cast('yeah' as boolean) as error; +select cast('yeah' as bool) as error; -select cast('n' as boolean) as "false"; +select cast('n' as bool) as "false"; -select cast('no' as boolean) as "false"; +select cast('no' as bool) as "false"; -select cast('nay' as boolean) as error; +select cast('nay' as bool) as error; -select cast('on' as boolean) as "true"; +select cast('on' as bool) as "true"; -select cast('off' as boolean) as "false"; +select cast('off' as bool) as "false"; -select cast('of' as boolean) as "false"; +select cast('of' as bool) as "false"; -select cast('o' as boolean) as error; +select cast('o' as bool) as error; -select cast('on_' as boolean) as error; +select cast('on_' as bool) as error; -select cast('off_' as boolean) as error; +select cast('off_' as bool) as error; -select cast('1' as boolean) as "true"; +select cast('1' as bool) as "true"; -select cast('11' as boolean) as error; +select cast('11' as bool) as error; -select cast('0' as boolean) as "false"; +select cast('0' as bool) as "false"; -select cast('000' as boolean) as error; +select cast('000' as bool) as error; -select cast('' as boolean) as error; +select cast('' as bool) as error; select pg_input_is_valid('true', 'bool'); @@ -61,79 +61,71 @@ select pg_input_is_valid('asdf', 'bool'); select * from pg_input_error_info('junk', 'bool'); -select cast('t' as boolean) or cast('f' as boolean) as "true"; +select cast('t' as bool) or cast('f' as bool) as "true"; -select cast('t' as boolean) and cast('f' as boolean) as "false"; +select cast('t' as bool) and cast('f' as bool) as "false"; -select not cast('f' as boolean) as "true"; +select not cast('f' as bool) as "true"; -select cast('t' as boolean) = cast('f' as boolean) as "false"; +select cast('t' as bool) = cast('f' as bool) as "false"; -select cast('t' as boolean) <> cast('f' as boolean) as "true"; +select cast('t' as bool) <> cast('f' as bool) as "true"; -select cast('t' as boolean) > cast('f' as boolean) as "true"; +select cast('t' as bool) > cast('f' as bool) as "true"; -select cast('t' as boolean) >= cast('f' as boolean) as "true"; +select cast('t' as bool) >= cast('f' as bool) as "true"; -select cast('f' as boolean) < cast('t' as boolean) as "true"; +select cast('f' as bool) < cast('t' as bool) as "true"; -select cast('f' as boolean) <= cast('t' as boolean) as "true"; +select cast('f' as bool) <= cast('t' as bool) as "true"; select - cast(cast('TrUe' as text) as boolean) - as "true", - cast(cast('fAlse' as text) as boolean) - as "false"; + cast(cast('TrUe' as text) as boolean) as "true", + cast(cast('fAlse' as text) as boolean) as "false"; select - cast(cast(' true ' as text) - as boolean) - as "true", - cast(cast(' FALSE' as text) - as boolean) - as "false"; + cast(cast(' true ' as text) as boolean) as "true", + cast(cast(' FALSE' as text) as boolean) as "false"; select - cast(cast(true as boolean) as text) - as "true", - cast(cast(false as boolean) as text) - as "false"; + cast(cast(true as boolean) as text) as "true", + cast(cast(false as boolean) as text) as "false"; select cast(cast(' tru e ' as text) as boolean) as invalid; select cast(cast('' as text) as boolean) as invalid; -create table booltbl1 (f1 boolean); +create table booltbl1 (f1 bool); -insert into booltbl1 (f1) values (cast('t' as boolean)); +insert into booltbl1 (f1) values (cast('t' as bool)); -insert into booltbl1 (f1) values (cast('True' as boolean)); +insert into booltbl1 (f1) values (cast('True' as bool)); -insert into booltbl1 (f1) values (cast('true' as boolean)); +insert into booltbl1 (f1) values (cast('true' as bool)); select booltbl1.* from booltbl1; -select booltbl1.* from booltbl1 where f1 = cast('true' as boolean); +select booltbl1.* from booltbl1 where f1 = cast('true' as bool); -select booltbl1.* from booltbl1 where f1 <> cast('false' as boolean); +select booltbl1.* from booltbl1 where f1 <> cast('false' as bool); -select booltbl1.* from booltbl1 where booleq(cast('false' as boolean), f1); +select booltbl1.* from booltbl1 where booleq(cast('false' as bool), f1); -insert into booltbl1 (f1) values (cast('f' as boolean)); +insert into booltbl1 (f1) values (cast('f' as bool)); -select booltbl1.* from booltbl1 where f1 = cast('false' as boolean); +select booltbl1.* from booltbl1 where f1 = cast('false' as bool); -create table booltbl2 (f1 boolean); +create table booltbl2 (f1 bool); -insert into booltbl2 (f1) values (cast('f' as boolean)); +insert into booltbl2 (f1) values (cast('f' as bool)); -insert into booltbl2 (f1) values (cast('false' as boolean)); +insert into booltbl2 (f1) values (cast('false' as bool)); -insert into booltbl2 (f1) values (cast('False' as boolean)); +insert into booltbl2 (f1) values (cast('False' as bool)); -insert into booltbl2 (f1) values (cast('FALSE' as boolean)); +insert into booltbl2 (f1) values (cast('FALSE' as bool)); -insert into booltbl2 (f1) values (cast('XXX' as boolean)); +insert into booltbl2 (f1) values (cast('XXX' as bool)); select booltbl2.* from booltbl2; @@ -162,8 +154,7 @@ from booltbl1, booltbl2 where - booltbl2.f1 = booltbl1.f1 and - booltbl1.f1 = cast('false' as boolean); + booltbl2.f1 = booltbl1.f1 and booltbl1.f1 = cast('false' as bool); select booltbl1.*, @@ -172,8 +163,7 @@ from booltbl1, booltbl2 where - booltbl2.f1 = booltbl1.f1 or - booltbl1.f1 = cast('true' as boolean) + booltbl2.f1 = booltbl1.f1 or booltbl1.f1 = cast('true' as bool) order by booltbl1.f1, booltbl2.f1; @@ -195,7 +185,7 @@ select f1 from booltbl2 where f1 is not true; create table booltbl3 ( d text, - b boolean, + b bool, o int ); @@ -218,9 +208,9 @@ from order by o; create table booltbl4 ( - isfalse boolean, - istrue boolean, - isnul boolean + isfalse bool, + istrue bool, + isnul bool ); insert into booltbl4 values (false, true, null); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__box_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__box_100.snap index 347bcb24b..6782e7100 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__box_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__box_100.snap @@ -64,7 +64,7 @@ create temporary table box_temp (f1 box); insert into box_temp select box(point(i, i), point(i * 2, i * 2)) from generate_series(1, 50) as i; -create index "box_spgist" on box_temp using spgist (f1); +create index box_spgist on box_temp using spgist (f1); insert into box_temp values @@ -137,33 +137,23 @@ create table quad_box_tbl ( insert into quad_box_tbl select (x - 1) * 100 + y, - box( - point(x * 10, y * 10), - point(x * 10 + 5, y * 10 + 5) - ) + box(point(x * 10, y * 10), point(x * 10 + 5, y * 10 + 5)) from generate_series(1, 100) as x, generate_series(1, 100) as y; insert into quad_box_tbl -select - i, - '((200, 300),(210, 310))' -from - generate_series(10001, 11000) as i; +select i, '((200, 300),(210, 310))' from generate_series(10001, 11000) as i; insert into quad_box_tbl values (11001, null), (11002, null), - ( - 11003, - '((-infinity,-infinity),(infinity,infinity))' - ), + (11003, '((-infinity,-infinity),(infinity,infinity))'), (11004, '((-infinity,100),(-infinity,500))'), (11005, '((-infinity,-infinity),(700,infinity))'); -create index "quad_box_tbl_idx" on quad_box_tbl using spgist (b); +create index quad_box_tbl_idx on quad_box_tbl using spgist (b); set enable_seqscan = 'on'; @@ -174,7 +164,7 @@ set enable_bitmapscan = off; create table quad_box_tbl_ord_seq1 as select - RANK() over (order by b <-> cast('123,456' as point)) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -183,7 +173,7 @@ as create table quad_box_tbl_ord_seq2 as select - RANK() over (order by b <-> cast('123,456' as point)) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -197,38 +187,38 @@ set enable_indexscan = 'on'; set enable_bitmapscan = 'on'; -select COUNT(*) from quad_box_tbl where b << cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b << cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b &< cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b &< cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b && cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b && cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b &> cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b &> cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b >> cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b >> cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b >> cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b >> cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b <<| cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b <<| cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b &<| cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b &<| cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b |&> cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b |&> cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b |>> cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b |>> cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b @> cast('((201,301),(202,303))' as box); +select count(*) from quad_box_tbl where b @> cast('((201,301),(202,303))' as box); -select COUNT(*) from quad_box_tbl where b <@ cast('((100,200),(300,500))' as box); +select count(*) from quad_box_tbl where b <@ cast('((100,200),(300,500))' as box); -select COUNT(*) from quad_box_tbl where b ~= cast('((200,300),(205,305))' as box); +select count(*) from quad_box_tbl where b ~= cast('((200,300),(205,305))' as box); set enable_indexscan = 'on'; set enable_bitmapscan = off; select - RANK() over (order by b <-> cast('123,456' as point)) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -237,7 +227,7 @@ from create temporary table quad_box_tbl_ord_idx1 as select - RANK() over (order by b <-> cast('123,456' as point)) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -252,14 +242,13 @@ from on seq.n = idx.n and seq.id = idx.id and ( - seq.dist = idx.dist or - (seq.dist is null and idx.dist is null) + seq.dist = idx.dist or (seq.dist is null and idx.dist is null) ) where seq.id is null or idx.id is null; select - RANK() over (order by b <-> cast('123,456' as point)) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -270,7 +259,7 @@ where create temporary table quad_box_tbl_ord_idx2 as select - RANK() over (order by b <-> cast('123,456' as point)) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -287,8 +276,7 @@ from on seq.n = idx.n and seq.id = idx.id and ( - seq.dist = idx.dist or - (seq.dist is null and idx.dist is null) + seq.dist = idx.dist or (seq.dist is null and idx.dist is null) ) where seq.id is null or idx.id is null; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__box_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__box_80.snap index c18cd22d3..d162a7a1e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__box_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__box_80.snap @@ -70,12 +70,9 @@ select height(f1), width(f1) from box_tbl; create temporary table box_temp (f1 box); insert into box_temp -select - box(point(i, i), point(i * 2, i * 2)) -from - generate_series(1, 50) as i; +select box(point(i, i), point(i * 2, i * 2)) from generate_series(1, 50) as i; -create index "box_spgist" on box_temp using spgist (f1); +create index box_spgist on box_temp using spgist (f1); insert into box_temp values @@ -84,9 +81,7 @@ values ('(-3,4.3333333333)(40,1)'), ('(0,100)(0,infinity)'), ('(-infinity,0)(0,infinity)'), - ( - '(-infinity,-infinity)(infinity,infinity)' - ); + ('(-infinity,-infinity)(infinity,infinity)'); set enable_seqscan = 'false'; @@ -150,39 +145,23 @@ create table quad_box_tbl ( insert into quad_box_tbl select (x - 1) * 100 + y, - box( - point(x * 10, y * 10), - point(x * 10 + 5, y * 10 + 5) - ) + box(point(x * 10, y * 10), point(x * 10 + 5, y * 10 + 5)) from generate_series(1, 100) as x, generate_series(1, 100) as y; insert into quad_box_tbl -select - i, - '((200, 300),(210, 310))' -from - generate_series(10001, 11000) as i; +select i, '((200, 300),(210, 310))' from generate_series(10001, 11000) as i; insert into quad_box_tbl values (11001, null), (11002, null), - ( - 11003, - '((-infinity,-infinity),(infinity,infinity))' - ), - ( - 11004, - '((-infinity,100),(-infinity,500))' - ), - ( - 11005, - '((-infinity,-infinity),(700,infinity))' - ); - -create index "quad_box_tbl_idx" on quad_box_tbl using spgist (b); + (11003, '((-infinity,-infinity),(infinity,infinity))'), + (11004, '((-infinity,100),(-infinity,500))'), + (11005, '((-infinity,-infinity),(700,infinity))'); + +create index quad_box_tbl_idx on quad_box_tbl using spgist (b); set enable_seqscan = 'on'; @@ -193,9 +172,7 @@ set enable_bitmapscan = off; create table quad_box_tbl_ord_seq1 as select - RANK() over ( - order by b <-> cast('123,456' as point) - ) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -204,16 +181,13 @@ as create table quad_box_tbl_ord_seq2 as select - RANK() over ( - order by b <-> cast('123,456' as point) - ) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from quad_box_tbl where - b <@ - cast('((200,300),(500,600))' as box); + b <@ cast('((200,300),(500,600))' as box); set enable_seqscan = off; @@ -222,117 +196,102 @@ set enable_indexscan = 'on'; set enable_bitmapscan = 'on'; select - COUNT(*) + count(*) from quad_box_tbl where - b << - cast('((100,200),(300,500))' as box); + b << cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b &< - cast('((100,200),(300,500))' as box); + b &< cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b && - cast('((100,200),(300,500))' as box); + b && cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b &> - cast('((100,200),(300,500))' as box); + b &> cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b >> - cast('((100,200),(300,500))' as box); + b >> cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b >> - cast('((100,200),(300,500))' as box); + b >> cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b <<| - cast('((100,200),(300,500))' as box); + b <<| cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b &<| - cast('((100,200),(300,500))' as box); + b &<| cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b |&> - cast('((100,200),(300,500))' as box); + b |&> cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b |>> - cast('((100,200),(300,500))' as box); + b |>> cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b @> - cast('((201,301),(202,303))' as box); + b @> cast('((201,301),(202,303))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b <@ - cast('((100,200),(300,500))' as box); + b <@ cast('((100,200),(300,500))' as box); select - COUNT(*) + count(*) from quad_box_tbl where - b ~= - cast('((200,300),(205,305))' as box); + b ~= cast('((200,300),(205,305))' as box); set enable_indexscan = 'on'; set enable_bitmapscan = off; select - RANK() over ( - order by b <-> cast('123,456' as point) - ) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -341,9 +300,7 @@ from create temporary table quad_box_tbl_ord_idx1 as select - RANK() over ( - order by b <-> cast('123,456' as point) - ) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from @@ -358,37 +315,30 @@ from on seq.n = idx.n and seq.id = idx.id and ( - seq.dist = idx.dist or - (seq.dist is null and idx.dist is null) + seq.dist = idx.dist or (seq.dist is null and idx.dist is null) ) where seq.id is null or idx.id is null; select - RANK() over ( - order by b <-> cast('123,456' as point) - ) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from quad_box_tbl where - b <@ - cast('((200,300),(500,600))' as box); + b <@ cast('((200,300),(500,600))' as box); create temporary table quad_box_tbl_ord_idx2 as select - RANK() over ( - order by b <-> cast('123,456' as point) - ) as n, + rank() over (order by b <-> cast('123,456' as point)) as n, b <-> cast('123,456' as point) as dist, id from quad_box_tbl where - b <@ - cast('((200,300),(500,600))' as box); + b <@ cast('((200,300),(500,600))' as box); select * @@ -399,8 +349,7 @@ from on seq.n = idx.n and seq.id = idx.id and ( - seq.dist = idx.dist or - (seq.dist is null and idx.dist is null) + seq.dist = idx.dist or (seq.dist is null and idx.dist is null) ) where seq.id is null or idx.id is null; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_100.snap index 952c34b66..7e44f9831 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_100.snap @@ -47,37 +47,20 @@ select cast(unique1 as oid), cast(format('(%s,%s)', tenthous, twenty) as tid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) - as macaddr), + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), cast('10.2.3.4/24' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast(substr(stringu1, 1, 1) as bpchar), cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * cast('18.5 second' as interval), - cast('1942-07-23 03:05:09' as timestamp) + - tenthous * cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + - thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * cast('12 minutes' as interval) - ) - ), - cast('01:30:20+02' as time with time zone) + - hundred * cast('15 seconds' as interval), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), + cast('1942-07-23 03:05:09' as timestamp) + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20+02' as timetz) + hundred * cast('15 seconds' as interval), cast(thousand as bit(10)), - cast(cast(tenthous as bit(16)) as bit varying), - cast(tenthous as numeric(36, 30)) * fivethous * - even / - (hundred + 1), + cast(cast(tenthous as bit(16)) as varbit), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -91,12 +74,8 @@ select ) as uuid), int4range(thousand, twothousand), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn), - box( - point(odd, even), - point(thousand, twothousand) - ) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn), + box(point(odd, even), point(thousand, twothousand)) from tenk1 order by unique2 @@ -104,10 +83,8 @@ limit 100; insert into brintest (inetcol, cidrcol, int4rangecol) select - cast('fe80::6e40:8ff:fea9:8c46' as inet) + - tenthous, - cast('fe80::6e40:8ff:fea9:8c46' as cidr) + - tenthous, + cast('fe80::6e40:8ff:fea9:8c46' as inet) + tenthous, + cast('fe80::6e40:8ff:fea9:8c46' as cidr) + tenthous, cast('empty' as int4range) from tenk1 @@ -115,10 +92,7 @@ order by thousand, tenthous limit 25; -create index "brinidx" -on brintest -using brin -( +create index brinidx on brintest using brin ( byteacol, charcol, namecol, @@ -171,13 +145,7 @@ values '{AAAAAA, AAAAAA, BNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAA, ZZZZZZ, ZZZZZZ}', '{100, 100, 1, 100, 100}' ), - ( - 'charcol', - '"char"', - '{>, >=, =, <=, <}', - '{A, A, M, Z, Z}', - '{97, 100, 6, 100, 98}' - ), + ('charcol', '"char"', '{>, >=, =, <=, <}', '{A, A, M, Z, Z}', '{97, 100, 6, 100, 98}'), ( 'namecol', 'name', @@ -185,20 +153,8 @@ values '{AAAAAA, AAAAAA, MAAAAA, ZZAAAA, ZZAAAA}', '{100, 100, 2, 100, 100}' ), - ( - 'int2col', - 'int2', - '{>, >=, =, <=, <}', - '{0, 0, 800, 999, 999}', - '{100, 100, 1, 100, 100}' - ), - ( - 'int2col', - 'int4', - '{>, >=, =, <=, <}', - '{0, 0, 800, 999, 1999}', - '{100, 100, 1, 100, 100}' - ), + ('int2col', 'int2', '{>, >=, =, <=, <}', '{0, 0, 800, 999, 999}', '{100, 100, 1, 100, 100}'), + ('int2col', 'int4', '{>, >=, =, <=, <}', '{0, 0, 800, 999, 1999}', '{100, 100, 1, 100, 100}'), ( 'int2col', 'int8', @@ -206,20 +162,8 @@ values '{0, 0, 800, 999, 1428427143}', '{100, 100, 1, 100, 100}' ), - ( - 'int4col', - 'int2', - '{>, >=, =, <=, <}', - '{0, 0, 800, 1999, 1999}', - '{100, 100, 1, 100, 100}' - ), - ( - 'int4col', - 'int4', - '{>, >=, =, <=, <}', - '{0, 0, 800, 1999, 1999}', - '{100, 100, 1, 100, 100}' - ), + ('int4col', 'int2', '{>, >=, =, <=, <}', '{0, 0, 800, 1999, 1999}', '{100, 100, 1, 100, 100}'), + ('int4col', 'int4', '{>, >=, =, <=, <}', '{0, 0, 800, 1999, 1999}', '{100, 100, 1, 100, 100}'), ( 'int4col', 'int8', @@ -227,20 +171,8 @@ values '{0, 0, 800, 1999, 1428427143}', '{100, 100, 1, 100, 100}' ), - ( - 'int8col', - 'int2', - '{>, >=}', - '{0, 0}', - '{100, 100}' - ), - ( - 'int8col', - 'int4', - '{>, >=}', - '{0, 0}', - '{100, 100}' - ), + ('int8col', 'int2', '{>, >=}', '{0, 0}', '{100, 100}'), + ('int8col', 'int4', '{>, >=}', '{0, 0}', '{100, 100}'), ( 'int8col', 'int8', @@ -255,13 +187,7 @@ values '{ABABAB, ABABAB, BNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAA, ZZAAAA, ZZAAAA}', '{100, 100, 1, 100, 100}' ), - ( - 'oidcol', - 'oid', - '{>, >=, =, <=, <}', - '{0, 0, 8800, 9999, 9999}', - '{100, 100, 1, 100, 100}' - ), + ('oidcol', 'oid', '{>, >=, =, <=, <}', '{0, 0, 8800, 9999, 9999}', '{100, 100, 1, 100, 100}'), ( 'tidcol', 'tid', @@ -283,20 +209,8 @@ values '{0.0103093, 0.0103093, 1, 1, 1}', '{100, 100, 4, 100, 96}' ), - ( - 'float8col', - 'float4', - '{>, >=, =, <=, <}', - '{0, 0, 0, 1.98, 1.98}', - '{99, 100, 1, 100, 100}' - ), - ( - 'float8col', - 'float8', - '{>, >=, =, <=, <}', - '{0, 0, 0, 1.98, 1.98}', - '{99, 100, 1, 100, 100}' - ), + ('float8col', 'float4', '{>, >=, =, <=, <}', '{0, 0, 0, 1.98, 1.98}', '{99, 100, 1, 100, 100}'), + ('float8col', 'float8', '{>, >=, =, <=, <}', '{0, 0, 0, 1.98, 1.98}', '{99, 100, 1, 100, 100}'), ( 'macaddrcol', 'macaddr', @@ -360,13 +274,7 @@ values '{fe80::/32, fe80::6e40:8ff:fea9:8c46, fe80::/32, fe80::6e40:8ff:fea9:8c46}', '{25, 1, 25, 1}' ), - ( - 'bpcharcol', - 'bpchar', - '{>, >=, =, <=, <}', - '{A, A, W, Z, Z}', - '{97, 100, 6, 100, 98}' - ), + ('bpcharcol', 'bpchar', '{>, >=, =, <=, <}', '{A, A, W, Z, Z}', '{97, 100, 6, 100, 98}'), ( 'datecol', 'date', @@ -466,9 +374,7 @@ values '{0/1200, 0/1200, 44/455222, 198/1999799, 198/1999799, NULL, NULL}', '{100, 100, 1, 100, 100, 25, 100}' ), - ( - 'boxcol', 'point', '{@>}', '{"(500,43)"}', '{11}' - ), + ('boxcol', 'point', '{@>}', '{"(500,43)"}', '{11}'), ( 'boxcol', 'box', @@ -477,8 +383,7 @@ values '{100, 100, 100, 99, 96, 100, 100, 99, 96, 1, 99, 1}' ); -do -$do$ +do $x$ DECLARE r record; r2 record; @@ -557,7 +462,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$do$; +$x$; reset enable_seqscan; @@ -575,37 +480,20 @@ select cast(unique1 as oid), cast(format('(%s,%s)', tenthous, twenty) as tid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) - as macaddr), + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), cast('10.2.3.4' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast(substr(stringu1, 1, 1) as bpchar), cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * cast('18.5 second' as interval), - cast('1942-07-23 03:05:09' as timestamp) + - tenthous * cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + - thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * cast('12 minutes' as interval) - ) - ), - cast('01:30:20' as time with time zone) + - hundred * cast('15 seconds' as interval), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), + cast('1942-07-23 03:05:09' as timestamp) + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20' as timetz) + hundred * cast('15 seconds' as interval), cast(thousand as bit(10)), - cast(cast(tenthous as bit(16)) as bit varying), - cast(tenthous as numeric(36, 30)) * fivethous * - even / - (hundred + 1), + cast(cast(tenthous as bit(16)) as varbit), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -619,12 +507,8 @@ select ) as uuid), int4range(thousand, twothousand), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn), - box( - point(odd, even), - point(thousand, twothousand) - ) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn), + box(point(odd, even), point(thousand, twothousand)) from tenk1 order by unique2 @@ -655,16 +539,9 @@ select brin_desummarize_range('brinidx', 100000000); create table brin_summarize (value int) with (fillfactor = 10, autovacuum_enabled = 'false'); -create index "brin_summarize_idx" -on brin_summarize -using brin -( - value -) -with (pages_per_range = 2); +create index brin_summarize_idx on brin_summarize using brin (value) with (pages_per_range = 2); -do -$do$ +do $$ DECLARE curtid tid; BEGIN LOOP @@ -672,7 +549,7 @@ BEGIN EXIT WHEN curtid > tid '(2, 0)'; END LOOP; END; -$do$; +$$; select brin_summarize_range('brin_summarize_idx', 0); @@ -688,7 +565,7 @@ select brin_summarize_range('brin_summarize_idx', 4294967296); create table brintest_2 (n numrange); -create index "brinidx_2" on brintest_2 using brin (n); +create index brinidx_2 on brintest_2 using brin (n); insert into brintest_2 values ('empty'); @@ -709,23 +586,11 @@ create table brin_test ( insert into brin_test select x / 100, x % 100 from generate_series(1, 10000) as x (x); -create index "brin_test_a_idx" -on brin_test -using brin -( - a -) -with (pages_per_range = 2); +create index brin_test_a_idx on brin_test using brin (a) with (pages_per_range = 2); -create index "brin_test_b_idx" -on brin_test -using brin -( - b -) -with (pages_per_range = 2); +create index brin_test_b_idx on brin_test using brin (b) with (pages_per_range = 2); -vacuum (ANALYZE) brin_test; +vacuum (analyze) brin_test; select * from brin_test where a = 1; @@ -741,19 +606,16 @@ create table brintest_3 ( with rand_value as ( - select - string_agg(fipshash(cast(i as text)), '') as val - from - generate_series(1, 60) as s (i) + select string_agg(fipshash(cast(i as text)), '') as val from generate_series(1, 60) as s (i) ) insert into brintest_3 select val, val, val, val from rand_value; -create index "brin_test_toast_idx" on brintest_3 using brin (b, c); +create index brin_test_toast_idx on brintest_3 using brin (b, c); delete from brintest_3; -create index concurrently "brin_test_temp_idx" on brintest_3 using btree (a); +create index concurrently brin_test_temp_idx on brintest_3 using btree (a); drop index brin_test_temp_idx; @@ -762,10 +624,7 @@ vacuum brintest_3; with rand_value as ( - select - string_agg(fipshash(cast(-i as text)), '') as val - from - generate_series(1, 60) as s (i) + select string_agg(fipshash(cast(-i as text)), '') as val from generate_series(1, 60) as s (i) ) insert into brintest_3 select val, val, val, val from rand_value; @@ -794,7 +653,7 @@ set local min_parallel_table_scan_size = 0; set local max_parallel_maintenance_workers = 4; -create index "brintest_expr_idx" on brintest_expr using brin ((brintest_func())); +create index brintest_expr_idx on brintest_expr using brin ((brintest_func())); commit; @@ -804,7 +663,7 @@ drop function brintest_func(); create unlogged table brintest_unlogged (n numrange); -create index "brinidx_unlogged" on brintest_unlogged using brin (n); +create index brinidx_unlogged on brintest_unlogged using brin (n); insert into brintest_unlogged values (numrange(0, 2 ^ cast(1000 as numeric))); @@ -814,10 +673,10 @@ create table brin_insert_optimization (a int); insert into brin_insert_optimization values (1); -create index "brin_insert_optimization_idx" on brin_insert_optimization using brin (a); +create index brin_insert_optimization_idx on brin_insert_optimization using brin (a); update brin_insert_optimization set a = a; -reindex (CONCURRENTLY) index brin_insert_optimization_idx; +reindex (concurrently) index brin_insert_optimization_idx; drop table brin_insert_optimization; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_80.snap index a06e6e62b..8e0866d80 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_80.snap @@ -33,10 +33,7 @@ create table brintest ( lsncol pg_lsn, boxcol box ) -with ( - fillfactor = 10, - autovacuum_enabled = off -); +with (fillfactor = 10, autovacuum_enabled = off); insert into brintest select @@ -48,47 +45,25 @@ select twothousand, repeat(stringu1, 8), cast(unique1 as oid), - cast(format('(%s,%s)', tenthous, twenty) - as tid), + cast(format('(%s,%s)', tenthous, twenty) as tid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / - (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), cast('10.2.3.4/24' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast(substr(stringu1, 1, 1) as bpchar), cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * - cast('18.5 second' as interval), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), cast('1942-07-23 03:05:09' as timestamp) + - tenthous * - cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * - cast('12 minutes' as interval) - ) - ), - cast('01:30:20+02' - as time with time zone) + - hundred * cast('15 seconds' as interval), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20+02' as timetz) + hundred * cast('15 seconds' as interval), cast(thousand as bit(10)), - cast(cast(tenthous as bit(16)) - as bit varying), - cast(tenthous as numeric(36, 30)) * - fivethous * - even / - (hundred + 1), + cast(cast(tenthous as bit(16)) as varbit), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -102,12 +77,8 @@ select ) as uuid), int4range(thousand, twothousand), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn), - box( - point(odd, even), - point(thousand, twothousand) - ) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn), + box(point(odd, even), point(thousand, twothousand)) from tenk1 order by unique2 @@ -115,10 +86,8 @@ limit 100; insert into brintest (inetcol, cidrcol, int4rangecol) select - cast('fe80::6e40:8ff:fea9:8c46' as inet) + - tenthous, - cast('fe80::6e40:8ff:fea9:8c46' as cidr) + - tenthous, + cast('fe80::6e40:8ff:fea9:8c46' as inet) + tenthous, + cast('fe80::6e40:8ff:fea9:8c46' as cidr) + tenthous, cast('empty' as int4range) from tenk1 @@ -126,10 +95,7 @@ order by thousand, tenthous limit 25; -create index "brinidx" -on brintest -using brin -( +create index brinidx on brintest using brin ( byteacol, charcol, namecol, @@ -238,20 +204,8 @@ values '{0, 0, 800, 1999, 1428427143}', '{100, 100, 1, 100, 100}' ), - ( - 'int8col', - 'int2', - '{>, >=}', - '{0, 0}', - '{100, 100}' - ), - ( - 'int8col', - 'int4', - '{>, >=}', - '{0, 0}', - '{100, 100}' - ), + ('int8col', 'int2', '{>, >=}', '{0, 0}', '{100, 100}'), + ('int8col', 'int4', '{>, >=}', '{0, 0}', '{100, 100}'), ( 'int8col', 'int8', @@ -469,13 +423,7 @@ values '{empty, empty, empty, empty, empty, empty}', '{125, 72, 72, 72, 53, 125}' ), - ( - 'int4rangecol', - 'int4', - '{@>}', - '{1500}', - '{22}' - ), + ('int4rangecol', 'int4', '{@>}', '{1500}', '{22}'), ( 'lsncol', 'pg_lsn', @@ -483,13 +431,7 @@ values '{0/1200, 0/1200, 44/455222, 198/1999799, 198/1999799, NULL, NULL}', '{100, 100, 1, 100, 100, 25, 100}' ), - ( - 'boxcol', - 'point', - '{@>}', - '{"(500,43)"}', - '{11}' - ), + ('boxcol', 'point', '{@>}', '{"(500,43)"}', '{11}'), ( 'boxcol', 'box', @@ -498,8 +440,7 @@ values '{100, 100, 100, 99, 96, 100, 100, 99, 96, 1, 99, 1}' ); -do -$do$ +do $x$ DECLARE r record; r2 record; @@ -578,7 +519,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$do$; +$x$; reset enable_seqscan; @@ -594,46 +535,25 @@ select twothousand, repeat(stringu1, 42), cast(unique1 as oid), - cast(format('(%s,%s)', tenthous, twenty) - as tid), + cast(format('(%s,%s)', tenthous, twenty) as tid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / - (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), cast('10.2.3.4' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast(substr(stringu1, 1, 1) as bpchar), cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * - cast('18.5 second' as interval), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), cast('1942-07-23 03:05:09' as timestamp) + - tenthous * - cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * - cast('12 minutes' as interval) - ) - ), - cast('01:30:20' as time with time zone) + - hundred * cast('15 seconds' as interval), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20' as timetz) + hundred * cast('15 seconds' as interval), cast(thousand as bit(10)), - cast(cast(tenthous as bit(16)) - as bit varying), - cast(tenthous as numeric(36, 30)) * - fivethous * - even / - (hundred + 1), + cast(cast(tenthous as bit(16)) as varbit), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -647,12 +567,8 @@ select ) as uuid), int4range(thousand, twothousand), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn), - box( - point(odd, even), - point(thousand, twothousand) - ) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn), + box(point(odd, even), point(thousand, twothousand)) from tenk1 order by unique2 @@ -682,21 +598,12 @@ select brin_desummarize_range('brinidx', 0); select brin_desummarize_range('brinidx', 100000000); create table brin_summarize (value int) -with ( - fillfactor = 10, - autovacuum_enabled = 'false' -); +with (fillfactor = 10, autovacuum_enabled = 'false'); -create index "brin_summarize_idx" -on brin_summarize -using brin -( - value -) +create index brin_summarize_idx on brin_summarize using brin (value) with (pages_per_range = 2); -do -$do$ +do $$ DECLARE curtid tid; BEGIN LOOP @@ -704,7 +611,7 @@ BEGIN EXIT WHEN curtid > tid '(2, 0)'; END LOOP; END; -$do$; +$$; select brin_summarize_range('brin_summarize_idx', 0); @@ -720,7 +627,7 @@ select brin_summarize_range('brin_summarize_idx', 4294967296); create table brintest_2 (n numrange); -create index "brinidx_2" on brintest_2 using brin (n); +create index brinidx_2 on brintest_2 using brin (n); insert into brintest_2 values ('empty'); @@ -740,29 +647,15 @@ create table brin_test ( ); insert into brin_test -select - x / 100, - x % 100 -from - generate_series(1, 10000) as x (x); +select x / 100, x % 100 from generate_series(1, 10000) as x (x); -create index "brin_test_a_idx" -on brin_test -using brin -( - a -) +create index brin_test_a_idx on brin_test using brin (a) with (pages_per_range = 2); -create index "brin_test_b_idx" -on brin_test -using brin -( - b -) +create index brin_test_b_idx on brin_test using brin (b) with (pages_per_range = 2); -vacuum (ANALYZE) brin_test; +vacuum (analyze) brin_test; select * from brin_test where a = 1; @@ -779,28 +672,18 @@ with rand_value as ( select - string_agg( - fipshash(cast(i as text)), - '' - ) - as val + string_agg(fipshash(cast(i as text)), '') as val from generate_series(1, 60) as s (i) ) insert into brintest_3 -select - val, - val, - val, - val -from - rand_value; +select val, val, val, val from rand_value; -create index "brin_test_toast_idx" on brintest_3 using brin (b, c); +create index brin_test_toast_idx on brintest_3 using brin (b, c); delete from brintest_3; -create index concurrently "brin_test_temp_idx" on brintest_3 using btree (a); +create index concurrently brin_test_temp_idx on brintest_3 using btree (a); drop index brin_test_temp_idx; @@ -810,22 +693,12 @@ with rand_value as ( select - string_agg( - fipshash(cast(-i as text)), - '' - ) - as val + string_agg(fipshash(cast(-i as text)), '') as val from generate_series(1, 60) as s (i) ) insert into brintest_3 -select - val, - val, - val, - val -from - rand_value; +select val, val, val, val from rand_value; set enable_seqscan = off; @@ -851,12 +724,7 @@ set local min_parallel_table_scan_size = 0; set local max_parallel_maintenance_workers = 4; -create index "brintest_expr_idx" -on brintest_expr -using brin -( - (brintest_func()) -); +create index brintest_expr_idx on brintest_expr using brin ((brintest_func())); commit; @@ -866,7 +734,7 @@ drop function brintest_func(); create unlogged table brintest_unlogged (n numrange); -create index "brinidx_unlogged" on brintest_unlogged using brin (n); +create index brinidx_unlogged on brintest_unlogged using brin (n); insert into brintest_unlogged values (numrange(0, 2 ^ cast(1000 as numeric))); @@ -876,15 +744,12 @@ create table brin_insert_optimization (a int); insert into brin_insert_optimization values (1); -create index "brin_insert_optimization_idx" -on brin_insert_optimization -using brin -( - a -); +create index brin_insert_optimization_idx + on brin_insert_optimization + using brin (a); update brin_insert_optimization set a = a; -reindex (CONCURRENTLY) index brin_insert_optimization_idx; +reindex (concurrently) index brin_insert_optimization_idx; drop table brin_insert_optimization; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_100.snap index 9f0115e33..649e78556 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_100.snap @@ -41,35 +41,18 @@ select repeat(stringu1, 8), cast(unique1 as oid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) - as macaddr), + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), cast('10.2.3.4/24' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast(substr(stringu1, 1, 1) as bpchar), cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * cast('18.5 second' as interval), - cast('1942-07-23 03:05:09' as timestamp) + - tenthous * cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + - thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * cast('12 minutes' as interval) - ) - ), - cast('01:30:20+02' as time with time zone) + - hundred * cast('15 seconds' as interval), - cast(tenthous as numeric(36, 30)) * fivethous * - even / - (hundred + 1), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), + cast('1942-07-23 03:05:09' as timestamp) + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20+02' as timetz) + hundred * cast('15 seconds' as interval), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -82,8 +65,7 @@ select to_char(tenthous, 'FM0000') ) as uuid), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn) from tenk1 order by unique2 @@ -91,44 +73,27 @@ limit 100; insert into brintest_bloom (inetcol, cidrcol) select - cast('fe80::6e40:8ff:fea9:8c46' as inet) + - tenthous, - cast('fe80::6e40:8ff:fea9:8c46' as cidr) + - tenthous + cast('fe80::6e40:8ff:fea9:8c46' as inet) + tenthous, + cast('fe80::6e40:8ff:fea9:8c46' as cidr) + tenthous from tenk1 order by thousand, tenthous limit 25; -create index "brinidx_bloom" -on brintest_bloom -using brin -( - byteacol - bytea_bloom_ops(n_distinct_per_range = -1.1) +create index brinidx_bloom on brintest_bloom using brin ( + byteacol bytea_bloom_ops(n_distinct_per_range = -1.1) ); -create index "brinidx_bloom" -on brintest_bloom -using brin -( - byteacol - bytea_bloom_ops(false_positive_rate = 0.00009) +create index brinidx_bloom on brintest_bloom using brin ( + byteacol bytea_bloom_ops(false_positive_rate = 0.00009) ); -create index "brinidx_bloom" -on brintest_bloom -using brin -( - byteacol - bytea_bloom_ops(false_positive_rate = 0.26) +create index brinidx_bloom on brintest_bloom using brin ( + byteacol bytea_bloom_ops(false_positive_rate = 0.26) ); -create index "brinidx_bloom" -on brintest_bloom -using brin -( +create index brinidx_bloom on brintest_bloom using brin ( byteacol bytea_bloom_ops, charcol char_bloom_ops, namecol name_bloom_ops, @@ -167,120 +132,35 @@ create table brinopers_bloom ( insert into brinopers_bloom values - ( - 'byteacol', - 'bytea', - '{=}', - '{BNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAA}', - '{1}' - ), + ('byteacol', 'bytea', '{=}', '{BNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAA}', '{1}'), ('charcol', '"char"', '{=}', '{M}', '{6}'), ('namecol', 'name', '{=}', '{MAAAAA}', '{2}'), ('int2col', 'int2', '{=}', '{800}', '{1}'), ('int4col', 'int4', '{=}', '{800}', '{1}'), ('int8col', 'int8', '{=}', '{1257141600}', '{1}'), - ( - 'textcol', - 'text', - '{=}', - '{BNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAA}', - '{1}' - ), + ('textcol', 'text', '{=}', '{BNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAA}', '{1}'), ('oidcol', 'oid', '{=}', '{8800}', '{1}'), ('float4col', 'float4', '{=}', '{1}', '{4}'), ('float8col', 'float8', '{=}', '{0}', '{1}'), - ( - 'macaddrcol', - 'macaddr', - '{=}', - '{2c:00:2d:00:16:00}', - '{2}' - ), - ( - 'inetcol', - 'inet', - '{=}', - '{10.2.14.231/24}', - '{1}' - ), - ( - 'inetcol', - 'cidr', - '{=}', - '{fe80::6e40:8ff:fea9:8c46}', - '{1}' - ), + ('macaddrcol', 'macaddr', '{=}', '{2c:00:2d:00:16:00}', '{2}'), + ('inetcol', 'inet', '{=}', '{10.2.14.231/24}', '{1}'), + ('inetcol', 'cidr', '{=}', '{fe80::6e40:8ff:fea9:8c46}', '{1}'), ('cidrcol', 'inet', '{=}', '{10.2.14/24}', '{2}'), - ( - 'cidrcol', - 'inet', - '{=}', - '{fe80::6e40:8ff:fea9:8c46}', - '{1}' - ), + ('cidrcol', 'inet', '{=}', '{fe80::6e40:8ff:fea9:8c46}', '{1}'), ('cidrcol', 'cidr', '{=}', '{10.2.14/24}', '{2}'), - ( - 'cidrcol', - 'cidr', - '{=}', - '{fe80::6e40:8ff:fea9:8c46}', - '{1}' - ), + ('cidrcol', 'cidr', '{=}', '{fe80::6e40:8ff:fea9:8c46}', '{1}'), ('bpcharcol', 'bpchar', '{=}', '{W}', '{6}'), ('datecol', 'date', '{=}', '{2009-12-01}', '{1}'), ('timecol', 'time', '{=}', '{02:28:57}', '{1}'), - ( - 'timestampcol', - 'timestamp', - '{=}', - '{1964-03-24 19:26:45}', - '{1}' - ), - ( - 'timestamptzcol', - 'timestamptz', - '{=}', - '{1972-10-19 09:00:00-07}', - '{1}' - ), - ( - 'intervalcol', - 'interval', - '{=}', - '{1 mons 13 days 12:24}', - '{1}' - ), - ( - 'timetzcol', - 'timetz', - '{=}', - '{01:35:50+02}', - '{2}' - ), - ( - 'numericcol', - 'numeric', - '{=}', - '{2268164.347826086956521739130434782609}', - '{1}' - ), - ( - 'uuidcol', - 'uuid', - '{=}', - '{52225222-5222-5222-5222-522252225222}', - '{1}' - ), - ( - 'lsncol', - 'pg_lsn', - '{=, IS, IS NOT}', - '{44/455222, NULL, NULL}', - '{1, 25, 100}' - ); - -do -$do$ + ('timestampcol', 'timestamp', '{=}', '{1964-03-24 19:26:45}', '{1}'), + ('timestamptzcol', 'timestamptz', '{=}', '{1972-10-19 09:00:00-07}', '{1}'), + ('intervalcol', 'interval', '{=}', '{1 mons 13 days 12:24}', '{1}'), + ('timetzcol', 'timetz', '{=}', '{01:35:50+02}', '{2}'), + ('numericcol', 'numeric', '{=}', '{2268164.347826086956521739130434782609}', '{1}'), + ('uuidcol', 'uuid', '{=}', '{52225222-5222-5222-5222-522252225222}', '{1}'), + ('lsncol', 'pg_lsn', '{=, IS, IS NOT}', '{44/455222, NULL, NULL}', '{1, 25, 100}'); + +do $x$ DECLARE r record; r2 record; @@ -359,7 +239,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$do$; +$x$; reset enable_seqscan; @@ -376,35 +256,18 @@ select repeat(stringu1, 42), cast(unique1 as oid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) - as macaddr), + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), cast('10.2.3.4' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast(substr(stringu1, 1, 1) as bpchar), cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * cast('18.5 second' as interval), - cast('1942-07-23 03:05:09' as timestamp) + - tenthous * cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + - thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * cast('12 minutes' as interval) - ) - ), - cast('01:30:20' as time with time zone) + - hundred * cast('15 seconds' as interval), - cast(tenthous as numeric(36, 30)) * fivethous * - even / - (hundred + 1), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), + cast('1942-07-23 03:05:09' as timestamp) + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20' as timetz) + hundred * cast('15 seconds' as interval), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -417,8 +280,7 @@ select to_char(tenthous, 'FM0000') ) as uuid), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn) from tenk1 order by unique2 @@ -449,16 +311,10 @@ select brin_desummarize_range('brinidx_bloom', 100000000); create table brin_summarize_bloom (value int) with (fillfactor = 10, autovacuum_enabled = 'false'); -create index "brin_summarize_bloom_idx" -on brin_summarize_bloom -using brin -( - value -) +create index brin_summarize_bloom_idx on brin_summarize_bloom using brin (value) with (pages_per_range = 2); -do -$do$ +do $$ DECLARE curtid tid; BEGIN LOOP @@ -466,7 +322,7 @@ BEGIN EXIT WHEN curtid > tid '(2, 0)'; END LOOP; END; -$do$; +$$; select brin_summarize_range('brin_summarize_bloom_idx', 0); @@ -487,23 +343,11 @@ create table brin_test_bloom ( insert into brin_test_bloom select x / 100, x % 100 from generate_series(1, 10000) as x (x); -create index "brin_test_bloom_a_idx" -on brin_test_bloom -using brin -( - a -) -with (pages_per_range = 2); +create index brin_test_bloom_a_idx on brin_test_bloom using brin (a) with (pages_per_range = 2); -create index "brin_test_bloom_b_idx" -on brin_test_bloom -using brin -( - b -) -with (pages_per_range = 2); +create index brin_test_bloom_b_idx on brin_test_bloom using brin (b) with (pages_per_range = 2); -vacuum (ANALYZE) brin_test_bloom; +vacuum (analyze) brin_test_bloom; select * from brin_test_bloom where a = 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_80.snap index 9cc310224..c0d30a691 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_80.snap @@ -41,41 +41,21 @@ select repeat(stringu1, 8), cast(unique1 as oid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / - (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), cast('10.2.3.4/24' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast(substr(stringu1, 1, 1) as bpchar), cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * - cast('18.5 second' as interval), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), cast('1942-07-23 03:05:09' as timestamp) + - tenthous * - cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * - cast('12 minutes' as interval) - ) - ), - cast('01:30:20+02' - as time with time zone) + - hundred * cast('15 seconds' as interval), - cast(tenthous as numeric(36, 30)) * - fivethous * - even / - (hundred + 1), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20+02' as timetz) + hundred * cast('15 seconds' as interval), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -88,8 +68,7 @@ select to_char(tenthous, 'FM0000') ) as uuid), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn) from tenk1 order by unique2 @@ -97,44 +76,27 @@ limit 100; insert into brintest_bloom (inetcol, cidrcol) select - cast('fe80::6e40:8ff:fea9:8c46' as inet) + - tenthous, - cast('fe80::6e40:8ff:fea9:8c46' as cidr) + - tenthous + cast('fe80::6e40:8ff:fea9:8c46' as inet) + tenthous, + cast('fe80::6e40:8ff:fea9:8c46' as cidr) + tenthous from tenk1 order by thousand, tenthous limit 25; -create index "brinidx_bloom" -on brintest_bloom -using brin -( - byteacol - bytea_bloom_ops(n_distinct_per_range = -1.1) +create index brinidx_bloom on brintest_bloom using brin ( + byteacol bytea_bloom_ops(n_distinct_per_range = -1.1) ); -create index "brinidx_bloom" -on brintest_bloom -using brin -( - byteacol - bytea_bloom_ops(false_positive_rate = 0.00009) +create index brinidx_bloom on brintest_bloom using brin ( + byteacol bytea_bloom_ops(false_positive_rate = 0.00009) ); -create index "brinidx_bloom" -on brintest_bloom -using brin -( - byteacol - bytea_bloom_ops(false_positive_rate = 0.26) +create index brinidx_bloom on brintest_bloom using brin ( + byteacol bytea_bloom_ops(false_positive_rate = 0.26) ); -create index "brinidx_bloom" -on brintest_bloom -using brin -( +create index brinidx_bloom on brintest_bloom using brin ( byteacol bytea_bloom_ops, charcol char_bloom_ops, namecol name_bloom_ops, @@ -180,29 +142,11 @@ values '{BNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAA}', '{1}' ), - ( - 'charcol', '"char"', '{=}', '{M}', '{6}' - ), - ( - 'namecol', - 'name', - '{=}', - '{MAAAAA}', - '{2}' - ), - ( - 'int2col', 'int2', '{=}', '{800}', '{1}' - ), - ( - 'int4col', 'int4', '{=}', '{800}', '{1}' - ), - ( - 'int8col', - 'int8', - '{=}', - '{1257141600}', - '{1}' - ), + ('charcol', '"char"', '{=}', '{M}', '{6}'), + ('namecol', 'name', '{=}', '{MAAAAA}', '{2}'), + ('int2col', 'int2', '{=}', '{800}', '{1}'), + ('int4col', 'int4', '{=}', '{800}', '{1}'), + ('int8col', 'int8', '{=}', '{1257141600}', '{1}'), ( 'textcol', 'text', @@ -210,121 +154,23 @@ values '{BNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAABNAAAA}', '{1}' ), - ( - 'oidcol', 'oid', '{=}', '{8800}', '{1}' - ), - ( - 'float4col', - 'float4', - '{=}', - '{1}', - '{4}' - ), - ( - 'float8col', - 'float8', - '{=}', - '{0}', - '{1}' - ), - ( - 'macaddrcol', - 'macaddr', - '{=}', - '{2c:00:2d:00:16:00}', - '{2}' - ), - ( - 'inetcol', - 'inet', - '{=}', - '{10.2.14.231/24}', - '{1}' - ), - ( - 'inetcol', - 'cidr', - '{=}', - '{fe80::6e40:8ff:fea9:8c46}', - '{1}' - ), - ( - 'cidrcol', - 'inet', - '{=}', - '{10.2.14/24}', - '{2}' - ), - ( - 'cidrcol', - 'inet', - '{=}', - '{fe80::6e40:8ff:fea9:8c46}', - '{1}' - ), - ( - 'cidrcol', - 'cidr', - '{=}', - '{10.2.14/24}', - '{2}' - ), - ( - 'cidrcol', - 'cidr', - '{=}', - '{fe80::6e40:8ff:fea9:8c46}', - '{1}' - ), - ( - 'bpcharcol', - 'bpchar', - '{=}', - '{W}', - '{6}' - ), - ( - 'datecol', - 'date', - '{=}', - '{2009-12-01}', - '{1}' - ), - ( - 'timecol', - 'time', - '{=}', - '{02:28:57}', - '{1}' - ), - ( - 'timestampcol', - 'timestamp', - '{=}', - '{1964-03-24 19:26:45}', - '{1}' - ), - ( - 'timestamptzcol', - 'timestamptz', - '{=}', - '{1972-10-19 09:00:00-07}', - '{1}' - ), - ( - 'intervalcol', - 'interval', - '{=}', - '{1 mons 13 days 12:24}', - '{1}' - ), - ( - 'timetzcol', - 'timetz', - '{=}', - '{01:35:50+02}', - '{2}' - ), + ('oidcol', 'oid', '{=}', '{8800}', '{1}'), + ('float4col', 'float4', '{=}', '{1}', '{4}'), + ('float8col', 'float8', '{=}', '{0}', '{1}'), + ('macaddrcol', 'macaddr', '{=}', '{2c:00:2d:00:16:00}', '{2}'), + ('inetcol', 'inet', '{=}', '{10.2.14.231/24}', '{1}'), + ('inetcol', 'cidr', '{=}', '{fe80::6e40:8ff:fea9:8c46}', '{1}'), + ('cidrcol', 'inet', '{=}', '{10.2.14/24}', '{2}'), + ('cidrcol', 'inet', '{=}', '{fe80::6e40:8ff:fea9:8c46}', '{1}'), + ('cidrcol', 'cidr', '{=}', '{10.2.14/24}', '{2}'), + ('cidrcol', 'cidr', '{=}', '{fe80::6e40:8ff:fea9:8c46}', '{1}'), + ('bpcharcol', 'bpchar', '{=}', '{W}', '{6}'), + ('datecol', 'date', '{=}', '{2009-12-01}', '{1}'), + ('timecol', 'time', '{=}', '{02:28:57}', '{1}'), + ('timestampcol', 'timestamp', '{=}', '{1964-03-24 19:26:45}', '{1}'), + ('timestamptzcol', 'timestamptz', '{=}', '{1972-10-19 09:00:00-07}', '{1}'), + ('intervalcol', 'interval', '{=}', '{1 mons 13 days 12:24}', '{1}'), + ('timetzcol', 'timetz', '{=}', '{01:35:50+02}', '{2}'), ( 'numericcol', 'numeric', @@ -332,13 +178,7 @@ values '{2268164.347826086956521739130434782609}', '{1}' ), - ( - 'uuidcol', - 'uuid', - '{=}', - '{52225222-5222-5222-5222-522252225222}', - '{1}' - ), + ('uuidcol', 'uuid', '{=}', '{52225222-5222-5222-5222-522252225222}', '{1}'), ( 'lsncol', 'pg_lsn', @@ -347,8 +187,7 @@ values '{1, 25, 100}' ); -do -$do$ +do $x$ DECLARE r record; r2 record; @@ -427,7 +266,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$do$; +$x$; reset enable_seqscan; @@ -444,40 +283,21 @@ select repeat(stringu1, 42), cast(unique1 as oid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / - (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), cast('10.2.3.4' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast(substr(stringu1, 1, 1) as bpchar), cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * - cast('18.5 second' as interval), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), cast('1942-07-23 03:05:09' as timestamp) + - tenthous * - cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * - cast('12 minutes' as interval) - ) - ), - cast('01:30:20' as time with time zone) + - hundred * cast('15 seconds' as interval), - cast(tenthous as numeric(36, 30)) * - fivethous * - even / - (hundred + 1), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20' as timetz) + hundred * cast('15 seconds' as interval), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -490,8 +310,7 @@ select to_char(tenthous, 'FM0000') ) as uuid), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn) from tenk1 order by unique2 @@ -521,21 +340,12 @@ select brin_desummarize_range('brinidx_bloom', 0); select brin_desummarize_range('brinidx_bloom', 100000000); create table brin_summarize_bloom (value int) -with ( - fillfactor = 10, - autovacuum_enabled = 'false' -); +with (fillfactor = 10, autovacuum_enabled = 'false'); -create index "brin_summarize_bloom_idx" -on brin_summarize_bloom -using brin -( - value -) +create index brin_summarize_bloom_idx on brin_summarize_bloom using brin (value) with (pages_per_range = 2); -do -$do$ +do $$ DECLARE curtid tid; BEGIN LOOP @@ -543,7 +353,7 @@ BEGIN EXIT WHEN curtid > tid '(2, 0)'; END LOOP; END; -$do$; +$$; select brin_summarize_range('brin_summarize_bloom_idx', 0); @@ -563,29 +373,15 @@ create table brin_test_bloom ( ); insert into brin_test_bloom -select - x / 100, - x % 100 -from - generate_series(1, 10000) as x (x); +select x / 100, x % 100 from generate_series(1, 10000) as x (x); -create index "brin_test_bloom_a_idx" -on brin_test_bloom -using brin -( - a -) +create index brin_test_bloom_a_idx on brin_test_bloom using brin (a) with (pages_per_range = 2); -create index "brin_test_bloom_b_idx" -on brin_test_bloom -using brin -( - b -) +create index brin_test_bloom_b_idx on brin_test_bloom using brin (b) with (pages_per_range = 2); -vacuum (ANALYZE) brin_test_bloom; +vacuum (analyze) brin_test_bloom; select * from brin_test_bloom where a = 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_100.snap index 71b2fc4a9..4a9223ea1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_100.snap @@ -35,36 +35,18 @@ select cast(unique1 as oid), cast(format('(%s,%s)', tenthous, twenty) as tid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) - as macaddr), - cast(substr(fipshash(cast(unique1 as text)), 1, 16) - as macaddr8), + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), + cast(substr(fipshash(cast(unique1 as text)), 1, 16) as macaddr8), cast('10.2.3.4/24' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * cast('18.5 second' as interval), - cast('1942-07-23 03:05:09' as timestamp) + - tenthous * cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + - thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * cast('12 minutes' as interval) - ) - ), - cast('01:30:20+02' as time with time zone) + - hundred * cast('15 seconds' as interval), - cast(tenthous as numeric(36, 30)) * fivethous * - even / - (hundred + 1), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), + cast('1942-07-23 03:05:09' as timestamp) + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20+02' as timetz) + hundred * cast('15 seconds' as interval), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -77,8 +59,7 @@ select to_char(tenthous, 'FM0000') ) as uuid), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn) from tenk1 order by unique2 @@ -86,36 +67,23 @@ limit 100; insert into brintest_multi (inetcol, cidrcol) select - cast('fe80::6e40:8ff:fea9:8c46' as inet) + - tenthous, - cast('fe80::6e40:8ff:fea9:8c46' as cidr) + - tenthous + cast('fe80::6e40:8ff:fea9:8c46' as inet) + tenthous, + cast('fe80::6e40:8ff:fea9:8c46' as cidr) + tenthous from tenk1 order by thousand, tenthous limit 25; -create index "brinidx_multi" -on brintest_multi -using brin -( - int8col - int8_minmax_multi_ops(values_per_range = 7) +create index brinidx_multi on brintest_multi using brin ( + int8col int8_minmax_multi_ops(values_per_range = 7) ); -create index "brinidx_multi" -on brintest_multi -using brin -( - int8col - int8_minmax_multi_ops(values_per_range = 257) +create index brinidx_multi on brintest_multi using brin ( + int8col int8_minmax_multi_ops(values_per_range = 257) ); -create index "brinidx_multi" -on brintest_multi -using brin -( +create index brinidx_multi on brintest_multi using brin ( int8col int8_minmax_multi_ops, int2col int2_minmax_multi_ops, int4col int4_minmax_multi_ops, @@ -140,10 +108,7 @@ using brin drop index brinidx_multi; -create index "brinidx_multi" -on brintest_multi -using brin -( +create index brinidx_multi on brintest_multi using brin ( int8col int8_minmax_multi_ops, int2col int2_minmax_multi_ops, int4col int4_minmax_multi_ops, @@ -179,20 +144,8 @@ create table brinopers_multi ( insert into brinopers_multi values - ( - 'int2col', - 'int2', - '{>, >=, =, <=, <}', - '{0, 0, 800, 999, 999}', - '{100, 100, 1, 100, 100}' - ), - ( - 'int2col', - 'int4', - '{>, >=, =, <=, <}', - '{0, 0, 800, 999, 1999}', - '{100, 100, 1, 100, 100}' - ), + ('int2col', 'int2', '{>, >=, =, <=, <}', '{0, 0, 800, 999, 999}', '{100, 100, 1, 100, 100}'), + ('int2col', 'int4', '{>, >=, =, <=, <}', '{0, 0, 800, 999, 1999}', '{100, 100, 1, 100, 100}'), ( 'int2col', 'int8', @@ -200,20 +153,8 @@ values '{0, 0, 800, 999, 1428427143}', '{100, 100, 1, 100, 100}' ), - ( - 'int4col', - 'int2', - '{>, >=, =, <=, <}', - '{0, 0, 800, 1999, 1999}', - '{100, 100, 1, 100, 100}' - ), - ( - 'int4col', - 'int4', - '{>, >=, =, <=, <}', - '{0, 0, 800, 1999, 1999}', - '{100, 100, 1, 100, 100}' - ), + ('int4col', 'int2', '{>, >=, =, <=, <}', '{0, 0, 800, 1999, 1999}', '{100, 100, 1, 100, 100}'), + ('int4col', 'int4', '{>, >=, =, <=, <}', '{0, 0, 800, 1999, 1999}', '{100, 100, 1, 100, 100}'), ( 'int4col', 'int8', @@ -221,20 +162,8 @@ values '{0, 0, 800, 1999, 1428427143}', '{100, 100, 1, 100, 100}' ), - ( - 'int8col', - 'int2', - '{>, >=}', - '{0, 0}', - '{100, 100}' - ), - ( - 'int8col', - 'int4', - '{>, >=}', - '{0, 0}', - '{100, 100}' - ), + ('int8col', 'int2', '{>, >=}', '{0, 0}', '{100, 100}'), + ('int8col', 'int4', '{>, >=}', '{0, 0}', '{100, 100}'), ( 'int8col', 'int8', @@ -242,13 +171,7 @@ values '{0, 0, 1257141600, 1428427143, 1428427143}', '{100, 100, 1, 100, 100}' ), - ( - 'oidcol', - 'oid', - '{>, >=, =, <=, <}', - '{0, 0, 8800, 9999, 9999}', - '{100, 100, 1, 100, 100}' - ), + ('oidcol', 'oid', '{>, >=, =, <=, <}', '{0, 0, 8800, 9999, 9999}', '{100, 100, 1, 100, 100}'), ( 'tidcol', 'tid', @@ -270,20 +193,8 @@ values '{0.0103093, 0.0103093, 1, 1, 1}', '{100, 100, 4, 100, 96}' ), - ( - 'float8col', - 'float4', - '{>, >=, =, <=, <}', - '{0, 0, 0, 1.98, 1.98}', - '{99, 100, 1, 100, 100}' - ), - ( - 'float8col', - 'float8', - '{>, >=, =, <=, <}', - '{0, 0, 0, 1.98, 1.98}', - '{99, 100, 1, 100, 100}' - ), + ('float8col', 'float4', '{>, >=, =, <=, <}', '{0, 0, 0, 1.98, 1.98}', '{99, 100, 1, 100, 100}'), + ('float8col', 'float8', '{>, >=, =, <=, <}', '{0, 0, 0, 1.98, 1.98}', '{99, 100, 1, 100, 100}'), ( 'macaddrcol', 'macaddr', @@ -397,8 +308,7 @@ values '{100, 100, 1, 100, 100, 25, 100}' ); -do -$do$ +do $x$ DECLARE r record; r2 record; @@ -477,7 +387,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$do$; +$x$; reset enable_seqscan; @@ -491,36 +401,18 @@ select cast(unique1 as oid), cast(format('(%s,%s)', tenthous, twenty) as tid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) - as macaddr), - cast(substr(fipshash(cast(unique1 as text)), 1, 16) - as macaddr8), + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), + cast(substr(fipshash(cast(unique1 as text)), 1, 16) as macaddr8), cast('10.2.3.4' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * cast('18.5 second' as interval), - cast('1942-07-23 03:05:09' as timestamp) + - tenthous * cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + - thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * cast('12 minutes' as interval) - ) - ), - cast('01:30:20' as time with time zone) + - hundred * cast('15 seconds' as interval), - cast(tenthous as numeric(36, 30)) * fivethous * - even / - (hundred + 1), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), + cast('1942-07-23 03:05:09' as timestamp) + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20' as timetz) + hundred * cast('15 seconds' as interval), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -533,8 +425,7 @@ select to_char(tenthous, 'FM0000') ) as uuid), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn) from tenk1 order by unique2 @@ -575,26 +466,20 @@ select brin_desummarize_range('brinidx_multi', 0); select brin_desummarize_range('brinidx_multi', 100000000); -create table brin_large_range (a int); +create table brin_large_range (a int4); insert into brin_large_range select i from generate_series(1, 10000) as s (i); -create index "brin_large_range_idx" on brin_large_range using brin (a int4_minmax_multi_ops); +create index brin_large_range_idx on brin_large_range using brin (a int4_minmax_multi_ops); drop table brin_large_range; create table brin_summarize_multi (value int) with (fillfactor = 10, autovacuum_enabled = 'false'); -create index "brin_summarize_multi_idx" -on brin_summarize_multi -using brin -( - value -) +create index brin_summarize_multi_idx on brin_summarize_multi using brin (value) with (pages_per_range = 2); -do -$do$ +do $$ DECLARE curtid tid; BEGIN LOOP @@ -602,7 +487,7 @@ BEGIN EXIT WHEN curtid > tid '(2, 0)'; END LOOP; END; -$do$; +$$; select brin_summarize_range('brin_summarize_multi_idx', 0); @@ -623,23 +508,11 @@ create table brin_test_multi ( insert into brin_test_multi select x / 100, x % 100 from generate_series(1, 10000) as x (x); -create index "brin_test_multi_a_idx" -on brin_test_multi -using brin -( - a -) -with (pages_per_range = 2); +create index brin_test_multi_a_idx on brin_test_multi using brin (a) with (pages_per_range = 2); -create index "brin_test_multi_b_idx" -on brin_test_multi -using brin -( - b -) -with (pages_per_range = 2); +create index brin_test_multi_b_idx on brin_test_multi using brin (b) with (pages_per_range = 2); -vacuum (ANALYZE) brin_test_multi; +vacuum (analyze) brin_test_multi; select * from brin_test_multi where a = 1; @@ -658,63 +531,53 @@ select from generate_series(1, 1000) as s (i); -create index "brin_test_multi_1_idx_1" -on brin_test_multi_1 -using brin -( - a int4_minmax_multi_ops -) +create index brin_test_multi_1_idx_1 on brin_test_multi_1 using brin (a int4_minmax_multi_ops) with (pages_per_range = 5); -create index "brin_test_multi_1_idx_2" -on brin_test_multi_1 -using brin -( - b int8_minmax_multi_ops -) +create index brin_test_multi_1_idx_2 on brin_test_multi_1 using brin (b int8_minmax_multi_ops) with (pages_per_range = 5); set enable_seqscan = off; -select COUNT(*) from brin_test_multi_1 where a < 37; +select count(*) from brin_test_multi_1 where a < 37; -select COUNT(*) from brin_test_multi_1 where a < 113; +select count(*) from brin_test_multi_1 where a < 113; -select COUNT(*) from brin_test_multi_1 where a <= 177; +select count(*) from brin_test_multi_1 where a <= 177; -select COUNT(*) from brin_test_multi_1 where a <= 25; +select count(*) from brin_test_multi_1 where a <= 25; -select COUNT(*) from brin_test_multi_1 where a > 120; +select count(*) from brin_test_multi_1 where a > 120; -select COUNT(*) from brin_test_multi_1 where a >= 180; +select count(*) from brin_test_multi_1 where a >= 180; -select COUNT(*) from brin_test_multi_1 where a > 71; +select count(*) from brin_test_multi_1 where a > 71; -select COUNT(*) from brin_test_multi_1 where a >= 63; +select count(*) from brin_test_multi_1 where a >= 63; -select COUNT(*) from brin_test_multi_1 where a = 207; +select count(*) from brin_test_multi_1 where a = 207; -select COUNT(*) from brin_test_multi_1 where a = 177; +select count(*) from brin_test_multi_1 where a = 177; -select COUNT(*) from brin_test_multi_1 where b < 73; +select count(*) from brin_test_multi_1 where b < 73; -select COUNT(*) from brin_test_multi_1 where b <= 47; +select count(*) from brin_test_multi_1 where b <= 47; -select COUNT(*) from brin_test_multi_1 where b < 199; +select count(*) from brin_test_multi_1 where b < 199; -select COUNT(*) from brin_test_multi_1 where b <= 150; +select count(*) from brin_test_multi_1 where b <= 150; -select COUNT(*) from brin_test_multi_1 where b > 93; +select count(*) from brin_test_multi_1 where b > 93; -select COUNT(*) from brin_test_multi_1 where b > 37; +select count(*) from brin_test_multi_1 where b > 37; -select COUNT(*) from brin_test_multi_1 where b >= 215; +select count(*) from brin_test_multi_1 where b >= 215; -select COUNT(*) from brin_test_multi_1 where b > 201; +select count(*) from brin_test_multi_1 where b > 201; -select COUNT(*) from brin_test_multi_1 where b = 88; +select count(*) from brin_test_multi_1 where b = 88; -select COUNT(*) from brin_test_multi_1 where b = 103; +select count(*) from brin_test_multi_1 where b = 103; truncate brin_test_multi_1; @@ -725,45 +588,45 @@ select from generate_series(1, 1000) as s (i); -select COUNT(*) from brin_test_multi_1 where a < 37; +select count(*) from brin_test_multi_1 where a < 37; -select COUNT(*) from brin_test_multi_1 where a < 113; +select count(*) from brin_test_multi_1 where a < 113; -select COUNT(*) from brin_test_multi_1 where a <= 177; +select count(*) from brin_test_multi_1 where a <= 177; -select COUNT(*) from brin_test_multi_1 where a <= 25; +select count(*) from brin_test_multi_1 where a <= 25; -select COUNT(*) from brin_test_multi_1 where a > 120; +select count(*) from brin_test_multi_1 where a > 120; -select COUNT(*) from brin_test_multi_1 where a >= 180; +select count(*) from brin_test_multi_1 where a >= 180; -select COUNT(*) from brin_test_multi_1 where a > 71; +select count(*) from brin_test_multi_1 where a > 71; -select COUNT(*) from brin_test_multi_1 where a >= 63; +select count(*) from brin_test_multi_1 where a >= 63; -select COUNT(*) from brin_test_multi_1 where a = 207; +select count(*) from brin_test_multi_1 where a = 207; -select COUNT(*) from brin_test_multi_1 where a = 177; +select count(*) from brin_test_multi_1 where a = 177; -select COUNT(*) from brin_test_multi_1 where b < 73; +select count(*) from brin_test_multi_1 where b < 73; -select COUNT(*) from brin_test_multi_1 where b <= 47; +select count(*) from brin_test_multi_1 where b <= 47; -select COUNT(*) from brin_test_multi_1 where b < 199; +select count(*) from brin_test_multi_1 where b < 199; -select COUNT(*) from brin_test_multi_1 where b <= 150; +select count(*) from brin_test_multi_1 where b <= 150; -select COUNT(*) from brin_test_multi_1 where b > 93; +select count(*) from brin_test_multi_1 where b > 93; -select COUNT(*) from brin_test_multi_1 where b > 37; +select count(*) from brin_test_multi_1 where b > 37; -select COUNT(*) from brin_test_multi_1 where b >= 215; +select count(*) from brin_test_multi_1 where b >= 215; -select COUNT(*) from brin_test_multi_1 where b > 201; +select count(*) from brin_test_multi_1 where b > 201; -select COUNT(*) from brin_test_multi_1 where b = 88; +select count(*) from brin_test_multi_1 where b = 88; -select COUNT(*) from brin_test_multi_1 where b = 103; +select count(*) from brin_test_multi_1 where b = 103; drop table brin_test_multi_1; @@ -777,41 +640,30 @@ select from ( select - ROW_NUMBER() over (order by v) as c, + row_number() over (order by v) as c, v from - ( - select - fipshash(cast(i / 13 as text)) as v - from - generate_series(1, 1000) as s (i) - ) - as foo + (select fipshash(cast(i / 13 as text)) as v from generate_series(1, 1000) as s (i)) as foo ) as bar order by c + 25 * random(); -create index "brin_test_multi_2_idx" -on brin_test_multi_2 -using brin -( - a uuid_minmax_multi_ops -) +create index brin_test_multi_2_idx on brin_test_multi_2 using brin (a uuid_minmax_multi_ops) with (pages_per_range = 5); set enable_seqscan = off; -select COUNT(*) from brin_test_multi_2 where a < '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; +select count(*) from brin_test_multi_2 where a < '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; -select COUNT(*) from brin_test_multi_2 where a > '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; +select count(*) from brin_test_multi_2 where a > '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; -select COUNT(*) from brin_test_multi_2 where a <= 'f369cb89-fc62-7e66-8987-007d121ed1ea'; +select count(*) from brin_test_multi_2 where a <= 'f369cb89-fc62-7e66-8987-007d121ed1ea'; -select COUNT(*) from brin_test_multi_2 where a >= 'aea92132-c4cb-eb26-3e6a-c2bf6c183b5d'; +select count(*) from brin_test_multi_2 where a >= 'aea92132-c4cb-eb26-3e6a-c2bf6c183b5d'; -select COUNT(*) from brin_test_multi_2 where a = '5feceb66-ffc8-6f38-d952-786c6d696c79'; +select count(*) from brin_test_multi_2 where a = '5feceb66-ffc8-6f38-d952-786c6d696c79'; -select COUNT(*) from brin_test_multi_2 where a = '86e50149-6586-6131-2a9e-0b35558d84f6'; +select count(*) from brin_test_multi_2 where a = '86e50149-6586-6131-2a9e-0b35558d84f6'; truncate brin_test_multi_2; @@ -821,62 +673,47 @@ select from ( select - ROW_NUMBER() over (order by v) as c, + row_number() over (order by v) as c, v from - ( - select - fipshash(cast(i / 13 as text)) as v - from - generate_series(1, 1000) as s (i) - ) - as foo + (select fipshash(cast(i / 13 as text)) as v from generate_series(1, 1000) as s (i)) as foo ) as bar order by c + 25 * random(); -select COUNT(*) from brin_test_multi_2 where a < '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; +select count(*) from brin_test_multi_2 where a < '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; -select COUNT(*) from brin_test_multi_2 where a > '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; +select count(*) from brin_test_multi_2 where a > '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; -select COUNT(*) from brin_test_multi_2 where a <= 'f369cb89-fc62-7e66-8987-007d121ed1ea'; +select count(*) from brin_test_multi_2 where a <= 'f369cb89-fc62-7e66-8987-007d121ed1ea'; -select COUNT(*) from brin_test_multi_2 where a >= 'aea92132-c4cb-eb26-3e6a-c2bf6c183b5d'; +select count(*) from brin_test_multi_2 where a >= 'aea92132-c4cb-eb26-3e6a-c2bf6c183b5d'; -select COUNT(*) from brin_test_multi_2 where a = '5feceb66-ffc8-6f38-d952-786c6d696c79'; +select count(*) from brin_test_multi_2 where a = '5feceb66-ffc8-6f38-d952-786c6d696c79'; -select COUNT(*) from brin_test_multi_2 where a = '86e50149-6586-6131-2a9e-0b35558d84f6'; +select count(*) from brin_test_multi_2 where a = '86e50149-6586-6131-2a9e-0b35558d84f6'; drop table brin_test_multi_2; reset enable_seqscan; -create table brin_timestamp_test (a timestamp with time zone); +create table brin_timestamp_test (a timestamptz); set datestyle = iso; insert into brin_timestamp_test select - cast('4713-01-01 00:00:01 BC' - as timestamp with time zone) + - cast(i || ' seconds' as interval) + cast('4713-01-01 00:00:01 BC' as timestamptz) + cast(i || ' seconds' as interval) from generate_series(1, 30) as s (i); insert into brin_timestamp_test select - cast('294276-12-01 00:00:01' - as timestamp with time zone) + - cast(i || ' seconds' as interval) + cast('294276-12-01 00:00:01' as timestamptz) + cast(i || ' seconds' as interval) from generate_series(1, 30) as s (i); -create index -on brin_timestamp_test -using brin -( - a timestamptz_minmax_multi_ops -) +create index on brin_timestamp_test using brin (a timestamptz_minmax_multi_ops) with (pages_per_range = 1); drop table brin_timestamp_test; @@ -884,24 +721,12 @@ drop table brin_timestamp_test; create table brin_date_test (a date); insert into brin_date_test -select - cast('4713-01-01 BC' as date) + i -from - generate_series(1, 30) as s (i); +select cast('4713-01-01 BC' as date) + i from generate_series(1, 30) as s (i); insert into brin_date_test -select - cast('5874897-12-01' as date) + i -from - generate_series(1, 30) as s (i); +select cast('5874897-12-01' as date) + i from generate_series(1, 30) as s (i); -create index -on brin_date_test -using brin -( - a date_minmax_multi_ops -) -with (pages_per_range = 1); +create index on brin_date_test using brin (a date_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; @@ -926,12 +751,7 @@ from ) as s (i); -create index -on brin_timestamp_test -using brin -( - a timestamp_minmax_multi_ops -) +create index on brin_timestamp_test using brin (a timestamp_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; @@ -949,18 +769,9 @@ create table brin_date_test (a date); insert into brin_date_test values ('-infinity'), ('infinity'); insert into brin_date_test -select - cast('2000-01-01' as date) + i -from - generate_series(1, 40) as s (i); +select cast('2000-01-01' as date) + i from generate_series(1, 40) as s (i); -create index -on brin_date_test -using brin -( - a date_minmax_multi_ops -) -with (pages_per_range = 1); +create index on brin_date_test using brin (a date_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; @@ -977,23 +788,12 @@ reset datestyle; create table brin_interval_test (a interval); insert into brin_interval_test -select - cast(i || ' years' as interval) -from - generate_series(-178000000, -177999980) as s (i); +select cast(i || ' years' as interval) from generate_series(-178000000, -177999980) as s (i); insert into brin_interval_test -select - cast(i || ' years' as interval) -from - generate_series(177999980, 178000000) as s (i); +select cast(i || ' years' as interval) from generate_series(177999980, 178000000) as s (i); -create index -on brin_interval_test -using brin -( - a interval_minmax_multi_ops -) +create index on brin_interval_test using brin (a interval_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; @@ -1011,17 +811,9 @@ create table brin_interval_test (a interval); insert into brin_interval_test values ('-infinity'), ('infinity'); insert into brin_interval_test -select - cast(i || ' days' as interval) -from - generate_series(100, 140) as s (i); +select cast(i || ' days' as interval) from generate_series(100, 140) as s (i); -create index -on brin_interval_test -using brin -( - a interval_minmax_multi_ops -) +create index on brin_interval_test using brin (a interval_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_80.snap index 64d7740b9..2c55c2a0d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_80.snap @@ -33,49 +33,23 @@ select thousand, twothousand, cast(unique1 as oid), - cast(format('(%s,%s)', tenthous, twenty) - as tid), + cast(format('(%s,%s)', tenthous, twenty) as tid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / - (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), - cast(substr( - fipshash(cast(unique1 as text)), - 1, - 16 - ) - as macaddr8), + cast(substr(fipshash(cast(unique1 as text)), 1, 16) as macaddr8), cast('10.2.3.4/24' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * - cast('18.5 second' as interval), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), cast('1942-07-23 03:05:09' as timestamp) + - tenthous * - cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * - cast('12 minutes' as interval) - ) - ), - cast('01:30:20+02' - as time with time zone) + - hundred * cast('15 seconds' as interval), - cast(tenthous as numeric(36, 30)) * - fivethous * - even / - (hundred + 1), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20+02' as timetz) + hundred * cast('15 seconds' as interval), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -88,8 +62,7 @@ select to_char(tenthous, 'FM0000') ) as uuid), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn) from tenk1 order by unique2 @@ -97,36 +70,23 @@ limit 100; insert into brintest_multi (inetcol, cidrcol) select - cast('fe80::6e40:8ff:fea9:8c46' as inet) + - tenthous, - cast('fe80::6e40:8ff:fea9:8c46' as cidr) + - tenthous + cast('fe80::6e40:8ff:fea9:8c46' as inet) + tenthous, + cast('fe80::6e40:8ff:fea9:8c46' as cidr) + tenthous from tenk1 order by thousand, tenthous limit 25; -create index "brinidx_multi" -on brintest_multi -using brin -( - int8col - int8_minmax_multi_ops(values_per_range = 7) +create index brinidx_multi on brintest_multi using brin ( + int8col int8_minmax_multi_ops(values_per_range = 7) ); -create index "brinidx_multi" -on brintest_multi -using brin -( - int8col - int8_minmax_multi_ops(values_per_range = 257) +create index brinidx_multi on brintest_multi using brin ( + int8col int8_minmax_multi_ops(values_per_range = 257) ); -create index "brinidx_multi" -on brintest_multi -using brin -( +create index brinidx_multi on brintest_multi using brin ( int8col int8_minmax_multi_ops, int2col int2_minmax_multi_ops, int4col int4_minmax_multi_ops, @@ -141,8 +101,7 @@ using brin datecol date_minmax_multi_ops, timecol time_minmax_multi_ops, timestampcol timestamp_minmax_multi_ops, - timestamptzcol - timestamptz_minmax_multi_ops, + timestamptzcol timestamptz_minmax_multi_ops, intervalcol interval_minmax_multi_ops, timetzcol timetz_minmax_multi_ops, numericcol numeric_minmax_multi_ops, @@ -152,10 +111,7 @@ using brin drop index brinidx_multi; -create index "brinidx_multi" -on brintest_multi -using brin -( +create index brinidx_multi on brintest_multi using brin ( int8col int8_minmax_multi_ops, int2col int2_minmax_multi_ops, int4col int4_minmax_multi_ops, @@ -170,8 +126,7 @@ using brin datecol date_minmax_multi_ops, timecol time_minmax_multi_ops, timestampcol timestamp_minmax_multi_ops, - timestamptzcol - timestamptz_minmax_multi_ops, + timestamptzcol timestamptz_minmax_multi_ops, intervalcol interval_minmax_multi_ops, timetzcol timetz_minmax_multi_ops, numericcol numeric_minmax_multi_ops, @@ -234,20 +189,8 @@ values '{0, 0, 800, 1999, 1428427143}', '{100, 100, 1, 100, 100}' ), - ( - 'int8col', - 'int2', - '{>, >=}', - '{0, 0}', - '{100, 100}' - ), - ( - 'int8col', - 'int4', - '{>, >=}', - '{0, 0}', - '{100, 100}' - ), + ('int8col', 'int2', '{>, >=}', '{0, 0}', '{100, 100}'), + ('int8col', 'int4', '{>, >=}', '{0, 0}', '{100, 100}'), ( 'int8col', 'int8', @@ -410,8 +353,7 @@ values '{100, 100, 1, 100, 100, 25, 100}' ); -do -$do$ +do $x$ DECLARE r record; r2 record; @@ -490,7 +432,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$do$; +$x$; reset enable_seqscan; @@ -502,48 +444,23 @@ select thousand, twothousand, cast(unique1 as oid), - cast(format('(%s,%s)', tenthous, twenty) - as tid), + cast(format('(%s,%s)', tenthous, twenty) as tid), (four + 1.0) / (hundred + 1), - cast(odd as double precision) / - (tenthous + 1), - cast(format( - '%s:00:%s:00:%s:00', - to_hex(odd), - to_hex(even), - to_hex(hundred) - ) + cast(odd as float8) / (tenthous + 1), + cast(format('%s:00:%s:00:%s:00', to_hex(odd), to_hex(even), to_hex(hundred)) as macaddr), - cast(substr( - fipshash(cast(unique1 as text)), - 1, - 16 - ) - as macaddr8), + cast(substr(fipshash(cast(unique1 as text)), 1, 16) as macaddr8), cast('10.2.3.4' as inet) + tenthous, cast('10.2.3/24' as cidr) + tenthous, cast('1995-08-15' as date) + tenthous, - cast('01:20:30' as time) + - thousand * - cast('18.5 second' as interval), + cast('01:20:30' as time) + thousand * cast('18.5 second' as interval), cast('1942-07-23 03:05:09' as timestamp) + - tenthous * - cast('36.38 hours' as interval), - cast('1972-10-10 03:00' - as timestamp with time zone) + + tenthous * cast('36.38 hours' as interval), + cast('1972-10-10 03:00' as timestamptz) + thousand * cast('1 hour' as interval), - justify_days( - justify_hours( - tenthous * - cast('12 minutes' as interval) - ) - ), - cast('01:30:20' as time with time zone) + - hundred * cast('15 seconds' as interval), - cast(tenthous as numeric(36, 30)) * - fivethous * - even / - (hundred + 1), + justify_days(justify_hours(tenthous * cast('12 minutes' as interval))), + cast('01:30:20' as timetz) + hundred * cast('15 seconds' as interval), + cast(tenthous as numeric(36, 30)) * fivethous * even / (hundred + 1), cast(format( '%s%s-%s-%s-%s-%s%s%s', to_char(tenthous, 'FM0000'), @@ -556,8 +473,7 @@ select to_char(tenthous, 'FM0000') ) as uuid), - cast(format('%s/%s%s', odd, even, tenthous) - as pg_lsn) + cast(format('%s/%s%s', odd, even, tenthous) as pg_lsn) from tenk1 order by unique2 @@ -598,35 +514,23 @@ select brin_desummarize_range('brinidx_multi', 0); select brin_desummarize_range('brinidx_multi', 100000000); -create table brin_large_range (a int); +create table brin_large_range (a int4); insert into brin_large_range select i from generate_series(1, 10000) as s (i); -create index "brin_large_range_idx" -on brin_large_range -using brin -( +create index brin_large_range_idx on brin_large_range using brin ( a int4_minmax_multi_ops ); drop table brin_large_range; create table brin_summarize_multi (value int) -with ( - fillfactor = 10, - autovacuum_enabled = 'false' -); +with (fillfactor = 10, autovacuum_enabled = 'false'); -create index "brin_summarize_multi_idx" -on brin_summarize_multi -using brin -( - value -) +create index brin_summarize_multi_idx on brin_summarize_multi using brin (value) with (pages_per_range = 2); -do -$do$ +do $$ DECLARE curtid tid; BEGIN LOOP @@ -634,7 +538,7 @@ BEGIN EXIT WHEN curtid > tid '(2, 0)'; END LOOP; END; -$do$; +$$; select brin_summarize_range('brin_summarize_multi_idx', 0); @@ -654,29 +558,15 @@ create table brin_test_multi ( ); insert into brin_test_multi -select - x / 100, - x % 100 -from - generate_series(1, 10000) as x (x); +select x / 100, x % 100 from generate_series(1, 10000) as x (x); -create index "brin_test_multi_a_idx" -on brin_test_multi -using brin -( - a -) +create index brin_test_multi_a_idx on brin_test_multi using brin (a) with (pages_per_range = 2); -create index "brin_test_multi_b_idx" -on brin_test_multi -using brin -( - b -) +create index brin_test_multi_b_idx on brin_test_multi using brin (b) with (pages_per_range = 2); -vacuum (ANALYZE) brin_test_multi; +vacuum (analyze) brin_test_multi; select * from brin_test_multi where a = 1; @@ -695,63 +585,57 @@ select from generate_series(1, 1000) as s (i); -create index "brin_test_multi_1_idx_1" -on brin_test_multi_1 -using brin -( +create index brin_test_multi_1_idx_1 on brin_test_multi_1 using brin ( a int4_minmax_multi_ops ) with (pages_per_range = 5); -create index "brin_test_multi_1_idx_2" -on brin_test_multi_1 -using brin -( +create index brin_test_multi_1_idx_2 on brin_test_multi_1 using brin ( b int8_minmax_multi_ops ) with (pages_per_range = 5); set enable_seqscan = off; -select COUNT(*) from brin_test_multi_1 where a < 37; +select count(*) from brin_test_multi_1 where a < 37; -select COUNT(*) from brin_test_multi_1 where a < 113; +select count(*) from brin_test_multi_1 where a < 113; -select COUNT(*) from brin_test_multi_1 where a <= 177; +select count(*) from brin_test_multi_1 where a <= 177; -select COUNT(*) from brin_test_multi_1 where a <= 25; +select count(*) from brin_test_multi_1 where a <= 25; -select COUNT(*) from brin_test_multi_1 where a > 120; +select count(*) from brin_test_multi_1 where a > 120; -select COUNT(*) from brin_test_multi_1 where a >= 180; +select count(*) from brin_test_multi_1 where a >= 180; -select COUNT(*) from brin_test_multi_1 where a > 71; +select count(*) from brin_test_multi_1 where a > 71; -select COUNT(*) from brin_test_multi_1 where a >= 63; +select count(*) from brin_test_multi_1 where a >= 63; -select COUNT(*) from brin_test_multi_1 where a = 207; +select count(*) from brin_test_multi_1 where a = 207; -select COUNT(*) from brin_test_multi_1 where a = 177; +select count(*) from brin_test_multi_1 where a = 177; -select COUNT(*) from brin_test_multi_1 where b < 73; +select count(*) from brin_test_multi_1 where b < 73; -select COUNT(*) from brin_test_multi_1 where b <= 47; +select count(*) from brin_test_multi_1 where b <= 47; -select COUNT(*) from brin_test_multi_1 where b < 199; +select count(*) from brin_test_multi_1 where b < 199; -select COUNT(*) from brin_test_multi_1 where b <= 150; +select count(*) from brin_test_multi_1 where b <= 150; -select COUNT(*) from brin_test_multi_1 where b > 93; +select count(*) from brin_test_multi_1 where b > 93; -select COUNT(*) from brin_test_multi_1 where b > 37; +select count(*) from brin_test_multi_1 where b > 37; -select COUNT(*) from brin_test_multi_1 where b >= 215; +select count(*) from brin_test_multi_1 where b >= 215; -select COUNT(*) from brin_test_multi_1 where b > 201; +select count(*) from brin_test_multi_1 where b > 201; -select COUNT(*) from brin_test_multi_1 where b = 88; +select count(*) from brin_test_multi_1 where b = 88; -select COUNT(*) from brin_test_multi_1 where b = 103; +select count(*) from brin_test_multi_1 where b = 103; truncate brin_test_multi_1; @@ -762,45 +646,45 @@ select from generate_series(1, 1000) as s (i); -select COUNT(*) from brin_test_multi_1 where a < 37; +select count(*) from brin_test_multi_1 where a < 37; -select COUNT(*) from brin_test_multi_1 where a < 113; +select count(*) from brin_test_multi_1 where a < 113; -select COUNT(*) from brin_test_multi_1 where a <= 177; +select count(*) from brin_test_multi_1 where a <= 177; -select COUNT(*) from brin_test_multi_1 where a <= 25; +select count(*) from brin_test_multi_1 where a <= 25; -select COUNT(*) from brin_test_multi_1 where a > 120; +select count(*) from brin_test_multi_1 where a > 120; -select COUNT(*) from brin_test_multi_1 where a >= 180; +select count(*) from brin_test_multi_1 where a >= 180; -select COUNT(*) from brin_test_multi_1 where a > 71; +select count(*) from brin_test_multi_1 where a > 71; -select COUNT(*) from brin_test_multi_1 where a >= 63; +select count(*) from brin_test_multi_1 where a >= 63; -select COUNT(*) from brin_test_multi_1 where a = 207; +select count(*) from brin_test_multi_1 where a = 207; -select COUNT(*) from brin_test_multi_1 where a = 177; +select count(*) from brin_test_multi_1 where a = 177; -select COUNT(*) from brin_test_multi_1 where b < 73; +select count(*) from brin_test_multi_1 where b < 73; -select COUNT(*) from brin_test_multi_1 where b <= 47; +select count(*) from brin_test_multi_1 where b <= 47; -select COUNT(*) from brin_test_multi_1 where b < 199; +select count(*) from brin_test_multi_1 where b < 199; -select COUNT(*) from brin_test_multi_1 where b <= 150; +select count(*) from brin_test_multi_1 where b <= 150; -select COUNT(*) from brin_test_multi_1 where b > 93; +select count(*) from brin_test_multi_1 where b > 93; -select COUNT(*) from brin_test_multi_1 where b > 37; +select count(*) from brin_test_multi_1 where b > 37; -select COUNT(*) from brin_test_multi_1 where b >= 215; +select count(*) from brin_test_multi_1 where b >= 215; -select COUNT(*) from brin_test_multi_1 where b > 201; +select count(*) from brin_test_multi_1 where b > 201; -select COUNT(*) from brin_test_multi_1 where b = 88; +select count(*) from brin_test_multi_1 where b = 88; -select COUNT(*) from brin_test_multi_1 where b = 103; +select count(*) from brin_test_multi_1 where b = 103; drop table brin_test_multi_1; @@ -814,7 +698,7 @@ select from ( select - ROW_NUMBER() over (order by v) as c, + row_number() over (order by v) as c, v from ( @@ -828,10 +712,7 @@ from as bar order by c + 25 * random(); -create index "brin_test_multi_2_idx" -on brin_test_multi_2 -using brin -( +create index brin_test_multi_2_idx on brin_test_multi_2 using brin ( a uuid_minmax_multi_ops ) with (pages_per_range = 5); @@ -839,52 +720,46 @@ with (pages_per_range = 5); set enable_seqscan = off; select - COUNT(*) + count(*) from brin_test_multi_2 where - a < - '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; + a < '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a > - '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; + a > '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a <= - 'f369cb89-fc62-7e66-8987-007d121ed1ea'; + a <= 'f369cb89-fc62-7e66-8987-007d121ed1ea'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a >= - 'aea92132-c4cb-eb26-3e6a-c2bf6c183b5d'; + a >= 'aea92132-c4cb-eb26-3e6a-c2bf6c183b5d'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a = - '5feceb66-ffc8-6f38-d952-786c6d696c79'; + a = '5feceb66-ffc8-6f38-d952-786c6d696c79'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a = - '86e50149-6586-6131-2a9e-0b35558d84f6'; + a = '86e50149-6586-6131-2a9e-0b35558d84f6'; truncate brin_test_multi_2; @@ -894,7 +769,7 @@ select from ( select - ROW_NUMBER() over (order by v) as c, + row_number() over (order by v) as c, v from ( @@ -909,83 +784,70 @@ from order by c + 25 * random(); select - COUNT(*) + count(*) from brin_test_multi_2 where - a < - '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; + a < '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a > - '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; + a > '3d914f93-48c9-cc0f-f8a7-9716700b9fcd'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a <= - 'f369cb89-fc62-7e66-8987-007d121ed1ea'; + a <= 'f369cb89-fc62-7e66-8987-007d121ed1ea'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a >= - 'aea92132-c4cb-eb26-3e6a-c2bf6c183b5d'; + a >= 'aea92132-c4cb-eb26-3e6a-c2bf6c183b5d'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a = - '5feceb66-ffc8-6f38-d952-786c6d696c79'; + a = '5feceb66-ffc8-6f38-d952-786c6d696c79'; select - COUNT(*) + count(*) from brin_test_multi_2 where - a = - '86e50149-6586-6131-2a9e-0b35558d84f6'; + a = '86e50149-6586-6131-2a9e-0b35558d84f6'; drop table brin_test_multi_2; reset enable_seqscan; -create table brin_timestamp_test (a timestamp with time zone); +create table brin_timestamp_test (a timestamptz); set datestyle = iso; insert into brin_timestamp_test select - cast('4713-01-01 00:00:01 BC' - as timestamp with time zone) + + cast('4713-01-01 00:00:01 BC' as timestamptz) + cast(i || ' seconds' as interval) from generate_series(1, 30) as s (i); insert into brin_timestamp_test select - cast('294276-12-01 00:00:01' - as timestamp with time zone) + + cast('294276-12-01 00:00:01' as timestamptz) + cast(i || ' seconds' as interval) from generate_series(1, 30) as s (i); -create index -on brin_timestamp_test -using brin -( - a timestamptz_minmax_multi_ops -) +create index on brin_timestamp_test using brin (a timestamptz_minmax_multi_ops) with (pages_per_range = 1); drop table brin_timestamp_test; @@ -993,23 +855,12 @@ drop table brin_timestamp_test; create table brin_date_test (a date); insert into brin_date_test -select - cast('4713-01-01 BC' as date) + i -from - generate_series(1, 30) as s (i); +select cast('4713-01-01 BC' as date) + i from generate_series(1, 30) as s (i); insert into brin_date_test -select - cast('5874897-12-01' as date) + i -from - generate_series(1, 30) as s (i); +select cast('5874897-12-01' as date) + i from generate_series(1, 30) as s (i); -create index -on brin_date_test -using brin -( - a date_minmax_multi_ops -) +create index on brin_date_test using brin (a date_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; @@ -1035,12 +886,7 @@ from ) as s (i); -create index -on brin_timestamp_test -using brin -( - a timestamp_minmax_multi_ops -) +create index on brin_timestamp_test using brin (a timestamp_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; @@ -1058,17 +904,9 @@ create table brin_date_test (a date); insert into brin_date_test values ('-infinity'), ('infinity'); insert into brin_date_test -select - cast('2000-01-01' as date) + i -from - generate_series(1, 40) as s (i); +select cast('2000-01-01' as date) + i from generate_series(1, 40) as s (i); -create index -on brin_date_test -using brin -( - a date_minmax_multi_ops -) +create index on brin_date_test using brin (a date_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; @@ -1089,22 +927,15 @@ insert into brin_interval_test select cast(i || ' years' as interval) from - generate_series(-178000000, -177999980) - as s (i); + generate_series(-178000000, -177999980) as s (i); insert into brin_interval_test select cast(i || ' years' as interval) from - generate_series(177999980, 178000000) - as s (i); + generate_series(177999980, 178000000) as s (i); -create index -on brin_interval_test -using brin -( - a interval_minmax_multi_ops -) +create index on brin_interval_test using brin (a interval_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; @@ -1122,17 +953,9 @@ create table brin_interval_test (a interval); insert into brin_interval_test values ('-infinity'), ('infinity'); insert into brin_interval_test -select - cast(i || ' days' as interval) -from - generate_series(100, 140) as s (i); +select cast(i || ' days' as interval) from generate_series(100, 140) as s (i); -create index -on brin_interval_test -using brin -( - a interval_minmax_multi_ops -) +create index on brin_interval_test using brin (a interval_minmax_multi_ops) with (pages_per_range = 1); set enable_seqscan = off; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__btree_index_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__btree_index_100.snap index 749b6d166..60240eb31 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__btree_index_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__btree_index_100.snap @@ -3,23 +3,23 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/btree_index.sql --- create table bt_i4_heap ( - seqno int, - random int + seqno int4, + random int4 ); create table bt_name_heap ( seqno name, - random int + random int4 ); create table bt_txt_heap ( seqno text, - random int + random int4 ); create table bt_f8_heap ( - seqno double precision, - random int + seqno float8, + random int4 ); copy bt_i4_heap from 'filename'; @@ -38,13 +38,13 @@ analyze bt_txt_heap; analyze bt_f8_heap; -create index "bt_i4_index" on bt_i4_heap using btree (seqno int4_ops); +create index bt_i4_index on bt_i4_heap using btree (seqno int4_ops); -create index "bt_name_index" on bt_name_heap using btree (seqno name_ops); +create index bt_name_index on bt_name_heap using btree (seqno name_ops); -create index "bt_txt_index" on bt_txt_heap using btree (seqno text_ops); +create index bt_txt_index on bt_txt_heap using btree (seqno text_ops); -create index "bt_f8_index" on bt_f8_heap using btree (seqno float8_ops); +create index bt_f8_index on bt_f8_heap using btree (seqno float8_ops); select b.* from bt_i4_heap as b where b.seqno < 1; @@ -64,11 +64,11 @@ select b.* from bt_txt_heap as b where b.seqno >= cast('9999' as text); select b.* from bt_txt_heap as b where b.seqno = cast('4500' as text); -select b.* from bt_f8_heap as b where b.seqno < cast('1' as double precision); +select b.* from bt_f8_heap as b where b.seqno < cast('1' as float8); -select b.* from bt_f8_heap as b where b.seqno >= cast('9999' as double precision); +select b.* from bt_f8_heap as b where b.seqno >= cast('9999' as float8); -select b.* from bt_f8_heap as b where b.seqno = cast('4500' as double precision); +select b.* from bt_f8_heap as b where b.seqno = cast('4500' as float8); select proname, @@ -129,8 +129,7 @@ select from pg_proc where - (proname, proargtypes) >= ('abs', null) and - proname <= 'abs' + (proname, proargtypes) >= ('abs', null) and proname <= 'abs' order by proname, proargtypes, pronamespace; @@ -142,8 +141,7 @@ select from pg_proc where - (proname, proargtypes) >= ('abs', null) and - proname <= 'abs' + (proname, proargtypes) >= ('abs', null) and proname <= 'abs' order by proname, proargtypes, pronamespace; @@ -155,8 +153,7 @@ select from pg_proc where - proname >= 'abs' and - (proname, proargtypes) < ('abs', null) + proname >= 'abs' and (proname, proargtypes) < ('abs', null) order by proname, proargtypes, pronamespace; @@ -168,8 +165,7 @@ select from pg_proc where - proname >= 'abs' and - (proname, proargtypes) < ('abs', null) + proname >= 'abs' and (proname, proargtypes) < ('abs', null) order by proname, proargtypes, pronamespace; @@ -181,8 +177,7 @@ select from pg_proc where - proname >= 'abs' and - (proname, proargtypes) <= ('abs', null) + proname >= 'abs' and (proname, proargtypes) <= ('abs', null) order by proname desc, proargtypes desc, pronamespace desc; @@ -194,8 +189,7 @@ select from pg_proc where - proname >= 'abs' and - (proname, proargtypes) <= ('abs', null) + proname >= 'abs' and (proname, proargtypes) <= ('abs', null) order by proname desc, proargtypes desc, pronamespace desc; @@ -207,8 +201,7 @@ select from pg_proc where - (proname, proargtypes) > ('abs', null) and - proname <= 'abs' + (proname, proargtypes) > ('abs', null) and proname <= 'abs' order by proname desc, proargtypes desc, pronamespace desc; @@ -220,8 +213,7 @@ select from pg_proc where - (proname, proargtypes) > ('abs', null) and - proname <= 'abs' + (proname, proargtypes) > ('abs', null) and proname <= 'abs' order by proname desc, proargtypes desc, pronamespace desc; @@ -324,13 +316,7 @@ reset enable_bitmapscan; create temporary table btree_bpchar (f1 text collate "C"); -create index -on btree_bpchar -using btree -( - f1 bpchar_ops -) -with (deduplicate_items = 'on'); +create index on btree_bpchar using btree (f1 bpchar_ops) with (deduplicate_items = 'on'); insert into btree_bpchar values ('foo'), ('fool'), ('bar'), ('quux'); @@ -354,31 +340,19 @@ insert into btree_bpchar select 'foo' from generate_series(1, 1500); create table dedup_unique_test_table (a int) with (autovacuum_enabled = 'false'); -create unique index "dedup_unique" -on dedup_unique_test_table -using btree -( - a -) +create unique index dedup_unique on dedup_unique_test_table using btree (a) with (deduplicate_items = 'on'); -create unique index "plain_unique" -on dedup_unique_test_table -using btree -( - a -) +create unique index plain_unique on dedup_unique_test_table using btree (a) with (deduplicate_items = off); -do -$do$ +do $$ BEGIN FOR r IN 1..1350 LOOP DELETE FROM dedup_unique_test_table; INSERT INTO dedup_unique_test_table SELECT 1; END LOOP; -END -$do$; +END$$; drop index plain_unique; @@ -387,21 +361,14 @@ delete from dedup_unique_test_table where a = 1; insert into dedup_unique_test_table select i from generate_series(0, 450) as i; create table btree_tall_tbl ( - id int, + id int4, t text ); alter table btree_tall_tbl alter column t set storage plain; -create index "btree_tall_idx" -on btree_tall_tbl -using btree -( - t, - id -) -with (fillfactor = 10); +create index btree_tall_idx on btree_tall_tbl using btree (t, id) with (fillfactor = 10); insert into btree_tall_tbl select g, repeat('x', 250) from generate_series(1, 130) as g; @@ -457,7 +424,7 @@ set local min_parallel_table_scan_size = 0; set local max_parallel_maintenance_workers = 4; -create index "btree_test_expr_idx" on btree_test_expr using btree ((btree_test_func())); +create index btree_test_expr_idx on btree_test_expr using btree ((btree_test_func())); commit; @@ -465,17 +432,17 @@ drop table btree_test_expr; drop function btree_test_func(); -create index "btree_tall_idx2" on btree_tall_tbl using btree (id); +create index btree_tall_idx2 on btree_tall_tbl using btree (id); alter index btree_tall_idx2 alter column id set (n_distinct = 100); drop index btree_tall_idx2; -create table btree_part (id int) +create table btree_part (id int4) partition by range(id); -create index "btree_part_idx" on btree_part using btree (id); +create index btree_part_idx on btree_part using btree (id); alter index btree_part_idx alter column id set (n_distinct = 100); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__btree_index_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__btree_index_80.snap index a662e23f9..463bef6d3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__btree_index_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__btree_index_80.snap @@ -3,23 +3,23 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/btree_index.sql --- create table bt_i4_heap ( - seqno int, - random int + seqno int4, + random int4 ); create table bt_name_heap ( seqno name, - random int + random int4 ); create table bt_txt_heap ( seqno text, - random int + random int4 ); create table bt_f8_heap ( - seqno double precision, - random int + seqno float8, + random int4 ); copy bt_i4_heap from 'filename'; @@ -38,13 +38,13 @@ analyze bt_txt_heap; analyze bt_f8_heap; -create index "bt_i4_index" on bt_i4_heap using btree (seqno int4_ops); +create index bt_i4_index on bt_i4_heap using btree (seqno int4_ops); -create index "bt_name_index" on bt_name_heap using btree (seqno name_ops); +create index bt_name_index on bt_name_heap using btree (seqno name_ops); -create index "bt_txt_index" on bt_txt_heap using btree (seqno text_ops); +create index bt_txt_index on bt_txt_heap using btree (seqno text_ops); -create index "bt_f8_index" on bt_f8_heap using btree (seqno float8_ops); +create index bt_f8_index on bt_f8_heap using btree (seqno float8_ops); select b.* from bt_i4_heap as b where b.seqno < 1; @@ -64,23 +64,11 @@ select b.* from bt_txt_heap as b where b.seqno >= cast('9999' as text); select b.* from bt_txt_heap as b where b.seqno = cast('4500' as text); -select b.* from bt_f8_heap as b where b.seqno < cast('1' as double precision); +select b.* from bt_f8_heap as b where b.seqno < cast('1' as float8); -select - b.* -from - bt_f8_heap as b -where - b.seqno >= - cast('9999' as double precision); +select b.* from bt_f8_heap as b where b.seqno >= cast('9999' as float8); -select - b.* -from - bt_f8_heap as b -where - b.seqno = - cast('4500' as double precision); +select b.* from bt_f8_heap as b where b.seqno = cast('4500' as float8); select proname, @@ -115,8 +103,7 @@ select from pg_proc where - (proname, pronamespace) < - ('abs', 1000000) + (proname, pronamespace) < ('abs', 1000000) order by proname desc, proargtypes desc, pronamespace desc @@ -129,8 +116,7 @@ select from pg_proc where - (proname, pronamespace) < - ('abs', 1000000) + (proname, pronamespace) < ('abs', 1000000) order by proname desc, proargtypes desc, pronamespace desc @@ -143,8 +129,7 @@ select from pg_proc where - (proname, proargtypes) >= ('abs', null) and - proname <= 'abs' + (proname, proargtypes) >= ('abs', null) and proname <= 'abs' order by proname, proargtypes, pronamespace; @@ -156,8 +141,7 @@ select from pg_proc where - (proname, proargtypes) >= ('abs', null) and - proname <= 'abs' + (proname, proargtypes) >= ('abs', null) and proname <= 'abs' order by proname, proargtypes, pronamespace; @@ -169,8 +153,7 @@ select from pg_proc where - proname >= 'abs' and - (proname, proargtypes) < ('abs', null) + proname >= 'abs' and (proname, proargtypes) < ('abs', null) order by proname, proargtypes, pronamespace; @@ -182,8 +165,7 @@ select from pg_proc where - proname >= 'abs' and - (proname, proargtypes) < ('abs', null) + proname >= 'abs' and (proname, proargtypes) < ('abs', null) order by proname, proargtypes, pronamespace; @@ -195,8 +177,7 @@ select from pg_proc where - proname >= 'abs' and - (proname, proargtypes) <= ('abs', null) + proname >= 'abs' and (proname, proargtypes) <= ('abs', null) order by proname desc, proargtypes desc, pronamespace desc; @@ -208,8 +189,7 @@ select from pg_proc where - proname >= 'abs' and - (proname, proargtypes) <= ('abs', null) + proname >= 'abs' and (proname, proargtypes) <= ('abs', null) order by proname desc, proargtypes desc, pronamespace desc; @@ -221,8 +201,7 @@ select from pg_proc where - (proname, proargtypes) > ('abs', null) and - proname <= 'abs' + (proname, proargtypes) > ('abs', null) and proname <= 'abs' order by proname desc, proargtypes desc, pronamespace desc; @@ -234,8 +213,7 @@ select from pg_proc where - (proname, proargtypes) > ('abs', null) and - proname <= 'abs' + (proname, proargtypes) > ('abs', null) and proname <= 'abs' order by proname desc, proargtypes desc, pronamespace desc; @@ -276,8 +254,7 @@ select from tenk1 where - thousand in (182, 183) and - tenthous > 7550; + thousand in (182, 183) and tenthous > 7550; select thousand, @@ -285,8 +262,7 @@ select from tenk1 where - thousand in (182, 183) and - tenthous > 7550; + thousand in (182, 183) and tenthous > 7550; set enable_seqscan = 'false'; @@ -359,16 +335,14 @@ select from tenk1 where - thousand in (364, 366, 380) and - tenthous = 200000; + thousand in (364, 366, 380) and tenthous = 200000; select thousand from tenk1 where - thousand in (364, 366, 380) and - tenthous = 200000; + thousand in (364, 366, 380) and tenthous = 200000; set enable_seqscan = 'false'; @@ -408,12 +382,7 @@ reset enable_bitmapscan; create temporary table btree_bpchar (f1 text collate "C"); -create index -on btree_bpchar -using btree -( - f1 bpchar_ops -) +create index on btree_bpchar using btree (f1 bpchar_ops) with (deduplicate_items = 'on'); insert into btree_bpchar values ('foo'), ('fool'), ('bar'), ('quux'); @@ -439,31 +408,19 @@ insert into btree_bpchar select 'foo' from generate_series(1, 1500); create table dedup_unique_test_table (a int) with (autovacuum_enabled = 'false'); -create unique index "dedup_unique" -on dedup_unique_test_table -using btree -( - a -) +create unique index dedup_unique on dedup_unique_test_table using btree (a) with (deduplicate_items = 'on'); -create unique index "plain_unique" -on dedup_unique_test_table -using btree -( - a -) +create unique index plain_unique on dedup_unique_test_table using btree (a) with (deduplicate_items = off); -do -$do$ +do $$ BEGIN FOR r IN 1..1350 LOOP DELETE FROM dedup_unique_test_table; INSERT INTO dedup_unique_test_table SELECT 1; END LOOP; -END -$do$; +END$$; drop index plain_unique; @@ -472,28 +429,18 @@ delete from dedup_unique_test_table where a = 1; insert into dedup_unique_test_table select i from generate_series(0, 450) as i; create table btree_tall_tbl ( - id int, + id int4, t text ); alter table btree_tall_tbl alter column t set storage plain; -create index "btree_tall_idx" -on btree_tall_tbl -using btree -( - t, - id -) +create index btree_tall_idx on btree_tall_tbl using btree (t, id) with (fillfactor = 10); insert into btree_tall_tbl -select - g, - repeat('x', 250) -from - generate_series(1, 130) as g; +select g, repeat('x', 250) from generate_series(1, 130) as g; insert into btree_tall_tbl select g, null from generate_series(50, 60) as g; @@ -521,13 +468,7 @@ create table delete_test_table ( ); insert into delete_test_table -select - i, - 1, - 2, - 3 -from - generate_series(1, 80000) as i; +select i, 1, 2, 3 from generate_series(1, 80000) as i; alter table delete_test_table add primary key (a, b, c, d); @@ -537,13 +478,7 @@ delete from delete_test_table where a < 79990; vacuum delete_test_table; insert into delete_test_table -select - i, - 1, - 2, - 3 -from - generate_series(1, 1000) as i; +select i, 1, 2, 3 from generate_series(1, 1000) as i; create index on btree_tall_tbl using btree (id int4_ops(foo = 1)); @@ -561,10 +496,7 @@ set local min_parallel_table_scan_size = 0; set local max_parallel_maintenance_workers = 4; -create index "btree_test_expr_idx" -on btree_test_expr -using btree -( +create index btree_test_expr_idx on btree_test_expr using btree ( (btree_test_func()) ); @@ -574,17 +506,17 @@ drop table btree_test_expr; drop function btree_test_func(); -create index "btree_tall_idx2" on btree_tall_tbl using btree (id); +create index btree_tall_idx2 on btree_tall_tbl using btree (id); alter index btree_tall_idx2 alter column id set (n_distinct = 100); drop index btree_tall_idx2; -create table btree_part (id int) +create table btree_part (id int4) partition by range(id); -create index "btree_part_idx" on btree_part using btree (id); +create index btree_part_idx on btree_part using btree (id); alter index btree_part_idx alter column id set (n_distinct = 100); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_100.snap index 41b63019c..bc40bb140 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_100.snap @@ -126,9 +126,7 @@ create function vol(text) returns text language plpgsql volatile -as $function$ -begin return $1; end -$function$; +as 'begin return $1; end'; select case case vol('bar') @@ -147,18 +145,14 @@ create function volfoo(text) returns foodomain language plpgsql volatile -as $function$ -begin return $1::foodomain; end -$function$; +as 'begin return $1::foodomain; end'; create function inline_eq(foodomain, foodomain) returns boolean language sql -as $function$ -SELECT CASE $2::text WHEN $1::text THEN true ELSE false END -$function$; +as 'SELECT CASE $2::text WHEN $1::text THEN true ELSE false END'; -create operator = (PROCEDURE = inline_eq, LEFTARG = foodomain, RIGHTARG = foodomain); +create operator = (procedure = inline_eq, leftarg = foodomain, rightarg = foodomain); select case volfoo('bar') when cast('foo' as foodomain) then 'is foo' else 'is not foo' end; @@ -172,28 +166,23 @@ create function make_ad(int, int) returns arrdomain language plpgsql volatile -as $function$ -declare x arrdomain; +as 'declare x arrdomain; begin x := array[$1,$2]; return x; - end -$function$; + end'; create function ad_eq(arrdomain, arrdomain) returns boolean language plpgsql -as $function$ -begin return array_eq($1, $2); end -$function$; +as 'begin return array_eq($1, $2); end'; -create operator = (PROCEDURE = ad_eq, LEFTARG = arrdomain, RIGHTARG = arrdomain); +create operator = (procedure = ad_eq, leftarg = arrdomain, rightarg = arrdomain); select case make_ad(1, 2) when cast(array[2, 4] as arrdomain) then 'wrong' - when cast(array[2, 5] as arrdomain) - then 'still wrong' + when cast(array[2, 5] as arrdomain) then 'still wrong' when cast(array[1, 2] as arrdomain) then 'right' end; @@ -208,9 +197,7 @@ create type casetestenum as enum ('e', 'f', 'g'); select case cast('foo' as text) when 'foo' - then array['a', 'b', 'c', 'd'] || - cast(enum_range(cast(null as casetestenum)) - as text[]) + then array['a', 'b', 'c', 'd'] || cast(enum_range(cast(null as casetestenum)) as text[]) else array['x', 'y'] end; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_80.snap index 1e5a3550c..e34c883d1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_80.snap @@ -42,11 +42,7 @@ select '4' as "One", case when 1 > 2 then 3 else 4 end as "ELSE default"; select '6' as "One", - case - when 1 > 2 then 3 - when 4 < 5 then 6 - else 7 - end + case when 1 > 2 then 3 when 4 < 5 then 6 else 7 end as "Two WHEN with default"; select '7' as "None", case when random() < 0 then 1 end as "NULL on no matches"; @@ -120,10 +116,7 @@ update case_tbl set i = case when i >= 2 then 2 * i else 3 * i end; select * from case_tbl; update case_tbl -set i = case - when b.i >= 2 then 2 * j - else 3 * j -end +set i = case when b.i >= 2 then 2 * j else 3 * j end from case2_tbl as b where j = -case_tbl.i; @@ -136,9 +129,7 @@ create function vol(text) returns text language plpgsql volatile -as $function$ -begin return $1; end -$function$; +as 'begin return $1; end'; select case case vol('bar') @@ -157,25 +148,22 @@ create function volfoo(text) returns foodomain language plpgsql volatile -as $function$ -begin return $1::foodomain; end -$function$; +as 'begin return $1::foodomain; end'; create function inline_eq(foodomain, foodomain) returns boolean language sql -as $function$ -SELECT CASE $2::text WHEN $1::text THEN true ELSE false END -$function$; +as 'SELECT CASE $2::text WHEN $1::text THEN true ELSE false END'; -create operator = (PROCEDURE = inline_eq, -LEFTARG = foodomain, -RIGHTARG = foodomain); +create operator = ( + procedure = inline_eq, + leftarg = foodomain, + rightarg = foodomain +); select case volfoo('bar') - when cast('foo' as foodomain) - then 'is foo' + when cast('foo' as foodomain) then 'is foo' else 'is not foo' end; @@ -189,33 +177,28 @@ create function make_ad(int, int) returns arrdomain language plpgsql volatile -as $function$ -declare x arrdomain; +as 'declare x arrdomain; begin x := array[$1,$2]; return x; - end -$function$; + end'; create function ad_eq(arrdomain, arrdomain) returns boolean language plpgsql -as $function$ -begin return array_eq($1, $2); end -$function$; +as 'begin return array_eq($1, $2); end'; -create operator = (PROCEDURE = ad_eq, -LEFTARG = arrdomain, -RIGHTARG = arrdomain); +create operator = ( + procedure = ad_eq, + leftarg = arrdomain, + rightarg = arrdomain +); select case make_ad(1, 2) - when cast(array[2, 4] as arrdomain) - then 'wrong' - when cast(array[2, 5] as arrdomain) - then 'still wrong' - when cast(array[1, 2] as arrdomain) - then 'right' + when cast(array[2, 4] as arrdomain) then 'wrong' + when cast(array[2, 5] as arrdomain) then 'still wrong' + when cast(array[1, 2] as arrdomain) then 'right' end; select nullif(make_ad(1, 2), cast(array[2, 3] as arrdomain)); @@ -230,8 +213,7 @@ select case cast('foo' as text) when 'foo' then array['a', 'b', 'c', 'd'] || - cast(enum_range(cast(null as casetestenum)) - as text[]) + cast(enum_range(cast(null as casetestenum)) as text[]) else array['x', 'y'] end; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__char_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__char_80.snap index 797b8ce9a..c6ddc2562 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__char_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__char_80.snap @@ -4,9 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/char.sql snapshot_kind: text --- select - cast('c' as pg_catalog.bpchar) = - cast('c' as pg_catalog.bpchar) - as "true"; + cast('c' as pg_catalog.bpchar) = cast('c' as pg_catalog.bpchar) as "true"; create temporary table char_tbl (f1 char(1)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__cluster_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__cluster_100.snap index a00bb4668..1cdecb481 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__cluster_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__cluster_100.snap @@ -13,19 +13,16 @@ create table clstr_tst ( b int, c text, d text, - constraint "clstr_tst_con" - foreign key - (b) - references clstr_tst_s + constraint clstr_tst_con foreign key (b) references clstr_tst_s ); -create index "clstr_tst_b" on clstr_tst using btree (b); +create index clstr_tst_b on clstr_tst using btree (b); -create index "clstr_tst_c" on clstr_tst using btree (c); +create index clstr_tst_c on clstr_tst using btree (c); -create index "clstr_tst_c_b" on clstr_tst using btree (c, b); +create index clstr_tst_c_b on clstr_tst using btree (c, b); -create index "clstr_tst_b_c" on clstr_tst using btree (b, c); +create index clstr_tst_b_c on clstr_tst using btree (b, c); insert into clstr_tst_s (b) values (0); @@ -108,17 +105,17 @@ insert into clstr_tst (b, c, d) values (6, 'seis', repeat('xyzzy', 100000)); cluster clstr_tst using clstr_tst_c; -select a, b, c, SUBSTRING(d from 1 for cast(30 as int)), length(d) from clstr_tst; +select a, b, c, substring(d from 1 for cast(30 as int)), length(d) from clstr_tst; -select a, b, c, SUBSTRING(d from 1 for cast(30 as int)), length(d) from clstr_tst order by a; +select a, b, c, substring(d from 1 for cast(30 as int)), length(d) from clstr_tst order by a; -select a, b, c, SUBSTRING(d from 1 for cast(30 as int)), length(d) from clstr_tst order by b; +select a, b, c, substring(d from 1 for cast(30 as int)), length(d) from clstr_tst order by b; -select a, b, c, SUBSTRING(d from 1 for cast(30 as int)), length(d) from clstr_tst order by c; +select a, b, c, substring(d from 1 for cast(30 as int)), length(d) from clstr_tst order by c; insert into clstr_tst_inh values (0, 100, 'in child table'); -select a, b, c, SUBSTRING(d from 1 for cast(30 as int)), length(d) from clstr_tst; +select a, b, c, substring(d from 1 for cast(30 as int)), length(d) from clstr_tst; insert into clstr_tst (b, c) values (1111, 'this should fail'); @@ -127,11 +124,7 @@ select conname from pg_constraint where conrelid = cast('clstr_tst' as regclass) select relname, relkind, - exists - ( - select 1 from pg_class where oid = c.reltoastrelid - ) - as hastoast + exists (select 1 from pg_class where oid = c.reltoastrelid) as hastoast from pg_class as c where @@ -196,7 +189,7 @@ alter table clstr_1 alter table clstr_3 owner to regress_clstr_user; -grant SELECT on table clstr_2 to regress_clstr_user; +grant select on table clstr_2 to regress_clstr_user; insert into clstr_1 values (2); @@ -328,13 +321,13 @@ create table clstrpart3 partition of clstrpart default partition by range(a); create table clstrpart33 partition of clstrpart3 default; -create index "clstrpart_only_idx" on only clstrpart using btree (a); +create index clstrpart_only_idx on only clstrpart using btree (a); cluster clstrpart using clstrpart_only_idx; drop index clstrpart_only_idx; -create index "clstrpart_idx" on clstrpart using btree (a); +create index clstrpart_idx on clstrpart using btree (a); create temporary table old_cluster_info as @@ -344,8 +337,7 @@ as relfilenode, relkind from - pg_partition_tree(cast('clstrpart' as regclass)) - as tree + pg_partition_tree(cast('clstrpart' as regclass)) as tree inner join pg_class as c on c.oid = tree.relid; @@ -360,8 +352,7 @@ as relfilenode, relkind from - pg_partition_tree(cast('clstrpart' as regclass)) - as tree + pg_partition_tree(cast('clstrpart' as regclass)) as tree inner join pg_class as c on c.oid = tree.relid; @@ -372,10 +363,7 @@ select old.relkind, old.relfilenode = new.relfilenode from - old_cluster_info as old - inner join - new_cluster_info as new - using ("relname") + old_cluster_info as old inner join new_cluster_info as new using (relname) order by relname collate "C"; cluster clstrpart; @@ -389,9 +377,9 @@ alter table clstrpart drop table clstrpart; create table ptnowner (i int unique) -partition by LIST(i); +partition by list(i); -create index "ptnowner_i_idx" on ptnowner using btree (i); +create index ptnowner_i_idx on ptnowner using btree (i); create table ptnowner1 partition of ptnowner for values in (1); @@ -418,10 +406,7 @@ as relname, relfilenode from - pg_partition_tree('ptnowner') as tree - inner join - pg_class as c - on c.oid = tree.relid; + pg_partition_tree('ptnowner') as tree inner join pg_class as c on c.oid = tree.relid; set session authorization regress_ptnowner; @@ -433,10 +418,7 @@ select a.relname, a.relfilenode = b.relfilenode from - pg_class as a - inner join - ptnowner_oldnodes as b - using ("oid") + pg_class as a inner join ptnowner_oldnodes as b using (oid) order by a.relname collate "C"; drop table ptnowner; @@ -445,7 +427,7 @@ drop role regress_ptnowner; create table clstr_4 as select * from tenk1; -create index "cluster_sort" on clstr_4 using btree (hundred, thousand, tenthous); +create index cluster_sort on clstr_4 using btree (hundred, thousand, tenthous); set enable_indexscan = off; @@ -459,18 +441,17 @@ from ( select hundred, - LAG(hundred) over () as lhundred, + lag(hundred) over () as lhundred, thousand, - LAG(thousand) over () as lthousand, + lag(thousand) over () as lthousand, tenthous, - LAG(tenthous) over () as ltenthous + lag(tenthous) over () as ltenthous from clstr_4 ) as ss where - row(hundred, thousand, tenthous) <= - row(lhundred, lthousand, ltenthous); + row(hundred, thousand, tenthous) <= row(lhundred, lthousand, ltenthous); reset enable_indexscan; @@ -483,15 +464,11 @@ create table clstr_expression ( ); insert into clstr_expression (a, b) -select - g.i % 42, - 'prefix' || g.i -from - generate_series(1, 133) as g (i); +select g.i % 42, 'prefix' || g.i from generate_series(1, 133) as g (i); -create index "clstr_expression_minus_a" on clstr_expression using btree ((-a), b); +create index clstr_expression_minus_a on clstr_expression using btree ((-a), b); -create index "clstr_expression_upper_b" on clstr_expression using btree ((upper(b))); +create index clstr_expression_upper_b on clstr_expression using btree ((upper(b))); begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__cluster_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__cluster_80.snap index d85cc7b3e..0c5cf8f0e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__cluster_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__cluster_80.snap @@ -13,19 +13,16 @@ create table clstr_tst ( b int, c text, d text, - constraint "clstr_tst_con" - foreign key - (b) - references clstr_tst_s + constraint clstr_tst_con foreign key (b) references clstr_tst_s ); -create index "clstr_tst_b" on clstr_tst using btree (b); +create index clstr_tst_b on clstr_tst using btree (b); -create index "clstr_tst_c" on clstr_tst using btree (c); +create index clstr_tst_c on clstr_tst using btree (c); -create index "clstr_tst_c_b" on clstr_tst using btree (c, b); +create index clstr_tst_c_b on clstr_tst using btree (c, b); -create index "clstr_tst_b_c" on clstr_tst using btree (b, c); +create index clstr_tst_b_c on clstr_tst using btree (b, c); insert into clstr_tst_s (b) values (0); @@ -112,7 +109,7 @@ select a, b, c, - SUBSTRING(d from 1 for cast(30 as int)), + substring(d from 1 for cast(30 as int)), length(d) from clstr_tst; @@ -121,7 +118,7 @@ select a, b, c, - SUBSTRING(d from 1 for cast(30 as int)), + substring(d from 1 for cast(30 as int)), length(d) from clstr_tst @@ -131,7 +128,7 @@ select a, b, c, - SUBSTRING(d from 1 for cast(30 as int)), + substring(d from 1 for cast(30 as int)), length(d) from clstr_tst @@ -141,7 +138,7 @@ select a, b, c, - SUBSTRING(d from 1 for cast(30 as int)), + substring(d from 1 for cast(30 as int)), length(d) from clstr_tst @@ -153,7 +150,7 @@ select a, b, c, - SUBSTRING(d from 1 for cast(30 as int)), + substring(d from 1 for cast(30 as int)), length(d) from clstr_tst; @@ -171,16 +168,7 @@ order by 1; select relname, relkind, - exists - ( - select - 1 - from - pg_class - where - oid = c.reltoastrelid - ) - as hastoast + exists (select 1 from pg_class where oid = c.reltoastrelid) as hastoast from pg_class as c where @@ -245,7 +233,7 @@ alter table clstr_1 alter table clstr_3 owner to regress_clstr_user; -grant SELECT on table clstr_2 to regress_clstr_user; +grant select on table clstr_2 to regress_clstr_user; insert into clstr_1 values (2); @@ -265,9 +253,7 @@ cluster clstr_1 using clstr_1_pkey; cluster clstr_2 using clstr_2_pkey; -select * from clstr_1 -union all -select * from clstr_2 +select * from clstr_1 union all select * from clstr_2 union all select * from clstr_3; @@ -297,9 +283,7 @@ cluster; reset client_min_messages; -select * from clstr_1 -union all -select * from clstr_2 +select * from clstr_1 union all select * from clstr_2 union all select * from clstr_3; @@ -391,13 +375,13 @@ create table clstrpart3 partition of clstrpart default partition by range(a); create table clstrpart33 partition of clstrpart3 default; -create index "clstrpart_only_idx" on only clstrpart using btree (a); +create index clstrpart_only_idx on only clstrpart using btree (a); cluster clstrpart using clstrpart_only_idx; drop index clstrpart_only_idx; -create index "clstrpart_idx" on clstrpart using btree (a); +create index clstrpart_idx on clstrpart using btree (a); create temporary table old_cluster_info as @@ -407,10 +391,7 @@ as relfilenode, relkind from - pg_partition_tree( - cast('clstrpart' as regclass) - ) - as tree + pg_partition_tree(cast('clstrpart' as regclass)) as tree inner join pg_class as c on c.oid = tree.relid; @@ -425,10 +406,7 @@ as relfilenode, relkind from - pg_partition_tree( - cast('clstrpart' as regclass) - ) - as tree + pg_partition_tree(cast('clstrpart' as regclass)) as tree inner join pg_class as c on c.oid = tree.relid; @@ -439,10 +417,7 @@ select old.relkind, old.relfilenode = new.relfilenode from - old_cluster_info as old - inner join - new_cluster_info as new - using ("relname") + old_cluster_info as old inner join new_cluster_info as new using (relname) order by relname collate "C"; cluster clstrpart; @@ -456,9 +431,9 @@ alter table clstrpart drop table clstrpart; create table ptnowner (i int unique) -partition by LIST(i); +partition by list(i); -create index "ptnowner_i_idx" on ptnowner using btree (i); +create index ptnowner_i_idx on ptnowner using btree (i); create table ptnowner1 partition of ptnowner for values in (1); @@ -500,10 +475,7 @@ select a.relname, a.relfilenode = b.relfilenode from - pg_class as a - inner join - ptnowner_oldnodes as b - using ("oid") + pg_class as a inner join ptnowner_oldnodes as b using (oid) order by a.relname collate "C"; drop table ptnowner; @@ -512,14 +484,7 @@ drop role regress_ptnowner; create table clstr_4 as select * from tenk1; -create index "cluster_sort" -on clstr_4 -using btree -( - hundred, - thousand, - tenthous -); +create index cluster_sort on clstr_4 using btree (hundred, thousand, tenthous); set enable_indexscan = off; @@ -533,18 +498,17 @@ from ( select hundred, - LAG(hundred) over () as lhundred, + lag(hundred) over () as lhundred, thousand, - LAG(thousand) over () as lthousand, + lag(thousand) over () as lthousand, tenthous, - LAG(tenthous) over () as ltenthous + lag(tenthous) over () as ltenthous from clstr_4 ) as ss where - row(hundred, thousand, tenthous) <= - row(lhundred, lthousand, ltenthous); + row(hundred, thousand, tenthous) <= row(lhundred, lthousand, ltenthous); reset enable_indexscan; @@ -557,24 +521,11 @@ create table clstr_expression ( ); insert into clstr_expression (a, b) -select - g.i % 42, - 'prefix' || g.i -from - generate_series(1, 133) as g (i); - -create index "clstr_expression_minus_a" -on clstr_expression -using btree -( - (-a), - b -); +select g.i % 42, 'prefix' || g.i from generate_series(1, 133) as g (i); + +create index clstr_expression_minus_a on clstr_expression using btree ((-a), b); -create index "clstr_expression_upper_b" -on clstr_expression -using btree -( +create index clstr_expression_upper_b on clstr_expression using btree ( (upper(b)) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_100.snap index f29904d0c..bb9f1f3a7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_100.snap @@ -4,20 +4,12 @@ input_file: crates/pgls_pretty_print/tests/data/multi/collate.icu.utf8.sql --- select getdatabaseencoding() <> 'UTF8' or - ( - select - COUNT(*) - from - pg_collation - where - collprovider = 'i' and collname <> 'unicode' - ) = - 0 + (select count(*) from pg_collation where collprovider = 'i' and collname <> 'unicode') = 0 as skip_test; set client_encoding to utf8; -create schema "collate_tests"; +create schema collate_tests; set search_path to collate_tests; @@ -214,27 +206,13 @@ select 'bıt' ~* 'BIT' collate "tr-x-icu" as "false"; select relname from pg_class where relname ~* '^abc'; create view collview1 -as select - * -from - collate_test1 -where - b collate "C" >= 'bbc'; +as select * from collate_test1 where b collate "C" >= 'bbc'; create view collview2 -as select - a, - b -from - collate_test1 -order by b collate "C"; +as select a, b from collate_test1 order by b collate "C"; create view collview3 -as select - a, - lower((x || x) collate "C") -from - collate_test10; +as select a, lower((x || x) collate "C") from collate_test10; select table_name, @@ -287,11 +265,11 @@ select a, cast(b as testdomain_sv) from collate_test3 order by 2; select a, lower(cast(x as testdomain)), lower(cast(y as testdomain)) from collate_test10; -select MIN(b), MAX(b) from collate_test1; +select min(b), max(b) from collate_test1; -select MIN(b), MAX(b) from collate_test2; +select min(b), max(b) from collate_test2; -select MIN(b), MAX(b) from collate_test3; +select min(b), max(b) from collate_test3; select array_agg(b order by b) from collate_test1; @@ -330,17 +308,9 @@ select x, y from collate_test10 order by x || y; with recursive foo (x) as ( - select - x - from - (values ('a' collate "en-x-icu"), ('b')) as t (x) + select x from (values ('a' collate "en-x-icu"), ('b')) as t (x) union all - select - (x || 'c') collate "de-x-icu" - from - foo - where - length(x) < 10 + select (x || 'c') collate "de-x-icu" from foo where length(x) < 10 ) select * @@ -356,23 +326,17 @@ select a, cast(b as varchar) from collate_test3 order by 2; create function mylt(text, text) returns boolean language sql -as $function$ -select $1 < $2 -$function$; +as $$ select $1 < $2 $$; create function mylt_noninline(text, text) returns boolean language sql -as $function$ -select $1 < $2 limit 1 -$function$; +as $$ select $1 < $2 limit 1 $$; create function mylt_plpgsql(text, text) returns boolean language plpgsql -as $function$ -begin return $1 < $2; end -$function$; +as $$ begin return $1 < $2; end $$; select a.b as a, @@ -403,28 +367,28 @@ order by a.b, create function mylt2(x text, y text) returns boolean language plpgsql -as $function$ +as $$ declare xx text := x; yy text := y; begin return xx < yy; end -$function$; +$$; select mylt2('a', 'B' collate "en-x-icu") as t, mylt2('a', 'B' collate "C") as f; create or replace function mylt2(x text, y text) returns boolean language plpgsql -as $function$ +as $$ declare xx text COLLATE "POSIX" := x; yy text := y; begin return xx < yy; end -$function$; +$$; select mylt2('a', 'B') as f; @@ -441,9 +405,7 @@ select * from unnest((select array_agg(b order by b) from collate_test3)) order create function dup(anyelement) returns anyelement language sql -as $function$ -select $1 -$function$; +as 'select $1'; select a, dup(b) from collate_test1 order by 2; @@ -451,17 +413,17 @@ select a, dup(b) from collate_test2 order by 2; select a, dup(b) from collate_test3 order by 2; -create index "collate_test1_idx1" on collate_test1 using btree (b); +create index collate_test1_idx1 on collate_test1 using btree (b); -create index "collate_test1_idx2" on collate_test1 using btree (b collate "C"); +create index collate_test1_idx2 on collate_test1 using btree (b collate "C"); -create index "collate_test1_idx3" on collate_test1 using btree ((b collate "C")); +create index collate_test1_idx3 on collate_test1 using btree ((b collate "C")); -create index "collate_test1_idx4" on collate_test1 using btree (((b || 'foo') collate "POSIX")); +create index collate_test1_idx4 on collate_test1 using btree (((b || 'foo') collate "POSIX")); -create index "collate_test1_idx5" on collate_test1 using btree (a collate "C"); +create index collate_test1_idx5 on collate_test1 using btree (a collate "C"); -create index "collate_test1_idx6" on collate_test1 using btree ((a collate "C")); +create index collate_test1_idx6 on collate_test1 using btree ((a collate "C")); select relname, @@ -486,29 +448,27 @@ reset enable_seqscan; create role regress_test_role; -create schema "test_schema"; +create schema test_schema; set client_min_messages = warning; set icu_validation_level = disabled; -do -$do$ +do $$ BEGIN EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' || quote_literal((SELECT CASE WHEN datlocprovider='i' THEN datlocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');'; END -$do$; +$$; create collation test0 from "C"; -do -$do$ +do $$ BEGIN EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' || quote_literal((SELECT CASE WHEN datlocprovider='i' THEN datlocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');'; END -$do$; +$$; reset icu_validation_level; @@ -557,10 +517,7 @@ select nspname, obj_description(pg_collation.oid, 'pg_collation') from - pg_collation - inner join - pg_namespace - on collnamespace = pg_namespace.oid + pg_collation inner join pg_namespace on collnamespace = pg_namespace.oid where collname like 'test%' order by 1; @@ -600,7 +557,7 @@ create table collate_dep_test4t ( b text ); -create index "collate_dep_test4i" on collate_dep_test4t using btree (b collate test0); +create index collate_dep_test4i on collate_dep_test4t using btree (b collate test0); drop collation test0; @@ -610,9 +567,9 @@ drop table collate_dep_test1, collate_dep_test4t; drop type collate_dep_test2; -create type textrange_c as range (subtype = text, collation = "C"); +create type textrange_c as range (subtype = text, "collation" = "C"); -create type textrange_en_us as range (subtype = text, collation = "en-x-icu"); +create type textrange_en_us as range (subtype = text, "collation" = "en-x-icu"); select textrange_c('A', 'Z') @> cast('b' as text); @@ -671,8 +628,7 @@ create collation testcoll_de_phonebook (provider = icu, locale = 'de@collation=p select 'Goldmann' < 'Götz' collate "de-x-icu", - 'Goldmann' > - 'Götz' collate "testcoll_de_phonebook"; + 'Goldmann' > 'Götz' collate "testcoll_de_phonebook"; create collation testcoll_rules1 (provider = icu, locale = '', rules = '&a < g'); @@ -824,11 +780,11 @@ select distinct x from test3cs order by x; reset enable_hashagg; -select COUNT(distinct x) from test3cs; +select count(distinct x) from test3cs; -select x, COUNT(*) from test3cs group by x order by x; +select x, count(*) from test3cs group by x order by x; -select x, ROW_NUMBER() over (order by x), RANK() over (order by x) from test3cs order by x; +select x, row_number() over (order by x), rank() over (order by x) from test3cs order by x; create unique index on test1cs using btree (x); @@ -880,11 +836,11 @@ select x from test2ci except select x from test1ci; select distinct x from test3ci order by x; -select COUNT(distinct x) from test3ci; +select count(distinct x) from test3ci; -select x, COUNT(*) from test3ci group by x order by x; +select x, count(*) from test3ci group by x order by x; -select x, ROW_NUMBER() over (order by x), RANK() over (order by x) from test3ci order by x; +select x, row_number() over (order by x), rank() over (order by x) from test3ci order by x; create unique index on test1ci using btree (x); @@ -936,11 +892,11 @@ select x from test2bpci except select x from test1bpci; select distinct x from test3bpci order by x; -select COUNT(distinct x) from test3bpci; +select count(distinct x) from test3bpci; -select x, COUNT(*) from test3bpci group by x order by x; +select x, count(*) from test3bpci group by x order by x; -select x, ROW_NUMBER() over (order by x), RANK() over (order by x) from test3bpci order by x; +select x, row_number() over (order by x), rank() over (order by x) from test3bpci order by x; create unique index on test1bpci using btree (x); @@ -987,9 +943,7 @@ select from pg_type where - typname like 'int_' and - typname <> - cast('INT2' as text) collate "case_insensitive" + typname like 'int_' and typname <> cast('INT2' as text) collate "case_insensitive" order by typname; select @@ -997,9 +951,7 @@ select from pg_type where - typname like 'int_' and - cast('INT2' as text) <> - typname collate "case_insensitive" + typname like 'int_' and cast('INT2' as text) <> typname collate "case_insensitive" order by typname; create temporary table outer_text ( @@ -1056,7 +1008,7 @@ create table test4nfd ( insert into test4nfd values (1, 'cote'), (2, 'côte'), (3, 'coté'), (4, 'côté'); -update test4nfd set b = NORMALIZE(b, NFD); +update test4nfd set b = normalize(b, nfd); select a, b, replace(b collate "ignore_accents", 'co', 'ma') from test4; @@ -1099,30 +1051,20 @@ select 'foox' like 'foo\' collate "ignore_accents"; create table test10pk (x text collate "case_sensitive" primary key); create table test10fk ( - x text - collate "case_insensitive" - references test10pk (x) - on DELETE cascade - on UPDATE cascade + x text collate "case_insensitive" references test10pk (x) on delete cascade on update cascade ); create table test11pk (x text collate "case_insensitive" primary key); create table test11fk ( - x text - collate "case_sensitive" - references test11pk (x) - on DELETE cascade - on UPDATE cascade + x text collate "case_sensitive" references test11pk (x) on delete cascade on update cascade ); create table test12pk (x text collate "case_insensitive" primary key); create table test12fk ( a int, - b text - collate "case_insensitive" - references test12pk (x) + b text collate "case_insensitive" references test12pk (x) ); insert into test12pk values ('abc'); @@ -1141,9 +1083,7 @@ create table test12pk (x text collate "case_insensitive" primary key); create table test12fk ( a int, - b text - collate "case_insensitive" - references test12pk (x) on UPDATE restrict + b text collate "case_insensitive" references test12pk (x) on update restrict ); insert into test12pk values ('abc'); @@ -1162,9 +1102,7 @@ create table test12pk (x text collate "case_insensitive" primary key); create table test12fk ( a int, - b text - collate "case_insensitive" - references test12pk (x) on UPDATE cascade + b text collate "case_insensitive" references test12pk (x) on update cascade ); insert into test12pk values ('abc'); @@ -1183,7 +1121,7 @@ create table test20 ( a int, b text collate "case_insensitive" ) -partition by LIST(b); +partition by list(b); create table test20_1 partition of test20 for values in ('abc'); @@ -1211,71 +1149,71 @@ create table test22 ( a int, b text collate "case_sensitive" ) -partition by HASH(b); +partition by hash(b); -create table test22_0 partition of test22 for values with (MODULUS 2, REMAINDER 0); +create table test22_0 partition of test22 for values with (modulus 2, remainder 0); -create table test22_1 partition of test22 for values with (MODULUS 2, REMAINDER 1); +create table test22_1 partition of test22 for values with (modulus 2, remainder 1); insert into test22 values (1, 'def'); insert into test22 values (2, 'DEF'); -select (select COUNT(*) from test22_0) = (select COUNT(*) from test22_1); +select (select count(*) from test22_0) = (select count(*) from test22_1); create table test22a ( a int, b text[] collate "case_sensitive" ) -partition by HASH(b); +partition by hash(b); -create table test22a_0 partition of test22a for values with (MODULUS 2, REMAINDER 0); +create table test22a_0 partition of test22a for values with (modulus 2, remainder 0); -create table test22a_1 partition of test22a for values with (MODULUS 2, REMAINDER 1); +create table test22a_1 partition of test22a for values with (modulus 2, remainder 1); insert into test22a values (1, array['def']); insert into test22a values (2, array['DEF']); -select (select COUNT(*) from test22a_0) = (select COUNT(*) from test22a_1); +select (select count(*) from test22a_0) = (select count(*) from test22a_1); create table test23 ( a int, b text collate "case_insensitive" ) -partition by HASH(b); +partition by hash(b); -create table test23_0 partition of test23 for values with (MODULUS 2, REMAINDER 0); +create table test23_0 partition of test23 for values with (modulus 2, remainder 0); -create table test23_1 partition of test23 for values with (MODULUS 2, REMAINDER 1); +create table test23_1 partition of test23 for values with (modulus 2, remainder 1); insert into test23 values (1, 'def'); insert into test23 values (2, 'DEF'); -select (select COUNT(*) from test23_0) <> (select COUNT(*) from test23_1); +select (select count(*) from test23_0) <> (select count(*) from test23_1); create table test23a ( a int, b text[] collate "case_insensitive" ) -partition by HASH(b); +partition by hash(b); -create table test23a_0 partition of test23a for values with (MODULUS 2, REMAINDER 0); +create table test23a_0 partition of test23a for values with (modulus 2, remainder 0); -create table test23a_1 partition of test23a for values with (MODULUS 2, REMAINDER 1); +create table test23a_1 partition of test23a for values with (modulus 2, remainder 1); insert into test23a values (1, array['def']); insert into test23a values (2, array['DEF']); -select (select COUNT(*) from test23a_0) <> (select COUNT(*) from test23a_1); +select (select count(*) from test23a_0) <> (select count(*) from test23a_1); create table test30 ( a int, b char(3) collate "case_insensitive" ) -partition by LIST(b); +partition by list(b); create table test30_1 partition of test30 for values in ('abc'); @@ -1303,33 +1241,33 @@ create table test32 ( a int, b char(3) collate "case_sensitive" ) -partition by HASH(b); +partition by hash(b); -create table test32_0 partition of test32 for values with (MODULUS 2, REMAINDER 0); +create table test32_0 partition of test32 for values with (modulus 2, remainder 0); -create table test32_1 partition of test32 for values with (MODULUS 2, REMAINDER 1); +create table test32_1 partition of test32 for values with (modulus 2, remainder 1); insert into test32 values (1, 'def'); insert into test32 values (2, 'DEF'); -select (select COUNT(*) from test32_0) = (select COUNT(*) from test32_1); +select (select count(*) from test32_0) = (select count(*) from test32_1); create table test33 ( a int, b char(3) collate "case_insensitive" ) -partition by HASH(b); +partition by hash(b); -create table test33_0 partition of test33 for values with (MODULUS 2, REMAINDER 0); +create table test33_0 partition of test33 for values with (modulus 2, remainder 0); -create table test33_1 partition of test33 for values with (MODULUS 2, REMAINDER 1); +create table test33_1 partition of test33 for values with (modulus 2, remainder 1); insert into test33 values (1, 'def'); insert into test33 values (2, 'DEF'); -select (select COUNT(*) from test33_0) <> (select COUNT(*) from test33_1); +select (select count(*) from test33_0) <> (select count(*) from test33_1); set max_parallel_workers_per_gather = 0; @@ -1339,18 +1277,14 @@ create table pagg_tab3 ( a text, c text collate "case_insensitive" ) -partition by LIST(c collate "C"); +partition by list(c collate "C"); create table pagg_tab3_p1 partition of pagg_tab3 for values in ('a', 'b'); create table pagg_tab3_p2 partition of pagg_tab3 for values in ('B', 'A'); insert into pagg_tab3 -select - i % 4 + 1, - substr('abAB', i % 4 + 1, 1) -from - generate_series(0, 19) as i; +select i % 4 + 1, substr('abAB', i % 4 + 1, 1) from generate_series(0, 19) as i; analyze pagg_tab3; @@ -1358,7 +1292,7 @@ set enable_partitionwise_aggregate = 'false'; select upper(c collate "case_insensitive"), - COUNT(c) + count(c) from pagg_tab3 group by c collate "case_insensitive" @@ -1366,7 +1300,7 @@ order by 1; select upper(c collate "case_insensitive"), - COUNT(c) + count(c) from pagg_tab3 group by c collate "case_insensitive" @@ -1376,7 +1310,7 @@ set enable_partitionwise_aggregate = 'true'; select upper(c collate "case_insensitive"), - COUNT(c) + count(c) from pagg_tab3 group by c collate "case_insensitive" @@ -1384,37 +1318,31 @@ order by 1; select upper(c collate "case_insensitive"), - COUNT(c) + count(c) from pagg_tab3 group by c collate "case_insensitive" order by 1; -select c collate "C", COUNT(c) from pagg_tab3 group by c collate "C" order by 1; +select c collate "C", count(c) from pagg_tab3 group by c collate "C" order by 1; -select c collate "C", COUNT(c) from pagg_tab3 group by c collate "C" order by 1; +select c collate "C", count(c) from pagg_tab3 group by c collate "C" order by 1; set enable_partitionwise_join = 'false'; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c group by 1 order by t1.c collate "C"; @@ -1422,45 +1350,33 @@ set enable_partitionwise_join = 'true'; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c group by 1 order by t1.c collate "C"; select t1.c collate "C", - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c collate "C" + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c collate "C" group by t1.c collate "C" order by t1.c collate "C"; select t1.c collate "C", - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c collate "C" + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c collate "C" group by t1.c collate "C" order by t1.c collate "C"; @@ -1468,23 +1384,17 @@ set enable_partitionwise_join = 'false'; select t1.c collate "C", - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c collate "C" + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c collate "C" group by t1.c collate "C" order by t1.c collate "C"; select t1.c collate "C", - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c collate "C" + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c collate "C" group by t1.c collate "C" order by t1.c collate "C"; @@ -1494,40 +1404,30 @@ create table pagg_tab4 ( c text collate "case_insensitive", b text collate "case_insensitive" ) -partition by LIST(b collate "C"); +partition by list(b collate "C"); create table pagg_tab4_p1 partition of pagg_tab4 for values in ('a', 'b'); create table pagg_tab4_p2 partition of pagg_tab4 for values in ('B', 'A'); insert into pagg_tab4 (b, c) -select - substr('abAB', i % 4 + 1, 1), - substr('abAB', i % 2 + 1, 1) -from - generate_series(0, 11) as i; +select substr('abAB', i % 4 + 1, 1), substr('abAB', i % 2 + 1, 1) from generate_series(0, 11) as i; analyze pagg_tab4; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab4 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab3 as t1 inner join pagg_tab4 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab4 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab3 as t1 inner join pagg_tab4 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; @@ -1535,25 +1435,17 @@ create table pagg_tab5 ( c text collate "case_insensitive", b text collate "case_insensitive" ) -partition by LIST(c collate case_insensitive); +partition by list(c collate case_insensitive); create table pagg_tab5_p1 partition of pagg_tab5 for values in ('a', 'b'); create table pagg_tab5_p2 partition of pagg_tab5 for values in ('c', 'd'); insert into pagg_tab5 (b, c) -select - substr('abAB', i % 4 + 1, 1), - substr('abAB', i % 2 + 1, 1) -from - generate_series(0, 5) as i; +select substr('abAB', i % 4 + 1, 1), substr('abAB', i % 2 + 1, 1) from generate_series(0, 5) as i; insert into pagg_tab5 (b, c) -select - substr('cdCD', i % 4 + 1, 1), - substr('cdCD', i % 2 + 1, 1) -from - generate_series(0, 5) as i; +select substr('cdCD', i % 4 + 1, 1), substr('cdCD', i % 2 + 1, 1) from generate_series(0, 5) as i; analyze pagg_tab5; @@ -1561,47 +1453,33 @@ create table pagg_tab6 ( c text collate "case_insensitive", b text collate "case_insensitive" ) -partition by LIST(b collate case_insensitive); +partition by list(b collate case_insensitive); create table pagg_tab6_p1 partition of pagg_tab6 for values in ('a', 'b'); create table pagg_tab6_p2 partition of pagg_tab6 for values in ('c', 'd'); insert into pagg_tab6 (b, c) -select - substr('abAB', i % 4 + 1, 1), - substr('abAB', i % 2 + 1, 1) -from - generate_series(0, 5) as i; +select substr('abAB', i % 4 + 1, 1), substr('abAB', i % 2 + 1, 1) from generate_series(0, 5) as i; insert into pagg_tab6 (b, c) -select - substr('cdCD', i % 4 + 1, 1), - substr('cdCD', i % 2 + 1, 1) -from - generate_series(0, 5) as i; +select substr('cdCD', i % 4 + 1, 1), substr('cdCD', i % 2 + 1, 1) from generate_series(0, 5) as i; analyze pagg_tab6; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab5 as t1 - inner join - pagg_tab6 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab5 as t1 inner join pagg_tab6 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab5 as t1 - inner join - pagg_tab6 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab5 as t1 inner join pagg_tab6 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; @@ -1609,23 +1487,17 @@ set enable_partitionwise_join = 'false'; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab5 as t1 - inner join - pagg_tab6 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab5 as t1 inner join pagg_tab6 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab5 as t1 - inner join - pagg_tab6 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab5 as t1 inner join pagg_tab6 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_80.snap index b59682ab0..8b25ac11d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_80.snap @@ -6,19 +6,18 @@ select getdatabaseencoding() <> 'UTF8' or ( select - COUNT(*) + count(*) from pg_collation where - collprovider = 'i' and - collname <> 'unicode' + collprovider = 'i' and collname <> 'unicode' ) = 0 as skip_test; set client_encoding to utf8; -create schema "collate_tests"; +create schema collate_tests; set search_path to collate_tests; @@ -55,11 +54,7 @@ create table collate_test3 ( ); insert into collate_test1 -values - (1, 'abc'), - (2, 'äbc'), - (3, 'bbc'), - (4, 'ABC'); +values (1, 'abc'), (2, 'äbc'), (3, 'bbc'), (4, 'ABC'); insert into collate_test2 select * from collate_test1; @@ -241,27 +236,13 @@ select 'bıt' ~* 'BIT' collate "tr-x-icu" as "false"; select relname from pg_class where relname ~* '^abc'; create view collview1 -as select - * -from - collate_test1 -where - b collate "C" >= 'bbc'; +as select * from collate_test1 where b collate "C" >= 'bbc'; create view collview2 -as select - a, - b -from - collate_test1 -order by b collate "C"; +as select a, b from collate_test1 order by b collate "C"; create view collview3 -as select - a, - lower((x || x) collate "C") -from - collate_test10; +as select a, lower((x || x) collate "C") from collate_test10; select table_name, @@ -346,11 +327,11 @@ select from collate_test10; -select MIN(b), MAX(b) from collate_test1; +select min(b), max(b) from collate_test1; -select MIN(b), MAX(b) from collate_test2; +select min(b), max(b) from collate_test2; -select MIN(b), MAX(b) from collate_test3; +select min(b), max(b) from collate_test3; select array_agg(b order by b) from collate_test1; @@ -369,13 +350,7 @@ select a, b from collate_test3 where a > 1 order by 2; select a, b from collate_test3 except -select - a, - b -from - collate_test3 -where - a < 2 +select a, b from collate_test3 where a < 2 order by 2; select a, b from collate_test1 @@ -387,11 +362,7 @@ select a, b from collate_test1 union all select a, b from collate_test3; select a, b from collate_test1 union select a, b from collate_test3 order by 2; -select - a, - b collate "C" -from - collate_test1 +select a, b collate "C" from collate_test1 union select a, b from collate_test3 order by 2; @@ -402,9 +373,7 @@ select a, b from collate_test1 except select a, b from collate_test3 order by 2; create table test_u as - select a, b from collate_test1 - union all - select a, b from collate_test3; + select a, b from collate_test1 union all select a, b from collate_test3; select x < y from collate_test10; @@ -415,20 +384,9 @@ select x, y from collate_test10 order by x || y; with recursive foo (x) as ( - select - x - from - ( - values ('a' collate "en-x-icu"), ('b') - ) - as t (x) + select x from (values ('a' collate "en-x-icu"), ('b')) as t (x) union all - select - (x || 'c') collate "de-x-icu" - from - foo - where - length(x) < 10 + select (x || 'c') collate "de-x-icu" from foo where length(x) < 10 ) select * @@ -444,23 +402,17 @@ select a, cast(b as varchar) from collate_test3 order by 2; create function mylt(text, text) returns boolean language sql -as $function$ -select $1 < $2 -$function$; +as $$ select $1 < $2 $$; create function mylt_noninline(text, text) returns boolean language sql -as $function$ -select $1 < $2 limit 1 -$function$; +as $$ select $1 < $2 limit 1 $$; create function mylt_plpgsql(text, text) returns boolean language plpgsql -as $function$ -begin return $1 < $2; end -$function$; +as $$ begin return $1 < $2; end $$; select a.b as a, @@ -491,14 +443,14 @@ order by a.b, create function mylt2(x text, y text) returns boolean language plpgsql -as $function$ +as $$ declare xx text := x; yy text := y; begin return xx < yy; end -$function$; +$$; select mylt2('a', 'B' collate "en-x-icu") as t, @@ -507,14 +459,14 @@ select create or replace function mylt2(x text, y text) returns boolean language plpgsql -as $function$ +as $$ declare xx text COLLATE "POSIX" := x; yy text := y; begin return xx < yy; end -$function$; +$$; select mylt2('a', 'B') as f; @@ -525,48 +477,25 @@ select mylt2('a', 'B' collate "POSIX") as f; select * from - unnest( - ( - select - array_agg(b order by b) - from - collate_test1 - ) - ) + unnest((select array_agg(b order by b) from collate_test1)) order by 1; select * from - unnest( - ( - select - array_agg(b order by b) - from - collate_test2 - ) - ) + unnest((select array_agg(b order by b) from collate_test2)) order by 1; select * from - unnest( - ( - select - array_agg(b order by b) - from - collate_test3 - ) - ) + unnest((select array_agg(b order by b) from collate_test3)) order by 1; create function dup(anyelement) returns anyelement language sql -as $function$ -select $1 -$function$; +as 'select $1'; select a, dup(b) from collate_test1 order by 2; @@ -574,32 +503,19 @@ select a, dup(b) from collate_test2 order by 2; select a, dup(b) from collate_test3 order by 2; -create index "collate_test1_idx1" on collate_test1 using btree (b); +create index collate_test1_idx1 on collate_test1 using btree (b); -create index "collate_test1_idx2" on collate_test1 using btree (b collate "C"); +create index collate_test1_idx2 on collate_test1 using btree (b collate "C"); -create index "collate_test1_idx3" -on collate_test1 -using btree -( - (b collate "C") -); +create index collate_test1_idx3 on collate_test1 using btree ((b collate "C")); -create index "collate_test1_idx4" -on collate_test1 -using btree -( +create index collate_test1_idx4 on collate_test1 using btree ( ((b || 'foo') collate "POSIX") ); -create index "collate_test1_idx5" on collate_test1 using btree (a collate "C"); +create index collate_test1_idx5 on collate_test1 using btree (a collate "C"); -create index "collate_test1_idx6" -on collate_test1 -using btree -( - (a collate "C") -); +create index collate_test1_idx6 on collate_test1 using btree ((a collate "C")); select relname, @@ -624,29 +540,27 @@ reset enable_seqscan; create role regress_test_role; -create schema "test_schema"; +create schema test_schema; set client_min_messages = warning; set icu_validation_level = disabled; -do -$do$ +do $$ BEGIN EXECUTE 'CREATE COLLATION test0 (provider = icu, locale = ' || quote_literal((SELECT CASE WHEN datlocprovider='i' THEN datlocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');'; END -$do$; +$$; create collation test0 from "C"; -do -$do$ +do $$ BEGIN EXECUTE 'CREATE COLLATION test1 (provider = icu, locale = ' || quote_literal((SELECT CASE WHEN datlocprovider='i' THEN datlocale ELSE datcollate END FROM pg_database WHERE datname = current_database())) || ');'; END -$do$; +$$; reset icu_validation_level; @@ -699,15 +613,9 @@ comment on collation test0 is 'US English'; select collname, nspname, - obj_description( - pg_collation.oid, - 'pg_collation' - ) + obj_description(pg_collation.oid, 'pg_collation') from - pg_collation - inner join - pg_namespace - on collnamespace = pg_namespace.oid + pg_collation inner join pg_namespace on collnamespace = pg_namespace.oid where collname like 'test%' order by 1; @@ -740,19 +648,14 @@ create domain collate_dep_dom1 as text collate "test0"; create type collate_dep_test2 as (x int, y text collate "test0"); create view collate_dep_test3 -as select - cast('foo' as text) collate "test0" - as foo; +as select cast('foo' as text) collate "test0" as foo; create table collate_dep_test4t ( a int, b text ); -create index "collate_dep_test4i" -on collate_dep_test4t -using btree -( +create index collate_dep_test4i on collate_dep_test4t using btree ( b collate test0 ); @@ -764,9 +667,9 @@ drop table collate_dep_test1, collate_dep_test4t; drop type collate_dep_test2; -create type textrange_c as range (subtype = text, collation = "C"); +create type textrange_c as range (subtype = text, "collation" = "C"); -create type textrange_en_us as range (subtype = text, collation = "en-x-icu"); +create type textrange_en_us as range (subtype = text, "collation" = "en-x-icu"); select textrange_c('A', 'Z') @> cast('b' as text); @@ -791,8 +694,7 @@ reset client_min_messages; select 'aaá' > 'AAA' collate "und-x-icu", - 'aaá' < - 'AAA' collate "testcoll_ignore_accents"; + 'aaá' < 'AAA' collate "testcoll_ignore_accents"; set client_min_messages = warning; @@ -804,10 +706,8 @@ create collation testcoll_backwards ( reset client_min_messages; select - 'coté' < - 'côte' collate "und-x-icu", - 'coté' > - 'côte' collate "testcoll_backwards"; + 'coté' < 'côte' collate "und-x-icu", + 'coté' > 'côte' collate "testcoll_backwards"; create collation testcoll_lower_first ( provider = icu, @@ -820,10 +720,8 @@ create collation testcoll_upper_first ( ); select - 'aaa' < - 'AAA' collate "testcoll_lower_first", - 'aaa' > - 'AAA' collate "testcoll_upper_first"; + 'aaa' < 'AAA' collate "testcoll_lower_first", + 'aaa' > 'AAA' collate "testcoll_upper_first"; create collation testcoll_shifted ( provider = icu, @@ -832,8 +730,7 @@ create collation testcoll_shifted ( select 'de-luge' < 'deanza' collate "und-x-icu", - 'de-luge' > - 'deanza' collate "testcoll_shifted"; + 'de-luge' > 'deanza' collate "testcoll_shifted"; set client_min_messages = warning; @@ -843,8 +740,7 @@ reset client_min_messages; select 'A-21' > 'A-123' collate "und-x-icu", - 'A-21' < - 'A-123' collate "testcoll_numeric"; + 'A-21' < 'A-123' collate "testcoll_numeric"; create collation testcoll_error1 (provider = icu, locale = '@colNumeric=lower'); @@ -854,10 +750,8 @@ create collation testcoll_de_phonebook ( ); select - 'Goldmann' < - 'Götz' collate "de-x-icu", - 'Goldmann' > - 'Götz' collate "testcoll_de_phonebook"; + 'Goldmann' < 'Götz' collate "de-x-icu", + 'Goldmann' > 'Götz' collate "testcoll_de_phonebook"; create collation testcoll_rules1 ( provider = icu, @@ -868,13 +762,7 @@ create collation testcoll_rules1 ( create table test7 (a text); insert into test7 -values - ('Abernathy'), - ('apple'), - ('bird'), - ('Boston'), - ('Graham'), - ('green'); +values ('Abernathy'), ('apple'), ('bird'), ('Boston'), ('Graham'), ('green'); select * from test7 order by a collate "en-x-icu"; @@ -975,10 +863,8 @@ select 'abc' >= 'ABC' collate "case_sensitive"; select - 'abc' <= - 'ABC' collate "case_insensitive", - 'abc' >= - 'ABC' collate "case_insensitive"; + 'abc' <= 'ABC' collate "case_insensitive", + 'abc' >= 'ABC' collate "case_insensitive"; select array_sort(cast('{a,B}' as text[]) collate "case_insensitive"); @@ -1038,14 +924,14 @@ select distinct x from test3cs order by x; reset enable_hashagg; -select COUNT(distinct x) from test3cs; +select count(distinct x) from test3cs; -select x, COUNT(*) from test3cs group by x order by x; +select x, count(*) from test3cs group by x order by x; select x, - ROW_NUMBER() over (order by x), - RANK() over (order by x) + row_number() over (order by x), + rank() over (order by x) from test3cs order by x; @@ -1100,14 +986,14 @@ select x from test2ci except select x from test1ci; select distinct x from test3ci order by x; -select COUNT(distinct x) from test3ci; +select count(distinct x) from test3ci; -select x, COUNT(*) from test3ci group by x order by x; +select x, count(*) from test3ci group by x order by x; select x, - ROW_NUMBER() over (order by x), - RANK() over (order by x) + row_number() over (order by x), + rank() over (order by x) from test3ci order by x; @@ -1162,14 +1048,14 @@ select x from test2bpci except select x from test1bpci; select distinct x from test3bpci order by x; -select COUNT(distinct x) from test3bpci; +select count(distinct x) from test3bpci; -select x, COUNT(*) from test3bpci group by x order by x; +select x, count(*) from test3bpci group by x order by x; select x, - ROW_NUMBER() over (order by x), - RANK() over (order by x) + row_number() over (order by x), + rank() over (order by x) from test3bpci order by x; @@ -1225,16 +1111,14 @@ select from pg_class where - relname = - cast('PG_CLASS' as text) collate "case_insensitive"; + relname = cast('PG_CLASS' as text) collate "case_insensitive"; select relname from pg_class where - cast('PG_CLASS' as text) = - relname collate "case_insensitive"; + cast('PG_CLASS' as text) = relname collate "case_insensitive"; select typname @@ -1242,8 +1126,7 @@ from pg_type where typname like 'int_' and - typname <> - cast('INT2' as text) collate "case_insensitive" + typname <> cast('INT2' as text) collate "case_insensitive" order by typname; select @@ -1252,8 +1135,7 @@ from pg_type where typname like 'int_' and - cast('INT2' as text) <> - typname collate "case_insensitive" + cast('INT2' as text) <> typname collate "case_insensitive" order by typname; create temporary table outer_text ( @@ -1294,11 +1176,7 @@ create table test4 ( ); insert into test4 -values - (1, 'cote'), - (2, 'côte'), - (3, 'coté'), - (4, 'côté'); +values (1, 'cote'), (2, 'côte'), (3, 'coté'), (4, 'côté'); select * from test4 where b = 'cote'; @@ -1314,13 +1192,9 @@ create table test4nfd ( ); insert into test4nfd -values - (1, 'cote'), - (2, 'côte'), - (3, 'coté'), - (4, 'côté'); +values (1, 'cote'), (2, 'côte'), (3, 'coté'), (4, 'côté'); -update test4nfd set b = NORMALIZE(b, NFD); +update test4nfd set b = normalize(b, nfd); select a, b, replace(b collate "ignore_accents", 'co', 'ma') from test4; @@ -1364,29 +1238,23 @@ create table test10pk (x text collate "case_sensitive" primary key); create table test10fk ( x text - collate "case_insensitive" - references test10pk (x) - on DELETE cascade - on UPDATE cascade + collate "case_insensitive" + references test10pk (x) on delete cascade on update cascade ); create table test11pk (x text collate "case_insensitive" primary key); create table test11fk ( x text - collate "case_sensitive" - references test11pk (x) - on DELETE cascade - on UPDATE cascade + collate "case_sensitive" + references test11pk (x) on delete cascade on update cascade ); create table test12pk (x text collate "case_insensitive" primary key); create table test12fk ( a int, - b text - collate "case_insensitive" - references test12pk (x) + b text collate "case_insensitive" references test12pk (x) ); insert into test12pk values ('abc'); @@ -1405,10 +1273,7 @@ create table test12pk (x text collate "case_insensitive" primary key); create table test12fk ( a int, - b text - collate "case_insensitive" - references test12pk (x) - on UPDATE restrict + b text collate "case_insensitive" references test12pk (x) on update restrict ); insert into test12pk values ('abc'); @@ -1427,10 +1292,7 @@ create table test12pk (x text collate "case_insensitive" primary key); create table test12fk ( a int, - b text - collate "case_insensitive" - references test12pk (x) - on UPDATE cascade + b text collate "case_insensitive" references test12pk (x) on update cascade ); insert into test12pk values ('abc'); @@ -1449,7 +1311,7 @@ create table test20 ( a int, b text collate "case_insensitive" ) -partition by LIST(b); +partition by list(b); create table test20_1 partition of test20 for values in ('abc'); @@ -1477,87 +1339,87 @@ create table test22 ( a int, b text collate "case_sensitive" ) -partition by HASH(b); +partition by hash(b); create table test22_0 partition of test22 -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table test22_1 partition of test22 -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); insert into test22 values (1, 'def'); insert into test22 values (2, 'DEF'); -select (select COUNT(*) from test22_0) = (select COUNT(*) from test22_1); +select (select count(*) from test22_0) = (select count(*) from test22_1); create table test22a ( a int, b text[] collate "case_sensitive" ) -partition by HASH(b); +partition by hash(b); create table test22a_0 partition of test22a -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table test22a_1 partition of test22a -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); insert into test22a values (1, array['def']); insert into test22a values (2, array['DEF']); -select (select COUNT(*) from test22a_0) = (select COUNT(*) from test22a_1); +select (select count(*) from test22a_0) = (select count(*) from test22a_1); create table test23 ( a int, b text collate "case_insensitive" ) -partition by HASH(b); +partition by hash(b); create table test23_0 partition of test23 -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table test23_1 partition of test23 -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); insert into test23 values (1, 'def'); insert into test23 values (2, 'DEF'); -select (select COUNT(*) from test23_0) <> (select COUNT(*) from test23_1); +select (select count(*) from test23_0) <> (select count(*) from test23_1); create table test23a ( a int, b text[] collate "case_insensitive" ) -partition by HASH(b); +partition by hash(b); create table test23a_0 partition of test23a -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table test23a_1 partition of test23a -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); insert into test23a values (1, array['def']); insert into test23a values (2, array['DEF']); -select (select COUNT(*) from test23a_0) <> (select COUNT(*) from test23a_1); +select (select count(*) from test23a_0) <> (select count(*) from test23a_1); create table test30 ( a int, b char(3) collate "case_insensitive" ) -partition by LIST(b); +partition by list(b); create table test30_1 partition of test30 for values in ('abc'); @@ -1585,41 +1447,41 @@ create table test32 ( a int, b char(3) collate "case_sensitive" ) -partition by HASH(b); +partition by hash(b); create table test32_0 partition of test32 -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table test32_1 partition of test32 -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); insert into test32 values (1, 'def'); insert into test32 values (2, 'DEF'); -select (select COUNT(*) from test32_0) = (select COUNT(*) from test32_1); +select (select count(*) from test32_0) = (select count(*) from test32_1); create table test33 ( a int, b char(3) collate "case_insensitive" ) -partition by HASH(b); +partition by hash(b); create table test33_0 partition of test33 -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table test33_1 partition of test33 -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); insert into test33 values (1, 'def'); insert into test33 values (2, 'DEF'); -select (select COUNT(*) from test33_0) <> (select COUNT(*) from test33_1); +select (select count(*) from test33_0) <> (select count(*) from test33_1); set max_parallel_workers_per_gather = 0; @@ -1629,18 +1491,14 @@ create table pagg_tab3 ( a text, c text collate "case_insensitive" ) -partition by LIST(c collate "C"); +partition by list(c collate "C"); create table pagg_tab3_p1 partition of pagg_tab3 for values in ('a', 'b'); create table pagg_tab3_p2 partition of pagg_tab3 for values in ('B', 'A'); insert into pagg_tab3 -select - i % 4 + 1, - substr('abAB', i % 4 + 1, 1) -from - generate_series(0, 19) as i; +select i % 4 + 1, substr('abAB', i % 4 + 1, 1) from generate_series(0, 19) as i; analyze pagg_tab3; @@ -1648,7 +1506,7 @@ set enable_partitionwise_aggregate = 'false'; select upper(c collate "case_insensitive"), - COUNT(c) + count(c) from pagg_tab3 group by c collate "case_insensitive" @@ -1656,7 +1514,7 @@ order by 1; select upper(c collate "case_insensitive"), - COUNT(c) + count(c) from pagg_tab3 group by c collate "case_insensitive" @@ -1666,7 +1524,7 @@ set enable_partitionwise_aggregate = 'true'; select upper(c collate "case_insensitive"), - COUNT(c) + count(c) from pagg_tab3 group by c collate "case_insensitive" @@ -1674,37 +1532,31 @@ order by 1; select upper(c collate "case_insensitive"), - COUNT(c) + count(c) from pagg_tab3 group by c collate "case_insensitive" order by 1; -select c collate "C", COUNT(c) from pagg_tab3 group by c collate "C" order by 1; +select c collate "C", count(c) from pagg_tab3 group by c collate "C" order by 1; -select c collate "C", COUNT(c) from pagg_tab3 group by c collate "C" order by 1; +select c collate "C", count(c) from pagg_tab3 group by c collate "C" order by 1; set enable_partitionwise_join = 'false'; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c group by 1 order by t1.c collate "C"; @@ -1712,45 +1564,33 @@ set enable_partitionwise_join = 'true'; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c group by 1 order by t1.c collate "C"; select t1.c collate "C", - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c collate "C" + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c collate "C" group by t1.c collate "C" order by t1.c collate "C"; select t1.c collate "C", - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c collate "C" + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c collate "C" group by t1.c collate "C" order by t1.c collate "C"; @@ -1758,23 +1598,17 @@ set enable_partitionwise_join = 'false'; select t1.c collate "C", - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c collate "C" + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c collate "C" group by t1.c collate "C" order by t1.c collate "C"; select t1.c collate "C", - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab3 as t2 - on t1.c = t2.c collate "C" + pagg_tab3 as t1 inner join pagg_tab3 as t2 on t1.c = t2.c collate "C" group by t1.c collate "C" order by t1.c collate "C"; @@ -1784,7 +1618,7 @@ create table pagg_tab4 ( c text collate "case_insensitive", b text collate "case_insensitive" ) -partition by LIST(b collate "C"); +partition by list(b collate "C"); create table pagg_tab4_p1 partition of pagg_tab4 for values in ('a', 'b'); @@ -1801,23 +1635,17 @@ analyze pagg_tab4; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab4 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab3 as t1 inner join pagg_tab4 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab3 as t1 - inner join - pagg_tab4 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab3 as t1 inner join pagg_tab4 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; @@ -1825,7 +1653,7 @@ create table pagg_tab5 ( c text collate "case_insensitive", b text collate "case_insensitive" ) -partition by LIST(c collate case_insensitive); +partition by list(c collate case_insensitive); create table pagg_tab5_p1 partition of pagg_tab5 for values in ('a', 'b'); @@ -1851,7 +1679,7 @@ create table pagg_tab6 ( c text collate "case_insensitive", b text collate "case_insensitive" ) -partition by LIST(b collate case_insensitive); +partition by list(b collate case_insensitive); create table pagg_tab6_p1 partition of pagg_tab6 for values in ('a', 'b'); @@ -1875,23 +1703,17 @@ analyze pagg_tab6; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab5 as t1 - inner join - pagg_tab6 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab5 as t1 inner join pagg_tab6 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab5 as t1 - inner join - pagg_tab6 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab5 as t1 inner join pagg_tab6 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; @@ -1899,23 +1721,17 @@ set enable_partitionwise_join = 'false'; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab5 as t1 - inner join - pagg_tab6 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab5 as t1 inner join pagg_tab6 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; select t1.c, - COUNT(t2.c) + count(t2.c) from - pagg_tab5 as t1 - inner join - pagg_tab6 as t2 - on t1.c = t2.c and t1.c = t2.b + pagg_tab5 as t1 inner join pagg_tab6 as t2 on t1.c = t2.c and t1.c = t2.b group by 1 order by t1.c collate "C"; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_100.snap index b431bc272..97a942184 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_100.snap @@ -6,7 +6,7 @@ select getdatabaseencoding() <> 'UTF8' or ( select - COUNT(*) + count(*) from pg_collation where @@ -19,7 +19,7 @@ select set client_encoding to utf8; -create schema "collate_tests"; +create schema collate_tests; set search_path to collate_tests; @@ -207,7 +207,7 @@ select 'bıt' ~* 'BIT' collate "tr_TR" as "true"; select relname from pg_class where relname ~* '^abc'; -set lc_time = tr_TR; +set lc_time = 'tr_TR'; select to_char(cast('2010-02-01' as date), 'DD TMMON YYYY'); @@ -224,27 +224,13 @@ select to_date('01 Şub 2010', 'DD TMMON YYYY'); select to_date('1234567890ab 2010', 'TMMONTH YYYY'); create view collview1 -as select - * -from - collate_test1 -where - b collate "C" >= 'bbc'; +as select * from collate_test1 where b collate "C" >= 'bbc'; create view collview2 -as select - a, - b -from - collate_test1 -order by b collate "C"; +as select a, b from collate_test1 order by b collate "C"; create view collview3 -as select - a, - lower((x || x) collate "C") -from - collate_test10; +as select a, lower((x || x) collate "C") from collate_test10; select table_name, @@ -297,11 +283,11 @@ select a, cast(b as testdomain_sv) from collate_test3 order by 2; select a, lower(cast(x as testdomain)), lower(cast(y as testdomain)) from collate_test10; -select MIN(b), MAX(b) from collate_test1; +select min(b), max(b) from collate_test1; -select MIN(b), MAX(b) from collate_test2; +select min(b), max(b) from collate_test2; -select MIN(b), MAX(b) from collate_test3; +select min(b), max(b) from collate_test3; select array_agg(b order by b) from collate_test1; @@ -340,17 +326,9 @@ select x, y from collate_test10 order by x || y; with recursive foo (x) as ( - select - x - from - (values ('a' collate "en_US"), ('b')) as t (x) + select x from (values ('a' collate "en_US"), ('b')) as t (x) union all - select - (x || 'c') collate "de_DE" - from - foo - where - length(x) < 10 + select (x || 'c') collate "de_DE" from foo where length(x) < 10 ) select * @@ -366,23 +344,17 @@ select a, cast(b as varchar) from collate_test3 order by 2; create function mylt(text, text) returns boolean language sql -as $function$ -select $1 < $2 -$function$; +as $$ select $1 < $2 $$; create function mylt_noninline(text, text) returns boolean language sql -as $function$ -select $1 < $2 limit 1 -$function$; +as $$ select $1 < $2 limit 1 $$; create function mylt_plpgsql(text, text) returns boolean language plpgsql -as $function$ -begin return $1 < $2; end -$function$; +as $$ begin return $1 < $2; end $$; select a.b as a, @@ -413,28 +385,28 @@ order by a.b, create function mylt2(x text, y text) returns boolean language plpgsql -as $function$ +as $$ declare xx text := x; yy text := y; begin return xx < yy; end -$function$; +$$; select mylt2('a', 'B' collate "en_US") as t, mylt2('a', 'B' collate "C") as f; create or replace function mylt2(x text, y text) returns boolean language plpgsql -as $function$ +as $$ declare xx text COLLATE "POSIX" := x; yy text := y; begin return xx < yy; end -$function$; +$$; select mylt2('a', 'B') as f; @@ -451,9 +423,7 @@ select * from unnest((select array_agg(b order by b) from collate_test3)) order create function dup(anyelement) returns anyelement language sql -as $function$ -select $1 -$function$; +as 'select $1'; select a, dup(b) from collate_test1 order by 2; @@ -461,17 +431,17 @@ select a, dup(b) from collate_test2 order by 2; select a, dup(b) from collate_test3 order by 2; -create index "collate_test1_idx1" on collate_test1 using btree (b); +create index collate_test1_idx1 on collate_test1 using btree (b); -create index "collate_test1_idx2" on collate_test1 using btree (b collate "C"); +create index collate_test1_idx2 on collate_test1 using btree (b collate "C"); -create index "collate_test1_idx3" on collate_test1 using btree ((b collate "C")); +create index collate_test1_idx3 on collate_test1 using btree ((b collate "C")); -create index "collate_test1_idx4" on collate_test1 using btree (((b || 'foo') collate "POSIX")); +create index collate_test1_idx4 on collate_test1 using btree (((b || 'foo') collate "POSIX")); -create index "collate_test1_idx5" on collate_test1 using btree (a collate "C"); +create index collate_test1_idx5 on collate_test1 using btree (a collate "C"); -create index "collate_test1_idx6" on collate_test1 using btree ((a collate "C")); +create index collate_test1_idx6 on collate_test1 using btree ((a collate "C")); select relname, @@ -484,15 +454,14 @@ order by 1; create role regress_test_role; -create schema "test_schema"; +create schema test_schema; -do -$do$ +do $$ BEGIN EXECUTE 'CREATE COLLATION test0 (locale = ' || quote_literal((SELECT datcollate FROM pg_database WHERE datname = current_database())) || ');'; END -$do$; +$$; create collation test0 from "C"; @@ -500,15 +469,14 @@ create collation if not exists test0 from "C"; create collation if not exists test0 (locale = 'foo'); -do -$do$ +do $$ BEGIN EXECUTE 'CREATE COLLATION test1 (lc_collate = ' || quote_literal((SELECT datcollate FROM pg_database WHERE datname = current_database())) || ', lc_ctype = ' || quote_literal((SELECT datctype FROM pg_database WHERE datname = current_database())) || ');'; END -$do$; +$$; create collation test3 (lc_collate = 'en_US.utf8'); @@ -539,10 +507,7 @@ select nspname, obj_description(pg_collation.oid, 'pg_collation') from - pg_collation - inner join - pg_namespace - on collnamespace = pg_namespace.oid + pg_collation inner join pg_namespace on collnamespace = pg_namespace.oid where collname like 'test%' order by 1; @@ -582,7 +547,7 @@ create table collate_dep_test4t ( b text ); -create index "collate_dep_test4i" on collate_dep_test4t using btree (b collate test0); +create index collate_dep_test4i on collate_dep_test4t using btree (b collate test0); drop collation test0; @@ -592,9 +557,9 @@ drop table collate_dep_test1, collate_dep_test4t; drop type collate_dep_test2; -create type textrange_c as range (subtype = text, collation = "C"); +create type textrange_c as range (subtype = text, "collation" = "C"); -create type textrange_en_us as range (subtype = text, collation = "en_US"); +create type textrange_en_us as range (subtype = text, "collation" = "en_US"); select textrange_c('A', 'Z') @> cast('b' as text); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_80.snap index 6f8ce2727..c474adcc8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_80.snap @@ -6,16 +6,12 @@ select getdatabaseencoding() <> 'UTF8' or ( select - COUNT(*) + count(*) from pg_collation where - collname - in ( - 'de_DE', 'en_US', 'sv_SE', 'tr_TR' - ) and - collencoding = - pg_char_to_encoding('UTF8') + collname in ('de_DE', 'en_US', 'sv_SE', 'tr_TR') and + collencoding = pg_char_to_encoding('UTF8') ) <> 4 or version() !~ 'linux-gnu' @@ -23,7 +19,7 @@ select set client_encoding to utf8; -create schema "collate_tests"; +create schema collate_tests; set search_path to collate_tests; @@ -60,11 +56,7 @@ create table collate_test3 ( ); insert into collate_test1 -values - (1, 'abc'), - (2, 'äbc'), - (3, 'bbc'), - (4, 'ABC'); +values (1, 'abc'), (2, 'äbc'), (3, 'bbc'), (4, 'ABC'); insert into collate_test2 select * from collate_test1; @@ -225,7 +217,7 @@ select 'bıt' ~* 'BIT' collate "tr_TR" as "true"; select relname from pg_class where relname ~* '^abc'; -set lc_time = tr_TR; +set lc_time = 'tr_TR'; select to_char(cast('2010-02-01' as date), 'DD TMMON YYYY'); @@ -242,27 +234,13 @@ select to_date('01 Şub 2010', 'DD TMMON YYYY'); select to_date('1234567890ab 2010', 'TMMONTH YYYY'); create view collview1 -as select - * -from - collate_test1 -where - b collate "C" >= 'bbc'; +as select * from collate_test1 where b collate "C" >= 'bbc'; create view collview2 -as select - a, - b -from - collate_test1 -order by b collate "C"; +as select a, b from collate_test1 order by b collate "C"; create view collview3 -as select - a, - lower((x || x) collate "C") -from - collate_test10; +as select a, lower((x || x) collate "C") from collate_test10; select table_name, @@ -347,11 +325,11 @@ select from collate_test10; -select MIN(b), MAX(b) from collate_test1; +select min(b), max(b) from collate_test1; -select MIN(b), MAX(b) from collate_test2; +select min(b), max(b) from collate_test2; -select MIN(b), MAX(b) from collate_test3; +select min(b), max(b) from collate_test3; select array_agg(b order by b) from collate_test1; @@ -370,13 +348,7 @@ select a, b from collate_test3 where a > 1 order by 2; select a, b from collate_test3 except -select - a, - b -from - collate_test3 -where - a < 2 +select a, b from collate_test3 where a < 2 order by 2; select a, b from collate_test1 @@ -388,11 +360,7 @@ select a, b from collate_test1 union all select a, b from collate_test3; select a, b from collate_test1 union select a, b from collate_test3 order by 2; -select - a, - b collate "C" -from - collate_test1 +select a, b collate "C" from collate_test1 union select a, b from collate_test3 order by 2; @@ -403,9 +371,7 @@ select a, b from collate_test1 except select a, b from collate_test3 order by 2; create table test_u as - select a, b from collate_test1 - union all - select a, b from collate_test3; + select a, b from collate_test1 union all select a, b from collate_test3; select x < y from collate_test10; @@ -416,20 +382,9 @@ select x, y from collate_test10 order by x || y; with recursive foo (x) as ( - select - x - from - ( - values ('a' collate "en_US"), ('b') - ) - as t (x) + select x from (values ('a' collate "en_US"), ('b')) as t (x) union all - select - (x || 'c') collate "de_DE" - from - foo - where - length(x) < 10 + select (x || 'c') collate "de_DE" from foo where length(x) < 10 ) select * @@ -445,23 +400,17 @@ select a, cast(b as varchar) from collate_test3 order by 2; create function mylt(text, text) returns boolean language sql -as $function$ -select $1 < $2 -$function$; +as $$ select $1 < $2 $$; create function mylt_noninline(text, text) returns boolean language sql -as $function$ -select $1 < $2 limit 1 -$function$; +as $$ select $1 < $2 limit 1 $$; create function mylt_plpgsql(text, text) returns boolean language plpgsql -as $function$ -begin return $1 < $2; end -$function$; +as $$ begin return $1 < $2; end $$; select a.b as a, @@ -492,28 +441,28 @@ order by a.b, create function mylt2(x text, y text) returns boolean language plpgsql -as $function$ +as $$ declare xx text := x; yy text := y; begin return xx < yy; end -$function$; +$$; select mylt2('a', 'B' collate "en_US") as t, mylt2('a', 'B' collate "C") as f; create or replace function mylt2(x text, y text) returns boolean language plpgsql -as $function$ +as $$ declare xx text COLLATE "POSIX" := x; yy text := y; begin return xx < yy; end -$function$; +$$; select mylt2('a', 'B') as f; @@ -524,48 +473,25 @@ select mylt2('a', 'B' collate "POSIX") as f; select * from - unnest( - ( - select - array_agg(b order by b) - from - collate_test1 - ) - ) + unnest((select array_agg(b order by b) from collate_test1)) order by 1; select * from - unnest( - ( - select - array_agg(b order by b) - from - collate_test2 - ) - ) + unnest((select array_agg(b order by b) from collate_test2)) order by 1; select * from - unnest( - ( - select - array_agg(b order by b) - from - collate_test3 - ) - ) + unnest((select array_agg(b order by b) from collate_test3)) order by 1; create function dup(anyelement) returns anyelement language sql -as $function$ -select $1 -$function$; +as 'select $1'; select a, dup(b) from collate_test1 order by 2; @@ -573,32 +499,19 @@ select a, dup(b) from collate_test2 order by 2; select a, dup(b) from collate_test3 order by 2; -create index "collate_test1_idx1" on collate_test1 using btree (b); +create index collate_test1_idx1 on collate_test1 using btree (b); -create index "collate_test1_idx2" on collate_test1 using btree (b collate "C"); +create index collate_test1_idx2 on collate_test1 using btree (b collate "C"); -create index "collate_test1_idx3" -on collate_test1 -using btree -( - (b collate "C") -); +create index collate_test1_idx3 on collate_test1 using btree ((b collate "C")); -create index "collate_test1_idx4" -on collate_test1 -using btree -( +create index collate_test1_idx4 on collate_test1 using btree ( ((b || 'foo') collate "POSIX") ); -create index "collate_test1_idx5" on collate_test1 using btree (a collate "C"); +create index collate_test1_idx5 on collate_test1 using btree (a collate "C"); -create index "collate_test1_idx6" -on collate_test1 -using btree -( - (a collate "C") -); +create index collate_test1_idx6 on collate_test1 using btree ((a collate "C")); select relname, @@ -611,15 +524,14 @@ order by 1; create role regress_test_role; -create schema "test_schema"; +create schema test_schema; -do -$do$ +do $$ BEGIN EXECUTE 'CREATE COLLATION test0 (locale = ' || quote_literal((SELECT datcollate FROM pg_database WHERE datname = current_database())) || ');'; END -$do$; +$$; create collation test0 from "C"; @@ -627,15 +539,14 @@ create collation if not exists test0 from "C"; create collation if not exists test0 (locale = 'foo'); -do -$do$ +do $$ BEGIN EXECUTE 'CREATE COLLATION test1 (lc_collate = ' || quote_literal((SELECT datcollate FROM pg_database WHERE datname = current_database())) || ', lc_ctype = ' || quote_literal((SELECT datctype FROM pg_database WHERE datname = current_database())) || ');'; END -$do$; +$$; create collation test3 (lc_collate = 'en_US.utf8'); @@ -664,15 +575,9 @@ comment on collation test0 is 'US English'; select collname, nspname, - obj_description( - pg_collation.oid, - 'pg_collation' - ) + obj_description(pg_collation.oid, 'pg_collation') from - pg_collation - inner join - pg_namespace - on collnamespace = pg_namespace.oid + pg_collation inner join pg_namespace on collnamespace = pg_namespace.oid where collname like 'test%' order by 1; @@ -705,19 +610,14 @@ create domain collate_dep_dom1 as text collate "test0"; create type collate_dep_test2 as (x int, y text collate "test0"); create view collate_dep_test3 -as select - cast('foo' as text) collate "test0" - as foo; +as select cast('foo' as text) collate "test0" as foo; create table collate_dep_test4t ( a int, b text ); -create index "collate_dep_test4i" -on collate_dep_test4t -using btree -( +create index collate_dep_test4i on collate_dep_test4t using btree ( b collate test0 ); @@ -729,9 +629,9 @@ drop table collate_dep_test1, collate_dep_test4t; drop type collate_dep_test2; -create type textrange_c as range (subtype = text, collation = "C"); +create type textrange_c as range (subtype = text, "collation" = "C"); -create type textrange_en_us as range (subtype = text, collation = "en_US"); +create type textrange_en_us as range (subtype = text, "collation" = "en_US"); select textrange_c('A', 'Z') @> cast('b' as text); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.utf8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.utf8_100.snap index cde16be36..351e277fb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.utf8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.utf8_100.snap @@ -43,12 +43,9 @@ select initcap(t), upper(t), length(convert_to(t, 'UTF8')) as t_bytes, - length(convert_to(lower(t), 'UTF8')) - as lower_t_bytes, - length(convert_to(initcap(t), 'UTF8')) - as initcap_t_bytes, - length(convert_to(upper(t), 'UTF8')) - as upper_t_bytes + length(convert_to(lower(t), 'UTF8')) as lower_t_bytes, + length(convert_to(initcap(t), 'UTF8')) as initcap_t_bytes, + length(convert_to(upper(t), 'UTF8')) as upper_t_bytes from test_pg_c_utf8; @@ -83,9 +80,7 @@ select 'Δ' ~* '[γ-λ]' collate "pg_c_utf8"; select 'δ' ~* '[Γ-Λ]' collate "pg_c_utf8"; select - casefold( - 'AbCd 123 #$% ıiIİ ẞ ß DŽDždž Σσς' collate "pg_c_utf8" - ); + casefold('AbCd 123 #$% ıiIİ ẞ ß DŽDždž Σσς' collate "pg_c_utf8"); create collation regress_pg_unicode_fast (provider = builtin, locale = 'unicode'); @@ -109,12 +104,9 @@ select initcap(t), upper(t), length(convert_to(t, 'UTF8')) as t_bytes, - length(convert_to(lower(t), 'UTF8')) - as lower_t_bytes, - length(convert_to(initcap(t), 'UTF8')) - as initcap_t_bytes, - length(convert_to(upper(t), 'UTF8')) - as upper_t_bytes + length(convert_to(lower(t), 'UTF8')) as lower_t_bytes, + length(convert_to(initcap(t), 'UTF8')) as initcap_t_bytes, + length(convert_to(upper(t), 'UTF8')) as upper_t_bytes from test_pg_unicode_fast; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.utf8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.utf8_80.snap index b12b91473..0a9ec3677 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.utf8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.utf8_80.snap @@ -43,12 +43,9 @@ select initcap(t), upper(t), length(convert_to(t, 'UTF8')) as t_bytes, - length(convert_to(lower(t), 'UTF8')) - as lower_t_bytes, - length(convert_to(initcap(t), 'UTF8')) - as initcap_t_bytes, - length(convert_to(upper(t), 'UTF8')) - as upper_t_bytes + length(convert_to(lower(t), 'UTF8')) as lower_t_bytes, + length(convert_to(initcap(t), 'UTF8')) as initcap_t_bytes, + length(convert_to(upper(t), 'UTF8')) as upper_t_bytes from test_pg_c_utf8; @@ -115,12 +112,9 @@ select initcap(t), upper(t), length(convert_to(t, 'UTF8')) as t_bytes, - length(convert_to(lower(t), 'UTF8')) - as lower_t_bytes, - length(convert_to(initcap(t), 'UTF8')) - as initcap_t_bytes, - length(convert_to(upper(t), 'UTF8')) - as upper_t_bytes + length(convert_to(lower(t), 'UTF8')) as lower_t_bytes, + length(convert_to(initcap(t), 'UTF8')) as initcap_t_bytes, + length(convert_to(upper(t), 'UTF8')) as upper_t_bytes from test_pg_unicode_fast; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_100.snap index 685db34fa..222c5cf4f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/collate.sql --- -create schema "collate_tests"; +create schema collate_tests; set search_path to collate_tests; @@ -86,27 +86,13 @@ select a, lower(x collate "C"), lower(y collate "C") from collate_test10; select a, x, y from collate_test10 order by lower(y), a; create view collview1 -as select - * -from - collate_test1 -where - b collate "C" >= 'bbc'; +as select * from collate_test1 where b collate "C" >= 'bbc'; create view collview2 -as select - a, - b -from - collate_test1 -order by b collate "C"; +as select a, b from collate_test1 order by b collate "C"; create view collview3 -as select - a, - lower((x || x) collate "POSIX") -from - collate_test10; +as select a, lower((x || x) collate "POSIX") from collate_test10; select table_name, @@ -149,9 +135,9 @@ select a, cast(b as testdomain_p) from collate_test2 order by 2; select a, lower(cast(x as testdomain)), lower(cast(y as testdomain)) from collate_test10; -select MIN(b), MAX(b) from collate_test1; +select min(b), max(b) from collate_test1; -select MIN(b), MAX(b) from collate_test2; +select min(b), max(b) from collate_test2; select array_agg(b order by b) from collate_test1; @@ -196,17 +182,9 @@ select x, y from collate_test10 order by x || y; with recursive foo (x) as ( - select - x - from - (values ('a' collate "C"), ('b')) as t (x) + select x from (values ('a' collate "C"), ('b')) as t (x) union all - select - (x || 'c') collate "POSIX" - from - foo - where - length(x) < 10 + select (x || 'c') collate "POSIX" from foo where length(x) < 10 ) select * @@ -222,24 +200,14 @@ select from collate_test10 where - not (x collate "POSIX", y collate "C") in - ( - select y, x from collate_test10 - ); + not (x collate "POSIX", y collate "C") in (select y, x from collate_test10); select * from collate_test10 where - not (x, y) in - ( - select - y collate "C", - x collate "POSIX" - from - collate_test10 - ); + not (x, y) in (select y collate "C", x collate "POSIX" from collate_test10); select a, cast(b as varchar) from collate_test1 order by 2; @@ -248,9 +216,7 @@ select a, cast(b as varchar) from collate_test2 order by 2; create function vc(text) returns text language sql -as $function$ -select $1::varchar -$function$; +as 'select $1::varchar'; select a, b from collate_test1 order by a, vc(b); @@ -261,25 +227,23 @@ select * from unnest((select array_agg(b order by b) from collate_test2)) order create function dup(anyelement) returns anyelement language sql -as $function$ -select $1 -$function$; +as 'select $1'; select a, dup(b) from collate_test1 order by 2; select a, dup(b) from collate_test2 order by 2; -create index "collate_test1_idx1" on collate_test1 using btree (b); +create index collate_test1_idx1 on collate_test1 using btree (b); -create index "collate_test1_idx2" on collate_test1 using btree (b collate "POSIX"); +create index collate_test1_idx2 on collate_test1 using btree (b collate "POSIX"); -create index "collate_test1_idx3" on collate_test1 using btree ((b collate "POSIX")); +create index collate_test1_idx3 on collate_test1 using btree ((b collate "POSIX")); -create index "collate_test1_idx4" on collate_test1 using btree (((b || 'foo') collate "POSIX")); +create index collate_test1_idx4 on collate_test1 using btree (((b || 'foo') collate "POSIX")); -create index "collate_test1_idx5" on collate_test1 using btree (a collate "POSIX"); +create index collate_test1_idx5 on collate_test1 using btree (a collate "POSIX"); -create index "collate_test1_idx6" on collate_test1 using btree ((a collate "POSIX")); +create index collate_test1_idx6 on collate_test1 using btree ((a collate "POSIX")); select relname, @@ -356,19 +320,16 @@ create temporary table vctable (f1 varchar(25)); insert into vctable values ('foo' collate "C"); -select pg_collation_for('foo'); +select collation for ('foo'); -select pg_collation_for(cast('foo' as text)); +select collation for (cast('foo' as text)); -select pg_collation_for((select a from collate_test1 limit 1)); +select collation for ((select a from collate_test1 limit 1)); -select pg_collation_for((select b from collate_test1 limit 1)); +select collation for ((select b from collate_test1 limit 1)); create view collate_on_int -as select - c1 + 1 as c1p -from - (select cast('4' collate "C" as int) as c1) as ss; +as select c1 + 1 as c1p from (select cast('4' collate "C" as int) as c1) as ss; create collation coll_dup_chk (lc_collate = "POSIX", lc_collate = "NONSENSE", lc_ctype = "POSIX"); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_80.snap index e437d4349..145d6247c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/collate.sql --- -create schema "collate_tests"; +create schema collate_tests; set search_path to collate_tests; @@ -95,27 +95,13 @@ select a, lower(x collate "C"), lower(y collate "C") from collate_test10; select a, x, y from collate_test10 order by lower(y), a; create view collview1 -as select - * -from - collate_test1 -where - b collate "C" >= 'bbc'; +as select * from collate_test1 where b collate "C" >= 'bbc'; create view collview2 -as select - a, - b -from - collate_test1 -order by b collate "C"; +as select a, b from collate_test1 order by b collate "C"; create view collview3 -as select - a, - lower((x || x) collate "POSIX") -from - collate_test10; +as select a, lower((x || x) collate "POSIX") from collate_test10; select table_name, @@ -185,9 +171,9 @@ select from collate_test10; -select MIN(b), MAX(b) from collate_test1; +select min(b), max(b) from collate_test1; -select MIN(b), MAX(b) from collate_test2; +select min(b), max(b) from collate_test2; select array_agg(b order by b) from collate_test1; @@ -198,10 +184,7 @@ select string_agg(x collate "C", y collate "POSIX") from collate_test10; select array_agg(x collate "C" order by y collate "POSIX") from collate_test10; select - array_agg( - a order by x collate "C", - y collate "POSIX" - ) + array_agg(a order by x collate "C", y collate "POSIX") from collate_test10; @@ -218,13 +201,7 @@ select a, b from collate_test2 where a > 1 order by 2; select a, b from collate_test2 except -select - a, - b -from - collate_test2 -where - a < 2 +select a, b from collate_test2 where a < 2 order by 2; select a, b from collate_test1 @@ -236,11 +213,7 @@ select a, b from collate_test1 union all select a, b from collate_test2; select a, b from collate_test1 union select a, b from collate_test2 order by 2; -select - a, - b collate "C" -from - collate_test1 +select a, b collate "C" from collate_test1 union select a, b from collate_test2 order by 2; @@ -251,9 +224,7 @@ select a, b from collate_test1 except select a, b from collate_test2 order by 2; create table test_u as - select a, b from collate_test1 - union all - select a, b from collate_test2; + select a, b from collate_test1 union all select a, b from collate_test2; select x < y from collate_test10; @@ -264,20 +235,9 @@ select x, y from collate_test10 order by x || y; with recursive foo (x) as ( - select - x - from - ( - values ('a' collate "C"), ('b') - ) - as t (x) + select x from (values ('a' collate "C"), ('b')) as t (x) union all - select - (x || 'c') collate "POSIX" - from - foo - where - length(x) < 10 + select (x || 'c') collate "POSIX" from foo where length(x) < 10 ) select * @@ -289,46 +249,28 @@ select b, a < b as lt from - ( - values - ('a', 'B'), - ('A', 'b' collate "C") - ) - as v (a, b); + (values ('a', 'B'), ('A', 'b' collate "C")) as v (a, b); select * from collate_test10 where - not (x, y) in - ( - select y, x from collate_test10 - ); + not (x, y) in (select y, x from collate_test10); select * from collate_test10 where - not (x collate "POSIX", y collate "C") in - ( - select y, x from collate_test10 - ); + not (x collate "POSIX", y collate "C") in (select y, x from collate_test10); select * from collate_test10 where - not (x, y) in - ( - select - y collate "C", - x collate "POSIX" - from - collate_test10 - ); + not (x, y) in (select y collate "C", x collate "POSIX" from collate_test10); select a, cast(b as varchar) from collate_test1 order by 2; @@ -337,83 +279,50 @@ select a, cast(b as varchar) from collate_test2 order by 2; create function vc(text) returns text language sql -as $function$ -select $1::varchar -$function$; +as 'select $1::varchar'; select a, b from collate_test1 order by a, vc(b); select * from - unnest( - ( - select - array_agg(b order by b) - from - collate_test1 - ) - ) + unnest((select array_agg(b order by b) from collate_test1)) order by 1; select * from - unnest( - ( - select - array_agg(b order by b) - from - collate_test2 - ) - ) + unnest((select array_agg(b order by b) from collate_test2)) order by 1; create function dup(anyelement) returns anyelement language sql -as $function$ -select $1 -$function$; +as 'select $1'; select a, dup(b) from collate_test1 order by 2; select a, dup(b) from collate_test2 order by 2; -create index "collate_test1_idx1" on collate_test1 using btree (b); +create index collate_test1_idx1 on collate_test1 using btree (b); -create index "collate_test1_idx2" -on collate_test1 -using btree -( +create index collate_test1_idx2 on collate_test1 using btree ( b collate "POSIX" ); -create index "collate_test1_idx3" -on collate_test1 -using btree -( +create index collate_test1_idx3 on collate_test1 using btree ( (b collate "POSIX") ); -create index "collate_test1_idx4" -on collate_test1 -using btree -( +create index collate_test1_idx4 on collate_test1 using btree ( ((b || 'foo') collate "POSIX") ); -create index "collate_test1_idx5" -on collate_test1 -using btree -( +create index collate_test1_idx5 on collate_test1 using btree ( a collate "POSIX" ); -create index "collate_test1_idx6" -on collate_test1 -using btree -( +create index collate_test1_idx6 on collate_test1 using btree ( (a collate "POSIX") ); @@ -447,16 +356,12 @@ create table collate_test22 (f2 text collate "POSIX"); insert into collate_test22 values ('foo'), ('bar'), ('baz'); alter table collate_test22 - add foreign key - (f2) - references collate_test20; + add foreign key (f2) references collate_test20; delete from collate_test22 where f2 = 'baz'; alter table collate_test22 - add foreign key - (f2) - references collate_test20; + add foreign key (f2) references collate_test20; reset enable_seqscan; @@ -500,23 +405,16 @@ create temporary table vctable (f1 varchar(25)); insert into vctable values ('foo' collate "C"); -select pg_collation_for('foo'); +select collation for ('foo'); -select pg_collation_for(cast('foo' as text)); +select collation for (cast('foo' as text)); -select pg_collation_for((select a from collate_test1 limit 1)); +select collation for ((select a from collate_test1 limit 1)); -select pg_collation_for((select b from collate_test1 limit 1)); +select collation for ((select b from collate_test1 limit 1)); create view collate_on_int -as select - c1 + 1 as c1p -from - ( - select - cast('4' collate "C" as int) as c1 - ) - as ss; +as select c1 + 1 as c1p from (select cast('4' collate "C" as int) as c1) as ss; create collation coll_dup_chk ( lc_collate = "POSIX", diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__combocid_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__combocid_100.snap index 08270aac3..5487c8ada 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__combocid_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__combocid_100.snap @@ -51,7 +51,7 @@ begin; insert into combocidtest values (333); -declare "c" cursor for select ctid, cmin, * from combocidtest;; +declare c cursor for select ctid, cmin, * from combocidtest;; delete from combocidtest; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__combocid_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__combocid_80.snap index 08270aac3..5487c8ada 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__combocid_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__combocid_80.snap @@ -51,7 +51,7 @@ begin; insert into combocidtest values (333); -declare "c" cursor for select ctid, cmin, * from combocidtest;; +declare c cursor for select ctid, cmin, * from combocidtest;; delete from combocidtest; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_100.snap index f328cd34f..5c373d2d6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/compression.sql --- -create schema "pglz"; +create schema pglz; set search_path to pglz, public; @@ -10,7 +10,7 @@ set default_toast_compression = pglz; create table cmdata (f1 text compression pglz); -create index "idx" on cmdata using btree (f1); +create index idx on cmdata using btree (f1); insert into cmdata values (repeat('1234567890', 1000)); @@ -27,9 +27,7 @@ create table cmdata2 (f1 int compression pglz); create or replace function large_val() returns text language sql -as $function$ -select array_agg(fipshash(g::text))::text from generate_series(1, 256) g -$function$; +as 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g'; create table cmdata2 (f1 text compression pglz); @@ -65,8 +63,7 @@ select pg_column_compression(f1) from cmdata2; create table cmdata3 (f1 text); create table cminh () -inherits (cmdata, -cmdata3); +inherits (cmdata, cmdata3); set default_toast_compression = ''; @@ -81,7 +78,7 @@ drop table cmdata2; select pg_column_compression(f1) from cmdata; -vacuum (FULL) cmdata; +vacuum (full) cmdata; select pg_column_compression(f1) from cmdata; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_80.snap index f328cd34f..5c373d2d6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/compression.sql --- -create schema "pglz"; +create schema pglz; set search_path to pglz, public; @@ -10,7 +10,7 @@ set default_toast_compression = pglz; create table cmdata (f1 text compression pglz); -create index "idx" on cmdata using btree (f1); +create index idx on cmdata using btree (f1); insert into cmdata values (repeat('1234567890', 1000)); @@ -27,9 +27,7 @@ create table cmdata2 (f1 int compression pglz); create or replace function large_val() returns text language sql -as $function$ -select array_agg(fipshash(g::text))::text from generate_series(1, 256) g -$function$; +as 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g'; create table cmdata2 (f1 text compression pglz); @@ -65,8 +63,7 @@ select pg_column_compression(f1) from cmdata2; create table cmdata3 (f1 text); create table cminh () -inherits (cmdata, -cmdata3); +inherits (cmdata, cmdata3); set default_toast_compression = ''; @@ -81,7 +78,7 @@ drop table cmdata2; select pg_column_compression(f1) from cmdata; -vacuum (FULL) cmdata; +vacuum (full) cmdata; select pg_column_compression(f1) from cmdata; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_100.snap index ef243bd8c..2fe4a2bf0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_100.snap @@ -9,7 +9,7 @@ from where name = 'default_toast_compression'; -create schema "lz4"; +create schema lz4; set search_path to lz4, public; @@ -17,7 +17,7 @@ set default_toast_compression = pglz; create table cmdata_pglz (f1 text compression pglz); -create index "idx" on cmdata_pglz using btree (f1); +create index idx on cmdata_pglz using btree (f1); insert into cmdata_pglz values (repeat('1234567890', 1000)); @@ -35,7 +35,7 @@ select * into cmmove1 from cmdata_lz4; select pg_column_compression(f1) from cmmove1; -create table cmdata2 (like cmdata_lz4 including COMPRESSION); +create table cmdata2 (like cmdata_lz4 including compression); drop table cmdata2; @@ -60,9 +60,7 @@ select pg_column_compression(f1) from cmmove2; create or replace function large_val_lz4() returns text language sql -as $function$ -select array_agg(fipshash(g::text))::text from generate_series(1, 256) g -$function$; +as 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g'; create table cmdata2 (f1 text compression lz4); @@ -83,9 +81,9 @@ select pg_column_compression(f1) from cmdata_lz4; select pg_column_compression(x) from compressmv; create table cmpart (f1 text compression lz4) -partition by HASH(f1); +partition by hash(f1); -create table cmpart1 partition of cmpart for values with (MODULUS 2, REMAINDER 0); +create table cmpart1 partition of cmpart for values with (modulus 2, remainder 0); create table cmpart2 (f1 text compression pglz); @@ -98,8 +96,7 @@ select pg_column_compression(f1) from cmpart1; select pg_column_compression(f1) from cmpart2; create table cminh () -inherits (cmdata_pglz, -cmdata_lz4); +inherits (cmdata_pglz, cmdata_lz4); create table cminh (f1 text compression lz4) inherits (cmdata_pglz); @@ -107,8 +104,7 @@ inherits (cmdata_pglz); create table cmdata3 (f1 text); create table cminh () -inherits (cmdata_pglz, -cmdata3); +inherits (cmdata_pglz, cmdata3); set default_toast_compression = lz4; @@ -144,17 +140,12 @@ create table cmdata2 ( f2 text compression lz4 ); -create unique index "idx1" on cmdata2 using btree ((f1 || f2)); +create unique index idx1 on cmdata2 using btree ((f1 || f2)); insert into cmdata2 values ( - ( - select - cast(array_agg(fipshash(cast(g as text))) as text) - from - generate_series(1, 50) as g - ), + (select cast(array_agg(fipshash(cast(g as text))) as text) from generate_series(1, 50) as g), version() ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_80.snap index 07f58455d..3d1a7a9d8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_80.snap @@ -9,7 +9,7 @@ from where name = 'default_toast_compression'; -create schema "lz4"; +create schema lz4; set search_path to lz4, public; @@ -17,7 +17,7 @@ set default_toast_compression = pglz; create table cmdata_pglz (f1 text compression pglz); -create index "idx" on cmdata_pglz using btree (f1); +create index idx on cmdata_pglz using btree (f1); insert into cmdata_pglz values (repeat('1234567890', 1000)); @@ -35,7 +35,7 @@ select * into cmmove1 from cmdata_lz4; select pg_column_compression(f1) from cmmove1; -create table cmdata2 (like cmdata_lz4 including COMPRESSION); +create table cmdata2 (like cmdata_lz4 including compression); drop table cmdata2; @@ -60,9 +60,7 @@ select pg_column_compression(f1) from cmmove2; create or replace function large_val_lz4() returns text language sql -as $function$ -select array_agg(fipshash(g::text))::text from generate_series(1, 256) g -$function$; +as 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g'; create table cmdata2 (f1 text compression lz4); @@ -83,11 +81,11 @@ select pg_column_compression(f1) from cmdata_lz4; select pg_column_compression(x) from compressmv; create table cmpart (f1 text compression lz4) -partition by HASH(f1); +partition by hash(f1); create table cmpart1 partition of cmpart -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table cmpart2 (f1 text compression pglz); @@ -100,8 +98,7 @@ select pg_column_compression(f1) from cmpart1; select pg_column_compression(f1) from cmpart2; create table cminh () -inherits (cmdata_pglz, -cmdata_lz4); +inherits (cmdata_pglz, cmdata_lz4); create table cminh (f1 text compression lz4) inherits (cmdata_pglz); @@ -109,8 +106,7 @@ inherits (cmdata_pglz); create table cmdata3 (f1 text); create table cminh () -inherits (cmdata_pglz, -cmdata3); +inherits (cmdata_pglz, cmdata3); set default_toast_compression = lz4; @@ -146,15 +142,14 @@ create table cmdata2 ( f2 text compression lz4 ); -create unique index "idx1" on cmdata2 using btree ((f1 || f2)); +create unique index idx1 on cmdata2 using btree ((f1 || f2)); insert into cmdata2 values ( ( select - cast(array_agg(fipshash(cast(g as text))) - as text) + cast(array_agg(fipshash(cast(g as text))) as text) from generate_series(1, 50) as g ), diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__constraints_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__constraints_100.snap index 407cf206d..c943a3b37 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__constraints_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__constraints_100.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/constraints.sql create table default_tbl ( i int default 100, x text default 'vadim', - f double precision default 123.456 + f float8 default 123.456 ); insert into default_tbl values (1, 'thomas', 57.0613); @@ -37,13 +37,13 @@ insert into defaultexpr_tbl (i2) values (null); select * from defaultexpr_tbl; -create table error_tbl (b1 boolean default (1 in (1, 2))); +create table error_tbl (b1 bool default (1 in (1, 2))); drop table error_tbl; create table check_tbl ( x int, - constraint "check_con" check (x > 3) + constraint check_con check (x > 3) ); insert into check_tbl values (5); @@ -80,7 +80,7 @@ create table check2_tbl ( x int, y text, z int, - constraint "sequence_con" check (x > 3 and y <> 'check failed' and z < 8) + constraint sequence_con check (x > 3 and y <> 'check failed' and z < 8) ); insert into check2_tbl values (4, 'check ok', -2); @@ -144,13 +144,9 @@ select * from insert_tbl; create table sys_col_check_tbl ( city text, state text, - is_capital boolean, + is_capital bool, altitude int, - check (not ( - is_capital and - cast(cast(tableoid as regclass) as text) = - 'sys_col_check_tbl' - )) + check (not (is_capital and cast(cast(tableoid as regclass) as text) = 'sys_col_check_tbl')) ); insert into sys_col_check_tbl values ('Seattle', 'Washington', false, 100); @@ -164,12 +160,9 @@ drop table sys_col_check_tbl; create table sys_col_check_tbl ( city text, state text, - is_capital boolean, + is_capital bool, altitude int, - check (not ( - is_capital and - cast(ctid as text) = 'sys_col_check_tbl' - )) + check (not (is_capital and cast(ctid as text) = 'sys_col_check_tbl')) ); create table insert_child ( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__constraints_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__constraints_80.snap index 407cf206d..cad3da22d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__constraints_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__constraints_80.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/constraints.sql create table default_tbl ( i int default 100, x text default 'vadim', - f double precision default 123.456 + f float8 default 123.456 ); insert into default_tbl values (1, 'thomas', 57.0613); @@ -37,13 +37,13 @@ insert into defaultexpr_tbl (i2) values (null); select * from defaultexpr_tbl; -create table error_tbl (b1 boolean default (1 in (1, 2))); +create table error_tbl (b1 bool default (1 in (1, 2))); drop table error_tbl; create table check_tbl ( x int, - constraint "check_con" check (x > 3) + constraint check_con check (x > 3) ); insert into check_tbl values (5); @@ -80,7 +80,7 @@ create table check2_tbl ( x int, y text, z int, - constraint "sequence_con" check (x > 3 and y <> 'check failed' and z < 8) + constraint sequence_con check (x > 3 and y <> 'check failed' and z < 8) ); insert into check2_tbl values (4, 'check ok', -2); @@ -144,12 +144,11 @@ select * from insert_tbl; create table sys_col_check_tbl ( city text, state text, - is_capital boolean, + is_capital bool, altitude int, check (not ( is_capital and - cast(cast(tableoid as regclass) as text) = - 'sys_col_check_tbl' + cast(cast(tableoid as regclass) as text) = 'sys_col_check_tbl' )) ); @@ -164,12 +163,9 @@ drop table sys_col_check_tbl; create table sys_col_check_tbl ( city text, state text, - is_capital boolean, + is_capital bool, altitude int, - check (not ( - is_capital and - cast(ctid as text) = 'sys_col_check_tbl' - )) + check (not (is_capital and cast(ctid as text) = 'sys_col_check_tbl')) ); create table insert_child ( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__conversion_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__conversion_100.snap index b0e0e5ce7..04614b40e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__conversion_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__conversion_100.snap @@ -10,7 +10,7 @@ as 'regresslib', 'test_enc_setup'; select from test_enc_setup(); -create function test_enc_conversion(bytea, name, name, boolean, out validlen int, out result bytea) +create function test_enc_conversion(bytea, name, name, bool, out validlen int, out result bytea) language c strict as 'regresslib', 'test_enc_conversion'; @@ -51,7 +51,7 @@ test_conv( out error text ) language plpgsql -as $function$ +as $$ declare validlen int; begin @@ -69,7 +69,7 @@ begin end; return; end; -$function$; +$$; create table utf8_verification_inputs ( inbytes bytea, @@ -110,11 +110,7 @@ as ( select inbytes, description, - (test_conv( - inbytes || cast(repeat('.', 3) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8')).error from utf8_verification_inputs ), @@ -122,11 +118,7 @@ test_padded as ( select description, - (test_conv( - inbytes || cast(repeat('.', 64) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 64) as bytea), 'utf8', 'utf8')).error from test_bytes ) @@ -135,10 +127,7 @@ select b.error as orig_error, p.error as error_after_padding from - test_padded as p - inner join - test_bytes as b - using ("description") + test_padded as p inner join test_bytes as b using (description) where p.error is distinct from b.error order by description; @@ -149,11 +138,7 @@ as ( select inbytes, description, - (test_conv( - inbytes || cast(repeat('.', 3) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8')).error from utf8_verification_inputs ), @@ -162,9 +147,7 @@ as ( select description, (test_conv( - cast(repeat('.', 64 - length(inbytes)) as bytea) || - inbytes || - cast(repeat('.', 64) as bytea), + cast(repeat('.', 64 - length(inbytes)) as bytea) || inbytes || cast(repeat('.', 64) as bytea), 'utf8', 'utf8' )).error @@ -176,10 +159,7 @@ select b.error as orig_error, p.error as error_after_padding from - test_padded as p - inner join - test_bytes as b - using ("description") + test_padded as p inner join test_bytes as b using (description) where p.error is distinct from b.error order by description; @@ -190,11 +170,7 @@ as ( select inbytes, description, - (test_conv( - inbytes || cast(repeat('.', 3) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8')).error from utf8_verification_inputs ), @@ -203,8 +179,7 @@ as ( select description, (test_conv( - cast(repeat('.', 64) as bytea) || inbytes || - cast(repeat('.', 3) as bytea), + cast(repeat('.', 64) as bytea) || inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8' )).error @@ -216,10 +191,7 @@ select b.error as orig_error, p.error as error_after_padding from - test_padded as p - inner join - test_bytes as b - using ("description") + test_padded as p inner join test_bytes as b using (description) where p.error is distinct from b.error order by description; @@ -230,11 +202,7 @@ as ( select inbytes, description, - (test_conv( - inbytes || cast(repeat('.', 3) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8')).error from utf8_verification_inputs ), @@ -243,9 +211,7 @@ as ( select description, (test_conv( - cast(repeat('.', 64 - length(inbytes)) as bytea) || - inbytes || - cast(repeat('.', 3) as bytea), + cast(repeat('.', 64 - length(inbytes)) as bytea) || inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8' )).error @@ -257,10 +223,7 @@ select b.error as orig_error, p.error as error_after_padding from - test_padded as p - inner join - test_bytes as b - using ("description") + test_padded as p inner join test_bytes as b using (description) where p.error is distinct from b.error order by description; @@ -276,23 +239,11 @@ values ('\xc3a4c3b6', 'valid, extra latin chars'), ('\xd184d0bed0be', 'valid, cyrillic'), ('\x666f6fe8b1a1', 'valid, kanji/Chinese'), - ( - '\xe382abe3829a', - 'valid, two chars that combine to one in EUC_JIS_2004' - ), - ( - '\xe382ab', - 'only first half of combined char in EUC_JIS_2004' - ), - ( - '\xe382abe382', - 'incomplete combination when converted EUC_JIS_2004' - ), + ('\xe382abe3829a', 'valid, two chars that combine to one in EUC_JIS_2004'), + ('\xe382ab', 'only first half of combined char in EUC_JIS_2004'), + ('\xe382abe382', 'incomplete combination when converted EUC_JIS_2004'), ('\xecbd94eb81bceba6ac', 'valid, Hangul, Korean'), - ( - '\x666f6fefa8aa', - 'valid, needs mapping function to convert to GB18030' - ), + ('\x666f6fefa8aa', 'valid, needs mapping function to convert to GB18030'), ('\x66e8b1ff6f6f', 'invalid byte sequence'), ('\x66006f', 'invalid, NUL byte'), ('\x666f6fe8b100', 'invalid, NUL byte'), @@ -321,9 +272,7 @@ insert into euc_jis_2004_inputs values ('\x666f6f', 'valid, pure ASCII'), ('\x666f6fbedd', 'valid'), - ( - '\xa5f7', 'valid, translates to two UTF-8 chars ' - ), + ('\xa5f7', 'valid, translates to two UTF-8 chars '), ('\xbeddbe', 'incomplete char '), ('\x666f6f00bedd', 'invalid, NUL byte'), ('\x666f6fbe00dd', 'invalid, NUL byte'), @@ -354,15 +303,9 @@ values ('\x666f6f', 'valid, pure ASCII'), ('\x666f6f8fdb', 'valid'), ('\x666f6f81c0', 'valid, no translation to UTF-8'), - ( - '\x666f6f82f5', - 'valid, translates to two UTF-8 chars ' - ), + ('\x666f6f82f5', 'valid, translates to two UTF-8 chars '), ('\x666f6f8fdb8f', 'incomplete char '), - ( - '\x666f6f820a', - 'incomplete char, followed by newline ' - ), + ('\x666f6f820a', 'incomplete char, followed by newline '), ('\x666f6f008fdb', 'invalid, NUL byte'), ('\x666f6f8f00db', 'invalid, NUL byte'), ('\x666f6f8fdb00', 'invalid, NUL byte'); @@ -397,19 +340,10 @@ insert into gb18030_inputs values ('\x666f6f', 'valid, pure ASCII'), ('\x666f6fcff3', 'valid'), - ( - '\x666f6f8431a530', - 'valid, no translation to UTF-8' - ), - ( - '\x666f6f84309c38', - 'valid, translates to UTF-8 by mapping function' - ), + ('\x666f6f8431a530', 'valid, no translation to UTF-8'), + ('\x666f6f84309c38', 'valid, translates to UTF-8 by mapping function'), ('\x666f6f84309c', 'incomplete char '), - ( - '\x666f6f84309c0a', - 'incomplete char, followed by newline ' - ), + ('\x666f6f84309c0a', 'incomplete char, followed by newline '), ('\x666f6f84', 'incomplete char at end'), ('\x666f6f84309c3800', 'invalid, NUL byte'), ('\x666f6f84309c0038', 'invalid, NUL byte'); @@ -417,11 +351,7 @@ values select description, inbytes, - (test_conv( - cast(cast(inbytes as text) as bytea), - 'gb18030', - 'gb18030' - )).* + (test_conv(cast(cast(inbytes as text) as bytea), 'gb18030', 'gb18030')).* from gb18030_inputs; @@ -493,11 +423,7 @@ values select description, inbytes, - (test_conv( - inbytes, - 'mule_internal', - 'mule_internal' - )).* + (test_conv(inbytes, 'mule_internal', 'mule_internal')).* from mic_inputs; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__conversion_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__conversion_80.snap index 01d7525ae..82fc9ff66 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__conversion_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__conversion_80.snap @@ -15,7 +15,7 @@ test_enc_conversion( bytea, name, name, - boolean, + bool, out validlen int, out result bytea ) @@ -63,7 +63,7 @@ test_conv( out error text ) language plpgsql -as $function$ +as $$ declare validlen int; begin @@ -81,7 +81,7 @@ begin end; return; end; -$function$; +$$; create table utf8_verification_inputs ( inbytes bytea, @@ -92,44 +92,24 @@ insert into utf8_verification_inputs values ('\x66006f', 'NUL byte'), ('\xaf', 'bare continuation'), - ( - '\xc5', - 'missing second byte in 2-byte char' - ), + ('\xc5', 'missing second byte in 2-byte char'), ('\xc080', 'smallest 2-byte overlong'), ('\xc1bf', 'largest 2-byte overlong'), - ( - '\xc280', 'next 2-byte after overlongs' - ), + ('\xc280', 'next 2-byte after overlongs'), ('\xdfbf', 'largest 2-byte'), - ( - '\xe9af', - 'missing third byte in 3-byte char' - ), + ('\xe9af', 'missing third byte in 3-byte char'), ('\xe08080', 'smallest 3-byte overlong'), ('\xe09fbf', 'largest 3-byte overlong'), - ( - '\xe0a080', 'next 3-byte after overlong' - ), + ('\xe0a080', 'next 3-byte after overlong'), ('\xed9fbf', 'last before surrogates'), ('\xeda080', 'smallest surrogate'), ('\xedbfbf', 'largest surrogate'), ('\xee8080', 'next after surrogates'), ('\xefbfbf', 'largest 3-byte'), - ( - '\xf1afbf', - 'missing fourth byte in 4-byte char' - ), - ( - '\xf0808080', 'smallest 4-byte overlong' - ), - ( - '\xf08fbfbf', 'largest 4-byte overlong' - ), - ( - '\xf0908080', - 'next 4-byte after overlong' - ), + ('\xf1afbf', 'missing fourth byte in 4-byte char'), + ('\xf0808080', 'smallest 4-byte overlong'), + ('\xf08fbfbf', 'largest 4-byte overlong'), + ('\xf0908080', 'next 4-byte after overlong'), ('\xf48fbfbf', 'largest 4-byte'), ('\xf4908080', 'smallest too large'), ('\xfa9a9a8a8a', '5-byte'); @@ -146,11 +126,7 @@ as ( select inbytes, description, - (test_conv( - inbytes || cast(repeat('.', 3) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8')).error from utf8_verification_inputs ), @@ -158,12 +134,7 @@ test_padded as ( select description, - (test_conv( - inbytes || - cast(repeat('.', 64) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 64) as bytea), 'utf8', 'utf8')).error from test_bytes ) @@ -172,10 +143,7 @@ select b.error as orig_error, p.error as error_after_padding from - test_padded as p - inner join - test_bytes as b - using ("description") + test_padded as p inner join test_bytes as b using (description) where p.error is distinct from b.error order by description; @@ -186,11 +154,7 @@ as ( select inbytes, description, - (test_conv( - inbytes || cast(repeat('.', 3) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8')).error from utf8_verification_inputs ), @@ -199,9 +163,7 @@ as ( select description, (test_conv( - cast(repeat('.', 64 - length(inbytes)) - as bytea) || - inbytes || + cast(repeat('.', 64 - length(inbytes)) as bytea) || inbytes || cast(repeat('.', 64) as bytea), 'utf8', 'utf8' @@ -214,10 +176,7 @@ select b.error as orig_error, p.error as error_after_padding from - test_padded as p - inner join - test_bytes as b - using ("description") + test_padded as p inner join test_bytes as b using (description) where p.error is distinct from b.error order by description; @@ -228,11 +187,7 @@ as ( select inbytes, description, - (test_conv( - inbytes || cast(repeat('.', 3) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8')).error from utf8_verification_inputs ), @@ -241,8 +196,7 @@ as ( select description, (test_conv( - cast(repeat('.', 64) as bytea) || - inbytes || + cast(repeat('.', 64) as bytea) || inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8' @@ -255,10 +209,7 @@ select b.error as orig_error, p.error as error_after_padding from - test_padded as p - inner join - test_bytes as b - using ("description") + test_padded as p inner join test_bytes as b using (description) where p.error is distinct from b.error order by description; @@ -269,11 +220,7 @@ as ( select inbytes, description, - (test_conv( - inbytes || cast(repeat('.', 3) as bytea), - 'utf8', - 'utf8' - )).error + (test_conv(inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8')).error from utf8_verification_inputs ), @@ -282,9 +229,7 @@ as ( select description, (test_conv( - cast(repeat('.', 64 - length(inbytes)) - as bytea) || - inbytes || + cast(repeat('.', 64 - length(inbytes)) as bytea) || inbytes || cast(repeat('.', 3) as bytea), 'utf8', 'utf8' @@ -297,10 +242,7 @@ select b.error as orig_error, p.error as error_after_padding from - test_padded as p - inner join - test_bytes as b - using ("description") + test_padded as p inner join test_bytes as b using (description) where p.error is distinct from b.error order by description; @@ -313,54 +255,25 @@ create table utf8_inputs ( insert into utf8_inputs values ('\x666f6f', 'valid, pure ASCII'), - ( - '\xc3a4c3b6', 'valid, extra latin chars' - ), + ('\xc3a4c3b6', 'valid, extra latin chars'), ('\xd184d0bed0be', 'valid, cyrillic'), - ( - '\x666f6fe8b1a1', 'valid, kanji/Chinese' - ), - ( - '\xe382abe3829a', - 'valid, two chars that combine to one in EUC_JIS_2004' - ), - ( - '\xe382ab', - 'only first half of combined char in EUC_JIS_2004' - ), - ( - '\xe382abe382', - 'incomplete combination when converted EUC_JIS_2004' - ), - ( - '\xecbd94eb81bceba6ac', - 'valid, Hangul, Korean' - ), - ( - '\x666f6fefa8aa', - 'valid, needs mapping function to convert to GB18030' - ), - ( - '\x66e8b1ff6f6f', - 'invalid byte sequence' - ), + ('\x666f6fe8b1a1', 'valid, kanji/Chinese'), + ('\xe382abe3829a', 'valid, two chars that combine to one in EUC_JIS_2004'), + ('\xe382ab', 'only first half of combined char in EUC_JIS_2004'), + ('\xe382abe382', 'incomplete combination when converted EUC_JIS_2004'), + ('\xecbd94eb81bceba6ac', 'valid, Hangul, Korean'), + ('\x666f6fefa8aa', 'valid, needs mapping function to convert to GB18030'), + ('\x66e8b1ff6f6f', 'invalid byte sequence'), ('\x66006f', 'invalid, NUL byte'), ('\x666f6fe8b100', 'invalid, NUL byte'), - ( - '\x666f6fe8b1', - 'incomplete character at end' - ); + ('\x666f6fe8b1', 'incomplete character at end'); select description, (test_conv(inbytes, 'utf8', 'utf8')).* from utf8_inputs; select description, inbytes, - (test_conv( - inbytes, - 'utf8', - 'euc_jis_2004' - )).* + (test_conv(inbytes, 'utf8', 'euc_jis_2004')).* from utf8_inputs; @@ -408,10 +321,7 @@ insert into euc_jis_2004_inputs values ('\x666f6f', 'valid, pure ASCII'), ('\x666f6fbedd', 'valid'), - ( - '\xa5f7', - 'valid, translates to two UTF-8 chars ' - ), + ('\xa5f7', 'valid, translates to two UTF-8 chars '), ('\xbeddbe', 'incomplete char '), ('\x666f6f00bedd', 'invalid, NUL byte'), ('\x666f6fbe00dd', 'invalid, NUL byte'), @@ -421,22 +331,14 @@ values select description, inbytes, - (test_conv( - inbytes, - 'euc_jis_2004', - 'euc_jis_2004' - )).* + (test_conv(inbytes, 'euc_jis_2004', 'euc_jis_2004')).* from euc_jis_2004_inputs; select description, inbytes, - (test_conv( - inbytes, - 'euc_jis_2004', - 'utf8' - )).* + (test_conv(inbytes, 'euc_jis_2004', 'utf8')).* from euc_jis_2004_inputs; @@ -449,19 +351,10 @@ insert into shiftjis2004_inputs values ('\x666f6f', 'valid, pure ASCII'), ('\x666f6f8fdb', 'valid'), - ( - '\x666f6f81c0', - 'valid, no translation to UTF-8' - ), - ( - '\x666f6f82f5', - 'valid, translates to two UTF-8 chars ' - ), + ('\x666f6f81c0', 'valid, no translation to UTF-8'), + ('\x666f6f82f5', 'valid, translates to two UTF-8 chars '), ('\x666f6f8fdb8f', 'incomplete char '), - ( - '\x666f6f820a', - 'incomplete char, followed by newline ' - ), + ('\x666f6f820a', 'incomplete char, followed by newline '), ('\x666f6f008fdb', 'invalid, NUL byte'), ('\x666f6f8f00db', 'invalid, NUL byte'), ('\x666f6f8fdb00', 'invalid, NUL byte'); @@ -469,33 +362,21 @@ values select description, inbytes, - (test_conv( - inbytes, - 'shiftjis2004', - 'shiftjis2004' - )).* + (test_conv(inbytes, 'shiftjis2004', 'shiftjis2004')).* from shiftjis2004_inputs; select description, inbytes, - (test_conv( - inbytes, - 'shiftjis2004', - 'utf8' - )).* + (test_conv(inbytes, 'shiftjis2004', 'utf8')).* from shiftjis2004_inputs; select description, inbytes, - (test_conv( - inbytes, - 'shiftjis2004', - 'euc_jis_2004' - )).* + (test_conv(inbytes, 'shiftjis2004', 'euc_jis_2004')).* from shiftjis2004_inputs; @@ -508,37 +389,18 @@ insert into gb18030_inputs values ('\x666f6f', 'valid, pure ASCII'), ('\x666f6fcff3', 'valid'), - ( - '\x666f6f8431a530', - 'valid, no translation to UTF-8' - ), - ( - '\x666f6f84309c38', - 'valid, translates to UTF-8 by mapping function' - ), + ('\x666f6f8431a530', 'valid, no translation to UTF-8'), + ('\x666f6f84309c38', 'valid, translates to UTF-8 by mapping function'), ('\x666f6f84309c', 'incomplete char '), - ( - '\x666f6f84309c0a', - 'incomplete char, followed by newline ' - ), + ('\x666f6f84309c0a', 'incomplete char, followed by newline '), ('\x666f6f84', 'incomplete char at end'), - ( - '\x666f6f84309c3800', - 'invalid, NUL byte' - ), - ( - '\x666f6f84309c0038', - 'invalid, NUL byte' - ); + ('\x666f6f84309c3800', 'invalid, NUL byte'), + ('\x666f6f84309c0038', 'invalid, NUL byte'); select description, inbytes, - (test_conv( - cast(cast(inbytes as text) as bytea), - 'gb18030', - 'gb18030' - )).* + (test_conv(cast(cast(inbytes as text) as bytea), 'gb18030', 'gb18030')).* from gb18030_inputs; @@ -565,11 +427,7 @@ values select description, inbytes, - (test_conv( - inbytes, - 'iso8859-5', - 'iso8859-5' - )).* + (test_conv(inbytes, 'iso8859-5', 'iso8859-5')).* from iso8859_5_inputs; @@ -590,11 +448,7 @@ from select description, inbytes, - (test_conv( - inbytes, - 'iso8859_5', - 'mule_internal' - )).* + (test_conv(inbytes, 'iso8859_5', 'mule_internal')).* from iso8859_5_inputs; @@ -607,10 +461,7 @@ insert into big5_inputs values ('\x666f6f', 'valid, pure ASCII'), ('\x666f6fb648', 'valid'), - ( - '\x666f6fa27f', - 'valid, no translation to UTF-8' - ), + ('\x666f6fa27f', 'valid, no translation to UTF-8'), ('\x666f6fb60048', 'invalid, NUL byte'), ('\x666f6fb64800', 'invalid, NUL byte'); @@ -631,11 +482,7 @@ from select description, inbytes, - (test_conv( - inbytes, - 'big5', - 'mule_internal' - )).* + (test_conv(inbytes, 'big5', 'mule_internal')).* from big5_inputs; @@ -648,85 +495,53 @@ insert into mic_inputs values ('\x666f6f', 'valid, pure ASCII'), ('\x8bc68bcf8bcf', 'valid (in KOI8R)'), - ( - '\x8bc68bcf8b', - 'invalid,incomplete char' - ), + ('\x8bc68bcf8b', 'invalid,incomplete char'), ('\x92bedd', 'valid (in SHIFT_JIS)'), ('\x92be', 'invalid, incomplete char)'), ('\x666f6f95a3c1', 'valid (in Big5)'), - ( - '\x666f6f95a3', - 'invalid, incomplete char' - ), + ('\x666f6f95a3', 'invalid, incomplete char'), ('\x9200bedd', 'invalid, NUL byte'), ('\x92bedd00', 'invalid, NUL byte'), - ( - '\x8b00c68bcf8bcf', 'invalid, NUL byte' - ); + ('\x8b00c68bcf8bcf', 'invalid, NUL byte'); select description, inbytes, - (test_conv( - inbytes, - 'mule_internal', - 'mule_internal' - )).* + (test_conv(inbytes, 'mule_internal', 'mule_internal')).* from mic_inputs; select description, inbytes, - (test_conv( - inbytes, - 'mule_internal', - 'koi8r' - )).* + (test_conv(inbytes, 'mule_internal', 'koi8r')).* from mic_inputs; select description, inbytes, - (test_conv( - inbytes, - 'mule_internal', - 'iso8859-5' - )).* + (test_conv(inbytes, 'mule_internal', 'iso8859-5')).* from mic_inputs; select description, inbytes, - (test_conv( - inbytes, - 'mule_internal', - 'sjis' - )).* + (test_conv(inbytes, 'mule_internal', 'sjis')).* from mic_inputs; select description, inbytes, - (test_conv( - inbytes, - 'mule_internal', - 'big5' - )).* + (test_conv(inbytes, 'mule_internal', 'big5')).* from mic_inputs; select description, inbytes, - (test_conv( - inbytes, - 'mule_internal', - 'euc_jp' - )).* + (test_conv(inbytes, 'mule_internal', 'euc_jp')).* from mic_inputs; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_100.snap index 4a8e32fac..7dda8b3aa 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_100.snap @@ -13,22 +13,22 @@ create temporary table x ( create function fn_x_before() returns trigger language plpgsql -as $function$ -BEGIN - NEW.e := 'before trigger fired'::text; +as ' + BEGIN + NEW.e := ''before trigger fired''::text; return NEW; END; -$function$; +'; create function fn_x_after() returns trigger language plpgsql -as $function$ -BEGIN - UPDATE x set e='after trigger fired' where c='stuff'; +as ' + BEGIN + UPDATE x set e=''after trigger fired'' where c=''stuff''; return NULL; END; -$function$; +'; create trigger trg_x_after after insert on x for each row execute function fn_x_after(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_80.snap index 68a167a76..ec1640d42 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_80.snap @@ -13,22 +13,22 @@ create temporary table x ( create function fn_x_before() returns trigger language plpgsql -as $function$ -BEGIN - NEW.e := 'before trigger fired'::text; +as ' + BEGIN + NEW.e := ''before trigger fired''::text; return NEW; END; -$function$; +'; create function fn_x_after() returns trigger language plpgsql -as $function$ -BEGIN - UPDATE x set e='after trigger fired' where c='stuff'; +as ' + BEGIN + UPDATE x set e=''after trigger fired'' where c=''stuff''; return NULL; END; -$function$; +'; create trigger trg_x_after after insert diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy_100.snap index 5445342c2..4006c75ab 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy_100.snap @@ -19,25 +19,25 @@ insert into copytest values ('Mac', 'abc def', 3); insert into copytest values ('esc\ape', 'a\r\ \ \nb', 4); -copy copytest to 'filename' with (FORMAT 'csv'); +copy copytest to 'filename' with (format 'csv'); create temporary table copytest2 (like copytest); -copy copytest2 from 'filename' with (FORMAT 'csv'); +copy copytest2 from 'filename' with (format 'csv'); select * from copytest except select * from copytest2; truncate copytest2; -copy copytest to 'filename' with (FORMAT 'csv', QUOTE '''', ESCAPE '\'); +copy copytest to 'filename' with (format 'csv', quote '''', escape '\'); -copy copytest2 from 'filename' with (FORMAT 'csv', QUOTE '''', ESCAPE '\'); +copy copytest2 from 'filename' with (format 'csv', quote '''', escape '\'); select * from copytest except select * from copytest2; truncate copytest2; -copy copytest2 (test) from 'filename' with (FORMAT 'csv'); +copy copytest2 (test) from 'filename' with (format 'csv'); select test from copytest2 order by test collate "C"; @@ -53,41 +53,41 @@ create temporary table copytest3 ( "col with "" quote" int ); -copy copytest3 from stdout with (FORMAT 'csv', HEADER); +copy copytest3 from stdout with (format 'csv', header); -copy copytest3 to stdout with (FORMAT 'csv', HEADER); +copy copytest3 to stdout with (format 'csv', header); create temporary table copytest4 ( c1 int, "colname with tab: " text ); -copy copytest4 from stdout with (HEADER); +copy copytest4 from stdout with (header); -copy copytest4 to stdout with (HEADER); +copy copytest4 to stdout with (header); create temporary table copytest5 (c1 int); -copy copytest5 from stdout with (FORMAT 'csv', HEADER 2); +copy copytest5 from stdout with (format 'csv', header 2); truncate copytest5; -copy copytest5 from stdout with (FORMAT 'csv', HEADER 4); +copy copytest5 from stdout with (format 'csv', header 4); -select COUNT(*) from copytest5; +select count(*) from copytest5; truncate copytest5; -copy copytest5 from stdout with (FORMAT 'csv', HEADER 5); +copy copytest5 from stdout with (format 'csv', header 5); -select COUNT(*) from copytest5; +select count(*) from copytest5; create table parted_copytest ( a int, b int, c text ) -partition by LIST(b); +partition by list(b); create table parted_copytest_a1 ( c text, @@ -125,14 +125,14 @@ begin; truncate parted_copytest; -copy parted_copytest from 'filename' with (FREEZE); +copy parted_copytest from 'filename' with (freeze); rollback; select cast(tableoid as regclass), - COUNT(*), - SUM(a) + count(*), + sum(a) from parted_copytest group by tableoid @@ -143,11 +143,11 @@ truncate parted_copytest; create function part_ins_func() returns trigger language plpgsql -as $function$ +as $$ begin return new; end; -$function$; +$$; create trigger part_ins_trig before insert @@ -159,8 +159,8 @@ copy parted_copytest from 'filename'; select cast(tableoid as regclass), - COUNT(*), - SUM(a) + count(*), + sum(a) from parted_copytest group by tableoid @@ -182,16 +182,16 @@ drop table parted_copytest; create table tab_progress_reporting ( name text, - age int, + age int4, location point, - salary int, + salary int4, manager name ); create function notice_after_tab_progress_reporting() returns trigger language plpgsql -as $function$ +as $$ declare report record; begin -- The fields ignored here are the ones that may not remain @@ -215,7 +215,7 @@ begin raise info 'progress: %', report.value::text; return new; end; -$function$; +$$; create trigger check_after_tab_progress_reporting after insert @@ -229,7 +229,7 @@ truncate tab_progress_reporting; copy tab_progress_reporting from 'filename' where salary < 2000; -copy tab_progress_reporting from stdout with (ON_ERROR 'ignore'); +copy tab_progress_reporting from stdout with (on_error 'ignore'); drop trigger check_after_tab_progress_reporting on tab_progress_reporting; @@ -275,16 +275,16 @@ copy oversized_column_default from stdout; copy oversized_column_default (col2) from stdout; -copy oversized_column_default from stdout with (DEFAULT ''); +copy oversized_column_default from stdout with (default ''); drop table oversized_column_default; create table parted_si ( id int not null, data text not null, - rand double precision not null default random() + rand float8 not null default random() ) -partition by LIST((id % 2)); +partition by list((id % 2)); create table parted_si_p_even partition of parted_si for values in (0); @@ -295,7 +295,7 @@ copy parted_si (id, data) from 'filename'; select cast(tableoid as regclass), id % 2 = 0 as is_even, - COUNT(*) + count(*) from parted_si group by 1, @@ -312,7 +312,7 @@ create server copytest_server foreign data wrapper copytest_wrapper; create foreign table copytest_foreign_table ( a int ) server copytest_server; -copy copytest_foreign_table from stdout with (FREEZE); +copy copytest_foreign_table from stdout with (freeze); create materialized view copytest_mv as select 1 as id with no data; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy_80.snap index 611b66674..cbdd77dcb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy_80.snap @@ -19,25 +19,25 @@ insert into copytest values ('Mac', 'abc def', 3); insert into copytest values ('esc\ape', 'a\r\ \ \nb', 4); -copy copytest to 'filename' with (FORMAT 'csv'); +copy copytest to 'filename' with (format 'csv'); create temporary table copytest2 (like copytest); -copy copytest2 from 'filename' with (FORMAT 'csv'); +copy copytest2 from 'filename' with (format 'csv'); select * from copytest except select * from copytest2; truncate copytest2; -copy copytest to 'filename' with (FORMAT 'csv', QUOTE '''', ESCAPE '\'); +copy copytest to 'filename' with (format 'csv', quote '''', escape '\'); -copy copytest2 from 'filename' with (FORMAT 'csv', QUOTE '''', ESCAPE '\'); +copy copytest2 from 'filename' with (format 'csv', quote '''', escape '\'); select * from copytest except select * from copytest2; truncate copytest2; -copy copytest2 (test) from 'filename' with (FORMAT 'csv'); +copy copytest2 (test) from 'filename' with (format 'csv'); select test from copytest2 order by test collate "C"; @@ -53,41 +53,41 @@ create temporary table copytest3 ( "col with "" quote" int ); -copy copytest3 from stdout with (FORMAT 'csv', HEADER); +copy copytest3 from stdout with (format 'csv', header); -copy copytest3 to stdout with (FORMAT 'csv', HEADER); +copy copytest3 to stdout with (format 'csv', header); create temporary table copytest4 ( c1 int, "colname with tab: " text ); -copy copytest4 from stdout with (HEADER); +copy copytest4 from stdout with (header); -copy copytest4 to stdout with (HEADER); +copy copytest4 to stdout with (header); create temporary table copytest5 (c1 int); -copy copytest5 from stdout with (FORMAT 'csv', HEADER 2); +copy copytest5 from stdout with (format 'csv', header 2); truncate copytest5; -copy copytest5 from stdout with (FORMAT 'csv', HEADER 4); +copy copytest5 from stdout with (format 'csv', header 4); -select COUNT(*) from copytest5; +select count(*) from copytest5; truncate copytest5; -copy copytest5 from stdout with (FORMAT 'csv', HEADER 5); +copy copytest5 from stdout with (format 'csv', header 5); -select COUNT(*) from copytest5; +select count(*) from copytest5; create table parted_copytest ( a int, b int, c text ) -partition by LIST(b); +partition by list(b); create table parted_copytest_a1 ( c text, @@ -110,28 +110,13 @@ alter table parted_copytest parted_copytest_a2 for values in (2); insert into parted_copytest -select - x, - 1, - 'One' -from - generate_series(1, 1000) as x; +select x, 1, 'One' from generate_series(1, 1000) as x; insert into parted_copytest -select - x, - 2, - 'Two' -from - generate_series(1001, 1010) as x; +select x, 2, 'Two' from generate_series(1001, 1010) as x; insert into parted_copytest -select - x, - 1, - 'One' -from - generate_series(1011, 1020) as x; +select x, 1, 'One' from generate_series(1011, 1020) as x; copy (select * from parted_copytest order by a) to 'filename'; @@ -143,14 +128,14 @@ begin; truncate parted_copytest; -copy parted_copytest from 'filename' with (FREEZE); +copy parted_copytest from 'filename' with (freeze); rollback; select cast(tableoid as regclass), - COUNT(*), - SUM(a) + count(*), + sum(a) from parted_copytest group by tableoid @@ -161,11 +146,11 @@ truncate parted_copytest; create function part_ins_func() returns trigger language plpgsql -as $function$ +as $$ begin return new; end; -$function$; +$$; create trigger part_ins_trig before insert @@ -177,8 +162,8 @@ copy parted_copytest from 'filename'; select cast(tableoid as regclass), - COUNT(*), - SUM(a) + count(*), + sum(a) from parted_copytest group by tableoid @@ -200,16 +185,16 @@ drop table parted_copytest; create table tab_progress_reporting ( name text, - age int, + age int4, location point, - salary int, + salary int4, manager name ); create function notice_after_tab_progress_reporting() returns trigger language plpgsql -as $function$ +as $$ declare report record; begin -- The fields ignored here are the ones that may not remain @@ -233,7 +218,7 @@ begin raise info 'progress: %', report.value::text; return new; end; -$function$; +$$; create trigger check_after_tab_progress_reporting after insert @@ -247,7 +232,7 @@ truncate tab_progress_reporting; copy tab_progress_reporting from 'filename' where salary < 2000; -copy tab_progress_reporting from stdout with (ON_ERROR 'ignore'); +copy tab_progress_reporting from stdout with (on_error 'ignore'); drop trigger check_after_tab_progress_reporting on tab_progress_reporting; @@ -285,8 +270,7 @@ select * from header_copytest order by a; drop table header_copytest; create temporary table oversized_column_default ( - col1 varchar(5) - default 'more than 5 chars', + col1 varchar(5) default 'more than 5 chars', col2 varchar(5) ); @@ -294,18 +278,16 @@ copy oversized_column_default from stdout; copy oversized_column_default (col2) from stdout; -copy oversized_column_default from stdout with (DEFAULT ''); +copy oversized_column_default from stdout with (default ''); drop table oversized_column_default; create table parted_si ( id int not null, data text not null, - rand double precision - not null - default random() + rand float8 not null default random() ) -partition by LIST((id % 2)); +partition by list((id % 2)); create table parted_si_p_even partition of parted_si for values in (0); @@ -316,7 +298,7 @@ copy parted_si (id, data) from 'filename'; select cast(tableoid as regclass), id % 2 = 0 as is_even, - COUNT(*) + count(*) from parted_si group by 1, @@ -333,7 +315,7 @@ create server copytest_server foreign data wrapper copytest_wrapper; create foreign table copytest_foreign_table ( a int ) server copytest_server; -copy copytest_foreign_table from stdout with (FREEZE); +copy copytest_foreign_table from stdout with (freeze); create materialized view copytest_mv as select 1 as id with no data; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copydml_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copydml_100.snap index d18a95c4c..cacc56e0f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copydml_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copydml_100.snap @@ -146,7 +146,7 @@ drop rule qqq on copydml_test; create rule qqq as on insert to copydml_test do instead - notify "copydml_test";; + notify copydml_test;; copy (insert into copydml_test default values) to stdout; @@ -155,7 +155,7 @@ drop rule qqq on copydml_test; create function qqq_trig() returns trigger language plpgsql -as $function$ +as $$ begin if tg_op in ('INSERT', 'UPDATE') then raise notice '% % %', tg_when, tg_op, new.id; @@ -165,7 +165,7 @@ else return old; end if; end -$function$; +$$; create trigger qqqbef before insert or delete or update diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copydml_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copydml_80.snap index d18a95c4c..cacc56e0f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copydml_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copydml_80.snap @@ -146,7 +146,7 @@ drop rule qqq on copydml_test; create rule qqq as on insert to copydml_test do instead - notify "copydml_test";; + notify copydml_test;; copy (insert into copydml_test default values) to stdout; @@ -155,7 +155,7 @@ drop rule qqq on copydml_test; create function qqq_trig() returns trigger language plpgsql -as $function$ +as $$ begin if tg_op in ('INSERT', 'UPDATE') then raise notice '% % %', tg_when, tg_op, new.id; @@ -165,7 +165,7 @@ else return old; end if; end -$function$; +$$; create trigger qqqbef before insert or delete or update diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copyselect_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copyselect_100.snap index 75e22e314..ce2379034 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copyselect_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copyselect_100.snap @@ -46,23 +46,14 @@ copy (select t from test1 where id = 3 for update) to stdout; copy (select t into temporary table test3 from test1 where id = 3) to stdout; -copy (select * from test1 inner join test2 using ("id")) to stdout; +copy (select * from test1 inner join test2 using (id)) to stdout; copy (select t from test1 where id = 1 union select * from v_test1 order by 1) to stdout; -copy (select - * -from - ( - select t from test1 where id = 1 - union - select * from v_test1 - order by 1 - ) - as t1) +copy (select * from (select t from test1 where id = 1 union select * from v_test1 order by 1) as t1) to stdout; -copy (select t from test1 where id = 1) to stdout with (FORMAT 'csv', HEADER, FORCE_QUOTE (t)); +copy (select t from test1 where id = 1) to stdout with (format 'csv', header, force_quote (t)); drop table test2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copyselect_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copyselect_80.snap index 48e3677f8..42dac00bd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copyselect_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copyselect_80.snap @@ -46,29 +46,23 @@ copy (select t from test1 where id = 3 for update) to stdout; copy (select t into temporary table test3 from test1 where id = 3) to stdout; -copy (select * from test1 inner join test2 using ("id")) to stdout; +copy (select * from test1 inner join test2 using (id)) to stdout; -copy (select t from test1 where id = 1 -union -select * from v_test1 -order by 1) +copy (select t from test1 where id = 1 union select * from v_test1 order by 1) to stdout; copy (select * from ( - select t from test1 where id = 1 - union - select * from v_test1 - order by 1 + select t from test1 where id = 1 union select * from v_test1 order by 1 ) as t1) to stdout; copy (select t from test1 where id = 1) to stdout -with (FORMAT 'csv', HEADER, FORCE_QUOTE (t)); +with (format 'csv', header, force_quote (t)); drop table test2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_100.snap index 1b123c736..f28c44e19 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_100.snap @@ -4,25 +4,25 @@ input_file: crates/pgls_pretty_print/tests/data/multi/create_aggregate.sql --- create aggregate newavg ( sfunc = int4_avg_accum, - basetype = int, + basetype = int4, stype = _int8, finalfunc = int8_avg, initcond1 = '{0,0}' ); -comment on aggregate newavg_wrong(int) is 'an agg comment'; +comment on aggregate newavg_wrong(int4) is 'an agg comment'; -comment on aggregate newavg(int) is 'an agg comment'; +comment on aggregate newavg(int4) is 'an agg comment'; -comment on aggregate newavg(int) is null; +comment on aggregate newavg(int4) is null; -create aggregate newsum (sfunc1 = int4pl, basetype = int, stype1 = int, initcond1 = '0'); +create aggregate newsum (sfunc1 = int4pl, basetype = int4, stype1 = int4, initcond1 = '0'); -create aggregate newcnt (*) (sfunc = int8inc, stype = bigint, initcond = '0', parallel = safe); +create aggregate newcnt (*) (sfunc = int8inc, stype = int8, initcond = '0', parallel = safe); -create aggregate oldcnt (sfunc = int8inc, basetype = 'ANY', stype = bigint, initcond = '0'); +create aggregate oldcnt (sfunc = int8inc, basetype = 'ANY', stype = int8, initcond = '0'); -create aggregate newcnt ("any") (sfunc = int8inc_any, stype = bigint, initcond = '0'); +create aggregate newcnt ("any") (sfunc = int8inc_any, stype = int8, initcond = '0'); comment on aggregate nosuchagg(*) is 'should fail'; @@ -30,16 +30,14 @@ comment on aggregate newcnt(*) is 'an agg(*) comment'; comment on aggregate newcnt("any") is 'an agg(any) comment'; -create function sum3(bigint, bigint, bigint) -returns bigint +create function sum3(int8, int8, int8) +returns int8 language sql immutable strict -as $function$ -select $1 + $2 + $3 -$function$; +as 'select $1 + $2 + $3'; -create aggregate sum2 (bigint, bigint) (sfunc = sum3, stype = bigint, initcond = '0'); +create aggregate sum2 (int8, int8) (sfunc = sum3, stype = int8, initcond = '0'); create type aggtype as (a int, b int, c text); @@ -48,17 +46,13 @@ returns aggtype[] language sql immutable strict -as $function$ -select array_append($1,ROW($2,$3,$4)::aggtype) -$function$; +as 'select array_append($1,ROW($2,$3,$4)::aggtype)'; create function aggfns_trans(aggtype[], int, int, text) returns aggtype[] language sql immutable -as $function$ -select array_append($1,ROW($2,$3,$4)::aggtype) -$function$; +as 'select array_append($1,ROW($2,$3,$4)::aggtype)'; create aggregate aggfstr (int, int, text) (sfunc = aggf_trans, stype = aggtype[], initcond = '{}'); @@ -71,45 +65,37 @@ create aggregate aggfns ( initcond = '{}' ); -create function least_accum(bigint, bigint) -returns bigint +create function least_accum(int8, int8) +returns int8 language sql -as $function$ -select least($1, $2) -$function$; +as 'select least($1, $2)'; -create aggregate least_agg (int) (stype = bigint, sfunc = least_accum); +create aggregate least_agg (int4) (stype = int8, sfunc = least_accum); -drop function least_accum(bigint, bigint); +drop function least_accum(int8, int8); create function least_accum(anycompatible, anycompatible) returns anycompatible language sql -as $function$ -select least($1, $2) -$function$; +as 'select least($1, $2)'; -create aggregate least_agg (int) (stype = bigint, sfunc = least_accum); +create aggregate least_agg (int4) (stype = int8, sfunc = least_accum); -create aggregate least_agg (bigint) (stype = bigint, sfunc = least_accum); +create aggregate least_agg (int8) (stype = int8, sfunc = least_accum); drop function least_accum(anycompatible, anycompatible) cascade; create function least_accum(anyelement, variadic anyarray) returns anyelement language sql -as $function$ -select least($1, min($2[i])) from generate_subscripts($2,1) g(i) -$function$; +as 'select least($1, min($2[i])) from generate_subscripts($2,1) g(i)'; create aggregate least_agg (variadic items anyarray) (stype = anyelement, sfunc = least_accum); create function cleast_accum(anycompatible, variadic anycompatiblearray) returns anycompatible language sql -as $function$ -select least($1, min($2[i])) from generate_subscripts($2,1) g(i) -$function$; +as 'select least($1, min($2[i])) from generate_subscripts($2,1) g(i)'; create aggregate cleast_agg ( variadic items anycompatiblearray @@ -119,7 +105,7 @@ create aggregate cleast_agg ( ); create aggregate my_percentile_disc ( - double precision, anyelement + float8, anyelement ) ( stype = internal, sfunc = ordered_set_transition, @@ -138,16 +124,16 @@ create aggregate my_rank ( hypothetical ); -alter aggregate my_percentile_disc(double precision, anyelement) rename to test_percentile_disc; +alter aggregate my_percentile_disc(float8, anyelement) rename to test_percentile_disc; -alter aggregate my_rank("any") rename to test_rank; +alter aggregate my_rank(variadic "any") rename to test_rank; create aggregate sumdouble ( - double precision + float8 ) ( - stype = double precision, + stype = float8, sfunc = float8pl, - mstype = double precision, + mstype = float8, msfunc = float8pl, minvfunc = float8mi ); @@ -273,67 +259,61 @@ create or replace aggregate myavg ( create or replace aggregate myavg (numeric) (stype = numeric, sfunc = numeric_add); -create function sum4(bigint, bigint, bigint, bigint) -returns bigint +create function sum4(int8, int8, int8, int8) +returns int8 language sql immutable strict -as $function$ -select $1 + $2 + $3 + $4 -$function$; +as 'select $1 + $2 + $3 + $4'; -create or replace aggregate sum3 (bigint, bigint, bigint) (stype = bigint, sfunc = sum4); +create or replace aggregate sum3 (int8, int8, int8) (stype = int8, sfunc = sum4); -drop function sum4(bigint, bigint, bigint, bigint); +drop function sum4(int8, int8, int8, int8); drop aggregate myavg(numeric); create aggregate mysum (int) (stype = int, sfunc = int4pl, parallel = pear); -create function float8mi_n(double precision, double precision) -returns double precision +create function float8mi_n(float8, float8) +returns float8 language sql -as $function$ -SELECT $1 - $2; -$function$; +as $$ SELECT $1 - $2; $$; create aggregate invalidsumdouble ( - double precision + float8 ) ( - stype = double precision, + stype = float8, sfunc = float8pl, - mstype = double precision, + mstype = float8, msfunc = float8pl, minvfunc = float8mi_n ); -create function float8mi_int(double precision, double precision) +create function float8mi_int(float8, float8) returns int language sql -as $function$ -SELECT CAST($1 - $2 AS INT); -$function$; +as $$ SELECT CAST($1 - $2 AS INT); $$; create aggregate wrongreturntype ( - double precision + float8 ) ( - stype = double precision, + stype = float8, sfunc = float8pl, - mstype = double precision, + mstype = float8, msfunc = float8pl, minvfunc = float8mi_int ); create aggregate case_agg ( "Sfunc1" = int4pl, - "Basetype" = int, - "Stype1" = int, + "Basetype" = int4, + "Stype1" = int4, "Initcond1" = '0', "Parallel" = safe ); create aggregate case_agg ( - double precision + float8 ) ( "Stype" = internal, "Sfunc" = ordered_set_transition, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_80.snap index 13aa6bcab..d24992b63 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_80.snap @@ -4,22 +4,22 @@ input_file: crates/pgls_pretty_print/tests/data/multi/create_aggregate.sql --- create aggregate newavg ( sfunc = int4_avg_accum, - basetype = int, + basetype = int4, stype = _int8, finalfunc = int8_avg, initcond1 = '{0,0}' ); -comment on aggregate newavg_wrong(int) is 'an agg comment'; +comment on aggregate newavg_wrong(int4) is 'an agg comment'; -comment on aggregate newavg(int) is 'an agg comment'; +comment on aggregate newavg(int4) is 'an agg comment'; -comment on aggregate newavg(int) is null; +comment on aggregate newavg(int4) is null; create aggregate newsum ( sfunc1 = int4pl, - basetype = int, - stype1 = int, + basetype = int4, + stype1 = int4, initcond1 = '0' ); @@ -27,7 +27,7 @@ create aggregate newcnt ( * ) ( sfunc = int8inc, - stype = bigint, + stype = int8, initcond = '0', parallel = safe ); @@ -35,7 +35,7 @@ create aggregate newcnt ( create aggregate oldcnt ( sfunc = int8inc, basetype = 'ANY', - stype = bigint, + stype = int8, initcond = '0' ); @@ -43,7 +43,7 @@ create aggregate newcnt ( "any" ) ( sfunc = int8inc_any, - stype = bigint, + stype = int8, initcond = '0' ); @@ -53,22 +53,14 @@ comment on aggregate newcnt(*) is 'an agg(*) comment'; comment on aggregate newcnt("any") is 'an agg(any) comment'; -create function sum3(bigint, bigint, bigint) -returns bigint +create function sum3(int8, int8, int8) +returns int8 language sql immutable strict -as $function$ -select $1 + $2 + $3 -$function$; +as 'select $1 + $2 + $3'; -create aggregate sum2 ( - bigint, bigint -) ( - sfunc = sum3, - stype = bigint, - initcond = '0' -); +create aggregate sum2 (int8, int8) (sfunc = sum3, stype = int8, initcond = '0'); create type aggtype as (a int, b int, c text); @@ -77,17 +69,13 @@ returns aggtype[] language sql immutable strict -as $function$ -select array_append($1,ROW($2,$3,$4)::aggtype) -$function$; +as 'select array_append($1,ROW($2,$3,$4)::aggtype)'; create function aggfns_trans(aggtype[], int, int, text) returns aggtype[] language sql immutable -as $function$ -select array_append($1,ROW($2,$3,$4)::aggtype) -$function$; +as 'select array_append($1,ROW($2,$3,$4)::aggtype)'; create aggregate aggfstr ( int, int, text @@ -106,36 +94,30 @@ create aggregate aggfns ( initcond = '{}' ); -create function least_accum(bigint, bigint) -returns bigint +create function least_accum(int8, int8) +returns int8 language sql -as $function$ -select least($1, $2) -$function$; +as 'select least($1, $2)'; -create aggregate least_agg (int) (stype = bigint, sfunc = least_accum); +create aggregate least_agg (int4) (stype = int8, sfunc = least_accum); -drop function least_accum(bigint, bigint); +drop function least_accum(int8, int8); create function least_accum(anycompatible, anycompatible) returns anycompatible language sql -as $function$ -select least($1, $2) -$function$; +as 'select least($1, $2)'; -create aggregate least_agg (int) (stype = bigint, sfunc = least_accum); +create aggregate least_agg (int4) (stype = int8, sfunc = least_accum); -create aggregate least_agg (bigint) (stype = bigint, sfunc = least_accum); +create aggregate least_agg (int8) (stype = int8, sfunc = least_accum); drop function least_accum(anycompatible, anycompatible) cascade; create function least_accum(anyelement, variadic anyarray) returns anyelement language sql -as $function$ -select least($1, min($2[i])) from generate_subscripts($2,1) g(i) -$function$; +as 'select least($1, min($2[i])) from generate_subscripts($2,1) g(i)'; create aggregate least_agg ( variadic items anyarray @@ -147,9 +129,7 @@ create aggregate least_agg ( create function cleast_accum(anycompatible, variadic anycompatiblearray) returns anycompatible language sql -as $function$ -select least($1, min($2[i])) from generate_subscripts($2,1) g(i) -$function$; +as 'select least($1, min($2[i])) from generate_subscripts($2,1) g(i)'; create aggregate cleast_agg ( variadic items anycompatiblearray @@ -159,7 +139,7 @@ create aggregate cleast_agg ( ); create aggregate my_percentile_disc ( - double precision, anyelement + float8, anyelement ) ( stype = internal, sfunc = ordered_set_transition, @@ -178,19 +158,17 @@ create aggregate my_rank ( hypothetical ); -alter aggregate my_percentile_disc( - double precision, - anyelement) +alter aggregate my_percentile_disc(float8, anyelement) rename to test_percentile_disc; -alter aggregate my_rank("any") rename to test_rank; +alter aggregate my_rank(variadic "any") rename to test_rank; create aggregate sumdouble ( - double precision + float8 ) ( - stype = double precision, + stype = float8, sfunc = float8pl, - mstype = double precision, + mstype = float8, msfunc = float8pl, minvfunc = float8mi ); @@ -326,72 +304,66 @@ create or replace aggregate myavg ( sfunc = numeric_add ); -create function sum4(bigint, bigint, bigint, bigint) -returns bigint +create function sum4(int8, int8, int8, int8) +returns int8 language sql immutable strict -as $function$ -select $1 + $2 + $3 + $4 -$function$; +as 'select $1 + $2 + $3 + $4'; create or replace aggregate sum3 ( - bigint, bigint, bigint + int8, int8, int8 ) ( - stype = bigint, + stype = int8, sfunc = sum4 ); -drop function sum4(bigint, bigint, bigint, bigint); +drop function sum4(int8, int8, int8, int8); drop aggregate myavg(numeric); create aggregate mysum (int) (stype = int, sfunc = int4pl, parallel = pear); -create function float8mi_n(double precision, double precision) -returns double precision +create function float8mi_n(float8, float8) +returns float8 language sql -as $function$ -SELECT $1 - $2; -$function$; +as $$ SELECT $1 - $2; $$; create aggregate invalidsumdouble ( - double precision + float8 ) ( - stype = double precision, + stype = float8, sfunc = float8pl, - mstype = double precision, + mstype = float8, msfunc = float8pl, minvfunc = float8mi_n ); -create function float8mi_int(double precision, double precision) +create function float8mi_int(float8, float8) returns int language sql -as $function$ -SELECT CAST($1 - $2 AS INT); -$function$; +as $$ SELECT CAST($1 - $2 AS INT); $$; create aggregate wrongreturntype ( - double precision + float8 ) ( - stype = double precision, + stype = float8, sfunc = float8pl, - mstype = double precision, + mstype = float8, msfunc = float8pl, minvfunc = float8mi_int ); create aggregate case_agg ( "Sfunc1" = int4pl, - "Basetype" = int, - "Stype1" = int, + "Basetype" = int4, + "Stype1" = int4, "Initcond1" = '0', "Parallel" = safe ); create aggregate case_agg ( - double precision + float8 ) ( "Stype" = internal, "Sfunc" = ordered_set_transition, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_am_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_am_100.snap index 79dfa5d43..634db5f08 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_am_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_am_100.snap @@ -9,7 +9,7 @@ create access method bogus type index handler int4in; create access method bogus type index handler heap_tableam_handler; -create index "grect2ind2" on fast_emp4000 using gist2 (home_base); +create index grect2ind2 on fast_emp4000 using gist2 (home_base); create operator class box_ops default for type box @@ -26,18 +26,13 @@ create operator class box_ops default operator 10 <<|, operator 11 |>>, operator 12 |&>, - function 1 gist_box_consistent( - internal, - box, - smallint, - oid, - internal), + function 1 gist_box_consistent(internal, box, smallint, oid, internal), function 2 gist_box_union(internal, internal), function 5 gist_box_penalty(internal, internal, internal), function 6 gist_box_picksplit(internal, internal), function 7 gist_box_same(box, box, internal); -create index "grect2ind2" on fast_emp4000 using gist2 (home_base); +create index grect2ind2 on fast_emp4000 using gist2 (home_base); begin; @@ -65,13 +60,13 @@ where home_base <@ cast('(200,200),(2000,1000)' as box) order by (home_base[0])[0]; -select COUNT(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); +select count(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); -select COUNT(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); +select count(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; rollback; @@ -79,7 +74,7 @@ drop access method gist2; begin; -lock table fast_emp4000 in ACCESS EXCLUSIVE mode; +lock table fast_emp4000 in access exclusive mode; drop access method gist2 cascade; @@ -117,7 +112,7 @@ create table tableam_parted_heap2 ( a text, b int ) -partition by LIST(a) using heap2; +partition by list(a) using heap2; select a.amname @@ -125,8 +120,7 @@ from pg_class as c, pg_am as a where - c.relname = 'tableam_parted_heap2' and - a.oid = c.relam; + c.relname = 'tableam_parted_heap2' and a.oid = c.relam; drop table tableam_parted_heap2; @@ -134,7 +128,7 @@ create table tableam_parted_heap2 ( a text, b int ) -partition by LIST(a); +partition by list(a); set default_table_access_method = heap; @@ -180,8 +174,7 @@ order by 3, 2; select - pg_describe_object(classid, objid, objsubid) - as obj + pg_describe_object(classid, objid, objsubid) as obj from pg_depend, pg_am @@ -195,11 +188,7 @@ order by classid, create table heaptable using heap as - select - a, - repeat(cast(a as text), 100) - from - generate_series(1, 9) as a; + select a, repeat(cast(a as text), 100) from generate_series(1, 9) as a; select amname @@ -207,27 +196,19 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heaptable' as regclass); + c.relam = am.oid and c.oid = cast('heaptable' as regclass); alter table heaptable set access method heap2; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend where - classid = cast('pg_class' as regclass) and - objid = cast('heaptable' as regclass) + classid = cast('pg_class' as regclass) and objid = cast('heaptable' as regclass) order by 1, 2; @@ -235,20 +216,13 @@ alter table heaptable set access method heap; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend where - classid = cast('pg_class' as regclass) and - objid = cast('heaptable' as regclass) + classid = cast('pg_class' as regclass) and objid = cast('heaptable' as regclass) order by 1, 2; @@ -261,10 +235,9 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heaptable' as regclass); + c.relam = am.oid and c.oid = cast('heaptable' as regclass); -select COUNT(a), COUNT(1) filter (where a = 1) from heaptable; +select count(a), count(1) filter (where a = 1) from heaptable; begin; @@ -279,8 +252,7 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heaptable' as regclass); + c.relam = am.oid and c.oid = cast('heaptable' as regclass); set local default_table_access_method = heap; @@ -293,8 +265,7 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heaptable' as regclass); + c.relam = am.oid and c.oid = cast('heaptable' as regclass); rollback; @@ -306,8 +277,7 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heapmv' as regclass); + c.relam = am.oid and c.oid = cast('heapmv' as regclass); alter materialized view heapmv set access method heap2; @@ -318,10 +288,9 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heapmv' as regclass); + c.relam = am.oid and c.oid = cast('heapmv' as regclass); -select COUNT(a), COUNT(1) filter (where a = 1) from heapmv; +select count(a), count(1) filter (where a = 1) from heapmv; alter table heaptable set access method heap, @@ -343,25 +312,18 @@ create table am_partitioned ( x int, y int ) -partition by HASH(x) using heap2; +partition by hash(x) using heap2; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as refobj + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as refobj from pg_depend, pg_am where pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and - pg_depend.objid = - cast('am_partitioned' as regclass); + pg_depend.objid = cast('am_partitioned' as regclass); drop table am_partitioned; @@ -373,27 +335,20 @@ create table am_partitioned ( x int, y int ) -partition by HASH(x); +partition by hash(x); select relam from pg_class where relname = 'am_partitioned'; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as refobj + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as refobj from pg_depend, pg_am where pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and - pg_depend.objid = - cast('am_partitioned' as regclass); + pg_depend.objid = cast('am_partitioned' as regclass); alter table am_partitioned set access method heap2; @@ -407,22 +362,15 @@ where c.relname = 'am_partitioned' and a.oid = c.relam; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as refobj + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as refobj from pg_depend, pg_am where pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and - pg_depend.objid = - cast('am_partitioned' as regclass); + pg_depend.objid = cast('am_partitioned' as regclass); set local default_table_access_method = heap2; @@ -438,22 +386,15 @@ where c.relname = 'am_partitioned' and a.oid = c.relam; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as refobj + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as refobj from pg_depend, pg_am where pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and - pg_depend.objid = - cast('am_partitioned' as regclass); + pg_depend.objid = cast('am_partitioned' as regclass); set local default_table_access_method = heap2; @@ -477,49 +418,49 @@ select relam from pg_class where relname = 'am_partitioned'; set local default_table_access_method = heap; -create table am_partitioned_0 partition of am_partitioned for values with (MODULUS 10, REMAINDER 0); +create table am_partitioned_0 partition of am_partitioned for values with (modulus 10, remainder 0); set local default_table_access_method = heap2; -create table am_partitioned_1 partition of am_partitioned for values with (MODULUS 10, REMAINDER 1); +create table am_partitioned_1 partition of am_partitioned for values with (modulus 10, remainder 1); set local default_table_access_method = heap; alter table am_partitioned set access method heap2; -create table am_partitioned_2 partition of am_partitioned for values with (MODULUS 10, REMAINDER 2); +create table am_partitioned_2 partition of am_partitioned for values with (modulus 10, remainder 2); alter table am_partitioned set access method default; select relam from pg_class where relname = 'am_partitioned'; -create table am_partitioned_3 partition of am_partitioned for values with (MODULUS 10, REMAINDER 3); +create table am_partitioned_3 partition of am_partitioned for values with (modulus 10, remainder 3); alter table am_partitioned set access method default; create table am_partitioned_5p partition of am_partitioned -for values with (MODULUS 10, REMAINDER 5) -partition by HASH(y); +for values with (modulus 10, remainder 5) +partition by hash(y); create table am_partitioned_5p1 partition of am_partitioned_5p -for values with (MODULUS 10, REMAINDER 1); +for values with (modulus 10, remainder 1); alter table am_partitioned set access method heap2; create table am_partitioned_6p partition of am_partitioned -for values with (MODULUS 10, REMAINDER 6) -partition by HASH(y); +for values with (modulus 10, remainder 6) +partition by hash(y); create table am_partitioned_6p1 partition of am_partitioned_6p -for values with (MODULUS 10, REMAINDER 1); +for values with (modulus 10, remainder 1); select c.relname, @@ -528,8 +469,7 @@ from pg_class as c, pg_am as a where - c.relam = a.oid and - c.relname like 'am_partitioned%' + c.relam = a.oid and c.relname like 'am_partitioned%' union all select c.relname, @@ -560,7 +500,7 @@ create table tableam_parted_heapx ( a text, b int ) -partition by LIST(a); +partition by list(a); create table tableam_parted_1_heapx partition of tableam_parted_heapx for values in ('a', 'b'); @@ -596,10 +536,7 @@ select end) collate "C" as relname from - pg_class as pc - left outer join - pg_am as pa - on pa.oid = pc.relam + pg_class as pc left outer join pg_am as pa on pa.oid = pc.relam where pc.relname like 'tableam_%_heapx' order by 3, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_am_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_am_80.snap index 568c05b15..631b3066e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_am_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_am_80.snap @@ -9,7 +9,7 @@ create access method bogus type index handler int4in; create access method bogus type index handler heap_tableam_handler; -create index "grect2ind2" on fast_emp4000 using gist2 (home_base); +create index grect2ind2 on fast_emp4000 using gist2 (home_base); create operator class box_ops default for type box @@ -26,21 +26,13 @@ create operator class box_ops default operator 10 <<|, operator 11 |>>, operator 12 |&>, - function 1 gist_box_consistent( - internal, - box, - smallint, - oid, - internal), + function 1 gist_box_consistent(internal, box, smallint, oid, internal), function 2 gist_box_union(internal, internal), - function 5 gist_box_penalty( - internal, - internal, - internal), + function 5 gist_box_penalty(internal, internal, internal), function 6 gist_box_picksplit(internal, internal), function 7 gist_box_same(box, box, internal); -create index "grect2ind2" on fast_emp4000 using gist2 (home_base); +create index grect2ind2 on fast_emp4000 using gist2 (home_base); begin; @@ -57,8 +49,7 @@ select from fast_emp4000 where - home_base <@ - cast('(200,200),(2000,1000)' as box) + home_base <@ cast('(200,200),(2000,1000)' as box) order by (home_base[0])[0]; select @@ -66,29 +57,26 @@ select from fast_emp4000 where - home_base <@ - cast('(200,200),(2000,1000)' as box) + home_base <@ cast('(200,200),(2000,1000)' as box) order by (home_base[0])[0]; select - COUNT(*) + count(*) from fast_emp4000 where - home_base && - cast('(1000,1000,0,0)' as box); + home_base && cast('(1000,1000,0,0)' as box); select - COUNT(*) + count(*) from fast_emp4000 where - home_base && - cast('(1000,1000,0,0)' as box); + home_base && cast('(1000,1000,0,0)' as box); -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; rollback; @@ -96,7 +84,7 @@ drop access method gist2; begin; -lock table fast_emp4000 in ACCESS EXCLUSIVE mode; +lock table fast_emp4000 in access exclusive mode; drop access method gist2 cascade; @@ -136,7 +124,7 @@ create table tableam_parted_heap2 ( a text, b int ) -partition by LIST(a) using heap2; +partition by list(a) using heap2; select a.amname @@ -144,8 +132,7 @@ from pg_class as c, pg_am as a where - c.relname = 'tableam_parted_heap2' and - a.oid = c.relam; + c.relname = 'tableam_parted_heap2' and a.oid = c.relam; drop table tableam_parted_heap2; @@ -153,7 +140,7 @@ create table tableam_parted_heap2 ( a text, b int ) -partition by LIST(a); +partition by list(a); set default_table_access_method = heap; @@ -184,8 +171,7 @@ select when relkind = 't' then ( select - 'toast for ' || - cast(relname as regclass) + 'toast for ' || cast(relname as regclass) from pg_class as pcm where @@ -198,25 +184,18 @@ from pg_class as pc, pg_am as pa where - pa.oid = pc.relam and - pa.amname = 'heap2' + pa.oid = pc.relam and pa.amname = 'heap2' order by 3, 1, 2; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj + pg_describe_object(classid, objid, objsubid) as obj from pg_depend, pg_am where - pg_depend.refclassid = - cast('pg_am' as regclass) and + pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and pg_am.amname = 'heap2' order by classid, @@ -225,11 +204,7 @@ order by classid, create table heaptable using heap as - select - a, - repeat(cast(a as text), 100) - from - generate_series(1, 9) as a; + select a, repeat(cast(a as text), 100) from generate_series(1, 9) as a; select amname @@ -237,25 +212,14 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heaptable' as regclass); + c.relam = am.oid and c.oid = cast('heaptable' as regclass); alter table heaptable set access method heap2; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -269,18 +233,8 @@ alter table heaptable set access method heap; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -299,10 +253,9 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heaptable' as regclass); + c.relam = am.oid and c.oid = cast('heaptable' as regclass); -select COUNT(a), COUNT(1) filter (where a = 1) from heaptable; +select count(a), count(1) filter (where a = 1) from heaptable; begin; @@ -317,8 +270,7 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heaptable' as regclass); + c.relam = am.oid and c.oid = cast('heaptable' as regclass); set local default_table_access_method = heap; @@ -331,8 +283,7 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heaptable' as regclass); + c.relam = am.oid and c.oid = cast('heaptable' as regclass); rollback; @@ -344,8 +295,7 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heapmv' as regclass); + c.relam = am.oid and c.oid = cast('heapmv' as regclass); alter materialized view heapmv set access method heap2; @@ -356,10 +306,9 @@ from pg_class as c, pg_am as am where - c.relam = am.oid and - c.oid = cast('heapmv' as regclass); + c.relam = am.oid and c.oid = cast('heapmv' as regclass); -select COUNT(a), COUNT(1) filter (where a = 1) from heapmv; +select count(a), count(1) filter (where a = 1) from heapmv; alter table heaptable set access method heap, @@ -381,30 +330,18 @@ create table am_partitioned ( x int, y int ) -partition by HASH(x) using heap2; +partition by hash(x) using heap2; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as refobj + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as refobj from pg_depend, pg_am where - pg_depend.refclassid = - cast('pg_am' as regclass) and + pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and - pg_depend.objid = - cast('am_partitioned' as regclass); + pg_depend.objid = cast('am_partitioned' as regclass); drop table am_partitioned; @@ -416,32 +353,20 @@ create table am_partitioned ( x int, y int ) -partition by HASH(x); +partition by hash(x); select relam from pg_class where relname = 'am_partitioned'; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as refobj + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as refobj from pg_depend, pg_am where - pg_depend.refclassid = - cast('pg_am' as regclass) and + pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and - pg_depend.objid = - cast('am_partitioned' as regclass); + pg_depend.objid = cast('am_partitioned' as regclass); alter table am_partitioned set access method heap2; @@ -452,31 +377,18 @@ from pg_class as c, pg_am as a where - c.relname = 'am_partitioned' and - a.oid = c.relam; + c.relname = 'am_partitioned' and a.oid = c.relam; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as refobj + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as refobj from pg_depend, pg_am where - pg_depend.refclassid = - cast('pg_am' as regclass) and + pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and - pg_depend.objid = - cast('am_partitioned' as regclass); + pg_depend.objid = cast('am_partitioned' as regclass); set local default_table_access_method = heap2; @@ -489,31 +401,18 @@ from pg_class as c, pg_am as a where - c.relname = 'am_partitioned' and - a.oid = c.relam; + c.relname = 'am_partitioned' and a.oid = c.relam; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as refobj + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as refobj from pg_depend, pg_am where - pg_depend.refclassid = - cast('pg_am' as regclass) and + pg_depend.refclassid = cast('pg_am' as regclass) and pg_am.oid = pg_depend.refobjid and - pg_depend.objid = - cast('am_partitioned' as regclass); + pg_depend.objid = cast('am_partitioned' as regclass); set local default_table_access_method = heap2; @@ -526,8 +425,7 @@ from pg_class as c, pg_am as a where - c.relname = 'am_partitioned' and - a.oid = c.relam; + c.relname = 'am_partitioned' and a.oid = c.relam; alter table am_partitioned set access method default; @@ -540,13 +438,13 @@ set local default_table_access_method = heap; create table am_partitioned_0 partition of am_partitioned -for values with (MODULUS 10, REMAINDER 0); +for values with (modulus 10, remainder 0); set local default_table_access_method = heap2; create table am_partitioned_1 partition of am_partitioned -for values with (MODULUS 10, REMAINDER 1); +for values with (modulus 10, remainder 1); set local default_table_access_method = heap; @@ -555,7 +453,7 @@ alter table am_partitioned create table am_partitioned_2 partition of am_partitioned -for values with (MODULUS 10, REMAINDER 2); +for values with (modulus 10, remainder 2); alter table am_partitioned set access method default; @@ -564,31 +462,31 @@ select relam from pg_class where relname = 'am_partitioned'; create table am_partitioned_3 partition of am_partitioned -for values with (MODULUS 10, REMAINDER 3); +for values with (modulus 10, remainder 3); alter table am_partitioned set access method default; create table am_partitioned_5p partition of am_partitioned -for values with (MODULUS 10, REMAINDER 5) -partition by HASH(y); +for values with (modulus 10, remainder 5) +partition by hash(y); create table am_partitioned_5p1 partition of am_partitioned_5p -for values with (MODULUS 10, REMAINDER 1); +for values with (modulus 10, remainder 1); alter table am_partitioned set access method heap2; create table am_partitioned_6p partition of am_partitioned -for values with (MODULUS 10, REMAINDER 6) -partition by HASH(y); +for values with (modulus 10, remainder 6) +partition by hash(y); create table am_partitioned_6p1 partition of am_partitioned_6p -for values with (MODULUS 10, REMAINDER 1); +for values with (modulus 10, remainder 1); select c.relname, @@ -597,8 +495,7 @@ from pg_class as c, pg_am as a where - c.relam = a.oid and - c.relname like 'am_partitioned%' + c.relam = a.oid and c.relname like 'am_partitioned%' union all select c.relname, @@ -606,8 +503,7 @@ select from pg_class as c where - c.relam = 0 and - c.relname like 'am_partitioned%' + c.relam = 0 and c.relname like 'am_partitioned%' order by 1; drop table am_partitioned; @@ -632,7 +528,7 @@ create table tableam_parted_heapx ( a text, b int ) -partition by LIST(a); +partition by list(a); create table tableam_parted_1_heapx partition of tableam_parted_heapx @@ -660,8 +556,7 @@ select when relkind = 't' then ( select - 'toast for ' || - cast(relname as regclass) + 'toast for ' || cast(relname as regclass) from pg_class as pcm where @@ -671,10 +566,7 @@ select end) collate "C" as relname from - pg_class as pc - left outer join - pg_am as pa - on pa.oid = pc.relam + pg_class as pc left outer join pg_am as pa on pa.oid = pc.relam where pc.relname like 'tableam_%_heapx' order by 3, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_100.snap index ef63e5e05..66847c604 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_100.snap @@ -9,32 +9,26 @@ returns casttesttype language internal immutable strict -as $function$ -textin -$function$; +as 'textin'; create function casttesttype_out(casttesttype) returns cstring language internal immutable strict -as $function$ -textout -$function$; +as 'textout'; create type casttesttype ( internallength = variable, input = casttesttype_in, output = casttesttype_out, - alignment = int + alignment = int4 ); create function casttestfunc(casttesttype) -returns int +returns int4 language sql -as $function$ -SELECT 1; -$function$; +as $$ SELECT 1; $$; select casttestfunc(cast('foo' as text)); @@ -50,47 +44,37 @@ create cast (text as casttesttype) without function as implicit; select casttestfunc(cast('foo' as text)); -select cast(cast(1234 as int) as casttesttype); +select cast(cast(1234 as int4) as casttesttype); -create cast (int as casttesttype) with inout; +create cast (int4 as casttesttype) with inout; -select cast(cast(1234 as int) as casttesttype); +select cast(cast(1234 as int4) as casttesttype); -drop cast (int as casttesttype); +drop cast (int4 as casttesttype); -create function int4_casttesttype(int) +create function int4_casttesttype(int4) returns casttesttype language sql -as $function$ -SELECT ('foo'::text || $1::text)::casttesttype; -$function$; +as $$ SELECT ('foo'::text || $1::text)::casttesttype; $$; -create cast (int as casttesttype) with function int4_casttesttype(int) as implicit; +create cast (int4 as casttesttype) with function int4_casttesttype(int4) as implicit; -select cast(cast(1234 as int) as casttesttype); +select cast(cast(1234 as int4) as casttesttype); -drop function int4_casttesttype(int) cascade; +drop function int4_casttesttype(int4) cascade; -create function bar_int4_text(int) +create function bar_int4_text(int4) returns text language sql -as $function$ -SELECT ('bar'::text || $1::text); -$function$; +as $$ SELECT ('bar'::text || $1::text); $$; -create cast (int as casttesttype) with function bar_int4_text(int) as implicit; +create cast (int4 as casttesttype) with function bar_int4_text(int4) as implicit; -select cast(cast(1234 as int) as casttesttype); +select cast(cast(1234 as int4) as casttesttype); select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -103,7 +87,6 @@ where from pg_cast where - castsource = cast('int4' as regtype) and - casttarget = cast('casttesttype' as regtype) + castsource = cast('int4' as regtype) and casttarget = cast('casttesttype' as regtype) ) order by refclassid; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_80.snap index b85f46257..692efe0a8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_80.snap @@ -9,32 +9,26 @@ returns casttesttype language internal immutable strict -as $function$ -textin -$function$; +as 'textin'; create function casttesttype_out(casttesttype) returns cstring language internal immutable strict -as $function$ -textout -$function$; +as 'textout'; create type casttesttype ( internallength = variable, input = casttesttype_in, output = casttesttype_out, - alignment = int + alignment = int4 ); create function casttestfunc(casttesttype) -returns int +returns int4 language sql -as $function$ -SELECT 1; -$function$; +as $$ SELECT 1; $$; select casttestfunc(cast('foo' as text)); @@ -50,53 +44,41 @@ create cast (text as casttesttype) without function as implicit; select casttestfunc(cast('foo' as text)); -select cast(cast(1234 as int) as casttesttype); +select cast(cast(1234 as int4) as casttesttype); -create cast (int as casttesttype) with inout; +create cast (int4 as casttesttype) with inout; -select cast(cast(1234 as int) as casttesttype); +select cast(cast(1234 as int4) as casttesttype); -drop cast (int as casttesttype); +drop cast (int4 as casttesttype); -create function int4_casttesttype(int) +create function int4_casttesttype(int4) returns casttesttype language sql -as $function$ -SELECT ('foo'::text || $1::text)::casttesttype; -$function$; +as $$ SELECT ('foo'::text || $1::text)::casttesttype; $$; -create cast (int as casttesttype) -with function int4_casttesttype(int) +create cast (int4 as casttesttype) +with function int4_casttesttype(int4) as implicit; -select cast(cast(1234 as int) as casttesttype); +select cast(cast(1234 as int4) as casttesttype); -drop function int4_casttesttype(int) cascade; +drop function int4_casttesttype(int4) cascade; -create function bar_int4_text(int) +create function bar_int4_text(int4) returns text language sql -as $function$ -SELECT ('bar'::text || $1::text); -$function$; +as $$ SELECT ('bar'::text || $1::text); $$; -create cast (int as casttesttype) with function bar_int4_text(int) as implicit; +create cast (int4 as casttesttype) +with function bar_int4_text(int4) +as implicit; -select cast(cast(1234 as int) as casttesttype); +select cast(cast(1234 as int4) as casttesttype); select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -110,7 +92,6 @@ where pg_cast where castsource = cast('int4' as regtype) and - casttarget = - cast('casttesttype' as regtype) + casttarget = cast('casttesttype' as regtype) ) order by refclassid; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_100.snap index fb1159a33..94aa3a361 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_100.snap @@ -7,9 +7,7 @@ load 'regresslib'; create function test1(int) returns int language c -as $function$ -nosuchfile -$function$; +as 'nosuchfile'; create function test1(int) returns int @@ -21,6 +19,4 @@ select regexp_replace('LAST_ERROR_MESSAGE', 'file ".*"', 'file "..."'); create function test1(int) returns int language internal -as $function$ -nosuch -$function$; +as 'nosuch'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_80.snap index fb1159a33..94aa3a361 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_80.snap @@ -7,9 +7,7 @@ load 'regresslib'; create function test1(int) returns int language c -as $function$ -nosuchfile -$function$; +as 'nosuchfile'; create function test1(int) returns int @@ -21,6 +19,4 @@ select regexp_replace('LAST_ERROR_MESSAGE', 'file ".*"', 'file "..."'); create function test1(int) returns int language internal -as $function$ -nosuch -$function$; +as 'nosuch'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_100.snap index 5b0636beb..889e4f874 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_100.snap @@ -4,32 +4,26 @@ input_file: crates/pgls_pretty_print/tests/data/multi/create_function_sql.sql --- create user regress_unpriv_user; -create schema "temp_func_test"; +create schema temp_func_test; grant all on schema temp_func_test to public; set search_path to temp_func_test, public; create function functest_a_1(text, date) -returns boolean +returns bool language sql -as $function$ -SELECT $1 = 'abcd' AND $2 > '2001-01-01' -$function$; +as 'SELECT $1 = ''abcd'' AND $2 > ''2001-01-01'''; create function functest_a_2(text[]) returns int language sql -as $function$ -SELECT $1[1]::int -$function$; +as 'SELECT $1[1]::int'; create function functest_a_3() -returns boolean +returns bool language sql -as $function$ -SELECT false -$function$; +as 'SELECT false'; select proname, @@ -52,35 +46,27 @@ select functest_a_2(array['1', '2', '3']); select functest_a_3(); create function functest_b_1(int) -returns boolean +returns bool language sql -as $function$ -SELECT $1 > 0 -$function$; +as 'SELECT $1 > 0'; create function functest_b_2(int) -returns boolean +returns bool language sql immutable -as $function$ -SELECT $1 > 0 -$function$; +as 'SELECT $1 > 0'; create function functest_b_3(int) -returns boolean +returns bool language sql stable -as $function$ -SELECT $1 = 0 -$function$; +as 'SELECT $1 = 0'; create function functest_b_4(int) -returns boolean +returns bool language sql volatile -as $function$ -SELECT $1 < 0 -$function$; +as 'SELECT $1 < 0'; select proname, @@ -113,27 +99,21 @@ where order by proname; create function functest_c_1(int) -returns boolean +returns bool language sql -as $function$ -SELECT $1 > 0 -$function$; +as 'SELECT $1 > 0'; create function functest_c_2(int) -returns boolean +returns bool language sql security definer -as $function$ -SELECT $1 = 0 -$function$; +as 'SELECT $1 = 0'; create function functest_c_3(int) -returns boolean +returns bool language sql security invoker -as $function$ -SELECT $1 < 0 -$function$; +as 'SELECT $1 < 0'; select proname, @@ -168,19 +148,15 @@ where order by proname; create function functest_e_1(int) -returns boolean +returns bool language sql -as $function$ -SELECT $1 > 100 -$function$; +as 'SELECT $1 > 100'; create function functest_e_2(int) -returns boolean +returns bool language sql leakproof -as $function$ -SELECT $1 > 100 -$function$; +as 'SELECT $1 > 100'; select proname, @@ -188,10 +164,7 @@ select from pg_proc where - oid - in ( - cast('functest_E_1' as regproc), cast('functest_E_2' as regproc) - ) + oid in (cast('functest_E_1' as regproc), cast('functest_E_2' as regproc)) order by proname; alter function functest_e_1(int) leakproof; @@ -204,10 +177,7 @@ select from pg_proc where - oid - in ( - cast('functest_E_1' as regproc), cast('functest_E_2' as regproc) - ) + oid in (cast('functest_E_1' as regproc), cast('functest_E_2' as regproc)) order by proname; alter function functest_e_2(int) not leakproof; @@ -218,10 +188,7 @@ select from pg_proc where - oid - in ( - cast('functest_E_1' as regproc), cast('functest_E_2' as regproc) - ) + oid in (cast('functest_E_1' as regproc), cast('functest_E_2' as regproc)) order by proname; alter function functest_e_1(int) owner to regress_unpriv_user; @@ -237,45 +204,35 @@ alter function functest_e_1(int) not leakproof; alter function functest_e_2(int) leakproof; create function functest_e_3(int) -returns boolean +returns bool language sql leakproof -as $function$ -SELECT $1 < 200 -$function$; +as 'SELECT $1 < 200'; reset session_authorization; create function functest_f_1(int) -returns boolean +returns bool language sql -as $function$ -SELECT $1 > 50 -$function$; +as 'SELECT $1 > 50'; create function functest_f_2(int) -returns boolean +returns bool language sql called on null input -as $function$ -SELECT $1 = 50 -$function$; +as 'SELECT $1 = 50'; create function functest_f_3(int) -returns boolean +returns bool language sql strict -as $function$ -SELECT $1 < 50 -$function$; +as 'SELECT $1 < 50'; create function functest_f_4(int) -returns boolean +returns bool language sql strict -as $function$ -SELECT $1 = 50 -$function$; +as 'SELECT $1 = 50'; select proname, @@ -351,9 +308,7 @@ commit; create function functest_s_xxx(x int) returns int language sql -as $function$ -SELECT x * 2 -$function$ +as $$ SELECT x * 2 $$ return x * 3; create function functest_s_xx(x anyarray) @@ -407,7 +362,7 @@ as select * from functest3; create function functest_s_14() returns bigint -return (select COUNT(*) from functestv3); +return (select count(*) from functestv3); select functest_s_14(); @@ -416,23 +371,17 @@ drop table functest3 cascade; create function functest_is_1(a int, b int default 1, c text default 'foo') returns int language sql -as $function$ -SELECT $1 + $2 -$function$; +as 'SELECT $1 + $2'; create function functest_is_2(out a int, b int default 1) returns int language sql -as $function$ -SELECT $1 -$function$; +as 'SELECT $1'; create function functest_is_3(a int default 1, out b int) returns int language sql -as $function$ -SELECT $1 -$function$; +as 'SELECT $1'; select routine_name, @@ -444,11 +393,10 @@ from inner join information_schema.routines using ( - "specific_schema", - "specific_name") + specific_schema, + specific_name) where - routine_schema = 'temp_func_test' and - routine_name ~ '^functest_is_' + routine_schema = 'temp_func_test' and routine_name ~ '^functest_is_' order by 1, 2; @@ -457,25 +405,19 @@ drop function functest_is_1(int, int, text), functest_is_2(int), functest_is_3(i create function functest_is_4a() returns int language sql -as $function$ -SELECT 1 -$function$; +as 'SELECT 1'; create function functest_is_4b(x int default functest_is_4a()) returns int language sql -as $function$ -SELECT x -$function$; +as 'SELECT x'; create sequence functest1; create function functest_is_5(x int default nextval('functest1')) returns int language sql -as $function$ -SELECT x -$function$; +as 'SELECT x'; create function functest_is_6() returns int @@ -490,7 +432,7 @@ create table functest2 ( create function functest_is_7() returns int language sql -return (select COUNT(a) from functest2); +return (select count(a) from functest2); select r0.routine_name, @@ -504,8 +446,7 @@ from information_schema.routines as r1 on r1.specific_name = rru.routine_name where - r0.routine_schema = 'temp_func_test' and - r1.routine_schema = 'temp_func_test' + r0.routine_schema = 'temp_func_test' and r1.routine_schema = 'temp_func_test' order by 1, 2; @@ -547,12 +488,10 @@ drop sequence functest1 cascade; drop table functest2 cascade; create function functest_b_2(bigint) -returns boolean +returns bool language sql immutable -as $function$ -SELECT $1 > 0 -$function$; +as 'SELECT $1 > 0'; drop function functest_b_1; @@ -563,32 +502,24 @@ drop function functest_b_2; create function functest1(a int) returns int language sql -as $function$ -SELECT $1 -$function$; +as 'SELECT $1'; create or replace function functest1(a int) returns int language sql window -as $function$ -SELECT $1 -$function$; +as 'SELECT $1'; create or replace procedure functest1(a int) language sql -as $procedure$ -SELECT $1 -$procedure$; +as 'SELECT $1'; -drop function functest1(int); +drop function functest1(a int); create function functest_srf0() returns setof int language sql -as $function$ -SELECT i FROM generate_series(1, 100) i -$function$; +as $$ SELECT i FROM generate_series(1, 100) i $$; select functest_srf0() limit 5; @@ -600,9 +531,9 @@ create function functest_sri1() returns setof int language sql stable -as $function$ -SELECT * FROM functest3; -$function$; +as ' + SELECT * FROM functest3; +'; select * from functest_sri1(); @@ -621,18 +552,14 @@ drop table functest3 cascade; create function voidtest1(a int) returns void language sql -as $function$ -SELECT a + 1 -$function$; +as $$ SELECT a + 1 $$; select voidtest1(42); create function voidtest2(a int, b int) returns void language sql -as $function$ -SELECT voidtest1(a + b) -$function$; +as $$ SELECT voidtest1(a + b) $$; select voidtest2(11, 22); @@ -643,18 +570,14 @@ create temporary table sometable (f1 int); create function voidtest3(a int) returns void language sql -as $function$ -INSERT INTO sometable VALUES(a + 1) -$function$; +as $$ INSERT INTO sometable VALUES(a + 1) $$; select voidtest3(17); create function voidtest4(a int) returns void language sql -as $function$ -INSERT INTO sometable VALUES(a - 1) RETURNING f1 -$function$; +as $$ INSERT INTO sometable VALUES(a - 1) RETURNING f1 $$; select voidtest4(39); @@ -664,9 +587,7 @@ create function voidtest5(a int) returns setof void language sql stable -as $function$ -SELECT generate_series(1, a) -$function$; +as $$ SELECT generate_series(1, a) $$; select * from voidtest5(3); @@ -675,10 +596,10 @@ set check_function_bodies = off; create function create_and_insert() returns void language sql -as $function$ -create table ddl_test (f1 int); +as $$ + create table ddl_test (f1 int); insert into ddl_test values (1.2); -$function$; +$$; select create_and_insert(); @@ -687,10 +608,10 @@ select * from ddl_test; create function alter_and_insert() returns void language sql -as $function$ -alter table ddl_test alter column f1 type numeric; +as $$ + alter table ddl_test alter column f1 type numeric; insert into ddl_test values (1.2); -$function$; +$$; select alter_and_insert(); @@ -702,34 +623,30 @@ create function double_append(anyarray, anyelement) returns setof anyarray language sql immutable -as $function$ -SELECT array_append($1, $2) || array_append($1, $2) -$function$; +as $$ SELECT array_append($1, $2) || array_append($1, $2) $$; select double_append(array_append(array[q1], q2), q3) from (values (1, 2, 3), (4, 5, 6)) as v (q1, q2, q3); -create function part_hashint4_error(value int, seed bigint) -returns bigint +create function part_hashint4_error(value int4, seed int8) +returns int8 language sql immutable strict -parallel SAFE -as $function$ -SELECT value + seed + random()::int/0 -$function$; +parallel safe +as $$ SELECT value + seed + random()::int/0 $$; create operator class part_test_int4_ops_bad - for type int + for type int4 using hash - as function 2 part_hashint4_error(int, bigint); + as function 2 part_hashint4_error(int4, int8); create table pt (i int) -partition by HASH(i part_test_int4_ops_bad); +partition by hash(i part_test_int4_ops_bad); -create table p1 partition of pt for values with (MODULUS 4, REMAINDER 0); +create table p1 partition of pt for values with (modulus 4, remainder 0); insert into pt values (1); @@ -738,30 +655,22 @@ insert into pt values (1); create function test1(int) returns int language sql -as $function$ -SELECT 'not an integer'; -$function$; +as 'SELECT ''not an integer'';'; create function test1(int) returns int language sql -as $function$ -not even SQL -$function$; +as 'not even SQL'; create function test1(int) returns int language sql -as $function$ -SELECT 1, 2, 3; -$function$; +as 'SELECT 1, 2, 3;'; create function test1(int) returns int language sql -as $function$ -SELECT $2; -$function$; +as 'SELECT $2;'; create function test1(int) returns int @@ -771,18 +680,14 @@ as 'a', 'b'; create function test1(int) returns int language sql -as $function$ - -$function$; +as ''; set check_function_bodies = off; create function test1(anyelement) returns anyarray language sql -as $function$ - -$function$; +as ''; select test1(0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_80.snap index 90f6edc99..a45693e58 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_80.snap @@ -4,32 +4,26 @@ input_file: crates/pgls_pretty_print/tests/data/multi/create_function_sql.sql --- create user regress_unpriv_user; -create schema "temp_func_test"; +create schema temp_func_test; grant all on schema temp_func_test to public; set search_path to temp_func_test, public; create function functest_a_1(text, date) -returns boolean +returns bool language sql -as $function$ -SELECT $1 = 'abcd' AND $2 > '2001-01-01' -$function$; +as 'SELECT $1 = ''abcd'' AND $2 > ''2001-01-01'''; create function functest_a_2(text[]) returns int language sql -as $function$ -SELECT $1[1]::int -$function$; +as 'SELECT $1[1]::int'; create function functest_a_3() -returns boolean +returns bool language sql -as $function$ -SELECT false -$function$; +as 'SELECT false'; select proname, @@ -52,35 +46,27 @@ select functest_a_2(array['1', '2', '3']); select functest_a_3(); create function functest_b_1(int) -returns boolean +returns bool language sql -as $function$ -SELECT $1 > 0 -$function$; +as 'SELECT $1 > 0'; create function functest_b_2(int) -returns boolean +returns bool language sql immutable -as $function$ -SELECT $1 > 0 -$function$; +as 'SELECT $1 > 0'; create function functest_b_3(int) -returns boolean +returns bool language sql stable -as $function$ -SELECT $1 = 0 -$function$; +as 'SELECT $1 = 0'; create function functest_b_4(int) -returns boolean +returns bool language sql volatile -as $function$ -SELECT $1 < 0 -$function$; +as 'SELECT $1 < 0'; select proname, @@ -113,27 +99,21 @@ where order by proname; create function functest_c_1(int) -returns boolean +returns bool language sql -as $function$ -SELECT $1 > 0 -$function$; +as 'SELECT $1 > 0'; create function functest_c_2(int) -returns boolean +returns bool language sql security definer -as $function$ -SELECT $1 = 0 -$function$; +as 'SELECT $1 = 0'; create function functest_c_3(int) -returns boolean +returns bool language sql security invoker -as $function$ -SELECT $1 < 0 -$function$; +as 'SELECT $1 < 0'; select proname, @@ -168,19 +148,15 @@ where order by proname; create function functest_e_1(int) -returns boolean +returns bool language sql -as $function$ -SELECT $1 > 100 -$function$; +as 'SELECT $1 > 100'; create function functest_e_2(int) -returns boolean +returns bool language sql leakproof -as $function$ -SELECT $1 > 100 -$function$; +as 'SELECT $1 > 100'; select proname, @@ -188,10 +164,7 @@ select from pg_proc where - oid - in ( - cast('functest_E_1' as regproc), cast('functest_E_2' as regproc) - ) + oid in (cast('functest_E_1' as regproc), cast('functest_E_2' as regproc)) order by proname; alter function functest_e_1(int) leakproof; @@ -204,10 +177,7 @@ select from pg_proc where - oid - in ( - cast('functest_E_1' as regproc), cast('functest_E_2' as regproc) - ) + oid in (cast('functest_E_1' as regproc), cast('functest_E_2' as regproc)) order by proname; alter function functest_e_2(int) not leakproof; @@ -218,10 +188,7 @@ select from pg_proc where - oid - in ( - cast('functest_E_1' as regproc), cast('functest_E_2' as regproc) - ) + oid in (cast('functest_E_1' as regproc), cast('functest_E_2' as regproc)) order by proname; alter function functest_e_1(int) owner to regress_unpriv_user; @@ -237,45 +204,35 @@ alter function functest_e_1(int) not leakproof; alter function functest_e_2(int) leakproof; create function functest_e_3(int) -returns boolean +returns bool language sql leakproof -as $function$ -SELECT $1 < 200 -$function$; +as 'SELECT $1 < 200'; reset session_authorization; create function functest_f_1(int) -returns boolean +returns bool language sql -as $function$ -SELECT $1 > 50 -$function$; +as 'SELECT $1 > 50'; create function functest_f_2(int) -returns boolean +returns bool language sql called on null input -as $function$ -SELECT $1 = 50 -$function$; +as 'SELECT $1 = 50'; create function functest_f_3(int) -returns boolean +returns bool language sql strict -as $function$ -SELECT $1 < 50 -$function$; +as 'SELECT $1 < 50'; create function functest_f_4(int) -returns boolean +returns bool language sql strict -as $function$ -SELECT $1 = 50 -$function$; +as 'SELECT $1 = 50'; select proname, @@ -351,9 +308,7 @@ commit; create function functest_s_xxx(x int) returns int language sql -as $function$ -SELECT x * 2 -$function$ +as $$ SELECT x * 2 $$ return x * 3; create function functest_s_xx(x anyarray) @@ -407,7 +362,7 @@ as select * from functest3; create function functest_s_14() returns bigint -return (select COUNT(*) from functestv3); +return (select count(*) from functestv3); select functest_s_14(); @@ -416,23 +371,17 @@ drop table functest3 cascade; create function functest_is_1(a int, b int default 1, c text default 'foo') returns int language sql -as $function$ -SELECT $1 + $2 -$function$; +as 'SELECT $1 + $2'; create function functest_is_2(out a int, b int default 1) returns int language sql -as $function$ -SELECT $1 -$function$; +as 'SELECT $1'; create function functest_is_3(a int default 1, out b int) returns int language sql -as $function$ -SELECT $1 -$function$; +as 'SELECT $1'; select routine_name, @@ -444,11 +393,10 @@ from inner join information_schema.routines using ( - "specific_schema", - "specific_name") + specific_schema, + specific_name) where - routine_schema = 'temp_func_test' and - routine_name ~ '^functest_is_' + routine_schema = 'temp_func_test' and routine_name ~ '^functest_is_' order by 1, 2; @@ -460,25 +408,19 @@ drop function create function functest_is_4a() returns int language sql -as $function$ -SELECT 1 -$function$; +as 'SELECT 1'; create function functest_is_4b(x int default functest_is_4a()) returns int language sql -as $function$ -SELECT x -$function$; +as 'SELECT x'; create sequence functest1; create function functest_is_5(x int default nextval('functest1')) returns int language sql -as $function$ -SELECT x -$function$; +as 'SELECT x'; create function functest_is_6() returns int @@ -493,14 +435,13 @@ create table functest2 ( create function functest_is_7() returns int language sql -return (select COUNT(a) from functest2); +return (select count(a) from functest2); select r0.routine_name, r1.routine_name from - information_schema.routine_routine_usage - as rru + information_schema.routine_routine_usage as rru inner join information_schema.routines as r0 on r0.specific_name = rru.specific_name @@ -508,8 +449,7 @@ from information_schema.routines as r1 on r1.specific_name = rru.routine_name where - r0.routine_schema = 'temp_func_test' and - r1.routine_schema = 'temp_func_test' + r0.routine_schema = 'temp_func_test' and r1.routine_schema = 'temp_func_test' order by 1, 2; @@ -551,12 +491,10 @@ drop sequence functest1 cascade; drop table functest2 cascade; create function functest_b_2(bigint) -returns boolean +returns bool language sql immutable -as $function$ -SELECT $1 > 0 -$function$; +as 'SELECT $1 > 0'; drop function functest_b_1; @@ -567,32 +505,24 @@ drop function functest_b_2; create function functest1(a int) returns int language sql -as $function$ -SELECT $1 -$function$; +as 'SELECT $1'; create or replace function functest1(a int) returns int language sql window -as $function$ -SELECT $1 -$function$; +as 'SELECT $1'; create or replace procedure functest1(a int) language sql -as $procedure$ -SELECT $1 -$procedure$; +as 'SELECT $1'; -drop function functest1(int); +drop function functest1(a int); create function functest_srf0() returns setof int language sql -as $function$ -SELECT i FROM generate_series(1, 100) i -$function$; +as $$ SELECT i FROM generate_series(1, 100) i $$; select functest_srf0() limit 5; @@ -604,9 +534,9 @@ create function functest_sri1() returns setof int language sql stable -as $function$ -SELECT * FROM functest3; -$function$; +as ' + SELECT * FROM functest3; +'; select * from functest_sri1(); @@ -625,18 +555,14 @@ drop table functest3 cascade; create function voidtest1(a int) returns void language sql -as $function$ -SELECT a + 1 -$function$; +as $$ SELECT a + 1 $$; select voidtest1(42); create function voidtest2(a int, b int) returns void language sql -as $function$ -SELECT voidtest1(a + b) -$function$; +as $$ SELECT voidtest1(a + b) $$; select voidtest2(11, 22); @@ -647,18 +573,14 @@ create temporary table sometable (f1 int); create function voidtest3(a int) returns void language sql -as $function$ -INSERT INTO sometable VALUES(a + 1) -$function$; +as $$ INSERT INTO sometable VALUES(a + 1) $$; select voidtest3(17); create function voidtest4(a int) returns void language sql -as $function$ -INSERT INTO sometable VALUES(a - 1) RETURNING f1 -$function$; +as $$ INSERT INTO sometable VALUES(a - 1) RETURNING f1 $$; select voidtest4(39); @@ -668,9 +590,7 @@ create function voidtest5(a int) returns setof void language sql stable -as $function$ -SELECT generate_series(1, a) -$function$; +as $$ SELECT generate_series(1, a) $$; select * from voidtest5(3); @@ -679,10 +599,10 @@ set check_function_bodies = off; create function create_and_insert() returns void language sql -as $function$ -create table ddl_test (f1 int); +as $$ + create table ddl_test (f1 int); insert into ddl_test values (1.2); -$function$; +$$; select create_and_insert(); @@ -691,10 +611,10 @@ select * from ddl_test; create function alter_and_insert() returns void language sql -as $function$ -alter table ddl_test alter column f1 type numeric; +as $$ + alter table ddl_test alter column f1 type numeric; insert into ddl_test values (1.2); -$function$; +$$; select alter_and_insert(); @@ -706,40 +626,30 @@ create function double_append(anyarray, anyelement) returns setof anyarray language sql immutable -as $function$ -SELECT array_append($1, $2) || array_append($1, $2) -$function$; +as $$ SELECT array_append($1, $2) || array_append($1, $2) $$; select - double_append( - array_append(array[q1], q2), - q3 - ) + double_append(array_append(array[q1], q2), q3) from - ( - values (1, 2, 3), (4, 5, 6) - ) - as v (q1, q2, q3); + (values (1, 2, 3), (4, 5, 6)) as v (q1, q2, q3); -create function part_hashint4_error(value int, seed bigint) -returns bigint +create function part_hashint4_error(value int4, seed int8) +returns int8 language sql immutable strict -parallel SAFE -as $function$ -SELECT value + seed + random()::int/0 -$function$; +parallel safe +as $$ SELECT value + seed + random()::int/0 $$; create operator class part_test_int4_ops_bad - for type int + for type int4 using hash - as function 2 part_hashint4_error(int, bigint); + as function 2 part_hashint4_error(int4, int8); create table pt (i int) -partition by HASH(i part_test_int4_ops_bad); +partition by hash(i part_test_int4_ops_bad); -create table p1 partition of pt for values with (MODULUS 4, REMAINDER 0); +create table p1 partition of pt for values with (modulus 4, remainder 0); insert into pt values (1); @@ -748,30 +658,22 @@ insert into pt values (1); create function test1(int) returns int language sql -as $function$ -SELECT 'not an integer'; -$function$; +as 'SELECT ''not an integer'';'; create function test1(int) returns int language sql -as $function$ -not even SQL -$function$; +as 'not even SQL'; create function test1(int) returns int language sql -as $function$ -SELECT 1, 2, 3; -$function$; +as 'SELECT 1, 2, 3;'; create function test1(int) returns int language sql -as $function$ -SELECT $2; -$function$; +as 'SELECT $2;'; create function test1(int) returns int @@ -781,18 +683,14 @@ as 'a', 'b'; create function test1(int) returns int language sql -as $function$ - -$function$; +as ''; set check_function_bodies = off; create function test1(anyelement) returns anyarray language sql -as $function$ - -$function$; +as ''; select test1(0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_100.snap index 4560c11f8..e77afc50c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_100.snap @@ -2,35 +2,35 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/create_index.sql --- -create index "onek_unique1" on onek using btree (unique1 int4_ops); +create index onek_unique1 on onek using btree (unique1 int4_ops); -create index if not exists "onek_unique1" on onek using btree (unique1 int4_ops); +create index if not exists onek_unique1 on onek using btree (unique1 int4_ops); -create index "onek_unique2" on onek using btree (unique2 int4_ops); +create index onek_unique2 on onek using btree (unique2 int4_ops); -create index "onek_hundred" on onek using btree (hundred int4_ops); +create index onek_hundred on onek using btree (hundred int4_ops); -create index "onek_stringu1" on onek using btree (stringu1 name_ops); +create index onek_stringu1 on onek using btree (stringu1 name_ops); -create index "tenk1_unique1" on tenk1 using btree (unique1 int4_ops); +create index tenk1_unique1 on tenk1 using btree (unique1 int4_ops); -create index "tenk1_unique2" on tenk1 using btree (unique2 int4_ops); +create index tenk1_unique2 on tenk1 using btree (unique2 int4_ops); -create index "tenk1_hundred" on tenk1 using btree (hundred int4_ops); +create index tenk1_hundred on tenk1 using btree (hundred int4_ops); -create index "tenk1_thous_tenthous" on tenk1 using btree (thousand, tenthous); +create index tenk1_thous_tenthous on tenk1 using btree (thousand, tenthous); -create index "tenk2_unique1" on tenk2 using btree (unique1 int4_ops); +create index tenk2_unique1 on tenk2 using btree (unique1 int4_ops); -create index "tenk2_unique2" on tenk2 using btree (unique2 int4_ops); +create index tenk2_unique2 on tenk2 using btree (unique2 int4_ops); -create index "tenk2_hundred" on tenk2 using btree (hundred int4_ops); +create index tenk2_hundred on tenk2 using btree (hundred int4_ops); -create index "rix" on road using btree (name text_ops); +create index rix on road using btree (name text_ops); -create index "iix" on ihighway using btree (name text_ops); +create index iix on ihighway using btree (name text_ops); -create index "six" on shighway using btree (name text_ops); +create index six on shighway using btree (name text_ops); comment on index six_wrong is 'bad index'; @@ -38,32 +38,13 @@ comment on index six is 'good index'; comment on index six is null; -create index "onek2_u1_prtl" -on onek2 -using btree -( - unique1 int4_ops -) -where - unique1 < 20 or unique1 > 980; +create index onek2_u1_prtl on onek2 using btree (unique1 int4_ops) +where unique1 < 20 or unique1 > 980; -create index "onek2_u2_prtl" -on onek2 -using btree -( - unique2 int4_ops -) -where - stringu1 < 'B'; +create index onek2_u2_prtl on onek2 using btree (unique2 int4_ops) where stringu1 < 'B'; -create index "onek2_stu1_prtl" -on onek2 -using btree -( - stringu1 name_ops -) -where - onek2.stringu1 >= 'J' and onek2.stringu1 < 'K'; +create index onek2_stu1_prtl on onek2 using btree (stringu1 name_ops) +where onek2.stringu1 >= 'J' and onek2.stringu1 < 'K'; create table slow_emp4000 (home_base box); @@ -77,13 +58,13 @@ analyze slow_emp4000; analyze fast_emp4000; -create index "grect2ind" on fast_emp4000 using gist (home_base); +create index grect2ind on fast_emp4000 using gist (home_base); create temporary table point_tbl as select * from public.point_tbl; insert into point_tbl (f1) values (null); -create index "gpointind" on point_tbl using gist (f1); +create index gpointind on point_tbl using gist (f1); create temporary table gpolygon_tbl as select polygon(home_base) as f1 from slow_emp4000; @@ -93,9 +74,9 @@ insert into gpolygon_tbl values ('(0,1000,1000,1000)'); create temporary table gcircle_tbl as select circle(home_base) as f1 from slow_emp4000; -create index "ggpolygonind" on gpolygon_tbl using gist (f1); +create index ggpolygonind on gpolygon_tbl using gist (f1); -create index "ggcircleind" on gcircle_tbl using gist (f1); +create index ggcircleind on gcircle_tbl using gist (f1); set enable_seqscan = 'on'; @@ -111,38 +92,36 @@ where home_base <@ cast('(200,200),(2000,1000)' as box) order by (home_base[0])[0]; -select COUNT(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); +select count(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; -select COUNT(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); +select count(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); -select COUNT(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); +select count(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); -select COUNT(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); +select count(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); -select COUNT(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; +select count(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; select - COUNT(*) + count(*) from point_tbl where - f1 <@ - cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' - as polygon); + f1 <@ cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' as polygon); -select COUNT(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); +select count(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); -select COUNT(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; +select count(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; select * from point_tbl order by f1 <-> '0,1'; @@ -184,71 +163,67 @@ where home_base <@ cast('(200,200),(2000,1000)' as box) order by (home_base[0])[0]; -select COUNT(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); +select count(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); -select COUNT(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); +select count(*) from fast_emp4000 where home_base && cast('(1000,1000,0,0)' as box); -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; -select COUNT(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); +select count(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); -select COUNT(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); +select count(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); -select COUNT(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); +select count(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); -select COUNT(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); +select count(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); -select COUNT(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); +select count(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); -select COUNT(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); +select count(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); -select COUNT(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; +select count(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; -select COUNT(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; +select count(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; select - COUNT(*) + count(*) from point_tbl where - f1 <@ - cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' - as polygon); + f1 <@ cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' as polygon); select - COUNT(*) + count(*) from point_tbl where - f1 <@ - cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' - as polygon); + f1 <@ cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' as polygon); -select COUNT(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); +select count(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); -select COUNT(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); +select count(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); -select COUNT(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; +select count(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; -select COUNT(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; +select count(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; select * from point_tbl order by f1 <-> '0,1'; @@ -288,29 +263,13 @@ limit 10; select point(x, x), - ( - select - f1 - from - gpolygon_tbl - order by f1 <-> point(x, x) - limit 1 - ) - as c + (select f1 from gpolygon_tbl order by f1 <-> point(x, x) limit 1) as c from generate_series(0, 10, 1) as x; select point(x, x), - ( - select - f1 - from - gpolygon_tbl - order by f1 <-> point(x, x) - limit 1 - ) - as c + (select f1 from gpolygon_tbl order by f1 <-> point(x, x) limit 1) as c from generate_series(0, 10, 1) as x; @@ -331,8 +290,8 @@ reset enable_indexscan; reset enable_bitmapscan; create table array_index_op_test ( - seqno int, - i int[], + seqno int4, + i int4[], t text[] ); @@ -354,7 +313,7 @@ set enable_indexscan = off; set enable_bitmapscan = 'on'; -create index "intarrayidx" on array_index_op_test using gin (i); +create index intarrayidx on array_index_op_test using gin (i); select * from array_index_op_test where i @> '{32}' order by seqno; @@ -382,7 +341,7 @@ select * from array_index_op_test where i && '{}' order by seqno; select * from array_index_op_test where i <@ '{}' order by seqno; -create index "textarrayidx" on array_index_op_test using gin (t); +create index textarrayidx on array_index_op_test using gin (t); select * from array_index_op_test where t @> '{AAAAAAAA72908}' order by seqno; @@ -419,7 +378,7 @@ select * from array_index_op_test where t <@ '{}' order by seqno; drop index intarrayidx, textarrayidx; -create index "botharrayidx" on array_index_op_test using gin (i, t); +create index botharrayidx on array_index_op_test using gin (i, t); select * from array_index_op_test where i @> '{32}' order by seqno; @@ -445,44 +404,32 @@ create table array_gin_test (a int[]); insert into array_gin_test select array[1, g % 5, g] from generate_series(1, 10000) as g; -create index "array_gin_test_idx" on array_gin_test using gin (a); +create index array_gin_test_idx on array_gin_test using gin (a); -select COUNT(*) from array_gin_test where a @> '{2}'; +select count(*) from array_gin_test where a @> '{2}'; drop table array_gin_test; -create index "gin_relopts_test" -on array_index_op_test -using gin -( - i -) -with (fastupdate = 'on', -gin_pending_list_limit = 128); +create index gin_relopts_test on array_index_op_test using gin (i) +with (fastupdate = 'on', gin_pending_list_limit = 128); -create unlogged table unlogged_hash_table (id int); +create unlogged table unlogged_hash_table (id int4); -create index "unlogged_hash_index" on unlogged_hash_table using hash (id int4_ops); +create index unlogged_hash_index on unlogged_hash_table using hash (id int4_ops); drop table unlogged_hash_table; set maintenance_work_mem = '1MB'; -create index "hash_tuplesort_idx" -on tenk1 -using hash -( - stringu1 name_ops -) -with (fillfactor = 10); +create index hash_tuplesort_idx on tenk1 using hash (stringu1 name_ops) with (fillfactor = 10); -select COUNT(*) from tenk1 where stringu1 = 'TVAAAA'; +select count(*) from tenk1 where stringu1 = 'TVAAAA'; -select COUNT(*) from tenk1 where stringu1 = 'TVAAAA'; +select count(*) from tenk1 where stringu1 = 'TVAAAA'; set enable_seqscan = off; -select COUNT(*) from tenk1 where stringu1 = 'TVAAAA' or stringu1 = 'TVAAAB'; +select count(*) from tenk1 where stringu1 = 'TVAAAA' or stringu1 = 'TVAAAB'; reset enable_seqscan; @@ -495,9 +442,9 @@ create table unique_tbl ( t text ); -create unique index "unique_idx1" on unique_tbl using btree (i); +create unique index unique_idx1 on unique_tbl using btree (i); -create unique index "unique_idx2" on unique_tbl using btree (i) nulls not distinct; +create unique index unique_idx2 on unique_tbl using btree (i) nulls not distinct; insert into unique_tbl values (1, 'one'); @@ -517,13 +464,13 @@ drop index unique_idx1, unique_idx2; insert into unique_tbl (t) values ('seven'); -create unique index "unique_idx3" on unique_tbl using btree (i); +create unique index unique_idx3 on unique_tbl using btree (i); -create unique index "unique_idx4" on unique_tbl using btree (i) nulls not distinct; +create unique index unique_idx4 on unique_tbl using btree (i) nulls not distinct; delete from unique_tbl where t = 'seven'; -create unique index "unique_idx4" on unique_tbl using btree (i) nulls not distinct; +create unique index unique_idx4 on unique_tbl using btree (i) nulls not distinct; select pg_get_indexdef(cast('unique_idx3' as regclass)); @@ -536,7 +483,7 @@ create table func_index_heap ( f2 text ); -create unique index "func_index_index" on func_index_heap using btree ((textcat(f1, f2))); +create unique index func_index_index on func_index_heap using btree ((textcat(f1, f2))); insert into func_index_heap values ('ABC', 'DEF'); @@ -555,7 +502,7 @@ create table func_index_heap ( f2 text ); -create unique index "func_index_index" on func_index_heap using btree ((f1 || f2) text_ops); +create unique index func_index_index on func_index_heap using btree ((f1 || f2) text_ops); insert into func_index_heap values ('ABC', 'DEF'); @@ -575,7 +522,7 @@ create table covering_index_heap ( f3 text ); -create unique index "covering_index_index" on covering_index_heap using btree (f1, f2) include (f3); +create unique index covering_index_index on covering_index_heap using btree (f1, f2) include (f3); insert into covering_index_heap values (1, 1, 'AAA'); @@ -585,10 +532,10 @@ insert into covering_index_heap values (1, 2, 'BBB'); insert into covering_index_heap values (1, 4, 'AAA'); -create unique index "covering_pkey" on covering_index_heap using btree (f1, f2) include (f3); +create unique index covering_pkey on covering_index_heap using btree (f1, f2) include (f3); alter table covering_index_heap - add constraint "covering_pkey" primary key using index "covering_pkey"; + add constraint covering_pkey primary key using index covering_pkey; drop table covering_index_heap; @@ -597,67 +544,45 @@ create table concur_heap ( f2 text ); -create index concurrently "concur_index1" on concur_heap using btree (f2, f1); +create index concurrently concur_index1 on concur_heap using btree (f2, f1); -create index concurrently if not exists "concur_index1" on concur_heap using btree (f2, f1); +create index concurrently if not exists concur_index1 on concur_heap using btree (f2, f1); insert into concur_heap values ('a', 'b'); insert into concur_heap values ('b', 'b'); -create unique index concurrently "concur_index2" on concur_heap using btree (f1); +create unique index concurrently concur_index2 on concur_heap using btree (f1); -create unique index concurrently if not exists "concur_index2" on concur_heap using btree (f1); +create unique index concurrently if not exists concur_index2 on concur_heap using btree (f1); insert into concur_heap values ('b', 'x'); -create unique index concurrently "concur_index3" on concur_heap using btree (f2); +create unique index concurrently concur_index3 on concur_heap using btree (f2); -create index concurrently "concur_index4" -on concur_heap -using btree -( - f2 -) -where - f1 = 'a'; +create index concurrently concur_index4 on concur_heap using btree (f2) where f1 = 'a'; -create index concurrently "concur_index5" -on concur_heap -using btree -( - f2 -) -where - f1 = 'x'; +create index concurrently concur_index5 on concur_heap using btree (f2) where f1 = 'x'; create index concurrently on concur_heap using btree ((f2 || f1)); begin; -create index concurrently "concur_index7" on concur_heap using btree (f1); +create index concurrently concur_index7 on concur_heap using btree (f1); commit; create function predicate_stable() -returns boolean +returns bool language plpgsql immutable -as $function$ +as $$ BEGIN EXECUTE 'SELECT txid_current()'; RETURN true; -END; -$function$; - -create index concurrently "concur_index8" -on concur_heap -using btree -( - f1 -) -where - predicate_stable(); +END; $$; + +create index concurrently concur_index8 on concur_heap using btree (f1) where predicate_stable(); drop index concur_index8; @@ -665,17 +590,17 @@ drop function predicate_stable(); begin; -create index "std_index" on concur_heap using btree (f2); +create index std_index on concur_heap using btree (f2); commit; -vacuum (FULL) concur_heap; +vacuum (full) concur_heap; reindex table concur_heap; delete from concur_heap where f1 = 'b'; -vacuum (FULL) concur_heap; +vacuum (full) concur_heap; reindex table concur_heap; @@ -687,7 +612,7 @@ on commit preserve rows; insert into concur_temp values (1, 'foo'), (2, 'bar'); -create index concurrently "concur_temp_ind" on concur_temp using btree (f1); +create index concurrently concur_temp_ind on concur_temp using btree (f1); drop index concurrently concur_temp_ind; @@ -703,13 +628,13 @@ on commit drop; insert into concur_temp values (1, 'foo'), (2, 'bar'); -create index concurrently "concur_temp_ind" on concur_temp using btree (f1); +create index concurrently concur_temp_ind on concur_temp using btree (f1); commit; insert into concur_temp values (1, 'foo'), (2, 'bar'); -create index concurrently "concur_temp_ind" on concur_temp using btree (f1); +create index concurrently concur_temp_ind on concur_temp using btree (f1); drop index concurrently concur_temp_ind; @@ -747,38 +672,38 @@ create table cwi_test ( insert into cwi_test values (1, 2), (3, 4), (5, 6); -create unique index "cwi_uniq_idx" on cwi_test using btree (a, b); +create unique index cwi_uniq_idx on cwi_test using btree (a, b); alter table cwi_test - add primary key using index "cwi_uniq_idx"; + add primary key using index cwi_uniq_idx; -create unique index "cwi_uniq2_idx" on cwi_test using btree (b, a); +create unique index cwi_uniq2_idx on cwi_test using btree (b, a); alter table cwi_test drop constraint cwi_uniq_idx, - add constraint "cwi_replaced_pkey" primary key using index "cwi_uniq2_idx"; + add constraint cwi_replaced_pkey primary key using index cwi_uniq2_idx; drop index cwi_replaced_pkey; -create unique index "cwi_uniq3_idx" on cwi_test using btree (a desc); +create unique index cwi_uniq3_idx on cwi_test using btree (a desc); alter table cwi_test - add unique using index "cwi_uniq3_idx"; + add unique using index cwi_uniq3_idx; -create unique index "cwi_uniq4_idx" on cwi_test using btree (b collate "POSIX"); +create unique index cwi_uniq4_idx on cwi_test using btree (b collate "POSIX"); alter table cwi_test - add unique using index "cwi_uniq4_idx"; + add unique using index cwi_uniq4_idx; drop table cwi_test; create table cwi_test (a int) -partition by HASH(a); +partition by hash(a); create unique index on cwi_test using btree (a); alter table cwi_test - add primary key using index "cwi_test_a_idx"; + add primary key using index cwi_test_a_idx; drop table cwi_test; @@ -787,10 +712,10 @@ create table cwi_test ( b int ); -create unique index "cwi_a_nnd" on cwi_test using btree (a) nulls not distinct; +create unique index cwi_a_nnd on cwi_test using btree (a) nulls not distinct; alter table cwi_test - add primary key using index "cwi_a_nnd"; + add primary key using index cwi_a_nnd; drop table cwi_test; @@ -800,28 +725,16 @@ create index on syscol_table using btree (ctid); create index on syscol_table using btree ((ctid >= '(1000,0)')); -create index -on syscol_table -using btree -( - a -) -where - ctid >= '(1000,0)'; +create index on syscol_table using btree (a) where ctid >= '(1000,0)'; drop table syscol_table; create table onek_with_null as select unique1, unique2 from onek; insert into onek_with_null (unique1, unique2) -values - (null, -1), - (null, 2147483647), - (null, null), - (100, null), - (500, null); +values (null, -1), (null, 2147483647), (null, null), (100, null), (500, null); -create unique index "onek_nulltest" on onek_with_null using btree (unique2, unique1); +create unique index onek_nulltest on onek_with_null using btree (unique2, unique1); set enable_seqscan = off; @@ -829,17 +742,17 @@ set enable_indexscan = 'on'; set enable_bitmapscan = 'on'; -select COUNT(*) from onek_with_null where unique1 is null; +select count(*) from onek_with_null where unique1 is null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is null; +select count(*) from onek_with_null where unique1 is null and unique2 is null; -select COUNT(*) from onek_with_null where unique1 is not null; +select count(*) from onek_with_null where unique1 is not null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is not null; +select count(*) from onek_with_null where unique1 is null and unique2 is not null; -select COUNT(*) from onek_with_null where unique1 is not null and unique1 > 500; +select count(*) from onek_with_null where unique1 is not null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique1 > 500; +select count(*) from onek_with_null where unique1 is null and unique1 > 500; select unique1, @@ -854,21 +767,21 @@ limit 1; drop index onek_nulltest; -create unique index "onek_nulltest" on onek_with_null using btree (unique2 desc, unique1); +create unique index onek_nulltest on onek_with_null using btree (unique2 desc, unique1); -select COUNT(*) from onek_with_null where unique1 is null; +select count(*) from onek_with_null where unique1 is null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is null; +select count(*) from onek_with_null where unique1 is null and unique2 is null; -select COUNT(*) from onek_with_null where unique1 is not null; +select count(*) from onek_with_null where unique1 is not null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is not null; +select count(*) from onek_with_null where unique1 is null and unique2 is not null; -select COUNT(*) from onek_with_null where unique1 is not null and unique1 > 500; +select count(*) from onek_with_null where unique1 is not null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique1 > 500; +select count(*) from onek_with_null where unique1 is null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique2 in (-1, 0, 1); +select count(*) from onek_with_null where unique1 is null and unique2 in (-1, 0, 1); select unique1, @@ -883,25 +796,19 @@ limit 1; drop index onek_nulltest; -create unique index "onek_nulltest" -on onek_with_null -using btree -( - unique2 desc nulls last, - unique1 -); +create unique index onek_nulltest on onek_with_null using btree (unique2 desc nulls last, unique1); -select COUNT(*) from onek_with_null where unique1 is null; +select count(*) from onek_with_null where unique1 is null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is null; +select count(*) from onek_with_null where unique1 is null and unique2 is null; -select COUNT(*) from onek_with_null where unique1 is not null; +select count(*) from onek_with_null where unique1 is not null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is not null; +select count(*) from onek_with_null where unique1 is null and unique2 is not null; -select COUNT(*) from onek_with_null where unique1 is not null and unique1 > 500; +select count(*) from onek_with_null where unique1 is not null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique1 > 500; +select count(*) from onek_with_null where unique1 is null and unique1 > 500; select unique1, @@ -916,19 +823,19 @@ limit 1; drop index onek_nulltest; -create unique index "onek_nulltest" on onek_with_null using btree (unique2 nulls first, unique1); +create unique index onek_nulltest on onek_with_null using btree (unique2 nulls first, unique1); -select COUNT(*) from onek_with_null where unique1 is null; +select count(*) from onek_with_null where unique1 is null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is null; +select count(*) from onek_with_null where unique1 is null and unique2 is null; -select COUNT(*) from onek_with_null where unique1 is not null; +select count(*) from onek_with_null where unique1 is not null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is not null; +select count(*) from onek_with_null where unique1 is null and unique2 is not null; -select COUNT(*) from onek_with_null where unique1 is not null and unique1 > 500; +select count(*) from onek_with_null where unique1 is not null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique1 > 500; +select count(*) from onek_with_null where unique1 is null and unique1 > 500; select unique1, @@ -943,7 +850,7 @@ limit 1; drop index onek_nulltest; -create unique index "onek_nulltest" on onek_with_null using btree (unique2); +create unique index onek_nulltest on onek_with_null using btree (unique2); set enable_seqscan = off; @@ -976,63 +883,35 @@ select from tenk1 where - thousand = 42 and - ( - tenthous = 1 or - tenthous = 3 or - tenthous = 42 or - tenthous = 0 - ); + thousand = 42 and (tenthous = 1 or tenthous = 3 or tenthous = 42 or tenthous = 0); select * from tenk1 where - thousand = 42 and - ( - tenthous = 1 or - tenthous = 3 or - tenthous = 42 or - tenthous = 0 - ); + thousand = 42 and (tenthous = 1 or tenthous = 3 or tenthous = 42 or tenthous = 0); select * from tenk1 where - thousand = 42 and - ( - tenthous = 1 or - tenthous = (select 1 + 2) or - tenthous = 42 - ); + thousand = 42 and (tenthous = 1 or tenthous = (select 1 + 2) or tenthous = 42); select * from tenk1 where - thousand = 42 and - ( - tenthous = 1 or - tenthous = (select 1 + 2) or - tenthous = 42 - ); + thousand = 42 and (tenthous = 1 or tenthous = (select 1 + 2) or tenthous = 42); select * from tenk1 where - thousand = 42 and - ( - tenthous = 1 or - tenthous = 3 or - tenthous = 42 or - tenthous is null - ); + thousand = 42 and (tenthous = 1 or tenthous = 3 or tenthous = 42 or tenthous is null); select * @@ -1041,9 +920,9 @@ from where thousand = 42 and ( - tenthous = cast(1 as smallint) or - cast(tenthous as smallint) = cast(3 as bigint) or - tenthous = cast(42 as bigint) + tenthous = cast(1 as int2) or + cast(tenthous as int2) = cast(3 as int8) or + tenthous = cast(42 as int8) ); select @@ -1053,9 +932,9 @@ from where thousand = 42 and ( - tenthous = cast(1 as smallint) or - cast(tenthous as smallint) = cast(3 as bigint) or - cast(tenthous as smallint) = cast(42 as bigint) + tenthous = cast(1 as int2) or + cast(tenthous as int2) = cast(3 as int8) or + cast(tenthous as int2) = cast(42 as int8) ); select @@ -1065,14 +944,12 @@ from where thousand = 42 and ( - tenthous = cast(1 as smallint) or - tenthous = cast(3 as bigint) or - tenthous = cast(42 as bigint) + tenthous = cast(1 as int2) or tenthous = cast(3 as int8) or tenthous = cast(42 as int8) ); -select COUNT(*) from tenk1 where hundred = 42 and (thousand = 42 or thousand = 99); +select count(*) from tenk1 where hundred = 42 and (thousand = 42 or thousand = 99); -select COUNT(*) from tenk1 where hundred = 42 and (thousand = 42 or thousand = 99); +select count(*) from tenk1 where hundred = 42 and (thousand = 42 or thousand = 99); select * from tenk1 where thousand = 42 and (tenthous = 1 or tenthous = 3 or tenthous = 42); @@ -1085,9 +962,7 @@ from where thousand = 42 and ( - tenthous = cast(1 as numeric) or - tenthous = cast(3 as int) or - tenthous = cast(42 as numeric) + tenthous = cast(1 as numeric) or tenthous = cast(3 as int4) or tenthous = cast(42 as numeric) ); select @@ -1095,201 +970,141 @@ select from tenk1 where - tenthous = cast(1 as numeric) or - tenthous = cast(3 as int) or - tenthous = cast(42 as numeric); + tenthous = cast(1 as numeric) or tenthous = cast(3 as int4) or tenthous = cast(42 as numeric); select - COUNT(*) + count(*) from tenk1 as t1 where t1.thousand = 42 or - t1.thousand = - ( - select - t2.tenthous - from - tenk1 as t2 - where - t2.thousand = t1.tenthous + 1 - limit 1 - ); + t1.thousand = (select t2.tenthous from tenk1 as t2 where t2.thousand = t1.tenthous + 1 limit 1); select - COUNT(*) + count(*) from tenk1 as t1 where t1.thousand = 42 or - t1.thousand = - ( - select - t2.tenthous - from - tenk1 as t2 - where - t2.thousand = t1.tenthous + 1 - limit 1 - ); + t1.thousand = (select t2.tenthous from tenk1 as t2 where t2.thousand = t1.tenthous + 1 limit 1); -select COUNT(*) from tenk1 where hundred = 42 and (thousand = 42 or thousand = 99); +select count(*) from tenk1 where hundred = 42 and (thousand = 42 or thousand = 99); -select COUNT(*) from tenk1 where hundred = 42 and (thousand = 42 or thousand = 99); +select count(*) from tenk1 where hundred = 42 and (thousand = 42 or thousand = 99); select - COUNT(*) + count(*) from tenk1 where - hundred = 42 and - ( - thousand < 42 or - thousand < 99 or - 43 > thousand or - 42 > thousand - ); + hundred = 42 and (thousand < 42 or thousand < 99 or 43 > thousand or 42 > thousand); select - COUNT(*) + count(*) from tenk1 where - hundred = 42 and - ( - thousand < 42 or - thousand < 99 or - 43 > thousand or - 42 > thousand - ); + hundred = 42 and (thousand < 42 or thousand < 99 or 43 > thousand or 42 > thousand); select - COUNT(*) + count(*) from tenk1 where - (thousand = 42 and (tenthous = 1 or tenthous = 3)) or - thousand = 41; + (thousand = 42 and (tenthous = 1 or tenthous = 3)) or thousand = 41; select - COUNT(*) + count(*) from tenk1 where - (thousand = 42 and (tenthous = 1 or tenthous = 3)) or - thousand = 41; + (thousand = 42 and (tenthous = 1 or tenthous = 3)) or thousand = 41; select - COUNT(*) + count(*) from tenk1 where - (hundred = 42 and - ( - thousand = 42 or thousand = 99 or tenthous < 2 - )) or - thousand = 41; + (hundred = 42 and (thousand = 42 or thousand = 99 or tenthous < 2)) or thousand = 41; select - COUNT(*) + count(*) from tenk1 where - (hundred = 42 and - ( - thousand = 42 or thousand = 99 or tenthous < 2 - )) or - thousand = 41; + (hundred = 42 and (thousand = 42 or thousand = 99 or tenthous < 2)) or thousand = 41; select - COUNT(*) + count(*) from tenk1 where - hundred = 42 and - ( - thousand = 42 or - thousand = 41 or - (thousand = 99 and tenthous = 2) - ); + hundred = 42 and (thousand = 42 or thousand = 41 or (thousand = 99 and tenthous = 2)); select - COUNT(*) + count(*) from tenk1 where - hundred = 42 and - ( - thousand = 42 or - thousand = 41 or - (thousand = 99 and tenthous = 2) - ); + hundred = 42 and (thousand = 42 or thousand = 41 or (thousand = 99 and tenthous = 2)); select - COUNT(*) + count(*) from tenk1, tenk2 where tenk1.hundred = 42 and ( - tenk2.thousand = 42 or - tenk1.thousand = 41 or - tenk2.tenthous = 2 + tenk2.thousand = 42 or tenk1.thousand = 41 or tenk2.tenthous = 2 ) and tenk2.hundred = tenk1.hundred; select - COUNT(*) + count(*) from tenk1, tenk2 where tenk1.hundred = 42 and ( - tenk2.thousand = 42 or - tenk2.thousand = 41 or - tenk2.tenthous = 2 + tenk2.thousand = 42 or tenk2.thousand = 41 or tenk2.tenthous = 2 ) and tenk2.hundred = tenk1.hundred; select - COUNT(*) + count(*) from tenk1 inner join tenk2 on tenk1.hundred = 42 and ( - tenk2.thousand = 42 or - tenk2.thousand = 41 or - tenk2.tenthous = 2 + tenk2.thousand = 42 or tenk2.thousand = 41 or tenk2.tenthous = 2 ) and tenk2.hundred = tenk1.hundred; select - COUNT(*) + count(*) from tenk1 left outer join tenk2 on tenk1.hundred = 42 and ( - tenk2.thousand = 42 or - tenk2.thousand = 41 or - tenk2.tenthous = 2 + tenk2.thousand = 42 or tenk2.thousand = 41 or tenk2.tenthous = 2 ) and tenk2.hundred = tenk1.hundred; create table dupindexcols as select unique1 as id, cast(stringu2 as text) as f1 from tenk1; -create index "dupindexcols_i" on dupindexcols using btree (f1, id, f1 text_pattern_ops); +create index dupindexcols_i on dupindexcols using btree (f1, id, f1 text_pattern_ops); analyze dupindexcols; -select COUNT(*) from dupindexcols where f1 between 'WA' and 'ZZZ' and id < 1000 and f1 ~<~ 'YX'; +select count(*) from dupindexcols where f1 between 'WA' and 'ZZZ' and id < 1000 and f1 ~<~ 'YX'; -select COUNT(*) from dupindexcols where f1 between 'WA' and 'ZZZ' and id < 1000 and f1 ~<~ 'YX'; +select count(*) from dupindexcols where f1 between 'WA' and 'ZZZ' and id < 1000 and f1 ~<~ 'YX'; select unique1 from tenk1 where unique1 in (1, 42, 7) order by unique1; @@ -1360,16 +1175,14 @@ select from tenk1 where - unique1 = any ('{7, 14, 22}') and - unique1 = any (cast('{33, 44}' as bigint[])); + unique1 = any ('{7, 14, 22}') and unique1 = any (cast('{33, 44}' as bigint[])); select unique1 from tenk1 where - unique1 = any ('{7, 14, 22}') and - unique1 = any (cast('{33, 44}' as bigint[])); + unique1 = any ('{7, 14, 22}') and unique1 = any (cast('{33, 44}' as bigint[])); select unique1 from tenk1 where unique1 = any (null); @@ -1425,9 +1238,7 @@ select from tenk1 where - thousand > -1 and - thousand >= 0 and - tenthous = 3000 + thousand > -1 and thousand >= 0 and tenthous = 3000 order by thousand; select @@ -1436,9 +1247,7 @@ select from tenk1 where - thousand > -1 and - thousand >= 0 and - tenthous = 3000 + thousand > -1 and thousand >= 0 and tenthous = 3000 order by thousand; select @@ -1482,7 +1291,7 @@ limit 2; select * from tenk1 where (thousand, tenthous) in ((1, 1001), (null, null)); create temporary table boolindex ( - b boolean, + b bool, i int, unique (b, i), junk double precision @@ -1502,7 +1311,7 @@ select * from boolindex where b is false order by i desc limit 10; create table reindex_verbose (id int primary key); -reindex (VERBOSE) table reindex_verbose; +reindex (verbose) table reindex_verbose; drop table reindex_verbose; @@ -1510,21 +1319,21 @@ create table concur_reindex_tab (c1 int); reindex table concur_reindex_tab; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; alter table concur_reindex_tab add column c2 text; -create unique index "concur_reindex_ind1" on concur_reindex_tab using btree (c1); +create unique index concur_reindex_ind1 on concur_reindex_tab using btree (c1); -create index "concur_reindex_ind2" on concur_reindex_tab using btree (c2); +create index concur_reindex_ind2 on concur_reindex_tab using btree (c2); -create unique index "concur_reindex_ind3" on concur_reindex_tab using btree ((abs(c1))); +create unique index concur_reindex_ind3 on concur_reindex_tab using btree ((abs(c1))); -create index "concur_reindex_ind4" on concur_reindex_tab using btree (c1, c1, c2); +create index concur_reindex_ind4 on concur_reindex_tab using btree (c1, c1, c2); alter table concur_reindex_tab - add primary key using index "concur_reindex_ind1"; + add primary key using index concur_reindex_ind1; create table concur_reindex_tab2 (c1 int references concur_reindex_tab); @@ -1540,23 +1349,17 @@ create table concur_reindex_tab3 ( insert into concur_reindex_tab3 values (3, '[1,2]'); -reindex (CONCURRENTLY) index concur_reindex_tab3_c2_excl; +reindex (concurrently) index concur_reindex_tab3_c2_excl; -reindex (CONCURRENTLY) table concur_reindex_tab3; +reindex (concurrently) table concur_reindex_tab3; insert into concur_reindex_tab3 values (4, '[2,4]'); create materialized view concur_reindex_matview as select * from concur_reindex_tab; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -1571,21 +1374,15 @@ where order by 1, 2; -reindex (CONCURRENTLY) index concur_reindex_ind1; +reindex (concurrently) index concur_reindex_ind1; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; -reindex (CONCURRENTLY) table concur_reindex_matview; +reindex (concurrently) table concur_reindex_matview; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -1602,7 +1399,7 @@ order by 1, create table testcomment (i int); -create index "testcomment_idx1" on testcomment using btree (i); +create index testcomment_idx1 on testcomment using btree (i); comment on index testcomment_idx1 is 'test comment'; @@ -1612,7 +1409,7 @@ reindex table testcomment; select obj_description(cast('testcomment_idx1' as regclass), 'pg_class'); -reindex (CONCURRENTLY) table testcomment; +reindex (concurrently) table testcomment; select obj_description(cast('testcomment_idx1' as regclass), 'pg_class'); @@ -1620,12 +1417,12 @@ drop table testcomment; create table concur_clustered (i int); -create index "concur_clustered_i_idx" on concur_clustered using btree (i); +create index concur_clustered_i_idx on concur_clustered using btree (i); alter table concur_clustered cluster on concur_clustered_i_idx; -reindex (CONCURRENTLY) table concur_clustered; +reindex (concurrently) table concur_clustered; select cast(indexrelid as regclass), @@ -1639,12 +1436,10 @@ drop table concur_clustered; create table concur_replident (i int not null); -create unique index "concur_replident_i_idx" on concur_replident using btree (i); +create unique index concur_replident_i_idx on concur_replident using btree (i); alter table concur_replident - replica identity - using index - concur_replident_i_idx; + replica identity using index concur_replident_i_idx; select cast(indexrelid as regclass), @@ -1654,7 +1449,7 @@ from where indrelid = cast('concur_replident' as regclass); -reindex (CONCURRENTLY) table concur_replident; +reindex (concurrently) table concur_replident; select cast(indexrelid as regclass), @@ -1672,23 +1467,17 @@ create table concur_appclass_tab ( k tsvector ); -create index "concur_appclass_ind" -on concur_appclass_tab -using gist -( +create index concur_appclass_ind on concur_appclass_tab using gist ( i tsvector_ops(siglen = "1000"), j tsvector_ops(siglen = "500") ); -create index "concur_appclass_ind_2" -on concur_appclass_tab -using gist -( +create index concur_appclass_ind_2 on concur_appclass_tab using gist ( k tsvector_ops(siglen = "300"), j tsvector_ops ); -reindex (CONCURRENTLY) table concur_appclass_tab; +reindex (concurrently) table concur_appclass_tab; drop table concur_appclass_tab; @@ -1701,7 +1490,7 @@ partition by range(c1); create table concur_reindex_part_0 partition of concur_reindex_part for values from (0) to (10) -partition by LIST(c2); +partition by list(c2); create table concur_reindex_part_0_1 partition of concur_reindex_part_0 for values in (1); @@ -1710,29 +1499,29 @@ create table concur_reindex_part_0_2 partition of concur_reindex_part_0 for valu create table concur_reindex_part_10 partition of concur_reindex_part for values from (10) to (20) -partition by LIST(c2); +partition by list(c2); -create index "concur_reindex_part_index" on only concur_reindex_part using btree (c1); +create index concur_reindex_part_index on only concur_reindex_part using btree (c1); -create index "concur_reindex_part_index_0" on only concur_reindex_part_0 using btree (c1); +create index concur_reindex_part_index_0 on only concur_reindex_part_0 using btree (c1); alter index concur_reindex_part_index attach partition concur_reindex_part_index_0; -create index "concur_reindex_part_index_10" on only concur_reindex_part_10 using btree (c1); +create index concur_reindex_part_index_10 on only concur_reindex_part_10 using btree (c1); alter index concur_reindex_part_index attach partition concur_reindex_part_index_10; -create index "concur_reindex_part_index_0_1" on only concur_reindex_part_0_1 using btree (c1); +create index concur_reindex_part_index_0_1 on only concur_reindex_part_0_1 using btree (c1); alter index concur_reindex_part_index_0 attach partition concur_reindex_part_index_0_1; -create index "concur_reindex_part_index_0_2" on only concur_reindex_part_0_2 using btree (c1); +create index concur_reindex_part_index_0_2 on only concur_reindex_part_0_2 using btree (c1); alter index concur_reindex_part_index_0 attach partition @@ -1757,14 +1546,8 @@ order by relid, level; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -1781,9 +1564,9 @@ where order by 1, 2; -reindex (CONCURRENTLY) index concur_reindex_part_index_0_1; +reindex (concurrently) index concur_reindex_part_index_0_1; -reindex (CONCURRENTLY) index concur_reindex_part_index_0_2; +reindex (concurrently) index concur_reindex_part_index_0_2; select relid, @@ -1794,19 +1577,13 @@ from order by relid, level; -reindex (CONCURRENTLY) table concur_reindex_part_0_1; +reindex (concurrently) table concur_reindex_part_0_1; -reindex (CONCURRENTLY) table concur_reindex_part_0_2; +reindex (concurrently) table concur_reindex_part_0_2; select - pg_describe_object(classid, objid, objsubid) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -1834,11 +1611,11 @@ order by relid, reindex table concur_reindex_part_index; -reindex (CONCURRENTLY) table concur_reindex_part_index; +reindex (concurrently) table concur_reindex_part_index; reindex table concur_reindex_part_index_10; -reindex (CONCURRENTLY) table concur_reindex_part_index_10; +reindex (concurrently) table concur_reindex_part_index_10; begin; @@ -1849,8 +1626,8 @@ rollback; create or replace function create_relfilenode_part(relname text, indname text) returns void language plpgsql -as $function$ -BEGIN +as $func$ + BEGIN EXECUTE format(' CREATE TABLE %I AS SELECT oid, relname, relfilenode, relkind, reltoastrelid @@ -1859,7 +1636,7 @@ BEGIN (SELECT relid FROM pg_partition_tree(''%I''));', relname, indname); END -$function$; + $func$; create or replace function compare_relfilenode_part(tabname text) returns table ( @@ -1868,8 +1645,8 @@ returns table ( state text ) language plpgsql -as $function$ -BEGIN +as $func$ + BEGIN RETURN QUERY EXECUTE format( 'SELECT b.relname, @@ -1880,7 +1657,7 @@ BEGIN FROM %I b JOIN pg_class a ON b.relname = a.relname ORDER BY 1;', tabname); END -$function$; + $func$; select create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); @@ -1892,7 +1669,7 @@ drop table reindex_index_status; select create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); -reindex (CONCURRENTLY) index concur_reindex_part_index; +reindex (concurrently) index concur_reindex_part_index; select * from compare_relfilenode_part('reindex_index_status'); @@ -1900,11 +1677,11 @@ drop table reindex_index_status; reindex index concur_reindex_part; -reindex (CONCURRENTLY) index concur_reindex_part; +reindex (concurrently) index concur_reindex_part; reindex index concur_reindex_part_10; -reindex (CONCURRENTLY) index concur_reindex_part_10; +reindex (concurrently) index concur_reindex_part_10; begin; @@ -1922,7 +1699,7 @@ drop table reindex_index_status; select create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); -reindex (CONCURRENTLY) table concur_reindex_part; +reindex (concurrently) table concur_reindex_part; select * from compare_relfilenode_part('reindex_index_status'); @@ -1936,25 +1713,25 @@ drop table concur_reindex_part; begin; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; commit; -reindex (CONCURRENTLY) table pg_class; +reindex (concurrently) table pg_class; -reindex (CONCURRENTLY) index pg_class_oid_index; +reindex (concurrently) index pg_class_oid_index; -reindex (CONCURRENTLY) table pg_toast.pg_toast_1262; +reindex (concurrently) table pg_toast.pg_toast_1262; -reindex (CONCURRENTLY) index pg_toast.pg_toast_1262_index; +reindex (concurrently) index pg_toast.pg_toast_1262_index; -reindex (CONCURRENTLY) system postgres; +reindex (concurrently) system postgres; -reindex (CONCURRENTLY) system postgres; +reindex (concurrently) system postgres; -reindex (CONCURRENTLY) system ; +reindex (concurrently) system ; -reindex (CONCURRENTLY) schema pg_catalog; +reindex (concurrently) schema pg_catalog; reindex database not_current_database; @@ -1966,17 +1743,17 @@ create table concur_reindex_tab4 (c1 int); insert into concur_reindex_tab4 values (1), (1), (2); -create unique index concurrently "concur_reindex_ind5" on concur_reindex_tab4 using btree (c1); +create unique index concurrently concur_reindex_ind5 on concur_reindex_tab4 using btree (c1); -reindex (CONCURRENTLY) index concur_reindex_ind5; +reindex (concurrently) index concur_reindex_ind5; drop index concur_reindex_ind5_ccnew; delete from concur_reindex_tab4 where c1 = 1; -reindex (CONCURRENTLY) table concur_reindex_tab4; +reindex (concurrently) table concur_reindex_tab4; -reindex (CONCURRENTLY) index concur_reindex_ind5; +reindex (concurrently) index concur_reindex_ind5; drop table concur_reindex_tab4; @@ -1986,36 +1763,17 @@ create table concur_exprs_tab ( ); insert into concur_exprs_tab (c1, c2) -values - (1369652450, false), - (414515746, true), - (897778963, false); - -create unique index "concur_exprs_index_expr" -on concur_exprs_tab -using btree -( +values (1369652450, false), (414515746, true), (897778963, false); + +create unique index concur_exprs_index_expr on concur_exprs_tab using btree ( (cast(c1 as text) collate "C") ); -create unique index "concur_exprs_index_pred" -on concur_exprs_tab -using btree -( - c1 -) -where - cast(c1 as text) > - cast(500000000 as text) collate "C"; - -create unique index "concur_exprs_index_pred_2" -on concur_exprs_tab -using btree -( - (1 / c1) -) -where - '-H' >= cast(c2 as text) collate "C"; +create unique index concur_exprs_index_pred on concur_exprs_tab using btree (c1) +where cast(c1 as text) > cast(500000000 as text) collate "C"; + +create unique index concur_exprs_index_pred_2 on concur_exprs_tab using btree ((1 / c1)) +where '-H' >= cast(c2 as text) collate "C"; alter index concur_exprs_index_expr alter column 1 set statistics 100; @@ -2024,7 +1782,7 @@ analyze concur_exprs_tab; select cast(starelid as regclass), - COUNT(*) + count(*) from pg_statistic where @@ -2042,7 +1800,7 @@ select pg_get_indexdef(cast('concur_exprs_index_pred' as regclass)); select pg_get_indexdef(cast('concur_exprs_index_pred_2' as regclass)); -reindex (CONCURRENTLY) table concur_exprs_tab; +reindex (concurrently) table concur_exprs_tab; select pg_get_indexdef(cast('concur_exprs_index_expr' as regclass)); @@ -2061,7 +1819,7 @@ select pg_get_indexdef(cast('concur_exprs_index_pred_2' as regclass)); select cast(starelid as regclass), - COUNT(*) + count(*) from pg_statistic where @@ -2098,23 +1856,23 @@ on commit preserve rows; insert into concur_temp_tab_1 values (1, 'foo'), (2, 'bar'); -create index "concur_temp_ind_1" on concur_temp_tab_1 using btree (c2); +create index concur_temp_ind_1 on concur_temp_tab_1 using btree (c2); -reindex (CONCURRENTLY) table concur_temp_tab_1; +reindex (concurrently) table concur_temp_tab_1; -reindex (CONCURRENTLY) index concur_temp_ind_1; +reindex (concurrently) index concur_temp_ind_1; begin; -reindex (CONCURRENTLY) index concur_temp_ind_1; +reindex (concurrently) index concur_temp_ind_1; commit; -create index "concur_temp_ind_2" on concur_temp_tab_2 using btree (c2); +create index concur_temp_ind_2 on concur_temp_tab_2 using btree (c2); -reindex (CONCURRENTLY) table concur_temp_tab_2; +reindex (concurrently) table concur_temp_tab_2; -reindex (CONCURRENTLY) index concur_temp_ind_2; +reindex (concurrently) index concur_temp_ind_2; begin; @@ -2126,9 +1884,9 @@ on commit preserve rows; insert into concur_temp_tab_3 values (1, 'foo'), (2, 'bar'); -create index "concur_temp_ind_3" on concur_temp_tab_3 using btree (c2); +create index concur_temp_ind_3 on concur_temp_tab_3 using btree (c2); -reindex (CONCURRENTLY) index concur_temp_ind_3; +reindex (concurrently) index concur_temp_ind_3; commit; @@ -2143,10 +1901,7 @@ as from pg_class where - relname - in ( - 'concur_temp_ind_1', 'concur_temp_ind_2' - ); + relname in ('concur_temp_ind_1', 'concur_temp_ind_2'); select cast(pg_my_temp_schema() as regnamespace) as temp_schema_name; @@ -2154,15 +1909,11 @@ select b.relname, b.relkind, case - when a.relfilenode = b.relfilenode - then 'relfilenode is unchanged' + when a.relfilenode = b.relfilenode then 'relfilenode is unchanged' else 'relfilenode has changed' end from - reindex_temp_before as b - inner join - pg_class as a - on b.oid = a.oid + reindex_temp_before as b inner join pg_class as a on b.oid = a.oid order by 1; drop table concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before; @@ -2181,25 +1932,11 @@ insert into bitmap_split_or select 1, 1, i from generate_series(1, 1000) as i; insert into bitmap_split_or select i, 2, 2 from generate_series(1, 1000) as i; -vacuum (ANALYZE) bitmap_split_or; +vacuum (analyze) bitmap_split_or; -create index "t_b_partial_1_idx" -on bitmap_split_or -using btree -( - b -) -where - a = 1; +create index t_b_partial_1_idx on bitmap_split_or using btree (b) where a = 1; -create index "t_b_partial_2_idx" -on bitmap_split_or -using btree -( - b -) -where - a = 2; +create index t_b_partial_2_idx on bitmap_split_or using btree (b) where a = 2; select * from bitmap_split_or where (a = 1 or a = 2) and b = 2; @@ -2207,13 +1944,13 @@ drop index t_b_partial_1_idx; drop index t_b_partial_2_idx; -create index "t_a_b_idx" on bitmap_split_or using btree (a, b); +create index t_a_b_idx on bitmap_split_or using btree (a, b); -create index "t_b_c_idx" on bitmap_split_or using btree (b, c); +create index t_b_c_idx on bitmap_split_or using btree (b, c); -create statistics t_a_b_stat (mcv) on "a", "b" from bitmap_split_or; +create statistics t_a_b_stat (mcv) on a, b from bitmap_split_or; -create statistics t_b_c_stat (mcv) on "b", "c" from bitmap_split_or; +create statistics t_b_c_stat (mcv) on b, c from bitmap_split_or; analyze bitmap_split_or; @@ -2225,7 +1962,7 @@ drop table bitmap_split_or; reindex schema schema_to_reindex; -create schema "schema_to_reindex"; +create schema schema_to_reindex; set search_path to schema_to_reindex; @@ -2260,15 +1997,7 @@ as from pg_class where - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'schema_to_reindex' - ); + relnamespace = (select oid from pg_namespace where nspname = 'schema_to_reindex'); insert into reindex_before select @@ -2280,15 +2009,7 @@ select from pg_class where - oid in - ( - select - reltoastrelid - from - reindex_before - where - reltoastrelid > 0 - ); + oid in (select reltoastrelid from reindex_before where reltoastrelid > 0); insert into reindex_before select @@ -2307,15 +2028,7 @@ where from pg_index where - indrelid in - ( - select - reltoastrelid - from - reindex_before - where - reltoastrelid > 0 - ) + indrelid in (select reltoastrelid from reindex_before where reltoastrelid > 0) ); reindex schema schema_to_reindex; @@ -2330,29 +2043,17 @@ as from pg_class where - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'schema_to_reindex' - ); + relnamespace = (select oid from pg_namespace where nspname = 'schema_to_reindex'); select b.relname, b.relkind, case - when a.relfilenode = b.relfilenode - then 'relfilenode is unchanged' + when a.relfilenode = b.relfilenode then 'relfilenode is unchanged' else 'relfilenode has changed' end from - reindex_before as b - inner join - pg_class as a - on b.oid = a.oid + reindex_before as b inner join pg_class as a on b.oid = a.oid order by 1; reindex schema schema_to_reindex; @@ -2363,7 +2064,7 @@ reindex schema schema_to_reindex; commit; -reindex (CONCURRENTLY) schema schema_to_reindex; +reindex (concurrently) schema schema_to_reindex; create role regress_reindexuser nologin; @@ -2373,7 +2074,7 @@ reindex schema schema_to_reindex; reset role; -grant USAGE on schema pg_toast to regress_reindexuser; +grant usage on schema pg_toast to regress_reindexuser; set role to regress_reindexuser; @@ -2383,7 +2084,7 @@ reindex index pg_toast.pg_toast_1262_index; reset role; -revoke USAGE on schema pg_toast from regress_reindexuser; +revoke usage on schema pg_toast from regress_reindexuser; drop role regress_reindexuser; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_80.snap index c8411e855..8418409cc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_80.snap @@ -2,41 +2,35 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/create_index.sql --- -create index "onek_unique1" on onek using btree (unique1 int4_ops); - -create index -if not exists "onek_unique1" -on onek -using btree -( - unique1 int4_ops -); +create index onek_unique1 on onek using btree (unique1 int4_ops); + +create index if not exists onek_unique1 on onek using btree (unique1 int4_ops); -create index "onek_unique2" on onek using btree (unique2 int4_ops); +create index onek_unique2 on onek using btree (unique2 int4_ops); -create index "onek_hundred" on onek using btree (hundred int4_ops); +create index onek_hundred on onek using btree (hundred int4_ops); -create index "onek_stringu1" on onek using btree (stringu1 name_ops); +create index onek_stringu1 on onek using btree (stringu1 name_ops); -create index "tenk1_unique1" on tenk1 using btree (unique1 int4_ops); +create index tenk1_unique1 on tenk1 using btree (unique1 int4_ops); -create index "tenk1_unique2" on tenk1 using btree (unique2 int4_ops); +create index tenk1_unique2 on tenk1 using btree (unique2 int4_ops); -create index "tenk1_hundred" on tenk1 using btree (hundred int4_ops); +create index tenk1_hundred on tenk1 using btree (hundred int4_ops); -create index "tenk1_thous_tenthous" on tenk1 using btree (thousand, tenthous); +create index tenk1_thous_tenthous on tenk1 using btree (thousand, tenthous); -create index "tenk2_unique1" on tenk2 using btree (unique1 int4_ops); +create index tenk2_unique1 on tenk2 using btree (unique1 int4_ops); -create index "tenk2_unique2" on tenk2 using btree (unique2 int4_ops); +create index tenk2_unique2 on tenk2 using btree (unique2 int4_ops); -create index "tenk2_hundred" on tenk2 using btree (hundred int4_ops); +create index tenk2_hundred on tenk2 using btree (hundred int4_ops); -create index "rix" on road using btree (name text_ops); +create index rix on road using btree (name text_ops); -create index "iix" on ihighway using btree (name text_ops); +create index iix on ihighway using btree (name text_ops); -create index "six" on shighway using btree (name text_ops); +create index six on shighway using btree (name text_ops); comment on index six_wrong is 'bad index'; @@ -44,33 +38,14 @@ comment on index six is 'good index'; comment on index six is null; -create index "onek2_u1_prtl" -on onek2 -using btree -( - unique1 int4_ops -) -where - unique1 < 20 or unique1 > 980; +create index onek2_u1_prtl on onek2 using btree (unique1 int4_ops) +where unique1 < 20 or unique1 > 980; -create index "onek2_u2_prtl" -on onek2 -using btree -( - unique2 int4_ops -) -where - stringu1 < 'B'; +create index onek2_u2_prtl on onek2 using btree (unique2 int4_ops) +where stringu1 < 'B'; -create index "onek2_stu1_prtl" -on onek2 -using btree -( - stringu1 name_ops -) -where - onek2.stringu1 >= 'J' and - onek2.stringu1 < 'K'; +create index onek2_stu1_prtl on onek2 using btree (stringu1 name_ops) +where onek2.stringu1 >= 'J' and onek2.stringu1 < 'K'; create table slow_emp4000 (home_base box); @@ -84,20 +59,17 @@ analyze slow_emp4000; analyze fast_emp4000; -create index "grect2ind" on fast_emp4000 using gist (home_base); +create index grect2ind on fast_emp4000 using gist (home_base); create temporary table point_tbl as select * from public.point_tbl; insert into point_tbl (f1) values (null); -create index "gpointind" on point_tbl using gist (f1); +create index gpointind on point_tbl using gist (f1); create temporary table gpolygon_tbl as - select - polygon(home_base) as f1 - from - slow_emp4000; + select polygon(home_base) as f1 from slow_emp4000; insert into gpolygon_tbl values ('(1000,0,0,1000)'); @@ -105,14 +77,11 @@ insert into gpolygon_tbl values ('(0,1000,1000,1000)'); create temporary table gcircle_tbl as - select - circle(home_base) as f1 - from - slow_emp4000; + select circle(home_base) as f1 from slow_emp4000; -create index "ggpolygonind" on gpolygon_tbl using gist (f1); +create index ggpolygonind on gpolygon_tbl using gist (f1); -create index "ggcircleind" on gcircle_tbl using gist (f1); +create index ggcircleind on gcircle_tbl using gist (f1); set enable_seqscan = 'on'; @@ -125,53 +94,49 @@ select from fast_emp4000 where - home_base <@ - cast('(200,200),(2000,1000)' as box) + home_base <@ cast('(200,200),(2000,1000)' as box) order by (home_base[0])[0]; select - COUNT(*) + count(*) from fast_emp4000 where - home_base && - cast('(1000,1000,0,0)' as box); + home_base && cast('(1000,1000,0,0)' as box); -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; select - COUNT(*) + count(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); -select COUNT(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); +select count(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); -select COUNT(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); +select count(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); -select COUNT(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; +select count(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; select - COUNT(*) + count(*) from point_tbl where - f1 <@ - cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' - as polygon); + f1 <@ cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' as polygon); -select COUNT(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); +select count(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); -select COUNT(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; +select count(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; select * from point_tbl order by f1 <-> '0,1'; @@ -208,8 +173,7 @@ select from fast_emp4000 where - home_base <@ - cast('(200,200),(2000,1000)' as box) + home_base <@ cast('(200,200),(2000,1000)' as box) order by (home_base[0])[0]; select @@ -217,97 +181,90 @@ select from fast_emp4000 where - home_base <@ - cast('(200,200),(2000,1000)' as box) + home_base <@ cast('(200,200),(2000,1000)' as box) order by (home_base[0])[0]; select - COUNT(*) + count(*) from fast_emp4000 where - home_base && - cast('(1000,1000,0,0)' as box); + home_base && cast('(1000,1000,0,0)' as box); select - COUNT(*) + count(*) from fast_emp4000 where - home_base && - cast('(1000,1000,0,0)' as box); + home_base && cast('(1000,1000,0,0)' as box); -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; -select COUNT(*) from fast_emp4000 where home_base is null; +select count(*) from fast_emp4000 where home_base is null; select - COUNT(*) + count(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); select - COUNT(*) + count(*) from gpolygon_tbl where f1 && cast('(1000,1000,0,0)' as polygon); -select COUNT(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); +select count(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); -select COUNT(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); +select count(*) from gcircle_tbl where f1 && cast('<(500,500),500>' as circle); -select COUNT(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); +select count(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); -select COUNT(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); +select count(*) from point_tbl where f1 <@ cast('(0,0,100,100)' as box); -select COUNT(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; +select count(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; -select COUNT(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; +select count(*) from point_tbl where cast('(0,0,100,100)' as box) @> f1; select - COUNT(*) + count(*) from point_tbl where - f1 <@ - cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' - as polygon); + f1 <@ cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' as polygon); select - COUNT(*) + count(*) from point_tbl where - f1 <@ - cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' - as polygon); + f1 <@ cast('(0,0),(0,100),(100,100),(50,50),(100,0),(0,0)' as polygon); -select COUNT(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); +select count(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); -select COUNT(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); +select count(*) from point_tbl where f1 <@ cast('<(50,50),50>' as circle); -select COUNT(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 << '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 >> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 <<| '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; +select count(*) from point_tbl as p where p.f1 |>> '(0.0, 0.0)'; -select COUNT(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; +select count(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; -select COUNT(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; +select count(*) from point_tbl as p where p.f1 ~= '(-5, -12)'; select * from point_tbl order by f1 <-> '0,1'; @@ -359,29 +316,13 @@ limit 10; select point(x, x), - ( - select - f1 - from - gpolygon_tbl - order by f1 <-> point(x, x) - limit 1 - ) - as c + (select f1 from gpolygon_tbl order by f1 <-> point(x, x) limit 1) as c from generate_series(0, 10, 1) as x; select point(x, x), - ( - select - f1 - from - gpolygon_tbl - order by f1 <-> point(x, x) - limit 1 - ) - as c + (select f1 from gpolygon_tbl order by f1 <-> point(x, x) limit 1) as c from generate_series(0, 10, 1) as x; @@ -414,8 +355,8 @@ reset enable_indexscan; reset enable_bitmapscan; create table array_index_op_test ( - seqno int, - i int[], + seqno int4, + i int4[], t text[] ); @@ -437,7 +378,7 @@ set enable_indexscan = off; set enable_bitmapscan = 'on'; -create index "intarrayidx" on array_index_op_test using gin (i); +create index intarrayidx on array_index_op_test using gin (i); select * from array_index_op_test where i @> '{32}' order by seqno; @@ -465,7 +406,7 @@ select * from array_index_op_test where i && '{}' order by seqno; select * from array_index_op_test where i <@ '{}' order by seqno; -create index "textarrayidx" on array_index_op_test using gin (t); +create index textarrayidx on array_index_op_test using gin (t); select * from array_index_op_test where t @> '{AAAAAAAA72908}' order by seqno; @@ -520,7 +461,7 @@ select * from array_index_op_test where t <@ '{}' order by seqno; drop index intarrayidx, textarrayidx; -create index "botharrayidx" on array_index_op_test using gin (i, t); +create index botharrayidx on array_index_op_test using gin (i, t); select * from array_index_op_test where i @> '{32}' order by seqno; @@ -557,32 +498,20 @@ reset enable_bitmapscan; create table array_gin_test (a int[]); insert into array_gin_test -select - array[1, g % 5, g] -from - generate_series(1, 10000) as g; +select array[1, g % 5, g] from generate_series(1, 10000) as g; -create index "array_gin_test_idx" on array_gin_test using gin (a); +create index array_gin_test_idx on array_gin_test using gin (a); -select COUNT(*) from array_gin_test where a @> '{2}'; +select count(*) from array_gin_test where a @> '{2}'; drop table array_gin_test; -create index "gin_relopts_test" -on array_index_op_test -using gin -( - i -) -with (fastupdate = 'on', -gin_pending_list_limit = 128); +create index gin_relopts_test on array_index_op_test using gin (i) +with (fastupdate = 'on', gin_pending_list_limit = 128); -create unlogged table unlogged_hash_table (id int); +create unlogged table unlogged_hash_table (id int4); -create index "unlogged_hash_index" -on unlogged_hash_table -using hash -( +create index unlogged_hash_index on unlogged_hash_table using hash ( id int4_ops ); @@ -590,21 +519,16 @@ drop table unlogged_hash_table; set maintenance_work_mem = '1MB'; -create index "hash_tuplesort_idx" -on tenk1 -using hash -( - stringu1 name_ops -) +create index hash_tuplesort_idx on tenk1 using hash (stringu1 name_ops) with (fillfactor = 10); -select COUNT(*) from tenk1 where stringu1 = 'TVAAAA'; +select count(*) from tenk1 where stringu1 = 'TVAAAA'; -select COUNT(*) from tenk1 where stringu1 = 'TVAAAA'; +select count(*) from tenk1 where stringu1 = 'TVAAAA'; set enable_seqscan = off; -select COUNT(*) from tenk1 where stringu1 = 'TVAAAA' or stringu1 = 'TVAAAB'; +select count(*) from tenk1 where stringu1 = 'TVAAAA' or stringu1 = 'TVAAAB'; reset enable_seqscan; @@ -617,14 +541,9 @@ create table unique_tbl ( t text ); -create unique index "unique_idx1" on unique_tbl using btree (i); +create unique index unique_idx1 on unique_tbl using btree (i); -create unique index "unique_idx2" -on unique_tbl -using btree -( - i -) +create unique index unique_idx2 on unique_tbl using btree (i) nulls not distinct; insert into unique_tbl values (1, 'one'); @@ -645,24 +564,14 @@ drop index unique_idx1, unique_idx2; insert into unique_tbl (t) values ('seven'); -create unique index "unique_idx3" on unique_tbl using btree (i); +create unique index unique_idx3 on unique_tbl using btree (i); -create unique index "unique_idx4" -on unique_tbl -using btree -( - i -) +create unique index unique_idx4 on unique_tbl using btree (i) nulls not distinct; delete from unique_tbl where t = 'seven'; -create unique index "unique_idx4" -on unique_tbl -using btree -( - i -) +create unique index unique_idx4 on unique_tbl using btree (i) nulls not distinct; select pg_get_indexdef(cast('unique_idx3' as regclass)); @@ -676,10 +585,7 @@ create table func_index_heap ( f2 text ); -create unique index "func_index_index" -on func_index_heap -using btree -( +create unique index func_index_index on func_index_heap using btree ( (textcat(f1, f2)) ); @@ -700,10 +606,7 @@ create table func_index_heap ( f2 text ); -create unique index "func_index_index" -on func_index_heap -using btree -( +create unique index func_index_index on func_index_heap using btree ( (f1 || f2) text_ops ); @@ -725,11 +628,7 @@ create table covering_index_heap ( f3 text ); -create unique -index "covering_index_index" -on covering_index_heap -using btree -( +create unique index covering_index_index on covering_index_heap using btree ( f1, f2 ) @@ -743,17 +642,11 @@ insert into covering_index_heap values (1, 2, 'BBB'); insert into covering_index_heap values (1, 4, 'AAA'); -create unique index "covering_pkey" -on covering_index_heap -using btree -( - f1, - f2 -) +create unique index covering_pkey on covering_index_heap using btree (f1, f2) include (f3); alter table covering_index_heap - add constraint "covering_pkey" primary key using index "covering_pkey"; + add constraint covering_pkey primary key using index covering_pkey; drop table covering_index_heap; @@ -762,100 +655,52 @@ create table concur_heap ( f2 text ); -create index concurrently "concur_index1" on concur_heap using btree (f2, f1); +create index concurrently concur_index1 on concur_heap using btree (f2, f1); -create index -concurrently -if not exists "concur_index1" -on concur_heap -using btree -( - f2, - f1 -); +create index concurrently if not exists concur_index1 + on concur_heap + using btree (f2, f1); insert into concur_heap values ('a', 'b'); insert into concur_heap values ('b', 'b'); -create unique -index -concurrently "concur_index2" -on concur_heap -using btree -( - f1 -); +create unique index concurrently concur_index2 on concur_heap using btree (f1); -create unique -index -concurrently -if not exists "concur_index2" -on concur_heap -using btree -( - f1 -); +create unique index concurrently if not exists concur_index2 + on concur_heap + using btree (f1); insert into concur_heap values ('b', 'x'); -create unique -index -concurrently "concur_index3" -on concur_heap -using btree -( - f2 -); +create unique index concurrently concur_index3 on concur_heap using btree (f2); -create index -concurrently "concur_index4" -on concur_heap -using btree -( - f2 -) -where - f1 = 'a'; +create index concurrently concur_index4 on concur_heap using btree (f2) +where f1 = 'a'; -create index -concurrently "concur_index5" -on concur_heap -using btree -( - f2 -) -where - f1 = 'x'; +create index concurrently concur_index5 on concur_heap using btree (f2) +where f1 = 'x'; create index concurrently on concur_heap using btree ((f2 || f1)); begin; -create index concurrently "concur_index7" on concur_heap using btree (f1); +create index concurrently concur_index7 on concur_heap using btree (f1); commit; create function predicate_stable() -returns boolean +returns bool language plpgsql immutable -as $function$ +as $$ BEGIN EXECUTE 'SELECT txid_current()'; RETURN true; -END; -$function$; - -create index -concurrently "concur_index8" -on concur_heap -using btree -( - f1 -) -where - predicate_stable(); +END; $$; + +create index concurrently concur_index8 on concur_heap using btree (f1) +where predicate_stable(); drop index concur_index8; @@ -863,17 +708,17 @@ drop function predicate_stable(); begin; -create index "std_index" on concur_heap using btree (f2); +create index std_index on concur_heap using btree (f2); commit; -vacuum (FULL) concur_heap; +vacuum (full) concur_heap; reindex table concur_heap; delete from concur_heap where f1 = 'b'; -vacuum (FULL) concur_heap; +vacuum (full) concur_heap; reindex table concur_heap; @@ -885,7 +730,7 @@ on commit preserve rows; insert into concur_temp values (1, 'foo'), (2, 'bar'); -create index concurrently "concur_temp_ind" on concur_temp using btree (f1); +create index concurrently concur_temp_ind on concur_temp using btree (f1); drop index concurrently concur_temp_ind; @@ -901,13 +746,13 @@ on commit drop; insert into concur_temp values (1, 'foo'), (2, 'bar'); -create index concurrently "concur_temp_ind" on concur_temp using btree (f1); +create index concurrently concur_temp_ind on concur_temp using btree (f1); commit; insert into concur_temp values (1, 'foo'), (2, 'bar'); -create index concurrently "concur_temp_ind" on concur_temp using btree (f1); +create index concurrently concur_temp_ind on concur_temp using btree (f1); drop index concurrently concur_temp_ind; @@ -945,38 +790,38 @@ create table cwi_test ( insert into cwi_test values (1, 2), (3, 4), (5, 6); -create unique index "cwi_uniq_idx" on cwi_test using btree (a, b); +create unique index cwi_uniq_idx on cwi_test using btree (a, b); alter table cwi_test - add primary key using index "cwi_uniq_idx"; + add primary key using index cwi_uniq_idx; -create unique index "cwi_uniq2_idx" on cwi_test using btree (b, a); +create unique index cwi_uniq2_idx on cwi_test using btree (b, a); alter table cwi_test drop constraint cwi_uniq_idx, - add constraint "cwi_replaced_pkey" primary key using index "cwi_uniq2_idx"; + add constraint cwi_replaced_pkey primary key using index cwi_uniq2_idx; drop index cwi_replaced_pkey; -create unique index "cwi_uniq3_idx" on cwi_test using btree (a desc); +create unique index cwi_uniq3_idx on cwi_test using btree (a desc); alter table cwi_test - add unique using index "cwi_uniq3_idx"; + add unique using index cwi_uniq3_idx; -create unique index "cwi_uniq4_idx" on cwi_test using btree (b collate "POSIX"); +create unique index cwi_uniq4_idx on cwi_test using btree (b collate "POSIX"); alter table cwi_test - add unique using index "cwi_uniq4_idx"; + add unique using index cwi_uniq4_idx; drop table cwi_test; create table cwi_test (a int) -partition by HASH(a); +partition by hash(a); create unique index on cwi_test using btree (a); alter table cwi_test - add primary key using index "cwi_test_a_idx"; + add primary key using index cwi_test_a_idx; drop table cwi_test; @@ -985,10 +830,10 @@ create table cwi_test ( b int ); -create unique index "cwi_a_nnd" on cwi_test using btree (a) nulls not distinct; +create unique index cwi_a_nnd on cwi_test using btree (a) nulls not distinct; alter table cwi_test - add primary key using index "cwi_a_nnd"; + add primary key using index cwi_a_nnd; drop table cwi_test; @@ -998,31 +843,16 @@ create index on syscol_table using btree (ctid); create index on syscol_table using btree ((ctid >= '(1000,0)')); -create index -on syscol_table -using btree -( - a -) -where - ctid >= '(1000,0)'; +create index on syscol_table using btree (a) where ctid >= '(1000,0)'; drop table syscol_table; create table onek_with_null as select unique1, unique2 from onek; insert into onek_with_null (unique1, unique2) -values - (null, -1), - (null, 2147483647), - (null, null), - (100, null), - (500, null); - -create unique index "onek_nulltest" -on onek_with_null -using btree -( +values (null, -1), (null, 2147483647), (null, null), (100, null), (500, null); + +create unique index onek_nulltest on onek_with_null using btree ( unique2, unique1 ); @@ -1033,22 +863,22 @@ set enable_indexscan = 'on'; set enable_bitmapscan = 'on'; -select COUNT(*) from onek_with_null where unique1 is null; +select count(*) from onek_with_null where unique1 is null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is null; +select count(*) from onek_with_null where unique1 is null and unique2 is null; -select COUNT(*) from onek_with_null where unique1 is not null; +select count(*) from onek_with_null where unique1 is not null; select - COUNT(*) + count(*) from onek_with_null where unique1 is null and unique2 is not null; -select COUNT(*) from onek_with_null where unique1 is not null and unique1 > 500; +select count(*) from onek_with_null where unique1 is not null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique1 > 500; +select count(*) from onek_with_null where unique1 is null and unique1 > 500; select unique1, @@ -1063,38 +893,34 @@ limit 1; drop index onek_nulltest; -create unique index "onek_nulltest" -on onek_with_null -using btree -( +create unique index onek_nulltest on onek_with_null using btree ( unique2 desc, unique1 ); -select COUNT(*) from onek_with_null where unique1 is null; +select count(*) from onek_with_null where unique1 is null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is null; +select count(*) from onek_with_null where unique1 is null and unique2 is null; -select COUNT(*) from onek_with_null where unique1 is not null; +select count(*) from onek_with_null where unique1 is not null; select - COUNT(*) + count(*) from onek_with_null where unique1 is null and unique2 is not null; -select COUNT(*) from onek_with_null where unique1 is not null and unique1 > 500; +select count(*) from onek_with_null where unique1 is not null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique1 > 500; +select count(*) from onek_with_null where unique1 is null and unique1 > 500; select - COUNT(*) + count(*) from onek_with_null where - unique1 is null and - unique2 in (-1, 0, 1); + unique1 is null and unique2 in (-1, 0, 1); select unique1, @@ -1109,30 +935,27 @@ limit 1; drop index onek_nulltest; -create unique index "onek_nulltest" -on onek_with_null -using btree -( +create unique index onek_nulltest on onek_with_null using btree ( unique2 desc nulls last, unique1 ); -select COUNT(*) from onek_with_null where unique1 is null; +select count(*) from onek_with_null where unique1 is null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is null; +select count(*) from onek_with_null where unique1 is null and unique2 is null; -select COUNT(*) from onek_with_null where unique1 is not null; +select count(*) from onek_with_null where unique1 is not null; select - COUNT(*) + count(*) from onek_with_null where unique1 is null and unique2 is not null; -select COUNT(*) from onek_with_null where unique1 is not null and unique1 > 500; +select count(*) from onek_with_null where unique1 is not null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique1 > 500; +select count(*) from onek_with_null where unique1 is null and unique1 > 500; select unique1, @@ -1147,30 +970,27 @@ limit 1; drop index onek_nulltest; -create unique index "onek_nulltest" -on onek_with_null -using btree -( +create unique index onek_nulltest on onek_with_null using btree ( unique2 nulls first, unique1 ); -select COUNT(*) from onek_with_null where unique1 is null; +select count(*) from onek_with_null where unique1 is null; -select COUNT(*) from onek_with_null where unique1 is null and unique2 is null; +select count(*) from onek_with_null where unique1 is null and unique2 is null; -select COUNT(*) from onek_with_null where unique1 is not null; +select count(*) from onek_with_null where unique1 is not null; select - COUNT(*) + count(*) from onek_with_null where unique1 is null and unique2 is not null; -select COUNT(*) from onek_with_null where unique1 is not null and unique1 > 500; +select count(*) from onek_with_null where unique1 is not null and unique1 > 500; -select COUNT(*) from onek_with_null where unique1 is null and unique1 > 500; +select count(*) from onek_with_null where unique1 is null and unique1 > 500; select unique1, @@ -1185,7 +1005,7 @@ limit 1; drop index onek_nulltest; -create unique index "onek_nulltest" on onek_with_null using btree (unique2); +create unique index onek_nulltest on onek_with_null using btree (unique2); set enable_seqscan = off; @@ -1252,10 +1072,7 @@ from where thousand = 42 and ( - tenthous = 1 or - tenthous = 3 or - tenthous = 42 or - tenthous = 0 + tenthous = 1 or tenthous = 3 or tenthous = 42 or tenthous = 0 ); select @@ -1265,10 +1082,7 @@ from where thousand = 42 and ( - tenthous = 1 or - tenthous = 3 or - tenthous = 42 or - tenthous = 0 + tenthous = 1 or tenthous = 3 or tenthous = 42 or tenthous = 0 ); select @@ -1278,9 +1092,7 @@ from where thousand = 42 and ( - tenthous = 1 or - tenthous = (select 1 + 2) or - tenthous = 42 + tenthous = 1 or tenthous = (select 1 + 2) or tenthous = 42 ); select @@ -1290,9 +1102,7 @@ from where thousand = 42 and ( - tenthous = 1 or - tenthous = (select 1 + 2) or - tenthous = 42 + tenthous = 1 or tenthous = (select 1 + 2) or tenthous = 42 ); select @@ -1302,10 +1112,7 @@ from where thousand = 42 and ( - tenthous = 1 or - tenthous = 3 or - tenthous = 42 or - tenthous is null + tenthous = 1 or tenthous = 3 or tenthous = 42 or tenthous is null ); select @@ -1315,10 +1122,9 @@ from where thousand = 42 and ( - tenthous = cast(1 as smallint) or - cast(tenthous as smallint) = - cast(3 as bigint) or - tenthous = cast(42 as bigint) + tenthous = cast(1 as int2) or + cast(tenthous as int2) = cast(3 as int8) or + tenthous = cast(42 as int8) ); select @@ -1328,11 +1134,9 @@ from where thousand = 42 and ( - tenthous = cast(1 as smallint) or - cast(tenthous as smallint) = - cast(3 as bigint) or - cast(tenthous as smallint) = - cast(42 as bigint) + tenthous = cast(1 as int2) or + cast(tenthous as int2) = cast(3 as int8) or + cast(tenthous as int2) = cast(42 as int8) ); select @@ -1342,54 +1146,38 @@ from where thousand = 42 and ( - tenthous = cast(1 as smallint) or - tenthous = cast(3 as bigint) or - tenthous = cast(42 as bigint) + tenthous = cast(1 as int2) or + tenthous = cast(3 as int8) or + tenthous = cast(42 as int8) ); select - COUNT(*) + count(*) from tenk1 where - hundred = 42 and - ( - thousand = 42 or thousand = 99 - ); + hundred = 42 and (thousand = 42 or thousand = 99); select - COUNT(*) + count(*) from tenk1 where - hundred = 42 and - ( - thousand = 42 or thousand = 99 - ); + hundred = 42 and (thousand = 42 or thousand = 99); select * from tenk1 where - thousand = 42 and - ( - tenthous = 1 or - tenthous = 3 or - tenthous = 42 - ); + thousand = 42 and (tenthous = 1 or tenthous = 3 or tenthous = 42); select * from tenk1 where - thousand = 42 and - ( - tenthous = 1 or - tenthous = 3 or - tenthous = 42 - ); + thousand = 42 and (tenthous = 1 or tenthous = 3 or tenthous = 42); select * @@ -1399,7 +1187,7 @@ where thousand = 42 and ( tenthous = cast(1 as numeric) or - tenthous = cast(3 as int) or + tenthous = cast(3 as int4) or tenthous = cast(42 as numeric) ); @@ -1409,11 +1197,11 @@ from tenk1 where tenthous = cast(1 as numeric) or - tenthous = cast(3 as int) or + tenthous = cast(3 as int4) or tenthous = cast(42 as numeric); select - COUNT(*) + count(*) from tenk1 as t1 where @@ -1430,7 +1218,7 @@ where ); select - COUNT(*) + count(*) from tenk1 as t1 where @@ -1447,191 +1235,142 @@ where ); select - COUNT(*) + count(*) from tenk1 where - hundred = 42 and - ( - thousand = 42 or thousand = 99 - ); + hundred = 42 and (thousand = 42 or thousand = 99); select - COUNT(*) + count(*) from tenk1 where - hundred = 42 and - ( - thousand = 42 or thousand = 99 - ); + hundred = 42 and (thousand = 42 or thousand = 99); select - COUNT(*) + count(*) from tenk1 where hundred = 42 and ( - thousand < 42 or - thousand < 99 or - 43 > thousand or - 42 > thousand + thousand < 42 or thousand < 99 or 43 > thousand or 42 > thousand ); select - COUNT(*) + count(*) from tenk1 where hundred = 42 and ( - thousand < 42 or - thousand < 99 or - 43 > thousand or - 42 > thousand + thousand < 42 or thousand < 99 or 43 > thousand or 42 > thousand ); select - COUNT(*) + count(*) from tenk1 where - (thousand = 42 and - ( - tenthous = 1 or tenthous = 3 - )) or - thousand = 41; + (thousand = 42 and (tenthous = 1 or tenthous = 3)) or thousand = 41; select - COUNT(*) + count(*) from tenk1 where - (thousand = 42 and - ( - tenthous = 1 or tenthous = 3 - )) or - thousand = 41; + (thousand = 42 and (tenthous = 1 or tenthous = 3)) or thousand = 41; select - COUNT(*) + count(*) from tenk1 where - (hundred = 42 and - ( - thousand = 42 or - thousand = 99 or - tenthous < 2 - )) or + (hundred = 42 and (thousand = 42 or thousand = 99 or tenthous < 2)) or thousand = 41; select - COUNT(*) + count(*) from tenk1 where - (hundred = 42 and - ( - thousand = 42 or - thousand = 99 or - tenthous < 2 - )) or + (hundred = 42 and (thousand = 42 or thousand = 99 or tenthous < 2)) or thousand = 41; select - COUNT(*) + count(*) from tenk1 where hundred = 42 and ( - thousand = 42 or - thousand = 41 or - (thousand = 99 and tenthous = 2) + thousand = 42 or thousand = 41 or (thousand = 99 and tenthous = 2) ); select - COUNT(*) + count(*) from tenk1 where hundred = 42 and ( - thousand = 42 or - thousand = 41 or - (thousand = 99 and tenthous = 2) + thousand = 42 or thousand = 41 or (thousand = 99 and tenthous = 2) ); select - COUNT(*) + count(*) from tenk1, tenk2 where tenk1.hundred = 42 and ( - tenk2.thousand = 42 or - tenk1.thousand = 41 or - tenk2.tenthous = 2 + tenk2.thousand = 42 or tenk1.thousand = 41 or tenk2.tenthous = 2 ) and tenk2.hundred = tenk1.hundred; select - COUNT(*) + count(*) from tenk1, tenk2 where tenk1.hundred = 42 and ( - tenk2.thousand = 42 or - tenk2.thousand = 41 or - tenk2.tenthous = 2 + tenk2.thousand = 42 or tenk2.thousand = 41 or tenk2.tenthous = 2 ) and tenk2.hundred = tenk1.hundred; select - COUNT(*) + count(*) from tenk1 inner join tenk2 on tenk1.hundred = 42 and ( - tenk2.thousand = 42 or - tenk2.thousand = 41 or - tenk2.tenthous = 2 + tenk2.thousand = 42 or tenk2.thousand = 41 or tenk2.tenthous = 2 ) and tenk2.hundred = tenk1.hundred; select - COUNT(*) + count(*) from tenk1 left outer join tenk2 on tenk1.hundred = 42 and ( - tenk2.thousand = 42 or - tenk2.thousand = 41 or - tenk2.tenthous = 2 + tenk2.thousand = 42 or tenk2.thousand = 41 or tenk2.tenthous = 2 ) and tenk2.hundred = tenk1.hundred; create table dupindexcols as - select - unique1 as id, - cast(stringu2 as text) as f1 - from - tenk1; + select unique1 as id, cast(stringu2 as text) as f1 from tenk1; -create index "dupindexcols_i" -on dupindexcols -using btree -( +create index dupindexcols_i on dupindexcols using btree ( f1, id, f1 text_pattern_ops @@ -1640,22 +1379,18 @@ using btree analyze dupindexcols; select - COUNT(*) + count(*) from dupindexcols where - f1 between 'WA' and 'ZZZ' and - id < 1000 and - f1 ~<~ 'YX'; + f1 between 'WA' and 'ZZZ' and id < 1000 and f1 ~<~ 'YX'; select - COUNT(*) + count(*) from dupindexcols where - f1 between 'WA' and 'ZZZ' and - id < 1000 and - f1 ~<~ 'YX'; + f1 between 'WA' and 'ZZZ' and id < 1000 and f1 ~<~ 'YX'; select unique1 from tenk1 where unique1 in (1, 42, 7) order by unique1; @@ -1667,8 +1402,7 @@ select from tenk1 where - thousand < 2 and - tenthous in (1001, 3000) + thousand < 2 and tenthous in (1001, 3000) order by thousand; select @@ -1677,8 +1411,7 @@ select from tenk1 where - thousand < 2 and - tenthous in (1001, 3000) + thousand < 2 and tenthous in (1001, 3000) order by thousand; select @@ -1687,8 +1420,7 @@ select from tenk1 where - thousand < 2 and - tenthous in (1001, 3000) + thousand < 2 and tenthous in (1001, 3000) order by thousand desc, tenthous desc; @@ -1698,8 +1430,7 @@ select from tenk1 where - thousand < 2 and - tenthous in (1001, 3000) + thousand < 2 and tenthous in (1001, 3000) order by thousand desc, tenthous desc; @@ -1709,8 +1440,7 @@ select from tenk1 where - thousand > 995 and - tenthous in (998, 999) + thousand > 995 and tenthous in (998, 999) order by thousand desc; select @@ -1719,8 +1449,7 @@ select from tenk1 where - thousand > 995 and - tenthous in (998, 999) + thousand > 995 and tenthous in (998, 999) order by thousand desc; select @@ -1728,16 +1457,14 @@ select from tenk1 where - unique1 in (1, 42, 7) and - unique1 = any ('{7, 8, 9}'); + unique1 in (1, 42, 7) and unique1 = any ('{7, 8, 9}'); select unique1 from tenk1 where - unique1 in (1, 42, 7) and - unique1 = any ('{7, 8, 9}'); + unique1 in (1, 42, 7) and unique1 = any ('{7, 8, 9}'); select unique1 @@ -1800,16 +1527,14 @@ select from tenk1 where - unique1 in (1, 42, 7) and - unique1 < cast(-1 as bigint); + unique1 in (1, 42, 7) and unique1 < cast(-1 as bigint); select unique1 from tenk1 where - unique1 in (1, 42, 7) and - unique1 < cast(-1 as bigint); + unique1 in (1, 42, 7) and unique1 < cast(-1 as bigint); select unique1 from tenk1 where (thousand, tenthous) > (null, 5); @@ -1821,9 +1546,7 @@ select from tenk1 where - thousand > -1 and - thousand >= 0 and - tenthous = 3000 + thousand > -1 and thousand >= 0 and tenthous = 3000 order by thousand; select @@ -1832,9 +1555,7 @@ select from tenk1 where - thousand > -1 and - thousand >= 0 and - tenthous = 3000 + thousand > -1 and thousand >= 0 and tenthous = 3000 order by thousand; select @@ -1843,9 +1564,7 @@ select from tenk1 where - thousand < 3 and - thousand <= 2 and - tenthous = 1001 + thousand < 3 and thousand <= 2 and tenthous = 1001 order by thousand; select @@ -1854,9 +1573,7 @@ select from tenk1 where - thousand < 3 and - thousand <= 2 and - tenthous = 1001 + thousand < 3 and thousand <= 2 and tenthous = 1001 order by thousand; select @@ -1865,8 +1582,7 @@ select from tenk1 where - thousand > -1 and - tenthous in (1001, 3000) + thousand > -1 and tenthous in (1001, 3000) order by thousand limit 2; @@ -1876,15 +1592,14 @@ select from tenk1 where - thousand > -1 and - tenthous in (1001, 3000) + thousand > -1 and tenthous in (1001, 3000) order by thousand limit 2; select * from tenk1 where (thousand, tenthous) in ((1, 1001), (null, null)); create temporary table boolindex ( - b boolean, + b bool, i int, unique (b, i), junk double precision @@ -1904,7 +1619,7 @@ select * from boolindex where b is false order by i desc limit 10; create table reindex_verbose (id int primary key); -reindex (VERBOSE) table reindex_verbose; +reindex (verbose) table reindex_verbose; drop table reindex_verbose; @@ -1912,40 +1627,23 @@ create table concur_reindex_tab (c1 int); reindex table concur_reindex_tab; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; alter table concur_reindex_tab add column c2 text; -create unique -index "concur_reindex_ind1" -on concur_reindex_tab -using btree -( - c1 -); +create unique index concur_reindex_ind1 on concur_reindex_tab using btree (c1); -create index "concur_reindex_ind2" on concur_reindex_tab using btree (c2); +create index concur_reindex_ind2 on concur_reindex_tab using btree (c2); -create unique -index "concur_reindex_ind3" -on concur_reindex_tab -using btree -( +create unique index concur_reindex_ind3 on concur_reindex_tab using btree ( (abs(c1)) ); -create index "concur_reindex_ind4" -on concur_reindex_tab -using btree -( - c1, - c1, - c2 -); +create index concur_reindex_ind4 on concur_reindex_tab using btree (c1, c1, c2); alter table concur_reindex_tab - add primary key using index "concur_reindex_ind1"; + add primary key using index concur_reindex_ind1; create table concur_reindex_tab2 (c1 int references concur_reindex_tab); @@ -1961,9 +1659,9 @@ create table concur_reindex_tab3 ( insert into concur_reindex_tab3 values (3, '[1,2]'); -reindex (CONCURRENTLY) index concur_reindex_tab3_c2_excl; +reindex (concurrently) index concur_reindex_tab3_c2_excl; -reindex (CONCURRENTLY) table concur_reindex_tab3; +reindex (concurrently) table concur_reindex_tab3; insert into concur_reindex_tab3 values (4, '[2,4]'); @@ -1972,18 +1670,8 @@ as select * from concur_reindex_tab; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -1996,31 +1684,20 @@ where cast('concur_reindex_ind2' as regclass), cast('concur_reindex_ind3' as regclass), cast('concur_reindex_ind4' as regclass), - cast('concur_reindex_matview' - as regclass) + cast('concur_reindex_matview' as regclass) ) order by 1, 2; -reindex (CONCURRENTLY) index concur_reindex_ind1; +reindex (concurrently) index concur_reindex_ind1; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; -reindex (CONCURRENTLY) table concur_reindex_matview; +reindex (concurrently) table concur_reindex_matview; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -2033,15 +1710,14 @@ where cast('concur_reindex_ind2' as regclass), cast('concur_reindex_ind3' as regclass), cast('concur_reindex_ind4' as regclass), - cast('concur_reindex_matview' - as regclass) + cast('concur_reindex_matview' as regclass) ) order by 1, 2; create table testcomment (i int); -create index "testcomment_idx1" on testcomment using btree (i); +create index testcomment_idx1 on testcomment using btree (i); comment on index testcomment_idx1 is 'test comment'; @@ -2051,7 +1727,7 @@ reindex table testcomment; select obj_description(cast('testcomment_idx1' as regclass), 'pg_class'); -reindex (CONCURRENTLY) table testcomment; +reindex (concurrently) table testcomment; select obj_description(cast('testcomment_idx1' as regclass), 'pg_class'); @@ -2059,12 +1735,12 @@ drop table testcomment; create table concur_clustered (i int); -create index "concur_clustered_i_idx" on concur_clustered using btree (i); +create index concur_clustered_i_idx on concur_clustered using btree (i); alter table concur_clustered cluster on concur_clustered_i_idx; -reindex (CONCURRENTLY) table concur_clustered; +reindex (concurrently) table concur_clustered; select cast(indexrelid as regclass), @@ -2072,25 +1748,16 @@ select from pg_index where - indrelid = - cast('concur_clustered' as regclass); + indrelid = cast('concur_clustered' as regclass); drop table concur_clustered; create table concur_replident (i int not null); -create unique -index "concur_replident_i_idx" -on concur_replident -using btree -( - i -); +create unique index concur_replident_i_idx on concur_replident using btree (i); alter table concur_replident - replica identity - using index - concur_replident_i_idx; + replica identity using index concur_replident_i_idx; select cast(indexrelid as regclass), @@ -2098,10 +1765,9 @@ select from pg_index where - indrelid = - cast('concur_replident' as regclass); + indrelid = cast('concur_replident' as regclass); -reindex (CONCURRENTLY) table concur_replident; +reindex (concurrently) table concur_replident; select cast(indexrelid as regclass), @@ -2109,8 +1775,7 @@ select from pg_index where - indrelid = - cast('concur_replident' as regclass); + indrelid = cast('concur_replident' as regclass); drop table concur_replident; @@ -2120,23 +1785,17 @@ create table concur_appclass_tab ( k tsvector ); -create index "concur_appclass_ind" -on concur_appclass_tab -using gist -( +create index concur_appclass_ind on concur_appclass_tab using gist ( i tsvector_ops(siglen = "1000"), j tsvector_ops(siglen = "500") ); -create index "concur_appclass_ind_2" -on concur_appclass_tab -using gist -( +create index concur_appclass_ind_2 on concur_appclass_tab using gist ( k tsvector_ops(siglen = "300"), j tsvector_ops ); -reindex (CONCURRENTLY) table concur_appclass_tab; +reindex (concurrently) table concur_appclass_tab; drop table concur_appclass_tab; @@ -2149,7 +1808,7 @@ partition by range(c1); create table concur_reindex_part_0 partition of concur_reindex_part for values from (0) to (10) -partition by LIST(c2); +partition by list(c2); create table concur_reindex_part_0_1 partition of concur_reindex_part_0 @@ -2162,54 +1821,39 @@ for values in (2); create table concur_reindex_part_10 partition of concur_reindex_part for values from (10) to (20) -partition by LIST(c2); +partition by list(c2); -create index "concur_reindex_part_index" -on only concur_reindex_part -using btree -( +create index concur_reindex_part_index on only concur_reindex_part using btree ( c1 ); -create index "concur_reindex_part_index_0" -on only concur_reindex_part_0 -using btree -( - c1 -); +create index concur_reindex_part_index_0 + on only concur_reindex_part_0 + using btree (c1); alter index concur_reindex_part_index attach partition concur_reindex_part_index_0; -create index "concur_reindex_part_index_10" -on only concur_reindex_part_10 -using btree -( - c1 -); +create index concur_reindex_part_index_10 + on only concur_reindex_part_10 + using btree (c1); alter index concur_reindex_part_index attach partition concur_reindex_part_index_10; -create index "concur_reindex_part_index_0_1" -on only concur_reindex_part_0_1 -using btree -( - c1 -); +create index concur_reindex_part_index_0_1 + on only concur_reindex_part_0_1 + using btree (c1); alter index concur_reindex_part_index_0 attach partition concur_reindex_part_index_0_1; -create index "concur_reindex_part_index_0_2" -on only concur_reindex_part_0_2 -using btree -( - c1 -); +create index concur_reindex_part_index_0_2 + on only concur_reindex_part_0_2 + using btree (c1); alter index concur_reindex_part_index_0 attach partition @@ -2220,9 +1864,7 @@ select parentrelid, level from - pg_partition_tree( - 'concur_reindex_part_index' - ) + pg_partition_tree('concur_reindex_part_index') order by relid, level; @@ -2231,25 +1873,13 @@ select parentrelid, level from - pg_partition_tree( - 'concur_reindex_part_index' - ) + pg_partition_tree('concur_reindex_part_index') order by relid, level; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -2258,50 +1888,37 @@ where objid in ( cast('concur_reindex_part' as regclass), - cast('concur_reindex_part_0' - as regclass), cast('concur_reindex_part_0_1' - as regclass), cast('concur_reindex_part_0_2' - as regclass), cast('concur_reindex_part_index' - as regclass), cast('concur_reindex_part_index_0' - as regclass), cast('concur_reindex_part_index_0_1' - as regclass), cast('concur_reindex_part_index_0_2' - as regclass) + cast('concur_reindex_part_0' as regclass), + cast('concur_reindex_part_0_1' as regclass), + cast('concur_reindex_part_0_2' as regclass), + cast('concur_reindex_part_index' as regclass), + cast('concur_reindex_part_index_0' as regclass), + cast('concur_reindex_part_index_0_1' as regclass), + cast('concur_reindex_part_index_0_2' as regclass) ) order by 1, 2; -reindex (CONCURRENTLY) index concur_reindex_part_index_0_1; +reindex (concurrently) index concur_reindex_part_index_0_1; -reindex (CONCURRENTLY) index concur_reindex_part_index_0_2; +reindex (concurrently) index concur_reindex_part_index_0_2; select relid, parentrelid, level from - pg_partition_tree( - 'concur_reindex_part_index' - ) + pg_partition_tree('concur_reindex_part_index') order by relid, level; -reindex (CONCURRENTLY) table concur_reindex_part_0_1; +reindex (concurrently) table concur_reindex_part_0_1; -reindex (CONCURRENTLY) table concur_reindex_part_0_2; +reindex (concurrently) table concur_reindex_part_0_2; select - pg_describe_object( - classid, - objid, - objsubid - ) - as obj, - pg_describe_object( - refclassid, - refobjid, - refobjsubid - ) - as objref, + pg_describe_object(classid, objid, objsubid) as obj, + pg_describe_object(refclassid, refobjid, refobjsubid) as objref, deptype from pg_depend @@ -2310,14 +1927,13 @@ where objid in ( cast('concur_reindex_part' as regclass), - cast('concur_reindex_part_0' - as regclass), cast('concur_reindex_part_0_1' - as regclass), cast('concur_reindex_part_0_2' - as regclass), cast('concur_reindex_part_index' - as regclass), cast('concur_reindex_part_index_0' - as regclass), cast('concur_reindex_part_index_0_1' - as regclass), cast('concur_reindex_part_index_0_2' - as regclass) + cast('concur_reindex_part_0' as regclass), + cast('concur_reindex_part_0_1' as regclass), + cast('concur_reindex_part_0_2' as regclass), + cast('concur_reindex_part_index' as regclass), + cast('concur_reindex_part_index_0' as regclass), + cast('concur_reindex_part_index_0_1' as regclass), + cast('concur_reindex_part_index_0_2' as regclass) ) order by 1, 2; @@ -2327,19 +1943,17 @@ select parentrelid, level from - pg_partition_tree( - 'concur_reindex_part_index' - ) + pg_partition_tree('concur_reindex_part_index') order by relid, level; reindex table concur_reindex_part_index; -reindex (CONCURRENTLY) table concur_reindex_part_index; +reindex (concurrently) table concur_reindex_part_index; reindex table concur_reindex_part_index_10; -reindex (CONCURRENTLY) table concur_reindex_part_index_10; +reindex (concurrently) table concur_reindex_part_index_10; begin; @@ -2350,8 +1964,8 @@ rollback; create or replace function create_relfilenode_part(relname text, indname text) returns void language plpgsql -as $function$ -BEGIN +as $func$ + BEGIN EXECUTE format(' CREATE TABLE %I AS SELECT oid, relname, relfilenode, relkind, reltoastrelid @@ -2360,7 +1974,7 @@ BEGIN (SELECT relid FROM pg_partition_tree(''%I''));', relname, indname); END -$function$; + $func$; create or replace function compare_relfilenode_part(tabname text) returns table ( @@ -2369,8 +1983,8 @@ returns table ( state text ) language plpgsql -as $function$ -BEGIN +as $func$ + BEGIN RETURN QUERY EXECUTE format( 'SELECT b.relname, @@ -2381,13 +1995,10 @@ BEGIN FROM %I b JOIN pg_class a ON b.relname = a.relname ORDER BY 1;', tabname); END -$function$; + $func$; select - create_relfilenode_part( - 'reindex_index_status', - 'concur_reindex_part_index' - ); + create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); reindex index concur_reindex_part_index; @@ -2396,12 +2007,9 @@ select * from compare_relfilenode_part('reindex_index_status'); drop table reindex_index_status; select - create_relfilenode_part( - 'reindex_index_status', - 'concur_reindex_part_index' - ); + create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); -reindex (CONCURRENTLY) index concur_reindex_part_index; +reindex (concurrently) index concur_reindex_part_index; select * from compare_relfilenode_part('reindex_index_status'); @@ -2409,11 +2017,11 @@ drop table reindex_index_status; reindex index concur_reindex_part; -reindex (CONCURRENTLY) index concur_reindex_part; +reindex (concurrently) index concur_reindex_part; reindex index concur_reindex_part_10; -reindex (CONCURRENTLY) index concur_reindex_part_10; +reindex (concurrently) index concur_reindex_part_10; begin; @@ -2422,10 +2030,7 @@ reindex table concur_reindex_part; rollback; select - create_relfilenode_part( - 'reindex_index_status', - 'concur_reindex_part_index' - ); + create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); reindex table concur_reindex_part; @@ -2434,12 +2039,9 @@ select * from compare_relfilenode_part('reindex_index_status'); drop table reindex_index_status; select - create_relfilenode_part( - 'reindex_index_status', - 'concur_reindex_part_index' - ); + create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); -reindex (CONCURRENTLY) table concur_reindex_part; +reindex (concurrently) table concur_reindex_part; select * from compare_relfilenode_part('reindex_index_status'); @@ -2453,25 +2055,25 @@ drop table concur_reindex_part; begin; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; commit; -reindex (CONCURRENTLY) table pg_class; +reindex (concurrently) table pg_class; -reindex (CONCURRENTLY) index pg_class_oid_index; +reindex (concurrently) index pg_class_oid_index; -reindex (CONCURRENTLY) table pg_toast.pg_toast_1262; +reindex (concurrently) table pg_toast.pg_toast_1262; -reindex (CONCURRENTLY) index pg_toast.pg_toast_1262_index; +reindex (concurrently) index pg_toast.pg_toast_1262_index; -reindex (CONCURRENTLY) system postgres; +reindex (concurrently) system postgres; -reindex (CONCURRENTLY) system postgres; +reindex (concurrently) system postgres; -reindex (CONCURRENTLY) system ; +reindex (concurrently) system ; -reindex (CONCURRENTLY) schema pg_catalog; +reindex (concurrently) schema pg_catalog; reindex database not_current_database; @@ -2483,24 +2085,19 @@ create table concur_reindex_tab4 (c1 int); insert into concur_reindex_tab4 values (1), (1), (2); -create unique -index -concurrently "concur_reindex_ind5" -on concur_reindex_tab4 -using btree -( - c1 -); +create unique index concurrently concur_reindex_ind5 + on concur_reindex_tab4 + using btree (c1); -reindex (CONCURRENTLY) index concur_reindex_ind5; +reindex (concurrently) index concur_reindex_ind5; drop index concur_reindex_ind5_ccnew; delete from concur_reindex_tab4 where c1 = 1; -reindex (CONCURRENTLY) table concur_reindex_tab4; +reindex (concurrently) table concur_reindex_tab4; -reindex (CONCURRENTLY) index concur_reindex_ind5; +reindex (concurrently) index concur_reindex_ind5; drop table concur_reindex_tab4; @@ -2510,39 +2107,19 @@ create table concur_exprs_tab ( ); insert into concur_exprs_tab (c1, c2) -values - (1369652450, false), - (414515746, true), - (897778963, false); - -create unique -index "concur_exprs_index_expr" -on concur_exprs_tab -using btree -( +values (1369652450, false), (414515746, true), (897778963, false); + +create unique index concur_exprs_index_expr on concur_exprs_tab using btree ( (cast(c1 as text) collate "C") ); -create unique -index "concur_exprs_index_pred" -on concur_exprs_tab -using btree -( - c1 -) -where - cast(c1 as text) > - cast(500000000 as text) collate "C"; +create unique index concur_exprs_index_pred on concur_exprs_tab using btree (c1) +where cast(c1 as text) > cast(500000000 as text) collate "C"; -create unique -index "concur_exprs_index_pred_2" -on concur_exprs_tab -using btree -( +create unique index concur_exprs_index_pred_2 on concur_exprs_tab using btree ( (1 / c1) ) -where - '-H' >= cast(c2 as text) collate "C"; +where '-H' >= cast(c2 as text) collate "C"; alter index concur_exprs_index_expr alter column 1 set statistics 100; @@ -2551,16 +2128,15 @@ analyze concur_exprs_tab; select cast(starelid as regclass), - COUNT(*) + count(*) from pg_statistic where starelid in ( - cast('concur_exprs_index_expr' - as regclass), cast('concur_exprs_index_pred' - as regclass), cast('concur_exprs_index_pred_2' - as regclass) + cast('concur_exprs_index_expr' as regclass), + cast('concur_exprs_index_pred' as regclass), + cast('concur_exprs_index_pred_2' as regclass) ) group by starelid order by cast(cast(starelid as regclass) as text); @@ -2571,7 +2147,7 @@ select pg_get_indexdef(cast('concur_exprs_index_pred' as regclass)); select pg_get_indexdef(cast('concur_exprs_index_pred_2' as regclass)); -reindex (CONCURRENTLY) table concur_exprs_tab; +reindex (concurrently) table concur_exprs_tab; select pg_get_indexdef(cast('concur_exprs_index_expr' as regclass)); @@ -2590,16 +2166,15 @@ select pg_get_indexdef(cast('concur_exprs_index_pred_2' as regclass)); select cast(starelid as regclass), - COUNT(*) + count(*) from pg_statistic where starelid in ( - cast('concur_exprs_index_expr' - as regclass), cast('concur_exprs_index_pred' - as regclass), cast('concur_exprs_index_pred_2' - as regclass) + cast('concur_exprs_index_expr' as regclass), + cast('concur_exprs_index_pred' as regclass), + cast('concur_exprs_index_pred_2' as regclass) ) group by starelid order by cast(cast(starelid as regclass) as text); @@ -2613,10 +2188,9 @@ from where attrelid in ( - cast('concur_exprs_index_expr' - as regclass), cast('concur_exprs_index_pred' - as regclass), cast('concur_exprs_index_pred_2' - as regclass) + cast('concur_exprs_index_expr' as regclass), + cast('concur_exprs_index_pred' as regclass), + cast('concur_exprs_index_pred_2' as regclass) ) order by cast(cast(attrelid as regclass) as text), attnum; @@ -2631,23 +2205,23 @@ on commit preserve rows; insert into concur_temp_tab_1 values (1, 'foo'), (2, 'bar'); -create index "concur_temp_ind_1" on concur_temp_tab_1 using btree (c2); +create index concur_temp_ind_1 on concur_temp_tab_1 using btree (c2); -reindex (CONCURRENTLY) table concur_temp_tab_1; +reindex (concurrently) table concur_temp_tab_1; -reindex (CONCURRENTLY) index concur_temp_ind_1; +reindex (concurrently) index concur_temp_ind_1; begin; -reindex (CONCURRENTLY) index concur_temp_ind_1; +reindex (concurrently) index concur_temp_ind_1; commit; -create index "concur_temp_ind_2" on concur_temp_tab_2 using btree (c2); +create index concur_temp_ind_2 on concur_temp_tab_2 using btree (c2); -reindex (CONCURRENTLY) table concur_temp_tab_2; +reindex (concurrently) table concur_temp_tab_2; -reindex (CONCURRENTLY) index concur_temp_ind_2; +reindex (concurrently) index concur_temp_ind_2; begin; @@ -2659,9 +2233,9 @@ on commit preserve rows; insert into concur_temp_tab_3 values (1, 'foo'), (2, 'bar'); -create index "concur_temp_ind_3" on concur_temp_tab_3 using btree (c2); +create index concur_temp_ind_3 on concur_temp_tab_3 using btree (c2); -reindex (CONCURRENTLY) index concur_temp_ind_3; +reindex (concurrently) index concur_temp_ind_3; commit; @@ -2676,10 +2250,7 @@ as from pg_class where - relname - in ( - 'concur_temp_ind_1', 'concur_temp_ind_2' - ); + relname in ('concur_temp_ind_1', 'concur_temp_ind_2'); select cast(pg_my_temp_schema() as regnamespace) as temp_schema_name; @@ -2687,15 +2258,11 @@ select b.relname, b.relkind, case - when a.relfilenode = b.relfilenode - then 'relfilenode is unchanged' + when a.relfilenode = b.relfilenode then 'relfilenode is unchanged' else 'relfilenode has changed' end from - reindex_temp_before as b - inner join - pg_class as a - on b.oid = a.oid + reindex_temp_before as b inner join pg_class as a on b.oid = a.oid order by 1; drop table concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before; @@ -2714,25 +2281,11 @@ insert into bitmap_split_or select 1, 1, i from generate_series(1, 1000) as i; insert into bitmap_split_or select i, 2, 2 from generate_series(1, 1000) as i; -vacuum (ANALYZE) bitmap_split_or; +vacuum (analyze) bitmap_split_or; -create index "t_b_partial_1_idx" -on bitmap_split_or -using btree -( - b -) -where - a = 1; +create index t_b_partial_1_idx on bitmap_split_or using btree (b) where a = 1; -create index "t_b_partial_2_idx" -on bitmap_split_or -using btree -( - b -) -where - a = 2; +create index t_b_partial_2_idx on bitmap_split_or using btree (b) where a = 2; select * from bitmap_split_or where (a = 1 or a = 2) and b = 2; @@ -2740,13 +2293,13 @@ drop index t_b_partial_1_idx; drop index t_b_partial_2_idx; -create index "t_a_b_idx" on bitmap_split_or using btree (a, b); +create index t_a_b_idx on bitmap_split_or using btree (a, b); -create index "t_b_c_idx" on bitmap_split_or using btree (b, c); +create index t_b_c_idx on bitmap_split_or using btree (b, c); -create statistics t_a_b_stat (mcv) on "a", "b" from bitmap_split_or; +create statistics t_a_b_stat (mcv) on a, b from bitmap_split_or; -create statistics t_b_c_stat (mcv) on "b", "c" from bitmap_split_or; +create statistics t_b_c_stat (mcv) on b, c from bitmap_split_or; analyze bitmap_split_or; @@ -2764,7 +2317,7 @@ drop table bitmap_split_or; reindex schema schema_to_reindex; -create schema "schema_to_reindex"; +create schema schema_to_reindex; set search_path to schema_to_reindex; @@ -2800,14 +2353,7 @@ as pg_class where relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'schema_to_reindex' - ); + (select oid from pg_namespace where nspname = 'schema_to_reindex'); insert into reindex_before select @@ -2819,15 +2365,7 @@ select from pg_class where - oid in - ( - select - reltoastrelid - from - reindex_before - where - reltoastrelid > 0 - ); + oid in (select reltoastrelid from reindex_before where reltoastrelid > 0); insert into reindex_before select @@ -2848,12 +2386,7 @@ where where indrelid in ( - select - reltoastrelid - from - reindex_before - where - reltoastrelid > 0 + select reltoastrelid from reindex_before where reltoastrelid > 0 ) ); @@ -2870,28 +2403,17 @@ as pg_class where relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'schema_to_reindex' - ); + (select oid from pg_namespace where nspname = 'schema_to_reindex'); select b.relname, b.relkind, case - when a.relfilenode = b.relfilenode - then 'relfilenode is unchanged' + when a.relfilenode = b.relfilenode then 'relfilenode is unchanged' else 'relfilenode has changed' end from - reindex_before as b - inner join - pg_class as a - on b.oid = a.oid + reindex_before as b inner join pg_class as a on b.oid = a.oid order by 1; reindex schema schema_to_reindex; @@ -2902,7 +2424,7 @@ reindex schema schema_to_reindex; commit; -reindex (CONCURRENTLY) schema schema_to_reindex; +reindex (concurrently) schema schema_to_reindex; create role regress_reindexuser nologin; @@ -2912,7 +2434,7 @@ reindex schema schema_to_reindex; reset role; -grant USAGE on schema pg_toast to regress_reindexuser; +grant usage on schema pg_toast to regress_reindexuser; set role to regress_reindexuser; @@ -2922,7 +2444,7 @@ reindex index pg_toast.pg_toast_1262_index; reset role; -revoke USAGE on schema pg_toast from regress_reindexuser; +revoke usage on schema pg_toast from regress_reindexuser; drop role regress_reindexuser; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_spgist_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_spgist_100.snap index 523788de8..eb5c310b9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_spgist_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_spgist_100.snap @@ -9,11 +9,11 @@ insert into quad_point_tbl select cast('(333.0,400.0)' as point) from generate_s insert into quad_point_tbl values (null), (null), (null); -create index "sp_quad_ind" on quad_point_tbl using spgist (p); +create index sp_quad_ind on quad_point_tbl using spgist (p); create table kd_point_tbl as select * from quad_point_tbl; -create index "sp_kd_ind" on kd_point_tbl using spgist (p kd_point_ops); +create index sp_kd_ind on kd_point_tbl using spgist (p kd_point_ops); create table radix_text_tbl as select name as t from road where name !~ '^[0-9]'; @@ -23,7 +23,7 @@ insert into radix_text_tbl values ('P0123456789abcde'); insert into radix_text_tbl values ('P0123456789abcdefF'); -create index "sp_radix_ind" on radix_text_tbl using spgist (t); +create index sp_radix_ind on radix_text_tbl using spgist (t); set enable_seqscan = 'on'; @@ -31,39 +31,34 @@ set enable_indexscan = off; set enable_bitmapscan = off; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; -select COUNT(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; create temporary table quad_point_tbl_ord_seq1 as - select - ROW_NUMBER() over (order by p <-> '0,0') as n, - p <-> '0,0' as dist, - p - from - quad_point_tbl; + select row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from quad_point_tbl; create temporary table quad_point_tbl_ord_seq2 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -74,7 +69,7 @@ as create temporary table quad_point_tbl_ord_seq3 as select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -82,33 +77,33 @@ as where p is not null; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; -select COUNT(*) from radix_text_tbl where t < 'Aztec Ct '; +select count(*) from radix_text_tbl where t < 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t <= 'Aztec Ct '; +select count(*) from radix_text_tbl where t <= 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t = 'Aztec Ct '; +select count(*) from radix_text_tbl where t = 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t = 'Worth St '; +select count(*) from radix_text_tbl where t = 'Worth St '; -select COUNT(*) from radix_text_tbl where t >= 'Worth St '; +select count(*) from radix_text_tbl where t >= 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>=~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>=~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t > 'Worth St '; +select count(*) from radix_text_tbl where t > 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; set enable_seqscan = off; @@ -116,69 +111,61 @@ set enable_indexscan = 'on'; set enable_bitmapscan = off; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; -select COUNT(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; -select ROW_NUMBER() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from quad_point_tbl; +select row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from quad_point_tbl; create temporary table quad_point_tbl_ord_idx1 as - select - ROW_NUMBER() over (order by p <-> '0,0') as n, - p <-> '0,0' as dist, - p - from - quad_point_tbl; + select row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from quad_point_tbl; select * from - quad_point_tbl_ord_seq1 as seq - full outer join - quad_point_tbl_ord_idx1 as idx - on seq.n = idx.n + quad_point_tbl_ord_seq1 as seq full outer join quad_point_tbl_ord_idx1 as idx on seq.n = idx.n where seq.dist is distinct from idx.dist; select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -189,7 +176,7 @@ where create temporary table quad_point_tbl_ord_idx2 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -200,15 +187,12 @@ as select * from - quad_point_tbl_ord_seq2 as seq - full outer join - quad_point_tbl_ord_idx2 as idx - on seq.n = idx.n + quad_point_tbl_ord_seq2 as seq full outer join quad_point_tbl_ord_idx2 as idx on seq.n = idx.n where seq.dist is distinct from idx.dist; select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -219,7 +203,7 @@ where create temporary table quad_point_tbl_ord_idx3 as select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -230,64 +214,53 @@ as select * from - quad_point_tbl_ord_seq3 as seq - full outer join - quad_point_tbl_ord_idx3 as idx - on seq.n = idx.n + quad_point_tbl_ord_seq3 as seq full outer join quad_point_tbl_ord_idx3 as idx on seq.n = idx.n where seq.dist is distinct from idx.dist; -select COUNT(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from kd_point_tbl where p << '(5000, 4000)'; +select count(*) from kd_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p << '(5000, 4000)'; +select count(*) from kd_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p >> '(5000, 4000)'; +select count(*) from kd_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p >> '(5000, 4000)'; +select count(*) from kd_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p <<| '(5000, 4000)'; +select count(*) from kd_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p <<| '(5000, 4000)'; +select count(*) from kd_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p |>> '(5000, 4000)'; +select count(*) from kd_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p |>> '(5000, 4000)'; +select count(*) from kd_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p ~= '(4585, 365)'; +select count(*) from kd_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from kd_point_tbl where p ~= '(4585, 365)'; +select count(*) from kd_point_tbl where p ~= '(4585, 365)'; -select ROW_NUMBER() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from kd_point_tbl; +select row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from kd_point_tbl; create temporary table kd_point_tbl_ord_idx1 as - select - ROW_NUMBER() over (order by p <-> '0,0') as n, - p <-> '0,0' as dist, - p - from - kd_point_tbl; + select row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from kd_point_tbl; select * from - quad_point_tbl_ord_seq1 as seq - full outer join - kd_point_tbl_ord_idx1 as idx - on seq.n = idx.n + quad_point_tbl_ord_seq1 as seq full outer join kd_point_tbl_ord_idx1 as idx on seq.n = idx.n where seq.dist is distinct from idx.dist; select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -298,7 +271,7 @@ where create temporary table kd_point_tbl_ord_idx2 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -309,15 +282,12 @@ as select * from - quad_point_tbl_ord_seq2 as seq - full outer join - kd_point_tbl_ord_idx2 as idx - on seq.n = idx.n + quad_point_tbl_ord_seq2 as seq full outer join kd_point_tbl_ord_idx2 as idx on seq.n = idx.n where seq.dist is distinct from idx.dist; select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -328,7 +298,7 @@ where create temporary table kd_point_tbl_ord_idx3 as select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -339,10 +309,7 @@ as select * from - quad_point_tbl_ord_seq3 as seq - full outer join - kd_point_tbl_ord_idx3 as idx - on seq.n = idx.n + quad_point_tbl_ord_seq3 as seq full outer join kd_point_tbl_ord_idx3 as idx on seq.n = idx.n where seq.dist is distinct from idx.dist; @@ -357,83 +324,69 @@ select p, dist from quad_point_tbl_ord_seq1 order by p <-> '0,0' limit 10; reset extra_float_digits; select - ( - select - p - from - kd_point_tbl - order by p <-> pt, - p <-> '0,0' - limit 1 - ) + (select p from kd_point_tbl order by p <-> pt, p <-> '0,0' limit 1) from - ( - values - (cast('1,2' as point)), - (null), - ('1234,5678') - ) - as pts (pt); + (values (cast('1,2' as point)), (null), ('1234,5678')) as pts (pt); -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; -select COUNT(*) from radix_text_tbl where t < 'Aztec Ct '; +select count(*) from radix_text_tbl where t < 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t < 'Aztec Ct '; +select count(*) from radix_text_tbl where t < 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t <= 'Aztec Ct '; +select count(*) from radix_text_tbl where t <= 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t <= 'Aztec Ct '; +select count(*) from radix_text_tbl where t <= 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t = 'Aztec Ct '; +select count(*) from radix_text_tbl where t = 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t = 'Aztec Ct '; +select count(*) from radix_text_tbl where t = 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t = 'Worth St '; +select count(*) from radix_text_tbl where t = 'Worth St '; -select COUNT(*) from radix_text_tbl where t = 'Worth St '; +select count(*) from radix_text_tbl where t = 'Worth St '; -select COUNT(*) from radix_text_tbl where t >= 'Worth St '; +select count(*) from radix_text_tbl where t >= 'Worth St '; -select COUNT(*) from radix_text_tbl where t >= 'Worth St '; +select count(*) from radix_text_tbl where t >= 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>=~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>=~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>=~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>=~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t > 'Worth St '; +select count(*) from radix_text_tbl where t > 'Worth St '; -select COUNT(*) from radix_text_tbl where t > 'Worth St '; +select count(*) from radix_text_tbl where t > 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; -select COUNT(*) from radix_text_tbl where starts_with(t, 'Worth'); +select count(*) from radix_text_tbl where starts_with(t, 'Worth'); -select COUNT(*) from radix_text_tbl where starts_with(t, 'Worth'); +select count(*) from radix_text_tbl where starts_with(t, 'Worth'); set enable_seqscan = off; @@ -441,133 +394,133 @@ set enable_indexscan = off; set enable_bitmapscan = 'on'; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; -select COUNT(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from kd_point_tbl where p << '(5000, 4000)'; +select count(*) from kd_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p << '(5000, 4000)'; +select count(*) from kd_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p >> '(5000, 4000)'; +select count(*) from kd_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p >> '(5000, 4000)'; +select count(*) from kd_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p <<| '(5000, 4000)'; +select count(*) from kd_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p <<| '(5000, 4000)'; +select count(*) from kd_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p |>> '(5000, 4000)'; +select count(*) from kd_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p |>> '(5000, 4000)'; +select count(*) from kd_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p ~= '(4585, 365)'; +select count(*) from kd_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from kd_point_tbl where p ~= '(4585, 365)'; +select count(*) from kd_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; -select COUNT(*) from radix_text_tbl where t < 'Aztec Ct '; +select count(*) from radix_text_tbl where t < 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t < 'Aztec Ct '; +select count(*) from radix_text_tbl where t < 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t <= 'Aztec Ct '; +select count(*) from radix_text_tbl where t <= 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t <= 'Aztec Ct '; +select count(*) from radix_text_tbl where t <= 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; +select count(*) from radix_text_tbl where t ~<=~ 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t = 'Aztec Ct '; +select count(*) from radix_text_tbl where t = 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t = 'Aztec Ct '; +select count(*) from radix_text_tbl where t = 'Aztec Ct '; -select COUNT(*) from radix_text_tbl where t = 'Worth St '; +select count(*) from radix_text_tbl where t = 'Worth St '; -select COUNT(*) from radix_text_tbl where t = 'Worth St '; +select count(*) from radix_text_tbl where t = 'Worth St '; -select COUNT(*) from radix_text_tbl where t >= 'Worth St '; +select count(*) from radix_text_tbl where t >= 'Worth St '; -select COUNT(*) from radix_text_tbl where t >= 'Worth St '; +select count(*) from radix_text_tbl where t >= 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>=~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>=~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>=~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>=~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t > 'Worth St '; +select count(*) from radix_text_tbl where t > 'Worth St '; -select COUNT(*) from radix_text_tbl where t > 'Worth St '; +select count(*) from radix_text_tbl where t > 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ~>~ 'Worth St '; +select count(*) from radix_text_tbl where t ~>~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; -select COUNT(*) from radix_text_tbl where starts_with(t, 'Worth'); +select count(*) from radix_text_tbl where starts_with(t, 'Worth'); -select COUNT(*) from radix_text_tbl where starts_with(t, 'Worth'); +select count(*) from radix_text_tbl where starts_with(t, 'Worth'); reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_spgist_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_spgist_80.snap index 53a41fda4..314d15c1e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_spgist_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_spgist_80.snap @@ -6,39 +6,28 @@ snapshot_kind: text create table quad_point_tbl as select point(unique1, unique2) as p from tenk1; insert into quad_point_tbl -select - cast('(333.0,400.0)' as point) -from - generate_series(1, 1000); +select cast('(333.0,400.0)' as point) from generate_series(1, 1000); insert into quad_point_tbl values (null), (null), (null); -create index "sp_quad_ind" on quad_point_tbl using spgist (p); +create index sp_quad_ind on quad_point_tbl using spgist (p); create table kd_point_tbl as select * from quad_point_tbl; -create index "sp_kd_ind" on kd_point_tbl using spgist (p kd_point_ops); +create index sp_kd_ind on kd_point_tbl using spgist (p kd_point_ops); create table radix_text_tbl as - select - name as t - from - road - where - name !~ '^[0-9]'; + select name as t from road where name !~ '^[0-9]'; insert into radix_text_tbl -select - 'P0123456789abcdef' -from - generate_series(1, 1000); +select 'P0123456789abcdef' from generate_series(1, 1000); insert into radix_text_tbl values ('P0123456789abcde'); insert into radix_text_tbl values ('P0123456789abcdefF'); -create index "sp_radix_ind" on radix_text_tbl using spgist (t); +create index sp_radix_ind on radix_text_tbl using spgist (t); set enable_seqscan = 'on'; @@ -46,40 +35,40 @@ set enable_indexscan = off; set enable_bitmapscan = off; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; select - COUNT(*) + count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); select - COUNT(*) + count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; create temporary table quad_point_tbl_ord_seq1 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -88,7 +77,7 @@ as create temporary table quad_point_tbl_ord_seq2 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -99,7 +88,7 @@ as create temporary table quad_point_tbl_ord_seq3 as select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -107,89 +96,83 @@ as where p is not null; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; select - COUNT(*) + count(*) from radix_text_tbl where t < 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<~ - 'Aztec Ct '; + t ~<~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t <= - 'Aztec Ct '; + t <= 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<=~ - 'Aztec Ct '; + t ~<=~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t >= - 'Worth St '; + t >= 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>=~ - 'Worth St '; + t ~>=~ 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where t > 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>~ - 'Worth St '; + t ~>~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; set enable_seqscan = off; @@ -197,68 +180,68 @@ set enable_indexscan = 'on'; set enable_bitmapscan = off; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; select - COUNT(*) + count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); select - COUNT(*) + count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); select - COUNT(*) + count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; select - COUNT(*) + count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -267,7 +250,7 @@ from create temporary table quad_point_tbl_ord_idx1 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -284,7 +267,7 @@ where seq.dist is distinct from idx.dist; select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -295,7 +278,7 @@ where create temporary table quad_point_tbl_ord_idx2 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -314,7 +297,7 @@ where seq.dist is distinct from idx.dist; select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -325,7 +308,7 @@ where create temporary table quad_point_tbl_ord_idx3 as select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -343,36 +326,36 @@ from where seq.dist is distinct from idx.dist; -select COUNT(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from kd_point_tbl where p << '(5000, 4000)'; +select count(*) from kd_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p << '(5000, 4000)'; +select count(*) from kd_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p >> '(5000, 4000)'; +select count(*) from kd_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p >> '(5000, 4000)'; +select count(*) from kd_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p <<| '(5000, 4000)'; +select count(*) from kd_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p <<| '(5000, 4000)'; +select count(*) from kd_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p |>> '(5000, 4000)'; +select count(*) from kd_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p |>> '(5000, 4000)'; +select count(*) from kd_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p ~= '(4585, 365)'; +select count(*) from kd_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from kd_point_tbl where p ~= '(4585, 365)'; +select count(*) from kd_point_tbl where p ~= '(4585, 365)'; select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -381,7 +364,7 @@ from create temporary table kd_point_tbl_ord_idx1 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -398,7 +381,7 @@ where seq.dist is distinct from idx.dist; select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -409,7 +392,7 @@ where create temporary table kd_point_tbl_ord_idx2 as select - ROW_NUMBER() over (order by p <-> '0,0') as n, + row_number() over (order by p <-> '0,0') as n, p <-> '0,0' as dist, p from @@ -428,7 +411,7 @@ where seq.dist is distinct from idx.dist; select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -439,7 +422,7 @@ where create temporary table kd_point_tbl_ord_idx3 as select - ROW_NUMBER() over (order by p <-> '333,400') as n, + row_number() over (order by p <-> '333,400') as n, p <-> '333,400' as dist, p from @@ -468,195 +451,169 @@ select p, dist from quad_point_tbl_ord_seq1 order by p <-> '0,0' limit 10; reset extra_float_digits; select - ( - select - p - from - kd_point_tbl - order by p <-> pt, - p <-> '0,0' - limit 1 - ) + (select p from kd_point_tbl order by p <-> pt, p <-> '0,0' limit 1) from - ( - values - (cast('1,2' as point)), - (null), - ('1234,5678') - ) - as pts (pt); + (values (cast('1,2' as point)), (null), ('1234,5678')) as pts (pt); -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; select - COUNT(*) + count(*) from radix_text_tbl where t < 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t < 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<~ - 'Aztec Ct '; + t ~<~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<~ - 'Aztec Ct '; + t ~<~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t <= - 'Aztec Ct '; + t <= 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t <= - 'Aztec Ct '; + t <= 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<=~ - 'Aztec Ct '; + t ~<=~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<=~ - 'Aztec Ct '; + t ~<=~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t >= - 'Worth St '; + t >= 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t >= - 'Worth St '; + t >= 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>=~ - 'Worth St '; + t ~>=~ 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>=~ - 'Worth St '; + t ~>=~ 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where t > 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where t > 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>~ - 'Worth St '; + t ~>~ 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>~ - 'Worth St '; + t ~>~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; -select COUNT(*) from radix_text_tbl where starts_with(t, 'Worth'); +select count(*) from radix_text_tbl where starts_with(t, 'Worth'); -select COUNT(*) from radix_text_tbl where starts_with(t, 'Worth'); +select count(*) from radix_text_tbl where starts_with(t, 'Worth'); set enable_seqscan = off; @@ -664,265 +621,253 @@ set enable_indexscan = off; set enable_bitmapscan = 'on'; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is null; +select count(*) from quad_point_tbl where p is null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl where p is not null; +select count(*) from quad_point_tbl where p is not null; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; -select COUNT(*) from quad_point_tbl; +select count(*) from quad_point_tbl; select - COUNT(*) + count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); select - COUNT(*) + count(*) from quad_point_tbl where p <@ cast('(200,200,1000,1000)' as box); select - COUNT(*) + count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; select - COUNT(*) + count(*) from quad_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p << '(5000, 4000)'; +select count(*) from quad_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p >> '(5000, 4000)'; +select count(*) from quad_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p <<| '(5000, 4000)'; +select count(*) from quad_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p |>> '(5000, 4000)'; +select count(*) from quad_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from quad_point_tbl where p ~= '(4585, 365)'; +select count(*) from quad_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); +select count(*) from kd_point_tbl where p <@ cast('(200,200,1000,1000)' as box); -select COUNT(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; +select count(*) from kd_point_tbl where cast('(200,200,1000,1000)' as box) @> p; -select COUNT(*) from kd_point_tbl where p << '(5000, 4000)'; +select count(*) from kd_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p << '(5000, 4000)'; +select count(*) from kd_point_tbl where p << '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p >> '(5000, 4000)'; +select count(*) from kd_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p >> '(5000, 4000)'; +select count(*) from kd_point_tbl where p >> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p <<| '(5000, 4000)'; +select count(*) from kd_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p <<| '(5000, 4000)'; +select count(*) from kd_point_tbl where p <<| '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p |>> '(5000, 4000)'; +select count(*) from kd_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p |>> '(5000, 4000)'; +select count(*) from kd_point_tbl where p |>> '(5000, 4000)'; -select COUNT(*) from kd_point_tbl where p ~= '(4585, 365)'; +select count(*) from kd_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from kd_point_tbl where p ~= '(4585, 365)'; +select count(*) from kd_point_tbl where p ~= '(4585, 365)'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdef'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdef'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcde'; +select count(*) from radix_text_tbl where t = 'P0123456789abcde'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; -select COUNT(*) from radix_text_tbl where t = 'P0123456789abcdefF'; +select count(*) from radix_text_tbl where t = 'P0123456789abcdefF'; select - COUNT(*) + count(*) from radix_text_tbl where t < 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t < 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<~ - 'Aztec Ct '; + t ~<~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<~ - 'Aztec Ct '; + t ~<~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t <= - 'Aztec Ct '; + t <= 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t <= - 'Aztec Ct '; + t <= 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<=~ - 'Aztec Ct '; + t ~<=~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~<=~ - 'Aztec Ct '; + t ~<=~ 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Aztec Ct '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where t = 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t >= - 'Worth St '; + t >= 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t >= - 'Worth St '; + t >= 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>=~ - 'Worth St '; + t ~>=~ 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>=~ - 'Worth St '; + t ~>=~ 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where t > 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where t > 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>~ - 'Worth St '; + t ~>~ 'Worth St '; select - COUNT(*) + count(*) from radix_text_tbl where - t ~>~ - 'Worth St '; + t ~>~ 'Worth St '; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; -select COUNT(*) from radix_text_tbl where t ^@ 'Worth'; +select count(*) from radix_text_tbl where t ^@ 'Worth'; -select COUNT(*) from radix_text_tbl where starts_with(t, 'Worth'); +select count(*) from radix_text_tbl where starts_with(t, 'Worth'); -select COUNT(*) from radix_text_tbl where starts_with(t, 'Worth'); +select count(*) from radix_text_tbl where starts_with(t, 'Worth'); reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_misc_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_misc_100.snap index 3d87871a1..e34b52181 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_misc_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_misc_100.snap @@ -5,7 +5,7 @@ snapshot_kind: text --- create table a_star ( class char(1), - a int + a int4 ); create table b_star (b text) @@ -14,11 +14,10 @@ inherits (a_star); create table c_star (c name) inherits (a_star); -create table d_star (d double precision) -inherits (b_star, -c_star); +create table d_star (d float8) +inherits (b_star, c_star); -create table e_star (e smallint) +create table e_star (e int2) inherits (c_star); create table f_star (f polygon) @@ -47,74 +46,32 @@ insert into c_star (class, c) values ('c', cast('hi paul' as name)); insert into c_star (class) values ('c'); insert into d_star (class, a, b, c, d) -values - ( - 'd', - 7, - cast('grumble' as text), - cast('hi sunita' as name), - cast('0.0' as double precision) - ); +values ('d', 7, cast('grumble' as text), cast('hi sunita' as name), cast('0.0' as float8)); insert into d_star (class, a, b, c) -values - ( - 'd', - 8, - cast('stumble' as text), - cast('hi koko' as name) - ); - -insert into d_star (class, a, b, d) -values - ( - 'd', - 9, - cast('rumble' as text), - cast('1.1' as double precision) - ); +values ('d', 8, cast('stumble' as text), cast('hi koko' as name)); + +insert into d_star (class, a, b, d) values ('d', 9, cast('rumble' as text), cast('1.1' as float8)); insert into d_star (class, a, c, d) -values - ( - 'd', - 10, - cast('hi kristin' as name), - cast('10.01' as double precision) - ); +values ('d', 10, cast('hi kristin' as name), cast('10.01' as float8)); insert into d_star (class, b, c, d) -values - ( - 'd', - cast('crumble' as text), - cast('hi boris' as name), - cast('100.001' as double precision) - ); +values ('d', cast('crumble' as text), cast('hi boris' as name), cast('100.001' as float8)); insert into d_star (class, a, b) values ('d', 11, cast('fumble' as text)); insert into d_star (class, a, c) values ('d', 12, cast('hi avi' as name)); -insert into d_star (class, a, d) values ('d', 13, cast('1000.0001' as double precision)); +insert into d_star (class, a, d) values ('d', 13, cast('1000.0001' as float8)); insert into d_star (class, b, c) values ('d', cast('tumble' as text), cast('hi andrew' as name)); insert into d_star (class, b, d) -values - ( - 'd', - cast('humble' as text), - cast('10000.00001' as double precision) - ); +values ('d', cast('humble' as text), cast('10000.00001' as float8)); insert into d_star (class, c, d) -values - ( - 'd', - cast('hi ginger' as name), - cast('100000.000001' as double precision) - ); +values ('d', cast('hi ginger' as name), cast('100000.000001' as float8)); insert into d_star (class, a) values ('d', 14); @@ -122,116 +79,61 @@ insert into d_star (class, b) values ('d', cast('jumble' as text)); insert into d_star (class, c) values ('d', cast('hi jolly' as name)); -insert into d_star (class, d) values ('d', cast('1000000.0000001' as double precision)); +insert into d_star (class, d) values ('d', cast('1000000.0000001' as float8)); insert into d_star (class) values ('d'); -insert into e_star (class, a, c, e) -values - ( - 'e', - 15, - cast('hi carol' as name), - cast('-1' as smallint) - ); +insert into e_star (class, a, c, e) values ('e', 15, cast('hi carol' as name), cast('-1' as int2)); insert into e_star (class, a, c) values ('e', 16, cast('hi bob' as name)); -insert into e_star (class, a, e) values ('e', 17, cast('-2' as smallint)); +insert into e_star (class, a, e) values ('e', 17, cast('-2' as int2)); -insert into e_star (class, c, e) values ('e', cast('hi michelle' as name), cast('-3' as smallint)); +insert into e_star (class, c, e) values ('e', cast('hi michelle' as name), cast('-3' as int2)); insert into e_star (class, a) values ('e', 18); insert into e_star (class, c) values ('e', cast('hi elisa' as name)); -insert into e_star (class, e) values ('e', cast('-4' as smallint)); +insert into e_star (class, e) values ('e', cast('-4' as int2)); insert into f_star (class, a, c, e, f) -values - ( - 'f', - 19, - cast('hi claire' as name), - cast('-5' as smallint), - cast('(1,3),(2,4)' as polygon) - ); - -insert into f_star (class, a, c, e) -values - ( - 'f', - 20, - cast('hi mike' as name), - cast('-6' as smallint) - ); +values ('f', 19, cast('hi claire' as name), cast('-5' as int2), cast('(1,3),(2,4)' as polygon)); + +insert into f_star (class, a, c, e) values ('f', 20, cast('hi mike' as name), cast('-6' as int2)); insert into f_star (class, a, c, f) -values - ( - 'f', - 21, - cast('hi marcel' as name), - cast('(11,44),(22,55),(33,66)' as polygon) - ); +values ('f', 21, cast('hi marcel' as name), cast('(11,44),(22,55),(33,66)' as polygon)); insert into f_star (class, a, e, f) -values - ( - 'f', - 22, - cast('-7' as smallint), - cast('(111,555),(222,666),(333,777),(444,888)' - as polygon) - ); +values ('f', 22, cast('-7' as int2), cast('(111,555),(222,666),(333,777),(444,888)' as polygon)); insert into f_star (class, c, e, f) values - ( - 'f', - cast('hi keith' as name), - cast('-8' as smallint), - cast('(1111,3333),(2222,4444)' as polygon) - ); + ('f', cast('hi keith' as name), cast('-8' as int2), cast('(1111,3333),(2222,4444)' as polygon)); insert into f_star (class, a, c) values ('f', 24, cast('hi marc' as name)); -insert into f_star (class, a, e) values ('f', 25, cast('-9' as smallint)); +insert into f_star (class, a, e) values ('f', 25, cast('-9' as int2)); insert into f_star (class, a, f) values ('f', 26, cast('(11111,33333),(22222,44444)' as polygon)); -insert into f_star (class, c, e) values ('f', cast('hi allison' as name), cast('-10' as smallint)); +insert into f_star (class, c, e) values ('f', cast('hi allison' as name), cast('-10' as int2)); insert into f_star (class, c, f) -values - ( - 'f', - cast('hi jeff' as name), - cast('(111111,333333),(222222,444444)' as polygon) - ); +values ('f', cast('hi jeff' as name), cast('(111111,333333),(222222,444444)' as polygon)); insert into f_star (class, e, f) -values - ( - 'f', - cast('-11' as smallint), - cast('(1111111,3333333),(2222222,4444444)' - as polygon) - ); +values ('f', cast('-11' as int2), cast('(1111111,3333333),(2222222,4444444)' as polygon)); insert into f_star (class, a) values ('f', 27); insert into f_star (class, c) values ('f', cast('hi carl' as name)); -insert into f_star (class, e) values ('f', cast('-12' as smallint)); +insert into f_star (class, e) values ('f', cast('-12' as int2)); insert into f_star (class, f) -values - ( - 'f', - cast('(11111111,33333333),(22222222,44444444)' - as polygon) - ); +values ('f', cast('(11111111,33333333),(22222222,44444444)' as polygon)); insert into f_star (class) values ('f'); @@ -259,9 +161,9 @@ select class, c from e_star as x where x.c is not null; select * from f_star as x where x.c is null; -select SUM(a) from a_star; +select sum(a) from a_star; -select class, SUM(a) from a_star group by class order by class; +select class, sum(a) from a_star group by class order by class; alter table f_star rename column f to ff; @@ -286,12 +188,12 @@ alter table a_star rename column foo to aa; select * from a_star where aa < 1000; alter table f_star - add column f int; + add column f int4; update f_star set f = 10; alter table e_star - add column e int; + add column e int4; select * from e_star; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_misc_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_misc_80.snap index 7b2cb0194..fd03c6c1a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_misc_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_misc_80.snap @@ -5,7 +5,7 @@ snapshot_kind: text --- create table a_star ( class char(1), - a int + a int4 ); create table b_star (b text) @@ -14,11 +14,10 @@ inherits (a_star); create table c_star (c name) inherits (a_star); -create table d_star (d double precision) -inherits (b_star, -c_star); +create table d_star (d float8) +inherits (b_star, c_star); -create table e_star (e smallint) +create table e_star (e int2) inherits (c_star); create table f_star (f polygon) @@ -53,35 +52,17 @@ values 7, cast('grumble' as text), cast('hi sunita' as name), - cast('0.0' as double precision) + cast('0.0' as float8) ); insert into d_star (class, a, b, c) -values - ( - 'd', - 8, - cast('stumble' as text), - cast('hi koko' as name) - ); +values ('d', 8, cast('stumble' as text), cast('hi koko' as name)); insert into d_star (class, a, b, d) -values - ( - 'd', - 9, - cast('rumble' as text), - cast('1.1' as double precision) - ); +values ('d', 9, cast('rumble' as text), cast('1.1' as float8)); insert into d_star (class, a, c, d) -values - ( - 'd', - 10, - cast('hi kristin' as name), - cast('10.01' as double precision) - ); +values ('d', 10, cast('hi kristin' as name), cast('10.01' as float8)); insert into d_star (class, b, c, d) values @@ -89,45 +70,23 @@ values 'd', cast('crumble' as text), cast('hi boris' as name), - cast('100.001' as double precision) + cast('100.001' as float8) ); insert into d_star (class, a, b) values ('d', 11, cast('fumble' as text)); insert into d_star (class, a, c) values ('d', 12, cast('hi avi' as name)); -insert into d_star (class, a, d) -values - ( - 'd', - 13, - cast('1000.0001' as double precision) - ); +insert into d_star (class, a, d) values ('d', 13, cast('1000.0001' as float8)); insert into d_star (class, b, c) -values - ( - 'd', - cast('tumble' as text), - cast('hi andrew' as name) - ); +values ('d', cast('tumble' as text), cast('hi andrew' as name)); insert into d_star (class, b, d) -values - ( - 'd', - cast('humble' as text), - cast('10000.00001' as double precision) - ); +values ('d', cast('humble' as text), cast('10000.00001' as float8)); insert into d_star (class, c, d) -values - ( - 'd', - cast('hi ginger' as name), - cast('100000.000001' - as double precision) - ); +values ('d', cast('hi ginger' as name), cast('100000.000001' as float8)); insert into d_star (class, a) values ('d', 14); @@ -135,42 +94,25 @@ insert into d_star (class, b) values ('d', cast('jumble' as text)); insert into d_star (class, c) values ('d', cast('hi jolly' as name)); -insert into d_star (class, d) -values - ( - 'd', - cast('1000000.0000001' - as double precision) - ); +insert into d_star (class, d) values ('d', cast('1000000.0000001' as float8)); insert into d_star (class) values ('d'); insert into e_star (class, a, c, e) -values - ( - 'e', - 15, - cast('hi carol' as name), - cast('-1' as smallint) - ); +values ('e', 15, cast('hi carol' as name), cast('-1' as int2)); insert into e_star (class, a, c) values ('e', 16, cast('hi bob' as name)); -insert into e_star (class, a, e) values ('e', 17, cast('-2' as smallint)); +insert into e_star (class, a, e) values ('e', 17, cast('-2' as int2)); insert into e_star (class, c, e) -values - ( - 'e', - cast('hi michelle' as name), - cast('-3' as smallint) - ); +values ('e', cast('hi michelle' as name), cast('-3' as int2)); insert into e_star (class, a) values ('e', 18); insert into e_star (class, c) values ('e', cast('hi elisa' as name)); -insert into e_star (class, e) values ('e', cast('-4' as smallint)); +insert into e_star (class, e) values ('e', cast('-4' as int2)); insert into f_star (class, a, c, e, f) values @@ -178,18 +120,12 @@ values 'f', 19, cast('hi claire' as name), - cast('-5' as smallint), + cast('-5' as int2), cast('(1,3),(2,4)' as polygon) ); insert into f_star (class, a, c, e) -values - ( - 'f', - 20, - cast('hi mike' as name), - cast('-6' as smallint) - ); +values ('f', 20, cast('hi mike' as name), cast('-6' as int2)); insert into f_star (class, a, c, f) values @@ -197,8 +133,7 @@ values 'f', 21, cast('hi marcel' as name), - cast('(11,44),(22,55),(33,66)' - as polygon) + cast('(11,44),(22,55),(33,66)' as polygon) ); insert into f_star (class, a, e, f) @@ -206,9 +141,8 @@ values ( 'f', 22, - cast('-7' as smallint), - cast('(111,555),(222,666),(333,777),(444,888)' - as polygon) + cast('-7' as int2), + cast('(111,555),(222,666),(333,777),(444,888)' as polygon) ); insert into f_star (class, c, e, f) @@ -216,63 +150,44 @@ values ( 'f', cast('hi keith' as name), - cast('-8' as smallint), - cast('(1111,3333),(2222,4444)' - as polygon) + cast('-8' as int2), + cast('(1111,3333),(2222,4444)' as polygon) ); insert into f_star (class, a, c) values ('f', 24, cast('hi marc' as name)); -insert into f_star (class, a, e) values ('f', 25, cast('-9' as smallint)); +insert into f_star (class, a, e) values ('f', 25, cast('-9' as int2)); insert into f_star (class, a, f) -values - ( - 'f', - 26, - cast('(11111,33333),(22222,44444)' - as polygon) - ); +values ('f', 26, cast('(11111,33333),(22222,44444)' as polygon)); insert into f_star (class, c, e) -values - ( - 'f', - cast('hi allison' as name), - cast('-10' as smallint) - ); +values ('f', cast('hi allison' as name), cast('-10' as int2)); insert into f_star (class, c, f) values ( 'f', cast('hi jeff' as name), - cast('(111111,333333),(222222,444444)' - as polygon) + cast('(111111,333333),(222222,444444)' as polygon) ); insert into f_star (class, e, f) values ( 'f', - cast('-11' as smallint), - cast('(1111111,3333333),(2222222,4444444)' - as polygon) + cast('-11' as int2), + cast('(1111111,3333333),(2222222,4444444)' as polygon) ); insert into f_star (class, a) values ('f', 27); insert into f_star (class, c) values ('f', cast('hi carl' as name)); -insert into f_star (class, e) values ('f', cast('-12' as smallint)); +insert into f_star (class, e) values ('f', cast('-12' as int2)); insert into f_star (class, f) -values - ( - 'f', - cast('(11111111,33333333),(22222222,44444444)' - as polygon) - ); +values ('f', cast('(11111111,33333333),(22222222,44444444)' as polygon)); insert into f_star (class) values ('f'); @@ -300,9 +215,9 @@ select class, c from e_star as x where x.c is not null; select * from f_star as x where x.c is null; -select SUM(a) from a_star; +select sum(a) from a_star; -select class, SUM(a) from a_star group by class order by class; +select class, sum(a) from a_star group by class order by class; alter table f_star rename column f to ff; @@ -327,12 +242,12 @@ alter table a_star rename column foo to aa; select * from a_star where aa < 1000; alter table f_star - add column f int; + add column f int4; update f_star set f = 10; alter table e_star - add column e int; + add column e int4; select * from e_star; @@ -345,10 +260,7 @@ select from pg_class where - cast(oid as regclass) - in ( - 'a_star', 'c_star' - ) + cast(oid as regclass) in ('a_star', 'c_star') order by 1; select class, aa, a from a_star; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_operator_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_operator_100.snap index a44b460cd..cb15de89f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_operator_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_operator_100.snap @@ -2,11 +2,11 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/create_operator.sql --- -create operator ## (LEFTARG = path, RIGHTARG = path, FUNCTION = path_inter, COMMUTATOR = ##); +create operator ## (leftarg = path, rightarg = path, function = path_inter, commutator = ##); -create operator @#@ (RIGHTARG = bigint, PROCEDURE = factorial); +create operator @#@ (rightarg = int8, procedure = factorial); -create operator #%# (LEFTARG = bigint, PROCEDURE = factorial); +create operator #%# (leftarg = int8, procedure = factorial); select @#@24; @@ -20,19 +20,19 @@ reset search_path; select @#@24.0; -comment on operator ###### (none, int) is 'bad prefix'; +comment on operator ###### (none, int4) is 'bad prefix'; -comment on operator ###### (int, none) is 'bad postfix'; +comment on operator ###### (int4, none) is 'bad postfix'; -comment on operator ###### (int, bigint) is 'bad infix'; +comment on operator ###### (int4, int8) is 'bad infix'; -drop operator ###### (none, int); +drop operator ###### (none, int4); -drop operator ###### (int, none); +drop operator ###### (int4, none); -drop operator ###### (int, bigint); +drop operator ###### (int4, int8); -create operator !=- (RIGHTARG = bigint, PROCEDURE = factorial); +create operator !=- (rightarg = int8, procedure = factorial); select !=-10; @@ -40,16 +40,14 @@ select 2 <> 1, 2 <> 2; select 2 <> 1; -do -$do$ --- use DO to protect -- from psql +do $$ -- use DO to protect -- from psql declare r boolean; begin execute $e$ select 2 !=-- comment 1 $e$ into r; raise info 'r = %', r; end; -$do$; +$$; select true <> -1 between 1 and 1; @@ -67,27 +65,27 @@ begin; create role regress_rol_op1; -create schema "schema_op1"; +create schema schema_op1; -grant USAGE on schema schema_op1 to public; +grant usage on schema schema_op1 to public; -revoke USAGE on schema schema_op1 from regress_rol_op1; +revoke usage on schema schema_op1 from regress_rol_op1; set role to regress_rol_op1; -create operator schema_op1.#*# (RIGHTARG = bigint, PROCEDURE = factorial); +create operator schema_op1.#*# (rightarg = int8, procedure = factorial); rollback; begin; -create operator #*# (LEFTARG = setof bigint, PROCEDURE = factorial); +create operator #*# (leftarg = setof int8, procedure = factorial); rollback; begin; -create operator #*# (RIGHTARG = setof bigint, PROCEDURE = factorial); +create operator #*# (rightarg = setof int8, procedure = factorial); rollback; @@ -97,31 +95,33 @@ create or replace function fn_op2(boolean, boolean) returns boolean language sql immutable -as $function$ -SELECT NULL::BOOLEAN; -$function$; - -create operator === (LEFTARG = boolean, -RIGHTARG = boolean, -PROCEDURE = fn_op2, -COMMUTATOR = ===, -NEGATOR = !==, -RESTRICT = contsel, -JOIN = contjoinsel, -SORT1, -SORT2, -LTCMP, -GTCMP, -HASHES, -MERGES); +as $$ + SELECT NULL::BOOLEAN; +$$; + +create operator === ( + leftarg = boolean, + rightarg = boolean, + procedure = fn_op2, + commutator = ===, + negator = !==, + restrict = contsel, + join = contjoinsel, + sort1, + sort2, + ltcmp, + gtcmp, + hashes, + merges +); rollback; -create operator #@%# (RIGHTARG = bigint, PROCEDURE = factorial, INVALID_ATT = bigint); +create operator #@%# (rightarg = int8, procedure = factorial, invalid_att = int8); -create operator #@%# (PROCEDURE = factorial); +create operator #@%# (procedure = factorial); -create operator #@%# (RIGHTARG = bigint); +create operator #@%# (rightarg = int8); begin; @@ -129,21 +129,21 @@ create role regress_rol_op3; create type type_op3 as enum ('new', 'open', 'closed'); -create function fn_op3(type_op3, bigint) -returns bigint +create function fn_op3(type_op3, int8) +returns int8 language sql immutable -as $function$ -SELECT NULL::int8; -$function$; +as $$ + SELECT NULL::int8; +$$; -revoke USAGE on type type_op3 from regress_rol_op3; +revoke usage on type type_op3 from regress_rol_op3; -revoke USAGE on type type_op3 from public; +revoke usage on type type_op3 from public; set role to regress_rol_op3; -create operator #*# (LEFTARG = type_op3, RIGHTARG = bigint, PROCEDURE = fn_op3); +create operator #*# (leftarg = type_op3, rightarg = int8, procedure = fn_op3); rollback; @@ -153,21 +153,21 @@ create role regress_rol_op4; create type type_op4 as enum ('new', 'open', 'closed'); -create function fn_op4(bigint, type_op4) -returns bigint +create function fn_op4(int8, type_op4) +returns int8 language sql immutable -as $function$ -SELECT NULL::int8; -$function$; +as $$ + SELECT NULL::int8; +$$; -revoke USAGE on type type_op4 from regress_rol_op4; +revoke usage on type type_op4 from regress_rol_op4; -revoke USAGE on type type_op4 from public; +revoke usage on type type_op4 from public; set role to regress_rol_op4; -create operator #*# (LEFTARG = bigint, RIGHTARG = type_op4, PROCEDURE = fn_op4); +create operator #*# (leftarg = int8, rightarg = type_op4, procedure = fn_op4); rollback; @@ -177,21 +177,21 @@ create role regress_rol_op5; create type type_op5 as enum ('new', 'open', 'closed'); -create function fn_op5(bigint, bigint) -returns bigint +create function fn_op5(int8, int8) +returns int8 language sql immutable -as $function$ -SELECT NULL::int8; -$function$; +as $$ + SELECT NULL::int8; +$$; -revoke EXECUTE on function fn_op5(bigint, bigint) from regress_rol_op5; +revoke execute on function fn_op5(int8, int8) from regress_rol_op5; -revoke EXECUTE on function fn_op5(bigint, bigint) from public; +revoke execute on function fn_op5(int8, int8) from public; set role to regress_rol_op5; -create operator #*# (LEFTARG = bigint, RIGHTARG = bigint, PROCEDURE = fn_op5); +create operator #*# (leftarg = int8, rightarg = int8, procedure = fn_op5); rollback; @@ -201,48 +201,50 @@ create role regress_rol_op6; create type type_op6 as enum ('new', 'open', 'closed'); -create function fn_op6(bigint, bigint) +create function fn_op6(int8, int8) returns type_op6 language sql immutable -as $function$ -SELECT NULL::type_op6; -$function$; +as $$ + SELECT NULL::type_op6; +$$; -revoke USAGE on type type_op6 from regress_rol_op6; +revoke usage on type type_op6 from regress_rol_op6; -revoke USAGE on type type_op6 from public; +revoke usage on type type_op6 from public; set role to regress_rol_op6; -create operator #*# (LEFTARG = bigint, RIGHTARG = bigint, PROCEDURE = fn_op6); +create operator #*# (leftarg = int8, rightarg = int8, procedure = fn_op6); rollback; begin; -create operator === (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4eq, NEGATOR = ===); +create operator === (leftarg = int, rightarg = int, procedure = int4eq, negator = ===); rollback; begin; -create operator === (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4eq, COMMUTATOR = ===!!!); +create operator === (leftarg = int, rightarg = int, procedure = int4eq, commutator = ===!!!); -create operator ===!!! (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4ne, NEGATOR = ===!!!); +create operator ===!!! (leftarg = int, rightarg = int, procedure = int4ne, negator = ===!!!); rollback; -create operator === (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4eq, COMMUTATOR = =); - -create operator === (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4eq, NEGATOR = <>); - -create operator === (LEFTARG = box, -RIGHTARG = box, -PROCEDURE = area_equal_function, -COMMUTATOR = ===, -NEGATOR = !==, -RESTRICT = area_restriction_function, -JOIN = area_join_function, -HASHES, -MERGES); +create operator === (leftarg = int, rightarg = int, procedure = int4eq, commutator = =); + +create operator === (leftarg = int, rightarg = int, procedure = int4eq, negator = <>); + +create operator === ( + leftarg = box, + rightarg = box, + procedure = area_equal_function, + commutator = ===, + negator = !==, + restrict = area_restriction_function, + join = area_join_function, + hashes, + merges +); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_operator_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_operator_80.snap index d79010f4a..06b122b36 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_operator_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_operator_80.snap @@ -2,14 +2,16 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/create_operator.sql --- -create operator ## (LEFTARG = path, -RIGHTARG = path, -FUNCTION = path_inter, -COMMUTATOR = ##); +create operator ## ( + leftarg = path, + rightarg = path, + function = path_inter, + commutator = ## +); -create operator @#@ (RIGHTARG = bigint, PROCEDURE = factorial); +create operator @#@ (rightarg = int8, procedure = factorial); -create operator #%# (LEFTARG = bigint, PROCEDURE = factorial); +create operator #%# (leftarg = int8, procedure = factorial); select @#@24; @@ -23,19 +25,19 @@ reset search_path; select @#@24.0; -comment on operator ###### (none, int) is 'bad prefix'; +comment on operator ###### (none, int4) is 'bad prefix'; -comment on operator ###### (int, none) is 'bad postfix'; +comment on operator ###### (int4, none) is 'bad postfix'; -comment on operator ###### (int, bigint) is 'bad infix'; +comment on operator ###### (int4, int8) is 'bad infix'; -drop operator ###### (none, int); +drop operator ###### (none, int4); -drop operator ###### (int, none); +drop operator ###### (int4, none); -drop operator ###### (int, bigint); +drop operator ###### (int4, int8); -create operator !=- (RIGHTARG = bigint, PROCEDURE = factorial); +create operator !=- (rightarg = int8, procedure = factorial); select !=-10; @@ -43,16 +45,14 @@ select 2 <> 1, 2 <> 2; select 2 <> 1; -do -$do$ --- use DO to protect -- from psql +do $$ -- use DO to protect -- from psql declare r boolean; begin execute $e$ select 2 !=-- comment 1 $e$ into r; raise info 'r = %', r; end; -$do$; +$$; select true <> -1 between 1 and 1; @@ -70,27 +70,27 @@ begin; create role regress_rol_op1; -create schema "schema_op1"; +create schema schema_op1; -grant USAGE on schema schema_op1 to public; +grant usage on schema schema_op1 to public; -revoke USAGE on schema schema_op1 from regress_rol_op1; +revoke usage on schema schema_op1 from regress_rol_op1; set role to regress_rol_op1; -create operator schema_op1.#*# (RIGHTARG = bigint, PROCEDURE = factorial); +create operator schema_op1.#*# (rightarg = int8, procedure = factorial); rollback; begin; -create operator #*# (LEFTARG = setof bigint, PROCEDURE = factorial); +create operator #*# (leftarg = setof int8, procedure = factorial); rollback; begin; -create operator #*# (RIGHTARG = setof bigint, PROCEDURE = factorial); +create operator #*# (rightarg = setof int8, procedure = factorial); rollback; @@ -100,33 +100,37 @@ create or replace function fn_op2(boolean, boolean) returns boolean language sql immutable -as $function$ -SELECT NULL::BOOLEAN; -$function$; - -create operator === (LEFTARG = boolean, -RIGHTARG = boolean, -PROCEDURE = fn_op2, -COMMUTATOR = ===, -NEGATOR = !==, -RESTRICT = contsel, -JOIN = contjoinsel, -SORT1, -SORT2, -LTCMP, -GTCMP, -HASHES, -MERGES); +as $$ + SELECT NULL::BOOLEAN; +$$; + +create operator === ( + leftarg = boolean, + rightarg = boolean, + procedure = fn_op2, + commutator = ===, + negator = !==, + restrict = contsel, + join = contjoinsel, + sort1, + sort2, + ltcmp, + gtcmp, + hashes, + merges +); rollback; -create operator #@%# (RIGHTARG = bigint, -PROCEDURE = factorial, -INVALID_ATT = bigint); +create operator #@%# ( + rightarg = int8, + procedure = factorial, + invalid_att = int8 +); -create operator #@%# (PROCEDURE = factorial); +create operator #@%# (procedure = factorial); -create operator #@%# (RIGHTARG = bigint); +create operator #@%# (rightarg = int8); begin; @@ -134,21 +138,21 @@ create role regress_rol_op3; create type type_op3 as enum ('new', 'open', 'closed'); -create function fn_op3(type_op3, bigint) -returns bigint +create function fn_op3(type_op3, int8) +returns int8 language sql immutable -as $function$ -SELECT NULL::int8; -$function$; +as $$ + SELECT NULL::int8; +$$; -revoke USAGE on type type_op3 from regress_rol_op3; +revoke usage on type type_op3 from regress_rol_op3; -revoke USAGE on type type_op3 from public; +revoke usage on type type_op3 from public; set role to regress_rol_op3; -create operator #*# (LEFTARG = type_op3, RIGHTARG = bigint, PROCEDURE = fn_op3); +create operator #*# (leftarg = type_op3, rightarg = int8, procedure = fn_op3); rollback; @@ -158,21 +162,21 @@ create role regress_rol_op4; create type type_op4 as enum ('new', 'open', 'closed'); -create function fn_op4(bigint, type_op4) -returns bigint +create function fn_op4(int8, type_op4) +returns int8 language sql immutable -as $function$ -SELECT NULL::int8; -$function$; +as $$ + SELECT NULL::int8; +$$; -revoke USAGE on type type_op4 from regress_rol_op4; +revoke usage on type type_op4 from regress_rol_op4; -revoke USAGE on type type_op4 from public; +revoke usage on type type_op4 from public; set role to regress_rol_op4; -create operator #*# (LEFTARG = bigint, RIGHTARG = type_op4, PROCEDURE = fn_op4); +create operator #*# (leftarg = int8, rightarg = type_op4, procedure = fn_op4); rollback; @@ -182,21 +186,21 @@ create role regress_rol_op5; create type type_op5 as enum ('new', 'open', 'closed'); -create function fn_op5(bigint, bigint) -returns bigint +create function fn_op5(int8, int8) +returns int8 language sql immutable -as $function$ -SELECT NULL::int8; -$function$; +as $$ + SELECT NULL::int8; +$$; -revoke EXECUTE on function fn_op5(bigint, bigint) from regress_rol_op5; +revoke execute on function fn_op5(int8, int8) from regress_rol_op5; -revoke EXECUTE on function fn_op5(bigint, bigint) from public; +revoke execute on function fn_op5(int8, int8) from public; set role to regress_rol_op5; -create operator #*# (LEFTARG = bigint, RIGHTARG = bigint, PROCEDURE = fn_op5); +create operator #*# (leftarg = int8, rightarg = int8, procedure = fn_op5); rollback; @@ -206,63 +210,75 @@ create role regress_rol_op6; create type type_op6 as enum ('new', 'open', 'closed'); -create function fn_op6(bigint, bigint) +create function fn_op6(int8, int8) returns type_op6 language sql immutable -as $function$ -SELECT NULL::type_op6; -$function$; +as $$ + SELECT NULL::type_op6; +$$; -revoke USAGE on type type_op6 from regress_rol_op6; +revoke usage on type type_op6 from regress_rol_op6; -revoke USAGE on type type_op6 from public; +revoke usage on type type_op6 from public; set role to regress_rol_op6; -create operator #*# (LEFTARG = bigint, RIGHTARG = bigint, PROCEDURE = fn_op6); +create operator #*# (leftarg = int8, rightarg = int8, procedure = fn_op6); rollback; begin; -create operator === (LEFTARG = int, -RIGHTARG = int, -PROCEDURE = int4eq, -NEGATOR = ===); +create operator === ( + leftarg = int, + rightarg = int, + procedure = int4eq, + negator = === +); rollback; begin; -create operator === (LEFTARG = int, -RIGHTARG = int, -PROCEDURE = int4eq, -COMMUTATOR = ===!!!); +create operator === ( + leftarg = int, + rightarg = int, + procedure = int4eq, + commutator = ===!!! +); -create operator ===!!! (LEFTARG = int, -RIGHTARG = int, -PROCEDURE = int4ne, -NEGATOR = ===!!!); +create operator ===!!! ( + leftarg = int, + rightarg = int, + procedure = int4ne, + negator = ===!!! +); rollback; -create operator === (LEFTARG = int, -RIGHTARG = int, -PROCEDURE = int4eq, -COMMUTATOR = =); - -create operator === (LEFTARG = int, -RIGHTARG = int, -PROCEDURE = int4eq, -NEGATOR = <>); - -create operator === (LEFTARG = box, -RIGHTARG = box, -PROCEDURE = area_equal_function, -COMMUTATOR = ===, -NEGATOR = !==, -RESTRICT = area_restriction_function, -JOIN = area_join_function, -HASHES, -MERGES); +create operator === ( + leftarg = int, + rightarg = int, + procedure = int4eq, + commutator = = +); + +create operator === ( + leftarg = int, + rightarg = int, + procedure = int4eq, + negator = <> +); + +create operator === ( + leftarg = box, + rightarg = box, + procedure = area_equal_function, + commutator = ===, + negator = !==, + restrict = area_restriction_function, + join = area_join_function, + hashes, + merges +); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_procedure_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_procedure_100.snap index a855862d2..1f313d130 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_procedure_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_procedure_100.snap @@ -9,9 +9,7 @@ call random(); create function cp_testfunc1(a int) returns int language sql -as $function$ -SELECT a -$function$; +as $$ SELECT a $$; create table cp_test ( a int, @@ -20,9 +18,9 @@ create table cp_test ( create procedure ptest1(x text) language sql -as $procedure$ +as $$ INSERT INTO cp_test VALUES (1, x); -$procedure$; +$$; select pg_get_functiondef(cast('ptest1' as regproc)); @@ -32,7 +30,7 @@ call ptest1('a'); call ptest1('xy' || 'zzy'); -call ptest1(SUBSTRING(cast(cast(random() as numeric(20, 15)) as text) from 1 for 1)); +call ptest1(substring(cast(cast(random() as numeric(20, 15)) as text), 1, 1)); select * from cp_test order by b collate "C"; @@ -52,9 +50,9 @@ commit; create procedure ptest2() language sql -as $procedure$ +as $$ SELECT 5; -$procedure$; +$$; call ptest2(); @@ -62,10 +60,10 @@ truncate cp_test; create procedure ptest3(y text) language sql -as $procedure$ +as $$ CALL ptest1(y); CALL ptest1($1); -$procedure$; +$$; call ptest3('b'); @@ -73,23 +71,23 @@ select * from cp_test; create procedure ptest4a(inout a int, inout b int) language sql -as $procedure$ +as $$ SELECT 1, 2; -$procedure$; +$$; call ptest4a(null, null); create procedure ptest4b(inout b int, inout a int) language sql -as $procedure$ +as $$ CALL ptest4a(a, b); -- error, not supported -$procedure$; +$$; create procedure ptest4c(inout comp int8_tbl) language sql -as $procedure$ +as $$ SELECT ROW(1, 2); -$procedure$; +$$; call ptest4c(null); @@ -97,10 +95,10 @@ drop procedure ptest4a, ptest4c; create or replace procedure ptest5(a int, b text, c int default 100) language sql -as $procedure$ +as $$ INSERT INTO cp_test VALUES(a, b); INSERT INTO cp_test VALUES(c, b); -$procedure$; +$$; truncate cp_test; @@ -108,25 +106,25 @@ call ptest5(10, 'Hello', 20); call ptest5(10, 'Hello'); -call ptest5(10, "b" := 'Hello'); +call ptest5(10, b := 'Hello'); -call ptest5("b" := 'Hello', "a" := 10); +call ptest5(b := 'Hello', a := 10); select * from cp_test; create procedure ptest6(a int, b anyelement) language sql -as $procedure$ +as $$ SELECT NULL::int; -$procedure$; +$$; call ptest6(1, 2); create procedure ptest6a(inout a anyelement, out b anyelement) language sql -as $procedure$ +as $$ SELECT $1, $1; -$procedure$; +$$; call ptest6a(1, null); @@ -134,9 +132,9 @@ call ptest6a(1.1, null); create procedure ptest6b(a anyelement, out b anyelement, out c anyarray) language sql -as $procedure$ +as $$ SELECT $1, array[$1]; -$procedure$; +$$; call ptest6b(1, null, null); @@ -144,9 +142,9 @@ call ptest6b(1.1, null, null); create procedure ptest6c(inout a anyelement, inout b anyelement) language sql -as $procedure$ +as $$ SELECT $1, 1; -$procedure$; +$$; call ptest6c(1, null); @@ -154,9 +152,9 @@ call ptest6c(1.1, null); create procedure ptest7(a text, b text) language sql -as $procedure$ +as $$ SELECT a = b; -$procedure$; +$$; call ptest7(least('a', 'b'), 'a'); @@ -170,10 +168,10 @@ call ptest8(''); create procedure ptest9(out a int) language sql -as $procedure$ +as $$ INSERT INTO cp_test VALUES (1, 'a'); SELECT 1; -$procedure$; +$$; call ptest9(null); @@ -183,33 +181,27 @@ call ptest9(1. / 0.); create procedure ptest10(out a int, in b int, in c int) language sql -as $procedure$ -SELECT b - c -$procedure$; +as $$ SELECT b - c $$; call ptest10(null, 7, 4); -call ptest10("a" := null, "b" := 8, "c" := 2); +call ptest10(a := null, b := 8, c := 2); -call ptest10(null, 7, "c" := 2); +call ptest10(null, 7, c := 2); -call ptest10(null, "c" := 4, "b" := 11); +call ptest10(null, c := 4, b := 11); -call ptest10("b" := 8, "c" := 2, "a" := 0); +call ptest10(b := 8, c := 2, a := 0); create procedure ptest11(out a int, variadic b int[]) language sql -as $procedure$ -SELECT b[1] + b[2] -$procedure$; +as $$ SELECT b[1] + b[2] $$; call ptest11(null, 11, 12, 13); create procedure ptest10(in a int, in b int, in c int) language sql -as $procedure$ -SELECT a + b - c -$procedure$; +as $$ SELECT a + b - c $$; drop procedure ptest10; @@ -217,7 +209,7 @@ drop procedure ptest10(int, int, int); begin; -drop procedure ptest10(int, int); +drop procedure ptest10(out int, int, int); drop procedure ptest10(int, int, int); @@ -225,7 +217,7 @@ rollback; begin; -drop procedure ptest10(int, int, int); +drop procedure ptest10(in int, int, int); drop procedure ptest10(int, int, int); @@ -233,33 +225,25 @@ rollback; call version(); -call SUM(1); +call sum(1); create procedure ptestx() language sql window -as $procedure$ -INSERT INTO cp_test VALUES (1, 'a') -$procedure$; +as $$ INSERT INTO cp_test VALUES (1, 'a') $$; create procedure ptestx() language sql strict -as $procedure$ -INSERT INTO cp_test VALUES (1, 'a') -$procedure$; +as $$ INSERT INTO cp_test VALUES (1, 'a') $$; create procedure ptestx(variadic a int[], out b int) language sql -as $procedure$ -SELECT a[1] -$procedure$; +as $$ SELECT a[1] $$; create procedure ptestx(a int default 42, out b int) language sql -as $procedure$ -SELECT a -$procedure$; +as $$ SELECT a $$; alter procedure ptest1(text) strict; @@ -277,9 +261,9 @@ drop procedure nonexistent(); create user regress_cp_user1; -grant INSERT on table cp_test to regress_cp_user1; +grant insert on table cp_test to regress_cp_user1; -revoke EXECUTE on procedure ptest1(text) from public; +revoke execute on procedure ptest1(text) from public; set role to regress_cp_user1; @@ -287,7 +271,7 @@ call ptest1('a'); reset role; -grant EXECUTE on procedure ptest1(text) to regress_cp_user1; +grant execute on procedure ptest1(text) to regress_cp_user1; set role to regress_cp_user1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_procedure_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_procedure_80.snap index c269f4519..1f313d130 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_procedure_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_procedure_80.snap @@ -9,9 +9,7 @@ call random(); create function cp_testfunc1(a int) returns int language sql -as $function$ -SELECT a -$function$; +as $$ SELECT a $$; create table cp_test ( a int, @@ -20,9 +18,9 @@ create table cp_test ( create procedure ptest1(x text) language sql -as $procedure$ +as $$ INSERT INTO cp_test VALUES (1, x); -$procedure$; +$$; select pg_get_functiondef(cast('ptest1' as regproc)); @@ -32,12 +30,7 @@ call ptest1('a'); call ptest1('xy' || 'zzy'); -call ptest1( - SUBSTRING(cast(cast(random() as numeric(20, 15)) - as text) - from 1 - for 1) -); +call ptest1(substring(cast(cast(random() as numeric(20, 15)) as text), 1, 1)); select * from cp_test order by b collate "C"; @@ -57,9 +50,9 @@ commit; create procedure ptest2() language sql -as $procedure$ +as $$ SELECT 5; -$procedure$; +$$; call ptest2(); @@ -67,10 +60,10 @@ truncate cp_test; create procedure ptest3(y text) language sql -as $procedure$ +as $$ CALL ptest1(y); CALL ptest1($1); -$procedure$; +$$; call ptest3('b'); @@ -78,23 +71,23 @@ select * from cp_test; create procedure ptest4a(inout a int, inout b int) language sql -as $procedure$ +as $$ SELECT 1, 2; -$procedure$; +$$; call ptest4a(null, null); create procedure ptest4b(inout b int, inout a int) language sql -as $procedure$ +as $$ CALL ptest4a(a, b); -- error, not supported -$procedure$; +$$; create procedure ptest4c(inout comp int8_tbl) language sql -as $procedure$ +as $$ SELECT ROW(1, 2); -$procedure$; +$$; call ptest4c(null); @@ -102,10 +95,10 @@ drop procedure ptest4a, ptest4c; create or replace procedure ptest5(a int, b text, c int default 100) language sql -as $procedure$ +as $$ INSERT INTO cp_test VALUES(a, b); INSERT INTO cp_test VALUES(c, b); -$procedure$; +$$; truncate cp_test; @@ -113,25 +106,25 @@ call ptest5(10, 'Hello', 20); call ptest5(10, 'Hello'); -call ptest5(10, "b" := 'Hello'); +call ptest5(10, b := 'Hello'); -call ptest5("b" := 'Hello', "a" := 10); +call ptest5(b := 'Hello', a := 10); select * from cp_test; create procedure ptest6(a int, b anyelement) language sql -as $procedure$ +as $$ SELECT NULL::int; -$procedure$; +$$; call ptest6(1, 2); create procedure ptest6a(inout a anyelement, out b anyelement) language sql -as $procedure$ +as $$ SELECT $1, $1; -$procedure$; +$$; call ptest6a(1, null); @@ -139,9 +132,9 @@ call ptest6a(1.1, null); create procedure ptest6b(a anyelement, out b anyelement, out c anyarray) language sql -as $procedure$ +as $$ SELECT $1, array[$1]; -$procedure$; +$$; call ptest6b(1, null, null); @@ -149,9 +142,9 @@ call ptest6b(1.1, null, null); create procedure ptest6c(inout a anyelement, inout b anyelement) language sql -as $procedure$ +as $$ SELECT $1, 1; -$procedure$; +$$; call ptest6c(1, null); @@ -159,9 +152,9 @@ call ptest6c(1.1, null); create procedure ptest7(a text, b text) language sql -as $procedure$ +as $$ SELECT a = b; -$procedure$; +$$; call ptest7(least('a', 'b'), 'a'); @@ -175,10 +168,10 @@ call ptest8(''); create procedure ptest9(out a int) language sql -as $procedure$ +as $$ INSERT INTO cp_test VALUES (1, 'a'); SELECT 1; -$procedure$; +$$; call ptest9(null); @@ -188,33 +181,27 @@ call ptest9(1. / 0.); create procedure ptest10(out a int, in b int, in c int) language sql -as $procedure$ -SELECT b - c -$procedure$; +as $$ SELECT b - c $$; call ptest10(null, 7, 4); -call ptest10("a" := null, "b" := 8, "c" := 2); +call ptest10(a := null, b := 8, c := 2); -call ptest10(null, 7, "c" := 2); +call ptest10(null, 7, c := 2); -call ptest10(null, "c" := 4, "b" := 11); +call ptest10(null, c := 4, b := 11); -call ptest10("b" := 8, "c" := 2, "a" := 0); +call ptest10(b := 8, c := 2, a := 0); create procedure ptest11(out a int, variadic b int[]) language sql -as $procedure$ -SELECT b[1] + b[2] -$procedure$; +as $$ SELECT b[1] + b[2] $$; call ptest11(null, 11, 12, 13); create procedure ptest10(in a int, in b int, in c int) language sql -as $procedure$ -SELECT a + b - c -$procedure$; +as $$ SELECT a + b - c $$; drop procedure ptest10; @@ -222,7 +209,7 @@ drop procedure ptest10(int, int, int); begin; -drop procedure ptest10(int, int); +drop procedure ptest10(out int, int, int); drop procedure ptest10(int, int, int); @@ -230,7 +217,7 @@ rollback; begin; -drop procedure ptest10(int, int, int); +drop procedure ptest10(in int, int, int); drop procedure ptest10(int, int, int); @@ -238,33 +225,25 @@ rollback; call version(); -call SUM(1); +call sum(1); create procedure ptestx() language sql window -as $procedure$ -INSERT INTO cp_test VALUES (1, 'a') -$procedure$; +as $$ INSERT INTO cp_test VALUES (1, 'a') $$; create procedure ptestx() language sql strict -as $procedure$ -INSERT INTO cp_test VALUES (1, 'a') -$procedure$; +as $$ INSERT INTO cp_test VALUES (1, 'a') $$; create procedure ptestx(variadic a int[], out b int) language sql -as $procedure$ -SELECT a[1] -$procedure$; +as $$ SELECT a[1] $$; create procedure ptestx(a int default 42, out b int) language sql -as $procedure$ -SELECT a -$procedure$; +as $$ SELECT a $$; alter procedure ptest1(text) strict; @@ -282,9 +261,9 @@ drop procedure nonexistent(); create user regress_cp_user1; -grant INSERT on table cp_test to regress_cp_user1; +grant insert on table cp_test to regress_cp_user1; -revoke EXECUTE on procedure ptest1(text) from public; +revoke execute on procedure ptest1(text) from public; set role to regress_cp_user1; @@ -292,7 +271,7 @@ call ptest1('a'); reset role; -grant EXECUTE on procedure ptest1(text) to regress_cp_user1; +grant execute on procedure ptest1(text) to regress_cp_user1; set role to regress_cp_user1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_role_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_role_100.snap index 2c45042d7..db7d49799 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_role_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_role_100.snap @@ -7,7 +7,7 @@ create role regress_role_super superuser; create role regress_role_admin createdb createrole replication bypassrls; -grant CREATE on database regression to regress_role_admin with grant option; +grant create on database regression to regress_role_admin with grant option; create role regress_role_limited_admin createrole; @@ -65,7 +65,7 @@ alter role regress_createdb nosuperuser; create role regress_createrole createrole noinherit; -grant CREATE on database regression to regress_createrole with grant option; +grant create on database regression to regress_createrole with grant option; create role regress_login login; @@ -77,7 +77,7 @@ create role regress_encrypted_password password 'foo'; create role regress_password_null password null; -create role regress_noiseword SYSID 12345; +create role regress_noiseword sysid 12345; create role regress_nosuch_super in role regress_role_super; @@ -109,7 +109,7 @@ create role regress_nosuch_admin_recursive admin regress_nosuch_admin_recursive; set session authorization regress_createrole; -create database "regress_nosuch_db"; +create database regress_nosuch_db; create role regress_plainrole; @@ -133,7 +133,7 @@ set session authorization regress_tenant; create table tenant_table (i int); -create index "tenant_idx" on tenant_table using btree (i); +create index tenant_idx on tenant_table using btree (i); create view tenant_view as select * from pg_catalog.pg_class; @@ -154,7 +154,7 @@ alter view tenant_view drop view tenant_view; -create schema "regress_tenant_schema" authorization regress_tenant; +create schema regress_tenant_schema authorization regress_tenant; reassign owned by regress_tenant to regress_createrole; @@ -162,7 +162,7 @@ set createrole_self_grant = 'set, inherit'; create role regress_tenant2; -grant CREATE on database regression to regress_tenant2; +grant create on database regression to regress_tenant2; set session authorization regress_tenant2; @@ -172,7 +172,7 @@ revoke all on table tenant2_table from public; set session authorization regress_createrole; -create schema "regress_tenant2_schema" authorization regress_tenant2; +create schema regress_tenant2_schema authorization regress_tenant2; alter schema regress_tenant2_schema owner to regress_createrole; @@ -182,14 +182,14 @@ alter table tenant2_table alter table tenant2_table owner to regress_tenant2; -revoke INHERIT option for REGRESS_TENANT2 from regress_createrole restrict; +revoke inherit option for regress_tenant2 from regress_createrole restrict; alter schema regress_tenant2_schema owner to regress_tenant2; alter table tenant2_table owner to regress_createrole; -grant REGRESS_TENANT2 to regress_createrole with INHERIT true, SET false; +grant regress_tenant2 to regress_createrole with inherit true, set false; alter table tenant2_table owner to regress_createrole; @@ -241,7 +241,7 @@ drop role regress_nosuch_admin_recursive; drop role regress_plainrole; -revoke CREATE on database regression from regress_createrole cascade; +revoke create on database regression from regress_createrole cascade; drop role regress_replication_bypassrls; @@ -277,7 +277,7 @@ drop role regress_rolecreator; reset session_authorization; -revoke CREATE on database regression from regress_role_admin cascade; +revoke create on database regression from regress_role_admin cascade; drop index tenant_idx; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_role_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_role_80.snap index 2c45042d7..db7d49799 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_role_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_role_80.snap @@ -7,7 +7,7 @@ create role regress_role_super superuser; create role regress_role_admin createdb createrole replication bypassrls; -grant CREATE on database regression to regress_role_admin with grant option; +grant create on database regression to regress_role_admin with grant option; create role regress_role_limited_admin createrole; @@ -65,7 +65,7 @@ alter role regress_createdb nosuperuser; create role regress_createrole createrole noinherit; -grant CREATE on database regression to regress_createrole with grant option; +grant create on database regression to regress_createrole with grant option; create role regress_login login; @@ -77,7 +77,7 @@ create role regress_encrypted_password password 'foo'; create role regress_password_null password null; -create role regress_noiseword SYSID 12345; +create role regress_noiseword sysid 12345; create role regress_nosuch_super in role regress_role_super; @@ -109,7 +109,7 @@ create role regress_nosuch_admin_recursive admin regress_nosuch_admin_recursive; set session authorization regress_createrole; -create database "regress_nosuch_db"; +create database regress_nosuch_db; create role regress_plainrole; @@ -133,7 +133,7 @@ set session authorization regress_tenant; create table tenant_table (i int); -create index "tenant_idx" on tenant_table using btree (i); +create index tenant_idx on tenant_table using btree (i); create view tenant_view as select * from pg_catalog.pg_class; @@ -154,7 +154,7 @@ alter view tenant_view drop view tenant_view; -create schema "regress_tenant_schema" authorization regress_tenant; +create schema regress_tenant_schema authorization regress_tenant; reassign owned by regress_tenant to regress_createrole; @@ -162,7 +162,7 @@ set createrole_self_grant = 'set, inherit'; create role regress_tenant2; -grant CREATE on database regression to regress_tenant2; +grant create on database regression to regress_tenant2; set session authorization regress_tenant2; @@ -172,7 +172,7 @@ revoke all on table tenant2_table from public; set session authorization regress_createrole; -create schema "regress_tenant2_schema" authorization regress_tenant2; +create schema regress_tenant2_schema authorization regress_tenant2; alter schema regress_tenant2_schema owner to regress_createrole; @@ -182,14 +182,14 @@ alter table tenant2_table alter table tenant2_table owner to regress_tenant2; -revoke INHERIT option for REGRESS_TENANT2 from regress_createrole restrict; +revoke inherit option for regress_tenant2 from regress_createrole restrict; alter schema regress_tenant2_schema owner to regress_tenant2; alter table tenant2_table owner to regress_createrole; -grant REGRESS_TENANT2 to regress_createrole with INHERIT true, SET false; +grant regress_tenant2 to regress_createrole with inherit true, set false; alter table tenant2_table owner to regress_createrole; @@ -241,7 +241,7 @@ drop role regress_nosuch_admin_recursive; drop role regress_plainrole; -revoke CREATE on database regression from regress_createrole cascade; +revoke create on database regression from regress_createrole cascade; drop role regress_replication_bypassrls; @@ -277,7 +277,7 @@ drop role regress_rolecreator; reset session_authorization; -revoke CREATE on database regression from regress_role_admin cascade; +revoke create on database regression from regress_role_admin cascade; drop index tenant_idx; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_schema_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_schema_100.snap index 05ee54a9b..c7d9a2c65 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_schema_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_schema_100.snap @@ -57,24 +57,24 @@ on schema_not_existing.tab for each statement execute function schema_trig.no_func(); -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create sequence schema_not_existing.seq; -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create table schema_not_existing.tab (id int); -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create view schema_not_existing.view as select 1; -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create index on schema_not_existing.tab using btree (id); -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create trigger schema_trig before insert @@ -98,7 +98,7 @@ create table regress_create_schema_role.tab (id int); drop schema regress_create_schema_role cascade; -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create table regress_schema_1.tab (id int); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_schema_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_schema_80.snap index 05ee54a9b..c7d9a2c65 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_schema_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_schema_80.snap @@ -57,24 +57,24 @@ on schema_not_existing.tab for each statement execute function schema_trig.no_func(); -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create sequence schema_not_existing.seq; -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create table schema_not_existing.tab (id int); -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create view schema_not_existing.view as select 1; -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create index on schema_not_existing.tab using btree (id); -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create trigger schema_trig before insert @@ -98,7 +98,7 @@ create table regress_create_schema_role.tab (id int); drop schema regress_create_schema_role cascade; -create schema "regress_schema_1" authorization current_role; +create schema regress_schema_1 authorization current_role; create table regress_schema_1.tab (id int); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_100.snap index 6dd8a52d8..dd887015e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_100.snap @@ -92,10 +92,7 @@ deallocate select1; select 'CREATE TABLE extra_wide_table(firstc text, ' || - array_to_string( - array_agg('c' || i || ' bool'), - ',' - ) || + array_to_string(array_agg('c' || i || ' bool'), ',') || ', lastc text);' from generate_series(1, 1100) as g (i); @@ -120,10 +117,7 @@ create temporary table relation_filenode_check (c1 int); select relpersistence, - pg_filenode_relation( - reltablespace, - pg_relation_filenode(oid) - ) + pg_filenode_relation(reltablespace, pg_relation_filenode(oid)) from pg_class where @@ -135,11 +129,11 @@ create table default_expr_column (id int default id); create table default_expr_column (id int default bar.id); -create table default_expr_agg_column (id int default AVG(id)); +create table default_expr_agg_column (id int default avg(id)); -create table default_expr_non_column (a int default AVG(non_existent)); +create table default_expr_non_column (a int default avg(non_existent)); -create table default_expr_agg (a int default AVG(1)); +create table default_expr_agg (a int default avg(1)); create table default_expr_agg (a int default ((select 1))); @@ -178,21 +172,19 @@ drop table remember_node_subid; create table partitioned (a int) inherits (some_table) -partition by LIST(a); +partition by list(a); create table partitioned ( a1 int, a2 int ) -partition by LIST(a1, a2); +partition by list(a1, a2); create function retset(a int) returns setof int language sql immutable -as $function$ -SELECT 1; -$function$; +as $$ SELECT 1; $$; create table partitioned (a int) partition by range((retset(a))); @@ -200,16 +192,16 @@ partition by range((retset(a))); drop function retset(int); create table partitioned (a int) -partition by range((AVG(a))); +partition by range((avg(a))); create table partitioned ( a int, b int ) -partition by range((AVG(a) over (partition by b))); +partition by range((avg(a) over (partition by b))); create table partitioned (a int) -partition by LIST((a like (select 1))); +partition by list((a like (select 1))); create table partitioned (a int) partition by range((42)); @@ -218,9 +210,7 @@ create function const_func() returns int language sql immutable -as $function$ -SELECT 1; -$function$; +as $$ SELECT 1; $$; create table partitioned (a int) partition by range((const_func())); @@ -248,9 +238,7 @@ partition by range(a, ('unknown')); create function immut_func(a int) returns int language sql -as $function$ -SELECT a + random()::int; -$function$; +as $$ SELECT a + random()::int; $$; create table partitioned (a int) partition by range((immut_func(a))); @@ -258,10 +246,10 @@ partition by range((immut_func(a))); drop function immut_func(int); create table partitioned (a point) -partition by LIST(a); +partition by list(a); create table partitioned (a point) -partition by LIST(a point_ops); +partition by list(a point_ops); create table partitioned (a point) partition by range(a); @@ -271,16 +259,14 @@ partition by range(a point_ops); create table partitioned ( a int, - constraint "check_a" check (a > 0) no inherit + constraint check_a check (a > 0) no inherit ) partition by range(a); create function plusone(a int) returns int language sql -as $function$ -SELECT a+1; -$function$; +as $$ SELECT a+1; $$; create table partitioned ( a int, @@ -288,10 +274,7 @@ create table partitioned ( c text, d text ) -partition by range(a oid_ops, -(plusone(b)), -c collate "default", -d collate "C"); +partition by range(a oid_ops, (plusone(b)), c collate "default", d collate "C"); select relkind from pg_class where relname = 'partitioned'; @@ -316,7 +299,7 @@ create table partitioned ( a int, b int ) -partition by LIST((cast(row(a, b) as partitioned))); +partition by list((cast(row(a, b) as partitioned))); create table partitioned1 partition of partitioned for values in (cast('(1,2)' as partitioned)); @@ -330,7 +313,7 @@ create table partitioned ( a int, b int ) -partition by LIST((partitioned)); +partition by list((partitioned)); create table partitioned1 partition of partitioned for values in ('(1,2)'); @@ -375,7 +358,7 @@ drop domain intdom1 cascade; select * from partitioned; create table list_parted (a int) -partition by LIST(a); +partition by list(a); create table part_p1 partition of list_parted for values in ('1'); @@ -391,11 +374,11 @@ create table part_bogus_expr_fail partition of list_parted for values in (somena create table part_bogus_expr_fail partition of list_parted for values in (a); -create table part_bogus_expr_fail partition of list_parted for values in (SUM(a)); +create table part_bogus_expr_fail partition of list_parted for values in (sum(a)); -create table part_bogus_expr_fail partition of list_parted for values in (SUM(somename)); +create table part_bogus_expr_fail partition of list_parted for values in (sum(somename)); -create table part_bogus_expr_fail partition of list_parted for values in (SUM(1)); +create table part_bogus_expr_fail partition of list_parted for values in (sum(1)); create table part_bogus_expr_fail partition of list_parted for values in ((select 1)); @@ -405,21 +388,21 @@ create table part_bogus_expr_fail partition of list_parted for values in ((1 + 1 create table fail_part partition of list_parted for values from (1) to (2); -create table fail_part partition of list_parted for values with (MODULUS 10, REMAINDER 1); +create table fail_part partition of list_parted for values with (modulus 10, remainder 1); create table part_default partition of list_parted default; create table fail_default_part partition of list_parted default; -create table bools (a boolean) -partition by LIST(a); +create table bools (a bool) +partition by list(a); create table bools_true partition of bools for values in (1); drop table bools; create table moneyp (a money) -partition by LIST(a); +partition by list(a); create table moneyp_10 partition of moneyp for values in (10); @@ -430,7 +413,7 @@ create table moneyp_12 partition of moneyp for values in (cast(to_char(12, '99') drop table moneyp; create table bigintp (a bigint) -partition by LIST(a); +partition by list(a); create table bigintp_10 partition of bigintp for values in (10); @@ -453,15 +436,15 @@ create table part_bogus_expr_fail partition of range_parted for values from (a) create table part_bogus_expr_fail partition of range_parted -for values from (MAX(a)) to ('2019-01-01'); +for values from (max(a)) to ('2019-01-01'); create table part_bogus_expr_fail partition of range_parted -for values from (MAX(somename)) to ('2019-01-01'); +for values from (max(somename)) to ('2019-01-01'); create table part_bogus_expr_fail partition of range_parted -for values from (MAX(cast('2019-02-01' as date))) to ('2019-01-01'); +for values from (max(cast('2019-02-01' as date))) to ('2019-01-01'); create table part_bogus_expr_fail partition of range_parted @@ -473,7 +456,7 @@ for values from (generate_series(1, 3)) to ('2019-01-01'); create table fail_part partition of range_parted for values in ('a'); -create table fail_part partition of range_parted for values with (MODULUS 10, REMAINDER 1); +create table fail_part partition of range_parted for values with (modulus 10, remainder 1); create table fail_part partition of range_parted for values from ('a', 1) to ('z'); @@ -481,24 +464,24 @@ create table fail_part partition of range_parted for values from ('a') to ('z', create table fail_part partition of range_parted for values from (null) to (maxvalue); -create table fail_part partition of range_parted for values with (MODULUS 10, REMAINDER 1); +create table fail_part partition of range_parted for values with (modulus 10, remainder 1); create table hash_parted (a int) -partition by HASH(a); +partition by hash(a); -create table hpart_1 partition of hash_parted for values with (MODULUS 10, REMAINDER 0); +create table hpart_1 partition of hash_parted for values with (modulus 10, remainder 0); -create table hpart_2 partition of hash_parted for values with (MODULUS 50, REMAINDER 1); +create table hpart_2 partition of hash_parted for values with (modulus 50, remainder 1); -create table hpart_3 partition of hash_parted for values with (MODULUS 200, REMAINDER 2); +create table hpart_3 partition of hash_parted for values with (modulus 200, remainder 2); -create table hpart_4 partition of hash_parted for values with (MODULUS 10, REMAINDER 3); +create table hpart_4 partition of hash_parted for values with (modulus 10, remainder 3); -create table fail_part partition of hash_parted for values with (MODULUS 25, REMAINDER 3); +create table fail_part partition of hash_parted for values with (modulus 25, remainder 3); -create table fail_part partition of hash_parted for values with (MODULUS 150, REMAINDER 3); +create table fail_part partition of hash_parted for values with (modulus 150, remainder 3); -create table fail_part partition of hash_parted for values with (MODULUS 100, REMAINDER 3); +create table fail_part partition of hash_parted for values with (modulus 100, remainder 3); create table fail_part partition of hash_parted for values from ('a', 1) to ('z'); @@ -510,19 +493,19 @@ create table unparted (a int); create table fail_part partition of unparted for values in ('a'); -create table fail_part partition of unparted for values with (MODULUS 2, REMAINDER 1); +create table fail_part partition of unparted for values with (modulus 2, remainder 1); drop table unparted; create temporary table temp_parted (a int) -partition by LIST(a); +partition by list(a); create table fail_part partition of temp_parted for values in ('a'); drop table temp_parted; create table list_parted2 (a varchar) -partition by LIST(a); +partition by list(a); create table part_null_z partition of list_parted2 for values in (null, 'z'); @@ -596,28 +579,28 @@ create table range3_default partition of range_parted3 default; create table fail_part partition of range_parted3 for values from (1, minvalue) to (1, maxvalue); create table hash_parted2 (a varchar) -partition by HASH(a); +partition by hash(a); -create table h2part_1 partition of hash_parted2 for values with (MODULUS 4, REMAINDER 2); +create table h2part_1 partition of hash_parted2 for values with (modulus 4, remainder 2); -create table h2part_2 partition of hash_parted2 for values with (MODULUS 8, REMAINDER 0); +create table h2part_2 partition of hash_parted2 for values with (modulus 8, remainder 0); -create table h2part_3 partition of hash_parted2 for values with (MODULUS 8, REMAINDER 4); +create table h2part_3 partition of hash_parted2 for values with (modulus 8, remainder 4); -create table h2part_4 partition of hash_parted2 for values with (MODULUS 8, REMAINDER 5); +create table h2part_4 partition of hash_parted2 for values with (modulus 8, remainder 5); -create table fail_part partition of hash_parted2 for values with (MODULUS 2, REMAINDER 1); +create table fail_part partition of hash_parted2 for values with (modulus 2, remainder 1); -create table fail_part partition of hash_parted2 for values with (MODULUS 0, REMAINDER 1); +create table fail_part partition of hash_parted2 for values with (modulus 0, remainder 1); -create table fail_part partition of hash_parted2 for values with (MODULUS 8, REMAINDER 8); +create table fail_part partition of hash_parted2 for values with (modulus 8, remainder 8); create table parted ( a text, b int not null default 0, - constraint "check_a" check (length(a) > 0) + constraint check_a check (length(a) > 0) ) -partition by LIST(a); +partition by list(a); create table part_a partition of parted for values in ('a'); @@ -628,8 +611,7 @@ select from pg_attribute where - attrelid = cast('part_a' as regclass) and - attnum > 0 + attrelid = cast('part_a' as regclass) and attnum > 0 order by attnum; create table part_b @@ -638,7 +620,7 @@ partition of parted b not null, b default 1, b check (b >= 0), - constraint "check_a" check (length(a) > 0) + constraint check_a check (length(a) > 0) ) for values in ('b'); @@ -646,8 +628,8 @@ create table part_b partition of parted ( b not null default 1, - constraint "check_a" check (length(a) > 0), - constraint "check_b" check (b >= 0) + constraint check_a check (length(a) > 0), + constraint check_b check (b >= 0) ) for values in ('b'); @@ -663,7 +645,7 @@ order by coninhcount desc, conname; alter table parted - add constraint "check_b" check (b >= 0); + add constraint check_b check (b >= 0); select conname, @@ -713,7 +695,7 @@ create table parted_notnull_inh_test ( a int default 1, b int not null default 0 ) -partition by LIST(a); +partition by list(a); create table parted_notnull_inh_test1 partition of parted_notnull_inh_test @@ -728,10 +710,10 @@ insert into parted_notnull_inh_test (b) values (null); drop table parted_notnull_inh_test; create table parted_boolean_col ( - a boolean, + a bool, b text ) -partition by LIST(a); +partition by list(a); create table parted_boolean_less partition of parted_boolean_col for values in ('foo' < 'bar'); @@ -789,21 +771,13 @@ partition by range((abs(a)), (abs(b)), c); create table unbounded_range_part partition of range_parted4 -for values from (minvalue, -minvalue, -minvalue) to (maxvalue, -maxvalue, -maxvalue); +for values from (minvalue, minvalue, minvalue) to (maxvalue, maxvalue, maxvalue); drop table unbounded_range_part; create table range_parted4_1 partition of range_parted4 -for values from (minvalue, -minvalue, -minvalue) to (1, -maxvalue, -maxvalue); +for values from (minvalue, minvalue, minvalue) to (1, maxvalue, maxvalue); create table range_parted4_2 partition of range_parted4 @@ -811,32 +785,26 @@ for values from (3, 4, 5) to (6, 7, maxvalue); create table range_parted4_3 partition of range_parted4 -for values from (6, -8, -minvalue) to (9, -maxvalue, -maxvalue); +for values from (6, 8, minvalue) to (9, maxvalue, maxvalue); drop table range_parted4; -create function my_int4_sort(int, int) +create function my_int4_sort(int4, int4) returns int language sql -as $function$ -SELECT CASE WHEN $1 = $2 THEN 0 WHEN $1 > $2 THEN 1 ELSE -1 END; -$function$; +as $$ SELECT CASE WHEN $1 = $2 THEN 0 WHEN $1 > $2 THEN 1 ELSE -1 END; $$; create operator class test_int4_ops - for type int + for type int4 using btree - as operator 1 < (int, int), - operator 2 <= (int, int), - operator 3 = (int, int), - operator 4 >= (int, int), - operator 5 > (int, int), - function 1 my_int4_sort(int, int); - -create table partkey_t (a int) + as operator 1 < (int4, int4), + operator 2 <= (int4, int4), + operator 3 = (int4, int4), + operator 4 >= (int4, int4), + operator 5 > (int4, int4), + function 1 my_int4_sort(int4, int4); + +create table partkey_t (a int4) partition by range(a test_int4_ops); create table partkey_t_1 partition of partkey_t for values from (0) to (1000); @@ -851,13 +819,13 @@ drop table partkey_t, hash_parted, hash_parted2; drop operator class test_int4_ops using btree; -drop function my_int4_sort(int, int); +drop function my_int4_sort(int4, int4); create table parted_col_comment ( a int, b text ) -partition by LIST(a); +partition by list(a); comment on table parted_col_comment is 'Am partitioned table'; @@ -871,18 +839,18 @@ create table parted_col_comment ( a int, b text ) -partition by LIST(a) +partition by list(a) with (fillfactor = 100); create table arrlp (a int[]) -partition by LIST(a); +partition by list(a); create table arrlp12 partition of arrlp for values in ('{1}', '{2}'); drop table arrlp; -create table boolspart (a boolean) -partition by LIST(a); +create table boolspart (a bool) +partition by list(a); create table boolspart_t partition of boolspart for values in (true); @@ -891,10 +859,10 @@ create table boolspart_f partition of boolspart for values in (false); drop table boolspart; create table perm_parted (a int) -partition by LIST(a); +partition by list(a); create temporary table temp_parted (a int) -partition by LIST(a); +partition by list(a); create table perm_part partition of temp_parted default; @@ -907,17 +875,16 @@ drop table perm_parted cascade; drop table temp_parted cascade; create table tab_part_create (a int) -partition by LIST(a); +partition by list(a); create or replace function func_part_create() returns trigger language plpgsql -as $function$ -begin +as $$ + begin execute 'create table tab_part_create_1 partition of tab_part_create for values in (1)'; return null; - end -$function$; + end $$; create trigger trig_part_create before insert @@ -952,7 +919,7 @@ create table defcheck ( a int, b int ) -partition by LIST(b); +partition by list(b); create table defcheck_def ( a int, @@ -997,27 +964,13 @@ alter table part_column_drop alter table part_column_drop drop column useless_3; -create index "part_column_drop_b_pred" -on part_column_drop -using btree -( - b -) -where - b = 1; +create index part_column_drop_b_pred on part_column_drop using btree (b) where b = 1; -create index "part_column_drop_b_expr" on part_column_drop using btree ((b = 1)); +create index part_column_drop_b_expr on part_column_drop using btree ((b = 1)); -create index "part_column_drop_d_pred" -on part_column_drop -using btree -( - d -) -where - d = 2; +create index part_column_drop_d_pred on part_column_drop using btree (d) where d = 2; -create index "part_column_drop_d_expr" on part_column_drop using btree ((d = 2)); +create index part_column_drop_d_expr on part_column_drop using btree ((d = 2)); create table part_column_drop_1_10 partition of part_column_drop for values from (1) to (10); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_80.snap index 33d215005..a68489255 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_80.snap @@ -74,12 +74,7 @@ create table as_select1 as select * from pg_class where relkind = 'r'; create table if not exists as_select1 as - select - * - from - pg_class - where - relkind = 'r'; + select * from pg_class where relkind = 'r'; drop table as_select1; @@ -99,10 +94,7 @@ deallocate select1; select 'CREATE TABLE extra_wide_table(firstc text, ' || - array_to_string( - array_agg('c' || i || ' bool'), - ',' - ) || + array_to_string(array_agg('c' || i || ' bool'), ',') || ', lastc text);' from generate_series(1, 1100) as g (i); @@ -127,10 +119,7 @@ create temporary table relation_filenode_check (c1 int); select relpersistence, - pg_filenode_relation( - reltablespace, - pg_relation_filenode(oid) - ) + pg_filenode_relation(reltablespace, pg_relation_filenode(oid)) from pg_class where @@ -142,11 +131,11 @@ create table default_expr_column (id int default id); create table default_expr_column (id int default bar.id); -create table default_expr_agg_column (id int default AVG(id)); +create table default_expr_agg_column (id int default avg(id)); -create table default_expr_non_column (a int default AVG(non_existent)); +create table default_expr_non_column (a int default avg(non_existent)); -create table default_expr_agg (a int default AVG(1)); +create table default_expr_agg (a int default avg(1)); create table default_expr_agg (a int default ((select 1))); @@ -185,21 +174,19 @@ drop table remember_node_subid; create table partitioned (a int) inherits (some_table) -partition by LIST(a); +partition by list(a); create table partitioned ( a1 int, a2 int ) -partition by LIST(a1, a2); +partition by list(a1, a2); create function retset(a int) returns setof int language sql immutable -as $function$ -SELECT 1; -$function$; +as $$ SELECT 1; $$; create table partitioned (a int) partition by range((retset(a))); @@ -207,16 +194,16 @@ partition by range((retset(a))); drop function retset(int); create table partitioned (a int) -partition by range((AVG(a))); +partition by range((avg(a))); create table partitioned ( a int, b int ) -partition by range((AVG(a) over (partition by b))); +partition by range((avg(a) over (partition by b))); create table partitioned (a int) -partition by LIST((a like (select 1))); +partition by list((a like (select 1))); create table partitioned (a int) partition by range((42)); @@ -225,9 +212,7 @@ create function const_func() returns int language sql immutable -as $function$ -SELECT 1; -$function$; +as $$ SELECT 1; $$; create table partitioned (a int) partition by range((const_func())); @@ -255,9 +240,7 @@ partition by range(a, ('unknown')); create function immut_func(a int) returns int language sql -as $function$ -SELECT a + random()::int; -$function$; +as $$ SELECT a + random()::int; $$; create table partitioned (a int) partition by range((immut_func(a))); @@ -265,10 +248,10 @@ partition by range((immut_func(a))); drop function immut_func(int); create table partitioned (a point) -partition by LIST(a); +partition by list(a); create table partitioned (a point) -partition by LIST(a point_ops); +partition by list(a point_ops); create table partitioned (a point) partition by range(a); @@ -278,16 +261,14 @@ partition by range(a point_ops); create table partitioned ( a int, - constraint "check_a" check (a > 0) no inherit + constraint check_a check (a > 0) no inherit ) partition by range(a); create function plusone(a int) returns int language sql -as $function$ -SELECT a+1; -$function$; +as $$ SELECT a+1; $$; create table partitioned ( a int, @@ -295,10 +276,7 @@ create table partitioned ( c text, d text ) -partition by range(a oid_ops, -(plusone(b)), -c collate "default", -d collate "C"); +partition by range(a oid_ops, (plusone(b)), c collate "default", d collate "C"); select relkind from pg_class where relname = 'partitioned'; @@ -308,8 +286,7 @@ create table partitioned2 ( a int, b text ) -partition by range((a + 1), -(substr(b, 1, 5))); +partition by range((a + 1), (substr(b, 1, 5))); create table fail () inherits (partitioned2); @@ -318,9 +295,7 @@ insert into partitioned2 values (1, 'hello'); create table part2_1 partition of partitioned2 -for values from (-1, -'aaaaa') to (100, -'ccccc'); +for values from (-1, 'aaaaa') to (100, 'ccccc'); drop table partitioned, partitioned2; @@ -328,7 +303,7 @@ create table partitioned ( a int, b int ) -partition by LIST((cast(row(a, b) as partitioned))); +partition by list((cast(row(a, b) as partitioned))); create table partitioned1 partition of partitioned @@ -343,8 +318,7 @@ select from partitioned where - cast(row(a, b) as partitioned) = - cast('(1,2)' as partitioned); + cast(row(a, b) as partitioned) = cast('(1,2)' as partitioned); drop table partitioned; @@ -352,7 +326,7 @@ create table partitioned ( a int, b int ) -partition by LIST((partitioned)); +partition by list((partitioned)); create table partitioned1 partition of partitioned for values in ('(1,2)'); @@ -397,7 +371,7 @@ drop domain intdom1 cascade; select * from partitioned; create table list_parted (a int) -partition by LIST(a); +partition by list(a); create table part_p1 partition of list_parted for values in ('1'); @@ -419,15 +393,15 @@ create table part_bogus_expr_fail partition of list_parted for values in (a); create table part_bogus_expr_fail partition of list_parted -for values in (SUM(a)); +for values in (sum(a)); create table part_bogus_expr_fail partition of list_parted -for values in (SUM(somename)); +for values in (sum(somename)); create table part_bogus_expr_fail partition of list_parted -for values in (SUM(1)); +for values in (sum(1)); create table part_bogus_expr_fail partition of list_parted @@ -445,21 +419,21 @@ create table fail_part partition of list_parted for values from (1) to (2); create table fail_part partition of list_parted -for values with (MODULUS 10, REMAINDER 1); +for values with (modulus 10, remainder 1); create table part_default partition of list_parted default; create table fail_default_part partition of list_parted default; -create table bools (a boolean) -partition by LIST(a); +create table bools (a bool) +partition by list(a); create table bools_true partition of bools for values in (1); drop table bools; create table moneyp (a money) -partition by LIST(a); +partition by list(a); create table moneyp_10 partition of moneyp for values in (10); @@ -472,7 +446,7 @@ for values in (cast(to_char(12, '99') as int)); drop table moneyp; create table bigintp (a bigint) -partition by LIST(a); +partition by list(a); create table bigintp_10 partition of bigintp for values in (10); @@ -497,15 +471,15 @@ for values from (a) to ('2019-01-01'); create table part_bogus_expr_fail partition of range_parted -for values from (MAX(a)) to ('2019-01-01'); +for values from (max(a)) to ('2019-01-01'); create table part_bogus_expr_fail partition of range_parted -for values from (MAX(somename)) to ('2019-01-01'); +for values from (max(somename)) to ('2019-01-01'); create table part_bogus_expr_fail partition of range_parted -for values from (MAX(cast('2019-02-01' as date))) to ('2019-01-01'); +for values from (max(cast('2019-02-01' as date))) to ('2019-01-01'); create table part_bogus_expr_fail partition of range_parted @@ -519,7 +493,7 @@ create table fail_part partition of range_parted for values in ('a'); create table fail_part partition of range_parted -for values with (MODULUS 10, REMAINDER 1); +for values with (modulus 10, remainder 1); create table fail_part partition of range_parted @@ -535,38 +509,38 @@ for values from (null) to (maxvalue); create table fail_part partition of range_parted -for values with (MODULUS 10, REMAINDER 1); +for values with (modulus 10, remainder 1); create table hash_parted (a int) -partition by HASH(a); +partition by hash(a); create table hpart_1 partition of hash_parted -for values with (MODULUS 10, REMAINDER 0); +for values with (modulus 10, remainder 0); create table hpart_2 partition of hash_parted -for values with (MODULUS 50, REMAINDER 1); +for values with (modulus 50, remainder 1); create table hpart_3 partition of hash_parted -for values with (MODULUS 200, REMAINDER 2); +for values with (modulus 200, remainder 2); create table hpart_4 partition of hash_parted -for values with (MODULUS 10, REMAINDER 3); +for values with (modulus 10, remainder 3); create table fail_part partition of hash_parted -for values with (MODULUS 25, REMAINDER 3); +for values with (modulus 25, remainder 3); create table fail_part partition of hash_parted -for values with (MODULUS 150, REMAINDER 3); +for values with (modulus 150, remainder 3); create table fail_part partition of hash_parted -for values with (MODULUS 100, REMAINDER 3); +for values with (modulus 100, remainder 3); create table fail_part partition of hash_parted @@ -582,19 +556,19 @@ create table fail_part partition of unparted for values in ('a'); create table fail_part partition of unparted -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); drop table unparted; create temporary table temp_parted (a int) -partition by LIST(a); +partition by list(a); create table fail_part partition of temp_parted for values in ('a'); drop table temp_parted; create table list_parted2 (a varchar) -partition by LIST(a); +partition by list(a); create table part_null_z partition of list_parted2 for values in (null, 'z'); @@ -657,9 +631,7 @@ partition by range(a, (b + 1)); create table part00 partition of range_parted3 -for values from (0, -minvalue) to (0, -maxvalue); +for values from (0, minvalue) to (0, maxvalue); create table fail_part partition of range_parted3 @@ -685,47 +657,45 @@ create table range3_default partition of range_parted3 default; create table fail_part partition of range_parted3 -for values from (1, -minvalue) to (1, -maxvalue); +for values from (1, minvalue) to (1, maxvalue); create table hash_parted2 (a varchar) -partition by HASH(a); +partition by hash(a); create table h2part_1 partition of hash_parted2 -for values with (MODULUS 4, REMAINDER 2); +for values with (modulus 4, remainder 2); create table h2part_2 partition of hash_parted2 -for values with (MODULUS 8, REMAINDER 0); +for values with (modulus 8, remainder 0); create table h2part_3 partition of hash_parted2 -for values with (MODULUS 8, REMAINDER 4); +for values with (modulus 8, remainder 4); create table h2part_4 partition of hash_parted2 -for values with (MODULUS 8, REMAINDER 5); +for values with (modulus 8, remainder 5); create table fail_part partition of hash_parted2 -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); create table fail_part partition of hash_parted2 -for values with (MODULUS 0, REMAINDER 1); +for values with (modulus 0, remainder 1); create table fail_part partition of hash_parted2 -for values with (MODULUS 8, REMAINDER 8); +for values with (modulus 8, remainder 8); create table parted ( a text, b int not null default 0, - constraint "check_a" check (length(a) > 0) + constraint check_a check (length(a) > 0) ) -partition by LIST(a); +partition by list(a); create table part_a partition of parted for values in ('a'); @@ -736,8 +706,7 @@ select from pg_attribute where - attrelid = cast('part_a' as regclass) and - attnum > 0 + attrelid = cast('part_a' as regclass) and attnum > 0 order by attnum; create table part_b @@ -746,7 +715,7 @@ partition of parted b not null, b default 1, b check (b >= 0), - constraint "check_a" check (length(a) > 0) + constraint check_a check (length(a) > 0) ) for values in ('b'); @@ -754,8 +723,8 @@ create table part_b partition of parted ( b not null default 1, - constraint "check_a" check (length(a) > 0), - constraint "check_b" check (b >= 0) + constraint check_a check (length(a) > 0), + constraint check_b check (b >= 0) ) for values in ('b'); @@ -771,7 +740,7 @@ order by coninhcount desc, conname; alter table parted - add constraint "check_b" check (b >= 0); + add constraint check_b check (b >= 0); select conname, @@ -824,7 +793,7 @@ create table parted_notnull_inh_test ( a int default 1, b int not null default 0 ) -partition by LIST(a); +partition by list(a); create table parted_notnull_inh_test1 partition of parted_notnull_inh_test @@ -839,10 +808,10 @@ insert into parted_notnull_inh_test (b) values (null); drop table parted_notnull_inh_test; create table parted_boolean_col ( - a boolean, + a bool, b text ) -partition by LIST(a); +partition by list(a); create table parted_boolean_less partition of parted_boolean_col @@ -902,64 +871,48 @@ create table range_parted4 ( b int, c int ) -partition by range((abs(a)), -(abs(b)), -c); +partition by range((abs(a)), (abs(b)), c); create table unbounded_range_part partition of range_parted4 -for values from (minvalue, -minvalue, -minvalue) to (maxvalue, -maxvalue, -maxvalue); +for values from (minvalue, minvalue, minvalue) to ( + maxvalue, + maxvalue, + maxvalue +); drop table unbounded_range_part; create table range_parted4_1 partition of range_parted4 -for values from (minvalue, -minvalue, -minvalue) to (1, -maxvalue, -maxvalue); +for values from (minvalue, minvalue, minvalue) to (1, maxvalue, maxvalue); create table range_parted4_2 partition of range_parted4 -for values from (3, -4, -5) to (6, -7, -maxvalue); +for values from (3, 4, 5) to (6, 7, maxvalue); create table range_parted4_3 partition of range_parted4 -for values from (6, -8, -minvalue) to (9, -maxvalue, -maxvalue); +for values from (6, 8, minvalue) to (9, maxvalue, maxvalue); drop table range_parted4; -create function my_int4_sort(int, int) +create function my_int4_sort(int4, int4) returns int language sql -as $function$ -SELECT CASE WHEN $1 = $2 THEN 0 WHEN $1 > $2 THEN 1 ELSE -1 END; -$function$; +as $$ SELECT CASE WHEN $1 = $2 THEN 0 WHEN $1 > $2 THEN 1 ELSE -1 END; $$; create operator class test_int4_ops - for type int + for type int4 using btree - as operator 1 < (int, int), - operator 2 <= (int, int), - operator 3 = (int, int), - operator 4 >= (int, int), - operator 5 > (int, int), - function 1 my_int4_sort(int, int); - -create table partkey_t (a int) + as operator 1 < (int4, int4), + operator 2 <= (int4, int4), + operator 3 = (int4, int4), + operator 4 >= (int4, int4), + operator 5 > (int4, int4), + function 1 my_int4_sort(int4, int4); + +create table partkey_t (a int4) partition by range(a test_int4_ops); create table partkey_t_1 partition of partkey_t for values from (0) to (1000); @@ -980,13 +933,13 @@ drop table partkey_t, hash_parted, hash_parted2; drop operator class test_int4_ops using btree; -drop function my_int4_sort(int, int); +drop function my_int4_sort(int4, int4); create table parted_col_comment ( a int, b text ) -partition by LIST(a); +partition by list(a); comment on table parted_col_comment is 'Am partitioned table'; @@ -1000,18 +953,18 @@ create table parted_col_comment ( a int, b text ) -partition by LIST(a) +partition by list(a) with (fillfactor = 100); create table arrlp (a int[]) -partition by LIST(a); +partition by list(a); create table arrlp12 partition of arrlp for values in ('{1}', '{2}'); drop table arrlp; -create table boolspart (a boolean) -partition by LIST(a); +create table boolspart (a bool) +partition by list(a); create table boolspart_t partition of boolspart for values in (true); @@ -1020,10 +973,10 @@ create table boolspart_f partition of boolspart for values in (false); drop table boolspart; create table perm_parted (a int) -partition by LIST(a); +partition by list(a); create temporary table temp_parted (a int) -partition by LIST(a); +partition by list(a); create table perm_part partition of temp_parted default; @@ -1036,17 +989,16 @@ drop table perm_parted cascade; drop table temp_parted cascade; create table tab_part_create (a int) -partition by LIST(a); +partition by list(a); create or replace function func_part_create() returns trigger language plpgsql -as $function$ -begin +as $$ + begin execute 'create table tab_part_create_1 partition of tab_part_create for values in (1)'; return null; - end -$function$; + end $$; create trigger trig_part_create before insert @@ -1081,7 +1033,7 @@ create table defcheck ( a int, b int ) -partition by LIST(b); +partition by list(b); create table defcheck_def ( a int, @@ -1126,37 +1078,15 @@ alter table part_column_drop alter table part_column_drop drop column useless_3; -create index "part_column_drop_b_pred" -on part_column_drop -using btree -( - b -) -where - b = 1; +create index part_column_drop_b_pred on part_column_drop using btree (b) +where b = 1; -create index "part_column_drop_b_expr" -on part_column_drop -using btree -( - (b = 1) -); +create index part_column_drop_b_expr on part_column_drop using btree ((b = 1)); -create index "part_column_drop_d_pred" -on part_column_drop -using btree -( - d -) -where - d = 2; +create index part_column_drop_d_pred on part_column_drop using btree (d) +where d = 2; -create index "part_column_drop_d_expr" -on part_column_drop -using btree -( - (d = 2) -); +create index part_column_drop_d_expr on part_column_drop using btree ((d = 2)); create table part_column_drop_1_10 partition of part_column_drop diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_like_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_like_100.snap index 6410b6a2d..51fde4e72 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_like_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_like_100.snap @@ -33,14 +33,14 @@ create table inhf ( like inhx ); -create table inhf (like inhx including CONSTRAINTS including DEFAULTS); +create table inhf (like inhx including constraints including defaults); insert into inhf default values; select * from inhf; alter table inhx - add constraint "foo" check (xx = 'text'); + add constraint foo check (xx = 'text'); alter table inhx add primary key (xx); @@ -53,7 +53,7 @@ drop table inhg; create table inhg ( x text, - like inhx including CONSTRAINTS, + like inhx including constraints, y text ); @@ -82,7 +82,7 @@ insert into test_like_id_2 (b) values ('b2'); select * from test_like_id_2; -create table test_like_id_3 (like test_like_id_1 including IDENTITY); +create table test_like_id_3 (like test_like_id_1 including identity); insert into test_like_id_3 (b) values ('b3'); @@ -100,7 +100,7 @@ insert into test_like_gen_2 (a) values (1); select * from test_like_gen_2; -create table test_like_gen_3 (like test_like_gen_1 including GENERATED); +create table test_like_gen_3 (like test_like_gen_1 including generated); insert into test_like_gen_3 (a) values (1); @@ -116,11 +116,11 @@ create table test_like_4 ( create table test_like_4a (like test_like_4); -create table test_like_4b (like test_like_4 including DEFAULTS); +create table test_like_4b (like test_like_4 including defaults); -create table test_like_4c (like test_like_4 including GENERATED); +create table test_like_4c (like test_like_4 including generated); -create table test_like_4d (like test_like_4 including DEFAULTS including GENERATED); +create table test_like_4d (like test_like_4 including defaults including generated); insert into test_like_4a (a) values (11); @@ -150,8 +150,7 @@ create table test_like_5x ( ); create table test_like_5c (like test_like_4 including all) -inherits (test_like_5, -test_like_5x); +inherits (test_like_5, test_like_5x); create table test_like_6 ( a int, @@ -174,7 +173,7 @@ drop table test_like_6, test_like_6c; create table inhg ( x text, - like inhx including INDEXES, + like inhx including indexes, y text ); @@ -186,7 +185,7 @@ drop table inhg; create table inhg ( x text, - like inhx including INDEXES, + like inhx including indexes, primary key (x) ); @@ -195,18 +194,11 @@ create table inhz ( yy int unique ); -create unique index "inhz_xx_idx" -on inhz -using btree -( - xx -) -where - xx <> 'test'; +create unique index inhz_xx_idx on inhz using btree (xx) where xx <> 'test'; create table inhg ( x text unique, - like inhz including INDEXES + like inhz including indexes ); insert into inhg (xx, yy, x) values ('test', 5, 10); @@ -221,19 +213,19 @@ drop table inhz; create table inhz ( x text references inhz, - like inhx including INDEXES + like inhx including indexes ); drop table inhz; alter table ctlt1 - add constraint "cc" check (length(b) > 100) not valid; + add constraint cc check (length(b) > 100) not valid; -create index "ctlt1_b_key" on ctlt1 using btree (b); +create index ctlt1_b_key on ctlt1 using btree (b); -create index "ctlt1_fnidx" on ctlt1 using btree ((a || b)); +create index ctlt1_fnidx on ctlt1 using btree ((a || b)); -create statistics ctlt1_a_b_stat on "a", "b" from ctlt1; +create statistics ctlt1_a_b_stat on a, b from ctlt1; create statistics ctlt1_expr_stat on (a || b) from ctlt1; @@ -274,7 +266,7 @@ alter table ctlt3 alter table ctlt3 alter column a set storage main; -create index "ctlt3_fnidx" on ctlt3 using btree ((a || c)); +create index ctlt3_fnidx on ctlt3 using btree ((a || c)); comment on column ctlt3.a is 'A3'; @@ -291,13 +283,13 @@ alter table ctlt4 alter column c set storage external; create table ctlt12_storage ( - like ctlt1 including STORAGE, - like ctlt2 including STORAGE + like ctlt1 including storage, + like ctlt2 including storage ); create table ctlt12_comments ( - like ctlt1 including COMMENTS, - like ctlt2 including COMMENTS + like ctlt1 including comments, + like ctlt2 including comments ); select @@ -311,7 +303,7 @@ where objoid = c.oid and c.conrelid = cast('ctlt12_comments' as regclass); -create table ctlt1_inh (like ctlt1 including COMMENTS including CONSTRAINTS) +create table ctlt1_inh (like ctlt1 including comments including constraints) inherits (ctlt1); select @@ -325,15 +317,10 @@ where c.conrelid = cast('ctlt1_inh' as regclass); create table ctlt13_inh () -inherits (ctlt1, -ctlt3); +inherits (ctlt1, ctlt3); create table ctlt13_like ( - like ctlt3 - including COMMENTS - including CONSTRAINTS - including INDEXES - including STORAGE + like ctlt3 including comments including constraints including indexes including storage ) inherits (ctlt1); @@ -380,10 +367,9 @@ order by s.stxname, objsubid; create table inh_error1 () -inherits (ctlt1, -ctlt4); +inherits (ctlt1, ctlt4); -create table inh_error2 (like ctlt4 including STORAGE) +create table inh_error2 (like ctlt4 including storage) inherits (ctlt1); create table pg_attrdef (like ctlt1 including all); @@ -392,7 +378,7 @@ drop table public.pg_attrdef; begin; -create schema "ctl_schema"; +create schema ctl_schema; set local search_path to ctl_schema, public; @@ -418,7 +404,7 @@ comment on constraint noinh_con_copy_b_not_null on noinh_con_copy is 'not null b comment on constraint noinh_con_copy_c_not_null on noinh_con_copy is 'not null c no inherit'; -create table noinh_con_copy1 (like noinh_con_copy including COMMENTS including CONSTRAINTS); +create table noinh_con_copy1 (like noinh_con_copy including comments including constraints); select conname, @@ -433,7 +419,7 @@ where order by conname collate "C"; create table noinh_con_copy1_parted (like noinh_con_copy including all) -partition by LIST(a); +partition by list(a); drop table noinh_con_copy, noinh_con_copy1; @@ -477,14 +463,14 @@ create table ctl_table ( e int default 1 ); -create index "ctl_table_a_key" on ctl_table using btree (a); +create index ctl_table_a_key on ctl_table using btree (a); comment on column ctl_table.b is 'Column b'; -create statistics ctl_table_stat on "a", "b" from ctl_table; +create statistics ctl_table_stat on a, b from ctl_table; alter table ctl_table - add constraint "foo" check (b = 'text'); + add constraint foo check (b = 'text'); alter table ctl_table alter column b set storage main; @@ -497,8 +483,7 @@ select from pg_attribute where - attrelid = cast('ctl_foreign_table1' as regclass) and - attnum > 0 + attrelid = cast('ctl_foreign_table1' as regclass) and attnum > 0 order by attnum; create foreign table ctl_foreign_table2 ( like ctl_table including all ) server ctl_s0; @@ -509,8 +494,7 @@ select from pg_attribute where - attrelid = cast('ctl_foreign_table2' as regclass) and - attnum > 0 + attrelid = cast('ctl_foreign_table2' as regclass) and attnum > 0 order by attnum; drop table ctl_table; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_like_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_like_80.snap index dc3a7fb5e..e6aaa8d71 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_like_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_table_like_80.snap @@ -33,14 +33,14 @@ create table inhf ( like inhx ); -create table inhf (like inhx including CONSTRAINTS including DEFAULTS); +create table inhf (like inhx including constraints including defaults); insert into inhf default values; select * from inhf; alter table inhx - add constraint "foo" check (xx = 'text'); + add constraint foo check (xx = 'text'); alter table inhx add primary key (xx); @@ -53,7 +53,7 @@ drop table inhg; create table inhg ( x text, - like inhx including CONSTRAINTS, + like inhx including constraints, y text ); @@ -82,7 +82,7 @@ insert into test_like_id_2 (b) values ('b2'); select * from test_like_id_2; -create table test_like_id_3 (like test_like_id_1 including IDENTITY); +create table test_like_id_3 (like test_like_id_1 including identity); insert into test_like_id_3 (b) values ('b3'); @@ -100,7 +100,7 @@ insert into test_like_gen_2 (a) values (1); select * from test_like_gen_2; -create table test_like_gen_3 (like test_like_gen_1 including GENERATED); +create table test_like_gen_3 (like test_like_gen_1 including generated); insert into test_like_gen_3 (a) values (1); @@ -116,14 +116,12 @@ create table test_like_4 ( create table test_like_4a (like test_like_4); -create table test_like_4b (like test_like_4 including DEFAULTS); +create table test_like_4b (like test_like_4 including defaults); -create table test_like_4c (like test_like_4 including GENERATED); +create table test_like_4c (like test_like_4 including generated); create table test_like_4d ( - like test_like_4 - including DEFAULTS - including GENERATED + like test_like_4 including defaults including generated ); insert into test_like_4a (a) values (11); @@ -154,8 +152,7 @@ create table test_like_5x ( ); create table test_like_5c (like test_like_4 including all) -inherits (test_like_5, -test_like_5x); +inherits (test_like_5, test_like_5x); create table test_like_6 ( a int, @@ -178,7 +175,7 @@ drop table test_like_6, test_like_6c; create table inhg ( x text, - like inhx including INDEXES, + like inhx including indexes, y text ); @@ -190,7 +187,7 @@ drop table inhg; create table inhg ( x text, - like inhx including INDEXES, + like inhx including indexes, primary key (x) ); @@ -199,18 +196,11 @@ create table inhz ( yy int unique ); -create unique index "inhz_xx_idx" -on inhz -using btree -( - xx -) -where - xx <> 'test'; +create unique index inhz_xx_idx on inhz using btree (xx) where xx <> 'test'; create table inhg ( x text unique, - like inhz including INDEXES + like inhz including indexes ); insert into inhg (xx, yy, x) values ('test', 5, 10); @@ -225,19 +215,19 @@ drop table inhz; create table inhz ( x text references inhz, - like inhx including INDEXES + like inhx including indexes ); drop table inhz; alter table ctlt1 - add constraint "cc" check (length(b) > 100) not valid; + add constraint cc check (length(b) > 100) not valid; -create index "ctlt1_b_key" on ctlt1 using btree (b); +create index ctlt1_b_key on ctlt1 using btree (b); -create index "ctlt1_fnidx" on ctlt1 using btree ((a || b)); +create index ctlt1_fnidx on ctlt1 using btree ((a || b)); -create statistics ctlt1_a_b_stat on "a", "b" from ctlt1; +create statistics ctlt1_a_b_stat on a, b from ctlt1; create statistics ctlt1_expr_stat on (a || b) from ctlt1; @@ -278,7 +268,7 @@ alter table ctlt3 alter table ctlt3 alter column a set storage main; -create index "ctlt3_fnidx" on ctlt3 using btree ((a || c)); +create index ctlt3_fnidx on ctlt3 using btree ((a || c)); comment on column ctlt3.a is 'A3'; @@ -295,13 +285,13 @@ alter table ctlt4 alter column c set storage external; create table ctlt12_storage ( - like ctlt1 including STORAGE, - like ctlt2 including STORAGE + like ctlt1 including storage, + like ctlt2 including storage ); create table ctlt12_comments ( - like ctlt1 including COMMENTS, - like ctlt2 including COMMENTS + like ctlt1 including comments, + like ctlt2 including comments ); select @@ -311,13 +301,11 @@ from pg_description, pg_constraint as c where - classoid = - cast('pg_constraint' as regclass) and + classoid = cast('pg_constraint' as regclass) and objoid = c.oid and - c.conrelid = - cast('ctlt12_comments' as regclass); + c.conrelid = cast('ctlt12_comments' as regclass); -create table ctlt1_inh (like ctlt1 including COMMENTS including CONSTRAINTS) +create table ctlt1_inh (like ctlt1 including comments including constraints) inherits (ctlt1); select @@ -326,22 +314,19 @@ from pg_description, pg_constraint as c where - classoid = - cast('pg_constraint' as regclass) and + classoid = cast('pg_constraint' as regclass) and objoid = c.oid and - c.conrelid = - cast('ctlt1_inh' as regclass); + c.conrelid = cast('ctlt1_inh' as regclass); create table ctlt13_inh () -inherits (ctlt1, -ctlt3); +inherits (ctlt1, ctlt3); create table ctlt13_like ( like ctlt3 - including COMMENTS - including CONSTRAINTS - including INDEXES - including STORAGE + including comments + including constraints + including indexes + including storage ) inherits (ctlt1); @@ -351,11 +336,9 @@ from pg_description, pg_constraint as c where - classoid = - cast('pg_constraint' as regclass) and + classoid = cast('pg_constraint' as regclass) and objoid = c.oid and - c.conrelid = - cast('ctlt13_like' as regclass); + c.conrelid = cast('ctlt13_like' as regclass); create table ctlt_all (like ctlt1 including all); @@ -371,8 +354,7 @@ where classoid = cast('pg_class' as regclass) and objoid = i.indexrelid and c.oid = i.indexrelid and - i.indrelid = - cast('ctlt_all' as regclass) + i.indrelid = cast('ctlt_all' as regclass) order by c.relname, objsubid; @@ -384,19 +366,16 @@ from pg_description, pg_statistic_ext as s where - classoid = - cast('pg_statistic_ext' as regclass) and + classoid = cast('pg_statistic_ext' as regclass) and objoid = s.oid and - s.stxrelid = - cast('ctlt_all' as regclass) + s.stxrelid = cast('ctlt_all' as regclass) order by s.stxname, objsubid; create table inh_error1 () -inherits (ctlt1, -ctlt4); +inherits (ctlt1, ctlt4); -create table inh_error2 (like ctlt4 including STORAGE) +create table inh_error2 (like ctlt4 including storage) inherits (ctlt1); create table pg_attrdef (like ctlt1 including all); @@ -405,7 +384,7 @@ drop table public.pg_attrdef; begin; -create schema "ctl_schema"; +create schema ctl_schema; set local search_path to ctl_schema, public; @@ -434,9 +413,7 @@ comment on constraint noinh_con_copy_c_not_null on noinh_con_copy is 'not null c no inherit'; create table noinh_con_copy1 ( - like noinh_con_copy - including COMMENTS - including CONSTRAINTS + like noinh_con_copy including comments including constraints ); select @@ -446,15 +423,13 @@ from pg_description, pg_constraint as c where - classoid = - cast('pg_constraint' as regclass) and + classoid = cast('pg_constraint' as regclass) and objoid = c.oid and - c.conrelid = - cast('noinh_con_copy1' as regclass) + c.conrelid = cast('noinh_con_copy1' as regclass) order by conname collate "C"; create table noinh_con_copy1_parted (like noinh_con_copy including all) -partition by LIST(a); +partition by list(a); drop table noinh_con_copy, noinh_con_copy1; @@ -498,14 +473,14 @@ create table ctl_table ( e int default 1 ); -create index "ctl_table_a_key" on ctl_table using btree (a); +create index ctl_table_a_key on ctl_table using btree (a); comment on column ctl_table.b is 'Column b'; -create statistics ctl_table_stat on "a", "b" from ctl_table; +create statistics ctl_table_stat on a, b from ctl_table; alter table ctl_table - add constraint "foo" check (b = 'text'); + add constraint foo check (b = 'text'); alter table ctl_table alter column b set storage main; @@ -518,9 +493,7 @@ select from pg_attribute where - attrelid = - cast('ctl_foreign_table1' as regclass) and - attnum > 0 + attrelid = cast('ctl_foreign_table1' as regclass) and attnum > 0 order by attnum; create foreign table ctl_foreign_table2 ( @@ -533,9 +506,7 @@ select from pg_attribute where - attrelid = - cast('ctl_foreign_table2' as regclass) and - attnum > 0 + attrelid = cast('ctl_foreign_table2' as regclass) and attnum > 0 order by attnum; drop table ctl_table; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_100.snap index 8af26961f..402cec997 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_100.snap @@ -7,36 +7,28 @@ returns widget language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; create function widget_out(widget) returns cstring language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; create function int44in(cstring) returns city_budget language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; create function int44out(city_budget) returns cstring language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; create type widget ( internallength = 24, @@ -51,7 +43,7 @@ create type city_budget ( internallength = 16, input = int44in, output = int44out, - element = int, + element = int4, category = 'x', preferred = 'true' ); @@ -75,42 +67,34 @@ returns int42 language internal immutable strict -as $function$ -int4in -$function$; +as 'int4in'; create function int42_out(int42) returns cstring language internal immutable strict -as $function$ -int4out -$function$; +as 'int4out'; create function text_w_default_in(cstring) returns text_w_default language internal immutable strict -as $function$ -textin -$function$; +as 'textin'; create function text_w_default_out(text_w_default) returns cstring language internal immutable strict -as $function$ -textout -$function$; +as 'textout'; create type int42 ( internallength = 4, input = int42_in, output = int42_out, - alignment = int, + alignment = int4, "default" = 42, passedbyvalue ); @@ -119,7 +103,7 @@ create type text_w_default ( internallength = variable, input = text_w_default_in, output = text_w_default_out, - alignment = int, + alignment = int4, "default" = 'zippo' ); @@ -138,7 +122,7 @@ create type bogus_type ( "Internallength" = 4, "Input" = int42_in, "Output" = int42_out, - "Alignment" = int, + "Alignment" = int4, "Default" = 42, "Passedbyvalue" ); @@ -154,9 +138,9 @@ create type default_test_row as (f1 text_w_default, f2 int42); create function get_default_test() returns setof default_test_row language sql -as $function$ -SELECT * FROM default_test; -$function$; +as ' + SELECT * FROM default_test; +'; select * from get_default_test(); @@ -185,18 +169,14 @@ returns base_type language internal immutable strict -as $function$ -boolin -$function$; +as 'boolin'; create function base_fn_out(base_type) returns cstring language internal immutable strict -as $function$ -boolout -$function$; +as 'boolout'; create type base_type (input = base_fn_in, output = base_fn_out); @@ -217,8 +197,7 @@ select from pg_attribute where - attrelid = cast('mytab' as regclass) and - attnum > 0; + attrelid = cast('mytab' as regclass) and attnum > 0; insert into mytab values ('(1,2,3)'), ('(-44,5.5,12)'); @@ -243,26 +222,22 @@ select pg_input_is_valid('("(1,2,3)")', 'mytab'); select pg_input_is_valid('("(1,2)")', 'mytab'); create function pt_in_widget(point, widget) -returns boolean +returns bool language c strict -as $function$ -regresslib -$function$; - -create operator <% (LEFTARG = point, -RIGHTARG = widget, -PROCEDURE = pt_in_widget, -COMMUTATOR = >%, -NEGATOR = >=%); +as 'regresslib'; + +create operator <% ( + leftarg = point, + rightarg = widget, + procedure = pt_in_widget, + commutator = >%, + negator = >=% +); select - cast('(1,2)' as point) <% - cast('(0,0,3)' as widget) - as t, - cast('(1,2)' as point) <% - cast('(0,0,1)' as widget) - as f; + cast('(1,2)' as point) <% cast('(0,0,3)' as widget) as t, + cast('(1,2)' as point) <% cast('(0,0,1)' as widget) as f; create table city ( name name, @@ -273,11 +248,7 @@ create table city ( insert into city values ('Podunk', '(1,2),(3,4)', '100,127,1000'), - ( - 'Gotham', - '(1000,34),(1100,334)', - '123456,127,-1000,6789' - ); + ('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789'); select * from city; @@ -288,40 +259,32 @@ returns myvarchar language internal immutable strict -parallel SAFE -as $function$ -varcharin -$function$; +parallel safe +as 'varcharin'; create function myvarcharout(myvarchar) returns cstring language internal immutable strict -parallel SAFE -as $function$ -varcharout -$function$; +parallel safe +as 'varcharout'; create function myvarcharsend(myvarchar) returns bytea language internal stable strict -parallel SAFE -as $function$ -varcharsend -$function$; +parallel safe +as 'varcharsend'; create function myvarcharrecv(internal, oid, int) returns myvarchar language internal stable strict -parallel SAFE -as $function$ -varcharrecv -$function$; +parallel safe +as 'varcharrecv'; alter type myvarchar set (storage = extended); @@ -334,12 +297,14 @@ alter type myvarchar set (storage = plain); alter type myvarchar set (storage = extended); alter type myvarchar -set (send = myvarcharsend, -receive = myvarcharrecv, -typmod_in = varchartypmodin, -typmod_out = varchartypmodout, -analyze = ts_typanalyze, -subscript = raw_array_subscript_handler); +set ( + send = myvarcharsend, + receive = myvarcharrecv, + typmod_in = varchartypmodin, + typmod_out = varchartypmodout, + analyze = ts_typanalyze, + subscript = raw_array_subscript_handler +); select typinput, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_80.snap index 27f0e1d47..da453ac37 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_80.snap @@ -7,36 +7,28 @@ returns widget language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; create function widget_out(widget) returns cstring language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; create function int44in(cstring) returns city_budget language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; create function int44out(city_budget) returns cstring language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; create type widget ( internallength = 24, @@ -51,7 +43,7 @@ create type city_budget ( internallength = 16, input = int44in, output = int44out, - element = int, + element = int4, category = 'x', preferred = 'true' ); @@ -75,42 +67,34 @@ returns int42 language internal immutable strict -as $function$ -int4in -$function$; +as 'int4in'; create function int42_out(int42) returns cstring language internal immutable strict -as $function$ -int4out -$function$; +as 'int4out'; create function text_w_default_in(cstring) returns text_w_default language internal immutable strict -as $function$ -textin -$function$; +as 'textin'; create function text_w_default_out(text_w_default) returns cstring language internal immutable strict -as $function$ -textout -$function$; +as 'textout'; create type int42 ( internallength = 4, input = int42_in, output = int42_out, - alignment = int, + alignment = int4, "default" = 42, passedbyvalue ); @@ -119,7 +103,7 @@ create type text_w_default ( internallength = variable, input = text_w_default_in, output = text_w_default_out, - alignment = int, + alignment = int4, "default" = 'zippo' ); @@ -138,7 +122,7 @@ create type bogus_type ( "Internallength" = 4, "Input" = int42_in, "Output" = int42_out, - "Alignment" = int, + "Alignment" = int4, "Default" = 42, "Passedbyvalue" ); @@ -164,9 +148,9 @@ create type default_test_row as (f1 text_w_default, f2 int42); create function get_default_test() returns setof default_test_row language sql -as $function$ -SELECT * FROM default_test; -$function$; +as ' + SELECT * FROM default_test; +'; select * from get_default_test(); @@ -195,18 +179,14 @@ returns base_type language internal immutable strict -as $function$ -boolin -$function$; +as 'boolin'; create function base_fn_out(base_type) returns cstring language internal immutable strict -as $function$ -boolout -$function$; +as 'boolout'; create type base_type (input = base_fn_in, output = base_fn_out); @@ -227,8 +207,7 @@ select from pg_attribute where - attrelid = cast('mytab' as regclass) and - attnum > 0; + attrelid = cast('mytab' as regclass) and attnum > 0; insert into mytab values ('(1,2,3)'), ('(-44,5.5,12)'); @@ -253,26 +232,22 @@ select pg_input_is_valid('("(1,2,3)")', 'mytab'); select pg_input_is_valid('("(1,2)")', 'mytab'); create function pt_in_widget(point, widget) -returns boolean +returns bool language c strict -as $function$ -regresslib -$function$; - -create operator <% (LEFTARG = point, -RIGHTARG = widget, -PROCEDURE = pt_in_widget, -COMMUTATOR = >%, -NEGATOR = >=%); +as 'regresslib'; + +create operator <% ( + leftarg = point, + rightarg = widget, + procedure = pt_in_widget, + commutator = >%, + negator = >=% +); select - cast('(1,2)' as point) <% - cast('(0,0,3)' as widget) - as t, - cast('(1,2)' as point) <% - cast('(0,0,1)' as widget) - as f; + cast('(1,2)' as point) <% cast('(0,0,3)' as widget) as t, + cast('(1,2)' as point) <% cast('(0,0,1)' as widget) as f; create table city ( name name, @@ -282,14 +257,8 @@ create table city ( insert into city values - ( - 'Podunk', '(1,2),(3,4)', '100,127,1000' - ), - ( - 'Gotham', - '(1000,34),(1100,334)', - '123456,127,-1000,6789' - ); + ('Podunk', '(1,2),(3,4)', '100,127,1000'), + ('Gotham', '(1000,34),(1100,334)', '123456,127,-1000,6789'); select * from city; @@ -300,40 +269,32 @@ returns myvarchar language internal immutable strict -parallel SAFE -as $function$ -varcharin -$function$; +parallel safe +as 'varcharin'; create function myvarcharout(myvarchar) returns cstring language internal immutable strict -parallel SAFE -as $function$ -varcharout -$function$; +parallel safe +as 'varcharout'; create function myvarcharsend(myvarchar) returns bytea language internal stable strict -parallel SAFE -as $function$ -varcharsend -$function$; +parallel safe +as 'varcharsend'; create function myvarcharrecv(internal, oid, int) returns myvarchar language internal stable strict -parallel SAFE -as $function$ -varcharrecv -$function$; +parallel safe +as 'varcharrecv'; alter type myvarchar set (storage = extended); @@ -351,12 +312,14 @@ alter type myvarchar set (storage = plain); alter type myvarchar set (storage = extended); alter type myvarchar -set (send = myvarcharsend, -receive = myvarcharrecv, -typmod_in = varchartypmodin, -typmod_out = varchartypmodout, -analyze = ts_typanalyze, -subscript = raw_array_subscript_handler); +set ( + send = myvarcharsend, + receive = myvarcharrecv, + typmod_in = varchartypmodin, + typmod_out = varchartypmodout, + analyze = ts_typanalyze, + subscript = raw_array_subscript_handler +); select typinput, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_100.snap index 819aac827..27cd8a96b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_100.snap @@ -6,12 +6,10 @@ create function interpt_pp(path, path) returns point language c strict -as $function$ -regresslib -$function$; +as 'regresslib'; create table real_city ( - pop int, + pop int4, cname text, outline path ); @@ -45,13 +43,7 @@ where ih.thepath ?# r.thepath; create view toyemp -as select - name, - age, - location, - 12 * salary as annualsal -from - emp; +as select name, age, location, 12 * salary as annualsal from emp; comment on view noview is 'no view'; @@ -71,12 +63,7 @@ alter table view_base_table drop constraint view_base_table_pkey; create view key_dependent_view_no_cols -as select -from - view_base_table -group by key -having - length(data) > 0; +as select from view_base_table group by key having length(data) > 0; create table viewtest_tbl ( a int, @@ -94,16 +81,7 @@ as select * from viewtest_tbl where a > 10; select * from viewtest; create or replace view viewtest -as select - a, - b, - c, - d -from - viewtest_tbl -where - a > 5 -order by b desc; +as select a, b, c, d from viewtest_tbl where a > 5 order by b desc; select * from viewtest; @@ -114,31 +92,13 @@ create or replace view viewtest as select 1, * from viewtest_tbl; create or replace view viewtest -as select - a, - cast(b as numeric), - c, - d -from - viewtest_tbl; +as select a, cast(b as numeric), c, d from viewtest_tbl; create or replace view viewtest -as select - a, - b, - cast(c as numeric(10, 2)), - d -from - viewtest_tbl; +as select a, b, cast(c as numeric(10, 2)), d from viewtest_tbl; create or replace view viewtest -as select - a, - b, - c, - d collate "POSIX" -from - viewtest_tbl; +as select a, b, c, d collate "POSIX" from viewtest_tbl; create or replace view viewtest as select a, b, c, d, 0 as e from viewtest_tbl; @@ -147,7 +107,7 @@ drop view viewtest; drop table viewtest_tbl; -create schema "temp_view_test"; +create schema temp_view_test; create table base_table ( a int, @@ -181,30 +141,16 @@ as select * from base_table; create view temp_view_test.v3_temp as select * from temp_table; -create schema "test_view_schema"; +create schema test_view_schema; create temporary view testview as select 1; create view v3 -as select - t1.a as t1_a, - t2.a as t2_a -from - base_table as t1, - base_table2 as t2 -where - t1.id = t2.id; +as select t1.a as t1_a, t2.a as t2_a from base_table as t1, base_table2 as t2 where t1.id = t2.id; create view v4_temp -as select - t1.a as t1_a, - t2.a as t2_a -from - base_table as t1, - temp_table as t2 -where - t1.id = t2.id; +as select t1.a as t1_a, t2.a as t2_a from base_table as t1, temp_table as t2 where t1.id = t2.id; create view v5_temp as select @@ -219,82 +165,37 @@ where t1.id = t2.id and t2.id = t3.id; create view v4 -as select - * -from - base_table -where - id in (select id from base_table2); +as select * from base_table where id in (select id from base_table2); create view v5 -as select - t1.id, - t2.a -from - base_table as t1, - (select * from base_table2) as t2; +as select t1.id, t2.a from base_table as t1, (select * from base_table2) as t2; create view v6 -as select - * -from - base_table -where - exists (select 1 from base_table2); +as select * from base_table where exists (select 1 from base_table2); create view v7 -as select - * -from - base_table -where - not exists (select 1 from base_table2); +as select * from base_table where not exists (select 1 from base_table2); create view v8 as select * from base_table where exists (select 1); create view v6_temp -as select - * -from - base_table -where - id in (select id from temp_table); +as select * from base_table where id in (select id from temp_table); create view v7_temp -as select - t1.id, - t2.a -from - base_table as t1, - (select * from temp_table) as t2; +as select t1.id, t2.a from base_table as t1, (select * from temp_table) as t2; create view v8_temp -as select - * -from - base_table -where - exists (select 1 from temp_table); +as select * from base_table where exists (select 1 from temp_table); create view v9_temp -as select - * -from - base_table -where - not exists (select 1 from temp_table); +as select * from base_table where not exists (select 1 from temp_table); create view v10_temp as select * from v7_temp; create view v11_temp -as select - t1.id, - t2.a -from - base_table as t1, - v10_temp as t2; +as select t1.id, t2.a from base_table as t1, v10_temp as t2; create view v12_temp as select true from v11_temp; @@ -315,15 +216,7 @@ from pg_class where relname like 'v_' and - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'temp_view_test' - ) + relnamespace = (select oid from pg_namespace where nspname = 'temp_view_test') order by relname; select @@ -331,19 +224,10 @@ select from pg_class where - relname like 'v%' and - relnamespace in - ( - select - oid - from - pg_namespace - where - nspname like 'pg_temp%' - ) + relname like 'v%' and relnamespace in (select oid from pg_namespace where nspname like 'pg_temp%') order by relname; -create schema "testviewschm2"; +create schema testviewschm2; set search_path to testviewschm2, public; @@ -375,34 +259,16 @@ create view temporal2 as select * from t1 inner join tt on t1.num = tt.num2; create view nontemp3 -as select - * -from - t1 left outer join t2 on t1.num = t2.num2; +as select * from t1 left outer join t2 on t1.num = t2.num2; create view temporal3 -as select - * -from - t1 left outer join tt on t1.num = tt.num2; +as select * from t1 left outer join tt on t1.num = tt.num2; create view nontemp4 -as select - * -from - t1 - left outer join - t2 - on t1.num = t2.num2 and t2.value = 'xxx'; +as select * from t1 left outer join t2 on t1.num = t2.num2 and t2.value = 'xxx'; create view temporal4 -as select - * -from - t1 - left outer join - tt - on t1.num = tt.num2 and tt.value = 'xxx'; +as select * from t1 left outer join tt on t1.num = tt.num2 and tt.value = 'xxx'; select relname @@ -410,15 +276,7 @@ from pg_class where relname like 'nontemp%' and - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'testviewschm2' - ) + relnamespace = (select oid from pg_namespace where nspname = 'testviewschm2') order by relname; select @@ -427,15 +285,7 @@ from pg_class where relname like 'temporal%' and - relnamespace in - ( - select - oid - from - pg_namespace - where - nspname like 'pg_temp%' - ) + relnamespace in (select oid from pg_namespace where nspname like 'pg_temp%') order by relname; create table tbl1 ( @@ -469,32 +319,16 @@ as select from tbl1 where - tbl1.a - between (select d from tbl2 where c = 1) - and (select e from tbl3 where f = 2) and - exists - ( - select - g - from - tbl4 left outer join tbl3 on tbl4.h = tbl3.f - ); + tbl1.a between (select d from tbl2 where c = 1) and (select e from tbl3 where f = 2) and + exists (select g from tbl4 left outer join tbl3 on tbl4.h = tbl3.f); select - COUNT(*) + count(*) from pg_class where relname = 'pubview' and - relnamespace in - ( - select - oid - from - pg_namespace - where - nspname = 'testviewschm2' - ); + relnamespace in (select oid from pg_namespace where nspname = 'testviewschm2'); create view mytempview as select @@ -502,39 +336,17 @@ as select from tbl1 where - tbl1.a - between (select d from tbl2 where c = 1) - and (select e from tbl3 where f = 2) and - exists - ( - select - g - from - tbl4 left outer join tbl3 on tbl4.h = tbl3.f - ) and - not exists - ( - select - g - from - tbl4 left outer join tmptbl on tbl4.h = tmptbl.j - ); + tbl1.a between (select d from tbl2 where c = 1) and (select e from tbl3 where f = 2) and + exists (select g from tbl4 left outer join tbl3 on tbl4.h = tbl3.f) and + not exists (select g from tbl4 left outer join tmptbl on tbl4.h = tmptbl.j); select - COUNT(*) + count(*) from pg_class where relname like 'mytempview' and - relnamespace in - ( - select - oid - from - pg_namespace - where - nspname like 'pg_temp%' - ); + relnamespace in (select oid from pg_namespace where nspname like 'pg_temp%'); create view mysecview1 as select * from tbl1 where a = 0; @@ -564,8 +376,7 @@ create view mysecview7 as select * from tbl1 where a = 100; create view mysecview8 - with (security_invoker = 'false', - security_barrier = 'true') + with (security_invoker = 'false', security_barrier = 'true') as select * from tbl1 where a > 100; create view mysecview9 @@ -613,8 +424,7 @@ create or replace view mysecview8 as select * from tbl1 where a < 256; create or replace view mysecview9 - with (security_invoker = 'false', - security_barrier = 'true') + with (security_invoker = 'false', security_barrier = 'true') as select * from tbl1 where a <> 256; select @@ -633,12 +443,7 @@ where order by relname; create view unspecified_types -as select - 42 as i, - 42.5 as num, - 'foo' as u, - cast('foo' as unknown) as u2, - null as n; +as select 42 as i, 42.5 as num, 'foo' as u, cast('foo' as unknown) as u2, null as n; select * from unspecified_types; @@ -648,18 +453,8 @@ as select from ( values - ( - cast('abc' as varchar(3)), - '0123456789', - 42, - cast('abcd' as varchar(4)) - ), - ( - '0123456789', - cast('abc' as varchar(3)), - 42.12, - cast('abc' as varchar(4)) - ) + (cast('abc' as varchar(3)), '0123456789', 42, cast('abcd' as varchar(4))), + ('0123456789', cast('abc' as varchar(3)), 42.12, cast('abc' as varchar(4))) ) as vv (a, b, c, d); @@ -688,31 +483,13 @@ create table temp_view_test.tt1 ( ); create view aliased_view_1 -as select - * -from - tt1 -where - exists (select 1 from tx1 where tt1.f1 = tx1.x1); +as select * from tt1 where exists (select 1 from tx1 where tt1.f1 = tx1.x1); create view aliased_view_2 -as select - * -from - tt1 as a1 -where - exists (select 1 from tx1 where a1.f1 = tx1.x1); +as select * from tt1 as a1 where exists (select 1 from tx1 where a1.f1 = tx1.x1); create view aliased_view_3 -as select - * -from - tt1 -where - exists - ( - select 1 from tx1 as a2 where tt1.f1 = a2.x1 - ); +as select * from tt1 where exists (select 1 from tx1 as a2 where tt1.f1 = a2.x1); create view aliased_view_4 as select @@ -720,15 +497,7 @@ as select from temp_view_test.tt1 where - exists - ( - select - 1 - from - tt1 - where - temp_view_test.tt1.y1 = tt1.f1 - ); + exists (select 1 from tt1 where temp_view_test.tt1.y1 = tt1.f1); alter table tx1 rename to a1; @@ -757,14 +526,8 @@ create view view_of_joins as select * from - ( - select - * - from - (tbl1 inner join tbl2 on true) as "same" - ) - as ss, - (tbl3 inner join tbl4 on true) as "same"; + (select * from (tbl1 inner join tbl2 on true) as same) as ss, + (tbl3 inner join tbl4 on true) as same; create table tbl1a ( a int, @@ -772,25 +535,16 @@ create table tbl1a ( ); create view view_of_joins_2a -as select * from tbl1 inner join tbl1a using ("a"); +as select * from tbl1 inner join tbl1a using (a); create view view_of_joins_2b -as select - * -from - tbl1 inner join tbl1a using ("a") as "x"; +as select * from tbl1 inner join tbl1a using (a) as x; create view view_of_joins_2c -as select - * -from - (tbl1 inner join tbl1a using ("a")) as "y"; +as select * from (tbl1 inner join tbl1a using (a)) as y; create view view_of_joins_2d -as select - * -from - (tbl1 inner join tbl1a using ("a") as "x") as "y"; +as select * from (tbl1 inner join tbl1a using (a) as x) as y; select pg_get_viewdef('view_of_joins_2a', true); @@ -807,8 +561,8 @@ create table tt2 ( ); create table tt3 ( - ax bigint, - b smallint, + ax int8, + b int2, c numeric ); @@ -822,34 +576,16 @@ create view v1 as select * from tt2 natural join tt3; create view v1a -as select * from (tt2 natural join tt3) as "j"; +as select * from (tt2 natural join tt3) as j; create view v2 -as select - * -from - tt2 inner join tt3 using ( "b", "c") - inner join - tt4 - using ("b"); +as select * from tt2 inner join tt3 using ( b, c) inner join tt4 using (b); create view v2a -as select - * -from - (tt2 inner join tt3 using ( "b", "c") - inner join - tt4 - using ("b")) as "j"; +as select * from (tt2 inner join tt3 using ( b, c) inner join tt4 using (b)) as j; create view v3 -as select - * -from - tt2 inner join tt3 using ( "b", "c") - full outer join - tt4 - using ("b"); +as select * from tt2 inner join tt3 using ( b, c) full outer join tt4 using (b); select pg_get_viewdef('v1', true); @@ -929,16 +665,7 @@ create table tt6 ( ); create view vv1 -as select - * -from - (tt5 - inner join - tt6 - on true) as "j" ("aa", - "bb", - "cc", - "dd"); +as select * from (tt5 inner join tt6 on true) as j (aa, bb, cc, dd); select pg_get_viewdef('vv1', true); @@ -981,59 +708,27 @@ create table tt8 ( ); create view vv2 -as select - * -from - (values (1, 2, 3, 4, 5)) as v (a, b, c, d, e) +as select * from (values (1, 2, 3, 4, 5)) as v (a, b, c, d, e) union all -select - * -from - tt7 full outer join tt8 using ("x"), - tt8 as tt8x; +select * from tt7 full outer join tt8 using (x), tt8 as tt8x; select pg_get_viewdef('vv2', true); create view vv3 -as select - * -from - ( - values (1, 2, 3, 4, 5, 6) - ) - as v (a, b, c, x, e, f) +as select * from (values (1, 2, 3, 4, 5, 6)) as v (a, b, c, x, e, f) union all -select - * -from - tt7 full outer join tt8 using ("x"), - tt7 as tt7x - full outer join - tt8 as tt8x - using ("x"); +select * from tt7 full outer join tt8 using (x), tt7 as tt7x full outer join tt8 as tt8x using (x); select pg_get_viewdef('vv3', true); create view vv4 -as select - * -from - ( - values (1, 2, 3, 4, 5, 6, 7) - ) - as v (a, b, c, x, e, f, g) +as select * from (values (1, 2, 3, 4, 5, 6, 7)) as v (a, b, c, x, e, f, g) union all select * from - tt7 full outer join tt8 using ("x"), - tt7 as tt7x - full outer join - tt8 as tt8x - using ("x") - full outer join - tt8 as tt8y - using ("x"); + tt7 full outer join tt8 using (x), + tt7 as tt7x full outer join tt8 as tt8x using (x) full outer join tt8 as tt8y using (x); select pg_get_viewdef('vv4', true); @@ -1065,24 +760,14 @@ alter table tt7a drop column xx; create table tt8a ( - x timestamp with time zone, + x timestamptz, z int ); create view vv2a -as select - * -from - ( - values (NOW(), 2, 3, NOW(), 5) - ) - as v (a, b, c, d, e) +as select * from (values (now(), 2, 3, now(), 5)) as v (a, b, c, d, e) union all -select - * -from - tt7a left outer join tt8a using ("x"), - tt8a as tt8ax; +select * from tt7a left outer join tt8a using (x), tt8a as tt8ax; select pg_get_viewdef('vv2a', true); @@ -1098,12 +783,7 @@ create table tt10 ( ); create view vv5 -as select - x, - y, - z -from - tt9 inner join tt10 using ("x"); +as select x, y, z from tt9 inner join tt10 using (x); select pg_get_viewdef('vv5', true); @@ -1128,16 +808,7 @@ create table tt13 ( ); create view vv6 -as select - x, - y, - z, - q -from - tt11 inner join tt12 using ("x") - inner join - tt13 - using ("z"); +as select x, y, z, q from tt11 inner join tt12 using (x) inner join tt13 using (z); select pg_get_viewdef('vv6', true); @@ -1161,7 +832,7 @@ alter table tt14t create function tt14f() returns setof tt14t language plpgsql -as $function$ +as $$ declare rec1 record; begin @@ -1170,7 +841,7 @@ begin return next rec1; end loop; end; -$function$; +$$; create view tt14v as select t.* from tt14f() as t; @@ -1188,23 +859,11 @@ delete from pg_depend where objid = ( - select - oid - from - pg_rewrite - where - ev_class = cast('tt14v' as regclass) and - rulename = '_RETURN' + select oid from pg_rewrite where ev_class = cast('tt14v' as regclass) and rulename = '_RETURN' ) and refobjsubid = 3 -returning pg_describe_object(classid, objid, objsubid) -as obj, -pg_describe_object( - refclassid, - refobjid, - refobjsubid -) -as ref, +returning pg_describe_object(classid, objid, objsubid) as obj, +pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype; alter table tt14t @@ -1229,23 +888,11 @@ delete from pg_depend where objid = ( - select - oid - from - pg_rewrite - where - ev_class = cast('tt14v' as regclass) and - rulename = '_RETURN' + select oid from pg_rewrite where ev_class = cast('tt14v' as regclass) and rulename = '_RETURN' ) and refobjsubid = 4 -returning pg_describe_object(classid, objid, objsubid) -as obj, -pg_describe_object( - refclassid, - refobjid, - refobjsubid -) -as ref, +returning pg_describe_object(classid, objid, objsubid) as obj, +pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype; alter table tt14t @@ -1280,10 +927,7 @@ select * from tt14v; create type nestedcomposite as (x int8_tbl); create view tt15v -as select - cast(row(i) as nestedcomposite) -from - int8_tbl as i; +as select cast(row(i) as nestedcomposite) from int8_tbl as i; select * from tt15v; @@ -1292,11 +936,7 @@ select pg_get_viewdef('tt15v', true); select cast(row(cast(i.* as int8_tbl)) as nestedcomposite) from int8_tbl as i; create view tt16v -as select - * -from - int8_tbl as i, - lateral (values (i)) as ss; +as select * from int8_tbl as i, lateral (values (i)) as ss; select * from tt16v; @@ -1305,12 +945,7 @@ select pg_get_viewdef('tt16v', true); select * from int8_tbl as i, lateral (values (cast(i.* as int8_tbl))) as ss; create view tt17v -as select - * -from - int8_tbl as i -where - i in (values (i)); +as select * from int8_tbl as i where i in (values (i)); select * from tt17v; @@ -1321,27 +956,18 @@ select * from int8_tbl as i where i.* in (values (cast(i.* as int8_tbl))); create table tt15v_log ( o tt15v, n tt15v, - incr boolean + incr bool ); create rule updlog as on update to tt15v do - insert into tt15v_log - values (old, new, row(old, old) < row(new, new));; + insert into tt15v_log values (old, new, row(old, old) < row(new, new));; create view tt18v -as select - * -from - int8_tbl - as xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +as select * from int8_tbl as xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx union all -select - * -from - int8_tbl - as xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; +select * from int8_tbl as xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; select pg_get_viewdef('tt18v', true); @@ -1352,19 +978,12 @@ select cast('foo' as text) = any (cast(array['abc', 'def', 'foo'] as text[])); select cast('foo' as text) = any (select cast(array['abc', 'def', 'foo'] as text[])); select - cast('foo' as text) = any (cast(( - select cast(array['abc', 'def', 'foo'] as text[]) - ) - as text[])); + cast('foo' as text) = any (cast((select cast(array['abc', 'def', 'foo'] as text[])) as text[])); create view tt19v as select - cast('foo' as text) = any (cast(array['abc', 'def', 'foo'] as text[])) - as c1, - cast('foo' as text) = any (cast(( - select cast(array['abc', 'def', 'foo'] as text[]) - ) - as text[])) + cast('foo' as text) = any (cast(array['abc', 'def', 'foo'] as text[])) as c1, + cast('foo' as text) = any (cast((select cast(array['abc', 'def', 'foo'] as text[])) as text[])) as c2; select pg_get_viewdef('tt19v', true); @@ -1374,58 +993,36 @@ as select * from coalesce(1, 2) as c, - pg_collation_for(cast('x' as text)) as col, + collation for (cast('x' as text)) as col, current_date as d, localtimestamp(3) as t, - cast(1 + 2 as int) as i4, - cast(1 + 2 as bigint) as i8; + cast(1 + 2 as int4) as i4, + cast(1 + 2 as int8) as i8; select pg_get_viewdef('tt20v', true); create view tt201v as select - timezone( - 'UTC', - cast('2022-12-01' as date) + - cast('1 day' as interval) - ) - as atz, - EXTRACT('day' from NOW()) as extr, - overlaps( - NOW(), - cast('1 day' as interval), - current_timestamp(2), - cast('1 day' as interval) - ) + ((cast('2022-12-01' as date) + cast('1 day' as interval)) at time zone 'UTC') as atz, + extract(day from now()) as extr, + ((now(), cast('1 day' as interval)) overlaps (current_timestamp(2), cast('1 day' as interval))) as o, - is_normalized('foo') as isn, - is_normalized('foo', 'NFKC') as isnn, - NORMALIZE('foo') as n, - NORMALIZE('foo', NFKD) as nfkd, - OVERLAY('foo' placing 'bar' from 2) as ovl, - OVERLAY('foo' placing 'bar' from 2 for 3) as ovl2, - POSITION('foo' in 'foobar') as p, - SUBSTRING('foo' from 2 for 3) as s, - SUBSTRING('foo' from 'f' for '#') as ss, - SUBSTRING('foo' from 'oo') as ssf, - btrim(' foo ', ' ') as bt, - ltrim(' foo ', ' ') as lt, - rtrim(' foo ') as rt, - btrim( - cast('\000Tom\000' as bytea), - cast('\000' as bytea) - ) - as btb, - ltrim( - cast('\000Tom\000' as bytea), - cast('\000' as bytea) - ) - as ltb, - rtrim( - cast('\000Tom\000' as bytea), - cast('\000' as bytea) - ) - as rtb, + ('foo' is normalized) as isn, + ('foo' is nfkc normalized) as isnn, + normalize('foo') as n, + normalize('foo', nfkd) as nfkd, + overlay('foo' placing 'bar' from 2) as ovl, + overlay('foo' placing 'bar' from 2 for 3) as ovl2, + position('foo' in 'foobar') as p, + substring('foo' from 2 for 3) as s, + substring('foo' from 'f' for '#') as ss, + substring('foo' from 'oo') as ssf, + trim(' ' from ' foo ') as bt, + trim(leading ' ' from ' foo ') as lt, + trim(trailing ' foo ') as rt, + trim(cast('\000' as bytea) from cast('\000Tom\000' as bytea)) as btb, + trim(leading cast('\000' as bytea) from cast('\000Tom\000' as bytea)) as ltb, + trim(trailing cast('\000' as bytea) from cast('\000Tom\000' as bytea)) as rtb, current_date as cd, (select * from current_date) as cd2, current_time as ct, @@ -1456,8 +1053,8 @@ as select (select * from user) as us2, session_user as seu, (select * from session_user) as seu2, - SYSTEM_USER as su, - (select * from SYSTEM_USER) as su2; + system_user as su, + (select * from system_user) as su2; select pg_get_viewdef('tt201v', true); @@ -1476,13 +1073,7 @@ create view tt23v col_a, col_b ) -as select - q1 as other_name1, - q2 as other_name2 -from - int8_tbl -union -select 42, 43; +as select q1 as other_name1, q2 as other_name2 from int8_tbl union select 42, 43; select pg_get_viewdef('tt23v', true); @@ -1491,8 +1082,7 @@ select from pg_rewrite where - ev_class = cast('tt23v' as regclass) and - ev_type = '1'; + ev_class = cast('tt23v' as regclass) and ev_type = '1'; select (r).column2 as col_a, @@ -1500,14 +1090,7 @@ select from cte inner join - ( - select - rr - from - (values (1, 7), (3, 8)) as rr - limit 2 - ) - as ss + (select rr from (values (1, 7), (3, 8)) as rr limit 2) as ss on (r).column1 = (rr).column1; select pg_get_viewdef('tt24v', true); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap index bbfdaf658..98d801fbd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap @@ -6,12 +6,10 @@ create function interpt_pp(path, path) returns point language c strict -as $function$ -regresslib -$function$; +as 'regresslib'; create table real_city ( - pop int, + pop int4, cname text, outline path ); @@ -37,8 +35,7 @@ create view iexit as select ih.name, ih.thepath, - interpt_pp(ih.thepath, r.thepath) - as exit + interpt_pp(ih.thepath, r.thepath) as exit from ihighway as ih, ramp as r @@ -46,13 +43,7 @@ where ih.thepath ?# r.thepath; create view toyemp -as select - name, - age, - location, - 12 * salary as annualsal -from - emp; +as select name, age, location, 12 * salary as annualsal from emp; comment on view noview is 'no view'; @@ -66,22 +57,13 @@ create table view_base_table ( ); create view key_dependent_view -as select - * -from - view_base_table -group by key; +as select * from view_base_table group by key; alter table view_base_table drop constraint view_base_table_pkey; create view key_dependent_view_no_cols -as select -from - view_base_table -group by key -having - length(data) > 0; +as select from view_base_table group by key having length(data) > 0; create table viewtest_tbl ( a int, @@ -99,16 +81,7 @@ as select * from viewtest_tbl where a > 10; select * from viewtest; create or replace view viewtest -as select - a, - b, - c, - d -from - viewtest_tbl -where - a > 5 -order by b desc; +as select a, b, c, d from viewtest_tbl where a > 5 order by b desc; select * from viewtest; @@ -119,47 +92,22 @@ create or replace view viewtest as select 1, * from viewtest_tbl; create or replace view viewtest -as select - a, - cast(b as numeric), - c, - d -from - viewtest_tbl; +as select a, cast(b as numeric), c, d from viewtest_tbl; create or replace view viewtest -as select - a, - b, - cast(c as numeric(10, 2)), - d -from - viewtest_tbl; +as select a, b, cast(c as numeric(10, 2)), d from viewtest_tbl; create or replace view viewtest -as select - a, - b, - c, - d collate "POSIX" -from - viewtest_tbl; +as select a, b, c, d collate "POSIX" from viewtest_tbl; create or replace view viewtest -as select - a, - b, - c, - d, - 0 as e -from - viewtest_tbl; +as select a, b, c, d, 0 as e from viewtest_tbl; drop view viewtest; drop table viewtest_tbl; -create schema "temp_view_test"; +create schema temp_view_test; create table base_table ( a int, @@ -193,7 +141,7 @@ as select * from base_table; create view temp_view_test.v3_temp as select * from temp_table; -create schema "test_view_schema"; +create schema test_view_schema; create temporary view testview as select 1; @@ -231,87 +179,37 @@ where t1.id = t2.id and t2.id = t3.id; create view v4 -as select - * -from - base_table -where - id in (select id from base_table2); +as select * from base_table where id in (select id from base_table2); create view v5 -as select - t1.id, - t2.a -from - base_table as t1, - (select * from base_table2) as t2; +as select t1.id, t2.a from base_table as t1, (select * from base_table2) as t2; create view v6 -as select - * -from - base_table -where - exists (select 1 from base_table2); +as select * from base_table where exists (select 1 from base_table2); create view v7 -as select - * -from - base_table -where - not exists (select 1 from base_table2); +as select * from base_table where not exists (select 1 from base_table2); create view v8 -as select - * -from - base_table -where - exists (select 1); +as select * from base_table where exists (select 1); create view v6_temp -as select - * -from - base_table -where - id in (select id from temp_table); +as select * from base_table where id in (select id from temp_table); create view v7_temp -as select - t1.id, - t2.a -from - base_table as t1, - (select * from temp_table) as t2; +as select t1.id, t2.a from base_table as t1, (select * from temp_table) as t2; create view v8_temp -as select - * -from - base_table -where - exists (select 1 from temp_table); +as select * from base_table where exists (select 1 from temp_table); create view v9_temp -as select - * -from - base_table -where - not exists (select 1 from temp_table); +as select * from base_table where not exists (select 1 from temp_table); create view v10_temp as select * from v7_temp; create view v11_temp -as select - t1.id, - t2.a -from - base_table as t1, - v10_temp as t2; +as select t1.id, t2.a from base_table as t1, v10_temp as t2; create view v12_temp as select true from v11_temp; @@ -324,10 +222,7 @@ create view v9 as select seq1.is_called from seq1; create view v13_temp -as select - seq1_temp.is_called -from - seq1_temp; +as select seq1_temp.is_called from seq1_temp; select relname @@ -335,15 +230,7 @@ from pg_class where relname like 'v_' and - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'temp_view_test' - ) + relnamespace = (select oid from pg_namespace where nspname = 'temp_view_test') order by relname; select @@ -352,18 +239,10 @@ from pg_class where relname like 'v%' and - relnamespace in - ( - select - oid - from - pg_namespace - where - nspname like 'pg_temp%' - ) + relnamespace in (select oid from pg_namespace where nspname like 'pg_temp%') order by relname; -create schema "testviewschm2"; +create schema testviewschm2; set search_path to testviewschm2, public; @@ -389,52 +268,22 @@ create view temporal1 as select * from t1 inner join tt on true; create view nontemp2 -as select - * -from - t1 inner join t2 on t1.num = t2.num2; +as select * from t1 inner join t2 on t1.num = t2.num2; create view temporal2 -as select - * -from - t1 inner join tt on t1.num = tt.num2; +as select * from t1 inner join tt on t1.num = tt.num2; create view nontemp3 -as select - * -from - t1 - left outer join - t2 - on t1.num = t2.num2; +as select * from t1 left outer join t2 on t1.num = t2.num2; create view temporal3 -as select - * -from - t1 - left outer join - tt - on t1.num = tt.num2; +as select * from t1 left outer join tt on t1.num = tt.num2; create view nontemp4 -as select - * -from - t1 - left outer join - t2 - on t1.num = t2.num2 and t2.value = 'xxx'; +as select * from t1 left outer join t2 on t1.num = t2.num2 and t2.value = 'xxx'; create view temporal4 -as select - * -from - t1 - left outer join - tt - on t1.num = tt.num2 and tt.value = 'xxx'; +as select * from t1 left outer join tt on t1.num = tt.num2 and tt.value = 'xxx'; select relname @@ -442,15 +291,7 @@ from pg_class where relname like 'nontemp%' and - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'testviewschm2' - ) + relnamespace = (select oid from pg_namespace where nspname = 'testviewschm2') order by relname; select @@ -459,15 +300,7 @@ from pg_class where relname like 'temporal%' and - relnamespace in - ( - select - oid - from - pg_namespace - where - nspname like 'pg_temp%' - ) + relnamespace in (select oid from pg_namespace where nspname like 'pg_temp%') order by relname; create table tbl1 ( @@ -504,31 +337,17 @@ where tbl1.a between (select d from tbl2 where c = 1) and (select e from tbl3 where f = 2) and - exists - ( - select - g - from - tbl4 - left outer join - tbl3 - on tbl4.h = tbl3.f - ); + exists (select g from tbl4 left outer join tbl3 on tbl4.h = tbl3.f); select - COUNT(*) + count(*) from pg_class where relname = 'pubview' and relnamespace in ( - select - oid - from - pg_namespace - where - nspname = 'testviewschm2' + select oid from pg_namespace where nspname = 'testviewschm2' ); create view mytempview @@ -540,42 +359,16 @@ where tbl1.a between (select d from tbl2 where c = 1) and (select e from tbl3 where f = 2) and - exists - ( - select - g - from - tbl4 - left outer join - tbl3 - on tbl4.h = tbl3.f - ) and - not exists - ( - select - g - from - tbl4 - left outer join - tmptbl - on tbl4.h = tmptbl.j - ); + exists (select g from tbl4 left outer join tbl3 on tbl4.h = tbl3.f) and + not exists (select g from tbl4 left outer join tmptbl on tbl4.h = tmptbl.j); select - COUNT(*) + count(*) from pg_class where relname like 'mytempview' and - relnamespace in - ( - select - oid - from - pg_namespace - where - nspname like 'pg_temp%' - ); + relnamespace in (select oid from pg_namespace where nspname like 'pg_temp%'); create view mysecview1 as select * from tbl1 where a = 0; @@ -605,8 +398,7 @@ create view mysecview7 as select * from tbl1 where a = 100; create view mysecview8 - with (security_invoker = 'false', - security_barrier = 'true') + with (security_invoker = 'false', security_barrier = 'true') as select * from tbl1 where a > 100; create view mysecview9 @@ -655,8 +447,7 @@ create or replace view mysecview8 as select * from tbl1 where a < 256; create or replace view mysecview9 - with (security_invoker = 'false', - security_barrier = 'true') + with (security_invoker = 'false', security_barrier = 'true') as select * from tbl1 where a <> 256; select @@ -691,12 +482,7 @@ as select from ( values - ( - cast('abc' as varchar(3)), - '0123456789', - 42, - cast('abcd' as varchar(4)) - ), + (cast('abc' as varchar(3)), '0123456789', 42, cast('abcd' as varchar(4))), ( '0123456789', cast('abc' as varchar(3)), @@ -731,15 +517,7 @@ create table temp_view_test.tt1 ( ); create view aliased_view_1 -as select - * -from - tt1 -where - exists - ( - select 1 from tx1 where tt1.f1 = tx1.x1 - ); +as select * from tt1 where exists (select 1 from tx1 where tt1.f1 = tx1.x1); create view aliased_view_2 as select @@ -747,10 +525,7 @@ as select from tt1 as a1 where - exists - ( - select 1 from tx1 where a1.f1 = tx1.x1 - ); + exists (select 1 from tx1 where a1.f1 = tx1.x1); create view aliased_view_3 as select @@ -758,15 +533,7 @@ as select from tt1 where - exists - ( - select - 1 - from - tx1 as a2 - where - tt1.f1 = a2.x1 - ); + exists (select 1 from tx1 as a2 where tt1.f1 = a2.x1); create view aliased_view_4 as select @@ -774,15 +541,7 @@ as select from temp_view_test.tt1 where - exists - ( - select - 1 - from - tt1 - where - temp_view_test.tt1.y1 = tt1.f1 - ); + exists (select 1 from tt1 where temp_view_test.tt1.y1 = tt1.f1); alter table tx1 rename to a1; @@ -801,13 +560,7 @@ alter table temp_view_test.tmp1 set schema testviewschm2; alter table tmp1 rename to tx1; create view aliased_order_by -as select - x1 as x2, - x2 as x1, - x3 -from - tt1 -order by x2; +as select x1 as x2, x2 as x1, x3 from tt1 order by x2; alter view aliased_order_by rename column x1 to x0; @@ -817,14 +570,8 @@ create view view_of_joins as select * from - ( - select - * - from - (tbl1 inner join tbl2 on true) as "same" - ) - as ss, - (tbl3 inner join tbl4 on true) as "same"; + (select * from (tbl1 inner join tbl2 on true) as same) as ss, + (tbl3 inner join tbl4 on true) as same; create table tbl1a ( a int, @@ -832,34 +579,16 @@ create table tbl1a ( ); create view view_of_joins_2a -as select - * -from - tbl1 inner join tbl1a using ("a"); +as select * from tbl1 inner join tbl1a using (a); create view view_of_joins_2b -as select - * -from - tbl1 inner join tbl1a using ("a") as "x"; +as select * from tbl1 inner join tbl1a using (a) as x; create view view_of_joins_2c -as select - * -from - (tbl1 - inner join - tbl1a - using ("a")) as "y"; +as select * from (tbl1 inner join tbl1a using (a)) as y; create view view_of_joins_2d -as select - * -from - (tbl1 - inner join - tbl1a - using ("a") as "x") as "y"; +as select * from (tbl1 inner join tbl1a using (a) as x) as y; select pg_get_viewdef('view_of_joins_2a', true); @@ -876,8 +605,8 @@ create table tt2 ( ); create table tt3 ( - ax bigint, - b smallint, + ax int8, + b int2, c numeric ); @@ -891,37 +620,19 @@ create view v1 as select * from tt2 natural join tt3; create view v1a -as select - * -from - (tt2 natural join tt3) as "j"; +as select * from (tt2 natural join tt3) as j; create view v2 -as select - * -from - tt2 inner join tt3 using ( "b", "c") - inner join - tt4 - using ("b"); +as select * from tt2 inner join tt3 using ( b, c) inner join tt4 using (b); create view v2a as select * from - (tt2 inner join tt3 using ( "b", "c") - inner join - tt4 - using ("b")) as "j"; + (tt2 inner join tt3 using ( b, c) inner join tt4 using (b)) as j; create view v3 -as select - * -from - tt2 inner join tt3 using ( "b", "c") - full outer join - tt4 - using ("b"); +as select * from tt2 inner join tt3 using ( b, c) full outer join tt4 using (b); select pg_get_viewdef('v1', true); @@ -1001,16 +712,7 @@ create table tt6 ( ); create view vv1 -as select - * -from - (tt5 - inner join - tt6 - on true) as "j" ("aa", - "bb", - "cc", - "dd"); +as select * from (tt5 inner join tt6 on true) as j (aa, bb, cc, dd); select pg_get_viewdef('vv1', true); @@ -1053,62 +755,34 @@ create table tt8 ( ); create view vv2 -as select - * -from - ( - values (1, 2, 3, 4, 5) - ) - as v (a, b, c, d, e) +as select * from (values (1, 2, 3, 4, 5)) as v (a, b, c, d, e) union all -select - * -from - tt7 full outer join tt8 using ("x"), - tt8 as tt8x; +select * from tt7 full outer join tt8 using (x), tt8 as tt8x; select pg_get_viewdef('vv2', true); create view vv3 -as select - * -from - ( - values (1, 2, 3, 4, 5, 6) - ) - as v (a, b, c, x, e, f) +as select * from (values (1, 2, 3, 4, 5, 6)) as v (a, b, c, x, e, f) union all select * from - tt7 full outer join tt8 using ("x"), - tt7 as tt7x - full outer join - tt8 as tt8x - using ("x"); + tt7 full outer join tt8 using (x), + tt7 as tt7x full outer join tt8 as tt8x using (x); select pg_get_viewdef('vv3', true); create view vv4 -as select - * -from - ( - values (1, 2, 3, 4, 5, 6, 7) - ) - as v (a, b, c, x, e, f, g) +as select * from (values (1, 2, 3, 4, 5, 6, 7)) as v (a, b, c, x, e, f, g) union all select * from - tt7 full outer join tt8 using ("x"), - tt7 as tt7x - full outer join - tt8 as tt8x - using ("x") + tt7 full outer join tt8 using (x), + tt7 as tt7x full outer join tt8 as tt8x using (x) full outer join tt8 as tt8y - using ("x"); + using (x); select pg_get_viewdef('vv4', true); @@ -1140,24 +814,14 @@ alter table tt7a drop column xx; create table tt8a ( - x timestamp with time zone, + x timestamptz, z int ); create view vv2a -as select - * -from - ( - values (NOW(), 2, 3, NOW(), 5) - ) - as v (a, b, c, d, e) +as select * from (values (now(), 2, 3, now(), 5)) as v (a, b, c, d, e) union all -select - * -from - tt7a left outer join tt8a using ("x"), - tt8a as tt8ax; +select * from tt7a left outer join tt8a using (x), tt8a as tt8ax; select pg_get_viewdef('vv2a', true); @@ -1173,12 +837,7 @@ create table tt10 ( ); create view vv5 -as select - x, - y, - z -from - tt9 inner join tt10 using ("x"); +as select x, y, z from tt9 inner join tt10 using (x); select pg_get_viewdef('vv5', true); @@ -1209,10 +868,7 @@ as select z, q from - tt11 inner join tt12 using ("x") - inner join - tt13 - using ("z"); + tt11 inner join tt12 using (x) inner join tt13 using (z); select pg_get_viewdef('vv6', true); @@ -1236,7 +892,7 @@ alter table tt14t create function tt14f() returns setof tt14t language plpgsql -as $function$ +as $$ declare rec1 record; begin @@ -1245,7 +901,7 @@ begin return next rec1; end loop; end; -$function$; +$$; create view tt14v as select t.* from tt14f() as t; @@ -1268,22 +924,11 @@ where from pg_rewrite where - ev_class = cast('tt14v' as regclass) and - rulename = '_RETURN' + ev_class = cast('tt14v' as regclass) and rulename = '_RETURN' ) and refobjsubid = 3 -returning pg_describe_object( - classid, - objid, - objsubid -) -as obj, -pg_describe_object( - refclassid, - refobjid, - refobjsubid -) -as ref, +returning pg_describe_object(classid, objid, objsubid) as obj, +pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype; alter table tt14t @@ -1313,22 +958,11 @@ where from pg_rewrite where - ev_class = cast('tt14v' as regclass) and - rulename = '_RETURN' + ev_class = cast('tt14v' as regclass) and rulename = '_RETURN' ) and refobjsubid = 4 -returning pg_describe_object( - classid, - objid, - objsubid -) -as obj, -pg_describe_object( - refclassid, - refobjid, - refobjsubid -) -as ref, +returning pg_describe_object(classid, objid, objsubid) as obj, +pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype; alter table tt14t @@ -1363,10 +997,7 @@ select * from tt14v; create type nestedcomposite as (x int8_tbl); create view tt15v -as select - cast(row(i) as nestedcomposite) -from - int8_tbl as i; +as select cast(row(i) as nestedcomposite) from int8_tbl as i; select * from tt15v; @@ -1375,11 +1006,7 @@ select pg_get_viewdef('tt15v', true); select cast(row(cast(i.* as int8_tbl)) as nestedcomposite) from int8_tbl as i; create view tt16v -as select - * -from - int8_tbl as i, - lateral (values (i)) as ss; +as select * from int8_tbl as i, lateral (values (i)) as ss; select * from tt16v; @@ -1388,12 +1015,7 @@ select pg_get_viewdef('tt16v', true); select * from int8_tbl as i, lateral (values (cast(i.* as int8_tbl))) as ss; create view tt17v -as select - * -from - int8_tbl as i -where - i in (values (i)); +as select * from int8_tbl as i where i in (values (i)); select * from tt17v; @@ -1404,30 +1026,24 @@ select * from int8_tbl as i where i.* in (values (cast(i.* as int8_tbl))); create table tt15v_log ( o tt15v, n tt15v, - incr boolean + incr bool ); create rule updlog as on update to tt15v do - insert into tt15v_log - values - ( - old, new, row(old, old) < row(new, new) - );; + insert into tt15v_log values (old, new, row(old, old) < row(new, new));; create view tt18v as select * from - int8_tbl - as xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + int8_tbl as xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx union all select * from - int8_tbl - as xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; + int8_tbl as xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; select pg_get_viewdef('tt18v', true); @@ -1436,30 +1052,19 @@ select * from tt18v; select cast('foo' as text) = any (cast(array['abc', 'def', 'foo'] as text[])); select - cast('foo' as text) = any - ( - select - cast(array['abc', 'def', 'foo'] - as text[]) - ); + cast('foo' as text) = any (select cast(array['abc', 'def', 'foo'] as text[])); select cast('foo' as text) = any (cast(( - select - cast(array['abc', 'def', 'foo'] - as text[]) + select cast(array['abc', 'def', 'foo'] as text[]) ) as text[])); create view tt19v as select - cast('foo' as text) = any (cast(array['abc', 'def', 'foo'] - as text[])) - as c1, + cast('foo' as text) = any (cast(array['abc', 'def', 'foo'] as text[])) as c1, cast('foo' as text) = any (cast(( - select - cast(array['abc', 'def', 'foo'] - as text[]) + select cast(array['abc', 'def', 'foo'] as text[]) ) as text[])) as c2; @@ -1471,61 +1076,38 @@ as select * from coalesce(1, 2) as c, - pg_collation_for(cast('x' as text)) - as col, + collation for (cast('x' as text)) as col, current_date as d, localtimestamp(3) as t, - cast(1 + 2 as int) as i4, - cast(1 + 2 as bigint) as i8; + cast(1 + 2 as int4) as i4, + cast(1 + 2 as int8) as i8; select pg_get_viewdef('tt20v', true); create view tt201v as select - timezone( - 'UTC', - cast('2022-12-01' as date) + - cast('1 day' as interval) - ) + ((cast('2022-12-01' as date) + cast('1 day' as interval)) at time zone 'UTC') as atz, - EXTRACT('day' from NOW()) as extr, - overlaps( - NOW(), - cast('1 day' as interval), - current_timestamp(2), - cast('1 day' as interval) - ) + extract(day from now()) as extr, + ((now(), cast('1 day' + as interval)) overlaps (current_timestamp(2), cast('1 day' as interval))) as o, - is_normalized('foo') as isn, - is_normalized('foo', 'NFKC') as isnn, - NORMALIZE('foo') as n, - NORMALIZE('foo', NFKD) as nfkd, - OVERLAY('foo' placing 'bar' from 2) - as ovl, - OVERLAY('foo' placing 'bar' from 2 for 3) - as ovl2, - POSITION('foo' in 'foobar') as p, - SUBSTRING('foo' from 2 for 3) as s, - SUBSTRING('foo' from 'f' for '#') as ss, - SUBSTRING('foo' from 'oo') as ssf, - btrim(' foo ', ' ') as bt, - ltrim(' foo ', ' ') as lt, - rtrim(' foo ') as rt, - btrim( - cast('\000Tom\000' as bytea), - cast('\000' as bytea) - ) - as btb, - ltrim( - cast('\000Tom\000' as bytea), - cast('\000' as bytea) - ) - as ltb, - rtrim( - cast('\000Tom\000' as bytea), - cast('\000' as bytea) - ) - as rtb, + ('foo' is normalized) as isn, + ('foo' is nfkc normalized) as isnn, + normalize('foo') as n, + normalize('foo', nfkd) as nfkd, + overlay('foo' placing 'bar' from 2) as ovl, + overlay('foo' placing 'bar' from 2 for 3) as ovl2, + position('foo' in 'foobar') as p, + substring('foo' from 2 for 3) as s, + substring('foo' from 'f' for '#') as ss, + substring('foo' from 'oo') as ssf, + trim(' ' from ' foo ') as bt, + trim(leading ' ' from ' foo ') as lt, + trim(trailing ' foo ') as rt, + trim(cast('\000' as bytea) from cast('\000Tom\000' as bytea)) as btb, + trim(leading cast('\000' as bytea) from cast('\000Tom\000' as bytea)) as ltb, + trim(trailing cast('\000' as bytea) from cast('\000Tom\000' as bytea)) as rtb, current_date as cd, (select * from current_date) as cd2, current_time as ct, @@ -1535,8 +1117,7 @@ as select current_timestamp as ct5, (select * from current_timestamp) as ct6, current_timestamp(1) as ct7, - (select * from current_timestamp(1)) - as ct8, + (select * from current_timestamp(1)) as ct8, localtime as lt1, (select * from localtime) as lt2, localtime(1) as lt3, @@ -1557,8 +1138,8 @@ as select (select * from user) as us2, session_user as seu, (select * from session_user) as seu2, - SYSTEM_USER as su, - (select * from SYSTEM_USER) as su2; + system_user as su, + (select * from system_user) as su2; select pg_get_viewdef('tt201v', true); @@ -1577,11 +1158,7 @@ create view tt23v col_a, col_b ) -as select - q1 as other_name1, - q2 as other_name2 -from - int8_tbl +as select q1 as other_name1, q2 as other_name2 from int8_tbl union select 42, 43; @@ -1592,8 +1169,7 @@ select from pg_rewrite where - ev_class = cast('tt23v' as regclass) and - ev_type = '1'; + ev_class = cast('tt23v' as regclass) and ev_type = '1'; select (r).column2 as col_a, @@ -1601,14 +1177,7 @@ select from cte inner join - ( - select - rr - from - (values (1, 7), (3, 8)) as rr - limit 2 - ) - as ss + (select rr from (values (1, 7), (3, 8)) as rr limit 2) as ss on (r).column1 = (rr).column1; select pg_get_viewdef('tt24v', true); @@ -1622,14 +1191,7 @@ select * from tt24v; select (r).column2 from - ( - select - r - from - (values (1, 2), (3, 4)) as r - limit 1 - ) - as ss; + (select r from (values (1, 2), (3, 4)) as r limit 1) as ss; create view tt26v as select @@ -1642,10 +1204,8 @@ as select x + (y # z) as c7, x > y and (y > z or x > z) as c8, x > y or (y > z and not x > z) as c9, - (x, y) <> all (values (1, 2), (3, 4)) - as c10, - (x, y) <= any (values (1, 2), (3, 4)) - as c11 + (x, y) <> all (values (1, 2), (3, 4)) as c10, + (x, y) <= any (values (1, 2), (3, 4)) as c11 from (values (1, 2, 3)) as v (x, y, z); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__database_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__database_100.snap index 13bc61409..7cf24a913 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__database_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__database_100.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/database.sql snapshot_kind: text --- -create database "regression_tbd" with encoding = 'utf8' +create database regression_tbd with encoding = 'utf8' lc_collate = 'C' lc_ctype = 'C' template = 'template0'; @@ -19,10 +19,7 @@ alter database regression_utf8 connection_limit = 123; begin; update pg_database -set datacl = array_fill( - makeaclitem(10, 10, 'USAGE', false), - array[cast(5e5 as int)] -) +set datacl = array_fill(makeaclitem(10, 10, 'USAGE', false), array[cast(5e5 as int)]) where datname = 'regression_utf8'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__database_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__database_80.snap index 13bc61409..f8fd533f5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__database_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__database_80.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/database.sql snapshot_kind: text --- -create database "regression_tbd" with encoding = 'utf8' +create database regression_tbd with encoding = 'utf8' lc_collate = 'C' lc_ctype = 'C' template = 'template0'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__date_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__date_100.snap index 82c31ae4f..45de1117d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__date_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__date_100.snap @@ -372,107 +372,107 @@ select from date_tbl; -select EXTRACT('epoch' from cast('1970-01-01' as date)); +select extract(epoch from cast('1970-01-01' as date)); -select EXTRACT('century' from cast('0101-12-31 BC' as date)); +select extract(century from cast('0101-12-31 BC' as date)); -select EXTRACT('century' from cast('0100-12-31 BC' as date)); +select extract(century from cast('0100-12-31 BC' as date)); -select EXTRACT('century' from cast('0001-12-31 BC' as date)); +select extract(century from cast('0001-12-31 BC' as date)); -select EXTRACT('century' from cast('0001-01-01' as date)); +select extract(century from cast('0001-01-01' as date)); -select EXTRACT('century' from cast('0001-01-01 AD' as date)); +select extract(century from cast('0001-01-01 AD' as date)); -select EXTRACT('century' from cast('1900-12-31' as date)); +select extract(century from cast('1900-12-31' as date)); -select EXTRACT('century' from cast('1901-01-01' as date)); +select extract(century from cast('1901-01-01' as date)); -select EXTRACT('century' from cast('2000-12-31' as date)); +select extract(century from cast('2000-12-31' as date)); -select EXTRACT('century' from cast('2001-01-01' as date)); +select extract(century from cast('2001-01-01' as date)); -select EXTRACT('century' from current_date) >= 21 as "true"; +select extract(century from current_date) >= 21 as "true"; -select EXTRACT('millennium' from cast('0001-12-31 BC' as date)); +select extract(millennium from cast('0001-12-31 BC' as date)); -select EXTRACT('millennium' from cast('0001-01-01 AD' as date)); +select extract(millennium from cast('0001-01-01 AD' as date)); -select EXTRACT('millennium' from cast('1000-12-31' as date)); +select extract(millennium from cast('1000-12-31' as date)); -select EXTRACT('millennium' from cast('1001-01-01' as date)); +select extract(millennium from cast('1001-01-01' as date)); -select EXTRACT('millennium' from cast('2000-12-31' as date)); +select extract(millennium from cast('2000-12-31' as date)); -select EXTRACT('millennium' from cast('2001-01-01' as date)); +select extract(millennium from cast('2001-01-01' as date)); -select EXTRACT('millennium' from current_date); +select extract(millennium from current_date); -select EXTRACT('decade' from cast('1994-12-25' as date)); +select extract(decade from cast('1994-12-25' as date)); -select EXTRACT('decade' from cast('0010-01-01' as date)); +select extract(decade from cast('0010-01-01' as date)); -select EXTRACT('decade' from cast('0009-12-31' as date)); +select extract(decade from cast('0009-12-31' as date)); -select EXTRACT('decade' from cast('0001-01-01 BC' as date)); +select extract(decade from cast('0001-01-01 BC' as date)); -select EXTRACT('decade' from cast('0002-12-31 BC' as date)); +select extract(decade from cast('0002-12-31 BC' as date)); -select EXTRACT('decade' from cast('0011-01-01 BC' as date)); +select extract(decade from cast('0011-01-01 BC' as date)); -select EXTRACT('decade' from cast('0012-12-31 BC' as date)); +select extract(decade from cast('0012-12-31 BC' as date)); -select EXTRACT('microseconds' from cast('2020-08-11' as date)); +select extract(microseconds from cast('2020-08-11' as date)); -select EXTRACT('milliseconds' from cast('2020-08-11' as date)); +select extract(milliseconds from cast('2020-08-11' as date)); -select EXTRACT('second' from cast('2020-08-11' as date)); +select extract(second from cast('2020-08-11' as date)); -select EXTRACT('minute' from cast('2020-08-11' as date)); +select extract(minute from cast('2020-08-11' as date)); -select EXTRACT('hour' from cast('2020-08-11' as date)); +select extract(hour from cast('2020-08-11' as date)); -select EXTRACT('day' from cast('2020-08-11' as date)); +select extract(day from cast('2020-08-11' as date)); -select EXTRACT('month' from cast('2020-08-11' as date)); +select extract(month from cast('2020-08-11' as date)); -select EXTRACT('year' from cast('2020-08-11' as date)); +select extract(year from cast('2020-08-11' as date)); -select EXTRACT('year' from cast('2020-08-11 BC' as date)); +select extract(year from cast('2020-08-11 BC' as date)); -select EXTRACT('decade' from cast('2020-08-11' as date)); +select extract(decade from cast('2020-08-11' as date)); -select EXTRACT('century' from cast('2020-08-11' as date)); +select extract(century from cast('2020-08-11' as date)); -select EXTRACT('millennium' from cast('2020-08-11' as date)); +select extract(millennium from cast('2020-08-11' as date)); -select EXTRACT('isoyear' from cast('2020-08-11' as date)); +select extract(isoyear from cast('2020-08-11' as date)); -select EXTRACT('isoyear' from cast('2020-08-11 BC' as date)); +select extract(isoyear from cast('2020-08-11 BC' as date)); -select EXTRACT('quarter' from cast('2020-08-11' as date)); +select extract(quarter from cast('2020-08-11' as date)); -select EXTRACT('week' from cast('2020-08-11' as date)); +select extract(week from cast('2020-08-11' as date)); -select EXTRACT('dow' from cast('2020-08-11' as date)); +select extract(dow from cast('2020-08-11' as date)); -select EXTRACT('dow' from cast('2020-08-16' as date)); +select extract(dow from cast('2020-08-16' as date)); -select EXTRACT('isodow' from cast('2020-08-11' as date)); +select extract(isodow from cast('2020-08-11' as date)); -select EXTRACT('isodow' from cast('2020-08-16' as date)); +select extract(isodow from cast('2020-08-16' as date)); -select EXTRACT('doy' from cast('2020-08-11' as date)); +select extract(doy from cast('2020-08-11' as date)); -select EXTRACT('timezone' from cast('2020-08-11' as date)); +select extract(timezone from cast('2020-08-11' as date)); -select EXTRACT('timezone_m' from cast('2020-08-11' as date)); +select extract(timezone_m from cast('2020-08-11' as date)); -select EXTRACT('timezone_h' from cast('2020-08-11' as date)); +select extract(timezone_h from cast('2020-08-11' as date)); -select EXTRACT('epoch' from cast('2020-08-11' as date)); +select extract(epoch from cast('2020-08-11' as date)); -select EXTRACT('julian' from cast('2020-08-11' as date)); +select extract(julian from cast('2020-08-11' as date)); select date_trunc('MILLENNIUM', cast('1970-03-20 04:30:00.00000' as timestamp)); @@ -507,43 +507,43 @@ select select cast('infinity' as date) = cast('+infinity' as date) as t; -select EXTRACT('day' from cast('infinity' as date)); +select extract(day from cast('infinity' as date)); -select EXTRACT('day' from cast('-infinity' as date)); +select extract(day from cast('-infinity' as date)); -select EXTRACT('day' from cast('infinity' as date)); +select extract(day from cast('infinity' as date)); -select EXTRACT('month' from cast('infinity' as date)); +select extract(month from cast('infinity' as date)); -select EXTRACT('quarter' from cast('infinity' as date)); +select extract(quarter from cast('infinity' as date)); -select EXTRACT('week' from cast('infinity' as date)); +select extract(week from cast('infinity' as date)); -select EXTRACT('dow' from cast('infinity' as date)); +select extract(dow from cast('infinity' as date)); -select EXTRACT('isodow' from cast('infinity' as date)); +select extract(isodow from cast('infinity' as date)); -select EXTRACT('doy' from cast('infinity' as date)); +select extract(doy from cast('infinity' as date)); -select EXTRACT('epoch' from cast('infinity' as date)); +select extract(epoch from cast('infinity' as date)); -select EXTRACT('epoch' from cast('-infinity' as date)); +select extract(epoch from cast('-infinity' as date)); -select EXTRACT('year' from cast('infinity' as date)); +select extract(year from cast('infinity' as date)); -select EXTRACT('decade' from cast('infinity' as date)); +select extract(decade from cast('infinity' as date)); -select EXTRACT('century' from cast('infinity' as date)); +select extract(century from cast('infinity' as date)); -select EXTRACT('millennium' from cast('infinity' as date)); +select extract(millennium from cast('infinity' as date)); -select EXTRACT('julian' from cast('infinity' as date)); +select extract(julian from cast('infinity' as date)); -select EXTRACT('isoyear' from cast('infinity' as date)); +select extract(isoyear from cast('infinity' as date)); -select EXTRACT('epoch' from cast('infinity' as date)); +select extract(epoch from cast('infinity' as date)); -select EXTRACT('microsec' from cast('infinity' as date)); +select extract(microsec from cast('infinity' as date)); select make_date(2013, 7, 15); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__date_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__date_80.snap index 6fe64e00b..45de1117d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__date_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__date_80.snap @@ -361,8 +361,7 @@ select date_part('quarter', f1) as quarter, date_part('decade', f1) as decade, date_part('century', f1) as century, - date_part('millennium', f1) - as millennium, + date_part('millennium', f1) as millennium, date_part('isoyear', f1) as isoyear, date_part('week', f1) as week, date_part('dow', f1) as dow, @@ -373,107 +372,107 @@ select from date_tbl; -select EXTRACT('epoch' from cast('1970-01-01' as date)); +select extract(epoch from cast('1970-01-01' as date)); -select EXTRACT('century' from cast('0101-12-31 BC' as date)); +select extract(century from cast('0101-12-31 BC' as date)); -select EXTRACT('century' from cast('0100-12-31 BC' as date)); +select extract(century from cast('0100-12-31 BC' as date)); -select EXTRACT('century' from cast('0001-12-31 BC' as date)); +select extract(century from cast('0001-12-31 BC' as date)); -select EXTRACT('century' from cast('0001-01-01' as date)); +select extract(century from cast('0001-01-01' as date)); -select EXTRACT('century' from cast('0001-01-01 AD' as date)); +select extract(century from cast('0001-01-01 AD' as date)); -select EXTRACT('century' from cast('1900-12-31' as date)); +select extract(century from cast('1900-12-31' as date)); -select EXTRACT('century' from cast('1901-01-01' as date)); +select extract(century from cast('1901-01-01' as date)); -select EXTRACT('century' from cast('2000-12-31' as date)); +select extract(century from cast('2000-12-31' as date)); -select EXTRACT('century' from cast('2001-01-01' as date)); +select extract(century from cast('2001-01-01' as date)); -select EXTRACT('century' from current_date) >= 21 as "true"; +select extract(century from current_date) >= 21 as "true"; -select EXTRACT('millennium' from cast('0001-12-31 BC' as date)); +select extract(millennium from cast('0001-12-31 BC' as date)); -select EXTRACT('millennium' from cast('0001-01-01 AD' as date)); +select extract(millennium from cast('0001-01-01 AD' as date)); -select EXTRACT('millennium' from cast('1000-12-31' as date)); +select extract(millennium from cast('1000-12-31' as date)); -select EXTRACT('millennium' from cast('1001-01-01' as date)); +select extract(millennium from cast('1001-01-01' as date)); -select EXTRACT('millennium' from cast('2000-12-31' as date)); +select extract(millennium from cast('2000-12-31' as date)); -select EXTRACT('millennium' from cast('2001-01-01' as date)); +select extract(millennium from cast('2001-01-01' as date)); -select EXTRACT('millennium' from current_date); +select extract(millennium from current_date); -select EXTRACT('decade' from cast('1994-12-25' as date)); +select extract(decade from cast('1994-12-25' as date)); -select EXTRACT('decade' from cast('0010-01-01' as date)); +select extract(decade from cast('0010-01-01' as date)); -select EXTRACT('decade' from cast('0009-12-31' as date)); +select extract(decade from cast('0009-12-31' as date)); -select EXTRACT('decade' from cast('0001-01-01 BC' as date)); +select extract(decade from cast('0001-01-01 BC' as date)); -select EXTRACT('decade' from cast('0002-12-31 BC' as date)); +select extract(decade from cast('0002-12-31 BC' as date)); -select EXTRACT('decade' from cast('0011-01-01 BC' as date)); +select extract(decade from cast('0011-01-01 BC' as date)); -select EXTRACT('decade' from cast('0012-12-31 BC' as date)); +select extract(decade from cast('0012-12-31 BC' as date)); -select EXTRACT('microseconds' from cast('2020-08-11' as date)); +select extract(microseconds from cast('2020-08-11' as date)); -select EXTRACT('milliseconds' from cast('2020-08-11' as date)); +select extract(milliseconds from cast('2020-08-11' as date)); -select EXTRACT('second' from cast('2020-08-11' as date)); +select extract(second from cast('2020-08-11' as date)); -select EXTRACT('minute' from cast('2020-08-11' as date)); +select extract(minute from cast('2020-08-11' as date)); -select EXTRACT('hour' from cast('2020-08-11' as date)); +select extract(hour from cast('2020-08-11' as date)); -select EXTRACT('day' from cast('2020-08-11' as date)); +select extract(day from cast('2020-08-11' as date)); -select EXTRACT('month' from cast('2020-08-11' as date)); +select extract(month from cast('2020-08-11' as date)); -select EXTRACT('year' from cast('2020-08-11' as date)); +select extract(year from cast('2020-08-11' as date)); -select EXTRACT('year' from cast('2020-08-11 BC' as date)); +select extract(year from cast('2020-08-11 BC' as date)); -select EXTRACT('decade' from cast('2020-08-11' as date)); +select extract(decade from cast('2020-08-11' as date)); -select EXTRACT('century' from cast('2020-08-11' as date)); +select extract(century from cast('2020-08-11' as date)); -select EXTRACT('millennium' from cast('2020-08-11' as date)); +select extract(millennium from cast('2020-08-11' as date)); -select EXTRACT('isoyear' from cast('2020-08-11' as date)); +select extract(isoyear from cast('2020-08-11' as date)); -select EXTRACT('isoyear' from cast('2020-08-11 BC' as date)); +select extract(isoyear from cast('2020-08-11 BC' as date)); -select EXTRACT('quarter' from cast('2020-08-11' as date)); +select extract(quarter from cast('2020-08-11' as date)); -select EXTRACT('week' from cast('2020-08-11' as date)); +select extract(week from cast('2020-08-11' as date)); -select EXTRACT('dow' from cast('2020-08-11' as date)); +select extract(dow from cast('2020-08-11' as date)); -select EXTRACT('dow' from cast('2020-08-16' as date)); +select extract(dow from cast('2020-08-16' as date)); -select EXTRACT('isodow' from cast('2020-08-11' as date)); +select extract(isodow from cast('2020-08-11' as date)); -select EXTRACT('isodow' from cast('2020-08-16' as date)); +select extract(isodow from cast('2020-08-16' as date)); -select EXTRACT('doy' from cast('2020-08-11' as date)); +select extract(doy from cast('2020-08-11' as date)); -select EXTRACT('timezone' from cast('2020-08-11' as date)); +select extract(timezone from cast('2020-08-11' as date)); -select EXTRACT('timezone_m' from cast('2020-08-11' as date)); +select extract(timezone_m from cast('2020-08-11' as date)); -select EXTRACT('timezone_h' from cast('2020-08-11' as date)); +select extract(timezone_h from cast('2020-08-11' as date)); -select EXTRACT('epoch' from cast('2020-08-11' as date)); +select extract(epoch from cast('2020-08-11' as date)); -select EXTRACT('julian' from cast('2020-08-11' as date)); +select extract(julian from cast('2020-08-11' as date)); select date_trunc('MILLENNIUM', cast('1970-03-20 04:30:00.00000' as timestamp)); @@ -508,43 +507,43 @@ select select cast('infinity' as date) = cast('+infinity' as date) as t; -select EXTRACT('day' from cast('infinity' as date)); +select extract(day from cast('infinity' as date)); -select EXTRACT('day' from cast('-infinity' as date)); +select extract(day from cast('-infinity' as date)); -select EXTRACT('day' from cast('infinity' as date)); +select extract(day from cast('infinity' as date)); -select EXTRACT('month' from cast('infinity' as date)); +select extract(month from cast('infinity' as date)); -select EXTRACT('quarter' from cast('infinity' as date)); +select extract(quarter from cast('infinity' as date)); -select EXTRACT('week' from cast('infinity' as date)); +select extract(week from cast('infinity' as date)); -select EXTRACT('dow' from cast('infinity' as date)); +select extract(dow from cast('infinity' as date)); -select EXTRACT('isodow' from cast('infinity' as date)); +select extract(isodow from cast('infinity' as date)); -select EXTRACT('doy' from cast('infinity' as date)); +select extract(doy from cast('infinity' as date)); -select EXTRACT('epoch' from cast('infinity' as date)); +select extract(epoch from cast('infinity' as date)); -select EXTRACT('epoch' from cast('-infinity' as date)); +select extract(epoch from cast('-infinity' as date)); -select EXTRACT('year' from cast('infinity' as date)); +select extract(year from cast('infinity' as date)); -select EXTRACT('decade' from cast('infinity' as date)); +select extract(decade from cast('infinity' as date)); -select EXTRACT('century' from cast('infinity' as date)); +select extract(century from cast('infinity' as date)); -select EXTRACT('millennium' from cast('infinity' as date)); +select extract(millennium from cast('infinity' as date)); -select EXTRACT('julian' from cast('infinity' as date)); +select extract(julian from cast('infinity' as date)); -select EXTRACT('isoyear' from cast('infinity' as date)); +select extract(isoyear from cast('infinity' as date)); -select EXTRACT('epoch' from cast('infinity' as date)); +select extract(epoch from cast('infinity' as date)); -select EXTRACT('microsec' from cast('infinity' as date)); +select extract(microsec from cast('infinity' as date)); select make_date(2013, 7, 15); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__dbsize_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__dbsize_100.snap index 01e95dd88..ca8eabc36 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__dbsize_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__dbsize_100.snap @@ -84,12 +84,8 @@ from as x (size); select - pg_size_pretty( - cast('-9223372036854775808' as bigint) - ), - pg_size_pretty( - cast('9223372036854775807' as bigint) - ); + pg_size_pretty(cast('-9223372036854775808' as bigint)), + pg_size_pretty(cast('9223372036854775807' as bigint)); select size, @@ -154,15 +150,7 @@ select pg_size_bytes(size) from ( - values - ('-1.'), - ('-1.kb'), - ('-1. kb'), - ('-0. gb'), - ('-.1'), - ('-.1kb'), - ('-.1 kb'), - ('-.0 gb') + values ('-1.'), ('-1.kb'), ('-1. kb'), ('-0. gb'), ('-.1'), ('-.1kb'), ('-.1 kb'), ('-.0 gb') ) as x (size); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__dbsize_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__dbsize_80.snap index 01e95dd88..03ca552f9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__dbsize_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__dbsize_80.snap @@ -84,12 +84,8 @@ from as x (size); select - pg_size_pretty( - cast('-9223372036854775808' as bigint) - ), - pg_size_pretty( - cast('9223372036854775807' as bigint) - ); + pg_size_pretty(cast('-9223372036854775808' as bigint)), + pg_size_pretty(cast('9223372036854775807' as bigint)); select size, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__dependency_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__dependency_100.snap index 3ceb592c3..1f9c38dcc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__dependency_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__dependency_100.snap @@ -15,7 +15,7 @@ create table deptest ( f2 text ); -grant SELECT on table deptest to regress_dep_group; +grant select on table deptest to regress_dep_group; grant all on table deptest to regress_dep_user, regress_dep_user2; @@ -23,23 +23,23 @@ drop role regress_dep_user; drop role regress_dep_group; -revoke SELECT on table deptest from regress_dep_group; +revoke select on table deptest from regress_dep_group; drop role regress_dep_group; -revoke SELECT, -INSERT, -UPDATE, -DELETE, -TRUNCATE, -REFERENCES, -MAINTAIN +revoke select, +insert, +update, +delete, +truncate, +references, +maintain on table deptest from regress_dep_user; drop role regress_dep_user; -revoke TRIGGER on table deptest from regress_dep_user; +revoke trigger on table deptest from regress_dep_user; drop role regress_dep_user; @@ -93,11 +93,11 @@ drop owned by regress_dep_user1; grant all on table deptest1 to regress_dep_user1; -grant CREATE on database regression to regress_dep_user1; +grant create on database regression to regress_dep_user1; set session authorization regress_dep_user1; -create schema "deptest"; +create schema deptest; create table deptest ( a serial primary key, @@ -112,13 +112,11 @@ grant all on tables to regress_dep_user2; create function deptest_func() returns void language plpgsql -as $function$ -BEGIN END; -$function$; +as $$ BEGIN END; $$; create type deptest_enum as enum ('red'); -create type deptest_range as range (subtype = int); +create type deptest_range as range (subtype = int4); create table deptest2 (f1 int); @@ -134,10 +132,7 @@ create type deptest_t as (a int); select typowner = relowner from - pg_type - inner join - pg_class as c - on typrelid = c.oid + pg_type inner join pg_class as c on typrelid = c.oid where typname = 'deptest_t'; @@ -148,10 +143,7 @@ reassign owned by regress_dep_user1 to regress_dep_user2; select typowner = relowner from - pg_type - inner join - pg_class as c - on typrelid = c.oid + pg_type inner join pg_class as c on typrelid = c.oid where typname = 'deptest_t'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__dependency_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__dependency_80.snap index 3ef9861b1..1f9c38dcc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__dependency_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__dependency_80.snap @@ -15,7 +15,7 @@ create table deptest ( f2 text ); -grant SELECT on table deptest to regress_dep_group; +grant select on table deptest to regress_dep_group; grant all on table deptest to regress_dep_user, regress_dep_user2; @@ -23,23 +23,23 @@ drop role regress_dep_user; drop role regress_dep_group; -revoke SELECT on table deptest from regress_dep_group; +revoke select on table deptest from regress_dep_group; drop role regress_dep_group; -revoke SELECT, -INSERT, -UPDATE, -DELETE, -TRUNCATE, -REFERENCES, -MAINTAIN +revoke select, +insert, +update, +delete, +truncate, +references, +maintain on table deptest from regress_dep_user; drop role regress_dep_user; -revoke TRIGGER on table deptest from regress_dep_user; +revoke trigger on table deptest from regress_dep_user; drop role regress_dep_user; @@ -93,11 +93,11 @@ drop owned by regress_dep_user1; grant all on table deptest1 to regress_dep_user1; -grant CREATE on database regression to regress_dep_user1; +grant create on database regression to regress_dep_user1; set session authorization regress_dep_user1; -create schema "deptest"; +create schema deptest; create table deptest ( a serial primary key, @@ -107,20 +107,16 @@ create table deptest ( alter default privileges for role regress_dep_user1 in schema deptest -grant all -on tables -to regress_dep_user2; +grant all on tables to regress_dep_user2; create function deptest_func() returns void language plpgsql -as $function$ -BEGIN END; -$function$; +as $$ BEGIN END; $$; create type deptest_enum as enum ('red'); -create type deptest_range as range (subtype = int); +create type deptest_range as range (subtype = int4); create table deptest2 (f1 int); @@ -136,10 +132,7 @@ create type deptest_t as (a int); select typowner = relowner from - pg_type - inner join - pg_class as c - on typrelid = c.oid + pg_type inner join pg_class as c on typrelid = c.oid where typname = 'deptest_t'; @@ -150,10 +143,7 @@ reassign owned by regress_dep_user1 to regress_dep_user2; select typowner = relowner from - pg_type - inner join - pg_class as c - on typrelid = c.oid + pg_type inner join pg_class as c on typrelid = c.oid where typname = 'deptest_t'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_100.snap index 214fb3907..4e8bcabaf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/domain.sql --- -create domain domaindroptest as int; +create domain domaindroptest as int4; comment on domain domaindroptest is 'About to drop this..'; @@ -16,33 +16,33 @@ drop domain domaindroptest cascade; create domain d_fail as no_such_type; -create domain d_fail as int constraint "cc" references this_table_not_exists (i); +create domain d_fail as int constraint cc references this_table_not_exists (i); -create domain d_fail as int not null null; +create domain d_fail as int4 not null null; -create domain d_fail as int not null default 3 default 3; +create domain d_fail as int4 not null default 3 default 3; -create domain d_fail as int default (3 + 'h'); +create domain d_fail as int4 default (3 + 'h'); -create domain d_fail as int collate "C"; +create domain d_fail as int4 collate "C"; create domain d_fail as anyelement; -create domain d_fail as int unique; +create domain d_fail as int4 unique; -create domain d_fail as int primary key; +create domain d_fail as int4 primary key; -create domain d_fail as int constraint "cc" generated by default as identity; +create domain d_fail as int4 constraint cc generated by default as identity; -create domain d_fail as int constraint "cc" check (values > 1) no inherit; +create domain d_fail as int4 constraint cc check (values > 1) no inherit; -create domain d_fail as int constraint "cc" check (values > 1) deferrable; +create domain d_fail as int4 constraint cc check (values > 1) deferrable; create domain domainvarchar as varchar(5); create domain domainnumeric as numeric(8, 2); -create domain domainint4 as int; +create domain domainint4 as int4; create domain domaintext as text; @@ -81,9 +81,9 @@ drop domain domainint4; drop domain domaintext; -create domain positiveint as int check (value > 0); +create domain positiveint as int4 check (value > 0); -create domain weirdfloat as double precision check (1 / value < 10); +create domain weirdfloat as float8 check (1 / value < 10); select pg_input_is_valid('1', 'positiveint'); @@ -105,7 +105,7 @@ drop domain positiveint; drop domain weirdfloat; -create domain domainint4arr as int[1]; +create domain domainint4arr as int4[1]; create domain domainchar4arr as varchar(4)[2][3]; @@ -162,7 +162,7 @@ select pg_typeof(cast('{1,2,3}' as dia) || 42); drop domain dia; -create type comptype as (r double precision, i double precision); +create type comptype as (r float8, i float8); create domain dcomptype as comptype; @@ -184,9 +184,9 @@ update dcomptable set d1."r" = (d1).r + 1 where (d1).i > 0; select * from dcomptable; -alter domain dcomptype add constraint "c1" check ((value).r <= (value).i); +alter domain dcomptype add constraint c1 check ((value).r <= (value).i); -alter domain dcomptype add constraint "c2" check ((value).r > (value).i); +alter domain dcomptype add constraint c2 check ((value).r > (value).i); select cast(row(2, 1) as dcomptype); @@ -211,18 +211,12 @@ update dcomptable set d1."r" = (d1).r - 1, d1."i" = (d1).i + 1 where (d1).i > 0; create rule silly as on delete to dcomptable do instead - update dcomptable - set d1."r" = (d1).r - 1, - d1."i" = (d1).i + 1 - where - (d1).i > 0;; + update dcomptable set d1."r" = (d1).r - 1, d1."i" = (d1).i + 1 where (d1).i > 0;; -create function makedcomp(r double precision, i double precision) +create function makedcomp(r float8, i float8) returns dcomptype language sql -as $function$ -select row(r, i) -$function$; +as 'select row(r, i)'; select makedcomp(1, 2); @@ -232,17 +226,17 @@ select * from makedcomp(1, 2) as m; select m, m is not null from makedcomp(1, 2) as m; -drop function makedcomp(double precision, double precision); +drop function makedcomp(float8, float8); drop table dcomptable; drop type comptype cascade; -create type comptype as (r double precision, i double precision); +create type comptype as (r float8, i float8); create domain dcomptype as comptype; -alter domain dcomptype add constraint "c1" check ((value).r > 0); +alter domain dcomptype add constraint c1 check ((value).r > 0); comment on constraint c1 on domain dcomptype is 'random commentary'; @@ -270,7 +264,7 @@ where drop type comptype cascade; -create type comptype as (r double precision, i double precision); +create type comptype as (r float8, i float8); create domain dcomptypea as comptype[]; @@ -300,9 +294,9 @@ update dcomptable set d1[1]."r" = d1[1].r + 1 where d1[1].i > 0; select * from dcomptable; -alter domain dcomptypea add constraint "c1" check (value[1].r <= value[1].i); +alter domain dcomptypea add constraint c1 check (value[1].r <= value[1].i); -alter domain dcomptypea add constraint "c2" check (value[1].r > value[1].i); +alter domain dcomptypea add constraint c2 check (value[1].r > value[1].i); select cast(array[row(2, 1)] as dcomptypea); @@ -327,11 +321,7 @@ update dcomptable set d1[1]."r" = d1[1].r - 1, d1[1]."i" = d1[1].i + 1 where d1[ create rule silly as on delete to dcomptable do instead - update dcomptable - set d1[1]."r" = d1[1].r - 1, - d1[1]."i" = d1[1].i + 1 - where - d1[1].i > 0;; + update dcomptable set d1[1]."r" = d1[1].r - 1, d1[1]."i" = d1[1].i + 1 where d1[1].i > 0;; drop table dcomptable; @@ -475,7 +465,7 @@ drop domain dnull; drop domain dcheck; -create domain ddef1 as int default 3; +create domain ddef1 as int4 default 3; create domain ddef2 as oid default '12'; @@ -483,7 +473,7 @@ create domain ddef3 as text default 5; create sequence ddef4_seq; -create domain ddef4 as int default nextval('ddef4_seq'); +create domain ddef4 as int4 default nextval('ddef4_seq'); create domain ddef5 as numeric(8, 2) not null default '12.12'; @@ -548,7 +538,7 @@ update domnotnull set col1 = null; update domnotnull set col1 = 5; -alter domain dnotnulltest add constraint "dnotnulltest_notnull" not null; +alter domain dnotnulltest add constraint dnotnulltest_notnull not null; update domnotnull set col1 = null; @@ -594,9 +584,9 @@ insert into domcontest values (1); insert into domcontest values (2); -alter domain con add constraint "t" check (value < 1); +alter domain con add constraint t check (value < 1); -alter domain con add constraint "t" check (value < 34); +alter domain con add constraint t check (value < 34); alter domain con add check (value > 0); @@ -633,13 +623,13 @@ alter domain connotnull add not null; update domconnotnulltest set col2 = 6; -alter domain connotnull add constraint "constr1" not null; +alter domain connotnull add constraint constr1 not null; -select COUNT(*) from pg_constraint where contypid = cast('connotnull' as regtype) and contype = 'n'; +select count(*) from pg_constraint where contypid = cast('connotnull' as regtype) and contype = 'n'; -alter domain connotnull add constraint "constr1bis" not null; +alter domain connotnull add constraint constr1bis not null; -select COUNT(*) from pg_constraint where contypid = cast('connotnull' as regtype) and contype = 'n'; +select count(*) from pg_constraint where contypid = cast('connotnull' as regtype) and contype = 'n'; update domconnotnulltest set col1 = null; @@ -657,9 +647,9 @@ create table thethings (stuff things); insert into thethings (stuff) values (55); -alter domain things add constraint "meow" check (value < 11); +alter domain things add constraint meow check (value < 11); -alter domain things add constraint "meow" check (value < 11) not valid; +alter domain things add constraint meow check (value < 11) not valid; alter domain things validate constraint meow; @@ -688,7 +678,7 @@ alter domain dom drop not null; select * from domview; -alter domain dom add constraint "domchkgt6" check (value > 6); +alter domain dom add constraint domchkgt6 check (value > 6); select * from domview; @@ -710,9 +700,9 @@ drop sequence ddef4_seq; create domain vchar4 as varchar(4); -create domain dinter as vchar4 check (SUBSTRING(value from 1 for 1) = 'x'); +create domain dinter as vchar4 check (substring(value, 1, 1) = 'x'); -create domain dtop as dinter check (SUBSTRING(value from 2 for 1) = '1'); +create domain dtop as dinter check (substring(value, 2, 1) = '1'); select cast('x123' as dtop); @@ -758,14 +748,14 @@ insert into domain_test values (1, 2); alter table domain_test add column c str_domain; -create domain int_domain1 as int constraint "nn1" not null constraint "nn2" not null; +create domain int_domain1 as int constraint nn1 not null constraint nn2 not null; create domain str_domain2 as text check (value <> 'foo') default 'foo'; alter table domain_test add column d str_domain2; -create domain pos_int as int check (value > 0) not null; +create domain pos_int as int4 check (value > 0) not null; prepare s1 as select cast($1 as pos_int) = 10 as is_ten;; @@ -778,37 +768,34 @@ execute s1 (null); create function doubledecrement(p1 pos_int) returns pos_int language plpgsql -as $function$ +as $$ declare v pos_int; begin return p1; -end -$function$; +end$$; select doubledecrement(3); create or replace function doubledecrement(p1 pos_int) returns pos_int language plpgsql -as $function$ +as $$ declare v pos_int := 0; begin return p1; -end -$function$; +end$$; select doubledecrement(3); create or replace function doubledecrement(p1 pos_int) returns pos_int language plpgsql -as $function$ +as $$ declare v pos_int := 1; begin v := p1 - 1; return v - 1; -end -$function$; +end$$; select doubledecrement(null); @@ -820,7 +807,7 @@ select doubledecrement(2); select doubledecrement(3); -create domain posint as int; +create domain posint as int4; create type ddtest1 as (f1 posint); @@ -828,7 +815,7 @@ create table ddtest2 (f1 ddtest1); insert into ddtest2 values (row(-1)); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; @@ -836,7 +823,7 @@ create table ddtest2 (f1 ddtest1[]); insert into ddtest2 values ('{(-1)}'); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; @@ -846,7 +833,7 @@ create table ddtest2 (f1 ddtest1d); insert into ddtest2 values ('(-1)'); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; @@ -858,7 +845,7 @@ create table ddtest2 (f1 ddtest1d); insert into ddtest2 values ('{(-1)}'); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; @@ -870,13 +857,13 @@ create table ddtest2 (f1 rposint); insert into ddtest2 values ('(-1,3]'); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; drop type rposint; -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); create domain posint2 as posint check (value % 2 = 0); @@ -888,9 +875,9 @@ insert into ddtest2 values (-2); insert into ddtest2 values (2); -alter domain posint add constraint "c2" check (value >= 10); +alter domain posint add constraint c2 check (value >= 10); -alter domain posint add constraint "c2" check (value > 0); +alter domain posint add constraint c2 check (value > 0); drop table ddtest2; @@ -901,14 +888,13 @@ drop domain posint cascade; create or replace function array_elem_check(numeric) returns numeric language plpgsql -as $function$ +as $$ declare x numeric(4,2)[1]; begin x[1] := $1; return x[1]; -end -$function$; +end$$; select array_elem_check(121.00); @@ -919,14 +905,13 @@ create domain mynums as numeric(4, 2)[1]; create or replace function array_elem_check(numeric) returns numeric language plpgsql -as $function$ +as $$ declare x mynums; begin x[1] := $1; return x[1]; -end -$function$; +end$$; select array_elem_check(121.00); @@ -937,14 +922,13 @@ create domain mynums2 as mynums; create or replace function array_elem_check(numeric) returns numeric language plpgsql -as $function$ +as $$ declare x mynums2; begin x[1] := $1; return x[1]; -end -$function$; +end$$; select array_elem_check(121.00); @@ -973,14 +957,13 @@ select * from op; create or replace function array_elem_check(int) returns int language plpgsql -as $function$ +as $$ declare x orderedpair := '{1,2}'; begin x[2] := $1; return x[2]; -end -$function$; +end$$; select array_elem_check(3); @@ -994,17 +977,17 @@ create function dom_check(int) returns di language plpgsql immutable -as $function$ +as $$ declare d di; begin d := $1::di; return d; end -$function$; +$$; select dom_check(0); -alter domain di add constraint "pos" check (value > 0); +alter domain di add constraint pos check (value > 0); select dom_check(0); @@ -1016,17 +999,17 @@ create or replace function dom_check(int) returns di language plpgsql immutable -as $function$ +as $$ declare d di; begin d := $1; return d; end -$function$; +$$; select dom_check(0); -alter domain di add constraint "pos" check (value > 0); +alter domain di add constraint pos check (value > 0); select dom_check(0); @@ -1041,9 +1024,7 @@ drop domain di; create function sql_is_distinct_from(anyelement, anyelement) returns boolean language sql -as $function$ -select $1 is distinct from $2 limit 1 -$function$; +as 'select $1 is distinct from $2 limit 1'; create domain inotnull as int check (sql_is_distinct_from(value, null)); @@ -1073,7 +1054,7 @@ alter type testdomain2 rename to testdomain3; drop domain testdomain3; -create domain testdomain1 as int constraint "unsigned" check (value > 0); +create domain testdomain1 as int constraint unsigned check (value > 0); alter domain testdomain1 rename constraint unsigned to unsigned_foo; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_80.snap index 9bd5ac007..7cedf4bcf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/domain.sql --- -create domain domaindroptest as int; +create domain domaindroptest as int4; comment on domain domaindroptest is 'About to drop this..'; @@ -16,35 +16,33 @@ drop domain domaindroptest cascade; create domain d_fail as no_such_type; -create domain d_fail as int - constraint "cc" - references this_table_not_exists (i); +create domain d_fail as int constraint cc references this_table_not_exists (i); -create domain d_fail as int not null null; +create domain d_fail as int4 not null null; -create domain d_fail as int not null default 3 default 3; +create domain d_fail as int4 not null default 3 default 3; -create domain d_fail as int default (3 + 'h'); +create domain d_fail as int4 default (3 + 'h'); -create domain d_fail as int collate "C"; +create domain d_fail as int4 collate "C"; create domain d_fail as anyelement; -create domain d_fail as int unique; +create domain d_fail as int4 unique; -create domain d_fail as int primary key; +create domain d_fail as int4 primary key; -create domain d_fail as int constraint "cc" generated by default as identity; +create domain d_fail as int4 constraint cc generated by default as identity; -create domain d_fail as int constraint "cc" check (values > 1) no inherit; +create domain d_fail as int4 constraint cc check (values > 1) no inherit; -create domain d_fail as int constraint "cc" check (values > 1) deferrable; +create domain d_fail as int4 constraint cc check (values > 1) deferrable; create domain domainvarchar as varchar(5); create domain domainnumeric as numeric(8, 2); -create domain domainint4 as int; +create domain domainint4 as int4; create domain domaintext as text; @@ -87,9 +85,9 @@ drop domain domainint4; drop domain domaintext; -create domain positiveint as int check (value > 0); +create domain positiveint as int4 check (value > 0); -create domain weirdfloat as double precision check (1 / value < 10); +create domain weirdfloat as float8 check (1 / value < 10); select pg_input_is_valid('1', 'positiveint'); @@ -111,7 +109,7 @@ drop domain positiveint; drop domain weirdfloat; -create domain domainint4arr as int[1]; +create domain domainint4arr as int4[1]; create domain domainchar4arr as varchar(4)[2][3]; @@ -168,7 +166,7 @@ select pg_typeof(cast('{1,2,3}' as dia) || 42); drop domain dia; -create type comptype as (r double precision, i double precision); +create type comptype as (r float8, i float8); create domain dcomptype as comptype; @@ -190,9 +188,9 @@ update dcomptable set d1."r" = (d1).r + 1 where (d1).i > 0; select * from dcomptable; -alter domain dcomptype add constraint "c1" check ((value).r <= (value).i); +alter domain dcomptype add constraint c1 check ((value).r <= (value).i); -alter domain dcomptype add constraint "c2" check ((value).r > (value).i); +alter domain dcomptype add constraint c2 check ((value).r > (value).i); select cast(row(2, 1) as dcomptype); @@ -223,12 +221,10 @@ do instead where (d1).i > 0;; -create function makedcomp(r double precision, i double precision) +create function makedcomp(r float8, i float8) returns dcomptype language sql -as $function$ -select row(r, i) -$function$; +as 'select row(r, i)'; select makedcomp(1, 2); @@ -238,17 +234,17 @@ select * from makedcomp(1, 2) as m; select m, m is not null from makedcomp(1, 2) as m; -drop function makedcomp(double precision, double precision); +drop function makedcomp(float8, float8); drop table dcomptable; drop type comptype cascade; -create type comptype as (r double precision, i double precision); +create type comptype as (r float8, i float8); create domain dcomptype as comptype; -alter domain dcomptype add constraint "c1" check ((value).r > 0); +alter domain dcomptype add constraint c1 check ((value).r > 0); comment on constraint c1 on domain dcomptype is 'random commentary'; @@ -276,7 +272,7 @@ where drop type comptype cascade; -create type comptype as (r double precision, i double precision); +create type comptype as (r float8, i float8); create domain dcomptypea as comptype[]; @@ -287,11 +283,7 @@ insert into dcomptable values (cast(array[row(1, 2)] as dcomptypea)); insert into dcomptable values (cast(array[row(3, 4), row(5, 6)] as comptype[])); insert into dcomptable -values - ( - array[cast(row(7, 8) as comptype), - cast(row(9, 10) as comptype)] - ); +values (array[cast(row(7, 8) as comptype), cast(row(9, 10) as comptype)]); insert into dcomptable values (cast(array[row(1, 2)] as dcomptypea)); @@ -311,9 +303,9 @@ update dcomptable set d1[1]."r" = d1[1].r + 1 where d1[1].i > 0; select * from dcomptable; -alter domain dcomptypea add constraint "c1" check (value[1].r <= value[1].i); +alter domain dcomptypea add constraint c1 check (value[1].r <= value[1].i); -alter domain dcomptypea add constraint "c2" check (value[1].r > value[1].i); +alter domain dcomptypea add constraint c2 check (value[1].r > value[1].i); select cast(array[row(2, 1)] as dcomptypea); @@ -452,9 +444,7 @@ create domain dnull as varchar(15); create domain dcheck as varchar(15) not null - check (value = 'a' or - value = 'c' or - value = 'd'); + check (value = 'a' or value = 'c' or value = 'd'); create table nulltest ( col1 dnotnull, @@ -498,7 +488,7 @@ drop domain dnull; drop domain dcheck; -create domain ddef1 as int default 3; +create domain ddef1 as int4 default 3; create domain ddef2 as oid default '12'; @@ -506,7 +496,7 @@ create domain ddef3 as text default 5; create sequence ddef4_seq; -create domain ddef4 as int default nextval('ddef4_seq'); +create domain ddef4 as int4 default nextval('ddef4_seq'); create domain ddef5 as numeric(8, 2) not null default '12.12'; @@ -571,7 +561,7 @@ update domnotnull set col1 = null; update domnotnull set col1 = 5; -alter domain dnotnulltest add constraint "dnotnulltest_notnull" not null; +alter domain dnotnulltest add constraint dnotnulltest_notnull not null; update domnotnull set col1 = null; @@ -581,8 +571,7 @@ select from pg_constraint where - contypid = - cast('dnotnulltest' as regtype); + contypid = cast('dnotnulltest' as regtype); alter domain dnotnulltest drop constraint dnotnulltest_notnull; @@ -618,9 +607,9 @@ insert into domcontest values (1); insert into domcontest values (2); -alter domain con add constraint "t" check (value < 1); +alter domain con add constraint t check (value < 1); -alter domain con add constraint "t" check (value < 34); +alter domain con add constraint t check (value < 34); alter domain con add check (value > 0); @@ -657,25 +646,23 @@ alter domain connotnull add not null; update domconnotnulltest set col2 = 6; -alter domain connotnull add constraint "constr1" not null; +alter domain connotnull add constraint constr1 not null; select - COUNT(*) + count(*) from pg_constraint where - contypid = cast('connotnull' as regtype) and - contype = 'n'; + contypid = cast('connotnull' as regtype) and contype = 'n'; -alter domain connotnull add constraint "constr1bis" not null; +alter domain connotnull add constraint constr1bis not null; select - COUNT(*) + count(*) from pg_constraint where - contypid = cast('connotnull' as regtype) and - contype = 'n'; + contypid = cast('connotnull' as regtype) and contype = 'n'; update domconnotnulltest set col1 = null; @@ -693,9 +680,9 @@ create table thethings (stuff things); insert into thethings (stuff) values (55); -alter domain things add constraint "meow" check (value < 11); +alter domain things add constraint meow check (value < 11); -alter domain things add constraint "meow" check (value < 11) not valid; +alter domain things add constraint meow check (value < 11) not valid; alter domain things validate constraint meow; @@ -724,7 +711,7 @@ alter domain dom drop not null; select * from domview; -alter domain dom add constraint "domchkgt6" check (value > 6); +alter domain dom add constraint domchkgt6 check (value > 6); select * from domview; @@ -746,9 +733,9 @@ drop sequence ddef4_seq; create domain vchar4 as varchar(4); -create domain dinter as vchar4 check (SUBSTRING(value from 1 for 1) = 'x'); +create domain dinter as vchar4 check (substring(value, 1, 1) = 'x'); -create domain dtop as dinter check (SUBSTRING(value from 2 for 1) = '1'); +create domain dtop as dinter check (substring(value, 2, 1) = '1'); select cast('x123' as dtop); @@ -795,15 +782,15 @@ alter table domain_test add column c str_domain; create domain int_domain1 as int - constraint "nn1" not null - constraint "nn2" not null; + constraint nn1 not null + constraint nn2 not null; create domain str_domain2 as text check (value <> 'foo') default 'foo'; alter table domain_test add column d str_domain2; -create domain pos_int as int check (value > 0) not null; +create domain pos_int as int4 check (value > 0) not null; prepare s1 as select cast($1 as pos_int) = 10 as is_ten;; @@ -816,37 +803,34 @@ execute s1 (null); create function doubledecrement(p1 pos_int) returns pos_int language plpgsql -as $function$ +as $$ declare v pos_int; begin return p1; -end -$function$; +end$$; select doubledecrement(3); create or replace function doubledecrement(p1 pos_int) returns pos_int language plpgsql -as $function$ +as $$ declare v pos_int := 0; begin return p1; -end -$function$; +end$$; select doubledecrement(3); create or replace function doubledecrement(p1 pos_int) returns pos_int language plpgsql -as $function$ +as $$ declare v pos_int := 1; begin v := p1 - 1; return v - 1; -end -$function$; +end$$; select doubledecrement(null); @@ -858,7 +842,7 @@ select doubledecrement(2); select doubledecrement(3); -create domain posint as int; +create domain posint as int4; create type ddtest1 as (f1 posint); @@ -866,7 +850,7 @@ create table ddtest2 (f1 ddtest1); insert into ddtest2 values (row(-1)); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; @@ -874,7 +858,7 @@ create table ddtest2 (f1 ddtest1[]); insert into ddtest2 values ('{(-1)}'); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; @@ -884,7 +868,7 @@ create table ddtest2 (f1 ddtest1d); insert into ddtest2 values ('(-1)'); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; @@ -896,7 +880,7 @@ create table ddtest2 (f1 ddtest1d); insert into ddtest2 values ('{(-1)}'); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; @@ -908,13 +892,13 @@ create table ddtest2 (f1 rposint); insert into ddtest2 values ('(-1,3]'); -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); drop table ddtest2; drop type rposint; -alter domain posint add constraint "c1" check (value >= 0); +alter domain posint add constraint c1 check (value >= 0); create domain posint2 as posint check (value % 2 = 0); @@ -926,9 +910,9 @@ insert into ddtest2 values (-2); insert into ddtest2 values (2); -alter domain posint add constraint "c2" check (value >= 10); +alter domain posint add constraint c2 check (value >= 10); -alter domain posint add constraint "c2" check (value > 0); +alter domain posint add constraint c2 check (value > 0); drop table ddtest2; @@ -939,14 +923,13 @@ drop domain posint cascade; create or replace function array_elem_check(numeric) returns numeric language plpgsql -as $function$ +as $$ declare x numeric(4,2)[1]; begin x[1] := $1; return x[1]; -end -$function$; +end$$; select array_elem_check(121.00); @@ -957,14 +940,13 @@ create domain mynums as numeric(4, 2)[1]; create or replace function array_elem_check(numeric) returns numeric language plpgsql -as $function$ +as $$ declare x mynums; begin x[1] := $1; return x[1]; -end -$function$; +end$$; select array_elem_check(121.00); @@ -975,14 +957,13 @@ create domain mynums2 as mynums; create or replace function array_elem_check(numeric) returns numeric language plpgsql -as $function$ +as $$ declare x mynums2; begin x[1] := $1; return x[1]; -end -$function$; +end$$; select array_elem_check(121.00); @@ -1011,14 +992,13 @@ select * from op; create or replace function array_elem_check(int) returns int language plpgsql -as $function$ +as $$ declare x orderedpair := '{1,2}'; begin x[2] := $1; return x[2]; -end -$function$; +end$$; select array_elem_check(3); @@ -1032,17 +1012,17 @@ create function dom_check(int) returns di language plpgsql immutable -as $function$ +as $$ declare d di; begin d := $1::di; return d; end -$function$; +$$; select dom_check(0); -alter domain di add constraint "pos" check (value > 0); +alter domain di add constraint pos check (value > 0); select dom_check(0); @@ -1054,17 +1034,17 @@ create or replace function dom_check(int) returns di language plpgsql immutable -as $function$ +as $$ declare d di; begin d := $1; return d; end -$function$; +$$; select dom_check(0); -alter domain di add constraint "pos" check (value > 0); +alter domain di add constraint pos check (value > 0); select dom_check(0); @@ -1079,9 +1059,7 @@ drop domain di; create function sql_is_distinct_from(anyelement, anyelement) returns boolean language sql -as $function$ -select $1 is distinct from $2 limit 1 -$function$; +as 'select $1 is distinct from $2 limit 1'; create domain inotnull as int check (sql_is_distinct_from(value, null)); @@ -1111,7 +1089,7 @@ alter type testdomain2 rename to testdomain3; drop domain testdomain3; -create domain testdomain1 as int constraint "unsigned" check (value > 0); +create domain testdomain1 as int constraint unsigned check (value > 0); alter domain testdomain1 rename constraint unsigned to unsigned_foo; @@ -1140,10 +1118,7 @@ select from information_schema.column_domain_usage where - domain_name - in ( - 'con', 'dom', 'pos_int', 'things' - ) + domain_name in ('con', 'dom', 'pos_int', 'things') order by domain_name; select @@ -1151,10 +1126,7 @@ select from information_schema.domain_constraints where - domain_name - in ( - 'con', 'dom', 'pos_int', 'things' - ) + domain_name in ('con', 'dom', 'pos_int', 'things') order by constraint_name; select @@ -1162,10 +1134,7 @@ select from information_schema.domains where - domain_name - in ( - 'con', 'dom', 'pos_int', 'things' - ) + domain_name in ('con', 'dom', 'pos_int', 'things') order by domain_name; select @@ -1181,9 +1150,6 @@ where from information_schema.domain_constraints where - domain_name - in ( - 'con', 'dom', 'pos_int', 'things' - ) + domain_name in ('con', 'dom', 'pos_int', 'things') ) order by constraint_name; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_if_exists_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_if_exists_100.snap index 6f633f4f9..788415cb4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_if_exists_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_if_exists_100.snap @@ -26,7 +26,7 @@ drop index test_index_exists; drop index if exists test_index_exists; -create index "test_index_exists" on test_exists using btree (a); +create index test_index_exists on test_exists using btree (a); drop index if exists test_index_exists; @@ -46,7 +46,7 @@ drop schema test_schema_exists; drop schema if exists test_schema_exists; -create schema "test_schema_exists"; +create schema test_schema_exists; drop schema if exists test_schema_exists; @@ -158,9 +158,9 @@ drop operator @#@ (int, int); drop operator if exists @#@ (int, int); -create operator @#@ (LEFTARG = bigint, RIGHTARG = bigint, PROCEDURE = int8xor); +create operator @#@ (leftarg = int8, rightarg = int8, procedure = int8xor); -drop operator @#@ (bigint, bigint); +drop operator @#@ (int8, int8); drop language test_language_exists; @@ -205,8 +205,7 @@ drop rule if exists test_rule_exists on no_such_schema.no_such_table; create rule test_rule_exists as on insert to test_exists do instead - insert into test_exists - values (new.a, new.b || cast(new.a as text));; + insert into test_exists values (new.a, new.b || cast(new.a as text));; drop rule test_rule_exists on test_exists; @@ -309,16 +308,12 @@ drop view if exists no_such_schema.foo; create function test_ambiguous_funcname(int) returns int language sql -as $function$ -select $1; -$function$; +as $$ select $1; $$; create function test_ambiguous_funcname(text) returns text language sql -as $function$ -select $1; -$function$; +as $$ select $1; $$; drop function test_ambiguous_funcname; @@ -330,15 +325,11 @@ drop function test_ambiguous_funcname(text); create procedure test_ambiguous_procname(int) language plpgsql -as $procedure$ -begin end; -$procedure$; +as $$ begin end; $$; create procedure test_ambiguous_procname(text) language plpgsql -as $procedure$ -begin end; -$procedure$; +as $$ begin end; $$; drop procedure test_ambiguous_procname; @@ -350,10 +341,10 @@ drop procedure test_ambiguous_procname(int); drop procedure test_ambiguous_procname(text); -drop database test_database_exists (FORCE); +drop database test_database_exists (force); drop database test_database_exists; -drop database if exists test_database_exists (FORCE); +drop database if exists test_database_exists (force); drop database if exists test_database_exists; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_if_exists_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_if_exists_80.snap index aa73e931f..783f4feee 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_if_exists_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_if_exists_80.snap @@ -26,7 +26,7 @@ drop index test_index_exists; drop index if exists test_index_exists; -create index "test_index_exists" on test_exists using btree (a); +create index test_index_exists on test_exists using btree (a); drop index if exists test_index_exists; @@ -46,7 +46,7 @@ drop schema test_schema_exists; drop schema if exists test_schema_exists; -create schema "test_schema_exists"; +create schema test_schema_exists; drop schema if exists test_schema_exists; @@ -160,9 +160,9 @@ drop operator @#@ (int, int); drop operator if exists @#@ (int, int); -create operator @#@ (LEFTARG = bigint, RIGHTARG = bigint, PROCEDURE = int8xor); +create operator @#@ (leftarg = int8, rightarg = int8, procedure = int8xor); -drop operator @#@ (bigint, bigint); +drop operator @#@ (int8, int8); drop language test_language_exists; @@ -207,9 +207,7 @@ drop rule if exists test_rule_exists on no_such_schema.no_such_table; create rule test_rule_exists as on insert to test_exists do instead - insert into test_exists - values - (new.a, new.b || cast(new.a as text));; + insert into test_exists values (new.a, new.b || cast(new.a as text));; drop rule test_rule_exists on test_exists; @@ -282,9 +280,7 @@ drop operator if exists no_such_schema.+ (int, int); drop operator if exists + (no_such_type, no_such_type); drop operator if exists - + ( - no_such_schema.no_such_type, - no_such_schema.no_such_type); + + (no_such_schema.no_such_type, no_such_schema.no_such_type); drop operator if exists # (none, no_such_schema.no_such_type); @@ -315,16 +311,12 @@ drop view if exists no_such_schema.foo; create function test_ambiguous_funcname(int) returns int language sql -as $function$ -select $1; -$function$; +as $$ select $1; $$; create function test_ambiguous_funcname(text) returns text language sql -as $function$ -select $1; -$function$; +as $$ select $1; $$; drop function test_ambiguous_funcname; @@ -336,15 +328,11 @@ drop function test_ambiguous_funcname(text); create procedure test_ambiguous_procname(int) language plpgsql -as $procedure$ -begin end; -$procedure$; +as $$ begin end; $$; create procedure test_ambiguous_procname(text) language plpgsql -as $procedure$ -begin end; -$procedure$; +as $$ begin end; $$; drop procedure test_ambiguous_procname; @@ -356,10 +344,10 @@ drop procedure test_ambiguous_procname(int); drop procedure test_ambiguous_procname(text); -drop database test_database_exists (FORCE); +drop database test_database_exists (force); drop database test_database_exists; -drop database if exists test_database_exists (FORCE); +drop database if exists test_database_exists (force); drop database if exists test_database_exists; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_operator_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_operator_100.snap index aa0dfb49d..19d7b8a3e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_operator_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_operator_100.snap @@ -3,13 +3,15 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/drop_operator.sql snapshot_kind: text --- -create operator === (PROCEDURE = int8eq, LEFTARG = bigint, RIGHTARG = bigint, COMMUTATOR = ===); +create operator === (procedure = int8eq, leftarg = bigint, rightarg = bigint, commutator = ===); -create operator !== (PROCEDURE = int8ne, -LEFTARG = bigint, -RIGHTARG = bigint, -NEGATOR = ===, -COMMUTATOR = !==); +create operator !== ( + procedure = int8ne, + leftarg = bigint, + rightarg = bigint, + negator = ===, + commutator = !== +); drop operator !== (bigint, bigint); @@ -19,16 +21,7 @@ select from pg_catalog.pg_operator as fk where - oprcom <> 0 and - not exists - ( - select - 1 - from - pg_catalog.pg_operator as pk - where - pk.oid = fk.oprcom - ); + oprcom <> 0 and not exists (select 1 from pg_catalog.pg_operator as pk where pk.oid = fk.oprcom); select ctid, @@ -37,25 +30,19 @@ from pg_catalog.pg_operator as fk where oprnegate <> 0 and - not exists - ( - select - 1 - from - pg_catalog.pg_operator as pk - where - pk.oid = fk.oprnegate - ); + not exists (select 1 from pg_catalog.pg_operator as pk where pk.oid = fk.oprnegate); drop operator === (bigint, bigint); -create operator <| (PROCEDURE = int8lt, LEFTARG = bigint, RIGHTARG = bigint); +create operator <| (procedure = int8lt, leftarg = bigint, rightarg = bigint); -create operator |> (PROCEDURE = int8gt, -LEFTARG = bigint, -RIGHTARG = bigint, -NEGATOR = <|, -COMMUTATOR = <|); +create operator |> ( + procedure = int8gt, + leftarg = bigint, + rightarg = bigint, + negator = <|, + commutator = <| +); drop operator |> (bigint, bigint); @@ -65,16 +52,7 @@ select from pg_catalog.pg_operator as fk where - oprcom <> 0 and - not exists - ( - select - 1 - from - pg_catalog.pg_operator as pk - where - pk.oid = fk.oprcom - ); + oprcom <> 0 and not exists (select 1 from pg_catalog.pg_operator as pk where pk.oid = fk.oprcom); select ctid, @@ -83,14 +61,6 @@ from pg_catalog.pg_operator as fk where oprnegate <> 0 and - not exists - ( - select - 1 - from - pg_catalog.pg_operator as pk - where - pk.oid = fk.oprnegate - ); + not exists (select 1 from pg_catalog.pg_operator as pk where pk.oid = fk.oprnegate); drop operator <| (bigint, bigint); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_operator_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_operator_80.snap index 53381e57c..ce60c55fa 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_operator_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__drop_operator_80.snap @@ -3,16 +3,20 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/drop_operator.sql snapshot_kind: text --- -create operator === (PROCEDURE = int8eq, -LEFTARG = bigint, -RIGHTARG = bigint, -COMMUTATOR = ===); +create operator === ( + procedure = int8eq, + leftarg = bigint, + rightarg = bigint, + commutator = === +); -create operator !== (PROCEDURE = int8ne, -LEFTARG = bigint, -RIGHTARG = bigint, -NEGATOR = ===, -COMMUTATOR = !==); +create operator !== ( + procedure = int8ne, + leftarg = bigint, + rightarg = bigint, + negator = ===, + commutator = !== +); drop operator !== (bigint, bigint); @@ -25,12 +29,7 @@ where oprcom <> 0 and not exists ( - select - 1 - from - pg_catalog.pg_operator as pk - where - pk.oid = fk.oprcom + select 1 from pg_catalog.pg_operator as pk where pk.oid = fk.oprcom ); select @@ -42,23 +41,20 @@ where oprnegate <> 0 and not exists ( - select - 1 - from - pg_catalog.pg_operator as pk - where - pk.oid = fk.oprnegate + select 1 from pg_catalog.pg_operator as pk where pk.oid = fk.oprnegate ); drop operator === (bigint, bigint); -create operator <| (PROCEDURE = int8lt, LEFTARG = bigint, RIGHTARG = bigint); +create operator <| (procedure = int8lt, leftarg = bigint, rightarg = bigint); -create operator |> (PROCEDURE = int8gt, -LEFTARG = bigint, -RIGHTARG = bigint, -NEGATOR = <|, -COMMUTATOR = <|); +create operator |> ( + procedure = int8gt, + leftarg = bigint, + rightarg = bigint, + negator = <|, + commutator = <| +); drop operator |> (bigint, bigint); @@ -71,12 +67,7 @@ where oprcom <> 0 and not exists ( - select - 1 - from - pg_catalog.pg_operator as pk - where - pk.oid = fk.oprcom + select 1 from pg_catalog.pg_operator as pk where pk.oid = fk.oprcom ); select @@ -88,12 +79,7 @@ where oprnegate <> 0 and not exists ( - select - 1 - from - pg_catalog.pg_operator as pk - where - pk.oid = fk.oprnegate + select 1 from pg_catalog.pg_operator as pk where pk.oid = fk.oprnegate ); drop operator <| (bigint, bigint); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__enum_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__enum_100.snap index dd71eba28..74f4060d4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__enum_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__enum_100.snap @@ -4,7 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/enum.sql --- create type rainbow as enum ('red', 'orange', 'yellow', 'green', 'blue', 'purple'); -select COUNT(*) from pg_enum where enumtypid = cast('rainbow' as regtype); +select count(*) from pg_enum where enumtypid = cast('rainbow' as regtype); select cast('red' as rainbow); @@ -147,11 +147,7 @@ alter type insenum add value 'i30' before 'L2'; select enumlabel, - case - when enumsortorder > 20 then null - else enumsortorder - end - as so + case when enumsortorder > 20 then null else enumsortorder end as so from pg_enum where @@ -180,17 +176,17 @@ select cast(cast('red' as rainbow) as text) || 'hithere'; select cast(cast('red' as text) as rainbow) = cast('red' as rainbow); -select MIN(col) from enumtest; +select min(col) from enumtest; -select MAX(col) from enumtest; +select max(col) from enumtest; -select MAX(col) from enumtest where col < 'green'; +select max(col) from enumtest where col < 'green'; set enable_seqscan = off; set enable_bitmapscan = off; -create unique index "enumtest_btree" on enumtest using btree (col); +create unique index enumtest_btree on enumtest using btree (col); select * from enumtest where col = 'orange'; @@ -204,15 +200,15 @@ select * from enumtest where col < 'green' order by col; select * from enumtest where col <= 'green' order by col; -select MIN(col) from enumtest; +select min(col) from enumtest; -select MAX(col) from enumtest; +select max(col) from enumtest; -select MAX(col) from enumtest where col < 'green'; +select max(col) from enumtest where col < 'green'; drop index enumtest_btree; -create index "enumtest_hash" on enumtest using hash (col); +create index enumtest_hash on enumtest using hash (col); select * from enumtest where col = 'orange'; @@ -261,22 +257,22 @@ select enum_range(cast(null as rainbow), null); create function echo_me(anyenum) returns text language plpgsql -as $function$ +as $$ BEGIN RETURN $1::text || 'omg'; END -$function$; +$$; select echo_me(cast('red' as rainbow)); create function echo_me(rainbow) returns text language plpgsql -as $function$ +as $$ BEGIN RETURN $1::text || 'wtf'; END -$function$; +$$; select echo_me(cast('red' as rainbow)); @@ -399,6 +395,6 @@ drop table enumtest; drop type rainbow; -select COUNT(*) from pg_type where typname = 'rainbow'; +select count(*) from pg_type where typname = 'rainbow'; select * from pg_enum where not exists (select 1 from pg_type where pg_type.oid = enumtypid); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__enum_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__enum_80.snap index 8fd3e8db4..a0b1609ef 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__enum_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__enum_80.snap @@ -2,14 +2,16 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/enum.sql --- -create type rainbow as enum ('red', -'orange', -'yellow', -'green', -'blue', -'purple'); +create type rainbow as enum ( + 'red', + 'orange', + 'yellow', + 'green', + 'blue', + 'purple' +); -select COUNT(*) from pg_enum where enumtypid = cast('rainbow' as regtype); +select count(*) from pg_enum where enumtypid = cast('rainbow' as regtype); select cast('red' as rainbow); @@ -152,11 +154,7 @@ alter type insenum add value 'i30' before 'L2'; select enumlabel, - case - when enumsortorder > 20 then null - else enumsortorder - end - as so + case when enumsortorder > 20 then null else enumsortorder end as so from pg_enum where @@ -185,17 +183,17 @@ select cast(cast('red' as rainbow) as text) || 'hithere'; select cast(cast('red' as text) as rainbow) = cast('red' as rainbow); -select MIN(col) from enumtest; +select min(col) from enumtest; -select MAX(col) from enumtest; +select max(col) from enumtest; -select MAX(col) from enumtest where col < 'green'; +select max(col) from enumtest where col < 'green'; set enable_seqscan = off; set enable_bitmapscan = off; -create unique index "enumtest_btree" on enumtest using btree (col); +create unique index enumtest_btree on enumtest using btree (col); select * from enumtest where col = 'orange'; @@ -209,15 +207,15 @@ select * from enumtest where col < 'green' order by col; select * from enumtest where col <= 'green' order by col; -select MIN(col) from enumtest; +select min(col) from enumtest; -select MAX(col) from enumtest; +select max(col) from enumtest; -select MAX(col) from enumtest where col < 'green'; +select max(col) from enumtest where col < 'green'; drop index enumtest_btree; -create index "enumtest_hash" on enumtest using hash (col); +create index enumtest_hash on enumtest using hash (col); select * from enumtest where col = 'orange'; @@ -266,22 +264,22 @@ select enum_range(cast(null as rainbow), null); create function echo_me(anyenum) returns text language plpgsql -as $function$ +as $$ BEGIN RETURN $1::text || 'omg'; END -$function$; +$$; select echo_me(cast('red' as rainbow)); create function echo_me(rainbow) returns text language plpgsql -as $function$ +as $$ BEGIN RETURN $1::text || 'wtf'; END -$function$; +$$; select echo_me(cast('red' as rainbow)); @@ -411,19 +409,11 @@ drop table enumtest; drop type rainbow; -select COUNT(*) from pg_type where typname = 'rainbow'; +select count(*) from pg_type where typname = 'rainbow'; select * from pg_enum where - not exists - ( - select - 1 - from - pg_type - where - pg_type.oid = enumtypid - ); + not exists (select 1 from pg_type where pg_type.oid = enumtypid); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_100.snap index 3b10c361f..cd294daba 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_100.snap @@ -9,20 +9,16 @@ returns int8alias1 language internal immutable strict -as $function$ -int8in -$function$; +as 'int8in'; create function int8alias1out(int8alias1) returns cstring language internal immutable strict -as $function$ -int8out -$function$; +as 'int8out'; -create type int8alias1 (input = int8alias1in, output = int8alias1out, like = bigint); +create type int8alias1 (input = int8alias1in, output = int8alias1out, "like" = int8); create type int8alias2; @@ -31,141 +27,133 @@ returns int8alias2 language internal immutable strict -as $function$ -int8in -$function$; +as 'int8in'; create function int8alias2out(int8alias2) returns cstring language internal immutable strict -as $function$ -int8out -$function$; +as 'int8out'; -create type int8alias2 (input = int8alias2in, output = int8alias2out, like = bigint); +create type int8alias2 (input = int8alias2in, output = int8alias2out, "like" = int8); -create cast (bigint as int8alias1) without function; +create cast (int8 as int8alias1) without function; -create cast (bigint as int8alias2) without function; +create cast (int8 as int8alias2) without function; -create cast (int8alias1 as bigint) without function; +create cast (int8alias1 as int8) without function; -create cast (int8alias2 as bigint) without function; +create cast (int8alias2 as int8) without function; create function int8alias1eq(int8alias1, int8alias1) -returns boolean +returns bool language internal immutable strict -as $function$ -int8eq -$function$; - -create operator = (PROCEDURE = int8alias1eq, -LEFTARG = int8alias1, -RIGHTARG = int8alias1, -COMMUTATOR = =, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +as 'int8eq'; + +create operator = ( + procedure = int8alias1eq, + leftarg = int8alias1, + rightarg = int8alias1, + commutator = =, + restrict = eqsel, + join = eqjoinsel, + merges +); alter operator family integer_ops using btree add operator 3 = (int8alias1, int8alias1); create function int8alias2eq(int8alias2, int8alias2) -returns boolean +returns bool language internal immutable strict -as $function$ -int8eq -$function$; - -create operator = (PROCEDURE = int8alias2eq, -LEFTARG = int8alias2, -RIGHTARG = int8alias2, -COMMUTATOR = =, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +as 'int8eq'; + +create operator = ( + procedure = int8alias2eq, + leftarg = int8alias2, + rightarg = int8alias2, + commutator = =, + restrict = eqsel, + join = eqjoinsel, + merges +); alter operator family integer_ops using btree add operator 3 = (int8alias2, int8alias2); -create function int8alias1eq(bigint, int8alias1) -returns boolean +create function int8alias1eq(int8, int8alias1) +returns bool language internal immutable strict -as $function$ -int8eq -$function$; - -create operator = (PROCEDURE = int8alias1eq, -LEFTARG = bigint, -RIGHTARG = int8alias1, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +as 'int8eq'; + +create operator = ( + procedure = int8alias1eq, + leftarg = int8, + rightarg = int8alias1, + restrict = eqsel, + join = eqjoinsel, + merges +); -alter operator family integer_ops using btree add operator 3 = (bigint, int8alias1); +alter operator family integer_ops using btree add operator 3 = (int8, int8alias1); create function int8alias1eq(int8alias1, int8alias2) -returns boolean +returns bool language internal immutable strict -as $function$ -int8eq -$function$; - -create operator = (PROCEDURE = int8alias1eq, -LEFTARG = int8alias1, -RIGHTARG = int8alias2, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +as 'int8eq'; + +create operator = ( + procedure = int8alias1eq, + leftarg = int8alias1, + rightarg = int8alias2, + restrict = eqsel, + join = eqjoinsel, + merges +); alter operator family integer_ops using btree add operator 3 = (int8alias1, int8alias2); create function int8alias1lt(int8alias1, int8alias1) -returns boolean +returns bool language internal immutable strict -as $function$ -int8lt -$function$; +as 'int8lt'; -create operator < (PROCEDURE = int8alias1lt, LEFTARG = int8alias1, RIGHTARG = int8alias1); +create operator < (procedure = int8alias1lt, leftarg = int8alias1, rightarg = int8alias1); alter operator family integer_ops using btree add operator 1 < (int8alias1, int8alias1); -create function int8alias1cmp(bigint, int8alias1) +create function int8alias1cmp(int8, int8alias1) returns int language internal immutable strict -as $function$ -btint8cmp -$function$; +as 'btint8cmp'; -alter operator family integer_ops using btree add function 1 int8alias1cmp(bigint, int8alias1); +alter operator family integer_ops using btree add function 1 int8alias1cmp(int8, int8alias1); create table ec0 ( - ff bigint primary key, - f1 bigint, - f2 bigint + ff int8 primary key, + f1 int8, + f2 int8 ); create table ec1 ( - ff bigint primary key, + ff int8 primary key, f1 int8alias1, f2 int8alias2 ); create table ec2 ( - xf bigint primary key, + xf int8 primary key, x1 int8alias1, x2 int8alias2 ); @@ -174,7 +162,7 @@ set enable_hashjoin = off; set enable_mergejoin = off; -select * from ec0 where ff = f1 and f1 = cast('42' as bigint); +select * from ec0 where ff = f1 and f1 = cast('42' as int8); select * from ec0 where ff = f1 and f1 = cast('42' as int8alias1); @@ -182,23 +170,23 @@ select * from ec1 where ff = f1 and f1 = cast('42' as int8alias1); select * from ec1 where ff = f1 and f1 = cast('42' as int8alias2); -select * from ec1, ec2 where ff = x1 and ff = cast('42' as bigint); +select * from ec1, ec2 where ff = x1 and ff = cast('42' as int8); select * from ec1, ec2 where ff = x1 and ff = cast('42' as int8alias1); -select * from ec1, ec2 where ff = x1 and cast('42' as bigint) = x1; +select * from ec1, ec2 where ff = x1 and cast('42' as int8) = x1; select * from ec1, ec2 where ff = x1 and x1 = cast('42' as int8alias1); select * from ec1, ec2 where ff = x1 and x1 = cast('42' as int8alias2); -create unique index "ec1_expr1" on ec1 using btree ((ff + 1)); +create unique index ec1_expr1 on ec1 using btree ((ff + 1)); -create unique index "ec1_expr2" on ec1 using btree ((ff + 2 + 1)); +create unique index ec1_expr2 on ec1 using btree ((ff + 2 + 1)); -create unique index "ec1_expr3" on ec1 using btree ((ff + 3 + 1)); +create unique index ec1_expr3 on ec1 using btree ((ff + 3 + 1)); -create unique index "ec1_expr4" on ec1 using btree ((ff + 4)); +create unique index ec1_expr4 on ec1 using btree ((ff + 4)); select * @@ -208,18 +196,13 @@ from select ff + 1 as x from - ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 - ) - as ss0 + (select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1) as ss0 union all select ff + 4 as x from ec1 ) as ss1 where - ss1.x = ec1.f1 and ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ec1.ff = cast(42 as int8); select * @@ -229,20 +212,13 @@ from select ff + 1 as x from - ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 - ) - as ss0 + (select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1) as ss0 union all select ff + 4 as x from ec1 ) as ss1 where - ss1.x = ec1.f1 and - ec1.ff = cast(42 as bigint) and - ec1.ff = ec1.f1; + ss1.x = ec1.f1 and ec1.ff = cast(42 as int8) and ec1.ff = ec1.f1; select * @@ -252,12 +228,7 @@ from select ff + 1 as x from - ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 - ) - as ss0 + (select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1) as ss0 union all select ff + 4 as x from ec1 ) @@ -266,20 +237,13 @@ from select ff + 1 as x from - ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 - ) - as ss0 + (select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1) as ss0 union all select ff + 4 as x from ec1 ) as ss2 where - ss1.x = ec1.f1 and - ss1.x = ss2.x and - ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ss1.x = ss2.x and ec1.ff = cast(42 as int8); set enable_mergejoin = 'on'; @@ -293,12 +257,7 @@ from select ff + 1 as x from - ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 - ) - as ss0 + (select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1) as ss0 union all select ff + 4 as x from ec1 ) @@ -307,20 +266,13 @@ from select ff + 1 as x from - ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 - ) - as ss0 + (select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1) as ss0 union all select ff + 4 as x from ec1 ) as ss2 where - ss1.x = ec1.f1 and - ss1.x = ss2.x and - ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ss1.x = ss2.x and ec1.ff = cast(42 as int8); set enable_nestloop = 'on'; @@ -336,18 +288,13 @@ from select ff + 1 as x from - ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 - ) - as ss0 + (select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1) as ss0 union all select ff + 4 as x from ec1 ) as ss1 where - ss1.x = ec1.f1 and ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ec1.ff = cast(42 as int8); set enable_mergejoin = 'on'; @@ -361,18 +308,13 @@ from select ff + 1 as x from - ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 - ) - as ss0 + (select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1) as ss0 union all select ff + 4 as x from ec1 ) as ss1 where - ss1.x = ec1.f1 and ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ec1.ff = cast(42 as int8); set enable_nestloop = 'on'; @@ -385,9 +327,9 @@ create policy p1 on ec1 as permissive for all to public using (f1 < cast('5' as create user regress_user_ectest; -grant SELECT on table ec0 to regress_user_ectest; +grant select on table ec0 to regress_user_ectest; -grant SELECT on table ec1 to regress_user_ectest; +grant select on table ec1 to regress_user_ectest; select * @@ -395,8 +337,7 @@ from ec0 as a, ec1 as b where - a.ff = b.ff and - a.ff = cast(cast(43 as bigint) as int8alias1); + a.ff = b.ff and a.ff = cast(cast(43 as bigint) as int8alias1); set session authorization regress_user_ectest; @@ -406,14 +347,13 @@ from ec0 as a, ec1 as b where - a.ff = b.ff and - a.ff = cast(cast(43 as bigint) as int8alias1); + a.ff = b.ff and a.ff = cast(cast(43 as bigint) as int8alias1); reset session_authorization; -revoke SELECT on table ec0 from regress_user_ectest; +revoke select on table ec0 from regress_user_ectest; -revoke SELECT on table ec1 from regress_user_ectest; +revoke select on table ec1 from regress_user_ectest; drop role regress_user_ectest; @@ -429,8 +369,7 @@ from ec0 as m inner join ec0 as n on m.ff = n.ff inner join ec1 as p - on cast(p.f1 as bigint) = - cast(m.ff + n.ff as int8alias1); + on cast(p.f1 as int8) = cast(m.ff + n.ff as int8alias1); reset enable_mergejoin; @@ -442,19 +381,14 @@ create temporary table undername ( ); create temporary view overview -as select - cast(f1 as information_schema.sql_identifier) - as sqli, - f2 -from - undername; +as select cast(f1 as information_schema.sql_identifier) as sqli, f2 from undername; select * from overview where sqli = 'foo' order by sqli; begin; create table tbl_nocom ( - a bigint, + a int8, b int8alias1 ); @@ -464,18 +398,16 @@ set enable_mergejoin = 'on'; select * from tbl_nocom as t1 full outer join tbl_nocom as t2 on t2.a = t1.b; -alter operator = (bigint, int8alias1) set (hashes); +alter operator = (int8, int8alias1) set (hashes); -alter operator family integer_ops using hash add operator 1 = (bigint, int8alias1); +alter operator family integer_ops using hash add operator 1 = (int8, int8alias1); create function hashint8alias1(int8alias1) returns int language internal immutable strict -as $function$ -hashint8 -$function$; +as 'hashint8'; alter operator family integer_ops using hash add function 1 hashint8alias1(int8alias1); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_80.snap index 7e2ea0184..98e856c9b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_80.snap @@ -9,23 +9,19 @@ returns int8alias1 language internal immutable strict -as $function$ -int8in -$function$; +as 'int8in'; create function int8alias1out(int8alias1) returns cstring language internal immutable strict -as $function$ -int8out -$function$; +as 'int8out'; create type int8alias1 ( input = int8alias1in, output = int8alias1out, - like = bigint + "like" = int8 ); create type int8alias2; @@ -35,153 +31,147 @@ returns int8alias2 language internal immutable strict -as $function$ -int8in -$function$; +as 'int8in'; create function int8alias2out(int8alias2) returns cstring language internal immutable strict -as $function$ -int8out -$function$; +as 'int8out'; create type int8alias2 ( input = int8alias2in, output = int8alias2out, - like = bigint + "like" = int8 ); -create cast (bigint as int8alias1) without function; +create cast (int8 as int8alias1) without function; -create cast (bigint as int8alias2) without function; +create cast (int8 as int8alias2) without function; -create cast (int8alias1 as bigint) without function; +create cast (int8alias1 as int8) without function; -create cast (int8alias2 as bigint) without function; +create cast (int8alias2 as int8) without function; create function int8alias1eq(int8alias1, int8alias1) -returns boolean +returns bool language internal immutable strict -as $function$ -int8eq -$function$; - -create operator = (PROCEDURE = int8alias1eq, -LEFTARG = int8alias1, -RIGHTARG = int8alias1, -COMMUTATOR = =, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +as 'int8eq'; + +create operator = ( + procedure = int8alias1eq, + leftarg = int8alias1, + rightarg = int8alias1, + commutator = =, + restrict = eqsel, + join = eqjoinsel, + merges +); alter operator family integer_ops using btree add operator 3 = (int8alias1, int8alias1); create function int8alias2eq(int8alias2, int8alias2) -returns boolean +returns bool language internal immutable strict -as $function$ -int8eq -$function$; - -create operator = (PROCEDURE = int8alias2eq, -LEFTARG = int8alias2, -RIGHTARG = int8alias2, -COMMUTATOR = =, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +as 'int8eq'; + +create operator = ( + procedure = int8alias2eq, + leftarg = int8alias2, + rightarg = int8alias2, + commutator = =, + restrict = eqsel, + join = eqjoinsel, + merges +); alter operator family integer_ops using btree add operator 3 = (int8alias2, int8alias2); -create function int8alias1eq(bigint, int8alias1) -returns boolean +create function int8alias1eq(int8, int8alias1) +returns bool language internal immutable strict -as $function$ -int8eq -$function$; - -create operator = (PROCEDURE = int8alias1eq, -LEFTARG = bigint, -RIGHTARG = int8alias1, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +as 'int8eq'; + +create operator = ( + procedure = int8alias1eq, + leftarg = int8, + rightarg = int8alias1, + restrict = eqsel, + join = eqjoinsel, + merges +); alter operator family integer_ops using btree - add operator 3 = (bigint, int8alias1); + add operator 3 = (int8, int8alias1); create function int8alias1eq(int8alias1, int8alias2) -returns boolean +returns bool language internal immutable strict -as $function$ -int8eq -$function$; - -create operator = (PROCEDURE = int8alias1eq, -LEFTARG = int8alias1, -RIGHTARG = int8alias2, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +as 'int8eq'; + +create operator = ( + procedure = int8alias1eq, + leftarg = int8alias1, + rightarg = int8alias2, + restrict = eqsel, + join = eqjoinsel, + merges +); alter operator family integer_ops using btree add operator 3 = (int8alias1, int8alias2); create function int8alias1lt(int8alias1, int8alias1) -returns boolean +returns bool language internal immutable strict -as $function$ -int8lt -$function$; +as 'int8lt'; -create operator < (PROCEDURE = int8alias1lt, -LEFTARG = int8alias1, -RIGHTARG = int8alias1); +create operator < ( + procedure = int8alias1lt, + leftarg = int8alias1, + rightarg = int8alias1 +); alter operator family integer_ops using btree add operator 1 < (int8alias1, int8alias1); -create function int8alias1cmp(bigint, int8alias1) +create function int8alias1cmp(int8, int8alias1) returns int language internal immutable strict -as $function$ -btint8cmp -$function$; +as 'btint8cmp'; alter operator family integer_ops using btree - add function 1 int8alias1cmp(bigint, int8alias1); + add function 1 int8alias1cmp(int8, int8alias1); create table ec0 ( - ff bigint primary key, - f1 bigint, - f2 bigint + ff int8 primary key, + f1 int8, + f2 int8 ); create table ec1 ( - ff bigint primary key, + ff int8 primary key, f1 int8alias1, f2 int8alias2 ); create table ec2 ( - xf bigint primary key, + xf int8 primary key, x1 int8alias1, x2 int8alias2 ); @@ -190,7 +180,7 @@ set enable_hashjoin = off; set enable_mergejoin = off; -select * from ec0 where ff = f1 and f1 = cast('42' as bigint); +select * from ec0 where ff = f1 and f1 = cast('42' as int8); select * from ec0 where ff = f1 and f1 = cast('42' as int8alias1); @@ -198,23 +188,23 @@ select * from ec1 where ff = f1 and f1 = cast('42' as int8alias1); select * from ec1 where ff = f1 and f1 = cast('42' as int8alias2); -select * from ec1, ec2 where ff = x1 and ff = cast('42' as bigint); +select * from ec1, ec2 where ff = x1 and ff = cast('42' as int8); select * from ec1, ec2 where ff = x1 and ff = cast('42' as int8alias1); -select * from ec1, ec2 where ff = x1 and cast('42' as bigint) = x1; +select * from ec1, ec2 where ff = x1 and cast('42' as int8) = x1; select * from ec1, ec2 where ff = x1 and x1 = cast('42' as int8alias1); select * from ec1, ec2 where ff = x1 and x1 = cast('42' as int8alias2); -create unique index "ec1_expr1" on ec1 using btree ((ff + 1)); +create unique index ec1_expr1 on ec1 using btree ((ff + 1)); -create unique index "ec1_expr2" on ec1 using btree ((ff + 2 + 1)); +create unique index ec1_expr2 on ec1 using btree ((ff + 2 + 1)); -create unique index "ec1_expr3" on ec1 using btree ((ff + 3 + 1)); +create unique index ec1_expr3 on ec1 using btree ((ff + 3 + 1)); -create unique index "ec1_expr4" on ec1 using btree ((ff + 4)); +create unique index ec1_expr4 on ec1 using btree ((ff + 4)); select * @@ -225,9 +215,7 @@ from ff + 1 as x from ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 + select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1 ) as ss0 union all @@ -235,8 +223,7 @@ from ) as ss1 where - ss1.x = ec1.f1 and - ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ec1.ff = cast(42 as int8); select * @@ -247,9 +234,7 @@ from ff + 1 as x from ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 + select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1 ) as ss0 union all @@ -257,9 +242,7 @@ from ) as ss1 where - ss1.x = ec1.f1 and - ec1.ff = cast(42 as bigint) and - ec1.ff = ec1.f1; + ss1.x = ec1.f1 and ec1.ff = cast(42 as int8) and ec1.ff = ec1.f1; select * @@ -270,9 +253,7 @@ from ff + 1 as x from ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 + select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1 ) as ss0 union all @@ -284,9 +265,7 @@ from ff + 1 as x from ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 + select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1 ) as ss0 union all @@ -294,9 +273,7 @@ from ) as ss2 where - ss1.x = ec1.f1 and - ss1.x = ss2.x and - ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ss1.x = ss2.x and ec1.ff = cast(42 as int8); set enable_mergejoin = 'on'; @@ -311,9 +288,7 @@ from ff + 1 as x from ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 + select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1 ) as ss0 union all @@ -325,9 +300,7 @@ from ff + 1 as x from ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 + select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1 ) as ss0 union all @@ -335,9 +308,7 @@ from ) as ss2 where - ss1.x = ec1.f1 and - ss1.x = ss2.x and - ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ss1.x = ss2.x and ec1.ff = cast(42 as int8); set enable_nestloop = 'on'; @@ -354,9 +325,7 @@ from ff + 1 as x from ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 + select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1 ) as ss0 union all @@ -364,8 +333,7 @@ from ) as ss1 where - ss1.x = ec1.f1 and - ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ec1.ff = cast(42 as int8); set enable_mergejoin = 'on'; @@ -380,9 +348,7 @@ from ff + 1 as x from ( - select ff + 2 as ff from ec1 - union all - select ff + 3 as ff from ec1 + select ff + 2 as ff from ec1 union all select ff + 3 as ff from ec1 ) as ss0 union all @@ -390,8 +356,7 @@ from ) as ss1 where - ss1.x = ec1.f1 and - ec1.ff = cast(42 as bigint); + ss1.x = ec1.f1 and ec1.ff = cast(42 as int8); set enable_nestloop = 'on'; @@ -409,9 +374,9 @@ using (f1 < cast('5' as int8alias1)); create user regress_user_ectest; -grant SELECT on table ec0 to regress_user_ectest; +grant select on table ec0 to regress_user_ectest; -grant SELECT on table ec1 to regress_user_ectest; +grant select on table ec1 to regress_user_ectest; select * @@ -419,9 +384,7 @@ from ec0 as a, ec1 as b where - a.ff = b.ff and - a.ff = - cast(cast(43 as bigint) as int8alias1); + a.ff = b.ff and a.ff = cast(cast(43 as bigint) as int8alias1); set session authorization regress_user_ectest; @@ -431,15 +394,13 @@ from ec0 as a, ec1 as b where - a.ff = b.ff and - a.ff = - cast(cast(43 as bigint) as int8alias1); + a.ff = b.ff and a.ff = cast(cast(43 as bigint) as int8alias1); reset session_authorization; -revoke SELECT on table ec0 from regress_user_ectest; +revoke select on table ec0 from regress_user_ectest; -revoke SELECT on table ec1 from regress_user_ectest; +revoke select on table ec1 from regress_user_ectest; drop role regress_user_ectest; @@ -450,10 +411,7 @@ set enable_mergejoin = off; select * from - ec0 as m - inner join - ec0 as n - on m.ff = n.ff + ec0 as m inner join ec0 as n on m.ff = n.ff inner join ec1 as p on m.ff + n.ff = p.f1; @@ -461,14 +419,10 @@ from select * from - ec0 as m - inner join - ec0 as n - on m.ff = n.ff + ec0 as m inner join ec0 as n on m.ff = n.ff inner join ec1 as p - on cast(p.f1 as bigint) = - cast(m.ff + n.ff as int8alias1); + on cast(p.f1 as int8) = cast(m.ff + n.ff as int8alias1); reset enable_mergejoin; @@ -481,9 +435,7 @@ create temporary table undername ( create temporary view overview as select - cast(f1 - as information_schema.sql_identifier) - as sqli, + cast(f1 as information_schema.sql_identifier) as sqli, f2 from undername; @@ -493,7 +445,7 @@ select * from overview where sqli = 'foo' order by sqli; begin; create table tbl_nocom ( - a bigint, + a int8, b int8alias1 ); @@ -503,19 +455,17 @@ set enable_mergejoin = 'on'; select * from tbl_nocom as t1 full outer join tbl_nocom as t2 on t2.a = t1.b; -alter operator = (bigint, int8alias1) set (hashes); +alter operator = (int8, int8alias1) set (hashes); alter operator family integer_ops using hash - add operator 1 = (bigint, int8alias1); + add operator 1 = (int8, int8alias1); create function hashint8alias1(int8alias1) returns int language internal immutable strict -as $function$ -hashint8 -$function$; +as 'hashint8'; alter operator family integer_ops using hash add function 1 hashint8alias1(int8alias1); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__errors_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__errors_100.snap index 846d4169a..9f130e46b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__errors_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__errors_100.snap @@ -47,52 +47,52 @@ commit; create aggregate newavg2 ( sfunc = int4pl, - basetype = int, - stype = int, + basetype = int4, + stype = int4, finalfunc = int2um, initcond = '0' ); -create aggregate newcnt1 (sfunc = int4inc, stype = int, initcond = '0'); +create aggregate newcnt1 (sfunc = int4inc, stype = int4, initcond = '0'); drop index nonesuch; drop aggregate newcnt(nonesuch); -drop aggregate nonesuch(int); +drop aggregate nonesuch(int4); -drop aggregate newcnt(real); +drop aggregate newcnt(float4); drop function nonesuch(); drop type nonesuch; -drop operator === (int, int); +drop operator === (int4, int4); -drop operator = (nonesuch, int); +drop operator = (nonesuch, int4); -drop operator = (int, nonesuch); +drop operator = (int4, nonesuch); drop rule nonesuch on noplace; select 1 / 0; -select cast(1 as bigint) / 0; +select cast(1 as int8) / 0; -select 1 / cast(0 as bigint); +select 1 / cast(0 as int8); -select cast(1 as smallint) / 0; +select cast(1 as int2) / 0; -select 1 / cast(0 as smallint); +select 1 / cast(0 as int2); select cast(1 as numeric) / 0; select 1 / cast(0 as numeric); -select cast(1 as double precision) / 0; +select cast(1 as float8) / 0; -select 1 / cast(0 as double precision); +select 1 / cast(0 as float8); -select cast(1 as real) / 0; +select cast(1 as float4) / 0; -select 1 / cast(0 as real); +select 1 / cast(0 as float4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__errors_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__errors_80.snap index 846d4169a..9f130e46b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__errors_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__errors_80.snap @@ -47,52 +47,52 @@ commit; create aggregate newavg2 ( sfunc = int4pl, - basetype = int, - stype = int, + basetype = int4, + stype = int4, finalfunc = int2um, initcond = '0' ); -create aggregate newcnt1 (sfunc = int4inc, stype = int, initcond = '0'); +create aggregate newcnt1 (sfunc = int4inc, stype = int4, initcond = '0'); drop index nonesuch; drop aggregate newcnt(nonesuch); -drop aggregate nonesuch(int); +drop aggregate nonesuch(int4); -drop aggregate newcnt(real); +drop aggregate newcnt(float4); drop function nonesuch(); drop type nonesuch; -drop operator === (int, int); +drop operator === (int4, int4); -drop operator = (nonesuch, int); +drop operator = (nonesuch, int4); -drop operator = (int, nonesuch); +drop operator = (int4, nonesuch); drop rule nonesuch on noplace; select 1 / 0; -select cast(1 as bigint) / 0; +select cast(1 as int8) / 0; -select 1 / cast(0 as bigint); +select 1 / cast(0 as int8); -select cast(1 as smallint) / 0; +select cast(1 as int2) / 0; -select 1 / cast(0 as smallint); +select 1 / cast(0 as int2); select cast(1 as numeric) / 0; select 1 / cast(0 as numeric); -select cast(1 as double precision) / 0; +select cast(1 as float8) / 0; -select 1 / cast(0 as double precision); +select 1 / cast(0 as float8); -select cast(1 as real) / 0; +select cast(1 as float4) / 0; -select 1 / cast(0 as real); +select 1 / cast(0 as float4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_100.snap index 9d3a57232..63cbbca3d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_100.snap @@ -2,88 +2,85 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/event_trigger.sql --- -create event trigger "regress_event_trigger" on ddl_command_start execute function pg_backend_pid(); +create event trigger regress_event_trigger on ddl_command_start execute function pg_backend_pid(); create function test_event_trigger() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'test_event_trigger: % %', tg_event, tg_tag; END -$function$; +$$; select test_event_trigger(); create function test_event_trigger_arg(name text) returns event_trigger language plpgsql -as $function$ -BEGIN RETURN 1; END -$function$; +as $$ BEGIN RETURN 1; END $$; create function test_event_trigger_sql() returns event_trigger language sql -as $function$ -SELECT 1 -$function$; +as $$ +SELECT 1 $$; -create event trigger "regress_event_trigger" +create event trigger regress_event_trigger on elephant_bootstrap execute function test_event_trigger(); -create event trigger "regress_event_trigger" +create event trigger regress_event_trigger on ddl_command_start execute function test_event_trigger(); -create event trigger "regress_event_trigger_end" +create event trigger regress_event_trigger_end on ddl_command_end execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when FOOD in ('sandwich') +when food in ('sandwich') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('sandwich') +when tag in ('sandwich') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('create table', 'create skunkcabbage') +when tag in ('create table', 'create skunkcabbage') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('DROP EVENT TRIGGER') +when tag in ('DROP EVENT TRIGGER') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('CREATE ROLE') +when tag in ('CREATE ROLE') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('CREATE DATABASE') +when tag in ('CREATE DATABASE') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('CREATE TABLESPACE') +when tag in ('CREATE TABLESPACE') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('create table') and TAG in ('CREATE FUNCTION') +when tag in ('create table') and tag in ('CREATE FUNCTION') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('create table', 'CREATE FUNCTION') +when tag in ('create table', 'CREATE FUNCTION') execute function test_event_trigger(); comment on event trigger regress_event_trigger is 'test comment'; @@ -92,7 +89,7 @@ create role regress_evt_user; set role to regress_evt_user; -create event trigger "regress_event_trigger_noperms" +create event trigger regress_event_trigger_noperms on ddl_command_start execute function test_event_trigger(); @@ -123,22 +120,20 @@ create table event_trigger_fire5 (a int); create function f1() returns int language plpgsql -as $function$ +as $$ begin create table event_trigger_fire6 (a int); return 0; -end -$function$; +end $$; select f1(); create procedure p1() language plpgsql -as $procedure$ +as $$ begin create table event_trigger_fire7 (a int); -end -$procedure$; +end $$; call p1(); @@ -168,7 +163,7 @@ create server useless_server foreign data wrapper useless; create user mapping for regress_evt_user server useless_server; -alter default privileges for role regress_evt_user revoke DELETE on tables from regress_evt_user; +alter default privileges for role regress_evt_user revoke delete on tables from regress_evt_user; alter event trigger regress_event_trigger owner to regress_evt_user; @@ -192,11 +187,11 @@ drop event trigger regress_event_trigger3; drop event trigger regress_event_trigger_end; -create schema "schema_one" authorization regress_evt_user; +create schema schema_one authorization regress_evt_user; -create schema "schema_two" authorization regress_evt_user; +create schema schema_two authorization regress_evt_user; -create schema "audit_tbls" authorization regress_evt_user; +create schema audit_tbls authorization regress_evt_user; create temporary table a_temp_tbl (); @@ -223,9 +218,7 @@ create or replace function schema_two.add(int, int) returns int language plpgsql called on null input -as $function$ -BEGIN RETURN coalesce($1,0) + coalesce($2,0); END; -$function$; +as $$ BEGIN RETURN coalesce($1,0) + coalesce($2,0); END; $$; create aggregate schema_two.newton (basetype = int, sfunc = schema_two.add, stype = int); @@ -237,9 +230,7 @@ create table undroppable_objs ( ); insert into undroppable_objs -values - ('table', 'schema_one.table_three'), - ('table', 'audit_tbls.schema_two_table_three'); +values ('table', 'schema_one.table_three'), ('table', 'audit_tbls.schema_two_table_three'); create table dropped_objects ( object_type text, @@ -248,15 +239,15 @@ create table dropped_objects ( object_identity text, address_names text[], address_args text[], - is_temporary boolean, - original boolean, - normal boolean + is_temporary bool, + original bool, + normal bool ); create or replace function undroppable() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE obj record; BEGIN @@ -273,14 +264,14 @@ BEGIN obj.object_identity, obj.object_type; END LOOP; END; -$function$; +$$; -create event trigger "undroppable" on sql_drop execute function undroppable(); +create event trigger undroppable on sql_drop execute function undroppable(); create or replace function test_evtrig_dropped_objects() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE obj record; BEGIN @@ -300,11 +291,11 @@ BEGIN obj.is_temporary, obj.original, obj.normal); END LOOP; END -$function$; +$$; -create event trigger "regress_event_trigger_drop_objects" +create event trigger regress_event_trigger_drop_objects on sql_drop -when TAG in ('drop table', 'drop function', 'drop view', 'drop owned', 'drop schema', 'alter table') +when tag in ('drop table', 'drop function', 'drop view', 'drop owned', 'drop schema', 'alter table') execute function test_evtrig_dropped_objects(); alter table schema_one.table_one @@ -335,7 +326,7 @@ drop event trigger undroppable; create or replace function event_trigger_report_dropped() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE r record; BEGIN FOR r IN SELECT * from pg_event_trigger_dropped_objects() @@ -348,17 +339,16 @@ BEGIN r.object_identity, r.schema_name, r.object_name, r.address_names, r.address_args; END LOOP; -END; -$function$; +END; $$; -create event trigger "regress_event_trigger_report_dropped" +create event trigger regress_event_trigger_report_dropped on sql_drop execute function event_trigger_report_dropped(); create or replace function event_trigger_report_end() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE r RECORD; BEGIN FOR r IN SELECT * FROM pg_event_trigger_ddl_commands() @@ -366,14 +356,13 @@ BEGIN RAISE NOTICE 'END: command_tag=% type=% identity=%', r.command_tag, r.object_type, r.object_identity; END LOOP; -END; -$function$; +END; $$; -create event trigger "regress_event_trigger_report_end" +create event trigger regress_event_trigger_report_end on ddl_command_end execute function event_trigger_report_end(); -create schema "evttrig"; +create schema evttrig; create table one ( col_a serial primary key, @@ -381,7 +370,7 @@ create table one ( col_c serial ); -create index "one_idx" on one using btree (col_b); +create index one_idx on one using btree (col_b); create table two (col_c int check (col_c > 0) references one default 42); @@ -432,7 +421,7 @@ drop table a_temp_tbl; create or replace function event_trigger_report_dropped() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE r record; BEGIN FOR r IN SELECT * from pg_event_trigger_dropped_objects() @@ -442,17 +431,15 @@ BEGIN r.object_identity, r.schema_name, r.object_name, r.address_names, r.address_args; END LOOP; -END; -$function$; +END; $$; create function event_trigger_dummy_trigger() returns trigger language plpgsql -as $function$ +as $$ BEGIN RETURN new; -END; -$function$; +END; $$; create table evtrg_nontemp_table ( f1 int primary key, @@ -502,20 +489,18 @@ select pg_event_trigger_table_rewrite_oid(); create or replace function test_evtrig_no_rewrite() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE EXCEPTION 'rewrites not allowed'; END; -$function$; +$$; -create event trigger "no_rewrite_allowed" -on table_rewrite -execute function test_evtrig_no_rewrite(); +create event trigger no_rewrite_allowed on table_rewrite execute function test_evtrig_no_rewrite(); create table rewriteme ( id serial primary key, foo double precision, - bar timestamp with time zone + bar timestamptz ); insert into rewriteme select x * 1.001 from generate_series(1, 500) as t (x); @@ -529,13 +514,13 @@ alter table rewriteme create or replace function test_evtrig_no_rewrite() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'Table ''%'' is being rewritten (reason = %)', pg_event_trigger_table_rewrite_oid()::regclass, pg_event_trigger_table_rewrite_reason(); END; -$function$; +$$; alter table rewriteme add column onemore int default 0, @@ -554,7 +539,7 @@ alter table rewriteme begin; -set time zone UTC; +set time zone 'UTC'; alter table rewriteme alter column bar type timestamp; @@ -562,7 +547,7 @@ alter table rewriteme set time zone '0'; alter table rewriteme - alter column bar type timestamp with time zone; + alter column bar type timestamptz; set time zone 'Europe/London'; @@ -574,12 +559,12 @@ rollback; create or replace function test_evtrig_no_rewrite() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'Table is being rewritten (reason = %)', pg_event_trigger_table_rewrite_reason(); END; -$function$; +$$; create type rewritetype as (a int); @@ -604,21 +589,21 @@ drop function test_evtrig_no_rewrite(); create or replace function reindex_start_command() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'REINDEX START: % %', tg_event, tg_tag; END; -$function$; +$$; -create event trigger "regress_reindex_start" +create event trigger regress_reindex_start on ddl_command_start -when TAG in ('REINDEX') +when tag in ('REINDEX') execute function reindex_start_command(); create function reindex_end_command() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE obj record; BEGIN @@ -628,67 +613,65 @@ BEGIN obj.command_tag, obj.object_type, obj.object_identity; END LOOP; END; -$function$; +$$; -create event trigger "regress_reindex_end" +create event trigger regress_reindex_end on ddl_command_end -when TAG in ('REINDEX') +when tag in ('REINDEX') execute function reindex_end_command(); create function reindex_end_command_snap() returns event_trigger language plpgsql -as $function$ -BEGIN PERFORM 1; END -$function$; +as $$ BEGIN PERFORM 1; END $$; -create event trigger "regress_reindex_end_snap" +create event trigger regress_reindex_end_snap on ddl_command_end execute function reindex_end_command_snap(); create table concur_reindex_tab (c1 int); -create index "concur_reindex_ind" on concur_reindex_tab using btree (c1); +create index concur_reindex_ind on concur_reindex_tab using btree (c1); reindex index concur_reindex_ind; reindex table concur_reindex_tab; -reindex (CONCURRENTLY) index concur_reindex_ind; +reindex (concurrently) index concur_reindex_ind; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; alter event trigger regress_reindex_start disable; reindex index concur_reindex_ind; -reindex (CONCURRENTLY) index concur_reindex_ind; +reindex (concurrently) index concur_reindex_ind; drop index concur_reindex_ind; reindex table concur_reindex_tab; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; -create schema "concur_reindex_schema"; +create schema concur_reindex_schema; reindex schema concur_reindex_schema; -reindex (CONCURRENTLY) schema concur_reindex_schema; +reindex (concurrently) schema concur_reindex_schema; create table concur_reindex_schema.tab (a int); -create index "ind" on concur_reindex_schema.tab using btree (a); +create index ind on concur_reindex_schema.tab using btree (a); reindex schema concur_reindex_schema; -reindex (CONCURRENTLY) schema concur_reindex_schema; +reindex (concurrently) schema concur_reindex_schema; drop index concur_reindex_schema.ind; reindex schema concur_reindex_schema; -reindex (CONCURRENTLY) schema concur_reindex_schema; +reindex (concurrently) schema concur_reindex_schema; drop schema concur_reindex_schema cascade; @@ -697,23 +680,23 @@ partition by range(id); reindex table concur_reindex_part; -reindex (CONCURRENTLY) table concur_reindex_part; +reindex (concurrently) table concur_reindex_part; create table concur_reindex_child partition of concur_reindex_part for values from (0) to (10); reindex table concur_reindex_part; -reindex (CONCURRENTLY) table concur_reindex_part; +reindex (concurrently) table concur_reindex_part; -create index "concur_reindex_partidx" on concur_reindex_part using btree (id); +create index concur_reindex_partidx on concur_reindex_part using btree (id); reindex index concur_reindex_partidx; -reindex (CONCURRENTLY) index concur_reindex_partidx; +reindex (concurrently) index concur_reindex_partidx; reindex table concur_reindex_part; -reindex (CONCURRENTLY) table concur_reindex_part; +reindex (concurrently) table concur_reindex_part; drop table concur_reindex_part; @@ -741,43 +724,43 @@ create table event_trigger_test ( create or replace function start_command() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE '% - ddl_command_start', tg_tag; END; -$function$; +$$; create or replace function end_command() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE '% - ddl_command_end', tg_tag; END; -$function$; +$$; create or replace function drop_sql_command() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE '% - sql_drop', tg_tag; END; -$function$; +$$; -create event trigger "start_rls_command" +create event trigger start_rls_command on ddl_command_start -when TAG in ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') +when tag in ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') execute function start_command(); -create event trigger "end_rls_command" +create event trigger end_rls_command on ddl_command_end -when TAG in ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') +when tag in ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') execute function end_command(); -create event trigger "sql_drop_command" +create event trigger sql_drop_command on sql_drop -when TAG in ('DROP POLICY') +when tag in ('DROP POLICY') execute function drop_sql_command(); create policy p1 on event_trigger_test as permissive for all to public using (false); @@ -790,31 +773,15 @@ drop policy p2 on event_trigger_test; select e.evtname, - pg_describe_object( - cast('pg_event_trigger' as regclass), - e.oid, - 0 - ) - as descr, + pg_describe_object(cast('pg_event_trigger' as regclass), e.oid, 0) as descr, b.type, b.object_names, b.object_args, - pg_identify_object(a.classid, a.objid, a.objsubid) - as ident + pg_identify_object(a.classid, a.objid, a.objsubid) as ident from pg_event_trigger as e, - lateral pg_identify_object_as_address( - cast('pg_event_trigger' as regclass), - e.oid, - 0 - ) - as b, - lateral pg_get_object_address( - b.type, - b.object_names, - b.object_args - ) - as a + lateral pg_identify_object_as_address(cast('pg_event_trigger' as regclass), e.oid, 0) as b, + lateral pg_get_object_address(b.type, b.object_names, b.object_args) as a order by e.evtname; drop event trigger start_rls_command; @@ -826,7 +793,7 @@ drop event trigger sql_drop_command; create function test_event_trigger_guc() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE obj record; BEGIN @@ -835,11 +802,11 @@ BEGIN RAISE NOTICE '% dropped %', tg_tag, obj.object_type; END LOOP; END; -$function$; +$$; -create event trigger "test_event_trigger_guc" +create event trigger test_event_trigger_guc on sql_drop -when TAG in ('DROP POLICY') +when tag in ('DROP POLICY') execute function test_event_trigger_guc(); set event_triggers = 'on'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_80.snap index 15a176b1d..d69365b99 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_80.snap @@ -2,90 +2,87 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/event_trigger.sql --- -create event trigger "regress_event_trigger" +create event trigger regress_event_trigger on ddl_command_start execute function pg_backend_pid(); create function test_event_trigger() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'test_event_trigger: % %', tg_event, tg_tag; END -$function$; +$$; select test_event_trigger(); create function test_event_trigger_arg(name text) returns event_trigger language plpgsql -as $function$ -BEGIN RETURN 1; END -$function$; +as $$ BEGIN RETURN 1; END $$; create function test_event_trigger_sql() returns event_trigger language sql -as $function$ -SELECT 1 -$function$; +as $$ +SELECT 1 $$; -create event trigger "regress_event_trigger" +create event trigger regress_event_trigger on elephant_bootstrap execute function test_event_trigger(); -create event trigger "regress_event_trigger" +create event trigger regress_event_trigger on ddl_command_start execute function test_event_trigger(); -create event trigger "regress_event_trigger_end" +create event trigger regress_event_trigger_end on ddl_command_end execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when FOOD in ('sandwich') +when food in ('sandwich') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('sandwich') +when tag in ('sandwich') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('create table', 'create skunkcabbage') +when tag in ('create table', 'create skunkcabbage') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('DROP EVENT TRIGGER') +when tag in ('DROP EVENT TRIGGER') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('CREATE ROLE') +when tag in ('CREATE ROLE') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('CREATE DATABASE') +when tag in ('CREATE DATABASE') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('CREATE TABLESPACE') +when tag in ('CREATE TABLESPACE') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('create table') and TAG in ('CREATE FUNCTION') +when tag in ('create table') and tag in ('CREATE FUNCTION') execute function test_event_trigger(); -create event trigger "regress_event_trigger2" +create event trigger regress_event_trigger2 on ddl_command_start -when TAG in ('create table', 'CREATE FUNCTION') +when tag in ('create table', 'CREATE FUNCTION') execute function test_event_trigger(); comment on event trigger regress_event_trigger is 'test comment'; @@ -94,7 +91,7 @@ create role regress_evt_user; set role to regress_evt_user; -create event trigger "regress_event_trigger_noperms" +create event trigger regress_event_trigger_noperms on ddl_command_start execute function test_event_trigger(); @@ -125,22 +122,20 @@ create table event_trigger_fire5 (a int); create function f1() returns int language plpgsql -as $function$ +as $$ begin create table event_trigger_fire6 (a int); return 0; -end -$function$; +end $$; select f1(); create procedure p1() language plpgsql -as $procedure$ +as $$ begin create table event_trigger_fire7 (a int); -end -$procedure$; +end $$; call p1(); @@ -172,9 +167,7 @@ create user mapping for regress_evt_user server useless_server; alter default privileges for role regress_evt_user -revoke DELETE -on tables -from regress_evt_user; +revoke delete on tables from regress_evt_user; alter event trigger regress_event_trigger owner to regress_evt_user; @@ -198,11 +191,11 @@ drop event trigger regress_event_trigger3; drop event trigger regress_event_trigger_end; -create schema "schema_one" authorization regress_evt_user; +create schema schema_one authorization regress_evt_user; -create schema "schema_two" authorization regress_evt_user; +create schema schema_two authorization regress_evt_user; -create schema "audit_tbls" authorization regress_evt_user; +create schema audit_tbls authorization regress_evt_user; create temporary table a_temp_tbl (); @@ -229,9 +222,7 @@ create or replace function schema_two.add(int, int) returns int language plpgsql called on null input -as $function$ -BEGIN RETURN coalesce($1,0) + coalesce($2,0); END; -$function$; +as $$ BEGIN RETURN coalesce($1,0) + coalesce($2,0); END; $$; create aggregate schema_two.newton ( basetype = int, @@ -249,10 +240,7 @@ create table undroppable_objs ( insert into undroppable_objs values ('table', 'schema_one.table_three'), - ( - 'table', - 'audit_tbls.schema_two_table_three' - ); + ('table', 'audit_tbls.schema_two_table_three'); create table dropped_objects ( object_type text, @@ -261,15 +249,15 @@ create table dropped_objects ( object_identity text, address_names text[], address_args text[], - is_temporary boolean, - original boolean, - normal boolean + is_temporary bool, + original bool, + normal bool ); create or replace function undroppable() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE obj record; BEGIN @@ -286,14 +274,14 @@ BEGIN obj.object_identity, obj.object_type; END LOOP; END; -$function$; +$$; -create event trigger "undroppable" on sql_drop execute function undroppable(); +create event trigger undroppable on sql_drop execute function undroppable(); create or replace function test_evtrig_dropped_objects() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE obj record; BEGIN @@ -313,11 +301,11 @@ BEGIN obj.is_temporary, obj.original, obj.normal); END LOOP; END -$function$; +$$; -create event trigger "regress_event_trigger_drop_objects" +create event trigger regress_event_trigger_drop_objects on sql_drop -when TAG in ('drop table', 'drop function', 'drop view', 'drop owned', 'drop schema', 'alter table') +when tag in ('drop table', 'drop function', 'drop view', 'drop owned', 'drop schema', 'alter table') execute function test_evtrig_dropped_objects(); alter table schema_one.table_one @@ -327,8 +315,7 @@ drop schema schema_one, schema_two cascade; delete from undroppable_objs where - object_identity = - 'audit_tbls.schema_two_table_three'; + object_identity = 'audit_tbls.schema_two_table_three'; drop schema schema_one, schema_two cascade; @@ -341,8 +328,7 @@ select from dropped_objects where - schema_name is null or - schema_name <> 'pg_toast'; + schema_name is null or schema_name <> 'pg_toast'; drop owned by regress_evt_user; @@ -357,7 +343,7 @@ drop event trigger undroppable; create or replace function event_trigger_report_dropped() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE r record; BEGIN FOR r IN SELECT * from pg_event_trigger_dropped_objects() @@ -370,17 +356,16 @@ BEGIN r.object_identity, r.schema_name, r.object_name, r.address_names, r.address_args; END LOOP; -END; -$function$; +END; $$; -create event trigger "regress_event_trigger_report_dropped" +create event trigger regress_event_trigger_report_dropped on sql_drop execute function event_trigger_report_dropped(); create or replace function event_trigger_report_end() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE r RECORD; BEGIN FOR r IN SELECT * FROM pg_event_trigger_ddl_commands() @@ -388,14 +373,13 @@ BEGIN RAISE NOTICE 'END: command_tag=% type=% identity=%', r.command_tag, r.object_type, r.object_identity; END LOOP; -END; -$function$; +END; $$; -create event trigger "regress_event_trigger_report_end" +create event trigger regress_event_trigger_report_end on ddl_command_end execute function event_trigger_report_end(); -create schema "evttrig"; +create schema evttrig; create table one ( col_a serial primary key, @@ -403,7 +387,7 @@ create table one ( col_c serial ); -create index "one_idx" on one using btree (col_b); +create index one_idx on one using btree (col_b); create table two (col_c int check (col_c > 0) references one default 42); @@ -469,7 +453,7 @@ drop table a_temp_tbl; create or replace function event_trigger_report_dropped() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE r record; BEGIN FOR r IN SELECT * from pg_event_trigger_dropped_objects() @@ -479,17 +463,15 @@ BEGIN r.object_identity, r.schema_name, r.object_name, r.address_names, r.address_args; END LOOP; -END; -$function$; +END; $$; create function event_trigger_dummy_trigger() returns trigger language plpgsql -as $function$ +as $$ BEGIN RETURN new; -END; -$function$; +END; $$; create table evtrg_nontemp_table ( f1 int primary key, @@ -544,20 +526,20 @@ select pg_event_trigger_table_rewrite_oid(); create or replace function test_evtrig_no_rewrite() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE EXCEPTION 'rewrites not allowed'; END; -$function$; +$$; -create event trigger "no_rewrite_allowed" +create event trigger no_rewrite_allowed on table_rewrite execute function test_evtrig_no_rewrite(); create table rewriteme ( id serial primary key, foo double precision, - bar timestamp with time zone + bar timestamptz ); insert into rewriteme select x * 1.001 from generate_series(1, 500) as t (x); @@ -571,13 +553,13 @@ alter table rewriteme create or replace function test_evtrig_no_rewrite() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'Table ''%'' is being rewritten (reason = %)', pg_event_trigger_table_rewrite_oid()::regclass, pg_event_trigger_table_rewrite_reason(); END; -$function$; +$$; alter table rewriteme add column onemore int default 0, @@ -596,7 +578,7 @@ alter table rewriteme begin; -set time zone UTC; +set time zone 'UTC'; alter table rewriteme alter column bar type timestamp; @@ -604,7 +586,7 @@ alter table rewriteme set time zone '0'; alter table rewriteme - alter column bar type timestamp with time zone; + alter column bar type timestamptz; set time zone 'Europe/London'; @@ -616,12 +598,12 @@ rollback; create or replace function test_evtrig_no_rewrite() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'Table is being rewritten (reason = %)', pg_event_trigger_table_rewrite_reason(); END; -$function$; +$$; create type rewritetype as (a int); @@ -646,21 +628,21 @@ drop function test_evtrig_no_rewrite(); create or replace function reindex_start_command() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'REINDEX START: % %', tg_event, tg_tag; END; -$function$; +$$; -create event trigger "regress_reindex_start" +create event trigger regress_reindex_start on ddl_command_start -when TAG in ('REINDEX') +when tag in ('REINDEX') execute function reindex_start_command(); create function reindex_end_command() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE obj record; BEGIN @@ -670,67 +652,65 @@ BEGIN obj.command_tag, obj.object_type, obj.object_identity; END LOOP; END; -$function$; +$$; -create event trigger "regress_reindex_end" +create event trigger regress_reindex_end on ddl_command_end -when TAG in ('REINDEX') +when tag in ('REINDEX') execute function reindex_end_command(); create function reindex_end_command_snap() returns event_trigger language plpgsql -as $function$ -BEGIN PERFORM 1; END -$function$; +as $$ BEGIN PERFORM 1; END $$; -create event trigger "regress_reindex_end_snap" +create event trigger regress_reindex_end_snap on ddl_command_end execute function reindex_end_command_snap(); create table concur_reindex_tab (c1 int); -create index "concur_reindex_ind" on concur_reindex_tab using btree (c1); +create index concur_reindex_ind on concur_reindex_tab using btree (c1); reindex index concur_reindex_ind; reindex table concur_reindex_tab; -reindex (CONCURRENTLY) index concur_reindex_ind; +reindex (concurrently) index concur_reindex_ind; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; alter event trigger regress_reindex_start disable; reindex index concur_reindex_ind; -reindex (CONCURRENTLY) index concur_reindex_ind; +reindex (concurrently) index concur_reindex_ind; drop index concur_reindex_ind; reindex table concur_reindex_tab; -reindex (CONCURRENTLY) table concur_reindex_tab; +reindex (concurrently) table concur_reindex_tab; -create schema "concur_reindex_schema"; +create schema concur_reindex_schema; reindex schema concur_reindex_schema; -reindex (CONCURRENTLY) schema concur_reindex_schema; +reindex (concurrently) schema concur_reindex_schema; create table concur_reindex_schema.tab (a int); -create index "ind" on concur_reindex_schema.tab using btree (a); +create index ind on concur_reindex_schema.tab using btree (a); reindex schema concur_reindex_schema; -reindex (CONCURRENTLY) schema concur_reindex_schema; +reindex (concurrently) schema concur_reindex_schema; drop index concur_reindex_schema.ind; reindex schema concur_reindex_schema; -reindex (CONCURRENTLY) schema concur_reindex_schema; +reindex (concurrently) schema concur_reindex_schema; drop schema concur_reindex_schema cascade; @@ -739,7 +719,7 @@ partition by range(id); reindex table concur_reindex_part; -reindex (CONCURRENTLY) table concur_reindex_part; +reindex (concurrently) table concur_reindex_part; create table concur_reindex_child partition of concur_reindex_part @@ -747,17 +727,17 @@ for values from (0) to (10); reindex table concur_reindex_part; -reindex (CONCURRENTLY) table concur_reindex_part; +reindex (concurrently) table concur_reindex_part; -create index "concur_reindex_partidx" on concur_reindex_part using btree (id); +create index concur_reindex_partidx on concur_reindex_part using btree (id); reindex index concur_reindex_partidx; -reindex (CONCURRENTLY) index concur_reindex_partidx; +reindex (concurrently) index concur_reindex_partidx; reindex table concur_reindex_part; -reindex (CONCURRENTLY) table concur_reindex_part; +reindex (concurrently) table concur_reindex_part; drop table concur_reindex_part; @@ -785,43 +765,43 @@ create table event_trigger_test ( create or replace function start_command() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE '% - ddl_command_start', tg_tag; END; -$function$; +$$; create or replace function end_command() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE '% - ddl_command_end', tg_tag; END; -$function$; +$$; create or replace function drop_sql_command() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE '% - sql_drop', tg_tag; END; -$function$; +$$; -create event trigger "start_rls_command" +create event trigger start_rls_command on ddl_command_start -when TAG in ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') +when tag in ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') execute function start_command(); -create event trigger "end_rls_command" +create event trigger end_rls_command on ddl_command_end -when TAG in ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') +when tag in ('CREATE POLICY', 'ALTER POLICY', 'DROP POLICY') execute function end_command(); -create event trigger "sql_drop_command" +create event trigger sql_drop_command on sql_drop -when TAG in ('DROP POLICY') +when tag in ('DROP POLICY') execute function drop_sql_command(); create policy p1 @@ -839,21 +819,11 @@ drop policy p2 on event_trigger_test; select e.evtname, - pg_describe_object( - cast('pg_event_trigger' as regclass), - e.oid, - 0 - ) - as descr, + pg_describe_object(cast('pg_event_trigger' as regclass), e.oid, 0) as descr, b.type, b.object_names, b.object_args, - pg_identify_object( - a.classid, - a.objid, - a.objsubid - ) - as ident + pg_identify_object(a.classid, a.objid, a.objsubid) as ident from pg_event_trigger as e, lateral pg_identify_object_as_address( @@ -862,12 +832,7 @@ from 0 ) as b, - lateral pg_get_object_address( - b.type, - b.object_names, - b.object_args - ) - as a + lateral pg_get_object_address(b.type, b.object_names, b.object_args) as a order by e.evtname; drop event trigger start_rls_command; @@ -879,7 +844,7 @@ drop event trigger sql_drop_command; create function test_event_trigger_guc() returns event_trigger language plpgsql -as $function$ +as $$ DECLARE obj record; BEGIN @@ -888,11 +853,11 @@ BEGIN RAISE NOTICE '% dropped %', tg_tag, obj.object_type; END LOOP; END; -$function$; +$$; -create event trigger "test_event_trigger_guc" +create event trigger test_event_trigger_guc on sql_drop -when TAG in ('DROP POLICY') +when tag in ('DROP POLICY') execute function test_event_trigger_guc(); set event_triggers = 'on'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_login_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_login_100.snap index 68e9b7197..e8276b54e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_login_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_login_100.snap @@ -7,25 +7,25 @@ create table user_logins ( who text ); -grant SELECT on table user_logins to public; +grant select on table user_logins to public; create function on_login_proc() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN INSERT INTO user_logins (who) VALUES (SESSION_USER); RAISE NOTICE 'You are welcome!'; END; -$function$; +$$; -create event trigger "on_login_trigger" on login execute function on_login_proc(); +create event trigger on_login_trigger on login execute function on_login_proc(); alter event trigger on_login_trigger enable always; -select COUNT(*) from user_logins; +select count(*) from user_logins; -select COUNT(*) from user_logins; +select count(*) from user_logins; select dathasloginevt from pg_database where datname = 'DBNAME'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_login_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_login_80.snap index 8cbf9c7ac..e8276b54e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_login_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__event_trigger_login_80.snap @@ -7,27 +7,25 @@ create table user_logins ( who text ); -grant SELECT on table user_logins to public; +grant select on table user_logins to public; create function on_login_proc() returns event_trigger language plpgsql -as $function$ +as $$ BEGIN INSERT INTO user_logins (who) VALUES (SESSION_USER); RAISE NOTICE 'You are welcome!'; END; -$function$; +$$; -create event trigger "on_login_trigger" -on login -execute function on_login_proc(); +create event trigger on_login_trigger on login execute function on_login_proc(); alter event trigger on_login_trigger enable always; -select COUNT(*) from user_logins; +select count(*) from user_logins; -select COUNT(*) from user_logins; +select count(*) from user_logins; select dathasloginevt from pg_database where datname = 'DBNAME'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_100.snap index 1ba9384ee..8fd0248b6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_100.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/explain.sql create function explain_filter(text) returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin @@ -24,12 +24,12 @@ begin return next ln; end loop; end; -$function$; +$$; create function explain_filter_to_json(text) returns jsonb language plpgsql -as $function$ +as $$ declare data text := ''; ln text; @@ -42,7 +42,7 @@ begin end loop; return data::jsonb; end; -$function$; +$$; set jit = off; @@ -59,9 +59,7 @@ select explain_filter('explain (analyze, buffers, format text) select * from int select explain_filter('explain (analyze, buffers, format xml) select * from int8_tbl i8'); select - explain_filter( - 'explain (analyze, serialize, buffers, format yaml) select * from int8_tbl i8' - ); + explain_filter('explain (analyze, serialize, buffers, format yaml) select * from int8_tbl i8'); select explain_filter('explain (buffers, format text) select * from int8_tbl i8'); @@ -90,18 +88,12 @@ set local plan_cache_mode = force_generic_plan; select true as "OK" from - explain_filter( - 'explain (settings) select * from int8_tbl i8' - ) - as ln + explain_filter('explain (settings) select * from int8_tbl i8') as ln where - ln ~ - '^ *Settings: .*plan_cache_mode = ''force_generic_plan'''; + ln ~ '^ *Settings: .*plan_cache_mode = ''force_generic_plan'''; select - explain_filter_to_json( - 'explain (settings, format json) select * from int8_tbl i8' - ) #> + explain_filter_to_json('explain (settings, format json) select * from int8_tbl i8') #> '{0,Settings,plan_cache_mode}'; rollback; @@ -109,9 +101,7 @@ rollback; select explain_filter('explain (generic_plan) select unique1 from tenk1 where thousand = $1'); select - explain_filter( - 'explain (analyze, generic_plan) select unique1 from tenk1 where thousand = $1' - ); + explain_filter('explain (analyze, generic_plan) select unique1 from tenk1 where thousand = $1'); select explain_filter('explain (memory) select * from int8_tbl i8'); @@ -129,7 +119,7 @@ create table gen_part ( key1 int not null, key2 int not null ) -partition by LIST(key1); +partition by list(key1); create table gen_part_1 partition of gen_part for values in (1) partition by range(key2); @@ -156,28 +146,17 @@ set min_parallel_table_scan_size = 0; set max_parallel_workers_per_gather = 4; -select - jsonb_pretty( - explain_filter_to_json( - 'explain (analyze, verbose, buffers, format json) - select * from tenk1 order by tenthous' - ) #- - '{0,Plan,Plans,0,Plans,0,Workers}' #- - '{0,Plan,Plans,0,Workers}' #- - '{0,Plan,Plans,0,Sort Method}' #- - '{0,Plan,Plans,0,Sort Space Type}' - ); +select jsonb_pretty(explain_filter_to_json('explain (analyze, verbose, buffers, format json) + select * from tenk1 order by tenthous') #- '{0,Plan,Plans,0,Plans,0,Workers}' #- '{0,Plan,Plans,0,Workers}' #- '{0,Plan,Plans,0,Sort Method}' #- '{0,Plan,Plans,0,Sort Space Type}'); rollback; -create temporary table t1 (f1 double precision); +create temporary table t1 (f1 float8); -create function pg_temp.mysin(double precision) -returns double precision +create function pg_temp.mysin(float8) +returns float8 language plpgsql -as $function$ -begin return sin($1); end -$function$; +as 'begin return sin($1); end'; select explain_filter('explain (verbose) select * from t1 where pg_temp.mysin(f1) < 0.5'); @@ -192,14 +171,10 @@ select explain_filter('explain (verbose) create table test_ctas as select 1'); select explain_filter('explain (analyze,buffers off,serialize) select * from int8_tbl i8'); select - explain_filter( - 'explain (analyze,serialize text,buffers,timing off) select * from int8_tbl i8' - ); + explain_filter('explain (analyze,serialize text,buffers,timing off) select * from int8_tbl i8'); select - explain_filter( - 'explain (analyze,serialize binary,buffers,timing) select * from int8_tbl i8' - ); + explain_filter('explain (analyze,serialize binary,buffers,timing) select * from int8_tbl i8'); select explain_filter( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_80.snap index a071fd0cb..8d49aab3a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_80.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/explain.sql create function explain_filter(text) returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin @@ -24,12 +24,12 @@ begin return next ln; end loop; end; -$function$; +$$; create function explain_filter_to_json(text) returns jsonb language plpgsql -as $function$ +as $$ declare data text := ''; ln text; @@ -42,7 +42,7 @@ begin end loop; return data::jsonb; end; -$function$; +$$; set jit = off; @@ -51,9 +51,7 @@ set track_io_timing = off; select explain_filter('explain select * from int8_tbl i8'); select - explain_filter( - 'explain (analyze, buffers off) select * from int8_tbl i8' - ); + explain_filter('explain (analyze, buffers off) select * from int8_tbl i8'); select explain_filter( @@ -76,14 +74,10 @@ select ); select - explain_filter( - 'explain (buffers, format text) select * from int8_tbl i8' - ); + explain_filter('explain (buffers, format text) select * from int8_tbl i8'); select - explain_filter( - 'explain (buffers, format json) select * from int8_tbl i8' - ); + explain_filter('explain (buffers, format json) select * from int8_tbl i8'); select explain_filter( @@ -111,13 +105,9 @@ set local plan_cache_mode = force_generic_plan; select true as "OK" from - explain_filter( - 'explain (settings) select * from int8_tbl i8' - ) - as ln + explain_filter('explain (settings) select * from int8_tbl i8') as ln where - ln ~ - '^ *Settings: .*plan_cache_mode = ''force_generic_plan'''; + ln ~ '^ *Settings: .*plan_cache_mode = ''force_generic_plan'''; select explain_filter_to_json( @@ -162,7 +152,7 @@ create table gen_part ( key1 int not null, key2 int not null ) -partition by LIST(key1); +partition by list(key1); create table gen_part_1 partition of gen_part @@ -194,26 +184,18 @@ set max_parallel_workers_per_gather = 4; select jsonb_pretty( - explain_filter_to_json( - 'explain (analyze, verbose, buffers, format json) - select * from tenk1 order by tenthous' - ) #- - '{0,Plan,Plans,0,Plans,0,Workers}' #- - '{0,Plan,Plans,0,Workers}' #- - '{0,Plan,Plans,0,Sort Method}' #- - '{0,Plan,Plans,0,Sort Space Type}' + explain_filter_to_json('explain (analyze, verbose, buffers, format json) + select * from tenk1 order by tenthous') #- '{0,Plan,Plans,0,Plans,0,Workers}' #- '{0,Plan,Plans,0,Workers}' #- '{0,Plan,Plans,0,Sort Method}' #- '{0,Plan,Plans,0,Sort Space Type}' ); rollback; -create temporary table t1 (f1 double precision); +create temporary table t1 (f1 float8); -create function pg_temp.mysin(double precision) -returns double precision +create function pg_temp.mysin(float8) +returns float8 language plpgsql -as $function$ -begin return sin($1); end -$function$; +as 'begin return sin($1); end'; select explain_filter( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_100.snap index 686e22636..a88757c44 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_100.snap @@ -2,21 +2,21 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/expressions.sql --- -select cast(date(NOW()) as text) = cast(current_date as text); +select cast(date(now()) as text) = cast(current_date as text); -select cast(cast(NOW() as time with time zone) as text) = cast(current_time as text); +select cast(cast(now() as timetz) as text) = cast(current_time as text); -select cast(cast(NOW() as time(4) with time zone) as text) = cast(current_time(4) as text); +select cast(cast(now() as timetz(4)) as text) = cast(current_time(4) as text); -select cast(cast(NOW() as time) as text) = cast(localtime as text); +select cast(cast(now() as time) as text) = cast(localtime as text); -select cast(cast(NOW() as time(3)) as text) = cast(localtime(3) as text); +select cast(cast(now() as time(3)) as text) = cast(localtime(3) as text); -select current_timestamp = NOW(); +select current_timestamp = now(); select length(cast(current_timestamp as text)) >= length(cast(current_timestamp(0) as text)); -select cast(cast(NOW() as timestamp) as text) = cast(localtimestamp as text); +select cast(cast(now() as timestamp) as text) = cast(localtimestamp as text); select current_time = current_time(7); @@ -92,21 +92,21 @@ create function return_int_input(int) returns int language plpgsql stable -as $function$ +as $$ begin return $1; end; -$function$; +$$; create function return_text_input(text) returns text language plpgsql stable -as $function$ +as $$ begin return $1; end; -$function$; +$$; select return_int_input(1) in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1); @@ -131,10 +131,7 @@ select return_int_input(1) not in (10, 9, 2, 8, 3, 7, 4, 6, 5, 2, null); select return_int_input(1) not in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1, null); select - return_int_input(1) - not in ( - null, null, null, null, null, null, null, null, null, null, null - ); + return_int_input(1) not in (null, null, null, null, null, null, null, null, null, null, null); select return_int_input(cast(null as int)) not in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1); @@ -153,39 +150,33 @@ returns myint language internal immutable strict -as $function$ -int4in -$function$; +as 'int4in'; create function myintout(myint) returns cstring language internal immutable strict -as $function$ -int4out -$function$; +as 'int4out'; create function myinthash(myint) returns int language internal immutable strict -as $function$ -hashint4 -$function$; +as 'hashint4'; -create type myint (input = myintin, output = myintout, like = int); +create type myint (input = myintin, output = myintout, "like" = int4); -create cast (int as myint) without function; +create cast (int4 as myint) without function; -create cast (myint as int) without function; +create cast (myint as int4) without function; create function myinteq(myint, myint) -returns boolean +returns bool language plpgsql immutable -as $function$ +as $$ begin if $1 is null and $2 is null then return true; @@ -193,35 +184,39 @@ begin return $1::int = $2::int; end if; end; -$function$; +$$; create function myintne(myint, myint) -returns boolean +returns bool language plpgsql immutable -as $function$ +as $$ begin return not myinteq($1, $2); end; -$function$; - -create operator = (LEFTARG = myint, -RIGHTARG = myint, -COMMUTATOR = =, -NEGATOR = <>, -PROCEDURE = myinteq, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); - -create operator <> (LEFTARG = myint, -RIGHTARG = myint, -COMMUTATOR = <>, -NEGATOR = =, -PROCEDURE = myintne, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +$$; + +create operator = ( + leftarg = myint, + rightarg = myint, + commutator = =, + negator = <>, + procedure = myinteq, + restrict = eqsel, + join = eqjoinsel, + merges +); + +create operator <> ( + leftarg = myint, + rightarg = myint, + commutator = <>, + negator = =, + procedure = myintne, + restrict = eqsel, + join = eqjoinsel, + merges +); create operator class myint_ops default for type myint diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_80.snap index 482407ac4..24a20099e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_80.snap @@ -2,31 +2,23 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/expressions.sql --- -select cast(date(NOW()) as text) = cast(current_date as text); +select cast(date(now()) as text) = cast(current_date as text); -select - cast(cast(NOW() as time with time zone) - as text) = - cast(current_time as text); +select cast(cast(now() as timetz) as text) = cast(current_time as text); -select - cast(cast(NOW() as time(4) with time zone) - as text) = - cast(current_time(4) as text); +select cast(cast(now() as timetz(4)) as text) = cast(current_time(4) as text); -select cast(cast(NOW() as time) as text) = cast(localtime as text); +select cast(cast(now() as time) as text) = cast(localtime as text); -select cast(cast(NOW() as time(3)) as text) = cast(localtime(3) as text); +select cast(cast(now() as time(3)) as text) = cast(localtime(3) as text); -select current_timestamp = NOW(); +select current_timestamp = now(); select length(cast(current_timestamp as text)) >= - length( - cast(current_timestamp(0) as text) - ); + length(cast(current_timestamp(0) as text)); -select cast(cast(NOW() as timestamp) as text) = cast(localtimestamp as text); +select cast(cast(now() as timestamp) as text) = cast(localtimestamp as text); select current_time = current_time(7); @@ -102,21 +94,21 @@ create function return_int_input(int) returns int language plpgsql stable -as $function$ +as $$ begin return $1; end; -$function$; +$$; create function return_text_input(text) returns text language plpgsql stable -as $function$ +as $$ begin return $1; end; -$function$; +$$; select return_int_input(1) in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1); @@ -133,16 +125,10 @@ select return_int_input(1) in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1, null); select return_int_input(cast(null as int)) in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1); select - return_int_input(cast(null as int)) - in ( - 10, 9, 2, 8, 3, 7, 4, 6, 5, null - ); + return_int_input(cast(null as int)) in (10, 9, 2, 8, 3, 7, 4, 6, 5, null); select - return_text_input('a') - in ( - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' - ); + return_text_input('a') in ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'); select return_int_input(1) not in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1); @@ -159,16 +145,10 @@ select ); select - return_int_input(cast(null as int)) - not in ( - 10, 9, 2, 8, 3, 7, 4, 6, 5, 1 - ); + return_int_input(cast(null as int)) not in (10, 9, 2, 8, 3, 7, 4, 6, 5, 1); select - return_int_input(cast(null as int)) - not in ( - 10, 9, 2, 8, 3, 7, 4, 6, 5, null - ); + return_int_input(cast(null as int)) not in (10, 9, 2, 8, 3, 7, 4, 6, 5, null); select return_text_input('a') @@ -187,39 +167,33 @@ returns myint language internal immutable strict -as $function$ -int4in -$function$; +as 'int4in'; create function myintout(myint) returns cstring language internal immutable strict -as $function$ -int4out -$function$; +as 'int4out'; create function myinthash(myint) returns int language internal immutable strict -as $function$ -hashint4 -$function$; +as 'hashint4'; -create type myint (input = myintin, output = myintout, like = int); +create type myint (input = myintin, output = myintout, "like" = int4); -create cast (int as myint) without function; +create cast (int4 as myint) without function; -create cast (myint as int) without function; +create cast (myint as int4) without function; create function myinteq(myint, myint) -returns boolean +returns bool language plpgsql immutable -as $function$ +as $$ begin if $1 is null and $2 is null then return true; @@ -227,35 +201,39 @@ begin return $1::int = $2::int; end if; end; -$function$; +$$; create function myintne(myint, myint) -returns boolean +returns bool language plpgsql immutable -as $function$ +as $$ begin return not myinteq($1, $2); end; -$function$; - -create operator = (LEFTARG = myint, -RIGHTARG = myint, -COMMUTATOR = =, -NEGATOR = <>, -PROCEDURE = myinteq, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); - -create operator <> (LEFTARG = myint, -RIGHTARG = myint, -COMMUTATOR = <>, -NEGATOR = =, -PROCEDURE = myintne, -RESTRICT = eqsel, -JOIN = eqjoinsel, -MERGES); +$$; + +create operator = ( + leftarg = myint, + rightarg = myint, + commutator = =, + negator = <>, + procedure = myinteq, + restrict = eqsel, + join = eqjoinsel, + merges +); + +create operator <> ( + leftarg = myint, + rightarg = myint, + commutator = <>, + negator = =, + procedure = myintne, + restrict = eqsel, + join = eqjoinsel, + merges +); create operator class myint_ops default for type myint diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_100.snap index fb3cb1520..cd0272251 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_100.snap @@ -4,7 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/fast_default.sql --- set search_path to fast_default; -create schema "fast_default"; +create schema fast_default; create table m (id oid); @@ -13,7 +13,7 @@ insert into m values (cast(null as oid)); create function set(tabname name) returns void language plpgsql -as $function$ +as $$ BEGIN UPDATE m SET id = (SELECT c.relfilenode @@ -22,12 +22,12 @@ BEGIN AND c.relnamespace = s.oid AND s.nspname = 'fast_default'); END; -$function$; +$$; create function comp() returns text language plpgsql -as $function$ +as $$ BEGIN RETURN (SELECT CASE WHEN m.id = c.relfilenode THEN 'Unchanged' @@ -38,12 +38,13 @@ BEGIN AND c.relnamespace = s.oid AND s.nspname = 'fast_default'); END; -$function$; +$$; create function log_rewrite() returns event_trigger language plpgsql -as $function$ +as $func$ + declare this_schema text; begin @@ -57,11 +58,11 @@ begin pg_event_trigger_table_rewrite_reason(); end if; end; -$function$; +$func$; create table has_volatile as select * from generate_series(1, 10) as id; -create event trigger "has_volatile_rewrite" on table_rewrite execute function log_rewrite(); +create event trigger has_volatile_rewrite on table_rewrite execute function log_rewrite(); alter table has_volatile add column col1 int; @@ -70,14 +71,13 @@ alter table has_volatile add column col2 int default 1; alter table has_volatile - add column col3 timestamp with time zone - default current_timestamp; + add column col3 timestamptz default current_timestamp; alter table has_volatile add column col4 int default cast(random() * 10000 as int); alter table has_volatile - alter column col5 type double precision; + alter column col5 type float8; alter table has_volatile alter column col5 type numeric; @@ -98,7 +98,7 @@ select set('t'); insert into t values (1), (2); alter table t - add column c_bpchar char(5) default 'hello', + add column c_bpchar bpchar(5) default 'hello', alter column c_int set default 2; insert into t values (3), (4); @@ -116,16 +116,14 @@ alter table t insert into t values (7), (8); alter table t - add column c_timestamp timestamp - default '2016-09-01 12:00:00', + add column c_timestamp timestamp default '2016-09-01 12:00:00', add column c_timestamp_null timestamp, alter column c_date set default '2010-01-01'; insert into t values (9), (10); alter table t - add column c_array text[] - default '{"This", "is", "the", "real", "world"}', + add column c_array text[] default '{"This", "is", "the", "real", "world"}', alter column c_timestamp set default '1970-12-31 11:12:13', alter column c_timestamp_null set default '2016-09-29 12:00:00'; @@ -204,10 +202,8 @@ select c_num, c_time, c_interval, - c_hugetext = repeat('abcdefg', 1000) - as c_hugetext_origdef, - c_hugetext = repeat('poiuyt', 1000) - as c_hugetext_newdef + c_hugetext = repeat('abcdefg', 1000) as c_hugetext_origdef, + c_hugetext = repeat('poiuyt', 1000) as c_hugetext_newdef from t order by pk; @@ -220,7 +216,7 @@ create or replace function foo(a int) returns text language plpgsql stable -as $function$ +as $$ DECLARE res TEXT := ''; i INT; BEGIN @@ -230,8 +226,7 @@ BEGIN i := i + 1; END LOOP; RETURN res; -END; -$function$; +END; $$; create table t ( pk int not null primary key, @@ -243,7 +238,7 @@ select set('t'); insert into t values (1), (2); alter table t - add column c_bpchar char(5) default foo(4), + add column c_bpchar bpchar(5) default foo(4), alter column c_int set default length(foo(8)); insert into t values (3), (4); @@ -255,32 +250,27 @@ alter table t insert into t values (5), (6); alter table t - add column c_date date - default (cast('2016-06-02' as date) + length(foo(10))), + add column c_date date default (cast('2016-06-02' as date) + length(foo(10))), alter column c_text set default foo(12); insert into t values (7), (8); alter table t - add column c_timestamp timestamp - default (cast('2016-09-01' as date) + length(foo(10))), + add column c_timestamp timestamp default (cast('2016-09-01' as date) + length(foo(10))), alter column c_date set default cast('2010-01-01' as date) - length(foo(4)); insert into t values (9), (10); alter table t add column c_array text[] - default cast('{"This", "is", "' || foo(4) || - '","the", "real", "world"}' - as text[]), + default cast('{"This", "is", "' || foo(4) || '","the", "real", "world"}' as text[]), alter column c_timestamp set default cast('1970-12-31' as date) + length(foo(30)); insert into t values (11), (12); alter table t alter column c_int drop default, - alter column c_array set default cast('{"This", "is", "' || foo(1) || '", "fantasy"}' - as text[]); + alter column c_array set default cast('{"This", "is", "' || foo(1) || '", "fantasy"}' as text[]); insert into t values (13), (14); @@ -301,14 +291,12 @@ drop table t; create domain domain1 as int default 11; -create domain domain2 as int default random("min" := 10, "max" := 100); +create domain domain2 as int default random(min := 10, max := 100); create domain domain3 as text default foo(4); create domain domain4 as text[] - default cast('{"This", "is", "' || foo(4) || - '","the", "real", "world"}' - as text[]); + default cast('{"This", "is", "' || foo(4) || '","the", "real", "world"}' as text[]); create table t2 (a domain1); @@ -383,7 +371,7 @@ insert into t values (1); select set('t'); alter table t - add column c1 timestamp default NOW(); + add column c1 timestamp default now(); select comp(); @@ -392,16 +380,14 @@ alter table t select comp(); -create function foolme(timestamp with time zone default clock_timestamp()) -returns timestamp with time zone +create function foolme(timestamptz default clock_timestamp()) +returns timestamptz language sql immutable -as $function$ -select $1 -$function$; +as 'select $1'; alter table t - add column c3 timestamp with time zone default foolme(); + add column c3 timestamptz default foolme(); select attname, @@ -415,7 +401,7 @@ order by attnum; drop table t; -drop function foolme(timestamp with time zone); +drop function foolme(timestamptz); create table t (pk int not null primary key); @@ -443,7 +429,7 @@ select c_bigint, c_text from t where c_text = 'hello' limit 1; select coalesce(c_bigint, pk), coalesce(c_text, cast(pk as text)) from t order by pk limit 10; -select SUM(c_bigint), MAX(c_text collate "C"), MIN(c_text collate "C") from t; +select sum(c_bigint), max(c_text collate "C"), min(c_text collate "C") from t; select * from t order by c_bigint, c_text, pk limit 10; @@ -489,7 +475,7 @@ insert into t values (7), (8); select * from t order by pk; -create index "i" on t using btree (c_int, c_text); +create index i on t using btree (c_int, c_text); select c_text from t where c_int = -1; @@ -502,10 +488,12 @@ alter table t1 select a, - stddev( - cast((select SUM(1) from generate_series(1, 20) as x) - as real) - ) over (partition by a, b, c order by b) as z + stddev(cast((select sum(1) from generate_series(1, 20) as x) as float4)) over ( + partition by a, + b, + c + order by b + ) as z from t1; @@ -514,7 +502,8 @@ drop table t; create function test_trigger() returns trigger language plpgsql -as $function$ +as $$ + begin raise notice 'old tuple: %', to_json(OLD)::text; if TG_OP = 'DELETE' @@ -524,7 +513,8 @@ begin return NEW; end if; end; -$function$; + +$$; create table t ( id serial primary key, @@ -732,7 +722,7 @@ create table leader ( ); create table follower ( - a int references leader on DELETE cascade, + a int references leader on delete cascade, b int ); @@ -817,14 +807,11 @@ alter foreign table ft1 alter column c8 type char(10); select - COUNT(*) + count(*) from pg_attribute where - attrelid = cast('ft1' as regclass) and - ( - attmissingval is not null or atthasmissing - ); + attrelid = cast('ft1' as regclass) and (attmissingval is not null or atthasmissing); drop foreign table ft1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_80.snap index 567a89c53..1af35acbd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_80.snap @@ -4,7 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/fast_default.sql --- set search_path to fast_default; -create schema "fast_default"; +create schema fast_default; create table m (id oid); @@ -13,7 +13,7 @@ insert into m values (cast(null as oid)); create function set(tabname name) returns void language plpgsql -as $function$ +as $$ BEGIN UPDATE m SET id = (SELECT c.relfilenode @@ -22,12 +22,12 @@ BEGIN AND c.relnamespace = s.oid AND s.nspname = 'fast_default'); END; -$function$; +$$; create function comp() returns text language plpgsql -as $function$ +as $$ BEGIN RETURN (SELECT CASE WHEN m.id = c.relfilenode THEN 'Unchanged' @@ -38,12 +38,13 @@ BEGIN AND c.relnamespace = s.oid AND s.nspname = 'fast_default'); END; -$function$; +$$; create function log_rewrite() returns event_trigger language plpgsql -as $function$ +as $func$ + declare this_schema text; begin @@ -57,11 +58,11 @@ begin pg_event_trigger_table_rewrite_reason(); end if; end; -$function$; +$func$; create table has_volatile as select * from generate_series(1, 10) as id; -create event trigger "has_volatile_rewrite" +create event trigger has_volatile_rewrite on table_rewrite execute function log_rewrite(); @@ -72,15 +73,13 @@ alter table has_volatile add column col2 int default 1; alter table has_volatile - add column col3 timestamp with time zone - default current_timestamp; + add column col3 timestamptz default current_timestamp; alter table has_volatile - add column col4 int - default cast(random() * 10000 as int); + add column col4 int default cast(random() * 10000 as int); alter table has_volatile - alter column col5 type double precision; + alter column col5 type float8; alter table has_volatile alter column col5 type numeric; @@ -101,7 +100,7 @@ select set('t'); insert into t values (1), (2); alter table t - add column c_bpchar char(5) default 'hello', + add column c_bpchar bpchar(5) default 'hello', alter column c_int set default 2; insert into t values (3), (4); @@ -119,16 +118,14 @@ alter table t insert into t values (7), (8); alter table t - add column c_timestamp timestamp - default '2016-09-01 12:00:00', + add column c_timestamp timestamp default '2016-09-01 12:00:00', add column c_timestamp_null timestamp, alter column c_date set default '2010-01-01'; insert into t values (9), (10); alter table t - add column c_array text[] - default '{"This", "is", "the", "real", "world"}', + add column c_array text[] default '{"This", "is", "the", "real", "world"}', alter column c_timestamp set default '1970-12-31 11:12:13', alter column c_timestamp_null set default '2016-09-29 12:00:00'; @@ -167,8 +164,7 @@ alter table t insert into t values (21), (22); alter table t - add column c_hugetext text - default repeat('abcdefg', 1000), + add column c_hugetext text default repeat('abcdefg', 1000), alter column c_interval set default '3 hours'; insert into t values (23), (24); @@ -208,10 +204,8 @@ select c_num, c_time, c_interval, - c_hugetext = repeat('abcdefg', 1000) - as c_hugetext_origdef, - c_hugetext = repeat('poiuyt', 1000) - as c_hugetext_newdef + c_hugetext = repeat('abcdefg', 1000) as c_hugetext_origdef, + c_hugetext = repeat('poiuyt', 1000) as c_hugetext_newdef from t order by pk; @@ -224,7 +218,7 @@ create or replace function foo(a int) returns text language plpgsql stable -as $function$ +as $$ DECLARE res TEXT := ''; i INT; BEGIN @@ -234,8 +228,7 @@ BEGIN i := i + 1; END LOOP; RETURN res; -END; -$function$; +END; $$; create table t ( pk int not null primary key, @@ -247,7 +240,7 @@ select set('t'); insert into t values (1), (2); alter table t - add column c_bpchar char(5) default foo(4), + add column c_bpchar bpchar(5) default foo(4), alter column c_int set default length(foo(8)); insert into t values (3), (4); @@ -259,27 +252,22 @@ alter table t insert into t values (5), (6); alter table t - add column c_date date - default (cast('2016-06-02' as date) + - length(foo(10))), + add column c_date date default (cast('2016-06-02' as date) + length(foo(10))), alter column c_text set default foo(12); insert into t values (7), (8); alter table t add column c_timestamp timestamp - default (cast('2016-09-01' as date) + - length(foo(10))), - alter column c_date set default cast('2010-01-01' as date) - - length(foo(4)); + default (cast('2016-09-01' as date) + length(foo(10))), + alter column c_date set default cast('2010-01-01' as date) - length(foo(4)); insert into t values (9), (10); alter table t add column c_array text[] - default cast('{"This", "is", "' || foo(4) || - '","the", "real", "world"}' - as text[]), + default cast('{"This", "is", "' || foo(4) || '","the", "real", "world"}' + as text[]), alter column c_timestamp set default cast('1970-12-31' as date) + length(foo(30)); @@ -310,13 +298,12 @@ drop table t; create domain domain1 as int default 11; -create domain domain2 as int default random("min" := 10, "max" := 100); +create domain domain2 as int default random(min := 10, max := 100); create domain domain3 as text default foo(4); create domain domain4 as text[] - default cast('{"This", "is", "' || foo(4) || - '","the", "real", "world"}' + default cast('{"This", "is", "' || foo(4) || '","the", "real", "world"}' as text[]); create table t2 (a domain1); @@ -335,13 +322,11 @@ select from pg_attribute where - attnum > 0 and - attrelid = cast('t2' as regclass) + attnum > 0 and attrelid = cast('t2' as regclass) order by attnum; alter table t2 - add column c domain3 - default left(cast(random() as text), 3); + add column c domain3 default left(cast(random() as text), 3); alter table t2 add column d domain4; @@ -355,8 +340,7 @@ select from pg_attribute where - attnum > 0 and - attrelid = cast('t2' as regclass) + attnum > 0 and attrelid = cast('t2' as regclass) order by attnum; alter table t2 @@ -371,8 +355,7 @@ select from pg_attribute where - attnum > 0 and - attrelid = cast('t2' as regclass) + attnum > 0 and attrelid = cast('t2' as regclass) order by attnum; select a, b, length(c) = 3 as c_ok, d, e >= 10 as e_ok from t2; @@ -396,7 +379,7 @@ insert into t values (1); select set('t'); alter table t - add column c1 timestamp default NOW(); + add column c1 timestamp default now(); select comp(); @@ -405,17 +388,14 @@ alter table t select comp(); -create function foolme(timestamp with time zone default clock_timestamp()) -returns timestamp with time zone +create function foolme(timestamptz default clock_timestamp()) +returns timestamptz language sql immutable -as $function$ -select $1 -$function$; +as 'select $1'; alter table t - add column c3 timestamp with time zone - default foolme(); + add column c3 timestamptz default foolme(); select attname, @@ -424,13 +404,12 @@ select from pg_attribute where - attrelid = cast('t' as regclass) and - attnum > 0 + attrelid = cast('t' as regclass) and attnum > 0 order by attnum; drop table t; -drop function foolme(timestamp with time zone); +drop function foolme(timestamptz); create table t (pk int not null primary key); @@ -447,12 +426,7 @@ alter table t add column c_text text default 'hello'; insert into t -select - b, - b - 10, - cast(b + 10 as text) -from - generate_series(21, 30) as a (b); +select b, b - 10, cast(b + 10 as text) from generate_series(21, 30) as a (b); select c_bigint, c_text from t where c_bigint = -1 limit 1; @@ -470,7 +444,7 @@ from order by pk limit 10; -select SUM(c_bigint), MAX(c_text collate "C"), MIN(c_text collate "C") from t; +select sum(c_bigint), max(c_text collate "C"), min(c_text collate "C") from t; select * from t order by c_bigint, c_text, pk limit 10; @@ -516,7 +490,7 @@ insert into t values (7), (8); select * from t order by pk; -create index "i" on t using btree (c_int, c_text); +create index i on t using btree (c_int, c_text); select c_text from t where c_int = -1; @@ -536,13 +510,7 @@ alter table t1 select a, stddev( - cast(( - select - SUM(1) - from - generate_series(1, 20) as x - ) - as real) + cast((select sum(1) from generate_series(1, 20) as x) as float4) ) over (partition by a, b, c order by b) as z from t1; @@ -552,7 +520,8 @@ drop table t; create function test_trigger() returns trigger language plpgsql -as $function$ +as $$ + begin raise notice 'old tuple: %', to_json(OLD)::text; if TG_OP = 'DELETE' @@ -562,7 +531,8 @@ begin return NEW; end if; end; -$function$; + +$$; create table t ( id serial primary key, @@ -802,8 +772,7 @@ create table leader ( ); create table follower ( - a int - references leader on DELETE cascade, + a int references leader on delete cascade, b int ); @@ -888,14 +857,13 @@ alter foreign table ft1 alter column c8 type char(10); select - COUNT(*) + count(*) from pg_attribute where attrelid = cast('ft1' as regclass) and ( - attmissingval is not null or - atthasmissing + attmissingval is not null or atthasmissing ); drop foreign table ft1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_100.snap index fcc192705..5c7cdd644 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/float4.sql --- -create table float4_tbl (f1 real); +create table float4_tbl (f1 float4); insert into float4_tbl (f1) values (' 0.0'); @@ -22,13 +22,13 @@ insert into float4_tbl (f1) values ('10e-70'); insert into float4_tbl (f1) values ('-10e-70'); -insert into float4_tbl (f1) values (cast('10e70' as double precision)); +insert into float4_tbl (f1) values (cast('10e70' as float8)); -insert into float4_tbl (f1) values (cast('-10e70' as double precision)); +insert into float4_tbl (f1) values (cast('-10e70' as float8)); -insert into float4_tbl (f1) values (cast('10e-70' as double precision)); +insert into float4_tbl (f1) values (cast('10e-70' as float8)); -insert into float4_tbl (f1) values (cast('-10e-70' as double precision)); +insert into float4_tbl (f1) values (cast('-10e-70' as float8)); insert into float4_tbl (f1) values ('10e400'); @@ -62,33 +62,33 @@ select pg_input_is_valid('1e400', 'float4'); select * from pg_input_error_info('1e400', 'float4'); -select cast('NaN' as real); +select cast('NaN' as float4); -select cast('nan' as real); +select cast('nan' as float4); -select cast(' NAN ' as real); +select cast(' NAN ' as float4); -select cast('infinity' as real); +select cast('infinity' as float4); -select cast(' -INFINiTY ' as real); +select cast(' -INFINiTY ' as float4); -select cast('N A N' as real); +select cast('N A N' as float4); -select cast('NaN x' as real); +select cast('NaN x' as float4); -select cast(' INFINITY x' as real); +select cast(' INFINITY x' as float4); -select cast('Infinity' as real) + 100.0; +select cast('Infinity' as float4) + 100.0; -select cast('Infinity' as real) / cast('Infinity' as real); +select cast('Infinity' as float4) / cast('Infinity' as float4); -select cast('42' as real) / cast('Infinity' as real); +select cast('42' as float4) / cast('Infinity' as float4); -select cast('nan' as real) / cast('nan' as real); +select cast('nan' as float4) / cast('nan' as float4); -select cast('nan' as real) / cast('0' as real); +select cast('nan' as float4) / cast('0' as float4); -select cast(cast('nan' as numeric) as real); +select cast(cast('nan' as numeric) as float4); select * from float4_tbl; @@ -122,63 +122,63 @@ update float4_tbl set f1 = float4_tbl.f1 * '-1' where float4_tbl.f1 > '0.0'; select * from float4_tbl order by 1; -select cast(cast('32767.4' as real) as smallint); +select cast(cast('32767.4' as float4) as int2); -select cast(cast('32767.6' as real) as smallint); +select cast(cast('32767.6' as float4) as int2); -select cast(cast('-32768.4' as real) as smallint); +select cast(cast('-32768.4' as float4) as int2); -select cast(cast('-32768.6' as real) as smallint); +select cast(cast('-32768.6' as float4) as int2); -select cast(cast('2147483520' as real) as int); +select cast(cast('2147483520' as float4) as int4); -select cast(cast('2147483647' as real) as int); +select cast(cast('2147483647' as float4) as int4); -select cast(cast('-2147483648.5' as real) as int); +select cast(cast('-2147483648.5' as float4) as int4); -select cast(cast('-2147483900' as real) as int); +select cast(cast('-2147483900' as float4) as int4); -select cast(cast('9223369837831520256' as real) as bigint); +select cast(cast('9223369837831520256' as float4) as int8); -select cast(cast('9223372036854775807' as real) as bigint); +select cast(cast('9223372036854775807' as float4) as int8); -select cast(cast('-9223372036854775808.5' as real) as bigint); +select cast(cast('-9223372036854775808.5' as float4) as int8); -select cast(cast('-9223380000000000000' as real) as bigint); +select cast(cast('-9223380000000000000' as float4) as int8); -select float4send(cast('5e-20' as real)); +select float4send(cast('5e-20' as float4)); -select float4send(cast('67e14' as real)); +select float4send(cast('67e14' as float4)); -select float4send(cast('985e15' as real)); +select float4send(cast('985e15' as float4)); -select float4send(cast('55895e-16' as real)); +select float4send(cast('55895e-16' as float4)); -select float4send(cast('7038531e-32' as real)); +select float4send(cast('7038531e-32' as float4)); -select float4send(cast('702990899e-20' as real)); +select float4send(cast('702990899e-20' as float4)); -select float4send(cast('3e-23' as real)); +select float4send(cast('3e-23' as float4)); -select float4send(cast('57e18' as real)); +select float4send(cast('57e18' as float4)); -select float4send(cast('789e-35' as real)); +select float4send(cast('789e-35' as float4)); -select float4send(cast('2539e-18' as real)); +select float4send(cast('2539e-18' as float4)); -select float4send(cast('76173e28' as real)); +select float4send(cast('76173e28' as float4)); -select float4send(cast('887745e-11' as real)); +select float4send(cast('887745e-11' as float4)); -select float4send(cast('5382571e-37' as real)); +select float4send(cast('5382571e-37' as float4)); -select float4send(cast('82381273e-35' as real)); +select float4send(cast('82381273e-35' as float4)); -select float4send(cast('750486563e-38' as real)); +select float4send(cast('750486563e-38' as float4)); -select float4send(cast('1.17549435e-38' as real)); +select float4send(cast('1.17549435e-38' as float4)); -select float4send(cast('1.1754944e-38' as real)); +select float4send(cast('1.1754944e-38' as float4)); create type xfloat4; @@ -187,24 +187,20 @@ returns xfloat4 language internal immutable strict -as $function$ -int4in -$function$; +as 'int4in'; create function xfloat4out(xfloat4) returns cstring language internal immutable strict -as $function$ -int4out -$function$; +as 'int4out'; -create type xfloat4 (input = xfloat4in, output = xfloat4out, like = real); +create type xfloat4 (input = xfloat4in, output = xfloat4out, "like" = float4); -create cast (xfloat4 as real) without function; +create cast (xfloat4 as float4) without function; -create cast (real as xfloat4) without function; +create cast (float4 as xfloat4) without function; create cast (xfloat4 as int) without function; @@ -240,15 +236,7 @@ select float4send(flt) as ibits, flt from - ( - select - cast(cast(cast(bits as int) as xfloat4) as real) - as flt - from - testdata - offset 0 - ) - as s; + (select cast(cast(cast(bits as int) as xfloat4) as float4) as flt from testdata offset 0) as s; with testdata (bits) @@ -519,21 +507,10 @@ as ( select float4send(flt) as ibits, flt, - cast(cast(flt as text) as real) as r_flt, - float4send(cast(cast(flt as text) as real)) - as obits, - float4send(cast(cast(flt as text) as real)) = - float4send(flt) - as correct + cast(cast(flt as text) as float4) as r_flt, + float4send(cast(cast(flt as text) as float4)) as obits, + float4send(cast(cast(flt as text) as float4)) = float4send(flt) as correct from - ( - select - cast(cast(cast(bits as int) as xfloat4) as real) - as flt - from - testdata - offset 0 - ) - as s; + (select cast(cast(cast(bits as int) as xfloat4) as float4) as flt from testdata offset 0) as s; drop type xfloat4 cascade; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_80.snap index 0d355f581..b6f98fbad 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/float4.sql --- -create table float4_tbl (f1 real); +create table float4_tbl (f1 float4); insert into float4_tbl (f1) values (' 0.0'); @@ -22,13 +22,13 @@ insert into float4_tbl (f1) values ('10e-70'); insert into float4_tbl (f1) values ('-10e-70'); -insert into float4_tbl (f1) values (cast('10e70' as double precision)); +insert into float4_tbl (f1) values (cast('10e70' as float8)); -insert into float4_tbl (f1) values (cast('-10e70' as double precision)); +insert into float4_tbl (f1) values (cast('-10e70' as float8)); -insert into float4_tbl (f1) values (cast('10e-70' as double precision)); +insert into float4_tbl (f1) values (cast('10e-70' as float8)); -insert into float4_tbl (f1) values (cast('-10e-70' as double precision)); +insert into float4_tbl (f1) values (cast('-10e-70' as float8)); insert into float4_tbl (f1) values ('10e400'); @@ -62,33 +62,33 @@ select pg_input_is_valid('1e400', 'float4'); select * from pg_input_error_info('1e400', 'float4'); -select cast('NaN' as real); +select cast('NaN' as float4); -select cast('nan' as real); +select cast('nan' as float4); -select cast(' NAN ' as real); +select cast(' NAN ' as float4); -select cast('infinity' as real); +select cast('infinity' as float4); -select cast(' -INFINiTY ' as real); +select cast(' -INFINiTY ' as float4); -select cast('N A N' as real); +select cast('N A N' as float4); -select cast('NaN x' as real); +select cast('NaN x' as float4); -select cast(' INFINITY x' as real); +select cast(' INFINITY x' as float4); -select cast('Infinity' as real) + 100.0; +select cast('Infinity' as float4) + 100.0; -select cast('Infinity' as real) / cast('Infinity' as real); +select cast('Infinity' as float4) / cast('Infinity' as float4); -select cast('42' as real) / cast('Infinity' as real); +select cast('42' as float4) / cast('Infinity' as float4); -select cast('nan' as real) / cast('nan' as real); +select cast('nan' as float4) / cast('nan' as float4); -select cast('nan' as real) / cast('0' as real); +select cast('nan' as float4) / cast('0' as float4); -select cast(cast('nan' as numeric) as real); +select cast(cast('nan' as numeric) as float4); select * from float4_tbl; @@ -122,63 +122,63 @@ update float4_tbl set f1 = float4_tbl.f1 * '-1' where float4_tbl.f1 > '0.0'; select * from float4_tbl order by 1; -select cast(cast('32767.4' as real) as smallint); +select cast(cast('32767.4' as float4) as int2); -select cast(cast('32767.6' as real) as smallint); +select cast(cast('32767.6' as float4) as int2); -select cast(cast('-32768.4' as real) as smallint); +select cast(cast('-32768.4' as float4) as int2); -select cast(cast('-32768.6' as real) as smallint); +select cast(cast('-32768.6' as float4) as int2); -select cast(cast('2147483520' as real) as int); +select cast(cast('2147483520' as float4) as int4); -select cast(cast('2147483647' as real) as int); +select cast(cast('2147483647' as float4) as int4); -select cast(cast('-2147483648.5' as real) as int); +select cast(cast('-2147483648.5' as float4) as int4); -select cast(cast('-2147483900' as real) as int); +select cast(cast('-2147483900' as float4) as int4); -select cast(cast('9223369837831520256' as real) as bigint); +select cast(cast('9223369837831520256' as float4) as int8); -select cast(cast('9223372036854775807' as real) as bigint); +select cast(cast('9223372036854775807' as float4) as int8); -select cast(cast('-9223372036854775808.5' as real) as bigint); +select cast(cast('-9223372036854775808.5' as float4) as int8); -select cast(cast('-9223380000000000000' as real) as bigint); +select cast(cast('-9223380000000000000' as float4) as int8); -select float4send(cast('5e-20' as real)); +select float4send(cast('5e-20' as float4)); -select float4send(cast('67e14' as real)); +select float4send(cast('67e14' as float4)); -select float4send(cast('985e15' as real)); +select float4send(cast('985e15' as float4)); -select float4send(cast('55895e-16' as real)); +select float4send(cast('55895e-16' as float4)); -select float4send(cast('7038531e-32' as real)); +select float4send(cast('7038531e-32' as float4)); -select float4send(cast('702990899e-20' as real)); +select float4send(cast('702990899e-20' as float4)); -select float4send(cast('3e-23' as real)); +select float4send(cast('3e-23' as float4)); -select float4send(cast('57e18' as real)); +select float4send(cast('57e18' as float4)); -select float4send(cast('789e-35' as real)); +select float4send(cast('789e-35' as float4)); -select float4send(cast('2539e-18' as real)); +select float4send(cast('2539e-18' as float4)); -select float4send(cast('76173e28' as real)); +select float4send(cast('76173e28' as float4)); -select float4send(cast('887745e-11' as real)); +select float4send(cast('887745e-11' as float4)); -select float4send(cast('5382571e-37' as real)); +select float4send(cast('5382571e-37' as float4)); -select float4send(cast('82381273e-35' as real)); +select float4send(cast('82381273e-35' as float4)); -select float4send(cast('750486563e-38' as real)); +select float4send(cast('750486563e-38' as float4)); -select float4send(cast('1.17549435e-38' as real)); +select float4send(cast('1.17549435e-38' as float4)); -select float4send(cast('1.1754944e-38' as real)); +select float4send(cast('1.1754944e-38' as float4)); create type xfloat4; @@ -187,24 +187,20 @@ returns xfloat4 language internal immutable strict -as $function$ -int4in -$function$; +as 'int4in'; create function xfloat4out(xfloat4) returns cstring language internal immutable strict -as $function$ -int4out -$function$; +as 'int4out'; -create type xfloat4 (input = xfloat4in, output = xfloat4out, like = real); +create type xfloat4 (input = xfloat4in, output = xfloat4out, "like" = float4); -create cast (xfloat4 as real) without function; +create cast (xfloat4 as float4) without function; -create cast (real as xfloat4) without function; +create cast (float4 as xfloat4) without function; create cast (xfloat4 as int) without function; @@ -242,9 +238,7 @@ select from ( select - cast(cast(cast(bits as int) as xfloat4) - as real) - as flt + cast(cast(cast(bits as int) as xfloat4) as float4) as flt from testdata offset 0 @@ -520,22 +514,13 @@ as ( select float4send(flt) as ibits, flt, - cast(cast(flt as text) as real) as r_flt, - float4send( - cast(cast(flt as text) as real) - ) - as obits, - float4send( - cast(cast(flt as text) as real) - ) = - float4send(flt) - as correct + cast(cast(flt as text) as float4) as r_flt, + float4send(cast(cast(flt as text) as float4)) as obits, + float4send(cast(cast(flt as text) as float4)) = float4send(flt) as correct from ( select - cast(cast(cast(bits as int) as xfloat4) - as real) - as flt + cast(cast(cast(bits as int) as xfloat4) as float4) as flt from testdata offset 0 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_100.snap index 0312b6c9d..a689ac8d3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/float8.sql --- -create temporary table float8_tbl (f1 double precision); +create temporary table float8_tbl (f1 float8); insert into float8_tbl (f1) values (' 0.0 '); @@ -14,15 +14,15 @@ insert into float8_tbl (f1) values ('1.2345678901234e+200'); insert into float8_tbl (f1) values ('1.2345678901234e-200'); -select cast('10e400' as double precision); +select cast('10e400' as float8); -select cast('-10e400' as double precision); +select cast('-10e400' as float8); -select cast('10e-400' as double precision); +select cast('10e-400' as float8); -select cast('-10e-400' as double precision); +select cast('-10e-400' as float8); -select float8send(cast('2.2250738585072014E-308' as double precision)); +select float8send(cast('2.2250738585072014E-308' as float8)); insert into float8_tbl (f1) values (''); @@ -48,33 +48,33 @@ select pg_input_is_valid('1e4000', 'float8'); select * from pg_input_error_info('1e4000', 'float8'); -select cast('NaN' as double precision); +select cast('NaN' as float8); -select cast('nan' as double precision); +select cast('nan' as float8); -select cast(' NAN ' as double precision); +select cast(' NAN ' as float8); -select cast('infinity' as double precision); +select cast('infinity' as float8); -select cast(' -INFINiTY ' as double precision); +select cast(' -INFINiTY ' as float8); -select cast('N A N' as double precision); +select cast('N A N' as float8); -select cast('NaN x' as double precision); +select cast('NaN x' as float8); -select cast(' INFINITY x' as double precision); +select cast(' INFINITY x' as float8); -select cast('Infinity' as double precision) + 100.0; +select cast('Infinity' as float8) + 100.0; -select cast('Infinity' as double precision) / cast('Infinity' as double precision); +select cast('Infinity' as float8) / cast('Infinity' as float8); -select cast('42' as double precision) / cast('Infinity' as double precision); +select cast('42' as float8) / cast('Infinity' as float8); -select cast('nan' as double precision) / cast('nan' as double precision); +select cast('nan' as float8) / cast('nan' as float8); -select cast('nan' as double precision) / cast('0' as double precision); +select cast('nan' as float8) / cast('0' as float8); -select cast(cast('nan' as numeric) as double precision); +select cast(cast('nan' as numeric) as float8); select * from float8_tbl; @@ -116,88 +116,85 @@ select sign(f1) as sign_f1 from float8_tbl as f; set extra_float_digits = 0; -select sqrt(cast('64' as double precision)) as eight; +select sqrt(cast('64' as float8)) as eight; -select |/cast('64' as double precision) as eight; +select |/cast('64' as float8) as eight; select f.f1, |/f.f1 as sqrt_f1 from float8_tbl as f where f.f1 > '0.0'; -select power(cast('144' as double precision), cast('0.5' as double precision)); +select power(cast('144' as float8), cast('0.5' as float8)); -select power(cast('NaN' as double precision), cast('0.5' as double precision)); +select power(cast('NaN' as float8), cast('0.5' as float8)); -select power(cast('144' as double precision), cast('NaN' as double precision)); +select power(cast('144' as float8), cast('NaN' as float8)); -select power(cast('NaN' as double precision), cast('NaN' as double precision)); +select power(cast('NaN' as float8), cast('NaN' as float8)); -select power(cast('-1' as double precision), cast('NaN' as double precision)); +select power(cast('-1' as float8), cast('NaN' as float8)); -select power(cast('1' as double precision), cast('NaN' as double precision)); +select power(cast('1' as float8), cast('NaN' as float8)); -select power(cast('NaN' as double precision), cast('0' as double precision)); +select power(cast('NaN' as float8), cast('0' as float8)); -select power(cast('inf' as double precision), cast('0' as double precision)); +select power(cast('inf' as float8), cast('0' as float8)); -select power(cast('-inf' as double precision), cast('0' as double precision)); +select power(cast('-inf' as float8), cast('0' as float8)); -select power(cast('0' as double precision), cast('inf' as double precision)); +select power(cast('0' as float8), cast('inf' as float8)); -select power(cast('0' as double precision), cast('-inf' as double precision)); +select power(cast('0' as float8), cast('-inf' as float8)); -select power(cast('1' as double precision), cast('inf' as double precision)); +select power(cast('1' as float8), cast('inf' as float8)); -select power(cast('1' as double precision), cast('-inf' as double precision)); +select power(cast('1' as float8), cast('-inf' as float8)); -select power(cast('-1' as double precision), cast('inf' as double precision)); +select power(cast('-1' as float8), cast('inf' as float8)); -select power(cast('-1' as double precision), cast('-inf' as double precision)); +select power(cast('-1' as float8), cast('-inf' as float8)); -select power(cast('0.1' as double precision), cast('inf' as double precision)); +select power(cast('0.1' as float8), cast('inf' as float8)); -select power(cast('-0.1' as double precision), cast('inf' as double precision)); +select power(cast('-0.1' as float8), cast('inf' as float8)); -select power(cast('1.1' as double precision), cast('inf' as double precision)); +select power(cast('1.1' as float8), cast('inf' as float8)); -select power(cast('-1.1' as double precision), cast('inf' as double precision)); +select power(cast('-1.1' as float8), cast('inf' as float8)); -select power(cast('0.1' as double precision), cast('-inf' as double precision)); +select power(cast('0.1' as float8), cast('-inf' as float8)); -select power(cast('-0.1' as double precision), cast('-inf' as double precision)); +select power(cast('-0.1' as float8), cast('-inf' as float8)); -select power(cast('1.1' as double precision), cast('-inf' as double precision)); +select power(cast('1.1' as float8), cast('-inf' as float8)); -select power(cast('-1.1' as double precision), cast('-inf' as double precision)); +select power(cast('-1.1' as float8), cast('-inf' as float8)); -select power(cast('inf' as double precision), cast('-2' as double precision)); +select power(cast('inf' as float8), cast('-2' as float8)); -select power(cast('inf' as double precision), cast('2' as double precision)); +select power(cast('inf' as float8), cast('2' as float8)); -select power(cast('inf' as double precision), cast('inf' as double precision)); +select power(cast('inf' as float8), cast('inf' as float8)); -select power(cast('inf' as double precision), cast('-inf' as double precision)); +select power(cast('inf' as float8), cast('-inf' as float8)); -select power(cast('-inf' as double precision), cast('-2' as double precision)) = '0'; +select power(cast('-inf' as float8), cast('-2' as float8)) = '0'; -select power(cast('-inf' as double precision), cast('-3' as double precision)); +select power(cast('-inf' as float8), cast('-3' as float8)); -select power(cast('-inf' as double precision), cast('2' as double precision)); +select power(cast('-inf' as float8), cast('2' as float8)); -select power(cast('-inf' as double precision), cast('3' as double precision)); +select power(cast('-inf' as float8), cast('3' as float8)); -select power(cast('-inf' as double precision), cast('3.5' as double precision)); +select power(cast('-inf' as float8), cast('3.5' as float8)); -select power(cast('-inf' as double precision), cast('inf' as double precision)); +select power(cast('-inf' as float8), cast('inf' as float8)); -select power(cast('-inf' as double precision), cast('-inf' as double precision)); +select power(cast('-inf' as float8), cast('-inf' as float8)); select f.f1, exp(ln(f.f1)) as exp_ln_f1 from float8_tbl as f where f.f1 > '0.0'; -select - exp(cast('inf' as double precision)), - exp(cast('-inf' as double precision)), - exp(cast('nan' as double precision)); +select exp(cast('inf' as float8)), exp(cast('-inf' as float8)), exp(cast('nan' as float8)); -select ||/cast('27' as double precision) as three; +select ||/cast('27' as float8) as three; select f.f1, ||/f.f1 as cbrt_f1 from float8_tbl as f; @@ -221,51 +218,51 @@ select f.f1 / '0.0' from float8_tbl as f; select * from float8_tbl order by 1; -select sinh(cast('1' as double precision)); +select sinh(cast('1' as float8)); -select cosh(cast('1' as double precision)); +select cosh(cast('1' as float8)); -select tanh(cast('1' as double precision)); +select tanh(cast('1' as float8)); -select asinh(cast('1' as double precision)); +select asinh(cast('1' as float8)); -select acosh(cast('2' as double precision)); +select acosh(cast('2' as float8)); -select atanh(cast('0.5' as double precision)); +select atanh(cast('0.5' as float8)); -select sinh(cast('infinity' as double precision)); +select sinh(cast('infinity' as float8)); -select sinh(cast('-infinity' as double precision)); +select sinh(cast('-infinity' as float8)); -select sinh(cast('nan' as double precision)); +select sinh(cast('nan' as float8)); -select cosh(cast('infinity' as double precision)); +select cosh(cast('infinity' as float8)); -select cosh(cast('-infinity' as double precision)); +select cosh(cast('-infinity' as float8)); -select cosh(cast('nan' as double precision)); +select cosh(cast('nan' as float8)); -select tanh(cast('infinity' as double precision)); +select tanh(cast('infinity' as float8)); -select tanh(cast('-infinity' as double precision)); +select tanh(cast('-infinity' as float8)); -select tanh(cast('nan' as double precision)); +select tanh(cast('nan' as float8)); -select asinh(cast('infinity' as double precision)); +select asinh(cast('infinity' as float8)); -select asinh(cast('-infinity' as double precision)); +select asinh(cast('-infinity' as float8)); -select asinh(cast('nan' as double precision)); +select asinh(cast('nan' as float8)); -select acosh(cast('-infinity' as double precision)); +select acosh(cast('-infinity' as float8)); -select acosh(cast('nan' as double precision)); +select acosh(cast('nan' as float8)); -select atanh(cast('infinity' as double precision)); +select atanh(cast('infinity' as float8)); -select atanh(cast('-infinity' as double precision)); +select atanh(cast('-infinity' as float8)); -select atanh(cast('nan' as double precision)); +select atanh(cast('nan' as float8)); set extra_float_digits = -1; @@ -276,7 +273,7 @@ select from ( values - (cast('-infinity' as double precision)), + (cast('-infinity' as float8)), (-28), (-6), (-3.4), @@ -296,8 +293,8 @@ from (3.4), (6), (28), - (cast('infinity' as double precision)), - (cast('nan' as double precision)) + (cast('infinity' as float8)), + (cast('nan' as float8)) ) as t (x); @@ -311,39 +308,31 @@ select lgamma(x) from ( - values - (0.5), - (1), - (2), - (3), - (4), - (5), - (cast('infinity' as double precision)), - (cast('nan' as double precision)) + values (0.5), (1), (2), (3), (4), (5), (cast('infinity' as float8)), (cast('nan' as float8)) ) as t (x); -select gamma(cast('-infinity' as double precision)); +select gamma(cast('-infinity' as float8)); -select lgamma(cast('-infinity' as double precision)); +select lgamma(cast('-infinity' as float8)); -select gamma(cast('-1000.5' as double precision)); +select gamma(cast('-1000.5' as float8)); -select lgamma(cast('-1000.5' as double precision)); +select lgamma(cast('-1000.5' as float8)); -select gamma(cast('-1' as double precision)); +select gamma(cast('-1' as float8)); -select lgamma(cast('-1' as double precision)); +select lgamma(cast('-1' as float8)); -select gamma(cast('0' as double precision)); +select gamma(cast('0' as float8)); -select lgamma(cast('0' as double precision)); +select lgamma(cast('0' as float8)); -select gamma(cast('1000' as double precision)); +select gamma(cast('1000' as float8)); -select lgamma(cast('1000' as double precision)); +select lgamma(cast('1000' as float8)); -select lgamma(cast('1e308' as double precision)); +select lgamma(cast('1e308' as float8)); reset extra_float_digits; @@ -359,96 +348,52 @@ drop table float8_tbl; select * from float8_tbl; -select cast(cast('32767.4' as double precision) as smallint); +select cast(cast('32767.4' as float8) as int2); -select cast(cast('32767.6' as double precision) as smallint); +select cast(cast('32767.6' as float8) as int2); -select cast(cast('-32768.4' as double precision) as smallint); +select cast(cast('-32768.4' as float8) as int2); -select cast(cast('-32768.6' as double precision) as smallint); +select cast(cast('-32768.6' as float8) as int2); -select cast(cast('2147483647.4' as double precision) as int); +select cast(cast('2147483647.4' as float8) as int4); -select cast(cast('2147483647.6' as double precision) as int); +select cast(cast('2147483647.6' as float8) as int4); -select cast(cast('-2147483648.4' as double precision) as int); +select cast(cast('-2147483648.4' as float8) as int4); -select cast(cast('-2147483648.6' as double precision) as int); +select cast(cast('-2147483648.6' as float8) as int4); -select cast(cast('9223372036854773760' as double precision) as bigint); +select cast(cast('9223372036854773760' as float8) as int8); -select cast(cast('9223372036854775807' as double precision) as bigint); +select cast(cast('9223372036854775807' as float8) as int8); -select cast(cast('-9223372036854775808.5' as double precision) as bigint); +select cast(cast('-9223372036854775808.5' as float8) as int8); -select cast(cast('-9223372036854780000' as double precision) as bigint); +select cast(cast('-9223372036854780000' as float8) as int8); select x, sind(x), sind(x) in (-1, -0.5, 0, 0.5, 1) as sind_exact from - ( - values - (0), - (30), - (90), - (150), - (180), - (210), - (270), - (330), - (360) - ) - as t (x); + (values (0), (30), (90), (150), (180), (210), (270), (330), (360)) as t (x); select x, cosd(x), cosd(x) in (-1, -0.5, 0, 0.5, 1) as cosd_exact from - ( - values - (0), - (60), - (90), - (120), - (180), - (240), - (270), - (300), - (360) - ) - as t (x); + (values (0), (60), (90), (120), (180), (240), (270), (300), (360)) as t (x); select x, tand(x), - tand(x) - in ( - cast('-Infinity' as double precision), -1, 0, 1, cast('Infinity' as double precision) - ) - as tand_exact, + tand(x) in (cast('-Infinity' as float8), -1, 0, 1, cast('Infinity' as float8)) as tand_exact, cotd(x), - cotd(x) - in ( - cast('-Infinity' as double precision), -1, 0, 1, cast('Infinity' as double precision) - ) - as cotd_exact + cotd(x) in (cast('-Infinity' as float8), -1, 0, 1, cast('Infinity' as float8)) as cotd_exact from - ( - values - (0), - (45), - (90), - (135), - (180), - (225), - (270), - (315), - (360) - ) - as t (x); + (values (0), (45), (90), (135), (180), (225), (270), (315), (360)) as t (x); select x, @@ -464,15 +409,7 @@ select atand(x), atand(x) in (-90, -45, 0, 45, 90) as atand_exact from - ( - values - (cast('-Infinity' as double precision)), - (-1), - (0), - (1), - (cast('Infinity' as double precision)) - ) - as t (x); + (values (cast('-Infinity' as float8)), (-1), (0), (1), (cast('Infinity' as float8))) as t (x); select x, @@ -480,14 +417,7 @@ select atan2d(y, x), atan2d(y, x) in (-90, 0, 90, 180) as atan2d_exact from - ( - select - 10 * cosd(a), - 10 * sind(a) - from - generate_series(0, 360, 90) as t (a) - ) - as t (x, y); + (select 10 * cosd(a), 10 * sind(a) from generate_series(0, 360, 90) as t (a)) as t (x, y); create type xfloat8; @@ -496,26 +426,22 @@ returns xfloat8 language internal immutable strict -as $function$ -int8in -$function$; +as 'int8in'; create function xfloat8out(xfloat8) returns cstring language internal immutable strict -as $function$ -int8out -$function$; +as 'int8out'; -create type xfloat8 (input = xfloat8in, output = xfloat8out, like = no_such_type); +create type xfloat8 (input = xfloat8in, output = xfloat8out, "like" = no_such_type); -create type xfloat8 (input = xfloat8in, output = xfloat8out, like = double precision); +create type xfloat8 (input = xfloat8in, output = xfloat8out, "like" = float8); -create cast (xfloat8 as double precision) without function; +create cast (xfloat8 as float8) without function; -create cast (double precision as xfloat8) without function; +create cast (float8 as xfloat8) without function; create cast (xfloat8 as bigint) without function; @@ -548,16 +474,7 @@ select float8send(flt) as ibits, flt from - ( - select - cast(cast(cast(bits as bigint) as xfloat8) - as double precision) - as flt - from - testdata - offset 0 - ) - as s; + (select cast(cast(cast(bits as bigint) as xfloat8) as float8) as flt from testdata offset 0) as s; with testdata (bits) @@ -776,27 +693,10 @@ as ( select float8send(flt) as ibits, flt, - cast(cast(flt as text) as double precision) - as r_flt, - float8send( - cast(cast(flt as text) as double precision) - ) - as obits, - float8send( - cast(cast(flt as text) as double precision) - ) = - float8send(flt) - as correct + cast(cast(flt as text) as float8) as r_flt, + float8send(cast(cast(flt as text) as float8)) as obits, + float8send(cast(cast(flt as text) as float8)) = float8send(flt) as correct from - ( - select - cast(cast(cast(bits as bigint) as xfloat8) - as double precision) - as flt - from - testdata - offset 0 - ) - as s; + (select cast(cast(cast(bits as bigint) as xfloat8) as float8) as flt from testdata offset 0) as s; drop type xfloat8 cascade; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_80.snap index af3bd3697..2f665862d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/float8.sql --- -create temporary table float8_tbl (f1 double precision); +create temporary table float8_tbl (f1 float8); insert into float8_tbl (f1) values (' 0.0 '); @@ -14,15 +14,15 @@ insert into float8_tbl (f1) values ('1.2345678901234e+200'); insert into float8_tbl (f1) values ('1.2345678901234e-200'); -select cast('10e400' as double precision); +select cast('10e400' as float8); -select cast('-10e400' as double precision); +select cast('-10e400' as float8); -select cast('10e-400' as double precision); +select cast('10e-400' as float8); -select cast('-10e-400' as double precision); +select cast('-10e-400' as float8); -select float8send(cast('2.2250738585072014E-308' as double precision)); +select float8send(cast('2.2250738585072014E-308' as float8)); insert into float8_tbl (f1) values (''); @@ -48,35 +48,33 @@ select pg_input_is_valid('1e4000', 'float8'); select * from pg_input_error_info('1e4000', 'float8'); -select cast('NaN' as double precision); +select cast('NaN' as float8); -select cast('nan' as double precision); +select cast('nan' as float8); -select cast(' NAN ' as double precision); +select cast(' NAN ' as float8); -select cast('infinity' as double precision); +select cast('infinity' as float8); -select cast(' -INFINiTY ' as double precision); +select cast(' -INFINiTY ' as float8); -select cast('N A N' as double precision); +select cast('N A N' as float8); -select cast('NaN x' as double precision); +select cast('NaN x' as float8); -select cast(' INFINITY x' as double precision); +select cast(' INFINITY x' as float8); -select cast('Infinity' as double precision) + 100.0; +select cast('Infinity' as float8) + 100.0; -select - cast('Infinity' as double precision) / - cast('Infinity' as double precision); +select cast('Infinity' as float8) / cast('Infinity' as float8); -select cast('42' as double precision) / cast('Infinity' as double precision); +select cast('42' as float8) / cast('Infinity' as float8); -select cast('nan' as double precision) / cast('nan' as double precision); +select cast('nan' as float8) / cast('nan' as float8); -select cast('nan' as double precision) / cast('0' as double precision); +select cast('nan' as float8) / cast('0' as float8); -select cast(cast('nan' as numeric) as double precision); +select cast(cast('nan' as numeric) as float8); select * from float8_tbl; @@ -118,105 +116,88 @@ select sign(f1) as sign_f1 from float8_tbl as f; set extra_float_digits = 0; -select sqrt(cast('64' as double precision)) as eight; +select sqrt(cast('64' as float8)) as eight; -select |/cast('64' as double precision) as eight; +select |/cast('64' as float8) as eight; select f.f1, |/f.f1 as sqrt_f1 from float8_tbl as f where f.f1 > '0.0'; -select power(cast('144' as double precision), cast('0.5' as double precision)); +select power(cast('144' as float8), cast('0.5' as float8)); -select power(cast('NaN' as double precision), cast('0.5' as double precision)); +select power(cast('NaN' as float8), cast('0.5' as float8)); -select power(cast('144' as double precision), cast('NaN' as double precision)); +select power(cast('144' as float8), cast('NaN' as float8)); -select power(cast('NaN' as double precision), cast('NaN' as double precision)); +select power(cast('NaN' as float8), cast('NaN' as float8)); -select power(cast('-1' as double precision), cast('NaN' as double precision)); +select power(cast('-1' as float8), cast('NaN' as float8)); -select power(cast('1' as double precision), cast('NaN' as double precision)); +select power(cast('1' as float8), cast('NaN' as float8)); -select power(cast('NaN' as double precision), cast('0' as double precision)); +select power(cast('NaN' as float8), cast('0' as float8)); -select power(cast('inf' as double precision), cast('0' as double precision)); +select power(cast('inf' as float8), cast('0' as float8)); -select power(cast('-inf' as double precision), cast('0' as double precision)); +select power(cast('-inf' as float8), cast('0' as float8)); -select power(cast('0' as double precision), cast('inf' as double precision)); +select power(cast('0' as float8), cast('inf' as float8)); -select power(cast('0' as double precision), cast('-inf' as double precision)); +select power(cast('0' as float8), cast('-inf' as float8)); -select power(cast('1' as double precision), cast('inf' as double precision)); +select power(cast('1' as float8), cast('inf' as float8)); -select power(cast('1' as double precision), cast('-inf' as double precision)); +select power(cast('1' as float8), cast('-inf' as float8)); -select power(cast('-1' as double precision), cast('inf' as double precision)); +select power(cast('-1' as float8), cast('inf' as float8)); -select power(cast('-1' as double precision), cast('-inf' as double precision)); +select power(cast('-1' as float8), cast('-inf' as float8)); -select power(cast('0.1' as double precision), cast('inf' as double precision)); +select power(cast('0.1' as float8), cast('inf' as float8)); -select power(cast('-0.1' as double precision), cast('inf' as double precision)); +select power(cast('-0.1' as float8), cast('inf' as float8)); -select power(cast('1.1' as double precision), cast('inf' as double precision)); +select power(cast('1.1' as float8), cast('inf' as float8)); -select power(cast('-1.1' as double precision), cast('inf' as double precision)); +select power(cast('-1.1' as float8), cast('inf' as float8)); -select power(cast('0.1' as double precision), cast('-inf' as double precision)); +select power(cast('0.1' as float8), cast('-inf' as float8)); -select - power( - cast('-0.1' as double precision), - cast('-inf' as double precision) - ); +select power(cast('-0.1' as float8), cast('-inf' as float8)); -select power(cast('1.1' as double precision), cast('-inf' as double precision)); +select power(cast('1.1' as float8), cast('-inf' as float8)); -select - power( - cast('-1.1' as double precision), - cast('-inf' as double precision) - ); +select power(cast('-1.1' as float8), cast('-inf' as float8)); -select power(cast('inf' as double precision), cast('-2' as double precision)); +select power(cast('inf' as float8), cast('-2' as float8)); -select power(cast('inf' as double precision), cast('2' as double precision)); +select power(cast('inf' as float8), cast('2' as float8)); -select power(cast('inf' as double precision), cast('inf' as double precision)); +select power(cast('inf' as float8), cast('inf' as float8)); -select power(cast('inf' as double precision), cast('-inf' as double precision)); +select power(cast('inf' as float8), cast('-inf' as float8)); -select - power( - cast('-inf' as double precision), - cast('-2' as double precision) - ) = - '0'; +select power(cast('-inf' as float8), cast('-2' as float8)) = '0'; -select power(cast('-inf' as double precision), cast('-3' as double precision)); +select power(cast('-inf' as float8), cast('-3' as float8)); -select power(cast('-inf' as double precision), cast('2' as double precision)); +select power(cast('-inf' as float8), cast('2' as float8)); -select power(cast('-inf' as double precision), cast('3' as double precision)); +select power(cast('-inf' as float8), cast('3' as float8)); -select power(cast('-inf' as double precision), cast('3.5' as double precision)); +select power(cast('-inf' as float8), cast('3.5' as float8)); -select power(cast('-inf' as double precision), cast('inf' as double precision)); +select power(cast('-inf' as float8), cast('inf' as float8)); -select - power( - cast('-inf' as double precision), - cast('-inf' as double precision) - ); +select power(cast('-inf' as float8), cast('-inf' as float8)); select f.f1, exp(ln(f.f1)) as exp_ln_f1 from float8_tbl as f where f.f1 > '0.0'; select - exp(cast('inf' as double precision)), - exp(cast('-inf' as double precision)), - exp(cast('nan' as double precision)); + exp(cast('inf' as float8)), + exp(cast('-inf' as float8)), + exp(cast('nan' as float8)); -select ||/cast('27' as double precision) as three; +select ||/cast('27' as float8) as three; select f.f1, ||/f.f1 as cbrt_f1 from float8_tbl as f; @@ -240,51 +221,51 @@ select f.f1 / '0.0' from float8_tbl as f; select * from float8_tbl order by 1; -select sinh(cast('1' as double precision)); +select sinh(cast('1' as float8)); -select cosh(cast('1' as double precision)); +select cosh(cast('1' as float8)); -select tanh(cast('1' as double precision)); +select tanh(cast('1' as float8)); -select asinh(cast('1' as double precision)); +select asinh(cast('1' as float8)); -select acosh(cast('2' as double precision)); +select acosh(cast('2' as float8)); -select atanh(cast('0.5' as double precision)); +select atanh(cast('0.5' as float8)); -select sinh(cast('infinity' as double precision)); +select sinh(cast('infinity' as float8)); -select sinh(cast('-infinity' as double precision)); +select sinh(cast('-infinity' as float8)); -select sinh(cast('nan' as double precision)); +select sinh(cast('nan' as float8)); -select cosh(cast('infinity' as double precision)); +select cosh(cast('infinity' as float8)); -select cosh(cast('-infinity' as double precision)); +select cosh(cast('-infinity' as float8)); -select cosh(cast('nan' as double precision)); +select cosh(cast('nan' as float8)); -select tanh(cast('infinity' as double precision)); +select tanh(cast('infinity' as float8)); -select tanh(cast('-infinity' as double precision)); +select tanh(cast('-infinity' as float8)); -select tanh(cast('nan' as double precision)); +select tanh(cast('nan' as float8)); -select asinh(cast('infinity' as double precision)); +select asinh(cast('infinity' as float8)); -select asinh(cast('-infinity' as double precision)); +select asinh(cast('-infinity' as float8)); -select asinh(cast('nan' as double precision)); +select asinh(cast('nan' as float8)); -select acosh(cast('-infinity' as double precision)); +select acosh(cast('-infinity' as float8)); -select acosh(cast('nan' as double precision)); +select acosh(cast('nan' as float8)); -select atanh(cast('infinity' as double precision)); +select atanh(cast('infinity' as float8)); -select atanh(cast('-infinity' as double precision)); +select atanh(cast('-infinity' as float8)); -select atanh(cast('nan' as double precision)); +select atanh(cast('nan' as float8)); set extra_float_digits = -1; @@ -295,7 +276,7 @@ select from ( values - (cast('-infinity' as double precision)), + (cast('-infinity' as float8)), (-28), (-6), (-3.4), @@ -315,8 +296,8 @@ from (3.4), (6), (28), - (cast('infinity' as double precision)), - (cast('nan' as double precision)) + (cast('infinity' as float8)), + (cast('nan' as float8)) ) as t (x); @@ -337,32 +318,32 @@ from (3), (4), (5), - (cast('infinity' as double precision)), - (cast('nan' as double precision)) + (cast('infinity' as float8)), + (cast('nan' as float8)) ) as t (x); -select gamma(cast('-infinity' as double precision)); +select gamma(cast('-infinity' as float8)); -select lgamma(cast('-infinity' as double precision)); +select lgamma(cast('-infinity' as float8)); -select gamma(cast('-1000.5' as double precision)); +select gamma(cast('-1000.5' as float8)); -select lgamma(cast('-1000.5' as double precision)); +select lgamma(cast('-1000.5' as float8)); -select gamma(cast('-1' as double precision)); +select gamma(cast('-1' as float8)); -select lgamma(cast('-1' as double precision)); +select lgamma(cast('-1' as float8)); -select gamma(cast('0' as double precision)); +select gamma(cast('0' as float8)); -select lgamma(cast('0' as double precision)); +select lgamma(cast('0' as float8)); -select gamma(cast('1000' as double precision)); +select gamma(cast('1000' as float8)); -select lgamma(cast('1000' as double precision)); +select lgamma(cast('1000' as float8)); -select lgamma(cast('1e308' as double precision)); +select lgamma(cast('1e308' as float8)); reset extra_float_digits; @@ -378,128 +359,76 @@ drop table float8_tbl; select * from float8_tbl; -select cast(cast('32767.4' as double precision) as smallint); +select cast(cast('32767.4' as float8) as int2); -select cast(cast('32767.6' as double precision) as smallint); +select cast(cast('32767.6' as float8) as int2); -select cast(cast('-32768.4' as double precision) as smallint); +select cast(cast('-32768.4' as float8) as int2); -select cast(cast('-32768.6' as double precision) as smallint); +select cast(cast('-32768.6' as float8) as int2); -select cast(cast('2147483647.4' as double precision) as int); +select cast(cast('2147483647.4' as float8) as int4); -select cast(cast('2147483647.6' as double precision) as int); +select cast(cast('2147483647.6' as float8) as int4); -select cast(cast('-2147483648.4' as double precision) as int); +select cast(cast('-2147483648.4' as float8) as int4); -select cast(cast('-2147483648.6' as double precision) as int); +select cast(cast('-2147483648.6' as float8) as int4); -select cast(cast('9223372036854773760' as double precision) as bigint); +select cast(cast('9223372036854773760' as float8) as int8); -select cast(cast('9223372036854775807' as double precision) as bigint); +select cast(cast('9223372036854775807' as float8) as int8); -select cast(cast('-9223372036854775808.5' as double precision) as bigint); +select cast(cast('-9223372036854775808.5' as float8) as int8); -select cast(cast('-9223372036854780000' as double precision) as bigint); +select cast(cast('-9223372036854780000' as float8) as int8); select x, sind(x), - sind(x) in (-1, -0.5, 0, 0.5, 1) - as sind_exact + sind(x) in (-1, -0.5, 0, 0.5, 1) as sind_exact from - ( - values - (0), - (30), - (90), - (150), - (180), - (210), - (270), - (330), - (360) - ) - as t (x); + (values (0), (30), (90), (150), (180), (210), (270), (330), (360)) as t (x); select x, cosd(x), - cosd(x) in (-1, -0.5, 0, 0.5, 1) - as cosd_exact + cosd(x) in (-1, -0.5, 0, 0.5, 1) as cosd_exact from - ( - values - (0), - (60), - (90), - (120), - (180), - (240), - (270), - (300), - (360) - ) - as t (x); + (values (0), (60), (90), (120), (180), (240), (270), (300), (360)) as t (x); select x, tand(x), - tand(x) - in ( - cast('-Infinity' as double precision), -1, 0, 1, - cast('Infinity' as double precision) - ) + tand(x) in (cast('-Infinity' as float8), -1, 0, 1, cast('Infinity' as float8)) as tand_exact, cotd(x), - cotd(x) - in ( - cast('-Infinity' as double precision), -1, 0, 1, - cast('Infinity' as double precision) - ) + cotd(x) in (cast('-Infinity' as float8), -1, 0, 1, cast('Infinity' as float8)) as cotd_exact from - ( - values - (0), - (45), - (90), - (135), - (180), - (225), - (270), - (315), - (360) - ) - as t (x); + (values (0), (45), (90), (135), (180), (225), (270), (315), (360)) as t (x); select x, asind(x), - asind(x) in (-90, -30, 0, 30, 90) - as asind_exact, + asind(x) in (-90, -30, 0, 30, 90) as asind_exact, acosd(x), - acosd(x) in (0, 60, 90, 120, 180) - as acosd_exact + acosd(x) in (0, 60, 90, 120, 180) as acosd_exact from - ( - values (-1), (-0.5), (0), (0.5), (1) - ) - as t (x); + (values (-1), (-0.5), (0), (0.5), (1)) as t (x); select x, atand(x), - atand(x) in (-90, -45, 0, 45, 90) - as atand_exact + atand(x) in (-90, -45, 0, 45, 90) as atand_exact from ( values - (cast('-Infinity' as double precision)), + (cast('-Infinity' as float8)), (-1), (0), (1), - (cast('Infinity' as double precision)) + (cast('Infinity' as float8)) ) as t (x); @@ -507,15 +436,10 @@ select x, y, atan2d(y, x), - atan2d(y, x) in (-90, 0, 90, 180) - as atan2d_exact + atan2d(y, x) in (-90, 0, 90, 180) as atan2d_exact from ( - select - 10 * cosd(a), - 10 * sind(a) - from - generate_series(0, 360, 90) as t (a) + select 10 * cosd(a), 10 * sind(a) from generate_series(0, 360, 90) as t (a) ) as t (x, y); @@ -526,34 +450,26 @@ returns xfloat8 language internal immutable strict -as $function$ -int8in -$function$; +as 'int8in'; create function xfloat8out(xfloat8) returns cstring language internal immutable strict -as $function$ -int8out -$function$; +as 'int8out'; create type xfloat8 ( input = xfloat8in, output = xfloat8out, - like = no_such_type + "like" = no_such_type ); -create type xfloat8 ( - input = xfloat8in, - output = xfloat8out, - like = double precision -); +create type xfloat8 (input = xfloat8in, output = xfloat8out, "like" = float8); -create cast (xfloat8 as double precision) without function; +create cast (xfloat8 as float8) without function; -create cast (double precision as xfloat8) without function; +create cast (float8 as xfloat8) without function; create cast (xfloat8 as bigint) without function; @@ -588,9 +504,7 @@ select from ( select - cast(cast(cast(bits as bigint) as xfloat8) - as double precision) - as flt + cast(cast(cast(bits as bigint) as xfloat8) as float8) as flt from testdata offset 0 @@ -814,26 +728,13 @@ as ( select float8send(flt) as ibits, flt, - cast(cast(flt as text) - as double precision) - as r_flt, - float8send( - cast(cast(flt as text) - as double precision) - ) - as obits, - float8send( - cast(cast(flt as text) - as double precision) - ) = - float8send(flt) - as correct + cast(cast(flt as text) as float8) as r_flt, + float8send(cast(cast(flt as text) as float8)) as obits, + float8send(cast(cast(flt as text) as float8)) = float8send(flt) as correct from ( select - cast(cast(cast(bits as bigint) as xfloat8) - as double precision) - as flt + cast(cast(cast(bits as bigint) as xfloat8) as float8) as flt from testdata offset 0 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_100.snap index 4846d84b8..09450bf1a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_100.snap @@ -83,9 +83,7 @@ create foreign data wrapper foo validator postgresql_fdw_validator ; create function invalid_fdw_handler() returns int language sql -as $function$ -SELECT 1; -$function$; +as 'SELECT 1;'; create foreign data wrapper test_fdw handler invalid_fdw_handler ; @@ -207,8 +205,7 @@ create server s7 type 'oracle' version '17.0' foreign data wrapper foo - options (host 'a', - dbname 'b'); + options (host 'a', dbname 'b'); create server s8 foreign data wrapper postgresql options (foo '1'); @@ -220,7 +217,7 @@ create server t1 foreign data wrapper foo; reset role; -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; set role to regress_test_role; @@ -228,9 +225,9 @@ create server t1 foreign data wrapper foo; reset role; -revoke USAGE on foreign data wrapper foo from regress_test_role; +revoke usage on foreign data wrapper foo from regress_test_role; -grant USAGE on foreign data wrapper foo to regress_test_indirect; +grant usage on foreign data wrapper foo to regress_test_indirect; set role to regress_test_role; @@ -238,7 +235,7 @@ create server t2 foreign data wrapper foo; reset role; -grant REGRESS_TEST_INDIRECT to regress_test_role; +grant regress_test_indirect to regress_test_role; set role to regress_test_role; @@ -246,7 +243,7 @@ create server t2 foreign data wrapper foo; reset role; -revoke REGRESS_TEST_INDIRECT from regress_test_role restrict; +revoke regress_test_indirect from regress_test_role restrict; alter server s0 options (a '1'); @@ -256,9 +253,9 @@ alter server s2 version '1.1'; alter server s3 options ("tns name" 'orcl', port '1521'); -grant USAGE on foreign server s1 to regress_test_role; +grant usage on foreign server s1 to regress_test_role; -grant USAGE on foreign server s6 to regress_test_role2 with grant option; +grant usage on foreign server s6 to regress_test_role2 with grant option; set role to regress_test_role; @@ -270,7 +267,7 @@ reset role; alter server s1 owner to regress_test_role; -grant REGRESS_TEST_ROLE2 to regress_test_role; +grant regress_test_role2 to regress_test_role; set role to regress_test_role; @@ -290,7 +287,7 @@ alter server s1 owner to regress_test_indirect; reset role; -grant REGRESS_TEST_INDIRECT to regress_test_role; +grant regress_test_indirect to regress_test_role; set role to regress_test_role; @@ -298,7 +295,7 @@ alter server s1 owner to regress_test_indirect; reset role; -grant USAGE on foreign data wrapper foo to regress_test_indirect; +grant usage on foreign data wrapper foo to regress_test_indirect; set role to regress_test_role; @@ -420,7 +417,7 @@ reset role; drop server s7; -create schema "foreign_schema"; +create schema foreign_schema; create server s0 foreign data wrapper dummy; @@ -430,21 +427,15 @@ create foreign table ft1 ( c1 int options ("param 1" 'val1') primary key, c2 text options (param2 'val2', param3 'val3'), c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); create table ref_table (id int primary key); create foreign table ft1 ( - c1 int - options ("param 1" 'val1') - references ref_table (id), + c1 int options ("param 1" 'val1') references ref_table (id), c2 text options (param2 'val2', param3 'val3'), c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); drop table ref_table; @@ -453,28 +444,20 @@ create foreign table ft1 ( c2 text options (param2 'val2', param3 'val3'), c3 date, unique (c3) -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); create foreign table ft1 ( c1 int options ("param 1" 'val1') not null, - c2 text - options (param2 'val2', param3 'val3') - check (c2 <> ''), + c2 text options (param2 'val2', param3 'val3') check (c2 <> ''), c3 date, - check (c3 - between cast('1994-01-01' as date) - and cast('1994-01-31' as date)) -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); + check (c3 between cast('1994-01-01' as date) and cast('1994-01-31' as date)) +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); comment on foreign table ft1 is 'ft1'; comment on column ft1.c1 is 'ft1.c1'; -create index "id_ft1_c2" on ft1 using btree (c2); +create index id_ft1_c2 on ft1 using btree (c2); select * from ft1; @@ -648,10 +631,10 @@ alter foreign table ft1 add primary key (c7); alter foreign table ft1 - add constraint "ft1_c9_check" check (c9 < 0) not valid; + add constraint ft1_c9_check check (c9 < 0) not valid; alter foreign table ft1 - alter constraint "ft1_c9_check" deferrable initially immediate; + alter constraint ft1_c9_check deferrable initially immediate; alter foreign table ft1 drop constraint ft1_c9_check; @@ -776,8 +759,7 @@ select from information_schema.usage_privileges where - object_type like 'FOREIGN%' and - object_name in ('s6', 'foo') + object_type like 'FOREIGN%' and object_name in ('s6', 'foo') order by 1, 2, 3, @@ -789,8 +771,7 @@ select from information_schema.role_usage_grants where - object_type like 'FOREIGN%' and - object_name in ('s6', 'foo') + object_type like 'FOREIGN%' and object_name in ('s6', 'foo') order by 1, 2, 3, @@ -810,8 +791,7 @@ select from information_schema.usage_privileges where - object_type like 'FOREIGN%' and - object_name in ('s6', 'foo') + object_type like 'FOREIGN%' and object_name in ('s6', 'foo') order by 1, 2, 3, @@ -823,8 +803,7 @@ select from information_schema.role_usage_grants where - object_type like 'FOREIGN%' and - object_name in ('s6', 'foo') + object_type like 'FOREIGN%' and object_name in ('s6', 'foo') order by 1, 2, 3, @@ -842,14 +821,7 @@ reset role; select has_foreign_data_wrapper_privilege( 'regress_test_role', - ( - select - oid - from - pg_foreign_data_wrapper - where - fdwname = 'foo' - ), + (select oid from pg_foreign_data_wrapper where fdwname = 'foo'), 'USAGE' ); @@ -857,69 +829,34 @@ select has_foreign_data_wrapper_privilege('regress_test_role', 'foo', 'USAGE'); select has_foreign_data_wrapper_privilege( - ( - select - oid - from - pg_roles - where - rolname = 'regress_test_role' - ), - ( - select - oid - from - pg_foreign_data_wrapper - where - fdwname = 'foo' - ), + (select oid from pg_roles where rolname = 'regress_test_role'), + (select oid from pg_foreign_data_wrapper where fdwname = 'foo'), 'USAGE' ); select has_foreign_data_wrapper_privilege( - ( - select - oid - from - pg_foreign_data_wrapper - where - fdwname = 'foo' - ), + (select oid from pg_foreign_data_wrapper where fdwname = 'foo'), 'USAGE' ); select has_foreign_data_wrapper_privilege( - ( - select - oid - from - pg_roles - where - rolname = 'regress_test_role' - ), + (select oid from pg_roles where rolname = 'regress_test_role'), 'foo', 'USAGE' ); select has_foreign_data_wrapper_privilege('foo', 'USAGE'); -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; select has_foreign_data_wrapper_privilege('regress_test_role', 'foo', 'USAGE'); select has_server_privilege( 'regress_test_role', - ( - select - oid - from - pg_foreign_server - where - srvname = 's8' - ), + (select oid from pg_foreign_server where srvname = 's8'), 'USAGE' ); @@ -927,22 +864,8 @@ select has_server_privilege('regress_test_role', 's8', 'USAGE'); select has_server_privilege( - ( - select - oid - from - pg_roles - where - rolname = 'regress_test_role' - ), - ( - select - oid - from - pg_foreign_server - where - srvname = 's8' - ), + (select oid from pg_roles where rolname = 'regress_test_role'), + (select oid from pg_foreign_server where srvname = 's8'), 'USAGE' ); @@ -950,27 +873,20 @@ select has_server_privilege((select oid from pg_foreign_server where srvname = ' select has_server_privilege( - ( - select - oid - from - pg_roles - where - rolname = 'regress_test_role' - ), + (select oid from pg_roles where rolname = 'regress_test_role'), 's8', 'USAGE' ); select has_server_privilege('s8', 'USAGE'); -grant USAGE on foreign server s8 to regress_test_role; +grant usage on foreign server s8 to regress_test_role; select has_server_privilege('regress_test_role', 's8', 'USAGE'); -revoke USAGE on foreign server s8 from regress_test_role; +revoke usage on foreign server s8 from regress_test_role; -grant USAGE on foreign server s4 to regress_test_role; +grant usage on foreign server s4 to regress_test_role; drop user mapping for public server s4; @@ -990,7 +906,7 @@ alter foreign data wrapper foo owner to regress_unprivileged_role; drop foreign data wrapper foo; -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; create server s9 foreign data wrapper foo; @@ -1000,7 +916,7 @@ alter server s4 owner to regress_unprivileged_role; drop server s4; -grant USAGE on foreign server s4 to regress_test_role; +grant usage on foreign server s4 to regress_test_role; create user mapping for public server s4; @@ -1010,9 +926,9 @@ drop user mapping for regress_test_role server s6; reset role; -grant USAGE on foreign data wrapper postgresql to regress_unprivileged_role; +grant usage on foreign data wrapper postgresql to regress_unprivileged_role; -grant USAGE on foreign data wrapper foo to regress_unprivileged_role with grant option; +grant usage on foreign data wrapper foo to regress_unprivileged_role with grant option; set role to regress_unprivileged_role; @@ -1022,9 +938,9 @@ alter foreign data wrapper foo options (gotcha 'true'); drop foreign data wrapper foo; -grant USAGE on foreign data wrapper postgresql to regress_test_role; +grant usage on foreign data wrapper postgresql to regress_test_role; -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; create server s9 foreign data wrapper postgresql; @@ -1032,9 +948,9 @@ alter server s6 version '0.5'; drop server s6; -grant USAGE on foreign server s6 to regress_test_role; +grant usage on foreign server s6 to regress_test_role; -grant USAGE on foreign server s9 to regress_test_role; +grant usage on foreign server s9 to regress_test_role; create user mapping for public server s6; @@ -1046,19 +962,19 @@ drop user mapping for regress_test_role server s6; reset role; -revoke USAGE on foreign data wrapper foo from regress_unprivileged_role; +revoke usage on foreign data wrapper foo from regress_unprivileged_role; -revoke USAGE on foreign data wrapper foo from regress_unprivileged_role cascade; +revoke usage on foreign data wrapper foo from regress_unprivileged_role cascade; set role to regress_unprivileged_role; -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; create server s10 foreign data wrapper foo; alter server s9 version '1.1'; -grant USAGE on foreign server s9 to regress_test_role; +grant usage on foreign server s9 to regress_test_role; create user mapping for current_user server s9; @@ -1068,13 +984,13 @@ reset role; create server s9 foreign data wrapper foo; -grant USAGE on foreign server s9 to regress_unprivileged_role; +grant usage on foreign server s9 to regress_unprivileged_role; set role to regress_unprivileged_role; alter server s9 version '1.2'; -grant USAGE on foreign server s9 to regress_test_role; +grant usage on foreign server s9 to regress_test_role; create user mapping for current_user server s9; @@ -1099,11 +1015,11 @@ drop server s10 cascade; create function dummy_trigger() returns trigger language plpgsql -as $function$ -BEGIN +as $$ + BEGIN RETURN NULL; END -$function$; +$$; create trigger trigtest_before_stmt before insert or delete or update @@ -1166,9 +1082,7 @@ create table fd_pt1 ( create foreign table ft2 partition of fd_pt1 -default server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +default server s0 options (delimiter ',', quote '"', "be quoted" 'value'); drop foreign table ft2; @@ -1176,9 +1090,7 @@ create foreign table ft2 ( c1 int not null, c2 text, c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); alter foreign table ft2 inherit fd_pt1; @@ -1252,10 +1164,10 @@ alter table fd_pt1 drop column c8; alter table fd_pt1 - add constraint "fd_pt1chk1" check (c1 > 0) no inherit; + add constraint fd_pt1chk1 check (c1 > 0) no inherit; alter table fd_pt1 - add constraint "fd_pt1chk2" check (c2 <> ''); + add constraint fd_pt1chk2 check (c2 <> ''); select relname, @@ -1265,10 +1177,7 @@ select coninhcount, connoinherit from - pg_class as pc - inner join - pg_constraint as pgc - on conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on conrelid = pc.oid where pc.relname = 'fd_pt1' order by 1, @@ -1282,15 +1191,13 @@ create foreign table ft2 ( c1 int not null, c2 text, c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); alter foreign table ft2 inherit fd_pt1; alter foreign table ft2 - add constraint "fd_pt1chk2" check (c2 <> ''); + add constraint fd_pt1chk2 check (c2 <> ''); alter foreign table ft2 inherit fd_pt1; @@ -1304,7 +1211,7 @@ alter table fd_pt1 insert into fd_pt1 values (1, cast('fd_pt1' as text), cast('1994-01-01' as date)); alter table fd_pt1 - add constraint "fd_pt1chk3" check (c2 <> '') not valid; + add constraint fd_pt1chk3 check (c2 <> '') not valid; alter table fd_pt1 validate constraint fd_pt1chk3; @@ -1326,12 +1233,10 @@ import foreign schema s1 limit to (t1) from server s9 into public; import foreign schema s1 except (t1) from server s9 into public; import foreign schema s1 -except (t1, -t2) +except (t1, t2) from server s9 into public -options (option1 'value1', -option2 'value2'); +options (option1 'value1', option2 'value2'); drop foreign table no_table; @@ -1350,13 +1255,11 @@ create table fd_pt2 ( c2 text, c3 date ) -partition by LIST(c1); +partition by list(c1); create foreign table fd_pt2_1 partition of fd_pt2 -for values in (1) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +for values in (1) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); drop foreign table fd_pt2_1; @@ -1365,9 +1268,7 @@ create foreign table fd_pt2_1 ( c2 text, c3 date, c4 char(1) -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); alter table fd_pt2 attach partition @@ -1379,9 +1280,7 @@ create foreign table fd_pt2_1 ( c1 int not null, c2 text, c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); alter table fd_pt2 attach partition @@ -1394,7 +1293,7 @@ alter table fd_pt2_1 alter column c3 set not null; alter table fd_pt2_1 - add constraint "p21chk" check (c2 <> ''); + add constraint p21chk check (c2 <> ''); alter table fd_pt2_1 alter column c1 drop not null; @@ -1422,14 +1321,14 @@ alter table fd_pt2 fd_pt2_1; alter table fd_pt2 - add constraint "fd_pt2chk1" check (c1 > 0); + add constraint fd_pt2chk1 check (c1 > 0); alter table fd_pt2 attach partition fd_pt2_1 for values in (1); alter foreign table fd_pt2_1 - add constraint "fd_pt2chk1" check (c1 > 0); + add constraint fd_pt2chk1 check (c1 > 0); alter table fd_pt2 attach partition @@ -1440,7 +1339,7 @@ drop foreign table fd_pt2_1; drop table fd_pt2; create temporary table temp_parted (a int) -partition by LIST(a); +partition by list(a); create foreign table foreign_part partition of temp_parted default server s0; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_80.snap index 9959a8615..b2cec8329 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_80.snap @@ -83,9 +83,7 @@ create foreign data wrapper foo validator postgresql_fdw_validator ; create function invalid_fdw_handler() returns int language sql -as $function$ -SELECT 1; -$function$; +as 'SELECT 1;'; create foreign data wrapper test_fdw handler invalid_fdw_handler ; @@ -201,30 +199,26 @@ create server s3 type 'oracle' foreign data wrapper foo; create server s4 type 'oracle' foreign data wrapper foo - options (host 'a', - dbname 'b'); + options (host 'a', dbname 'b'); create server s5 version '15.0' foreign data wrapper foo; create server s6 version '16.0' foreign data wrapper foo - options (host 'a', - dbname 'b'); + options (host 'a', dbname 'b'); create server s7 type 'oracle' version '17.0' foreign data wrapper foo - options (host 'a', - dbname 'b'); + options (host 'a', dbname 'b'); create server s8 foreign data wrapper postgresql options (foo '1'); create server s8 foreign data wrapper postgresql - options (host 'localhost', - dbname 's8db'); + options (host 'localhost', dbname 's8db'); set role to regress_test_role; @@ -232,7 +226,7 @@ create server t1 foreign data wrapper foo; reset role; -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; set role to regress_test_role; @@ -240,9 +234,9 @@ create server t1 foreign data wrapper foo; reset role; -revoke USAGE on foreign data wrapper foo from regress_test_role; +revoke usage on foreign data wrapper foo from regress_test_role; -grant USAGE on foreign data wrapper foo to regress_test_indirect; +grant usage on foreign data wrapper foo to regress_test_indirect; set role to regress_test_role; @@ -250,7 +244,7 @@ create server t2 foreign data wrapper foo; reset role; -grant REGRESS_TEST_INDIRECT to regress_test_role; +grant regress_test_indirect to regress_test_role; set role to regress_test_role; @@ -258,7 +252,7 @@ create server t2 foreign data wrapper foo; reset role; -revoke REGRESS_TEST_INDIRECT from regress_test_role restrict; +revoke regress_test_indirect from regress_test_role restrict; alter server s0 options (a '1'); @@ -268,9 +262,9 @@ alter server s2 version '1.1'; alter server s3 options ("tns name" 'orcl', port '1521'); -grant USAGE on foreign server s1 to regress_test_role; +grant usage on foreign server s1 to regress_test_role; -grant USAGE on foreign server s6 to regress_test_role2 with grant option; +grant usage on foreign server s6 to regress_test_role2 with grant option; set role to regress_test_role; @@ -282,7 +276,7 @@ reset role; alter server s1 owner to regress_test_role; -grant REGRESS_TEST_ROLE2 to regress_test_role; +grant regress_test_role2 to regress_test_role; set role to regress_test_role; @@ -302,7 +296,7 @@ alter server s1 owner to regress_test_indirect; reset role; -grant REGRESS_TEST_INDIRECT to regress_test_role; +grant regress_test_indirect to regress_test_role; set role to regress_test_role; @@ -310,7 +304,7 @@ alter server s1 owner to regress_test_indirect; reset role; -grant USAGE on foreign data wrapper foo to regress_test_indirect; +grant usage on foreign data wrapper foo to regress_test_indirect; set role to regress_test_role; @@ -362,13 +356,11 @@ create user mapping for public server s4 options ("this mapping" 'is public'); create user mapping for current_user -server s8 options (username 'test', -password 'secret'); +server s8 options (username 'test', password 'secret'); create user mapping for current_user -server s8 options ("user" 'test', -password 'secret'); +server s8 options ("user" 'test', password 'secret'); alter server s5 owner to regress_test_role; @@ -392,8 +384,7 @@ set role to regress_test_role; create user mapping for current_user -server t1 options (username 'bob', -password 'boo'); +server t1 options (username 'bob', password 'boo'); create user mapping for public server t1; @@ -409,8 +400,7 @@ alter user mapping for public server s5 options (gotcha 'true'); alter user mapping for current_user server s8 options (username 'test'); alter user mapping for current_user server s8 - options (drop "user", - set password 'public'); + options (drop "user", set password 'public'); set role to regress_test_role; @@ -444,70 +434,47 @@ reset role; drop server s7; -create schema "foreign_schema"; +create schema foreign_schema; create server s0 foreign data wrapper dummy; create foreign table ft1 () server no_server; create foreign table ft1 ( - c1 int - options ("param 1" 'val1') - primary key, - c2 text - options (param2 'val2', param3 'val3'), + c1 int options ("param 1" 'val1') primary key, + c2 text options (param2 'val2', param3 'val3'), c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); create table ref_table (id int primary key); create foreign table ft1 ( - c1 int - options ("param 1" 'val1') - references ref_table (id), - c2 text - options (param2 'val2', param3 'val3'), + c1 int options ("param 1" 'val1') references ref_table (id), + c2 text options (param2 'val2', param3 'val3'), c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); drop table ref_table; create foreign table ft1 ( - c1 int - options ("param 1" 'val1') - not null, - c2 text - options (param2 'val2', param3 'val3'), + c1 int options ("param 1" 'val1') not null, + c2 text options (param2 'val2', param3 'val3'), c3 date, unique (c3) -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); create foreign table ft1 ( - c1 int - options ("param 1" 'val1') - not null, - c2 text - options (param2 'val2', param3 'val3') - check (c2 <> ''), + c1 int options ("param 1" 'val1') not null, + c2 text options (param2 'val2', param3 'val3') check (c2 <> ''), c3 date, - check (c3 - between cast('1994-01-01' as date) - and cast('1994-01-31' as date)) -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); + check (c3 between cast('1994-01-01' as date) and cast('1994-01-31' as date)) +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); comment on foreign table ft1 is 'ft1'; comment on column ft1.c1 is 'ft1.c1'; -create index "id_ft1_c2" on ft1 using btree (c2); +create index id_ft1_c2 on ft1 using btree (c2); select * from ft1; @@ -542,8 +509,7 @@ create foreign table ft_part2 ( a int ) server s0; alter table lt1 attach partition - ft_part2 - for values from (1000) to (2000); + ft_part2 for values from (1000) to (2000); drop foreign table ft_part1, ft_part2; @@ -560,8 +526,7 @@ create foreign table ft_part2 ( a int not null ) server s0; alter table lt1 attach partition - ft_part2 - for values from (1000) to (2000); + ft_part2 for values from (1000) to (2000); drop table lt1; @@ -585,8 +550,7 @@ create foreign table ft_part_1_2 ( a int ) server s0; alter table lt1_part1 attach partition - ft_part_1_2 - for values from (100) to (200); + ft_part_1_2 for values from (100) to (200); create unique index on lt1 using btree (a); @@ -608,8 +572,7 @@ create foreign table ft_part_1_2 ( a int not null ) server s0; alter table lt1_part1 attach partition - ft_part_1_2 - for values from (100) to (200); + ft_part_1_2 for values from (100) to (200); drop table lt1; @@ -698,10 +661,10 @@ alter foreign table ft1 add primary key (c7); alter foreign table ft1 - add constraint "ft1_c9_check" check (c9 < 0) not valid; + add constraint ft1_c9_check check (c9 < 0) not valid; alter foreign table ft1 - alter constraint "ft1_c9_check" deferrable initially immediate; + alter constraint ft1_c9_check deferrable initially immediate; alter foreign table ft1 drop constraint ft1_c9_check; @@ -834,8 +797,7 @@ select from information_schema.usage_privileges where - object_type like 'FOREIGN%' and - object_name in ('s6', 'foo') + object_type like 'FOREIGN%' and object_name in ('s6', 'foo') order by 1, 2, 3, @@ -847,8 +809,7 @@ select from information_schema.role_usage_grants where - object_type like 'FOREIGN%' and - object_name in ('s6', 'foo') + object_type like 'FOREIGN%' and object_name in ('s6', 'foo') order by 1, 2, 3, @@ -868,8 +829,7 @@ select from information_schema.usage_privileges where - object_type like 'FOREIGN%' and - object_name in ('s6', 'foo') + object_type like 'FOREIGN%' and object_name in ('s6', 'foo') order by 1, 2, 3, @@ -881,8 +841,7 @@ select from information_schema.role_usage_grants where - object_type like 'FOREIGN%' and - object_name in ('s6', 'foo') + object_type like 'FOREIGN%' and object_name in ('s6', 'foo') order by 1, 2, 3, @@ -900,14 +859,7 @@ reset role; select has_foreign_data_wrapper_privilege( 'regress_test_role', - ( - select - oid - from - pg_foreign_data_wrapper - where - fdwname = 'foo' - ), + (select oid from pg_foreign_data_wrapper where fdwname = 'foo'), 'USAGE' ); @@ -915,69 +867,34 @@ select has_foreign_data_wrapper_privilege('regress_test_role', 'foo', 'USAGE'); select has_foreign_data_wrapper_privilege( - ( - select - oid - from - pg_roles - where - rolname = 'regress_test_role' - ), - ( - select - oid - from - pg_foreign_data_wrapper - where - fdwname = 'foo' - ), + (select oid from pg_roles where rolname = 'regress_test_role'), + (select oid from pg_foreign_data_wrapper where fdwname = 'foo'), 'USAGE' ); select has_foreign_data_wrapper_privilege( - ( - select - oid - from - pg_foreign_data_wrapper - where - fdwname = 'foo' - ), + (select oid from pg_foreign_data_wrapper where fdwname = 'foo'), 'USAGE' ); select has_foreign_data_wrapper_privilege( - ( - select - oid - from - pg_roles - where - rolname = 'regress_test_role' - ), + (select oid from pg_roles where rolname = 'regress_test_role'), 'foo', 'USAGE' ); select has_foreign_data_wrapper_privilege('foo', 'USAGE'); -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; select has_foreign_data_wrapper_privilege('regress_test_role', 'foo', 'USAGE'); select has_server_privilege( 'regress_test_role', - ( - select - oid - from - pg_foreign_server - where - srvname = 's8' - ), + (select oid from pg_foreign_server where srvname = 's8'), 'USAGE' ); @@ -985,61 +902,33 @@ select has_server_privilege('regress_test_role', 's8', 'USAGE'); select has_server_privilege( - ( - select - oid - from - pg_roles - where - rolname = 'regress_test_role' - ), - ( - select - oid - from - pg_foreign_server - where - srvname = 's8' - ), + (select oid from pg_roles where rolname = 'regress_test_role'), + (select oid from pg_foreign_server where srvname = 's8'), 'USAGE' ); select has_server_privilege( - ( - select - oid - from - pg_foreign_server - where - srvname = 's8' - ), + (select oid from pg_foreign_server where srvname = 's8'), 'USAGE' ); select has_server_privilege( - ( - select - oid - from - pg_roles - where - rolname = 'regress_test_role' - ), + (select oid from pg_roles where rolname = 'regress_test_role'), 's8', 'USAGE' ); select has_server_privilege('s8', 'USAGE'); -grant USAGE on foreign server s8 to regress_test_role; +grant usage on foreign server s8 to regress_test_role; select has_server_privilege('regress_test_role', 's8', 'USAGE'); -revoke USAGE on foreign server s8 from regress_test_role; +revoke usage on foreign server s8 from regress_test_role; -grant USAGE on foreign server s4 to regress_test_role; +grant usage on foreign server s4 to regress_test_role; drop user mapping for public server s4; @@ -1059,7 +948,7 @@ alter foreign data wrapper foo owner to regress_unprivileged_role; drop foreign data wrapper foo; -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; create server s9 foreign data wrapper foo; @@ -1069,7 +958,7 @@ alter server s4 owner to regress_unprivileged_role; drop server s4; -grant USAGE on foreign server s4 to regress_test_role; +grant usage on foreign server s4 to regress_test_role; create user mapping for public server s4; @@ -1079,9 +968,9 @@ drop user mapping for regress_test_role server s6; reset role; -grant USAGE on foreign data wrapper postgresql to regress_unprivileged_role; +grant usage on foreign data wrapper postgresql to regress_unprivileged_role; -grant USAGE +grant usage on foreign data wrapper foo to regress_unprivileged_role with grant option; @@ -1094,9 +983,9 @@ alter foreign data wrapper foo options (gotcha 'true'); drop foreign data wrapper foo; -grant USAGE on foreign data wrapper postgresql to regress_test_role; +grant usage on foreign data wrapper postgresql to regress_test_role; -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; create server s9 foreign data wrapper postgresql; @@ -1104,9 +993,9 @@ alter server s6 version '0.5'; drop server s6; -grant USAGE on foreign server s6 to regress_test_role; +grant usage on foreign server s6 to regress_test_role; -grant USAGE on foreign server s9 to regress_test_role; +grant usage on foreign server s9 to regress_test_role; create user mapping for public server s6; @@ -1118,19 +1007,19 @@ drop user mapping for regress_test_role server s6; reset role; -revoke USAGE on foreign data wrapper foo from regress_unprivileged_role; +revoke usage on foreign data wrapper foo from regress_unprivileged_role; -revoke USAGE on foreign data wrapper foo from regress_unprivileged_role cascade; +revoke usage on foreign data wrapper foo from regress_unprivileged_role cascade; set role to regress_unprivileged_role; -grant USAGE on foreign data wrapper foo to regress_test_role; +grant usage on foreign data wrapper foo to regress_test_role; create server s10 foreign data wrapper foo; alter server s9 version '1.1'; -grant USAGE on foreign server s9 to regress_test_role; +grant usage on foreign server s9 to regress_test_role; create user mapping for current_user server s9; @@ -1140,13 +1029,13 @@ reset role; create server s9 foreign data wrapper foo; -grant USAGE on foreign server s9 to regress_unprivileged_role; +grant usage on foreign server s9 to regress_unprivileged_role; set role to regress_unprivileged_role; alter server s9 version '1.2'; -grant USAGE on foreign server s9 to regress_test_role; +grant usage on foreign server s9 to regress_test_role; create user mapping for current_user server s9; @@ -1173,11 +1062,11 @@ drop server s10 cascade; create function dummy_trigger() returns trigger language plpgsql -as $function$ -BEGIN +as $$ + BEGIN RETURN NULL; END -$function$; +$$; create trigger trigtest_before_stmt before insert or delete or update @@ -1240,9 +1129,7 @@ create table fd_pt1 ( create foreign table ft2 partition of fd_pt1 -default server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +default server s0 options (delimiter ',', quote '"', "be quoted" 'value'); drop foreign table ft2; @@ -1250,9 +1137,7 @@ create foreign table ft2 ( c1 int not null, c2 text, c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); alter foreign table ft2 inherit fd_pt1; @@ -1326,10 +1211,10 @@ alter table fd_pt1 drop column c8; alter table fd_pt1 - add constraint "fd_pt1chk1" check (c1 > 0) no inherit; + add constraint fd_pt1chk1 check (c1 > 0) no inherit; alter table fd_pt1 - add constraint "fd_pt1chk2" check (c2 <> ''); + add constraint fd_pt1chk2 check (c2 <> ''); select relname, @@ -1339,10 +1224,7 @@ select coninhcount, connoinherit from - pg_class as pc - inner join - pg_constraint as pgc - on conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on conrelid = pc.oid where pc.relname = 'fd_pt1' order by 1, @@ -1356,15 +1238,13 @@ create foreign table ft2 ( c1 int not null, c2 text, c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); alter foreign table ft2 inherit fd_pt1; alter foreign table ft2 - add constraint "fd_pt1chk2" check (c2 <> ''); + add constraint fd_pt1chk2 check (c2 <> ''); alter foreign table ft2 inherit fd_pt1; @@ -1376,15 +1256,10 @@ alter table fd_pt1 drop constraint fd_pt1chk2 cascade; insert into fd_pt1 -values - ( - 1, - cast('fd_pt1' as text), - cast('1994-01-01' as date) - ); +values (1, cast('fd_pt1' as text), cast('1994-01-01' as date)); alter table fd_pt1 - add constraint "fd_pt1chk3" check (c2 <> '') not valid; + add constraint fd_pt1chk3 check (c2 <> '') not valid; alter table fd_pt1 validate constraint fd_pt1chk3; @@ -1406,12 +1281,10 @@ import foreign schema s1 limit to (t1) from server s9 into public; import foreign schema s1 except (t1) from server s9 into public; import foreign schema s1 -except (t1, -t2) +except (t1, t2) from server s9 into public -options (option1 'value1', -option2 'value2'); +options (option1 'value1', option2 'value2'); drop foreign table no_table; @@ -1430,13 +1303,15 @@ create table fd_pt2 ( c2 text, c3 date ) -partition by LIST(c1); +partition by list(c1); create foreign table fd_pt2_1 partition of fd_pt2 -for values in (1) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +for values in (1) server s0 options ( + delimiter ',', + quote '"', + "be quoted" 'value' +); drop foreign table fd_pt2_1; @@ -1445,9 +1320,7 @@ create foreign table fd_pt2_1 ( c2 text, c3 date, c4 char(1) -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); alter table fd_pt2 attach partition @@ -1459,9 +1332,7 @@ create foreign table fd_pt2_1 ( c1 int not null, c2 text, c3 date -) server s0 options (delimiter ',', -quote '"', -"be quoted" 'value'); +) server s0 options (delimiter ',', quote '"', "be quoted" 'value'); alter table fd_pt2 attach partition @@ -1474,7 +1345,7 @@ alter table fd_pt2_1 alter column c3 set not null; alter table fd_pt2_1 - add constraint "p21chk" check (c2 <> ''); + add constraint p21chk check (c2 <> ''); alter table fd_pt2_1 alter column c1 drop not null; @@ -1502,14 +1373,14 @@ alter table fd_pt2 fd_pt2_1; alter table fd_pt2 - add constraint "fd_pt2chk1" check (c1 > 0); + add constraint fd_pt2chk1 check (c1 > 0); alter table fd_pt2 attach partition fd_pt2_1 for values in (1); alter foreign table fd_pt2_1 - add constraint "fd_pt2chk1" check (c1 > 0); + add constraint fd_pt2chk1 check (c1 > 0); alter table fd_pt2 attach partition @@ -1520,7 +1391,7 @@ drop foreign table fd_pt2_1; drop table fd_pt2; create temporary table temp_parted (a int) -partition by LIST(a); +partition by list(a); create foreign table foreign_part partition of temp_parted default server s0; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_key_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_key_100.snap index 50643eb0b..620e8c4bf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_key_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_key_100.snap @@ -56,14 +56,11 @@ create table fktable ( ftest1 int, ftest2 int, ftest3 int, - constraint "constrname" - foreign key - (ftest1, - ftest2) - references pktable - match full - on DELETE set null - on UPDATE set null + constraint constrname foreign key (ftest1, ftest2) + references pktable + match full + on delete set null + on update set null ); comment on constraint constrname_wrong on fktable is 'fk constraint comment'; @@ -145,14 +142,11 @@ create table fktable ( ftest1 int default -1, ftest2 int default -2, ftest3 int, - constraint "constrname2" - foreign key - (ftest1, - ftest2) - references pktable - match full - on DELETE set default - on UPDATE set default + constraint constrname2 foreign key (ftest1, ftest2) + references pktable + match full + on delete set default + on update set default ); insert into pktable values (-1, -2, 'The Default!'); @@ -273,14 +267,10 @@ insert into pktable values (1, 2); insert into fktable values (1, null); alter table fktable - add foreign key - (ftest1, - ftest2) - references pktable - match full; + add foreign key (ftest1, ftest2) references pktable match full; alter table fktable - alter constraint "fk_con" deferrable initially deferred; + alter constraint fk_con deferrable initially deferred; select condeferrable, @@ -339,12 +329,7 @@ create table fktable ( ftest2 int, ftest3 int, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable + constraint constrname3 foreign key (ftest1, ftest2, ftest3) references pktable ); insert into pktable values (1, 2, 3, 'test1'); @@ -398,14 +383,8 @@ create table fktable ( ftest2 int, ftest3 int, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable (ptest1, - ptest2, - ptest3) + constraint constrname3 foreign key (ftest1, ftest2, ftest3) + references pktable (ptest1, ptest2, ptest3) ); insert into pktable values (1, 2, 3, 'test1'); @@ -439,14 +418,10 @@ create table fktable ( ftest2 int, ftest3 int, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable - on DELETE cascade - on UPDATE cascade + constraint constrname3 foreign key (ftest1, ftest2, ftest3) + references pktable + on delete cascade + on update cascade ); insert into pktable values (1, 2, 3, 'test1'); @@ -508,14 +483,10 @@ create table fktable ( ftest2 int, ftest3 int, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable - on DELETE set default - on UPDATE set null + constraint constrname3 foreign key (ftest1, ftest2, ftest3) + references pktable + on delete set default + on update set null ); insert into pktable values (1, 2, 3, 'test1'); @@ -579,14 +550,10 @@ create table fktable ( ftest2 int default -1, ftest3 int default -2, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable - on DELETE set null - on UPDATE set default + constraint constrname3 foreign key (ftest1, ftest2, ftest3) + references pktable + on delete set null + on update set default ); insert into pktable values (1, 2, 3, 'test1'); @@ -655,22 +622,14 @@ create table fktable ( tid int, id int, foo int, - foreign key - (tid, - id) - references pktable - on DELETE set null (bar) + foreign key (tid, id) references pktable on delete set null (bar) ); create table fktable ( tid int, id int, foo int, - foreign key - (tid, - id) - references pktable - on DELETE set null (foo) + foreign key (tid, id) references pktable on delete set null (foo) ); create table fktable ( @@ -678,17 +637,10 @@ create table fktable ( id int, fk_id_del_set_null int, fk_id_del_set_default int default 0, - foreign key - (tid, - fk_id_del_set_null) - references pktable - on DELETE set null (fk_id_del_set_null), - foreign key - (tid, - fk_id_del_set_default) - references pktable - on DELETE set default (fk_id_del_set_default, - fk_id_del_set_default) + foreign key (tid, fk_id_del_set_null) references pktable on delete set null (fk_id_del_set_null), + foreign key (tid, fk_id_del_set_default) + references pktable + on delete set default (fk_id_del_set_default, fk_id_del_set_default) ); select @@ -696,8 +648,7 @@ select from pg_constraint where - conrelid = - cast(cast('fktable' as regclass) as oid) + conrelid = cast(cast('fktable' as regclass) as oid) order by oid; insert into pktable values (1, 0), (1, 1), (1, 2); @@ -719,34 +670,22 @@ create table pktable ( create table fktable_fail1 ( ftest1 int, - constraint "fkfail1" - foreign key - (ftest2) - references pktable + constraint fkfail1 foreign key (ftest2) references pktable ); create table fktable_fail2 ( ftest1 int, - constraint "fkfail1" - foreign key - (ftest1) - references pktable (ptest2) + constraint fkfail1 foreign key (ftest1) references pktable (ptest2) ); create table fktable_fail3 ( ftest1 int, - constraint "fkfail1" - foreign key - (tableoid) - references pktable (someoid) + constraint fkfail1 foreign key (tableoid) references pktable (someoid) ); create table fktable_fail4 ( ftest1 oid, - constraint "fkfail1" - foreign key - (ftest1) - references pktable (tableoid) + constraint fkfail1 foreign key (ftest1) references pktable (tableoid) ); drop table pktable; @@ -771,7 +710,7 @@ create table fktable (ftest1 inet references pktable); create table fktable (ftest1 inet references pktable (ptest1)); -create table fktable (ftest1 bigint references pktable); +create table fktable (ftest1 int8 references pktable); insert into fktable values (42); @@ -820,11 +759,7 @@ create table fktable ( create table fktable ( ftest1 cidr, ftest2 timestamp, - foreign key - (ftest1, - ftest2) - references pktable (ptest1, - ptest2) + foreign key (ftest1, ftest2) references pktable (ptest1, ptest2) ); create table fktable ( @@ -836,31 +771,19 @@ create table fktable ( create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest2, - ftest1) - references pktable (ptest1, - ptest2) + foreign key (ftest2, ftest1) references pktable (ptest1, ptest2) ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest1, - ftest2) - references pktable (ptest2, - ptest1) + foreign key (ftest1, ftest2) references pktable (ptest2, ptest1) ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest2, - ftest1) - references pktable (ptest2, - ptest1) + foreign key (ftest2, ftest1) references pktable (ptest2, ptest1) ); drop table fktable; @@ -868,11 +791,7 @@ drop table fktable; create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest1, - ftest2) - references pktable (ptest1, - ptest2) + foreign key (ftest1, ftest2) references pktable (ptest1, ptest2) ); drop table fktable; @@ -885,11 +804,7 @@ create table pktable ( ptest3 int, ptest4 inet, primary key (ptest1, ptest2), - foreign key - (ptest3, - ptest4) - references pktable (ptest1, - ptest2) + foreign key (ptest3, ptest4) references pktable (ptest1, ptest2) ); drop table pktable; @@ -911,11 +826,7 @@ create table pktable ( ptest3 int, ptest4 inet, primary key (ptest1, ptest2), - foreign key - (ptest3, - ptest4) - references pktable (ptest2, - ptest1) + foreign key (ptest3, ptest4) references pktable (ptest2, ptest1) ); create table pktable ( @@ -924,11 +835,7 @@ create table pktable ( ptest3 int, ptest4 inet, primary key (ptest1, ptest2), - foreign key - (ptest4, - ptest3) - references pktable (ptest1, - ptest2) + foreign key (ptest4, ptest3) references pktable (ptest1, ptest2) ); create table pktable ( @@ -976,11 +883,7 @@ delete from pktable; create table fktable ( ftest1 int, ftest2 int, - foreign key - (ftest1, - ftest2) - references pktable (base1, - ptest1) + foreign key (ftest1, ftest2) references pktable (base1, ptest1) ); insert into pktable (base1, ptest1) values (1, 1); @@ -1016,11 +919,7 @@ create table pktable ( ptest1 int, ptest2 int, primary key (base1, ptest1), - foreign key - (base2, - ptest2) - references pktable (base1, - ptest1) + foreign key (base2, ptest2) references pktable (base1, ptest1) ) inherits (pktable_base); @@ -1063,11 +962,7 @@ create table fktable ( create table fktable ( ftest1 cidr, ftest2 int[], - foreign key - (ftest1, - ftest2) - references pktable (base1, - ptest1) + foreign key (ftest1, ftest2) references pktable (base1, ptest1) ); create table fktable ( @@ -1079,21 +974,13 @@ create table fktable ( create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest2, - ftest1) - references pktable (base1, - ptest1) + foreign key (ftest2, ftest1) references pktable (base1, ptest1) ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest1, - ftest2) - references pktable (ptest1, - base1) + foreign key (ftest1, ftest2) references pktable (ptest1, base1) ); drop table pktable; @@ -1109,11 +996,7 @@ create table pktable ( ptest1 inet, ptest2 inet[], primary key (base1, ptest1), - foreign key - (base2, - ptest2) - references pktable (base1, - ptest1) + foreign key (base2, ptest2) references pktable (base1, ptest1) ) inherits (pktable_base); @@ -1121,11 +1004,7 @@ create table pktable ( ptest1 inet, ptest2 inet, primary key (base1, ptest1), - foreign key - (base2, - ptest2) - references pktable (ptest1, - base1) + foreign key (base2, ptest2) references pktable (ptest1, base1) ) inherits (pktable_base); @@ -1133,11 +1012,7 @@ create table pktable ( ptest1 inet, ptest2 inet, primary key (base1, ptest1), - foreign key - (ptest2, - base2) - references pktable (base1, - ptest1) + foreign key (ptest2, base2) references pktable (base1, ptest1) ) inherits (pktable_base); @@ -1145,11 +1020,7 @@ create table pktable ( ptest1 inet, ptest2 inet, primary key (base1, ptest1), - foreign key - (ptest2, - base2) - references pktable (base1, - ptest1) + foreign key (ptest2, base2) references pktable (base1, ptest1) ) inherits (pktable_base); @@ -1158,13 +1029,13 @@ drop table pktable; drop table pktable_base; create table pktable ( - id int primary key, - other int + id int4 primary key, + other int4 ); create table fktable ( - id int primary key, - fk int references pktable deferrable + id int4 primary key, + fk int4 references pktable deferrable ); insert into fktable values (5, 10); @@ -1182,16 +1053,13 @@ commit; drop table fktable, pktable; create table pktable ( - id int primary key, - other int + id int4 primary key, + other int4 ); create table fktable ( - id int primary key, - fk int - references pktable - deferrable - initially deferred + id int4 primary key, + fk int4 references pktable deferrable initially deferred ); begin; @@ -1213,13 +1081,13 @@ commit; drop table fktable, pktable; create table pktable ( - id int primary key, - other int + id int4 primary key, + other int4 ); create table fktable ( - id int primary key, - fk int references pktable deferrable + id int4 primary key, + fk int4 references pktable deferrable ); begin; @@ -1237,16 +1105,13 @@ commit; drop table fktable, pktable; create table pktable ( - id int primary key, - other int + id int4 primary key, + other int4 ); create table fktable ( - id int primary key, - fk int - references pktable - deferrable - initially deferred + id int4 primary key, + fk int4 references pktable deferrable initially deferred ); begin; @@ -1258,111 +1123,55 @@ commit; drop table pktable, fktable; create temporary table pktable ( - id1 int primary key, + id1 int4 primary key, id2 varchar(4) unique, id3 real unique, unique (id1, id2, id3) ); create temporary table fktable ( - x1 int references pktable (id1), + x1 int4 references pktable (id1), x2 varchar(4) references pktable (id2), x3 real references pktable (id3), x4 text, - x5 smallint + x5 int2 ); alter table fktable - add constraint "fk_2_3" - foreign key - (x2) - references pktable (id3); + add constraint fk_2_3 foreign key (x2) references pktable (id3); alter table fktable - add constraint "fk_2_1" - foreign key - (x2) - references pktable (id1); + add constraint fk_2_1 foreign key (x2) references pktable (id1); alter table fktable - add constraint "fk_3_1" - foreign key - (x3) - references pktable (id1); + add constraint fk_3_1 foreign key (x3) references pktable (id1); alter table fktable - add constraint "fk_1_2" - foreign key - (x1) - references pktable (id2); + add constraint fk_1_2 foreign key (x1) references pktable (id2); alter table fktable - add constraint "fk_1_3" - foreign key - (x1) - references pktable (id3); + add constraint fk_1_3 foreign key (x1) references pktable (id3); alter table fktable - add constraint "fk_4_2" - foreign key - (x4) - references pktable (id2); + add constraint fk_4_2 foreign key (x4) references pktable (id2); alter table fktable - add constraint "fk_5_1" - foreign key - (x5) - references pktable (id1); + add constraint fk_5_1 foreign key (x5) references pktable (id1); alter table fktable - add constraint "fk_123_123" - foreign key - (x1, - x2, - x3) - references pktable (id1, - id2, - id3); + add constraint fk_123_123 foreign key (x1, x2, x3) references pktable (id1, id2, id3); alter table fktable - add constraint "fk_213_213" - foreign key - (x2, - x1, - x3) - references pktable (id2, - id1, - id3); + add constraint fk_213_213 foreign key (x2, x1, x3) references pktable (id2, id1, id3); alter table fktable - add constraint "fk_253_213" - foreign key - (x2, - x5, - x3) - references pktable (id2, - id1, - id3); + add constraint fk_253_213 foreign key (x2, x5, x3) references pktable (id2, id1, id3); alter table fktable - add constraint "fk_123_231" - foreign key - (x1, - x2, - x3) - references pktable (id2, - id3, - id1); + add constraint fk_123_231 foreign key (x1, x2, x3) references pktable (id2, id3, id1); alter table fktable - add constraint "fk_241_132" - foreign key - (x2, - x4, - x1) - references pktable (id1, - id3, - id2); + add constraint fk_241_132 foreign key (x2, x4, x1) references pktable (id1, id3, id2); drop table pktable, fktable; @@ -1373,10 +1182,7 @@ create temporary table pktable ( create temporary table fktable ( id int primary key, - fk int - references pktable - deferrable - initially deferred + fk int references pktable deferrable initially deferred ); insert into pktable values (5, 10); @@ -1426,7 +1232,7 @@ commit; insert into fktable values (1, 5); alter table fktable - alter constraint "fktable_fk_fkey" deferrable initially immediate; + alter constraint fktable_fk_fkey deferrable initially immediate; begin; @@ -1449,7 +1255,7 @@ insert into fktable values (0, 20); rollback; alter table fktable - alter constraint "fktable_fk_fkey" not deferrable initially immediate; + alter constraint fktable_fk_fkey not deferrable initially immediate; create temporary table users ( id int primary key, @@ -1464,18 +1270,9 @@ insert into users values (3, 'Samko'); create temporary table tasks ( id int primary key, - owner int - references users - on DELETE set null - on UPDATE cascade, - worker int - references users - on DELETE set null - on UPDATE cascade, - checked_by int - references users - on DELETE set null - on UPDATE cascade + owner int references users on delete set null on update cascade, + worker int references users on delete set null on update cascade, + checked_by int references users on delete set null on update cascade ); insert into tasks values (1, 1, null, null); @@ -1509,11 +1306,7 @@ commit; create temporary table selfref ( a int primary key, b int, - foreign key - (b) - references selfref (a) - on DELETE cascade - on UPDATE cascade + foreign key (b) references selfref (a) on delete cascade on update cascade ); insert into selfref (a, b) values (0, 0), (1, 1); @@ -1532,7 +1325,7 @@ commit; create temporary table defp (f1 int primary key); -create temporary table defc (f1 int default 0 references defp on DELETE set default); +create temporary table defc (f1 int default 0 references defp on delete set default); insert into defp values (0), (1), (2); @@ -1577,7 +1370,7 @@ drop table pp, cc; create temporary table pp (f1 int primary key); -create temporary table cc (f1 int references pp on DELETE restrict on UPDATE restrict); +create temporary table cc (f1 int references pp on delete restrict on update restrict); insert into pp values (12); @@ -1649,17 +1442,9 @@ create table fktable2 ( a int, b int, very_very_long_column_name_to_exceed_63_characters int, - foreign key - (very_very_long_column_name_to_exceed_63_characters) - references pktable1, - foreign key - (a, - very_very_long_column_name_to_exceed_63_characters) - references pktable2, - foreign key - (a, - very_very_long_column_name_to_exceed_63_characters) - references pktable2 + foreign key (very_very_long_column_name_to_exceed_63_characters) references pktable1, + foreign key (a, very_very_long_column_name_to_exceed_63_characters) references pktable2, + foreign key (a, very_very_long_column_name_to_exceed_63_characters) references pktable2 ); select conname from pg_constraint where conrelid = cast('fktable2' as regclass) order by conname; @@ -1717,20 +1502,15 @@ commit; drop table pktable2, fktable2; create table pktable2 ( - a double precision, - b double precision, + a float8, + b float8, primary key (a, b) ); create table fktable2 ( - x double precision, - y double precision, - foreign key - (x, - y) - references pktable2 (a, - b) - on UPDATE cascade + x float8, + y float8, + foreign key (x, y) references pktable2 (a, b) on update cascade ); insert into pktable2 values ('-0', '-0'); @@ -1786,8 +1566,7 @@ alter table fk_partitioned_fk_1 alter table fk_partitioned_fk attach partition - fk_partitioned_fk_1 - for values from (0, 0) to (1000, 1000); + fk_partitioned_fk_1 for values from (0, 0) to (1000, 1000); create table fk_partitioned_fk_2 ( b int, @@ -1802,8 +1581,7 @@ alter table fk_partitioned_fk_2 alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values from (1000, 1000) to (2000, 2000); + fk_partitioned_fk_2 for values from (1000, 1000) to (2000, 2000); create table fk_partitioned_fk_3 ( fdrop1 int, @@ -1813,7 +1591,7 @@ create table fk_partitioned_fk_3 ( b int, a int ) -partition by HASH(a); +partition by hash(a); alter table fk_partitioned_fk_3 drop column fdrop1, @@ -1823,16 +1601,15 @@ alter table fk_partitioned_fk_3 create table fk_partitioned_fk_3_0 partition of fk_partitioned_fk_3 -for values with (MODULUS 5, REMAINDER 0); +for values with (modulus 5, remainder 0); create table fk_partitioned_fk_3_1 partition of fk_partitioned_fk_3 -for values with (MODULUS 5, REMAINDER 1); +for values with (modulus 5, remainder 1); alter table fk_partitioned_fk attach partition - fk_partitioned_fk_3 - for values from (2000, 2000) to (3000, 3000); + fk_partitioned_fk_3 for values from (2000, 2000) to (3000, 3000); alter table only fk_partitioned_fk add foreign key (a, b) references fk_notpartitioned_pk; @@ -1881,19 +1658,11 @@ select regexp_replace(tgname, '[0-9]+', 'N') as tgname, tgtype from - pg_trigger as t - inner join - pg_constraint as c - on t.tgconstraint = c.oid + pg_trigger as t inner join pg_constraint as c on t.tgconstraint = c.oid where tgrelid in ( - select - relid - from - pg_partition_tree( - cast('fk_partitioned_fk' as regclass) - ) + select relid from pg_partition_tree(cast('fk_partitioned_fk' as regclass)) union all select cast('fk_notpartitioned_pk' as regclass) ) @@ -1906,19 +1675,11 @@ select regexp_replace(tgname, '[0-9]+', 'N') as tgname, tgtype from - pg_trigger as t - inner join - pg_constraint as c - on t.tgconstraint = c.oid + pg_trigger as t inner join pg_constraint as c on t.tgconstraint = c.oid where tgrelid in ( - select - relid - from - pg_partition_tree( - cast('fk_partitioned_fk' as regclass) - ) + select relid from pg_partition_tree(cast('fk_partitioned_fk' as regclass)) union all select cast('fk_notpartitioned_pk' as regclass) ) @@ -1931,19 +1692,11 @@ select regexp_replace(tgname, '[0-9]+', 'N') as tgname, tgtype from - pg_trigger as t - inner join - pg_constraint as c - on t.tgconstraint = c.oid + pg_trigger as t inner join pg_constraint as c on t.tgconstraint = c.oid where tgrelid in ( - select - relid - from - pg_partition_tree( - cast('fk_partitioned_fk' as regclass) - ) + select relid from pg_partition_tree(cast('fk_partitioned_fk' as regclass)) union all select cast('fk_notpartitioned_pk' as regclass) ) @@ -1992,11 +1745,7 @@ create table fk_partitioned_fk ( partition by range(a, b); alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - not valid; + add foreign key (a, b) references fk_notpartitioned_pk not valid; create table fk_partitioned_fk_1 ( a int, @@ -2008,8 +1757,7 @@ alter table fk_partitioned_fk_1 alter table fk_partitioned_fk attach partition - fk_partitioned_fk_1 - for values from (0, 0) to (1000, 1000); + fk_partitioned_fk_1 for values from (0, 0) to (1000, 1000); select conname, @@ -2042,23 +1790,17 @@ create table fk_partitioned_fk_2 ( insert into fk_partitioned_fk_2 values (1000, 1000); alter table fk_partitioned_fk_2 - add foreign key - (a, - b) - references fk_notpartitioned_pk - not valid; + add foreign key (a, b) references fk_notpartitioned_pk not valid; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values from (1000, 1000) to (2000, 2000); + fk_partitioned_fk_2 for values from (1000, 1000) to (2000, 2000); truncate fk_partitioned_fk_2; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values from (1000, 1000) to (2000, 2000); + fk_partitioned_fk_2 for values from (1000, 1000) to (2000, 2000); select conname, @@ -2076,11 +1818,7 @@ create table fk_partitioned_fk_3 ( partition by range(a, b); alter table fk_partitioned_fk_3 - add foreign key - (a, - b) - references fk_notpartitioned_pk - not valid; + add foreign key (a, b) references fk_notpartitioned_pk not valid; create table fk_partitioned_fk_3_1 ( a int, @@ -2092,13 +1830,11 @@ alter table fk_partitioned_fk_3_1 alter table fk_partitioned_fk_3 attach partition - fk_partitioned_fk_3_1 - for values from (2000, 2000) to (3000, 3000); + fk_partitioned_fk_3_1 for values from (2000, 2000) to (3000, 3000); alter table fk_partitioned_fk attach partition - fk_partitioned_fk_3 - for values from (2000, 2000) to (3000, 3000); + fk_partitioned_fk_3 for values from (2000, 2000) to (3000, 3000); select conname, @@ -2137,12 +1873,9 @@ insert into fk_partitioned_pk values (100, 100), (1000, 1000); insert into fk_notpartitioned_fk values (100, 100), (1000, 1000); alter table fk_notpartitioned_fk - add constraint "fk_notpartitioned_fk_a_b_fkey" - foreign key - (a, - b) - references fk_partitioned_pk - not valid; + add constraint fk_notpartitioned_fk_a_b_fkey foreign key (a, b) + references fk_partitioned_pk + not valid; select conname, @@ -2151,8 +1884,7 @@ select from pg_constraint where - conrelid = - cast('fk_notpartitioned_fk' as regclass) + conrelid = cast('fk_notpartitioned_fk' as regclass) order by cast(cast(oid as regclass) as text); alter table fk_notpartitioned_fk @@ -2165,17 +1897,11 @@ select from pg_constraint where - conrelid = - cast('fk_notpartitioned_fk' as regclass) + conrelid = cast('fk_notpartitioned_fk' as regclass) order by cast(cast(oid as regclass) as text); alter table fk_partitioned_pk - add constraint "selffk" - foreign key - (a, - b) - references fk_partitioned_pk - not valid; + add constraint selffk foreign key (a, b) references fk_partitioned_pk not valid; create table fk_partitioned_pk_3 partition of fk_partitioned_pk @@ -2193,8 +1919,7 @@ select from pg_constraint where - conrelid = cast('fk_partitioned_pk' as regclass) and - contype = 'f' + conrelid = cast('fk_partitioned_pk' as regclass) and contype = 'f' order by cast(cast(oid as regclass) as text); alter table fk_partitioned_pk_2 @@ -2210,8 +1935,7 @@ select from pg_constraint where - conrelid = cast('fk_partitioned_pk' as regclass) and - contype = 'f' + conrelid = cast('fk_partitioned_pk' as regclass) and contype = 'f' order by cast(cast(oid as regclass) as text); drop table fk_notpartitioned_fk, fk_partitioned_pk; @@ -2226,17 +1950,12 @@ create table fk_partitioned_fk ( a int default 2501, b int default 142857 ) -partition by LIST(a); +partition by list(a); create table fk_partitioned_fk_1 partition of fk_partitioned_fk for values in (null, 500, 501, 502); alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE set null - on UPDATE set null; + add foreign key (a, b) references fk_notpartitioned_pk on delete set null on update set null; create table fk_partitioned_fk_2 partition of fk_partitioned_fk for values in (1500, 1502); @@ -2247,8 +1966,7 @@ create table fk_partitioned_fk_3 ( alter table fk_partitioned_fk attach partition - fk_partitioned_fk_3 - for values in (2500, 2501, 2502, 2503); + fk_partitioned_fk_3 for values in (2500, 2501, 2502, 2503); insert into fk_partitioned_fk (a, b) values (2502, 2503); @@ -2275,20 +1993,12 @@ create table fk_partitioned_fk_full_1 partition of fk_partitioned_fk_full defaul insert into fk_partitioned_fk_full values (1, null); alter table fk_partitioned_fk_full - add foreign key - (x, - y) - references fk_notpartitioned_pk - match full; + add foreign key (x, y) references fk_notpartitioned_pk match full; truncate fk_partitioned_fk_full; alter table fk_partitioned_fk_full - add foreign key - (x, - y) - references fk_notpartitioned_pk - match full; + add foreign key (x, y) references fk_notpartitioned_pk match full; insert into fk_partitioned_fk_full values (1, null); @@ -2302,22 +2012,20 @@ select cast(tableoid as regclass), a, b from fk_partitioned_fk where b is null o insert into fk_partitioned_fk values (2503, 2503); -select COUNT(*) from fk_partitioned_fk where a is null; +select count(*) from fk_partitioned_fk where a is null; delete from fk_notpartitioned_pk; -select COUNT(*) from fk_partitioned_fk where a is null; +select count(*) from fk_partitioned_fk where a is null; alter table fk_partitioned_fk drop constraint fk_partitioned_fk_a_b_fkey; alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE set default - on UPDATE set default; + add foreign key (a, b) + references fk_notpartitioned_pk + on delete set default + on update set default; insert into fk_notpartitioned_pk values (2502, 2503); @@ -2335,11 +2043,7 @@ alter table fk_partitioned_fk drop constraint fk_partitioned_fk_a_b_fkey; alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE set null (a); + add foreign key (a, b) references fk_notpartitioned_pk on delete set null (a); begin; @@ -2353,11 +2057,7 @@ alter table fk_partitioned_fk drop constraint fk_partitioned_fk_a_b_fkey; alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE set default (a); + add foreign key (a, b) references fk_notpartitioned_pk on delete set default (a); begin; @@ -2379,12 +2079,7 @@ alter table fk_partitioned_fk drop constraint fk_partitioned_fk_a_b_fkey; alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE cascade - on UPDATE cascade; + add foreign key (a, b) references fk_notpartitioned_pk on delete cascade on update cascade; update fk_notpartitioned_pk set a = 2502 where a = 2501; @@ -2420,12 +2115,7 @@ create table fk_partitioned_fk_2 ( b int, c text, a int, - foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE cascade - on UPDATE cascade + foreign key (a, b) references fk_notpartitioned_pk on delete cascade on update cascade ); alter table fk_partitioned_fk_2 @@ -2462,13 +2152,7 @@ drop table fk_partitioned_fk_2; create table fk_partitioned_fk_4 ( a int, b int, - foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b) - on DELETE cascade - on UPDATE cascade + foreign key (a, b) references fk_notpartitioned_pk (a, b) on delete cascade on update cascade ) partition by range(b, a); @@ -2479,18 +2163,12 @@ for values from (1, 1) to (100, 100); create table fk_partitioned_fk_4_2 ( a int, b int, - foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b) - on UPDATE set null + foreign key (a, b) references fk_notpartitioned_pk (a, b) on update set null ); alter table fk_partitioned_fk_4 attach partition - fk_partitioned_fk_4_2 - for values from (100, 100) to (1000, 1000); + fk_partitioned_fk_4_2 for values from (100, 100) to (1000, 1000); alter table fk_partitioned_fk attach partition @@ -2507,22 +2185,16 @@ alter table fk_partitioned_fk create table fk_partitioned_fk_5 ( a int, b int, - foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b) - on DELETE cascade - on UPDATE cascade - deferrable initially immediate, - foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b) - match full - on DELETE cascade - on UPDATE cascade + foreign key (a, b) + references fk_notpartitioned_pk (a, b) + on delete cascade + on update cascade + deferrable initially immediate, + foreign key (a, b) + references fk_notpartitioned_pk (a, b) + match full + on delete cascade + on update cascade ) partition by range(a); @@ -2583,7 +2255,7 @@ alter table fk_partitioned_fk create table fk_partitioned_pk_6 (a int primary key); create table fk_partitioned_fk_6 (a int references fk_partitioned_pk_6) -partition by LIST(a); +partition by list(a); alter table fk_partitioned_fk_6 attach partition @@ -2598,7 +2270,7 @@ create table fk_partitioned_fk_6 ( foreign key (a) references fk_partitioned_pk_6, foreign key (a) references fk_partitioned_pk_6 ) -partition by LIST(a); +partition by list(a); create table fk_partitioned_fk_6_1 partition of fk_partitioned_fk_6 for values in (1); @@ -2613,12 +2285,12 @@ alter table fk_partitioned_fk_6 drop table fk_partitioned_pk_6, fk_partitioned_fk_6; create table fk_partitioned_pk_6 (a int primary key) -partition by LIST(a); +partition by list(a); create table fk_partitioned_pk_61 partition of fk_partitioned_pk_6 for values in (1); create table fk_partitioned_fk_6 (a int references fk_partitioned_pk_61) -partition by LIST(a); +partition by list(a); alter table fk_partitioned_fk_6 attach partition @@ -2628,7 +2300,7 @@ drop table fk_partitioned_pk_6, fk_partitioned_fk_6; create role regress_other_partitioned_fk_owner; -grant REFERENCES on table fk_notpartitioned_pk to regress_other_partitioned_fk_owner; +grant references on table fk_notpartitioned_pk to regress_other_partitioned_fk_owner; set role to regress_other_partitioned_fk_owner; @@ -2636,18 +2308,14 @@ create table other_partitioned_fk ( a int, b int ) -partition by LIST(a); +partition by list(a); create table other_partitioned_fk_1 partition of other_partitioned_fk for values in (2048); insert into other_partitioned_fk select 2048, x from generate_series(1, 10) as x; alter table other_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b); + add foreign key (a, b) references fk_notpartitioned_pk (a, b); reset role; @@ -2656,11 +2324,7 @@ insert into fk_notpartitioned_pk (a, b) select 2048, x from generate_series(1, 1 set role to regress_other_partitioned_fk_owner; alter table other_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b); + add foreign key (a, b) references fk_notpartitioned_pk (a, b); drop table other_partitioned_fk; @@ -2673,9 +2337,7 @@ drop role regress_other_partitioned_fk_owner; create table parted_self_fk ( id bigint not null primary key, id_abc bigint, - foreign key - (id_abc) - references parted_self_fk (id) + foreign key (id_abc) references parted_self_fk (id) ) partition by range(id); @@ -2727,10 +2389,7 @@ select p.convalidated, cf.relname as foreignrel from - pg_constraint as co - inner join - pg_class as cr - on cr.oid = co.conrelid + pg_constraint as co inner join pg_class as cr on cr.oid = co.conrelid left outer join pg_class as cf on cf.oid = co.confrelid @@ -2738,14 +2397,7 @@ from pg_constraint as p on p.oid = co.conparentid where - co.contype = 'f' and - cr.oid in - ( - select - relid - from - pg_partition_tree('parted_self_fk') - ) + co.contype = 'f' and cr.oid in (select relid from pg_partition_tree('parted_self_fk')) order by cr.relname, co.conname, p.conname; @@ -2798,10 +2450,7 @@ select p.convalidated, cf.relname as foreignrel from - pg_constraint as co - inner join - pg_class as cr - on cr.oid = co.conrelid + pg_constraint as co inner join pg_class as cr on cr.oid = co.conrelid left outer join pg_class as cf on cf.oid = co.confrelid @@ -2809,24 +2458,17 @@ from pg_constraint as p on p.oid = co.conparentid where - co.contype = 'f' and - cr.oid in - ( - select - relid - from - pg_partition_tree('parted_self_fk') - ) + co.contype = 'f' and cr.oid in (select relid from pg_partition_tree('parted_self_fk')) order by cr.relname, co.conname, p.conname; -create schema "fkpart0"; +create schema fkpart0; create table pkey (a int primary key); create table fk_part (a int) -partition by LIST(a); +partition by list(a); create table fk_part_1 partition of fk_part @@ -2841,7 +2483,7 @@ partition of fk_part foreign key (a) references fkpart0.pkey ) for values in (2, 3) -partition by LIST(a); +partition by list(a); create table fk_part_23_2 partition of fk_part_23 for values in (2); @@ -2865,7 +2507,7 @@ alter table fkpart0.fk_part_4 create table fkpart0.fk_part_56 partition of fkpart0.fk_part for values in (5, 6) -partition by LIST(a); +partition by list(a); create table fkpart0.fk_part_56_5 partition of fkpart0.fk_part_56 for values in (5); @@ -2875,14 +2517,14 @@ alter table fkpart0.fk_part_56 alter table fkpart0.fk_part_56_5 drop constraint fk_part_a_fkey; -create schema "fkpart1"; +create schema fkpart1; create table pkey (a int primary key); create table fk_part (a int) -partition by LIST(a); +partition by list(a); -create table fk_part_1 partition of fk_part for values in (1) partition by LIST(a); +create table fk_part_1 partition of fk_part for values in (1) partition by list(a); create table fk_part_1_1 partition of fk_part_1 for values in (1); @@ -2907,27 +2549,21 @@ insert into fkpart1.fk_part_1 values (2); delete from fkpart1.pkey where a = 1; -create schema "fkpart2"; +create schema fkpart2; create table pkey (a int primary key); create table fk_part ( a int, - constraint "fkey" - foreign key - (a) - references fkpart2.pkey + constraint fkey foreign key (a) references fkpart2.pkey ) -partition by LIST(a); +partition by list(a); -create table fk_part_1 partition of fkpart2.fk_part for values in (1) partition by LIST(a); +create table fk_part_1 partition of fkpart2.fk_part for values in (1) partition by list(a); create table fk_part_1_1 ( a int, - constraint "my_fkey" - foreign key - (a) - references fkpart2.pkey + constraint my_fkey foreign key (a) references fkpart2.pkey ); alter table fkpart2.fk_part_1 @@ -2950,21 +2586,17 @@ alter table fkpart2.fk_part_1 alter table fkpart2.fk_part_1_1 drop constraint my_fkey; -create schema "fkpart3"; +create schema fkpart3; create table pkey (a int primary key); create table fk_part ( a int, - constraint "fkey" - foreign key - (a) - references fkpart3.pkey - deferrable initially immediate + constraint fkey foreign key (a) references fkpart3.pkey deferrable initially immediate ) -partition by LIST(a); +partition by list(a); -create table fk_part_1 partition of fkpart3.fk_part for values in (1) partition by LIST(a); +create table fk_part_1 partition of fkpart3.fk_part for values in (1) partition by list(a); create table fk_part_1_1 partition of fkpart3.fk_part_1 for values in (1); @@ -2992,7 +2624,7 @@ commit; drop schema fkpart0, fkpart1, fkpart2, fkpart3 cascade; -create schema "fkpart3"; +create schema fkpart3; set search_path to fkpart3; @@ -3135,7 +2767,7 @@ create table ffk ( a int, b int references pk ) -partition by LIST(a); +partition by list(a); create table ffk1 partition of ffk for values in (1); @@ -3148,7 +2780,7 @@ alter table ffk drop table ffk, ffk1; -create schema "fkpart4"; +create schema fkpart4; set search_path to fkpart4; @@ -3215,21 +2847,21 @@ alter table droppk2 drop table droppk2; -create schema "fkpart5"; +create schema fkpart5; set search_path to fkpart5; create table pk (a int primary key) -partition by LIST(a); +partition by list(a); -create table pk1 partition of pk for values in (1) partition by LIST(a); +create table pk1 partition of pk for values in (1) partition by list(a); create table pk11 partition of pk1 for values in (1); create table fk (a int) -partition by LIST(a); +partition by list(a); -create table fk1 partition of fk for values in (1) partition by LIST(a); +create table fk1 partition of fk for values in (1) partition by list(a); create table fk11 partition of fk1 for values in (1); @@ -3239,7 +2871,7 @@ alter table fk create table pk2 partition of pk for values in (2); create table pk3 (a int not null) -partition by LIST(a); +partition by list(a); create table pk31 partition of pk3 for values in (31); @@ -3274,28 +2906,16 @@ alter table fk fk3 for values in (3); select - pg_describe_object( - cast('pg_constraint' as regclass), - oid, - 0 - ), + pg_describe_object(cast('pg_constraint' as regclass), oid, 0), cast(confrelid as regclass), case - when conparentid <> 0 - then pg_describe_object( - cast('pg_constraint' as regclass), - conparentid, - 0 - ) + when conparentid <> 0 then pg_describe_object(cast('pg_constraint' as regclass), conparentid, 0) else 'TOP' end from pg_catalog.pg_constraint where - conrelid in - ( - select relid from pg_partition_tree('fk') - ) + conrelid in (select relid from pg_partition_tree('fk')) order by cast(cast(conrelid as regclass) as text), conname; @@ -3307,14 +2927,14 @@ alter table fk attach partition fk4 for values in (50); -create schema "fkpart9"; +create schema fkpart9; set search_path to fkpart9; create table pk (a int primary key) -partition by LIST(a); +partition by list(a); -create table pk1 partition of pk for values in (1, 2) partition by LIST(a); +create table pk1 partition of pk for values in (1, 2) partition by list(a); create table pk11 partition of pk1 for values in (1); @@ -3364,7 +2984,7 @@ create table ref ( f2 int, f3 int ) -partition by LIST(f1); +partition by list(f1); create table ref1 partition of ref for values in (1); @@ -3374,7 +2994,7 @@ alter table ref add foreign key (f1, f2) references pt; alter table ref - alter constraint "ref_f1_f2_fkey" deferrable initially deferred; + alter constraint ref_f1_f2_fkey deferrable initially deferred; insert into pt values (1, 2, 3); @@ -3402,13 +3022,13 @@ create table ref ( f2 int, f3 int ) -partition by LIST(f1); +partition by list(f1); -create table ref1_2 partition of ref for values in (1, 2) partition by LIST(f2); +create table ref1_2 partition of ref for values in (1, 2) partition by list(f2); create table ref1 partition of ref1_2 for values in (1); -create table ref2 partition of ref1_2 for values in (2) partition by LIST(f2); +create table ref2 partition of ref1_2 for values in (2) partition by list(f2); create table ref22 partition of ref2 for values in (2); @@ -3420,10 +3040,10 @@ insert into pt values (1, 2, 3); insert into ref values (1, 2, 3); alter table ref22 - alter constraint "ref_f1_f2_fkey" deferrable initially immediate; + alter constraint ref_f1_f2_fkey deferrable initially immediate; alter table ref - alter constraint "ref_f1_f2_fkey" deferrable initially deferred; + alter constraint ref_f1_f2_fkey deferrable initially deferred; begin; @@ -3441,7 +3061,7 @@ create table pt ( f3 int, primary key (f1, f2) ) -partition by LIST(f1); +partition by list(f1); create table pt1 partition of pt for values in (1); @@ -3457,7 +3077,7 @@ alter table ref add foreign key (f1, f2) references pt; alter table ref - alter constraint "ref_f1_f2_fkey" deferrable initially deferred; + alter constraint ref_f1_f2_fkey deferrable initially deferred; insert into pt values (1, 2, 3); @@ -3479,9 +3099,9 @@ create table pt ( f3 int, primary key (f1, f2) ) -partition by LIST(f1); +partition by list(f1); -create table pt1_2 partition of pt for values in (1, 2) partition by LIST(f1); +create table pt1_2 partition of pt for values in (1, 2) partition by list(f1); create table pt1 partition of pt1_2 for values in (1); @@ -3497,10 +3117,10 @@ alter table ref add foreign key (f1, f2) references pt; alter table ref - alter constraint "ref_f1_f2_fkey_1" deferrable initially deferred; + alter constraint ref_f1_f2_fkey_1 deferrable initially deferred; alter table ref - alter constraint "ref_f1_f2_fkey" deferrable initially deferred; + alter constraint ref_f1_f2_fkey deferrable initially deferred; insert into pt values (1, 2, 3); @@ -3518,7 +3138,7 @@ drop table pt, ref; drop schema fkpart9 cascade; -create schema "fkpart6"; +create schema fkpart6; set search_path to fkpart6; @@ -3541,11 +3161,7 @@ create table fk11 partition of fk1 for values from (1) to (10); create table fk12 partition of fk1 for values from (10) to (100); alter table fk - add foreign key - (a) - references pk - on DELETE cascade - on UPDATE cascade; + add foreign key (a) references pk on delete cascade on update cascade; create table fk_d partition of fk default; @@ -3577,11 +3193,7 @@ create table fk11 partition of fk1 for values from (1) to (10); create table fk12 partition of fk1 for values from (10) to (100); alter table fk - add foreign key - (a) - references pk - on DELETE set null - on UPDATE set null; + add foreign key (a) references pk on delete set null on update set null; create table fk_d partition of fk default; @@ -3612,11 +3224,7 @@ create table fk11 partition of fk1 for values from (1) to (10); create table fk12 partition of fk1 for values from (10) to (100); alter table fk - add foreign key - (a) - references pk - on DELETE set default - on UPDATE set default; + add foreign key (a) references pk on delete set default on update set default; create table fk_d partition of fk default; @@ -3644,11 +3252,7 @@ create table fk11 partition of fk1 for values from (1) to (10); create table fk12 partition of fk1 for values from (10) to (100); alter table fk - add foreign key - (a) - references pk - on DELETE restrict - on UPDATE restrict; + add foreign key (a) references pk on delete restrict on update restrict; create table fk_d partition of fk default; @@ -3662,10 +3266,10 @@ select cast(tableoid as regclass), * from fk; drop table fk; -create schema "fkpart7"; +create schema fkpart7; create table pkpart (a int) -partition by LIST(a); +partition by list(a); create table pkpart1 partition of pkpart for values in (1); @@ -3679,7 +3283,7 @@ create table fkpart7.fk (a int references fkpart7.pkpart); drop schema fkpart7 cascade; -create schema "fkpart8"; +create schema fkpart8; create table tbl1 (f1 int primary key); @@ -3701,12 +3305,12 @@ commit; drop schema fkpart8 cascade; -create schema "fkpart9"; +create schema fkpart9; create table pk (a int primary key) partition by range(a); -create table fk (fk_a int references pk (a) on DELETE cascade); +create table fk (fk_a int references pk (a) on delete cascade); create table pk1 partition of pk for values from (30) to (50) partition by range(a); @@ -3724,7 +3328,7 @@ select * from fkpart9.fk; drop schema fkpart9 cascade; -create schema "fkpart10"; +create schema fkpart10; create table tbl1 (f1 int primary key) partition by range(f1); @@ -3818,46 +3422,31 @@ commit; drop schema fkpart10 cascade; -create schema "fkpart11"; +create schema fkpart11; create table pk ( a int primary key, b text ) -partition by LIST(a); +partition by list(a); create table fk ( a int, - constraint "fkey" - foreign key - (a) - references pk (a) - on DELETE cascade - on UPDATE cascade + constraint fkey foreign key (a) references pk (a) on delete cascade on update cascade ); create table fk_parted ( a int primary key, - constraint "fkey" - foreign key - (a) - references pk (a) - on DELETE cascade - on UPDATE cascade + constraint fkey foreign key (a) references pk (a) on delete cascade on update cascade ) -partition by LIST(a); +partition by list(a); create table fk_another ( a int, - constraint "fkey" - foreign key - (a) - references fk_parted (a) - on DELETE cascade - on UPDATE cascade + constraint fkey foreign key (a) references fk_parted (a) on delete cascade on update cascade ); -create table pk1 partition of pk for values in (1, 2) partition by LIST(a); +create table pk1 partition of pk for values in (1, 2) partition by list(a); create table pk2 partition of pk for values in (3); @@ -3899,13 +3488,13 @@ insert into fkpart11.fk_parted values (1), (3); insert into fkpart11.fk_another values (1), (3); -update fkpart11.pk set a = a + 1 returning cast(tableoid as regclass), *; +update fkpart11.pk set a = a + 1 returning cast(tableoid as pg_catalog.regclass), *; -select cast(tableoid as regclass), * from fkpart11.fk; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk; -select cast(tableoid as regclass), * from fkpart11.fk_parted; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk_parted; -select cast(tableoid as regclass), * from fkpart11.fk_another; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk_another; alter table fkpart11.fk drop constraint fkey; @@ -3913,51 +3502,47 @@ alter table fkpart11.fk delete from fkpart11.fk where a = 4; alter table fkpart11.fk - add constraint "fkey" - foreign key - (a) - references fkpart11.pk1 (a) - on DELETE cascade - on UPDATE cascade; + add constraint fkey foreign key (a) + references fkpart11.pk1 (a) + on delete cascade + on update cascade; update fkpart11.pk set a = a - 1; update fkpart11.pk1 set a = a - 1; -select cast(tableoid as regclass), * from fkpart11.pk; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.pk; -select cast(tableoid as regclass), * from fkpart11.fk; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk; -select cast(tableoid as regclass), * from fkpart11.fk_parted; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk_parted; -select cast(tableoid as regclass), * from fkpart11.fk_another; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk_another; alter table fkpart11.fk drop constraint fkey; alter table fkpart11.fk - add constraint "fkey" - foreign key - (a) - references fkpart11.pk11 (a) - on DELETE cascade - on UPDATE cascade; + add constraint fkey foreign key (a) + references fkpart11.pk11 (a) + on delete cascade + on update cascade; update fkpart11.pk set a = a + 1 where a = 1; -select cast(tableoid as regclass), * from fkpart11.fk; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk; drop table fkpart11.fk; create function fkpart11.print_row() returns trigger language plpgsql -as $function$ -BEGIN +as $$ + BEGIN RAISE NOTICE 'TABLE: %, OP: %, OLD: %, NEW: %', TG_RELNAME, TG_OP, OLD, NEW; RETURN NULL; END; -$function$; +$$; create trigger trig_upd_pk after update @@ -4007,16 +3592,16 @@ update fkpart11.pk set a = 1 where a = 2; drop schema fkpart11 cascade; -create schema "fkpart12"; +create schema fkpart12; create table fk_p ( id int, jd int, primary key (id, jd) ) -partition by LIST(id); +partition by list(id); -create table fk_p_1 partition of fk_p for values in (1) partition by LIST(jd); +create table fk_p_1 partition of fk_p for values in (1) partition by list(jd); create table fk_p_1_1 partition of fk_p_1 for values in (1); @@ -4027,7 +3612,7 @@ create table fk_p_1_2 ( id int not null ); -create table fk_p_2 partition of fk_p for values in (2) partition by LIST(jd); +create table fk_p_2 partition of fk_p for values in (2) partition by list(jd); create table fk_p_2_1 partition of fk_p_2 for values in (1); @@ -4045,7 +3630,7 @@ create table fk_r_2 ( p_id int not null, p_jd int not null ) -partition by LIST(id); +partition by list(id); create table fk_r_2_1 partition of fk_r_2 for values in (2, 1); @@ -4055,7 +3640,7 @@ create table fk_r ( p_jd int not null, foreign key (p_id, p_jd) references fk_p (id, jd) ) -partition by LIST(id); +partition by list(id); set search_path to fkpart12; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_key_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_key_80.snap index 4d60c09db..74a8973af 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_key_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_key_80.snap @@ -56,14 +56,11 @@ create table fktable ( ftest1 int, ftest2 int, ftest3 int, - constraint "constrname" - foreign key - (ftest1, - ftest2) - references pktable - match full - on DELETE set null - on UPDATE set null + constraint constrname foreign key (ftest1, ftest2) + references pktable + match full + on delete set null + on update set null ); comment on constraint constrname_wrong on fktable is 'fk constraint comment'; @@ -145,14 +142,11 @@ create table fktable ( ftest1 int default -1, ftest2 int default -2, ftest3 int, - constraint "constrname2" - foreign key - (ftest1, - ftest2) - references pktable - match full - on DELETE set default - on UPDATE set default + constraint constrname2 foreign key (ftest1, ftest2) + references pktable + match full + on delete set default + on update set default ); insert into pktable values (-1, -2, 'The Default!'); @@ -273,14 +267,10 @@ insert into pktable values (1, 2); insert into fktable values (1, null); alter table fktable - add foreign key - (ftest1, - ftest2) - references pktable - match full; + add foreign key (ftest1, ftest2) references pktable match full; alter table fktable - alter constraint "fk_con" deferrable initially deferred; + alter constraint fk_con deferrable initially deferred; select condeferrable, @@ -339,12 +329,7 @@ create table fktable ( ftest2 int, ftest3 int, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable + constraint constrname3 foreign key (ftest1, ftest2, ftest3) references pktable ); insert into pktable values (1, 2, 3, 'test1'); @@ -398,14 +383,8 @@ create table fktable ( ftest2 int, ftest3 int, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable (ptest1, - ptest2, - ptest3) + constraint constrname3 foreign key (ftest1, ftest2, ftest3) + references pktable (ptest1, ptest2, ptest3) ); insert into pktable values (1, 2, 3, 'test1'); @@ -439,14 +418,10 @@ create table fktable ( ftest2 int, ftest3 int, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable - on DELETE cascade - on UPDATE cascade + constraint constrname3 foreign key (ftest1, ftest2, ftest3) + references pktable + on delete cascade + on update cascade ); insert into pktable values (1, 2, 3, 'test1'); @@ -508,14 +483,10 @@ create table fktable ( ftest2 int, ftest3 int, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable - on DELETE set default - on UPDATE set null + constraint constrname3 foreign key (ftest1, ftest2, ftest3) + references pktable + on delete set default + on update set null ); insert into pktable values (1, 2, 3, 'test1'); @@ -579,14 +550,10 @@ create table fktable ( ftest2 int default -1, ftest3 int default -2, ftest4 int, - constraint "constrname3" - foreign key - (ftest1, - ftest2, - ftest3) - references pktable - on DELETE set null - on UPDATE set default + constraint constrname3 foreign key (ftest1, ftest2, ftest3) + references pktable + on delete set null + on update set default ); insert into pktable values (1, 2, 3, 'test1'); @@ -655,22 +622,14 @@ create table fktable ( tid int, id int, foo int, - foreign key - (tid, - id) - references pktable - on DELETE set null (bar) + foreign key (tid, id) references pktable on delete set null (bar) ); create table fktable ( tid int, id int, foo int, - foreign key - (tid, - id) - references pktable - on DELETE set null (foo) + foreign key (tid, id) references pktable on delete set null (foo) ); create table fktable ( @@ -678,17 +637,12 @@ create table fktable ( id int, fk_id_del_set_null int, fk_id_del_set_default int default 0, - foreign key - (tid, - fk_id_del_set_null) - references pktable - on DELETE set null (fk_id_del_set_null), - foreign key - (tid, - fk_id_del_set_default) - references pktable - on DELETE set default (fk_id_del_set_default, - fk_id_del_set_default) + foreign key (tid, fk_id_del_set_null) + references pktable + on delete set null (fk_id_del_set_null), + foreign key (tid, fk_id_del_set_default) + references pktable + on delete set default (fk_id_del_set_default, fk_id_del_set_default) ); select @@ -696,8 +650,7 @@ select from pg_constraint where - conrelid = - cast(cast('fktable' as regclass) as oid) + conrelid = cast(cast('fktable' as regclass) as oid) order by oid; insert into pktable values (1, 0), (1, 1), (1, 2); @@ -719,34 +672,22 @@ create table pktable ( create table fktable_fail1 ( ftest1 int, - constraint "fkfail1" - foreign key - (ftest2) - references pktable + constraint fkfail1 foreign key (ftest2) references pktable ); create table fktable_fail2 ( ftest1 int, - constraint "fkfail1" - foreign key - (ftest1) - references pktable (ptest2) + constraint fkfail1 foreign key (ftest1) references pktable (ptest2) ); create table fktable_fail3 ( ftest1 int, - constraint "fkfail1" - foreign key - (tableoid) - references pktable (someoid) + constraint fkfail1 foreign key (tableoid) references pktable (someoid) ); create table fktable_fail4 ( ftest1 oid, - constraint "fkfail1" - foreign key - (ftest1) - references pktable (tableoid) + constraint fkfail1 foreign key (ftest1) references pktable (tableoid) ); drop table pktable; @@ -771,7 +712,7 @@ create table fktable (ftest1 inet references pktable); create table fktable (ftest1 inet references pktable (ptest1)); -create table fktable (ftest1 bigint references pktable); +create table fktable (ftest1 int8 references pktable); insert into fktable values (42); @@ -814,59 +755,37 @@ create table pktable ( create table fktable ( ftest1 cidr, ftest2 timestamp, - foreign key - (ftest1, - ftest2) - references pktable + foreign key (ftest1, ftest2) references pktable ); create table fktable ( ftest1 cidr, ftest2 timestamp, - foreign key - (ftest1, - ftest2) - references pktable (ptest1, - ptest2) + foreign key (ftest1, ftest2) references pktable (ptest1, ptest2) ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest2, - ftest1) - references pktable + foreign key (ftest2, ftest1) references pktable ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest2, - ftest1) - references pktable (ptest1, - ptest2) + foreign key (ftest2, ftest1) references pktable (ptest1, ptest2) ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest1, - ftest2) - references pktable (ptest2, - ptest1) + foreign key (ftest1, ftest2) references pktable (ptest2, ptest1) ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest2, - ftest1) - references pktable (ptest2, - ptest1) + foreign key (ftest2, ftest1) references pktable (ptest2, ptest1) ); drop table fktable; @@ -874,11 +793,7 @@ drop table fktable; create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest1, - ftest2) - references pktable (ptest1, - ptest2) + foreign key (ftest1, ftest2) references pktable (ptest1, ptest2) ); drop table fktable; @@ -891,11 +806,7 @@ create table pktable ( ptest3 int, ptest4 inet, primary key (ptest1, ptest2), - foreign key - (ptest3, - ptest4) - references pktable (ptest1, - ptest2) + foreign key (ptest3, ptest4) references pktable (ptest1, ptest2) ); drop table pktable; @@ -906,10 +817,7 @@ create table pktable ( ptest3 int, ptest4 inet, primary key (ptest1, ptest2), - foreign key - (ptest3, - ptest4) - references pktable + foreign key (ptest3, ptest4) references pktable ); drop table pktable; @@ -920,11 +828,7 @@ create table pktable ( ptest3 int, ptest4 inet, primary key (ptest1, ptest2), - foreign key - (ptest3, - ptest4) - references pktable (ptest2, - ptest1) + foreign key (ptest3, ptest4) references pktable (ptest2, ptest1) ); create table pktable ( @@ -933,11 +837,7 @@ create table pktable ( ptest3 int, ptest4 inet, primary key (ptest1, ptest2), - foreign key - (ptest4, - ptest3) - references pktable (ptest1, - ptest2) + foreign key (ptest4, ptest3) references pktable (ptest1, ptest2) ); create table pktable ( @@ -946,10 +846,7 @@ create table pktable ( ptest3 int, ptest4 inet, primary key (ptest1, ptest2), - foreign key - (ptest4, - ptest3) - references pktable + foreign key (ptest4, ptest3) references pktable ); create table pktable_base (base1 int not null); @@ -988,11 +885,7 @@ delete from pktable; create table fktable ( ftest1 int, ftest2 int, - foreign key - (ftest1, - ftest2) - references pktable (base1, - ptest1) + foreign key (ftest1, ftest2) references pktable (base1, ptest1) ); insert into pktable (base1, ptest1) values (1, 1); @@ -1028,11 +921,7 @@ create table pktable ( ptest1 int, ptest2 int, primary key (base1, ptest1), - foreign key - (base2, - ptest2) - references pktable (base1, - ptest1) + foreign key (base2, ptest2) references pktable (base1, ptest1) ) inherits (pktable_base); @@ -1069,49 +958,31 @@ inherits (pktable_base); create table fktable ( ftest1 cidr, ftest2 int[], - foreign key - (ftest1, - ftest2) - references pktable + foreign key (ftest1, ftest2) references pktable ); create table fktable ( ftest1 cidr, ftest2 int[], - foreign key - (ftest1, - ftest2) - references pktable (base1, - ptest1) + foreign key (ftest1, ftest2) references pktable (base1, ptest1) ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest2, - ftest1) - references pktable + foreign key (ftest2, ftest1) references pktable ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest2, - ftest1) - references pktable (base1, - ptest1) + foreign key (ftest2, ftest1) references pktable (base1, ptest1) ); create table fktable ( ftest1 int, ftest2 inet, - foreign key - (ftest1, - ftest2) - references pktable (ptest1, - base1) + foreign key (ftest1, ftest2) references pktable (ptest1, base1) ); drop table pktable; @@ -1127,11 +998,7 @@ create table pktable ( ptest1 inet, ptest2 inet[], primary key (base1, ptest1), - foreign key - (base2, - ptest2) - references pktable (base1, - ptest1) + foreign key (base2, ptest2) references pktable (base1, ptest1) ) inherits (pktable_base); @@ -1139,11 +1006,7 @@ create table pktable ( ptest1 inet, ptest2 inet, primary key (base1, ptest1), - foreign key - (base2, - ptest2) - references pktable (ptest1, - base1) + foreign key (base2, ptest2) references pktable (ptest1, base1) ) inherits (pktable_base); @@ -1151,11 +1014,7 @@ create table pktable ( ptest1 inet, ptest2 inet, primary key (base1, ptest1), - foreign key - (ptest2, - base2) - references pktable (base1, - ptest1) + foreign key (ptest2, base2) references pktable (base1, ptest1) ) inherits (pktable_base); @@ -1163,11 +1022,7 @@ create table pktable ( ptest1 inet, ptest2 inet, primary key (base1, ptest1), - foreign key - (ptest2, - base2) - references pktable (base1, - ptest1) + foreign key (ptest2, base2) references pktable (base1, ptest1) ) inherits (pktable_base); @@ -1176,13 +1031,13 @@ drop table pktable; drop table pktable_base; create table pktable ( - id int primary key, - other int + id int4 primary key, + other int4 ); create table fktable ( - id int primary key, - fk int references pktable deferrable + id int4 primary key, + fk int4 references pktable deferrable ); insert into fktable values (5, 10); @@ -1200,16 +1055,13 @@ commit; drop table fktable, pktable; create table pktable ( - id int primary key, - other int + id int4 primary key, + other int4 ); create table fktable ( - id int primary key, - fk int - references pktable - deferrable - initially deferred + id int4 primary key, + fk int4 references pktable deferrable initially deferred ); begin; @@ -1231,13 +1083,13 @@ commit; drop table fktable, pktable; create table pktable ( - id int primary key, - other int + id int4 primary key, + other int4 ); create table fktable ( - id int primary key, - fk int references pktable deferrable + id int4 primary key, + fk int4 references pktable deferrable ); begin; @@ -1255,16 +1107,13 @@ commit; drop table fktable, pktable; create table pktable ( - id int primary key, - other int + id int4 primary key, + other int4 ); create table fktable ( - id int primary key, - fk int - references pktable - deferrable - initially deferred + id int4 primary key, + fk int4 references pktable deferrable initially deferred ); begin; @@ -1276,111 +1125,60 @@ commit; drop table pktable, fktable; create temporary table pktable ( - id1 int primary key, + id1 int4 primary key, id2 varchar(4) unique, id3 real unique, unique (id1, id2, id3) ); create temporary table fktable ( - x1 int references pktable (id1), + x1 int4 references pktable (id1), x2 varchar(4) references pktable (id2), x3 real references pktable (id3), x4 text, - x5 smallint + x5 int2 ); alter table fktable - add constraint "fk_2_3" - foreign key - (x2) - references pktable (id3); + add constraint fk_2_3 foreign key (x2) references pktable (id3); alter table fktable - add constraint "fk_2_1" - foreign key - (x2) - references pktable (id1); + add constraint fk_2_1 foreign key (x2) references pktable (id1); alter table fktable - add constraint "fk_3_1" - foreign key - (x3) - references pktable (id1); + add constraint fk_3_1 foreign key (x3) references pktable (id1); alter table fktable - add constraint "fk_1_2" - foreign key - (x1) - references pktable (id2); + add constraint fk_1_2 foreign key (x1) references pktable (id2); alter table fktable - add constraint "fk_1_3" - foreign key - (x1) - references pktable (id3); + add constraint fk_1_3 foreign key (x1) references pktable (id3); alter table fktable - add constraint "fk_4_2" - foreign key - (x4) - references pktable (id2); + add constraint fk_4_2 foreign key (x4) references pktable (id2); alter table fktable - add constraint "fk_5_1" - foreign key - (x5) - references pktable (id1); + add constraint fk_5_1 foreign key (x5) references pktable (id1); alter table fktable - add constraint "fk_123_123" - foreign key - (x1, - x2, - x3) - references pktable (id1, - id2, - id3); + add constraint fk_123_123 foreign key (x1, x2, x3) + references pktable (id1, id2, id3); alter table fktable - add constraint "fk_213_213" - foreign key - (x2, - x1, - x3) - references pktable (id2, - id1, - id3); + add constraint fk_213_213 foreign key (x2, x1, x3) + references pktable (id2, id1, id3); alter table fktable - add constraint "fk_253_213" - foreign key - (x2, - x5, - x3) - references pktable (id2, - id1, - id3); + add constraint fk_253_213 foreign key (x2, x5, x3) + references pktable (id2, id1, id3); alter table fktable - add constraint "fk_123_231" - foreign key - (x1, - x2, - x3) - references pktable (id2, - id3, - id1); + add constraint fk_123_231 foreign key (x1, x2, x3) + references pktable (id2, id3, id1); alter table fktable - add constraint "fk_241_132" - foreign key - (x2, - x4, - x1) - references pktable (id1, - id3, - id2); + add constraint fk_241_132 foreign key (x2, x4, x1) + references pktable (id1, id3, id2); drop table pktable, fktable; @@ -1391,10 +1189,7 @@ create temporary table pktable ( create temporary table fktable ( id int primary key, - fk int - references pktable - deferrable - initially deferred + fk int references pktable deferrable initially deferred ); insert into pktable values (5, 10); @@ -1444,7 +1239,7 @@ commit; insert into fktable values (1, 5); alter table fktable - alter constraint "fktable_fk_fkey" deferrable initially immediate; + alter constraint fktable_fk_fkey deferrable initially immediate; begin; @@ -1467,7 +1262,7 @@ insert into fktable values (0, 20); rollback; alter table fktable - alter constraint "fktable_fk_fkey" not deferrable initially immediate; + alter constraint fktable_fk_fkey not deferrable initially immediate; create temporary table users ( id int primary key, @@ -1482,18 +1277,9 @@ insert into users values (3, 'Samko'); create temporary table tasks ( id int primary key, - owner int - references users - on DELETE set null - on UPDATE cascade, - worker int - references users - on DELETE set null - on UPDATE cascade, - checked_by int - references users - on DELETE set null - on UPDATE cascade + owner int references users on delete set null on update cascade, + worker int references users on delete set null on update cascade, + checked_by int references users on delete set null on update cascade ); insert into tasks values (1, 1, null, null); @@ -1527,11 +1313,7 @@ commit; create temporary table selfref ( a int primary key, b int, - foreign key - (b) - references selfref (a) - on DELETE cascade - on UPDATE cascade + foreign key (b) references selfref (a) on delete cascade on update cascade ); insert into selfref (a, b) values (0, 0), (1, 1); @@ -1551,9 +1333,7 @@ commit; create temporary table defp (f1 int primary key); create temporary table defc ( - f1 int - default 0 - references defp on DELETE set default + f1 int default 0 references defp on delete set default ); insert into defp values (0), (1), (2); @@ -1600,10 +1380,7 @@ drop table pp, cc; create temporary table pp (f1 int primary key); create temporary table cc ( - f1 int - references pp - on DELETE restrict - on UPDATE restrict + f1 int references pp on delete restrict on update restrict ); insert into pp values (12); @@ -1676,17 +1453,12 @@ create table fktable2 ( a int, b int, very_very_long_column_name_to_exceed_63_characters int, - foreign key - (very_very_long_column_name_to_exceed_63_characters) - references pktable1, - foreign key - (a, - very_very_long_column_name_to_exceed_63_characters) - references pktable2, - foreign key - (a, - very_very_long_column_name_to_exceed_63_characters) - references pktable2 + foreign key (very_very_long_column_name_to_exceed_63_characters) + references pktable1, + foreign key (a, very_very_long_column_name_to_exceed_63_characters) + references pktable2, + foreign key (a, very_very_long_column_name_to_exceed_63_characters) + references pktable2 ); select @@ -1702,10 +1474,7 @@ drop table pktable1, pktable2, fktable2; create table pktable2 (f1 int primary key); create table fktable2 ( - f1 int - references pktable2 - deferrable - initially deferred + f1 int references pktable2 deferrable initially deferred ); insert into pktable2 values (1); @@ -1755,20 +1524,15 @@ commit; drop table pktable2, fktable2; create table pktable2 ( - a double precision, - b double precision, + a float8, + b float8, primary key (a, b) ); create table fktable2 ( - x double precision, - y double precision, - foreign key - (x, - y) - references pktable2 (a, - b) - on UPDATE cascade + x float8, + y float8, + foreign key (x, y) references pktable2 (a, b) on update cascade ); insert into pktable2 values ('-0', '-0'); @@ -1824,8 +1588,7 @@ alter table fk_partitioned_fk_1 alter table fk_partitioned_fk attach partition - fk_partitioned_fk_1 - for values from (0, 0) to (1000, 1000); + fk_partitioned_fk_1 for values from (0, 0) to (1000, 1000); create table fk_partitioned_fk_2 ( b int, @@ -1840,10 +1603,7 @@ alter table fk_partitioned_fk_2 alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values from (1000, - 1000) to (2000, - 2000); + fk_partitioned_fk_2 for values from (1000, 1000) to (2000, 2000); create table fk_partitioned_fk_3 ( fdrop1 int, @@ -1853,7 +1613,7 @@ create table fk_partitioned_fk_3 ( b int, a int ) -partition by HASH(a); +partition by hash(a); alter table fk_partitioned_fk_3 drop column fdrop1, @@ -1863,24 +1623,18 @@ alter table fk_partitioned_fk_3 create table fk_partitioned_fk_3_0 partition of fk_partitioned_fk_3 -for values with (MODULUS 5, REMAINDER 0); +for values with (modulus 5, remainder 0); create table fk_partitioned_fk_3_1 partition of fk_partitioned_fk_3 -for values with (MODULUS 5, REMAINDER 1); +for values with (modulus 5, remainder 1); alter table fk_partitioned_fk attach partition - fk_partitioned_fk_3 - for values from (2000, - 2000) to (3000, - 3000); + fk_partitioned_fk_3 for values from (2000, 2000) to (3000, 3000); alter table only fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk; + add foreign key (a, b) references fk_notpartitioned_pk; insert into fk_partitioned_fk (a, b) values (500, 501); @@ -1899,11 +1653,7 @@ insert into fk_partitioned_fk (a, b) values (2501, 2503); insert into fk_partitioned_fk_3 (a, b) values (2501, 2503); insert into fk_notpartitioned_pk -values - (500, 501), - (1500, 1501), - (2500, 2502), - (2501, 2503); +values (500, 501), (1500, 1501), (2500, 2502), (2501, 2503); insert into fk_partitioned_fk (a, b) values (500, 501); @@ -1928,26 +1678,16 @@ update fk_notpartitioned_pk set b = 2504 where a = 2500; select conname, cast(tgrelid as regclass) as tgrel, - regexp_replace(tgname, '[0-9]+', 'N') - as tgname, + regexp_replace(tgname, '[0-9]+', 'N') as tgname, tgtype from - pg_trigger as t - inner join - pg_constraint as c - on t.tgconstraint = c.oid + pg_trigger as t inner join pg_constraint as c on t.tgconstraint = c.oid where tgrelid in ( - select - relid - from - pg_partition_tree( - cast('fk_partitioned_fk' as regclass) - ) + select relid from pg_partition_tree(cast('fk_partitioned_fk' as regclass)) union all - select - cast('fk_notpartitioned_pk' as regclass) + select cast('fk_notpartitioned_pk' as regclass) ) order by tgrelid, tgtype; @@ -1955,26 +1695,16 @@ order by tgrelid, select conname, cast(tgrelid as regclass) as tgrel, - regexp_replace(tgname, '[0-9]+', 'N') - as tgname, + regexp_replace(tgname, '[0-9]+', 'N') as tgname, tgtype from - pg_trigger as t - inner join - pg_constraint as c - on t.tgconstraint = c.oid + pg_trigger as t inner join pg_constraint as c on t.tgconstraint = c.oid where tgrelid in ( - select - relid - from - pg_partition_tree( - cast('fk_partitioned_fk' as regclass) - ) + select relid from pg_partition_tree(cast('fk_partitioned_fk' as regclass)) union all - select - cast('fk_notpartitioned_pk' as regclass) + select cast('fk_notpartitioned_pk' as regclass) ) order by tgrelid, tgtype; @@ -1982,26 +1712,16 @@ order by tgrelid, select conname, cast(tgrelid as regclass) as tgrel, - regexp_replace(tgname, '[0-9]+', 'N') - as tgname, + regexp_replace(tgname, '[0-9]+', 'N') as tgname, tgtype from - pg_trigger as t - inner join - pg_constraint as c - on t.tgconstraint = c.oid + pg_trigger as t inner join pg_constraint as c on t.tgconstraint = c.oid where tgrelid in ( - select - relid - from - pg_partition_tree( - cast('fk_partitioned_fk' as regclass) - ) + select relid from pg_partition_tree(cast('fk_partitioned_fk' as regclass)) union all - select - cast('fk_notpartitioned_pk' as regclass) + select cast('fk_notpartitioned_pk' as regclass) ) order by tgrelid, tgtype; @@ -2018,9 +1738,7 @@ create table fk_notpartitioned_pk ( ); create table fk_partitioned_fk ( - a int - references fk_notpartitioned_pk (a) - primary key + a int references fk_notpartitioned_pk (a) primary key ) partition by range(a); @@ -2052,11 +1770,7 @@ create table fk_partitioned_fk ( partition by range(a, b); alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - not valid; + add foreign key (a, b) references fk_notpartitioned_pk not valid; create table fk_partitioned_fk_1 ( a int, @@ -2064,15 +1778,11 @@ create table fk_partitioned_fk_1 ( ); alter table fk_partitioned_fk_1 - add foreign key - (a, - b) - references fk_notpartitioned_pk; + add foreign key (a, b) references fk_notpartitioned_pk; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_1 - for values from (0, 0) to (1000, 1000); + fk_partitioned_fk_1 for values from (0, 0) to (1000, 1000); select conname, @@ -2105,27 +1815,17 @@ create table fk_partitioned_fk_2 ( insert into fk_partitioned_fk_2 values (1000, 1000); alter table fk_partitioned_fk_2 - add foreign key - (a, - b) - references fk_notpartitioned_pk - not valid; + add foreign key (a, b) references fk_notpartitioned_pk not valid; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values from (1000, - 1000) to (2000, - 2000); + fk_partitioned_fk_2 for values from (1000, 1000) to (2000, 2000); truncate fk_partitioned_fk_2; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values from (1000, - 1000) to (2000, - 2000); + fk_partitioned_fk_2 for values from (1000, 1000) to (2000, 2000); select conname, @@ -2133,8 +1833,7 @@ select from pg_constraint where - conrelid = - cast('fk_partitioned_fk_2' as regclass) + conrelid = cast('fk_partitioned_fk_2' as regclass) order by cast(cast(oid as regclass) as text); create table fk_partitioned_fk_3 ( @@ -2144,11 +1843,7 @@ create table fk_partitioned_fk_3 ( partition by range(a, b); alter table fk_partitioned_fk_3 - add foreign key - (a, - b) - references fk_notpartitioned_pk - not valid; + add foreign key (a, b) references fk_notpartitioned_pk not valid; create table fk_partitioned_fk_3_1 ( a int, @@ -2156,24 +1851,15 @@ create table fk_partitioned_fk_3_1 ( ); alter table fk_partitioned_fk_3_1 - add foreign key - (a, - b) - references fk_notpartitioned_pk; + add foreign key (a, b) references fk_notpartitioned_pk; alter table fk_partitioned_fk_3 attach partition - fk_partitioned_fk_3_1 - for values from (2000, - 2000) to (3000, - 3000); + fk_partitioned_fk_3_1 for values from (2000, 2000) to (3000, 3000); alter table fk_partitioned_fk attach partition - fk_partitioned_fk_3 - for values from (2000, - 2000) to (3000, - 3000); + fk_partitioned_fk_3 for values from (2000, 2000) to (3000, 3000); select conname, @@ -2200,9 +1886,7 @@ for values from (0, 0) to (1000, 1000); create table fk_partitioned_pk_2 partition of fk_partitioned_pk -for values from (1000, -1000) to (2000, -2000); +for values from (1000, 1000) to (2000, 2000); create table fk_notpartitioned_fk ( b int, @@ -2214,12 +1898,9 @@ insert into fk_partitioned_pk values (100, 100), (1000, 1000); insert into fk_notpartitioned_fk values (100, 100), (1000, 1000); alter table fk_notpartitioned_fk - add constraint "fk_notpartitioned_fk_a_b_fkey" - foreign key - (a, - b) - references fk_partitioned_pk - not valid; + add constraint fk_notpartitioned_fk_a_b_fkey foreign key (a, b) + references fk_partitioned_pk + not valid; select conname, @@ -2228,8 +1909,7 @@ select from pg_constraint where - conrelid = - cast('fk_notpartitioned_fk' as regclass) + conrelid = cast('fk_notpartitioned_fk' as regclass) order by cast(cast(oid as regclass) as text); alter table fk_notpartitioned_fk @@ -2242,23 +1922,17 @@ select from pg_constraint where - conrelid = - cast('fk_notpartitioned_fk' as regclass) + conrelid = cast('fk_notpartitioned_fk' as regclass) order by cast(cast(oid as regclass) as text); alter table fk_partitioned_pk - add constraint "selffk" - foreign key - (a, - b) - references fk_partitioned_pk - not valid; + add constraint selffk foreign key (a, b) + references fk_partitioned_pk + not valid; create table fk_partitioned_pk_3 partition of fk_partitioned_pk -for values from (2000, -2000) to (3000, -3000) +for values from (2000, 2000) to (3000, 3000) partition by range(a); create table fk_partitioned_pk_3_1 @@ -2272,9 +1946,7 @@ select from pg_constraint where - conrelid = - cast('fk_partitioned_pk' as regclass) and - contype = 'f' + conrelid = cast('fk_partitioned_pk' as regclass) and contype = 'f' order by cast(cast(oid as regclass) as text); alter table fk_partitioned_pk_2 @@ -2290,9 +1962,7 @@ select from pg_constraint where - conrelid = - cast('fk_partitioned_pk' as regclass) and - contype = 'f' + conrelid = cast('fk_partitioned_pk' as regclass) and contype = 'f' order by cast(cast(oid as regclass) as text); drop table fk_notpartitioned_fk, fk_partitioned_pk; @@ -2307,19 +1977,17 @@ create table fk_partitioned_fk ( a int default 2501, b int default 142857 ) -partition by LIST(a); +partition by list(a); create table fk_partitioned_fk_1 partition of fk_partitioned_fk for values in (null, 500, 501, 502); alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE set null - on UPDATE set null; + add foreign key (a, b) + references fk_notpartitioned_pk + on delete set null + on update set null; create table fk_partitioned_fk_2 partition of fk_partitioned_fk @@ -2332,8 +2000,7 @@ create table fk_partitioned_fk_3 ( alter table fk_partitioned_fk attach partition - fk_partitioned_fk_3 - for values in (2500, 2501, 2502, 2503); + fk_partitioned_fk_3 for values in (2500, 2501, 2502, 2503); insert into fk_partitioned_fk (a, b) values (2502, 2503); @@ -2362,20 +2029,12 @@ default; insert into fk_partitioned_fk_full values (1, null); alter table fk_partitioned_fk_full - add foreign key - (x, - y) - references fk_notpartitioned_pk - match full; + add foreign key (x, y) references fk_notpartitioned_pk match full; truncate fk_partitioned_fk_full; alter table fk_partitioned_fk_full - add foreign key - (x, - y) - references fk_notpartitioned_pk - match full; + add foreign key (x, y) references fk_notpartitioned_pk match full; insert into fk_partitioned_fk_full values (1, null); @@ -2405,22 +2064,20 @@ order by a; insert into fk_partitioned_fk values (2503, 2503); -select COUNT(*) from fk_partitioned_fk where a is null; +select count(*) from fk_partitioned_fk where a is null; delete from fk_notpartitioned_pk; -select COUNT(*) from fk_partitioned_fk where a is null; +select count(*) from fk_partitioned_fk where a is null; alter table fk_partitioned_fk drop constraint fk_partitioned_fk_a_b_fkey; alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE set default - on UPDATE set default; + add foreign key (a, b) + references fk_notpartitioned_pk + on delete set default + on update set default; insert into fk_notpartitioned_pk values (2502, 2503); @@ -2438,11 +2095,7 @@ alter table fk_partitioned_fk drop constraint fk_partitioned_fk_a_b_fkey; alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE set null (a); + add foreign key (a, b) references fk_notpartitioned_pk on delete set null (a); begin; @@ -2462,11 +2115,9 @@ alter table fk_partitioned_fk drop constraint fk_partitioned_fk_a_b_fkey; alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE set default (a); + add foreign key (a, b) + references fk_notpartitioned_pk + on delete set default (a); begin; @@ -2488,12 +2139,10 @@ alter table fk_partitioned_fk drop constraint fk_partitioned_fk_a_b_fkey; alter table fk_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE cascade - on UPDATE cascade; + add foreign key (a, b) + references fk_notpartitioned_pk + on delete cascade + on update cascade; update fk_notpartitioned_pk set a = 2502 where a = 2501; @@ -2523,8 +2172,7 @@ rollback; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values in (1500, 1502); + fk_partitioned_fk_2 for values in (1500, 1502); drop table fk_partitioned_fk_2; @@ -2532,12 +2180,10 @@ create table fk_partitioned_fk_2 ( b int, c text, a int, - foreign key - (a, - b) - references fk_notpartitioned_pk - on DELETE cascade - on UPDATE cascade + foreign key (a, b) + references fk_notpartitioned_pk + on delete cascade + on update cascade ); alter table fk_partitioned_fk_2 @@ -2545,22 +2191,19 @@ alter table fk_partitioned_fk_2 alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values in (1500, 1502); + fk_partitioned_fk_2 for values in (1500, 1502); drop table fk_partitioned_fk_2; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values in (1500, 1502); + fk_partitioned_fk_2 for values in (1500, 1502); begin; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values in (1500, 1502); + fk_partitioned_fk_2 for values in (1500, 1502); rollback; @@ -2568,8 +2211,7 @@ begin; alter table fk_partitioned_fk attach partition - fk_partitioned_fk_2 - for values in (1500, 1502); + fk_partitioned_fk_2 for values in (1500, 1502); rollback; @@ -2578,13 +2220,10 @@ drop table fk_partitioned_fk_2; create table fk_partitioned_fk_4 ( a int, b int, - foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b) - on DELETE cascade - on UPDATE cascade + foreign key (a, b) + references fk_notpartitioned_pk (a, b) + on delete cascade + on update cascade ) partition by range(b, a); @@ -2595,25 +2234,16 @@ for values from (1, 1) to (100, 100); create table fk_partitioned_fk_4_2 ( a int, b int, - foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b) - on UPDATE set null + foreign key (a, b) references fk_notpartitioned_pk (a, b) on update set null ); alter table fk_partitioned_fk_4 attach partition - fk_partitioned_fk_4_2 - for values from (100, - 100) to (1000, - 1000); + fk_partitioned_fk_4_2 for values from (100, 100) to (1000, 1000); alter table fk_partitioned_fk attach partition - fk_partitioned_fk_4 - for values in (3500, 3502); + fk_partitioned_fk_4 for values in (3500, 3502); alter table fk_partitioned_fk detach partition @@ -2621,38 +2251,28 @@ alter table fk_partitioned_fk alter table fk_partitioned_fk attach partition - fk_partitioned_fk_4 - for values in (3500, 3502); + fk_partitioned_fk_4 for values in (3500, 3502); create table fk_partitioned_fk_5 ( a int, b int, - foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b) - on DELETE cascade - on UPDATE cascade - deferrable initially immediate, - foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b) - match full - on DELETE cascade - on UPDATE cascade + foreign key (a, b) + references fk_notpartitioned_pk (a, b) + on delete cascade + on update cascade + deferrable initially immediate, + foreign key (a, b) + references fk_notpartitioned_pk (a, b) + match full + on delete cascade + on update cascade ) partition by range(a); create table fk_partitioned_fk_5_1 ( a int, b int, - foreign key - (a, - b) - references fk_notpartitioned_pk + foreign key (a, b) references fk_notpartitioned_pk ); alter table fk_partitioned_fk @@ -2661,8 +2281,7 @@ alter table fk_partitioned_fk alter table fk_partitioned_fk_5 attach partition - fk_partitioned_fk_5_1 - for values from (0) to (10); + fk_partitioned_fk_5_1 for values from (0) to (10); alter table fk_partitioned_fk detach partition @@ -2678,8 +2297,7 @@ alter table fk_partitioned_fk_5 alter table fk_partitioned_fk_5 attach partition - fk_partitioned_fk_5_1 - for values from (0) to (10); + fk_partitioned_fk_5_1 for values from (0) to (10); create table fk_partitioned_fk_2 ( a int, @@ -2710,7 +2328,7 @@ alter table fk_partitioned_fk create table fk_partitioned_pk_6 (a int primary key); create table fk_partitioned_fk_6 (a int references fk_partitioned_pk_6) -partition by LIST(a); +partition by list(a); alter table fk_partitioned_fk_6 attach partition @@ -2722,14 +2340,10 @@ create table fk_partitioned_pk_6 (a int primary key); create table fk_partitioned_fk_6 ( a int, - foreign key - (a) - references fk_partitioned_pk_6, - foreign key - (a) - references fk_partitioned_pk_6 + foreign key (a) references fk_partitioned_pk_6, + foreign key (a) references fk_partitioned_pk_6 ) -partition by LIST(a); +partition by list(a); create table fk_partitioned_fk_6_1 partition of fk_partitioned_fk_6 @@ -2746,14 +2360,14 @@ alter table fk_partitioned_fk_6 drop table fk_partitioned_pk_6, fk_partitioned_fk_6; create table fk_partitioned_pk_6 (a int primary key) -partition by LIST(a); +partition by list(a); create table fk_partitioned_pk_61 partition of fk_partitioned_pk_6 for values in (1); create table fk_partitioned_fk_6 (a int references fk_partitioned_pk_61) -partition by LIST(a); +partition by list(a); alter table fk_partitioned_fk_6 attach partition @@ -2763,7 +2377,7 @@ drop table fk_partitioned_pk_6, fk_partitioned_fk_6; create role regress_other_partitioned_fk_owner; -grant REFERENCES +grant references on table fk_notpartitioned_pk to regress_other_partitioned_fk_owner; @@ -2773,43 +2387,27 @@ create table other_partitioned_fk ( a int, b int ) -partition by LIST(a); +partition by list(a); create table other_partitioned_fk_1 partition of other_partitioned_fk for values in (2048); insert into other_partitioned_fk -select - 2048, - x -from - generate_series(1, 10) as x; +select 2048, x from generate_series(1, 10) as x; alter table other_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b); + add foreign key (a, b) references fk_notpartitioned_pk (a, b); reset role; insert into fk_notpartitioned_pk (a, b) -select - 2048, - x -from - generate_series(1, 10) as x; +select 2048, x from generate_series(1, 10) as x; set role to regress_other_partitioned_fk_owner; alter table other_partitioned_fk - add foreign key - (a, - b) - references fk_notpartitioned_pk (a, - b); + add foreign key (a, b) references fk_notpartitioned_pk (a, b); drop table other_partitioned_fk; @@ -2824,9 +2422,7 @@ drop role regress_other_partitioned_fk_owner; create table parted_self_fk ( id bigint not null primary key, id_abc bigint, - foreign key - (id_abc) - references parted_self_fk (id) + foreign key (id_abc) references parted_self_fk (id) ) partition by range(id); @@ -2837,8 +2433,7 @@ create table part1_self_fk ( alter table parted_self_fk attach partition - part1_self_fk - for values from (0) to (10); + part1_self_fk for values from (0) to (10); create table part2_self_fk partition of parted_self_fk @@ -2856,8 +2451,7 @@ for values from (20) to (30); alter table parted_self_fk attach partition - part3_self_fk - for values from (20) to (40); + part3_self_fk for values from (20) to (40); create table part33_self_fk ( id bigint not null primary key, @@ -2866,8 +2460,7 @@ create table part33_self_fk ( alter table part3_self_fk attach partition - part33_self_fk - for values from (30) to (40); + part33_self_fk for values from (30) to (40); insert into parted_self_fk values (1, null), (2, null), (3, null); @@ -2887,10 +2480,7 @@ select p.convalidated, cf.relname as foreignrel from - pg_constraint as co - inner join - pg_class as cr - on cr.oid = co.conrelid + pg_constraint as co inner join pg_class as cr on cr.oid = co.conrelid left outer join pg_class as cf on cf.oid = co.confrelid @@ -2899,13 +2489,7 @@ from on p.oid = co.conparentid where co.contype = 'f' and - cr.oid in - ( - select - relid - from - pg_partition_tree('parted_self_fk') - ) + cr.oid in (select relid from pg_partition_tree('parted_self_fk')) order by cr.relname, co.conname, p.conname; @@ -2920,8 +2504,7 @@ delete from parted_self_fk where id = 2 returning *; alter table parted_self_fk attach partition - part2_self_fk - for values from (10) to (20); + part2_self_fk for values from (10) to (20); insert into parted_self_fk values (16, 9); @@ -2933,8 +2516,7 @@ alter table parted_self_fk alter table parted_self_fk attach partition - part2_self_fk - for values from (10) to (20); + part2_self_fk for values from (10) to (20); alter table parted_self_fk detach partition @@ -2942,8 +2524,7 @@ alter table parted_self_fk alter table parted_self_fk attach partition - part3_self_fk - for values from (30) to (40); + part3_self_fk for values from (30) to (40); alter table part3_self_fk detach partition @@ -2951,8 +2532,7 @@ alter table part3_self_fk alter table part3_self_fk attach partition - part33_self_fk - for values from (30) to (40); + part33_self_fk for values from (30) to (40); select cr.relname, @@ -2962,10 +2542,7 @@ select p.convalidated, cf.relname as foreignrel from - pg_constraint as co - inner join - pg_class as cr - on cr.oid = co.conrelid + pg_constraint as co inner join pg_class as cr on cr.oid = co.conrelid left outer join pg_class as cf on cf.oid = co.confrelid @@ -2974,23 +2551,17 @@ from on p.oid = co.conparentid where co.contype = 'f' and - cr.oid in - ( - select - relid - from - pg_partition_tree('parted_self_fk') - ) + cr.oid in (select relid from pg_partition_tree('parted_self_fk')) order by cr.relname, co.conname, p.conname; -create schema "fkpart0"; +create schema fkpart0; create table pkey (a int primary key); create table fk_part (a int) -partition by LIST(a); +partition by list(a); create table fk_part_1 partition of fk_part @@ -3005,7 +2576,7 @@ partition of fk_part foreign key (a) references fkpart0.pkey ) for values in (2, 3) -partition by LIST(a); +partition by list(a); create table fk_part_23_2 partition of fk_part_23 for values in (2); @@ -3029,7 +2600,7 @@ alter table fkpart0.fk_part_4 create table fkpart0.fk_part_56 partition of fkpart0.fk_part for values in (5, 6) -partition by LIST(a); +partition by list(a); create table fkpart0.fk_part_56_5 partition of fkpart0.fk_part_56 @@ -3041,17 +2612,17 @@ alter table fkpart0.fk_part_56 alter table fkpart0.fk_part_56_5 drop constraint fk_part_a_fkey; -create schema "fkpart1"; +create schema fkpart1; create table pkey (a int primary key); create table fk_part (a int) -partition by LIST(a); +partition by list(a); create table fk_part_1 partition of fk_part for values in (1) -partition by LIST(a); +partition by list(a); create table fk_part_1_1 partition of fk_part_1 for values in (1); @@ -3078,30 +2649,24 @@ insert into fkpart1.fk_part_1 values (2); delete from fkpart1.pkey where a = 1; -create schema "fkpart2"; +create schema fkpart2; create table pkey (a int primary key); create table fk_part ( a int, - constraint "fkey" - foreign key - (a) - references fkpart2.pkey + constraint fkey foreign key (a) references fkpart2.pkey ) -partition by LIST(a); +partition by list(a); create table fk_part_1 partition of fkpart2.fk_part for values in (1) -partition by LIST(a); +partition by list(a); create table fk_part_1_1 ( a int, - constraint "my_fkey" - foreign key - (a) - references fkpart2.pkey + constraint my_fkey foreign key (a) references fkpart2.pkey ); alter table fkpart2.fk_part_1 @@ -3124,24 +2689,22 @@ alter table fkpart2.fk_part_1 alter table fkpart2.fk_part_1_1 drop constraint my_fkey; -create schema "fkpart3"; +create schema fkpart3; create table pkey (a int primary key); create table fk_part ( a int, - constraint "fkey" - foreign key - (a) - references fkpart3.pkey - deferrable initially immediate + constraint fkey foreign key (a) + references fkpart3.pkey + deferrable initially immediate ) -partition by LIST(a); +partition by list(a); create table fk_part_1 partition of fkpart3.fk_part for values in (1) -partition by LIST(a); +partition by list(a); create table fk_part_1_1 partition of fkpart3.fk_part_1 for values in (1); @@ -3169,7 +2732,7 @@ commit; drop schema fkpart0, fkpart1, fkpart2, fkpart3 cascade; -create schema "fkpart3"; +create schema fkpart3; set search_path to fkpart3; @@ -3312,7 +2875,7 @@ create table ffk ( a int, b int references pk ) -partition by LIST(a); +partition by list(a); create table ffk1 partition of ffk for values in (1); @@ -3325,7 +2888,7 @@ alter table ffk drop table ffk, ffk1; -create schema "fkpart4"; +create schema fkpart4; set search_path to fkpart4; @@ -3395,21 +2958,21 @@ alter table droppk2 drop table droppk2; -create schema "fkpart5"; +create schema fkpart5; set search_path to fkpart5; create table pk (a int primary key) -partition by LIST(a); +partition by list(a); -create table pk1 partition of pk for values in (1) partition by LIST(a); +create table pk1 partition of pk for values in (1) partition by list(a); create table pk11 partition of pk1 for values in (1); create table fk (a int) -partition by LIST(a); +partition by list(a); -create table fk1 partition of fk for values in (1) partition by LIST(a); +create table fk1 partition of fk for values in (1) partition by list(a); create table fk11 partition of fk1 for values in (1); @@ -3419,7 +2982,7 @@ alter table fk create table pk2 partition of pk for values in (2); create table pk3 (a int not null) -partition by LIST(a); +partition by list(a); create table pk31 partition of pk3 for values in (31); @@ -3454,31 +3017,17 @@ alter table fk fk3 for values in (3); select - pg_describe_object( - cast('pg_constraint' as regclass), - oid, - 0 - ), + pg_describe_object(cast('pg_constraint' as regclass), oid, 0), cast(confrelid as regclass), case when conparentid <> 0 - then pg_describe_object( - cast('pg_constraint' as regclass), - conparentid, - 0 - ) + then pg_describe_object(cast('pg_constraint' as regclass), conparentid, 0) else 'TOP' end from pg_catalog.pg_constraint where - conrelid in - ( - select - relid - from - pg_partition_tree('fk') - ) + conrelid in (select relid from pg_partition_tree('fk')) order by cast(cast(conrelid as regclass) as text), conname; @@ -3490,14 +3039,14 @@ alter table fk attach partition fk4 for values in (50); -create schema "fkpart9"; +create schema fkpart9; set search_path to fkpart9; create table pk (a int primary key) -partition by LIST(a); +partition by list(a); -create table pk1 partition of pk for values in (1, 2) partition by LIST(a); +create table pk1 partition of pk for values in (1, 2) partition by list(a); create table pk11 partition of pk1 for values in (1); @@ -3547,7 +3096,7 @@ create table ref ( f2 int, f3 int ) -partition by LIST(f1); +partition by list(f1); create table ref1 partition of ref for values in (1); @@ -3557,7 +3106,7 @@ alter table ref add foreign key (f1, f2) references pt; alter table ref - alter constraint "ref_f1_f2_fkey" deferrable initially deferred; + alter constraint ref_f1_f2_fkey deferrable initially deferred; insert into pt values (1, 2, 3); @@ -3585,13 +3134,13 @@ create table ref ( f2 int, f3 int ) -partition by LIST(f1); +partition by list(f1); -create table ref1_2 partition of ref for values in (1, 2) partition by LIST(f2); +create table ref1_2 partition of ref for values in (1, 2) partition by list(f2); create table ref1 partition of ref1_2 for values in (1); -create table ref2 partition of ref1_2 for values in (2) partition by LIST(f2); +create table ref2 partition of ref1_2 for values in (2) partition by list(f2); create table ref22 partition of ref2 for values in (2); @@ -3603,10 +3152,10 @@ insert into pt values (1, 2, 3); insert into ref values (1, 2, 3); alter table ref22 - alter constraint "ref_f1_f2_fkey" deferrable initially immediate; + alter constraint ref_f1_f2_fkey deferrable initially immediate; alter table ref - alter constraint "ref_f1_f2_fkey" deferrable initially deferred; + alter constraint ref_f1_f2_fkey deferrable initially deferred; begin; @@ -3624,7 +3173,7 @@ create table pt ( f3 int, primary key (f1, f2) ) -partition by LIST(f1); +partition by list(f1); create table pt1 partition of pt for values in (1); @@ -3640,7 +3189,7 @@ alter table ref add foreign key (f1, f2) references pt; alter table ref - alter constraint "ref_f1_f2_fkey" deferrable initially deferred; + alter constraint ref_f1_f2_fkey deferrable initially deferred; insert into pt values (1, 2, 3); @@ -3662,9 +3211,9 @@ create table pt ( f3 int, primary key (f1, f2) ) -partition by LIST(f1); +partition by list(f1); -create table pt1_2 partition of pt for values in (1, 2) partition by LIST(f1); +create table pt1_2 partition of pt for values in (1, 2) partition by list(f1); create table pt1 partition of pt1_2 for values in (1); @@ -3680,10 +3229,10 @@ alter table ref add foreign key (f1, f2) references pt; alter table ref - alter constraint "ref_f1_f2_fkey_1" deferrable initially deferred; + alter constraint ref_f1_f2_fkey_1 deferrable initially deferred; alter table ref - alter constraint "ref_f1_f2_fkey" deferrable initially deferred; + alter constraint ref_f1_f2_fkey deferrable initially deferred; insert into pt values (1, 2, 3); @@ -3701,7 +3250,7 @@ drop table pt, ref; drop schema fkpart9 cascade; -create schema "fkpart6"; +create schema fkpart6; set search_path to fkpart6; @@ -3730,11 +3279,7 @@ create table fk11 partition of fk1 for values from (1) to (10); create table fk12 partition of fk1 for values from (10) to (100); alter table fk - add foreign key - (a) - references pk - on DELETE cascade - on UPDATE cascade; + add foreign key (a) references pk on delete cascade on update cascade; create table fk_d partition of fk default; @@ -3769,11 +3314,7 @@ create table fk11 partition of fk1 for values from (1) to (10); create table fk12 partition of fk1 for values from (10) to (100); alter table fk - add foreign key - (a) - references pk - on DELETE set null - on UPDATE set null; + add foreign key (a) references pk on delete set null on update set null; create table fk_d partition of fk default; @@ -3807,11 +3348,7 @@ create table fk11 partition of fk1 for values from (1) to (10); create table fk12 partition of fk1 for values from (10) to (100); alter table fk - add foreign key - (a) - references pk - on DELETE set default - on UPDATE set default; + add foreign key (a) references pk on delete set default on update set default; create table fk_d partition of fk default; @@ -3842,11 +3379,7 @@ create table fk11 partition of fk1 for values from (1) to (10); create table fk12 partition of fk1 for values from (10) to (100); alter table fk - add foreign key - (a) - references pk - on DELETE restrict - on UPDATE restrict; + add foreign key (a) references pk on delete restrict on update restrict; create table fk_d partition of fk default; @@ -3860,10 +3393,10 @@ select cast(tableoid as regclass), * from fk; drop table fk; -create schema "fkpart7"; +create schema fkpart7; create table pkpart (a int) -partition by LIST(a); +partition by list(a); create table pkpart1 partition of pkpart for values in (1); @@ -3877,7 +3410,7 @@ create table fkpart7.fk (a int references fkpart7.pkpart); drop schema fkpart7 cascade; -create schema "fkpart8"; +create schema fkpart8; create table tbl1 (f1 int primary key); @@ -3899,12 +3432,12 @@ commit; drop schema fkpart8 cascade; -create schema "fkpart9"; +create schema fkpart9; create table pk (a int primary key) partition by range(a); -create table fk (fk_a int references pk (a) on DELETE cascade); +create table fk (fk_a int references pk (a) on delete cascade); create table pk1 partition of pk @@ -3925,7 +3458,7 @@ select * from fkpart9.fk; drop schema fkpart9 cascade; -create schema "fkpart10"; +create schema fkpart10; create table tbl1 (f1 int primary key) partition by range(f1); @@ -4019,46 +3552,40 @@ commit; drop schema fkpart10 cascade; -create schema "fkpart11"; +create schema fkpart11; create table pk ( a int primary key, b text ) -partition by LIST(a); +partition by list(a); create table fk ( a int, - constraint "fkey" - foreign key - (a) - references pk (a) - on DELETE cascade - on UPDATE cascade + constraint fkey foreign key (a) + references pk (a) + on delete cascade + on update cascade ); create table fk_parted ( a int primary key, - constraint "fkey" - foreign key - (a) - references pk (a) - on DELETE cascade - on UPDATE cascade + constraint fkey foreign key (a) + references pk (a) + on delete cascade + on update cascade ) -partition by LIST(a); +partition by list(a); create table fk_another ( a int, - constraint "fkey" - foreign key - (a) - references fk_parted (a) - on DELETE cascade - on UPDATE cascade + constraint fkey foreign key (a) + references fk_parted (a) + on delete cascade + on update cascade ); -create table pk1 partition of pk for values in (1, 2) partition by LIST(a); +create table pk1 partition of pk for values in (1, 2) partition by list(a); create table pk2 partition of pk for values in (3); @@ -4100,13 +3627,16 @@ insert into fkpart11.fk_parted values (1), (3); insert into fkpart11.fk_another values (1), (3); -update fkpart11.pk set a = a + 1 returning cast(tableoid as regclass), *; +update fkpart11.pk +set a = a + 1 +returning cast(tableoid as pg_catalog.regclass), +*; -select cast(tableoid as regclass), * from fkpart11.fk; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk; -select cast(tableoid as regclass), * from fkpart11.fk_parted; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk_parted; -select cast(tableoid as regclass), * from fkpart11.fk_another; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk_another; alter table fkpart11.fk drop constraint fkey; @@ -4114,51 +3644,47 @@ alter table fkpart11.fk delete from fkpart11.fk where a = 4; alter table fkpart11.fk - add constraint "fkey" - foreign key - (a) - references fkpart11.pk1 (a) - on DELETE cascade - on UPDATE cascade; + add constraint fkey foreign key (a) + references fkpart11.pk1 (a) + on delete cascade + on update cascade; update fkpart11.pk set a = a - 1; update fkpart11.pk1 set a = a - 1; -select cast(tableoid as regclass), * from fkpart11.pk; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.pk; -select cast(tableoid as regclass), * from fkpart11.fk; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk; -select cast(tableoid as regclass), * from fkpart11.fk_parted; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk_parted; -select cast(tableoid as regclass), * from fkpart11.fk_another; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk_another; alter table fkpart11.fk drop constraint fkey; alter table fkpart11.fk - add constraint "fkey" - foreign key - (a) - references fkpart11.pk11 (a) - on DELETE cascade - on UPDATE cascade; + add constraint fkey foreign key (a) + references fkpart11.pk11 (a) + on delete cascade + on update cascade; update fkpart11.pk set a = a + 1 where a = 1; -select cast(tableoid as regclass), * from fkpart11.fk; +select cast(tableoid as pg_catalog.regclass), * from fkpart11.fk; drop table fkpart11.fk; create function fkpart11.print_row() returns trigger language plpgsql -as $function$ -BEGIN +as $$ + BEGIN RAISE NOTICE 'TABLE: %, OP: %, OLD: %, NEW: %', TG_RELNAME, TG_OP, OLD, NEW; RETURN NULL; END; -$function$; +$$; create trigger trig_upd_pk after update @@ -4208,16 +3734,16 @@ update fkpart11.pk set a = 1 where a = 2; drop schema fkpart11 cascade; -create schema "fkpart12"; +create schema fkpart12; create table fk_p ( id int, jd int, primary key (id, jd) ) -partition by LIST(id); +partition by list(id); -create table fk_p_1 partition of fk_p for values in (1) partition by LIST(jd); +create table fk_p_1 partition of fk_p for values in (1) partition by list(jd); create table fk_p_1_1 partition of fk_p_1 for values in (1); @@ -4228,7 +3754,7 @@ create table fk_p_1_2 ( id int not null ); -create table fk_p_2 partition of fk_p for values in (2) partition by LIST(jd); +create table fk_p_2 partition of fk_p for values in (2) partition by list(jd); create table fk_p_2_1 partition of fk_p_2 for values in (1); @@ -4246,7 +3772,7 @@ create table fk_r_2 ( p_id int not null, p_jd int not null ) -partition by LIST(id); +partition by list(id); create table fk_r_2_1 partition of fk_r_2 for values in (2, 1); @@ -4254,13 +3780,9 @@ create table fk_r ( id int primary key, p_id int not null, p_jd int not null, - foreign key - (p_id, - p_jd) - references fk_p (id, - jd) + foreign key (p_id, p_jd) references fk_p (id, jd) ) -partition by LIST(id); +partition by list(id); set search_path to fkpart12; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__functional_deps_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__functional_deps_100.snap index cfd22bb81..d7f47df3c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__functional_deps_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__functional_deps_100.snap @@ -4,7 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/functional_deps.sql snapshot_kind: text --- create temporary table articles ( - id int constraint "articles_pkey" primary key, + id int constraint articles_pkey primary key, keywords text, title text unique not null, body text unique, @@ -36,8 +36,7 @@ from articles as a, articles_in_category as aic where - a.id = aic.article_id and - aic.category_id in (14, 62, 70, 53, 138) + a.id = aic.article_id and aic.category_id in (14, 62, 70, 53, 138) group by a.id; select @@ -50,8 +49,7 @@ from articles as a, articles_in_category as aic where - a.id = aic.article_id and - aic.category_id in (14, 62, 70, 53, 138) + a.id = aic.article_id and aic.category_id in (14, 62, 70, 53, 138) group by aic.article_id, aic.category_id; @@ -62,10 +60,7 @@ select a.body, a.created from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by a.id; @@ -77,10 +72,7 @@ select a.body, a.created from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by aic.article_id, @@ -89,10 +81,7 @@ group by aic.article_id, select aic.changed from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by aic.category_id, @@ -101,10 +90,7 @@ group by aic.category_id, select aic.changed from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by aic.article_id; @@ -123,12 +109,9 @@ create temporary table sales ( select product_id, p.name, - SUM(s.units) * p.price as sales + sum(s.units) * p.price as sales from - products as p - left outer join - sales as s - using ("product_id") + products as p left outer join sales as s using (product_id) group by product_id, p.name, p.price; @@ -136,12 +119,9 @@ group by product_id, select product_id, p.name, - SUM(s.units) * p.price as sales + sum(s.units) * p.price as sales from - products as p - left outer join - sales as s - using ("product_id") + products as p left outer join sales as s using (product_id) group by product_id; alter table products @@ -150,12 +130,9 @@ alter table products select product_id, p.name, - SUM(s.units) * p.price as sales + sum(s.units) * p.price as sales from - products as p - left outer join - sales as s - using ("product_id") + products as p left outer join sales as s using (product_id) group by product_id; create temporary table node ( @@ -197,26 +174,10 @@ where group by u.uid; create temporary view fdv1 -as select - id, - keywords, - title, - body, - created -from - articles -group by body; +as select id, keywords, title, body, created from articles group by body; create temporary view fdv1 -as select - id, - keywords, - title, - body, - created -from - articles -group by id; +as select id, keywords, title, body, created from articles group by id; alter table articles drop constraint articles_pkey; @@ -231,10 +192,7 @@ as select aic.category_id, aic.changed from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by a.id, @@ -250,25 +208,9 @@ alter table articles_in_category drop view fdv2; create temporary view fdv3 -as select - id, - keywords, - title, - body, - created -from - articles -group by id +as select id, keywords, title, body, created from articles group by id union -select - id, - keywords, - title, - body, - created -from - articles -group by id; +select id, keywords, title, body, created from articles group by id; alter table articles drop constraint articles_pkey; @@ -276,12 +218,7 @@ alter table articles drop view fdv3; create temporary view fdv4 -as select - * -from - articles -where - title in (select title from articles group by id); +as select * from articles where title in (select title from articles group by id); alter table articles drop constraint articles_pkey; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__functional_deps_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__functional_deps_80.snap index 393cee8e2..c9433c65f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__functional_deps_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__functional_deps_80.snap @@ -4,8 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/functional_deps.sql snapshot_kind: text --- create temporary table articles ( - id int - constraint "articles_pkey" primary key, + id int constraint articles_pkey primary key, keywords text, title text unique not null, body text unique, @@ -37,8 +36,7 @@ from articles as a, articles_in_category as aic where - a.id = aic.article_id and - aic.category_id in (14, 62, 70, 53, 138) + a.id = aic.article_id and aic.category_id in (14, 62, 70, 53, 138) group by a.id; select @@ -51,8 +49,7 @@ from articles as a, articles_in_category as aic where - a.id = aic.article_id and - aic.category_id in (14, 62, 70, 53, 138) + a.id = aic.article_id and aic.category_id in (14, 62, 70, 53, 138) group by aic.article_id, aic.category_id; @@ -63,10 +60,7 @@ select a.body, a.created from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by a.id; @@ -78,10 +72,7 @@ select a.body, a.created from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by aic.article_id, @@ -90,10 +81,7 @@ group by aic.article_id, select aic.changed from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by aic.category_id, @@ -102,10 +90,7 @@ group by aic.category_id, select aic.changed from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by aic.article_id; @@ -124,12 +109,9 @@ create temporary table sales ( select product_id, p.name, - SUM(s.units) * p.price as sales + sum(s.units) * p.price as sales from - products as p - left outer join - sales as s - using ("product_id") + products as p left outer join sales as s using (product_id) group by product_id, p.name, p.price; @@ -137,12 +119,9 @@ group by product_id, select product_id, p.name, - SUM(s.units) * p.price as sales + sum(s.units) * p.price as sales from - products as p - left outer join - sales as s - using ("product_id") + products as p left outer join sales as s using (product_id) group by product_id; alter table products @@ -151,12 +130,9 @@ alter table products select product_id, p.name, - SUM(s.units) * p.price as sales + sum(s.units) * p.price as sales from - products as p - left outer join - sales as s - using ("product_id") + products as p left outer join sales as s using (product_id) group by product_id; create temporary table node ( @@ -182,10 +158,7 @@ select u.uid, u.name from - node as n - inner join - users as u - on u.uid = n.uid + node as n inner join users as u on u.uid = n.uid where n.type = 'blog' and n.status = 1 group by u.uid, @@ -195,35 +168,16 @@ select u.uid, u.name from - node as n - inner join - users as u - on u.uid = n.uid + node as n inner join users as u on u.uid = n.uid where n.type = 'blog' and n.status = 1 group by u.uid; create temporary view fdv1 -as select - id, - keywords, - title, - body, - created -from - articles -group by body; +as select id, keywords, title, body, created from articles group by body; create temporary view fdv1 -as select - id, - keywords, - title, - body, - created -from - articles -group by id; +as select id, keywords, title, body, created from articles group by id; alter table articles drop constraint articles_pkey; @@ -238,10 +192,7 @@ as select aic.category_id, aic.changed from - articles as a - inner join - articles_in_category as aic - on a.id = aic.article_id + articles as a inner join articles_in_category as aic on a.id = aic.article_id where aic.category_id in (14, 62, 70, 53, 138) group by a.id, @@ -257,25 +208,9 @@ alter table articles_in_category drop view fdv2; create temporary view fdv3 -as select - id, - keywords, - title, - body, - created -from - articles -group by id +as select id, keywords, title, body, created from articles group by id union -select - id, - keywords, - title, - body, - created -from - articles -group by id; +select id, keywords, title, body, created from articles group by id; alter table articles drop constraint articles_pkey; @@ -288,10 +223,7 @@ as select from articles where - title in - ( - select title from articles group by id - ); + title in (select title from articles group by id); alter table articles drop constraint articles_pkey; @@ -299,15 +231,7 @@ alter table articles drop view fdv4; prepare foo -as select - id, - keywords, - title, - body, - created -from - articles -group by id;; +as select id, keywords, title, body, created from articles group by id;; execute foo; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_stored_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_stored_100.snap index 7284e7728..37f37b713 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_stored_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_stored_100.snap @@ -2,9 +2,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/generated_stored.sql --- -create schema "generated_stored_tests"; +create schema generated_stored_tests; -grant USAGE on schema generated_stored_tests to public; +grant usage on schema generated_stored_tests to public; set search_path to generated_stored_tests; @@ -46,9 +46,7 @@ order by 1, create table gtest_err_1 ( a int primary key, - b int - generated always as (a * 2) stored - generated always as (a * 3) stored + b int generated always as (a * 2) stored generated always as (a * 3) stored ); create table gtest_err_2a ( @@ -64,8 +62,7 @@ create table gtest_err_2b ( create table gtest_err_2c ( a int primary key, - b int - generated always as (num_nulls(gtest_err_2c)) stored + b int generated always as (num_nulls(gtest_err_2c)) stored ); create table gtest_err_3 ( @@ -75,8 +72,7 @@ create table gtest_err_3 ( create table gtest_err_4 ( a int primary key, - b double precision - generated always as (random()) stored + b double precision generated always as (random()) stored ); create table gtest2 ( @@ -93,25 +89,22 @@ create table gtest_err_5a ( create table gtest_err_5b ( a int primary key, - b int - generated always as identity - generated always as (a * 2) stored + b int generated always as identity generated always as (a * 2) stored ); create table gtest_err_6a ( a int primary key, - b boolean generated always as (xmin <> 37) stored + b bool generated always as (xmin <> 37) stored ); create table gtest_err_7a ( a int primary key, - b int generated always as (AVG(a)) stored + b int generated always as (avg(a)) stored ); create table gtest_err_7b ( a int primary key, - b int - generated always as (ROW_NUMBER() over (order by a)) stored + b int generated always as (row_number() over (order by a)) stored ); create table gtest_err_7c ( @@ -121,8 +114,7 @@ create table gtest_err_7c ( create table gtest_err_7d ( a int primary key, - b int - generated always as (generate_series(1, a)) stored + b int generated always as (generate_series(1, a)) stored ); insert into gtest1 values (1); @@ -325,8 +317,7 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest0, -gtesty); +inherits (gtest0, gtesty); drop table gtesty; @@ -336,8 +327,7 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); drop table gtesty; @@ -347,12 +337,10 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); create table gtest1_y (b int generated always as (x + 1) stored) -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); create table gtestp (f1 int); @@ -441,8 +429,7 @@ create type double_int as (a int, b int); create table gtest4 ( a int, - b double_int - generated always as ((a * 2, a * 3)) stored + b double_int generated always as ((a * 2, a * 3)) stored ); insert into gtest4 values (1), (6); @@ -455,8 +442,7 @@ drop type double_int; create table gtest_tableoid ( a int primary key, - b boolean - generated always as (tableoid = cast('gtest_tableoid' as regclass)) stored + b bool generated always as (tableoid = cast('gtest_tableoid' as regclass)) stored ); insert into gtest_tableoid values (1), (2); @@ -498,15 +484,13 @@ create table gtest11 ( insert into gtest11 values (1, 10), (2, 20); -grant SELECT (a, c) on table gtest11 to regress_user11; +grant select (a, c) on table gtest11 to regress_user11; create function gf1(a int) returns int language sql immutable -as $function$ -SELECT a * 3 -$function$; +as $$ SELECT a * 3 $$; revoke all on function gf1(int) from public; @@ -518,7 +502,7 @@ create table gtest12 ( insert into gtest12 values (1, 10), (2, 20); -grant SELECT (a, c), INSERT on table gtest12 to regress_user11; +grant select (a, c), insert on table gtest12 to regress_user11; set role to regress_user11; @@ -544,9 +528,7 @@ drop role regress_user11; create table gtest20 ( a int primary key, - b int - generated always as (a * 2) stored - check (b < 50) + b int generated always as (a * 2) stored check (b < 50) ); insert into gtest20 (a) values (10); @@ -574,10 +556,10 @@ alter table gtest20a add check (b < 50); alter table gtest20a - add column c double precision default random() check (b < 50); + add column c float8 default random() check (b < 50); alter table gtest20a - add column c double precision default random() check (b < 61); + add column c float8 default random() check (b < 61); create table gtest20b ( a int primary key, @@ -589,7 +571,7 @@ insert into gtest20b (a) values (10); insert into gtest20b (a) values (30); alter table gtest20b - add constraint "chk" check (b < 50) not valid; + add constraint chk check (b < 50) not valid; alter table gtest20b validate constraint chk; @@ -600,7 +582,7 @@ create table gtest20c ( ); alter table gtest20c - add constraint "whole_row_check" check (gtest20c is not null); + add constraint whole_row_check check (gtest20c is not null); insert into gtest20c values (1); @@ -608,9 +590,7 @@ insert into gtest20c values (null); create table gtest21a ( a int primary key, - b int - generated always as (nullif(a, 0)) stored - not null + b int generated always as (nullif(a, 0)) stored not null ); insert into gtest21a (a) values (1); @@ -660,18 +640,11 @@ create table gtest22c ( b int generated always as (a * 2) stored ); -create index "gtest22c_b_idx" on gtest22c using btree (b); +create index gtest22c_b_idx on gtest22c using btree (b); -create index "gtest22c_expr_idx" on gtest22c using btree ((b * 3)); +create index gtest22c_expr_idx on gtest22c using btree ((b * 3)); -create index "gtest22c_pred_idx" -on gtest22c -using btree -( - a -) -where - b > 0; +create index gtest22c_pred_idx on gtest22c using btree (a) where b > 0; insert into gtest22c values (1), (2), (3); @@ -722,23 +695,17 @@ insert into gtest23a values (1, 11), (2, 22), (3, 33); create table gtest23x ( a int primary key, - b int - generated always as (a * 2) stored - references gtest23a (x) on UPDATE cascade + b int generated always as (a * 2) stored references gtest23a (x) on update cascade ); create table gtest23x ( a int primary key, - b int - generated always as (a * 2) stored - references gtest23a (x) on DELETE set null + b int generated always as (a * 2) stored references gtest23a (x) on delete set null ); create table gtest23b ( a int primary key, - b int - generated always as (a * 2) stored - references gtest23a (x) + b int generated always as (a * 2) stored references gtest23a (x) ); insert into gtest23b values (1); @@ -789,8 +756,7 @@ create type gtestdomain1range as range (subtype = gtestdomain1); create table gtest24r ( a int primary key, - b gtestdomain1range - generated always as (gtestdomain1range(a, a + 5)) stored + b gtestdomain1range generated always as (gtestdomain1range(a, a + 5)) stored ); insert into gtest24r (a) values (4); @@ -836,8 +802,7 @@ create table gtest_child ( alter table gtest_parent attach partition - gtest_child - for values from ('2016-07-01') to ('2016-08-01'); + gtest_child for values from ('2016-07-01') to ('2016-08-01'); drop table gtest_parent, gtest_child; @@ -879,8 +844,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -892,8 +856,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -905,15 +868,13 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -925,8 +886,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); insert into gtest_parent (f1, f2) values ('2016-07-15', 1); @@ -1001,9 +961,8 @@ alter table gtest25 add column d int default 101; alter table gtest25 - alter column d type double precision, - add column y double precision - generated always as (d * 4) stored; + alter column d type float8, + add column y float8 generated always as (d * 4) stored; select * from gtest25 order by a; @@ -1036,8 +995,8 @@ alter table gtest27 add column x bigint generated always as ((a + b) * 2) stored; alter table gtest27 - alter column a type double precision, - alter column b type double precision; + alter column a type float8, + alter column b type float8; select * from gtest27; @@ -1120,7 +1079,7 @@ alter table gtest31_1 alter column b type varchar; alter table gtest31_2 - add constraint "cc" check ((y).b is not null); + add constraint cc check ((y).b is not null); alter table gtest31_1 alter column b set expression @@ -1137,7 +1096,7 @@ alter table gtest31_1 drop statistics gtest31_2_stat; -create index "gtest31_2_y_idx" on gtest31_2 using btree (((y).b)); +create index gtest31_2_y_idx on gtest31_2 using btree (((y).b)); alter table gtest31_1 alter column b set expression @@ -1150,7 +1109,7 @@ create table gtest31_1 ( b text generated always as ('hello') stored, c text ) -partition by LIST(a); +partition by list(a); create table gtest31_2 ( x int, @@ -1170,7 +1129,7 @@ create table gtest26 ( create function gtest_trigger_func() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF tg_op IN ('DELETE', 'UPDATE') THEN RAISE INFO '%: %: old = %', TG_NAME, TG_WHEN, OLD; @@ -1184,7 +1143,7 @@ BEGIN RETURN NEW; END IF; END -$function$; +$$; create trigger gtest1 before delete or update @@ -1249,12 +1208,12 @@ drop trigger gtest3 on gtest26; create function gtest_trigger_func3() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'OK'; RETURN NEW; END -$function$; +$$; create trigger gtest11 before update of b @@ -1271,13 +1230,13 @@ truncate gtest26; create function gtest_trigger_func4() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.a = 10; NEW.b = 300; RETURN NEW; END; -$function$; +$$; create trigger gtest12_01 before insert or update @@ -1315,6 +1274,6 @@ create table gtest28a ( alter table gtest28a drop column a; -create table gtest28b (like gtest28a including GENERATED); +create table gtest28b (like gtest28a including generated); select attrelid, attname, attgenerated from pg_attribute where attgenerated not in ('', 's', 'v'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_stored_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_stored_80.snap index 431cd1306..17399c1e9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_stored_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_stored_80.snap @@ -2,9 +2,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/generated_stored.sql --- -create schema "generated_stored_tests"; +create schema generated_stored_tests; -grant USAGE on schema generated_stored_tests to public; +grant usage on schema generated_stored_tests to public; set search_path to generated_stored_tests; @@ -46,9 +46,7 @@ order by 1, create table gtest_err_1 ( a int primary key, - b int - generated always as (a * 2) stored - generated always as (a * 3) stored + b int generated always as (a * 2) stored generated always as (a * 3) stored ); create table gtest_err_2a ( @@ -64,8 +62,7 @@ create table gtest_err_2b ( create table gtest_err_2c ( a int primary key, - b int - generated always as (num_nulls(gtest_err_2c)) stored + b int generated always as (num_nulls(gtest_err_2c)) stored ); create table gtest_err_3 ( @@ -75,60 +72,49 @@ create table gtest_err_3 ( create table gtest_err_4 ( a int primary key, - b double precision - generated always as (random()) stored + b double precision generated always as (random()) stored ); create table gtest2 ( a int, - b text - generated always as (a || ' sec') stored + b text generated always as (a || ' sec') stored ); drop table gtest2; create table gtest_err_5a ( a int primary key, - b int - default 5 - generated always as (a * 2) stored + b int default 5 generated always as (a * 2) stored ); create table gtest_err_5b ( a int primary key, - b int - generated always as identity - generated always as (a * 2) stored + b int generated always as identity generated always as (a * 2) stored ); create table gtest_err_6a ( a int primary key, - b boolean - generated always as (xmin <> 37) stored + b bool generated always as (xmin <> 37) stored ); create table gtest_err_7a ( a int primary key, - b int - generated always as (AVG(a)) stored + b int generated always as (avg(a)) stored ); create table gtest_err_7b ( a int primary key, - b int - generated always as (ROW_NUMBER() over (order by a)) stored + b int generated always as (row_number() over (order by a)) stored ); create table gtest_err_7c ( a int primary key, - b int - generated always as ((select a)) stored + b int generated always as ((select a)) stored ); create table gtest_err_7d ( a int primary key, - b int - generated always as (generate_series(1, a)) stored + b int generated always as (generate_series(1, a)) stored ); insert into gtest1 values (1); @@ -194,10 +180,8 @@ create table gtestm ( id int primary key, f1 int, f2 int, - f3 int - generated always as (f1 * 2) stored, - f4 int - generated always as (f2 * 2) stored + f3 int generated always as (f1 * 2) stored, + f4 int generated always as (f2 * 2) stored ); insert into gtestm values (1, 5, 100); @@ -293,8 +277,7 @@ inherits (gtest1); create table gtestx ( x int, - b int - generated always as (a * 22) stored + b int generated always as (a * 22) stored ) inherits (gtest1); @@ -334,8 +317,7 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest0, -gtesty); +inherits (gtest0, gtesty); drop table gtesty; @@ -345,24 +327,20 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); drop table gtesty; create table gtesty ( x int, - b int - generated always as (x * 22) stored + b int generated always as (x * 22) stored ); create table gtest1_y () -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); create table gtest1_y (b int generated always as (x + 1) stored) -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); create table gtestp (f1 int); @@ -394,8 +372,7 @@ select * from gtest3 order by a; create table gtest3a ( a text, - b text - generated always as (a || '+' || a) stored + b text generated always as (a || '+' || a) stored ); insert into gtest3a (a) values ('a'), ('b'), ('c'), (null); @@ -452,8 +429,7 @@ create type double_int as (a int, b int); create table gtest4 ( a int, - b double_int - generated always as ((a * 2, a * 3)) stored + b double_int generated always as ((a * 2, a * 3)) stored ); insert into gtest4 values (1), (6); @@ -466,16 +442,14 @@ drop type double_int; create table gtest_tableoid ( a int primary key, - b boolean - generated always as (tableoid = - cast('gtest_tableoid' as regclass)) stored + b bool + generated always as (tableoid = cast('gtest_tableoid' as regclass)) stored ); insert into gtest_tableoid values (1), (2); alter table gtest_tableoid - add column c regclass - generated always as (tableoid) stored; + add column c regclass generated always as (tableoid) stored; select * from gtest_tableoid; @@ -511,28 +485,25 @@ create table gtest11 ( insert into gtest11 values (1, 10), (2, 20); -grant SELECT (a, c) on table gtest11 to regress_user11; +grant select (a, c) on table gtest11 to regress_user11; create function gf1(a int) returns int language sql immutable -as $function$ -SELECT a * 3 -$function$; +as $$ SELECT a * 3 $$; revoke all on function gf1(int) from public; create table gtest12 ( a int primary key, b int, - c int - generated always as (gf1(b)) stored + c int generated always as (gf1(b)) stored ); insert into gtest12 values (1, 10), (2, 20); -grant SELECT (a, c), INSERT on table gtest12 to regress_user11; +grant select (a, c), insert on table gtest12 to regress_user11; set role to regress_user11; @@ -558,9 +529,7 @@ drop role regress_user11; create table gtest20 ( a int primary key, - b int - generated always as (a * 2) stored - check (b < 50) + b int generated always as (a * 2) stored check (b < 50) ); insert into gtest20 (a) values (10); @@ -588,14 +557,10 @@ alter table gtest20a add check (b < 50); alter table gtest20a - add column c double precision - default random() - check (b < 50); + add column c float8 default random() check (b < 50); alter table gtest20a - add column c double precision - default random() - check (b < 61); + add column c float8 default random() check (b < 61); create table gtest20b ( a int primary key, @@ -607,7 +572,7 @@ insert into gtest20b (a) values (10); insert into gtest20b (a) values (30); alter table gtest20b - add constraint "chk" check (b < 50) not valid; + add constraint chk check (b < 50) not valid; alter table gtest20b validate constraint chk; @@ -618,7 +583,7 @@ create table gtest20c ( ); alter table gtest20c - add constraint "whole_row_check" check (gtest20c is not null); + add constraint whole_row_check check (gtest20c is not null); insert into gtest20c values (1); @@ -626,9 +591,7 @@ insert into gtest20c values (null); create table gtest21a ( a int primary key, - b int - generated always as (nullif(a, 0)) stored - not null + b int generated always as (nullif(a, 0)) stored not null ); insert into gtest21a (a) values (1); @@ -637,8 +600,7 @@ insert into gtest21a (a) values (0); create table gtest21b ( a int primary key, - b int - generated always as (nullif(a, 0)) stored + b int generated always as (nullif(a, 0)) stored ); alter table gtest21b @@ -655,9 +617,7 @@ insert into gtest21b (a) values (0); create table gtest22a ( a int primary key, - b int - generated always as (a / 2) stored - unique + b int generated always as (a / 2) stored unique ); insert into gtest22a values (2); @@ -681,18 +641,11 @@ create table gtest22c ( b int generated always as (a * 2) stored ); -create index "gtest22c_b_idx" on gtest22c using btree (b); +create index gtest22c_b_idx on gtest22c using btree (b); -create index "gtest22c_expr_idx" on gtest22c using btree ((b * 3)); +create index gtest22c_expr_idx on gtest22c using btree ((b * 3)); -create index "gtest22c_pred_idx" -on gtest22c -using btree -( - a -) -where - b > 0; +create index gtest22c_pred_idx on gtest22c using btree (a) where b > 0; insert into gtest22c values (1), (2), (3); @@ -744,24 +697,20 @@ insert into gtest23a values (1, 11), (2, 22), (3, 33); create table gtest23x ( a int primary key, b int - generated always as (a * 2) stored - references gtest23a (x) - on UPDATE cascade + generated always as (a * 2) stored + references gtest23a (x) on update cascade ); create table gtest23x ( a int primary key, b int - generated always as (a * 2) stored - references gtest23a (x) - on DELETE set null + generated always as (a * 2) stored + references gtest23a (x) on delete set null ); create table gtest23b ( a int primary key, - b int - generated always as (a * 2) stored - references gtest23a (x) + b int generated always as (a * 2) stored references gtest23a (x) ); insert into gtest23b values (1); @@ -801,8 +750,7 @@ create domain gtestdomain1 as int check (value < 10); create table gtest24 ( a int primary key, - b gtestdomain1 - generated always as (a * 2) stored + b gtestdomain1 generated always as (a * 2) stored ); insert into gtest24 (a) values (4); @@ -813,8 +761,7 @@ create type gtestdomain1range as range (subtype = gtestdomain1); create table gtest24r ( a int primary key, - b gtestdomain1range - generated always as (gtestdomain1range(a, a + 5)) stored + b gtestdomain1range generated always as (gtestdomain1range(a, a + 5)) stored ); insert into gtest24r (a) values (4); @@ -825,8 +772,7 @@ create domain gtestdomainnn as int check (value is not null); create table gtest24nn ( a int, - b gtestdomainnn - generated always as (a * 2) stored + b gtestdomainnn generated always as (a * 2) stored ); insert into gtest24nn (a) values (4); @@ -860,22 +806,19 @@ for values from ('2016-07-01') to ('2016-08-01'); create table gtest_child ( f1 date not null, f2 bigint, - f3 bigint - generated always as (f2 * 2) stored + f3 bigint generated always as (f2 * 2) stored ); alter table gtest_parent attach partition - gtest_child - for values from ('2016-07-01') to ('2016-08-01'); + gtest_child for values from ('2016-07-01') to ('2016-08-01'); drop table gtest_parent, gtest_child; create table gtest_parent ( f1 date not null, f2 bigint, - f3 bigint - generated always as (f2 * 2) stored + f3 bigint generated always as (f2 * 2) stored ) partition by range(f1); @@ -912,8 +855,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -925,8 +867,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -938,29 +879,25 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; create table gtest_child3 ( f1 date not null, f2 bigint, - f3 bigint - generated always as (f2 * 33) stored + f3 bigint generated always as (f2 * 33) stored ); alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); insert into gtest_parent (f1, f2) values ('2016-07-15', 1); @@ -999,16 +936,14 @@ select cast(tableoid as regclass), * from gtest_parent order by 1, 2, 3; create table gtest_part_key ( f1 date not null, f2 bigint, - f3 bigint - generated always as (f2 * 2) stored + f3 bigint generated always as (f2 * 2) stored ) partition by range(f3); create table gtest_part_key ( f1 date not null, f2 bigint, - f3 bigint - generated always as (f2 * 2) stored + f3 bigint generated always as (f2 * 2) stored ) partition by range((f3 * 3)); @@ -1037,17 +972,15 @@ alter table gtest25 add column d int default 101; alter table gtest25 - alter column d type double precision, - add column y double precision - generated always as (d * 4) stored; + alter column d type float8, + add column y float8 generated always as (d * 4) stored; select * from gtest25 order by a; create table gtest27 ( a int, b int, - x int - generated always as ((a + b) * 2) stored + x int generated always as ((a + b) * 2) stored ); insert into gtest27 (a, b) values (3, 7), (4, 11); @@ -1070,12 +1003,11 @@ alter table gtest27 drop column x, alter column a type bigint, alter column b type bigint, - add column x bigint - generated always as ((a + b) * 2) stored; + add column x bigint generated always as ((a + b) * 2) stored; alter table gtest27 - alter column a type double precision, - alter column b type double precision; + alter column a type float8, + alter column b type float8; select * from gtest27; @@ -1145,8 +1077,7 @@ alter table gtest30_1 create table gtest31_1 ( a int, - b text - generated always as ('hello') stored, + b text generated always as ('hello') stored, c text ); @@ -1159,7 +1090,7 @@ alter table gtest31_1 alter column b type varchar; alter table gtest31_2 - add constraint "cc" check ((y).b is not null); + add constraint cc check ((y).b is not null); alter table gtest31_1 alter column b set expression @@ -1176,7 +1107,7 @@ alter table gtest31_1 drop statistics gtest31_2_stat; -create index "gtest31_2_y_idx" on gtest31_2 using btree (((y).b)); +create index gtest31_2_y_idx on gtest31_2 using btree (((y).b)); alter table gtest31_1 alter column b set expression @@ -1186,11 +1117,10 @@ drop table gtest31_1, gtest31_2; create table gtest31_1 ( a int, - b text - generated always as ('hello') stored, + b text generated always as ('hello') stored, c text ) -partition by LIST(a); +partition by list(a); create table gtest31_2 ( x int, @@ -1210,7 +1140,7 @@ create table gtest26 ( create function gtest_trigger_func() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF tg_op IN ('DELETE', 'UPDATE') THEN RAISE INFO '%: %: old = %', TG_NAME, TG_WHEN, OLD; @@ -1224,7 +1154,7 @@ BEGIN RETURN NEW; END IF; END -$function$; +$$; create trigger gtest1 before delete or update @@ -1289,12 +1219,12 @@ drop trigger gtest3 on gtest26; create function gtest_trigger_func3() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'OK'; RETURN NEW; END -$function$; +$$; create trigger gtest11 before update of b @@ -1311,13 +1241,13 @@ truncate gtest26; create function gtest_trigger_func4() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.a = 10; NEW.b = 300; RETURN NEW; END; -$function$; +$$; create trigger gtest12_01 before insert or update @@ -1355,7 +1285,7 @@ create table gtest28a ( alter table gtest28a drop column a; -create table gtest28b (like gtest28a including GENERATED); +create table gtest28b (like gtest28a including generated); select attrelid, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_virtual_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_virtual_100.snap index 07f08c7fd..0747f16be 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_virtual_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_virtual_100.snap @@ -2,9 +2,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/generated_virtual.sql --- -create schema "generated_virtual_tests"; +create schema generated_virtual_tests; -grant USAGE on schema generated_virtual_tests to public; +grant usage on schema generated_virtual_tests to public; set search_path to generated_virtual_tests; @@ -202,8 +202,7 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest0, -gtesty); +inherits (gtest0, gtesty); drop table gtesty; @@ -213,14 +212,12 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); drop table gtesty; create table gtest1_y () -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); create table gtestp (f1 int); @@ -305,15 +302,13 @@ create user regress_user11; insert into gtest11 values (1, 10), (2, 20); -grant SELECT (a, c) on table gtest11 to regress_user11; +grant select (a, c) on table gtest11 to regress_user11; create function gf1(a int) returns int language sql immutable -as $function$ -SELECT a * 3 -$function$; +as $$ SELECT a * 3 $$; revoke all on function gf1(int) from public; @@ -353,23 +348,23 @@ alter table gtest20a add check (b < 50); alter table gtest20a - add column c double precision default random() check (b < 50); + add column c float8 default random() check (b < 50); alter table gtest20a - add column c double precision default random() check (b < 61); + add column c float8 default random() check (b < 61); insert into gtest20b (a) values (10); insert into gtest20b (a) values (30); alter table gtest20b - add constraint "chk" check (b < 50) not valid; + add constraint chk check (b < 50) not valid; alter table gtest20b validate constraint chk; alter table gtest20c - add constraint "whole_row_check" check (gtest20c is not null); + add constraint whole_row_check check (gtest20c is not null); insert into gtest20c values (1); @@ -459,8 +454,7 @@ partition by range(f1); alter table gtest_parent attach partition - gtest_child - for values from ('2016-07-01') to ('2016-08-01'); + gtest_child for values from ('2016-07-01') to ('2016-08-01'); drop table gtest_parent, gtest_child; @@ -495,8 +489,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -508,8 +501,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -521,8 +513,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -534,15 +525,13 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); insert into gtest_parent (f1, f2) values ('2016-07-15', 1); @@ -610,8 +599,8 @@ insert into gtest27 (a, b) values (null, null); delete from gtest27 where a is null and b is null; alter table gtest27 - alter column a type double precision, - alter column b type double precision; + alter column a type float8, + alter column b type float8; select * from gtest27; @@ -670,7 +659,7 @@ alter table gtest31_1 alter column b type varchar; alter table gtest31_2 - add constraint "cc" check ((y).b is not null); + add constraint cc check ((y).b is not null); alter table gtest31_1 alter column b set expression @@ -687,7 +676,7 @@ alter table gtest31_1 drop statistics gtest31_2_stat; -create index "gtest31_2_y_idx" on gtest31_2 using btree (((y).b)); +create index gtest31_2_y_idx on gtest31_2 using btree (((y).b)); alter table gtest31_1 alter column b set expression @@ -708,7 +697,7 @@ drop table gtest31_1, gtest31_2; create function gtest_trigger_func() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF tg_op IN ('DELETE', 'UPDATE') THEN RAISE INFO '%: %: old = %', TG_NAME, TG_WHEN, OLD; @@ -722,7 +711,7 @@ BEGIN RETURN NEW; END IF; END -$function$; +$$; create trigger gtest1 before delete or update @@ -787,12 +776,12 @@ drop trigger gtest3 on gtest26; create function gtest_trigger_func3() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'OK'; RETURN NEW; END -$function$; +$$; create trigger gtest11 before update of b @@ -809,13 +798,13 @@ truncate gtest26; create function gtest_trigger_func4() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.a = 10; NEW.b = 300; RETURN NEW; END; -$function$; +$$; create trigger gtest12_01 before insert or update @@ -846,7 +835,7 @@ select * from gtest26 order by a; alter table gtest28a drop column a; -create table gtest28b (like gtest28a including GENERATED); +create table gtest28b (like gtest28a including generated); select attrelid, attname, attgenerated from pg_attribute where attgenerated not in ('', 's', 'v'); @@ -855,64 +844,46 @@ insert into gtest32 values (1), (2); analyze gtest32; select - SUM(t2.b) over (partition by t2.a), - SUM(t2.c) over (partition by t2.a), - SUM(t2.d) over (partition by t2.a) + sum(t2.b) over (partition by t2.a), + sum(t2.c) over (partition by t2.a), + sum(t2.d) over (partition by t2.a) from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a order by t1.a; select - SUM(t2.b) over (partition by t2.a), - SUM(t2.c) over (partition by t2.a), - SUM(t2.d) over (partition by t2.a) + sum(t2.b) over (partition by t2.a), + sum(t2.c) over (partition by t2.a), + sum(t2.d) over (partition by t2.a) from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a order by t1.a; select t1.a from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a where coalesce(t2.b, 1) = 2; select t1.a from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a where coalesce(t2.b, 1) = 2; select t1.a from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a where coalesce(t2.b, 1) = 2 or t1.a is null; select t1.a from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a where coalesce(t2.b, 1) = 2 or t1.a is null; @@ -932,30 +903,14 @@ select from gtest32 as t1 where - exists - ( - select - 1 - from - gtest32 as t2 - where - t1.a > t2.a and t2.b = 2 - ); + exists (select 1 from gtest32 as t2 where t1.a > t2.a and t2.b = 2); select 1 from gtest32 as t1 where - exists - ( - select - 1 - from - gtest32 as t2 - where - t1.a > t2.a and t2.b = 2 - ); + exists (select 1 from gtest32 as t2 where t1.a > t2.a and t2.b = 2); drop table gtest32; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_virtual_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_virtual_80.snap index 9e5f141e4..e6c49fa73 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_virtual_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__generated_virtual_80.snap @@ -2,9 +2,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/generated_virtual.sql --- -create schema "generated_virtual_tests"; +create schema generated_virtual_tests; -grant USAGE on schema generated_virtual_tests to public; +grant usage on schema generated_virtual_tests to public; set search_path to generated_virtual_tests; @@ -172,8 +172,7 @@ inherits (gtest1); create table gtestx ( x int, - b int - generated always as (a * 22) stored + b int generated always as (a * 22) stored ) inherits (gtest1); @@ -203,8 +202,7 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest0, -gtesty); +inherits (gtest0, gtesty); drop table gtesty; @@ -214,14 +212,12 @@ create table gtesty ( ); create table gtest1_y () -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); drop table gtesty; create table gtest1_y () -inherits (gtest1, -gtesty); +inherits (gtest1, gtesty); create table gtestp (f1 int); @@ -306,15 +302,13 @@ create user regress_user11; insert into gtest11 values (1, 10), (2, 20); -grant SELECT (a, c) on table gtest11 to regress_user11; +grant select (a, c) on table gtest11 to regress_user11; create function gf1(a int) returns int language sql immutable -as $function$ -SELECT a * 3 -$function$; +as $$ SELECT a * 3 $$; revoke all on function gf1(int) from public; @@ -354,27 +348,23 @@ alter table gtest20a add check (b < 50); alter table gtest20a - add column c double precision - default random() - check (b < 50); + add column c float8 default random() check (b < 50); alter table gtest20a - add column c double precision - default random() - check (b < 61); + add column c float8 default random() check (b < 61); insert into gtest20b (a) values (10); insert into gtest20b (a) values (30); alter table gtest20b - add constraint "chk" check (b < 50) not valid; + add constraint chk check (b < 50) not valid; alter table gtest20b validate constraint chk; alter table gtest20c - add constraint "whole_row_check" check (gtest20c is not null); + add constraint whole_row_check check (gtest20c is not null); insert into gtest20c values (1); @@ -419,10 +409,7 @@ for values from (1) to (5); create table gtestnn_childdef partition of gtestnn_parent default; insert into gtestnn_parent -values - (2, 2, default), - (3, 5, default), - (14, 12, default); +values (2, 2, default), (3, 5, default), (14, 12, default); insert into gtestnn_parent values (1, 2, default); @@ -470,8 +457,7 @@ partition by range(f1); alter table gtest_parent attach partition - gtest_child - for values from ('2016-07-01') to ('2016-08-01'); + gtest_child for values from ('2016-07-01') to ('2016-08-01'); drop table gtest_parent, gtest_child; @@ -508,8 +494,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -521,8 +506,7 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; @@ -534,29 +518,25 @@ create table gtest_child3 ( alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; create table gtest_child3 ( f1 date not null, f2 bigint, - f3 bigint - generated always as (f2 * 33) stored + f3 bigint generated always as (f2 * 33) stored ); alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); drop table gtest_child3; alter table gtest_parent attach partition - gtest_child3 - for values from ('2016-09-01') to ('2016-10-01'); + gtest_child3 for values from ('2016-09-01') to ('2016-10-01'); insert into gtest_parent (f1, f2) values ('2016-07-15', 1); @@ -624,8 +604,8 @@ insert into gtest27 (a, b) values (null, null); delete from gtest27 where a is null and b is null; alter table gtest27 - alter column a type double precision, - alter column b type double precision; + alter column a type float8, + alter column b type float8; select * from gtest27; @@ -684,7 +664,7 @@ alter table gtest31_1 alter column b type varchar; alter table gtest31_2 - add constraint "cc" check ((y).b is not null); + add constraint cc check ((y).b is not null); alter table gtest31_1 alter column b set expression @@ -701,7 +681,7 @@ alter table gtest31_1 drop statistics gtest31_2_stat; -create index "gtest31_2_y_idx" on gtest31_2 using btree (((y).b)); +create index gtest31_2_y_idx on gtest31_2 using btree (((y).b)); alter table gtest31_1 alter column b set expression @@ -722,7 +702,7 @@ drop table gtest31_1, gtest31_2; create function gtest_trigger_func() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF tg_op IN ('DELETE', 'UPDATE') THEN RAISE INFO '%: %: old = %', TG_NAME, TG_WHEN, OLD; @@ -736,7 +716,7 @@ BEGIN RETURN NEW; END IF; END -$function$; +$$; create trigger gtest1 before delete or update @@ -801,12 +781,12 @@ drop trigger gtest3 on gtest26; create function gtest_trigger_func3() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'OK'; RETURN NEW; END -$function$; +$$; create trigger gtest11 before update of b @@ -823,13 +803,13 @@ truncate gtest26; create function gtest_trigger_func4() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.a = 10; NEW.b = 300; RETURN NEW; END; -$function$; +$$; create trigger gtest12_01 before insert or update @@ -860,7 +840,7 @@ select * from gtest26 order by a; alter table gtest28a drop column a; -create table gtest28b (like gtest28a including GENERATED); +create table gtest28b (like gtest28a including generated); select attrelid, @@ -876,64 +856,46 @@ insert into gtest32 values (1), (2); analyze gtest32; select - SUM(t2.b) over (partition by t2.a), - SUM(t2.c) over (partition by t2.a), - SUM(t2.d) over (partition by t2.a) + sum(t2.b) over (partition by t2.a), + sum(t2.c) over (partition by t2.a), + sum(t2.d) over (partition by t2.a) from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a order by t1.a; select - SUM(t2.b) over (partition by t2.a), - SUM(t2.c) over (partition by t2.a), - SUM(t2.d) over (partition by t2.a) + sum(t2.b) over (partition by t2.a), + sum(t2.c) over (partition by t2.a), + sum(t2.d) over (partition by t2.a) from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a order by t1.a; select t1.a from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a where coalesce(t2.b, 1) = 2; select t1.a from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a where coalesce(t2.b, 1) = 2; select t1.a from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a where coalesce(t2.b, 1) = 2 or t1.a is null; select t1.a from - gtest32 as t1 - left outer join - gtest32 as t2 - on t1.a = t2.a + gtest32 as t1 left outer join gtest32 as t2 on t1.a = t2.a where coalesce(t2.b, 1) = 2 or t1.a is null; @@ -953,30 +915,14 @@ select from gtest32 as t1 where - exists - ( - select - 1 - from - gtest32 as t2 - where - t1.a > t2.a and t2.b = 2 - ); + exists (select 1 from gtest32 as t2 where t1.a > t2.a and t2.b = 2); select 1 from gtest32 as t1 where - exists - ( - select - 1 - from - gtest32 as t2 - where - t1.a > t2.a and t2.b = 2 - ); + exists (select 1 from gtest32 as t2 where t1.a > t2.a and t2.b = 2); drop table gtest32; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__geometry_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__geometry_100.snap index e8acb7314..c7f163f28 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__geometry_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__geometry_100.snap @@ -412,7 +412,7 @@ where select c.f1, p.f1, c.f1 <-> p.f1 from circle_tbl as c, polygon_tbl as p; -create index "gcircleind" on circle_tbl using gist (f1); +create index gcircleind on circle_tbl using gist (f1); select * from circle_tbl where f1 && circle(point(1, -2), 1) order by area(f1); @@ -420,7 +420,7 @@ select * from circle_tbl where f1 && circle(point(1, -2), 1) order by area(f1); select * from circle_tbl where f1 && circle(point(1, -2), 1) order by area(f1); -create index "gpolygonind" on polygon_tbl using gist (f1); +create index gpolygonind on polygon_tbl using gist (f1); select * diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__geometry_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__geometry_80.snap index 6d543e6c0..55b177d8c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__geometry_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__geometry_80.snap @@ -20,10 +20,7 @@ select from point_tbl as p1 where - ishorizontal( - p1.f1, - cast('(0,0)' as point) - ); + ishorizontal(p1.f1, cast('(0,0)' as point)); select p1.f1 from point_tbl as p1 where p1.f1 ?- cast('(0,0)' as point); @@ -32,10 +29,7 @@ select from point_tbl as p1 where - isvertical( - p1.f1, - cast('(5.1,34.5)' as point) - ); + isvertical(p1.f1, cast('(5.1,34.5)' as point)); select p1.f1 from point_tbl as p1 where p1.f1 ?| cast('(5.1,34.5)' as point); @@ -698,7 +692,7 @@ where select c.f1, p.f1, c.f1 <-> p.f1 from circle_tbl as c, polygon_tbl as p; -create index "gcircleind" on circle_tbl using gist (f1); +create index gcircleind on circle_tbl using gist (f1); select * from circle_tbl where f1 && circle(point(1, -2), 1) order by area(f1); @@ -706,15 +700,14 @@ select * from circle_tbl where f1 && circle(point(1, -2), 1) order by area(f1); select * from circle_tbl where f1 && circle(point(1, -2), 1) order by area(f1); -create index "gpolygonind" on polygon_tbl using gist (f1); +create index gpolygonind on polygon_tbl using gist (f1); select * from polygon_tbl where - f1 @> - cast('((1,1),(2,2),(2,1))' as polygon) + f1 @> cast('((1,1),(2,2),(2,1))' as polygon) order by (poly_center(f1))[0]; select @@ -722,8 +715,7 @@ select from polygon_tbl where - f1 @> - cast('((1,1),(2,2),(2,1))' as polygon) + f1 @> cast('((1,1),(2,2),(2,1))' as polygon) order by (poly_center(f1))[0]; select @@ -731,8 +723,7 @@ select from polygon_tbl where - f1 @> - cast('((1,1),(2,2),(2,1))' as polygon) + f1 @> cast('((1,1),(2,2),(2,1))' as polygon) order by (poly_center(f1))[0]; select pg_input_is_valid('(1', 'circle'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__gin_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__gin_100.snap index c1686b64e..f1de6d3f7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__gin_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__gin_100.snap @@ -3,16 +3,10 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/gin.sql snapshot_kind: text --- -create table gin_test_tbl (i int[]) with (autovacuum_enabled = off); +create table gin_test_tbl (i int4[]) with (autovacuum_enabled = off); -create index "gin_test_idx" -on gin_test_tbl -using gin -( - i -) -with (fastupdate = 'on', -gin_pending_list_limit = 4096); +create index gin_test_idx on gin_test_tbl using gin (i) +with (fastupdate = 'on', gin_pending_list_limit = 4096); insert into gin_test_tbl select array[1, 2, g] from generate_series(1, 20000) as g; @@ -41,21 +35,21 @@ delete from gin_test_tbl where i @> array[2]; vacuum gin_test_tbl; -select COUNT(*) from gin_test_tbl where i @> array[1, 999]; +select count(*) from gin_test_tbl where i @> array[1, 999]; -select COUNT(*) from gin_test_tbl where i @> array[1, 999]; +select count(*) from gin_test_tbl where i @> array[1, 999]; set gin_fuzzy_search_limit = 1000; -select COUNT(*) > 0 as ok from gin_test_tbl where i @> array[1]; +select count(*) > 0 as ok from gin_test_tbl where i @> array[1]; -select COUNT(*) > 0 as ok from gin_test_tbl where i @> array[1]; +select count(*) > 0 as ok from gin_test_tbl where i @> array[1]; reset gin_fuzzy_search_limit; create temporary table t_gin_test_tbl ( - i int[], - j int[] + i int4[], + j int4[] ); create index on t_gin_test_tbl using gin (i, j); @@ -79,7 +73,7 @@ select * from t_gin_test_tbl where array[0] <@ i; select * from t_gin_test_tbl where array[0] <@ i; -select * from t_gin_test_tbl where array[0] <@ i and cast('{}' as int[]) <@ j; +select * from t_gin_test_tbl where array[0] <@ i and cast('{}' as int4[]) <@ j; select * from t_gin_test_tbl where i @> '{}'; @@ -90,43 +84,40 @@ returns table ( explain_line json ) language plpgsql -as $function$ +as $$ begin set enable_seqscan = off; set enable_bitmapscan = on; return query execute 'EXPLAIN (ANALYZE, FORMAT json) ' || query_sql; end; -$function$; +$$; create function execute_text_query_index(query_sql text) returns setof text language plpgsql -as $function$ +as $$ begin set enable_seqscan = off; set enable_bitmapscan = on; return query execute query_sql; end; -$function$; +$$; create function execute_text_query_heap(query_sql text) returns setof text language plpgsql -as $function$ +as $$ begin set enable_seqscan = on; set enable_bitmapscan = off; return query execute query_sql; end; -$function$; +$$; select query, - js -> 0 -> 'Plan' -> 'Plans' -> 0 -> 'Actual Rows' - as "return by index", - js -> 0 -> 'Plan' -> - 'Rows Removed by Index Recheck' - as "removed by recheck", + js -> 0 -> 'Plan' -> 'Plans' -> 0 -> 'Actual Rows' as "return by index", + js -> 0 -> 'Plan' -> 'Rows Removed by Index Recheck' as "removed by recheck", res_index = res_heap as match from ( @@ -139,24 +130,17 @@ from (' i @> ''{1}'' and i @> ''{}'' and j @> ''{}'' '), (' j @> ''{10}'' '), (' j @> ''{10}'' and i @> ''{}'' '), - ( - ' j @> ''{10}'' and j @> ''{}'' and i @> ''{}'' ' - ), + (' j @> ''{10}'' and j @> ''{}'' and i @> ''{}'' '), (' i @> ''{1}'' and j @> ''{10}'' ') ) as q (query), - lateral explain_query_json( - 'select * from t_gin_test_tbl where ' || query - ) - as js, + lateral explain_query_json('select * from t_gin_test_tbl where ' || query) as js, lateral execute_text_query_index( - 'select string_agg((i, j)::text, '' '') from t_gin_test_tbl where ' || - query + 'select string_agg((i, j)::text, '' '') from t_gin_test_tbl where ' || query ) as res_index, lateral execute_text_query_heap( - 'select string_agg((i, j)::text, '' '') from t_gin_test_tbl where ' || - query + 'select string_agg((i, j)::text, '' '') from t_gin_test_tbl where ' || query ) as res_heap; @@ -165,11 +149,7 @@ reset enable_seqscan; reset enable_bitmapscan; insert into t_gin_test_tbl -select - array[1, g, g / 10], - array[2, g, g / 10] -from - generate_series(1, 20000) as g; +select array[1, g, g / 10], array[2, g, g / 10] from generate_series(1, 20000) as g; select gin_clean_pending_list('t_gin_test_tbl_i_j_idx') is not null; @@ -179,27 +159,27 @@ set enable_seqscan = off; set enable_bitmapscan = 'on'; -select COUNT(*) from t_gin_test_tbl where j @> array[50]; +select count(*) from t_gin_test_tbl where j @> array[50]; -select COUNT(*) from t_gin_test_tbl where j @> array[50]; +select count(*) from t_gin_test_tbl where j @> array[50]; -select COUNT(*) from t_gin_test_tbl where j @> array[2]; +select count(*) from t_gin_test_tbl where j @> array[2]; -select COUNT(*) from t_gin_test_tbl where j @> array[2]; +select count(*) from t_gin_test_tbl where j @> array[2]; -select COUNT(*) from t_gin_test_tbl where j @> cast('{}' as int[]); +select count(*) from t_gin_test_tbl where j @> cast('{}' as int[]); -select COUNT(*) from t_gin_test_tbl where j @> cast('{}' as int[]); +select count(*) from t_gin_test_tbl where j @> cast('{}' as int[]); delete from t_gin_test_tbl where j @> array[2]; vacuum t_gin_test_tbl; -select COUNT(*) from t_gin_test_tbl where j @> array[50]; +select count(*) from t_gin_test_tbl where j @> array[50]; -select COUNT(*) from t_gin_test_tbl where j @> array[2]; +select count(*) from t_gin_test_tbl where j @> array[2]; -select COUNT(*) from t_gin_test_tbl where j @> cast('{}' as int[]); +select count(*) from t_gin_test_tbl where j @> cast('{}' as int[]); reset enable_seqscan; @@ -208,8 +188,8 @@ reset enable_bitmapscan; drop table t_gin_test_tbl; create unlogged table t_gin_test_tbl ( - i int[], - j int[] + i int4[], + j int4[] ); create index on t_gin_test_tbl using gin (i, j); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__gin_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__gin_80.snap index b88b3d05b..b6ecce9f3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__gin_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__gin_80.snap @@ -3,36 +3,21 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/gin.sql snapshot_kind: text --- -create table gin_test_tbl (i int[]) with (autovacuum_enabled = off); +create table gin_test_tbl (i int4[]) with (autovacuum_enabled = off); -create index "gin_test_idx" -on gin_test_tbl -using gin -( - i -) -with (fastupdate = 'on', -gin_pending_list_limit = 4096); +create index gin_test_idx on gin_test_tbl using gin (i) +with (fastupdate = 'on', gin_pending_list_limit = 4096); insert into gin_test_tbl -select - array[1, 2, g] -from - generate_series(1, 20000) as g; +select array[1, 2, g] from generate_series(1, 20000) as g; insert into gin_test_tbl -select - array[1, 3, g] -from - generate_series(1, 1000) as g; +select array[1, 3, g] from generate_series(1, 1000) as g; select gin_clean_pending_list('gin_test_idx') > 10 as many; insert into gin_test_tbl -select - array[3, 1, g] -from - generate_series(1, 1000) as g; +select array[3, 1, g] from generate_series(1, 1000) as g; vacuum gin_test_tbl; @@ -46,36 +31,30 @@ alter index gin_test_idx set (fastupdate = off); insert into gin_test_tbl -select - array[1, 2, g] -from - generate_series(1, 1000) as g; +select array[1, 2, g] from generate_series(1, 1000) as g; insert into gin_test_tbl -select - array[1, 3, g] -from - generate_series(1, 1000) as g; +select array[1, 3, g] from generate_series(1, 1000) as g; delete from gin_test_tbl where i @> array[2]; vacuum gin_test_tbl; -select COUNT(*) from gin_test_tbl where i @> array[1, 999]; +select count(*) from gin_test_tbl where i @> array[1, 999]; -select COUNT(*) from gin_test_tbl where i @> array[1, 999]; +select count(*) from gin_test_tbl where i @> array[1, 999]; set gin_fuzzy_search_limit = 1000; -select COUNT(*) > 0 as ok from gin_test_tbl where i @> array[1]; +select count(*) > 0 as ok from gin_test_tbl where i @> array[1]; -select COUNT(*) > 0 as ok from gin_test_tbl where i @> array[1]; +select count(*) > 0 as ok from gin_test_tbl where i @> array[1]; reset gin_fuzzy_search_limit; create temporary table t_gin_test_tbl ( - i int[], - j int[] + i int4[], + j int4[] ); create index on t_gin_test_tbl using gin (i, j); @@ -99,7 +78,7 @@ select * from t_gin_test_tbl where array[0] <@ i; select * from t_gin_test_tbl where array[0] <@ i; -select * from t_gin_test_tbl where array[0] <@ i and cast('{}' as int[]) <@ j; +select * from t_gin_test_tbl where array[0] <@ i and cast('{}' as int4[]) <@ j; select * from t_gin_test_tbl where i @> '{}'; @@ -110,44 +89,40 @@ returns table ( explain_line json ) language plpgsql -as $function$ +as $$ begin set enable_seqscan = off; set enable_bitmapscan = on; return query execute 'EXPLAIN (ANALYZE, FORMAT json) ' || query_sql; end; -$function$; +$$; create function execute_text_query_index(query_sql text) returns setof text language plpgsql -as $function$ +as $$ begin set enable_seqscan = off; set enable_bitmapscan = on; return query execute query_sql; end; -$function$; +$$; create function execute_text_query_heap(query_sql text) returns setof text language plpgsql -as $function$ +as $$ begin set enable_seqscan = on; set enable_bitmapscan = off; return query execute query_sql; end; -$function$; +$$; select query, - js -> 0 -> 'Plan' -> 'Plans' -> 0 -> - 'Actual Rows' - as "return by index", - js -> 0 -> 'Plan' -> - 'Rows Removed by Index Recheck' - as "removed by recheck", + js -> 0 -> 'Plan' -> 'Plans' -> 0 -> 'Actual Rows' as "return by index", + js -> 0 -> 'Plan' -> 'Rows Removed by Index Recheck' as "removed by recheck", res_index = res_heap as match from ( @@ -157,30 +132,21 @@ from (' i @> ''{}'' and j @> ''{}'' '), (' i @> ''{1}'' '), (' i @> ''{1}'' and j @> ''{}'' '), - ( - ' i @> ''{1}'' and i @> ''{}'' and j @> ''{}'' ' - ), + (' i @> ''{1}'' and i @> ''{}'' and j @> ''{}'' '), (' j @> ''{10}'' '), (' j @> ''{10}'' and i @> ''{}'' '), - ( - ' j @> ''{10}'' and j @> ''{}'' and i @> ''{}'' ' - ), + (' j @> ''{10}'' and j @> ''{}'' and i @> ''{}'' '), (' i @> ''{1}'' and j @> ''{10}'' ') ) as q (query), - lateral explain_query_json( - 'select * from t_gin_test_tbl where ' || - query - ) + lateral explain_query_json('select * from t_gin_test_tbl where ' || query) as js, lateral execute_text_query_index( - 'select string_agg((i, j)::text, '' '') from t_gin_test_tbl where ' || - query + 'select string_agg((i, j)::text, '' '') from t_gin_test_tbl where ' || query ) as res_index, lateral execute_text_query_heap( - 'select string_agg((i, j)::text, '' '') from t_gin_test_tbl where ' || - query + 'select string_agg((i, j)::text, '' '') from t_gin_test_tbl where ' || query ) as res_heap; @@ -203,27 +169,27 @@ set enable_seqscan = off; set enable_bitmapscan = 'on'; -select COUNT(*) from t_gin_test_tbl where j @> array[50]; +select count(*) from t_gin_test_tbl where j @> array[50]; -select COUNT(*) from t_gin_test_tbl where j @> array[50]; +select count(*) from t_gin_test_tbl where j @> array[50]; -select COUNT(*) from t_gin_test_tbl where j @> array[2]; +select count(*) from t_gin_test_tbl where j @> array[2]; -select COUNT(*) from t_gin_test_tbl where j @> array[2]; +select count(*) from t_gin_test_tbl where j @> array[2]; -select COUNT(*) from t_gin_test_tbl where j @> cast('{}' as int[]); +select count(*) from t_gin_test_tbl where j @> cast('{}' as int[]); -select COUNT(*) from t_gin_test_tbl where j @> cast('{}' as int[]); +select count(*) from t_gin_test_tbl where j @> cast('{}' as int[]); delete from t_gin_test_tbl where j @> array[2]; vacuum t_gin_test_tbl; -select COUNT(*) from t_gin_test_tbl where j @> array[50]; +select count(*) from t_gin_test_tbl where j @> array[50]; -select COUNT(*) from t_gin_test_tbl where j @> array[2]; +select count(*) from t_gin_test_tbl where j @> array[2]; -select COUNT(*) from t_gin_test_tbl where j @> cast('{}' as int[]); +select count(*) from t_gin_test_tbl where j @> cast('{}' as int[]); reset enable_seqscan; @@ -232,8 +198,8 @@ reset enable_bitmapscan; drop table t_gin_test_tbl; create unlogged table t_gin_test_tbl ( - i int[], - j int[] + i int4[], + j int4[] ); create index on t_gin_test_tbl using gin (i, j); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__gist_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__gist_100.snap index a3fb21dee..15e49fae3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__gist_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__gist_100.snap @@ -4,82 +4,38 @@ input_file: crates/pgls_pretty_print/tests/data/multi/gist.sql snapshot_kind: text --- create table gist_point_tbl ( - id int, + id int4, p point ); -create index "gist_pointidx" on gist_point_tbl using gist (p); +create index gist_pointidx on gist_point_tbl using gist (p); -create index "gist_pointidx2" -on gist_point_tbl -using gist -( - p -) -with (buffering = 'on', -fillfactor = 50); - -create index "gist_pointidx3" -on gist_point_tbl -using gist -( - p -) -with (buffering = off); +create index gist_pointidx2 on gist_point_tbl using gist (p) +with (buffering = 'on', fillfactor = 50); -create index "gist_pointidx4" -on gist_point_tbl -using gist -( - p -) -with (buffering = auto); +create index gist_pointidx3 on gist_point_tbl using gist (p) with (buffering = off); + +create index gist_pointidx4 on gist_point_tbl using gist (p) with (buffering = auto); drop index gist_pointidx2, gist_pointidx3, gist_pointidx4; -create index "gist_pointidx5" -on gist_point_tbl -using gist -( - p -) -with (buffering = invalid_value); +create index gist_pointidx5 on gist_point_tbl using gist (p) with (buffering = invalid_value); -create index "gist_pointidx5" -on gist_point_tbl -using gist -( - p -) -with (fillfactor = 9); +create index gist_pointidx5 on gist_point_tbl using gist (p) with (fillfactor = 9); -create index "gist_pointidx5" -on gist_point_tbl -using gist -( - p -) -with (fillfactor = 101); +create index gist_pointidx5 on gist_point_tbl using gist (p) with (fillfactor = 101); insert into gist_point_tbl (id, p) -select - g, - point(g * 10, g * 10) -from - generate_series(1, 10000) as g; +select g, point(g * 10, g * 10) from generate_series(1, 10000) as g; insert into gist_point_tbl (id, p) -select - g + 100000, - point(g * 10 + 1, g * 10 + 1) -from - generate_series(1, 10000) as g; +select g + 100000, point(g * 10 + 1, g * 10 + 1) from generate_series(1, 10000) as g; delete from gist_point_tbl where id % 2 = 1; delete from gist_point_tbl where id > 5000; -vacuum (ANALYZE) gist_point_tbl; +vacuum (analyze) gist_point_tbl; alter index gist_pointidx set (fillfactor = 40); @@ -94,16 +50,13 @@ create table gist_tbl ( insert into gist_tbl select - box( - point(0.05 * i, 0.05 * i), - point(0.05 * i, 0.05 * i) - ), + box(point(0.05 * i, 0.05 * i), point(0.05 * i, 0.05 * i)), point(0.05 * i, 0.05 * i), circle(point(0.05 * i, 0.05 * i), 1.0) from generate_series(0, 10000) as i; -vacuum (ANALYZE) gist_tbl; +vacuum (analyze) gist_tbl; set enable_seqscan = off; @@ -111,7 +64,7 @@ set enable_bitmapscan = off; set enable_indexonlyscan = 'on'; -create index "gist_tbl_point_index" on gist_tbl using gist (p); +create index gist_tbl_point_index on gist_tbl using gist (p); select p from gist_tbl where p <@ box(point(0, 0), point(0.5, 0.5)); @@ -160,17 +113,7 @@ from ) as v (bb) inner join - lateral ( - select - p - from - gist_tbl - where - p <@ bb - order by p <-> bb[0] - limit 2 - ) - as ss + lateral (select p from gist_tbl where p <@ bb order by p <-> bb[0] limit 2) as ss on true; select @@ -184,22 +127,12 @@ from ) as v (bb) inner join - lateral ( - select - p - from - gist_tbl - where - p <@ bb - order by p <-> bb[0] - limit 2 - ) - as ss + lateral (select p from gist_tbl where p <@ bb order by p <-> bb[0] limit 2) as ss on true; drop index gist_tbl_point_index; -create index "gist_tbl_box_index" on gist_tbl using gist (b); +create index gist_tbl_box_index on gist_tbl using gist (b); select b from gist_tbl where b <@ box(point(5, 5), point(6, 6)); @@ -215,7 +148,7 @@ select b from gist_tbl where b <@ box(point(5, 5), point(6, 6)) order by point(5 drop index gist_tbl_box_index; -create index "gist_tbl_multi_index" on gist_tbl using gist (p, c); +create index gist_tbl_multi_index on gist_tbl using gist (p, c); select p, c from gist_tbl where p <@ box(point(5, 5), point(6, 6)); @@ -225,12 +158,11 @@ select from gist_tbl where - b <@ box(point(4.5, 4.5), point(5.5, 5.5)) and - p <@ box(point(5, 5), point(6, 6)); + b <@ box(point(4.5, 4.5), point(5.5, 5.5)) and p <@ box(point(5, 5), point(6, 6)); drop index gist_tbl_multi_index; -create index "gist_tbl_multi_index" on gist_tbl using gist ((circle(p, 1)), p); +create index gist_tbl_multi_index on gist_tbl using gist ((circle(p, 1)), p); select circle(p, 1) from gist_tbl where p <@ box(point(5, 5), point(5.3, 5.3)); @@ -240,22 +172,16 @@ select p from gist_tbl where circle(p, 1) @> circle(point(0, 0), 0.95); select p from gist_tbl where circle(p, 1) @> circle(point(0, 0), 0.95); -select COUNT(*) from gist_tbl; +select count(*) from gist_tbl; -select COUNT(*) from gist_tbl; +select count(*) from gist_tbl; select p from gist_tbl order by circle(p, 1) <-> point(0, 0) limit 1; select p from gist_tbl order by circle(p, 1) <-> point(0, 0) limit 1; -create index "gist_tbl_box_index_forcing_buffering" -on gist_tbl -using gist -( - p -) -with (buffering = 'on', -fillfactor = 50); +create index gist_tbl_box_index_forcing_buffering on gist_tbl using gist (p) +with (buffering = 'on', fillfactor = 50); reset enable_seqscan; @@ -267,7 +193,7 @@ drop table gist_tbl; create unlogged table gist_tbl (b box); -create index "gist_tbl_box_index" on gist_tbl using gist (b); +create index gist_tbl_box_index on gist_tbl using gist (b); insert into gist_tbl select box(point(0.05 * i, 0.05 * i)) from generate_series(0, 10) as i; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__gist_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__gist_80.snap index 92997a865..f59185dee 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__gist_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__gist_80.snap @@ -4,69 +4,34 @@ input_file: crates/pgls_pretty_print/tests/data/multi/gist.sql snapshot_kind: text --- create table gist_point_tbl ( - id int, + id int4, p point ); -create index "gist_pointidx" on gist_point_tbl using gist (p); +create index gist_pointidx on gist_point_tbl using gist (p); -create index "gist_pointidx2" -on gist_point_tbl -using gist -( - p -) -with (buffering = 'on', -fillfactor = 50); - -create index "gist_pointidx3" -on gist_point_tbl -using gist -( - p -) +create index gist_pointidx2 on gist_point_tbl using gist (p) +with (buffering = 'on', fillfactor = 50); + +create index gist_pointidx3 on gist_point_tbl using gist (p) with (buffering = off); -create index "gist_pointidx4" -on gist_point_tbl -using gist -( - p -) +create index gist_pointidx4 on gist_point_tbl using gist (p) with (buffering = auto); drop index gist_pointidx2, gist_pointidx3, gist_pointidx4; -create index "gist_pointidx5" -on gist_point_tbl -using gist -( - p -) +create index gist_pointidx5 on gist_point_tbl using gist (p) with (buffering = invalid_value); -create index "gist_pointidx5" -on gist_point_tbl -using gist -( - p -) +create index gist_pointidx5 on gist_point_tbl using gist (p) with (fillfactor = 9); -create index "gist_pointidx5" -on gist_point_tbl -using gist -( - p -) +create index gist_pointidx5 on gist_point_tbl using gist (p) with (fillfactor = 101); insert into gist_point_tbl (id, p) -select - g, - point(g * 10, g * 10) -from - generate_series(1, 10000) as g; +select g, point(g * 10, g * 10) from generate_series(1, 10000) as g; insert into gist_point_tbl (id, p) select @@ -79,7 +44,7 @@ delete from gist_point_tbl where id % 2 = 1; delete from gist_point_tbl where id > 5000; -vacuum (ANALYZE) gist_point_tbl; +vacuum (analyze) gist_point_tbl; alter index gist_pointidx set (fillfactor = 40); @@ -94,16 +59,13 @@ create table gist_tbl ( insert into gist_tbl select - box( - point(0.05 * i, 0.05 * i), - point(0.05 * i, 0.05 * i) - ), + box(point(0.05 * i, 0.05 * i), point(0.05 * i, 0.05 * i)), point(0.05 * i, 0.05 * i), circle(point(0.05 * i, 0.05 * i), 1.0) from generate_series(0, 10000) as i; -vacuum (ANALYZE) gist_tbl; +vacuum (analyze) gist_tbl; set enable_seqscan = off; @@ -111,7 +73,7 @@ set enable_bitmapscan = off; set enable_indexonlyscan = 'on'; -create index "gist_tbl_point_index" on gist_tbl using gist (p); +create index gist_tbl_point_index on gist_tbl using gist (p); select p from gist_tbl where p <@ box(point(0, 0), point(0.5, 0.5)); @@ -155,22 +117,13 @@ from ( values (box(point(0, 0), point(0.5, 0.5))), - ( - box(point(0.5, 0.5), point(0.75, 0.75)) - ), + (box(point(0.5, 0.5), point(0.75, 0.75))), (box(point(0.8, 0.8), point(1.0, 1.0))) ) as v (bb) inner join lateral ( - select - p - from - gist_tbl - where - p <@ bb - order by p <-> bb[0] - limit 2 + select p from gist_tbl where p <@ bb order by p <-> bb[0] limit 2 ) as ss on true; @@ -181,29 +134,20 @@ from ( values (box(point(0, 0), point(0.5, 0.5))), - ( - box(point(0.5, 0.5), point(0.75, 0.75)) - ), + (box(point(0.5, 0.5), point(0.75, 0.75))), (box(point(0.8, 0.8), point(1.0, 1.0))) ) as v (bb) inner join lateral ( - select - p - from - gist_tbl - where - p <@ bb - order by p <-> bb[0] - limit 2 + select p from gist_tbl where p <@ bb order by p <-> bb[0] limit 2 ) as ss on true; drop index gist_tbl_point_index; -create index "gist_tbl_box_index" on gist_tbl using gist (b); +create index gist_tbl_box_index on gist_tbl using gist (b); select b from gist_tbl where b <@ box(point(5, 5), point(6, 6)); @@ -243,7 +187,7 @@ order by point(5.2, 5.91) <-> b; drop index gist_tbl_box_index; -create index "gist_tbl_multi_index" on gist_tbl using gist (p, c); +create index gist_tbl_multi_index on gist_tbl using gist (p, c); select p, c from gist_tbl where p <@ box(point(5, 5), point(6, 6)); @@ -253,13 +197,12 @@ select from gist_tbl where - b <@ - box(point(4.5, 4.5), point(5.5, 5.5)) and + b <@ box(point(4.5, 4.5), point(5.5, 5.5)) and p <@ box(point(5, 5), point(6, 6)); drop index gist_tbl_multi_index; -create index "gist_tbl_multi_index" on gist_tbl using gist ((circle(p, 1)), p); +create index gist_tbl_multi_index on gist_tbl using gist ((circle(p, 1)), p); select circle(p, 1) from gist_tbl where p <@ box(point(5, 5), point(5.3, 5.3)); @@ -269,22 +212,16 @@ select p from gist_tbl where circle(p, 1) @> circle(point(0, 0), 0.95); select p from gist_tbl where circle(p, 1) @> circle(point(0, 0), 0.95); -select COUNT(*) from gist_tbl; +select count(*) from gist_tbl; -select COUNT(*) from gist_tbl; +select count(*) from gist_tbl; select p from gist_tbl order by circle(p, 1) <-> point(0, 0) limit 1; select p from gist_tbl order by circle(p, 1) <-> point(0, 0) limit 1; -create index "gist_tbl_box_index_forcing_buffering" -on gist_tbl -using gist -( - p -) -with (buffering = 'on', -fillfactor = 50); +create index gist_tbl_box_index_forcing_buffering on gist_tbl using gist (p) +with (buffering = 'on', fillfactor = 50); reset enable_seqscan; @@ -296,12 +233,9 @@ drop table gist_tbl; create unlogged table gist_tbl (b box); -create index "gist_tbl_box_index" on gist_tbl using gist (b); +create index gist_tbl_box_index on gist_tbl using gist (b); insert into gist_tbl -select - box(point(0.05 * i, 0.05 * i)) -from - generate_series(0, 10) as i; +select box(point(0.05 * i, 0.05 * i)) from generate_series(0, 10) as i; drop table gist_tbl; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap index b6915ee46..0016dcc4a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap @@ -72,23 +72,23 @@ create temporary table gstest_empty ( create function gstest_data(v int, out a int, out b int) returns setof record language plpgsql -as $function$ -begin +as $f$ + begin return query select v, i from generate_series(1,3) i; end; -$function$; + $f$; set enable_hashagg = 'false'; -select a, b, grouping(a, b), SUM(v), COUNT(*), MAX(v) from gstest1 group by rollup (a, b); +select a, b, grouping(a, b), sum(v), count(*), max(v) from gstest1 group by rollup (a, b); select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by rollup (a, b) @@ -99,9 +99,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by rollup (a, b) @@ -112,9 +112,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by rollup (a, b) @@ -127,7 +127,7 @@ select array_agg(v order by v), string_agg(cast(v as text), ':' order by v desc), percentile_disc(0.5) within group (order by v), - RANK(1, 2, 12) within group (order by a, b, v) + rank(1, 2, 12) within group (order by a, b, v) from gstest1 group by rollup (a, b) @@ -138,21 +138,18 @@ select grouping(a), a, array_agg(b), - RANK(a) within group (order by b nulls first), - RANK(a) within group (order by b nulls last) + rank(a) within group (order by b nulls first), + rank(a) within group (order by b nulls last) from - ( - values (1, 1), (1, 4), (1, 5), (3, 1), (3, 2) - ) - as v (a, b) + (values (1, 1), (1, 4), (1, 5), (3, 1), (3, 2)) as v (a, b) group by rollup (a) order by a; select a, b, - SUM(c), - SUM(SUM(c)) over (order by a, b) as rsum + sum(c), + sum(sum(c)) over (order by a, b) as rsum from gstest2 group by rollup (a, b) @@ -161,77 +158,68 @@ order by rsum, b; select - SUM(c) + sum(c) from gstest2 -group by grouping sets ((), - grouping sets ((), grouping sets (()))) +group by grouping sets ((), grouping sets ((), grouping sets (()))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets ((), - grouping sets ((), grouping sets ((a, b)))) +group by grouping sets ((), grouping sets ((), grouping sets ((a, b)))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets (grouping sets (rollup (c), - grouping sets (cube (c)))) +group by grouping sets (grouping sets (rollup (c), grouping sets (cube (c)))) order by 1 desc; -select SUM(c) from gstest2 group by grouping sets (a, grouping sets (a, cube (b))) order by 1 desc; +select sum(c) from gstest2 group by grouping sets (a, grouping sets (a, cube (b))) order by 1 desc; -select SUM(c) from gstest2 group by grouping sets (grouping sets ((a, b))) order by 1 desc; +select sum(c) from gstest2 group by grouping sets (grouping sets ((a, b))) order by 1 desc; -select SUM(c) from gstest2 group by grouping sets (grouping sets ((a, b))) order by 1 desc; +select sum(c) from gstest2 group by grouping sets (grouping sets ((a, b))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 group by grouping sets (grouping sets (a, grouping sets (a), a)) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets (grouping sets (a, - grouping sets (a, - grouping sets (a), - a, - a, - grouping sets (a), - a), - a)) +group by grouping sets ( + grouping sets (a, grouping sets (a, grouping sets (a), a, a, grouping sets (a), a), a) + ) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets ((a, (a, b)), - grouping sets ((a, (a, b)), a)) +group by grouping sets ((a, (a, b)), grouping sets ((a, (a, b)), a)) order by 1 desc; -select a, b, SUM(v), COUNT(*) from gstest_empty group by grouping sets ((a, b), a); +select a, b, sum(v), count(*) from gstest_empty group by grouping sets ((a, b), a); -select a, b, SUM(v), COUNT(*) from gstest_empty group by grouping sets ((a, b), ()); +select a, b, sum(v), count(*) from gstest_empty group by grouping sets ((a, b), ()); -select a, b, SUM(v), COUNT(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); +select a, b, sum(v), count(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); -select SUM(v), COUNT(*) from gstest_empty group by grouping sets ((), (), ()); +select sum(v), count(*) from gstest_empty group by grouping sets ((), (), ()); select t1.a, t2.b, - SUM(t1.v), - COUNT(*) + sum(t1.v), + count(*) from gstest_empty as t1, gstest_empty as t2 @@ -241,8 +229,8 @@ select t1.a, t2.b, grouping(t1.a, t2.b), - SUM(t1.v), - MAX(t2.a) + sum(t1.v), + max(t2.a) from gstest1 as t1, gstest2 as t2 @@ -252,28 +240,20 @@ select t1.a, t2.b, grouping(t1.a, t2.b), - SUM(t1.v), - MAX(t2.a) + sum(t1.v), + max(t2.a) from - gstest1 as t1 - inner join - gstest2 as t2 - on t1.a = t2.a + gstest1 as t1 inner join gstest2 as t2 on t1.a = t2.a group by grouping sets ((t1.a, t2.b), ()); select a, b, grouping(a, b), - SUM(t1.v), - MAX(t2.c) -from - gstest1 as t1 - inner join - gstest2 as t2 - using ( - "a", - "b") + sum(t1.v), + max(t2.c) +from + gstest1 as t1 inner join gstest2 as t2 using ( a, b) group by grouping sets ((a, b), ()); select a, d, grouping(a, b, c) from gstest3 group by grouping sets ((a, b), (a, c)); @@ -286,15 +266,7 @@ select four, x from - ( - select - four, - ten, - cast('foo' as text) as x - from - tenk1 - ) - as t + (select four, ten, cast('foo' as text) as x from tenk1) as t group by grouping sets (four, x) having x = 'foo'; @@ -303,21 +275,13 @@ select four, x || 'x' from - ( - select - four, - ten, - cast('foo' as text) as x - from - tenk1 - ) - as t + (select four, ten, cast('foo' as text) as x from tenk1) as t group by grouping sets (four, x) order by four; select (x + y) * 1, - SUM(z) + sum(z) from (select 1 as x, 2 as y, 3 as z) as s group by grouping sets (x + y, x); @@ -355,98 +319,59 @@ order by 1, select * from - ( - select - 1 as x, - q1, - SUM(q2) - from - int8_tbl as i1 - group by grouping sets (1, 2) - ) - as ss + (select 1 as x, q1, sum(q2) from int8_tbl as i1 group by grouping sets (1, 2)) as ss where x = 1 and q1 = 123; select * from - ( - select - 1 as x, - q1, - SUM(q2) - from - int8_tbl as i1 - group by grouping sets (1, 2) - ) - as ss + (select 1 as x, q1, sum(q2) from int8_tbl as i1 group by grouping sets (1, 2)) as ss where x = 1 and q1 = 123; select grouping(ss.x) from - int8_tbl as i1 - inner join - lateral (select (select i1.q1) as x) as ss - on true + int8_tbl as i1 inner join lateral (select (select i1.q1) as x) as ss on true group by ss.x; select grouping(ss.x) from - int8_tbl as i1 - inner join - lateral (select (select i1.q1) as x) as ss - on true + int8_tbl as i1 inner join lateral (select (select i1.q1) as x) as ss on true group by ss.x; select (select grouping(ss.x)) from - int8_tbl as i1 - inner join - lateral (select (select i1.q1) as x) as ss - on true + int8_tbl as i1 inner join lateral (select (select i1.q1) as x) as ss on true group by ss.x; select (select grouping(ss.x)) from - int8_tbl as i1 - inner join - lateral (select (select i1.q1) as x) as ss - on true + int8_tbl as i1 inner join lateral (select (select i1.q1) as x) as ss on true group by ss.x; -select a, b, SUM(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) group by rollup (a, b); +select a, b, sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) group by rollup (a, b); select * from (values (1), (2)) as v (x), - lateral ( - select - a, - b, - SUM(v.x) - from - gstest_data(v.x) - group by rollup (a, b) - ) - as s; + lateral (select a, b, sum(v.x) from gstest_data(v.x) group by rollup (a, b)) as s; -select MIN(unique1) from tenk1 group by (); +select min(unique1) from tenk1 group by (); create view gstest_view as select a, b, grouping(a, b), - SUM(c), - COUNT(*), - MAX(c) + sum(c), + count(*), + max(c) from gstest2 group by rollup ((a, b, c), (c, d)); @@ -456,9 +381,7 @@ select pg_get_viewdef(cast('gstest_view' as regclass), true); select ( select - ( - select grouping(a, b) from (values (1)) as v2 (c) - ) + (select grouping(a, b) from (values (1)) as v2 (c)) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -470,9 +393,7 @@ group by rollup (e, f); select ( select - ( - select grouping(e, f) from (values (1)) as v2 (c) - ) + (select grouping(e, f) from (values (1)) as v2 (c)) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -484,13 +405,7 @@ group by rollup (e, f); select ( select - ( - select - grouping(c) - from - (values (1)) as v2 (c) - group by c - ) + (select grouping(c) from (values (1)) as v2 (c) group by c) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -507,23 +422,19 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 -group by grouping sets ((a, b), - (a + 1, b + 1), - (a + 2, b + 2)) +group by grouping sets ((a, b), (a + 1, b + 1), (a + 2, b + 2)) order by 3, 6; select ( select - ( - select grouping(a, b) from (values (1)) as v2 (c) - ) + (select grouping(a, b) from (values (1)) as v2 (c)) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -535,9 +446,7 @@ group by rollup (e + 1, f + 1); select ( select - ( - select grouping(a, b) from (values (1)) as v2 (c) - ) + (select grouping(a, b) from (values (1)) as v2 (c)) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -551,8 +460,8 @@ order by e + 1, select a, b, - SUM(c), - SUM(SUM(c)) over (order by a, b) as rsum + sum(c), + sum(sum(c)) over (order by a, b) as rsum from gstest2 group by cube (a, b) @@ -563,7 +472,7 @@ order by rsum, select a, b, - SUM(c) + sum(c) from ( values @@ -584,7 +493,7 @@ group by rollup (a, b); select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -596,64 +505,40 @@ select * from gstest1 group by grouping sets ((a, b, v), v) order by v, b, a; select (select grouping(a, b) from gstest2) from gstest2 group by a, b; -select a, b, SUM(c), COUNT(*) from gstest2 group by grouping sets (rollup (a, b), a); +select a, b, sum(c), count(*) from gstest2 group by grouping sets (rollup (a, b), a); select ten, - SUM(distinct four) + sum(distinct four) from onek as a group by grouping sets ((ten, four), ten) having - exists - ( - select - 1 - from - onek as b - where - SUM(distinct a.four) = b.four - ); + exists (select 1 from onek as b where sum(distinct a.four) = b.four); -select a, COUNT(*) from gstest2 group by rollup (a) order by a; +select a, count(*) from gstest2 group by rollup (a) order by a; -select a, COUNT(*) from gstest2 group by rollup (a) having a is distinct from 1 order by a; +select a, count(*) from gstest2 group by rollup (a) having a is distinct from 1 order by a; -select a, COUNT(*) from gstest2 group by rollup (a) having a is distinct from 1 order by a; +select a, count(*) from gstest2 group by rollup (a) having a is distinct from 1 order by a; select v.c, - ( - select - COUNT(*) - from - gstest2 - group by () - having - v.c - ) + (select count(*) from gstest2 group by () having v.c) from (values (false), (true)) as v (c) order by v.c; select v.c, - ( - select - COUNT(*) - from - gstest2 - group by () - having - v.c - ) + (select count(*) from gstest2 group by () having v.c) from (values (false), (true)) as v (c) order by v.c; -select a, b, COUNT(*) from gstest2 group by grouping sets ((a, b), a) having a > 1 and b > 1; +select a, b, count(*) from gstest2 group by grouping sets ((a, b), a) having a > 1 and b > 1; -select a, b, COUNT(*) from gstest2 group by grouping sets ((a, b), a) having a > 1 and b > 1; +select a, b, count(*) from gstest2 group by grouping sets ((a, b), a) having a > 1 and b > 1; select ten, @@ -685,11 +570,7 @@ select ten, grouping(ten) from onek group by ten having grouping(ten) >= 0 order select ten, - SUM( - distinct four - ) - filter (where - cast(four as text) ~ '123') + sum(distinct four) filter (where cast(four as text) ~ '123') from onek as a group by rollup (ten); @@ -699,17 +580,7 @@ select from (values (1), (2)) as v (a) left outer join - lateral ( - select - v.a, - four, - ten, - COUNT(*) - from - onek - group by cube (four, ten) - ) - as s + lateral (select v.a, four, ten, count(*) from onek group by cube (four, ten)) as s on true order by v.a, four, @@ -720,29 +591,18 @@ select select row(v.a, s1.*) from - ( - select - two, - four, - COUNT(*) - from - onek - group by cube (two, four) - order by two, - four - ) - as s1 + (select two, four, count(*) from onek group by cube (two, four) order by two, four) as s1 ) from (values (1), (2)) as v (a); -select SUM(ten) from onek group by two, rollup (cast(four as text)) order by 1; +select sum(ten) from onek group by two, rollup (cast(four as text)) order by 1; -select SUM(ten) from onek group by rollup (cast(four as text)), two order by 1; +select sum(ten) from onek group by rollup (cast(four as text)), two order by 1; set enable_hashagg = 'true'; -select COUNT(*) from gstest4 group by rollup (unhashable_col, unsortable_col); +select count(*) from gstest4 group by rollup (unhashable_col, unsortable_col); select array_agg(v order by v) from gstest4 group by grouping sets ((id, unsortable_col), id); @@ -750,9 +610,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by grouping sets (a, b) @@ -764,9 +624,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by grouping sets (a, b) @@ -778,9 +638,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by cube (a, b) @@ -792,9 +652,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by cube (a, b) @@ -806,7 +666,7 @@ select a, b, grouping(a, b), array_agg(v order by v) from gstest1 group by cube select unsortable_col, - COUNT(*) + count(*) from gstest4 group by grouping sets (unsortable_col, unsortable_col) @@ -816,8 +676,8 @@ select unhashable_col, unsortable_col, grouping(unhashable_col, unsortable_col), - COUNT(*), - SUM(v) + count(*), + sum(v) from gstest4 group by grouping sets (unhashable_col, unsortable_col) @@ -828,8 +688,8 @@ select unhashable_col, unsortable_col, grouping(unhashable_col, unsortable_col), - COUNT(*), - SUM(v) + count(*), + sum(v) from gstest4 group by grouping sets (unhashable_col, unsortable_col) @@ -840,12 +700,11 @@ select unhashable_col, unsortable_col, grouping(unhashable_col, unsortable_col), - COUNT(*), - SUM(v) + count(*), + sum(v) from gstest4 -group by grouping sets ((v, unhashable_col), - (v, unsortable_col)) +group by grouping sets ((v, unhashable_col), (v, unsortable_col)) order by 3, 5; @@ -853,28 +712,27 @@ select unhashable_col, unsortable_col, grouping(unhashable_col, unsortable_col), - COUNT(*), - SUM(v) + count(*), + sum(v) from gstest4 -group by grouping sets ((v, unhashable_col), - (v, unsortable_col)) +group by grouping sets ((v, unhashable_col), (v, unsortable_col)) order by 3, 5; -select a, b, SUM(v), COUNT(*) from gstest_empty group by grouping sets ((a, b), a); +select a, b, sum(v), count(*) from gstest_empty group by grouping sets ((a, b), a); -select a, b, SUM(v), COUNT(*) from gstest_empty group by grouping sets ((a, b), a); +select a, b, sum(v), count(*) from gstest_empty group by grouping sets ((a, b), a); -select a, b, SUM(v), COUNT(*) from gstest_empty group by grouping sets ((a, b), ()); +select a, b, sum(v), count(*) from gstest_empty group by grouping sets ((a, b), ()); -select a, b, SUM(v), COUNT(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); +select a, b, sum(v), count(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); -select a, b, SUM(v), COUNT(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); +select a, b, sum(v), count(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); -select SUM(v), COUNT(*) from gstest_empty group by grouping sets ((), (), ()); +select sum(v), count(*) from gstest_empty group by grouping sets ((), (), ()); -select SUM(v), COUNT(*) from gstest_empty group by grouping sets ((), (), ()); +select sum(v), count(*) from gstest_empty group by grouping sets ((), (), ()); select a, d, grouping(a, b, c) from gstest3 group by grouping sets ((a, b), (a, c)); @@ -883,7 +741,7 @@ select a, d, grouping(a, b, c) from gstest3 group by grouping sets ((a, b), (a, select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -895,7 +753,7 @@ order by 1, select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -908,44 +766,24 @@ select * from (values (1), (2)) as v (x), - lateral ( - select - a, - b, - SUM(v.x) - from - gstest_data(v.x) - group by grouping sets (a, b) - ) - as s; + lateral (select a, b, sum(v.x) from gstest_data(v.x) group by grouping sets (a, b)) as s; select * from (values (1), (2)) as v (x), - lateral ( - select - a, - b, - SUM(v.x) - from - gstest_data(v.x) - group by grouping sets (a, b) - ) - as s; + lateral (select a, b, sum(v.x) from gstest_data(v.x) group by grouping sets (a, b)) as s; select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 -group by grouping sets ((a, b), - (a + 1, b + 1), - (a + 2, b + 2)) +group by grouping sets ((a, b), (a + 1, b + 1), (a + 2, b + 2)) order by 3, 6; @@ -953,22 +791,20 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 -group by grouping sets ((a, b), - (a + 1, b + 1), - (a + 2, b + 2)) +group by grouping sets ((a, b), (a + 1, b + 1), (a + 2, b + 2)) order by 3, 6; select a, b, - SUM(c), - SUM(SUM(c)) over (order by a, b) as rsum + sum(c), + sum(sum(c)) over (order by a, b) as rsum from gstest2 group by cube (a, b) @@ -979,8 +815,8 @@ order by rsum, select a, b, - SUM(c), - SUM(SUM(c)) over (order by a, b) as rsum + sum(c), + sum(sum(c)) over (order by a, b) as rsum from gstest2 group by cube (a, b) @@ -991,7 +827,7 @@ order by rsum, select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -1002,7 +838,7 @@ order by a, select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -1014,15 +850,15 @@ begin; set local enable_hashagg = 'false'; -select a, b, COUNT(*), MAX(a), MAX(b) from gstest3 group by grouping sets (a, b, ()) order by a, b; +select a, b, count(*), max(a), max(b) from gstest3 group by grouping sets (a, b, ()) order by a, b; -select a, b, COUNT(*), MAX(a), MAX(b) from gstest3 group by grouping sets (a, b, ()) order by a, b; +select a, b, count(*), max(a), max(b) from gstest3 group by grouping sets (a, b, ()) order by a, b; set local enable_seqscan = 'false'; -select a, b, COUNT(*), MAX(a), MAX(b) from gstest3 group by grouping sets (a, b, ()) order by a, b; +select a, b, count(*), max(a), max(b) from gstest3 group by grouping sets (a, b, ()) order by a, b; -select a, b, COUNT(*), MAX(a), MAX(b) from gstest3 group by grouping sets (a, b, ()) order by a, b; +select a, b, count(*), max(a), max(b) from gstest3 group by grouping sets (a, b, ()) order by a, b; commit; @@ -1031,17 +867,7 @@ select from (values (1), (2)) as v (a) left outer join - lateral ( - select - v.a, - four, - ten, - COUNT(*) - from - onek - group by cube (four, ten) - ) - as s + lateral (select v.a, four, ten, count(*) from onek group by cube (four, ten)) as s on true order by v.a, four, @@ -1052,18 +878,7 @@ select select row(v.a, s1.*) from - ( - select - two, - four, - COUNT(*) - from - onek - group by cube (two, four) - order by two, - four - ) - as s1 + (select two, four, count(*) from onek group by cube (two, four) order by two, four) as s1 ) from (values (1), (2)) as v (a); @@ -1073,17 +888,7 @@ select from (values (1), (2)) as v (a) left outer join - lateral ( - select - v.a, - four, - ten, - COUNT(*) - from - onek - group by grouping sets (four, ten) - ) - as s + lateral (select v.a, four, ten, count(*) from onek group by grouping sets (four, ten)) as s on true order by v.a, four, @@ -1095,15 +900,7 @@ select row(v.a, s1.*) from ( - select - two, - four, - COUNT(*) - from - onek - group by grouping sets (two, four) - order by two, - four + select two, four, count(*) from onek group by grouping sets (two, four) order by two, four ) as s1 ) @@ -1118,32 +915,26 @@ set work_mem = '64kB'; select unique1, - COUNT(two), - COUNT(four), - COUNT(ten), - COUNT(hundred), - COUNT(thousand), - COUNT(twothousand), - COUNT(*) + count(two), + count(four), + count(ten), + count(hundred), + count(thousand), + count(twothousand), + count(*) from tenk1 -group by grouping sets (unique1, - twothousand, - thousand, - hundred, - ten, - four, - two); +group by grouping sets (unique1, twothousand, thousand, hundred, ten, four, two); select unique1, - COUNT(two), - COUNT(four), - COUNT(ten), - COUNT(hundred), - COUNT(thousand), - COUNT(twothousand), - COUNT(*) + count(two), + count(four), + count(ten), + count(hundred), + count(thousand), + count(twothousand), + count(*) from tenk1 group by grouping sets (unique1, hundred, ten, four, two); @@ -1152,27 +943,21 @@ set work_mem = '384kB'; select unique1, - COUNT(two), - COUNT(four), - COUNT(ten), - COUNT(hundred), - COUNT(thousand), - COUNT(twothousand), - COUNT(*) + count(two), + count(four), + count(ten), + count(hundred), + count(thousand), + count(twothousand), + count(*) from tenk1 -group by grouping sets (unique1, - twothousand, - thousand, - hundred, - ten, - four, - two); +group by grouping sets (unique1, twothousand, thousand, hundred, ten, four, two); select v || 'a', case grouping(v || 'a') when 1 then 1 else 0 end, - COUNT(*) + count(*) from unnest(array[1, 1], array['a', 'b']) as u (i, v) group by rollup (i, v || 'a') @@ -1182,7 +967,7 @@ order by 1, select v || 'a', case when grouping(v || 'a') = 1 then 1 else 0 end, - COUNT(*) + count(*) from unnest(array[1, 1], array['a', 'b']) as u (i, v) group by rollup (i, v || 'a') @@ -1211,30 +996,14 @@ select * from (values (1), (2)) as v (a), - lateral ( - select - a, - i, - j, - COUNT(*) - from - bug_16784 - group by cube (i, j) - ) - as s + lateral (select a, i, j, count(*) from bug_16784 group by cube (i, j)) as s order by v.a, i, j; create table gs_data_1 as - select - g % 1000 as g1000, - g % 100 as g100, - g % 10 as g10, - g - from - generate_series(0, 1999) as g; + select g % 1000 as g1000, g % 100 as g100, g % 10 as g10, g from generate_series(0, 1999) as g; analyze gs_data_1; @@ -1254,9 +1023,9 @@ set jit_above_cost = 0; select g100, g10, - SUM(cast(g as numeric)), - COUNT(*), - MAX(cast(g as text)) + sum(cast(g as numeric)), + count(*), + max(cast(g as text)) from gs_data_1 group by cube (g1000, g100, g10); @@ -1266,9 +1035,9 @@ as select g100, g10, - SUM(cast(g as numeric)), - COUNT(*), - MAX(cast(g as text)) + sum(cast(g as numeric)), + count(*), + max(cast(g as text)) from gs_data_1 group by cube (g1000, g100, g10); @@ -1280,9 +1049,9 @@ set enable_sort = 'false'; select g100, g10, - SUM(cast(g as numeric)), - COUNT(*), - MAX(cast(g as text)) + sum(cast(g as numeric)), + count(*), + max(cast(g as text)) from gs_data_1 group by cube (g1000, g100, g10); @@ -1292,9 +1061,9 @@ as select g100, g10, - SUM(cast(g as numeric)), - COUNT(*), - MAX(cast(g as text)) + sum(cast(g as numeric)), + count(*), + max(cast(g as text)) from gs_data_1 group by cube (g1000, g100, g10); @@ -1305,13 +1074,9 @@ set work_mem = default; set hash_mem_multiplier = default; -select * from gs_hash_1 -except -select * from gs_group_1 +select * from gs_hash_1 except select * from gs_group_1 union all -(select * from gs_group_1 -except -select * from gs_hash_1); +(select * from gs_group_1 except select * from gs_hash_1); drop table gs_group_1; @@ -1322,10 +1087,7 @@ select b, c from - ( - values (1, 2, 3), (4, null, 6), (7, 8, 9) - ) - as t (a, b, c) + (values (1, 2, 3), (4, null, 6), (7, 8, 9)) as t (a, b, c) group by rollup (a, b), rollup (a, c) order by a, @@ -1337,10 +1099,7 @@ select b, c from - ( - values (1, 2, 3), (4, null, 6), (7, 8, 9) - ) - as t (a, b, c) + (values (1, 2, 3), (4, null, 6), (7, 8, 9)) as t (a, b, c) group by rollup (a, b), rollup (a, c) order by a, @@ -1352,10 +1111,7 @@ select b, c from - ( - values (1, 2, 3), (4, null, 6), (7, 8, 9) - ) - as t (a, b, c) + (values (1, 2, 3), (4, null, 6), (7, 8, 9)) as t (a, b, c) group by distinct rollup (a, b), rollup (a, c) order by a, @@ -1367,10 +1123,7 @@ select distinct b, c from - ( - values (1, 2, 3), (4, null, 6), (7, 8, 9) - ) - as t (a, b, c) + (values (1, 2, 3), (4, null, 6), (7, 8, 9)) as t (a, b, c) group by rollup (a, b), rollup (a, c) order by a, @@ -1394,39 +1147,33 @@ insert into gstest5 select i, i from generate_series(1, 5) as i; select grouping((select t1.v from gstest5 as t2 where id = t1.id)), - (select t1.v from gstest5 as t2 where id = t1.id) - as s + (select t1.v from gstest5 as t2 where id = t1.id) as s from gstest5 as t1 group by grouping sets (v, s) order by case - when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = - 0 + when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = 0 then (select t1.v from gstest5 as t2 where id = t1.id) else null end nulls first; select grouping((select t1.v from gstest5 as t2 where id = t1.id)), - (select t1.v from gstest5 as t2 where id = t1.id) - as s + (select t1.v from gstest5 as t2 where id = t1.id) as s from gstest5 as t1 group by grouping sets (v, s) order by case - when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = - 0 + when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = 0 then (select t1.v from gstest5 as t2 where id = t1.id) else null end nulls first; select grouping((select t1.v from gstest5 as t2 where id = t1.id)), - (select t1.v from gstest5 as t2 where id = t1.id) - as s, + (select t1.v from gstest5 as t2 where id = t1.id) as s, case - when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = - 0 + when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = 0 then (select t1.v from gstest5 as t2 where id = t1.id) else null end @@ -1438,11 +1185,9 @@ order by o nulls first; select grouping((select t1.v from gstest5 as t2 where id = t1.id)), - (select t1.v from gstest5 as t2 where id = t1.id) - as s, + (select t1.v from gstest5 as t2 where id = t1.id) as s, case - when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = - 0 + when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = 0 then (select t1.v from gstest5 as t2 where id = t1.id) else null end @@ -1545,7 +1290,7 @@ select 1 as one group by rollup (one) order by one nulls first; select a, b, - ROW_NUMBER() over (order by a, b nulls first) + row_number() over (order by a, b nulls first) from (values (1, 1), (2, 2)) as t (a, b) where @@ -1555,7 +1300,7 @@ group by grouping sets ((a, b), a); select a, b, - ROW_NUMBER() over (order by a, b nulls first) + row_number() over (order by a, b nulls first) from (values (1, 1), (2, 2)) as t (a, b) where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap index bac64f969..f1b84154d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap @@ -72,11 +72,11 @@ create temporary table gstest_empty ( create function gstest_data(v int, out a int, out b int) returns setof record language plpgsql -as $function$ -begin +as $f$ + begin return query select v, i from generate_series(1,3) i; end; -$function$; + $f$; set enable_hashagg = 'false'; @@ -84,9 +84,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by rollup (a, b); @@ -95,9 +95,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by rollup (a, b) @@ -108,9 +108,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by rollup (a, b) @@ -121,9 +121,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by rollup (a, b) @@ -134,20 +134,9 @@ select b, grouping(a, b), array_agg(v order by v), - string_agg( - cast(v as text), - ':' order by v desc - ), - percentile_disc( - 0.5 - ) - within group (order by v), - RANK( - 1, - 2, - 12 - ) - within group (order by a, b, v) + string_agg(cast(v as text), ':' order by v desc), + percentile_disc(0.5) within group (order by v), + rank(1, 2, 12) within group (order by a, b, v) from gstest1 group by rollup (a, b) @@ -158,32 +147,18 @@ select grouping(a), a, array_agg(b), - RANK( - a - ) - within group (order by b nulls first), - RANK( - a - ) - within group (order by b nulls last) + rank(a) within group (order by b nulls first), + rank(a) within group (order by b nulls last) from - ( - values - (1, 1), - (1, 4), - (1, 5), - (3, 1), - (3, 2) - ) - as v (a, b) + (values (1, 1), (1, 4), (1, 5), (3, 1), (3, 2)) as v (a, b) group by rollup (a) order by a; select a, b, - SUM(c), - SUM(SUM(c)) over (order by a, b) as rsum + sum(c), + sum(sum(c)) over (order by a, b) as rsum from gstest2 group by rollup (a, b) @@ -192,86 +167,79 @@ order by rsum, b; select - SUM(c) + sum(c) from gstest2 -group by grouping sets ((), - grouping sets ((), grouping sets (()))) +group by grouping sets ((), grouping sets ((), grouping sets (()))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets ((), - grouping sets ((), - grouping sets ((a, b)))) +group by grouping sets ((), grouping sets ((), grouping sets ((a, b)))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets (grouping sets (rollup (c), - grouping sets (cube (c)))) +group by grouping sets (grouping sets (rollup (c), grouping sets (cube (c)))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets (a, - grouping sets (a, cube (b))) +group by grouping sets (a, grouping sets (a, cube (b))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 group by grouping sets (grouping sets ((a, b))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 group by grouping sets (grouping sets ((a, b))) order by 1 desc; select - SUM(c) + sum(c) from gstest2 group by grouping sets (grouping sets (a, grouping sets (a), a)) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets (grouping sets (a, - grouping sets (a, - grouping sets (a), - a, - a, - grouping sets (a), - a), - a)) +group by grouping sets ( + grouping sets ( + a, + grouping sets (a, grouping sets (a), a, a, grouping sets (a), a), + a + ) + ) order by 1 desc; select - SUM(c) + sum(c) from gstest2 -group by grouping sets ((a, (a, b)), - grouping sets ((a, (a, b)), a)) +group by grouping sets ((a, (a, b)), grouping sets ((a, (a, b)), a)) order by 1 desc; select a, b, - SUM(v), - COUNT(*) + sum(v), + count(*) from gstest_empty group by grouping sets ((a, b), a); @@ -279,8 +247,8 @@ group by grouping sets ((a, b), a); select a, b, - SUM(v), - COUNT(*) + sum(v), + count(*) from gstest_empty group by grouping sets ((a, b), ()); @@ -288,19 +256,19 @@ group by grouping sets ((a, b), ()); select a, b, - SUM(v), - COUNT(*) + sum(v), + count(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); -select SUM(v), COUNT(*) from gstest_empty group by grouping sets ((), (), ()); +select sum(v), count(*) from gstest_empty group by grouping sets ((), (), ()); select t1.a, t2.b, - SUM(t1.v), - COUNT(*) + sum(t1.v), + count(*) from gstest_empty as t1, gstest_empty as t2 @@ -310,8 +278,8 @@ select t1.a, t2.b, grouping(t1.a, t2.b), - SUM(t1.v), - MAX(t2.a) + sum(t1.v), + max(t2.a) from gstest1 as t1, gstest2 as t2 @@ -321,28 +289,20 @@ select t1.a, t2.b, grouping(t1.a, t2.b), - SUM(t1.v), - MAX(t2.a) + sum(t1.v), + max(t2.a) from - gstest1 as t1 - inner join - gstest2 as t2 - on t1.a = t2.a + gstest1 as t1 inner join gstest2 as t2 on t1.a = t2.a group by grouping sets ((t1.a, t2.b), ()); select a, b, grouping(a, b), - SUM(t1.v), - MAX(t2.c) -from - gstest1 as t1 - inner join - gstest2 as t2 - using ( - "a", - "b") + sum(t1.v), + max(t2.c) +from + gstest1 as t1 inner join gstest2 as t2 using ( a, b) group by grouping sets ((a, b), ()); select @@ -373,15 +333,7 @@ select four, x from - ( - select - four, - ten, - cast('foo' as text) as x - from - tenk1 - ) - as t + (select four, ten, cast('foo' as text) as x from tenk1) as t group by grouping sets (four, x) having x = 'foo'; @@ -390,21 +342,13 @@ select four, x || 'x' from - ( - select - four, - ten, - cast('foo' as text) as x - from - tenk1 - ) - as t + (select four, ten, cast('foo' as text) as x from tenk1) as t group by grouping sets (four, x) order by four; select (x + y) * 1, - SUM(z) + sum(z) from (select 1 as x, 2 as y, 3 as z) as s group by grouping sets (x + y, x); @@ -414,14 +358,7 @@ select not x as not_x, q2 from - ( - select - *, - q1 = 1 as x - from - int8_tbl as i1 - ) - as t + (select *, q1 = 1 as x from int8_tbl as i1) as t group by grouping sets (x, q2) order by x, q2; @@ -430,10 +367,7 @@ select x, y from - ( - select four as x, four as y from tenk1 - ) - as t + (select four as x, four as y from tenk1) as t group by grouping sets (x, y) having y is null @@ -444,10 +378,7 @@ select x, y || 'y' from - ( - select four as x, four as y from tenk1 - ) - as t + (select four as x, four as y from tenk1) as t group by grouping sets (x, y) order by 1, 2; @@ -456,13 +387,7 @@ select * from ( - select - 1 as x, - q1, - SUM(q2) - from - int8_tbl as i1 - group by grouping sets (1, 2) + select 1 as x, q1, sum(q2) from int8_tbl as i1 group by grouping sets (1, 2) ) as ss where @@ -472,13 +397,7 @@ select * from ( - select - 1 as x, - q1, - SUM(q2) - from - int8_tbl as i1 - group by grouping sets (1, 2) + select 1 as x, q1, sum(q2) from int8_tbl as i1 group by grouping sets (1, 2) ) as ss where @@ -487,55 +406,31 @@ where select grouping(ss.x) from - int8_tbl as i1 - inner join - lateral ( - select (select i1.q1) as x - ) - as ss - on true + int8_tbl as i1 inner join lateral (select (select i1.q1) as x) as ss on true group by ss.x; select grouping(ss.x) from - int8_tbl as i1 - inner join - lateral ( - select (select i1.q1) as x - ) - as ss - on true + int8_tbl as i1 inner join lateral (select (select i1.q1) as x) as ss on true group by ss.x; select (select grouping(ss.x)) from - int8_tbl as i1 - inner join - lateral ( - select (select i1.q1) as x - ) - as ss - on true + int8_tbl as i1 inner join lateral (select (select i1.q1) as x) as ss on true group by ss.x; select (select grouping(ss.x)) from - int8_tbl as i1 - inner join - lateral ( - select (select i1.q1) as x - ) - as ss - on true + int8_tbl as i1 inner join lateral (select (select i1.q1) as x) as ss on true group by ss.x; select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -546,26 +441,20 @@ select from (values (1), (2)) as v (x), lateral ( - select - a, - b, - SUM(v.x) - from - gstest_data(v.x) - group by rollup (a, b) + select a, b, sum(v.x) from gstest_data(v.x) group by rollup (a, b) ) as s; -select MIN(unique1) from tenk1 group by (); +select min(unique1) from tenk1 group by (); create view gstest_view as select a, b, grouping(a, b), - SUM(c), - COUNT(*), - MAX(c) + sum(c), + count(*), + max(c) from gstest2 group by rollup ((a, b, c), (c, d)); @@ -575,12 +464,7 @@ select pg_get_viewdef(cast('gstest_view' as regclass), true); select ( select - ( - select - grouping(a, b) - from - (values (1)) as v2 (c) - ) + (select grouping(a, b) from (values (1)) as v2 (c)) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -592,12 +476,7 @@ group by rollup (e, f); select ( select - ( - select - grouping(e, f) - from - (values (1)) as v2 (c) - ) + (select grouping(e, f) from (values (1)) as v2 (c)) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -609,13 +488,7 @@ group by rollup (e, f); select ( select - ( - select - grouping(c) - from - (values (1)) as v2 (c) - group by c - ) + (select grouping(c) from (values (1)) as v2 (c) group by c) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -639,26 +512,19 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 -group by grouping sets ((a, b), - (a + 1, b + 1), - (a + 2, b + 2)) +group by grouping sets ((a, b), (a + 1, b + 1), (a + 2, b + 2)) order by 3, 6; select ( select - ( - select - grouping(a, b) - from - (values (1)) as v2 (c) - ) + (select grouping(a, b) from (values (1)) as v2 (c)) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -670,12 +536,7 @@ group by rollup (e + 1, f + 1); select ( select - ( - select - grouping(a, b) - from - (values (1)) as v2 (c) - ) + (select grouping(a, b) from (values (1)) as v2 (c)) from (values (1, 2)) as v1 (a, b) group by (a, b) @@ -689,8 +550,8 @@ order by e + 1, select a, b, - SUM(c), - SUM(SUM(c)) over (order by a, b) as rsum + sum(c), + sum(sum(c)) over (order by a, b) as rsum from gstest2 group by cube (a, b) @@ -701,7 +562,7 @@ order by rsum, select a, b, - SUM(c) + sum(c) from ( values @@ -722,7 +583,7 @@ group by rollup (a, b); select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -737,34 +598,26 @@ select (select grouping(a, b) from gstest2) from gstest2 group by a, b; select a, b, - SUM(c), - COUNT(*) + sum(c), + count(*) from gstest2 group by grouping sets (rollup (a, b), a); select ten, - SUM(distinct four) + sum(distinct four) from onek as a group by grouping sets ((ten, four), ten) having - exists - ( - select - 1 - from - onek as b - where - SUM(distinct a.four) = b.four - ); + exists (select 1 from onek as b where sum(distinct a.four) = b.four); -select a, COUNT(*) from gstest2 group by rollup (a) order by a; +select a, count(*) from gstest2 group by rollup (a) order by a; select a, - COUNT(*) + count(*) from gstest2 group by rollup (a) @@ -774,7 +627,7 @@ order by a; select a, - COUNT(*) + count(*) from gstest2 group by rollup (a) @@ -784,30 +637,14 @@ order by a; select v.c, - ( - select - COUNT(*) - from - gstest2 - group by () - having - v.c - ) + (select count(*) from gstest2 group by () having v.c) from (values (false), (true)) as v (c) order by v.c; select v.c, - ( - select - COUNT(*) - from - gstest2 - group by () - having - v.c - ) + (select count(*) from gstest2 group by () having v.c) from (values (false), (true)) as v (c) order by v.c; @@ -815,7 +652,7 @@ order by v.c; select a, b, - COUNT(*) + count(*) from gstest2 group by grouping sets ((a, b), a) @@ -825,7 +662,7 @@ having select a, b, - COUNT(*) + count(*) from gstest2 group by grouping sets ((a, b), a) @@ -889,11 +726,7 @@ order by 2, select ten, - SUM( - distinct four - ) - filter (where - cast(four as text) ~ '123') + sum(distinct four) filter (where cast(four as text) ~ '123') from onek as a group by rollup (ten); @@ -904,14 +737,7 @@ from (values (1), (2)) as v (a) left outer join lateral ( - select - v.a, - four, - ten, - COUNT(*) - from - onek - group by cube (four, ten) + select v.a, four, ten, count(*) from onek group by cube (four, ten) ) as s on true @@ -928,7 +754,7 @@ select select two, four, - COUNT(*) + count(*) from onek group by cube (two, four) @@ -940,13 +766,13 @@ select from (values (1), (2)) as v (a); -select SUM(ten) from onek group by two, rollup (cast(four as text)) order by 1; +select sum(ten) from onek group by two, rollup (cast(four as text)) order by 1; -select SUM(ten) from onek group by rollup (cast(four as text)), two order by 1; +select sum(ten) from onek group by rollup (cast(four as text)), two order by 1; set enable_hashagg = 'true'; -select COUNT(*) from gstest4 group by rollup (unhashable_col, unsortable_col); +select count(*) from gstest4 group by rollup (unhashable_col, unsortable_col); select array_agg(v order by v) @@ -958,9 +784,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by grouping sets (a, b) @@ -972,9 +798,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by grouping sets (a, b) @@ -986,9 +812,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by cube (a, b) @@ -1000,9 +826,9 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 group by cube (a, b) @@ -1021,23 +847,21 @@ group by cube (a, b); select unsortable_col, - COUNT(*) + count(*) from gstest4 -group by grouping sets (unsortable_col, - unsortable_col) +group by grouping sets (unsortable_col, unsortable_col) order by cast(unsortable_col as text); select unhashable_col, unsortable_col, grouping(unhashable_col, unsortable_col), - COUNT(*), - SUM(v) + count(*), + sum(v) from gstest4 -group by grouping sets (unhashable_col, - unsortable_col) +group by grouping sets (unhashable_col, unsortable_col) order by 3, 5; @@ -1045,12 +869,11 @@ select unhashable_col, unsortable_col, grouping(unhashable_col, unsortable_col), - COUNT(*), - SUM(v) + count(*), + sum(v) from gstest4 -group by grouping sets (unhashable_col, - unsortable_col) +group by grouping sets (unhashable_col, unsortable_col) order by 3, 5; @@ -1058,12 +881,11 @@ select unhashable_col, unsortable_col, grouping(unhashable_col, unsortable_col), - COUNT(*), - SUM(v) + count(*), + sum(v) from gstest4 -group by grouping sets ((v, unhashable_col), - (v, unsortable_col)) +group by grouping sets ((v, unhashable_col), (v, unsortable_col)) order by 3, 5; @@ -1071,20 +893,19 @@ select unhashable_col, unsortable_col, grouping(unhashable_col, unsortable_col), - COUNT(*), - SUM(v) + count(*), + sum(v) from gstest4 -group by grouping sets ((v, unhashable_col), - (v, unsortable_col)) +group by grouping sets ((v, unhashable_col), (v, unsortable_col)) order by 3, 5; select a, b, - SUM(v), - COUNT(*) + sum(v), + count(*) from gstest_empty group by grouping sets ((a, b), a); @@ -1092,8 +913,8 @@ group by grouping sets ((a, b), a); select a, b, - SUM(v), - COUNT(*) + sum(v), + count(*) from gstest_empty group by grouping sets ((a, b), a); @@ -1101,8 +922,8 @@ group by grouping sets ((a, b), a); select a, b, - SUM(v), - COUNT(*) + sum(v), + count(*) from gstest_empty group by grouping sets ((a, b), ()); @@ -1110,8 +931,8 @@ group by grouping sets ((a, b), ()); select a, b, - SUM(v), - COUNT(*) + sum(v), + count(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); @@ -1119,15 +940,15 @@ group by grouping sets ((a, b), (), (), ()); select a, b, - SUM(v), - COUNT(*) + sum(v), + count(*) from gstest_empty group by grouping sets ((a, b), (), (), ()); -select SUM(v), COUNT(*) from gstest_empty group by grouping sets ((), (), ()); +select sum(v), count(*) from gstest_empty group by grouping sets ((), (), ()); -select SUM(v), COUNT(*) from gstest_empty group by grouping sets ((), (), ()); +select sum(v), count(*) from gstest_empty group by grouping sets ((), (), ()); select a, @@ -1148,7 +969,7 @@ group by grouping sets ((a, b), (a, c)); select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -1160,7 +981,7 @@ order by 1, select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -1174,13 +995,7 @@ select from (values (1), (2)) as v (x), lateral ( - select - a, - b, - SUM(v.x) - from - gstest_data(v.x) - group by grouping sets (a, b) + select a, b, sum(v.x) from gstest_data(v.x) group by grouping sets (a, b) ) as s; @@ -1189,13 +1004,7 @@ select from (values (1), (2)) as v (x), lateral ( - select - a, - b, - SUM(v.x) - from - gstest_data(v.x) - group by grouping sets (a, b) + select a, b, sum(v.x) from gstest_data(v.x) group by grouping sets (a, b) ) as s; @@ -1203,14 +1012,12 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 -group by grouping sets ((a, b), - (a + 1, b + 1), - (a + 2, b + 2)) +group by grouping sets ((a, b), (a + 1, b + 1), (a + 2, b + 2)) order by 3, 6; @@ -1218,22 +1025,20 @@ select a, b, grouping(a, b), - SUM(v), - COUNT(*), - MAX(v) + sum(v), + count(*), + max(v) from gstest1 -group by grouping sets ((a, b), - (a + 1, b + 1), - (a + 2, b + 2)) +group by grouping sets ((a, b), (a + 1, b + 1), (a + 2, b + 2)) order by 3, 6; select a, b, - SUM(c), - SUM(SUM(c)) over (order by a, b) as rsum + sum(c), + sum(sum(c)) over (order by a, b) as rsum from gstest2 group by cube (a, b) @@ -1244,8 +1049,8 @@ order by rsum, select a, b, - SUM(c), - SUM(SUM(c)) over (order by a, b) as rsum + sum(c), + sum(sum(c)) over (order by a, b) as rsum from gstest2 group by cube (a, b) @@ -1256,7 +1061,7 @@ order by rsum, select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -1267,7 +1072,7 @@ order by a, select a, b, - SUM(v.x) + sum(v.x) from (values (1), (2)) as v (x), gstest_data(v.x) @@ -1282,9 +1087,9 @@ set local enable_hashagg = 'false'; select a, b, - COUNT(*), - MAX(a), - MAX(b) + count(*), + max(a), + max(b) from gstest3 group by grouping sets (a, b, ()) @@ -1294,9 +1099,9 @@ order by a, select a, b, - COUNT(*), - MAX(a), - MAX(b) + count(*), + max(a), + max(b) from gstest3 group by grouping sets (a, b, ()) @@ -1308,9 +1113,9 @@ set local enable_seqscan = 'false'; select a, b, - COUNT(*), - MAX(a), - MAX(b) + count(*), + max(a), + max(b) from gstest3 group by grouping sets (a, b, ()) @@ -1320,9 +1125,9 @@ order by a, select a, b, - COUNT(*), - MAX(a), - MAX(b) + count(*), + max(a), + max(b) from gstest3 group by grouping sets (a, b, ()) @@ -1337,14 +1142,7 @@ from (values (1), (2)) as v (a) left outer join lateral ( - select - v.a, - four, - ten, - COUNT(*) - from - onek - group by cube (four, ten) + select v.a, four, ten, count(*) from onek group by cube (four, ten) ) as s on true @@ -1361,7 +1159,7 @@ select select two, four, - COUNT(*) + count(*) from onek group by cube (two, four) @@ -1383,7 +1181,7 @@ from v.a, four, ten, - COUNT(*) + count(*) from onek group by grouping sets (four, ten) @@ -1403,7 +1201,7 @@ select select two, four, - COUNT(*) + count(*) from onek group by grouping sets (two, four) @@ -1423,85 +1221,77 @@ set work_mem = '64kB'; select unique1, - COUNT(two), - COUNT(four), - COUNT(ten), - COUNT(hundred), - COUNT(thousand), - COUNT(twothousand), - COUNT(*) + count(two), + count(four), + count(ten), + count(hundred), + count(thousand), + count(twothousand), + count(*) from tenk1 -group by grouping sets (unique1, - twothousand, - thousand, - hundred, - ten, - four, - two); +group by grouping sets ( + unique1, + twothousand, + thousand, + hundred, + ten, + four, + two + ); select unique1, - COUNT(two), - COUNT(four), - COUNT(ten), - COUNT(hundred), - COUNT(thousand), - COUNT(twothousand), - COUNT(*) + count(two), + count(four), + count(ten), + count(hundred), + count(thousand), + count(twothousand), + count(*) from tenk1 -group by grouping sets (unique1, - hundred, - ten, - four, - two); +group by grouping sets (unique1, hundred, ten, four, two); set work_mem = '384kB'; select unique1, - COUNT(two), - COUNT(four), - COUNT(ten), - COUNT(hundred), - COUNT(thousand), - COUNT(twothousand), - COUNT(*) + count(two), + count(four), + count(ten), + count(hundred), + count(thousand), + count(twothousand), + count(*) from tenk1 -group by grouping sets (unique1, - twothousand, - thousand, - hundred, - ten, - four, - two); +group by grouping sets ( + unique1, + twothousand, + thousand, + hundred, + ten, + four, + two + ); select v || 'a', - case grouping(v || 'a') - when 1 then 1 - else 0 - end, - COUNT(*) -from - unnest(array[1, 1], array['a', 'b']) - as u (i, v) + case grouping(v || 'a') when 1 then 1 else 0 end, + count(*) +from + unnest(array[1, 1], array['a', 'b']) as u (i, v) group by rollup (i, v || 'a') order by 1, 3; select v || 'a', - case - when grouping(v || 'a') = 1 then 1 - else 0 - end, - COUNT(*) + case when grouping(v || 'a') = 1 then 1 else 0 end, + count(*) from - unnest(array[1, 1], array['a', 'b']) - as u (i, v) + unnest(array[1, 1], array['a', 'b']) as u (i, v) group by rollup (i, v || 'a') order by 1, 3; @@ -1528,17 +1318,7 @@ select * from (values (1), (2)) as v (a), - lateral ( - select - a, - i, - j, - COUNT(*) - from - bug_16784 - group by cube (i, j) - ) - as s + lateral (select a, i, j, count(*) from bug_16784 group by cube (i, j)) as s order by v.a, i, j; @@ -1571,9 +1351,9 @@ set jit_above_cost = 0; select g100, g10, - SUM(cast(g as numeric)), - COUNT(*), - MAX(cast(g as text)) + sum(cast(g as numeric)), + count(*), + max(cast(g as text)) from gs_data_1 group by cube (g1000, g100, g10); @@ -1583,9 +1363,9 @@ as select g100, g10, - SUM(cast(g as numeric)), - COUNT(*), - MAX(cast(g as text)) + sum(cast(g as numeric)), + count(*), + max(cast(g as text)) from gs_data_1 group by cube (g1000, g100, g10); @@ -1597,9 +1377,9 @@ set enable_sort = 'false'; select g100, g10, - SUM(cast(g as numeric)), - COUNT(*), - MAX(cast(g as text)) + sum(cast(g as numeric)), + count(*), + max(cast(g as text)) from gs_data_1 group by cube (g1000, g100, g10); @@ -1609,9 +1389,9 @@ as select g100, g10, - SUM(cast(g as numeric)), - COUNT(*), - MAX(cast(g as text)) + sum(cast(g as numeric)), + count(*), + max(cast(g as text)) from gs_data_1 group by cube (g1000, g100, g10); @@ -1622,13 +1402,9 @@ set work_mem = default; set hash_mem_multiplier = default; -select * from gs_hash_1 -except -select * from gs_group_1 +select * from gs_hash_1 except select * from gs_group_1 union all -(select * from gs_group_1 -except -select * from gs_hash_1); +(select * from gs_group_1 except select * from gs_hash_1); drop table gs_group_1; @@ -1639,13 +1415,7 @@ select b, c from - ( - values - (1, 2, 3), - (4, null, 6), - (7, 8, 9) - ) - as t (a, b, c) + (values (1, 2, 3), (4, null, 6), (7, 8, 9)) as t (a, b, c) group by rollup (a, b), rollup (a, c) order by a, @@ -1657,13 +1427,7 @@ select b, c from - ( - values - (1, 2, 3), - (4, null, 6), - (7, 8, 9) - ) - as t (a, b, c) + (values (1, 2, 3), (4, null, 6), (7, 8, 9)) as t (a, b, c) group by rollup (a, b), rollup (a, c) order by a, @@ -1675,13 +1439,7 @@ select b, c from - ( - values - (1, 2, 3), - (4, null, 6), - (7, 8, 9) - ) - as t (a, b, c) + (values (1, 2, 3), (4, null, 6), (7, 8, 9)) as t (a, b, c) group by distinct rollup (a, b), rollup (a, c) order by a, @@ -1693,13 +1451,7 @@ select distinct b, c from - ( - values - (1, 2, 3), - (4, null, 6), - (7, 8, 9) - ) - as t (a, b, c) + (values (1, 2, 3), (4, null, 6), (7, 8, 9)) as t (a, b, c) group by rollup (a, b), rollup (a, c) order by a, @@ -1730,125 +1482,35 @@ create temporary table gstest5 ( insert into gstest5 select i, i from generate_series(1, 5) as i; select - grouping(( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - )), - ( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - ) - as s + grouping((select t1.v from gstest5 as t2 where id = t1.id)), + (select t1.v from gstest5 as t2 where id = t1.id) as s from gstest5 as t1 group by grouping sets (v, s) order by case - when grouping(( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - )) = - 0 - then ( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - ) + when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = 0 + then (select t1.v from gstest5 as t2 where id = t1.id) else null end nulls first; select - grouping(( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - )), - ( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - ) - as s + grouping((select t1.v from gstest5 as t2 where id = t1.id)), + (select t1.v from gstest5 as t2 where id = t1.id) as s from gstest5 as t1 group by grouping sets (v, s) order by case - when grouping(( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - )) = - 0 - then ( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - ) + when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = 0 + then (select t1.v from gstest5 as t2 where id = t1.id) else null end nulls first; select - grouping(( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - )), - ( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - ) - as s, + grouping((select t1.v from gstest5 as t2 where id = t1.id)), + (select t1.v from gstest5 as t2 where id = t1.id) as s, case - when grouping(( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - )) = - 0 - then ( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - ) + when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = 0 + then (select t1.v from gstest5 as t2 where id = t1.id) else null end as o @@ -1858,41 +1520,11 @@ group by grouping sets (v, s) order by o nulls first; select - grouping(( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - )), - ( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - ) - as s, + grouping((select t1.v from gstest5 as t2 where id = t1.id)), + (select t1.v from gstest5 as t2 where id = t1.id) as s, case - when grouping(( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - )) = - 0 - then ( - select - t1.v - from - gstest5 as t2 - where - id = t1.id - ) + when grouping((select t1.v from gstest5 as t2 where id = t1.id)) = 0 + then (select t1.v from gstest5 as t2 where id = t1.id) else null end as o @@ -2006,7 +1638,7 @@ select 1 as one group by rollup (one) order by one nulls first; select a, b, - ROW_NUMBER() over (order by a, b nulls first) + row_number() over (order by a, b nulls first) from (values (1, 1), (2, 2)) as t (a, b) where @@ -2016,7 +1648,7 @@ group by grouping sets ((a, b), a); select a, b, - ROW_NUMBER() over (order by a, b nulls first) + row_number() over (order by a, b nulls first) from (values (1, 1), (2, 2)) as t (a, b) where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__guc_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__guc_100.snap index 7ccb33f58..26d069278 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__guc_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__guc_100.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/guc.sql snapshot_kind: text --- -show "datestyle"; +show datestyle; set intervalstyle = asd; @@ -11,89 +11,89 @@ set vacuum_cost_delay = 40; set datestyle = 'ISO, YMD'; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); set local vacuum_cost_delay = 50; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -set local datestyle = SQL; +set local datestyle = 'SQL'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; set local vacuum_cost_delay = 50; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -set local datestyle = SQL; +set local datestyle = 'SQL'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); commit; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; set vacuum_cost_delay = 60; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -set datestyle = German; +set datestyle = 'German'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; set vacuum_cost_delay = 70; -set datestyle = MDY; +set datestyle = 'MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint first_sp; set vacuum_cost_delay = 80.1; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set datestyle = 'German, DMY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback to savepoint first_sp; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint second_sp; @@ -101,117 +101,117 @@ set vacuum_cost_delay = '900us'; set datestyle = 'SQL, YMD'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint third_sp; set vacuum_cost_delay = 100; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set datestyle = 'Postgres, MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback to savepoint third_sp; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback to savepoint second_sp; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint sp; set local vacuum_cost_delay = 30; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set local datestyle = 'Postgres, MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback to savepoint sp; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint sp; set local vacuum_cost_delay = 30; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set local datestyle = 'Postgres, MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); release savepoint sp; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; @@ -219,37 +219,37 @@ set vacuum_cost_delay = 40; set local vacuum_cost_delay = 50; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set datestyle = 'ISO, DMY'; set local datestyle = 'Postgres, MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); commit; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); set datestyle = iso, ymd; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); reset datestyle; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); -set seq_page_cost = NaN; +set seq_page_cost = 'NaN'; set vacuum_cost_delay = '10s'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__guc_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__guc_80.snap index 7ccb33f58..26d069278 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__guc_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__guc_80.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/guc.sql snapshot_kind: text --- -show "datestyle"; +show datestyle; set intervalstyle = asd; @@ -11,89 +11,89 @@ set vacuum_cost_delay = 40; set datestyle = 'ISO, YMD'; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); set local vacuum_cost_delay = 50; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -set local datestyle = SQL; +set local datestyle = 'SQL'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; set local vacuum_cost_delay = 50; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -set local datestyle = SQL; +set local datestyle = 'SQL'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); commit; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; set vacuum_cost_delay = 60; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -set datestyle = German; +set datestyle = 'German'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; set vacuum_cost_delay = 70; -set datestyle = MDY; +set datestyle = 'MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint first_sp; set vacuum_cost_delay = 80.1; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set datestyle = 'German, DMY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback to savepoint first_sp; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint second_sp; @@ -101,117 +101,117 @@ set vacuum_cost_delay = '900us'; set datestyle = 'SQL, YMD'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint third_sp; set vacuum_cost_delay = 100; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set datestyle = 'Postgres, MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback to savepoint third_sp; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback to savepoint second_sp; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint sp; set local vacuum_cost_delay = 30; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set local datestyle = 'Postgres, MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback to savepoint sp; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); savepoint sp; set local vacuum_cost_delay = 30; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set local datestyle = 'Postgres, MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); release savepoint sp; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); rollback; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); begin; @@ -219,37 +219,37 @@ set vacuum_cost_delay = 40; set local vacuum_cost_delay = 50; -show "vacuum_cost_delay"; +show vacuum_cost_delay; set datestyle = 'ISO, DMY'; set local datestyle = 'Postgres, MDY'; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); commit; -show "vacuum_cost_delay"; +show vacuum_cost_delay; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); set datestyle = iso, ymd; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); reset datestyle; -show "datestyle"; +show datestyle; -select cast('2006-08-13 12:34:56' as timestamp with time zone); +select cast('2006-08-13 12:34:56' as timestamptz); -set seq_page_cost = NaN; +set seq_page_cost = 'NaN'; set vacuum_cost_delay = '10s'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_func_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_func_100.snap index 0ea865527..8d2b552cb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_func_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_func_100.snap @@ -6,194 +6,113 @@ snapshot_kind: text select v as value, cast(hashint2(v) as bit(32)) as standard, - cast(hashint2extended(v, 0) as bit(32)) - as extended0, - cast(hashint2extended(v, 1) as bit(32)) - as extended1 + cast(hashint2extended(v, 0) as bit(32)) as extended0, + cast(hashint2extended(v, 1) as bit(32)) as extended1 from - ( - values - (cast(0 as smallint)), - (cast(1 as smallint)), - (cast(17 as smallint)), - (cast(42 as smallint)) - ) - as x (v) + (values (cast(0 as int2)), (cast(1 as int2)), (cast(17 as int2)), (cast(42 as int2))) as x (v) where - cast(hashint2(v) as bit(32)) <> - cast(hashint2extended(v, 0) as bit(32)) or - cast(hashint2(v) as bit(32)) = - cast(hashint2extended(v, 1) as bit(32)); + cast(hashint2(v) as bit(32)) <> cast(hashint2extended(v, 0) as bit(32)) or + cast(hashint2(v) as bit(32)) = cast(hashint2extended(v, 1) as bit(32)); select v as value, cast(hashint4(v) as bit(32)) as standard, - cast(hashint4extended(v, 0) as bit(32)) - as extended0, - cast(hashint4extended(v, 1) as bit(32)) - as extended1 + cast(hashint4extended(v, 0) as bit(32)) as extended0, + cast(hashint4extended(v, 1) as bit(32)) as extended1 from - ( - values (0), (1), (17), (42), (550273), (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashint4(v) as bit(32)) <> - cast(hashint4extended(v, 0) as bit(32)) or - cast(hashint4(v) as bit(32)) = - cast(hashint4extended(v, 1) as bit(32)); + cast(hashint4(v) as bit(32)) <> cast(hashint4extended(v, 0) as bit(32)) or + cast(hashint4(v) as bit(32)) = cast(hashint4extended(v, 1) as bit(32)); select v as value, cast(hashint8(v) as bit(32)) as standard, - cast(hashint8extended(v, 0) as bit(32)) - as extended0, - cast(hashint8extended(v, 1) as bit(32)) - as extended1 + cast(hashint8extended(v, 0) as bit(32)) as extended0, + cast(hashint8extended(v, 1) as bit(32)) as extended1 from - ( - values (0), (1), (17), (42), (550273), (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashint8(v) as bit(32)) <> - cast(hashint8extended(v, 0) as bit(32)) or - cast(hashint8(v) as bit(32)) = - cast(hashint8extended(v, 1) as bit(32)); + cast(hashint8(v) as bit(32)) <> cast(hashint8extended(v, 0) as bit(32)) or + cast(hashint8(v) as bit(32)) = cast(hashint8extended(v, 1) as bit(32)); select v as value, cast(hashfloat4(v) as bit(32)) as standard, - cast(hashfloat4extended(v, 0) as bit(32)) - as extended0, - cast(hashfloat4extended(v, 1) as bit(32)) - as extended1 + cast(hashfloat4extended(v, 0) as bit(32)) as extended0, + cast(hashfloat4extended(v, 1) as bit(32)) as extended1 from - ( - values (0), (1), (17), (42), (550273), (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashfloat4(v) as bit(32)) <> - cast(hashfloat4extended(v, 0) as bit(32)) or - cast(hashfloat4(v) as bit(32)) = - cast(hashfloat4extended(v, 1) as bit(32)); + cast(hashfloat4(v) as bit(32)) <> cast(hashfloat4extended(v, 0) as bit(32)) or + cast(hashfloat4(v) as bit(32)) = cast(hashfloat4extended(v, 1) as bit(32)); select v as value, cast(hashfloat8(v) as bit(32)) as standard, - cast(hashfloat8extended(v, 0) as bit(32)) - as extended0, - cast(hashfloat8extended(v, 1) as bit(32)) - as extended1 + cast(hashfloat8extended(v, 0) as bit(32)) as extended0, + cast(hashfloat8extended(v, 1) as bit(32)) as extended1 from - ( - values (0), (1), (17), (42), (550273), (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashfloat8(v) as bit(32)) <> - cast(hashfloat8extended(v, 0) as bit(32)) or - cast(hashfloat8(v) as bit(32)) = - cast(hashfloat8extended(v, 1) as bit(32)); + cast(hashfloat8(v) as bit(32)) <> cast(hashfloat8extended(v, 0) as bit(32)) or + cast(hashfloat8(v) as bit(32)) = cast(hashfloat8extended(v, 1) as bit(32)); select v as value, cast(hashoid(v) as bit(32)) as standard, - cast(hashoidextended(v, 0) as bit(32)) - as extended0, - cast(hashoidextended(v, 1) as bit(32)) - as extended1 + cast(hashoidextended(v, 0) as bit(32)) as extended0, + cast(hashoidextended(v, 1) as bit(32)) as extended1 from - ( - values (0), (1), (17), (42), (550273), (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashoid(v) as bit(32)) <> - cast(hashoidextended(v, 0) as bit(32)) or - cast(hashoid(v) as bit(32)) = - cast(hashoidextended(v, 1) as bit(32)); + cast(hashoid(v) as bit(32)) <> cast(hashoidextended(v, 0) as bit(32)) or + cast(hashoid(v) as bit(32)) = cast(hashoidextended(v, 1) as bit(32)); select v as value, cast(hashchar(v) as bit(32)) as standard, - cast(hashcharextended(v, 0) as bit(32)) - as extended0, - cast(hashcharextended(v, 1) as bit(32)) - as extended1 + cast(hashcharextended(v, 0) as bit(32)) as extended0, + cast(hashcharextended(v, 1) as bit(32)) as extended1 from - ( - values - (cast(null as "char")), - ('1'), - ('x'), - ('X'), - ('p'), - ('N') - ) - as x (v) + (values (cast(null as "char")), ('1'), ('x'), ('X'), ('p'), ('N')) as x (v) where - cast(hashchar(v) as bit(32)) <> - cast(hashcharextended(v, 0) as bit(32)) or - cast(hashchar(v) as bit(32)) = - cast(hashcharextended(v, 1) as bit(32)); + cast(hashchar(v) as bit(32)) <> cast(hashcharextended(v, 0) as bit(32)) or + cast(hashchar(v) as bit(32)) = cast(hashcharextended(v, 1) as bit(32)); select v as value, cast(hashname(v) as bit(32)) as standard, - cast(hashnameextended(v, 0) as bit(32)) - as extended0, - cast(hashnameextended(v, 1) as bit(32)) - as extended1 + cast(hashnameextended(v, 0) as bit(32)) as extended0, + cast(hashnameextended(v, 1) as bit(32)) as extended1 from ( - values - (null), - ('PostgreSQL'), - ('eIpUEtqmY89'), - ('AXKEJBTK'), - ('muop28x03'), - ('yi3nm0d73') + values (null), ('PostgreSQL'), ('eIpUEtqmY89'), ('AXKEJBTK'), ('muop28x03'), ('yi3nm0d73') ) as x (v) where - cast(hashname(v) as bit(32)) <> - cast(hashnameextended(v, 0) as bit(32)) or - cast(hashname(v) as bit(32)) = - cast(hashnameextended(v, 1) as bit(32)); + cast(hashname(v) as bit(32)) <> cast(hashnameextended(v, 0) as bit(32)) or + cast(hashname(v) as bit(32)) = cast(hashnameextended(v, 1) as bit(32)); select v as value, cast(hashtext(v) as bit(32)) as standard, - cast(hashtextextended(v, 0) as bit(32)) - as extended0, - cast(hashtextextended(v, 1) as bit(32)) - as extended1 + cast(hashtextextended(v, 0) as bit(32)) as extended0, + cast(hashtextextended(v, 1) as bit(32)) as extended1 from ( - values - (null), - ('PostgreSQL'), - ('eIpUEtqmY89'), - ('AXKEJBTK'), - ('muop28x03'), - ('yi3nm0d73') + values (null), ('PostgreSQL'), ('eIpUEtqmY89'), ('AXKEJBTK'), ('muop28x03'), ('yi3nm0d73') ) as x (v) where - cast(hashtext(v) as bit(32)) <> - cast(hashtextextended(v, 0) as bit(32)) or - cast(hashtext(v) as bit(32)) = - cast(hashtextextended(v, 1) as bit(32)); + cast(hashtext(v) as bit(32)) <> cast(hashtextextended(v, 0) as bit(32)) or + cast(hashtext(v) as bit(32)) = cast(hashtextextended(v, 1) as bit(32)); select v as value, cast(hashoidvector(v) as bit(32)) as standard, - cast(hashoidvectorextended(v, 0) as bit(32)) - as extended0, - cast(hashoidvectorextended(v, 1) as bit(32)) - as extended1 + cast(hashoidvectorextended(v, 0) as bit(32)) as extended0, + cast(hashoidvectorextended(v, 1) as bit(32)) as extended1 from ( values @@ -206,36 +125,25 @@ from ) as x (v) where - cast(hashoidvector(v) as bit(32)) <> - cast(hashoidvectorextended(v, 0) as bit(32)) or - cast(hashoidvector(v) as bit(32)) = - cast(hashoidvectorextended(v, 1) as bit(32)); + cast(hashoidvector(v) as bit(32)) <> cast(hashoidvectorextended(v, 0) as bit(32)) or + cast(hashoidvector(v) as bit(32)) = cast(hashoidvectorextended(v, 1) as bit(32)); select v as value, cast(hash_aclitem(v) as bit(32)) as standard, - cast(hash_aclitem_extended(v, 0) as bit(32)) - as extended0, - cast(hash_aclitem_extended(v, 1) as bit(32)) - as extended1 + cast(hash_aclitem_extended(v, 0) as bit(32)) as extended0, + cast(hash_aclitem_extended(v, 1) as bit(32)) as extended1 from - ( - select distinct relacl[1] from pg_class limit 10 - ) - as x (v) + (select distinct relacl[1] from pg_class limit 10) as x (v) where - cast(hash_aclitem(v) as bit(32)) <> - cast(hash_aclitem_extended(v, 0) as bit(32)) or - cast(hash_aclitem(v) as bit(32)) = - cast(hash_aclitem_extended(v, 1) as bit(32)); + cast(hash_aclitem(v) as bit(32)) <> cast(hash_aclitem_extended(v, 0) as bit(32)) or + cast(hash_aclitem(v) as bit(32)) = cast(hash_aclitem_extended(v, 1) as bit(32)); select v as value, cast(hashmacaddr(v) as bit(32)) as standard, - cast(hashmacaddrextended(v, 0) as bit(32)) - as extended0, - cast(hashmacaddrextended(v, 1) as bit(32)) - as extended1 + cast(hashmacaddrextended(v, 0) as bit(32)) as extended0, + cast(hashmacaddrextended(v, 1) as bit(32)) as extended1 from ( values @@ -248,18 +156,14 @@ from ) as x (v) where - cast(hashmacaddr(v) as bit(32)) <> - cast(hashmacaddrextended(v, 0) as bit(32)) or - cast(hashmacaddr(v) as bit(32)) = - cast(hashmacaddrextended(v, 1) as bit(32)); + cast(hashmacaddr(v) as bit(32)) <> cast(hashmacaddrextended(v, 0) as bit(32)) or + cast(hashmacaddr(v) as bit(32)) = cast(hashmacaddrextended(v, 1) as bit(32)); select v as value, cast(hashinet(v) as bit(32)) as standard, - cast(hashinetextended(v, 0) as bit(32)) - as extended0, - cast(hashinetextended(v, 1) as bit(32)) - as extended1 + cast(hashinetextended(v, 0) as bit(32)) as extended0, + cast(hashinetextended(v, 1) as bit(32)) as extended1 from ( values @@ -272,42 +176,28 @@ from ) as x (v) where - cast(hashinet(v) as bit(32)) <> - cast(hashinetextended(v, 0) as bit(32)) or - cast(hashinet(v) as bit(32)) = - cast(hashinetextended(v, 1) as bit(32)); + cast(hashinet(v) as bit(32)) <> cast(hashinetextended(v, 0) as bit(32)) or + cast(hashinet(v) as bit(32)) = cast(hashinetextended(v, 1) as bit(32)); select v as value, cast(hash_numeric(v) as bit(32)) as standard, - cast(hash_numeric_extended(v, 0) as bit(32)) - as extended0, - cast(hash_numeric_extended(v, 1) as bit(32)) - as extended1 + cast(hash_numeric_extended(v, 0) as bit(32)) as extended0, + cast(hash_numeric_extended(v, 1) as bit(32)) as extended1 from ( - values - (0), - (1.149484958), - (17.149484958), - (42.149484958), - (149484958.550273), - (2071124898672) + values (0), (1.149484958), (17.149484958), (42.149484958), (149484958.550273), (2071124898672) ) as x (v) where - cast(hash_numeric(v) as bit(32)) <> - cast(hash_numeric_extended(v, 0) as bit(32)) or - cast(hash_numeric(v) as bit(32)) = - cast(hash_numeric_extended(v, 1) as bit(32)); + cast(hash_numeric(v) as bit(32)) <> cast(hash_numeric_extended(v, 0) as bit(32)) or + cast(hash_numeric(v) as bit(32)) = cast(hash_numeric_extended(v, 1) as bit(32)); select v as value, cast(hashmacaddr8(v) as bit(32)) as standard, - cast(hashmacaddr8extended(v, 0) as bit(32)) - as extended0, - cast(hashmacaddr8extended(v, 1) as bit(32)) - as extended1 + cast(hashmacaddr8extended(v, 0) as bit(32)) as extended0, + cast(hashmacaddr8extended(v, 1) as bit(32)) as extended1 from ( values @@ -320,22 +210,18 @@ from ) as x (v) where - cast(hashmacaddr8(v) as bit(32)) <> - cast(hashmacaddr8extended(v, 0) as bit(32)) or - cast(hashmacaddr8(v) as bit(32)) = - cast(hashmacaddr8extended(v, 1) as bit(32)); + cast(hashmacaddr8(v) as bit(32)) <> cast(hashmacaddr8extended(v, 0) as bit(32)) or + cast(hashmacaddr8(v) as bit(32)) = cast(hashmacaddr8extended(v, 1) as bit(32)); select v as value, cast(hash_array(v) as bit(32)) as standard, - cast(hash_array_extended(v, 0) as bit(32)) - as extended0, - cast(hash_array_extended(v, 1) as bit(32)) - as extended1 + cast(hash_array_extended(v, 0) as bit(32)) as extended0, + cast(hash_array_extended(v, 1) as bit(32)) as extended1 from ( values - (cast('{0}' as int[])), + (cast('{0}' as int4[])), ('{0,1,2,3,4}'), ('{17,18,19,20}'), ('{42,34,65,98}'), @@ -344,83 +230,58 @@ from ) as x (v) where - cast(hash_array(v) as bit(32)) <> - cast(hash_array_extended(v, 0) as bit(32)) or - cast(hash_array(v) as bit(32)) = - cast(hash_array_extended(v, 1) as bit(32)); + cast(hash_array(v) as bit(32)) <> cast(hash_array_extended(v, 0) as bit(32)) or + cast(hash_array(v) as bit(32)) = cast(hash_array_extended(v, 1) as bit(32)); select v as value, cast(hash_array(v) as bit(32)) as standard from - (values (cast('{101}' as bit varying[]))) as x (v); + (values (cast('{101}' as varbit[]))) as x (v); select v as value, - cast(hash_array_extended(v, 0) as bit(32)) - as extended0 + cast(hash_array_extended(v, 0) as bit(32)) as extended0 from - (values (cast('{101}' as bit varying[]))) as x (v); + (values (cast('{101}' as varbit[]))) as x (v); select v as value, cast(hashbpchar(v) as bit(32)) as standard, - cast(hashbpcharextended(v, 0) as bit(32)) - as extended0, - cast(hashbpcharextended(v, 1) as bit(32)) - as extended1 + cast(hashbpcharextended(v, 0) as bit(32)) as extended0, + cast(hashbpcharextended(v, 1) as bit(32)) as extended1 from ( - values - (null), - ('PostgreSQL'), - ('eIpUEtqmY89'), - ('AXKEJBTK'), - ('muop28x03'), - ('yi3nm0d73') + values (null), ('PostgreSQL'), ('eIpUEtqmY89'), ('AXKEJBTK'), ('muop28x03'), ('yi3nm0d73') ) as x (v) where - cast(hashbpchar(v) as bit(32)) <> - cast(hashbpcharextended(v, 0) as bit(32)) or - cast(hashbpchar(v) as bit(32)) = - cast(hashbpcharextended(v, 1) as bit(32)); + cast(hashbpchar(v) as bit(32)) <> cast(hashbpcharextended(v, 0) as bit(32)) or + cast(hashbpchar(v) as bit(32)) = cast(hashbpcharextended(v, 1) as bit(32)); select v as value, cast(time_hash(v) as bit(32)) as standard, - cast(time_hash_extended(v, 0) as bit(32)) - as extended0, - cast(time_hash_extended(v, 1) as bit(32)) - as extended1 + cast(time_hash_extended(v, 0) as bit(32)) as extended0, + cast(time_hash_extended(v, 1) as bit(32)) as extended1 from ( - values - (cast(null as time)), - ('11:09:59'), - ('1:09:59'), - ('11:59:59'), - ('7:9:59'), - ('5:15:59') + values (cast(null as time)), ('11:09:59'), ('1:09:59'), ('11:59:59'), ('7:9:59'), ('5:15:59') ) as x (v) where - cast(time_hash(v) as bit(32)) <> - cast(time_hash_extended(v, 0) as bit(32)) or - cast(time_hash(v) as bit(32)) = - cast(time_hash_extended(v, 1) as bit(32)); + cast(time_hash(v) as bit(32)) <> cast(time_hash_extended(v, 0) as bit(32)) or + cast(time_hash(v) as bit(32)) = cast(time_hash_extended(v, 1) as bit(32)); select v as value, cast(timetz_hash(v) as bit(32)) as standard, - cast(timetz_hash_extended(v, 0) as bit(32)) - as extended0, - cast(timetz_hash_extended(v, 1) as bit(32)) - as extended1 + cast(timetz_hash_extended(v, 0) as bit(32)) as extended0, + cast(timetz_hash_extended(v, 1) as bit(32)) as extended1 from ( values - (cast(null as time with time zone)), + (cast(null as timetz)), ('00:11:52.518762-07'), ('00:11:52.51762-08'), ('00:11:52.62-01'), @@ -429,18 +290,14 @@ from ) as x (v) where - cast(timetz_hash(v) as bit(32)) <> - cast(timetz_hash_extended(v, 0) as bit(32)) or - cast(timetz_hash(v) as bit(32)) = - cast(timetz_hash_extended(v, 1) as bit(32)); + cast(timetz_hash(v) as bit(32)) <> cast(timetz_hash_extended(v, 0) as bit(32)) or + cast(timetz_hash(v) as bit(32)) = cast(timetz_hash_extended(v, 1) as bit(32)); select v as value, cast(interval_hash(v) as bit(32)) as standard, - cast(interval_hash_extended(v, 0) as bit(32)) - as extended0, - cast(interval_hash_extended(v, 1) as bit(32)) - as extended1 + cast(interval_hash_extended(v, 0) as bit(32)) as extended0, + cast(interval_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -449,24 +306,18 @@ from ('1 year 7 day 46 minutes'), ('1 year 7 month 20 day 46 minutes'), ('5 month'), - ( - '17 year 11 month 7 day 9 hours 46 minutes 5 seconds' - ) + ('17 year 11 month 7 day 9 hours 46 minutes 5 seconds') ) as x (v) where - cast(interval_hash(v) as bit(32)) <> - cast(interval_hash_extended(v, 0) as bit(32)) or - cast(interval_hash(v) as bit(32)) = - cast(interval_hash_extended(v, 1) as bit(32)); + cast(interval_hash(v) as bit(32)) <> cast(interval_hash_extended(v, 0) as bit(32)) or + cast(interval_hash(v) as bit(32)) = cast(interval_hash_extended(v, 1) as bit(32)); select v as value, cast(timestamp_hash(v) as bit(32)) as standard, - cast(timestamp_hash_extended(v, 0) as bit(32)) - as extended0, - cast(timestamp_hash_extended(v, 1) as bit(32)) - as extended1 + cast(timestamp_hash_extended(v, 0) as bit(32)) as extended0, + cast(timestamp_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -479,18 +330,14 @@ from ) as x (v) where - cast(timestamp_hash(v) as bit(32)) <> - cast(timestamp_hash_extended(v, 0) as bit(32)) or - cast(timestamp_hash(v) as bit(32)) = - cast(timestamp_hash_extended(v, 1) as bit(32)); + cast(timestamp_hash(v) as bit(32)) <> cast(timestamp_hash_extended(v, 0) as bit(32)) or + cast(timestamp_hash(v) as bit(32)) = cast(timestamp_hash_extended(v, 1) as bit(32)); select v as value, cast(uuid_hash(v) as bit(32)) as standard, - cast(uuid_hash_extended(v, 0) as bit(32)) - as extended0, - cast(uuid_hash_extended(v, 1) as bit(32)) - as extended1 + cast(uuid_hash_extended(v, 0) as bit(32)) as extended0, + cast(uuid_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -503,18 +350,14 @@ from ) as x (v) where - cast(uuid_hash(v) as bit(32)) <> - cast(uuid_hash_extended(v, 0) as bit(32)) or - cast(uuid_hash(v) as bit(32)) = - cast(uuid_hash_extended(v, 1) as bit(32)); + cast(uuid_hash(v) as bit(32)) <> cast(uuid_hash_extended(v, 0) as bit(32)) or + cast(uuid_hash(v) as bit(32)) = cast(uuid_hash_extended(v, 1) as bit(32)); select v as value, cast(pg_lsn_hash(v) as bit(32)) as standard, - cast(pg_lsn_hash_extended(v, 0) as bit(32)) - as extended0, - cast(pg_lsn_hash_extended(v, 1) as bit(32)) - as extended1 + cast(pg_lsn_hash_extended(v, 0) as bit(32)) as extended0, + cast(pg_lsn_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -527,66 +370,47 @@ from ) as x (v) where - cast(pg_lsn_hash(v) as bit(32)) <> - cast(pg_lsn_hash_extended(v, 0) as bit(32)) or - cast(pg_lsn_hash(v) as bit(32)) = - cast(pg_lsn_hash_extended(v, 1) as bit(32)); + cast(pg_lsn_hash(v) as bit(32)) <> cast(pg_lsn_hash_extended(v, 0) as bit(32)) or + cast(pg_lsn_hash(v) as bit(32)) = cast(pg_lsn_hash_extended(v, 1) as bit(32)); create type mood as enum ('sad', 'ok', 'happy'); select v as value, cast(hashenum(v) as bit(32)) as standard, - cast(hashenumextended(v, 0) as bit(32)) - as extended0, - cast(hashenumextended(v, 1) as bit(32)) - as extended1 + cast(hashenumextended(v, 0) as bit(32)) as extended0, + cast(hashenumextended(v, 1) as bit(32)) as extended1 from - ( - values (cast('sad' as mood)), ('ok'), ('happy') - ) - as x (v) + (values (cast('sad' as mood)), ('ok'), ('happy')) as x (v) where - cast(hashenum(v) as bit(32)) <> - cast(hashenumextended(v, 0) as bit(32)) or - cast(hashenum(v) as bit(32)) = - cast(hashenumextended(v, 1) as bit(32)); + cast(hashenum(v) as bit(32)) <> cast(hashenumextended(v, 0) as bit(32)) or + cast(hashenum(v) as bit(32)) = cast(hashenumextended(v, 1) as bit(32)); drop type mood; select v as value, cast(jsonb_hash(v) as bit(32)) as standard, - cast(jsonb_hash_extended(v, 0) as bit(32)) - as extended0, - cast(jsonb_hash_extended(v, 1) as bit(32)) - as extended1 + cast(jsonb_hash_extended(v, 0) as bit(32)) as extended0, + cast(jsonb_hash_extended(v, 1) as bit(32)) as extended1 from ( values (cast(null as jsonb)), - ( - '{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' - ), - ( - '{"foo": [true, "bar"], "tags": {"e": 1, "f": null}}' - ), + ('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'), + ('{"foo": [true, "bar"], "tags": {"e": 1, "f": null}}'), ('{"g": {"h": "value"}}') ) as x (v) where - cast(jsonb_hash(v) as bit(32)) <> - cast(jsonb_hash_extended(v, 0) as bit(32)) or - cast(jsonb_hash(v) as bit(32)) = - cast(jsonb_hash_extended(v, 1) as bit(32)); + cast(jsonb_hash(v) as bit(32)) <> cast(jsonb_hash_extended(v, 0) as bit(32)) or + cast(jsonb_hash(v) as bit(32)) = cast(jsonb_hash_extended(v, 1) as bit(32)); select v as value, cast(hash_range(v) as bit(32)) as standard, - cast(hash_range_extended(v, 0) as bit(32)) - as extended0, - cast(hash_range_extended(v, 1) as bit(32)) - as extended1 + cast(hash_range_extended(v, 0) as bit(32)) as extended0, + cast(hash_range_extended(v, 1) as bit(32)) as extended1 from ( values @@ -598,18 +422,14 @@ from ) as x (v) where - cast(hash_range(v) as bit(32)) <> - cast(hash_range_extended(v, 0) as bit(32)) or - cast(hash_range(v) as bit(32)) = - cast(hash_range_extended(v, 1) as bit(32)); + cast(hash_range(v) as bit(32)) <> cast(hash_range_extended(v, 0) as bit(32)) or + cast(hash_range(v) as bit(32)) = cast(hash_range_extended(v, 1) as bit(32)); select v as value, cast(hash_multirange(v) as bit(32)) as standard, - cast(hash_multirange_extended(v, 0) as bit(32)) - as extended0, - cast(hash_multirange_extended(v, 1) as bit(32)) - as extended1 + cast(hash_multirange_extended(v, 0) as bit(32)) as extended0, + cast(hash_multirange_extended(v, 1) as bit(32)) as extended1 from ( values @@ -621,78 +441,46 @@ from ) as x (v) where - cast(hash_multirange(v) as bit(32)) <> - cast(hash_multirange_extended(v, 0) as bit(32)) or - cast(hash_multirange(v) as bit(32)) = - cast(hash_multirange_extended(v, 1) as bit(32)); + cast(hash_multirange(v) as bit(32)) <> cast(hash_multirange_extended(v, 0) as bit(32)) or + cast(hash_multirange(v) as bit(32)) = cast(hash_multirange_extended(v, 1) as bit(32)); create type hash_test_t1 as (a int, b text); select v as value, cast(hash_record(v) as bit(32)) as standard, - cast(hash_record_extended(v, 0) as bit(32)) - as extended0, - cast(hash_record_extended(v, 1) as bit(32)) - as extended1 + cast(hash_record_extended(v, 0) as bit(32)) as extended0, + cast(hash_record_extended(v, 1) as bit(32)) as extended1 from - ( - values - ( - cast(row(1, 'aaa') as hash_test_t1), - row(2, 'bbb'), - row(-1, 'ccc') - ) - ) - as x (v) + (values (cast(row(1, 'aaa') as hash_test_t1), row(2, 'bbb'), row(-1, 'ccc'))) as x (v) where - cast(hash_record(v) as bit(32)) <> - cast(hash_record_extended(v, 0) as bit(32)) or - cast(hash_record(v) as bit(32)) = - cast(hash_record_extended(v, 1) as bit(32)); + cast(hash_record(v) as bit(32)) <> cast(hash_record_extended(v, 0) as bit(32)) or + cast(hash_record(v) as bit(32)) = cast(hash_record_extended(v, 1) as bit(32)); drop type hash_test_t1; -create type hash_test_t2 as (a bit varying, b text); +create type hash_test_t2 as (a varbit, b text); select v as value, cast(hash_record(v) as bit(32)) as standard from - ( - values - ( - cast(row(cast('10' as bit varying), 'aaa') - as hash_test_t2) - ) - ) - as x (v); + (values (cast(row(cast('10' as varbit), 'aaa') as hash_test_t2))) as x (v); select v as value, - cast(hash_record_extended(v, 0) as bit(32)) - as extended0 + cast(hash_record_extended(v, 0) as bit(32)) as extended0 from - ( - values - ( - cast(row(cast('11' as bit varying), 'aaa') - as hash_test_t2) - ) - ) - as x (v); + (values (cast(row(cast('11' as varbit), 'aaa') as hash_test_t2))) as x (v); drop type hash_test_t2; -select hashfloat4(cast('0' as real)) = hashfloat4(cast('-0' as real)) as t; +select hashfloat4(cast('0' as float4)) = hashfloat4(cast('-0' as float4)) as t; -select hashfloat4(cast('NaN' as real)) = hashfloat4(-cast('NaN' as real)) as t; +select hashfloat4(cast('NaN' as float4)) = hashfloat4(-cast('NaN' as float4)) as t; -select hashfloat8(cast('0' as double precision)) = hashfloat8(cast('-0' as double precision)) as t; +select hashfloat8(cast('0' as float8)) = hashfloat8(cast('-0' as float8)) as t; -select - hashfloat8(cast('NaN' as double precision)) = - hashfloat8(-cast('NaN' as double precision)) - as t; +select hashfloat8(cast('NaN' as float8)) = hashfloat8(-cast('NaN' as float8)) as t; -select hashfloat4(cast('NaN' as real)) = hashfloat8(cast('NaN' as double precision)) as t; +select hashfloat4(cast('NaN' as float4)) = hashfloat8(cast('NaN' as float8)) as t; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_func_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_func_80.snap index e3d2e9842..dbf82e727 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_func_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_func_80.snap @@ -6,186 +6,92 @@ snapshot_kind: text select v as value, cast(hashint2(v) as bit(32)) as standard, - cast(hashint2extended(v, 0) as bit(32)) - as extended0, - cast(hashint2extended(v, 1) as bit(32)) - as extended1 + cast(hashint2extended(v, 0) as bit(32)) as extended0, + cast(hashint2extended(v, 1) as bit(32)) as extended1 from ( values - (cast(0 as smallint)), - (cast(1 as smallint)), - (cast(17 as smallint)), - (cast(42 as smallint)) + (cast(0 as int2)), + (cast(1 as int2)), + (cast(17 as int2)), + (cast(42 as int2)) ) as x (v) where - cast(hashint2(v) as bit(32)) <> - cast(hashint2extended(v, 0) as bit(32)) or - cast(hashint2(v) as bit(32)) = - cast(hashint2extended(v, 1) as bit(32)); + cast(hashint2(v) as bit(32)) <> cast(hashint2extended(v, 0) as bit(32)) or + cast(hashint2(v) as bit(32)) = cast(hashint2extended(v, 1) as bit(32)); select v as value, cast(hashint4(v) as bit(32)) as standard, - cast(hashint4extended(v, 0) as bit(32)) - as extended0, - cast(hashint4extended(v, 1) as bit(32)) - as extended1 + cast(hashint4extended(v, 0) as bit(32)) as extended0, + cast(hashint4extended(v, 1) as bit(32)) as extended1 from - ( - values - (0), - (1), - (17), - (42), - (550273), - (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashint4(v) as bit(32)) <> - cast(hashint4extended(v, 0) as bit(32)) or - cast(hashint4(v) as bit(32)) = - cast(hashint4extended(v, 1) as bit(32)); + cast(hashint4(v) as bit(32)) <> cast(hashint4extended(v, 0) as bit(32)) or + cast(hashint4(v) as bit(32)) = cast(hashint4extended(v, 1) as bit(32)); select v as value, cast(hashint8(v) as bit(32)) as standard, - cast(hashint8extended(v, 0) as bit(32)) - as extended0, - cast(hashint8extended(v, 1) as bit(32)) - as extended1 + cast(hashint8extended(v, 0) as bit(32)) as extended0, + cast(hashint8extended(v, 1) as bit(32)) as extended1 from - ( - values - (0), - (1), - (17), - (42), - (550273), - (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashint8(v) as bit(32)) <> - cast(hashint8extended(v, 0) as bit(32)) or - cast(hashint8(v) as bit(32)) = - cast(hashint8extended(v, 1) as bit(32)); + cast(hashint8(v) as bit(32)) <> cast(hashint8extended(v, 0) as bit(32)) or + cast(hashint8(v) as bit(32)) = cast(hashint8extended(v, 1) as bit(32)); select v as value, - cast(hashfloat4(v) as bit(32)) - as standard, - cast(hashfloat4extended(v, 0) - as bit(32)) - as extended0, - cast(hashfloat4extended(v, 1) - as bit(32)) - as extended1 + cast(hashfloat4(v) as bit(32)) as standard, + cast(hashfloat4extended(v, 0) as bit(32)) as extended0, + cast(hashfloat4extended(v, 1) as bit(32)) as extended1 from - ( - values - (0), - (1), - (17), - (42), - (550273), - (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashfloat4(v) as bit(32)) <> - cast(hashfloat4extended(v, 0) - as bit(32)) or - cast(hashfloat4(v) as bit(32)) = - cast(hashfloat4extended(v, 1) - as bit(32)); + cast(hashfloat4(v) as bit(32)) <> cast(hashfloat4extended(v, 0) as bit(32)) or + cast(hashfloat4(v) as bit(32)) = cast(hashfloat4extended(v, 1) as bit(32)); select v as value, - cast(hashfloat8(v) as bit(32)) - as standard, - cast(hashfloat8extended(v, 0) - as bit(32)) - as extended0, - cast(hashfloat8extended(v, 1) - as bit(32)) - as extended1 + cast(hashfloat8(v) as bit(32)) as standard, + cast(hashfloat8extended(v, 0) as bit(32)) as extended0, + cast(hashfloat8extended(v, 1) as bit(32)) as extended1 from - ( - values - (0), - (1), - (17), - (42), - (550273), - (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashfloat8(v) as bit(32)) <> - cast(hashfloat8extended(v, 0) - as bit(32)) or - cast(hashfloat8(v) as bit(32)) = - cast(hashfloat8extended(v, 1) - as bit(32)); + cast(hashfloat8(v) as bit(32)) <> cast(hashfloat8extended(v, 0) as bit(32)) or + cast(hashfloat8(v) as bit(32)) = cast(hashfloat8extended(v, 1) as bit(32)); select v as value, cast(hashoid(v) as bit(32)) as standard, - cast(hashoidextended(v, 0) as bit(32)) - as extended0, - cast(hashoidextended(v, 1) as bit(32)) - as extended1 + cast(hashoidextended(v, 0) as bit(32)) as extended0, + cast(hashoidextended(v, 1) as bit(32)) as extended1 from - ( - values - (0), - (1), - (17), - (42), - (550273), - (207112489) - ) - as x (v) + (values (0), (1), (17), (42), (550273), (207112489)) as x (v) where - cast(hashoid(v) as bit(32)) <> - cast(hashoidextended(v, 0) as bit(32)) or - cast(hashoid(v) as bit(32)) = - cast(hashoidextended(v, 1) as bit(32)); + cast(hashoid(v) as bit(32)) <> cast(hashoidextended(v, 0) as bit(32)) or + cast(hashoid(v) as bit(32)) = cast(hashoidextended(v, 1) as bit(32)); select v as value, cast(hashchar(v) as bit(32)) as standard, - cast(hashcharextended(v, 0) as bit(32)) - as extended0, - cast(hashcharextended(v, 1) as bit(32)) - as extended1 + cast(hashcharextended(v, 0) as bit(32)) as extended0, + cast(hashcharextended(v, 1) as bit(32)) as extended1 from - ( - values - (cast(null as "char")), - ('1'), - ('x'), - ('X'), - ('p'), - ('N') - ) - as x (v) + (values (cast(null as "char")), ('1'), ('x'), ('X'), ('p'), ('N')) as x (v) where - cast(hashchar(v) as bit(32)) <> - cast(hashcharextended(v, 0) as bit(32)) or - cast(hashchar(v) as bit(32)) = - cast(hashcharextended(v, 1) as bit(32)); + cast(hashchar(v) as bit(32)) <> cast(hashcharextended(v, 0) as bit(32)) or + cast(hashchar(v) as bit(32)) = cast(hashcharextended(v, 1) as bit(32)); select v as value, cast(hashname(v) as bit(32)) as standard, - cast(hashnameextended(v, 0) as bit(32)) - as extended0, - cast(hashnameextended(v, 1) as bit(32)) - as extended1 + cast(hashnameextended(v, 0) as bit(32)) as extended0, + cast(hashnameextended(v, 1) as bit(32)) as extended1 from ( values @@ -198,18 +104,14 @@ from ) as x (v) where - cast(hashname(v) as bit(32)) <> - cast(hashnameextended(v, 0) as bit(32)) or - cast(hashname(v) as bit(32)) = - cast(hashnameextended(v, 1) as bit(32)); + cast(hashname(v) as bit(32)) <> cast(hashnameextended(v, 0) as bit(32)) or + cast(hashname(v) as bit(32)) = cast(hashnameextended(v, 1) as bit(32)); select v as value, cast(hashtext(v) as bit(32)) as standard, - cast(hashtextextended(v, 0) as bit(32)) - as extended0, - cast(hashtextextended(v, 1) as bit(32)) - as extended1 + cast(hashtextextended(v, 0) as bit(32)) as extended0, + cast(hashtextextended(v, 1) as bit(32)) as extended1 from ( values @@ -222,21 +124,14 @@ from ) as x (v) where - cast(hashtext(v) as bit(32)) <> - cast(hashtextextended(v, 0) as bit(32)) or - cast(hashtext(v) as bit(32)) = - cast(hashtextextended(v, 1) as bit(32)); + cast(hashtext(v) as bit(32)) <> cast(hashtextextended(v, 0) as bit(32)) or + cast(hashtext(v) as bit(32)) = cast(hashtextextended(v, 1) as bit(32)); select v as value, - cast(hashoidvector(v) as bit(32)) - as standard, - cast(hashoidvectorextended(v, 0) - as bit(32)) - as extended0, - cast(hashoidvectorextended(v, 1) - as bit(32)) - as extended1 + cast(hashoidvector(v) as bit(32)) as standard, + cast(hashoidvectorextended(v, 0) as bit(32)) as extended0, + cast(hashoidvectorextended(v, 1) as bit(32)) as extended1 from ( values @@ -245,56 +140,33 @@ from ('17 18 19 20'), ('42 43 42 45'), ('550273 550273 570274'), - ( - '207112489 207112499 21512 2155 372325 1363252' - ) + ('207112489 207112499 21512 2155 372325 1363252') ) as x (v) where cast(hashoidvector(v) as bit(32)) <> - cast(hashoidvectorextended(v, 0) - as bit(32)) or + cast(hashoidvectorextended(v, 0) as bit(32)) or cast(hashoidvector(v) as bit(32)) = - cast(hashoidvectorextended(v, 1) - as bit(32)); + cast(hashoidvectorextended(v, 1) as bit(32)); select v as value, - cast(hash_aclitem(v) as bit(32)) - as standard, - cast(hash_aclitem_extended(v, 0) - as bit(32)) - as extended0, - cast(hash_aclitem_extended(v, 1) - as bit(32)) - as extended1 + cast(hash_aclitem(v) as bit(32)) as standard, + cast(hash_aclitem_extended(v, 0) as bit(32)) as extended0, + cast(hash_aclitem_extended(v, 1) as bit(32)) as extended1 from - ( - select distinct - relacl[1] - from - pg_class - limit 10 - ) - as x (v) + (select distinct relacl[1] from pg_class limit 10) as x (v) where cast(hash_aclitem(v) as bit(32)) <> - cast(hash_aclitem_extended(v, 0) - as bit(32)) or + cast(hash_aclitem_extended(v, 0) as bit(32)) or cast(hash_aclitem(v) as bit(32)) = - cast(hash_aclitem_extended(v, 1) - as bit(32)); + cast(hash_aclitem_extended(v, 1) as bit(32)); select v as value, - cast(hashmacaddr(v) as bit(32)) - as standard, - cast(hashmacaddrextended(v, 0) - as bit(32)) - as extended0, - cast(hashmacaddrextended(v, 1) - as bit(32)) - as extended1 + cast(hashmacaddr(v) as bit(32)) as standard, + cast(hashmacaddrextended(v, 0) as bit(32)) as extended0, + cast(hashmacaddrextended(v, 1) as bit(32)) as extended1 from ( values @@ -308,19 +180,14 @@ from as x (v) where cast(hashmacaddr(v) as bit(32)) <> - cast(hashmacaddrextended(v, 0) - as bit(32)) or - cast(hashmacaddr(v) as bit(32)) = - cast(hashmacaddrextended(v, 1) - as bit(32)); + cast(hashmacaddrextended(v, 0) as bit(32)) or + cast(hashmacaddr(v) as bit(32)) = cast(hashmacaddrextended(v, 1) as bit(32)); select v as value, cast(hashinet(v) as bit(32)) as standard, - cast(hashinetextended(v, 0) as bit(32)) - as extended0, - cast(hashinetextended(v, 1) as bit(32)) - as extended1 + cast(hashinetextended(v, 0) as bit(32)) as extended0, + cast(hashinetextended(v, 1) as bit(32)) as extended1 from ( values @@ -333,21 +200,14 @@ from ) as x (v) where - cast(hashinet(v) as bit(32)) <> - cast(hashinetextended(v, 0) as bit(32)) or - cast(hashinet(v) as bit(32)) = - cast(hashinetextended(v, 1) as bit(32)); + cast(hashinet(v) as bit(32)) <> cast(hashinetextended(v, 0) as bit(32)) or + cast(hashinet(v) as bit(32)) = cast(hashinetextended(v, 1) as bit(32)); select v as value, - cast(hash_numeric(v) as bit(32)) - as standard, - cast(hash_numeric_extended(v, 0) - as bit(32)) - as extended0, - cast(hash_numeric_extended(v, 1) - as bit(32)) - as extended1 + cast(hash_numeric(v) as bit(32)) as standard, + cast(hash_numeric_extended(v, 0) as bit(32)) as extended0, + cast(hash_numeric_extended(v, 1) as bit(32)) as extended1 from ( values @@ -361,22 +221,15 @@ from as x (v) where cast(hash_numeric(v) as bit(32)) <> - cast(hash_numeric_extended(v, 0) - as bit(32)) or + cast(hash_numeric_extended(v, 0) as bit(32)) or cast(hash_numeric(v) as bit(32)) = - cast(hash_numeric_extended(v, 1) - as bit(32)); + cast(hash_numeric_extended(v, 1) as bit(32)); select v as value, - cast(hashmacaddr8(v) as bit(32)) - as standard, - cast(hashmacaddr8extended(v, 0) - as bit(32)) - as extended0, - cast(hashmacaddr8extended(v, 1) - as bit(32)) - as extended1 + cast(hashmacaddr8(v) as bit(32)) as standard, + cast(hashmacaddr8extended(v, 0) as bit(32)) as extended0, + cast(hashmacaddr8extended(v, 1) as bit(32)) as extended1 from ( values @@ -390,26 +243,19 @@ from as x (v) where cast(hashmacaddr8(v) as bit(32)) <> - cast(hashmacaddr8extended(v, 0) - as bit(32)) or + cast(hashmacaddr8extended(v, 0) as bit(32)) or cast(hashmacaddr8(v) as bit(32)) = - cast(hashmacaddr8extended(v, 1) - as bit(32)); + cast(hashmacaddr8extended(v, 1) as bit(32)); select v as value, - cast(hash_array(v) as bit(32)) - as standard, - cast(hash_array_extended(v, 0) - as bit(32)) - as extended0, - cast(hash_array_extended(v, 1) - as bit(32)) - as extended1 + cast(hash_array(v) as bit(32)) as standard, + cast(hash_array_extended(v, 0) as bit(32)) as extended0, + cast(hash_array_extended(v, 1) as bit(32)) as extended1 from ( values - (cast('{0}' as int[])), + (cast('{0}' as int4[])), ('{0,1,2,3,4}'), ('{17,18,19,20}'), ('{42,34,65,98}'), @@ -419,43 +265,26 @@ from as x (v) where cast(hash_array(v) as bit(32)) <> - cast(hash_array_extended(v, 0) - as bit(32)) or - cast(hash_array(v) as bit(32)) = - cast(hash_array_extended(v, 1) - as bit(32)); + cast(hash_array_extended(v, 0) as bit(32)) or + cast(hash_array(v) as bit(32)) = cast(hash_array_extended(v, 1) as bit(32)); select v as value, - cast(hash_array(v) as bit(32)) - as standard + cast(hash_array(v) as bit(32)) as standard from - ( - values (cast('{101}' as bit varying[])) - ) - as x (v); + (values (cast('{101}' as varbit[]))) as x (v); select v as value, - cast(hash_array_extended(v, 0) - as bit(32)) - as extended0 + cast(hash_array_extended(v, 0) as bit(32)) as extended0 from - ( - values (cast('{101}' as bit varying[])) - ) - as x (v); + (values (cast('{101}' as varbit[]))) as x (v); select v as value, - cast(hashbpchar(v) as bit(32)) - as standard, - cast(hashbpcharextended(v, 0) - as bit(32)) - as extended0, - cast(hashbpcharextended(v, 1) - as bit(32)) - as extended1 + cast(hashbpchar(v) as bit(32)) as standard, + cast(hashbpcharextended(v, 0) as bit(32)) as extended0, + cast(hashbpcharextended(v, 1) as bit(32)) as extended1 from ( values @@ -468,23 +297,14 @@ from ) as x (v) where - cast(hashbpchar(v) as bit(32)) <> - cast(hashbpcharextended(v, 0) - as bit(32)) or - cast(hashbpchar(v) as bit(32)) = - cast(hashbpcharextended(v, 1) - as bit(32)); + cast(hashbpchar(v) as bit(32)) <> cast(hashbpcharextended(v, 0) as bit(32)) or + cast(hashbpchar(v) as bit(32)) = cast(hashbpcharextended(v, 1) as bit(32)); select v as value, - cast(time_hash(v) as bit(32)) - as standard, - cast(time_hash_extended(v, 0) - as bit(32)) - as extended0, - cast(time_hash_extended(v, 1) - as bit(32)) - as extended1 + cast(time_hash(v) as bit(32)) as standard, + cast(time_hash_extended(v, 0) as bit(32)) as extended0, + cast(time_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -497,27 +317,18 @@ from ) as x (v) where - cast(time_hash(v) as bit(32)) <> - cast(time_hash_extended(v, 0) - as bit(32)) or - cast(time_hash(v) as bit(32)) = - cast(time_hash_extended(v, 1) - as bit(32)); + cast(time_hash(v) as bit(32)) <> cast(time_hash_extended(v, 0) as bit(32)) or + cast(time_hash(v) as bit(32)) = cast(time_hash_extended(v, 1) as bit(32)); select v as value, - cast(timetz_hash(v) as bit(32)) - as standard, - cast(timetz_hash_extended(v, 0) - as bit(32)) - as extended0, - cast(timetz_hash_extended(v, 1) - as bit(32)) - as extended1 + cast(timetz_hash(v) as bit(32)) as standard, + cast(timetz_hash_extended(v, 0) as bit(32)) as extended0, + cast(timetz_hash_extended(v, 1) as bit(32)) as extended1 from ( values - (cast(null as time with time zone)), + (cast(null as timetz)), ('00:11:52.518762-07'), ('00:11:52.51762-08'), ('00:11:52.62-01'), @@ -527,22 +338,14 @@ from as x (v) where cast(timetz_hash(v) as bit(32)) <> - cast(timetz_hash_extended(v, 0) - as bit(32)) or - cast(timetz_hash(v) as bit(32)) = - cast(timetz_hash_extended(v, 1) - as bit(32)); + cast(timetz_hash_extended(v, 0) as bit(32)) or + cast(timetz_hash(v) as bit(32)) = cast(timetz_hash_extended(v, 1) as bit(32)); select v as value, - cast(interval_hash(v) as bit(32)) - as standard, - cast(interval_hash_extended(v, 0) - as bit(32)) - as extended0, - cast(interval_hash_extended(v, 1) - as bit(32)) - as extended1 + cast(interval_hash(v) as bit(32)) as standard, + cast(interval_hash_extended(v, 0) as bit(32)) as extended0, + cast(interval_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -551,29 +354,20 @@ from ('1 year 7 day 46 minutes'), ('1 year 7 month 20 day 46 minutes'), ('5 month'), - ( - '17 year 11 month 7 day 9 hours 46 minutes 5 seconds' - ) + ('17 year 11 month 7 day 9 hours 46 minutes 5 seconds') ) as x (v) where cast(interval_hash(v) as bit(32)) <> - cast(interval_hash_extended(v, 0) - as bit(32)) or + cast(interval_hash_extended(v, 0) as bit(32)) or cast(interval_hash(v) as bit(32)) = - cast(interval_hash_extended(v, 1) - as bit(32)); + cast(interval_hash_extended(v, 1) as bit(32)); select v as value, - cast(timestamp_hash(v) as bit(32)) - as standard, - cast(timestamp_hash_extended(v, 0) - as bit(32)) - as extended0, - cast(timestamp_hash_extended(v, 1) - as bit(32)) - as extended1 + cast(timestamp_hash(v) as bit(32)) as standard, + cast(timestamp_hash_extended(v, 0) as bit(32)) as extended0, + cast(timestamp_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -587,22 +381,15 @@ from as x (v) where cast(timestamp_hash(v) as bit(32)) <> - cast(timestamp_hash_extended(v, 0) - as bit(32)) or + cast(timestamp_hash_extended(v, 0) as bit(32)) or cast(timestamp_hash(v) as bit(32)) = - cast(timestamp_hash_extended(v, 1) - as bit(32)); + cast(timestamp_hash_extended(v, 1) as bit(32)); select v as value, - cast(uuid_hash(v) as bit(32)) - as standard, - cast(uuid_hash_extended(v, 0) - as bit(32)) - as extended0, - cast(uuid_hash_extended(v, 1) - as bit(32)) - as extended1 + cast(uuid_hash(v) as bit(32)) as standard, + cast(uuid_hash_extended(v, 0) as bit(32)) as extended0, + cast(uuid_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -615,23 +402,14 @@ from ) as x (v) where - cast(uuid_hash(v) as bit(32)) <> - cast(uuid_hash_extended(v, 0) - as bit(32)) or - cast(uuid_hash(v) as bit(32)) = - cast(uuid_hash_extended(v, 1) - as bit(32)); + cast(uuid_hash(v) as bit(32)) <> cast(uuid_hash_extended(v, 0) as bit(32)) or + cast(uuid_hash(v) as bit(32)) = cast(uuid_hash_extended(v, 1) as bit(32)); select v as value, - cast(pg_lsn_hash(v) as bit(32)) - as standard, - cast(pg_lsn_hash_extended(v, 0) - as bit(32)) - as extended0, - cast(pg_lsn_hash_extended(v, 1) - as bit(32)) - as extended1 + cast(pg_lsn_hash(v) as bit(32)) as standard, + cast(pg_lsn_hash_extended(v, 0) as bit(32)) as extended0, + cast(pg_lsn_hash_extended(v, 1) as bit(32)) as extended1 from ( values @@ -645,78 +423,48 @@ from as x (v) where cast(pg_lsn_hash(v) as bit(32)) <> - cast(pg_lsn_hash_extended(v, 0) - as bit(32)) or - cast(pg_lsn_hash(v) as bit(32)) = - cast(pg_lsn_hash_extended(v, 1) - as bit(32)); + cast(pg_lsn_hash_extended(v, 0) as bit(32)) or + cast(pg_lsn_hash(v) as bit(32)) = cast(pg_lsn_hash_extended(v, 1) as bit(32)); create type mood as enum ('sad', 'ok', 'happy'); select v as value, cast(hashenum(v) as bit(32)) as standard, - cast(hashenumextended(v, 0) as bit(32)) - as extended0, - cast(hashenumextended(v, 1) as bit(32)) - as extended1 + cast(hashenumextended(v, 0) as bit(32)) as extended0, + cast(hashenumextended(v, 1) as bit(32)) as extended1 from - ( - values - (cast('sad' as mood)), - ('ok'), - ('happy') - ) - as x (v) + (values (cast('sad' as mood)), ('ok'), ('happy')) as x (v) where - cast(hashenum(v) as bit(32)) <> - cast(hashenumextended(v, 0) as bit(32)) or - cast(hashenum(v) as bit(32)) = - cast(hashenumextended(v, 1) as bit(32)); + cast(hashenum(v) as bit(32)) <> cast(hashenumextended(v, 0) as bit(32)) or + cast(hashenum(v) as bit(32)) = cast(hashenumextended(v, 1) as bit(32)); drop type mood; select v as value, - cast(jsonb_hash(v) as bit(32)) - as standard, - cast(jsonb_hash_extended(v, 0) - as bit(32)) - as extended0, - cast(jsonb_hash_extended(v, 1) - as bit(32)) - as extended1 + cast(jsonb_hash(v) as bit(32)) as standard, + cast(jsonb_hash_extended(v, 0) as bit(32)) as extended0, + cast(jsonb_hash_extended(v, 1) as bit(32)) as extended1 from ( values (cast(null as jsonb)), - ( - '{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' - ), - ( - '{"foo": [true, "bar"], "tags": {"e": 1, "f": null}}' - ), + ('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}'), + ('{"foo": [true, "bar"], "tags": {"e": 1, "f": null}}'), ('{"g": {"h": "value"}}') ) as x (v) where cast(jsonb_hash(v) as bit(32)) <> - cast(jsonb_hash_extended(v, 0) - as bit(32)) or - cast(jsonb_hash(v) as bit(32)) = - cast(jsonb_hash_extended(v, 1) - as bit(32)); + cast(jsonb_hash_extended(v, 0) as bit(32)) or + cast(jsonb_hash(v) as bit(32)) = cast(jsonb_hash_extended(v, 1) as bit(32)); select v as value, - cast(hash_range(v) as bit(32)) - as standard, - cast(hash_range_extended(v, 0) - as bit(32)) - as extended0, - cast(hash_range_extended(v, 1) - as bit(32)) - as extended1 + cast(hash_range(v) as bit(32)) as standard, + cast(hash_range_extended(v, 0) as bit(32)) as extended0, + cast(hash_range_extended(v, 1) as bit(32)) as extended1 from ( values @@ -729,139 +477,74 @@ from as x (v) where cast(hash_range(v) as bit(32)) <> - cast(hash_range_extended(v, 0) - as bit(32)) or - cast(hash_range(v) as bit(32)) = - cast(hash_range_extended(v, 1) - as bit(32)); + cast(hash_range_extended(v, 0) as bit(32)) or + cast(hash_range(v) as bit(32)) = cast(hash_range_extended(v, 1) as bit(32)); select v as value, - cast(hash_multirange(v) as bit(32)) - as standard, - cast(hash_multirange_extended(v, 0) - as bit(32)) - as extended0, - cast(hash_multirange_extended(v, 1) - as bit(32)) - as extended1 + cast(hash_multirange(v) as bit(32)) as standard, + cast(hash_multirange_extended(v, 0) as bit(32)) as extended0, + cast(hash_multirange_extended(v, 1) as bit(32)) as extended1 from ( values (cast('{[10,20)}' as int4multirange)), (cast('{[23, 43]}' as int4multirange)), - ( - cast('{[5675, 550273)}' - as int4multirange) - ), - ( - cast('{[550274, 1550274)}' - as int4multirange) - ), - ( - cast('{[1550275, 208112489)}' - as int4multirange) - ) + (cast('{[5675, 550273)}' as int4multirange)), + (cast('{[550274, 1550274)}' as int4multirange)), + (cast('{[1550275, 208112489)}' as int4multirange)) ) as x (v) where cast(hash_multirange(v) as bit(32)) <> - cast(hash_multirange_extended(v, 0) - as bit(32)) or + cast(hash_multirange_extended(v, 0) as bit(32)) or cast(hash_multirange(v) as bit(32)) = - cast(hash_multirange_extended(v, 1) - as bit(32)); + cast(hash_multirange_extended(v, 1) as bit(32)); create type hash_test_t1 as (a int, b text); select v as value, - cast(hash_record(v) as bit(32)) - as standard, - cast(hash_record_extended(v, 0) - as bit(32)) - as extended0, - cast(hash_record_extended(v, 1) - as bit(32)) - as extended1 + cast(hash_record(v) as bit(32)) as standard, + cast(hash_record_extended(v, 0) as bit(32)) as extended0, + cast(hash_record_extended(v, 1) as bit(32)) as extended1 from ( - values - ( - cast(row(1, 'aaa') as hash_test_t1), - row(2, 'bbb'), - row(-1, 'ccc') - ) + values (cast(row(1, 'aaa') as hash_test_t1), row(2, 'bbb'), row(-1, 'ccc')) ) as x (v) where cast(hash_record(v) as bit(32)) <> - cast(hash_record_extended(v, 0) - as bit(32)) or - cast(hash_record(v) as bit(32)) = - cast(hash_record_extended(v, 1) - as bit(32)); + cast(hash_record_extended(v, 0) as bit(32)) or + cast(hash_record(v) as bit(32)) = cast(hash_record_extended(v, 1) as bit(32)); drop type hash_test_t1; -create type hash_test_t2 as (a bit varying, b text); +create type hash_test_t2 as (a varbit, b text); select v as value, - cast(hash_record(v) as bit(32)) - as standard + cast(hash_record(v) as bit(32)) as standard from - ( - values - ( - cast(row(cast('10' as bit varying), 'aaa') - as hash_test_t2) - ) - ) - as x (v); + (values (cast(row(cast('10' as varbit), 'aaa') as hash_test_t2))) as x (v); select v as value, - cast(hash_record_extended(v, 0) - as bit(32)) - as extended0 + cast(hash_record_extended(v, 0) as bit(32)) as extended0 from - ( - values - ( - cast(row(cast('11' as bit varying), 'aaa') - as hash_test_t2) - ) - ) - as x (v); + (values (cast(row(cast('11' as varbit), 'aaa') as hash_test_t2))) as x (v); drop type hash_test_t2; -select hashfloat4(cast('0' as real)) = hashfloat4(cast('-0' as real)) as t; - -select hashfloat4(cast('NaN' as real)) = hashfloat4(-cast('NaN' as real)) as t; +select hashfloat4(cast('0' as float4)) = hashfloat4(cast('-0' as float4)) as t; select - hashfloat8( - cast('0' as double precision) - ) = - hashfloat8( - cast('-0' as double precision) - ) - as t; + hashfloat4(cast('NaN' as float4)) = hashfloat4(-cast('NaN' as float4)) as t; + +select hashfloat8(cast('0' as float8)) = hashfloat8(cast('-0' as float8)) as t; select - hashfloat8( - cast('NaN' as double precision) - ) = - hashfloat8( - -cast('NaN' as double precision) - ) - as t; + hashfloat8(cast('NaN' as float8)) = hashfloat8(-cast('NaN' as float8)) as t; select - hashfloat4(cast('NaN' as real)) = - hashfloat8( - cast('NaN' as double precision) - ) - as t; + hashfloat4(cast('NaN' as float4)) = hashfloat8(cast('NaN' as float8)) as t; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_index_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_index_100.snap index 2bb570c39..96f1a4ed0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_index_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_index_100.snap @@ -4,23 +4,23 @@ input_file: crates/pgls_pretty_print/tests/data/multi/hash_index.sql snapshot_kind: text --- create table hash_i4_heap ( - seqno int, - random int + seqno int4, + random int4 ); create table hash_name_heap ( - seqno int, + seqno int4, random name ); create table hash_txt_heap ( - seqno int, + seqno int4, random text ); create table hash_f8_heap ( - seqno int, - random double precision + seqno int4, + random float8 ); copy hash_i4_heap from 'filename'; @@ -39,32 +39,19 @@ analyze hash_txt_heap; analyze hash_f8_heap; -create index "hash_i4_index" on hash_i4_heap using hash (random int4_ops); +create index hash_i4_index on hash_i4_heap using hash (random int4_ops); -create index "hash_name_index" on hash_name_heap using hash (random name_ops); +create index hash_name_index on hash_name_heap using hash (random name_ops); -create index "hash_txt_index" on hash_txt_heap using hash (random text_ops); +create index hash_txt_index on hash_txt_heap using hash (random text_ops); -create index "hash_f8_index" -on hash_f8_heap -using hash -( - random float8_ops -) -with (fillfactor = 60); +create index hash_f8_index on hash_f8_heap using hash (random float8_ops) with (fillfactor = 60); -create unique index "hash_f8_index_1" on hash_f8_heap using btree ((abs(random))); +create unique index hash_f8_index_1 on hash_f8_heap using btree ((abs(random))); -create unique index "hash_f8_index_2" on hash_f8_heap using btree ((seqno + 1), random); +create unique index hash_f8_index_2 on hash_f8_heap using btree ((seqno + 1), random); -create unique index "hash_f8_index_3" -on hash_f8_heap -using btree -( - random -) -where - seqno > 1000; +create unique index hash_f8_index_3 on hash_f8_heap using btree (random) where seqno > 1000; select * from hash_i4_heap where hash_i4_heap.random = 843938989; @@ -78,9 +65,9 @@ select * from hash_txt_heap where hash_txt_heap.random = cast('1351610853' as te select * from hash_txt_heap where hash_txt_heap.random = cast('111111112222222233333333' as text); -select * from hash_f8_heap where hash_f8_heap.random = cast('444705537' as double precision); +select * from hash_f8_heap where hash_f8_heap.random = cast('444705537' as float8); -select * from hash_f8_heap where hash_f8_heap.random = cast('88888888' as double precision); +select * from hash_f8_heap where hash_f8_heap.random = cast('88888888' as float8); update hash_i4_heap set random = 1 where hash_i4_heap.seqno = 1492; @@ -118,17 +105,13 @@ select from hash_txt_heap as h where - h.random = - cast('0123456789abcdefghijklmnop' as text); + h.random = cast('0123456789abcdefghijklmnop' as text); update hash_txt_heap set seqno = 20000 where hash_txt_heap.random = cast('959363399' as text); select h.seqno as t20000 from hash_txt_heap as h where h.random = cast('959363399' as text); -update hash_f8_heap -set random = cast('-1234.1234' as double precision) -where - hash_f8_heap.seqno = 8906; +update hash_f8_heap set random = cast('-1234.1234' as float8) where hash_f8_heap.seqno = 8906; select h.seqno as i8096, @@ -136,26 +119,17 @@ select from hash_f8_heap as h where - h.random = cast('-1234.1234' as double precision); + h.random = cast('-1234.1234' as float8); -update hash_f8_heap -set seqno = 20000 -where - hash_f8_heap.random = - cast('488912369' as double precision); +update hash_f8_heap set seqno = 20000 where hash_f8_heap.random = cast('488912369' as float8); -select - h.seqno as f20000 -from - hash_f8_heap as h -where - h.random = cast('488912369' as double precision); +select h.seqno as f20000 from hash_f8_heap as h where h.random = cast('488912369' as float8); create table hash_split_heap (keycol int); insert into hash_split_heap select 1 from generate_series(1, 500) as a; -create index "hash_split_index" on hash_split_heap using hash (keycol); +create index hash_split_index on hash_split_heap using hash (keycol); insert into hash_split_heap select 1 from generate_series(1, 5000) as a; @@ -165,7 +139,7 @@ set enable_seqscan = off; set enable_bitmapscan = off; -declare "c" cursor for select * from hash_split_heap where keycol = 1;; +declare c cursor for select * from hash_split_heap where keycol = 1;; move forward all from c; @@ -192,7 +166,7 @@ drop table hash_split_heap; create table hash_cleanup_heap (keycol int); -create index "hash_cleanup_index" on hash_cleanup_heap using hash (keycol); +create index hash_cleanup_index on hash_cleanup_heap using hash (keycol); insert into hash_cleanup_heap select 1 from generate_series(1, 500) as i; @@ -247,33 +221,21 @@ create temporary table hash_temp_heap ( insert into hash_temp_heap values (1, 1); -create index "hash_idx" on hash_temp_heap using hash (x); +create index hash_idx on hash_temp_heap using hash (x); drop table hash_temp_heap cascade; create table hash_heap_float4 ( - x real, + x float4, y int ); insert into hash_heap_float4 values (1.1, 1); -create index "hash_idx" on hash_heap_float4 using hash (x); +create index hash_idx on hash_heap_float4 using hash (x); drop table hash_heap_float4 cascade; -create index "hash_f8_index2" -on hash_f8_heap -using hash -( - random float8_ops -) -with (fillfactor = 9); - -create index "hash_f8_index2" -on hash_f8_heap -using hash -( - random float8_ops -) -with (fillfactor = 101); +create index hash_f8_index2 on hash_f8_heap using hash (random float8_ops) with (fillfactor = 9); + +create index hash_f8_index2 on hash_f8_heap using hash (random float8_ops) with (fillfactor = 101); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_index_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_index_80.snap index 2277e1e04..c893fd5a9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_index_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_index_80.snap @@ -4,23 +4,23 @@ input_file: crates/pgls_pretty_print/tests/data/multi/hash_index.sql snapshot_kind: text --- create table hash_i4_heap ( - seqno int, - random int + seqno int4, + random int4 ); create table hash_name_heap ( - seqno int, + seqno int4, random name ); create table hash_txt_heap ( - seqno int, + seqno int4, random text ); create table hash_f8_heap ( - seqno int, - random double precision + seqno int4, + random float8 ); copy hash_i4_heap from 'filename'; @@ -39,43 +39,24 @@ analyze hash_txt_heap; analyze hash_f8_heap; -create index "hash_i4_index" on hash_i4_heap using hash (random int4_ops); +create index hash_i4_index on hash_i4_heap using hash (random int4_ops); -create index "hash_name_index" on hash_name_heap using hash (random name_ops); +create index hash_name_index on hash_name_heap using hash (random name_ops); -create index "hash_txt_index" on hash_txt_heap using hash (random text_ops); +create index hash_txt_index on hash_txt_heap using hash (random text_ops); -create index "hash_f8_index" -on hash_f8_heap -using hash -( - random float8_ops -) +create index hash_f8_index on hash_f8_heap using hash (random float8_ops) with (fillfactor = 60); -create unique index "hash_f8_index_1" -on hash_f8_heap -using btree -( - (abs(random)) -); +create unique index hash_f8_index_1 on hash_f8_heap using btree ((abs(random))); -create unique index "hash_f8_index_2" -on hash_f8_heap -using btree -( +create unique index hash_f8_index_2 on hash_f8_heap using btree ( (seqno + 1), random ); -create unique index "hash_f8_index_3" -on hash_f8_heap -using btree -( - random -) -where - seqno > 1000; +create unique index hash_f8_index_3 on hash_f8_heap using btree (random) +where seqno > 1000; select * from hash_i4_heap where hash_i4_heap.random = 843938989; @@ -86,48 +67,42 @@ select from hash_name_heap where - hash_name_heap.random = - cast('1505703298' as name); + hash_name_heap.random = cast('1505703298' as name); select * from hash_name_heap where - hash_name_heap.random = - cast('7777777' as name); + hash_name_heap.random = cast('7777777' as name); select * from hash_txt_heap where - hash_txt_heap.random = - cast('1351610853' as text); + hash_txt_heap.random = cast('1351610853' as text); select * from hash_txt_heap where - hash_txt_heap.random = - cast('111111112222222233333333' as text); + hash_txt_heap.random = cast('111111112222222233333333' as text); select * from hash_f8_heap where - hash_f8_heap.random = - cast('444705537' as double precision); + hash_f8_heap.random = cast('444705537' as float8); select * from hash_f8_heap where - hash_f8_heap.random = - cast('88888888' as double precision); + hash_f8_heap.random = cast('88888888' as float8); update hash_i4_heap set random = 1 where hash_i4_heap.seqno = 1492; @@ -154,14 +129,12 @@ select from hash_name_heap as h where - h.random = - cast('0123456789abcdef' as name); + h.random = cast('0123456789abcdef' as name); update hash_name_heap set seqno = 20000 where - hash_name_heap.random = - cast('76652222' as name); + hash_name_heap.random = cast('76652222' as name); select h.seqno as emptyset @@ -171,8 +144,7 @@ where h.random = cast('76652222' as name); update hash_txt_heap -set random = cast('0123456789abcdefghijklmnop' -as text) +set random = cast('0123456789abcdefghijklmnop' as text) where hash_txt_heap.seqno = 4002; @@ -182,15 +154,12 @@ select from hash_txt_heap as h where - h.random = - cast('0123456789abcdefghijklmnop' - as text); + h.random = cast('0123456789abcdefghijklmnop' as text); update hash_txt_heap set seqno = 20000 where - hash_txt_heap.random = - cast('959363399' as text); + hash_txt_heap.random = cast('959363399' as text); select h.seqno as t20000 @@ -200,7 +169,7 @@ where h.random = cast('959363399' as text); update hash_f8_heap -set random = cast('-1234.1234' as double precision) +set random = cast('-1234.1234' as float8) where hash_f8_heap.seqno = 8906; @@ -210,28 +179,25 @@ select from hash_f8_heap as h where - h.random = - cast('-1234.1234' as double precision); + h.random = cast('-1234.1234' as float8); update hash_f8_heap set seqno = 20000 where - hash_f8_heap.random = - cast('488912369' as double precision); + hash_f8_heap.random = cast('488912369' as float8); select h.seqno as f20000 from hash_f8_heap as h where - h.random = - cast('488912369' as double precision); + h.random = cast('488912369' as float8); create table hash_split_heap (keycol int); insert into hash_split_heap select 1 from generate_series(1, 500) as a; -create index "hash_split_index" on hash_split_heap using hash (keycol); +create index hash_split_index on hash_split_heap using hash (keycol); insert into hash_split_heap select 1 from generate_series(1, 5000) as a; @@ -241,7 +207,7 @@ set enable_seqscan = off; set enable_bitmapscan = off; -declare "c" cursor for select * from hash_split_heap where keycol = 1;; +declare c cursor for select * from hash_split_heap where keycol = 1;; move forward all from c; @@ -268,7 +234,7 @@ drop table hash_split_heap; create table hash_cleanup_heap (keycol int); -create index "hash_cleanup_index" on hash_cleanup_heap using hash (keycol); +create index hash_cleanup_index on hash_cleanup_heap using hash (keycol); insert into hash_cleanup_heap select 1 from generate_series(1, 500) as i; @@ -323,33 +289,23 @@ create temporary table hash_temp_heap ( insert into hash_temp_heap values (1, 1); -create index "hash_idx" on hash_temp_heap using hash (x); +create index hash_idx on hash_temp_heap using hash (x); drop table hash_temp_heap cascade; create table hash_heap_float4 ( - x real, + x float4, y int ); insert into hash_heap_float4 values (1.1, 1); -create index "hash_idx" on hash_heap_float4 using hash (x); +create index hash_idx on hash_heap_float4 using hash (x); drop table hash_heap_float4 cascade; -create index "hash_f8_index2" -on hash_f8_heap -using hash -( - random float8_ops -) +create index hash_f8_index2 on hash_f8_heap using hash (random float8_ops) with (fillfactor = 9); -create index "hash_f8_index2" -on hash_f8_heap -using hash -( - random float8_ops -) +create index hash_f8_index2 on hash_f8_heap using hash (random float8_ops) with (fillfactor = 101); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_part_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_part_100.snap index c7e3e54dc..3ca49727f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_part_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_part_100.snap @@ -8,10 +8,9 @@ create table mchash ( b text, c jsonb ) -partition by HASH(a part_test_int4_ops, -b part_test_text_ops); +partition by hash(a part_test_int4_ops, b part_test_text_ops); -create table mchash1 partition of mchash for values with (MODULUS 4, REMAINDER 0); +create table mchash1 partition of mchash for values with (modulus 4, remainder 0); select satisfies_hash_partition(0, 4, 0, null); @@ -42,68 +41,41 @@ select select satisfies_hash_partition(cast('mchash' as regclass), 3, 1, cast(null as int)); select - satisfies_hash_partition( - cast('mchash' as regclass), - 2, - 1, - cast(null as int), - cast(null as int) - ); + satisfies_hash_partition(cast('mchash' as regclass), 2, 1, cast(null as int), cast(null as int)); select satisfies_hash_partition(cast('mchash' as regclass), 4, 0, 0, cast('' as text)); select satisfies_hash_partition(cast('mchash' as regclass), 4, 0, 2, cast('' as text)); select - satisfies_hash_partition( - cast('mchash' as regclass), - 2, - 1, - variadic cast(array[1, 2] as int[]) - ); + satisfies_hash_partition(cast('mchash' as regclass), 2, 1, variadic cast(array[1, 2] as int[])); create table mcinthash ( a int, b int, c jsonb ) -partition by HASH(a part_test_int4_ops, -b part_test_int4_ops); +partition by hash(a part_test_int4_ops, b part_test_int4_ops); select satisfies_hash_partition(cast('mcinthash' as regclass), 4, 0, variadic array[0, 0]); select satisfies_hash_partition(cast('mcinthash' as regclass), 4, 0, variadic array[0, 1]); select - satisfies_hash_partition( - cast('mcinthash' as regclass), - 4, - 0, - variadic cast(array[] as int[]) - ); + satisfies_hash_partition(cast('mcinthash' as regclass), 4, 0, variadic cast(array[] as int[])); -select satisfies_hash_partition(cast('mcinthash' as regclass), 4, 0, variadic array[NOW(), NOW()]); +select satisfies_hash_partition(cast('mcinthash' as regclass), 4, 0, variadic array[now(), now()]); create table text_hashp (a text) -partition by HASH(a); +partition by hash(a); -create table text_hashp0 partition of text_hashp for values with (MODULUS 2, REMAINDER 0); +create table text_hashp0 partition of text_hashp for values with (modulus 2, remainder 0); -create table text_hashp1 partition of text_hashp for values with (MODULUS 2, REMAINDER 1); +create table text_hashp1 partition of text_hashp for values with (modulus 2, remainder 1); select - satisfies_hash_partition( - cast('text_hashp' as regclass), - 2, - 0, - cast('xxx' as text) - ) or - satisfies_hash_partition( - cast('text_hashp' as regclass), - 2, - 1, - cast('xxx' as text) - ) + satisfies_hash_partition(cast('text_hashp' as regclass), 2, 0, cast('xxx' as text)) or + satisfies_hash_partition(cast('text_hashp' as regclass), 2, 1, cast('xxx' as text)) as satisfies; drop table mchash; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_part_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_part_80.snap index 6f581a060..62b78e908 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_part_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__hash_part_80.snap @@ -8,12 +8,11 @@ create table mchash ( b text, c jsonb ) -partition by HASH(a part_test_int4_ops, -b part_test_text_ops); +partition by hash(a part_test_int4_ops, b part_test_text_ops); create table mchash1 partition of mchash -for values with (MODULUS 4, REMAINDER 0); +for values with (modulus 4, remainder 0); select satisfies_hash_partition(0, 4, 0, null); @@ -42,12 +41,7 @@ select ); select - satisfies_hash_partition( - cast('mchash' as regclass), - 3, - 1, - cast(null as int) - ); + satisfies_hash_partition(cast('mchash' as regclass), 3, 1, cast(null as int)); select satisfies_hash_partition( @@ -89,8 +83,7 @@ create table mcinthash ( b int, c jsonb ) -partition by HASH(a part_test_int4_ops, -b part_test_int4_ops); +partition by hash(a part_test_int4_ops, b part_test_int4_ops); select satisfies_hash_partition( @@ -121,19 +114,19 @@ select cast('mcinthash' as regclass), 4, 0, - variadic array[NOW(), NOW()] + variadic array[now(), now()] ); create table text_hashp (a text) -partition by HASH(a); +partition by hash(a); create table text_hashp0 partition of text_hashp -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table text_hashp1 partition of text_hashp -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); select satisfies_hash_partition( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_100.snap index db06ef1a2..76ce77037 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_100.snap @@ -3,9 +3,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/horology.sql snapshot_kind: text --- -show "timezone"; +show timezone; -show "datestyle"; +show datestyle; select cast('20011227 040506+08' as timestamp with time zone); @@ -67,13 +67,13 @@ select cast('12.27.2001 04:05:06.789+08' as timestamp with time zone); select cast('12.27.2001 04:05:06.789-08' as timestamp with time zone); -set datestyle = German; +set datestyle = 'German'; select cast('27.12.2001 04:05:06.789+08' as timestamp with time zone); select cast('27.12.2001 04:05:06.789-08' as timestamp with time zone); -set datestyle = ISO; +set datestyle = 'ISO'; select cast('040506.789+08' as time); @@ -197,33 +197,29 @@ select cast('now epoch' as timestamp); select cast('-infinity infinity' as timestamp); -select cast('1995-08-06 epoch' as timestamp with time zone); +select cast('1995-08-06 epoch' as timestamptz); -select cast('1995-08-06 infinity' as timestamp with time zone); +select cast('1995-08-06 infinity' as timestamptz); -select cast('1995-08-06 -infinity' as timestamp with time zone); +select cast('1995-08-06 -infinity' as timestamptz); -select cast('epoch 01:01:01' as timestamp with time zone); +select cast('epoch 01:01:01' as timestamptz); -select cast('infinity 01:01:01' as timestamp with time zone); +select cast('infinity 01:01:01' as timestamptz); -select cast('-infinity 01:01:01' as timestamp with time zone); +select cast('-infinity 01:01:01' as timestamptz); -select cast('now epoch' as timestamp with time zone); +select cast('now epoch' as timestamptz); -select cast('-infinity infinity' as timestamp with time zone); +select cast('-infinity infinity' as timestamptz); select cast('1981-02-03' as date) + cast('04:05:06' as time) as "Date + Time"; select - cast('1991-02-03' as date) + - cast('04:05:06 PST' as time with time zone) - as "Date + Time PST"; + cast('1991-02-03' as date) + cast('04:05:06 PST' as time with time zone) as "Date + Time PST"; select - cast('2001-02-03' as date) + - cast('04:05:06 UTC' as time with time zone) - as "Date + Time UTC"; + cast('2001-02-03' as date) + cast('04:05:06 UTC' as time with time zone) as "Date + Time UTC"; select cast('1991-02-03' as date) + cast('2 years' as interval) as "Add Two Years"; @@ -232,9 +228,7 @@ select cast('2001-12-13' as date) - cast('2 years' as interval) as "Subtract Two select cast('1991-02-03' as date) - cast('04:05:06' as time) as "Subtract Time"; select - cast('1991-02-03' as date) - - cast('04:05:06 UTC' as time with time zone) - as "Subtract Time UTC"; + cast('1991-02-03' as date) - cast('04:05:06 UTC' as time with time zone) as "Subtract Time UTC"; select cast('1996-03-01' as timestamp) - cast('1 second' as interval) as "Feb 29"; @@ -253,65 +247,49 @@ select cast('Jan 1, 4713 BC' as timestamp) + cast('109203489 days' as interval) select cast('2000-01-01' as timestamp) - cast('2483590 days' as interval) as "out of range"; select - cast('294276-12-31 23:59:59' as timestamp) + - cast('9223372036854775807 microseconds' - as interval) + cast('294276-12-31 23:59:59' as timestamp) + cast('9223372036854775807 microseconds' as interval) as "out of range"; select cast('12/31/294276' as timestamp) - cast('12/23/1999' as timestamp) as "106751991 Days"; select - cast('today' as timestamp) = - cast('yesterday' as timestamp) + - cast('1 day' as interval) - as "True"; + cast('today' as timestamp) = cast('yesterday' as timestamp) + cast('1 day' as interval) as "True"; select - cast('today' as timestamp) = - cast('tomorrow' as timestamp) - - cast('1 day' as interval) - as "True"; + cast('today' as timestamp) = cast('tomorrow' as timestamp) - cast('1 day' as interval) as "True"; select cast('today 10:30' as timestamp) = - cast('yesterday' as timestamp) + - cast('1 day 10 hr 30 min' as interval) + cast('yesterday' as timestamp) + cast('1 day 10 hr 30 min' as interval) as "True"; select cast('10:30 today' as timestamp) = - cast('yesterday' as timestamp) + - cast('1 day 10 hr 30 min' as interval) + cast('yesterday' as timestamp) + cast('1 day 10 hr 30 min' as interval) as "True"; select - cast('tomorrow' as timestamp) = - cast('yesterday' as timestamp) + - cast('2 days' as interval) + cast('tomorrow' as timestamp) = cast('yesterday' as timestamp) + cast('2 days' as interval) as "True"; select cast('tomorrow 16:00:00' as timestamp) = - cast('today' as timestamp) + - cast('1 day 16 hours' as interval) + cast('today' as timestamp) + cast('1 day 16 hours' as interval) as "True"; select cast('16:00:00 tomorrow' as timestamp) = - cast('today' as timestamp) + - cast('1 day 16 hours' as interval) + cast('today' as timestamp) + cast('1 day 16 hours' as interval) as "True"; select cast('yesterday 12:34:56' as timestamp) = - cast('tomorrow' as timestamp) - - cast('2 days - 12:34:56' as interval) + cast('tomorrow' as timestamp) - cast('2 days - 12:34:56' as interval) as "True"; select cast('12:34:56 yesterday' as timestamp) = - cast('tomorrow' as timestamp) - - cast('2 days - 12:34:56' as interval) + cast('tomorrow' as timestamp) - cast('2 days - 12:34:56' as interval) as "True"; select cast('tomorrow' as timestamp) > 'now' as "True"; @@ -320,13 +298,10 @@ select cast('1994-01-01' as date) + cast('11:00' as time) as "Jan_01_1994_11am"; select cast('1994-01-01' as date) + cast('10:00' as time) as "Jan_01_1994_10am"; -select cast('1994-01-01' as date) + cast('11:00-5' as time with time zone) as "Jan_01_1994_8am"; +select cast('1994-01-01' as date) + cast('11:00-5' as timetz) as "Jan_01_1994_8am"; select - timestamptz( - cast('1994-01-01' as date), - cast('11:00-5' as time with time zone) - ) + timestamptz(cast('1994-01-01' as date), cast('11:00-5' as time with time zone)) as "Jan_01_1994_8am"; select d1 + cast('1 year' as interval) as one_year from timestamp_tbl; @@ -340,38 +315,31 @@ select cast('1999-03-01' as timestamp with time zone) - cast('1 second' as inter select cast('2000-03-01' as timestamp with time zone) - cast('1 second' as interval) as "Feb 29"; select - cast('1999-12-01' as timestamp with time zone) + - cast('1 month - 1 second' as interval) + cast('1999-12-01' as timestamp with time zone) + cast('1 month - 1 second' as interval) as "Dec 31"; select - cast('2000-01-01' as timestamp with time zone) - - cast('2483590 days' as interval) + cast('2000-01-01' as timestamp with time zone) - cast('2483590 days' as interval) as "out of range"; select - cast('294276-12-31 23:59:59 UTC' - as timestamp with time zone) + - cast('9223372036854775807 microseconds' - as interval) + cast('294276-12-31 23:59:59 UTC' as timestamp with time zone) + + cast('9223372036854775807 microseconds' as interval) as "out of range"; select cast('today' as timestamp with time zone) = - cast('yesterday' as timestamp with time zone) + - cast('1 day' as interval) + cast('yesterday' as timestamp with time zone) + cast('1 day' as interval) as "True"; select cast('today' as timestamp with time zone) = - cast('tomorrow' as timestamp with time zone) - - cast('1 day' as interval) + cast('tomorrow' as timestamp with time zone) - cast('1 day' as interval) as "True"; select cast('tomorrow' as timestamp with time zone) = - cast('yesterday' as timestamp with time zone) + - cast('2 days' as interval) + cast('yesterday' as timestamp with time zone) + cast('2 days' as interval) as "True"; select cast('tomorrow' as timestamp with time zone) > 'now' as "True"; @@ -379,27 +347,19 @@ select cast('tomorrow' as timestamp with time zone) > 'now' as "True"; set time zone 'CST7CDT,M4.1.0,M10.5.0'; select - cast('2005-04-02 12:00-07' - as timestamp with time zone) + - cast('1 day' as interval) + cast('2005-04-02 12:00-07' as timestamp with time zone) + cast('1 day' as interval) as "Apr 3, 12:00"; select - cast('2005-04-02 12:00-07' - as timestamp with time zone) + - cast('24 hours' as interval) + cast('2005-04-02 12:00-07' as timestamp with time zone) + cast('24 hours' as interval) as "Apr 3, 13:00"; select - cast('2005-04-03 12:00-06' - as timestamp with time zone) - - cast('1 day' as interval) + cast('2005-04-03 12:00-06' as timestamp with time zone) - cast('1 day' as interval) as "Apr 2, 12:00"; select - cast('2005-04-03 12:00-06' - as timestamp with time zone) - - cast('24 hours' as interval) + cast('2005-04-03 12:00-06' as timestamp with time zone) - cast('24 hours' as interval) as "Apr 2, 11:00"; reset timezone; @@ -409,24 +369,15 @@ select timestamptz(cast('1994-01-01' as date), cast('11:00' as time)) as "Jan_01 select timestamptz(cast('1994-01-01' as date), cast('10:00' as time)) as "Jan_01_1994_9am"; select - timestamptz( - cast('1994-01-01' as date), - cast('11:00-8' as time with time zone) - ) + timestamptz(cast('1994-01-01' as date), cast('11:00-8' as time with time zone)) as "Jan_01_1994_11am"; select - timestamptz( - cast('1994-01-01' as date), - cast('10:00-8' as time with time zone) - ) + timestamptz(cast('1994-01-01' as date), cast('10:00-8' as time with time zone)) as "Jan_01_1994_10am"; select - timestamptz( - cast('1994-01-01' as date), - cast('11:00-5' as time with time zone) - ) + timestamptz(cast('1994-01-01' as date), cast('11:00-5' as time with time zone)) as "Jan_01_1994_8am"; select d1 + cast('1 year' as interval) as one_year from timestamptz_tbl; @@ -458,16 +409,13 @@ select cast('01:30-08' as time with time zone) - cast('02:01' as interval) as "2 select cast('02:30-08' as time with time zone) + cast('36:01' as interval) as "14:31:00-08"; select - cast(cast(cast('today' as date) + - cast('05:30' as time with time zone) + - cast('02:01' as interval) + cast(cast(cast('today' as date) + cast('05:30' as time with time zone) + cast('02:01' as interval) as time with time zone) as time) as "07:31:00"; select - cast(cast(cast('today' as date) + - cast('03:30' as time with time zone) + + cast(cast(cast('today' as date) + cast('03:30' as time with time zone) + cast('1 month 04:01' as interval) as timestamp) as time) @@ -482,8 +430,7 @@ from timestamp_tbl as t, interval_tbl as i where - t.d1 between '1990-01-01' and '2001-01-01' and - i.f1 between '00:00' and '23:00' + t.d1 between '1990-01-01' and '2001-01-01' and i.f1 between '00:00' and '23:00' order by 1, 2; @@ -514,152 +461,89 @@ order by 1, 2; select - overlaps( - cast('2000-11-27' as timestamp with time zone), - cast('2000-11-28' as timestamp with time zone), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('2000-11-30' as timestamp with time zone) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('2000-11-28' + as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' + as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) as "True"; select - overlaps( - cast('2000-11-26' as timestamp with time zone), - cast('2000-11-27' as timestamp with time zone), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('2000-11-30' as timestamp with time zone) - ) + ((cast('2000-11-26' as timestamp with time zone), cast('2000-11-27' + as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' + as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) as "False"; select - overlaps( - cast('2000-11-27' as timestamp with time zone), - cast('2000-11-28' as timestamp with time zone), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('1 day' as interval) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('2000-11-28' + as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' + as timestamp with time zone), cast('1 day' as interval))) as "True"; select - overlaps( - cast('2000-11-27' as timestamp with time zone), - cast('12 hours' as interval), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('2000-11-30' as timestamp with time zone) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' + as interval)) overlaps (cast('2000-11-27 12:00' as timestamp with time zone), cast('2000-11-30' + as timestamp with time zone))) as "False"; select - overlaps( - cast('2000-11-27' as timestamp with time zone), - cast('12 hours' as interval), - cast('2000-11-27' as timestamp with time zone), - cast('12 hours' as interval) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' + as interval)) overlaps (cast('2000-11-27' as timestamp with time zone), cast('12 hours' + as interval))) as "True"; select - overlaps( - cast('2000-11-27' as timestamp with time zone), - cast('12 hours' as interval), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('12 hours' as interval) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' + as interval)) overlaps (cast('2000-11-27 12:00' as timestamp with time zone), cast('12 hours' + as interval))) as "False"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('2000-11-28' as timestamp), - cast('2000-11-27 12:00' as timestamp), - cast('2000-11-30' as timestamp) - ) + ((cast('2000-11-27' as timestamp), cast('2000-11-28' + as timestamp)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('2000-11-30' as timestamp))) as "True"; select - overlaps( - cast('2000-11-26' as timestamp), - cast('2000-11-27' as timestamp), - cast('2000-11-27 12:00' as timestamp), - cast('2000-11-30' as timestamp) - ) + ((cast('2000-11-26' as timestamp), cast('2000-11-27' + as timestamp)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('2000-11-30' as timestamp))) as "False"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('2000-11-28' as timestamp), - cast('2000-11-27 12:00' as timestamp), - cast('1 day' as interval) - ) + ((cast('2000-11-27' as timestamp), cast('2000-11-28' + as timestamp)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('1 day' as interval))) as "True"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('12 hours' as interval), - cast('2000-11-27 12:00' as timestamp), - cast('2000-11-30' as timestamp) - ) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps (cast('2000-11-27 12:00' + as timestamp), cast('2000-11-30' as timestamp))) as "False"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('12 hours' as interval), - cast('2000-11-27' as timestamp), - cast('12 hours' as interval) - ) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps (cast('2000-11-27' + as timestamp), cast('12 hours' as interval))) as "True"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('12 hours' as interval), - cast('2000-11-27 12:00' as timestamp), - cast('12 hours' as interval) - ) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps (cast('2000-11-27 12:00' + as timestamp), cast('12 hours' as interval))) as "False"; select - overlaps( - cast('00:00' as time), - cast('01:00' as time), - cast('00:30' as time), - cast('01:30' as time) - ) + ((cast('00:00' as time), cast('01:00' as time)) overlaps (cast('00:30' as time), cast('01:30' + as time))) as "True"; select - overlaps( - cast('00:00' as time), - cast('1 hour' as interval), - cast('00:30' as time), - cast('1 hour' as interval) - ) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('00:30' + as time), cast('1 hour' as interval))) as "True"; select - overlaps( - cast('00:00' as time), - cast('1 hour' as interval), - cast('01:30' as time), - cast('1 hour' as interval) - ) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('01:30' + as time), cast('1 hour' as interval))) as "False"; select - overlaps( - cast('00:00' as time), - cast('1 hour' as interval), - cast('01:30' as time), - cast('1 day' as interval) - ) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('01:30' as time), cast('1 day' + as interval))) as "False"; create table temp_timestamp (f1 timestamp with time zone); @@ -670,8 +554,7 @@ select from timestamp_tbl where - d1 between '13-jun-1957' and '1-jan-1997' or - d1 between '1-jan-1999' and '1-jan-2010'; + d1 between '13-jun-1957' and '1-jan-1997' or d1 between '1-jan-1999' and '1-jan-2010'; select f1 as timestamp from temp_timestamp order by timestamp; @@ -699,13 +582,8 @@ order by minus, select d.f1 as timestamp, - cast('1980-01-06 00:00 GMT' - as timestamp with time zone) - as gpstime_zero, - d.f1 - - cast('1980-01-06 00:00 GMT' - as timestamp with time zone) - as difference + cast('1980-01-06 00:00 GMT' as timestamp with time zone) as gpstime_zero, + d.f1 - cast('1980-01-06 00:00 GMT' as timestamp with time zone) as difference from temp_timestamp as d order by difference; @@ -739,47 +617,47 @@ select cast('2202020-10-05' as date) > cast('2020-10-05' as timestamp) as t; select cast('2020-10-05' as timestamp) > cast('2202020-10-05' as date) as f; -select cast(cast('2202020-10-05' as date) as timestamp with time zone); +select cast(cast('2202020-10-05' as date) as timestamptz); -select cast('2202020-10-05' as date) > cast('2020-10-05' as timestamp with time zone) as t; +select cast('2202020-10-05' as date) > cast('2020-10-05' as timestamptz) as t; -select cast('2020-10-05' as timestamp with time zone) > cast('2202020-10-05' as date) as f; +select cast('2020-10-05' as timestamptz) > cast('2202020-10-05' as date) as f; -select cast(cast('4714-11-24 BC' as date) as timestamp with time zone); +select cast(cast('4714-11-24 BC' as date) as timestamptz); set time zone 'UTC-2'; -select cast(cast('4714-11-24 BC' as date) as timestamp with time zone); +select cast(cast('4714-11-24 BC' as date) as timestamptz); -select cast('4714-11-24 BC' as date) < cast('2020-10-05' as timestamp with time zone) as t; +select cast('4714-11-24 BC' as date) < cast('2020-10-05' as timestamptz) as t; -select cast('2020-10-05' as timestamp with time zone) >= cast('4714-11-24 BC' as date) as t; +select cast('2020-10-05' as timestamptz) >= cast('4714-11-24 BC' as date) as t; -select cast('4714-11-24 BC' as timestamp) < cast('2020-10-05' as timestamp with time zone) as t; +select cast('4714-11-24 BC' as timestamp) < cast('2020-10-05' as timestamptz) as t; -select cast('2020-10-05' as timestamp with time zone) >= cast('4714-11-24 BC' as timestamp) as t; +select cast('2020-10-05' as timestamptz) >= cast('4714-11-24 BC' as timestamp) as t; reset timezone; -select COUNT(*) from date_tbl where f1 between '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 between '1997-01-01' and '1998-01-01'; -select COUNT(*) from date_tbl where f1 between '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 between '1997-01-01' and '1998-01-01'; -select COUNT(*) from date_tbl where f1 not between '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 not between '1997-01-01' and '1998-01-01'; -select COUNT(*) from date_tbl where f1 not between '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 not between '1997-01-01' and '1998-01-01'; -select COUNT(*) from date_tbl where f1 between symmetric '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 between symmetric '1997-01-01' and '1998-01-01'; -select COUNT(*) from date_tbl where f1 between symmetric '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 between symmetric '1997-01-01' and '1998-01-01'; -select COUNT(*) from date_tbl where f1 not between symmetric '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 not between symmetric '1997-01-01' and '1998-01-01'; -select COUNT(*) from date_tbl where f1 not between symmetric '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 not between symmetric '1997-01-01' and '1998-01-01'; set datestyle = 'US,Postgres'; -show "datestyle"; +show datestyle; select d1 as us_postgres from timestamp_tbl; @@ -789,29 +667,29 @@ select d1 as us_iso from timestamp_tbl; set datestyle = 'US,SQL'; -show "datestyle"; +show datestyle; select d1 as us_sql from timestamp_tbl; set datestyle = 'European,Postgres'; -show "datestyle"; +show datestyle; insert into timestamp_tbl values ('13/06/1957'); -select COUNT(*) as one from timestamp_tbl where d1 = 'Jun 13 1957'; +select count(*) as one from timestamp_tbl where d1 = 'Jun 13 1957'; select d1 as european_postgres from timestamp_tbl; set datestyle = 'European,ISO'; -show "datestyle"; +show datestyle; select d1 as european_iso from timestamp_tbl; set datestyle = 'European,SQL'; -show "datestyle"; +show datestyle; select d1 as european_sql from timestamp_tbl; @@ -943,82 +821,55 @@ select to_timestamp('2018-11-02 12:34:56.025', 'YYYY-MM-DD HH24:MI:SS.MS'); select i, - to_timestamp( - '2018-11-02 12:34:56', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.1', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.1', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.12', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.12', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.123', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.123', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.1234', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.1234', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.12345', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.12345', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.123456', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.123456', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.123456789', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.123456789', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '20181102123456123456', - 'YYYYMMDDHH24MISSFF' || i - ) + to_timestamp('20181102123456123456', 'YYYYMMDDHH24MISSFF' || i) from generate_series(1, 6) as i; @@ -1170,28 +1021,28 @@ select to_date('-2147483648 01', 'CC YY'); select to_date('2147483647 01', 'CC YY'); -select to_char(cast('2012-12-12 12:00' as timestamp with time zone), 'YYYY-MM-DD HH:MI:SS TZ'); +select to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD HH:MI:SS TZ'); -select to_char(cast('2012-12-12 12:00' as timestamp with time zone), 'YYYY-MM-DD HH:MI:SS tz'); +select to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD HH:MI:SS tz'); set time zone 'America/New_York'; set time zone '-1.5'; -show "timezone"; +show timezone; -select cast('2012-12-12 12:00' as timestamp with time zone); +select cast('2012-12-12 12:00' as timestamptz); -select cast('2012-12-12 12:00 America/New_York' as timestamp with time zone); +select cast('2012-12-12 12:00 America/New_York' as timestamptz); -select to_char(cast('2012-12-12 12:00' as timestamp with time zone), 'YYYY-MM-DD HH:MI:SS TZ'); +select to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD HH:MI:SS TZ'); -select to_char(cast('2012-12-12 12:00' as timestamp with time zone), 'YYYY-MM-DD SSSS'); +select to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD SSSS'); -select to_char(cast('2012-12-12 12:00' as timestamp with time zone), 'YYYY-MM-DD SSSSS'); +select to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD SSSSS'); set time zone '+2'; -select to_char(cast('2012-12-12 12:00' as timestamp with time zone), 'YYYY-MM-DD HH:MI:SS TZ'); +select to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD HH:MI:SS TZ'); reset timezone; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_80.snap index 97b7c15ba..3a6bd3676 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_80.snap @@ -3,9 +3,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/horology.sql snapshot_kind: text --- -show "timezone"; +show timezone; -show "datestyle"; +show datestyle; select cast('20011227 040506+08' as timestamp with time zone); @@ -67,13 +67,13 @@ select cast('12.27.2001 04:05:06.789+08' as timestamp with time zone); select cast('12.27.2001 04:05:06.789-08' as timestamp with time zone); -set datestyle = German; +set datestyle = 'German'; select cast('27.12.2001 04:05:06.789+08' as timestamp with time zone); select cast('27.12.2001 04:05:06.789-08' as timestamp with time zone); -set datestyle = ISO; +set datestyle = 'ISO'; select cast('040506.789+08' as time); @@ -98,8 +98,7 @@ select cast('T040506.789 -08' as time with time zone); select cast('T040506.789 America/Los_Angeles' as time with time zone); select - cast('2001-12-27 T040506.789 America/Los_Angeles' - as time with time zone); + cast('2001-12-27 T040506.789 America/Los_Angeles' as time with time zone); select cast('J2452271 T040506.789 America/Los_Angeles' as time with time zone); @@ -199,158 +198,126 @@ select cast('now epoch' as timestamp); select cast('-infinity infinity' as timestamp); -select cast('1995-08-06 epoch' as timestamp with time zone); +select cast('1995-08-06 epoch' as timestamptz); -select cast('1995-08-06 infinity' as timestamp with time zone); +select cast('1995-08-06 infinity' as timestamptz); -select cast('1995-08-06 -infinity' as timestamp with time zone); +select cast('1995-08-06 -infinity' as timestamptz); -select cast('epoch 01:01:01' as timestamp with time zone); +select cast('epoch 01:01:01' as timestamptz); -select cast('infinity 01:01:01' as timestamp with time zone); +select cast('infinity 01:01:01' as timestamptz); -select cast('-infinity 01:01:01' as timestamp with time zone); +select cast('-infinity 01:01:01' as timestamptz); -select cast('now epoch' as timestamp with time zone); +select cast('now epoch' as timestamptz); -select cast('-infinity infinity' as timestamp with time zone); +select cast('-infinity infinity' as timestamptz); select cast('1981-02-03' as date) + cast('04:05:06' as time) as "Date + Time"; select - cast('1991-02-03' as date) + - cast('04:05:06 PST' - as time with time zone) + cast('1991-02-03' as date) + cast('04:05:06 PST' as time with time zone) as "Date + Time PST"; select - cast('2001-02-03' as date) + - cast('04:05:06 UTC' - as time with time zone) + cast('2001-02-03' as date) + cast('04:05:06 UTC' as time with time zone) as "Date + Time UTC"; select - cast('1991-02-03' as date) + - cast('2 years' as interval) - as "Add Two Years"; + cast('1991-02-03' as date) + cast('2 years' as interval) as "Add Two Years"; select - cast('2001-12-13' as date) - - cast('2 years' as interval) + cast('2001-12-13' as date) - cast('2 years' as interval) as "Subtract Two Years"; select cast('1991-02-03' as date) - cast('04:05:06' as time) as "Subtract Time"; select - cast('1991-02-03' as date) - - cast('04:05:06 UTC' - as time with time zone) + cast('1991-02-03' as date) - cast('04:05:06 UTC' as time with time zone) as "Subtract Time UTC"; select - cast('1996-03-01' as timestamp) - - cast('1 second' as interval) - as "Feb 29"; + cast('1996-03-01' as timestamp) - cast('1 second' as interval) as "Feb 29"; select - cast('1999-03-01' as timestamp) - - cast('1 second' as interval) - as "Feb 28"; + cast('1999-03-01' as timestamp) - cast('1 second' as interval) as "Feb 28"; select - cast('2000-03-01' as timestamp) - - cast('1 second' as interval) - as "Feb 29"; + cast('2000-03-01' as timestamp) - cast('1 second' as interval) as "Feb 29"; select - cast('1999-12-01' as timestamp) + - cast('1 month - 1 second' as interval) + cast('1999-12-01' as timestamp) + cast('1 month - 1 second' as interval) as "Dec 31"; select - cast('Jan 1, 4713 BC' as timestamp) + - cast('106000000 days' as interval) + cast('Jan 1, 4713 BC' as timestamp) + cast('106000000 days' as interval) as "Feb 23, 285506"; select - cast('Jan 1, 4713 BC' as timestamp) + - cast('107000000 days' as interval) + cast('Jan 1, 4713 BC' as timestamp) + cast('107000000 days' as interval) as "Jan 20, 288244"; select - cast('Jan 1, 4713 BC' as timestamp) + - cast('109203489 days' as interval) + cast('Jan 1, 4713 BC' as timestamp) + cast('109203489 days' as interval) as "Dec 31, 294276"; select - cast('2000-01-01' as timestamp) - - cast('2483590 days' as interval) + cast('2000-01-01' as timestamp) - cast('2483590 days' as interval) as "out of range"; select - cast('294276-12-31 23:59:59' - as timestamp) + - cast('9223372036854775807 microseconds' - as interval) + cast('294276-12-31 23:59:59' as timestamp) + + cast('9223372036854775807 microseconds' as interval) as "out of range"; select - cast('12/31/294276' as timestamp) - - cast('12/23/1999' as timestamp) + cast('12/31/294276' as timestamp) - cast('12/23/1999' as timestamp) as "106751991 Days"; select cast('today' as timestamp) = - cast('yesterday' as timestamp) + - cast('1 day' as interval) + cast('yesterday' as timestamp) + cast('1 day' as interval) as "True"; select cast('today' as timestamp) = - cast('tomorrow' as timestamp) - - cast('1 day' as interval) + cast('tomorrow' as timestamp) - cast('1 day' as interval) as "True"; select cast('today 10:30' as timestamp) = - cast('yesterday' as timestamp) + - cast('1 day 10 hr 30 min' as interval) + cast('yesterday' as timestamp) + cast('1 day 10 hr 30 min' as interval) as "True"; select cast('10:30 today' as timestamp) = - cast('yesterday' as timestamp) + - cast('1 day 10 hr 30 min' as interval) + cast('yesterday' as timestamp) + cast('1 day 10 hr 30 min' as interval) as "True"; select cast('tomorrow' as timestamp) = - cast('yesterday' as timestamp) + - cast('2 days' as interval) + cast('yesterday' as timestamp) + cast('2 days' as interval) as "True"; select cast('tomorrow 16:00:00' as timestamp) = - cast('today' as timestamp) + - cast('1 day 16 hours' as interval) + cast('today' as timestamp) + cast('1 day 16 hours' as interval) as "True"; select cast('16:00:00 tomorrow' as timestamp) = - cast('today' as timestamp) + - cast('1 day 16 hours' as interval) + cast('today' as timestamp) + cast('1 day 16 hours' as interval) as "True"; select cast('yesterday 12:34:56' as timestamp) = - cast('tomorrow' as timestamp) - - cast('2 days - 12:34:56' as interval) + cast('tomorrow' as timestamp) - cast('2 days - 12:34:56' as interval) as "True"; select cast('12:34:56 yesterday' as timestamp) = - cast('tomorrow' as timestamp) - - cast('2 days - 12:34:56' as interval) + cast('tomorrow' as timestamp) - cast('2 days - 12:34:56' as interval) as "True"; select cast('tomorrow' as timestamp) > 'now' as "True"; @@ -360,9 +327,7 @@ select cast('1994-01-01' as date) + cast('11:00' as time) as "Jan_01_1994_11am"; select cast('1994-01-01' as date) + cast('10:00' as time) as "Jan_01_1994_10am"; select - cast('1994-01-01' as date) + - cast('11:00-5' as time with time zone) - as "Jan_01_1994_8am"; + cast('1994-01-01' as date) + cast('11:00-5' as timetz) as "Jan_01_1994_8am"; select timestamptz( @@ -376,64 +341,45 @@ select d1 + cast('1 year' as interval) as one_year from timestamp_tbl; select d1 - cast('1 year' as interval) as one_year from timestamp_tbl; select - cast('1996-03-01' - as timestamp with time zone) - - cast('1 second' as interval) + cast('1996-03-01' as timestamp with time zone) - cast('1 second' as interval) as "Feb 29"; select - cast('1999-03-01' - as timestamp with time zone) - - cast('1 second' as interval) + cast('1999-03-01' as timestamp with time zone) - cast('1 second' as interval) as "Feb 28"; select - cast('2000-03-01' - as timestamp with time zone) - - cast('1 second' as interval) + cast('2000-03-01' as timestamp with time zone) - cast('1 second' as interval) as "Feb 29"; select - cast('1999-12-01' - as timestamp with time zone) + + cast('1999-12-01' as timestamp with time zone) + cast('1 month - 1 second' as interval) as "Dec 31"; select - cast('2000-01-01' - as timestamp with time zone) - + cast('2000-01-01' as timestamp with time zone) - cast('2483590 days' as interval) as "out of range"; select - cast('294276-12-31 23:59:59 UTC' - as timestamp with time zone) + - cast('9223372036854775807 microseconds' - as interval) + cast('294276-12-31 23:59:59 UTC' as timestamp with time zone) + + cast('9223372036854775807 microseconds' as interval) as "out of range"; select - cast('today' - as timestamp with time zone) = - cast('yesterday' - as timestamp with time zone) + - cast('1 day' as interval) + cast('today' as timestamp with time zone) = + cast('yesterday' as timestamp with time zone) + cast('1 day' as interval) as "True"; select - cast('today' - as timestamp with time zone) = - cast('tomorrow' - as timestamp with time zone) - - cast('1 day' as interval) + cast('today' as timestamp with time zone) = + cast('tomorrow' as timestamp with time zone) - cast('1 day' as interval) as "True"; select - cast('tomorrow' - as timestamp with time zone) = - cast('yesterday' - as timestamp with time zone) + - cast('2 days' as interval) + cast('tomorrow' as timestamp with time zone) = + cast('yesterday' as timestamp with time zone) + cast('2 days' as interval) as "True"; select cast('tomorrow' as timestamp with time zone) > 'now' as "True"; @@ -441,43 +387,33 @@ select cast('tomorrow' as timestamp with time zone) > 'now' as "True"; set time zone 'CST7CDT,M4.1.0,M10.5.0'; select - cast('2005-04-02 12:00-07' - as timestamp with time zone) + + cast('2005-04-02 12:00-07' as timestamp with time zone) + cast('1 day' as interval) as "Apr 3, 12:00"; select - cast('2005-04-02 12:00-07' - as timestamp with time zone) + + cast('2005-04-02 12:00-07' as timestamp with time zone) + cast('24 hours' as interval) as "Apr 3, 13:00"; select - cast('2005-04-03 12:00-06' - as timestamp with time zone) - + cast('2005-04-03 12:00-06' as timestamp with time zone) - cast('1 day' as interval) as "Apr 2, 12:00"; select - cast('2005-04-03 12:00-06' - as timestamp with time zone) - + cast('2005-04-03 12:00-06' as timestamp with time zone) - cast('24 hours' as interval) as "Apr 2, 11:00"; reset timezone; select - timestamptz( - cast('1994-01-01' as date), - cast('11:00' as time) - ) + timestamptz(cast('1994-01-01' as date), cast('11:00' as time)) as "Jan_01_1994_10am"; select - timestamptz( - cast('1994-01-01' as date), - cast('10:00' as time) - ) + timestamptz(cast('1994-01-01' as date), cast('10:00' as time)) as "Jan_01_1994_9am"; select @@ -526,26 +462,22 @@ select cast(cast('01:02-08' as time with time zone) as interval) as "+00:01"; select cast(cast('02:03' as interval) as time with time zone) as "02:03:00-08"; select - cast('01:30-08' as time with time zone) - - cast('02:01' as interval) + cast('01:30-08' as time with time zone) - cast('02:01' as interval) as "23:29:00-08"; select - cast('02:30-08' as time with time zone) + - cast('36:01' as interval) + cast('02:30-08' as time with time zone) + cast('36:01' as interval) as "14:31:00-08"; select - cast(cast(cast('today' as date) + - cast('05:30' as time with time zone) + + cast(cast(cast('today' as date) + cast('05:30' as time with time zone) + cast('02:01' as interval) as time with time zone) as time) as "07:31:00"; select - cast(cast(cast('today' as date) + - cast('03:30' as time with time zone) + + cast(cast(cast('today' as date) + cast('03:30' as time with time zone) + cast('1 month 04:01' as interval) as timestamp) as time) @@ -560,9 +492,7 @@ from timestamp_tbl as t, interval_tbl as i where - t.d1 - between '1990-01-01' - and '2001-01-01' and + t.d1 between '1990-01-01' and '2001-01-01' and i.f1 between '00:00' and '23:00' order by 1, 2; @@ -594,165 +524,95 @@ order by 1, 2; select - overlaps( - cast('2000-11-27' - as timestamp with time zone), - cast('2000-11-28' - as timestamp with time zone), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('2000-11-30' - as timestamp with time zone) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('2000-11-28' + as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' + as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) as "True"; select - overlaps( - cast('2000-11-26' - as timestamp with time zone), - cast('2000-11-27' - as timestamp with time zone), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('2000-11-30' - as timestamp with time zone) - ) + ((cast('2000-11-26' as timestamp with time zone), cast('2000-11-27' + as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' + as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) as "False"; select - overlaps( - cast('2000-11-27' - as timestamp with time zone), - cast('2000-11-28' - as timestamp with time zone), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('1 day' as interval) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('2000-11-28' + as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' + as timestamp with time zone), cast('1 day' as interval))) as "True"; select - overlaps( - cast('2000-11-27' - as timestamp with time zone), - cast('12 hours' as interval), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('2000-11-30' - as timestamp with time zone) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' + as interval)) overlaps (cast('2000-11-27 12:00' + as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) as "False"; select - overlaps( - cast('2000-11-27' - as timestamp with time zone), - cast('12 hours' as interval), - cast('2000-11-27' - as timestamp with time zone), - cast('12 hours' as interval) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' + as interval)) overlaps (cast('2000-11-27' + as timestamp with time zone), cast('12 hours' as interval))) as "True"; select - overlaps( - cast('2000-11-27' - as timestamp with time zone), - cast('12 hours' as interval), - cast('2000-11-27 12:00' - as timestamp with time zone), - cast('12 hours' as interval) - ) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' + as interval)) overlaps (cast('2000-11-27 12:00' + as timestamp with time zone), cast('12 hours' as interval))) as "False"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('2000-11-28' as timestamp), - cast('2000-11-27 12:00' as timestamp), - cast('2000-11-30' as timestamp) - ) + ((cast('2000-11-27' as timestamp), cast('2000-11-28' + as timestamp)) overlaps (cast('2000-11-27 12:00' + as timestamp), cast('2000-11-30' as timestamp))) as "True"; select - overlaps( - cast('2000-11-26' as timestamp), - cast('2000-11-27' as timestamp), - cast('2000-11-27 12:00' as timestamp), - cast('2000-11-30' as timestamp) - ) + ((cast('2000-11-26' as timestamp), cast('2000-11-27' + as timestamp)) overlaps (cast('2000-11-27 12:00' + as timestamp), cast('2000-11-30' as timestamp))) as "False"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('2000-11-28' as timestamp), - cast('2000-11-27 12:00' as timestamp), - cast('1 day' as interval) - ) + ((cast('2000-11-27' as timestamp), cast('2000-11-28' + as timestamp)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('1 day' + as interval))) as "True"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('12 hours' as interval), - cast('2000-11-27 12:00' as timestamp), - cast('2000-11-30' as timestamp) - ) + ((cast('2000-11-27' as timestamp), cast('12 hours' + as interval)) overlaps (cast('2000-11-27 12:00' + as timestamp), cast('2000-11-30' as timestamp))) as "False"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('12 hours' as interval), - cast('2000-11-27' as timestamp), - cast('12 hours' as interval) - ) + ((cast('2000-11-27' as timestamp), cast('12 hours' + as interval)) overlaps (cast('2000-11-27' as timestamp), cast('12 hours' + as interval))) as "True"; select - overlaps( - cast('2000-11-27' as timestamp), - cast('12 hours' as interval), - cast('2000-11-27 12:00' as timestamp), - cast('12 hours' as interval) - ) + ((cast('2000-11-27' as timestamp), cast('12 hours' + as interval)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('12 hours' + as interval))) as "False"; select - overlaps( - cast('00:00' as time), - cast('01:00' as time), - cast('00:30' as time), - cast('01:30' as time) - ) + ((cast('00:00' as time), cast('01:00' as time)) overlaps (cast('00:30' + as time), cast('01:30' as time))) as "True"; select - overlaps( - cast('00:00' as time), - cast('1 hour' as interval), - cast('00:30' as time), - cast('1 hour' as interval) - ) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('00:30' + as time), cast('1 hour' as interval))) as "True"; select - overlaps( - cast('00:00' as time), - cast('1 hour' as interval), - cast('01:30' as time), - cast('1 hour' as interval) - ) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('01:30' + as time), cast('1 hour' as interval))) as "False"; select - overlaps( - cast('00:00' as time), - cast('1 hour' as interval), - cast('01:30' as time), - cast('1 day' as interval) - ) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('01:30' + as time), cast('1 day' as interval))) as "False"; create table temp_timestamp (f1 timestamp with time zone); @@ -763,9 +623,7 @@ select from timestamp_tbl where - d1 - between '13-jun-1957' - and '1-jan-1997' or + d1 between '13-jun-1957' and '1-jan-1997' or d1 between '1-jan-1999' and '1-jan-2010'; select f1 as timestamp from temp_timestamp order by timestamp; @@ -794,13 +652,8 @@ order by minus, select d.f1 as timestamp, - cast('1980-01-06 00:00 GMT' - as timestamp with time zone) - as gpstime_zero, - d.f1 - - cast('1980-01-06 00:00 GMT' - as timestamp with time zone) - as difference + cast('1980-01-06 00:00 GMT' as timestamp with time zone) as gpstime_zero, + d.f1 - cast('1980-01-06 00:00 GMT' as timestamp with time zone) as difference from temp_timestamp as d order by difference; @@ -834,113 +687,79 @@ select cast('2202020-10-05' as date) > cast('2020-10-05' as timestamp) as t; select cast('2020-10-05' as timestamp) > cast('2202020-10-05' as date) as f; -select cast(cast('2202020-10-05' as date) as timestamp with time zone); +select cast(cast('2202020-10-05' as date) as timestamptz); -select - cast('2202020-10-05' as date) > - cast('2020-10-05' - as timestamp with time zone) - as t; +select cast('2202020-10-05' as date) > cast('2020-10-05' as timestamptz) as t; -select - cast('2020-10-05' - as timestamp with time zone) > - cast('2202020-10-05' as date) - as f; +select cast('2020-10-05' as timestamptz) > cast('2202020-10-05' as date) as f; -select cast(cast('4714-11-24 BC' as date) as timestamp with time zone); +select cast(cast('4714-11-24 BC' as date) as timestamptz); set time zone 'UTC-2'; -select cast(cast('4714-11-24 BC' as date) as timestamp with time zone); +select cast(cast('4714-11-24 BC' as date) as timestamptz); -select - cast('4714-11-24 BC' as date) < - cast('2020-10-05' - as timestamp with time zone) - as t; +select cast('4714-11-24 BC' as date) < cast('2020-10-05' as timestamptz) as t; -select - cast('2020-10-05' - as timestamp with time zone) >= - cast('4714-11-24 BC' as date) - as t; +select cast('2020-10-05' as timestamptz) >= cast('4714-11-24 BC' as date) as t; select - cast('4714-11-24 BC' as timestamp) < - cast('2020-10-05' - as timestamp with time zone) - as t; + cast('4714-11-24 BC' as timestamp) < cast('2020-10-05' as timestamptz) as t; select - cast('2020-10-05' - as timestamp with time zone) >= - cast('4714-11-24 BC' as timestamp) - as t; + cast('2020-10-05' as timestamptz) >= cast('4714-11-24 BC' as timestamp) as t; reset timezone; -select COUNT(*) from date_tbl where f1 between '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 between '1997-01-01' and '1998-01-01'; -select COUNT(*) from date_tbl where f1 between '1997-01-01' and '1998-01-01'; +select count(*) from date_tbl where f1 between '1997-01-01' and '1998-01-01'; select - COUNT(*) + count(*) from date_tbl where - f1 - not between '1997-01-01' - and '1998-01-01'; + f1 not between '1997-01-01' and '1998-01-01'; select - COUNT(*) + count(*) from date_tbl where - f1 - not between '1997-01-01' - and '1998-01-01'; + f1 not between '1997-01-01' and '1998-01-01'; select - COUNT(*) + count(*) from date_tbl where - f1 - between symmetric '1997-01-01' - and '1998-01-01'; + f1 between symmetric '1997-01-01' and '1998-01-01'; select - COUNT(*) + count(*) from date_tbl where - f1 - between symmetric '1997-01-01' - and '1998-01-01'; + f1 between symmetric '1997-01-01' and '1998-01-01'; select - COUNT(*) + count(*) from date_tbl where - f1 - not between symmetric '1997-01-01' - and '1998-01-01'; + f1 not between symmetric '1997-01-01' and '1998-01-01'; select - COUNT(*) + count(*) from date_tbl where - f1 - not between symmetric '1997-01-01' - and '1998-01-01'; + f1 not between symmetric '1997-01-01' and '1998-01-01'; set datestyle = 'US,Postgres'; -show "datestyle"; +show datestyle; select d1 as us_postgres from timestamp_tbl; @@ -950,29 +769,29 @@ select d1 as us_iso from timestamp_tbl; set datestyle = 'US,SQL'; -show "datestyle"; +show datestyle; select d1 as us_sql from timestamp_tbl; set datestyle = 'European,Postgres'; -show "datestyle"; +show datestyle; insert into timestamp_tbl values ('13/06/1957'); -select COUNT(*) as one from timestamp_tbl where d1 = 'Jun 13 1957'; +select count(*) as one from timestamp_tbl where d1 = 'Jun 13 1957'; select d1 as european_postgres from timestamp_tbl; set datestyle = 'European,ISO'; -show "datestyle"; +show datestyle; select d1 as european_iso from timestamp_tbl; set datestyle = 'European,SQL'; -show "datestyle"; +show datestyle; select d1 as european_sql from timestamp_tbl; @@ -1104,82 +923,55 @@ select to_timestamp('2018-11-02 12:34:56.025', 'YYYY-MM-DD HH24:MI:SS.MS'); select i, - to_timestamp( - '2018-11-02 12:34:56', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.1', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.1', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.12', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.12', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.123', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.123', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.1234', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.1234', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.12345', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.12345', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.123456', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.123456', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '2018-11-02 12:34:56.123456789', - 'YYYY-MM-DD HH24:MI:SS.FF' || i - ) + to_timestamp('2018-11-02 12:34:56.123456789', 'YYYY-MM-DD HH24:MI:SS.FF' || i) from generate_series(1, 6) as i; select i, - to_timestamp( - '20181102123456123456', - 'YYYYMMDDHH24MISSFF' || i - ) + to_timestamp('20181102123456123456', 'YYYYMMDDHH24MISSFF' || i) from generate_series(1, 6) as i; @@ -1332,57 +1124,31 @@ select to_date('-2147483648 01', 'CC YY'); select to_date('2147483647 01', 'CC YY'); select - to_char( - cast('2012-12-12 12:00' - as timestamp with time zone), - 'YYYY-MM-DD HH:MI:SS TZ' - ); + to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD HH:MI:SS TZ'); select - to_char( - cast('2012-12-12 12:00' - as timestamp with time zone), - 'YYYY-MM-DD HH:MI:SS tz' - ); + to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD HH:MI:SS tz'); set time zone 'America/New_York'; set time zone '-1.5'; -show "timezone"; +show timezone; -select cast('2012-12-12 12:00' as timestamp with time zone); +select cast('2012-12-12 12:00' as timestamptz); -select cast('2012-12-12 12:00 America/New_York' as timestamp with time zone); +select cast('2012-12-12 12:00 America/New_York' as timestamptz); select - to_char( - cast('2012-12-12 12:00' - as timestamp with time zone), - 'YYYY-MM-DD HH:MI:SS TZ' - ); + to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD HH:MI:SS TZ'); -select - to_char( - cast('2012-12-12 12:00' - as timestamp with time zone), - 'YYYY-MM-DD SSSS' - ); +select to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD SSSS'); -select - to_char( - cast('2012-12-12 12:00' - as timestamp with time zone), - 'YYYY-MM-DD SSSSS' - ); +select to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD SSSSS'); set time zone '+2'; select - to_char( - cast('2012-12-12 12:00' - as timestamp with time zone), - 'YYYY-MM-DD HH:MI:SS TZ' - ); + to_char(cast('2012-12-12 12:00' as timestamptz), 'YYYY-MM-DD HH:MI:SS TZ'); reset timezone; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__identity_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__identity_100.snap index 3e9d1215f..90c12d1c4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__identity_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__identity_100.snap @@ -16,11 +16,7 @@ create table itest2 ( ); create table itest3 ( - a smallint - generated by default - as identity - (start with 7 - increment by 5), + a smallint generated by default as identity (start with 7 increment by 5), b text ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__identity_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__identity_80.snap index d6f62a885..acbe69cb9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__identity_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__identity_80.snap @@ -23,11 +23,7 @@ create table itest2 ( ); create table itest3 ( - a smallint - generated by default - as identity - (start with 7 - increment by 5), + a smallint generated by default as identity (start with 7 increment by 5), b text ); @@ -100,9 +96,7 @@ alter table itest4 create table itest_err_1 (a text generated by default as identity); create table itest_err_2 ( - a int - generated always as identity - generated by default as identity + a int generated always as identity generated by default as identity ); create table itest_err_3 (a int default 5 generated by default as identity); @@ -172,9 +166,7 @@ insert into itest5 overriding user value values (-5, 'fff'), (default, 'ggg'); insert into itest5 overriding user value -values - (default, 'hhh'), - (default, 'iii'); +values (default, 'hhh'), (default, 'iii'); select * from itest5; @@ -316,8 +308,7 @@ select from pg_sequence where - seqrelid = - cast('itest3_a_seq' as regclass); + seqrelid = cast('itest3_a_seq' as regclass); alter table itest3 alter column a type text; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__incremental_sort_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__incremental_sort_100.snap index 100415b6a..1048d387d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__incremental_sort_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__incremental_sort_100.snap @@ -21,7 +21,7 @@ returns table ( out_line text ) language plpgsql -as $function$ +as $$ declare line text; begin @@ -32,12 +32,12 @@ begin return next; end loop; end; -$function$; +$$; create or replace function explain_analyze_inc_sort_nodes(query text) returns jsonb language plpgsql -as $function$ +as $$ declare elements jsonb; element jsonb; @@ -69,12 +69,12 @@ begin end loop; return matching_nodes; end; -$function$; +$$; create or replace function explain_analyze_inc_sort_nodes_without_memory(query text) returns jsonb language plpgsql -as $function$ +as $$ declare nodes jsonb := '[]'::jsonb; node jsonb; @@ -92,12 +92,12 @@ begin end loop; return nodes; end; -$function$; +$$; create or replace function explain_analyze_inc_sort_nodes_verify_invariants(query text) -returns boolean +returns bool language plpgsql -as $function$ +as $$ declare node jsonb; group_stats jsonb; @@ -116,7 +116,7 @@ begin end loop; return true; end; -$function$; +$$; insert into t (a, b) select i / 100 + 1, i + 1 from generate_series(0, 999) as n (i); @@ -172,11 +172,7 @@ select delete from t; insert into t (a, b) -select - case when i < 5 then i else 9 end, - i -from - generate_series(1, 1000) as n (i); +select case when i < 5 then i else 9 end, i from generate_series(1, 1000) as n (i); analyze t; @@ -203,15 +199,7 @@ select from t left outer join - ( - select - * - from - (select * from t order by a) as v - order by a, - b - ) - as s + (select * from (select * from t order by a) as v order by a, b) as s on s.a = t.a where t.a in (1, 2); @@ -221,15 +209,7 @@ select from t left outer join - ( - select - * - from - (select * from t order by a) as v - order by a, - b - ) - as s + (select * from (select * from t order by a) as v order by a, b) as s on s.a = t.a where t.a in (1, 2); @@ -333,11 +313,11 @@ analyze t; set enable_incremental_sort = off; -select a, b, SUM(c) from t group by 1, 2 order by 1, 2, 3 limit 1; +select a, b, sum(c) from t group by 1, 2 order by 1, 2, 3 limit 1; set enable_incremental_sort = 'on'; -select a, b, SUM(c) from t group by 1, 2 order by 1, 2, 3 limit 1; +select a, b, sum(c) from t group by 1, 2 order by 1, 2, 3 limit 1; set enable_hashagg = off; @@ -366,20 +346,14 @@ select distinct stringu1 from tenk1, - lateral ( - select tenk1.unique1 from generate_series(1, 1000) - ) - as sub; + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub; select sub.unique1, stringu1 from tenk1, - lateral ( - select tenk1.unique1 from generate_series(1, 1000) - ) - as sub + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub order by 1, 2; @@ -388,59 +362,36 @@ select distinct md5(stringu1) from tenk1, - lateral ( - select tenk1.unique1 from generate_series(1, 1000) - ) - as sub; + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub; select sub.unique1, md5(stringu1) from tenk1, - lateral ( - select tenk1.unique1 from generate_series(1, 1000) - ) - as sub + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub order by 1, 2; select - COUNT(*) + count(*) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.unique2 + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.unique2 inner join tenk1 as t3 on t2.unique1 = t3.unique1 -order by COUNT(*); +order by count(*); select distinct unique1, - ( - select - t.unique1 - from - tenk1 - where - tenk1.unique1 = t.unique1 - ) + (select t.unique1 from tenk1 where tenk1.unique1 = t.unique1) from tenk1 as t, generate_series(1, 1000); select unique1, - ( - select - t.unique1 - from - tenk1 - where - tenk1.unique1 = t.unique1 - ) + (select t.unique1 from tenk1 where tenk1.unique1 = t.unique1) from tenk1 as t, generate_series(1, 1000) @@ -452,20 +403,14 @@ select distinct stringu1 || cast(random() as text) from tenk1, - lateral ( - select tenk1.unique1 from generate_series(1, 1000) - ) - as sub; + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub; select sub.unique1, stringu1 || cast(random() as text) from tenk1, - lateral ( - select tenk1.unique1 from generate_series(1, 1000) - ) - as sub + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub order by 1, 2; @@ -488,7 +433,7 @@ create table point_table ( b int ); -create index "point_table_a_idx" on point_table using gist (a); +create index point_table_a_idx on point_table using gist (a); select a, b, a <-> point(5, 5) as dist from point_table order by dist, b limit 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__incremental_sort_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__incremental_sort_80.snap index 9d82657a6..d13be3b41 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__incremental_sort_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__incremental_sort_80.snap @@ -27,7 +27,7 @@ returns table ( out_line text ) language plpgsql -as $function$ +as $$ declare line text; begin @@ -38,12 +38,12 @@ begin return next; end loop; end; -$function$; +$$; create or replace function explain_analyze_inc_sort_nodes(query text) returns jsonb language plpgsql -as $function$ +as $$ declare elements jsonb; element jsonb; @@ -75,7 +75,7 @@ begin end loop; return matching_nodes; end; -$function$; +$$; create or replace function explain_analyze_inc_sort_nodes_without_memory( @@ -83,7 +83,7 @@ explain_analyze_inc_sort_nodes_without_memory( ) returns jsonb language plpgsql -as $function$ +as $$ declare nodes jsonb := '[]'::jsonb; node jsonb; @@ -101,15 +101,15 @@ begin end loop; return nodes; end; -$function$; +$$; create or replace function explain_analyze_inc_sort_nodes_verify_invariants( query text ) -returns boolean +returns bool language plpgsql -as $function$ +as $$ declare node jsonb; group_stats jsonb; @@ -128,14 +128,10 @@ begin end loop; return true; end; -$function$; +$$; insert into t (a, b) -select - i / 100 + 1, - i + 1 -from - generate_series(0, 999) as n (i); +select i / 100 + 1, i + 1 from generate_series(0, 999) as n (i); analyze t; @@ -162,11 +158,7 @@ select * from (select * from t order by a) as s order by a, b limit 66; delete from t; insert into t (a, b) -select - i / 50 + 1, - i + 1 -from - generate_series(0, 999) as n (i); +select i / 50 + 1, i + 1 from generate_series(0, 999) as n (i); analyze t; @@ -225,15 +217,7 @@ select from t left outer join - ( - select - * - from - (select * from t order by a) as v - order by a, - b - ) - as s + (select * from (select * from t order by a) as v order by a, b) as s on s.a = t.a where t.a in (1, 2); @@ -243,15 +227,7 @@ select from t left outer join - ( - select - * - from - (select * from t order by a) as v - order by a, - b - ) - as s + (select * from (select * from t order by a) as v order by a, b) as s on s.a = t.a where t.a in (1, 2); @@ -348,12 +324,7 @@ create table t ( ); insert into t -select - mod(i, 10), - mod(i, 10), - i -from - generate_series(1, 10000) as s (i); +select mod(i, 10), mod(i, 10), i from generate_series(1, 10000) as s (i); create index on t using btree (a); @@ -361,11 +332,11 @@ analyze t; set enable_incremental_sort = off; -select a, b, SUM(c) from t group by 1, 2 order by 1, 2, 3 limit 1; +select a, b, sum(c) from t group by 1, 2 order by 1, 2, 3 limit 1; set enable_incremental_sort = 'on'; -select a, b, SUM(c) from t group by 1, 2 order by 1, 2, 3 limit 1; +select a, b, sum(c) from t group by 1, 2 order by 1, 2, 3 limit 1; set enable_hashagg = off; @@ -394,26 +365,14 @@ select distinct stringu1 from tenk1, - lateral ( - select - tenk1.unique1 - from - generate_series(1, 1000) - ) - as sub; + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub; select sub.unique1, stringu1 from tenk1, - lateral ( - select - tenk1.unique1 - from - generate_series(1, 1000) - ) - as sub + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub order by 1, 2; @@ -422,65 +381,36 @@ select distinct md5(stringu1) from tenk1, - lateral ( - select - tenk1.unique1 - from - generate_series(1, 1000) - ) - as sub; + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub; select sub.unique1, md5(stringu1) from tenk1, - lateral ( - select - tenk1.unique1 - from - generate_series(1, 1000) - ) - as sub + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub order by 1, 2; select - COUNT(*) + count(*) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.unique2 + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.unique2 inner join tenk1 as t3 on t2.unique1 = t3.unique1 -order by COUNT(*); +order by count(*); select distinct unique1, - ( - select - t.unique1 - from - tenk1 - where - tenk1.unique1 = t.unique1 - ) + (select t.unique1 from tenk1 where tenk1.unique1 = t.unique1) from tenk1 as t, generate_series(1, 1000); select unique1, - ( - select - t.unique1 - from - tenk1 - where - tenk1.unique1 = t.unique1 - ) + (select t.unique1 from tenk1 where tenk1.unique1 = t.unique1) from tenk1 as t, generate_series(1, 1000) @@ -492,26 +422,14 @@ select distinct stringu1 || cast(random() as text) from tenk1, - lateral ( - select - tenk1.unique1 - from - generate_series(1, 1000) - ) - as sub; + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub; select sub.unique1, stringu1 || cast(random() as text) from tenk1, - lateral ( - select - tenk1.unique1 - from - generate_series(1, 1000) - ) - as sub + lateral (select tenk1.unique1 from generate_series(1, 1000)) as sub order by 1, 2; @@ -534,7 +452,7 @@ create table point_table ( b int ); -create index "point_table_a_idx" on point_table using gist (a); +create index point_table_a_idx on point_table using gist (a); select a, @@ -559,10 +477,7 @@ limit 1; select * from - ( - select * from tenk1 order by four - ) - as t1 + (select * from tenk1 order by four) as t1 inner join tenk1 as t2 on t1.four = t2.four and t1.two = t2.two diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_100.snap index f3afadbb3..fa560c923 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_100.snap @@ -12,17 +12,14 @@ create table tbl_include_reg ( insert into tbl_include_reg select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create index "tbl_include_reg_idx" on tbl_include_reg using btree (c1, c2) include (c3, c4); +create index tbl_include_reg_idx on tbl_include_reg using btree (c1, c2) include (c3, c4); create index on tbl_include_reg using btree (c1, c2) include (c1, c3); select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where i.indrelid = cast('tbl_include_reg' as regclass) order by c.relname; @@ -35,41 +32,23 @@ create table tbl_include_unique1 ( ); insert into tbl_include_unique1 -select - x, - 2 * x, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; - -create unique -index "tbl_include_unique1_idx_unique" -on tbl_include_unique1 -using btree -( - c1, - c2 -) -include (c3, -c4); +select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; + +create unique index tbl_include_unique1_idx_unique on tbl_include_unique1 using btree (c1, c2) +include (c3, c4); alter table tbl_include_unique1 - add unique using index "tbl_include_unique1_idx_unique"; + add unique using index tbl_include_unique1_idx_unique; alter table tbl_include_unique1 - add unique (c1, c2) include ("c3", "c4"); + add unique (c1, c2) include (c3, c4); select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where - i.indrelid = - cast('tbl_include_unique1' as regclass) + i.indrelid = cast('tbl_include_unique1' as regclass) order by c.relname; create table tbl_include_unique2 ( @@ -81,19 +60,11 @@ create table tbl_include_unique2 ( insert into tbl_include_unique2 select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create unique -index "tbl_include_unique2_idx_unique" -on tbl_include_unique2 -using btree -( - c1, - c2 -) -include (c3, -c4); +create unique index tbl_include_unique2_idx_unique on tbl_include_unique2 using btree (c1, c2) +include (c3, c4); alter table tbl_include_unique2 - add unique (c1, c2) include ("c3", "c4"); + add unique (c1, c2) include (c3, c4); create table tbl_include_pk ( c1 int, @@ -105,15 +76,12 @@ create table tbl_include_pk ( insert into tbl_include_pk select 1, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; alter table tbl_include_pk - add primary key (c1, c2) include ("c3", "c4"); + add primary key (c1, c2) include (c3, c4); select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where i.indrelid = cast('tbl_include_pk' as regclass) order by c.relname; @@ -127,26 +95,16 @@ create table tbl_include_box ( insert into tbl_include_box select 1, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create unique index "tbl_include_box_idx_unique" -on tbl_include_box -using btree -( - c1, - c2 -) -include (c3, -c4); +create unique index tbl_include_box_idx_unique on tbl_include_box using btree (c1, c2) +include (c3, c4); alter table tbl_include_box - add primary key using index "tbl_include_box_idx_unique"; + add primary key using index tbl_include_box_idx_unique; select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where i.indrelid = cast('tbl_include_box' as regclass) order by c.relname; @@ -161,17 +119,14 @@ create table tbl_include_box_pk ( insert into tbl_include_box_pk select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; alter table tbl_include_box_pk - add primary key (c1, c2) include ("c3", "c4"); + add primary key (c1, c2) include (c3, c4); create table tbl ( c1 int, c2 int, c3 int, c4 box, - constraint "covering" unique (c1, - c2) - include ("c3", - "c4") + constraint covering unique (c1, c2) include (c3, c4) ); select @@ -205,10 +160,7 @@ create table tbl ( c2 int, c3 int, c4 box, - constraint "covering" primary key (c1, - c2) - include ("c3", - "c4") + constraint covering primary key (c1, c2) include (c3, c4) ); select @@ -231,8 +183,7 @@ select from pg_constraint where - conrelid = cast(cast('tbl' as regclass) as oid) and - contype = 'p'; + conrelid = cast(cast('tbl' as regclass) as oid) and contype = 'p'; insert into tbl select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; @@ -259,7 +210,7 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); select @@ -293,7 +244,7 @@ create table tbl ( c2 int, c3 int, c4 box, - primary key (c1, c2) include ("c3", "c4") + primary key (c1, c2) include (c3, c4) ); select @@ -316,8 +267,7 @@ select from pg_constraint where - conrelid = cast(cast('tbl' as regclass) as oid) and - contype = 'p'; + conrelid = cast(cast('tbl' as regclass) as oid) and contype = 'p'; insert into tbl select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; @@ -332,9 +282,7 @@ create table tbl ( c2 int, c3 int, c4 box, - exclude using btree (c1 with =) - include ("c3", - "c4") + exclude using btree (c1 with =) include (c3, c4) ); select @@ -372,7 +320,7 @@ create table tbl ( c4 int ); -create unique index "tbl_idx" on tbl using btree (c1, c2, c3, c4); +create unique index tbl_idx on tbl using btree (c1, c2, c3, c4); select indexdef from pg_indexes where tablename = 'tbl' order by indexname; @@ -390,7 +338,7 @@ create table tbl ( c4 box ); -create unique index "tbl_idx" on tbl using btree (c1, c2) include (c3, c4); +create unique index tbl_idx on tbl using btree (c1, c2) include (c3, c4); select indexdef from pg_indexes where tablename = 'tbl' order by indexname; @@ -406,7 +354,7 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); select indexdef from pg_indexes where tablename = 'tbl' order by indexname; @@ -428,7 +376,7 @@ create table tbl ( c2 int ); -create index "tbl_idx" on tbl using btree (c1, (c1 + 0)) include (c2); +create index tbl_idx on tbl using btree (c1, (c1 + 0)) include (c2); alter index tbl_idx alter column 1 set statistics 1000; @@ -449,7 +397,7 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); insert into tbl select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 1000) as x; @@ -465,7 +413,7 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); select indexdef from pg_indexes where tablename = 'tbl' order by indexname; @@ -518,7 +466,7 @@ create table tbl ( insert into tbl select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create unique index "tbl_idx_unique" on tbl using btree (c1, c2) include (c3, c4); +create unique index tbl_idx_unique on tbl using btree (c1, c2) include (c3, c4); update tbl set c1 = 100 where c1 = 2; @@ -537,7 +485,7 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); insert into tbl select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; @@ -556,7 +504,7 @@ create table nametbl ( c3 double precision ); -create index "nametbl_c1_c2_idx" on nametbl using btree (c2, c1) include (c3); +create index nametbl_c1_c2_idx on nametbl using btree (c2, c1) include (c3); insert into nametbl values (1, 'two', 3.0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_80.snap index 5afbfc935..0337ca2bd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_80.snap @@ -11,36 +11,19 @@ create table tbl_include_reg ( ); insert into tbl_include_reg -select - x, - 2 * x, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create index "tbl_include_reg_idx" -on tbl_include_reg -using btree -( - c1, - c2 -) -include (c3, -c4); +create index tbl_include_reg_idx on tbl_include_reg using btree (c1, c2) +include (c3, c4); create index on tbl_include_reg using btree (c1, c2) include (c1, c3); select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where - i.indrelid = - cast('tbl_include_reg' as regclass) + i.indrelid = cast('tbl_include_reg' as regclass) order by c.relname; create table tbl_include_unique1 ( @@ -51,41 +34,25 @@ create table tbl_include_unique1 ( ); insert into tbl_include_unique1 -select - x, - 2 * x, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create unique -index "tbl_include_unique1_idx_unique" -on tbl_include_unique1 -using btree -( - c1, - c2 -) -include (c3, -c4); +create unique index tbl_include_unique1_idx_unique + on tbl_include_unique1 + using btree (c1, c2) +include (c3, c4); alter table tbl_include_unique1 - add unique using index "tbl_include_unique1_idx_unique"; + add unique using index tbl_include_unique1_idx_unique; alter table tbl_include_unique1 - add unique (c1, c2) include ("c3", "c4"); + add unique (c1, c2) include (c3, c4); select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where - i.indrelid = - cast('tbl_include_unique1' as regclass) + i.indrelid = cast('tbl_include_unique1' as regclass) order by c.relname; create table tbl_include_unique2 ( @@ -96,27 +63,15 @@ create table tbl_include_unique2 ( ); insert into tbl_include_unique2 -select - 1, - 2, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create unique -index "tbl_include_unique2_idx_unique" -on tbl_include_unique2 -using btree -( - c1, - c2 -) -include (c3, -c4); +create unique index tbl_include_unique2_idx_unique + on tbl_include_unique2 + using btree (c1, c2) +include (c3, c4); alter table tbl_include_unique2 - add unique (c1, c2) include ("c3", "c4"); + add unique (c1, c2) include (c3, c4); create table tbl_include_pk ( c1 int, @@ -126,30 +81,17 @@ create table tbl_include_pk ( ); insert into tbl_include_pk -select - 1, - 2 * x, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; alter table tbl_include_pk - add primary key (c1, - c2) - include ("c3", - "c4"); + add primary key (c1, c2) include (c3, c4); select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where - i.indrelid = - cast('tbl_include_pk' as regclass) + i.indrelid = cast('tbl_include_pk' as regclass) order by c.relname; create table tbl_include_box ( @@ -160,38 +102,23 @@ create table tbl_include_box ( ); insert into tbl_include_box -select - 1, - 2 * x, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create unique -index "tbl_include_box_idx_unique" -on tbl_include_box -using btree -( +create unique index tbl_include_box_idx_unique on tbl_include_box using btree ( c1, c2 ) -include (c3, -c4); +include (c3, c4); alter table tbl_include_box - add primary key using index "tbl_include_box_idx_unique"; + add primary key using index tbl_include_box_idx_unique; select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where - i.indrelid = - cast('tbl_include_box' as regclass) + i.indrelid = cast('tbl_include_box' as regclass) order by c.relname; create table tbl_include_box_pk ( @@ -202,29 +129,17 @@ create table tbl_include_box_pk ( ); insert into tbl_include_box_pk -select - 1, - 2, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; alter table tbl_include_box_pk - add primary key (c1, - c2) - include ("c3", - "c4"); + add primary key (c1, c2) include (c3, c4); create table tbl ( c1 int, c2 int, c3 int, c4 box, - constraint "covering" unique (c1, - c2) - include ("c3", - "c4") + constraint covering unique (c1, c2) include (c3, c4) ); select @@ -238,8 +153,7 @@ select from pg_index where - indrelid = - cast(cast('tbl' as regclass) as oid); + indrelid = cast(cast('tbl' as regclass) as oid); select pg_get_constraintdef(oid), @@ -248,17 +162,10 @@ select from pg_constraint where - conrelid = - cast(cast('tbl' as regclass) as oid); + conrelid = cast(cast('tbl' as regclass) as oid); insert into tbl -select - 1, - 2, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; drop table tbl; @@ -267,10 +174,7 @@ create table tbl ( c2 int, c3 int, c4 box, - constraint "covering" primary key (c1, - c2) - include ("c3", - "c4") + constraint covering primary key (c1, c2) include (c3, c4) ); select @@ -284,8 +188,7 @@ select from pg_index where - indrelid = - cast(cast('tbl' as regclass) as oid); + indrelid = cast(cast('tbl' as regclass) as oid); select pg_get_constraintdef(oid), @@ -294,27 +197,13 @@ select from pg_constraint where - conrelid = - cast(cast('tbl' as regclass) as oid) and - contype = 'p'; + conrelid = cast(cast('tbl' as regclass) as oid) and contype = 'p'; insert into tbl -select - 1, - 2, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; insert into tbl -select - 1, - null, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, null, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; insert into tbl select x, 2 * x, null, null from generate_series(1, 300) as x; @@ -337,7 +226,7 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); select @@ -351,8 +240,7 @@ select from pg_index where - indrelid = - cast(cast('tbl' as regclass) as oid); + indrelid = cast(cast('tbl' as regclass) as oid); select pg_get_constraintdef(oid), @@ -361,17 +249,10 @@ select from pg_constraint where - conrelid = - cast(cast('tbl' as regclass) as oid); + conrelid = cast(cast('tbl' as regclass) as oid); insert into tbl -select - 1, - 2, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; drop table tbl; @@ -380,10 +261,7 @@ create table tbl ( c2 int, c3 int, c4 box, - primary key (c1, - c2) - include ("c3", - "c4") + primary key (c1, c2) include (c3, c4) ); select @@ -397,8 +275,7 @@ select from pg_index where - indrelid = - cast(cast('tbl' as regclass) as oid); + indrelid = cast(cast('tbl' as regclass) as oid); select pg_get_constraintdef(oid), @@ -407,27 +284,13 @@ select from pg_constraint where - conrelid = - cast(cast('tbl' as regclass) as oid) and - contype = 'p'; + conrelid = cast(cast('tbl' as regclass) as oid) and contype = 'p'; insert into tbl -select - 1, - 2, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; insert into tbl -select - 1, - null, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, null, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; insert into tbl select x, 2 * x, null, null from generate_series(1, 10) as x; @@ -438,9 +301,7 @@ create table tbl ( c2 int, c3 int, c4 box, - exclude using btree (c1 with =) - include ("c3", - "c4") + exclude using btree (c1 with =) include (c3, c4) ); select @@ -454,8 +315,7 @@ select from pg_index where - indrelid = - cast(cast('tbl' as regclass) as oid); + indrelid = cast(cast('tbl' as regclass) as oid); select pg_get_constraintdef(oid), @@ -464,17 +324,10 @@ select from pg_constraint where - conrelid = - cast(cast('tbl' as regclass) as oid); + conrelid = cast(cast('tbl' as regclass) as oid); insert into tbl -select - 1, - 2, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select 1, 2, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; insert into tbl select x, 2 * x, null, null from generate_series(1, 10) as x; @@ -487,7 +340,7 @@ create table tbl ( c4 int ); -create unique index "tbl_idx" on tbl using btree (c1, c2, c3, c4); +create unique index tbl_idx on tbl using btree (c1, c2, c3, c4); select indexdef from pg_indexes where tablename = 'tbl' order by indexname; @@ -505,7 +358,7 @@ create table tbl ( c4 box ); -create unique index "tbl_idx" on tbl using btree (c1, c2) include (c3, c4); +create unique index tbl_idx on tbl using btree (c1, c2) include (c3, c4); select indexdef from pg_indexes where tablename = 'tbl' order by indexname; @@ -521,7 +374,7 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); select indexdef from pg_indexes where tablename = 'tbl' order by indexname; @@ -543,7 +396,7 @@ create table tbl ( c2 int ); -create index "tbl_idx" on tbl using btree (c1, (c1 + 0)) include (c2); +create index tbl_idx on tbl using btree (c1, (c1 + 0)) include (c2); alter index tbl_idx alter column 1 set statistics 1000; @@ -564,17 +417,11 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); insert into tbl -select - x, - 2 * x, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 1000) as x; +select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 1000) as x; create unique index concurrently on tbl using btree (c1, c2) include (c3, c4); @@ -587,7 +434,7 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); select indexdef from pg_indexes where tablename = 'tbl' order by indexname; @@ -639,23 +486,9 @@ create table tbl ( ); insert into tbl -select - x, - 2 * x, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; -create unique index "tbl_idx_unique" -on tbl -using btree -( - c1, - c2 -) -include (c3, -c4); +create unique index tbl_idx_unique on tbl using btree (c1, c2) include (c3, c4); update tbl set c1 = 100 where c1 = 2; @@ -674,17 +507,11 @@ create table tbl ( c2 int, c3 int, c4 box, - unique (c1, c2) include ("c3", "c4") + unique (c1, c2) include (c3, c4) ); insert into tbl -select - x, - 2 * x, - 3 * x, - box('4,4,4,4') -from - generate_series(1, 10) as x; +select x, 2 * x, 3 * x, box('4,4,4,4') from generate_series(1, 10) as x; alter table tbl alter column c1 type bigint; @@ -700,7 +527,7 @@ create table nametbl ( c3 double precision ); -create index "nametbl_c1_c2_idx" on nametbl using btree (c2, c1) include (c3); +create index nametbl_c1_c2_idx on nametbl using btree (c2, c1) include (c3); insert into nametbl values (1, 'two', 3.0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_gist_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_gist_100.snap index f8411af8b..00e223390 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_gist_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_gist_100.snap @@ -19,15 +19,12 @@ select from generate_series(1, 8000) as x; -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c2, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c2, c3); select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where i.indrelid = cast('tbl_gist' as regclass) order by c.relname; @@ -49,7 +46,7 @@ create table tbl_gist ( c4 box ); -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c2, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c2, c3); insert into tbl_gist select @@ -63,10 +60,7 @@ from select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where i.indrelid = cast('tbl_gist' as regclass) order by c.relname; @@ -97,7 +91,7 @@ select from generate_series(1, 10) as x; -create index concurrently "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c2, c3); +create index concurrently tbl_gist_idx on tbl_gist using gist (c4) include (c1, c2, c3); select indexdef from pg_indexes where tablename = 'tbl_gist' order by indexname; @@ -119,7 +113,7 @@ select from generate_series(1, 10) as x; -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c3); select indexdef from pg_indexes where tablename = 'tbl_gist' order by indexname; @@ -150,7 +144,7 @@ select from generate_series(1, 10) as x; -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c3); update tbl_gist set c1 = 100 where c1 = 2; @@ -176,7 +170,7 @@ select from generate_series(1, 10) as x; -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c3); alter table tbl_gist alter column c1 type bigint; @@ -191,10 +185,7 @@ create table tbl_gist ( c2 int, c3 int, c4 box, - exclude using gist (c4 with &&) - include ("c1", - "c2", - "c3") + exclude using gist (c4 with &&) include (c1, c2, c3) ); insert into tbl_gist @@ -211,10 +202,7 @@ select x, 2 * x, 3 * x, - box( - point(3 * x, 2 * x), - point(3 * x + 1, 2 * x + 1) - ) + box(point(3 * x, 2 * x), point(3 * x + 1, 2 * x + 1)) from generate_series(1, 10) as x; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_gist_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_gist_80.snap index 079d84b04..d71876489 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_gist_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__index_including_gist_80.snap @@ -15,25 +15,18 @@ select x, 2 * x, 3 * x, - box( - point(x, x + 1), - point(2 * x, 2 * x + 1) - ) + box(point(x, x + 1), point(2 * x, 2 * x + 1)) from generate_series(1, 8000) as x; -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c2, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c2, c3); select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where - i.indrelid = - cast('tbl_gist' as regclass) + i.indrelid = cast('tbl_gist' as regclass) order by c.relname; select * from tbl_gist where c4 <@ box(point(1, 1), point(10, 10)); @@ -53,30 +46,23 @@ create table tbl_gist ( c4 box ); -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c2, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c2, c3); insert into tbl_gist select x, 2 * x, 3 * x, - box( - point(x, x + 1), - point(2 * x, 2 * x + 1) - ) + box(point(x, x + 1), point(2 * x, 2 * x + 1)) from generate_series(1, 8000) as x; select pg_get_indexdef(i.indexrelid) from - pg_index as i - inner join - pg_class as c - on i.indexrelid = c.oid + pg_index as i inner join pg_class as c on i.indexrelid = c.oid where - i.indrelid = - cast('tbl_gist' as regclass) + i.indrelid = cast('tbl_gist' as regclass) order by c.relname; select * from tbl_gist where c4 <@ box(point(1, 1), point(10, 10)); @@ -101,22 +87,12 @@ select x, 2 * x, 3 * x, - box( - point(x, x + 1), - point(2 * x, 2 * x + 1) - ) + box(point(x, x + 1), point(2 * x, 2 * x + 1)) from generate_series(1, 10) as x; -create index concurrently "tbl_gist_idx" -on tbl_gist -using gist -( - c4 -) -include (c1, -c2, -c3); +create index concurrently tbl_gist_idx on tbl_gist using gist (c4) +include (c1, c2, c3); select indexdef from pg_indexes where tablename = 'tbl_gist' order by indexname; @@ -134,14 +110,11 @@ select x, 2 * x, 3 * x, - box( - point(x, x + 1), - point(2 * x, 2 * x + 1) - ) + box(point(x, x + 1), point(2 * x, 2 * x + 1)) from generate_series(1, 10) as x; -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c3); select indexdef from pg_indexes where tablename = 'tbl_gist' order by indexname; @@ -168,14 +141,11 @@ select x, 2 * x, 3 * x, - box( - point(x, x + 1), - point(2 * x, 2 * x + 1) - ) + box(point(x, x + 1), point(2 * x, 2 * x + 1)) from generate_series(1, 10) as x; -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c3); update tbl_gist set c1 = 100 where c1 = 2; @@ -197,14 +167,11 @@ select x, 2 * x, 3 * x, - box( - point(x, x + 1), - point(2 * x, 2 * x + 1) - ) + box(point(x, x + 1), point(2 * x, 2 * x + 1)) from generate_series(1, 10) as x; -create index "tbl_gist_idx" on tbl_gist using gist (c4) include (c1, c3); +create index tbl_gist_idx on tbl_gist using gist (c4) include (c1, c3); alter table tbl_gist alter column c1 type bigint; @@ -219,10 +186,7 @@ create table tbl_gist ( c2 int, c3 int, c4 box, - exclude using gist (c4 with &&) - include ("c1", - "c2", - "c3") + exclude using gist (c4 with &&) include (c1, c2, c3) ); insert into tbl_gist @@ -230,10 +194,7 @@ select x, 2 * x, 3 * x, - box( - point(x, x + 1), - point(2 * x, 2 * x + 1) - ) + box(point(x, x + 1), point(2 * x, 2 * x + 1)) from generate_series(1, 10) as x; @@ -242,10 +203,7 @@ select x, 2 * x, 3 * x, - box( - point(3 * x, 2 * x), - point(3 * x + 1, 2 * x + 1) - ) + box(point(3 * x, 2 * x), point(3 * x + 1, 2 * x + 1)) from generate_series(1, 10) as x; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indexing_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indexing_100.snap index c84aad7e6..9d3a73db0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indexing_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indexing_100.snap @@ -9,7 +9,7 @@ create table idxpart ( ) partition by range(a); -create index "idxpart_idx" on idxpart using btree (a); +create index idxpart_idx on idxpart using btree (a); select relhassubclass from pg_class where relname = 'idxpart_idx'; @@ -23,7 +23,7 @@ create table idxpart2 partition of idxpart for values from (10) to (100) partiti create table idxpart21 partition of idxpart2 for values from (0) to (100); -create index "idxpart_idx" on only idxpart using btree (a); +create index idxpart_idx on only idxpart using btree (a); select relhassubclass from pg_class where relname = 'idxpart_idx'; @@ -37,10 +37,7 @@ select relhassubclass, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -83,7 +80,7 @@ partition by range(a); create table idxpart1 partition of idxpart for values from (minvalue) to (maxvalue); -create index "partidx_abc_idx" on idxpart using btree (a, b, c); +create index partidx_abc_idx on idxpart using btree (a, b, c); insert into idxpart (a, b, c) select i, i, i from generate_series(1, 50) as i; @@ -99,9 +96,9 @@ create table idxpart ( ) partition by range(a); -create index "idxparti" on idxpart using btree (a); +create index idxparti on idxpart using btree (a); -create index "idxparti2" on idxpart using btree (b, c); +create index idxparti2 on idxpart using btree (b, c); create table idxpart1 (like idxpart); @@ -109,9 +106,9 @@ alter table idxpart attach partition idxpart1 for values from (0) to (10); -create index "idxpart_c" on only idxpart using btree (c); +create index idxpart_c on only idxpart using btree (c); -create index "idxpart1_c" on idxpart1 using btree (c); +create index idxpart1_c on idxpart1 using btree (c); alter table idxpart_c attach partition @@ -154,10 +151,7 @@ select relhassubclass, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -213,23 +207,15 @@ partition by range(a, b); create table idxpart1 partition of idxpart for values from (0, 0) to (10, 10); -create index "idxpart_a_b_idx" on only idxpart using btree (a, b); +create index idxpart_a_b_idx on only idxpart using btree (a, b); -create index "idxpart1_a_b_idx" on idxpart1 using btree (a, b); +create index idxpart1_a_b_idx on idxpart1 using btree (a, b); -create index "idxpart1_tst1" on idxpart1 using btree (b, a); +create index idxpart1_tst1 on idxpart1 using btree (b, a); -create index "idxpart1_tst2" on idxpart1 using hash (a); +create index idxpart1_tst2 on idxpart1 using hash (a); -create index "idxpart1_tst3" -on idxpart1 -using btree -( - a, - b -) -where - a > 10; +create index idxpart1_tst3 on idxpart1 using btree (a, b) where a > 10; alter index idxpart attach partition @@ -267,7 +253,7 @@ alter index idxpart_a_b_idx attach partition idxpart1_a_b_idx; -create index "idxpart1_2_a_b" on idxpart1 using btree (a, b); +create index idxpart1_2_a_b on idxpart1 using btree (a, b); alter index idxpart_a_b_idx attach partition @@ -296,14 +282,7 @@ create table idxpart1 ( create index on idxpart1 using hash (a); -create index -on idxpart1 -using btree -( - a -) -where - b > 1; +create index on idxpart1 using btree (a) where b > 1; create index on idxpart1 using btree ((a + 0)); @@ -339,10 +318,7 @@ select cast(indrelid as regclass), cast(inhparent as regclass) from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid where cast(cast(indexrelid as regclass) as text) like 'idxpart%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -356,10 +332,7 @@ select cast(indrelid as regclass), cast(inhparent as regclass) from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid where cast(cast(indexrelid as regclass) as text) like 'idxpart%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -380,25 +353,22 @@ create table idxpart ( a int, b int, c text, - d boolean + d bool ) partition by range(a); -create index "idxparti" on idxpart using btree (a); +create index idxparti on idxpart using btree (a); -create index "idxparti2" on idxpart using btree (b, c); +create index idxparti2 on idxpart using btree (b, c); -create table idxpart1 (like idxpart including INDEXES); +create table idxpart1 (like idxpart including indexes); select relname, relkind, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -415,10 +385,7 @@ select relkind, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -426,24 +393,14 @@ where relname like 'idxpart%' order by relname; -create index -on idxpart1 -using btree -( - (a + b) -) -where - d = true; +create index on idxpart1 using btree ((a + b)) where d = true; select relname, relkind, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -451,24 +408,14 @@ where relname like 'idxpart%' order by relname; -create index "idxparti3" -on idxpart -using btree -( - (a + b) -) -where - d = true; +create index idxparti3 on idxpart using btree ((a + b)) where d = true; select relname, relkind, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -712,10 +659,7 @@ select cast(inhparent as regclass) as parent, pg_get_indexdef as childdef from - pg_class - left outer join - pg_inherits - on inhrelid = oid, + pg_class left outer join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' @@ -751,10 +695,7 @@ select cast(inhparent as regclass) as parent, pg_get_indexdef as childdef from - pg_class - left outer join - pg_inherits - on inhrelid = oid, + pg_class left outer join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' @@ -799,47 +740,19 @@ alter table idxpart attach partition idxpart1 for values from (0) to (1000); -create index "idxpart_1_idx" on only idxpart using btree (b, a); +create index idxpart_1_idx on only idxpart using btree (b, a); -create index "idxpart1_1_idx" on idxpart1 using btree (b, a); +create index idxpart1_1_idx on idxpart1 using btree (b, a); -create index "idxpart1_1b_idx" on idxpart1 using btree (b); +create index idxpart1_1b_idx on idxpart1 using btree (b); -create index "idxpart_2_idx" -on only idxpart -using btree -( - (b + a) -) -where - a > 1; +create index idxpart_2_idx on only idxpart using btree ((b + a)) where a > 1; -create index "idxpart1_2_idx" -on idxpart1 -using btree -( - (b + a) -) -where - a > 1; +create index idxpart1_2_idx on idxpart1 using btree ((b + a)) where a > 1; -create index "idxpart1_2b_idx" -on idxpart1 -using btree -( - (a + b) -) -where - a > 1; +create index idxpart1_2b_idx on idxpart1 using btree ((a + b)) where a > 1; -create index "idxpart1_2c_idx" -on idxpart1 -using btree -( - (b + a) -) -where - b > 1; +create index idxpart1_2c_idx on idxpart1 using btree ((b + a)) where b > 1; alter index idxpart_1_idx attach partition @@ -866,10 +779,7 @@ select cast(inhparent as regclass) as parent, pg_get_indexdef as childdef from - pg_class - left outer join - pg_inherits - on inhrelid = oid, + pg_class left outer join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' @@ -884,9 +794,9 @@ create table idxpart ( ) partition by range(a); -create index "idxparti" on idxpart using btree (a); +create index idxparti on idxpart using btree (a); -create index "idxparti2" on idxpart using btree (c, b); +create index idxparti2 on idxpart using btree (c, b); create table idxpart1 ( c text, @@ -916,10 +826,7 @@ select c.relname, pg_get_indexdef(indexrelid) from - pg_class as c - inner join - pg_index as i - on c.oid = i.indexrelid + pg_class as c inner join pg_index as i on c.oid = i.indexrelid where cast(cast(indrelid as regclass) as text) like 'idxpart%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -978,10 +885,7 @@ select c.relname, pg_get_indexdef(indexrelid) from - pg_class as c - inner join - pg_index as i - on c.oid = i.indexrelid + pg_class as c inner join pg_index as i on c.oid = i.indexrelid where cast(cast(indrelid as regclass) as text) like 'idxpart%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -1026,14 +930,7 @@ create table idxpart2 ( a int ); -create index -on idxpart2 -using btree -( - a -) -where - b > 1000; +create index on idxpart2 using btree (a) where b > 1000; alter table idxpart2 drop column col1, @@ -1043,23 +940,13 @@ alter table idxpart attach partition idxpart2 for values from (1000) to (2000); -create index -on idxpart -using btree -( - a -) -where - b > 1000; +create index on idxpart using btree (a) where b > 1000; select c.relname, pg_get_indexdef(indexrelid) from - pg_class as c - inner join - pg_index as i - on c.oid = i.indexrelid + pg_class as c inner join pg_index as i on c.oid = i.indexrelid where cast(cast(indrelid as regclass) as text) like 'idxpart%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -1100,8 +987,7 @@ select from pg_attribute where - cast(cast(attrelid as regclass) as text) like 'idxpart%' and - attnum > 0 + cast(cast(attrelid as regclass) as text) like 'idxpart%' and attnum > 0 order by cast(attrelid as regclass), attnum; @@ -1141,8 +1027,7 @@ select from pg_attribute where - cast(cast(attrelid as regclass) as text) like 'idxpart%' and - attnum > 0 + cast(cast(attrelid as regclass) as text) like 'idxpart%' and attnum > 0 order by cast(attrelid as regclass), attnum; @@ -1497,11 +1382,11 @@ order by cast(cast(conrelid as regclass) as text), drop table idxpart; create table idxpart (i int) -partition by HASH(i); +partition by hash(i); -create table idxpart0 partition of idxpart (i) for values with (MODULUS 2, REMAINDER 0); +create table idxpart0 partition of idxpart (i) for values with (modulus 2, remainder 0); -create table idxpart1 partition of idxpart (i) for values with (MODULUS 2, REMAINDER 1); +create table idxpart1 partition of idxpart (i) for values with (modulus 2, remainder 1); alter table idxpart0 add primary key (i); @@ -1520,10 +1405,7 @@ select connoinherit, convalidated from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid left outer join pg_constraint as con on idx.indexrelid = con.conindid @@ -1555,10 +1437,7 @@ select connoinherit, convalidated from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid left outer join pg_constraint as con on idx.indexrelid = con.conindid @@ -1640,10 +1519,7 @@ select connoinherit, convalidated from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid left outer join pg_constraint as con on idx.indexrelid = con.conindid @@ -1666,10 +1542,7 @@ select connoinherit, convalidated from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid left outer join pg_constraint as con on idx.indexrelid = con.conindid @@ -1737,10 +1610,7 @@ select connoinherit, convalidated from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid left outer join pg_constraint as con on idx.indexrelid = con.conindid @@ -1830,19 +1700,19 @@ create table idxpart1 partition of idxpart for values from (0) to (100000); set enable_seqscan = off; -create index "idxpart_brin" on idxpart using brin (b); +create index idxpart_brin on idxpart using brin (b); select * from idxpart where b = 'abcd'; drop index idxpart_brin; -create index "idxpart_spgist" on idxpart using spgist (b); +create index idxpart_spgist on idxpart using spgist (b); select * from idxpart where b = 'abcd'; drop index idxpart_spgist; -create index "idxpart_gin" on idxpart using gin (c); +create index idxpart_gin on idxpart using gin (c); select * from idxpart where c @> array[42]; @@ -1901,7 +1771,7 @@ alter table idxpart attach partition idxpart3 for values from (1000) to (2000); -create schema "regress_indexing"; +create schema regress_indexing; set search_path to regress_indexing; @@ -1950,7 +1820,7 @@ create table covidxpart ( a int, b int ) -partition by LIST(a); +partition by list(a); create unique index on covidxpart using btree (a) include (b); @@ -1999,7 +1869,7 @@ insert into covidxpart values (4, 1); create unique index on covidxpart using btree (b) include (a); create table parted_pk_detach_test (a int primary key) -partition by LIST(a); +partition by list(a); create table parted_pk_detach_test1 partition of parted_pk_detach_test for values in (1); @@ -2016,7 +1886,7 @@ alter table parted_pk_detach_test1 drop table parted_pk_detach_test, parted_pk_detach_test1; create table parted_uniq_detach_test (a int unique) -partition by LIST(a); +partition by list(a); create table parted_uniq_detach_test1 partition of parted_uniq_detach_test for values in (1); @@ -2037,17 +1907,17 @@ create table parted_index_col_drop ( b int, c int ) -partition by LIST(a); +partition by list(a); create table parted_index_col_drop1 partition of parted_index_col_drop for values in (1) -partition by LIST(a); +partition by list(a); create table parted_index_col_drop2 partition of parted_index_col_drop for values in (2) -partition by LIST(a); +partition by list(a); create table parted_index_col_drop11 partition of parted_index_col_drop1 for values in (1); @@ -2065,7 +1935,7 @@ drop table parted_index_col_drop; create table parted_inval_tab (a int) partition by range(a); -create index "parted_inval_idx" on parted_inval_tab using btree (a); +create index parted_inval_idx on parted_inval_tab using btree (a); create table parted_inval_tab_1 (a int) partition by range(a); @@ -2074,7 +1944,7 @@ create table parted_inval_tab_1_1 partition of parted_inval_tab_1 for values fro create table parted_inval_tab_1_2 partition of parted_inval_tab_1 for values from (10) to (20); -create index "parted_inval_ixd_1" on only parted_inval_tab_1 using btree (a); +create index parted_inval_ixd_1 on only parted_inval_tab_1 using btree (a); alter table parted_inval_tab attach partition @@ -2086,10 +1956,7 @@ select cast(indrelid as regclass), cast(inhparent as regclass) from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid where cast(cast(indexrelid as regclass) as text) like 'parted_inval%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -2118,9 +1985,9 @@ create table parted_isvalid_tab_12 partition of parted_isvalid_tab_1 for values insert into parted_isvalid_tab_11 values (1, 0); -create index concurrently "parted_isvalid_idx_11" on parted_isvalid_tab_11 using btree ((a / b)); +create index concurrently parted_isvalid_idx_11 on parted_isvalid_tab_11 using btree ((a / b)); -create index "parted_isvalid_idx" on parted_isvalid_tab using btree ((a / b)); +create index parted_isvalid_idx on parted_isvalid_tab using btree ((a / b)); select cast(indexrelid as regclass), @@ -2128,10 +1995,7 @@ select cast(indrelid as regclass), cast(inhparent as regclass) from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid where cast(cast(indexrelid as regclass) as text) like 'parted_isvalid%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -2150,14 +2014,14 @@ partition by range(id); create table parted_replica_tab_11 partition of parted_replica_tab_1 for values from (1) to (5); -create unique index "parted_replica_idx" on only parted_replica_tab using btree (id); +create unique index parted_replica_idx on only parted_replica_tab using btree (id); -create unique index "parted_replica_idx_1" on only parted_replica_tab_1 using btree (id); +create unique index parted_replica_idx_1 on only parted_replica_tab_1 using btree (id); alter table only parted_replica_tab_1 replica identity using index parted_replica_idx_1; -create unique index "parted_replica_idx_11" on parted_replica_tab_11 using btree (id); +create unique index parted_replica_idx_11 on parted_replica_tab_11 using btree (id); select cast(indexrelid as regclass), @@ -2166,10 +2030,7 @@ select cast(indrelid as regclass), cast(inhparent as regclass) from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid where cast(cast(indexrelid as regclass) as text) like 'parted_replica%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -2185,10 +2046,7 @@ select cast(indrelid as regclass), cast(inhparent as regclass) from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid where cast(cast(indexrelid as regclass) as text) like 'parted_replica%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -2209,10 +2067,7 @@ select cast(indrelid as regclass), cast(inhparent as regclass) from - pg_index as idx - left outer join - pg_inherits as inh - on idx.indexrelid = inh.inhrelid + pg_index as idx left outer join pg_inherits as inh on idx.indexrelid = inh.inhrelid where cast(cast(indexrelid as regclass) as text) like 'parted_replica%' order by cast(cast(indexrelid as regclass) as text) collate "C"; @@ -2222,31 +2077,22 @@ drop table parted_replica_tab; create table test_pg_index_toast_table (a int); create or replace function test_pg_index_toast_func(a int, b int[]) -returns boolean +returns bool language sql immutable -as $function$ -select true -$function$; +as $$ select true $$; select array_agg(n) as b from generate_series(1, 10000) as n; -create index -concurrently "test_pg_index_toast_index" -on test_pg_index_toast_table -using btree -( +create index concurrently test_pg_index_toast_index on test_pg_index_toast_table using btree ( (test_pg_index_toast_func(a, 'b')) ); -reindex (CONCURRENTLY) index test_pg_index_toast_index; +reindex (concurrently) index test_pg_index_toast_index; drop index concurrently test_pg_index_toast_index; -create index "test_pg_index_toast_index" -on test_pg_index_toast_table -using btree -( +create index test_pg_index_toast_index on test_pg_index_toast_table using btree ( (test_pg_index_toast_func(a, 'b')) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indexing_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indexing_80.snap index dabc1cca2..d22d26068 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indexing_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indexing_80.snap @@ -9,7 +9,7 @@ create table idxpart ( ) partition by range(a); -create index "idxpart_idx" on idxpart using btree (a); +create index idxpart_idx on idxpart using btree (a); select relhassubclass from pg_class where relname = 'idxpart_idx'; @@ -26,7 +26,7 @@ partition by range(b); create table idxpart21 partition of idxpart2 for values from (0) to (100); -create index "idxpart_idx" on only idxpart using btree (a); +create index idxpart_idx on only idxpart using btree (a); select relhassubclass from pg_class where relname = 'idxpart_idx'; @@ -40,10 +40,7 @@ select relhassubclass, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -88,7 +85,7 @@ create table idxpart1 partition of idxpart for values from (minvalue) to (maxvalue); -create index "partidx_abc_idx" on idxpart using btree (a, b, c); +create index partidx_abc_idx on idxpart using btree (a, b, c); insert into idxpart (a, b, c) select i, i, i from generate_series(1, 50) as i; @@ -104,9 +101,9 @@ create table idxpart ( ) partition by range(a); -create index "idxparti" on idxpart using btree (a); +create index idxparti on idxpart using btree (a); -create index "idxparti2" on idxpart using btree (b, c); +create index idxparti2 on idxpart using btree (b, c); create table idxpart1 (like idxpart); @@ -114,9 +111,9 @@ alter table idxpart attach partition idxpart1 for values from (0) to (10); -create index "idxpart_c" on only idxpart using btree (c); +create index idxpart_c on only idxpart using btree (c); -create index "idxpart1_c" on idxpart1 using btree (c); +create index idxpart1_c on idxpart1 using btree (c); alter table idxpart_c attach partition @@ -159,10 +156,7 @@ select relhassubclass, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -241,23 +235,15 @@ partition by range(a, b); create table idxpart1 partition of idxpart for values from (0, 0) to (10, 10); -create index "idxpart_a_b_idx" on only idxpart using btree (a, b); +create index idxpart_a_b_idx on only idxpart using btree (a, b); -create index "idxpart1_a_b_idx" on idxpart1 using btree (a, b); +create index idxpart1_a_b_idx on idxpart1 using btree (a, b); -create index "idxpart1_tst1" on idxpart1 using btree (b, a); +create index idxpart1_tst1 on idxpart1 using btree (b, a); -create index "idxpart1_tst2" on idxpart1 using hash (a); +create index idxpart1_tst2 on idxpart1 using hash (a); -create index "idxpart1_tst3" -on idxpart1 -using btree -( - a, - b -) -where - a > 10; +create index idxpart1_tst3 on idxpart1 using btree (a, b) where a > 10; alter index idxpart attach partition @@ -295,7 +281,7 @@ alter index idxpart_a_b_idx attach partition idxpart1_a_b_idx; -create index "idxpart1_2_a_b" on idxpart1 using btree (a, b); +create index idxpart1_2_a_b on idxpart1 using btree (a, b); alter index idxpart_a_b_idx attach partition @@ -309,8 +295,7 @@ select from pg_index where - cast(cast(indexrelid as regclass) - as text) like 'idxpart%'; + cast(cast(indexrelid as regclass) as text) like 'idxpart%'; create table idxpart ( a int, @@ -325,14 +310,7 @@ create table idxpart1 ( create index on idxpart1 using hash (a); -create index -on idxpart1 -using btree -( - a -) -where - b > 1; +create index on idxpart1 using btree (a) where b > 1; create index on idxpart1 using btree ((a + 0)); @@ -376,10 +354,8 @@ from pg_inherits as inh on idx.indexrelid = inh.inhrelid where - cast(cast(indexrelid as regclass) - as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; + cast(cast(indexrelid as regclass) as text) like 'idxpart%' +order by cast(cast(indexrelid as regclass) as text) collate "C"; alter index idxpart2_a_idx attach partition @@ -395,10 +371,8 @@ from pg_inherits as inh on idx.indexrelid = inh.inhrelid where - cast(cast(indexrelid as regclass) - as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; + cast(cast(indexrelid as regclass) as text) like 'idxpart%' +order by cast(cast(indexrelid as regclass) as text) collate "C"; alter index idxpart2_a_idx attach partition @@ -416,25 +390,22 @@ create table idxpart ( a int, b int, c text, - d boolean + d bool ) partition by range(a); -create index "idxparti" on idxpart using btree (a); +create index idxparti on idxpart using btree (a); -create index "idxparti2" on idxpart using btree (b, c); +create index idxparti2 on idxpart using btree (b, c); -create table idxpart1 (like idxpart including INDEXES); +create table idxpart1 (like idxpart including indexes); select relname, relkind, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -451,10 +422,7 @@ select relkind, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -462,24 +430,14 @@ where relname like 'idxpart%' order by relname; -create index -on idxpart1 -using btree -( - (a + b) -) -where - d = true; +create index on idxpart1 using btree ((a + b)) where d = true; select relname, relkind, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -487,24 +445,14 @@ where relname like 'idxpart%' order by relname; -create index "idxparti3" -on idxpart -using btree -( - (a + b) -) -where - d = true; +create index idxparti3 on idxpart using btree ((a + b)) where d = true; select relname, relkind, cast(inhparent as regclass) from - pg_class - left outer join - pg_index as ix - on indexrelid = oid + pg_class left outer join pg_index as ix on indexrelid = oid left outer join pg_inherits on ix.indexrelid = inhrelid @@ -535,10 +483,7 @@ select relname, indisvalid from - pg_class - inner join - pg_index - on indexrelid = oid + pg_class inner join pg_index on indexrelid = oid where relname like 'idxpart%' order by relname; @@ -551,10 +496,7 @@ select relname, indisvalid from - pg_class - inner join - pg_index - on indexrelid = oid + pg_class inner join pg_index on indexrelid = oid where relname like 'idxpart%' order by relname; @@ -569,10 +511,7 @@ select relname, indisvalid from - pg_class - inner join - pg_index - on indexrelid = oid + pg_class inner join pg_index on indexrelid = oid where relname like 'idxpart%' order by relname; @@ -596,8 +535,7 @@ alter table idxpart alter table idxpart attach partition - idxpart2 - for values from (1000) to (2000); + idxpart2 for values from (1000) to (2000); create table idxpart3 partition of idxpart for values from (2000) to (3000); @@ -665,8 +603,7 @@ alter table idxpart alter table idxpart attach partition - idxpart2 - for values from (1000) to (2000); + idxpart2 for values from (1000) to (2000); create table idxpart3 partition of idxpart for values from (2000) to (3000); @@ -755,8 +692,7 @@ alter table idxpart alter table idxpart attach partition - idxpart2 - for values from (1000) to (2000); + idxpart2 for values from (1000) to (2000); create table idxpart3 partition of idxpart for values from (2000) to (3000); @@ -765,14 +701,10 @@ select cast(inhparent as regclass) as parent, pg_get_indexdef as childdef from - pg_class - inner join - pg_inherits - on inhrelid = oid, + pg_class inner join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where - relkind in ('i', 'I') and - relname like 'idxpart%' + relkind in ('i', 'I') and relname like 'idxpart%' order by relname; drop table idxpart; @@ -792,13 +724,11 @@ create index on idxpart2 using btree (a collate "C"); alter table idxpart attach partition - idxpart1 - for values from ('aaa') to ('bbb'); + idxpart1 for values from ('aaa') to ('bbb'); alter table idxpart attach partition - idxpart2 - for values from ('bbb') to ('ccc'); + idxpart2 for values from ('bbb') to ('ccc'); create table idxpart3 partition of idxpart for values from ('ccc') to ('ddd'); @@ -811,14 +741,10 @@ select cast(inhparent as regclass) as parent, pg_get_indexdef as childdef from - pg_class - left outer join - pg_inherits - on inhrelid = oid, + pg_class left outer join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where - relkind in ('i', 'I') and - relname like 'idxpart%' + relkind in ('i', 'I') and relname like 'idxpart%' order by relname; drop table idxpart; @@ -834,13 +760,11 @@ create index on idxpart2 using btree (a); alter table idxpart attach partition - idxpart1 - for values from ('aaa') to ('bbb'); + idxpart1 for values from ('aaa') to ('bbb'); alter table idxpart attach partition - idxpart2 - for values from ('bbb') to ('ccc'); + idxpart2 for values from ('bbb') to ('ccc'); create table idxpart3 partition of idxpart for values from ('ccc') to ('ddd'); @@ -853,14 +777,10 @@ select cast(inhparent as regclass) as parent, pg_get_indexdef as childdef from - pg_class - left outer join - pg_inherits - on inhrelid = oid, + pg_class left outer join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where - relkind in ('i', 'I') and - relname like 'idxpart%' + relkind in ('i', 'I') and relname like 'idxpart%' order by relname; drop index idxpart_a_idx; @@ -902,47 +822,19 @@ alter table idxpart attach partition idxpart1 for values from (0) to (1000); -create index "idxpart_1_idx" on only idxpart using btree (b, a); +create index idxpart_1_idx on only idxpart using btree (b, a); -create index "idxpart1_1_idx" on idxpart1 using btree (b, a); +create index idxpart1_1_idx on idxpart1 using btree (b, a); -create index "idxpart1_1b_idx" on idxpart1 using btree (b); +create index idxpart1_1b_idx on idxpart1 using btree (b); -create index "idxpart_2_idx" -on only idxpart -using btree -( - (b + a) -) -where - a > 1; +create index idxpart_2_idx on only idxpart using btree ((b + a)) where a > 1; -create index "idxpart1_2_idx" -on idxpart1 -using btree -( - (b + a) -) -where - a > 1; +create index idxpart1_2_idx on idxpart1 using btree ((b + a)) where a > 1; -create index "idxpart1_2b_idx" -on idxpart1 -using btree -( - (a + b) -) -where - a > 1; +create index idxpart1_2b_idx on idxpart1 using btree ((a + b)) where a > 1; -create index "idxpart1_2c_idx" -on idxpart1 -using btree -( - (b + a) -) -where - b > 1; +create index idxpart1_2c_idx on idxpart1 using btree ((b + a)) where b > 1; alter index idxpart_1_idx attach partition @@ -969,14 +861,10 @@ select cast(inhparent as regclass) as parent, pg_get_indexdef as childdef from - pg_class - left outer join - pg_inherits - on inhrelid = oid, + pg_class left outer join pg_inherits on inhrelid = oid, lateral pg_get_indexdef(pg_class.oid) where - relkind in ('i', 'I') and - relname like 'idxpart%' + relkind in ('i', 'I') and relname like 'idxpart%' order by relname; drop table idxpart; @@ -988,9 +876,9 @@ create table idxpart ( ) partition by range(a); -create index "idxparti" on idxpart using btree (a); +create index idxparti on idxpart using btree (a); -create index "idxparti2" on idxpart using btree (c, b); +create index idxparti2 on idxpart using btree (c, b); create table idxpart1 ( c text, @@ -1020,14 +908,10 @@ select c.relname, pg_get_indexdef(indexrelid) from - pg_class as c - inner join - pg_index as i - on c.oid = i.indexrelid + pg_class as c inner join pg_index as i on c.oid = i.indexrelid where cast(cast(indrelid as regclass) as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table idxpart; @@ -1083,14 +967,10 @@ select c.relname, pg_get_indexdef(indexrelid) from - pg_class as c - inner join - pg_index as i - on c.oid = i.indexrelid + pg_class as c inner join pg_index as i on c.oid = i.indexrelid where cast(cast(indrelid as regclass) as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table idxpart; @@ -1132,14 +1012,7 @@ create table idxpart2 ( a int ); -create index -on idxpart2 -using btree -( - a -) -where - b > 1000; +create index on idxpart2 using btree (a) where b > 1000; alter table idxpart2 drop column col1, @@ -1147,30 +1020,18 @@ alter table idxpart2 alter table idxpart attach partition - idxpart2 - for values from (1000) to (2000); + idxpart2 for values from (1000) to (2000); -create index -on idxpart -using btree -( - a -) -where - b > 1000; +create index on idxpart using btree (a) where b > 1000; select c.relname, pg_get_indexdef(indexrelid) from - pg_class as c - inner join - pg_index as i - on c.oid = i.indexrelid + pg_class as c inner join pg_index as i on c.oid = i.indexrelid where cast(cast(indrelid as regclass) as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table idxpart; @@ -1208,8 +1069,7 @@ select from pg_attribute where - cast(cast(attrelid as regclass) as text) like 'idxpart%' and - attnum > 0 + cast(cast(attrelid as regclass) as text) like 'idxpart%' and attnum > 0 order by cast(attrelid as regclass), attnum; @@ -1249,8 +1109,7 @@ select from pg_attribute where - cast(cast(attrelid as regclass) as text) like 'idxpart%' and - attnum > 0 + cast(cast(attrelid as regclass) as text) like 'idxpart%' and attnum > 0 order by cast(attrelid as regclass), attnum; @@ -1377,9 +1236,7 @@ create table idxpart ( a int4range, b int4range, c int4range, - exclude using gist (a with =, - b with =, - c with &&) + exclude using gist (a with =, b with =, c with &&) ) partition by range(a, b); @@ -1516,9 +1373,7 @@ create table idxpart ( partition by range(a, b); alter table idxpart - add exclude using gist (a with =, - b with =, - c with &&); + add exclude using gist (a with =, b with =, c with &&); drop table idxpart; @@ -1547,8 +1402,7 @@ create table idxpart3 ( alter table idxpart attach partition - idxpart3 - for values from (20, 20) to (30, 30); + idxpart3 for values from (20, 20) to (30, 30); select conname, @@ -1628,21 +1482,21 @@ order by cast(cast(conrelid as regclass) as text), drop table idxpart; create table idxpart (i int) -partition by HASH(i); +partition by hash(i); create table idxpart0 partition of idxpart ( i ) -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table idxpart1 partition of idxpart ( i ) -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); alter table idxpart0 add primary key (i); @@ -1670,8 +1524,7 @@ from on idx.indexrelid = con.conindid where cast(cast(indrelid as regclass) as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop index idxpart0_pkey; @@ -1706,8 +1559,7 @@ from on idx.indexrelid = con.conindid where cast(cast(indrelid as regclass) as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table idxpart; @@ -1792,8 +1644,7 @@ from on idx.indexrelid = con.conindid where cast(cast(indrelid as regclass) as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; +order by cast(cast(indexrelid as regclass) as text) collate "C"; alter index idxpart_pkey attach partition @@ -1819,8 +1670,7 @@ from on idx.indexrelid = con.conindid where cast(cast(indrelid as regclass) as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table idxpart; @@ -1891,8 +1741,7 @@ from on idx.indexrelid = con.conindid where cast(cast(indrelid as regclass) as text) like 'idxpart%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table idxpart; @@ -1945,30 +1794,19 @@ create unique index on idxpart using btree (a); alter table idxpart attach partition - idxpart2 - for values from (100000) to (1000000); + idxpart2 for values from (100000) to (1000000); insert into idxpart values (0, 'zero'), (42, 'life'), (2 ^ 16, 'sixteen'); insert into idxpart -select - 2 ^ g, - format('two to power of %s', g) -from - generate_series(15, 17) as g; +select 2 ^ g, format('two to power of %s', g) from generate_series(15, 17) as g; insert into idxpart values (16, 'sixteen'); insert into idxpart (b, a) values ('one', 142857), ('two', 285714); insert into idxpart -select - a * 2, - b || b -from - idxpart -where - a between 2 ^ 16 and 2 ^ 19; +select a * 2, b || b from idxpart where a between 2 ^ 16 and 2 ^ 19; insert into idxpart values (572814, 'five'); @@ -1989,19 +1827,19 @@ create table idxpart1 partition of idxpart for values from (0) to (100000); set enable_seqscan = off; -create index "idxpart_brin" on idxpart using brin (b); +create index idxpart_brin on idxpart using brin (b); select * from idxpart where b = 'abcd'; drop index idxpart_brin; -create index "idxpart_spgist" on idxpart using spgist (b); +create index idxpart_spgist on idxpart using spgist (b); select * from idxpart where b = 'abcd'; drop index idxpart_spgist; -create index "idxpart_gin" on idxpart using gin (c); +create index idxpart_gin on idxpart using gin (c); select * from idxpart where c @> array[42]; @@ -2063,10 +1901,9 @@ create table idxpart32 partition of idxpart3 for values from (1200) to (1400); alter table idxpart attach partition - idxpart3 - for values from (1000) to (2000); + idxpart3 for values from (1000) to (2000); -create schema "regress_indexing"; +create schema regress_indexing; set search_path to regress_indexing; @@ -2115,7 +1952,7 @@ create table covidxpart ( a int, b int ) -partition by LIST(a); +partition by list(a); create unique index on covidxpart using btree (a) include (b); @@ -2164,7 +2001,7 @@ insert into covidxpart values (4, 1); create unique index on covidxpart using btree (b) include (a); create table parted_pk_detach_test (a int primary key) -partition by LIST(a); +partition by list(a); create table parted_pk_detach_test1 partition of parted_pk_detach_test @@ -2183,7 +2020,7 @@ alter table parted_pk_detach_test1 drop table parted_pk_detach_test, parted_pk_detach_test1; create table parted_uniq_detach_test (a int unique) -partition by LIST(a); +partition by list(a); create table parted_uniq_detach_test1 partition of parted_uniq_detach_test @@ -2206,17 +2043,17 @@ create table parted_index_col_drop ( b int, c int ) -partition by LIST(a); +partition by list(a); create table parted_index_col_drop1 partition of parted_index_col_drop for values in (1) -partition by LIST(a); +partition by list(a); create table parted_index_col_drop2 partition of parted_index_col_drop for values in (2) -partition by LIST(a); +partition by list(a); create table parted_index_col_drop11 partition of parted_index_col_drop1 @@ -2236,7 +2073,7 @@ drop table parted_index_col_drop; create table parted_inval_tab (a int) partition by range(a); -create index "parted_inval_idx" on parted_inval_tab using btree (a); +create index parted_inval_idx on parted_inval_tab using btree (a); create table parted_inval_tab_1 (a int) partition by range(a); @@ -2249,12 +2086,11 @@ create table parted_inval_tab_1_2 partition of parted_inval_tab_1 for values from (10) to (20); -create index "parted_inval_ixd_1" on only parted_inval_tab_1 using btree (a); +create index parted_inval_ixd_1 on only parted_inval_tab_1 using btree (a); alter table parted_inval_tab attach partition - parted_inval_tab_1 - for values from (1) to (100); + parted_inval_tab_1 for values from (1) to (100); select cast(indexrelid as regclass), @@ -2267,10 +2103,8 @@ from pg_inherits as inh on idx.indexrelid = inh.inhrelid where - cast(cast(indexrelid as regclass) - as text) like 'parted_inval%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; + cast(cast(indexrelid as regclass) as text) like 'parted_inval%' +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table parted_inval_tab; @@ -2300,15 +2134,11 @@ for values from (5) to (10); insert into parted_isvalid_tab_11 values (1, 0); -create index -concurrently "parted_isvalid_idx_11" -on parted_isvalid_tab_11 -using btree -( - (a / b) -); +create index concurrently parted_isvalid_idx_11 + on parted_isvalid_tab_11 + using btree ((a / b)); -create index "parted_isvalid_idx" on parted_isvalid_tab using btree ((a / b)); +create index parted_isvalid_idx on parted_isvalid_tab using btree ((a / b)); select cast(indexrelid as regclass), @@ -2321,10 +2151,8 @@ from pg_inherits as inh on idx.indexrelid = inh.inhrelid where - cast(cast(indexrelid as regclass) - as text) like 'parted_isvalid%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; + cast(cast(indexrelid as regclass) as text) like 'parted_isvalid%' +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table parted_isvalid_tab; @@ -2342,31 +2170,18 @@ create table parted_replica_tab_11 partition of parted_replica_tab_1 for values from (1) to (5); -create unique index "parted_replica_idx" -on only parted_replica_tab -using btree -( +create unique index parted_replica_idx on only parted_replica_tab using btree ( id ); -create unique -index "parted_replica_idx_1" -on only parted_replica_tab_1 -using btree -( - id -); +create unique index parted_replica_idx_1 + on only parted_replica_tab_1 + using btree (id); alter table only parted_replica_tab_1 - replica identity - using index - parted_replica_idx_1; + replica identity using index parted_replica_idx_1; -create unique -index "parted_replica_idx_11" -on parted_replica_tab_11 -using btree -( +create unique index parted_replica_idx_11 on parted_replica_tab_11 using btree ( id ); @@ -2382,10 +2197,8 @@ from pg_inherits as inh on idx.indexrelid = inh.inhrelid where - cast(cast(indexrelid as regclass) - as text) like 'parted_replica%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; + cast(cast(indexrelid as regclass) as text) like 'parted_replica%' +order by cast(cast(indexrelid as regclass) as text) collate "C"; alter index parted_replica_idx attach partition @@ -2403,19 +2216,15 @@ from pg_inherits as inh on idx.indexrelid = inh.inhrelid where - cast(cast(indexrelid as regclass) - as text) like 'parted_replica%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; + cast(cast(indexrelid as regclass) as text) like 'parted_replica%' +order by cast(cast(indexrelid as regclass) as text) collate "C"; alter index parted_replica_idx_1 attach partition parted_replica_idx_11; alter table only parted_replica_tab_1 - replica identity - using index - parted_replica_idx_1; + replica identity using index parted_replica_idx_1; commit; @@ -2431,43 +2240,32 @@ from pg_inherits as inh on idx.indexrelid = inh.inhrelid where - cast(cast(indexrelid as regclass) - as text) like 'parted_replica%' -order by cast(cast(indexrelid as regclass) - as text) collate "C"; + cast(cast(indexrelid as regclass) as text) like 'parted_replica%' +order by cast(cast(indexrelid as regclass) as text) collate "C"; drop table parted_replica_tab; create table test_pg_index_toast_table (a int); create or replace function test_pg_index_toast_func(a int, b int[]) -returns boolean +returns bool language sql immutable -as $function$ -select true -$function$; +as $$ select true $$; select array_agg(n) as b from generate_series(1, 10000) as n; -create index -concurrently "test_pg_index_toast_index" -on test_pg_index_toast_table -using btree -( - (test_pg_index_toast_func(a, 'b')) -); +create index concurrently test_pg_index_toast_index + on test_pg_index_toast_table + using btree ((test_pg_index_toast_func(a, 'b'))); -reindex (CONCURRENTLY) index test_pg_index_toast_index; +reindex (concurrently) index test_pg_index_toast_index; drop index concurrently test_pg_index_toast_index; -create index "test_pg_index_toast_index" -on test_pg_index_toast_table -using btree -( - (test_pg_index_toast_func(a, 'b')) -); +create index test_pg_index_toast_index + on test_pg_index_toast_table + using btree ((test_pg_index_toast_func(a, 'b'))); reindex index test_pg_index_toast_index; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_100.snap index 096a67cd9..877331f8a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_100.snap @@ -6,9 +6,7 @@ create function make_tuple_indirect(record) returns record language c strict -as $function$ -regresslib -$function$; +as 'regresslib'; set default_toast_compression = pglz; @@ -20,87 +18,50 @@ create table indtoasttest ( ); insert into indtoasttest (descr, f1, f2) -values - ( - 'two-compressed', - repeat('1234567890', 1000), - repeat('1234567890', 1000) - ); +values ('two-compressed', repeat('1234567890', 1000), repeat('1234567890', 1000)); insert into indtoasttest (descr, f1, f2) -values - ( - 'two-toasted', - repeat('1234567890', 30000), - repeat('1234567890', 50000) - ); +values ('two-toasted', repeat('1234567890', 30000), repeat('1234567890', 50000)); insert into indtoasttest (descr, f1, f2) -values - ( - 'one-compressed,one-null', - null, - repeat('1234567890', 1000) - ); +values ('one-compressed,one-null', null, repeat('1234567890', 1000)); insert into indtoasttest (descr, f1, f2) -values - ( - 'one-toasted,one-null', - null, - repeat('1234567890', 50000) - ); - -select - descr, - SUBSTRING(cast(make_tuple_indirect(indtoasttest) as text) - from 1 - for 200) -from - indtoasttest; +values ('one-toasted,one-null', null, repeat('1234567890', 50000)); -update indtoasttest -set cnt = cnt + 1 -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +select descr, substring(cast(make_tuple_indirect(indtoasttest) as text), 1, 200) from indtoasttest; + +update indtoasttest set cnt = cnt + 1 returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = f1 -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = f1 || '' -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = '-' || f1 || '-' -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); -select SUBSTRING(cast(indtoasttest as text) from 1 for 200) from indtoasttest; +select substring(cast(indtoasttest as text), 1, 200) from indtoasttest; -vacuum (FREEZE) indtoasttest; +vacuum (freeze) indtoasttest; -select SUBSTRING(cast(indtoasttest as text) from 1 for 200) from indtoasttest; +select substring(cast(indtoasttest as text), 1, 200) from indtoasttest; create function update_using_indirect() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW := make_tuple_indirect(NEW); RETURN NEW; -END -$function$; +END$$; create trigger indtoasttest_update_indirect before insert or update @@ -108,46 +69,31 @@ on indtoasttest for each row execute function update_using_indirect(); -update indtoasttest -set cnt = cnt + 1 -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +update indtoasttest set cnt = cnt + 1 returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = f1 -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = f1 || '' -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = '-' || f1 || '-' -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); insert into indtoasttest (descr, f1, f2) -values - ( - 'one-toasted,one-null, via indirect', - repeat('1234567890', 30000), - null - ); +values ('one-toasted,one-null, via indirect', repeat('1234567890', 30000), null); -select SUBSTRING(cast(indtoasttest as text) from 1 for 200) from indtoasttest; +select substring(cast(indtoasttest as text), 1, 200) from indtoasttest; -vacuum (FREEZE) indtoasttest; +vacuum (freeze) indtoasttest; -select SUBSTRING(cast(indtoasttest as text) from 1 for 200) from indtoasttest; +select substring(cast(indtoasttest as text), 1, 200) from indtoasttest; drop table indtoasttest; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_80.snap index f01c106bd..483be6768 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_80.snap @@ -6,9 +6,7 @@ create function make_tuple_indirect(record) returns record language c strict -as $function$ -regresslib -$function$; +as 'regresslib'; set default_toast_compression = pglz; @@ -21,87 +19,57 @@ create table indtoasttest ( insert into indtoasttest (descr, f1, f2) values - ( - 'two-compressed', - repeat('1234567890', 1000), - repeat('1234567890', 1000) - ); + ('two-compressed', repeat('1234567890', 1000), repeat('1234567890', 1000)); insert into indtoasttest (descr, f1, f2) values - ( - 'two-toasted', - repeat('1234567890', 30000), - repeat('1234567890', 50000) - ); + ('two-toasted', repeat('1234567890', 30000), repeat('1234567890', 50000)); insert into indtoasttest (descr, f1, f2) -values - ( - 'one-compressed,one-null', - null, - repeat('1234567890', 1000) - ); +values ('one-compressed,one-null', null, repeat('1234567890', 1000)); insert into indtoasttest (descr, f1, f2) -values - ( - 'one-toasted,one-null', - null, - repeat('1234567890', 50000) - ); +values ('one-toasted,one-null', null, repeat('1234567890', 50000)); select descr, - SUBSTRING(cast(make_tuple_indirect(indtoasttest) - as text) - from 1 - for 200) + substring(cast(make_tuple_indirect(indtoasttest) as text), 1, 200) from indtoasttest; update indtoasttest set cnt = cnt + 1 -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = f1 -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = f1 || '' -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = '-' || f1 || '-' -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); -select SUBSTRING(cast(indtoasttest as text) from 1 for 200) from indtoasttest; +select substring(cast(indtoasttest as text), 1, 200) from indtoasttest; -vacuum (FREEZE) indtoasttest; +vacuum (freeze) indtoasttest; -select SUBSTRING(cast(indtoasttest as text) from 1 for 200) from indtoasttest; +select substring(cast(indtoasttest as text), 1, 200) from indtoasttest; create function update_using_indirect() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW := make_tuple_indirect(NEW); RETURN NEW; -END -$function$; +END$$; create trigger indtoasttest_update_indirect before insert or update @@ -111,44 +79,32 @@ execute function update_using_indirect(); update indtoasttest set cnt = cnt + 1 -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = f1 -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = f1 || '' -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); update indtoasttest set cnt = cnt + 1, f1 = '-' || f1 || '-' -returning SUBSTRING(cast(indtoasttest as text) -from 1 -for 200); +returning substring(cast(indtoasttest as text), 1, 200); insert into indtoasttest (descr, f1, f2) values - ( - 'one-toasted,one-null, via indirect', - repeat('1234567890', 30000), - null - ); + ('one-toasted,one-null, via indirect', repeat('1234567890', 30000), null); -select SUBSTRING(cast(indtoasttest as text) from 1 for 200) from indtoasttest; +select substring(cast(indtoasttest as text), 1, 200) from indtoasttest; -vacuum (FREEZE) indtoasttest; +vacuum (freeze) indtoasttest; -select SUBSTRING(cast(indtoasttest as text) from 1 for 200) from indtoasttest; +select substring(cast(indtoasttest as text), 1, 200) from indtoasttest; drop table indtoasttest; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inet_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inet_100.snap index fdc5cc913..c97f22d63 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inet_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inet_100.snap @@ -115,27 +115,23 @@ select from inet_tbl; -select MAX(i) as max, MIN(i) as min from inet_tbl; +select max(i) as max, min(i) as min from inet_tbl; -select MAX(c) as max, MIN(c) as min from inet_tbl; +select max(c) as max, min(c) as min from inet_tbl; select c as cidr, - set_masklen(cidr(text(c)), 24) - as "set_masklen(cidr)", + set_masklen(cidr(text(c)), 24) as "set_masklen(cidr)", i as inet, - set_masklen(inet(text(i)), 24) - as "set_masklen(inet)" + set_masklen(inet(text(i)), 24) as "set_masklen(inet)" from inet_tbl; select c as cidr, - set_masklen(cidr(text(c)), -1) - as "set_masklen(cidr)", + set_masklen(cidr(text(c)), -1) as "set_masklen(cidr)", i as inet, - set_masklen(inet(text(i)), -1) - as "set_masklen(inet)" + set_masklen(inet(text(i)), -1) as "set_masklen(inet)" from inet_tbl; @@ -143,7 +139,7 @@ select set_masklen(inet(text(i)), 33) from inet_tbl; select set_masklen(cidr(text(c)), 33) from inet_tbl; -create index "inet_idx1" on inet_tbl using btree (i); +create index inet_idx1 on inet_tbl using btree (i); set enable_seqscan = off; @@ -167,7 +163,7 @@ set enable_seqscan = 'on'; drop index inet_idx1; -create index "inet_idx2" on inet_tbl using gist (i inet_ops); +create index inet_idx2 on inet_tbl using gist (i inet_ops); set enable_seqscan = off; @@ -201,7 +197,7 @@ set enable_seqscan = 'on'; drop index inet_idx2; -create index "inet_idx3" on inet_tbl using spgist (i); +create index inet_idx3 on inet_tbl using spgist (i); set enable_seqscan = off; @@ -335,129 +331,48 @@ from (cast('255.255.255.253/32' as inet)), (cast('255.255.255.252/32' as inet)), (cast('255.3.0.0/0' as inet)), - ( - cast('0000:0000:0000:0000:0000:0000:0000:0000/0' - as inet) - ), - ( - cast('0000:0000:0000:0000:0000:0000:0000:0000/128' - as inet) - ), - ( - cast('0000:0000:0000:0000:0000:0000:0000:0001/128' - as inet) - ), + (cast('0000:0000:0000:0000:0000:0000:0000:0000/0' as inet)), + (cast('0000:0000:0000:0000:0000:0000:0000:0000/128' as inet)), + (cast('0000:0000:0000:0000:0000:0000:0000:0001/128' as inet)), (cast('10:23::f1/64' as inet)), (cast('10:23::f1/65' as inet)), (cast('10:23::ffff' as inet)), (cast('127::1' as inet)), (cast('127::2' as inet)), - ( - cast('8000:0000:0000:0000:0000:0000:0000:0000/1' - as inet) - ), + (cast('8000:0000:0000:0000:0000:0000:0000:0000/1' as inet)), (cast('::1:ffff:ffff:ffff:ffff/128' as inet)), (cast('::2:ffff:ffff:ffff:ffff/128' as inet)), (cast('::4:3:2:0/24' as inet)), (cast('::4:3:2:1/24' as inet)), (cast('::4:3:2:2/24' as inet)), - ( - cast('ffff:83e7:f118:57dc:6093:6d92:689d:58cf/70' - as inet) - ), - ( - cast('ffff:84b0:4775:536e:c3ed:7116:a6d6:34f0/44' - as inet) - ), - ( - cast('ffff:8566:f84:5867:47f1:7867:d2ba:8a1a/69' - as inet) - ), - ( - cast('ffff:8883:f028:7d2:4d68:d510:7d6b:ac43/73' - as inet) - ), - ( - cast('ffff:8ae8:7c14:65b3:196:8e4a:89ae:fb30/89' - as inet) - ), - ( - cast('ffff:8dd0:646:694c:7c16:7e35:6a26:171/104' - as inet) - ), - ( - cast('ffff:8eef:cbf:700:eda3:ae32:f4b4:318b/121' - as inet) - ), - ( - cast('ffff:90e7:e744:664:a93:8efe:1f25:7663/122' - as inet) - ), - ( - cast('ffff:9597:c69c:8b24:57a:8639:ec78:6026/111' - as inet) - ), - ( - cast('ffff:9e86:79ea:f16e:df31:8e4d:7783:532e/88' - as inet) - ), - ( - cast('ffff:a0c7:82d3:24de:f762:6e1f:316d:3fb2/23' - as inet) - ), - ( - cast('ffff:fffa:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:fffb:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:fffc:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:fffd:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:fffe:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffa:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffb:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffc:ffff:ffff:ffff:ffff/0' - as inet) - ), + (cast('ffff:83e7:f118:57dc:6093:6d92:689d:58cf/70' as inet)), + (cast('ffff:84b0:4775:536e:c3ed:7116:a6d6:34f0/44' as inet)), + (cast('ffff:8566:f84:5867:47f1:7867:d2ba:8a1a/69' as inet)), + (cast('ffff:8883:f028:7d2:4d68:d510:7d6b:ac43/73' as inet)), + (cast('ffff:8ae8:7c14:65b3:196:8e4a:89ae:fb30/89' as inet)), + (cast('ffff:8dd0:646:694c:7c16:7e35:6a26:171/104' as inet)), + (cast('ffff:8eef:cbf:700:eda3:ae32:f4b4:318b/121' as inet)), + (cast('ffff:90e7:e744:664:a93:8efe:1f25:7663/122' as inet)), + (cast('ffff:9597:c69c:8b24:57a:8639:ec78:6026/111' as inet)), + (cast('ffff:9e86:79ea:f16e:df31:8e4d:7783:532e/88' as inet)), + (cast('ffff:a0c7:82d3:24de:f762:6e1f:316d:3fb2/23' as inet)), + (cast('ffff:fffa:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:fffb:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:fffc:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:fffd:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:fffe:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:fffa:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:fffb:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:fffc:ffff:ffff:ffff:ffff/0' as inet)), (cast('ffff:ffff:ffff:fffd::/128' as inet)), - ( - cast('ffff:ffff:ffff:fffd:ffff:ffff:ffff:ffff/0' - as inet) - ), + (cast('ffff:ffff:ffff:fffd:ffff:ffff:ffff:ffff/0' as inet)), (cast('ffff:ffff:ffff:fffe::/128' as inet)), - ( - cast('ffff:ffff:ffff:fffe:ffff:ffff:ffff:ffff/0' - as inet) - ), + (cast('ffff:ffff:ffff:fffe:ffff:ffff:ffff:ffff/0' as inet)), (cast('ffff:ffff:ffff:ffff:4:3:2:0/24' as inet)), (cast('ffff:ffff:ffff:ffff:4:3:2:1/24' as inet)), (cast('ffff:ffff:ffff:ffff:4:3:2:2/24' as inet)), - ( - cast('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128' - as inet) - ) + (cast('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128' as inet)) ) as i (a) order by a; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inet_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inet_80.snap index 5d79be28f..965238f26 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inet_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inet_80.snap @@ -51,11 +51,7 @@ insert into inet_tbl (c, i) values ('1234::1234::1234', '::1.2.3.4'); insert into inet_tbl (c, i) values (cidr('192.168.1.2/30'), '192.168.1.226'); insert into inet_tbl (c, i) -values - ( - cidr('ffff:ffff:ffff:ffff::/24'), - '::192.168.1.226' - ); +values (cidr('ffff:ffff:ffff:ffff::/24'), '::192.168.1.226'); select c as cidr, i as inet from inet_tbl; @@ -126,27 +122,23 @@ select from inet_tbl; -select MAX(i) as max, MIN(i) as min from inet_tbl; +select max(i) as max, min(i) as min from inet_tbl; -select MAX(c) as max, MIN(c) as min from inet_tbl; +select max(c) as max, min(c) as min from inet_tbl; select c as cidr, - set_masklen(cidr(text(c)), 24) - as "set_masklen(cidr)", + set_masklen(cidr(text(c)), 24) as "set_masklen(cidr)", i as inet, - set_masklen(inet(text(i)), 24) - as "set_masklen(inet)" + set_masklen(inet(text(i)), 24) as "set_masklen(inet)" from inet_tbl; select c as cidr, - set_masklen(cidr(text(c)), -1) - as "set_masklen(cidr)", + set_masklen(cidr(text(c)), -1) as "set_masklen(cidr)", i as inet, - set_masklen(inet(text(i)), -1) - as "set_masklen(inet)" + set_masklen(inet(text(i)), -1) as "set_masklen(inet)" from inet_tbl; @@ -154,7 +146,7 @@ select set_masklen(inet(text(i)), 33) from inet_tbl; select set_masklen(cidr(text(c)), 33) from inet_tbl; -create index "inet_idx1" on inet_tbl using btree (i); +create index inet_idx1 on inet_tbl using btree (i); set enable_seqscan = off; @@ -178,7 +170,7 @@ set enable_seqscan = 'on'; drop index inet_idx1; -create index "inet_idx2" on inet_tbl using gist (i inet_ops); +create index inet_idx2 on inet_tbl using gist (i inet_ops); set enable_seqscan = off; @@ -212,7 +204,7 @@ set enable_seqscan = 'on'; drop index inet_idx2; -create index "inet_idx3" on inet_tbl using spgist (i); +create index inet_idx3 on inet_tbl using spgist (i); set enable_seqscan = off; @@ -346,150 +338,48 @@ from (cast('255.255.255.253/32' as inet)), (cast('255.255.255.252/32' as inet)), (cast('255.3.0.0/0' as inet)), - ( - cast('0000:0000:0000:0000:0000:0000:0000:0000/0' - as inet) - ), - ( - cast('0000:0000:0000:0000:0000:0000:0000:0000/128' - as inet) - ), - ( - cast('0000:0000:0000:0000:0000:0000:0000:0001/128' - as inet) - ), + (cast('0000:0000:0000:0000:0000:0000:0000:0000/0' as inet)), + (cast('0000:0000:0000:0000:0000:0000:0000:0000/128' as inet)), + (cast('0000:0000:0000:0000:0000:0000:0000:0001/128' as inet)), (cast('10:23::f1/64' as inet)), (cast('10:23::f1/65' as inet)), (cast('10:23::ffff' as inet)), (cast('127::1' as inet)), (cast('127::2' as inet)), - ( - cast('8000:0000:0000:0000:0000:0000:0000:0000/1' - as inet) - ), - ( - cast('::1:ffff:ffff:ffff:ffff/128' - as inet) - ), - ( - cast('::2:ffff:ffff:ffff:ffff/128' - as inet) - ), + (cast('8000:0000:0000:0000:0000:0000:0000:0000/1' as inet)), + (cast('::1:ffff:ffff:ffff:ffff/128' as inet)), + (cast('::2:ffff:ffff:ffff:ffff/128' as inet)), (cast('::4:3:2:0/24' as inet)), (cast('::4:3:2:1/24' as inet)), (cast('::4:3:2:2/24' as inet)), - ( - cast('ffff:83e7:f118:57dc:6093:6d92:689d:58cf/70' - as inet) - ), - ( - cast('ffff:84b0:4775:536e:c3ed:7116:a6d6:34f0/44' - as inet) - ), - ( - cast('ffff:8566:f84:5867:47f1:7867:d2ba:8a1a/69' - as inet) - ), - ( - cast('ffff:8883:f028:7d2:4d68:d510:7d6b:ac43/73' - as inet) - ), - ( - cast('ffff:8ae8:7c14:65b3:196:8e4a:89ae:fb30/89' - as inet) - ), - ( - cast('ffff:8dd0:646:694c:7c16:7e35:6a26:171/104' - as inet) - ), - ( - cast('ffff:8eef:cbf:700:eda3:ae32:f4b4:318b/121' - as inet) - ), - ( - cast('ffff:90e7:e744:664:a93:8efe:1f25:7663/122' - as inet) - ), - ( - cast('ffff:9597:c69c:8b24:57a:8639:ec78:6026/111' - as inet) - ), - ( - cast('ffff:9e86:79ea:f16e:df31:8e4d:7783:532e/88' - as inet) - ), - ( - cast('ffff:a0c7:82d3:24de:f762:6e1f:316d:3fb2/23' - as inet) - ), - ( - cast('ffff:fffa:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:fffb:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:fffc:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:fffd:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:fffe:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffa:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffb:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffc:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffd::/128' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffd:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffe::/128' - as inet) - ), - ( - cast('ffff:ffff:ffff:fffe:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:ffff:4:3:2:0/24' - as inet) - ), - ( - cast('ffff:ffff:ffff:ffff:4:3:2:1/24' - as inet) - ), - ( - cast('ffff:ffff:ffff:ffff:4:3:2:2/24' - as inet) - ), - ( - cast('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0' - as inet) - ), - ( - cast('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128' - as inet) - ) + (cast('ffff:83e7:f118:57dc:6093:6d92:689d:58cf/70' as inet)), + (cast('ffff:84b0:4775:536e:c3ed:7116:a6d6:34f0/44' as inet)), + (cast('ffff:8566:f84:5867:47f1:7867:d2ba:8a1a/69' as inet)), + (cast('ffff:8883:f028:7d2:4d68:d510:7d6b:ac43/73' as inet)), + (cast('ffff:8ae8:7c14:65b3:196:8e4a:89ae:fb30/89' as inet)), + (cast('ffff:8dd0:646:694c:7c16:7e35:6a26:171/104' as inet)), + (cast('ffff:8eef:cbf:700:eda3:ae32:f4b4:318b/121' as inet)), + (cast('ffff:90e7:e744:664:a93:8efe:1f25:7663/122' as inet)), + (cast('ffff:9597:c69c:8b24:57a:8639:ec78:6026/111' as inet)), + (cast('ffff:9e86:79ea:f16e:df31:8e4d:7783:532e/88' as inet)), + (cast('ffff:a0c7:82d3:24de:f762:6e1f:316d:3fb2/23' as inet)), + (cast('ffff:fffa:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:fffb:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:fffc:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:fffd:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:fffe:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:fffa:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:fffb:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:fffc:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:fffd::/128' as inet)), + (cast('ffff:ffff:ffff:fffd:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:fffe::/128' as inet)), + (cast('ffff:ffff:ffff:fffe:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:ffff:4:3:2:0/24' as inet)), + (cast('ffff:ffff:ffff:ffff:4:3:2:1/24' as inet)), + (cast('ffff:ffff:ffff:ffff:4:3:2:2/24' as inet)), + (cast('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0' as inet)), + (cast('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128' as inet)) ) as i (a) order by a; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_100.snap index 785e68087..645f946c4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_100.snap @@ -5,9 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/infinite_recurse.sql create function infinite_recurse() returns int language sql -as $function$ -select infinite_recurse() -$function$; +as 'select infinite_recurse()'; select version() ~ 'powerpc64[^,]*-linux-gnu' as skip_test; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_80.snap index 785e68087..645f946c4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_80.snap @@ -5,9 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/infinite_recurse.sql create function infinite_recurse() returns int language sql -as $function$ -select infinite_recurse() -$function$; +as 'select infinite_recurse()'; select version() ~ 'powerpc64[^,]*-linux-gnu' as skip_test; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_100.snap index 95e19f3a8..e10dd07cf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_100.snap @@ -11,9 +11,7 @@ create table c (cc text) inherits (a); create table d (dd text) -inherits (b, -c, -a); +inherits (b, c, a); insert into a (aa) values ('aaa'); @@ -194,9 +192,7 @@ create index on some_tab_child using btree (f1, f2); create function some_tab_stmt_trig_func() returns trigger language plpgsql -as $function$ -begin raise notice 'updating some_tab'; return NULL; end; -$function$; +as $$begin raise notice 'updating some_tab'; return NULL; end;$$; create trigger some_tab_stmt_trig before update @@ -280,12 +276,7 @@ select cast(cast(tableoid as regclass) as text) as relname, bar.* from bar order update bar set f2 = f2 + 100 -from ( - select f1 from foo - union all - select f1 + 3 from foo -) -as ss +from (select f1 from foo union all select f1 + 3 from foo) as ss where bar.f1 = ss.f1; @@ -304,7 +295,7 @@ create table parted_tab ( a int, b char(1) ) -partition by LIST(a); +partition by list(a); create table parted_tab_part1 partition of parted_tab for values in (1); @@ -316,18 +307,12 @@ insert into parted_tab values (1, 'a'), (2, 'a'), (3, 'a'); update parted_tab set b = 'b' -from ( - select a from some_tab - union all - select a + 1 from some_tab -) -as ss (a) +from (select a from some_tab union all select a + 1 from some_tab) as ss (a) where parted_tab.a = ss.a; select - cast(cast(tableoid as regclass) as text) - as relname, + cast(cast(tableoid as regclass) as text) as relname, parted_tab.* from parted_tab @@ -340,18 +325,12 @@ insert into parted_tab values (1, 'a'), (2, 'a'), (3, 'a'); update parted_tab set b = 'b' -from ( - select 0 from parted_tab - union all - select 1 from parted_tab -) -as ss (a) +from (select 0 from parted_tab union all select 1 from parted_tab) as ss (a) where parted_tab.a = ss.a; select - cast(cast(tableoid as regclass) as text) - as relname, + cast(cast(tableoid as regclass) as text) as relname, parted_tab.* from parted_tab @@ -367,11 +346,11 @@ create table mlparted_tab ( b char(1), c text ) -partition by LIST(a); +partition by list(a); create table mlparted_tab_part1 partition of mlparted_tab for values in (1); -create table mlparted_tab_part2 partition of mlparted_tab for values in (2) partition by LIST(b); +create table mlparted_tab_part2 partition of mlparted_tab for values in (2) partition by list(b); create table mlparted_tab_part3 partition of mlparted_tab for values in (3); @@ -383,18 +362,12 @@ insert into mlparted_tab values (1, 'a'), (2, 'a'), (2, 'b'), (3, 'a'); update mlparted_tab as mlp set c = 'xxx' -from ( - select a from some_tab - union all - select a + 1 from some_tab -) -as ss (a) +from (select a from some_tab union all select a + 1 from some_tab) as ss (a) where (mlp.a = ss.a and mlp.b = 'b') or mlp.a = 3; select - cast(cast(tableoid as regclass) as text) - as relname, + cast(cast(tableoid as regclass) as text) as relname, mlparted_tab.* from mlparted_tab @@ -405,23 +378,20 @@ drop table mlparted_tab; drop table some_tab cascade; -create table firstparent (tomorrow date default (cast(NOW() as date) + 1)); +create table firstparent (tomorrow date default (cast(now() as date) + 1)); -create table secondparent (tomorrow date default (cast(NOW() as date) + 1)); +create table secondparent (tomorrow date default (cast(now() as date) + 1)); create table jointchild () -inherits (firstparent, -secondparent); +inherits (firstparent, secondparent); -create table thirdparent (tomorrow date default (cast(NOW() as date) - 1)); +create table thirdparent (tomorrow date default (cast(now() as date) - 1)); create table otherchild () -inherits (firstparent, -thirdparent); +inherits (firstparent, thirdparent); -create table otherchild (tomorrow date default NOW()) -inherits (firstparent, -thirdparent); +create table otherchild (tomorrow date default now()) +inherits (firstparent, thirdparent); drop table firstparent, secondparent, jointchild, thirdparent, otherchild; @@ -443,8 +413,7 @@ create temporary table parent2 ( ); create temporary table childtab (f4 int) -inherits (parent1, -parent2); +inherits (parent1, parent2); alter table parent1 alter column f1 type bigint; @@ -455,10 +424,10 @@ alter table parent1 create table p1 (ff1 int); alter table p1 - add constraint "p1chk" check (ff1 > 0) no inherit; + add constraint p1chk check (ff1 > 0) no inherit; alter table p1 - add constraint "p2chk" check (ff1 > 10); + add constraint p2chk check (ff1 > 10); select pc.relname, @@ -468,10 +437,7 @@ select pgc.coninhcount, pgc.connoinherit from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname = 'p1' order by 1, @@ -480,7 +446,7 @@ order by 1, create table c1 () inherits (p1); -create table c2 (constraint "p2chk" check (ff1 > 10) no inherit) +create table c2 (constraint p2chk check (ff1 > 10) no inherit) inherits (p1); drop table p1 cascade; @@ -519,13 +485,10 @@ create table p2 (f1 text); create function p2text(p2) returns text language sql -as $function$ -select $1.f1 -$function$; +as 'select $1.f1'; create table c1 (f3 int) -inherits (p1, -p2); +inherits (p1, p2); insert into c1 values (123456789, 'hi', 42); @@ -542,7 +505,7 @@ drop table p1; create table ac (aa text); alter table ac - add constraint "ac_check" check (aa is not null); + add constraint ac_check check (aa is not null); create table bc (bb text) inherits (ac); @@ -555,10 +518,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -582,10 +542,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -602,10 +559,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -629,17 +583,14 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, 2; alter table ac - add constraint "ac_check" check (aa is not null); + add constraint ac_check check (aa is not null); alter table bc no inherit ac; @@ -652,10 +603,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -672,10 +620,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -692,10 +637,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -705,11 +647,11 @@ drop table bc; drop table ac; -create table ac (a int constraint "check_a" check (a <> 0)); +create table ac (a int constraint check_a check (a <> 0)); create table bc ( - a int constraint "check_a" check (a <> 0), - b int constraint "check_b" check (b <> 0) + a int constraint check_a check (a <> 0), + b int constraint check_b check (b <> 0) ) inherits (ac); @@ -721,10 +663,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -734,13 +673,12 @@ drop table bc; drop table ac; -create table ac (a int constraint "check_a" check (a <> 0)); +create table ac (a int constraint check_a check (a <> 0)); -create table bc (b int constraint "check_b" check (b <> 0)); +create table bc (b int constraint check_b check (b <> 0)); -create table cc (c int constraint "check_c" check (c <> 0)) -inherits (ac, -bc); +create table cc (c int constraint check_c check (c <> 0)) +inherits (ac, bc); select pc.relname, @@ -750,10 +688,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc', 'cc') order by 1, @@ -770,10 +705,7 @@ select pgc.coninhcount, pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc', 'cc') order by 1, @@ -790,13 +722,12 @@ create table p1 (f1 int); create table p2 (f2 int); create table c1 (f3 int) -inherits (p1, -p2); +inherits (p1, p2); insert into c1 values (1, -1, 2); alter table p2 - add constraint "cc" check (f2 > 0); + add constraint cc check (f2 > 0); alter table p2 add check (f2 > 0); @@ -811,12 +742,10 @@ alter table p2 insert into c1 values (1, -1, 2); create table c2 (f3 int) -inherits (p1, -p2); +inherits (p1, p2); create table c3 (f4 int) -inherits (c1, -c2); +inherits (c1, c2); drop table p1 cascade; @@ -834,8 +763,7 @@ alter table pp1 add column a1 int check (a1 > 0); create table cc2 (f4 double precision) -inherits (pp1, -cc1); +inherits (pp1, cc1); alter table pp1 add column a2 int check (a2 > 0); @@ -853,8 +781,7 @@ create table inhs1 ( ); create table inhts (d int) -inherits (inht1, -inhs1); +inherits (inht1, inhs1); alter table inht1 rename column a to aa; @@ -875,9 +802,7 @@ create table inhtc () inherits (inhtb); create table inhtd () -inherits (inhta, -inhtb, -inhtc); +inherits (inhta, inhtb, inhtc); alter table inhta add column i int, @@ -892,14 +817,12 @@ create table inht3 (y int) inherits (inht1); create table inht4 (z int) -inherits (inht2, -inht3); +inherits (inht2, inht3); alter table inht1 rename column aa to aaa; create table inhts (d int) -inherits (inht2, -inhs1); +inherits (inht2, inhs1); alter table inht1 rename column aaa to aaaa; @@ -910,13 +833,7 @@ r as ( select cast('inht1' as regclass) as inhrelid union all - select - c.inhrelid - from - pg_inherits as c, - r - where - r.inhrelid = c.inhparent + select c.inhrelid from pg_inherits as c, r where r.inhrelid = c.inhparent ) select cast(a.attrelid as regclass), @@ -927,7 +844,7 @@ from ( select inhrelid, - COUNT(*) as expected + count(*) as expected from pg_inherits where @@ -999,7 +916,7 @@ insert into inh_fk_1 values (1), (2), (3); create table inh_fk_2 ( x int primary key, - y int references inh_fk_1 on DELETE cascade + y int references inh_fk_1 on delete cascade ); insert into inh_fk_2 values (11, 1), (22, 2), (33, 3); @@ -1023,27 +940,25 @@ create table p1_c1 () inherits (p1); alter table p1 - add constraint "inh_check_constraint1" check (f1 > 0); + add constraint inh_check_constraint1 check (f1 > 0); alter table p1_c1 - add constraint "inh_check_constraint1" check (f1 > 0); + add constraint inh_check_constraint1 check (f1 > 0); alter table p1_c1 - add constraint "inh_check_constraint2" check (f1 < 10); + add constraint inh_check_constraint2 check (f1 < 10); alter table p1 - add constraint "inh_check_constraint2" check (f1 < 10); + add constraint inh_check_constraint2 check (f1 < 10); -create table p1_c2 (f1 int constraint "inh_check_constraint4" check (f1 < 10)) +create table p1_c2 (f1 int constraint inh_check_constraint4 check (f1 < 10)) inherits (p1); create table p1_c3 () -inherits (p1, -p1_c1); +inherits (p1, p1_c1); select - cast(cast(conrelid as regclass) as text) - as relname, + cast(cast(conrelid as regclass) as text) as relname, conname, conislocal, coninhcount, @@ -1068,9 +983,9 @@ alter table p1_c1 drop table p1, p1_c1; -create table p1 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p1 (f1 int constraint f1_pos check (f1 > 0)); -create table p1_c1 (f1 int constraint "f1_pos" check (f1 > 0)) +create table p1_c1 (f1 int constraint f1_pos check (f1 > 0)) inherits (p1); alter table p1_c1 @@ -1081,17 +996,15 @@ alter table p1 drop table p1 cascade; -create table p1 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p1 (f1 int constraint f1_pos check (f1 > 0)); -create table p2 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p2 (f1 int constraint f1_pos check (f1 > 0)); create table p1p2_c1 (f1 int) -inherits (p1, -p2); +inherits (p1, p2); -create table p1p2_c2 (f1 int constraint "f1_pos" check (f1 > 0)) -inherits (p1, -p2); +create table p1p2_c2 (f1 int constraint f1_pos check (f1 > 0)) +inherits (p1, p2); alter table p2 drop constraint f1_pos; @@ -1101,7 +1014,7 @@ alter table p1 drop table p1, p2 cascade; -create table p1 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p1 (f1 int constraint f1_pos check (f1 > 0)); create table p1_c1 () inherits (p1); @@ -1110,26 +1023,23 @@ create table p1_c2 () inherits (p1); create table p1_c1c2 () -inherits (p1_c1, -p1_c2); +inherits (p1_c1, p1_c2); alter table p1 drop constraint f1_pos; drop table p1 cascade; -create table p1 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p1 (f1 int constraint f1_pos check (f1 > 0)); create table p1_c1 () inherits (p1); -create table p1_c2 (constraint "f1_pos" check (f1 > 0)) +create table p1_c2 (constraint f1_pos check (f1 > 0)) inherits (p1); create table p1_c1c2 () -inherits (p1_c1, -p1_c2, -p1); +inherits (p1_c1, p1_c2, p1); alter table p1_c2 drop constraint f1_pos; @@ -1151,10 +1061,10 @@ create table invalid_check_con_child () inherits (invalid_check_con); alter table invalid_check_con_child - add constraint "inh_check_constraint" check (f1 > 0) not valid; + add constraint inh_check_constraint check (f1 > 0) not valid; alter table invalid_check_con - add constraint "inh_check_constraint" check (f1 > 0); + add constraint inh_check_constraint check (f1 > 0); alter table invalid_check_con_child drop constraint inh_check_constraint; @@ -1162,18 +1072,17 @@ alter table invalid_check_con_child insert into invalid_check_con values (0); alter table invalid_check_con_child - add constraint "inh_check_constraint" check (f1 > 0); + add constraint inh_check_constraint check (f1 > 0); alter table invalid_check_con - add constraint "inh_check_constraint" check (f1 > 0) not valid; + add constraint inh_check_constraint check (f1 > 0) not valid; insert into invalid_check_con values (0); insert into invalid_check_con_child values (0); select - cast(cast(conrelid as regclass) as text) - as relname, + cast(cast(conrelid as regclass) as text) as relname, conname, convalidated, conislocal, @@ -1198,11 +1107,11 @@ inherits (patest0); insert into patest2 select x, x from generate_series(0, 1000) as x; -create index "patest0i" on patest0 using btree (id); +create index patest0i on patest0 using btree (id); -create index "patest1i" on patest1 using btree (id); +create index patest1i on patest1 using btree (id); -create index "patest2i" on patest2 using btree (id); +create index patest2i on patest2 using btree (id); analyze patest0; @@ -1236,11 +1145,11 @@ inherits (matest0); create table matest3 (id int primary key) inherits (matest0); -create index "matest0i" on matest0 using btree ((1 - id)); +create index matest0i on matest0 using btree ((1 - id)); -create index "matest1i" on matest1 using btree ((1 - id)); +create index matest1i on matest1 using btree ((1 - id)); -create index "matest3i" on matest3 using btree ((1 - id)); +create index matest3i on matest3 using btree ((1 - id)); insert into matest1 (name) values ('Test 1'); @@ -1260,9 +1169,9 @@ select * from matest0 order by 1 - id; select * from matest0 order by 1 - id; -select MIN(1 - id) from matest0; +select min(1 - id) from matest0; -select MIN(1 - id) from matest0; +select min(1 - id) from matest0; reset enable_indexscan; @@ -1274,9 +1183,9 @@ select * from matest0 order by 1 - id; select * from matest0 order by 1 - id; -select MIN(1 - id) from matest0; +select min(1 - id) from matest0; -select MIN(1 - id) from matest0; +select min(1 - id) from matest0; reset enable_seqscan; @@ -1285,23 +1194,13 @@ reset enable_parallel_append; select 1 - id as c from - ( - select id from matest3 as t1 - union all - select id * 2 from matest3 as t2 - ) - as ss + (select id from matest3 as t1 union all select id * 2 from matest3 as t2) as ss order by c; select 1 - id as c from - ( - select id from matest3 as t1 - union all - select id * 2 from matest3 as t2 - ) - as ss + (select id from matest3 as t1 union all select id * 2 from matest3 as t2) as ss order by c; drop table matest0 cascade; @@ -1316,9 +1215,9 @@ create table matest0 ( create table matest1 () inherits (matest0); -create index "matest0i" on matest0 using btree (b, c); +create index matest0i on matest0 using btree (b, c); -create index "matest1i" on matest1 using btree (b, c); +create index matest1i on matest1 using btree (b, c); set enable_nestloop = off; @@ -1365,12 +1264,7 @@ select thousand, thousand from tenk1 order by thousand, tenthous; -select - thousand, - tenthous, - thousand + tenthous as x -from - tenk1 +select thousand, tenthous, thousand + tenthous as x from tenk1 union all select 42, 42, hundred from tenk1 order by thousand, @@ -1383,17 +1277,12 @@ order by thousand, tenthous; select - MIN(x) + min(x) from - ( - select unique1 as x from tenk1 as a - union all - select unique2 as x from tenk1 as b - ) - as s; + (select unique1 as x from tenk1 as a union all select unique2 as x from tenk1 as b) as s; select - MIN(y) + min(y) from ( select unique1 as x, unique1 as y from tenk1 as a @@ -1407,11 +1296,7 @@ select y from ( - select - thousand as x, - tenthous as y - from - tenk1 as a + select thousand as x, tenthous as y from tenk1 as a union all select unique2 as x, unique2 as y from tenk1 as b ) @@ -1425,17 +1310,9 @@ select f.i from ( - (select - d + g.i - from - generate_series(4, 30, 3) as d - order by 1) + (select d + g.i from generate_series(4, 30, 3) as d order by 1) union all - (select - d + g.i - from - generate_series(0, 30, 5) as d - order by 1) + (select d + g.i from generate_series(0, 30, 5) as d order by 1) ) as f (i) order by f.i @@ -1450,17 +1327,9 @@ select f.i from ( - (select - d + g.i - from - generate_series(4, 30, 3) as d - order by 1) + (select d + g.i from generate_series(4, 30, 3) as d order by 1) union all - (select - d + g.i - from - generate_series(0, 30, 5) as d - order by 1) + (select d + g.i from generate_series(0, 30, 5) as d order by 1) ) as f (i) order by f.i @@ -1534,11 +1403,7 @@ select * from inhpar; insert into inhpar as i values (3), (7) -on conflict -(f1) -do -update -set (f1, f2) = (select i.f1, i.f2 || '+'); +on conflict (f1) do update set (f1, f2) = (select i.f1, i.f2 || '+'); select * from inhpar order by f1; @@ -1570,13 +1435,10 @@ create table cc1 ( inherits (pp1); create table cc2 (f4 double precision) -inherits (pp1, -cc1); +inherits (pp1, cc1); create table cc3 () -inherits (pp1, -cc1, -cc2); +inherits (pp1, cc1, cc2); alter table pp1 alter column f1 set not null; @@ -1593,7 +1455,7 @@ alter table cc3 drop table cc3; alter table cc1 - add column a2 int constraint "nn" not null; + add column a2 int constraint nn not null; alter table pp1 alter column f1 set not null; @@ -1633,8 +1495,7 @@ create table inh_cc1 ( inherits (inh_pp1); create table inh_cc2 (f4 double precision) -inherits (inh_pp1, -inh_cc1); +inherits (inh_pp1, inh_cc1); alter table inh_pp1 alter column f1 set not null; @@ -1656,8 +1517,7 @@ create table inh_cc1 ( inherits (inh_pp1); create table inh_cc2 (f4 double precision) -inherits (inh_pp1, -inh_cc1); +inherits (inh_pp1, inh_cc1); alter table inh_pp1 alter column f1 drop not null; @@ -1670,21 +1530,19 @@ create table inh_child (i int) inherits (inh_parent); create table inh_grandchild () -inherits (inh_parent, -inh_child); +inherits (inh_parent, inh_child); alter table inh_parent add column i int not null; drop table inh_parent, inh_child, inh_grandchild; -create table inh_parent1 (a int constraint "nn" not null); +create table inh_parent1 (a int constraint nn not null); -create table inh_parent2 (b int constraint "nn" not null); +create table inh_parent2 (b int constraint nn not null); create table inh_child1 () -inherits (inh_parent1, -inh_parent2); +inherits (inh_parent1, inh_parent2); alter table inh_child2 no inherit inh_parent2; @@ -1706,8 +1564,7 @@ create table inh_parent2 ( ); create table inh_child () -inherits (inh_parent1, -inh_parent2); +inherits (inh_parent1, inh_parent2); select cast(conrelid as regclass), @@ -1721,10 +1578,7 @@ from pg_constraint where contype in ('n', 'p') and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_child', 'inh_parent1', 'inh_parent2' - ) + cast(cast(conrelid as regclass) as text) in ('inh_child', 'inh_parent1', 'inh_parent2') order by 1, 2; @@ -1743,22 +1597,14 @@ select conname, contype, conkey, - ( - select - attname - from - pg_attribute - where - attrelid = conrelid and attnum = conkey[1] - ), + (select attname from pg_attribute where attrelid = conrelid and attnum = conkey[1]), coninhcount, conislocal, connoinherit from pg_constraint where - contype = 'n' and - cast(cast(conrelid as regclass) as text) like 'inh\_nn\_%' + contype = 'n' and cast(cast(conrelid as regclass) as text) like 'inh\_nn\_%' order by 2, 1; @@ -1871,16 +1717,13 @@ create table inh_child (a int primary key) inherits (inh_parent); alter table inh_parent - add constraint "inh_parent_excl" exclude using btree ((1) with =); + add constraint inh_parent_excl exclude using btree ((1) with =); alter table inh_parent - add constraint "inh_parent_uq" unique (a); + add constraint inh_parent_uq unique (a); alter table inh_parent - add constraint "inh_parent_fk" - foreign key - (a) - references inh_parent (a); + add constraint inh_parent_fk foreign key (a) references inh_parent (a); create table inh_child2 () inherits (inh_parent); @@ -1917,8 +1760,7 @@ create table inh_child2 () inherits (inh_parent); create table inh_child3 () -inherits (inh_child1, -inh_child2); +inherits (inh_child1, inh_child2); select cast(conrelid as regclass), @@ -1948,8 +1790,7 @@ create table inh_child ( f1 int not null, f2 text not null ) -inherits (inh_parent_1, -inh_parent_2); +inherits (inh_parent_1, inh_parent_2); select cast(conrelid as regclass), @@ -1985,33 +1826,20 @@ create table inh_p4 ( ); create table inh_multiparent () -inherits (inh_p1, -inh_p2, -inh_p3, -inh_p4); +inherits (inh_p1, inh_p2, inh_p3, inh_p4); select cast(conrelid as regclass), contype, conname, - ( - select - attname - from - pg_attribute - where - attrelid = conrelid and attnum = conkey[1] - ), + (select attname from pg_attribute where attrelid = conrelid and attnum = conkey[1]), coninhcount, conislocal from pg_constraint where contype = 'n' and - cast(conrelid as regclass) - in ( - 'inh_p1', 'inh_p2', 'inh_p3', 'inh_p4', 'inh_multiparent' - ) + cast(conrelid as regclass) in ('inh_p1', 'inh_p2', 'inh_p3', 'inh_p4', 'inh_multiparent') order by cast(cast(conrelid as regclass) as text), conname; @@ -2019,31 +1847,19 @@ create table inh_multiparent2 ( a int not null, f1 int ) -inherits (inh_p3, -inh_multiparent); +inherits (inh_p3, inh_multiparent); select cast(conrelid as regclass), contype, conname, - ( - select - attname - from - pg_attribute - where - attrelid = conrelid and attnum = conkey[1] - ), + (select attname from pg_attribute where attrelid = conrelid and attnum = conkey[1]), coninhcount, conislocal from pg_constraint where - contype = 'n' and - cast(conrelid as regclass) - in ( - 'inh_p3', 'inh_multiparent', 'inh_multiparent2' - ) + contype = 'n' and cast(conrelid as regclass) in ('inh_p3', 'inh_multiparent', 'inh_multiparent2') order by cast(cast(conrelid as regclass) as text), conname; @@ -2085,10 +1901,7 @@ from pg_constraint where contype = 'n' and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_nn1', 'inh_nn2', 'inh_nn3', 'inh_nn4' - ) + cast(cast(conrelid as regclass) as text) in ('inh_nn1', 'inh_nn2', 'inh_nn3', 'inh_nn4') order by 2, 1; @@ -2103,10 +1916,7 @@ from pg_constraint where contype = 'n' and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_nn1', 'inh_nn2', 'inh_nn3', 'inh_nn4' - ) + cast(cast(conrelid as regclass) as text) in ('inh_nn1', 'inh_nn2', 'inh_nn3', 'inh_nn4') order by 2, 1; @@ -2123,10 +1933,7 @@ from pg_constraint where contype = 'n' and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_nn1', 'inh_nn2', 'inh_nn3', 'inh_nn4' - ) + cast(cast(conrelid as regclass) as text) in ('inh_nn1', 'inh_nn2', 'inh_nn3', 'inh_nn4') order by 2, 1; @@ -2146,8 +1953,7 @@ create table inh_nn3 () inherits (inh_nn2); create table inh_nn4 () -inherits (inh_nn1, -inh_nn2); +inherits (inh_nn1, inh_nn2); select cast(conrelid as regclass), @@ -2159,10 +1965,7 @@ from pg_constraint where contype = 'n' and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_nn1', 'inh_nn2', 'inh_nn3', 'inh_nn4' - ) + cast(cast(conrelid as regclass) as text) in ('inh_nn1', 'inh_nn2', 'inh_nn3', 'inh_nn4') order by 2, 1; @@ -2184,11 +1987,7 @@ select from pg_constraint where - contype = 'n' and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_nn1', 'inh_nn2', 'inh_nn3' - ) + contype = 'n' and cast(cast(conrelid as regclass) as text) in ('inh_nn1', 'inh_nn2', 'inh_nn3') order by 2, 1; @@ -2202,21 +2001,14 @@ select from pg_constraint where - contype = 'n' and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_nn1', 'inh_nn2', 'inh_nn3' - ) + contype = 'n' and cast(cast(conrelid as regclass) as text) in ('inh_nn1', 'inh_nn2', 'inh_nn3') order by 2, 1; drop table inh_nn1, inh_nn2, inh_nn3; create table inh_nn1 ( - f1 int - check (f1 > 5) - primary key - references inh_nn1, + f1 int check (f1 > 5) primary key references inh_nn1, f2 int not null ); @@ -2231,7 +2023,7 @@ create role regress_bob; grant all on schema public to regress_alice, regress_bob; -grant REGRESS_ALICE to regress_bob; +grant regress_alice to regress_bob; set session authorization regress_alice; @@ -2290,7 +2082,7 @@ drop table inh_perm_parent cascade; drop table inh_temp_parent cascade; create table list_parted (a varchar) -partition by LIST(a); +partition by list(a); create table part_ab_cd partition of list_parted for values in ('ab', 'cd'); @@ -2319,7 +2111,7 @@ partition by range(a); create table part_1_10 partition of range_list_parted for values from (1) to (10) -partition by LIST(b); +partition by list(b); create table part_1_10_ab partition of part_1_10 for values in ('ab'); @@ -2328,7 +2120,7 @@ create table part_1_10_cd partition of part_1_10 for values in ('cd'); create table part_10_20 partition of range_list_parted for values from (10) to (20) -partition by LIST(b); +partition by list(b); create table part_10_20_ab partition of part_10_20 for values in ('ab'); @@ -2337,7 +2129,7 @@ create table part_10_20_cd partition of part_10_20 for values in ('cd'); create table part_21_30 partition of range_list_parted for values from (21) to (30) -partition by LIST(b); +partition by list(b); create table part_21_30_ab partition of part_21_30 for values in ('ab'); @@ -2346,7 +2138,7 @@ create table part_21_30_cd partition of part_21_30 for values in ('cd'); create table part_40_inf partition of range_list_parted for values from (40) to (maxvalue) -partition by LIST(b); +partition by list(b); create table part_40_inf_ab partition of part_40_inf for values in ('ab'); @@ -2385,11 +2177,7 @@ create table mcrparted_def partition of mcrparted default; create table mcrparted0 partition of mcrparted -for values from (minvalue, -minvalue, -minvalue) to (1, -1, -1); +for values from (minvalue, minvalue, minvalue) to (1, 1, 1); create table mcrparted1 partition of mcrparted for values from (1, 1, 1) to (10, 5, 10); @@ -2401,11 +2189,7 @@ create table mcrparted4 partition of mcrparted for values from (20, 10, 10) to ( create table mcrparted5 partition of mcrparted -for values from (20, -20, -20) to (maxvalue, -maxvalue, -maxvalue); +for values from (20, 20, 20) to (maxvalue, maxvalue, maxvalue); select * from mcrparted where a = 0; @@ -2429,17 +2213,17 @@ partition by range(a); create table parted_minmax1 partition of parted_minmax for values from (1) to (10); -create index "parted_minmax1i" on parted_minmax1 using btree (a, b); +create index parted_minmax1i on parted_minmax1 using btree (a, b); insert into parted_minmax values (1, '12345'); -select MIN(a), MAX(a) from parted_minmax where b = '12345'; +select min(a), max(a) from parted_minmax where b = '12345'; -select MIN(a), MAX(a) from parted_minmax where b = '12345'; +select min(a), max(a) from parted_minmax where b = '12345'; drop table parted_minmax; -create index "mcrparted_a_abs_c_idx" on mcrparted using btree (a, (abs(b)), c); +create index mcrparted_a_abs_c_idx on mcrparted using btree (a, (abs(b)), c); select * from mcrparted order by a, abs(b), c; @@ -2453,12 +2237,8 @@ drop table mcrparted5; create table mcrparted5 partition of mcrparted -for values from (20, -20, -20) to (maxvalue, -maxvalue, -maxvalue) -partition by LIST(a); +for values from (20, 20, 20) to (maxvalue, maxvalue, maxvalue) +partition by list(a); create table mcrparted5a partition of mcrparted5 for values in (20); @@ -2477,7 +2257,7 @@ set enable_bitmapscan = off; set enable_sort = off; create table mclparted (a int) -partition by LIST(a); +partition by list(a); create table mclparted1 partition of mclparted for values in (1); @@ -2541,8 +2321,8 @@ reset enable_bitmapscan; drop table mcrparted; -create table bool_lp (b boolean) -partition by LIST(b); +create table bool_lp (b bool) +partition by list(b); create table bool_lp_true partition of bool_lp for values in (true); @@ -2555,7 +2335,7 @@ select * from bool_lp order by b; drop table bool_lp; create table bool_rp ( - b boolean, + b bool, a int ) partition by range(b, a); @@ -2604,14 +2384,14 @@ create table permtest_parent ( b text, c text ) -partition by LIST(a); +partition by list(a); create table permtest_child ( b text, c text, a int ) -partition by LIST(b); +partition by list(b); create table permtest_grandchild ( c text, @@ -2630,12 +2410,7 @@ alter table permtest_parent create index on permtest_parent using btree ((left(c, 3))); insert into permtest_parent -select - 1, - 'a', - left(fipshash(cast(i as text)), 5) -from - generate_series(0, 100) as i; +select 1, 'a', left(fipshash(cast(i as text)), 5) from generate_series(0, 100) as i; analyze permtest_parent; @@ -2643,31 +2418,25 @@ create role regress_no_child_access; revoke all on table permtest_grandchild from regress_no_child_access; -grant SELECT on table permtest_parent to regress_no_child_access; +grant select on table permtest_parent to regress_no_child_access; set session authorization regress_no_child_access; select * from - permtest_parent as p1 - inner join - permtest_parent as p2 - on p1.a = p2.a and p1.c ~ 'a1$'; + permtest_parent as p1 inner join permtest_parent as p2 on p1.a = p2.a and p1.c ~ 'a1$'; select * from - permtest_parent as p1 - inner join - permtest_parent as p2 - on p1.a = p2.a and left(p1.c, 3) ~ 'a1$'; + permtest_parent as p1 inner join permtest_parent as p2 on p1.a = p2.a and left(p1.c, 3) ~ 'a1$'; reset session_authorization; revoke all on table permtest_parent from regress_no_child_access; -grant SELECT (a, c) on table permtest_parent to regress_no_child_access; +grant select (a, c) on table permtest_parent to regress_no_child_access; set session authorization regress_no_child_access; @@ -2675,19 +2444,13 @@ select p2.a, p1.c from - permtest_parent as p1 - inner join - permtest_parent as p2 - on p1.a = p2.a and p1.c ~ 'a1$'; + permtest_parent as p1 inner join permtest_parent as p2 on p1.a = p2.a and p1.c ~ 'a1$'; select p2.a, p1.c from - permtest_parent as p1 - inner join - permtest_parent as p2 - on p1.a = p2.a and left(p1.c, 3) ~ 'a1$'; + permtest_parent as p1 inner join permtest_parent as p2 on p1.a = p2.a and left(p1.c, 3) ~ 'a1$'; reset session_authorization; @@ -2701,21 +2464,21 @@ create table errtst_parent ( partid int not null, shdata int not null, data int not null default 0, - constraint "shdata_small" check (shdata < 3) + constraint shdata_small check (shdata < 3) ) partition by range(partid); create table errtst_child_fastdef ( partid int not null, shdata int not null, - constraint "shdata_small" check (shdata < 3) + constraint shdata_small check (shdata < 3) ); create table errtst_child_plaindef ( partid int not null, shdata int not null, data int not null default 0, - constraint "shdata_small" check (shdata < 3), + constraint shdata_small check (shdata < 3), check (data < 10) ); @@ -2723,7 +2486,7 @@ create table errtst_child_reorder ( data int not null default 0, shdata int not null, partid int not null, - constraint "shdata_small" check (shdata < 3), + constraint shdata_small check (shdata < 3), check (data < 10) ); @@ -2731,7 +2494,7 @@ alter table errtst_child_fastdef add column data int not null default 0; alter table errtst_child_fastdef - add constraint "errtest_child_fastdef_data_check" check (data < 10); + add constraint errtest_child_fastdef_data_check check (data < 10); alter table errtst_parent attach partition @@ -2850,16 +2613,7 @@ select from tuplesest_tab inner join - ( - select - b - from - tuplesest_parted - where - c < 100 - group by b - ) - as sub + (select b from tuplesest_parted where c < 100 group by b) as sub on tuplesest_tab.a = sub.b; drop table tuplesest_parted; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_80.snap index 2e647d3c1..30ed05a5e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_80.snap @@ -11,9 +11,7 @@ create table c (cc text) inherits (a); create table d (dd text) -inherits (b, -c, -a); +inherits (b, c, a); insert into a (aa) values ('aaa'); @@ -188,21 +186,14 @@ create table some_tab_child () inherits (some_tab); insert into some_tab_child -select - i, - i + 1, - 0 -from - generate_series(1, 1000) as i; +select i, i + 1, 0 from generate_series(1, 1000) as i; create index on some_tab_child using btree (f1, f2); create function some_tab_stmt_trig_func() returns trigger language plpgsql -as $function$ -begin raise notice 'updating some_tab'; return NULL; end; -$function$; +as $$begin raise notice 'updating some_tab'; return NULL; end;$$; create trigger some_tab_stmt_trig before update @@ -283,8 +274,7 @@ insert into bar2 values (4, 4, 4); update bar set f2 = f2 + 100 where f1 in (select f1 from foo); select - cast(cast(tableoid as regclass) as text) - as relname, + cast(cast(tableoid as regclass) as text) as relname, bar.* from bar @@ -293,18 +283,12 @@ order by 1, update bar set f2 = f2 + 100 -from ( - select f1 from foo - union all - select f1 + 3 from foo -) -as ss +from (select f1 from foo union all select f1 + 3 from foo) as ss where bar.f1 = ss.f1; select - cast(cast(tableoid as regclass) as text) - as relname, + cast(cast(tableoid as regclass) as text) as relname, bar.* from bar @@ -324,7 +308,7 @@ create table parted_tab ( a int, b char(1) ) -partition by LIST(a); +partition by list(a); create table parted_tab_part1 partition of parted_tab for values in (1); @@ -336,18 +320,12 @@ insert into parted_tab values (1, 'a'), (2, 'a'), (3, 'a'); update parted_tab set b = 'b' -from ( - select a from some_tab - union all - select a + 1 from some_tab -) -as ss (a) +from (select a from some_tab union all select a + 1 from some_tab) as ss (a) where parted_tab.a = ss.a; select - cast(cast(tableoid as regclass) as text) - as relname, + cast(cast(tableoid as regclass) as text) as relname, parted_tab.* from parted_tab @@ -360,18 +338,12 @@ insert into parted_tab values (1, 'a'), (2, 'a'), (3, 'a'); update parted_tab set b = 'b' -from ( - select 0 from parted_tab - union all - select 1 from parted_tab -) -as ss (a) +from (select 0 from parted_tab union all select 1 from parted_tab) as ss (a) where parted_tab.a = ss.a; select - cast(cast(tableoid as regclass) as text) - as relname, + cast(cast(tableoid as regclass) as text) as relname, parted_tab.* from parted_tab @@ -387,14 +359,14 @@ create table mlparted_tab ( b char(1), c text ) -partition by LIST(a); +partition by list(a); create table mlparted_tab_part1 partition of mlparted_tab for values in (1); create table mlparted_tab_part2 partition of mlparted_tab for values in (2) -partition by LIST(b); +partition by list(b); create table mlparted_tab_part3 partition of mlparted_tab for values in (3); @@ -410,19 +382,12 @@ insert into mlparted_tab values (1, 'a'), (2, 'a'), (2, 'b'), (3, 'a'); update mlparted_tab as mlp set c = 'xxx' -from ( - select a from some_tab - union all - select a + 1 from some_tab -) -as ss (a) +from (select a from some_tab union all select a + 1 from some_tab) as ss (a) where - (mlp.a = ss.a and mlp.b = 'b') or - mlp.a = 3; + (mlp.a = ss.a and mlp.b = 'b') or mlp.a = 3; select - cast(cast(tableoid as regclass) as text) - as relname, + cast(cast(tableoid as regclass) as text) as relname, mlparted_tab.* from mlparted_tab @@ -433,23 +398,20 @@ drop table mlparted_tab; drop table some_tab cascade; -create table firstparent (tomorrow date default (cast(NOW() as date) + 1)); +create table firstparent (tomorrow date default (cast(now() as date) + 1)); -create table secondparent (tomorrow date default (cast(NOW() as date) + 1)); +create table secondparent (tomorrow date default (cast(now() as date) + 1)); create table jointchild () -inherits (firstparent, -secondparent); +inherits (firstparent, secondparent); -create table thirdparent (tomorrow date default (cast(NOW() as date) - 1)); +create table thirdparent (tomorrow date default (cast(now() as date) - 1)); create table otherchild () -inherits (firstparent, -thirdparent); +inherits (firstparent, thirdparent); -create table otherchild (tomorrow date default NOW()) -inherits (firstparent, -thirdparent); +create table otherchild (tomorrow date default now()) +inherits (firstparent, thirdparent); drop table firstparent, secondparent, jointchild, thirdparent, otherchild; @@ -471,8 +433,7 @@ create temporary table parent2 ( ); create temporary table childtab (f4 int) -inherits (parent1, -parent2); +inherits (parent1, parent2); alter table parent1 alter column f1 type bigint; @@ -483,10 +444,10 @@ alter table parent1 create table p1 (ff1 int); alter table p1 - add constraint "p1chk" check (ff1 > 0) no inherit; + add constraint p1chk check (ff1 > 0) no inherit; alter table p1 - add constraint "p2chk" check (ff1 > 10); + add constraint p2chk check (ff1 > 10); select pc.relname, @@ -496,10 +457,7 @@ select pgc.coninhcount, pgc.connoinherit from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname = 'p1' order by 1, @@ -508,7 +466,7 @@ order by 1, create table c1 () inherits (p1); -create table c2 (constraint "p2chk" check (ff1 > 10) no inherit) +create table c2 (constraint p2chk check (ff1 > 10) no inherit) inherits (p1); drop table p1 cascade; @@ -531,9 +489,7 @@ select cast(derived as base) from derived; select cast(cast(null as derived) as base); select - cast(cast(cast(row(i, b) as more_derived) - as derived) - as base) + cast(cast(cast(row(i, b) as more_derived) as derived) as base) from more_derived; @@ -552,13 +508,10 @@ create table p2 (f1 text); create function p2text(p2) returns text language sql -as $function$ -select $1.f1 -$function$; +as 'select $1.f1'; create table c1 (f3 int) -inherits (p1, -p2); +inherits (p1, p2); insert into c1 values (123456789, 'hi', 42); @@ -575,7 +528,7 @@ drop table p1; create table ac (aa text); alter table ac - add constraint "ac_check" check (aa is not null); + add constraint ac_check check (aa is not null); create table bc (bb text) inherits (ac); @@ -586,13 +539,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -614,13 +563,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -635,13 +580,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -663,20 +604,16 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, 2; alter table ac - add constraint "ac_check" check (aa is not null); + add constraint ac_check check (aa is not null); alter table bc no inherit ac; @@ -687,13 +624,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -708,13 +641,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -729,13 +658,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -745,13 +670,11 @@ drop table bc; drop table ac; -create table ac (a int constraint "check_a" check (a <> 0)); +create table ac (a int constraint check_a check (a <> 0)); create table bc ( - a int - constraint "check_a" check (a <> 0), - b int - constraint "check_b" check (b <> 0) + a int constraint check_a check (a <> 0), + b int constraint check_b check (b <> 0) ) inherits (ac); @@ -761,13 +684,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc') order by 1, @@ -777,13 +696,12 @@ drop table bc; drop table ac; -create table ac (a int constraint "check_a" check (a <> 0)); +create table ac (a int constraint check_a check (a <> 0)); -create table bc (b int constraint "check_b" check (b <> 0)); +create table bc (b int constraint check_b check (b <> 0)); -create table cc (c int constraint "check_c" check (c <> 0)) -inherits (ac, -bc); +create table cc (c int constraint check_c check (c <> 0)) +inherits (ac, bc); select pc.relname, @@ -791,13 +709,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc', 'cc') order by 1, @@ -812,13 +726,9 @@ select pgc.contype, pgc.conislocal, pgc.coninhcount, - pg_get_expr(pgc.conbin, pc.oid) - as consrc + pg_get_expr(pgc.conbin, pc.oid) as consrc from - pg_class as pc - inner join - pg_constraint as pgc - on pgc.conrelid = pc.oid + pg_class as pc inner join pg_constraint as pgc on pgc.conrelid = pc.oid where pc.relname in ('ac', 'bc', 'cc') order by 1, @@ -835,13 +745,12 @@ create table p1 (f1 int); create table p2 (f2 int); create table c1 (f3 int) -inherits (p1, -p2); +inherits (p1, p2); insert into c1 values (1, -1, 2); alter table p2 - add constraint "cc" check (f2 > 0); + add constraint cc check (f2 > 0); alter table p2 add check (f2 > 0); @@ -856,12 +765,10 @@ alter table p2 insert into c1 values (1, -1, 2); create table c2 (f3 int) -inherits (p1, -p2); +inherits (p1, p2); create table c3 (f4 int) -inherits (c1, -c2); +inherits (c1, c2); drop table p1 cascade; @@ -879,8 +786,7 @@ alter table pp1 add column a1 int check (a1 > 0); create table cc2 (f4 double precision) -inherits (pp1, -cc1); +inherits (pp1, cc1); alter table pp1 add column a2 int check (a2 > 0); @@ -898,8 +804,7 @@ create table inhs1 ( ); create table inhts (d int) -inherits (inht1, -inhs1); +inherits (inht1, inhs1); alter table inht1 rename column a to aa; @@ -920,9 +825,7 @@ create table inhtc () inherits (inhtb); create table inhtd () -inherits (inhta, -inhtb, -inhtc); +inherits (inhta, inhtb, inhtc); alter table inhta add column i int, @@ -937,14 +840,12 @@ create table inht3 (y int) inherits (inht1); create table inht4 (z int) -inherits (inht2, -inht3); +inherits (inht2, inht3); alter table inht1 rename column aa to aaa; create table inhts (d int) -inherits (inht2, -inhs1); +inherits (inht2, inhs1); alter table inht1 rename column aaa to aaaa; @@ -953,16 +854,9 @@ alter table inht1 rename column b to bb; with recursive r as ( - select - cast('inht1' as regclass) as inhrelid + select cast('inht1' as regclass) as inhrelid union all - select - c.inhrelid - from - pg_inherits as c, - r - where - r.inhrelid = c.inhparent + select c.inhrelid from pg_inherits as c, r where r.inhrelid = c.inhparent ) select cast(a.attrelid as regclass), @@ -973,7 +867,7 @@ from ( select inhrelid, - COUNT(*) as expected + count(*) as expected from pg_inherits where @@ -986,8 +880,7 @@ from on e.inhrelid = a.attrelid where not attislocal -order by cast(cast(a.attrelid as regclass) - as name), +order by cast(cast(a.attrelid as regclass) as name), a.attnum; drop table inht1, inhs1 cascade; @@ -1027,8 +920,7 @@ drop table test_ex_constraints; create table test_primary_constraints (id int primary key); create table test_foreign_constraints ( - id1 int - references test_primary_constraints (id) + id1 int references test_primary_constraints (id) ); create table test_foreign_constraints_inh () @@ -1049,8 +941,7 @@ insert into inh_fk_1 values (1), (2), (3); create table inh_fk_2 ( x int primary key, - y int - references inh_fk_1 on DELETE cascade + y int references inh_fk_1 on delete cascade ); insert into inh_fk_2 values (11, 1), (22, 2), (33, 3); @@ -1074,27 +965,25 @@ create table p1_c1 () inherits (p1); alter table p1 - add constraint "inh_check_constraint1" check (f1 > 0); + add constraint inh_check_constraint1 check (f1 > 0); alter table p1_c1 - add constraint "inh_check_constraint1" check (f1 > 0); + add constraint inh_check_constraint1 check (f1 > 0); alter table p1_c1 - add constraint "inh_check_constraint2" check (f1 < 10); + add constraint inh_check_constraint2 check (f1 < 10); alter table p1 - add constraint "inh_check_constraint2" check (f1 < 10); + add constraint inh_check_constraint2 check (f1 < 10); -create table p1_c2 (f1 int constraint "inh_check_constraint4" check (f1 < 10)) +create table p1_c2 (f1 int constraint inh_check_constraint4 check (f1 < 10)) inherits (p1); create table p1_c3 () -inherits (p1, -p1_c1); +inherits (p1, p1_c1); select - cast(cast(conrelid as regclass) as text) - as relname, + cast(cast(conrelid as regclass) as text) as relname, conname, conislocal, coninhcount, @@ -1119,9 +1008,9 @@ alter table p1_c1 drop table p1, p1_c1; -create table p1 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p1 (f1 int constraint f1_pos check (f1 > 0)); -create table p1_c1 (f1 int constraint "f1_pos" check (f1 > 0)) +create table p1_c1 (f1 int constraint f1_pos check (f1 > 0)) inherits (p1); alter table p1_c1 @@ -1132,17 +1021,15 @@ alter table p1 drop table p1 cascade; -create table p1 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p1 (f1 int constraint f1_pos check (f1 > 0)); -create table p2 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p2 (f1 int constraint f1_pos check (f1 > 0)); create table p1p2_c1 (f1 int) -inherits (p1, -p2); +inherits (p1, p2); -create table p1p2_c2 (f1 int constraint "f1_pos" check (f1 > 0)) -inherits (p1, -p2); +create table p1p2_c2 (f1 int constraint f1_pos check (f1 > 0)) +inherits (p1, p2); alter table p2 drop constraint f1_pos; @@ -1152,7 +1039,7 @@ alter table p1 drop table p1, p2 cascade; -create table p1 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p1 (f1 int constraint f1_pos check (f1 > 0)); create table p1_c1 () inherits (p1); @@ -1161,26 +1048,23 @@ create table p1_c2 () inherits (p1); create table p1_c1c2 () -inherits (p1_c1, -p1_c2); +inherits (p1_c1, p1_c2); alter table p1 drop constraint f1_pos; drop table p1 cascade; -create table p1 (f1 int constraint "f1_pos" check (f1 > 0)); +create table p1 (f1 int constraint f1_pos check (f1 > 0)); create table p1_c1 () inherits (p1); -create table p1_c2 (constraint "f1_pos" check (f1 > 0)) +create table p1_c2 (constraint f1_pos check (f1 > 0)) inherits (p1); create table p1_c1c2 () -inherits (p1_c1, -p1_c2, -p1); +inherits (p1_c1, p1_c2, p1); alter table p1_c2 drop constraint f1_pos; @@ -1202,10 +1086,10 @@ create table invalid_check_con_child () inherits (invalid_check_con); alter table invalid_check_con_child - add constraint "inh_check_constraint" check (f1 > 0) not valid; + add constraint inh_check_constraint check (f1 > 0) not valid; alter table invalid_check_con - add constraint "inh_check_constraint" check (f1 > 0); + add constraint inh_check_constraint check (f1 > 0); alter table invalid_check_con_child drop constraint inh_check_constraint; @@ -1213,18 +1097,17 @@ alter table invalid_check_con_child insert into invalid_check_con values (0); alter table invalid_check_con_child - add constraint "inh_check_constraint" check (f1 > 0); + add constraint inh_check_constraint check (f1 > 0); alter table invalid_check_con - add constraint "inh_check_constraint" check (f1 > 0) not valid; + add constraint inh_check_constraint check (f1 > 0) not valid; insert into invalid_check_con values (0); insert into invalid_check_con_child values (0); select - cast(cast(conrelid as regclass) as text) - as relname, + cast(cast(conrelid as regclass) as text) as relname, conname, convalidated, conislocal, @@ -1237,14 +1120,9 @@ where order by 1, 2; -create temporary table patest0 (id, -x) +create temporary table patest0 (id, x) as - select - x, - x - from - generate_series(0, 1000) as x; + select x, x from generate_series(0, 1000) as x; create temporary table patest1 () inherits (patest0); @@ -1256,11 +1134,11 @@ inherits (patest0); insert into patest2 select x, x from generate_series(0, 1000) as x; -create index "patest0i" on patest0 using btree (id); +create index patest0i on patest0 using btree (id); -create index "patest1i" on patest1 using btree (id); +create index patest1i on patest1 using btree (id); -create index "patest2i" on patest2 using btree (id); +create index patest2i on patest2 using btree (id); analyze patest0; @@ -1271,36 +1149,24 @@ analyze patest2; select * from - patest0 - inner join - (select f1 from int4_tbl limit 1) as ss - on id = f1; + patest0 inner join (select f1 from int4_tbl limit 1) as ss on id = f1; select * from - patest0 - inner join - (select f1 from int4_tbl limit 1) as ss - on id = f1; + patest0 inner join (select f1 from int4_tbl limit 1) as ss on id = f1; drop index patest2i; select * from - patest0 - inner join - (select f1 from int4_tbl limit 1) as ss - on id = f1; + patest0 inner join (select f1 from int4_tbl limit 1) as ss on id = f1; select * from - patest0 - inner join - (select f1 from int4_tbl limit 1) as ss - on id = f1; + patest0 inner join (select f1 from int4_tbl limit 1) as ss on id = f1; drop table patest0 cascade; @@ -1318,11 +1184,11 @@ inherits (matest0); create table matest3 (id int primary key) inherits (matest0); -create index "matest0i" on matest0 using btree ((1 - id)); +create index matest0i on matest0 using btree ((1 - id)); -create index "matest1i" on matest1 using btree ((1 - id)); +create index matest1i on matest1 using btree ((1 - id)); -create index "matest3i" on matest3 using btree ((1 - id)); +create index matest3i on matest3 using btree ((1 - id)); insert into matest1 (name) values ('Test 1'); @@ -1342,9 +1208,9 @@ select * from matest0 order by 1 - id; select * from matest0 order by 1 - id; -select MIN(1 - id) from matest0; +select min(1 - id) from matest0; -select MIN(1 - id) from matest0; +select min(1 - id) from matest0; reset enable_indexscan; @@ -1356,9 +1222,9 @@ select * from matest0 order by 1 - id; select * from matest0 order by 1 - id; -select MIN(1 - id) from matest0; +select min(1 - id) from matest0; -select MIN(1 - id) from matest0; +select min(1 - id) from matest0; reset enable_seqscan; @@ -1368,9 +1234,7 @@ select 1 - id as c from ( - select id from matest3 as t1 - union all - select id * 2 from matest3 as t2 + select id from matest3 as t1 union all select id * 2 from matest3 as t2 ) as ss order by c; @@ -1379,9 +1243,7 @@ select 1 - id as c from ( - select id from matest3 as t1 - union all - select id * 2 from matest3 as t2 + select id from matest3 as t1 union all select id * 2 from matest3 as t2 ) as ss order by c; @@ -1398,9 +1260,9 @@ create table matest0 ( create table matest1 () inherits (matest0); -create index "matest0i" on matest0 using btree (b, c); +create index matest0i on matest0 using btree (b, c); -create index "matest1i" on matest1 using btree (b, c); +create index matest1i on matest1 using btree (b, c); set enable_nestloop = off; @@ -1447,12 +1309,7 @@ select thousand, thousand from tenk1 order by thousand, tenthous; -select - thousand, - tenthous, - thousand + tenthous as x -from - tenk1 +select thousand, tenthous, thousand + tenthous as x from tenk1 union all select 42, 42, hundred from tenk1 order by thousand, @@ -1460,16 +1317,12 @@ order by thousand, select thousand, tenthous from tenk1 union all -select - thousand, - cast(random() as int) -from - tenk1 +select thousand, cast(random() as int) from tenk1 order by thousand, tenthous; select - MIN(x) + min(x) from ( select unique1 as x from tenk1 as a @@ -1479,20 +1332,12 @@ from as s; select - MIN(y) + min(y) from ( - select - unique1 as x, - unique1 as y - from - tenk1 as a + select unique1 as x, unique1 as y from tenk1 as a union all - select - unique2 as x, - unique2 as y - from - tenk1 as b + select unique2 as x, unique2 as y from tenk1 as b ) as s; @@ -1501,17 +1346,9 @@ select y from ( - select - thousand as x, - tenthous as y - from - tenk1 as a + select thousand as x, tenthous as y from tenk1 as a union all - select - unique2 as x, - unique2 as y - from - tenk1 as b + select unique2 as x, unique2 as y from tenk1 as b ) as s order by x, @@ -1523,17 +1360,9 @@ select f.i from ( - (select - d + g.i - from - generate_series(4, 30, 3) as d - order by 1) + (select d + g.i from generate_series(4, 30, 3) as d order by 1) union all - (select - d + g.i - from - generate_series(0, 30, 5) as d - order by 1) + (select d + g.i from generate_series(0, 30, 5) as d order by 1) ) as f (i) order by f.i @@ -1548,17 +1377,9 @@ select f.i from ( - (select - d + g.i - from - generate_series(4, 30, 3) as d - order by 1) + (select d + g.i from generate_series(4, 30, 3) as d order by 1) union all - (select - d + g.i - from - generate_series(0, 30, 5) as d - order by 1) + (select d + g.i from generate_series(0, 30, 5) as d order by 1) ) as f (i) order by f.i @@ -1591,24 +1412,10 @@ insert into inhpar select x, cast(x as text) from generate_series(1, 5) as x; insert into inhcld select cast(x as text), x from generate_series(6, 10) as x; update inhpar as i -set (f1, f2) = ( - select - i.f1, - i.f2 || '-' - from - int4_tbl - limit 1 -); +set (f1, f2) = (select i.f1, i.f2 || '-' from int4_tbl limit 1); update inhpar as i -set (f1, f2) = ( - select - i.f1, - i.f2 || '-' - from - int4_tbl - limit 1 -); +set (f1, f2) = (select i.f1, i.f2 || '-' from int4_tbl limit 1); select * from inhpar; @@ -1641,34 +1448,16 @@ alter table inhpar insert into inhpar select x, cast(x as text) from generate_series(1, 10) as x; update inhpar as i -set (f1, f2) = ( - select - i.f1, - i.f2 || '-' - from - int4_tbl - limit 1 -); +set (f1, f2) = (select i.f1, i.f2 || '-' from int4_tbl limit 1); update inhpar as i -set (f1, f2) = ( - select - i.f1, - i.f2 || '-' - from - int4_tbl - limit 1 -); +set (f1, f2) = (select i.f1, i.f2 || '-' from int4_tbl limit 1); select * from inhpar; insert into inhpar as i values (3), (7) -on conflict -(f1) -do -update -set (f1, f2) = (select i.f1, i.f2 || '+'); +on conflict (f1) do update set (f1, f2) = (select i.f1, i.f2 || '+'); select * from inhpar order by f1; @@ -1700,13 +1489,10 @@ create table cc1 ( inherits (pp1); create table cc2 (f4 double precision) -inherits (pp1, -cc1); +inherits (pp1, cc1); create table cc3 () -inherits (pp1, -cc1, -cc2); +inherits (pp1, cc1, cc2); alter table pp1 alter column f1 set not null; @@ -1723,7 +1509,7 @@ alter table cc3 drop table cc3; alter table cc1 - add column a2 int constraint "nn" not null; + add column a2 int constraint nn not null; alter table pp1 alter column f1 set not null; @@ -1763,8 +1549,7 @@ create table inh_cc1 ( inherits (inh_pp1); create table inh_cc2 (f4 double precision) -inherits (inh_pp1, -inh_cc1); +inherits (inh_pp1, inh_cc1); alter table inh_pp1 alter column f1 set not null; @@ -1786,8 +1571,7 @@ create table inh_cc1 ( inherits (inh_pp1); create table inh_cc2 (f4 double precision) -inherits (inh_pp1, -inh_cc1); +inherits (inh_pp1, inh_cc1); alter table inh_pp1 alter column f1 drop not null; @@ -1800,21 +1584,19 @@ create table inh_child (i int) inherits (inh_parent); create table inh_grandchild () -inherits (inh_parent, -inh_child); +inherits (inh_parent, inh_child); alter table inh_parent add column i int not null; drop table inh_parent, inh_child, inh_grandchild; -create table inh_parent1 (a int constraint "nn" not null); +create table inh_parent1 (a int constraint nn not null); -create table inh_parent2 (b int constraint "nn" not null); +create table inh_parent2 (b int constraint nn not null); create table inh_child1 () -inherits (inh_parent1, -inh_parent2); +inherits (inh_parent1, inh_parent2); alter table inh_child2 no inherit inh_parent2; @@ -1836,8 +1618,7 @@ create table inh_parent2 ( ); create table inh_child () -inherits (inh_parent1, -inh_parent2); +inherits (inh_parent1, inh_parent2); select cast(conrelid as regclass), @@ -1879,8 +1660,7 @@ select from pg_attribute where - attrelid = conrelid and - attnum = conkey[1] + attrelid = conrelid and attnum = conkey[1] ), coninhcount, conislocal, @@ -1888,8 +1668,7 @@ select from pg_constraint where - contype = 'n' and - cast(cast(conrelid as regclass) as text) like 'inh\_nn\_%' + contype = 'n' and cast(cast(conrelid as regclass) as text) like 'inh\_nn\_%' order by 2, 1; @@ -2003,16 +1782,13 @@ create table inh_child (a int primary key) inherits (inh_parent); alter table inh_parent - add constraint "inh_parent_excl" exclude using btree ((1) with =); + add constraint inh_parent_excl exclude using btree ((1) with =); alter table inh_parent - add constraint "inh_parent_uq" unique (a); + add constraint inh_parent_uq unique (a); alter table inh_parent - add constraint "inh_parent_fk" - foreign key - (a) - references inh_parent (a); + add constraint inh_parent_fk foreign key (a) references inh_parent (a); create table inh_child2 () inherits (inh_parent); @@ -2049,8 +1825,7 @@ create table inh_child2 () inherits (inh_parent); create table inh_child3 () -inherits (inh_child1, -inh_child2); +inherits (inh_child1, inh_child2); select cast(conrelid as regclass), @@ -2080,8 +1855,7 @@ create table inh_child ( f1 int not null, f2 text not null ) -inherits (inh_parent_1, -inh_parent_2); +inherits (inh_parent_1, inh_parent_2); select cast(conrelid as regclass), @@ -2117,10 +1891,7 @@ create table inh_p4 ( ); create table inh_multiparent () -inherits (inh_p1, -inh_p2, -inh_p3, -inh_p4); +inherits (inh_p1, inh_p2, inh_p3, inh_p4); select cast(conrelid as regclass), @@ -2132,8 +1903,7 @@ select from pg_attribute where - attrelid = conrelid and - attnum = conkey[1] + attrelid = conrelid and attnum = conkey[1] ), coninhcount, conislocal @@ -2152,8 +1922,7 @@ create table inh_multiparent2 ( a int not null, f1 int ) -inherits (inh_p3, -inh_multiparent); +inherits (inh_p3, inh_multiparent); select cast(conrelid as regclass), @@ -2165,8 +1934,7 @@ select from pg_attribute where - attrelid = conrelid and - attnum = conkey[1] + attrelid = conrelid and attnum = conkey[1] ), coninhcount, conislocal @@ -2280,8 +2048,7 @@ create table inh_nn3 () inherits (inh_nn2); create table inh_nn4 () -inherits (inh_nn1, -inh_nn2); +inherits (inh_nn1, inh_nn2); select cast(conrelid as regclass), @@ -2319,10 +2086,7 @@ from pg_constraint where contype = 'n' and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_nn1', 'inh_nn2', 'inh_nn3' - ) + cast(cast(conrelid as regclass) as text) in ('inh_nn1', 'inh_nn2', 'inh_nn3') order by 2, 1; @@ -2337,20 +2101,14 @@ from pg_constraint where contype = 'n' and - cast(cast(conrelid as regclass) as text) - in ( - 'inh_nn1', 'inh_nn2', 'inh_nn3' - ) + cast(cast(conrelid as regclass) as text) in ('inh_nn1', 'inh_nn2', 'inh_nn3') order by 2, 1; drop table inh_nn1, inh_nn2, inh_nn3; create table inh_nn1 ( - f1 int - check (f1 > 5) - primary key - references inh_nn1, + f1 int check (f1 > 5) primary key references inh_nn1, f2 int not null ); @@ -2365,7 +2123,7 @@ create role regress_bob; grant all on schema public to regress_alice, regress_bob; -grant REGRESS_ALICE to regress_bob; +grant regress_alice to regress_bob; set session authorization regress_alice; @@ -2424,7 +2182,7 @@ drop table inh_perm_parent cascade; drop table inh_temp_parent cascade; create table list_parted (a varchar) -partition by LIST(a); +partition by list(a); create table part_ab_cd partition of list_parted for values in ('ab', 'cd'); @@ -2453,7 +2211,7 @@ partition by range(a); create table part_1_10 partition of range_list_parted for values from (1) to (10) -partition by LIST(b); +partition by list(b); create table part_1_10_ab partition of part_1_10 for values in ('ab'); @@ -2462,7 +2220,7 @@ create table part_1_10_cd partition of part_1_10 for values in ('cd'); create table part_10_20 partition of range_list_parted for values from (10) to (20) -partition by LIST(b); +partition by list(b); create table part_10_20_ab partition of part_10_20 for values in ('ab'); @@ -2471,7 +2229,7 @@ create table part_10_20_cd partition of part_10_20 for values in ('cd'); create table part_21_30 partition of range_list_parted for values from (21) to (30) -partition by LIST(b); +partition by list(b); create table part_21_30_ab partition of part_21_30 for values in ('ab'); @@ -2480,7 +2238,7 @@ create table part_21_30_cd partition of part_21_30 for values in ('cd'); create table part_40_inf partition of range_list_parted for values from (40) to (maxvalue) -partition by LIST(b); +partition by list(b); create table part_40_inf_ab partition of part_40_inf for values in ('ab'); @@ -2519,11 +2277,7 @@ create table mcrparted_def partition of mcrparted default; create table mcrparted0 partition of mcrparted -for values from (minvalue, -minvalue, -minvalue) to (1, -1, -1); +for values from (minvalue, minvalue, minvalue) to (1, 1, 1); create table mcrparted1 partition of mcrparted @@ -2531,35 +2285,19 @@ for values from (1, 1, 1) to (10, 5, 10); create table mcrparted2 partition of mcrparted -for values from (10, -5, -10) to (10, -10, -10); +for values from (10, 5, 10) to (10, 10, 10); create table mcrparted3 partition of mcrparted -for values from (11, -1, -1) to (20, -10, -10); +for values from (11, 1, 1) to (20, 10, 10); create table mcrparted4 partition of mcrparted -for values from (20, -10, -10) to (20, -20, -20); +for values from (20, 10, 10) to (20, 20, 20); create table mcrparted5 partition of mcrparted -for values from (20, -20, -20) to (maxvalue, -maxvalue, -maxvalue); +for values from (20, 20, 20) to (maxvalue, maxvalue, maxvalue); select * from mcrparted where a = 0; @@ -2585,17 +2323,17 @@ create table parted_minmax1 partition of parted_minmax for values from (1) to (10); -create index "parted_minmax1i" on parted_minmax1 using btree (a, b); +create index parted_minmax1i on parted_minmax1 using btree (a, b); insert into parted_minmax values (1, '12345'); -select MIN(a), MAX(a) from parted_minmax where b = '12345'; +select min(a), max(a) from parted_minmax where b = '12345'; -select MIN(a), MAX(a) from parted_minmax where b = '12345'; +select min(a), max(a) from parted_minmax where b = '12345'; drop table parted_minmax; -create index "mcrparted_a_abs_c_idx" on mcrparted using btree (a, (abs(b)), c); +create index mcrparted_a_abs_c_idx on mcrparted using btree (a, (abs(b)), c); select * from mcrparted order by a, abs(b), c; @@ -2609,12 +2347,8 @@ drop table mcrparted5; create table mcrparted5 partition of mcrparted -for values from (20, -20, -20) to (maxvalue, -maxvalue, -maxvalue) -partition by LIST(a); +for values from (20, 20, 20) to (maxvalue, maxvalue, maxvalue) +partition by list(a); create table mcrparted5a partition of mcrparted5 for values in (20); @@ -2633,7 +2367,7 @@ set enable_bitmapscan = off; set enable_sort = off; create table mclparted (a int) -partition by LIST(a); +partition by list(a); create table mclparted1 partition of mclparted for values in (1); @@ -2697,8 +2431,8 @@ reset enable_bitmapscan; drop table mcrparted; -create table bool_lp (b boolean) -partition by LIST(b); +create table bool_lp (b bool) +partition by list(b); create table bool_lp_true partition of bool_lp for values in (true); @@ -2711,34 +2445,26 @@ select * from bool_lp order by b; drop table bool_lp; create table bool_rp ( - b boolean, + b bool, a int ) partition by range(b, a); create table bool_rp_false_1k partition of bool_rp -for values from (false, -0) to (false, -1000); +for values from (false, 0) to (false, 1000); create table bool_rp_true_1k partition of bool_rp -for values from (true, -0) to (true, -1000); +for values from (true, 0) to (true, 1000); create table bool_rp_false_2k partition of bool_rp -for values from (false, -1000) to (false, -2000); +for values from (false, 1000) to (false, 2000); create table bool_rp_true_2k partition of bool_rp -for values from (true, -1000) to (true, -2000); +for values from (true, 1000) to (true, 2000); create index on bool_rp using btree (b, a); @@ -2780,14 +2506,14 @@ create table permtest_parent ( b text, c text ) -partition by LIST(a); +partition by list(a); create table permtest_child ( b text, c text, a int ) -partition by LIST(b); +partition by list(b); create table permtest_grandchild ( c text, @@ -2819,7 +2545,7 @@ create role regress_no_child_access; revoke all on table permtest_grandchild from regress_no_child_access; -grant SELECT on table permtest_parent to regress_no_child_access; +grant select on table permtest_parent to regress_no_child_access; set session authorization regress_no_child_access; @@ -2843,7 +2569,7 @@ reset session_authorization; revoke all on table permtest_parent from regress_no_child_access; -grant SELECT (a, c) on table permtest_parent to regress_no_child_access; +grant select (a, c) on table permtest_parent to regress_no_child_access; set session authorization regress_no_child_access; @@ -2877,21 +2603,21 @@ create table errtst_parent ( partid int not null, shdata int not null, data int not null default 0, - constraint "shdata_small" check (shdata < 3) + constraint shdata_small check (shdata < 3) ) partition by range(partid); create table errtst_child_fastdef ( partid int not null, shdata int not null, - constraint "shdata_small" check (shdata < 3) + constraint shdata_small check (shdata < 3) ); create table errtst_child_plaindef ( partid int not null, shdata int not null, data int not null default 0, - constraint "shdata_small" check (shdata < 3), + constraint shdata_small check (shdata < 3), check (data < 10) ); @@ -2899,7 +2625,7 @@ create table errtst_child_reorder ( data int not null default 0, shdata int not null, partid int not null, - constraint "shdata_small" check (shdata < 3), + constraint shdata_small check (shdata < 3), check (data < 10) ); @@ -2907,22 +2633,19 @@ alter table errtst_child_fastdef add column data int not null default 0; alter table errtst_child_fastdef - add constraint "errtest_child_fastdef_data_check" check (data < 10); + add constraint errtest_child_fastdef_data_check check (data < 10); alter table errtst_parent attach partition - errtst_child_fastdef - for values from (0) to (10); + errtst_child_fastdef for values from (0) to (10); alter table errtst_parent attach partition - errtst_child_plaindef - for values from (10) to (20); + errtst_child_plaindef for values from (10) to (20); alter table errtst_parent attach partition - errtst_child_reorder - for values from (20) to (30); + errtst_child_reorder for values from (20) to (30); insert into errtst_parent (partid, shdata, data) values ('0', '1', '5'); @@ -3021,12 +2744,7 @@ create table tuplesest_tab ( ); insert into tuplesest_parted -select - i % 200, - i % 300, - i % 400 -from - generate_series(1, 1000) as i; +select i % 200, i % 300, i % 400 from generate_series(1, 1000) as i; insert into tuplesest_tab select i, i from generate_series(1, 100) as i; @@ -3039,16 +2757,7 @@ select from tuplesest_tab inner join - ( - select - b - from - tuplesest_parted - where - c < 100 - group by b - ) - as sub + (select b from tuplesest_parted where c < 100 group by b) as sub on tuplesest_tab.a = sub.b; drop table tuplesest_parted; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__init_privs_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__init_privs_100.snap index 1f6d7783b..851958fa3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__init_privs_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__init_privs_100.snap @@ -3,10 +3,10 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/init_privs.sql snapshot_kind: text --- -select COUNT(*) > 0 from pg_init_privs; +select count(*) > 0 from pg_init_privs; -grant SELECT on table pg_proc to current_user; +grant select on table pg_proc to current_user; -grant SELECT (prosrc) on table pg_proc to current_user; +grant select (prosrc) on table pg_proc to current_user; -grant SELECT (rolname, rolsuper) on table pg_authid to current_user; +grant select (rolname, rolsuper) on table pg_authid to current_user; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__init_privs_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__init_privs_80.snap index 1f6d7783b..851958fa3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__init_privs_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__init_privs_80.snap @@ -3,10 +3,10 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/init_privs.sql snapshot_kind: text --- -select COUNT(*) > 0 from pg_init_privs; +select count(*) > 0 from pg_init_privs; -grant SELECT on table pg_proc to current_user; +grant select on table pg_proc to current_user; -grant SELECT (prosrc) on table pg_proc to current_user; +grant select (prosrc) on table pg_proc to current_user; -grant SELECT (rolname, rolsuper) on table pg_authid to current_user; +grant select (rolname, rolsuper) on table pg_authid to current_user; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_100.snap index 94c5e876d..155e49558 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_100.snap @@ -3,8 +3,8 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/insert.sql --- create table inserttest ( - col1 int, - col2 int not null, + col1 int4, + col2 int4 not null, col3 text default 'testing' ); @@ -34,11 +34,7 @@ insert into inserttest values (10, 20, '40'), (-1, 2, default), - ( - (select 2), - (select i from (values (3)) as foo (i)), - 'values are fun!' - ); + ((select 2), (select i from (values (3)) as foo (i)), 'values are fun!'); select * from inserttest; @@ -116,14 +112,12 @@ create table inserttest2 ( create rule irule1 as on insert to inserttest2 do - insert into inserttest (f3."if2"[1], f3."if2"[2]) - values (new.f1, new.f2);; + insert into inserttest (f3."if2"[1], f3."if2"[2]) values (new.f1, new.f2);; create rule irule2 as on insert to inserttest2 do - insert into inserttest (f4[1]."if1", f4[1]."if2"[2]) - values (1, 'fool'), (new.f1, new.f2);; + insert into inserttest (f4[1]."if1", f4[1]."if2"[2]) values (1, 'fool'), (new.f1, new.f2);; select new.f1, new.f2; @@ -182,15 +176,10 @@ insert into inserttestb (f3."if2"[1], f3."if2"[2]) select 'bear', 'beer'; insert into inserttestb (f3, f4[1]."if2"[1], f4[1]."if2"[2]) values (row(1, '{x}'), 'foo', 'bar'); insert into inserttestb (f3, f4[1]."if2"[1], f4[1]."if2"[2]) -values - (row(1, '{x}'), 'foo', 'bar'), - (row(2, '{y}'), 'baz', 'quux'); +values (row(1, '{x}'), 'foo', 'bar'), (row(2, '{y}'), 'baz', 'quux'); insert into inserttestb (f3, f4[1]."if2"[1], f4[1]."if2"[2]) -select - cast(row(1, '{x}') as insert_test_domain), - 'bear', - 'beer'; +select cast(row(1, '{x}') as insert_test_domain), 'bear', 'beer'; select * from inserttesta; @@ -204,14 +193,12 @@ create table inserttest2 ( create rule irule1 as on insert to inserttest2 do - insert into inserttestb (f3."if2"[1], f3."if2"[2]) - values (new.f1, new.f2);; + insert into inserttestb (f3."if2"[1], f3."if2"[2]) values (new.f1, new.f2);; create rule irule2 as on insert to inserttest2 do - insert into inserttestb (f4[1]."if1", f4[1]."if2"[2]) - values (1, 'fool'), (new.f1, new.f2);; + insert into inserttestb (f4[1]."if1", f4[1]."if2"[2]) values (1, 'fool'), (new.f1, new.f2);; select new.f1, new.f2; @@ -228,8 +215,7 @@ drop domain insert_test_domain; create domain insert_nnarray as int[] check (value[1] is not null and value[2] is not null); create domain insert_test_domain as insert_test_type - check ((value).if1 is not null and - (value).if2 is not null); + check ((value).if1 is not null and (value).if2 is not null); create table inserttesta (f1 insert_nnarray); @@ -287,7 +273,7 @@ create table list_parted ( a text, b int ) -partition by LIST((lower(a))); +partition by list((lower(a))); create table part_aa_bb partition of list_parted for values in ('aa', 'bb'); @@ -321,7 +307,7 @@ insert into part_default values ('Zz', 2); drop table part_default; -create table part_xx_yy partition of list_parted for values in ('xx', 'yy') partition by LIST(a); +create table part_xx_yy partition of list_parted for values in ('xx', 'yy') partition by list(a); create table part_xx_yy_p1 partition of part_xx_yy for values in ('xx'); @@ -430,8 +416,8 @@ insert into list_parted (b) values (1); select cast(cast(tableoid as regclass) as text), a, - MIN(b) as min_b, - MAX(b) as max_b + min(b) as min_b, + max(b) as max_b from list_parted group by 1, @@ -439,15 +425,15 @@ group by 1, order by 1; create table hash_parted (a int) -partition by HASH(a part_test_int4_ops); +partition by hash(a part_test_int4_ops); -create table hpart0 partition of hash_parted for values with (MODULUS 4, REMAINDER 0); +create table hpart0 partition of hash_parted for values with (modulus 4, remainder 0); -create table hpart1 partition of hash_parted for values with (MODULUS 4, REMAINDER 1); +create table hpart1 partition of hash_parted for values with (modulus 4, remainder 1); -create table hpart2 partition of hash_parted for values with (MODULUS 4, REMAINDER 2); +create table hpart2 partition of hash_parted for values with (modulus 4, remainder 2); -create table hpart3 partition of hash_parted for values with (MODULUS 4, REMAINDER 3); +create table hpart3 partition of hash_parted for values with (modulus 4, remainder 3); insert into hash_parted values (generate_series(1, 10)); @@ -470,7 +456,7 @@ drop table range_parted, list_parted; drop table hash_parted; create table list_parted (a int) -partition by LIST(a); +partition by list(a); create table part_default partition of list_parted default; @@ -542,17 +528,17 @@ insert into mlparted (a, b) values (1, 5); truncate mlparted; alter table mlparted - add constraint "check_b" check (b = 3); + add constraint check_b check (b = 3); create function mlparted11_trig_fn() returns trigger language plpgsql -as $function$ +as $$ begin NEW.b := 4; return NEW; end; -$function$; +$$; create trigger mlparted11_trig before insert @@ -572,7 +558,7 @@ create table lparted_nonullpart ( a int, b char(1) ) -partition by LIST(b); +partition by list(b); create table lparted_nonullpart_a partition of lparted_nonullpart for values in ('a'); @@ -609,9 +595,7 @@ alter table mlparted mlparted4 for values from (1, 30) to (1, 40); with -ins (a, -b, -c) +ins (a, b, c) as ( insert into mlparted (b, a) select s.a, 1 from generate_series(2, 39) as s (a) @@ -621,8 +605,8 @@ as ( select a, b, - MIN(c), - MAX(c) + min(c), + max(c) from ins group by a, @@ -637,7 +621,7 @@ create table mlparted5 ( a int not null, b int not null ) -partition by LIST(c); +partition by list(c); create table mlparted5a ( a int not null, @@ -654,16 +638,14 @@ alter table mlparted mlparted5 for values from (1, 40) to (1, 50); alter table mlparted - add constraint "check_b" check (a = 1 and b < 45); + add constraint check_b check (a = 1 and b < 45); insert into mlparted values (1, 45, 'a'); create function mlparted5abrtrig_func() returns trigger language plpgsql -as $function$ -begin new.c = 'b'; return new; end; -$function$; +as $$ begin new.c = 'b'; return new; end; $$; create trigger mlparted5abrtrig before insert @@ -717,12 +699,12 @@ partition by range(c); create table mlparted5_ab partition of mlparted5 for values from ('a') to ('c') -partition by LIST(c); +partition by list(c); create table mlparted5_cd partition of mlparted5 for values from ('c') to ('e') -partition by LIST(c); +partition by list(c); create table mlparted5_a partition of mlparted5_ab for values in ('a'); @@ -784,15 +766,15 @@ create table key_desc ( a int, b int ) -partition by LIST((a + 0)); +partition by list((a + 0)); create table key_desc_1 partition of key_desc for values in (1) partition by range(b); create user regress_insert_other_user; -grant SELECT (a) on table key_desc_1 to regress_insert_other_user; +grant select (a) on table key_desc_1 to regress_insert_other_user; -grant INSERT on table key_desc to regress_insert_other_user; +grant insert on table key_desc to regress_insert_other_user; set role to regress_insert_other_user; @@ -800,7 +782,7 @@ insert into key_desc values (1, 1); reset role; -grant SELECT (b) on table key_desc_1 to regress_insert_other_user; +grant select (b) on table key_desc_1 to regress_insert_other_user; set role to regress_insert_other_user; @@ -827,63 +809,35 @@ partition by range(a, (abs(b)), c); create table mcrparted0 partition of mcrparted -for values from (minvalue, -0, -0) to (1, -maxvalue, -maxvalue); +for values from (minvalue, 0, 0) to (1, maxvalue, maxvalue); create table mcrparted2 partition of mcrparted -for values from (10, -6, -minvalue) to (10, -maxvalue, -minvalue); +for values from (10, 6, minvalue) to (10, maxvalue, minvalue); create table mcrparted4 partition of mcrparted -for values from (21, -minvalue, -0) to (30, -20, -minvalue); +for values from (21, minvalue, 0) to (30, 20, minvalue); create table mcrparted0 partition of mcrparted -for values from (minvalue, -minvalue, -minvalue) to (1, -maxvalue, -maxvalue); +for values from (minvalue, minvalue, minvalue) to (1, maxvalue, maxvalue); create table mcrparted1 partition of mcrparted for values from (2, 1, minvalue) to (10, 5, 10); create table mcrparted2 partition of mcrparted -for values from (10, -6, -minvalue) to (10, -maxvalue, -maxvalue); +for values from (10, 6, minvalue) to (10, maxvalue, maxvalue); create table mcrparted3 partition of mcrparted for values from (11, 1, 1) to (20, 10, 10); create table mcrparted4 partition of mcrparted -for values from (21, -minvalue, -minvalue) to (30, -20, -maxvalue); +for values from (21, minvalue, minvalue) to (30, 20, maxvalue); create table mcrparted5 partition of mcrparted -for values from (30, -21, -20) to (maxvalue, -maxvalue, -maxvalue); +for values from (30, 21, 20) to (maxvalue, maxvalue, maxvalue); insert into mcrparted values (null, null, null); @@ -929,16 +883,14 @@ create table brtrigpartcon ( a int, b text ) -partition by LIST(a); +partition by list(a); create table brtrigpartcon1 partition of brtrigpartcon for values in (1); create or replace function brtrigpartcon1trigf() returns trigger language plpgsql -as $function$ -begin new.a := 2; return new; end -$function$; +as $$begin new.a := 2; return new; end$$; create trigger brtrigpartcon1trig before insert @@ -958,21 +910,15 @@ create table inserttest3 ( create role regress_coldesc_role; -grant INSERT on table inserttest3 to regress_coldesc_role; +grant insert on table inserttest3 to regress_coldesc_role; -grant INSERT on table brtrigpartcon to regress_coldesc_role; +grant insert on table brtrigpartcon to regress_coldesc_role; -revoke SELECT on table brtrigpartcon from regress_coldesc_role; +revoke select on table brtrigpartcon from regress_coldesc_role; set role to regress_coldesc_role; -with -result -as ( - insert into brtrigpartcon - values (1, 'hi there') - returning 1 -) +with result as (insert into brtrigpartcon values (1, 'hi there') returning 1) insert into inserttest3 (f3) select * from result; @@ -994,7 +940,7 @@ create table donothingbrtrig_test ( a int, b text ) -partition by LIST(a); +partition by list(a); create table donothingbrtrig_test1 ( b text, @@ -1013,9 +959,7 @@ alter table donothingbrtrig_test2 create or replace function donothingbrtrig_func() returns trigger language plpgsql -as $function$ -begin raise notice 'b: %', new.b; return NULL; end -$function$; +as $$begin raise notice 'b: %', new.b; return NULL; end$$; create trigger donothingbrtrig1 before insert @@ -1055,23 +999,17 @@ partition by range(a, b); create table mcrparted1_lt_b partition of mcrparted -for values from (minvalue, -minvalue) to ('b', -minvalue); +for values from (minvalue, minvalue) to ('b', minvalue); create table mcrparted2_b partition of mcrparted for values from ('b', minvalue) to ('c', minvalue); create table mcrparted3_c_to_common partition of mcrparted -for values from ('c', -minvalue) to ('common', -minvalue); +for values from ('c', minvalue) to ('common', minvalue); create table mcrparted4_common_lt_0 partition of mcrparted -for values from ('common', -minvalue) to ('common', -0); +for values from ('common', minvalue) to ('common', 0); create table mcrparted5_common_0_to_10 partition of mcrparted @@ -1079,21 +1017,15 @@ for values from ('common', 0) to ('common', 10); create table mcrparted6_common_ge_10 partition of mcrparted -for values from ('common', -10) to ('common', -maxvalue); +for values from ('common', 10) to ('common', maxvalue); create table mcrparted7_gt_common_lt_d partition of mcrparted -for values from ('common', -maxvalue) to ('d', -minvalue); +for values from ('common', maxvalue) to ('d', minvalue); create table mcrparted8_ge_d partition of mcrparted -for values from ('d', -minvalue) to (maxvalue, -maxvalue); +for values from ('d', minvalue) to (maxvalue, maxvalue); insert into mcrparted values @@ -1114,7 +1046,7 @@ select cast(tableoid as regclass), * from mcrparted order by a, b; drop table mcrparted; create table returningwrtest (a int) -partition by LIST(a); +partition by list(a); create table returningwrtest1 partition of returningwrtest for values in (1); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_80.snap index 8db82de9a..9f32c450c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_80.snap @@ -3,8 +3,8 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/insert.sql --- create table inserttest ( - col1 int, - col2 int not null, + col1 int4, + col2 int4 not null, col3 text default 'testing' ); @@ -34,11 +34,7 @@ insert into inserttest values (10, 20, '40'), (-1, 2, default), - ( - (select 2), - (select i from (values (3)) as foo (i)), - 'values are fun!' - ); + ((select 2), (select i from (values (3)) as foo (i)), 'values are fun!'); select * from inserttest; @@ -63,10 +59,7 @@ insert into large_tuple_test select 2, repeat('a', 1000); select pg_size_pretty( - pg_relation_size( - cast('large_tuple_test' as regclass), - 'main' - ) + pg_relation_size(cast('large_tuple_test' as regclass), 'main') ); insert into large_tuple_test select 3, null; @@ -124,8 +117,7 @@ create table inserttest2 ( create rule irule1 as on insert to inserttest2 do - insert into inserttest (f3."if2"[1], f3."if2"[2]) - values (new.f1, new.f2);; + insert into inserttest (f3."if2"[1], f3."if2"[2]) values (new.f1, new.f2);; create rule irule2 as on insert to inserttest2 @@ -193,16 +185,10 @@ insert into inserttestb (f3, f4[1]."if2"[1], f4[1]."if2"[2]) values (row(1, '{x}'), 'foo', 'bar'); insert into inserttestb (f3, f4[1]."if2"[1], f4[1]."if2"[2]) -values - (row(1, '{x}'), 'foo', 'bar'), - (row(2, '{y}'), 'baz', 'quux'); +values (row(1, '{x}'), 'foo', 'bar'), (row(2, '{y}'), 'baz', 'quux'); insert into inserttestb (f3, f4[1]."if2"[1], f4[1]."if2"[2]) -select - cast(row(1, '{x}') - as insert_test_domain), - 'bear', - 'beer'; +select cast(row(1, '{x}') as insert_test_domain), 'bear', 'beer'; select * from inserttesta; @@ -216,8 +202,7 @@ create table inserttest2 ( create rule irule1 as on insert to inserttest2 do - insert into inserttestb (f3."if2"[1], f3."if2"[2]) - values (new.f1, new.f2);; + insert into inserttestb (f3."if2"[1], f3."if2"[2]) values (new.f1, new.f2);; create rule irule2 as on insert to inserttest2 @@ -238,12 +223,10 @@ drop domain insert_pos_ints; drop domain insert_test_domain; create domain insert_nnarray as int[] - check (value[1] is not null and - value[2] is not null); + check (value[1] is not null and value[2] is not null); create domain insert_test_domain as insert_test_type - check ((value).if1 is not null and - (value).if2 is not null); + check ((value).if1 is not null and (value).if2 is not null); create table inserttesta (f1 insert_nnarray); @@ -309,7 +292,7 @@ create table list_parted ( a text, b int ) -partition by LIST((lower(a))); +partition by list((lower(a))); create table part_aa_bb partition of list_parted for values in ('aa', 'bb'); @@ -349,7 +332,7 @@ drop table part_default; create table part_xx_yy partition of list_parted for values in ('xx', 'yy') -partition by LIST(a); +partition by list(a); create table part_xx_yy_p1 partition of part_xx_yy for values in ('xx'); @@ -478,8 +461,8 @@ insert into list_parted (b) values (1); select cast(cast(tableoid as regclass) as text), a, - MIN(b) as min_b, - MAX(b) as max_b + min(b) as min_b, + max(b) as max_b from list_parted group by 1, @@ -487,23 +470,23 @@ group by 1, order by 1; create table hash_parted (a int) -partition by HASH(a part_test_int4_ops); +partition by hash(a part_test_int4_ops); create table hpart0 partition of hash_parted -for values with (MODULUS 4, REMAINDER 0); +for values with (modulus 4, remainder 0); create table hpart1 partition of hash_parted -for values with (MODULUS 4, REMAINDER 1); +for values with (modulus 4, remainder 1); create table hpart2 partition of hash_parted -for values with (MODULUS 4, REMAINDER 2); +for values with (modulus 4, remainder 2); create table hpart3 partition of hash_parted -for values with (MODULUS 4, REMAINDER 3); +for values with (modulus 4, remainder 3); insert into hash_parted values (generate_series(1, 10)); @@ -526,7 +509,7 @@ drop table range_parted, list_parted; drop table hash_parted; create table list_parted (a int) -partition by LIST(a); +partition by list(a); create table part_default partition of list_parted default; @@ -577,8 +560,7 @@ where ( attrelid = cast('mlparted' as regclass) or attrelid = cast('mlparted1' as regclass) or - attrelid = - cast('mlparted11' as regclass) + attrelid = cast('mlparted11' as regclass) ) order by cast(cast(attrelid as regclass) as text); @@ -588,8 +570,7 @@ alter table mlparted1 alter table mlparted attach partition - mlparted1 - for values from (1, 2) to (1, 10); + mlparted1 for values from (1, 2) to (1, 10); insert into mlparted values (1, 2); @@ -600,17 +581,17 @@ insert into mlparted (a, b) values (1, 5); truncate mlparted; alter table mlparted - add constraint "check_b" check (b = 3); + add constraint check_b check (b = 3); create function mlparted11_trig_fn() returns trigger language plpgsql -as $function$ +as $$ begin NEW.b := 4; return NEW; end; -$function$; +$$; create trigger mlparted11_trig before insert @@ -630,7 +611,7 @@ create table lparted_nonullpart ( a int, b char(1) ) -partition by LIST(b); +partition by list(b); create table lparted_nonullpart_a partition of lparted_nonullpart @@ -652,8 +633,7 @@ create table mlparted2 ( alter table mlparted attach partition - mlparted2 - for values from (1, 10) to (1, 20); + mlparted2 for values from (1, 10) to (1, 20); create table mlparted3 partition of mlparted for values from (1, 20) to (1, 30); @@ -667,28 +647,21 @@ alter table mlparted4 alter table mlparted attach partition - mlparted4 - for values from (1, 30) to (1, 40); + mlparted4 for values from (1, 30) to (1, 40); with -ins (a, -b, -c) +ins (a, b, c) as ( insert into mlparted (b, a) - select - s.a, - 1 - from - generate_series(2, 39) as s (a) + select s.a, 1 from generate_series(2, 39) as s (a) returning cast(tableoid as regclass), * ) select a, b, - MIN(c), - MAX(c) + min(c), + max(c) from ins group by a, @@ -703,7 +676,7 @@ create table mlparted5 ( a int not null, b int not null ) -partition by LIST(c); +partition by list(c); create table mlparted5a ( a int not null, @@ -717,20 +690,17 @@ alter table mlparted5 alter table mlparted attach partition - mlparted5 - for values from (1, 40) to (1, 50); + mlparted5 for values from (1, 40) to (1, 50); alter table mlparted - add constraint "check_b" check (a = 1 and b < 45); + add constraint check_b check (a = 1 and b < 45); insert into mlparted values (1, 45, 'a'); create function mlparted5abrtrig_func() returns trigger language plpgsql -as $function$ -begin new.c = 'b'; return new; end; -$function$; +as $$ begin new.c = 'b'; return new; end; $$; create trigger mlparted5abrtrig before insert @@ -788,12 +758,12 @@ partition by range(c); create table mlparted5_ab partition of mlparted5 for values from ('a') to ('c') -partition by LIST(c); +partition by list(c); create table mlparted5_cd partition of mlparted5 for values from ('c') to ('e') -partition by LIST(c); +partition by list(c); create table mlparted5_a partition of mlparted5_ab for values in ('a'); @@ -855,7 +825,7 @@ create table key_desc ( a int, b int ) -partition by LIST((a + 0)); +partition by list((a + 0)); create table key_desc_1 partition of key_desc @@ -864,9 +834,9 @@ partition by range(b); create user regress_insert_other_user; -grant SELECT (a) on table key_desc_1 to regress_insert_other_user; +grant select (a) on table key_desc_1 to regress_insert_other_user; -grant INSERT on table key_desc to regress_insert_other_user; +grant insert on table key_desc to regress_insert_other_user; set role to regress_insert_other_user; @@ -874,7 +844,7 @@ insert into key_desc values (1, 1); reset role; -grant SELECT (b) on table key_desc_1 to regress_insert_other_user; +grant select (b) on table key_desc_1 to regress_insert_other_user; set role to regress_insert_other_user; @@ -901,75 +871,39 @@ partition by range(a, (abs(b)), c); create table mcrparted0 partition of mcrparted -for values from (minvalue, -0, -0) to (1, -maxvalue, -maxvalue); +for values from (minvalue, 0, 0) to (1, maxvalue, maxvalue); create table mcrparted2 partition of mcrparted -for values from (10, -6, -minvalue) to (10, -maxvalue, -minvalue); +for values from (10, 6, minvalue) to (10, maxvalue, minvalue); create table mcrparted4 partition of mcrparted -for values from (21, -minvalue, -0) to (30, -20, -minvalue); +for values from (21, minvalue, 0) to (30, 20, minvalue); create table mcrparted0 partition of mcrparted -for values from (minvalue, -minvalue, -minvalue) to (1, -maxvalue, -maxvalue); +for values from (minvalue, minvalue, minvalue) to (1, maxvalue, maxvalue); create table mcrparted1 partition of mcrparted -for values from (2, -1, -minvalue) to (10, -5, -10); +for values from (2, 1, minvalue) to (10, 5, 10); create table mcrparted2 partition of mcrparted -for values from (10, -6, -minvalue) to (10, -maxvalue, -maxvalue); +for values from (10, 6, minvalue) to (10, maxvalue, maxvalue); create table mcrparted3 partition of mcrparted -for values from (11, -1, -1) to (20, -10, -10); +for values from (11, 1, 1) to (20, 10, 10); create table mcrparted4 partition of mcrparted -for values from (21, -minvalue, -minvalue) to (30, -20, -maxvalue); +for values from (21, minvalue, minvalue) to (30, 20, maxvalue); create table mcrparted5 partition of mcrparted -for values from (30, -21, -20) to (maxvalue, -maxvalue, -maxvalue); +for values from (30, 21, 20) to (maxvalue, maxvalue, maxvalue); insert into mcrparted values (null, null, null); @@ -1015,16 +949,14 @@ create table brtrigpartcon ( a int, b text ) -partition by LIST(a); +partition by list(a); create table brtrigpartcon1 partition of brtrigpartcon for values in (1); create or replace function brtrigpartcon1trigf() returns trigger language plpgsql -as $function$ -begin new.a := 2; return new; end -$function$; +as $$begin new.a := 2; return new; end$$; create trigger brtrigpartcon1trig before insert @@ -1044,21 +976,15 @@ create table inserttest3 ( create role regress_coldesc_role; -grant INSERT on table inserttest3 to regress_coldesc_role; +grant insert on table inserttest3 to regress_coldesc_role; -grant INSERT on table brtrigpartcon to regress_coldesc_role; +grant insert on table brtrigpartcon to regress_coldesc_role; -revoke SELECT on table brtrigpartcon from regress_coldesc_role; +revoke select on table brtrigpartcon from regress_coldesc_role; set role to regress_coldesc_role; -with -result -as ( - insert into brtrigpartcon - values (1, 'hi there') - returning 1 -) +with result as (insert into brtrigpartcon values (1, 'hi there') returning 1) insert into inserttest3 (f3) select * from result; @@ -1080,7 +1006,7 @@ create table donothingbrtrig_test ( a int, b text ) -partition by LIST(a); +partition by list(a); create table donothingbrtrig_test1 ( b text, @@ -1099,9 +1025,7 @@ alter table donothingbrtrig_test2 create or replace function donothingbrtrig_func() returns trigger language plpgsql -as $function$ -begin raise notice 'b: %', new.b; return NULL; end -$function$; +as $$begin raise notice 'b: %', new.b; return NULL; end$$; create trigger donothingbrtrig1 before insert @@ -1141,51 +1065,35 @@ partition by range(a, b); create table mcrparted1_lt_b partition of mcrparted -for values from (minvalue, -minvalue) to ('b', -minvalue); +for values from (minvalue, minvalue) to ('b', minvalue); create table mcrparted2_b partition of mcrparted -for values from ('b', -minvalue) to ('c', -minvalue); +for values from ('b', minvalue) to ('c', minvalue); create table mcrparted3_c_to_common partition of mcrparted -for values from ('c', -minvalue) to ('common', -minvalue); +for values from ('c', minvalue) to ('common', minvalue); create table mcrparted4_common_lt_0 partition of mcrparted -for values from ('common', -minvalue) to ('common', -0); +for values from ('common', minvalue) to ('common', 0); create table mcrparted5_common_0_to_10 partition of mcrparted -for values from ('common', -0) to ('common', -10); +for values from ('common', 0) to ('common', 10); create table mcrparted6_common_ge_10 partition of mcrparted -for values from ('common', -10) to ('common', -maxvalue); +for values from ('common', 10) to ('common', maxvalue); create table mcrparted7_gt_common_lt_d partition of mcrparted -for values from ('common', -maxvalue) to ('d', -minvalue); +for values from ('common', maxvalue) to ('d', minvalue); create table mcrparted8_ge_d partition of mcrparted -for values from ('d', -minvalue) to (maxvalue, -maxvalue); +for values from ('d', minvalue) to (maxvalue, maxvalue); insert into mcrparted values @@ -1206,7 +1114,7 @@ select cast(tableoid as regclass), * from mcrparted order by a, b; drop table mcrparted; create table returningwrtest (a int) -partition by LIST(a); +partition by list(a); create table returningwrtest1 partition of returningwrtest for values in (1); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_conflict_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_conflict_100.snap index 2109f230b..66014e05c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_conflict_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_conflict_100.snap @@ -3,35 +3,23 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/insert_conflict.sql --- create table insertconflicttest ( - key int, + key int4, fruit text ); create view insertconflictview as select * from insertconflicttest; -create unique index "op_index_key" on insertconflicttest using btree (key, fruit text_pattern_ops); +create unique index op_index_key on insertconflicttest using btree (key, fruit text_pattern_ops); -create unique index "collation_index_key" -on insertconflicttest -using btree -( - key, - fruit collate "C" -); +create unique index collation_index_key on insertconflicttest using btree (key, fruit collate "C"); -create unique index "both_index_key" -on insertconflicttest -using btree -( +create unique index both_index_key on insertconflicttest using btree ( key, fruit collate "C" text_pattern_ops ); -create unique index "both_index_expr_key" -on insertconflicttest -using btree -( +create unique index both_index_expr_key on insertconflicttest using btree ( key, (lower(fruit)) collate "C" text_pattern_ops ); @@ -48,15 +36,11 @@ on conflict (fruit, key, fruit, key) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -((lower(fruit)), key, (lower(fruit)), key) -do nothing; +on conflict ((lower(fruit)), key, (lower(fruit)), key) do nothing; insert into insertconflictview values (0, 'Crowberry') -on conflict -((lower(fruit)), key, (lower(fruit)), key) -do nothing; +on conflict ((lower(fruit)), key, (lower(fruit)), key) do nothing; insert into insertconflicttest values (0, 'Crowberry') @@ -66,21 +50,11 @@ do update set fruit = excluded.fruit where - exists - ( - select - 1 - from - insertconflicttest as ii - where - ii.key = excluded.key - ); + exists (select 1 from insertconflicttest as ii where ii.key = excluded.key); insert into insertconflicttest values (0, 'Crowberry') -on conflict -(key, fruit text_pattern_ops) -do nothing; +on conflict (key, fruit text_pattern_ops) do nothing; insert into insertconflicttest values (0, 'Crowberry') @@ -88,29 +62,19 @@ on conflict (key, fruit collate "C") do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -(fruit collate "C" text_pattern_ops, key) -do nothing; +on conflict (fruit collate "C" text_pattern_ops, key) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -((lower(fruit)) collate "C", key, key) -do nothing; +on conflict ((lower(fruit)) collate "C", key, key) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -(fruit, key, fruit text_pattern_ops, key) -do nothing; +on conflict (fruit, key, fruit text_pattern_ops, key) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -((lower(fruit)) collate "C" text_pattern_ops, -key, -key) -do nothing; +on conflict ((lower(fruit)) collate "C" text_pattern_ops, key, key) do nothing; drop index op_index_key; @@ -120,161 +84,86 @@ drop index both_index_key; drop index both_index_expr_key; -create unique index "cross_match" -on insertconflicttest -using btree -( +create unique index cross_match on insertconflicttest using btree ( (lower(fruit)) collate "C", (upper(fruit)) text_pattern_ops ); insert into insertconflicttest values (0, 'Crowberry') -on conflict -((lower(fruit)) text_pattern_ops, -(upper(fruit)) collate "C") -do nothing; +on conflict ((lower(fruit)) text_pattern_ops, (upper(fruit)) collate "C") do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -((lower(fruit)) collate "C", -(upper(fruit)) text_pattern_ops) -do nothing; +on conflict ((lower(fruit)) collate "C", (upper(fruit)) text_pattern_ops) do nothing; drop index cross_match; -create unique index "key_index" on insertconflicttest using btree (key); +create unique index key_index on insertconflicttest using btree (key); insert into insertconflicttest values (0, 'Bilberry') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (0, 'Bilberry') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - insertconflicttest.fruit <> 'Cawesh'; +on conflict (key) do update set fruit = excluded.fruit where insertconflicttest.fruit <> 'Cawesh'; insert into insertconflicttest values (0, 'Crowberry') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - excluded.fruit <> 'Elderberry'; +on conflict (key) do update set fruit = excluded.fruit where excluded.fruit <> 'Elderberry'; insert into insertconflicttest values (0, 'Bilberry') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - insertconflicttest.fruit <> 'Lime' +on conflict (key) do update set fruit = excluded.fruit where insertconflicttest.fruit <> 'Lime' returning *; insert into insertconflicttest values (1, 'Apple') on conflict do update set fruit = excluded.fruit; insert into insertconflicttest values (1, 'Apple') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (2, 'Orange') -on conflict -(key, key, key) -do -update -set fruit = excluded.fruit; +on conflict (key, key, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (1, 'Apple'), (2, 'Orange') -on conflict -(key) -do -update -set (fruit, key) = (excluded.fruit, excluded.key); +on conflict (key) do update set (fruit, key) = (excluded.fruit, excluded.key); insert into insertconflicttest values (1, 'Apple') -on conflict -(key) -do -update -set fruit = excluded.fruit +on conflict (key) do update set fruit = excluded.fruit returning excluded.fruit; insert into insertconflicttest values (1, 'Apple') -on conflict -(keyy) -do -update -set fruit = excluded.fruit; +on conflict (keyy) do update set fruit = excluded.fruit; insert into insertconflicttest values (1, 'Apple') -on conflict -(key) -do -update -set fruit = excluded.fruitt; +on conflict (key) do update set fruit = excluded.fruitt; insert into insertconflicttest values (3, 'Kiwi') -on conflict -(key, fruit) -do -update -set fruit = excluded.fruit; +on conflict (key, fruit) do update set fruit = excluded.fruit; insert into insertconflicttest values (4, 'Mango') -on conflict -(fruit, key) -do -update -set fruit = excluded.fruit; +on conflict (fruit, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (5, 'Lemon') -on conflict -(fruit) -do -update -set fruit = excluded.fruit; +on conflict (fruit) do update set fruit = excluded.fruit; insert into insertconflicttest values (6, 'Passionfruit') -on conflict -((lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest as ict values (6, 'Passionfruit') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest as ict values (6, 'Passionfruit') @@ -282,188 +171,99 @@ on conflict (key) do update set fruit = ict.fruit; insert into insertconflicttest as ict values (6, 'Passionfruit') -on conflict -(key) -do -update -set fruit = insertconflicttest.fruit; +on conflict (key) do update set fruit = insertconflicttest.fruit; insert into insertconflicttest values (3, 'Kiwi') -on conflict -(key, fruit) -do -update -set insertconflicttest."fruit" = 'Mango'; +on conflict (key, fruit) do update set insertconflicttest."fruit" = 'Mango'; drop index key_index; -create unique index "comp_key_index" on insertconflicttest using btree (key, fruit); +create unique index comp_key_index on insertconflicttest using btree (key, fruit); insert into insertconflicttest values (7, 'Raspberry') -on conflict -(key, fruit) -do -update -set fruit = excluded.fruit; +on conflict (key, fruit) do update set fruit = excluded.fruit; insert into insertconflicttest values (8, 'Lime') -on conflict -(fruit, key) -do -update -set fruit = excluded.fruit; +on conflict (fruit, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (9, 'Banana') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (10, 'Blueberry') -on conflict -(key, key, key) -do -update -set fruit = excluded.fruit; +on conflict (key, key, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (11, 'Cherry') -on conflict -(key, (lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict (key, (lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (12, 'Date') -on conflict -((lower(fruit)), key) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit)), key) do update set fruit = excluded.fruit; drop index comp_key_index; -create unique index "part_comp_key_index" -on insertconflicttest -using btree -( - key, - fruit -) -where - key < 5; +create unique index part_comp_key_index on insertconflicttest using btree (key, fruit) +where key < 5; -create unique index "expr_part_comp_key_index" -on insertconflicttest -using btree -( - key, - (lower(fruit)) -) -where - key < 5; +create unique index expr_part_comp_key_index on insertconflicttest using btree (key, (lower(fruit))) +where key < 5; insert into insertconflicttest values (13, 'Grape') -on conflict -(key, fruit) -do -update -set fruit = excluded.fruit; +on conflict (key, fruit) do update set fruit = excluded.fruit; insert into insertconflicttest values (14, 'Raisin') -on conflict -(fruit, key) -do -update -set fruit = excluded.fruit; +on conflict (fruit, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (15, 'Cranberry') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (16, 'Melon') -on conflict -(key, key, key) -do -update -set fruit = excluded.fruit; +on conflict (key, key, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (17, 'Mulberry') -on conflict -(key, (lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict (key, (lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (18, 'Pineapple') -on conflict -((lower(fruit)), key) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit)), key) do update set fruit = excluded.fruit; drop index part_comp_key_index; drop index expr_part_comp_key_index; -create unique index "expr_key_index" on insertconflicttest using btree ((lower(fruit))); +create unique index expr_key_index on insertconflicttest using btree ((lower(fruit))); insert into insertconflicttest values (20, 'Quince') -on conflict -((lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (21, 'Pomegranate') -on conflict -((lower(fruit)), (lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit)), (lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (22, 'Apricot') -on conflict -((upper(fruit))) -do -update -set fruit = excluded.fruit; +on conflict ((upper(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (23, 'Blackberry') -on conflict -(fruit) -do -update -set fruit = excluded.fruit; +on conflict (fruit) do update set fruit = excluded.fruit; drop index expr_key_index; -create unique index "expr_comp_key_index" on insertconflicttest using btree (key, (lower(fruit))); +create unique index expr_comp_key_index on insertconflicttest using btree (key, (lower(fruit))); -create unique index "tricky_expr_comp_key_index" -on insertconflicttest -using btree -( +create unique index tricky_expr_comp_key_index on insertconflicttest using btree ( key, (lower(fruit)), (upper(fruit)) @@ -471,210 +271,110 @@ using btree insert into insertconflicttest values (24, 'Plum') -on conflict -(key, (lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict (key, (lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (25, 'Peach') -on conflict -((lower(fruit)), key) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit)), key) do update set fruit = excluded.fruit; insert into insertconflicttest values (26, 'Fig') -on conflict -((lower(fruit)), key, (lower(fruit)), key) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit)), key, (lower(fruit)), key) do update set fruit = excluded.fruit; insert into insertconflicttest values (27, 'Prune') -on conflict -(key, (upper(fruit))) -do -update -set fruit = excluded.fruit; +on conflict (key, (upper(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (28, 'Redcurrant') -on conflict -(fruit, key) -do -update -set fruit = excluded.fruit; +on conflict (fruit, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (29, 'Nectarine') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; drop index expr_comp_key_index; drop index tricky_expr_comp_key_index; -create unique index "key_index" on insertconflicttest using btree (key); +create unique index key_index on insertconflicttest using btree (key); -create unique index "fruit_index" on insertconflicttest using btree (fruit); +create unique index fruit_index on insertconflicttest using btree (fruit); insert into insertconflicttest values (26, 'Fig') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (26, 'Peach') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (25, 'Fig') -on conflict -(fruit) -do -update -set fruit = excluded.fruit; +on conflict (fruit) do update set fruit = excluded.fruit; drop index key_index; drop index fruit_index; -create unique index "partial_key_index" -on insertconflicttest -using btree -( - key -) -where - fruit like '%berry'; +create unique index partial_key_index on insertconflicttest using btree (key) +where fruit like '%berry'; insert into insertconflicttest values (23, 'Blackberry') -on conflict -(key) where fruit like '%berry' -do -update -set fruit = excluded.fruit; +on conflict (key) where fruit like '%berry' do update set fruit = excluded.fruit; insert into insertconflicttest as t values (23, 'Blackberry') -on conflict -(key) -where - fruit like '%berry' and - t.fruit = 'inconsequential' -do nothing; +on conflict (key) where fruit like '%berry' and t.fruit = 'inconsequential' do nothing; insert into insertconflictview as t values (23, 'Blackberry') -on conflict -(key) -where - fruit like '%berry' and - t.fruit = 'inconsequential' -do nothing; +on conflict (key) where fruit like '%berry' and t.fruit = 'inconsequential' do nothing; insert into insertconflicttest values (23, 'Blackberry') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (23, 'Blackberry') -on conflict -(key) -where - fruit like '%berry' or fruit = 'consequential' -do nothing; +on conflict (key) where fruit like '%berry' or fruit = 'consequential' do nothing; insert into insertconflicttest values (23, 'Blackberry') -on conflict -(fruit) where fruit like '%berry' -do -update -set fruit = excluded.fruit; +on conflict (fruit) where fruit like '%berry' do update set fruit = excluded.fruit; drop index partial_key_index; -create unique index "plain" on insertconflicttest using btree (key); +create unique index plain on insertconflicttest using btree (key); insert into insertconflicttest as i values (23, 'Jackfruit') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - i.* <> excluded.* +on conflict (key) do update set fruit = excluded.fruit where i.* <> excluded.* returning *; insert into insertconflicttest as i values (23, 'Jackfruit') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - i.* <> excluded.* +on conflict (key) do update set fruit = excluded.fruit where i.* <> excluded.* returning *; insert into insertconflicttest as i values (23, 'Jackfruit') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - i.* = excluded.* +on conflict (key) do update set fruit = excluded.fruit where i.* = excluded.* returning *; insert into insertconflicttest as i values (23, 'Avocado') -on conflict -(key) -do -update -set fruit = cast(excluded.* as text) +on conflict (key) do update set fruit = cast(excluded.* as text) returning *; insert into insertconflicttest as i values (23, 'Avocado') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - excluded.* is null; +on conflict (key) do update set fruit = excluded.fruit where excluded.* is null; insert into insertconflicttest as i values (23, 'Avocado') -on conflict -(key) -do -update -set fruit = cast(excluded.* as text); +on conflict (key) do update set fruit = cast(excluded.* as text); drop index plain; @@ -683,7 +383,7 @@ drop view insertconflictview; drop table insertconflicttest; create table syscolconflicttest ( - key int, + key int4, data text ); @@ -691,11 +391,7 @@ insert into syscolconflicttest values (1); insert into syscolconflicttest values (1) -on conflict -(key) -do -update -set data = cast(excluded.ctid as text); +on conflict (key) do update set data = cast(excluded.ctid as text); drop table syscolconflicttest; @@ -704,16 +400,9 @@ create table insertconflict ( b bigint ); -create unique index "insertconflicti1" on insertconflict using btree ((coalesce(a, 0))); +create unique index insertconflicti1 on insertconflict using btree ((coalesce(a, 0))); -create unique index "insertconflicti2" -on insertconflict -using btree -( - b -) -where - coalesce(a, 1) > 0; +create unique index insertconflicti2 on insertconflict using btree (b) where coalesce(a, 1) > 0; insert into insertconflict values (1, 2) on conflict ((coalesce(a, 0))) do nothing; @@ -746,16 +435,16 @@ drop table insertconflict; create table cities ( name text, - population double precision, + population float8, altitude int ); create table capitals (state char(2)) inherits (cities); -create unique index "cities_names_unique" on cities using btree (name); +create unique index cities_names_unique on cities using btree (name); -create unique index "capitals_names_unique" on capitals using btree (name); +create unique index capitals_names_unique on capitals using btree (name); insert into cities values ('San Francisco', 7.24E+5, 63); @@ -773,11 +462,7 @@ insert into cities values ('Las Vegas', 2.583E+5, 2174) on conflict do nothing; insert into capitals values ('Sacramento', 4664.E+5, 30, 'CA') -on conflict -(name) -do -update -set population = excluded.population; +on conflict (name) do update set population = excluded.population; insert into capitals values ('Sacramento', 50, 2267, 'NE') on conflict (name) do nothing; @@ -785,22 +470,13 @@ select * from capitals; insert into cities values ('Las Vegas', 5.83E+5, 2001) -on conflict -(name) -do -update -set population = excluded.population, -altitude = excluded.altitude; +on conflict (name) do update set population = excluded.population, altitude = excluded.altitude; select cast(tableoid as regclass), * from cities; insert into capitals values ('Las Vegas', 5.83E+5, 2222, 'NV') -on conflict -(name) -do -update -set population = excluded.population; +on conflict (name) do update set population = excluded.population; select * from capitals; @@ -808,12 +484,7 @@ select cast(tableoid as regclass), * from cities; insert into cities values ('Las Vegas', 5.86E+5, 2223) -on conflict -(name) -do -update -set population = excluded.population, -altitude = excluded.altitude; +on conflict (name) do update set population = excluded.population, altitude = excluded.altitude; select cast(tableoid as regclass), * from cities; @@ -830,20 +501,12 @@ insert into excluded values (1, '1'); insert into excluded values (1, '2') -on conflict -(key) -do -update -set data = excluded.data +on conflict (key) do update set data = excluded.data returning *; insert into excluded as target values (1, '2') -on conflict -(key) -do -update -set data = excluded.data +on conflict (key) do update set data = excluded.data returning *; insert into excluded as target @@ -919,12 +582,7 @@ returning *; insert into dropcol (key, keep1, keep2) values (1, '5', 5) -on conflict -(key) -do -update -set keep1 = dropcol.keep1, -keep2 = dropcol.keep2 +on conflict (key) do update set keep1 = dropcol.keep1, keep2 = dropcol.keep2 returning *; drop table dropcol; @@ -943,15 +601,11 @@ insert into twoconstraints values (2, '((0,0),(1,2))'); insert into twoconstraints values (2, '((0,0),(1,2))') -on conflict -on constraint twoconstraints_f1_key -do nothing; +on conflict on constraint twoconstraints_f1_key do nothing; insert into twoconstraints values (2, '((0,0),(1,2))') -on conflict -on constraint twoconstraints_f2_excl -do nothing; +on conflict on constraint twoconstraints_f2_excl do nothing; select * from twoconstraints; @@ -1006,7 +660,7 @@ create table parted_conflict_test ( a int unique, b char(1) ) -partition by LIST(a); +partition by list(a); create table parted_conflict_test_1 partition of parted_conflict_test @@ -1062,20 +716,14 @@ on conflict (a) do update set b = excluded.b; insert into parted_conflict_test (a, b) values (4, 'b') -on conflict -(a) -do -update -set b = excluded.b -where - parted_conflict_test.b = 'a'; +on conflict (a) do update set b = excluded.b where parted_conflict_test.b = 'a'; select * from parted_conflict_test order by a; create table parted_conflict_test_4 partition of parted_conflict_test for values in (5) -partition by LIST(a); +partition by list(a); create table parted_conflict_test_4_1 partition of parted_conflict_test_4 for values in (5); @@ -1087,13 +735,7 @@ on conflict (a) do update set b = excluded.b; insert into parted_conflict_test (a, b) values (5, 'b') -on conflict -(a) -do -update -set b = excluded.b -where - parted_conflict_test.b = 'a'; +on conflict (a) do update set b = excluded.b where parted_conflict_test.b = 'a'; select * from parted_conflict_test order by a; @@ -1101,23 +743,11 @@ truncate parted_conflict_test; insert into parted_conflict_test (a, b) values (1, 'a'), (2, 'a'), (4, 'a') -on conflict -(a) -do -update -set b = excluded.b -where - excluded.b = 'b'; +on conflict (a) do update set b = excluded.b where excluded.b = 'b'; insert into parted_conflict_test (a, b) values (1, 'b'), (2, 'c'), (4, 'b') -on conflict -(a) -do -update -set b = excluded.b -where - excluded.b = 'b'; +on conflict (a) do update set b = excluded.b where excluded.b = 'b'; select * from parted_conflict_test order by a; @@ -1204,8 +834,7 @@ do update set (a, b, c) = row(excluded.*) where - parted_conflict = - (50, cast('cincuenta' as text), 1) and + parted_conflict = (50, cast('cincuenta' as text), 1) and excluded = (50, cast('cincuenta' as text), 2); select * from parted_conflict order by a; @@ -1213,7 +842,7 @@ select * from parted_conflict order by a; create or replace function parted_conflict_update_func() returns trigger language plpgsql -as $function$ +as $$ declare r record; begin @@ -1222,7 +851,7 @@ begin end loop; return new; end; -$function$; +$$; create trigger parted_conflict_update after update @@ -1237,11 +866,7 @@ insert into parted_conflict values (0, 'cero', 1); insert into parted_conflict values (0, 'cero', 1) -on conflict -(a, b) -do -update -set c = parted_conflict.c + 1; +on conflict (a, b) do update set c = parted_conflict.c + 1; drop table parted_conflict; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_conflict_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_conflict_80.snap index 8146855dc..1e6cbff02 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_conflict_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__insert_conflict_80.snap @@ -3,47 +3,31 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/insert_conflict.sql --- create table insertconflicttest ( - key int, + key int4, fruit text ); create view insertconflictview as select * from insertconflicttest; -create unique index "op_index_key" -on insertconflicttest -using btree -( +create unique index op_index_key on insertconflicttest using btree ( key, fruit text_pattern_ops ); -create unique -index "collation_index_key" -on insertconflicttest -using btree -( +create unique index collation_index_key on insertconflicttest using btree ( key, fruit collate "C" ); -create unique index "both_index_key" -on insertconflicttest -using btree -( +create unique index both_index_key on insertconflicttest using btree ( key, fruit collate "C" text_pattern_ops ); -create unique -index "both_index_expr_key" -on insertconflicttest -using btree -( +create unique index both_index_expr_key on insertconflicttest using btree ( key, - (lower(fruit)) - collate "C" - text_pattern_ops + (lower(fruit)) collate "C" text_pattern_ops ); insert into insertconflicttest @@ -60,27 +44,15 @@ on conflict (key, fruit) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -(fruit, key, fruit, key) -do nothing; +on conflict (fruit, key, fruit, key) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -((lower(fruit)), -key, -(lower(fruit)), -key) -do nothing; +on conflict ((lower(fruit)), key, (lower(fruit)), key) do nothing; insert into insertconflictview values (0, 'Crowberry') -on conflict -((lower(fruit)), -key, -(lower(fruit)), -key) -do nothing; +on conflict ((lower(fruit)), key, (lower(fruit)), key) do nothing; insert into insertconflicttest values (0, 'Crowberry') @@ -90,59 +62,31 @@ do update set fruit = excluded.fruit where - exists - ( - select - 1 - from - insertconflicttest as ii - where - ii.key = excluded.key - ); + exists (select 1 from insertconflicttest as ii where ii.key = excluded.key); insert into insertconflicttest values (0, 'Crowberry') -on conflict -(key, fruit text_pattern_ops) -do nothing; +on conflict (key, fruit text_pattern_ops) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -(key, fruit collate "C") -do nothing; +on conflict (key, fruit collate "C") do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -(fruit collate "C" text_pattern_ops, -key) -do nothing; +on conflict (fruit collate "C" text_pattern_ops, key) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -((lower(fruit)) collate "C", key, key) -do nothing; +on conflict ((lower(fruit)) collate "C", key, key) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -(fruit, -key, -fruit text_pattern_ops, -key) -do nothing; +on conflict (fruit, key, fruit text_pattern_ops, key) do nothing; insert into insertconflicttest values (0, 'Crowberry') -on conflict -((lower(fruit)) -collate "C" -text_pattern_ops, -key, -key) -do nothing; +on conflict ((lower(fruit)) collate "C" text_pattern_ops, key, key) do nothing; drop index op_index_key; @@ -152,10 +96,7 @@ drop index both_index_key; drop index both_index_expr_key; -create unique index "cross_match" -on insertconflicttest -using btree -( +create unique index cross_match on insertconflicttest using btree ( (lower(fruit)) collate "C", (upper(fruit)) text_pattern_ops ); @@ -163,28 +104,22 @@ using btree insert into insertconflicttest values (0, 'Crowberry') on conflict -((lower(fruit)) text_pattern_ops, -(upper(fruit)) collate "C") +((lower(fruit)) text_pattern_ops, (upper(fruit)) collate "C") do nothing; insert into insertconflicttest values (0, 'Crowberry') on conflict -((lower(fruit)) collate "C", -(upper(fruit)) text_pattern_ops) +((lower(fruit)) collate "C", (upper(fruit)) text_pattern_ops) do nothing; drop index cross_match; -create unique index "key_index" on insertconflicttest using btree (key); +create unique index key_index on insertconflicttest using btree (key); insert into insertconflicttest values (0, 'Bilberry') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (0, 'Bilberry') @@ -219,272 +154,145 @@ returning *; insert into insertconflicttest values (1, 'Apple') -on conflict -do -update -set fruit = excluded.fruit; +on conflict do update set fruit = excluded.fruit; insert into insertconflicttest values (1, 'Apple') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (2, 'Orange') -on conflict -(key, key, key) -do -update -set fruit = excluded.fruit; +on conflict (key, key, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (1, 'Apple'), (2, 'Orange') -on conflict -(key) -do -update -set (fruit, key) = (excluded.fruit, excluded.key); +on conflict (key) do update set (fruit, key) = (excluded.fruit, excluded.key); insert into insertconflicttest values (1, 'Apple') -on conflict -(key) -do -update -set fruit = excluded.fruit +on conflict (key) do update set fruit = excluded.fruit returning excluded.fruit; insert into insertconflicttest values (1, 'Apple') -on conflict -(keyy) -do -update -set fruit = excluded.fruit; +on conflict (keyy) do update set fruit = excluded.fruit; insert into insertconflicttest values (1, 'Apple') -on conflict -(key) -do -update -set fruit = excluded.fruitt; +on conflict (key) do update set fruit = excluded.fruitt; insert into insertconflicttest values (3, 'Kiwi') -on conflict -(key, fruit) -do -update -set fruit = excluded.fruit; +on conflict (key, fruit) do update set fruit = excluded.fruit; insert into insertconflicttest values (4, 'Mango') -on conflict -(fruit, key) -do -update -set fruit = excluded.fruit; +on conflict (fruit, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (5, 'Lemon') -on conflict -(fruit) -do -update -set fruit = excluded.fruit; +on conflict (fruit) do update set fruit = excluded.fruit; insert into insertconflicttest values (6, 'Passionfruit') -on conflict -((lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest as ict values (6, 'Passionfruit') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest as ict values (6, 'Passionfruit') -on conflict -(key) -do -update -set fruit = ict.fruit; +on conflict (key) do update set fruit = ict.fruit; insert into insertconflicttest as ict values (6, 'Passionfruit') -on conflict -(key) -do -update -set fruit = insertconflicttest.fruit; +on conflict (key) do update set fruit = insertconflicttest.fruit; insert into insertconflicttest values (3, 'Kiwi') -on conflict -(key, fruit) -do -update -set insertconflicttest."fruit" = 'Mango'; +on conflict (key, fruit) do update set insertconflicttest."fruit" = 'Mango'; drop index key_index; -create unique index "comp_key_index" -on insertconflicttest -using btree -( +create unique index comp_key_index on insertconflicttest using btree ( key, fruit ); insert into insertconflicttest values (7, 'Raspberry') -on conflict -(key, fruit) -do -update -set fruit = excluded.fruit; +on conflict (key, fruit) do update set fruit = excluded.fruit; insert into insertconflicttest values (8, 'Lime') -on conflict -(fruit, key) -do -update -set fruit = excluded.fruit; +on conflict (fruit, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (9, 'Banana') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (10, 'Blueberry') -on conflict -(key, key, key) -do -update -set fruit = excluded.fruit; +on conflict (key, key, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (11, 'Cherry') -on conflict -(key, (lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict (key, (lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (12, 'Date') -on conflict -((lower(fruit)), key) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit)), key) do update set fruit = excluded.fruit; drop index comp_key_index; -create unique -index "part_comp_key_index" -on insertconflicttest -using btree -( +create unique index part_comp_key_index on insertconflicttest using btree ( key, fruit ) -where - key < 5; +where key < 5; -create unique -index "expr_part_comp_key_index" -on insertconflicttest -using btree -( +create unique index expr_part_comp_key_index on insertconflicttest using btree ( key, (lower(fruit)) ) -where - key < 5; +where key < 5; insert into insertconflicttest values (13, 'Grape') -on conflict -(key, fruit) -do -update -set fruit = excluded.fruit; +on conflict (key, fruit) do update set fruit = excluded.fruit; insert into insertconflicttest values (14, 'Raisin') -on conflict -(fruit, key) -do -update -set fruit = excluded.fruit; +on conflict (fruit, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (15, 'Cranberry') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (16, 'Melon') -on conflict -(key, key, key) -do -update -set fruit = excluded.fruit; +on conflict (key, key, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (17, 'Mulberry') -on conflict -(key, (lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict (key, (lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (18, 'Pineapple') -on conflict -((lower(fruit)), key) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit)), key) do update set fruit = excluded.fruit; drop index part_comp_key_index; drop index expr_part_comp_key_index; -create unique index "expr_key_index" -on insertconflicttest -using btree -( +create unique index expr_key_index on insertconflicttest using btree ( (lower(fruit)) ); insert into insertconflicttest values (20, 'Quince') -on conflict -((lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (21, 'Pomegranate') @@ -496,136 +304,77 @@ set fruit = excluded.fruit; insert into insertconflicttest values (22, 'Apricot') -on conflict -((upper(fruit))) -do -update -set fruit = excluded.fruit; +on conflict ((upper(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (23, 'Blackberry') -on conflict -(fruit) -do -update -set fruit = excluded.fruit; +on conflict (fruit) do update set fruit = excluded.fruit; drop index expr_key_index; -create unique -index "expr_comp_key_index" -on insertconflicttest -using btree -( +create unique index expr_comp_key_index on insertconflicttest using btree ( key, (lower(fruit)) ); -create unique -index "tricky_expr_comp_key_index" -on insertconflicttest -using btree -( - key, - (lower(fruit)), - (upper(fruit)) -); +create unique index tricky_expr_comp_key_index + on insertconflicttest + using btree (key, (lower(fruit)), (upper(fruit))); insert into insertconflicttest values (24, 'Plum') -on conflict -(key, (lower(fruit))) -do -update -set fruit = excluded.fruit; +on conflict (key, (lower(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (25, 'Peach') -on conflict -((lower(fruit)), key) -do -update -set fruit = excluded.fruit; +on conflict ((lower(fruit)), key) do update set fruit = excluded.fruit; insert into insertconflicttest values (26, 'Fig') on conflict -((lower(fruit)), -key, -(lower(fruit)), -key) +((lower(fruit)), key, (lower(fruit)), key) do update set fruit = excluded.fruit; insert into insertconflicttest values (27, 'Prune') -on conflict -(key, (upper(fruit))) -do -update -set fruit = excluded.fruit; +on conflict (key, (upper(fruit))) do update set fruit = excluded.fruit; insert into insertconflicttest values (28, 'Redcurrant') -on conflict -(fruit, key) -do -update -set fruit = excluded.fruit; +on conflict (fruit, key) do update set fruit = excluded.fruit; insert into insertconflicttest values (29, 'Nectarine') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; drop index expr_comp_key_index; drop index tricky_expr_comp_key_index; -create unique index "key_index" on insertconflicttest using btree (key); +create unique index key_index on insertconflicttest using btree (key); -create unique index "fruit_index" on insertconflicttest using btree (fruit); +create unique index fruit_index on insertconflicttest using btree (fruit); insert into insertconflicttest values (26, 'Fig') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (26, 'Peach') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (25, 'Fig') -on conflict -(fruit) -do -update -set fruit = excluded.fruit; +on conflict (fruit) do update set fruit = excluded.fruit; drop index key_index; drop index fruit_index; -create unique index "partial_key_index" -on insertconflicttest -using btree -( - key -) -where - fruit like '%berry'; +create unique index partial_key_index on insertconflicttest using btree (key) +where fruit like '%berry'; insert into insertconflicttest values (23, 'Blackberry') @@ -638,36 +387,23 @@ set fruit = excluded.fruit; insert into insertconflicttest as t values (23, 'Blackberry') on conflict -(key) -where - fruit like '%berry' and - t.fruit = 'inconsequential' +(key) where fruit like '%berry' and t.fruit = 'inconsequential' do nothing; insert into insertconflictview as t values (23, 'Blackberry') on conflict -(key) -where - fruit like '%berry' and - t.fruit = 'inconsequential' +(key) where fruit like '%berry' and t.fruit = 'inconsequential' do nothing; insert into insertconflicttest values (23, 'Blackberry') -on conflict -(key) -do -update -set fruit = excluded.fruit; +on conflict (key) do update set fruit = excluded.fruit; insert into insertconflicttest values (23, 'Blackberry') on conflict -(key) -where - fruit like '%berry' or - fruit = 'consequential' +(key) where fruit like '%berry' or fruit = 'consequential' do nothing; insert into insertconflicttest @@ -680,67 +416,35 @@ set fruit = excluded.fruit; drop index partial_key_index; -create unique index "plain" on insertconflicttest using btree (key); +create unique index plain on insertconflicttest using btree (key); insert into insertconflicttest as i values (23, 'Jackfruit') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - i.* <> excluded.* +on conflict (key) do update set fruit = excluded.fruit where i.* <> excluded.* returning *; insert into insertconflicttest as i values (23, 'Jackfruit') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - i.* <> excluded.* +on conflict (key) do update set fruit = excluded.fruit where i.* <> excluded.* returning *; insert into insertconflicttest as i values (23, 'Jackfruit') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - i.* = excluded.* +on conflict (key) do update set fruit = excluded.fruit where i.* = excluded.* returning *; insert into insertconflicttest as i values (23, 'Avocado') -on conflict -(key) -do -update -set fruit = cast(excluded.* as text) +on conflict (key) do update set fruit = cast(excluded.* as text) returning *; insert into insertconflicttest as i values (23, 'Avocado') -on conflict -(key) -do -update -set fruit = excluded.fruit -where - excluded.* is null; +on conflict (key) do update set fruit = excluded.fruit where excluded.* is null; insert into insertconflicttest as i values (23, 'Avocado') -on conflict -(key) -do -update -set fruit = cast(excluded.* as text); +on conflict (key) do update set fruit = cast(excluded.* as text); drop index plain; @@ -749,7 +453,7 @@ drop view insertconflictview; drop table insertconflicttest; create table syscolconflicttest ( - key int, + key int4, data text ); @@ -757,11 +461,7 @@ insert into syscolconflicttest values (1); insert into syscolconflicttest values (1) -on conflict -(key) -do -update -set data = cast(excluded.ctid as text); +on conflict (key) do update set data = cast(excluded.ctid as text); drop table syscolconflicttest; @@ -770,39 +470,24 @@ create table insertconflict ( b bigint ); -create unique index "insertconflicti1" -on insertconflict -using btree -( +create unique index insertconflicti1 on insertconflict using btree ( (coalesce(a, 0)) ); -create unique index "insertconflicti2" -on insertconflict -using btree -( - b -) -where - coalesce(a, 1) > 0; +create unique index insertconflicti2 on insertconflict using btree (b) +where coalesce(a, 1) > 0; insert into insertconflict values (1, 2) -on conflict -((coalesce(a, 0))) -do nothing; +on conflict ((coalesce(a, 0))) do nothing; insert into insertconflict values (1, 2) -on conflict -(b) where coalesce(a, 1) > 0 -do nothing; +on conflict (b) where coalesce(a, 1) > 0 do nothing; insert into insertconflict values (1, 2) -on conflict -(b) where coalesce(a, 1) > 1 -do nothing; +on conflict (b) where coalesce(a, 1) > 1 do nothing; drop table insertconflict; @@ -817,21 +502,13 @@ with cascaded check option; insert into insertconflictv values (1, 'foo') -on conflict -(f1) -do -update -set f2 = excluded.f2; +on conflict (f1) do update set f2 = excluded.f2; select * from insertconflict; insert into insertconflictv values (1, 'bar') -on conflict -(f1) -do -update -set f2 = excluded.f2; +on conflict (f1) do update set f2 = excluded.f2; select * from insertconflict; @@ -841,16 +518,16 @@ drop table insertconflict; create table cities ( name text, - population double precision, + population float8, altitude int ); create table capitals (state char(2)) inherits (cities); -create unique index "cities_names_unique" on cities using btree (name); +create unique index cities_names_unique on cities using btree (name); -create unique index "capitals_names_unique" on capitals using btree (name); +create unique index capitals_names_unique on capitals using btree (name); insert into cities values ('San Francisco', 7.24E+5, 63); @@ -867,13 +544,8 @@ select * from capitals; insert into cities values ('Las Vegas', 2.583E+5, 2174) on conflict do nothing; insert into capitals -values - ('Sacramento', 4664.E+5, 30, 'CA') -on conflict -(name) -do -update -set population = excluded.population; +values ('Sacramento', 4664.E+5, 30, 'CA') +on conflict (name) do update set population = excluded.population; insert into capitals values ('Sacramento', 50, 2267, 'NE') @@ -893,13 +565,8 @@ altitude = excluded.altitude; select cast(tableoid as regclass), * from cities; insert into capitals -values - ('Las Vegas', 5.83E+5, 2222, 'NV') -on conflict -(name) -do -update -set population = excluded.population; +values ('Las Vegas', 5.83E+5, 2222, 'NV') +on conflict (name) do update set population = excluded.population; select * from capitals; @@ -929,29 +596,17 @@ insert into excluded values (1, '1'); insert into excluded values (1, '2') -on conflict -(key) -do -update -set data = excluded.data +on conflict (key) do update set data = excluded.data returning *; insert into excluded as target values (1, '2') -on conflict -(key) -do -update -set data = excluded.data +on conflict (key) do update set data = excluded.data returning *; insert into excluded as target values (1, '2') -on conflict -(key) -do -update -set data = target.data +on conflict (key) do update set data = target.data returning *; insert into excluded @@ -1026,12 +681,7 @@ returning *; insert into dropcol (key, keep1, keep2) values (1, '5', 5) -on conflict -(key) -do -update -set keep1 = dropcol.keep1, -keep2 = dropcol.keep2 +on conflict (key) do update set keep1 = dropcol.keep1, keep2 = dropcol.keep2 returning *; drop table dropcol; @@ -1050,15 +700,11 @@ insert into twoconstraints values (2, '((0,0),(1,2))'); insert into twoconstraints values (2, '((0,0),(1,2))') -on conflict -on constraint twoconstraints_f1_key -do nothing; +on conflict on constraint twoconstraints_f1_key do nothing; insert into twoconstraints values (2, '((0,0),(1,2))') -on conflict -on constraint twoconstraints_f2_excl -do nothing; +on conflict on constraint twoconstraints_f2_excl do nothing; select * from twoconstraints; @@ -1119,7 +765,7 @@ create table parted_conflict_test ( a int unique, b char(1) ) -partition by LIST(a); +partition by list(a); create table parted_conflict_test_1 partition of parted_conflict_test @@ -1134,37 +780,21 @@ insert into parted_conflict_test values (1, 'a') on conflict (a) do nothing; insert into parted_conflict_test values (1, 'a') -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; insert into parted_conflict_test_1 values (1, 'a') on conflict (a) do nothing; insert into parted_conflict_test_1 values (1, 'b') -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; insert into parted_conflict_test values (2, 'b') -on conflict -(b) -do -update -set a = excluded.a; +on conflict (b) do update set a = excluded.a; insert into parted_conflict_test_1 values (2, 'b') -on conflict -(b) -do -update -set a = excluded.a; +on conflict (b) do update set a = excluded.a; select * from parted_conflict_test order by a; @@ -1181,19 +811,11 @@ truncate parted_conflict_test; insert into parted_conflict_test values (3, 'a') -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; insert into parted_conflict_test values (3, 'b') -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; select * from parted_conflict_test order by a; @@ -1209,28 +831,18 @@ truncate parted_conflict_test; insert into parted_conflict_test (a, b) values (4, 'a') -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; insert into parted_conflict_test (a, b) values (4, 'b') -on conflict -(a) -do -update -set b = excluded.b -where - parted_conflict_test.b = 'a'; +on conflict (a) do update set b = excluded.b where parted_conflict_test.b = 'a'; select * from parted_conflict_test order by a; create table parted_conflict_test_4 partition of parted_conflict_test for values in (5) -partition by LIST(a); +partition by list(a); create table parted_conflict_test_4_1 partition of parted_conflict_test_4 @@ -1240,21 +852,11 @@ truncate parted_conflict_test; insert into parted_conflict_test (a, b) values (5, 'a') -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; insert into parted_conflict_test (a, b) values (5, 'b') -on conflict -(a) -do -update -set b = excluded.b -where - parted_conflict_test.b = 'a'; +on conflict (a) do update set b = excluded.b where parted_conflict_test.b = 'a'; select * from parted_conflict_test order by a; @@ -1262,23 +864,11 @@ truncate parted_conflict_test; insert into parted_conflict_test (a, b) values (1, 'a'), (2, 'a'), (4, 'a') -on conflict -(a) -do -update -set b = excluded.b -where - excluded.b = 'b'; +on conflict (a) do update set b = excluded.b where excluded.b = 'b'; insert into parted_conflict_test (a, b) values (1, 'b'), (2, 'c'), (4, 'b') -on conflict -(a) -do -update -set b = excluded.b -where - excluded.b = 'b'; +on conflict (a) do update set b = excluded.b where excluded.b = 'b'; select * from parted_conflict_test order by a; @@ -1303,11 +893,7 @@ insert into parted_conflict values (40, 'forty'); insert into parted_conflict_1 values (40, 'cuarenta') -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; drop table parted_conflict; @@ -1338,11 +924,7 @@ insert into parted_conflict values (40, 'forty'); insert into parted_conflict_1 values (40, 'cuarenta') -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; drop table parted_conflict; @@ -1367,8 +949,7 @@ create unique index on parted_conflict using btree (a, b); alter table parted_conflict attach partition - parted_conflict_1 - for values from (0) to (1000); + parted_conflict_1 for values from (0) to (1000); truncate parted_conflict; @@ -1382,17 +963,15 @@ do update set (a, b, c) = row(excluded.*) where - parted_conflict = - (50, cast('cincuenta' as text), 1) and - excluded = - (50, cast('cincuenta' as text), 2); + parted_conflict = (50, cast('cincuenta' as text), 1) and + excluded = (50, cast('cincuenta' as text), 2); select * from parted_conflict order by a; create or replace function parted_conflict_update_func() returns trigger language plpgsql -as $function$ +as $$ declare r record; begin @@ -1401,7 +980,7 @@ begin end loop; return new; end; -$function$; +$$; create trigger parted_conflict_update after update @@ -1416,11 +995,7 @@ insert into parted_conflict values (0, 'cero', 1); insert into parted_conflict values (0, 'cero', 1) -on conflict -(a, b) -do -update -set c = parted_conflict.c + 1; +on conflict (a, b) do update set c = parted_conflict.c + 1; drop table parted_conflict; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int2_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int2_100.snap index 5095e1c66..730948e84 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int2_100.snap @@ -39,85 +39,85 @@ select * from int2_tbl as f (a, b); select * from (select * from int2_tbl) as s (a, b); -select i.* from int2_tbl as i where i.f1 <> cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 <> cast('0' as int2); -select i.* from int2_tbl as i where i.f1 <> cast('0' as int); +select i.* from int2_tbl as i where i.f1 <> cast('0' as int4); -select i.* from int2_tbl as i where i.f1 = cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 = cast('0' as int2); -select i.* from int2_tbl as i where i.f1 = cast('0' as int); +select i.* from int2_tbl as i where i.f1 = cast('0' as int4); -select i.* from int2_tbl as i where i.f1 < cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 < cast('0' as int2); -select i.* from int2_tbl as i where i.f1 < cast('0' as int); +select i.* from int2_tbl as i where i.f1 < cast('0' as int4); -select i.* from int2_tbl as i where i.f1 <= cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 <= cast('0' as int2); -select i.* from int2_tbl as i where i.f1 <= cast('0' as int); +select i.* from int2_tbl as i where i.f1 <= cast('0' as int4); -select i.* from int2_tbl as i where i.f1 > cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 > cast('0' as int2); -select i.* from int2_tbl as i where i.f1 > cast('0' as int); +select i.* from int2_tbl as i where i.f1 > cast('0' as int4); -select i.* from int2_tbl as i where i.f1 >= cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 >= cast('0' as int2); -select i.* from int2_tbl as i where i.f1 >= cast('0' as int); +select i.* from int2_tbl as i where i.f1 >= cast('0' as int4); -select i.* from int2_tbl as i where i.f1 % cast('2' as smallint) = cast('1' as smallint); +select i.* from int2_tbl as i where i.f1 % cast('2' as int2) = cast('1' as int2); -select i.* from int2_tbl as i where i.f1 % cast('2' as int) = cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 % cast('2' as int4) = cast('0' as int2); -select i.f1, i.f1 * cast('2' as smallint) as x from int2_tbl as i; +select i.f1, i.f1 * cast('2' as int2) as x from int2_tbl as i; -select i.f1, i.f1 * cast('2' as smallint) as x from int2_tbl as i where abs(f1) < 16384; +select i.f1, i.f1 * cast('2' as int2) as x from int2_tbl as i where abs(f1) < 16384; -select i.f1, i.f1 * cast('2' as int) as x from int2_tbl as i; +select i.f1, i.f1 * cast('2' as int4) as x from int2_tbl as i; -select i.f1, i.f1 + cast('2' as smallint) as x from int2_tbl as i; +select i.f1, i.f1 + cast('2' as int2) as x from int2_tbl as i; -select i.f1, i.f1 + cast('2' as smallint) as x from int2_tbl as i where f1 < 32766; +select i.f1, i.f1 + cast('2' as int2) as x from int2_tbl as i where f1 < 32766; -select i.f1, i.f1 + cast('2' as int) as x from int2_tbl as i; +select i.f1, i.f1 + cast('2' as int4) as x from int2_tbl as i; -select i.f1, i.f1 - cast('2' as smallint) as x from int2_tbl as i; +select i.f1, i.f1 - cast('2' as int2) as x from int2_tbl as i; -select i.f1, i.f1 - cast('2' as smallint) as x from int2_tbl as i where f1 > -32767; +select i.f1, i.f1 - cast('2' as int2) as x from int2_tbl as i where f1 > -32767; -select i.f1, i.f1 - cast('2' as int) as x from int2_tbl as i; +select i.f1, i.f1 - cast('2' as int4) as x from int2_tbl as i; -select i.f1, i.f1 / cast('2' as smallint) as x from int2_tbl as i; +select i.f1, i.f1 / cast('2' as int2) as x from int2_tbl as i; -select i.f1, i.f1 / cast('2' as int) as x from int2_tbl as i; +select i.f1, i.f1 / cast('2' as int4) as x from int2_tbl as i; -select cast(-cast(1 as smallint) << 15 as text); +select cast(-cast(1 as int2) << 15 as text); -select cast((-cast(1 as smallint) << 15) + cast(1 as smallint) as text); +select cast((-cast(1 as int2) << 15) + cast(1 as int2) as text); -select cast(-32768 as smallint) * cast(-1 as smallint); +select cast(-32768 as int2) * cast(-1 as int2); -select cast(-32768 as smallint) / cast(-1 as smallint); +select cast(-32768 as int2) / cast(-1 as int2); -select cast(-32768 as smallint) % cast(-1 as smallint); +select cast(-32768 as int2) % cast(-1 as int2); select x, - cast(x as smallint) as int2_value + cast(x as int2) as int2_value from ( values - (-cast(2.5 as double precision)), - (-cast(1.5 as double precision)), - (-cast(0.5 as double precision)), - (cast(0.0 as double precision)), - (cast(0.5 as double precision)), - (cast(1.5 as double precision)), - (cast(2.5 as double precision)) + (-cast(2.5 as float8)), + (-cast(1.5 as float8)), + (-cast(0.5 as float8)), + (cast(0.0 as float8)), + (cast(0.5 as float8)), + (cast(1.5 as float8)), + (cast(2.5 as float8)) ) as t (x); select x, - cast(x as smallint) as int2_value + cast(x as int2) as int2_value from ( values @@ -131,54 +131,54 @@ from ) as t (x); -select cast('0b100101' as smallint); +select cast('0b100101' as int2); -select cast('0o273' as smallint); +select cast('0o273' as int2); -select cast('0x42F' as smallint); +select cast('0x42F' as int2); -select cast('0b' as smallint); +select cast('0b' as int2); -select cast('0o' as smallint); +select cast('0o' as int2); -select cast('0x' as smallint); +select cast('0x' as int2); -select cast('0b111111111111111' as smallint); +select cast('0b111111111111111' as int2); -select cast('0b1000000000000000' as smallint); +select cast('0b1000000000000000' as int2); -select cast('0o77777' as smallint); +select cast('0o77777' as int2); -select cast('0o100000' as smallint); +select cast('0o100000' as int2); -select cast('0x7FFF' as smallint); +select cast('0x7FFF' as int2); -select cast('0x8000' as smallint); +select cast('0x8000' as int2); -select cast('-0b1000000000000000' as smallint); +select cast('-0b1000000000000000' as int2); -select cast('-0b1000000000000001' as smallint); +select cast('-0b1000000000000001' as int2); -select cast('-0o100000' as smallint); +select cast('-0o100000' as int2); -select cast('-0o100001' as smallint); +select cast('-0o100001' as int2); -select cast('-0x8000' as smallint); +select cast('-0x8000' as int2); -select cast('-0x8001' as smallint); +select cast('-0x8001' as int2); -select cast('1_000' as smallint); +select cast('1_000' as int2); -select cast('1_2_3' as smallint); +select cast('1_2_3' as int2); -select cast('0xE_FF' as smallint); +select cast('0xE_FF' as int2); -select cast('0o2_73' as smallint); +select cast('0o2_73' as int2); -select cast('0b_10_0101' as smallint); +select cast('0b_10_0101' as int2); -select cast('_100' as smallint); +select cast('_100' as int2); -select cast('100_' as smallint); +select cast('100_' as int2); -select cast('10__000' as smallint); +select cast('10__000' as int2); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int2_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int2_80.snap index 5f74dd49c..7549a3ac5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int2_80.snap @@ -39,115 +39,101 @@ select * from int2_tbl as f (a, b); select * from (select * from int2_tbl) as s (a, b); -select i.* from int2_tbl as i where i.f1 <> cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 <> cast('0' as int2); -select i.* from int2_tbl as i where i.f1 <> cast('0' as int); +select i.* from int2_tbl as i where i.f1 <> cast('0' as int4); -select i.* from int2_tbl as i where i.f1 = cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 = cast('0' as int2); -select i.* from int2_tbl as i where i.f1 = cast('0' as int); +select i.* from int2_tbl as i where i.f1 = cast('0' as int4); -select i.* from int2_tbl as i where i.f1 < cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 < cast('0' as int2); -select i.* from int2_tbl as i where i.f1 < cast('0' as int); +select i.* from int2_tbl as i where i.f1 < cast('0' as int4); -select i.* from int2_tbl as i where i.f1 <= cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 <= cast('0' as int2); -select i.* from int2_tbl as i where i.f1 <= cast('0' as int); +select i.* from int2_tbl as i where i.f1 <= cast('0' as int4); -select i.* from int2_tbl as i where i.f1 > cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 > cast('0' as int2); -select i.* from int2_tbl as i where i.f1 > cast('0' as int); +select i.* from int2_tbl as i where i.f1 > cast('0' as int4); -select i.* from int2_tbl as i where i.f1 >= cast('0' as smallint); +select i.* from int2_tbl as i where i.f1 >= cast('0' as int2); -select i.* from int2_tbl as i where i.f1 >= cast('0' as int); +select i.* from int2_tbl as i where i.f1 >= cast('0' as int4); select i.* from int2_tbl as i where - i.f1 % cast('2' as smallint) = - cast('1' as smallint); + i.f1 % cast('2' as int2) = cast('1' as int2); select i.* from int2_tbl as i where - i.f1 % cast('2' as int) = - cast('0' as smallint); + i.f1 % cast('2' as int4) = cast('0' as int2); -select i.f1, i.f1 * cast('2' as smallint) as x from int2_tbl as i; +select i.f1, i.f1 * cast('2' as int2) as x from int2_tbl as i; select i.f1, - i.f1 * cast('2' as smallint) as x + i.f1 * cast('2' as int2) as x from int2_tbl as i where abs(f1) < 16384; -select i.f1, i.f1 * cast('2' as int) as x from int2_tbl as i; +select i.f1, i.f1 * cast('2' as int4) as x from int2_tbl as i; -select i.f1, i.f1 + cast('2' as smallint) as x from int2_tbl as i; +select i.f1, i.f1 + cast('2' as int2) as x from int2_tbl as i; -select - i.f1, - i.f1 + cast('2' as smallint) as x -from - int2_tbl as i -where - f1 < 32766; +select i.f1, i.f1 + cast('2' as int2) as x from int2_tbl as i where f1 < 32766; -select i.f1, i.f1 + cast('2' as int) as x from int2_tbl as i; +select i.f1, i.f1 + cast('2' as int4) as x from int2_tbl as i; -select i.f1, i.f1 - cast('2' as smallint) as x from int2_tbl as i; +select i.f1, i.f1 - cast('2' as int2) as x from int2_tbl as i; -select - i.f1, - i.f1 - cast('2' as smallint) as x -from - int2_tbl as i -where - f1 > -32767; +select i.f1, i.f1 - cast('2' as int2) as x from int2_tbl as i where f1 > -32767; -select i.f1, i.f1 - cast('2' as int) as x from int2_tbl as i; +select i.f1, i.f1 - cast('2' as int4) as x from int2_tbl as i; -select i.f1, i.f1 / cast('2' as smallint) as x from int2_tbl as i; +select i.f1, i.f1 / cast('2' as int2) as x from int2_tbl as i; -select i.f1, i.f1 / cast('2' as int) as x from int2_tbl as i; +select i.f1, i.f1 / cast('2' as int4) as x from int2_tbl as i; -select cast(-cast(1 as smallint) << 15 as text); +select cast(-cast(1 as int2) << 15 as text); -select cast((-cast(1 as smallint) << 15) + cast(1 as smallint) as text); +select cast((-cast(1 as int2) << 15) + cast(1 as int2) as text); -select cast(-32768 as smallint) * cast(-1 as smallint); +select cast(-32768 as int2) * cast(-1 as int2); -select cast(-32768 as smallint) / cast(-1 as smallint); +select cast(-32768 as int2) / cast(-1 as int2); -select cast(-32768 as smallint) % cast(-1 as smallint); +select cast(-32768 as int2) % cast(-1 as int2); select x, - cast(x as smallint) as int2_value + cast(x as int2) as int2_value from ( values - (-cast(2.5 as double precision)), - (-cast(1.5 as double precision)), - (-cast(0.5 as double precision)), - (cast(0.0 as double precision)), - (cast(0.5 as double precision)), - (cast(1.5 as double precision)), - (cast(2.5 as double precision)) + (-cast(2.5 as float8)), + (-cast(1.5 as float8)), + (-cast(0.5 as float8)), + (cast(0.0 as float8)), + (cast(0.5 as float8)), + (cast(1.5 as float8)), + (cast(2.5 as float8)) ) as t (x); select x, - cast(x as smallint) as int2_value + cast(x as int2) as int2_value from ( values @@ -161,54 +147,54 @@ from ) as t (x); -select cast('0b100101' as smallint); +select cast('0b100101' as int2); -select cast('0o273' as smallint); +select cast('0o273' as int2); -select cast('0x42F' as smallint); +select cast('0x42F' as int2); -select cast('0b' as smallint); +select cast('0b' as int2); -select cast('0o' as smallint); +select cast('0o' as int2); -select cast('0x' as smallint); +select cast('0x' as int2); -select cast('0b111111111111111' as smallint); +select cast('0b111111111111111' as int2); -select cast('0b1000000000000000' as smallint); +select cast('0b1000000000000000' as int2); -select cast('0o77777' as smallint); +select cast('0o77777' as int2); -select cast('0o100000' as smallint); +select cast('0o100000' as int2); -select cast('0x7FFF' as smallint); +select cast('0x7FFF' as int2); -select cast('0x8000' as smallint); +select cast('0x8000' as int2); -select cast('-0b1000000000000000' as smallint); +select cast('-0b1000000000000000' as int2); -select cast('-0b1000000000000001' as smallint); +select cast('-0b1000000000000001' as int2); -select cast('-0o100000' as smallint); +select cast('-0o100000' as int2); -select cast('-0o100001' as smallint); +select cast('-0o100001' as int2); -select cast('-0x8000' as smallint); +select cast('-0x8000' as int2); -select cast('-0x8001' as smallint); +select cast('-0x8001' as int2); -select cast('1_000' as smallint); +select cast('1_000' as int2); -select cast('1_2_3' as smallint); +select cast('1_2_3' as int2); -select cast('0xE_FF' as smallint); +select cast('0xE_FF' as int2); -select cast('0o2_73' as smallint); +select cast('0o2_73' as int2); -select cast('0b_10_0101' as smallint); +select cast('0b_10_0101' as int2); -select cast('_100' as smallint); +select cast('_100' as int2); -select cast('100_' as smallint); +select cast('100_' as int2); -select cast('10__000' as smallint); +select cast('10__000' as int2); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int4_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int4_100.snap index f7db7dfa3..98a657611 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int4_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int4_100.snap @@ -29,61 +29,61 @@ select pg_input_is_valid('1000000000000', 'int4'); select * from pg_input_error_info('1000000000000', 'int4'); -select i.* from int4_tbl as i where i.f1 <> cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 <> cast('0' as int2); -select i.* from int4_tbl as i where i.f1 <> cast('0' as int); +select i.* from int4_tbl as i where i.f1 <> cast('0' as int4); -select i.* from int4_tbl as i where i.f1 = cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 = cast('0' as int2); -select i.* from int4_tbl as i where i.f1 = cast('0' as int); +select i.* from int4_tbl as i where i.f1 = cast('0' as int4); -select i.* from int4_tbl as i where i.f1 < cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 < cast('0' as int2); -select i.* from int4_tbl as i where i.f1 < cast('0' as int); +select i.* from int4_tbl as i where i.f1 < cast('0' as int4); -select i.* from int4_tbl as i where i.f1 <= cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 <= cast('0' as int2); -select i.* from int4_tbl as i where i.f1 <= cast('0' as int); +select i.* from int4_tbl as i where i.f1 <= cast('0' as int4); -select i.* from int4_tbl as i where i.f1 > cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 > cast('0' as int2); -select i.* from int4_tbl as i where i.f1 > cast('0' as int); +select i.* from int4_tbl as i where i.f1 > cast('0' as int4); -select i.* from int4_tbl as i where i.f1 >= cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 >= cast('0' as int2); -select i.* from int4_tbl as i where i.f1 >= cast('0' as int); +select i.* from int4_tbl as i where i.f1 >= cast('0' as int4); -select i.* from int4_tbl as i where i.f1 % cast('2' as smallint) = cast('1' as smallint); +select i.* from int4_tbl as i where i.f1 % cast('2' as int2) = cast('1' as int2); -select i.* from int4_tbl as i where i.f1 % cast('2' as int) = cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 % cast('2' as int4) = cast('0' as int2); -select i.f1, i.f1 * cast('2' as smallint) as x from int4_tbl as i; +select i.f1, i.f1 * cast('2' as int2) as x from int4_tbl as i; -select i.f1, i.f1 * cast('2' as smallint) as x from int4_tbl as i where abs(f1) < 1073741824; +select i.f1, i.f1 * cast('2' as int2) as x from int4_tbl as i where abs(f1) < 1073741824; -select i.f1, i.f1 * cast('2' as int) as x from int4_tbl as i; +select i.f1, i.f1 * cast('2' as int4) as x from int4_tbl as i; -select i.f1, i.f1 * cast('2' as int) as x from int4_tbl as i where abs(f1) < 1073741824; +select i.f1, i.f1 * cast('2' as int4) as x from int4_tbl as i where abs(f1) < 1073741824; -select i.f1, i.f1 + cast('2' as smallint) as x from int4_tbl as i; +select i.f1, i.f1 + cast('2' as int2) as x from int4_tbl as i; -select i.f1, i.f1 + cast('2' as smallint) as x from int4_tbl as i where f1 < 2147483646; +select i.f1, i.f1 + cast('2' as int2) as x from int4_tbl as i where f1 < 2147483646; -select i.f1, i.f1 + cast('2' as int) as x from int4_tbl as i; +select i.f1, i.f1 + cast('2' as int4) as x from int4_tbl as i; -select i.f1, i.f1 + cast('2' as int) as x from int4_tbl as i where f1 < 2147483646; +select i.f1, i.f1 + cast('2' as int4) as x from int4_tbl as i where f1 < 2147483646; -select i.f1, i.f1 - cast('2' as smallint) as x from int4_tbl as i; +select i.f1, i.f1 - cast('2' as int2) as x from int4_tbl as i; -select i.f1, i.f1 - cast('2' as smallint) as x from int4_tbl as i where f1 > -2147483647; +select i.f1, i.f1 - cast('2' as int2) as x from int4_tbl as i where f1 > -2147483647; -select i.f1, i.f1 - cast('2' as int) as x from int4_tbl as i; +select i.f1, i.f1 - cast('2' as int4) as x from int4_tbl as i; -select i.f1, i.f1 - cast('2' as int) as x from int4_tbl as i where f1 > -2147483647; +select i.f1, i.f1 - cast('2' as int4) as x from int4_tbl as i where f1 > -2147483647; -select i.f1, i.f1 / cast('2' as smallint) as x from int4_tbl as i; +select i.f1, i.f1 / cast('2' as int2) as x from int4_tbl as i; -select i.f1, i.f1 / cast('2' as int) as x from int4_tbl as i; +select i.f1, i.f1 / cast('2' as int4) as x from int4_tbl as i; select -2 + 3 as one; @@ -93,22 +93,13 @@ select 2 - -1 as three; select 2 - -2 as four; -select - cast('2' as smallint) * cast('2' as smallint) = - cast('16' as smallint) / cast('4' as smallint) - as "true"; +select cast('2' as int2) * cast('2' as int2) = cast('16' as int2) / cast('4' as int2) as "true"; -select - cast('2' as int) * cast('2' as smallint) = - cast('16' as smallint) / cast('4' as int) - as "true"; +select cast('2' as int4) * cast('2' as int2) = cast('16' as int2) / cast('4' as int4) as "true"; -select - cast('2' as smallint) * cast('2' as int) = - cast('16' as int) / cast('4' as smallint) - as "true"; +select cast('2' as int2) * cast('2' as int4) = cast('16' as int4) / cast('4' as int2) as "true"; -select cast('1000' as int) < cast('999' as int) as "false"; +select cast('1000' as int4) < cast('999' as int4) as "false"; select 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 as ten; @@ -116,41 +107,41 @@ select 2 + 2 / 2 as three; select (2 + 2) / 2 as two; -select cast(-cast(1 as int) << 31 as text); +select cast(-cast(1 as int4) << 31 as text); -select cast((-cast(1 as int) << 31) + 1 as text); +select cast((-cast(1 as int4) << 31) + 1 as text); -select cast(-2147483648 as int) * cast(-1 as int); +select cast(-2147483648 as int4) * cast(-1 as int4); -select cast(-2147483648 as int) / cast(-1 as int); +select cast(-2147483648 as int4) / cast(-1 as int4); -select cast(-2147483648 as int) % cast(-1 as int); +select cast(-2147483648 as int4) % cast(-1 as int4); -select cast(-2147483648 as int) * cast(-1 as smallint); +select cast(-2147483648 as int4) * cast(-1 as int2); -select cast(-2147483648 as int) / cast(-1 as smallint); +select cast(-2147483648 as int4) / cast(-1 as int2); -select cast(-2147483648 as int) % cast(-1 as smallint); +select cast(-2147483648 as int4) % cast(-1 as int2); select x, - cast(x as int) as int4_value + cast(x as int4) as int4_value from ( values - (-cast(2.5 as double precision)), - (-cast(1.5 as double precision)), - (-cast(0.5 as double precision)), - (cast(0.0 as double precision)), - (cast(0.5 as double precision)), - (cast(1.5 as double precision)), - (cast(2.5 as double precision)) + (-cast(2.5 as float8)), + (-cast(1.5 as float8)), + (-cast(0.5 as float8)), + (cast(0.0 as float8)), + (cast(0.5 as float8)), + (cast(1.5 as float8)), + (cast(2.5 as float8)) ) as t (x); select x, - cast(x as int) as int4_value + cast(x as int4) as int4_value from ( values @@ -174,23 +165,19 @@ select from ( values - (cast(0 as int), cast(0 as int)), - (cast(0 as int), cast(6410818 as int)), - (cast(61866666 as int), cast(6410818 as int)), - (-cast(61866666 as int), cast(6410818 as int)), - (cast(-2147483648 as int), cast(1 as int)), - ( - cast(-2147483648 as int), cast(2147483647 as int) - ), - ( - cast(-2147483648 as int), cast(1073741824 as int) - ) + (cast(0 as int4), cast(0 as int4)), + (cast(0 as int4), cast(6410818 as int4)), + (cast(61866666 as int4), cast(6410818 as int4)), + (-cast(61866666 as int4), cast(6410818 as int4)), + (cast(-2147483648 as int4), cast(1 as int4)), + (cast(-2147483648 as int4), cast(2147483647 as int4)), + (cast(-2147483648 as int4), cast(1073741824 as int4)) ) as v (a, b); -select gcd(cast(-2147483648 as int), cast(0 as int)); +select gcd(cast(-2147483648 as int4), cast(0 as int4)); -select gcd(cast(-2147483648 as int), cast(-2147483648 as int)); +select gcd(cast(-2147483648 as int4), cast(-2147483648 as int4)); select a, @@ -202,67 +189,67 @@ select from ( values - (cast(0 as int), cast(0 as int)), - (cast(0 as int), cast(42 as int)), - (cast(42 as int), cast(42 as int)), - (cast(330 as int), cast(462 as int)), - (-cast(330 as int), cast(462 as int)), - (cast(-2147483648 as int), cast(0 as int)) + (cast(0 as int4), cast(0 as int4)), + (cast(0 as int4), cast(42 as int4)), + (cast(42 as int4), cast(42 as int4)), + (cast(330 as int4), cast(462 as int4)), + (-cast(330 as int4), cast(462 as int4)), + (cast(-2147483648 as int4), cast(0 as int4)) ) as v (a, b); -select lcm(cast(-2147483648 as int), cast(1 as int)); +select lcm(cast(-2147483648 as int4), cast(1 as int4)); -select lcm(cast(2147483647 as int), cast(2147483646 as int)); +select lcm(cast(2147483647 as int4), cast(2147483646 as int4)); -select cast('0b100101' as int); +select cast('0b100101' as int4); -select cast('0o273' as int); +select cast('0o273' as int4); -select cast('0x42F' as int); +select cast('0x42F' as int4); -select cast('0b' as int); +select cast('0b' as int4); -select cast('0o' as int); +select cast('0o' as int4); -select cast('0x' as int); +select cast('0x' as int4); -select cast('0b1111111111111111111111111111111' as int); +select cast('0b1111111111111111111111111111111' as int4); -select cast('0b10000000000000000000000000000000' as int); +select cast('0b10000000000000000000000000000000' as int4); -select cast('0o17777777777' as int); +select cast('0o17777777777' as int4); -select cast('0o20000000000' as int); +select cast('0o20000000000' as int4); -select cast('0x7FFFFFFF' as int); +select cast('0x7FFFFFFF' as int4); -select cast('0x80000000' as int); +select cast('0x80000000' as int4); -select cast('-0b10000000000000000000000000000000' as int); +select cast('-0b10000000000000000000000000000000' as int4); -select cast('-0b10000000000000000000000000000001' as int); +select cast('-0b10000000000000000000000000000001' as int4); -select cast('-0o20000000000' as int); +select cast('-0o20000000000' as int4); -select cast('-0o20000000001' as int); +select cast('-0o20000000001' as int4); -select cast('-0x80000000' as int); +select cast('-0x80000000' as int4); -select cast('-0x80000001' as int); +select cast('-0x80000001' as int4); -select cast('1_000_000' as int); +select cast('1_000_000' as int4); -select cast('1_2_3' as int); +select cast('1_2_3' as int4); -select cast('0x1EEE_FFFF' as int); +select cast('0x1EEE_FFFF' as int4); -select cast('0o2_73' as int); +select cast('0o2_73' as int4); -select cast('0b_10_0101' as int); +select cast('0b_10_0101' as int4); -select cast('_100' as int); +select cast('_100' as int4); -select cast('100_' as int); +select cast('100_' as int4); -select cast('100__000' as int); +select cast('100__000' as int4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int4_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int4_80.snap index b7a5d4843..f6164aecf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int4_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int4_80.snap @@ -29,109 +29,107 @@ select pg_input_is_valid('1000000000000', 'int4'); select * from pg_input_error_info('1000000000000', 'int4'); -select i.* from int4_tbl as i where i.f1 <> cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 <> cast('0' as int2); -select i.* from int4_tbl as i where i.f1 <> cast('0' as int); +select i.* from int4_tbl as i where i.f1 <> cast('0' as int4); -select i.* from int4_tbl as i where i.f1 = cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 = cast('0' as int2); -select i.* from int4_tbl as i where i.f1 = cast('0' as int); +select i.* from int4_tbl as i where i.f1 = cast('0' as int4); -select i.* from int4_tbl as i where i.f1 < cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 < cast('0' as int2); -select i.* from int4_tbl as i where i.f1 < cast('0' as int); +select i.* from int4_tbl as i where i.f1 < cast('0' as int4); -select i.* from int4_tbl as i where i.f1 <= cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 <= cast('0' as int2); -select i.* from int4_tbl as i where i.f1 <= cast('0' as int); +select i.* from int4_tbl as i where i.f1 <= cast('0' as int4); -select i.* from int4_tbl as i where i.f1 > cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 > cast('0' as int2); -select i.* from int4_tbl as i where i.f1 > cast('0' as int); +select i.* from int4_tbl as i where i.f1 > cast('0' as int4); -select i.* from int4_tbl as i where i.f1 >= cast('0' as smallint); +select i.* from int4_tbl as i where i.f1 >= cast('0' as int2); -select i.* from int4_tbl as i where i.f1 >= cast('0' as int); +select i.* from int4_tbl as i where i.f1 >= cast('0' as int4); select i.* from int4_tbl as i where - i.f1 % cast('2' as smallint) = - cast('1' as smallint); + i.f1 % cast('2' as int2) = cast('1' as int2); select i.* from int4_tbl as i where - i.f1 % cast('2' as int) = - cast('0' as smallint); + i.f1 % cast('2' as int4) = cast('0' as int2); -select i.f1, i.f1 * cast('2' as smallint) as x from int4_tbl as i; +select i.f1, i.f1 * cast('2' as int2) as x from int4_tbl as i; select i.f1, - i.f1 * cast('2' as smallint) as x + i.f1 * cast('2' as int2) as x from int4_tbl as i where abs(f1) < 1073741824; -select i.f1, i.f1 * cast('2' as int) as x from int4_tbl as i; +select i.f1, i.f1 * cast('2' as int4) as x from int4_tbl as i; select i.f1, - i.f1 * cast('2' as int) as x + i.f1 * cast('2' as int4) as x from int4_tbl as i where abs(f1) < 1073741824; -select i.f1, i.f1 + cast('2' as smallint) as x from int4_tbl as i; +select i.f1, i.f1 + cast('2' as int2) as x from int4_tbl as i; select i.f1, - i.f1 + cast('2' as smallint) as x + i.f1 + cast('2' as int2) as x from int4_tbl as i where f1 < 2147483646; -select i.f1, i.f1 + cast('2' as int) as x from int4_tbl as i; +select i.f1, i.f1 + cast('2' as int4) as x from int4_tbl as i; select i.f1, - i.f1 + cast('2' as int) as x + i.f1 + cast('2' as int4) as x from int4_tbl as i where f1 < 2147483646; -select i.f1, i.f1 - cast('2' as smallint) as x from int4_tbl as i; +select i.f1, i.f1 - cast('2' as int2) as x from int4_tbl as i; select i.f1, - i.f1 - cast('2' as smallint) as x + i.f1 - cast('2' as int2) as x from int4_tbl as i where f1 > -2147483647; -select i.f1, i.f1 - cast('2' as int) as x from int4_tbl as i; +select i.f1, i.f1 - cast('2' as int4) as x from int4_tbl as i; select i.f1, - i.f1 - cast('2' as int) as x + i.f1 - cast('2' as int4) as x from int4_tbl as i where f1 > -2147483647; -select i.f1, i.f1 / cast('2' as smallint) as x from int4_tbl as i; +select i.f1, i.f1 / cast('2' as int2) as x from int4_tbl as i; -select i.f1, i.f1 / cast('2' as int) as x from int4_tbl as i; +select i.f1, i.f1 / cast('2' as int4) as x from int4_tbl as i; select -2 + 3 as one; @@ -142,25 +140,18 @@ select 2 - -1 as three; select 2 - -2 as four; select - cast('2' as smallint) * - cast('2' as smallint) = - cast('16' as smallint) / - cast('4' as smallint) + cast('2' as int2) * cast('2' as int2) = cast('16' as int2) / cast('4' as int2) as "true"; select - cast('2' as int) * cast('2' as smallint) = - cast('16' as smallint) / - cast('4' as int) + cast('2' as int4) * cast('2' as int2) = cast('16' as int2) / cast('4' as int4) as "true"; select - cast('2' as smallint) * cast('2' as int) = - cast('16' as int) / - cast('4' as smallint) + cast('2' as int2) * cast('2' as int4) = cast('16' as int4) / cast('4' as int2) as "true"; -select cast('1000' as int) < cast('999' as int) as "false"; +select cast('1000' as int4) < cast('999' as int4) as "false"; select 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 as ten; @@ -168,41 +159,41 @@ select 2 + 2 / 2 as three; select (2 + 2) / 2 as two; -select cast(-cast(1 as int) << 31 as text); +select cast(-cast(1 as int4) << 31 as text); -select cast((-cast(1 as int) << 31) + 1 as text); +select cast((-cast(1 as int4) << 31) + 1 as text); -select cast(-2147483648 as int) * cast(-1 as int); +select cast(-2147483648 as int4) * cast(-1 as int4); -select cast(-2147483648 as int) / cast(-1 as int); +select cast(-2147483648 as int4) / cast(-1 as int4); -select cast(-2147483648 as int) % cast(-1 as int); +select cast(-2147483648 as int4) % cast(-1 as int4); -select cast(-2147483648 as int) * cast(-1 as smallint); +select cast(-2147483648 as int4) * cast(-1 as int2); -select cast(-2147483648 as int) / cast(-1 as smallint); +select cast(-2147483648 as int4) / cast(-1 as int2); -select cast(-2147483648 as int) % cast(-1 as smallint); +select cast(-2147483648 as int4) % cast(-1 as int2); select x, - cast(x as int) as int4_value + cast(x as int4) as int4_value from ( values - (-cast(2.5 as double precision)), - (-cast(1.5 as double precision)), - (-cast(0.5 as double precision)), - (cast(0.0 as double precision)), - (cast(0.5 as double precision)), - (cast(1.5 as double precision)), - (cast(2.5 as double precision)) + (-cast(2.5 as float8)), + (-cast(1.5 as float8)), + (-cast(0.5 as float8)), + (cast(0.0 as float8)), + (cast(0.5 as float8)), + (cast(1.5 as float8)), + (cast(2.5 as float8)) ) as t (x); select x, - cast(x as int) as int4_value + cast(x as int4) as int4_value from ( values @@ -226,33 +217,19 @@ select from ( values - (cast(0 as int), cast(0 as int)), - (cast(0 as int), cast(6410818 as int)), - ( - cast(61866666 as int), - cast(6410818 as int) - ), - ( - -cast(61866666 as int), - cast(6410818 as int) - ), - ( - cast(-2147483648 as int), cast(1 as int) - ), - ( - cast(-2147483648 as int), - cast(2147483647 as int) - ), - ( - cast(-2147483648 as int), - cast(1073741824 as int) - ) + (cast(0 as int4), cast(0 as int4)), + (cast(0 as int4), cast(6410818 as int4)), + (cast(61866666 as int4), cast(6410818 as int4)), + (-cast(61866666 as int4), cast(6410818 as int4)), + (cast(-2147483648 as int4), cast(1 as int4)), + (cast(-2147483648 as int4), cast(2147483647 as int4)), + (cast(-2147483648 as int4), cast(1073741824 as int4)) ) as v (a, b); -select gcd(cast(-2147483648 as int), cast(0 as int)); +select gcd(cast(-2147483648 as int4), cast(0 as int4)); -select gcd(cast(-2147483648 as int), cast(-2147483648 as int)); +select gcd(cast(-2147483648 as int4), cast(-2147483648 as int4)); select a, @@ -264,69 +241,67 @@ select from ( values - (cast(0 as int), cast(0 as int)), - (cast(0 as int), cast(42 as int)), - (cast(42 as int), cast(42 as int)), - (cast(330 as int), cast(462 as int)), - (-cast(330 as int), cast(462 as int)), - ( - cast(-2147483648 as int), cast(0 as int) - ) + (cast(0 as int4), cast(0 as int4)), + (cast(0 as int4), cast(42 as int4)), + (cast(42 as int4), cast(42 as int4)), + (cast(330 as int4), cast(462 as int4)), + (-cast(330 as int4), cast(462 as int4)), + (cast(-2147483648 as int4), cast(0 as int4)) ) as v (a, b); -select lcm(cast(-2147483648 as int), cast(1 as int)); +select lcm(cast(-2147483648 as int4), cast(1 as int4)); -select lcm(cast(2147483647 as int), cast(2147483646 as int)); +select lcm(cast(2147483647 as int4), cast(2147483646 as int4)); -select cast('0b100101' as int); +select cast('0b100101' as int4); -select cast('0o273' as int); +select cast('0o273' as int4); -select cast('0x42F' as int); +select cast('0x42F' as int4); -select cast('0b' as int); +select cast('0b' as int4); -select cast('0o' as int); +select cast('0o' as int4); -select cast('0x' as int); +select cast('0x' as int4); -select cast('0b1111111111111111111111111111111' as int); +select cast('0b1111111111111111111111111111111' as int4); -select cast('0b10000000000000000000000000000000' as int); +select cast('0b10000000000000000000000000000000' as int4); -select cast('0o17777777777' as int); +select cast('0o17777777777' as int4); -select cast('0o20000000000' as int); +select cast('0o20000000000' as int4); -select cast('0x7FFFFFFF' as int); +select cast('0x7FFFFFFF' as int4); -select cast('0x80000000' as int); +select cast('0x80000000' as int4); -select cast('-0b10000000000000000000000000000000' as int); +select cast('-0b10000000000000000000000000000000' as int4); -select cast('-0b10000000000000000000000000000001' as int); +select cast('-0b10000000000000000000000000000001' as int4); -select cast('-0o20000000000' as int); +select cast('-0o20000000000' as int4); -select cast('-0o20000000001' as int); +select cast('-0o20000000001' as int4); -select cast('-0x80000000' as int); +select cast('-0x80000000' as int4); -select cast('-0x80000001' as int); +select cast('-0x80000001' as int4); -select cast('1_000_000' as int); +select cast('1_000_000' as int4); -select cast('1_2_3' as int); +select cast('1_2_3' as int4); -select cast('0x1EEE_FFFF' as int); +select cast('0x1EEE_FFFF' as int4); -select cast('0o2_73' as int); +select cast('0o2_73' as int4); -select cast('0b_10_0101' as int); +select cast('0b_10_0101' as int4); -select cast('_100' as int); +select cast('_100' as int4); -select cast('100_' as int); +select cast('100_' as int4); -select cast('100__000' as int); +select cast('100__000' as int4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int8_100.snap index 4288e09f2..7844ef8ac 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int8_100.snap @@ -62,29 +62,29 @@ select * from int8_tbl where 123 <= q1; select * from int8_tbl where 123 >= q1; -select * from int8_tbl where q2 = cast('456' as smallint); +select * from int8_tbl where q2 = cast('456' as int2); -select * from int8_tbl where q2 <> cast('456' as smallint); +select * from int8_tbl where q2 <> cast('456' as int2); -select * from int8_tbl where q2 < cast('456' as smallint); +select * from int8_tbl where q2 < cast('456' as int2); -select * from int8_tbl where q2 > cast('456' as smallint); +select * from int8_tbl where q2 > cast('456' as int2); -select * from int8_tbl where q2 <= cast('456' as smallint); +select * from int8_tbl where q2 <= cast('456' as int2); -select * from int8_tbl where q2 >= cast('456' as smallint); +select * from int8_tbl where q2 >= cast('456' as int2); -select * from int8_tbl where cast('123' as smallint) = q1; +select * from int8_tbl where cast('123' as int2) = q1; -select * from int8_tbl where cast('123' as smallint) <> q1; +select * from int8_tbl where cast('123' as int2) <> q1; -select * from int8_tbl where cast('123' as smallint) < q1; +select * from int8_tbl where cast('123' as int2) < q1; -select * from int8_tbl where cast('123' as smallint) > q1; +select * from int8_tbl where cast('123' as int2) > q1; -select * from int8_tbl where cast('123' as smallint) <= q1; +select * from int8_tbl where cast('123' as int2) <= q1; -select * from int8_tbl where cast('123' as smallint) >= q1; +select * from int8_tbl where cast('123' as int2) >= q1; select q1 as plus, -q1 as minus from int8_tbl; @@ -111,42 +111,42 @@ select 2 * q1 as "twice int4" from int8_tbl; select q1 * 2 as "twice int4" from int8_tbl; select - q1 + cast(42 as int) as "8plus4", - q1 - cast(42 as int) as "8minus4", - q1 * cast(42 as int) as "8mul4", - q1 / cast(42 as int) as "8div4" + q1 + cast(42 as int4) as "8plus4", + q1 - cast(42 as int4) as "8minus4", + q1 * cast(42 as int4) as "8mul4", + q1 / cast(42 as int4) as "8div4" from int8_tbl; select - cast(246 as int) + q1 as "4plus8", - cast(246 as int) - q1 as "4minus8", - cast(246 as int) * q1 as "4mul8", - cast(246 as int) / q1 as "4div8" + cast(246 as int4) + q1 as "4plus8", + cast(246 as int4) - q1 as "4minus8", + cast(246 as int4) * q1 as "4mul8", + cast(246 as int4) / q1 as "4div8" from int8_tbl; select - q1 + cast(42 as smallint) as "8plus2", - q1 - cast(42 as smallint) as "8minus2", - q1 * cast(42 as smallint) as "8mul2", - q1 / cast(42 as smallint) as "8div2" + q1 + cast(42 as int2) as "8plus2", + q1 - cast(42 as int2) as "8minus2", + q1 * cast(42 as int2) as "8mul2", + q1 / cast(42 as int2) as "8div2" from int8_tbl; select - cast(246 as smallint) + q1 as "2plus8", - cast(246 as smallint) - q1 as "2minus8", - cast(246 as smallint) * q1 as "2mul8", - cast(246 as smallint) / q1 as "2div8" + cast(246 as int2) + q1 as "2plus8", + cast(246 as int2) - q1 as "2minus8", + cast(246 as int2) * q1 as "2mul8", + cast(246 as int2) / q1 as "2div8" from int8_tbl; select q2, abs(q2) from int8_tbl; -select MIN(q1), MIN(q2) from int8_tbl; +select min(q1), min(q2) from int8_tbl; -select MAX(q1), MAX(q2) from int8_tbl; +select max(q1), max(q2) from int8_tbl; select to_char(q1, '9G999G999G999G999G999'), to_char(q2, '9,999,999,999,999,999') from int8_tbl; @@ -189,10 +189,7 @@ select to_char(q2, 'FM9999999999999999.999') from int8_tbl; select to_char(q2, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9') from int8_tbl; select - to_char( - q2, - '99999 "text" 9999 "9999" 999 "\"text between quote marks\"" 9999' - ) + to_char(q2, '99999 "text" 9999 "9999" 999 "\"text between quote marks\"" 9999') from int8_tbl; @@ -202,163 +199,149 @@ select to_char(q2, 'FMRN') from int8_tbl; select to_char(1234, '9.99EEEE'); -select to_char(cast(1234 as bigint), '9.99eeee'); +select to_char(cast(1234 as int8), '9.99eeee'); -select to_char(-cast(1234 as bigint), '9.99eeee'); +select to_char(-cast(1234 as int8), '9.99eeee'); select to_char(1234, '99999V99'); -select to_char(cast(1234 as bigint), '99999V99'); +select to_char(cast(1234 as int8), '99999V99'); -select cast('-9223372036854775808' as bigint); +select cast('-9223372036854775808' as int8); -select cast('-9223372036854775809' as bigint); +select cast('-9223372036854775809' as int8); -select cast('9223372036854775807' as bigint); +select cast('9223372036854775807' as int8); -select cast('9223372036854775808' as bigint); +select cast('9223372036854775808' as int8); -select -cast('-9223372036854775807' as bigint); +select -cast('-9223372036854775807' as int8); -select -cast('-9223372036854775808' as bigint); +select -cast('-9223372036854775808' as int8); -select cast(0 as bigint) - cast('-9223372036854775808' as bigint); +select cast(0 as int8) - cast('-9223372036854775808' as int8); -select cast('9223372036854775800' as bigint) + cast('9223372036854775800' as bigint); +select cast('9223372036854775800' as int8) + cast('9223372036854775800' as int8); -select cast('-9223372036854775800' as bigint) + cast('-9223372036854775800' as bigint); +select cast('-9223372036854775800' as int8) + cast('-9223372036854775800' as int8); -select cast('9223372036854775800' as bigint) - cast('-9223372036854775800' as bigint); +select cast('9223372036854775800' as int8) - cast('-9223372036854775800' as int8); -select cast('-9223372036854775800' as bigint) - cast('9223372036854775800' as bigint); +select cast('-9223372036854775800' as int8) - cast('9223372036854775800' as int8); -select cast('9223372036854775800' as bigint) * cast('9223372036854775800' as bigint); +select cast('9223372036854775800' as int8) * cast('9223372036854775800' as int8); -select cast('9223372036854775800' as bigint) / cast('0' as bigint); +select cast('9223372036854775800' as int8) / cast('0' as int8); -select cast('9223372036854775800' as bigint) % cast('0' as bigint); +select cast('9223372036854775800' as int8) % cast('0' as int8); -select abs(cast('-9223372036854775808' as bigint)); +select abs(cast('-9223372036854775808' as int8)); -select cast('9223372036854775800' as bigint) + cast('100' as int); +select cast('9223372036854775800' as int8) + cast('100' as int4); -select cast('-9223372036854775800' as bigint) - cast('100' as int); +select cast('-9223372036854775800' as int8) - cast('100' as int4); -select cast('9223372036854775800' as bigint) * cast('100' as int); +select cast('9223372036854775800' as int8) * cast('100' as int4); -select cast('100' as int) + cast('9223372036854775800' as bigint); +select cast('100' as int4) + cast('9223372036854775800' as int8); -select cast('-100' as int) - cast('9223372036854775800' as bigint); +select cast('-100' as int4) - cast('9223372036854775800' as int8); -select cast('100' as int) * cast('9223372036854775800' as bigint); +select cast('100' as int4) * cast('9223372036854775800' as int8); -select cast('9223372036854775800' as bigint) + cast('100' as smallint); +select cast('9223372036854775800' as int8) + cast('100' as int2); -select cast('-9223372036854775800' as bigint) - cast('100' as smallint); +select cast('-9223372036854775800' as int8) - cast('100' as int2); -select cast('9223372036854775800' as bigint) * cast('100' as smallint); +select cast('9223372036854775800' as int8) * cast('100' as int2); -select cast('-9223372036854775808' as bigint) / cast('0' as smallint); +select cast('-9223372036854775808' as int8) / cast('0' as int2); -select cast('100' as smallint) + cast('9223372036854775800' as bigint); +select cast('100' as int2) + cast('9223372036854775800' as int8); -select cast('-100' as smallint) - cast('9223372036854775800' as bigint); +select cast('-100' as int2) - cast('9223372036854775800' as int8); -select cast('100' as smallint) * cast('9223372036854775800' as bigint); +select cast('100' as int2) * cast('9223372036854775800' as int8); -select cast('100' as smallint) / cast('0' as bigint); +select cast('100' as int2) / cast('0' as int8); -select cast(q1 as int) from int8_tbl where q2 = 456; +select cast(q1 as int4) from int8_tbl where q2 = 456; -select cast(q1 as int) from int8_tbl where q2 <> 456; +select cast(q1 as int4) from int8_tbl where q2 <> 456; -select cast(q1 as smallint) from int8_tbl where q2 = 456; +select cast(q1 as int2) from int8_tbl where q2 = 456; -select cast(q1 as smallint) from int8_tbl where q2 <> 456; +select cast(q1 as int2) from int8_tbl where q2 <> 456; -select cast(cast('42' as smallint) as bigint), cast(cast('-37' as smallint) as bigint); +select cast(cast('42' as int2) as int8), cast(cast('-37' as int2) as int8); -select cast(q1 as real), cast(q2 as double precision) from int8_tbl; +select cast(q1 as float4), cast(q2 as float8) from int8_tbl; -select cast(cast('36854775807.0' as real) as bigint); +select cast(cast('36854775807.0' as float4) as int8); -select cast(cast('922337203685477580700.0' as double precision) as bigint); +select cast(cast('922337203685477580700.0' as float8) as int8); select cast(q1 as oid) from int8_tbl; -select cast(oid as bigint) from pg_class where relname = 'pg_class'; +select cast(oid as int8) from pg_class where relname = 'pg_class'; select q1, q2, q1 & q2 as "and", q1 | q2 as "or", q1 # q2 as xor, ~q1 as "not" from int8_tbl; select q1, q1 << 2 as shl, q1 >> 3 as shr from int8_tbl; -select - * -from - generate_series( - cast('+4567890123456789' as bigint), - cast('+4567890123456799' as bigint) - ); +select * from generate_series(cast('+4567890123456789' as int8), cast('+4567890123456799' as int8)); select * from - generate_series( - cast('+4567890123456789' as bigint), - cast('+4567890123456799' as bigint), - 0 - ); + generate_series(cast('+4567890123456789' as int8), cast('+4567890123456799' as int8), 0); select * from - generate_series( - cast('+4567890123456789' as bigint), - cast('+4567890123456799' as bigint), - 2 - ); + generate_series(cast('+4567890123456789' as int8), cast('+4567890123456799' as int8), 2); -select cast(-cast(1 as bigint) << 63 as text); +select cast(-cast(1 as int8) << 63 as text); -select cast((-cast(1 as bigint) << 63) + 1 as text); +select cast((-cast(1 as int8) << 63) + 1 as text); -select cast(-9223372036854775808 as bigint) * cast(-1 as bigint); +select cast(-9223372036854775808 as int8) * cast(-1 as int8); -select cast(-9223372036854775808 as bigint) / cast(-1 as bigint); +select cast(-9223372036854775808 as int8) / cast(-1 as int8); -select cast(-9223372036854775808 as bigint) % cast(-1 as bigint); +select cast(-9223372036854775808 as int8) % cast(-1 as int8); -select cast(-9223372036854775808 as bigint) * cast(-1 as int); +select cast(-9223372036854775808 as int8) * cast(-1 as int4); -select cast(-9223372036854775808 as bigint) / cast(-1 as int); +select cast(-9223372036854775808 as int8) / cast(-1 as int4); -select cast(-9223372036854775808 as bigint) % cast(-1 as int); +select cast(-9223372036854775808 as int8) % cast(-1 as int4); -select cast(-9223372036854775808 as bigint) * cast(-1 as smallint); +select cast(-9223372036854775808 as int8) * cast(-1 as int2); -select cast(-9223372036854775808 as bigint) / cast(-1 as smallint); +select cast(-9223372036854775808 as int8) / cast(-1 as int2); -select cast(-9223372036854775808 as bigint) % cast(-1 as smallint); +select cast(-9223372036854775808 as int8) % cast(-1 as int2); select x, - cast(x as bigint) as int8_value + cast(x as int8) as int8_value from ( values - (-cast(2.5 as double precision)), - (-cast(1.5 as double precision)), - (-cast(0.5 as double precision)), - (cast(0.0 as double precision)), - (cast(0.5 as double precision)), - (cast(1.5 as double precision)), - (cast(2.5 as double precision)) + (-cast(2.5 as float8)), + (-cast(1.5 as float8)), + (-cast(0.5 as float8)), + (cast(0.0 as float8)), + (cast(0.5 as float8)), + (cast(1.5 as float8)), + (cast(2.5 as float8)) ) as t (x); select x, - cast(x as bigint) as int8_value + cast(x as int8) as int8_value from ( values @@ -382,34 +365,19 @@ select from ( values - (cast(0 as bigint), cast(0 as bigint)), - (cast(0 as bigint), cast(29893644334 as bigint)), - ( - cast(288484263558 as bigint), - cast(29893644334 as bigint) - ), - ( - -cast(288484263558 as bigint), - cast(29893644334 as bigint) - ), - ( - cast(-9223372036854775808 as bigint), - cast(1 as bigint) - ), - ( - cast(-9223372036854775808 as bigint), - cast(9223372036854775807 as bigint) - ), - ( - cast(-9223372036854775808 as bigint), - cast(4611686018427387904 as bigint) - ) + (cast(0 as int8), cast(0 as int8)), + (cast(0 as int8), cast(29893644334 as int8)), + (cast(288484263558 as int8), cast(29893644334 as int8)), + (-cast(288484263558 as int8), cast(29893644334 as int8)), + (cast(-9223372036854775808 as int8), cast(1 as int8)), + (cast(-9223372036854775808 as int8), cast(9223372036854775807 as int8)), + (cast(-9223372036854775808 as int8), cast(4611686018427387904 as int8)) ) as v (a, b); -select gcd(cast(-9223372036854775808 as bigint), cast(0 as bigint)); +select gcd(cast(-9223372036854775808 as int8), cast(0 as int8)); -select gcd(cast(-9223372036854775808 as bigint), cast(-9223372036854775808 as bigint)); +select gcd(cast(-9223372036854775808 as int8), cast(-9223372036854775808 as int8)); select a, @@ -421,79 +389,67 @@ select from ( values - (cast(0 as bigint), cast(0 as bigint)), - (cast(0 as bigint), cast(29893644334 as bigint)), - ( - cast(29893644334 as bigint), - cast(29893644334 as bigint) - ), - ( - cast(288484263558 as bigint), - cast(29893644334 as bigint) - ), - ( - -cast(288484263558 as bigint), - cast(29893644334 as bigint) - ), - ( - cast(-9223372036854775808 as bigint), - cast(0 as bigint) - ) + (cast(0 as int8), cast(0 as int8)), + (cast(0 as int8), cast(29893644334 as int8)), + (cast(29893644334 as int8), cast(29893644334 as int8)), + (cast(288484263558 as int8), cast(29893644334 as int8)), + (-cast(288484263558 as int8), cast(29893644334 as int8)), + (cast(-9223372036854775808 as int8), cast(0 as int8)) ) as v (a, b); -select lcm(cast(-9223372036854775808 as bigint), cast(1 as bigint)); +select lcm(cast(-9223372036854775808 as int8), cast(1 as int8)); -select lcm(cast(9223372036854775807 as bigint), cast(9223372036854775806 as bigint)); +select lcm(cast(9223372036854775807 as int8), cast(9223372036854775806 as int8)); -select cast('0b100101' as bigint); +select cast('0b100101' as int8); -select cast('0o273' as bigint); +select cast('0o273' as int8); -select cast('0x42F' as bigint); +select cast('0x42F' as int8); -select cast('0b' as bigint); +select cast('0b' as int8); -select cast('0o' as bigint); +select cast('0o' as int8); -select cast('0x' as bigint); +select cast('0x' as int8); -select cast('0b111111111111111111111111111111111111111111111111111111111111111' as bigint); +select cast('0b111111111111111111111111111111111111111111111111111111111111111' as int8); -select cast('0b1000000000000000000000000000000000000000000000000000000000000000' as bigint); +select cast('0b1000000000000000000000000000000000000000000000000000000000000000' as int8); -select cast('0o777777777777777777777' as bigint); +select cast('0o777777777777777777777' as int8); -select cast('0o1000000000000000000000' as bigint); +select cast('0o1000000000000000000000' as int8); -select cast('0x7FFFFFFFFFFFFFFF' as bigint); +select cast('0x7FFFFFFFFFFFFFFF' as int8); -select cast('0x8000000000000000' as bigint); +select cast('0x8000000000000000' as int8); -select cast('-0b1000000000000000000000000000000000000000000000000000000000000000' as bigint); +select cast('-0b1000000000000000000000000000000000000000000000000000000000000000' as int8); -select cast('-0b1000000000000000000000000000000000000000000000000000000000000001' as bigint); +select cast('-0b1000000000000000000000000000000000000000000000000000000000000001' as int8); -select cast('-0o1000000000000000000000' as bigint); +select cast('-0o1000000000000000000000' as int8); -select cast('-0o1000000000000000000001' as bigint); +select cast('-0o1000000000000000000001' as int8); -select cast('-0x8000000000000000' as bigint); +select cast('-0x8000000000000000' as int8); -select cast('-0x8000000000000001' as bigint); +select cast('-0x8000000000000001' as int8); -select cast('1_000_000' as bigint); +select cast('1_000_000' as int8); -select cast('1_2_3' as bigint); +select cast('1_2_3' as int8); -select cast('0x1EEE_FFFF' as bigint); +select cast('0x1EEE_FFFF' as int8); -select cast('0o2_73' as bigint); +select cast('0o2_73' as int8); -select cast('0b_10_0101' as bigint); +select cast('0b_10_0101' as int8); -select cast('_100' as bigint); +select cast('_100' as int8); -select cast('100_' as bigint); +select cast('100_' as int8); -select cast('100__000' as bigint); +select cast('100__000' as int8); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int8_80.snap index 332ef4857..f67ba6ee9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__int8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__int8_80.snap @@ -62,29 +62,29 @@ select * from int8_tbl where 123 <= q1; select * from int8_tbl where 123 >= q1; -select * from int8_tbl where q2 = cast('456' as smallint); +select * from int8_tbl where q2 = cast('456' as int2); -select * from int8_tbl where q2 <> cast('456' as smallint); +select * from int8_tbl where q2 <> cast('456' as int2); -select * from int8_tbl where q2 < cast('456' as smallint); +select * from int8_tbl where q2 < cast('456' as int2); -select * from int8_tbl where q2 > cast('456' as smallint); +select * from int8_tbl where q2 > cast('456' as int2); -select * from int8_tbl where q2 <= cast('456' as smallint); +select * from int8_tbl where q2 <= cast('456' as int2); -select * from int8_tbl where q2 >= cast('456' as smallint); +select * from int8_tbl where q2 >= cast('456' as int2); -select * from int8_tbl where cast('123' as smallint) = q1; +select * from int8_tbl where cast('123' as int2) = q1; -select * from int8_tbl where cast('123' as smallint) <> q1; +select * from int8_tbl where cast('123' as int2) <> q1; -select * from int8_tbl where cast('123' as smallint) < q1; +select * from int8_tbl where cast('123' as int2) < q1; -select * from int8_tbl where cast('123' as smallint) > q1; +select * from int8_tbl where cast('123' as int2) > q1; -select * from int8_tbl where cast('123' as smallint) <= q1; +select * from int8_tbl where cast('123' as int2) <= q1; -select * from int8_tbl where cast('123' as smallint) >= q1; +select * from int8_tbl where cast('123' as int2) >= q1; select q1 as plus, -q1 as minus from int8_tbl; @@ -118,42 +118,42 @@ select 2 * q1 as "twice int4" from int8_tbl; select q1 * 2 as "twice int4" from int8_tbl; select - q1 + cast(42 as int) as "8plus4", - q1 - cast(42 as int) as "8minus4", - q1 * cast(42 as int) as "8mul4", - q1 / cast(42 as int) as "8div4" + q1 + cast(42 as int4) as "8plus4", + q1 - cast(42 as int4) as "8minus4", + q1 * cast(42 as int4) as "8mul4", + q1 / cast(42 as int4) as "8div4" from int8_tbl; select - cast(246 as int) + q1 as "4plus8", - cast(246 as int) - q1 as "4minus8", - cast(246 as int) * q1 as "4mul8", - cast(246 as int) / q1 as "4div8" + cast(246 as int4) + q1 as "4plus8", + cast(246 as int4) - q1 as "4minus8", + cast(246 as int4) * q1 as "4mul8", + cast(246 as int4) / q1 as "4div8" from int8_tbl; select - q1 + cast(42 as smallint) as "8plus2", - q1 - cast(42 as smallint) as "8minus2", - q1 * cast(42 as smallint) as "8mul2", - q1 / cast(42 as smallint) as "8div2" + q1 + cast(42 as int2) as "8plus2", + q1 - cast(42 as int2) as "8minus2", + q1 * cast(42 as int2) as "8mul2", + q1 / cast(42 as int2) as "8div2" from int8_tbl; select - cast(246 as smallint) + q1 as "2plus8", - cast(246 as smallint) - q1 as "2minus8", - cast(246 as smallint) * q1 as "2mul8", - cast(246 as smallint) / q1 as "2div8" + cast(246 as int2) + q1 as "2plus8", + cast(246 as int2) - q1 as "2minus8", + cast(246 as int2) * q1 as "2mul8", + cast(246 as int2) / q1 as "2div8" from int8_tbl; select q2, abs(q2) from int8_tbl; -select MIN(q1), MIN(q2) from int8_tbl; +select min(q1), min(q2) from int8_tbl; -select MAX(q1), MAX(q2) from int8_tbl; +select max(q1), max(q2) from int8_tbl; select to_char(q1, '9G999G999G999G999G999'), @@ -162,23 +162,14 @@ from int8_tbl; select - to_char( - q1, - '9G999G999G999G999G999D999G999' - ), - to_char( - q2, - '9,999,999,999,999,999.999,999' - ) + to_char(q1, '9G999G999G999G999G999D999G999'), + to_char(q2, '9,999,999,999,999,999.999,999') from int8_tbl; select to_char(q1 * -1, '9999999999999999PR'), - to_char( - q2 * -1, - '9999999999999999.999PR' - ) + to_char(q2 * -1, '9999999999999999.999PR') from int8_tbl; @@ -226,103 +217,96 @@ select to_char(q2, 'FMRN') from int8_tbl; select to_char(1234, '9.99EEEE'); -select to_char(cast(1234 as bigint), '9.99eeee'); +select to_char(cast(1234 as int8), '9.99eeee'); -select to_char(-cast(1234 as bigint), '9.99eeee'); +select to_char(-cast(1234 as int8), '9.99eeee'); select to_char(1234, '99999V99'); -select to_char(cast(1234 as bigint), '99999V99'); +select to_char(cast(1234 as int8), '99999V99'); -select cast('-9223372036854775808' as bigint); +select cast('-9223372036854775808' as int8); -select cast('-9223372036854775809' as bigint); +select cast('-9223372036854775809' as int8); -select cast('9223372036854775807' as bigint); +select cast('9223372036854775807' as int8); -select cast('9223372036854775808' as bigint); +select cast('9223372036854775808' as int8); -select -cast('-9223372036854775807' as bigint); +select -cast('-9223372036854775807' as int8); -select -cast('-9223372036854775808' as bigint); +select -cast('-9223372036854775808' as int8); -select cast(0 as bigint) - cast('-9223372036854775808' as bigint); +select cast(0 as int8) - cast('-9223372036854775808' as int8); select - cast('9223372036854775800' as bigint) + - cast('9223372036854775800' as bigint); + cast('9223372036854775800' as int8) + cast('9223372036854775800' as int8); select - cast('-9223372036854775800' as bigint) + - cast('-9223372036854775800' as bigint); + cast('-9223372036854775800' as int8) + cast('-9223372036854775800' as int8); select - cast('9223372036854775800' as bigint) - - cast('-9223372036854775800' as bigint); + cast('9223372036854775800' as int8) - cast('-9223372036854775800' as int8); select - cast('-9223372036854775800' as bigint) - - cast('9223372036854775800' as bigint); + cast('-9223372036854775800' as int8) - cast('9223372036854775800' as int8); select - cast('9223372036854775800' as bigint) * - cast('9223372036854775800' as bigint); + cast('9223372036854775800' as int8) * cast('9223372036854775800' as int8); -select cast('9223372036854775800' as bigint) / cast('0' as bigint); +select cast('9223372036854775800' as int8) / cast('0' as int8); -select cast('9223372036854775800' as bigint) % cast('0' as bigint); +select cast('9223372036854775800' as int8) % cast('0' as int8); -select abs(cast('-9223372036854775808' as bigint)); +select abs(cast('-9223372036854775808' as int8)); -select cast('9223372036854775800' as bigint) + cast('100' as int); +select cast('9223372036854775800' as int8) + cast('100' as int4); -select cast('-9223372036854775800' as bigint) - cast('100' as int); +select cast('-9223372036854775800' as int8) - cast('100' as int4); -select cast('9223372036854775800' as bigint) * cast('100' as int); +select cast('9223372036854775800' as int8) * cast('100' as int4); -select cast('100' as int) + cast('9223372036854775800' as bigint); +select cast('100' as int4) + cast('9223372036854775800' as int8); -select cast('-100' as int) - cast('9223372036854775800' as bigint); +select cast('-100' as int4) - cast('9223372036854775800' as int8); -select cast('100' as int) * cast('9223372036854775800' as bigint); +select cast('100' as int4) * cast('9223372036854775800' as int8); -select cast('9223372036854775800' as bigint) + cast('100' as smallint); +select cast('9223372036854775800' as int8) + cast('100' as int2); -select cast('-9223372036854775800' as bigint) - cast('100' as smallint); +select cast('-9223372036854775800' as int8) - cast('100' as int2); -select cast('9223372036854775800' as bigint) * cast('100' as smallint); +select cast('9223372036854775800' as int8) * cast('100' as int2); -select cast('-9223372036854775808' as bigint) / cast('0' as smallint); +select cast('-9223372036854775808' as int8) / cast('0' as int2); -select cast('100' as smallint) + cast('9223372036854775800' as bigint); +select cast('100' as int2) + cast('9223372036854775800' as int8); -select cast('-100' as smallint) - cast('9223372036854775800' as bigint); +select cast('-100' as int2) - cast('9223372036854775800' as int8); -select cast('100' as smallint) * cast('9223372036854775800' as bigint); +select cast('100' as int2) * cast('9223372036854775800' as int8); -select cast('100' as smallint) / cast('0' as bigint); +select cast('100' as int2) / cast('0' as int8); -select cast(q1 as int) from int8_tbl where q2 = 456; +select cast(q1 as int4) from int8_tbl where q2 = 456; -select cast(q1 as int) from int8_tbl where q2 <> 456; +select cast(q1 as int4) from int8_tbl where q2 <> 456; -select cast(q1 as smallint) from int8_tbl where q2 = 456; +select cast(q1 as int2) from int8_tbl where q2 = 456; -select cast(q1 as smallint) from int8_tbl where q2 <> 456; +select cast(q1 as int2) from int8_tbl where q2 <> 456; -select - cast(cast('42' as smallint) as bigint), - cast(cast('-37' as smallint) as bigint); +select cast(cast('42' as int2) as int8), cast(cast('-37' as int2) as int8); -select cast(q1 as real), cast(q2 as double precision) from int8_tbl; +select cast(q1 as float4), cast(q2 as float8) from int8_tbl; -select cast(cast('36854775807.0' as real) as bigint); +select cast(cast('36854775807.0' as float4) as int8); -select cast(cast('922337203685477580700.0' as double precision) as bigint); +select cast(cast('922337203685477580700.0' as float8) as int8); select cast(q1 as oid) from int8_tbl; -select cast(oid as bigint) from pg_class where relname = 'pg_class'; +select cast(oid as int8) from pg_class where relname = 'pg_class'; select q1, @@ -340,16 +324,16 @@ select * from generate_series( - cast('+4567890123456789' as bigint), - cast('+4567890123456799' as bigint) + cast('+4567890123456789' as int8), + cast('+4567890123456799' as int8) ); select * from generate_series( - cast('+4567890123456789' as bigint), - cast('+4567890123456799' as bigint), + cast('+4567890123456789' as int8), + cast('+4567890123456799' as int8), 0 ); @@ -357,52 +341,52 @@ select * from generate_series( - cast('+4567890123456789' as bigint), - cast('+4567890123456799' as bigint), + cast('+4567890123456789' as int8), + cast('+4567890123456799' as int8), 2 ); -select cast(-cast(1 as bigint) << 63 as text); +select cast(-cast(1 as int8) << 63 as text); -select cast((-cast(1 as bigint) << 63) + 1 as text); +select cast((-cast(1 as int8) << 63) + 1 as text); -select cast(-9223372036854775808 as bigint) * cast(-1 as bigint); +select cast(-9223372036854775808 as int8) * cast(-1 as int8); -select cast(-9223372036854775808 as bigint) / cast(-1 as bigint); +select cast(-9223372036854775808 as int8) / cast(-1 as int8); -select cast(-9223372036854775808 as bigint) % cast(-1 as bigint); +select cast(-9223372036854775808 as int8) % cast(-1 as int8); -select cast(-9223372036854775808 as bigint) * cast(-1 as int); +select cast(-9223372036854775808 as int8) * cast(-1 as int4); -select cast(-9223372036854775808 as bigint) / cast(-1 as int); +select cast(-9223372036854775808 as int8) / cast(-1 as int4); -select cast(-9223372036854775808 as bigint) % cast(-1 as int); +select cast(-9223372036854775808 as int8) % cast(-1 as int4); -select cast(-9223372036854775808 as bigint) * cast(-1 as smallint); +select cast(-9223372036854775808 as int8) * cast(-1 as int2); -select cast(-9223372036854775808 as bigint) / cast(-1 as smallint); +select cast(-9223372036854775808 as int8) / cast(-1 as int2); -select cast(-9223372036854775808 as bigint) % cast(-1 as smallint); +select cast(-9223372036854775808 as int8) % cast(-1 as int2); select x, - cast(x as bigint) as int8_value + cast(x as int8) as int8_value from ( values - (-cast(2.5 as double precision)), - (-cast(1.5 as double precision)), - (-cast(0.5 as double precision)), - (cast(0.0 as double precision)), - (cast(0.5 as double precision)), - (cast(1.5 as double precision)), - (cast(2.5 as double precision)) + (-cast(2.5 as float8)), + (-cast(1.5 as float8)), + (-cast(0.5 as float8)), + (cast(0.0 as float8)), + (cast(0.5 as float8)), + (cast(1.5 as float8)), + (cast(2.5 as float8)) ) as t (x); select x, - cast(x as bigint) as int8_value + cast(x as int8) as int8_value from ( values @@ -426,41 +410,20 @@ select from ( values - (cast(0 as bigint), cast(0 as bigint)), - ( - cast(0 as bigint), - cast(29893644334 as bigint) - ), - ( - cast(288484263558 as bigint), - cast(29893644334 as bigint) - ), - ( - -cast(288484263558 as bigint), - cast(29893644334 as bigint) - ), - ( - cast(-9223372036854775808 as bigint), - cast(1 as bigint) - ), - ( - cast(-9223372036854775808 as bigint), - cast(9223372036854775807 as bigint) - ), - ( - cast(-9223372036854775808 as bigint), - cast(4611686018427387904 as bigint) - ) + (cast(0 as int8), cast(0 as int8)), + (cast(0 as int8), cast(29893644334 as int8)), + (cast(288484263558 as int8), cast(29893644334 as int8)), + (-cast(288484263558 as int8), cast(29893644334 as int8)), + (cast(-9223372036854775808 as int8), cast(1 as int8)), + (cast(-9223372036854775808 as int8), cast(9223372036854775807 as int8)), + (cast(-9223372036854775808 as int8), cast(4611686018427387904 as int8)) ) as v (a, b); -select gcd(cast(-9223372036854775808 as bigint), cast(0 as bigint)); +select gcd(cast(-9223372036854775808 as int8), cast(0 as int8)); select - gcd( - cast(-9223372036854775808 as bigint), - cast(-9223372036854775808 as bigint) - ); + gcd(cast(-9223372036854775808 as int8), cast(-9223372036854775808 as int8)); select a, @@ -472,94 +435,76 @@ select from ( values - (cast(0 as bigint), cast(0 as bigint)), - ( - cast(0 as bigint), - cast(29893644334 as bigint) - ), - ( - cast(29893644334 as bigint), - cast(29893644334 as bigint) - ), - ( - cast(288484263558 as bigint), - cast(29893644334 as bigint) - ), - ( - -cast(288484263558 as bigint), - cast(29893644334 as bigint) - ), - ( - cast(-9223372036854775808 as bigint), - cast(0 as bigint) - ) + (cast(0 as int8), cast(0 as int8)), + (cast(0 as int8), cast(29893644334 as int8)), + (cast(29893644334 as int8), cast(29893644334 as int8)), + (cast(288484263558 as int8), cast(29893644334 as int8)), + (-cast(288484263558 as int8), cast(29893644334 as int8)), + (cast(-9223372036854775808 as int8), cast(0 as int8)) ) as v (a, b); -select lcm(cast(-9223372036854775808 as bigint), cast(1 as bigint)); +select lcm(cast(-9223372036854775808 as int8), cast(1 as int8)); select - lcm( - cast(9223372036854775807 as bigint), - cast(9223372036854775806 as bigint) - ); + lcm(cast(9223372036854775807 as int8), cast(9223372036854775806 as int8)); -select cast('0b100101' as bigint); +select cast('0b100101' as int8); -select cast('0o273' as bigint); +select cast('0o273' as int8); -select cast('0x42F' as bigint); +select cast('0x42F' as int8); -select cast('0b' as bigint); +select cast('0b' as int8); -select cast('0o' as bigint); +select cast('0o' as int8); -select cast('0x' as bigint); +select cast('0x' as int8); select cast('0b111111111111111111111111111111111111111111111111111111111111111' - as bigint); + as int8); select cast('0b1000000000000000000000000000000000000000000000000000000000000000' - as bigint); + as int8); -select cast('0o777777777777777777777' as bigint); +select cast('0o777777777777777777777' as int8); -select cast('0o1000000000000000000000' as bigint); +select cast('0o1000000000000000000000' as int8); -select cast('0x7FFFFFFFFFFFFFFF' as bigint); +select cast('0x7FFFFFFFFFFFFFFF' as int8); -select cast('0x8000000000000000' as bigint); +select cast('0x8000000000000000' as int8); select cast('-0b1000000000000000000000000000000000000000000000000000000000000000' - as bigint); + as int8); select cast('-0b1000000000000000000000000000000000000000000000000000000000000001' - as bigint); + as int8); -select cast('-0o1000000000000000000000' as bigint); +select cast('-0o1000000000000000000000' as int8); -select cast('-0o1000000000000000000001' as bigint); +select cast('-0o1000000000000000000001' as int8); -select cast('-0x8000000000000000' as bigint); +select cast('-0x8000000000000000' as int8); -select cast('-0x8000000000000001' as bigint); +select cast('-0x8000000000000001' as int8); -select cast('1_000_000' as bigint); +select cast('1_000_000' as int8); -select cast('1_2_3' as bigint); +select cast('1_2_3' as int8); -select cast('0x1EEE_FFFF' as bigint); +select cast('0x1EEE_FFFF' as int8); -select cast('0o2_73' as bigint); +select cast('0o2_73' as int8); -select cast('0b_10_0101' as bigint); +select cast('0b_10_0101' as int8); -select cast('_100' as bigint); +select cast('_100' as int8); -select cast('100_' as bigint); +select cast('100_' as int8); -select cast('100__000' as bigint); +select cast('100__000' as int8); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__interval_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__interval_100.snap index 303cb7081..132187212 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__interval_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__interval_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/interval.sql --- -set datestyle = ISO; +set datestyle = 'ISO'; set intervalstyle = postgres; @@ -125,9 +125,7 @@ insert into interval_tbl_of (f1) values ('2147483647 years'); insert into interval_tbl_of (f1) values ('-2147483648 years'); -select - EXTRACT('epoch' from cast('256 microseconds' as interval) * - cast(2 ^ 55 as double precision)); +select extract(epoch from cast('256 microseconds' as interval) * cast(2 ^ 55 as float8)); select r1.*, @@ -184,7 +182,7 @@ select cast('1 month 2146410 days' as interval) * 1000.5002; select cast('4611686018427387904 usec' as interval) / 0.1; -select AVG(f1) from interval_tbl where isfinite(f1); +select avg(f1) from interval_tbl where isfinite(f1); select cast('4 millenniums 5 centuries 4 decades 1 year 4 months 4 days 17 minutes 31 seconds' @@ -193,17 +191,11 @@ select select cast('100000000y 10mon -1000000000d -100000h -10min -10.000001s ago' as interval); select - justify_hours( - cast('6 months 3 days 52 hours 3 minutes 2 seconds' - as interval) - ) + justify_hours(cast('6 months 3 days 52 hours 3 minutes 2 seconds' as interval)) as "6 mons 5 days 4 hours 3 mins 2 seconds"; select - justify_days( - cast('6 months 36 days 5 hours 4 minutes 3 seconds' - as interval) - ) + justify_days(cast('6 months 36 days 5 hours 4 minutes 3 seconds' as interval)) as "7 mons 6 days 5 hours 4 mins 3 seconds"; select justify_hours(cast('2147483647 days 24 hrs' as interval)); @@ -228,15 +220,14 @@ select justify_interval(cast('2147483647 months -30 days 1440 hrs' as interval)) select justify_interval(cast('-2147483648 months 30 days -1440 hrs' as interval)); -set datestyle = ISO; +set datestyle = 'ISO'; set intervalstyle = postgres; select cast('1 millisecond' as interval), cast('1 microsecond' as interval), - cast('500 seconds 99 milliseconds 51 microseconds' - as interval); + cast('500 seconds 99 milliseconds 51 microseconds' as interval); select cast('3 days 5 milliseconds' as interval); @@ -367,10 +358,7 @@ select cast('-2562047788:00:54.775807' as interval second(2)); select f1, cast(f1 as interval day to minute) as minutes, - cast(cast(f1 + cast('1 month' as interval) - as interval month) - as interval year) - as years + cast(cast(f1 + cast('1 month' as interval) as interval month) as interval year) as years from interval_tbl; @@ -378,13 +366,10 @@ set intervalstyle = sql_standard; select cast('0' as interval) as zero, - cast('1-2' as interval year to month) - as "year-month", - cast('1 2:03:04' as interval day to second) - as "day-time", + cast('1-2' as interval year to month) as "year-month", + cast('1 2:03:04' as interval day to second) as "day-time", -cast('1-2' as interval) as "negative year-month", - -cast('1 2:03:04' as interval) - as "negative day-time"; + -cast('1 2:03:04' as interval) as "negative day-time"; set intervalstyle = postgres; @@ -396,31 +381,23 @@ select select cast('-23 hours 45 min 12.34 sec' as interval), - cast('-1 day 23 hours 45 min 12.34 sec' - as interval), - cast('-1 year 2 months 1 day 23 hours 45 min 12.34 sec' - as interval), - cast('-1 year 2 months 1 day 23 hours 45 min +12.34 sec' - as interval); + cast('-1 day 23 hours 45 min 12.34 sec' as interval), + cast('-1 year 2 months 1 day 23 hours 45 min 12.34 sec' as interval), + cast('-1 year 2 months 1 day 23 hours 45 min +12.34 sec' as interval); set intervalstyle = sql_standard; select cast('1 day -1 hours' as interval), cast('-1 days +1 hours' as interval), - cast('1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds' - as interval), - -cast('1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds' - as interval); + cast('1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds' as interval), + -cast('1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds' as interval); select cast('-23 hours 45 min 12.34 sec' as interval), - cast('-1 day 23 hours 45 min 12.34 sec' - as interval), - cast('-1 year 2 months 1 day 23 hours 45 min 12.34 sec' - as interval), - cast('-1 year 2 months 1 day 23 hours 45 min +12.34 sec' - as interval); + cast('-1 day 23 hours 45 min 12.34 sec' as interval), + cast('-1 year 2 months 1 day 23 hours 45 min 12.34 sec' as interval), + cast('-1 year 2 months 1 day 23 hours 45 min +12.34 sec' as interval); select cast('' as interval); @@ -429,19 +406,11 @@ set intervalstyle = iso_8601; select cast('0' as interval) as zero, cast('1-2' as interval) as "a year 2 months", - cast('1 2:03:04' as interval) - as "a bit over a day", - cast('2:03:04.45679' as interval) - as "a bit over 2 hours", - cast('1-2' as interval) + - cast('3 4:05:06.7' as interval) - as "all fields", - cast('1-2' as interval) - - cast('3 4:05:06.7' as interval) - as "mixed sign", - -cast('1-2' as interval) + - cast('3 4:05:06.7' as interval) - as negative; + cast('1 2:03:04' as interval) as "a bit over a day", + cast('2:03:04.45679' as interval) as "a bit over 2 hours", + cast('1-2' as interval) + cast('3 4:05:06.7' as interval) as "all fields", + cast('1-2' as interval) - cast('3 4:05:06.7' as interval) as "mixed sign", + -cast('1-2' as interval) + cast('3 4:05:06.7' as interval) as negative; set intervalstyle = sql_standard; @@ -449,33 +418,24 @@ select cast('P0Y' as interval) as zero, cast('P1Y2M' as interval) as "a year 2 months", cast('P1W' as interval) as "a week", - cast('P1DT2H3M4S' as interval) - as "a bit over a day", - cast('P1Y2M3DT4H5M6.7S' as interval) - as "all fields", - cast('P-1Y-2M-3DT-4H-5M-6.7S' as interval) - as negative, + cast('P1DT2H3M4S' as interval) as "a bit over a day", + cast('P1Y2M3DT4H5M6.7S' as interval) as "all fields", + cast('P-1Y-2M-3DT-4H-5M-6.7S' as interval) as negative, cast('PT-0.1S' as interval) as "fractional second"; set intervalstyle = postgres; select - cast('P00021015T103020' as interval) - as "ISO8601 Basic Format", - cast('P0002-10-15T10:30:20' as interval) - as "ISO8601 Extended Format"; + cast('P00021015T103020' as interval) as "ISO8601 Basic Format", + cast('P0002-10-15T10:30:20' as interval) as "ISO8601 Extended Format"; select cast('P0002' as interval) as "year only", cast('P0002-10' as interval) as "year month", - cast('P0002-10-15' as interval) - as "year month day", - cast('P0002T1S' as interval) - as "year only plus time", - cast('P0002-10T1S' as interval) - as "year month plus time", - cast('P0002-10-15T1S' as interval) - as "year month day plus time", + cast('P0002-10-15' as interval) as "year month day", + cast('P0002T1S' as interval) as "year only plus time", + cast('P0002-10T1S' as interval) as "year month plus time", + cast('P0002-10-15T1S' as interval) as "year month day plus time", cast('PT10' as interval) as "hour only", cast('PT10:30' as interval) as "hour minute"; @@ -775,34 +735,33 @@ select cast('-2147483648 days ago' as interval); select cast('-9223372036854775808 microseconds ago' as interval); select - cast('-2147483648 months -2147483648 days -9223372036854775808 microseconds ago' - as interval); + cast('-2147483648 months -2147483648 days -9223372036854775808 microseconds ago' as interval); -select make_interval("years" := 178956971); +select make_interval(years := 178956971); -select make_interval("years" := -178956971); +select make_interval(years := -178956971); -select make_interval("years" := 1, "months" := 2147483647); +select make_interval(years := 1, months := 2147483647); -select make_interval("years" := -1, "months" := -2147483648); +select make_interval(years := -1, months := -2147483648); -select make_interval("weeks" := 306783379); +select make_interval(weeks := 306783379); -select make_interval("weeks" := -306783379); +select make_interval(weeks := -306783379); -select make_interval("weeks" := 1, "days" := 2147483647); +select make_interval(weeks := 1, days := 2147483647); -select make_interval("weeks" := -1, "days" := -2147483648); +select make_interval(weeks := -1, days := -2147483648); -select make_interval("secs" := 1e308); +select make_interval(secs := 1e308); -select make_interval("secs" := 1e18); +select make_interval(secs := 1e18); -select make_interval("secs" := -1e18); +select make_interval(secs := -1e18); -select make_interval("mins" := 1, "secs" := 9223372036800.0); +select make_interval(mins := 1, secs := 9223372036800.0); -select make_interval("mins" := -1, "secs" := -9223372036800.0); +select make_interval(mins := -1, secs := -9223372036800.0); set intervalstyle = postgres; @@ -824,100 +783,85 @@ select cast('30 days' as interval) = cast('1 month' as interval) as t; select interval_hash(cast('30 days' as interval)) = interval_hash(cast('1 month' as interval)) as t; -select make_interval("years" := 2); +select make_interval(years := 2); -select make_interval("years" := 1, "months" := 6); +select make_interval(years := 1, months := 6); -select - make_interval( - "years" := 1, - "months" := -1, - "weeks" := 5, - "days" := -7, - "hours" := 25, - "mins" := -180 - ); +select make_interval(years := 1, months := -1, weeks := 5, days := -7, hours := 25, mins := -180); select make_interval() = - make_interval( - "years" := 0, - "months" := 0, - "weeks" := 0, - "days" := 0, - "mins" := 0, - "secs" := 0.0 - ); + make_interval(years := 0, months := 0, weeks := 0, days := 0, mins := 0, secs := 0.0); -select make_interval("hours" := -2, "mins" := -10, "secs" := -25.3); +select make_interval(hours := -2, mins := -10, secs := -25.3); -select make_interval("years" := cast(cast('inf' as double precision) as int)); +select make_interval(years := cast(cast('inf' as double precision) as int)); -select make_interval("months" := cast(cast('NaN' as double precision) as int)); +select make_interval(months := cast(cast('NaN' as double precision) as int)); -select make_interval("secs" := 'inf'); +select make_interval(secs := 'inf'); -select make_interval("secs" := 'NaN'); +select make_interval(secs := 'NaN'); -select make_interval("secs" := 7e12); +select make_interval(secs := 7e12); select f1, - EXTRACT('microsecond' from f1) as microsecond, - EXTRACT('millisecond' from f1) as millisecond, - EXTRACT('second' from f1) as second, - EXTRACT('minute' from f1) as minute, - EXTRACT('hour' from f1) as hour, - EXTRACT('day' from f1) as day, - EXTRACT('week' from f1) as week, - EXTRACT('month' from f1) as month, - EXTRACT('quarter' from f1) as quarter, - EXTRACT('year' from f1) as year, - EXTRACT('decade' from f1) as decade, - EXTRACT('century' from f1) as century, - EXTRACT('millennium' from f1) as millennium, - EXTRACT('epoch' from f1) as epoch + extract(microsecond from f1) as microsecond, + extract(millisecond from f1) as millisecond, + extract(second from f1) as second, + extract(minute from f1) as minute, + extract(hour from f1) as hour, + extract(day from f1) as day, + extract(week from f1) as week, + extract(month from f1) as month, + extract(quarter from f1) as quarter, + extract(year from f1) as year, + extract(decade from f1) as decade, + extract(century from f1) as century, + extract(millennium from f1) as millennium, + extract(epoch from f1) as epoch from interval_tbl; select -f1, - EXTRACT('microsecond' from -f1) as microsecond, - EXTRACT('millisecond' from -f1) as millisecond, - EXTRACT('second' from -f1) as second, - EXTRACT('minute' from -f1) as minute, - EXTRACT('hour' from -f1) as hour, - EXTRACT('day' from -f1) as day, - EXTRACT('week' from -f1) as week, - EXTRACT('month' from -f1) as month, - EXTRACT('quarter' from -f1) as quarter, - EXTRACT('year' from -f1) as year, - EXTRACT('decade' from -f1) as decade, - EXTRACT('century' from -f1) as century, - EXTRACT('millennium' from -f1) as millennium, - EXTRACT('epoch' from -f1) as epoch + extract(microsecond from -f1) as microsecond, + extract(millisecond from -f1) as millisecond, + extract(second from -f1) as second, + extract(minute from -f1) as minute, + extract(hour from -f1) as hour, + extract(day from -f1) as day, + extract(week from -f1) as week, + extract(month from -f1) as month, + extract(quarter from -f1) as quarter, + extract(year from -f1) as year, + extract(decade from -f1) as decade, + extract(century from -f1) as century, + extract(millennium from -f1) as millennium, + extract(epoch from -f1) as epoch from interval_tbl; -select EXTRACT('fortnight' from cast('2 days' as interval)); +select extract(fortnight from cast('2 days' as interval)); -select EXTRACT('timezone' from cast('2 days' as interval)); +select extract(timezone from cast('2 days' as interval)); -select EXTRACT('decade' from cast('100 y' as interval)); +select extract(decade from cast('100 y' as interval)); -select EXTRACT('decade' from cast('99 y' as interval)); +select extract(decade from cast('99 y' as interval)); -select EXTRACT('decade' from cast('-99 y' as interval)); +select extract(decade from cast('-99 y' as interval)); -select EXTRACT('decade' from cast('-100 y' as interval)); +select extract(decade from cast('-100 y' as interval)); -select EXTRACT('century' from cast('100 y' as interval)); +select extract(century from cast('100 y' as interval)); -select EXTRACT('century' from cast('99 y' as interval)); +select extract(century from cast('99 y' as interval)); -select EXTRACT('century' from cast('-99 y' as interval)); +select extract(century from cast('-99 y' as interval)); -select EXTRACT('century' from cast('-100 y' as interval)); +select extract(century from cast('-100 y' as interval)); select f1, @@ -928,7 +872,7 @@ select from interval_tbl; -select EXTRACT('epoch' from cast('1000000000 days' as interval)); +select extract(epoch from cast('1000000000 days' as interval)); select cast('-2147483648 months -2147483648 days -9223372036854775807 us' as interval); @@ -947,7 +891,7 @@ select i, isfinite(i) from infinite_interval_tbl; create function eval(expr text) returns text language plpgsql -as $function$ +as $$ DECLARE result text; BEGIN @@ -956,37 +900,25 @@ BEGIN EXCEPTION WHEN OTHERS THEN RETURN SQLERRM; END -$function$; +$$; select d as date, i as interval, - eval(format('date %L + interval %L', d, i)) - as plus, - eval(format('date %L - interval %L', d, i)) - as minus + eval(format('date %L + interval %L', d, i)) as plus, + eval(format('date %L - interval %L', d, i)) as minus from ( - values - (cast('-infinity' as date)), - (cast('1995-08-06' as date)), - (cast('infinity' as date)) + values (cast('-infinity' as date)), (cast('1995-08-06' as date)), (cast('infinity' as date)) ) as t1 (d), - ( - values - (cast('-infinity' as interval)), - (cast('infinity' as interval)) - ) - as t2 (i); + (values (cast('-infinity' as interval)), (cast('infinity' as interval))) as t2 (i); select i1 as interval1, i2 as interval2, - eval(format('interval %L + interval %L', i1, i2)) - as plus, - eval(format('interval %L - interval %L', i1, i2)) - as minus + eval(format('interval %L + interval %L', i1, i2)) as plus, + eval(format('interval %L - interval %L', i1, i2)) as minus from ( values @@ -1004,32 +936,26 @@ from as t2 (i2); select - cast('2147483646 months 2147483646 days 9223372036854775806 us' - as interval) + + cast('2147483646 months 2147483646 days 9223372036854775806 us' as interval) + cast('1 month 1 day 1 us' as interval); select - cast('-2147483647 months -2147483647 days -9223372036854775807 us' - as interval) + + cast('-2147483647 months -2147483647 days -9223372036854775807 us' as interval) + cast('-1 month -1 day -1 us' as interval); select - cast('2147483646 months 2147483646 days 9223372036854775806 us' - as interval) - + cast('2147483646 months 2147483646 days 9223372036854775806 us' as interval) - cast('-1 month -1 day -1 us' as interval); select - cast('-2147483647 months -2147483647 days -9223372036854775807 us' - as interval) - + cast('-2147483647 months -2147483647 days -9223372036854775807 us' as interval) - cast('1 month 1 day 1 us' as interval); select t as timestamp, i as interval, - eval(format('timestamp %L + interval %L', t, i)) - as plus, - eval(format('timestamp %L - interval %L', t, i)) - as minus + eval(format('timestamp %L + interval %L', t, i)) as plus, + eval(format('timestamp %L - interval %L', t, i)) as minus from ( values @@ -1038,37 +964,22 @@ from (cast('infinity' as timestamp)) ) as t1 (t), - ( - values - (cast('-infinity' as interval)), - (cast('infinity' as interval)) - ) - as t2 (i); + (values (cast('-infinity' as interval)), (cast('infinity' as interval))) as t2 (i); select - timezone('GMT', t) as timestamptz, + (t at time zone 'GMT') as timestamptz, i as interval, - eval(format('timestamptz %L + interval %L', t, i)) - as plus, - eval(format('timestamptz %L - interval %L', t, i)) - as minus + eval(format('timestamptz %L + interval %L', t, i)) as plus, + eval(format('timestamptz %L - interval %L', t, i)) as minus from ( values - (cast('-infinity' as timestamp with time zone)), - ( - cast('1995-08-06 12:30:15 GMT' - as timestamp with time zone) - ), - (cast('infinity' as timestamp with time zone)) + (cast('-infinity' as timestamptz)), + (cast('1995-08-06 12:30:15 GMT' as timestamptz)), + (cast('infinity' as timestamptz)) ) as t1 (t), - ( - values - (cast('-infinity' as interval)), - (cast('infinity' as interval)) - ) - as t2 (i); + (values (cast('-infinity' as interval)), (cast('infinity' as interval))) as t2 (i); select cast('11:27:42' as time) + cast('infinity' as interval); @@ -1078,13 +989,13 @@ select cast('11:27:42' as time) - cast('infinity' as interval); select cast('11:27:42' as time) - cast('-infinity' as interval); -select cast('11:27:42' as time with time zone) + cast('infinity' as interval); +select cast('11:27:42' as timetz) + cast('infinity' as interval); -select cast('11:27:42' as time with time zone) + cast('-infinity' as interval); +select cast('11:27:42' as timetz) + cast('-infinity' as interval); -select cast('11:27:42' as time with time zone) - cast('infinity' as interval); +select cast('11:27:42' as timetz) - cast('infinity' as interval); -select cast('11:27:42' as time with time zone) - cast('-infinity' as interval); +select cast('11:27:42' as timetz) - cast('-infinity' as interval); select lhst.i as lhs, @@ -1096,10 +1007,7 @@ select lhst.i >= rhst.i as ge, lhst.i <> rhst.i as ne from - infinite_interval_tbl as lhst - inner join - infinite_interval_tbl as rhst - on true + infinite_interval_tbl as lhst inner join infinite_interval_tbl as rhst on true where not isfinite(lhst.i); @@ -1185,27 +1093,17 @@ select timezone(cast('infinity' as interval), cast('1995-08-06 12:12:12' as time select timezone(cast('-infinity' as interval), cast('1995-08-06 12:12:12' as timestamp)); -select - timezone( - cast('infinity' as interval), - cast('1995-08-06 12:12:12' - as timestamp with time zone) - ); +select timezone(cast('infinity' as interval), cast('1995-08-06 12:12:12' as timestamptz)); -select - timezone( - cast('-infinity' as interval), - cast('1995-08-06 12:12:12' - as timestamp with time zone) - ); +select timezone(cast('-infinity' as interval), cast('1995-08-06 12:12:12' as timestamptz)); select timezone(cast('infinity' as interval), cast('12:12:12' as time)); select timezone(cast('-infinity' as interval), cast('12:12:12' as time)); -select timezone(cast('infinity' as interval), cast('12:12:12' as time with time zone)); +select timezone(cast('infinity' as interval), cast('12:12:12' as timetz)); -select timezone(cast('-infinity' as interval), cast('12:12:12' as time with time zone)); +select timezone(cast('-infinity' as interval), cast('12:12:12' as timetz)); select cast(cast('infinity' as interval) as time); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__interval_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__interval_80.snap index 77e67157b..226275e74 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__interval_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__interval_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/interval.sql --- -set datestyle = ISO; +set datestyle = 'ISO'; set intervalstyle = postgres; @@ -73,16 +73,14 @@ select from interval_tbl where - interval_tbl.f1 <> - cast('@ 10 days' as interval); + interval_tbl.f1 <> cast('@ 10 days' as interval); select * from interval_tbl where - interval_tbl.f1 <= - cast('@ 5 hours' as interval); + interval_tbl.f1 <= cast('@ 5 hours' as interval); select * from interval_tbl where interval_tbl.f1 < cast('@ 1 day' as interval); @@ -91,24 +89,21 @@ select from interval_tbl where - interval_tbl.f1 = - cast('@ 34 years' as interval); + interval_tbl.f1 = cast('@ 34 years' as interval); select * from interval_tbl where - interval_tbl.f1 >= - cast('@ 1 month' as interval); + interval_tbl.f1 >= cast('@ 1 month' as interval); select * from interval_tbl where - interval_tbl.f1 > - cast('@ 3 seconds ago' as interval); + interval_tbl.f1 > cast('@ 3 seconds ago' as interval); select r1.*, @@ -158,8 +153,8 @@ insert into interval_tbl_of (f1) values ('2147483647 years'); insert into interval_tbl_of (f1) values ('-2147483648 years'); select - EXTRACT('epoch' from cast('256 microseconds' as interval) * - cast(2 ^ 55 as double precision)); + extract(epoch from cast('256 microseconds' as interval) * + cast(2 ^ 55 as float8)); select r1.*, @@ -216,7 +211,7 @@ select cast('1 month 2146410 days' as interval) * 1000.5002; select cast('4611686018427387904 usec' as interval) / 0.1; -select AVG(f1) from interval_tbl where isfinite(f1); +select avg(f1) from interval_tbl where isfinite(f1); select cast('4 millenniums 5 centuries 4 decades 1 year 4 months 4 days 17 minutes 31 seconds' @@ -228,16 +223,12 @@ select select justify_hours( - cast('6 months 3 days 52 hours 3 minutes 2 seconds' - as interval) + cast('6 months 3 days 52 hours 3 minutes 2 seconds' as interval) ) as "6 mons 5 days 4 hours 3 mins 2 seconds"; select - justify_days( - cast('6 months 36 days 5 hours 4 minutes 3 seconds' - as interval) - ) + justify_days(cast('6 months 36 days 5 hours 4 minutes 3 seconds' as interval)) as "7 mons 6 days 5 hours 4 mins 3 seconds"; select justify_hours(cast('2147483647 days 24 hrs' as interval)); @@ -245,10 +236,7 @@ select justify_hours(cast('2147483647 days 24 hrs' as interval)); select justify_days(cast('2147483647 months 30 days' as interval)); select - justify_interval( - cast('1 month -1 hour' as interval) - ) - as "1 month -1 hour"; + justify_interval(cast('1 month -1 hour' as interval)) as "1 month -1 hour"; select justify_interval(cast('2147483647 days 24 hrs' as interval)); @@ -263,26 +251,19 @@ select justify_interval(cast('2147483647 months 30 days -24 hrs' as interval)); select justify_interval(cast('-2147483648 months -30 days 24 hrs' as interval)); select - justify_interval( - cast('2147483647 months -30 days 1440 hrs' - as interval) - ); + justify_interval(cast('2147483647 months -30 days 1440 hrs' as interval)); select - justify_interval( - cast('-2147483648 months 30 days -1440 hrs' - as interval) - ); + justify_interval(cast('-2147483648 months 30 days -1440 hrs' as interval)); -set datestyle = ISO; +set datestyle = 'ISO'; set intervalstyle = postgres; select cast('1 millisecond' as interval), cast('1 microsecond' as interval), - cast('500 seconds 99 milliseconds 51 microseconds' - as interval); + cast('500 seconds 99 milliseconds 51 microseconds' as interval); select cast('3 days 5 milliseconds' as interval); @@ -412,10 +393,8 @@ select cast('-2562047788:00:54.775807' as interval second(2)); select f1, - cast(f1 as interval day to minute) - as minutes, - cast(cast(f1 + cast('1 month' as interval) - as interval month) + cast(f1 as interval day to minute) as minutes, + cast(cast(f1 + cast('1 month' as interval) as interval month) as interval year) as years from @@ -425,15 +404,10 @@ set intervalstyle = sql_standard; select cast('0' as interval) as zero, - cast('1-2' as interval year to month) - as "year-month", - cast('1 2:03:04' - as interval day to second) - as "day-time", - -cast('1-2' as interval) - as "negative year-month", - -cast('1 2:03:04' as interval) - as "negative day-time"; + cast('1-2' as interval year to month) as "year-month", + cast('1 2:03:04' as interval day to second) as "day-time", + -cast('1-2' as interval) as "negative year-month", + -cast('1 2:03:04' as interval) as "negative day-time"; set intervalstyle = postgres; @@ -444,34 +418,24 @@ select cast('-1-2 +3 -4:05:06.789' as interval); select - cast('-23 hours 45 min 12.34 sec' - as interval), - cast('-1 day 23 hours 45 min 12.34 sec' - as interval), - cast('-1 year 2 months 1 day 23 hours 45 min 12.34 sec' - as interval), - cast('-1 year 2 months 1 day 23 hours 45 min +12.34 sec' - as interval); + cast('-23 hours 45 min 12.34 sec' as interval), + cast('-1 day 23 hours 45 min 12.34 sec' as interval), + cast('-1 year 2 months 1 day 23 hours 45 min 12.34 sec' as interval), + cast('-1 year 2 months 1 day 23 hours 45 min +12.34 sec' as interval); set intervalstyle = sql_standard; select cast('1 day -1 hours' as interval), cast('-1 days +1 hours' as interval), - cast('1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds' - as interval), - -cast('1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds' - as interval); + cast('1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds' as interval), + -cast('1 years 2 months -3 days 4 hours 5 minutes 6.789 seconds' as interval); select - cast('-23 hours 45 min 12.34 sec' - as interval), - cast('-1 day 23 hours 45 min 12.34 sec' - as interval), - cast('-1 year 2 months 1 day 23 hours 45 min 12.34 sec' - as interval), - cast('-1 year 2 months 1 day 23 hours 45 min +12.34 sec' - as interval); + cast('-23 hours 45 min 12.34 sec' as interval), + cast('-1 day 23 hours 45 min 12.34 sec' as interval), + cast('-1 year 2 months 1 day 23 hours 45 min 12.34 sec' as interval), + cast('-1 year 2 months 1 day 23 hours 45 min +12.34 sec' as interval); select cast('' as interval); @@ -479,62 +443,39 @@ set intervalstyle = iso_8601; select cast('0' as interval) as zero, - cast('1-2' as interval) - as "a year 2 months", - cast('1 2:03:04' as interval) - as "a bit over a day", - cast('2:03:04.45679' as interval) - as "a bit over 2 hours", - cast('1-2' as interval) + - cast('3 4:05:06.7' as interval) - as "all fields", - cast('1-2' as interval) - - cast('3 4:05:06.7' as interval) - as "mixed sign", - -cast('1-2' as interval) + - cast('3 4:05:06.7' as interval) - as negative; + cast('1-2' as interval) as "a year 2 months", + cast('1 2:03:04' as interval) as "a bit over a day", + cast('2:03:04.45679' as interval) as "a bit over 2 hours", + cast('1-2' as interval) + cast('3 4:05:06.7' as interval) as "all fields", + cast('1-2' as interval) - cast('3 4:05:06.7' as interval) as "mixed sign", + -cast('1-2' as interval) + cast('3 4:05:06.7' as interval) as negative; set intervalstyle = sql_standard; select cast('P0Y' as interval) as zero, - cast('P1Y2M' as interval) - as "a year 2 months", + cast('P1Y2M' as interval) as "a year 2 months", cast('P1W' as interval) as "a week", - cast('P1DT2H3M4S' as interval) - as "a bit over a day", - cast('P1Y2M3DT4H5M6.7S' as interval) - as "all fields", - cast('P-1Y-2M-3DT-4H-5M-6.7S' - as interval) - as negative, - cast('PT-0.1S' as interval) - as "fractional second"; + cast('P1DT2H3M4S' as interval) as "a bit over a day", + cast('P1Y2M3DT4H5M6.7S' as interval) as "all fields", + cast('P-1Y-2M-3DT-4H-5M-6.7S' as interval) as negative, + cast('PT-0.1S' as interval) as "fractional second"; set intervalstyle = postgres; select - cast('P00021015T103020' as interval) - as "ISO8601 Basic Format", - cast('P0002-10-15T10:30:20' as interval) - as "ISO8601 Extended Format"; + cast('P00021015T103020' as interval) as "ISO8601 Basic Format", + cast('P0002-10-15T10:30:20' as interval) as "ISO8601 Extended Format"; select cast('P0002' as interval) as "year only", - cast('P0002-10' as interval) - as "year month", - cast('P0002-10-15' as interval) - as "year month day", - cast('P0002T1S' as interval) - as "year only plus time", - cast('P0002-10T1S' as interval) - as "year month plus time", - cast('P0002-10-15T1S' as interval) - as "year month day plus time", + cast('P0002-10' as interval) as "year month", + cast('P0002-10-15' as interval) as "year month day", + cast('P0002T1S' as interval) as "year only plus time", + cast('P0002-10T1S' as interval) as "year month plus time", + cast('P0002-10-15T1S' as interval) as "year month day plus time", cast('PT10' as interval) as "hour only", - cast('PT10:30' as interval) - as "hour minute"; + cast('PT10:30' as interval) as "hour minute"; select cast('P1Y0M3DT4H5M6S' as interval); @@ -835,31 +776,31 @@ select cast('-2147483648 months -2147483648 days -9223372036854775808 microseconds ago' as interval); -select make_interval("years" := 178956971); +select make_interval(years := 178956971); -select make_interval("years" := -178956971); +select make_interval(years := -178956971); -select make_interval("years" := 1, "months" := 2147483647); +select make_interval(years := 1, months := 2147483647); -select make_interval("years" := -1, "months" := -2147483648); +select make_interval(years := -1, months := -2147483648); -select make_interval("weeks" := 306783379); +select make_interval(weeks := 306783379); -select make_interval("weeks" := -306783379); +select make_interval(weeks := -306783379); -select make_interval("weeks" := 1, "days" := 2147483647); +select make_interval(weeks := 1, days := 2147483647); -select make_interval("weeks" := -1, "days" := -2147483648); +select make_interval(weeks := -1, days := -2147483648); -select make_interval("secs" := 1e308); +select make_interval(secs := 1e308); -select make_interval("secs" := 1e18); +select make_interval(secs := 1e18); -select make_interval("secs" := -1e18); +select make_interval(secs := -1e18); -select make_interval("mins" := 1, "secs" := 9223372036800.0); +select make_interval(mins := 1, secs := 9223372036800.0); -select make_interval("mins" := -1, "secs" := -9223372036800.0); +select make_interval(mins := -1, secs := -9223372036800.0); set intervalstyle = postgres; @@ -888,158 +829,141 @@ select select cast('30 days' as interval) = cast('1 month' as interval) as t; select - interval_hash( - cast('30 days' as interval) - ) = - interval_hash( - cast('1 month' as interval) - ) + interval_hash(cast('30 days' as interval)) = + interval_hash(cast('1 month' as interval)) as t; -select make_interval("years" := 2); +select make_interval(years := 2); -select make_interval("years" := 1, "months" := 6); +select make_interval(years := 1, months := 6); select make_interval( - "years" := 1, - "months" := -1, - "weeks" := 5, - "days" := -7, - "hours" := 25, - "mins" := -180 + years := 1, + months := -1, + weeks := 5, + days := -7, + hours := 25, + mins := -180 ); select make_interval() = make_interval( - "years" := 0, - "months" := 0, - "weeks" := 0, - "days" := 0, - "mins" := 0, - "secs" := 0.0 + years := 0, + months := 0, + weeks := 0, + days := 0, + mins := 0, + secs := 0.0 ); -select make_interval("hours" := -2, "mins" := -10, "secs" := -25.3); +select make_interval(hours := -2, mins := -10, secs := -25.3); -select make_interval("years" := cast(cast('inf' as double precision) as int)); +select make_interval(years := cast(cast('inf' as double precision) as int)); -select make_interval("months" := cast(cast('NaN' as double precision) as int)); +select make_interval(months := cast(cast('NaN' as double precision) as int)); -select make_interval("secs" := 'inf'); +select make_interval(secs := 'inf'); -select make_interval("secs" := 'NaN'); +select make_interval(secs := 'NaN'); -select make_interval("secs" := 7e12); +select make_interval(secs := 7e12); select f1, - EXTRACT('microsecond' from f1) - as microsecond, - EXTRACT('millisecond' from f1) - as millisecond, - EXTRACT('second' from f1) as second, - EXTRACT('minute' from f1) as minute, - EXTRACT('hour' from f1) as hour, - EXTRACT('day' from f1) as day, - EXTRACT('week' from f1) as week, - EXTRACT('month' from f1) as month, - EXTRACT('quarter' from f1) as quarter, - EXTRACT('year' from f1) as year, - EXTRACT('decade' from f1) as decade, - EXTRACT('century' from f1) as century, - EXTRACT('millennium' from f1) - as millennium, - EXTRACT('epoch' from f1) as epoch + extract(microsecond from f1) as microsecond, + extract(millisecond from f1) as millisecond, + extract(second from f1) as second, + extract(minute from f1) as minute, + extract(hour from f1) as hour, + extract(day from f1) as day, + extract(week from f1) as week, + extract(month from f1) as month, + extract(quarter from f1) as quarter, + extract(year from f1) as year, + extract(decade from f1) as decade, + extract(century from f1) as century, + extract(millennium from f1) as millennium, + extract(epoch from f1) as epoch from interval_tbl; select -f1, - EXTRACT('microsecond' from -f1) - as microsecond, - EXTRACT('millisecond' from -f1) - as millisecond, - EXTRACT('second' from -f1) as second, - EXTRACT('minute' from -f1) as minute, - EXTRACT('hour' from -f1) as hour, - EXTRACT('day' from -f1) as day, - EXTRACT('week' from -f1) as week, - EXTRACT('month' from -f1) as month, - EXTRACT('quarter' from -f1) as quarter, - EXTRACT('year' from -f1) as year, - EXTRACT('decade' from -f1) as decade, - EXTRACT('century' from -f1) as century, - EXTRACT('millennium' from -f1) - as millennium, - EXTRACT('epoch' from -f1) as epoch + extract(microsecond from -f1) as microsecond, + extract(millisecond from -f1) as millisecond, + extract(second from -f1) as second, + extract(minute from -f1) as minute, + extract(hour from -f1) as hour, + extract(day from -f1) as day, + extract(week from -f1) as week, + extract(month from -f1) as month, + extract(quarter from -f1) as quarter, + extract(year from -f1) as year, + extract(decade from -f1) as decade, + extract(century from -f1) as century, + extract(millennium from -f1) as millennium, + extract(epoch from -f1) as epoch from interval_tbl; -select EXTRACT('fortnight' from cast('2 days' as interval)); +select extract(fortnight from cast('2 days' as interval)); -select EXTRACT('timezone' from cast('2 days' as interval)); +select extract(timezone from cast('2 days' as interval)); -select EXTRACT('decade' from cast('100 y' as interval)); +select extract(decade from cast('100 y' as interval)); -select EXTRACT('decade' from cast('99 y' as interval)); +select extract(decade from cast('99 y' as interval)); -select EXTRACT('decade' from cast('-99 y' as interval)); +select extract(decade from cast('-99 y' as interval)); -select EXTRACT('decade' from cast('-100 y' as interval)); +select extract(decade from cast('-100 y' as interval)); -select EXTRACT('century' from cast('100 y' as interval)); +select extract(century from cast('100 y' as interval)); -select EXTRACT('century' from cast('99 y' as interval)); +select extract(century from cast('99 y' as interval)); -select EXTRACT('century' from cast('-99 y' as interval)); +select extract(century from cast('-99 y' as interval)); -select EXTRACT('century' from cast('-100 y' as interval)); +select extract(century from cast('-100 y' as interval)); select f1, - date_part('microsecond', f1) - as microsecond, - date_part('millisecond', f1) - as millisecond, + date_part('microsecond', f1) as microsecond, + date_part('millisecond', f1) as millisecond, date_part('second', f1) as second, date_part('epoch', f1) as epoch from interval_tbl; -select EXTRACT('epoch' from cast('1000000000 days' as interval)); +select extract(epoch from cast('1000000000 days' as interval)); select cast('-2147483648 months -2147483648 days -9223372036854775807 us' as interval); select - cast('2147483647 months 2147483647 days 9223372036854775806 us' - as interval); + cast('2147483647 months 2147483647 days 9223372036854775806 us' as interval); select cast('-2147483648 months -2147483648 days -9223372036854775808 us' as interval); select - cast('2147483647 months 2147483647 days 9223372036854775807 us' - as interval); + cast('2147483647 months 2147483647 days 9223372036854775807 us' as interval); create table infinite_interval_tbl (i interval); insert into infinite_interval_tbl -values - ('infinity'), - ('-infinity'), - ('1 year 2 days 3 hours'); +values ('infinity'), ('-infinity'), ('1 year 2 days 3 hours'); select i, isfinite(i) from infinite_interval_tbl; create function eval(expr text) returns text language plpgsql -as $function$ +as $$ DECLARE result text; BEGIN @@ -1048,19 +972,13 @@ BEGIN EXCEPTION WHEN OTHERS THEN RETURN SQLERRM; END -$function$; +$$; select d as date, i as interval, - eval( - format('date %L + interval %L', d, i) - ) - as plus, - eval( - format('date %L - interval %L', d, i) - ) - as minus + eval(format('date %L + interval %L', d, i)) as plus, + eval(format('date %L - interval %L', d, i)) as minus from ( values @@ -1070,31 +988,15 @@ from ) as t1 (d), ( - values - (cast('-infinity' as interval)), - (cast('infinity' as interval)) + values (cast('-infinity' as interval)), (cast('infinity' as interval)) ) as t2 (i); select i1 as interval1, i2 as interval2, - eval( - format( - 'interval %L + interval %L', - i1, - i2 - ) - ) - as plus, - eval( - format( - 'interval %L - interval %L', - i1, - i2 - ) - ) - as minus + eval(format('interval %L + interval %L', i1, i2)) as plus, + eval(format('interval %L - interval %L', i1, i2)) as minus from ( values @@ -1112,21 +1014,17 @@ from as t2 (i2); select - cast('2147483646 months 2147483646 days 9223372036854775806 us' - as interval) + + cast('2147483646 months 2147483646 days 9223372036854775806 us' as interval) + cast('1 month 1 day 1 us' as interval); select cast('-2147483647 months -2147483647 days -9223372036854775807 us' as interval) + - cast('-1 month -1 day -1 us' - as interval); + cast('-1 month -1 day -1 us' as interval); select - cast('2147483646 months 2147483646 days 9223372036854775806 us' - as interval) - - cast('-1 month -1 day -1 us' - as interval); + cast('2147483646 months 2147483646 days 9223372036854775806 us' as interval) - + cast('-1 month -1 day -1 us' as interval); select cast('-2147483647 months -2147483647 days -9223372036854775807 us' @@ -1136,79 +1034,36 @@ select select t as timestamp, i as interval, - eval( - format( - 'timestamp %L + interval %L', - t, - i - ) - ) - as plus, - eval( - format( - 'timestamp %L - interval %L', - t, - i - ) - ) - as minus + eval(format('timestamp %L + interval %L', t, i)) as plus, + eval(format('timestamp %L - interval %L', t, i)) as minus from ( values (cast('-infinity' as timestamp)), - ( - cast('1995-08-06 12:30:15' as timestamp) - ), + (cast('1995-08-06 12:30:15' as timestamp)), (cast('infinity' as timestamp)) ) as t1 (t), ( - values - (cast('-infinity' as interval)), - (cast('infinity' as interval)) + values (cast('-infinity' as interval)), (cast('infinity' as interval)) ) as t2 (i); select - timezone('GMT', t) as timestamptz, + (t at time zone 'GMT') as timestamptz, i as interval, - eval( - format( - 'timestamptz %L + interval %L', - t, - i - ) - ) - as plus, - eval( - format( - 'timestamptz %L - interval %L', - t, - i - ) - ) - as minus + eval(format('timestamptz %L + interval %L', t, i)) as plus, + eval(format('timestamptz %L - interval %L', t, i)) as minus from ( values - ( - cast('-infinity' - as timestamp with time zone) - ), - ( - cast('1995-08-06 12:30:15 GMT' - as timestamp with time zone) - ), - ( - cast('infinity' - as timestamp with time zone) - ) + (cast('-infinity' as timestamptz)), + (cast('1995-08-06 12:30:15 GMT' as timestamptz)), + (cast('infinity' as timestamptz)) ) as t1 (t), ( - values - (cast('-infinity' as interval)), - (cast('infinity' as interval)) + values (cast('-infinity' as interval)), (cast('infinity' as interval)) ) as t2 (i); @@ -1220,13 +1075,13 @@ select cast('11:27:42' as time) - cast('infinity' as interval); select cast('11:27:42' as time) - cast('-infinity' as interval); -select cast('11:27:42' as time with time zone) + cast('infinity' as interval); +select cast('11:27:42' as timetz) + cast('infinity' as interval); -select cast('11:27:42' as time with time zone) + cast('-infinity' as interval); +select cast('11:27:42' as timetz) + cast('-infinity' as interval); -select cast('11:27:42' as time with time zone) - cast('infinity' as interval); +select cast('11:27:42' as timetz) - cast('infinity' as interval); -select cast('11:27:42' as time with time zone) - cast('-infinity' as interval); +select cast('11:27:42' as timetz) - cast('-infinity' as interval); select lhst.i as lhs, @@ -1238,10 +1093,7 @@ select lhst.i >= rhst.i as ge, lhst.i <> rhst.i as ne from - infinite_interval_tbl as lhst - inner join - infinite_interval_tbl as rhst - on true + infinite_interval_tbl as lhst inner join infinite_interval_tbl as rhst on true where not isfinite(lhst.i); @@ -1364,32 +1216,22 @@ select select timezone( cast('infinity' as interval), - cast('1995-08-06 12:12:12' - as timestamp with time zone) + cast('1995-08-06 12:12:12' as timestamptz) ); select timezone( cast('-infinity' as interval), - cast('1995-08-06 12:12:12' - as timestamp with time zone) + cast('1995-08-06 12:12:12' as timestamptz) ); select timezone(cast('infinity' as interval), cast('12:12:12' as time)); select timezone(cast('-infinity' as interval), cast('12:12:12' as time)); -select - timezone( - cast('infinity' as interval), - cast('12:12:12' as time with time zone) - ); +select timezone(cast('infinity' as interval), cast('12:12:12' as timetz)); -select - timezone( - cast('-infinity' as interval), - cast('12:12:12' as time with time zone) - ); +select timezone(cast('-infinity' as interval), cast('12:12:12' as timetz)); select cast(cast('infinity' as interval) as time); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_100.snap index 715a56d21..49348be8f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_100.snap @@ -77,51 +77,44 @@ select i, k, t from j1_tbl inner join j2_tbl on true; select t1.i, k, t from j1_tbl as t1 inner join j2_tbl as t2 on true; -select ii, tt, kk from (j1_tbl inner join j2_tbl on true) as "tx" ("ii", "jj", "tt", "ii2", "kk"); +select ii, tt, kk from (j1_tbl inner join j2_tbl on true) as tx (ii, jj, tt, ii2, kk); select tx.ii, tx.jj, tx.kk from - (j1_tbl as t1 (a, b, c) - inner join - j2_tbl as t2 (d, e) - on true) as "tx" ("ii", - "jj", - "tt", - "ii2", - "kk"); + (j1_tbl as t1 (a, b, c) inner join j2_tbl as t2 (d, e) on true) as tx (ii, jj, tt, ii2, kk); select * from j1_tbl inner join j2_tbl as a on true inner join j2_tbl as b on true; -select * from j1_tbl inner join j2_tbl using ("i"); +select * from j1_tbl inner join j2_tbl using (i); -select * from j1_tbl inner join j2_tbl using ("i"); +select * from j1_tbl inner join j2_tbl using (i); -select * from j1_tbl as t1 (a, b, c) inner join j2_tbl as t2 (a, d) using ("a") order by a, d; +select * from j1_tbl as t1 (a, b, c) inner join j2_tbl as t2 (a, d) using (a) order by a, d; -select * from j1_tbl as t1 (a, b, c) inner join j2_tbl as t2 (a, b) using ("b") order by b, t1.a; +select * from j1_tbl as t1 (a, b, c) inner join j2_tbl as t2 (a, b) using (b) order by b, t1.a; -select * from j1_tbl inner join j2_tbl using ("i") where j1_tbl.t = 'one'; +select * from j1_tbl inner join j2_tbl using (i) where j1_tbl.t = 'one'; -select * from j1_tbl inner join j2_tbl using ("i") as "x" where j1_tbl.t = 'one'; +select * from j1_tbl inner join j2_tbl using (i) as x where j1_tbl.t = 'one'; -select * from (j1_tbl inner join j2_tbl using ("i")) as "x" where j1_tbl.t = 'one'; +select * from (j1_tbl inner join j2_tbl using (i)) as x where j1_tbl.t = 'one'; -select * from j1_tbl inner join j2_tbl using ("i") as "x" where x.i = 1; +select * from j1_tbl inner join j2_tbl using (i) as x where x.i = 1; -select * from j1_tbl inner join j2_tbl using ("i") as "x" where x.t = 'one'; +select * from j1_tbl inner join j2_tbl using (i) as x where x.t = 'one'; -select * from (j1_tbl inner join j2_tbl using ("i") as "x") as "xx" where x.i = 1; +select * from (j1_tbl inner join j2_tbl using (i) as x) as xx where x.i = 1; -select * from j1_tbl as a1 inner join j2_tbl as a2 using ("i") as "a1"; +select * from j1_tbl as a1 inner join j2_tbl as a2 using (i) as a1; -select x.* from j1_tbl inner join j2_tbl using ("i") as "x" where j1_tbl.t = 'one'; +select x.* from j1_tbl inner join j2_tbl using (i) as x where j1_tbl.t = 'one'; -select row(x.*) from j1_tbl inner join j2_tbl using ("i") as "x" where j1_tbl.t = 'one'; +select row(x.*) from j1_tbl inner join j2_tbl using (i) as x where j1_tbl.t = 'one'; -select row_to_json(x.*) from j1_tbl inner join j2_tbl using ("i") as "x" where j1_tbl.t = 'one'; +select row_to_json(x.*) from j1_tbl inner join j2_tbl using (i) as x where j1_tbl.t = 'one'; select * from j1_tbl natural join j2_tbl; @@ -137,21 +130,21 @@ select * from j1_tbl inner join j2_tbl on j1_tbl.i = j2_tbl.k; select * from j1_tbl inner join j2_tbl on j1_tbl.i <= j2_tbl.k; -select * from j1_tbl left outer join j2_tbl using ("i") order by i, k, t; +select * from j1_tbl left outer join j2_tbl using (i) order by i, k, t; -select * from j1_tbl left outer join j2_tbl using ("i") order by i, k, t; +select * from j1_tbl left outer join j2_tbl using (i) order by i, k, t; -select * from j1_tbl right outer join j2_tbl using ("i"); +select * from j1_tbl right outer join j2_tbl using (i); -select * from j1_tbl right outer join j2_tbl using ("i"); +select * from j1_tbl right outer join j2_tbl using (i); -select * from j1_tbl full outer join j2_tbl using ("i") order by i, k, t; +select * from j1_tbl full outer join j2_tbl using (i) order by i, k, t; -select * from j1_tbl full outer join j2_tbl using ("i") order by i, k, t; +select * from j1_tbl full outer join j2_tbl using (i) order by i, k, t; -select * from j1_tbl left outer join j2_tbl using ("i") where k = 1; +select * from j1_tbl left outer join j2_tbl using (i) where k = 1; -select * from j1_tbl left outer join j2_tbl using ("i") where i = 1; +select * from j1_tbl left outer join j2_tbl using (i) where i = 1; select * @@ -161,13 +154,7 @@ from where exists ( - select - * - from - tenk1 as c - where - b.twothousand = c.twothousand and - b.fivethous <> c.fivethous + select * from tenk1 as c where b.twothousand = c.twothousand and b.fivethous <> c.fivethous ) and a.tenthous = b.tenthous and a.tenthous < 5000; @@ -201,13 +188,13 @@ insert into t3 values ('cc', 23); insert into t3 values ('dd', 33); -select * from t1 full outer join t2 using ("name") full outer join t3 using ("name"); +select * from t1 full outer join t2 using (name) full outer join t3 using (name); -select * from (select * from t2) as s2 inner join (select * from t3) as s3 using ("name"); +select * from (select * from t2) as s2 inner join (select * from t3) as s3 using (name); -select * from (select * from t2) as s2 left outer join (select * from t3) as s3 using ("name"); +select * from (select * from t2) as s2 left outer join (select * from t3) as s3 using (name); -select * from (select * from t2) as s2 full outer join (select * from t3) as s3 using ("name"); +select * from (select * from t2) as s2 full outer join (select * from t3) as s3 using (name); select * @@ -327,98 +314,57 @@ select * from x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 and x2 is not null; + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 and x2 is not null; select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 and y2 is not null; + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 and y2 is not null; select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 and xx2 is not null; + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 and xx2 is not null; select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 where x2 is not null; select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 where y2 is not null; select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 where xx2 is not null; select - COUNT(*) + count(*) from tenk1 as a where unique1 in ( - select - unique1 - from - tenk1 as b inner join tenk1 as c using ("unique1") - where - b.unique2 = 42 + select unique1 from tenk1 as b inner join tenk1 as c using (unique1) where b.unique2 = 42 ); select - COUNT(*) + count(*) from tenk1 as x where - x.unique1 in - ( - select - a.f1 - from - int4_tbl as a, - float8_tbl as b - where - a.f1 = b.f1 - ) and + x.unique1 in (select a.f1 from int4_tbl as a, float8_tbl as b where a.f1 = b.f1) and x.unique1 = 0 and - x.unique1 in - ( - select - aa.f1 - from - int4_tbl as aa, - float8_tbl as bb - where - aa.f1 = bb.f1 - ); + x.unique1 in (select aa.f1 from int4_tbl as aa, float8_tbl as bb where aa.f1 = bb.f1); begin; @@ -427,31 +373,13 @@ set geqo = 'on'; set geqo_threshold = 2; select - COUNT(*) + count(*) from tenk1 as x where - x.unique1 in - ( - select - a.f1 - from - int4_tbl as a, - float8_tbl as b - where - a.f1 = b.f1 - ) and + x.unique1 in (select a.f1 from int4_tbl as a, float8_tbl as b where a.f1 = b.f1) and x.unique1 = 0 and - x.unique1 in - ( - select - aa.f1 - from - int4_tbl as aa, - float8_tbl as bb - where - aa.f1 = bb.f1 - ); + x.unique1 in (select aa.f1 from int4_tbl as aa, float8_tbl as bb where aa.f1 = bb.f1); rollback; @@ -480,10 +408,7 @@ select from int8_tbl as i1 left outer join - int8_tbl as i2 - inner join - (select 123 as x) as ss - on i2.q1 = x + int8_tbl as i2 inner join (select 123 as x) as ss on i2.q1 = x on i1.q2 = i2.q2 order by 1, 2; @@ -493,26 +418,20 @@ select from int8_tbl as i1 left outer join - int8_tbl as i2 - inner join - (select 123 as x) as ss - on i2.q1 = x + int8_tbl as i2 inner join (select 123 as x) as ss on i2.q1 = x on i1.q2 = i2.q2 order by 1, 2; select - COUNT(*) + count(*) from ( select t3.tenthous as x1, coalesce(t1.stringu1, t2.stringu1) as x2 from - tenk1 as t1 - left outer join - tenk1 as t2 - on t1.unique1 = t2.unique1 + tenk1 as t1 left outer join tenk1 as t2 on t1.unique1 = t2.unique1 inner join tenk1 as t3 on t1.unique2 = t3.unique2 @@ -521,9 +440,7 @@ from tenk1 as t4, tenk1 as t5 where - t4.thousand = t5.unique1 and - ss.x1 = t4.tenthous and - ss.x2 = t5.stringu1; + t4.thousand = t5.unique1 and ss.x1 = t4.tenthous and ss.x2 = t5.stringu1; select a.f1, @@ -532,15 +449,10 @@ select t.tenthous from tenk1 as t, - ( - select SUM(f1) + 1 as f1 from int4_tbl as i4a - ) - as a, - (select SUM(f1) as f1 from int4_tbl as i4b) as b + (select sum(f1) + 1 as f1 from int4_tbl as i4a) as a, + (select sum(f1) as f1 from int4_tbl as i4b) as b where - b.f1 = t.thousand and - a.f1 = b.f1 and - a.f1 + b.f1 + 999 = t.tenthous; + b.f1 = t.thousand and a.f1 = b.f1 and a.f1 + b.f1 + 999 = t.tenthous; select a.f1, @@ -549,15 +461,10 @@ select t.tenthous from tenk1 as t, - ( - select SUM(f1) + 1 as f1 from int4_tbl as i4a - ) - as a, - (select SUM(f1) as f1 from int4_tbl as i4b) as b + (select sum(f1) + 1 as f1 from int4_tbl as i4a) as a, + (select sum(f1) as f1 from int4_tbl as i4b) as b where - b.f1 = t.thousand and - a.f1 = b.f1 and - a.f1 + b.f1 + 999 = t.tenthous; + b.f1 = t.thousand and a.f1 = b.f1 and a.f1 + b.f1 + 999 = t.tenthous; select t1.unique1, @@ -566,16 +473,7 @@ from tenk1 as t1 inner join tenk1 as t2 - on t1.two = t2.two and - t1.unique1 = - ( - select - MIN(unique1) - from - tenk1 - where - t2.unique1 = unique1 - ) + on t1.two = t2.two and t1.unique1 = (select min(unique1) from tenk1 where t2.unique1 = unique1) where t1.unique1 < 10 and t2.unique1 < 10 order by t1.unique1; @@ -587,16 +485,7 @@ from tenk1 as t1 inner join tenk1 as t2 - on t1.two = t2.two and - t1.unique1 = - ( - select - MIN(unique1) - from - tenk1 - where - t2.unique1 = unique1 - ) + on t1.two = t2.two and t1.unique1 = (select min(unique1) from tenk1 where t2.unique1 = unique1) where t1.unique1 < 10 and t2.unique1 < 10 order by t1.unique1; @@ -605,10 +494,7 @@ select t1.f1 from int4_tbl as t1, - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t3.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t3.f1 > 0 left outer join int4_tbl as t4 on t3.f1 > 1 @@ -619,10 +505,7 @@ select t1.f1 from int4_tbl as t1, - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t3.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t3.f1 > 0 left outer join int4_tbl as t4 on t3.f1 > 1 @@ -632,13 +515,7 @@ where select * from - int4_tbl as t1 - left outer join - int4_tbl as t2 - on true - left outer join - int4_tbl as t3 - on t2.f1 > 0 + int4_tbl as t1 left outer join int4_tbl as t2 on true left outer join int4_tbl as t3 on t2.f1 > 0 left outer join int4_tbl as t4 on t3.f1 > 0; @@ -646,10 +523,7 @@ from select * from - onek as t1 - left outer join - onek as t2 - on t1.unique1 = t2.unique1 + onek as t1 left outer join onek as t2 on t1.unique1 = t2.unique1 left outer join onek as t3 on t2.unique1 <> t3.unique1 @@ -664,12 +538,9 @@ from left outer join ( select - NOW() + now() from - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t2.f1 = t3.f1 + int4_tbl as t2 left outer join int4_tbl as t3 on t2.f1 = t3.f1 left outer join int4_tbl as t4 on t3.f1 = t4.f1 @@ -683,13 +554,7 @@ from select * from - int4_tbl as t1 - left outer join - int4_tbl as t2 - on true - left outer join - int4_tbl as t3 - on true + int4_tbl as t1 left outer join int4_tbl as t2 on true left outer join int4_tbl as t3 on true left outer join int4_tbl as t4 on t2.f1 = t3.f1; @@ -697,10 +562,7 @@ from select * from - int4_tbl as t1 - left outer join - int4_tbl as t2 - on true + int4_tbl as t1 left outer join int4_tbl as t2 on true left outer join int4_tbl as t3 on t2.f1 = t3.f1 @@ -713,10 +575,7 @@ select from int4_tbl as t1 left outer join - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t2.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t2.f1 > 0 on t2.f1 > 1 left outer join int4_tbl as t4 @@ -733,10 +592,7 @@ from select t2.f1 from - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t2.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t2.f1 > 0 where t3.f1 is null ) @@ -755,10 +611,7 @@ from select t2.f1 from - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t2.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t2.f1 > 0 where t2.f1 <> coalesce(t3.f1, -1) ) @@ -771,30 +624,20 @@ from select * from - onek as t1 - left outer join - onek as t2 - on t1.unique1 = t2.unique1 + onek as t1 left outer join onek as t2 on t1.unique1 = t2.unique1 left outer join onek as t3 on t2.unique1 = t3.unique1 left outer join onek as t4 - on t3.unique1 = t4.unique1 and - t2.unique2 = t4.unique2; + on t3.unique1 = t4.unique1 and t2.unique2 = t4.unique2; select * from int8_tbl as t1 left outer join - int8_tbl as t2 - left outer join - int8_tbl as t3 - full outer join - int8_tbl as t4 - on false - on false + int8_tbl as t2 left outer join int8_tbl as t3 full outer join int8_tbl as t4 on false on false left outer join int8_tbl as t5 on t2.q1 = t5.q1 @@ -803,44 +646,23 @@ from select * from - int8_tbl as t1 - left outer join - int8_tbl as t2 - on true + int8_tbl as t1 left outer join int8_tbl as t2 on true left outer join - lateral ( - select - * - from - int8_tbl as t3 - where - t3.q1 = t2.q1 - offset 0 - ) - as s + lateral (select * from int8_tbl as t3 where t3.q1 = t2.q1 offset 0) as s on t2.q1 = 1; select * from - int8_tbl as t1 - left outer join - int8_tbl as t2 - on true + int8_tbl as t1 left outer join int8_tbl as t2 on true left outer join - lateral ( - select * from generate_series(t2.q1, 100) - ) - as s + lateral (select * from generate_series(t2.q1, 100)) as s on t2.q1 = 1; select * from - int8_tbl as t1 - left outer join - int8_tbl as t2 - on true + int8_tbl as t1 left outer join int8_tbl as t2 on true left outer join lateral (select t2.q1 from int8_tbl as t3) as s on t2.q1 = 1; @@ -850,16 +672,7 @@ select from onek as t1 left outer join onek as t2 on true left outer join - lateral ( - select - * - from - onek as t3 - where - t3.two = t2.two - offset 0 - ) - as s + lateral (select * from onek as t3 where t3.two = t2.two offset 0) as s on t2.unique1 = 1; select @@ -867,15 +680,7 @@ select from j1_tbl full outer join - ( - select - * - from - j2_tbl - order by j2_tbl.i desc, - j2_tbl.k asc - ) - as j2_tbl + (select * from j2_tbl order by j2_tbl.i desc, j2_tbl.k asc) as j2_tbl on j1_tbl.i = j2_tbl.i and j1_tbl.i = j2_tbl.k; select @@ -883,54 +688,24 @@ select from j1_tbl full outer join - ( - select - * - from - j2_tbl - order by j2_tbl.i desc, - j2_tbl.k asc - ) - as j2_tbl + (select * from j2_tbl order by j2_tbl.i desc, j2_tbl.k asc) as j2_tbl on j1_tbl.i = j2_tbl.i and j1_tbl.i = j2_tbl.k; select - COUNT(*) + count(*) from - ( - select - * - from - tenk1 as x - order by x.thousand, - x.twothousand, - x.fivethous - ) - as x + (select * from tenk1 as x order by x.thousand, x.twothousand, x.fivethous) as x left outer join (select * from tenk1 as y order by y.unique2) as y - on x.thousand = y.unique2 and - x.twothousand = y.hundred and - x.fivethous = y.unique2; + on x.thousand = y.unique2 and x.twothousand = y.hundred and x.fivethous = y.unique2; select - COUNT(*) + count(*) from - ( - select - * - from - tenk1 as x - order by x.thousand, - x.twothousand, - x.fivethous - ) - as x + (select * from tenk1 as x order by x.thousand, x.twothousand, x.fivethous) as x left outer join (select * from tenk1 as y order by y.unique2) as y - on x.thousand = y.unique2 and - x.twothousand = y.hundred and - x.fivethous = y.unique2; + on x.thousand = y.unique2 and x.twothousand = y.hundred and x.fivethous = y.unique2; set enable_hashjoin = 0; @@ -941,12 +716,9 @@ set enable_hashagg = 0; select x.thousand, x.twothousand, - COUNT(*) + count(*) from - tenk1 as x - inner join - tenk1 as y - on x.thousand = y.thousand + tenk1 as x inner join tenk1 as y on x.thousand = y.thousand group by x.thousand, x.twothousand order by x.thousand desc, @@ -1005,7 +777,7 @@ delete from t3 using t1 as table1 where t3.x = table1.a; select * from t3; -delete from t3 using t1 inner join t2 using ("a") where t3.x > t1.a; +delete from t3 using t1 inner join t2 using (a) where t3.x > t1.a; select * from t3; @@ -1035,7 +807,7 @@ select foo.*, unnamed_join.* from - t1 inner join t2 using ("a") as "foo", + t1 inner join t2 using (a) as foo, t3 as unnamed_join for update of unnamed_join; @@ -1043,7 +815,7 @@ select foo.*, unnamed_join.* from - t1 inner join t2 using ("a") as "foo", + t1 inner join t2 using (a) as foo, t3 as unnamed_join for update of foo; @@ -1051,7 +823,7 @@ select bar.*, unnamed_join.* from - (t1 inner join t2 using ("a") as "foo") as "bar", + (t1 inner join t2 using (a) as foo) as bar, t3 as unnamed_join for update of foo; @@ -1059,13 +831,13 @@ select bar.*, unnamed_join.* from - (t1 inner join t2 using ("a") as "foo") as "bar", + (t1 inner join t2 using (a) as foo) as bar, t3 as unnamed_join for update of bar; create temporary table tt1 ( - tt1_id int, - joincol int + tt1_id int4, + joincol int4 ); insert into tt1 values (1, 11); @@ -1073,8 +845,8 @@ insert into tt1 values (1, 11); insert into tt1 values (2, null); create temporary table tt2 ( - tt2_id int, - joincol int + tt2_id int4, + joincol int4 ); insert into tt2 values (21, 11); @@ -1113,22 +885,14 @@ select from tbl_ra as t1 where - not exists - ( - select 1 from tbl_ra as t2 where t2.b = t1.a - ) and - t1.b < 2; + not exists (select 1 from tbl_ra as t2 where t2.b = t1.a) and t1.b < 2; select * from tbl_ra as t1 where - not exists - ( - select 1 from tbl_ra as t2 where t2.b = t1.a - ) and - t1.b < 2; + not exists (select 1 from tbl_ra as t2 where t2.b = t1.a) and t1.b < 2; reset enable_hashjoin; @@ -1149,13 +913,7 @@ from tbl_rs as t1 inner join lateral ( - select - * - from - tbl_rs as t2 - where - t2.a in (select t1.a + t3.a from tbl_rs as t3) and - t2.a < 5 + select * from tbl_rs as t2 where t2.a in (select t1.a + t3.a from tbl_rs as t3) and t2.a < 5 ) on true; @@ -1165,13 +923,7 @@ from tbl_rs as t1 inner join lateral ( - select - * - from - tbl_rs as t2 - where - t2.a in (select t1.a + t3.a from tbl_rs as t3) and - t2.a < 5 + select * from tbl_rs as t2 where t2.a in (select t1.a + t3.a from tbl_rs as t3) and t2.a < 5 ) on true; @@ -1181,9 +933,9 @@ set enable_mergejoin = off; set enable_memoize = off; -select COUNT(*) from tenk1 as a, tenk1 as b where a.hundred = b.thousand and b.fivethous % 10 < 10; +select count(*) from tenk1 as a, tenk1 as b where a.hundred = b.thousand and b.fivethous % 10 < 10; -select COUNT(*) from tenk1 as a, tenk1 as b where a.hundred = b.thousand and b.fivethous % 10 < 10; +select count(*) from tenk1 as a, tenk1 as b where a.hundred = b.thousand and b.fivethous % 10 < 10; reset work_mem; @@ -1214,12 +966,7 @@ from tt4 as a left outer join ( - select - b.f1 - from - tt3 as b left outer join tt3 as c on b.f1 = c.f1 - where - coalesce(c.f1, 0) = 0 + select b.f1 from tt3 as b left outer join tt3 as c on b.f1 = c.f1 where coalesce(c.f1, 0) = 0 ) as d on a.f1 = d.f1 @@ -1233,12 +980,7 @@ from tt4 as a left outer join ( - select - b.f1 - from - tt3 as b left outer join tt3 as c on b.f1 = c.f1 - where - coalesce(c.f1, 0) = 0 + select b.f1 from tt3 as b left outer join tt3 as c on b.f1 = c.f1 where coalesce(c.f1, 0) = 0 ) as d on a.f1 = d.f1 @@ -1259,10 +1001,7 @@ select a.* from tenk1 as a where not exists (select 1 from tenk1 as b where a.un select a.* from - tenk1 as a - left outer join - tenk1 as b - on a.unique1 = b.unique2 + tenk1 as a left outer join tenk1 as b on a.unique1 = b.unique2 where b.unique2 is null; @@ -1277,16 +1016,7 @@ select from tenk1 as a where - exists - ( - select - 1 - from - tenk1 as b - where - a.unique1 = b.unique2 - group by b.unique1 - ); + exists (select 1 from tenk1 as b where a.unique1 = b.unique2 group by b.unique1); create temporary table tt4x ( c1 int, @@ -1304,21 +1034,9 @@ where select 1 from - tt4x as t2 + tt4x as t2 left outer join tt4x as t3 on t2.c3 = t3.c1 left outer join - tt4x as t3 - on t2.c3 = t3.c1 - left outer join - ( - select - t5.c1 as c1 - from - tt4x as t4 - left outer join - tt4x as t5 - on t4.c2 = t5.c1 - ) - as a1 + (select t5.c1 as c1 from tt4x as t4 left outer join tt4x as t5 on t4.c2 = t5.c1) as a1 on t3.c2 = a1.c1 where t1.c1 = t2.c2 @@ -1372,10 +1090,7 @@ select xxa.pkxx as xxa_pkxx, xxb.pkxx as xxb_pkxx from - yy - left outer join - (select * from yy where pkyy = 101) as yya - on yy.pkyy = yya.pkyy + yy left outer join (select * from yy where pkyy = 101) as yya on yy.pkyy = yya.pkyy left outer join xx as xxa on yya.pkxx = xxa.pkxx @@ -1407,34 +1122,20 @@ select b.unique2, b.hundred from - tenk1 as a - left outer join - tenk1 as b - on a.unique2 = b.tenthous + tenk1 as a left outer join tenk1 as b on a.unique2 = b.tenthous where - a.unique1 = 42 and - ( - (b.unique2 is null and a.ten = 2) or b.hundred = 3 - ); + a.unique1 = 42 and ((b.unique2 is null and a.ten = 2) or b.hundred = 3); prepare foo -(boolean) +(bool) as select - COUNT(*) + count(*) from tenk1 as a left outer join tenk1 as b on a.unique2 = b.unique1 and - exists - ( - select - 1 - from - tenk1 as c - where - c.thousand = b.unique2 and $1 - );; + exists (select 1 from tenk1 as c where c.thousand = b.unique2 and $1);; execute foo (true); @@ -1479,51 +1180,35 @@ rollback; select t1.q2, - COUNT(t2.*) + count(t2.*) from - int8_tbl as t1 - left outer join - int8_tbl as t2 - on t1.q2 = t2.q1 + int8_tbl as t1 left outer join int8_tbl as t2 on t1.q2 = t2.q1 group by t1.q2 order by 1; select t1.q2, - COUNT(t2.*) + count(t2.*) from - int8_tbl as t1 - left outer join - (select * from int8_tbl) as t2 - on t1.q2 = t2.q1 + int8_tbl as t1 left outer join (select * from int8_tbl) as t2 on t1.q2 = t2.q1 group by t1.q2 order by 1; select t1.q2, - COUNT(t2.*) + count(t2.*) from - int8_tbl as t1 - left outer join - (select * from int8_tbl offset 0) as t2 - on t1.q2 = t2.q1 + int8_tbl as t1 left outer join (select * from int8_tbl offset 0) as t2 on t1.q2 = t2.q1 group by t1.q2 order by 1; select t1.q2, - COUNT(t2.*) + count(t2.*) from int8_tbl as t1 left outer join - ( - select - q1, - case when q2 = 1 then 1 else q2 end as q2 - from - int8_tbl - ) - as t2 + (select q1, case when q2 = 1 then 1 else q2 end as q2 from int8_tbl) as t2 on t1.q2 = t2.q1 group by t1.q2 order by 1; @@ -1532,19 +1217,19 @@ begin; create temporary table a ( code char(1) not null, - constraint "a_pk" primary key (code) + constraint a_pk primary key (code) ); create temporary table b ( a char(1) not null, num int not null, - constraint "b_pk" primary key (a, num) + constraint b_pk primary key (a, num) ); create temporary table c ( name char(1) not null, a char(1), - constraint "c_pk" primary key (name) + constraint c_pk primary key (name) ); insert into a (code) values ('p'); @@ -1577,10 +1262,7 @@ from from a left outer join - ( - select COUNT(1) as cnt, b.a from b group by b.a - ) - as b_grp + (select count(1) as cnt, b.a from b group by b.a) as b_grp on a.code = b_grp.a ) as ss @@ -1651,16 +1333,10 @@ select qq, unique1 from - ( - select coalesce(q1, 0) as qq from int8_tbl as a - ) - as ss1 + (select coalesce(q1, 0) as qq from int8_tbl as a) as ss1 full outer join - ( - select coalesce(q2, -1) as qq from int8_tbl as b - ) - as ss2 - using ("qq") + (select coalesce(q2, -1) as qq from int8_tbl as b) as ss2 + using (qq) inner join tenk1 as c on qq = unique2; @@ -1669,16 +1345,10 @@ select qq, unique1 from - ( - select coalesce(q1, 0) as qq from int8_tbl as a - ) - as ss1 + (select coalesce(q1, 0) as qq from int8_tbl as a) as ss1 full outer join - ( - select coalesce(q2, -1) as qq from int8_tbl as b - ) - as ss2 - using ("qq") + (select coalesce(q2, -1) as qq from int8_tbl as b) as ss2 + using (qq) inner join tenk1 as c on qq = unique2; @@ -1734,10 +1404,7 @@ from from nt2 as nt2 left outer join - ( - select nt1.*, nt1.id is not null as a3 from nt1 - ) - as ss1 + (select nt1.*, nt1.id is not null as a3 from nt1) as ss1 on ss1.id = nt2.nt1_id ) as ss2 @@ -1757,10 +1424,7 @@ from from nt2 as nt2 left outer join - ( - select nt1.*, nt1.id is not null as a3 from nt1 - ) - as ss1 + (select nt1.*, nt1.id is not null as a3 from nt1) as ss1 on ss1.id = nt2.nt1_id ) as ss2 @@ -1771,48 +1435,18 @@ where select * from - int8_tbl as t1 - left outer join - ( - select q1 as x, 42 as y from int8_tbl as t2 - ) - as ss - on t1.q2 = ss.x + int8_tbl as t1 left outer join (select q1 as x, 42 as y from int8_tbl as t2) as ss on t1.q2 = ss.x where - 1 = - ( - select - 1 - from - int8_tbl as t3 - where - ss.y is not null - limit 1 - ) + 1 = (select 1 from int8_tbl as t3 where ss.y is not null limit 1) order by 1, 2; select * from - int8_tbl as t1 - left outer join - ( - select q1 as x, 42 as y from int8_tbl as t2 - ) - as ss - on t1.q2 = ss.x + int8_tbl as t1 left outer join (select q1 as x, 42 as y from int8_tbl as t2) as ss on t1.q2 = ss.x where - 1 = - ( - select - 1 - from - int8_tbl as t3 - where - ss.y is not null - limit 1 - ) + 1 = (select 1 from int8_tbl as t3 where ss.y is not null limit 1) order by 1, 2; @@ -1824,15 +1458,7 @@ from select 1 as x from - ( - select - i41.f1 as lat, - i42.f1 as loc - from - int8_tbl as i81, - int4_tbl as i42 - ) - as ss1 + (select i41.f1 as lat, i42.f1 as loc from int8_tbl as i81, int4_tbl as i42) as ss1 right outer join int4_tbl as i43 on i43.f1 > 1 @@ -1851,15 +1477,7 @@ from select 1 as x from - ( - select - i41.f1 as lat, - i42.f1 as loc - from - int8_tbl as i81, - int4_tbl as i42 - ) - as ss1 + (select i41.f1 as lat, i42.f1 as loc from int8_tbl as i81, int4_tbl as i42) as ss1 right outer join int4_tbl as i43 on i43.f1 > 1 @@ -1900,10 +1518,7 @@ from int8_tbl as a, int8_tbl as b where - thousand = a.q1 and - tenthous = b.q1 and - a.q2 = 1 and - b.q2 = 2; + thousand = a.q1 and tenthous = b.q1 and a.q2 = 1 and b.q2 = 2; select t1.unique2, @@ -1968,10 +1583,7 @@ where select ss1.d1 from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.tenthous = t2.ten + tenk1 as t1 inner join tenk1 as t2 on t1.tenthous = t2.ten inner join int8_tbl as i8 left outer join @@ -1979,14 +1591,10 @@ from inner join ( select - cast(64 as information_schema.cardinal_number) - as d1 + cast(64 as information_schema.cardinal_number) as d1 from tenk1 as t3, - lateral ( - select abs(t3.unique1) + random() - ) - as ss0 (x) + lateral (select abs(t3.unique1) + random()) as ss0 (x) where t3.fivethous < 0 ) @@ -2000,10 +1608,7 @@ where select ss1.d1 from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.tenthous = t2.ten + tenk1 as t1 inner join tenk1 as t2 on t1.tenthous = t2.ten inner join int8_tbl as i8 left outer join @@ -2011,14 +1616,10 @@ from inner join ( select - cast(64 as information_schema.cardinal_number) - as d1 + cast(64 as information_schema.cardinal_number) as d1 from tenk1 as t3, - lateral ( - select abs(t3.unique1) + random() - ) - as ss0 (x) + lateral (select abs(t3.unique1) + random()) as ss0 (x) where t3.fivethous < 0 ) @@ -2092,19 +1693,13 @@ where select * from - (select 1 as x) as ss1 - left outer join - (select 2 as y) as ss2 - on true, + (select 1 as x) as ss1 left outer join (select 2 as y) as ss2 on true, lateral (select ss2.y as z limit 1) as ss3; select * from - (select 1 as x) as ss1 - left outer join - (select 2 as y) as ss2 - on true, + (select 1 as x) as ss1 left outer join (select 2 as y) as ss2 on true, lateral (select ss2.y as z limit 1) as ss3; begin; @@ -2121,13 +1716,7 @@ from coalesce(t2.q1 + x, 0) from int8_tbl as t2, - lateral ( - select - t3.q1 as x - from - int8_tbl as t3, - lateral (select t2.q1, t3.q1 offset 0) as s - ) + lateral (select t3.q1 as x from int8_tbl as t3, lateral (select t2.q1, t3.q1 offset 0) as s) ) on true; @@ -2140,10 +1729,7 @@ create temporary table t (i int primary key); select * from - t as t1 - left outer join - (select 1 as x, * from t as t2 (i2)) as t2ss - on t1.i = t2ss.i2 + t as t1 left outer join (select 1 as x, * from t as t2 (i2)) as t2ss on t1.i = t2ss.i2 left outer join t as t3 (i3) on false @@ -2163,10 +1749,7 @@ from i, coalesce(i, j) as k from - (select i from t union all select 0) - inner join - (select 1 as j limit 1) - on i = j + (select i from t union all select 0) inner join (select 1 as j limit 1) on i = j ) right outer join (select 2 as x) @@ -2198,10 +1781,7 @@ from right outer join (select false as z) as ss3 on true, - lateral ( - select i8.q2 as q2l where x limit 1 - ) - as ss4 + lateral (select i8.q2 as q2l where x limit 1) as ss4 where i8.q2 = 123; @@ -2224,37 +1804,22 @@ from right outer join (select false as z) as ss3 on true, - lateral ( - select i8.q2 as q2l where x limit 1 - ) - as ss4 + lateral (select i8.q2 as q2l where x limit 1) as ss4 where i8.q2 = 123; select * from - (select 0 as z) as t1 - left outer join - (select true as a) as t2 - on true, - lateral ( - select true as b union all select a as b - ) - as t3 + (select 0 as z) as t1 left outer join (select true as a) as t2 on true, + lateral (select true as b union all select a as b) as t3 where b; select * from - (select 0 as z) as t1 - left outer join - (select true as a) as t2 - on true, - lateral ( - select true as b union all select a as b - ) - as t3 + (select 0 as z) as t1 left outer join (select true as a) as t2 on true, + lateral (select true as b union all select a as b) as t3 where b; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_80.snap index 8c7336bef..5e71dbc32 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_80.snap @@ -89,14 +89,7 @@ select tt, kk from - (j1_tbl - inner join - j2_tbl - on true) as "tx" ("ii", - "jj", - "tt", - "ii2", - "kk"); + (j1_tbl inner join j2_tbl on true) as tx (ii, jj, tt, ii2, kk); select tx.ii, @@ -106,109 +99,58 @@ from (j1_tbl as t1 (a, b, c) inner join j2_tbl as t2 (d, e) - on true) as "tx" ("ii", - "jj", - "tt", - "ii2", - "kk"); + on true) as tx (ii, jj, tt, ii2, kk); select * from - j1_tbl inner join j2_tbl as a on true - inner join - j2_tbl as b - on true; + j1_tbl inner join j2_tbl as a on true inner join j2_tbl as b on true; -select * from j1_tbl inner join j2_tbl using ("i"); +select * from j1_tbl inner join j2_tbl using (i); -select * from j1_tbl inner join j2_tbl using ("i"); +select * from j1_tbl inner join j2_tbl using (i); select * from - j1_tbl as t1 (a, b, c) - inner join - j2_tbl as t2 (a, d) - using ("a") + j1_tbl as t1 (a, b, c) inner join j2_tbl as t2 (a, d) using (a) order by a, d; select * from - j1_tbl as t1 (a, b, c) - inner join - j2_tbl as t2 (a, b) - using ("b") + j1_tbl as t1 (a, b, c) inner join j2_tbl as t2 (a, b) using (b) order by b, t1.a; -select * from j1_tbl inner join j2_tbl using ("i") where j1_tbl.t = 'one'; +select * from j1_tbl inner join j2_tbl using (i) where j1_tbl.t = 'one'; -select - * -from - j1_tbl - inner join - j2_tbl - using ("i") as "x" -where - j1_tbl.t = 'one'; +select * from j1_tbl inner join j2_tbl using (i) as x where j1_tbl.t = 'one'; -select - * -from - (j1_tbl - inner join - j2_tbl - using ("i")) as "x" -where - j1_tbl.t = 'one'; +select * from (j1_tbl inner join j2_tbl using (i)) as x where j1_tbl.t = 'one'; -select * from j1_tbl inner join j2_tbl using ("i") as "x" where x.i = 1; +select * from j1_tbl inner join j2_tbl using (i) as x where x.i = 1; -select * from j1_tbl inner join j2_tbl using ("i") as "x" where x.t = 'one'; +select * from j1_tbl inner join j2_tbl using (i) as x where x.t = 'one'; -select - * -from - (j1_tbl - inner join - j2_tbl - using ("i") as "x") as "xx" -where - x.i = 1; +select * from (j1_tbl inner join j2_tbl using (i) as x) as xx where x.i = 1; -select * from j1_tbl as a1 inner join j2_tbl as a2 using ("i") as "a1"; +select * from j1_tbl as a1 inner join j2_tbl as a2 using (i) as a1; -select - x.* -from - j1_tbl - inner join - j2_tbl - using ("i") as "x" -where - j1_tbl.t = 'one'; +select x.* from j1_tbl inner join j2_tbl using (i) as x where j1_tbl.t = 'one'; select row(x.*) from - j1_tbl - inner join - j2_tbl - using ("i") as "x" + j1_tbl inner join j2_tbl using (i) as x where j1_tbl.t = 'one'; select row_to_json(x.*) from - j1_tbl - inner join - j2_tbl - using ("i") as "x" + j1_tbl inner join j2_tbl using (i) as x where j1_tbl.t = 'one'; @@ -226,21 +168,21 @@ select * from j1_tbl inner join j2_tbl on j1_tbl.i = j2_tbl.k; select * from j1_tbl inner join j2_tbl on j1_tbl.i <= j2_tbl.k; -select * from j1_tbl left outer join j2_tbl using ("i") order by i, k, t; +select * from j1_tbl left outer join j2_tbl using (i) order by i, k, t; -select * from j1_tbl left outer join j2_tbl using ("i") order by i, k, t; +select * from j1_tbl left outer join j2_tbl using (i) order by i, k, t; -select * from j1_tbl right outer join j2_tbl using ("i"); +select * from j1_tbl right outer join j2_tbl using (i); -select * from j1_tbl right outer join j2_tbl using ("i"); +select * from j1_tbl right outer join j2_tbl using (i); -select * from j1_tbl full outer join j2_tbl using ("i") order by i, k, t; +select * from j1_tbl full outer join j2_tbl using (i) order by i, k, t; -select * from j1_tbl full outer join j2_tbl using ("i") order by i, k, t; +select * from j1_tbl full outer join j2_tbl using (i) order by i, k, t; -select * from j1_tbl left outer join j2_tbl using ("i") where k = 1; +select * from j1_tbl left outer join j2_tbl using (i) where k = 1; -select * from j1_tbl left outer join j2_tbl using ("i") where i = 1; +select * from j1_tbl left outer join j2_tbl using (i) where i = 1; select * @@ -255,8 +197,7 @@ where from tenk1 as c where - b.twothousand = c.twothousand and - b.fivethous <> c.fivethous + b.twothousand = c.twothousand and b.fivethous <> c.fivethous ) and a.tenthous = b.tenthous and a.tenthous < 5000; @@ -293,18 +234,12 @@ insert into t3 values ('dd', 33); select * from - t1 full outer join t2 using ("name") - full outer join - t3 - using ("name"); + t1 full outer join t2 using (name) full outer join t3 using (name); select * from - (select * from t2) as s2 - inner join - (select * from t3) as s3 - using ("name"); + (select * from t2) as s2 inner join (select * from t3) as s3 using (name); select * @@ -312,7 +247,7 @@ from (select * from t2) as s2 left outer join (select * from t3) as s3 - using ("name"); + using (name); select * @@ -320,142 +255,46 @@ from (select * from t2) as s2 full outer join (select * from t3) as s3 - using ("name"); + using (name); select * from - ( - select - name, - n as s2_n, - 2 as s2_2 - from - t2 - ) - as s2 + (select name, n as s2_n, 2 as s2_2 from t2) as s2 natural join - ( - select - name, - n as s3_n, - 3 as s3_2 - from - t3 - ) - as s3; + (select name, n as s3_n, 3 as s3_2 from t3) as s3; select * from - ( - select - name, - n as s2_n, - 2 as s2_2 - from - t2 - ) - as s2 + (select name, n as s2_n, 2 as s2_2 from t2) as s2 natural left join - ( - select - name, - n as s3_n, - 3 as s3_2 - from - t3 - ) - as s3; + (select name, n as s3_n, 3 as s3_2 from t3) as s3; select * from - ( - select - name, - n as s2_n, - 2 as s2_2 - from - t2 - ) - as s2 + (select name, n as s2_n, 2 as s2_2 from t2) as s2 natural full join - ( - select - name, - n as s3_n, - 3 as s3_2 - from - t3 - ) - as s3; + (select name, n as s3_n, 3 as s3_2 from t3) as s3; select * from - ( - select - name, - n as s1_n, - 1 as s1_1 - from - t1 - ) - as s1 + (select name, n as s1_n, 1 as s1_1 from t1) as s1 natural join - ( - select - name, - n as s2_n, - 2 as s2_2 - from - t2 - ) - as s2 + (select name, n as s2_n, 2 as s2_2 from t2) as s2 natural join - ( - select - name, - n as s3_n, - 3 as s3_2 - from - t3 - ) - as s3; + (select name, n as s3_n, 3 as s3_2 from t3) as s3; select * from - ( - select - name, - n as s1_n, - 1 as s1_1 - from - t1 - ) - as s1 + (select name, n as s1_n, 1 as s1_1 from t1) as s1 natural full join - ( - select - name, - n as s2_n, - 2 as s2_2 - from - t2 - ) - as s2 + (select name, n as s2_n, 2 as s2_2 from t2) as s2 natural full join - ( - select - name, - n as s3_n, - 3 as s3_2 - from - t3 - ) - as s3; + (select name, n as s3_n, 3 as s3_2 from t3) as s3; select * @@ -481,15 +320,7 @@ from select * from - ( - select - name, - n as s2_n, - 2 as s2_2 - from - t2 - ) - as s2 + (select name, n as s2_n, 2 as s2_2 from t2) as s2 natural full join (select name, n as s3_n from t3) as s3 ) @@ -542,10 +373,7 @@ select * from x left outer join y on x1 = y1 and y2 is not null; select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1; + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1; select * @@ -574,35 +402,26 @@ from select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 where x2 is not null; select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 where y2 is not null; select * from - x left outer join y on x1 = y1 - left outer join - x as xx (xx1, xx2) - on x1 = xx1 + x left outer join y on x1 = y1 left outer join x as xx (xx1, xx2) on x1 = xx1 where xx2 is not null; select - COUNT(*) + count(*) from tenk1 as a where @@ -611,39 +430,24 @@ where select unique1 from - tenk1 as b - inner join - tenk1 as c - using ("unique1") + tenk1 as b inner join tenk1 as c using (unique1) where b.unique2 = 42 ); select - COUNT(*) + count(*) from tenk1 as x where x.unique1 in ( - select - a.f1 - from - int4_tbl as a, - float8_tbl as b - where - a.f1 = b.f1 + select a.f1 from int4_tbl as a, float8_tbl as b where a.f1 = b.f1 ) and x.unique1 = 0 and x.unique1 in ( - select - aa.f1 - from - int4_tbl as aa, - float8_tbl as bb - where - aa.f1 = bb.f1 + select aa.f1 from int4_tbl as aa, float8_tbl as bb where aa.f1 = bb.f1 ); begin; @@ -653,30 +457,18 @@ set geqo = 'on'; set geqo_threshold = 2; select - COUNT(*) + count(*) from tenk1 as x where x.unique1 in ( - select - a.f1 - from - int4_tbl as a, - float8_tbl as b - where - a.f1 = b.f1 + select a.f1 from int4_tbl as a, float8_tbl as b where a.f1 = b.f1 ) and x.unique1 = 0 and x.unique1 in ( - select - aa.f1 - from - int4_tbl as aa, - float8_tbl as bb - where - aa.f1 = bb.f1 + select aa.f1 from int4_tbl as aa, float8_tbl as bb where aa.f1 = bb.f1 ); rollback; @@ -687,10 +479,7 @@ select unique1, unique1 from - tenk1 - right outer join - b_star - on aa = unique1 + tenk1 right outer join b_star on aa = unique1 where bb < bb and bb is null; @@ -700,10 +489,7 @@ select unique1, unique1 from - tenk1 - right outer join - b_star - on aa = unique1 + tenk1 right outer join b_star on aa = unique1 where bb < bb and bb is null; @@ -712,10 +498,7 @@ select from int8_tbl as i1 left outer join - int8_tbl as i2 - inner join - (select 123 as x) as ss - on i2.q1 = x + int8_tbl as i2 inner join (select 123 as x) as ss on i2.q1 = x on i1.q2 = i2.q2 order by 1, 2; @@ -725,26 +508,20 @@ select from int8_tbl as i1 left outer join - int8_tbl as i2 - inner join - (select 123 as x) as ss - on i2.q1 = x + int8_tbl as i2 inner join (select 123 as x) as ss on i2.q1 = x on i1.q2 = i2.q2 order by 1, 2; select - COUNT(*) + count(*) from ( select t3.tenthous as x1, coalesce(t1.stringu1, t2.stringu1) as x2 from - tenk1 as t1 - left outer join - tenk1 as t2 - on t1.unique1 = t2.unique1 + tenk1 as t1 left outer join tenk1 as t2 on t1.unique1 = t2.unique1 inner join tenk1 as t3 on t1.unique2 = t3.unique2 @@ -753,9 +530,7 @@ from tenk1 as t4, tenk1 as t5 where - t4.thousand = t5.unique1 and - ss.x1 = t4.tenthous and - ss.x2 = t5.stringu1; + t4.thousand = t5.unique1 and ss.x1 = t4.tenthous and ss.x2 = t5.stringu1; select a.f1, @@ -764,24 +539,10 @@ select t.tenthous from tenk1 as t, - ( - select - SUM(f1) + 1 as f1 - from - int4_tbl as i4a - ) - as a, - ( - select - SUM(f1) as f1 - from - int4_tbl as i4b - ) - as b + (select sum(f1) + 1 as f1 from int4_tbl as i4a) as a, + (select sum(f1) as f1 from int4_tbl as i4b) as b where - b.f1 = t.thousand and - a.f1 = b.f1 and - a.f1 + b.f1 + 999 = t.tenthous; + b.f1 = t.thousand and a.f1 = b.f1 and a.f1 + b.f1 + 999 = t.tenthous; select a.f1, @@ -790,24 +551,10 @@ select t.tenthous from tenk1 as t, - ( - select - SUM(f1) + 1 as f1 - from - int4_tbl as i4a - ) - as a, - ( - select - SUM(f1) as f1 - from - int4_tbl as i4b - ) - as b + (select sum(f1) + 1 as f1 from int4_tbl as i4a) as a, + (select sum(f1) as f1 from int4_tbl as i4b) as b where - b.f1 = t.thousand and - a.f1 = b.f1 and - a.f1 + b.f1 + 999 = t.tenthous; + b.f1 = t.thousand and a.f1 = b.f1 and a.f1 + b.f1 + 999 = t.tenthous; select t1.unique1, @@ -817,15 +564,7 @@ from inner join tenk1 as t2 on t1.two = t2.two and - t1.unique1 = - ( - select - MIN(unique1) - from - tenk1 - where - t2.unique1 = unique1 - ) + t1.unique1 = (select min(unique1) from tenk1 where t2.unique1 = unique1) where t1.unique1 < 10 and t2.unique1 < 10 order by t1.unique1; @@ -838,15 +577,7 @@ from inner join tenk1 as t2 on t1.two = t2.two and - t1.unique1 = - ( - select - MIN(unique1) - from - tenk1 - where - t2.unique1 = unique1 - ) + t1.unique1 = (select min(unique1) from tenk1 where t2.unique1 = unique1) where t1.unique1 < 10 and t2.unique1 < 10 order by t1.unique1; @@ -855,10 +586,7 @@ select t1.f1 from int4_tbl as t1, - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t3.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t3.f1 > 0 left outer join int4_tbl as t4 on t3.f1 > 1 @@ -869,10 +597,7 @@ select t1.f1 from int4_tbl as t1, - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t3.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t3.f1 > 0 left outer join int4_tbl as t4 on t3.f1 > 1 @@ -882,10 +607,7 @@ where select * from - int4_tbl as t1 - left outer join - int4_tbl as t2 - on true + int4_tbl as t1 left outer join int4_tbl as t2 on true left outer join int4_tbl as t3 on t2.f1 > 0 @@ -896,10 +618,7 @@ from select * from - onek as t1 - left outer join - onek as t2 - on t1.unique1 = t2.unique1 + onek as t1 left outer join onek as t2 on t1.unique1 = t2.unique1 left outer join onek as t3 on t2.unique1 <> t3.unique1 @@ -914,12 +633,9 @@ from left outer join ( select - NOW() + now() from - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t2.f1 = t3.f1 + int4_tbl as t2 left outer join int4_tbl as t3 on t2.f1 = t3.f1 left outer join int4_tbl as t4 on t3.f1 = t4.f1 @@ -933,10 +649,7 @@ from select * from - int4_tbl as t1 - left outer join - int4_tbl as t2 - on true + int4_tbl as t1 left outer join int4_tbl as t2 on true left outer join int4_tbl as t3 on true @@ -947,10 +660,7 @@ from select * from - int4_tbl as t1 - left outer join - int4_tbl as t2 - on true + int4_tbl as t1 left outer join int4_tbl as t2 on true left outer join int4_tbl as t3 on t2.f1 = t3.f1 @@ -963,10 +673,7 @@ select from int4_tbl as t1 left outer join - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t2.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t2.f1 > 0 on t2.f1 > 1 left outer join int4_tbl as t4 @@ -983,10 +690,7 @@ from select t2.f1 from - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t2.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t2.f1 > 0 where t3.f1 is null ) @@ -1005,10 +709,7 @@ from select t2.f1 from - int4_tbl as t2 - left outer join - int4_tbl as t3 - on t2.f1 > 0 + int4_tbl as t2 left outer join int4_tbl as t3 on t2.f1 > 0 where t2.f1 <> coalesce(t3.f1, -1) ) @@ -1021,17 +722,13 @@ from select * from - onek as t1 - left outer join - onek as t2 - on t1.unique1 = t2.unique1 + onek as t1 left outer join onek as t2 on t1.unique1 = t2.unique1 left outer join onek as t3 on t2.unique1 = t3.unique1 left outer join onek as t4 - on t3.unique1 = t4.unique1 and - t2.unique2 = t4.unique2; + on t3.unique1 = t4.unique1 and t2.unique2 = t4.unique2; select * @@ -1040,10 +737,7 @@ from left outer join int8_tbl as t2 left outer join - int8_tbl as t3 - full outer join - int8_tbl as t4 - on false + int8_tbl as t3 full outer join int8_tbl as t4 on false on false left outer join int8_tbl as t5 @@ -1053,72 +747,33 @@ from select * from - int8_tbl as t1 - left outer join - int8_tbl as t2 - on true + int8_tbl as t1 left outer join int8_tbl as t2 on true left outer join - lateral ( - select - * - from - int8_tbl as t3 - where - t3.q1 = t2.q1 - offset 0 - ) - as s + lateral (select * from int8_tbl as t3 where t3.q1 = t2.q1 offset 0) as s on t2.q1 = 1; select * from - int8_tbl as t1 - left outer join - int8_tbl as t2 - on true + int8_tbl as t1 left outer join int8_tbl as t2 on true left outer join - lateral ( - select - * - from - generate_series(t2.q1, 100) - ) - as s + lateral (select * from generate_series(t2.q1, 100)) as s on t2.q1 = 1; select * from - int8_tbl as t1 - left outer join - int8_tbl as t2 - on true + int8_tbl as t1 left outer join int8_tbl as t2 on true left outer join - lateral ( - select t2.q1 from int8_tbl as t3 - ) - as s + lateral (select t2.q1 from int8_tbl as t3) as s on t2.q1 = 1; select * from - onek as t1 - left outer join - onek as t2 - on true + onek as t1 left outer join onek as t2 on true left outer join - lateral ( - select - * - from - onek as t3 - where - t3.two = t2.two - offset 0 - ) - as s + lateral (select * from onek as t3 where t3.two = t2.two offset 0) as s on t2.unique1 = 1; select @@ -1126,83 +781,39 @@ select from j1_tbl full outer join - ( - select - * - from - j2_tbl - order by j2_tbl.i desc, - j2_tbl.k asc - ) - as j2_tbl - on j1_tbl.i = j2_tbl.i and - j1_tbl.i = j2_tbl.k; + (select * from j2_tbl order by j2_tbl.i desc, j2_tbl.k asc) as j2_tbl + on j1_tbl.i = j2_tbl.i and j1_tbl.i = j2_tbl.k; select * from j1_tbl full outer join - ( - select - * - from - j2_tbl - order by j2_tbl.i desc, - j2_tbl.k asc - ) - as j2_tbl - on j1_tbl.i = j2_tbl.i and - j1_tbl.i = j2_tbl.k; + (select * from j2_tbl order by j2_tbl.i desc, j2_tbl.k asc) as j2_tbl + on j1_tbl.i = j2_tbl.i and j1_tbl.i = j2_tbl.k; select - COUNT(*) + count(*) from ( - select - * - from - tenk1 as x - order by x.thousand, - x.twothousand, - x.fivethous + select * from tenk1 as x order by x.thousand, x.twothousand, x.fivethous ) as x left outer join - ( - select - * - from - tenk1 as y - order by y.unique2 - ) - as y + (select * from tenk1 as y order by y.unique2) as y on x.thousand = y.unique2 and x.twothousand = y.hundred and x.fivethous = y.unique2; select - COUNT(*) + count(*) from ( - select - * - from - tenk1 as x - order by x.thousand, - x.twothousand, - x.fivethous + select * from tenk1 as x order by x.thousand, x.twothousand, x.fivethous ) as x left outer join - ( - select - * - from - tenk1 as y - order by y.unique2 - ) - as y + (select * from tenk1 as y order by y.unique2) as y on x.thousand = y.unique2 and x.twothousand = y.hundred and x.fivethous = y.unique2; @@ -1216,12 +827,9 @@ set enable_hashagg = 0; select x.thousand, x.twothousand, - COUNT(*) + count(*) from - tenk1 as x - inner join - tenk1 as y - on x.thousand = y.thousand + tenk1 as x inner join tenk1 as y on x.thousand = y.thousand group by x.thousand, x.twothousand order by x.thousand desc, @@ -1280,7 +888,7 @@ delete from t3 using t1 as table1 where t3.x = table1.a; select * from t3; -delete from t3 using t1 inner join t2 using ("a") where t3.x > t1.a; +delete from t3 using t1 inner join t2 using (a) where t3.x > t1.a; select * from t3; @@ -1313,7 +921,7 @@ select foo.*, unnamed_join.* from - t1 inner join t2 using ("a") as "foo", + t1 inner join t2 using (a) as foo, t3 as unnamed_join for update of unnamed_join; @@ -1321,7 +929,7 @@ select foo.*, unnamed_join.* from - t1 inner join t2 using ("a") as "foo", + t1 inner join t2 using (a) as foo, t3 as unnamed_join for update of foo; @@ -1329,10 +937,7 @@ select bar.*, unnamed_join.* from - (t1 - inner join - t2 - using ("a") as "foo") as "bar", + (t1 inner join t2 using (a) as foo) as bar, t3 as unnamed_join for update of foo; @@ -1340,16 +945,13 @@ select bar.*, unnamed_join.* from - (t1 - inner join - t2 - using ("a") as "foo") as "bar", + (t1 inner join t2 using (a) as foo) as bar, t3 as unnamed_join for update of bar; create temporary table tt1 ( - tt1_id int, - joincol int + tt1_id int4, + joincol int4 ); insert into tt1 values (1, 11); @@ -1357,8 +959,8 @@ insert into tt1 values (1, 11); insert into tt1 values (2, null); create temporary table tt2 ( - tt2_id int, - joincol int + tt2_id int4, + joincol int4 ); insert into tt2 values (21, 11); @@ -1397,32 +999,14 @@ select from tbl_ra as t1 where - not exists - ( - select - 1 - from - tbl_ra as t2 - where - t2.b = t1.a - ) and - t1.b < 2; + not exists (select 1 from tbl_ra as t2 where t2.b = t1.a) and t1.b < 2; select * from tbl_ra as t1 where - not exists - ( - select - 1 - from - tbl_ra as t2 - where - t2.b = t1.a - ) and - t1.b < 2; + not exists (select 1 from tbl_ra as t2 where t2.b = t1.a) and t1.b < 2; reset enable_hashjoin; @@ -1448,11 +1032,7 @@ from from tbl_rs as t2 where - t2.a in - ( - select t1.a + t3.a from tbl_rs as t3 - ) and - t2.a < 5 + t2.a in (select t1.a + t3.a from tbl_rs as t3) and t2.a < 5 ) on true; @@ -1467,11 +1047,7 @@ from from tbl_rs as t2 where - t2.a in - ( - select t1.a + t3.a from tbl_rs as t3 - ) and - t2.a < 5 + t2.a in (select t1.a + t3.a from tbl_rs as t3) and t2.a < 5 ) on true; @@ -1482,22 +1058,20 @@ set enable_mergejoin = off; set enable_memoize = off; select - COUNT(*) + count(*) from tenk1 as a, tenk1 as b where - a.hundred = b.thousand and - b.fivethous % 10 < 10; + a.hundred = b.thousand and b.fivethous % 10 < 10; select - COUNT(*) + count(*) from tenk1 as a, tenk1 as b where - a.hundred = b.thousand and - b.fivethous % 10 < 10; + a.hundred = b.thousand and b.fivethous % 10 < 10; reset work_mem; @@ -1511,11 +1085,7 @@ create temporary table tt3 ( ); insert into tt3 -select - x, - repeat('xyzzy', 100) -from - generate_series(1, 10000) as x; +select x, repeat('xyzzy', 100) from generate_series(1, 10000) as x; analyze tt3; @@ -1536,10 +1106,7 @@ from select b.f1 from - tt3 as b - left outer join - tt3 as c - on b.f1 = c.f1 + tt3 as b left outer join tt3 as c on b.f1 = c.f1 where coalesce(c.f1, 0) = 0 ) @@ -1558,10 +1125,7 @@ from select b.f1 from - tt3 as b - left outer join - tt3 as c - on b.f1 = c.f1 + tt3 as b left outer join tt3 as c on b.f1 = c.f1 where coalesce(c.f1, 0) = 0 ) @@ -1580,48 +1144,26 @@ select from tenk1 as a where - not unique1 in - ( - select unique2 from tenk1 as b - ); + not unique1 in (select unique2 from tenk1 as b); select a.* from tenk1 as a where - exists - ( - select - 1 - from - tenk1 as b - where - a.unique1 = b.unique2 - ); + exists (select 1 from tenk1 as b where a.unique1 = b.unique2); select a.* from tenk1 as a where - not exists - ( - select - 1 - from - tenk1 as b - where - a.unique1 = b.unique2 - ); + not exists (select 1 from tenk1 as b where a.unique1 = b.unique2); select a.* from - tenk1 as a - left outer join - tenk1 as b - on a.unique1 = b.unique2 + tenk1 as a left outer join tenk1 as b on a.unique1 = b.unique2 where b.unique2 is null; @@ -1632,14 +1174,7 @@ select from tenk1 where - (hundred, thousand) in - ( - select - twothousand, - twothousand - from - onek - ); + (hundred, thousand) in (select twothousand, twothousand from onek); reset enable_memoize; @@ -1650,13 +1185,7 @@ from where exists ( - select - 1 - from - tenk1 as b - where - a.unique1 = b.unique2 - group by b.unique1 + select 1 from tenk1 as b where a.unique1 = b.unique2 group by b.unique1 ); create temporary table tt4x ( @@ -1675,19 +1204,13 @@ where select 1 from - tt4x as t2 - left outer join - tt4x as t3 - on t2.c3 = t3.c1 + tt4x as t2 left outer join tt4x as t3 on t2.c3 = t3.c1 left outer join ( select t5.c1 as c1 from - tt4x as t4 - left outer join - tt4x as t5 - on t4.c2 = t5.c1 + tt4x as t4 left outer join tt4x as t5 on t4.c2 = t5.c1 ) as a1 on t3.c2 = a1.c1 @@ -1745,10 +1268,7 @@ select from yy left outer join - ( - select * from yy where pkyy = 101 - ) - as yya + (select * from yy where pkyy = 101) as yya on yy.pkyy = yya.pkyy left outer join xx as xxa @@ -1770,27 +1290,17 @@ insert into zt2 values (53); select * from - zt2 left outer join zt3 on f2 = f3 - left outer join - zt1 - on f3 = f1 + zt2 left outer join zt3 on f2 = f3 left outer join zt1 on f3 = f1 where f2 = 53; create temporary view zv1 -as select - *, - cast('dummy' as text) as junk -from - zt1; +as select *, cast('dummy' as text) as junk from zt1; select * from - zt2 left outer join zt3 on f2 = f3 - left outer join - zv1 - on f3 = f1 + zt2 left outer join zt3 on f2 = f3 left outer join zv1 on f3 = f1 where f2 = 53; @@ -1801,35 +1311,20 @@ select b.unique2, b.hundred from - tenk1 as a - left outer join - tenk1 as b - on a.unique2 = b.tenthous + tenk1 as a left outer join tenk1 as b on a.unique2 = b.tenthous where - a.unique1 = 42 and - ( - (b.unique2 is null and a.ten = 2) or - b.hundred = 3 - ); + a.unique1 = 42 and ((b.unique2 is null and a.ten = 2) or b.hundred = 3); prepare foo -(boolean) +(bool) as select - COUNT(*) + count(*) from tenk1 as a left outer join tenk1 as b on a.unique2 = b.unique1 and - exists - ( - select - 1 - from - tenk1 as c - where - c.thousand = b.unique2 and $1 - );; + exists (select 1 from tenk1 as c where c.thousand = b.unique2 and $1);; execute foo (true); @@ -1874,29 +1369,23 @@ rollback; select t1.q2, - COUNT(t2.*) + count(t2.*) from - int8_tbl as t1 - left outer join - int8_tbl as t2 - on t1.q2 = t2.q1 + int8_tbl as t1 left outer join int8_tbl as t2 on t1.q2 = t2.q1 group by t1.q2 order by 1; select t1.q2, - COUNT(t2.*) + count(t2.*) from - int8_tbl as t1 - left outer join - (select * from int8_tbl) as t2 - on t1.q2 = t2.q1 + int8_tbl as t1 left outer join (select * from int8_tbl) as t2 on t1.q2 = t2.q1 group by t1.q2 order by 1; select t1.q2, - COUNT(t2.*) + count(t2.*) from int8_tbl as t1 left outer join @@ -1907,19 +1396,11 @@ order by 1; select t1.q2, - COUNT(t2.*) + count(t2.*) from int8_tbl as t1 left outer join - ( - select - q1, - case when q2 = 1 then 1 else q2 end - as q2 - from - int8_tbl - ) - as t2 + (select q1, case when q2 = 1 then 1 else q2 end as q2 from int8_tbl) as t2 on t1.q2 = t2.q1 group by t1.q2 order by 1; @@ -1928,19 +1409,19 @@ begin; create temporary table a ( code char(1) not null, - constraint "a_pk" primary key (code) + constraint a_pk primary key (code) ); create temporary table b ( a char(1) not null, num int not null, - constraint "b_pk" primary key (a, num) + constraint b_pk primary key (a, num) ); create temporary table c ( name char(1) not null, a char(1), - constraint "c_pk" primary key (name) + constraint c_pk primary key (name) ); insert into a (code) values ('p'); @@ -1973,15 +1454,7 @@ from from a left outer join - ( - select - COUNT(1) as cnt, - b.a - from - b - group by b.a - ) - as b_grp + (select count(1) as cnt, b.a from b group by b.a) as b_grp on a.code = b_grp.a ) as ss @@ -2052,22 +1525,10 @@ select qq, unique1 from - ( - select - coalesce(q1, 0) as qq - from - int8_tbl as a - ) - as ss1 + (select coalesce(q1, 0) as qq from int8_tbl as a) as ss1 full outer join - ( - select - coalesce(q2, -1) as qq - from - int8_tbl as b - ) - as ss2 - using ("qq") + (select coalesce(q2, -1) as qq from int8_tbl as b) as ss2 + using (qq) inner join tenk1 as c on qq = unique2; @@ -2076,22 +1537,10 @@ select qq, unique1 from - ( - select - coalesce(q1, 0) as qq - from - int8_tbl as a - ) - as ss1 + (select coalesce(q1, 0) as qq from int8_tbl as a) as ss1 full outer join - ( - select - coalesce(q2, -1) as qq - from - int8_tbl as b - ) - as ss2 - using ("qq") + (select coalesce(q2, -1) as qq from int8_tbl as b) as ss2 + using (qq) inner join tenk1 as c on qq = unique2; @@ -2147,14 +1596,7 @@ from from nt2 as nt2 left outer join - ( - select - nt1.*, - nt1.id is not null as a3 - from - nt1 - ) - as ss1 + (select nt1.*, nt1.id is not null as a3 from nt1) as ss1 on ss1.id = nt2.nt1_id ) as ss2 @@ -2174,14 +1616,7 @@ from from nt2 as nt2 left outer join - ( - select - nt1.*, - nt1.id is not null as a3 - from - nt1 - ) - as ss1 + (select nt1.*, nt1.id is not null as a3 from nt1) as ss1 on ss1.id = nt2.nt1_id ) as ss2 @@ -2194,26 +1629,10 @@ select from int8_tbl as t1 left outer join - ( - select - q1 as x, - 42 as y - from - int8_tbl as t2 - ) - as ss + (select q1 as x, 42 as y from int8_tbl as t2) as ss on t1.q2 = ss.x where - 1 = - ( - select - 1 - from - int8_tbl as t3 - where - ss.y is not null - limit 1 - ) + 1 = (select 1 from int8_tbl as t3 where ss.y is not null limit 1) order by 1, 2; @@ -2222,26 +1641,10 @@ select from int8_tbl as t1 left outer join - ( - select - q1 as x, - 42 as y - from - int8_tbl as t2 - ) - as ss + (select q1 as x, 42 as y from int8_tbl as t2) as ss on t1.q2 = ss.x where - 1 = - ( - select - 1 - from - int8_tbl as t3 - where - ss.y is not null - limit 1 - ) + 1 = (select 1 from int8_tbl as t3 where ss.y is not null limit 1) order by 1, 2; @@ -2314,10 +1717,7 @@ analyze q2; select * from - tenk1 - inner join - int4_tbl - on f1 = twothousand, + tenk1 inner join int4_tbl on f1 = twothousand, q1, q2 where @@ -2326,10 +1726,7 @@ where select * from - tenk1 - inner join - int4_tbl - on f1 = twothousand, + tenk1 inner join int4_tbl on f1 = twothousand, q1, q2 where @@ -2342,10 +1739,7 @@ from int8_tbl as a, int8_tbl as b where - thousand = a.q1 and - tenthous = b.q1 and - a.q2 = 1 and - b.q2 = 2; + thousand = a.q1 and tenthous = b.q1 and a.q2 = 1 and b.q2 = 2; select t1.unique2, @@ -2375,8 +1769,7 @@ from tenk1 as t2 on subq1.y1 = t2.unique1 where - t1.unique2 < 42 and - t1.stringu1 > t2.stringu2; + t1.unique2 < 42 and t1.stringu1 > t2.stringu2; select t1.unique2, @@ -2406,16 +1799,12 @@ from tenk1 as t2 on subq1.y1 = t2.unique1 where - t1.unique2 < 42 and - t1.stringu1 > t2.stringu2; + t1.unique2 < 42 and t1.stringu1 > t2.stringu2; select ss1.d1 from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.tenthous = t2.ten + tenk1 as t1 inner join tenk1 as t2 on t1.tenthous = t2.ten inner join int8_tbl as i8 left outer join @@ -2423,15 +1812,10 @@ from inner join ( select - cast(64 - as information_schema.cardinal_number) - as d1 + cast(64 as information_schema.cardinal_number) as d1 from tenk1 as t3, - lateral ( - select abs(t3.unique1) + random() - ) - as ss0 (x) + lateral (select abs(t3.unique1) + random()) as ss0 (x) where t3.fivethous < 0 ) @@ -2445,10 +1829,7 @@ where select ss1.d1 from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.tenthous = t2.ten + tenk1 as t1 inner join tenk1 as t2 on t1.tenthous = t2.ten inner join int8_tbl as i8 left outer join @@ -2456,15 +1837,10 @@ from inner join ( select - cast(64 - as information_schema.cardinal_number) - as d1 + cast(64 as information_schema.cardinal_number) as d1 from tenk1 as t3, - lateral ( - select abs(t3.unique1) + random() - ) - as ss0 (x) + lateral (select abs(t3.unique1) + random()) as ss0 (x) where t3.fivethous < 0 ) @@ -2503,8 +1879,7 @@ from tenk1 as t2 on subq1.y1 = t2.unique1 where - t1.unique2 < 42 and - t1.stringu1 > t2.stringu2; + t1.unique2 < 42 and t1.stringu1 > t2.stringu2; select t1.unique2, @@ -2534,32 +1909,19 @@ from tenk1 as t2 on subq1.y1 = t2.unique1 where - t1.unique2 < 42 and - t1.stringu1 > t2.stringu2; + t1.unique2 < 42 and t1.stringu1 > t2.stringu2; select * from - (select 1 as x) as ss1 - left outer join - (select 2 as y) as ss2 - on true, - lateral ( - select ss2.y as z limit 1 - ) - as ss3; + (select 1 as x) as ss1 left outer join (select 2 as y) as ss2 on true, + lateral (select ss2.y as z limit 1) as ss3; select * from - (select 1 as x) as ss1 - left outer join - (select 2 as y) as ss2 - on true, - lateral ( - select ss2.y as z limit 1 - ) - as ss3; + (select 1 as x) as ss1 left outer join (select 2 as y) as ss2 on true, + lateral (select ss2.y as z limit 1) as ss3; begin; @@ -2580,10 +1942,7 @@ from t3.q1 as x from int8_tbl as t3, - lateral ( - select t2.q1, t3.q1 offset 0 - ) - as s + lateral (select t2.q1, t3.q1 offset 0) as s ) ) on true; @@ -2599,10 +1958,7 @@ select from t as t1 left outer join - ( - select 1 as x, * from t as t2 (i2) - ) - as t2ss + (select 1 as x, * from t as t2 (i2)) as t2ss on t1.i = t2ss.i2 left outer join t as t3 (i3) @@ -2649,10 +2005,7 @@ from (select true) as x from int4_tbl as i4, - lateral ( - select i4.f1 as y limit 1 - ) - as ss1 + lateral (select i4.f1 as y limit 1) as ss1 where i4.f1 = 0 ) @@ -2661,10 +2014,7 @@ from right outer join (select false as z) as ss3 on true, - lateral ( - select i8.q2 as q2l where x limit 1 - ) - as ss4 + lateral (select i8.q2 as q2l where x limit 1) as ss4 where i8.q2 = 123; @@ -2687,37 +2037,22 @@ from right outer join (select false as z) as ss3 on true, - lateral ( - select i8.q2 as q2l where x limit 1 - ) - as ss4 + lateral (select i8.q2 as q2l where x limit 1) as ss4 where i8.q2 = 123; select * from - (select 0 as z) as t1 - left outer join - (select true as a) as t2 - on true, - lateral ( - select true as b union all select a as b - ) - as t3 + (select 0 as z) as t1 left outer join (select true as a) as t2 on true, + lateral (select true as b union all select a as b) as t3 where b; select * from - (select 0 as z) as t1 - left outer join - (select true as a) as t2 - on true, - lateral ( - select true as b union all select a as b - ) - as t3 + (select 0 as z) as t1 left outer join (select true as a) as t2 on true, + lateral (select true as b union all select a as b) as t3 where b; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_hash_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_hash_100.snap index ac1ecf3ce..710bb586b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_hash_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_hash_100.snap @@ -14,7 +14,7 @@ set local enable_hashjoin = 'on'; create or replace function find_hash(node json) returns json language plpgsql -as $function$ +as $$ declare x json; child json; @@ -32,7 +32,7 @@ begin return null; end if; end; -$function$; +$$; create or replace function hash_join_batches(query text) returns table ( @@ -40,7 +40,7 @@ returns table ( final int ) language plpgsql -as $function$ +as $$ declare whole_plan json; hash_node json; @@ -54,7 +54,7 @@ begin return next; end loop; end; -$function$; +$$; create table simple as select generate_series(1, 20000) as id, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; @@ -65,9 +65,7 @@ analyze simple; create table bigger_than_it_looks as - select - generate_series(1, 20000) as id, - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; + select generate_series(1, 20000) as id, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; alter table bigger_than_it_looks set (autovacuum_enabled = 'false'); @@ -93,11 +91,7 @@ alter table extremely_skewed analyze extremely_skewed; insert into extremely_skewed -select - 42 as id, - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' -from - generate_series(1, 20000); +select 42 as id, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' from generate_series(1, 20000); update pg_class set reltuples = 2, @@ -118,19 +112,17 @@ set local work_mem = '4MB'; set local hash_mem_multiplier = 1.0; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -144,19 +136,17 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = off; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -170,19 +160,17 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = 'on'; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -194,19 +182,17 @@ set local work_mem = '128kB'; set local hash_mem_multiplier = 1.0; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -220,19 +206,17 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = off; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -246,21 +230,19 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = 'on'; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); rollback to savepoint settings; @@ -272,19 +254,17 @@ set local work_mem = '128kB'; set local hash_mem_multiplier = 1.0; -select COUNT(*) from simple as r inner join bigger_than_it_looks as s using ("id"); +select count(*) from simple as r inner join bigger_than_it_looks as s using (id); -select COUNT(*) from simple as r inner join bigger_than_it_looks as s using ("id"); +select count(*) from simple as r inner join bigger_than_it_looks as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) FROM simple r JOIN bigger_than_it_looks s USING (id); -' - ); +'); rollback to savepoint settings; @@ -298,19 +278,17 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = off; -select COUNT(*) from simple as r inner join bigger_than_it_looks as s using ("id"); +select count(*) from simple as r inner join bigger_than_it_looks as s using (id); -select COUNT(*) from simple as r inner join bigger_than_it_looks as s using ("id"); +select count(*) from simple as r inner join bigger_than_it_looks as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join bigger_than_it_looks s using (id); -' - ); +'); rollback to savepoint settings; @@ -324,19 +302,17 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = 'on'; -select COUNT(*) from simple as r inner join bigger_than_it_looks as s using ("id"); +select count(*) from simple as r inner join bigger_than_it_looks as s using (id); -select COUNT(*) from simple as r inner join bigger_than_it_looks as s using ("id"); +select count(*) from simple as r inner join bigger_than_it_looks as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join bigger_than_it_looks s using (id); -' - ); +'); rollback to savepoint settings; @@ -348,18 +324,13 @@ set local work_mem = '128kB'; set local hash_mem_multiplier = 1.0; -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select - * -from - hash_join_batches( - ' +select * from hash_join_batches(' select count(*) from simple r join extremely_skewed s using (id); -' - ); +'); rollback to savepoint settings; @@ -373,18 +344,13 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = off; -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select - * -from - hash_join_batches( - ' +select * from hash_join_batches(' select count(*) from simple r join extremely_skewed s using (id); -' - ); +'); rollback to savepoint settings; @@ -398,18 +364,13 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = 'on'; -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select - * -from - hash_join_batches( - ' +select * from hash_join_batches(' select count(*) from simple r join extremely_skewed s using (id); -' - ); +'); rollback to savepoint settings; @@ -462,53 +423,26 @@ set work_mem = '64kB'; set hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from join_foo left outer join - ( - select - b1.id, - b1.t - from - join_bar as b1 - inner join - join_bar as b2 - using ("id") - ) - as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + (select b1.id, b1.t from join_bar as b1 inner join join_bar as b2 using (id)) as ss + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; select - COUNT(*) + count(*) from join_foo left outer join - ( - select - b1.id, - b1.t - from - join_bar as b1 - inner join - join_bar as b2 - using ("id") - ) - as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + (select b1.id, b1.t from join_bar as b1 inner join join_bar as b2 using (id)) as ss + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select count(*) from join_foo left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -' - ); +'); rollback to savepoint settings; @@ -535,53 +469,26 @@ set work_mem = '4MB'; set hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from join_foo left outer join - ( - select - b1.id, - b1.t - from - join_bar as b1 - inner join - join_bar as b2 - using ("id") - ) - as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + (select b1.id, b1.t from join_bar as b1 inner join join_bar as b2 using (id)) as ss + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; select - COUNT(*) + count(*) from join_foo left outer join - ( - select - b1.id, - b1.t - from - join_bar as b1 - inner join - join_bar as b2 - using ("id") - ) - as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + (select b1.id, b1.t from join_bar as b1 inner join join_bar as b2 using (id)) as ss + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select count(*) from join_foo left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -' - ); +'); rollback to savepoint settings; @@ -608,53 +515,26 @@ set work_mem = '64kB'; set hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from join_foo left outer join - ( - select - b1.id, - b1.t - from - join_bar as b1 - inner join - join_bar as b2 - using ("id") - ) - as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + (select b1.id, b1.t from join_bar as b1 inner join join_bar as b2 using (id)) as ss + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; select - COUNT(*) + count(*) from join_foo left outer join - ( - select - b1.id, - b1.t - from - join_bar as b1 - inner join - join_bar as b2 - using ("id") - ) - as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + (select b1.id, b1.t from join_bar as b1 inner join join_bar as b2 using (id)) as ss + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select count(*) from join_foo left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -' - ); +'); rollback to savepoint settings; @@ -681,53 +561,26 @@ set work_mem = '4MB'; set hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from join_foo left outer join - ( - select - b1.id, - b1.t - from - join_bar as b1 - inner join - join_bar as b2 - using ("id") - ) - as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + (select b1.id, b1.t from join_bar as b1 inner join join_bar as b2 using (id)) as ss + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; select - COUNT(*) + count(*) from join_foo left outer join - ( - select - b1.id, - b1.t - from - join_bar as b1 - inner join - join_bar as b2 - using ("id") - ) - as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + (select b1.id, b1.t from join_bar as b1 inner join join_bar as b2 using (id)) as ss + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select count(*) from join_foo left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -' - ); +'); rollback to savepoint settings; @@ -735,9 +588,9 @@ savepoint settings; set local max_parallel_workers_per_gather = 0; -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); rollback to savepoint settings; @@ -747,9 +600,9 @@ set enable_parallel_hash = off; set local max_parallel_workers_per_gather = 2; -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); rollback to savepoint settings; @@ -757,9 +610,9 @@ savepoint settings; set local max_parallel_workers_per_gather = 2; -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); rollback to savepoint settings; @@ -767,9 +620,9 @@ savepoint settings; set local max_parallel_workers_per_gather = 0; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; rollback to savepoint settings; @@ -779,9 +632,9 @@ set enable_parallel_hash = off; set local max_parallel_workers_per_gather = 2; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; rollback to savepoint settings; @@ -789,9 +642,9 @@ savepoint settings; set local max_parallel_workers_per_gather = 2; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; rollback to savepoint settings; @@ -806,36 +659,19 @@ set work_mem = '128kB'; set hash_mem_multiplier = 1.0; select - length(MAX(s.t)) + length(max(s.t)) from - wide - left outer join - ( - select id, coalesce(t, '') || '' as t from wide - ) - as s - using ("id"); + wide left outer join (select id, coalesce(t, '') || '' as t from wide) as s using (id); select - length(MAX(s.t)) + length(max(s.t)) from - wide - left outer join - ( - select id, coalesce(t, '') || '' as t from wide - ) - as s - using ("id"); + wide left outer join (select id, coalesce(t, '') || '' as t from wide) as s using (id); -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select length(max(s.t)) from wide left join (select id, coalesce(t, '''') || '''' as t from wide) s using (id); -' - ); +'); rollback to savepoint settings; @@ -862,10 +698,7 @@ update hjtest_matchbits_t2 set id = 2; select * from - hjtest_matchbits_t1 as t1 - full outer join - hjtest_matchbits_t2 as t2 - on t1.id = t2.id + hjtest_matchbits_t1 as t1 full outer join hjtest_matchbits_t2 as t2 on t1.id = t2.id order by t1.id; reset parallel_setup_cost; @@ -888,11 +721,11 @@ create table hjtest_1 ( a text, b int, id int, - c boolean + c bool ); create table hjtest_2 ( - a boolean, + a bool, id int, b text, c int @@ -992,10 +825,7 @@ from t1.fivethous, i4.f1 from - tenk1 as t1 - inner join - int4_tbl as i4 - on t1.fivethous = i4.f1 + i8.q2 + tenk1 as t1 inner join int4_tbl as i4 on t1.fivethous = i4.f1 + i8.q2 order by 1, 2 ) @@ -1011,10 +841,7 @@ from t1.fivethous, i4.f1 from - tenk1 as t1 - inner join - int4_tbl as i4 - on t1.fivethous = i4.f1 + i8.q2 + tenk1 as t1 inner join int4_tbl as i4 on t1.fivethous = i4.f1 + i8.q2 order by 1, 2 ) diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_hash_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_hash_80.snap index dbe7e9cad..66fcf9b3c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_hash_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__join_hash_80.snap @@ -14,7 +14,7 @@ set local enable_hashjoin = 'on'; create or replace function find_hash(node json) returns json language plpgsql -as $function$ +as $$ declare x json; child json; @@ -32,7 +32,7 @@ begin return null; end if; end; -$function$; +$$; create or replace function hash_join_batches(query text) returns table ( @@ -40,7 +40,7 @@ returns table ( final int ) language plpgsql -as $function$ +as $$ declare whole_plan json; hash_node json; @@ -54,13 +54,11 @@ begin return next; end loop; end; -$function$; +$$; create table simple as - select - generate_series(1, 20000) as id, - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; + select generate_series(1, 20000) as id, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; alter table simple set (parallel_workers = 2); @@ -69,9 +67,7 @@ analyze simple; create table bigger_than_it_looks as - select - generate_series(1, 20000) as id, - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; + select generate_series(1, 20000) as id, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; alter table bigger_than_it_looks set (autovacuum_enabled = 'false'); @@ -105,16 +101,13 @@ from update pg_class set reltuples = 2, -relpages = pg_relation_size('extremely_skewed') / -8192 +relpages = pg_relation_size('extremely_skewed') / 8192 where relname = 'extremely_skewed'; create table wide as - select - generate_series(1, 2) as id, - rpad('', 320000, 'x') as t; + select generate_series(1, 2) as id, rpad('', 320000, 'x') as t; alter table wide set (parallel_workers = 2); @@ -127,19 +120,17 @@ set local work_mem = '4MB'; set local hash_mem_multiplier = 1.0; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -153,19 +144,17 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = off; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -179,19 +168,17 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = 'on'; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -203,19 +190,17 @@ set local work_mem = '128kB'; set local hash_mem_multiplier = 1.0; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -229,19 +214,17 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = off; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; @@ -255,21 +238,19 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = 'on'; -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); -select COUNT(*) from simple as r inner join simple as s using ("id"); +select count(*) from simple as r inner join simple as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); rollback to savepoint settings; @@ -282,30 +263,22 @@ set local work_mem = '128kB'; set local hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from - simple as r - inner join - bigger_than_it_looks as s - using ("id"); + simple as r inner join bigger_than_it_looks as s using (id); select - COUNT(*) + count(*) from - simple as r - inner join - bigger_than_it_looks as s - using ("id"); + simple as r inner join bigger_than_it_looks as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) FROM simple r JOIN bigger_than_it_looks s USING (id); -' - ); +'); rollback to savepoint settings; @@ -320,30 +293,22 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = off; select - COUNT(*) + count(*) from - simple as r - inner join - bigger_than_it_looks as s - using ("id"); + simple as r inner join bigger_than_it_looks as s using (id); select - COUNT(*) + count(*) from - simple as r - inner join - bigger_than_it_looks as s - using ("id"); + simple as r inner join bigger_than_it_looks as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join bigger_than_it_looks s using (id); -' - ); +'); rollback to savepoint settings; @@ -358,30 +323,22 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = 'on'; select - COUNT(*) + count(*) from - simple as r - inner join - bigger_than_it_looks as s - using ("id"); + simple as r inner join bigger_than_it_looks as s using (id); select - COUNT(*) + count(*) from - simple as r - inner join - bigger_than_it_looks as s - using ("id"); + simple as r inner join bigger_than_it_looks as s using (id); select original > 1 as initially_multibatch, final > original as increased_batches from - hash_join_batches( - ' + hash_join_batches(' select count(*) from simple r join bigger_than_it_looks s using (id); -' - ); +'); rollback to savepoint settings; @@ -393,18 +350,13 @@ set local work_mem = '128kB'; set local hash_mem_multiplier = 1.0; -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select - * -from - hash_join_batches( - ' +select * from hash_join_batches(' select count(*) from simple r join extremely_skewed s using (id); -' - ); +'); rollback to savepoint settings; @@ -418,18 +370,13 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = off; -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select - * -from - hash_join_batches( - ' +select * from hash_join_batches(' select count(*) from simple r join extremely_skewed s using (id); -' - ); +'); rollback to savepoint settings; @@ -443,18 +390,13 @@ set local hash_mem_multiplier = 1.0; set local enable_parallel_hash = 'on'; -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select COUNT(*) from simple as r inner join extremely_skewed as s using ("id"); +select count(*) from simple as r inner join extremely_skewed as s using (id); -select - * -from - hash_join_batches( - ' +select * from hash_join_batches(' select count(*) from simple r join extremely_skewed s using (id); -' - ); +'); rollback to savepoint settings; @@ -468,31 +410,22 @@ set local hash_mem_multiplier = 1.0; set local parallel_leader_participation = off; -select - * -from - hash_join_batches( - ' +select * from hash_join_batches(' select count(*) from simple r join simple s using (id); -' - ); +'); rollback to savepoint settings; create table join_foo as - select - generate_series(1, 3) as id, - cast('xxxxx' as text) as t; + select generate_series(1, 3) as id, cast('xxxxx' as text) as t; alter table join_foo set (parallel_workers = 0); create table join_bar as - select - generate_series(1, 10000) as id, - cast('xxxxx' as text) as t; + select generate_series(1, 10000) as id, cast('xxxxx' as text) as t; alter table join_bar set (parallel_workers = 2); @@ -520,7 +453,7 @@ set work_mem = '64kB'; set hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from join_foo left outer join @@ -529,17 +462,13 @@ from b1.id, b1.t from - join_bar as b1 - inner join - join_bar as b2 - using ("id") + join_bar as b1 inner join join_bar as b2 using (id) ) as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; select - COUNT(*) + count(*) from join_foo left outer join @@ -548,25 +477,16 @@ from b1.id, b1.t from - join_bar as b1 - inner join - join_bar as b2 - using ("id") + join_bar as b1 inner join join_bar as b2 using (id) ) as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select count(*) from join_foo left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -' - ); +'); rollback to savepoint settings; @@ -593,7 +513,7 @@ set work_mem = '4MB'; set hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from join_foo left outer join @@ -602,17 +522,13 @@ from b1.id, b1.t from - join_bar as b1 - inner join - join_bar as b2 - using ("id") + join_bar as b1 inner join join_bar as b2 using (id) ) as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; select - COUNT(*) + count(*) from join_foo left outer join @@ -621,25 +537,16 @@ from b1.id, b1.t from - join_bar as b1 - inner join - join_bar as b2 - using ("id") + join_bar as b1 inner join join_bar as b2 using (id) ) as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select count(*) from join_foo left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -' - ); +'); rollback to savepoint settings; @@ -666,7 +573,7 @@ set work_mem = '64kB'; set hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from join_foo left outer join @@ -675,17 +582,13 @@ from b1.id, b1.t from - join_bar as b1 - inner join - join_bar as b2 - using ("id") + join_bar as b1 inner join join_bar as b2 using (id) ) as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; select - COUNT(*) + count(*) from join_foo left outer join @@ -694,25 +597,16 @@ from b1.id, b1.t from - join_bar as b1 - inner join - join_bar as b2 - using ("id") + join_bar as b1 inner join join_bar as b2 using (id) ) as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select count(*) from join_foo left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -' - ); +'); rollback to savepoint settings; @@ -739,7 +633,7 @@ set work_mem = '4MB'; set hash_mem_multiplier = 1.0; select - COUNT(*) + count(*) from join_foo left outer join @@ -748,17 +642,13 @@ from b1.id, b1.t from - join_bar as b1 - inner join - join_bar as b2 - using ("id") + join_bar as b1 inner join join_bar as b2 using (id) ) as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; select - COUNT(*) + count(*) from join_foo left outer join @@ -767,25 +657,16 @@ from b1.id, b1.t from - join_bar as b1 - inner join - join_bar as b2 - using ("id") + join_bar as b1 inner join join_bar as b2 using (id) ) as ss - on join_foo.id < ss.id + 1 and - join_foo.id > ss.id - 1; + on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select count(*) from join_foo left join (select b1.id, b1.t from join_bar b1 join join_bar b2 using (id)) ss on join_foo.id < ss.id + 1 and join_foo.id > ss.id - 1; -' - ); +'); rollback to savepoint settings; @@ -793,9 +674,9 @@ savepoint settings; set local max_parallel_workers_per_gather = 0; -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); rollback to savepoint settings; @@ -805,9 +686,9 @@ set enable_parallel_hash = off; set local max_parallel_workers_per_gather = 2; -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); rollback to savepoint settings; @@ -815,9 +696,9 @@ savepoint settings; set local max_parallel_workers_per_gather = 2; -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); -select COUNT(*) from simple as r full outer join simple as s using ("id"); +select count(*) from simple as r full outer join simple as s using (id); rollback to savepoint settings; @@ -825,9 +706,9 @@ savepoint settings; set local max_parallel_workers_per_gather = 0; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; rollback to savepoint settings; @@ -837,9 +718,9 @@ set enable_parallel_hash = off; set local max_parallel_workers_per_gather = 2; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; rollback to savepoint settings; @@ -847,9 +728,9 @@ savepoint settings; set local max_parallel_workers_per_gather = 2; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; -select COUNT(*) from simple as r full outer join simple as s on r.id = 0 - s.id; +select count(*) from simple as r full outer join simple as s on r.id = 0 - s.id; rollback to savepoint settings; @@ -864,44 +745,25 @@ set work_mem = '128kB'; set hash_mem_multiplier = 1.0; select - length(MAX(s.t)) + length(max(s.t)) from wide left outer join - ( - select - id, - coalesce(t, '') || '' as t - from - wide - ) - as s - using ("id"); + (select id, coalesce(t, '') || '' as t from wide) as s + using (id); select - length(MAX(s.t)) + length(max(s.t)) from wide left outer join - ( - select - id, - coalesce(t, '') || '' as t - from - wide - ) - as s - using ("id"); + (select id, coalesce(t, '') || '' as t from wide) as s + using (id); -select - final > 1 as multibatch -from - hash_join_batches( - ' +select final > 1 as multibatch from hash_join_batches(' select length(max(s.t)) from wide left join (select id, coalesce(t, '''') || '''' as t from wide) s using (id); -' - ); +'); rollback to savepoint settings; @@ -960,11 +822,11 @@ create table hjtest_1 ( a text, b int, id int, - c boolean + c bool ); create table hjtest_2 ( - a boolean, + a bool, id int, b text, c int @@ -991,18 +853,14 @@ insert into hjtest_2 (a, id, b, c) values (true, 1, 'text', 1); select hjtest_1.a as a1, hjtest_2.a as a2, - cast(hjtest_1.tableoid as regclass) - as t1, - cast(hjtest_2.tableoid as regclass) - as t2 + cast(hjtest_1.tableoid as regclass) as t1, + cast(hjtest_2.tableoid as regclass) as t2 from hjtest_1, hjtest_2 where - hjtest_1.id = - (select 1 where hjtest_2.id = 1) and - (select hjtest_1.b * 5) = - (select hjtest_2.c * 5) and + hjtest_1.id = (select 1 where hjtest_2.id = 1) and + (select hjtest_1.b * 5) = (select hjtest_2.c * 5) and (select hjtest_1.b * 5) < 50 and (select hjtest_2.c * 5) < 55 and hjtest_1.a <> hjtest_2.b; @@ -1010,18 +868,14 @@ where select hjtest_1.a as a1, hjtest_2.a as a2, - cast(hjtest_1.tableoid as regclass) - as t1, - cast(hjtest_2.tableoid as regclass) - as t2 + cast(hjtest_1.tableoid as regclass) as t1, + cast(hjtest_2.tableoid as regclass) as t2 from hjtest_1, hjtest_2 where - hjtest_1.id = - (select 1 where hjtest_2.id = 1) and - (select hjtest_1.b * 5) = - (select hjtest_2.c * 5) and + hjtest_1.id = (select 1 where hjtest_2.id = 1) and + (select hjtest_1.b * 5) = (select hjtest_2.c * 5) and (select hjtest_1.b * 5) < 50 and (select hjtest_2.c * 5) < 55 and hjtest_1.a <> hjtest_2.b; @@ -1029,18 +883,14 @@ where select hjtest_1.a as a1, hjtest_2.a as a2, - cast(hjtest_1.tableoid as regclass) - as t1, - cast(hjtest_2.tableoid as regclass) - as t2 + cast(hjtest_1.tableoid as regclass) as t1, + cast(hjtest_2.tableoid as regclass) as t2 from hjtest_2, hjtest_1 where - hjtest_1.id = - (select 1 where hjtest_2.id = 1) and - (select hjtest_1.b * 5) = - (select hjtest_2.c * 5) and + hjtest_1.id = (select 1 where hjtest_2.id = 1) and + (select hjtest_1.b * 5) = (select hjtest_2.c * 5) and (select hjtest_1.b * 5) < 50 and (select hjtest_2.c * 5) < 55 and hjtest_1.a <> hjtest_2.b; @@ -1048,18 +898,14 @@ where select hjtest_1.a as a1, hjtest_2.a as a2, - cast(hjtest_1.tableoid as regclass) - as t1, - cast(hjtest_2.tableoid as regclass) - as t2 + cast(hjtest_1.tableoid as regclass) as t1, + cast(hjtest_2.tableoid as regclass) as t2 from hjtest_2, hjtest_1 where - hjtest_1.id = - (select 1 where hjtest_2.id = 1) and - (select hjtest_1.b * 5) = - (select hjtest_2.c * 5) and + hjtest_1.id = (select 1 where hjtest_2.id = 1) and + (select hjtest_1.b * 5) = (select hjtest_2.c * 5) and (select hjtest_1.b * 5) < 50 and (select hjtest_2.c * 5) < 55 and hjtest_1.a <> hjtest_2.b; @@ -1080,10 +926,7 @@ from t1.fivethous, i4.f1 from - tenk1 as t1 - inner join - int4_tbl as i4 - on t1.fivethous = i4.f1 + i8.q2 + tenk1 as t1 inner join int4_tbl as i4 on t1.fivethous = i4.f1 + i8.q2 order by 1, 2 ) @@ -1099,10 +942,7 @@ from t1.fivethous, i4.f1 from - tenk1 as t1 - inner join - int4_tbl as i4 - on t1.fivethous = i4.f1 + i8.q2 + tenk1 as t1 inner join int4_tbl as i4 on t1.fivethous = i4.f1 + i8.q2 order by 1, 2 ) diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_100.snap index 6c4a6c8f4..acdf16390 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_100.snap @@ -26,11 +26,7 @@ select cast(row_to_json(j) as jsonb) from ( - select - left('abcdefghijklmnopqrstuv" wxyz012345678', a) - as a - from - generate_series(0, 37) as a + select left('abcdefghijklmnopqrstuv" wxyz012345678', a) as a from generate_series(0, 37) as a ) as j; @@ -122,20 +118,16 @@ select cast('{ "three": true}' as json); -select - cast('{ +select cast('{ "one": 1, "two":,"two", -- ERROR extraneous comma before field "two" "three": - true}' - as json); + true}' as json); -select - cast('{ +select cast('{ "one": 1, "two":"two", - "averyveryveryveryveryveryveryveryveryverylongfieldname":}' - as json); + "averyveryveryveryveryveryveryveryveryverylongfieldname":}' as json); select pg_input_is_valid('{"a":true}', 'json'); @@ -148,26 +140,12 @@ select array_to_json(array(select 1 as a)); select array_to_json(array_agg(q), false) from - ( - select - x as b, - x * 2 as c - from - generate_series(1, 3) as x - ) - as q; + (select x as b, x * 2 as c from generate_series(1, 3) as x) as q; select array_to_json(array_agg(q), true) from - ( - select - x as b, - x * 2 as c - from - generate_series(1, 3) as x - ) - as q; + (select x as b, x * 2 as c from generate_series(1, 3) as x) as q; select array_to_json(array_agg(q), false) @@ -176,9 +154,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -198,9 +174,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -214,9 +188,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -237,10 +209,7 @@ select from pg_stats where - tablename = 'rows' and - schemaname = - cast(cast(pg_my_temp_schema() as regnamespace) - as text) + tablename = 'rows' and schemaname = cast(cast(pg_my_temp_schema() as regnamespace) as text) order by 1; select to_json(cast('2014-05-28 12:22:35.614298' as timestamp)); @@ -249,11 +218,11 @@ begin; set local time zone 10.5; -select to_json(cast('2014-05-28 12:22:35.614298-04' as timestamp with time zone)); +select to_json(cast('2014-05-28 12:22:35.614298-04' as timestamptz)); set local time zone -8; -select to_json(cast('2014-05-28 12:22:35.614298-04' as timestamp with time zone)); +select to_json(cast('2014-05-28 12:22:35.614298-04' as timestamptz)); commit; @@ -267,9 +236,9 @@ select to_json(cast('Infinity' as timestamp)); select to_json(cast('-Infinity' as timestamp)); -select to_json(cast('Infinity' as timestamp with time zone)); +select to_json(cast('Infinity' as timestamptz)); -select to_json(cast('-Infinity' as timestamp with time zone)); +select to_json(cast('-Infinity' as timestamptz)); select json_agg(q) @@ -278,9 +247,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -293,22 +260,16 @@ update rows set x = null where x = 1; select json_agg(q order by x nulls first, y) from rows as q; -select row_to_json(q) from (select cast('NaN' as double precision) as float8field) as q; +select row_to_json(q) from (select cast('NaN' as float8) as float8field) as q; -select row_to_json(q) from (select cast('Infinity' as double precision) as float8field) as q; +select row_to_json(q) from (select cast('Infinity' as float8) as float8field) as q; -select row_to_json(q) from (select cast('-Infinity' as double precision) as float8field) as q; +select row_to_json(q) from (select cast('-Infinity' as float8) as float8field) as q; select row_to_json(q) from - ( - select - cast('{"a":1,"b": [2,3,4,"d","e","f"],"c":{"p":1,"q":2}}' - as json) - as jsonfield - ) - as q; + (select cast('{"a":1,"b": [2,3,4,"d","e","f"],"c":{"p":1,"q":2}}' as json) as jsonfield) as q; create temporary table test_json ( json_type text, @@ -318,10 +279,7 @@ create temporary table test_json ( insert into test_json values ('scalar', '"a scalar"'), - ( - 'array', - '["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]' - ), + ('array', '["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), ( 'object', '{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}' @@ -364,19 +322,13 @@ select json_object_keys(test_json) from test_json where json_type = 'array'; select json_object_keys(test_json) from test_json where json_type = 'object'; select - COUNT(*) + count(*) from ( select json_object_keys(json_object(array_agg(g))) from - ( - select - unnest(array['f' || n, cast(n as text)]) as g - from - generate_series(1, 300) as n - ) - as x + (select unnest(array['f' || n, cast(n as text)]) as g from generate_series(1, 300) as n) as x ) as y; @@ -463,44 +415,23 @@ select json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}', ' select json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}', 'f2'); select - json_extract_path_text( - '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}', - 'f2', - cast(0 as text) - ); + json_extract_path_text('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}', 'f2', cast(0 as text)); select - json_extract_path_text( - '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}', - 'f2', - cast(1 as text) - ); + json_extract_path_text('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}', 'f2', cast(1 as text)); select - json_extract_path( - '{"f2":{"f3":1},"f4":{"f5":null,"f6":"stringy"}}', - 'f4', - 'f5' - ) is null + json_extract_path('{"f2":{"f3":1},"f4":{"f5":null,"f6":"stringy"}}', 'f4', 'f5') is null as expect_false; select - json_extract_path_text( - '{"f2":{"f3":1},"f4":{"f5":null,"f6":"stringy"}}', - 'f4', - 'f5' - ) is null + json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":null,"f6":"stringy"}}', 'f4', 'f5') is null as expect_true; select json_extract_path('{"f2":{"f3":1},"f4":[0,1,2,null]}', 'f4', '3') is null as expect_false; select - json_extract_path_text( - '{"f2":{"f3":1},"f4":[0,1,2,null]}', - 'f4', - '3' - ) is null - as expect_true; + json_extract_path_text('{"f2":{"f3":1},"f4":[0,1,2,null]}', 'f4', '3') is null as expect_true; select cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as json) #> array['f4', 'f6']; @@ -603,20 +534,14 @@ select json_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false," select * from - json_array_elements( - '[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]' - ) - as q; + json_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]') as q; select json_array_elements_text('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]'); select * from - json_array_elements_text( - '[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]' - ) - as q; + json_array_elements_text('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]') as q; create type jpop as (a text, b int, c timestamp); @@ -657,10 +582,7 @@ select * from json_populate_record(cast(null as jpop), '{"a":"blurfl","x":43.2}' select * from - json_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') as jpop), - '{"a":"blurfl","x":43.2}' - ) + json_populate_record(cast(row('x', 3, '2012-12-31 15:30:56') as jpop), '{"a":"blurfl","x":43.2}') as q; select * from json_populate_record(cast(null as jpop), '{"a":"blurfl","x":43.2}') as q; @@ -668,10 +590,7 @@ select * from json_populate_record(cast(null as jpop), '{"a":"blurfl","x":43.2}' select * from - json_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') as jpop), - '{"a":"blurfl","x":43.2}' - ) + json_populate_record(cast(row('x', 3, '2012-12-31 15:30:56') as jpop), '{"a":"blurfl","x":43.2}') as q; select * from json_populate_record(cast(null as jpop), '{"a":[100,200,false],"x":43.2}') as q; @@ -747,11 +666,7 @@ select ia2d from json_populate_record(cast(null as jsrec), '{"ia2d": [[1, "2"], select ia2d from - json_populate_record( - cast(null as jsrec), - '{"ia2d": [[1, "2", 3], [null, 5, 6]]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia2d": [[1, "2", 3], [null, 5, 6]]}') as q; select ia3 from json_populate_record(cast(null as jsrec), '{"ia3": [1, "2", null, 4]}') as q; @@ -760,22 +675,14 @@ select ia3 from json_populate_record(cast(null as jsrec), '{"ia3": [[1, 2], [nul select ia3 from - json_populate_record( - cast(null as jsrec), - '{"ia3": [ [[], []], [[], []], [[], []] ]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia3": [ [[], []], [[], []], [[], []] ]}') as q; select ia3 from json_populate_record(cast(null as jsrec), '{"ia3": [ [[1, 2]], [[3, 4]] ]}') as q; select ia3 from - json_populate_record( - cast(null as jsrec), - '{"ia3": [ [[1, 2], [3, 4]], [[5, 6], [7, 8]] ]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia3": [ [[1, 2], [3, 4]], [[5, 6], [7, 8]] ]}') as q; select ia3 @@ -825,20 +732,12 @@ select js from json_populate_record(cast(null as jsrec), '{"js": "abc"}') as q; select js from - json_populate_record( - cast(null as jsrec), - '{"js": [123, "123", null, {"key": "value"}]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"js": [123, "123", null, {"key": "value"}]}') as q; select js from - json_populate_record( - cast(null as jsrec), - '{"js": {"a": "bbb", "b": null, "c": 123.45}}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"js": {"a": "bbb", "b": null, "c": 123.45}}') as q; select jsb from json_populate_record(cast(null as jsrec), '{"jsb": null}') as q; @@ -853,20 +752,12 @@ select jsb from json_populate_record(cast(null as jsrec), '{"jsb": "abc"}') as q select jsb from - json_populate_record( - cast(null as jsrec), - '{"jsb": [123, "123", null, {"key": "value"}]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"jsb": [123, "123", null, {"key": "value"}]}') as q; select jsb from - json_populate_record( - cast(null as jsrec), - '{"jsb": {"a": "bbb", "b": null, "c": 123.45}}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"jsb": {"a": "bbb", "b": null, "c": 123.45}}') as q; select jsa from json_populate_record(cast(null as jsrec), '{"jsa": null}') as q; @@ -890,10 +781,7 @@ select rec from json_populate_record(cast(null as jsrec), '{"rec": [1, 2]}') as select rec from - json_populate_record( - cast(null as jsrec), - '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}' - ) + json_populate_record(cast(null as jsrec), '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}') as q; select rec from json_populate_record(cast(null as jsrec), '{"rec": "(abc,42,01.02.2003)"}') as q; @@ -914,42 +802,36 @@ from select reca from - json_populate_record( - cast(null as jsrec), - '{"reca": ["(abc,42,01.02.2003)"]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"reca": ["(abc,42,01.02.2003)"]}') as q; select reca from - json_populate_record( - cast(null as jsrec), - '{"reca": "{\"(abc,42,01.02.2003)\"}"}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"reca": "{\"(abc,42,01.02.2003)\"}"}') as q; select rec from json_populate_record( - cast(row(null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - cast(row('x', 3, '2012-12-31 15:30:56') as jpop), - null) + cast(row( + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + cast(row('x', 3, '2012-12-31 15:30:56') as jpop), + null + ) as jsrec), '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}' ) @@ -1026,11 +908,7 @@ create type jpop2 as (a int, b json, c int, d int); select * from - json_populate_recordset( - cast(null as jpop2), - '[{"a":2,"c":3,"b":{"z":4},"d":6}]' - ) - as q; + json_populate_recordset(cast(null as jpop2), '[{"a":2,"c":3,"b":{"z":4},"d":6}]') as q; select * @@ -1065,10 +943,7 @@ select json_populate_recordset(row(1, 2), '[{"f1": 0, "f2": 1}]'); select i, - json_populate_recordset( - row(i, 50), - '[{"f1":"42"},{"f2":"43"}]' - ) + json_populate_recordset(row(i, 50), '[{"f1":"42"},{"f2":"43"}]') from (values (1), (2)) as v (i); @@ -1091,20 +966,14 @@ select json_populate_recordset(cast(row(1, 2) as j_ordered_pair), '[{"x": 1, "y" select * from - json_populate_recordset( - row(cast(0 as int)), - '[{"a":"1","b":"2"},{"a":"3"}]' - ) + json_populate_recordset(row(cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]') as q (a text, b text); select * from - json_populate_recordset( - row(cast(0 as int), cast(0 as int)), - '[{"a":"1","b":"2"},{"a":"3"}]' - ) + json_populate_recordset(row(cast(0 as int), cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]') as q (a text, b text); @@ -1112,9 +981,7 @@ select * from json_populate_recordset( - row(cast(0 as int), - cast(0 as int), - cast(0 as int)), + row(cast(0 as int), cast(0 as int), cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]' ) as q @@ -1123,25 +990,17 @@ from select * from - json_populate_recordset( - row(cast(1000000000 as int), cast(50 as int)), - '[{"b":"2"},{"a":"3"}]' - ) + json_populate_recordset(row(cast(1000000000 as int), cast(50 as int)), '[{"b":"2"},{"a":"3"}]') as q (a text, b text); create temporary table jspoptest (js json); -insert into jspoptest -select - cast('{ +insert into jspoptest select cast('{ "jsa": [1, "2", null, 4], "rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}, "reca": [{"a": "abc", "b": 456}, null, {"c": "01.02.2003", "x": 43.2}] -}' - as json) -from - generate_series(1, 3); +}' as json) from generate_series(1, 3); select (json_populate_record(cast(null as jsrec), js)).* from jspoptest; @@ -1230,13 +1089,7 @@ select row_to_json(r) from ( - select - relkind, - cast(oid as regclass) as name - from - pg_class - where - relname = 'pg_class' + select relkind, cast(oid as regclass) as name from pg_class where relname = 'pg_class' ) as r ) @@ -1347,18 +1200,14 @@ select * from json_to_record('{"a":1,"b":"foo","c":"bar"}') as x (a int, b text, select * from - json_to_recordset( - '[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]' - ) + json_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]') as x (a int, b text, c boolean); select * from - json_to_recordset( - '[{"a":1,"b":{"d":"foo"},"c":true},{"a":2,"c":false,"b":{"d":"bar"}}]' - ) + json_to_recordset('[{"a":1,"b":{"d":"foo"},"c":true},{"a":2,"c":false,"b":{"d":"bar"}}]') as x (a int, b json, c boolean); @@ -1371,24 +1220,13 @@ from as json) ) as t - ( - a int, - b json, - c text, - x int, - ca char(5)[], - ia int[][], - r jpop - ); + (a int, b json, c text, x int, ca char(5)[], ia int[][], r jpop); select *, c is null as c_is_null from - json_to_recordset( - cast('[{"a":1, "b":{"c":16, "d":2}, "x":8}]' - as json) - ) + json_to_recordset(cast('[{"a":1, "b":{"c":16, "d":2}, "x":8}]' as json)) as t (a int, b json, c text, x int); @@ -1406,9 +1244,9 @@ select * from json_to_record('{"ia": [[1], [2, 3]]}') as x (ia _int4); select * from json_to_record('{"ia2": [1, 2, 3]}') as x (ia2 int[][]); -select * from json_to_record('{"ia2": [[1, 2], [3, 4]]}') as x (ia2 int[][]); +select * from json_to_record('{"ia2": [[1, 2], [3, 4]]}') as x (ia2 int4[][]); -select * from json_to_record('{"ia2": [[[1], [2], [3]]]}') as x (ia2 int[][]); +select * from json_to_record('{"ia2": [[[1], [2], [3]]]}') as x (ia2 int4[][]); select * from json_to_record('{"out": {"key": 1}}') as x (out json); @@ -1456,22 +1294,19 @@ select json_strip_nulls('{"a": {"b": null, "c": null}, "d": {} }', true); select to_tsvector( - cast('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' - as json) + cast('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' as json) ); select to_tsvector( 'simple', - cast('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' - as json) + cast('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' as json) ); select to_tsvector( 'english', - cast('{"a": "aaa in bbb ddd ccc", "b": ["the eee fff ggg"], "c": {"d": "hhh. iii"}}' - as json) + cast('{"a": "aaa in bbb ddd ccc", "b": ["the eee fff ggg"], "c": {"d": "hhh. iii"}}' as json) ); select to_tsvector('english', cast('{"a": "aaa in bbb ddd ccc", "b": 123, "c": 456}' as json)); @@ -1479,96 +1314,84 @@ select to_tsvector('english', cast('{"a": "aaa in bbb ddd ccc", "b": 123, "c": 4 select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"all"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"key"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"string"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"numeric"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"boolean"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '["string", "numeric"]' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"all"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"key"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"string"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"numeric"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '"boolean"' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '["string", "numeric"]' ); @@ -1591,40 +1414,35 @@ select json_to_tsvector(cast('null' as json), '"all"'); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '""' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '{}' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '[]' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), 'null' ); select json_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as json), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as json), '["all", null]' ); @@ -1638,8 +1456,7 @@ select select ts_headline( 'english', - cast('{"a": "aaa bbb", "b": {"c": "ccc ddd fff"}, "d": ["ggg hhh", "iii jjj"]}' - as json), + cast('{"a": "aaa bbb", "b": {"c": "ccc ddd fff"}, "d": ["ggg hhh", "iii jjj"]}' as json), tsquery('bbb & ddd & hhh') ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_80.snap index b406cdf1d..d7db8f001 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_80.snap @@ -27,11 +27,7 @@ select from ( select - left( - 'abcdefghijklmnopqrstuv" wxyz012345678', - a - ) - as a + left('abcdefghijklmnopqrstuv" wxyz012345678', a) as a from generate_series(0, 37) as a ) @@ -125,20 +121,16 @@ select cast('{ "three": true}' as json); -select - cast('{ +select cast('{ "one": 1, "two":,"two", -- ERROR extraneous comma before field "two" "three": - true}' - as json); + true}' as json); -select - cast('{ +select cast('{ "one": 1, "two":"two", - "averyveryveryveryveryveryveryveryveryverylongfieldname":}' - as json); + "averyveryveryveryveryveryveryveryveryverylongfieldname":}' as json); select pg_input_is_valid('{"a":true}', 'json'); @@ -151,26 +143,12 @@ select array_to_json(array(select 1 as a)); select array_to_json(array_agg(q), false) from - ( - select - x as b, - x * 2 as c - from - generate_series(1, 3) as x - ) - as q; + (select x as b, x * 2 as c from generate_series(1, 3) as x) as q; select array_to_json(array_agg(q), true) from - ( - select - x as b, - x * 2 as c - from - generate_series(1, 3) as x - ) - as q; + (select x as b, x * 2 as c from generate_series(1, 3) as x) as q; select array_to_json(array_agg(q), false) @@ -179,9 +157,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -201,9 +177,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -217,9 +191,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -228,22 +200,13 @@ from create temporary table rows as - select - x, - 'txt' || x as y - from - generate_series(1, 3) as x; + select x, 'txt' || x as y from generate_series(1, 3) as x; select row_to_json(q, true) from rows as q; select row_to_json( - row(( - select - array_agg(x) as d - from - generate_series(5, 10) as x - )), + row((select array_agg(x) as d from generate_series(5, 10) as x)), false ); @@ -251,16 +214,12 @@ analyze rows; select attname, - to_json(histogram_bounds) - as histogram_bounds + to_json(histogram_bounds) as histogram_bounds from pg_stats where tablename = 'rows' and - schemaname = - cast(cast(pg_my_temp_schema() - as regnamespace) - as text) + schemaname = cast(cast(pg_my_temp_schema() as regnamespace) as text) order by 1; select to_json(cast('2014-05-28 12:22:35.614298' as timestamp)); @@ -269,19 +228,11 @@ begin; set local time zone 10.5; -select - to_json( - cast('2014-05-28 12:22:35.614298-04' - as timestamp with time zone) - ); +select to_json(cast('2014-05-28 12:22:35.614298-04' as timestamptz)); set local time zone -8; -select - to_json( - cast('2014-05-28 12:22:35.614298-04' - as timestamp with time zone) - ); +select to_json(cast('2014-05-28 12:22:35.614298-04' as timestamptz)); commit; @@ -295,9 +246,9 @@ select to_json(cast('Infinity' as timestamp)); select to_json(cast('-Infinity' as timestamp)); -select to_json(cast('Infinity' as timestamp with time zone)); +select to_json(cast('Infinity' as timestamptz)); -select to_json(cast('-Infinity' as timestamp with time zone)); +select to_json(cast('-Infinity' as timestamptz)); select json_agg(q) @@ -306,9 +257,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -321,43 +270,24 @@ update rows set x = null where x = 1; select json_agg(q order by x nulls first, y) from rows as q; -select - row_to_json(q) -from - ( - select - cast('NaN' as double precision) - as float8field - ) - as q; +select row_to_json(q) from (select cast('NaN' as float8) as float8field) as q; select row_to_json(q) from - ( - select - cast('Infinity' as double precision) - as float8field - ) - as q; + (select cast('Infinity' as float8) as float8field) as q; select row_to_json(q) from - ( - select - cast('-Infinity' as double precision) - as float8field - ) - as q; + (select cast('-Infinity' as float8) as float8field) as q; select row_to_json(q) from ( select - cast('{"a":1,"b": [2,3,4,"d","e","f"],"c":{"p":1,"q":2}}' - as json) + cast('{"a":1,"b": [2,3,4,"d","e","f"],"c":{"p":1,"q":2}}' as json) as jsonfield ) as q; @@ -370,10 +300,7 @@ create temporary table test_json ( insert into test_json values ('scalar', '"a scalar"'), - ( - 'array', - '["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]' - ), + ('array', '["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), ( 'object', '{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}' @@ -416,18 +343,15 @@ select json_object_keys(test_json) from test_json where json_type = 'array'; select json_object_keys(test_json) from test_json where json_type = 'object'; select - COUNT(*) + count(*) from ( select - json_object_keys( - json_object(array_agg(g)) - ) + json_object_keys(json_object(array_agg(g))) from ( select - unnest(array['f' || n, cast(n as text)]) - as g + unnest(array['f' || n, cast(n as text)]) as g from generate_series(1, 300) as n ) @@ -436,16 +360,14 @@ from as y; select - test_json -> 'field3' is null - as expect_false + test_json -> 'field3' is null as expect_false from test_json where json_type = 'object'; select - test_json ->> 'field3' is null - as expect_true + test_json ->> 'field3' is null as expect_true from test_json where @@ -524,9 +446,7 @@ select json_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null}'); select * from - json_each( - '{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}' - ) + json_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') as q; select json_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":"null"}'); @@ -570,10 +490,7 @@ select ); select - json_extract_path_text( - '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}', - 'f2' - ); + json_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}', 'f2'); select json_extract_path_text( @@ -606,59 +523,41 @@ select as expect_true; select - json_extract_path( - '{"f2":{"f3":1},"f4":[0,1,2,null]}', - 'f4', - '3' - ) is null + json_extract_path('{"f2":{"f3":1},"f4":[0,1,2,null]}', 'f4', '3') is null as expect_false; select - json_extract_path_text( - '{"f2":{"f3":1},"f4":[0,1,2,null]}', - 'f4', - '3' - ) is null + json_extract_path_text('{"f2":{"f3":1},"f4":[0,1,2,null]}', 'f4', '3') is null as expect_true; select - cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' - as json) #> + cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as json) #> array['f4', 'f6']; select - cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' - as json) #> - array['f2']; + cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as json) #> array['f2']; select - cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' - as json) #> + cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' as json) #> array['f2', '0']; select - cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' - as json) #> + cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' as json) #> array['f2', '1']; select - cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' - as json) #>> + cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as json) #>> array['f4', 'f6']; select - cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' - as json) #>> - array['f2']; + cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as json) #>> array['f2']; select - cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' - as json) #>> + cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' as json) #>> array['f2', '0']; select - cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' - as json) #>> + cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' as json) #>> array['f2', '1']; select cast('{"a": {"b":{"c": "foo"}}}' as json) #> '{}'; @@ -726,14 +625,10 @@ select cast('{"a": {"b":{"c": "foo"}}}' as json) #>> array['a', 'b', 'c', 'd']; select cast('{"a": {"b":{"c": "foo"}}}' as json) #>> array['a', 'z', 'c']; select - cast('{"a": [{"b": "c"}, {"b": "cc"}]}' - as json) #>> - array['a', '1', 'b']; + cast('{"a": [{"b": "c"}, {"b": "cc"}]}' as json) #>> array['a', '1', 'b']; select - cast('{"a": [{"b": "c"}, {"b": "cc"}]}' - as json) #>> - array['a', 'z', 'b']; + cast('{"a": [{"b": "c"}, {"b": "cc"}]}' as json) #>> array['a', 'z', 'b']; select cast('[{"b": "c"}, {"b": "cc"}]' as json) #>> array['1', 'b']; @@ -810,18 +705,13 @@ create type jsrec_i_not_null as (i js_int_not_null); select * from - json_populate_record( - cast(null as jpop), - '{"a":"blurfl","x":43.2}' - ) - as q; + json_populate_record(cast(null as jpop), '{"a":"blurfl","x":43.2}') as q; select * from json_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jpop), + cast(row('x', 3, '2012-12-31 15:30:56') as jpop), '{"a":"blurfl","x":43.2}' ) as q; @@ -829,18 +719,13 @@ from select * from - json_populate_record( - cast(null as jpop), - '{"a":"blurfl","x":43.2}' - ) - as q; + json_populate_record(cast(null as jpop), '{"a":"blurfl","x":43.2}') as q; select * from json_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jpop), + cast(row('x', 3, '2012-12-31 15:30:56') as jpop), '{"a":"blurfl","x":43.2}' ) as q; @@ -848,18 +733,14 @@ from select * from - json_populate_record( - cast(null as jpop), - '{"a":[100,200,false],"x":43.2}' - ) + json_populate_record(cast(null as jpop), '{"a":[100,200,false],"x":43.2}') as q; select * from json_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jpop), + cast(row('x', 3, '2012-12-31 15:30:56') as jpop), '{"a":[100,200,false],"x":43.2}' ) as q; @@ -868,8 +749,7 @@ select * from json_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jpop), + cast(row('x', 3, '2012-12-31 15:30:56') as jpop), '{"c":[100,200,false],"x":43.2}' ) as q; @@ -877,39 +757,23 @@ from select * from - json_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jpop), - '{}' - ) + json_populate_record(cast(row('x', 3, '2012-12-31 15:30:56') as jpop), '{}') as q; select i from - json_populate_record( - cast(null as jsrec_i_not_null), - '{"x": 43.2}' - ) - as q; + json_populate_record(cast(null as jsrec_i_not_null), '{"x": 43.2}') as q; select i from - json_populate_record( - cast(null as jsrec_i_not_null), - '{"i": null}' - ) - as q; + json_populate_record(cast(null as jsrec_i_not_null), '{"i": null}') as q; select i from - json_populate_record( - cast(null as jsrec_i_not_null), - '{"i": 12345}' - ) - as q; + json_populate_record(cast(null as jsrec_i_not_null), '{"i": 12345}') as q; select ia from json_populate_record(cast(null as jsrec), '{"ia": null}') as q; @@ -918,47 +782,27 @@ select ia from json_populate_record(cast(null as jsrec), '{"ia": 123}') as q; select ia from - json_populate_record( - cast(null as jsrec), - '{"ia": [1, "2", null, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia": [1, "2", null, 4]}') as q; select ia from - json_populate_record( - cast(null as jsrec), - '{"ia": [[1, 2], [3, 4]]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia": [[1, 2], [3, 4]]}') as q; select ia from - json_populate_record( - cast(null as jsrec), - '{"ia": [[1], 2]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia": [[1], 2]}') as q; select ia from - json_populate_record( - cast(null as jsrec), - '{"ia": [[1], [2, 3]]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia": [[1], [2, 3]]}') as q; select ia from - json_populate_record( - cast(null as jsrec), - '{"ia": "{1,2,3}"}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia": "{1,2,3}"}') as q; select ia1 from json_populate_record(cast(null as jsrec), '{"ia1": null}') as q; @@ -967,109 +811,63 @@ select ia1 from json_populate_record(cast(null as jsrec), '{"ia1": 123}') as q; select ia1 from - json_populate_record( - cast(null as jsrec), - '{"ia1": [1, "2", null, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia1": [1, "2", null, 4]}') as q; select ia1 from - json_populate_record( - cast(null as jsrec), - '{"ia1": [[1, 2, 3]]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia1": [[1, 2, 3]]}') as q; select ia1d from - json_populate_record( - cast(null as jsrec), - '{"ia1d": null}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia1d": null}') as q; select ia1d from - json_populate_record( - cast(null as jsrec), - '{"ia1d": 123}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia1d": 123}') as q; select ia1d from - json_populate_record( - cast(null as jsrec), - '{"ia1d": [1, "2", null, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia1d": [1, "2", null, 4]}') as q; select ia1d from - json_populate_record( - cast(null as jsrec), - '{"ia1d": [1, "2", null]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia1d": [1, "2", null]}') as q; select ia2 from - json_populate_record( - cast(null as jsrec), - '{"ia2": [1, "2", null, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia2": [1, "2", null, 4]}') as q; select ia2 from - json_populate_record( - cast(null as jsrec), - '{"ia2": [[1, 2], [null, 4]]}' - ) + json_populate_record(cast(null as jsrec), '{"ia2": [[1, 2], [null, 4]]}') as q; select ia2 from - json_populate_record( - cast(null as jsrec), - '{"ia2": [[], []]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia2": [[], []]}') as q; select ia2 from - json_populate_record( - cast(null as jsrec), - '{"ia2": [[1, 2], [3]]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia2": [[1, 2], [3]]}') as q; select ia2 from - json_populate_record( - cast(null as jsrec), - '{"ia2": [[1, 2], 3, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia2": [[1, 2], 3, 4]}') as q; select ia2d from - json_populate_record( - cast(null as jsrec), - '{"ia2d": [[1, "2"], [null, 4]]}' - ) + json_populate_record(cast(null as jsrec), '{"ia2d": [[1, "2"], [null, 4]]}') as q; select @@ -1084,19 +882,12 @@ from select ia3 from - json_populate_record( - cast(null as jsrec), - '{"ia3": [1, "2", null, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ia3": [1, "2", null, 4]}') as q; select ia3 from - json_populate_record( - cast(null as jsrec), - '{"ia3": [[1, 2], [null, 4]]}' - ) + json_populate_record(cast(null as jsrec), '{"ia3": [[1, 2], [null, 4]]}') as q; select @@ -1111,10 +902,7 @@ from select ia3 from - json_populate_record( - cast(null as jsrec), - '{"ia3": [ [[1, 2]], [[3, 4]] ]}' - ) + json_populate_record(cast(null as jsrec), '{"ia3": [ [[1, 2]], [[3, 4]] ]}') as q; select @@ -1142,19 +930,12 @@ select ta from json_populate_record(cast(null as jsrec), '{"ta": 123}') as q; select ta from - json_populate_record( - cast(null as jsrec), - '{"ta": [1, "2", null, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ta": [1, "2", null, 4]}') as q; select ta from - json_populate_record( - cast(null as jsrec), - '{"ta": [[1, 2, 3], {"k": "v"}]}' - ) + json_populate_record(cast(null as jsrec), '{"ta": [[1, 2, 3], {"k": "v"}]}') as q; select c from json_populate_record(cast(null as jsrec), '{"c": null}') as q; @@ -1164,20 +945,12 @@ select c from json_populate_record(cast(null as jsrec), '{"c": "aaa"}') as q; select c from - json_populate_record( - cast(null as jsrec), - '{"c": "aaaaaaaaaa"}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"c": "aaaaaaaaaa"}') as q; select c from - json_populate_record( - cast(null as jsrec), - '{"c": "aaaaaaaaaaaaa"}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"c": "aaaaaaaaaaaaa"}') as q; select ca from json_populate_record(cast(null as jsrec), '{"ca": null}') as q; @@ -1186,28 +959,18 @@ select ca from json_populate_record(cast(null as jsrec), '{"ca": 123}') as q; select ca from - json_populate_record( - cast(null as jsrec), - '{"ca": [1, "2", null, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"ca": [1, "2", null, 4]}') as q; select ca from - json_populate_record( - cast(null as jsrec), - '{"ca": ["aaaaaaaaaaaaaaaa"]}' - ) + json_populate_record(cast(null as jsrec), '{"ca": ["aaaaaaaaaaaaaaaa"]}') as q; select ca from - json_populate_record( - cast(null as jsrec), - '{"ca": [[1, 2, 3], {"k": "v"}]}' - ) + json_populate_record(cast(null as jsrec), '{"ca": [[1, 2, 3], {"k": "v"}]}') as q; select js from json_populate_record(cast(null as jsrec), '{"js": null}') as q; @@ -1219,11 +982,7 @@ select js from json_populate_record(cast(null as jsrec), '{"js": 123.45}') as q; select js from - json_populate_record( - cast(null as jsrec), - '{"js": "123.45"}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"js": "123.45"}') as q; select js from json_populate_record(cast(null as jsrec), '{"js": "abc"}') as q; @@ -1252,29 +1011,17 @@ select jsb from json_populate_record(cast(null as jsrec), '{"jsb": true}') as q; select jsb from - json_populate_record( - cast(null as jsrec), - '{"jsb": 123.45}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"jsb": 123.45}') as q; select jsb from - json_populate_record( - cast(null as jsrec), - '{"jsb": "123.45"}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"jsb": "123.45"}') as q; select jsb from - json_populate_record( - cast(null as jsrec), - '{"jsb": "abc"}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"jsb": "abc"}') as q; select jsb @@ -1301,11 +1048,7 @@ select jsa from json_populate_record(cast(null as jsrec), '{"jsa": 123}') as q; select jsa from - json_populate_record( - cast(null as jsrec), - '{"jsa": [1, "2", null, 4]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"jsa": [1, "2", null, 4]}') as q; select jsa @@ -1321,11 +1064,7 @@ select rec from json_populate_record(cast(null as jsrec), '{"rec": 123}') as q; select rec from - json_populate_record( - cast(null as jsrec), - '{"rec": [1, 2]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"rec": [1, 2]}') as q; select rec @@ -1339,29 +1078,18 @@ from select rec from - json_populate_record( - cast(null as jsrec), - '{"rec": "(abc,42,01.02.2003)"}' - ) + json_populate_record(cast(null as jsrec), '{"rec": "(abc,42,01.02.2003)"}') as q; select reca from - json_populate_record( - cast(null as jsrec), - '{"reca": 123}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"reca": 123}') as q; select reca from - json_populate_record( - cast(null as jsrec), - '{"reca": [1, 2]}' - ) - as q; + json_populate_record(cast(null as jsrec), '{"reca": [1, 2]}') as q; select reca @@ -1375,10 +1103,7 @@ from select reca from - json_populate_record( - cast(null as jsrec), - '{"reca": ["(abc,42,01.02.2003)"]}' - ) + json_populate_record(cast(null as jsrec), '{"reca": ["(abc,42,01.02.2003)"]}') as q; select @@ -1394,24 +1119,25 @@ select rec from json_populate_record( - cast(row(null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - cast(row('x', 3, '2012-12-31 15:30:56') - as jpop), - null) + cast(row( + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + cast(row('x', 3, '2012-12-31 15:30:56') as jpop), + null + ) as jsrec), '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}' ) @@ -1424,21 +1150,14 @@ select json_populate_record(row(1, 2), '{"f1": 0, "f2": 1}'); select * from - json_populate_record( - cast(null as record), - '{"x": 776}' - ) as - (x int, y int); + json_populate_record(cast(null as record), '{"x": 776}') as (x int, y int); select json_populate_record(cast(null as j_ordered_pair), '{"x": 0, "y": 1}'); select json_populate_record(cast(row(1, 2) as j_ordered_pair), '{"x": 0}'); select - json_populate_record( - cast(row(1, 2) as j_ordered_pair), - '{"x": 1, "y": 0}' - ); + json_populate_record(cast(row(1, 2) as j_ordered_pair), '{"x": 1, "y": 0}'); select * @@ -1538,20 +1257,14 @@ select json_populate_recordset(row(1, 2), '[{"f1": 0, "f2": 1}]'); select i, - json_populate_recordset( - row(i, 50), - '[{"f1":"42"},{"f2":"43"}]' - ) + json_populate_recordset(row(i, 50), '[{"f1":"42"},{"f2":"43"}]') from (values (1), (2)) as v (i); select * from - json_populate_recordset( - cast(null as record), - '[{"x": 776}]' - ) as + json_populate_recordset(cast(null as record), '[{"x": 776}]') as (x int, y int); select json_populate_recordset(cast(null as record), '[]'); @@ -1563,17 +1276,10 @@ select * from json_populate_recordset(cast(null as jpop), '[]') as q; select * from - json_populate_recordset( - cast(null as record), - '[]' - ) as - (x int, y int); + json_populate_recordset(cast(null as record), '[]') as (x int, y int); select - json_populate_recordset( - cast(null as j_ordered_pair), - '[{"x": 0, "y": 1}]' - ); + json_populate_recordset(cast(null as j_ordered_pair), '[{"x": 0, "y": 1}]'); select json_populate_recordset( @@ -1590,10 +1296,7 @@ select select * from - json_populate_recordset( - row(cast(0 as int)), - '[{"a":"1","b":"2"},{"a":"3"}]' - ) + json_populate_recordset(row(cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]') as q (a text, b text); @@ -1611,9 +1314,7 @@ select * from json_populate_recordset( - row(cast(0 as int), - cast(0 as int), - cast(0 as int)), + row(cast(0 as int), cast(0 as int), cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]' ) as q @@ -1623,8 +1324,7 @@ select * from json_populate_recordset( - row(cast(1000000000 as int), - cast(50 as int)), + row(cast(1000000000 as int), cast(50 as int)), '[{"b":"2"},{"a":"3"}]' ) as q @@ -1632,16 +1332,11 @@ from create temporary table jspoptest (js json); -insert into jspoptest -select - cast('{ +insert into jspoptest select cast('{ "jsa": [1, "2", null, 4], "rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}, "reca": [{"a": "abc", "b": 456}, null, {"c": "01.02.2003", "x": 43.2}] -}' - as json) -from - generate_series(1, 3); +}' as json) from generate_series(1, 3); select (json_populate_record(cast(null as jsrec), js)).* from jspoptest; @@ -1798,13 +1493,7 @@ insert into foo values (847003, 'sub-alpha', 'GESS90'); select json_build_object( 'turbines', - json_object_agg( - serial_num, - json_build_object( - 'name', name, - 'type', type - ) - ) + json_object_agg(serial_num, json_build_object('name', name, 'type', type)) ) from foo; @@ -1852,18 +1541,12 @@ select json_object_agg_unique(mod(i, 100), i) from generate_series(0, 199) as i; select * from - json_to_record( - '{"a":1,"b":"foo","c":"bar"}' - ) - as x - (a int, b text, d text); + json_to_record('{"a":1,"b":"foo","c":"bar"}') as x (a int, b text, d text); select * from - json_to_recordset( - '[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]' - ) + json_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]') as x (a int, b text, c boolean); @@ -1885,24 +1568,13 @@ from as json) ) as t - ( - a int, - b json, - c text, - x int, - ca char(5)[], - ia int[][], - r jpop - ); + (a int, b json, c text, x int, ca char(5)[], ia int[][], r jpop); select *, c is null as c_is_null from - json_to_recordset( - cast('[{"a":1, "b":{"c":16, "d":2}, "x":8}]' - as json) - ) + json_to_recordset(cast('[{"a":1, "b":{"c":16, "d":2}, "x":8}]' as json)) as t (a int, b json, c text, x int); @@ -1920,9 +1592,9 @@ select * from json_to_record('{"ia": [[1], [2, 3]]}') as x (ia _int4); select * from json_to_record('{"ia2": [1, 2, 3]}') as x (ia2 int[][]); -select * from json_to_record('{"ia2": [[1, 2], [3, 4]]}') as x (ia2 int[][]); +select * from json_to_record('{"ia2": [[1, 2], [3, 4]]}') as x (ia2 int4[][]); -select * from json_to_record('{"ia2": [[[1], [2], [3]]]}') as x (ia2 int[][]); +select * from json_to_record('{"ia2": [[[1], [2], [3]]]}') as x (ia2 int4[][]); select * from json_to_record('{"out": {"key": 1}}') as x (out json); @@ -1995,8 +1667,7 @@ select select to_tsvector( 'english', - cast('{"a": "aaa in bbb ddd ccc", "b": 123, "c": 456}' - as json) + cast('{"a": "aaa in bbb ddd ccc", "b": 123, "c": 456}' as json) ); select diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_encoding_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_encoding_100.snap index 1ee7e191f..284f89758 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_encoding_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_encoding_100.snap @@ -60,12 +60,7 @@ select cast('"\u0000"' as jsonb); select octet_length(cast(cast('"\uaBcD"' as jsonb) as text)); select - octet_length( - cast(cast('{ "a": "\ud83d\ude04\ud83d\udc36" }' - as jsonb) -> - 'a' - as text) - ) + octet_length(cast(cast('{ "a": "\ud83d\ude04\ud83d\udc36" }' as jsonb) -> 'a' as text)) as correct_in_utf8; select cast('{ "a": "\ud83d\ud83d" }' as jsonb) -> 'a'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_encoding_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_encoding_80.snap index e46670370..c265a61ae 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_encoding_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__json_encoding_80.snap @@ -18,9 +18,7 @@ select cast('"\u0000"' as json); select cast('"\uaBcD"' as json); select - cast('{ "a": "\ud83d\ude04\ud83d\udc36" }' - as json) -> - 'a' + cast('{ "a": "\ud83d\ude04\ud83d\udc36" }' as json) -> 'a' as correct_in_utf8; select cast('{ "a": "\ud83d\ud83d" }' as json) -> 'a'; @@ -34,9 +32,7 @@ select cast('{ "a": "\ude04X" }' as json) -> 'a'; select cast('{ "a": "the Copyright \u00a9 sign" }' as json) as correct_in_utf8; select - cast('{ "a": "dollar \u0024 character" }' - as json) - as correct_everywhere; + cast('{ "a": "dollar \u0024 character" }' as json) as correct_everywhere; select cast('{ "a": "dollar \\u0024 character" }' as json) as not_an_escape; @@ -45,22 +41,15 @@ select cast('{ "a": "null \u0000 escape" }' as json) as not_unescaped; select cast('{ "a": "null \\u0000 escape" }' as json) as not_an_escape; select - cast('{ "a": "the Copyright \u00a9 sign" }' - as json) ->> - 'a' + cast('{ "a": "the Copyright \u00a9 sign" }' as json) ->> 'a' as correct_in_utf8; select - cast('{ "a": "dollar \u0024 character" }' - as json) ->> - 'a' + cast('{ "a": "dollar \u0024 character" }' as json) ->> 'a' as correct_everywhere; select - cast('{ "a": "dollar \\u0024 character" }' - as json) ->> - 'a' - as not_an_escape; + cast('{ "a": "dollar \\u0024 character" }' as json) ->> 'a' as not_an_escape; select cast('{ "a": "null \u0000 escape" }' as json) ->> 'a' as fails; @@ -80,10 +69,7 @@ select octet_length(cast(cast('"\uaBcD"' as jsonb) as text)); select octet_length( - cast(cast('{ "a": "\ud83d\ude04\ud83d\udc36" }' - as jsonb) -> - 'a' - as text) + cast(cast('{ "a": "\ud83d\ude04\ud83d\udc36" }' as jsonb) -> 'a' as text) ) as correct_in_utf8; @@ -96,14 +82,10 @@ select cast('{ "a": "\ud83dX" }' as jsonb) -> 'a'; select cast('{ "a": "\ude04X" }' as jsonb) -> 'a'; select - cast('{ "a": "the Copyright \u00a9 sign" }' - as jsonb) - as correct_in_utf8; + cast('{ "a": "the Copyright \u00a9 sign" }' as jsonb) as correct_in_utf8; select - cast('{ "a": "dollar \u0024 character" }' - as jsonb) - as correct_everywhere; + cast('{ "a": "dollar \u0024 character" }' as jsonb) as correct_everywhere; select cast('{ "a": "dollar \\u0024 character" }' as jsonb) as not_an_escape; @@ -112,35 +94,23 @@ select cast('{ "a": "null \u0000 escape" }' as jsonb) as fails; select cast('{ "a": "null \\u0000 escape" }' as jsonb) as not_an_escape; select - cast('{ "a": "the Copyright \u00a9 sign" }' - as jsonb) ->> - 'a' + cast('{ "a": "the Copyright \u00a9 sign" }' as jsonb) ->> 'a' as correct_in_utf8; select - cast('{ "a": "dollar \u0024 character" }' - as jsonb) ->> - 'a' + cast('{ "a": "dollar \u0024 character" }' as jsonb) ->> 'a' as correct_everywhere; select - cast('{ "a": "dollar \\u0024 character" }' - as jsonb) ->> - 'a' + cast('{ "a": "dollar \\u0024 character" }' as jsonb) ->> 'a' as not_an_escape; select cast('{ "a": "null \u0000 escape" }' as jsonb) ->> 'a' as fails; select - cast('{ "a": "null \\u0000 escape" }' - as jsonb) ->> - 'a' - as not_an_escape; + cast('{ "a": "null \\u0000 escape" }' as jsonb) ->> 'a' as not_an_escape; select * from - pg_input_error_info( - '{ "a": "\ud83d\ude04\ud83d\udc36" }', - 'jsonb' - ); + pg_input_error_info('{ "a": "\ud83d\ude04\ud83d\udc36" }', 'jsonb'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_100.snap index 5a08d5d14..ad2199bf2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_100.snap @@ -110,20 +110,16 @@ select cast('{ "three": true}' as jsonb); -select - cast('{ +select cast('{ "one": 1, "two":,"two", -- ERROR extraneous comma before field "two" "three": - true}' - as jsonb); + true}' as jsonb); -select - cast('{ +select cast('{ "one": 1, "two":"two", - "averyveryveryveryveryveryveryveryveryverylongfieldname":}' - as jsonb); + "averyveryveryveryveryveryveryveryveryverylongfieldname":}' as jsonb); select pg_input_is_valid('{"a":true}', 'jsonb'); @@ -145,10 +141,7 @@ select from pg_stats where - tablename = 'rows' and - schemaname = - cast(cast(pg_my_temp_schema() as regnamespace) - as text) + tablename = 'rows' and schemaname = cast(cast(pg_my_temp_schema() as regnamespace) as text) order by 1; select to_jsonb(cast('2014-05-28 12:22:35.614298' as timestamp)); @@ -157,11 +150,11 @@ begin; set local time zone 10.5; -select to_jsonb(cast('2014-05-28 12:22:35.614298-04' as timestamp with time zone)); +select to_jsonb(cast('2014-05-28 12:22:35.614298-04' as timestamptz)); set local time zone -8; -select to_jsonb(cast('2014-05-28 12:22:35.614298-04' as timestamp with time zone)); +select to_jsonb(cast('2014-05-28 12:22:35.614298-04' as timestamptz)); commit; @@ -175,9 +168,9 @@ select to_jsonb(cast('Infinity' as timestamp)); select to_jsonb(cast('-Infinity' as timestamp)); -select to_jsonb(cast('Infinity' as timestamp with time zone)); +select to_jsonb(cast('Infinity' as timestamptz)); -select to_jsonb(cast('-Infinity' as timestamp with time zone)); +select to_jsonb(cast('-Infinity' as timestamptz)); select jsonb_agg(q) @@ -186,9 +179,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -209,10 +200,7 @@ create temporary table test_jsonb ( insert into test_jsonb values ('scalar', '"a scalar"'), - ( - 'array', - '["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]' - ), + ('array', '["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), ( 'object', '{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}' @@ -420,8 +408,7 @@ select jsonb_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null}'); select jsonb_each( - cast('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}' - as jsonb) + cast('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}' as jsonb) ) as q; @@ -431,8 +418,7 @@ select * from jsonb_each( - cast('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}' - as jsonb) + cast('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}' as jsonb) ) as q; @@ -440,8 +426,7 @@ select jsonb_each_text('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":"null"}'); select jsonb_each_text( - cast('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}' - as jsonb) + cast('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}' as jsonb) ) as q; @@ -451,8 +436,7 @@ select * from jsonb_each_text( - cast('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}' - as jsonb) + cast('{"a":{"b":"c","c":"b","1":"first"},"b":[1,2],"c":"cc","1":"first","n":null}' as jsonb) ) as q; @@ -472,11 +456,11 @@ select cast('{"a":null, "b":"qq"}' as jsonb) ? 'c'; select cast('{"a":"null", "b":"qq"}' as jsonb) ? 'a'; -select COUNT(*) from testjsonb where j -> 'array' ? 'bar'; +select count(*) from testjsonb where j -> 'array' ? 'bar'; -select COUNT(*) from testjsonb where j -> 'array' ? cast('5' as text); +select count(*) from testjsonb where j -> 'array' ? cast('5' as text); -select COUNT(*) from testjsonb where j -> 'array' @> cast('5' as jsonb); +select count(*) from testjsonb where j -> 'array' @> cast('5' as jsonb); select jsonb_exists_any('{"a":null, "b":"qq"}', array['a', 'b']); @@ -601,13 +585,7 @@ select row_to_json(r) from ( - select - relkind, - cast(oid as regclass) as name - from - pg_class - where - relname = 'pg_class' + select relkind, cast(oid as regclass) as name from pg_class where relname = 'pg_class' ) as r ) @@ -730,44 +708,23 @@ select jsonb_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}', select jsonb_extract_path_text('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}', 'f2'); select - jsonb_extract_path_text( - '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}', - 'f2', - cast(0 as text) - ); + jsonb_extract_path_text('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}', 'f2', cast(0 as text)); select - jsonb_extract_path_text( - '{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}', - 'f2', - cast(1 as text) - ); + jsonb_extract_path_text('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}', 'f2', cast(1 as text)); select - jsonb_extract_path( - '{"f2":{"f3":1},"f4":{"f5":null,"f6":"stringy"}}', - 'f4', - 'f5' - ) is null + jsonb_extract_path('{"f2":{"f3":1},"f4":{"f5":null,"f6":"stringy"}}', 'f4', 'f5') is null as expect_false; select - jsonb_extract_path_text( - '{"f2":{"f3":1},"f4":{"f5":null,"f6":"stringy"}}', - 'f4', - 'f5' - ) is null + jsonb_extract_path_text('{"f2":{"f3":1},"f4":{"f5":null,"f6":"stringy"}}', 'f4', 'f5') is null as expect_true; select jsonb_extract_path('{"f2":{"f3":1},"f4":[0,1,2,null]}', 'f4', '3') is null as expect_false; select - jsonb_extract_path_text( - '{"f2":{"f3":1},"f4":[0,1,2,null]}', - 'f4', - '3' - ) is null - as expect_true; + jsonb_extract_path_text('{"f2":{"f3":1},"f4":[0,1,2,null]}', 'f4', '3') is null as expect_true; select cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #> array['f4', 'f6']; @@ -874,10 +831,7 @@ select jsonb_array_elements_text('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},f select * from - jsonb_array_elements_text( - '[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]' - ) - as q; + jsonb_array_elements_text('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false,"stringy"]') as q; create type jbpop as (a text, b int, c timestamp); @@ -1006,20 +960,12 @@ select ia2 from jsonb_populate_record(cast(null as jsbrec), '{"ia2": [[1, 2], 3, select ia2d from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia2d": [[1, "2"], [null, 4]]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia2d": [[1, "2"], [null, 4]]}') as q; select ia2d from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia2d": [[1, "2", 3], [null, 5, 6]]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia2d": [[1, "2", 3], [null, 5, 6]]}') as q; select ia3 from jsonb_populate_record(cast(null as jsbrec), '{"ia3": [1, "2", null, 4]}') as q; @@ -1028,21 +974,14 @@ select ia3 from jsonb_populate_record(cast(null as jsbrec), '{"ia3": [[1, 2], [n select ia3 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia3": [ [[], []], [[], []], [[], []] ]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia3": [ [[], []], [[], []], [[], []] ]}') as q; select ia3 from jsonb_populate_record(cast(null as jsbrec), '{"ia3": [ [[1, 2]], [[3, 4]] ]}') as q; select ia3 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia3": [ [[1, 2], [3, 4]], [[5, 6], [7, 8]] ]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia3": [ [[1, 2], [3, 4]], [[5, 6], [7, 8]] ]}') as q; select @@ -1093,20 +1032,12 @@ select js from jsonb_populate_record(cast(null as jsbrec), '{"js": "abc"}') as q select js from - jsonb_populate_record( - cast(null as jsbrec), - '{"js": [123, "123", null, {"key": "value"}]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"js": [123, "123", null, {"key": "value"}]}') as q; select js from - jsonb_populate_record( - cast(null as jsbrec), - '{"js": {"a": "bbb", "b": null, "c": 123.45}}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"js": {"a": "bbb", "b": null, "c": 123.45}}') as q; select jsb from jsonb_populate_record(cast(null as jsbrec), '{"jsb": null}') as q; @@ -1121,20 +1052,12 @@ select jsb from jsonb_populate_record(cast(null as jsbrec), '{"jsb": "abc"}') as select jsb from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsb": [123, "123", null, {"key": "value"}]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsb": [123, "123", null, {"key": "value"}]}') as q; select jsb from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsb": {"a": "bbb", "b": null, "c": 123.45}}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsb": {"a": "bbb", "b": null, "c": 123.45}}') as q; select jsa from jsonb_populate_record(cast(null as jsbrec), '{"jsa": null}') as q; @@ -1158,10 +1081,7 @@ select rec from jsonb_populate_record(cast(null as jsbrec), '{"rec": [1, 2]}') a select rec from - jsonb_populate_record( - cast(null as jsbrec), - '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}') as q; select rec from jsonb_populate_record(cast(null as jsbrec), '{"rec": "(abc,42,01.02.2003)"}') as q; @@ -1182,42 +1102,36 @@ from select reca from - jsonb_populate_record( - cast(null as jsbrec), - '{"reca": ["(abc,42,01.02.2003)"]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"reca": ["(abc,42,01.02.2003)"]}') as q; select reca from - jsonb_populate_record( - cast(null as jsbrec), - '{"reca": "{\"(abc,42,01.02.2003)\"}"}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"reca": "{\"(abc,42,01.02.2003)\"}"}') as q; select rec from jsonb_populate_record( - cast(row(null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - cast(row('x', 3, '2012-12-31 15:30:56') as jbpop), - null) + cast(row( + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + cast(row('x', 3, '2012-12-31 15:30:56') as jbpop), + null + ) as jsbrec), '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}' ) @@ -1380,10 +1294,7 @@ select jsonb_populate_recordset(row(1, 2), '[{"f1": 0, "f2": 1}]'); select i, - jsonb_populate_recordset( - row(i, 50), - '[{"f1":"42"},{"f2":"43"}]' - ) + jsonb_populate_recordset(row(i, 50), '[{"f1":"42"},{"f2":"43"}]') from (values (1), (2)) as v (i); @@ -1406,20 +1317,14 @@ select jsonb_populate_recordset(cast(row(1, 2) as jb_ordered_pair), '[{"x": 1, " select * from - jsonb_populate_recordset( - row(cast(0 as int)), - '[{"a":"1","b":"2"},{"a":"3"}]' - ) + jsonb_populate_recordset(row(cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]') as q (a text, b text); select * from - jsonb_populate_recordset( - row(cast(0 as int), cast(0 as int)), - '[{"a":"1","b":"2"},{"a":"3"}]' - ) + jsonb_populate_recordset(row(cast(0 as int), cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]') as q (a text, b text); @@ -1427,9 +1332,7 @@ select * from jsonb_populate_recordset( - row(cast(0 as int), - cast(0 as int), - cast(0 as int)), + row(cast(0 as int), cast(0 as int), cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]' ) as q @@ -1438,10 +1341,7 @@ from select * from - jsonb_populate_recordset( - row(cast(1000000000 as int), cast(50 as int)), - '[{"b":"2"},{"a":"3"}]' - ) + jsonb_populate_recordset(row(cast(1000000000 as int), cast(50 as int)), '[{"b":"2"},{"a":"3"}]') as q (a text, b text); @@ -1450,9 +1350,7 @@ select * from jsonb_to_record('{"a":1,"b":"foo","c":"bar"}') as x (a int, b text select * from - jsonb_to_recordset( - '[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]' - ) + jsonb_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]') as x (a int, b text, c boolean); @@ -1465,24 +1363,13 @@ from as jsonb) ) as t - ( - a int, - b jsonb, - c text, - x int, - ca char(5)[], - ia int[][], - r jbpop - ); + (a int, b jsonb, c text, x int, ca char(5)[], ia int[][], r jbpop); select *, c is null as c_is_null from - jsonb_to_recordset( - cast('[{"a":1, "b":{"c":16, "d":2}, "x":8}]' - as jsonb) - ) + jsonb_to_recordset(cast('[{"a":1, "b":{"c":16, "d":2}, "x":8}]' as jsonb)) as t (a int, b jsonb, c text, x int); @@ -1500,9 +1387,9 @@ select * from jsonb_to_record('{"ia": [[1], [2, 3]]}') as x (ia _int4); select * from jsonb_to_record('{"ia2": [1, 2, 3]}') as x (ia2 int[][]); -select * from jsonb_to_record('{"ia2": [[1, 2], [3, 4]]}') as x (ia2 int[][]); +select * from jsonb_to_record('{"ia2": [[1, 2], [3, 4]]}') as x (ia2 int4[][]); -select * from jsonb_to_record('{"ia2": [[[1], [2], [3]]]}') as x (ia2 int[][]); +select * from jsonb_to_record('{"ia2": [[[1], [2], [3]]]}') as x (ia2 int4[][]); select * from jsonb_to_record('{"out": {"key": 1}}') as x (out json); @@ -1518,16 +1405,11 @@ select * from jsonb_to_record('{"out": "{\"key\": 1}"}') as x (out jsonb); create temporary table jsbpoptest (js jsonb); -insert into jsbpoptest -select - cast('{ +insert into jsbpoptest select cast('{ "jsa": [1, "2", null, 4], "rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}, "reca": [{"a": "abc", "b": 456}, null, {"c": "01.02.2003", "x": 43.2}] -}' - as jsonb) -from - generate_series(1, 3); +}' as jsonb) from generate_series(1, 3); select (jsonb_populate_record(cast(null as jsbrec), js)).* from jsbpoptest; @@ -1545,187 +1427,178 @@ drop domain jb_ordered_pair; drop type jb_unordered_pair; -select COUNT(*) from testjsonb where j @> '{"wait":null}'; +select count(*) from testjsonb where j @> '{"wait":null}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC"}'; +select count(*) from testjsonb where j @> '{"wait":"CC"}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; +select count(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; -select COUNT(*) from testjsonb where j @> '{"age":25}'; +select count(*) from testjsonb where j @> '{"age":25}'; -select COUNT(*) from testjsonb where j @> '{"age":25.0}'; +select count(*) from testjsonb where j @> '{"age":25.0}'; -select COUNT(*) from testjsonb where j ? 'public'; +select count(*) from testjsonb where j ? 'public'; -select COUNT(*) from testjsonb where j ? 'bar'; +select count(*) from testjsonb where j ? 'bar'; -select COUNT(*) from testjsonb where j ?| array['public', 'disabled']; +select count(*) from testjsonb where j ?| array['public', 'disabled']; -select COUNT(*) from testjsonb where j ?& array['public', 'disabled']; +select count(*) from testjsonb where j ?& array['public', 'disabled']; -select COUNT(*) from testjsonb where j @@ '$.wait == null'; +select count(*) from testjsonb where j @@ '$.wait == null'; -select COUNT(*) from testjsonb where j @@ '"CC" == $.wait'; +select count(*) from testjsonb where j @@ '"CC" == $.wait'; -select COUNT(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; +select count(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; -select COUNT(*) from testjsonb where j @@ '$.age == 25'; +select count(*) from testjsonb where j @@ '$.age == 25'; -select COUNT(*) from testjsonb where j @@ '$.age == 25.0'; +select count(*) from testjsonb where j @@ '$.age == 25.0'; -select COUNT(*) from testjsonb where j @@ 'exists($)'; +select count(*) from testjsonb where j @@ 'exists($)'; -select COUNT(*) from testjsonb where j @@ 'exists($.public)'; +select count(*) from testjsonb where j @@ 'exists($.public)'; -select COUNT(*) from testjsonb where j @@ 'exists($.bar)'; +select count(*) from testjsonb where j @@ 'exists($.bar)'; -select COUNT(*) from testjsonb where j @@ 'exists($.public) || exists($.disabled)'; +select count(*) from testjsonb where j @@ 'exists($.public) || exists($.disabled)'; -select COUNT(*) from testjsonb where j @@ 'exists($.public) && exists($.disabled)'; +select count(*) from testjsonb where j @@ 'exists($.public) && exists($.disabled)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; +select count(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.wait == "CC" && true == @.public)'; +select count(*) from testjsonb where j @? '$ ? (@.wait == "CC" && true == @.public)'; -select COUNT(*) from testjsonb where j @? '$.age ? (@ == 25)'; +select count(*) from testjsonb where j @? '$.age ? (@ == 25)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; +select count(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; -select COUNT(*) from testjsonb where j @? '$'; +select count(*) from testjsonb where j @? '$'; -select COUNT(*) from testjsonb where j @? '$.public'; +select count(*) from testjsonb where j @? '$.public'; -select COUNT(*) from testjsonb where j @? '$.bar'; +select count(*) from testjsonb where j @? '$.bar'; -create index "jidx" on testjsonb using gin (j); +create index jidx on testjsonb using gin (j); set enable_seqscan = off; -select COUNT(*) from testjsonb where j @> '{"wait":null}'; +select count(*) from testjsonb where j @> '{"wait":null}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC"}'; +select count(*) from testjsonb where j @> '{"wait":"CC"}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; +select count(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; -select COUNT(*) from testjsonb where j @> '{"age":25}'; +select count(*) from testjsonb where j @> '{"age":25}'; -select COUNT(*) from testjsonb where j @> '{"age":25.0}'; +select count(*) from testjsonb where j @> '{"age":25.0}'; -select COUNT(*) from testjsonb where j @> '{"array":["foo"]}'; +select count(*) from testjsonb where j @> '{"array":["foo"]}'; -select COUNT(*) from testjsonb where j @> '{"array":["bar"]}'; +select count(*) from testjsonb where j @> '{"array":["bar"]}'; -select COUNT(*) from testjsonb where j @> '{}'; +select count(*) from testjsonb where j @> '{}'; -select COUNT(*) from testjsonb where j ? 'public'; +select count(*) from testjsonb where j ? 'public'; -select COUNT(*) from testjsonb where j ? 'bar'; +select count(*) from testjsonb where j ? 'bar'; -select COUNT(*) from testjsonb where j ?| array['public', 'disabled']; +select count(*) from testjsonb where j ?| array['public', 'disabled']; -select COUNT(*) from testjsonb where j ?& array['public', 'disabled']; +select count(*) from testjsonb where j ?& array['public', 'disabled']; -select COUNT(*) from testjsonb where j @@ '$.wait == null'; +select count(*) from testjsonb where j @@ '$.wait == null'; -select COUNT(*) from testjsonb where j @@ '$.wait == null'; +select count(*) from testjsonb where j @@ '$.wait == null'; -select COUNT(*) from testjsonb where j @@ 'exists($ ? (@.wait == null))'; +select count(*) from testjsonb where j @@ 'exists($ ? (@.wait == null))'; -select COUNT(*) from testjsonb where j @@ 'exists($.wait ? (@ == null))'; +select count(*) from testjsonb where j @@ 'exists($.wait ? (@ == null))'; -select COUNT(*) from testjsonb where j @@ '"CC" == $.wait'; +select count(*) from testjsonb where j @@ '"CC" == $.wait'; -select COUNT(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; +select count(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; -select COUNT(*) from testjsonb where j @@ '$.age == 25'; +select count(*) from testjsonb where j @@ '$.age == 25'; -select COUNT(*) from testjsonb where j @@ '$.age == 25.0'; +select count(*) from testjsonb where j @@ '$.age == 25.0'; -select COUNT(*) from testjsonb where j @@ '$.array[*] == "foo"'; +select count(*) from testjsonb where j @@ '$.array[*] == "foo"'; -select COUNT(*) from testjsonb where j @@ '$.array[*] == "bar"'; +select count(*) from testjsonb where j @@ '$.array[*] == "bar"'; -select COUNT(*) from testjsonb where j @@ 'exists($ ? (@.array[*] == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($ ? (@.array[*] == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($.array ? (@[*] == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($.array ? (@[*] == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($.array[*] ? (@ == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($.array[*] ? (@ == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($)'; +select count(*) from testjsonb where j @@ 'exists($)'; -select COUNT(*) from testjsonb where j @@ 'exists($.public)'; +select count(*) from testjsonb where j @@ 'exists($.public)'; -select COUNT(*) from testjsonb where j @@ 'exists($.bar)'; +select count(*) from testjsonb where j @@ 'exists($.bar)'; -select COUNT(*) from testjsonb where j @@ 'exists($.public) || exists($.disabled)'; +select count(*) from testjsonb where j @@ 'exists($.public) || exists($.disabled)'; -select COUNT(*) from testjsonb where j @@ 'exists($.public) && exists($.disabled)'; +select count(*) from testjsonb where j @@ 'exists($.public) && exists($.disabled)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; +select count(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.wait == "CC" && true == @.public)'; +select count(*) from testjsonb where j @? '$ ? (@.wait == "CC" && true == @.public)'; -select COUNT(*) from testjsonb where j @? '$.age ? (@ == 25)'; +select count(*) from testjsonb where j @? '$.age ? (@ == 25)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; +select count(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.array[*] == "bar")'; +select count(*) from testjsonb where j @? '$ ? (@.array[*] == "bar")'; -select COUNT(*) from testjsonb where j @? '$.array ? (@[*] == "bar")'; +select count(*) from testjsonb where j @? '$.array ? (@[*] == "bar")'; -select COUNT(*) from testjsonb where j @? '$.array[*] ? (@ == "bar")'; +select count(*) from testjsonb where j @? '$.array[*] ? (@ == "bar")'; -select COUNT(*) from testjsonb where j @? '$'; +select count(*) from testjsonb where j @? '$'; -select COUNT(*) from testjsonb where j @? '$.public'; +select count(*) from testjsonb where j @? '$.public'; -select COUNT(*) from testjsonb where j @? '$.bar'; +select count(*) from testjsonb where j @? '$.bar'; -create index "jidx_array" on testjsonb using gin ((j -> 'array')); +create index jidx_array on testjsonb using gin ((j -> 'array')); -select COUNT(*) from testjsonb where j -> 'array' ? 'bar'; +select count(*) from testjsonb where j -> 'array' ? 'bar'; -select COUNT(*) from testjsonb where j -> 'array' ? cast('5' as text); +select count(*) from testjsonb where j -> 'array' ? cast('5' as text); -select COUNT(*) from testjsonb where j -> 'array' @> cast('5' as jsonb); +select count(*) from testjsonb where j -> 'array' @> cast('5' as jsonb); reset enable_seqscan; -select COUNT(*) from (select (jsonb_each(j)).key from testjsonb) as wow; +select count(*) from (select (jsonb_each(j)).key from testjsonb) as wow; select key, - COUNT(*) + count(*) from (select (jsonb_each(j)).key from testjsonb) as wow group by key order by count desc, key; -select COUNT(distinct j) from testjsonb; +select count(distinct j) from testjsonb; set enable_hashagg = off; select - COUNT(*) + count(*) from ( - select - j - from - ( - select * from testjsonb - union all - select * from testjsonb - ) - as js - group by j + select j from (select * from testjsonb union all select * from testjsonb) as js group by j ) as js2; @@ -1734,19 +1607,10 @@ set enable_hashagg = 'on'; set enable_sort = off; select - COUNT(*) + count(*) from ( - select - j - from - ( - select * from testjsonb - union all - select * from testjsonb - ) - as js - group by j + select j from (select * from testjsonb union all select * from testjsonb) as js group by j ) as js2; @@ -1762,81 +1626,81 @@ drop index jidx; drop index jidx_array; -create index "jidx" on testjsonb using btree (j); +create index jidx on testjsonb using btree (j); set enable_seqscan = off; -select COUNT(*) from testjsonb where j > '{"p":1}'; +select count(*) from testjsonb where j > '{"p":1}'; -select COUNT(*) from testjsonb where j = '{"pos":98, "line":371, "node":"CBA", "indexed":true}'; +select count(*) from testjsonb where j = '{"pos":98, "line":371, "node":"CBA", "indexed":true}'; drop index jidx; -create index "jidx" on testjsonb using gin (j jsonb_path_ops); +create index jidx on testjsonb using gin (j jsonb_path_ops); set enable_seqscan = off; -select COUNT(*) from testjsonb where j @> '{"wait":null}'; +select count(*) from testjsonb where j @> '{"wait":null}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC"}'; +select count(*) from testjsonb where j @> '{"wait":"CC"}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; +select count(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; -select COUNT(*) from testjsonb where j @> '{"age":25}'; +select count(*) from testjsonb where j @> '{"age":25}'; -select COUNT(*) from testjsonb where j @> '{"age":25.0}'; +select count(*) from testjsonb where j @> '{"age":25.0}'; -select COUNT(*) from testjsonb where j @> '{}'; +select count(*) from testjsonb where j @> '{}'; -select COUNT(*) from testjsonb where j @@ '$.wait == null'; +select count(*) from testjsonb where j @@ '$.wait == null'; -select COUNT(*) from testjsonb where j @@ 'exists($ ? (@.wait == null))'; +select count(*) from testjsonb where j @@ 'exists($ ? (@.wait == null))'; -select COUNT(*) from testjsonb where j @@ 'exists($.wait ? (@ == null))'; +select count(*) from testjsonb where j @@ 'exists($.wait ? (@ == null))'; -select COUNT(*) from testjsonb where j @@ '"CC" == $.wait'; +select count(*) from testjsonb where j @@ '"CC" == $.wait'; -select COUNT(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; +select count(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; -select COUNT(*) from testjsonb where j @@ '$.age == 25'; +select count(*) from testjsonb where j @@ '$.age == 25'; -select COUNT(*) from testjsonb where j @@ '$.age == 25.0'; +select count(*) from testjsonb where j @@ '$.age == 25.0'; -select COUNT(*) from testjsonb where j @@ '$.array[*] == "foo"'; +select count(*) from testjsonb where j @@ '$.array[*] == "foo"'; -select COUNT(*) from testjsonb where j @@ '$.array[*] == "bar"'; +select count(*) from testjsonb where j @@ '$.array[*] == "bar"'; -select COUNT(*) from testjsonb where j @@ 'exists($ ? (@.array[*] == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($ ? (@.array[*] == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($.array ? (@[*] == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($.array ? (@[*] == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($.array[*] ? (@ == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($.array[*] ? (@ == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($)'; +select count(*) from testjsonb where j @@ 'exists($)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; +select count(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.wait == "CC" && true == @.public)'; +select count(*) from testjsonb where j @? '$ ? (@.wait == "CC" && true == @.public)'; -select COUNT(*) from testjsonb where j @? '$.age ? (@ == 25)'; +select count(*) from testjsonb where j @? '$.age ? (@ == 25)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; +select count(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.array[*] == "bar")'; +select count(*) from testjsonb where j @? '$ ? (@.array[*] == "bar")'; -select COUNT(*) from testjsonb where j @? '$.array ? (@[*] == "bar")'; +select count(*) from testjsonb where j @? '$.array ? (@[*] == "bar")'; -select COUNT(*) from testjsonb where j @? '$.array[*] ? (@ == "bar")'; +select count(*) from testjsonb where j @? '$.array[*] ? (@ == "bar")'; -select COUNT(*) from testjsonb where j @? '$'; +select count(*) from testjsonb where j @? '$'; -select COUNT(*) from testjsonb where j @? '$.public'; +select count(*) from testjsonb where j @? '$.public'; -select COUNT(*) from testjsonb where j @? '$.bar'; +select count(*) from testjsonb where j @? '$.bar'; reset enable_seqscan; @@ -1861,23 +1725,11 @@ select select cast('{"ff":["a","aaa"]}' as jsonb); select - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) -> - 'ff', - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) -> - 'qq', - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) -> - 'Y' is null - as f, - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) ->> - 'Y' is null - as t, - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) -> - 'x'; + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) -> 'ff', + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) -> 'qq', + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) -> 'Y' is null as f, + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) ->> 'Y' is null as t, + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) -> 'x'; select cast('{"a":[1,2],"c":"b"}' as jsonb) @> '{"a":[1,2]}'; @@ -2115,30 +1967,18 @@ select cast('{"c": 1}' as jsonb) || '["a", "b"]'; select cast('{}' as jsonb) || '{"cq":"l", "b":"g", "fg":false}'; select - pg_column_size( - cast('{}' as jsonb) || cast('{}' as jsonb) - ) = - pg_column_size(cast('{}' as jsonb)); + pg_column_size(cast('{}' as jsonb) || cast('{}' as jsonb)) = pg_column_size(cast('{}' as jsonb)); select - pg_column_size( - cast('{"aa":1}' as jsonb) || - cast('{"b":2}' as jsonb) - ) = + pg_column_size(cast('{"aa":1}' as jsonb) || cast('{"b":2}' as jsonb)) = pg_column_size(cast('{"aa":1, "b":2}' as jsonb)); select - pg_column_size( - cast('{"aa":1, "b":2}' as jsonb) || - cast('{}' as jsonb) - ) = + pg_column_size(cast('{"aa":1, "b":2}' as jsonb) || cast('{}' as jsonb)) = pg_column_size(cast('{"aa":1, "b":2}' as jsonb)); select - pg_column_size( - cast('{}' as jsonb) || - cast('{"aa":1, "b":2}' as jsonb) - ) = + pg_column_size(cast('{}' as jsonb) || cast('{"aa":1, "b":2}' as jsonb)) = pg_column_size(cast('{"aa":1, "b":2}' as jsonb)); select jsonb_delete(cast('{"a":1 , "b":2, "c":3}' as jsonb), 'a'); @@ -2162,9 +2002,7 @@ select cast('{"a":1 , "b":2, "c":3}' as jsonb) - 'c'; select cast('{"a":1 , "b":2, "c":3}' as jsonb) - 'd'; select - pg_column_size( - cast('{"a":1 , "b":2, "c":3}' as jsonb) - 'b' - ) = + pg_column_size(cast('{"a":1 , "b":2, "c":3}' as jsonb) - 'b') = pg_column_size(cast('{"a":1, "b":2}' as jsonb)); select cast('["a","b","c"]' as jsonb) - 3; @@ -2191,80 +2029,70 @@ select cast('{"a":1 , "b":2, "c":3}' as jsonb) - cast('{}' as text[]); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{n}', '[1,2,3]' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{b,-1}', '[1,2,3]' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{d,1,0}', '[1,2,3]' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{d,NULL,0}', '[1,2,3]' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{n}', '{"1": 2}' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{b,-1}', '{"1": 2}' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{d,1,0}', '{"1": 2}' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{d,NULL,0}', '{"1": 2}' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{b,-1}', '"test"' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{b,-1}', '{"f": "test"}' ); @@ -2350,39 +2178,18 @@ select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, true, null); select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, true, 'no_such_treatment'); select - jsonb_set_lax( - '{"a":1,"b":2}', - '{b}', - null, - "null_value_treatment" := 'raise_exception' - ) + jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment := 'raise_exception') as raise_exception; select - jsonb_set_lax( - '{"a":1,"b":2}', - '{b}', - null, - "null_value_treatment" := 'return_target' - ) + jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment := 'return_target') as return_target; select - jsonb_set_lax( - '{"a":1,"b":2}', - '{b}', - null, - "null_value_treatment" := 'delete_key' - ) - as delete_key; + jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment := 'delete_key') as delete_key; select - jsonb_set_lax( - '{"a":1,"b":2}', - '{b}', - null, - "null_value_treatment" := 'use_json_null' - ) + jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment := 'use_json_null') as use_json_null; select jsonb_insert('{"a": [0,1,2]}', '{a, 1}', '"new_value"'); @@ -2480,8 +2287,7 @@ select (cast('{"a": {"a1": {"a2": "aaa"}}, "b": "bbb", "c": "ccc"}' as jsonb))[' select (cast('{"a": {"a1": {"a2": "aaa"}}, "b": "bbb", "c": "ccc"}' as jsonb))['a']['a1']['a2']; select - (cast('{"a": {"a1": {"a2": "aaa"}}, "b": "bbb", "c": "ccc"}' - as jsonb))['a']['a1']['a2']['a3']; + (cast('{"a": {"a1": {"a2": "aaa"}}, "b": "bbb", "c": "ccc"}' as jsonb))['a']['a1']['a2']['a3']; select (cast('{"a": ["a1", {"b1": ["aaa", "bbb", "ccc"]}], "b": "bb"}' as jsonb))['a'][1]['b1']; @@ -2692,11 +2498,7 @@ create temporary table test_jsonb_subscript ( insert into test_jsonb_subscript values ('foo', '{"foo": "bar"}'); insert into test_jsonb_subscript -select - s, - cast('{"' || s || '": "bar"}' as jsonb) -from - repeat('xyzzy', 500) as s; +select s, cast('{"' || s || '": "bar"}' as jsonb) from repeat('xyzzy', 500) as s; select length(id), test_json[id] from test_jsonb_subscript; @@ -2708,22 +2510,19 @@ select * from test_jsonb_subscript; select to_tsvector( - cast('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' - as jsonb) + cast('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' as jsonb) ); select to_tsvector( 'simple', - cast('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' - as jsonb) + cast('{"a": "aaa bbb ddd ccc", "b": ["eee fff ggg"], "c": {"d": "hhh iii"}}' as jsonb) ); select to_tsvector( 'english', - cast('{"a": "aaa in bbb ddd ccc", "b": ["the eee fff ggg"], "c": {"d": "hhh. iii"}}' - as jsonb) + cast('{"a": "aaa in bbb ddd ccc", "b": ["the eee fff ggg"], "c": {"d": "hhh. iii"}}' as jsonb) ); select to_tsvector('english', cast('{"a": "aaa in bbb ddd ccc", "b": 123, "c": 456}' as jsonb)); @@ -2731,96 +2530,84 @@ select to_tsvector('english', cast('{"a": "aaa in bbb ddd ccc", "b": 123, "c": 4 select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"all"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"key"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"string"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"numeric"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"boolean"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '["string", "numeric"]' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"all"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"key"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"string"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"numeric"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '"boolean"' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '["string", "numeric"]' ); @@ -2843,40 +2630,35 @@ select jsonb_to_tsvector(cast('null' as jsonb), '"all"'); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '""' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '{}' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '[]' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), 'null' ); select jsonb_to_tsvector( 'english', - cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' - as jsonb), + cast('{"a": "aaa in bbb", "b": 123, "c": 456, "d": true, "f": false, "g": null}' as jsonb), '["all", null]' ); @@ -2890,8 +2672,7 @@ select select ts_headline( 'english', - cast('{"a": "aaa bbb", "b": {"c": "ccc ddd fff"}, "d": ["ggg hhh", "iii jjj"]}' - as jsonb), + cast('{"a": "aaa bbb", "b": {"c": "ccc ddd fff"}, "d": ["ggg hhh", "iii jjj"]}' as jsonb), tsquery('bbb & ddd & hhh') ); @@ -2918,11 +2699,11 @@ select ts_headline(cast('{}' as jsonb), tsquery('aaa & bbb')); select ts_headline(cast('[]' as jsonb), tsquery('aaa & bbb')); -select cast(cast('true' as jsonb) as boolean); +select cast(cast('true' as jsonb) as bool); -select cast(cast('null' as jsonb) as boolean); +select cast(cast('null' as jsonb) as bool); -select cast(cast('[]' as jsonb) as boolean); +select cast(cast('[]' as jsonb) as bool); select cast(cast('1.0' as jsonb) as double precision); @@ -2930,29 +2711,29 @@ select cast(cast('null' as jsonb) as double precision); select cast(cast('[1.0]' as jsonb) as double precision); -select cast(cast('1.0' as jsonb) as real); +select cast(cast('1.0' as jsonb) as float4); -select cast(cast('null' as jsonb) as real); +select cast(cast('null' as jsonb) as float4); -select cast(cast('[1.0]' as jsonb) as real); +select cast(cast('[1.0]' as jsonb) as float4); -select cast(cast('12345' as jsonb) as smallint); +select cast(cast('12345' as jsonb) as int2); -select cast(cast('null' as jsonb) as smallint); +select cast(cast('null' as jsonb) as int2); -select cast(cast('"hello"' as jsonb) as smallint); +select cast(cast('"hello"' as jsonb) as int2); -select cast(cast('12345' as jsonb) as int); +select cast(cast('12345' as jsonb) as int4); -select cast(cast('null' as jsonb) as int); +select cast(cast('null' as jsonb) as int4); -select cast(cast('"hello"' as jsonb) as int); +select cast(cast('"hello"' as jsonb) as int4); -select cast(cast('12345' as jsonb) as bigint); +select cast(cast('12345' as jsonb) as int8); -select cast(cast('null' as jsonb) as bigint); +select cast(cast('null' as jsonb) as int8); -select cast(cast('"hello"' as jsonb) as bigint); +select cast(cast('"hello"' as jsonb) as int8); select cast(cast('12345' as jsonb) as numeric); @@ -2962,27 +2743,24 @@ select cast(cast('{}' as jsonb) as numeric); select cast(cast('12345.05' as jsonb) as numeric); -select cast(cast('12345.05' as jsonb) as real); +select cast(cast('12345.05' as jsonb) as float4); -select cast(cast('12345.05' as jsonb) as double precision); +select cast(cast('12345.05' as jsonb) as float8); -select cast(cast('12345.05' as jsonb) as smallint); +select cast(cast('12345.05' as jsonb) as int2); -select cast(cast('12345.05' as jsonb) as int); +select cast(cast('12345.05' as jsonb) as int4); -select cast(cast('12345.05' as jsonb) as bigint); +select cast(cast('12345.05' as jsonb) as int8); select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as numeric); -select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as real); +select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as float4); -select - cast(cast('12345.0000000000000000000000000000000000000000000005' - as jsonb) - as double precision); +select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as float8); -select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as smallint); +select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as int2); -select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as int); +select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as int4); -select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as bigint); +select cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as int8); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_80.snap index d79b75432..091f69e35 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_80.snap @@ -110,20 +110,16 @@ select cast('{ "three": true}' as jsonb); -select - cast('{ +select cast('{ "one": 1, "two":,"two", -- ERROR extraneous comma before field "two" "three": - true}' - as jsonb); + true}' as jsonb); -select - cast('{ +select cast('{ "one": 1, "two":"two", - "averyveryveryveryveryveryveryveryveryverylongfieldname":}' - as jsonb); + "averyveryveryveryveryveryveryveryveryverylongfieldname":}' as jsonb); select pg_input_is_valid('{"a":true}', 'jsonb'); @@ -134,33 +130,22 @@ select * from pg_input_error_info('{"a":true', 'jsonb'); select * from pg_input_error_info('{"a":1e1000000}', 'jsonb'); select - array_to_json( - array[cast('{"a":1}' as jsonb), - cast('{"b":[2,3]}' as jsonb)] - ); + array_to_json(array[cast('{"a":1}' as jsonb), cast('{"b":[2,3]}' as jsonb)]); create temporary table rows as - select - x, - 'txt' || x as y - from - generate_series(1, 3) as x; + select x, 'txt' || x as y from generate_series(1, 3) as x; analyze rows; select attname, - to_jsonb(histogram_bounds) - as histogram_bounds + to_jsonb(histogram_bounds) as histogram_bounds from pg_stats where tablename = 'rows' and - schemaname = - cast(cast(pg_my_temp_schema() - as regnamespace) - as text) + schemaname = cast(cast(pg_my_temp_schema() as regnamespace) as text) order by 1; select to_jsonb(cast('2014-05-28 12:22:35.614298' as timestamp)); @@ -169,19 +154,11 @@ begin; set local time zone 10.5; -select - to_jsonb( - cast('2014-05-28 12:22:35.614298-04' - as timestamp with time zone) - ); +select to_jsonb(cast('2014-05-28 12:22:35.614298-04' as timestamptz)); set local time zone -8; -select - to_jsonb( - cast('2014-05-28 12:22:35.614298-04' - as timestamp with time zone) - ); +select to_jsonb(cast('2014-05-28 12:22:35.614298-04' as timestamptz)); commit; @@ -195,9 +172,9 @@ select to_jsonb(cast('Infinity' as timestamp)); select to_jsonb(cast('-Infinity' as timestamp)); -select to_jsonb(cast('Infinity' as timestamp with time zone)); +select to_jsonb(cast('Infinity' as timestamptz)); -select to_jsonb(cast('-Infinity' as timestamp with time zone)); +select to_jsonb(cast('-Infinity' as timestamptz)); select jsonb_agg(q) @@ -206,9 +183,7 @@ from select 'a' || x as b, y as c, - array[row(x.*, array[1, 2, 3]), - row(y.*, array[4, 5, 6])] - as z + array[row(x.*, array[1, 2, 3]), row(y.*, array[4, 5, 6])] as z from generate_series(1, 2) as x, generate_series(4, 5) as y @@ -229,10 +204,7 @@ create temporary table test_jsonb ( insert into test_jsonb values ('scalar', '"a scalar"'), - ( - 'array', - '["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]' - ), + ('array', '["zero", "one","two",null,"four","five", [1,2,3],{"f1":9}]'), ( 'object', '{"field1":"val1","field2":"val2","field3":null, "field4": 4, "field5": [1,2,3], "field6": {"f1":9}}' @@ -283,16 +255,14 @@ select jsonb_object_keys(test_json) from test_jsonb where json_type = 'array'; select jsonb_object_keys(test_json) from test_jsonb where json_type = 'object'; select - test_json -> 'field3' is null - as expect_false + test_json -> 'field3' is null as expect_false from test_jsonb where json_type = 'object'; select - test_json ->> 'field3' is null - as expect_true + test_json ->> 'field3' is null as expect_true from test_jsonb where @@ -449,14 +419,11 @@ select cast('["9", ["7", "3"], 1]' as jsonb); select - cast('["9", ["7", "3"], ["1"]]' - as jsonb) @> - cast('["9", ["7", "3"], ["1"]]' - as jsonb); + cast('["9", ["7", "3"], ["1"]]' as jsonb) @> + cast('["9", ["7", "3"], ["1"]]' as jsonb); select - cast('{ "name": "Bob", "tags": [ "enim", "qui"]}' - as jsonb) @> + cast('{ "name": "Bob", "tags": [ "enim", "qui"]}' as jsonb) @> '{"tags":["qu"]}'; select jsonb_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]'); @@ -479,9 +446,7 @@ select select * from - jsonb_each( - '{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}' - ) + jsonb_each('{"f1":[1,2,3],"f2":{"f3":1},"f4":null,"f5":99,"f6":"stringy"}') as q; select @@ -535,11 +500,11 @@ select cast('{"a":null, "b":"qq"}' as jsonb) ? 'c'; select cast('{"a":"null", "b":"qq"}' as jsonb) ? 'a'; -select COUNT(*) from testjsonb where j -> 'array' ? 'bar'; +select count(*) from testjsonb where j -> 'array' ? 'bar'; -select COUNT(*) from testjsonb where j -> 'array' ? cast('5' as text); +select count(*) from testjsonb where j -> 'array' ? cast('5' as text); -select COUNT(*) from testjsonb where j -> 'array' @> cast('5' as jsonb); +select count(*) from testjsonb where j -> 'array' @> cast('5' as jsonb); select jsonb_exists_any('{"a":null, "b":"qq"}', array['a', 'b']); @@ -736,13 +701,7 @@ insert into foo values (847003, 'sub-alpha', 'GESS90'); select jsonb_build_object( 'turbines', - jsonb_object_agg( - serial_num, - jsonb_build_object( - 'name', name, - 'type', type - ) - ) + jsonb_object_agg(serial_num, jsonb_build_object('name', name, 'type', type)) ) from foo; @@ -795,10 +754,7 @@ select ); select - jsonb_extract_path( - '{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}', - 'f2' - ); + jsonb_extract_path('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}', 'f2'); select jsonb_extract_path( @@ -858,11 +814,7 @@ select as expect_true; select - jsonb_extract_path( - '{"f2":{"f3":1},"f4":[0,1,2,null]}', - 'f4', - '3' - ) is null + jsonb_extract_path('{"f2":{"f3":1},"f4":[0,1,2,null]}', 'f4', '3') is null as expect_false; select @@ -874,43 +826,34 @@ select as expect_true; select - cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' - as jsonb) #> + cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #> array['f4', 'f6']; select - cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' - as jsonb) #> - array['f2']; + cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #> array['f2']; select - cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' - as jsonb) #> + cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #> array['f2', '0']; select - cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' - as jsonb) #> + cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #> array['f2', '1']; select - cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' - as jsonb) #>> + cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #>> array['f4', 'f6']; select - cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' - as jsonb) #>> + cast('{"f2":{"f3":1},"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #>> array['f2']; select - cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' - as jsonb) #>> + cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #>> array['f2', '0']; select - cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' - as jsonb) #>> + cast('{"f2":["f3",1],"f4":{"f5":99,"f6":"stringy"}}' as jsonb) #>> array['f2', '1']; select cast('{"a": {"b":{"c": "foo"}}}' as jsonb) #> '{}'; @@ -938,14 +881,10 @@ select cast('{"a": {"b":{"c": "foo"}}}' as jsonb) #> array['a', 'b', 'c', 'd']; select cast('{"a": {"b":{"c": "foo"}}}' as jsonb) #> array['a', 'z', 'c']; select - cast('{"a": [{"b": "c"}, {"b": "cc"}]}' - as jsonb) #> - array['a', '1', 'b']; + cast('{"a": [{"b": "c"}, {"b": "cc"}]}' as jsonb) #> array['a', '1', 'b']; select - cast('{"a": [{"b": "c"}, {"b": "cc"}]}' - as jsonb) #> - array['a', 'z', 'b']; + cast('{"a": [{"b": "c"}, {"b": "cc"}]}' as jsonb) #> array['a', 'z', 'b']; select cast('[{"b": "c"}, {"b": "cc"}]' as jsonb) #> array['1', 'b']; @@ -984,14 +923,10 @@ select cast('{"a": {"b":{"c": "foo"}}}' as jsonb) #>> array['a', 'b', 'c', 'd']; select cast('{"a": {"b":{"c": "foo"}}}' as jsonb) #>> array['a', 'z', 'c']; select - cast('{"a": [{"b": "c"}, {"b": "cc"}]}' - as jsonb) #>> - array['a', '1', 'b']; + cast('{"a": [{"b": "c"}, {"b": "cc"}]}' as jsonb) #>> array['a', '1', 'b']; select - cast('{"a": [{"b": "c"}, {"b": "cc"}]}' - as jsonb) #>> - array['a', 'z', 'b']; + cast('{"a": [{"b": "c"}, {"b": "cc"}]}' as jsonb) #>> array['a', 'z', 'b']; select cast('[{"b": "c"}, {"b": "cc"}]' as jsonb) #>> array['1', 'b']; @@ -1006,16 +941,12 @@ select cast('42' as jsonb) #>> array['f2']; select cast('42' as jsonb) #>> array['0']; select - jsonb_array_elements( - '[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false]' - ); + jsonb_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false]'); select * from - jsonb_array_elements( - '[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false]' - ) + jsonb_array_elements('[1,true,[1,[2,3]],null,{"f1":1,"f2":[7,8,9]},false]') as q; select @@ -1069,18 +1000,13 @@ create type jsbrec_i_not_null as (i jsb_int_not_null); select * from - jsonb_populate_record( - cast(null as jbpop), - '{"a":"blurfl","x":43.2}' - ) - as q; + jsonb_populate_record(cast(null as jbpop), '{"a":"blurfl","x":43.2}') as q; select * from jsonb_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jbpop), + cast(row('x', 3, '2012-12-31 15:30:56') as jbpop), '{"a":"blurfl","x":43.2}' ) as q; @@ -1088,18 +1014,13 @@ from select * from - jsonb_populate_record( - cast(null as jbpop), - '{"a":"blurfl","x":43.2}' - ) - as q; + jsonb_populate_record(cast(null as jbpop), '{"a":"blurfl","x":43.2}') as q; select * from jsonb_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jbpop), + cast(row('x', 3, '2012-12-31 15:30:56') as jbpop), '{"a":"blurfl","x":43.2}' ) as q; @@ -1107,18 +1028,14 @@ from select * from - jsonb_populate_record( - cast(null as jbpop), - '{"a":[100,200,false],"x":43.2}' - ) + jsonb_populate_record(cast(null as jbpop), '{"a":[100,200,false],"x":43.2}') as q; select * from jsonb_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jbpop), + cast(row('x', 3, '2012-12-31 15:30:56') as jbpop), '{"a":[100,200,false],"x":43.2}' ) as q; @@ -1127,8 +1044,7 @@ select * from jsonb_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jbpop), + cast(row('x', 3, '2012-12-31 15:30:56') as jbpop), '{"c":[100,200,false],"x":43.2}' ) as q; @@ -1136,39 +1052,23 @@ from select * from - jsonb_populate_record( - cast(row('x', 3, '2012-12-31 15:30:56') - as jbpop), - '{}' - ) + jsonb_populate_record(cast(row('x', 3, '2012-12-31 15:30:56') as jbpop), '{}') as q; select i from - jsonb_populate_record( - cast(null as jsbrec_i_not_null), - '{"x": 43.2}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec_i_not_null), '{"x": 43.2}') as q; select i from - jsonb_populate_record( - cast(null as jsbrec_i_not_null), - '{"i": null}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec_i_not_null), '{"i": null}') as q; select i from - jsonb_populate_record( - cast(null as jsbrec_i_not_null), - '{"i": 12345}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec_i_not_null), '{"i": 12345}') as q; select ia from jsonb_populate_record(cast(null as jsbrec), '{"ia": null}') as q; @@ -1177,172 +1077,101 @@ select ia from jsonb_populate_record(cast(null as jsbrec), '{"ia": 123}') as q; select ia from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia": [1, "2", null, 4]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia": [1, "2", null, 4]}') as q; select ia from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia": [[1, 2], [3, 4]]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia": [[1, 2], [3, 4]]}') as q; select ia from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia": [[1], 2]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia": [[1], 2]}') as q; select ia from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia": [[1], [2, 3]]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia": [[1], [2, 3]]}') as q; select ia from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia": "{1,2,3}"}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia": "{1,2,3}"}') as q; select ia1 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia1": null}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia1": null}') as q; select ia1 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia1": 123}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia1": 123}') as q; select ia1 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia1": [1, "2", null, 4]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia1": [1, "2", null, 4]}') as q; select ia1 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia1": [[1, 2, 3]]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia1": [[1, 2, 3]]}') as q; select ia1d from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia1d": null}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia1d": null}') as q; select ia1d from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia1d": 123}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia1d": 123}') as q; select ia1d from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia1d": [1, "2", null, 4]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia1d": [1, "2", null, 4]}') as q; select ia1d from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia1d": [1, "2", null]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia1d": [1, "2", null]}') as q; select ia2 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia2": [1, "2", null, 4]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia2": [1, "2", null, 4]}') as q; select ia2 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia2": [[1, 2], [null, 4]]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia2": [[1, 2], [null, 4]]}') as q; select ia2 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia2": [[], []]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia2": [[], []]}') as q; select ia2 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia2": [[1, 2], [3]]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia2": [[1, 2], [3]]}') as q; select ia2 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia2": [[1, 2], 3, 4]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ia2": [[1, 2], 3, 4]}') as q; select ia2d from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia2d": [[1, "2"], [null, 4]]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia2d": [[1, "2"], [null, 4]]}') as q; select @@ -1357,19 +1186,13 @@ from select ia3 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia3": [1, "2", null, 4]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia3": [1, "2", null, 4]}') as q; select ia3 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia3": [[1, 2], [null, 4]]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia3": [[1, 2], [null, 4]]}') as q; select @@ -1384,10 +1207,7 @@ from select ia3 from - jsonb_populate_record( - cast(null as jsbrec), - '{"ia3": [ [[1, 2]], [[3, 4]] ]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ia3": [ [[1, 2]], [[3, 4]] ]}') as q; select @@ -1415,19 +1235,12 @@ select ta from jsonb_populate_record(cast(null as jsbrec), '{"ta": 123}') as q; select ta from - jsonb_populate_record( - cast(null as jsbrec), - '{"ta": [1, "2", null, 4]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ta": [1, "2", null, 4]}') as q; select ta from - jsonb_populate_record( - cast(null as jsbrec), - '{"ta": [[1, 2, 3], {"k": "v"}]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ta": [[1, 2, 3], {"k": "v"}]}') as q; select c from jsonb_populate_record(cast(null as jsbrec), '{"c": null}') as q; @@ -1437,20 +1250,12 @@ select c from jsonb_populate_record(cast(null as jsbrec), '{"c": "aaa"}') as q; select c from - jsonb_populate_record( - cast(null as jsbrec), - '{"c": "aaaaaaaaaa"}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"c": "aaaaaaaaaa"}') as q; select c from - jsonb_populate_record( - cast(null as jsbrec), - '{"c": "aaaaaaaaaaaaa"}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"c": "aaaaaaaaaaaaa"}') as q; select ca from jsonb_populate_record(cast(null as jsbrec), '{"ca": null}') as q; @@ -1459,28 +1264,18 @@ select ca from jsonb_populate_record(cast(null as jsbrec), '{"ca": 123}') as q; select ca from - jsonb_populate_record( - cast(null as jsbrec), - '{"ca": [1, "2", null, 4]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"ca": [1, "2", null, 4]}') as q; select ca from - jsonb_populate_record( - cast(null as jsbrec), - '{"ca": ["aaaaaaaaaaaaaaaa"]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ca": ["aaaaaaaaaaaaaaaa"]}') as q; select ca from - jsonb_populate_record( - cast(null as jsbrec), - '{"ca": [[1, 2, 3], {"k": "v"}]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"ca": [[1, 2, 3], {"k": "v"}]}') as q; select js from jsonb_populate_record(cast(null as jsbrec), '{"js": null}') as q; @@ -1490,29 +1285,17 @@ select js from jsonb_populate_record(cast(null as jsbrec), '{"js": true}') as q; select js from - jsonb_populate_record( - cast(null as jsbrec), - '{"js": 123.45}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"js": 123.45}') as q; select js from - jsonb_populate_record( - cast(null as jsbrec), - '{"js": "123.45"}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"js": "123.45"}') as q; select js from - jsonb_populate_record( - cast(null as jsbrec), - '{"js": "abc"}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"js": "abc"}') as q; select js @@ -1535,47 +1318,27 @@ from select jsb from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsb": null}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsb": null}') as q; select jsb from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsb": true}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsb": true}') as q; select jsb from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsb": 123.45}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsb": 123.45}') as q; select jsb from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsb": "123.45"}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsb": "123.45"}') as q; select jsb from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsb": "abc"}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsb": "abc"}') as q; select jsb @@ -1598,28 +1361,17 @@ from select jsa from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsa": null}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsa": null}') as q; select jsa from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsa": 123}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"jsa": 123}') as q; select jsa from - jsonb_populate_record( - cast(null as jsbrec), - '{"jsa": [1, "2", null, 4]}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"jsa": [1, "2", null, 4]}') as q; select @@ -1634,20 +1386,12 @@ from select rec from - jsonb_populate_record( - cast(null as jsbrec), - '{"rec": 123}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"rec": 123}') as q; select rec from - jsonb_populate_record( - cast(null as jsbrec), - '{"rec": [1, 2]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"rec": [1, 2]}') as q; select rec @@ -1661,29 +1405,18 @@ from select rec from - jsonb_populate_record( - cast(null as jsbrec), - '{"rec": "(abc,42,01.02.2003)"}' - ) + jsonb_populate_record(cast(null as jsbrec), '{"rec": "(abc,42,01.02.2003)"}') as q; select reca from - jsonb_populate_record( - cast(null as jsbrec), - '{"reca": 123}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"reca": 123}') as q; select reca from - jsonb_populate_record( - cast(null as jsbrec), - '{"reca": [1, 2]}' - ) - as q; + jsonb_populate_record(cast(null as jsbrec), '{"reca": [1, 2]}') as q; select reca @@ -1716,24 +1449,25 @@ select rec from jsonb_populate_record( - cast(row(null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - cast(row('x', 3, '2012-12-31 15:30:56') - as jbpop), - null) + cast(row( + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + cast(row('x', 3, '2012-12-31 15:30:56') as jbpop), + null + ) as jsbrec), '{"rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}}' ) @@ -1746,22 +1480,14 @@ select jsonb_populate_record_valid(cast(null as jsb_char2), '{"a": "aaa"}'); select * from - jsonb_populate_record( - cast(null as jsb_char2), - '{"a": "aaa"}' - ) - as q; + jsonb_populate_record(cast(null as jsb_char2), '{"a": "aaa"}') as q; select jsonb_populate_record_valid(cast(null as jsb_char2), '{"a": "aa"}'); select * from - jsonb_populate_record( - cast(null as jsb_char2), - '{"a": "aa"}' - ) - as q; + jsonb_populate_record(cast(null as jsb_char2), '{"a": "aa"}') as q; create type jsb_ia as (a int[]); @@ -1776,34 +1502,20 @@ select jsonb_populate_record_valid(cast(null as jsb_ia), '{"a": [1, 2]}'); select * from jsonb_populate_record(cast(null as jsb_ia), '{"a": [1, 2]}') as q; select - jsonb_populate_record_valid( - cast(null as jsb_ia2), - '{"a": [[1], [2, 3]]}' - ); + jsonb_populate_record_valid(cast(null as jsb_ia2), '{"a": [[1], [2, 3]]}'); select * from - jsonb_populate_record( - cast(null as jsb_ia2), - '{"a": [[1], [2, 3]]}' - ) - as q; + jsonb_populate_record(cast(null as jsb_ia2), '{"a": [[1], [2, 3]]}') as q; select - jsonb_populate_record_valid( - cast(null as jsb_ia2), - '{"a": [[1, 0], [2, 3]]}' - ); + jsonb_populate_record_valid(cast(null as jsb_ia2), '{"a": [[1, 0], [2, 3]]}'); select * from - jsonb_populate_record( - cast(null as jsb_ia2), - '{"a": [[1, 0], [2, 3]]}' - ) - as q; + jsonb_populate_record(cast(null as jsb_ia2), '{"a": [[1, 0], [2, 3]]}') as q; create domain jsb_i_not_null as int not null; @@ -1814,56 +1526,34 @@ create type jsb_i_not_null_rec as (a jsb_i_not_null); create type jsb_i_gt_1_rec as (a jsb_i_gt_1); select - jsonb_populate_record_valid( - cast(null as jsb_i_not_null_rec), - '{"a": null}' - ); + jsonb_populate_record_valid(cast(null as jsb_i_not_null_rec), '{"a": null}'); select * from - jsonb_populate_record( - cast(null as jsb_i_not_null_rec), - '{"a": null}' - ) - as q; + jsonb_populate_record(cast(null as jsb_i_not_null_rec), '{"a": null}') as q; select - jsonb_populate_record_valid( - cast(null as jsb_i_not_null_rec), - '{"a": 1}' - ); + jsonb_populate_record_valid(cast(null as jsb_i_not_null_rec), '{"a": 1}'); select * from - jsonb_populate_record( - cast(null as jsb_i_not_null_rec), - '{"a": 1}' - ) - as q; + jsonb_populate_record(cast(null as jsb_i_not_null_rec), '{"a": 1}') as q; select jsonb_populate_record_valid(cast(null as jsb_i_gt_1_rec), '{"a": 1}'); select * from - jsonb_populate_record( - cast(null as jsb_i_gt_1_rec), - '{"a": 1}' - ) - as q; + jsonb_populate_record(cast(null as jsb_i_gt_1_rec), '{"a": 1}') as q; select jsonb_populate_record_valid(cast(null as jsb_i_gt_1_rec), '{"a": 2}'); select * from - jsonb_populate_record( - cast(null as jsb_i_gt_1_rec), - '{"a": 2}' - ) - as q; + jsonb_populate_record(cast(null as jsb_i_gt_1_rec), '{"a": 2}') as q; drop type jsb_ia, jsb_ia2, jsb_char2, jsb_i_not_null_rec, jsb_i_gt_1_rec; @@ -1876,21 +1566,14 @@ select jsonb_populate_record(row(1, 2), '{"f1": 0, "f2": 1}'); select * from - jsonb_populate_record( - cast(null as record), - '{"x": 776}' - ) as - (x int, y int); + jsonb_populate_record(cast(null as record), '{"x": 776}') as (x int, y int); select jsonb_populate_record(cast(null as jb_ordered_pair), '{"x": 0, "y": 1}'); select jsonb_populate_record(cast(row(1, 2) as jb_ordered_pair), '{"x": 0}'); select - jsonb_populate_record( - cast(row(1, 2) as jb_ordered_pair), - '{"x": 1, "y": 0}' - ); + jsonb_populate_record(cast(row(1, 2) as jb_ordered_pair), '{"x": 1, "y": 0}'); select * @@ -1979,20 +1662,14 @@ select jsonb_populate_recordset(row(1, 2), '[{"f1": 0, "f2": 1}]'); select i, - jsonb_populate_recordset( - row(i, 50), - '[{"f1":"42"},{"f2":"43"}]' - ) + jsonb_populate_recordset(row(i, 50), '[{"f1":"42"},{"f2":"43"}]') from (values (1), (2)) as v (i); select * from - jsonb_populate_recordset( - cast(null as record), - '[{"x": 776}]' - ) as + jsonb_populate_recordset(cast(null as record), '[{"x": 776}]') as (x int, y int); select jsonb_populate_recordset(cast(null as record), '[]'); @@ -2004,17 +1681,10 @@ select * from jsonb_populate_recordset(cast(null as jbpop), '[]') as q; select * from - jsonb_populate_recordset( - cast(null as record), - '[]' - ) as - (x int, y int); + jsonb_populate_recordset(cast(null as record), '[]') as (x int, y int); select - jsonb_populate_recordset( - cast(null as jb_ordered_pair), - '[{"x": 0, "y": 1}]' - ); + jsonb_populate_recordset(cast(null as jb_ordered_pair), '[{"x": 0, "y": 1}]'); select jsonb_populate_recordset( @@ -2031,10 +1701,7 @@ select select * from - jsonb_populate_recordset( - row(cast(0 as int)), - '[{"a":"1","b":"2"},{"a":"3"}]' - ) + jsonb_populate_recordset(row(cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]') as q (a text, b text); @@ -2052,9 +1719,7 @@ select * from jsonb_populate_recordset( - row(cast(0 as int), - cast(0 as int), - cast(0 as int)), + row(cast(0 as int), cast(0 as int), cast(0 as int)), '[{"a":"1","b":"2"},{"a":"3"}]' ) as q @@ -2064,8 +1729,7 @@ select * from jsonb_populate_recordset( - row(cast(1000000000 as int), - cast(50 as int)), + row(cast(1000000000 as int), cast(50 as int)), '[{"b":"2"},{"a":"3"}]' ) as q @@ -2074,18 +1738,12 @@ from select * from - jsonb_to_record( - '{"a":1,"b":"foo","c":"bar"}' - ) - as x - (a int, b text, d text); + jsonb_to_record('{"a":1,"b":"foo","c":"bar"}') as x (a int, b text, d text); select * from - jsonb_to_recordset( - '[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]' - ) + jsonb_to_recordset('[{"a":1,"b":"foo","d":false},{"a":2,"b":"bar","c":true}]') as x (a int, b text, c boolean); @@ -2098,24 +1756,13 @@ from as jsonb) ) as t - ( - a int, - b jsonb, - c text, - x int, - ca char(5)[], - ia int[][], - r jbpop - ); + (a int, b jsonb, c text, x int, ca char(5)[], ia int[][], r jbpop); select *, c is null as c_is_null from - jsonb_to_recordset( - cast('[{"a":1, "b":{"c":16, "d":2}, "x":8}]' - as jsonb) - ) + jsonb_to_recordset(cast('[{"a":1, "b":{"c":16, "d":2}, "x":8}]' as jsonb)) as t (a int, b jsonb, c text, x int); @@ -2133,9 +1780,9 @@ select * from jsonb_to_record('{"ia": [[1], [2, 3]]}') as x (ia _int4); select * from jsonb_to_record('{"ia2": [1, 2, 3]}') as x (ia2 int[][]); -select * from jsonb_to_record('{"ia2": [[1, 2], [3, 4]]}') as x (ia2 int[][]); +select * from jsonb_to_record('{"ia2": [[1, 2], [3, 4]]}') as x (ia2 int4[][]); -select * from jsonb_to_record('{"ia2": [[[1], [2], [3]]]}') as x (ia2 int[][]); +select * from jsonb_to_record('{"ia2": [[[1], [2], [3]]]}') as x (ia2 int4[][]); select * from jsonb_to_record('{"out": {"key": 1}}') as x (out json); @@ -2151,16 +1798,11 @@ select * from jsonb_to_record('{"out": "{\"key\": 1}"}') as x (out jsonb); create temporary table jsbpoptest (js jsonb); -insert into jsbpoptest -select - cast('{ +insert into jsbpoptest select cast('{ "jsa": [1, "2", null, 4], "rec": {"a": "abc", "c": "01.02.2003", "x": 43.2}, "reca": [{"a": "abc", "b": 456}, null, {"c": "01.02.2003", "x": 43.2}] -}' - as jsonb) -from - generate_series(1, 3); +}' as jsonb) from generate_series(1, 3); select (jsonb_populate_record(cast(null as jsbrec), js)).* from jsbpoptest; @@ -2178,228 +1820,211 @@ drop domain jb_ordered_pair; drop type jb_unordered_pair; -select COUNT(*) from testjsonb where j @> '{"wait":null}'; +select count(*) from testjsonb where j @> '{"wait":null}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC"}'; +select count(*) from testjsonb where j @> '{"wait":"CC"}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; +select count(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; -select COUNT(*) from testjsonb where j @> '{"age":25}'; +select count(*) from testjsonb where j @> '{"age":25}'; -select COUNT(*) from testjsonb where j @> '{"age":25.0}'; +select count(*) from testjsonb where j @> '{"age":25.0}'; -select COUNT(*) from testjsonb where j ? 'public'; +select count(*) from testjsonb where j ? 'public'; -select COUNT(*) from testjsonb where j ? 'bar'; +select count(*) from testjsonb where j ? 'bar'; -select COUNT(*) from testjsonb where j ?| array['public', 'disabled']; +select count(*) from testjsonb where j ?| array['public', 'disabled']; -select COUNT(*) from testjsonb where j ?& array['public', 'disabled']; +select count(*) from testjsonb where j ?& array['public', 'disabled']; -select COUNT(*) from testjsonb where j @@ '$.wait == null'; +select count(*) from testjsonb where j @@ '$.wait == null'; -select COUNT(*) from testjsonb where j @@ '"CC" == $.wait'; +select count(*) from testjsonb where j @@ '"CC" == $.wait'; -select COUNT(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; +select count(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; -select COUNT(*) from testjsonb where j @@ '$.age == 25'; +select count(*) from testjsonb where j @@ '$.age == 25'; -select COUNT(*) from testjsonb where j @@ '$.age == 25.0'; +select count(*) from testjsonb where j @@ '$.age == 25.0'; -select COUNT(*) from testjsonb where j @@ 'exists($)'; +select count(*) from testjsonb where j @@ 'exists($)'; -select COUNT(*) from testjsonb where j @@ 'exists($.public)'; +select count(*) from testjsonb where j @@ 'exists($.public)'; -select COUNT(*) from testjsonb where j @@ 'exists($.bar)'; +select count(*) from testjsonb where j @@ 'exists($.bar)'; select - COUNT(*) + count(*) from testjsonb where - j @@ - 'exists($.public) || exists($.disabled)'; + j @@ 'exists($.public) || exists($.disabled)'; select - COUNT(*) + count(*) from testjsonb where - j @@ - 'exists($.public) && exists($.disabled)'; + j @@ 'exists($.public) && exists($.disabled)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; +select count(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; select - COUNT(*) + count(*) from testjsonb where - j @? - '$ ? (@.wait == "CC" && true == @.public)'; + j @? '$ ? (@.wait == "CC" && true == @.public)'; -select COUNT(*) from testjsonb where j @? '$.age ? (@ == 25)'; +select count(*) from testjsonb where j @? '$.age ? (@ == 25)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; +select count(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; -select COUNT(*) from testjsonb where j @? '$'; +select count(*) from testjsonb where j @? '$'; -select COUNT(*) from testjsonb where j @? '$.public'; +select count(*) from testjsonb where j @? '$.public'; -select COUNT(*) from testjsonb where j @? '$.bar'; +select count(*) from testjsonb where j @? '$.bar'; -create index "jidx" on testjsonb using gin (j); +create index jidx on testjsonb using gin (j); set enable_seqscan = off; -select COUNT(*) from testjsonb where j @> '{"wait":null}'; +select count(*) from testjsonb where j @> '{"wait":null}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC"}'; +select count(*) from testjsonb where j @> '{"wait":"CC"}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; +select count(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; -select COUNT(*) from testjsonb where j @> '{"age":25}'; +select count(*) from testjsonb where j @> '{"age":25}'; -select COUNT(*) from testjsonb where j @> '{"age":25.0}'; +select count(*) from testjsonb where j @> '{"age":25.0}'; -select COUNT(*) from testjsonb where j @> '{"array":["foo"]}'; +select count(*) from testjsonb where j @> '{"array":["foo"]}'; -select COUNT(*) from testjsonb where j @> '{"array":["bar"]}'; +select count(*) from testjsonb where j @> '{"array":["bar"]}'; -select COUNT(*) from testjsonb where j @> '{}'; +select count(*) from testjsonb where j @> '{}'; -select COUNT(*) from testjsonb where j ? 'public'; +select count(*) from testjsonb where j ? 'public'; -select COUNT(*) from testjsonb where j ? 'bar'; +select count(*) from testjsonb where j ? 'bar'; -select COUNT(*) from testjsonb where j ?| array['public', 'disabled']; +select count(*) from testjsonb where j ?| array['public', 'disabled']; -select COUNT(*) from testjsonb where j ?& array['public', 'disabled']; +select count(*) from testjsonb where j ?& array['public', 'disabled']; -select COUNT(*) from testjsonb where j @@ '$.wait == null'; +select count(*) from testjsonb where j @@ '$.wait == null'; -select COUNT(*) from testjsonb where j @@ '$.wait == null'; +select count(*) from testjsonb where j @@ '$.wait == null'; -select COUNT(*) from testjsonb where j @@ 'exists($ ? (@.wait == null))'; +select count(*) from testjsonb where j @@ 'exists($ ? (@.wait == null))'; -select COUNT(*) from testjsonb where j @@ 'exists($.wait ? (@ == null))'; +select count(*) from testjsonb where j @@ 'exists($.wait ? (@ == null))'; -select COUNT(*) from testjsonb where j @@ '"CC" == $.wait'; +select count(*) from testjsonb where j @@ '"CC" == $.wait'; -select COUNT(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; +select count(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; -select COUNT(*) from testjsonb where j @@ '$.age == 25'; +select count(*) from testjsonb where j @@ '$.age == 25'; -select COUNT(*) from testjsonb where j @@ '$.age == 25.0'; +select count(*) from testjsonb where j @@ '$.age == 25.0'; -select COUNT(*) from testjsonb where j @@ '$.array[*] == "foo"'; +select count(*) from testjsonb where j @@ '$.array[*] == "foo"'; -select COUNT(*) from testjsonb where j @@ '$.array[*] == "bar"'; +select count(*) from testjsonb where j @@ '$.array[*] == "bar"'; -select COUNT(*) from testjsonb where j @@ 'exists($ ? (@.array[*] == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($ ? (@.array[*] == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($.array ? (@[*] == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($.array ? (@[*] == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($.array[*] ? (@ == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($.array[*] ? (@ == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($)'; +select count(*) from testjsonb where j @@ 'exists($)'; -select COUNT(*) from testjsonb where j @@ 'exists($.public)'; +select count(*) from testjsonb where j @@ 'exists($.public)'; -select COUNT(*) from testjsonb where j @@ 'exists($.bar)'; +select count(*) from testjsonb where j @@ 'exists($.bar)'; select - COUNT(*) + count(*) from testjsonb where - j @@ - 'exists($.public) || exists($.disabled)'; + j @@ 'exists($.public) || exists($.disabled)'; select - COUNT(*) + count(*) from testjsonb where - j @@ - 'exists($.public) && exists($.disabled)'; + j @@ 'exists($.public) && exists($.disabled)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; +select count(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; select - COUNT(*) + count(*) from testjsonb where - j @? - '$ ? (@.wait == "CC" && true == @.public)'; + j @? '$ ? (@.wait == "CC" && true == @.public)'; -select COUNT(*) from testjsonb where j @? '$.age ? (@ == 25)'; +select count(*) from testjsonb where j @? '$.age ? (@ == 25)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; +select count(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.array[*] == "bar")'; +select count(*) from testjsonb where j @? '$ ? (@.array[*] == "bar")'; -select COUNT(*) from testjsonb where j @? '$.array ? (@[*] == "bar")'; +select count(*) from testjsonb where j @? '$.array ? (@[*] == "bar")'; -select COUNT(*) from testjsonb where j @? '$.array[*] ? (@ == "bar")'; +select count(*) from testjsonb where j @? '$.array[*] ? (@ == "bar")'; -select COUNT(*) from testjsonb where j @? '$'; +select count(*) from testjsonb where j @? '$'; -select COUNT(*) from testjsonb where j @? '$.public'; +select count(*) from testjsonb where j @? '$.public'; -select COUNT(*) from testjsonb where j @? '$.bar'; +select count(*) from testjsonb where j @? '$.bar'; -create index "jidx_array" on testjsonb using gin ((j -> 'array')); +create index jidx_array on testjsonb using gin ((j -> 'array')); -select COUNT(*) from testjsonb where j -> 'array' ? 'bar'; +select count(*) from testjsonb where j -> 'array' ? 'bar'; -select COUNT(*) from testjsonb where j -> 'array' ? cast('5' as text); +select count(*) from testjsonb where j -> 'array' ? cast('5' as text); -select COUNT(*) from testjsonb where j -> 'array' @> cast('5' as jsonb); +select count(*) from testjsonb where j -> 'array' @> cast('5' as jsonb); reset enable_seqscan; -select COUNT(*) from (select (jsonb_each(j)).key from testjsonb) as wow; +select count(*) from (select (jsonb_each(j)).key from testjsonb) as wow; select key, - COUNT(*) + count(*) from - ( - select - (jsonb_each(j)).key - from - testjsonb - ) - as wow + (select (jsonb_each(j)).key from testjsonb) as wow group by key order by count desc, key; -select COUNT(distinct j) from testjsonb; +select count(distinct j) from testjsonb; set enable_hashagg = off; select - COUNT(*) + count(*) from ( select j from - ( - select * from testjsonb - union all - select * from testjsonb - ) - as js + (select * from testjsonb union all select * from testjsonb) as js group by j ) as js2; @@ -2409,18 +2034,13 @@ set enable_hashagg = 'on'; set enable_sort = off; select - COUNT(*) + count(*) from ( select j from - ( - select * from testjsonb - union all - select * from testjsonb - ) - as js + (select * from testjsonb union all select * from testjsonb) as js group by j ) as js2; @@ -2428,14 +2048,7 @@ from select distinct * from - ( - values - ( - cast('{}' as jsonb) || cast('' as text) - ), - ('{}') - ) - as v (j); + (values (cast('{}' as jsonb) || cast('' as text)), ('{}')) as v (j); set enable_sort = 'on'; @@ -2447,93 +2060,91 @@ drop index jidx; drop index jidx_array; -create index "jidx" on testjsonb using btree (j); +create index jidx on testjsonb using btree (j); set enable_seqscan = off; -select COUNT(*) from testjsonb where j > '{"p":1}'; +select count(*) from testjsonb where j > '{"p":1}'; select - COUNT(*) + count(*) from testjsonb where - j = - '{"pos":98, "line":371, "node":"CBA", "indexed":true}'; + j = '{"pos":98, "line":371, "node":"CBA", "indexed":true}'; drop index jidx; -create index "jidx" on testjsonb using gin (j jsonb_path_ops); +create index jidx on testjsonb using gin (j jsonb_path_ops); set enable_seqscan = off; -select COUNT(*) from testjsonb where j @> '{"wait":null}'; +select count(*) from testjsonb where j @> '{"wait":null}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC"}'; +select count(*) from testjsonb where j @> '{"wait":"CC"}'; -select COUNT(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; +select count(*) from testjsonb where j @> '{"wait":"CC", "public":true}'; -select COUNT(*) from testjsonb where j @> '{"age":25}'; +select count(*) from testjsonb where j @> '{"age":25}'; -select COUNT(*) from testjsonb where j @> '{"age":25.0}'; +select count(*) from testjsonb where j @> '{"age":25.0}'; -select COUNT(*) from testjsonb where j @> '{}'; +select count(*) from testjsonb where j @> '{}'; -select COUNT(*) from testjsonb where j @@ '$.wait == null'; +select count(*) from testjsonb where j @@ '$.wait == null'; -select COUNT(*) from testjsonb where j @@ 'exists($ ? (@.wait == null))'; +select count(*) from testjsonb where j @@ 'exists($ ? (@.wait == null))'; -select COUNT(*) from testjsonb where j @@ 'exists($.wait ? (@ == null))'; +select count(*) from testjsonb where j @@ 'exists($.wait ? (@ == null))'; -select COUNT(*) from testjsonb where j @@ '"CC" == $.wait'; +select count(*) from testjsonb where j @@ '"CC" == $.wait'; -select COUNT(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; +select count(*) from testjsonb where j @@ '$.wait == "CC" && true == $.public'; -select COUNT(*) from testjsonb where j @@ '$.age == 25'; +select count(*) from testjsonb where j @@ '$.age == 25'; -select COUNT(*) from testjsonb where j @@ '$.age == 25.0'; +select count(*) from testjsonb where j @@ '$.age == 25.0'; -select COUNT(*) from testjsonb where j @@ '$.array[*] == "foo"'; +select count(*) from testjsonb where j @@ '$.array[*] == "foo"'; -select COUNT(*) from testjsonb where j @@ '$.array[*] == "bar"'; +select count(*) from testjsonb where j @@ '$.array[*] == "bar"'; -select COUNT(*) from testjsonb where j @@ 'exists($ ? (@.array[*] == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($ ? (@.array[*] == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($.array ? (@[*] == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($.array ? (@[*] == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($.array[*] ? (@ == "bar"))'; +select count(*) from testjsonb where j @@ 'exists($.array[*] ? (@ == "bar"))'; -select COUNT(*) from testjsonb where j @@ 'exists($)'; +select count(*) from testjsonb where j @@ 'exists($)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? (@ == null)'; +select count(*) from testjsonb where j @? '$.wait ? (@ == null)'; -select COUNT(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; +select count(*) from testjsonb where j @? '$.wait ? ("CC" == @)'; select - COUNT(*) + count(*) from testjsonb where - j @? - '$ ? (@.wait == "CC" && true == @.public)'; + j @? '$ ? (@.wait == "CC" && true == @.public)'; -select COUNT(*) from testjsonb where j @? '$.age ? (@ == 25)'; +select count(*) from testjsonb where j @? '$.age ? (@ == 25)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; +select count(*) from testjsonb where j @? '$ ? (@.age == 25.0)'; -select COUNT(*) from testjsonb where j @? '$ ? (@.array[*] == "bar")'; +select count(*) from testjsonb where j @? '$ ? (@.array[*] == "bar")'; -select COUNT(*) from testjsonb where j @? '$.array ? (@[*] == "bar")'; +select count(*) from testjsonb where j @? '$.array ? (@[*] == "bar")'; -select COUNT(*) from testjsonb where j @? '$.array[*] ? (@ == "bar")'; +select count(*) from testjsonb where j @? '$.array[*] ? (@ == "bar")'; -select COUNT(*) from testjsonb where j @? '$'; +select count(*) from testjsonb where j @? '$'; -select COUNT(*) from testjsonb where j @? '$.public'; +select count(*) from testjsonb where j @? '$.public'; -select COUNT(*) from testjsonb where j @? '$.bar'; +select count(*) from testjsonb where j @? '$.bar'; reset enable_seqscan; @@ -2558,23 +2169,15 @@ select select cast('{"ff":["a","aaa"]}' as jsonb); select - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) -> - 'ff', - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) -> - 'qq', - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) -> + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) -> 'ff', + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) -> 'qq', + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) -> 'Y' is null as f, - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) ->> + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) ->> 'Y' is null as t, - cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' - as jsonb) -> - 'x'; + cast('{"ff":{"a":12,"b":16},"qq":123,"x":[1,2],"Y":null}' as jsonb) -> 'x'; select cast('{"a":[1,2],"c":"b"}' as jsonb) @> '{"a":[1,2]}'; @@ -2607,14 +2210,10 @@ select cast('{"a":[1,2,{"c":3,"x":4}],"c":"b"}' as jsonb) @> '{"a":[{"c":3}]}'; select cast('{"a":[1,2,{"c":3,"x":4}],"c":"b"}' as jsonb) @> '{"a":[{"x":4}]}'; select - cast('{"a":[1,2,{"c":3,"x":4}],"c":"b"}' - as jsonb) @> - '{"a":[{"x":4},3]}'; + cast('{"a":[1,2,{"c":3,"x":4}],"c":"b"}' as jsonb) @> '{"a":[{"x":4},3]}'; select - cast('{"a":[1,2,{"c":3,"x":4}],"c":"b"}' - as jsonb) @> - '{"a":[{"x":4},1]}'; + cast('{"a":[1,2,{"c":3,"x":4}],"c":"b"}' as jsonb) @> '{"a":[{"x":4},1]}'; create temporary table nestjsonb (j jsonb); @@ -2651,45 +2250,36 @@ reset enable_seqscan; reset enable_bitmapscan; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) -> + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) -> 'n'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) -> + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) -> 'a'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) -> + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) -> 'b'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) -> + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) -> 'c'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) -> + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) -> 'd'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) -> + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) -> 'd' -> '1'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) -> + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) -> 'e'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) -> - 0; + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) -> 0; select cast('["a","b","c",[1,2],null]' as jsonb) -> 0; @@ -2740,34 +2330,22 @@ select cast('[0,1,2,[3,4],{"5":"five"}]' as jsonb) #> '{4}'; select cast('[0,1,2,[3,4],{"5":"five"}]' as jsonb) #> '{4,5}'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) ? - 'n'; + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) ? 'n'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) ? - 'a'; + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) ? 'a'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) ? - 'b'; + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) ? 'b'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) ? - 'c'; + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) ? 'c'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) ? - 'd'; + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) ? 'd'; select - cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' - as jsonb) ? - 'e'; + cast('{"n":null,"a":1,"b":[1,2],"c":{"1":2},"d":{"1":[2,3]}}' as jsonb) ? 'e'; select jsonb_strip_nulls(null); @@ -2780,9 +2358,7 @@ select jsonb_strip_nulls('null'); select jsonb_strip_nulls('[1,2,null,3,4]'); select - jsonb_strip_nulls( - '{"a":1,"b":null,"c":[2,null,3],"d":{"e":4,"f":null}}' - ); + jsonb_strip_nulls('{"a":1,"b":null,"c":[2,null,3],"d":{"e":4,"f":null}}'); select jsonb_strip_nulls('[1,{"a":1,"b":null,"c":2},3]'); @@ -2824,8 +2400,7 @@ select ); select - cast('{"aa":1 , "b":2, "cq":3}' - as jsonb) || + cast('{"aa":1 , "b":2, "cq":3}' as jsonb) || '{"cq":"l", "b":"g", "fg":false}'; select cast('{"aa":1 , "b":2, "cq":3}' as jsonb) || '{"aq":"l"}'; @@ -2875,38 +2450,20 @@ select cast('{"c": 1}' as jsonb) || '["a", "b"]'; select cast('{}' as jsonb) || '{"cq":"l", "b":"g", "fg":false}'; select - pg_column_size( - cast('{}' as jsonb) || - cast('{}' as jsonb) - ) = + pg_column_size(cast('{}' as jsonb) || cast('{}' as jsonb)) = pg_column_size(cast('{}' as jsonb)); select - pg_column_size( - cast('{"aa":1}' as jsonb) || - cast('{"b":2}' as jsonb) - ) = - pg_column_size( - cast('{"aa":1, "b":2}' as jsonb) - ); + pg_column_size(cast('{"aa":1}' as jsonb) || cast('{"b":2}' as jsonb)) = + pg_column_size(cast('{"aa":1, "b":2}' as jsonb)); select - pg_column_size( - cast('{"aa":1, "b":2}' as jsonb) || - cast('{}' as jsonb) - ) = - pg_column_size( - cast('{"aa":1, "b":2}' as jsonb) - ); + pg_column_size(cast('{"aa":1, "b":2}' as jsonb) || cast('{}' as jsonb)) = + pg_column_size(cast('{"aa":1, "b":2}' as jsonb)); select - pg_column_size( - cast('{}' as jsonb) || - cast('{"aa":1, "b":2}' as jsonb) - ) = - pg_column_size( - cast('{"aa":1, "b":2}' as jsonb) - ); + pg_column_size(cast('{}' as jsonb) || cast('{"aa":1, "b":2}' as jsonb)) = + pg_column_size(cast('{"aa":1, "b":2}' as jsonb)); select jsonb_delete(cast('{"a":1 , "b":2, "c":3}' as jsonb), 'a'); @@ -2929,13 +2486,8 @@ select cast('{"a":1 , "b":2, "c":3}' as jsonb) - 'c'; select cast('{"a":1 , "b":2, "c":3}' as jsonb) - 'd'; select - pg_column_size( - cast('{"a":1 , "b":2, "c":3}' as jsonb) - - 'b' - ) = - pg_column_size( - cast('{"a":1, "b":2}' as jsonb) - ); + pg_column_size(cast('{"a":1 , "b":2, "c":3}' as jsonb) - 'b') = + pg_column_size(cast('{"a":1, "b":2}' as jsonb)); select cast('["a","b","c"]' as jsonb) - 3; @@ -2961,80 +2513,70 @@ select cast('{"a":1 , "b":2, "c":3}' as jsonb) - cast('{}' as text[]); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{n}', '[1,2,3]' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{b,-1}', '[1,2,3]' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{d,1,0}', '[1,2,3]' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{d,NULL,0}', '[1,2,3]' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{n}', '{"1": 2}' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{b,-1}', '{"1": 2}' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{d,1,0}', '{"1": 2}' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{d,NULL,0}', '{"1": 2}' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{b,-1}', '"test"' ); select jsonb_set( - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb), + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb), '{b,-1}', '{"f": "test"}' ); @@ -3060,23 +2602,19 @@ select select jsonb_delete_path('{"a":[]}', '{"a",-2147483648}'); select - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb) #- + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb) #- '{n}'; select - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb) #- + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb) #- '{b,-1}'; select - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb) #- + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb) #- '{b,-1e}'; select - cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' - as jsonb) #- + cast('{"n":null, "a":1, "b":[1,2], "c":{"1":2}, "d":{"1":[2,3]}}' as jsonb) #- '{d,1,0}'; select cast('"a"' as jsonb) - 'a'; @@ -3133,11 +2671,7 @@ select jsonb_set('[]', '{-99}', '{"foo":123}'); select jsonb_set('{"a": [1, 2, 3]}', '{a, non_integer}', '"new_value"'); select - jsonb_set( - '{"a": {"b": [1, 2, 3]}}', - '{a, b, non_integer}', - '"new_value"' - ); + jsonb_set('{"a": {"b": [1, 2, 3]}}', '{a, b, non_integer}', '"new_value"'); select jsonb_set('{"a": {"b": [1, 2, 3]}}', '{a, b, NULL}', '"new_value"'); @@ -3158,7 +2692,7 @@ select '{"a":1,"b":2}', '{b}', null, - "null_value_treatment" := 'raise_exception' + null_value_treatment := 'raise_exception' ) as raise_exception; @@ -3167,7 +2701,7 @@ select '{"a":1,"b":2}', '{b}', null, - "null_value_treatment" := 'return_target' + null_value_treatment := 'return_target' ) as return_target; @@ -3176,7 +2710,7 @@ select '{"a":1,"b":2}', '{b}', null, - "null_value_treatment" := 'delete_key' + null_value_treatment := 'delete_key' ) as delete_key; @@ -3185,7 +2719,7 @@ select '{"a":1,"b":2}', '{b}', null, - "null_value_treatment" := 'use_json_null' + null_value_treatment := 'use_json_null' ) as use_json_null; @@ -3348,8 +2882,7 @@ select from test_jsonb_subscript where - test_json['key_doesnt_exists'] = - '"value"'; + test_json['key_doesnt_exists'] = '"value"'; select * from test_jsonb_subscript where test_json['key'] = '"wrong_value"'; @@ -3552,8 +3085,7 @@ select select to_tsvector( 'english', - cast('{"a": "aaa in bbb ddd ccc", "b": 123, "c": 456}' - as jsonb) + cast('{"a": "aaa in bbb ddd ccc", "b": 123, "c": 456}' as jsonb) ); select @@ -3746,11 +3278,11 @@ select ts_headline(cast('{}' as jsonb), tsquery('aaa & bbb')); select ts_headline(cast('[]' as jsonb), tsquery('aaa & bbb')); -select cast(cast('true' as jsonb) as boolean); +select cast(cast('true' as jsonb) as bool); -select cast(cast('null' as jsonb) as boolean); +select cast(cast('null' as jsonb) as bool); -select cast(cast('[]' as jsonb) as boolean); +select cast(cast('[]' as jsonb) as bool); select cast(cast('1.0' as jsonb) as double precision); @@ -3758,29 +3290,29 @@ select cast(cast('null' as jsonb) as double precision); select cast(cast('[1.0]' as jsonb) as double precision); -select cast(cast('1.0' as jsonb) as real); +select cast(cast('1.0' as jsonb) as float4); -select cast(cast('null' as jsonb) as real); +select cast(cast('null' as jsonb) as float4); -select cast(cast('[1.0]' as jsonb) as real); +select cast(cast('[1.0]' as jsonb) as float4); -select cast(cast('12345' as jsonb) as smallint); +select cast(cast('12345' as jsonb) as int2); -select cast(cast('null' as jsonb) as smallint); +select cast(cast('null' as jsonb) as int2); -select cast(cast('"hello"' as jsonb) as smallint); +select cast(cast('"hello"' as jsonb) as int2); -select cast(cast('12345' as jsonb) as int); +select cast(cast('12345' as jsonb) as int4); -select cast(cast('null' as jsonb) as int); +select cast(cast('null' as jsonb) as int4); -select cast(cast('"hello"' as jsonb) as int); +select cast(cast('"hello"' as jsonb) as int4); -select cast(cast('12345' as jsonb) as bigint); +select cast(cast('12345' as jsonb) as int8); -select cast(cast('null' as jsonb) as bigint); +select cast(cast('null' as jsonb) as int8); -select cast(cast('"hello"' as jsonb) as bigint); +select cast(cast('"hello"' as jsonb) as int8); select cast(cast('12345' as jsonb) as numeric); @@ -3790,42 +3322,36 @@ select cast(cast('{}' as jsonb) as numeric); select cast(cast('12345.05' as jsonb) as numeric); -select cast(cast('12345.05' as jsonb) as real); +select cast(cast('12345.05' as jsonb) as float4); -select cast(cast('12345.05' as jsonb) as double precision); +select cast(cast('12345.05' as jsonb) as float8); -select cast(cast('12345.05' as jsonb) as smallint); +select cast(cast('12345.05' as jsonb) as int2); -select cast(cast('12345.05' as jsonb) as int); +select cast(cast('12345.05' as jsonb) as int4); -select cast(cast('12345.05' as jsonb) as bigint); +select cast(cast('12345.05' as jsonb) as int8); select - cast(cast('12345.0000000000000000000000000000000000000000000005' - as jsonb) + cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) as numeric); select - cast(cast('12345.0000000000000000000000000000000000000000000005' - as jsonb) - as real); + cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) + as float4); select - cast(cast('12345.0000000000000000000000000000000000000000000005' - as jsonb) - as double precision); + cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) + as float8); select - cast(cast('12345.0000000000000000000000000000000000000000000005' - as jsonb) - as smallint); + cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) + as int2); select - cast(cast('12345.0000000000000000000000000000000000000000000005' - as jsonb) - as int); + cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) + as int4); select - cast(cast('12345.0000000000000000000000000000000000000000000005' - as jsonb) - as bigint); + cast(cast('12345.0000000000000000000000000000000000000000000005' as jsonb) + as int8); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_jsonpath_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_jsonpath_100.snap index 48d7ecdad..6ea6aa884 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_jsonpath_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_jsonpath_100.snap @@ -45,7 +45,7 @@ select cast('[1]' as jsonb) @? 'strict $[1]'; select jsonb_path_query('[1]', 'strict $[1]'); -select jsonb_path_query('[1]', 'strict $[1]', "silent" := true); +select jsonb_path_query('[1]', 'strict $[1]', silent := true); select cast('[1]' as jsonb) @? 'lax $[10000000000000000]'; @@ -83,13 +83,13 @@ select cast('1' as jsonb) @? '$ ? ((@ == 1) is unknown)'; select cast('[{"a": 1}, {"a": 2}]' as jsonb) @? '$[0 to 1] ? (@.a > 1)'; -select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', "silent" := false); +select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', silent := false); -select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', "silent" := true); +select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', silent := true); -select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', "silent" := false); +select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent := false); -select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', "silent" := true); +select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent := true); select jsonb_path_query('1', 'lax $.a'); @@ -97,21 +97,21 @@ select jsonb_path_query('1', 'strict $.a'); select jsonb_path_query('1', 'strict $.*'); -select jsonb_path_query('1', 'strict $.a', "silent" := true); +select jsonb_path_query('1', 'strict $.a', silent := true); -select jsonb_path_query('1', 'strict $.*', "silent" := true); +select jsonb_path_query('1', 'strict $.*', silent := true); select jsonb_path_query('[]', 'lax $.a'); select jsonb_path_query('[]', 'strict $.a'); -select jsonb_path_query('[]', 'strict $.a', "silent" := true); +select jsonb_path_query('[]', 'strict $.a', silent := true); select jsonb_path_query('{}', 'lax $.a'); select jsonb_path_query('{}', 'strict $.a'); -select jsonb_path_query('{}', 'strict $.a', "silent" := true); +select jsonb_path_query('{}', 'strict $.a', silent := true); select jsonb_path_query('1', 'strict $[1]'); @@ -121,13 +121,13 @@ select jsonb_path_query('[]', 'strict $[1]'); select jsonb_path_query('[]', 'strict $["a"]'); -select jsonb_path_query('1', 'strict $[1]', "silent" := true); +select jsonb_path_query('1', 'strict $[1]', silent := true); -select jsonb_path_query('1', 'strict $[*]', "silent" := true); +select jsonb_path_query('1', 'strict $[*]', silent := true); -select jsonb_path_query('[]', 'strict $[1]', "silent" := true); +select jsonb_path_query('[]', 'strict $[1]', silent := true); -select jsonb_path_query('[]', 'strict $["a"]', "silent" := true); +select jsonb_path_query('[]', 'strict $["a"]', silent := true); select jsonb_path_query('{"a": 12, "b": {"a": 13}}', '$.a'); @@ -167,7 +167,7 @@ select jsonb_path_query('[1,2,3]', 'lax $[*]'); select jsonb_path_query('[1,2,3]', 'strict $[*].a'); -select jsonb_path_query('[1,2,3]', 'strict $[*].a', "silent" := true); +select jsonb_path_query('[1,2,3]', 'strict $[*].a', silent := true); select jsonb_path_query('[]', '$[last]'); @@ -175,7 +175,7 @@ select jsonb_path_query('[]', '$[last ? (exists(last))]'); select jsonb_path_query('[]', 'strict $[last]'); -select jsonb_path_query('[]', 'strict $[last]', "silent" := true); +select jsonb_path_query('[]', 'strict $[last]', silent := true); select jsonb_path_query('[1]', '$[last]'); @@ -187,7 +187,7 @@ select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "number")]'); select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]'); -select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]', "silent" := true); +select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]', silent := true); select * from jsonb_path_query('{"a": 10}', '$'); @@ -208,11 +208,7 @@ select * from jsonb_path_query('[10,11,12,13,14,15]', '$[*] ? (@ < $value)', '{" select * from - jsonb_path_query( - '[10,11,12,13,14,15]', - '$[0,1] ? (@ < $x.value)', - '{"x": {"value" : 13}}' - ); + jsonb_path_query('[10,11,12,13,14,15]', '$[0,1] ? (@ < $x.value)', '{"x": {"value" : 13}}'); select * from jsonb_path_query('[10,11,12,13,14,15]', '$[0 to 2] ? (@ < $value)', '{"value" : 15}'); @@ -311,80 +307,37 @@ select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'lax $.g ? (exists (@.x)) select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'lax $.g ? (exists (@.x + "3"))'); select - jsonb_path_query( - '{"g": [{"x": 2}, {"y": 3}]}', - 'lax $.g ? ((exists (@.x + "3")) is unknown)' - ); + jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'lax $.g ? ((exists (@.x + "3")) is unknown)'); select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'strict $.g[*] ? (exists (@.x))'); select - jsonb_path_query( - '{"g": [{"x": 2}, {"y": 3}]}', - 'strict $.g[*] ? ((exists (@.x)) is unknown)' - ); + jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'strict $.g[*] ? ((exists (@.x)) is unknown)'); select jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'strict $.g ? (exists (@[*].x))'); select - jsonb_path_query( - '{"g": [{"x": 2}, {"y": 3}]}', - 'strict $.g ? ((exists (@[*].x)) is unknown)' - ); + jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'strict $.g ? ((exists (@[*].x)) is unknown)'); select x, y, - jsonb_path_query( - '[true, false, null]', - '$[*] ? (@ == true && ($x == true && $y == true) || + jsonb_path_query('[true, false, null]', '$[*] ? (@ == true && ($x == true && $y == true) || @ == false && !($x == true && $y == true) || - @ == null && ($x == true && $y == true) is unknown)', - jsonb_build_object('x', x, 'y', y) - ) - as "x && y" + @ == null && ($x == true && $y == true) is unknown)', jsonb_build_object('x', x, 'y', y)) as "x && y" from - ( - values - (cast('true' as jsonb)), - ('false'), - ('"null"') - ) - as x (x), - ( - values - (cast('true' as jsonb)), - ('false'), - ('"null"') - ) - as y (y); + (values (cast('true' as jsonb)), ('false'), ('"null"')) as x (x), + (values (cast('true' as jsonb)), ('false'), ('"null"')) as y (y); select x, y, - jsonb_path_query( - '[true, false, null]', - '$[*] ? (@ == true && ($x == true || $y == true) || + jsonb_path_query('[true, false, null]', '$[*] ? (@ == true && ($x == true || $y == true) || @ == false && !($x == true || $y == true) || - @ == null && ($x == true || $y == true) is unknown)', - jsonb_build_object('x', x, 'y', y) - ) - as "x || y" + @ == null && ($x == true || $y == true) is unknown)', jsonb_build_object('x', x, 'y', y)) as "x || y" from - ( - values - (cast('true' as jsonb)), - ('false'), - ('"null"') - ) - as x (x), - ( - values - (cast('true' as jsonb)), - ('false'), - ('"null"') - ) - as y (y); + (values (cast('true' as jsonb)), ('false'), ('"null"')) as x (x), + (values (cast('true' as jsonb)), ('false'), ('"null"')) as y (y); select cast('{"a": 1, "b":1}' as jsonb) @? '$ ? (@.a == @.b)'; @@ -450,13 +403,13 @@ select jsonb_path_query('"a"', '-$'); select jsonb_path_query('[1,"2",3]', '+$'); -select jsonb_path_query('1', '$ + "2"', "silent" := true); +select jsonb_path_query('1', '$ + "2"', silent := true); -select jsonb_path_query('[1, 2]', '3 * $', "silent" := true); +select jsonb_path_query('[1, 2]', '3 * $', silent := true); -select jsonb_path_query('"a"', '-$', "silent" := true); +select jsonb_path_query('"a"', '-$', silent := true); -select jsonb_path_query('[1,"2",3]', '+$', "silent" := true); +select jsonb_path_query('[1,"2",3]', '+$', silent := true); select cast('["1",2,0,3]' as jsonb) @? '-$[*]'; @@ -474,7 +427,7 @@ select jsonb_path_query('{"a": [2, 3, 4]}', 'lax -$.a'); select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3'); -select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3', "silent" := true); +select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3', silent := true); select jsonb_path_query('{"a": [1,2,3], "b": [3,4,5]}', '$.*'); @@ -522,13 +475,13 @@ select jsonb_path_match('[[1, true], [2, false]]', 'strict $[*] ? (@[0] > $x) [1 select jsonb_path_match('[[1, true], [2, false]]', 'strict $[*] ? (@[0] < $x) [1]', '{"x": 2}'); -select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'lax exists($[*].a)', "silent" := false); +select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'lax exists($[*].a)', silent := false); -select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'lax exists($[*].a)', "silent" := true); +select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'lax exists($[*].a)', silent := true); -select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'strict exists($[*].a)', "silent" := false); +select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'strict exists($[*].a)', silent := false); -select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'strict exists($[*].a)', "silent" := true); +select jsonb_path_match('[{"a": 1}, {"a": 2}, 3]', 'strict exists($[*].a)', silent := true); select jsonb_path_query('[null,1,true,"a",[],{}]', '$.type()'); @@ -562,7 +515,7 @@ select jsonb_path_query( '[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'strict $[*].size()', - "silent" := true + silent := true ); select jsonb_path_query('[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'lax $[*].size()'); @@ -579,7 +532,7 @@ select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].ceiling().abs().type()'); select jsonb_path_query('[{},1]', '$[*].keyvalue()'); -select jsonb_path_query('[{},1]', '$[*].keyvalue()', "silent" := true); +select jsonb_path_query('[{},1]', '$[*].keyvalue()', silent := true); select jsonb_path_query('{}', '$.keyvalue()'); @@ -601,9 +554,9 @@ select jsonb_path_query('null', '$.double()'); select jsonb_path_query('true', '$.double()'); -select jsonb_path_query('null', '$.double()', "silent" := true); +select jsonb_path_query('null', '$.double()', silent := true); -select jsonb_path_query('true', '$.double()', "silent" := true); +select jsonb_path_query('true', '$.double()', silent := true); select jsonb_path_query('[]', '$.double()'); @@ -611,9 +564,9 @@ select jsonb_path_query('[]', 'strict $.double()'); select jsonb_path_query('{}', '$.double()'); -select jsonb_path_query('[]', 'strict $.double()', "silent" := true); +select jsonb_path_query('[]', 'strict $.double()', silent := true); -select jsonb_path_query('{}', '$.double()', "silent" := true); +select jsonb_path_query('{}', '$.double()', silent := true); select jsonb_path_query('1.23', '$.double()'); @@ -631,9 +584,9 @@ select jsonb_path_query('"inf"', '$.double()'); select jsonb_path_query('"-inf"', '$.double()'); -select jsonb_path_query('"inf"', '$.double()', "silent" := true); +select jsonb_path_query('"inf"', '$.double()', silent := true); -select jsonb_path_query('"-inf"', '$.double()', "silent" := true); +select jsonb_path_query('"-inf"', '$.double()', silent := true); select jsonb_path_query('{}', '$.abs()'); @@ -641,11 +594,11 @@ select jsonb_path_query('true', '$.floor()'); select jsonb_path_query('"1.2"', '$.ceiling()'); -select jsonb_path_query('{}', '$.abs()', "silent" := true); +select jsonb_path_query('{}', '$.abs()', silent := true); -select jsonb_path_query('true', '$.floor()', "silent" := true); +select jsonb_path_query('true', '$.floor()', silent := true); -select jsonb_path_query('"1.2"', '$.ceiling()', "silent" := true); +select jsonb_path_query('"1.2"', '$.ceiling()', silent := true); select jsonb_path_query('["", "a", "abc", "abcabc"]', '$[*] ? (@ starts with "abc")'); @@ -664,16 +617,10 @@ select select jsonb_path_query('[[null, 1, "abc", "abcabc"]]', 'lax $ ? (@[*] starts with "abc")'); select - jsonb_path_query( - '[[null, 1, "abd", "abdabc"]]', - 'lax $ ? ((@[*] starts with "abc") is unknown)' - ); + jsonb_path_query('[[null, 1, "abd", "abdabc"]]', 'lax $ ? ((@[*] starts with "abc") is unknown)'); select - jsonb_path_query( - '[null, 1, "abd", "abdabc"]', - 'lax $[*] ? ((@ starts with "abc") is unknown)' - ); + jsonb_path_query('[null, 1, "abd", "abdabc"]', 'lax $[*] ? ((@ starts with "abc") is unknown)'); select jsonb_path_query( @@ -766,10 +713,7 @@ select jsonb_path_query('"10-03-2017 12:34"', '$.datetime("dd-mm-yyyy").type()') select jsonb_path_query('"10-03-2017 12:34"', ' $.datetime("dd-mm-yyyy HH24:MI").type()'); select - jsonb_path_query( - '"10-03-2017 12:34 +05:20"', - '$.datetime("dd-mm-yyyy HH24:MI TZH:TZM").type()' - ); + jsonb_path_query('"10-03-2017 12:34 +05:20"', '$.datetime("dd-mm-yyyy HH24:MI TZH:TZM").type()'); select jsonb_path_query('"12:34:56"', '$.datetime("HH24:MI:SS").type()'); @@ -785,9 +729,9 @@ select jsonb_path_query('null', '$.bigint()'); select jsonb_path_query('true', '$.bigint()'); -select jsonb_path_query('null', '$.bigint()', "silent" := true); +select jsonb_path_query('null', '$.bigint()', silent := true); -select jsonb_path_query('true', '$.bigint()', "silent" := true); +select jsonb_path_query('true', '$.bigint()', silent := true); select jsonb_path_query('[]', '$.bigint()'); @@ -795,9 +739,9 @@ select jsonb_path_query('[]', 'strict $.bigint()'); select jsonb_path_query('{}', '$.bigint()'); -select jsonb_path_query('[]', 'strict $.bigint()', "silent" := true); +select jsonb_path_query('[]', 'strict $.bigint()', silent := true); -select jsonb_path_query('{}', '$.bigint()', "silent" := true); +select jsonb_path_query('{}', '$.bigint()', silent := true); select jsonb_path_query('"1.23"', '$.bigint()'); @@ -813,9 +757,9 @@ select jsonb_path_query('"inf"', '$.bigint()'); select jsonb_path_query('"-inf"', '$.bigint()'); -select jsonb_path_query('"inf"', '$.bigint()', "silent" := true); +select jsonb_path_query('"inf"', '$.bigint()', silent := true); -select jsonb_path_query('"-inf"', '$.bigint()', "silent" := true); +select jsonb_path_query('"-inf"', '$.bigint()', silent := true); select jsonb_path_query('123', '$.bigint()'); @@ -843,7 +787,7 @@ select jsonb_path_query('123', '$.bigint() * 2'); select jsonb_path_query('null', '$.boolean()'); -select jsonb_path_query('null', '$.boolean()', "silent" := true); +select jsonb_path_query('null', '$.boolean()', silent := true); select jsonb_path_query('[]', '$.boolean()'); @@ -851,9 +795,9 @@ select jsonb_path_query('[]', 'strict $.boolean()'); select jsonb_path_query('{}', '$.boolean()'); -select jsonb_path_query('[]', 'strict $.boolean()', "silent" := true); +select jsonb_path_query('[]', 'strict $.boolean()', silent := true); -select jsonb_path_query('{}', '$.boolean()', "silent" := true); +select jsonb_path_query('{}', '$.boolean()', silent := true); select jsonb_path_query('1.23', '$.boolean()'); @@ -871,9 +815,9 @@ select jsonb_path_query('"inf"', '$.boolean()'); select jsonb_path_query('"-inf"', '$.boolean()'); -select jsonb_path_query('"inf"', '$.boolean()', "silent" := true); +select jsonb_path_query('"inf"', '$.boolean()', silent := true); -select jsonb_path_query('"-inf"', '$.boolean()', "silent" := true); +select jsonb_path_query('"-inf"', '$.boolean()', silent := true); select jsonb_path_query('"100"', '$.boolean()'); @@ -957,9 +901,9 @@ select jsonb_path_query('null', '$.decimal()'); select jsonb_path_query('true', '$.decimal()'); -select jsonb_path_query('null', '$.decimal()', "silent" := true); +select jsonb_path_query('null', '$.decimal()', silent := true); -select jsonb_path_query('true', '$.decimal()', "silent" := true); +select jsonb_path_query('true', '$.decimal()', silent := true); select jsonb_path_query('[]', '$.decimal()'); @@ -967,9 +911,9 @@ select jsonb_path_query('[]', 'strict $.decimal()'); select jsonb_path_query('{}', '$.decimal()'); -select jsonb_path_query('[]', 'strict $.decimal()', "silent" := true); +select jsonb_path_query('[]', 'strict $.decimal()', silent := true); -select jsonb_path_query('{}', '$.decimal()', "silent" := true); +select jsonb_path_query('{}', '$.decimal()', silent := true); select jsonb_path_query('1.23', '$.decimal()'); @@ -987,9 +931,9 @@ select jsonb_path_query('"inf"', '$.decimal()'); select jsonb_path_query('"-inf"', '$.decimal()'); -select jsonb_path_query('"inf"', '$.decimal()', "silent" := true); +select jsonb_path_query('"inf"', '$.decimal()', silent := true); -select jsonb_path_query('"-inf"', '$.decimal()', "silent" := true); +select jsonb_path_query('"-inf"', '$.decimal()', silent := true); select jsonb_path_query('123', '$.decimal()'); @@ -1045,9 +989,9 @@ select jsonb_path_query('null', '$.integer()'); select jsonb_path_query('true', '$.integer()'); -select jsonb_path_query('null', '$.integer()', "silent" := true); +select jsonb_path_query('null', '$.integer()', silent := true); -select jsonb_path_query('true', '$.integer()', "silent" := true); +select jsonb_path_query('true', '$.integer()', silent := true); select jsonb_path_query('[]', '$.integer()'); @@ -1055,9 +999,9 @@ select jsonb_path_query('[]', 'strict $.integer()'); select jsonb_path_query('{}', '$.integer()'); -select jsonb_path_query('[]', 'strict $.integer()', "silent" := true); +select jsonb_path_query('[]', 'strict $.integer()', silent := true); -select jsonb_path_query('{}', '$.integer()', "silent" := true); +select jsonb_path_query('{}', '$.integer()', silent := true); select jsonb_path_query('"1.23"', '$.integer()'); @@ -1073,9 +1017,9 @@ select jsonb_path_query('"inf"', '$.integer()'); select jsonb_path_query('"-inf"', '$.integer()'); -select jsonb_path_query('"inf"', '$.integer()', "silent" := true); +select jsonb_path_query('"inf"', '$.integer()', silent := true); -select jsonb_path_query('"-inf"', '$.integer()', "silent" := true); +select jsonb_path_query('"-inf"', '$.integer()', silent := true); select jsonb_path_query('123', '$.integer()'); @@ -1101,9 +1045,9 @@ select jsonb_path_query('null', '$.number()'); select jsonb_path_query('true', '$.number()'); -select jsonb_path_query('null', '$.number()', "silent" := true); +select jsonb_path_query('null', '$.number()', silent := true); -select jsonb_path_query('true', '$.number()', "silent" := true); +select jsonb_path_query('true', '$.number()', silent := true); select jsonb_path_query('[]', '$.number()'); @@ -1111,9 +1055,9 @@ select jsonb_path_query('[]', 'strict $.number()'); select jsonb_path_query('{}', '$.number()'); -select jsonb_path_query('[]', 'strict $.number()', "silent" := true); +select jsonb_path_query('[]', 'strict $.number()', silent := true); -select jsonb_path_query('{}', '$.number()', "silent" := true); +select jsonb_path_query('{}', '$.number()', silent := true); select jsonb_path_query('1.23', '$.number()'); @@ -1131,9 +1075,9 @@ select jsonb_path_query('"inf"', '$.number()'); select jsonb_path_query('"-inf"', '$.number()'); -select jsonb_path_query('"inf"', '$.number()', "silent" := true); +select jsonb_path_query('"inf"', '$.number()', silent := true); -select jsonb_path_query('"-inf"', '$.number()', "silent" := true); +select jsonb_path_query('"-inf"', '$.number()', silent := true); select jsonb_path_query('123', '$.number()'); @@ -1153,7 +1097,7 @@ select jsonb_path_query('12.3', '$.number() * 2'); select jsonb_path_query('null', '$.string()'); -select jsonb_path_query('null', '$.string()', "silent" := true); +select jsonb_path_query('null', '$.string()', silent := true); select jsonb_path_query('[]', '$.string()'); @@ -1161,9 +1105,9 @@ select jsonb_path_query('[]', 'strict $.string()'); select jsonb_path_query('{}', '$.string()'); -select jsonb_path_query('[]', 'strict $.string()', "silent" := true); +select jsonb_path_query('[]', 'strict $.string()', silent := true); -select jsonb_path_query('{}', '$.string()', "silent" := true); +select jsonb_path_query('{}', '$.string()', silent := true); select jsonb_path_query('1.23', '$.string()'); @@ -1211,9 +1155,9 @@ select jsonb_path_query('"2023-08-15"', '$.date().string()'); begin; -set local time zone UTC; +set local time zone 'UTC'; -set local datestyle = German; +set local datestyle = 'German'; select jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp_tz().string()'); @@ -2036,8 +1980,7 @@ select select jsonb_path_query( '"1000000-01-01"', - cast('$.datetime() > "2020-01-01 12:00:00".datetime()' - as jsonpath) + cast('$.datetime() > "2020-01-01 12:00:00".datetime()' as jsonpath) ); set timezone to default; @@ -2062,19 +2005,19 @@ select jsonb_path_query_array( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', - "vars" := '{"min": 1, "max": 4}' + vars := '{"min": 1, "max": 4}' ); select jsonb_path_query_array( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', - "vars" := '{"min": 3, "max": 4}' + vars := '{"min": 3, "max": 4}' ); select jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a'); -select jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a', "silent" := true); +select jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a', silent := true); select jsonb_path_query_first('[{"a": 1}, {"a": 2}]', '$[*].a'); @@ -2086,14 +2029,14 @@ select jsonb_path_query_first( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', - "vars" := '{"min": 1, "max": 4}' + vars := '{"min": 1, "max": 4}' ); select jsonb_path_query_first( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', - "vars" := '{"min": 3, "max": 4}' + vars := '{"min": 3, "max": 4}' ); select jsonb_path_query_first('[{"a": 1}]', '$undefined_var'); @@ -2110,43 +2053,43 @@ select jsonb_path_exists( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', - "vars" := '{"min": 1, "max": 4}' + vars := '{"min": 1, "max": 4}' ); select jsonb_path_exists( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', - "vars" := '{"min": 3, "max": 4}' + vars := '{"min": 3, "max": 4}' ); select jsonb_path_exists('[{"a": 1}]', '$undefined_var'); select jsonb_path_exists('[{"a": 1}]', 'false'); -select jsonb_path_match('true', '$', "silent" := false); +select jsonb_path_match('true', '$', silent := false); -select jsonb_path_match('false', '$', "silent" := false); +select jsonb_path_match('false', '$', silent := false); -select jsonb_path_match('null', '$', "silent" := false); +select jsonb_path_match('null', '$', silent := false); -select jsonb_path_match('1', '$', "silent" := true); +select jsonb_path_match('1', '$', silent := true); -select jsonb_path_match('1', '$', "silent" := false); +select jsonb_path_match('1', '$', silent := false); -select jsonb_path_match('"a"', '$', "silent" := false); +select jsonb_path_match('"a"', '$', silent := false); -select jsonb_path_match('{}', '$', "silent" := false); +select jsonb_path_match('{}', '$', silent := false); -select jsonb_path_match('[true]', '$', "silent" := false); +select jsonb_path_match('[true]', '$', silent := false); -select jsonb_path_match('{}', 'lax $.a', "silent" := false); +select jsonb_path_match('{}', 'lax $.a', silent := false); -select jsonb_path_match('{}', 'strict $.a', "silent" := false); +select jsonb_path_match('{}', 'strict $.a', silent := false); -select jsonb_path_match('{}', 'strict $.a', "silent" := true); +select jsonb_path_match('{}', 'strict $.a', silent := true); -select jsonb_path_match('[true, true]', '$[*]', "silent" := false); +select jsonb_path_match('[true, true]', '$[*]', silent := false); select cast('[{"a": 1}, {"a": 2}]' as jsonb) @@ '$[*].a > 1'; @@ -2159,16 +2102,14 @@ select jsonb_path_match('[{"a": 1}]', '$undefined_var'); select jsonb_path_match('[{"a": 1}]', 'false'); with -str (j, -num) +str (j, num) as ( select jsonb_build_object('s', s), num from unnest( - cast('{"", "a", "ab", "abc", "abcd", "b", "A", "AB", "ABC", "ABc", "ABcD", "B"}' - as text[]) + cast('{"", "a", "ab", "abc", "abcd", "b", "A", "AB", "ABC", "ABc", "ABcD", "B"}' as text[]) ) with ordinality as a (s, num) @@ -2176,36 +2117,11 @@ as ( select s1.j, s2.j, - jsonb_path_query_first( - s1.j, - '$.s < $s', - "vars" := s2.j - ) - as lt, - jsonb_path_query_first( - s1.j, - '$.s <= $s', - "vars" := s2.j - ) - as le, - jsonb_path_query_first( - s1.j, - '$.s == $s', - "vars" := s2.j - ) - as eq, - jsonb_path_query_first( - s1.j, - '$.s >= $s', - "vars" := s2.j - ) - as ge, - jsonb_path_query_first( - s1.j, - '$.s > $s', - "vars" := s2.j - ) - as gt + jsonb_path_query_first(s1.j, '$.s < $s', vars := s2.j) as lt, + jsonb_path_query_first(s1.j, '$.s <= $s', vars := s2.j) as le, + jsonb_path_query_first(s1.j, '$.s == $s', vars := s2.j) as eq, + jsonb_path_query_first(s1.j, '$.s >= $s', vars := s2.j) as ge, + jsonb_path_query_first(s1.j, '$.s > $s', vars := s2.j) as gt from str as s1, str as s2 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_jsonpath_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_jsonpath_80.snap index fdfceb477..f1311ee40 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_jsonpath_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonb_jsonpath_80.snap @@ -45,7 +45,7 @@ select cast('[1]' as jsonb) @? 'strict $[1]'; select jsonb_path_query('[1]', 'strict $[1]'); -select jsonb_path_query('[1]', 'strict $[1]', "silent" := true); +select jsonb_path_query('[1]', 'strict $[1]', silent := true); select cast('[1]' as jsonb) @? 'lax $[10000000000000000]'; @@ -68,29 +68,20 @@ select cast('[1]' as jsonb) @? '$[1.2]'; select cast('[1]' as jsonb) @? 'strict $[1.2]'; select - cast('{"a": [1,2,3], "b": [3,4,5]}' - as jsonb) @? - '$ ? (@.a[*] > @.b[*])'; + cast('{"a": [1,2,3], "b": [3,4,5]}' as jsonb) @? '$ ? (@.a[*] > @.b[*])'; select - cast('{"a": [1,2,3], "b": [3,4,5]}' - as jsonb) @? - '$ ? (@.a[*] >= @.b[*])'; + cast('{"a": [1,2,3], "b": [3,4,5]}' as jsonb) @? '$ ? (@.a[*] >= @.b[*])'; select - cast('{"a": [1,2,3], "b": [3,4,"5"]}' - as jsonb) @? - '$ ? (@.a[*] >= @.b[*])'; + cast('{"a": [1,2,3], "b": [3,4,"5"]}' as jsonb) @? '$ ? (@.a[*] >= @.b[*])'; select - cast('{"a": [1,2,3], "b": [3,4,"5"]}' - as jsonb) @? + cast('{"a": [1,2,3], "b": [3,4,"5"]}' as jsonb) @? 'strict $ ? (@.a[*] >= @.b[*])'; select - cast('{"a": [1,2,3], "b": [3,4,null]}' - as jsonb) @? - '$ ? (@.a[*] >= @.b[*])'; + cast('{"a": [1,2,3], "b": [3,4,null]}' as jsonb) @? '$ ? (@.a[*] >= @.b[*])'; select cast('1' as jsonb) @? '$ ? ((@ == "1") is unknown)'; @@ -99,32 +90,20 @@ select cast('1' as jsonb) @? '$ ? ((@ == 1) is unknown)'; select cast('[{"a": 1}, {"a": 2}]' as jsonb) @? '$[0 to 1] ? (@.a > 1)'; select - jsonb_path_exists( - '[{"a": 1}, {"a": 2}, 3]', - 'lax $[*].a', - "silent" := false - ); + jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', silent := false); select - jsonb_path_exists( - '[{"a": 1}, {"a": 2}, 3]', - 'lax $[*].a', - "silent" := true - ); + jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', silent := true); select jsonb_path_exists( '[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', - "silent" := false + silent := false ); select - jsonb_path_exists( - '[{"a": 1}, {"a": 2}, 3]', - 'strict $[*].a', - "silent" := true - ); + jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent := true); select jsonb_path_query('1', 'lax $.a'); @@ -132,21 +111,21 @@ select jsonb_path_query('1', 'strict $.a'); select jsonb_path_query('1', 'strict $.*'); -select jsonb_path_query('1', 'strict $.a', "silent" := true); +select jsonb_path_query('1', 'strict $.a', silent := true); -select jsonb_path_query('1', 'strict $.*', "silent" := true); +select jsonb_path_query('1', 'strict $.*', silent := true); select jsonb_path_query('[]', 'lax $.a'); select jsonb_path_query('[]', 'strict $.a'); -select jsonb_path_query('[]', 'strict $.a', "silent" := true); +select jsonb_path_query('[]', 'strict $.a', silent := true); select jsonb_path_query('{}', 'lax $.a'); select jsonb_path_query('{}', 'strict $.a'); -select jsonb_path_query('{}', 'strict $.a', "silent" := true); +select jsonb_path_query('{}', 'strict $.a', silent := true); select jsonb_path_query('1', 'strict $[1]'); @@ -156,13 +135,13 @@ select jsonb_path_query('[]', 'strict $[1]'); select jsonb_path_query('[]', 'strict $["a"]'); -select jsonb_path_query('1', 'strict $[1]', "silent" := true); +select jsonb_path_query('1', 'strict $[1]', silent := true); -select jsonb_path_query('1', 'strict $[*]', "silent" := true); +select jsonb_path_query('1', 'strict $[*]', silent := true); -select jsonb_path_query('[]', 'strict $[1]', "silent" := true); +select jsonb_path_query('[]', 'strict $[1]', silent := true); -select jsonb_path_query('[]', 'strict $["a"]', "silent" := true); +select jsonb_path_query('[]', 'strict $["a"]', silent := true); select jsonb_path_query('{"a": 12, "b": {"a": 13}}', '$.a'); @@ -206,7 +185,7 @@ select jsonb_path_query('[1,2,3]', 'lax $[*]'); select jsonb_path_query('[1,2,3]', 'strict $[*].a'); -select jsonb_path_query('[1,2,3]', 'strict $[*].a', "silent" := true); +select jsonb_path_query('[1,2,3]', 'strict $[*].a', silent := true); select jsonb_path_query('[]', '$[last]'); @@ -214,7 +193,7 @@ select jsonb_path_query('[]', '$[last ? (exists(last))]'); select jsonb_path_query('[]', 'strict $[last]'); -select jsonb_path_query('[]', 'strict $[last]', "silent" := true); +select jsonb_path_query('[]', 'strict $[last]', silent := true); select jsonb_path_query('[1]', '$[last]'); @@ -230,7 +209,7 @@ select jsonb_path_query( '[1,2,3]', '$[last ? (@.type() == "string")]', - "silent" := true + silent := true ); select * from jsonb_path_query('{"a": 10}', '$'); @@ -242,38 +221,22 @@ select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '1'); select * from - jsonb_path_query( - '{"a": 10}', - '$ ? (@.a < $value)', - '[{"value" : 13}]' - ); + jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '[{"value" : 13}]'); select * from - jsonb_path_query( - '{"a": 10}', - '$ ? (@.a < $value)', - '{"value" : 13}' - ); + jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '{"value" : 13}'); select * from - jsonb_path_query( - '{"a": 10}', - '$ ? (@.a < $value)', - '{"value" : 8}' - ); + jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '{"value" : 8}'); select * from - jsonb_path_query( - '{"a": 10}', - '$.a ? (@ < $value)', - '{"value" : 13}' - ); + jsonb_path_query('{"a": 10}', '$.a ? (@ < $value)', '{"value" : 13}'); select * @@ -367,28 +330,16 @@ select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{0}.b ? (@ > 0)'); select jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{1}.b ? (@ > 0)'); select - jsonb_path_query( - '{"a": {"c": {"b": 1}}}', - 'lax $.**{0 to last}.b ? (@ > 0)' - ); + jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{0 to last}.b ? (@ > 0)'); select - jsonb_path_query( - '{"a": {"c": {"b": 1}}}', - 'lax $.**{1 to last}.b ? (@ > 0)' - ); + jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{1 to last}.b ? (@ > 0)'); select - jsonb_path_query( - '{"a": {"c": {"b": 1}}}', - 'lax $.**{1 to 2}.b ? (@ > 0)' - ); + jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{1 to 2}.b ? (@ > 0)'); select - jsonb_path_query( - '{"a": {"c": {"b": 1}}}', - 'lax $.**{2 to 3}.b ? (@ > 0)' - ); + jsonb_path_query('{"a": {"c": {"b": 1}}}', 'lax $.**{2 to 3}.b ? (@ > 0)'); select cast('{"a": {"b": 1}}' as jsonb) @? '$.**.b ? ( @ > 0)'; @@ -409,12 +360,10 @@ select cast('{"a": {"c": {"b": 1}}}' as jsonb) @? '$.**{0}.b ? ( @ > 0)'; select cast('{"a": {"c": {"b": 1}}}' as jsonb) @? '$.**{1}.b ? ( @ > 0)'; select - cast('{"a": {"c": {"b": 1}}}' as jsonb) @? - '$.**{0 to last}.b ? ( @ > 0)'; + cast('{"a": {"c": {"b": 1}}}' as jsonb) @? '$.**{0 to last}.b ? ( @ > 0)'; select - cast('{"a": {"c": {"b": 1}}}' as jsonb) @? - '$.**{1 to last}.b ? ( @ > 0)'; + cast('{"a": {"c": {"b": 1}}}' as jsonb) @? '$.**{1 to last}.b ? ( @ > 0)'; select cast('{"a": {"c": {"b": 1}}}' as jsonb) @? '$.**{1 to 2}.b ? ( @ > 0)'; @@ -427,10 +376,7 @@ select jsonb_path_query('{"g": {"x": 2}}', '$.g ? (exists (@.y))'); select jsonb_path_query('{"g": {"x": 2}}', '$.g ? (exists (@.x ? (@ >= 2) ))'); select - jsonb_path_query( - '{"g": [{"x": 2}, {"y": 3}]}', - 'lax $.g ? (exists (@.x))' - ); + jsonb_path_query('{"g": [{"x": 2}, {"y": 3}]}', 'lax $.g ? (exists (@.x))'); select jsonb_path_query( @@ -480,20 +426,8 @@ select ) as "x && y" from - ( - values - (cast('true' as jsonb)), - ('false'), - ('"null"') - ) - as x (x), - ( - values - (cast('true' as jsonb)), - ('false'), - ('"null"') - ) - as y (y); + (values (cast('true' as jsonb)), ('false'), ('"null"')) as x (x), + (values (cast('true' as jsonb)), ('false'), ('"null"')) as y (y); select x, @@ -507,20 +441,8 @@ select ) as "x || y" from - ( - values - (cast('true' as jsonb)), - ('false'), - ('"null"') - ) - as x (x), - ( - values - (cast('true' as jsonb)), - ('false'), - ('"null"') - ) - as y (y); + (values (cast('true' as jsonb)), ('false'), ('"null"')) as x (x), + (values (cast('true' as jsonb)), ('false'), ('"null"')) as y (y); select cast('{"a": 1, "b":1}' as jsonb) @? '$ ? (@.a == @.b)'; @@ -586,13 +508,13 @@ select jsonb_path_query('"a"', '-$'); select jsonb_path_query('[1,"2",3]', '+$'); -select jsonb_path_query('1', '$ + "2"', "silent" := true); +select jsonb_path_query('1', '$ + "2"', silent := true); -select jsonb_path_query('[1, 2]', '3 * $', "silent" := true); +select jsonb_path_query('[1, 2]', '3 * $', silent := true); -select jsonb_path_query('"a"', '-$', "silent" := true); +select jsonb_path_query('"a"', '-$', silent := true); -select jsonb_path_query('[1,"2",3]', '+$', "silent" := true); +select jsonb_path_query('[1,"2",3]', '+$', silent := true); select cast('["1",2,0,3]' as jsonb) @? '-$[*]'; @@ -610,7 +532,7 @@ select jsonb_path_query('{"a": [2, 3, 4]}', 'lax -$.a'); select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3'); -select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3', "silent" := true); +select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3', silent := true); select jsonb_path_query('{"a": [1,2,3], "b": [3,4,5]}', '$.*'); @@ -672,28 +594,28 @@ select jsonb_path_match( '[{"a": 1}, {"a": 2}, 3]', 'lax exists($[*].a)', - "silent" := false + silent := false ); select jsonb_path_match( '[{"a": 1}, {"a": 2}, 3]', 'lax exists($[*].a)', - "silent" := true + silent := true ); select jsonb_path_match( '[{"a": 1}, {"a": 2}, 3]', 'strict exists($[*].a)', - "silent" := false + silent := false ); select jsonb_path_match( '[{"a": 1}, {"a": 2}, 3]', 'strict exists($[*].a)', - "silent" := true + silent := true ); select jsonb_path_query('[null,1,true,"a",[],{}]', '$.type()'); @@ -732,7 +654,7 @@ select jsonb_path_query( '[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'strict $[*].size()', - "silent" := true + silent := true ); select @@ -753,15 +675,12 @@ select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].ceiling().abs().type()'); select jsonb_path_query('[{},1]', '$[*].keyvalue()'); -select jsonb_path_query('[{},1]', '$[*].keyvalue()', "silent" := true); +select jsonb_path_query('[{},1]', '$[*].keyvalue()', silent := true); select jsonb_path_query('{}', '$.keyvalue()'); select - jsonb_path_query( - '{"a": 1, "b": [1, 2], "c": {"a": "bbb"}}', - '$.keyvalue()' - ); + jsonb_path_query('{"a": 1, "b": [1, 2], "c": {"a": "bbb"}}', '$.keyvalue()'); select jsonb_path_query( @@ -795,9 +714,9 @@ select jsonb_path_query('null', '$.double()'); select jsonb_path_query('true', '$.double()'); -select jsonb_path_query('null', '$.double()', "silent" := true); +select jsonb_path_query('null', '$.double()', silent := true); -select jsonb_path_query('true', '$.double()', "silent" := true); +select jsonb_path_query('true', '$.double()', silent := true); select jsonb_path_query('[]', '$.double()'); @@ -805,9 +724,9 @@ select jsonb_path_query('[]', 'strict $.double()'); select jsonb_path_query('{}', '$.double()'); -select jsonb_path_query('[]', 'strict $.double()', "silent" := true); +select jsonb_path_query('[]', 'strict $.double()', silent := true); -select jsonb_path_query('{}', '$.double()', "silent" := true); +select jsonb_path_query('{}', '$.double()', silent := true); select jsonb_path_query('1.23', '$.double()'); @@ -825,9 +744,9 @@ select jsonb_path_query('"inf"', '$.double()'); select jsonb_path_query('"-inf"', '$.double()'); -select jsonb_path_query('"inf"', '$.double()', "silent" := true); +select jsonb_path_query('"inf"', '$.double()', silent := true); -select jsonb_path_query('"-inf"', '$.double()', "silent" := true); +select jsonb_path_query('"-inf"', '$.double()', silent := true); select jsonb_path_query('{}', '$.abs()'); @@ -835,11 +754,11 @@ select jsonb_path_query('true', '$.floor()'); select jsonb_path_query('"1.2"', '$.ceiling()'); -select jsonb_path_query('{}', '$.abs()', "silent" := true); +select jsonb_path_query('{}', '$.abs()', silent := true); -select jsonb_path_query('true', '$.floor()', "silent" := true); +select jsonb_path_query('true', '$.floor()', silent := true); -select jsonb_path_query('"1.2"', '$.ceiling()', "silent" := true); +select jsonb_path_query('"1.2"', '$.ceiling()', silent := true); select jsonb_path_query( @@ -976,10 +895,7 @@ select jsonb_path_query('"10-03-2017"', '$.datetime("dd-mm-yyyy").type()'); select jsonb_path_query('"10-03-2017 12:34"', '$.datetime("dd-mm-yyyy")'); select - jsonb_path_query( - '"10-03-2017 12:34"', - '$.datetime("dd-mm-yyyy").type()' - ); + jsonb_path_query('"10-03-2017 12:34"', '$.datetime("dd-mm-yyyy").type()'); select jsonb_path_query( @@ -1023,9 +939,9 @@ select jsonb_path_query('null', '$.bigint()'); select jsonb_path_query('true', '$.bigint()'); -select jsonb_path_query('null', '$.bigint()', "silent" := true); +select jsonb_path_query('null', '$.bigint()', silent := true); -select jsonb_path_query('true', '$.bigint()', "silent" := true); +select jsonb_path_query('true', '$.bigint()', silent := true); select jsonb_path_query('[]', '$.bigint()'); @@ -1033,9 +949,9 @@ select jsonb_path_query('[]', 'strict $.bigint()'); select jsonb_path_query('{}', '$.bigint()'); -select jsonb_path_query('[]', 'strict $.bigint()', "silent" := true); +select jsonb_path_query('[]', 'strict $.bigint()', silent := true); -select jsonb_path_query('{}', '$.bigint()', "silent" := true); +select jsonb_path_query('{}', '$.bigint()', silent := true); select jsonb_path_query('"1.23"', '$.bigint()'); @@ -1051,9 +967,9 @@ select jsonb_path_query('"inf"', '$.bigint()'); select jsonb_path_query('"-inf"', '$.bigint()'); -select jsonb_path_query('"inf"', '$.bigint()', "silent" := true); +select jsonb_path_query('"inf"', '$.bigint()', silent := true); -select jsonb_path_query('"-inf"', '$.bigint()', "silent" := true); +select jsonb_path_query('"-inf"', '$.bigint()', silent := true); select jsonb_path_query('123', '$.bigint()'); @@ -1081,7 +997,7 @@ select jsonb_path_query('123', '$.bigint() * 2'); select jsonb_path_query('null', '$.boolean()'); -select jsonb_path_query('null', '$.boolean()', "silent" := true); +select jsonb_path_query('null', '$.boolean()', silent := true); select jsonb_path_query('[]', '$.boolean()'); @@ -1089,9 +1005,9 @@ select jsonb_path_query('[]', 'strict $.boolean()'); select jsonb_path_query('{}', '$.boolean()'); -select jsonb_path_query('[]', 'strict $.boolean()', "silent" := true); +select jsonb_path_query('[]', 'strict $.boolean()', silent := true); -select jsonb_path_query('{}', '$.boolean()', "silent" := true); +select jsonb_path_query('{}', '$.boolean()', silent := true); select jsonb_path_query('1.23', '$.boolean()'); @@ -1109,9 +1025,9 @@ select jsonb_path_query('"inf"', '$.boolean()'); select jsonb_path_query('"-inf"', '$.boolean()'); -select jsonb_path_query('"inf"', '$.boolean()', "silent" := true); +select jsonb_path_query('"inf"', '$.boolean()', silent := true); -select jsonb_path_query('"-inf"', '$.boolean()', "silent" := true); +select jsonb_path_query('"-inf"', '$.boolean()', silent := true); select jsonb_path_query('"100"', '$.boolean()'); @@ -1195,9 +1111,9 @@ select jsonb_path_query('null', '$.decimal()'); select jsonb_path_query('true', '$.decimal()'); -select jsonb_path_query('null', '$.decimal()', "silent" := true); +select jsonb_path_query('null', '$.decimal()', silent := true); -select jsonb_path_query('true', '$.decimal()', "silent" := true); +select jsonb_path_query('true', '$.decimal()', silent := true); select jsonb_path_query('[]', '$.decimal()'); @@ -1205,9 +1121,9 @@ select jsonb_path_query('[]', 'strict $.decimal()'); select jsonb_path_query('{}', '$.decimal()'); -select jsonb_path_query('[]', 'strict $.decimal()', "silent" := true); +select jsonb_path_query('[]', 'strict $.decimal()', silent := true); -select jsonb_path_query('{}', '$.decimal()', "silent" := true); +select jsonb_path_query('{}', '$.decimal()', silent := true); select jsonb_path_query('1.23', '$.decimal()'); @@ -1225,9 +1141,9 @@ select jsonb_path_query('"inf"', '$.decimal()'); select jsonb_path_query('"-inf"', '$.decimal()'); -select jsonb_path_query('"inf"', '$.decimal()', "silent" := true); +select jsonb_path_query('"inf"', '$.decimal()', silent := true); -select jsonb_path_query('"-inf"', '$.decimal()', "silent" := true); +select jsonb_path_query('"-inf"', '$.decimal()', silent := true); select jsonb_path_query('123', '$.decimal()'); @@ -1283,9 +1199,9 @@ select jsonb_path_query('null', '$.integer()'); select jsonb_path_query('true', '$.integer()'); -select jsonb_path_query('null', '$.integer()', "silent" := true); +select jsonb_path_query('null', '$.integer()', silent := true); -select jsonb_path_query('true', '$.integer()', "silent" := true); +select jsonb_path_query('true', '$.integer()', silent := true); select jsonb_path_query('[]', '$.integer()'); @@ -1293,9 +1209,9 @@ select jsonb_path_query('[]', 'strict $.integer()'); select jsonb_path_query('{}', '$.integer()'); -select jsonb_path_query('[]', 'strict $.integer()', "silent" := true); +select jsonb_path_query('[]', 'strict $.integer()', silent := true); -select jsonb_path_query('{}', '$.integer()', "silent" := true); +select jsonb_path_query('{}', '$.integer()', silent := true); select jsonb_path_query('"1.23"', '$.integer()'); @@ -1311,9 +1227,9 @@ select jsonb_path_query('"inf"', '$.integer()'); select jsonb_path_query('"-inf"', '$.integer()'); -select jsonb_path_query('"inf"', '$.integer()', "silent" := true); +select jsonb_path_query('"inf"', '$.integer()', silent := true); -select jsonb_path_query('"-inf"', '$.integer()', "silent" := true); +select jsonb_path_query('"-inf"', '$.integer()', silent := true); select jsonb_path_query('123', '$.integer()'); @@ -1339,9 +1255,9 @@ select jsonb_path_query('null', '$.number()'); select jsonb_path_query('true', '$.number()'); -select jsonb_path_query('null', '$.number()', "silent" := true); +select jsonb_path_query('null', '$.number()', silent := true); -select jsonb_path_query('true', '$.number()', "silent" := true); +select jsonb_path_query('true', '$.number()', silent := true); select jsonb_path_query('[]', '$.number()'); @@ -1349,9 +1265,9 @@ select jsonb_path_query('[]', 'strict $.number()'); select jsonb_path_query('{}', '$.number()'); -select jsonb_path_query('[]', 'strict $.number()', "silent" := true); +select jsonb_path_query('[]', 'strict $.number()', silent := true); -select jsonb_path_query('{}', '$.number()', "silent" := true); +select jsonb_path_query('{}', '$.number()', silent := true); select jsonb_path_query('1.23', '$.number()'); @@ -1369,9 +1285,9 @@ select jsonb_path_query('"inf"', '$.number()'); select jsonb_path_query('"-inf"', '$.number()'); -select jsonb_path_query('"inf"', '$.number()', "silent" := true); +select jsonb_path_query('"inf"', '$.number()', silent := true); -select jsonb_path_query('"-inf"', '$.number()', "silent" := true); +select jsonb_path_query('"-inf"', '$.number()', silent := true); select jsonb_path_query('123', '$.number()'); @@ -1391,7 +1307,7 @@ select jsonb_path_query('12.3', '$.number() * 2'); select jsonb_path_query('null', '$.string()'); -select jsonb_path_query('null', '$.string()', "silent" := true); +select jsonb_path_query('null', '$.string()', silent := true); select jsonb_path_query('[]', '$.string()'); @@ -1399,9 +1315,9 @@ select jsonb_path_query('[]', 'strict $.string()'); select jsonb_path_query('{}', '$.string()'); -select jsonb_path_query('[]', 'strict $.string()', "silent" := true); +select jsonb_path_query('[]', 'strict $.string()', silent := true); -select jsonb_path_query('{}', '$.string()', "silent" := true); +select jsonb_path_query('{}', '$.string()', silent := true); select jsonb_path_query('1.23', '$.string()'); @@ -1422,30 +1338,18 @@ select jsonb_path_query_array('[1.23, "yes", false]', '$[*].string()'); select jsonb_path_query_array('[1.23, "yes", false]', '$[*].string().type()'); select - jsonb_path_query( - '"2023-08-15 12:34:56 +5:30"', - '$.timestamp().string()' - ); + jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp().string()'); select - jsonb_path_query_tz( - '"2023-08-15 12:34:56 +5:30"', - '$.timestamp().string()' - ); + jsonb_path_query_tz('"2023-08-15 12:34:56 +5:30"', '$.timestamp().string()'); select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp_tz().string()'); select - jsonb_path_query_tz( - '"2023-08-15 12:34:56"', - '$.timestamp_tz().string()' - ); + jsonb_path_query_tz('"2023-08-15 12:34:56"', '$.timestamp_tz().string()'); select - jsonb_path_query( - '"2023-08-15 12:34:56 +5:30"', - '$.timestamp_tz().string()' - ); + jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp_tz().string()'); select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp().string()'); @@ -1465,15 +1369,12 @@ select jsonb_path_query('"2023-08-15"', '$.date().string()'); begin; -set local time zone UTC; +set local time zone 'UTC'; -set local datestyle = German; +set local datestyle = 'German'; select - jsonb_path_query( - '"2023-08-15 12:34:56 +5:30"', - '$.timestamp_tz().string()' - ); + jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp_tz().string()'); select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp().string()'); @@ -1594,10 +1495,7 @@ select jsonb_path_query('"2023-08-15 12:34:56.789"', '$.timestamp(-1)'); select jsonb_path_query('"2023-08-15 12:34:56.789"', '$.timestamp(2.0)'); select - jsonb_path_query( - '"2023-08-15 12:34:56.789"', - '$.timestamp(12345678901)' - ); + jsonb_path_query('"2023-08-15 12:34:56.789"', '$.timestamp(12345678901)'); select jsonb_path_query('"2023-08-15 12:34:56.789"', '$.timestamp(0)'); @@ -1628,10 +1526,7 @@ select cast('"2023-08-15 12:34:56 +05:30"' as jsonb) @? '$.timestamp_tz()'; select jsonb_path_query('"2023-08-15 12:34:56 +05:30"', '$.timestamp_tz()'); select - jsonb_path_query( - '"2023-08-15 12:34:56 +05:30"', - '$.timestamp_tz().type()' - ); + jsonb_path_query('"2023-08-15 12:34:56 +05:30"', '$.timestamp_tz().type()'); select jsonb_path_query('"2023-08-15"', '$.timestamp_tz()'); @@ -1642,16 +1537,10 @@ select jsonb_path_query('"12:34:56"', '$.timestamp_tz()'); select jsonb_path_query('"12:34:56 +05:30"', '$.timestamp_tz()'); select - jsonb_path_query( - '"2023-08-15 12:34:56.789 +05:30"', - '$.timestamp_tz(-1)' - ); + jsonb_path_query('"2023-08-15 12:34:56.789 +05:30"', '$.timestamp_tz(-1)'); select - jsonb_path_query( - '"2023-08-15 12:34:56.789 +05:30"', - '$.timestamp_tz(2.0)' - ); + jsonb_path_query('"2023-08-15 12:34:56.789 +05:30"', '$.timestamp_tz(2.0)'); select jsonb_path_query( @@ -1660,34 +1549,19 @@ select ); select - jsonb_path_query( - '"2023-08-15 12:34:56.789 +05:30"', - '$.timestamp_tz(0)' - ); + jsonb_path_query('"2023-08-15 12:34:56.789 +05:30"', '$.timestamp_tz(0)'); select - jsonb_path_query( - '"2023-08-15 12:34:56.789 +05:30"', - '$.timestamp_tz(2)' - ); + jsonb_path_query('"2023-08-15 12:34:56.789 +05:30"', '$.timestamp_tz(2)'); select - jsonb_path_query( - '"2023-08-15 12:34:56.789 +05:30"', - '$.timestamp_tz(5)' - ); + jsonb_path_query('"2023-08-15 12:34:56.789 +05:30"', '$.timestamp_tz(5)'); select - jsonb_path_query( - '"2023-08-15 12:34:56.789 +05:30"', - '$.timestamp_tz(10)' - ); + jsonb_path_query('"2023-08-15 12:34:56.789 +05:30"', '$.timestamp_tz(10)'); select - jsonb_path_query( - '"2023-08-15 12:34:56.789012 +05:30"', - '$.timestamp_tz(8)' - ); + jsonb_path_query('"2023-08-15 12:34:56.789012 +05:30"', '$.timestamp_tz(8)'); set time zone '+00'; @@ -1710,10 +1584,7 @@ select jsonb_path_query('"2023-08-15 12:34:56"', '$.timestamp_tz()'); select jsonb_path_query_tz('"2023-08-15 12:34:56"', '$.timestamp_tz()'); select - jsonb_path_query( - '"10-03-2017 12:34"', - '$.datetime("dd-mm-yyyy HH24:MI")' - ); + jsonb_path_query('"10-03-2017 12:34"', '$.datetime("dd-mm-yyyy HH24:MI")'); select jsonb_path_query( @@ -1776,10 +1647,7 @@ select jsonb_path_query_tz('"2023-08-15 12:34:56"', '$.timestamp_tz()'); select jsonb_path_query('"2023-08-15 12:34:56 +05:30"', '$.timestamp_tz()'); select - jsonb_path_query( - '"10-03-2017 12:34"', - '$.datetime("dd-mm-yyyy HH24:MI")' - ); + jsonb_path_query('"10-03-2017 12:34"', '$.datetime("dd-mm-yyyy HH24:MI")'); select jsonb_path_query( @@ -2382,8 +2250,7 @@ select select jsonb_path_query( '"1000000-01-01"', - cast('$.datetime() > "2020-01-01 12:00:00".datetime()' - as jsonpath) + cast('$.datetime() > "2020-01-01 12:00:00".datetime()' as jsonpath) ); set timezone to default; @@ -2408,14 +2275,14 @@ select jsonb_path_query_array( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', - "vars" := '{"min": 1, "max": 4}' + vars := '{"min": 1, "max": 4}' ); select jsonb_path_query_array( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', - "vars" := '{"min": 3, "max": 4}' + vars := '{"min": 3, "max": 4}' ); select jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a'); @@ -2424,7 +2291,7 @@ select jsonb_path_query_first( '[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a', - "silent" := true + silent := true ); select jsonb_path_query_first('[{"a": 1}, {"a": 2}]', '$[*].a'); @@ -2437,14 +2304,14 @@ select jsonb_path_query_first( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', - "vars" := '{"min": 1, "max": 4}' + vars := '{"min": 1, "max": 4}' ); select jsonb_path_query_first( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a ? (@ > $min && @ < $max)', - "vars" := '{"min": 3, "max": 4}' + vars := '{"min": 3, "max": 4}' ); select jsonb_path_query_first('[{"a": 1}]', '$undefined_var'); @@ -2461,43 +2328,43 @@ select jsonb_path_exists( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', - "vars" := '{"min": 1, "max": 4}' + vars := '{"min": 1, "max": 4}' ); select jsonb_path_exists( '[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', - "vars" := '{"min": 3, "max": 4}' + vars := '{"min": 3, "max": 4}' ); select jsonb_path_exists('[{"a": 1}]', '$undefined_var'); select jsonb_path_exists('[{"a": 1}]', 'false'); -select jsonb_path_match('true', '$', "silent" := false); +select jsonb_path_match('true', '$', silent := false); -select jsonb_path_match('false', '$', "silent" := false); +select jsonb_path_match('false', '$', silent := false); -select jsonb_path_match('null', '$', "silent" := false); +select jsonb_path_match('null', '$', silent := false); -select jsonb_path_match('1', '$', "silent" := true); +select jsonb_path_match('1', '$', silent := true); -select jsonb_path_match('1', '$', "silent" := false); +select jsonb_path_match('1', '$', silent := false); -select jsonb_path_match('"a"', '$', "silent" := false); +select jsonb_path_match('"a"', '$', silent := false); -select jsonb_path_match('{}', '$', "silent" := false); +select jsonb_path_match('{}', '$', silent := false); -select jsonb_path_match('[true]', '$', "silent" := false); +select jsonb_path_match('[true]', '$', silent := false); -select jsonb_path_match('{}', 'lax $.a', "silent" := false); +select jsonb_path_match('{}', 'lax $.a', silent := false); -select jsonb_path_match('{}', 'strict $.a', "silent" := false); +select jsonb_path_match('{}', 'strict $.a', silent := false); -select jsonb_path_match('{}', 'strict $.a', "silent" := true); +select jsonb_path_match('{}', 'strict $.a', silent := true); -select jsonb_path_match('[true, true]', '$[*]', "silent" := false); +select jsonb_path_match('[true, true]', '$[*]', silent := false); select cast('[{"a": 1}, {"a": 2}]' as jsonb) @@ '$[*].a > 1'; @@ -2510,8 +2377,7 @@ select jsonb_path_match('[{"a": 1}]', '$undefined_var'); select jsonb_path_match('[{"a": 1}]', 'false'); with -str (j, -num) +str (j, num) as ( select jsonb_build_object('s', s), @@ -2527,36 +2393,11 @@ as ( select s1.j, s2.j, - jsonb_path_query_first( - s1.j, - '$.s < $s', - "vars" := s2.j - ) - as lt, - jsonb_path_query_first( - s1.j, - '$.s <= $s', - "vars" := s2.j - ) - as le, - jsonb_path_query_first( - s1.j, - '$.s == $s', - "vars" := s2.j - ) - as eq, - jsonb_path_query_first( - s1.j, - '$.s >= $s', - "vars" := s2.j - ) - as ge, - jsonb_path_query_first( - s1.j, - '$.s > $s', - "vars" := s2.j - ) - as gt + jsonb_path_query_first(s1.j, '$.s < $s', vars := s2.j) as lt, + jsonb_path_query_first(s1.j, '$.s <= $s', vars := s2.j) as le, + jsonb_path_query_first(s1.j, '$.s == $s', vars := s2.j) as eq, + jsonb_path_query_first(s1.j, '$.s >= $s', vars := s2.j) as ge, + jsonb_path_query_first(s1.j, '$.s > $s', vars := s2.j) as gt from str as s1, str as s2 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonpath_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonpath_100.snap index 354ca604d..e1661d3dd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonpath_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonpath_100.snap @@ -458,13 +458,11 @@ select errinfo.hint from unnest( - array[cast('$ ? (@ like_regex "pattern" flag "smixq")' - as text), + array[cast('$ ? (@ like_regex "pattern" flag "smixq")' as text), '$ ? (@ like_regex "pattern" flag "a")', '@ + 1', '00', '1a'] ) as str, - lateral pg_input_error_info(str, 'jsonpath') - as errinfo; + lateral pg_input_error_info(str, 'jsonpath') as errinfo; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonpath_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonpath_80.snap index 79e594c03..3c9bce573 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonpath_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__jsonpath_80.snap @@ -82,8 +82,7 @@ select cast('$.g ? (@.a == 1 || @.a == 4 && @.b == 7)' as jsonpath); select cast('$.g ? (@.a == 1 || !(@.a == 4) && @.b == 7)' as jsonpath); select - cast('$.g ? (@.a == 1 || !(@.x >= 123 || @.a == 4) && @.b == 7)' - as jsonpath); + cast('$.g ? (@.a == 1 || !(@.x >= 123 || @.a == 4) && @.b == 7)' as jsonpath); select cast('$.g ? (@.x >= @[*]?(@.a > "abc"))' as jsonpath); @@ -220,8 +219,7 @@ select cast('($)' as jsonpath); select cast('(($))' as jsonpath); select - cast('((($ + 1)).a + ((2)).b ? ((((@ > 1)) || (exists(@.c)))))' - as jsonpath); + cast('((($ + 1)).a + ((2)).b ? ((((@ > 1)) || (exists(@.c)))))' as jsonpath); select cast('$ ? (@.a < 1)' as jsonpath); @@ -464,13 +462,11 @@ select errinfo.hint from unnest( - array[cast('$ ? (@ like_regex "pattern" flag "smixq")' - as text), + array[cast('$ ? (@ like_regex "pattern" flag "smixq")' as text), '$ ? (@ like_regex "pattern" flag "a")', '@ + 1', '00', '1a'] ) as str, - lateral pg_input_error_info(str, 'jsonpath') - as errinfo; + lateral pg_input_error_info(str, 'jsonpath') as errinfo; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_100.snap index f00f6cedf..318dd634b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_100.snap @@ -12,7 +12,7 @@ alter large object 42 owner to regress_lo_user; set session authorization regress_lo_user; -grant SELECT on large object 42 to public; +grant select on large object 42 to public; comment on large object 42 is 'the ultimate answer'; @@ -29,10 +29,7 @@ begin; update lotest_stash_values set fd = lo_open(loid, cast(X'20000' | X'40000' as int)); -select - lowrite( - fd, - ' +select lowrite(fd, ' I wandered lonely as a cloud That floats on high o''er vales and hills, When all at once I saw a crowd, @@ -62,10 +59,7 @@ And then my heart with pleasure fills, And dances with the daffodils. -- William Wordsworth -' - ) -from - lotest_stash_values; +') from lotest_stash_values; select lo_close(fd) from lotest_stash_values; @@ -101,10 +95,7 @@ select lo_open(loid, cast(X'40000' as int)) from lotest_stash_values; rollback; -do -$do$ -dobody -$do$; +do 'dobody'; begin; @@ -196,21 +187,9 @@ commit; select lo_export(loid, 'filename') from lotest_stash_values; -select - pageno, - data -from - pg_largeobject -where - loid = (select loid from lotest_stash_values) +select pageno, data from pg_largeobject where loid = (select loid from lotest_stash_values) except -select - pageno, - data -from - pg_largeobject -where - loid = 'newloid'; +select pageno, data from pg_largeobject where loid = 'newloid'; select lo_unlink(loid) from lotest_stash_values; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_80.snap index e9eb69e9a..15170640d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_80.snap @@ -12,7 +12,7 @@ alter large object 42 owner to regress_lo_user; set session authorization regress_lo_user; -grant SELECT on large object 42 to public; +grant select on large object 42 to public; comment on large object 42 is 'the ultimate answer'; @@ -28,15 +28,9 @@ insert into lotest_stash_values (loid) select lo_creat(42); begin; update lotest_stash_values -set fd = lo_open( - loid, - cast(X'20000' | X'40000' as int) -); +set fd = lo_open(loid, cast(X'20000' | X'40000' as int)); -select - lowrite( - fd, - ' +select lowrite(fd, ' I wandered lonely as a cloud That floats on high o''er vales and hills, When all at once I saw a crowd, @@ -66,10 +60,7 @@ And then my heart with pleasure fills, And dances with the daffodils. -- William Wordsworth -' - ) -from - lotest_stash_values; +') from lotest_stash_values; select lo_close(fd) from lotest_stash_values; @@ -80,10 +71,7 @@ select lo_from_bytea(0, lo_get(loid)) as newloid from lotest_stash_values; begin; update lotest_stash_values -set fd = lo_open( - loid, - cast(X'20000' | X'40000' as int) -); +set fd = lo_open(loid, cast(X'20000' | X'40000' as int)); select lo_lseek(fd, 104, 0) from lotest_stash_values; @@ -109,18 +97,12 @@ select lo_open(loid, cast(X'40000' as int)) from lotest_stash_values; rollback; -do -$do$ -dobody -$do$; +do 'dobody'; begin; update lotest_stash_values -set fd = lo_open( - loid, - cast(X'20000' | X'40000' as int) -); +set fd = lo_open(loid, cast(X'20000' | X'40000' as int)); select lo_truncate(fd, 11) from lotest_stash_values; @@ -147,10 +129,7 @@ commit; begin; update lotest_stash_values -set fd = lo_open( - loid, - cast(X'20000' | X'40000' as int) -); +set fd = lo_open(loid, cast(X'20000' | X'40000' as int)); select lo_lseek64(fd, 4294967296, 0) from lotest_stash_values; @@ -189,10 +168,7 @@ insert into lotest_stash_values (loid) select lo_import('filename'); begin; update lotest_stash_values -set fd = lo_open( - loid, - cast(X'20000' | X'40000' as int) -); +set fd = lo_open(loid, cast(X'20000' | X'40000' as int)); select lo_lseek(fd, 0, 2) from lotest_stash_values; @@ -222,16 +198,9 @@ select from pg_largeobject where - loid = - (select loid from lotest_stash_values) + loid = (select loid from lotest_stash_values) except -select - pageno, - data -from - pg_largeobject -where - loid = 'newloid'; +select pageno, data from pg_largeobject where loid = 'newloid'; select lo_unlink(loid) from lotest_stash_values; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__limit_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__limit_100.snap index 2820a5267..b5f6fb4c8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__limit_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__limit_100.snap @@ -108,7 +108,7 @@ select * from int8_tbl offset case when random() < 0.5 then cast(null as bigint) begin; -declare "c1" cursor for select * from int8_tbl limit 10;; +declare c1 cursor for select * from int8_tbl limit 10;; fetch forward all from c1; @@ -122,7 +122,7 @@ fetch prior from c1; fetch forward all from c1; -declare "c2" cursor for select * from int8_tbl limit 3;; +declare c2 cursor for select * from int8_tbl limit 3;; fetch forward all from c2; @@ -136,7 +136,7 @@ fetch prior from c2; fetch forward all from c2; -declare "c3" cursor for select * from int8_tbl offset 3;; +declare c3 cursor for select * from int8_tbl offset 3;; fetch forward all from c3; @@ -150,7 +150,7 @@ fetch prior from c3; fetch forward all from c3; -declare "c4" cursor for select * from int8_tbl offset 10;; +declare c4 cursor for select * from int8_tbl offset 10;; fetch forward all from c4; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__limit_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__limit_80.snap index d035a421c..ea98be54c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__limit_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__limit_80.snap @@ -114,23 +114,17 @@ select * from int8_tbl -limit case - when random() < 0.5 - then cast(null as bigint) -end; +limit case when random() < 0.5 then cast(null as bigint) end; select * from int8_tbl -offset case - when random() < 0.5 - then cast(null as bigint) -end; +offset case when random() < 0.5 then cast(null as bigint) end; begin; -declare "c1" cursor for select * from int8_tbl limit 10;; +declare c1 cursor for select * from int8_tbl limit 10;; fetch forward all from c1; @@ -144,7 +138,7 @@ fetch prior from c1; fetch forward all from c1; -declare "c2" cursor for select * from int8_tbl limit 3;; +declare c2 cursor for select * from int8_tbl limit 3;; fetch forward all from c2; @@ -158,7 +152,7 @@ fetch prior from c2; fetch forward all from c2; -declare "c3" cursor for select * from int8_tbl offset 3;; +declare c3 cursor for select * from int8_tbl offset 3;; fetch forward all from c3; @@ -172,7 +166,7 @@ fetch prior from c3; fetch forward all from c3; -declare "c4" cursor for select * from int8_tbl offset 10;; +declare c4 cursor for select * from int8_tbl offset 10;; fetch forward all from c4; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__line_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__line_100.snap index 463923bb0..9d508601d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__line_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__line_100.snap @@ -52,12 +52,8 @@ insert into line_tbl values (line(cast('(1,0)' as point), cast('(1,0)' as point) select * from line_tbl; select - cast('{nan, 1, nan}' as line) = - cast('{nan, 1, nan}' as line) - as "true", - cast('{nan, 1, nan}' as line) = - cast('{nan, 2, nan}' as line) - as "false"; + cast('{nan, 1, nan}' as line) = cast('{nan, 1, nan}' as line) as "true", + cast('{nan, 1, nan}' as line) = cast('{nan, 2, nan}' as line) as "false"; select pg_input_is_valid('{1, 1}', 'line'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__line_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__line_80.snap index 817a69285..61dbb4eb6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__line_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__line_80.snap @@ -24,13 +24,7 @@ insert into line_tbl values ('{NaN,NaN,NaN}'); insert into line_tbl values ('[(1,3),(2,3)]'); insert into line_tbl -values - ( - line( - cast('(3,1)' as point), - cast('(3,2)' as point) - ) - ); +values (line(cast('(3,1)' as point), cast('(3,2)' as point))); insert into line_tbl values ('{}'); @@ -55,23 +49,13 @@ insert into line_tbl values ('[(1,2),(3,4)'); insert into line_tbl values ('[(1,2),(1,2)]'); insert into line_tbl -values - ( - line( - cast('(1,0)' as point), - cast('(1,0)' as point) - ) - ); +values (line(cast('(1,0)' as point), cast('(1,0)' as point))); select * from line_tbl; select - cast('{nan, 1, nan}' as line) = - cast('{nan, 1, nan}' as line) - as "true", - cast('{nan, 1, nan}' as line) = - cast('{nan, 2, nan}' as line) - as "false"; + cast('{nan, 1, nan}' as line) = cast('{nan, 1, nan}' as line) as "true", + cast('{nan, 1, nan}' as line) = cast('{nan, 2, nan}' as line) as "false"; select pg_input_is_valid('{1, 1}', 'line'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_100.snap index f8f3dc734..23eb4c964 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/lock.sql --- -create schema "lock_schema1"; +create schema lock_schema1; set search_path to lock_schema1; @@ -24,18 +24,10 @@ create view lock_view3 as select * from lock_view2; create view lock_view4 -as select - (select a from lock_tbl1a limit 1) -from - lock_tbl1; +as select (select a from lock_tbl1a limit 1) from lock_tbl1; create view lock_view5 -as select - * -from - lock_tbl1 -where - a in (select * from lock_tbl1a); +as select * from lock_tbl1 where a in (select * from lock_tbl1a); create view lock_view6 as select * from (select * from lock_tbl1) as sub; @@ -44,47 +36,47 @@ create role regress_rol_lock1; alter role regress_rol_lock1 set search_path to lock_schema1; -grant USAGE on schema lock_schema1 to regress_rol_lock1; +grant usage on schema lock_schema1 to regress_rol_lock1; begin; -lock table lock_tbl1 in ACCESS SHARE mode; +lock table lock_tbl1 in access share mode; -lock table lock_tbl1 in ROW SHARE mode; +lock table lock_tbl1 in row share mode; -lock table lock_tbl1 in ROW EXCLUSIVE mode; +lock table lock_tbl1 in row exclusive mode; -lock table lock_tbl1 in SHARE mode; +lock table lock_tbl1 in share mode; -lock table lock_tbl1 in SHARE ROW EXCLUSIVE mode; +lock table lock_tbl1 in share row exclusive mode; -lock table lock_tbl1 in EXCLUSIVE mode; +lock table lock_tbl1 in exclusive mode; -lock table lock_tbl1 in ACCESS EXCLUSIVE mode; +lock table lock_tbl1 in access exclusive mode; rollback; begin; -lock table lock_tbl1 in ACCESS SHARE mode nowait; +lock table lock_tbl1 in access share mode nowait; -lock table lock_tbl1 in ROW SHARE mode nowait; +lock table lock_tbl1 in row share mode nowait; -lock table lock_tbl1 in ROW EXCLUSIVE mode nowait; +lock table lock_tbl1 in row exclusive mode nowait; -lock table lock_tbl1 in SHARE mode nowait; +lock table lock_tbl1 in share mode nowait; -lock table lock_tbl1 in SHARE ROW EXCLUSIVE mode nowait; +lock table lock_tbl1 in share row exclusive mode nowait; -lock table lock_tbl1 in EXCLUSIVE mode nowait; +lock table lock_tbl1 in exclusive mode nowait; -lock table lock_tbl1 in ACCESS EXCLUSIVE mode nowait; +lock table lock_tbl1 in access exclusive mode nowait; rollback; begin; -lock table lock_view1 in EXCLUSIVE mode; +lock table lock_view1 in exclusive mode; select relname @@ -92,16 +84,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view2 in EXCLUSIVE mode; +lock table lock_view2 in exclusive mode; select relname @@ -109,16 +99,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view3 in EXCLUSIVE mode; +lock table lock_view3 in exclusive mode; select relname @@ -126,16 +114,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view4 in EXCLUSIVE mode; +lock table lock_view4 in exclusive mode; select relname @@ -143,16 +129,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view5 in EXCLUSIVE mode; +lock table lock_view5 in exclusive mode; select relname @@ -160,16 +144,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view6 in EXCLUSIVE mode; +lock table lock_view6 in exclusive mode; select relname @@ -177,9 +159,7 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; @@ -189,7 +169,7 @@ as select * from lock_view3; begin; -lock table lock_view2 in EXCLUSIVE mode; +lock table lock_view2 in exclusive mode; rollback; @@ -198,7 +178,7 @@ as select * from lock_view2; begin; -lock table lock_view7 in EXCLUSIVE mode; +lock table lock_view7 in exclusive mode; rollback; @@ -210,53 +190,53 @@ inherits (lock_tbl2); begin; -lock table lock_tbl1 in ACCESS EXCLUSIVE mode; +lock table lock_tbl1 in access exclusive mode; rollback; -grant UPDATE on table lock_tbl1 to regress_rol_lock1; +grant update on table lock_tbl1 to regress_rol_lock1; set role to regress_rol_lock1; begin; -lock table lock_tbl2 in ACCESS EXCLUSIVE mode; +lock table lock_tbl2 in access exclusive mode; rollback; begin; -lock table lock_tbl1 in ACCESS EXCLUSIVE mode; +lock table lock_tbl1 in access exclusive mode; rollback; begin; -lock table only lock_tbl1 in ACCESS EXCLUSIVE mode; +lock table only lock_tbl1 in access exclusive mode; rollback; reset role; -revoke UPDATE on table lock_tbl1 from regress_rol_lock1; +revoke update on table lock_tbl1 from regress_rol_lock1; set role to regress_rol_lock1; begin; -lock table lock_view1 in ACCESS EXCLUSIVE mode; +lock table lock_view1 in access exclusive mode; rollback; reset role; -grant UPDATE on table lock_view1 to regress_rol_lock1; +grant update on table lock_view1 to regress_rol_lock1; set role to regress_rol_lock1; begin; -lock table lock_view1 in ACCESS EXCLUSIVE mode; +lock table lock_view1 in access exclusive mode; select relname @@ -264,16 +244,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'AccessExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'AccessExclusiveLock' order by relname; rollback; reset role; -revoke UPDATE on table lock_view1 from regress_rol_lock1; +revoke update on table lock_view1 from regress_rol_lock1; create view lock_view8 with (security_invoker) @@ -283,29 +261,29 @@ set role to regress_rol_lock1; begin; -lock table lock_view8 in ACCESS EXCLUSIVE mode; +lock table lock_view8 in access exclusive mode; rollback; reset role; -grant UPDATE on table lock_view8 to regress_rol_lock1; +grant update on table lock_view8 to regress_rol_lock1; set role to regress_rol_lock1; begin; -lock table lock_view8 in ACCESS EXCLUSIVE mode; +lock table lock_view8 in access exclusive mode; rollback; reset role; -grant UPDATE on table lock_tbl1 to regress_rol_lock1; +grant update on table lock_tbl1 to regress_rol_lock1; begin; -lock table lock_view8 in ACCESS EXCLUSIVE mode; +lock table lock_view8 in access exclusive mode; select relname @@ -313,16 +291,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'AccessExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'AccessExclusiveLock' order by relname; rollback; reset role; -revoke UPDATE on table lock_view8 from regress_rol_lock1; +revoke update on table lock_view8 from regress_rol_lock1; drop view lock_view8; @@ -353,10 +329,8 @@ drop role regress_rol_lock1; reset search_path; create function test_atomic_ops() -returns boolean +returns bool language c -as $function$ -regresslib -$function$; +as 'regresslib'; select test_atomic_ops(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_80.snap index 3471d115e..23eb4c964 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/lock.sql --- -create schema "lock_schema1"; +create schema lock_schema1; set search_path to lock_schema1; @@ -24,70 +24,59 @@ create view lock_view3 as select * from lock_view2; create view lock_view4 -as select - (select a from lock_tbl1a limit 1) -from - lock_tbl1; +as select (select a from lock_tbl1a limit 1) from lock_tbl1; create view lock_view5 -as select - * -from - lock_tbl1 -where - a in (select * from lock_tbl1a); +as select * from lock_tbl1 where a in (select * from lock_tbl1a); create view lock_view6 -as select - * -from - (select * from lock_tbl1) as sub; +as select * from (select * from lock_tbl1) as sub; create role regress_rol_lock1; alter role regress_rol_lock1 set search_path to lock_schema1; -grant USAGE on schema lock_schema1 to regress_rol_lock1; +grant usage on schema lock_schema1 to regress_rol_lock1; begin; -lock table lock_tbl1 in ACCESS SHARE mode; +lock table lock_tbl1 in access share mode; -lock table lock_tbl1 in ROW SHARE mode; +lock table lock_tbl1 in row share mode; -lock table lock_tbl1 in ROW EXCLUSIVE mode; +lock table lock_tbl1 in row exclusive mode; -lock table lock_tbl1 in SHARE mode; +lock table lock_tbl1 in share mode; -lock table lock_tbl1 in SHARE ROW EXCLUSIVE mode; +lock table lock_tbl1 in share row exclusive mode; -lock table lock_tbl1 in EXCLUSIVE mode; +lock table lock_tbl1 in exclusive mode; -lock table lock_tbl1 in ACCESS EXCLUSIVE mode; +lock table lock_tbl1 in access exclusive mode; rollback; begin; -lock table lock_tbl1 in ACCESS SHARE mode nowait; +lock table lock_tbl1 in access share mode nowait; -lock table lock_tbl1 in ROW SHARE mode nowait; +lock table lock_tbl1 in row share mode nowait; -lock table lock_tbl1 in ROW EXCLUSIVE mode nowait; +lock table lock_tbl1 in row exclusive mode nowait; -lock table lock_tbl1 in SHARE mode nowait; +lock table lock_tbl1 in share mode nowait; -lock table lock_tbl1 in SHARE ROW EXCLUSIVE mode nowait; +lock table lock_tbl1 in share row exclusive mode nowait; -lock table lock_tbl1 in EXCLUSIVE mode nowait; +lock table lock_tbl1 in exclusive mode nowait; -lock table lock_tbl1 in ACCESS EXCLUSIVE mode nowait; +lock table lock_tbl1 in access exclusive mode nowait; rollback; begin; -lock table lock_view1 in EXCLUSIVE mode; +lock table lock_view1 in exclusive mode; select relname @@ -95,16 +84,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view2 in EXCLUSIVE mode; +lock table lock_view2 in exclusive mode; select relname @@ -112,16 +99,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view3 in EXCLUSIVE mode; +lock table lock_view3 in exclusive mode; select relname @@ -129,16 +114,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view4 in EXCLUSIVE mode; +lock table lock_view4 in exclusive mode; select relname @@ -146,16 +129,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view5 in EXCLUSIVE mode; +lock table lock_view5 in exclusive mode; select relname @@ -163,16 +144,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; begin; -lock table lock_view6 in EXCLUSIVE mode; +lock table lock_view6 in exclusive mode; select relname @@ -180,9 +159,7 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'ExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'ExclusiveLock' order by relname; rollback; @@ -192,7 +169,7 @@ as select * from lock_view3; begin; -lock table lock_view2 in EXCLUSIVE mode; +lock table lock_view2 in exclusive mode; rollback; @@ -201,7 +178,7 @@ as select * from lock_view2; begin; -lock table lock_view7 in EXCLUSIVE mode; +lock table lock_view7 in exclusive mode; rollback; @@ -213,53 +190,53 @@ inherits (lock_tbl2); begin; -lock table lock_tbl1 in ACCESS EXCLUSIVE mode; +lock table lock_tbl1 in access exclusive mode; rollback; -grant UPDATE on table lock_tbl1 to regress_rol_lock1; +grant update on table lock_tbl1 to regress_rol_lock1; set role to regress_rol_lock1; begin; -lock table lock_tbl2 in ACCESS EXCLUSIVE mode; +lock table lock_tbl2 in access exclusive mode; rollback; begin; -lock table lock_tbl1 in ACCESS EXCLUSIVE mode; +lock table lock_tbl1 in access exclusive mode; rollback; begin; -lock table only lock_tbl1 in ACCESS EXCLUSIVE mode; +lock table only lock_tbl1 in access exclusive mode; rollback; reset role; -revoke UPDATE on table lock_tbl1 from regress_rol_lock1; +revoke update on table lock_tbl1 from regress_rol_lock1; set role to regress_rol_lock1; begin; -lock table lock_view1 in ACCESS EXCLUSIVE mode; +lock table lock_view1 in access exclusive mode; rollback; reset role; -grant UPDATE on table lock_view1 to regress_rol_lock1; +grant update on table lock_view1 to regress_rol_lock1; set role to regress_rol_lock1; begin; -lock table lock_view1 in ACCESS EXCLUSIVE mode; +lock table lock_view1 in access exclusive mode; select relname @@ -267,16 +244,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'AccessExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'AccessExclusiveLock' order by relname; rollback; reset role; -revoke UPDATE on table lock_view1 from regress_rol_lock1; +revoke update on table lock_view1 from regress_rol_lock1; create view lock_view8 with (security_invoker) @@ -286,29 +261,29 @@ set role to regress_rol_lock1; begin; -lock table lock_view8 in ACCESS EXCLUSIVE mode; +lock table lock_view8 in access exclusive mode; rollback; reset role; -grant UPDATE on table lock_view8 to regress_rol_lock1; +grant update on table lock_view8 to regress_rol_lock1; set role to regress_rol_lock1; begin; -lock table lock_view8 in ACCESS EXCLUSIVE mode; +lock table lock_view8 in access exclusive mode; rollback; reset role; -grant UPDATE on table lock_tbl1 to regress_rol_lock1; +grant update on table lock_tbl1 to regress_rol_lock1; begin; -lock table lock_view8 in ACCESS EXCLUSIVE mode; +lock table lock_view8 in access exclusive mode; select relname @@ -316,16 +291,14 @@ from pg_locks as l, pg_class as c where - l.relation = c.oid and - relname like '%lock_%' and - mode = 'AccessExclusiveLock' + l.relation = c.oid and relname like '%lock_%' and mode = 'AccessExclusiveLock' order by relname; rollback; reset role; -revoke UPDATE on table lock_view8 from regress_rol_lock1; +revoke update on table lock_view8 from regress_rol_lock1; drop view lock_view8; @@ -356,10 +329,8 @@ drop role regress_rol_lock1; reset search_path; create function test_atomic_ops() -returns boolean +returns bool language c -as $function$ -regresslib -$function$; +as 'regresslib'; select test_atomic_ops(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr8_100.snap index 7e94097ed..e06f3e0e8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr8_100.snap @@ -94,9 +94,9 @@ insert into macaddr8_data values (21, '08002b0102030405'); select * from macaddr8_data order by 1; -create index "macaddr8_data_btree" on macaddr8_data using btree (b); +create index macaddr8_data_btree on macaddr8_data using btree (b); -create index "macaddr8_data_hash" on macaddr8_data using hash (b); +create index macaddr8_data_hash on macaddr8_data using hash (b); select a, b, trunc(b) from macaddr8_data order by 2, 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr8_80.snap index d0e13fde1..ed5d59e8c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr8_80.snap @@ -94,9 +94,9 @@ insert into macaddr8_data values (21, '08002b0102030405'); select * from macaddr8_data order by 1; -create index "macaddr8_data_btree" on macaddr8_data using btree (b); +create index macaddr8_data_btree on macaddr8_data using btree (b); -create index "macaddr8_data_hash" on macaddr8_data using hash (b); +create index macaddr8_data_hash on macaddr8_data using hash (b); select a, b, trunc(b) from macaddr8_data order by 2, 1; @@ -113,16 +113,14 @@ select cast(b as macaddr) >= '08:00:2b:01:02:04' from macaddr8_data where a = 1; select b = '08:00:2b:ff:fe:01:02:03' from macaddr8_data where a = 1; select - cast(b as macaddr) <> - cast('08:00:2b:01:02:04' as macaddr) + cast(b as macaddr) <> cast('08:00:2b:01:02:04' as macaddr) from macaddr8_data where a = 1; select - cast(b as macaddr) <> - cast('08:00:2b:01:02:03' as macaddr) + cast(b as macaddr) <> cast('08:00:2b:01:02:03' as macaddr) from macaddr8_data where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr_100.snap index b6db6c432..b2b0e5024 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr_100.snap @@ -38,9 +38,9 @@ insert into macaddr_data values (14, '08:00:2a:01:02:04'); select * from macaddr_data; -create index "macaddr_data_btree" on macaddr_data using btree (b); +create index macaddr_data_btree on macaddr_data using btree (b); -create index "macaddr_data_hash" on macaddr_data using hash (b); +create index macaddr_data_hash on macaddr_data using hash (b); select a, b, trunc(b) from macaddr_data order by 2, 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr_80.snap index b6db6c432..b2b0e5024 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__macaddr_80.snap @@ -38,9 +38,9 @@ insert into macaddr_data values (14, '08:00:2a:01:02:04'); select * from macaddr_data; -create index "macaddr_data_btree" on macaddr_data using btree (b); +create index macaddr_data_btree on macaddr_data using btree (b); -create index "macaddr_data_hash" on macaddr_data using hash (b); +create index macaddr_data_hash on macaddr_data using hash (b); select a, b, trunc(b) from macaddr_data order by 2, 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__maintain_every_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__maintain_every_80.snap index ca91ab84d..dd3dab3ad 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__maintain_every_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__maintain_every_80.snap @@ -22,8 +22,7 @@ select from pg_class where - oid = - cast('past_inh_db_parent' as regclass); + oid = cast('past_inh_db_parent' as regclass); drop table past_inh_db_child; @@ -39,8 +38,7 @@ select from pg_class where - oid = - cast('past_inh_db_parent' as regclass); + oid = cast('past_inh_db_parent' as regclass); drop table past_inh_db_parent, past_inh_db_other; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__matview_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__matview_100.snap index 6008e5f43..69d5fd061 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__matview_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__matview_100.snap @@ -12,32 +12,17 @@ create table mvtest_t ( insert into mvtest_t values (1, 'x', 2), (2, 'x', 3), (3, 'y', 5), (4, 'y', 7), (5, 'z', 11); create view mvtest_tv -as select - type, - SUM(amt) as totamt -from - mvtest_t -group by type; +as select type, sum(amt) as totamt from mvtest_t group by type; select * from mvtest_tv order by type; create materialized view mvtest_tm as - select - type, - SUM(amt) as totamt - from - mvtest_t - group by type with no data; + select type, sum(amt) as totamt from mvtest_t group by type with no data; create materialized view mvtest_tm as - select - type, - SUM(amt) as totamt - from - mvtest_t - group by type with no data; + select type, sum(amt) as totamt from mvtest_t group by type with no data; select relispopulated from pg_class where oid = cast('mvtest_tm' as regclass); @@ -47,7 +32,7 @@ refresh materialized view mvtest_tm; select relispopulated from pg_class where oid = cast('mvtest_tm' as regclass); -create unique index "mvtest_tm_type" on mvtest_tm using btree (type); +create unique index mvtest_tm_type on mvtest_tm using btree (type); select * from mvtest_tm order by type; @@ -57,23 +42,16 @@ create materialized view mvtest_tvm as select * from mvtest_tv order by type; select * from mvtest_tvm; -create materialized view mvtest_tmm as select SUM(totamt) as grandtot from mvtest_tm; +create materialized view mvtest_tmm as select sum(totamt) as grandtot from mvtest_tm; -create materialized view mvtest_tvmm as select SUM(totamt) as grandtot from mvtest_tvm; +create materialized view mvtest_tvmm as select sum(totamt) as grandtot from mvtest_tvm; -create unique index "mvtest_tvmm_expr" on mvtest_tvmm using btree ((grandtot > 0)); +create unique index mvtest_tvmm_expr on mvtest_tvmm using btree ((grandtot > 0)); -create unique index "mvtest_tvmm_pred" -on mvtest_tvmm -using btree -( - grandtot -) -where - grandtot < 0; +create unique index mvtest_tvmm_pred on mvtest_tvmm using btree (grandtot) where grandtot < 0; create view mvtest_tvv -as select SUM(totamt) as grandtot from mvtest_tv; +as select sum(totamt) as grandtot from mvtest_tv; create materialized view mvtest_tvvm as select * from mvtest_tvv; @@ -84,9 +62,9 @@ as select * from mvtest_tvvm; create materialized view mvtest_bb as select * from mvtest_tvvmv; -create index "mvtest_aa" on mvtest_bb using btree (grandtot); +create index mvtest_aa on mvtest_bb using btree (grandtot); -create schema "mvtest_mvschema"; +create schema mvtest_mvschema; alter materialized view mvtest_tvm set schema mvtest_mvschema; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__matview_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__matview_80.snap index d9d160106..7c629e52c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__matview_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__matview_80.snap @@ -10,40 +10,20 @@ create table mvtest_t ( ); insert into mvtest_t -values - (1, 'x', 2), - (2, 'x', 3), - (3, 'y', 5), - (4, 'y', 7), - (5, 'z', 11); +values (1, 'x', 2), (2, 'x', 3), (3, 'y', 5), (4, 'y', 7), (5, 'z', 11); create view mvtest_tv -as select - type, - SUM(amt) as totamt -from - mvtest_t -group by type; +as select type, sum(amt) as totamt from mvtest_t group by type; select * from mvtest_tv order by type; create materialized view mvtest_tm as - select - type, - SUM(amt) as totamt - from - mvtest_t - group by type with no data; + select type, sum(amt) as totamt from mvtest_t group by type with no data; create materialized view mvtest_tm as - select - type, - SUM(amt) as totamt - from - mvtest_t - group by type with no data; + select type, sum(amt) as totamt from mvtest_t group by type with no data; select relispopulated from pg_class where oid = cast('mvtest_tm' as regclass); @@ -53,7 +33,7 @@ refresh materialized view mvtest_tm; select relispopulated from pg_class where oid = cast('mvtest_tm' as regclass); -create unique index "mvtest_tm_type" on mvtest_tm using btree (type); +create unique index mvtest_tm_type on mvtest_tm using btree (type); select * from mvtest_tm order by type; @@ -65,39 +45,21 @@ select * from mvtest_tvm; create materialized view mvtest_tmm as - select - SUM(totamt) as grandtot - from - mvtest_tm; + select sum(totamt) as grandtot from mvtest_tm; create materialized view mvtest_tvmm as - select - SUM(totamt) as grandtot - from - mvtest_tvm; - -create unique index "mvtest_tvmm_expr" -on mvtest_tvmm -using btree -( + select sum(totamt) as grandtot from mvtest_tvm; + +create unique index mvtest_tvmm_expr on mvtest_tvmm using btree ( (grandtot > 0) ); -create unique index "mvtest_tvmm_pred" -on mvtest_tvmm -using btree -( - grandtot -) -where - grandtot < 0; +create unique index mvtest_tvmm_pred on mvtest_tvmm using btree (grandtot) +where grandtot < 0; create view mvtest_tvv -as select - SUM(totamt) as grandtot -from - mvtest_tv; +as select sum(totamt) as grandtot from mvtest_tv; create materialized view mvtest_tvvm as select * from mvtest_tvv; @@ -108,9 +70,9 @@ as select * from mvtest_tvvm; create materialized view mvtest_bb as select * from mvtest_tvvmv; -create index "mvtest_aa" on mvtest_bb using btree (grandtot); +create index mvtest_aa on mvtest_bb using btree (grandtot); -create schema "mvtest_mvschema"; +create schema mvtest_mvschema; alter materialized view mvtest_tvm set schema mvtest_mvschema; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__md5_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__md5_100.snap index 23382a98d..0f6611700 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__md5_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__md5_100.snap @@ -14,16 +14,12 @@ select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' as "TRUE"; select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' as "TRUE"; select - md5( - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' - ) = + md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' as "TRUE"; select - md5( - '12345678901234567890123456789012345678901234567890123456789012345678901234567890' - ) = + md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' as "TRUE"; @@ -36,15 +32,10 @@ select md5(cast('abc' as bytea)) = '900150983cd24fb0d6963f7d28e17f72' as "TRUE"; select md5(cast('message digest' as bytea)) = 'f96b697d7cb7938d525a2f31aaf161d0' as "TRUE"; select - md5(cast('abcdefghijklmnopqrstuvwxyz' as bytea)) = - 'c3fcd3d76192e4007dfb496cca67e13b' - as "TRUE"; + md5(cast('abcdefghijklmnopqrstuvwxyz' as bytea)) = 'c3fcd3d76192e4007dfb496cca67e13b' as "TRUE"; select - md5( - cast('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' - as bytea) - ) = + md5(cast('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' as bytea)) = 'd174ab98d277d9f5a5611c2c9f419d9f' as "TRUE"; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__md5_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__md5_80.snap index 100a679c6..b9bb07d7f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__md5_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__md5_80.snap @@ -12,14 +12,11 @@ select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' as "TRUE"; select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' as "TRUE"; select - md5('abcdefghijklmnopqrstuvwxyz') = - 'c3fcd3d76192e4007dfb496cca67e13b' + md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' as "TRUE"; select - md5( - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' - ) = + md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' as "TRUE"; @@ -37,15 +34,11 @@ select md5(cast('a' as bytea)) = '0cc175b9c0f1b6a831c399e269772661' as "TRUE"; select md5(cast('abc' as bytea)) = '900150983cd24fb0d6963f7d28e17f72' as "TRUE"; select - md5(cast('message digest' as bytea)) = - 'f96b697d7cb7938d525a2f31aaf161d0' + md5(cast('message digest' as bytea)) = 'f96b697d7cb7938d525a2f31aaf161d0' as "TRUE"; select - md5( - cast('abcdefghijklmnopqrstuvwxyz' - as bytea) - ) = + md5(cast('abcdefghijklmnopqrstuvwxyz' as bytea)) = 'c3fcd3d76192e4007dfb496cca67e13b' as "TRUE"; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_100.snap index 6b45c688c..7fd389c0f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_100.snap @@ -2,10 +2,10 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/memoize.sql --- -create function explain_memoize(query text, hide_hitmiss boolean) +create function explain_memoize(query text, hide_hitmiss bool) returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin @@ -29,145 +29,88 @@ begin return next ln; end loop; end; -$function$; +$$; set enable_hashjoin = off; set enable_bitmapscan = off; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 INNER JOIN tenk1 t2 ON t1.unique1 = t2.twenty -WHERE t2.unique1 < 1000;', - false - ); +WHERE t2.unique1 < 1000;', false); select - COUNT(*), - AVG(t1.unique1) + count(*), + avg(t1.unique1) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.twenty + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.twenty where t2.unique1 < 1000; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1, LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1 OFFSET 0) t2 -WHERE t1.unique1 < 1000;', - false - ); +WHERE t1.unique1 < 1000;', false); select - COUNT(*), - AVG(t2.unique1) + count(*), + avg(t2.unique1) from tenk1 as t1, - lateral ( - select - t2.unique1 - from - tenk1 as t2 - where - t1.twenty = t2.unique1 - offset 0 - ) - as t2 + lateral (select t2.unique1 from tenk1 as t2 where t1.twenty = t2.unique1 offset 0) as t2 where t1.unique1 < 1000; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*),AVG(t2.t1two) FROM tenk1 t1 LEFT JOIN LATERAL ( SELECT t1.two as t1two, * FROM tenk1 t2 WHERE t2.unique1 < 4 OFFSET 0 ) t2 ON t1.two = t2.two -WHERE t1.unique1 < 10;', - false - ); +WHERE t1.unique1 < 10;', false); select - COUNT(*), - AVG(t2.t1two) + count(*), + avg(t2.t1two) from tenk1 as t1 left outer join - lateral ( - select - t1.two as t1two, - * - from - tenk1 as t2 - where - t2.unique1 < 4 - offset 0 - ) - as t2 + lateral (select t1.two as t1two, * from tenk1 as t2 where t2.unique1 < 4 offset 0) as t2 on t1.two = t2.two where t1.unique1 < 10; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*), AVG(t1.twenty) FROM tenk1 t1 LEFT JOIN LATERAL (SELECT t1.two+1 AS c1, t2.unique1 AS c2 FROM tenk1 t2) s ON TRUE -WHERE s.c1 = s.c2 AND t1.unique1 < 1000;', - false - ); +WHERE s.c1 = s.c2 AND t1.unique1 < 1000;', false); select - COUNT(*), - AVG(t1.twenty) + count(*), + avg(t1.twenty) from tenk1 as t1 left outer join - lateral ( - select - t1.two + 1 as c1, - t2.unique1 as c2 - from - tenk1 as t2 - ) - as s + lateral (select t1.two + 1 as c1, t2.unique1 as c2 from tenk1 as t2) as s on true where s.c1 = s.c2 and t1.unique1 < 1000; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*), AVG(t1.twenty) FROM tenk1 t1 LEFT JOIN LATERAL (SELECT t1.twenty AS c1, t2.unique1 AS c2, t2.two FROM tenk1 t2) s ON t1.two = s.two -WHERE s.c1 = s.c2 AND t1.unique1 < 1000;', - false - ); +WHERE s.c1 = s.c2 AND t1.unique1 < 1000;', false); select - COUNT(*), - AVG(t1.twenty) + count(*), + avg(t1.twenty) from tenk1 as t1 left outer join - lateral ( - select - t1.twenty as c1, - t2.unique1 as c2, - t2.two - from - tenk1 as t2 - ) - as s + lateral (select t1.twenty as c1, t2.unique1 as c2, t2.two from tenk1 as t2) as s on t1.two = s.two where s.c1 = s.c2 and t1.unique1 < 1000; @@ -184,27 +127,17 @@ select cast(d1 as numeric), cast(d1 as text) from - ( - select - round(cast(d / pi() as numeric), 7) as d1 - from - generate_series(1, 20) as d - ) - as t; + (select round(cast(d / pi() as numeric), 7) as d1 from generate_series(1, 20) as d) as t; insert into expr_key select * from expr_key; -create index "expr_key_idx_x_t" on expr_key using btree (x, t); +create index expr_key_idx_x_t on expr_key using btree (x, t); -vacuum (ANALYZE) expr_key; +vacuum (analyze) expr_key; -select - explain_memoize( - ' +select explain_memoize(' SELECT * FROM expr_key t1 INNER JOIN expr_key t2 -ON t1.x = t2.t::numeric AND t1.t::numeric = t2.x;', - false - ); +ON t1.x = t2.t::numeric AND t1.t::numeric = t2.x;', false); drop table expr_key; @@ -212,18 +145,14 @@ set work_mem = '64kB'; set hash_mem_multiplier = 1.0; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 INNER JOIN tenk1 t2 ON t1.unique1 = t2.thousand -WHERE t2.unique1 < 1200;', - true - ); +WHERE t2.unique1 < 1200;', true); create table flt (f double precision); -create index "flt_f_idx" on flt using btree (f); +create index flt_f_idx on flt using btree (f); insert into flt values (cast('-0.0' as double precision)), (cast('+0.0' as double precision)); @@ -244,15 +173,12 @@ create table strtest ( t text ); -create index "strtest_n_idx" on strtest using btree (n); +create index strtest_n_idx on strtest using btree (n); -create index "strtest_t_idx" on strtest using btree (t); +create index strtest_t_idx on strtest using btree (t); insert into strtest -values - ('one', 'one'), - ('two', 'two'), - ('three', repeat(fipshash('three'), 100)); +values ('one', 'one'), ('two', 'two'), ('three', repeat(fipshash('three'), 100)); insert into strtest select * from strtest; @@ -279,9 +205,9 @@ insert into prt values (0), (0), (0), (0); insert into prt values (10), (10), (10), (10); -create index "iprt_p1_a" on prt_p1 using btree (a); +create index iprt_p1_a on prt_p1 using btree (a); -create index "iprt_p2_a" on prt_p2 using btree (a); +create index iprt_p2_a on prt_p2 using btree (a); analyze prt; @@ -290,14 +216,10 @@ SELECT * FROM prt t1 INNER JOIN prt t2 ON t1.a = t2.a;', false); set enable_partitionwise_join = off; -select - explain_memoize( - ' +select explain_memoize(' SELECT * FROM prt_p1 t1 INNER JOIN (SELECT * FROM prt_p1 UNION ALL SELECT * FROM prt_p2) t2 -ON t1.a = t2.a;', - false - ); +ON t1.a = t2.a;', false); drop table prt; @@ -314,10 +236,7 @@ where select 1 from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.hundred + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.hundred where t0.ten = t1.twenty and t0.two <> t2.four offset 0 @@ -334,10 +253,7 @@ where select 1 from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.hundred + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.hundred where t0.ten = t1.twenty and t0.two <> t2.four offset 0 @@ -364,36 +280,20 @@ set parallel_tuple_cost = 0; set max_parallel_workers_per_gather = 2; select - COUNT(*), - AVG(t2.unique1) + count(*), + avg(t2.unique1) from tenk1 as t1, - lateral ( - select - t2.unique1 - from - tenk1 as t2 - where - t1.twenty = t2.unique1 - ) - as t2 + lateral (select t2.unique1 from tenk1 as t2 where t1.twenty = t2.unique1) as t2 where t1.unique1 < 1000; select - COUNT(*), - AVG(t2.unique1) + count(*), + avg(t2.unique1) from tenk1 as t1, - lateral ( - select - t2.unique1 - from - tenk1 as t2 - where - t1.twenty = t2.unique1 - ) - as t2 + lateral (select t2.unique1 from tenk1 as t2 where t1.twenty = t2.unique1) as t2 where t1.unique1 < 1000; @@ -414,30 +314,18 @@ insert into tab_anti select i % 3, false from generate_series(1, 100) as i; analyze tab_anti; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*) FROM tab_anti t1 LEFT JOIN LATERAL (SELECT DISTINCT ON (a) a, b, t1.a AS x FROM tab_anti t2) t2 ON t1.a+1 = t2.a -WHERE t2.a IS NULL;', - false - ); +WHERE t2.a IS NULL;', false); select - COUNT(*) + count(*) from tab_anti as t1 left outer join - lateral ( - select distinct on (a) - a, - b, - t1.a as x - from - tab_anti as t2 - ) - as t2 + lateral (select distinct on (a) a, b, t1.a as x from tab_anti as t2) as t2 on t1.a + 1 = t2.a where t2.a is null; @@ -454,16 +342,7 @@ where from tab_anti as t2 where - t2.b in - ( - select - t1.b - from - tab_anti as t3 - where - t2.a > 1 - offset 0 - ) + t2.b in (select t1.b from tab_anti as t3 where t2.a > 1 offset 0) ); drop table tab_anti; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_80.snap index 3605e8c53..6ec571172 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__memoize_80.snap @@ -2,10 +2,10 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/memoize.sql --- -create function explain_memoize(query text, hide_hitmiss boolean) +create function explain_memoize(query text, hide_hitmiss bool) returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin @@ -29,143 +29,95 @@ begin return next ln; end loop; end; -$function$; +$$; set enable_hashjoin = off; set enable_bitmapscan = off; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 INNER JOIN tenk1 t2 ON t1.unique1 = t2.twenty -WHERE t2.unique1 < 1000;', - false - ); +WHERE t2.unique1 < 1000;', false); select - COUNT(*), - AVG(t1.unique1) + count(*), + avg(t1.unique1) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.twenty + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.twenty where t2.unique1 < 1000; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1, LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1 OFFSET 0) t2 -WHERE t1.unique1 < 1000;', - false - ); +WHERE t1.unique1 < 1000;', false); select - COUNT(*), - AVG(t2.unique1) + count(*), + avg(t2.unique1) from tenk1 as t1, lateral ( - select - t2.unique1 - from - tenk1 as t2 - where - t1.twenty = t2.unique1 - offset 0 + select t2.unique1 from tenk1 as t2 where t1.twenty = t2.unique1 offset 0 ) as t2 where t1.unique1 < 1000; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*),AVG(t2.t1two) FROM tenk1 t1 LEFT JOIN LATERAL ( SELECT t1.two as t1two, * FROM tenk1 t2 WHERE t2.unique1 < 4 OFFSET 0 ) t2 ON t1.two = t2.two -WHERE t1.unique1 < 10;', - false - ); +WHERE t1.unique1 < 10;', false); select - COUNT(*), - AVG(t2.t1two) + count(*), + avg(t2.t1two) from tenk1 as t1 left outer join lateral ( - select - t1.two as t1two, - * - from - tenk1 as t2 - where - t2.unique1 < 4 - offset 0 + select t1.two as t1two, * from tenk1 as t2 where t2.unique1 < 4 offset 0 ) as t2 on t1.two = t2.two where t1.unique1 < 10; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*), AVG(t1.twenty) FROM tenk1 t1 LEFT JOIN LATERAL (SELECT t1.two+1 AS c1, t2.unique1 AS c2 FROM tenk1 t2) s ON TRUE -WHERE s.c1 = s.c2 AND t1.unique1 < 1000;', - false - ); +WHERE s.c1 = s.c2 AND t1.unique1 < 1000;', false); select - COUNT(*), - AVG(t1.twenty) + count(*), + avg(t1.twenty) from tenk1 as t1 left outer join - lateral ( - select - t1.two + 1 as c1, - t2.unique1 as c2 - from - tenk1 as t2 - ) - as s + lateral (select t1.two + 1 as c1, t2.unique1 as c2 from tenk1 as t2) as s on true where s.c1 = s.c2 and t1.unique1 < 1000; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*), AVG(t1.twenty) FROM tenk1 t1 LEFT JOIN LATERAL (SELECT t1.twenty AS c1, t2.unique1 AS c2, t2.two FROM tenk1 t2) s ON t1.two = s.two -WHERE s.c1 = s.c2 AND t1.unique1 < 1000;', - false - ); +WHERE s.c1 = s.c2 AND t1.unique1 < 1000;', false); select - COUNT(*), - AVG(t1.twenty) + count(*), + avg(t1.twenty) from tenk1 as t1 left outer join lateral ( - select - t1.twenty as c1, - t2.unique1 as c2, - t2.two - from - tenk1 as t2 + select t1.twenty as c1, t2.unique1 as c2, t2.two from tenk1 as t2 ) as s on t1.two = s.two @@ -186,8 +138,7 @@ select from ( select - round(cast(d / pi() as numeric), 7) - as d1 + round(cast(d / pi() as numeric), 7) as d1 from generate_series(1, 20) as d ) @@ -195,17 +146,13 @@ from insert into expr_key select * from expr_key; -create index "expr_key_idx_x_t" on expr_key using btree (x, t); +create index expr_key_idx_x_t on expr_key using btree (x, t); -vacuum (ANALYZE) expr_key; +vacuum (analyze) expr_key; -select - explain_memoize( - ' +select explain_memoize(' SELECT * FROM expr_key t1 INNER JOIN expr_key t2 -ON t1.x = t2.t::numeric AND t1.t::numeric = t2.x;', - false - ); +ON t1.x = t2.t::numeric AND t1.t::numeric = t2.x;', false); drop table expr_key; @@ -213,41 +160,27 @@ set work_mem = '64kB'; set hash_mem_multiplier = 1.0; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 INNER JOIN tenk1 t2 ON t1.unique1 = t2.thousand -WHERE t2.unique1 < 1200;', - true - ); +WHERE t2.unique1 < 1200;', true); create table flt (f double precision); -create index "flt_f_idx" on flt using btree (f); +create index flt_f_idx on flt using btree (f); insert into flt -values - (cast('-0.0' as double precision)), - (cast('+0.0' as double precision)); +values (cast('-0.0' as double precision)), (cast('+0.0' as double precision)); analyze flt; set enable_seqscan = off; -select - explain_memoize( - ' -SELECT * FROM flt f1 INNER JOIN flt f2 ON f1.f = f2.f;', - false - ); +select explain_memoize(' +SELECT * FROM flt f1 INNER JOIN flt f2 ON f1.f = f2.f;', false); -select - explain_memoize( - ' -SELECT * FROM flt f1 INNER JOIN flt f2 ON f1.f >= f2.f;', - false - ); +select explain_memoize(' +SELECT * FROM flt f1 INNER JOIN flt f2 ON f1.f >= f2.f;', false); drop table flt; @@ -256,35 +189,25 @@ create table strtest ( t text ); -create index "strtest_n_idx" on strtest using btree (n); +create index strtest_n_idx on strtest using btree (n); -create index "strtest_t_idx" on strtest using btree (t); +create index strtest_t_idx on strtest using btree (t); insert into strtest values ('one', 'one'), ('two', 'two'), - ( - 'three', repeat(fipshash('three'), 100) - ); + ('three', repeat(fipshash('three'), 100)); insert into strtest select * from strtest; analyze strtest; -select - explain_memoize( - ' -SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.n >= s2.n;', - false - ); +select explain_memoize(' +SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.n >= s2.n;', false); -select - explain_memoize( - ' -SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.t >= s2.t;', - false - ); +select explain_memoize(' +SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.t >= s2.t;', false); drop table strtest; @@ -301,29 +224,21 @@ insert into prt values (0), (0), (0), (0); insert into prt values (10), (10), (10), (10); -create index "iprt_p1_a" on prt_p1 using btree (a); +create index iprt_p1_a on prt_p1 using btree (a); -create index "iprt_p2_a" on prt_p2 using btree (a); +create index iprt_p2_a on prt_p2 using btree (a); analyze prt; -select - explain_memoize( - ' -SELECT * FROM prt t1 INNER JOIN prt t2 ON t1.a = t2.a;', - false - ); +select explain_memoize(' +SELECT * FROM prt t1 INNER JOIN prt t2 ON t1.a = t2.a;', false); set enable_partitionwise_join = off; -select - explain_memoize( - ' +select explain_memoize(' SELECT * FROM prt_p1 t1 INNER JOIN (SELECT * FROM prt_p1 UNION ALL SELECT * FROM prt_p2) t2 -ON t1.a = t2.a;', - false - ); +ON t1.a = t2.a;', false); drop table prt; @@ -340,10 +255,7 @@ where select 1 from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.hundred + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.hundred where t0.ten = t1.twenty and t0.two <> t2.four offset 0 @@ -360,10 +272,7 @@ where select 1 from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.hundred + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.hundred where t0.ten = t1.twenty and t0.two <> t2.four offset 0 @@ -390,34 +299,24 @@ set parallel_tuple_cost = 0; set max_parallel_workers_per_gather = 2; select - COUNT(*), - AVG(t2.unique1) + count(*), + avg(t2.unique1) from tenk1 as t1, lateral ( - select - t2.unique1 - from - tenk1 as t2 - where - t1.twenty = t2.unique1 + select t2.unique1 from tenk1 as t2 where t1.twenty = t2.unique1 ) as t2 where t1.unique1 < 1000; select - COUNT(*), - AVG(t2.unique1) + count(*), + avg(t2.unique1) from tenk1 as t1, lateral ( - select - t2.unique1 - from - tenk1 as t2 - where - t1.twenty = t2.unique1 + select t2.unique1 from tenk1 as t2 where t1.twenty = t2.unique1 ) as t2 where @@ -440,30 +339,18 @@ insert into tab_anti select i % 3, false from generate_series(1, 100) as i; analyze tab_anti; -select - explain_memoize( - ' +select explain_memoize(' SELECT COUNT(*) FROM tab_anti t1 LEFT JOIN LATERAL (SELECT DISTINCT ON (a) a, b, t1.a AS x FROM tab_anti t2) t2 ON t1.a+1 = t2.a -WHERE t2.a IS NULL;', - false - ); +WHERE t2.a IS NULL;', false); select - COUNT(*) + count(*) from tab_anti as t1 left outer join - lateral ( - select distinct on (a) - a, - b, - t1.a as x - from - tab_anti as t2 - ) - as t2 + lateral (select distinct on (a) a, b, t1.a as x from tab_anti as t2) as t2 on t1.a + 1 = t2.a where t2.a is null; @@ -480,16 +367,7 @@ where from tab_anti as t2 where - t2.b in - ( - select - t1.b - from - tab_anti as t3 - where - t2.a > 1 - offset 0 - ) + t2.b in (select t1.b from tab_anti as t3 where t2.a > 1 offset 0) ); drop table tab_anti; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__merge_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__merge_100.snap index f403fbfae..a704dbb87 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__merge_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__merge_100.snap @@ -35,10 +35,7 @@ select t.*, s.* from - source as s - full outer join - target as t - on s.sid = t.tid + source as s full outer join target as t on s.sid = t.tid order by t.tid, s.sid; @@ -66,7 +63,7 @@ alter table target2 alter table source2 owner to regress_merge_no_privs; -grant INSERT on table target to regress_merge_no_privs; +grant insert on table target to regress_merge_no_privs; set session authorization regress_merge_privs; @@ -90,11 +87,11 @@ merge into target using (select 1) on true when matched then do nothing; set session authorization regress_merge_privs; -grant INSERT on table target to regress_merge_no_privs; +grant insert on table target to regress_merge_no_privs; set session authorization regress_merge_no_privs; -grant UPDATE on table target2 to regress_merge_privs; +grant update on table target2 to regress_merge_privs; set session authorization regress_merge_privs; @@ -337,7 +334,7 @@ drop table wq_target, wq_source; create or replace function merge_trigfunc() returns trigger language plpgsql -as $function$ +as $$ DECLARE line text; BEGIN @@ -362,7 +359,7 @@ BEGIN RETURN NULL; END IF; END; -$function$; +$$; create trigger merge_bsi before insert @@ -431,11 +428,11 @@ rollback; create or replace function skip_merge_op() returns trigger language plpgsql -as $function$ +as $$ BEGIN RETURN NULL; END; -$function$; +$$; select * from target full outer join source on sid = tid; @@ -445,8 +442,7 @@ on target for each row execute function skip_merge_op(); -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -464,7 +460,7 @@ END IF; GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from target full outer join source on sid = tid; @@ -474,9 +470,7 @@ drop function skip_merge_op(); begin; -do -language plpgsql -$do$ +do language plpgsql $$ BEGIN MERGE INTO target t USING source AS s @@ -484,7 +478,7 @@ ON t.tid = s.sid WHEN MATCHED AND t.balance > s.delta THEN UPDATE SET balance = t.balance - s.delta; END; -$do$; +$$; rollback; @@ -529,7 +523,7 @@ begin; create function merge_func(p_id int, p_bal int) returns int language plpgsql -as $function$ +as $$ DECLARE result integer; BEGIN @@ -543,7 +537,7 @@ IF FOUND THEN END IF; RETURN result; END; -$function$; +$$; select merge_func(3, 4); @@ -619,12 +613,8 @@ with targq as (select * from v) merge into sq_target as t using v on tid = sid -when matched and - tid >= 2 -then update set balance = t.balance + delta -when not matched by target -then insert (balance, tid) -values (balance + delta, sid) +when matched and tid >= 2 then update set balance = t.balance + delta +when not matched by target then insert (balance, tid) values (balance + delta, sid) when matched and tid < 2 then delete; rollback; @@ -663,12 +653,8 @@ as ( merge into sq_target as t using sq_source as s on tid = sid - when matched and - tid >= 2 - then update set balance = t.balance + delta - when not matched by target - then insert (balance, tid) - values (balance + delta, sid) + when matched and tid >= 2 then update set balance = t.balance + delta + when not matched by target then insert (balance, tid) values (balance + delta, sid) when matched and tid < 2 then delete returning "mergesupport#25" as action, old as old_data, @@ -676,8 +662,7 @@ as ( t.*, case "mergesupport#25" when 'INSERT' then 'Inserted ' || t - when 'UPDATE' - then 'Added ' || delta || ' to balance' + when 'UPDATE' then 'Added ' || delta || ' to balance' when 'DELETE' then 'Removed ' || t end as description @@ -687,11 +672,8 @@ as ( merge into sq_target_merge_log as l using m on l.tid = m.tid - when matched - then update set last_change = description - when not matched by target - then insert - values (m.tid, description) + when matched then update set last_change = description + when not matched by target then insert values (m.tid, description) returning m.*, "mergesupport#25" as log_action, old as old_log, @@ -712,12 +694,8 @@ begin; copy (merge into sq_target as t using sq_source as s on tid = sid -when matched and - tid >= 2 -then update set balance = t.balance + delta -when not matched by target -then insert (balance, tid) -values (balance + delta, sid) +when matched and tid >= 2 then update set balance = t.balance + delta +when not matched by target then insert (balance, tid) values (balance + delta, sid) when matched and tid < 2 then delete returning "mergesupport#25", old.*, @@ -738,8 +716,8 @@ merge_into_sq_target( out new_balance int ) language sql -as $function$ -MERGE INTO sq_target t +as $$ + MERGE INTO sq_target t USING (VALUES ($1, $2, $3)) AS v(sid, balance, delta) ON tid = v.sid WHEN MATCHED AND tid >= 2 THEN @@ -749,24 +727,13 @@ MERGE INTO sq_target t WHEN MATCHED AND tid < 2 THEN DELETE RETURNING merge_action(), t.*; -$function$; +$$; select m.* from - ( - values (1, 0, 0), (3, 0, 20), (4, 100, 10) - ) - as v (sid, balance, delta), - lateral ( - select - action, - tid, - new_balance - from - merge_into_sq_target(sid, balance, delta) - ) - as m; + (values (1, 0, 0), (3, 0, 20), (4, 100, 10)) as v (sid, balance, delta), + lateral (select action, tid, new_balance from merge_into_sq_target(sid, balance, delta)) as m; rollback; @@ -779,8 +746,8 @@ returns table ( balance int ) language sql -as $function$ -MERGE INTO sq_target t +as $$ + MERGE INTO sq_target t USING sq_source s ON tid = sid WHEN MATCHED AND tid >= 2 THEN @@ -790,7 +757,7 @@ MERGE INTO sq_target t WHEN MATCHED AND tid < 2 THEN DELETE RETURNING merge_action(), t.*; -$function$; +$$; select * from merge_sq_source_into_sq_target(); @@ -808,7 +775,7 @@ merge_into_sq_target( out r_balance int ) language plpgsql -as $function$ +as $$ BEGIN MERGE INTO sq_target t USING (VALUES ($1, $2, $3)) AS v(sid, balance, delta) @@ -821,24 +788,13 @@ BEGIN DELETE RETURNING merge_action(), t.* INTO r_action, r_tid, r_balance; END; -$function$; +$$; select m.* from - ( - values (1, 0, 0), (3, 0, 20), (4, 100, 10) - ) - as v (sid, balance, delta), - lateral ( - select - r_action, - r_tid, - r_balance - from - merge_into_sq_target(sid, balance, delta) - ) - as m; + (values (1, 0, 0), (3, 0, 20), (4, 100, 10)) as v (sid, balance, delta), + lateral (select r_action, r_tid, r_balance from merge_into_sq_target(sid, balance, delta)) as m; rollback; @@ -861,7 +817,7 @@ insert into ex_msource select i, i * 10 from generate_series(1, 100, 1) as i; create function explain_merge(query text) returns setof text language plpgsql -as $function$ +as $$ DECLARE ln text; BEGIN FOR ln IN @@ -872,79 +828,55 @@ BEGIN RETURN NEXT ln; END LOOP; END; -$function$; +$$; -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN MATCHED THEN - UPDATE SET b = t.b + 1' - ); + UPDATE SET b = t.b + 1'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN MATCHED AND t.a < 10 THEN - UPDATE SET b = t.b + 1' - ); + UPDATE SET b = t.b + 1'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN MATCHED AND t.a < 10 THEN UPDATE SET b = t.b + 1 WHEN MATCHED AND t.a >= 10 AND t.a <= 20 THEN - DELETE' - ); + DELETE'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN NOT MATCHED AND s.a < 10 THEN - INSERT VALUES (a, b)' - ); + INSERT VALUES (a, b)'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN MATCHED AND t.a < 10 THEN UPDATE SET b = t.b + 1 WHEN MATCHED AND t.a >= 30 AND t.a <= 40 THEN DELETE WHEN NOT MATCHED AND s.a < 20 THEN - INSERT VALUES (a, b)' - ); + INSERT VALUES (a, b)'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN NOT MATCHED BY SOURCE and t.a < 10 THEN - DELETE' - ); + DELETE'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN NOT MATCHED BY SOURCE AND t.a < 10 THEN DELETE WHEN NOT MATCHED BY TARGET AND s.a < 20 THEN - INSERT VALUES (a, b)' - ); + INSERT VALUES (a, b)'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a AND t.a < -1000 WHEN MATCHED AND t.a < 10 THEN - DO NOTHING' - ); + DO NOTHING'); drop table ex_msource, ex_mtarget; @@ -996,7 +928,7 @@ create table pa_target ( balance double precision, val text ) -partition by LIST(tid); +partition by list(tid); create table part1 partition of pa_target for values in (1, 4) with (autovacuum_enabled = off); @@ -1032,7 +964,7 @@ begin; create function merge_func() returns int language plpgsql -as $function$ +as $$ DECLARE result integer; BEGIN @@ -1050,7 +982,7 @@ IF FOUND THEN END IF; RETURN result; END; -$function$; +$$; select merge_func(); @@ -1079,7 +1011,7 @@ create table pa_target ( balance double precision, val text ) -partition by LIST(tid); +partition by list(tid); create table part1 ( tid int, @@ -1133,8 +1065,7 @@ insert into pa_target select id, id * 100, 'initial' from generate_series(1, 15, begin; -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -1150,7 +1081,7 @@ MERGE INTO pa_target t GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from pa_target order by tid, val; @@ -1164,8 +1095,7 @@ rollback; begin; -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -1181,7 +1111,7 @@ MERGE INTO pa_target t GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from pa_target order by tid, val; @@ -1192,14 +1122,11 @@ begin; create function trig_fn() returns trigger language plpgsql -as $function$ -BEGIN RETURN NULL; END; -$function$; +as $$ BEGIN RETURN NULL; END; $$; create trigger del_trig before delete on pa_target for each row execute function trig_fn(); -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -1215,7 +1142,7 @@ MERGE INTO pa_target t GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from pa_target order by tid, val; @@ -1226,14 +1153,11 @@ begin; create function trig_fn() returns trigger language plpgsql -as $function$ -BEGIN RETURN NULL; END; -$function$; +as $$ BEGIN RETURN NULL; END; $$; create trigger ins_trig before insert on pa_target for each row execute function trig_fn(); -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -1249,7 +1173,7 @@ MERGE INTO pa_target t GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from pa_target order by tid, val; @@ -1282,7 +1206,7 @@ partition by range(logts); create table part_m01 partition of pa_target for values from ('2017-01-01') to ('2017-02-01') -partition by LIST(tid); +partition by list(tid); create table part_m01_odd partition of part_m01 @@ -1297,7 +1221,7 @@ with (autovacuum_enabled = off); create table part_m02 partition of pa_target for values from ('2017-02-01') to ('2017-03-01') -partition by LIST(tid); +partition by list(tid); create table part_m02_odd partition of part_m02 @@ -1318,22 +1242,10 @@ with (autovacuum_enabled = off); insert into pa_source select id, id * 10 from generate_series(1, 14) as id; insert into pa_target -select - '2017-01-31', - id, - id * 100, - 'initial' -from - generate_series(1, 9, 3) as id; +select '2017-01-31', id, id * 100, 'initial' from generate_series(1, 9, 3) as id; insert into pa_target -select - '2017-02-28', - id, - id * 100, - 'initial' -from - generate_series(2, 9, 3) as id; +select '2017-02-28', id, id * 100, 'initial' from generate_series(2, 9, 3) as id; begin; @@ -1346,7 +1258,7 @@ drop table pa_source; drop table pa_target cascade; create table pa_target (tid int primary key) -partition by LIST(tid); +partition by list(tid); create table pa_targetp partition of pa_target default; @@ -1415,7 +1327,7 @@ create table fs_target ( ) with (autovacuum_enabled = off); -select COUNT(*) from fs_target; +select count(*) from fs_target; drop table fs_target; @@ -1428,15 +1340,13 @@ create table measurement ( with (autovacuum_enabled = off); create table measurement_y2006m02 ( - check (logdate >= cast('2006-02-01' as date) and - logdate < cast('2006-03-01' as date)) + check (logdate >= cast('2006-02-01' as date) and logdate < cast('2006-03-01' as date)) ) inherits (measurement) with (autovacuum_enabled = off); create table measurement_y2006m03 ( - check (logdate >= cast('2006-03-01' as date) and - logdate < cast('2006-04-01' as date)) + check (logdate >= cast('2006-03-01' as date) and logdate < cast('2006-04-01' as date)) ) inherits (measurement) with (autovacuum_enabled = off); @@ -1447,8 +1357,7 @@ create table measurement_y2007m01 ( logdate date not null, city_id int not null, unitsales int - check (logdate >= cast('2007-01-01' as date) and - logdate < cast('2007-02-01' as date)) + check (logdate >= cast('2007-01-01' as date) and logdate < cast('2007-02-01' as date)) ) with (autovacuum_enabled = off); @@ -1463,7 +1372,7 @@ insert into measurement values (0, '2005-07-21', 5, 15); create or replace function measurement_insert_trigger() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF ( NEW.logdate >= DATE '2006-02-01' AND NEW.logdate < DATE '2006-03-01' ) THEN @@ -1480,7 +1389,7 @@ BEGIN END IF; RETURN NULL; END; -$function$; +$$; create trigger insert_measurement_trigger before insert @@ -1539,7 +1448,7 @@ select * from new_measurement order by city_id, logdate; drop trigger insert_measurement_trigger on measurement; alter table measurement - add constraint "mcheck" check (city_id = 0) no inherit; + add constraint mcheck check (city_id = 0) no inherit; begin; @@ -1593,12 +1502,7 @@ create table bug18634t ( insert into bug18634t values (1, 10, 'tgt1'), (2, 20, 'tgt2'); create view bug18634v -as select - * -from - bug18634t -where - exists (select 1 from bug18634t); +as select * from bug18634t where exists (select 1 from bug18634t); create table bug18634s ( a int, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__merge_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__merge_80.snap index 7ef650da9..4f08540e9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__merge_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__merge_80.snap @@ -35,10 +35,7 @@ select t.*, s.* from - source as s - full outer join - target as t - on s.sid = t.tid + source as s full outer join target as t on s.sid = t.tid order by t.tid, s.sid; @@ -66,7 +63,7 @@ alter table target2 alter table source2 owner to regress_merge_no_privs; -grant INSERT on table target to regress_merge_no_privs; +grant insert on table target to regress_merge_no_privs; set session authorization regress_merge_privs; @@ -76,23 +73,13 @@ update target set balance = 0; merge into target using target on tid = tid when matched then do nothing; -with -foo -as ( - merge into target - using source - on true - when matched then delete -) +with foo as (merge into target using source on true when matched then delete) select * from foo; -copy (merge into target -using source -on true -when matched then delete) +copy (merge into target using source on true when matched then delete) to stdout; create materialized view mv as select * from target; @@ -105,11 +92,11 @@ merge into target using (select 1) on true when matched then do nothing; set session authorization regress_merge_privs; -grant INSERT on table target to regress_merge_no_privs; +grant insert on table target to regress_merge_no_privs; set session authorization regress_merge_no_privs; -grant UPDATE on table target2 to regress_merge_privs; +grant update on table target2 to regress_merge_privs; set session authorization regress_merge_privs; @@ -126,8 +113,7 @@ select * from target order by tid; merge into target as t using source as s on t.tid = s.sid -when not matched by target -then do nothing; +when not matched by target then do nothing; begin; @@ -356,7 +342,7 @@ drop table wq_target, wq_source; create or replace function merge_trigfunc() returns trigger language plpgsql -as $function$ +as $$ DECLARE line text; BEGIN @@ -381,7 +367,7 @@ BEGIN RETURN NULL; END IF; END; -$function$; +$$; create trigger merge_bsi before insert @@ -474,11 +460,11 @@ rollback; create or replace function skip_merge_op() returns trigger language plpgsql -as $function$ +as $$ BEGIN RETURN NULL; END; -$function$; +$$; select * from target full outer join source on sid = tid; @@ -488,8 +474,7 @@ on target for each row execute function skip_merge_op(); -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -507,7 +492,7 @@ END IF; GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from target full outer join source on sid = tid; @@ -517,9 +502,7 @@ drop function skip_merge_op(); begin; -do -language plpgsql -$do$ +do language plpgsql $$ BEGIN MERGE INTO target t USING source AS s @@ -527,7 +510,7 @@ ON t.tid = s.sid WHEN MATCHED AND t.balance > s.delta THEN UPDATE SET balance = t.balance - s.delta; END; -$do$; +$$; rollback; @@ -572,7 +555,7 @@ begin; create function merge_func(p_id int, p_bal int) returns int language plpgsql -as $function$ +as $$ DECLARE result integer; BEGIN @@ -586,7 +569,7 @@ IF FOUND THEN END IF; RETURN result; END; -$function$; +$$; select merge_func(3, 4); @@ -662,9 +645,7 @@ with targq as (select * from v) merge into sq_target as t using v on tid = sid -when matched and - tid >= 2 -then update set balance = t.balance + delta +when matched and tid >= 2 then update set balance = t.balance + delta when not matched by target then insert (balance, tid) values (balance + delta, sid) @@ -684,10 +665,7 @@ create table merge_actions ( ); insert into merge_actions -values - ('INSERT', 'ins'), - ('UPDATE', 'upd'), - ('DELETE', 'del'); +values ('INSERT', 'ins'), ('UPDATE', 'upd'), ('DELETE', 'del'); rollback; @@ -710,9 +688,7 @@ as ( merge into sq_target as t using sq_source as s on tid = sid - when matched and - tid >= 2 - then update set balance = t.balance + delta + when matched and tid >= 2 then update set balance = t.balance + delta when not matched by target then insert (balance, tid) values (balance + delta, sid) @@ -723,8 +699,7 @@ as ( t.*, case "mergesupport#25" when 'INSERT' then 'Inserted ' || t - when 'UPDATE' - then 'Added ' || delta || ' to balance' + when 'UPDATE' then 'Added ' || delta || ' to balance' when 'DELETE' then 'Removed ' || t end as description @@ -734,11 +709,8 @@ as ( merge into sq_target_merge_log as l using m on l.tid = m.tid - when matched - then update set last_change = description - when not matched by target - then insert - values (m.tid, description) + when matched then update set last_change = description + when not matched by target then insert values (m.tid, description) returning m.*, "mergesupport#25" as log_action, old as old_log, @@ -759,9 +731,7 @@ begin; copy (merge into sq_target as t using sq_source as s on tid = sid -when matched and - tid >= 2 -then update set balance = t.balance + delta +when matched and tid >= 2 then update set balance = t.balance + delta when not matched by target then insert (balance, tid) values (balance + delta, sid) @@ -785,8 +755,8 @@ merge_into_sq_target( out new_balance int ) language sql -as $function$ -MERGE INTO sq_target t +as $$ + MERGE INTO sq_target t USING (VALUES ($1, $2, $3)) AS v(sid, balance, delta) ON tid = v.sid WHEN MATCHED AND tid >= 2 THEN @@ -796,29 +766,19 @@ MERGE INTO sq_target t WHEN MATCHED AND tid < 2 THEN DELETE RETURNING merge_action(), t.*; -$function$; +$$; select m.* from - ( - values - (1, 0, 0), - (3, 0, 20), - (4, 100, 10) - ) - as v (sid, balance, delta), + (values (1, 0, 0), (3, 0, 20), (4, 100, 10)) as v (sid, balance, delta), lateral ( select action, tid, new_balance from - merge_into_sq_target( - sid, - balance, - delta - ) + merge_into_sq_target(sid, balance, delta) ) as m; @@ -833,8 +793,8 @@ returns table ( balance int ) language sql -as $function$ -MERGE INTO sq_target t +as $$ + MERGE INTO sq_target t USING sq_source s ON tid = sid WHEN MATCHED AND tid >= 2 THEN @@ -844,7 +804,7 @@ MERGE INTO sq_target t WHEN MATCHED AND tid < 2 THEN DELETE RETURNING merge_action(), t.*; -$function$; +$$; select * from merge_sq_source_into_sq_target(); @@ -862,7 +822,7 @@ merge_into_sq_target( out r_balance int ) language plpgsql -as $function$ +as $$ BEGIN MERGE INTO sq_target t USING (VALUES ($1, $2, $3)) AS v(sid, balance, delta) @@ -875,29 +835,19 @@ BEGIN DELETE RETURNING merge_action(), t.* INTO r_action, r_tid, r_balance; END; -$function$; +$$; select m.* from - ( - values - (1, 0, 0), - (3, 0, 20), - (4, 100, 10) - ) - as v (sid, balance, delta), + (values (1, 0, 0), (3, 0, 20), (4, 100, 10)) as v (sid, balance, delta), lateral ( select r_action, r_tid, r_balance from - merge_into_sq_target( - sid, - balance, - delta - ) + merge_into_sq_target(sid, balance, delta) ) as m; @@ -922,7 +872,7 @@ insert into ex_msource select i, i * 10 from generate_series(1, 100, 1) as i; create function explain_merge(query text) returns setof text language plpgsql -as $function$ +as $$ DECLARE ln text; BEGIN FOR ln IN @@ -933,79 +883,55 @@ BEGIN RETURN NEXT ln; END LOOP; END; -$function$; +$$; -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN MATCHED THEN - UPDATE SET b = t.b + 1' - ); + UPDATE SET b = t.b + 1'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN MATCHED AND t.a < 10 THEN - UPDATE SET b = t.b + 1' - ); + UPDATE SET b = t.b + 1'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN MATCHED AND t.a < 10 THEN UPDATE SET b = t.b + 1 WHEN MATCHED AND t.a >= 10 AND t.a <= 20 THEN - DELETE' - ); + DELETE'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN NOT MATCHED AND s.a < 10 THEN - INSERT VALUES (a, b)' - ); + INSERT VALUES (a, b)'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN MATCHED AND t.a < 10 THEN UPDATE SET b = t.b + 1 WHEN MATCHED AND t.a >= 30 AND t.a <= 40 THEN DELETE WHEN NOT MATCHED AND s.a < 20 THEN - INSERT VALUES (a, b)' - ); + INSERT VALUES (a, b)'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN NOT MATCHED BY SOURCE and t.a < 10 THEN - DELETE' - ); + DELETE'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a WHEN NOT MATCHED BY SOURCE AND t.a < 10 THEN DELETE WHEN NOT MATCHED BY TARGET AND s.a < 20 THEN - INSERT VALUES (a, b)' - ); + INSERT VALUES (a, b)'); -select - explain_merge( - ' +select explain_merge(' MERGE INTO ex_mtarget t USING ex_msource s ON t.a = s.a AND t.a < -1000 WHEN MATCHED AND t.a < 10 THEN - DO NOTHING' - ); + DO NOTHING'); drop table ex_msource, ex_mtarget; @@ -1057,7 +983,7 @@ create table pa_target ( balance double precision, val text ) -partition by LIST(tid); +partition by list(tid); create table part1 partition of pa_target @@ -1087,12 +1013,7 @@ create table pa_source ( insert into pa_source select id, id * 10 from generate_series(1, 14) as id; insert into pa_target -select - id, - id * 100, - 'initial' -from - generate_series(1, 15, 2) as id; +select id, id * 100, 'initial' from generate_series(1, 15, 2) as id; begin; @@ -1111,7 +1032,7 @@ begin; create function merge_func() returns int language plpgsql -as $function$ +as $$ DECLARE result integer; BEGIN @@ -1129,7 +1050,7 @@ IF FOUND THEN END IF; RETURN result; END; -$function$; +$$; select merge_func(); @@ -1158,7 +1079,7 @@ create table pa_target ( balance double precision, val text ) -partition by LIST(tid); +partition by list(tid); create table part1 ( tid int, @@ -1209,17 +1130,11 @@ alter table pa_target part4 default; insert into pa_target -select - id, - id * 100, - 'initial' -from - generate_series(1, 15, 2) as id; +select id, id * 100, 'initial' from generate_series(1, 15, 2) as id; begin; -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -1235,7 +1150,7 @@ MERGE INTO pa_target t GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from pa_target order by tid, val; @@ -1249,8 +1164,7 @@ rollback; begin; -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -1266,7 +1180,7 @@ MERGE INTO pa_target t GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from pa_target order by tid, val; @@ -1277,9 +1191,7 @@ begin; create function trig_fn() returns trigger language plpgsql -as $function$ -BEGIN RETURN NULL; END; -$function$; +as $$ BEGIN RETURN NULL; END; $$; create trigger del_trig before delete @@ -1287,8 +1199,7 @@ on pa_target for each row execute function trig_fn(); -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -1304,7 +1215,7 @@ MERGE INTO pa_target t GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from pa_target order by tid, val; @@ -1315,9 +1226,7 @@ begin; create function trig_fn() returns trigger language plpgsql -as $function$ -BEGIN RETURN NULL; END; -$function$; +as $$ BEGIN RETURN NULL; END; $$; create trigger ins_trig before insert @@ -1325,8 +1234,7 @@ on pa_target for each row execute function trig_fn(); -do -$do$ +do $$ DECLARE result integer; BEGIN @@ -1342,7 +1250,7 @@ MERGE INTO pa_target t GET DIAGNOSTICS result := ROW_COUNT; RAISE NOTICE 'ROW_COUNT = %', result; END; -$do$; +$$; select * from pa_target order by tid, val; @@ -1380,7 +1288,7 @@ partition by range(logts); create table part_m01 partition of pa_target for values from ('2017-01-01') to ('2017-02-01') -partition by LIST(tid); +partition by list(tid); create table part_m01_odd partition of part_m01 @@ -1395,7 +1303,7 @@ with (autovacuum_enabled = off); create table part_m02 partition of pa_target for values from ('2017-02-01') to ('2017-03-01') -partition by LIST(tid); +partition by list(tid); create table part_m02_odd partition of part_m02 @@ -1444,7 +1352,7 @@ drop table pa_source; drop table pa_target cascade; create table pa_target (tid int primary key) -partition by LIST(tid); +partition by list(tid); create table pa_targetp partition of pa_target default; @@ -1513,7 +1421,7 @@ create table fs_target ( ) with (autovacuum_enabled = off); -select COUNT(*) from fs_target; +select count(*) from fs_target; drop table fs_target; @@ -1545,8 +1453,8 @@ create table measurement_y2007m01 ( logdate date not null, city_id int not null, unitsales int - check (logdate >= cast('2007-01-01' as date) and - logdate < cast('2007-02-01' as date)) + check (logdate >= cast('2007-01-01' as date) and + logdate < cast('2007-02-01' as date)) ) with (autovacuum_enabled = off); @@ -1561,7 +1469,7 @@ insert into measurement values (0, '2005-07-21', 5, 15); create or replace function measurement_insert_trigger() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF ( NEW.logdate >= DATE '2006-02-01' AND NEW.logdate < DATE '2006-03-01' ) THEN @@ -1578,7 +1486,7 @@ BEGIN END IF; RETURN NULL; END; -$function$; +$$; create trigger insert_measurement_trigger before insert @@ -1644,7 +1552,7 @@ select * from new_measurement order by city_id, logdate; drop trigger insert_measurement_trigger on measurement; alter table measurement - add constraint "mcheck" check (city_id = 0) no inherit; + add constraint mcheck check (city_id = 0) no inherit; begin; @@ -1698,12 +1606,7 @@ create table bug18634t ( insert into bug18634t values (1, 10, 'tgt1'), (2, 20, 'tgt2'); create view bug18634v -as select - * -from - bug18634t -where - exists (select 1 from bug18634t); +as select * from bug18634t where exists (select 1 from bug18634t); create table bug18634s ( a int, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_100.snap index f94e3228a..c6272bdbf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_100.snap @@ -3,20 +3,16 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/misc.sql --- create function overpaid(emp) -returns boolean +returns bool language c strict -as $function$ -regresslib -$function$; +as 'regresslib'; create function reverse_name(name) returns name language c strict -as $function$ -regresslib -$function$; +as 'regresslib'; update onek set unique1 = onek.unique1 + 1; @@ -28,15 +24,13 @@ update tmp set stringu1 = reverse_name(onek.stringu1) from onek where - onek.stringu1 = 'JBAAAA' and - onek.stringu1 = tmp.stringu1; + onek.stringu1 = 'JBAAAA' and onek.stringu1 = tmp.stringu1; update tmp set stringu1 = reverse_name(onek2.stringu1) from onek2 where - onek2.stringu1 = 'JCAAAA' and - onek2.stringu1 = tmp.stringu1; + onek2.stringu1 = 'JCAAAA' and onek2.stringu1 = tmp.stringu1; drop table tmp; @@ -50,11 +44,11 @@ select * from onek except all select * from onek_copy; select * from onek_copy except all select * from onek; -copy stud_emp to 'filename' with (FORMAT 'binary'); +copy stud_emp to 'filename' with (format 'binary'); create temporary table stud_emp_copy (like stud_emp); -copy stud_emp_copy from 'filename' with (FORMAT 'binary'); +copy stud_emp_copy from 'filename' with (format 'binary'); select * from stud_emp_copy; @@ -69,22 +63,10 @@ create table equipment_r ( ); insert into hobbies_r (name, person) -select - 'posthacking', - p.name -from - person as p -where - p.name = 'mike' or p.name = 'jeff'; +select 'posthacking', p.name from person as p where p.name = 'mike' or p.name = 'jeff'; insert into hobbies_r (name, person) -select - 'basketball', - p.name -from - person as p -where - p.name = 'joe' or p.name = 'sally'; +select 'basketball', p.name from person as p where p.name = 'joe' or p.name = 'sally'; insert into hobbies_r (name) values ('skywalking'); @@ -99,79 +81,57 @@ insert into equipment_r (name, hobby) values ('guts', 'skywalking'); create function hobbies(person) returns setof hobbies_r language sql -as $function$ -select * from hobbies_r where person = $1.name -$function$; +as 'select * from hobbies_r where person = $1.name'; create function hobby_construct(text, text) returns hobbies_r language sql -as $function$ -select $1 as name, $2 as hobby -$function$; +as 'select $1 as name, $2 as hobby'; create function hobby_construct_named(name text, hobby text) returns hobbies_r language sql -as $function$ -select name, hobby -$function$; +as 'select name, hobby'; create function hobbies_by_name(hobbies_r.name%type) returns hobbies_r.person%type language sql -as $function$ -select person from hobbies_r where name = $1 -$function$; +as 'select person from hobbies_r where name = $1'; create function equipment(hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where hobby = $1.name -$function$; +as 'select * from equipment_r where hobby = $1.name'; create function equipment_named(hobby hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where equipment_r.hobby = equipment_named.hobby.name -$function$; +as 'select * from equipment_r where equipment_r.hobby = equipment_named.hobby.name'; create function equipment_named_ambiguous_1a(hobby hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where hobby = equipment_named_ambiguous_1a.hobby.name -$function$; +as 'select * from equipment_r where hobby = equipment_named_ambiguous_1a.hobby.name'; create function equipment_named_ambiguous_1b(hobby hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where equipment_r.hobby = hobby.name -$function$; +as 'select * from equipment_r where equipment_r.hobby = hobby.name'; create function equipment_named_ambiguous_1c(hobby hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where hobby = hobby.name -$function$; +as 'select * from equipment_r where hobby = hobby.name'; create function equipment_named_ambiguous_2a(hobby text) returns setof equipment_r language sql -as $function$ -select * from equipment_r where hobby = equipment_named_ambiguous_2a.hobby -$function$; +as 'select * from equipment_r where hobby = equipment_named_ambiguous_2a.hobby'; create function equipment_named_ambiguous_2b(hobby text) returns setof equipment_r language sql -as $function$ -select * from equipment_r where equipment_r.hobby = hobby -$function$; +as 'select * from equipment_r where equipment_r.hobby = hobby'; select p.name, name(p.hobbies) from only person as p; @@ -198,42 +158,26 @@ select name(equipment(hobby_construct(cast('skywalking' as text), cast('mer' as select name(equipment(hobby_construct_named(cast('skywalking' as text), cast('mer' as text)))); select - name( - equipment_named( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) - ) - ); + name(equipment_named(hobby_construct_named(cast('skywalking' as text), cast('mer' as text)))); select name( equipment_named_ambiguous_1a( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) + hobby_construct_named(cast('skywalking' as text), cast('mer' as text)) ) ); select name( equipment_named_ambiguous_1b( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) + hobby_construct_named(cast('skywalking' as text), cast('mer' as text)) ) ); select name( equipment_named_ambiguous_1c( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) + hobby_construct_named(cast('skywalking' as text), cast('mer' as text)) ) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_80.snap index 9c936e738..17aac5a0a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_80.snap @@ -3,20 +3,16 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/misc.sql --- create function overpaid(emp) -returns boolean +returns bool language c strict -as $function$ -regresslib -$function$; +as 'regresslib'; create function reverse_name(name) returns name language c strict -as $function$ -regresslib -$function$; +as 'regresslib'; update onek set unique1 = onek.unique1 + 1; @@ -28,15 +24,13 @@ update tmp set stringu1 = reverse_name(onek.stringu1) from onek where - onek.stringu1 = 'JBAAAA' and - onek.stringu1 = tmp.stringu1; + onek.stringu1 = 'JBAAAA' and onek.stringu1 = tmp.stringu1; update tmp set stringu1 = reverse_name(onek2.stringu1) from onek2 where - onek2.stringu1 = 'JCAAAA' and - onek2.stringu1 = tmp.stringu1; + onek2.stringu1 = 'JCAAAA' and onek2.stringu1 = tmp.stringu1; drop table tmp; @@ -50,11 +44,11 @@ select * from onek except all select * from onek_copy; select * from onek_copy except all select * from onek; -copy stud_emp to 'filename' with (FORMAT 'binary'); +copy stud_emp to 'filename' with (format 'binary'); create temporary table stud_emp_copy (like stud_emp); -copy stud_emp_copy from 'filename' with (FORMAT 'binary'); +copy stud_emp_copy from 'filename' with (format 'binary'); select * from stud_emp_copy; @@ -99,79 +93,57 @@ insert into equipment_r (name, hobby) values ('guts', 'skywalking'); create function hobbies(person) returns setof hobbies_r language sql -as $function$ -select * from hobbies_r where person = $1.name -$function$; +as 'select * from hobbies_r where person = $1.name'; create function hobby_construct(text, text) returns hobbies_r language sql -as $function$ -select $1 as name, $2 as hobby -$function$; +as 'select $1 as name, $2 as hobby'; create function hobby_construct_named(name text, hobby text) returns hobbies_r language sql -as $function$ -select name, hobby -$function$; +as 'select name, hobby'; create function hobbies_by_name(hobbies_r.name%type) returns hobbies_r.person%type language sql -as $function$ -select person from hobbies_r where name = $1 -$function$; +as 'select person from hobbies_r where name = $1'; create function equipment(hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where hobby = $1.name -$function$; +as 'select * from equipment_r where hobby = $1.name'; create function equipment_named(hobby hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where equipment_r.hobby = equipment_named.hobby.name -$function$; +as 'select * from equipment_r where equipment_r.hobby = equipment_named.hobby.name'; create function equipment_named_ambiguous_1a(hobby hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where hobby = equipment_named_ambiguous_1a.hobby.name -$function$; +as 'select * from equipment_r where hobby = equipment_named_ambiguous_1a.hobby.name'; create function equipment_named_ambiguous_1b(hobby hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where equipment_r.hobby = hobby.name -$function$; +as 'select * from equipment_r where equipment_r.hobby = hobby.name'; create function equipment_named_ambiguous_1c(hobby hobbies_r) returns setof equipment_r language sql -as $function$ -select * from equipment_r where hobby = hobby.name -$function$; +as 'select * from equipment_r where hobby = hobby.name'; create function equipment_named_ambiguous_2a(hobby text) returns setof equipment_r language sql -as $function$ -select * from equipment_r where hobby = equipment_named_ambiguous_2a.hobby -$function$; +as 'select * from equipment_r where hobby = equipment_named_ambiguous_2a.hobby'; create function equipment_named_ambiguous_2b(hobby text) returns setof equipment_r language sql -as $function$ -select * from equipment_r where equipment_r.hobby = hobby -$function$; +as 'select * from equipment_r where equipment_r.hobby = hobby'; select p.name, name(p.hobbies) from only person as p; @@ -216,61 +188,41 @@ select name(equipment(p.hobbies)), name(p.hobbies), p.name from person as p; select name( - equipment( - hobby_construct( - cast('skywalking' as text), - cast('mer' as text) - ) - ) + equipment(hobby_construct(cast('skywalking' as text), cast('mer' as text))) ); select name( equipment( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) + hobby_construct_named(cast('skywalking' as text), cast('mer' as text)) ) ); select name( equipment_named( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) + hobby_construct_named(cast('skywalking' as text), cast('mer' as text)) ) ); select name( equipment_named_ambiguous_1a( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) + hobby_construct_named(cast('skywalking' as text), cast('mer' as text)) ) ); select name( equipment_named_ambiguous_1b( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) + hobby_construct_named(cast('skywalking' as text), cast('mer' as text)) ) ); select name( equipment_named_ambiguous_1c( - hobby_construct_named( - cast('skywalking' as text), - cast('mer' as text) - ) + hobby_construct_named(cast('skywalking' as text), cast('mer' as text)) ) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_100.snap index b7363595f..3ba9648ae 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_100.snap @@ -5,14 +5,14 @@ input_file: crates/pgls_pretty_print/tests/data/multi/misc_functions.sql create function explain_mask_costs( query text, - do_analyze boolean, - hide_costs boolean, - hide_row_est boolean, - hide_width boolean + do_analyze bool, + hide_costs bool, + hide_row_est bool, + hide_width bool ) returns setof text language plpgsql -as $function$ +as $$ DECLARE ln text; analyze_str text; @@ -46,7 +46,7 @@ BEGIN RETURN NEXT ln; END LOOP; END; -$function$; +$$; select num_nonnulls(null); @@ -57,15 +57,7 @@ select num_nonnulls(cast(null as text)); select num_nonnulls(cast(null as text), cast(null as int)); select - num_nonnulls( - 1, - 2, - cast(null as text), - cast(null as point), - '', - cast('9' as bigint), - 1.0 / null - ); + num_nonnulls(1, 2, cast(null as text), cast(null as point), '', cast('9' as int8), 1.0 / null); select num_nonnulls(variadic cast('{1,2,NULL,3}' as int[])); @@ -73,12 +65,7 @@ select num_nonnulls(variadic cast('{"1","2","3","4"}' as text[])); select num_nonnulls( - variadic array( - select - case when i <> 40 then i end - from - generate_series(1, 100) as i - ) + variadic array(select case when i <> 40 then i end from generate_series(1, 100) as i) ); select num_nulls(null); @@ -89,30 +76,14 @@ select num_nulls(cast(null as text)); select num_nulls(cast(null as text), cast(null as int)); -select - num_nulls( - 1, - 2, - cast(null as text), - cast(null as point), - '', - cast('9' as bigint), - 1.0 / null - ); +select num_nulls(1, 2, cast(null as text), cast(null as point), '', cast('9' as int8), 1.0 / null); select num_nulls(variadic cast('{1,2,NULL,3}' as int[])); select num_nulls(variadic cast('{"1","2","3","4"}' as text[])); select - num_nulls( - variadic array( - select - case when i <> 40 then i end - from - generate_series(1, 100) as i - ) - ); + num_nulls(variadic array(select case when i <> 40 then i end from generate_series(1, 100) as i)); select num_nonnulls(variadic cast(null as text[])); @@ -131,9 +102,7 @@ returns text language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; select test_canonicalize_path('/'); @@ -197,7 +166,7 @@ select 'EXECUTE' ); -grant EXECUTE on function pg_log_backend_memory_contexts(int) to regress_log_memory; +grant execute on function pg_log_backend_memory_contexts(int) to regress_log_memory; select has_function_privilege( @@ -212,19 +181,19 @@ select pg_log_backend_memory_contexts(pg_backend_pid()); reset role; -revoke EXECUTE on function pg_log_backend_memory_contexts(int) from regress_log_memory; +revoke execute on function pg_log_backend_memory_contexts(int) from regress_log_memory; drop role regress_log_memory; select setting as segsize from pg_settings where name = 'wal_segment_size'; -select COUNT(*) > 0 as ok from pg_ls_waldir(); +select count(*) > 0 as ok from pg_ls_waldir(); -select COUNT(*) > 0 as ok from (select pg_ls_waldir()) as ss; +select count(*) > 0 as ok from (select pg_ls_waldir()) as ss; select * from pg_ls_waldir() limit 0; -select COUNT(*) > 0 as ok from (select * from pg_ls_waldir() limit 1) as ss; +select count(*) > 0 as ok from (select * from pg_ls_waldir() limit 1) as ss; select (w).size = 'segsize' as ok @@ -234,9 +203,9 @@ where length((w).name) = 24 limit 1; -select COUNT(*) >= 0 as ok from pg_ls_archive_statusdir(); +select count(*) >= 0 as ok from pg_ls_archive_statusdir(); -select COUNT(*) >= 0 as ok from pg_ls_summariesdir(); +select count(*) >= 0 as ok from pg_ls_summariesdir(); select length(pg_read_file('postmaster.pid')) > 20; @@ -270,22 +239,17 @@ select pg_ls_dir('does not exist', false, false); select pg_ls_dir('does not exist', true, false); -select COUNT(*) = 1 as dot_found from pg_ls_dir('.', false, true) as ls where ls = '.'; +select count(*) = 1 as dot_found from pg_ls_dir('.', false, true) as ls where ls = '.'; -select COUNT(*) = 1 as dot_found from pg_ls_dir('.', false, false) as ls where ls = '.'; +select count(*) = 1 as dot_found from pg_ls_dir('.', false, false) as ls where ls = '.'; select * from (select (pg_timezone_names()).name) as ptn where name = 'UTC' limit 1; select - COUNT(*) > 0 + count(*) > 0 from ( - select - pg_tablespace_databases(oid) as pts - from - pg_tablespace - where - spcname = 'pg_default' + select pg_tablespace_databases(oid) as pts from pg_tablespace where spcname = 'pg_default' ) as pts inner join @@ -300,7 +264,7 @@ select has_function_privilege('regress_slot_dir_funcs', 'pg_ls_logicalmapdir()', select has_function_privilege('regress_slot_dir_funcs', 'pg_ls_replslotdir(text)', 'EXECUTE'); -grant PG_MONITOR to regress_slot_dir_funcs; +grant pg_monitor to regress_slot_dir_funcs; select has_function_privilege('regress_slot_dir_funcs', 'pg_ls_logicalsnapdir()', 'EXECUTE'); @@ -311,22 +275,17 @@ select has_function_privilege('regress_slot_dir_funcs', 'pg_ls_replslotdir(text) drop role regress_slot_dir_funcs; create function my_int_eq(int, int) -returns boolean +returns bool language internal immutable strict -parallel SAFE -as $function$ -int4eq -$function$; +parallel safe +as $$int4eq$$; select * from - tenk1 as a - inner join - tenk1 as b - on a.unique1 = b.unique1 + tenk1 as a inner join tenk1 as b on a.unique1 = b.unique1 where my_int_eq(a.unique2, 42); @@ -341,10 +300,7 @@ alter function my_int_eq(int, int) support test_support_func; select * from - tenk1 as a - inner join - tenk1 as b - on a.unique1 = b.unique1 + tenk1 as a inner join tenk1 as b on a.unique1 = b.unique1 where my_int_eq(a.unique2, 42); @@ -353,173 +309,73 @@ returns setof int language internal immutable strict -parallel SAFE +parallel safe support test_support_func -as $function$ -generate_series_int4 -$function$; +as $$generate_series_int4$$; select * from tenk1 as a inner join my_gen_series(1, 1000) as g on a.unique1 = g; select * from tenk1 as a inner join my_gen_series(1, 10) as g on a.unique1 = g; -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''1 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''1 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMP ''2024-02-01'', TIMESTAMP ''2024-03-01'', INTERVAL ''1 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMP ''2024-02-01'', TIMESTAMP ''2024-03-01'', INTERVAL ''1 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''1 day'', ''UTC'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''1 day'', ''UTC'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''7 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''7 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-03-01'', TIMESTAMPTZ ''2024-02-01'', INTERVAL ''-1 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-03-01'', TIMESTAMPTZ ''2024-02-01'', INTERVAL ''-1 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-03-01'', TIMESTAMPTZ ''2024-02-01'', INTERVAL ''1 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-03-01'', TIMESTAMPTZ ''2024-02-01'', INTERVAL ''1 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''-infinity'', TIMESTAMPTZ ''infinity'', INTERVAL ''1 day'') g(s);', - false, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''-infinity'', TIMESTAMPTZ ''infinity'', INTERVAL ''1 day'') g(s);', false, true, false, true); select * from generate_series( - cast('2024-02-01' as timestamp with time zone), - cast('2024-03-01' as timestamp with time zone), + cast('2024-02-01' as timestamptz), + cast('2024-03-01' as timestamptz), cast('0 day' as interval) ) as g (s); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(1.0, 25.0) g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(1.0, 25.0) g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(1.0, 25.0, 2.0) g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(1.0, 25.0, 2.0) g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(25.0, 1.0, -1.0) g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(25.0, 1.0, -1.0) g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(25.0, 1.0, 1.0) g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(25.0, 1.0, 1.0) g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(''-infinity''::NUMERIC, ''infinity''::NUMERIC, 1.0) g(s);', - false, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(''-infinity''::NUMERIC, ''infinity''::NUMERIC, 1.0) g(s);', false, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(1.0, 25.0, ''NaN''::NUMERIC) g(s);', - false, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(1.0, 25.0, ''NaN''::NUMERIC) g(s);', false, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(25.0, 2.0, 0.0) g(s);', - false, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(25.0, 2.0, 0.0) g(s);', false, true, false, true); -select COUNT(*) > 0 as ok from pg_control_checkpoint(); +select count(*) > 0 as ok from pg_control_checkpoint(); -select COUNT(*) > 0 as ok from pg_control_init(); +select count(*) > 0 as ok from pg_control_init(); -select COUNT(*) > 0 as ok from pg_control_recovery(); +select count(*) > 0 as ok from pg_control_recovery(); -select COUNT(*) > 0 as ok from pg_control_system(); +select count(*) > 0 as ok from pg_control_system(); select * from pg_split_walfile_name(null); @@ -537,40 +393,34 @@ select from pg_split_walfile_name('ffffffFF00000001000000af'); -select cast(setting as bigint) as segment_size from pg_settings where name = 'wal_segment_size'; +select cast(setting as int8) as segment_size from pg_settings where name = 'wal_segment_size'; select segment_number, file_offset from - pg_walfile_name_offset( - cast('0/0' as pg_lsn) + 'segment_size' - ), + pg_walfile_name_offset(cast('0/0' as pg_lsn) + 'segment_size'), pg_split_walfile_name(file_name); select segment_number, file_offset from - pg_walfile_name_offset( - cast('0/0' as pg_lsn) + 'segment_size' + 1 - ), + pg_walfile_name_offset(cast('0/0' as pg_lsn) + 'segment_size' + 1), pg_split_walfile_name(file_name); select segment_number, file_offset = 'segment_size' - 1 from - pg_walfile_name_offset( - cast('0/0' as pg_lsn) + 'segment_size' - 1 - ), + pg_walfile_name_offset(cast('0/0' as pg_lsn) + 'segment_size' - 1), pg_split_walfile_name(file_name); create role regress_current_logfile; select has_function_privilege('regress_current_logfile', 'pg_current_logfile()', 'EXECUTE'); -grant PG_MONITOR to regress_current_logfile; +grant pg_monitor to regress_current_logfile; select has_function_privilege('regress_current_logfile', 'pg_current_logfile()', 'EXECUTE'); @@ -586,16 +436,13 @@ insert into test_chunk_id values ('x', repeat('x', 8192)); select t.relname as toastrel from - pg_class as c - left outer join - pg_class as t - on c.reltoastrelid = t.oid + pg_class as c left outer join pg_class as t on c.reltoastrelid = t.oid where c.relname = 'test_chunk_id'; drop table test_chunk_id; -drop function explain_mask_costs(text, boolean, boolean, boolean, boolean); +drop function explain_mask_costs(text, bool, bool, bool, bool); select gist_translate_cmptype_common(7); @@ -604,9 +451,7 @@ select gist_translate_cmptype_common(3); create function test_relpath() returns void language c -as $function$ -regresslib -$function$; +as 'regresslib'; select test_relpath(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_80.snap index 69803818e..823d003f5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_80.snap @@ -5,14 +5,14 @@ input_file: crates/pgls_pretty_print/tests/data/multi/misc_functions.sql create function explain_mask_costs( query text, - do_analyze boolean, - hide_costs boolean, - hide_row_est boolean, - hide_width boolean + do_analyze bool, + hide_costs bool, + hide_row_est bool, + hide_width bool ) returns setof text language plpgsql -as $function$ +as $$ DECLARE ln text; analyze_str text; @@ -46,7 +46,7 @@ BEGIN RETURN NEXT ln; END LOOP; END; -$function$; +$$; select num_nonnulls(null); @@ -63,7 +63,7 @@ select cast(null as text), cast(null as point), '', - cast('9' as bigint), + cast('9' as int8), 1.0 / null ); @@ -74,10 +74,7 @@ select num_nonnulls(variadic cast('{"1","2","3","4"}' as text[])); select num_nonnulls( variadic array( - select - case when i <> 40 then i end - from - generate_series(1, 100) as i + select case when i <> 40 then i end from generate_series(1, 100) as i ) ); @@ -96,7 +93,7 @@ select cast(null as text), cast(null as point), '', - cast('9' as bigint), + cast('9' as int8), 1.0 / null ); @@ -107,10 +104,7 @@ select num_nulls(variadic cast('{"1","2","3","4"}' as text[])); select num_nulls( variadic array( - select - case when i <> 40 then i end - from - generate_series(1, 100) as i + select case when i <> 40 then i end from generate_series(1, 100) as i ) ); @@ -131,9 +125,7 @@ returns text language c immutable strict -as $function$ -regresslib -$function$; +as 'regresslib'; select test_canonicalize_path('/'); @@ -197,7 +189,7 @@ select 'EXECUTE' ); -grant EXECUTE +grant execute on function pg_log_backend_memory_contexts(int) to regress_log_memory; @@ -214,7 +206,7 @@ select pg_log_backend_memory_contexts(pg_backend_pid()); reset role; -revoke EXECUTE +revoke execute on function pg_log_backend_memory_contexts(int) from regress_log_memory; @@ -222,13 +214,13 @@ drop role regress_log_memory; select setting as segsize from pg_settings where name = 'wal_segment_size'; -select COUNT(*) > 0 as ok from pg_ls_waldir(); +select count(*) > 0 as ok from pg_ls_waldir(); -select COUNT(*) > 0 as ok from (select pg_ls_waldir()) as ss; +select count(*) > 0 as ok from (select pg_ls_waldir()) as ss; select * from pg_ls_waldir() limit 0; -select COUNT(*) > 0 as ok from (select * from pg_ls_waldir() limit 1) as ss; +select count(*) > 0 as ok from (select * from pg_ls_waldir() limit 1) as ss; select (w).size = 'segsize' as ok @@ -238,9 +230,9 @@ where length((w).name) = 24 limit 1; -select COUNT(*) >= 0 as ok from pg_ls_archive_statusdir(); +select count(*) >= 0 as ok from pg_ls_archive_statusdir(); -select COUNT(*) >= 0 as ok from pg_ls_summariesdir(); +select count(*) >= 0 as ok from pg_ls_summariesdir(); select length(pg_read_file('postmaster.pid')) > 20; @@ -275,14 +267,14 @@ select pg_ls_dir('does not exist', false, false); select pg_ls_dir('does not exist', true, false); select - COUNT(*) = 1 as dot_found + count(*) = 1 as dot_found from pg_ls_dir('.', false, true) as ls where ls = '.'; select - COUNT(*) = 1 as dot_found + count(*) = 1 as dot_found from pg_ls_dir('.', false, false) as ls where @@ -291,16 +283,13 @@ where select * from - ( - select (pg_timezone_names()).name - ) - as ptn + (select (pg_timezone_names()).name) as ptn where name = 'UTC' limit 1; select - COUNT(*) > 0 + count(*) > 0 from ( select @@ -338,7 +327,7 @@ select 'EXECUTE' ); -grant PG_MONITOR to regress_slot_dir_funcs; +grant pg_monitor to regress_slot_dir_funcs; select has_function_privilege( @@ -364,22 +353,17 @@ select drop role regress_slot_dir_funcs; create function my_int_eq(int, int) -returns boolean +returns bool language internal immutable strict -parallel SAFE -as $function$ -int4eq -$function$; +parallel safe +as $$int4eq$$; select * from - tenk1 as a - inner join - tenk1 as b - on a.unique1 = b.unique1 + tenk1 as a inner join tenk1 as b on a.unique1 = b.unique1 where my_int_eq(a.unique2, 42); @@ -394,10 +378,7 @@ alter function my_int_eq(int, int) support test_support_func; select * from - tenk1 as a - inner join - tenk1 as b - on a.unique1 = b.unique1 + tenk1 as a inner join tenk1 as b on a.unique1 = b.unique1 where my_int_eq(a.unique2, 42); @@ -406,181 +387,76 @@ returns setof int language internal immutable strict -parallel SAFE +parallel safe support test_support_func -as $function$ -generate_series_int4 -$function$; +as $$generate_series_int4$$; select * from - tenk1 as a - inner join - my_gen_series(1, 1000) as g - on a.unique1 = g; + tenk1 as a inner join my_gen_series(1, 1000) as g on a.unique1 = g; select * from tenk1 as a inner join my_gen_series(1, 10) as g on a.unique1 = g; -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''1 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''1 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMP ''2024-02-01'', TIMESTAMP ''2024-03-01'', INTERVAL ''1 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMP ''2024-02-01'', TIMESTAMP ''2024-03-01'', INTERVAL ''1 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''1 day'', ''UTC'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''1 day'', ''UTC'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''7 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-02-01'', TIMESTAMPTZ ''2024-03-01'', INTERVAL ''7 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-03-01'', TIMESTAMPTZ ''2024-02-01'', INTERVAL ''-1 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-03-01'', TIMESTAMPTZ ''2024-02-01'', INTERVAL ''-1 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''2024-03-01'', TIMESTAMPTZ ''2024-02-01'', INTERVAL ''1 day'') g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''2024-03-01'', TIMESTAMPTZ ''2024-02-01'', INTERVAL ''1 day'') g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(TIMESTAMPTZ ''-infinity'', TIMESTAMPTZ ''infinity'', INTERVAL ''1 day'') g(s);', - false, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(TIMESTAMPTZ ''-infinity'', TIMESTAMPTZ ''infinity'', INTERVAL ''1 day'') g(s);', false, true, false, true); select * from generate_series( - cast('2024-02-01' - as timestamp with time zone), - cast('2024-03-01' - as timestamp with time zone), + cast('2024-02-01' as timestamptz), + cast('2024-03-01' as timestamptz), cast('0 day' as interval) ) as g (s); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(1.0, 25.0) g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(1.0, 25.0) g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(1.0, 25.0, 2.0) g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(1.0, 25.0, 2.0) g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(25.0, 1.0, -1.0) g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(25.0, 1.0, -1.0) g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(25.0, 1.0, 1.0) g(s);', - true, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(25.0, 1.0, 1.0) g(s);', true, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(''-infinity''::NUMERIC, ''infinity''::NUMERIC, 1.0) g(s);', - false, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(''-infinity''::NUMERIC, ''infinity''::NUMERIC, 1.0) g(s);', false, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(1.0, 25.0, ''NaN''::NUMERIC) g(s);', - false, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(1.0, 25.0, ''NaN''::NUMERIC) g(s);', false, true, false, true); -select - explain_mask_costs( - ' -SELECT * FROM generate_series(25.0, 2.0, 0.0) g(s);', - false, - true, - false, - true - ); +select explain_mask_costs(' +SELECT * FROM generate_series(25.0, 2.0, 0.0) g(s);', false, true, false, true); -select COUNT(*) > 0 as ok from pg_control_checkpoint(); +select count(*) > 0 as ok from pg_control_checkpoint(); -select COUNT(*) > 0 as ok from pg_control_init(); +select count(*) > 0 as ok from pg_control_init(); -select COUNT(*) > 0 as ok from pg_control_recovery(); +select count(*) > 0 as ok from pg_control_recovery(); -select COUNT(*) > 0 as ok from pg_control_system(); +select count(*) > 0 as ok from pg_control_system(); select * from pg_split_walfile_name(null); @@ -590,20 +466,16 @@ select segment_number > 0 as ok_segment_number, timeline_id from - pg_split_walfile_name( - '000000010000000100000000' - ); + pg_split_walfile_name('000000010000000100000000'); select segment_number > 0 as ok_segment_number, timeline_id from - pg_split_walfile_name( - 'ffffffFF00000001000000af' - ); + pg_split_walfile_name('ffffffFF00000001000000af'); select - cast(setting as bigint) as segment_size + cast(setting as int8) as segment_size from pg_settings where @@ -613,29 +485,21 @@ select segment_number, file_offset from - pg_walfile_name_offset( - cast('0/0' as pg_lsn) + 'segment_size' - ), + pg_walfile_name_offset(cast('0/0' as pg_lsn) + 'segment_size'), pg_split_walfile_name(file_name); select segment_number, file_offset from - pg_walfile_name_offset( - cast('0/0' as pg_lsn) + 'segment_size' + - 1 - ), + pg_walfile_name_offset(cast('0/0' as pg_lsn) + 'segment_size' + 1), pg_split_walfile_name(file_name); select segment_number, file_offset = 'segment_size' - 1 from - pg_walfile_name_offset( - cast('0/0' as pg_lsn) + 'segment_size' - - 1 - ), + pg_walfile_name_offset(cast('0/0' as pg_lsn) + 'segment_size' - 1), pg_split_walfile_name(file_name); create role regress_current_logfile; @@ -647,7 +511,7 @@ select 'EXECUTE' ); -grant PG_MONITOR to regress_current_logfile; +grant pg_monitor to regress_current_logfile; select has_function_privilege( @@ -668,16 +532,13 @@ insert into test_chunk_id values ('x', repeat('x', 8192)); select t.relname as toastrel from - pg_class as c - left outer join - pg_class as t - on c.reltoastrelid = t.oid + pg_class as c left outer join pg_class as t on c.reltoastrelid = t.oid where c.relname = 'test_chunk_id'; drop table test_chunk_id; -drop function explain_mask_costs(text, boolean, boolean, boolean, boolean); +drop function explain_mask_costs(text, bool, bool, bool, bool); select gist_translate_cmptype_common(7); @@ -686,9 +547,7 @@ select gist_translate_cmptype_common(3); create function test_relpath() returns void language c -as $function$ -regresslib -$function$; +as 'regresslib'; select test_relpath(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_sanity_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_sanity_100.snap index 5d9d30ee2..9af663fd2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_sanity_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_sanity_100.snap @@ -30,15 +30,9 @@ select attname, cast(atttypid as regtype) from - pg_class as c - inner join - pg_attribute as a - on c.oid = attrelid + pg_class as c inner join pg_attribute as a on c.oid = attrelid where - c.oid < 16384 and - reltoastrelid = 0 and - relkind = 'r' and - attstorage <> 'p' + c.oid < 16384 and reltoastrelid = 0 and relkind = 'r' and attstorage <> 'p' order by 1, 2; @@ -49,19 +43,13 @@ from where relnamespace = cast('pg_catalog' as regnamespace) and relkind = 'r' and - not pg_class.oid in - ( - select indrelid from pg_index where indisprimary - ) + not pg_class.oid in (select indrelid from pg_index where indisprimary) order by 1; select relname from - pg_class as c - inner join - pg_index as i - on c.oid = i.indexrelid + pg_class as c inner join pg_index as i on c.oid = i.indexrelid where relnamespace = cast('pg_catalog' as regnamespace) and relkind = 'i' and diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_sanity_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_sanity_80.snap index 6af302d2b..9af663fd2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_sanity_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_sanity_80.snap @@ -12,10 +12,7 @@ where refobjid = 0 or classid = 0 or objid = 0 or - deptype - not in ( - 'a', 'e', 'i', 'n', 'x', 'P', 'S' - ); + deptype not in ('a', 'e', 'i', 'n', 'x', 'P', 'S'); select * @@ -33,15 +30,9 @@ select attname, cast(atttypid as regtype) from - pg_class as c - inner join - pg_attribute as a - on c.oid = attrelid + pg_class as c inner join pg_attribute as a on c.oid = attrelid where - c.oid < 16384 and - reltoastrelid = 0 and - relkind = 'r' and - attstorage <> 'p' + c.oid < 16384 and reltoastrelid = 0 and relkind = 'r' and attstorage <> 'p' order by 1, 2; @@ -50,34 +41,18 @@ select from pg_class where - relnamespace = - cast('pg_catalog' as regnamespace) and + relnamespace = cast('pg_catalog' as regnamespace) and relkind = 'r' and - not pg_class.oid in - ( - select - indrelid - from - pg_index - where - indisprimary - ) + not pg_class.oid in (select indrelid from pg_index where indisprimary) order by 1; select relname from - pg_class as c - inner join - pg_index as i - on c.oid = i.indexrelid + pg_class as c inner join pg_index as i on c.oid = i.indexrelid where - relnamespace = - cast('pg_catalog' as regnamespace) and + relnamespace = cast('pg_catalog' as regnamespace) and relkind = 'i' and i.indisunique and - not c.oid in - ( - select conindid from pg_constraint - ) + not c.oid in (select conindid from pg_constraint) order by 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__money_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__money_100.snap index 79e0d102f..0cb721bfa 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__money_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__money_100.snap @@ -23,29 +23,29 @@ select 2 * m from money_data; select m / 2 from money_data; -select m * cast(2 as smallint) from money_data; +select m * cast(2 as int2) from money_data; -select cast(2 as smallint) * m from money_data; +select cast(2 as int2) * m from money_data; -select m / cast(2 as smallint) from money_data; +select m / cast(2 as int2) from money_data; -select m * cast(2 as bigint) from money_data; +select m * cast(2 as int8) from money_data; -select cast(2 as bigint) * m from money_data; +select cast(2 as int8) * m from money_data; -select m / cast(2 as bigint) from money_data; +select m / cast(2 as int8) from money_data; -select m * cast(2 as double precision) from money_data; +select m * cast(2 as float8) from money_data; -select cast(2 as double precision) * m from money_data; +select cast(2 as float8) * m from money_data; -select m / cast(2 as double precision) from money_data; +select m / cast(2 as float8) from money_data; -select m * cast(2 as real) from money_data; +select m * cast(2 as float4) from money_data; -select cast(2 as real) * m from money_data; +select cast(2 as float4) * m from money_data; -select m / cast(2 as real) from money_data; +select m / cast(2 as float4) from money_data; select m = '$123.00' from money_data; @@ -157,9 +157,9 @@ select cast('-92233720368547758.085' as money); select cast('92233720368547758.075' as money); -select cast('878.08' as money) / cast(11 as double precision); +select cast('878.08' as money) / cast(11 as float8); -select cast('878.08' as money) / cast(11 as real); +select cast('878.08' as money) / cast(11 as float4); select cast('878.08' as money) / cast(11 as bigint); @@ -183,15 +183,15 @@ select cast(-1234567890 as money); select cast(-12345678901234567 as money); -select cast(cast(1234567890 as int) as money); +select cast(cast(1234567890 as int4) as money); -select cast(cast(12345678901234567 as bigint) as money); +select cast(cast(12345678901234567 as int8) as money); select cast(cast(12345678901234567 as numeric) as money); -select cast(cast(-1234567890 as int) as money); +select cast(cast(-1234567890 as int4) as money); -select cast(cast(-12345678901234567 as bigint) as money); +select cast(cast(-12345678901234567 as int8) as money); select cast(cast(-12345678901234567 as numeric) as money); @@ -207,16 +207,16 @@ select cast('92233720368547758.07' as money) + cast('0.01' as money); select cast('-92233720368547758.08' as money) - cast('0.01' as money); -select cast('92233720368547758.07' as money) * cast(2 as double precision); +select cast('92233720368547758.07' as money) * cast(2 as float8); -select cast('-1' as money) / cast(1.175494e-38 as real); +select cast('-1' as money) / cast(1.175494e-38 as float4); -select cast('92233720368547758.07' as money) * cast(2 as int); +select cast('92233720368547758.07' as money) * cast(2 as int4); -select cast('1' as money) / cast(0 as smallint); +select cast('1' as money) / cast(0 as int2); -select cast('42' as money) * cast('inf' as double precision); +select cast('42' as money) * cast('inf' as float8); -select cast('42' as money) * cast('-inf' as double precision); +select cast('42' as money) * cast('-inf' as float8); -select cast('42' as money) * cast('nan' as real); +select cast('42' as money) * cast('nan' as float4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__money_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__money_80.snap index 79e0d102f..0cb721bfa 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__money_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__money_80.snap @@ -23,29 +23,29 @@ select 2 * m from money_data; select m / 2 from money_data; -select m * cast(2 as smallint) from money_data; +select m * cast(2 as int2) from money_data; -select cast(2 as smallint) * m from money_data; +select cast(2 as int2) * m from money_data; -select m / cast(2 as smallint) from money_data; +select m / cast(2 as int2) from money_data; -select m * cast(2 as bigint) from money_data; +select m * cast(2 as int8) from money_data; -select cast(2 as bigint) * m from money_data; +select cast(2 as int8) * m from money_data; -select m / cast(2 as bigint) from money_data; +select m / cast(2 as int8) from money_data; -select m * cast(2 as double precision) from money_data; +select m * cast(2 as float8) from money_data; -select cast(2 as double precision) * m from money_data; +select cast(2 as float8) * m from money_data; -select m / cast(2 as double precision) from money_data; +select m / cast(2 as float8) from money_data; -select m * cast(2 as real) from money_data; +select m * cast(2 as float4) from money_data; -select cast(2 as real) * m from money_data; +select cast(2 as float4) * m from money_data; -select m / cast(2 as real) from money_data; +select m / cast(2 as float4) from money_data; select m = '$123.00' from money_data; @@ -157,9 +157,9 @@ select cast('-92233720368547758.085' as money); select cast('92233720368547758.075' as money); -select cast('878.08' as money) / cast(11 as double precision); +select cast('878.08' as money) / cast(11 as float8); -select cast('878.08' as money) / cast(11 as real); +select cast('878.08' as money) / cast(11 as float4); select cast('878.08' as money) / cast(11 as bigint); @@ -183,15 +183,15 @@ select cast(-1234567890 as money); select cast(-12345678901234567 as money); -select cast(cast(1234567890 as int) as money); +select cast(cast(1234567890 as int4) as money); -select cast(cast(12345678901234567 as bigint) as money); +select cast(cast(12345678901234567 as int8) as money); select cast(cast(12345678901234567 as numeric) as money); -select cast(cast(-1234567890 as int) as money); +select cast(cast(-1234567890 as int4) as money); -select cast(cast(-12345678901234567 as bigint) as money); +select cast(cast(-12345678901234567 as int8) as money); select cast(cast(-12345678901234567 as numeric) as money); @@ -207,16 +207,16 @@ select cast('92233720368547758.07' as money) + cast('0.01' as money); select cast('-92233720368547758.08' as money) - cast('0.01' as money); -select cast('92233720368547758.07' as money) * cast(2 as double precision); +select cast('92233720368547758.07' as money) * cast(2 as float8); -select cast('-1' as money) / cast(1.175494e-38 as real); +select cast('-1' as money) / cast(1.175494e-38 as float4); -select cast('92233720368547758.07' as money) * cast(2 as int); +select cast('92233720368547758.07' as money) * cast(2 as int4); -select cast('1' as money) / cast(0 as smallint); +select cast('1' as money) / cast(0 as int2); -select cast('42' as money) * cast('inf' as double precision); +select cast('42' as money) * cast('inf' as float8); -select cast('42' as money) * cast('-inf' as double precision); +select cast('42' as money) * cast('-inf' as float8); -select cast('42' as money) * cast('nan' as real); +select cast('42' as money) * cast('nan' as float4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_100.snap index 34e296309..9c5dc4cb5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_100.snap @@ -138,7 +138,7 @@ select unnest(textmultirange(textrange('\\\\', repeat('a', 200)), textrange('c', create table nummultirange_test (nmr nummultirange); -create index "nummultirange_test_btree" on nummultirange_test using btree (nmr); +create index nummultirange_test_btree on nummultirange_test using btree (nmr); insert into nummultirange_test values ('{}'); @@ -231,13 +231,7 @@ select from nummultirange_test where - multirange_overlaps_multirange( - nmr, - nummultirange( - numrange(4.0, 4.2), - numrange(6.0, 7.0) - ) - ); + multirange_overlaps_multirange(nmr, nummultirange(numrange(4.0, 4.2), numrange(6.0, 7.0))); select * from nummultirange_test where nmr && nummultirange(numrange(4.0, 4.2), numrange(6.0, 7.0)); @@ -258,10 +252,7 @@ select from nummultirange_test where - multirange_contains_multirange( - nmr, - '{[4.0,4.2), [6.0, 8.0)}' - ); + multirange_contains_multirange(nmr, '{[4.0,4.2), [6.0, 8.0)}'); select * from nummultirange_test where nmr @> cast('{[4.0,4.2), [6.0, 8.0)}' as nummultirange); @@ -278,10 +269,7 @@ select from nummultirange_test where - multirange_contained_by_multirange( - '{[4.0,4.2), [6.0, 8.0)}', - nmr - ); + multirange_contained_by_multirange('{[4.0,4.2), [6.0, 8.0)}', nmr); select * from nummultirange_test where cast('{[4.0,4.2), [6.0, 8.0)}' as nummultirange) <@ nmr; @@ -638,8 +626,7 @@ select nummultirange(numrange(1, 2)) << nummultirange(numrange(3, 4)); select nummultirange(numrange(1, 2)) << nummultirange(numrange(3, 4), numrange(7, 8)); select - nummultirange(numrange(1, 2), numrange(4, 5)) << - nummultirange(numrange(3, 4), numrange(7, 8)); + nummultirange(numrange(1, 2), numrange(4, 5)) << nummultirange(numrange(3, 4), numrange(7, 8)); select nummultirange() >> cast('empty' as numrange); @@ -676,8 +663,7 @@ select nummultirange(numrange(3, 4)) >> nummultirange(numrange(1, 2)); select nummultirange(numrange(3, 4), numrange(7, 8)) >> nummultirange(numrange(1, 2)); select - nummultirange(numrange(3, 4), numrange(7, 8)) >> - nummultirange(numrange(1, 2), numrange(4, 5)); + nummultirange(numrange(3, 4), numrange(7, 8)) >> nummultirange(numrange(1, 2), numrange(4, 5)); select nummultirange() + nummultirange(); @@ -742,8 +728,7 @@ select nummultirange(numrange(1, 3), numrange(4, 5)) - nummultirange(numrange(2, select nummultirange(numrange(1, 2), numrange(4, 5)) - nummultirange(numrange(8, 9)); select - nummultirange(numrange(1, 2), numrange(4, 5)) - - nummultirange(numrange(-2, 0), numrange(8, 9)); + nummultirange(numrange(1, 2), numrange(4, 5)) - nummultirange(numrange(-2, 0), numrange(8, 9)); select nummultirange() * nummultirange(); @@ -777,45 +762,29 @@ create table test_multirange_gist (mr int4multirange); insert into test_multirange_gist select - int4multirange( - int4range(g, g + 10), - int4range(g + 20, g + 30), - int4range(g + 40, g + 50) - ) + int4multirange(int4range(g, g + 10), int4range(g + 20, g + 30), int4range(g + 40, g + 50)) from generate_series(1, 2000) as g; insert into test_multirange_gist -select - cast('{}' as int4multirange) -from - generate_series(1, 500) as g; +select cast('{}' as int4multirange) from generate_series(1, 500) as g; insert into test_multirange_gist -select - int4multirange(int4range(g, g + 10000)) -from - generate_series(1, 1000) as g; +select int4multirange(int4range(g, g + 10000)) from generate_series(1, 1000) as g; insert into test_multirange_gist select - int4multirange( - int4range(null, g * 10, '(]'), - int4range(g * 10, g * 20, '(]') - ) + int4multirange(int4range(null, g * 10, '(]'), int4range(g * 10, g * 20, '(]')) from generate_series(1, 100) as g; insert into test_multirange_gist select - int4multirange( - int4range(g * 10, g * 20, '(]'), - int4range(g * 20, null, '(]') - ) + int4multirange(int4range(g * 10, g * 20, '(]'), int4range(g * 20, null, '(]')) from generate_series(1, 100) as g; -create index "test_mulrirange_gist_idx" on test_multirange_gist using gist (mr); +create index test_mulrirange_gist_idx on test_multirange_gist using gist (mr); analyze test_multirange_gist; @@ -825,157 +794,124 @@ set enable_indexscan = f; set enable_bitmapscan = f; -select COUNT(*) from test_multirange_gist where mr = cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr = cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr @> cast('empty' as int4range); +select count(*) from test_multirange_gist where mr @> cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr && cast('empty' as int4range); +select count(*) from test_multirange_gist where mr && cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr <@ cast('empty' as int4range); +select count(*) from test_multirange_gist where mr <@ cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr << cast('empty' as int4range); +select count(*) from test_multirange_gist where mr << cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr >> cast('empty' as int4range); +select count(*) from test_multirange_gist where mr >> cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr &< cast('empty' as int4range); +select count(*) from test_multirange_gist where mr &< cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr &> cast('empty' as int4range); +select count(*) from test_multirange_gist where mr &> cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr -|- cast('empty' as int4range); +select count(*) from test_multirange_gist where mr -|- cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr && cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr && cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr <@ cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr <@ cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr << cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr << cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr >> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr >> cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr &< cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr &< cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr &> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr &> cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr -|- cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr -|- cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr = - int4multirange( - int4range(10, 20), - int4range(30, 40), - int4range(50, 60) - ); + mr = int4multirange(int4range(10, 20), int4range(30, 40), int4range(50, 60)); -select COUNT(*) from test_multirange_gist where mr @> 10; +select count(*) from test_multirange_gist where mr @> 10; -select COUNT(*) from test_multirange_gist where mr @> int4range(10, 20); +select count(*) from test_multirange_gist where mr @> int4range(10, 20); -select COUNT(*) from test_multirange_gist where mr && int4range(10, 20); +select count(*) from test_multirange_gist where mr && int4range(10, 20); -select COUNT(*) from test_multirange_gist where mr <@ int4range(10, 50); +select count(*) from test_multirange_gist where mr <@ int4range(10, 50); -select COUNT(*) from test_multirange_gist where mr << int4range(100, 500); +select count(*) from test_multirange_gist where mr << int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr >> int4range(100, 500); +select count(*) from test_multirange_gist where mr >> int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr &< int4range(100, 500); +select count(*) from test_multirange_gist where mr &< int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr &> int4range(100, 500); +select count(*) from test_multirange_gist where mr &> int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr -|- int4range(100, 500); +select count(*) from test_multirange_gist where mr -|- int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + mr @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_multirange_gist where - mr && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + mr && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + mr <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr -|- int4multirange(int4range(100, 200), int4range(400, 500)); set enable_seqscan = f; @@ -983,159 +919,126 @@ set enable_indexscan = t; set enable_bitmapscan = f; -select COUNT(*) from test_multirange_gist where mr = cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr = cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr @> cast('empty' as int4range); +select count(*) from test_multirange_gist where mr @> cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr && cast('empty' as int4range); +select count(*) from test_multirange_gist where mr && cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr <@ cast('empty' as int4range); +select count(*) from test_multirange_gist where mr <@ cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr << cast('empty' as int4range); +select count(*) from test_multirange_gist where mr << cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr >> cast('empty' as int4range); +select count(*) from test_multirange_gist where mr >> cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr &< cast('empty' as int4range); +select count(*) from test_multirange_gist where mr &< cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr &> cast('empty' as int4range); +select count(*) from test_multirange_gist where mr &> cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr -|- cast('empty' as int4range); +select count(*) from test_multirange_gist where mr -|- cast('empty' as int4range); -select COUNT(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr && cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr && cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr <@ cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr <@ cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr << cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr << cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr >> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr >> cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr &< cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr &< cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr &> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr &> cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr -|- cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr -|- cast('{}' as int4multirange); -select COUNT(*) from test_multirange_gist where mr @> cast('empty' as int4range); +select count(*) from test_multirange_gist where mr @> cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where - mr = - int4multirange( - int4range(10, 20), - int4range(30, 40), - int4range(50, 60) - ); + mr = int4multirange(int4range(10, 20), int4range(30, 40), int4range(50, 60)); -select COUNT(*) from test_multirange_gist where mr @> 10; +select count(*) from test_multirange_gist where mr @> 10; -select COUNT(*) from test_multirange_gist where mr @> int4range(10, 20); +select count(*) from test_multirange_gist where mr @> int4range(10, 20); -select COUNT(*) from test_multirange_gist where mr && int4range(10, 20); +select count(*) from test_multirange_gist where mr && int4range(10, 20); -select COUNT(*) from test_multirange_gist where mr <@ int4range(10, 50); +select count(*) from test_multirange_gist where mr <@ int4range(10, 50); -select COUNT(*) from test_multirange_gist where mr << int4range(100, 500); +select count(*) from test_multirange_gist where mr << int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr >> int4range(100, 500); +select count(*) from test_multirange_gist where mr >> int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr &< int4range(100, 500); +select count(*) from test_multirange_gist where mr &< int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr &> int4range(100, 500); +select count(*) from test_multirange_gist where mr &> int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr -|- int4range(100, 500); +select count(*) from test_multirange_gist where mr -|- int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); +select count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + mr @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_multirange_gist where - mr && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + mr && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + mr <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr -|- int4multirange(int4range(100, 200), int4range(400, 500)); drop table test_multirange_gist; @@ -1187,12 +1090,7 @@ select range_agg(nmr) from (values (cast('{}' as nummultirange))) as t (nmr); select range_agg(nmr) from - ( - values - (cast('{}' as nummultirange)), - (cast('{}' as nummultirange)) - ) - as t (nmr); + (values (cast('{}' as nummultirange)), (cast('{}' as nummultirange))) as t (nmr); select range_agg(nmr) from (values (cast('{[1,2]}' as nummultirange))) as t (nmr); @@ -1203,22 +1101,12 @@ select range_agg(nmr) from (values (cast('{[1,2], [2,3]}' as nummultirange))) as select range_agg(nmr) from - ( - values - (cast('{[1,2]}' as nummultirange)), - (cast('{[5,6]}' as nummultirange)) - ) - as t (nmr); + (values (cast('{[1,2]}' as nummultirange)), (cast('{[5,6]}' as nummultirange))) as t (nmr); select range_agg(nmr) from - ( - values - (cast('{[1,2]}' as nummultirange)), - (cast('{[2,3]}' as nummultirange)) - ) - as t (nmr); + (values (cast('{[1,2]}' as nummultirange)), (cast('{[2,3]}' as nummultirange))) as t (nmr); select range_intersect_agg(nmr) from nummultirange_test; @@ -1229,30 +1117,18 @@ select range_intersect_agg(cast(null as nummultirange)) from nummultirange_test; select range_intersect_agg(nmr) from - ( - values - (cast('{[1,3]}' as nummultirange)), - (cast('{[6,12]}' as nummultirange)) - ) - as t (nmr); + (values (cast('{[1,3]}' as nummultirange)), (cast('{[6,12]}' as nummultirange))) as t (nmr); select range_intersect_agg(nmr) from - ( - values - (cast('{[1,6]}' as nummultirange)), - (cast('{[3,12]}' as nummultirange)) - ) - as t (nmr); + (values (cast('{[1,6]}' as nummultirange)), (cast('{[3,12]}' as nummultirange))) as t (nmr); select range_intersect_agg(nmr) from ( - values - (cast('{[1,6], [10,12]}' as nummultirange)), - (cast('{[4,14]}' as nummultirange)) + values (cast('{[1,6], [10,12]}' as nummultirange)), (cast('{[4,14]}' as nummultirange)) ) as t (nmr); @@ -1263,16 +1139,13 @@ select range_intersect_agg(nmr) from (values (cast('{[1,2]}' as nummultirange))) select range_intersect_agg(nmr) from - ( - values (cast('{[1,6], [10,12]}' as nummultirange)) - ) - as t (nmr); + (values (cast('{[1,6], [10,12]}' as nummultirange))) as t (nmr); select range_intersect_agg(nmr) from nummultirange_test where nmr @> 4.0; create table nummultirange_test2 (nmr nummultirange); -create index "nummultirange_test2_hash_idx" on nummultirange_test2 using hash (nmr); +create index nummultirange_test2_hash_idx on nummultirange_test2 using hash (nmr); insert into nummultirange_test2 values ('{[, 5)}'); @@ -1322,7 +1195,7 @@ set enable_mergejoin = default; drop table nummultirange_test2; -select cast('{[123.001, 5.e9)}' as float8multirange) @> cast(888.882 as double precision); +select cast('{[123.001, 5.e9)}' as float8multirange) @> cast(888.882 as float8); create table float8multirange_test ( f8mr float8multirange, @@ -1330,19 +1203,13 @@ create table float8multirange_test ( ); insert into float8multirange_test -values - ( - float8multirange( - float8range(-100.00007, '1.111113e9') - ), - 42 - ); +values (float8multirange(float8range(-100.00007, '1.111113e9')), 42); select * from float8multirange_test; drop table float8multirange_test; -create domain mydomain as int; +create domain mydomain as int4; create type mydomainrange as range (subtype = mydomain); @@ -1376,18 +1243,18 @@ create type intr as range (subtype = int); drop type intr_multirange; -create type textrange1 as range (subtype = text, multirange_type_name = int, collation = "C"); +create type textrange1 as range (subtype = text, multirange_type_name = int, "collation" = "C"); create type textrange1 as range ( subtype = text, multirange_type_name = multirange_of_text, - collation = "C" + "collation" = "C" ); create type textrange2 as range ( subtype = text, multirange_type_name = _textrange1, - collation = "C" + "collation" = "C" ); select multirange_of_text(textrange2('a', 'Z')); @@ -1405,7 +1272,7 @@ drop type textrange2; create type textrange1 as range ( subtype = text, multirange_type_name = multitextrange1, - collation = "C" + "collation" = "C" ); create role regress_multirange_owner; @@ -1416,13 +1283,13 @@ alter type textrange1 owner to regress_multirange_owner; set role to regress_multirange_owner; -revoke USAGE on type multitextrange1 from public; +revoke usage on type multitextrange1 from public; -revoke USAGE on type textrange1 from public; +revoke usage on type textrange1 from public; create temporary table test1 (f1 multitextrange1[]); -revoke USAGE on type textrange1 from regress_multirange_owner; +revoke usage on type textrange1 from regress_multirange_owner; create temporary table test2 (f1 multitextrange1[]); @@ -1437,9 +1304,7 @@ drop role regress_multirange_owner; create function anyarray_anymultirange_func(a anyarray, r anymultirange) returns anyelement language sql -as $function$ -select $1[1] + lower($2); -$function$; +as 'select $1[1] + lower($2);'; select anyarray_anymultirange_func(array[1, 2], int4multirange(int4range(10, 20))); @@ -1450,23 +1315,17 @@ drop function anyarray_anymultirange_func(anyarray, anymultirange); create function bogus_func(anyelement) returns anymultirange language sql -as $function$ -select int4multirange(int4range(1,10)) -$function$; +as 'select int4multirange(int4range(1,10))'; create function bogus_func(int) returns anymultirange language sql -as $function$ -select int4multirange(int4range(1,10)) -$function$; +as 'select int4multirange(int4range(1,10))'; create function range_add_bounds(anymultirange) returns anyelement language sql -as $function$ -select lower($1) + upper($1) -$function$; +as 'select lower($1) + upper($1)'; select range_add_bounds(int4multirange(int4range(1, 17))); @@ -1474,9 +1333,7 @@ select range_add_bounds(nummultirange(numrange(1.0001, 123.123))); create function multirangetypes_sql(q anymultirange, b anyarray, out c anyelement) language sql -as $function$ -select upper($1) + $2[1] -$function$; +as $$ select upper($1) + $2[1] $$; select multirangetypes_sql(int4multirange(int4range(1, 10)), array[2, 20]); @@ -1489,24 +1346,17 @@ anycompatiblearray_anycompatiblemultirange_func( ) returns anycompatible language sql -as $function$ -select $1[1] + lower($2); -$function$; +as 'select $1[1] + lower($2);'; select anycompatiblearray_anycompatiblemultirange_func(array[1, 2], multirange(int4range(10, 20))); select anycompatiblearray_anycompatiblemultirange_func(array[1, 2], multirange(numrange(10, 20))); select - anycompatiblearray_anycompatiblemultirange_func( - array[1.1, 2], - multirange(int4range(10, 20)) - ); + anycompatiblearray_anycompatiblemultirange_func(array[1.1, 2], multirange(int4range(10, 20))); drop function - anycompatiblearray_anycompatiblemultirange_func( - anycompatiblearray, - anycompatiblemultirange); + anycompatiblearray_anycompatiblemultirange_func(anycompatiblearray, anycompatiblemultirange); create function anycompatiblerange_anycompatiblemultirange_func( @@ -1515,33 +1365,21 @@ anycompatiblerange_anycompatiblemultirange_func( ) returns anycompatible language sql -as $function$ -select lower($1) + lower($2); -$function$; +as 'select lower($1) + lower($2);'; select - anycompatiblerange_anycompatiblemultirange_func( - int4range(1, 2), - multirange(int4range(10, 20)) - ); + anycompatiblerange_anycompatiblemultirange_func(int4range(1, 2), multirange(int4range(10, 20))); select - anycompatiblerange_anycompatiblemultirange_func( - numrange(1, 2), - multirange(int4range(10, 20)) - ); + anycompatiblerange_anycompatiblemultirange_func(numrange(1, 2), multirange(int4range(10, 20))); drop function - anycompatiblerange_anycompatiblemultirange_func( - anycompatiblerange, - anycompatiblemultirange); + anycompatiblerange_anycompatiblemultirange_func(anycompatiblerange, anycompatiblemultirange); create function bogus_func(anycompatible) returns anycompatiblerange language sql -as $function$ -select int4range(1,10) -$function$; +as 'select int4range(1,10)'; select array[nummultirange(numrange(1.1, 1.2)), nummultirange(numrange(12.3, 155.5))]; @@ -1551,12 +1389,7 @@ create table i8mr_array ( ); insert into i8mr_array -values - ( - 42, - array[int8multirange(int8range(1, 10)), - int8multirange(int8range(2, 20))] - ); +values (42, array[int8multirange(int8range(1, 10)), int8multirange(int8range(2, 20))]); select * from i8mr_array; @@ -1580,16 +1413,8 @@ select from ( values - ( - two_ints_multirange( - two_ints_range(row(1, 2), row(3, 4)) - ) - ), - ( - two_ints_multirange( - two_ints_range(row(5, 6), row(7, 8)) - ) - ) + (two_ints_multirange(two_ints_range(row(1, 2), row(3, 4)))), + (two_ints_multirange(two_ints_range(row(5, 6), row(7, 8)))) ) as v (t); @@ -1603,41 +1428,31 @@ reset enable_sort; create function mr_outparam_succeed(i anymultirange, out r anymultirange, out t text) language sql -as $function$ -select $1, 'foo'::text -$function$; +as $$ select $1, 'foo'::text $$; select * from mr_outparam_succeed(int4multirange(int4range(1, 2))); create function mr_outparam_succeed2(i anymultirange, out r anyarray, out t text) language sql -as $function$ -select ARRAY[upper($1)], 'foo'::text -$function$; +as $$ select ARRAY[upper($1)], 'foo'::text $$; select * from mr_outparam_succeed2(int4multirange(int4range(1, 2))); create function mr_outparam_succeed3(i anymultirange, out r anyrange, out t text) language sql -as $function$ -select range_merge($1), 'foo'::text -$function$; +as $$ select range_merge($1), 'foo'::text $$; select * from mr_outparam_succeed3(int4multirange(int4range(1, 2))); create function mr_outparam_succeed4(i anyrange, out r anymultirange, out t text) language sql -as $function$ -select multirange($1), 'foo'::text -$function$; +as $$ select multirange($1), 'foo'::text $$; select * from mr_outparam_succeed4(int4range(1, 2)); create function mr_inoutparam_succeed(out i anyelement, inout r anymultirange) language sql -as $function$ -select upper($1), $1 -$function$; +as $$ select upper($1), $1 $$; select * from mr_inoutparam_succeed(int4multirange(int4range(1, 2))); @@ -1647,32 +1462,24 @@ returns table ( r anymultirange ) language sql -as $function$ -select $1, $2 -$function$; +as $$ select $1, $2 $$; select * from mr_table_succeed(123, int4multirange(int4range(1, 11))); create function mr_polymorphic(i anyrange) returns anymultirange language plpgsql -as $function$ -begin return multirange($1); end; -$function$; +as $$ begin return multirange($1); end; $$; select mr_polymorphic(int4range(1, 4)); create function mr_outparam_fail(i anyelement, out r anymultirange, out t text) language sql -as $function$ -select '[1,10]', 'foo' -$function$; +as $$ select '[1,10]', 'foo' $$; create function mr_inoutparam_fail(inout i anyelement, out r anymultirange) language sql -as $function$ -select $1, '[1,10]' -$function$; +as $$ select $1, '[1,10]' $$; create function mr_table_fail(i anyelement) returns table ( @@ -1680,6 +1487,4 @@ returns table ( r anymultirange ) language sql -as $function$ -select $1, '[1,10]' -$function$; +as $$ select $1, '[1,10]' $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_80.snap index 35f1657ca..f5958c363 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_80.snap @@ -136,15 +136,12 @@ select unnest(textmultirange(textrange('a', 'b'), textrange('d', 'e'))); select unnest( - textmultirange( - textrange('\\\\', repeat('a', 200)), - textrange('c', 'd') - ) + textmultirange(textrange('\\\\', repeat('a', 200)), textrange('c', 'd')) ); create table nummultirange_test (nmr nummultirange); -create index "nummultirange_test_btree" on nummultirange_test using btree (nmr); +create index nummultirange_test_btree on nummultirange_test using btree (nmr); insert into nummultirange_test values ('{}'); @@ -159,34 +156,17 @@ insert into nummultirange_test values ('{[, 5)}'); insert into nummultirange_test values (nummultirange()); insert into nummultirange_test -values - ( - nummultirange( - variadic cast('{}' as numrange[]) - ) - ); +values (nummultirange(variadic cast('{}' as numrange[]))); insert into nummultirange_test values (nummultirange(numrange(1.1, 2.2))); insert into nummultirange_test values ('{empty}'); insert into nummultirange_test -values - ( - nummultirange( - numrange(1.7, 1.7, '[]'), - numrange(1.7, 1.9) - ) - ); +values (nummultirange(numrange(1.7, 1.7, '[]'), numrange(1.7, 1.9))); insert into nummultirange_test -values - ( - nummultirange( - numrange(1.7, 1.7, '[]'), - numrange(1.9, 2.1) - ) - ); +values (nummultirange(numrange(1.7, 1.7, '[]'), numrange(1.9, 2.1))); select nmr, @@ -256,10 +236,7 @@ select from nummultirange_test where - range_overlaps_multirange( - numrange(4.0, 4.2), - nmr - ); + range_overlaps_multirange(numrange(4.0, 4.2), nmr); select * from nummultirange_test where numrange(4.0, 4.2) && nmr; @@ -268,10 +245,7 @@ select from nummultirange_test where - multirange_overlaps_range( - nmr, - numrange(4.0, 4.2) - ); + multirange_overlaps_range(nmr, numrange(4.0, 4.2)); select * from nummultirange_test where nmr && numrange(4.0, 4.2); @@ -282,10 +256,7 @@ from where multirange_overlaps_multirange( nmr, - nummultirange( - numrange(4.0, 4.2), - numrange(6.0, 7.0) - ) + nummultirange(numrange(4.0, 4.2), numrange(6.0, 7.0)) ); select @@ -293,11 +264,7 @@ select from nummultirange_test where - nmr && - nummultirange( - numrange(4.0, 4.2), - numrange(6.0, 7.0) - ); + nmr && nummultirange(numrange(4.0, 4.2), numrange(6.0, 7.0)); select * from nummultirange_test where nmr && nummultirange(numrange(6.0, 7.0)); @@ -306,11 +273,7 @@ select from nummultirange_test where - nmr && - nummultirange( - numrange(6.0, 7.0), - numrange(8.0, 9.0) - ); + nmr && nummultirange(numrange(6.0, 7.0), numrange(8.0, 9.0)); select * from nummultirange_test where multirange_contains_elem(nmr, 4.0); @@ -321,10 +284,7 @@ select from nummultirange_test where - multirange_contains_range( - nmr, - numrange(4.0, 4.2) - ); + multirange_contains_range(nmr, numrange(4.0, 4.2)); select * from nummultirange_test where nmr @> numrange(4.0, 4.2); @@ -333,19 +293,14 @@ select from nummultirange_test where - multirange_contains_multirange( - nmr, - '{[4.0,4.2), [6.0, 8.0)}' - ); + multirange_contains_multirange(nmr, '{[4.0,4.2), [6.0, 8.0)}'); select * from nummultirange_test where - nmr @> - cast('{[4.0,4.2), [6.0, 8.0)}' - as nummultirange); + nmr @> cast('{[4.0,4.2), [6.0, 8.0)}' as nummultirange); select * from nummultirange_test where elem_contained_by_multirange(4.0, nmr); @@ -356,10 +311,7 @@ select from nummultirange_test where - range_contained_by_multirange( - numrange(4.0, 4.2), - nmr - ); + range_contained_by_multirange(numrange(4.0, 4.2), nmr); select * from nummultirange_test where numrange(4.0, 4.2) <@ nmr; @@ -368,19 +320,14 @@ select from nummultirange_test where - multirange_contained_by_multirange( - '{[4.0,4.2), [6.0, 8.0)}', - nmr - ); + multirange_contained_by_multirange('{[4.0,4.2), [6.0, 8.0)}', nmr); select * from nummultirange_test where - cast('{[4.0,4.2), [6.0, 8.0)}' - as nummultirange) <@ - nmr; + cast('{[4.0,4.2), [6.0, 8.0)}' as nummultirange) <@ nmr; select cast('empty' as numrange) && nummultirange(); @@ -398,37 +345,24 @@ select nummultirange(numrange(1, 2)) && nummultirange(); select nummultirange(numrange(3, 4)) && - nummultirange( - numrange(1, 2), - numrange(7, 8) - ); + nummultirange(numrange(1, 2), numrange(7, 8)); select - nummultirange( - numrange(1, 2), - numrange(7, 8) - ) && + nummultirange(numrange(1, 2), numrange(7, 8)) && nummultirange(numrange(3, 4)); select nummultirange(numrange(3, 4)) && - nummultirange( - numrange(1, 2), - numrange(3.5, 8) - ); + nummultirange(numrange(1, 2), numrange(3.5, 8)); select nummultirange(numrange(1, 2), numrange(3.5, 8)) && numrange(3, 4); select - nummultirange( - numrange(1, 2), - numrange(3.5, 8) - ) && + nummultirange(numrange(1, 2), numrange(3.5, 8)) && nummultirange(numrange(3, 4)); select - cast('{(10,20),(30,40),(50,60)}' - as nummultirange) && + cast('{(10,20),(30,40),(50,60)}' as nummultirange) && cast('(42,92)' as numrange); select nummultirange() @> nummultirange(); @@ -476,8 +410,7 @@ select cast('{[1,5), [8,9)}' as nummultirange) @> '{[6,7)}'; select cast('{[1,5), [6,9)}' as nummultirange) @> '{[6,7)}'; select - cast('{(10,20),(30,40),(50,60)}' - as nummultirange) @> + cast('{(10,20),(30,40),(50,60)}' as nummultirange) @> cast('(52,56)' as numrange); select numrange(null, null) @> nummultirange(numrange(1, 2)); @@ -719,32 +652,20 @@ select nummultirange(numrange(1, 2)) -|- nummultirange(numrange(2, 4)); select nummultirange(numrange(1, 2)) -|- nummultirange(numrange(3, 4)); select - nummultirange( - numrange(1, 2), - numrange(5, 6) - ) -|- + nummultirange(numrange(1, 2), numrange(5, 6)) -|- nummultirange(numrange(3, 4)); select - nummultirange( - numrange(1, 2), - numrange(5, 6) - ) -|- + nummultirange(numrange(1, 2), numrange(5, 6)) -|- nummultirange(numrange(6, 7)); select - nummultirange( - numrange(1, 2), - numrange(5, 6) - ) -|- + nummultirange(numrange(1, 2), numrange(5, 6)) -|- nummultirange(numrange(8, 9)); select nummultirange(numrange(1, 2)) -|- - nummultirange( - numrange(2, 4), - numrange(6, 7) - ); + nummultirange(numrange(2, 4), numrange(6, 7)); select cast('empty' as numrange) << nummultirange(); @@ -780,20 +701,11 @@ select nummultirange(numrange(1, 2)) << nummultirange(numrange(3, 4)); select nummultirange(numrange(1, 2)) << - nummultirange( - numrange(3, 4), - numrange(7, 8) - ); + nummultirange(numrange(3, 4), numrange(7, 8)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) << - nummultirange( - numrange(3, 4), - numrange(7, 8) - ); + nummultirange(numrange(1, 2), numrange(4, 5)) << + nummultirange(numrange(3, 4), numrange(7, 8)); select nummultirange() >> cast('empty' as numrange); @@ -828,21 +740,12 @@ select nummultirange(numrange(1, 2)) >> nummultirange(numrange(1, 2)); select nummultirange(numrange(3, 4)) >> nummultirange(numrange(1, 2)); select - nummultirange( - numrange(3, 4), - numrange(7, 8) - ) >> + nummultirange(numrange(3, 4), numrange(7, 8)) >> nummultirange(numrange(1, 2)); select - nummultirange( - numrange(3, 4), - numrange(7, 8) - ) >> - nummultirange( - numrange(1, 2), - numrange(4, 5) - ); + nummultirange(numrange(3, 4), numrange(7, 8)) >> + nummultirange(numrange(1, 2), numrange(4, 5)); select nummultirange() + nummultirange(); @@ -857,25 +760,13 @@ select nummultirange(numrange(1, 2)) + nummultirange(numrange(2, 4)); select nummultirange(numrange(1, 2)) + nummultirange(numrange(3, 4)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) + - nummultirange(numrange(2, 4)); + nummultirange(numrange(1, 2), numrange(4, 5)) + nummultirange(numrange(2, 4)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) + - nummultirange(numrange(3, 4)); + nummultirange(numrange(1, 2), numrange(4, 5)) + nummultirange(numrange(3, 4)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) + - nummultirange(numrange(0, 9)); + nummultirange(numrange(1, 2), numrange(4, 5)) + nummultirange(numrange(0, 9)); select range_merge(nummultirange()); @@ -906,70 +797,34 @@ select nummultirange(numrange(1, 4)) - nummultirange(numrange(0, 8)); select nummultirange(numrange(1, 4)) - nummultirange(numrange(0, 2)); select - nummultirange(numrange(1, 8)) - - nummultirange( - numrange(0, 2), - numrange(3, 4) - ); + nummultirange(numrange(1, 8)) - nummultirange(numrange(0, 2), numrange(3, 4)); select nummultirange(numrange(1, 8)) - - nummultirange( - numrange(2, 3), - numrange(5, null) - ); + nummultirange(numrange(2, 3), numrange(5, null)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) - + nummultirange(numrange(1, 2), numrange(4, 5)) - nummultirange(numrange(-2, 0)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) - - nummultirange(numrange(2, 4)); + nummultirange(numrange(1, 2), numrange(4, 5)) - nummultirange(numrange(2, 4)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) - - nummultirange(numrange(3, 5)); + nummultirange(numrange(1, 2), numrange(4, 5)) - nummultirange(numrange(3, 5)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) - - nummultirange(numrange(0, 9)); + nummultirange(numrange(1, 2), numrange(4, 5)) - nummultirange(numrange(0, 9)); select - nummultirange( - numrange(1, 3), - numrange(4, 5) - ) - - nummultirange(numrange(2, 9)); + nummultirange(numrange(1, 3), numrange(4, 5)) - nummultirange(numrange(2, 9)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) - - nummultirange(numrange(8, 9)); + nummultirange(numrange(1, 2), numrange(4, 5)) - nummultirange(numrange(8, 9)); select - nummultirange( - numrange(1, 2), - numrange(4, 5) - ) - - nummultirange( - numrange(-2, 0), - numrange(8, 9) - ); + nummultirange(numrange(1, 2), numrange(4, 5)) - + nummultirange(numrange(-2, 0), numrange(8, 9)); select nummultirange() * nummultirange(); @@ -988,31 +843,26 @@ select cast('{[1,3)}' as nummultirange) * cast('{[2,5)}' as nummultirange); select cast('{[1,4)}' as nummultirange) * cast('{[2,3)}' as nummultirange); select - cast('{[1,4)}' as nummultirange) * - cast('{[0,2), [3,5)}' as nummultirange); + cast('{[1,4)}' as nummultirange) * cast('{[0,2), [3,5)}' as nummultirange); select cast('{[1,4), [7,10)}' as nummultirange) * cast('{[0,8), [9,12)}' as nummultirange); select - cast('{[1,4), [7,10)}' as nummultirange) * - cast('{[9,12)}' as nummultirange); + cast('{[1,4), [7,10)}' as nummultirange) * cast('{[9,12)}' as nummultirange); select cast('{[1,4), [7,10)}' as nummultirange) * - cast('{[-5,-4), [5,6), [9,12)}' - as nummultirange); + cast('{[-5,-4), [5,6), [9,12)}' as nummultirange); select cast('{[1,4), [7,10)}' as nummultirange) * - cast('{[0,2), [3,8), [9,12)}' - as nummultirange); + cast('{[0,2), [3,8), [9,12)}' as nummultirange); select cast('{[1,4), [7,10)}' as nummultirange) * - cast('{[0,2), [3,8), [9,12)}' - as nummultirange); + cast('{[0,2), [3,8), [9,12)}' as nummultirange); create table test_multirange_gist (mr int4multirange); @@ -1027,10 +877,7 @@ from generate_series(1, 2000) as g; insert into test_multirange_gist -select - cast('{}' as int4multirange) -from - generate_series(1, 500) as g; +select cast('{}' as int4multirange) from generate_series(1, 500) as g; insert into test_multirange_gist select @@ -1040,23 +887,17 @@ from insert into test_multirange_gist select - int4multirange( - int4range(null, g * 10, '(]'), - int4range(g * 10, g * 20, '(]') - ) + int4multirange(int4range(null, g * 10, '(]'), int4range(g * 10, g * 20, '(]')) from generate_series(1, 100) as g; insert into test_multirange_gist select - int4multirange( - int4range(g * 10, g * 20, '(]'), - int4range(g * 20, null, '(]') - ) + int4multirange(int4range(g * 10, g * 20, '(]'), int4range(g * 20, null, '(]')) from generate_series(1, 100) as g; -create index "test_mulrirange_gist_idx" on test_multirange_gist using gist (mr); +create index test_mulrirange_gist_idx on test_multirange_gist using gist (mr); analyze test_multirange_gist; @@ -1067,251 +908,218 @@ set enable_indexscan = f; set enable_bitmapscan = f; select - COUNT(*) + count(*) from test_multirange_gist where mr = cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr && cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr <@ cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr << cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr >> cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr &< cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr &> cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr -|- cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr && cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr <@ cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr << cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr >> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr &< cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr &> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr -|- cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr = - int4multirange( - int4range(10, 20), - int4range(30, 40), - int4range(50, 60) - ); + mr = int4multirange(int4range(10, 20), int4range(30, 40), int4range(50, 60)); -select COUNT(*) from test_multirange_gist where mr @> 10; +select count(*) from test_multirange_gist where mr @> 10; -select COUNT(*) from test_multirange_gist where mr @> int4range(10, 20); +select count(*) from test_multirange_gist where mr @> int4range(10, 20); -select COUNT(*) from test_multirange_gist where mr && int4range(10, 20); +select count(*) from test_multirange_gist where mr && int4range(10, 20); -select COUNT(*) from test_multirange_gist where mr <@ int4range(10, 50); +select count(*) from test_multirange_gist where mr <@ int4range(10, 50); -select COUNT(*) from test_multirange_gist where mr << int4range(100, 500); +select count(*) from test_multirange_gist where mr << int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr >> int4range(100, 500); +select count(*) from test_multirange_gist where mr >> int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr &< int4range(100, 500); +select count(*) from test_multirange_gist where mr &< int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr &> int4range(100, 500); +select count(*) from test_multirange_gist where mr &> int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr -|- int4range(100, 500); +select count(*) from test_multirange_gist where mr -|- int4range(100, 500); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + mr @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_multirange_gist where - mr && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + mr && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + mr <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr -|- int4multirange(int4range(100, 200), int4range(400, 500)); set enable_seqscan = f; @@ -1320,258 +1128,225 @@ set enable_indexscan = t; set enable_bitmapscan = f; select - COUNT(*) + count(*) from test_multirange_gist where mr = cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr && cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr <@ cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr << cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr >> cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr &< cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr &> cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr -|- cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr && cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr <@ cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr << cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr >> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr &< cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr &> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr -|- cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('empty' as int4range); select - COUNT(*) + count(*) from test_multirange_gist where - mr = - int4multirange( - int4range(10, 20), - int4range(30, 40), - int4range(50, 60) - ); + mr = int4multirange(int4range(10, 20), int4range(30, 40), int4range(50, 60)); -select COUNT(*) from test_multirange_gist where mr @> 10; +select count(*) from test_multirange_gist where mr @> 10; -select COUNT(*) from test_multirange_gist where mr @> int4range(10, 20); +select count(*) from test_multirange_gist where mr @> int4range(10, 20); -select COUNT(*) from test_multirange_gist where mr && int4range(10, 20); +select count(*) from test_multirange_gist where mr && int4range(10, 20); -select COUNT(*) from test_multirange_gist where mr <@ int4range(10, 50); +select count(*) from test_multirange_gist where mr <@ int4range(10, 50); -select COUNT(*) from test_multirange_gist where mr << int4range(100, 500); +select count(*) from test_multirange_gist where mr << int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr >> int4range(100, 500); +select count(*) from test_multirange_gist where mr >> int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr &< int4range(100, 500); +select count(*) from test_multirange_gist where mr &< int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr &> int4range(100, 500); +select count(*) from test_multirange_gist where mr &> int4range(100, 500); -select COUNT(*) from test_multirange_gist where mr -|- int4range(100, 500); +select count(*) from test_multirange_gist where mr -|- int4range(100, 500); select - COUNT(*) + count(*) from test_multirange_gist where mr @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + mr @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_multirange_gist where - mr && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + mr && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + mr <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_multirange_gist where - mr << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_multirange_gist where - mr -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + mr -|- int4multirange(int4range(100, 200), int4range(400, 500)); drop table test_multirange_gist; @@ -1582,37 +1357,19 @@ create table reservations ( insert into reservations values - ( - 1, daterange('2018-07-01', '2018-07-07') - ), - ( - 1, daterange('2018-07-07', '2018-07-14') - ), - ( - 1, daterange('2018-07-20', '2018-07-22') - ), - ( - 2, daterange('2018-07-01', '2018-07-03') - ), + (1, daterange('2018-07-01', '2018-07-07')), + (1, daterange('2018-07-07', '2018-07-14')), + (1, daterange('2018-07-20', '2018-07-22')), + (2, daterange('2018-07-01', '2018-07-03')), (3, null), (4, null), (4, null), (5, null), - ( - 5, daterange('2018-07-01', '2018-07-03') - ), - ( - 6, daterange('2018-07-01', '2018-07-07') - ), - ( - 6, daterange('2018-07-05', '2018-07-10') - ), - ( - 7, daterange('2018-07-01', '2018-07-07') - ), - ( - 7, daterange('2018-07-07', '2018-07-14') - ), + (5, daterange('2018-07-01', '2018-07-03')), + (6, daterange('2018-07-01', '2018-07-07')), + (6, daterange('2018-07-05', '2018-07-10')), + (7, daterange('2018-07-01', '2018-07-07')), + (7, daterange('2018-07-07', '2018-07-14')), (8, cast('empty' as daterange)); select @@ -1648,42 +1405,24 @@ select range_agg(nmr) from ( - values - (cast('{}' as nummultirange)), - (cast('{}' as nummultirange)) + values (cast('{}' as nummultirange)), (cast('{}' as nummultirange)) ) as t (nmr); select range_agg(nmr) from - ( - values - (cast('{[1,2]}' as nummultirange)) - ) - as t (nmr); + (values (cast('{[1,2]}' as nummultirange))) as t (nmr); select range_agg(nmr) from - ( - values - ( - cast('{[1,2], [5,6]}' as nummultirange) - ) - ) - as t (nmr); + (values (cast('{[1,2], [5,6]}' as nummultirange))) as t (nmr); select range_agg(nmr) from - ( - values - ( - cast('{[1,2], [2,3]}' as nummultirange) - ) - ) - as t (nmr); + (values (cast('{[1,2], [2,3]}' as nummultirange))) as t (nmr); select range_agg(nmr) @@ -1736,10 +1475,7 @@ select from ( values - ( - cast('{[1,6], [10,12]}' - as nummultirange) - ), + (cast('{[1,6], [10,12]}' as nummultirange)), (cast('{[4,14]}' as nummultirange)) ) as t (nmr); @@ -1747,40 +1483,23 @@ from select range_intersect_agg(nmr) from - ( - values (cast('{}' as nummultirange)) - ) - as t (nmr); + (values (cast('{}' as nummultirange))) as t (nmr); select range_intersect_agg(nmr) from - ( - values - (cast('{[1,2]}' as nummultirange)) - ) - as t (nmr); + (values (cast('{[1,2]}' as nummultirange))) as t (nmr); select range_intersect_agg(nmr) from - ( - values - ( - cast('{[1,6], [10,12]}' - as nummultirange) - ) - ) - as t (nmr); + (values (cast('{[1,6], [10,12]}' as nummultirange))) as t (nmr); select range_intersect_agg(nmr) from nummultirange_test where nmr @> 4.0; create table nummultirange_test2 (nmr nummultirange); -create index "nummultirange_test2_hash_idx" -on nummultirange_test2 -using hash -( +create index nummultirange_test2_hash_idx on nummultirange_test2 using hash ( nmr ); @@ -1791,10 +1510,7 @@ insert into nummultirange_test2 values (nummultirange(numrange(1.1, 2.2))); insert into nummultirange_test2 values (nummultirange(numrange(1.1, 2.2))); insert into nummultirange_test2 -values - ( - nummultirange(numrange(1.1, 2.2, '()')) - ); +values (nummultirange(numrange(1.1, 2.2, '()'))); insert into nummultirange_test2 values ('{}'); @@ -1836,10 +1552,7 @@ set enable_mergejoin = default; drop table nummultirange_test2; -select - cast('{[123.001, 5.e9)}' - as float8multirange) @> - cast(888.882 as double precision); +select cast('{[123.001, 5.e9)}' as float8multirange) @> cast(888.882 as float8); create table float8multirange_test ( f8mr float8multirange, @@ -1847,19 +1560,13 @@ create table float8multirange_test ( ); insert into float8multirange_test -values - ( - float8multirange( - float8range(-100.00007, '1.111113e9') - ), - 42 - ); +values (float8multirange(float8range(-100.00007, '1.111113e9')), 42); select * from float8multirange_test; drop table float8multirange_test; -create domain mydomain as int; +create domain mydomain as int4; create type mydomainrange as range (subtype = mydomain); @@ -1896,19 +1603,19 @@ drop type intr_multirange; create type textrange1 as range ( subtype = text, multirange_type_name = int, - collation = "C" + "collation" = "C" ); create type textrange1 as range ( subtype = text, multirange_type_name = multirange_of_text, - collation = "C" + "collation" = "C" ); create type textrange2 as range ( subtype = text, multirange_type_name = _textrange1, - collation = "C" + "collation" = "C" ); select multirange_of_text(textrange2('a', 'Z')); @@ -1926,7 +1633,7 @@ drop type textrange2; create type textrange1 as range ( subtype = text, multirange_type_name = multitextrange1, - collation = "C" + "collation" = "C" ); create role regress_multirange_owner; @@ -1937,13 +1644,13 @@ alter type textrange1 owner to regress_multirange_owner; set role to regress_multirange_owner; -revoke USAGE on type multitextrange1 from public; +revoke usage on type multitextrange1 from public; -revoke USAGE on type textrange1 from public; +revoke usage on type textrange1 from public; create temporary table test1 (f1 multitextrange1[]); -revoke USAGE on type textrange1 from regress_multirange_owner; +revoke usage on type textrange1 from regress_multirange_owner; create temporary table test2 (f1 multitextrange1[]); @@ -1958,44 +1665,30 @@ drop role regress_multirange_owner; create function anyarray_anymultirange_func(a anyarray, r anymultirange) returns anyelement language sql -as $function$ -select $1[1] + lower($2); -$function$; +as 'select $1[1] + lower($2);'; select - anyarray_anymultirange_func( - array[1, 2], - int4multirange(int4range(10, 20)) - ); + anyarray_anymultirange_func(array[1, 2], int4multirange(int4range(10, 20))); select - anyarray_anymultirange_func( - array[1, 2], - nummultirange(numrange(10, 20)) - ); + anyarray_anymultirange_func(array[1, 2], nummultirange(numrange(10, 20))); drop function anyarray_anymultirange_func(anyarray, anymultirange); create function bogus_func(anyelement) returns anymultirange language sql -as $function$ -select int4multirange(int4range(1,10)) -$function$; +as 'select int4multirange(int4range(1,10))'; create function bogus_func(int) returns anymultirange language sql -as $function$ -select int4multirange(int4range(1,10)) -$function$; +as 'select int4multirange(int4range(1,10))'; create function range_add_bounds(anymultirange) returns anyelement language sql -as $function$ -select lower($1) + upper($1) -$function$; +as 'select lower($1) + upper($1)'; select range_add_bounds(int4multirange(int4range(1, 17))); @@ -2008,9 +1701,7 @@ multirangetypes_sql( out c anyelement ) language sql -as $function$ -select upper($1) + $2[1] -$function$; +as $$ select upper($1) + $2[1] $$; select multirangetypes_sql(int4multirange(int4range(1, 10)), array[2, 20]); @@ -2023,9 +1714,7 @@ anycompatiblearray_anycompatiblemultirange_func( ) returns anycompatible language sql -as $function$ -select $1[1] + lower($2); -$function$; +as 'select $1[1] + lower($2);'; select anycompatiblearray_anycompatiblemultirange_func( @@ -2057,9 +1746,7 @@ anycompatiblerange_anycompatiblemultirange_func( ) returns anycompatible language sql -as $function$ -select lower($1) + lower($2); -$function$; +as 'select lower($1) + lower($2);'; select anycompatiblerange_anycompatiblemultirange_func( @@ -2081,9 +1768,7 @@ drop function create function bogus_func(anycompatible) returns anycompatiblerange language sql -as $function$ -select int4range(1,10) -$function$; +as 'select int4range(1,10)'; select array[nummultirange(numrange(1.1, 1.2)), @@ -2098,8 +1783,7 @@ insert into i8mr_array values ( 42, - array[int8multirange(int8range(1, 10)), - int8multirange(int8range(2, 20))] + array[int8multirange(int8range(1, 10)), int8multirange(int8range(2, 20))] ); select * from i8mr_array; @@ -2124,16 +1808,8 @@ select from ( values - ( - two_ints_multirange( - two_ints_range(row(1, 2), row(3, 4)) - ) - ), - ( - two_ints_multirange( - two_ints_range(row(5, 6), row(7, 8)) - ) - ) + (two_ints_multirange(two_ints_range(row(1, 2), row(3, 4)))), + (two_ints_multirange(two_ints_range(row(5, 6), row(7, 8)))) ) as v (t); @@ -2141,11 +1817,9 @@ drop type two_ints cascade; set enable_sort = off; -select - cast('{(01,10)}' as varbitmultirange) +select cast('{(01,10)}' as varbitmultirange) except -select - cast('{(10,11)}' as varbitmultirange); +select cast('{(10,11)}' as varbitmultirange); reset enable_sort; @@ -2156,9 +1830,7 @@ mr_outparam_succeed( out t text ) language sql -as $function$ -select $1, 'foo'::text -$function$; +as $$ select $1, 'foo'::text $$; select * from mr_outparam_succeed(int4multirange(int4range(1, 2))); @@ -2169,9 +1841,7 @@ mr_outparam_succeed2( out t text ) language sql -as $function$ -select ARRAY[upper($1)], 'foo'::text -$function$; +as $$ select ARRAY[upper($1)], 'foo'::text $$; select * from mr_outparam_succeed2(int4multirange(int4range(1, 2))); @@ -2182,9 +1852,7 @@ mr_outparam_succeed3( out t text ) language sql -as $function$ -select range_merge($1), 'foo'::text -$function$; +as $$ select range_merge($1), 'foo'::text $$; select * from mr_outparam_succeed3(int4multirange(int4range(1, 2))); @@ -2195,17 +1863,13 @@ mr_outparam_succeed4( out t text ) language sql -as $function$ -select multirange($1), 'foo'::text -$function$; +as $$ select multirange($1), 'foo'::text $$; select * from mr_outparam_succeed4(int4range(1, 2)); create function mr_inoutparam_succeed(out i anyelement, inout r anymultirange) language sql -as $function$ -select upper($1), $1 -$function$; +as $$ select upper($1), $1 $$; select * from mr_inoutparam_succeed(int4multirange(int4range(1, 2))); @@ -2215,32 +1879,24 @@ returns table ( r anymultirange ) language sql -as $function$ -select $1, $2 -$function$; +as $$ select $1, $2 $$; select * from mr_table_succeed(123, int4multirange(int4range(1, 11))); create function mr_polymorphic(i anyrange) returns anymultirange language plpgsql -as $function$ -begin return multirange($1); end; -$function$; +as $$ begin return multirange($1); end; $$; select mr_polymorphic(int4range(1, 4)); create function mr_outparam_fail(i anyelement, out r anymultirange, out t text) language sql -as $function$ -select '[1,10]', 'foo' -$function$; +as $$ select '[1,10]', 'foo' $$; create function mr_inoutparam_fail(inout i anyelement, out r anymultirange) language sql -as $function$ -select $1, '[1,10]' -$function$; +as $$ select $1, '[1,10]' $$; create function mr_table_fail(i anyelement) returns table ( @@ -2248,6 +1904,4 @@ returns table ( r anymultirange ) language sql -as $function$ -select $1, '[1,10]' -$function$; +as $$ select $1, '[1,10]' $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__mvcc_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__mvcc_100.snap index fc498f96b..cce9fba5d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__mvcc_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__mvcc_100.snap @@ -15,14 +15,13 @@ create table clean_aborted_self ( data text ); -create index "clean_aborted_self_key" on clean_aborted_self using btree (key); +create index clean_aborted_self_key on clean_aborted_self using btree (key); insert into clean_aborted_self (key, data) values (-1, 'just to allocate metapage'); select pg_relation_size('clean_aborted_self_key') as clean_aborted_self_key_before; -do -$do$ +do $$ BEGIN -- iterate often enough to see index growth even on larger-than-default page sizes FOR i IN 1..100 LOOP @@ -36,15 +35,12 @@ BEGIN RAISE reading_sql_data_not_permitted USING MESSAGE = 'round and round again'; EXCEPTION WHEN reading_sql_data_not_permitted THEN END; END LOOP; -END; -$do$; +END;$$; select 'clean_aborted_self_key_before' as size_before, - pg_relation_size('clean_aborted_self_key') - as size_after + pg_relation_size('clean_aborted_self_key') as size_after where - 'clean_aborted_self_key_before' <> - pg_relation_size('clean_aborted_self_key'); + 'clean_aborted_self_key_before' <> pg_relation_size('clean_aborted_self_key'); rollback; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__mvcc_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__mvcc_80.snap index 19e8a0fec..51d3d283b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__mvcc_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__mvcc_80.snap @@ -15,19 +15,15 @@ create table clean_aborted_self ( data text ); -create index "clean_aborted_self_key" on clean_aborted_self using btree (key); +create index clean_aborted_self_key on clean_aborted_self using btree (key); insert into clean_aborted_self (key, data) values (-1, 'just to allocate metapage'); select - pg_relation_size( - 'clean_aborted_self_key' - ) - as clean_aborted_self_key_before; + pg_relation_size('clean_aborted_self_key') as clean_aborted_self_key_before; -do -$do$ +do $$ BEGIN -- iterate often enough to see index growth even on larger-than-default page sizes FOR i IN 1..100 LOOP @@ -41,20 +37,12 @@ BEGIN RAISE reading_sql_data_not_permitted USING MESSAGE = 'round and round again'; EXCEPTION WHEN reading_sql_data_not_permitted THEN END; END LOOP; -END; -$do$; +END;$$; select - 'clean_aborted_self_key_before' - as size_before, - pg_relation_size( - 'clean_aborted_self_key' - ) - as size_after + 'clean_aborted_self_key_before' as size_before, + pg_relation_size('clean_aborted_self_key') as size_after where - 'clean_aborted_self_key_before' <> - pg_relation_size( - 'clean_aborted_self_key' - ); + 'clean_aborted_self_key_before' <> pg_relation_size('clean_aborted_self_key'); rollback; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__name_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__name_100.snap index 64e903d04..12a6e5dd1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__name_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__name_100.snap @@ -10,16 +10,10 @@ select cast('name string' as name) = cast('name string ' as name) as "False"; create table name_tbl (f1 name); insert into name_tbl (f1) -values - ( - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR' - ); +values ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'); insert into name_tbl (f1) -values - ( - '1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqr' - ); +values ('1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqr'); insert into name_tbl (f1) values ('asdfghjkl;'); @@ -30,10 +24,7 @@ insert into name_tbl (f1) values ('d34aaasdf'); insert into name_tbl (f1) values (''); insert into name_tbl (f1) -values - ( - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ' - ); +values ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'); select * from name_tbl; @@ -42,48 +33,42 @@ select from name_tbl as c where - c.f1 <> - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 <> '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 = - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 < - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 < '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 <= - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 <= '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 > - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 > '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 >= - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 >= '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where c.f1 ~ '.*'; @@ -95,8 +80,7 @@ select c.f1 from name_tbl as c where c.f1 ~ '.*asdf.*'; drop table name_tbl; -do -$do$ +do $$ DECLARE r text[]; BEGIN r := parse_ident('Schemax.Tabley'); @@ -104,13 +88,13 @@ BEGIN r := parse_ident('"SchemaX"."TableY"'); RAISE NOTICE '%', format('%I.%I', r[1], r[2]); END; -$do$; +$$; select parse_ident('foo.boo'); select parse_ident('foo.boo[]'); -select parse_ident('foo.boo[]', "strict" := false); +select parse_ident('foo.boo[]', strict := false); select parse_ident(' '); @@ -134,11 +118,7 @@ from select parse_ident(' first . " second " ." third ". " ' || repeat('x', 66) || '"'); select - cast(parse_ident( - ' first . " second " ." third ". " ' || - repeat('x', 66) || - '"' - ) + cast(parse_ident(' first . " second " ." third ". " ' || repeat('x', 66) || '"') as name[]); select parse_ident('"c".X XXXXXXXXXX'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__name_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__name_80.snap index c3029a5eb..0d7cbe0e0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__name_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__name_80.snap @@ -10,16 +10,10 @@ select cast('name string' as name) = cast('name string ' as name) as "False"; create table name_tbl (f1 name); insert into name_tbl (f1) -values - ( - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR' - ); +values ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'); insert into name_tbl (f1) -values - ( - '1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqr' - ); +values ('1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqr'); insert into name_tbl (f1) values ('asdfghjkl;'); @@ -31,9 +25,7 @@ insert into name_tbl (f1) values (''); insert into name_tbl (f1) values - ( - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ' - ); + ('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'); select * from name_tbl; @@ -42,48 +34,42 @@ select from name_tbl as c where - c.f1 <> - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 <> '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 = - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 < - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 < '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 <= - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 <= '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 > - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 > '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where - c.f1 >= - '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; + c.f1 >= '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890ABCDEFGHIJKLMNOPQR'; select c.f1 from name_tbl as c where c.f1 ~ '.*'; @@ -95,8 +81,7 @@ select c.f1 from name_tbl as c where c.f1 ~ '.*asdf.*'; drop table name_tbl; -do -$do$ +do $$ DECLARE r text[]; BEGIN r := parse_ident('Schemax.Tabley'); @@ -104,13 +89,13 @@ BEGIN r := parse_ident('"SchemaX"."TableY"'); RAISE NOTICE '%', format('%I.%I', r[1], r[2]); END; -$do$; +$$; select parse_ident('foo.boo'); select parse_ident('foo.boo[]'); -select parse_ident('foo.boo[]', "strict" := false); +select parse_ident('foo.boo[]', strict := false); select parse_ident(' '); @@ -133,16 +118,12 @@ from select parse_ident( - ' first . " second " ." third ". " ' || - repeat('x', 66) || - '"' + ' first . " second " ." third ". " ' || repeat('x', 66) || '"' ); select cast(parse_ident( - ' first . " second " ." third ". " ' || - repeat('x', 66) || - '"' + ' first . " second " ." third ". " ' || repeat('x', 66) || '"' ) as name[]); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__namespace_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__namespace_100.snap index c7d0c50ab..afd619231 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__namespace_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__namespace_100.snap @@ -2,11 +2,11 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/namespace.sql --- -select set_config('search_path', ' ', false); +select pg_catalog.set_config('search_path', ' ', false); -create schema "test_ns_schema_1"; +create schema test_ns_schema_1; -create unique index "abc_a_idx" on abc using btree (a); +create unique index abc_a_idx on abc using btree (a); create view abc_view as select a + 1 as a, b + 1 as b from abc; @@ -22,46 +22,38 @@ begin; set search_path to public, test_ns_schema_1; -create schema "test_ns_schema_2"; +create schema test_ns_schema_2; create view abc_view as select c from abc; commit; -show "search_path"; +show search_path; begin; set search_path to public, test_ns_schema_1; -create schema "test_ns_schema_2"; +create schema test_ns_schema_2; create view abc_view as select a from abc; -show "search_path"; +show search_path; commit; -show "search_path"; +show search_path; drop schema test_ns_schema_2 cascade; select - COUNT(*) + count(*) from pg_class where - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'test_ns_schema_1' - ); + relnamespace = (select oid from pg_namespace where nspname = 'test_ns_schema_1'); insert into test_ns_schema_1.abc default values; @@ -76,25 +68,17 @@ select * from test_ns_schema_1.abc_view; alter schema test_ns_schema_1 rename to test_ns_schema_renamed; select - COUNT(*) + count(*) from pg_class where - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'test_ns_schema_1' - ); + relnamespace = (select oid from pg_namespace where nspname = 'test_ns_schema_1'); -create schema "test_ns_schema_renamed"; +create schema test_ns_schema_renamed; -create schema if not exists "test_ns_schema_renamed"; +create schema if not exists test_ns_schema_renamed; -create schema if not exists "test_ns_schema_renamed"; +create schema if not exists test_ns_schema_renamed; create table abc ( a serial, @@ -104,21 +88,13 @@ create table abc ( drop schema test_ns_schema_renamed cascade; select - COUNT(*) + count(*) from pg_class where - relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'test_ns_schema_renamed' - ); - -create schema "test_maint_search_path"; + relnamespace = (select oid from pg_namespace where nspname = 'test_ns_schema_renamed'); + +create schema test_maint_search_path; set search_path to test_maint_search_path; @@ -126,12 +102,12 @@ create function fn(int) returns int language plpgsql immutable -as $function$ -BEGIN +as $$ + BEGIN RAISE NOTICE 'current search_path: %', current_setting('search_path'); RETURN $1; END; -$function$; +$$; create table test_maint (i int); @@ -139,13 +115,13 @@ insert into test_maint values (1), (2); create materialized view test_maint_mv as select fn(i) from test_maint; -create index "test_maint_idx" on test_maint_search_path.test_maint using btree ((fn(i))); +create index test_maint_idx on test_maint_search_path.test_maint using btree ((fn(i))); reindex table test_maint_search_path.test_maint; analyze test_maint_search_path.test_maint; -vacuum (FULL) test_maint_search_path.test_maint; +vacuum (full) test_maint_search_path.test_maint; cluster test_maint_search_path.test_maint using test_maint_idx; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__namespace_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__namespace_80.snap index b07ba6f64..2e668aa7d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__namespace_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__namespace_80.snap @@ -2,11 +2,11 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/namespace.sql --- -select set_config('search_path', ' ', false); +select pg_catalog.set_config('search_path', ' ', false); -create schema "test_ns_schema_1"; +create schema test_ns_schema_1; -create unique index "abc_a_idx" on abc using btree (a); +create unique index abc_a_idx on abc using btree (a); create view abc_view as select a + 1 as a, b + 1 as b from abc; @@ -22,46 +22,39 @@ begin; set search_path to public, test_ns_schema_1; -create schema "test_ns_schema_2"; +create schema test_ns_schema_2; create view abc_view as select c from abc; commit; -show "search_path"; +show search_path; begin; set search_path to public, test_ns_schema_1; -create schema "test_ns_schema_2"; +create schema test_ns_schema_2; create view abc_view as select a from abc; -show "search_path"; +show search_path; commit; -show "search_path"; +show search_path; drop schema test_ns_schema_2 cascade; select - COUNT(*) + count(*) from pg_class where relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'test_ns_schema_1' - ); + (select oid from pg_namespace where nspname = 'test_ns_schema_1'); insert into test_ns_schema_1.abc default values; @@ -76,25 +69,18 @@ select * from test_ns_schema_1.abc_view; alter schema test_ns_schema_1 rename to test_ns_schema_renamed; select - COUNT(*) + count(*) from pg_class where relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'test_ns_schema_1' - ); + (select oid from pg_namespace where nspname = 'test_ns_schema_1'); -create schema "test_ns_schema_renamed"; +create schema test_ns_schema_renamed; -create schema if not exists "test_ns_schema_renamed"; +create schema if not exists test_ns_schema_renamed; -create schema if not exists "test_ns_schema_renamed"; +create schema if not exists test_ns_schema_renamed; create table abc ( a serial, @@ -104,21 +90,14 @@ create table abc ( drop schema test_ns_schema_renamed cascade; select - COUNT(*) + count(*) from pg_class where relnamespace = - ( - select - oid - from - pg_namespace - where - nspname = 'test_ns_schema_renamed' - ); + (select oid from pg_namespace where nspname = 'test_ns_schema_renamed'); -create schema "test_maint_search_path"; +create schema test_maint_search_path; set search_path to test_maint_search_path; @@ -126,12 +105,12 @@ create function fn(int) returns int language plpgsql immutable -as $function$ -BEGIN +as $$ + BEGIN RAISE NOTICE 'current search_path: %', current_setting('search_path'); RETURN $1; END; -$function$; +$$; create table test_maint (i int); @@ -139,10 +118,7 @@ insert into test_maint values (1), (2); create materialized view test_maint_mv as select fn(i) from test_maint; -create index "test_maint_idx" -on test_maint_search_path.test_maint -using btree -( +create index test_maint_idx on test_maint_search_path.test_maint using btree ( (fn(i)) ); @@ -150,7 +126,7 @@ reindex table test_maint_search_path.test_maint; analyze test_maint_search_path.test_maint; -vacuum (FULL) test_maint_search_path.test_maint; +vacuum (full) test_maint_search_path.test_maint; cluster test_maint_search_path.test_maint using test_maint_idx; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numa_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numa_100.snap index 6fbe92b28..6bc847e4a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numa_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numa_100.snap @@ -5,6 +5,6 @@ snapshot_kind: text --- select not pg_numa_available() as skip_test; -select COUNT(*) = 0 as ok from pg_shmem_allocations_numa; +select count(*) = 0 as ok from pg_shmem_allocations_numa; -select COUNT(*) >= 0 as ok from pg_shmem_allocations_numa; +select count(*) >= 0 as ok from pg_shmem_allocations_numa; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numa_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numa_80.snap index 6fbe92b28..6bc847e4a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numa_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numa_80.snap @@ -5,6 +5,6 @@ snapshot_kind: text --- select not pg_numa_available() as skip_test; -select COUNT(*) = 0 as ok from pg_shmem_allocations_numa; +select count(*) = 0 as ok from pg_shmem_allocations_numa; -select COUNT(*) >= 0 as ok from pg_shmem_allocations_numa; +select count(*) >= 0 as ok from pg_shmem_allocations_numa; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_100.snap index 0813561f2..c6a0d7c2f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_100.snap @@ -4,57 +4,57 @@ input_file: crates/pgls_pretty_print/tests/data/multi/numeric.sql snapshot_kind: text --- create table num_data ( - id int, + id int4, val numeric(210, 10) ); create table num_exp_add ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(210, 10) ); create table num_exp_sub ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(210, 10) ); create table num_exp_div ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(210, 10) ); create table num_exp_mul ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(210, 10) ); create table num_exp_sqrt ( - id int, + id int4, expected numeric(210, 10) ); create table num_exp_ln ( - id int, + id int4, expected numeric(210, 10) ); create table num_exp_log10 ( - id int, + id int4, expected numeric(210, 10) ); create table num_exp_power_10_ln ( - id int, + id int4, expected numeric(210, 10) ); create table num_result ( - id1 int, - id2 int, + id1 int4, + id2 int4, result numeric(210, 10) ); @@ -982,37 +982,37 @@ insert into num_data values (9, '-24926804.045047420'); commit; -create unique index "num_exp_add_idx" on num_exp_add using btree (id1, id2); +create unique index num_exp_add_idx on num_exp_add using btree (id1, id2); -create unique index "num_exp_sub_idx" on num_exp_sub using btree (id1, id2); +create unique index num_exp_sub_idx on num_exp_sub using btree (id1, id2); -create unique index "num_exp_div_idx" on num_exp_div using btree (id1, id2); +create unique index num_exp_div_idx on num_exp_div using btree (id1, id2); -create unique index "num_exp_mul_idx" on num_exp_mul using btree (id1, id2); +create unique index num_exp_mul_idx on num_exp_mul using btree (id1, id2); -create unique index "num_exp_sqrt_idx" on num_exp_sqrt using btree (id); +create unique index num_exp_sqrt_idx on num_exp_sqrt using btree (id); -create unique index "num_exp_ln_idx" on num_exp_ln using btree (id); +create unique index num_exp_ln_idx on num_exp_ln using btree (id); -create unique index "num_exp_log10_idx" on num_exp_log10 using btree (id); +create unique index num_exp_log10_idx on num_exp_log10 using btree (id); -create unique index "num_exp_power_10_ln_idx" on num_exp_power_10_ln using btree (id); +create unique index num_exp_power_10_ln_idx on num_exp_power_10_ln using btree (id); -vacuum (ANALYZE) num_exp_add; +vacuum (analyze) num_exp_add; -vacuum (ANALYZE) num_exp_sub; +vacuum (analyze) num_exp_sub; -vacuum (ANALYZE) num_exp_div; +vacuum (analyze) num_exp_div; -vacuum (ANALYZE) num_exp_mul; +vacuum (analyze) num_exp_mul; -vacuum (ANALYZE) num_exp_sqrt; +vacuum (analyze) num_exp_sqrt; -vacuum (ANALYZE) num_exp_ln; +vacuum (analyze) num_exp_ln; -vacuum (ANALYZE) num_exp_log10; +vacuum (analyze) num_exp_log10; -vacuum (ANALYZE) num_exp_power_10_ln; +vacuum (analyze) num_exp_power_10_ln; delete from num_result; @@ -1027,20 +1027,12 @@ from num_result as t1, num_exp_add as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; insert into num_result -select - t1.id, - t2.id, - round(t1.val + t2.val, 10) -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, round(t1.val + t2.val, 10) from num_data as t1, num_data as t2; select t1.id1, @@ -1051,9 +1043,7 @@ from num_result as t1, num_exp_add as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 10); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 10); delete from num_result; @@ -1068,20 +1058,12 @@ from num_result as t1, num_exp_sub as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; insert into num_result -select - t1.id, - t2.id, - round(t1.val - t2.val, 40) -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, round(t1.val - t2.val, 40) from num_data as t1, num_data as t2; select t1.id1, @@ -1092,9 +1074,7 @@ from num_result as t1, num_exp_sub as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 40); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 40); delete from num_result; @@ -1109,20 +1089,12 @@ from num_result as t1, num_exp_mul as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; insert into num_result -select - t1.id, - t2.id, - round(t1.val * t2.val, 30) -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, round(t1.val * t2.val, 30) from num_data as t1, num_data as t2; select t1.id1, @@ -1133,22 +1105,12 @@ from num_result as t1, num_exp_mul as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 30); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 30); delete from num_result; insert into num_result -select - t1.id, - t2.id, - t1.val / t2.val -from - num_data as t1, - num_data as t2 -where - t2.val <> '0.0'; +select t1.id, t2.id, t1.val / t2.val from num_data as t1, num_data as t2 where t2.val <> '0.0'; select t1.id1, @@ -1159,9 +1121,7 @@ from num_result as t1, num_exp_div as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -1185,9 +1145,7 @@ from num_result as t1, num_exp_div as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 80); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 80); delete from num_result; @@ -1220,14 +1178,7 @@ where delete from num_result; insert into num_result -select - id, - 0, - log(cast('10' as numeric), abs(val)) -from - num_data -where - val <> '0.0'; +select id, 0, log(cast('10' as numeric), abs(val)) from num_data where val <> '0.0'; select t1.id1, @@ -1245,10 +1196,7 @@ insert into num_result select id, 0, - power( - cast('10' as numeric), - ln(abs(round(val, 200))) - ) + power(cast('10' as numeric), ln(abs(round(val, 200)))) from num_data where @@ -1264,18 +1212,7 @@ from where t1.id1 = t2.id and t1.result <> t2.expected; -with -v (x) -as ( - values - (cast('0' as numeric)), - ('1'), - ('-1'), - ('4.2'), - ('inf'), - ('-inf'), - ('nan') -) +with v (x) as (values (cast('0' as numeric)), ('1'), ('-1'), ('4.2'), ('inf'), ('-inf'), ('nan')) select x1, x2, @@ -1286,18 +1223,7 @@ from v as v1 (x1), v as v2 (x2); -with -v (x) -as ( - values - (cast('0' as numeric)), - ('1'), - ('-1'), - ('4.2'), - ('inf'), - ('-inf'), - ('nan') -) +with v (x) as (values (cast('0' as numeric)), ('1'), ('-1'), ('4.2'), ('inf'), ('-inf'), ('nan')) select x1, x2, @@ -1337,15 +1263,7 @@ select div(cast('0' as numeric), '0'); with v (x) as ( - values - (cast('0' as numeric)), - ('1'), - ('-1'), - ('4.2'), - ('-7.777'), - ('inf'), - ('-inf'), - ('nan') + values (cast('0' as numeric)), ('1'), ('-1'), ('4.2'), ('-7.777'), ('inf'), ('-inf'), ('nan') ) select x, @@ -1361,15 +1279,7 @@ from with v (x) as ( - values - (cast('0' as numeric)), - ('1'), - ('-1'), - ('4.2'), - ('-7.777'), - ('inf'), - ('-inf'), - ('nan') + values (cast('0' as numeric)), ('1'), ('-1'), ('4.2'), ('-7.777'), ('inf'), ('-inf'), ('nan') ) select x, @@ -1399,21 +1309,12 @@ as ( ('nan') ) select - SUBSTRING(cast(x as text) from 1 for 32) + substring(cast(x as text), 1, 32) from v order by x; -with -v (x) -as ( - values - (cast('0' as numeric)), - ('1'), - ('4.2'), - ('inf'), - ('nan') -) +with v (x) as (values (cast('0' as numeric)), ('1'), ('4.2'), ('inf'), ('nan')) select x, sqrt(x) @@ -1424,15 +1325,7 @@ select sqrt(cast('-1' as numeric)); select sqrt(cast('-inf' as numeric)); -with -v (x) -as ( - values - (cast('1' as numeric)), - ('4.2'), - ('inf'), - ('nan') -) +with v (x) as (values (cast('1' as numeric)), ('4.2'), ('inf'), ('nan')) select x, log(x), @@ -1447,15 +1340,7 @@ select ln(cast('-1' as numeric)); select ln(cast('-inf' as numeric)); -with -v (x) -as ( - values - (cast('2' as numeric)), - ('4.2'), - ('inf'), - ('nan') -) +with v (x) as (values (cast('2' as numeric)), ('4.2'), ('inf'), ('nan')) select x1, x2, @@ -1478,17 +1363,7 @@ select log(cast('inf' as numeric), '-inf'); select log(cast('-inf' as numeric), 'inf'); -with -v (x) -as ( - values - (cast('0' as numeric)), - ('1'), - ('2'), - ('4.2'), - ('inf'), - ('nan') -) +with v (x) as (values (cast('0' as numeric)), ('1'), ('2'), ('4.2'), ('inf'), ('nan')) select x1, x2, @@ -1537,11 +1412,11 @@ select power(cast('-inf' as numeric), 'inf'); select power(cast('-inf' as numeric), '-inf'); -select AVG(val) from num_data; +select avg(val) from num_data; -select MAX(val) from num_data; +select max(val) from num_data; -select MIN(val) from num_data; +select min(val) from num_data; select stddev(val) from num_data; @@ -1578,73 +1453,73 @@ select * from fract_only; drop table fract_only; -select cast(-9223372036854775808.5 as bigint); +select cast(-9223372036854775808.5 as int8); -select cast(-9223372036854775808.4 as bigint); +select cast(-9223372036854775808.4 as int8); -select cast(9223372036854775807.4 as bigint); +select cast(9223372036854775807.4 as int8); -select cast(9223372036854775807.5 as bigint); +select cast(9223372036854775807.5 as int8); -select cast(-2147483648.5 as int); +select cast(-2147483648.5 as int4); -select cast(-2147483648.4 as int); +select cast(-2147483648.4 as int4); -select cast(2147483647.4 as int); +select cast(2147483647.4 as int4); -select cast(2147483647.5 as int); +select cast(2147483647.5 as int4); -select cast(-32768.5 as smallint); +select cast(-32768.5 as int2); -select cast(-32768.4 as smallint); +select cast(-32768.4 as int2); -select cast(32767.4 as smallint); +select cast(32767.4 as int2); -select cast(32767.5 as smallint); +select cast(32767.5 as int2); -select cast(cast('NaN' as double precision) as numeric); +select cast(cast('NaN' as float8) as numeric); -select cast(cast('Infinity' as double precision) as numeric); +select cast(cast('Infinity' as float8) as numeric); -select cast(cast('-Infinity' as double precision) as numeric); +select cast(cast('-Infinity' as float8) as numeric); -select cast(cast('NaN' as numeric) as double precision); +select cast(cast('NaN' as numeric) as float8); -select cast(cast('Infinity' as numeric) as double precision); +select cast(cast('Infinity' as numeric) as float8); -select cast(cast('-Infinity' as numeric) as double precision); +select cast(cast('-Infinity' as numeric) as float8); -select cast(cast('NaN' as real) as numeric); +select cast(cast('NaN' as float4) as numeric); -select cast(cast('Infinity' as real) as numeric); +select cast(cast('Infinity' as float4) as numeric); -select cast(cast('-Infinity' as real) as numeric); +select cast(cast('-Infinity' as float4) as numeric); -select cast(cast('NaN' as numeric) as real); +select cast(cast('NaN' as numeric) as float4); -select cast(cast('Infinity' as numeric) as real); +select cast(cast('Infinity' as numeric) as float4); -select cast(cast('-Infinity' as numeric) as real); +select cast(cast('-Infinity' as numeric) as float4); -select cast(cast('42' as smallint) as numeric); +select cast(cast('42' as int2) as numeric); -select cast(cast('NaN' as numeric) as smallint); +select cast(cast('NaN' as numeric) as int2); -select cast(cast('Infinity' as numeric) as smallint); +select cast(cast('Infinity' as numeric) as int2); -select cast(cast('-Infinity' as numeric) as smallint); +select cast(cast('-Infinity' as numeric) as int2); -select cast(cast('NaN' as numeric) as int); +select cast(cast('NaN' as numeric) as int4); -select cast(cast('Infinity' as numeric) as int); +select cast(cast('Infinity' as numeric) as int4); -select cast(cast('-Infinity' as numeric) as int); +select cast(cast('-Infinity' as numeric) as int4); -select cast(cast('NaN' as numeric) as bigint); +select cast(cast('NaN' as numeric) as int8); -select cast(cast('Infinity' as numeric) as bigint); +select cast(cast('Infinity' as numeric) as int8); -select cast(cast('-Infinity' as numeric) as bigint); +select cast(cast('-Infinity' as numeric) as int8); create table ceil_floor_round (a numeric); @@ -1717,54 +1592,30 @@ select width_bucket(5.0, 3.0, 4.0, -5); select width_bucket(3.5, 3.0, 3.0, 888); -select - width_bucket( - cast(5.0 as double precision), - cast(3.0 as double precision), - cast(4.0 as double precision), - 0 - ); +select width_bucket(cast(5.0 as float8), cast(3.0 as float8), cast(4.0 as float8), 0); -select - width_bucket( - cast(5.0 as double precision), - cast(3.0 as double precision), - cast(4.0 as double precision), - -5 - ); +select width_bucket(cast(5.0 as float8), cast(3.0 as float8), cast(4.0 as float8), -5); -select - width_bucket( - cast(3.5 as double precision), - cast(3.0 as double precision), - cast(3.0 as double precision), - 888 - ); +select width_bucket(cast(3.5 as float8), cast(3.0 as float8), cast(3.0 as float8), 888); select width_bucket('NaN', 3.0, 4.0, 888); -select - width_bucket( - cast('NaN' as double precision), - cast(3.0 as double precision), - cast(4.0 as double precision), - 888 - ); +select width_bucket(cast('NaN' as float8), cast(3.0 as float8), cast(4.0 as float8), 888); select width_bucket(0, 'NaN', 4.0, 888); -select width_bucket(cast(0 as double precision), 'NaN', cast(4.0 as double precision), 888); +select width_bucket(cast(0 as float8), 'NaN', cast(4.0 as float8), 888); select width_bucket(2.0, 3.0, '-inf', 888); -select width_bucket(cast(0 as double precision), '-inf', cast(4.0 as double precision), 888); +select width_bucket(cast(0 as float8), '-inf', cast(4.0 as float8), 888); create table width_bucket_test ( operand_num numeric, - operand_f8 double precision + operand_f8 float8 ); -update width_bucket_test set operand_f8 = cast(operand_num as double precision); +update width_bucket_test set operand_f8 = cast(operand_num as float8); select operand_num, @@ -1786,74 +1637,40 @@ select width_bucket(cast(0.0 as numeric), cast('Infinity' as numeric), 5, 10); select width_bucket(cast(0.0 as numeric), 5, cast('-Infinity' as numeric), 20); select - width_bucket( - cast('Infinity' as numeric), - 1, - 10, - 10 - ), - width_bucket( - cast('-Infinity' as numeric), - 1, - 10, - 10 - ); - -select width_bucket(cast(0.0 as double precision), cast('Infinity' as double precision), 5, 10); - -select width_bucket(cast(0.0 as double precision), 5, cast('-Infinity' as double precision), 20); + width_bucket(cast('Infinity' as numeric), 1, 10, 10), + width_bucket(cast('-Infinity' as numeric), 1, 10, 10); + +select width_bucket(cast(0.0 as float8), cast('Infinity' as float8), 5, 10); + +select width_bucket(cast(0.0 as float8), 5, cast('-Infinity' as float8), 20); select - width_bucket( - cast('Infinity' as double precision), - 1, - 10, - 10 - ), - width_bucket( - cast('-Infinity' as double precision), - 1, - 10, - 10 - ); + width_bucket(cast('Infinity' as float8), 1, 10, 10), + width_bucket(cast('-Infinity' as float8), 1, 10, 10); drop table width_bucket_test; select x, - width_bucket( - cast(x as double precision), - 10, - 100, - 9 - ) - as flt, - width_bucket(cast(x as numeric), 10, 100, 9) - as num + width_bucket(cast(x as float8), 10, 100, 9) as flt, + width_bucket(cast(x as numeric), 10, 100, 9) as num from generate_series(0, 110, 10) as x; select x, - width_bucket( - cast(x as double precision), - 100, - 10, - 9 - ) - as flt, - width_bucket(cast(x as numeric), 100, 10, 9) - as num + width_bucket(cast(x as float8), 100, 10, 9) as flt, + width_bucket(cast(x as numeric), 100, 10, 9) as num from generate_series(0, 110, 10) as x; select width_bucket(0, -cast(1e100 as numeric), 1, 10); -select width_bucket(0, -cast(1e100 as double precision), 1, 10); +select width_bucket(0, -cast(1e100 as float8), 1, 10); select width_bucket(1, cast(1e100 as numeric), 0, 10); -select width_bucket(1, cast(1e100 as double precision), 0, 10); +select width_bucket(1, cast(1e100 as float8), 0, 10); select oper, @@ -1862,21 +1679,16 @@ select cnt, width_bucket(oper, low, high, cnt) from - ( - select - cast(1.797e+308 as double precision) as big, - cast(5e-324 as double precision) as tiny - ) - as v, + (select cast(1.797e+308 as float8) as big, cast(5e-324 as float8) as tiny) as v, lateral ( values - (cast(10.5 as double precision), -big, big, 1), - (cast(10.5 as double precision), -big, big, 2), - (cast(10.5 as double precision), -big, big, 3), + (cast(10.5 as float8), -big, big, 1), + (cast(10.5 as float8), -big, big, 2), + (cast(10.5 as float8), -big, big, 3), (big / 4, -big / 2, big / 2, 10), - (cast(10.5 as double precision), big, -big, 1), - (cast(10.5 as double precision), big, -big, 2), - (cast(10.5 as double precision), big, -big, 3), + (cast(10.5 as float8), big, -big, 1), + (cast(10.5 as float8), big, -big, 2), + (cast(10.5 as float8), big, -big, 3), (big / 4, big / 2, -big / 2, 10), (0, 0, tiny, 4), (tiny, 0, tiny, 4), @@ -1885,9 +1697,9 @@ from ) as sample (oper, low, high, cnt); -select width_bucket(cast(1 as double precision), 0, 1, 2147483647); +select width_bucket(cast(1 as float8), 0, 1, 2147483647); -select width_bucket(cast(0 as double precision), 1, 0, 2147483647); +select width_bucket(cast(0 as float8), 1, 0, 2147483647); select to_char(val, '9G999G999G999G999G999') from num_data; @@ -1924,26 +1736,17 @@ select to_char(val, 'L9999999999999999.099999999999999') from num_data; select to_char(val, 'FM9999999999999999.99999999999999') from num_data; select - to_char( - val, - 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9' - ) + to_char(val, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9') from num_data; select - to_char( - val, - 'FMS 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9' - ) + to_char(val, 'FMS 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9') from num_data; select - to_char( - val, - '99999 "text" 9999 "9999" 999 "\"text between quote marks\"" 9999' - ) + to_char(val, '99999 "text" 9999 "9999" 999 "\"text between quote marks\"" 9999') from num_data; @@ -1958,24 +1761,13 @@ select to_char(val, 'FMRN') from num_data; with v (val) as ( - values - (cast('0' as numeric)), - ('-4.2'), - ('4.2e9'), - ('1.2e-5'), - ('inf'), - ('-inf'), - ('nan') + values (cast('0' as numeric)), ('-4.2'), ('4.2e9'), ('1.2e-5'), ('inf'), ('-inf'), ('nan') ) select val, to_char(val, '9.999EEEE') as numeric, - to_char( - cast(val as double precision), - '9.999EEEE' - ) - as float8, - to_char(cast(val as real), '9.999EEEE') as float4 + to_char(cast(val as float8), '9.999EEEE') as float8, + to_char(cast(val as float4), '9.999EEEE') as float4 from v; @@ -2008,57 +1800,33 @@ as ( ) select exp, - to_char( - cast('1.2345e' || exp as numeric), - '9.999EEEE' - ) - as numeric + to_char(cast('1.2345e' || exp as numeric), '9.999EEEE') as numeric from v; with v (val) as ( - values - (cast('0' as numeric)), - ('-4.2'), - ('4.2e9'), - ('1.2e-5'), - ('inf'), - ('-inf'), - ('nan') + values (cast('0' as numeric)), ('-4.2'), ('4.2e9'), ('1.2e-5'), ('inf'), ('-inf'), ('nan') ) select val, to_char(val, 'MI9999999999.99') as numeric, - to_char( - cast(val as double precision), - 'MI9999999999.99' - ) - as float8, - to_char(cast(val as real), 'MI9999999999.99') - as float4 + to_char(cast(val as float8), 'MI9999999999.99') as float8, + to_char(cast(val as float4), 'MI9999999999.99') as float4 from v; with v (val) as ( - values - (cast('0' as numeric)), - ('-4.2'), - ('4.2e9'), - ('1.2e-5'), - ('inf'), - ('-inf'), - ('nan') + values (cast('0' as numeric)), ('-4.2'), ('4.2e9'), ('1.2e-5'), ('inf'), ('-inf'), ('nan') ) select val, to_char(val, 'MI99.99') as numeric, - to_char(cast(val as double precision), 'MI99.99') - as float8, - to_char(cast(val as real), 'MI99.99') as float4 + to_char(cast(val as float8), 'MI99.99') as float8, + to_char(cast(val as float4), 'MI99.99') as float4 from v; @@ -2068,29 +1836,29 @@ select to_char(cast('100' as numeric), 'FM999.'); select to_char(cast('100' as numeric), 'FM999'); -select to_char(cast('12345678901' as double precision), 'FM9999999999D9999900000000000000000'); +select to_char(cast('12345678901' as float8), 'FM9999999999D9999900000000000000000'); select to_char(cast('100' as numeric), 'rn'); select to_char(cast('1234' as numeric), 'rn'); -select to_char(cast('1235' as real), 'rn'); +select to_char(cast('1235' as float4), 'rn'); -select to_char(cast('1236' as double precision), 'rn'); +select to_char(cast('1236' as float8), 'rn'); -select to_char(cast('1237' as double precision), 'fmrn'); +select to_char(cast('1237' as float8), 'fmrn'); select to_char(cast('100e9' as numeric), 'RN'); -select to_char(cast('100e9' as real), 'RN'); +select to_char(cast('100e9' as float4), 'RN'); -select to_char(cast('100e9' as double precision), 'RN'); +select to_char(cast('100e9' as float8), 'RN'); select to_char(cast(1234.56 as numeric), '99999V99'); -select to_char(cast(1234.56 as real), '99999V99'); +select to_char(cast(1234.56 as float4), '99999V99'); -select to_char(cast(1234.56 as double precision), '99999V99'); +select to_char(cast(1234.56 as float8), '99999V99'); select to_char(cast('100' as numeric), 'foo999'); @@ -2112,7 +1880,7 @@ select to_char(cast('100' as numeric), 'f"ool\"999'); select to_char(cast('100' as numeric), 'f"ool\\"999'); -set lc_numeric = C; +set lc_numeric = 'C'; select to_number('-34,338,492', '99G999G999'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_80.snap index 6ea79533f..9d88e06a6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_80.snap @@ -4,57 +4,57 @@ input_file: crates/pgls_pretty_print/tests/data/multi/numeric.sql snapshot_kind: text --- create table num_data ( - id int, + id int4, val numeric(210, 10) ); create table num_exp_add ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(210, 10) ); create table num_exp_sub ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(210, 10) ); create table num_exp_div ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(210, 10) ); create table num_exp_mul ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(210, 10) ); create table num_exp_sqrt ( - id int, + id int4, expected numeric(210, 10) ); create table num_exp_ln ( - id int, + id int4, expected numeric(210, 10) ); create table num_exp_log10 ( - id int, + id int4, expected numeric(210, 10) ); create table num_exp_power_10_ln ( - id int, + id int4, expected numeric(210, 10) ); create table num_result ( - id1 int, - id2 int, + id1 int4, + id2 int4, result numeric(210, 10) ); @@ -941,40 +941,24 @@ insert into num_exp_power_10_ln values (0, 'NaN'); insert into num_exp_power_10_ln values (1, 'NaN'); insert into num_exp_power_10_ln -values - ( - 2, - '224790267919917955.13261618583642653184' - ); +values (2, '224790267919917955.13261618583642653184'); insert into num_exp_power_10_ln values (3, '28.90266599445155957393'); insert into num_exp_power_10_ln -values - ( - 4, - '7405685069594999.07733999469386277636' - ); +values (4, '7405685069594999.07733999469386277636'); insert into num_exp_power_10_ln values (5, '5068226527.32127265408584640098'); insert into num_exp_power_10_ln values (6, '281839893606.99372343357047819067'); insert into num_exp_power_10_ln -values - ( - 7, - '1716699575118597095.42330819910640247627' - ); +values (7, '1716699575118597095.42330819910640247627'); insert into num_exp_power_10_ln values (8, '167361463828.07491320069016125952'); insert into num_exp_power_10_ln -values - ( - 9, - '107511333880052007.04141124673540337457' - ); +values (9, '107511333880052007.04141124673540337457'); commit; @@ -1002,54 +986,44 @@ insert into num_data values (9, '-24926804.045047420'); commit; -create unique index "num_exp_add_idx" on num_exp_add using btree (id1, id2); +create unique index num_exp_add_idx on num_exp_add using btree (id1, id2); -create unique index "num_exp_sub_idx" on num_exp_sub using btree (id1, id2); +create unique index num_exp_sub_idx on num_exp_sub using btree (id1, id2); -create unique index "num_exp_div_idx" on num_exp_div using btree (id1, id2); +create unique index num_exp_div_idx on num_exp_div using btree (id1, id2); -create unique index "num_exp_mul_idx" on num_exp_mul using btree (id1, id2); +create unique index num_exp_mul_idx on num_exp_mul using btree (id1, id2); -create unique index "num_exp_sqrt_idx" on num_exp_sqrt using btree (id); +create unique index num_exp_sqrt_idx on num_exp_sqrt using btree (id); -create unique index "num_exp_ln_idx" on num_exp_ln using btree (id); +create unique index num_exp_ln_idx on num_exp_ln using btree (id); -create unique index "num_exp_log10_idx" on num_exp_log10 using btree (id); +create unique index num_exp_log10_idx on num_exp_log10 using btree (id); -create unique -index "num_exp_power_10_ln_idx" -on num_exp_power_10_ln -using btree -( +create unique index num_exp_power_10_ln_idx on num_exp_power_10_ln using btree ( id ); -vacuum (ANALYZE) num_exp_add; +vacuum (analyze) num_exp_add; -vacuum (ANALYZE) num_exp_sub; +vacuum (analyze) num_exp_sub; -vacuum (ANALYZE) num_exp_div; +vacuum (analyze) num_exp_div; -vacuum (ANALYZE) num_exp_mul; +vacuum (analyze) num_exp_mul; -vacuum (ANALYZE) num_exp_sqrt; +vacuum (analyze) num_exp_sqrt; -vacuum (ANALYZE) num_exp_ln; +vacuum (analyze) num_exp_ln; -vacuum (ANALYZE) num_exp_log10; +vacuum (analyze) num_exp_log10; -vacuum (ANALYZE) num_exp_power_10_ln; +vacuum (analyze) num_exp_power_10_ln; delete from num_result; insert into num_result -select - t1.id, - t2.id, - t1.val + t2.val -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, t1.val + t2.val from num_data as t1, num_data as t2; select t1.id1, @@ -1060,9 +1034,7 @@ from num_result as t1, num_exp_add as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -1084,20 +1056,12 @@ from num_result as t1, num_exp_add as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 10); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 10); delete from num_result; insert into num_result -select - t1.id, - t2.id, - t1.val - t2.val -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, t1.val - t2.val from num_data as t1, num_data as t2; select t1.id1, @@ -1108,9 +1072,7 @@ from num_result as t1, num_exp_sub as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -1132,20 +1094,12 @@ from num_result as t1, num_exp_sub as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 40); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 40); delete from num_result; insert into num_result -select - t1.id, - t2.id, - t1.val * t2.val -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, t1.val * t2.val from num_data as t1, num_data as t2; select t1.id1, @@ -1156,9 +1110,7 @@ from num_result as t1, num_exp_mul as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -1180,9 +1132,7 @@ from num_result as t1, num_exp_mul as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 30); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 30); delete from num_result; @@ -1206,9 +1156,7 @@ from num_result as t1, num_exp_div as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -1232,9 +1180,7 @@ from num_result as t1, num_exp_div as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 80); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 80); delete from num_result; @@ -1248,20 +1194,12 @@ from num_result as t1, num_exp_sqrt as t2 where - t1.id1 = t2.id and - t1.result <> t2.expected; + t1.id1 = t2.id and t1.result <> t2.expected; delete from num_result; insert into num_result -select - id, - 0, - ln(abs(val)) -from - num_data -where - val <> '0.0'; +select id, 0, ln(abs(val)) from num_data where val <> '0.0'; select t1.id1, @@ -1271,8 +1209,7 @@ from num_result as t1, num_exp_ln as t2 where - t1.id1 = t2.id and - t1.result <> t2.expected; + t1.id1 = t2.id and t1.result <> t2.expected; delete from num_result; @@ -1294,8 +1231,7 @@ from num_result as t1, num_exp_log10 as t2 where - t1.id1 = t2.id and - t1.result <> t2.expected; + t1.id1 = t2.id and t1.result <> t2.expected; delete from num_result; @@ -1303,10 +1239,7 @@ insert into num_result select id, 0, - power( - cast('10' as numeric), - ln(abs(round(val, 200))) - ) + power(cast('10' as numeric), ln(abs(round(val, 200)))) from num_data where @@ -1320,8 +1253,7 @@ from num_result as t1, num_exp_power_10_ln as t2 where - t1.id1 = t2.id and - t1.result <> t2.expected; + t1.id1 = t2.id and t1.result <> t2.expected; with v (x) @@ -1458,21 +1390,12 @@ as ( ('nan') ) select - SUBSTRING(cast(x as text) from 1 for 32) + substring(cast(x as text), 1, 32) from v order by x; -with -v (x) -as ( - values - (cast('0' as numeric)), - ('1'), - ('4.2'), - ('inf'), - ('nan') -) +with v (x) as (values (cast('0' as numeric)), ('1'), ('4.2'), ('inf'), ('nan')) select x, sqrt(x) @@ -1483,15 +1406,7 @@ select sqrt(cast('-1' as numeric)); select sqrt(cast('-inf' as numeric)); -with -v (x) -as ( - values - (cast('1' as numeric)), - ('4.2'), - ('inf'), - ('nan') -) +with v (x) as (values (cast('1' as numeric)), ('4.2'), ('inf'), ('nan')) select x, log(x), @@ -1506,15 +1421,7 @@ select ln(cast('-1' as numeric)); select ln(cast('-inf' as numeric)); -with -v (x) -as ( - values - (cast('2' as numeric)), - ('4.2'), - ('inf'), - ('nan') -) +with v (x) as (values (cast('2' as numeric)), ('4.2'), ('inf'), ('nan')) select x1, x2, @@ -1540,13 +1447,7 @@ select log(cast('-inf' as numeric), 'inf'); with v (x) as ( - values - (cast('0' as numeric)), - ('1'), - ('2'), - ('4.2'), - ('inf'), - ('nan') + values (cast('0' as numeric)), ('1'), ('2'), ('4.2'), ('inf'), ('nan') ) select x1, @@ -1596,11 +1497,11 @@ select power(cast('-inf' as numeric), 'inf'); select power(cast('-inf' as numeric), '-inf'); -select AVG(val) from num_data; +select avg(val) from num_data; -select MAX(val) from num_data; +select max(val) from num_data; -select MIN(val) from num_data; +select min(val) from num_data; select stddev(val) from num_data; @@ -1637,73 +1538,73 @@ select * from fract_only; drop table fract_only; -select cast(-9223372036854775808.5 as bigint); +select cast(-9223372036854775808.5 as int8); -select cast(-9223372036854775808.4 as bigint); +select cast(-9223372036854775808.4 as int8); -select cast(9223372036854775807.4 as bigint); +select cast(9223372036854775807.4 as int8); -select cast(9223372036854775807.5 as bigint); +select cast(9223372036854775807.5 as int8); -select cast(-2147483648.5 as int); +select cast(-2147483648.5 as int4); -select cast(-2147483648.4 as int); +select cast(-2147483648.4 as int4); -select cast(2147483647.4 as int); +select cast(2147483647.4 as int4); -select cast(2147483647.5 as int); +select cast(2147483647.5 as int4); -select cast(-32768.5 as smallint); +select cast(-32768.5 as int2); -select cast(-32768.4 as smallint); +select cast(-32768.4 as int2); -select cast(32767.4 as smallint); +select cast(32767.4 as int2); -select cast(32767.5 as smallint); +select cast(32767.5 as int2); -select cast(cast('NaN' as double precision) as numeric); +select cast(cast('NaN' as float8) as numeric); -select cast(cast('Infinity' as double precision) as numeric); +select cast(cast('Infinity' as float8) as numeric); -select cast(cast('-Infinity' as double precision) as numeric); +select cast(cast('-Infinity' as float8) as numeric); -select cast(cast('NaN' as numeric) as double precision); +select cast(cast('NaN' as numeric) as float8); -select cast(cast('Infinity' as numeric) as double precision); +select cast(cast('Infinity' as numeric) as float8); -select cast(cast('-Infinity' as numeric) as double precision); +select cast(cast('-Infinity' as numeric) as float8); -select cast(cast('NaN' as real) as numeric); +select cast(cast('NaN' as float4) as numeric); -select cast(cast('Infinity' as real) as numeric); +select cast(cast('Infinity' as float4) as numeric); -select cast(cast('-Infinity' as real) as numeric); +select cast(cast('-Infinity' as float4) as numeric); -select cast(cast('NaN' as numeric) as real); +select cast(cast('NaN' as numeric) as float4); -select cast(cast('Infinity' as numeric) as real); +select cast(cast('Infinity' as numeric) as float4); -select cast(cast('-Infinity' as numeric) as real); +select cast(cast('-Infinity' as numeric) as float4); -select cast(cast('42' as smallint) as numeric); +select cast(cast('42' as int2) as numeric); -select cast(cast('NaN' as numeric) as smallint); +select cast(cast('NaN' as numeric) as int2); -select cast(cast('Infinity' as numeric) as smallint); +select cast(cast('Infinity' as numeric) as int2); -select cast(cast('-Infinity' as numeric) as smallint); +select cast(cast('-Infinity' as numeric) as int2); -select cast(cast('NaN' as numeric) as int); +select cast(cast('NaN' as numeric) as int4); -select cast(cast('Infinity' as numeric) as int); +select cast(cast('Infinity' as numeric) as int4); -select cast(cast('-Infinity' as numeric) as int); +select cast(cast('-Infinity' as numeric) as int4); -select cast(cast('NaN' as numeric) as bigint); +select cast(cast('NaN' as numeric) as int8); -select cast(cast('Infinity' as numeric) as bigint); +select cast(cast('Infinity' as numeric) as int8); -select cast(cast('-Infinity' as numeric) as bigint); +select cast(cast('-Infinity' as numeric) as int8); create table ceil_floor_round (a numeric); @@ -1727,18 +1628,9 @@ drop table ceil_floor_round; select i as pow, - round( - cast(-2.5 * 10 ^ i as numeric), - -i - ), - round( - cast(-1.5 * 10 ^ i as numeric), - -i - ), - round( - cast(-0.5 * 10 ^ i as numeric), - -i - ), + round(cast(-2.5 * 10 ^ i as numeric), -i), + round(cast(-1.5 * 10 ^ i as numeric), -i), + round(cast(-0.5 * 10 ^ i as numeric), -i), round(cast(0.5 * 10 ^ i as numeric), -i), round(cast(1.5 * 10 ^ i as numeric), -i), round(cast(2.5 * 10 ^ i as numeric), -i) @@ -1787,25 +1679,25 @@ select width_bucket(3.5, 3.0, 3.0, 888); select width_bucket( - cast(5.0 as double precision), - cast(3.0 as double precision), - cast(4.0 as double precision), + cast(5.0 as float8), + cast(3.0 as float8), + cast(4.0 as float8), 0 ); select width_bucket( - cast(5.0 as double precision), - cast(3.0 as double precision), - cast(4.0 as double precision), + cast(5.0 as float8), + cast(3.0 as float8), + cast(4.0 as float8), -5 ); select width_bucket( - cast(3.5 as double precision), - cast(3.0 as double precision), - cast(3.0 as double precision), + cast(3.5 as float8), + cast(3.0 as float8), + cast(3.0 as float8), 888 ); @@ -1813,61 +1705,39 @@ select width_bucket('NaN', 3.0, 4.0, 888); select width_bucket( - cast('NaN' as double precision), - cast(3.0 as double precision), - cast(4.0 as double precision), + cast('NaN' as float8), + cast(3.0 as float8), + cast(4.0 as float8), 888 ); select width_bucket(0, 'NaN', 4.0, 888); -select - width_bucket( - cast(0 as double precision), - 'NaN', - cast(4.0 as double precision), - 888 - ); +select width_bucket(cast(0 as float8), 'NaN', cast(4.0 as float8), 888); select width_bucket(2.0, 3.0, '-inf', 888); -select - width_bucket( - cast(0 as double precision), - '-inf', - cast(4.0 as double precision), - 888 - ); +select width_bucket(cast(0 as float8), '-inf', cast(4.0 as float8), 888); create table width_bucket_test ( operand_num numeric, - operand_f8 double precision + operand_f8 float8 ); -update width_bucket_test set operand_f8 = cast(operand_num as double precision); +update width_bucket_test set operand_f8 = cast(operand_num as float8); select operand_num, - width_bucket(operand_num, 0, 10, 5) - as wb_1, - width_bucket(operand_f8, 0, 10, 5) - as wb_1f, - width_bucket(operand_num, 10, 0, 5) - as wb_2, - width_bucket(operand_f8, 10, 0, 5) - as wb_2f, - width_bucket(operand_num, 2, 8, 4) - as wb_3, - width_bucket(operand_f8, 2, 8, 4) - as wb_3f, - width_bucket(operand_num, 5.0, 5.5, 20) - as wb_4, - width_bucket(operand_f8, 5.0, 5.5, 20) - as wb_4f, - width_bucket(operand_num, -25, 25, 10) - as wb_5, - width_bucket(operand_f8, -25, 25, 10) - as wb_5f + width_bucket(operand_num, 0, 10, 5) as wb_1, + width_bucket(operand_f8, 0, 10, 5) as wb_1f, + width_bucket(operand_num, 10, 0, 5) as wb_2, + width_bucket(operand_f8, 10, 0, 5) as wb_2f, + width_bucket(operand_num, 2, 8, 4) as wb_3, + width_bucket(operand_f8, 2, 8, 4) as wb_3f, + width_bucket(operand_num, 5.0, 5.5, 20) as wb_4, + width_bucket(operand_f8, 5.0, 5.5, 20) as wb_4f, + width_bucket(operand_num, -25, 25, 10) as wb_5, + width_bucket(operand_f8, -25, 25, 10) as wb_5f from width_bucket_test; @@ -1876,96 +1746,40 @@ select width_bucket(cast(0.0 as numeric), cast('Infinity' as numeric), 5, 10); select width_bucket(cast(0.0 as numeric), 5, cast('-Infinity' as numeric), 20); select - width_bucket( - cast('Infinity' as numeric), - 1, - 10, - 10 - ), - width_bucket( - cast('-Infinity' as numeric), - 1, - 10, - 10 - ); + width_bucket(cast('Infinity' as numeric), 1, 10, 10), + width_bucket(cast('-Infinity' as numeric), 1, 10, 10); -select - width_bucket( - cast(0.0 as double precision), - cast('Infinity' as double precision), - 5, - 10 - ); +select width_bucket(cast(0.0 as float8), cast('Infinity' as float8), 5, 10); -select - width_bucket( - cast(0.0 as double precision), - 5, - cast('-Infinity' as double precision), - 20 - ); +select width_bucket(cast(0.0 as float8), 5, cast('-Infinity' as float8), 20); select - width_bucket( - cast('Infinity' as double precision), - 1, - 10, - 10 - ), - width_bucket( - cast('-Infinity' as double precision), - 1, - 10, - 10 - ); + width_bucket(cast('Infinity' as float8), 1, 10, 10), + width_bucket(cast('-Infinity' as float8), 1, 10, 10); drop table width_bucket_test; select x, - width_bucket( - cast(x as double precision), - 10, - 100, - 9 - ) - as flt, - width_bucket( - cast(x as numeric), - 10, - 100, - 9 - ) - as num + width_bucket(cast(x as float8), 10, 100, 9) as flt, + width_bucket(cast(x as numeric), 10, 100, 9) as num from generate_series(0, 110, 10) as x; select x, - width_bucket( - cast(x as double precision), - 100, - 10, - 9 - ) - as flt, - width_bucket( - cast(x as numeric), - 100, - 10, - 9 - ) - as num + width_bucket(cast(x as float8), 100, 10, 9) as flt, + width_bucket(cast(x as numeric), 100, 10, 9) as num from generate_series(0, 110, 10) as x; select width_bucket(0, -cast(1e100 as numeric), 1, 10); -select width_bucket(0, -cast(1e100 as double precision), 1, 10); +select width_bucket(0, -cast(1e100 as float8), 1, 10); select width_bucket(1, cast(1e100 as numeric), 0, 10); -select width_bucket(1, cast(1e100 as double precision), 0, 10); +select width_bucket(1, cast(1e100 as float8), 0, 10); select oper, @@ -1975,51 +1789,18 @@ select width_bucket(oper, low, high, cnt) from ( - select - cast(1.797e+308 as double precision) - as big, - cast(5e-324 as double precision) as tiny + select cast(1.797e+308 as float8) as big, cast(5e-324 as float8) as tiny ) as v, lateral ( values - ( - cast(10.5 as double precision), - -big, - big, - 1 - ), - ( - cast(10.5 as double precision), - -big, - big, - 2 - ), - ( - cast(10.5 as double precision), - -big, - big, - 3 - ), + (cast(10.5 as float8), -big, big, 1), + (cast(10.5 as float8), -big, big, 2), + (cast(10.5 as float8), -big, big, 3), (big / 4, -big / 2, big / 2, 10), - ( - cast(10.5 as double precision), - big, - -big, - 1 - ), - ( - cast(10.5 as double precision), - big, - -big, - 2 - ), - ( - cast(10.5 as double precision), - big, - -big, - 3 - ), + (cast(10.5 as float8), big, -big, 1), + (cast(10.5 as float8), big, -big, 2), + (cast(10.5 as float8), big, -big, 3), (big / 4, big / 2, -big / 2, 10), (0, 0, tiny, 4), (tiny, 0, tiny, 4), @@ -2028,9 +1809,9 @@ from ) as sample (oper, low, high, cnt); -select width_bucket(cast(1 as double precision), 0, 1, 2147483647); +select width_bucket(cast(1 as float8), 0, 1, 2147483647); -select width_bucket(cast(0 as double precision), 1, 0, 2147483647); +select width_bucket(cast(0 as float8), 1, 0, 2147483647); select to_char(val, '9G999G999G999G999G999') from num_data; @@ -2113,13 +1894,8 @@ as ( select val, to_char(val, '9.999EEEE') as numeric, - to_char( - cast(val as double precision), - '9.999EEEE' - ) - as float8, - to_char(cast(val as real), '9.999EEEE') - as float4 + to_char(cast(val as float8), '9.999EEEE') as float8, + to_char(cast(val as float4), '9.999EEEE') as float4 from v; @@ -2152,11 +1928,7 @@ as ( ) select exp, - to_char( - cast('1.2345e' || exp as numeric), - '9.999EEEE' - ) - as numeric + to_char(cast('1.2345e' || exp as numeric), '9.999EEEE') as numeric from v; @@ -2174,18 +1946,9 @@ as ( ) select val, - to_char(val, 'MI9999999999.99') - as numeric, - to_char( - cast(val as double precision), - 'MI9999999999.99' - ) - as float8, - to_char( - cast(val as real), - 'MI9999999999.99' - ) - as float4 + to_char(val, 'MI9999999999.99') as numeric, + to_char(cast(val as float8), 'MI9999999999.99') as float8, + to_char(cast(val as float4), 'MI9999999999.99') as float4 from v; @@ -2204,13 +1967,8 @@ as ( select val, to_char(val, 'MI99.99') as numeric, - to_char( - cast(val as double precision), - 'MI99.99' - ) - as float8, - to_char(cast(val as real), 'MI99.99') - as float4 + to_char(cast(val as float8), 'MI99.99') as float8, + to_char(cast(val as float4), 'MI99.99') as float4 from v; @@ -2221,32 +1979,29 @@ select to_char(cast('100' as numeric), 'FM999.'); select to_char(cast('100' as numeric), 'FM999'); select - to_char( - cast('12345678901' as double precision), - 'FM9999999999D9999900000000000000000' - ); + to_char(cast('12345678901' as float8), 'FM9999999999D9999900000000000000000'); select to_char(cast('100' as numeric), 'rn'); select to_char(cast('1234' as numeric), 'rn'); -select to_char(cast('1235' as real), 'rn'); +select to_char(cast('1235' as float4), 'rn'); -select to_char(cast('1236' as double precision), 'rn'); +select to_char(cast('1236' as float8), 'rn'); -select to_char(cast('1237' as double precision), 'fmrn'); +select to_char(cast('1237' as float8), 'fmrn'); select to_char(cast('100e9' as numeric), 'RN'); -select to_char(cast('100e9' as real), 'RN'); +select to_char(cast('100e9' as float4), 'RN'); -select to_char(cast('100e9' as double precision), 'RN'); +select to_char(cast('100e9' as float8), 'RN'); select to_char(cast(1234.56 as numeric), '99999V99'); -select to_char(cast(1234.56 as real), '99999V99'); +select to_char(cast(1234.56 as float4), '99999V99'); -select to_char(cast(1234.56 as double precision), '99999V99'); +select to_char(cast(1234.56 as float8), '99999V99'); select to_char(cast('100' as numeric), 'foo999'); @@ -2268,7 +2023,7 @@ select to_char(cast('100' as numeric), 'f"ool\"999'); select to_char(cast('100' as numeric), 'f"ool\\"999'); -set lc_numeric = C; +set lc_numeric = 'C'; select to_number('-34,338,492', '99G999G999'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_big_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_big_100.snap index 431c6543e..e28261cce 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_big_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_big_100.snap @@ -24,57 +24,57 @@ drop table num_exp_power_10_ln; drop table num_result; create table num_data ( - id int, + id int4, val numeric(1000, 800) ); create table num_exp_add ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(1000, 800) ); create table num_exp_sub ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(1000, 800) ); create table num_exp_div ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(1000, 800) ); create table num_exp_mul ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(1000, 800) ); create table num_exp_sqrt ( - id int, + id int4, expected numeric(1000, 800) ); create table num_exp_ln ( - id int, + id int4, expected numeric(1000, 800) ); create table num_exp_log10 ( - id int, + id int4, expected numeric(1000, 800) ); create table num_exp_power_10_ln ( - id int, + id int4, expected numeric(1000, 800) ); create table num_result ( - id1 int, - id2 int, + id1 int4, + id2 int4, result numeric(1000, 800) ); @@ -3292,37 +3292,37 @@ values commit; -create unique index "num_exp_add_idx" on num_exp_add using btree (id1, id2); +create unique index num_exp_add_idx on num_exp_add using btree (id1, id2); -create unique index "num_exp_sub_idx" on num_exp_sub using btree (id1, id2); +create unique index num_exp_sub_idx on num_exp_sub using btree (id1, id2); -create unique index "num_exp_div_idx" on num_exp_div using btree (id1, id2); +create unique index num_exp_div_idx on num_exp_div using btree (id1, id2); -create unique index "num_exp_mul_idx" on num_exp_mul using btree (id1, id2); +create unique index num_exp_mul_idx on num_exp_mul using btree (id1, id2); -create unique index "num_exp_sqrt_idx" on num_exp_sqrt using btree (id); +create unique index num_exp_sqrt_idx on num_exp_sqrt using btree (id); -create unique index "num_exp_ln_idx" on num_exp_ln using btree (id); +create unique index num_exp_ln_idx on num_exp_ln using btree (id); -create unique index "num_exp_log10_idx" on num_exp_log10 using btree (id); +create unique index num_exp_log10_idx on num_exp_log10 using btree (id); -create unique index "num_exp_power_10_ln_idx" on num_exp_power_10_ln using btree (id); +create unique index num_exp_power_10_ln_idx on num_exp_power_10_ln using btree (id); -vacuum (ANALYZE) num_exp_add; +vacuum (analyze) num_exp_add; -vacuum (ANALYZE) num_exp_sub; +vacuum (analyze) num_exp_sub; -vacuum (ANALYZE) num_exp_div; +vacuum (analyze) num_exp_div; -vacuum (ANALYZE) num_exp_mul; +vacuum (analyze) num_exp_mul; -vacuum (ANALYZE) num_exp_sqrt; +vacuum (analyze) num_exp_sqrt; -vacuum (ANALYZE) num_exp_ln; +vacuum (analyze) num_exp_ln; -vacuum (ANALYZE) num_exp_log10; +vacuum (analyze) num_exp_log10; -vacuum (ANALYZE) num_exp_power_10_ln; +vacuum (analyze) num_exp_power_10_ln; delete from num_result; @@ -3337,20 +3337,12 @@ from num_result as t1, num_exp_add as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; insert into num_result -select - t1.id, - t2.id, - round(t1.val + t2.val, 10) -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, round(t1.val + t2.val, 10) from num_data as t1, num_data as t2; select t1.id1, @@ -3361,9 +3353,7 @@ from num_result as t1, num_exp_add as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 10); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 10); delete from num_result; @@ -3378,20 +3368,12 @@ from num_result as t1, num_exp_sub as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; insert into num_result -select - t1.id, - t2.id, - round(t1.val - t2.val, 40) -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, round(t1.val - t2.val, 40) from num_data as t1, num_data as t2; select t1.id1, @@ -3402,9 +3384,7 @@ from num_result as t1, num_exp_sub as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 40); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 40); delete from num_result; @@ -3419,20 +3399,12 @@ from num_result as t1, num_exp_mul as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; insert into num_result -select - t1.id, - t2.id, - round(t1.val * t2.val, 30) -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, round(t1.val * t2.val, 30) from num_data as t1, num_data as t2; select t1.id1, @@ -3443,22 +3415,12 @@ from num_result as t1, num_exp_mul as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 30); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 30); delete from num_result; insert into num_result -select - t1.id, - t2.id, - t1.val / t2.val -from - num_data as t1, - num_data as t2 -where - t2.val <> '0.0'; +select t1.id, t2.id, t1.val / t2.val from num_data as t1, num_data as t2 where t2.val <> '0.0'; select t1.id1, @@ -3469,9 +3431,7 @@ from num_result as t1, num_exp_div as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -3495,9 +3455,7 @@ from num_result as t1, num_exp_div as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 80); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 80); delete from num_result; @@ -3530,14 +3488,7 @@ where delete from num_result; insert into num_result -select - id, - 0, - log(cast('10' as numeric), abs(val)) -from - num_data -where - val <> '0.0'; +select id, 0, log(cast('10' as numeric), abs(val)) from num_data where val <> '0.0'; select t1.id1, @@ -3555,10 +3506,7 @@ insert into num_result select id, 0, - pow( - cast('10' as numeric), - ln(abs(round(val, 1000))) - ) + pow(cast('10' as numeric), ln(abs(round(val, 1000)))) from num_data where @@ -3575,9 +3523,7 @@ where t1.id1 = t2.id and t1.result <> t2.expected; with -t (b, -p, -bc_result) +t (b, p, bc_result) as ( values (0.084738, -20, 2744326694304960114888.785913), @@ -3617,22 +3563,10 @@ as ( (0.084738, 14, .0000000000000009842262254614642), (0.084738, 15, .00000000000000008340136189315355), (0.084738, 16, .000000000000000007067264604102046), - ( - 0.084738, 17, .0000000000000000005988658680223991 - ), - ( - 0.084738, 18, .00000000000000000005074669592448206 - ), - ( - 0.084738, - 19, - .000000000000000000004300173519248761 - ), - ( - 0.084738, - 20, - .0000000000000000000003643881036741015 - ) + (0.084738, 17, .0000000000000000005988658680223991), + (0.084738, 18, .00000000000000000005074669592448206), + (0.084738, 19, .000000000000000000004300173519248761), + (0.084738, 20, .0000000000000000000003643881036741015) ) select b, @@ -3644,59 +3578,19 @@ from t; with -t (b, -p, -bc_result) +t (b, p, bc_result) as ( values - ( - 37.821637, - -20, - .00000000000000000000000000000002787363175065101 - ), - ( - 37.821637, - -19, - .000000000000000000000000000001054226381944797 - ), - ( - 37.821637, - -18, - .00000000000000000000000000003987256753373947 - ), - ( - 37.821637, - -17, - .000000000000000000000000001508045775519079 - ), - ( - 37.821637, - -16, - .00000000000000000000000005703675990106610 - ), - ( - 37.821637, - -15, - .000000000000000000000002157223628634278 - ), - ( - 37.821637, - -14, - .00000000000000000000008158972901002847 - ), - ( - 37.821637, - -13, - .000000000000000000003085857113545666 - ), - ( - 37.821637, - -12, - .0000000000000000001167121675823920 - ), - ( - 37.821637, -11, .000000000000000004414245235784397 - ), + (37.821637, -20, .00000000000000000000000000000002787363175065101), + (37.821637, -19, .000000000000000000000000000001054226381944797), + (37.821637, -18, .00000000000000000000000000003987256753373947), + (37.821637, -17, .000000000000000000000000001508045775519079), + (37.821637, -16, .00000000000000000000000005703675990106610), + (37.821637, -15, .000000000000000000000002157223628634278), + (37.821637, -14, .00000000000000000000008158972901002847), + (37.821637, -13, .000000000000000000003085857113545666), + (37.821637, -12, .0000000000000000001167121675823920), + (37.821637, -11, .000000000000000004414245235784397), (37.821637, -10, .0000000000000001669539809368169), (37.821637, -9, .000000000000006314472862697207), (37.821637, -8, .0000000000002388237004592846), @@ -3724,24 +3618,10 @@ as ( (37.821637, 14, 12256444679171401239980.310926), (37.821637, 15, 463558801566202198479885.206986), (37.821637, 16, 17532552720991931019508170.100286), - ( - 37.821637, 17, 663109844696719094948877928.067252 - ), - ( - 37.821637, - 18, - 25079899837245684700124994552.671731 - ), - ( - 37.821637, - 19, - 948562867640665366544581398598.127577 - ), - ( - 37.821637, - 20, - 35876200451584291931921101974730.690104 - ) + (37.821637, 17, 663109844696719094948877928.067252), + (37.821637, 18, 25079899837245684700124994552.671731), + (37.821637, 19, 948562867640665366544581398598.127577), + (37.821637, 20, 35876200451584291931921101974730.690104) ) select b, @@ -3753,47 +3633,17 @@ from t; with -t (b, -p, -bc_result) +t (b, p, bc_result) as ( values - ( - 0.06933247, - -20.342987, - 379149253615977128356318.39406340 - ), - ( - 0.06933247, - -19.342987, - 26287354251852125772450.59436685 - ), - ( - 0.06933247, - -18.342987, - 1822567200045909954554.65766042 - ), - ( - 0.06933247, - -17.342987, - 126363085720167050546.86216560 - ), - ( - 0.06933247, - -16.342987, - 8761064849800910427.02880469 - ), - ( - 0.06933247, - -15.342987, - 607426265866876128.15466179 - ), - ( - 0.06933247, -14.342987, 42114363355427213.14899924 - ), - ( - 0.06933247, -13.342987, 2919892833909256.59283660 - ), + (0.06933247, -20.342987, 379149253615977128356318.39406340), + (0.06933247, -19.342987, 26287354251852125772450.59436685), + (0.06933247, -18.342987, 1822567200045909954554.65766042), + (0.06933247, -17.342987, 126363085720167050546.86216560), + (0.06933247, -16.342987, 8761064849800910427.02880469), + (0.06933247, -15.342987, 607426265866876128.15466179), + (0.06933247, -14.342987, 42114363355427213.14899924), + (0.06933247, -13.342987, 2919892833909256.59283660), (0.06933247, -12.342987, 202443382310228.51544515), (0.06933247, -11.342987, 14035899730722.44924025), (0.06933247, -10.342987, 973143597003.32229028), @@ -3815,64 +3665,18 @@ as ( (0.06933247, 6.342987, .00000004447094732199898), (0.06933247, 7.342987, .000000003083280621074075), (0.06933247, 8.342987, .0000000002137714611621997), - ( - 0.06933247, 9.342987, .00000000001482130341788437 - ), - ( - 0.06933247, - 10.342987, - .000000000001027597574581366 - ), - ( - 0.06933247, - 11.342987, - .00000000000007124587801173530 - ), - ( - 0.06933247, - 12.342987, - .000000000000004939652699872298 - ), - ( - 0.06933247, - 13.342987, - .0000000000000003424783226243151 - ), - ( - 0.06933247, - 14.342987, - .00000000000000002374486802900065 - ), - ( - 0.06933247, - 15.342987, - .000000000000000001646290350274646 - ), - ( - 0.06933247, - 16.342987, - .0000000000000000001141413763217064 - ), - ( - 0.06933247, - 17.342987, - .000000000000000000007913703549583420 - ), - ( - 0.06933247, - 18.342987, - .0000000000000000000005486766139403860 - ), - ( - 0.06933247, - 19.342987, - .00000000000000000000003804110487572339 - ), - ( - 0.06933247, - 20.342987, - .000000000000000000000002637483762562946 - ) + (0.06933247, 9.342987, .00000000001482130341788437), + (0.06933247, 10.342987, .000000000001027597574581366), + (0.06933247, 11.342987, .00000000000007124587801173530), + (0.06933247, 12.342987, .000000000000004939652699872298), + (0.06933247, 13.342987, .0000000000000003424783226243151), + (0.06933247, 14.342987, .00000000000000002374486802900065), + (0.06933247, 15.342987, .000000000000000001646290350274646), + (0.06933247, 16.342987, .0000000000000000001141413763217064), + (0.06933247, 17.342987, .000000000000000000007913703549583420), + (0.06933247, 18.342987, .0000000000000000000005486766139403860), + (0.06933247, 19.342987, .00000000000000000000003804110487572339), + (0.06933247, 20.342987, .000000000000000000000002637483762562946) ) select b, @@ -3884,77 +3688,23 @@ from t; with -t (b, -p, -bc_result) +t (b, p, bc_result) as ( values - ( - 27.234987, - -20.230957, - .000000000000000000000000000009247064512095633 - ), - ( - 27.234987, - -19.230957, - .0000000000000000000000000002518436817750859 - ), - ( - 27.234987, - -18.230957, - .000000000000000000000000006858959399176602 - ), - ( - 27.234987, - -17.230957, - .0000000000000000000000001868036700701026 - ), - ( - 27.234987, - -16.230957, - .000000000000000000000005087595525911532 - ), - ( - 27.234987, - -15.230957, - .0000000000000000000001385605980094587 - ), - ( - 27.234987, - -14.230957, - .000000000000000000003773696085499835 - ), - ( - 27.234987, - -13.230957, - .0000000000000000001027765638305389 - ), - ( - 27.234987, - -12.230957, - .000000000000000002799118379829397 - ), - ( - 27.234987, - -11.230957, - .00000000000000007623395268611469 - ), - ( - 27.234987, - -10.230957, - .000000000000002076230710364949 - ), - ( - 27.234987, - -9.230957, - .00000000000005654611640579014 - ), - ( - 27.234987, -8.230957, .000000000001540032745212181 - ), - ( - 27.234987, -7.230957, .00000000004194277179542807 - ), + (27.234987, -20.230957, .000000000000000000000000000009247064512095633), + (27.234987, -19.230957, .0000000000000000000000000002518436817750859), + (27.234987, -18.230957, .000000000000000000000000006858959399176602), + (27.234987, -17.230957, .0000000000000000000000001868036700701026), + (27.234987, -16.230957, .000000000000000000000005087595525911532), + (27.234987, -15.230957, .0000000000000000000001385605980094587), + (27.234987, -14.230957, .000000000000000000003773696085499835), + (27.234987, -13.230957, .0000000000000000001027765638305389), + (27.234987, -12.230957, .000000000000000002799118379829397), + (27.234987, -11.230957, .00000000000000007623395268611469), + (27.234987, -10.230957, .000000000000002076230710364949), + (27.234987, -9.230957, .00000000000005654611640579014), + (27.234987, -8.230957, .000000000001540032745212181), + (27.234987, -7.230957, .00000000004194277179542807), (27.234987, -6.230957, .000000001142310844592450), (27.234987, -5.230957, .00000003111082100243440), (27.234987, -4.230957, .0000008473028055606278), @@ -3975,39 +3725,13 @@ as ( (27.234987, 11.230957, 13117514765597885.614921), (27.234987, 12.230957, 357255344113366461.949871), (27.234987, 13.230957, 9729844652608062117.440722), - ( - 27.234987, 14.230957, 264992192625800087863.690528 - ), - ( - 27.234987, - 15.230957, - 7217058921265161257566.469315 - ), - ( - 27.234987, - 16.230957, - 196556505898890690402726.443417 - ), - ( - 27.234987, - 17.230957, - 5353213882921711267539279.451015 - ), - ( - 27.234987, - 18.230957, - 145794710509592328389185797.837767 - ), - ( - 27.234987, - 19.230957, - 3970717045397510438979206144.696206 - ), - ( - 27.234987, - 20.230957, - 108142427112079606637962972621.121293 - ) + (27.234987, 14.230957, 264992192625800087863.690528), + (27.234987, 15.230957, 7217058921265161257566.469315), + (27.234987, 16.230957, 196556505898890690402726.443417), + (27.234987, 17.230957, 5353213882921711267539279.451015), + (27.234987, 18.230957, 145794710509592328389185797.837767), + (27.234987, 19.230957, 3970717045397510438979206144.696206), + (27.234987, 20.230957, 108142427112079606637962972621.121293) ) select b, @@ -4019,9 +3743,7 @@ from t; with -t (b, -p, -bc_result) +t (b, p, bc_result) as ( values ( @@ -4045,8 +3767,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values (-20.29837, .000000001529431101152222), @@ -4100,8 +3821,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e-1', -2.3025850929940457), @@ -4136,36 +3856,14 @@ as ( ('1.0e-30', -69.0775527898213705205397436405309), ('1.0e-31', -71.38013788281541620455773509521529), ('1.0e-32', -73.682722975809461888575726549899655), - ( - '1.0e-33', -75.9853080688035075725937180045840189 - ), - ( - '1.0e-34', -78.28789316179755325661170945926838306 - ), - ( - '1.0e-35', - -80.590478254791598940629700913952747266 - ), - ( - '1.0e-36', - -82.8930633477856446246476923686371114736 - ), - ( - '1.0e-37', - -85.19564844077969030866568382332147568124 - ), - ( - '1.0e-38', - -87.498233533773735992683675278005839888842 - ), - ( - '1.0e-39', - -89.8008186267677816767016667326902040964430 - ), - ( - '1.0e-40', - -92.10340371976182736071965818737456830404406 - ) + ('1.0e-33', -75.9853080688035075725937180045840189), + ('1.0e-34', -78.28789316179755325661170945926838306), + ('1.0e-35', -80.590478254791598940629700913952747266), + ('1.0e-36', -82.8930633477856446246476923686371114736), + ('1.0e-37', -85.19564844077969030866568382332147568124), + ('1.0e-38', -87.498233533773735992683675278005839888842), + ('1.0e-39', -89.8008186267677816767016667326902040964430), + ('1.0e-40', -92.10340371976182736071965818737456830404406) ) select x, @@ -4176,8 +3874,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e-1', -.10536051565782630), @@ -4199,88 +3896,27 @@ as ( ('1.0e-17', -.000000000000000010000000000000000), ('1.0e-18', -.0000000000000000010000000000000000), ('1.0e-19', -.00000000000000000010000000000000000), - ( - '1.0e-20', -.000000000000000000010000000000000000 - ), - ( - '1.0e-21', -.0000000000000000000010000000000000000 - ), - ( - '1.0e-22', - -.00000000000000000000010000000000000000 - ), - ( - '1.0e-23', - -.000000000000000000000010000000000000000 - ), - ( - '1.0e-24', - -.0000000000000000000000010000000000000000 - ), - ( - '1.0e-25', - -.00000000000000000000000010000000000000000 - ), - ( - '1.0e-26', - -.000000000000000000000000010000000000000000 - ), - ( - '1.0e-27', - -.0000000000000000000000000010000000000000000 - ), - ( - '1.0e-28', - -.00000000000000000000000000010000000000000000 - ), - ( - '1.0e-29', - -.000000000000000000000000000010000000000000000 - ), - ( - '1.0e-30', - -.0000000000000000000000000000010000000000000000 - ), - ( - '1.0e-31', - -.00000000000000000000000000000010000000000000000 - ), - ( - '1.0e-32', - -.000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-33', - -.0000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-34', - -.00000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-35', - -.000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-36', - -.0000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-37', - -.00000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-38', - -.000000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-39', - -.0000000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-40', - -.00000000000000000000000000000000000000010000000000000000 - ) + ('1.0e-20', -.000000000000000000010000000000000000), + ('1.0e-21', -.0000000000000000000010000000000000000), + ('1.0e-22', -.00000000000000000000010000000000000000), + ('1.0e-23', -.000000000000000000000010000000000000000), + ('1.0e-24', -.0000000000000000000000010000000000000000), + ('1.0e-25', -.00000000000000000000000010000000000000000), + ('1.0e-26', -.000000000000000000000000010000000000000000), + ('1.0e-27', -.0000000000000000000000000010000000000000000), + ('1.0e-28', -.00000000000000000000000000010000000000000000), + ('1.0e-29', -.000000000000000000000000000010000000000000000), + ('1.0e-30', -.0000000000000000000000000000010000000000000000), + ('1.0e-31', -.00000000000000000000000000000010000000000000000), + ('1.0e-32', -.000000000000000000000000000000010000000000000000), + ('1.0e-33', -.0000000000000000000000000000000010000000000000000), + ('1.0e-34', -.00000000000000000000000000000000010000000000000000), + ('1.0e-35', -.000000000000000000000000000000000010000000000000000), + ('1.0e-36', -.0000000000000000000000000000000000010000000000000000), + ('1.0e-37', -.00000000000000000000000000000000000010000000000000000), + ('1.0e-38', -.000000000000000000000000000000000000010000000000000000), + ('1.0e-39', -.0000000000000000000000000000000000000010000000000000000), + ('1.0e-40', -.00000000000000000000000000000000000000010000000000000000) ) select '1-' || x, @@ -4291,8 +3927,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e-1', .09531017980432486), @@ -4315,84 +3950,26 @@ as ( ('1.0e-18', .0000000000000000010000000000000000), ('1.0e-19', .00000000000000000010000000000000000), ('1.0e-20', .000000000000000000010000000000000000), - ( - '1.0e-21', .0000000000000000000010000000000000000 - ), - ( - '1.0e-22', .00000000000000000000010000000000000000 - ), - ( - '1.0e-23', - .000000000000000000000010000000000000000 - ), - ( - '1.0e-24', - .0000000000000000000000010000000000000000 - ), - ( - '1.0e-25', - .00000000000000000000000010000000000000000 - ), - ( - '1.0e-26', - .000000000000000000000000010000000000000000 - ), - ( - '1.0e-27', - .0000000000000000000000000010000000000000000 - ), - ( - '1.0e-28', - .00000000000000000000000000010000000000000000 - ), - ( - '1.0e-29', - .000000000000000000000000000010000000000000000 - ), - ( - '1.0e-30', - .0000000000000000000000000000010000000000000000 - ), - ( - '1.0e-31', - .00000000000000000000000000000010000000000000000 - ), - ( - '1.0e-32', - .000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-33', - .0000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-34', - .00000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-35', - .000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-36', - .0000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-37', - .00000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-38', - .000000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-39', - .0000000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-40', - .00000000000000000000000000000000000000010000000000000000 - ) + ('1.0e-21', .0000000000000000000010000000000000000), + ('1.0e-22', .00000000000000000000010000000000000000), + ('1.0e-23', .000000000000000000000010000000000000000), + ('1.0e-24', .0000000000000000000000010000000000000000), + ('1.0e-25', .00000000000000000000000010000000000000000), + ('1.0e-26', .000000000000000000000000010000000000000000), + ('1.0e-27', .0000000000000000000000000010000000000000000), + ('1.0e-28', .00000000000000000000000000010000000000000000), + ('1.0e-29', .000000000000000000000000000010000000000000000), + ('1.0e-30', .0000000000000000000000000000010000000000000000), + ('1.0e-31', .00000000000000000000000000000010000000000000000), + ('1.0e-32', .000000000000000000000000000000010000000000000000), + ('1.0e-33', .0000000000000000000000000000000010000000000000000), + ('1.0e-34', .00000000000000000000000000000000010000000000000000), + ('1.0e-35', .000000000000000000000000000000000010000000000000000), + ('1.0e-36', .0000000000000000000000000000000000010000000000000000), + ('1.0e-37', .00000000000000000000000000000000000010000000000000000), + ('1.0e-38', .000000000000000000000000000000000000010000000000000000), + ('1.0e-39', .0000000000000000000000000000000000000010000000000000000), + ('1.0e-40', .00000000000000000000000000000000000000010000000000000000) ) select '1+' || x, @@ -4403,8 +3980,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e1', 2.3025850929940457), @@ -4457,8 +4033,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e100', 230.25850929940457), @@ -4481,8 +4056,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ( @@ -4499,19 +4073,11 @@ as ( ) ) select - trim_scale(ln(cast(x as numeric)) - bc_result) - as diff + trim_scale(ln(cast(x as numeric)) - bc_result) as diff from t; -with -t (x) -as ( - select - '1e-' || n - from - generate_series(1, 100) as g (n) -) +with t (x) as (select '1e-' || n from generate_series(1, 100) as g (n)) select x, log(cast(x as numeric)) @@ -4519,8 +4085,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('9.0e-1', -.04575749056067513), @@ -4538,42 +4103,15 @@ as ( ('9.0e-29', -28.045757490560675125409944193490), ('6.0e-29', -28.221848749616356367491233202020), ('3.0e-29', -28.522878745280337562704972096745), - ( - '9.0e-36', - -35.0457574905606751254099441934897693816 - ), - ( - '6.0e-36', - -35.2218487496163563674912332020203916640 - ), - ( - '3.0e-36', - -35.5228787452803375627049720967448846908 - ), - ( - '9.0e-43', - -42.04575749056067512540994419348976938159974227 - ), - ( - '6.0e-43', - -42.22184874961635636749123320202039166403168125 - ), - ( - '3.0e-43', - -42.52287874528033756270497209674488469079987114 - ), - ( - '9.0e-50', - -49.045757490560675125409944193489769381599742271618608 - ), - ( - '6.0e-50', - -49.221848749616356367491233202020391664031681254347196 - ), - ( - '3.0e-50', - -49.522878745280337562704972096744884690799871135809304 - ) + ('9.0e-36', -35.0457574905606751254099441934897693816), + ('6.0e-36', -35.2218487496163563674912332020203916640), + ('3.0e-36', -35.5228787452803375627049720967448846908), + ('9.0e-43', -42.04575749056067512540994419348976938159974227), + ('6.0e-43', -42.22184874961635636749123320202039166403168125), + ('3.0e-43', -42.52287874528033756270497209674488469079987114), + ('9.0e-50', -49.045757490560675125409944193489769381599742271618608), + ('6.0e-50', -49.221848749616356367491233202020391664031681254347196), + ('3.0e-50', -49.522878745280337562704972096744884690799871135809304) ) select x, @@ -4584,8 +4122,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('9.0e-1', -1.0000000000000000), @@ -4597,42 +4134,15 @@ as ( ('9.0e-15', -.0000000000000039086503371292840), ('6.0e-15', -.0000000000000026057668914195188), ('3.0e-15', -.0000000000000013028834457097574), - ( - '9.0e-22', - -.00000000000000000000039086503371292664 - ), - ( - '6.0e-22', - -.00000000000000000000026057668914195110 - ), - ( - '3.0e-22', - -.00000000000000000000013028834457097555 - ), - ( - '9.0e-29', - -.000000000000000000000000000039086503371292664 - ), - ( - '6.0e-29', - -.000000000000000000000000000026057668914195110 - ), - ( - '3.0e-29', - -.000000000000000000000000000013028834457097555 - ), - ( - '9.0e-36', - -.0000000000000000000000000000000000039086503371292664 - ), - ( - '6.0e-36', - -.0000000000000000000000000000000000026057668914195110 - ), - ( - '3.0e-36', - -.0000000000000000000000000000000000013028834457097555 - ) + ('9.0e-22', -.00000000000000000000039086503371292664), + ('6.0e-22', -.00000000000000000000026057668914195110), + ('3.0e-22', -.00000000000000000000013028834457097555), + ('9.0e-29', -.000000000000000000000000000039086503371292664), + ('6.0e-29', -.000000000000000000000000000026057668914195110), + ('3.0e-29', -.000000000000000000000000000013028834457097555), + ('9.0e-36', -.0000000000000000000000000000000000039086503371292664), + ('6.0e-36', -.0000000000000000000000000000000000026057668914195110), + ('3.0e-36', -.0000000000000000000000000000000000013028834457097555) ) select '1-' || x, @@ -4643,8 +4153,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('9.0e-1', .2787536009528290), @@ -4656,39 +4165,15 @@ as ( ('9.0e-15', .0000000000000039086503371292489), ('6.0e-15', .0000000000000026057668914195031), ('3.0e-15', .0000000000000013028834457097535), - ( - '9.0e-22', .00000000000000000000039086503371292664 - ), - ( - '6.0e-22', .00000000000000000000026057668914195110 - ), - ( - '3.0e-22', .00000000000000000000013028834457097555 - ), - ( - '9.0e-29', - .000000000000000000000000000039086503371292664 - ), - ( - '6.0e-29', - .000000000000000000000000000026057668914195110 - ), - ( - '3.0e-29', - .000000000000000000000000000013028834457097555 - ), - ( - '9.0e-36', - .0000000000000000000000000000000000039086503371292664 - ), - ( - '6.0e-36', - .0000000000000000000000000000000000026057668914195110 - ), - ( - '3.0e-36', - .0000000000000000000000000000000000013028834457097555 - ) + ('9.0e-22', .00000000000000000000039086503371292664), + ('6.0e-22', .00000000000000000000026057668914195110), + ('3.0e-22', .00000000000000000000013028834457097555), + ('9.0e-29', .000000000000000000000000000039086503371292664), + ('6.0e-29', .000000000000000000000000000026057668914195110), + ('3.0e-29', .000000000000000000000000000013028834457097555), + ('9.0e-36', .0000000000000000000000000000000000039086503371292664), + ('6.0e-36', .0000000000000000000000000000000000026057668914195110), + ('3.0e-36', .0000000000000000000000000000000000013028834457097555) ) select '1+' || x, @@ -4698,14 +4183,7 @@ select from t; -with -t (x) -as ( - select - '1e' || n - from - generate_series(1, 100) as g (n) -) +with t (x) as (select '1e' || n from generate_series(1, 100) as g (n)) select x, log(cast(x as numeric)) @@ -4713,8 +4191,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('2.0e10', 10.301029995663981), diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_big_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_big_80.snap index c6b4c4fe4..a2f3e640f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_big_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numeric_big_80.snap @@ -24,57 +24,57 @@ drop table num_exp_power_10_ln; drop table num_result; create table num_data ( - id int, + id int4, val numeric(1000, 800) ); create table num_exp_add ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(1000, 800) ); create table num_exp_sub ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(1000, 800) ); create table num_exp_div ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(1000, 800) ); create table num_exp_mul ( - id1 int, - id2 int, + id1 int4, + id2 int4, expected numeric(1000, 800) ); create table num_exp_sqrt ( - id int, + id int4, expected numeric(1000, 800) ); create table num_exp_ln ( - id int, + id int4, expected numeric(1000, 800) ); create table num_exp_log10 ( - id int, + id int4, expected numeric(1000, 800) ); create table num_exp_power_10_ln ( - id int, + id int4, expected numeric(1000, 800) ); create table num_result ( - id1 int, - id2 int, + id1 int4, + id2 int4, result numeric(1000, 800) ); @@ -3292,54 +3292,44 @@ values commit; -create unique index "num_exp_add_idx" on num_exp_add using btree (id1, id2); +create unique index num_exp_add_idx on num_exp_add using btree (id1, id2); -create unique index "num_exp_sub_idx" on num_exp_sub using btree (id1, id2); +create unique index num_exp_sub_idx on num_exp_sub using btree (id1, id2); -create unique index "num_exp_div_idx" on num_exp_div using btree (id1, id2); +create unique index num_exp_div_idx on num_exp_div using btree (id1, id2); -create unique index "num_exp_mul_idx" on num_exp_mul using btree (id1, id2); +create unique index num_exp_mul_idx on num_exp_mul using btree (id1, id2); -create unique index "num_exp_sqrt_idx" on num_exp_sqrt using btree (id); +create unique index num_exp_sqrt_idx on num_exp_sqrt using btree (id); -create unique index "num_exp_ln_idx" on num_exp_ln using btree (id); +create unique index num_exp_ln_idx on num_exp_ln using btree (id); -create unique index "num_exp_log10_idx" on num_exp_log10 using btree (id); +create unique index num_exp_log10_idx on num_exp_log10 using btree (id); -create unique -index "num_exp_power_10_ln_idx" -on num_exp_power_10_ln -using btree -( +create unique index num_exp_power_10_ln_idx on num_exp_power_10_ln using btree ( id ); -vacuum (ANALYZE) num_exp_add; +vacuum (analyze) num_exp_add; -vacuum (ANALYZE) num_exp_sub; +vacuum (analyze) num_exp_sub; -vacuum (ANALYZE) num_exp_div; +vacuum (analyze) num_exp_div; -vacuum (ANALYZE) num_exp_mul; +vacuum (analyze) num_exp_mul; -vacuum (ANALYZE) num_exp_sqrt; +vacuum (analyze) num_exp_sqrt; -vacuum (ANALYZE) num_exp_ln; +vacuum (analyze) num_exp_ln; -vacuum (ANALYZE) num_exp_log10; +vacuum (analyze) num_exp_log10; -vacuum (ANALYZE) num_exp_power_10_ln; +vacuum (analyze) num_exp_power_10_ln; delete from num_result; insert into num_result -select - t1.id, - t2.id, - t1.val + t2.val -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, t1.val + t2.val from num_data as t1, num_data as t2; select t1.id1, @@ -3350,9 +3340,7 @@ from num_result as t1, num_exp_add as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -3374,20 +3362,12 @@ from num_result as t1, num_exp_add as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 10); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 10); delete from num_result; insert into num_result -select - t1.id, - t2.id, - t1.val - t2.val -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, t1.val - t2.val from num_data as t1, num_data as t2; select t1.id1, @@ -3398,9 +3378,7 @@ from num_result as t1, num_exp_sub as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -3422,20 +3400,12 @@ from num_result as t1, num_exp_sub as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 40); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 40); delete from num_result; insert into num_result -select - t1.id, - t2.id, - t1.val * t2.val -from - num_data as t1, - num_data as t2; +select t1.id, t2.id, t1.val * t2.val from num_data as t1, num_data as t2; select t1.id1, @@ -3446,9 +3416,7 @@ from num_result as t1, num_exp_mul as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -3470,9 +3438,7 @@ from num_result as t1, num_exp_mul as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 30); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 30); delete from num_result; @@ -3496,9 +3462,7 @@ from num_result as t1, num_exp_div as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> t2.expected; + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> t2.expected; delete from num_result; @@ -3522,9 +3486,7 @@ from num_result as t1, num_exp_div as t2 where - t1.id1 = t2.id1 and - t1.id2 = t2.id2 and - t1.result <> round(t2.expected, 80); + t1.id1 = t2.id1 and t1.id2 = t2.id2 and t1.result <> round(t2.expected, 80); delete from num_result; @@ -3538,20 +3500,12 @@ from num_result as t1, num_exp_sqrt as t2 where - t1.id1 = t2.id and - t1.result <> t2.expected; + t1.id1 = t2.id and t1.result <> t2.expected; delete from num_result; insert into num_result -select - id, - 0, - ln(abs(val)) -from - num_data -where - val <> '0.0'; +select id, 0, ln(abs(val)) from num_data where val <> '0.0'; select t1.id1, @@ -3561,8 +3515,7 @@ from num_result as t1, num_exp_ln as t2 where - t1.id1 = t2.id and - t1.result <> t2.expected; + t1.id1 = t2.id and t1.result <> t2.expected; delete from num_result; @@ -3584,8 +3537,7 @@ from num_result as t1, num_exp_log10 as t2 where - t1.id1 = t2.id and - t1.result <> t2.expected; + t1.id1 = t2.id and t1.result <> t2.expected; delete from num_result; @@ -3593,10 +3545,7 @@ insert into num_result select id, 0, - pow( - cast('10' as numeric), - ln(abs(round(val, 1000))) - ) + pow(cast('10' as numeric), ln(abs(round(val, 1000)))) from num_data where @@ -3610,41 +3559,18 @@ from num_result as t1, num_exp_power_10_ln as t2 where - t1.id1 = t2.id and - t1.result <> t2.expected; + t1.id1 = t2.id and t1.result <> t2.expected; with -t (b, -p, -bc_result) +t (b, p, bc_result) as ( values - ( - 0.084738, - -20, - 2744326694304960114888.785913 - ), - ( - 0.084738, - -19, - 232548755422013710215.445941 - ), - ( - 0.084738, - -18, - 19705716436950597776.236458 - ), - ( - 0.084738, - -17, - 1669822999434319754.362725 - ), - ( - 0.084738, -16, 141497461326065387.345189 - ), - ( - 0.084738, -15, 11990211877848128.792857 - ), + (0.084738, -20, 2744326694304960114888.785913), + (0.084738, -19, 232548755422013710215.445941), + (0.084738, -18, 19705716436950597776.236458), + (0.084738, -17, 1669822999434319754.362725), + (0.084738, -16, 141497461326065387.345189), + (0.084738, -15, 11990211877848128.792857), (0.084738, -14, 1016026574105094.737649), (0.084738, -13, 86096059836517.517879), (0.084738, -12, 7295607918426.821430), @@ -3668,64 +3594,18 @@ as ( (0.084738, 6, .0000003702279966206494), (0.084738, 7, .00000003137237997764059), (0.084738, 8, .000000002658432734545308), - ( - 0.084738, 9, .0000000002252702730599003 - ), - ( - 0.084738, - 10, - .00000000001908895239854983 - ), - ( - 0.084738, - 11, - .000000000001617559648348316 - ), - ( - 0.084738, - 12, - .0000000000001370687694817396 - ), - ( - 0.084738, - 13, - .00000000000001161493338834365 - ), - ( - 0.084738, - 14, - .0000000000000009842262254614642 - ), - ( - 0.084738, - 15, - .00000000000000008340136189315355 - ), - ( - 0.084738, - 16, - .000000000000000007067264604102046 - ), - ( - 0.084738, - 17, - .0000000000000000005988658680223991 - ), - ( - 0.084738, - 18, - .00000000000000000005074669592448206 - ), - ( - 0.084738, - 19, - .000000000000000000004300173519248761 - ), - ( - 0.084738, - 20, - .0000000000000000000003643881036741015 - ) + (0.084738, 9, .0000000002252702730599003), + (0.084738, 10, .00000000001908895239854983), + (0.084738, 11, .000000000001617559648348316), + (0.084738, 12, .0000000000001370687694817396), + (0.084738, 13, .00000000000001161493338834365), + (0.084738, 14, .0000000000000009842262254614642), + (0.084738, 15, .00000000000000008340136189315355), + (0.084738, 16, .000000000000000007067264604102046), + (0.084738, 17, .0000000000000000005988658680223991), + (0.084738, 18, .00000000000000000005074669592448206), + (0.084738, 19, .000000000000000000004300173519248761), + (0.084738, 20, .0000000000000000000003643881036741015) ) select b, @@ -3737,89 +3617,25 @@ from t; with -t (b, -p, -bc_result) +t (b, p, bc_result) as ( values - ( - 37.821637, - -20, - .00000000000000000000000000000002787363175065101 - ), - ( - 37.821637, - -19, - .000000000000000000000000000001054226381944797 - ), - ( - 37.821637, - -18, - .00000000000000000000000000003987256753373947 - ), - ( - 37.821637, - -17, - .000000000000000000000000001508045775519079 - ), - ( - 37.821637, - -16, - .00000000000000000000000005703675990106610 - ), - ( - 37.821637, - -15, - .000000000000000000000002157223628634278 - ), - ( - 37.821637, - -14, - .00000000000000000000008158972901002847 - ), - ( - 37.821637, - -13, - .000000000000000000003085857113545666 - ), - ( - 37.821637, - -12, - .0000000000000000001167121675823920 - ), - ( - 37.821637, - -11, - .000000000000000004414245235784397 - ), - ( - 37.821637, - -10, - .0000000000000001669539809368169 - ), - ( - 37.821637, - -9, - .000000000000006314472862697207 - ), - ( - 37.821637, - -8, - .0000000000002388237004592846 - ), - ( - 37.821637, - -7, - .000000000009032703305767796 - ), - ( - 37.821637, - -6, - .0000000003416316255594496 - ), - ( - 37.821637, -5, .00000001292106732962942 - ), + (37.821637, -20, .00000000000000000000000000000002787363175065101), + (37.821637, -19, .000000000000000000000000000001054226381944797), + (37.821637, -18, .00000000000000000000000000003987256753373947), + (37.821637, -17, .000000000000000000000000001508045775519079), + (37.821637, -16, .00000000000000000000000005703675990106610), + (37.821637, -15, .000000000000000000000002157223628634278), + (37.821637, -14, .00000000000000000000008158972901002847), + (37.821637, -13, .000000000000000000003085857113545666), + (37.821637, -12, .0000000000000000001167121675823920), + (37.821637, -11, .000000000000000004414245235784397), + (37.821637, -10, .0000000000000001669539809368169), + (37.821637, -9, .000000000000006314472862697207), + (37.821637, -8, .0000000000002388237004592846), + (37.821637, -7, .000000000009032703305767796), + (37.821637, -6, .0000000003416316255594496), + (37.821637, -5, .00000001292106732962942), (37.821637, -4, .0000004886959181938034), (37.821637, -3, .00001848327962130773), (37.821637, -2, .0006990678924065984), @@ -3835,472 +3651,126 @@ as ( (37.821637, 8, 4187189119324.792454), (37.821637, 9, 158366346921451.985294), (37.821637, 10, 5989674486279224.500736), - ( - 37.821637, 11, 226539294168214309.708325 - ), - ( - 37.821637, - 12, - 8568086950266418559.993831 - ), - ( - 37.821637, - 13, - 324059074417413536066.149409 - ), - ( - 37.821637, - 14, - 12256444679171401239980.310926 - ), - ( - 37.821637, - 15, - 463558801566202198479885.206986 - ), - ( - 37.821637, - 16, - 17532552720991931019508170.100286 - ), - ( - 37.821637, - 17, - 663109844696719094948877928.067252 - ), - ( - 37.821637, - 18, - 25079899837245684700124994552.671731 - ), - ( - 37.821637, - 19, - 948562867640665366544581398598.127577 - ), - ( - 37.821637, - 20, - 35876200451584291931921101974730.690104 - ) + (37.821637, 11, 226539294168214309.708325), + (37.821637, 12, 8568086950266418559.993831), + (37.821637, 13, 324059074417413536066.149409), + (37.821637, 14, 12256444679171401239980.310926), + (37.821637, 15, 463558801566202198479885.206986), + (37.821637, 16, 17532552720991931019508170.100286), + (37.821637, 17, 663109844696719094948877928.067252), + (37.821637, 18, 25079899837245684700124994552.671731), + (37.821637, 19, 948562867640665366544581398598.127577), + (37.821637, 20, 35876200451584291931921101974730.690104) ) select b, p, bc_result, b ^ p as power, - b ^ p - bc_result as diff -from - t; - -with -t (b, -p, -bc_result) -as ( - values - ( - 0.06933247, - -20.342987, - 379149253615977128356318.39406340 - ), - ( - 0.06933247, - -19.342987, - 26287354251852125772450.59436685 - ), - ( - 0.06933247, - -18.342987, - 1822567200045909954554.65766042 - ), - ( - 0.06933247, - -17.342987, - 126363085720167050546.86216560 - ), - ( - 0.06933247, - -16.342987, - 8761064849800910427.02880469 - ), - ( - 0.06933247, - -15.342987, - 607426265866876128.15466179 - ), - ( - 0.06933247, - -14.342987, - 42114363355427213.14899924 - ), - ( - 0.06933247, - -13.342987, - 2919892833909256.59283660 - ), - ( - 0.06933247, - -12.342987, - 202443382310228.51544515 - ), - ( - 0.06933247, - -11.342987, - 14035899730722.44924025 - ), - ( - 0.06933247, - -10.342987, - 973143597003.32229028 - ), - ( - 0.06933247, - -9.342987, - 67470449244.92493259 - ), - ( - 0.06933247, - -8.342987, - 4677892898.16028054 - ), - ( - 0.06933247, - -7.342987, - 324329869.02491071 - ), - ( - 0.06933247, - -6.342987, - 22486590.914273551 - ), - ( - 0.06933247, - -5.342987, - 1559050.8899661435 - ), - ( - 0.06933247, - -4.342987, - 108092.84905705095 - ), - ( - 0.06933247, - -3.342987, - 7494.3442144625131 - ), - ( - 0.06933247, - -2.342987, - 519.60139541889576 - ), - ( - 0.06933247, - -1.342987, - 36.025248159838727 - ), - ( - 0.06933247, 0.342987, .40036522320023350 - ), - ( - 0.06933247, 1.342987, .02775830982657349 - ), - ( - 0.06933247, - 2.342987, - .001924552183301612 - ), - ( - 0.06933247, - 3.342987, - .0001334339565121935 - ), - ( - 0.06933247, - 4.342987, - .000009251305786862961 - ), - ( - 0.06933247, - 5.342987, - .0000006414158809285026 - ), - ( - 0.06933247, - 6.342987, - .00000004447094732199898 - ), - ( - 0.06933247, - 7.342987, - .000000003083280621074075 - ), - ( - 0.06933247, - 8.342987, - .0000000002137714611621997 - ), - ( - 0.06933247, - 9.342987, - .00000000001482130341788437 - ), - ( - 0.06933247, - 10.342987, - .000000000001027597574581366 - ), - ( - 0.06933247, - 11.342987, - .00000000000007124587801173530 - ), - ( - 0.06933247, - 12.342987, - .000000000000004939652699872298 - ), - ( - 0.06933247, - 13.342987, - .0000000000000003424783226243151 - ), - ( - 0.06933247, - 14.342987, - .00000000000000002374486802900065 - ), - ( - 0.06933247, - 15.342987, - .000000000000000001646290350274646 - ), - ( - 0.06933247, - 16.342987, - .0000000000000000001141413763217064 - ), - ( - 0.06933247, - 17.342987, - .000000000000000000007913703549583420 - ), - ( - 0.06933247, - 18.342987, - .0000000000000000000005486766139403860 - ), - ( - 0.06933247, - 19.342987, - .00000000000000000000003804110487572339 - ), - ( - 0.06933247, - 20.342987, - .000000000000000000000002637483762562946 - ) -) -select - b, - p, - bc_result, - b ^ p as power, - b ^ p - bc_result as diff -from - t; - -with -t (b, -p, -bc_result) -as ( - values - ( - 27.234987, - -20.230957, - .000000000000000000000000000009247064512095633 - ), - ( - 27.234987, - -19.230957, - .0000000000000000000000000002518436817750859 - ), - ( - 27.234987, - -18.230957, - .000000000000000000000000006858959399176602 - ), - ( - 27.234987, - -17.230957, - .0000000000000000000000001868036700701026 - ), - ( - 27.234987, - -16.230957, - .000000000000000000000005087595525911532 - ), - ( - 27.234987, - -15.230957, - .0000000000000000000001385605980094587 - ), - ( - 27.234987, - -14.230957, - .000000000000000000003773696085499835 - ), - ( - 27.234987, - -13.230957, - .0000000000000000001027765638305389 - ), - ( - 27.234987, - -12.230957, - .000000000000000002799118379829397 - ), - ( - 27.234987, - -11.230957, - .00000000000000007623395268611469 - ), - ( - 27.234987, - -10.230957, - .000000000000002076230710364949 - ), - ( - 27.234987, - -9.230957, - .00000000000005654611640579014 - ), - ( - 27.234987, - -8.230957, - .000000000001540032745212181 - ), - ( - 27.234987, - -7.230957, - .00000000004194277179542807 - ), - ( - 27.234987, - -6.230957, - .000000001142310844592450 - ), - ( - 27.234987, - -5.230957, - .00000003111082100243440 - ), - ( - 27.234987, - -4.230957, - .0000008473028055606278 - ), - ( - 27.234987, - -3.230957, - .00002307628089450723 - ), - ( - 27.234987, - -2.230957, - .0006284822101702527 - ), - ( - 27.234987, -1.230957, .01711670482371810 - ), - ( - 27.234987, 0.230957, 2.1451253063142300 - ), - ( - 27.234987, 1.230957, 58.422459830839071 - ), - ( - 27.234987, 2.230957, 1591.1349340009243 - ), - ( - 27.234987, 3.230957, 43334.539242761031 - ), - ( - 27.234987, 4.230957, 1180215.6129275865 - ), - ( - 27.234987, 5.230957, 32143156.875279851 - ), - ( - 27.234987, 6.230957, 875418459.63720737 - ), - ( - 27.234987, 7.230957, 23842010367.779367 - ), - ( - 27.234987, 8.230957, 649336842420.336290 - ), - ( - 27.234987, - 9.230957, - 17684680461938.907402 - ), - ( - 27.234987, - 10.230957, - 481642042480060.137900 - ), - ( - 27.234987, - 11.230957, - 13117514765597885.614921 - ), - ( - 27.234987, - 12.230957, - 357255344113366461.949871 - ), - ( - 27.234987, - 13.230957, - 9729844652608062117.440722 - ), - ( - 27.234987, - 14.230957, - 264992192625800087863.690528 - ), - ( - 27.234987, - 15.230957, - 7217058921265161257566.469315 - ), - ( - 27.234987, - 16.230957, - 196556505898890690402726.443417 - ), - ( - 27.234987, - 17.230957, - 5353213882921711267539279.451015 - ), - ( - 27.234987, - 18.230957, - 145794710509592328389185797.837767 - ), - ( - 27.234987, - 19.230957, - 3970717045397510438979206144.696206 - ), - ( - 27.234987, - 20.230957, - 108142427112079606637962972621.121293 - ) + b ^ p - bc_result as diff +from + t; + +with +t (b, p, bc_result) +as ( + values + (0.06933247, -20.342987, 379149253615977128356318.39406340), + (0.06933247, -19.342987, 26287354251852125772450.59436685), + (0.06933247, -18.342987, 1822567200045909954554.65766042), + (0.06933247, -17.342987, 126363085720167050546.86216560), + (0.06933247, -16.342987, 8761064849800910427.02880469), + (0.06933247, -15.342987, 607426265866876128.15466179), + (0.06933247, -14.342987, 42114363355427213.14899924), + (0.06933247, -13.342987, 2919892833909256.59283660), + (0.06933247, -12.342987, 202443382310228.51544515), + (0.06933247, -11.342987, 14035899730722.44924025), + (0.06933247, -10.342987, 973143597003.32229028), + (0.06933247, -9.342987, 67470449244.92493259), + (0.06933247, -8.342987, 4677892898.16028054), + (0.06933247, -7.342987, 324329869.02491071), + (0.06933247, -6.342987, 22486590.914273551), + (0.06933247, -5.342987, 1559050.8899661435), + (0.06933247, -4.342987, 108092.84905705095), + (0.06933247, -3.342987, 7494.3442144625131), + (0.06933247, -2.342987, 519.60139541889576), + (0.06933247, -1.342987, 36.025248159838727), + (0.06933247, 0.342987, .40036522320023350), + (0.06933247, 1.342987, .02775830982657349), + (0.06933247, 2.342987, .001924552183301612), + (0.06933247, 3.342987, .0001334339565121935), + (0.06933247, 4.342987, .000009251305786862961), + (0.06933247, 5.342987, .0000006414158809285026), + (0.06933247, 6.342987, .00000004447094732199898), + (0.06933247, 7.342987, .000000003083280621074075), + (0.06933247, 8.342987, .0000000002137714611621997), + (0.06933247, 9.342987, .00000000001482130341788437), + (0.06933247, 10.342987, .000000000001027597574581366), + (0.06933247, 11.342987, .00000000000007124587801173530), + (0.06933247, 12.342987, .000000000000004939652699872298), + (0.06933247, 13.342987, .0000000000000003424783226243151), + (0.06933247, 14.342987, .00000000000000002374486802900065), + (0.06933247, 15.342987, .000000000000000001646290350274646), + (0.06933247, 16.342987, .0000000000000000001141413763217064), + (0.06933247, 17.342987, .000000000000000000007913703549583420), + (0.06933247, 18.342987, .0000000000000000000005486766139403860), + (0.06933247, 19.342987, .00000000000000000000003804110487572339), + (0.06933247, 20.342987, .000000000000000000000002637483762562946) +) +select + b, + p, + bc_result, + b ^ p as power, + b ^ p - bc_result as diff +from + t; + +with +t (b, p, bc_result) +as ( + values + (27.234987, -20.230957, .000000000000000000000000000009247064512095633), + (27.234987, -19.230957, .0000000000000000000000000002518436817750859), + (27.234987, -18.230957, .000000000000000000000000006858959399176602), + (27.234987, -17.230957, .0000000000000000000000001868036700701026), + (27.234987, -16.230957, .000000000000000000000005087595525911532), + (27.234987, -15.230957, .0000000000000000000001385605980094587), + (27.234987, -14.230957, .000000000000000000003773696085499835), + (27.234987, -13.230957, .0000000000000000001027765638305389), + (27.234987, -12.230957, .000000000000000002799118379829397), + (27.234987, -11.230957, .00000000000000007623395268611469), + (27.234987, -10.230957, .000000000000002076230710364949), + (27.234987, -9.230957, .00000000000005654611640579014), + (27.234987, -8.230957, .000000000001540032745212181), + (27.234987, -7.230957, .00000000004194277179542807), + (27.234987, -6.230957, .000000001142310844592450), + (27.234987, -5.230957, .00000003111082100243440), + (27.234987, -4.230957, .0000008473028055606278), + (27.234987, -3.230957, .00002307628089450723), + (27.234987, -2.230957, .0006284822101702527), + (27.234987, -1.230957, .01711670482371810), + (27.234987, 0.230957, 2.1451253063142300), + (27.234987, 1.230957, 58.422459830839071), + (27.234987, 2.230957, 1591.1349340009243), + (27.234987, 3.230957, 43334.539242761031), + (27.234987, 4.230957, 1180215.6129275865), + (27.234987, 5.230957, 32143156.875279851), + (27.234987, 6.230957, 875418459.63720737), + (27.234987, 7.230957, 23842010367.779367), + (27.234987, 8.230957, 649336842420.336290), + (27.234987, 9.230957, 17684680461938.907402), + (27.234987, 10.230957, 481642042480060.137900), + (27.234987, 11.230957, 13117514765597885.614921), + (27.234987, 12.230957, 357255344113366461.949871), + (27.234987, 13.230957, 9729844652608062117.440722), + (27.234987, 14.230957, 264992192625800087863.690528), + (27.234987, 15.230957, 7217058921265161257566.469315), + (27.234987, 16.230957, 196556505898890690402726.443417), + (27.234987, 17.230957, 5353213882921711267539279.451015), + (27.234987, 18.230957, 145794710509592328389185797.837767), + (27.234987, 19.230957, 3970717045397510438979206144.696206), + (27.234987, 20.230957, 108142427112079606637962972621.121293) ) select b, @@ -4312,9 +3782,7 @@ from t; with -t (b, -p, -bc_result) +t (b, p, bc_result) as ( values ( @@ -4338,8 +3806,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values (-20.29837, .000000001529431101152222), @@ -4393,8 +3860,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e-1', -2.3025850929940457), @@ -4419,89 +3885,35 @@ as ( ('1.0e-20', -46.051701859880913680360), ('1.0e-21', -48.3542869528749593643778), ('1.0e-22', -50.65687204586900504839581), - ( - '1.0e-23', -52.959457138863050732413803 - ), - ( - '1.0e-24', -55.2620422318570964164317949 - ), - ( - '1.0e-25', - -57.56462732485114210044978637 - ), - ( - '1.0e-26', - -59.867212417845187784467777822 - ), - ( - '1.0e-27', - -62.1697975108392334684857692765 - ), - ( - '1.0e-28', - -64.47238260383327915250376073116 - ), - ( - '1.0e-29', - -66.774967696827324836521752185847 - ), - ( - '1.0e-30', - -69.0775527898213705205397436405309 - ), - ( - '1.0e-31', - -71.38013788281541620455773509521529 - ), - ( - '1.0e-32', - -73.682722975809461888575726549899655 - ), - ( - '1.0e-33', - -75.9853080688035075725937180045840189 - ), - ( - '1.0e-34', - -78.28789316179755325661170945926838306 - ), - ( - '1.0e-35', - -80.590478254791598940629700913952747266 - ), - ( - '1.0e-36', - -82.8930633477856446246476923686371114736 - ), - ( - '1.0e-37', - -85.19564844077969030866568382332147568124 - ), - ( - '1.0e-38', - -87.498233533773735992683675278005839888842 - ), - ( - '1.0e-39', - -89.8008186267677816767016667326902040964430 - ), - ( - '1.0e-40', - -92.10340371976182736071965818737456830404406 - ) + ('1.0e-23', -52.959457138863050732413803), + ('1.0e-24', -55.2620422318570964164317949), + ('1.0e-25', -57.56462732485114210044978637), + ('1.0e-26', -59.867212417845187784467777822), + ('1.0e-27', -62.1697975108392334684857692765), + ('1.0e-28', -64.47238260383327915250376073116), + ('1.0e-29', -66.774967696827324836521752185847), + ('1.0e-30', -69.0775527898213705205397436405309), + ('1.0e-31', -71.38013788281541620455773509521529), + ('1.0e-32', -73.682722975809461888575726549899655), + ('1.0e-33', -75.9853080688035075725937180045840189), + ('1.0e-34', -78.28789316179755325661170945926838306), + ('1.0e-35', -80.590478254791598940629700913952747266), + ('1.0e-36', -82.8930633477856446246476923686371114736), + ('1.0e-37', -85.19564844077969030866568382332147568124), + ('1.0e-38', -87.498233533773735992683675278005839888842), + ('1.0e-39', -89.8008186267677816767016667326902040964430), + ('1.0e-40', -92.10340371976182736071965818737456830404406) ) select x, bc_result, ln(cast(x as numeric)), - ln(cast(x as numeric)) - bc_result - as diff + ln(cast(x as numeric)) - bc_result as diff from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e-1', -.10536051565782630), @@ -4513,141 +3925,48 @@ as ( ('1.0e-7', -.00000010000000500000033), ('1.0e-8', -.000000010000000050000000), ('1.0e-9', -.0000000010000000005000000), - ( - '1.0e-10', -.00000000010000000000500000 - ), - ( - '1.0e-11', -.000000000010000000000050000 - ), - ( - '1.0e-12', - -.0000000000010000000000005000 - ), - ( - '1.0e-13', - -.00000000000010000000000000500 - ), - ( - '1.0e-14', - -.000000000000010000000000000050 - ), - ( - '1.0e-15', - -.0000000000000010000000000000005 - ), - ( - '1.0e-16', - -.00000000000000010000000000000001 - ), - ( - '1.0e-17', - -.000000000000000010000000000000000 - ), - ( - '1.0e-18', - -.0000000000000000010000000000000000 - ), - ( - '1.0e-19', - -.00000000000000000010000000000000000 - ), - ( - '1.0e-20', - -.000000000000000000010000000000000000 - ), - ( - '1.0e-21', - -.0000000000000000000010000000000000000 - ), - ( - '1.0e-22', - -.00000000000000000000010000000000000000 - ), - ( - '1.0e-23', - -.000000000000000000000010000000000000000 - ), - ( - '1.0e-24', - -.0000000000000000000000010000000000000000 - ), - ( - '1.0e-25', - -.00000000000000000000000010000000000000000 - ), - ( - '1.0e-26', - -.000000000000000000000000010000000000000000 - ), - ( - '1.0e-27', - -.0000000000000000000000000010000000000000000 - ), - ( - '1.0e-28', - -.00000000000000000000000000010000000000000000 - ), - ( - '1.0e-29', - -.000000000000000000000000000010000000000000000 - ), - ( - '1.0e-30', - -.0000000000000000000000000000010000000000000000 - ), - ( - '1.0e-31', - -.00000000000000000000000000000010000000000000000 - ), - ( - '1.0e-32', - -.000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-33', - -.0000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-34', - -.00000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-35', - -.000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-36', - -.0000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-37', - -.00000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-38', - -.000000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-39', - -.0000000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-40', - -.00000000000000000000000000000000000000010000000000000000 - ) + ('1.0e-10', -.00000000010000000000500000), + ('1.0e-11', -.000000000010000000000050000), + ('1.0e-12', -.0000000000010000000000005000), + ('1.0e-13', -.00000000000010000000000000500), + ('1.0e-14', -.000000000000010000000000000050), + ('1.0e-15', -.0000000000000010000000000000005), + ('1.0e-16', -.00000000000000010000000000000001), + ('1.0e-17', -.000000000000000010000000000000000), + ('1.0e-18', -.0000000000000000010000000000000000), + ('1.0e-19', -.00000000000000000010000000000000000), + ('1.0e-20', -.000000000000000000010000000000000000), + ('1.0e-21', -.0000000000000000000010000000000000000), + ('1.0e-22', -.00000000000000000000010000000000000000), + ('1.0e-23', -.000000000000000000000010000000000000000), + ('1.0e-24', -.0000000000000000000000010000000000000000), + ('1.0e-25', -.00000000000000000000000010000000000000000), + ('1.0e-26', -.000000000000000000000000010000000000000000), + ('1.0e-27', -.0000000000000000000000000010000000000000000), + ('1.0e-28', -.00000000000000000000000000010000000000000000), + ('1.0e-29', -.000000000000000000000000000010000000000000000), + ('1.0e-30', -.0000000000000000000000000000010000000000000000), + ('1.0e-31', -.00000000000000000000000000000010000000000000000), + ('1.0e-32', -.000000000000000000000000000000010000000000000000), + ('1.0e-33', -.0000000000000000000000000000000010000000000000000), + ('1.0e-34', -.00000000000000000000000000000000010000000000000000), + ('1.0e-35', -.000000000000000000000000000000000010000000000000000), + ('1.0e-36', -.0000000000000000000000000000000000010000000000000000), + ('1.0e-37', -.00000000000000000000000000000000000010000000000000000), + ('1.0e-38', -.000000000000000000000000000000000000010000000000000000), + ('1.0e-39', -.0000000000000000000000000000000000000010000000000000000), + ('1.0e-40', -.00000000000000000000000000000000000000010000000000000000) ) select '1-' || x, bc_result, ln(1.0 - cast(x as numeric)), - ln(1.0 - cast(x as numeric)) - bc_result - as diff + ln(1.0 - cast(x as numeric)) - bc_result as diff from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e-1', .09531017980432486), @@ -4660,137 +3979,47 @@ as ( ('1.0e-8', .000000009999999950000000), ('1.0e-9', .0000000009999999995000000), ('1.0e-10', .00000000009999999999500000), - ( - '1.0e-11', .000000000009999999999950000 - ), - ( - '1.0e-12', .0000000000009999999999995000 - ), - ( - '1.0e-13', - .00000000000009999999999999500 - ), - ( - '1.0e-14', - .000000000000009999999999999950 - ), - ( - '1.0e-15', - .0000000000000009999999999999995 - ), - ( - '1.0e-16', - .00000000000000010000000000000000 - ), - ( - '1.0e-17', - .000000000000000010000000000000000 - ), - ( - '1.0e-18', - .0000000000000000010000000000000000 - ), - ( - '1.0e-19', - .00000000000000000010000000000000000 - ), - ( - '1.0e-20', - .000000000000000000010000000000000000 - ), - ( - '1.0e-21', - .0000000000000000000010000000000000000 - ), - ( - '1.0e-22', - .00000000000000000000010000000000000000 - ), - ( - '1.0e-23', - .000000000000000000000010000000000000000 - ), - ( - '1.0e-24', - .0000000000000000000000010000000000000000 - ), - ( - '1.0e-25', - .00000000000000000000000010000000000000000 - ), - ( - '1.0e-26', - .000000000000000000000000010000000000000000 - ), - ( - '1.0e-27', - .0000000000000000000000000010000000000000000 - ), - ( - '1.0e-28', - .00000000000000000000000000010000000000000000 - ), - ( - '1.0e-29', - .000000000000000000000000000010000000000000000 - ), - ( - '1.0e-30', - .0000000000000000000000000000010000000000000000 - ), - ( - '1.0e-31', - .00000000000000000000000000000010000000000000000 - ), - ( - '1.0e-32', - .000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-33', - .0000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-34', - .00000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-35', - .000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-36', - .0000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-37', - .00000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-38', - .000000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-39', - .0000000000000000000000000000000000000010000000000000000 - ), - ( - '1.0e-40', - .00000000000000000000000000000000000000010000000000000000 - ) + ('1.0e-11', .000000000009999999999950000), + ('1.0e-12', .0000000000009999999999995000), + ('1.0e-13', .00000000000009999999999999500), + ('1.0e-14', .000000000000009999999999999950), + ('1.0e-15', .0000000000000009999999999999995), + ('1.0e-16', .00000000000000010000000000000000), + ('1.0e-17', .000000000000000010000000000000000), + ('1.0e-18', .0000000000000000010000000000000000), + ('1.0e-19', .00000000000000000010000000000000000), + ('1.0e-20', .000000000000000000010000000000000000), + ('1.0e-21', .0000000000000000000010000000000000000), + ('1.0e-22', .00000000000000000000010000000000000000), + ('1.0e-23', .000000000000000000000010000000000000000), + ('1.0e-24', .0000000000000000000000010000000000000000), + ('1.0e-25', .00000000000000000000000010000000000000000), + ('1.0e-26', .000000000000000000000000010000000000000000), + ('1.0e-27', .0000000000000000000000000010000000000000000), + ('1.0e-28', .00000000000000000000000000010000000000000000), + ('1.0e-29', .000000000000000000000000000010000000000000000), + ('1.0e-30', .0000000000000000000000000000010000000000000000), + ('1.0e-31', .00000000000000000000000000000010000000000000000), + ('1.0e-32', .000000000000000000000000000000010000000000000000), + ('1.0e-33', .0000000000000000000000000000000010000000000000000), + ('1.0e-34', .00000000000000000000000000000000010000000000000000), + ('1.0e-35', .000000000000000000000000000000000010000000000000000), + ('1.0e-36', .0000000000000000000000000000000000010000000000000000), + ('1.0e-37', .00000000000000000000000000000000000010000000000000000), + ('1.0e-38', .000000000000000000000000000000000000010000000000000000), + ('1.0e-39', .0000000000000000000000000000000000000010000000000000000), + ('1.0e-40', .00000000000000000000000000000000000000010000000000000000) ) select '1+' || x, bc_result, ln(1.0 + cast(x as numeric)), - ln(1.0 + cast(x as numeric)) - bc_result - as diff + ln(1.0 + cast(x as numeric)) - bc_result as diff from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e1', 2.3025850929940457), @@ -4838,14 +4067,12 @@ select x, bc_result, ln(cast(x as numeric)), - ln(cast(x as numeric)) - bc_result - as diff + ln(cast(x as numeric)) - bc_result as diff from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('1.0e100', 230.25850929940457), @@ -4863,14 +4090,12 @@ select x, bc_result, ln(cast(x as numeric)), - ln(cast(x as numeric)) - bc_result - as diff + ln(cast(x as numeric)) - bc_result as diff from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ( @@ -4887,21 +4112,11 @@ as ( ) ) select - trim_scale( - ln(cast(x as numeric)) - bc_result - ) - as diff + trim_scale(ln(cast(x as numeric)) - bc_result) as diff from t; -with -t (x) -as ( - select - '1e-' || n - from - generate_series(1, 100) as g (n) -) +with t (x) as (select '1e-' || n from generate_series(1, 100) as g (n)) select x, log(cast(x as numeric)) @@ -4909,8 +4124,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('9.0e-1', -.04575749056067513), @@ -4925,67 +4139,29 @@ as ( ('9.0e-22', -21.04575749056067512540994), ('6.0e-22', -21.22184874961635636749123), ('3.0e-22', -21.52287874528033756270497), - ( - '9.0e-29', - -28.045757490560675125409944193490 - ), - ( - '6.0e-29', - -28.221848749616356367491233202020 - ), - ( - '3.0e-29', - -28.522878745280337562704972096745 - ), - ( - '9.0e-36', - -35.0457574905606751254099441934897693816 - ), - ( - '6.0e-36', - -35.2218487496163563674912332020203916640 - ), - ( - '3.0e-36', - -35.5228787452803375627049720967448846908 - ), - ( - '9.0e-43', - -42.04575749056067512540994419348976938159974227 - ), - ( - '6.0e-43', - -42.22184874961635636749123320202039166403168125 - ), - ( - '3.0e-43', - -42.52287874528033756270497209674488469079987114 - ), - ( - '9.0e-50', - -49.045757490560675125409944193489769381599742271618608 - ), - ( - '6.0e-50', - -49.221848749616356367491233202020391664031681254347196 - ), - ( - '3.0e-50', - -49.522878745280337562704972096744884690799871135809304 - ) + ('9.0e-29', -28.045757490560675125409944193490), + ('6.0e-29', -28.221848749616356367491233202020), + ('3.0e-29', -28.522878745280337562704972096745), + ('9.0e-36', -35.0457574905606751254099441934897693816), + ('6.0e-36', -35.2218487496163563674912332020203916640), + ('3.0e-36', -35.5228787452803375627049720967448846908), + ('9.0e-43', -42.04575749056067512540994419348976938159974227), + ('6.0e-43', -42.22184874961635636749123320202039166403168125), + ('3.0e-43', -42.52287874528033756270497209674488469079987114), + ('9.0e-50', -49.045757490560675125409944193489769381599742271618608), + ('6.0e-50', -49.221848749616356367491233202020391664031681254347196), + ('3.0e-50', -49.522878745280337562704972096744884690799871135809304) ) select x, bc_result, log(cast(x as numeric)), - log(cast(x as numeric)) - bc_result - as diff + log(cast(x as numeric)) - bc_result as diff from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('9.0e-1', -1.0000000000000000), @@ -4994,68 +4170,29 @@ as ( ('9.0e-8', -.000000039086505130185422), ('6.0e-8', -.000000026057669695925208), ('3.0e-8', -.000000013028834652530076), - ( - '9.0e-15', - -.0000000000000039086503371292840 - ), - ( - '6.0e-15', - -.0000000000000026057668914195188 - ), - ( - '3.0e-15', - -.0000000000000013028834457097574 - ), - ( - '9.0e-22', - -.00000000000000000000039086503371292664 - ), - ( - '6.0e-22', - -.00000000000000000000026057668914195110 - ), - ( - '3.0e-22', - -.00000000000000000000013028834457097555 - ), - ( - '9.0e-29', - -.000000000000000000000000000039086503371292664 - ), - ( - '6.0e-29', - -.000000000000000000000000000026057668914195110 - ), - ( - '3.0e-29', - -.000000000000000000000000000013028834457097555 - ), - ( - '9.0e-36', - -.0000000000000000000000000000000000039086503371292664 - ), - ( - '6.0e-36', - -.0000000000000000000000000000000000026057668914195110 - ), - ( - '3.0e-36', - -.0000000000000000000000000000000000013028834457097555 - ) + ('9.0e-15', -.0000000000000039086503371292840), + ('6.0e-15', -.0000000000000026057668914195188), + ('3.0e-15', -.0000000000000013028834457097574), + ('9.0e-22', -.00000000000000000000039086503371292664), + ('6.0e-22', -.00000000000000000000026057668914195110), + ('3.0e-22', -.00000000000000000000013028834457097555), + ('9.0e-29', -.000000000000000000000000000039086503371292664), + ('6.0e-29', -.000000000000000000000000000026057668914195110), + ('3.0e-29', -.000000000000000000000000000013028834457097555), + ('9.0e-36', -.0000000000000000000000000000000000039086503371292664), + ('6.0e-36', -.0000000000000000000000000000000000026057668914195110), + ('3.0e-36', -.0000000000000000000000000000000000013028834457097555) ) select '1-' || x, bc_result, log(1.0 - cast(x as numeric)), - log(1.0 - cast(x as numeric)) - - bc_result - as diff + log(1.0 - cast(x as numeric)) - bc_result as diff from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('9.0e-1', .2787536009528290), @@ -5064,73 +4201,28 @@ as ( ('9.0e-8', .000000039086501612400118), ('6.0e-8', .000000026057668132465074), ('3.0e-8', .000000013028834261665042), - ( - '9.0e-15', - .0000000000000039086503371292489 - ), - ( - '6.0e-15', - .0000000000000026057668914195031 - ), - ( - '3.0e-15', - .0000000000000013028834457097535 - ), - ( - '9.0e-22', - .00000000000000000000039086503371292664 - ), - ( - '6.0e-22', - .00000000000000000000026057668914195110 - ), - ( - '3.0e-22', - .00000000000000000000013028834457097555 - ), - ( - '9.0e-29', - .000000000000000000000000000039086503371292664 - ), - ( - '6.0e-29', - .000000000000000000000000000026057668914195110 - ), - ( - '3.0e-29', - .000000000000000000000000000013028834457097555 - ), - ( - '9.0e-36', - .0000000000000000000000000000000000039086503371292664 - ), - ( - '6.0e-36', - .0000000000000000000000000000000000026057668914195110 - ), - ( - '3.0e-36', - .0000000000000000000000000000000000013028834457097555 - ) + ('9.0e-15', .0000000000000039086503371292489), + ('6.0e-15', .0000000000000026057668914195031), + ('3.0e-15', .0000000000000013028834457097535), + ('9.0e-22', .00000000000000000000039086503371292664), + ('6.0e-22', .00000000000000000000026057668914195110), + ('3.0e-22', .00000000000000000000013028834457097555), + ('9.0e-29', .000000000000000000000000000039086503371292664), + ('6.0e-29', .000000000000000000000000000026057668914195110), + ('3.0e-29', .000000000000000000000000000013028834457097555), + ('9.0e-36', .0000000000000000000000000000000000039086503371292664), + ('6.0e-36', .0000000000000000000000000000000000026057668914195110), + ('3.0e-36', .0000000000000000000000000000000000013028834457097555) ) select '1+' || x, bc_result, log(1.0 + cast(x as numeric)), - log(1.0 + cast(x as numeric)) - - bc_result - as diff + log(1.0 + cast(x as numeric)) - bc_result as diff from t; -with -t (x) -as ( - select - '1e' || n - from - generate_series(1, 100) as g (n) -) +with t (x) as (select '1e' || n from generate_series(1, 100) as g (n)) select x, log(cast(x as numeric)) @@ -5138,8 +4230,7 @@ from t; with -t (x, -bc_result) +t (x, bc_result) as ( values ('2.0e10', 10.301029995663981), @@ -5165,7 +4256,6 @@ select x, bc_result, log(cast(x as numeric)), - log(cast(x as numeric)) - bc_result - as diff + log(cast(x as numeric)) - bc_result as diff from t; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numerology_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numerology_100.snap index 4556b5c29..117a894c3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numerology_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numerology_100.snap @@ -78,22 +78,20 @@ select .000_005; select 1_000.5e0_1; -do -$do$ +do $$ DECLARE i int; BEGIN FOR i IN 1_001..1_003 LOOP RAISE NOTICE 'i = %', i; END LOOP; -END -$do$; +END $$; select _100; prepare p1 as select $0 as _1;; -create table temp_float (f1 double precision); +create table temp_float (f1 float8); insert into temp_float (f1) select float8(f1) from int4_tbl; @@ -101,21 +99,16 @@ insert into temp_float (f1) select float8(f1) from int2_tbl; select f1 from temp_float order by f1; -create table temp_int4 (f1 int); +create table temp_int4 (f1 int4); insert into temp_int4 (f1) -select - int4(f1) -from - float8_tbl -where - f1 > -2147483647 and f1 < 2147483647; +select int4(f1) from float8_tbl where f1 > -2147483647 and f1 < 2147483647; insert into temp_int4 (f1) select int4(f1) from int2_tbl; select f1 from temp_int4 order by f1; -create table temp_int2 (f1 smallint); +create table temp_int2 (f1 int2); insert into temp_int2 (f1) select int2(f1) from float8_tbl where f1 >= -32767 and f1 <= 32767; @@ -124,9 +117,9 @@ insert into temp_int2 (f1) select int2(f1) from int4_tbl where f1 >= -32767 and select f1 from temp_int2 order by f1; create table temp_group ( - f1 int, - f2 int, - f3 double precision + f1 int4, + f2 int4, + f3 float8 ); insert into temp_group select 1, -i.f1, -f.f1 from int4_tbl as i, float8_tbl as f; @@ -137,8 +130,8 @@ select distinct f1 as two from temp_group order by 1; select f1 as two, - MAX(f3) as max_float, - MIN(f3) as min_float + max(f3) as max_float, + min(f3) as min_float from temp_group group by f1 @@ -148,8 +141,8 @@ order by two, select f1 as two, - MAX(f3) as max_float, - MIN(f3) as min_float + max(f3) as max_float, + min(f3) as min_float from temp_group group by two @@ -159,8 +152,8 @@ order by two, select f1 as two, - MAX(f3) + 1 as max_plus_1, - MIN(f3) - 1 as min_minus_1 + max(f3) + 1 as max_plus_1, + min(f3) - 1 as min_minus_1 from temp_group group by f1 @@ -169,8 +162,8 @@ order by two, select f1 as two, - MAX(f2) + MIN(f2) as max_plus_min, - MIN(f3) - 1 as min_minus_1 + max(f2) + min(f2) as max_plus_min, + min(f3) - 1 as min_minus_1 from temp_group group by f1 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numerology_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numerology_80.snap index dde4c0acf..36c867211 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__numerology_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__numerology_80.snap @@ -78,22 +78,20 @@ select .000_005; select 1_000.5e0_1; -do -$do$ +do $$ DECLARE i int; BEGIN FOR i IN 1_001..1_003 LOOP RAISE NOTICE 'i = %', i; END LOOP; -END -$do$; +END $$; select _100; prepare p1 as select $0 as _1;; -create table temp_float (f1 double precision); +create table temp_float (f1 float8); insert into temp_float (f1) select float8(f1) from int4_tbl; @@ -101,54 +99,33 @@ insert into temp_float (f1) select float8(f1) from int2_tbl; select f1 from temp_float order by f1; -create table temp_int4 (f1 int); +create table temp_int4 (f1 int4); insert into temp_int4 (f1) -select - int4(f1) -from - float8_tbl -where - f1 > -2147483647 and f1 < 2147483647; +select int4(f1) from float8_tbl where f1 > -2147483647 and f1 < 2147483647; insert into temp_int4 (f1) select int4(f1) from int2_tbl; select f1 from temp_int4 order by f1; -create table temp_int2 (f1 smallint); +create table temp_int2 (f1 int2); insert into temp_int2 (f1) -select - int2(f1) -from - float8_tbl -where - f1 >= -32767 and f1 <= 32767; +select int2(f1) from float8_tbl where f1 >= -32767 and f1 <= 32767; insert into temp_int2 (f1) -select - int2(f1) -from - int4_tbl -where - f1 >= -32767 and f1 <= 32767; +select int2(f1) from int4_tbl where f1 >= -32767 and f1 <= 32767; select f1 from temp_int2 order by f1; create table temp_group ( - f1 int, - f2 int, - f3 double precision + f1 int4, + f2 int4, + f3 float8 ); insert into temp_group -select - 1, - -i.f1, - -f.f1 -from - int4_tbl as i, - float8_tbl as f; +select 1, -i.f1, -f.f1 from int4_tbl as i, float8_tbl as f; insert into temp_group select 2, i.f1, f.f1 from int4_tbl as i, float8_tbl as f; @@ -156,8 +133,8 @@ select distinct f1 as two from temp_group order by 1; select f1 as two, - MAX(f3) as max_float, - MIN(f3) as min_float + max(f3) as max_float, + min(f3) as min_float from temp_group group by f1 @@ -167,8 +144,8 @@ order by two, select f1 as two, - MAX(f3) as max_float, - MIN(f3) as min_float + max(f3) as max_float, + min(f3) as min_float from temp_group group by two @@ -178,8 +155,8 @@ order by two, select f1 as two, - MAX(f3) + 1 as max_plus_1, - MIN(f3) - 1 as min_minus_1 + max(f3) + 1 as max_plus_1, + min(f3) - 1 as min_minus_1 from temp_group group by f1 @@ -188,8 +165,8 @@ order by two, select f1 as two, - MAX(f2) + MIN(f2) as max_plus_min, - MIN(f3) - 1 as min_minus_1 + max(f2) + min(f2) as max_plus_min, + min(f3) - 1 as min_minus_1 from temp_group group by f1 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__object_address_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__object_address_100.snap index 7c515eb4a..abd082ccf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__object_address_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__object_address_100.snap @@ -10,7 +10,7 @@ reset client_min_messages; create user regress_addr_user; -create schema "addr_nsp"; +create schema addr_nsp; set search_path to addr_nsp; @@ -32,9 +32,7 @@ create text search parser addr_ts_prs ( ); create table addr_nsp.gentable ( - a serial - primary key - constraint "a_chk" check (a > 0), + a serial primary key constraint a_chk check (a > 0), b text default 'hello' ); @@ -52,26 +50,22 @@ create type addr_nsp.genenum as enum ('one', 'two'); create foreign table addr_nsp.genftable ( a int ) server addr_fserv; -create aggregate addr_nsp.genaggr (int) (sfunc = int4pl, stype = int); +create aggregate addr_nsp.genaggr (int4) (sfunc = int4pl, stype = int4); -create domain addr_nsp.gendomain as int constraint "domconstr" check (value > 0); +create domain addr_nsp.gendomain as int4 constraint domconstr check (value > 0); create function addr_nsp.trig() returns trigger language plpgsql -as $function$ -BEGIN END; -$function$; +as $$ BEGIN END; $$; create trigger t before insert on addr_nsp.gentable for each row execute function addr_nsp.trig(); create policy genpol on addr_nsp.gentable as permissive for all to public; -create procedure addr_nsp.proc(int) +create procedure addr_nsp.proc(int4) language sql -as $procedure$ - -$procedure$; +as $$ $$; create server integer foreign data wrapper addr_fdw; @@ -82,7 +76,7 @@ for role regress_addr_user in schema public grant all on tables to regress_addr_user; -alter default privileges for role regress_addr_user revoke DELETE on tables from regress_addr_user; +alter default privileges for role regress_addr_user revoke delete on tables from regress_addr_user; create transform for int language sql ( @@ -90,7 +84,7 @@ create transform for int language sql to sql with function int4recv(internal) ); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication addr_pub for table addr_nsp.gentable; @@ -98,10 +92,12 @@ create publication addr_pub_schema for tables in schema addr_nsp; reset client_min_messages; -create subscription regress_addr_sub connection '' publication bar with (connect = 'false', -slot_name = 'none'); +create subscription regress_addr_sub connection '' publication bar with ( + connect = 'false', + slot_name = 'none' +); -create statistics addr_nsp.gentable_stat on "a", "b" from addr_nsp.gentable; +create statistics addr_nsp.gentable_stat on a, b from addr_nsp.gentable; select pg_get_object_address('stone', '{}', '{}'); @@ -109,8 +105,7 @@ select pg_get_object_address('table', '{}', '{}'); select pg_get_object_address('table', '{NULL}', '{}'); -do -$do$ +do $$ DECLARE objtype text; BEGIN @@ -124,46 +119,29 @@ BEGIN END; END LOOP; END; -$do$; +$$; select * from - pg_get_object_address( - 'operator of access method', - '{btree,integer_ops,1}', - '{int4,bool}' - ); + pg_get_object_address('operator of access method', '{btree,integer_ops,1}', '{int4,bool}'); select * from - pg_get_object_address( - 'operator of access method', - '{btree,integer_ops,99}', - '{int4,int4}' - ); + pg_get_object_address('operator of access method', '{btree,integer_ops,99}', '{int4,int4}'); select * from - pg_get_object_address( - 'function of access method', - '{btree,integer_ops,1}', - '{int4,bool}' - ); + pg_get_object_address('function of access method', '{btree,integer_ops,1}', '{int4,bool}'); select * from - pg_get_object_address( - 'function of access method', - '{btree,integer_ops,99}', - '{int4,int4}' - ); - -do -$do$ + pg_get_object_address('function of access method', '{btree,integer_ops,99}', '{int4,int4}'); + +do $$ DECLARE objtype text; names text[]; @@ -195,7 +173,7 @@ BEGIN END LOOP; END LOOP; END; -$do$; +$$; select pg_get_object_address('language', '{one}', '{}'); @@ -252,43 +230,21 @@ select pg_get_object_address('subscription', '{one}', '{}'); select pg_get_object_address('subscription', '{one,two}', '{}'); with -objects (type, -name, -args) +objects (type, name, args) as ( values - ( - 'table', - cast('{addr_nsp, gentable}' as text[]), - cast('{}' as text[]) - ), - ( - 'table', - cast('{addr_nsp, parttable}' as text[]), - cast('{}' as text[]) - ), + ('table', cast('{addr_nsp, gentable}' as text[]), cast('{}' as text[])), + ('table', cast('{addr_nsp, parttable}' as text[]), cast('{}' as text[])), ('index', '{addr_nsp, gentable_pkey}', '{}'), ('index', '{addr_nsp, parttable_pkey}', '{}'), ('sequence', '{addr_nsp, gentable_a_seq}', '{}'), ('view', '{addr_nsp, genview}', '{}'), - ( - 'materialized view', - '{addr_nsp, genmatview}', - '{}' - ), + ('materialized view', '{addr_nsp, genmatview}', '{}'), ('foreign table', '{addr_nsp, genftable}', '{}'), ('table column', '{addr_nsp, gentable, b}', '{}'), - ( - 'foreign table column', - '{addr_nsp, genftable, a}', - '{}' - ), + ('foreign table column', '{addr_nsp, genftable, a}', '{}'), ('aggregate', '{addr_nsp, genaggr}', '{int4}'), - ( - 'function', - '{pg_catalog, pg_identify_object}', - '{pg_catalog.oid, pg_catalog.oid, int4}' - ), + ('function', '{pg_catalog, pg_identify_object}', '{pg_catalog.oid, pg_catalog.oid, int4}'), ('procedure', '{addr_nsp, proc}', '{int4}'), ('type', '{pg_catalog._int4}', '{}'), ('type', '{addr_nsp.gendomain}', '{}'), @@ -296,102 +252,47 @@ as ( ('type', '{addr_nsp.genenum}', '{}'), ('cast', '{int8}', '{int4}'), ('collation', '{default}', '{}'), - ( - 'table constraint', - '{addr_nsp, gentable, a_chk}', - '{}' - ), - ( - 'domain constraint', - '{addr_nsp.gendomain}', - '{domconstr}' - ), - ( - 'conversion', '{pg_catalog, koi8_r_to_mic}', '{}' - ), + ('table constraint', '{addr_nsp, gentable, a_chk}', '{}'), + ('domain constraint', '{addr_nsp.gendomain}', '{domconstr}'), + ('conversion', '{pg_catalog, koi8_r_to_mic}', '{}'), ('default value', '{addr_nsp, gentable, b}', '{}'), ('language', '{plpgsql}', '{}'), ('operator', '{+}', '{int4, int4}'), ('operator class', '{btree, int4_ops}', '{}'), ('operator family', '{btree, integer_ops}', '{}'), - ( - 'operator of access method', - '{btree,integer_ops,1}', - '{integer,integer}' - ), - ( - 'function of access method', - '{btree,integer_ops,2}', - '{integer,integer}' - ), + ('operator of access method', '{btree,integer_ops,1}', '{integer,integer}'), + ('function of access method', '{btree,integer_ops,2}', '{integer,integer}'), ('rule', '{addr_nsp, genview, _RETURN}', '{}'), ('trigger', '{addr_nsp, gentable, t}', '{}'), ('schema', '{addr_nsp}', '{}'), ('text search parser', '{addr_ts_prs}', '{}'), ('text search dictionary', '{addr_ts_dict}', '{}'), ('text search template', '{addr_ts_temp}', '{}'), - ( - 'text search configuration', - '{addr_ts_conf}', - '{}' - ), + ('text search configuration', '{addr_ts_conf}', '{}'), ('role', '{regress_addr_user}', '{}'), ('foreign-data wrapper', '{addr_fdw}', '{}'), ('server', '{addr_fserv}', '{}'), - ( - 'user mapping', '{regress_addr_user}', '{integer}' - ), - ( - 'default acl', '{regress_addr_user,public}', '{r}' - ), + ('user mapping', '{regress_addr_user}', '{integer}'), + ('default acl', '{regress_addr_user,public}', '{r}'), ('default acl', '{regress_addr_user}', '{r}'), ('policy', '{addr_nsp, gentable, genpol}', '{}'), ('transform', '{int}', '{sql}'), ('access method', '{btree}', '{}'), ('publication', '{addr_pub}', '{}'), - ( - 'publication namespace', - '{addr_nsp}', - '{addr_pub_schema}' - ), - ( - 'publication relation', - '{addr_nsp, gentable}', - '{addr_pub}' - ), + ('publication namespace', '{addr_nsp}', '{addr_pub_schema}'), + ('publication relation', '{addr_nsp, gentable}', '{addr_pub}'), ('subscription', '{regress_addr_sub}', '{}'), - ( - 'statistics object', - '{addr_nsp, gentable_stat}', - '{}' - ) + ('statistics object', '{addr_nsp, gentable_stat}', '{}') ) select - (pg_identify_object( - addr1.classid, - addr1.objid, - addr1.objsubid - )).*, - row(pg_identify_object( - addr1.classid, - addr1.objid, - addr1.objsubid - )) = - row(pg_identify_object( - addr2.classid, - addr2.objid, - addr2.objsubid - )) + (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, + row(pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)) = + row(pg_identify_object(addr2.classid, addr2.objid, addr2.objsubid)) as roundtrip from objects, pg_get_object_address(type, name, args) as addr1, - pg_identify_object_as_address( - classid, - objid, - objsubid - ) - as ioa (typ, nms, args), + pg_identify_object_as_address(classid, objid, objsubid) as ioa (typ, nms, args), pg_get_object_address(typ, nms, ioa.args) as addr2 order by addr1.classid, addr1.objid, @@ -412,17 +313,11 @@ drop owned by regress_addr_user; drop role regress_addr_user; with -objects (classid, -objid, -objsubid) +objects (classid, objid, objsubid) as ( values (cast('pg_class' as regclass), 0, 0), - ( - cast('pg_class' as regclass), - cast('pg_class' as regclass), - 100 - ), + (cast('pg_class' as regclass), cast('pg_class' as regclass), 100), (cast('pg_proc' as regclass), 0, 0), (cast('pg_type' as regclass), 0, 0), (cast('pg_cast' as regclass), 0, 0), @@ -450,9 +345,7 @@ as ( (cast('pg_auth_members' as regclass), 0, 0), (cast('pg_database' as regclass), 0, 0), (cast('pg_tablespace' as regclass), 0, 0), - ( - cast('pg_foreign_data_wrapper' as regclass), 0, 0 - ), + (cast('pg_foreign_data_wrapper' as regclass), 0, 0), (cast('pg_foreign_server' as regclass), 0, 0), (cast('pg_user_mapping' as regclass), 0, 0), (cast('pg_default_acl' as regclass), 0, 0), @@ -461,32 +354,15 @@ as ( (cast('pg_parameter_acl' as regclass), 0, 0), (cast('pg_policy' as regclass), 0, 0), (cast('pg_publication' as regclass), 0, 0), - ( - cast('pg_publication_namespace' as regclass), 0, 0 - ), + (cast('pg_publication_namespace' as regclass), 0, 0), (cast('pg_publication_rel' as regclass), 0, 0), (cast('pg_subscription' as regclass), 0, 0), (cast('pg_transform' as regclass), 0, 0) ) select - row(pg_identify_object( - objects.classid, - objects.objid, - objects.objsubid - )) - as ident, - row(pg_identify_object_as_address( - objects.classid, - objects.objid, - objects.objsubid - )) - as addr, - pg_describe_object( - objects.classid, - objects.objid, - objects.objsubid - ) - as descr + row(pg_identify_object(objects.classid, objects.objid, objects.objsubid)) as ident, + row(pg_identify_object_as_address(objects.classid, objects.objid, objects.objsubid)) as addr, + pg_describe_object(objects.classid, objects.objid, objects.objsubid) as descr from objects order by objects.classid, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__object_address_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__object_address_80.snap index e7c33d75b..384e667d5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__object_address_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__object_address_80.snap @@ -10,7 +10,7 @@ reset client_min_messages; create user regress_addr_user; -create schema "addr_nsp"; +create schema addr_nsp; set search_path to addr_nsp; @@ -32,9 +32,7 @@ create text search parser addr_ts_prs ( ); create table addr_nsp.gentable ( - a serial - primary key - constraint "a_chk" check (a > 0), + a serial primary key constraint a_chk check (a > 0), b text default 'hello' ); @@ -52,17 +50,14 @@ create type addr_nsp.genenum as enum ('one', 'two'); create foreign table addr_nsp.genftable ( a int ) server addr_fserv; -create aggregate addr_nsp.genaggr (int) (sfunc = int4pl, stype = int); +create aggregate addr_nsp.genaggr (int4) (sfunc = int4pl, stype = int4); -create domain addr_nsp.gendomain as int - constraint "domconstr" check (value > 0); +create domain addr_nsp.gendomain as int4 constraint domconstr check (value > 0); create function addr_nsp.trig() returns trigger language plpgsql -as $function$ -BEGIN END; -$function$; +as $$ BEGIN END; $$; create trigger t before insert @@ -72,11 +67,9 @@ execute function addr_nsp.trig(); create policy genpol on addr_nsp.gentable as permissive for all to public; -create procedure addr_nsp.proc(int) +create procedure addr_nsp.proc(int4) language sql -as $procedure$ - -$procedure$; +as $$ $$; create server integer foreign data wrapper addr_fdw; @@ -85,15 +78,11 @@ create user mapping for regress_addr_user server integer; alter default privileges for role regress_addr_user in schema public -grant all -on tables -to regress_addr_user; +grant all on tables to regress_addr_user; alter default privileges for role regress_addr_user -revoke DELETE -on tables -from regress_addr_user; +revoke delete on tables from regress_addr_user; create transform for int language sql ( @@ -101,7 +90,7 @@ create transform for int language sql to sql with function int4recv(internal) ); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication addr_pub for table addr_nsp.gentable; @@ -109,10 +98,12 @@ create publication addr_pub_schema for tables in schema addr_nsp; reset client_min_messages; -create subscription regress_addr_sub connection '' publication bar with (connect = 'false', -slot_name = 'none'); +create subscription regress_addr_sub connection '' publication bar with ( + connect = 'false', + slot_name = 'none' +); -create statistics addr_nsp.gentable_stat on "a", "b" from addr_nsp.gentable; +create statistics addr_nsp.gentable_stat on a, b from addr_nsp.gentable; select pg_get_object_address('stone', '{}', '{}'); @@ -120,8 +111,7 @@ select pg_get_object_address('table', '{}', '{}'); select pg_get_object_address('table', '{NULL}', '{}'); -do -$do$ +do $$ DECLARE objtype text; BEGIN @@ -135,7 +125,7 @@ BEGIN END; END LOOP; END; -$do$; +$$; select * @@ -173,8 +163,7 @@ from '{int4,int4}' ); -do -$do$ +do $$ DECLARE objtype text; names text[]; @@ -206,7 +195,7 @@ BEGIN END LOOP; END LOOP; END; -$do$; +$$; select pg_get_object_address('language', '{one}', '{}'); @@ -263,235 +252,75 @@ select pg_get_object_address('subscription', '{one}', '{}'); select pg_get_object_address('subscription', '{one,two}', '{}'); with -objects (type, -name, -args) +objects (type, name, args) as ( values - ( - 'table', - cast('{addr_nsp, gentable}' as text[]), - cast('{}' as text[]) - ), - ( - 'table', - cast('{addr_nsp, parttable}' as text[]), - cast('{}' as text[]) - ), - ( - 'index', - '{addr_nsp, gentable_pkey}', - '{}' - ), - ( - 'index', - '{addr_nsp, parttable_pkey}', - '{}' - ), - ( - 'sequence', - '{addr_nsp, gentable_a_seq}', - '{}' - ), + ('table', cast('{addr_nsp, gentable}' as text[]), cast('{}' as text[])), + ('table', cast('{addr_nsp, parttable}' as text[]), cast('{}' as text[])), + ('index', '{addr_nsp, gentable_pkey}', '{}'), + ('index', '{addr_nsp, parttable_pkey}', '{}'), + ('sequence', '{addr_nsp, gentable_a_seq}', '{}'), ('view', '{addr_nsp, genview}', '{}'), - ( - 'materialized view', - '{addr_nsp, genmatview}', - '{}' - ), - ( - 'foreign table', - '{addr_nsp, genftable}', - '{}' - ), - ( - 'table column', - '{addr_nsp, gentable, b}', - '{}' - ), - ( - 'foreign table column', - '{addr_nsp, genftable, a}', - '{}' - ), - ( - 'aggregate', - '{addr_nsp, genaggr}', - '{int4}' - ), + ('materialized view', '{addr_nsp, genmatview}', '{}'), + ('foreign table', '{addr_nsp, genftable}', '{}'), + ('table column', '{addr_nsp, gentable, b}', '{}'), + ('foreign table column', '{addr_nsp, genftable, a}', '{}'), + ('aggregate', '{addr_nsp, genaggr}', '{int4}'), ( 'function', '{pg_catalog, pg_identify_object}', '{pg_catalog.oid, pg_catalog.oid, int4}' ), - ( - 'procedure', - '{addr_nsp, proc}', - '{int4}' - ), + ('procedure', '{addr_nsp, proc}', '{int4}'), ('type', '{pg_catalog._int4}', '{}'), ('type', '{addr_nsp.gendomain}', '{}'), ('type', '{addr_nsp.gencomptype}', '{}'), ('type', '{addr_nsp.genenum}', '{}'), ('cast', '{int8}', '{int4}'), ('collation', '{default}', '{}'), - ( - 'table constraint', - '{addr_nsp, gentable, a_chk}', - '{}' - ), - ( - 'domain constraint', - '{addr_nsp.gendomain}', - '{domconstr}' - ), - ( - 'conversion', - '{pg_catalog, koi8_r_to_mic}', - '{}' - ), - ( - 'default value', - '{addr_nsp, gentable, b}', - '{}' - ), + ('table constraint', '{addr_nsp, gentable, a_chk}', '{}'), + ('domain constraint', '{addr_nsp.gendomain}', '{domconstr}'), + ('conversion', '{pg_catalog, koi8_r_to_mic}', '{}'), + ('default value', '{addr_nsp, gentable, b}', '{}'), ('language', '{plpgsql}', '{}'), ('operator', '{+}', '{int4, int4}'), - ( - 'operator class', - '{btree, int4_ops}', - '{}' - ), - ( - 'operator family', - '{btree, integer_ops}', - '{}' - ), - ( - 'operator of access method', - '{btree,integer_ops,1}', - '{integer,integer}' - ), - ( - 'function of access method', - '{btree,integer_ops,2}', - '{integer,integer}' - ), - ( - 'rule', - '{addr_nsp, genview, _RETURN}', - '{}' - ), - ( - 'trigger', - '{addr_nsp, gentable, t}', - '{}' - ), + ('operator class', '{btree, int4_ops}', '{}'), + ('operator family', '{btree, integer_ops}', '{}'), + ('operator of access method', '{btree,integer_ops,1}', '{integer,integer}'), + ('function of access method', '{btree,integer_ops,2}', '{integer,integer}'), + ('rule', '{addr_nsp, genview, _RETURN}', '{}'), + ('trigger', '{addr_nsp, gentable, t}', '{}'), ('schema', '{addr_nsp}', '{}'), - ( - 'text search parser', - '{addr_ts_prs}', - '{}' - ), - ( - 'text search dictionary', - '{addr_ts_dict}', - '{}' - ), - ( - 'text search template', - '{addr_ts_temp}', - '{}' - ), - ( - 'text search configuration', - '{addr_ts_conf}', - '{}' - ), + ('text search parser', '{addr_ts_prs}', '{}'), + ('text search dictionary', '{addr_ts_dict}', '{}'), + ('text search template', '{addr_ts_temp}', '{}'), + ('text search configuration', '{addr_ts_conf}', '{}'), ('role', '{regress_addr_user}', '{}'), - ( - 'foreign-data wrapper', - '{addr_fdw}', - '{}' - ), + ('foreign-data wrapper', '{addr_fdw}', '{}'), ('server', '{addr_fserv}', '{}'), - ( - 'user mapping', - '{regress_addr_user}', - '{integer}' - ), - ( - 'default acl', - '{regress_addr_user,public}', - '{r}' - ), - ( - 'default acl', - '{regress_addr_user}', - '{r}' - ), - ( - 'policy', - '{addr_nsp, gentable, genpol}', - '{}' - ), + ('user mapping', '{regress_addr_user}', '{integer}'), + ('default acl', '{regress_addr_user,public}', '{r}'), + ('default acl', '{regress_addr_user}', '{r}'), + ('policy', '{addr_nsp, gentable, genpol}', '{}'), ('transform', '{int}', '{sql}'), ('access method', '{btree}', '{}'), ('publication', '{addr_pub}', '{}'), - ( - 'publication namespace', - '{addr_nsp}', - '{addr_pub_schema}' - ), - ( - 'publication relation', - '{addr_nsp, gentable}', - '{addr_pub}' - ), - ( - 'subscription', - '{regress_addr_sub}', - '{}' - ), - ( - 'statistics object', - '{addr_nsp, gentable_stat}', - '{}' - ) + ('publication namespace', '{addr_nsp}', '{addr_pub_schema}'), + ('publication relation', '{addr_nsp, gentable}', '{addr_pub}'), + ('subscription', '{regress_addr_sub}', '{}'), + ('statistics object', '{addr_nsp, gentable_stat}', '{}') ) select - (pg_identify_object( - addr1.classid, - addr1.objid, - addr1.objsubid - )).*, - row(pg_identify_object( - addr1.classid, - addr1.objid, - addr1.objsubid - )) = - row(pg_identify_object( - addr2.classid, - addr2.objid, - addr2.objsubid - )) + (pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)).*, + row(pg_identify_object(addr1.classid, addr1.objid, addr1.objsubid)) = + row(pg_identify_object(addr2.classid, addr2.objid, addr2.objsubid)) as roundtrip from objects, - pg_get_object_address(type, name, args) - as addr1, - pg_identify_object_as_address( - classid, - objid, - objsubid - ) + pg_get_object_address(type, name, args) as addr1, + pg_identify_object_as_address(classid, objid, objsubid) as ioa (typ, nms, args), - pg_get_object_address( - typ, - nms, - ioa.args - ) - as addr2 + pg_get_object_address(typ, nms, ioa.args) as addr2 order by addr1.classid, addr1.objid, addr1.objsubid; @@ -511,32 +340,20 @@ drop owned by regress_addr_user; drop role regress_addr_user; with -objects (classid, -objid, -objsubid) +objects (classid, objid, objsubid) as ( values (cast('pg_class' as regclass), 0, 0), - ( - cast('pg_class' as regclass), - cast('pg_class' as regclass), - 100 - ), + (cast('pg_class' as regclass), cast('pg_class' as regclass), 100), (cast('pg_proc' as regclass), 0, 0), (cast('pg_type' as regclass), 0, 0), (cast('pg_cast' as regclass), 0, 0), (cast('pg_collation' as regclass), 0, 0), - ( - cast('pg_constraint' as regclass), 0, 0 - ), - ( - cast('pg_conversion' as regclass), 0, 0 - ), + (cast('pg_constraint' as regclass), 0, 0), + (cast('pg_conversion' as regclass), 0, 0), (cast('pg_attrdef' as regclass), 0, 0), (cast('pg_language' as regclass), 0, 0), - ( - cast('pg_largeobject' as regclass), 0, 0 - ), + (cast('pg_largeobject' as regclass), 0, 0), (cast('pg_operator' as regclass), 0, 0), (cast('pg_opclass' as regclass), 0, 0), (cast('pg_opfamily' as regclass), 0, 0), @@ -546,98 +363,41 @@ as ( (cast('pg_rewrite' as regclass), 0, 0), (cast('pg_trigger' as regclass), 0, 0), (cast('pg_namespace' as regclass), 0, 0), - ( - cast('pg_statistic_ext' as regclass), - 0, - 0 - ), + (cast('pg_statistic_ext' as regclass), 0, 0), (cast('pg_ts_parser' as regclass), 0, 0), (cast('pg_ts_dict' as regclass), 0, 0), - ( - cast('pg_ts_template' as regclass), 0, 0 - ), + (cast('pg_ts_template' as regclass), 0, 0), (cast('pg_ts_config' as regclass), 0, 0), (cast('pg_authid' as regclass), 0, 0), - ( - cast('pg_auth_members' as regclass), - 0, - 0 - ), + (cast('pg_auth_members' as regclass), 0, 0), (cast('pg_database' as regclass), 0, 0), - ( - cast('pg_tablespace' as regclass), 0, 0 - ), - ( - cast('pg_foreign_data_wrapper' - as regclass), - 0, - 0 - ), - ( - cast('pg_foreign_server' as regclass), - 0, - 0 - ), - ( - cast('pg_user_mapping' as regclass), - 0, - 0 - ), - ( - cast('pg_default_acl' as regclass), 0, 0 - ), + (cast('pg_tablespace' as regclass), 0, 0), + (cast('pg_foreign_data_wrapper' as regclass), 0, 0), + (cast('pg_foreign_server' as regclass), 0, 0), + (cast('pg_user_mapping' as regclass), 0, 0), + (cast('pg_default_acl' as regclass), 0, 0), (cast('pg_extension' as regclass), 0, 0), - ( - cast('pg_event_trigger' as regclass), - 0, - 0 - ), - ( - cast('pg_parameter_acl' as regclass), - 0, - 0 - ), + (cast('pg_event_trigger' as regclass), 0, 0), + (cast('pg_parameter_acl' as regclass), 0, 0), (cast('pg_policy' as regclass), 0, 0), - ( - cast('pg_publication' as regclass), 0, 0 - ), - ( - cast('pg_publication_namespace' - as regclass), - 0, - 0 - ), - ( - cast('pg_publication_rel' as regclass), - 0, - 0 - ), - ( - cast('pg_subscription' as regclass), - 0, - 0 - ), + (cast('pg_publication' as regclass), 0, 0), + (cast('pg_publication_namespace' as regclass), 0, 0), + (cast('pg_publication_rel' as regclass), 0, 0), + (cast('pg_subscription' as regclass), 0, 0), (cast('pg_transform' as regclass), 0, 0) ) select - row(pg_identify_object( - objects.classid, - objects.objid, - objects.objsubid - )) + row(pg_identify_object(objects.classid, objects.objid, objects.objsubid)) as ident, - row(pg_identify_object_as_address( - objects.classid, - objects.objid, - objects.objsubid - )) - as addr, - pg_describe_object( - objects.classid, - objects.objid, - objects.objsubid + row( + pg_identify_object_as_address( + objects.classid, + objects.objid, + objects.objsubid + ) ) - as descr + as addr, + pg_describe_object(objects.classid, objects.objid, objects.objsubid) as descr from objects order by objects.classid, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_100.snap index 3c7c70e0d..3d80ace4b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_100.snap @@ -3,8 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/oidjoins.sql snapshot_kind: text --- -do -$do$ +do $doblock$ declare fk record; nkeys integer; @@ -49,4 +48,4 @@ begin end loop; end loop; end -$do$; +$doblock$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_80.snap index 3c7c70e0d..3d80ace4b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_80.snap @@ -3,8 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/oidjoins.sql snapshot_kind: text --- -do -$do$ +do $doblock$ declare fk record; nkeys integer; @@ -49,4 +48,4 @@ begin end loop; end loop; end -$do$; +$doblock$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__opr_sanity_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__opr_sanity_100.snap index 5eb419f7c..3892eaa97 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__opr_sanity_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__opr_sanity_100.snap @@ -17,10 +17,7 @@ where array_upper(p1.proargtypes, 1) <> p1.pronargs - 1 or cast(0 as oid) = any (p1.proargtypes) or procost <= 0 or - case - when proretset then prorows <= 0 - else prorows <> 0 - end or + case when proretset then prorows <= 0 else prorows <> 0 end or prokind not in ('f', 'a', 'w', 'p') or provolatile not in ('i', 's', 'v') or proparallel not in ('s', 'r', 'u'); @@ -33,10 +30,7 @@ select from pg_proc as p1 where - ( - prosrc = '' or prosrc = '-' - ) and - prosqlbody is null; + (prosrc = '' or prosrc = '-') and prosqlbody is null; select p1.oid, p1.proname from pg_proc as p1 where proretset and prokind <> 'f'; @@ -48,8 +42,7 @@ select from pg_proc as p1 where - (pronargdefaults <> 0) <> - (proargdefaults is not null); + (pronargdefaults <> 0) <> (proargdefaults is not null); select p1.oid, @@ -57,10 +50,7 @@ select from pg_proc as p1 where - prolang = 13 and - ( - probin is null or probin = '' or probin = '-' - ); + prolang = 13 and (probin is null or probin = '' or probin = '-'); select p1.oid, p1.proname from pg_proc as p1 where prolang <> 13 and probin is not null; @@ -306,10 +296,7 @@ select from pg_proc as p1 where - p1.prorettype - in ( - cast('anyrange' as regtype), cast('anymultirange' as regtype) - ) and + p1.prorettype in (cast('anyrange' as regtype), cast('anymultirange' as regtype)) and not ( cast('anyrange' as regtype) = any (p1.proargtypes) or cast('anymultirange' as regtype) = any (p1.proargtypes) @@ -341,8 +328,7 @@ select from pg_proc as p1 where - p1.prorettype = - cast('anycompatiblerange' as regtype) and + p1.prorettype = cast('anycompatiblerange' as regtype) and not cast('anycompatiblerange' as regtype) = any (p1.proargtypes) order by 2; @@ -353,16 +339,9 @@ from pg_proc as p1 where cast('cstring' as regtype) = any (p1.proargtypes) and - not exists - ( - select 1 from pg_type where typinput = p1.oid - ) and - not exists - ( - select 1 from pg_conversion where conproc = p1.oid - ) and - p1.oid <> - cast('shell_in(cstring)' as regprocedure) + not exists (select 1 from pg_type where typinput = p1.oid) and + not exists (select 1 from pg_conversion where conproc = p1.oid) and + p1.oid <> cast('shell_in(cstring)' as regprocedure) order by 1; select @@ -372,14 +351,8 @@ from pg_proc as p1 where p1.prorettype = cast('cstring' as regtype) and - not exists - ( - select 1 from pg_type where typoutput = p1.oid - ) and - not exists - ( - select 1 from pg_type where typmodout = p1.oid - ) and + not exists (select 1 from pg_type where typoutput = p1.oid) and + not exists (select 1 from pg_type where typmodout = p1.oid) and p1.oid <> cast('shell_out(void)' as regprocedure) order by 1; @@ -389,9 +362,7 @@ select from pg_proc as p1 where - proallargtypes is not null and - array_length(proallargtypes, 1) < - array_length(proargtypes, 1); + proallargtypes is not null and array_length(proallargtypes, 1) < array_length(proargtypes, 1); select p1.oid, @@ -399,9 +370,7 @@ select from pg_proc as p1 where - proargmodes is not null and - array_length(proargmodes, 1) < - array_length(proargtypes, 1); + proargmodes is not null and array_length(proargmodes, 1) < array_length(proargtypes, 1); select p1.oid, @@ -409,9 +378,7 @@ select from pg_proc as p1 where - proargnames is not null and - array_length(proargnames, 1) < - array_length(proargtypes, 1); + proargnames is not null and array_length(proargnames, 1) < array_length(proargtypes, 1); select p1.oid, @@ -421,8 +388,7 @@ from where proallargtypes is not null and proargmodes is not null and - array_length(proallargtypes, 1) <> - array_length(proargmodes, 1); + array_length(proallargtypes, 1) <> array_length(proargmodes, 1); select p1.oid, @@ -432,8 +398,7 @@ from where proallargtypes is not null and proargnames is not null and - array_length(proallargtypes, 1) <> - array_length(proargnames, 1); + array_length(proallargtypes, 1) <> array_length(proargnames, 1); select p1.oid, @@ -443,8 +408,7 @@ from where proargmodes is not null and proargnames is not null and - array_length(proargmodes, 1) <> - array_length(proargnames, 1); + array_length(proargmodes, 1) <> array_length(proargnames, 1); select p1.oid, @@ -461,14 +425,9 @@ where select proallargtypes[i] from - generate_series( - 1, - array_length(proallargtypes, 1) - ) - as g (i) + generate_series(1, array_length(proallargtypes, 1)) as g (i) where - proargmodes is null or - proargmodes[i] in ('i', 'b', 'v') + proargmodes is null or proargmodes[i] in ('i', 'b', 'v') ); select @@ -480,20 +439,16 @@ from where provariadic <> 0 and case proargtypes[array_length(proargtypes, 1) - 1] - when cast('"any"' as regtype) - then cast('"any"' as regtype) - when cast('anyarray' as regtype) - then cast('anyelement' as regtype) - when cast('anycompatiblearray' as regtype) - then cast('anycompatible' as regtype) + when cast('"any"' as regtype) then cast('"any"' as regtype) + when cast('anyarray' as regtype) then cast('anyelement' as regtype) + when cast('anycompatiblearray' as regtype) then cast('anycompatible' as regtype) else ( select t.oid from pg_type as t where - t.typarray = - proargtypes[array_length(proargtypes, 1) - 1] + t.typarray = proargtypes[array_length(proargtypes, 1) - 1] ) end <> provariadic; @@ -505,8 +460,7 @@ select from pg_proc where - (proargmodes is not null and - 'v' = any (proargmodes)) is distinct from provariadic <> 0; + (proargmodes is not null and 'v' = any (proargmodes)) is distinct from provariadic <> 0; select p1.oid, @@ -532,19 +486,14 @@ from pg_proc as p1 left outer join pg_description as d - on p1.tableoid = d.classoid and - p1.oid = d.objoid and - d.objsubid = 0 + on p1.tableoid = d.classoid and p1.oid = d.objoid and d.objsubid = 0 where d.classoid is null and p1.oid <= 9999; select cast(p1.oid as regprocedure) from - pg_proc as p1 - inner join - pg_namespace as pn - on pronamespace = pn.oid + pg_proc as p1 inner join pg_namespace as pn on pronamespace = pn.oid where nspname = 'pg_catalog' and proleakproof order by 1; @@ -552,14 +501,9 @@ order by 1; select cast(p1.oid as regprocedure) from - pg_proc as p1 - inner join - pg_namespace as pn - on pronamespace = pn.oid + pg_proc as p1 inner join pg_namespace as pn on pronamespace = pn.oid where - nspname = 'pg_catalog' and - proleakproof and - pronargs = 0 + nspname = 'pg_catalog' and proleakproof and pronargs = 0 order by 1; select @@ -573,15 +517,7 @@ where 'lo_open', 'lo_close', 'lo_creat', 'lo_create', 'lo_unlink', 'lo_lseek', 'lo_lseek64', 'lo_tell', 'lo_tell64', 'lo_truncate', 'lo_truncate64', 'loread', 'lowrite' ) and - pronamespace = - ( - select - oid - from - pg_catalog.pg_namespace - where - nspname = 'pg_catalog' - ) + pronamespace = (select oid from pg_catalog.pg_namespace where nspname = 'pg_catalog') order by 1; select p1.oid, p1.proname from pg_proc as p1 where provolatile = 'i' and proparallel = 'u'; @@ -601,8 +537,7 @@ select from pg_cast as c where - (castmethod = 'f' and castfunc = 0) or - (castmethod in ('b', 'i') and castfunc <> 0); + (castmethod = 'f' and castfunc = 0) or (castmethod in ('b', 'i') and castfunc <> 0); select * from pg_cast as c where castsource = casttarget and castfunc = 0; @@ -612,9 +547,7 @@ from pg_cast as c, pg_proc as p where - c.castfunc = p.oid and - p.pronargs < 2 and - castsource = casttarget; + c.castfunc = p.oid and p.pronargs < 2 and castsource = casttarget; select c.* @@ -628,8 +561,7 @@ where p.pronargs > 3 or not ( binary_coercible(c.castsource, p.proargtypes[0]) or - (c.castsource = cast('character' as regtype) and - p.proargtypes[0] = cast('text' as regtype)) + (c.castsource = cast('character' as regtype) and p.proargtypes[0] = cast('text' as regtype)) ) or not binary_coercible(p.prorettype, c.casttarget) ); @@ -642,10 +574,8 @@ from where c.castfunc = p.oid and ( - (p.pronargs > 1 and - p.proargtypes[1] <> cast('int4' as regtype)) or - (p.pronargs > 2 and - p.proargtypes[2] <> cast('bool' as regtype)) + (p.pronargs > 1 and p.proargtypes[1] <> cast('int4' as regtype)) or + (p.pronargs > 2 and p.proargtypes[2] <> cast('bool' as regtype)) ); select @@ -664,9 +594,7 @@ where from pg_cast as k where - k.castmethod = 'b' and - k.castsource = c.casttarget and - k.casttarget = c.castsource + k.castmethod = 'b' and k.castsource = c.casttarget and k.casttarget = c.castsource ); select @@ -721,9 +649,7 @@ select from pg_operator as o1 where - (o1.oprkind <> 'b' and o1.oprkind <> 'l') or - o1.oprresult = 0 or - o1.oprcode = 0; + (o1.oprkind <> 'b' and o1.oprkind <> 'l') or o1.oprresult = 0 or o1.oprcode = 0; select o1.oid, @@ -819,11 +745,7 @@ where ( o1.oprcanmerge or o1.oprcanhash ) and - not ( - o1.oprkind = 'b' and - o1.oprresult = cast('bool' as regtype) and - o1.oprcom <> 0 - ); + not (o1.oprkind = 'b' and o1.oprresult = cast('bool' as regtype) and o1.oprcom <> 0); select o1.oid, @@ -834,11 +756,7 @@ from pg_operator as o1, pg_operator as o2 where - o1.oprcom = o2.oid and - ( - o1.oprcanmerge <> o2.oprcanmerge or - o1.oprcanhash <> o2.oprcanhash - ); + o1.oprcom = o2.oid and (o1.oprcanmerge <> o2.oprcanmerge or o1.oprcanhash <> o2.oprcanhash); select o1.oid, @@ -854,8 +772,7 @@ where from pg_amop where - amopmethod = - (select oid from pg_am where amname = 'btree') and + amopmethod = (select oid from pg_am where amname = 'btree') and amopopr = o1.oid and amopstrategy = 3 ); @@ -869,8 +786,7 @@ from pg_amop as p where amopopr = o1.oid and - amopmethod = - (select oid from pg_am where amname = 'btree') and + amopmethod = (select oid from pg_am where amname = 'btree') and amopstrategy = 3 and not o1.oprcanmerge; @@ -888,8 +804,7 @@ where from pg_amop where - amopmethod = - (select oid from pg_am where amname = 'hash') and + amopmethod = (select oid from pg_am where amname = 'hash') and amopopr = o1.oid and amopstrategy = 1 ); @@ -903,8 +818,7 @@ from pg_amop as p where amopopr = o1.oid and - amopmethod = - (select oid from pg_am where amname = 'hash') and + amopmethod = (select oid from pg_am where amname = 'hash') and not o1.oprcanhash; select @@ -952,11 +866,7 @@ from pg_operator as o1, pg_proc as p1 where - o1.oprcode = p1.oid and - ( - o1.oprcanmerge or o1.oprcanhash - ) and - p1.provolatile = 'v'; + o1.oprcode = p1.oid and (o1.oprcanmerge or o1.oprcanhash) and p1.provolatile = 'v'; select o1.oid, @@ -1009,9 +919,7 @@ from pg_operator as o1 left outer join pg_description as d - on o1.tableoid = d.classoid and - o1.oid = d.objoid and - d.objsubid = 0 + on o1.tableoid = d.classoid and o1.oid = d.objoid and d.objsubid = 0 where d.classoid is null and o1.oid <= 9999; @@ -1023,24 +931,16 @@ as ( proname, o.oid as o_oid, pd.description as prodesc, - 'implementation of ' || oprname || ' operator' - as expecteddesc, + 'implementation of ' || oprname || ' operator' as expecteddesc, od.description as oprdesc from - pg_proc as p - inner join - pg_operator as o - on oprcode = p.oid + pg_proc as p inner join pg_operator as o on oprcode = p.oid left outer join pg_description as pd - on pd.objoid = p.oid and - pd.classoid = p.tableoid and - pd.objsubid = 0 + on pd.objoid = p.oid and pd.classoid = p.tableoid and pd.objsubid = 0 left outer join pg_description as od - on od.objoid = o.oid and - od.classoid = o.tableoid and - od.objsubid = 0 + on od.objoid = o.oid and od.classoid = o.tableoid and od.objsubid = 0 where o.oid <= 9999 ) @@ -1061,24 +961,16 @@ as ( proname, o.oid as o_oid, pd.description as prodesc, - 'implementation of ' || oprname || ' operator' - as expecteddesc, + 'implementation of ' || oprname || ' operator' as expecteddesc, od.description as oprdesc from - pg_proc as p - inner join - pg_operator as o - on oprcode = p.oid + pg_proc as p inner join pg_operator as o on oprcode = p.oid left outer join pg_description as pd - on pd.objoid = p.oid and - pd.classoid = p.tableoid and - pd.objsubid = 0 + on pd.objoid = p.oid and pd.classoid = p.tableoid and pd.objsubid = 0 left outer join pg_description as od - on od.objoid = o.oid and - od.classoid = o.tableoid and - od.objsubid = 0 + on od.objoid = o.oid and od.classoid = o.tableoid and od.objsubid = 0 where o.oid <= 9999 ) @@ -1089,8 +981,7 @@ select from funcdescs where - prodesc is distinct from expecteddesc and - oprdesc not like 'deprecated%' + prodesc is distinct from expecteddesc and oprdesc not like 'deprecated%' order by 1; select @@ -1108,8 +999,7 @@ where p1.oid = o1.oprcode and p2.oid = o2.oprcode and ( - p1.provolatile <> p2.provolatile or - p1.proleakproof <> p2.proleakproof + p1.provolatile <> p2.provolatile or p1.proleakproof <> p2.proleakproof ); select @@ -1127,8 +1017,7 @@ where p1.oid = o1.oprcode and p2.oid = o2.oprcode and ( - p1.provolatile <> p2.provolatile or - p1.proleakproof <> p2.proleakproof + p1.provolatile <> p2.provolatile or p1.proleakproof <> p2.proleakproof ); select @@ -1148,15 +1037,13 @@ where pp.oid = ap.amproc and po.oid = o.oprcode and o.oid = ao.amopopr and - ao.amopmethod = - (select oid from pg_am where amname = 'btree') and + ao.amopmethod = (select oid from pg_am where amname = 'btree') and ao.amopfamily = ap.amprocfamily and ao.amoplefttype = ap.amproclefttype and ao.amoprighttype = ap.amprocrighttype and ap.amprocnum = 1 and ( - pp.provolatile <> po.provolatile or - pp.proleakproof <> po.proleakproof + pp.provolatile <> po.provolatile or pp.proleakproof <> po.proleakproof ) order by 1; @@ -1184,12 +1071,7 @@ from pg_aggregate as a, pg_proc as p where - a.aggfnoid = p.oid and - ( - p.prokind <> 'a' or - p.proretset or - p.pronargs < a.aggnumdirectargs - ); + a.aggfnoid = p.oid and (p.prokind <> 'a' or p.proretset or p.pronargs < a.aggnumdirectargs); select oid, @@ -1197,16 +1079,7 @@ select from pg_proc as p where - p.prokind = 'a' and - not exists - ( - select - 1 - from - pg_aggregate as a - where - a.aggfnoid = p.oid - ); + p.prokind = 'a' and not exists (select 1 from pg_aggregate as a where a.aggfnoid = p.oid); select cast(a.aggfnoid as oid), @@ -1215,9 +1088,7 @@ from pg_aggregate as a, pg_proc as p where - a.aggfnoid = p.oid and - a.aggfinalfn = 0 and - p.prorettype <> a.aggtranstype; + a.aggfnoid = p.oid and a.aggfinalfn = 0 and p.prorettype <> a.aggtranstype; select cast(a.aggfnoid as oid), @@ -1239,30 +1110,11 @@ where else greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 end or not binary_coercible(ptr.prorettype, a.aggtranstype) or - not binary_coercible( - a.aggtranstype, - ptr.proargtypes[0] - ) or - (p.pronargs > 0 and - not binary_coercible( - p.proargtypes[0], - ptr.proargtypes[1] - )) or - (p.pronargs > 1 and - not binary_coercible( - p.proargtypes[1], - ptr.proargtypes[2] - )) or - (p.pronargs > 2 and - not binary_coercible( - p.proargtypes[2], - ptr.proargtypes[3] - )) or - (p.pronargs > 3 and - not binary_coercible( - p.proargtypes[3], - ptr.proargtypes[4] - )) or + not binary_coercible(a.aggtranstype, ptr.proargtypes[0]) or + (p.pronargs > 0 and not binary_coercible(p.proargtypes[0], ptr.proargtypes[1])) or + (p.pronargs > 1 and not binary_coercible(p.proargtypes[1], ptr.proargtypes[2])) or + (p.pronargs > 2 and not binary_coercible(p.proargtypes[2], ptr.proargtypes[3])) or + (p.pronargs > 3 and not binary_coercible(p.proargtypes[3], ptr.proargtypes[4])) or p.pronargs > 4 ); @@ -1281,30 +1133,14 @@ where ( pfn.proretset or not binary_coercible(pfn.prorettype, p.prorettype) or - not binary_coercible( - a.aggtranstype, - pfn.proargtypes[0] - ) or + not binary_coercible(a.aggtranstype, pfn.proargtypes[0]) or case - when a.aggfinalextra - then pfn.pronargs <> p.pronargs + 1 + when a.aggfinalextra then pfn.pronargs <> p.pronargs + 1 else pfn.pronargs <> a.aggnumdirectargs + 1 end or - (pfn.pronargs > 1 and - not binary_coercible( - p.proargtypes[0], - pfn.proargtypes[1] - )) or - (pfn.pronargs > 2 and - not binary_coercible( - p.proargtypes[1], - pfn.proargtypes[2] - )) or - (pfn.pronargs > 3 and - not binary_coercible( - p.proargtypes[2], - pfn.proargtypes[3] - )) or + (pfn.pronargs > 1 and not binary_coercible(p.proargtypes[0], pfn.proargtypes[1])) or + (pfn.pronargs > 2 and not binary_coercible(p.proargtypes[1], pfn.proargtypes[2])) or + (pfn.pronargs > 3 and not binary_coercible(p.proargtypes[2], pfn.proargtypes[3])) or pfn.pronargs > 4 ); @@ -1330,10 +1166,7 @@ select from pg_aggregate as a where - aggmtranstype <> 0 and - ( - aggmtransfn = 0 or aggminvtransfn = 0 - ); + aggmtranstype <> 0 and (aggmtransfn = 0 or aggminvtransfn = 0); select ctid, @@ -1382,25 +1215,10 @@ where else greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 end or not binary_coercible(ptr.prorettype, a.aggmtranstype) or - not binary_coercible( - a.aggmtranstype, - ptr.proargtypes[0] - ) or - (p.pronargs > 0 and - not binary_coercible( - p.proargtypes[0], - ptr.proargtypes[1] - )) or - (p.pronargs > 1 and - not binary_coercible( - p.proargtypes[1], - ptr.proargtypes[2] - )) or - (p.pronargs > 2 and - not binary_coercible( - p.proargtypes[2], - ptr.proargtypes[3] - )) or + not binary_coercible(a.aggmtranstype, ptr.proargtypes[0]) or + (p.pronargs > 0 and not binary_coercible(p.proargtypes[0], ptr.proargtypes[1])) or + (p.pronargs > 1 and not binary_coercible(p.proargtypes[1], ptr.proargtypes[2])) or + (p.pronargs > 2 and not binary_coercible(p.proargtypes[2], ptr.proargtypes[3])) or p.pronargs > 3 ); @@ -1424,25 +1242,10 @@ where else greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 end or not binary_coercible(ptr.prorettype, a.aggmtranstype) or - not binary_coercible( - a.aggmtranstype, - ptr.proargtypes[0] - ) or - (p.pronargs > 0 and - not binary_coercible( - p.proargtypes[0], - ptr.proargtypes[1] - )) or - (p.pronargs > 1 and - not binary_coercible( - p.proargtypes[1], - ptr.proargtypes[2] - )) or - (p.pronargs > 2 and - not binary_coercible( - p.proargtypes[2], - ptr.proargtypes[3] - )) or + not binary_coercible(a.aggmtranstype, ptr.proargtypes[0]) or + (p.pronargs > 0 and not binary_coercible(p.proargtypes[0], ptr.proargtypes[1])) or + (p.pronargs > 1 and not binary_coercible(p.proargtypes[1], ptr.proargtypes[2])) or + (p.pronargs > 2 and not binary_coercible(p.proargtypes[2], ptr.proargtypes[3])) or p.pronargs > 3 ); @@ -1461,30 +1264,14 @@ where ( pfn.proretset or not binary_coercible(pfn.prorettype, p.prorettype) or - not binary_coercible( - a.aggmtranstype, - pfn.proargtypes[0] - ) or + not binary_coercible(a.aggmtranstype, pfn.proargtypes[0]) or case - when a.aggmfinalextra - then pfn.pronargs <> p.pronargs + 1 + when a.aggmfinalextra then pfn.pronargs <> p.pronargs + 1 else pfn.pronargs <> a.aggnumdirectargs + 1 end or - (pfn.pronargs > 1 and - not binary_coercible( - p.proargtypes[0], - pfn.proargtypes[1] - )) or - (pfn.pronargs > 2 and - not binary_coercible( - p.proargtypes[1], - pfn.proargtypes[2] - )) or - (pfn.pronargs > 3 and - not binary_coercible( - p.proargtypes[2], - pfn.proargtypes[3] - )) or + (pfn.pronargs > 1 and not binary_coercible(p.proargtypes[0], pfn.proargtypes[1])) or + (pfn.pronargs > 2 and not binary_coercible(p.proargtypes[1], pfn.proargtypes[2])) or + (pfn.pronargs > 3 and not binary_coercible(p.proargtypes[2], pfn.proargtypes[3])) or pfn.pronargs > 4 ); @@ -1502,10 +1289,7 @@ where a.aggmtransfn = ptr.oid and ptr.proisstrict and a.aggminitval is null and - not binary_coercible( - p.proargtypes[0], - a.aggmtranstype - ); + not binary_coercible(p.proargtypes[0], a.aggmtranstype); select cast(a.aggfnoid as oid), @@ -1547,9 +1331,7 @@ from pg_aggregate as a, pg_proc as p where - a.aggcombinefn = p.oid and - a.aggtranstype = cast('internal' as regtype) and - p.proisstrict; + a.aggcombinefn = p.oid and a.aggtranstype = cast('internal' as regtype) and p.proisstrict; select aggfnoid, @@ -1667,8 +1449,7 @@ where from pg_amop where - amopmethod = - (select oid from pg_am where amname = 'btree') and + amopmethod = (select oid from pg_am where amname = 'btree') and amopopr = o.oid and amoplefttype = o.oprleft and amoprighttype = o.oprright @@ -1687,8 +1468,7 @@ where a.aggfnoid = p.oid and a.aggsortop = o.oid and amopopr = o.oid and - amopmethod = - (select oid from pg_am where amname = 'btree') + amopmethod = (select oid from pg_am where amname = 'btree') order by 1, 2; @@ -1703,8 +1483,7 @@ where p1.proname = p2.proname and p1.prokind = 'a' and p2.prokind = 'a' and - array_dims(p1.proargtypes) <> - array_dims(p2.proargtypes) + array_dims(p1.proargtypes) <> array_dims(p2.proargtypes) order by 1; select oid, proname from pg_proc as p where prokind = 'a' and proargdefaults is not null; @@ -1713,14 +1492,9 @@ select p.oid, proname from - pg_proc as p - inner join - pg_aggregate as a - on a.aggfnoid = p.oid + pg_proc as p inner join pg_aggregate as a on a.aggfnoid = p.oid where - prokind = 'a' and - provariadic <> 0 and - a.aggkind = 'n'; + prokind = 'a' and provariadic <> 0 and a.aggkind = 'n'; select f.oid from pg_opfamily as f where f.opfmethod = 0 or f.opfnamespace = 0; @@ -1730,20 +1504,14 @@ select from pg_opfamily as f where - not exists - ( - select 1 from pg_opclass where opcfamily = f.oid - ); + not exists (select 1 from pg_opclass where opcfamily = f.oid); select c1.oid from pg_opclass as c1 where - c1.opcmethod = 0 or - c1.opcnamespace = 0 or - c1.opcfamily = 0 or - c1.opcintype = 0; + c1.opcmethod = 0 or c1.opcnamespace = 0 or c1.opcfamily = 0 or c1.opcintype = 0; select c1.oid, @@ -1752,8 +1520,7 @@ from pg_opclass as c1, pg_opfamily as f1 where - c1.opcfamily = f1.oid and - c1.opcmethod <> f1.opfmethod; + c1.opcfamily = f1.oid and c1.opcmethod <> f1.opfmethod; select c1.oid, @@ -1784,8 +1551,7 @@ where p1.oid = a1.amhandler and a1.amtype = 'i' and ( - p1.prorettype <> - cast('index_am_handler' as regtype) or + p1.prorettype <> cast('index_am_handler' as regtype) or p1.proretset or p1.pronargs <> 1 or p1.proargtypes[0] <> cast('internal' as regtype) @@ -1803,8 +1569,7 @@ where p1.oid = a1.amhandler and a1.amtype = 't' and ( - p1.prorettype <> - cast('table_am_handler' as regtype) or + p1.prorettype <> cast('table_am_handler' as regtype) or p1.proretset or p1.pronargs <> 1 or p1.proargtypes[0] <> cast('internal' as regtype) @@ -1841,18 +1606,14 @@ from pg_amop as a1, pg_opfamily as f1 where - a1.amopfamily = f1.oid and - a1.amopmethod <> f1.opfmethod; + a1.amopfamily = f1.oid and a1.amopmethod <> f1.opfmethod; select distinct amopmethod, amopstrategy, oprname from - pg_amop as a1 - left outer join - pg_operator as o1 - on amopopr = o1.oid + pg_amop as a1 left outer join pg_operator as o1 on amopopr = o1.oid order by 1, 2, 3; @@ -1866,11 +1627,7 @@ from pg_amop as a1, pg_operator as o1 where - a1.amopopr = o1.oid and - a1.amoppurpose = 's' and - ( - o1.oprrest = 0 or o1.oprjoin = 0 - ); + a1.amopopr = o1.oid and a1.amoppurpose = 's' and (o1.oprrest = 0 or o1.oprjoin = 0); select c1.opcname, @@ -1885,8 +1642,7 @@ where from pg_amop as a1 where - a1.amopfamily = c1.opcfamily and - binary_coercible(c1.opcintype, a1.amoplefttype) + a1.amopfamily = c1.opcfamily and binary_coercible(c1.opcintype, a1.amoplefttype) ); select @@ -1903,8 +1659,7 @@ where from pg_opclass as c1 where - c1.opcfamily = a1.amopfamily and - binary_coercible(c1.opcintype, a1.amoplefttype) + c1.opcfamily = a1.amopfamily and binary_coercible(c1.opcintype, a1.amoplefttype) ); select @@ -1957,9 +1712,7 @@ from pg_amproc as a1, pg_proc as p1 where - a1.amproc = p1.oid and - a1.amproclefttype = a1.amprocrighttype and - p1.provolatile <> 'i'; + a1.amproc = p1.oid and a1.amproclefttype = a1.amprocrighttype and p1.provolatile <> 'i'; select a1.amprocfamily, @@ -1969,9 +1722,7 @@ from pg_amproc as a1, pg_proc as p1 where - a1.amproc = p1.oid and - a1.amproclefttype <> a1.amprocrighttype and - p1.provolatile = 'v'; + a1.amproc = p1.oid and a1.amproclefttype <> a1.amprocrighttype and p1.provolatile = 'v'; select cast(amp.amproc as regproc) as proc, @@ -1979,21 +1730,15 @@ select opc.opcname as opclass_name, cast(opc.opcintype as regtype) as opcintype from - pg_am as am - inner join - pg_opclass as opc - on opc.opcmethod = am.oid + pg_am as am inner join pg_opclass as opc on opc.opcmethod = am.oid inner join pg_opfamily as opf on opc.opcfamily = opf.oid left outer join pg_amproc as amp - on amp.amprocfamily = opf.oid and - amp.amproclefttype = opc.opcintype and - amp.amprocnum = 4 + on amp.amprocfamily = opf.oid and amp.amproclefttype = opc.opcintype and amp.amprocnum = 4 where - am.amname = 'btree' and - amp.amproc is distinct from cast('btequalimage' as regproc) + am.amname = 'btree' and amp.amproc is distinct from cast('btequalimage' as regproc) order by 1, 2, 3; @@ -2004,10 +1749,7 @@ select from pg_index where - indexrelid = 0 or - indrelid = 0 or - indnatts <= 0 or - indnatts > 32; + indexrelid = 0 or indrelid = 0 or indnatts <= 0 or indnatts > 32; select indexrelid, @@ -2049,8 +1791,7 @@ where a.attnum = ikey and opc.oid = iclass and ( - not binary_coercible(atttypid, opcintype) or - icoll <> attcollation + not binary_coercible(atttypid, opcintype) or icoll <> attcollation ); select @@ -2096,10 +1837,7 @@ where c.oid < 16384 and c.relkind <> 'v' and attcollation <> 0 and - attcollation <> - ( - select oid from pg_collation where collname = 'C' - ); + attcollation <> (select oid from pg_collation where collname = 'C'); select cast(indexrelid as regclass), @@ -2120,8 +1858,4 @@ from ) as ss where - icoll <> 0 and - icoll <> - ( - select oid from pg_collation where collname = 'C' - ); + icoll <> 0 and icoll <> (select oid from pg_collation where collname = 'C'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__opr_sanity_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__opr_sanity_80.snap index 3131f9ace..86bc747bf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__opr_sanity_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__opr_sanity_80.snap @@ -1,6 +1,5 @@ --- source: crates/pgls_pretty_print/tests/tests.rs -assertion_line: 286 input_file: crates/pgls_pretty_print/tests/data/multi/opr_sanity.sql --- select @@ -15,14 +14,10 @@ where p1.pronargdefaults < 0 or p1.pronargdefaults > p1.pronargs or array_lower(p1.proargtypes, 1) <> 0 or - array_upper(p1.proargtypes, 1) <> - p1.pronargs - 1 or + array_upper(p1.proargtypes, 1) <> p1.pronargs - 1 or cast(0 as oid) = any (p1.proargtypes) or procost <= 0 or - case - when proretset then prorows <= 0 - else prorows <> 0 - end or + case when proretset then prorows <= 0 else prorows <> 0 end or prokind not in ('f', 'a', 'w', 'p') or provolatile not in ('i', 's', 'v') or proparallel not in ('s', 'r', 'u'); @@ -35,10 +30,7 @@ select from pg_proc as p1 where - ( - prosrc = '' or prosrc = '-' - ) and - prosqlbody is null; + (prosrc = '' or prosrc = '-') and prosqlbody is null; select p1.oid, p1.proname from pg_proc as p1 where proretset and prokind <> 'f'; @@ -50,8 +42,7 @@ select from pg_proc as p1 where - (pronargdefaults <> 0) <> - (proargdefaults is not null); + (pronargdefaults <> 0) <> (proargdefaults is not null); select p1.oid, @@ -59,12 +50,7 @@ select from pg_proc as p1 where - prolang = 13 and - ( - probin is null or - probin = '' or - probin = '-' - ); + prolang = 13 and (probin is null or probin = '' or probin = '-'); select p1.oid, @@ -286,8 +272,7 @@ select from pg_proc as p1 where - p1.prorettype = - cast('internal' as regtype) and + p1.prorettype = cast('internal' as regtype) and not cast('internal' as regtype) = any (p1.proargtypes); select @@ -352,8 +337,7 @@ select from pg_proc as p1 where - p1.prorettype = - cast('anycompatiblerange' as regtype) and + p1.prorettype = cast('anycompatiblerange' as regtype) and not cast('anycompatiblerange' as regtype) = any (p1.proargtypes) order by 2; @@ -364,27 +348,9 @@ from pg_proc as p1 where cast('cstring' as regtype) = any (p1.proargtypes) and - not exists - ( - select - 1 - from - pg_type - where - typinput = p1.oid - ) and - not exists - ( - select - 1 - from - pg_conversion - where - conproc = p1.oid - ) and - p1.oid <> - cast('shell_in(cstring)' - as regprocedure) + not exists (select 1 from pg_type where typinput = p1.oid) and + not exists (select 1 from pg_conversion where conproc = p1.oid) and + p1.oid <> cast('shell_in(cstring)' as regprocedure) order by 1; select @@ -393,28 +359,10 @@ select from pg_proc as p1 where - p1.prorettype = - cast('cstring' as regtype) and - not exists - ( - select - 1 - from - pg_type - where - typoutput = p1.oid - ) and - not exists - ( - select - 1 - from - pg_type - where - typmodout = p1.oid - ) and - p1.oid <> - cast('shell_out(void)' as regprocedure) + p1.prorettype = cast('cstring' as regtype) and + not exists (select 1 from pg_type where typoutput = p1.oid) and + not exists (select 1 from pg_type where typmodout = p1.oid) and + p1.oid <> cast('shell_out(void)' as regprocedure) order by 1; select @@ -424,8 +372,7 @@ from pg_proc as p1 where proallargtypes is not null and - array_length(proallargtypes, 1) < - array_length(proargtypes, 1); + array_length(proallargtypes, 1) < array_length(proargtypes, 1); select p1.oid, @@ -434,8 +381,7 @@ from pg_proc as p1 where proargmodes is not null and - array_length(proargmodes, 1) < - array_length(proargtypes, 1); + array_length(proargmodes, 1) < array_length(proargtypes, 1); select p1.oid, @@ -444,8 +390,7 @@ from pg_proc as p1 where proargnames is not null and - array_length(proargnames, 1) < - array_length(proargtypes, 1); + array_length(proargnames, 1) < array_length(proargtypes, 1); select p1.oid, @@ -455,8 +400,7 @@ from where proallargtypes is not null and proargmodes is not null and - array_length(proallargtypes, 1) <> - array_length(proargmodes, 1); + array_length(proallargtypes, 1) <> array_length(proargmodes, 1); select p1.oid, @@ -466,8 +410,7 @@ from where proallargtypes is not null and proargnames is not null and - array_length(proallargtypes, 1) <> - array_length(proargnames, 1); + array_length(proallargtypes, 1) <> array_length(proargnames, 1); select p1.oid, @@ -477,8 +420,7 @@ from where proargmodes is not null and proargnames is not null and - array_length(proargmodes, 1) <> - array_length(proargnames, 1); + array_length(proargmodes, 1) <> array_length(proargnames, 1); select p1.oid, @@ -495,14 +437,9 @@ where select proallargtypes[i] from - generate_series( - 1, - array_length(proallargtypes, 1) - ) - as g (i) + generate_series(1, array_length(proallargtypes, 1)) as g (i) where - proargmodes is null or - proargmodes[i] in ('i', 'b', 'v') + proargmodes is null or proargmodes[i] in ('i', 'b', 'v') ); select @@ -514,10 +451,8 @@ from where provariadic <> 0 and case proargtypes[array_length(proargtypes, 1) - 1] - when cast('"any"' as regtype) - then cast('"any"' as regtype) - when cast('anyarray' as regtype) - then cast('anyelement' as regtype) + when cast('"any"' as regtype) then cast('"any"' as regtype) + when cast('anyarray' as regtype) then cast('anyelement' as regtype) when cast('anycompatiblearray' as regtype) then cast('anycompatible' as regtype) else ( @@ -526,8 +461,7 @@ where from pg_type as t where - t.typarray = - proargtypes[array_length(proargtypes, 1) - 1] + t.typarray = proargtypes[array_length(proargtypes, 1) - 1] ) end <> provariadic; @@ -553,12 +487,10 @@ from where p2.oid = p1.prosupport and ( - p2.prorettype <> - cast('internal' as regtype) or + p2.prorettype <> cast('internal' as regtype) or p2.proretset or p2.pronargs <> 1 or - p2.proargtypes[0] <> - cast('internal' as regtype) + p2.proargtypes[0] <> cast('internal' as regtype) ); select @@ -568,19 +500,14 @@ from pg_proc as p1 left outer join pg_description as d - on p1.tableoid = d.classoid and - p1.oid = d.objoid and - d.objsubid = 0 + on p1.tableoid = d.classoid and p1.oid = d.objoid and d.objsubid = 0 where d.classoid is null and p1.oid <= 9999; select cast(p1.oid as regprocedure) from - pg_proc as p1 - inner join - pg_namespace as pn - on pronamespace = pn.oid + pg_proc as p1 inner join pg_namespace as pn on pronamespace = pn.oid where nspname = 'pg_catalog' and proleakproof order by 1; @@ -588,14 +515,9 @@ order by 1; select cast(p1.oid as regprocedure) from - pg_proc as p1 - inner join - pg_namespace as pn - on pronamespace = pn.oid + pg_proc as p1 inner join pg_namespace as pn on pronamespace = pn.oid where - nspname = 'pg_catalog' and - proleakproof and - pronargs = 0 + nspname = 'pg_catalog' and proleakproof and pronargs = 0 order by 1; select @@ -611,14 +533,7 @@ where 'loread', 'lowrite' ) and pronamespace = - ( - select - oid - from - pg_catalog.pg_namespace - where - nspname = 'pg_catalog' - ) + (select oid from pg_catalog.pg_namespace where nspname = 'pg_catalog') order by 1; select @@ -645,8 +560,7 @@ from pg_cast as c where (castmethod = 'f' and castfunc = 0) or - (castmethod in ('b', 'i') and - castfunc <> 0); + (castmethod in ('b', 'i') and castfunc <> 0); select * from pg_cast as c where castsource = casttarget and castfunc = 0; @@ -656,9 +570,7 @@ from pg_cast as c, pg_proc as p where - c.castfunc = p.oid and - p.pronargs < 2 and - castsource = casttarget; + c.castfunc = p.oid and p.pronargs < 2 and castsource = casttarget; select c.* @@ -671,19 +583,11 @@ where p.pronargs < 1 or p.pronargs > 3 or not ( - binary_coercible( - c.castsource, - p.proargtypes[0] - ) or - (c.castsource = - cast('character' as regtype) and - p.proargtypes[0] = - cast('text' as regtype)) + binary_coercible(c.castsource, p.proargtypes[0]) or + (c.castsource = cast('character' as regtype) and + p.proargtypes[0] = cast('text' as regtype)) ) or - not binary_coercible( - p.prorettype, - c.casttarget - ) + not binary_coercible(p.prorettype, c.casttarget) ); select @@ -694,12 +598,8 @@ from where c.castfunc = p.oid and ( - (p.pronargs > 1 and - p.proargtypes[1] <> - cast('int4' as regtype)) or - (p.pronargs > 2 and - p.proargtypes[2] <> - cast('bool' as regtype)) + (p.pronargs > 1 and p.proargtypes[1] <> cast('int4' as regtype)) or + (p.pronargs > 2 and p.proargtypes[2] <> cast('bool' as regtype)) ); select @@ -747,18 +647,12 @@ where p.prorettype <> cast('int4' as regtype) or p.proretset or p.pronargs <> 6 or - p.proargtypes[0] <> - cast('int4' as regtype) or - p.proargtypes[1] <> - cast('int4' as regtype) or - p.proargtypes[2] <> - cast('cstring' as regtype) or - p.proargtypes[3] <> - cast('internal' as regtype) or - p.proargtypes[4] <> - cast('int4' as regtype) or - p.proargtypes[5] <> - cast('bool' as regtype) + p.proargtypes[0] <> cast('int4' as regtype) or + p.proargtypes[1] <> cast('int4' as regtype) or + p.proargtypes[2] <> cast('cstring' as regtype) or + p.proargtypes[3] <> cast('internal' as regtype) or + p.proargtypes[4] <> cast('int4' as regtype) or + p.proargtypes[5] <> cast('bool' as regtype) ); select @@ -855,8 +749,7 @@ from pg_operator as o1, pg_operator as o2 where - o1.oprcom = o2.oid and - o1.oprname <= o2.oprname + o1.oprcom = o2.oid and o1.oprname <= o2.oprname order by 1, 2; @@ -867,8 +760,7 @@ from pg_operator as o1, pg_operator as o2 where - o1.oprnegate = o2.oid and - o1.oprname <= o2.oprname + o1.oprnegate = o2.oid and o1.oprname <= o2.oprname order by 1, 2; @@ -898,8 +790,7 @@ from where o1.oprcom = o2.oid and ( - o1.oprcanmerge <> o2.oprcanmerge or - o1.oprcanhash <> o2.oprcanhash + o1.oprcanmerge <> o2.oprcanmerge or o1.oprcanhash <> o2.oprcanhash ); select @@ -916,15 +807,7 @@ where from pg_amop where - amopmethod = - ( - select - oid - from - pg_am - where - amname = 'btree' - ) and + amopmethod = (select oid from pg_am where amname = 'btree') and amopopr = o1.oid and amopstrategy = 3 ); @@ -938,15 +821,7 @@ from pg_amop as p where amopopr = o1.oid and - amopmethod = - ( - select - oid - from - pg_am - where - amname = 'btree' - ) and + amopmethod = (select oid from pg_am where amname = 'btree') and amopstrategy = 3 and not o1.oprcanmerge; @@ -964,15 +839,7 @@ where from pg_amop where - amopmethod = - ( - select - oid - from - pg_am - where - amname = 'hash' - ) and + amopmethod = (select oid from pg_am where amname = 'hash') and amopopr = o1.oid and amopstrategy = 1 ); @@ -986,15 +853,7 @@ from pg_amop as p where amopopr = o1.oid and - amopmethod = - ( - select - oid - from - pg_am - where - amname = 'hash' - ) and + amopmethod = (select oid from pg_am where amname = 'hash') and not o1.oprcanhash; select @@ -1010,18 +869,9 @@ where o1.oprkind = 'b' and ( p1.pronargs <> 2 or - not binary_coercible( - p1.prorettype, - o1.oprresult - ) or - not binary_coercible( - o1.oprleft, - p1.proargtypes[0] - ) or - not binary_coercible( - o1.oprright, - p1.proargtypes[1] - ) + not binary_coercible(p1.prorettype, o1.oprresult) or + not binary_coercible(o1.oprleft, p1.proargtypes[0]) or + not binary_coercible(o1.oprright, p1.proargtypes[1]) ); select @@ -1037,14 +887,8 @@ where o1.oprkind = 'l' and ( p1.pronargs <> 1 or - not binary_coercible( - p1.prorettype, - o1.oprresult - ) or - not binary_coercible( - o1.oprright, - p1.proargtypes[0] - ) or + not binary_coercible(p1.prorettype, o1.oprresult) or + not binary_coercible(o1.oprright, p1.proargtypes[0]) or o1.oprleft <> 0 ); @@ -1075,18 +919,13 @@ where o1.oprrest = p2.oid and ( o1.oprresult <> cast('bool' as regtype) or - p2.prorettype <> - cast('float8' as regtype) or + p2.prorettype <> cast('float8' as regtype) or p2.proretset or p2.pronargs <> 4 or - p2.proargtypes[0] <> - cast('internal' as regtype) or - p2.proargtypes[1] <> - cast('oid' as regtype) or - p2.proargtypes[2] <> - cast('internal' as regtype) or - p2.proargtypes[3] <> - cast('int4' as regtype) + p2.proargtypes[0] <> cast('internal' as regtype) or + p2.proargtypes[1] <> cast('oid' as regtype) or + p2.proargtypes[2] <> cast('internal' as regtype) or + p2.proargtypes[3] <> cast('int4' as regtype) ); select @@ -1102,20 +941,14 @@ where ( o1.oprkind <> 'b' or o1.oprresult <> cast('bool' as regtype) or - p2.prorettype <> - cast('float8' as regtype) or + p2.prorettype <> cast('float8' as regtype) or p2.proretset or p2.pronargs <> 5 or - p2.proargtypes[0] <> - cast('internal' as regtype) or - p2.proargtypes[1] <> - cast('oid' as regtype) or - p2.proargtypes[2] <> - cast('internal' as regtype) or - p2.proargtypes[3] <> - cast('int2' as regtype) or - p2.proargtypes[4] <> - cast('internal' as regtype) + p2.proargtypes[0] <> cast('internal' as regtype) or + p2.proargtypes[1] <> cast('oid' as regtype) or + p2.proargtypes[2] <> cast('internal' as regtype) or + p2.proargtypes[3] <> cast('int2' as regtype) or + p2.proargtypes[4] <> cast('internal' as regtype) ); select @@ -1125,9 +958,7 @@ from pg_operator as o1 left outer join pg_description as d - on o1.tableoid = d.classoid and - o1.oid = d.objoid and - d.objsubid = 0 + on o1.tableoid = d.classoid and o1.oid = d.objoid and d.objsubid = 0 where d.classoid is null and o1.oid <= 9999; @@ -1139,25 +970,16 @@ as ( proname, o.oid as o_oid, pd.description as prodesc, - 'implementation of ' || oprname || - ' operator' - as expecteddesc, + 'implementation of ' || oprname || ' operator' as expecteddesc, od.description as oprdesc from - pg_proc as p - inner join - pg_operator as o - on oprcode = p.oid + pg_proc as p inner join pg_operator as o on oprcode = p.oid left outer join pg_description as pd - on pd.objoid = p.oid and - pd.classoid = p.tableoid and - pd.objsubid = 0 + on pd.objoid = p.oid and pd.classoid = p.tableoid and pd.objsubid = 0 left outer join pg_description as od - on od.objoid = o.oid and - od.classoid = o.tableoid and - od.objsubid = 0 + on od.objoid = o.oid and od.classoid = o.tableoid and od.objsubid = 0 where o.oid <= 9999 ) @@ -1178,25 +1000,16 @@ as ( proname, o.oid as o_oid, pd.description as prodesc, - 'implementation of ' || oprname || - ' operator' - as expecteddesc, + 'implementation of ' || oprname || ' operator' as expecteddesc, od.description as oprdesc from - pg_proc as p - inner join - pg_operator as o - on oprcode = p.oid + pg_proc as p inner join pg_operator as o on oprcode = p.oid left outer join pg_description as pd - on pd.objoid = p.oid and - pd.classoid = p.tableoid and - pd.objsubid = 0 + on pd.objoid = p.oid and pd.classoid = p.tableoid and pd.objsubid = 0 left outer join pg_description as od - on od.objoid = o.oid and - od.classoid = o.tableoid and - od.objsubid = 0 + on od.objoid = o.oid and od.classoid = o.tableoid and od.objsubid = 0 where o.oid <= 9999 ) @@ -1207,8 +1020,7 @@ select from funcdescs where - prodesc is distinct from expecteddesc and - oprdesc not like 'deprecated%' + prodesc is distinct from expecteddesc and oprdesc not like 'deprecated%' order by 1; select @@ -1226,8 +1038,7 @@ where p1.oid = o1.oprcode and p2.oid = o2.oprcode and ( - p1.provolatile <> p2.provolatile or - p1.proleakproof <> p2.proleakproof + p1.provolatile <> p2.provolatile or p1.proleakproof <> p2.proleakproof ); select @@ -1245,8 +1056,7 @@ where p1.oid = o1.oprcode and p2.oid = o2.oprcode and ( - p1.provolatile <> p2.provolatile or - p1.proleakproof <> p2.proleakproof + p1.provolatile <> p2.provolatile or p1.proleakproof <> p2.proleakproof ); select @@ -1266,22 +1076,13 @@ where pp.oid = ap.amproc and po.oid = o.oprcode and o.oid = ao.amopopr and - ao.amopmethod = - ( - select - oid - from - pg_am - where - amname = 'btree' - ) and + ao.amopmethod = (select oid from pg_am where amname = 'btree') and ao.amopfamily = ap.amprocfamily and ao.amoplefttype = ap.amproclefttype and ao.amoprighttype = ap.amprocrighttype and ap.amprocnum = 1 and ( - pp.provolatile <> po.provolatile or - pp.proleakproof <> po.proleakproof + pp.provolatile <> po.provolatile or pp.proleakproof <> po.proleakproof ) order by 1; @@ -1311,9 +1112,7 @@ from where a.aggfnoid = p.oid and ( - p.prokind <> 'a' or - p.proretset or - p.pronargs < a.aggnumdirectargs + p.prokind <> 'a' or p.proretset or p.pronargs < a.aggnumdirectargs ); select @@ -1323,15 +1122,7 @@ from pg_proc as p where p.prokind = 'a' and - not exists - ( - select - 1 - from - pg_aggregate as a - where - a.aggfnoid = p.oid - ); + not exists (select 1 from pg_aggregate as a where a.aggfnoid = p.oid); select cast(a.aggfnoid as oid), @@ -1340,9 +1131,7 @@ from pg_aggregate as a, pg_proc as p where - a.aggfnoid = p.oid and - a.aggfinalfn = 0 and - p.prorettype <> a.aggtranstype; + a.aggfnoid = p.oid and a.aggfinalfn = 0 and p.prorettype <> a.aggtranstype; select cast(a.aggfnoid as oid), @@ -1361,40 +1150,18 @@ where not ptr.pronargs = case when a.aggkind = 'n' then p.pronargs + 1 - else greatest( - p.pronargs - a.aggnumdirectargs, - 1 - ) + - 1 + else greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 end or - not binary_coercible( - ptr.prorettype, - a.aggtranstype - ) or - not binary_coercible( - a.aggtranstype, - ptr.proargtypes[0] - ) or + not binary_coercible(ptr.prorettype, a.aggtranstype) or + not binary_coercible(a.aggtranstype, ptr.proargtypes[0]) or (p.pronargs > 0 and - not binary_coercible( - p.proargtypes[0], - ptr.proargtypes[1] - )) or + not binary_coercible(p.proargtypes[0], ptr.proargtypes[1])) or (p.pronargs > 1 and - not binary_coercible( - p.proargtypes[1], - ptr.proargtypes[2] - )) or + not binary_coercible(p.proargtypes[1], ptr.proargtypes[2])) or (p.pronargs > 2 and - not binary_coercible( - p.proargtypes[2], - ptr.proargtypes[3] - )) or + not binary_coercible(p.proargtypes[2], ptr.proargtypes[3])) or (p.pronargs > 3 and - not binary_coercible( - p.proargtypes[3], - ptr.proargtypes[4] - )) or + not binary_coercible(p.proargtypes[3], ptr.proargtypes[4])) or p.pronargs > 4 ); @@ -1412,34 +1179,18 @@ where a.aggfinalfn = pfn.oid and ( pfn.proretset or - not binary_coercible( - pfn.prorettype, - p.prorettype - ) or - not binary_coercible( - a.aggtranstype, - pfn.proargtypes[0] - ) or + not binary_coercible(pfn.prorettype, p.prorettype) or + not binary_coercible(a.aggtranstype, pfn.proargtypes[0]) or case - when a.aggfinalextra - then pfn.pronargs <> p.pronargs + 1 + when a.aggfinalextra then pfn.pronargs <> p.pronargs + 1 else pfn.pronargs <> a.aggnumdirectargs + 1 end or (pfn.pronargs > 1 and - not binary_coercible( - p.proargtypes[0], - pfn.proargtypes[1] - )) or + not binary_coercible(p.proargtypes[0], pfn.proargtypes[1])) or (pfn.pronargs > 2 and - not binary_coercible( - p.proargtypes[1], - pfn.proargtypes[2] - )) or + not binary_coercible(p.proargtypes[1], pfn.proargtypes[2])) or (pfn.pronargs > 3 and - not binary_coercible( - p.proargtypes[2], - pfn.proargtypes[3] - )) or + not binary_coercible(p.proargtypes[2], pfn.proargtypes[3])) or pfn.pronargs > 4 ); @@ -1457,10 +1208,7 @@ where a.aggtransfn = ptr.oid and ptr.proisstrict and a.agginitval is null and - not binary_coercible( - p.proargtypes[0], - a.aggtranstype - ); + not binary_coercible(p.proargtypes[0], a.aggtranstype); select ctid, @@ -1468,10 +1216,7 @@ select from pg_aggregate as a where - aggmtranstype <> 0 and - ( - aggmtransfn = 0 or aggminvtransfn = 0 - ); + aggmtranstype <> 0 and (aggmtransfn = 0 or aggminvtransfn = 0); select ctid, @@ -1517,35 +1262,16 @@ where not ptr.pronargs = case when a.aggkind = 'n' then p.pronargs + 1 - else greatest( - p.pronargs - a.aggnumdirectargs, - 1 - ) + - 1 + else greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 end or - not binary_coercible( - ptr.prorettype, - a.aggmtranstype - ) or - not binary_coercible( - a.aggmtranstype, - ptr.proargtypes[0] - ) or + not binary_coercible(ptr.prorettype, a.aggmtranstype) or + not binary_coercible(a.aggmtranstype, ptr.proargtypes[0]) or (p.pronargs > 0 and - not binary_coercible( - p.proargtypes[0], - ptr.proargtypes[1] - )) or + not binary_coercible(p.proargtypes[0], ptr.proargtypes[1])) or (p.pronargs > 1 and - not binary_coercible( - p.proargtypes[1], - ptr.proargtypes[2] - )) or + not binary_coercible(p.proargtypes[1], ptr.proargtypes[2])) or (p.pronargs > 2 and - not binary_coercible( - p.proargtypes[2], - ptr.proargtypes[3] - )) or + not binary_coercible(p.proargtypes[2], ptr.proargtypes[3])) or p.pronargs > 3 ); @@ -1566,35 +1292,16 @@ where not ptr.pronargs = case when a.aggkind = 'n' then p.pronargs + 1 - else greatest( - p.pronargs - a.aggnumdirectargs, - 1 - ) + - 1 + else greatest(p.pronargs - a.aggnumdirectargs, 1) + 1 end or - not binary_coercible( - ptr.prorettype, - a.aggmtranstype - ) or - not binary_coercible( - a.aggmtranstype, - ptr.proargtypes[0] - ) or + not binary_coercible(ptr.prorettype, a.aggmtranstype) or + not binary_coercible(a.aggmtranstype, ptr.proargtypes[0]) or (p.pronargs > 0 and - not binary_coercible( - p.proargtypes[0], - ptr.proargtypes[1] - )) or + not binary_coercible(p.proargtypes[0], ptr.proargtypes[1])) or (p.pronargs > 1 and - not binary_coercible( - p.proargtypes[1], - ptr.proargtypes[2] - )) or + not binary_coercible(p.proargtypes[1], ptr.proargtypes[2])) or (p.pronargs > 2 and - not binary_coercible( - p.proargtypes[2], - ptr.proargtypes[3] - )) or + not binary_coercible(p.proargtypes[2], ptr.proargtypes[3])) or p.pronargs > 3 ); @@ -1612,34 +1319,18 @@ where a.aggmfinalfn = pfn.oid and ( pfn.proretset or - not binary_coercible( - pfn.prorettype, - p.prorettype - ) or - not binary_coercible( - a.aggmtranstype, - pfn.proargtypes[0] - ) or + not binary_coercible(pfn.prorettype, p.prorettype) or + not binary_coercible(a.aggmtranstype, pfn.proargtypes[0]) or case - when a.aggmfinalextra - then pfn.pronargs <> p.pronargs + 1 + when a.aggmfinalextra then pfn.pronargs <> p.pronargs + 1 else pfn.pronargs <> a.aggnumdirectargs + 1 end or (pfn.pronargs > 1 and - not binary_coercible( - p.proargtypes[0], - pfn.proargtypes[1] - )) or + not binary_coercible(p.proargtypes[0], pfn.proargtypes[1])) or (pfn.pronargs > 2 and - not binary_coercible( - p.proargtypes[1], - pfn.proargtypes[2] - )) or + not binary_coercible(p.proargtypes[1], pfn.proargtypes[2])) or (pfn.pronargs > 3 and - not binary_coercible( - p.proargtypes[2], - pfn.proargtypes[3] - )) or + not binary_coercible(p.proargtypes[2], pfn.proargtypes[3])) or pfn.pronargs > 4 ); @@ -1657,10 +1348,7 @@ where a.aggmtransfn = ptr.oid and ptr.proisstrict and a.aggminitval is null and - not binary_coercible( - p.proargtypes[0], - a.aggmtranstype - ); + not binary_coercible(p.proargtypes[0], a.aggmtranstype); select cast(a.aggfnoid as oid), @@ -1692,10 +1380,7 @@ where p.pronargs <> 2 or p.prorettype <> p.proargtypes[0] or p.prorettype <> p.proargtypes[1] or - not binary_coercible( - a.aggtranstype, - p.proargtypes[0] - ) + not binary_coercible(a.aggtranstype, p.proargtypes[0]) ); select @@ -1706,8 +1391,7 @@ from pg_proc as p where a.aggcombinefn = p.oid and - a.aggtranstype = - cast('internal' as regtype) and + a.aggtranstype = cast('internal' as regtype) and p.proisstrict; select @@ -1722,8 +1406,7 @@ where aggserialfn <> 0 or aggdeserialfn <> 0 ) and ( - aggtranstype <> - cast('internal' as regtype) or + aggtranstype <> cast('internal' as regtype) or aggcombinefn = 0 or aggserialfn = 0 or aggdeserialfn = 0 @@ -1740,8 +1423,7 @@ where ( p.prorettype <> cast('bytea' as regtype) or p.pronargs <> 1 or - p.proargtypes[0] <> - cast('internal' as regtype) or + p.proargtypes[0] <> cast('internal' as regtype) or not p.proisstrict ); @@ -1754,13 +1436,10 @@ from where a.aggdeserialfn = p.oid and ( - p.prorettype <> - cast('internal' as regtype) or + p.prorettype <> cast('internal' as regtype) or p.pronargs <> 2 or - p.proargtypes[0] <> - cast('bytea' as regtype) or - p.proargtypes[1] <> - cast('internal' as regtype) or + p.proargtypes[0] <> cast('bytea' as regtype) or + p.proargtypes[1] <> cast('internal' as regtype) or not p.proisstrict ); @@ -1793,8 +1472,7 @@ from pg_aggregate as a, pg_proc as p where - a.aggfnoid = p.oid and - a.aggsortop = o.oid + a.aggfnoid = p.oid and a.aggsortop = o.oid order by 1, 2; @@ -1832,15 +1510,7 @@ where from pg_amop where - amopmethod = - ( - select - oid - from - pg_am - where - amname = 'btree' - ) and + amopmethod = (select oid from pg_am where amname = 'btree') and amopopr = o.oid and amoplefttype = o.oprleft and amoprighttype = o.oprright @@ -1859,15 +1529,7 @@ where a.aggfnoid = p.oid and a.aggsortop = o.oid and amopopr = o.oid and - amopmethod = - ( - select - oid - from - pg_am - where - amname = 'btree' - ) + amopmethod = (select oid from pg_am where amname = 'btree') order by 1, 2; @@ -1882,8 +1544,7 @@ where p1.proname = p2.proname and p1.prokind = 'a' and p2.prokind = 'a' and - array_dims(p1.proargtypes) <> - array_dims(p2.proargtypes) + array_dims(p1.proargtypes) <> array_dims(p2.proargtypes) order by 1; select @@ -1892,21 +1553,15 @@ select from pg_proc as p where - prokind = 'a' and - proargdefaults is not null; + prokind = 'a' and proargdefaults is not null; select p.oid, proname from - pg_proc as p - inner join - pg_aggregate as a - on a.aggfnoid = p.oid + pg_proc as p inner join pg_aggregate as a on a.aggfnoid = p.oid where - prokind = 'a' and - provariadic <> 0 and - a.aggkind = 'n'; + prokind = 'a' and provariadic <> 0 and a.aggkind = 'n'; select f.oid from pg_opfamily as f where f.opfmethod = 0 or f.opfnamespace = 0; @@ -1916,15 +1571,7 @@ select from pg_opfamily as f where - not exists - ( - select - 1 - from - pg_opclass - where - opcfamily = f.oid - ); + not exists (select 1 from pg_opclass where opcfamily = f.oid); select c1.oid @@ -1943,8 +1590,7 @@ from pg_opclass as c1, pg_opfamily as f1 where - c1.opcfamily = f1.oid and - c1.opcmethod <> f1.opfmethod; + c1.opcfamily = f1.oid and c1.opcmethod <> f1.opfmethod; select c1.oid, @@ -1975,12 +1621,10 @@ where p1.oid = a1.amhandler and a1.amtype = 'i' and ( - p1.prorettype <> - cast('index_am_handler' as regtype) or + p1.prorettype <> cast('index_am_handler' as regtype) or p1.proretset or p1.pronargs <> 1 or - p1.proargtypes[0] <> - cast('internal' as regtype) + p1.proargtypes[0] <> cast('internal' as regtype) ); select @@ -1995,12 +1639,10 @@ where p1.oid = a1.amhandler and a1.amtype = 't' and ( - p1.prorettype <> - cast('table_am_handler' as regtype) or + p1.prorettype <> cast('table_am_handler' as regtype) or p1.proretset or p1.pronargs <> 1 or - p1.proargtypes[0] <> - cast('internal' as regtype) + p1.proargtypes[0] <> cast('internal' as regtype) ); select @@ -2023,10 +1665,8 @@ from pg_amop as a1 where not ( - (a1.amoppurpose = 's' and - a1.amopsortfamily = 0) or - (a1.amoppurpose = 'o' and - a1.amopsortfamily <> 0) + (a1.amoppurpose = 's' and a1.amopsortfamily = 0) or + (a1.amoppurpose = 'o' and a1.amopsortfamily <> 0) ); select @@ -2036,18 +1676,14 @@ from pg_amop as a1, pg_opfamily as f1 where - a1.amopfamily = f1.oid and - a1.amopmethod <> f1.opfmethod; + a1.amopfamily = f1.oid and a1.amopmethod <> f1.opfmethod; select distinct amopmethod, amopstrategy, oprname from - pg_amop as a1 - left outer join - pg_operator as o1 - on amopopr = o1.oid + pg_amop as a1 left outer join pg_operator as o1 on amopopr = o1.oid order by 1, 2, 3; @@ -2081,10 +1717,7 @@ where pg_amop as a1 where a1.amopfamily = c1.opcfamily and - binary_coercible( - c1.opcintype, - a1.amoplefttype - ) + binary_coercible(c1.opcintype, a1.amoplefttype) ); select @@ -2102,10 +1735,7 @@ where pg_opclass as c1 where c1.opcfamily = a1.amopfamily and - binary_coercible( - c1.opcintype, - a1.amoplefttype - ) + binary_coercible(c1.opcintype, a1.amoplefttype) ); select @@ -2178,13 +1808,9 @@ select cast(amp.amproc as regproc) as proc, opf.opfname as opfamily_name, opc.opcname as opclass_name, - cast(opc.opcintype as regtype) - as opcintype + cast(opc.opcintype as regtype) as opcintype from - pg_am as am - inner join - pg_opclass as opc - on opc.opcmethod = am.oid + pg_am as am inner join pg_opclass as opc on opc.opcmethod = am.oid inner join pg_opfamily as opf on opc.opcfamily = opf.oid @@ -2206,10 +1832,7 @@ select from pg_index where - indexrelid = 0 or - indrelid = 0 or - indnatts <= 0 or - indnatts > 32; + indexrelid = 0 or indrelid = 0 or indnatts <= 0 or indnatts > 32; select indexrelid, @@ -2222,11 +1845,9 @@ where array_lower(indclass, 1) <> 0 or array_upper(indclass, 1) <> indnatts - 1 or array_lower(indcollation, 1) <> 0 or - array_upper(indcollation, 1) <> - indnatts - 1 or + array_upper(indcollation, 1) <> indnatts - 1 or array_lower(indoption, 1) <> 0 or - array_upper(indoption, 1) <> - indnatts - 1; + array_upper(indoption, 1) <> indnatts - 1; select cast(indexrelid as regclass), @@ -2253,8 +1874,7 @@ where a.attnum = ikey and opc.oid = iclass and ( - not binary_coercible(atttypid, opcintype) or - icoll <> attcollation + not binary_coercible(atttypid, opcintype) or icoll <> attcollation ); select @@ -2284,8 +1904,7 @@ where a.attnum = ikey and opc.oid = iclass and ( - opcintype <> atttypid or - icoll <> attcollation + opcintype <> atttypid or icoll <> attcollation ) order by 1; @@ -2301,15 +1920,7 @@ where c.oid < 16384 and c.relkind <> 'v' and attcollation <> 0 and - attcollation <> - ( - select - oid - from - pg_collation - where - collname = 'C' - ); + attcollation <> (select oid from pg_collation where collname = 'C'); select cast(indexrelid as regclass), @@ -2330,13 +1941,4 @@ from ) as ss where - icoll <> 0 and - icoll <> - ( - select - oid - from - pg_collation - where - collname = 'C' - ); + icoll <> 0 and icoll <> (select oid from pg_collation where collname = 'C'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__ordered_set_filter_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__ordered_set_filter_100.snap index 4f898228c..acb951da6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__ordered_set_filter_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__ordered_set_filter_100.snap @@ -4,26 +4,11 @@ input_file: crates/pgls_pretty_print/tests/data/multi/ordered_set_filter.sql snapshot_kind: text --- select - percentile_disc( - 0.5 - ) - within group (order by score) - filter (where - score > 0) + percentile_disc(0.5) within group (order by score) filter (where score > 0) from (values (1), (2), (3)) as scores (score); select - percentile_cont( - 0.9 - ) - within group (order by duration) - filter (where - duration is not null) + percentile_cont(0.9) within group (order by duration) filter (where duration is not null) from - ( - values - (cast('1 hour' as interval)), - (cast('2 hours' as interval)) - ) - as durations (duration); + (values (cast('1 hour' as interval)), (cast('2 hours' as interval))) as durations (duration); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__ordered_set_filter_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__ordered_set_filter_80.snap index 4f898228c..aa0bfb3ce 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__ordered_set_filter_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__ordered_set_filter_80.snap @@ -4,12 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/ordered_set_filter.sql snapshot_kind: text --- select - percentile_disc( - 0.5 - ) - within group (order by score) - filter (where - score > 0) + percentile_disc(0.5) within group (order by score) filter (where score > 0) from (values (1), (2), (3)) as scores (score); @@ -22,8 +17,6 @@ select duration is not null) from ( - values - (cast('1 hour' as interval)), - (cast('2 hours' as interval)) + values (cast('1 hour' as interval)), (cast('2 hours' as interval)) ) as durations (duration); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_aggregate_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_aggregate_100.snap index 042d2e9bf..610d59127 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_aggregate_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_aggregate_100.snap @@ -17,118 +17,108 @@ create table pagg_tab ( c text, d int ) -partition by LIST(c); +partition by list(c); create table pagg_tab_p1 partition of pagg_tab -for values in ('0000', -'0001', -'0002', -'0003', -'0004'); +for values in ('0000', '0001', '0002', '0003', '0004'); create table pagg_tab_p2 partition of pagg_tab for values in ('0005', '0006', '0007', '0008'); create table pagg_tab_p3 partition of pagg_tab for values in ('0009', '0010', '0011'); insert into pagg_tab -select - i % 20, - i % 30, - to_char(i % 12, 'FM0000'), - i % 30 -from - generate_series(0, 2999) as i; +select i % 20, i % 30, to_char(i % 12, 'FM0000'), i % 30 from generate_series(0, 2999) as i; analyze pagg_tab; select c, - SUM(a), - AVG(b), - COUNT(*), - MIN(a), - MAX(b) + sum(a), + avg(b), + count(*), + min(a), + max(b) from pagg_tab group by c having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select c, - SUM(a), - AVG(b), - COUNT(*), - MIN(a), - MAX(b) + sum(a), + avg(b), + count(*), + min(a), + max(b) from pagg_tab group by c having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select a, - SUM(b), - AVG(b), - COUNT(*), - MIN(a), - MAX(b) + sum(b), + avg(b), + count(*), + min(a), + max(b) from pagg_tab group by a having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select a, - SUM(b), - AVG(b), - COUNT(*), - MIN(a), - MAX(b) + sum(b), + avg(b), + count(*), + min(a), + max(b) from pagg_tab group by a having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; -select a, c, COUNT(*) from pagg_tab group by a, c; +select a, c, count(*) from pagg_tab group by a, c; -select a, c, COUNT(*) from pagg_tab group by c, a; +select a, c, count(*) from pagg_tab group by c, a; -select c, a, COUNT(*) from pagg_tab group by a, c; +select c, a, count(*) from pagg_tab group by a, c; -select c, SUM(a) from pagg_tab where 1 = 2 group by c; +select c, sum(a) from pagg_tab where 1 = 2 group by c; -select c, SUM(a) from pagg_tab where 1 = 2 group by c; +select c, sum(a) from pagg_tab where 1 = 2 group by c; -select c, SUM(a) from pagg_tab where c = 'x' group by c; +select c, sum(a) from pagg_tab where c = 'x' group by c; -select c, SUM(a) from pagg_tab where c = 'x' group by c; +select c, sum(a) from pagg_tab where c = 'x' group by c; set enable_hashagg = 'false'; -select c, SUM(a), AVG(b), COUNT(*) from pagg_tab group by 1 having AVG(d) < 15 order by 1, 2, 3; +select c, sum(a), avg(b), count(*) from pagg_tab group by 1 having avg(d) < 15 order by 1, 2, 3; -select c, SUM(a), AVG(b), COUNT(*) from pagg_tab group by 1 having AVG(d) < 15 order by 1, 2, 3; +select c, sum(a), avg(b), count(*) from pagg_tab group by 1 having avg(d) < 15 order by 1, 2, 3; -select a, SUM(b), AVG(b), COUNT(*) from pagg_tab group by 1 having AVG(d) < 15 order by 1, 2, 3; +select a, sum(b), avg(b), count(*) from pagg_tab group by 1 having avg(d) < 15 order by 1, 2, 3; -select a, SUM(b), AVG(b), COUNT(*) from pagg_tab group by 1 having AVG(d) < 15 order by 1, 2, 3; +select a, sum(b), avg(b), count(*) from pagg_tab group by 1 having avg(d) < 15 order by 1, 2, 3; select c from pagg_tab group by c order by 1; @@ -140,11 +130,11 @@ select a from pagg_tab where a < 3 group by a order by 1; reset enable_hashagg; -select c, SUM(a) from pagg_tab group by rollup (c) order by 1, 2; +select c, sum(a) from pagg_tab group by rollup (c) order by 1, 2; -select c, SUM(b order by a) from pagg_tab group by c order by 1, 2; +select c, sum(b order by a) from pagg_tab group by c order by 1, 2; -select a, SUM(b order by a) from pagg_tab group by a order by 1, 2; +select a, sum(b order by a) from pagg_tab group by a order by 1, 2; create table pagg_tab1 ( x int, @@ -180,8 +170,8 @@ analyze pagg_tab2; select t1.x, - SUM(t1.y), - COUNT(*) + sum(t1.y), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -194,8 +184,8 @@ order by 1, select t1.x, - SUM(t1.y), - COUNT(*) + sum(t1.y), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -208,8 +198,8 @@ order by 1, select t1.x, - SUM(t1.y), - COUNT(t1) + sum(t1.y), + count(t1) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -222,8 +212,8 @@ order by 1, select t1.x, - SUM(t1.y), - COUNT(t1) + sum(t1.y), + count(t1) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -236,8 +226,8 @@ order by 1, select t2.y, - SUM(t1.y), - COUNT(*) + sum(t1.y), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -252,8 +242,8 @@ set enable_hashagg = 'false'; select t1.y, - SUM(t1.x), - COUNT(*) + sum(t1.x), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -261,15 +251,15 @@ where t1.x = t2.y group by t1.y having - AVG(t1.x) > 10 + avg(t1.x) > 10 order by 1, 2, 3; select t1.y, - SUM(t1.x), - COUNT(*) + sum(t1.x), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -277,7 +267,7 @@ where t1.x = t2.y group by t1.y having - AVG(t1.x) > 10 + avg(t1.x) > 10 order by 1, 2, 3; @@ -286,74 +276,56 @@ reset enable_hashagg; select b.y, - SUM(a.y) + sum(a.y) from - pagg_tab1 as a - left outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a left outer join pagg_tab2 as b on a.x = b.y group by b.y order by 1 nulls last; select b.y, - SUM(a.y) + sum(a.y) from - pagg_tab1 as a - left outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a left outer join pagg_tab2 as b on a.x = b.y group by b.y order by 1 nulls last; select b.y, - SUM(a.y) + sum(a.y) from - pagg_tab1 as a - right outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a right outer join pagg_tab2 as b on a.x = b.y group by b.y order by 1 nulls last; select b.y, - SUM(a.y) + sum(a.y) from - pagg_tab1 as a - right outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a right outer join pagg_tab2 as b on a.x = b.y group by b.y order by 1 nulls last; select a.x, - SUM(b.x) + sum(b.x) from - pagg_tab1 as a - full outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a full outer join pagg_tab2 as b on a.x = b.y group by a.x order by 1 nulls last; select a.x, - SUM(b.x) + sum(b.x) from - pagg_tab1 as a - full outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a full outer join pagg_tab2 as b on a.x = b.y group by a.x order by 1 nulls last; select a.x, b.y, - COUNT(*) + count(*) from (select * from pagg_tab1 where x < 20) as a left outer join @@ -369,7 +341,7 @@ order by 1, select a.x, b.y, - COUNT(*) + count(*) from (select * from pagg_tab1 where x < 20) as a left outer join @@ -385,7 +357,7 @@ order by 1, select a.x, b.y, - COUNT(*) + count(*) from (select * from pagg_tab1 where x < 20) as a full outer join @@ -401,7 +373,7 @@ order by 1, select a.x, b.y, - COUNT(*) + count(*) from (select * from pagg_tab1 where x < 20) as a full outer join @@ -417,15 +389,9 @@ order by 1, select a.x, a.y, - COUNT(*) + count(*) from - ( - select * from pagg_tab1 where x = 1 and x = 2 - ) - as a - left outer join - pagg_tab2 as b - on a.x = b.y + (select * from pagg_tab1 where x = 1 and x = 2) as a left outer join pagg_tab2 as b on a.x = b.y group by a.x, a.y order by 1, @@ -434,15 +400,9 @@ order by 1, select a.x, a.y, - COUNT(*) + count(*) from - ( - select * from pagg_tab1 where x = 1 and x = 2 - ) - as a - left outer join - pagg_tab2 as b - on a.x = b.y + (select * from pagg_tab1 where x = 1 and x = 2) as a left outer join pagg_tab2 as b on a.x = b.y group by a.x, a.y order by 1, @@ -465,36 +425,36 @@ insert into pagg_tab_m select i % 30, i % 40, i % 50 from generate_series(0, 299 analyze pagg_tab_m; -select a, SUM(b), AVG(c), COUNT(*) from pagg_tab_m group by a having AVG(c) < 22 order by 1, 2, 3; +select a, sum(b), avg(c), count(*) from pagg_tab_m group by a having avg(c) < 22 order by 1, 2, 3; -select a, SUM(b), AVG(c), COUNT(*) from pagg_tab_m group by a having AVG(c) < 22 order by 1, 2, 3; +select a, sum(b), avg(c), count(*) from pagg_tab_m group by a having avg(c) < 22 order by 1, 2, 3; select a, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by a, (a + b) / 2 having - SUM(b) < 50 + sum(b) < 50 order by 1, 2, 3; select a, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by a, (a + b) / 2 having - SUM(b) < 50 + sum(b) < 50 order by 1, 2, 3; @@ -502,16 +462,16 @@ order by 1, select a, c, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by (a + b) / 2, 2, 1 having - SUM(b) = 50 and AVG(c) > 25 + sum(b) = 50 and avg(c) > 25 order by 1, 2, 3; @@ -519,16 +479,16 @@ order by 1, select a, c, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by (a + b) / 2, 2, 1 having - SUM(b) = 50 and AVG(c) > 25 + sum(b) = 50 and avg(c) > 25 order by 1, 2, 3; @@ -545,7 +505,7 @@ create table pagg_tab_ml_p1 partition of pagg_tab_ml for values from (0) to (12) create table pagg_tab_ml_p2 partition of pagg_tab_ml for values from (12) to (20) -partition by LIST(c); +partition by list(c); create table pagg_tab_ml_p2_s1 partition of pagg_tab_ml_p2 for values in ('0000', '0001', '0002'); @@ -575,12 +535,7 @@ alter table pagg_tab_ml pagg_tab_ml_p3 for values from (20) to (30); insert into pagg_tab_ml -select - i % 30, - i % 10, - to_char(i % 4, 'FM0000') -from - generate_series(0, 29999) as i; +select i % 30, i % 10, to_char(i % 4, 'FM0000') from generate_series(0, 29999) as i; analyze pagg_tab_ml; @@ -590,63 +545,63 @@ set parallel_setup_cost = 0; select a, - SUM(b), + sum(b), array_agg(distinct c), - COUNT(*) + count(*) from pagg_tab_ml group by a having - AVG(b) < 3 + avg(b) < 3 order by 1, 2, 3; select a, - SUM(b), + sum(b), array_agg(distinct c), - COUNT(*) + count(*) from pagg_tab_ml group by a having - AVG(b) < 3 + avg(b) < 3 order by 1, 2, 3; -select a, SUM(b), array_agg(distinct c), COUNT(*) from pagg_tab_ml group by a having AVG(b) < 3; +select a, sum(b), array_agg(distinct c), count(*) from pagg_tab_ml group by a having avg(b) < 3; reset parallel_setup_cost; -select a, SUM(b), COUNT(*) from pagg_tab_ml group by a having AVG(b) < 3 order by 1, 2, 3; +select a, sum(b), count(*) from pagg_tab_ml group by a having avg(b) < 3 order by 1, 2, 3; -select a, SUM(b), COUNT(*) from pagg_tab_ml group by a having AVG(b) < 3 order by 1, 2, 3; +select a, sum(b), count(*) from pagg_tab_ml group by a having avg(b) < 3 order by 1, 2, 3; -select b, SUM(a), COUNT(*) from pagg_tab_ml group by b order by 1, 2, 3; +select b, sum(a), count(*) from pagg_tab_ml group by b order by 1, 2, 3; -select b, SUM(a), COUNT(*) from pagg_tab_ml group by b having AVG(a) < 15 order by 1, 2, 3; +select b, sum(a), count(*) from pagg_tab_ml group by b having avg(a) < 15 order by 1, 2, 3; -select a, SUM(b), COUNT(*) from pagg_tab_ml group by a, b, c having AVG(b) > 7 order by 1, 2, 3; +select a, sum(b), count(*) from pagg_tab_ml group by a, b, c having avg(b) > 7 order by 1, 2, 3; -select a, SUM(b), COUNT(*) from pagg_tab_ml group by a, b, c having AVG(b) > 7 order by 1, 2, 3; +select a, sum(b), count(*) from pagg_tab_ml group by a, b, c having avg(b) > 7 order by 1, 2, 3; set min_parallel_table_scan_size = '8kB'; set parallel_setup_cost = 0; -select a, SUM(b), COUNT(*) from pagg_tab_ml group by a having AVG(b) < 3 order by 1, 2, 3; +select a, sum(b), count(*) from pagg_tab_ml group by a having avg(b) < 3 order by 1, 2, 3; -select a, SUM(b), COUNT(*) from pagg_tab_ml group by a having AVG(b) < 3 order by 1, 2, 3; +select a, sum(b), count(*) from pagg_tab_ml group by a having avg(b) < 3 order by 1, 2, 3; -select b, SUM(a), COUNT(*) from pagg_tab_ml group by b order by 1, 2, 3; +select b, sum(a), count(*) from pagg_tab_ml group by b order by 1, 2, 3; -select b, SUM(a), COUNT(*) from pagg_tab_ml group by b having AVG(a) < 15 order by 1, 2, 3; +select b, sum(a), count(*) from pagg_tab_ml group by b having avg(a) < 15 order by 1, 2, 3; -select a, SUM(b), COUNT(*) from pagg_tab_ml group by a, b, c having AVG(b) > 7 order by 1, 2, 3; +select a, sum(b), count(*) from pagg_tab_ml group by a, b, c having avg(b) > 7 order by 1, 2, 3; -select a, SUM(b), COUNT(*) from pagg_tab_ml group by a, b, c having AVG(b) > 7 order by 1, 2, 3; +select a, sum(b), count(*) from pagg_tab_ml group by a, b, c having avg(b) > 7 order by 1, 2, 3; set parallel_setup_cost = 10; @@ -666,34 +621,34 @@ insert into pagg_tab_para select i % 30, i % 20 from generate_series(0, 29999) a analyze pagg_tab_para; -select x, SUM(y), AVG(y), COUNT(*) from pagg_tab_para group by x having AVG(y) < 7 order by 1, 2, 3; +select x, sum(y), avg(y), count(*) from pagg_tab_para group by x having avg(y) < 7 order by 1, 2, 3; -select x, SUM(y), AVG(y), COUNT(*) from pagg_tab_para group by x having AVG(y) < 7 order by 1, 2, 3; +select x, sum(y), avg(y), count(*) from pagg_tab_para group by x having avg(y) < 7 order by 1, 2, 3; select y, - SUM(x), - AVG(x), - COUNT(*) + sum(x), + avg(x), + count(*) from pagg_tab_para group by y having - AVG(x) < 12 + avg(x) < 12 order by 1, 2, 3; select y, - SUM(x), - AVG(x), - COUNT(*) + sum(x), + avg(x), + count(*) from pagg_tab_para group by y having - AVG(x) < 12 + avg(x) < 12 order by 1, 2, 3; @@ -708,30 +663,30 @@ analyze pagg_tab_para; select x, - SUM(y), - AVG(y), - SUM(x + y), - COUNT(*) + sum(y), + avg(y), + sum(x + y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; select x, - SUM(y), - AVG(y), - SUM(x + y), - COUNT(*) + sum(y), + avg(y), + sum(x + y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; @@ -743,30 +698,30 @@ analyze pagg_tab_para; select x, - SUM(y), - AVG(y), - SUM(x + y), - COUNT(*) + sum(y), + avg(y), + sum(x + y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; select x, - SUM(y), - AVG(y), - SUM(x + y), - COUNT(*) + sum(y), + avg(y), + sum(x + y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; @@ -775,6 +730,6 @@ reset min_parallel_table_scan_size; reset parallel_setup_cost; -select x, SUM(y), AVG(y), COUNT(*) from pagg_tab_para group by x having AVG(y) < 7 order by 1, 2, 3; +select x, sum(y), avg(y), count(*) from pagg_tab_para group by x having avg(y) < 7 order by 1, 2, 3; -select x, SUM(y), AVG(y), COUNT(*) from pagg_tab_para group by x having AVG(y) < 7 order by 1, 2, 3; +select x, sum(y), avg(y), count(*) from pagg_tab_para group by x having avg(y) < 7 order by 1, 2, 3; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_aggregate_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_aggregate_80.snap index 4f4c56059..8839a4a72 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_aggregate_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_aggregate_80.snap @@ -17,22 +17,15 @@ create table pagg_tab ( c text, d int ) -partition by LIST(c); +partition by list(c); create table pagg_tab_p1 partition of pagg_tab -for values in ('0000', -'0001', -'0002', -'0003', -'0004'); +for values in ('0000', '0001', '0002', '0003', '0004'); create table pagg_tab_p2 partition of pagg_tab -for values in ('0005', -'0006', -'0007', -'0008'); +for values in ('0005', '0006', '0007', '0008'); create table pagg_tab_p3 partition of pagg_tab @@ -51,136 +44,136 @@ analyze pagg_tab; select c, - SUM(a), - AVG(b), - COUNT(*), - MIN(a), - MAX(b) + sum(a), + avg(b), + count(*), + min(a), + max(b) from pagg_tab group by c having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select c, - SUM(a), - AVG(b), - COUNT(*), - MIN(a), - MAX(b) + sum(a), + avg(b), + count(*), + min(a), + max(b) from pagg_tab group by c having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select a, - SUM(b), - AVG(b), - COUNT(*), - MIN(a), - MAX(b) + sum(b), + avg(b), + count(*), + min(a), + max(b) from pagg_tab group by a having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select a, - SUM(b), - AVG(b), - COUNT(*), - MIN(a), - MAX(b) + sum(b), + avg(b), + count(*), + min(a), + max(b) from pagg_tab group by a having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; -select a, c, COUNT(*) from pagg_tab group by a, c; +select a, c, count(*) from pagg_tab group by a, c; -select a, c, COUNT(*) from pagg_tab group by c, a; +select a, c, count(*) from pagg_tab group by c, a; -select c, a, COUNT(*) from pagg_tab group by a, c; +select c, a, count(*) from pagg_tab group by a, c; -select c, SUM(a) from pagg_tab where 1 = 2 group by c; +select c, sum(a) from pagg_tab where 1 = 2 group by c; -select c, SUM(a) from pagg_tab where 1 = 2 group by c; +select c, sum(a) from pagg_tab where 1 = 2 group by c; -select c, SUM(a) from pagg_tab where c = 'x' group by c; +select c, sum(a) from pagg_tab where c = 'x' group by c; -select c, SUM(a) from pagg_tab where c = 'x' group by c; +select c, sum(a) from pagg_tab where c = 'x' group by c; set enable_hashagg = 'false'; select c, - SUM(a), - AVG(b), - COUNT(*) + sum(a), + avg(b), + count(*) from pagg_tab group by 1 having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select c, - SUM(a), - AVG(b), - COUNT(*) + sum(a), + avg(b), + count(*) from pagg_tab group by 1 having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select a, - SUM(b), - AVG(b), - COUNT(*) + sum(b), + avg(b), + count(*) from pagg_tab group by 1 having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; select a, - SUM(b), - AVG(b), - COUNT(*) + sum(b), + avg(b), + count(*) from pagg_tab group by 1 having - AVG(d) < 15 + avg(d) < 15 order by 1, 2, 3; @@ -195,11 +188,11 @@ select a from pagg_tab where a < 3 group by a order by 1; reset enable_hashagg; -select c, SUM(a) from pagg_tab group by rollup (c) order by 1, 2; +select c, sum(a) from pagg_tab group by rollup (c) order by 1, 2; -select c, SUM(b order by a) from pagg_tab group by c order by 1, 2; +select c, sum(b order by a) from pagg_tab group by c order by 1, 2; -select a, SUM(b order by a) from pagg_tab group by a order by 1, 2; +select a, sum(b order by a) from pagg_tab group by a order by 1, 2; create table pagg_tab1 ( x int, @@ -226,18 +219,10 @@ create table pagg_tab2_p2 partition of pagg_tab2 for values from (10) to (20); create table pagg_tab2_p3 partition of pagg_tab2 for values from (20) to (30); insert into pagg_tab1 -select - i % 30, - i % 20 -from - generate_series(0, 299, 2) as i; +select i % 30, i % 20 from generate_series(0, 299, 2) as i; insert into pagg_tab2 -select - i % 20, - i % 30 -from - generate_series(0, 299, 3) as i; +select i % 20, i % 30 from generate_series(0, 299, 3) as i; analyze pagg_tab1; @@ -245,8 +230,8 @@ analyze pagg_tab2; select t1.x, - SUM(t1.y), - COUNT(*) + sum(t1.y), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -259,8 +244,8 @@ order by 1, select t1.x, - SUM(t1.y), - COUNT(*) + sum(t1.y), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -273,8 +258,8 @@ order by 1, select t1.x, - SUM(t1.y), - COUNT(t1) + sum(t1.y), + count(t1) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -287,8 +272,8 @@ order by 1, select t1.x, - SUM(t1.y), - COUNT(t1) + sum(t1.y), + count(t1) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -301,8 +286,8 @@ order by 1, select t2.y, - SUM(t1.y), - COUNT(*) + sum(t1.y), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -317,8 +302,8 @@ set enable_hashagg = 'false'; select t1.y, - SUM(t1.x), - COUNT(*) + sum(t1.x), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -326,15 +311,15 @@ where t1.x = t2.y group by t1.y having - AVG(t1.x) > 10 + avg(t1.x) > 10 order by 1, 2, 3; select t1.y, - SUM(t1.x), - COUNT(*) + sum(t1.x), + count(*) from pagg_tab1 as t1, pagg_tab2 as t2 @@ -342,7 +327,7 @@ where t1.x = t2.y group by t1.y having - AVG(t1.x) > 10 + avg(t1.x) > 10 order by 1, 2, 3; @@ -351,84 +336,60 @@ reset enable_hashagg; select b.y, - SUM(a.y) + sum(a.y) from - pagg_tab1 as a - left outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a left outer join pagg_tab2 as b on a.x = b.y group by b.y order by 1 nulls last; select b.y, - SUM(a.y) + sum(a.y) from - pagg_tab1 as a - left outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a left outer join pagg_tab2 as b on a.x = b.y group by b.y order by 1 nulls last; select b.y, - SUM(a.y) + sum(a.y) from - pagg_tab1 as a - right outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a right outer join pagg_tab2 as b on a.x = b.y group by b.y order by 1 nulls last; select b.y, - SUM(a.y) + sum(a.y) from - pagg_tab1 as a - right outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a right outer join pagg_tab2 as b on a.x = b.y group by b.y order by 1 nulls last; select a.x, - SUM(b.x) + sum(b.x) from - pagg_tab1 as a - full outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a full outer join pagg_tab2 as b on a.x = b.y group by a.x order by 1 nulls last; select a.x, - SUM(b.x) + sum(b.x) from - pagg_tab1 as a - full outer join - pagg_tab2 as b - on a.x = b.y + pagg_tab1 as a full outer join pagg_tab2 as b on a.x = b.y group by a.x order by 1 nulls last; select a.x, b.y, - COUNT(*) + count(*) from - ( - select * from pagg_tab1 where x < 20 - ) - as a + (select * from pagg_tab1 where x < 20) as a left outer join - ( - select * from pagg_tab2 where y > 10 - ) - as b + (select * from pagg_tab2 where y > 10) as b on a.x = b.y where a.x > 5 or b.y < 20 @@ -440,17 +401,11 @@ order by 1, select a.x, b.y, - COUNT(*) + count(*) from - ( - select * from pagg_tab1 where x < 20 - ) - as a + (select * from pagg_tab1 where x < 20) as a left outer join - ( - select * from pagg_tab2 where y > 10 - ) - as b + (select * from pagg_tab2 where y > 10) as b on a.x = b.y where a.x > 5 or b.y < 20 @@ -462,17 +417,11 @@ order by 1, select a.x, b.y, - COUNT(*) + count(*) from - ( - select * from pagg_tab1 where x < 20 - ) - as a + (select * from pagg_tab1 where x < 20) as a full outer join - ( - select * from pagg_tab2 where y > 10 - ) - as b + (select * from pagg_tab2 where y > 10) as b on a.x = b.y where a.x > 5 or b.y < 20 @@ -484,17 +433,11 @@ order by 1, select a.x, b.y, - COUNT(*) + count(*) from - ( - select * from pagg_tab1 where x < 20 - ) - as a + (select * from pagg_tab1 where x < 20) as a full outer join - ( - select * from pagg_tab2 where y > 10 - ) - as b + (select * from pagg_tab2 where y > 10) as b on a.x = b.y where a.x > 5 or b.y < 20 @@ -506,17 +449,9 @@ order by 1, select a.x, a.y, - COUNT(*) + count(*) from - ( - select - * - from - pagg_tab1 - where - x = 1 and x = 2 - ) - as a + (select * from pagg_tab1 where x = 1 and x = 2) as a left outer join pagg_tab2 as b on a.x = b.y @@ -528,17 +463,9 @@ order by 1, select a.x, a.y, - COUNT(*) + count(*) from - ( - select - * - from - pagg_tab1 - where - x = 1 and x = 2 - ) - as a + (select * from pagg_tab1 where x = 1 and x = 2) as a left outer join pagg_tab2 as b on a.x = b.y @@ -567,69 +494,64 @@ partition of pagg_tab_m for values from (22, 22) to (30, 30); insert into pagg_tab_m -select - i % 30, - i % 40, - i % 50 -from - generate_series(0, 2999) as i; +select i % 30, i % 40, i % 50 from generate_series(0, 2999) as i; analyze pagg_tab_m; select a, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by a having - AVG(c) < 22 + avg(c) < 22 order by 1, 2, 3; select a, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by a having - AVG(c) < 22 + avg(c) < 22 order by 1, 2, 3; select a, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by a, (a + b) / 2 having - SUM(b) < 50 + sum(b) < 50 order by 1, 2, 3; select a, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by a, (a + b) / 2 having - SUM(b) < 50 + sum(b) < 50 order by 1, 2, 3; @@ -637,16 +559,16 @@ order by 1, select a, c, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by (a + b) / 2, 2, 1 having - SUM(b) = 50 and AVG(c) > 25 + sum(b) = 50 and avg(c) > 25 order by 1, 2, 3; @@ -654,16 +576,16 @@ order by 1, select a, c, - SUM(b), - AVG(c), - COUNT(*) + sum(b), + avg(c), + count(*) from pagg_tab_m group by (a + b) / 2, 2, 1 having - SUM(b) = 50 and AVG(c) > 25 + sum(b) = 50 and avg(c) > 25 order by 1, 2, 3; @@ -682,7 +604,7 @@ for values from (0) to (12); create table pagg_tab_ml_p2 partition of pagg_tab_ml for values from (12) to (20) -partition by LIST(c); +partition by list(c); create table pagg_tab_ml_p2_s1 partition of pagg_tab_ml_p2 @@ -711,13 +633,11 @@ for values from (7) to (10); alter table pagg_tab_ml_p3 attach partition - pagg_tab_ml_p3_s1 - for values from (0) to (7); + pagg_tab_ml_p3_s1 for values from (0) to (7); alter table pagg_tab_ml attach partition - pagg_tab_ml_p3 - for values from (20) to (30); + pagg_tab_ml_p3 for values from (20) to (30); insert into pagg_tab_ml select @@ -735,112 +655,112 @@ set parallel_setup_cost = 0; select a, - SUM(b), + sum(b), array_agg(distinct c), - COUNT(*) + count(*) from pagg_tab_ml group by a having - AVG(b) < 3 + avg(b) < 3 order by 1, 2, 3; select a, - SUM(b), + sum(b), array_agg(distinct c), - COUNT(*) + count(*) from pagg_tab_ml group by a having - AVG(b) < 3 + avg(b) < 3 order by 1, 2, 3; select a, - SUM(b), + sum(b), array_agg(distinct c), - COUNT(*) + count(*) from pagg_tab_ml group by a having - AVG(b) < 3; + avg(b) < 3; reset parallel_setup_cost; select a, - SUM(b), - COUNT(*) + sum(b), + count(*) from pagg_tab_ml group by a having - AVG(b) < 3 + avg(b) < 3 order by 1, 2, 3; select a, - SUM(b), - COUNT(*) + sum(b), + count(*) from pagg_tab_ml group by a having - AVG(b) < 3 + avg(b) < 3 order by 1, 2, 3; -select b, SUM(a), COUNT(*) from pagg_tab_ml group by b order by 1, 2, 3; +select b, sum(a), count(*) from pagg_tab_ml group by b order by 1, 2, 3; select b, - SUM(a), - COUNT(*) + sum(a), + count(*) from pagg_tab_ml group by b having - AVG(a) < 15 + avg(a) < 15 order by 1, 2, 3; select a, - SUM(b), - COUNT(*) + sum(b), + count(*) from pagg_tab_ml group by a, b, c having - AVG(b) > 7 + avg(b) > 7 order by 1, 2, 3; select a, - SUM(b), - COUNT(*) + sum(b), + count(*) from pagg_tab_ml group by a, b, c having - AVG(b) > 7 + avg(b) > 7 order by 1, 2, 3; @@ -851,71 +771,71 @@ set parallel_setup_cost = 0; select a, - SUM(b), - COUNT(*) + sum(b), + count(*) from pagg_tab_ml group by a having - AVG(b) < 3 + avg(b) < 3 order by 1, 2, 3; select a, - SUM(b), - COUNT(*) + sum(b), + count(*) from pagg_tab_ml group by a having - AVG(b) < 3 + avg(b) < 3 order by 1, 2, 3; -select b, SUM(a), COUNT(*) from pagg_tab_ml group by b order by 1, 2, 3; +select b, sum(a), count(*) from pagg_tab_ml group by b order by 1, 2, 3; select b, - SUM(a), - COUNT(*) + sum(a), + count(*) from pagg_tab_ml group by b having - AVG(a) < 15 + avg(a) < 15 order by 1, 2, 3; select a, - SUM(b), - COUNT(*) + sum(b), + count(*) from pagg_tab_ml group by a, b, c having - AVG(b) > 7 + avg(b) > 7 order by 1, 2, 3; select a, - SUM(b), - COUNT(*) + sum(b), + count(*) from pagg_tab_ml group by a, b, c having - AVG(b) > 7 + avg(b) > 7 order by 1, 2, 3; @@ -941,66 +861,62 @@ partition of pagg_tab_para for values from (22) to (30); insert into pagg_tab_para -select - i % 30, - i % 20 -from - generate_series(0, 29999) as i; +select i % 30, i % 20 from generate_series(0, 29999) as i; analyze pagg_tab_para; select x, - SUM(y), - AVG(y), - COUNT(*) + sum(y), + avg(y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; select x, - SUM(y), - AVG(y), - COUNT(*) + sum(y), + avg(y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; select y, - SUM(x), - AVG(x), - COUNT(*) + sum(x), + avg(x), + count(*) from pagg_tab_para group by y having - AVG(x) < 12 + avg(x) < 12 order by 1, 2, 3; select y, - SUM(x), - AVG(x), - COUNT(*) + sum(x), + avg(x), + count(*) from pagg_tab_para group by y having - AVG(x) < 12 + avg(x) < 12 order by 1, 2, 3; @@ -1015,30 +931,30 @@ analyze pagg_tab_para; select x, - SUM(y), - AVG(y), - SUM(x + y), - COUNT(*) + sum(y), + avg(y), + sum(x + y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; select x, - SUM(y), - AVG(y), - SUM(x + y), - COUNT(*) + sum(y), + avg(y), + sum(x + y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; @@ -1050,30 +966,30 @@ analyze pagg_tab_para; select x, - SUM(y), - AVG(y), - SUM(x + y), - COUNT(*) + sum(y), + avg(y), + sum(x + y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; select x, - SUM(y), - AVG(y), - SUM(x + y), - COUNT(*) + sum(y), + avg(y), + sum(x + y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; @@ -1084,28 +1000,28 @@ reset parallel_setup_cost; select x, - SUM(y), - AVG(y), - COUNT(*) + sum(y), + avg(y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; select x, - SUM(y), - AVG(y), - COUNT(*) + sum(y), + avg(y), + count(*) from pagg_tab_para group by x having - AVG(y) < 7 + avg(y) < 7 order by 1, 2, 3; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_info_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_info_100.snap index d4406fa65..90e90a12e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_info_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_info_100.snap @@ -24,11 +24,11 @@ partition by range(a); create table ptif_test0 partition of ptif_test for values from (minvalue) to (0) -partition by LIST(b); +partition by list(b); create table ptif_test01 partition of ptif_test0 for values in (1); -create table ptif_test1 partition of ptif_test for values from (0) to (100) partition by LIST(b); +create table ptif_test1 partition of ptif_test for values from (0) to (100) partition by list(b); create table ptif_test11 partition of ptif_test1 for values in (1); @@ -37,7 +37,7 @@ create table ptif_test2 partition of ptif_test for values from (100) to (200); create table ptif_test3 partition of ptif_test for values from (200) to (maxvalue) -partition by LIST(b); +partition by list(b); select pg_partition_root('ptif_test'); @@ -47,39 +47,39 @@ select pg_partition_root('ptif_test01'); select pg_partition_root('ptif_test3'); -create index "ptif_test_index" on only ptif_test using btree (a); +create index ptif_test_index on only ptif_test using btree (a); -create index "ptif_test0_index" on only ptif_test0 using btree (a); +create index ptif_test0_index on only ptif_test0 using btree (a); alter index ptif_test_index attach partition ptif_test0_index; -create index "ptif_test01_index" on ptif_test01 using btree (a); +create index ptif_test01_index on ptif_test01 using btree (a); alter index ptif_test0_index attach partition ptif_test01_index; -create index "ptif_test1_index" on only ptif_test1 using btree (a); +create index ptif_test1_index on only ptif_test1 using btree (a); alter index ptif_test_index attach partition ptif_test1_index; -create index "ptif_test11_index" on ptif_test11 using btree (a); +create index ptif_test11_index on ptif_test11 using btree (a); alter index ptif_test1_index attach partition ptif_test11_index; -create index "ptif_test2_index" on ptif_test2 using btree (a); +create index ptif_test2_index on ptif_test2 using btree (a); alter index ptif_test_index attach partition ptif_test2_index; -create index "ptif_test3_index" on ptif_test3 using btree (a); +create index ptif_test3_index on ptif_test3 using btree (a); alter index ptif_test_index attach partition @@ -101,10 +101,7 @@ select level, isleaf from - pg_partition_tree('ptif_test0') as p - inner join - pg_class as c - on p.relid = c.oid; + pg_partition_tree('ptif_test0') as p inner join pg_class as c on p.relid = c.oid; select relid, @@ -112,10 +109,7 @@ select level, isleaf from - pg_partition_tree('ptif_test01') as p - inner join - pg_class as c - on p.relid = c.oid; + pg_partition_tree('ptif_test01') as p inner join pg_class as c on p.relid = c.oid; select relid, @@ -123,10 +117,7 @@ select level, isleaf from - pg_partition_tree('ptif_test3') as p - inner join - pg_class as c - on p.relid = c.oid; + pg_partition_tree('ptif_test3') as p inner join pg_class as c on p.relid = c.oid; select * from pg_partition_ancestors('ptif_test01'); @@ -138,10 +129,7 @@ select level, isleaf from - pg_partition_tree( - pg_partition_root('ptif_test01') - ) - as p + pg_partition_tree(pg_partition_root('ptif_test01')) as p inner join pg_class as c on p.relid = c.oid; @@ -154,10 +142,7 @@ select level, isleaf from - pg_partition_tree('ptif_test0_index') as p - inner join - pg_class as c - on p.relid = c.oid; + pg_partition_tree('ptif_test0_index') as p inner join pg_class as c on p.relid = c.oid; select relid, @@ -165,10 +150,7 @@ select level, isleaf from - pg_partition_tree('ptif_test01_index') as p - inner join - pg_class as c - on p.relid = c.oid; + pg_partition_tree('ptif_test01_index') as p inner join pg_class as c on p.relid = c.oid; select relid, @@ -176,10 +158,7 @@ select level, isleaf from - pg_partition_tree('ptif_test3_index') as p - inner join - pg_class as c - on p.relid = c.oid; + pg_partition_tree('ptif_test3_index') as p inner join pg_class as c on p.relid = c.oid; select relid, @@ -187,10 +166,7 @@ select level, isleaf from - pg_partition_tree( - pg_partition_root('ptif_test01_index') - ) - as p + pg_partition_tree(pg_partition_root('ptif_test01_index')) as p inner join pg_class as c on p.relid = c.oid; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_info_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_info_80.snap index 603c072d1..41ba2b098 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_info_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_info_80.snap @@ -24,14 +24,14 @@ partition by range(a); create table ptif_test0 partition of ptif_test for values from (minvalue) to (0) -partition by LIST(b); +partition by list(b); create table ptif_test01 partition of ptif_test0 for values in (1); create table ptif_test1 partition of ptif_test for values from (0) to (100) -partition by LIST(b); +partition by list(b); create table ptif_test11 partition of ptif_test1 for values in (1); @@ -40,7 +40,7 @@ create table ptif_test2 partition of ptif_test for values from (100) to (200); create table ptif_test3 partition of ptif_test for values from (200) to (maxvalue) -partition by LIST(b); +partition by list(b); select pg_partition_root('ptif_test'); @@ -50,39 +50,39 @@ select pg_partition_root('ptif_test01'); select pg_partition_root('ptif_test3'); -create index "ptif_test_index" on only ptif_test using btree (a); +create index ptif_test_index on only ptif_test using btree (a); -create index "ptif_test0_index" on only ptif_test0 using btree (a); +create index ptif_test0_index on only ptif_test0 using btree (a); alter index ptif_test_index attach partition ptif_test0_index; -create index "ptif_test01_index" on ptif_test01 using btree (a); +create index ptif_test01_index on ptif_test01 using btree (a); alter index ptif_test0_index attach partition ptif_test01_index; -create index "ptif_test1_index" on only ptif_test1 using btree (a); +create index ptif_test1_index on only ptif_test1 using btree (a); alter index ptif_test_index attach partition ptif_test1_index; -create index "ptif_test11_index" on ptif_test11 using btree (a); +create index ptif_test11_index on ptif_test11 using btree (a); alter index ptif_test1_index attach partition ptif_test11_index; -create index "ptif_test2_index" on ptif_test2 using btree (a); +create index ptif_test2_index on ptif_test2 using btree (a); alter index ptif_test_index attach partition ptif_test2_index; -create index "ptif_test3_index" on ptif_test3 using btree (a); +create index ptif_test3_index on ptif_test3 using btree (a); alter index ptif_test_index attach partition @@ -141,10 +141,7 @@ select level, isleaf from - pg_partition_tree( - pg_partition_root('ptif_test01') - ) - as p + pg_partition_tree(pg_partition_root('ptif_test01')) as p inner join pg_class as c on p.relid = c.oid; @@ -163,8 +160,7 @@ select level, isleaf from - pg_partition_tree('ptif_test0_index') - as p + pg_partition_tree('ptif_test0_index') as p inner join pg_class as c on p.relid = c.oid; @@ -175,8 +171,7 @@ select level, isleaf from - pg_partition_tree('ptif_test01_index') - as p + pg_partition_tree('ptif_test01_index') as p inner join pg_class as c on p.relid = c.oid; @@ -187,8 +182,7 @@ select level, isleaf from - pg_partition_tree('ptif_test3_index') - as p + pg_partition_tree('ptif_test3_index') as p inner join pg_class as c on p.relid = c.oid; @@ -199,10 +193,7 @@ select level, isleaf from - pg_partition_tree( - pg_partition_root('ptif_test01_index') - ) - as p + pg_partition_tree(pg_partition_root('ptif_test01_index')) as p inner join pg_class as c on p.relid = c.oid; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_join_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_join_100.snap index 8ec3813fd..47d6d0026 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_join_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_join_100.snap @@ -18,20 +18,13 @@ create table prt1_p3 partition of prt1 for values from (500) to (600); create table prt1_p2 partition of prt1 for values from (250) to (500); insert into prt1 -select - i, - i % 25, - to_char(i, 'FM0000') -from - generate_series(0, 599) as i -where - i % 2 = 0; +select i, i % 25, to_char(i, 'FM0000') from generate_series(0, 599) as i where i % 2 = 0; -create index "iprt1_p1_a" on prt1_p1 using btree (a); +create index iprt1_p1_a on prt1_p1 using btree (a); -create index "iprt1_p2_a" on prt1_p2 using btree (a); +create index iprt1_p2_a on prt1_p2 using btree (a); -create index "iprt1_p3_a" on prt1_p3 using btree (a); +create index iprt1_p3_a on prt1_p3 using btree (a); analyze prt1; @@ -49,20 +42,13 @@ create table prt2_p2 partition of prt2 for values from (250) to (500); create table prt2_p3 partition of prt2 for values from (500) to (600); insert into prt2 -select - i % 25, - i, - to_char(i, 'FM0000') -from - generate_series(0, 599) as i -where - i % 3 = 0; +select i % 25, i, to_char(i, 'FM0000') from generate_series(0, 599) as i where i % 3 = 0; -create index "iprt2_p1_b" on prt2_p1 using btree (b); +create index iprt2_p1_b on prt2_p1 using btree (b); -create index "iprt2_p2_b" on prt2_p2 using btree (b); +create index iprt2_p2_b on prt2_p2 using btree (b); -create index "iprt2_p3_b" on prt2_p3 using btree (b); +create index iprt2_p3_b on prt2_p3 using btree (b); analyze prt2; @@ -119,35 +105,20 @@ order by t1.a, t2.b; select - COUNT(*) + count(*) from - prt1 as t1 - left outer join - prt1 as t2 - on t1.a = t2.a - left outer join - prt1 as t3 - on t2.a = t3.a; + prt1 as t1 left outer join prt1 as t2 on t1.a = t2.a left outer join prt1 as t3 on t2.a = t3.a; select - COUNT(*) + count(*) from - prt1 as t1 - left outer join - prt1 as t2 - on t1.a = t2.a - left outer join - prt1 as t3 - on t2.a = t3.a; + prt1 as t1 left outer join prt1 as t2 on t1.a = t2.a left outer join prt1 as t3 on t2.a = t3.a; select t1, t2 from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -157,10 +128,7 @@ select t1, t2 from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -172,10 +140,7 @@ select t2.b, t2.c from - prt1 as t1 - right outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 right outer join prt2 as t2 on t1.a = t2.b where t2.a = 0 order by t1.a, @@ -187,10 +152,7 @@ select t2.b, t2.c from - prt1 as t1 - right outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 right outer join prt2 as t2 on t1.a = t2.b where t2.a = 0 order by t1.a, @@ -202,15 +164,9 @@ select t2.b, t2.c from - ( - select 50 as phv, * from prt1 where prt1.b = 0 - ) - as t1 + (select 50 as phv, * from prt1 where prt1.b = 0) as t1 full outer join - ( - select 75 as phv, * from prt2 where prt2.a = 0 - ) - as t2 + (select 75 as phv, * from prt2 where prt2.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -223,15 +179,9 @@ select t2.b, t2.c from - ( - select 50 as phv, * from prt1 where prt1.b = 0 - ) - as t1 + (select 50 as phv, * from prt1 where prt1.b = 0) as t1 full outer join - ( - select 75 as phv, * from prt2 where prt2.a = 0 - ) - as t2 + (select 75 as phv, * from prt2 where prt2.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -247,10 +197,7 @@ from prt1 as t1, prt2 as t2 where - t1.a = t2.b and - t1.a < 450 and - t2.b > 250 and - t1.b = 0 + t1.a = t2.b and t1.a < 450 and t2.b > 250 and t1.b = 0 order by t1.a, t2.b; @@ -263,10 +210,7 @@ from prt1 as t1, prt2 as t2 where - t1.a = t2.b and - t1.a < 450 and - t2.b > 250 and - t1.b = 0 + t1.a = t2.b and t1.a < 450 and t2.b > 250 and t1.b = 0 order by t1.a, t2.b; @@ -335,11 +279,7 @@ select from prt1 as t1 where - t1.a in - ( - select t2.b from prt2 as t2 where t2.a = 0 - ) and - t1.b = 0 + t1.a in (select t2.b from prt2 as t2 where t2.a = 0) and t1.b = 0 order by t1.a; select @@ -347,38 +287,28 @@ select from prt1 as t1 where - t1.a in - ( - select t2.b from prt2 as t2 where t2.a = 0 - ) and - t1.b = 0 + t1.a in (select t2.b from prt2 as t2 where t2.a = 0) and t1.b = 0 order by t1.a; select - SUM(t1.a), - AVG(t1.a), - SUM(t1.b), - AVG(t1.b) + sum(t1.a), + avg(t1.a), + sum(t1.b), + avg(t1.b) from prt1 as t1 where - not exists - ( - select 1 from prt2 as t2 where t1.a = t2.b - ); + not exists (select 1 from prt2 as t2 where t1.a = t2.b); select - SUM(t1.a), - AVG(t1.a), - SUM(t1.b), - AVG(t1.b) + sum(t1.a), + avg(t1.a), + sum(t1.b), + avg(t1.b) from prt1 as t1 where - not exists - ( - select 1 from prt2 as t2 where t1.a = t2.b - ); + not exists (select 1 from prt2 as t2 where t1.a = t2.b); select * @@ -469,66 +399,34 @@ select from prt1 as t1 inner join - lateral ( - select - * - from - prt1 as t2 - tablesample system (t1.a) - repeatable (t1.b) - ) - as s + lateral (select * from prt1 as t2 tablesample system (t1.a) repeatable (t1.b)) as s on t1.a = s.a; select - COUNT(*) + count(*) from - prt1 as t1 - left outer join - lateral ( - select t1.b as t1b, t2.* from prt2 as t2 - ) - as s - on t1.a = s.b + prt1 as t1 left outer join lateral (select t1.b as t1b, t2.* from prt2 as t2) as s on t1.a = s.b where s.t1b = s.a; select - COUNT(*) + count(*) from - prt1 as t1 - left outer join - lateral ( - select t1.b as t1b, t2.* from prt2 as t2 - ) - as s - on t1.a = s.b + prt1 as t1 left outer join lateral (select t1.b as t1b, t2.* from prt2 as t2) as s on t1.a = s.b where s.t1b = s.a; select - COUNT(*) + count(*) from - prt1 as t1 - left outer join - lateral ( - select t1.b as t1b, t2.* from prt2 as t2 - ) - as s - on t1.a = s.b + prt1 as t1 left outer join lateral (select t1.b as t1b, t2.* from prt2 as t2) as s on t1.a = s.b where s.t1b = s.b; select - COUNT(*) + count(*) from - prt1 as t1 - left outer join - lateral ( - select t1.b as t1b, t2.* from prt2 as t2 - ) - as s - on t1.a = s.b + prt1 as t1 left outer join lateral (select t1.b as t1b, t2.* from prt2 as t2) as s on t1.a = s.b where s.t1b = s.b; @@ -540,12 +438,7 @@ select a, b from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) where a between 490 and 510 group by 1, @@ -557,12 +450,7 @@ select a, b from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) where a between 490 and 510 group by 1, @@ -596,11 +484,11 @@ create table prt1_e_p3 partition of prt1_e for values from (500) to (600); insert into prt1_e select i, i, i % 25 from generate_series(0, 599, 2) as i; -create index "iprt1_e_p1_ab2" on prt1_e_p1 using btree (((a + b) / 2)); +create index iprt1_e_p1_ab2 on prt1_e_p1 using btree (((a + b) / 2)); -create index "iprt1_e_p2_ab2" on prt1_e_p2 using btree (((a + b) / 2)); +create index iprt1_e_p2_ab2 on prt1_e_p2 using btree (((a + b) / 2)); -create index "iprt1_e_p3_ab2" on prt1_e_p3 using btree (((a + b) / 2)); +create index iprt1_e_p3_ab2 on prt1_e_p3 using btree (((a + b) / 2)); analyze prt1_e; @@ -659,9 +547,7 @@ from prt2 as t2, prt1_e as t3 where - t1.a = t2.b and - t1.a = (t3.a + t3.b) / 2 and - t1.b = 0 + t1.a = t2.b and t1.a = (t3.a + t3.b) / 2 and t1.b = 0 order by t1.a, t2.b; @@ -677,9 +563,7 @@ from prt2 as t2, prt1_e as t3 where - t1.a = t2.b and - t1.a = (t3.a + t3.b) / 2 and - t1.b = 0 + t1.a = t2.b and t1.a = (t3.a + t3.b) / 2 and t1.b = 0 order by t1.a, t2.b; @@ -691,10 +575,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b left outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -712,10 +593,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b left outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -733,10 +611,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b right outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -754,10 +629,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b right outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -768,80 +640,60 @@ order by t1.a, t3.a + t3.b; select - COUNT(*) + count(*) from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) full outer join prt2 as p3 (b, a, c) using ( - "a", - "b") + a, + b) where a between 490 and 510; select - COUNT(*) + count(*) from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) full outer join prt2 as p3 (b, a, c) using ( - "a", - "b") + a, + b) where a between 490 and 510; select - COUNT(*) + count(*) from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) full outer join prt2 as p3 (b, a, c) using ( - "a", - "b") + a, + b) full outer join prt1 as p4 (a, b, c) using ( - "a", - "b") + a, + b) where a between 490 and 510; select - COUNT(*) + count(*) from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) full outer join prt2 as p3 (b, a, c) using ( - "a", - "b") + a, + b) full outer join prt1 as p4 (a, b, c) using ( - "a", - "b") + a, + b) where a between 490 and 510; @@ -853,26 +705,15 @@ select t3.a + t3.b, t3.phv from - ( - select 50 as phv, * from prt1 where prt1.b = 0 - ) - as t1 + (select 50 as phv, * from prt1 where prt1.b = 0) as t1 full outer join - ( - select 75 as phv, * from prt2 where prt2.a = 0 - ) - as t2 + (select 75 as phv, * from prt2 where prt2.a = 0) as t2 on t1.a = t2.b full outer join - ( - select 50 as phv, * from prt1_e where prt1_e.c = 0 - ) - as t3 + (select 50 as phv, * from prt1_e where prt1_e.c = 0) as t3 on t1.a = (t3.a + t3.b) / 2 where - t1.a = t1.phv or - t2.b = t2.phv or - (t3.a + t3.b) / 2 = t3.phv + t1.a = t1.phv or t2.b = t2.phv or (t3.a + t3.b) / 2 = t3.phv order by t1.a, t2.b, t3.a + t3.b; @@ -885,26 +726,15 @@ select t3.a + t3.b, t3.phv from - ( - select 50 as phv, * from prt1 where prt1.b = 0 - ) - as t1 + (select 50 as phv, * from prt1 where prt1.b = 0) as t1 full outer join - ( - select 75 as phv, * from prt2 where prt2.a = 0 - ) - as t2 + (select 75 as phv, * from prt2 where prt2.a = 0) as t2 on t1.a = t2.b full outer join - ( - select 50 as phv, * from prt1_e where prt1_e.c = 0 - ) - as t3 + (select 50 as phv, * from prt1_e where prt1_e.c = 0) as t3 on t1.a = (t3.a + t3.b) / 2 where - t1.a = t1.phv or - t2.b = t2.phv or - (t3.a + t3.b) / 2 = t3.phv + t1.a = t1.phv or t2.b = t2.phv or (t3.a + t3.b) / 2 = t3.phv order by t1.a, t2.b, t3.a + t3.b; @@ -916,13 +746,7 @@ from where t1.a in ( - select - t1.b - from - prt2 as t1, - prt1_e as t2 - where - t1.a = 0 and t1.b = (t2.a + t2.b) / 2 + select t1.b from prt2 as t1, prt1_e as t2 where t1.a = 0 and t1.b = (t2.a + t2.b) / 2 ) and t1.b = 0 order by t1.a; @@ -934,13 +758,7 @@ from where t1.a in ( - select - t1.b - from - prt2 as t1, - prt1_e as t2 - where - t1.a = 0 and t1.b = (t2.a + t2.b) / 2 + select t1.b from prt2 as t1, prt1_e as t2 where t1.a = 0 and t1.b = (t2.a + t2.b) / 2 ) and t1.b = 0 order by t1.a; @@ -957,15 +775,7 @@ where from prt2 as t1 where - t1.b in - ( - select - (t1.a + t1.b) / 2 - from - prt1_e as t1 - where - t1.c = 0 - ) + t1.b in (select (t1.a + t1.b) / 2 from prt1_e as t1 where t1.c = 0) ) and t1.b = 0 order by t1.a; @@ -982,15 +792,7 @@ where from prt2 as t1 where - t1.b in - ( - select - (t1.a + t1.b) / 2 - from - prt1_e as t1 - where - t1.c = 0 - ) + t1.b in (select (t1.a + t1.b) / 2 from prt1_e as t1 where t1.c = 0) ) and t1.b = 0 order by t1.a; @@ -1011,15 +813,7 @@ where from prt2 as t1 where - t1.b in - ( - select - (t1.a + t1.b) / 2 - from - prt1_e as t1 - where - t1.c = 0 - ) + t1.b in (select (t1.a + t1.b) / 2 from prt1_e as t1 where t1.c = 0) ) and t1.b = 0 order by t1.a; @@ -1036,15 +830,7 @@ where from prt2 as t1 where - t1.b in - ( - select - (t1.a + t1.b) / 2 - from - prt1_e as t1 - where - t1.c = 0 - ) + t1.b in (select (t1.a + t1.b) / 2 from prt1_e as t1 where t1.c = 0) ) and t1.b = 0 order by t1.a; @@ -1057,10 +843,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b right outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -1078,10 +861,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b right outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -1124,8 +904,7 @@ from prt1 as t1, prt2 as t2 where - cast(t1 as text) = cast(t2 as text) and - t1.a = t2.b + cast(t1 as text) = cast(t2 as text) and t1.a = t2.b order by t1.a; select @@ -1135,8 +914,7 @@ from prt1 as t1, prt2 as t2 where - cast(t1 as text) = cast(t2 as text) and - t1.a = t2.b + cast(t1 as text) = cast(t2 as text) and t1.a = t2.b order by t1.a; reset enable_hashjoin; @@ -1186,8 +964,7 @@ from (select * from prt1_m where prt1_m.c = 0) as t1 full outer join (select * from prt2_m where prt2_m.c = 0) as t2 - on t1.a = (t2.b + t2.a) / 2 and - t2.b = (t1.a + t1.b) / 2 + on t1.a = (t2.b + t2.a) / 2 and t2.b = (t1.a + t1.b) / 2 order by t1.a, t2.b; @@ -1200,8 +977,7 @@ from (select * from prt1_m where prt1_m.c = 0) as t1 full outer join (select * from prt2_m where prt2_m.c = 0) as t2 - on t1.a = (t2.b + t2.a) / 2 and - t2.b = (t1.a + t1.b) / 2 + on t1.a = (t2.b + t2.a) / 2 and t2.b = (t1.a + t1.b) / 2 order by t1.a, t2.b; @@ -1210,7 +986,7 @@ create table plt1 ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt1_p1 partition of plt1 for values in ('0000', '0003', '0004', '0010'); @@ -1227,7 +1003,7 @@ create table plt2 ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt2_p1 partition of plt2 for values in ('0000', '0003', '0004', '0010'); @@ -1244,7 +1020,7 @@ create table plt1_e ( b int, c text ) -partition by LIST((ltrim(c, 'A'))); +partition by list((ltrim(c, 'A'))); create table plt1_e_p1 partition of plt1_e for values in ('0000', '0003', '0004', '0010'); @@ -1253,19 +1029,14 @@ create table plt1_e_p2 partition of plt1_e for values in ('0001', '0005', '0002' create table plt1_e_p3 partition of plt1_e for values in ('0006', '0007', '0008', '0011'); insert into plt1_e -select - i, - i, - 'A' || to_char(i / 50, 'FM0000') -from - generate_series(0, 599, 2) as i; +select i, i, 'A' || to_char(i / 50, 'FM0000') from generate_series(0, 599, 2) as i; analyze plt1_e; select - AVG(t1.a), - AVG(t2.b), - AVG(t3.a + t3.b), + avg(t1.a), + avg(t2.b), + avg(t3.a + t3.b), t1.c, t2.c, t3.c @@ -1274,9 +1045,7 @@ from plt2 as t2, plt1_e as t3 where - t1.b = t2.b and - t1.c = t2.c and - ltrim(t3.c, 'A') = t1.c + t1.b = t2.b and t1.c = t2.c and ltrim(t3.c, 'A') = t1.c group by t1.c, t2.c, t3.c @@ -1285,9 +1054,9 @@ order by t1.c, t3.c; select - AVG(t1.a), - AVG(t2.b), - AVG(t3.a + t3.b), + avg(t1.a), + avg(t2.b), + avg(t3.a + t3.b), t1.c, t2.c, t3.c @@ -1296,9 +1065,7 @@ from plt2 as t2, plt1_e as t3 where - t1.b = t2.b and - t1.c = t2.c and - ltrim(t3.c, 'A') = t1.c + t1.b = t2.b and t1.c = t2.c and ltrim(t3.c, 'A') = t1.c group by t1.c, t2.c, t3.c @@ -1323,10 +1090,7 @@ select t2.b, t2.c from - (select * from prt1 where a = 1 and a = 2) as t1 - left outer join - prt2 as t2 - on t1.a = t2.b; + (select * from prt1 where a = 1 and a = 2) as t1 left outer join prt2 as t2 on t1.a = t2.b; select t1.a, @@ -1334,10 +1098,7 @@ select t2.b, t2.c from - (select * from prt1 where a = 1 and a = 2) as t1 - right outer join - prt2 as t2 - on t1.a = t2.b, + (select * from prt1 where a = 1 and a = 2) as t1 right outer join prt2 as t2 on t1.a = t2.b, prt1 as t3 where t2.b = t3.a; @@ -1348,10 +1109,7 @@ select t2.b, t2.c from - (select * from prt1 where a = 1 and a = 2) as t1 - full outer join - prt2 as t2 - on t1.a = t2.b + (select * from prt1 where a = 1 and a = 2) as t1 full outer join prt2 as t2 on t1.a = t2.b where t2.a = 0 order by t1.a, @@ -1362,13 +1120,13 @@ create table pht1 ( b int, c text ) -partition by HASH(c); +partition by hash(c); -create table pht1_p1 partition of pht1 for values with (MODULUS 3, REMAINDER 0); +create table pht1_p1 partition of pht1 for values with (modulus 3, remainder 0); -create table pht1_p2 partition of pht1 for values with (MODULUS 3, REMAINDER 1); +create table pht1_p2 partition of pht1 for values with (modulus 3, remainder 1); -create table pht1_p3 partition of pht1 for values with (MODULUS 3, REMAINDER 2); +create table pht1_p3 partition of pht1 for values with (modulus 3, remainder 2); insert into pht1 select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 2) as i; @@ -1379,13 +1137,13 @@ create table pht2 ( b int, c text ) -partition by HASH(c); +partition by hash(c); -create table pht2_p1 partition of pht2 for values with (MODULUS 3, REMAINDER 0); +create table pht2_p1 partition of pht2 for values with (modulus 3, remainder 0); -create table pht2_p2 partition of pht2 for values with (MODULUS 3, REMAINDER 1); +create table pht2_p2 partition of pht2 for values with (modulus 3, remainder 1); -create table pht2_p3 partition of pht2 for values with (MODULUS 3, REMAINDER 2); +create table pht2_p3 partition of pht2 for values with (modulus 3, remainder 2); insert into pht2 select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 3) as i; @@ -1396,28 +1154,23 @@ create table pht1_e ( b int, c text ) -partition by HASH((ltrim(c, 'A'))); +partition by hash((ltrim(c, 'A'))); -create table pht1_e_p1 partition of pht1_e for values with (MODULUS 3, REMAINDER 0); +create table pht1_e_p1 partition of pht1_e for values with (modulus 3, remainder 0); -create table pht1_e_p2 partition of pht1_e for values with (MODULUS 3, REMAINDER 1); +create table pht1_e_p2 partition of pht1_e for values with (modulus 3, remainder 1); -create table pht1_e_p3 partition of pht1_e for values with (MODULUS 3, REMAINDER 2); +create table pht1_e_p3 partition of pht1_e for values with (modulus 3, remainder 2); insert into pht1_e -select - i, - i, - 'A' || to_char(i / 50, 'FM0000') -from - generate_series(0, 299, 2) as i; +select i, i, 'A' || to_char(i / 50, 'FM0000') from generate_series(0, 299, 2) as i; analyze pht1_e; select - AVG(t1.a), - AVG(t2.b), - AVG(t3.a + t3.b), + avg(t1.a), + avg(t2.b), + avg(t3.a + t3.b), t1.c, t2.c, t3.c @@ -1426,9 +1179,7 @@ from pht2 as t2, pht1_e as t3 where - t1.b = t2.b and - t1.c = t2.c and - ltrim(t3.c, 'A') = t1.c + t1.b = t2.b and t1.c = t2.c and ltrim(t3.c, 'A') = t1.c group by t1.c, t2.c, t3.c @@ -1437,9 +1188,9 @@ order by t1.c, t3.c; select - AVG(t1.a), - AVG(t2.b), - AVG(t3.a + t3.b), + avg(t1.a), + avg(t2.b), + avg(t3.a + t3.b), t1.c, t2.c, t3.c @@ -1448,9 +1199,7 @@ from pht2 as t2, pht1_e as t3 where - t1.b = t2.b and - t1.c = t2.c and - ltrim(t3.c, 'A') = t1.c + t1.b = t2.b and t1.c = t2.c and ltrim(t3.c, 'A') = t1.c group by t1.c, t2.c, t3.c @@ -1512,15 +1261,12 @@ alter table plt2 analyze plt2; select - AVG(t1.a), - AVG(t2.b), + avg(t1.a), + avg(t2.b), t1.c, t2.c from - plt1 as t1 - right outer join - plt2 as t2 - on t1.c = t2.c + plt1 as t1 right outer join plt2 as t2 on t1.c = t2.c where t1.a % 25 = 0 group by t1.c, @@ -1537,7 +1283,7 @@ partition by range(a); create table prt1_l_p1 partition of prt1_l for values from (0) to (250); -create table prt1_l_p2 partition of prt1_l for values from (250) to (500) partition by LIST(c); +create table prt1_l_p2 partition of prt1_l for values from (250) to (500) partition by list(c); create table prt1_l_p2_p1 partition of prt1_l_p2 for values in ('0000', '0001'); @@ -1562,7 +1308,7 @@ partition by range(b); create table prt2_l_p1 partition of prt2_l for values from (0) to (250); -create table prt2_l_p2 partition of prt2_l for values from (250) to (500) partition by LIST(c); +create table prt2_l_p2 partition of prt2_l for values from (250) to (500) partition by list(c); create table prt2_l_p2_p1 partition of prt2_l_p2 for values in ('0000', '0001'); @@ -1636,10 +1382,7 @@ select t2.b, t2.c from - prt1_l as t1 - left outer join - prt2_l as t2 - on t1.a = t2.b and t1.c = t2.c + prt1_l as t1 left outer join prt2_l as t2 on t1.a = t2.b and t1.c = t2.c where t1.b = 0 order by t1.a, @@ -1651,10 +1394,7 @@ select t2.b, t2.c from - prt1_l as t1 - left outer join - prt2_l as t2 - on t1.a = t2.b and t1.c = t2.c + prt1_l as t1 left outer join prt2_l as t2 on t1.a = t2.b and t1.c = t2.c where t1.b = 0 order by t1.a, @@ -1666,10 +1406,7 @@ select t2.b, t2.c from - prt1_l as t1 - right outer join - prt2_l as t2 - on t1.a = t2.b and t1.c = t2.c + prt1_l as t1 right outer join prt2_l as t2 on t1.a = t2.b and t1.c = t2.c where t2.a = 0 order by t1.a, @@ -1681,10 +1418,7 @@ select t2.b, t2.c from - prt1_l as t1 - right outer join - prt2_l as t2 - on t1.a = t2.b and t1.c = t2.c + prt1_l as t1 right outer join prt2_l as t2 on t1.a = t2.b and t1.c = t2.c where t2.a = 0 order by t1.a, @@ -1729,10 +1463,7 @@ from t3.b as t3b, least(t1.a, t2.a, t3.b) from - prt1_l as t2 - inner join - prt2_l as t3 - on t2.a = t3.b and t2.c = t3.c + prt1_l as t2 inner join prt2_l as t3 on t2.a = t3.b and t2.c = t3.c ) as ss on t1.a = ss.t2a and t1.c = ss.t2c @@ -1753,10 +1484,7 @@ from t3.b as t3b, least(t1.a, t2.a, t3.b) from - prt1_l as t2 - inner join - prt2_l as t3 - on t2.a = t3.b and t2.c = t3.c + prt1_l as t2 inner join prt2_l as t3 on t2.a = t3.b and t2.c = t3.c ) as ss on t1.a = ss.t2a and t1.c = ss.t2c @@ -1769,39 +1497,25 @@ select from prt1_l as t1 inner join - lateral ( - select - * - from - prt1_l as t2 - tablesample system (t1.a) - repeatable (t1.b) - ) - as s + lateral (select * from prt1_l as t2 tablesample system (t1.a) repeatable (t1.b)) as s on t1.a = s.a and t1.b = s.b and t1.c = s.c; select - COUNT(*) + count(*) from prt1_l as t1 left outer join - lateral ( - select t1.b as t1b, t2.* from prt2_l as t2 - ) - as s + lateral (select t1.b as t1b, t2.* from prt2_l as t2) as s on t1.a = s.b and t1.b = s.a and t1.c = s.c where s.t1b = s.a; select - COUNT(*) + count(*) from prt1_l as t1 left outer join - lateral ( - select t1.b as t1b, t2.* from prt2_l as t2 - ) - as s + lateral (select t1.b as t1b, t2.* from prt2_l as t2) as s on t1.a = s.b and t1.b = s.a and t1.c = s.c where s.t1b = s.a; @@ -1825,10 +1539,7 @@ where 1 from int4_tbl, - lateral ( - select int4_tbl.f1 from int8_tbl limit 2 - ) - as ss + lateral (select int4_tbl.f1 from int8_tbl limit 2) as ss where prt1_l.c is null ); @@ -1853,25 +1564,15 @@ create table prt2_n ( b int, c text ) -partition by LIST(c); +partition by list(c); create table prt2_n_p1 partition of prt2_n -for values in ('0000', -'0003', -'0004', -'0010', -'0006', -'0007'); +for values in ('0000', '0003', '0004', '0010', '0006', '0007'); create table prt2_n_p2 partition of prt2_n -for values in ('0001', -'0005', -'0002', -'0009', -'0008', -'0011'); +for values in ('0001', '0005', '0002', '0009', '0008', '0011'); insert into prt2_n select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 2) as i; @@ -1882,7 +1583,7 @@ create table prt3_n ( b int, c text ) -partition by LIST(c); +partition by list(c); create table prt3_n_p1 partition of prt3_n for values in ('0000', '0004', '0006', '0007'); @@ -1941,13 +1642,7 @@ select t2.b, t2.c from - prt1_n as t1 - inner join - prt2_n as t2 - on t1.c = t2.c - inner join - plt1 as t3 - on t1.c = t3.c; + prt1_n as t1 inner join prt2_n as t2 on t1.c = t2.c inner join plt1 as t3 on t1.c = t3.c; select t1.a, t1.c, t2.b, t2.c from prt1_n as t1 full outer join prt1 as t2 on t1.c = t2.c; @@ -1980,13 +1675,7 @@ create temporary table prtx2_3 partition of prtx2 for values from (21) to (31); insert into prtx1 select 1 + i % 30, i, i from generate_series(1, 1000) as i; insert into prtx2 -select - 1 + i % 30, - i, - i -from - generate_series(1, 500) as i, - generate_series(1, 10) as j; +select 1 + i % 30, i, i from generate_series(1, 500) as i, generate_series(1, 10) as j; create index on prtx2 using btree (b); @@ -2003,14 +1692,7 @@ from where not exists ( - select - 1 - from - prtx2 - where - prtx2.a = prtx1.a and - prtx2.b = prtx1.b and - prtx2.c = 123 + select 1 from prtx2 where prtx2.a = prtx1.a and prtx2.b = prtx1.b and prtx2.c = 123 ) and a < 20 and c = 120; @@ -2022,14 +1704,7 @@ from where not exists ( - select - 1 - from - prtx2 - where - prtx2.a = prtx1.a and - prtx2.b = prtx1.b and - prtx2.c = 123 + select 1 from prtx2 where prtx2.a = prtx1.a and prtx2.b = prtx1.b and prtx2.c = 123 ) and a < 20 and c = 120; @@ -2041,15 +1716,7 @@ from where not exists ( - select - 1 - from - prtx2 - where - prtx2.a = prtx1.a and - ( - prtx2.b = prtx1.b + 1 or prtx2.c = 99 - ) + select 1 from prtx2 where prtx2.a = prtx1.a and (prtx2.b = prtx1.b + 1 or prtx2.c = 99) ) and a < 20 and c = 91; @@ -2061,15 +1728,7 @@ from where not exists ( - select - 1 - from - prtx2 - where - prtx2.a = prtx1.a and - ( - prtx2.b = prtx1.b + 1 or prtx2.c = 99 - ) + select 1 from prtx2 where prtx2.a = prtx1.a and (prtx2.b = prtx1.b + 1 or prtx2.c = 99) ) and a < 20 and c = 91; @@ -2087,7 +1746,7 @@ create table prt1_adv_p2 partition of prt1_adv for values from (200) to (300); create table prt1_adv_p3 partition of prt1_adv for values from (300) to (400); -create index "prt1_adv_a_idx" on prt1_adv using btree (a); +create index prt1_adv_a_idx on prt1_adv using btree (a); insert into prt1_adv select i, i % 25, to_char(i, 'FM0000') from generate_series(100, 399) as i; @@ -2106,7 +1765,7 @@ create table prt2_adv_p2 partition of prt2_adv for values from (200) to (300); create table prt2_adv_p3 partition of prt2_adv for values from (350) to (500); -create index "prt2_adv_b_idx" on prt2_adv using btree (b); +create index prt2_adv_b_idx on prt2_adv using btree (b); insert into prt2_adv_p1 select i % 25, i, to_char(i, 'FM0000') from generate_series(100, 149) as i; @@ -2122,10 +1781,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2137,10 +1793,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2151,11 +1804,7 @@ select from prt1_adv as t1 where - exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2163,11 +1812,7 @@ select from prt1_adv as t1 where - exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2176,10 +1821,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2191,10 +1833,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2205,11 +1844,7 @@ select from prt1_adv as t1 where - not exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2217,11 +1852,7 @@ select from prt1_adv as t1 where - not exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2230,27 +1861,9 @@ select t2.b, t2.c from - ( - select - 175 as phv, - * - from - prt1_adv - where - prt1_adv.b = 0 - ) - as t1 + (select 175 as phv, * from prt1_adv where prt1_adv.b = 0) as t1 full outer join - ( - select - 425 as phv, - * - from - prt2_adv - where - prt2_adv.a = 0 - ) - as t2 + (select 425 as phv, * from prt2_adv where prt2_adv.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -2263,27 +1876,9 @@ select t2.b, t2.c from - ( - select - 175 as phv, - * - from - prt1_adv - where - prt1_adv.b = 0 - ) - as t1 + (select 175 as phv, * from prt1_adv where prt1_adv.b = 0) as t1 full outer join - ( - select - 425 as phv, - * - from - prt2_adv - where - prt2_adv.a = 0 - ) - as t2 + (select 425 as phv, * from prt2_adv where prt2_adv.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -2302,10 +1897,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2317,10 +1909,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2331,11 +1920,7 @@ select from prt1_adv as t1 where - exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2343,11 +1928,7 @@ select from prt1_adv as t1 where - exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2356,10 +1937,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2371,10 +1949,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2386,10 +1961,7 @@ select t2.a, t2.c from - prt2_adv as t1 - left outer join - prt1_adv as t2 - on t1.b = t2.a + prt2_adv as t1 left outer join prt1_adv as t2 on t1.b = t2.a where t1.a = 0 order by t1.b, @@ -2400,11 +1972,7 @@ select from prt1_adv as t1 where - not exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2412,11 +1980,7 @@ select from prt1_adv as t1 where - not exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2424,11 +1988,7 @@ select from prt2_adv as t1 where - not exists - ( - select 1 from prt1_adv as t2 where t1.b = t2.a - ) and - t1.a = 0 + not exists (select 1 from prt1_adv as t2 where t1.b = t2.a) and t1.a = 0 order by t1.b; select @@ -2437,27 +1997,9 @@ select t2.b, t2.c from - ( - select - 175 as phv, - * - from - prt1_adv - where - prt1_adv.b = 0 - ) - as t1 + (select 175 as phv, * from prt1_adv where prt1_adv.b = 0) as t1 full outer join - ( - select - 425 as phv, - * - from - prt2_adv - where - prt2_adv.a = 0 - ) - as t2 + (select 425 as phv, * from prt2_adv where prt2_adv.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -2472,10 +2014,7 @@ select t3.a, t3.c from - prt2_adv as t1 - left outer join - prt1_adv as t2 - on t1.b = t2.a + prt2_adv as t1 left outer join prt1_adv as t2 on t1.b = t2.a inner join prt1_adv as t3 on t1.b = t3.a @@ -2493,10 +2032,7 @@ select t3.a, t3.c from - prt2_adv as t1 - left outer join - prt1_adv as t2 - on t1.b = t2.a + prt2_adv as t1 left outer join prt1_adv as t2 on t1.b = t2.a inner join prt1_adv as t3 on t1.b = t3.a @@ -2526,10 +2062,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2540,11 +2073,7 @@ select from prt1_adv as t1 where - exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2553,10 +2082,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2567,11 +2093,7 @@ select from prt1_adv as t1 where - not exists - ( - select 1 from prt2_adv as t2 where t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2580,27 +2102,9 @@ select t2.b, t2.c from - ( - select - 175 as phv, - * - from - prt1_adv - where - prt1_adv.b = 0 - ) - as t1 + (select 175 as phv, * from prt1_adv where prt1_adv.b = 0) as t1 full outer join - ( - select - 425 as phv, - * - from - prt2_adv - where - prt2_adv.a = 0 - ) - as t2 + (select 425 as phv, * from prt2_adv where prt2_adv.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -2633,10 +2137,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2648,10 +2149,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2675,10 +2173,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2700,10 +2195,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2728,7 +2220,7 @@ create table prt3_adv_p1 partition of prt3_adv for values from (200) to (300); create table prt3_adv_p2 partition of prt3_adv for values from (300) to (400); -create index "prt3_adv_a_idx" on prt3_adv using btree (a); +create index prt3_adv_a_idx on prt3_adv using btree (a); insert into prt3_adv select i, i % 25, to_char(i, 'FM0000') from generate_series(200, 399) as i; @@ -2742,10 +2234,7 @@ select t3.a, t3.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b left outer join prt3_adv as t3 on t1.a = t3.a @@ -2763,10 +2252,7 @@ select t3.a, t3.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b left outer join prt3_adv as t3 on t1.a = t3.a @@ -2795,7 +2281,7 @@ create table prt1_adv_p2 partition of prt1_adv for values from (200) to (300); create table prt1_adv_p3 partition of prt1_adv for values from (300) to (400); -create index "prt1_adv_a_idx" on prt1_adv using btree (a); +create index prt1_adv_a_idx on prt1_adv using btree (a); insert into prt1_adv select i, i % 25, to_char(i, 'FM0000') from generate_series(100, 399) as i; @@ -2812,7 +2298,7 @@ create table prt2_adv_p1 partition of prt2_adv for values from (100) to (200); create table prt2_adv_p2 partition of prt2_adv for values from (200) to (400); -create index "prt2_adv_b_idx" on prt2_adv using btree (b); +create index prt2_adv_b_idx on prt2_adv using btree (b); insert into prt2_adv select i % 25, i, to_char(i, 'FM0000') from generate_series(100, 399) as i; @@ -2824,10 +2310,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.a < 300 and t1.b = 0 order by t1.a, @@ -2839,10 +2322,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.a < 300 and t1.b = 0 order by t1.a, @@ -2864,10 +2344,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.a >= 100 and t1.a < 300 and t1.b = 0 order by t1.a, @@ -2879,10 +2356,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.a >= 100 and t1.a < 300 and t1.b = 0 order by t1.a, @@ -2897,7 +2371,7 @@ create table plt1_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt1_adv_p1 partition of plt1_adv for values in ('0001', '0003'); @@ -2922,7 +2396,7 @@ create table plt2_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt2_adv_p1 partition of plt2_adv for values in ('0002', '0003'); @@ -2948,10 +2422,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -2962,10 +2433,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -2975,16 +2443,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -2992,16 +2451,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3010,10 +2460,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3024,10 +2471,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3037,16 +2481,7 @@ select from plt1_adv as t1 where - not exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + not exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3054,16 +2489,7 @@ select from plt1_adv as t1 where - not exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + not exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3072,10 +2498,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3087,10 +2510,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3108,10 +2528,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3122,10 +2539,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3135,16 +2549,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3152,16 +2557,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3170,10 +2566,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3184,10 +2577,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3198,10 +2588,7 @@ select t2.a, t2.c from - plt2_adv as t1 - left outer join - plt1_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt2_adv as t1 left outer join plt1_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3211,16 +2598,7 @@ select from plt1_adv as t1 where - not exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + not exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3228,16 +2606,7 @@ select from plt1_adv as t1 where - not exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + not exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3245,16 +2614,7 @@ select from plt2_adv as t1 where - not exists - ( - select - 1 - from - plt1_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + not exists (select 1 from plt1_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3263,10 +2623,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3283,14 +2640,7 @@ create table plt2_adv_p2_1 partition of plt2_adv for values in ('0004'); create table plt2_adv_p2_2 partition of plt2_adv for values in ('0006'); insert into plt2_adv -select - i, - i, - to_char(i % 10, 'FM0000') -from - generate_series(1, 299) as i -where - i % 10 in (4, 6); +select i, i, to_char(i % 10, 'FM0000') from generate_series(1, 299) as i where i % 10 in (4, 6); analyze plt2_adv; @@ -3300,10 +2650,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3313,16 +2660,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3331,10 +2669,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3344,16 +2679,7 @@ select from plt1_adv as t1 where - not exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + not exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3362,10 +2688,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3386,14 +2709,7 @@ alter table plt1_adv create table plt1_adv_p1_null partition of plt1_adv for values in (null, '0001', '0003'); insert into plt1_adv -select - i, - i, - to_char(i % 10, 'FM0000') -from - generate_series(1, 299) as i -where - i % 10 in (1, 3); +select i, i, to_char(i % 10, 'FM0000') from generate_series(1, 299) as i where i % 10 in (1, 3); insert into plt1_adv values (-1, -1, null); @@ -3406,14 +2722,7 @@ alter table plt2_adv create table plt2_adv_p3_null partition of plt2_adv for values in (null, '0007', '0009'); insert into plt2_adv -select - i, - i, - to_char(i % 10, 'FM0000') -from - generate_series(1, 299) as i -where - i % 10 in (7, 9); +select i, i, to_char(i % 10, 'FM0000') from generate_series(1, 299) as i where i % 10 in (7, 9); insert into plt2_adv values (-1, -1, null); @@ -3425,10 +2734,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3439,10 +2745,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3452,16 +2755,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3469,16 +2763,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3487,10 +2772,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3501,10 +2783,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3514,16 +2793,7 @@ select from plt1_adv as t1 where - not exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + not exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3531,16 +2801,7 @@ select from plt1_adv as t1 where - not exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and - t1.b < 10 + not exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; select @@ -3549,10 +2810,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3564,10 +2822,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3599,10 +2854,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3613,10 +2865,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3627,10 +2876,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3641,10 +2887,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3662,10 +2905,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3676,10 +2916,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3690,10 +2927,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3704,10 +2938,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3718,10 +2949,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3733,10 +2961,7 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, @@ -3750,10 +2975,7 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c left outer join plt1_adv as t3 on t1.a = t3.a and t1.c = t3.c @@ -3769,10 +2991,7 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c left outer join plt1_adv as t3 on t1.a = t3.a and t1.c = t3.c @@ -3806,10 +3025,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3820,10 +3036,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3835,14 +3048,7 @@ alter table plt2_adv create table plt2_adv_p2_ext partition of plt2_adv for values in ('0004', '0005', '0006'); insert into plt2_adv -select - i, - i, - to_char(i % 10, 'FM0000') -from - generate_series(1, 299) as i -where - i % 10 in (4, 5, 6); +select i, i, to_char(i % 10, 'FM0000') from generate_series(1, 299) as i where i % 10 in (4, 5, 6); analyze plt2_adv; @@ -3852,10 +3058,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3876,10 +3079,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3897,7 +3097,7 @@ create table plt3_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt3_adv_p1 partition of plt3_adv for values in ('0004', '0006'); @@ -3923,10 +3123,7 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c left outer join plt3_adv as t3 on t1.a = t3.a and t1.c = t3.c @@ -3942,10 +3139,7 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c left outer join plt3_adv as t3 on t1.a = t3.a and t1.c = t3.c @@ -3958,14 +3152,7 @@ drop table plt2_adv_p1; create table plt2_adv_p1_null partition of plt2_adv for values in (null, '0001', '0003'); insert into plt2_adv -select - i, - i, - to_char(i % 10, 'FM0000') -from - generate_series(1, 299) as i -where - i % 10 in (1, 3); +select i, i, to_char(i % 10, 'FM0000') from generate_series(1, 299) as i where i % 10 in (1, 3); insert into plt2_adv values (-1, -1, null); @@ -3977,10 +3164,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3991,10 +3175,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4013,10 +3194,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4027,10 +3205,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4046,7 +3221,7 @@ create table plt1_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt1_adv_p1 partition of plt1_adv for values in ('0001'); @@ -4075,7 +3250,7 @@ create table plt2_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt2_adv_p1 partition of plt2_adv for values in ('0001', '0002'); @@ -4105,10 +3280,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c in ('0003', '0004', '0005') and t1.b < 10 order by t1.a; @@ -4119,10 +3291,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c in ('0003', '0004', '0005') and t1.b < 10 order by t1.a; @@ -4133,10 +3302,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c is null and t1.b < 10 order by t1.a; @@ -4147,10 +3313,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c is null and t1.b < 10 order by t1.a; @@ -4169,10 +3332,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c in ('0003', '0004', '0005') and t1.b < 10 order by t1.a; @@ -4183,10 +3343,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c in ('0003', '0004', '0005') and t1.b < 10 order by t1.a; @@ -4197,10 +3354,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c is null and t1.b < 10 order by t1.a; @@ -4211,10 +3365,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c is null and t1.b < 10 order by t1.a; @@ -4228,7 +3379,7 @@ create table plt1_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt1_adv_p1 partition of plt1_adv for values in ('0000', '0001', '0002'); @@ -4243,21 +3394,14 @@ create table plt2_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt2_adv_p1 partition of plt2_adv for values in ('0002'); create table plt2_adv_p2 partition of plt2_adv for values in ('0003', '0004'); insert into plt2_adv -select - i, - i, - to_char(i % 5, 'FM0000') -from - generate_series(0, 24) as i -where - i % 5 in (2, 3, 4); +select i, i, to_char(i % 5, 'FM0000') from generate_series(0, 24) as i where i % 5 in (2, 3, 4); analyze plt2_adv; @@ -4266,21 +3410,14 @@ create table plt3_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt3_adv_p1 partition of plt3_adv for values in ('0001'); create table plt3_adv_p2 partition of plt3_adv for values in ('0003', '0004'); insert into plt3_adv -select - i, - i, - to_char(i % 5, 'FM0000') -from - generate_series(0, 24) as i -where - i % 5 in (1, 3, 4); +select i, i, to_char(i % 5, 'FM0000') from generate_series(0, 24) as i where i % 5 in (1, 3, 4); analyze plt3_adv; @@ -4292,16 +3429,12 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.c = t2.c full outer join plt3_adv as t3 on t1.c = t3.c where - coalesce(t1.a, 0) % 5 <> 3 and - coalesce(t1.a, 0) % 5 <> 4 + coalesce(t1.a, 0) % 5 <> 3 and coalesce(t1.a, 0) % 5 <> 4 order by t1.c, t1.a, t2.a, @@ -4315,16 +3448,12 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.c = t2.c full outer join plt3_adv as t3 on t1.c = t3.c where - coalesce(t1.a, 0) % 5 <> 3 and - coalesce(t1.a, 0) % 5 <> 4 + coalesce(t1.a, 0) % 5 <> 3 and coalesce(t1.a, 0) % 5 <> 4 order by t1.c, t1.a, t2.a, @@ -4348,7 +3477,7 @@ partition of alpha for values from ('-Infinity') to (0) partition by range(b); -create table alpha_pos partition of alpha for values from (0) to (10.0) partition by LIST(c); +create table alpha_pos partition of alpha for values from (0) to (10.0) partition by list(c); create table alpha_neg_p1 partition of alpha_neg for values from (100) to (200); @@ -4393,7 +3522,7 @@ partition by range(a); create table beta_neg partition of beta for values from (-10.0) to (0) partition by range(b); -create table beta_pos partition of beta for values from (0) to ('Infinity') partition by LIST(c); +create table beta_pos partition of beta for values from (0) to ('Infinity') partition by list(c); create table beta_neg_p1 partition of beta_neg for values from (100) to (150); @@ -4473,10 +3602,7 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.b = t2.b + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.b = t2.b where t1.b >= 125 and t1.b < 225 order by t1.a, @@ -4486,10 +3612,7 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.b = t2.b + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.b = t2.b where t1.b >= 125 and t1.b < 225 order by t1.a, @@ -4499,18 +3622,13 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.c = t2.c + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.c = t2.c where ( - (t1.b >= 100 and t1.b < 110) or - (t1.b >= 200 and t1.b < 210) + (t1.b >= 100 and t1.b < 110) or (t1.b >= 200 and t1.b < 210) ) and ( - (t2.b >= 100 and t2.b < 110) or - (t2.b >= 200 and t2.b < 210) + (t2.b >= 100 and t2.b < 110) or (t2.b >= 200 and t2.b < 210) ) and t1.c in ('0004', '0009') order by t1.a, @@ -4521,18 +3639,13 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.c = t2.c + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.c = t2.c where ( - (t1.b >= 100 and t1.b < 110) or - (t1.b >= 200 and t1.b < 210) + (t1.b >= 100 and t1.b < 110) or (t1.b >= 200 and t1.b < 210) ) and ( - (t2.b >= 100 and t2.b < 110) or - (t2.b >= 200 and t2.b < 210) + (t2.b >= 100 and t2.b < 110) or (t2.b >= 200 and t2.b < 210) ) and t1.c in ('0004', '0009') order by t1.a, @@ -4543,18 +3656,13 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.b = t2.b and t1.c = t2.c + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.b = t2.b and t1.c = t2.c where ( - (t1.b >= 100 and t1.b < 110) or - (t1.b >= 200 and t1.b < 210) + (t1.b >= 100 and t1.b < 110) or (t1.b >= 200 and t1.b < 210) ) and ( - (t2.b >= 100 and t2.b < 110) or - (t2.b >= 200 and t2.b < 210) + (t2.b >= 100 and t2.b < 110) or (t2.b >= 200 and t2.b < 210) ) and t1.c in ('0004', '0009') order by t1.a, @@ -4564,18 +3672,13 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.b = t2.b and t1.c = t2.c + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.b = t2.b and t1.c = t2.c where ( - (t1.b >= 100 and t1.b < 110) or - (t1.b >= 200 and t1.b < 210) + (t1.b >= 100 and t1.b < 110) or (t1.b >= 200 and t1.b < 210) ) and ( - (t2.b >= 100 and t2.b < 110) or - (t2.b >= 200 and t2.b < 210) + (t2.b >= 100 and t2.b < 110) or (t2.b >= 200 and t2.b < 210) ) and t1.c in ('0004', '0009') order by t1.a, @@ -4603,10 +3706,7 @@ select x.id, y.id from - fract_t as x - left outer join - fract_t as y - using ("id") + fract_t as x left outer join fract_t as y using (id) order by x.id asc limit 10; @@ -4614,10 +3714,7 @@ select x.id, y.id from - fract_t as x - left outer join - fract_t as y - using ("id") + fract_t as x left outer join fract_t as y using (id) order by x.id desc limit 10; @@ -4625,26 +3722,23 @@ select x.id, y.id from - fract_t as x - left outer join - fract_t as y - using ("id") + fract_t as x left outer join fract_t as y using (id) order by x.id desc limit 2; -create index "pht1_c_idx" on pht1 using btree (c); +create index pht1_c_idx on pht1 using btree (c); -select * from pht1 as p1 inner join pht1 as p2 using ("c") limit 1; +select * from pht1 as p1 inner join pht1 as p2 using (c) limit 1; -select * from pht1 as p1 inner join pht1 as p2 using ("c") limit 100; +select * from pht1 as p1 inner join pht1 as p2 using (c) limit 100; -select * from pht1 as p1 inner join pht1 as p2 using ("c") limit 1000; +select * from pht1 as p1 inner join pht1 as p2 using (c) limit 1000; set max_parallel_workers_per_gather = 1; set debug_parallel_query = 'on'; -select * from pht1 as p1 inner join pht1 as p2 using ("c") limit 100; +select * from pht1 as p1 inner join pht1 as p2 using (c) limit 100; reset debug_parallel_query; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_join_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_join_80.snap index cfe367034..670d9d4d7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_join_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_join_80.snap @@ -27,11 +27,11 @@ from where i % 2 = 0; -create index "iprt1_p1_a" on prt1_p1 using btree (a); +create index iprt1_p1_a on prt1_p1 using btree (a); -create index "iprt1_p2_a" on prt1_p2 using btree (a); +create index iprt1_p2_a on prt1_p2 using btree (a); -create index "iprt1_p3_a" on prt1_p3 using btree (a); +create index iprt1_p3_a on prt1_p3 using btree (a); analyze prt1; @@ -58,11 +58,11 @@ from where i % 3 = 0; -create index "iprt2_p1_b" on prt2_p1 using btree (b); +create index iprt2_p1_b on prt2_p1 using btree (b); -create index "iprt2_p2_b" on prt2_p2 using btree (b); +create index iprt2_p2_b on prt2_p2 using btree (b); -create index "iprt2_p3_b" on prt2_p3 using btree (b); +create index iprt2_p3_b on prt2_p3 using btree (b); analyze prt2; @@ -119,23 +119,17 @@ order by t1.a, t2.b; select - COUNT(*) + count(*) from - prt1 as t1 - left outer join - prt1 as t2 - on t1.a = t2.a + prt1 as t1 left outer join prt1 as t2 on t1.a = t2.a left outer join prt1 as t3 on t2.a = t3.a; select - COUNT(*) + count(*) from - prt1 as t1 - left outer join - prt1 as t2 - on t1.a = t2.a + prt1 as t1 left outer join prt1 as t2 on t1.a = t2.a left outer join prt1 as t3 on t2.a = t3.a; @@ -144,10 +138,7 @@ select t1, t2 from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -157,10 +148,7 @@ select t1, t2 from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -172,10 +160,7 @@ select t2.b, t2.c from - prt1 as t1 - right outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 right outer join prt2 as t2 on t1.a = t2.b where t2.a = 0 order by t1.a, @@ -187,10 +172,7 @@ select t2.b, t2.c from - prt1 as t1 - right outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 right outer join prt2 as t2 on t1.a = t2.b where t2.a = 0 order by t1.a, @@ -202,27 +184,9 @@ select t2.b, t2.c from - ( - select - 50 as phv, - * - from - prt1 - where - prt1.b = 0 - ) - as t1 + (select 50 as phv, * from prt1 where prt1.b = 0) as t1 full outer join - ( - select - 75 as phv, - * - from - prt2 - where - prt2.a = 0 - ) - as t2 + (select 75 as phv, * from prt2 where prt2.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -235,27 +199,9 @@ select t2.b, t2.c from - ( - select - 50 as phv, - * - from - prt1 - where - prt1.b = 0 - ) - as t1 + (select 50 as phv, * from prt1 where prt1.b = 0) as t1 full outer join - ( - select - 75 as phv, - * - from - prt2 - where - prt2.a = 0 - ) - as t2 + (select 75 as phv, * from prt2 where prt2.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -271,10 +217,7 @@ from prt1 as t1, prt2 as t2 where - t1.a = t2.b and - t1.a < 450 and - t2.b > 250 and - t1.b = 0 + t1.a = t2.b and t1.a < 450 and t2.b > 250 and t1.b = 0 order by t1.a, t2.b; @@ -287,10 +230,7 @@ from prt1 as t1, prt2 as t2 where - t1.a = t2.b and - t1.a < 450 and - t2.b > 250 and - t1.b = 0 + t1.a = t2.b and t1.a < 450 and t2.b > 250 and t1.b = 0 order by t1.a, t2.b; @@ -359,16 +299,7 @@ select from prt1 as t1 where - t1.a in - ( - select - t2.b - from - prt2 as t2 - where - t2.a = 0 - ) and - t1.b = 0 + t1.a in (select t2.b from prt2 as t2 where t2.a = 0) and t1.b = 0 order by t1.a; select @@ -376,53 +307,28 @@ select from prt1 as t1 where - t1.a in - ( - select - t2.b - from - prt2 as t2 - where - t2.a = 0 - ) and - t1.b = 0 + t1.a in (select t2.b from prt2 as t2 where t2.a = 0) and t1.b = 0 order by t1.a; select - SUM(t1.a), - AVG(t1.a), - SUM(t1.b), - AVG(t1.b) + sum(t1.a), + avg(t1.a), + sum(t1.b), + avg(t1.b) from prt1 as t1 where - not exists - ( - select - 1 - from - prt2 as t2 - where - t1.a = t2.b - ); + not exists (select 1 from prt2 as t2 where t1.a = t2.b); select - SUM(t1.a), - AVG(t1.a), - SUM(t1.b), - AVG(t1.b) + sum(t1.a), + avg(t1.a), + sum(t1.b), + avg(t1.b) from prt1 as t1 where - not exists - ( - select - 1 - from - prt2 as t2 - where - t1.a = t2.b - ); + not exists (select 1 from prt2 as t2 where t1.a = t2.b); select * @@ -435,10 +341,7 @@ from t3.a as t3a, least(t1.a, t2.a, t3.b) from - prt1 as t2 - inner join - prt2 as t3 - on t2.a = t3.b + prt1 as t2 inner join prt2 as t3 on t2.a = t3.b ) as ss on t1.a = ss.t2a @@ -457,10 +360,7 @@ from t3.a as t3a, least(t1.a, t2.a, t3.b) from - prt1 as t2 - inner join - prt2 as t3 - on t2.a = t3.b + prt1 as t2 inner join prt2 as t3 on t2.a = t3.b ) as ss on t1.a = ss.t2a @@ -483,10 +383,7 @@ from t2.c as t2c, least(t1.a, t2.a, t3.b) from - prt1 as t2 - inner join - prt2 as t3 - on t2.a = t3.b + prt1 as t2 inner join prt2 as t3 on t2.a = t3.b ) as ss on t1.c = ss.t2c @@ -509,10 +406,7 @@ from t2.c as t2c, least(t1.a, t2.a, t3.a) from - prt1 as t2 - inner join - prt2 as t3 - on t2.a = t3.b + prt1 as t2 inner join prt2 as t3 on t2.a = t3.b ) as ss on t1.c = ss.t2c @@ -526,64 +420,47 @@ from prt1 as t1 inner join lateral ( - select - * - from - prt1 as t2 - tablesample system (t1.a) - repeatable (t1.b) + select * from prt1 as t2 tablesample system (t1.a) repeatable (t1.b) ) as s on t1.a = s.a; select - COUNT(*) + count(*) from prt1 as t1 left outer join - lateral ( - select t1.b as t1b, t2.* from prt2 as t2 - ) - as s + lateral (select t1.b as t1b, t2.* from prt2 as t2) as s on t1.a = s.b where s.t1b = s.a; select - COUNT(*) + count(*) from prt1 as t1 left outer join - lateral ( - select t1.b as t1b, t2.* from prt2 as t2 - ) - as s + lateral (select t1.b as t1b, t2.* from prt2 as t2) as s on t1.a = s.b where s.t1b = s.a; select - COUNT(*) + count(*) from prt1 as t1 left outer join - lateral ( - select t1.b as t1b, t2.* from prt2 as t2 - ) - as s + lateral (select t1.b as t1b, t2.* from prt2 as t2) as s on t1.a = s.b where s.t1b = s.b; select - COUNT(*) + count(*) from prt1 as t1 left outer join - lateral ( - select t1.b as t1b, t2.* from prt2 as t2 - ) - as s + lateral (select t1.b as t1b, t2.* from prt2 as t2) as s on t1.a = s.b where s.t1b = s.b; @@ -596,12 +473,7 @@ select a, b from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) where a between 490 and 510 group by 1, @@ -613,12 +485,7 @@ select a, b from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) where a between 490 and 510 group by 1, @@ -633,10 +500,7 @@ reset enable_hashjoin; select * from - prt1 as t1 - inner join - prt1 as t2 - on t1.a = t2.a + prt1 as t1 inner join prt1 as t2 on t1.a = t2.a where t1.a in (select a from prt1 as t3); @@ -655,11 +519,11 @@ create table prt1_e_p3 partition of prt1_e for values from (500) to (600); insert into prt1_e select i, i, i % 25 from generate_series(0, 599, 2) as i; -create index "iprt1_e_p1_ab2" on prt1_e_p1 using btree (((a + b) / 2)); +create index iprt1_e_p1_ab2 on prt1_e_p1 using btree (((a + b) / 2)); -create index "iprt1_e_p2_ab2" on prt1_e_p2 using btree (((a + b) / 2)); +create index iprt1_e_p2_ab2 on prt1_e_p2 using btree (((a + b) / 2)); -create index "iprt1_e_p3_ab2" on prt1_e_p3 using btree (((a + b) / 2)); +create index iprt1_e_p3_ab2 on prt1_e_p3 using btree (((a + b) / 2)); analyze prt1_e; @@ -689,8 +553,7 @@ from prt1_e as t1, prt2_e as t2 where - (t1.a + t1.b) / 2 = (t2.b + t2.a) / 2 and - t1.c = 0 + (t1.a + t1.b) / 2 = (t2.b + t2.a) / 2 and t1.c = 0 order by t1.a, t2.b; @@ -703,8 +566,7 @@ from prt1_e as t1, prt2_e as t2 where - (t1.a + t1.b) / 2 = (t2.b + t2.a) / 2 and - t1.c = 0 + (t1.a + t1.b) / 2 = (t2.b + t2.a) / 2 and t1.c = 0 order by t1.a, t2.b; @@ -720,9 +582,7 @@ from prt2 as t2, prt1_e as t3 where - t1.a = t2.b and - t1.a = (t3.a + t3.b) / 2 and - t1.b = 0 + t1.a = t2.b and t1.a = (t3.a + t3.b) / 2 and t1.b = 0 order by t1.a, t2.b; @@ -738,9 +598,7 @@ from prt2 as t2, prt1_e as t3 where - t1.a = t2.b and - t1.a = (t3.a + t3.b) / 2 and - t1.b = 0 + t1.a = t2.b and t1.a = (t3.a + t3.b) / 2 and t1.b = 0 order by t1.a, t2.b; @@ -752,10 +610,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b left outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -773,10 +628,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b left outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -794,10 +646,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b right outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -815,10 +664,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b right outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -829,80 +675,60 @@ order by t1.a, t3.a + t3.b; select - COUNT(*) + count(*) from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) full outer join prt2 as p3 (b, a, c) using ( - "a", - "b") + a, + b) where a between 490 and 510; select - COUNT(*) + count(*) from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) full outer join prt2 as p3 (b, a, c) using ( - "a", - "b") + a, + b) where a between 490 and 510; select - COUNT(*) + count(*) from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) full outer join prt2 as p3 (b, a, c) using ( - "a", - "b") + a, + b) full outer join prt1 as p4 (a, b, c) using ( - "a", - "b") + a, + b) where a between 490 and 510; select - COUNT(*) + count(*) from - prt1 - full outer join - prt2 as p2 (b, a, c) - using ( - "a", - "b") + prt1 full outer join prt2 as p2 (b, a, c) using ( a, b) full outer join prt2 as p3 (b, a, c) using ( - "a", - "b") + a, + b) full outer join prt1 as p4 (a, b, c) using ( - "a", - "b") + a, + b) where a between 490 and 510; @@ -914,44 +740,15 @@ select t3.a + t3.b, t3.phv from - ( - select - 50 as phv, - * - from - prt1 - where - prt1.b = 0 - ) - as t1 + (select 50 as phv, * from prt1 where prt1.b = 0) as t1 full outer join - ( - select - 75 as phv, - * - from - prt2 - where - prt2.a = 0 - ) - as t2 + (select 75 as phv, * from prt2 where prt2.a = 0) as t2 on t1.a = t2.b full outer join - ( - select - 50 as phv, - * - from - prt1_e - where - prt1_e.c = 0 - ) - as t3 + (select 50 as phv, * from prt1_e where prt1_e.c = 0) as t3 on t1.a = (t3.a + t3.b) / 2 where - t1.a = t1.phv or - t2.b = t2.phv or - (t3.a + t3.b) / 2 = t3.phv + t1.a = t1.phv or t2.b = t2.phv or (t3.a + t3.b) / 2 = t3.phv order by t1.a, t2.b, t3.a + t3.b; @@ -964,44 +761,15 @@ select t3.a + t3.b, t3.phv from - ( - select - 50 as phv, - * - from - prt1 - where - prt1.b = 0 - ) - as t1 + (select 50 as phv, * from prt1 where prt1.b = 0) as t1 full outer join - ( - select - 75 as phv, - * - from - prt2 - where - prt2.a = 0 - ) - as t2 + (select 75 as phv, * from prt2 where prt2.a = 0) as t2 on t1.a = t2.b full outer join - ( - select - 50 as phv, - * - from - prt1_e - where - prt1_e.c = 0 - ) - as t3 + (select 50 as phv, * from prt1_e where prt1_e.c = 0) as t3 on t1.a = (t3.a + t3.b) / 2 where - t1.a = t1.phv or - t2.b = t2.phv or - (t3.a + t3.b) / 2 = t3.phv + t1.a = t1.phv or t2.b = t2.phv or (t3.a + t3.b) / 2 = t3.phv order by t1.a, t2.b, t3.a + t3.b; @@ -1054,15 +822,7 @@ where from prt2 as t1 where - t1.b in - ( - select - (t1.a + t1.b) / 2 - from - prt1_e as t1 - where - t1.c = 0 - ) + t1.b in (select (t1.a + t1.b) / 2 from prt1_e as t1 where t1.c = 0) ) and t1.b = 0 order by t1.a; @@ -1079,15 +839,7 @@ where from prt2 as t1 where - t1.b in - ( - select - (t1.a + t1.b) / 2 - from - prt1_e as t1 - where - t1.c = 0 - ) + t1.b in (select (t1.a + t1.b) / 2 from prt1_e as t1 where t1.c = 0) ) and t1.b = 0 order by t1.a; @@ -1108,15 +860,7 @@ where from prt2 as t1 where - t1.b in - ( - select - (t1.a + t1.b) / 2 - from - prt1_e as t1 - where - t1.c = 0 - ) + t1.b in (select (t1.a + t1.b) / 2 from prt1_e as t1 where t1.c = 0) ) and t1.b = 0 order by t1.a; @@ -1133,15 +877,7 @@ where from prt2 as t1 where - t1.b in - ( - select - (t1.a + t1.b) / 2 - from - prt1_e as t1 - where - t1.c = 0 - ) + t1.b in (select (t1.a + t1.b) / 2 from prt1_e as t1 where t1.c = 0) ) and t1.b = 0 order by t1.a; @@ -1154,10 +890,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b right outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -1175,10 +908,7 @@ select t3.a + t3.b, t3.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a = t2.b + prt1 as t1 left outer join prt2 as t2 on t1.a = t2.b right outer join prt1_e as t3 on t1.a = (t3.a + t3.b) / 2 @@ -1221,8 +951,7 @@ from prt1 as t1, prt2 as t2 where - cast(t1 as text) = cast(t2 as text) and - t1.a = t2.b + cast(t1 as text) = cast(t2 as text) and t1.a = t2.b order by t1.a; select @@ -1232,8 +961,7 @@ from prt1 as t1, prt2 as t2 where - cast(t1 as text) = cast(t2 as text) and - t1.a = t2.b + cast(t1 as text) = cast(t2 as text) and t1.a = t2.b order by t1.a; reset enable_hashjoin; @@ -1288,17 +1016,10 @@ select t2.b, t2.c from - ( - select * from prt1_m where prt1_m.c = 0 - ) - as t1 + (select * from prt1_m where prt1_m.c = 0) as t1 full outer join - ( - select * from prt2_m where prt2_m.c = 0 - ) - as t2 - on t1.a = (t2.b + t2.a) / 2 and - t2.b = (t1.a + t1.b) / 2 + (select * from prt2_m where prt2_m.c = 0) as t2 + on t1.a = (t2.b + t2.a) / 2 and t2.b = (t1.a + t1.b) / 2 order by t1.a, t2.b; @@ -1308,17 +1029,10 @@ select t2.b, t2.c from - ( - select * from prt1_m where prt1_m.c = 0 - ) - as t1 + (select * from prt1_m where prt1_m.c = 0) as t1 full outer join - ( - select * from prt2_m where prt2_m.c = 0 - ) - as t2 - on t1.a = (t2.b + t2.a) / 2 and - t2.b = (t1.a + t1.b) / 2 + (select * from prt2_m where prt2_m.c = 0) as t2 + on t1.a = (t2.b + t2.a) / 2 and t2.b = (t1.a + t1.b) / 2 order by t1.a, t2.b; @@ -1327,36 +1041,22 @@ create table plt1 ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt1_p1 partition of plt1 -for values in ('0000', -'0003', -'0004', -'0010'); +for values in ('0000', '0003', '0004', '0010'); create table plt1_p2 partition of plt1 -for values in ('0001', -'0005', -'0002', -'0009'); +for values in ('0001', '0005', '0002', '0009'); create table plt1_p3 partition of plt1 -for values in ('0006', -'0007', -'0008', -'0011'); +for values in ('0006', '0007', '0008', '0011'); insert into plt1 -select - i, - i, - to_char(i / 50, 'FM0000') -from - generate_series(0, 599, 2) as i; +select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 2) as i; analyze plt1; @@ -1365,36 +1065,22 @@ create table plt2 ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt2_p1 partition of plt2 -for values in ('0000', -'0003', -'0004', -'0010'); +for values in ('0000', '0003', '0004', '0010'); create table plt2_p2 partition of plt2 -for values in ('0001', -'0005', -'0002', -'0009'); +for values in ('0001', '0005', '0002', '0009'); create table plt2_p3 partition of plt2 -for values in ('0006', -'0007', -'0008', -'0011'); +for values in ('0006', '0007', '0008', '0011'); insert into plt2 -select - i, - i, - to_char(i / 50, 'FM0000') -from - generate_series(0, 599, 3) as i; +select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 3) as i; analyze plt2; @@ -1403,28 +1089,19 @@ create table plt1_e ( b int, c text ) -partition by LIST((ltrim(c, 'A'))); +partition by list((ltrim(c, 'A'))); create table plt1_e_p1 partition of plt1_e -for values in ('0000', -'0003', -'0004', -'0010'); +for values in ('0000', '0003', '0004', '0010'); create table plt1_e_p2 partition of plt1_e -for values in ('0001', -'0005', -'0002', -'0009'); +for values in ('0001', '0005', '0002', '0009'); create table plt1_e_p3 partition of plt1_e -for values in ('0006', -'0007', -'0008', -'0011'); +for values in ('0006', '0007', '0008', '0011'); insert into plt1_e select @@ -1437,9 +1114,9 @@ from analyze plt1_e; select - AVG(t1.a), - AVG(t2.b), - AVG(t3.a + t3.b), + avg(t1.a), + avg(t2.b), + avg(t3.a + t3.b), t1.c, t2.c, t3.c @@ -1448,9 +1125,7 @@ from plt2 as t2, plt1_e as t3 where - t1.b = t2.b and - t1.c = t2.c and - ltrim(t3.c, 'A') = t1.c + t1.b = t2.b and t1.c = t2.c and ltrim(t3.c, 'A') = t1.c group by t1.c, t2.c, t3.c @@ -1459,9 +1134,9 @@ order by t1.c, t3.c; select - AVG(t1.a), - AVG(t2.b), - AVG(t3.a + t3.b), + avg(t1.a), + avg(t2.b), + avg(t3.a + t3.b), t1.c, t2.c, t3.c @@ -1470,9 +1145,7 @@ from plt2 as t2, plt1_e as t3 where - t1.b = t2.b and - t1.c = t2.c and - ltrim(t3.c, 'A') = t1.c + t1.b = t2.b and t1.c = t2.c and ltrim(t3.c, 'A') = t1.c group by t1.c, t2.c, t3.c @@ -1497,10 +1170,7 @@ select t2.b, t2.c from - ( - select * from prt1 where a = 1 and a = 2 - ) - as t1 + (select * from prt1 where a = 1 and a = 2) as t1 left outer join prt2 as t2 on t1.a = t2.b; @@ -1511,10 +1181,7 @@ select t2.b, t2.c from - ( - select * from prt1 where a = 1 and a = 2 - ) - as t1 + (select * from prt1 where a = 1 and a = 2) as t1 right outer join prt2 as t2 on t1.a = t2.b, @@ -1528,10 +1195,7 @@ select t2.b, t2.c from - ( - select * from prt1 where a = 1 and a = 2 - ) - as t1 + (select * from prt1 where a = 1 and a = 2) as t1 full outer join prt2 as t2 on t1.a = t2.b @@ -1545,21 +1209,16 @@ create table pht1 ( b int, c text ) -partition by HASH(c); +partition by hash(c); -create table pht1_p1 partition of pht1 for values with (MODULUS 3, REMAINDER 0); +create table pht1_p1 partition of pht1 for values with (modulus 3, remainder 0); -create table pht1_p2 partition of pht1 for values with (MODULUS 3, REMAINDER 1); +create table pht1_p2 partition of pht1 for values with (modulus 3, remainder 1); -create table pht1_p3 partition of pht1 for values with (MODULUS 3, REMAINDER 2); +create table pht1_p3 partition of pht1 for values with (modulus 3, remainder 2); insert into pht1 -select - i, - i, - to_char(i / 50, 'FM0000') -from - generate_series(0, 599, 2) as i; +select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 2) as i; analyze pht1; @@ -1568,21 +1227,16 @@ create table pht2 ( b int, c text ) -partition by HASH(c); +partition by hash(c); -create table pht2_p1 partition of pht2 for values with (MODULUS 3, REMAINDER 0); +create table pht2_p1 partition of pht2 for values with (modulus 3, remainder 0); -create table pht2_p2 partition of pht2 for values with (MODULUS 3, REMAINDER 1); +create table pht2_p2 partition of pht2 for values with (modulus 3, remainder 1); -create table pht2_p3 partition of pht2 for values with (MODULUS 3, REMAINDER 2); +create table pht2_p3 partition of pht2 for values with (modulus 3, remainder 2); insert into pht2 -select - i, - i, - to_char(i / 50, 'FM0000') -from - generate_series(0, 599, 3) as i; +select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 3) as i; analyze pht2; @@ -1591,19 +1245,19 @@ create table pht1_e ( b int, c text ) -partition by HASH((ltrim(c, 'A'))); +partition by hash((ltrim(c, 'A'))); create table pht1_e_p1 partition of pht1_e -for values with (MODULUS 3, REMAINDER 0); +for values with (modulus 3, remainder 0); create table pht1_e_p2 partition of pht1_e -for values with (MODULUS 3, REMAINDER 1); +for values with (modulus 3, remainder 1); create table pht1_e_p3 partition of pht1_e -for values with (MODULUS 3, REMAINDER 2); +for values with (modulus 3, remainder 2); insert into pht1_e select @@ -1616,9 +1270,9 @@ from analyze pht1_e; select - AVG(t1.a), - AVG(t2.b), - AVG(t3.a + t3.b), + avg(t1.a), + avg(t2.b), + avg(t3.a + t3.b), t1.c, t2.c, t3.c @@ -1627,9 +1281,7 @@ from pht2 as t2, pht1_e as t3 where - t1.b = t2.b and - t1.c = t2.c and - ltrim(t3.c, 'A') = t1.c + t1.b = t2.b and t1.c = t2.c and ltrim(t3.c, 'A') = t1.c group by t1.c, t2.c, t3.c @@ -1638,9 +1290,9 @@ order by t1.c, t3.c; select - AVG(t1.a), - AVG(t2.b), - AVG(t3.a + t3.b), + avg(t1.a), + avg(t2.b), + avg(t3.a + t3.b), t1.c, t2.c, t3.c @@ -1649,9 +1301,7 @@ from pht2 as t2, pht1_e as t3 where - t1.b = t2.b and - t1.c = t2.c and - ltrim(t3.c, 'A') = t1.c + t1.b = t2.b and t1.c = t2.c and ltrim(t3.c, 'A') = t1.c group by t1.c, t2.c, t3.c @@ -1713,15 +1363,12 @@ alter table plt2 analyze plt2; select - AVG(t1.a), - AVG(t2.b), + avg(t1.a), + avg(t2.b), t1.c, t2.c from - plt1 as t1 - right outer join - plt2 as t2 - on t1.c = t2.c + plt1 as t1 right outer join plt2 as t2 on t1.c = t2.c where t1.a % 25 = 0 group by t1.c, @@ -1741,7 +1388,7 @@ create table prt1_l_p1 partition of prt1_l for values from (0) to (250); create table prt1_l_p2 partition of prt1_l for values from (250) to (500) -partition by LIST(c); +partition by list(c); create table prt1_l_p2_p1 partition of prt1_l_p2 for values in ('0000', '0001'); @@ -1757,12 +1404,7 @@ create table prt1_l_p3_p1 partition of prt1_l_p3 for values from (0) to (13); create table prt1_l_p3_p2 partition of prt1_l_p3 for values from (13) to (25); insert into prt1_l -select - i, - i % 25, - to_char(i % 4, 'FM0000') -from - generate_series(0, 599, 2) as i; +select i, i % 25, to_char(i % 4, 'FM0000') from generate_series(0, 599, 2) as i; analyze prt1_l; @@ -1778,7 +1420,7 @@ create table prt2_l_p1 partition of prt2_l for values from (0) to (250); create table prt2_l_p2 partition of prt2_l for values from (250) to (500) -partition by LIST(c); +partition by list(c); create table prt2_l_p2_p1 partition of prt2_l_p2 for values in ('0000', '0001'); @@ -1794,12 +1436,7 @@ create table prt2_l_p3_p1 partition of prt2_l_p3 for values from (0) to (13); create table prt2_l_p3_p2 partition of prt2_l_p3 for values from (13) to (25); insert into prt2_l -select - i % 25, - i, - to_char(i % 4, 'FM0000') -from - generate_series(0, 599, 3) as i; +select i % 25, i, to_char(i % 4, 'FM0000') from generate_series(0, 599, 3) as i; analyze prt2_l; @@ -1838,9 +1475,7 @@ from prt1_l as t1, prt2_l as t2 where - t1.a = t2.a and - t1.a = t2.b and - t1.c = t2.c + t1.a = t2.a and t1.a = t2.b and t1.c = t2.c order by t1.a, t2.b; @@ -1853,9 +1488,7 @@ from prt1_l as t1, prt2_l as t2 where - t1.a = t2.a and - t1.a = t2.b and - t1.c = t2.c + t1.a = t2.a and t1.a = t2.b and t1.c = t2.c order by t1.a, t2.b; @@ -1865,10 +1498,7 @@ select t2.b, t2.c from - prt1_l as t1 - left outer join - prt2_l as t2 - on t1.a = t2.b and t1.c = t2.c + prt1_l as t1 left outer join prt2_l as t2 on t1.a = t2.b and t1.c = t2.c where t1.b = 0 order by t1.a, @@ -1880,10 +1510,7 @@ select t2.b, t2.c from - prt1_l as t1 - left outer join - prt2_l as t2 - on t1.a = t2.b and t1.c = t2.c + prt1_l as t1 left outer join prt2_l as t2 on t1.a = t2.b and t1.c = t2.c where t1.b = 0 order by t1.a, @@ -1895,10 +1522,7 @@ select t2.b, t2.c from - prt1_l as t1 - right outer join - prt2_l as t2 - on t1.a = t2.b and t1.c = t2.c + prt1_l as t1 right outer join prt2_l as t2 on t1.a = t2.b and t1.c = t2.c where t2.a = 0 order by t1.a, @@ -1910,10 +1534,7 @@ select t2.b, t2.c from - prt1_l as t1 - right outer join - prt2_l as t2 - on t1.a = t2.b and t1.c = t2.c + prt1_l as t1 right outer join prt2_l as t2 on t1.a = t2.b and t1.c = t2.c where t2.a = 0 order by t1.a, @@ -1925,15 +1546,9 @@ select t2.b, t2.c from - ( - select * from prt1_l where prt1_l.b = 0 - ) - as t1 + (select * from prt1_l where prt1_l.b = 0) as t1 full outer join - ( - select * from prt2_l where prt2_l.a = 0 - ) - as t2 + (select * from prt2_l where prt2_l.a = 0) as t2 on t1.a = t2.b and t1.c = t2.c order by t1.a, t2.b; @@ -1944,15 +1559,9 @@ select t2.b, t2.c from - ( - select * from prt1_l where prt1_l.b = 0 - ) - as t1 + (select * from prt1_l where prt1_l.b = 0) as t1 full outer join - ( - select * from prt2_l where prt2_l.a = 0 - ) - as t2 + (select * from prt2_l where prt2_l.a = 0) as t2 on t1.a = t2.b and t1.c = t2.c order by t1.a, t2.b; @@ -1970,10 +1579,7 @@ from t3.b as t3b, least(t1.a, t2.a, t3.b) from - prt1_l as t2 - inner join - prt2_l as t3 - on t2.a = t3.b and t2.c = t3.c + prt1_l as t2 inner join prt2_l as t3 on t2.a = t3.b and t2.c = t3.c ) as ss on t1.a = ss.t2a and t1.c = ss.t2c @@ -1994,10 +1600,7 @@ from t3.b as t3b, least(t1.a, t2.a, t3.b) from - prt1_l as t2 - inner join - prt2_l as t3 - on t2.a = t3.b and t2.c = t3.c + prt1_l as t2 inner join prt2_l as t3 on t2.a = t3.b and t2.c = t3.c ) as ss on t1.a = ss.t2a and t1.c = ss.t2c @@ -2011,46 +1614,27 @@ from prt1_l as t1 inner join lateral ( - select - * - from - prt1_l as t2 - tablesample system (t1.a) - repeatable (t1.b) + select * from prt1_l as t2 tablesample system (t1.a) repeatable (t1.b) ) as s on t1.a = s.a and t1.b = s.b and t1.c = s.c; select - COUNT(*) + count(*) from prt1_l as t1 left outer join - lateral ( - select - t1.b as t1b, - t2.* - from - prt2_l as t2 - ) - as s + lateral (select t1.b as t1b, t2.* from prt2_l as t2) as s on t1.a = s.b and t1.b = s.a and t1.c = s.c where s.t1b = s.a; select - COUNT(*) + count(*) from prt1_l as t1 left outer join - lateral ( - select - t1.b as t1b, - t2.* - from - prt2_l as t2 - ) - as s + lateral (select t1.b as t1b, t2.* from prt2_l as t2) as s on t1.a = s.b and t1.b = s.a and t1.c = s.c where s.t1b = s.a; @@ -2061,20 +1645,10 @@ select t2.b, t2.c from - ( - select - * - from - prt1_l - where - a = 1 and a = 2 - ) - as t1 + (select * from prt1_l where a = 1 and a = 2) as t1 right outer join prt2_l as t2 - on t1.a = t2.b and - t1.b = t2.a and - t1.c = t2.c; + on t1.a = t2.b and t1.b = t2.a and t1.c = t2.c; delete from prt1_l where @@ -2084,10 +1658,7 @@ where 1 from int4_tbl, - lateral ( - select int4_tbl.f1 from int8_tbl limit 2 - ) - as ss + lateral (select int4_tbl.f1 from int8_tbl limit 2) as ss where prt1_l.c is null ); @@ -2104,12 +1675,7 @@ create table prt1_n_p1 partition of prt1_n for values from ('0000') to ('0250'); create table prt1_n_p2 partition of prt1_n for values from ('0250') to ('0500'); insert into prt1_n -select - i, - i, - to_char(i, 'FM0000') -from - generate_series(0, 499, 2) as i; +select i, i, to_char(i, 'FM0000') from generate_series(0, 499, 2) as i; analyze prt1_n; @@ -2118,33 +1684,18 @@ create table prt2_n ( b int, c text ) -partition by LIST(c); +partition by list(c); create table prt2_n_p1 partition of prt2_n -for values in ('0000', -'0003', -'0004', -'0010', -'0006', -'0007'); +for values in ('0000', '0003', '0004', '0010', '0006', '0007'); create table prt2_n_p2 partition of prt2_n -for values in ('0001', -'0005', -'0002', -'0009', -'0008', -'0011'); +for values in ('0001', '0005', '0002', '0009', '0008', '0011'); insert into prt2_n -select - i, - i, - to_char(i / 50, 'FM0000') -from - generate_series(0, 599, 2) as i; +select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 2) as i; analyze prt2_n; @@ -2153,36 +1704,22 @@ create table prt3_n ( b int, c text ) -partition by LIST(c); +partition by list(c); create table prt3_n_p1 partition of prt3_n -for values in ('0000', -'0004', -'0006', -'0007'); +for values in ('0000', '0004', '0006', '0007'); create table prt3_n_p2 partition of prt3_n -for values in ('0001', -'0002', -'0008', -'0010'); +for values in ('0001', '0002', '0008', '0010'); create table prt3_n_p3 partition of prt3_n -for values in ('0003', -'0005', -'0009', -'0011'); +for values in ('0003', '0005', '0009', '0011'); insert into prt2_n -select - i, - i, - to_char(i / 50, 'FM0000') -from - generate_series(0, 599, 2) as i; +select i, i, to_char(i / 50, 'FM0000') from generate_series(0, 599, 2) as i; analyze prt3_n; @@ -2200,12 +1737,7 @@ create table prt4_n_p2 partition of prt4_n for values from (300) to (500); create table prt4_n_p3 partition of prt4_n for values from (500) to (600); insert into prt4_n -select - i, - i, - to_char(i, 'FM0000') -from - generate_series(0, 599, 2) as i; +select i, i, to_char(i, 'FM0000') from generate_series(0, 599, 2) as i; analyze prt4_n; @@ -2229,10 +1761,7 @@ select t2.b, t2.c from - prt1 as t1 - left outer join - prt2 as t2 - on t1.a < t2.b; + prt1 as t1 left outer join prt2 as t2 on t1.a < t2.b; select t1.a, @@ -2251,10 +1780,7 @@ select t2.b, t2.c from - prt1_m as t1 - left outer join - prt2_m as t2 - on t1.a = t2.b; + prt1_m as t1 left outer join prt2_m as t2 on t1.a = t2.b; select t1.a, @@ -2262,10 +1788,7 @@ select t2.b, t2.c from - prt1_m as t1 - left outer join - prt2_m as t2 - on t1.c = t2.c; + prt1_m as t1 left outer join prt2_m as t2 on t1.c = t2.c; select t1.a, @@ -2273,10 +1796,7 @@ select t2.b, t2.c from - prt1_n as t1 - left outer join - prt2_n as t2 - on t1.c = t2.c; + prt1_n as t1 left outer join prt2_n as t2 on t1.c = t2.c; select t1.a, @@ -2284,10 +1804,7 @@ select t2.b, t2.c from - prt1_n as t1 - inner join - prt2_n as t2 - on t1.c = t2.c + prt1_n as t1 inner join prt2_n as t2 on t1.c = t2.c inner join plt1 as t3 on t1.c = t3.c; @@ -2298,10 +1815,7 @@ select t2.b, t2.c from - prt1_n as t1 - full outer join - prt1 as t2 - on t1.c = t2.c; + prt1_n as t1 full outer join prt1 as t2 on t1.c = t2.c; create temporary table prtx1 ( a int, @@ -2360,9 +1874,7 @@ where from prtx2 where - prtx2.a = prtx1.a and - prtx2.b = prtx1.b and - prtx2.c = 123 + prtx2.a = prtx1.a and prtx2.b = prtx1.b and prtx2.c = 123 ) and a < 20 and c = 120; @@ -2379,9 +1891,7 @@ where from prtx2 where - prtx2.a = prtx1.a and - prtx2.b = prtx1.b and - prtx2.c = 123 + prtx2.a = prtx1.a and prtx2.b = prtx1.b and prtx2.c = 123 ) and a < 20 and c = 120; @@ -2398,10 +1908,7 @@ where from prtx2 where - prtx2.a = prtx1.a and - ( - prtx2.b = prtx1.b + 1 or prtx2.c = 99 - ) + prtx2.a = prtx1.a and (prtx2.b = prtx1.b + 1 or prtx2.c = 99) ) and a < 20 and c = 91; @@ -2418,10 +1925,7 @@ where from prtx2 where - prtx2.a = prtx1.a and - ( - prtx2.b = prtx1.b + 1 or prtx2.c = 99 - ) + prtx2.a = prtx1.a and (prtx2.b = prtx1.b + 1 or prtx2.c = 99) ) and a < 20 and c = 91; @@ -2439,15 +1943,10 @@ create table prt1_adv_p2 partition of prt1_adv for values from (200) to (300); create table prt1_adv_p3 partition of prt1_adv for values from (300) to (400); -create index "prt1_adv_a_idx" on prt1_adv using btree (a); +create index prt1_adv_a_idx on prt1_adv using btree (a); insert into prt1_adv -select - i, - i % 25, - to_char(i, 'FM0000') -from - generate_series(100, 399) as i; +select i, i % 25, to_char(i, 'FM0000') from generate_series(100, 399) as i; analyze prt1_adv; @@ -2464,31 +1963,16 @@ create table prt2_adv_p2 partition of prt2_adv for values from (200) to (300); create table prt2_adv_p3 partition of prt2_adv for values from (350) to (500); -create index "prt2_adv_b_idx" on prt2_adv using btree (b); +create index prt2_adv_b_idx on prt2_adv using btree (b); insert into prt2_adv_p1 -select - i % 25, - i, - to_char(i, 'FM0000') -from - generate_series(100, 149) as i; +select i % 25, i, to_char(i, 'FM0000') from generate_series(100, 149) as i; insert into prt2_adv_p2 -select - i % 25, - i, - to_char(i, 'FM0000') -from - generate_series(200, 299) as i; +select i % 25, i, to_char(i, 'FM0000') from generate_series(200, 299) as i; insert into prt2_adv_p3 -select - i % 25, - i, - to_char(i, 'FM0000') -from - generate_series(350, 499) as i; +select i % 25, i, to_char(i, 'FM0000') from generate_series(350, 499) as i; analyze prt2_adv; @@ -2498,10 +1982,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2513,10 +1994,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2527,16 +2005,7 @@ select from prt1_adv as t1 where - exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2544,16 +2013,7 @@ select from prt1_adv as t1 where - exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2562,10 +2022,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2577,10 +2034,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2591,16 +2045,7 @@ select from prt1_adv as t1 where - not exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2608,16 +2053,7 @@ select from prt1_adv as t1 where - not exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2626,27 +2062,9 @@ select t2.b, t2.c from - ( - select - 175 as phv, - * - from - prt1_adv - where - prt1_adv.b = 0 - ) - as t1 + (select 175 as phv, * from prt1_adv where prt1_adv.b = 0) as t1 full outer join - ( - select - 425 as phv, - * - from - prt2_adv - where - prt2_adv.a = 0 - ) - as t2 + (select 425 as phv, * from prt2_adv where prt2_adv.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -2659,27 +2077,9 @@ select t2.b, t2.c from - ( - select - 175 as phv, - * - from - prt1_adv - where - prt1_adv.b = 0 - ) - as t1 + (select 175 as phv, * from prt1_adv where prt1_adv.b = 0) as t1 full outer join - ( - select - 425 as phv, - * - from - prt2_adv - where - prt2_adv.a = 0 - ) - as t2 + (select 425 as phv, * from prt2_adv where prt2_adv.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -2691,12 +2091,7 @@ partition of prt2_adv for values from (500) to (maxvalue); insert into prt2_adv -select - i % 25, - i, - to_char(i, 'FM0000') -from - generate_series(500, 599) as i; +select i % 25, i, to_char(i, 'FM0000') from generate_series(500, 599) as i; analyze prt2_adv; @@ -2706,10 +2101,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2721,10 +2113,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2735,16 +2124,7 @@ select from prt1_adv as t1 where - exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2752,16 +2132,7 @@ select from prt1_adv as t1 where - exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2770,10 +2141,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2785,10 +2153,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2800,10 +2165,7 @@ select t2.a, t2.c from - prt2_adv as t1 - left outer join - prt1_adv as t2 - on t1.b = t2.a + prt2_adv as t1 left outer join prt1_adv as t2 on t1.b = t2.a where t1.a = 0 order by t1.b, @@ -2814,16 +2176,7 @@ select from prt1_adv as t1 where - not exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2831,16 +2184,7 @@ select from prt1_adv as t1 where - not exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2848,16 +2192,7 @@ select from prt2_adv as t1 where - not exists - ( - select - 1 - from - prt1_adv as t2 - where - t1.b = t2.a - ) and - t1.a = 0 + not exists (select 1 from prt1_adv as t2 where t1.b = t2.a) and t1.a = 0 order by t1.b; select @@ -2866,27 +2201,9 @@ select t2.b, t2.c from - ( - select - 175 as phv, - * - from - prt1_adv - where - prt1_adv.b = 0 - ) - as t1 + (select 175 as phv, * from prt1_adv where prt1_adv.b = 0) as t1 full outer join - ( - select - 425 as phv, - * - from - prt2_adv - where - prt2_adv.a = 0 - ) - as t2 + (select 425 as phv, * from prt2_adv where prt2_adv.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -2901,10 +2218,7 @@ select t3.a, t3.c from - prt2_adv as t1 - left outer join - prt1_adv as t2 - on t1.b = t2.a + prt2_adv as t1 left outer join prt1_adv as t2 on t1.b = t2.a inner join prt1_adv as t3 on t1.b = t3.a @@ -2922,10 +2236,7 @@ select t3.a, t3.c from - prt2_adv as t1 - left outer join - prt1_adv as t2 - on t1.b = t2.a + prt2_adv as t1 left outer join prt1_adv as t2 on t1.b = t2.a inner join prt1_adv as t3 on t1.b = t3.a @@ -2946,12 +2257,7 @@ create table prt2_adv_p3_1 partition of prt2_adv for values from (350) to (375); create table prt2_adv_p3_2 partition of prt2_adv for values from (375) to (500); insert into prt2_adv -select - i % 25, - i, - to_char(i, 'FM0000') -from - generate_series(350, 499) as i; +select i % 25, i, to_char(i, 'FM0000') from generate_series(350, 499) as i; analyze prt2_adv; @@ -2961,10 +2267,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -2975,16 +2278,7 @@ select from prt1_adv as t1 where - exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -2993,10 +2287,7 @@ select t2.b, t2.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -3007,16 +2298,7 @@ select from prt1_adv as t1 where - not exists - ( - select - 1 - from - prt2_adv as t2 - where - t1.a = t2.b - ) and - t1.b = 0 + not exists (select 1 from prt2_adv as t2 where t1.a = t2.b) and t1.b = 0 order by t1.a; select @@ -3025,27 +2307,9 @@ select t2.b, t2.c from - ( - select - 175 as phv, - * - from - prt1_adv - where - prt1_adv.b = 0 - ) - as t1 + (select 175 as phv, * from prt1_adv where prt1_adv.b = 0) as t1 full outer join - ( - select - 425 as phv, - * - from - prt2_adv - where - prt2_adv.a = 0 - ) - as t2 + (select 425 as phv, * from prt2_adv where prt2_adv.a = 0) as t2 on t1.a = t2.b where t1.phv = t1.a or t2.phv = t2.b @@ -3078,10 +2342,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -3093,10 +2354,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -3104,15 +2362,13 @@ order by t1.a, alter table prt1_adv attach partition - prt1_adv_p3 - for values from (300) to (400); + prt1_adv_p3 for values from (300) to (400); analyze prt1_adv; alter table prt2_adv attach partition - prt2_adv_p3 - for values from (350) to (500); + prt2_adv_p3 for values from (350) to (500); analyze prt2_adv; @@ -3122,10 +2378,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -3147,10 +2400,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.b = 0 order by t1.a, @@ -3175,15 +2425,10 @@ create table prt3_adv_p1 partition of prt3_adv for values from (200) to (300); create table prt3_adv_p2 partition of prt3_adv for values from (300) to (400); -create index "prt3_adv_a_idx" on prt3_adv using btree (a); +create index prt3_adv_a_idx on prt3_adv using btree (a); insert into prt3_adv -select - i, - i % 25, - to_char(i, 'FM0000') -from - generate_series(200, 399) as i; +select i, i % 25, to_char(i, 'FM0000') from generate_series(200, 399) as i; analyze prt3_adv; @@ -3195,10 +2440,7 @@ select t3.a, t3.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b left outer join prt3_adv as t3 on t1.a = t3.a @@ -3216,10 +2458,7 @@ select t3.a, t3.c from - prt1_adv as t1 - left outer join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 left outer join prt2_adv as t2 on t1.a = t2.b left outer join prt3_adv as t3 on t1.a = t3.a @@ -3248,15 +2487,10 @@ create table prt1_adv_p2 partition of prt1_adv for values from (200) to (300); create table prt1_adv_p3 partition of prt1_adv for values from (300) to (400); -create index "prt1_adv_a_idx" on prt1_adv using btree (a); +create index prt1_adv_a_idx on prt1_adv using btree (a); insert into prt1_adv -select - i, - i % 25, - to_char(i, 'FM0000') -from - generate_series(100, 399) as i; +select i, i % 25, to_char(i, 'FM0000') from generate_series(100, 399) as i; analyze prt1_adv; @@ -3271,15 +2505,10 @@ create table prt2_adv_p1 partition of prt2_adv for values from (100) to (200); create table prt2_adv_p2 partition of prt2_adv for values from (200) to (400); -create index "prt2_adv_b_idx" on prt2_adv using btree (b); +create index prt2_adv_b_idx on prt2_adv using btree (b); insert into prt2_adv -select - i % 25, - i, - to_char(i, 'FM0000') -from - generate_series(100, 399) as i; +select i % 25, i, to_char(i, 'FM0000') from generate_series(100, 399) as i; analyze prt2_adv; @@ -3289,10 +2518,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.a < 300 and t1.b = 0 order by t1.a, @@ -3304,10 +2530,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.a < 300 and t1.b = 0 order by t1.a, @@ -3329,10 +2552,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.a >= 100 and t1.a < 300 and t1.b = 0 order by t1.a, @@ -3344,10 +2564,7 @@ select t2.b, t2.c from - prt1_adv as t1 - inner join - prt2_adv as t2 - on t1.a = t2.b + prt1_adv as t1 inner join prt2_adv as t2 on t1.a = t2.b where t1.a >= 100 and t1.a < 300 and t1.b = 0 order by t1.a, @@ -3362,7 +2579,7 @@ create table plt1_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt1_adv_p1 partition of plt1_adv for values in ('0001', '0003'); @@ -3387,7 +2604,7 @@ create table plt2_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt2_adv_p1 partition of plt2_adv for values in ('0002', '0003'); @@ -3413,10 +2630,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3427,10 +2641,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3440,15 +2651,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; @@ -3457,15 +2660,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; @@ -3475,10 +2670,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3489,10 +2681,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3504,12 +2693,7 @@ from where not exists ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c + select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c ) and t1.b < 10 order by t1.a; @@ -3521,12 +2705,7 @@ from where not exists ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c + select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c ) and t1.b < 10 order by t1.a; @@ -3537,13 +2716,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -3553,13 +2728,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -3575,10 +2746,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3589,10 +2757,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3602,15 +2767,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; @@ -3619,15 +2776,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; @@ -3637,10 +2786,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3651,10 +2797,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3665,10 +2808,7 @@ select t2.a, t2.c from - plt2_adv as t1 - left outer join - plt1_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt2_adv as t1 left outer join plt1_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3680,12 +2820,7 @@ from where not exists ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c + select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c ) and t1.b < 10 order by t1.a; @@ -3697,12 +2832,7 @@ from where not exists ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c + select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c ) and t1.b < 10 order by t1.a; @@ -3714,12 +2844,7 @@ from where not exists ( - select - 1 - from - plt1_adv as t2 - where - t1.a = t2.a and t1.c = t2.c + select 1 from plt1_adv as t2 where t1.a = t2.a and t1.c = t2.c ) and t1.b < 10 order by t1.a; @@ -3730,13 +2855,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -3768,10 +2889,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3781,15 +2899,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; @@ -3799,10 +2909,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3814,12 +2921,7 @@ from where not exists ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c + select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c ) and t1.b < 10 order by t1.a; @@ -3830,13 +2932,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -3846,8 +2944,7 @@ drop table plt2_adv_p2_2; alter table plt2_adv attach partition - plt2_adv_p2 - for values in ('0004', '0006'); + plt2_adv_p2 for values in ('0004', '0006'); alter table plt1_adv detach partition @@ -3899,10 +2996,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3913,10 +3007,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3926,15 +3017,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; @@ -3943,15 +3026,7 @@ select from plt1_adv as t1 where - exists - ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c - ) and + exists (select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c) and t1.b < 10 order by t1.a; @@ -3961,10 +3036,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3975,10 +3047,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -3990,12 +3059,7 @@ from where not exists ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c + select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c ) and t1.b < 10 order by t1.a; @@ -4007,12 +3071,7 @@ from where not exists ( - select - 1 - from - plt2_adv as t2 - where - t1.a = t2.a and t1.c = t2.c + select 1 from plt2_adv as t2 where t1.a = t2.a and t1.c = t2.c ) and t1.b < 10 order by t1.a; @@ -4023,13 +3082,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -4039,13 +3094,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -4053,8 +3104,7 @@ drop table plt1_adv_p1_null; alter table plt1_adv attach partition - plt1_adv_p1 - for values in ('0001', '0003'); + plt1_adv_p1 for values in ('0001', '0003'); create table plt1_adv_extra partition of plt1_adv for values in (null); @@ -4066,8 +3116,7 @@ drop table plt2_adv_p3_null; alter table plt2_adv attach partition - plt2_adv_p3 - for values in ('0007', '0009'); + plt2_adv_p3 for values in ('0007', '0009'); analyze plt2_adv; @@ -4077,10 +3126,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4091,10 +3137,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4105,10 +3148,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4119,13 +3159,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -4141,10 +3177,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4155,10 +3188,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4169,10 +3199,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4183,10 +3210,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4197,13 +3221,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -4213,13 +3233,9 @@ select t2.a, t2.c from - plt1_adv as t1 - full outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 full outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - coalesce(t1.b, 0) < 10 and - coalesce(t2.b, 0) < 10 + coalesce(t1.b, 0) < 10 and coalesce(t2.b, 0) < 10 order by t1.a, t2.a; @@ -4231,10 +3247,7 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c left outer join plt1_adv as t3 on t1.a = t3.a and t1.c = t3.c @@ -4250,10 +3263,7 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c left outer join plt1_adv as t3 on t1.a = t3.a and t1.c = t3.c @@ -4287,10 +3297,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4301,10 +3308,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4335,10 +3339,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4359,10 +3360,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4371,8 +3369,7 @@ drop table plt2_adv_p2_ext; alter table plt2_adv attach partition - plt2_adv_p2 - for values in ('0004', '0006'); + plt2_adv_p2 for values in ('0004', '0006'); analyze plt2_adv; @@ -4381,7 +3378,7 @@ create table plt3_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt3_adv_p1 partition of plt3_adv for values in ('0004', '0006'); @@ -4407,10 +3404,7 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c left outer join plt3_adv as t3 on t1.a = t3.a and t1.c = t3.c @@ -4426,10 +3420,7 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c left outer join plt3_adv as t3 on t1.a = t3.a and t1.c = t3.c @@ -4463,10 +3454,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4477,10 +3465,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4499,10 +3484,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4513,10 +3495,7 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.b < 10 order by t1.a; @@ -4532,7 +3511,7 @@ create table plt1_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt1_adv_p1 partition of plt1_adv for values in ('0001'); @@ -4563,7 +3542,7 @@ create table plt2_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt2_adv_p1 partition of plt2_adv for values in ('0001', '0002'); @@ -4593,13 +3572,9 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - t1.c in ('0003', '0004', '0005') and - t1.b < 10 + t1.c in ('0003', '0004', '0005') and t1.b < 10 order by t1.a; select @@ -4608,13 +3583,9 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - t1.c in ('0003', '0004', '0005') and - t1.b < 10 + t1.c in ('0003', '0004', '0005') and t1.b < 10 order by t1.a; select @@ -4623,10 +3594,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c is null and t1.b < 10 order by t1.a; @@ -4637,10 +3605,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c is null and t1.b < 10 order by t1.a; @@ -4659,13 +3624,9 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - t1.c in ('0003', '0004', '0005') and - t1.b < 10 + t1.c in ('0003', '0004', '0005') and t1.b < 10 order by t1.a; select @@ -4674,13 +3635,9 @@ select t2.a, t2.c from - plt1_adv as t1 - inner join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 inner join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where - t1.c in ('0003', '0004', '0005') and - t1.b < 10 + t1.c in ('0003', '0004', '0005') and t1.b < 10 order by t1.a; select @@ -4689,10 +3646,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c is null and t1.b < 10 order by t1.a; @@ -4703,10 +3657,7 @@ select t2.a, t2.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.a = t2.a and t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.a = t2.a and t1.c = t2.c where t1.c is null and t1.b < 10 order by t1.a; @@ -4720,7 +3671,7 @@ create table plt1_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt1_adv_p1 partition of plt1_adv @@ -4729,12 +3680,7 @@ for values in ('0000', '0001', '0002'); create table plt1_adv_p2 partition of plt1_adv for values in ('0003', '0004'); insert into plt1_adv -select - i, - i, - to_char(i % 5, 'FM0000') -from - generate_series(0, 24) as i; +select i, i, to_char(i % 5, 'FM0000') from generate_series(0, 24) as i; analyze plt1_adv; @@ -4743,7 +3689,7 @@ create table plt2_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt2_adv_p1 partition of plt2_adv for values in ('0002'); @@ -4766,7 +3712,7 @@ create table plt3_adv ( b int, c text ) -partition by LIST(c); +partition by list(c); create table plt3_adv_p1 partition of plt3_adv for values in ('0001'); @@ -4792,16 +3738,12 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.c = t2.c full outer join plt3_adv as t3 on t1.c = t3.c where - coalesce(t1.a, 0) % 5 <> 3 and - coalesce(t1.a, 0) % 5 <> 4 + coalesce(t1.a, 0) % 5 <> 3 and coalesce(t1.a, 0) % 5 <> 4 order by t1.c, t1.a, t2.a, @@ -4815,16 +3757,12 @@ select t3.a, t3.c from - plt1_adv as t1 - left outer join - plt2_adv as t2 - on t1.c = t2.c + plt1_adv as t1 left outer join plt2_adv as t2 on t1.c = t2.c full outer join plt3_adv as t3 on t1.c = t3.c where - coalesce(t1.a, 0) % 5 <> 3 and - coalesce(t1.a, 0) % 5 <> 4 + coalesce(t1.a, 0) % 5 <> 3 and coalesce(t1.a, 0) % 5 <> 4 order by t1.c, t1.a, t2.a, @@ -4851,7 +3789,7 @@ partition by range(b); create table alpha_pos partition of alpha for values from (0) to (10.0) -partition by LIST(c); +partition by list(c); create table alpha_neg_p1 partition of alpha_neg for values from (100) to (200); @@ -4902,7 +3840,7 @@ partition by range(b); create table beta_pos partition of beta for values from (0) to ('Infinity') -partition by LIST(c); +partition by list(c); create table beta_neg_p1 partition of beta_neg for values from (100) to (150); @@ -4982,10 +3920,7 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.b = t2.b + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.b = t2.b where t1.b >= 125 and t1.b < 225 order by t1.a, @@ -4995,10 +3930,7 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.b = t2.b + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.b = t2.b where t1.b >= 125 and t1.b < 225 order by t1.a, @@ -5008,18 +3940,13 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.c = t2.c + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.c = t2.c where ( - (t1.b >= 100 and t1.b < 110) or - (t1.b >= 200 and t1.b < 210) + (t1.b >= 100 and t1.b < 110) or (t1.b >= 200 and t1.b < 210) ) and ( - (t2.b >= 100 and t2.b < 110) or - (t2.b >= 200 and t2.b < 210) + (t2.b >= 100 and t2.b < 110) or (t2.b >= 200 and t2.b < 210) ) and t1.c in ('0004', '0009') order by t1.a, @@ -5030,18 +3957,13 @@ select t1.*, t2.* from - alpha as t1 - inner join - beta as t2 - on t1.a = t2.a and t1.c = t2.c + alpha as t1 inner join beta as t2 on t1.a = t2.a and t1.c = t2.c where ( - (t1.b >= 100 and t1.b < 110) or - (t1.b >= 200 and t1.b < 210) + (t1.b >= 100 and t1.b < 110) or (t1.b >= 200 and t1.b < 210) ) and ( - (t2.b >= 100 and t2.b < 110) or - (t2.b >= 200 and t2.b < 210) + (t2.b >= 100 and t2.b < 110) or (t2.b >= 200 and t2.b < 210) ) and t1.c in ('0004', '0009') order by t1.a, @@ -5055,17 +3977,13 @@ from alpha as t1 inner join beta as t2 - on t1.a = t2.a and - t1.b = t2.b and - t1.c = t2.c + on t1.a = t2.a and t1.b = t2.b and t1.c = t2.c where ( - (t1.b >= 100 and t1.b < 110) or - (t1.b >= 200 and t1.b < 210) + (t1.b >= 100 and t1.b < 110) or (t1.b >= 200 and t1.b < 210) ) and ( - (t2.b >= 100 and t2.b < 110) or - (t2.b >= 200 and t2.b < 210) + (t2.b >= 100 and t2.b < 110) or (t2.b >= 200 and t2.b < 210) ) and t1.c in ('0004', '0009') order by t1.a, @@ -5078,17 +3996,13 @@ from alpha as t1 inner join beta as t2 - on t1.a = t2.a and - t1.b = t2.b and - t1.c = t2.c + on t1.a = t2.a and t1.b = t2.b and t1.c = t2.c where ( - (t1.b >= 100 and t1.b < 110) or - (t1.b >= 200 and t1.b < 210) + (t1.b >= 100 and t1.b < 110) or (t1.b >= 200 and t1.b < 210) ) and ( - (t2.b >= 100 and t2.b < 110) or - (t2.b >= 200 and t2.b < 210) + (t2.b >= 100 and t2.b < 110) or (t2.b >= 200 and t2.b < 210) ) and t1.c in ('0004', '0009') order by t1.a, @@ -5116,10 +4030,7 @@ select x.id, y.id from - fract_t as x - left outer join - fract_t as y - using ("id") + fract_t as x left outer join fract_t as y using (id) order by x.id asc limit 10; @@ -5127,10 +4038,7 @@ select x.id, y.id from - fract_t as x - left outer join - fract_t as y - using ("id") + fract_t as x left outer join fract_t as y using (id) order by x.id desc limit 10; @@ -5138,26 +4046,23 @@ select x.id, y.id from - fract_t as x - left outer join - fract_t as y - using ("id") + fract_t as x left outer join fract_t as y using (id) order by x.id desc limit 2; -create index "pht1_c_idx" on pht1 using btree (c); +create index pht1_c_idx on pht1 using btree (c); -select * from pht1 as p1 inner join pht1 as p2 using ("c") limit 1; +select * from pht1 as p1 inner join pht1 as p2 using (c) limit 1; -select * from pht1 as p1 inner join pht1 as p2 using ("c") limit 100; +select * from pht1 as p1 inner join pht1 as p2 using (c) limit 100; -select * from pht1 as p1 inner join pht1 as p2 using ("c") limit 1000; +select * from pht1 as p1 inner join pht1 as p2 using (c) limit 1000; set max_parallel_workers_per_gather = 1; set debug_parallel_query = 'on'; -select * from pht1 as p1 inner join pht1 as p2 using ("c") limit 100; +select * from pht1 as p1 inner join pht1 as p2 using (c) limit 100; reset debug_parallel_query; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_prune_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_prune_100.snap index 462c0ce70..5316ea204 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_prune_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_prune_100.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/partition_prune.sql create function explain_analyze(query text) returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin @@ -17,12 +17,12 @@ begin return next ln; end loop; end; -$function$; +$$; set plan_cache_mode = force_generic_plan; create table lp (a char(1)) -partition by LIST(a); +partition by list(a); create table lp_default partition of lp default; @@ -61,7 +61,7 @@ select * from lp where a <> 'a' and a <> 'd'; select * from lp where a not in ('a', 'd'); create table coll_pruning (a text collate "C") -partition by LIST(a); +partition by list(a); create table coll_pruning_a partition of coll_pruning for values in ('a'); @@ -79,7 +79,7 @@ create table rlp ( ) partition by range(a); -create table rlp_default partition of rlp default partition by LIST(a); +create table rlp_default partition of rlp default partition by list(a); create table rlp_default_default partition of rlp_default default; @@ -97,7 +97,7 @@ create table rlp3 ( b varchar, a int ) -partition by LIST(b varchar_ops); +partition by list(b varchar_ops); create table rlp3_default partition of rlp3 default; @@ -249,9 +249,7 @@ select from mc3p where - (a = 1 and abs(b) = 1 and c = 1) or - (a = 10 and abs(b) = 5 and c = 10) or - (a > 11 and a < 20); + (a = 1 and abs(b) = 1 and c = 1) or (a = 10 and abs(b) = 5 and c = 10) or (a > 11 and a < 20); select * @@ -318,8 +316,8 @@ select * from mc2p where a is null; select * from mc2p where b is null; -create table boolpart (a boolean) -partition by LIST(a); +create table boolpart (a bool) +partition by list(a); create table boolpart_default partition of boolpart default; @@ -389,8 +387,8 @@ select * from boolpart where a is false and a is unknown; select * from boolpart where a is true and a is unknown; -create table iboolpart (a boolean) -partition by LIST((not a)); +create table iboolpart (a bool) +partition by list((not a)); create table iboolpart_default partition of iboolpart default; @@ -445,43 +443,27 @@ select * from iboolpart where a is not true and a is not false; select * from iboolpart where a is not false; create table boolrangep ( - a boolean, - b boolean, + a bool, + b bool, c int ) partition by range(a, b, c); create table boolrangep_tf partition of boolrangep -for values from ('true', -'false', -0) to ('true', -'false', -100); +for values from ('true', 'false', 0) to ('true', 'false', 100); create table boolrangep_ft partition of boolrangep -for values from ('false', -'true', -0) to ('false', -'true', -100); +for values from ('false', 'true', 0) to ('false', 'true', 100); create table boolrangep_ff1 partition of boolrangep -for values from ('false', -'false', -0) to ('false', -'false', -50); +for values from ('false', 'false', 0) to ('false', 'false', 50); create table boolrangep_ff2 partition of boolrangep -for values from ('false', -'false', -50) to ('false', -'false', -100); +for values from ('false', 'false', 50) to ('false', 'false', 100); create table boolrangep_null partition of boolrangep default; @@ -492,7 +474,7 @@ select * from boolrangep where a is not true and not b and c = 25; select * from boolrangep where a is not false and not b and c = 25; create table coercepart (a varchar) -partition by LIST(a); +partition by list(a); create table coercepart_ab partition of coercepart for values in ('ab'); @@ -530,7 +512,7 @@ create table part ( a int, b int ) -partition by LIST(a); +partition by list(a); create table part_p1 partition of part for values in (-2, -1, 0, 1, 2); @@ -565,15 +547,7 @@ select * from mc2p as t1, - lateral ( - select - COUNT(*) - from - mc3p as t2 - where - t2.a = t1.b and abs(t2.b) = 1 and t2.c = 1 - ) - as s + lateral (select count(*) from mc3p as t2 where t2.a = t1.b and abs(t2.b) = 1 and t2.c = 1) as s where t1.a = 1; @@ -581,15 +555,7 @@ select * from mc2p as t1, - lateral ( - select - COUNT(*) - from - mc3p as t2 - where - t2.c = t1.b and abs(t2.b) = 1 and t2.a = 1 - ) - as s + lateral (select count(*) from mc3p as t2 where t2.c = t1.b and abs(t2.b) = 1 and t2.a = 1) as s where t1.a = 1; @@ -597,15 +563,7 @@ select * from mc2p as t1, - lateral ( - select - COUNT(*) - from - mc3p as t2 - where - t2.a = 1 and abs(t2.b) = 1 and t2.c = 1 - ) - as s + lateral (select count(*) from mc3p as t2 where t2.a = 1 and abs(t2.b) = 1 and t2.c = 1) as s where t1.a = 1; @@ -631,8 +589,7 @@ select * from lp where (a <> 'a' and a <> 'd') or a is null; select * from rlp where a = 15 and b <> 'ab' and b <> 'cd' and b <> 'xy' and b is not null; create table coll_pruning_multi (a text) -partition by range((substr(a, 1)) collate "POSIX", -(substr(a, 1)) collate "C"); +partition by range((substr(a, 1)) collate "POSIX", (substr(a, 1)) collate "C"); create table coll_pruning_multi1 partition of coll_pruning_multi @@ -655,11 +612,10 @@ select from coll_pruning_multi where - substr(a, 1) = 'e' collate "C" and - substr(a, 1) = 'a' collate "POSIX"; + substr(a, 1) = 'e' collate "C" and substr(a, 1) = 'a' collate "POSIX"; create table like_op_noprune (a text) -partition by LIST(a); +partition by list(a); create table like_op_noprune1 partition of like_op_noprune for values in ('ABC'); @@ -668,7 +624,7 @@ create table like_op_noprune2 partition of like_op_noprune for values in ('BCD') select * from like_op_noprune where a like '%BC'; create table lparted_by_int2 (a smallint) -partition by LIST(a); +partition by list(a); create table lparted_by_int2_1 partition of lparted_by_int2 for values in (1); @@ -718,16 +674,7 @@ select from ( select - exists - ( - select - 1 - from - int4_tbl as tinner - where - f1 = touter.f1 - ) - as b + exists (select 1 from int4_tbl as tinner where f1 = touter.f1) as b from int4_tbl as touter ) @@ -743,16 +690,15 @@ create table hp ( b text, c int ) -partition by HASH(a part_test_int4_ops, -b part_test_text_ops); +partition by hash(a part_test_int4_ops, b part_test_text_ops); -create table hp0 partition of hp for values with (MODULUS 4, REMAINDER 0); +create table hp0 partition of hp for values with (modulus 4, remainder 0); -create table hp3 partition of hp for values with (MODULUS 4, REMAINDER 3); +create table hp3 partition of hp for values with (modulus 4, remainder 3); -create table hp1 partition of hp for values with (MODULUS 4, REMAINDER 1); +create table hp1 partition of hp for values with (modulus 4, remainder 1); -create table hp2 partition of hp for values with (MODULUS 4, REMAINDER 2); +create table hp2 partition of hp for values with (modulus 4, remainder 2); insert into hp values (null, null, 0); @@ -799,9 +745,7 @@ select from hp where - (a = 1 and b = 'abcde') or - (a = 2 and b = 'xxx') or - (a is null and b is null); + (a = 1 and b = 'abcde') or (a = 2 and b = 'xxx') or (a is null and b is null); drop table hp1; @@ -819,9 +763,9 @@ create table ab ( a int not null, b int not null ) -partition by LIST(a); +partition by list(a); -create table ab_a2 partition of ab for values in (2) partition by LIST(b); +create table ab_a2 partition of ab for values in (2) partition by list(b); create table ab_a2_b1 partition of ab_a2 for values in (1); @@ -829,7 +773,7 @@ create table ab_a2_b2 partition of ab_a2 for values in (2); create table ab_a2_b3 partition of ab_a2 for values in (3); -create table ab_a1 partition of ab for values in (1) partition by LIST(b); +create table ab_a1 partition of ab for values in (1) partition by list(b); create table ab_a1_b1 partition of ab_a1 for values in (1); @@ -837,7 +781,7 @@ create table ab_a1_b2 partition of ab_a1 for values in (2); create table ab_a1_b3 partition of ab_a1 for values in (3); -create table ab_a3 partition of ab for values in (3) partition by LIST(b); +create table ab_a3 partition of ab for values in (3) partition by list(b); create table ab_a3_b1 partition of ab_a3 for values in (1); @@ -849,42 +793,42 @@ set enable_indexonlyscan = off; prepare ab_q1 (int, int, int) as select * from ab where a between $1 and $2 and b <= $3;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ab_q1 (2, 2, 3); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q1 (2, 2, 3); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ab_q1 (1, 2, 3); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q1 (1, 2, 3); deallocate ab_q1; prepare ab_q1 (int, int) as select a from ab where a between $1 and $2 and b < 3;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ab_q1 (2, 2); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q1 (2, 2); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ab_q1 (2, 4); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q1 (2, 4); prepare ab_q2 (int, int) as select a from ab where a between $1 and $2 and b < (select 3);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ab_q2 (2, 2); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q2 (2, 2); prepare ab_q3 (int, int) as select a from ab where b between $1 and $2 and a < (select 3);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ab_q3 (2, 2); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q3 (2, 2); -create table hp1 partition of hp for values with (MODULUS 4, REMAINDER 1); +create table hp1 partition of hp for values with (modulus 4, remainder 1); -create table hp2 partition of hp for values with (MODULUS 4, REMAINDER 2); +create table hp2 partition of hp for values with (modulus 4, remainder 2); -create table hp3 partition of hp for values with (MODULUS 4, REMAINDER 3); +create table hp3 partition of hp for values with (modulus 4, remainder 3); prepare hp_q1 (text) as select * from hp where a is null and b = $1;; -explain (COSTS 'off') execute hp_q1 ('xxx'); +explain (costs 'off') execute hp_q1 ('xxx'); deallocate hp_q1; drop table hp; create table list_part (a int) -partition by LIST(a); +partition by list(a); create table list_part1 partition of list_part for values in (1); @@ -898,7 +842,7 @@ insert into list_part select generate_series(1, 4); begin; -declare "cur" scroll cursor for select 1 from list_part where a > (select 1) and a < (select 4);; +declare cur scroll cursor for select 1 from list_part where a > (select 1) and a < (select 4);; move forward 3 from cur; @@ -912,9 +856,7 @@ create function list_part_fn(int) returns int language plpgsql stable -as $function$ -begin return $1; end; -$function$; +as $$ begin return $1; end;$$; select * from list_part where a = list_part_fn(1); @@ -929,7 +871,7 @@ drop table list_part; create function explain_parallel_append(text) returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin @@ -947,9 +889,9 @@ begin return next ln; end loop; end; -$function$; +$$; -prepare ab_q4 (int, int) as select AVG(a) from ab where a between $1 and $2 and b < 4;; +prepare ab_q4 (int, int) as select avg(a) from ab where a between $1 and $2 and b < 4;; set parallel_setup_cost = 0; @@ -961,7 +903,7 @@ set max_parallel_workers_per_gather = 2; select explain_parallel_append('execute ab_q4 (2, 2)'); -prepare ab_q5 (int, int, int) as select AVG(a) from ab where a in ($1, $2, $3) and b < 4;; +prepare ab_q5 (int, int, int) as select avg(a) from ab where a in ($1, $2, $3) and b < 4;; select explain_parallel_append('execute ab_q5 (1, 1, 1)'); @@ -982,23 +924,23 @@ insert into lprt_a values (1), (1); analyze lprt_a; -create index "ab_a2_b1_a_idx" on ab_a2_b1 using btree (a); +create index ab_a2_b1_a_idx on ab_a2_b1 using btree (a); -create index "ab_a2_b2_a_idx" on ab_a2_b2 using btree (a); +create index ab_a2_b2_a_idx on ab_a2_b2 using btree (a); -create index "ab_a2_b3_a_idx" on ab_a2_b3 using btree (a); +create index ab_a2_b3_a_idx on ab_a2_b3 using btree (a); -create index "ab_a1_b1_a_idx" on ab_a1_b1 using btree (a); +create index ab_a1_b1_a_idx on ab_a1_b1 using btree (a); -create index "ab_a1_b2_a_idx" on ab_a1_b2 using btree (a); +create index ab_a1_b2_a_idx on ab_a1_b2 using btree (a); -create index "ab_a1_b3_a_idx" on ab_a1_b3 using btree (a); +create index ab_a1_b3_a_idx on ab_a1_b3 using btree (a); -create index "ab_a3_b1_a_idx" on ab_a3_b1 using btree (a); +create index ab_a3_b1_a_idx on ab_a3_b1 using btree (a); -create index "ab_a3_b2_a_idx" on ab_a3_b2 using btree (a); +create index ab_a3_b2_a_idx on ab_a3_b2 using btree (a); -create index "ab_a3_b3_a_idx" on ab_a3_b3 using btree (a); +create index ab_a3_b3_a_idx on ab_a3_b3 using btree (a); set enable_hashjoin = 0; @@ -1049,21 +991,14 @@ reset min_parallel_table_scan_size; reset max_parallel_workers_per_gather; -select * from ab where a = (select MAX(a) from lprt_a) and b = (select MAX(a) - 1 from lprt_a); +select * from ab where a = (select max(a) from lprt_a) and b = (select max(a) - 1 from lprt_a); select * from (select * from ab where a = 1 union all select * from ab) as ab where b = (select 1); select * from - ( - select * from ab where a = 1 - union all - values (10, 5) - union all - select * from ab - ) - as ab + (select * from ab where a = 1 union all values (10, 5) union all select * from ab) as ab where b = (select 1); @@ -1093,7 +1028,7 @@ from where a = $1 and b = (select -10);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ab_q6 (1); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q6 (1); execute ab_q6 (100); @@ -1150,17 +1085,17 @@ create table tprt_5 partition of tprt for values from (3001) to (4001); create table tprt_6 partition of tprt for values from (4001) to (5001); -create index "tprt1_idx" on tprt_1 using btree (col1); +create index tprt1_idx on tprt_1 using btree (col1); -create index "tprt2_idx" on tprt_2 using btree (col1); +create index tprt2_idx on tprt_2 using btree (col1); -create index "tprt3_idx" on tprt_3 using btree (col1); +create index tprt3_idx on tprt_3 using btree (col1); -create index "tprt4_idx" on tprt_4 using btree (col1); +create index tprt4_idx on tprt_4 using btree (col1); -create index "tprt5_idx" on tprt_5 using btree (col1); +create index tprt5_idx on tprt_5 using btree (col1); -create index "tprt6_idx" on tprt_6 using btree (col1); +create index tprt6_idx on tprt_6 using btree (col1); insert into tprt values (10), (20), (501), (502), (505), (1001), (4500); @@ -1245,21 +1180,21 @@ create table part_abc ( b int not null, c int not null ) -partition by LIST(a); +partition by list(a); create table part_bac ( b int not null, a int not null, c int not null ) -partition by LIST(b); +partition by list(b); create table part_cab ( c int not null, a int not null, b int not null ) -partition by LIST(c); +partition by list(c); create table part_abc_p1 ( a int not null, @@ -1281,7 +1216,7 @@ alter table part_cab prepare part_abc_q1 (int, int, int) as select * from part_abc where a = $1 and b = $2 and c = $3;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute part_abc_q1 (1, 2, 3); deallocate part_abc_q1; @@ -1292,13 +1227,13 @@ create table listp ( a int, b int ) -partition by LIST(a); +partition by list(a); -create table listp_1 partition of listp for values in (1) partition by LIST(b); +create table listp_1 partition of listp for values in (1) partition by list(b); create table listp_1_1 partition of listp_1 for values in (1); -create table listp_2 partition of listp for values in (2) partition by LIST(b); +create table listp_2 partition of listp for values in (2) partition by list(b); create table listp_2_1 partition of listp_2 for values in (2); @@ -1306,19 +1241,19 @@ select * from listp where b = 1; prepare q1 (int, int) as select * from listp where b in ($1, $2);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute q1 (1, 1); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (1, 1); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute q1 (2, 2); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (2, 2); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute q1 (0, 0); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (0, 0); deallocate q1; prepare q1 (int, int, int, int) as select * from listp where b in ($1, $2) and $3 <> b and $4 <> b;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute q1 (1, 2, 2, 0); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (1, 2, 2, 0); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute q1 (1, 2, 2, 1); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (1, 2, 2, 1); select * from listp where a = (select cast(null as int)); @@ -1341,49 +1276,44 @@ for values from ('3000-02-01') to ('3000-03-01'); select * from stable_qual_pruning where a < localtimestamp; -select * from stable_qual_pruning where a < cast('2000-02-01' as timestamp with time zone); +select * from stable_qual_pruning where a < cast('2000-02-01' as timestamptz); select * from stable_qual_pruning where - a = any (cast(array['2010-02-01', '2020-01-01'] - as timestamp[])); + a = any (cast(array['2010-02-01', '2020-01-01'] as timestamp[])); select * from stable_qual_pruning where - a = any (cast(array['2000-02-01', '2010-01-01'] - as timestamp[])); + a = any (cast(array['2000-02-01', '2010-01-01'] as timestamp[])); select * from stable_qual_pruning where - a = any (cast(array['2000-02-01', localtimestamp] - as timestamp[])); + a = any (cast(array['2000-02-01', localtimestamp] as timestamp[])); select * from stable_qual_pruning where - a = any (cast(array['2010-02-01', '2020-01-01'] - as timestamp with time zone[])); + a = any (cast(array['2010-02-01', '2020-01-01'] as timestamptz[])); select * from stable_qual_pruning where - a = any (cast(array['2000-02-01', '2010-01-01'] - as timestamp with time zone[])); + a = any (cast(array['2000-02-01', '2010-01-01'] as timestamptz[])); -select * from stable_qual_pruning where a = any (cast(null as timestamp with time zone[])); +select * from stable_qual_pruning where a = any (cast(null as timestamptz[])); drop table stable_qual_pruning; @@ -1400,11 +1330,7 @@ create table mc3p1 partition of mc3p for values from (1, 1, 1) to (2, minvalue, create table mc3p2 partition of mc3p -for values from (2, -minvalue, -minvalue) to (3, -maxvalue, -maxvalue); +for values from (2, minvalue, minvalue) to (3, maxvalue, maxvalue); insert into mc3p values (0, 1, 1), (1, 1, 1), (2, 1, 1); @@ -1412,24 +1338,24 @@ select * from mc3p where a < 3 and abs(b) = 1; prepare ps1 as select * from mc3p where a = $1 and abs(b) < (select 3);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ps1 (1); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ps1 (1); deallocate ps1; prepare ps2 as select * from mc3p where a <= $1 and abs(b) < (select 3);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute ps2 (1); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ps2 (1); deallocate ps2; drop table mc3p; -create table boolvalues (value boolean not null); +create table boolvalues (value bool not null); insert into boolvalues values ('t'), ('f'); -create table boolp (a boolean) -partition by LIST(a); +create table boolp (a bool) +partition by list(a); create table boolp_t partition of boolp for values in ('t'); @@ -1465,15 +1391,15 @@ analyze ma_test; prepare mt_q1 (int) as select a from ma_test where a >= $1 and a % 10 = 5 order by b;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute mt_q1 (15); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute mt_q1 (15); execute mt_q1 (15); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute mt_q1 (25); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute mt_q1 (25); execute mt_q1 (25); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') execute mt_q1 (35); +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute mt_q1 (35); execute mt_q1 (35); @@ -1481,12 +1407,12 @@ deallocate mt_q1; prepare mt_q2 (int) as select * from ma_test where a >= $1 order by b limit 1;; -explain (ANALYZE, VERBOSE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, verbose, costs 'off', summary 'off', timing 'off', buffers 'off') execute mt_q2 (35); deallocate mt_q2; -select * from ma_test where a >= (select MIN(b) from ma_test_p2) order by b; +select * from ma_test where a >= (select min(b) from ma_test_p2) order by b; reset enable_seqscan; @@ -1497,7 +1423,7 @@ drop table ma_test; reset enable_indexonlyscan; create table pp_arrpart (a int[]) -partition by LIST(a); +partition by list(a); create table pp_arrpart1 partition of pp_arrpart for values in ('{1}'); @@ -1516,11 +1442,11 @@ delete from pp_arrpart where a = '{1}'; drop table pp_arrpart; create table pph_arrpart (a int[]) -partition by HASH(a); +partition by hash(a); -create table pph_arrpart1 partition of pph_arrpart for values with (MODULUS 2, REMAINDER 0); +create table pph_arrpart1 partition of pph_arrpart for values with (modulus 2, remainder 0); -create table pph_arrpart2 partition of pph_arrpart for values with (MODULUS 2, REMAINDER 1); +create table pph_arrpart2 partition of pph_arrpart for values with (modulus 2, remainder 1); insert into pph_arrpart values ('{1}'), ('{1, 2}'), ('{4, 5}'); @@ -1537,7 +1463,7 @@ drop table pph_arrpart; create type pp_colors as enum ('green', 'blue', 'black'); create table pp_enumpart (a pp_colors) -partition by LIST(a); +partition by list(a); create table pp_enumpart_green partition of pp_enumpart for values in ('green'); @@ -1554,7 +1480,7 @@ drop type pp_colors; create type pp_rectype as (a int, b int); create table pp_recpart (a pp_rectype) -partition by LIST(a); +partition by list(a); create table pp_recpart_11 partition of pp_recpart for values in ('(1,1)'); @@ -1569,7 +1495,7 @@ drop table pp_recpart; drop type pp_rectype; create table pp_intrangepart (a int4range) -partition by LIST(a); +partition by list(a); create table pp_intrangepart12 partition of pp_intrangepart for values in ('[1,2]'); @@ -1585,7 +1511,7 @@ create table pp_lp ( a int, value int ) -partition by LIST(a); +partition by list(a); create table pp_lp1 partition of pp_lp for values in (1); @@ -1653,7 +1579,7 @@ reset enable_partition_pruning; reset constraint_exclusion; create temporary table pp_temp_parent (a int) -partition by LIST(a); +partition by list(a); create temporary table pp_temp_part_1 partition of pp_temp_parent for values in (1); @@ -1670,7 +1596,7 @@ create temporary table p ( b int, c int ) -partition by LIST(a); +partition by list(a); create temporary table p1 partition of p for values in (1); @@ -1681,15 +1607,15 @@ create temporary table q ( b int, c int ) -partition by LIST(a); +partition by list(a); -create temporary table q1 partition of q for values in (1) partition by LIST(b); +create temporary table q1 partition of q for values in (1) partition by list(b); -create temporary table q11 partition of q1 for values in (1) partition by LIST(c); +create temporary table q11 partition of q1 for values in (1) partition by list(c); create temporary table q111 partition of q11 for values in (1); -create temporary table q2 partition of q for values in (2) partition by LIST(b); +create temporary table q2 partition of q for values in (2) partition by list(b); create temporary table q21 partition of q2 for values in (1); @@ -1700,43 +1626,27 @@ insert into q22 values (2, 2, 3); select * from - ( - select * from p union all select * from q1 - union all - select 1, 1, 1 - ) - as s (a, b, c) + (select * from p union all select * from q1 union all select 1, 1, 1) as s (a, b, c) where s.a = 1 and s.b = 1 and s.c = (select 1); select * from - ( - select * from p union all select * from q1 - union all - select 1, 1, 1 - ) - as s (a, b, c) + (select * from p union all select * from q1 union all select 1, 1, 1) as s (a, b, c) where s.a = 1 and s.b = 1 and s.c = (select 1); prepare q -(int, -int) +(int, int) as select * from - ( - select * from p union all select * from q1 - union all - select 1, 1, 1 - ) - as s (a, b, c) + (select * from p union all select * from q1 union all select 1, 1, 1) as s (a, b, c) where s.a = $1 and s.b = $2 and s.c = (select 1);; -explain (COSTS 'off') execute q (1, 1); +explain (costs 'off') execute q (1, 1); execute q (1, 1); @@ -1746,11 +1656,11 @@ create table listp ( a int, b int ) -partition by LIST(a); +partition by list(a); create table listp1 partition of listp for values in (1); -create table listp2 partition of listp for values in (2) partition by LIST(b); +create table listp2 partition of listp for values in (2) partition by list(b); create table listp2_10 partition of listp2 for values in (10); @@ -1781,9 +1691,9 @@ set parallel_setup_cost = 0; set parallel_tuple_cost = 0; create table listp (a int) -partition by LIST(a); +partition by list(a); -create table listp_12 partition of listp for values in (1, 2) partition by LIST(a); +create table listp_12 partition of listp for values in (1, 2) partition by list(a); create table listp_12_1 partition of listp_12 for values in (1); @@ -1794,12 +1704,9 @@ alter table listp_12_1 select explain_parallel_append('select * from listp where a = (select 1);'); -select - explain_parallel_append( - 'select * from listp where a = (select 1) +select explain_parallel_append('select * from listp where a = (select 1) union all -select * from listp where a = (select 2);' - ); +select * from listp where a = (select 2);'); drop table listp; @@ -1815,7 +1722,7 @@ create table rangep ( ) partition by range(a); -create table rangep_0_to_100 partition of rangep for values from (0) to (100) partition by LIST(b); +create table rangep_0_to_100 partition of rangep for values from (0) to (100) partition by list(b); create table rangep_0_to_100_1 partition of rangep_0_to_100 for values in (1); @@ -1894,10 +1801,12 @@ create table hp_prefix_test ( c int, d int ) -partition by HASH(a part_test_int4_ops, -b part_test_int4_ops, -c part_test_int4_ops, -d part_test_int4_ops); +partition by hash( + a part_test_int4_ops, + b part_test_int4_ops, + c part_test_int4_ops, + d part_test_int4_ops +); select 'create table hp_prefix_test_p' || cast(x as text) || @@ -1923,17 +1832,11 @@ select 'explain (costs off) select tableoid::regclass,* from hp_prefix_test where ' || string_agg( c.colname || - case - when g.s & (1 << c.colpos) = 0 then ' is null' - else ' = ' || cast(colpos + 1 as text) - end, + case when g.s & (1 << c.colpos) = 0 then ' is null' else ' = ' || cast(colpos + 1 as text) end, ' and ' order by c.colpos ) from - ( - values ('a', 0), ('b', 1), ('c', 2), ('d', 3) - ) - as c (colname, colpos), + (values ('a', 0), ('b', 1), ('c', 2), ('d', 3)) as c (colname, colpos), generate_series(0, 15) as g (s) group by g.s order by g.s; @@ -1942,45 +1845,38 @@ select 'select tableoid::regclass,* from hp_prefix_test where ' || string_agg( c.colname || - case - when g.s & (1 << c.colpos) = 0 then ' is null' - else ' = ' || cast(colpos + 1 as text) - end, + case when g.s & (1 << c.colpos) = 0 then ' is null' else ' = ' || cast(colpos + 1 as text) end, ' and ' order by c.colpos ) from - ( - values ('a', 0), ('b', 1), ('c', 2), ('d', 3) - ) - as c (colname, colpos), + (values ('a', 0), ('b', 1), ('c', 2), ('d', 3)) as c (colname, colpos), generate_series(0, 15) as g (s) group by g.s order by g.s; drop table hp_prefix_test; -create operator === (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4eq, COMMUTATOR = ===, HASHES); +create operator === (leftarg = int4, rightarg = int4, procedure = int4eq, commutator = ===, hashes); create operator class part_test_int4_ops2 - for type int + for type int4 using hash as operator 1 ===, - function 2 part_hashint4_noop(int, bigint); + function 2 part_hashint4_noop(int4, int8); create table hp_contradict_test ( a int, b int ) -partition by HASH(a part_test_int4_ops2, -b part_test_int4_ops2); +partition by hash(a part_test_int4_ops2, b part_test_int4_ops2); create table hp_contradict_test_p1 partition of hp_contradict_test -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table hp_contradict_test_p2 partition of hp_contradict_test -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); select * from hp_contradict_test where a is null and a === 1 and b === 1; @@ -1990,26 +1886,26 @@ drop table hp_contradict_test; drop operator class part_test_int4_ops2 using hash; -drop operator === (int, int); +drop operator === (int4, int4); drop function explain_analyze(text); create table part_abc ( a int, b text, - c boolean + c bool ) -partition by LIST(a); +partition by list(a); create table part_abc_1 ( b text, a int, - c boolean + c bool ); create table part_abc_2 ( a int, - c boolean, + c bool, b text ); @@ -2031,15 +1927,15 @@ with cascaded check option; update part_abc_view set b = $2 where a = $1 returning *; -explain (VERBOSE, COSTS 'off') execute update_part_abc_view (1, 'd'); +explain (verbose, costs 'off') execute update_part_abc_view (1, 'd'); execute update_part_abc_view (1, 'd'); -explain (VERBOSE, COSTS 'off') execute update_part_abc_view (2, 'a'); +explain (verbose, costs 'off') execute update_part_abc_view (2, 'a'); execute update_part_abc_view (2, 'a'); -explain (VERBOSE, COSTS 'off') execute update_part_abc_view (3, 'a'); +explain (verbose, costs 'off') execute update_part_abc_view (3, 'a'); execute update_part_abc_view (3, 'a'); @@ -2049,9 +1945,7 @@ create function stable_one() returns int language plpgsql stable -as $function$ -begin return 1; end; -$function$; +as $$ begin return 1; end; $$; select * from part_abc_view; @@ -2069,21 +1963,16 @@ create table part_abc_log ( action text, a int, b text, - c boolean + c bool ); with t as ( merge into part_abc_view as pt - using (select stable_one() + 1 as pid) as q - inner join - part_abc_2 as pt2 - on q.pid = pt2.a + using (select stable_one() + 1 as pid) as q inner join part_abc_2 as pt2 on q.pid = pt2.a on pt.a = stable_one() + 2 - when not matched by target - then insert - values (1, 'd', false) + when not matched by target then insert values (1, 'd', false) returning "mergesupport#25", pt.* ) @@ -2095,14 +1984,9 @@ with t as ( merge into part_abc_view as pt - using (select stable_one() + 1 as pid) as q - inner join - part_abc_2 as pt2 - on q.pid = pt2.a + using (select stable_one() + 1 as pid) as q inner join part_abc_2 as pt2 on q.pid = pt2.a on pt.a = stable_one() + 2 - when not matched by target - then insert - values (1, 'd', false) + when not matched by target then insert values (1, 'd', false) returning "mergesupport#25", pt.* ) @@ -2130,14 +2014,14 @@ create table part_abc_3_2 partition of part_abc_3 for values from (1) to (100); create table part_abc_3_3 partition of part_abc_3 for values from (100) to (maxvalue); select - MIN(a) over (partition by a order by a) + min(a) over (partition by a order by a) from part_abc where a >= stable_one() + 1 and d <= stable_one() union all select - MIN(a) over (partition by a order by a) + min(a) over (partition by a order by a) from part_abc where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_prune_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_prune_80.snap index a5d0e86a0..8495d8189 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_prune_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__partition_prune_80.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/partition_prune.sql create function explain_analyze(query text) returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin @@ -17,12 +17,12 @@ begin return next ln; end loop; end; -$function$; +$$; set plan_cache_mode = force_generic_plan; create table lp (a char(1)) -partition by LIST(a); +partition by list(a); create table lp_default partition of lp default; @@ -61,7 +61,7 @@ select * from lp where a <> 'a' and a <> 'd'; select * from lp where a not in ('a', 'd'); create table coll_pruning (a text collate "C") -partition by LIST(a); +partition by list(a); create table coll_pruning_a partition of coll_pruning for values in ('a'); @@ -79,7 +79,7 @@ create table rlp ( ) partition by range(a); -create table rlp_default partition of rlp default partition by LIST(a); +create table rlp_default partition of rlp default partition by list(a); create table rlp_default_default partition of rlp_default default; @@ -97,7 +97,7 @@ create table rlp3 ( b varchar, a int ) -partition by LIST(b varchar_ops); +partition by list(b varchar_ops); create table rlp3_default partition of rlp3 default; @@ -210,55 +210,31 @@ create table mc3p_default partition of mc3p default; create table mc3p0 partition of mc3p -for values from (minvalue, -minvalue, -minvalue) to (1, -1, -1); +for values from (minvalue, minvalue, minvalue) to (1, 1, 1); create table mc3p1 partition of mc3p for values from (1, 1, 1) to (10, 5, 10); create table mc3p2 partition of mc3p -for values from (10, -5, -10) to (10, -10, -10); +for values from (10, 5, 10) to (10, 10, 10); create table mc3p3 partition of mc3p -for values from (10, -10, -10) to (10, -10, -20); +for values from (10, 10, 10) to (10, 10, 20); create table mc3p4 partition of mc3p -for values from (10, -10, -20) to (10, -maxvalue, -maxvalue); +for values from (10, 10, 20) to (10, maxvalue, maxvalue); create table mc3p5 partition of mc3p for values from (11, 1, 1) to (20, 10, 10); create table mc3p6 partition of mc3p -for values from (20, -10, -10) to (20, -20, -20); +for values from (20, 10, 10) to (20, 20, 20); create table mc3p7 partition of mc3p -for values from (20, -20, -20) to (maxvalue, -maxvalue, -maxvalue); +for values from (20, 20, 20) to (maxvalue, maxvalue, maxvalue); select * from mc3p where a = 1; @@ -332,9 +308,7 @@ create table mc2p_default partition of mc2p default; create table mc2p0 partition of mc2p -for values from (minvalue, -minvalue) to (1, -minvalue); +for values from (minvalue, minvalue) to (1, minvalue); create table mc2p1 partition of mc2p for values from (1, minvalue) to (1, 1); @@ -346,9 +320,7 @@ create table mc2p4 partition of mc2p for values from (2, 1) to (2, maxvalue); create table mc2p5 partition of mc2p -for values from (2, -maxvalue) to (maxvalue, -maxvalue); +for values from (2, maxvalue) to (maxvalue, maxvalue); select * from mc2p where a < 2; @@ -368,8 +340,8 @@ select * from mc2p where a is null; select * from mc2p where b is null; -create table boolpart (a boolean) -partition by LIST(a); +create table boolpart (a bool) +partition by list(a); create table boolpart_default partition of boolpart default; @@ -439,8 +411,8 @@ select * from boolpart where a is false and a is unknown; select * from boolpart where a is true and a is unknown; -create table iboolpart (a boolean) -partition by LIST((not a)); +create table iboolpart (a bool) +partition by list((not a)); create table iboolpart_default partition of iboolpart default; @@ -495,43 +467,27 @@ select * from iboolpart where a is not true and a is not false; select * from iboolpart where a is not false; create table boolrangep ( - a boolean, - b boolean, + a bool, + b bool, c int ) partition by range(a, b, c); create table boolrangep_tf partition of boolrangep -for values from ('true', -'false', -0) to ('true', -'false', -100); +for values from ('true', 'false', 0) to ('true', 'false', 100); create table boolrangep_ft partition of boolrangep -for values from ('false', -'true', -0) to ('false', -'true', -100); +for values from ('false', 'true', 0) to ('false', 'true', 100); create table boolrangep_ff1 partition of boolrangep -for values from ('false', -'false', -0) to ('false', -'false', -50); +for values from ('false', 'false', 0) to ('false', 'false', 50); create table boolrangep_ff2 partition of boolrangep -for values from ('false', -'false', -50) to ('false', -'false', -100); +for values from ('false', 'false', 50) to ('false', 'false', 100); create table boolrangep_null partition of boolrangep default; @@ -542,7 +498,7 @@ select * from boolrangep where a is not true and not b and c = 25; select * from boolrangep where a is not false and not b and c = 25; create table coercepart (a varchar) -partition by LIST(a); +partition by list(a); create table coercepart_ab partition of coercepart for values in ('ab'); @@ -580,7 +536,7 @@ create table part ( a int, b int ) -partition by LIST(a); +partition by list(a); create table part_p1 partition of part for values in (-2, -1, 0, 1, 2); @@ -627,13 +583,11 @@ from mc2p as t1, lateral ( select - COUNT(*) + count(*) from mc3p as t2 where - t2.a = t1.b and - abs(t2.b) = 1 and - t2.c = 1 + t2.a = t1.b and abs(t2.b) = 1 and t2.c = 1 ) as s where @@ -645,13 +599,11 @@ from mc2p as t1, lateral ( select - COUNT(*) + count(*) from mc3p as t2 where - t2.c = t1.b and - abs(t2.b) = 1 and - t2.a = 1 + t2.c = t1.b and abs(t2.b) = 1 and t2.a = 1 ) as s where @@ -663,7 +615,7 @@ from mc2p as t1, lateral ( select - COUNT(*) + count(*) from mc3p as t2 where @@ -697,15 +649,10 @@ select from rlp where - a = 15 and - b <> 'ab' and - b <> 'cd' and - b <> 'xy' and - b is not null; + a = 15 and b <> 'ab' and b <> 'cd' and b <> 'xy' and b is not null; create table coll_pruning_multi (a text) -partition by range((substr(a, 1)) collate "POSIX", -(substr(a, 1)) collate "C"); +partition by range((substr(a, 1)) collate "POSIX", (substr(a, 1)) collate "C"); create table coll_pruning_multi1 partition of coll_pruning_multi @@ -728,11 +675,10 @@ select from coll_pruning_multi where - substr(a, 1) = 'e' collate "C" and - substr(a, 1) = 'a' collate "POSIX"; + substr(a, 1) = 'e' collate "C" and substr(a, 1) = 'a' collate "POSIX"; create table like_op_noprune (a text) -partition by LIST(a); +partition by list(a); create table like_op_noprune1 partition of like_op_noprune @@ -745,7 +691,7 @@ for values in ('BCD'); select * from like_op_noprune where a like '%BC'; create table lparted_by_int2 (a smallint) -partition by LIST(a); +partition by list(a); create table lparted_by_int2_1 partition of lparted_by_int2 for values in (1); @@ -801,16 +747,7 @@ select from ( select - exists - ( - select - 1 - from - int4_tbl as tinner - where - f1 = touter.f1 - ) - as b + exists (select 1 from int4_tbl as tinner where f1 = touter.f1) as b from int4_tbl as touter ) @@ -826,16 +763,15 @@ create table hp ( b text, c int ) -partition by HASH(a part_test_int4_ops, -b part_test_text_ops); +partition by hash(a part_test_int4_ops, b part_test_text_ops); -create table hp0 partition of hp for values with (MODULUS 4, REMAINDER 0); +create table hp0 partition of hp for values with (modulus 4, remainder 0); -create table hp3 partition of hp for values with (MODULUS 4, REMAINDER 3); +create table hp3 partition of hp for values with (modulus 4, remainder 3); -create table hp1 partition of hp for values with (MODULUS 4, REMAINDER 1); +create table hp1 partition of hp for values with (modulus 4, remainder 1); -create table hp2 partition of hp for values with (MODULUS 4, REMAINDER 2); +create table hp2 partition of hp for values with (modulus 4, remainder 2); insert into hp values (null, null, 0); @@ -882,9 +818,7 @@ select from hp where - (a = 1 and b = 'abcde') or - (a = 2 and b = 'xxx') or - (a is null and b is null); + (a = 1 and b = 'abcde') or (a = 2 and b = 'xxx') or (a is null and b is null); drop table hp1; @@ -902,9 +836,9 @@ create table ab ( a int not null, b int not null ) -partition by LIST(a); +partition by list(a); -create table ab_a2 partition of ab for values in (2) partition by LIST(b); +create table ab_a2 partition of ab for values in (2) partition by list(b); create table ab_a2_b1 partition of ab_a2 for values in (1); @@ -912,7 +846,7 @@ create table ab_a2_b2 partition of ab_a2 for values in (2); create table ab_a2_b3 partition of ab_a2 for values in (3); -create table ab_a1 partition of ab for values in (1) partition by LIST(b); +create table ab_a1 partition of ab for values in (1) partition by list(b); create table ab_a1_b1 partition of ab_a1 for values in (1); @@ -920,7 +854,7 @@ create table ab_a1_b2 partition of ab_a1 for values in (2); create table ab_a1_b3 partition of ab_a1 for values in (3); -create table ab_a3 partition of ab for values in (3) partition by LIST(b); +create table ab_a3 partition of ab for values in (3) partition by list(b); create table ab_a3_b1 partition of ab_a3 for values in (1); @@ -931,82 +865,57 @@ create table ab_a3_b3 partition of ab_a3 for values in (3); set enable_indexonlyscan = off; prepare ab_q1 -(int, -int, -int) -as select - * -from - ab -where - a between $1 and $2 and b <= $3;; +(int, int, int) +as select * from ab where a between $1 and $2 and b <= $3;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q1 (2, 2, 3); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q1 (1, 2, 3); deallocate ab_q1; prepare ab_q1 -(int, -int) -as select - a -from - ab -where - a between $1 and $2 and b < 3;; +(int, int) +as select a from ab where a between $1 and $2 and b < 3;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q1 (2, 2); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q1 (2, 4); prepare ab_q2 -(int, -int) -as select - a -from - ab -where - a between $1 and $2 and b < (select 3);; +(int, int) +as select a from ab where a between $1 and $2 and b < (select 3);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q2 (2, 2); prepare ab_q3 -(int, -int) -as select - a -from - ab -where - b between $1 and $2 and a < (select 3);; +(int, int) +as select a from ab where b between $1 and $2 and a < (select 3);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q3 (2, 2); -create table hp1 partition of hp for values with (MODULUS 4, REMAINDER 1); +create table hp1 partition of hp for values with (modulus 4, remainder 1); -create table hp2 partition of hp for values with (MODULUS 4, REMAINDER 2); +create table hp2 partition of hp for values with (modulus 4, remainder 2); -create table hp3 partition of hp for values with (MODULUS 4, REMAINDER 3); +create table hp3 partition of hp for values with (modulus 4, remainder 3); prepare hp_q1 (text) as select * from hp where a is null and b = $1;; -explain (COSTS 'off') execute hp_q1 ('xxx'); +explain (costs 'off') execute hp_q1 ('xxx'); deallocate hp_q1; drop table hp; create table list_part (a int) -partition by LIST(a); +partition by list(a); create table list_part1 partition of list_part for values in (1); @@ -1020,14 +929,9 @@ insert into list_part select generate_series(1, 4); begin; -declare "cur" scroll +declare cur scroll cursor -for select - 1 -from - list_part -where - a > (select 1) and a < (select 4);; +for select 1 from list_part where a > (select 1) and a < (select 4);; move forward 3 from cur; @@ -1041,9 +945,7 @@ create function list_part_fn(int) returns int language plpgsql stable -as $function$ -begin return $1; end; -$function$; +as $$ begin return $1; end;$$; select * from list_part where a = list_part_fn(1); @@ -1058,7 +960,7 @@ drop table list_part; create function explain_parallel_append(text) returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin @@ -1076,17 +978,11 @@ begin return next ln; end loop; end; -$function$; +$$; prepare ab_q4 -(int, -int) -as select - AVG(a) -from - ab -where - a between $1 and $2 and b < 4;; +(int, int) +as select avg(a) from ab where a between $1 and $2 and b < 4;; set parallel_setup_cost = 0; @@ -1099,15 +995,8 @@ set max_parallel_workers_per_gather = 2; select explain_parallel_append('execute ab_q4 (2, 2)'); prepare ab_q5 -(int, -int, -int) -as select - AVG(a) -from - ab -where - a in ($1, $2, $3) and b < 4;; +(int, int, int) +as select avg(a) from ab where a in ($1, $2, $3) and b < 4;; select explain_parallel_append('execute ab_q5 (1, 1, 1)'); @@ -1128,23 +1017,23 @@ insert into lprt_a values (1), (1); analyze lprt_a; -create index "ab_a2_b1_a_idx" on ab_a2_b1 using btree (a); +create index ab_a2_b1_a_idx on ab_a2_b1 using btree (a); -create index "ab_a2_b2_a_idx" on ab_a2_b2 using btree (a); +create index ab_a2_b2_a_idx on ab_a2_b2 using btree (a); -create index "ab_a2_b3_a_idx" on ab_a2_b3 using btree (a); +create index ab_a2_b3_a_idx on ab_a2_b3 using btree (a); -create index "ab_a1_b1_a_idx" on ab_a1_b1 using btree (a); +create index ab_a1_b1_a_idx on ab_a1_b1 using btree (a); -create index "ab_a1_b2_a_idx" on ab_a1_b2 using btree (a); +create index ab_a1_b2_a_idx on ab_a1_b2 using btree (a); -create index "ab_a1_b3_a_idx" on ab_a1_b3 using btree (a); +create index ab_a1_b3_a_idx on ab_a1_b3 using btree (a); -create index "ab_a3_b1_a_idx" on ab_a3_b1 using btree (a); +create index ab_a3_b1_a_idx on ab_a3_b1 using btree (a); -create index "ab_a3_b2_a_idx" on ab_a3_b2 using btree (a); +create index ab_a3_b2_a_idx on ab_a3_b2 using btree (a); -create index "ab_a3_b3_a_idx" on ab_a3_b3 using btree (a); +create index ab_a3_b3_a_idx on ab_a3_b3 using btree (a); set enable_hashjoin = 0; @@ -1200,18 +1089,12 @@ select from ab where - a = (select MAX(a) from lprt_a) and - b = (select MAX(a) - 1 from lprt_a); + a = (select max(a) from lprt_a) and b = (select max(a) - 1 from lprt_a); select * from - ( - select * from ab where a = 1 - union all - select * from ab - ) - as ab + (select * from ab where a = 1 union all select * from ab) as ab where b = (select 1); @@ -1219,9 +1102,7 @@ select * from ( - select * from ab where a = 1 - union all - values (10, 5) + select * from ab where a = 1 union all values (10, 5) union all select * from ab ) @@ -1245,32 +1126,17 @@ as select * from ( - select - cast(tableoid as regclass), - a, - b - from - ab + select cast(tableoid as regclass), a, b from ab union all - select - cast(tableoid as regclass), - x, - y - from - xy_1 + select cast(tableoid as regclass), x, y from xy_1 union all - select - cast(tableoid as regclass), - a, - b - from - ab + select cast(tableoid as regclass), a, b from ab ) as ab where a = $1 and b = (select -10);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ab_q6 (1); execute ab_q6 (100); @@ -1293,11 +1159,8 @@ deallocate ab_q6; insert into ab values (1, 2); -select - explain_analyze( - ' -update ab_a1 set b = 3 from ab where ab.a = 1 and ab.a = ab_a1.a;' - ); +select explain_analyze(' +update ab_a1 set b = 3 from ab where ab.a = 1 and ab.a = ab_a1.a;'); select * from ab; @@ -1305,11 +1168,8 @@ truncate ab; insert into ab values (1, 1), (1, 2), (1, 3), (2, 1); -select - explain_analyze( - ' -update ab_a1 set b = 3 from ab_a2 where ab_a2.b = (select 1);' - ); +select explain_analyze(' +update ab_a1 set b = 3 from ab_a2 where ab_a2.b = (select 1);'); select cast(tableoid as regclass), * from ab; @@ -1334,17 +1194,17 @@ create table tprt_5 partition of tprt for values from (3001) to (4001); create table tprt_6 partition of tprt for values from (4001) to (5001); -create index "tprt1_idx" on tprt_1 using btree (col1); +create index tprt1_idx on tprt_1 using btree (col1); -create index "tprt2_idx" on tprt_2 using btree (col1); +create index tprt2_idx on tprt_2 using btree (col1); -create index "tprt3_idx" on tprt_3 using btree (col1); +create index tprt3_idx on tprt_3 using btree (col1); -create index "tprt4_idx" on tprt_4 using btree (col1); +create index tprt4_idx on tprt_4 using btree (col1); -create index "tprt5_idx" on tprt_5 using btree (col1); +create index tprt5_idx on tprt_5 using btree (col1); -create index "tprt6_idx" on tprt_6 using btree (col1); +create index tprt6_idx on tprt_6 using btree (col1); insert into tprt values (10), (20), (501), (502), (505), (1001), (4500); @@ -1360,10 +1220,7 @@ select tbl1.col1, tprt.col1 from - tbl1 - inner join - tprt - on tbl1.col1 > tprt.col1 + tbl1 inner join tprt on tbl1.col1 > tprt.col1 order by tbl1.col1, tprt.col1; @@ -1371,10 +1228,7 @@ select tbl1.col1, tprt.col1 from - tbl1 - inner join - tprt - on tbl1.col1 = tprt.col1 + tbl1 inner join tprt on tbl1.col1 = tprt.col1 order by tbl1.col1, tprt.col1; @@ -1388,10 +1242,7 @@ select tbl1.col1, tprt.col1 from - tbl1 - inner join - tprt - on tbl1.col1 > tprt.col1 + tbl1 inner join tprt on tbl1.col1 > tprt.col1 order by tbl1.col1, tprt.col1; @@ -1399,10 +1250,7 @@ select tbl1.col1, tprt.col1 from - tbl1 - inner join - tprt - on tbl1.col1 = tprt.col1 + tbl1 inner join tprt on tbl1.col1 = tprt.col1 order by tbl1.col1, tprt.col1; @@ -1416,10 +1264,7 @@ select tbl1.col1, tprt.col1 from - tbl1 - inner join - tprt - on tbl1.col1 < tprt.col1 + tbl1 inner join tprt on tbl1.col1 < tprt.col1 order by tbl1.col1, tprt.col1; @@ -1433,10 +1278,7 @@ select tbl1.col1, tprt.col1 from - tbl1 - inner join - tprt - on tbl1.col1 = tprt.col1 + tbl1 inner join tprt on tbl1.col1 = tprt.col1 order by tbl1.col1, tprt.col1; @@ -1447,21 +1289,21 @@ create table part_abc ( b int not null, c int not null ) -partition by LIST(a); +partition by list(a); create table part_bac ( b int not null, a int not null, c int not null ) -partition by LIST(b); +partition by list(b); create table part_cab ( c int not null, a int not null, b int not null ) -partition by LIST(c); +partition by list(c); create table part_abc_p1 ( a int not null, @@ -1482,17 +1324,10 @@ alter table part_cab part_abc_p1 for values in (3); prepare part_abc_q1 -(int, -int, -int) -as select - * -from - part_abc -where - a = $1 and b = $2 and c = $3;; +(int, int, int) +as select * from part_abc where a = $1 and b = $2 and c = $3;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute part_abc_q1 (1, 2, 3); deallocate part_abc_q1; @@ -1503,13 +1338,13 @@ create table listp ( a int, b int ) -partition by LIST(a); +partition by list(a); -create table listp_1 partition of listp for values in (1) partition by LIST(b); +create table listp_1 partition of listp for values in (1) partition by list(b); create table listp_1_1 partition of listp_1 for values in (1); -create table listp_2 partition of listp for values in (2) partition by LIST(b); +create table listp_2 partition of listp for values in (2) partition by list(b); create table listp_2_1 partition of listp_2 for values in (2); @@ -1517,33 +1352,25 @@ select * from listp where b = 1; prepare q1 (int, int) as select * from listp where b in ($1, $2);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (1, 1); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (2, 2); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (0, 0); deallocate q1; prepare q1 -(int, -int, -int, -int) -as select - * -from - listp -where - b in ($1, $2) and $3 <> b and $4 <> b;; +(int, int, int, int) +as select * from listp where b in ($1, $2) and $3 <> b and $4 <> b;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (1, 2, 2, 0); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute q1 (1, 2, 2, 1); select * from listp where a = (select cast(null as int)); @@ -1567,61 +1394,44 @@ for values from ('3000-02-01') to ('3000-03-01'); select * from stable_qual_pruning where a < localtimestamp; -select - * -from - stable_qual_pruning -where - a < - cast('2000-02-01' - as timestamp with time zone); +select * from stable_qual_pruning where a < cast('2000-02-01' as timestamptz); select * from stable_qual_pruning where - a = any (cast(array['2010-02-01', '2020-01-01'] - as timestamp[])); + a = any (cast(array['2010-02-01', '2020-01-01'] as timestamp[])); select * from stable_qual_pruning where - a = any (cast(array['2000-02-01', '2010-01-01'] - as timestamp[])); + a = any (cast(array['2000-02-01', '2010-01-01'] as timestamp[])); select * from stable_qual_pruning where - a = any (cast(array['2000-02-01', localtimestamp] - as timestamp[])); + a = any (cast(array['2000-02-01', localtimestamp] as timestamp[])); select * from stable_qual_pruning where - a = any (cast(array['2010-02-01', '2020-01-01'] - as timestamp with time zone[])); + a = any (cast(array['2010-02-01', '2020-01-01'] as timestamptz[])); select * from stable_qual_pruning where - a = any (cast(array['2000-02-01', '2010-01-01'] - as timestamp with time zone[])); + a = any (cast(array['2000-02-01', '2010-01-01'] as timestamptz[])); -select - * -from - stable_qual_pruning -where - a = any (cast(null as timestamp with time zone[])); +select * from stable_qual_pruning where a = any (cast(null as timestamptz[])); drop table stable_qual_pruning; @@ -1634,27 +1444,15 @@ partition by range(a, (abs(b)), c); create table mc3p0 partition of mc3p -for values from (0, -0, -0) to (0, -maxvalue, -maxvalue); +for values from (0, 0, 0) to (0, maxvalue, maxvalue); create table mc3p1 partition of mc3p -for values from (1, -1, -1) to (2, -minvalue, -minvalue); +for values from (1, 1, 1) to (2, minvalue, minvalue); create table mc3p2 partition of mc3p -for values from (2, -minvalue, -minvalue) to (3, -maxvalue, -maxvalue); +for values from (2, minvalue, minvalue) to (3, maxvalue, maxvalue); insert into mc3p values (0, 1, 1), (1, 1, 1), (2, 1, 1); @@ -1662,26 +1460,26 @@ select * from mc3p where a < 3 and abs(b) = 1; prepare ps1 as select * from mc3p where a = $1 and abs(b) < (select 3);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ps1 (1); deallocate ps1; prepare ps2 as select * from mc3p where a <= $1 and abs(b) < (select 3);; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute ps2 (1); deallocate ps2; drop table mc3p; -create table boolvalues (value boolean not null); +create table boolvalues (value bool not null); insert into boolvalues values ('t'), ('f'); -create table boolp (a boolean) -partition by LIST(a); +create table boolp (a bool) +partition by list(a); create table boolp_t partition of boolp for values in ('t'); @@ -1717,25 +1515,19 @@ analyze ma_test; prepare mt_q1 (int) -as select - a -from - ma_test -where - a >= $1 and a % 10 = 5 -order by b;; +as select a from ma_test where a >= $1 and a % 10 = 5 order by b;; -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute mt_q1 (15); execute mt_q1 (15); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute mt_q1 (25); execute mt_q1 (25); -explain (ANALYZE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, costs 'off', summary 'off', timing 'off', buffers 'off') execute mt_q1 (35); execute mt_q1 (35); @@ -1744,12 +1536,12 @@ deallocate mt_q1; prepare mt_q2 (int) as select * from ma_test where a >= $1 order by b limit 1;; -explain (ANALYZE, VERBOSE, COSTS 'off', SUMMARY 'off', TIMING 'off', BUFFERS 'off') +explain (analyze, verbose, costs 'off', summary 'off', timing 'off', buffers 'off') execute mt_q2 (35); deallocate mt_q2; -select * from ma_test where a >= (select MIN(b) from ma_test_p2) order by b; +select * from ma_test where a >= (select min(b) from ma_test_p2) order by b; reset enable_seqscan; @@ -1760,7 +1552,7 @@ drop table ma_test; reset enable_indexonlyscan; create table pp_arrpart (a int[]) -partition by LIST(a); +partition by list(a); create table pp_arrpart1 partition of pp_arrpart for values in ('{1}'); @@ -1781,15 +1573,15 @@ delete from pp_arrpart where a = '{1}'; drop table pp_arrpart; create table pph_arrpart (a int[]) -partition by HASH(a); +partition by hash(a); create table pph_arrpart1 partition of pph_arrpart -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table pph_arrpart2 partition of pph_arrpart -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); insert into pph_arrpart values ('{1}'), ('{1, 2}'), ('{4, 5}'); @@ -1806,7 +1598,7 @@ drop table pph_arrpart; create type pp_colors as enum ('green', 'blue', 'black'); create table pp_enumpart (a pp_colors) -partition by LIST(a); +partition by list(a); create table pp_enumpart_green partition of pp_enumpart for values in ('green'); @@ -1823,7 +1615,7 @@ drop type pp_colors; create type pp_rectype as (a int, b int); create table pp_recpart (a pp_rectype) -partition by LIST(a); +partition by list(a); create table pp_recpart_11 partition of pp_recpart for values in ('(1,1)'); @@ -1838,7 +1630,7 @@ drop table pp_recpart; drop type pp_rectype; create table pp_intrangepart (a int4range) -partition by LIST(a); +partition by list(a); create table pp_intrangepart12 partition of pp_intrangepart @@ -1858,7 +1650,7 @@ create table pp_lp ( a int, value int ) -partition by LIST(a); +partition by list(a); create table pp_lp1 partition of pp_lp for values in (1); @@ -1926,7 +1718,7 @@ reset enable_partition_pruning; reset constraint_exclusion; create temporary table pp_temp_parent (a int) -partition by LIST(a); +partition by list(a); create temporary table pp_temp_part_1 partition of pp_temp_parent @@ -1945,7 +1737,7 @@ create temporary table p ( b int, c int ) -partition by LIST(a); +partition by list(a); create temporary table p1 partition of p for values in (1); @@ -1956,18 +1748,18 @@ create temporary table q ( b int, c int ) -partition by LIST(a); +partition by list(a); -create temporary table q1 partition of q for values in (1) partition by LIST(b); +create temporary table q1 partition of q for values in (1) partition by list(b); create temporary table q11 partition of q1 for values in (1) -partition by LIST(c); +partition by list(c); create temporary table q111 partition of q11 for values in (1); -create temporary table q2 partition of q for values in (2) partition by LIST(b); +create temporary table q2 partition of q for values in (2) partition by list(b); create temporary table q21 partition of q2 for values in (1); @@ -1979,11 +1771,7 @@ select * from ( - select * from p - union all - select * from q1 - union all - select 1, 1, 1 + select * from p union all select * from q1 union all select 1, 1, 1 ) as s (a, b, c) where @@ -1993,36 +1781,25 @@ select * from ( - select * from p - union all - select * from q1 - union all - select 1, 1, 1 + select * from p union all select * from q1 union all select 1, 1, 1 ) as s (a, b, c) where s.a = 1 and s.b = 1 and s.c = (select 1); prepare q -(int, -int) +(int, int) as select * from ( - select * from p - union all - select * from q1 - union all - select 1, 1, 1 + select * from p union all select * from q1 union all select 1, 1, 1 ) as s (a, b, c) where - s.a = $1 and - s.b = $2 and - s.c = (select 1);; + s.a = $1 and s.b = $2 and s.c = (select 1);; -explain (COSTS 'off') execute q (1, 1); +explain (costs 'off') execute q (1, 1); execute q (1, 1); @@ -2032,11 +1809,11 @@ create table listp ( a int, b int ) -partition by LIST(a); +partition by list(a); create table listp1 partition of listp for values in (1); -create table listp2 partition of listp for values in (2) partition by LIST(b); +create table listp2 partition of listp for values in (2) partition by list(b); create table listp2_10 partition of listp2 for values in (10); @@ -2067,12 +1844,12 @@ set parallel_setup_cost = 0; set parallel_tuple_cost = 0; create table listp (a int) -partition by LIST(a); +partition by list(a); create table listp_12 partition of listp for values in (1, 2) -partition by LIST(a); +partition by list(a); create table listp_12_1 partition of listp_12 for values in (1); @@ -2083,12 +1860,9 @@ alter table listp_12_1 select explain_parallel_append('select * from listp where a = (select 1);'); -select - explain_parallel_append( - 'select * from listp where a = (select 1) +select explain_parallel_append('select * from listp where a = (select 1) union all -select * from listp where a = (select 2);' - ); +select * from listp where a = (select 2);'); drop table listp; @@ -2107,7 +1881,7 @@ partition by range(a); create table rangep_0_to_100 partition of rangep for values from (0) to (100) -partition by LIST(b); +partition by list(b); create table rangep_0_to_100_1 partition of rangep_0_to_100 for values in (1); @@ -2170,45 +1944,25 @@ partition by range(a, b, c, d); create table rp_prefix_test3_p1 partition of rp_prefix_test3 -for values from (1, -1, -1, -0) to (1, -1, -1, -10); +for values from (1, 1, 1, 0) to (1, 1, 1, 10); create table rp_prefix_test3_p2 partition of rp_prefix_test3 -for values from (2, -2, -2, -0) to (2, -2, -2, -10); +for values from (2, 2, 2, 0) to (2, 2, 2, 10); select * from rp_prefix_test3 where - a >= 1 and - b >= 1 and - b >= 2 and - c >= 2 and - d >= 0; + a >= 1 and b >= 1 and b >= 2 and c >= 2 and d >= 0; select * from rp_prefix_test3 where - a >= 1 and - b >= 1 and - b = 2 and - c = 2 and - d >= 0; + a >= 1 and b >= 1 and b = 2 and c = 2 and d >= 0; drop table rp_prefix_test1; @@ -2222,14 +1976,15 @@ create table hp_prefix_test ( c int, d int ) -partition by HASH(a part_test_int4_ops, -b part_test_int4_ops, -c part_test_int4_ops, -d part_test_int4_ops); +partition by hash( + a part_test_int4_ops, + b part_test_int4_ops, + c part_test_int4_ops, + d part_test_int4_ops +); select - 'create table hp_prefix_test_p' || - cast(x as text) || + 'create table hp_prefix_test_p' || cast(x as text) || ' partition of hp_prefix_test for values with (modulus 8, remainder ' || cast(x as text) || ');' @@ -2253,21 +2008,13 @@ select string_agg( c.colname || case - when g.s & (1 << c.colpos) = 0 - then ' is null' + when g.s & (1 << c.colpos) = 0 then ' is null' else ' = ' || cast(colpos + 1 as text) end, ' and ' order by c.colpos ) from - ( - values - ('a', 0), - ('b', 1), - ('c', 2), - ('d', 3) - ) - as c (colname, colpos), + (values ('a', 0), ('b', 1), ('c', 2), ('d', 3)) as c (colname, colpos), generate_series(0, 15) as g (s) group by g.s order by g.s; @@ -2277,53 +2024,46 @@ select string_agg( c.colname || case - when g.s & (1 << c.colpos) = 0 - then ' is null' + when g.s & (1 << c.colpos) = 0 then ' is null' else ' = ' || cast(colpos + 1 as text) end, ' and ' order by c.colpos ) from - ( - values - ('a', 0), - ('b', 1), - ('c', 2), - ('d', 3) - ) - as c (colname, colpos), + (values ('a', 0), ('b', 1), ('c', 2), ('d', 3)) as c (colname, colpos), generate_series(0, 15) as g (s) group by g.s order by g.s; drop table hp_prefix_test; -create operator === (LEFTARG = int, -RIGHTARG = int, -PROCEDURE = int4eq, -COMMUTATOR = ===, -HASHES); +create operator === ( + leftarg = int4, + rightarg = int4, + procedure = int4eq, + commutator = ===, + hashes +); create operator class part_test_int4_ops2 - for type int + for type int4 using hash as operator 1 ===, - function 2 part_hashint4_noop(int, bigint); + function 2 part_hashint4_noop(int4, int8); create table hp_contradict_test ( a int, b int ) -partition by HASH(a part_test_int4_ops2, -b part_test_int4_ops2); +partition by hash(a part_test_int4_ops2, b part_test_int4_ops2); create table hp_contradict_test_p1 partition of hp_contradict_test -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table hp_contradict_test_p2 partition of hp_contradict_test -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); select * from hp_contradict_test where a is null and a === 1 and b === 1; @@ -2333,26 +2073,26 @@ drop table hp_contradict_test; drop operator class part_test_int4_ops2 using hash; -drop operator === (int, int); +drop operator === (int4, int4); drop function explain_analyze(text); create table part_abc ( a int, b text, - c boolean + c bool ) -partition by LIST(a); +partition by list(a); create table part_abc_1 ( b text, a int, - c boolean + c bool ); create table part_abc_2 ( a int, - c boolean, + c bool, b text ); @@ -2374,15 +2114,15 @@ with cascaded check option; update part_abc_view set b = $2 where a = $1 returning *; -explain (VERBOSE, COSTS 'off') execute update_part_abc_view (1, 'd'); +explain (verbose, costs 'off') execute update_part_abc_view (1, 'd'); execute update_part_abc_view (1, 'd'); -explain (VERBOSE, COSTS 'off') execute update_part_abc_view (2, 'a'); +explain (verbose, costs 'off') execute update_part_abc_view (2, 'a'); execute update_part_abc_view (2, 'a'); -explain (VERBOSE, COSTS 'off') execute update_part_abc_view (3, 'a'); +explain (verbose, costs 'off') execute update_part_abc_view (3, 'a'); execute update_part_abc_view (3, 'a'); @@ -2392,9 +2132,7 @@ create function stable_one() returns int language plpgsql stable -as $function$ -begin return 1; end; -$function$; +as $$ begin return 1; end; $$; select * from part_abc_view; @@ -2412,7 +2150,7 @@ create table part_abc_log ( action text, a int, b text, - c boolean + c bool ); with @@ -2424,9 +2162,7 @@ as ( part_abc_2 as pt2 on q.pid = pt2.a on pt.a = stable_one() + 2 - when not matched by target - then insert - values (1, 'd', false) + when not matched by target then insert values (1, 'd', false) returning "mergesupport#25", pt.* ) @@ -2443,9 +2179,7 @@ as ( part_abc_2 as pt2 on q.pid = pt2.a on pt.a = stable_one() + 2 - when not matched by target - then insert - values (1, 'd', false) + when not matched by target then insert values (1, 'd', false) returning "mergesupport#25", pt.* ) @@ -2480,20 +2214,18 @@ partition of part_abc_3 for values from (100) to (maxvalue); select - MIN(a) over (partition by a order by a) + min(a) over (partition by a order by a) from part_abc where - a >= stable_one() + 1 and - d <= stable_one() + a >= stable_one() + 1 and d <= stable_one() union all select - MIN(a) over (partition by a order by a) + min(a) over (partition by a order by a) from part_abc where - a >= stable_one() + 1 and - d >= stable_one(); + a >= stable_one() + 1 and d >= stable_one(); drop view part_abc_view; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__password_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__password_100.snap index 0b16de307..d3c41f811 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__password_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__password_100.snap @@ -116,8 +116,7 @@ create role regress_passwd_sha_len2 select rolname, - rolpassword not like '%A6xHKoH/494E941doaPOYg==%' - as is_rolpassword_rehashed + rolpassword not like '%A6xHKoH/494E941doaPOYg==%' as is_rolpassword_rehashed from pg_authid where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__password_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__password_80.snap index 0b16de307..d3c41f811 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__password_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__password_80.snap @@ -116,8 +116,7 @@ create role regress_passwd_sha_len2 select rolname, - rolpassword not like '%A6xHKoH/494E941doaPOYg==%' - as is_rolpassword_rehashed + rolpassword not like '%A6xHKoH/494E941doaPOYg==%' as is_rolpassword_rehashed from pg_authid where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__pg_lsn_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__pg_lsn_100.snap index 8b315c5b3..2734a536b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__pg_lsn_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__pg_lsn_100.snap @@ -23,7 +23,7 @@ select pg_input_is_valid('16AE7F7', 'pg_lsn'); select * from pg_input_error_info('16AE7F7', 'pg_lsn'); -select MIN(f1), MAX(f1) from pg_lsn_tbl; +select min(f1), max(f1) from pg_lsn_tbl; drop table pg_lsn_tbl; @@ -57,8 +57,7 @@ select cast('0/0' as pg_lsn) + (cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - cast('0/0' select cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - - (cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - - cast('0/0' as pg_lsn)); + (cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - cast('0/0' as pg_lsn)); select cast('0/16AE7F7' as pg_lsn) + cast('NaN' as numeric); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__pg_lsn_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__pg_lsn_80.snap index 87335f1a0..acaf5c9b9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__pg_lsn_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__pg_lsn_80.snap @@ -23,7 +23,7 @@ select pg_input_is_valid('16AE7F7', 'pg_lsn'); select * from pg_input_error_info('16AE7F7', 'pg_lsn'); -select MIN(f1), MAX(f1) from pg_lsn_tbl; +select min(f1), max(f1) from pg_lsn_tbl; drop table pg_lsn_tbl; @@ -55,13 +55,11 @@ select cast('0/1' as pg_lsn) - cast(2 as numeric); select cast('0/0' as pg_lsn) + - (cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - - cast('0/0' as pg_lsn)); + (cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - cast('0/0' as pg_lsn)); select cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - - (cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - - cast('0/0' as pg_lsn)); + (cast('FFFFFFFF/FFFFFFFF' as pg_lsn) - cast('0/0' as pg_lsn)); select cast('0/16AE7F7' as pg_lsn) + cast('NaN' as numeric); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plancache_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plancache_100.snap index afde0c746..39616c298 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plancache_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plancache_100.snap @@ -53,7 +53,7 @@ execute vprep; create function cache_test(int) returns int language plpgsql -as $function$ +as $$ declare total int; begin create temp table t1(f1 int); @@ -65,7 +65,7 @@ begin drop table t1; return total; end -$function$; +$$; select cache_test(1); @@ -79,11 +79,10 @@ as select 2 + 2 as f1; create function cache_test_2() returns int language plpgsql -as $function$ +as $$ begin return f1 from v1; -end -$function$; +end$$; select cache_test_2(); @@ -93,16 +92,15 @@ as select 2 + 2 + 4 as f1; select cache_test_2(); create or replace temporary view v1 -as select - 2 + 2 + 4 + (select MAX(unique1) from tenk1) as f1; +as select 2 + 2 + 4 + (select max(unique1) from tenk1) as f1; select cache_test_2(); -create schema "s1"; +create schema s1; create table abc (f1 int); -create schema "s2"; +create schema s2; create table abc (f1 int); @@ -123,7 +121,7 @@ select f1 from abc; execute p1; alter table s1.abc - add column f2 double precision; + add column f2 float8; execute p1; @@ -148,7 +146,7 @@ execute p2; create function cachebug() returns void language plpgsql -as $function$ +as $$ declare r int; begin drop table if exists temptable cascade; @@ -157,15 +155,14 @@ begin for r in select * from vv loop raise notice '%', r; end loop; -end -$function$; +end$$; select cachebug(); select cachebug(); create table pc_list_parted (a int) -partition by LIST(a); +partition by list(a); create table pc_list_part_null partition of pc_list_parted for values in (null); @@ -205,19 +202,19 @@ create index on test_mode using btree (a); analyze test_mode; -prepare test_mode_pp (int) as select COUNT(*) from test_mode where a = $1;; +prepare test_mode_pp (int) as select count(*) from test_mode where a = $1;; select name, generic_plans, custom_plans from pg_prepared_statements where name = 'test_mode_pp'; set plan_cache_mode = auto; -explain (COSTS 'off') execute test_mode_pp (2); +explain (costs 'off') execute test_mode_pp (2); select name, generic_plans, custom_plans from pg_prepared_statements where name = 'test_mode_pp'; set plan_cache_mode = force_generic_plan; -explain (COSTS 'off') execute test_mode_pp (2); +explain (costs 'off') execute test_mode_pp (2); select name, generic_plans, custom_plans from pg_prepared_statements where name = 'test_mode_pp'; @@ -237,11 +234,11 @@ execute test_mode_pp (1); select name, generic_plans, custom_plans from pg_prepared_statements where name = 'test_mode_pp'; -explain (COSTS 'off') execute test_mode_pp (2); +explain (costs 'off') execute test_mode_pp (2); set plan_cache_mode = force_custom_plan; -explain (COSTS 'off') execute test_mode_pp (2); +explain (costs 'off') execute test_mode_pp (2); select name, generic_plans, custom_plans from pg_prepared_statements where name = 'test_mode_pp'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plancache_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plancache_80.snap index 2ca36ffc0..5d750acc2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plancache_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plancache_80.snap @@ -53,7 +53,7 @@ execute vprep; create function cache_test(int) returns int language plpgsql -as $function$ +as $$ declare total int; begin create temp table t1(f1 int); @@ -65,7 +65,7 @@ begin drop table t1; return total; end -$function$; +$$; select cache_test(1); @@ -79,11 +79,10 @@ as select 2 + 2 as f1; create function cache_test_2() returns int language plpgsql -as $function$ +as $$ begin return f1 from v1; -end -$function$; +end$$; select cache_test_2(); @@ -93,18 +92,15 @@ as select 2 + 2 + 4 as f1; select cache_test_2(); create or replace temporary view v1 -as select - 2 + 2 + 4 + - (select MAX(unique1) from tenk1) - as f1; +as select 2 + 2 + 4 + (select max(unique1) from tenk1) as f1; select cache_test_2(); -create schema "s1"; +create schema s1; create table abc (f1 int); -create schema "s2"; +create schema s2; create table abc (f1 int); @@ -125,7 +121,7 @@ select f1 from abc; execute p1; alter table s1.abc - add column f2 double precision; + add column f2 float8; execute p1; @@ -150,7 +146,7 @@ execute p2; create function cachebug() returns void language plpgsql -as $function$ +as $$ declare r int; begin drop table if exists temptable cascade; @@ -159,15 +155,14 @@ begin for r in select * from vv loop raise notice '%', r; end loop; -end -$function$; +end$$; select cachebug(); select cachebug(); create table pc_list_parted (a int) -partition by LIST(a); +partition by list(a); create table pc_list_part_null partition of pc_list_parted for values in (null); @@ -207,7 +202,7 @@ create index on test_mode using btree (a); analyze test_mode; -prepare test_mode_pp (int) as select COUNT(*) from test_mode where a = $1;; +prepare test_mode_pp (int) as select count(*) from test_mode where a = $1;; select name, @@ -220,7 +215,7 @@ where set plan_cache_mode = auto; -explain (COSTS 'off') execute test_mode_pp (2); +explain (costs 'off') execute test_mode_pp (2); select name, @@ -233,7 +228,7 @@ where set plan_cache_mode = force_generic_plan; -explain (COSTS 'off') execute test_mode_pp (2); +explain (costs 'off') execute test_mode_pp (2); select name, @@ -274,11 +269,11 @@ from where name = 'test_mode_pp'; -explain (COSTS 'off') execute test_mode_pp (2); +explain (costs 'off') execute test_mode_pp (2); set plan_cache_mode = force_custom_plan; -explain (COSTS 'off') execute test_mode_pp (2); +explain (costs 'off') execute test_mode_pp (2); select name, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_100.snap index 18306abf0..62f09effb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_100.snap @@ -7,7 +7,7 @@ create table room ( comment text ); -create unique index "room_rno" on room using btree (roomno bpchar_ops); +create unique index room_rno on room using btree (roomno bpchar_ops); create table wslot ( slotname char(20), @@ -16,14 +16,14 @@ create table wslot ( backlink char(20) ); -create unique index "wslot_name" on wslot using btree (slotname bpchar_ops); +create unique index wslot_name on wslot using btree (slotname bpchar_ops); create table pfield ( name text, comment text ); -create unique index "pfield_name" on pfield using btree (name text_ops); +create unique index pfield_name on pfield using btree (name text_ops); create table pslot ( slotname char(20), @@ -32,7 +32,7 @@ create table pslot ( backlink char(20) ); -create unique index "pslot_name" on pslot using btree (slotname bpchar_ops); +create unique index pslot_name on pslot using btree (slotname bpchar_ops); create table pline ( slotname char(20), @@ -41,7 +41,7 @@ create table pline ( backlink char(20) ); -create unique index "pline_name" on pline using btree (slotname bpchar_ops); +create unique index pline_name on pline using btree (slotname bpchar_ops); create table hub ( name char(14), @@ -49,7 +49,7 @@ create table hub ( nslots int ); -create unique index "hub_name" on hub using btree (name bpchar_ops); +create unique index hub_name on hub using btree (name bpchar_ops); create table hslot ( slotname char(20), @@ -58,16 +58,16 @@ create table hslot ( slotlink char(20) ); -create unique index "hslot_name" on hslot using btree (slotname bpchar_ops); +create unique index hslot_name on hslot using btree (slotname bpchar_ops); -create index "hslot_hubname" on hslot using btree (hubname bpchar_ops); +create index hslot_hubname on hslot using btree (hubname bpchar_ops); create table system ( name text, comment text ); -create unique index "system_name" on system using btree (name text_ops); +create unique index system_name on system using btree (name text_ops); create table iface ( slotname char(20), @@ -76,7 +76,7 @@ create table iface ( slotlink char(20) ); -create unique index "iface_name" on iface using btree (slotname bpchar_ops); +create unique index iface_name on iface using btree (slotname bpchar_ops); create table phone ( slotname char(20), @@ -84,45 +84,45 @@ create table phone ( slotlink char(20) ); -create unique index "phone_name" on phone using btree (slotname bpchar_ops); +create unique index phone_name on phone using btree (slotname bpchar_ops); create function tg_room_au() returns trigger language plpgsql -as $function$ +as ' begin if new.roomno != old.roomno then update WSlot set roomno = new.roomno where roomno = old.roomno; end if; return new; end; -$function$; +'; create trigger tg_room_au after update on room for each row execute function tg_room_au(); create function tg_room_ad() returns trigger language plpgsql -as $function$ +as ' begin delete from WSlot where roomno = old.roomno; return old; end; -$function$; +'; create trigger tg_room_ad after delete on room for each row execute function tg_room_ad(); create function tg_wslot_biu() returns trigger language plpgsql -as $function$ +as $$ begin if count(*) = 0 from Room where roomno = new.roomno then raise exception 'Room % does not exist', new.roomno; end if; return new; end; -$function$; +$$; create trigger tg_wslot_biu before insert or update @@ -133,33 +133,33 @@ execute function tg_wslot_biu(); create function tg_pfield_au() returns trigger language plpgsql -as $function$ +as ' begin if new.name != old.name then update PSlot set pfname = new.name where pfname = old.name; end if; return new; end; -$function$; +'; create trigger tg_pfield_au after update on pfield for each row execute function tg_pfield_au(); create function tg_pfield_ad() returns trigger language plpgsql -as $function$ +as ' begin delete from PSlot where pfname = old.name; return old; end; -$function$; +'; create trigger tg_pfield_ad after delete on pfield for each row execute function tg_pfield_ad(); create function tg_pslot_biu() returns trigger language plpgsql -as $function$ +as $proc$ declare pfrec record; ps alias for new; @@ -170,7 +170,7 @@ begin end if; return ps; end; -$function$; +$proc$; create trigger tg_pslot_biu before insert or update @@ -181,21 +181,21 @@ execute function tg_pslot_biu(); create function tg_system_au() returns trigger language plpgsql -as $function$ +as ' begin if new.name != old.name then update IFace set sysname = new.name where sysname = old.name; end if; return new; end; -$function$; +'; create trigger tg_system_au after update on system for each row execute function tg_system_au(); create function tg_iface_biu() returns trigger language plpgsql -as $function$ +as $$ declare sname text; sysrec record; @@ -213,7 +213,7 @@ begin new.slotname := sname; return new; end; -$function$; +$$; create trigger tg_iface_biu before insert or update @@ -224,28 +224,28 @@ execute function tg_iface_biu(); create function tg_hub_a() returns trigger language plpgsql -as $function$ +as ' declare hname text; dummy integer; begin - if tg_op = 'INSERT' then + if tg_op = ''INSERT'' then dummy := tg_hub_adjustslots(new.name, 0, new.nslots); return new; end if; - if tg_op = 'UPDATE' then + if tg_op = ''UPDATE'' then if new.name != old.name then update HSlot set hubname = new.name where hubname = old.name; end if; dummy := tg_hub_adjustslots(new.name, old.nslots, new.nslots); return new; end if; - if tg_op = 'DELETE' then + if tg_op = ''DELETE'' then dummy := tg_hub_adjustslots(old.name, old.nslots, 0); return old; end if; end; -$function$; +'; create trigger tg_hub_a after insert or delete or update @@ -256,7 +256,7 @@ execute function tg_hub_a(); create function tg_hub_adjustslots(hname bpchar, oldnslots int, newnslots int) returns int language plpgsql -as $function$ +as ' begin if newnslots = oldnslots then return 0; @@ -267,11 +267,11 @@ begin end if; for i in oldnslots + 1 .. newnslots loop insert into HSlot (slotname, hubname, slotno, slotlink) - values ('HS.dummy', hname, i, ''); + values (''HS.dummy'', hname, i, ''''); end loop; return 0; end -$function$; +'; comment on function tg_hub_adjustslots_wrong(bpchar, int, int) is 'function with args'; @@ -282,7 +282,7 @@ comment on function tg_hub_adjustslots(bpchar, int, int) is null; create function tg_hslot_biu() returns trigger language plpgsql -as $function$ +as ' declare sname text; xname HSlot.slotname%TYPE; @@ -290,26 +290,26 @@ declare begin select into hubrec * from Hub where name = new.hubname; if not found then - raise exception 'no manual manipulation of HSlot'; + raise exception ''no manual manipulation of HSlot''; end if; if new.slotno < 1 or new.slotno > hubrec.nslots then - raise exception 'no manual manipulation of HSlot'; + raise exception ''no manual manipulation of HSlot''; end if; - if tg_op = 'UPDATE' and new.hubname != old.hubname then + if tg_op = ''UPDATE'' and new.hubname != old.hubname then if count(*) > 0 from Hub where name = old.hubname then - raise exception 'no manual manipulation of HSlot'; + raise exception ''no manual manipulation of HSlot''; end if; end if; - sname := 'HS.' || trim(new.hubname); - sname := sname || '.'; + sname := ''HS.'' || trim(new.hubname); + sname := sname || ''.''; sname := sname || new.slotno::text; if length(sname) > 20 then - raise exception 'HSlot slotname "%" too long (20 char max)', sname; + raise exception ''HSlot slotname "%" too long (20 char max)'', sname; end if; new.slotname := sname; return new; end; -$function$; +'; create trigger tg_hslot_biu before insert or update @@ -320,7 +320,7 @@ execute function tg_hslot_biu(); create function tg_hslot_bd() returns trigger language plpgsql -as $function$ +as ' declare hubrec record; begin @@ -331,23 +331,23 @@ begin if old.slotno > hubrec.nslots then return old; end if; - raise exception 'no manual manipulation of HSlot'; + raise exception ''no manual manipulation of HSlot''; end; -$function$; +'; create trigger tg_hslot_bd before delete on hslot for each row execute function tg_hslot_bd(); create function tg_chkslotname() returns trigger language plpgsql -as $function$ +as ' begin if substr(new.slotname, 1, 2) != tg_argv[0] then - raise exception 'slotname must begin with %', tg_argv[0]; + raise exception ''slotname must begin with %'', tg_argv[0]; end if; return new; end; -$function$; +'; create trigger tg_chkslotname before insert @@ -382,14 +382,14 @@ execute function tg_chkslotname("PH"); create function tg_chkslotlink() returns trigger language plpgsql -as $function$ +as ' begin if new.slotlink isnull then - new.slotlink := ''; + new.slotlink := ''''; end if; return new; end; -$function$; +'; create trigger tg_chkslotlink before insert or update @@ -424,14 +424,14 @@ execute function tg_chkslotlink(); create function tg_chkbacklink() returns trigger language plpgsql -as $function$ +as ' begin if new.backlink isnull then - new.backlink := ''; + new.backlink := ''''; end if; return new; end; -$function$; +'; create trigger tg_chkbacklink before insert or update @@ -454,7 +454,7 @@ execute function tg_chkbacklink(); create function tg_pslot_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from PSlot where slotname = old.slotname; @@ -473,14 +473,14 @@ begin end if; return new; end; -$function$; +'; create trigger tg_pslot_bu before update on pslot for each row execute function tg_pslot_bu(); create function tg_wslot_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from WSlot where slotname = old.slotname; @@ -499,14 +499,14 @@ begin end if; return new; end; -$function$; +'; create trigger tg_wslot_bu before update on wslot for each row execute function tg_wslot_bu(); create function tg_pline_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from PLine where slotname = old.slotname; @@ -525,14 +525,14 @@ begin end if; return new; end; -$function$; +'; create trigger tg_pline_bu before update on pline for each row execute function tg_pline_bu(); create function tg_iface_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from IFace where slotname = old.slotname; @@ -551,14 +551,14 @@ begin end if; return new; end; -$function$; +'; create trigger tg_iface_bu before update on iface for each row execute function tg_iface_bu(); create function tg_hslot_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname or new.hubname != old.hubname then delete from HSlot where slotname = old.slotname; @@ -577,14 +577,14 @@ begin end if; return new; end; -$function$; +'; create trigger tg_hslot_bu before update on hslot for each row execute function tg_hslot_bu(); create function tg_phone_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from PHone where slotname = old.slotname; @@ -601,46 +601,46 @@ begin end if; return new; end; -$function$; +'; create trigger tg_phone_bu before update on phone for each row execute function tg_phone_bu(); create function tg_backlink_a() returns trigger language plpgsql -as $function$ +as ' declare dummy integer; begin - if tg_op = 'INSERT' then - if new.backlink != '' then + if tg_op = ''INSERT'' then + if new.backlink != '''' then dummy := tg_backlink_set(new.backlink, new.slotname); end if; return new; end if; - if tg_op = 'UPDATE' then + if tg_op = ''UPDATE'' then if new.backlink != old.backlink then - if old.backlink != '' then + if old.backlink != '''' then dummy := tg_backlink_unset(old.backlink, old.slotname); end if; - if new.backlink != '' then + if new.backlink != '''' then dummy := tg_backlink_set(new.backlink, new.slotname); end if; else - if new.slotname != old.slotname and new.backlink != '' then + if new.slotname != old.slotname and new.backlink != '''' then dummy := tg_slotlink_set(new.backlink, new.slotname); end if; end if; return new; end if; - if tg_op = 'DELETE' then - if old.backlink != '' then + if tg_op = ''DELETE'' then + if old.backlink != '''' then dummy := tg_backlink_unset(old.backlink, old.slotname); end if; return old; end if; end; -$function$; +'; create trigger tg_backlink_a after insert or delete or update @@ -663,7 +663,7 @@ execute function tg_backlink_a("PL"); create function tg_backlink_set(myname bpchar, blname bpchar) returns int language plpgsql -as $function$ +as ' declare mytype char(2); link char(4); @@ -671,52 +671,52 @@ declare begin mytype := substr(myname, 1, 2); link := mytype || substr(blname, 1, 2); - if link = 'PLPL' then + if link = ''PLPL'' then raise exception - 'backlink between two phone lines does not make sense'; + ''backlink between two phone lines does not make sense''; end if; - if link in ('PLWS', 'WSPL') then + if link in (''PLWS'', ''WSPL'') then raise exception - 'direct link of phone line to wall slot not permitted'; + ''direct link of phone line to wall slot not permitted''; end if; - if mytype = 'PS' then + if mytype = ''PS'' then select into rec * from PSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.backlink != blname then update PSlot set backlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'WS' then + if mytype = ''WS'' then select into rec * from WSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.backlink != blname then update WSlot set backlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'PL' then + if mytype = ''PL'' then select into rec * from PLine where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.backlink != blname then update PLine set backlink = blname where slotname = myname; end if; return 0; end if; - raise exception 'illegal backlink beginning with %', mytype; + raise exception ''illegal backlink beginning with %'', mytype; end; -$function$; +'; create function tg_backlink_unset(bpchar, bpchar) returns int language plpgsql -as $function$ +as ' declare myname alias for $1; blname alias for $2; @@ -724,75 +724,75 @@ declare rec record; begin mytype := substr(myname, 1, 2); - if mytype = 'PS' then + if mytype = ''PS'' then select into rec * from PSlot where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update PSlot set backlink = '' where slotname = myname; + update PSlot set backlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'WS' then + if mytype = ''WS'' then select into rec * from WSlot where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update WSlot set backlink = '' where slotname = myname; + update WSlot set backlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'PL' then + if mytype = ''PL'' then select into rec * from PLine where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update PLine set backlink = '' where slotname = myname; + update PLine set backlink = '''' where slotname = myname; end if; return 0; end if; end -$function$; +'; create function tg_slotlink_a() returns trigger language plpgsql -as $function$ +as ' declare dummy integer; begin - if tg_op = 'INSERT' then - if new.slotlink != '' then + if tg_op = ''INSERT'' then + if new.slotlink != '''' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; return new; end if; - if tg_op = 'UPDATE' then + if tg_op = ''UPDATE'' then if new.slotlink != old.slotlink then - if old.slotlink != '' then + if old.slotlink != '''' then dummy := tg_slotlink_unset(old.slotlink, old.slotname); end if; - if new.slotlink != '' then + if new.slotlink != '''' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; else - if new.slotname != old.slotname and new.slotlink != '' then + if new.slotname != old.slotname and new.slotlink != '''' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; end if; return new; end if; - if tg_op = 'DELETE' then - if old.slotlink != '' then + if tg_op = ''DELETE'' then + if old.slotlink != '''' then dummy := tg_slotlink_unset(old.slotlink, old.slotname); end if; return old; end if; end; -$function$; +'; create trigger tg_slotlink_a after insert or delete or update @@ -827,7 +827,7 @@ execute function tg_slotlink_a("PH"); create function tg_slotlink_set(bpchar, bpchar) returns int language plpgsql -as $function$ +as ' declare myname alias for $1; blname alias for $2; @@ -837,80 +837,80 @@ declare begin mytype := substr(myname, 1, 2); link := mytype || substr(blname, 1, 2); - if link = 'PHPH' then + if link = ''PHPH'' then raise exception - 'slotlink between two phones does not make sense'; + ''slotlink between two phones does not make sense''; end if; - if link in ('PHHS', 'HSPH') then + if link in (''PHHS'', ''HSPH'') then raise exception - 'link of phone to hub does not make sense'; + ''link of phone to hub does not make sense''; end if; - if link in ('PHIF', 'IFPH') then + if link in (''PHIF'', ''IFPH'') then raise exception - 'link of phone to hub does not make sense'; + ''link of phone to hub does not make sense''; end if; - if link in ('PSWS', 'WSPS') then + if link in (''PSWS'', ''WSPS'') then raise exception - 'slotlink from patchslot to wallslot not permitted'; + ''slotlink from patchslot to wallslot not permitted''; end if; - if mytype = 'PS' then + if mytype = ''PS'' then select into rec * from PSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update PSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'WS' then + if mytype = ''WS'' then select into rec * from WSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update WSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'IF' then + if mytype = ''IF'' then select into rec * from IFace where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update IFace set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'HS' then + if mytype = ''HS'' then select into rec * from HSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update HSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'PH' then + if mytype = ''PH'' then select into rec * from PHone where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update PHone set slotlink = blname where slotname = myname; end if; return 0; end if; - raise exception 'illegal slotlink beginning with %', mytype; + raise exception ''illegal slotlink beginning with %'', mytype; end; -$function$; +'; create function tg_slotlink_unset(bpchar, bpchar) returns int language plpgsql -as $function$ +as ' declare myname alias for $1; blname alias for $2; @@ -918,63 +918,63 @@ declare rec record; begin mytype := substr(myname, 1, 2); - if mytype = 'PS' then + if mytype = ''PS'' then select into rec * from PSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update PSlot set slotlink = '' where slotname = myname; + update PSlot set slotlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'WS' then + if mytype = ''WS'' then select into rec * from WSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update WSlot set slotlink = '' where slotname = myname; + update WSlot set slotlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'IF' then + if mytype = ''IF'' then select into rec * from IFace where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update IFace set slotlink = '' where slotname = myname; + update IFace set slotlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'HS' then + if mytype = ''HS'' then select into rec * from HSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update HSlot set slotlink = '' where slotname = myname; + update HSlot set slotlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'PH' then + if mytype = ''PH'' then select into rec * from PHone where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update PHone set slotlink = '' where slotname = myname; + update PHone set slotlink = '''' where slotname = myname; end if; return 0; end if; end; -$function$; +'; create function pslot_backlink_view(bpchar) returns text language plpgsql -as $function$ +as ' <> declare rec record; @@ -983,41 +983,41 @@ declare begin select into rec * from PSlot where slotname = $1; if not found then - return ''; + return ''''; end if; - if rec.backlink = '' then - return '-'; + if rec.backlink = '''' then + return ''-''; end if; bltype := substr(rec.backlink, 1, 2); - if bltype = 'PL' then + if bltype = ''PL'' then declare rec record; begin select into rec * from PLine where slotname = "outer".rec.backlink; - retval := 'Phone line ' || trim(rec.phonenumber); - if rec.comment != '' then - retval := retval || ' ('; + retval := ''Phone line '' || trim(rec.phonenumber); + if rec.comment != '''' then + retval := retval || '' (''; retval := retval || rec.comment; - retval := retval || ')'; + retval := retval || '')''; end if; return retval; end; end if; - if bltype = 'WS' then + if bltype = ''WS'' then select into rec * from WSlot where slotname = rec.backlink; - retval := trim(rec.slotname) || ' in room '; + retval := trim(rec.slotname) || '' in room ''; retval := retval || trim(rec.roomno); - retval := retval || ' -> '; + retval := retval || '' -> ''; return retval || wslot_slotlink_view(rec.slotname); end if; return rec.backlink; end; -$function$; +'; create function pslot_slotlink_view(bpchar) returns text language plpgsql -as $function$ +as ' declare psrec record; sltype char(2); @@ -1025,33 +1025,33 @@ declare begin select into psrec * from PSlot where slotname = $1; if not found then - return ''; + return ''''; end if; - if psrec.slotlink = '' then - return '-'; + if psrec.slotlink = '''' then + return ''-''; end if; sltype := substr(psrec.slotlink, 1, 2); - if sltype = 'PS' then - retval := trim(psrec.slotlink) || ' -> '; + if sltype = ''PS'' then + retval := trim(psrec.slotlink) || '' -> ''; return retval || pslot_backlink_view(psrec.slotlink); end if; - if sltype = 'HS' then + if sltype = ''HS'' then retval := comment from Hub H, HSlot HS where HS.slotname = psrec.slotlink and H.name = HS.hubname; - retval := retval || ' slot '; + retval := retval || '' slot ''; retval := retval || slotno::text from HSlot where slotname = psrec.slotlink; return retval; end if; return psrec.slotlink; end; -$function$; +'; create function wslot_slotlink_view(bpchar) returns text language plpgsql -as $function$ +as ' declare rec record; sltype char(2); @@ -1059,42 +1059,42 @@ declare begin select into rec * from WSlot where slotname = $1; if not found then - return ''; + return ''''; end if; - if rec.slotlink = '' then - return '-'; + if rec.slotlink = '''' then + return ''-''; end if; sltype := substr(rec.slotlink, 1, 2); - if sltype = 'PH' then + if sltype = ''PH'' then select into rec * from PHone where slotname = rec.slotlink; - retval := 'Phone ' || trim(rec.slotname); - if rec.comment != '' then - retval := retval || ' ('; + retval := ''Phone '' || trim(rec.slotname); + if rec.comment != '''' then + retval := retval || '' (''; retval := retval || rec.comment; - retval := retval || ')'; + retval := retval || '')''; end if; return retval; end if; - if sltype = 'IF' then + if sltype = ''IF'' then declare syrow System%RowType; ifrow IFace%ROWTYPE; begin select into ifrow * from IFace where slotname = rec.slotlink; select into syrow * from System where name = ifrow.sysname; - retval := syrow.name || ' IF '; + retval := syrow.name || '' IF ''; retval := retval || ifrow.ifname; - if syrow.comment != '' then - retval := retval || ' ('; + if syrow.comment != '''' then + retval := retval || '' (''; retval := retval || syrow.comment; - retval := retval || ')'; + retval := retval || '')''; end if; return retval; end; end if; return rec.slotlink; end; -$function$; +'; create view pfield_v1 as select @@ -1486,17 +1486,16 @@ insert into iface values ('IF', 'orion', 'ethernet_interface_name_too_long', '') create function recursion_test(int, int) returns text language plpgsql -as $function$ +as ' DECLARE rslt text; BEGIN IF $1 <= 0 THEN rslt = CAST($2 AS TEXT); ELSE - rslt = CAST($1 AS TEXT) || ',' || recursion_test($1 - 1, $2); + rslt = CAST($1 AS TEXT) || '','' || recursion_test($1 - 1, $2); END IF; RETURN rslt; -END; -$function$; +END;'; select recursion_test(4, 3); @@ -1505,8 +1504,8 @@ create table found_test_tbl (a int); create function test_found() returns boolean language plpgsql -as $function$ -declare +as ' + declare begin insert into found_test_tbl values (1); if FOUND then @@ -1538,8 +1537,7 @@ declare insert into found_test_tbl values (6); end if; return true; - end; -$function$; + end;'; select test_found(); @@ -1548,7 +1546,7 @@ select * from found_test_tbl; create function test_table_func_rec() returns setof found_test_tbl language plpgsql -as $function$ +as ' DECLARE rec RECORD; BEGIN @@ -1556,15 +1554,14 @@ BEGIN RETURN NEXT rec; END LOOP; RETURN; -END; -$function$; +END;'; select * from test_table_func_rec(); create function test_table_func_row() returns setof found_test_tbl language plpgsql -as $function$ +as ' DECLARE row found_test_tbl%ROWTYPE; BEGIN @@ -1572,15 +1569,14 @@ BEGIN RETURN NEXT row; END LOOP; RETURN; -END; -$function$; +END;'; select * from test_table_func_row(); create function test_ret_set_scalar(int, int) returns setof int language plpgsql -as $function$ +as ' DECLARE i int; BEGIN @@ -1588,15 +1584,14 @@ BEGIN RETURN NEXT i + 1; END LOOP; RETURN; -END; -$function$; +END;'; select * from test_ret_set_scalar(1, 10); create function test_ret_set_rec_dyn(int) returns setof record language plpgsql -as $function$ +as ' DECLARE retval RECORD; BEGIN @@ -1605,13 +1600,12 @@ BEGIN RETURN NEXT retval; RETURN NEXT retval; ELSE - SELECT INTO retval 50, 5::numeric, 'xxx'::text; + SELECT INTO retval 50, 5::numeric, ''xxx''::text; RETURN NEXT retval; RETURN NEXT retval; END IF; RETURN; -END; -$function$; +END;'; select * from test_ret_set_rec_dyn(1500) as (a int, b int, c int); @@ -1620,7 +1614,7 @@ select * from test_ret_set_rec_dyn(5) as (a int, b numeric, c text); create function test_ret_rec_dyn(int) returns record language plpgsql -as $function$ +as ' DECLARE retval RECORD; BEGIN @@ -1628,11 +1622,10 @@ BEGIN SELECT INTO retval 5, 10, 15; RETURN retval; ELSE - SELECT INTO retval 50, 5::numeric, 'xxx'::text; + SELECT INTO retval 50, 5::numeric, ''xxx''::text; RETURN retval; END IF; -END; -$function$; +END;'; select * from test_ret_rec_dyn(1500) as (a int, b int, c int); @@ -1641,136 +1634,124 @@ select * from test_ret_rec_dyn(5) as (a int, b numeric, c text); create function f1(x anyelement) returns anyelement language plpgsql -as $function$ +as $$ begin return x + 1; -end -$function$; +end$$; select f1(42) as int, f1(4.5) as num; select f1(point(3, 4)); -drop function f1(anyelement); +drop function f1(x anyelement); create function f1(x anyelement) returns anyarray language plpgsql -as $function$ +as $$ begin return array[x + 1, x + 2]; -end -$function$; +end$$; select f1(42) as int, f1(4.5) as num; -drop function f1(anyelement); +drop function f1(x anyelement); create function f1(x anyarray) returns anyelement language plpgsql -as $function$ +as $$ begin return x[1]; -end -$function$; +end$$; select f1(array[2, 4]) as int, f1(array[4.5, 7.7]) as num; select f1(stavalues1) from pg_statistic; -drop function f1(anyarray); +drop function f1(x anyarray); create function f1(x anyarray) returns anyarray language plpgsql -as $function$ +as $$ begin return x; -end -$function$; +end$$; select f1(array[2, 4]) as int, f1(array[4.5, 7.7]) as num; select f1(stavalues1) from pg_statistic; -drop function f1(anyarray); +drop function f1(x anyarray); create function f1(x anyelement) returns anyrange language plpgsql -as $function$ +as $$ begin return array[x + 1, x + 2]; -end -$function$; +end$$; create function f1(x anyrange) returns anyarray language plpgsql -as $function$ +as $$ begin return array[lower(x), upper(x)]; -end -$function$; +end$$; select f1(int4range(42, 49)) as int, f1(float8range(4.5, 7.8)) as num; -drop function f1(anyrange); +drop function f1(x anyrange); create function f1(x anycompatible, y anycompatible) returns anycompatiblearray language plpgsql -as $function$ +as $$ begin return array[x, y]; -end -$function$; +end$$; select f1(2, 4) as int, f1(2, 4.5) as num; -drop function f1(anycompatible, anycompatible); +drop function f1(x anycompatible, y anycompatible); create function f1(x anycompatiblerange, y anycompatible, z anycompatible) returns anycompatiblearray language plpgsql -as $function$ +as $$ begin return array[lower(x), upper(x), y, z]; -end -$function$; +end$$; select - f1(int4range(42, 49), 11, cast(2 as smallint)) - as int, - f1(float8range(4.5, 7.8), 7.8, cast(11 as real)) - as num; + f1(int4range(42, 49), 11, cast(2 as smallint)) as int, + f1(float8range(4.5, 7.8), 7.8, cast(11 as real)) as num; select f1(int4range(42, 49), 11, 4.5) as fail; -drop function f1(anycompatiblerange, anycompatible, anycompatible); +drop function f1(x anycompatiblerange, y anycompatible, z anycompatible); create function f1(x anycompatible) returns anycompatiblerange language plpgsql -as $function$ +as $$ begin return array[x + 1, x + 2]; -end -$function$; +end$$; create function f1(x anycompatiblerange, y anycompatiblearray) returns anycompatiblerange language plpgsql -as $function$ +as $$ begin return x; -end -$function$; +end$$; select f1(int4range(42, 49), array[11]) as int, f1(float8range(4.5, 7.8), array[7]) as num; -drop function f1(anycompatiblerange, anycompatiblearray); +drop function f1(x anycompatiblerange, y anycompatiblearray); create function f1( @@ -1782,12 +1763,11 @@ f1( out y anycompatiblearray ) language plpgsql -as $function$ +as $$ begin x := a || b; y := array[c, d]; -end -$function$; +end$$; select x, pg_typeof(x), y, pg_typeof(y) from f1(11, array[1, 2], 42, 34.5); @@ -1797,25 +1777,23 @@ select x, pg_typeof(x), y, pg_typeof(y) from f1(11, '{1,2}', point(1, 2), '(3,4) select x, pg_typeof(x), y, pg_typeof(y) from f1(11, array[1, 2.2], 42, 34.5); -drop function f1(anyelement, anyarray, anycompatible, anycompatible); +drop function f1(a anyelement, b anyarray, c anycompatible, d anycompatible); create function f1(in i int, out j int) returns int language plpgsql -as $function$ +as $$ begin return i+1; -end -$function$; +end$$; create function f1(in i int, out j int) language plpgsql -as $function$ +as $$ begin j := i+1; return; -end -$function$; +end$$; select f1(42); @@ -1823,11 +1801,10 @@ select * from f1(42); create or replace function f1(inout i int) language plpgsql -as $function$ +as $$ begin i := i+1; -end -$function$; +end$$; select f1(42); @@ -1838,15 +1815,14 @@ drop function f1(int); create function f1(in i int, out j int) returns setof int language plpgsql -as $function$ +as $$ begin j := i+1; return next; j := i+2; return next; return; -end -$function$; +end$$; select * from f1(42); @@ -1854,13 +1830,12 @@ drop function f1(int); create function f1(in i int, out j int, out k text) language plpgsql -as $function$ +as $$ begin j := i; j := j+1; k := 'foo'; -end -$function$; +end$$; select f1(42); @@ -1871,7 +1846,7 @@ drop function f1(int); create function f1(in i int, out j int, out k text) returns setof record language plpgsql -as $function$ +as $$ begin j := i+1; k := 'foo'; @@ -1879,8 +1854,7 @@ begin j := j+1; k := 'foot'; return next; -end -$function$; +end$$; select * from f1(42); @@ -1888,13 +1862,12 @@ drop function f1(int); create function duplic(in i anyelement, out j anyelement, out k anyarray) language plpgsql -as $function$ +as $$ begin j := i; k := array[j,j]; return; -end -$function$; +end$$; select * from duplic(42); @@ -1904,13 +1877,12 @@ drop function duplic(anyelement); create function duplic(in i anycompatiblerange, out j anycompatible, out k anycompatiblearray) language plpgsql -as $function$ +as $$ begin j := lower(i); k := array[lower(i),upper(i)]; return; -end -$function$; +end$$; select * from duplic(int4range(42, 49)); @@ -1926,7 +1898,7 @@ create table perform_test ( create function perform_simple_func(int) returns boolean language plpgsql -as $function$ +as ' BEGIN IF $1 < 20 THEN INSERT INTO perform_test VALUES ($1, $1 + 10); @@ -1934,13 +1906,12 @@ BEGIN ELSE RETURN FALSE; END IF; -END; -$function$; +END;'; create function perform_test_func() returns void language plpgsql -as $function$ +as ' BEGIN IF FOUND then INSERT INTO perform_test VALUES (100, 100); @@ -1959,8 +1930,7 @@ BEGIN END IF; RETURN; -END; -$function$; +END;'; select perform_test_func(); @@ -1977,14 +1947,13 @@ create function sp_id_user(a_login text) returns int language plpgsql stable -as $function$ +as $$ declare x int; begin select into x id from users where login = a_login; if found then return x; end if; return 0; -end -$function$; +end$$; insert into users values ('user1'); @@ -1995,7 +1964,7 @@ select sp_id_user('userx'); create function sp_add_user(a_login text) returns int language plpgsql -as $function$ +as $$ declare my_id_user int; begin my_id_user = sp_id_user( a_login ); @@ -2008,8 +1977,7 @@ begin RETURN -2; -- error code for insertion failure END IF; RETURN my_id_user; -end -$function$; +end$$; select sp_add_user('user1'); @@ -2035,19 +2003,19 @@ copy rc_test from stdout; create function return_unnamed_refcursor() returns refcursor language plpgsql -as $function$ +as $$ declare rc refcursor; begin open rc for select a from rc_test; return rc; end -$function$; +$$; create function use_refcursor(rc refcursor) returns int language plpgsql -as $function$ +as $$ declare rc refcursor; x record; @@ -2056,29 +2024,29 @@ begin fetch next from rc into x; return x.a; end -$function$; +$$; select use_refcursor(return_unnamed_refcursor()); create function return_refcursor(rc refcursor) returns refcursor language plpgsql -as $function$ +as $$ begin open rc for select a from rc_test; return rc; end -$function$; +$$; create function refcursor_test1(refcursor) returns refcursor language plpgsql -as $function$ +as $$ begin perform return_refcursor($1); return $1; end -$function$; +$$; begin; @@ -2097,7 +2065,7 @@ fetch next from test1; create function refcursor_test2(int, int) returns boolean language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param2 int) for select * from rc_test where a > param1 and b > param2; nonsense record; @@ -2111,7 +2079,7 @@ begin return false; end if; end -$function$; +$$; select refcursor_test2(20000, 20000) as "Should be false", @@ -2120,35 +2088,35 @@ select create function constant_refcursor() returns refcursor language plpgsql -as $function$ +as $$ declare rc constant refcursor; begin open rc for select a from rc_test; return rc; end -$function$; +$$; select constant_refcursor(); create or replace function constant_refcursor() returns refcursor language plpgsql -as $function$ +as $$ declare rc constant refcursor := 'my_cursor_name'; begin open rc for select a from rc_test; return rc; end -$function$; +$$; select constant_refcursor(); create function namedparmcursor_test1(int, int) returns boolean language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param12 int) for select * from rc_test where a > param1 and b > param12; nonsense record; @@ -2162,17 +2130,16 @@ begin return false; end if; end -$function$; +$$; select - namedparmcursor_test1(20000, 20000) - as "Should be false", + namedparmcursor_test1(20000, 20000) as "Should be false", namedparmcursor_test1(20, 20) as "Should be true"; create function namedparmcursor_test2(int, int) returns boolean language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param2 int) for select * from rc_test where a > param1 and b > param2; nonsense record; @@ -2186,74 +2153,73 @@ begin return false; end if; end -$function$; +$$; select namedparmcursor_test2(20, 20); create function namedparmcursor_test3() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param2 int) for select * from rc_test where a > param1 and b > param2; begin open c1(param2 := 20, 21); end -$function$; +$$; create function namedparmcursor_test4() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param2 int) for select * from rc_test where a > param1 and b > param2; begin open c1(20, param1 := 21); end -$function$; +$$; create function namedparmcursor_test5() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int) for select * from tenk1 where thousand = p1 and tenthous = p2; begin open c1 (p2 := 77, p2 := 42); end -$function$; +$$; create function namedparmcursor_test6() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int) for select * from tenk1 where thousand = p1 and tenthous = p2; begin open c1 (p2 := 77); end -$function$; +$$; create function namedparmcursor_test7() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int) for select * from tenk1 where thousand = p1 and tenthous = p2; begin open c1 (p2 := 77, p1 := 42/0); -end -$function$; +end $$; select namedparmcursor_test7(); create function namedparmcursor_test8() -returns int +returns int4 language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int) for select count(*) from tenk1 where thousand = p1 and tenthous = p2; @@ -2263,15 +2229,14 @@ begin , 42); fetch c1 into n; return n; -end -$function$; +end $$; select namedparmcursor_test8(); create function namedparmcursor_test9(p1 int) -returns int +returns int4 language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int, debug int) for select count(*) from tenk1 where thousand = p1 and tenthous = p2 @@ -2283,47 +2248,46 @@ begin open c1 (p1 := p1, p2 => p2, debug => 2); fetch c1 into n; return n; -end -$function$; +end $$; select namedparmcursor_test9(6); create function raise_test1(int) returns int language plpgsql -as $function$ +as $$ begin raise notice 'This message has too many parameters!', $1; return $1; end; -$function$; +$$; create function raise_test2(int) returns int language plpgsql -as $function$ +as $$ begin raise notice 'This message has too few parameters: %, %, %', $1, $1; return $1; end; -$function$; +$$; create function raise_test3(int) returns int language plpgsql -as $function$ +as $$ begin raise notice 'This message has no parameters (despite having %% signs in it)!'; return $1; end; -$function$; +$$; select raise_test3(1); create function reraise_test() returns void language plpgsql -as $function$ +as $$ BEGIN BEGIN RAISE syntax_error; @@ -2341,73 +2305,67 @@ EXCEPTION WHEN OTHERS THEN raise notice 'WRONG - exception % caught in outer block', sqlerrm; END; -$function$; +$$; select reraise_test(); create function bad_sql1() returns int language plpgsql -as $function$ +as $$ declare a int; begin a := 5; Johnny Yuma; a := 10; return a; -end -$function$; +end$$; create function bad_sql2() returns int language plpgsql -as $function$ +as $$ declare r record; begin for r in select I fought the law, the law won LOOP raise notice 'in loop'; end loop; return 5; -end; -$function$; +end;$$; create function missing_return_expr() returns int language plpgsql -as $function$ +as $$ begin return ; -end; -$function$; +end;$$; create function void_return_expr() returns void language plpgsql -as $function$ +as $$ begin return 5; -end; -$function$; +end;$$; create function void_return_expr() returns void language plpgsql -as $function$ +as $$ begin perform 2+2; -end; -$function$; +end;$$; select void_return_expr(); create function missing_return_expr() returns int language plpgsql -as $function$ +as $$ begin perform 2+2; -end; -$function$; +end;$$; select missing_return_expr(); @@ -2425,7 +2383,7 @@ create type eitype as (i int, y int); create or replace function execute_into_test(varchar) returns record language plpgsql -as $function$ +as $$ declare _r record; _rt eifoo%rowtype; @@ -2443,8 +2401,7 @@ begin raise notice '% % %', i, j, k; execute 'select 1,2' into _v; return _v; -end; -$function$; +end; $$; select execute_into_test('eifoo'); @@ -2455,33 +2412,31 @@ drop type eitype cascade; create function excpt_test1() returns void language plpgsql -as $function$ +as $$ begin raise notice '% %', sqlstate, sqlerrm; -end; -$function$; +end; $$; select excpt_test1(); create function excpt_test2() returns void language plpgsql -as $function$ +as $$ begin begin begin raise notice '% %', sqlstate, sqlerrm; end; end; -end; -$function$; +end; $$; select excpt_test2(); create function excpt_test3() returns void language plpgsql -as $function$ +as $$ begin begin raise exception 'user exception'; @@ -2499,20 +2454,18 @@ begin end; raise notice '% %', sqlstate, sqlerrm; end; -end; -$function$; +end; $$; select excpt_test3(); create function excpt_test4() returns text language plpgsql -as $function$ +as $$ begin begin perform 1/0; exception when others then return sqlerrm; end; -end; -$function$; +end; $$; select excpt_test4(); @@ -2527,7 +2480,7 @@ drop function excpt_test4(); create function raise_exprs() returns void language plpgsql -as $function$ +as $$ declare a integer[] = '{10,20,30}'; c varchar = 'xyz'; @@ -2535,25 +2488,23 @@ declare begin i := 2; raise notice '%; %; %; %; %; %', a, a[i], c, (select c || 'abc'), row(10,'aaa',NULL,30), NULL; -end; -$function$; +end;$$; select raise_exprs(); drop function raise_exprs(); create function multi_datum_use(p1 int) -returns boolean +returns bool language plpgsql -as $function$ +as $$ declare x int; y int; begin select into x,y unique1/p1, unique1/$1 from tenk1 group by unique1/p1; return x = y; -end -$function$; +end$$; select multi_datum_use(42); @@ -2567,56 +2518,52 @@ insert into foo values (1, 2), (3, 4); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should work insert into foo values(5,6) returning * into x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail due to implicit strict insert into foo values(7,8),(9,10) returning * into x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should work execute 'insert into foo values(5,6) returning *' into x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- this should work since EXECUTE isn't as picky execute 'insert into foo values(7,8),(9,10) returning *' into x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); @@ -2625,84 +2572,78 @@ select * from foo; create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should work select * from foo where f1 = 3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail, no rows select * from foo where f1 = 0 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail, too many rows select * from foo where f1 > 3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should work execute 'select * from foo where f1 = 3' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail, no rows execute 'select * from foo where f1 = 0' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail, too many rows execute 'select * from foo where f1 > 3' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); @@ -2713,7 +2654,7 @@ set plpgsql.print_strict_params = 'true'; create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; p1 int := 2; @@ -2722,15 +2663,14 @@ begin -- no rows select * from foo where f1 = p1 and f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; p1 int := 2; @@ -2739,15 +2679,14 @@ begin -- no rows select * from foo where f1 = p1 and f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; p1 int := 2; @@ -2756,71 +2695,66 @@ begin -- too many rows select * from foo where f1 > p1 or f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- too many rows, no params select * from foo where f1 > 3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- no rows execute 'select * from foo where f1 = $1 or f1::text = $2' using 0, 'foo' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- too many rows execute 'select * from foo where f1 > $1' using 1 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- too many rows, no parameters execute 'select * from foo where f1 > 3' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ -- override the global #print_strict_params off declare @@ -2831,8 +2765,7 @@ begin -- too many rows select * from foo where f1 > p1 or f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); @@ -2841,7 +2774,7 @@ reset plpgsql.print_strict_params; create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ -- override the global #print_strict_params on declare @@ -2852,18 +2785,17 @@ begin -- too many rows select * from foo where f1 > p1 or f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); set plpgsql.extra_warnings = 'all'; -set plpgsql.extra_warnings = 'none'; +set plpgsql.extra_warnings = none; set plpgsql.extra_errors = 'all'; -set plpgsql.extra_errors = 'none'; +set plpgsql.extra_errors = none; set plpgsql.extra_warnings = shadowed_variables; @@ -2872,13 +2804,13 @@ returns table ( out1 int ) language plpgsql -as $function$ +as $$ declare in1 int; out1 int; begin end -$function$; +$$; select shadowtest(1); @@ -2891,13 +2823,13 @@ returns table ( out1 int ) language plpgsql -as $function$ +as $$ declare in1 int; out1 int; begin end -$function$; +$$; select shadowtest(1); @@ -2906,7 +2838,7 @@ drop function shadowtest(int); create or replace function shadowtest() returns void language plpgsql -as $function$ +as $$ declare f1 int; begin @@ -2914,15 +2846,14 @@ begin f1 int; begin end; -end -$function$; +end$$; drop function shadowtest(); create or replace function shadowtest(in1 int) returns void language plpgsql -as $function$ +as $$ declare in1 int; begin @@ -2930,21 +2861,19 @@ begin in1 int; begin end; -end -$function$; +end$$; drop function shadowtest(int); create or replace function shadowtest() returns void language plpgsql -as $function$ +as $$ declare f1 int; c1 cursor (f1 int) for select 1; begin -end -$function$; +end$$; drop function shadowtest(); @@ -2953,9 +2882,8 @@ set plpgsql.extra_errors = shadowed_variables; create or replace function shadowtest(f1 int) returns boolean language plpgsql -as $function$ -declare f1 int; begin return 1; end -$function$; +as $$ +declare f1 int; begin return 1; end $$; select shadowtest(1); @@ -2966,31 +2894,28 @@ reset plpgsql.extra_warnings; create or replace function shadowtest(f1 int) returns boolean language plpgsql -as $function$ -declare f1 int; begin return 1; end -$function$; +as $$ +declare f1 int; begin return 1; end $$; select shadowtest(1); set plpgsql.extra_warnings = too_many_rows; -do -$do$ +do $$ declare x int; begin select v from generate_series(1,2) g(v) into x; end; -$do$; +$$; set plpgsql.extra_errors = too_many_rows; -do -$do$ +do $$ declare x int; begin select v from generate_series(1,2) g(v) into x; end; -$do$; +$$; reset plpgsql.extra_errors; @@ -2998,8 +2923,7 @@ reset plpgsql.extra_warnings; set plpgsql.extra_warnings = strict_multi_assignment; -do -$do$ +do $$ declare x int; y int; @@ -3008,12 +2932,11 @@ begin select 1,2 into x, y; select 1,2,3 into x, y; end -$do$; +$$; set plpgsql.extra_errors = strict_multi_assignment; -do -$do$ +do $$ declare x int; y int; @@ -3022,7 +2945,7 @@ begin select 1,2 into x, y; select 1,2,3 into x, y; end -$do$; +$$; create table test_01 ( a int, @@ -3035,8 +2958,7 @@ alter table test_01 insert into test_01 values (10, 20); -do -$do$ +do $$ declare x int; y int; @@ -3045,10 +2967,9 @@ begin raise notice 'ok'; select * from test_01 into x; -- should to fail end; -$do$; +$$; -do -$do$ +do $$ declare t test_01; begin @@ -3056,16 +2977,15 @@ begin raise notice 'ok'; select 1, 2, 3 into t; -- should fail; end; -$do$; +$$; -do -$do$ +do $$ declare t test_01; begin select 1 into t; -- should fail; end; -$do$; +$$; drop table test_01; @@ -3076,7 +2996,7 @@ reset plpgsql.extra_warnings; create function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c scroll cursor for select f1 from int4_tbl; x integer; @@ -3089,14 +3009,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c no scroll cursor for select f1 from int4_tbl; x integer; @@ -3109,14 +3029,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c refcursor; x integer; @@ -3129,14 +3049,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c refcursor; x integer; @@ -3149,14 +3069,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c refcursor; x integer; @@ -3170,14 +3090,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c cursor for select * from generate_series(1, 10); x integer; @@ -3195,14 +3115,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c cursor for select * from generate_series(1, 10); x integer; @@ -3215,7 +3135,7 @@ begin end if; close c; end; -$function$; +$$; select * from sc_test(); @@ -3224,7 +3144,7 @@ drop function sc_test(); create function pl_qual_names(param1 int) returns void language plpgsql -as $function$ +as $$ <> declare param1 int := 1; @@ -3239,7 +3159,7 @@ begin raise notice 'innerblock.param1 = %', innerblock.param1; end; end; -$function$; +$$; select pl_qual_names(42); @@ -3248,7 +3168,7 @@ drop function pl_qual_names(int); create function ret_query1(out int, out int) returns setof record language plpgsql -as $function$ +as $$ begin $1 := -1; $2 := -2; @@ -3256,7 +3176,7 @@ begin return query select x + 1, x * 10 from generate_series(0, 10) s (x); return next; end; -$function$; +$$; select * from ret_query1(); @@ -3265,19 +3185,19 @@ create type record_type as (x text, y int, z boolean); create or replace function ret_query2(lim int) returns setof record_type language plpgsql -as $function$ +as $$ begin return query select fipshash(s.x::text), s.x, s.x > 0 from generate_series(-8, lim) s (x) where s.x % 2 = 0; end; -$function$; +$$; select * from ret_query2(8); create function exc_using(int, text) returns int language plpgsql -as $function$ +as $$ declare i int; begin for i in execute 'select * from generate_series(1,$1)' using $1+1 loop @@ -3286,7 +3206,7 @@ begin execute 'select $2 + $2*3 + length($1)' into i using $2,$1; return i; end -$function$; +$$; select exc_using(5, 'foobar'); @@ -3295,7 +3215,7 @@ drop function exc_using(int, text); create or replace function exc_using(int) returns void language plpgsql -as $function$ +as $$ declare c refcursor; i int; @@ -3309,7 +3229,7 @@ begin close c; return; end; -$function$; +$$; select exc_using(5); @@ -3318,7 +3238,7 @@ drop function exc_using(int); create or replace function forc01() returns void language plpgsql -as $function$ +as $$ declare c cursor(r1 integer, r2 integer) for select * from generate_series(r1,r2) i; @@ -3356,7 +3276,7 @@ begin raise notice 'after loop, c2 = %', c2; return; end; -$function$; +$$; select forc01(); @@ -3365,7 +3285,7 @@ create temporary table forc_test as select n as i, n as j from generate_series(1 create or replace function forc01() returns void language plpgsql -as $function$ +as $$ declare c cursor for select * from forc_test; begin @@ -3374,7 +3294,7 @@ begin update forc_test set i = i * 100, j = r.j * 2 where current of c; end loop; end; -$function$; +$$; select forc01(); @@ -3383,7 +3303,7 @@ select * from forc_test; create or replace function forc01() returns void language plpgsql -as $function$ +as $$ declare c refcursor := 'fooled_ya'; r record; @@ -3396,7 +3316,7 @@ begin update forc_test set i = i * 100, j = r.j * 2 where current of c; end loop; end; -$function$; +$$; select forc01(); @@ -3404,8 +3324,7 @@ select * from forc_test; drop function forc01(); -do -$do$ +do $$ declare cnt int := 0; c1 cursor for select * from forc_test; begin @@ -3418,13 +3337,12 @@ begin end; end loop; raise notice 'cnt = %', cnt; -end -$do$; +end $$; create or replace function forc_bad() returns void language plpgsql -as $function$ +as $$ declare c refcursor; begin @@ -3432,17 +3350,17 @@ begin raise notice '%', r.i; end loop; end; -$function$; +$$; create or replace function return_dquery() returns setof int language plpgsql -as $function$ +as $$ begin return query execute 'select * from (values(10),(20)) f'; return query execute 'select * from (values($1),($2)) f' using 40,50; end; -$function$; +$$; select * from return_dquery(); @@ -3460,12 +3378,12 @@ insert into tabwithcols values (10, 20, 30, 40), (50, 60, 70, 80); create or replace function returnqueryf() returns setof tabwithcols language plpgsql -as $function$ +as $$ begin return query select * from tabwithcols; return query execute 'select * from tabwithcols'; end; -$function$; +$$; select * from returnqueryf(); @@ -3493,61 +3411,61 @@ create type compostype as (x int, y varchar); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ declare v compostype; begin v := (1, 'hello'); return v; end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ declare v record; begin v := (1, 'hello'::varchar); return v; end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ begin return (1, 'hello'::varchar); end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ begin return (1, 'hello'); end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ begin return (1, 'hello')::compostype; end; -$function$; +$$; select compos(); @@ -3556,25 +3474,25 @@ drop function compos(); create or replace function composrec() returns record language plpgsql -as $function$ +as $$ declare v record; begin v := (1, 'hello'); return v; end; -$function$; +$$; select composrec(); create or replace function composrec() returns record language plpgsql -as $function$ +as $$ begin return (1, 'hello'); end; -$function$; +$$; select composrec(); @@ -3583,7 +3501,7 @@ drop function composrec(); create or replace function compos() returns setof compostype language plpgsql -as $function$ +as $$ begin for i in 1..3 loop @@ -3592,7 +3510,7 @@ begin return next null::compostype; return next (2, 'goodbye')::compostype; end; -$function$; +$$; select * from compos(); @@ -3601,23 +3519,23 @@ drop function compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ begin return 1 + 1; end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ declare x int := 42; begin return x; end; -$function$; +$$; select * from compos(); @@ -3626,25 +3544,25 @@ drop function compos(); create or replace function compos() returns int language plpgsql -as $function$ +as $$ declare v compostype; begin v := (1, 'hello'); return v; end; -$function$; +$$; select compos(); create or replace function compos() returns int language plpgsql -as $function$ +as $$ begin return (1, 'hello')::compostype; end; -$function$; +$$; select compos(); @@ -3655,21 +3573,21 @@ drop type compostype; create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise notice '% % %', 1, 2, 3 using errcode = '55001', detail = 'some detail info', hint = 'some hint'; raise '% % %', 1, 2, 3 using errcode = 'division_by_zero', detail = 'some detail info'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise 'check me' using errcode = 'division_by_zero', detail = 'some detail info'; @@ -3678,14 +3596,14 @@ begin raise notice 'SQLSTATE: % SQLERRM: %', sqlstate, sqlerrm; raise; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise 'check me' using errcode = '1234F', detail = 'some detail info'; @@ -3694,14 +3612,14 @@ begin raise notice 'SQLSTATE: % SQLERRM: %', sqlstate, sqlerrm; raise; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise 'check me' using errcode = '1234F', detail = 'some detail info'; @@ -3710,14 +3628,14 @@ begin raise notice 'SQLSTATE: % SQLERRM: %', sqlstate, sqlerrm; raise; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise division_by_zero using detail = 'some detail info'; exception @@ -3725,113 +3643,113 @@ begin raise notice 'SQLSTATE: % SQLERRM: %', sqlstate, sqlerrm; raise; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise division_by_zero; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise sqlstate '1234F'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise division_by_zero using message = 'custom' || ' message'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise using message = 'custom' || ' message', errcode = '22012'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise notice 'some message' using message = 'custom' || ' message', errcode = '22012'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise division_by_zero using message = 'custom' || ' message', errcode = '22012'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise; end; -$function$; +$$; select raise_test(); create function zero_divide() returns int language plpgsql -parallel SAFE -as $function$ +parallel safe +as $$ declare v int := 0; begin return 10 / v; end; -$function$; +$$; create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise exception 'custom exception' using detail = 'some detail of custom exception', hint = 'some hint related to custom exception'; end; -$function$; +$$; create function stacked_diagnostics_test() returns void language plpgsql -as $function$ +as $$ declare _sqlstate text; _message text; _context text; @@ -3845,14 +3763,14 @@ exception when others then raise notice 'sqlstate: %, message: %, context: [%]', _sqlstate, _message, replace(_context, E'\n', ' <- '); end; -$function$; +$$; select stacked_diagnostics_test(); create or replace function stacked_diagnostics_test() returns void language plpgsql -as $function$ +as $$ declare _detail text; _hint text; _message text; @@ -3865,14 +3783,14 @@ exception when others then _hint = pg_exception_hint; raise notice 'message: %, detail: %, hint: %', _message, _detail, _hint; end; -$function$; +$$; select stacked_diagnostics_test(); create or replace function stacked_diagnostics_test() returns void language plpgsql -as $function$ +as $$ declare _detail text; _hint text; _message text; @@ -3883,7 +3801,7 @@ begin _hint = pg_exception_hint; raise notice 'message: %, detail: %, hint: %', _message, _detail, _hint; end; -$function$; +$$; select stacked_diagnostics_test(); @@ -3892,15 +3810,15 @@ drop function stacked_diagnostics_test(); create function error_trap_test() returns text language plpgsql -parallel SAFE -as $function$ +parallel safe +as $$ begin perform zero_divide(); return 'no error detected!'; exception when division_by_zero then return 'division_by_zero detected'; end; -$function$; +$$; set debug_parallel_query = 'on'; @@ -3917,7 +3835,7 @@ drop function zero_divide(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin perform 1/0; exception @@ -3925,7 +3843,7 @@ exception raise notice using message = sqlstate; raise sqlstate '22012' using message = 'substitute message'; end; -$function$; +$$; select raise_test(); @@ -3934,7 +3852,7 @@ drop function raise_test(); create or replace function stacked_diagnostics_test() returns void language plpgsql -as $function$ +as $$ declare _column_name text; _constraint_name text; _datatype_name text; @@ -3957,7 +3875,7 @@ exception when others then raise notice 'column %, constraint %, type %, table %, schema %', _column_name, _constraint_name, _datatype_name, _table_name, _schema_name; end; -$function$; +$$; select stacked_diagnostics_test(); @@ -3966,12 +3884,12 @@ drop function stacked_diagnostics_test(); create or replace function vari(variadic int[]) returns void language plpgsql -as $function$ +as $$ begin for i in array_lower($1,1)..array_upper($1,1) loop raise notice '%', $1[i]; end loop; end; -$function$; +$$; select vari(1, 2, 3, 4, 5); @@ -3986,7 +3904,7 @@ returns numeric language plpgsql immutable strict -as $function$ +as $$ declare aux numeric = $1[array_lower($1,1)]; begin for i in array_lower($1,1)+1..array_upper($1,1) loop @@ -3994,7 +3912,7 @@ begin end loop; return aux; end; -$function$; +$$; select pleast(10, 1, 2, 3, -16); @@ -4009,12 +3927,12 @@ returns numeric language plpgsql immutable strict -as $function$ +as $$ begin raise notice 'non-variadic function called'; return $1; end; -$function$; +$$; select pleast(10); @@ -4030,11 +3948,11 @@ returns table ( language plpgsql immutable strict -as $function$ +as $$ begin return query select $1, $1+i from generate_series(1,5) g(i); end; -$function$; +$$; select * from tftest(10); @@ -4046,14 +3964,14 @@ returns table ( language plpgsql immutable strict -as $function$ +as $$ begin a := a1; b := a1 + 1; return next; a := a1 * 10; b := a1 * 10 + 1; return next; end; -$function$; +$$; select * from tftest(10); @@ -4062,7 +3980,7 @@ drop function tftest(int); create function rttest() returns setof int language plpgsql -as $function$ +as $$ declare rc int; begin return query values(10),(20); @@ -4078,29 +3996,29 @@ begin get diagnostics rc = row_count; raise notice '% %', found, rc; end; -$function$; +$$; select * from rttest(); create or replace function rttest() returns setof int language plpgsql -as $function$ +as $$ begin return query select 10 into no_such_table; end; -$function$; +$$; select * from rttest(); create or replace function rttest() returns setof int language plpgsql -as $function$ +as $$ begin return query execute 'select 10 into no_such_table'; end; -$function$; +$$; select * from rttest(); @@ -4108,10 +4026,10 @@ select * from no_such_table; drop function rttest(); -create function leaker_1(fail boolean) +create function leaker_1(fail bool) returns int language plpgsql -as $function$ +as $$ DECLARE v_var INTEGER; BEGIN @@ -4122,12 +4040,12 @@ BEGIN END; RETURN 1; END; -$function$; +$$; -create function leaker_2(fail boolean, out error_code int, out new_id int) +create function leaker_2(fail bool, out error_code int, out new_id int) returns record language plpgsql -as $function$ +as $$ BEGIN IF fail THEN RAISE EXCEPTION 'fail ...'; @@ -4136,20 +4054,20 @@ BEGIN new_id := 1; RETURN; END; -$function$; +$$; select * from leaker_1(false); select * from leaker_1(true); -drop function leaker_1(boolean); +drop function leaker_1(bool); -drop function leaker_2(boolean); +drop function leaker_2(bool); create function nonsimple_expr_test() returns text[] language plpgsql -as $function$ +as $$ DECLARE arr text[]; lr text; @@ -4162,7 +4080,7 @@ BEGIN arr[(SELECT i)][(SELECT i+1)] := (SELECT lr); RETURN arr; END; -$function$; +$$; select nonsimple_expr_test(); @@ -4171,7 +4089,7 @@ drop function nonsimple_expr_test(); create function nonsimple_expr_test() returns int language plpgsql -as $function$ +as $$ declare i integer NOT NULL := 0; begin @@ -4183,16 +4101,16 @@ begin end; return i; end; -$function$; +$$; select nonsimple_expr_test(); drop function nonsimple_expr_test(); -create function recurse(double precision) -returns double precision +create function recurse(float8) +returns float8 language plpgsql -as $function$ +as $$ begin if ($1 > 0) then return sql_recurse($1 - 1); @@ -4200,32 +4118,27 @@ begin return $1; end if; end; -$function$; +$$; -create function sql_recurse(double precision) -returns double precision +create function sql_recurse(float8) +returns float8 language sql -as $function$ -select recurse($1) limit 1; -$function$; +as $$ select recurse($1) limit 1; $$; select recurse(10); create function error1(text) returns text language sql -as $function$ -SELECT relname::text FROM pg_class c WHERE c.oid = $1::regclass -$function$; +as $$ SELECT relname::text FROM pg_class c WHERE c.oid = $1::regclass $$; create function error2(p_name_table text) returns text language plpgsql -as $function$ +as $$ begin return error1(p_name_table); -end -$function$; +end$$; begin; @@ -4241,7 +4154,7 @@ select error2('public.stuffs'); rollback; -drop function error2(text); +drop function error2(p_name_table text); drop function error1(text); @@ -4250,20 +4163,19 @@ returns date language sql immutable strict -as $function$ +as $$ select $1::text::date -$function$; +$$; create cast (int as date) with function sql_to_date(int) as assignment; create function cast_invoker(int) returns date language plpgsql -as $function$ +as $$ begin return $1; -end -$function$; +end$$; select cast_invoker(20150717); @@ -4295,26 +4207,20 @@ drop function sql_to_date(int) cascade; begin; -do -$do$ -declare x text[]; begin x := '{1.23, 4.56}'::numeric[]; end -$do$; +do $$ declare x text[]; begin x := '{1.23, 4.56}'::numeric[]; end $$; -do -$do$ -declare x text[]; begin x := '{1.23, 4.56}'::numeric[]; end -$do$; +do $$ declare x text[]; begin x := '{1.23, 4.56}'::numeric[]; end $$; commit; create function fail() returns int language plpgsql -as $function$ +as $$ begin return 1/0; end -$function$; +$$; select fail(); @@ -4327,24 +4233,24 @@ set standard_conforming_strings = off; create or replace function strtest() returns text language plpgsql -as $function$ +as $$ begin raise notice 'foo\\bar\041baz'; return 'foo\\bar\041baz'; end -$function$; +$$; select strtest(); create or replace function strtest() returns text language plpgsql -as $function$ +as $$ begin raise notice E'foo\\bar\041baz'; return E'foo\\bar\041baz'; end -$function$; +$$; select strtest(); @@ -4353,59 +4259,50 @@ set standard_conforming_strings = 'on'; create or replace function strtest() returns text language plpgsql -as $function$ +as $$ begin raise notice 'foo\\bar\041baz\'; return 'foo\\bar\041baz\'; end -$function$; +$$; select strtest(); create or replace function strtest() returns text language plpgsql -as $function$ +as $$ begin raise notice E'foo\\bar\041baz'; return E'foo\\bar\041baz'; end -$function$; +$$; select strtest(); drop function strtest(); -do -$do$ +do $$ DECLARE r record; BEGIN FOR r IN SELECT rtrim(roomno) AS roomno, comment FROM Room ORDER BY roomno LOOP RAISE NOTICE '%, %', r.roomno, r.comment; END LOOP; -END -$do$; +END$$; -do -language plpgsql -$do$ -begin return 1; end -$do$; +do language plpgsql $$begin return 1; end$$; -do -$do$ +do $$ DECLARE r record; BEGIN FOR r IN SELECT rtrim(roomno) AS roomno, foo FROM Room ORDER BY roomno LOOP RAISE NOTICE '%, %', r.roomno, r.comment; END LOOP; -END -$do$; +END$$; -do -$do$ +do $outer$ begin for i in 1..10 loop begin @@ -4422,36 +4319,32 @@ begin end; end loop; end; -$do$; +$outer$; -do -$do$ +do $$ declare x int := x + 1; -- error begin raise notice 'x = %', x; end; -$do$; +$$; -do -$do$ +do $$ declare y int := x + 1; -- error x int := 42; begin raise notice 'x = %, y = %', x, y; end; -$do$; +$$; -do -$do$ +do $$ declare x int := 42; y int := x + 1; begin raise notice 'x = %, y = %', x, y; end; -$do$; +$$; -do -$do$ +do $$ declare x int := 42; begin declare y int := x + 1; @@ -4461,14 +4354,14 @@ begin raise notice 'x = %, y = %, z = %', x, y, z; end; end; -$do$; +$$; set plpgsql.variable_conflict = error; create function conflict_test() returns setof int8_tbl language plpgsql -as $function$ +as $$ declare r record; q1 bigint := 42; begin @@ -4476,14 +4369,14 @@ begin return next r; end loop; end; -$function$; +$$; select * from conflict_test(); create or replace function conflict_test() returns setof int8_tbl language plpgsql -as $function$ +as $$ #variable_conflict use_variable declare r record; q1 bigint := 42; @@ -4492,14 +4385,14 @@ begin return next r; end loop; end; -$function$; +$$; select * from conflict_test(); create or replace function conflict_test() returns setof int8_tbl language plpgsql -as $function$ +as $$ #variable_conflict use_column declare r record; q1 bigint := 42; @@ -4508,7 +4401,7 @@ begin return next r; end loop; end; -$function$; +$$; select * from conflict_test(); @@ -4517,35 +4410,35 @@ drop function conflict_test(); create function unreserved_test() returns int language plpgsql -as $function$ +as $$ declare forward int := 21; begin forward := forward * 2; return forward; end -$function$; +$$; select unreserved_test(); create or replace function unreserved_test() returns int language plpgsql -as $function$ +as $$ declare return int := 42; begin return := return + 1; return return; end -$function$; +$$; select unreserved_test(); create or replace function unreserved_test() returns int language plpgsql -as $function$ +as $$ declare comment int := 21; begin @@ -4553,7 +4446,7 @@ begin comment on function unreserved_test() is 'this is a test'; return comment; end -$function$; +$$; select unreserved_test(); @@ -4564,7 +4457,7 @@ drop function unreserved_test(); create function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int; begin foreach x in array $1 @@ -4572,7 +4465,7 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(array[1, 2, 3, 4]); @@ -4581,7 +4474,7 @@ select foreach_test(array[array[1, 2], array[3, 4]]); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int; begin foreach x slice 1 in array $1 @@ -4589,7 +4482,7 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(array[1, 2, 3, 4]); @@ -4598,7 +4491,7 @@ select foreach_test(array[array[1, 2], array[3, 4]]); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int[]; begin foreach x slice 1 in array $1 @@ -4606,7 +4499,7 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(array[1, 2, 3, 4]); @@ -4615,7 +4508,7 @@ select foreach_test(array[array[1, 2], array[3, 4]]); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int[]; begin foreach x slice 2 in array $1 @@ -4623,7 +4516,7 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(array[1, 2, 3, 4]); @@ -4636,7 +4529,7 @@ create type xy_tuple as (x int, y int); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare r record; begin foreach r in array $1 @@ -4644,21 +4537,17 @@ begin raise notice '%', r; end loop; end; -$function$; +$$; select foreach_test(cast(array[(10, 20), (40, 69), (35, 78)] as xy_tuple[])); select - foreach_test( - cast(array[array[(10, 20), (40, 69)], - array[(35, 78), (88, 76)]] - as xy_tuple[]) - ); + foreach_test(cast(array[array[(10, 20), (40, 69)], array[(35, 78), (88, 76)]] as xy_tuple[])); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int; y int; begin foreach x, y in array $1 @@ -4666,21 +4555,17 @@ begin raise notice 'x = %, y = %', x, y; end loop; end; -$function$; +$$; select foreach_test(cast(array[(10, 20), (40, 69), (35, 78)] as xy_tuple[])); select - foreach_test( - cast(array[array[(10, 20), (40, 69)], - array[(35, 78), (88, 76)]] - as xy_tuple[]) - ); + foreach_test(cast(array[array[(10, 20), (40, 69)], array[(35, 78), (88, 76)]] as xy_tuple[])); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x xy_tuple[]; begin foreach x slice 1 in array $1 @@ -4688,16 +4573,12 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(cast(array[(10, 20), (40, 69), (35, 78)] as xy_tuple[])); select - foreach_test( - cast(array[array[(10, 20), (40, 69)], - array[(35, 78), (88, 76)]] - as xy_tuple[]) - ); + foreach_test(cast(array[array[(10, 20), (40, 69)], array[(35, 78), (88, 76)]] as xy_tuple[])); drop function foreach_test(anyarray); @@ -4711,21 +4592,20 @@ create temporary table rtype ( create function arrayassign1() returns text[] language plpgsql -as $function$ +as $$ declare r record; begin r := row(12, '{foo,bar,baz}')::rtype; r.ar[2] := 'replace'; return r.ar; -end -$function$; +end$$; select arrayassign1(); select arrayassign1(); -create domain orderedarray as int[2] constraint "sorted" check (value[1] < value[2]); +create domain orderedarray as int[2] constraint sorted check (value[1] < value[2]); select cast('{1,2}' as orderedarray); @@ -4734,14 +4614,13 @@ select cast('{2,1}' as orderedarray); create function testoa(x1 int, x2 int, x3 int) returns orderedarray language plpgsql -as $function$ +as $$ declare res orderedarray; begin res := array[x1, x2]; res[2] := x3; return res; -end -$function$; +end$$; select testoa(1, 2, 3); @@ -4753,24 +4632,24 @@ select testoa(1, 2, 1); drop function arrayassign1(); -drop function testoa(int, int, int); +drop function testoa(x1 int, x2 int, x3 int); create function returns_rw_array(int) returns int[] language plpgsql stable -as $function$ -declare r int[]; +as $$ + declare r int[]; begin r := array[$1, $1]; return r; end; -$function$; +$$; create function consumes_rw_array(int[]) returns int language plpgsql stable -as $function$ -begin return $1[1]; end; -$function$; +as $$ + begin return $1[1]; end; +$$; select consumes_rw_array(returns_rw_array(42)); @@ -4796,19 +4675,17 @@ select consumes_rw_array(a), a from (values (returns_rw_array(1)), (returns_rw_a select consumes_rw_array(a), a from (values (returns_rw_array(1)), (returns_rw_array(2))) as v (a); -do -$do$ +do $$ declare a int[] := array[1,2]; begin a := a || 3; raise notice 'a = %', a; -end -$do$; +end$$; create function inner_func(int) returns int language plpgsql -as $function$ +as $$ declare _context text; begin get diagnostics _context = pg_context; @@ -4819,12 +4696,12 @@ begin raise notice 'lets make sure we didnt break anything'; return 2 * $1; end; -$function$; +$$; create or replace function outer_func(int) returns int language plpgsql -as $function$ +as $$ declare myresult int; begin @@ -4833,12 +4710,12 @@ begin raise notice 'inner_func() done'; return myresult; end; -$function$; +$$; create or replace function outer_outer_func(int) returns int language plpgsql -as $function$ +as $$ declare myresult int; begin @@ -4847,7 +4724,7 @@ begin raise notice 'outer_func() done'; return myresult; end; -$function$; +$$; select outer_outer_func(10); @@ -4862,7 +4739,7 @@ drop function inner_func(int); create function inner_func(int) returns int language plpgsql -as $function$ +as $$ declare _context text; sx int := 5; @@ -4881,12 +4758,12 @@ begin raise notice 'lets make sure we didnt break anything'; return 2 * $1; end; -$function$; +$$; create or replace function outer_func(int) returns int language plpgsql -as $function$ +as $$ declare myresult int; begin @@ -4895,12 +4772,12 @@ begin raise notice 'inner_func() done'; return myresult; end; -$function$; +$$; create or replace function outer_outer_func(int) returns int language plpgsql -as $function$ +as $$ declare myresult int; begin @@ -4909,7 +4786,7 @@ begin raise notice 'outer_func() done'; return myresult; end; -$function$; +$$; select outer_outer_func(10); @@ -4924,130 +4801,119 @@ drop function inner_func(int); create function current_function(text) returns regprocedure language plpgsql -as $function$ +as $$ declare fn_oid regprocedure; begin get diagnostics fn_oid = pg_routine_oid; return fn_oid; end; -$function$; +$$; select current_function('foo'); drop function current_function(text); -do -$do$ +do $$ declare fn_oid oid; begin get diagnostics fn_oid = pg_routine_oid; raise notice 'pg_routine_oid = %', fn_oid; end; -$do$; +$$; -do -$do$ +do $$ begin assert 1=1; -- should succeed end; -$do$; +$$; -do -$do$ +do $$ begin assert 1=0; -- should fail end; -$do$; +$$; -do -$do$ +do $$ begin assert NULL; -- should fail end; -$do$; +$$; set plpgsql.check_asserts = off; -do -$do$ +do $$ begin assert 1=0; -- won't be tested end; -$do$; +$$; reset plpgsql.check_asserts; -do -$do$ +do $$ declare var text := 'some value'; begin assert 1=0, format('assertion failed, var = "%s"', var); end; -$do$; +$$; -do -$do$ +do $$ begin assert 1=0, 'unhandled assertion'; exception when others then null; -- do nothing end; -$do$; +$$; create function plpgsql_domain_check(val int) returns boolean language plpgsql immutable -as $function$ +as $$ begin return val > 0; end -$function$; +$$; create domain plpgsql_domain as int check (plpgsql_domain_check(value)); -do -$do$ +do $$ declare v_test plpgsql_domain; begin v_test := 1; end; -$do$; +$$; -do -$do$ +do $$ declare v_test plpgsql_domain := 1; begin v_test := 0; -- fail end; -$do$; +$$; create function plpgsql_arr_domain_check(val int[]) returns boolean language plpgsql immutable -as $function$ +as $$ begin return val[1] > 0; end -$function$; +$$; create domain plpgsql_arr_domain as int[] check (plpgsql_arr_domain_check(value)); -do -$do$ +do $$ declare v_test plpgsql_arr_domain; begin v_test := array[1]; v_test := v_test || 2; end; -$do$; +$$; -do -$do$ +do $$ declare v_test plpgsql_arr_domain := array[1]; begin v_test := 0 || v_test; -- fail end; -$do$; +$$; create table transition_table_base ( id int primary key, @@ -5057,7 +4923,7 @@ create table transition_table_base ( create function transition_table_base_ins_func() returns trigger language plpgsql -as $function$ +as $$ DECLARE t text; l text; @@ -5074,7 +4940,7 @@ BEGIN RAISE INFO '%', t; RETURN new; END; -$function$; +$$; create trigger transition_table_base_ins_trig after insert @@ -5098,7 +4964,7 @@ insert into transition_table_base values (3, 'Three'), (4, 'Four'); create or replace function transition_table_base_upd_func() returns trigger language plpgsql -as $function$ +as $$ DECLARE t text; l text; @@ -5115,7 +4981,7 @@ BEGIN RAISE INFO '%', t; RETURN new; END; -$function$; +$$; create trigger transition_table_base_upd_trig after update @@ -5150,8 +5016,8 @@ create table transition_table_status ( create function transition_table_level1_ri_parent_del_func() returns trigger language plpgsql -as $function$ -DECLARE n bigint; +as $$ + DECLARE n bigint; BEGIN PERFORM FROM p JOIN transition_table_level2 c ON c.parent_no = p.level1_no; IF FOUND THEN @@ -5159,7 +5025,7 @@ DECLARE n bigint; END IF; RETURN NULL; END; -$function$; +$$; create trigger transition_table_level1_ri_parent_del_trigger after delete @@ -5171,8 +5037,8 @@ execute function transition_table_level1_ri_parent_del_func(); create function transition_table_level1_ri_parent_upd_func() returns trigger language plpgsql -as $function$ -DECLARE +as $$ + DECLARE x int; BEGIN WITH p AS (SELECT level1_no, sum(delta) cnt @@ -5189,7 +5055,7 @@ DECLARE END IF; RETURN NULL; END; -$function$; +$$; create trigger transition_table_level1_ri_parent_upd_trigger after update @@ -5202,8 +5068,8 @@ execute function transition_table_level1_ri_parent_upd_func(); create function transition_table_level2_ri_child_insupd_func() returns trigger language plpgsql -as $function$ -BEGIN +as $$ + BEGIN PERFORM FROM i LEFT JOIN transition_table_level1 p ON p.level1_no IS NOT NULL AND p.level1_no = i.parent_no @@ -5213,7 +5079,7 @@ BEGIN END IF; RETURN NULL; END; -$function$; +$$; create trigger transition_table_level2_ri_child_ins_trigger after insert @@ -5234,29 +5100,15 @@ insert into transition_table_level1 (level1_no) select generate_series(1, 200); analyze transition_table_level1; insert into transition_table_level2 (level2_no, parent_no) -select - level2_no, - level2_no / 50 + 1 as parent_no -from - generate_series(1, 9999) as level2_no; +select level2_no, level2_no / 50 + 1 as parent_no from generate_series(1, 9999) as level2_no; analyze transition_table_level2; insert into transition_table_status (level, node_no, status) -select - 1, - level1_no, - 0 -from - transition_table_level1; +select 1, level1_no, 0 from transition_table_level1; insert into transition_table_status (level, node_no, status) -select - 2, - level2_no, - 0 -from - transition_table_level2; +select 2, level2_no, 0 from transition_table_level2; analyze transition_table_status; @@ -5267,12 +5119,12 @@ analyze transition_table_level1; create function transition_table_level2_bad_usage_func() returns trigger language plpgsql -as $function$ -BEGIN +as $$ + BEGIN INSERT INTO dx VALUES (1000000, 1000000, 'x'); RETURN NULL; END; -$function$; +$$; create trigger transition_table_level2_bad_usage_trigger after delete @@ -5297,11 +5149,11 @@ delete from transition_table_level1 where level1_no between 201 and 1000; delete from transition_table_level1 where level1_no between 100000000 and 100000010; -select COUNT(*) from transition_table_level1; +select count(*) from transition_table_level1; delete from transition_table_level2 where level2_no between 211 and 220; -select COUNT(*) from transition_table_level2; +select count(*) from transition_table_level2; create table alter_table_under_transition_tables ( id int primary key, @@ -5311,7 +5163,7 @@ create table alter_table_under_transition_tables ( create function alter_table_under_transition_tables_upd_func() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE WARNING 'old table = %, new table = %', (SELECT string_agg(id || '=' || name, ',') FROM d), @@ -5319,7 +5171,7 @@ BEGIN RAISE NOTICE 'one = %', (SELECT 1 FROM alter_table_under_transition_tables LIMIT 1); RETURN NULL; END; -$function$; +$$; create trigger alter_table_under_transition_tables_upd_trigger after update or truncate @@ -5345,8 +5197,7 @@ alter table alter_table_under_transition_tables alter column name type int using cast(name as int); update alter_table_under_transition_tables -set name = cast(cast(name as text) || cast(name as text) -as int); +set name = cast(cast(name as text) || cast(name as text) as int); alter table alter_table_under_transition_tables drop column name; @@ -5360,15 +5211,14 @@ insert into multi_test values (1); create or replace function multi_test_trig() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'count = %', (SELECT COUNT(*) FROM new_test); RAISE NOTICE 'count union = %', (SELECT COUNT(*) FROM (SELECT * FROM new_test UNION ALL SELECT * FROM new_test) ss); RETURN NULL; -END -$function$; +END$$; create trigger my_trigger after update @@ -5388,7 +5238,7 @@ create table partitioned_table ( a int, b text ) -partition by LIST(a); +partition by list(a); create table pt_part1 partition of partitioned_table for values in (1); @@ -5401,7 +5251,7 @@ insert into partitioned_table values (2, 'Row 2'); create or replace function get_from_partitioned_table(partitioned_table.a%type) returns partitioned_table language plpgsql -as $function$ +as $$ DECLARE a_val partitioned_table.a%TYPE; result partitioned_table%ROWTYPE; @@ -5409,15 +5259,14 @@ BEGIN a_val := $1; SELECT * INTO result FROM partitioned_table WHERE a = a_val; RETURN result; -END; -$function$; +END; $$; select * from get_from_partitioned_table(1) as t; create or replace function list_partitioned_table() returns setof public.partitioned_table.a%type language plpgsql -as $function$ +as $$ DECLARE row public.partitioned_table%ROWTYPE; a_val public.partitioned_table.a%TYPE; @@ -5427,17 +5276,15 @@ BEGIN RETURN NEXT a_val; END LOOP; RETURN; -END; -$function$; +END; $$; select * from list_partitioned_table() as t; create function fx(x wslot) returns void language plpgsql -as $function$ +as $$ BEGIN GET DIAGNOSTICS x = ROW_COUNT; RETURN; -END; -$function$; +END; $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_80.snap index 55fda594e..59d769503 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_80.snap @@ -7,7 +7,7 @@ create table room ( comment text ); -create unique index "room_rno" on room using btree (roomno bpchar_ops); +create unique index room_rno on room using btree (roomno bpchar_ops); create table wslot ( slotname char(20), @@ -16,14 +16,14 @@ create table wslot ( backlink char(20) ); -create unique index "wslot_name" on wslot using btree (slotname bpchar_ops); +create unique index wslot_name on wslot using btree (slotname bpchar_ops); create table pfield ( name text, comment text ); -create unique index "pfield_name" on pfield using btree (name text_ops); +create unique index pfield_name on pfield using btree (name text_ops); create table pslot ( slotname char(20), @@ -32,7 +32,7 @@ create table pslot ( backlink char(20) ); -create unique index "pslot_name" on pslot using btree (slotname bpchar_ops); +create unique index pslot_name on pslot using btree (slotname bpchar_ops); create table pline ( slotname char(20), @@ -41,7 +41,7 @@ create table pline ( backlink char(20) ); -create unique index "pline_name" on pline using btree (slotname bpchar_ops); +create unique index pline_name on pline using btree (slotname bpchar_ops); create table hub ( name char(14), @@ -49,7 +49,7 @@ create table hub ( nslots int ); -create unique index "hub_name" on hub using btree (name bpchar_ops); +create unique index hub_name on hub using btree (name bpchar_ops); create table hslot ( slotname char(20), @@ -58,16 +58,16 @@ create table hslot ( slotlink char(20) ); -create unique index "hslot_name" on hslot using btree (slotname bpchar_ops); +create unique index hslot_name on hslot using btree (slotname bpchar_ops); -create index "hslot_hubname" on hslot using btree (hubname bpchar_ops); +create index hslot_hubname on hslot using btree (hubname bpchar_ops); create table system ( name text, comment text ); -create unique index "system_name" on system using btree (name text_ops); +create unique index system_name on system using btree (name text_ops); create table iface ( slotname char(20), @@ -76,7 +76,7 @@ create table iface ( slotlink char(20) ); -create unique index "iface_name" on iface using btree (slotname bpchar_ops); +create unique index iface_name on iface using btree (slotname bpchar_ops); create table phone ( slotname char(20), @@ -84,19 +84,19 @@ create table phone ( slotlink char(20) ); -create unique index "phone_name" on phone using btree (slotname bpchar_ops); +create unique index phone_name on phone using btree (slotname bpchar_ops); create function tg_room_au() returns trigger language plpgsql -as $function$ +as ' begin if new.roomno != old.roomno then update WSlot set roomno = new.roomno where roomno = old.roomno; end if; return new; end; -$function$; +'; create trigger tg_room_au after update @@ -107,12 +107,12 @@ execute function tg_room_au(); create function tg_room_ad() returns trigger language plpgsql -as $function$ +as ' begin delete from WSlot where roomno = old.roomno; return old; end; -$function$; +'; create trigger tg_room_ad after delete @@ -123,14 +123,14 @@ execute function tg_room_ad(); create function tg_wslot_biu() returns trigger language plpgsql -as $function$ +as $$ begin if count(*) = 0 from Room where roomno = new.roomno then raise exception 'Room % does not exist', new.roomno; end if; return new; end; -$function$; +$$; create trigger tg_wslot_biu before insert or update @@ -141,14 +141,14 @@ execute function tg_wslot_biu(); create function tg_pfield_au() returns trigger language plpgsql -as $function$ +as ' begin if new.name != old.name then update PSlot set pfname = new.name where pfname = old.name; end if; return new; end; -$function$; +'; create trigger tg_pfield_au after update @@ -159,12 +159,12 @@ execute function tg_pfield_au(); create function tg_pfield_ad() returns trigger language plpgsql -as $function$ +as ' begin delete from PSlot where pfname = old.name; return old; end; -$function$; +'; create trigger tg_pfield_ad after delete @@ -175,7 +175,7 @@ execute function tg_pfield_ad(); create function tg_pslot_biu() returns trigger language plpgsql -as $function$ +as $proc$ declare pfrec record; ps alias for new; @@ -186,7 +186,7 @@ begin end if; return ps; end; -$function$; +$proc$; create trigger tg_pslot_biu before insert or update @@ -197,14 +197,14 @@ execute function tg_pslot_biu(); create function tg_system_au() returns trigger language plpgsql -as $function$ +as ' begin if new.name != old.name then update IFace set sysname = new.name where sysname = old.name; end if; return new; end; -$function$; +'; create trigger tg_system_au after update @@ -215,7 +215,7 @@ execute function tg_system_au(); create function tg_iface_biu() returns trigger language plpgsql -as $function$ +as $$ declare sname text; sysrec record; @@ -233,7 +233,7 @@ begin new.slotname := sname; return new; end; -$function$; +$$; create trigger tg_iface_biu before insert or update @@ -244,28 +244,28 @@ execute function tg_iface_biu(); create function tg_hub_a() returns trigger language plpgsql -as $function$ +as ' declare hname text; dummy integer; begin - if tg_op = 'INSERT' then + if tg_op = ''INSERT'' then dummy := tg_hub_adjustslots(new.name, 0, new.nslots); return new; end if; - if tg_op = 'UPDATE' then + if tg_op = ''UPDATE'' then if new.name != old.name then update HSlot set hubname = new.name where hubname = old.name; end if; dummy := tg_hub_adjustslots(new.name, old.nslots, new.nslots); return new; end if; - if tg_op = 'DELETE' then + if tg_op = ''DELETE'' then dummy := tg_hub_adjustslots(old.name, old.nslots, 0); return old; end if; end; -$function$; +'; create trigger tg_hub_a after insert or delete or update @@ -276,7 +276,7 @@ execute function tg_hub_a(); create function tg_hub_adjustslots(hname bpchar, oldnslots int, newnslots int) returns int language plpgsql -as $function$ +as ' begin if newnslots = oldnslots then return 0; @@ -287,25 +287,28 @@ begin end if; for i in oldnslots + 1 .. newnslots loop insert into HSlot (slotname, hubname, slotno, slotlink) - values ('HS.dummy', hname, i, ''); + values (''HS.dummy'', hname, i, ''''); end loop; return 0; end -$function$; +'; comment on function tg_hub_adjustslots_wrong( bpchar, int, int) is 'function with args'; -comment on function tg_hub_adjustslots(bpchar, int, int) is 'function with args'; +comment on function tg_hub_adjustslots( + bpchar, + int, + int) is 'function with args'; comment on function tg_hub_adjustslots(bpchar, int, int) is null; create function tg_hslot_biu() returns trigger language plpgsql -as $function$ +as ' declare sname text; xname HSlot.slotname%TYPE; @@ -313,26 +316,26 @@ declare begin select into hubrec * from Hub where name = new.hubname; if not found then - raise exception 'no manual manipulation of HSlot'; + raise exception ''no manual manipulation of HSlot''; end if; if new.slotno < 1 or new.slotno > hubrec.nslots then - raise exception 'no manual manipulation of HSlot'; + raise exception ''no manual manipulation of HSlot''; end if; - if tg_op = 'UPDATE' and new.hubname != old.hubname then + if tg_op = ''UPDATE'' and new.hubname != old.hubname then if count(*) > 0 from Hub where name = old.hubname then - raise exception 'no manual manipulation of HSlot'; + raise exception ''no manual manipulation of HSlot''; end if; end if; - sname := 'HS.' || trim(new.hubname); - sname := sname || '.'; + sname := ''HS.'' || trim(new.hubname); + sname := sname || ''.''; sname := sname || new.slotno::text; if length(sname) > 20 then - raise exception 'HSlot slotname "%" too long (20 char max)', sname; + raise exception ''HSlot slotname "%" too long (20 char max)'', sname; end if; new.slotname := sname; return new; end; -$function$; +'; create trigger tg_hslot_biu before insert or update @@ -343,7 +346,7 @@ execute function tg_hslot_biu(); create function tg_hslot_bd() returns trigger language plpgsql -as $function$ +as ' declare hubrec record; begin @@ -354,9 +357,9 @@ begin if old.slotno > hubrec.nslots then return old; end if; - raise exception 'no manual manipulation of HSlot'; + raise exception ''no manual manipulation of HSlot''; end; -$function$; +'; create trigger tg_hslot_bd before delete @@ -367,14 +370,14 @@ execute function tg_hslot_bd(); create function tg_chkslotname() returns trigger language plpgsql -as $function$ +as ' begin if substr(new.slotname, 1, 2) != tg_argv[0] then - raise exception 'slotname must begin with %', tg_argv[0]; + raise exception ''slotname must begin with %'', tg_argv[0]; end if; return new; end; -$function$; +'; create trigger tg_chkslotname before insert @@ -409,14 +412,14 @@ execute function tg_chkslotname("PH"); create function tg_chkslotlink() returns trigger language plpgsql -as $function$ +as ' begin if new.slotlink isnull then - new.slotlink := ''; + new.slotlink := ''''; end if; return new; end; -$function$; +'; create trigger tg_chkslotlink before insert or update @@ -451,14 +454,14 @@ execute function tg_chkslotlink(); create function tg_chkbacklink() returns trigger language plpgsql -as $function$ +as ' begin if new.backlink isnull then - new.backlink := ''; + new.backlink := ''''; end if; return new; end; -$function$; +'; create trigger tg_chkbacklink before insert or update @@ -481,7 +484,7 @@ execute function tg_chkbacklink(); create function tg_pslot_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from PSlot where slotname = old.slotname; @@ -500,7 +503,7 @@ begin end if; return new; end; -$function$; +'; create trigger tg_pslot_bu before update @@ -511,7 +514,7 @@ execute function tg_pslot_bu(); create function tg_wslot_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from WSlot where slotname = old.slotname; @@ -530,7 +533,7 @@ begin end if; return new; end; -$function$; +'; create trigger tg_wslot_bu before update @@ -541,7 +544,7 @@ execute function tg_wslot_bu(); create function tg_pline_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from PLine where slotname = old.slotname; @@ -560,7 +563,7 @@ begin end if; return new; end; -$function$; +'; create trigger tg_pline_bu before update @@ -571,7 +574,7 @@ execute function tg_pline_bu(); create function tg_iface_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from IFace where slotname = old.slotname; @@ -590,7 +593,7 @@ begin end if; return new; end; -$function$; +'; create trigger tg_iface_bu before update @@ -601,7 +604,7 @@ execute function tg_iface_bu(); create function tg_hslot_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname or new.hubname != old.hubname then delete from HSlot where slotname = old.slotname; @@ -620,7 +623,7 @@ begin end if; return new; end; -$function$; +'; create trigger tg_hslot_bu before update @@ -631,7 +634,7 @@ execute function tg_hslot_bu(); create function tg_phone_bu() returns trigger language plpgsql -as $function$ +as ' begin if new.slotname != old.slotname then delete from PHone where slotname = old.slotname; @@ -648,7 +651,7 @@ begin end if; return new; end; -$function$; +'; create trigger tg_phone_bu before update @@ -659,39 +662,39 @@ execute function tg_phone_bu(); create function tg_backlink_a() returns trigger language plpgsql -as $function$ +as ' declare dummy integer; begin - if tg_op = 'INSERT' then - if new.backlink != '' then + if tg_op = ''INSERT'' then + if new.backlink != '''' then dummy := tg_backlink_set(new.backlink, new.slotname); end if; return new; end if; - if tg_op = 'UPDATE' then + if tg_op = ''UPDATE'' then if new.backlink != old.backlink then - if old.backlink != '' then + if old.backlink != '''' then dummy := tg_backlink_unset(old.backlink, old.slotname); end if; - if new.backlink != '' then + if new.backlink != '''' then dummy := tg_backlink_set(new.backlink, new.slotname); end if; else - if new.slotname != old.slotname and new.backlink != '' then + if new.slotname != old.slotname and new.backlink != '''' then dummy := tg_slotlink_set(new.backlink, new.slotname); end if; end if; return new; end if; - if tg_op = 'DELETE' then - if old.backlink != '' then + if tg_op = ''DELETE'' then + if old.backlink != '''' then dummy := tg_backlink_unset(old.backlink, old.slotname); end if; return old; end if; end; -$function$; +'; create trigger tg_backlink_a after insert or delete or update @@ -714,7 +717,7 @@ execute function tg_backlink_a("PL"); create function tg_backlink_set(myname bpchar, blname bpchar) returns int language plpgsql -as $function$ +as ' declare mytype char(2); link char(4); @@ -722,52 +725,52 @@ declare begin mytype := substr(myname, 1, 2); link := mytype || substr(blname, 1, 2); - if link = 'PLPL' then + if link = ''PLPL'' then raise exception - 'backlink between two phone lines does not make sense'; + ''backlink between two phone lines does not make sense''; end if; - if link in ('PLWS', 'WSPL') then + if link in (''PLWS'', ''WSPL'') then raise exception - 'direct link of phone line to wall slot not permitted'; + ''direct link of phone line to wall slot not permitted''; end if; - if mytype = 'PS' then + if mytype = ''PS'' then select into rec * from PSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.backlink != blname then update PSlot set backlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'WS' then + if mytype = ''WS'' then select into rec * from WSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.backlink != blname then update WSlot set backlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'PL' then + if mytype = ''PL'' then select into rec * from PLine where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.backlink != blname then update PLine set backlink = blname where slotname = myname; end if; return 0; end if; - raise exception 'illegal backlink beginning with %', mytype; + raise exception ''illegal backlink beginning with %'', mytype; end; -$function$; +'; create function tg_backlink_unset(bpchar, bpchar) returns int language plpgsql -as $function$ +as ' declare myname alias for $1; blname alias for $2; @@ -775,75 +778,75 @@ declare rec record; begin mytype := substr(myname, 1, 2); - if mytype = 'PS' then + if mytype = ''PS'' then select into rec * from PSlot where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update PSlot set backlink = '' where slotname = myname; + update PSlot set backlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'WS' then + if mytype = ''WS'' then select into rec * from WSlot where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update WSlot set backlink = '' where slotname = myname; + update WSlot set backlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'PL' then + if mytype = ''PL'' then select into rec * from PLine where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update PLine set backlink = '' where slotname = myname; + update PLine set backlink = '''' where slotname = myname; end if; return 0; end if; end -$function$; +'; create function tg_slotlink_a() returns trigger language plpgsql -as $function$ +as ' declare dummy integer; begin - if tg_op = 'INSERT' then - if new.slotlink != '' then + if tg_op = ''INSERT'' then + if new.slotlink != '''' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; return new; end if; - if tg_op = 'UPDATE' then + if tg_op = ''UPDATE'' then if new.slotlink != old.slotlink then - if old.slotlink != '' then + if old.slotlink != '''' then dummy := tg_slotlink_unset(old.slotlink, old.slotname); end if; - if new.slotlink != '' then + if new.slotlink != '''' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; else - if new.slotname != old.slotname and new.slotlink != '' then + if new.slotname != old.slotname and new.slotlink != '''' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; end if; return new; end if; - if tg_op = 'DELETE' then - if old.slotlink != '' then + if tg_op = ''DELETE'' then + if old.slotlink != '''' then dummy := tg_slotlink_unset(old.slotlink, old.slotname); end if; return old; end if; end; -$function$; +'; create trigger tg_slotlink_a after insert or delete or update @@ -878,7 +881,7 @@ execute function tg_slotlink_a("PH"); create function tg_slotlink_set(bpchar, bpchar) returns int language plpgsql -as $function$ +as ' declare myname alias for $1; blname alias for $2; @@ -888,80 +891,80 @@ declare begin mytype := substr(myname, 1, 2); link := mytype || substr(blname, 1, 2); - if link = 'PHPH' then + if link = ''PHPH'' then raise exception - 'slotlink between two phones does not make sense'; + ''slotlink between two phones does not make sense''; end if; - if link in ('PHHS', 'HSPH') then + if link in (''PHHS'', ''HSPH'') then raise exception - 'link of phone to hub does not make sense'; + ''link of phone to hub does not make sense''; end if; - if link in ('PHIF', 'IFPH') then + if link in (''PHIF'', ''IFPH'') then raise exception - 'link of phone to hub does not make sense'; + ''link of phone to hub does not make sense''; end if; - if link in ('PSWS', 'WSPS') then + if link in (''PSWS'', ''WSPS'') then raise exception - 'slotlink from patchslot to wallslot not permitted'; + ''slotlink from patchslot to wallslot not permitted''; end if; - if mytype = 'PS' then + if mytype = ''PS'' then select into rec * from PSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update PSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'WS' then + if mytype = ''WS'' then select into rec * from WSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update WSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'IF' then + if mytype = ''IF'' then select into rec * from IFace where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update IFace set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'HS' then + if mytype = ''HS'' then select into rec * from HSlot where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update HSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = 'PH' then + if mytype = ''PH'' then select into rec * from PHone where slotname = myname; if not found then - raise exception '% does not exist', myname; + raise exception ''% does not exist'', myname; end if; if rec.slotlink != blname then update PHone set slotlink = blname where slotname = myname; end if; return 0; end if; - raise exception 'illegal slotlink beginning with %', mytype; + raise exception ''illegal slotlink beginning with %'', mytype; end; -$function$; +'; create function tg_slotlink_unset(bpchar, bpchar) returns int language plpgsql -as $function$ +as ' declare myname alias for $1; blname alias for $2; @@ -969,63 +972,63 @@ declare rec record; begin mytype := substr(myname, 1, 2); - if mytype = 'PS' then + if mytype = ''PS'' then select into rec * from PSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update PSlot set slotlink = '' where slotname = myname; + update PSlot set slotlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'WS' then + if mytype = ''WS'' then select into rec * from WSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update WSlot set slotlink = '' where slotname = myname; + update WSlot set slotlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'IF' then + if mytype = ''IF'' then select into rec * from IFace where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update IFace set slotlink = '' where slotname = myname; + update IFace set slotlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'HS' then + if mytype = ''HS'' then select into rec * from HSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update HSlot set slotlink = '' where slotname = myname; + update HSlot set slotlink = '''' where slotname = myname; end if; return 0; end if; - if mytype = 'PH' then + if mytype = ''PH'' then select into rec * from PHone where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update PHone set slotlink = '' where slotname = myname; + update PHone set slotlink = '''' where slotname = myname; end if; return 0; end if; end; -$function$; +'; create function pslot_backlink_view(bpchar) returns text language plpgsql -as $function$ +as ' <> declare rec record; @@ -1034,41 +1037,41 @@ declare begin select into rec * from PSlot where slotname = $1; if not found then - return ''; + return ''''; end if; - if rec.backlink = '' then - return '-'; + if rec.backlink = '''' then + return ''-''; end if; bltype := substr(rec.backlink, 1, 2); - if bltype = 'PL' then + if bltype = ''PL'' then declare rec record; begin select into rec * from PLine where slotname = "outer".rec.backlink; - retval := 'Phone line ' || trim(rec.phonenumber); - if rec.comment != '' then - retval := retval || ' ('; + retval := ''Phone line '' || trim(rec.phonenumber); + if rec.comment != '''' then + retval := retval || '' (''; retval := retval || rec.comment; - retval := retval || ')'; + retval := retval || '')''; end if; return retval; end; end if; - if bltype = 'WS' then + if bltype = ''WS'' then select into rec * from WSlot where slotname = rec.backlink; - retval := trim(rec.slotname) || ' in room '; + retval := trim(rec.slotname) || '' in room ''; retval := retval || trim(rec.roomno); - retval := retval || ' -> '; + retval := retval || '' -> ''; return retval || wslot_slotlink_view(rec.slotname); end if; return rec.backlink; end; -$function$; +'; create function pslot_slotlink_view(bpchar) returns text language plpgsql -as $function$ +as ' declare psrec record; sltype char(2); @@ -1076,33 +1079,33 @@ declare begin select into psrec * from PSlot where slotname = $1; if not found then - return ''; + return ''''; end if; - if psrec.slotlink = '' then - return '-'; + if psrec.slotlink = '''' then + return ''-''; end if; sltype := substr(psrec.slotlink, 1, 2); - if sltype = 'PS' then - retval := trim(psrec.slotlink) || ' -> '; + if sltype = ''PS'' then + retval := trim(psrec.slotlink) || '' -> ''; return retval || pslot_backlink_view(psrec.slotlink); end if; - if sltype = 'HS' then + if sltype = ''HS'' then retval := comment from Hub H, HSlot HS where HS.slotname = psrec.slotlink and H.name = HS.hubname; - retval := retval || ' slot '; + retval := retval || '' slot ''; retval := retval || slotno::text from HSlot where slotname = psrec.slotlink; return retval; end if; return psrec.slotlink; end; -$function$; +'; create function wslot_slotlink_view(bpchar) returns text language plpgsql -as $function$ +as ' declare rec record; sltype char(2); @@ -1110,51 +1113,49 @@ declare begin select into rec * from WSlot where slotname = $1; if not found then - return ''; + return ''''; end if; - if rec.slotlink = '' then - return '-'; + if rec.slotlink = '''' then + return ''-''; end if; sltype := substr(rec.slotlink, 1, 2); - if sltype = 'PH' then + if sltype = ''PH'' then select into rec * from PHone where slotname = rec.slotlink; - retval := 'Phone ' || trim(rec.slotname); - if rec.comment != '' then - retval := retval || ' ('; + retval := ''Phone '' || trim(rec.slotname); + if rec.comment != '''' then + retval := retval || '' (''; retval := retval || rec.comment; - retval := retval || ')'; + retval := retval || '')''; end if; return retval; end if; - if sltype = 'IF' then + if sltype = ''IF'' then declare syrow System%RowType; ifrow IFace%ROWTYPE; begin select into ifrow * from IFace where slotname = rec.slotlink; select into syrow * from System where name = ifrow.sysname; - retval := syrow.name || ' IF '; + retval := syrow.name || '' IF ''; retval := retval || ifrow.ifname; - if syrow.comment != '' then - retval := retval || ' ('; + if syrow.comment != '''' then + retval := retval || '' (''; retval := retval || syrow.comment; - retval := retval || ')'; + retval := retval || '')''; end if; return retval; end; end if; return rec.slotlink; end; -$function$; +'; create view pfield_v1 as select pf.pfname, pf.slotname, - pslot_backlink_view(pf.slotname) - as backside, - pslot_slotlink_view(pf.slotname) - as patch + pslot_backlink_view(pf.slotname) as backside, + pslot_slotlink_view(pf.slotname) as patch from pslot as pf; @@ -1535,28 +1536,21 @@ delete from hslot; insert into iface values ('IF', 'notthere', 'eth0', ''); insert into iface -values - ( - 'IF', - 'orion', - 'ethernet_interface_name_too_long', - '' - ); +values ('IF', 'orion', 'ethernet_interface_name_too_long', ''); create function recursion_test(int, int) returns text language plpgsql -as $function$ +as ' DECLARE rslt text; BEGIN IF $1 <= 0 THEN rslt = CAST($2 AS TEXT); ELSE - rslt = CAST($1 AS TEXT) || ',' || recursion_test($1 - 1, $2); + rslt = CAST($1 AS TEXT) || '','' || recursion_test($1 - 1, $2); END IF; RETURN rslt; -END; -$function$; +END;'; select recursion_test(4, 3); @@ -1565,8 +1559,8 @@ create table found_test_tbl (a int); create function test_found() returns boolean language plpgsql -as $function$ -declare +as ' + declare begin insert into found_test_tbl values (1); if FOUND then @@ -1598,8 +1592,7 @@ declare insert into found_test_tbl values (6); end if; return true; - end; -$function$; + end;'; select test_found(); @@ -1608,7 +1601,7 @@ select * from found_test_tbl; create function test_table_func_rec() returns setof found_test_tbl language plpgsql -as $function$ +as ' DECLARE rec RECORD; BEGIN @@ -1616,15 +1609,14 @@ BEGIN RETURN NEXT rec; END LOOP; RETURN; -END; -$function$; +END;'; select * from test_table_func_rec(); create function test_table_func_row() returns setof found_test_tbl language plpgsql -as $function$ +as ' DECLARE row found_test_tbl%ROWTYPE; BEGIN @@ -1632,15 +1624,14 @@ BEGIN RETURN NEXT row; END LOOP; RETURN; -END; -$function$; +END;'; select * from test_table_func_row(); create function test_ret_set_scalar(int, int) returns setof int language plpgsql -as $function$ +as ' DECLARE i int; BEGIN @@ -1648,15 +1639,14 @@ BEGIN RETURN NEXT i + 1; END LOOP; RETURN; -END; -$function$; +END;'; select * from test_ret_set_scalar(1, 10); create function test_ret_set_rec_dyn(int) returns setof record language plpgsql -as $function$ +as ' DECLARE retval RECORD; BEGIN @@ -1665,13 +1655,12 @@ BEGIN RETURN NEXT retval; RETURN NEXT retval; ELSE - SELECT INTO retval 50, 5::numeric, 'xxx'::text; + SELECT INTO retval 50, 5::numeric, ''xxx''::text; RETURN NEXT retval; RETURN NEXT retval; END IF; RETURN; -END; -$function$; +END;'; select * from test_ret_set_rec_dyn(1500) as (a int, b int, c int); @@ -1680,7 +1669,7 @@ select * from test_ret_set_rec_dyn(5) as (a int, b numeric, c text); create function test_ret_rec_dyn(int) returns record language plpgsql -as $function$ +as ' DECLARE retval RECORD; BEGIN @@ -1688,11 +1677,10 @@ BEGIN SELECT INTO retval 5, 10, 15; RETURN retval; ELSE - SELECT INTO retval 50, 5::numeric, 'xxx'::text; + SELECT INTO retval 50, 5::numeric, ''xxx''::text; RETURN retval; END IF; -END; -$function$; +END;'; select * from test_ret_rec_dyn(1500) as (a int, b int, c int); @@ -1701,147 +1689,126 @@ select * from test_ret_rec_dyn(5) as (a int, b numeric, c text); create function f1(x anyelement) returns anyelement language plpgsql -as $function$ +as $$ begin return x + 1; -end -$function$; +end$$; select f1(42) as int, f1(4.5) as num; select f1(point(3, 4)); -drop function f1(anyelement); +drop function f1(x anyelement); create function f1(x anyelement) returns anyarray language plpgsql -as $function$ +as $$ begin return array[x + 1, x + 2]; -end -$function$; +end$$; select f1(42) as int, f1(4.5) as num; -drop function f1(anyelement); +drop function f1(x anyelement); create function f1(x anyarray) returns anyelement language plpgsql -as $function$ +as $$ begin return x[1]; -end -$function$; +end$$; select f1(array[2, 4]) as int, f1(array[4.5, 7.7]) as num; select f1(stavalues1) from pg_statistic; -drop function f1(anyarray); +drop function f1(x anyarray); create function f1(x anyarray) returns anyarray language plpgsql -as $function$ +as $$ begin return x; -end -$function$; +end$$; select f1(array[2, 4]) as int, f1(array[4.5, 7.7]) as num; select f1(stavalues1) from pg_statistic; -drop function f1(anyarray); +drop function f1(x anyarray); create function f1(x anyelement) returns anyrange language plpgsql -as $function$ +as $$ begin return array[x + 1, x + 2]; -end -$function$; +end$$; create function f1(x anyrange) returns anyarray language plpgsql -as $function$ +as $$ begin return array[lower(x), upper(x)]; -end -$function$; +end$$; select f1(int4range(42, 49)) as int, f1(float8range(4.5, 7.8)) as num; -drop function f1(anyrange); +drop function f1(x anyrange); create function f1(x anycompatible, y anycompatible) returns anycompatiblearray language plpgsql -as $function$ +as $$ begin return array[x, y]; -end -$function$; +end$$; select f1(2, 4) as int, f1(2, 4.5) as num; -drop function f1(anycompatible, anycompatible); +drop function f1(x anycompatible, y anycompatible); create function f1(x anycompatiblerange, y anycompatible, z anycompatible) returns anycompatiblearray language plpgsql -as $function$ +as $$ begin return array[lower(x), upper(x), y, z]; -end -$function$; +end$$; select - f1( - int4range(42, 49), - 11, - cast(2 as smallint) - ) - as int, - f1( - float8range(4.5, 7.8), - 7.8, - cast(11 as real) - ) - as num; + f1(int4range(42, 49), 11, cast(2 as smallint)) as int, + f1(float8range(4.5, 7.8), 7.8, cast(11 as real)) as num; select f1(int4range(42, 49), 11, 4.5) as fail; -drop function f1(anycompatiblerange, anycompatible, anycompatible); +drop function f1(x anycompatiblerange, y anycompatible, z anycompatible); create function f1(x anycompatible) returns anycompatiblerange language plpgsql -as $function$ +as $$ begin return array[x + 1, x + 2]; -end -$function$; +end$$; create function f1(x anycompatiblerange, y anycompatiblearray) returns anycompatiblerange language plpgsql -as $function$ +as $$ begin return x; -end -$function$; +end$$; select f1(int4range(42, 49), array[11]) as int, - f1(float8range(4.5, 7.8), array[7]) - as num; + f1(float8range(4.5, 7.8), array[7]) as num; -drop function f1(anycompatiblerange, anycompatiblearray); +drop function f1(x anycompatiblerange, y anycompatiblearray); create function f1( @@ -1853,12 +1820,11 @@ f1( out y anycompatiblearray ) language plpgsql -as $function$ +as $$ begin x := a || b; y := array[c, d]; -end -$function$; +end$$; select x, pg_typeof(x), y, pg_typeof(y) from f1(11, array[1, 2], 42, 34.5); @@ -1868,12 +1834,7 @@ select y, pg_typeof(y) from - f1( - 11, - array[1, 2], - point(1, 2), - point(3, 4) - ); + f1(11, array[1, 2], point(1, 2), point(3, 4)); select x, @@ -1885,25 +1846,23 @@ from select x, pg_typeof(x), y, pg_typeof(y) from f1(11, array[1, 2.2], 42, 34.5); -drop function f1(anyelement, anyarray, anycompatible, anycompatible); +drop function f1(a anyelement, b anyarray, c anycompatible, d anycompatible); create function f1(in i int, out j int) returns int language plpgsql -as $function$ +as $$ begin return i+1; -end -$function$; +end$$; create function f1(in i int, out j int) language plpgsql -as $function$ +as $$ begin j := i+1; return; -end -$function$; +end$$; select f1(42); @@ -1911,11 +1870,10 @@ select * from f1(42); create or replace function f1(inout i int) language plpgsql -as $function$ +as $$ begin i := i+1; -end -$function$; +end$$; select f1(42); @@ -1926,15 +1884,14 @@ drop function f1(int); create function f1(in i int, out j int) returns setof int language plpgsql -as $function$ +as $$ begin j := i+1; return next; j := i+2; return next; return; -end -$function$; +end$$; select * from f1(42); @@ -1942,13 +1899,12 @@ drop function f1(int); create function f1(in i int, out j int, out k text) language plpgsql -as $function$ +as $$ begin j := i; j := j+1; k := 'foo'; -end -$function$; +end$$; select f1(42); @@ -1959,7 +1915,7 @@ drop function f1(int); create function f1(in i int, out j int, out k text) returns setof record language plpgsql -as $function$ +as $$ begin j := i+1; k := 'foo'; @@ -1967,8 +1923,7 @@ begin j := j+1; k := 'foot'; return next; -end -$function$; +end$$; select * from f1(42); @@ -1976,13 +1931,12 @@ drop function f1(int); create function duplic(in i anyelement, out j anyelement, out k anyarray) language plpgsql -as $function$ +as $$ begin j := i; k := array[j,j]; return; -end -$function$; +end$$; select * from duplic(42); @@ -1997,13 +1951,12 @@ duplic( out k anycompatiblearray ) language plpgsql -as $function$ +as $$ begin j := lower(i); k := array[lower(i),upper(i)]; return; -end -$function$; +end$$; select * from duplic(int4range(42, 49)); @@ -2019,7 +1972,7 @@ create table perform_test ( create function perform_simple_func(int) returns boolean language plpgsql -as $function$ +as ' BEGIN IF $1 < 20 THEN INSERT INTO perform_test VALUES ($1, $1 + 10); @@ -2027,13 +1980,12 @@ BEGIN ELSE RETURN FALSE; END IF; -END; -$function$; +END;'; create function perform_test_func() returns void language plpgsql -as $function$ +as ' BEGIN IF FOUND then INSERT INTO perform_test VALUES (100, 100); @@ -2052,8 +2004,7 @@ BEGIN END IF; RETURN; -END; -$function$; +END;'; select perform_test_func(); @@ -2070,14 +2021,13 @@ create function sp_id_user(a_login text) returns int language plpgsql stable -as $function$ +as $$ declare x int; begin select into x id from users where login = a_login; if found then return x; end if; return 0; -end -$function$; +end$$; insert into users values ('user1'); @@ -2088,7 +2038,7 @@ select sp_id_user('userx'); create function sp_add_user(a_login text) returns int language plpgsql -as $function$ +as $$ declare my_id_user int; begin my_id_user = sp_id_user( a_login ); @@ -2101,8 +2051,7 @@ begin RETURN -2; -- error code for insertion failure END IF; RETURN my_id_user; -end -$function$; +end$$; select sp_add_user('user1'); @@ -2128,19 +2077,19 @@ copy rc_test from stdout; create function return_unnamed_refcursor() returns refcursor language plpgsql -as $function$ +as $$ declare rc refcursor; begin open rc for select a from rc_test; return rc; end -$function$; +$$; create function use_refcursor(rc refcursor) returns int language plpgsql -as $function$ +as $$ declare rc refcursor; x record; @@ -2149,29 +2098,29 @@ begin fetch next from rc into x; return x.a; end -$function$; +$$; select use_refcursor(return_unnamed_refcursor()); create function return_refcursor(rc refcursor) returns refcursor language plpgsql -as $function$ +as $$ begin open rc for select a from rc_test; return rc; end -$function$; +$$; create function refcursor_test1(refcursor) returns refcursor language plpgsql -as $function$ +as $$ begin perform return_refcursor($1); return $1; end -$function$; +$$; begin; @@ -2190,7 +2139,7 @@ fetch next from test1; create function refcursor_test2(int, int) returns boolean language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param2 int) for select * from rc_test where a > param1 and b > param2; nonsense record; @@ -2204,46 +2153,44 @@ begin return false; end if; end -$function$; +$$; select - refcursor_test2(20000, 20000) - as "Should be false", - refcursor_test2(20, 20) - as "Should be true"; + refcursor_test2(20000, 20000) as "Should be false", + refcursor_test2(20, 20) as "Should be true"; create function constant_refcursor() returns refcursor language plpgsql -as $function$ +as $$ declare rc constant refcursor; begin open rc for select a from rc_test; return rc; end -$function$; +$$; select constant_refcursor(); create or replace function constant_refcursor() returns refcursor language plpgsql -as $function$ +as $$ declare rc constant refcursor := 'my_cursor_name'; begin open rc for select a from rc_test; return rc; end -$function$; +$$; select constant_refcursor(); create function namedparmcursor_test1(int, int) returns boolean language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param12 int) for select * from rc_test where a > param1 and b > param12; nonsense record; @@ -2257,18 +2204,16 @@ begin return false; end if; end -$function$; +$$; select - namedparmcursor_test1(20000, 20000) - as "Should be false", - namedparmcursor_test1(20, 20) - as "Should be true"; + namedparmcursor_test1(20000, 20000) as "Should be false", + namedparmcursor_test1(20, 20) as "Should be true"; create function namedparmcursor_test2(int, int) returns boolean language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param2 int) for select * from rc_test where a > param1 and b > param2; nonsense record; @@ -2282,74 +2227,73 @@ begin return false; end if; end -$function$; +$$; select namedparmcursor_test2(20, 20); create function namedparmcursor_test3() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param2 int) for select * from rc_test where a > param1 and b > param2; begin open c1(param2 := 20, 21); end -$function$; +$$; create function namedparmcursor_test4() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (param1 int, param2 int) for select * from rc_test where a > param1 and b > param2; begin open c1(20, param1 := 21); end -$function$; +$$; create function namedparmcursor_test5() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int) for select * from tenk1 where thousand = p1 and tenthous = p2; begin open c1 (p2 := 77, p2 := 42); end -$function$; +$$; create function namedparmcursor_test6() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int) for select * from tenk1 where thousand = p1 and tenthous = p2; begin open c1 (p2 := 77); end -$function$; +$$; create function namedparmcursor_test7() returns void language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int) for select * from tenk1 where thousand = p1 and tenthous = p2; begin open c1 (p2 := 77, p1 := 42/0); -end -$function$; +end $$; select namedparmcursor_test7(); create function namedparmcursor_test8() -returns int +returns int4 language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int) for select count(*) from tenk1 where thousand = p1 and tenthous = p2; @@ -2359,15 +2303,14 @@ begin , 42); fetch c1 into n; return n; -end -$function$; +end $$; select namedparmcursor_test8(); create function namedparmcursor_test9(p1 int) -returns int +returns int4 language plpgsql -as $function$ +as $$ declare c1 cursor (p1 int, p2 int, debug int) for select count(*) from tenk1 where thousand = p1 and tenthous = p2 @@ -2379,47 +2322,46 @@ begin open c1 (p1 := p1, p2 => p2, debug => 2); fetch c1 into n; return n; -end -$function$; +end $$; select namedparmcursor_test9(6); create function raise_test1(int) returns int language plpgsql -as $function$ +as $$ begin raise notice 'This message has too many parameters!', $1; return $1; end; -$function$; +$$; create function raise_test2(int) returns int language plpgsql -as $function$ +as $$ begin raise notice 'This message has too few parameters: %, %, %', $1, $1; return $1; end; -$function$; +$$; create function raise_test3(int) returns int language plpgsql -as $function$ +as $$ begin raise notice 'This message has no parameters (despite having %% signs in it)!'; return $1; end; -$function$; +$$; select raise_test3(1); create function reraise_test() returns void language plpgsql -as $function$ +as $$ BEGIN BEGIN RAISE syntax_error; @@ -2437,73 +2379,67 @@ EXCEPTION WHEN OTHERS THEN raise notice 'WRONG - exception % caught in outer block', sqlerrm; END; -$function$; +$$; select reraise_test(); create function bad_sql1() returns int language plpgsql -as $function$ +as $$ declare a int; begin a := 5; Johnny Yuma; a := 10; return a; -end -$function$; +end$$; create function bad_sql2() returns int language plpgsql -as $function$ +as $$ declare r record; begin for r in select I fought the law, the law won LOOP raise notice 'in loop'; end loop; return 5; -end; -$function$; +end;$$; create function missing_return_expr() returns int language plpgsql -as $function$ +as $$ begin return ; -end; -$function$; +end;$$; create function void_return_expr() returns void language plpgsql -as $function$ +as $$ begin return 5; -end; -$function$; +end;$$; create function void_return_expr() returns void language plpgsql -as $function$ +as $$ begin perform 2+2; -end; -$function$; +end;$$; select void_return_expr(); create function missing_return_expr() returns int language plpgsql -as $function$ +as $$ begin perform 2+2; -end; -$function$; +end;$$; select missing_return_expr(); @@ -2521,7 +2457,7 @@ create type eitype as (i int, y int); create or replace function execute_into_test(varchar) returns record language plpgsql -as $function$ +as $$ declare _r record; _rt eifoo%rowtype; @@ -2539,8 +2475,7 @@ begin raise notice '% % %', i, j, k; execute 'select 1,2' into _v; return _v; -end; -$function$; +end; $$; select execute_into_test('eifoo'); @@ -2551,33 +2486,31 @@ drop type eitype cascade; create function excpt_test1() returns void language plpgsql -as $function$ +as $$ begin raise notice '% %', sqlstate, sqlerrm; -end; -$function$; +end; $$; select excpt_test1(); create function excpt_test2() returns void language plpgsql -as $function$ +as $$ begin begin begin raise notice '% %', sqlstate, sqlerrm; end; end; -end; -$function$; +end; $$; select excpt_test2(); create function excpt_test3() returns void language plpgsql -as $function$ +as $$ begin begin raise exception 'user exception'; @@ -2595,20 +2528,18 @@ begin end; raise notice '% %', sqlstate, sqlerrm; end; -end; -$function$; +end; $$; select excpt_test3(); create function excpt_test4() returns text language plpgsql -as $function$ +as $$ begin begin perform 1/0; exception when others then return sqlerrm; end; -end; -$function$; +end; $$; select excpt_test4(); @@ -2623,7 +2554,7 @@ drop function excpt_test4(); create function raise_exprs() returns void language plpgsql -as $function$ +as $$ declare a integer[] = '{10,20,30}'; c varchar = 'xyz'; @@ -2631,25 +2562,23 @@ declare begin i := 2; raise notice '%; %; %; %; %; %', a, a[i], c, (select c || 'abc'), row(10,'aaa',NULL,30), NULL; -end; -$function$; +end;$$; select raise_exprs(); drop function raise_exprs(); create function multi_datum_use(p1 int) -returns boolean +returns bool language plpgsql -as $function$ +as $$ declare x int; y int; begin select into x,y unique1/p1, unique1/$1 from tenk1 group by unique1/p1; return x = y; -end -$function$; +end$$; select multi_datum_use(42); @@ -2663,56 +2592,52 @@ insert into foo values (1, 2), (3, 4); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should work insert into foo values(5,6) returning * into x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail due to implicit strict insert into foo values(7,8),(9,10) returning * into x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should work execute 'insert into foo values(5,6) returning *' into x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- this should work since EXECUTE isn't as picky execute 'insert into foo values(7,8),(9,10) returning *' into x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); @@ -2721,84 +2646,78 @@ select * from foo; create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should work select * from foo where f1 = 3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail, no rows select * from foo where f1 = 0 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail, too many rows select * from foo where f1 > 3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should work execute 'select * from foo where f1 = 3' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail, no rows execute 'select * from foo where f1 = 0' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- should fail, too many rows execute 'select * from foo where f1 > 3' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); @@ -2809,7 +2728,7 @@ set plpgsql.print_strict_params = 'true'; create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; p1 int := 2; @@ -2818,15 +2737,14 @@ begin -- no rows select * from foo where f1 = p1 and f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; p1 int := 2; @@ -2835,15 +2753,14 @@ begin -- no rows select * from foo where f1 = p1 and f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; p1 int := 2; @@ -2852,71 +2769,66 @@ begin -- too many rows select * from foo where f1 > p1 or f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- too many rows, no params select * from foo where f1 > 3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- no rows execute 'select * from foo where f1 = $1 or f1::text = $2' using 0, 'foo' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- too many rows execute 'select * from foo where f1 > $1' using 1 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ declare x record; begin -- too many rows, no parameters execute 'select * from foo where f1 > 3' into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ -- override the global #print_strict_params off declare @@ -2927,8 +2839,7 @@ begin -- too many rows select * from foo where f1 > p1 or f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); @@ -2937,7 +2848,7 @@ reset plpgsql.print_strict_params; create or replace function stricttest() returns void language plpgsql -as $function$ +as $$ -- override the global #print_strict_params on declare @@ -2948,18 +2859,17 @@ begin -- too many rows select * from foo where f1 > p1 or f1::text = p3 into strict x; raise notice 'x.f1 = %, x.f2 = %', x.f1, x.f2; -end -$function$; +end$$; select stricttest(); set plpgsql.extra_warnings = 'all'; -set plpgsql.extra_warnings = 'none'; +set plpgsql.extra_warnings = none; set plpgsql.extra_errors = 'all'; -set plpgsql.extra_errors = 'none'; +set plpgsql.extra_errors = none; set plpgsql.extra_warnings = shadowed_variables; @@ -2968,13 +2878,13 @@ returns table ( out1 int ) language plpgsql -as $function$ +as $$ declare in1 int; out1 int; begin end -$function$; +$$; select shadowtest(1); @@ -2987,13 +2897,13 @@ returns table ( out1 int ) language plpgsql -as $function$ +as $$ declare in1 int; out1 int; begin end -$function$; +$$; select shadowtest(1); @@ -3002,7 +2912,7 @@ drop function shadowtest(int); create or replace function shadowtest() returns void language plpgsql -as $function$ +as $$ declare f1 int; begin @@ -3010,15 +2920,14 @@ begin f1 int; begin end; -end -$function$; +end$$; drop function shadowtest(); create or replace function shadowtest(in1 int) returns void language plpgsql -as $function$ +as $$ declare in1 int; begin @@ -3026,21 +2935,19 @@ begin in1 int; begin end; -end -$function$; +end$$; drop function shadowtest(int); create or replace function shadowtest() returns void language plpgsql -as $function$ +as $$ declare f1 int; c1 cursor (f1 int) for select 1; begin -end -$function$; +end$$; drop function shadowtest(); @@ -3049,9 +2956,8 @@ set plpgsql.extra_errors = shadowed_variables; create or replace function shadowtest(f1 int) returns boolean language plpgsql -as $function$ -declare f1 int; begin return 1; end -$function$; +as $$ +declare f1 int; begin return 1; end $$; select shadowtest(1); @@ -3062,31 +2968,28 @@ reset plpgsql.extra_warnings; create or replace function shadowtest(f1 int) returns boolean language plpgsql -as $function$ -declare f1 int; begin return 1; end -$function$; +as $$ +declare f1 int; begin return 1; end $$; select shadowtest(1); set plpgsql.extra_warnings = too_many_rows; -do -$do$ +do $$ declare x int; begin select v from generate_series(1,2) g(v) into x; end; -$do$; +$$; set plpgsql.extra_errors = too_many_rows; -do -$do$ +do $$ declare x int; begin select v from generate_series(1,2) g(v) into x; end; -$do$; +$$; reset plpgsql.extra_errors; @@ -3094,8 +2997,7 @@ reset plpgsql.extra_warnings; set plpgsql.extra_warnings = strict_multi_assignment; -do -$do$ +do $$ declare x int; y int; @@ -3104,12 +3006,11 @@ begin select 1,2 into x, y; select 1,2,3 into x, y; end -$do$; +$$; set plpgsql.extra_errors = strict_multi_assignment; -do -$do$ +do $$ declare x int; y int; @@ -3118,7 +3019,7 @@ begin select 1,2 into x, y; select 1,2,3 into x, y; end -$do$; +$$; create table test_01 ( a int, @@ -3131,8 +3032,7 @@ alter table test_01 insert into test_01 values (10, 20); -do -$do$ +do $$ declare x int; y int; @@ -3141,10 +3041,9 @@ begin raise notice 'ok'; select * from test_01 into x; -- should to fail end; -$do$; +$$; -do -$do$ +do $$ declare t test_01; begin @@ -3152,16 +3051,15 @@ begin raise notice 'ok'; select 1, 2, 3 into t; -- should fail; end; -$do$; +$$; -do -$do$ +do $$ declare t test_01; begin select 1 into t; -- should fail; end; -$do$; +$$; drop table test_01; @@ -3172,7 +3070,7 @@ reset plpgsql.extra_warnings; create function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c scroll cursor for select f1 from int4_tbl; x integer; @@ -3185,14 +3083,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c no scroll cursor for select f1 from int4_tbl; x integer; @@ -3205,14 +3103,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c refcursor; x integer; @@ -3225,14 +3123,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c refcursor; x integer; @@ -3245,14 +3143,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c refcursor; x integer; @@ -3266,14 +3164,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c cursor for select * from generate_series(1, 10); x integer; @@ -3291,14 +3189,14 @@ begin end loop; close c; end; -$function$; +$$; select * from sc_test(); create or replace function sc_test() returns setof int language plpgsql -as $function$ +as $$ declare c cursor for select * from generate_series(1, 10); x integer; @@ -3311,7 +3209,7 @@ begin end if; close c; end; -$function$; +$$; select * from sc_test(); @@ -3320,7 +3218,7 @@ drop function sc_test(); create function pl_qual_names(param1 int) returns void language plpgsql -as $function$ +as $$ <> declare param1 int := 1; @@ -3335,7 +3233,7 @@ begin raise notice 'innerblock.param1 = %', innerblock.param1; end; end; -$function$; +$$; select pl_qual_names(42); @@ -3344,7 +3242,7 @@ drop function pl_qual_names(int); create function ret_query1(out int, out int) returns setof record language plpgsql -as $function$ +as $$ begin $1 := -1; $2 := -2; @@ -3352,7 +3250,7 @@ begin return query select x + 1, x * 10 from generate_series(0, 10) s (x); return next; end; -$function$; +$$; select * from ret_query1(); @@ -3361,19 +3259,19 @@ create type record_type as (x text, y int, z boolean); create or replace function ret_query2(lim int) returns setof record_type language plpgsql -as $function$ +as $$ begin return query select fipshash(s.x::text), s.x, s.x > 0 from generate_series(-8, lim) s (x) where s.x % 2 = 0; end; -$function$; +$$; select * from ret_query2(8); create function exc_using(int, text) returns int language plpgsql -as $function$ +as $$ declare i int; begin for i in execute 'select * from generate_series(1,$1)' using $1+1 loop @@ -3382,7 +3280,7 @@ begin execute 'select $2 + $2*3 + length($1)' into i using $2,$1; return i; end -$function$; +$$; select exc_using(5, 'foobar'); @@ -3391,7 +3289,7 @@ drop function exc_using(int, text); create or replace function exc_using(int) returns void language plpgsql -as $function$ +as $$ declare c refcursor; i int; @@ -3405,7 +3303,7 @@ begin close c; return; end; -$function$; +$$; select exc_using(5); @@ -3414,7 +3312,7 @@ drop function exc_using(int); create or replace function forc01() returns void language plpgsql -as $function$ +as $$ declare c cursor(r1 integer, r2 integer) for select * from generate_series(r1,r2) i; @@ -3452,22 +3350,18 @@ begin raise notice 'after loop, c2 = %', c2; return; end; -$function$; +$$; select forc01(); create temporary table forc_test as - select - n as i, - n as j - from - generate_series(1, 10) as n; + select n as i, n as j from generate_series(1, 10) as n; create or replace function forc01() returns void language plpgsql -as $function$ +as $$ declare c cursor for select * from forc_test; begin @@ -3476,7 +3370,7 @@ begin update forc_test set i = i * 100, j = r.j * 2 where current of c; end loop; end; -$function$; +$$; select forc01(); @@ -3485,7 +3379,7 @@ select * from forc_test; create or replace function forc01() returns void language plpgsql -as $function$ +as $$ declare c refcursor := 'fooled_ya'; r record; @@ -3498,7 +3392,7 @@ begin update forc_test set i = i * 100, j = r.j * 2 where current of c; end loop; end; -$function$; +$$; select forc01(); @@ -3506,8 +3400,7 @@ select * from forc_test; drop function forc01(); -do -$do$ +do $$ declare cnt int := 0; c1 cursor for select * from forc_test; begin @@ -3520,13 +3413,12 @@ begin end; end loop; raise notice 'cnt = %', cnt; -end -$do$; +end $$; create or replace function forc_bad() returns void language plpgsql -as $function$ +as $$ declare c refcursor; begin @@ -3534,17 +3426,17 @@ begin raise notice '%', r.i; end loop; end; -$function$; +$$; create or replace function return_dquery() returns setof int language plpgsql -as $function$ +as $$ begin return query execute 'select * from (values(10),(20)) f'; return query execute 'select * from (values($1),($2)) f' using 40,50; end; -$function$; +$$; select * from return_dquery(); @@ -3562,12 +3454,12 @@ insert into tabwithcols values (10, 20, 30, 40), (50, 60, 70, 80); create or replace function returnqueryf() returns setof tabwithcols language plpgsql -as $function$ +as $$ begin return query select * from tabwithcols; return query execute 'select * from tabwithcols'; end; -$function$; +$$; select * from returnqueryf(); @@ -3595,61 +3487,61 @@ create type compostype as (x int, y varchar); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ declare v compostype; begin v := (1, 'hello'); return v; end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ declare v record; begin v := (1, 'hello'::varchar); return v; end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ begin return (1, 'hello'::varchar); end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ begin return (1, 'hello'); end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ begin return (1, 'hello')::compostype; end; -$function$; +$$; select compos(); @@ -3658,25 +3550,25 @@ drop function compos(); create or replace function composrec() returns record language plpgsql -as $function$ +as $$ declare v record; begin v := (1, 'hello'); return v; end; -$function$; +$$; select composrec(); create or replace function composrec() returns record language plpgsql -as $function$ +as $$ begin return (1, 'hello'); end; -$function$; +$$; select composrec(); @@ -3685,7 +3577,7 @@ drop function composrec(); create or replace function compos() returns setof compostype language plpgsql -as $function$ +as $$ begin for i in 1..3 loop @@ -3694,7 +3586,7 @@ begin return next null::compostype; return next (2, 'goodbye')::compostype; end; -$function$; +$$; select * from compos(); @@ -3703,23 +3595,23 @@ drop function compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ begin return 1 + 1; end; -$function$; +$$; select compos(); create or replace function compos() returns compostype language plpgsql -as $function$ +as $$ declare x int := 42; begin return x; end; -$function$; +$$; select * from compos(); @@ -3728,25 +3620,25 @@ drop function compos(); create or replace function compos() returns int language plpgsql -as $function$ +as $$ declare v compostype; begin v := (1, 'hello'); return v; end; -$function$; +$$; select compos(); create or replace function compos() returns int language plpgsql -as $function$ +as $$ begin return (1, 'hello')::compostype; end; -$function$; +$$; select compos(); @@ -3757,21 +3649,21 @@ drop type compostype; create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise notice '% % %', 1, 2, 3 using errcode = '55001', detail = 'some detail info', hint = 'some hint'; raise '% % %', 1, 2, 3 using errcode = 'division_by_zero', detail = 'some detail info'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise 'check me' using errcode = 'division_by_zero', detail = 'some detail info'; @@ -3780,14 +3672,14 @@ begin raise notice 'SQLSTATE: % SQLERRM: %', sqlstate, sqlerrm; raise; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise 'check me' using errcode = '1234F', detail = 'some detail info'; @@ -3796,14 +3688,14 @@ begin raise notice 'SQLSTATE: % SQLERRM: %', sqlstate, sqlerrm; raise; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise 'check me' using errcode = '1234F', detail = 'some detail info'; @@ -3812,14 +3704,14 @@ begin raise notice 'SQLSTATE: % SQLERRM: %', sqlstate, sqlerrm; raise; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise division_by_zero using detail = 'some detail info'; exception @@ -3827,113 +3719,113 @@ begin raise notice 'SQLSTATE: % SQLERRM: %', sqlstate, sqlerrm; raise; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise division_by_zero; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise sqlstate '1234F'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise division_by_zero using message = 'custom' || ' message'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise using message = 'custom' || ' message', errcode = '22012'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise notice 'some message' using message = 'custom' || ' message', errcode = '22012'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise division_by_zero using message = 'custom' || ' message', errcode = '22012'; end; -$function$; +$$; select raise_test(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise; end; -$function$; +$$; select raise_test(); create function zero_divide() returns int language plpgsql -parallel SAFE -as $function$ +parallel safe +as $$ declare v int := 0; begin return 10 / v; end; -$function$; +$$; create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin raise exception 'custom exception' using detail = 'some detail of custom exception', hint = 'some hint related to custom exception'; end; -$function$; +$$; create function stacked_diagnostics_test() returns void language plpgsql -as $function$ +as $$ declare _sqlstate text; _message text; _context text; @@ -3947,14 +3839,14 @@ exception when others then raise notice 'sqlstate: %, message: %, context: [%]', _sqlstate, _message, replace(_context, E'\n', ' <- '); end; -$function$; +$$; select stacked_diagnostics_test(); create or replace function stacked_diagnostics_test() returns void language plpgsql -as $function$ +as $$ declare _detail text; _hint text; _message text; @@ -3967,14 +3859,14 @@ exception when others then _hint = pg_exception_hint; raise notice 'message: %, detail: %, hint: %', _message, _detail, _hint; end; -$function$; +$$; select stacked_diagnostics_test(); create or replace function stacked_diagnostics_test() returns void language plpgsql -as $function$ +as $$ declare _detail text; _hint text; _message text; @@ -3985,7 +3877,7 @@ begin _hint = pg_exception_hint; raise notice 'message: %, detail: %, hint: %', _message, _detail, _hint; end; -$function$; +$$; select stacked_diagnostics_test(); @@ -3994,15 +3886,15 @@ drop function stacked_diagnostics_test(); create function error_trap_test() returns text language plpgsql -parallel SAFE -as $function$ +parallel safe +as $$ begin perform zero_divide(); return 'no error detected!'; exception when division_by_zero then return 'division_by_zero detected'; end; -$function$; +$$; set debug_parallel_query = 'on'; @@ -4019,7 +3911,7 @@ drop function zero_divide(); create or replace function raise_test() returns void language plpgsql -as $function$ +as $$ begin perform 1/0; exception @@ -4027,7 +3919,7 @@ exception raise notice using message = sqlstate; raise sqlstate '22012' using message = 'substitute message'; end; -$function$; +$$; select raise_test(); @@ -4036,7 +3928,7 @@ drop function raise_test(); create or replace function stacked_diagnostics_test() returns void language plpgsql -as $function$ +as $$ declare _column_name text; _constraint_name text; _datatype_name text; @@ -4059,7 +3951,7 @@ exception when others then raise notice 'column %, constraint %, type %, table %, schema %', _column_name, _constraint_name, _datatype_name, _table_name, _schema_name; end; -$function$; +$$; select stacked_diagnostics_test(); @@ -4068,12 +3960,12 @@ drop function stacked_diagnostics_test(); create or replace function vari(variadic int[]) returns void language plpgsql -as $function$ +as $$ begin for i in array_lower($1,1)..array_upper($1,1) loop raise notice '%', $1[i]; end loop; end; -$function$; +$$; select vari(1, 2, 3, 4, 5); @@ -4088,7 +3980,7 @@ returns numeric language plpgsql immutable strict -as $function$ +as $$ declare aux numeric = $1[array_lower($1,1)]; begin for i in array_lower($1,1)+1..array_upper($1,1) loop @@ -4096,7 +3988,7 @@ begin end loop; return aux; end; -$function$; +$$; select pleast(10, 1, 2, 3, -16); @@ -4111,12 +4003,12 @@ returns numeric language plpgsql immutable strict -as $function$ +as $$ begin raise notice 'non-variadic function called'; return $1; end; -$function$; +$$; select pleast(10); @@ -4132,11 +4024,11 @@ returns table ( language plpgsql immutable strict -as $function$ +as $$ begin return query select $1, $1+i from generate_series(1,5) g(i); end; -$function$; +$$; select * from tftest(10); @@ -4148,14 +4040,14 @@ returns table ( language plpgsql immutable strict -as $function$ +as $$ begin a := a1; b := a1 + 1; return next; a := a1 * 10; b := a1 * 10 + 1; return next; end; -$function$; +$$; select * from tftest(10); @@ -4164,7 +4056,7 @@ drop function tftest(int); create function rttest() returns setof int language plpgsql -as $function$ +as $$ declare rc int; begin return query values(10),(20); @@ -4180,29 +4072,29 @@ begin get diagnostics rc = row_count; raise notice '% %', found, rc; end; -$function$; +$$; select * from rttest(); create or replace function rttest() returns setof int language plpgsql -as $function$ +as $$ begin return query select 10 into no_such_table; end; -$function$; +$$; select * from rttest(); create or replace function rttest() returns setof int language plpgsql -as $function$ +as $$ begin return query execute 'select 10 into no_such_table'; end; -$function$; +$$; select * from rttest(); @@ -4210,10 +4102,10 @@ select * from no_such_table; drop function rttest(); -create function leaker_1(fail boolean) +create function leaker_1(fail bool) returns int language plpgsql -as $function$ +as $$ DECLARE v_var INTEGER; BEGIN @@ -4224,12 +4116,12 @@ BEGIN END; RETURN 1; END; -$function$; +$$; -create function leaker_2(fail boolean, out error_code int, out new_id int) +create function leaker_2(fail bool, out error_code int, out new_id int) returns record language plpgsql -as $function$ +as $$ BEGIN IF fail THEN RAISE EXCEPTION 'fail ...'; @@ -4238,20 +4130,20 @@ BEGIN new_id := 1; RETURN; END; -$function$; +$$; select * from leaker_1(false); select * from leaker_1(true); -drop function leaker_1(boolean); +drop function leaker_1(bool); -drop function leaker_2(boolean); +drop function leaker_2(bool); create function nonsimple_expr_test() returns text[] language plpgsql -as $function$ +as $$ DECLARE arr text[]; lr text; @@ -4264,7 +4156,7 @@ BEGIN arr[(SELECT i)][(SELECT i+1)] := (SELECT lr); RETURN arr; END; -$function$; +$$; select nonsimple_expr_test(); @@ -4273,7 +4165,7 @@ drop function nonsimple_expr_test(); create function nonsimple_expr_test() returns int language plpgsql -as $function$ +as $$ declare i integer NOT NULL := 0; begin @@ -4285,16 +4177,16 @@ begin end; return i; end; -$function$; +$$; select nonsimple_expr_test(); drop function nonsimple_expr_test(); -create function recurse(double precision) -returns double precision +create function recurse(float8) +returns float8 language plpgsql -as $function$ +as $$ begin if ($1 > 0) then return sql_recurse($1 - 1); @@ -4302,32 +4194,27 @@ begin return $1; end if; end; -$function$; +$$; -create function sql_recurse(double precision) -returns double precision +create function sql_recurse(float8) +returns float8 language sql -as $function$ -select recurse($1) limit 1; -$function$; +as $$ select recurse($1) limit 1; $$; select recurse(10); create function error1(text) returns text language sql -as $function$ -SELECT relname::text FROM pg_class c WHERE c.oid = $1::regclass -$function$; +as $$ SELECT relname::text FROM pg_class c WHERE c.oid = $1::regclass $$; create function error2(p_name_table text) returns text language plpgsql -as $function$ +as $$ begin return error1(p_name_table); -end -$function$; +end$$; begin; @@ -4343,7 +4230,7 @@ select error2('public.stuffs'); rollback; -drop function error2(text); +drop function error2(p_name_table text); drop function error1(text); @@ -4352,20 +4239,19 @@ returns date language sql immutable strict -as $function$ +as $$ select $1::text::date -$function$; +$$; create cast (int as date) with function sql_to_date(int) as assignment; create function cast_invoker(int) returns date language plpgsql -as $function$ +as $$ begin return $1; -end -$function$; +end$$; select cast_invoker(20150717); @@ -4397,26 +4283,20 @@ drop function sql_to_date(int) cascade; begin; -do -$do$ -declare x text[]; begin x := '{1.23, 4.56}'::numeric[]; end -$do$; +do $$ declare x text[]; begin x := '{1.23, 4.56}'::numeric[]; end $$; -do -$do$ -declare x text[]; begin x := '{1.23, 4.56}'::numeric[]; end -$do$; +do $$ declare x text[]; begin x := '{1.23, 4.56}'::numeric[]; end $$; commit; create function fail() returns int language plpgsql -as $function$ +as $$ begin return 1/0; end -$function$; +$$; select fail(); @@ -4429,24 +4309,24 @@ set standard_conforming_strings = off; create or replace function strtest() returns text language plpgsql -as $function$ +as $$ begin raise notice 'foo\\bar\041baz'; return 'foo\\bar\041baz'; end -$function$; +$$; select strtest(); create or replace function strtest() returns text language plpgsql -as $function$ +as $$ begin raise notice E'foo\\bar\041baz'; return E'foo\\bar\041baz'; end -$function$; +$$; select strtest(); @@ -4455,59 +4335,50 @@ set standard_conforming_strings = 'on'; create or replace function strtest() returns text language plpgsql -as $function$ +as $$ begin raise notice 'foo\\bar\041baz\'; return 'foo\\bar\041baz\'; end -$function$; +$$; select strtest(); create or replace function strtest() returns text language plpgsql -as $function$ +as $$ begin raise notice E'foo\\bar\041baz'; return E'foo\\bar\041baz'; end -$function$; +$$; select strtest(); drop function strtest(); -do -$do$ +do $$ DECLARE r record; BEGIN FOR r IN SELECT rtrim(roomno) AS roomno, comment FROM Room ORDER BY roomno LOOP RAISE NOTICE '%, %', r.roomno, r.comment; END LOOP; -END -$do$; +END$$; -do -language plpgsql -$do$ -begin return 1; end -$do$; +do language plpgsql $$begin return 1; end$$; -do -$do$ +do $$ DECLARE r record; BEGIN FOR r IN SELECT rtrim(roomno) AS roomno, foo FROM Room ORDER BY roomno LOOP RAISE NOTICE '%, %', r.roomno, r.comment; END LOOP; -END -$do$; +END$$; -do -$do$ +do $outer$ begin for i in 1..10 loop begin @@ -4524,36 +4395,32 @@ begin end; end loop; end; -$do$; +$outer$; -do -$do$ +do $$ declare x int := x + 1; -- error begin raise notice 'x = %', x; end; -$do$; +$$; -do -$do$ +do $$ declare y int := x + 1; -- error x int := 42; begin raise notice 'x = %, y = %', x, y; end; -$do$; +$$; -do -$do$ +do $$ declare x int := 42; y int := x + 1; begin raise notice 'x = %, y = %', x, y; end; -$do$; +$$; -do -$do$ +do $$ declare x int := 42; begin declare y int := x + 1; @@ -4563,14 +4430,14 @@ begin raise notice 'x = %, y = %, z = %', x, y, z; end; end; -$do$; +$$; set plpgsql.variable_conflict = error; create function conflict_test() returns setof int8_tbl language plpgsql -as $function$ +as $$ declare r record; q1 bigint := 42; begin @@ -4578,14 +4445,14 @@ begin return next r; end loop; end; -$function$; +$$; select * from conflict_test(); create or replace function conflict_test() returns setof int8_tbl language plpgsql -as $function$ +as $$ #variable_conflict use_variable declare r record; q1 bigint := 42; @@ -4594,14 +4461,14 @@ begin return next r; end loop; end; -$function$; +$$; select * from conflict_test(); create or replace function conflict_test() returns setof int8_tbl language plpgsql -as $function$ +as $$ #variable_conflict use_column declare r record; q1 bigint := 42; @@ -4610,7 +4477,7 @@ begin return next r; end loop; end; -$function$; +$$; select * from conflict_test(); @@ -4619,35 +4486,35 @@ drop function conflict_test(); create function unreserved_test() returns int language plpgsql -as $function$ +as $$ declare forward int := 21; begin forward := forward * 2; return forward; end -$function$; +$$; select unreserved_test(); create or replace function unreserved_test() returns int language plpgsql -as $function$ +as $$ declare return int := 42; begin return := return + 1; return return; end -$function$; +$$; select unreserved_test(); create or replace function unreserved_test() returns int language plpgsql -as $function$ +as $$ declare comment int := 21; begin @@ -4655,7 +4522,7 @@ begin comment on function unreserved_test() is 'this is a test'; return comment; end -$function$; +$$; select unreserved_test(); @@ -4666,7 +4533,7 @@ drop function unreserved_test(); create function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int; begin foreach x in array $1 @@ -4674,7 +4541,7 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(array[1, 2, 3, 4]); @@ -4683,7 +4550,7 @@ select foreach_test(array[array[1, 2], array[3, 4]]); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int; begin foreach x slice 1 in array $1 @@ -4691,7 +4558,7 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(array[1, 2, 3, 4]); @@ -4700,7 +4567,7 @@ select foreach_test(array[array[1, 2], array[3, 4]]); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int[]; begin foreach x slice 1 in array $1 @@ -4708,7 +4575,7 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(array[1, 2, 3, 4]); @@ -4717,7 +4584,7 @@ select foreach_test(array[array[1, 2], array[3, 4]]); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int[]; begin foreach x slice 2 in array $1 @@ -4725,7 +4592,7 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(array[1, 2, 3, 4]); @@ -4738,7 +4605,7 @@ create type xy_tuple as (x int, y int); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare r record; begin foreach r in array $1 @@ -4746,21 +4613,20 @@ begin raise notice '%', r; end loop; end; -$function$; +$$; select foreach_test(cast(array[(10, 20), (40, 69), (35, 78)] as xy_tuple[])); select foreach_test( - cast(array[array[(10, 20), (40, 69)], - array[(35, 78), (88, 76)]] + cast(array[array[(10, 20), (40, 69)], array[(35, 78), (88, 76)]] as xy_tuple[]) ); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x int; y int; begin foreach x, y in array $1 @@ -4768,21 +4634,20 @@ begin raise notice 'x = %, y = %', x, y; end loop; end; -$function$; +$$; select foreach_test(cast(array[(10, 20), (40, 69), (35, 78)] as xy_tuple[])); select foreach_test( - cast(array[array[(10, 20), (40, 69)], - array[(35, 78), (88, 76)]] + cast(array[array[(10, 20), (40, 69)], array[(35, 78), (88, 76)]] as xy_tuple[]) ); create or replace function foreach_test(anyarray) returns void language plpgsql -as $function$ +as $$ declare x xy_tuple[]; begin foreach x slice 1 in array $1 @@ -4790,14 +4655,13 @@ begin raise notice '%', x; end loop; end; -$function$; +$$; select foreach_test(cast(array[(10, 20), (40, 69), (35, 78)] as xy_tuple[])); select foreach_test( - cast(array[array[(10, 20), (40, 69)], - array[(35, 78), (88, 76)]] + cast(array[array[(10, 20), (40, 69)], array[(35, 78), (88, 76)]] as xy_tuple[]) ); @@ -4813,22 +4677,21 @@ create temporary table rtype ( create function arrayassign1() returns text[] language plpgsql -as $function$ +as $$ declare r record; begin r := row(12, '{foo,bar,baz}')::rtype; r.ar[2] := 'replace'; return r.ar; -end -$function$; +end$$; select arrayassign1(); select arrayassign1(); create domain orderedarray as int[2] - constraint "sorted" check (value[1] < value[2]); + constraint sorted check (value[1] < value[2]); select cast('{1,2}' as orderedarray); @@ -4837,14 +4700,13 @@ select cast('{2,1}' as orderedarray); create function testoa(x1 int, x2 int, x3 int) returns orderedarray language plpgsql -as $function$ +as $$ declare res orderedarray; begin res := array[x1, x2]; res[2] := x3; return res; -end -$function$; +end$$; select testoa(1, 2, 3); @@ -4856,24 +4718,24 @@ select testoa(1, 2, 1); drop function arrayassign1(); -drop function testoa(int, int, int); +drop function testoa(x1 int, x2 int, x3 int); create function returns_rw_array(int) returns int[] language plpgsql stable -as $function$ -declare r int[]; +as $$ + declare r int[]; begin r := array[$1, $1]; return r; end; -$function$; +$$; create function consumes_rw_array(int[]) returns int language plpgsql stable -as $function$ -begin return $1[1]; end; -$function$; +as $$ + begin return $1[1]; end; +$$; select consumes_rw_array(returns_rw_array(42)); @@ -4881,20 +4743,14 @@ select i, a from - ( - select returns_rw_array(1) as a offset 0 - ) - as ss, + (select returns_rw_array(1) as a offset 0) as ss, lateral consumes_rw_array(a) as i; select i, a from - ( - select returns_rw_array(1) as a offset 0 - ) - as ss, + (select returns_rw_array(1) as a offset 0) as ss, lateral consumes_rw_array(a) as i; select consumes_rw_array(a), a from returns_rw_array(1) as a; @@ -4905,37 +4761,25 @@ select consumes_rw_array(a), a from - ( - values - (returns_rw_array(1)), - (returns_rw_array(2)) - ) - as v (a); + (values (returns_rw_array(1)), (returns_rw_array(2))) as v (a); select consumes_rw_array(a), a from - ( - values - (returns_rw_array(1)), - (returns_rw_array(2)) - ) - as v (a); - -do -$do$ + (values (returns_rw_array(1)), (returns_rw_array(2))) as v (a); + +do $$ declare a int[] := array[1,2]; begin a := a || 3; raise notice 'a = %', a; -end -$do$; +end$$; create function inner_func(int) returns int language plpgsql -as $function$ +as $$ declare _context text; begin get diagnostics _context = pg_context; @@ -4946,12 +4790,12 @@ begin raise notice 'lets make sure we didnt break anything'; return 2 * $1; end; -$function$; +$$; create or replace function outer_func(int) returns int language plpgsql -as $function$ +as $$ declare myresult int; begin @@ -4960,12 +4804,12 @@ begin raise notice 'inner_func() done'; return myresult; end; -$function$; +$$; create or replace function outer_outer_func(int) returns int language plpgsql -as $function$ +as $$ declare myresult int; begin @@ -4974,7 +4818,7 @@ begin raise notice 'outer_func() done'; return myresult; end; -$function$; +$$; select outer_outer_func(10); @@ -4989,7 +4833,7 @@ drop function inner_func(int); create function inner_func(int) returns int language plpgsql -as $function$ +as $$ declare _context text; sx int := 5; @@ -5008,12 +4852,12 @@ begin raise notice 'lets make sure we didnt break anything'; return 2 * $1; end; -$function$; +$$; create or replace function outer_func(int) returns int language plpgsql -as $function$ +as $$ declare myresult int; begin @@ -5022,12 +4866,12 @@ begin raise notice 'inner_func() done'; return myresult; end; -$function$; +$$; create or replace function outer_outer_func(int) returns int language plpgsql -as $function$ +as $$ declare myresult int; begin @@ -5036,7 +4880,7 @@ begin raise notice 'outer_func() done'; return myresult; end; -$function$; +$$; select outer_outer_func(10); @@ -5051,131 +4895,120 @@ drop function inner_func(int); create function current_function(text) returns regprocedure language plpgsql -as $function$ +as $$ declare fn_oid regprocedure; begin get diagnostics fn_oid = pg_routine_oid; return fn_oid; end; -$function$; +$$; select current_function('foo'); drop function current_function(text); -do -$do$ +do $$ declare fn_oid oid; begin get diagnostics fn_oid = pg_routine_oid; raise notice 'pg_routine_oid = %', fn_oid; end; -$do$; +$$; -do -$do$ +do $$ begin assert 1=1; -- should succeed end; -$do$; +$$; -do -$do$ +do $$ begin assert 1=0; -- should fail end; -$do$; +$$; -do -$do$ +do $$ begin assert NULL; -- should fail end; -$do$; +$$; set plpgsql.check_asserts = off; -do -$do$ +do $$ begin assert 1=0; -- won't be tested end; -$do$; +$$; reset plpgsql.check_asserts; -do -$do$ +do $$ declare var text := 'some value'; begin assert 1=0, format('assertion failed, var = "%s"', var); end; -$do$; +$$; -do -$do$ +do $$ begin assert 1=0, 'unhandled assertion'; exception when others then null; -- do nothing end; -$do$; +$$; create function plpgsql_domain_check(val int) returns boolean language plpgsql immutable -as $function$ +as $$ begin return val > 0; end -$function$; +$$; create domain plpgsql_domain as int check (plpgsql_domain_check(value)); -do -$do$ +do $$ declare v_test plpgsql_domain; begin v_test := 1; end; -$do$; +$$; -do -$do$ +do $$ declare v_test plpgsql_domain := 1; begin v_test := 0; -- fail end; -$do$; +$$; create function plpgsql_arr_domain_check(val int[]) returns boolean language plpgsql immutable -as $function$ +as $$ begin return val[1] > 0; end -$function$; +$$; create domain plpgsql_arr_domain as int[] check (plpgsql_arr_domain_check(value)); -do -$do$ +do $$ declare v_test plpgsql_arr_domain; begin v_test := array[1]; v_test := v_test || 2; end; -$do$; +$$; -do -$do$ +do $$ declare v_test plpgsql_arr_domain := array[1]; begin v_test := 0 || v_test; -- fail end; -$do$; +$$; create table transition_table_base ( id int primary key, @@ -5185,7 +5018,7 @@ create table transition_table_base ( create function transition_table_base_ins_func() returns trigger language plpgsql -as $function$ +as $$ DECLARE t text; l text; @@ -5202,7 +5035,7 @@ BEGIN RAISE INFO '%', t; RETURN new; END; -$function$; +$$; create trigger transition_table_base_ins_trig after insert @@ -5226,7 +5059,7 @@ insert into transition_table_base values (3, 'Three'), (4, 'Four'); create or replace function transition_table_base_upd_func() returns trigger language plpgsql -as $function$ +as $$ DECLARE t text; l text; @@ -5243,7 +5076,7 @@ BEGIN RAISE INFO '%', t; RETURN new; END; -$function$; +$$; create trigger transition_table_base_upd_trig after update @@ -5281,8 +5114,8 @@ create table transition_table_status ( create function transition_table_level1_ri_parent_del_func() returns trigger language plpgsql -as $function$ -DECLARE n bigint; +as $$ + DECLARE n bigint; BEGIN PERFORM FROM p JOIN transition_table_level2 c ON c.parent_no = p.level1_no; IF FOUND THEN @@ -5290,7 +5123,7 @@ DECLARE n bigint; END IF; RETURN NULL; END; -$function$; +$$; create trigger transition_table_level1_ri_parent_del_trigger after delete @@ -5302,8 +5135,8 @@ execute function transition_table_level1_ri_parent_del_func(); create function transition_table_level1_ri_parent_upd_func() returns trigger language plpgsql -as $function$ -DECLARE +as $$ + DECLARE x int; BEGIN WITH p AS (SELECT level1_no, sum(delta) cnt @@ -5320,7 +5153,7 @@ DECLARE END IF; RETURN NULL; END; -$function$; +$$; create trigger transition_table_level1_ri_parent_upd_trigger after update @@ -5333,8 +5166,8 @@ execute function transition_table_level1_ri_parent_upd_func(); create function transition_table_level2_ri_child_insupd_func() returns trigger language plpgsql -as $function$ -BEGIN +as $$ + BEGIN PERFORM FROM i LEFT JOIN transition_table_level1 p ON p.level1_no IS NOT NULL AND p.level1_no = i.parent_no @@ -5344,7 +5177,7 @@ BEGIN END IF; RETURN NULL; END; -$function$; +$$; create trigger transition_table_level2_ri_child_ins_trigger after insert @@ -5374,20 +5207,10 @@ from analyze transition_table_level2; insert into transition_table_status (level, node_no, status) -select - 1, - level1_no, - 0 -from - transition_table_level1; +select 1, level1_no, 0 from transition_table_level1; insert into transition_table_status (level, node_no, status) -select - 2, - level2_no, - 0 -from - transition_table_level2; +select 2, level2_no, 0 from transition_table_level2; analyze transition_table_status; @@ -5399,12 +5222,12 @@ analyze transition_table_level1; create function transition_table_level2_bad_usage_func() returns trigger language plpgsql -as $function$ -BEGIN +as $$ + BEGIN INSERT INTO dx VALUES (1000000, 1000000, 'x'); RETURN NULL; END; -$function$; +$$; create trigger transition_table_level2_bad_usage_trigger after delete @@ -5431,15 +5254,13 @@ delete from transition_table_level1 where level1_no between 201 and 1000; delete from transition_table_level1 where - level1_no - between 100000000 - and 100000010; + level1_no between 100000000 and 100000010; -select COUNT(*) from transition_table_level1; +select count(*) from transition_table_level1; delete from transition_table_level2 where level2_no between 211 and 220; -select COUNT(*) from transition_table_level2; +select count(*) from transition_table_level2; create table alter_table_under_transition_tables ( id int primary key, @@ -5449,7 +5270,7 @@ create table alter_table_under_transition_tables ( create function alter_table_under_transition_tables_upd_func() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE WARNING 'old table = %, new table = %', (SELECT string_agg(id || '=' || name, ',') FROM d), @@ -5457,7 +5278,7 @@ BEGIN RAISE NOTICE 'one = %', (SELECT 1 FROM alter_table_under_transition_tables LIMIT 1); RETURN NULL; END; -$function$; +$$; create trigger alter_table_under_transition_tables_upd_trigger after update or truncate @@ -5484,8 +5305,7 @@ alter table alter_table_under_transition_tables alter column name type int using cast(name as int); update alter_table_under_transition_tables -set name = cast(cast(name as text) || cast(name as text) -as int); +set name = cast(cast(name as text) || cast(name as text) as int); alter table alter_table_under_transition_tables drop column name; @@ -5499,15 +5319,14 @@ insert into multi_test values (1); create or replace function multi_test_trig() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'count = %', (SELECT COUNT(*) FROM new_test); RAISE NOTICE 'count union = %', (SELECT COUNT(*) FROM (SELECT * FROM new_test UNION ALL SELECT * FROM new_test) ss); RETURN NULL; -END -$function$; +END$$; create trigger my_trigger after update @@ -5527,7 +5346,7 @@ create table partitioned_table ( a int, b text ) -partition by LIST(a); +partition by list(a); create table pt_part1 partition of partitioned_table for values in (1); @@ -5540,7 +5359,7 @@ insert into partitioned_table values (2, 'Row 2'); create or replace function get_from_partitioned_table(partitioned_table.a%type) returns partitioned_table language plpgsql -as $function$ +as $$ DECLARE a_val partitioned_table.a%TYPE; result partitioned_table%ROWTYPE; @@ -5548,15 +5367,14 @@ BEGIN a_val := $1; SELECT * INTO result FROM partitioned_table WHERE a = a_val; RETURN result; -END; -$function$; +END; $$; select * from get_from_partitioned_table(1) as t; create or replace function list_partitioned_table() returns setof public.partitioned_table.a%type language plpgsql -as $function$ +as $$ DECLARE row public.partitioned_table%ROWTYPE; a_val public.partitioned_table.a%TYPE; @@ -5566,17 +5384,15 @@ BEGIN RETURN NEXT a_val; END LOOP; RETURN; -END; -$function$; +END; $$; select * from list_partitioned_table() as t; create function fx(x wslot) returns void language plpgsql -as $function$ +as $$ BEGIN GET DIAGNOSTICS x = ROW_COUNT; RETURN; -END; -$function$; +END; $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__point_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__point_100.snap index 1c77e7638..6bef8dcaa 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__point_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__point_100.snap @@ -80,16 +80,14 @@ from point_tbl as p1, point_tbl as p2 where - p1.f1 <-> p2.f1 > 3 and - p1.f1 << p2.f1 and - p1.f1 |>> p2.f1 + p1.f1 <-> p2.f1 > 3 and p1.f1 << p2.f1 and p1.f1 |>> p2.f1 order by distance; create temporary table point_gist_tbl (f1 point); insert into point_gist_tbl select '(0,0)' from generate_series(0, 1000); -create index "point_gist_tbl_index" on point_gist_tbl using gist (f1); +create index point_gist_tbl_index on point_gist_tbl using gist (f1); insert into point_gist_tbl values ('(0.0000009,0.0000009)'); @@ -99,18 +97,16 @@ set enable_indexscan = 'false'; set enable_bitmapscan = 'false'; -select COUNT(*) from point_gist_tbl where f1 ~= cast('(0.0000009,0.0000009)' as point); +select count(*) from point_gist_tbl where f1 ~= cast('(0.0000009,0.0000009)' as point); select - COUNT(*) + count(*) from point_gist_tbl where - f1 <@ - cast('(0.0000009,0.0000009),(0.0000009,0.0000009)' - as box); + f1 <@ cast('(0.0000009,0.0000009),(0.0000009,0.0000009)' as box); -select COUNT(*) from point_gist_tbl where f1 ~= cast('(0.0000018,0.0000018)' as point); +select count(*) from point_gist_tbl where f1 ~= cast('(0.0000018,0.0000018)' as point); set enable_seqscan = 'false'; @@ -118,18 +114,16 @@ set enable_indexscan = 'true'; set enable_bitmapscan = 'true'; -select COUNT(*) from point_gist_tbl where f1 ~= cast('(0.0000009,0.0000009)' as point); +select count(*) from point_gist_tbl where f1 ~= cast('(0.0000009,0.0000009)' as point); select - COUNT(*) + count(*) from point_gist_tbl where - f1 <@ - cast('(0.0000009,0.0000009),(0.0000009,0.0000009)' - as box); + f1 <@ cast('(0.0000009,0.0000009),(0.0000009,0.0000009)' as box); -select COUNT(*) from point_gist_tbl where f1 ~= cast('(0.0000018,0.0000018)' as point); +select count(*) from point_gist_tbl where f1 ~= cast('(0.0000018,0.0000018)' as point); reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__point_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__point_80.snap index 17cf98579..a47ce4a2e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__point_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__point_80.snap @@ -38,8 +38,7 @@ select from point_tbl as p where - p.f1 <@ - cast('[(0,0),(-10,0),(-10,10)]' as path); + p.f1 <@ cast('[(0,0),(-10,0),(-10,10)]' as path); select p.* from point_tbl as p where not cast('(0,0,100,100)' as box) @> p.f1; @@ -91,16 +90,14 @@ from point_tbl as p1, point_tbl as p2 where - p1.f1 <-> p2.f1 > 3 and - p1.f1 << p2.f1 and - p1.f1 |>> p2.f1 + p1.f1 <-> p2.f1 > 3 and p1.f1 << p2.f1 and p1.f1 |>> p2.f1 order by distance; create temporary table point_gist_tbl (f1 point); insert into point_gist_tbl select '(0,0)' from generate_series(0, 1000); -create index "point_gist_tbl_index" on point_gist_tbl using gist (f1); +create index point_gist_tbl_index on point_gist_tbl using gist (f1); insert into point_gist_tbl values ('(0.0000009,0.0000009)'); @@ -111,29 +108,25 @@ set enable_indexscan = 'false'; set enable_bitmapscan = 'false'; select - COUNT(*) + count(*) from point_gist_tbl where - f1 ~= - cast('(0.0000009,0.0000009)' as point); + f1 ~= cast('(0.0000009,0.0000009)' as point); select - COUNT(*) + count(*) from point_gist_tbl where - f1 <@ - cast('(0.0000009,0.0000009),(0.0000009,0.0000009)' - as box); + f1 <@ cast('(0.0000009,0.0000009),(0.0000009,0.0000009)' as box); select - COUNT(*) + count(*) from point_gist_tbl where - f1 ~= - cast('(0.0000018,0.0000018)' as point); + f1 ~= cast('(0.0000018,0.0000018)' as point); set enable_seqscan = 'false'; @@ -142,29 +135,25 @@ set enable_indexscan = 'true'; set enable_bitmapscan = 'true'; select - COUNT(*) + count(*) from point_gist_tbl where - f1 ~= - cast('(0.0000009,0.0000009)' as point); + f1 ~= cast('(0.0000009,0.0000009)' as point); select - COUNT(*) + count(*) from point_gist_tbl where - f1 <@ - cast('(0.0000009,0.0000009),(0.0000009,0.0000009)' - as box); + f1 <@ cast('(0.0000009,0.0000009),(0.0000009,0.0000009)' as box); select - COUNT(*) + count(*) from point_gist_tbl where - f1 ~= - cast('(0.0000018,0.0000018)' as point); + f1 ~= cast('(0.0000018,0.0000018)' as point); reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polygon_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polygon_100.snap index 7de9f17ff..8e502a705 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polygon_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polygon_100.snap @@ -38,9 +38,7 @@ create table quad_poly_tbl ( insert into quad_poly_tbl select (x - 1) * 100 + y, - polygon( - circle(point(x * 10, y * 10), 1 + (x + y) % 10) - ) + polygon(circle(point(x * 10, y * 10), 1 + (x + y) % 10)) from generate_series(1, 100) as x, generate_series(1, 100) as y; @@ -48,14 +46,13 @@ from insert into quad_poly_tbl select i, - cast('((200, 300),(210, 310),(230, 290))' - as polygon) + cast('((200, 300),(210, 310),(230, 290))' as polygon) from generate_series(10001, 11000) as i; insert into quad_poly_tbl values (11001, null), (11002, null), (11003, null); -create index "quad_poly_tbl_idx" on quad_poly_tbl using spgist (p); +create index quad_poly_tbl_idx on quad_poly_tbl using spgist (p); set enable_seqscan = 'on'; @@ -66,15 +63,13 @@ set enable_bitmapscan = off; create temporary table quad_poly_tbl_ord_seq2 as select - RANK() over (order by p <-> cast('123,456' as point)) as n, + rank() over (order by p <-> cast('123,456' as point)) as n, p <-> cast('123,456' as point) as dist, id from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); set enable_seqscan = off; @@ -83,220 +78,176 @@ set enable_indexscan = off; set enable_bitmapscan = 'on'; select - COUNT(*) + count(*) from quad_poly_tbl where - p << - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p << cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p << - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p << cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &< - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &< cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &< - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &< cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p && - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p && cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p && - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p && cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p >> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p >> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p >> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p >> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p <<| - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <<| cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p <<| - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <<| cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &<| - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &<| cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &<| - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &<| cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p |&> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p |&> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p |&> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p |&> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p |>> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p |>> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p |>> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p |>> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); -select COUNT(*) from quad_poly_tbl where p @> cast('((340,550),(343,552),(341,553))' as polygon); +select count(*) from quad_poly_tbl where p @> cast('((340,550),(343,552),(341,553))' as polygon); -select COUNT(*) from quad_poly_tbl where p @> cast('((340,550),(343,552),(341,553))' as polygon); +select count(*) from quad_poly_tbl where p @> cast('((340,550),(343,552),(341,553))' as polygon); -select COUNT(*) from quad_poly_tbl where p ~= cast('((200, 300),(210, 310),(230, 290))' as polygon); +select count(*) from quad_poly_tbl where p ~= cast('((200, 300),(210, 310),(230, 290))' as polygon); -select COUNT(*) from quad_poly_tbl where p ~= cast('((200, 300),(210, 310),(230, 290))' as polygon); +select count(*) from quad_poly_tbl where p ~= cast('((200, 300),(210, 310),(230, 290))' as polygon); set enable_indexscan = 'on'; set enable_bitmapscan = off; select - RANK() over (order by p <-> cast('123,456' as point)) as n, + rank() over (order by p <-> cast('123,456' as point)) as n, p <-> cast('123,456' as point) as dist, id from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); create temporary table quad_poly_tbl_ord_idx2 as select - RANK() over (order by p <-> cast('123,456' as point)) as n, + rank() over (order by p <-> cast('123,456' as point)) as n, p <-> cast('123,456' as point) as dist, id from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select * @@ -307,8 +258,7 @@ from on seq.n = idx.n and seq.id = idx.id and ( - seq.dist = idx.dist or - (seq.dist is null and idx.dist is null) + seq.dist = idx.dist or (seq.dist is null and idx.dist is null) ) where seq.id is null or idx.id is null; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polygon_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polygon_80.snap index a7cb2f7e7..8547d9ca8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polygon_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polygon_80.snap @@ -38,12 +38,7 @@ create table quad_poly_tbl ( insert into quad_poly_tbl select (x - 1) * 100 + y, - polygon( - circle( - point(x * 10, y * 10), - 1 + (x + y) % 10 - ) - ) + polygon(circle(point(x * 10, y * 10), 1 + (x + y) % 10)) from generate_series(1, 100) as x, generate_series(1, 100) as y; @@ -51,14 +46,13 @@ from insert into quad_poly_tbl select i, - cast('((200, 300),(210, 310),(230, 290))' - as polygon) + cast('((200, 300),(210, 310),(230, 290))' as polygon) from generate_series(10001, 11000) as i; insert into quad_poly_tbl values (11001, null), (11002, null), (11003, null); -create index "quad_poly_tbl_idx" on quad_poly_tbl using spgist (p); +create index quad_poly_tbl_idx on quad_poly_tbl using spgist (p); set enable_seqscan = 'on'; @@ -69,17 +63,13 @@ set enable_bitmapscan = off; create temporary table quad_poly_tbl_ord_seq2 as select - RANK() over ( - order by p <-> cast('123,456' as point) - ) as n, + rank() over (order by p <-> cast('123,456' as point)) as n, p <-> cast('123,456' as point) as dist, id from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); set enable_seqscan = off; @@ -88,252 +78,196 @@ set enable_indexscan = off; set enable_bitmapscan = 'on'; select - COUNT(*) + count(*) from quad_poly_tbl where - p << - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p << cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p << - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p << cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &< - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &< cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &< - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &< cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p && - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p && cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p && - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p && cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p >> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p >> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p >> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p >> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p <<| - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <<| cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p <<| - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <<| cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &<| - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &<| cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p &<| - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p &<| cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p |&> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p |&> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p |&> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p |&> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p |>> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p |>> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p |>> - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p |>> cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p @> - cast('((340,550),(343,552),(341,553))' - as polygon); + p @> cast('((340,550),(343,552),(341,553))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p @> - cast('((340,550),(343,552),(341,553))' - as polygon); + p @> cast('((340,550),(343,552),(341,553))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p ~= - cast('((200, 300),(210, 310),(230, 290))' - as polygon); + p ~= cast('((200, 300),(210, 310),(230, 290))' as polygon); select - COUNT(*) + count(*) from quad_poly_tbl where - p ~= - cast('((200, 300),(210, 310),(230, 290))' - as polygon); + p ~= cast('((200, 300),(210, 310),(230, 290))' as polygon); set enable_indexscan = 'on'; set enable_bitmapscan = off; select - RANK() over ( - order by p <-> cast('123,456' as point) - ) as n, + rank() over (order by p <-> cast('123,456' as point)) as n, p <-> cast('123,456' as point) as dist, id from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); create temporary table quad_poly_tbl_ord_idx2 as select - RANK() over ( - order by p <-> cast('123,456' as point) - ) as n, + rank() over (order by p <-> cast('123,456' as point)) as n, p <-> cast('123,456' as point) as dist, id from quad_poly_tbl where - p <@ - cast('((300,300),(400,600),(600,500),(700,200))' - as polygon); + p <@ cast('((300,300),(400,600),(600,500),(700,200))' as polygon); select * @@ -344,8 +278,7 @@ from on seq.n = idx.n and seq.id = idx.id and ( - seq.dist = idx.dist or - (seq.dist is null and idx.dist is null) + seq.dist = idx.dist or (seq.dist is null and idx.dist is null) ) where seq.id is null or idx.id is null; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_100.snap index b332a0c0c..542b19ac0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_100.snap @@ -5,167 +5,149 @@ input_file: crates/pgls_pretty_print/tests/data/multi/polymorphism.sql create function polyf(x anyelement) returns anyelement language sql -as $function$ -select x + 1 -$function$; +as $$ + select x + 1 +$$; select polyf(42) as int, polyf(4.5) as num; select polyf(point(3, 4)); -drop function polyf(anyelement); +drop function polyf(x anyelement); create function polyf(x anyelement) returns anyarray language sql -as $function$ -select array[x + 1, x + 2] -$function$; +as $$ + select array[x + 1, x + 2] +$$; select polyf(42) as int, polyf(4.5) as num; -drop function polyf(anyelement); +drop function polyf(x anyelement); create function polyf(x anyarray) returns anyelement language sql -as $function$ -select x[1] -$function$; +as $$ + select x[1] +$$; select polyf(array[2, 4]) as int, polyf(array[4.5, 7.7]) as num; select polyf(stavalues1) from pg_statistic; -drop function polyf(anyarray); +drop function polyf(x anyarray); create function polyf(x anyarray) returns anyarray language sql -as $function$ -select x -$function$; +as $$ + select x +$$; select polyf(array[2, 4]) as int, polyf(array[4.5, 7.7]) as num; select polyf(stavalues1) from pg_statistic; -drop function polyf(anyarray); +drop function polyf(x anyarray); create function polyf(x anyelement) returns anyrange language sql -as $function$ -select array[x + 1, x + 2] -$function$; +as $$ + select array[x + 1, x + 2] +$$; create function polyf(x anyrange) returns anyarray language sql -as $function$ -select array[lower(x), upper(x)] -$function$; +as $$ + select array[lower(x), upper(x)] +$$; select polyf(int4range(42, 49)) as int, polyf(float8range(4.5, 7.8)) as num; -drop function polyf(anyrange); +drop function polyf(x anyrange); create function polyf(x anycompatible, y anycompatible) returns anycompatiblearray language sql -as $function$ -select array[x, y] -$function$; +as $$ + select array[x, y] +$$; select polyf(2, 4) as int, polyf(2, 4.5) as num; -drop function polyf(anycompatible, anycompatible); +drop function polyf(x anycompatible, y anycompatible); create function polyf(x anycompatiblerange, y anycompatible, z anycompatible) returns anycompatiblearray language sql -as $function$ -select array[lower(x), upper(x), y, z] -$function$; +as $$ + select array[lower(x), upper(x), y, z] +$$; select - polyf(int4range(42, 49), 11, cast(2 as smallint)) - as int, - polyf( - float8range(4.5, 7.8), - 7.8, - cast(11 as real) - ) - as num; + polyf(int4range(42, 49), 11, cast(2 as smallint)) as int, + polyf(float8range(4.5, 7.8), 7.8, cast(11 as real)) as num; select polyf(int4range(42, 49), 11, 4.5) as fail; -drop function polyf(anycompatiblerange, anycompatible, anycompatible); +drop function polyf(x anycompatiblerange, y anycompatible, z anycompatible); create function polyf(x anycompatiblemultirange, y anycompatible, z anycompatible) returns anycompatiblearray language sql -as $function$ -select array[lower(x), upper(x), y, z] -$function$; +as $$ + select array[lower(x), upper(x), y, z] +$$; select - polyf( - multirange(int4range(42, 49)), - 11, - cast(2 as smallint) - ) - as int, - polyf( - multirange(float8range(4.5, 7.8)), - 7.8, - cast(11 as real) - ) - as num; + polyf(multirange(int4range(42, 49)), 11, cast(2 as smallint)) as int, + polyf(multirange(float8range(4.5, 7.8)), 7.8, cast(11 as real)) as num; select polyf(multirange(int4range(42, 49)), 11, 4.5) as fail; -drop function polyf(anycompatiblemultirange, anycompatible, anycompatible); +drop function polyf(x anycompatiblemultirange, y anycompatible, z anycompatible); create function polyf(x anycompatible) returns anycompatiblerange language sql -as $function$ -select array[x + 1, x + 2] -$function$; +as $$ + select array[x + 1, x + 2] +$$; create function polyf(x anycompatiblerange, y anycompatiblearray) returns anycompatiblerange language sql -as $function$ -select x -$function$; +as $$ + select x +$$; select polyf(int4range(42, 49), array[11]) as int, polyf(float8range(4.5, 7.8), array[7]) as num; -drop function polyf(anycompatiblerange, anycompatiblearray); +drop function polyf(x anycompatiblerange, y anycompatiblearray); create function polyf(x anycompatible) returns anycompatiblemultirange language sql -as $function$ -select array[x + 1, x + 2] -$function$; +as $$ + select array[x + 1, x + 2] +$$; create function polyf(x anycompatiblemultirange, y anycompatiblearray) returns anycompatiblemultirange language sql -as $function$ -select x -$function$; +as $$ + select x +$$; select - polyf(multirange(int4range(42, 49)), array[11]) - as int, - polyf(multirange(float8range(4.5, 7.8)), array[7]) - as num; + polyf(multirange(int4range(42, 49)), array[11]) as int, + polyf(multirange(float8range(4.5, 7.8)), array[7]) as num; -drop function polyf(anycompatiblemultirange, anycompatiblearray); +drop function polyf(x anycompatiblemultirange, y anycompatiblearray); create function polyf( @@ -177,9 +159,9 @@ polyf( out y anycompatiblearray ) language sql -as $function$ -select a || b, array[c, d] -$function$; +as $$ + select a || b, array[c, d] +$$; select x, pg_typeof(x), y, pg_typeof(y) from polyf(11, array[1, 2], 42, 34.5); @@ -189,14 +171,12 @@ select x, pg_typeof(x), y, pg_typeof(y) from polyf(11, '{1,2}', point(1, 2), '(3 select x, pg_typeof(x), y, pg_typeof(y) from polyf(11, array[1, 2.2], 42, 34.5); -drop function polyf(anyelement, anyarray, anycompatible, anycompatible); +drop function polyf(a anyelement, b anyarray, c anycompatible, d anycompatible); create function polyf(anyrange) returns anymultirange language sql -as $function$ -select multirange($1); -$function$; +as 'select multirange($1);'; select polyf(int4range(1, 10)); @@ -207,9 +187,7 @@ drop function polyf(anyrange); create function polyf(anymultirange) returns anyelement language sql -as $function$ -select lower($1); -$function$; +as 'select lower($1);'; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -220,9 +198,7 @@ drop function polyf(anymultirange); create function polyf(anycompatiblerange) returns anycompatiblemultirange language sql -as $function$ -select multirange($1); -$function$; +as 'select multirange($1);'; select polyf(int4range(1, 10)); @@ -233,9 +209,7 @@ drop function polyf(anycompatiblerange); create function polyf(anymultirange) returns anyrange language sql -as $function$ -select range_merge($1); -$function$; +as 'select range_merge($1);'; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -246,9 +220,7 @@ drop function polyf(anymultirange); create function polyf(anycompatiblemultirange) returns anycompatiblerange language sql -as $function$ -select range_merge($1); -$function$; +as 'select range_merge($1);'; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -259,9 +231,7 @@ drop function polyf(anycompatiblemultirange); create function polyf(anycompatiblemultirange) returns anycompatible language sql -as $function$ -select lower($1); -$function$; +as 'select lower($1);'; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -272,74 +242,56 @@ drop function polyf(anycompatiblemultirange); create function stfp(anyarray) returns anyarray language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function stfnp(int[]) returns int[] language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function tfp(anyarray, anyelement) returns anyarray language sql -as $function$ -select $1 || $2 -$function$; +as 'select $1 || $2'; create function tfnp(int[], int) returns int[] language sql -as $function$ -select $1 || $2 -$function$; +as 'select $1 || $2'; create function tf1p(anyarray, int) returns anyarray language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function tf2p(int[], anyelement) returns int[] language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function sum3(anyelement, anyelement, anyelement) returns anyelement language sql strict -as $function$ -select $1+$2+$3 -$function$; +as 'select $1+$2+$3'; create function ffp(anyarray) returns anyarray language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function ffnp(int[]) returns int[] language sql -as $function$ -select $1 -$function$; +as 'select $1'; -create aggregate myaggp01a (*) (sfunc = stfnp, stype = int[], finalfunc = ffp, initcond = '{}'); +create aggregate myaggp01a (*) (sfunc = stfnp, stype = int4[], finalfunc = ffp, initcond = '{}'); create aggregate myaggp02a (*) (sfunc = stfnp, stype = anyarray, finalfunc = ffp, initcond = '{}'); -create aggregate myaggp03a (*) (sfunc = stfp, stype = int[], finalfunc = ffp, initcond = '{}'); +create aggregate myaggp03a (*) (sfunc = stfp, stype = int4[], finalfunc = ffp, initcond = '{}'); -create aggregate myaggp03b (*) (sfunc = stfp, stype = int[], initcond = '{}'); +create aggregate myaggp03b (*) (sfunc = stfp, stype = int4[], initcond = '{}'); create aggregate myaggp04a (*) (sfunc = stfp, stype = anyarray, finalfunc = ffp, initcond = '{}'); @@ -489,15 +441,15 @@ create aggregate myaggp20a ( create aggregate myaggp20b (basetype = anyelement, sfunc = tfp, stype = anyarray, initcond = '{}'); -create aggregate myaggn01a (*) (sfunc = stfnp, stype = int[], finalfunc = ffnp, initcond = '{}'); +create aggregate myaggn01a (*) (sfunc = stfnp, stype = int4[], finalfunc = ffnp, initcond = '{}'); -create aggregate myaggn01b (*) (sfunc = stfnp, stype = int[], initcond = '{}'); +create aggregate myaggn01b (*) (sfunc = stfnp, stype = int4[], initcond = '{}'); create aggregate myaggn02a (*) (sfunc = stfnp, stype = anyarray, finalfunc = ffnp, initcond = '{}'); create aggregate myaggn02b (*) (sfunc = stfnp, stype = anyarray, initcond = '{}'); -create aggregate myaggn03a (*) (sfunc = stfp, stype = int[], finalfunc = ffnp, initcond = '{}'); +create aggregate myaggn03a (*) (sfunc = stfp, stype = int4[], finalfunc = ffnp, initcond = '{}'); create aggregate myaggn04a (*) (sfunc = stfp, stype = anyarray, finalfunc = ffnp, initcond = '{}'); @@ -720,19 +672,17 @@ select mysum2(f1, f1 + 1) from t; create function bleat(int) returns int language plpgsql -as $function$ +as $$ begin raise notice 'bleat %', $1; return $1; -end -$function$; +end$$; -create function sql_if(boolean, anyelement, anyelement) +create function sql_if(bool, anyelement, anyelement) returns anyelement language sql -as $function$ -select case when $1 then $2 else $3 end -$function$; +as $$ +select case when $1 then $2 else $3 end $$; select f1, sql_if(f1 > 0, bleat(f1), bleat(f1 + 1)) from int4_tbl; @@ -751,18 +701,13 @@ select array_larger_accum(i) from (values (array[1, 2]), (array[3, 4])) as t (i) select array_larger_accum(i) from - ( - values - (array[row(1, 2), row(3, 4)]), - (array[row(5, 6), row(7, 8)]) - ) - as t (i); + (values (array[row(1, 2), row(3, 4)]), (array[row(5, 6), row(7, 8)])) as t (i); create function add_group(grp anyarray, ad anyelement, size int) returns anyarray language plpgsql immutable -as $function$ +as $$ begin if grp is null then return array[ad]; @@ -772,38 +717,34 @@ begin end if; return grp; end; -$function$; +$$; create aggregate build_group (anyelement, int) (sfunc = add_group, stype = anyarray); select build_group(q1, 3) from int8_tbl; -create aggregate build_group (bigint, int) (sfunc = add_group, stype = smallint[]); +create aggregate build_group (int8, int) (sfunc = add_group, stype = int2[]); -create aggregate build_group (bigint, int) (sfunc = add_group, stype = bigint[]); +create aggregate build_group (int8, int) (sfunc = add_group, stype = int8[]); create function first_el_transfn(anyarray, anyelement) returns anyarray language sql immutable -as $function$ -select $1 || $2 -$function$; +as 'select $1 || $2'; create function first_el(anyarray) returns anyelement language sql immutable strict -as $function$ -select $1[1] -$function$; +as 'select $1[1]'; create aggregate first_el_agg_f8 ( - double precision + float8 ) ( sfunc = array_append, - stype = double precision[], + stype = float8[], finalfunc = first_el ); @@ -815,20 +756,17 @@ create aggregate first_el_agg_any ( finalfunc = first_el ); -select first_el_agg_f8(cast(x as double precision)) from generate_series(1, 10) as x; +select first_el_agg_f8(cast(x as float8)) from generate_series(1, 10) as x; select first_el_agg_any(x) from generate_series(1, 10) as x; -select - first_el_agg_f8(cast(x as double precision)) over (order by x) -from - generate_series(1, 10) as x; +select first_el_agg_f8(cast(x as float8)) over (order by x) from generate_series(1, 10) as x; select first_el_agg_any(x) over (order by x) from generate_series(1, 10) as x; select distinct array_ndims(histogram_bounds) from pg_stats where histogram_bounds is not null; -select MAX(histogram_bounds) from pg_stats where tablename = 'pg_am'; +select max(histogram_bounds) from pg_stats where tablename = 'pg_am'; select array_in('{1,2,3}', cast('int4' as regtype), -1); @@ -841,9 +779,9 @@ returns anyelement language sql immutable strict -as $function$ -select min($1[i]) from generate_subscripts($1,1) g(i) -$function$; +as $$ + select min($1[i]) from generate_subscripts($1,1) g(i) +$$; select myleast(10, 1, 20, 33); @@ -864,9 +802,9 @@ returns text language sql immutable strict -as $function$ -select array_to_string($2, $1); -$function$; +as $$ + select array_to_string($2, $1); +$$; select concat('%', 1, 2, 3, 4, 5); @@ -883,9 +821,9 @@ returns anyarray language sql immutable strict -as $function$ -select array_prepend($1, $2); -$function$; +as $$ + select array_prepend($1, $2); +$$; select formarray(1, 2, 3, 4, 5); @@ -897,7 +835,7 @@ select formarray(1, cast('x' as text)); select formarray(1, variadic array[cast('x' as text)]); -drop function formarray(anyelement, anyarray); +drop function formarray(anyelement, variadic anyarray); select pg_typeof(null); @@ -920,9 +858,9 @@ select pg_typeof(myleast(10, 1, 20, 33)); create function dfunc(a int default 1, int default 2) returns int language sql -as $function$ -select $1 + $2; -$function$; +as $$ + select $1 + $2; +$$; select dfunc(); @@ -941,15 +879,15 @@ drop function dfunc(int, int); create function dfunc(a int default 1, b int) returns int language sql -as $function$ -select $1 + $2; -$function$; +as $$ + select $1 + $2; +$$; create function dfunc(a int default 1, out sum int, b int default 2) language sql -as $function$ -select $1 + $2; -$function$; +as $$ + select $1 + $2; +$$; select dfunc(); @@ -958,18 +896,18 @@ drop function dfunc(int, int); create function dfunc(a int default 1.0, int default '-1') returns int language sql -as $function$ -select $1 + $2; -$function$; +as $$ + select $1 + $2; +$$; select dfunc(); create function dfunc(a text default 'Hello', b text default 'World') returns text language sql -as $function$ -select $1 || ', ' || $2; -$function$; +as $$ + select $1 || ', ' || $2; +$$; select dfunc(); @@ -988,16 +926,16 @@ drop function dfunc(text, text); create function dfunc(int default 1, int default 2) returns int language sql -as $function$ -select 2; -$function$; +as $$ + select 2; +$$; create function dfunc(int default 1, int default 2, int default 3, int default 4) returns int language sql -as $function$ -select 4; -$function$; +as $$ + select 4; +$$; select dfunc(); @@ -1016,16 +954,16 @@ drop function dfunc(int, int, int, int); create function dfunc(out int default 20) returns int language sql -as $function$ -select 1; -$function$; +as $$ + select 1; +$$; create function dfunc(anyelement default cast('World' as text)) returns text language sql -as $function$ -select 'Hello, ' || $1::text; -$function$; +as $$ + select 'Hello, ' || $1::text; +$$; select dfunc(); @@ -1040,9 +978,7 @@ drop function dfunc(anyelement); create function dfunc(variadic a int[]) returns int language sql -as $function$ -select array_upper($1, 1) -$function$; +as $$ select array_upper($1, 1) $$; select dfunc(); @@ -1053,9 +989,7 @@ select dfunc(10, 20); create or replace function dfunc(variadic a int[] default cast(array[] as int[])) returns int language sql -as $function$ -select array_upper($1, 1) -$function$; +as $$ select array_upper($1, 1) $$; select dfunc(); @@ -1066,32 +1000,30 @@ select dfunc(10, 20); create or replace function dfunc(variadic a int[]) returns int language sql -as $function$ -select array_upper($1, 1) -$function$; +as $$ select array_upper($1, 1) $$; -drop function dfunc(int[]); +drop function dfunc(variadic a int[]); create function dfunc(int default 1, int default 2, int default 3) returns int language sql -as $function$ -select 3; -$function$; +as $$ + select 3; +$$; create function dfunc(int default 1, int default 2) returns int language sql -as $function$ -select 2; -$function$; +as $$ + select 2; +$$; create function dfunc(text) returns text language sql -as $function$ -select $1; -$function$; +as $$ + select $1; +$$; select dfunc(1); @@ -1111,68 +1043,68 @@ returns table ( d int ) language sql -as $function$ -select $1, $2, $3, $4; -$function$; +as $$ + select $1, $2, $3, $4; +$$; select (dfunc(10, 20, 30)).*; -select (dfunc("a" := 10, "b" := 20, "c" := 30)).*; +select (dfunc(a := 10, b := 20, c := 30)).*; -select * from dfunc("a" := 10, "b" := 20); +select * from dfunc(a := 10, b := 20); -select * from dfunc("b" := 10, "a" := 20); +select * from dfunc(b := 10, a := 20); select * from dfunc(0); select * from dfunc(1, 2); -select * from dfunc(1, 2, "c" := 3); +select * from dfunc(1, 2, c := 3); -select * from dfunc(1, 2, "d" := 3); +select * from dfunc(1, 2, d := 3); -select * from dfunc("x" := 20, "b" := 10, "x" := 30); +select * from dfunc(x := 20, b := 10, x := 30); -select * from dfunc(10, "b" := 20, 30); +select * from dfunc(10, b := 20, 30); -select * from dfunc("x" := 10, "b" := 20, "c" := 30); +select * from dfunc(x := 10, b := 20, c := 30); -select * from dfunc(10, 10, "a" := 20); +select * from dfunc(10, 10, a := 20); -select * from dfunc(1, "c" := 2, "d" := 3); +select * from dfunc(1, c := 2, d := 3); drop function dfunc(int, int, int, int); create function xleast(x numeric, variadic arr numeric[]) returns numeric language sql -as $function$ -select least(x, min(arr[i])) from generate_subscripts(arr, 1) g(i); -$function$; +as $$ + select least(x, min(arr[i])) from generate_subscripts(arr, 1) g(i); +$$; -select xleast("x" := 1, variadic "arr" := array[2, 3]); +select xleast(x := 1, variadic arr := array[2, 3]); -select xleast(1, variadic "arr" := array[2, 3]); +select xleast(1, variadic arr := array[2, 3]); set search_path to pg_catalog; -select xleast(1, variadic "arr" := array[2, 3]); +select xleast(1, variadic arr := array[2, 3]); reset search_path; -select xleast("foo" := 1, variadic "arr" := array[2, 3]); +select xleast(foo := 1, variadic arr := array[2, 3]); -select xleast("x" := 1, variadic array[2, 3]); +select xleast(x := 1, variadic array[2, 3]); -select xleast(1, variadic "x" := array[2, 3]); +select xleast(1, variadic x := array[2, 3]); -select xleast("arr" := array[1], variadic "x" := 3); +select xleast(arr := array[1], variadic x := 3); -select xleast("arr" := array[1], "x" := 3); +select xleast(arr := array[1], x := 3); -select xleast("arr" := 1, variadic "x" := array[2, 3]); +select xleast(arr := 1, variadic x := array[2, 3]); -drop function xleast(numeric, numeric[]); +drop function xleast(x numeric, variadic arr numeric[]); create function dfunc(a varchar, b numeric, c date default current_date) returns table ( @@ -1181,21 +1113,21 @@ returns table ( c date ) language sql -as $function$ -select $1, $2, $3; -$function$; +as $$ + select $1, $2, $3; +$$; select (dfunc('Hello World', 20, cast('2009-07-25' as date))).*; select * from dfunc('Hello World', 20, cast('2009-07-25' as date)); -select * from dfunc("c" := cast('2009-07-25' as date), "a" := 'Hello World', "b" := 20); +select * from dfunc(c := cast('2009-07-25' as date), a := 'Hello World', b := 20); -select * from dfunc('Hello World', "b" := 20, "c" := cast('2009-07-25' as date)); +select * from dfunc('Hello World', b := 20, c := cast('2009-07-25' as date)); -select * from dfunc('Hello World', "c" := cast('2009-07-25' as date), "b" := 20); +select * from dfunc('Hello World', c := cast('2009-07-25' as date), b := 20); -select * from dfunc('Hello World', "c" := 20, "b" := cast('2009-07-25' as date)); +select * from dfunc('Hello World', c := 20, b := cast('2009-07-25' as date)); drop function dfunc(varchar, numeric, date); @@ -1208,9 +1140,9 @@ dfunc( ) returns record language sql -as $function$ -select $1, $2; -$function$; +as $$ + select $1, $2; +$$; select (dfunc()).*; @@ -1218,15 +1150,15 @@ select * from dfunc(); select * from dfunc('Hello', 100); -select * from dfunc("a" := 'Hello', "c" := 100); +select * from dfunc(a := 'Hello', c := 100); -select * from dfunc("c" := 100, "a" := 'Hello'); +select * from dfunc(c := 100, a := 'Hello'); select * from dfunc('Hello'); -select * from dfunc('Hello', "c" := 100); +select * from dfunc('Hello', c := 100); -select * from dfunc("c" := 100); +select * from dfunc(c := 100); create or replace function dfunc( @@ -1237,9 +1169,9 @@ dfunc( ) returns record language sql -as $function$ -select $1, $2; -$function$; +as $$ + select $1, $2; +$$; create or replace function dfunc( @@ -1250,46 +1182,36 @@ dfunc( ) returns record language sql -as $function$ -select $1, $2; -$function$; +as $$ + select $1, $2; +$$; drop function dfunc(varchar, numeric); create function testpolym(a int, a int) returns int language sql -as $function$ -select 1; -$function$; +as $$ select 1;$$; create function testpolym(int, out a int, out a int) returns int language sql -as $function$ -select 1; -$function$; +as $$ select 1;$$; create function testpolym(out a int, inout a int) returns int language sql -as $function$ -select 1; -$function$; +as $$ select 1;$$; create function testpolym(a int, inout a int) returns int language sql -as $function$ -select 1; -$function$; +as $$ select 1;$$; create function testpolym(a int, out a int) returns int language sql -as $function$ -select $1; -$function$; +as $$ select $1;$$; select testpolym(37); @@ -1300,93 +1222,90 @@ returns table ( a int ) language sql -as $function$ -select $1; -$function$; +as $$ select $1;$$; select * from testpolym(37); drop function testpolym(int); -create function dfunc(a anyelement, b anyelement default null, flag boolean default true) +create function dfunc(a anyelement, b anyelement default null, flag bool default true) returns anyelement language sql -as $function$ -select case when $3 then $1 else $2 end; -$function$; +as $$ + select case when $3 then $1 else $2 end; +$$; select dfunc(1, 2); select dfunc(cast('a' as text), 'b'); -select dfunc("a" := 1, "b" := 2); +select dfunc(a := 1, b := 2); -select dfunc("a" := cast('a' as text), "b" := 'b'); +select dfunc(a := cast('a' as text), b := 'b'); -select dfunc("a" := cast('a' as text), "b" := 'b', "flag" := false); +select dfunc(a := cast('a' as text), b := 'b', flag := false); -select dfunc("b" := cast('b' as text), "a" := 'a'); +select dfunc(b := cast('b' as text), a := 'a'); -select dfunc("a" := cast('a' as text), "flag" := true); +select dfunc(a := cast('a' as text), flag := true); -select dfunc("a" := cast('a' as text), "flag" := false); +select dfunc(a := cast('a' as text), flag := false); -select dfunc("b" := cast('b' as text), "a" := 'a', "flag" := true); +select dfunc(b := cast('b' as text), a := 'a', flag := true); select dfunc(cast('a' as text), 'b', false); -select dfunc(cast('a' as text), 'b', "flag" := false); +select dfunc(cast('a' as text), 'b', flag := false); select dfunc(cast('a' as text), 'b', true); -select dfunc(cast('a' as text), 'b', "flag" := true); +select dfunc(cast('a' as text), 'b', flag := true); -select dfunc("a" := 1, "b" := 2); +select dfunc(a := 1, b := 2); -select dfunc("a" := cast('a' as text), "b" := 'b'); +select dfunc(a := cast('a' as text), b := 'b'); -select dfunc("a" := cast('a' as text), "b" := 'b', "flag" := false); +select dfunc(a := cast('a' as text), b := 'b', flag := false); -select dfunc("b" := cast('b' as text), "a" := 'a'); +select dfunc(b := cast('b' as text), a := 'a'); -select dfunc("a" := cast('a' as text), "flag" := true); +select dfunc(a := cast('a' as text), flag := true); -select dfunc("a" := cast('a' as text), "flag" := false); +select dfunc(a := cast('a' as text), flag := false); -select dfunc("b" := cast('b' as text), "a" := 'a', "flag" := true); +select dfunc(b := cast('b' as text), a := 'a', flag := true); select dfunc(cast('a' as text), 'b', false); -select dfunc(cast('a' as text), 'b', "flag" := false); +select dfunc(cast('a' as text), 'b', flag := false); select dfunc(cast('a' as text), 'b', true); -select dfunc(cast('a' as text), 'b', "flag" := true); +select dfunc(cast('a' as text), 'b', flag := true); -select dfunc("a" := -1); +select dfunc(a := -1); -select dfunc("a" := +1); +select dfunc(a := +1); -select dfunc("a" := 1); +select dfunc(a := 1); -select dfunc("a" := 1); +select dfunc(a := 1); -do -$do$ -declare r integer; +do $$ + declare r integer; begin select dfunc(a=>-- comment 1) into r; raise info 'r = %', r; end; -$do$; +$$; create view dfview as select q1, q2, - dfunc(q1, q2, "flag" := q1 > q2) as c3, - dfunc(q1, "flag" := q1 < q2, "b" := q2) as c4 + dfunc(q1, q2, flag := q1 > q2) as c3, + dfunc(q1, flag := q1 < q2, b := q2) as c4 from int8_tbl; @@ -1394,14 +1313,14 @@ select * from dfview; drop view dfview; -drop function dfunc(anyelement, anyelement, boolean); +drop function dfunc(anyelement, anyelement, bool); create function anyctest(anycompatible, anycompatible) returns anycompatible language sql -as $function$ -select greatest($1, $2) -$function$; +as $$ + select greatest($1, $2) +$$; select x, pg_typeof(x) from anyctest(11, 12) as x; @@ -1416,9 +1335,9 @@ drop function anyctest(anycompatible, anycompatible); create function anyctest(anycompatible, anycompatible) returns anycompatiblearray language sql -as $function$ -select array[$1, $2] -$function$; +as $$ + select array[$1, $2] +$$; select x, pg_typeof(x) from anyctest(11, 12) as x; @@ -1431,9 +1350,9 @@ drop function anyctest(anycompatible, anycompatible); create function anyctest(anycompatible, anycompatiblearray) returns anycompatiblearray language sql -as $function$ -select array[$1] || $2 -$function$; +as $$ + select array[$1] || $2 +$$; select x, pg_typeof(x) from anyctest(11, array[12]) as x; @@ -1452,9 +1371,9 @@ drop function anyctest(anycompatible, anycompatiblearray); create function anyctest(anycompatible, anycompatiblerange) returns anycompatiblerange language sql -as $function$ -select $2 -$function$; +as $$ + select $2 +$$; select x, pg_typeof(x) from anyctest(11, int4range(4, 7)) as x; @@ -1471,9 +1390,9 @@ drop function anyctest(anycompatible, anycompatiblerange); create function anyctest(anycompatiblerange, anycompatiblerange) returns anycompatible language sql -as $function$ -select lower($1) + upper($2) -$function$; +as $$ + select lower($1) + upper($2) +$$; select x, pg_typeof(x) from anyctest(int4range(11, 12), int4range(4, 7)) as x; @@ -1484,16 +1403,16 @@ drop function anyctest(anycompatiblerange, anycompatiblerange); create function anyctest(anycompatible) returns anycompatiblerange language sql -as $function$ -select $1 -$function$; +as $$ + select $1 +$$; create function anyctest(anycompatible, anycompatiblemultirange) returns anycompatiblemultirange language sql -as $function$ -select $2 -$function$; +as $$ + select $2 +$$; select x, pg_typeof(x) from anyctest(11, multirange(int4range(4, 7))) as x; @@ -1510,45 +1429,37 @@ drop function anyctest(anycompatible, anycompatiblemultirange); create function anyctest(anycompatiblemultirange, anycompatiblemultirange) returns anycompatible language sql -as $function$ -select lower($1) + upper($2) -$function$; +as $$ + select lower($1) + upper($2) +$$; select x, pg_typeof(x) from - anyctest( - multirange(int4range(11, 12)), - multirange(int4range(4, 7)) - ) - as x; + anyctest(multirange(int4range(11, 12)), multirange(int4range(4, 7))) as x; select x, pg_typeof(x) from - anyctest( - multirange(int4range(11, 12)), - multirange(numrange(4, 7)) - ) - as x; + anyctest(multirange(int4range(11, 12)), multirange(numrange(4, 7))) as x; drop function anyctest(anycompatiblemultirange, anycompatiblemultirange); create function anyctest(anycompatible) returns anycompatiblemultirange language sql -as $function$ -select $1 -$function$; +as $$ + select $1 +$$; create function anyctest(anycompatiblenonarray, anycompatiblenonarray) returns anycompatiblearray language sql -as $function$ -select array[$1, $2] -$function$; +as $$ + select array[$1, $2] +$$; select x, pg_typeof(x) from anyctest(11, 12) as x; @@ -1561,9 +1472,9 @@ drop function anyctest(anycompatiblenonarray, anycompatiblenonarray); create function anyctest(a anyelement, b anyarray, c anycompatible, d anycompatible) returns anycompatiblearray language sql -as $function$ -select array[c, d] -$function$; +as $$ + select array[c, d] +$$; select x, pg_typeof(x) from anyctest(11, array[1, 2], 42, 34.5) as x; @@ -1573,14 +1484,14 @@ select x, pg_typeof(x) from anyctest(11, '{1,2}', point(1, 2), '(3,4)') as x; select x, pg_typeof(x) from anyctest(11, array[1, 2.2], 42, 34.5) as x; -drop function anyctest(anyelement, anyarray, anycompatible, anycompatible); +drop function anyctest(a anyelement, b anyarray, c anycompatible, d anycompatible); create function anyctest(variadic anycompatiblearray) returns anycompatiblearray language sql -as $function$ -select $1 -$function$; +as $$ + select $1 +$$; select x, pg_typeof(x) from anyctest(11, 12) as x; @@ -1594,4 +1505,4 @@ select x, pg_typeof(x) from anyctest(variadic array[11, 12]) as x; select x, pg_typeof(x) from anyctest(variadic array[11, 12.2]) as x; -drop function anyctest(anycompatiblearray); +drop function anyctest(variadic anycompatiblearray); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_80.snap index a986959b3..9d56eacc8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_80.snap @@ -5,106 +5,96 @@ input_file: crates/pgls_pretty_print/tests/data/multi/polymorphism.sql create function polyf(x anyelement) returns anyelement language sql -as $function$ -select x + 1 -$function$; +as $$ + select x + 1 +$$; select polyf(42) as int, polyf(4.5) as num; select polyf(point(3, 4)); -drop function polyf(anyelement); +drop function polyf(x anyelement); create function polyf(x anyelement) returns anyarray language sql -as $function$ -select array[x + 1, x + 2] -$function$; +as $$ + select array[x + 1, x + 2] +$$; select polyf(42) as int, polyf(4.5) as num; -drop function polyf(anyelement); +drop function polyf(x anyelement); create function polyf(x anyarray) returns anyelement language sql -as $function$ -select x[1] -$function$; +as $$ + select x[1] +$$; select polyf(array[2, 4]) as int, polyf(array[4.5, 7.7]) as num; select polyf(stavalues1) from pg_statistic; -drop function polyf(anyarray); +drop function polyf(x anyarray); create function polyf(x anyarray) returns anyarray language sql -as $function$ -select x -$function$; +as $$ + select x +$$; select polyf(array[2, 4]) as int, polyf(array[4.5, 7.7]) as num; select polyf(stavalues1) from pg_statistic; -drop function polyf(anyarray); +drop function polyf(x anyarray); create function polyf(x anyelement) returns anyrange language sql -as $function$ -select array[x + 1, x + 2] -$function$; +as $$ + select array[x + 1, x + 2] +$$; create function polyf(x anyrange) returns anyarray language sql -as $function$ -select array[lower(x), upper(x)] -$function$; +as $$ + select array[lower(x), upper(x)] +$$; select polyf(int4range(42, 49)) as int, polyf(float8range(4.5, 7.8)) as num; -drop function polyf(anyrange); +drop function polyf(x anyrange); create function polyf(x anycompatible, y anycompatible) returns anycompatiblearray language sql -as $function$ -select array[x, y] -$function$; +as $$ + select array[x, y] +$$; select polyf(2, 4) as int, polyf(2, 4.5) as num; -drop function polyf(anycompatible, anycompatible); +drop function polyf(x anycompatible, y anycompatible); create function polyf(x anycompatiblerange, y anycompatible, z anycompatible) returns anycompatiblearray language sql -as $function$ -select array[lower(x), upper(x), y, z] -$function$; +as $$ + select array[lower(x), upper(x), y, z] +$$; select - polyf( - int4range(42, 49), - 11, - cast(2 as smallint) - ) - as int, - polyf( - float8range(4.5, 7.8), - 7.8, - cast(11 as real) - ) - as num; + polyf(int4range(42, 49), 11, cast(2 as smallint)) as int, + polyf(float8range(4.5, 7.8), 7.8, cast(11 as real)) as num; select polyf(int4range(42, 49), 11, 4.5) as fail; -drop function polyf(anycompatiblerange, anycompatible, anycompatible); +drop function polyf(x anycompatiblerange, y anycompatible, z anycompatible); create function polyf( @@ -114,77 +104,58 @@ polyf( ) returns anycompatiblearray language sql -as $function$ -select array[lower(x), upper(x), y, z] -$function$; +as $$ + select array[lower(x), upper(x), y, z] +$$; select - polyf( - multirange(int4range(42, 49)), - 11, - cast(2 as smallint) - ) - as int, - polyf( - multirange(float8range(4.5, 7.8)), - 7.8, - cast(11 as real) - ) - as num; + polyf(multirange(int4range(42, 49)), 11, cast(2 as smallint)) as int, + polyf(multirange(float8range(4.5, 7.8)), 7.8, cast(11 as real)) as num; select polyf(multirange(int4range(42, 49)), 11, 4.5) as fail; -drop function polyf(anycompatiblemultirange, anycompatible, anycompatible); +drop function + polyf(x anycompatiblemultirange, y anycompatible, z anycompatible); create function polyf(x anycompatible) returns anycompatiblerange language sql -as $function$ -select array[x + 1, x + 2] -$function$; +as $$ + select array[x + 1, x + 2] +$$; create function polyf(x anycompatiblerange, y anycompatiblearray) returns anycompatiblerange language sql -as $function$ -select x -$function$; +as $$ + select x +$$; select - polyf(int4range(42, 49), array[11]) - as int, - polyf(float8range(4.5, 7.8), array[7]) - as num; + polyf(int4range(42, 49), array[11]) as int, + polyf(float8range(4.5, 7.8), array[7]) as num; -drop function polyf(anycompatiblerange, anycompatiblearray); +drop function polyf(x anycompatiblerange, y anycompatiblearray); create function polyf(x anycompatible) returns anycompatiblemultirange language sql -as $function$ -select array[x + 1, x + 2] -$function$; +as $$ + select array[x + 1, x + 2] +$$; create function polyf(x anycompatiblemultirange, y anycompatiblearray) returns anycompatiblemultirange language sql -as $function$ -select x -$function$; +as $$ + select x +$$; select - polyf( - multirange(int4range(42, 49)), - array[11] - ) - as int, - polyf( - multirange(float8range(4.5, 7.8)), - array[7] - ) - as num; + polyf(multirange(int4range(42, 49)), array[11]) as int, + polyf(multirange(float8range(4.5, 7.8)), array[7]) as num; -drop function polyf(anycompatiblemultirange, anycompatiblearray); +drop function polyf(x anycompatiblemultirange, y anycompatiblearray); create function polyf( @@ -196,9 +167,9 @@ polyf( out y anycompatiblearray ) language sql -as $function$ -select a || b, array[c, d] -$function$; +as $$ + select a || b, array[c, d] +$$; select x, pg_typeof(x), y, pg_typeof(y) from polyf(11, array[1, 2], 42, 34.5); @@ -208,12 +179,7 @@ select y, pg_typeof(y) from - polyf( - 11, - array[1, 2], - point(1, 2), - point(3, 4) - ); + polyf(11, array[1, 2], point(1, 2), point(3, 4)); select x, @@ -225,14 +191,12 @@ from select x, pg_typeof(x), y, pg_typeof(y) from polyf(11, array[1, 2.2], 42, 34.5); -drop function polyf(anyelement, anyarray, anycompatible, anycompatible); +drop function polyf(a anyelement, b anyarray, c anycompatible, d anycompatible); create function polyf(anyrange) returns anymultirange language sql -as $function$ -select multirange($1); -$function$; +as 'select multirange($1);'; select polyf(int4range(1, 10)); @@ -243,9 +207,7 @@ drop function polyf(anyrange); create function polyf(anymultirange) returns anyelement language sql -as $function$ -select lower($1); -$function$; +as 'select lower($1);'; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -256,9 +218,7 @@ drop function polyf(anymultirange); create function polyf(anycompatiblerange) returns anycompatiblemultirange language sql -as $function$ -select multirange($1); -$function$; +as 'select multirange($1);'; select polyf(int4range(1, 10)); @@ -269,9 +229,7 @@ drop function polyf(anycompatiblerange); create function polyf(anymultirange) returns anyrange language sql -as $function$ -select range_merge($1); -$function$; +as 'select range_merge($1);'; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -282,9 +240,7 @@ drop function polyf(anymultirange); create function polyf(anycompatiblemultirange) returns anycompatiblerange language sql -as $function$ -select range_merge($1); -$function$; +as 'select range_merge($1);'; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -295,9 +251,7 @@ drop function polyf(anycompatiblemultirange); create function polyf(anycompatiblemultirange) returns anycompatible language sql -as $function$ -select lower($1); -$function$; +as 'select lower($1);'; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -308,72 +262,54 @@ drop function polyf(anycompatiblemultirange); create function stfp(anyarray) returns anyarray language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function stfnp(int[]) returns int[] language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function tfp(anyarray, anyelement) returns anyarray language sql -as $function$ -select $1 || $2 -$function$; +as 'select $1 || $2'; create function tfnp(int[], int) returns int[] language sql -as $function$ -select $1 || $2 -$function$; +as 'select $1 || $2'; create function tf1p(anyarray, int) returns anyarray language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function tf2p(int[], anyelement) returns int[] language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function sum3(anyelement, anyelement, anyelement) returns anyelement language sql strict -as $function$ -select $1+$2+$3 -$function$; +as 'select $1+$2+$3'; create function ffp(anyarray) returns anyarray language sql -as $function$ -select $1 -$function$; +as 'select $1'; create function ffnp(int[]) returns int[] language sql -as $function$ -select $1 -$function$; +as 'select $1'; create aggregate myaggp01a ( * ) ( sfunc = stfnp, - stype = int[], + stype = int4[], finalfunc = ffp, initcond = '{}' ); @@ -391,12 +327,12 @@ create aggregate myaggp03a ( * ) ( sfunc = stfp, - stype = int[], + stype = int4[], finalfunc = ffp, initcond = '{}' ); -create aggregate myaggp03b (*) (sfunc = stfp, stype = int[], initcond = '{}'); +create aggregate myaggp03b (*) (sfunc = stfp, stype = int4[], initcond = '{}'); create aggregate myaggp04a ( * @@ -603,12 +539,12 @@ create aggregate myaggn01a ( * ) ( sfunc = stfnp, - stype = int[], + stype = int4[], finalfunc = ffnp, initcond = '{}' ); -create aggregate myaggn01b (*) (sfunc = stfnp, stype = int[], initcond = '{}'); +create aggregate myaggn01b (*) (sfunc = stfnp, stype = int4[], initcond = '{}'); create aggregate myaggn02a ( * @@ -631,7 +567,7 @@ create aggregate myaggn03a ( * ) ( sfunc = stfp, - stype = int[], + stype = int4[], finalfunc = ffnp, initcond = '{}' ); @@ -910,19 +846,17 @@ select mysum2(f1, f1 + 1) from t; create function bleat(int) returns int language plpgsql -as $function$ +as $$ begin raise notice 'bleat %', $1; return $1; -end -$function$; +end$$; -create function sql_if(boolean, anyelement, anyelement) +create function sql_if(bool, anyelement, anyelement) returns anyelement language sql -as $function$ -select case when $1 then $2 else $3 end -$function$; +as $$ +select case when $1 then $2 else $3 end $$; select f1, sql_if(f1 > 0, bleat(f1), bleat(f1 + 1)) from int4_tbl; @@ -939,18 +873,13 @@ create aggregate array_larger_accum ( select array_larger_accum(i) from - ( - values (array[1, 2]), (array[3, 4]) - ) - as t (i); + (values (array[1, 2]), (array[3, 4])) as t (i); select array_larger_accum(i) from ( - values - (array[row(1, 2), row(3, 4)]), - (array[row(5, 6), row(7, 8)]) + values (array[row(1, 2), row(3, 4)]), (array[row(5, 6), row(7, 8)]) ) as t (i); @@ -958,7 +887,7 @@ create function add_group(grp anyarray, ad anyelement, size int) returns anyarray language plpgsql immutable -as $function$ +as $$ begin if grp is null then return array[ad]; @@ -968,7 +897,7 @@ begin end if; return grp; end; -$function$; +$$; create aggregate build_group ( anyelement, int @@ -979,42 +908,28 @@ create aggregate build_group ( select build_group(q1, 3) from int8_tbl; -create aggregate build_group ( - bigint, int -) ( - sfunc = add_group, - stype = smallint[] -); +create aggregate build_group (int8, int) (sfunc = add_group, stype = int2[]); -create aggregate build_group ( - bigint, int -) ( - sfunc = add_group, - stype = bigint[] -); +create aggregate build_group (int8, int) (sfunc = add_group, stype = int8[]); create function first_el_transfn(anyarray, anyelement) returns anyarray language sql immutable -as $function$ -select $1 || $2 -$function$; +as 'select $1 || $2'; create function first_el(anyarray) returns anyelement language sql immutable strict -as $function$ -select $1[1] -$function$; +as 'select $1[1]'; create aggregate first_el_agg_f8 ( - double precision + float8 ) ( sfunc = array_append, - stype = double precision[], + stype = float8[], finalfunc = first_el ); @@ -1026,19 +941,12 @@ create aggregate first_el_agg_any ( finalfunc = first_el ); -select - first_el_agg_f8( - cast(x as double precision) - ) -from - generate_series(1, 10) as x; +select first_el_agg_f8(cast(x as float8)) from generate_series(1, 10) as x; select first_el_agg_any(x) from generate_series(1, 10) as x; select - first_el_agg_f8( - cast(x as double precision) - ) over (order by x) + first_el_agg_f8(cast(x as float8)) over (order by x) from generate_series(1, 10) as x; @@ -1051,7 +959,7 @@ from where histogram_bounds is not null; -select MAX(histogram_bounds) from pg_stats where tablename = 'pg_am'; +select max(histogram_bounds) from pg_stats where tablename = 'pg_am'; select array_in('{1,2,3}', cast('int4' as regtype), -1); @@ -1064,9 +972,9 @@ returns anyelement language sql immutable strict -as $function$ -select min($1[i]) from generate_subscripts($1,1) g(i) -$function$; +as $$ + select min($1[i]) from generate_subscripts($1,1) g(i) +$$; select myleast(10, 1, 20, 33); @@ -1087,9 +995,9 @@ returns text language sql immutable strict -as $function$ -select array_to_string($2, $1); -$function$; +as $$ + select array_to_string($2, $1); +$$; select concat('%', 1, 2, 3, 4, 5); @@ -1106,9 +1014,9 @@ returns anyarray language sql immutable strict -as $function$ -select array_prepend($1, $2); -$function$; +as $$ + select array_prepend($1, $2); +$$; select formarray(1, 2, 3, 4, 5); @@ -1120,7 +1028,7 @@ select formarray(1, cast('x' as text)); select formarray(1, variadic array[cast('x' as text)]); -drop function formarray(anyelement, anyarray); +drop function formarray(anyelement, variadic anyarray); select pg_typeof(null); @@ -1143,9 +1051,9 @@ select pg_typeof(myleast(10, 1, 20, 33)); create function dfunc(a int default 1, int default 2) returns int language sql -as $function$ -select $1 + $2; -$function$; +as $$ + select $1 + $2; +$$; select dfunc(); @@ -1164,15 +1072,15 @@ drop function dfunc(int, int); create function dfunc(a int default 1, b int) returns int language sql -as $function$ -select $1 + $2; -$function$; +as $$ + select $1 + $2; +$$; create function dfunc(a int default 1, out sum int, b int default 2) language sql -as $function$ -select $1 + $2; -$function$; +as $$ + select $1 + $2; +$$; select dfunc(); @@ -1181,18 +1089,18 @@ drop function dfunc(int, int); create function dfunc(a int default 1.0, int default '-1') returns int language sql -as $function$ -select $1 + $2; -$function$; +as $$ + select $1 + $2; +$$; select dfunc(); create function dfunc(a text default 'Hello', b text default 'World') returns text language sql -as $function$ -select $1 || ', ' || $2; -$function$; +as $$ + select $1 || ', ' || $2; +$$; select dfunc(); @@ -1211,9 +1119,9 @@ drop function dfunc(text, text); create function dfunc(int default 1, int default 2) returns int language sql -as $function$ -select 2; -$function$; +as $$ + select 2; +$$; create function dfunc( @@ -1224,9 +1132,9 @@ dfunc( ) returns int language sql -as $function$ -select 4; -$function$; +as $$ + select 4; +$$; select dfunc(); @@ -1245,16 +1153,16 @@ drop function dfunc(int, int, int, int); create function dfunc(out int default 20) returns int language sql -as $function$ -select 1; -$function$; +as $$ + select 1; +$$; create function dfunc(anyelement default cast('World' as text)) returns text language sql -as $function$ -select 'Hello, ' || $1::text; -$function$; +as $$ + select 'Hello, ' || $1::text; +$$; select dfunc(); @@ -1269,9 +1177,7 @@ drop function dfunc(anyelement); create function dfunc(variadic a int[]) returns int language sql -as $function$ -select array_upper($1, 1) -$function$; +as $$ select array_upper($1, 1) $$; select dfunc(); @@ -1285,9 +1191,7 @@ dfunc( ) returns int language sql -as $function$ -select array_upper($1, 1) -$function$; +as $$ select array_upper($1, 1) $$; select dfunc(); @@ -1298,32 +1202,30 @@ select dfunc(10, 20); create or replace function dfunc(variadic a int[]) returns int language sql -as $function$ -select array_upper($1, 1) -$function$; +as $$ select array_upper($1, 1) $$; -drop function dfunc(int[]); +drop function dfunc(variadic a int[]); create function dfunc(int default 1, int default 2, int default 3) returns int language sql -as $function$ -select 3; -$function$; +as $$ + select 3; +$$; create function dfunc(int default 1, int default 2) returns int language sql -as $function$ -select 2; -$function$; +as $$ + select 2; +$$; create function dfunc(text) returns text language sql -as $function$ -select $1; -$function$; +as $$ + select $1; +$$; select dfunc(1); @@ -1343,68 +1245,68 @@ returns table ( d int ) language sql -as $function$ -select $1, $2, $3, $4; -$function$; +as $$ + select $1, $2, $3, $4; +$$; select (dfunc(10, 20, 30)).*; -select (dfunc("a" := 10, "b" := 20, "c" := 30)).*; +select (dfunc(a := 10, b := 20, c := 30)).*; -select * from dfunc("a" := 10, "b" := 20); +select * from dfunc(a := 10, b := 20); -select * from dfunc("b" := 10, "a" := 20); +select * from dfunc(b := 10, a := 20); select * from dfunc(0); select * from dfunc(1, 2); -select * from dfunc(1, 2, "c" := 3); +select * from dfunc(1, 2, c := 3); -select * from dfunc(1, 2, "d" := 3); +select * from dfunc(1, 2, d := 3); -select * from dfunc("x" := 20, "b" := 10, "x" := 30); +select * from dfunc(x := 20, b := 10, x := 30); -select * from dfunc(10, "b" := 20, 30); +select * from dfunc(10, b := 20, 30); -select * from dfunc("x" := 10, "b" := 20, "c" := 30); +select * from dfunc(x := 10, b := 20, c := 30); -select * from dfunc(10, 10, "a" := 20); +select * from dfunc(10, 10, a := 20); -select * from dfunc(1, "c" := 2, "d" := 3); +select * from dfunc(1, c := 2, d := 3); drop function dfunc(int, int, int, int); create function xleast(x numeric, variadic arr numeric[]) returns numeric language sql -as $function$ -select least(x, min(arr[i])) from generate_subscripts(arr, 1) g(i); -$function$; +as $$ + select least(x, min(arr[i])) from generate_subscripts(arr, 1) g(i); +$$; -select xleast("x" := 1, variadic "arr" := array[2, 3]); +select xleast(x := 1, variadic arr := array[2, 3]); -select xleast(1, variadic "arr" := array[2, 3]); +select xleast(1, variadic arr := array[2, 3]); set search_path to pg_catalog; -select xleast(1, variadic "arr" := array[2, 3]); +select xleast(1, variadic arr := array[2, 3]); reset search_path; -select xleast("foo" := 1, variadic "arr" := array[2, 3]); +select xleast(foo := 1, variadic arr := array[2, 3]); -select xleast("x" := 1, variadic array[2, 3]); +select xleast(x := 1, variadic array[2, 3]); -select xleast(1, variadic "x" := array[2, 3]); +select xleast(1, variadic x := array[2, 3]); -select xleast("arr" := array[1], variadic "x" := 3); +select xleast(arr := array[1], variadic x := 3); -select xleast("arr" := array[1], "x" := 3); +select xleast(arr := array[1], x := 3); -select xleast("arr" := 1, variadic "x" := array[2, 3]); +select xleast(arr := 1, variadic x := array[2, 3]); -drop function xleast(numeric, numeric[]); +drop function xleast(x numeric, variadic arr numeric[]); create function dfunc(a varchar, b numeric, c date default current_date) returns table ( @@ -1413,9 +1315,9 @@ returns table ( c date ) language sql -as $function$ -select $1, $2, $3; -$function$; +as $$ + select $1, $2, $3; +$$; select (dfunc('Hello World', 20, cast('2009-07-25' as date))).*; @@ -1424,38 +1326,13 @@ select * from dfunc('Hello World', 20, cast('2009-07-25' as date)); select * from - dfunc( - "c" := cast('2009-07-25' as date), - "a" := 'Hello World', - "b" := 20 - ); + dfunc(c := cast('2009-07-25' as date), a := 'Hello World', b := 20); -select - * -from - dfunc( - 'Hello World', - "b" := 20, - "c" := cast('2009-07-25' as date) - ); +select * from dfunc('Hello World', b := 20, c := cast('2009-07-25' as date)); -select - * -from - dfunc( - 'Hello World', - "c" := cast('2009-07-25' as date), - "b" := 20 - ); +select * from dfunc('Hello World', c := cast('2009-07-25' as date), b := 20); -select - * -from - dfunc( - 'Hello World', - "c" := 20, - "b" := cast('2009-07-25' as date) - ); +select * from dfunc('Hello World', c := 20, b := cast('2009-07-25' as date)); drop function dfunc(varchar, numeric, date); @@ -1468,9 +1345,9 @@ dfunc( ) returns record language sql -as $function$ -select $1, $2; -$function$; +as $$ + select $1, $2; +$$; select (dfunc()).*; @@ -1478,15 +1355,15 @@ select * from dfunc(); select * from dfunc('Hello', 100); -select * from dfunc("a" := 'Hello', "c" := 100); +select * from dfunc(a := 'Hello', c := 100); -select * from dfunc("c" := 100, "a" := 'Hello'); +select * from dfunc(c := 100, a := 'Hello'); select * from dfunc('Hello'); -select * from dfunc('Hello', "c" := 100); +select * from dfunc('Hello', c := 100); -select * from dfunc("c" := 100); +select * from dfunc(c := 100); create or replace function dfunc( @@ -1497,9 +1374,9 @@ dfunc( ) returns record language sql -as $function$ -select $1, $2; -$function$; +as $$ + select $1, $2; +$$; create or replace function dfunc( @@ -1510,46 +1387,36 @@ dfunc( ) returns record language sql -as $function$ -select $1, $2; -$function$; +as $$ + select $1, $2; +$$; drop function dfunc(varchar, numeric); create function testpolym(a int, a int) returns int language sql -as $function$ -select 1; -$function$; +as $$ select 1;$$; create function testpolym(int, out a int, out a int) returns int language sql -as $function$ -select 1; -$function$; +as $$ select 1;$$; create function testpolym(out a int, inout a int) returns int language sql -as $function$ -select 1; -$function$; +as $$ select 1;$$; create function testpolym(a int, inout a int) returns int language sql -as $function$ -select 1; -$function$; +as $$ select 1;$$; create function testpolym(a int, out a int) returns int language sql -as $function$ -select $1; -$function$; +as $$ select $1;$$; select testpolym(37); @@ -1560,9 +1427,7 @@ returns table ( a int ) language sql -as $function$ -select $1; -$function$; +as $$ select $1;$$; select * from testpolym(37); @@ -1572,87 +1437,85 @@ create function dfunc( a anyelement, b anyelement default null, - flag boolean default true + flag bool default true ) returns anyelement language sql -as $function$ -select case when $3 then $1 else $2 end; -$function$; +as $$ + select case when $3 then $1 else $2 end; +$$; select dfunc(1, 2); select dfunc(cast('a' as text), 'b'); -select dfunc("a" := 1, "b" := 2); +select dfunc(a := 1, b := 2); -select dfunc("a" := cast('a' as text), "b" := 'b'); +select dfunc(a := cast('a' as text), b := 'b'); -select dfunc("a" := cast('a' as text), "b" := 'b', "flag" := false); +select dfunc(a := cast('a' as text), b := 'b', flag := false); -select dfunc("b" := cast('b' as text), "a" := 'a'); +select dfunc(b := cast('b' as text), a := 'a'); -select dfunc("a" := cast('a' as text), "flag" := true); +select dfunc(a := cast('a' as text), flag := true); -select dfunc("a" := cast('a' as text), "flag" := false); +select dfunc(a := cast('a' as text), flag := false); -select dfunc("b" := cast('b' as text), "a" := 'a', "flag" := true); +select dfunc(b := cast('b' as text), a := 'a', flag := true); select dfunc(cast('a' as text), 'b', false); -select dfunc(cast('a' as text), 'b', "flag" := false); +select dfunc(cast('a' as text), 'b', flag := false); select dfunc(cast('a' as text), 'b', true); -select dfunc(cast('a' as text), 'b', "flag" := true); +select dfunc(cast('a' as text), 'b', flag := true); -select dfunc("a" := 1, "b" := 2); +select dfunc(a := 1, b := 2); -select dfunc("a" := cast('a' as text), "b" := 'b'); +select dfunc(a := cast('a' as text), b := 'b'); -select dfunc("a" := cast('a' as text), "b" := 'b', "flag" := false); +select dfunc(a := cast('a' as text), b := 'b', flag := false); -select dfunc("b" := cast('b' as text), "a" := 'a'); +select dfunc(b := cast('b' as text), a := 'a'); -select dfunc("a" := cast('a' as text), "flag" := true); +select dfunc(a := cast('a' as text), flag := true); -select dfunc("a" := cast('a' as text), "flag" := false); +select dfunc(a := cast('a' as text), flag := false); -select dfunc("b" := cast('b' as text), "a" := 'a', "flag" := true); +select dfunc(b := cast('b' as text), a := 'a', flag := true); select dfunc(cast('a' as text), 'b', false); -select dfunc(cast('a' as text), 'b', "flag" := false); +select dfunc(cast('a' as text), 'b', flag := false); select dfunc(cast('a' as text), 'b', true); -select dfunc(cast('a' as text), 'b', "flag" := true); +select dfunc(cast('a' as text), 'b', flag := true); -select dfunc("a" := -1); +select dfunc(a := -1); -select dfunc("a" := +1); +select dfunc(a := +1); -select dfunc("a" := 1); +select dfunc(a := 1); -select dfunc("a" := 1); +select dfunc(a := 1); -do -$do$ -declare r integer; +do $$ + declare r integer; begin select dfunc(a=>-- comment 1) into r; raise info 'r = %', r; end; -$do$; +$$; create view dfview as select q1, q2, - dfunc(q1, q2, "flag" := q1 > q2) as c3, - dfunc(q1, "flag" := q1 < q2, "b" := q2) - as c4 + dfunc(q1, q2, flag := q1 > q2) as c3, + dfunc(q1, flag := q1 < q2, b := q2) as c4 from int8_tbl; @@ -1660,14 +1523,14 @@ select * from dfview; drop view dfview; -drop function dfunc(anyelement, anyelement, boolean); +drop function dfunc(anyelement, anyelement, bool); create function anyctest(anycompatible, anycompatible) returns anycompatible language sql -as $function$ -select greatest($1, $2) -$function$; +as $$ + select greatest($1, $2) +$$; select x, pg_typeof(x) from anyctest(11, 12) as x; @@ -1682,9 +1545,9 @@ drop function anyctest(anycompatible, anycompatible); create function anyctest(anycompatible, anycompatible) returns anycompatiblearray language sql -as $function$ -select array[$1, $2] -$function$; +as $$ + select array[$1, $2] +$$; select x, pg_typeof(x) from anyctest(11, 12) as x; @@ -1697,9 +1560,9 @@ drop function anyctest(anycompatible, anycompatible); create function anyctest(anycompatible, anycompatiblearray) returns anycompatiblearray language sql -as $function$ -select array[$1] || $2 -$function$; +as $$ + select array[$1] || $2 +$$; select x, pg_typeof(x) from anyctest(11, array[12]) as x; @@ -1718,9 +1581,9 @@ drop function anyctest(anycompatible, anycompatiblearray); create function anyctest(anycompatible, anycompatiblerange) returns anycompatiblerange language sql -as $function$ -select $2 -$function$; +as $$ + select $2 +$$; select x, pg_typeof(x) from anyctest(11, int4range(4, 7)) as x; @@ -1737,9 +1600,9 @@ drop function anyctest(anycompatible, anycompatiblerange); create function anyctest(anycompatiblerange, anycompatiblerange) returns anycompatible language sql -as $function$ -select lower($1) + upper($2) -$function$; +as $$ + select lower($1) + upper($2) +$$; select x, pg_typeof(x) from anyctest(int4range(11, 12), int4range(4, 7)) as x; @@ -1750,16 +1613,16 @@ drop function anyctest(anycompatiblerange, anycompatiblerange); create function anyctest(anycompatible) returns anycompatiblerange language sql -as $function$ -select $1 -$function$; +as $$ + select $1 +$$; create function anyctest(anycompatible, anycompatiblemultirange) returns anycompatiblemultirange language sql -as $function$ -select $2 -$function$; +as $$ + select $2 +$$; select x, pg_typeof(x) from anyctest(11, multirange(int4range(4, 7))) as x; @@ -1776,45 +1639,37 @@ drop function anyctest(anycompatible, anycompatiblemultirange); create function anyctest(anycompatiblemultirange, anycompatiblemultirange) returns anycompatible language sql -as $function$ -select lower($1) + upper($2) -$function$; +as $$ + select lower($1) + upper($2) +$$; select x, pg_typeof(x) from - anyctest( - multirange(int4range(11, 12)), - multirange(int4range(4, 7)) - ) - as x; + anyctest(multirange(int4range(11, 12)), multirange(int4range(4, 7))) as x; select x, pg_typeof(x) from - anyctest( - multirange(int4range(11, 12)), - multirange(numrange(4, 7)) - ) - as x; + anyctest(multirange(int4range(11, 12)), multirange(numrange(4, 7))) as x; drop function anyctest(anycompatiblemultirange, anycompatiblemultirange); create function anyctest(anycompatible) returns anycompatiblemultirange language sql -as $function$ -select $1 -$function$; +as $$ + select $1 +$$; create function anyctest(anycompatiblenonarray, anycompatiblenonarray) returns anycompatiblearray language sql -as $function$ -select array[$1, $2] -$function$; +as $$ + select array[$1, $2] +$$; select x, pg_typeof(x) from anyctest(11, 12) as x; @@ -1833,9 +1688,9 @@ anyctest( ) returns anycompatiblearray language sql -as $function$ -select array[c, d] -$function$; +as $$ + select array[c, d] +$$; select x, pg_typeof(x) from anyctest(11, array[1, 2], 42, 34.5) as x; @@ -1843,26 +1698,21 @@ select x, pg_typeof(x) from - anyctest( - 11, - array[1, 2], - point(1, 2), - point(3, 4) - ) - as x; + anyctest(11, array[1, 2], point(1, 2), point(3, 4)) as x; select x, pg_typeof(x) from anyctest(11, '{1,2}', point(1, 2), '(3,4)') as x; select x, pg_typeof(x) from anyctest(11, array[1, 2.2], 42, 34.5) as x; -drop function anyctest(anyelement, anyarray, anycompatible, anycompatible); +drop function + anyctest(a anyelement, b anyarray, c anycompatible, d anycompatible); create function anyctest(variadic anycompatiblearray) returns anycompatiblearray language sql -as $function$ -select $1 -$function$; +as $$ + select $1 +$$; select x, pg_typeof(x) from anyctest(11, 12) as x; @@ -1876,4 +1726,4 @@ select x, pg_typeof(x) from anyctest(variadic array[11, 12]) as x; select x, pg_typeof(x) from anyctest(variadic array[11, 12.2]) as x; -drop function anyctest(anycompatiblearray); +drop function anyctest(variadic anycompatiblearray); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_100.snap index 858331ab0..efd02ca9e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_100.snap @@ -5,51 +5,51 @@ snapshot_kind: text --- begin; -declare "foo1" scroll cursor for select * from tenk1 order by unique2;; +declare foo1 scroll cursor for select * from tenk1 order by unique2;; -declare "foo2" scroll cursor for select * from tenk2;; +declare foo2 scroll cursor for select * from tenk2;; -declare "foo3" scroll cursor for select * from tenk1 order by unique2;; +declare foo3 scroll cursor for select * from tenk1 order by unique2;; -declare "foo4" scroll cursor for select * from tenk2;; +declare foo4 scroll cursor for select * from tenk2;; -declare "foo5" scroll cursor for select * from tenk1 order by unique2;; +declare foo5 scroll cursor for select * from tenk1 order by unique2;; -declare "foo6" scroll cursor for select * from tenk2;; +declare foo6 scroll cursor for select * from tenk2;; -declare "foo7" scroll cursor for select * from tenk1 order by unique2;; +declare foo7 scroll cursor for select * from tenk1 order by unique2;; -declare "foo8" scroll cursor for select * from tenk2;; +declare foo8 scroll cursor for select * from tenk2;; -declare "foo9" scroll cursor for select * from tenk1 order by unique2;; +declare foo9 scroll cursor for select * from tenk1 order by unique2;; -declare "foo10" scroll cursor for select * from tenk2;; +declare foo10 scroll cursor for select * from tenk2;; -declare "foo11" scroll cursor for select * from tenk1 order by unique2;; +declare foo11 scroll cursor for select * from tenk1 order by unique2;; -declare "foo12" scroll cursor for select * from tenk2;; +declare foo12 scroll cursor for select * from tenk2;; -declare "foo13" scroll cursor for select * from tenk1 order by unique2;; +declare foo13 scroll cursor for select * from tenk1 order by unique2;; -declare "foo14" scroll cursor for select * from tenk2;; +declare foo14 scroll cursor for select * from tenk2;; -declare "foo15" scroll cursor for select * from tenk1 order by unique2;; +declare foo15 scroll cursor for select * from tenk1 order by unique2;; -declare "foo16" scroll cursor for select * from tenk2;; +declare foo16 scroll cursor for select * from tenk2;; -declare "foo17" scroll cursor for select * from tenk1 order by unique2;; +declare foo17 scroll cursor for select * from tenk1 order by unique2;; -declare "foo18" scroll cursor for select * from tenk2;; +declare foo18 scroll cursor for select * from tenk2;; -declare "foo19" scroll cursor for select * from tenk1 order by unique2;; +declare foo19 scroll cursor for select * from tenk1 order by unique2;; -declare "foo20" scroll cursor for select * from tenk2;; +declare foo20 scroll cursor for select * from tenk2;; -declare "foo21" scroll cursor for select * from tenk1 order by unique2;; +declare foo21 scroll cursor for select * from tenk1 order by unique2;; -declare "foo22" scroll cursor for select * from tenk2;; +declare foo22 scroll cursor for select * from tenk2;; -declare "foo23" scroll cursor for select * from tenk1 order by unique2;; +declare foo23 scroll cursor for select * from tenk1 order by unique2;; fetch next from foo1; @@ -175,7 +175,7 @@ select name, statement, is_holdable, is_binary, is_scrollable from pg_cursors; begin; -declare "foo24" no scroll cursor for select * from tenk1 order by unique2;; +declare foo24 no scroll cursor for select * from tenk1 order by unique2;; fetch next from foo24; @@ -185,7 +185,7 @@ commit; begin; -declare "foo24" no scroll cursor for select * from tenk1 order by unique2;; +declare foo24 no scroll cursor for select * from tenk1 order by unique2;; fetch next from foo24; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_80.snap index 0385efce0..8dd1da7c8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_80.snap @@ -5,51 +5,51 @@ snapshot_kind: text --- begin; -declare "foo1" scroll cursor for select * from tenk1 order by unique2;; +declare foo1 scroll cursor for select * from tenk1 order by unique2;; -declare "foo2" scroll cursor for select * from tenk2;; +declare foo2 scroll cursor for select * from tenk2;; -declare "foo3" scroll cursor for select * from tenk1 order by unique2;; +declare foo3 scroll cursor for select * from tenk1 order by unique2;; -declare "foo4" scroll cursor for select * from tenk2;; +declare foo4 scroll cursor for select * from tenk2;; -declare "foo5" scroll cursor for select * from tenk1 order by unique2;; +declare foo5 scroll cursor for select * from tenk1 order by unique2;; -declare "foo6" scroll cursor for select * from tenk2;; +declare foo6 scroll cursor for select * from tenk2;; -declare "foo7" scroll cursor for select * from tenk1 order by unique2;; +declare foo7 scroll cursor for select * from tenk1 order by unique2;; -declare "foo8" scroll cursor for select * from tenk2;; +declare foo8 scroll cursor for select * from tenk2;; -declare "foo9" scroll cursor for select * from tenk1 order by unique2;; +declare foo9 scroll cursor for select * from tenk1 order by unique2;; -declare "foo10" scroll cursor for select * from tenk2;; +declare foo10 scroll cursor for select * from tenk2;; -declare "foo11" scroll cursor for select * from tenk1 order by unique2;; +declare foo11 scroll cursor for select * from tenk1 order by unique2;; -declare "foo12" scroll cursor for select * from tenk2;; +declare foo12 scroll cursor for select * from tenk2;; -declare "foo13" scroll cursor for select * from tenk1 order by unique2;; +declare foo13 scroll cursor for select * from tenk1 order by unique2;; -declare "foo14" scroll cursor for select * from tenk2;; +declare foo14 scroll cursor for select * from tenk2;; -declare "foo15" scroll cursor for select * from tenk1 order by unique2;; +declare foo15 scroll cursor for select * from tenk1 order by unique2;; -declare "foo16" scroll cursor for select * from tenk2;; +declare foo16 scroll cursor for select * from tenk2;; -declare "foo17" scroll cursor for select * from tenk1 order by unique2;; +declare foo17 scroll cursor for select * from tenk1 order by unique2;; -declare "foo18" scroll cursor for select * from tenk2;; +declare foo18 scroll cursor for select * from tenk2;; -declare "foo19" scroll cursor for select * from tenk1 order by unique2;; +declare foo19 scroll cursor for select * from tenk1 order by unique2;; -declare "foo20" scroll cursor for select * from tenk2;; +declare foo20 scroll cursor for select * from tenk2;; -declare "foo21" scroll cursor for select * from tenk1 order by unique2;; +declare foo21 scroll cursor for select * from tenk1 order by unique2;; -declare "foo22" scroll cursor for select * from tenk2;; +declare foo22 scroll cursor for select * from tenk2;; -declare "foo23" scroll cursor for select * from tenk1 order by unique2;; +declare foo23 scroll cursor for select * from tenk1 order by unique2;; fetch next from foo1; @@ -183,7 +183,7 @@ select name, statement, is_holdable, is_binary, is_scrollable from pg_cursors; begin; -declare "foo24" no scroll cursor for select * from tenk1 order by unique2;; +declare foo24 no scroll cursor for select * from tenk1 order by unique2;; fetch next from foo24; @@ -193,7 +193,7 @@ commit; begin; -declare "foo24" no scroll cursor for select * from tenk1 order by unique2;; +declare foo24 no scroll cursor for select * from tenk1 order by unique2;; fetch next from foo24; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_p2_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_p2_100.snap index 1da629ded..086a05d1e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_p2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_p2_100.snap @@ -5,31 +5,31 @@ snapshot_kind: text --- begin; -declare "foo13" cursor for select * from onek where unique1 = 50;; +declare foo13 cursor for select * from onek where unique1 = 50;; -declare "foo14" cursor for select * from onek where unique1 = 51;; +declare foo14 cursor for select * from onek where unique1 = 51;; -declare "foo15" cursor for select * from onek where unique1 = 52;; +declare foo15 cursor for select * from onek where unique1 = 52;; -declare "foo16" cursor for select * from onek where unique1 = 53;; +declare foo16 cursor for select * from onek where unique1 = 53;; -declare "foo17" cursor for select * from onek where unique1 = 54;; +declare foo17 cursor for select * from onek where unique1 = 54;; -declare "foo18" cursor for select * from onek where unique1 = 55;; +declare foo18 cursor for select * from onek where unique1 = 55;; -declare "foo19" cursor for select * from onek where unique1 = 56;; +declare foo19 cursor for select * from onek where unique1 = 56;; -declare "foo20" cursor for select * from onek where unique1 = 57;; +declare foo20 cursor for select * from onek where unique1 = 57;; -declare "foo21" cursor for select * from onek where unique1 = 58;; +declare foo21 cursor for select * from onek where unique1 = 58;; -declare "foo22" cursor for select * from onek where unique1 = 59;; +declare foo22 cursor for select * from onek where unique1 = 59;; -declare "foo23" cursor for select * from onek where unique1 = 60;; +declare foo23 cursor for select * from onek where unique1 = 60;; -declare "foo24" cursor for select * from onek2 where unique1 = 50;; +declare foo24 cursor for select * from onek2 where unique1 = 50;; -declare "foo25" cursor for select * from onek2 where unique1 = 60;; +declare foo25 cursor for select * from onek2 where unique1 = 60;; fetch forward all from foo13; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_p2_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_p2_80.snap index 1da629ded..086a05d1e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_p2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__portals_p2_80.snap @@ -5,31 +5,31 @@ snapshot_kind: text --- begin; -declare "foo13" cursor for select * from onek where unique1 = 50;; +declare foo13 cursor for select * from onek where unique1 = 50;; -declare "foo14" cursor for select * from onek where unique1 = 51;; +declare foo14 cursor for select * from onek where unique1 = 51;; -declare "foo15" cursor for select * from onek where unique1 = 52;; +declare foo15 cursor for select * from onek where unique1 = 52;; -declare "foo16" cursor for select * from onek where unique1 = 53;; +declare foo16 cursor for select * from onek where unique1 = 53;; -declare "foo17" cursor for select * from onek where unique1 = 54;; +declare foo17 cursor for select * from onek where unique1 = 54;; -declare "foo18" cursor for select * from onek where unique1 = 55;; +declare foo18 cursor for select * from onek where unique1 = 55;; -declare "foo19" cursor for select * from onek where unique1 = 56;; +declare foo19 cursor for select * from onek where unique1 = 56;; -declare "foo20" cursor for select * from onek where unique1 = 57;; +declare foo20 cursor for select * from onek where unique1 = 57;; -declare "foo21" cursor for select * from onek where unique1 = 58;; +declare foo21 cursor for select * from onek where unique1 = 58;; -declare "foo22" cursor for select * from onek where unique1 = 59;; +declare foo22 cursor for select * from onek where unique1 = 59;; -declare "foo23" cursor for select * from onek where unique1 = 60;; +declare foo23 cursor for select * from onek where unique1 = 60;; -declare "foo24" cursor for select * from onek2 where unique1 = 50;; +declare foo24 cursor for select * from onek2 where unique1 = 50;; -declare "foo25" cursor for select * from onek2 where unique1 = 60;; +declare foo25 cursor for select * from onek2 where unique1 = 60;; fetch forward all from foo13; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__predicate_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__predicate_100.snap index ef7daa15e..735dc1954 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__predicate_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__predicate_100.snap @@ -30,10 +30,7 @@ select * from pred_tab as t1 left outer join pred_tab as t2 on t1.a is not null; select * from - pred_tab as t1 - full outer join - pred_tab as t2 - on t1.a = t2.a + pred_tab as t1 full outer join pred_tab as t2 on t1.a = t2.a left outer join pred_tab as t3 on t2.a is not null; @@ -43,10 +40,7 @@ select * from pred_tab as t1 left outer join pred_tab as t2 on t1.a is null; select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on t1.a = 1 + pred_tab as t1 left outer join pred_tab as t2 on t1.a = 1 left outer join pred_tab as t3 on t2.a is null; @@ -56,10 +50,7 @@ select * from pred_tab as t1 left outer join pred_tab as t2 on t1.a is not null select * from - pred_tab as t1 - full outer join - pred_tab as t2 - on t1.a = t2.a + pred_tab as t1 full outer join pred_tab as t2 on t1.a = t2.a left outer join pred_tab as t3 on t2.a is not null or t2.b = 1; @@ -69,10 +60,7 @@ select * from pred_tab as t1 left outer join pred_tab as t2 on t1.a is null or t select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on t1.a = 1 + pred_tab as t1 left outer join pred_tab as t2 on t1.a = 1 left outer join pred_tab as t3 on t2.a is null or t2.c is null; @@ -166,10 +154,7 @@ analyze pred_tab_notnull; select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on true + pred_tab as t1 left outer join pred_tab as t2 on true left outer join pred_tab_notnull as t3 on t2.a = t3.a @@ -180,10 +165,7 @@ from select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on true + pred_tab as t1 left outer join pred_tab as t2 on true left outer join pred_tab_notnull as t3 on t2.a = t3.a @@ -194,10 +176,7 @@ from select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on true + pred_tab as t1 left outer join pred_tab as t2 on true left outer join pred_tab_notnull as t3 on t2.a = t3.a @@ -208,10 +187,7 @@ from select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on true + pred_tab as t1 left outer join pred_tab as t2 on true left outer join pred_tab_notnull as t3 on t2.a = t3.a @@ -226,13 +202,13 @@ drop table pred_tab_notnull; create table pred_tab1 ( a int not null, b int, - constraint "check_tab1" check (a is null or b > 2) + constraint check_tab1 check (a is null or b > 2) ); create table pred_tab2 ( a int, b int, - constraint "check_a" check (a is not null) + constraint check_a check (a is not null) ); set constraint_exclusion = 'on'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__predicate_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__predicate_80.snap index f93070456..12a573a92 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__predicate_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__predicate_80.snap @@ -30,10 +30,7 @@ select * from pred_tab as t1 left outer join pred_tab as t2 on t1.a is not null; select * from - pred_tab as t1 - full outer join - pred_tab as t2 - on t1.a = t2.a + pred_tab as t1 full outer join pred_tab as t2 on t1.a = t2.a left outer join pred_tab as t3 on t2.a is not null; @@ -43,10 +40,7 @@ select * from pred_tab as t1 left outer join pred_tab as t2 on t1.a is null; select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on t1.a = 1 + pred_tab as t1 left outer join pred_tab as t2 on t1.a = 1 left outer join pred_tab as t3 on t2.a is null; @@ -54,18 +48,12 @@ from select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on t1.a is not null or t2.b = 1; + pred_tab as t1 left outer join pred_tab as t2 on t1.a is not null or t2.b = 1; select * from - pred_tab as t1 - full outer join - pred_tab as t2 - on t1.a = t2.a + pred_tab as t1 full outer join pred_tab as t2 on t1.a = t2.a left outer join pred_tab as t3 on t2.a is not null or t2.b = 1; @@ -73,18 +61,12 @@ from select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on t1.a is null or t1.c is null; + pred_tab as t1 left outer join pred_tab as t2 on t1.a is null or t1.c is null; select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on t1.a = 1 + pred_tab as t1 left outer join pred_tab as t2 on t1.a = 1 left outer join pred_tab as t3 on t2.a is null or t2.c is null; @@ -178,10 +160,7 @@ analyze pred_tab_notnull; select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on true + pred_tab as t1 left outer join pred_tab as t2 on true left outer join pred_tab_notnull as t3 on t2.a = t3.a @@ -192,10 +171,7 @@ from select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on true + pred_tab as t1 left outer join pred_tab as t2 on true left outer join pred_tab_notnull as t3 on t2.a = t3.a @@ -206,10 +182,7 @@ from select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on true + pred_tab as t1 left outer join pred_tab as t2 on true left outer join pred_tab_notnull as t3 on t2.a = t3.a @@ -220,10 +193,7 @@ from select * from - pred_tab as t1 - left outer join - pred_tab as t2 - on true + pred_tab as t1 left outer join pred_tab as t2 on true left outer join pred_tab_notnull as t3 on t2.a = t3.a @@ -238,13 +208,13 @@ drop table pred_tab_notnull; create table pred_tab1 ( a int not null, b int, - constraint "check_tab1" check (a is null or b > 2) + constraint check_tab1 check (a is null or b > 2) ); create table pred_tab2 ( a int, b int, - constraint "check_a" check (a is not null) + constraint check_a check (a is not null) ); set constraint_exclusion = 'on'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepare_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepare_100.snap index a3c175c57..e3e4eaeea 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepare_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepare_100.snap @@ -32,53 +32,27 @@ select name, statement, parameter_types, result_types from pg_prepared_statement prepare q2 (text) -as select - datname, - datistemplate, - datallowconn -from - pg_database -where - datname = $1;; +as select datname, datistemplate, datallowconn from pg_database where datname = $1;; execute q2 ('postgres'); prepare q3 -(text, -int, -double precision, -boolean, -smallint) +(text, int, double precision, boolean, smallint) as select * from tenk1 where - string4 = $1 and - ( - four = $2 or - ten = cast($3 as bigint) or - true = $4 or - odd = cast($5 as int) - ) + string4 = $1 and (four = $2 or ten = cast($3 as bigint) or true = $4 or odd = cast($5 as int)) order by unique1;; execute q3 -('AAAAxx', -cast(5 as smallint), -cast(10.5 as double precision), -false, -cast(4 as bigint)); +('AAAAxx', cast(5 as smallint), cast(10.5 as double precision), false, cast(4 as bigint)); execute q3 ('bool'); execute q3 -('bytea', -cast(5 as smallint), -cast(10.5 as double precision), -false, -cast(4 as bigint), -true); +('bytea', cast(5 as smallint), cast(10.5 as double precision), false, cast(4 as bigint), true); execute q3 (cast(5 as smallint), cast(10.5 as double precision), false, cast(4 as bigint), 'bytea'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepare_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepare_80.snap index bd991fdf7..cb1abb97a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepare_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepare_80.snap @@ -74,11 +74,7 @@ where execute q2 ('postgres'); prepare q3 -(text, -int, -double precision, -boolean, -smallint) +(text, int, double precision, boolean, smallint) as select * from @@ -86,49 +82,45 @@ from where string4 = $1 and ( - four = $2 or - ten = cast($3 as bigint) or - true = $4 or - odd = cast($5 as int) + four = $2 or ten = cast($3 as bigint) or true = $4 or odd = cast($5 as int) ) order by unique1;; execute q3 -('AAAAxx', -cast(5 as smallint), -cast(10.5 as double precision), -false, -cast(4 as bigint)); +( + 'AAAAxx', + cast(5 as smallint), + cast(10.5 as double precision), + false, + cast(4 as bigint) +); execute q3 ('bool'); execute q3 -('bytea', -cast(5 as smallint), -cast(10.5 as double precision), -false, -cast(4 as bigint), -true); +( + 'bytea', + cast(5 as smallint), + cast(10.5 as double precision), + false, + cast(4 as bigint), + true +); execute q3 -(cast(5 as smallint), -cast(10.5 as double precision), -false, -cast(4 as bigint), -'bytea'); +( + cast(5 as smallint), + cast(10.5 as double precision), + false, + cast(4 as bigint), + 'bytea' +); prepare q4 (nonexistenttype) as select $1;; prepare q5 -(int, -text) -as select - * -from - tenk1 -where - unique1 = $1 or stringu1 = $2 -order by unique1;; +(int, text) +as select * from tenk1 where unique1 = $1 or stringu1 = $2 order by unique1;; create temporary table q5_prep_results as execute q5 (200, 'DTAAAA'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepared_xacts_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepared_xacts_100.snap index 7d605d2b5..9cc26dada 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepared_xacts_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepared_xacts_100.snap @@ -125,7 +125,7 @@ insert into pxtest4 values (1); insert into pxtest4 values (2); -declare "foo" cursor for select * from pxtest4;; +declare foo cursor for select * from pxtest4;; fetch next from foo; @@ -139,7 +139,7 @@ select gid from pg_prepared_xacts where gid ~ '^regress_' order by gid; begin; -lock table pxtest3 in ACCESS SHARE mode nowait; +lock table pxtest3 in access share mode nowait; rollback; @@ -147,7 +147,7 @@ select gid from pg_prepared_xacts where gid ~ '^regress_' order by gid; begin; -lock table pxtest3 in ACCESS SHARE mode nowait; +lock table pxtest3 in access share mode nowait; rollback; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepared_xacts_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepared_xacts_80.snap index 7d605d2b5..9cc26dada 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepared_xacts_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__prepared_xacts_80.snap @@ -125,7 +125,7 @@ insert into pxtest4 values (1); insert into pxtest4 values (2); -declare "foo" cursor for select * from pxtest4;; +declare foo cursor for select * from pxtest4;; fetch next from foo; @@ -139,7 +139,7 @@ select gid from pg_prepared_xacts where gid ~ '^regress_' order by gid; begin; -lock table pxtest3 in ACCESS SHARE mode nowait; +lock table pxtest3 in access share mode nowait; rollback; @@ -147,7 +147,7 @@ select gid from pg_prepared_xacts where gid ~ '^regress_' order by gid; begin; -lock table pxtest3 in ACCESS SHARE mode nowait; +lock table pxtest3 in access share mode nowait; rollback; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_100.snap index d7a90e9df..950efcbc2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_100.snap @@ -50,15 +50,15 @@ create user regress_priv_user10; create role regress_priv_role; -grant REGRESS_PRIV_USER1 to regress_priv_user2 with ADMIN true; +grant regress_priv_user1 to regress_priv_user2 with admin true; -grant REGRESS_PRIV_USER1 to regress_priv_user3 with ADMIN true granted by regress_priv_user2; +grant regress_priv_user1 to regress_priv_user3 with admin true granted by regress_priv_user2; -grant REGRESS_PRIV_USER1 to regress_priv_user2 with ADMIN true granted by regress_priv_user3; +grant regress_priv_user1 to regress_priv_user2 with admin true granted by regress_priv_user3; -revoke ADMIN option for REGRESS_PRIV_USER1 from regress_priv_user2 restrict; +revoke admin option for regress_priv_user1 from regress_priv_user2 restrict; -revoke REGRESS_PRIV_USER1 from regress_priv_user2 restrict; +revoke regress_priv_user1 from regress_priv_user2 restrict; select cast(member as regrole), @@ -70,7 +70,7 @@ where begin; -revoke ADMIN option for REGRESS_PRIV_USER1 from regress_priv_user2 cascade; +revoke admin option for regress_priv_user1 from regress_priv_user2 cascade; select cast(member as regrole), @@ -82,7 +82,7 @@ where rollback; -revoke REGRESS_PRIV_USER1 from regress_priv_user2 cascade; +revoke regress_priv_user1 from regress_priv_user2 cascade; select cast(member as regrole), @@ -92,31 +92,30 @@ from where roleid = cast('regress_priv_user1' as regrole); -grant REGRESS_PRIV_USER1 to regress_priv_user2 with ADMIN true; +grant regress_priv_user1 to regress_priv_user2 with admin true; -grant REGRESS_PRIV_USER2 to regress_priv_user3; +grant regress_priv_user2 to regress_priv_user3; set role to regress_priv_user3; -grant REGRESS_PRIV_USER1 to regress_priv_user4; +grant regress_priv_user1 to regress_priv_user4; select cast(grantor as regrole) from pg_auth_members where - roleid = cast('regress_priv_user1' as regrole) and - member = cast('regress_priv_user4' as regrole); + roleid = cast('regress_priv_user1' as regrole) and member = cast('regress_priv_user4' as regrole); reset role; -revoke REGRESS_PRIV_USER2 from regress_priv_user3 restrict; +revoke regress_priv_user2 from regress_priv_user3 restrict; -revoke REGRESS_PRIV_USER1 from regress_priv_user2 cascade; +revoke regress_priv_user1 from regress_priv_user2 cascade; -grant REGRESS_PRIV_USER1 to regress_priv_user2 with ADMIN true; +grant regress_priv_user1 to regress_priv_user2 with admin true; -grant REGRESS_PRIV_USER1 to regress_priv_user3 granted by regress_priv_user2; +grant regress_priv_user1 to regress_priv_user3 granted by regress_priv_user2; drop role regress_priv_user2; @@ -128,9 +127,9 @@ drop owned by regress_priv_user2; drop role regress_priv_user2; -grant REGRESS_PRIV_USER1 to regress_priv_user3 with ADMIN true; +grant regress_priv_user1 to regress_priv_user3 with admin true; -grant REGRESS_PRIV_USER1 to regress_priv_user4 granted by regress_priv_user3; +grant regress_priv_user1 to regress_priv_user4 granted by regress_priv_user3; drop role regress_priv_user3; @@ -138,9 +137,9 @@ drop role regress_priv_user4; drop role regress_priv_user3; -grant REGRESS_PRIV_USER1 to regress_priv_user5 with ADMIN true; +grant regress_priv_user1 to regress_priv_user5 with admin true; -grant REGRESS_PRIV_USER1 to regress_priv_user6 granted by regress_priv_user5; +grant regress_priv_user1 to regress_priv_user6 granted by regress_priv_user5; drop role regress_priv_user5; @@ -156,35 +155,35 @@ create user regress_priv_user4; create user regress_priv_user5; -grant PG_READ_ALL_DATA to regress_priv_user6; +grant pg_read_all_data to regress_priv_user6; -grant PG_WRITE_ALL_DATA to regress_priv_user7; +grant pg_write_all_data to regress_priv_user7; -grant PG_READ_ALL_SETTINGS to regress_priv_user8 with ADMIN true; +grant pg_read_all_settings to regress_priv_user8 with admin true; -grant REGRESS_PRIV_USER9 to regress_priv_user8; +grant regress_priv_user9 to regress_priv_user8; set session authorization regress_priv_user8; -grant PG_READ_ALL_SETTINGS to regress_priv_user9 with ADMIN true; +grant pg_read_all_settings to regress_priv_user9 with admin true; set session authorization regress_priv_user9; -grant PG_READ_ALL_SETTINGS to regress_priv_user10; +grant pg_read_all_settings to regress_priv_user10; set session authorization regress_priv_user8; -revoke PG_READ_ALL_SETTINGS from regress_priv_user10 granted by regress_priv_user9 restrict; +revoke pg_read_all_settings from regress_priv_user10 granted by regress_priv_user9 restrict; -revoke ADMIN option for PG_READ_ALL_SETTINGS from regress_priv_user9 restrict; +revoke admin option for pg_read_all_settings from regress_priv_user9 restrict; -revoke PG_READ_ALL_SETTINGS from regress_priv_user9 restrict; +revoke pg_read_all_settings from regress_priv_user9 restrict; reset session_authorization; -revoke REGRESS_PRIV_USER9 from regress_priv_user8 restrict; +revoke regress_priv_user9 from regress_priv_user8 restrict; -revoke ADMIN option for PG_READ_ALL_SETTINGS from regress_priv_user8 restrict; +revoke admin option for pg_read_all_settings from regress_priv_user8 restrict; set session authorization regress_priv_user8; @@ -194,9 +193,9 @@ reset role; reset session_authorization; -revoke SET option for PG_READ_ALL_SETTINGS from regress_priv_user8 restrict; +revoke set option for pg_read_all_settings from regress_priv_user8 restrict; -grant PG_READ_ALL_STATS to regress_priv_user8 with SET false; +grant pg_read_all_stats to regress_priv_user8 with set false; set session authorization regress_priv_user8; @@ -208,7 +207,7 @@ reset role; reset session_authorization; -grant REGRESS_PRIV_USER9 to regress_priv_user8; +grant regress_priv_user9 to regress_priv_user8; set session authorization regress_priv_user8; @@ -262,7 +261,7 @@ select reset debug_parallel_query; -revoke PG_READ_ALL_SETTINGS from regress_priv_user8 restrict; +revoke pg_read_all_settings from regress_priv_user8 restrict; drop role regress_priv_user10; @@ -276,7 +275,7 @@ create group regress_priv_group2 admin regress_priv_user1 role regress_priv_user alter group regress_priv_group1 add user regress_priv_user4; -grant REGRESS_PRIV_GROUP2 to regress_priv_user2 granted by regress_priv_user1; +grant regress_priv_group2 to regress_priv_user2 granted by regress_priv_user1; set session authorization regress_priv_user3; @@ -298,35 +297,33 @@ reset session_authorization; alter group regress_priv_group2 drop user regress_priv_user2; -revoke ADMIN option for REGRESS_PRIV_GROUP2 from regress_priv_user1 restrict; +revoke admin option for regress_priv_group2 from regress_priv_user1 restrict; -grant REGRESS_PRIV_GROUP2 to regress_priv_user4 with ADMIN true; +grant regress_priv_group2 to regress_priv_user4 with admin true; create function leak(int, int) returns boolean language internal immutable strict -as $function$ -int4lt -$function$; +as 'int4lt'; alter function leak(int, int) owner to regress_priv_user1; -grant REGRESS_PRIV_ROLE to regress_priv_user1 with ADMIN true granted by regress_priv_role; +grant regress_priv_role to regress_priv_user1 with admin true granted by regress_priv_role; -grant REGRESS_PRIV_ROLE to regress_priv_user1 with ADMIN true granted by current_role; +grant regress_priv_role to regress_priv_user1 with admin true granted by current_role; -revoke ADMIN option for REGRESS_PRIV_ROLE from regress_priv_user1 granted by foo restrict; +revoke admin option for regress_priv_role from regress_priv_user1 granted by foo restrict; -revoke ADMIN option for REGRESS_PRIV_ROLE +revoke admin option for regress_priv_role from regress_priv_user1 granted by regress_priv_user2 restrict; -revoke ADMIN option for REGRESS_PRIV_ROLE from regress_priv_user1 granted by current_user restrict; +revoke admin option for regress_priv_role from regress_priv_user1 granted by current_user restrict; -revoke REGRESS_PRIV_ROLE from regress_priv_user1 granted by current_role restrict; +revoke regress_priv_role from regress_priv_user1 granted by current_role restrict; drop role regress_priv_role; @@ -351,7 +348,7 @@ truncate atest1; begin; -lock table atest1 in ACCESS EXCLUSIVE mode; +lock table atest1 in access exclusive mode; commit; @@ -361,7 +358,7 @@ select * from atest1; grant all on table atest1 to regress_priv_user2; -grant SELECT on table atest1 to regress_priv_user3, regress_priv_user4; +grant select on table atest1 to regress_priv_user3, regress_priv_user4; select * from atest1; @@ -372,13 +369,13 @@ create table atest2 ( select pg_get_acl(cast('pg_class' as regclass), cast(cast('atest2' as regclass) as oid), 0); -grant SELECT on table atest2 to regress_priv_user2; +grant select on table atest2 to regress_priv_user2; -grant UPDATE on table atest2 to regress_priv_user3; +grant update on table atest2 to regress_priv_user3; -grant INSERT on table atest2 to regress_priv_user4 granted by current_user; +grant insert on table atest2 to regress_priv_user4 granted by current_user; -grant TRUNCATE on table atest2 to regress_priv_user5 granted by current_role; +grant truncate on table atest2 to regress_priv_user5 granted by current_role; select unnest(pg_get_acl(cast('pg_class' as regclass), cast(cast('atest2' as regclass) as oid), 0)); @@ -386,7 +383,7 @@ select pg_get_acl(cast('pg_class' as regclass), 0, 0); select pg_get_acl(0, 0, 0); -grant TRUNCATE on table atest2 to regress_priv_user4 granted by regress_priv_user5; +grant truncate on table atest2 to regress_priv_user4 granted by regress_priv_user5; set session authorization regress_priv_user2; @@ -416,7 +413,7 @@ truncate atest2; begin; -lock table atest2 in ACCESS EXCLUSIVE mode; +lock table atest2 in access exclusive mode; commit; @@ -482,7 +479,7 @@ truncate atest2; begin; -lock table atest2 in ACCESS EXCLUSIVE mode; +lock table atest2 in access exclusive mode; commit; @@ -507,11 +504,11 @@ alter table atest12 set default_statistics_target = 10000; -vacuum (ANALYZE) atest12; +vacuum (analyze) atest12; reset default_statistics_target; -create operator <<< (PROCEDURE = leak, LEFTARG = int, RIGHTARG = int, RESTRICT = scalarltsel); +create operator <<< (procedure = leak, leftarg = int, rightarg = int, restrict = scalarltsel); create view atest12v as select * from atest12 where b <<< 5; @@ -532,11 +529,9 @@ create function leak2(int, int) returns boolean language plpgsql immutable -as $function$ -begin raise notice 'leak % %', $1, $2; return $1 > $2; end -$function$; +as $$begin raise notice 'leak % %', $1, $2; return $1 > $2; end$$; -create operator >>> (PROCEDURE = leak2, LEFTARG = int, RIGHTARG = int, RESTRICT = scalargtsel); +create operator >>> (procedure = leak2, leftarg = int, rightarg = int, restrict = scalargtsel); select * from atest12 where a >>> 0; @@ -546,9 +541,9 @@ select * from atest12sbv where a >>> 0; set session authorization regress_priv_user1; -grant SELECT on table atest12v to public; +grant select on table atest12v to public; -grant SELECT on table atest12sbv to public; +grant select on table atest12sbv to public; set session authorization regress_priv_user2; @@ -562,7 +557,7 @@ select * from atest12sbv as x, atest12sbv as y where x.a = y.b and abs(y.a) <<< set session authorization regress_priv_user1; -grant SELECT (a, b) on table atest12 to public; +grant select (a, b) on table atest12 to public; set session authorization regress_priv_user2; @@ -580,7 +575,7 @@ create table atest3 ( three int ); -grant DELETE on table atest3 to regress_priv_group2; +grant delete on table atest3 to regress_priv_group2; set session authorization regress_priv_user1; @@ -604,7 +599,7 @@ rollback to savepoint s1; reset session_authorization; -grant REGRESS_PRIV_GROUP2 to regress_priv_user1 with INHERIT false; +grant regress_priv_group2 to regress_priv_user1 with inherit false; set session authorization regress_priv_user1; @@ -614,7 +609,7 @@ rollback to savepoint s1; reset session_authorization; -revoke INHERIT option for REGRESS_PRIV_GROUP2 from regress_priv_user1 restrict; +revoke inherit option for regress_priv_group2 from regress_priv_user1 restrict; set session authorization regress_priv_user1; @@ -640,9 +635,9 @@ select * from atestv1; select * from atestv2; -grant SELECT on table atestv1, atestv3 to regress_priv_user4; +grant select on table atestv1, atestv3 to regress_priv_user4; -grant SELECT on table atestv2 to regress_priv_user2; +grant select on table atestv2 to regress_priv_user2; set session authorization regress_priv_user4; @@ -672,21 +667,9 @@ select * from ( - select - a.q1 as x, - random() - from - int8_tbl as a - where - q1 > 0 + select a.q1 as x, random() from int8_tbl as a where q1 > 0 union all - select - b.q2 as x, - random() - from - int8_tbl as b - where - q2 > 0 + select b.q2 as x, random() from int8_tbl as b where q2 > 0 ) as ss where @@ -699,7 +682,7 @@ as select * from atestv3; select * from atestv4; -grant SELECT on table atestv4 to regress_priv_user2; +grant select on table atestv4 to regress_priv_user2; set session authorization regress_priv_user2; @@ -726,7 +709,7 @@ create table atest6 ( blue int ); -grant SELECT (one), INSERT (two), UPDATE (three) on table atest5 to regress_priv_user4; +grant select (one), insert (two), update (three) on table atest5 to regress_priv_user4; grant all (one) on table atest5 to regress_priv_user3; @@ -758,51 +741,51 @@ copy atest5 (one, two) to stdout; select 1 from atest5; -select 1 from atest5 as a inner join atest5 as b using ("one"); +select 1 from atest5 as a inner join atest5 as b using (one); -select 1 from atest5 as a inner join atest5 as b using ("two"); +select 1 from atest5 as a inner join atest5 as b using (two); select 1 from atest5 as a natural join atest5 as b; -select * from (atest5 as a inner join atest5 as b using ("one")) as "j"; +select * from (atest5 as a inner join atest5 as b using (one)) as j; -select j.* from (atest5 as a inner join atest5 as b using ("one")) as "j"; +select j.* from (atest5 as a inner join atest5 as b using (one)) as j; -select j.* is null from (atest5 as a inner join atest5 as b using ("one")) as "j"; +select j.* is null from (atest5 as a inner join atest5 as b using (one)) as j; -select one from (atest5 as a inner join atest5 as b (one, x, y, z) using ("one")) as "j"; +select one from (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; -select j.one from (atest5 as a inner join atest5 as b (one, x, y, z) using ("one")) as "j"; +select j.one from (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; -select two from (atest5 as a inner join atest5 as b (one, x, y, z) using ("one")) as "j"; +select two from (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; -select j.two from (atest5 as a inner join atest5 as b (one, x, y, z) using ("one")) as "j"; +select j.two from (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; -select y from (atest5 as a inner join atest5 as b (one, x, y, z) using ("one")) as "j"; +select y from (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; -select j.y from (atest5 as a inner join atest5 as b (one, x, y, z) using ("one")) as "j"; +select j.y from (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; -select * from atest5 as a inner join atest5 as b using ("one"); +select * from atest5 as a inner join atest5 as b using (one); -select a.* from atest5 as a inner join atest5 as b using ("one"); +select a.* from atest5 as a inner join atest5 as b using (one); -select a.* is null from atest5 as a inner join atest5 as b using ("one"); +select a.* is null from atest5 as a inner join atest5 as b using (one); -select two from atest5 as a inner join atest5 as b (one, x, y, z) using ("one"); +select two from atest5 as a inner join atest5 as b (one, x, y, z) using (one); -select a.two from atest5 as a inner join atest5 as b (one, x, y, z) using ("one"); +select a.two from atest5 as a inner join atest5 as b (one, x, y, z) using (one); -select y from atest5 as a inner join atest5 as b (one, x, y, z) using ("one"); +select y from atest5 as a inner join atest5 as b (one, x, y, z) using (one); -select b.y from atest5 as a inner join atest5 as b (one, x, y, z) using ("one"); +select b.y from atest5 as a inner join atest5 as b (one, x, y, z) using (one); -select y from atest5 as a left outer join atest5 as b (one, x, y, z) using ("one"); +select y from atest5 as a left outer join atest5 as b (one, x, y, z) using (one); -select b.y from atest5 as a left outer join atest5 as b (one, x, y, z) using ("one"); +select b.y from atest5 as a left outer join atest5 as b (one, x, y, z) using (one); -select y from atest5 as a full outer join atest5 as b (one, x, y, z) using ("one"); +select y from atest5 as a full outer join atest5 as b (one, x, y, z) using (one); -select b.y from atest5 as a full outer join atest5 as b (one, x, y, z) using ("one"); +select b.y from atest5 as a full outer join atest5 as b (one, x, y, z) using (one); select 1 from atest5 where two = 2; @@ -820,7 +803,7 @@ select one, two from atest5; set session authorization regress_priv_user1; -grant SELECT (one, two) on table atest6 to regress_priv_user4; +grant select (one, two) on table atest6 to regress_priv_user4; set session authorization regress_priv_user4; @@ -828,7 +811,7 @@ select one, two from atest5 natural join atest6; set session authorization regress_priv_user1; -grant SELECT (two) on table atest5 to regress_priv_user4; +grant select (two) on table atest5 to regress_priv_user4; set session authorization regress_priv_user4; @@ -867,7 +850,7 @@ insert into atest5 (four) values (4); set session authorization regress_priv_user1; -grant INSERT (four) on table atest5 to regress_priv_user4; +grant insert (four) on table atest5 to regress_priv_user4; set session authorization regress_priv_user4; @@ -875,17 +858,13 @@ insert into atest5 (four) values (4) on conflict (four) do update set three = 3; insert into atest5 (four) values (4) -on conflict -on constraint atest5_four_key -do -update -set three = 3; +on conflict on constraint atest5_four_key do update set three = 3; insert into atest5 (four) values (4); set session authorization regress_priv_user1; -grant SELECT (four) on table atest5 to regress_priv_user4; +grant select (four) on table atest5 to regress_priv_user4; set session authorization regress_priv_user4; @@ -893,17 +872,13 @@ insert into atest5 (four) values (4) on conflict (four) do update set three = 3; insert into atest5 (four) values (4) -on conflict -on constraint atest5_four_key -do -update -set three = 3; +on conflict on constraint atest5_four_key do update set three = 3; set session authorization regress_priv_user1; revoke all (one) on table atest5 from regress_priv_user4; -grant SELECT (one, two, blue) on table atest6 to regress_priv_user4; +grant select (one, two, blue) on table atest6 to regress_priv_user4; set session authorization regress_priv_user4; @@ -931,13 +906,13 @@ insert into mtarget values (1, 'init1'), (2, 'init2'); insert into msource values (1, 'source1'), (2, 'source2'), (3, 'source3'); -grant SELECT (a) on table msource to regress_priv_user4; +grant select (a) on table msource to regress_priv_user4; -grant SELECT (a) on table mtarget to regress_priv_user4; +grant select (a) on table mtarget to regress_priv_user4; -grant INSERT (a, b) on table mtarget to regress_priv_user4; +grant insert (a, b) on table mtarget to regress_priv_user4; -grant UPDATE (b) on table mtarget to regress_priv_user4; +grant update (b) on table mtarget to regress_priv_user4; set session authorization regress_priv_user4; @@ -947,7 +922,7 @@ rollback; set session authorization regress_priv_user1; -grant SELECT (b) on table msource to regress_priv_user4; +grant select (b) on table msource to regress_priv_user4; set session authorization regress_priv_user4; @@ -961,7 +936,7 @@ rollback; set session authorization regress_priv_user1; -grant DELETE on table mtarget to regress_priv_user4; +grant delete on table mtarget to regress_priv_user4; begin; @@ -976,11 +951,11 @@ create table t1 ( primary key (c1, c2) ); -grant SELECT (c1) on table t1 to regress_priv_user2; +grant select (c1) on table t1 to regress_priv_user2; -grant INSERT (c1, c2, c3) on table t1 to regress_priv_user2; +grant insert (c1, c2, c3) on table t1 to regress_priv_user2; -grant UPDATE (c1, c2, c3) on table t1 to regress_priv_user2; +grant update (c1, c2, c3) on table t1 to regress_priv_user2; insert into t1 values (1, 1, 1); @@ -1017,7 +992,7 @@ create table errtst ( secret1 text, secret2 text ) -partition by LIST(a); +partition by list(a); create table errtst_part_1 ( secret2 text, @@ -1043,17 +1018,14 @@ alter table errtst attach partition errtst_part_2 for values in ('aaaa'); -grant SELECT (a, b, c) on table errtst to regress_priv_user2; +grant select (a, b, c) on table errtst to regress_priv_user2; -grant UPDATE (a, b, c) on table errtst to regress_priv_user2; +grant update (a, b, c) on table errtst to regress_priv_user2; -grant INSERT (a, b, c) on table errtst to regress_priv_user2; +grant insert (a, b, c) on table errtst to regress_priv_user2; insert into errtst_part_1 (a, b, c, secret1, secret2) -values - ( - 'aaa', 'bbb', 'ccc', 'the body', 'is in the attic' - ); +values ('aaa', 'bbb', 'ccc', 'the body', 'is in the attic'); set session authorization regress_priv_user2; @@ -1076,13 +1048,13 @@ set session authorization regress_priv_user1; alter table atest6 add column three int; -grant DELETE on table atest5 to regress_priv_user3; +grant delete on table atest5 to regress_priv_user3; -grant SELECT (two) on table atest5 to regress_priv_user3; +grant select (two) on table atest5 to regress_priv_user3; revoke all (one) on table atest5 from regress_priv_user3; -grant SELECT (one) on table atest5 to regress_priv_user4; +grant select (one) on table atest5 to regress_priv_user4; set session authorization regress_priv_user4; @@ -1106,7 +1078,7 @@ set session authorization regress_priv_user1; alter table atest6 drop column two; -revoke SELECT (one, blue) on table atest6 from regress_priv_user4; +revoke select (one, blue) on table atest6 from regress_priv_user4; set session authorization regress_priv_user4; @@ -1133,12 +1105,11 @@ create table atestp2 ( ); create table atestc (fz int) -inherits (atestp1, -atestp2); +inherits (atestp1, atestp2); -grant SELECT (fx, fy, tableoid) on table atestp2 to regress_priv_user2; +grant select (fx, fy, tableoid) on table atestp2 to regress_priv_user2; -grant SELECT (fx) on table atestc to regress_priv_user2; +grant select (fx) on table atestc to regress_priv_user2; set session authorization regress_priv_user2; @@ -1154,7 +1125,7 @@ select fy from atestc; set session authorization regress_priv_user1; -grant SELECT (fy, tableoid) on table atestc to regress_priv_user2; +grant select (fy, tableoid) on table atestc to regress_priv_user2; set session authorization regress_priv_user2; @@ -1192,51 +1163,45 @@ truncate atestc; begin; -lock table atestp1 in ACCESS EXCLUSIVE mode; +lock table atestp1 in access exclusive mode; commit; begin; -lock table atestc in ACCESS EXCLUSIVE mode; +lock table atestc in access exclusive mode; commit; revoke all on language sql from public; -grant USAGE on language sql to regress_priv_user1; +grant usage on language sql to regress_priv_user1; -grant USAGE on language c to public; +grant usage on language c to public; set session authorization regress_priv_user1; -grant USAGE on language sql to regress_priv_user2; +grant usage on language sql to regress_priv_user2; create function priv_testfunc1(int) returns int language sql -as $function$ -select 2 * $1; -$function$; +as 'select 2 * $1;'; create function priv_testfunc2(int) returns int language sql -as $function$ -select 3 * $1; -$function$; +as 'select 3 * $1;'; -create aggregate priv_testagg1 (int) (sfunc = int4pl, stype = int); +create aggregate priv_testagg1 (int) (sfunc = int4pl, stype = int4); create procedure priv_testproc1(int) language sql -as $procedure$ -select $1; -$procedure$; +as 'select $1;'; revoke all on function priv_testfunc1(int), priv_testfunc2(int), priv_testagg1(int) from public; -grant EXECUTE +grant execute on function priv_testfunc1(int), priv_testfunc2(int), priv_testagg1(int) @@ -1246,13 +1211,13 @@ revoke all on function priv_testproc1(int) from public; revoke all on procedure priv_testproc1(int) from public; -grant EXECUTE on procedure priv_testproc1(int) to regress_priv_user2; +grant execute on procedure priv_testproc1(int) to regress_priv_user2; -grant USAGE on function priv_testfunc1(int) to regress_priv_user3; +grant usage on function priv_testfunc1(int) to regress_priv_user3; -grant USAGE on function priv_testagg1(int) to regress_priv_user3; +grant usage on function priv_testagg1(int) to regress_priv_user3; -grant USAGE on procedure priv_testproc1(int) to regress_priv_user3; +grant usage on procedure priv_testproc1(int) to regress_priv_user3; grant all on function priv_testfunc1(int) to regress_priv_user4; @@ -1266,11 +1231,9 @@ create function priv_testfunc4(boolean) returns text language sql security definer -as $function$ -select col1 from atest2 where col2 = $1; -$function$; +as 'select col1 from atest2 where col2 = $1;'; -grant EXECUTE on function priv_testfunc4(boolean) to regress_priv_user3; +grant execute on function priv_testfunc4(boolean) to regress_priv_user3; set session authorization regress_priv_user2; @@ -1279,9 +1242,7 @@ select priv_testfunc1(5), priv_testfunc2(5); create function priv_testfunc3(int) returns int language sql -as $function$ -select 2 * $1; -$function$; +as 'select 2 * $1;'; select priv_testagg1(x) from (values (1), (2), (3)) as _ (x); @@ -1319,35 +1280,35 @@ grant all on language sql to public; begin; -select cast(cast('{1}' as int[]) as bigint[]); +select cast(cast('{1}' as int4[]) as int8[]); revoke all on function int8(int) from public; -select cast(cast('{1}' as int[]) as bigint[]); +select cast(cast('{1}' as int4[]) as int8[]); set session authorization regress_priv_user4; -select cast(cast('{1}' as int[]) as bigint[]); +select cast(cast('{1}' as int4[]) as int8[]); rollback; create type priv_testtype1 as (a int, b text); -revoke USAGE on type priv_testtype1 from public; +revoke usage on type priv_testtype1 from public; -grant USAGE on type priv_testtype1 to regress_priv_user2; +grant usage on type priv_testtype1 to regress_priv_user2; -grant USAGE on type _priv_testtype1 to regress_priv_user2; +grant usage on type _priv_testtype1 to regress_priv_user2; -grant USAGE on domain priv_testtype1 to regress_priv_user2; +grant usage on domain priv_testtype1 to regress_priv_user2; create domain priv_testdomain1 as int; -revoke USAGE on domain priv_testdomain1 from public; +revoke usage on domain priv_testdomain1 from public; -grant USAGE on domain priv_testdomain1 to regress_priv_user2; +grant usage on domain priv_testdomain1 to regress_priv_user2; -grant USAGE on type priv_testdomain1 to regress_priv_user2; +grant usage on type priv_testdomain1 to regress_priv_user2; set session authorization regress_priv_user1; @@ -1360,9 +1321,7 @@ create domain priv_testdomain3a as int; create function castfunc(int) returns priv_testdomain3a language sql -as $function$ -SELECT $1::priv_testdomain3a -$function$; +as $$ SELECT $1::priv_testdomain3a $$; create cast (priv_testdomain1 as priv_testdomain3a) with function castfunc(int); @@ -1373,18 +1332,14 @@ drop domain priv_testdomain3a; create function priv_testfunc5a(a priv_testdomain1) returns int language sql -as $function$ -SELECT $1 -$function$; +as $$ SELECT $1 $$; create function priv_testfunc6a(b int) returns priv_testdomain1 language sql -as $function$ -SELECT $1::priv_testdomain1 -$function$; +as $$ SELECT $1::priv_testdomain1 $$; -create operator !+! (PROCEDURE = int4pl, LEFTARG = priv_testdomain1, RIGHTARG = priv_testdomain1); +create operator !+! (procedure = int4pl, leftarg = priv_testdomain1, rightarg = priv_testdomain1); create table test5a ( a int, @@ -1434,27 +1389,21 @@ create domain priv_testdomain3b as int; create function castfunc(int) returns priv_testdomain3b language sql -as $function$ -SELECT $1::priv_testdomain3b -$function$; +as $$ SELECT $1::priv_testdomain3b $$; create cast (priv_testdomain1 as priv_testdomain3b) with function castfunc(int); create function priv_testfunc5b(a priv_testdomain1) returns int language sql -as $function$ -SELECT $1 -$function$; +as $$ SELECT $1 $$; create function priv_testfunc6b(b int) returns priv_testdomain1 language sql -as $function$ -SELECT $1::priv_testdomain1 -$function$; +as $$ SELECT $1::priv_testdomain1 $$; -create operator !! (PROCEDURE = priv_testfunc5b, RIGHTARG = priv_testdomain1); +create operator !! (procedure = priv_testfunc5b, rightarg = priv_testdomain1); create table test5b ( a int, @@ -1499,9 +1448,9 @@ drop domain priv_testdomain2b; drop operator !! (none, priv_testdomain1); -drop function priv_testfunc5b(priv_testdomain1); +drop function priv_testfunc5b(a priv_testdomain1); -drop function priv_testfunc6b(int); +drop function priv_testfunc6b(b int); drop table test5b; @@ -1552,89 +1501,29 @@ select has_table_privilege(current_user, 'pg_authid', 'insert'); select has_table_privilege(t2.oid, 'pg_authid', 'update') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege(t2.oid, 'pg_authid', 'delete') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - current_user, - t1.oid, - 'references' - ) + has_table_privilege(current_user, t1.oid, 'references') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1; + (select oid from pg_class where relname = 'pg_authid') as t1; select has_table_privilege(t2.oid, t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'pg_authid') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege(t2.oid, t1.oid, 'insert') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'pg_authid') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege('pg_authid', 'update'); @@ -1645,28 +1534,12 @@ select has_table_privilege('pg_authid', 'truncate'); select has_table_privilege(t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1; + (select oid from pg_class where relname = 'pg_authid') as t1; select has_table_privilege(t1.oid, 'trigger') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1; + (select oid from pg_class where relname = 'pg_authid') as t1; set session authorization regress_priv_user3; @@ -1677,89 +1550,29 @@ select has_table_privilege(current_user, 'pg_class', 'insert'); select has_table_privilege(t2.oid, 'pg_class', 'update') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege(t2.oid, 'pg_class', 'delete') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - current_user, - t1.oid, - 'references' - ) + has_table_privilege(current_user, t1.oid, 'references') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1; + (select oid from pg_class where relname = 'pg_class') as t1; select has_table_privilege(t2.oid, t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'pg_class') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege(t2.oid, t1.oid, 'insert') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'pg_class') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege('pg_class', 'update'); @@ -1770,28 +1583,12 @@ select has_table_privilege('pg_class', 'truncate'); select has_table_privilege(t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1; + (select oid from pg_class where relname = 'pg_class') as t1; select has_table_privilege(t1.oid, 'trigger') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1; + (select oid from pg_class where relname = 'pg_class') as t1; select has_table_privilege(current_user, 'atest1', 'select'); @@ -1800,74 +1597,29 @@ select has_table_privilege(current_user, 'atest1', 'insert'); select has_table_privilege(t2.oid, 'atest1', 'update') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege(t2.oid, 'atest1', 'delete') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - current_user, - t1.oid, - 'references' - ) + has_table_privilege(current_user, t1.oid, 'references') from - ( - select oid from pg_class where relname = 'atest1' - ) - as t1; + (select oid from pg_class where relname = 'atest1') as t1; select has_table_privilege(t2.oid, t1.oid, 'select') from - ( - select oid from pg_class where relname = 'atest1' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'atest1') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege(t2.oid, t1.oid, 'insert') from - ( - select oid from pg_class where relname = 'atest1' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'atest1') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege('atest1', 'update'); @@ -1878,18 +1630,12 @@ select has_table_privilege('atest1', 'truncate'); select has_table_privilege(t1.oid, 'select') from - ( - select oid from pg_class where relname = 'atest1' - ) - as t1; + (select oid from pg_class where relname = 'atest1') as t1; select has_table_privilege(t1.oid, 'trigger') from - ( - select oid from pg_class where relname = 'atest1' - ) - as t1; + (select oid from pg_class where relname = 'atest1') as t1; select has_column_privilege('pg_authid', null, 'select'); @@ -1897,11 +1643,11 @@ select has_column_privilege('pg_authid', 'nosuchcol', 'select'); select has_column_privilege(9999, 'nosuchcol', 'select'); -select has_column_privilege(9999, cast(99 as smallint), 'select'); +select has_column_privilege(9999, cast(99 as int2), 'select'); -select has_column_privilege('pg_authid', cast(99 as smallint), 'select'); +select has_column_privilege('pg_authid', cast(99 as int2), 'select'); -select has_column_privilege(9999, cast(99 as smallint), 'select'); +select has_column_privilege(9999, cast(99 as int2), 'select'); create temporary table mytable ( f1 int, @@ -1916,15 +1662,15 @@ select has_column_privilege('mytable', 'f2', 'select'); select has_column_privilege('mytable', '........pg.dropped.2........', 'select'); -select has_column_privilege('mytable', cast(2 as smallint), 'select'); +select has_column_privilege('mytable', cast(2 as int2), 'select'); -select has_column_privilege('mytable', cast(99 as smallint), 'select'); +select has_column_privilege('mytable', cast(99 as int2), 'select'); -revoke SELECT on table mytable from regress_priv_user3; +revoke select on table mytable from regress_priv_user3; -select has_column_privilege('mytable', cast(2 as smallint), 'select'); +select has_column_privilege('mytable', cast(2 as int2), 'select'); -select has_column_privilege('mytable', cast(99 as smallint), 'select'); +select has_column_privilege('mytable', cast(99 as int2), 'select'); drop table mytable; @@ -1932,27 +1678,27 @@ set session authorization regress_priv_user1; create table atest4 (a int); -grant SELECT on table atest4 to regress_priv_user2 with grant option; +grant select on table atest4 to regress_priv_user2 with grant option; -grant UPDATE on table atest4 to regress_priv_user2; +grant update on table atest4 to regress_priv_user2; -grant SELECT on table atest4 to regress_priv_group1 with grant option; +grant select on table atest4 to regress_priv_group1 with grant option; set session authorization regress_priv_user2; -grant SELECT on table atest4 to regress_priv_user3; +grant select on table atest4 to regress_priv_user3; -grant UPDATE on table atest4 to regress_priv_user3; +grant update on table atest4 to regress_priv_user3; set session authorization regress_priv_user1; -revoke SELECT on table atest4 from regress_priv_user3; +revoke select on table atest4 from regress_priv_user3; select has_table_privilege('regress_priv_user3', 'atest4', 'SELECT'); -revoke SELECT on table atest4 from regress_priv_user2; +revoke select on table atest4 from regress_priv_user2; -revoke grant option for SELECT on table atest4 from regress_priv_user2 cascade; +revoke grant option for select on table atest4 from regress_priv_user2 cascade; select has_table_privilege('regress_priv_user2', 'atest4', 'SELECT'); @@ -1966,14 +1712,14 @@ create function sro_ifun(int) returns int language plpgsql immutable -as $function$ +as $$ BEGIN -- Below we set the table's owner to regress_sro_user ASSERT current_user = 'regress_sro_user', format('sro_ifun(%s) called by %s', $1, current_user); RETURN $1; END; -$function$; +$$; create table sro_tab (a int); @@ -1982,41 +1728,29 @@ alter table sro_tab insert into sro_tab values (1), (2), (3); -create index "sro_idx" -on sro_tab -using btree -( - (sro_ifun(a) + sro_ifun(0)) -) -where - sro_ifun(a + 10) > sro_ifun(10); +create index sro_idx on sro_tab using btree ((sro_ifun(a) + sro_ifun(0))) +where sro_ifun(a + 10) > sro_ifun(10); drop index sro_idx; -create index concurrently "sro_idx" -on sro_tab -using btree -( - (sro_ifun(a) + sro_ifun(0)) -) -where - sro_ifun(a + 10) > sro_ifun(10); +create index concurrently sro_idx on sro_tab using btree ((sro_ifun(a) + sro_ifun(0))) +where sro_ifun(a + 10) > sro_ifun(10); reindex table sro_tab; reindex index sro_idx; -reindex (CONCURRENTLY) table sro_tab; +reindex (concurrently) table sro_tab; drop index sro_idx; -create index "sro_cluster_idx" on sro_tab using btree ((sro_ifun(a) + sro_ifun(0))); +create index sro_cluster_idx on sro_tab using btree ((sro_ifun(a) + sro_ifun(0))); cluster sro_tab using sro_cluster_idx; drop index sro_cluster_idx; -create index "sro_brin" on sro_tab using brin ((sro_ifun(a) + sro_ifun(0))); +create index sro_brin on sro_tab using brin ((sro_ifun(a) + sro_ifun(0))); select brin_desummarize_range('sro_brin', 0); @@ -2037,34 +1771,24 @@ alter table sro_part insert into sro_ptab values (1), (2), (3); -create index "sro_pidx" -on sro_ptab -using btree -( - (sro_ifun(a) + sro_ifun(0)) -) -where - sro_ifun(a + 10) > sro_ifun(10); +create index sro_pidx on sro_ptab using btree ((sro_ifun(a) + sro_ifun(0))) +where sro_ifun(a + 10) > sro_ifun(10); reindex table sro_ptab; -reindex (CONCURRENTLY) index sro_pidx; +reindex (concurrently) index sro_pidx; set session authorization regress_sro_user; create function unwanted_grant() returns void language sql -as $function$ -GRANT regress_priv_group2 TO regress_sro_user -$function$; +as 'GRANT regress_priv_group2 TO regress_sro_user'; create function mv_action() -returns boolean +returns bool language sql -as $function$ -DECLARE c CURSOR WITH HOLD FOR SELECT public.unwanted_grant(); SELECT true -$function$; +as 'DECLARE c CURSOR WITH HOLD FOR SELECT public.unwanted_grant(); SELECT true'; create materialized view sro_mv as select mv_action() with no data; @@ -2079,9 +1803,7 @@ create table sro_trojan_table (); create function sro_trojan() returns trigger language plpgsql -as $function$ -BEGIN PERFORM public.unwanted_grant(); RETURN NULL; END -$function$; +as 'BEGIN PERFORM public.unwanted_grant(); RETURN NULL; END'; create constraint trigger t after insert @@ -2092,11 +1814,9 @@ for each row execute function sro_trojan(); create or replace function mv_action() -returns boolean +returns bool language sql -as $function$ -INSERT INTO public.sro_trojan_table DEFAULT VALUES; SELECT true -$function$; +as 'INSERT INTO public.sro_trojan_table DEFAULT VALUES; SELECT true'; refresh materialized view sro_mv; @@ -2116,26 +1836,18 @@ create function unwanted_grant_nofail(int) returns int language plpgsql immutable -as $function$ +as $$ BEGIN PERFORM public.unwanted_grant(); RAISE WARNING 'owned'; RETURN 1; EXCEPTION WHEN OTHERS THEN RETURN 2; -END -$function$; +END$$; create materialized view sro_index_mv as select 1 as c; -create unique index -on sro_index_mv -using btree -( - c -) -where - unwanted_grant_nofail(1) > 0; +create unique index on sro_index_mv using btree (c) where unwanted_grant_nofail(1) > 0; refresh materialized view concurrently sro_index_mv; @@ -2151,39 +1863,37 @@ create function dogrant_ok() returns void language sql security definer -as $function$ -GRANT regress_priv_group2 TO regress_priv_user5 -$function$; +as 'GRANT regress_priv_group2 TO regress_priv_user5'; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; set role to regress_priv_group2; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; set session authorization regress_priv_user1; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; select dogrant_ok(); set role to regress_priv_group2; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; set session authorization regress_priv_group2; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; set session authorization regress_priv_user4; drop function dogrant_ok(); -revoke REGRESS_PRIV_GROUP2 from regress_priv_user5 restrict; +revoke regress_priv_group2 from regress_priv_user5 restrict; create sequence x_seq; -grant USAGE on table x_seq to regress_priv_user2; +grant usage on table x_seq to regress_priv_user2; select has_sequence_privilege('regress_priv_user1', 'atest1', 'SELECT'); @@ -2209,19 +1919,19 @@ select lo_create(1005); grant all on large object 1001 to public; -grant SELECT on large object 1003 to regress_priv_user2; +grant select on large object 1003 to regress_priv_user2; -grant SELECT, UPDATE on large object 1004 to regress_priv_user2; +grant select, update on large object 1004 to regress_priv_user2; grant all on large object 1005 to regress_priv_user2; -grant SELECT on large object 1005 to regress_priv_user2 with grant option; +grant select on large object 1005 to regress_priv_user2 with grant option; -grant SELECT, INSERT on large object 1001 to public; +grant select, insert on large object 1001 to public; -grant SELECT, UPDATE on large object 1001 to nosuchuser; +grant select, update on large object 1001 to nosuchuser; -grant SELECT, UPDATE on large object 999 to public; +grant select, update on large object 999 to public; set session authorization regress_priv_user2; @@ -2249,9 +1959,9 @@ select lowrite(lo_open(1003, cast(X'20000' as int)), 'abcd'); select lowrite(lo_open(1004, cast(X'20000' as int)), 'abcd'); -grant SELECT on large object 1005 to regress_priv_user3; +grant select on large object 1005 to regress_priv_user3; -grant UPDATE on large object 1006 to regress_priv_user3; +grant update on large object 1006 to regress_priv_user3; revoke all on large object 2001, 2002 from public; @@ -2382,17 +2092,16 @@ reset session_authorization; begin; create or replace function terminate_nothrow(pid int) -returns boolean +returns bool language plpgsql security definer set client_min_messages = error -as $function$ +as $$ BEGIN RETURN pg_terminate_backend($1); EXCEPTION WHEN OTHERS THEN RETURN false; -END -$function$; +END$$; alter function terminate_nothrow owner to pg_signal_backend; @@ -2401,73 +2110,37 @@ select from pg_stat_activity where - case - when coalesce(usesysid, 10) = 10 - then terminate_nothrow(pid) - end; + case when coalesce(usesysid, 10) = 10 then terminate_nothrow(pid) end; rollback; reset session_authorization; -grant PG_DATABASE_OWNER to regress_priv_user1; +grant pg_database_owner to regress_priv_user1; -grant REGRESS_PRIV_USER1 to pg_database_owner; +grant regress_priv_user1 to pg_database_owner; create table datdba_only (); alter table datdba_only owner to pg_database_owner; -revoke DELETE on table datdba_only from pg_database_owner; +revoke delete on table datdba_only from pg_database_owner; select - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'USAGE' - ) - as priv, - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'MEMBER' - ) - as mem, - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'MEMBER WITH ADMIN OPTION' - ) - as admin; + pg_has_role('regress_priv_user1', 'pg_database_owner', 'USAGE') as priv, + pg_has_role('regress_priv_user1', 'pg_database_owner', 'MEMBER') as mem, + pg_has_role('regress_priv_user1', 'pg_database_owner', 'MEMBER WITH ADMIN OPTION') as admin; begin; -do -$do$ -BEGIN EXECUTE format( - 'ALTER DATABASE %I OWNER TO regress_priv_group2', current_catalog); END -$do$; +do $$BEGIN EXECUTE format( + 'ALTER DATABASE %I OWNER TO regress_priv_group2', current_catalog); END$$; select - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'USAGE' - ) - as priv, - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'MEMBER' - ) - as mem, - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'MEMBER WITH ADMIN OPTION' - ) - as admin; + pg_has_role('regress_priv_user1', 'pg_database_owner', 'USAGE') as priv, + pg_has_role('regress_priv_user1', 'pg_database_owner', 'MEMBER') as mem, + pg_has_role('regress_priv_user1', 'pg_database_owner', 'MEMBER WITH ADMIN OPTION') as admin; set session authorization regress_priv_user1; @@ -2491,7 +2164,7 @@ insert into datdba_only default values; rollback; -create schema "testns"; +create schema testns; grant all on schema testns to regress_priv_user1; @@ -2501,7 +2174,7 @@ select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'SELECT'); select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'INSERT'); -alter default privileges in schema testns, testns grant SELECT on tables to public, public; +alter default privileges in schema testns, testns grant select on tables to public, public; select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'SELECT'); @@ -2515,7 +2188,7 @@ select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'SELECT'); select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'INSERT'); -alter default privileges in schema testns grant INSERT on tables to regress_priv_user1; +alter default privileges in schema testns grant insert on tables to regress_priv_user1; drop table testns.acltest1; @@ -2525,7 +2198,7 @@ select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'SELECT'); select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'INSERT'); -alter default privileges in schema testns revoke INSERT on tables from regress_priv_user1; +alter default privileges in schema testns revoke insert on tables from regress_priv_user1; drop table testns.acltest1; @@ -2535,9 +2208,9 @@ select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'SELECT'); select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'INSERT'); -alter default privileges for role regress_priv_user1 revoke EXECUTE on functions from public; +alter default privileges for role regress_priv_user1 revoke execute on functions from public; -alter default privileges in schema testns grant USAGE on schemas to regress_priv_user2; +alter default privileges in schema testns grant usage on schemas to regress_priv_user2; select makeaclitem( @@ -2595,9 +2268,9 @@ select * from pg_input_error_info('regress_priv_user1=rY', 'aclitem'); begin; -alter default privileges grant USAGE on schemas to regress_priv_user2; +alter default privileges grant usage on schemas to regress_priv_user2; -create schema "testns2"; +create schema testns2; select has_schema_privilege('regress_priv_user2', 'testns2', 'USAGE'); @@ -2605,9 +2278,9 @@ select has_schema_privilege('regress_priv_user6', 'testns2', 'USAGE'); select has_schema_privilege('regress_priv_user2', 'testns2', 'CREATE'); -alter default privileges revoke USAGE on schemas from regress_priv_user2; +alter default privileges revoke usage on schemas from regress_priv_user2; -create schema "testns3"; +create schema testns3; select has_schema_privilege('regress_priv_user2', 'testns3', 'USAGE'); @@ -2615,7 +2288,7 @@ select has_schema_privilege('regress_priv_user2', 'testns3', 'CREATE'); alter default privileges grant all on schemas to regress_priv_user2; -create schema "testns4"; +create schema testns4; select has_schema_privilege('regress_priv_user2', 'testns4', 'USAGE'); @@ -2668,7 +2341,7 @@ alter default privileges grant all on tables to regress_priv_user2; alter default privileges grant all on types to regress_priv_user2; select - COUNT(*) + count(*) from pg_shdepend where @@ -2679,7 +2352,7 @@ where drop owned by regress_priv_user2, regress_priv_user2; select - COUNT(*) + count(*) from pg_shdepend where @@ -2689,7 +2362,7 @@ where rollback; -create schema "testns5"; +create schema testns5; select has_schema_privilege('regress_priv_user2', 'testns5', 'USAGE'); @@ -2700,17 +2373,13 @@ set role to regress_priv_user1; create function testns.foo() returns int language sql -as $function$ -select 1 -$function$; +as 'select 1'; -create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int); +create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int4); create procedure testns.bar() language sql -as $procedure$ -select 1 -$procedure$; +as 'select 1'; select has_function_privilege('regress_priv_user2', 'testns.foo()', 'EXECUTE'); @@ -2718,28 +2387,24 @@ select has_function_privilege('regress_priv_user2', 'testns.agg1(int)', 'EXECUTE select has_function_privilege('regress_priv_user2', 'testns.bar()', 'EXECUTE'); -alter default privileges in schema testns grant EXECUTE on functions to public; +alter default privileges in schema testns grant execute on functions to public; drop function testns.foo(); create function testns.foo() returns int language sql -as $function$ -select 1 -$function$; +as 'select 1'; drop aggregate testns.agg1(int); -create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int); +create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int4); drop procedure testns.bar(); create procedure testns.bar() language sql -as $procedure$ -select 1 -$procedure$; +as 'select 1'; select has_function_privilege('regress_priv_user2', 'testns.foo()', 'EXECUTE'); @@ -2753,13 +2418,13 @@ drop aggregate testns.agg1(int); drop procedure testns.bar(); -alter default privileges for role regress_priv_user1 revoke USAGE on types from public; +alter default privileges for role regress_priv_user1 revoke usage on types from public; create domain testns.priv_testdomain1 as int; select has_type_privilege('regress_priv_user2', 'testns.priv_testdomain1', 'USAGE'); -alter default privileges in schema testns grant USAGE on types to public; +alter default privileges in schema testns grant usage on types to public; drop domain testns.priv_testdomain1; @@ -2772,12 +2437,9 @@ drop domain testns.priv_testdomain1; reset role; select - COUNT(*) + count(*) from - pg_default_acl as d - left outer join - pg_namespace as n - on defaclnamespace = n.oid + pg_default_acl as d left outer join pg_namespace as n on defaclnamespace = n.oid where nspname = 'testns'; @@ -2794,14 +2456,11 @@ drop schema testns5 cascade; select d.* from - pg_default_acl as d - left outer join - pg_namespace as n - on defaclnamespace = n.oid + pg_default_acl as d left outer join pg_namespace as n on defaclnamespace = n.oid where nspname is null and defaclnamespace <> 0; -create schema "testns"; +create schema testns; create table testns.t1 (f1 int); @@ -2824,17 +2483,13 @@ select has_table_privilege('regress_priv_user1', 'testns.t2', 'SELECT'); create function testns.priv_testfunc(int) returns int language sql -as $function$ -select 3 * $1; -$function$; +as 'select 3 * $1;'; -create aggregate testns.priv_testagg (int) (sfunc = int4pl, stype = int); +create aggregate testns.priv_testagg (int) (sfunc = int4pl, stype = int4); create procedure testns.priv_testproc(int) language sql -as $procedure$ -select 3 -$procedure$; +as 'select 3'; select has_function_privilege('regress_priv_user1', 'testns.priv_testfunc(int)', 'EXECUTE'); @@ -2870,7 +2525,7 @@ create role regress_schemauser2 superuser login; set role to regress_schemauser1; -create schema "testns"; +create schema testns; select nspname, @@ -2879,8 +2534,7 @@ from pg_namespace, pg_roles where - pg_namespace.nspname = 'testns' and - pg_namespace.nspowner = pg_roles.oid; + pg_namespace.nspname = 'testns' and pg_namespace.nspowner = pg_roles.oid; alter schema testns owner to regress_schemauser2; @@ -2893,8 +2547,7 @@ from pg_namespace, pg_roles where - pg_namespace.nspname = 'testns' and - pg_namespace.nspowner = pg_roles.oid; + pg_namespace.nspname = 'testns' and pg_namespace.nspowner = pg_roles.oid; set role to regress_schemauser_renamed; @@ -2908,29 +2561,29 @@ set role to regress_priv_user1; create table dep_priv_test (a int); -grant SELECT on table dep_priv_test to regress_priv_user2 with grant option; +grant select on table dep_priv_test to regress_priv_user2 with grant option; -grant SELECT on table dep_priv_test to regress_priv_user3 with grant option; +grant select on table dep_priv_test to regress_priv_user3 with grant option; set role to regress_priv_user2; -grant SELECT on table dep_priv_test to regress_priv_user4 with grant option; +grant select on table dep_priv_test to regress_priv_user4 with grant option; set role to regress_priv_user3; -grant SELECT on table dep_priv_test to regress_priv_user4 with grant option; +grant select on table dep_priv_test to regress_priv_user4 with grant option; set role to regress_priv_user4; -grant SELECT on table dep_priv_test to regress_priv_user5; +grant select on table dep_priv_test to regress_priv_user5; set role to regress_priv_user2; -revoke SELECT on table dep_priv_test from regress_priv_user4 cascade; +revoke select on table dep_priv_test from regress_priv_user4 cascade; set role to regress_priv_user3; -revoke SELECT on table dep_priv_test from regress_priv_user4 cascade; +revoke select on table dep_priv_test from regress_priv_user4 cascade; set role to regress_priv_user1; @@ -2980,7 +2633,7 @@ drop role regress_priv_group1; drop role regress_priv_group2; -revoke USAGE on language sql from regress_priv_user1; +revoke usage on language sql from regress_priv_user1; drop owned by regress_priv_user1; @@ -3000,159 +2653,159 @@ drop role regress_priv_user7; drop role regress_priv_user8; -alter default privileges for role pg_signal_backend revoke USAGE on types from pg_signal_backend; +alter default privileges for role pg_signal_backend revoke usage on types from pg_signal_backend; alter default privileges for role pg_read_all_settings -revoke USAGE on types from pg_read_all_settings; +revoke usage on types from pg_read_all_settings; create user regress_locktable_user; create table lock_table (a int); -grant SELECT on table lock_table to regress_locktable_user; +grant select on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; commit; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; rollback; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; rollback; -revoke SELECT on table lock_table from regress_locktable_user; +revoke select on table lock_table from regress_locktable_user; -grant INSERT on table lock_table to regress_locktable_user; +grant insert on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; rollback; -revoke INSERT on table lock_table from regress_locktable_user; +revoke insert on table lock_table from regress_locktable_user; -grant UPDATE on table lock_table to regress_locktable_user; +grant update on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; commit; -revoke UPDATE on table lock_table from regress_locktable_user; +revoke update on table lock_table from regress_locktable_user; -grant DELETE on table lock_table to regress_locktable_user; +grant delete on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; commit; -revoke DELETE on table lock_table from regress_locktable_user; +revoke delete on table lock_table from regress_locktable_user; -grant TRUNCATE on table lock_table to regress_locktable_user; +grant truncate on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; commit; -revoke TRUNCATE on table lock_table from regress_locktable_user; +revoke truncate on table lock_table from regress_locktable_user; -grant MAINTAIN on table lock_table to regress_locktable_user; +grant maintain on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; commit; -revoke MAINTAIN on table lock_table from regress_locktable_user; +revoke maintain on table lock_table from regress_locktable_user; drop table lock_table; @@ -3170,7 +2823,7 @@ select has_table_privilege('regress_readallstats', 'pg_shmem_allocations_numa', select has_table_privilege('regress_readallstats', 'pg_dsm_registry_allocations', 'SELECT'); -grant PG_READ_ALL_STATS to regress_readallstats; +grant pg_read_all_stats to regress_readallstats; select has_table_privilege('regress_readallstats', 'pg_aios', 'SELECT'); @@ -3184,11 +2837,11 @@ select has_table_privilege('regress_readallstats', 'pg_dsm_registry_allocations' set role to regress_readallstats; -select COUNT(*) >= 0 as ok from pg_aios; +select count(*) >= 0 as ok from pg_aios; -select COUNT(*) >= 0 as ok from pg_backend_memory_contexts; +select count(*) >= 0 as ok from pg_backend_memory_contexts; -select COUNT(*) >= 0 as ok from pg_shmem_allocations; +select count(*) >= 0 as ok from pg_shmem_allocations; reset role; @@ -3202,20 +2855,17 @@ create role regress_group_indirect_manager; create role regress_group_member; -grant REGRESS_GROUP to regress_group_direct_manager with INHERIT false, ADMIN true; +grant regress_group to regress_group_direct_manager with inherit false, admin true; -grant REGRESS_GROUP_DIRECT_MANAGER to regress_group_indirect_manager; +grant regress_group_direct_manager to regress_group_indirect_manager; set session authorization regress_group_direct_manager; -grant REGRESS_GROUP to regress_group_member; +grant regress_group to regress_group_member; select cast(cast(member as regrole) as text), - case - when grantor = 10 then 'BOOTSTRAP SUPERUSER' - else cast(cast(grantor as regrole) as text) - end + case when grantor = 10 then 'BOOTSTRAP SUPERUSER' else cast(cast(grantor as regrole) as text) end from pg_auth_members where @@ -3223,18 +2873,15 @@ where order by 1, 2; -revoke REGRESS_GROUP from regress_group_member restrict; +revoke regress_group from regress_group_member restrict; set session authorization regress_group_indirect_manager; -grant REGRESS_GROUP to regress_group_member; +grant regress_group to regress_group_member; select cast(cast(member as regrole) as text), - case - when grantor = 10 then 'BOOTSTRAP SUPERUSER' - else cast(cast(grantor as regrole) as text) - end + case when grantor = 10 then 'BOOTSTRAP SUPERUSER' else cast(cast(grantor as regrole) as text) end from pg_auth_members where @@ -3242,7 +2889,7 @@ where order by 1, 2; -revoke REGRESS_GROUP from regress_group_member restrict; +revoke regress_group from regress_group_member restrict; reset session_authorization; @@ -3260,13 +2907,13 @@ create role regress_roleoption_donor; create role regress_roleoption_recipient; -create schema "regress_roleoption"; +create schema regress_roleoption; -grant CREATE, USAGE on schema regress_roleoption to public; +grant create, usage on schema regress_roleoption to public; -grant REGRESS_ROLEOPTION_DONOR to regress_roleoption_protagonist with INHERIT true, SET false; +grant regress_roleoption_donor to regress_roleoption_protagonist with inherit true, set false; -grant REGRESS_ROLEOPTION_RECIPIENT to regress_roleoption_protagonist with INHERIT false, SET true; +grant regress_roleoption_recipient to regress_roleoption_protagonist with inherit false, set true; set session authorization regress_roleoption_protagonist; @@ -3324,13 +2971,13 @@ create table maintain_test (a int); create index on maintain_test using btree (a); -grant MAINTAIN on table maintain_test to regress_maintain; +grant maintain on table maintain_test to regress_maintain; create materialized view refresh_test as select 1; -grant MAINTAIN on table refresh_test to regress_maintain; +grant maintain on table refresh_test to regress_maintain; -create schema "reindex_test"; +create schema reindex_test; set role to regress_no_maintain; @@ -3338,7 +2985,7 @@ vacuum maintain_test; analyze maintain_test; -vacuum (ANALYZE) maintain_test; +vacuum (analyze) maintain_test; cluster maintain_test using maintain_test_a_idx; @@ -3358,7 +3005,7 @@ vacuum maintain_test; analyze maintain_test; -vacuum (ANALYZE) maintain_test; +vacuum (analyze) maintain_test; cluster maintain_test using maintain_test_a_idx; @@ -3378,7 +3025,7 @@ vacuum maintain_test; analyze maintain_test; -vacuum (ANALYZE) maintain_test; +vacuum (analyze) maintain_test; cluster maintain_test using maintain_test_a_idx; @@ -3416,17 +3063,17 @@ create table grantor_test2 (); create table grantor_test3 (); -grant SELECT on table grantor_test2 to regress_grantor1 with grant option; +grant select on table grantor_test2 to regress_grantor1 with grant option; -grant SELECT, UPDATE on table grantor_test3 to regress_grantor2 with grant option; +grant select, update on table grantor_test3 to regress_grantor2 with grant option; set role to regress_grantor1; -grant SELECT, UPDATE on table grantor_test1 to regress_grantor3; +grant select, update on table grantor_test1 to regress_grantor3; -grant SELECT, UPDATE on table grantor_test2 to regress_grantor3; +grant select, update on table grantor_test2 to regress_grantor3; -grant SELECT, UPDATE on table grantor_test3 to regress_grantor3; +grant select, update on table grantor_test3 to regress_grantor3; reset role; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_80.snap index ebfd9388d..cb2f2b869 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_80.snap @@ -56,21 +56,21 @@ create user regress_priv_user10; create role regress_priv_role; -grant REGRESS_PRIV_USER1 to regress_priv_user2 with ADMIN true; +grant regress_priv_user1 to regress_priv_user2 with admin true; -grant REGRESS_PRIV_USER1 +grant regress_priv_user1 to regress_priv_user3 -with ADMIN true +with admin true granted by regress_priv_user2; -grant REGRESS_PRIV_USER1 +grant regress_priv_user1 to regress_priv_user2 -with ADMIN true +with admin true granted by regress_priv_user3; -revoke ADMIN option for REGRESS_PRIV_USER1 from regress_priv_user2 restrict; +revoke admin option for regress_priv_user1 from regress_priv_user2 restrict; -revoke REGRESS_PRIV_USER1 from regress_priv_user2 restrict; +revoke regress_priv_user1 from regress_priv_user2 restrict; select cast(member as regrole), @@ -78,12 +78,11 @@ select from pg_auth_members where - roleid = - cast('regress_priv_user1' as regrole); + roleid = cast('regress_priv_user1' as regrole); begin; -revoke ADMIN option for REGRESS_PRIV_USER1 from regress_priv_user2 cascade; +revoke admin option for regress_priv_user1 from regress_priv_user2 cascade; select cast(member as regrole), @@ -91,12 +90,11 @@ select from pg_auth_members where - roleid = - cast('regress_priv_user1' as regrole); + roleid = cast('regress_priv_user1' as regrole); rollback; -revoke REGRESS_PRIV_USER1 from regress_priv_user2 cascade; +revoke regress_priv_user1 from regress_priv_user2 cascade; select cast(member as regrole), @@ -104,36 +102,33 @@ select from pg_auth_members where - roleid = - cast('regress_priv_user1' as regrole); + roleid = cast('regress_priv_user1' as regrole); -grant REGRESS_PRIV_USER1 to regress_priv_user2 with ADMIN true; +grant regress_priv_user1 to regress_priv_user2 with admin true; -grant REGRESS_PRIV_USER2 to regress_priv_user3; +grant regress_priv_user2 to regress_priv_user3; set role to regress_priv_user3; -grant REGRESS_PRIV_USER1 to regress_priv_user4; +grant regress_priv_user1 to regress_priv_user4; select cast(grantor as regrole) from pg_auth_members where - roleid = - cast('regress_priv_user1' as regrole) and - member = - cast('regress_priv_user4' as regrole); + roleid = cast('regress_priv_user1' as regrole) and + member = cast('regress_priv_user4' as regrole); reset role; -revoke REGRESS_PRIV_USER2 from regress_priv_user3 restrict; +revoke regress_priv_user2 from regress_priv_user3 restrict; -revoke REGRESS_PRIV_USER1 from regress_priv_user2 cascade; +revoke regress_priv_user1 from regress_priv_user2 cascade; -grant REGRESS_PRIV_USER1 to regress_priv_user2 with ADMIN true; +grant regress_priv_user1 to regress_priv_user2 with admin true; -grant REGRESS_PRIV_USER1 to regress_priv_user3 granted by regress_priv_user2; +grant regress_priv_user1 to regress_priv_user3 granted by regress_priv_user2; drop role regress_priv_user2; @@ -145,9 +140,9 @@ drop owned by regress_priv_user2; drop role regress_priv_user2; -grant REGRESS_PRIV_USER1 to regress_priv_user3 with ADMIN true; +grant regress_priv_user1 to regress_priv_user3 with admin true; -grant REGRESS_PRIV_USER1 to regress_priv_user4 granted by regress_priv_user3; +grant regress_priv_user1 to regress_priv_user4 granted by regress_priv_user3; drop role regress_priv_user3; @@ -155,9 +150,9 @@ drop role regress_priv_user4; drop role regress_priv_user3; -grant REGRESS_PRIV_USER1 to regress_priv_user5 with ADMIN true; +grant regress_priv_user1 to regress_priv_user5 with admin true; -grant REGRESS_PRIV_USER1 to regress_priv_user6 granted by regress_priv_user5; +grant regress_priv_user1 to regress_priv_user6 granted by regress_priv_user5; drop role regress_priv_user5; @@ -173,38 +168,38 @@ create user regress_priv_user4; create user regress_priv_user5; -grant PG_READ_ALL_DATA to regress_priv_user6; +grant pg_read_all_data to regress_priv_user6; -grant PG_WRITE_ALL_DATA to regress_priv_user7; +grant pg_write_all_data to regress_priv_user7; -grant PG_READ_ALL_SETTINGS to regress_priv_user8 with ADMIN true; +grant pg_read_all_settings to regress_priv_user8 with admin true; -grant REGRESS_PRIV_USER9 to regress_priv_user8; +grant regress_priv_user9 to regress_priv_user8; set session authorization regress_priv_user8; -grant PG_READ_ALL_SETTINGS to regress_priv_user9 with ADMIN true; +grant pg_read_all_settings to regress_priv_user9 with admin true; set session authorization regress_priv_user9; -grant PG_READ_ALL_SETTINGS to regress_priv_user10; +grant pg_read_all_settings to regress_priv_user10; set session authorization regress_priv_user8; -revoke PG_READ_ALL_SETTINGS +revoke pg_read_all_settings from regress_priv_user10 granted by regress_priv_user9 restrict; -revoke ADMIN option for PG_READ_ALL_SETTINGS from regress_priv_user9 restrict; +revoke admin option for pg_read_all_settings from regress_priv_user9 restrict; -revoke PG_READ_ALL_SETTINGS from regress_priv_user9 restrict; +revoke pg_read_all_settings from regress_priv_user9 restrict; reset session_authorization; -revoke REGRESS_PRIV_USER9 from regress_priv_user8 restrict; +revoke regress_priv_user9 from regress_priv_user8 restrict; -revoke ADMIN option for PG_READ_ALL_SETTINGS from regress_priv_user8 restrict; +revoke admin option for pg_read_all_settings from regress_priv_user8 restrict; set session authorization regress_priv_user8; @@ -214,9 +209,9 @@ reset role; reset session_authorization; -revoke SET option for PG_READ_ALL_SETTINGS from regress_priv_user8 restrict; +revoke set option for pg_read_all_settings from regress_priv_user8 restrict; -grant PG_READ_ALL_STATS to regress_priv_user8 with SET false; +grant pg_read_all_stats to regress_priv_user8 with set false; set session authorization regress_priv_user8; @@ -228,7 +223,7 @@ reset role; reset session_authorization; -grant REGRESS_PRIV_USER9 to regress_priv_user8; +grant regress_priv_user9 to regress_priv_user8; set session authorization regress_priv_user8; @@ -306,7 +301,7 @@ select reset debug_parallel_query; -revoke PG_READ_ALL_SETTINGS from regress_priv_user8 restrict; +revoke pg_read_all_settings from regress_priv_user8 restrict; drop role regress_priv_user10; @@ -322,7 +317,7 @@ create group regress_priv_group2 alter group regress_priv_group1 add user regress_priv_user4; -grant REGRESS_PRIV_GROUP2 to regress_priv_user2 granted by regress_priv_user1; +grant regress_priv_group2 to regress_priv_user2 granted by regress_priv_user1; set session authorization regress_priv_user3; @@ -344,47 +339,45 @@ reset session_authorization; alter group regress_priv_group2 drop user regress_priv_user2; -revoke ADMIN option for REGRESS_PRIV_GROUP2 from regress_priv_user1 restrict; +revoke admin option for regress_priv_group2 from regress_priv_user1 restrict; -grant REGRESS_PRIV_GROUP2 to regress_priv_user4 with ADMIN true; +grant regress_priv_group2 to regress_priv_user4 with admin true; create function leak(int, int) returns boolean language internal immutable strict -as $function$ -int4lt -$function$; +as 'int4lt'; alter function leak(int, int) owner to regress_priv_user1; -grant REGRESS_PRIV_ROLE +grant regress_priv_role to regress_priv_user1 -with ADMIN true +with admin true granted by regress_priv_role; -grant REGRESS_PRIV_ROLE +grant regress_priv_role to regress_priv_user1 -with ADMIN true +with admin true granted by current_role; -revoke ADMIN option for REGRESS_PRIV_ROLE +revoke admin option for regress_priv_role from regress_priv_user1 granted by foo restrict; -revoke ADMIN option for REGRESS_PRIV_ROLE +revoke admin option for regress_priv_role from regress_priv_user1 granted by regress_priv_user2 restrict; -revoke ADMIN option for REGRESS_PRIV_ROLE +revoke admin option for regress_priv_role from regress_priv_user1 granted by current_user restrict; -revoke REGRESS_PRIV_ROLE +revoke regress_priv_role from regress_priv_user1 granted by current_role restrict; @@ -412,7 +405,7 @@ truncate atest1; begin; -lock table atest1 in ACCESS EXCLUSIVE mode; +lock table atest1 in access exclusive mode; commit; @@ -422,7 +415,7 @@ select * from atest1; grant all on table atest1 to regress_priv_user2; -grant SELECT on table atest1 to regress_priv_user3, regress_priv_user4; +grant select on table atest1 to regress_priv_user3, regress_priv_user4; select * from atest1; @@ -438,13 +431,13 @@ select 0 ); -grant SELECT on table atest2 to regress_priv_user2; +grant select on table atest2 to regress_priv_user2; -grant UPDATE on table atest2 to regress_priv_user3; +grant update on table atest2 to regress_priv_user3; -grant INSERT on table atest2 to regress_priv_user4 granted by current_user; +grant insert on table atest2 to regress_priv_user4 granted by current_user; -grant TRUNCATE on table atest2 to regress_priv_user5 granted by current_role; +grant truncate on table atest2 to regress_priv_user5 granted by current_role; select unnest( @@ -459,7 +452,7 @@ select pg_get_acl(cast('pg_class' as regclass), 0, 0); select pg_get_acl(0, 0, 0); -grant TRUNCATE +grant truncate on table atest2 to regress_priv_user4 granted by regress_priv_user5; @@ -492,7 +485,7 @@ truncate atest2; begin; -lock table atest2 in ACCESS EXCLUSIVE mode; +lock table atest2 in access exclusive mode; commit; @@ -558,7 +551,7 @@ truncate atest2; begin; -lock table atest2 in ACCESS EXCLUSIVE mode; +lock table atest2 in access exclusive mode; commit; @@ -574,11 +567,7 @@ set session authorization regress_priv_user1; create table atest12 as - select - x as a, - 10001 - x as b - from - generate_series(1, 10000) as x; + select x as a, 10001 - x as b from generate_series(1, 10000) as x; create index on atest12 using btree (a); @@ -589,14 +578,16 @@ alter table atest12 set default_statistics_target = 10000; -vacuum (ANALYZE) atest12; +vacuum (analyze) atest12; reset default_statistics_target; -create operator <<< (PROCEDURE = leak, -LEFTARG = int, -RIGHTARG = int, -RESTRICT = scalarltsel); +create operator <<< ( + procedure = leak, + leftarg = int, + rightarg = int, + restrict = scalarltsel +); create view atest12v as select * from atest12 where b <<< 5; @@ -617,14 +608,14 @@ create function leak2(int, int) returns boolean language plpgsql immutable -as $function$ -begin raise notice 'leak % %', $1, $2; return $1 > $2; end -$function$; +as $$begin raise notice 'leak % %', $1, $2; return $1 > $2; end$$; -create operator >>> (PROCEDURE = leak2, -LEFTARG = int, -RIGHTARG = int, -RESTRICT = scalargtsel); +create operator >>> ( + procedure = leak2, + leftarg = int, + rightarg = int, + restrict = scalargtsel +); select * from atest12 where a >>> 0; @@ -634,9 +625,9 @@ select * from atest12sbv where a >>> 0; set session authorization regress_priv_user1; -grant SELECT on table atest12v to public; +grant select on table atest12v to public; -grant SELECT on table atest12sbv to public; +grant select on table atest12sbv to public; set session authorization regress_priv_user2; @@ -656,7 +647,7 @@ where set session authorization regress_priv_user1; -grant SELECT (a, b) on table atest12 to public; +grant select (a, b) on table atest12 to public; set session authorization regress_priv_user2; @@ -674,7 +665,7 @@ create table atest3 ( three int ); -grant DELETE on table atest3 to regress_priv_group2; +grant delete on table atest3 to regress_priv_group2; set session authorization regress_priv_user1; @@ -698,7 +689,7 @@ rollback to savepoint s1; reset session_authorization; -grant REGRESS_PRIV_GROUP2 to regress_priv_user1 with INHERIT false; +grant regress_priv_group2 to regress_priv_user1 with inherit false; set session authorization regress_priv_user1; @@ -708,7 +699,7 @@ rollback to savepoint s1; reset session_authorization; -revoke INHERIT option for REGRESS_PRIV_GROUP2 from regress_priv_user1 restrict; +revoke inherit option for regress_priv_group2 from regress_priv_user1 restrict; set session authorization regress_priv_user1; @@ -734,9 +725,9 @@ select * from atestv1; select * from atestv2; -grant SELECT on table atestv1, atestv3 to regress_priv_user4; +grant select on table atestv1, atestv3 to regress_priv_user4; -grant SELECT on table atestv2 to regress_priv_user2; +grant select on table atestv2 to regress_priv_user2; set session authorization regress_priv_user4; @@ -752,17 +743,9 @@ select * from ( - (select - a.q1 as x - from - int8_tbl as a - offset 0) + (select a.q1 as x from int8_tbl as a offset 0) union all - (select - b.q2 as x - from - int8_tbl as b - offset 0) + (select b.q2 as x from int8_tbl as b offset 0) ) as ss where @@ -774,21 +757,9 @@ select * from ( - select - a.q1 as x, - random() - from - int8_tbl as a - where - q1 > 0 + select a.q1 as x, random() from int8_tbl as a where q1 > 0 union all - select - b.q2 as x, - random() - from - int8_tbl as b - where - q2 > 0 + select b.q2 as x, random() from int8_tbl as b where q2 > 0 ) as ss where @@ -801,7 +772,7 @@ as select * from atestv3; select * from atestv4; -grant SELECT on table atestv4 to regress_priv_user2; +grant select on table atestv4 to regress_priv_user2; set session authorization regress_priv_user2; @@ -828,9 +799,9 @@ create table atest6 ( blue int ); -grant SELECT (one), -INSERT (two), -UPDATE (three) +grant select (one), +insert (two), +update (three) on table atest5 to regress_priv_user4; @@ -892,123 +863,81 @@ copy atest5 (one, two) to stdout; select 1 from atest5; -select 1 from atest5 as a inner join atest5 as b using ("one"); +select 1 from atest5 as a inner join atest5 as b using (one); -select 1 from atest5 as a inner join atest5 as b using ("two"); +select 1 from atest5 as a inner join atest5 as b using (two); select 1 from atest5 as a natural join atest5 as b; -select * from (atest5 as a inner join atest5 as b using ("one")) as "j"; +select * from (atest5 as a inner join atest5 as b using (one)) as j; -select j.* from (atest5 as a inner join atest5 as b using ("one")) as "j"; +select j.* from (atest5 as a inner join atest5 as b using (one)) as j; -select - j.* is null -from - (atest5 as a - inner join - atest5 as b - using ("one")) as "j"; +select j.* is null from (atest5 as a inner join atest5 as b using (one)) as j; select one from - (atest5 as a - inner join - atest5 as b (one, x, y, z) - using ("one")) as "j"; + (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; select j.one from - (atest5 as a - inner join - atest5 as b (one, x, y, z) - using ("one")) as "j"; + (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; select two from - (atest5 as a - inner join - atest5 as b (one, x, y, z) - using ("one")) as "j"; + (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; select j.two from - (atest5 as a - inner join - atest5 as b (one, x, y, z) - using ("one")) as "j"; + (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; select y from - (atest5 as a - inner join - atest5 as b (one, x, y, z) - using ("one")) as "j"; + (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; select j.y from - (atest5 as a - inner join - atest5 as b (one, x, y, z) - using ("one")) as "j"; + (atest5 as a inner join atest5 as b (one, x, y, z) using (one)) as j; -select * from atest5 as a inner join atest5 as b using ("one"); +select * from atest5 as a inner join atest5 as b using (one); -select a.* from atest5 as a inner join atest5 as b using ("one"); +select a.* from atest5 as a inner join atest5 as b using (one); -select a.* is null from atest5 as a inner join atest5 as b using ("one"); +select a.* is null from atest5 as a inner join atest5 as b using (one); -select two from atest5 as a inner join atest5 as b (one, x, y, z) using ("one"); +select two from atest5 as a inner join atest5 as b (one, x, y, z) using (one); -select - a.two -from - atest5 as a - inner join - atest5 as b (one, x, y, z) - using ("one"); +select a.two from atest5 as a inner join atest5 as b (one, x, y, z) using (one); -select y from atest5 as a inner join atest5 as b (one, x, y, z) using ("one"); +select y from atest5 as a inner join atest5 as b (one, x, y, z) using (one); -select b.y from atest5 as a inner join atest5 as b (one, x, y, z) using ("one"); +select b.y from atest5 as a inner join atest5 as b (one, x, y, z) using (one); select y from - atest5 as a - left outer join - atest5 as b (one, x, y, z) - using ("one"); + atest5 as a left outer join atest5 as b (one, x, y, z) using (one); select b.y from - atest5 as a - left outer join - atest5 as b (one, x, y, z) - using ("one"); + atest5 as a left outer join atest5 as b (one, x, y, z) using (one); select y from - atest5 as a - full outer join - atest5 as b (one, x, y, z) - using ("one"); + atest5 as a full outer join atest5 as b (one, x, y, z) using (one); select b.y from - atest5 as a - full outer join - atest5 as b (one, x, y, z) - using ("one"); + atest5 as a full outer join atest5 as b (one, x, y, z) using (one); select 1 from atest5 where two = 2; @@ -1022,25 +951,19 @@ select atest1.*, atest5.one from - atest1 - inner join - atest5 - on atest1.a = atest5.two; + atest1 inner join atest5 on atest1.a = atest5.two; select atest1.*, atest5.one from - atest1 - inner join - atest5 - on atest1.a = atest5.one; + atest1 inner join atest5 on atest1.a = atest5.one; select one, two from atest5; set session authorization regress_priv_user1; -grant SELECT (one, two) on table atest6 to regress_priv_user4; +grant select (one, two) on table atest6 to regress_priv_user4; set session authorization regress_priv_user4; @@ -1048,7 +971,7 @@ select one, two from atest5 natural join atest6; set session authorization regress_priv_user1; -grant SELECT (two) on table atest5 to regress_priv_user4; +grant select (two) on table atest5 to regress_priv_user4; set session authorization regress_priv_user4; @@ -1070,53 +993,33 @@ insert into atest5 (two) values (6) on conflict (two) do update set three = 10; insert into atest5 (two) values (6) -on conflict -(two) -do -update -set three = 10 +on conflict (two) do update set three = 10 returning atest5.three; insert into atest5 (two) values (6) -on conflict -(two) -do -update -set three = 10 +on conflict (two) do update set three = 10 returning atest5.one; insert into atest5 (two) values (6) -on conflict -(two) -do -update -set three = excluded.one; +on conflict (two) do update set three = excluded.one; insert into atest5 (two) values (6) -on conflict -(two) -do -update -set three = excluded.three; +on conflict (two) do update set three = excluded.three; insert into atest5 (two) values (6) on conflict (two) do update set one = 8; insert into atest5 (three) values (4) -on conflict -(two) -do -update -set three = 10; +on conflict (two) do update set three = 10; insert into atest5 (four) values (4); set session authorization regress_priv_user1; -grant INSERT (four) on table atest5 to regress_priv_user4; +grant insert (four) on table atest5 to regress_priv_user4; set session authorization regress_priv_user4; @@ -1124,17 +1027,13 @@ insert into atest5 (four) values (4) on conflict (four) do update set three = 3; insert into atest5 (four) values (4) -on conflict -on constraint atest5_four_key -do -update -set three = 3; +on conflict on constraint atest5_four_key do update set three = 3; insert into atest5 (four) values (4); set session authorization regress_priv_user1; -grant SELECT (four) on table atest5 to regress_priv_user4; +grant select (four) on table atest5 to regress_priv_user4; set session authorization regress_priv_user4; @@ -1142,17 +1041,13 @@ insert into atest5 (four) values (4) on conflict (four) do update set three = 3; insert into atest5 (four) values (4) -on conflict -on constraint atest5_four_key -do -update -set three = 3; +on conflict on constraint atest5_four_key do update set three = 3; set session authorization regress_priv_user1; revoke all (one) on table atest5 from regress_priv_user4; -grant SELECT (one, two, blue) on table atest6 to regress_priv_user4; +grant select (one, two, blue) on table atest6 to regress_priv_user4; set session authorization regress_priv_user4; @@ -1180,13 +1075,13 @@ insert into mtarget values (1, 'init1'), (2, 'init2'); insert into msource values (1, 'source1'), (2, 'source2'), (3, 'source3'); -grant SELECT (a) on table msource to regress_priv_user4; +grant select (a) on table msource to regress_priv_user4; -grant SELECT (a) on table mtarget to regress_priv_user4; +grant select (a) on table mtarget to regress_priv_user4; -grant INSERT (a, b) on table mtarget to regress_priv_user4; +grant insert (a, b) on table mtarget to regress_priv_user4; -grant UPDATE (b) on table mtarget to regress_priv_user4; +grant update (b) on table mtarget to regress_priv_user4; set session authorization regress_priv_user4; @@ -1196,7 +1091,7 @@ rollback; set session authorization regress_priv_user1; -grant SELECT (b) on table msource to regress_priv_user4; +grant select (b) on table msource to regress_priv_user4; set session authorization regress_priv_user4; @@ -1210,7 +1105,7 @@ rollback; set session authorization regress_priv_user1; -grant DELETE on table mtarget to regress_priv_user4; +grant delete on table mtarget to regress_priv_user4; begin; @@ -1225,11 +1120,11 @@ create table t1 ( primary key (c1, c2) ); -grant SELECT (c1) on table t1 to regress_priv_user2; +grant select (c1) on table t1 to regress_priv_user2; -grant INSERT (c1, c2, c3) on table t1 to regress_priv_user2; +grant insert (c1, c2, c3) on table t1 to regress_priv_user2; -grant UPDATE (c1, c2, c3) on table t1 to regress_priv_user2; +grant update (c1, c2, c3) on table t1 to regress_priv_user2; insert into t1 values (1, 1, 1); @@ -1266,7 +1161,7 @@ create table errtst ( secret1 text, secret2 text ) -partition by LIST(a); +partition by list(a); create table errtst_part_1 ( secret2 text, @@ -1292,21 +1187,14 @@ alter table errtst attach partition errtst_part_2 for values in ('aaaa'); -grant SELECT (a, b, c) on table errtst to regress_priv_user2; +grant select (a, b, c) on table errtst to regress_priv_user2; -grant UPDATE (a, b, c) on table errtst to regress_priv_user2; +grant update (a, b, c) on table errtst to regress_priv_user2; -grant INSERT (a, b, c) on table errtst to regress_priv_user2; +grant insert (a, b, c) on table errtst to regress_priv_user2; insert into errtst_part_1 (a, b, c, secret1, secret2) -values - ( - 'aaa', - 'bbb', - 'ccc', - 'the body', - 'is in the attic' - ); +values ('aaa', 'bbb', 'ccc', 'the body', 'is in the attic'); set session authorization regress_priv_user2; @@ -1329,13 +1217,13 @@ set session authorization regress_priv_user1; alter table atest6 add column three int; -grant DELETE on table atest5 to regress_priv_user3; +grant delete on table atest5 to regress_priv_user3; -grant SELECT (two) on table atest5 to regress_priv_user3; +grant select (two) on table atest5 to regress_priv_user3; revoke all (one) on table atest5 from regress_priv_user3; -grant SELECT (one) on table atest5 to regress_priv_user4; +grant select (one) on table atest5 to regress_priv_user4; set session authorization regress_priv_user4; @@ -1359,7 +1247,7 @@ set session authorization regress_priv_user1; alter table atest6 drop column two; -revoke SELECT (one, blue) on table atest6 from regress_priv_user4; +revoke select (one, blue) on table atest6 from regress_priv_user4; set session authorization regress_priv_user4; @@ -1386,12 +1274,11 @@ create table atestp2 ( ); create table atestc (fz int) -inherits (atestp1, -atestp2); +inherits (atestp1, atestp2); -grant SELECT (fx, fy, tableoid) on table atestp2 to regress_priv_user2; +grant select (fx, fy, tableoid) on table atestp2 to regress_priv_user2; -grant SELECT (fx) on table atestc to regress_priv_user2; +grant select (fx) on table atestc to regress_priv_user2; set session authorization regress_priv_user2; @@ -1407,7 +1294,7 @@ select fy from atestc; set session authorization regress_priv_user1; -grant SELECT (fy, tableoid) on table atestc to regress_priv_user2; +grant select (fy, tableoid) on table atestc to regress_priv_user2; set session authorization regress_priv_user2; @@ -1445,47 +1332,41 @@ truncate atestc; begin; -lock table atestp1 in ACCESS EXCLUSIVE mode; +lock table atestp1 in access exclusive mode; commit; begin; -lock table atestc in ACCESS EXCLUSIVE mode; +lock table atestc in access exclusive mode; commit; revoke all on language sql from public; -grant USAGE on language sql to regress_priv_user1; +grant usage on language sql to regress_priv_user1; -grant USAGE on language c to public; +grant usage on language c to public; set session authorization regress_priv_user1; -grant USAGE on language sql to regress_priv_user2; +grant usage on language sql to regress_priv_user2; create function priv_testfunc1(int) returns int language sql -as $function$ -select 2 * $1; -$function$; +as 'select 2 * $1;'; create function priv_testfunc2(int) returns int language sql -as $function$ -select 3 * $1; -$function$; +as 'select 3 * $1;'; -create aggregate priv_testagg1 (int) (sfunc = int4pl, stype = int); +create aggregate priv_testagg1 (int) (sfunc = int4pl, stype = int4); create procedure priv_testproc1(int) language sql -as $procedure$ -select $1; -$procedure$; +as 'select $1;'; revoke all on function priv_testfunc1(int), @@ -1493,7 +1374,7 @@ priv_testfunc2(int), priv_testagg1(int) from public; -grant EXECUTE +grant execute on function priv_testfunc1(int), priv_testfunc2(int), priv_testagg1(int) @@ -1503,13 +1384,13 @@ revoke all on function priv_testproc1(int) from public; revoke all on procedure priv_testproc1(int) from public; -grant EXECUTE on procedure priv_testproc1(int) to regress_priv_user2; +grant execute on procedure priv_testproc1(int) to regress_priv_user2; -grant USAGE on function priv_testfunc1(int) to regress_priv_user3; +grant usage on function priv_testfunc1(int) to regress_priv_user3; -grant USAGE on function priv_testagg1(int) to regress_priv_user3; +grant usage on function priv_testagg1(int) to regress_priv_user3; -grant USAGE on procedure priv_testproc1(int) to regress_priv_user3; +grant usage on procedure priv_testproc1(int) to regress_priv_user3; grant all on function priv_testfunc1(int) to regress_priv_user4; @@ -1523,11 +1404,9 @@ create function priv_testfunc4(boolean) returns text language sql security definer -as $function$ -select col1 from atest2 where col2 = $1; -$function$; +as 'select col1 from atest2 where col2 = $1;'; -grant EXECUTE on function priv_testfunc4(boolean) to regress_priv_user3; +grant execute on function priv_testfunc4(boolean) to regress_priv_user3; set session authorization regress_priv_user2; @@ -1536,9 +1415,7 @@ select priv_testfunc1(5), priv_testfunc2(5); create function priv_testfunc3(int) returns int language sql -as $function$ -select 2 * $1; -$function$; +as 'select 2 * $1;'; select priv_testagg1(x) from (values (1), (2), (3)) as _ (x); @@ -1576,35 +1453,35 @@ grant all on language sql to public; begin; -select cast(cast('{1}' as int[]) as bigint[]); +select cast(cast('{1}' as int4[]) as int8[]); revoke all on function int8(int) from public; -select cast(cast('{1}' as int[]) as bigint[]); +select cast(cast('{1}' as int4[]) as int8[]); set session authorization regress_priv_user4; -select cast(cast('{1}' as int[]) as bigint[]); +select cast(cast('{1}' as int4[]) as int8[]); rollback; create type priv_testtype1 as (a int, b text); -revoke USAGE on type priv_testtype1 from public; +revoke usage on type priv_testtype1 from public; -grant USAGE on type priv_testtype1 to regress_priv_user2; +grant usage on type priv_testtype1 to regress_priv_user2; -grant USAGE on type _priv_testtype1 to regress_priv_user2; +grant usage on type _priv_testtype1 to regress_priv_user2; -grant USAGE on domain priv_testtype1 to regress_priv_user2; +grant usage on domain priv_testtype1 to regress_priv_user2; create domain priv_testdomain1 as int; -revoke USAGE on domain priv_testdomain1 from public; +revoke usage on domain priv_testdomain1 from public; -grant USAGE on domain priv_testdomain1 to regress_priv_user2; +grant usage on domain priv_testdomain1 to regress_priv_user2; -grant USAGE on type priv_testdomain1 to regress_priv_user2; +grant usage on type priv_testdomain1 to regress_priv_user2; set session authorization regress_priv_user1; @@ -1622,9 +1499,7 @@ create domain priv_testdomain3a as int; create function castfunc(int) returns priv_testdomain3a language sql -as $function$ -SELECT $1::priv_testdomain3a -$function$; +as $$ SELECT $1::priv_testdomain3a $$; create cast (priv_testdomain1 as priv_testdomain3a) with function castfunc(int); @@ -1635,20 +1510,18 @@ drop domain priv_testdomain3a; create function priv_testfunc5a(a priv_testdomain1) returns int language sql -as $function$ -SELECT $1 -$function$; +as $$ SELECT $1 $$; create function priv_testfunc6a(b int) returns priv_testdomain1 language sql -as $function$ -SELECT $1::priv_testdomain1 -$function$; +as $$ SELECT $1::priv_testdomain1 $$; -create operator !+! (PROCEDURE = int4pl, -LEFTARG = priv_testdomain1, -RIGHTARG = priv_testdomain1); +create operator !+! ( + procedure = int4pl, + leftarg = priv_testdomain1, + rightarg = priv_testdomain1 +); create table test5a ( a int, @@ -1703,27 +1576,21 @@ create domain priv_testdomain3b as int; create function castfunc(int) returns priv_testdomain3b language sql -as $function$ -SELECT $1::priv_testdomain3b -$function$; +as $$ SELECT $1::priv_testdomain3b $$; create cast (priv_testdomain1 as priv_testdomain3b) with function castfunc(int); create function priv_testfunc5b(a priv_testdomain1) returns int language sql -as $function$ -SELECT $1 -$function$; +as $$ SELECT $1 $$; create function priv_testfunc6b(b int) returns priv_testdomain1 language sql -as $function$ -SELECT $1::priv_testdomain1 -$function$; +as $$ SELECT $1::priv_testdomain1 $$; -create operator !! (PROCEDURE = priv_testfunc5b, RIGHTARG = priv_testdomain1); +create operator !! (procedure = priv_testfunc5b, rightarg = priv_testdomain1); create table test5b ( a int, @@ -1768,9 +1635,9 @@ drop domain priv_testdomain2b; drop operator !! (none, priv_testdomain1); -drop function priv_testfunc5b(priv_testdomain1); +drop function priv_testfunc5b(a priv_testdomain1); -drop function priv_testfunc6b(int); +drop function priv_testfunc6b(b int); drop table test5b; @@ -1819,107 +1686,31 @@ select has_table_privilege(current_user, 'pg_authid', 'select'); select has_table_privilege(current_user, 'pg_authid', 'insert'); select - has_table_privilege( - t2.oid, - 'pg_authid', - 'update' - ) + has_table_privilege(t2.oid, 'pg_authid', 'update') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - t2.oid, - 'pg_authid', - 'delete' - ) + has_table_privilege(t2.oid, 'pg_authid', 'delete') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - current_user, - t1.oid, - 'references' - ) + has_table_privilege(current_user, t1.oid, 'references') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1; + (select oid from pg_class where relname = 'pg_authid') as t1; select - has_table_privilege( - t2.oid, - t1.oid, - 'select' - ) + has_table_privilege(t2.oid, t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'pg_authid') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - t2.oid, - t1.oid, - 'insert' - ) + has_table_privilege(t2.oid, t1.oid, 'insert') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'pg_authid') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege('pg_authid', 'update'); @@ -1930,28 +1721,12 @@ select has_table_privilege('pg_authid', 'truncate'); select has_table_privilege(t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1; + (select oid from pg_class where relname = 'pg_authid') as t1; select has_table_privilege(t1.oid, 'trigger') from - ( - select - oid - from - pg_class - where - relname = 'pg_authid' - ) - as t1; + (select oid from pg_class where relname = 'pg_authid') as t1; set session authorization regress_priv_user3; @@ -1960,107 +1735,31 @@ select has_table_privilege(current_user, 'pg_class', 'select'); select has_table_privilege(current_user, 'pg_class', 'insert'); select - has_table_privilege( - t2.oid, - 'pg_class', - 'update' - ) + has_table_privilege(t2.oid, 'pg_class', 'update') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - t2.oid, - 'pg_class', - 'delete' - ) + has_table_privilege(t2.oid, 'pg_class', 'delete') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - current_user, - t1.oid, - 'references' - ) + has_table_privilege(current_user, t1.oid, 'references') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1; + (select oid from pg_class where relname = 'pg_class') as t1; select - has_table_privilege( - t2.oid, - t1.oid, - 'select' - ) + has_table_privilege(t2.oid, t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'pg_class') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - t2.oid, - t1.oid, - 'insert' - ) + has_table_privilege(t2.oid, t1.oid, 'insert') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'pg_class') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege('pg_class', 'update'); @@ -2071,135 +1770,43 @@ select has_table_privilege('pg_class', 'truncate'); select has_table_privilege(t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1; + (select oid from pg_class where relname = 'pg_class') as t1; select has_table_privilege(t1.oid, 'trigger') from - ( - select - oid - from - pg_class - where - relname = 'pg_class' - ) - as t1; + (select oid from pg_class where relname = 'pg_class') as t1; select has_table_privilege(current_user, 'atest1', 'select'); select has_table_privilege(current_user, 'atest1', 'insert'); select - has_table_privilege( - t2.oid, - 'atest1', - 'update' - ) + has_table_privilege(t2.oid, 'atest1', 'update') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - t2.oid, - 'atest1', - 'delete' - ) + has_table_privilege(t2.oid, 'atest1', 'delete') from - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - current_user, - t1.oid, - 'references' - ) + has_table_privilege(current_user, t1.oid, 'references') from - ( - select - oid - from - pg_class - where - relname = 'atest1' - ) - as t1; + (select oid from pg_class where relname = 'atest1') as t1; select - has_table_privilege( - t2.oid, - t1.oid, - 'select' - ) + has_table_privilege(t2.oid, t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'atest1' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'atest1') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select - has_table_privilege( - t2.oid, - t1.oid, - 'insert' - ) + has_table_privilege(t2.oid, t1.oid, 'insert') from - ( - select - oid - from - pg_class - where - relname = 'atest1' - ) - as t1, - ( - select - oid - from - pg_roles - where - rolname = current_user - ) - as t2; + (select oid from pg_class where relname = 'atest1') as t1, + (select oid from pg_roles where rolname = current_user) as t2; select has_table_privilege('atest1', 'update'); @@ -2210,28 +1817,12 @@ select has_table_privilege('atest1', 'truncate'); select has_table_privilege(t1.oid, 'select') from - ( - select - oid - from - pg_class - where - relname = 'atest1' - ) - as t1; + (select oid from pg_class where relname = 'atest1') as t1; select has_table_privilege(t1.oid, 'trigger') from - ( - select - oid - from - pg_class - where - relname = 'atest1' - ) - as t1; + (select oid from pg_class where relname = 'atest1') as t1; select has_column_privilege('pg_authid', null, 'select'); @@ -2239,11 +1830,11 @@ select has_column_privilege('pg_authid', 'nosuchcol', 'select'); select has_column_privilege(9999, 'nosuchcol', 'select'); -select has_column_privilege(9999, cast(99 as smallint), 'select'); +select has_column_privilege(9999, cast(99 as int2), 'select'); -select has_column_privilege('pg_authid', cast(99 as smallint), 'select'); +select has_column_privilege('pg_authid', cast(99 as int2), 'select'); -select has_column_privilege(9999, cast(99 as smallint), 'select'); +select has_column_privilege(9999, cast(99 as int2), 'select'); create temporary table mytable ( f1 int, @@ -2257,21 +1848,17 @@ alter table mytable select has_column_privilege('mytable', 'f2', 'select'); select - has_column_privilege( - 'mytable', - '........pg.dropped.2........', - 'select' - ); + has_column_privilege('mytable', '........pg.dropped.2........', 'select'); -select has_column_privilege('mytable', cast(2 as smallint), 'select'); +select has_column_privilege('mytable', cast(2 as int2), 'select'); -select has_column_privilege('mytable', cast(99 as smallint), 'select'); +select has_column_privilege('mytable', cast(99 as int2), 'select'); -revoke SELECT on table mytable from regress_priv_user3; +revoke select on table mytable from regress_priv_user3; -select has_column_privilege('mytable', cast(2 as smallint), 'select'); +select has_column_privilege('mytable', cast(2 as int2), 'select'); -select has_column_privilege('mytable', cast(99 as smallint), 'select'); +select has_column_privilege('mytable', cast(99 as int2), 'select'); drop table mytable; @@ -2279,27 +1866,27 @@ set session authorization regress_priv_user1; create table atest4 (a int); -grant SELECT on table atest4 to regress_priv_user2 with grant option; +grant select on table atest4 to regress_priv_user2 with grant option; -grant UPDATE on table atest4 to regress_priv_user2; +grant update on table atest4 to regress_priv_user2; -grant SELECT on table atest4 to regress_priv_group1 with grant option; +grant select on table atest4 to regress_priv_group1 with grant option; set session authorization regress_priv_user2; -grant SELECT on table atest4 to regress_priv_user3; +grant select on table atest4 to regress_priv_user3; -grant UPDATE on table atest4 to regress_priv_user3; +grant update on table atest4 to regress_priv_user3; set session authorization regress_priv_user1; -revoke SELECT on table atest4 from regress_priv_user3; +revoke select on table atest4 from regress_priv_user3; select has_table_privilege('regress_priv_user3', 'atest4', 'SELECT'); -revoke SELECT on table atest4 from regress_priv_user2; +revoke select on table atest4 from regress_priv_user2; -revoke grant option for SELECT on table atest4 from regress_priv_user2 cascade; +revoke grant option for select on table atest4 from regress_priv_user2 cascade; select has_table_privilege('regress_priv_user2', 'atest4', 'SELECT'); @@ -2318,14 +1905,14 @@ create function sro_ifun(int) returns int language plpgsql immutable -as $function$ +as $$ BEGIN -- Below we set the table's owner to regress_sro_user ASSERT current_user = 'regress_sro_user', format('sro_ifun(%s) called by %s', $1, current_user); RETURN $1; END; -$function$; +$$; create table sro_tab (a int); @@ -2334,38 +1921,25 @@ alter table sro_tab insert into sro_tab values (1), (2), (3); -create index "sro_idx" -on sro_tab -using btree -( - (sro_ifun(a) + sro_ifun(0)) -) -where - sro_ifun(a + 10) > sro_ifun(10); +create index sro_idx on sro_tab using btree ((sro_ifun(a) + sro_ifun(0))) +where sro_ifun(a + 10) > sro_ifun(10); drop index sro_idx; -create index concurrently "sro_idx" -on sro_tab -using btree -( +create index concurrently sro_idx on sro_tab using btree ( (sro_ifun(a) + sro_ifun(0)) ) -where - sro_ifun(a + 10) > sro_ifun(10); +where sro_ifun(a + 10) > sro_ifun(10); reindex table sro_tab; reindex index sro_idx; -reindex (CONCURRENTLY) table sro_tab; +reindex (concurrently) table sro_tab; drop index sro_idx; -create index "sro_cluster_idx" -on sro_tab -using btree -( +create index sro_cluster_idx on sro_tab using btree ( (sro_ifun(a) + sro_ifun(0)) ); @@ -2373,7 +1947,7 @@ cluster sro_tab using sro_cluster_idx; drop index sro_cluster_idx; -create index "sro_brin" on sro_tab using brin ((sro_ifun(a) + sro_ifun(0))); +create index sro_brin on sro_tab using brin ((sro_ifun(a) + sro_ifun(0))); select brin_desummarize_range('sro_brin', 0); @@ -2394,34 +1968,24 @@ alter table sro_part insert into sro_ptab values (1), (2), (3); -create index "sro_pidx" -on sro_ptab -using btree -( - (sro_ifun(a) + sro_ifun(0)) -) -where - sro_ifun(a + 10) > sro_ifun(10); +create index sro_pidx on sro_ptab using btree ((sro_ifun(a) + sro_ifun(0))) +where sro_ifun(a + 10) > sro_ifun(10); reindex table sro_ptab; -reindex (CONCURRENTLY) index sro_pidx; +reindex (concurrently) index sro_pidx; set session authorization regress_sro_user; create function unwanted_grant() returns void language sql -as $function$ -GRANT regress_priv_group2 TO regress_sro_user -$function$; +as 'GRANT regress_priv_group2 TO regress_sro_user'; create function mv_action() -returns boolean +returns bool language sql -as $function$ -DECLARE c CURSOR WITH HOLD FOR SELECT public.unwanted_grant(); SELECT true -$function$; +as 'DECLARE c CURSOR WITH HOLD FOR SELECT public.unwanted_grant(); SELECT true'; create materialized view sro_mv as select mv_action() with no data; @@ -2436,9 +2000,7 @@ create table sro_trojan_table (); create function sro_trojan() returns trigger language plpgsql -as $function$ -BEGIN PERFORM public.unwanted_grant(); RETURN NULL; END -$function$; +as 'BEGIN PERFORM public.unwanted_grant(); RETURN NULL; END'; create constraint trigger t after insert @@ -2449,11 +2011,9 @@ for each row execute function sro_trojan(); create or replace function mv_action() -returns boolean +returns bool language sql -as $function$ -INSERT INTO public.sro_trojan_table DEFAULT VALUES; SELECT true -$function$; +as 'INSERT INTO public.sro_trojan_table DEFAULT VALUES; SELECT true'; refresh materialized view sro_mv; @@ -2473,26 +2033,19 @@ create function unwanted_grant_nofail(int) returns int language plpgsql immutable -as $function$ +as $$ BEGIN PERFORM public.unwanted_grant(); RAISE WARNING 'owned'; RETURN 1; EXCEPTION WHEN OTHERS THEN RETURN 2; -END -$function$; +END$$; create materialized view sro_index_mv as select 1 as c; -create unique index -on sro_index_mv -using btree -( - c -) -where - unwanted_grant_nofail(1) > 0; +create unique index on sro_index_mv using btree (c) +where unwanted_grant_nofail(1) > 0; refresh materialized view concurrently sro_index_mv; @@ -2508,39 +2061,37 @@ create function dogrant_ok() returns void language sql security definer -as $function$ -GRANT regress_priv_group2 TO regress_priv_user5 -$function$; +as 'GRANT regress_priv_group2 TO regress_priv_user5'; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; set role to regress_priv_group2; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; set session authorization regress_priv_user1; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; select dogrant_ok(); set role to regress_priv_group2; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; set session authorization regress_priv_group2; -grant REGRESS_PRIV_GROUP2 to regress_priv_user5; +grant regress_priv_group2 to regress_priv_user5; set session authorization regress_priv_user4; drop function dogrant_ok(); -revoke REGRESS_PRIV_GROUP2 from regress_priv_user5 restrict; +revoke regress_priv_group2 from regress_priv_user5 restrict; create sequence x_seq; -grant USAGE on table x_seq to regress_priv_user2; +grant usage on table x_seq to regress_priv_user2; select has_sequence_privilege('regress_priv_user1', 'atest1', 'SELECT'); @@ -2566,19 +2117,19 @@ select lo_create(1005); grant all on large object 1001 to public; -grant SELECT on large object 1003 to regress_priv_user2; +grant select on large object 1003 to regress_priv_user2; -grant SELECT, UPDATE on large object 1004 to regress_priv_user2; +grant select, update on large object 1004 to regress_priv_user2; grant all on large object 1005 to regress_priv_user2; -grant SELECT on large object 1005 to regress_priv_user2 with grant option; +grant select on large object 1005 to regress_priv_user2 with grant option; -grant SELECT, INSERT on large object 1001 to public; +grant select, insert on large object 1001 to public; -grant SELECT, UPDATE on large object 1001 to nosuchuser; +grant select, update on large object 1001 to nosuchuser; -grant SELECT, UPDATE on large object 999 to public; +grant select, update on large object 999 to public; set session authorization regress_priv_user2; @@ -2606,9 +2157,9 @@ select lowrite(lo_open(1003, cast(X'20000' as int)), 'abcd'); select lowrite(lo_open(1004, cast(X'20000' as int)), 'abcd'); -grant SELECT on large object 1005 to regress_priv_user3; +grant select on large object 1005 to regress_priv_user3; -grant UPDATE on large object 1006 to regress_priv_user3; +grant update on large object 1006 to regress_priv_user3; revoke all on large object 2001, 2002 from public; @@ -2739,17 +2290,16 @@ reset session_authorization; begin; create or replace function terminate_nothrow(pid int) -returns boolean +returns bool language plpgsql security definer set client_min_messages = error -as $function$ +as $$ BEGIN RETURN pg_terminate_backend($1); EXCEPTION WHEN OTHERS THEN RETURN false; -END -$function$; +END$$; alter function terminate_nothrow owner to pg_signal_backend; @@ -2758,39 +2308,26 @@ select from pg_stat_activity where - case - when coalesce(usesysid, 10) = 10 - then terminate_nothrow(pid) - end; + case when coalesce(usesysid, 10) = 10 then terminate_nothrow(pid) end; rollback; reset session_authorization; -grant PG_DATABASE_OWNER to regress_priv_user1; +grant pg_database_owner to regress_priv_user1; -grant REGRESS_PRIV_USER1 to pg_database_owner; +grant regress_priv_user1 to pg_database_owner; create table datdba_only (); alter table datdba_only owner to pg_database_owner; -revoke DELETE on table datdba_only from pg_database_owner; +revoke delete on table datdba_only from pg_database_owner; select - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'USAGE' - ) - as priv, - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'MEMBER' - ) - as mem, + pg_has_role('regress_priv_user1', 'pg_database_owner', 'USAGE') as priv, + pg_has_role('regress_priv_user1', 'pg_database_owner', 'MEMBER') as mem, pg_has_role( 'regress_priv_user1', 'pg_database_owner', @@ -2800,25 +2337,12 @@ select begin; -do -$do$ -BEGIN EXECUTE format( - 'ALTER DATABASE %I OWNER TO regress_priv_group2', current_catalog); END -$do$; +do $$BEGIN EXECUTE format( + 'ALTER DATABASE %I OWNER TO regress_priv_group2', current_catalog); END$$; select - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'USAGE' - ) - as priv, - pg_has_role( - 'regress_priv_user1', - 'pg_database_owner', - 'MEMBER' - ) - as mem, + pg_has_role('regress_priv_user1', 'pg_database_owner', 'USAGE') as priv, + pg_has_role('regress_priv_user1', 'pg_database_owner', 'MEMBER') as mem, pg_has_role( 'regress_priv_user1', 'pg_database_owner', @@ -2852,7 +2376,7 @@ insert into datdba_only default values; rollback; -create schema "testns"; +create schema testns; grant all on schema testns to regress_priv_user1; @@ -2865,10 +2389,7 @@ select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'INSERT'); alter default privileges in schema testns, testns -grant SELECT -on tables -to public, -public; +grant select on tables to public, public; select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'SELECT'); @@ -2884,9 +2405,7 @@ select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'INSERT'); alter default privileges in schema testns -grant INSERT -on tables -to regress_priv_user1; +grant insert on tables to regress_priv_user1; drop table testns.acltest1; @@ -2898,9 +2417,7 @@ select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'INSERT'); alter default privileges in schema testns -revoke INSERT -on tables -from regress_priv_user1; +revoke insert on tables from regress_priv_user1; drop table testns.acltest1; @@ -2912,13 +2429,11 @@ select has_table_privilege('regress_priv_user1', 'testns.acltest1', 'INSERT'); alter default privileges for role regress_priv_user1 -revoke EXECUTE on functions from public; +revoke execute on functions from public; alter default privileges in schema testns -grant USAGE -on schemas -to regress_priv_user2; +grant usage on schemas to regress_priv_user2; select makeaclitem( @@ -2967,18 +2482,12 @@ select pg_input_is_valid('regress_priv_user1=r/', 'aclitem'); select * from pg_input_error_info('regress_priv_user1=r/', 'aclitem'); select - pg_input_is_valid( - 'regress_priv_user1=r/regress_no_such_user', - 'aclitem' - ); + pg_input_is_valid('regress_priv_user1=r/regress_no_such_user', 'aclitem'); select * from - pg_input_error_info( - 'regress_priv_user1=r/regress_no_such_user', - 'aclitem' - ); + pg_input_error_info('regress_priv_user1=r/regress_no_such_user', 'aclitem'); select pg_input_is_valid('regress_priv_user1=rY', 'aclitem'); @@ -2986,9 +2495,9 @@ select * from pg_input_error_info('regress_priv_user1=rY', 'aclitem'); begin; -alter default privileges grant USAGE on schemas to regress_priv_user2; +alter default privileges grant usage on schemas to regress_priv_user2; -create schema "testns2"; +create schema testns2; select has_schema_privilege('regress_priv_user2', 'testns2', 'USAGE'); @@ -2996,9 +2505,9 @@ select has_schema_privilege('regress_priv_user6', 'testns2', 'USAGE'); select has_schema_privilege('regress_priv_user2', 'testns2', 'CREATE'); -alter default privileges revoke USAGE on schemas from regress_priv_user2; +alter default privileges revoke usage on schemas from regress_priv_user2; -create schema "testns3"; +create schema testns3; select has_schema_privilege('regress_priv_user2', 'testns3', 'USAGE'); @@ -3006,7 +2515,7 @@ select has_schema_privilege('regress_priv_user2', 'testns3', 'CREATE'); alter default privileges grant all on schemas to regress_priv_user2; -create schema "testns4"; +create schema testns4; select has_schema_privilege('regress_priv_user2', 'testns4', 'USAGE'); @@ -3059,32 +2568,28 @@ alter default privileges grant all on tables to regress_priv_user2; alter default privileges grant all on types to regress_priv_user2; select - COUNT(*) + count(*) from pg_shdepend where deptype = 'a' and - refobjid = - cast('regress_priv_user2' as regrole) and - classid = - cast('pg_default_acl' as regclass); + refobjid = cast('regress_priv_user2' as regrole) and + classid = cast('pg_default_acl' as regclass); drop owned by regress_priv_user2, regress_priv_user2; select - COUNT(*) + count(*) from pg_shdepend where deptype = 'a' and - refobjid = - cast('regress_priv_user2' as regrole) and - classid = - cast('pg_default_acl' as regclass); + refobjid = cast('regress_priv_user2' as regrole) and + classid = cast('pg_default_acl' as regclass); rollback; -create schema "testns5"; +create schema testns5; select has_schema_privilege('regress_priv_user2', 'testns5', 'USAGE'); @@ -3095,60 +2600,44 @@ set role to regress_priv_user1; create function testns.foo() returns int language sql -as $function$ -select 1 -$function$; +as 'select 1'; -create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int); +create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int4); create procedure testns.bar() language sql -as $procedure$ -select 1 -$procedure$; +as 'select 1'; select has_function_privilege('regress_priv_user2', 'testns.foo()', 'EXECUTE'); select - has_function_privilege( - 'regress_priv_user2', - 'testns.agg1(int)', - 'EXECUTE' - ); + has_function_privilege('regress_priv_user2', 'testns.agg1(int)', 'EXECUTE'); select has_function_privilege('regress_priv_user2', 'testns.bar()', 'EXECUTE'); -alter default privileges in schema testns grant EXECUTE on functions to public; +alter default privileges in schema testns grant execute on functions to public; drop function testns.foo(); create function testns.foo() returns int language sql -as $function$ -select 1 -$function$; +as 'select 1'; drop aggregate testns.agg1(int); -create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int); +create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int4); drop procedure testns.bar(); create procedure testns.bar() language sql -as $procedure$ -select 1 -$procedure$; +as 'select 1'; select has_function_privilege('regress_priv_user2', 'testns.foo()', 'EXECUTE'); select - has_function_privilege( - 'regress_priv_user2', - 'testns.agg1(int)', - 'EXECUTE' - ); + has_function_privilege('regress_priv_user2', 'testns.agg1(int)', 'EXECUTE'); select has_function_privilege('regress_priv_user2', 'testns.bar()', 'EXECUTE'); @@ -3160,36 +2649,28 @@ drop procedure testns.bar(); alter default privileges for role regress_priv_user1 -revoke USAGE on types from public; +revoke usage on types from public; create domain testns.priv_testdomain1 as int; select - has_type_privilege( - 'regress_priv_user2', - 'testns.priv_testdomain1', - 'USAGE' - ); + has_type_privilege('regress_priv_user2', 'testns.priv_testdomain1', 'USAGE'); -alter default privileges in schema testns grant USAGE on types to public; +alter default privileges in schema testns grant usage on types to public; drop domain testns.priv_testdomain1; create domain testns.priv_testdomain1 as int; select - has_type_privilege( - 'regress_priv_user2', - 'testns.priv_testdomain1', - 'USAGE' - ); + has_type_privilege('regress_priv_user2', 'testns.priv_testdomain1', 'USAGE'); drop domain testns.priv_testdomain1; reset role; select - COUNT(*) + count(*) from pg_default_acl as d left outer join @@ -3218,7 +2699,7 @@ from where nspname is null and defaclnamespace <> 0; -create schema "testns"; +create schema testns; create table testns.t1 (f1 int); @@ -3241,17 +2722,13 @@ select has_table_privilege('regress_priv_user1', 'testns.t2', 'SELECT'); create function testns.priv_testfunc(int) returns int language sql -as $function$ -select 3 * $1; -$function$; +as 'select 3 * $1;'; -create aggregate testns.priv_testagg (int) (sfunc = int4pl, stype = int); +create aggregate testns.priv_testagg (int) (sfunc = int4pl, stype = int4); create procedure testns.priv_testproc(int) language sql -as $procedure$ -select 3 -$procedure$; +as 'select 3'; select has_function_privilege( @@ -3337,7 +2814,7 @@ create role regress_schemauser2 superuser login; set role to regress_schemauser1; -create schema "testns"; +create schema testns; select nspname, @@ -3346,8 +2823,7 @@ from pg_namespace, pg_roles where - pg_namespace.nspname = 'testns' and - pg_namespace.nspowner = pg_roles.oid; + pg_namespace.nspname = 'testns' and pg_namespace.nspowner = pg_roles.oid; alter schema testns owner to regress_schemauser2; @@ -3360,8 +2836,7 @@ from pg_namespace, pg_roles where - pg_namespace.nspname = 'testns' and - pg_namespace.nspowner = pg_roles.oid; + pg_namespace.nspname = 'testns' and pg_namespace.nspowner = pg_roles.oid; set role to regress_schemauser_renamed; @@ -3375,29 +2850,29 @@ set role to regress_priv_user1; create table dep_priv_test (a int); -grant SELECT on table dep_priv_test to regress_priv_user2 with grant option; +grant select on table dep_priv_test to regress_priv_user2 with grant option; -grant SELECT on table dep_priv_test to regress_priv_user3 with grant option; +grant select on table dep_priv_test to regress_priv_user3 with grant option; set role to regress_priv_user2; -grant SELECT on table dep_priv_test to regress_priv_user4 with grant option; +grant select on table dep_priv_test to regress_priv_user4 with grant option; set role to regress_priv_user3; -grant SELECT on table dep_priv_test to regress_priv_user4 with grant option; +grant select on table dep_priv_test to regress_priv_user4 with grant option; set role to regress_priv_user4; -grant SELECT on table dep_priv_test to regress_priv_user5; +grant select on table dep_priv_test to regress_priv_user5; set role to regress_priv_user2; -revoke SELECT on table dep_priv_test from regress_priv_user4 cascade; +revoke select on table dep_priv_test from regress_priv_user4 cascade; set role to regress_priv_user3; -revoke SELECT on table dep_priv_test from regress_priv_user4 cascade; +revoke select on table dep_priv_test from regress_priv_user4 cascade; set role to regress_priv_user1; @@ -3453,7 +2928,7 @@ drop role regress_priv_group1; drop role regress_priv_group2; -revoke USAGE on language sql from regress_priv_user1; +revoke usage on language sql from regress_priv_user1; drop owned by regress_priv_user1; @@ -3475,163 +2950,159 @@ drop role regress_priv_user8; alter default privileges for role pg_signal_backend -revoke USAGE -on types -from pg_signal_backend; +revoke usage on types from pg_signal_backend; alter default privileges for role pg_read_all_settings -revoke USAGE -on types -from pg_read_all_settings; +revoke usage on types from pg_read_all_settings; create user regress_locktable_user; create table lock_table (a int); -grant SELECT on table lock_table to regress_locktable_user; +grant select on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; commit; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; rollback; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; rollback; -revoke SELECT on table lock_table from regress_locktable_user; +revoke select on table lock_table from regress_locktable_user; -grant INSERT on table lock_table to regress_locktable_user; +grant insert on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; rollback; -revoke INSERT on table lock_table from regress_locktable_user; +revoke insert on table lock_table from regress_locktable_user; -grant UPDATE on table lock_table to regress_locktable_user; +grant update on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; commit; -revoke UPDATE on table lock_table from regress_locktable_user; +revoke update on table lock_table from regress_locktable_user; -grant DELETE on table lock_table to regress_locktable_user; +grant delete on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; commit; -revoke DELETE on table lock_table from regress_locktable_user; +revoke delete on table lock_table from regress_locktable_user; -grant TRUNCATE on table lock_table to regress_locktable_user; +grant truncate on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; commit; -revoke TRUNCATE on table lock_table from regress_locktable_user; +revoke truncate on table lock_table from regress_locktable_user; -grant MAINTAIN on table lock_table to regress_locktable_user; +grant maintain on table lock_table to regress_locktable_user; set session authorization regress_locktable_user; begin; -lock table lock_table in ACCESS SHARE mode; +lock table lock_table in access share mode; rollback; begin; -lock table lock_table in ROW EXCLUSIVE mode; +lock table lock_table in row exclusive mode; commit; begin; -lock table lock_table in ACCESS EXCLUSIVE mode; +lock table lock_table in access exclusive mode; commit; -revoke MAINTAIN on table lock_table from regress_locktable_user; +revoke maintain on table lock_table from regress_locktable_user; drop table lock_table; @@ -3649,11 +3120,7 @@ select ); select - has_table_privilege( - 'regress_readallstats', - 'pg_shmem_allocations', - 'SELECT' - ); + has_table_privilege('regress_readallstats', 'pg_shmem_allocations', 'SELECT'); select has_table_privilege( @@ -3669,7 +3136,7 @@ select 'SELECT' ); -grant PG_READ_ALL_STATS to regress_readallstats; +grant pg_read_all_stats to regress_readallstats; select has_table_privilege('regress_readallstats', 'pg_aios', 'SELECT'); @@ -3681,11 +3148,7 @@ select ); select - has_table_privilege( - 'regress_readallstats', - 'pg_shmem_allocations', - 'SELECT' - ); + has_table_privilege('regress_readallstats', 'pg_shmem_allocations', 'SELECT'); select has_table_privilege( @@ -3703,11 +3166,11 @@ select set role to regress_readallstats; -select COUNT(*) >= 0 as ok from pg_aios; +select count(*) >= 0 as ok from pg_aios; -select COUNT(*) >= 0 as ok from pg_backend_memory_contexts; +select count(*) >= 0 as ok from pg_backend_memory_contexts; -select COUNT(*) >= 0 as ok from pg_shmem_allocations; +select count(*) >= 0 as ok from pg_shmem_allocations; reset role; @@ -3721,54 +3184,50 @@ create role regress_group_indirect_manager; create role regress_group_member; -grant REGRESS_GROUP +grant regress_group to regress_group_direct_manager -with INHERIT false, -ADMIN true; +with inherit false, +admin true; -grant REGRESS_GROUP_DIRECT_MANAGER to regress_group_indirect_manager; +grant regress_group_direct_manager to regress_group_indirect_manager; set session authorization regress_group_direct_manager; -grant REGRESS_GROUP to regress_group_member; +grant regress_group to regress_group_member; select cast(cast(member as regrole) as text), case - when grantor = 10 - then 'BOOTSTRAP SUPERUSER' + when grantor = 10 then 'BOOTSTRAP SUPERUSER' else cast(cast(grantor as regrole) as text) end from pg_auth_members where - roleid = - cast('regress_group' as regrole) + roleid = cast('regress_group' as regrole) order by 1, 2; -revoke REGRESS_GROUP from regress_group_member restrict; +revoke regress_group from regress_group_member restrict; set session authorization regress_group_indirect_manager; -grant REGRESS_GROUP to regress_group_member; +grant regress_group to regress_group_member; select cast(cast(member as regrole) as text), case - when grantor = 10 - then 'BOOTSTRAP SUPERUSER' + when grantor = 10 then 'BOOTSTRAP SUPERUSER' else cast(cast(grantor as regrole) as text) end from pg_auth_members where - roleid = - cast('regress_group' as regrole) + roleid = cast('regress_group' as regrole) order by 1, 2; -revoke REGRESS_GROUP from regress_group_member restrict; +revoke regress_group from regress_group_member restrict; reset session_authorization; @@ -3786,19 +3245,19 @@ create role regress_roleoption_donor; create role regress_roleoption_recipient; -create schema "regress_roleoption"; +create schema regress_roleoption; -grant CREATE, USAGE on schema regress_roleoption to public; +grant create, usage on schema regress_roleoption to public; -grant REGRESS_ROLEOPTION_DONOR +grant regress_roleoption_donor to regress_roleoption_protagonist -with INHERIT true, -SET false; +with inherit true, +set false; -grant REGRESS_ROLEOPTION_RECIPIENT +grant regress_roleoption_recipient to regress_roleoption_protagonist -with INHERIT false, -SET true; +with inherit false, +set true; set session authorization regress_roleoption_protagonist; @@ -3856,13 +3315,13 @@ create table maintain_test (a int); create index on maintain_test using btree (a); -grant MAINTAIN on table maintain_test to regress_maintain; +grant maintain on table maintain_test to regress_maintain; create materialized view refresh_test as select 1; -grant MAINTAIN on table refresh_test to regress_maintain; +grant maintain on table refresh_test to regress_maintain; -create schema "reindex_test"; +create schema reindex_test; set role to regress_no_maintain; @@ -3870,7 +3329,7 @@ vacuum maintain_test; analyze maintain_test; -vacuum (ANALYZE) maintain_test; +vacuum (analyze) maintain_test; cluster maintain_test using maintain_test_a_idx; @@ -3890,7 +3349,7 @@ vacuum maintain_test; analyze maintain_test; -vacuum (ANALYZE) maintain_test; +vacuum (analyze) maintain_test; cluster maintain_test using maintain_test_a_idx; @@ -3910,7 +3369,7 @@ vacuum maintain_test; analyze maintain_test; -vacuum (ANALYZE) maintain_test; +vacuum (analyze) maintain_test; cluster maintain_test using maintain_test_a_idx; @@ -3948,21 +3407,21 @@ create table grantor_test2 (); create table grantor_test3 (); -grant SELECT on table grantor_test2 to regress_grantor1 with grant option; +grant select on table grantor_test2 to regress_grantor1 with grant option; -grant SELECT, -UPDATE +grant select, +update on table grantor_test3 to regress_grantor2 with grant option; set role to regress_grantor1; -grant SELECT, UPDATE on table grantor_test1 to regress_grantor3; +grant select, update on table grantor_test1 to regress_grantor3; -grant SELECT, UPDATE on table grantor_test2 to regress_grantor3; +grant select, update on table grantor_test2 to regress_grantor3; -grant SELECT, UPDATE on table grantor_test3 to regress_grantor3; +grant select, update on table grantor_test3 to regress_grantor3; reset role; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__publication_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__publication_100.snap index 8ad38b88d..edf4b451a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__publication_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__publication_100.snap @@ -10,7 +10,7 @@ create role regress_publication_user_dummy login nosuperuser; set session authorization regress_publication_user; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_default; @@ -20,7 +20,7 @@ comment on publication testpub_default is 'test publication'; select obj_description(p.oid, 'pg_publication') from pg_publication as p; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_ins_trunct with (publish = insert); @@ -33,12 +33,10 @@ create publication testpub_xxx with (foo); create publication testpub_xxx with (publish = 'cluster, vacuum'); create publication testpub_xxx -with (publish_via_partition_root = 'true', -publish_via_partition_root = '0'); +with (publish_via_partition_root = 'true', publish_via_partition_root = '0'); create publication testpub_xxx -with (publish_generated_columns = stored, -publish_generated_columns = 'none'); +with (publish_generated_columns = stored, publish_generated_columns = 'none'); create publication testpub_xxx with (publish_generated_columns = foo); @@ -46,7 +44,7 @@ create publication testpub_xxx with (publish_generated_columns); alter publication testpub_default set (publish = 'insert, update, delete'); -create schema "pub_test"; +create schema pub_test; create table testpub_tbl1 ( id serial primary key, @@ -62,9 +60,9 @@ create view testpub_view as select 1; create table testpub_parted (a int) -partition by LIST(a); +partition by list(a); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_foralltables for all tables with (publish = 'insert'); @@ -89,7 +87,7 @@ alter publication testpub_foralltables drop tables in schema pub_test; alter publication testpub_foralltables set tables in schema pub_test; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_fortable for table testpub_tbl1; @@ -101,7 +99,7 @@ alter publication testpub_fortable drop tables in schema pub_test; alter publication testpub_fortable set tables in schema pub_test; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_forschema for tables in schema pub_test; @@ -130,7 +128,7 @@ create table testpub_tbl3 (a int); create table testpub_tbl3a (b text) inherits (testpub_tbl3); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub3 for table testpub_tbl3; @@ -142,7 +140,7 @@ drop table testpub_tbl3, testpub_tbl3a; drop publication testpub3, testpub4; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_forparted; @@ -206,15 +204,15 @@ create table testpub_rf_tbl4 (g text); create table testpub_rf_tbl5 (a xml); -create schema "testpub_rf_schema1"; +create schema testpub_rf_schema1; create table testpub_rf_schema1.testpub_rf_tbl5 (h int); -create schema "testpub_rf_schema2"; +create schema testpub_rf_schema2; create table testpub_rf_schema2.testpub_rf_tbl6 (i int); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub5 for table testpub_rf_tbl1, @@ -229,7 +227,7 @@ alter publication testpub5 drop table testpub_rf_tbl2; alter publication testpub5 set table testpub_rf_tbl3 where ( e > 300 and e < 500); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_rf_yes for table testpub_rf_tbl1 where (a > 1) with (publish = 'insert'); @@ -239,7 +237,7 @@ reset client_min_messages; drop publication testpub_rf_yes, testpub_rf_no; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_syntax1 for table testpub_rf_tbl1, @@ -250,7 +248,7 @@ reset client_min_messages; drop publication testpub_syntax1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_syntax2 for table testpub_rf_tbl1, @@ -261,11 +259,11 @@ reset client_min_messages; drop publication testpub_syntax2; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; reset client_min_messages; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_dups for table testpub_rf_tbl1 where (a = 1), @@ -281,16 +279,14 @@ reset client_min_messages; alter publication testpub5 set table testpub_rf_tbl3 where ( 1234); -alter publication testpub5 set table testpub_rf_tbl3 where ( e < AVG(e)); +alter publication testpub5 set table testpub_rf_tbl3 where ( e < avg(e)); create function testpub_rf_func1(int, int) returns boolean language sql -as $function$ -SELECT hashint4($1) > $2 -$function$; +as $$ SELECT hashint4($1) > $2 $$; -create operator =#> (PROCEDURE = testpub_rf_func1, LEFTARG = int, RIGHTARG = int); +create operator =#> (procedure = testpub_rf_func1, leftarg = int, rightarg = int); create publication testpub6 for table testpub_rf_tbl3 where (e =#> 27); @@ -298,9 +294,7 @@ create function testpub_rf_func2() returns int language plpgsql immutable -as $function$ -BEGIN RETURN 123; END; -$function$; +as $$ BEGIN RETURN 123; END; $$; alter publication testpub5 add table testpub_rf_tbl1 where ( a >= testpub_rf_func2()); @@ -345,16 +339,12 @@ create publication testpub6 for table testpub_rf_tbl1 where (cast('(0,1)' as tid alter publication testpub5 set table testpub_rf_tbl5 where ( a is document); alter publication testpub5 set -table testpub_rf_tbl5 -where ( - xmlexists('//foo[text() = ''bar'']' passing a)); +table testpub_rf_tbl5 where ( xmlexists('//foo[text() = ''bar'']' passing a)); alter publication testpub5 set table testpub_rf_tbl1 where ( nullif(1, 2) = a); alter publication testpub5 set -table testpub_rf_tbl1 -where ( - case a when 5 then true else false end); +table testpub_rf_tbl1 where ( case a when 5 then true else false end); alter publication testpub5 set table testpub_rf_tbl1 where ( coalesce(b, 'foo') = 'foo'); @@ -368,7 +358,7 @@ alter publication testpub5 set table testpub_rf_tbl1 where ( row(a, 2) is null); alter publication testpub5 drop table testpub_rf_tbl1 where ( e < 27); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub6 for tables in schema testpub_rf_schema2; @@ -380,7 +370,7 @@ reset client_min_messages; create publication testpub7 for table testpub_rf_tbl6 where (y > 100); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub8 for table testpub_rf_tbl7 where (y > 100); @@ -454,7 +444,7 @@ alter table rf_tbl_abcd_part_pk attach partition rf_tbl_abcd_part_pk_1 for values from (1) to (10); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub6 for table rf_tbl_abcd_pk where (a > 99); @@ -513,7 +503,7 @@ update rf_tbl_abcd_nopk set a = 1; alter table rf_tbl_abcd_pk alter column c set not null; -create unique index "idx_abcd_pk_c" on rf_tbl_abcd_pk using btree (c); +create unique index idx_abcd_pk_c on rf_tbl_abcd_pk using btree (c); alter table rf_tbl_abcd_pk replica identity using index idx_abcd_pk_c; @@ -521,7 +511,7 @@ alter table rf_tbl_abcd_pk alter table rf_tbl_abcd_nopk alter column c set not null; -create unique index "idx_abcd_nopk_c" on rf_tbl_abcd_nopk using btree (c); +create unique index idx_abcd_nopk_c on rf_tbl_abcd_nopk using btree (c); alter table rf_tbl_abcd_nopk replica identity using index idx_abcd_nopk_c; @@ -582,14 +572,14 @@ drop table rf_tbl_abcd_nopk; drop table rf_tbl_abcd_part_pk; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create table testpub_gencol ( a int, b int generated always as (a + 1) stored not null ); -create unique index "testpub_gencol_idx" on testpub_gencol using btree (b); +create unique index testpub_gencol_idx on testpub_gencol using btree (b); alter table testpub_gencol replica identity using index testpub_gencol_idx; @@ -632,7 +622,7 @@ drop table testpub_gencol; reset client_min_messages; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_dups for table testpub_tbl1 (a), @@ -646,7 +636,7 @@ with (publish = 'insert'); reset client_min_messages; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_fortable for table testpub_tbl1; @@ -677,7 +667,7 @@ alter table testpub_tbl5 alter publication testpub_fortable_insert add table testpub_tbl5 (b, c); -create unique index "testpub_tbl5_b_key" on testpub_tbl5 using btree (b, c); +create unique index testpub_tbl5_b_key on testpub_tbl5 using btree (b, c); alter table testpub_tbl5 alter column b set not null, @@ -703,7 +693,7 @@ alter publication testpub_fortable add table testpub_tbl5 (a, c); update testpub_tbl5 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_table_ins with (publish = 'insert, truncate'); @@ -760,9 +750,9 @@ create table testpub_tbl8 ( b text, c text ) -partition by HASH(a); +partition by hash(a); -create table testpub_tbl8_0 partition of testpub_tbl8 for values with (MODULUS 2, REMAINDER 0); +create table testpub_tbl8_0 partition of testpub_tbl8 for values with (modulus 2, remainder 0); alter table testpub_tbl8_0 add primary key (a); @@ -770,7 +760,7 @@ alter table testpub_tbl8_0 alter table testpub_tbl8_0 replica identity using index testpub_tbl8_0_pkey; -create table testpub_tbl8_1 partition of testpub_tbl8 for values with (MODULUS 2, REMAINDER 1); +create table testpub_tbl8_1 partition of testpub_tbl8 for values with (modulus 2, remainder 1); alter table testpub_tbl8_1 add primary key (b); @@ -778,11 +768,10 @@ alter table testpub_tbl8_1 alter table testpub_tbl8_1 replica identity using index testpub_tbl8_1_pkey; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_col_list -for table testpub_tbl8 (a, -b) +for table testpub_tbl8 (a, b) with (publish_via_partition_root = 'true'); reset client_min_messages; @@ -838,7 +827,7 @@ create table testpub_tbl8 ( b text, c text ) -partition by HASH(a); +partition by hash(a); alter publication testpub_col_list add table testpub_tbl8 (a, b); @@ -873,7 +862,7 @@ alter table testpub_tbl8_0 update testpub_tbl8 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_tbl9 for tables in schema public, table public.testpub_tbl7 (a); @@ -902,7 +891,7 @@ drop publication testpub_col_list, testpub_tbl9; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_both_filters; @@ -916,9 +905,7 @@ create table testpub_tbl_both_filters ( ); alter table testpub_tbl_both_filters - replica identity - using index - testpub_tbl_both_filters_pkey; + replica identity using index testpub_tbl_both_filters_pkey; alter publication testpub_both_filters add table testpub_tbl_both_filters (a, c) where ( c <> 1); @@ -956,7 +943,7 @@ alter table rf_tbl_abcd_part_pk attach partition rf_tbl_abcd_part_pk_1 for values from (1) to (10); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub6 for table rf_tbl_abcd_pk (a, b); @@ -1015,7 +1002,7 @@ update rf_tbl_abcd_nopk set a = 1; alter table rf_tbl_abcd_pk alter column c set not null; -create unique index "idx_abcd_pk_c" on rf_tbl_abcd_pk using btree (c); +create unique index idx_abcd_pk_c on rf_tbl_abcd_pk using btree (c); alter table rf_tbl_abcd_pk replica identity using index idx_abcd_pk_c; @@ -1023,7 +1010,7 @@ alter table rf_tbl_abcd_pk alter table rf_tbl_abcd_nopk alter column c set not null; -create unique index "idx_abcd_nopk_c" on rf_tbl_abcd_nopk using btree (c); +create unique index idx_abcd_nopk_c on rf_tbl_abcd_nopk using btree (c); alter table rf_tbl_abcd_nopk replica identity using index idx_abcd_nopk_c; @@ -1084,7 +1071,7 @@ drop table rf_tbl_abcd_nopk; drop table rf_tbl_abcd_part_pk; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create table testpub_tbl4 (a int); @@ -1120,7 +1107,7 @@ drop table testpub_unloggedtbl; create publication testpub_forsystemtbl for table pg_publication; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_fortbl for table testpub_tbl1, table pub_test.testpub_nopk; @@ -1153,12 +1140,12 @@ alter publication testpub_default add table pub_test.testpub_addpk; insert into pub_test.testpub_addpk values (1, 11); -create unique index "testpub_addpk_id_idx" on pub_test.testpub_addpk using btree (id); +create unique index testpub_addpk_id_idx on pub_test.testpub_addpk using btree (id); update pub_test.testpub_addpk set id = 2; alter table pub_test.testpub_addpk - add primary key using index "testpub_addpk_id_idx"; + add primary key using index testpub_addpk_id_idx; update pub_test.testpub_addpk set id = 2; @@ -1170,11 +1157,11 @@ create publication testpub2; set role to regress_publication_user; -grant CREATE on database regression to regress_publication_user2; +grant create on database regression to regress_publication_user2; set role to regress_publication_user2; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub2; @@ -1190,7 +1177,7 @@ alter publication testpub3 add tables in schema pub_test; set role to regress_publication_user; -grant REGRESS_PUBLICATION_USER to regress_publication_user2; +grant regress_publication_user to regress_publication_user2; set role to regress_publication_user2; @@ -1204,9 +1191,9 @@ set role to regress_publication_user; create role regress_publication_user3; -grant REGRESS_PUBLICATION_USER2 to regress_publication_user3; +grant regress_publication_user2 to regress_publication_user3; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub4 for tables in schema pub_test; @@ -1226,7 +1213,7 @@ drop publication testpub4; drop role regress_publication_user3; -revoke CREATE on database regression from regress_publication_user2; +revoke create on database regression from regress_publication_user2; drop table testpub_parted; @@ -1244,11 +1231,11 @@ alter publication testpub_foo rename to testpub_default; alter publication testpub_default owner to regress_publication_user2; -create schema "pub_test1"; +create schema pub_test1; -create schema "pub_test2"; +create schema pub_test2; -create schema "pub_test3"; +create schema pub_test3; create schema "CURRENT_SCHEMA"; @@ -1269,7 +1256,7 @@ create table pub_test2.tbl1 ( create table "CURRENT_SCHEMA"."CURRENT_SCHEMA" (id int); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub1_forschema for tables in schema pub_test1; @@ -1355,12 +1342,12 @@ alter publication testpub1_forschema set tables in schema pub_test1; update pub_test1.tbl set id = 2; -create schema "pub_testpart1"; +create schema pub_testpart1; -create schema "pub_testpart2"; +create schema pub_testpart2; create table pub_testpart1.parent1 (a int) -partition by LIST(a); +partition by list(a); create table pub_testpart2.child_parent1 partition of pub_testpart1.parent1 for values in (1); @@ -1368,7 +1355,7 @@ insert into pub_testpart2.child_parent1 values (1); update pub_testpart2.child_parent1 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpubpart_forschema for tables in schema pub_testpart1; @@ -1381,7 +1368,7 @@ update pub_testpart2.child_parent1 set a = 1; drop publication testpubpart_forschema; create table pub_testpart2.parent2 (a int) -partition by LIST(a); +partition by list(a); create table pub_testpart1.child_parent2 partition of pub_testpart2.parent2 for values in (1); @@ -1389,7 +1376,7 @@ insert into pub_testpart1.child_parent2 values (1); update pub_testpart1.child_parent2 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpubpart_forschema for tables in schema pub_testpart2; @@ -1401,7 +1388,7 @@ update pub_testpart2.parent2 set a = 1; update pub_testpart1.child_parent2 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub3_forschema; @@ -1409,7 +1396,7 @@ reset client_min_messages; alter publication testpub3_forschema set tables in schema pub_test1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_forschema_fortable for tables in schema pub_test1, table pub_test2.tbl1; @@ -1447,11 +1434,11 @@ drop schema pub_testpart1 cascade; drop schema pub_testpart2 cascade; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; -create schema "sch1"; +create schema sch1; -create schema "sch2"; +create schema sch2; create table sch1.tbl1 (a int) partition by range(a); @@ -1522,7 +1509,7 @@ drop schema sch1 cascade; drop schema sch2 cascade; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication pub1 for all tables with (publish_generated_columns = stored); @@ -1570,7 +1557,7 @@ create table testpub_insert_onconfl_part_no_ri partition of testpub_insert_onconfl_parted for values from (1) to (10); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication pub1 for all tables; @@ -1600,7 +1587,7 @@ create table testpub_merge_pk ( b int ); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication pub1 for all tables; @@ -1618,7 +1605,7 @@ drop role regress_publication_user, regress_publication_user2; drop role regress_publication_user_dummy; -create schema "pubme"; +create schema pubme; create table t0 ( c int, @@ -1627,14 +1614,14 @@ create table t0 ( create table t1 (c int); -create schema "pubme2"; +create schema pubme2; create table t0 ( c int, d int ); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication dump_pub_qual_1ct for table only pubme.t0 (c, d) where (c > 0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__publication_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__publication_80.snap index 5ceb35a11..b4eeefa47 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__publication_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__publication_80.snap @@ -10,7 +10,7 @@ create role regress_publication_user_dummy login nosuperuser; set session authorization regress_publication_user; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_default; @@ -20,7 +20,7 @@ comment on publication testpub_default is 'test publication'; select obj_description(p.oid, 'pg_publication') from pg_publication as p; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_ins_trunct with (publish = insert); @@ -33,12 +33,10 @@ create publication testpub_xxx with (foo); create publication testpub_xxx with (publish = 'cluster, vacuum'); create publication testpub_xxx -with (publish_via_partition_root = 'true', -publish_via_partition_root = '0'); +with (publish_via_partition_root = 'true', publish_via_partition_root = '0'); create publication testpub_xxx -with (publish_generated_columns = stored, -publish_generated_columns = 'none'); +with (publish_generated_columns = stored, publish_generated_columns = 'none'); create publication testpub_xxx with (publish_generated_columns = foo); @@ -46,7 +44,7 @@ create publication testpub_xxx with (publish_generated_columns); alter publication testpub_default set (publish = 'insert, update, delete'); -create schema "pub_test"; +create schema pub_test; create table testpub_tbl1 ( id serial primary key, @@ -62,9 +60,9 @@ create view testpub_view as select 1; create table testpub_parted (a int) -partition by LIST(a); +partition by list(a); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_foralltables for all tables with (publish = 'insert'); @@ -90,7 +88,7 @@ alter publication testpub_foralltables drop tables in schema pub_test; alter publication testpub_foralltables set tables in schema pub_test; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_fortable for table testpub_tbl1; @@ -102,7 +100,7 @@ alter publication testpub_fortable drop tables in schema pub_test; alter publication testpub_fortable set tables in schema pub_test; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_forschema for tables in schema pub_test; @@ -141,7 +139,7 @@ create table testpub_tbl3 (a int); create table testpub_tbl3a (b text) inherits (testpub_tbl3); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub3 for table testpub_tbl3; @@ -153,7 +151,7 @@ drop table testpub_tbl3, testpub_tbl3a; drop publication testpub3, testpub4; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_forparted; @@ -217,15 +215,15 @@ create table testpub_rf_tbl4 (g text); create table testpub_rf_tbl5 (a xml); -create schema "testpub_rf_schema1"; +create schema testpub_rf_schema1; create table testpub_rf_schema1.testpub_rf_tbl5 (h int); -create schema "testpub_rf_schema2"; +create schema testpub_rf_schema2; create table testpub_rf_schema2.testpub_rf_tbl6 (i int); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub5 for table testpub_rf_tbl1, @@ -235,18 +233,14 @@ with (publish = 'insert'); reset client_min_messages; alter publication testpub5 add -table testpub_rf_tbl3 -where ( - e > 1000 and e < 2000); +table testpub_rf_tbl3 where ( e > 1000 and e < 2000); alter publication testpub5 drop table testpub_rf_tbl2; alter publication testpub5 set -table testpub_rf_tbl3 -where ( - e > 300 and e < 500); +table testpub_rf_tbl3 where ( e > 300 and e < 500); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_rf_yes for table testpub_rf_tbl1 where (a > 1) @@ -258,7 +252,7 @@ reset client_min_messages; drop publication testpub_rf_yes, testpub_rf_no; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_syntax1 for table testpub_rf_tbl1, @@ -269,7 +263,7 @@ reset client_min_messages; drop publication testpub_syntax1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_syntax2 for table testpub_rf_tbl1, @@ -280,11 +274,11 @@ reset client_min_messages; drop publication testpub_syntax2; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; reset client_min_messages; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_dups for table testpub_rf_tbl1 where (a = 1), @@ -300,18 +294,18 @@ reset client_min_messages; alter publication testpub5 set table testpub_rf_tbl3 where ( 1234); -alter publication testpub5 set table testpub_rf_tbl3 where ( e < AVG(e)); +alter publication testpub5 set table testpub_rf_tbl3 where ( e < avg(e)); create function testpub_rf_func1(int, int) returns boolean language sql -as $function$ -SELECT hashint4($1) > $2 -$function$; +as $$ SELECT hashint4($1) > $2 $$; -create operator =#> (PROCEDURE = testpub_rf_func1, -LEFTARG = int, -RIGHTARG = int); +create operator =#> ( + procedure = testpub_rf_func1, + leftarg = int, + rightarg = int +); create publication testpub6 for table testpub_rf_tbl3 where (e =#> 27); @@ -319,23 +313,17 @@ create function testpub_rf_func2() returns int language plpgsql immutable -as $function$ -BEGIN RETURN 123; END; -$function$; +as $$ BEGIN RETURN 123; END; $$; alter publication testpub5 add -table testpub_rf_tbl1 -where ( - a >= testpub_rf_func2()); +table testpub_rf_tbl1 where ( a >= testpub_rf_func2()); alter publication testpub5 add table testpub_rf_tbl1 where ( a < random()); create collation user_collation from "C"; alter publication testpub5 add -table testpub_rf_tbl1 -where ( - b < '2' collate "user_collation"); +table testpub_rf_tbl1 where ( b < '2' collate "user_collation"); alter publication testpub5 set table testpub_rf_tbl1 where ( nullif(1, 2) = a); @@ -344,19 +332,13 @@ alter publication testpub5 set table testpub_rf_tbl1 where ( a is null); alter publication testpub5 set table testpub_rf_tbl1 where ( a > 5 is false); alter publication testpub5 set -table testpub_rf_tbl1 -where ( - a is distinct from 5); +table testpub_rf_tbl1 where ( a is distinct from 5); alter publication testpub5 set -table testpub_rf_tbl1 -where ( - (a, a + 1) < (2, 3)); +table testpub_rf_tbl1 where ( (a, a + 1) < (2, 3)); alter publication testpub5 set -table testpub_rf_tbl1 -where ( - cast(b as varchar) < '2'); +table testpub_rf_tbl1 where ( cast(b as varchar) < '2'); alter publication testpub5 set table testpub_rf_tbl4 where ( length(g) < 6); @@ -385,53 +367,41 @@ for table testpub_rf_tbl1 where (cast('(0,1)' as tid) = ctid); alter publication testpub5 set table testpub_rf_tbl5 where ( a is document); alter publication testpub5 set -table testpub_rf_tbl5 -where ( - xmlexists('//foo[text() = ''bar'']' passing a)); +table testpub_rf_tbl5 where ( xmlexists('//foo[text() = ''bar'']' passing a)); alter publication testpub5 set table testpub_rf_tbl1 where ( nullif(1, 2) = a); alter publication testpub5 set -table testpub_rf_tbl1 -where ( - case a when 5 then true else false end); +table testpub_rf_tbl1 where ( case a when 5 then true else false end); alter publication testpub5 set -table testpub_rf_tbl1 -where ( - coalesce(b, 'foo') = 'foo'); +table testpub_rf_tbl1 where ( coalesce(b, 'foo') = 'foo'); alter publication testpub5 set -table testpub_rf_tbl1 -where ( - greatest(a, 10) > 10); +table testpub_rf_tbl1 where ( greatest(a, 10) > 10); alter publication testpub5 set table testpub_rf_tbl1 where ( a in (2, 4, 6)); alter publication testpub5 set -table testpub_rf_tbl1 -where ( - array[a] <@ array[2, 4, 6]); +table testpub_rf_tbl1 where ( array[a] <@ array[2, 4, 6]); alter publication testpub5 set table testpub_rf_tbl1 where ( row(a, 2) is null); alter publication testpub5 drop table testpub_rf_tbl1 where ( e < 27); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub6 for tables in schema testpub_rf_schema2; alter publication testpub6 set tables in schema testpub_rf_schema2, -table testpub_rf_schema2.testpub_rf_tbl6 -where ( - i < 99); +table testpub_rf_schema2.testpub_rf_tbl6 where ( i < 99); reset client_min_messages; create publication testpub7 for table testpub_rf_tbl6 where (y > 100); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub8 for table testpub_rf_tbl7 where (y > 100); @@ -503,10 +473,9 @@ create table rf_tbl_abcd_part_pk_1 ( alter table rf_tbl_abcd_part_pk attach partition - rf_tbl_abcd_part_pk_1 - for values from (1) to (10); + rf_tbl_abcd_part_pk_1 for values from (1) to (10); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub6 for table rf_tbl_abcd_pk where (a > 99); @@ -565,22 +534,18 @@ update rf_tbl_abcd_nopk set a = 1; alter table rf_tbl_abcd_pk alter column c set not null; -create unique index "idx_abcd_pk_c" on rf_tbl_abcd_pk using btree (c); +create unique index idx_abcd_pk_c on rf_tbl_abcd_pk using btree (c); alter table rf_tbl_abcd_pk - replica identity - using index - idx_abcd_pk_c; + replica identity using index idx_abcd_pk_c; alter table rf_tbl_abcd_nopk alter column c set not null; -create unique index "idx_abcd_nopk_c" on rf_tbl_abcd_nopk using btree (c); +create unique index idx_abcd_nopk_c on rf_tbl_abcd_nopk using btree (c); alter table rf_tbl_abcd_nopk - replica identity - using index - idx_abcd_nopk_c; + replica identity using index idx_abcd_nopk_c; alter publication testpub6 set table rf_tbl_abcd_pk where ( a > 99); @@ -638,21 +603,17 @@ drop table rf_tbl_abcd_nopk; drop table rf_tbl_abcd_part_pk; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create table testpub_gencol ( a int, - b int - generated always as (a + 1) stored - not null + b int generated always as (a + 1) stored not null ); -create unique index "testpub_gencol_idx" on testpub_gencol using btree (b); +create unique index testpub_gencol_idx on testpub_gencol using btree (b); alter table testpub_gencol - replica identity - using index - testpub_gencol_idx; + replica identity using index testpub_gencol_idx; create publication pub_gencol for table testpub_gencol; @@ -696,7 +657,7 @@ drop table testpub_gencol; reset client_min_messages; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_dups for table testpub_tbl1 (a), @@ -710,7 +671,7 @@ with (publish = 'insert'); reset client_min_messages; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_fortable for table testpub_tbl1; @@ -741,16 +702,14 @@ alter table testpub_tbl5 alter publication testpub_fortable_insert add table testpub_tbl5 (b, c); -create unique index "testpub_tbl5_b_key" on testpub_tbl5 using btree (b, c); +create unique index testpub_tbl5_b_key on testpub_tbl5 using btree (b, c); alter table testpub_tbl5 alter column b set not null, alter column c set not null; alter table testpub_tbl5 - replica identity - using index - testpub_tbl5_b_key; + replica identity using index testpub_tbl5_b_key; update testpub_tbl5 set a = 1; @@ -763,15 +722,13 @@ alter publication testpub_fortable drop table testpub_tbl5; alter publication testpub_fortable add table testpub_tbl5 (a, e); alter table testpub_tbl5 - replica identity - using index - testpub_tbl5_b_key; + replica identity using index testpub_tbl5_b_key; alter publication testpub_fortable add table testpub_tbl5 (a, c); update testpub_tbl5 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_table_ins with (publish = 'insert, truncate'); @@ -828,37 +785,32 @@ create table testpub_tbl8 ( b text, c text ) -partition by HASH(a); +partition by hash(a); create table testpub_tbl8_0 partition of testpub_tbl8 -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); alter table testpub_tbl8_0 add primary key (a); alter table testpub_tbl8_0 - replica identity - using index - testpub_tbl8_0_pkey; + replica identity using index testpub_tbl8_0_pkey; create table testpub_tbl8_1 partition of testpub_tbl8 -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); alter table testpub_tbl8_1 add primary key (b); alter table testpub_tbl8_1 - replica identity - using index - testpub_tbl8_1_pkey; + replica identity using index testpub_tbl8_1_pkey; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_col_list -for table testpub_tbl8 (a, -b) +for table testpub_tbl8 (a, b) with (publish_via_partition_root = 'true'); reset client_min_messages; @@ -887,9 +839,7 @@ update testpub_tbl8 set a = 1; alter publication testpub_col_list drop table testpub_tbl8; alter table testpub_tbl8_1 - replica identity - using index - testpub_tbl8_1_pkey; + replica identity using index testpub_tbl8_1_pkey; alter publication testpub_col_list add table testpub_tbl8 (a, b); @@ -905,9 +855,7 @@ alter table testpub_tbl8_1 add primary key (c); alter table testpub_tbl8_1 - replica identity - using index - testpub_tbl8_1_pkey; + replica identity using index testpub_tbl8_1_pkey; update testpub_tbl8 set a = 1; @@ -918,7 +866,7 @@ create table testpub_tbl8 ( b text, c text ) -partition by HASH(a); +partition by hash(a); alter publication testpub_col_list add table testpub_tbl8 (a, b); @@ -932,9 +880,7 @@ alter table testpub_tbl8_0 add primary key (a); alter table testpub_tbl8_0 - replica identity - using index - testpub_tbl8_0_pkey; + replica identity using index testpub_tbl8_0_pkey; create table testpub_tbl8_1 ( a int, @@ -946,9 +892,7 @@ alter table testpub_tbl8_1 add primary key (c); alter table testpub_tbl8_1 - replica identity - using index - testpub_tbl8_1_pkey; + replica identity using index testpub_tbl8_1_pkey; update testpub_tbl8 set a = 1; @@ -957,7 +901,7 @@ alter table testpub_tbl8_0 update testpub_tbl8 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_tbl9 for tables in schema public, @@ -997,7 +941,7 @@ drop publication testpub_col_list, testpub_tbl9; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_both_filters; @@ -1011,15 +955,10 @@ create table testpub_tbl_both_filters ( ); alter table testpub_tbl_both_filters - replica identity - using index - testpub_tbl_both_filters_pkey; + replica identity using index testpub_tbl_both_filters_pkey; alter publication testpub_both_filters add -table testpub_tbl_both_filters (a, -c) -where ( - c <> 1); +table testpub_tbl_both_filters (a, c) where ( c <> 1); drop table testpub_tbl_both_filters; @@ -1053,10 +992,9 @@ create table rf_tbl_abcd_part_pk_1 ( alter table rf_tbl_abcd_part_pk attach partition - rf_tbl_abcd_part_pk_1 - for values from (1) to (10); + rf_tbl_abcd_part_pk_1 for values from (1) to (10); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub6 for table rf_tbl_abcd_pk (a, b); @@ -1115,22 +1053,18 @@ update rf_tbl_abcd_nopk set a = 1; alter table rf_tbl_abcd_pk alter column c set not null; -create unique index "idx_abcd_pk_c" on rf_tbl_abcd_pk using btree (c); +create unique index idx_abcd_pk_c on rf_tbl_abcd_pk using btree (c); alter table rf_tbl_abcd_pk - replica identity - using index - idx_abcd_pk_c; + replica identity using index idx_abcd_pk_c; alter table rf_tbl_abcd_nopk alter column c set not null; -create unique index "idx_abcd_nopk_c" on rf_tbl_abcd_nopk using btree (c); +create unique index idx_abcd_nopk_c on rf_tbl_abcd_nopk using btree (c); alter table rf_tbl_abcd_nopk - replica identity - using index - idx_abcd_nopk_c; + replica identity using index idx_abcd_nopk_c; alter publication testpub6 set table rf_tbl_abcd_pk (a); @@ -1188,7 +1122,7 @@ drop table rf_tbl_abcd_nopk; drop table rf_tbl_abcd_part_pk; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create table testpub_tbl4 (a int); @@ -1224,7 +1158,7 @@ drop table testpub_unloggedtbl; create publication testpub_forsystemtbl for table pg_publication; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_fortbl for table testpub_tbl1, @@ -1263,18 +1197,14 @@ alter publication testpub_default add table pub_test.testpub_addpk; insert into pub_test.testpub_addpk values (1, 11); -create unique -index "testpub_addpk_id_idx" -on pub_test.testpub_addpk -using btree -( +create unique index testpub_addpk_id_idx on pub_test.testpub_addpk using btree ( id ); update pub_test.testpub_addpk set id = 2; alter table pub_test.testpub_addpk - add primary key using index "testpub_addpk_id_idx"; + add primary key using index testpub_addpk_id_idx; update pub_test.testpub_addpk set id = 2; @@ -1286,11 +1216,11 @@ create publication testpub2; set role to regress_publication_user; -grant CREATE on database regression to regress_publication_user2; +grant create on database regression to regress_publication_user2; set role to regress_publication_user2; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub2; @@ -1306,7 +1236,7 @@ alter publication testpub3 add tables in schema pub_test; set role to regress_publication_user; -grant REGRESS_PUBLICATION_USER to regress_publication_user2; +grant regress_publication_user to regress_publication_user2; set role to regress_publication_user2; @@ -1320,9 +1250,9 @@ set role to regress_publication_user; create role regress_publication_user3; -grant REGRESS_PUBLICATION_USER2 to regress_publication_user3; +grant regress_publication_user2 to regress_publication_user3; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub4 for tables in schema pub_test; @@ -1342,7 +1272,7 @@ drop publication testpub4; drop role regress_publication_user3; -revoke CREATE on database regression from regress_publication_user2; +revoke create on database regression from regress_publication_user2; drop table testpub_parted; @@ -1360,11 +1290,11 @@ alter publication testpub_foo rename to testpub_default; alter publication testpub_default owner to regress_publication_user2; -create schema "pub_test1"; +create schema pub_test1; -create schema "pub_test2"; +create schema pub_test2; -create schema "pub_test3"; +create schema pub_test3; create schema "CURRENT_SCHEMA"; @@ -1385,7 +1315,7 @@ create table pub_test2.tbl1 ( create table "CURRENT_SCHEMA"."CURRENT_SCHEMA" (id int); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub1_forschema for tables in schema pub_test1; @@ -1475,12 +1405,12 @@ alter publication testpub1_forschema set tables in schema pub_test1; update pub_test1.tbl set id = 2; -create schema "pub_testpart1"; +create schema pub_testpart1; -create schema "pub_testpart2"; +create schema pub_testpart2; create table pub_testpart1.parent1 (a int) -partition by LIST(a); +partition by list(a); create table pub_testpart2.child_parent1 partition of pub_testpart1.parent1 @@ -1490,7 +1420,7 @@ insert into pub_testpart2.child_parent1 values (1); update pub_testpart2.child_parent1 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpubpart_forschema for tables in schema pub_testpart1; @@ -1503,7 +1433,7 @@ update pub_testpart2.child_parent1 set a = 1; drop publication testpubpart_forschema; create table pub_testpart2.parent2 (a int) -partition by LIST(a); +partition by list(a); create table pub_testpart1.child_parent2 partition of pub_testpart2.parent2 @@ -1513,7 +1443,7 @@ insert into pub_testpart1.child_parent2 values (1); update pub_testpart1.child_parent2 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpubpart_forschema for tables in schema pub_testpart2; @@ -1525,7 +1455,7 @@ update pub_testpart2.parent2 set a = 1; update pub_testpart1.child_parent2 set a = 1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub3_forschema; @@ -1533,7 +1463,7 @@ reset client_min_messages; alter publication testpub3_forschema set tables in schema pub_test1; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication testpub_forschema_fortable for tables in schema pub_test1, @@ -1575,11 +1505,11 @@ drop schema pub_testpart1 cascade; drop schema pub_testpart2 cascade; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; -create schema "sch1"; +create schema sch1; -create schema "sch2"; +create schema sch2; create table sch1.tbl1 (a int) partition by range(a); @@ -1644,8 +1574,7 @@ partition by range(a); alter table sch1.tbl1 attach partition - sch1.tbl1_part3 - for values from (20) to (30); + sch1.tbl1_part3 for values from (20) to (30); create publication pub for tables in schema sch1 @@ -1663,7 +1592,7 @@ drop schema sch1 cascade; drop schema sch2 cascade; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication pub1 for all tables with (publish_generated_columns = stored); @@ -1677,18 +1606,15 @@ drop publication pub2; create table gencols ( a int, - gen1 int - generated always as (a * 2) stored + gen1 int generated always as (a * 2) stored ); create publication pub1 -for table gencols (a, -gen1) +for table gencols (a, gen1) with (publish_generated_columns = 'none'); create publication pub2 -for table gencols (a, -gen1) +for table gencols (a, gen1) with (publish_generated_columns = stored); alter publication pub2 set (publish_generated_columns = 'none'); @@ -1720,7 +1646,7 @@ create table testpub_insert_onconfl_part_no_ri partition of testpub_insert_onconfl_parted for values from (1) to (10); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication pub1 for all tables; @@ -1754,7 +1680,7 @@ create table testpub_merge_pk ( b int ); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication pub1 for all tables; @@ -1772,7 +1698,7 @@ drop role regress_publication_user, regress_publication_user2; drop role regress_publication_user_dummy; -create schema "pubme"; +create schema pubme; create table t0 ( c int, @@ -1781,18 +1707,17 @@ create table t0 ( create table t1 (c int); -create schema "pubme2"; +create schema pubme2; create table t0 ( c int, d int ); -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; create publication dump_pub_qual_1ct -for table only pubme.t0 (c, -d) where (c > 0); +for table only pubme.t0 (c, d) where (c > 0); create publication dump_pub_qual_2ct for table only pubme.t0 (c) where (c > 0), diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__random_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__random_100.snap index 4bfc35943..1d7fd49eb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__random_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__random_100.snap @@ -4,31 +4,24 @@ input_file: crates/pgls_pretty_print/tests/data/multi/random.sql --- select r, - COUNT(*) + count(*) from - ( - select random() as r from generate_series(1, 1000) - ) - as ss + (select random() as r from generate_series(1, 1000)) as ss group by r having - COUNT(*) > 1; + count(*) > 1; select - COUNT(*) filter (where r < 0 or r >= 1) - as out_of_range, - COUNT(*) filter (where r < 0.01) > 0 as has_small, - COUNT(*) filter (where r > 0.99) > 0 as has_large + count(*) filter (where r < 0 or r >= 1) as out_of_range, + count(*) filter (where r < 0.01) > 0 as has_small, + count(*) filter (where r > 0.99) > 0 as has_large from - ( - select random() as r from generate_series(1, 2000) - ) - as ss; + (select random() as r from generate_series(1, 2000)) as ss; create function ks_test_uniform_random() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -44,55 +37,37 @@ BEGIN ); RETURN ok; END -$function$; +$$; select ks_test_uniform_random() or ks_test_uniform_random() or ks_test_uniform_random() as uniform; select r, - COUNT(*) + count(*) from - ( - select - random_normal() as r - from - generate_series(1, 1000) - ) - as ss + (select random_normal() as r from generate_series(1, 1000)) as ss group by r having - COUNT(*) > 1; + count(*) > 1; select r, - COUNT(*) + count(*) from - ( - select - random_normal(10, 0) as r - from - generate_series(1, 100) - ) - as ss + (select random_normal(10, 0) as r from generate_series(1, 100)) as ss group by r; select r, - COUNT(*) + count(*) from - ( - select - random_normal(-10, 0) as r - from - generate_series(1, 100) - ) - as ss + (select random_normal(-10, 0) as r from generate_series(1, 100)) as ss group by r; create function ks_test_normal_random() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -109,13 +84,10 @@ BEGIN ); RETURN ok; END -$function$; +$$; select - ks_test_normal_random() or - ks_test_normal_random() or - ks_test_normal_random() - as standard_normal; + ks_test_normal_random() or ks_test_normal_random() or ks_test_normal_random() as standard_normal; select random(1, 0); @@ -139,178 +111,98 @@ select random(3.14, 3.14); select r, - COUNT(*) + count(*) from - ( - select - random(-2147483648, 2147483647) as r - from - generate_series(1, 1000) - ) - as ss + (select random(-2147483648, 2147483647) as r from generate_series(1, 1000)) as ss group by r having - COUNT(*) > 2; + count(*) > 2; select r, - COUNT(*) + count(*) from ( select - random_normal( - -9223372036854775808, - 9223372036854775807 - ) - as r + random_normal(-9223372036854775808, 9223372036854775807) as r from generate_series(1, 1000) ) as ss group by r having - COUNT(*) > 1; + count(*) > 1; select r, - COUNT(*) + count(*) from - ( - select - random_normal(0, 1 - 1e-15) as r - from - generate_series(1, 1000) - ) - as ss + (select random_normal(0, 1 - 1e-15) as r from generate_series(1, 1000)) as ss group by r having - COUNT(*) > 1; + count(*) > 1; select - COUNT(*) filter (where r < -2104533975) > 0 - as has_small, - COUNT(*) filter (where r > 2104533974) > 0 - as has_large + count(*) filter (where r < -2104533975) > 0 as has_small, + count(*) filter (where r > 2104533974) > 0 as has_large from - ( - select - random(-2147483648, 2147483647) as r - from - generate_series(1, 2000) - ) - as ss; + (select random(-2147483648, 2147483647) as r from generate_series(1, 2000)) as ss; select - COUNT( - * - ) - filter (where - r < -1500000000 or r > 1500000000) - as out_of_range, - COUNT(*) filter (where r < -1470000000) > 0 - as has_small, - COUNT(*) filter (where r > 1470000000) > 0 - as has_large + count(*) filter (where r < -1500000000 or r > 1500000000) as out_of_range, + count(*) filter (where r < -1470000000) > 0 as has_small, + count(*) filter (where r > 1470000000) > 0 as has_large from - ( - select - random(-1500000000, 1500000000) as r - from - generate_series(1, 2000) - ) - as ss; + (select random(-1500000000, 1500000000) as r from generate_series(1, 2000)) as ss; select - COUNT(*) filter (where r < -9038904596117680292) > - 0 - as has_small, - COUNT(*) filter (where r > 9038904596117680291) > - 0 - as has_large + count(*) filter (where r < -9038904596117680292) > 0 as has_small, + count(*) filter (where r > 9038904596117680291) > 0 as has_large from ( - select - random(-9223372036854775808, 9223372036854775807) - as r - from - generate_series(1, 2000) + select random(-9223372036854775808, 9223372036854775807) as r from generate_series(1, 2000) ) as ss; select - COUNT( - * - ) - filter (where - r < -1500000000000000 or r > 1500000000000000) - as out_of_range, - COUNT(*) filter (where r < -1470000000000000) > 0 - as has_small, - COUNT(*) filter (where r > 1470000000000000) > 0 - as has_large + count(*) filter (where r < -1500000000000000 or r > 1500000000000000) as out_of_range, + count(*) filter (where r < -1470000000000000) > 0 as has_small, + count(*) filter (where r > 1470000000000000) > 0 as has_large from - ( - select - random(-1500000000000000, 1500000000000000) as r - from - generate_series(1, 2000) - ) - as ss; + (select random(-1500000000000000, 1500000000000000) as r from generate_series(1, 2000)) as ss; select - COUNT(*) filter (where r < -1.5 or r > 1.5) - as out_of_range, - COUNT(*) filter (where r < -1.47) > 0 as has_small, - COUNT(*) filter (where r > 1.47) > 0 as has_large + count(*) filter (where r < -1.5 or r > 1.5) as out_of_range, + count(*) filter (where r < -1.47) > 0 as has_small, + count(*) filter (where r > 1.47) > 0 as has_large from - ( - select - random(-1.500000000000000, 1.500000000000000) as r - from - generate_series(1, 2000) - ) - as ss; + (select random(-1.500000000000000, 1.500000000000000) as r from generate_series(1, 2000)) as ss; select - MIN(r), - MAX(r), - COUNT(r) + min(r), + max(r), + count(r) from - ( - select distinct - random(-50, 49) as r - from - generate_series(1, 2500) - ); + (select distinct random(-50, 49) as r from generate_series(1, 2500)); select - MIN(r), - MAX(r), - COUNT(r) + min(r), + max(r), + count(r) from - ( - select distinct - random(123000000000, 123000000099) as r - from - generate_series(1, 2500) - ); + (select distinct random(123000000000, 123000000099) as r from generate_series(1, 2500)); select - MIN(r), - MAX(r), - COUNT(r) + min(r), + max(r), + count(r) from - ( - select distinct - random(-0.5, 0.49) as r - from - generate_series(1, 2500) - ); + (select distinct random(-0.5, 0.49) as r from generate_series(1, 2500)); create function ks_test_uniform_random_int_in_range() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -326,7 +218,7 @@ BEGIN ); RETURN ok; END -$function$; +$$; select ks_test_uniform_random_int_in_range() or @@ -337,7 +229,7 @@ select create function ks_test_uniform_random_bigint_in_range() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -353,7 +245,7 @@ BEGIN ); RETURN ok; END -$function$; +$$; select ks_test_uniform_random_bigint_in_range() or @@ -364,7 +256,7 @@ select create function ks_test_uniform_random_numeric_in_range() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -380,7 +272,7 @@ BEGIN ); RETURN ok; END -$function$; +$$; select ks_test_uniform_random_numeric_in_range() or @@ -396,7 +288,7 @@ set extra_float_digits = -1; select random_normal() from generate_series(1, 10); -select random_normal("mean" := 1, "stddev" := 0.1) as r from generate_series(1, 10); +select random_normal(mean := 1, stddev := 0.1) as r from generate_series(1, 10); select random(1, 6) from generate_series(1, 10); @@ -415,10 +307,7 @@ select n, random(0, trim_scale(abs(1 - 10.0 ^ -n))) from generate_series(-20, 20 select random(cast('1979-02-08' as date), cast('2025-07-03' as date)) as random_date_multiple_years; select - random( - cast('4714-11-24 BC' as date), - cast('5874897-12-31 AD' as date) - ) + random(cast('4714-11-24 BC' as date), cast('5874897-12-31 AD' as date)) as random_date_maximum_range; select random(cast('1979-02-08' as date), cast('1979-02-08' as date)) as random_date_empty_range; @@ -430,17 +319,11 @@ select random(cast('-infinity' as date), cast('2024-01-01' as date)); select random(cast('2024-12-31' as date), cast('infinity' as date)); select - random( - cast('1979-02-08' as timestamp), - cast('2025-07-03' as timestamp) - ) + random(cast('1979-02-08' as timestamp), cast('2025-07-03' as timestamp)) as random_timestamp_multiple_years; select - random( - cast('4714-11-24 BC' as timestamp), - cast('294276-12-31 23:59:59.999999' as timestamp) - ) + random(cast('4714-11-24 BC' as timestamp), cast('294276-12-31 23:59:59.999999' as timestamp)) as random_timestamp_maximum_range; select @@ -451,10 +334,7 @@ select as random_narrow_range; select - random( - cast('1979-02-08' as timestamp), - cast('1979-02-08' as timestamp) - ) + random(cast('1979-02-08' as timestamp), cast('1979-02-08' as timestamp)) as random_timestamp_empty_range; select random(cast('2024-12-31' as timestamp), cast('2024-01-01' as timestamp)); @@ -464,51 +344,29 @@ select random(cast('-infinity' as timestamp), cast('2024-01-01' as timestamp)); select random(cast('2024-12-31' as timestamp), cast('infinity' as timestamp)); select - random( - cast('1979-02-08 +01' as timestamp with time zone), - cast('2025-07-03 +02' as timestamp with time zone) - ) + random(cast('1979-02-08 +01' as timestamptz), cast('2025-07-03 +02' as timestamptz)) as random_timestamptz_multiple_years; select random( - cast('4714-11-24 BC +00' - as timestamp with time zone), - cast('294276-12-31 23:59:59.999999 +00' - as timestamp with time zone) + cast('4714-11-24 BC +00' as timestamptz), + cast('294276-12-31 23:59:59.999999 +00' as timestamptz) ) as random_timestamptz_maximum_range; select random( - cast('2024-07-01 12:00:00.000001 +04' - as timestamp with time zone), - cast('2024-07-01 12:00:00.999999 +04' - as timestamp with time zone) + cast('2024-07-01 12:00:00.000001 +04' as timestamptz), + cast('2024-07-01 12:00:00.999999 +04' as timestamptz) ) as random_timestamptz_narrow_range; select - random( - cast('1979-02-08 +05' as timestamp with time zone), - cast('1979-02-08 +05' as timestamp with time zone) - ) + random(cast('1979-02-08 +05' as timestamptz), cast('1979-02-08 +05' as timestamptz)) as random_timestamptz_empty_range; -select - random( - cast('2024-01-01 +06' as timestamp with time zone), - cast('2024-01-01 +07' as timestamp with time zone) - ); +select random(cast('2024-01-01 +06' as timestamptz), cast('2024-01-01 +07' as timestamptz)); -select - random( - cast('-infinity' as timestamp with time zone), - cast('2024-01-01 +07' as timestamp with time zone) - ); +select random(cast('-infinity' as timestamptz), cast('2024-01-01 +07' as timestamptz)); -select - random( - cast('2024-01-01 +06' as timestamp with time zone), - cast('infinity' as timestamp with time zone) - ); +select random(cast('2024-01-01 +06' as timestamptz), cast('infinity' as timestamptz)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__random_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__random_80.snap index 6846b2b77..bd0dec632 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__random_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__random_80.snap @@ -4,39 +4,24 @@ input_file: crates/pgls_pretty_print/tests/data/multi/random.sql --- select r, - COUNT(*) + count(*) from - ( - select - random() as r - from - generate_series(1, 1000) - ) - as ss + (select random() as r from generate_series(1, 1000)) as ss group by r having - COUNT(*) > 1; + count(*) > 1; select - COUNT(*) filter (where r < 0 or r >= 1) - as out_of_range, - COUNT(*) filter (where r < 0.01) > 0 - as has_small, - COUNT(*) filter (where r > 0.99) > 0 - as has_large + count(*) filter (where r < 0 or r >= 1) as out_of_range, + count(*) filter (where r < 0.01) > 0 as has_small, + count(*) filter (where r > 0.99) > 0 as has_large from - ( - select - random() as r - from - generate_series(1, 2000) - ) - as ss; + (select random() as r from generate_series(1, 2000)) as ss; create function ks_test_uniform_random() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -52,7 +37,7 @@ BEGIN ); RETURN ok; END -$function$; +$$; select ks_test_uniform_random() or @@ -62,49 +47,31 @@ select select r, - COUNT(*) + count(*) from - ( - select - random_normal() as r - from - generate_series(1, 1000) - ) - as ss + (select random_normal() as r from generate_series(1, 1000)) as ss group by r having - COUNT(*) > 1; + count(*) > 1; select r, - COUNT(*) + count(*) from - ( - select - random_normal(10, 0) as r - from - generate_series(1, 100) - ) - as ss + (select random_normal(10, 0) as r from generate_series(1, 100)) as ss group by r; select r, - COUNT(*) + count(*) from - ( - select - random_normal(-10, 0) as r - from - generate_series(1, 100) - ) - as ss + (select random_normal(-10, 0) as r from generate_series(1, 100)) as ss group by r; create function ks_test_normal_random() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -121,12 +88,10 @@ BEGIN ); RETURN ok; END -$function$; +$$; select - ks_test_normal_random() or - ks_test_normal_random() or - ks_test_normal_random() + ks_test_normal_random() or ks_test_normal_random() or ks_test_normal_random() as standard_normal; select random(1, 0); @@ -151,194 +116,109 @@ select random(3.14, 3.14); select r, - COUNT(*) + count(*) from ( - select - random(-2147483648, 2147483647) as r - from - generate_series(1, 1000) + select random(-2147483648, 2147483647) as r from generate_series(1, 1000) ) as ss group by r having - COUNT(*) > 2; + count(*) > 2; select r, - COUNT(*) + count(*) from ( select - random_normal( - -9223372036854775808, - 9223372036854775807 - ) - as r + random_normal(-9223372036854775808, 9223372036854775807) as r from generate_series(1, 1000) ) as ss group by r having - COUNT(*) > 1; + count(*) > 1; select r, - COUNT(*) + count(*) from - ( - select - random_normal(0, 1 - 1e-15) as r - from - generate_series(1, 1000) - ) - as ss + (select random_normal(0, 1 - 1e-15) as r from generate_series(1, 1000)) as ss group by r having - COUNT(*) > 1; + count(*) > 1; select - COUNT(*) filter (where r < -2104533975) > - 0 - as has_small, - COUNT(*) filter (where r > 2104533974) > - 0 - as has_large + count(*) filter (where r < -2104533975) > 0 as has_small, + count(*) filter (where r > 2104533974) > 0 as has_large from ( - select - random(-2147483648, 2147483647) as r - from - generate_series(1, 2000) + select random(-2147483648, 2147483647) as r from generate_series(1, 2000) ) as ss; select - COUNT( - * - ) - filter (where - r < -1500000000 or r > 1500000000) - as out_of_range, - COUNT(*) filter (where r < -1470000000) > - 0 - as has_small, - COUNT(*) filter (where r > 1470000000) > - 0 - as has_large + count(*) filter (where r < -1500000000 or r > 1500000000) as out_of_range, + count(*) filter (where r < -1470000000) > 0 as has_small, + count(*) filter (where r > 1470000000) > 0 as has_large from ( - select - random(-1500000000, 1500000000) as r - from - generate_series(1, 2000) + select random(-1500000000, 1500000000) as r from generate_series(1, 2000) ) as ss; select - COUNT( - * - ) - filter (where - r < -9038904596117680292) > - 0 - as has_small, - COUNT( - * - ) - filter (where - r > 9038904596117680291) > - 0 - as has_large + count(*) filter (where r < -9038904596117680292) > 0 as has_small, + count(*) filter (where r > 9038904596117680291) > 0 as has_large from ( select - random( - -9223372036854775808, - 9223372036854775807 - ) - as r + random(-9223372036854775808, 9223372036854775807) as r from generate_series(1, 2000) ) as ss; select - COUNT( - * - ) - filter (where - r < -1500000000000000 or - r > 1500000000000000) + count(*) filter (where r < -1500000000000000 or r > 1500000000000000) as out_of_range, - COUNT( - * - ) - filter (where - r < -1470000000000000) > - 0 - as has_small, - COUNT( - * - ) - filter (where - r > 1470000000000000) > - 0 - as has_large + count(*) filter (where r < -1470000000000000) > 0 as has_small, + count(*) filter (where r > 1470000000000000) > 0 as has_large from ( select - random( - -1500000000000000, - 1500000000000000 - ) - as r + random(-1500000000000000, 1500000000000000) as r from generate_series(1, 2000) ) as ss; select - COUNT( - * - ) - filter (where - r < -1.5 or r > 1.5) - as out_of_range, - COUNT(*) filter (where r < -1.47) > 0 - as has_small, - COUNT(*) filter (where r > 1.47) > 0 - as has_large + count(*) filter (where r < -1.5 or r > 1.5) as out_of_range, + count(*) filter (where r < -1.47) > 0 as has_small, + count(*) filter (where r > 1.47) > 0 as has_large from ( select - random( - -1.500000000000000, - 1.500000000000000 - ) - as r + random(-1.500000000000000, 1.500000000000000) as r from generate_series(1, 2000) ) as ss; select - MIN(r), - MAX(r), - COUNT(r) + min(r), + max(r), + count(r) from - ( - select distinct - random(-50, 49) as r - from - generate_series(1, 2500) - ); + (select distinct random(-50, 49) as r from generate_series(1, 2500)); select - MIN(r), - MAX(r), - COUNT(r) + min(r), + max(r), + count(r) from ( select distinct @@ -348,21 +228,16 @@ from ); select - MIN(r), - MAX(r), - COUNT(r) + min(r), + max(r), + count(r) from - ( - select distinct - random(-0.5, 0.49) as r - from - generate_series(1, 2500) - ); + (select distinct random(-0.5, 0.49) as r from generate_series(1, 2500)); create function ks_test_uniform_random_int_in_range() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -378,7 +253,7 @@ BEGIN ); RETURN ok; END -$function$; +$$; select ks_test_uniform_random_int_in_range() or @@ -389,7 +264,7 @@ select create function ks_test_uniform_random_bigint_in_range() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -405,7 +280,7 @@ BEGIN ); RETURN ok; END -$function$; +$$; select ks_test_uniform_random_bigint_in_range() or @@ -416,7 +291,7 @@ select create function ks_test_uniform_random_numeric_in_range() returns boolean language plpgsql -as $function$ +as $$ DECLARE n int := 1000; -- Number of samples c float8 := 1.94947; -- Critical value for 99.9% confidence @@ -432,7 +307,7 @@ BEGIN ); RETURN ok; END -$function$; +$$; select ks_test_uniform_random_numeric_in_range() or @@ -448,24 +323,14 @@ set extra_float_digits = -1; select random_normal() from generate_series(1, 10); -select - random_normal( - "mean" := 1, - "stddev" := 0.1 - ) - as r -from - generate_series(1, 10); +select random_normal(mean := 1, stddev := 0.1) as r from generate_series(1, 10); select random(1, 6) from generate_series(1, 10); select random(-2147483648, 2147483647) from generate_series(1, 10); select - random( - -9223372036854775808, - 9223372036854775807 - ) + random(-9223372036854775808, 9223372036854775807) from generate_series(1, 10); @@ -477,32 +342,20 @@ select random(0, 1 - 1e-30) from generate_series(1, 10); select n, - random( - 0, - trim_scale(abs(1 - 10.0 ^ -n)) - ) + random(0, trim_scale(abs(1 - 10.0 ^ -n))) from generate_series(-20, 20) as n; select - random( - cast('1979-02-08' as date), - cast('2025-07-03' as date) - ) + random(cast('1979-02-08' as date), cast('2025-07-03' as date)) as random_date_multiple_years; select - random( - cast('4714-11-24 BC' as date), - cast('5874897-12-31 AD' as date) - ) + random(cast('4714-11-24 BC' as date), cast('5874897-12-31 AD' as date)) as random_date_maximum_range; select - random( - cast('1979-02-08' as date), - cast('1979-02-08' as date) - ) + random(cast('1979-02-08' as date), cast('1979-02-08' as date)) as random_date_empty_range; select random(cast('2024-12-31' as date), cast('2024-01-01' as date)); @@ -512,34 +365,25 @@ select random(cast('-infinity' as date), cast('2024-01-01' as date)); select random(cast('2024-12-31' as date), cast('infinity' as date)); select - random( - cast('1979-02-08' as timestamp), - cast('2025-07-03' as timestamp) - ) + random(cast('1979-02-08' as timestamp), cast('2025-07-03' as timestamp)) as random_timestamp_multiple_years; select random( cast('4714-11-24 BC' as timestamp), - cast('294276-12-31 23:59:59.999999' - as timestamp) + cast('294276-12-31 23:59:59.999999' as timestamp) ) as random_timestamp_maximum_range; select random( - cast('2024-07-01 12:00:00.000001' - as timestamp), - cast('2024-07-01 12:00:00.999999' - as timestamp) + cast('2024-07-01 12:00:00.000001' as timestamp), + cast('2024-07-01 12:00:00.999999' as timestamp) ) as random_narrow_range; select - random( - cast('1979-02-08' as timestamp), - cast('1979-02-08' as timestamp) - ) + random(cast('1979-02-08' as timestamp), cast('1979-02-08' as timestamp)) as random_timestamp_empty_range; select random(cast('2024-12-31' as timestamp), cast('2024-01-01' as timestamp)); @@ -550,60 +394,46 @@ select random(cast('2024-12-31' as timestamp), cast('infinity' as timestamp)); select random( - cast('1979-02-08 +01' - as timestamp with time zone), - cast('2025-07-03 +02' - as timestamp with time zone) + cast('1979-02-08 +01' as timestamptz), + cast('2025-07-03 +02' as timestamptz) ) as random_timestamptz_multiple_years; select random( - cast('4714-11-24 BC +00' - as timestamp with time zone), - cast('294276-12-31 23:59:59.999999 +00' - as timestamp with time zone) + cast('4714-11-24 BC +00' as timestamptz), + cast('294276-12-31 23:59:59.999999 +00' as timestamptz) ) as random_timestamptz_maximum_range; select random( - cast('2024-07-01 12:00:00.000001 +04' - as timestamp with time zone), - cast('2024-07-01 12:00:00.999999 +04' - as timestamp with time zone) + cast('2024-07-01 12:00:00.000001 +04' as timestamptz), + cast('2024-07-01 12:00:00.999999 +04' as timestamptz) ) as random_timestamptz_narrow_range; select random( - cast('1979-02-08 +05' - as timestamp with time zone), - cast('1979-02-08 +05' - as timestamp with time zone) + cast('1979-02-08 +05' as timestamptz), + cast('1979-02-08 +05' as timestamptz) ) as random_timestamptz_empty_range; select random( - cast('2024-01-01 +06' - as timestamp with time zone), - cast('2024-01-01 +07' - as timestamp with time zone) + cast('2024-01-01 +06' as timestamptz), + cast('2024-01-01 +07' as timestamptz) ); select random( - cast('-infinity' - as timestamp with time zone), - cast('2024-01-01 +07' - as timestamp with time zone) + cast('-infinity' as timestamptz), + cast('2024-01-01 +07' as timestamptz) ); select random( - cast('2024-01-01 +06' - as timestamp with time zone), - cast('infinity' - as timestamp with time zone) + cast('2024-01-01 +06' as timestamptz), + cast('infinity' as timestamptz) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_100.snap index 37d2f0adc..14ebb6298 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_100.snap @@ -16,9 +16,7 @@ insert into rngfunc2 values (1, 111); create function rngfunct(int) returns setof rngfunc2 language sql -as $function$ -SELECT * FROM rngfunc2 WHERE rngfuncid = $1 ORDER BY f2; -$function$; +as 'SELECT * FROM rngfunc2 WHERE rngfuncid = $1 ORDER BY f2;'; select * from rngfunct(1) with ordinality as z (a, b, ord); @@ -30,9 +28,9 @@ select a, ord from unnest(array['a', 'b']) with ordinality as z (a, ord); select * from unnest(array['a', 'b']) with ordinality as z (a, ord); -select a, ord from unnest(array[cast(1.0 as double precision)]) with ordinality as z (a, ord); +select a, ord from unnest(array[cast(1.0 as float8)]) with ordinality as z (a, ord); -select * from unnest(array[cast(1.0 as double precision)]) with ordinality as z (a, ord); +select * from unnest(array[cast(1.0 as float8)]) with ordinality as z (a, ord); select row_to_json(s.*) from generate_series(11, 14) with ordinality as s; @@ -40,10 +38,7 @@ create temporary view vw_ord as select * from - (values (1)) as v (n) - inner join - rngfunct(1) with ordinality as z (a, b, ord) - on n = ord; + (values (1)) as v (n) inner join rngfunct(1) with ordinality as z (a, b, ord) on n = ord; select * from vw_ord; @@ -59,10 +54,7 @@ as select from (values (1)) as v (n) inner join - rows from (rngfunct(1), - rngfunct(2)) - with ordinality - as z (a, b, c, d, ord) + rows from (rngfunct(1), rngfunct(2)) with ordinality as z (a, b, c, d, ord) on n = ord; select * from vw_ord; @@ -76,22 +68,12 @@ select * from unnest(array[10, 20], array['foo', 'bar'], array[1.0]); select * from - unnest( - array[10, 20], - array['foo', 'bar'], - array[1.0] - ) - with ordinality - as z (a, b, c, ord); + unnest(array[10, 20], array['foo', 'bar'], array[1.0]) with ordinality as z (a, b, c, ord); select * from - rows from (unnest( - array[10, 20], - array['foo', 'bar'], - array[1.0] - )) + rows from (unnest(array[10, 20], array['foo', 'bar'], array[1.0])) with ordinality as z (a, b, c, ord); @@ -104,15 +86,7 @@ from as z (a, b, c, ord); create temporary view vw_ord -as select - * -from - unnest( - array[10, 20], - array['foo', 'bar'], - array[1.0] - ) - as z (a, b, c); +as select * from unnest(array[10, 20], array['foo', 'bar'], array[1.0]) as z (a, b, c); select * from vw_ord; @@ -121,15 +95,7 @@ select definition from pg_views where viewname = 'vw_ord'; drop view vw_ord; create temporary view vw_ord -as select - * -from - rows from (unnest( - array[10, 20], - array['foo', 'bar'], - array[1.0] - )) - as z (a, b, c); +as select * from rows from (unnest(array[10, 20], array['foo', 'bar'], array[1.0])) as z (a, b, c); select * from vw_ord; @@ -141,9 +107,7 @@ create temporary view vw_ord as select * from - rows from (unnest(array[10, 20], array['foo', 'bar']), - generate_series(1, 2)) - as z (a, b, c); + rows from (unnest(array[10, 20], array['foo', 'bar']), generate_series(1, 2)) as z (a, b, c); select * from vw_ord; @@ -153,15 +117,12 @@ drop view vw_ord; begin; -declare "rf_cur" scroll +declare rf_cur scroll cursor for select * from - rows from (generate_series(1, 5), - generate_series(1, 2)) - with ordinality - as g (i, j, o);; + rows from (generate_series(1, 5), generate_series(1, 2)) with ordinality as g (i, j, o);; fetch forward all from rf_cur; @@ -197,9 +158,7 @@ select * from rngfunc2, - rngfunct(rngfunc2.rngfuncid) - with ordinality - as z (rngfuncid, f2, ord) + rngfunct(rngfunc2.rngfuncid) with ordinality as z (rngfuncid, f2, ord) where rngfunc2.f2 = z.f2; @@ -208,15 +167,7 @@ select from rngfunc2 where - f2 in - ( - select - f2 - from - rngfunct(rngfunc2.rngfuncid) as z - where - z.rngfuncid = rngfunc2.rngfuncid - ) + f2 in (select f2 from rngfunct(rngfunc2.rngfuncid) as z where z.rngfuncid = rngfunc2.rngfuncid) order by 1, 2; @@ -225,15 +176,7 @@ select from rngfunc2 where - f2 in - ( - select - f2 - from - rngfunct(1) as z - where - z.rngfuncid = rngfunc2.rngfuncid - ) + f2 in (select f2 from rngfunct(1) as z where z.rngfuncid = rngfunc2.rngfuncid) order by 1, 2; @@ -242,15 +185,7 @@ select from rngfunc2 where - f2 in - ( - select - f2 - from - rngfunct(rngfunc2.rngfuncid) as z - where - z.rngfuncid = 1 - ) + f2 in (select f2 from rngfunct(rngfunc2.rngfuncid) as z where z.rngfuncid = 1) order by 1, 2; @@ -272,9 +207,7 @@ insert into rngfunc values (2, 1, 'Mary'); create function getrngfunc1(int) returns int language sql -as $function$ -SELECT $1; -$function$; +as 'SELECT $1;'; select * from getrngfunc1(1) as t1; @@ -288,10 +221,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc1(1) with ordinality as t1 (v, o); +as select * from getrngfunc1(1) with ordinality as t1 (v, o); select * from vw_getrngfunc; @@ -300,9 +230,7 @@ drop view vw_getrngfunc; create function getrngfunc2(int) returns setof int language sql -as $function$ -SELECT rngfuncid FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT rngfuncid FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc2(1) as t1; @@ -316,10 +244,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc2(1) with ordinality as t1 (v, o); +as select * from getrngfunc2(1) with ordinality as t1 (v, o); select * from vw_getrngfunc; @@ -328,9 +253,7 @@ drop view vw_getrngfunc; create function getrngfunc3(int) returns setof text language sql -as $function$ -SELECT rngfuncname FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT rngfuncname FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc3(1) as t1; @@ -344,10 +267,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc3(1) with ordinality as t1 (v, o); +as select * from getrngfunc3(1) with ordinality as t1 (v, o); select * from vw_getrngfunc; @@ -356,9 +276,7 @@ drop view vw_getrngfunc; create function getrngfunc4(int) returns rngfunc language sql -as $function$ -SELECT * FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc4(1) as t1; @@ -372,10 +290,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc4(1) with ordinality as t1 (a, b, c, o); +as select * from getrngfunc4(1) with ordinality as t1 (a, b, c, o); select * from vw_getrngfunc; @@ -384,9 +299,7 @@ drop view vw_getrngfunc; create function getrngfunc5(int) returns setof rngfunc language sql -as $function$ -SELECT * FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc5(1) as t1; @@ -400,10 +313,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc5(1) with ordinality as t1 (a, b, c, o); +as select * from getrngfunc5(1) with ordinality as t1 (a, b, c, o); select * from vw_getrngfunc; @@ -412,28 +322,17 @@ drop view vw_getrngfunc; create function getrngfunc6(int) returns record language sql -as $function$ -SELECT * FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc6(1) as t1 (rngfuncid int, rngfuncsubid int, rngfuncname text); select * from - rows from (getrngfunc6(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text)) - with ordinality; + rows from (getrngfunc6(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text)) with ordinality; create view vw_getrngfunc -as select - * -from - getrngfunc6(1) as - ( - rngfuncid int, - rngfuncsubid int, - rngfuncname text - ); +as select * from getrngfunc6(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text); select * from vw_getrngfunc; @@ -443,8 +342,7 @@ create view vw_getrngfunc as select * from - rows from (getrngfunc6(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text)) - with ordinality; + rows from (getrngfunc6(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text)) with ordinality; select * from vw_getrngfunc; @@ -453,28 +351,17 @@ drop view vw_getrngfunc; create function getrngfunc7(int) returns setof record language sql -as $function$ -SELECT * FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc7(1) as t1 (rngfuncid int, rngfuncsubid int, rngfuncname text); select * from - rows from (getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text)) - with ordinality; + rows from (getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text)) with ordinality; create view vw_getrngfunc -as select - * -from - getrngfunc7(1) as - ( - rngfuncid int, - rngfuncsubid int, - rngfuncname text - ); +as select * from getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text); select * from vw_getrngfunc; @@ -484,8 +371,7 @@ create view vw_getrngfunc as select * from - rows from (getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text)) - with ordinality; + rows from (getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text)) with ordinality; select * from vw_getrngfunc; @@ -494,9 +380,7 @@ drop view vw_getrngfunc; create function getrngfunc8(int) returns int language plpgsql -as $function$ -DECLARE rngfuncint int; BEGIN SELECT rngfuncid into rngfuncint FROM rngfunc WHERE rngfuncid = $1; RETURN rngfuncint; END; -$function$; +as 'DECLARE rngfuncint int; BEGIN SELECT rngfuncid into rngfuncint FROM rngfunc WHERE rngfuncid = $1; RETURN rngfuncint; END;'; select * from getrngfunc8(1) as t1; @@ -510,10 +394,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc8(1) with ordinality as t1 (v, o); +as select * from getrngfunc8(1) with ordinality as t1 (v, o); select * from vw_getrngfunc; @@ -522,9 +403,7 @@ drop view vw_getrngfunc; create function getrngfunc9(int) returns rngfunc language plpgsql -as $function$ -DECLARE rngfunctup rngfunc%ROWTYPE; BEGIN SELECT * into rngfunctup FROM rngfunc WHERE rngfuncid = $1; RETURN rngfunctup; END; -$function$; +as 'DECLARE rngfunctup rngfunc%ROWTYPE; BEGIN SELECT * into rngfunctup FROM rngfunc WHERE rngfuncid = $1; RETURN rngfunctup; END;'; select * from getrngfunc9(1) as t1; @@ -538,10 +417,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc9(1) with ordinality as t1 (a, b, c, o); +as select * from getrngfunc9(1) with ordinality as t1 (a, b, c, o); select * from vw_getrngfunc; @@ -560,27 +436,7 @@ from getrngfunc8(1), getrngfunc9(1)) with ordinality - as t1 - (a, - b, - c, - d, - e, - f, - g, - h, - i, - j, - k, - l, - m, - o, - p, - q, - r, - s, - t, - u); + as t1 (a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, t, u); select * @@ -595,27 +451,7 @@ from getrngfunc2(1), getrngfunc1(1)) with ordinality - as t1 - (a, - b, - c, - d, - e, - f, - g, - h, - i, - j, - k, - l, - m, - o, - p, - q, - r, - s, - t, - u); + as t1 (a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, t, u); create temporary view vw_rngfunc as select @@ -666,16 +502,12 @@ create type rngfunc_rescan_t as (i int, s bigint); create function rngfunc_sql(int, int) returns setof rngfunc_rescan_t language sql -as $function$ -SELECT i, nextval('rngfunc_rescan_seq1') FROM generate_series($1,$2) i; -$function$; +as 'SELECT i, nextval(''rngfunc_rescan_seq1'') FROM generate_series($1,$2) i;'; create function rngfunc_mat(int, int) returns setof rngfunc_rescan_t language plpgsql -as $function$ -begin for i in $1..$2 loop return next (i, nextval('rngfunc_rescan_seq2')); end loop; end; -$function$; +as 'begin for i in $1..$2 loop return next (i, nextval(''rngfunc_rescan_seq2'')); end loop; end;'; select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -712,46 +544,33 @@ select from (values (1), (2), (3)) as v (r) left outer join - rows from (rngfunc_sql(11, 13), - rngfunc_mat(11, 13)) - with ordinality - as f (i1, s1, i2, s2, o) + rows from (rngfunc_sql(11, 13), rngfunc_mat(11, 13)) with ordinality as f (i1, s1, i2, s2, o) on r + i1 + i2 < 100; select * from - (values (1), (2), (3)) as v (r) - left outer join - generate_series(11, 13) as f (i) - on r + i < 100; + (values (1), (2), (3)) as v (r) left outer join generate_series(11, 13) as f (i) on r + i < 100; select * from (values (1), (2), (3)) as v (r) left outer join - generate_series(11, 13) - with ordinality - as f (i, o) + generate_series(11, 13) with ordinality as f (i, o) on r + i < 100; select * from - (values (1), (2), (3)) as v (r) - left outer join - unnest(array[10, 20, 30]) as f (i) - on r + i < 100; + (values (1), (2), (3)) as v (r) left outer join unnest(array[10, 20, 30]) as f (i) on r + i < 100; select * from (values (1), (2), (3)) as v (r) left outer join - unnest(array[10, 20, 30]) - with ordinality - as f (i, o) + unnest(array[10, 20, 30]) with ordinality as f (i, o) on r + i < 100; select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -764,9 +583,7 @@ select * from (values (1), (2), (3)) as v (r), - rngfunc_sql(10 + r, 13) - with ordinality - as f (i, s, o); + rngfunc_sql(10 + r, 13) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -778,9 +595,7 @@ select * from (values (1), (2), (3)) as v (r), - rngfunc_sql(11, 10 + r) - with ordinality - as f (i, s, o); + rngfunc_sql(11, 10 + r) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -791,10 +606,7 @@ select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, select * from - ( - values (11, 12), (13, 15), (16, 20) - ) - as v (r1, r2), + (values (11, 12), (13, 15), (16, 20)) as v (r1, r2), rngfunc_sql(r1, r2) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -807,9 +619,7 @@ select * from (values (1), (2), (3)) as v (r), - rngfunc_mat(10 + r, 13) - with ordinality - as f (i, s, o); + rngfunc_mat(10 + r, 13) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -821,9 +631,7 @@ select * from (values (1), (2), (3)) as v (r), - rngfunc_mat(11, 10 + r) - with ordinality - as f (i, s, o); + rngfunc_mat(11, 10 + r) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -834,10 +642,7 @@ select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, select * from - ( - values (11, 12), (13, 15), (16, 20) - ) - as v (r1, r2), + (values (11, 12), (13, 15), (16, 20)) as v (r1, r2), rngfunc_mat(r1, r2) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -846,8 +651,7 @@ select * from (values (1), (2), (3)) as v (r), - rows from (rngfunc_sql(11, 11), - rngfunc_mat(10 + r, 13)); + rows from (rngfunc_sql(11, 11), rngfunc_mat(10 + r, 13)); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -855,8 +659,7 @@ select * from (values (1), (2), (3)) as v (r), - rows from (rngfunc_sql(10 + r, 13), - rngfunc_mat(11, 11)); + rows from (rngfunc_sql(10 + r, 13), rngfunc_mat(11, 11)); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -864,8 +667,7 @@ select * from (values (1), (2), (3)) as v (r), - rows from (rngfunc_sql(10 + r, 13), - rngfunc_mat(10 + r, 13)); + rows from (rngfunc_sql(10 + r, 13), rngfunc_mat(10 + r, 13)); select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -874,8 +676,7 @@ select from generate_series(1, 2) as r1, generate_series(r1, 3) as r2, - rows from (rngfunc_sql(10 + r1, 13), - rngfunc_mat(10 + r2, 13)); + rows from (rngfunc_sql(10 + r1, 13), rngfunc_mat(10 + r2, 13)); select * from (values (1), (2), (3)) as v (r), generate_series(10 + r, 20 - r) as f (i); @@ -883,9 +684,7 @@ select * from (values (1), (2), (3)) as v (r), - generate_series(10 + r, 20 - r) - with ordinality - as f (i, o); + generate_series(10 + r, 20 - r) with ordinality as f (i, o); select * from (values (1), (2), (3)) as v (r), unnest(array[r * 10, r * 20, r * 30]) as f (i); @@ -893,9 +692,7 @@ select * from (values (1), (2), (3)) as v (r), - unnest(array[r * 10, r * 20, r * 30]) - with ordinality - as f (i, o); + unnest(array[r * 10, r * 20, r * 30]) with ordinality as f (i, o); select * @@ -980,10 +777,7 @@ from select * from - generate_series(1, gs1) as gs2 - left outer join - generate_series(1, gs2) as gs3 - on true + generate_series(1, gs1) as gs2 left outer join generate_series(1, gs2) as gs3 on true ) as ss1 on true @@ -1004,9 +798,7 @@ drop sequence rngfunc_rescan_seq2; create function rngfunc(in f1 int, out f2 int) language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; select rngfunc(42); @@ -1017,36 +809,26 @@ select * from rngfunc(42) as p (x); create or replace function rngfunc(in f1 int, out f2 int) returns int language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; create or replace function rngfunc(in f1 int, out f2 int) returns double precision language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; create or replace function rngfunc(in f1 int, out f2 int, out f3 text) returns int language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; create or replace function rngfunc(in f1 int, out f2 int, out f3 text) returns record language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; create or replace function rngfuncr(in f1 int, out f2 int, out text) language sql -as $function$ -select $1-1, $1::text || 'z' -$function$; +as $$select $1-1, $1::text || 'z'$$; select f1, rngfuncr(f1) from int4_tbl; @@ -1056,9 +838,7 @@ select * from rngfuncr(42) as p (a, b); create or replace function rngfuncb(in f1 int, inout f2 int, out text) language sql -as $function$ -select $2-1, $1::text || 'z' -$function$; +as $$select $2-1, $1::text || 'z'$$; select f1, rngfuncb(f1, f1 / 2) from int4_tbl; @@ -1068,15 +848,13 @@ select * from rngfuncb(42, 99) as p (a, b); drop function rngfunc(int); -drop function rngfuncr(int); +drop function rngfuncr(in f2 int, out f1 int, out text); -drop function rngfuncb(int, int); +drop function rngfuncb(in f1 int, inout f2 int); create function dup(f1 anyelement, out f2 anyelement, out f3 anyarray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; select dup(22); @@ -1088,17 +866,13 @@ select * from dup(cast('xyz' as text)); create or replace function dup(inout f2 anyelement, out f3 anyarray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; drop function dup(anyelement); create or replace function dup(inout f2 anyelement, out f3 anyarray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; select dup(22); @@ -1106,9 +880,7 @@ drop function dup(anyelement); create function bad(f1 int, out f2 anyelement, out f3 anyarray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; create function dup( @@ -1118,9 +890,7 @@ dup( out f4 anycompatiblearray ) language sql -as $function$ -select $1, $2 -$function$; +as 'select $1, $2'; select dup(22, array[44]); @@ -1130,7 +900,7 @@ select dup(22, array[cast(44 as bigint)]); select *, pg_typeof(f3), pg_typeof(f4) from dup(22, array[cast(44 as bigint)]); -drop function dup(anycompatible, anycompatiblearray); +drop function dup(f1 anycompatible, f2 anycompatiblearray); create function dup( @@ -1140,9 +910,7 @@ dup( out f4 anycompatiblerange ) language sql -as $function$ -select lower($1), array[lower($1), upper($1)], $1 -$function$; +as 'select lower($1), array[lower($1), upper($1)], $1'; select dup(int4range(4, 7)); @@ -1150,22 +918,18 @@ select dup(numrange(4, 7)); select dup(textrange('aaa', 'bbb')); -drop function dup(anycompatiblerange); +drop function dup(f1 anycompatiblerange); create function bad(f1 anyarray, out f2 anycompatible, out f3 anycompatiblearray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; create or replace function rngfunc() returns table ( a int ) language sql -as $function$ -SELECT a FROM generate_series(1,5) a(a) -$function$; +as $$ SELECT a FROM generate_series(1,5) a(a) $$; select * from rngfunc(); @@ -1177,11 +941,9 @@ returns table ( b int ) language sql -as $function$ -SELECT a, b +as $$ SELECT a, b FROM generate_series(1,$1) a(a), - generate_series(1,$1) b(b) -$function$; + generate_series(1,$1) b(b) $$; select * from rngfunc(3); @@ -1193,9 +955,7 @@ returns table ( ) language sql stable -as $function$ -SELECT 'hello'::varchar(5) -$function$; +as $$ SELECT 'hello'::varchar(5) $$; select * from rngfunc() group by 1; @@ -1209,9 +969,7 @@ create temporary table tt ( create function insert_tt(text) returns int language sql -as $function$ -insert into tt(data) values($1) returning f1 -$function$; +as $$ insert into tt(data) values($1) returning f1 $$; select insert_tt('foo'); @@ -1222,9 +980,7 @@ select * from tt; create or replace function insert_tt(text) returns int language sql -as $function$ -insert into tt(data) values($1),($1||$1) returning f1 -$function$; +as $$ insert into tt(data) values($1),($1||$1) returning f1 $$; select insert_tt('fool'); @@ -1233,9 +989,7 @@ select * from tt; create or replace function insert_tt2(text, text) returns setof int language sql -as $function$ -insert into tt(data) values($1),($2) returning f1 -$function$; +as $$ insert into tt(data) values($1),($2) returning f1 $$; select insert_tt2('foolish', 'barrish'); @@ -1250,12 +1004,11 @@ select * from tt; create function noticetrigger() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'noticetrigger % %', new.f1, new.data; return null; -end -$function$; +end $$; create trigger tnoticetrigger after insert on tt for each row execute function noticetrigger(); @@ -1282,9 +1035,7 @@ select * from tt_log; create function rngfunc1(n int, out a text, out b text) returns setof record language sql -as $function$ -select 'foo ' || i, 'bar ' || i from generate_series(1,$1) i -$function$; +as $$ select 'foo ' || i, 'bar ' || i from generate_series(1,$1) i $$; set work_mem = '64kB'; @@ -1294,16 +1045,16 @@ reset work_mem; select t.a, t, t.a from rngfunc1(10000) as t limit 1; -drop function rngfunc1(int); +drop function rngfunc1(n int); create function array_to_set(anyarray) returns setof record language sql immutable strict -as $function$ -select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i -$function$; +as $$ + select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i +$$; select array_to_set(array['one', 'two']); @@ -1321,9 +1072,9 @@ create or replace function array_to_set(anyarray) returns setof record language sql immutable -as $function$ -select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i -$function$; +as $$ + select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i +$$; select array_to_set(array['one', 'two']); @@ -1336,20 +1087,20 @@ select * from array_to_set(array['one', 'two']) as t (f1 point, f2 text); select * from array_to_set(array['one', 'two']) as t (f1 numeric(4, 2), f2 text); create temporary table rngfunc ( - f1 bigint, - f2 bigint + f1 int8, + f2 int8 ); create function testrngfunc() returns record language sql -as $function$ -insert into rngfunc values (1,2) returning *; -$function$; +as $$ + insert into rngfunc values (1,2) returning *; +$$; select testrngfunc(); -select * from testrngfunc() as t (f1 bigint, f2 bigint); +select * from testrngfunc() as t (f1 int8, f2 int8); select * from testrngfunc(); @@ -1358,13 +1109,13 @@ drop function testrngfunc(); create function testrngfunc() returns setof record language sql -as $function$ -insert into rngfunc values (1,2), (3,4) returning *; -$function$; +as $$ + insert into rngfunc values (1,2), (3,4) returning *; +$$; select testrngfunc(); -select * from testrngfunc() as t (f1 bigint, f2 bigint); +select * from testrngfunc() as t (f1 int8, f2 int8); select * from testrngfunc(); @@ -1376,9 +1127,9 @@ create function testrngfunc() returns rngfunc_type language sql immutable -as $function$ -select 7.136178319899999964, 7.136178319899999964; -$function$; +as $$ + select 7.136178319899999964, 7.136178319899999964; +$$; select testrngfunc(); @@ -1392,9 +1143,9 @@ create or replace function testrngfunc() returns rngfunc_type language sql volatile -as $function$ -select 7.136178319899999964, 7.136178319899999964; -$function$; +as $$ + select 7.136178319899999964, 7.136178319899999964; +$$; select testrngfunc(); @@ -1410,9 +1161,9 @@ create function testrngfunc() returns setof rngfunc_type language sql immutable -as $function$ -select 7.136178319899999964, 7.136178319899999964; -$function$; +as $$ + select 7.136178319899999964, 7.136178319899999964; +$$; select testrngfunc(); @@ -1426,9 +1177,9 @@ create or replace function testrngfunc() returns setof rngfunc_type language sql volatile -as $function$ -select 7.136178319899999964, 7.136178319899999964; -$function$; +as $$ + select 7.136178319899999964, 7.136178319899999964; +$$; select testrngfunc(); @@ -1442,9 +1193,9 @@ create or replace function testrngfunc() returns setof rngfunc_type language sql immutable -as $function$ -select 1, 2 union select 3, 4 order by 1; -$function$; +as $$ + select 1, 2 union select 3, 4 order by 1; +$$; select testrngfunc(); @@ -1454,11 +1205,11 @@ select * from testrngfunc(); select * from testrngfunc(); -select * from testrngfunc() as t (f1 bigint, f2 bigint); +select * from testrngfunc() as t (f1 int8, f2 int8); -select * from pg_get_keywords() as t (f1 bigint, f2 bigint); +select * from pg_get_keywords() as t (f1 int8, f2 int8); -select * from sin(3) as t (f1 bigint, f2 bigint); +select * from sin(3) as t (f1 int8, f2 int8); drop type rngfunc_type cascade; @@ -1466,9 +1217,9 @@ create temporary table users ( userid text, seq int, email text, - todrop boolean, + todrop bool, moredrop int, - enabled boolean + enabled bool ); insert into users values ('id', 1, 'email', true, 11, true); @@ -1482,9 +1233,7 @@ create or replace function get_first_user() returns users language sql stable -as $function$ -SELECT * FROM users ORDER BY userid LIMIT 1; -$function$; +as $$ SELECT * FROM users ORDER BY userid LIMIT 1; $$; select get_first_user(); @@ -1494,9 +1243,7 @@ create or replace function get_users() returns setof users language sql stable -as $function$ -SELECT * FROM users ORDER BY userid; -$function$; +as $$ SELECT * FROM users ORDER BY userid; $$; select get_users(); @@ -1509,12 +1256,7 @@ select * from rows from (generate_series(10, 11), get_users()) with ordinality; select * from rows from (get_users(), generate_series(10, 11)) with ordinality; create temporary view usersview -as select - * -from - rows from (get_users(), - generate_series(10, 11)) - with ordinality; +as select * from rows from (get_users(), generate_series(10, 11)) with ordinality; select * from usersview; @@ -1537,18 +1279,11 @@ where from pg_rewrite where - ev_class = cast('usersview' as regclass) and - rulename = '_RETURN' + ev_class = cast('usersview' as regclass) and rulename = '_RETURN' ) and refobjsubid = 5 -returning pg_describe_object(classid, objid, objsubid) -as obj, -pg_describe_object( - refclassid, - refobjid, - refobjsubid -) -as ref, +returning pg_describe_object(classid, objid, objsubid) as obj, +pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype; alter table users @@ -1572,18 +1307,11 @@ where from pg_rewrite where - ev_class = cast('usersview' as regclass) and - rulename = '_RETURN' + ev_class = cast('usersview' as regclass) and rulename = '_RETURN' ) and refobjsubid = 2 -returning pg_describe_object(classid, objid, objsubid) -as obj, -pg_describe_object( - refclassid, - refobjid, - refobjsubid -) -as ref, +returning pg_describe_object(classid, objid, objsubid) as obj, +pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype; alter table users @@ -1605,9 +1333,7 @@ create or replace function rngfuncbar() returns setof text language sql stable -as $function$ -select 'foo'::varchar union all select 'bar'::varchar ; -$function$; +as $$ select 'foo'::varchar union all select 'bar'::varchar ; $$; select rngfuncbar(); @@ -1619,37 +1345,31 @@ drop function rngfuncbar(); create or replace function rngfuncbar(out int, out numeric) language sql -as $function$ -select (1, 2.1) -$function$; +as $$ select (1, 2.1) $$; select * from rngfuncbar(); create or replace function rngfuncbar(out int, out numeric) language sql -as $function$ -select (1, 2) -$function$; +as $$ select (1, 2) $$; select * from rngfuncbar(); create or replace function rngfuncbar(out int, out numeric) language sql -as $function$ -select (1, 2.1, 3) -$function$; +as $$ select (1, 2.1, 3) $$; select * from rngfuncbar(); drop function rngfuncbar(); create function extractq2(t int8_tbl) -returns bigint +returns int8 language sql immutable -as $function$ -select t.q2 -$function$; +as $$ + select t.q2 +$$; select x from int8_tbl, extractq2(int8_tbl) as f (x); @@ -1657,13 +1377,13 @@ select x from int8_tbl, extractq2(int8_tbl) as f (x); create function extractq2_2(t int8_tbl) returns table ( - ret1 bigint + ret1 int8 ) language sql immutable -as $function$ -select extractq2(t) offset 0 -$function$; +as $$ + select extractq2(t) offset 0 +$$; select x from int8_tbl, extractq2_2(int8_tbl) as f (x); @@ -1671,13 +1391,13 @@ select x from int8_tbl, extractq2_2(int8_tbl) as f (x); create function extractq2_2_opt(t int8_tbl) returns table ( - ret1 bigint + ret1 int8 ) language sql immutable -as $function$ -select extractq2(t) -$function$; +as $$ + select extractq2(t) +$$; select x from int8_tbl, extractq2_2_opt(int8_tbl) as f (x); @@ -1689,11 +1409,7 @@ select *, row_to_json(u) from - unnest( - array[cast((1, 'foo') as rngfunc2), - cast(null as rngfunc2)] - ) - as u; + unnest(array[cast((1, 'foo') as rngfunc2), cast(null as rngfunc2)]) as u; select *, row_to_json(u) from unnest(array[cast(null as rngfunc2), cast(null as rngfunc2)]) as u; @@ -1701,12 +1417,7 @@ select *, row_to_json(u) from - unnest( - array[cast(null as rngfunc2), - cast((1, 'foo') as rngfunc2), - cast(null as rngfunc2)] - ) - as u; + unnest(array[cast(null as rngfunc2), cast((1, 'foo') as rngfunc2), cast(null as rngfunc2)]) as u; select *, row_to_json(u) from unnest(cast(array[] as rngfunc2[])) as u; @@ -1717,16 +1428,9 @@ select from ( select - jsonb_path_query_array( - module -> 'lectures', - '$[*]' - ) - as lecture + jsonb_path_query_array(module -> 'lectures', '$[*]') as lecture from - unnest( - array[cast('{"lectures": [{"id": "1"}]}' as jsonb)] - ) - as unnested_modules (module) + unnest(array[cast('{"lectures": [{"id": "1"}]}' as jsonb)]) as unnested_modules (module) ) as ss, jsonb_to_recordset(ss.lecture) as j (id text); @@ -1736,16 +1440,9 @@ select from ( select - jsonb_path_query_array( - module -> 'lectures', - '$[*]' - ) - as lecture + jsonb_path_query_array(module -> 'lectures', '$[*]') as lecture from - unnest( - array[cast('{"lectures": [{"id": "1"}]}' as jsonb)] - ) - as unnested_modules (module) + unnest(array[cast('{"lectures": [{"id": "1"}]}' as jsonb)]) as unnested_modules (module) ) as ss, jsonb_to_recordset(ss.lecture) as j (id text); @@ -1764,8 +1461,6 @@ select * from a, - coalesce(b) - as c - (d int, e int, f double precision); + coalesce(b) as c (d int, e int, f double precision); select * from int8_tbl, coalesce(row(1)) as (a int, b int); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_80.snap index 3cf388bae..b0bae436d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_80.snap @@ -16,9 +16,7 @@ insert into rngfunc2 values (1, 111); create function rngfunct(int) returns setof rngfunc2 language sql -as $function$ -SELECT * FROM rngfunc2 WHERE rngfuncid = $1 ORDER BY f2; -$function$; +as 'SELECT * FROM rngfunc2 WHERE rngfuncid = $1 ORDER BY f2;'; select * from rngfunct(1) with ordinality as z (a, b, ord); @@ -34,20 +32,9 @@ select a, ord from - unnest( - array[cast(1.0 as double precision)] - ) - with ordinality - as z (a, ord); + unnest(array[cast(1.0 as float8)]) with ordinality as z (a, ord); -select - * -from - unnest( - array[cast(1.0 as double precision)] - ) - with ordinality - as z (a, ord); +select * from unnest(array[cast(1.0 as float8)]) with ordinality as z (a, ord); select row_to_json(s.*) from generate_series(11, 14) with ordinality as s; @@ -57,9 +44,7 @@ as select from (values (1)) as v (n) inner join - rngfunct(1) - with ordinality - as z (a, b, ord) + rngfunct(1) with ordinality as z (a, b, ord) on n = ord; select * from vw_ord; @@ -71,10 +56,7 @@ drop view vw_ord; select * from - rows from (rngfunct(1), - rngfunct(2)) - with ordinality - as z (a, b, c, d, ord); + rows from (rngfunct(1), rngfunct(2)) with ordinality as z (a, b, c, d, ord); create temporary view vw_ord as select @@ -82,10 +64,7 @@ as select from (values (1)) as v (n) inner join - rows from (rngfunct(1), - rngfunct(2)) - with ordinality - as z (a, b, c, d, ord) + rows from (rngfunct(1), rngfunct(2)) with ordinality as z (a, b, c, d, ord) on n = ord; select * from vw_ord; @@ -99,32 +78,21 @@ select * from unnest(array[10, 20], array['foo', 'bar'], array[1.0]); select * from - unnest( - array[10, 20], - array['foo', 'bar'], - array[1.0] - ) + unnest(array[10, 20], array['foo', 'bar'], array[1.0]) with ordinality as z (a, b, c, ord); select * from - rows from (unnest( - array[10, 20], - array['foo', 'bar'], - array[1.0] - )) + rows from (unnest(array[10, 20], array['foo', 'bar'], array[1.0])) with ordinality as z (a, b, c, ord); select * from - rows from (unnest( - array[10, 20], - array['foo', 'bar'] - ), + rows from (unnest(array[10, 20], array['foo', 'bar']), generate_series(101, 102)) with ordinality as z (a, b, c, ord); @@ -133,12 +101,7 @@ create temporary view vw_ord as select * from - unnest( - array[10, 20], - array['foo', 'bar'], - array[1.0] - ) - as z (a, b, c); + unnest(array[10, 20], array['foo', 'bar'], array[1.0]) as z (a, b, c); select * from vw_ord; @@ -150,11 +113,7 @@ create temporary view vw_ord as select * from - rows from (unnest( - array[10, 20], - array['foo', 'bar'], - array[1.0] - )) + rows from (unnest(array[10, 20], array['foo', 'bar'], array[1.0])) as z (a, b, c); select * from vw_ord; @@ -167,10 +126,7 @@ create temporary view vw_ord as select * from - rows from (unnest( - array[10, 20], - array['foo', 'bar'] - ), + rows from (unnest(array[10, 20], array['foo', 'bar']), generate_series(1, 2)) as z (a, b, c); @@ -182,7 +138,7 @@ drop view vw_ord; begin; -declare "rf_cur" scroll +declare rf_cur scroll cursor for select * @@ -232,9 +188,7 @@ select * from rngfunc2, - rngfunct(rngfunc2.rngfuncid) - with ordinality - as z (rngfuncid, f2, ord) + rngfunct(rngfunc2.rngfuncid) with ordinality as z (rngfuncid, f2, ord) where rngfunc2.f2 = z.f2; @@ -260,15 +214,7 @@ select from rngfunc2 where - f2 in - ( - select - f2 - from - rngfunct(1) as z - where - z.rngfuncid = rngfunc2.rngfuncid - ) + f2 in (select f2 from rngfunct(1) as z where z.rngfuncid = rngfunc2.rngfuncid) order by 1, 2; @@ -277,15 +223,7 @@ select from rngfunc2 where - f2 in - ( - select - f2 - from - rngfunct(rngfunc2.rngfuncid) as z - where - z.rngfuncid = 1 - ) + f2 in (select f2 from rngfunct(rngfunc2.rngfuncid) as z where z.rngfuncid = 1) order by 1, 2; @@ -313,9 +251,7 @@ insert into rngfunc values (2, 1, 'Mary'); create function getrngfunc1(int) returns int language sql -as $function$ -SELECT $1; -$function$; +as 'SELECT $1;'; select * from getrngfunc1(1) as t1; @@ -329,12 +265,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc1(1) - with ordinality - as t1 (v, o); +as select * from getrngfunc1(1) with ordinality as t1 (v, o); select * from vw_getrngfunc; @@ -343,9 +274,7 @@ drop view vw_getrngfunc; create function getrngfunc2(int) returns setof int language sql -as $function$ -SELECT rngfuncid FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT rngfuncid FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc2(1) as t1; @@ -359,12 +288,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc2(1) - with ordinality - as t1 (v, o); +as select * from getrngfunc2(1) with ordinality as t1 (v, o); select * from vw_getrngfunc; @@ -373,9 +297,7 @@ drop view vw_getrngfunc; create function getrngfunc3(int) returns setof text language sql -as $function$ -SELECT rngfuncname FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT rngfuncname FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc3(1) as t1; @@ -389,12 +311,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc3(1) - with ordinality - as t1 (v, o); +as select * from getrngfunc3(1) with ordinality as t1 (v, o); select * from vw_getrngfunc; @@ -403,9 +320,7 @@ drop view vw_getrngfunc; create function getrngfunc4(int) returns rngfunc language sql -as $function$ -SELECT * FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc4(1) as t1; @@ -419,12 +334,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc4(1) - with ordinality - as t1 (a, b, c, o); +as select * from getrngfunc4(1) with ordinality as t1 (a, b, c, o); select * from vw_getrngfunc; @@ -433,9 +343,7 @@ drop view vw_getrngfunc; create function getrngfunc5(int) returns setof rngfunc language sql -as $function$ -SELECT * FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; select * from getrngfunc5(1) as t1; @@ -449,12 +357,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc5(1) - with ordinality - as t1 (a, b, c, o); +as select * from getrngfunc5(1) with ordinality as t1 (a, b, c, o); select * from vw_getrngfunc; @@ -463,39 +366,26 @@ drop view vw_getrngfunc; create function getrngfunc6(int) returns record language sql -as $function$ -SELECT * FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; select * from - getrngfunc6(1) - as t1 - ( - rngfuncid int, - rngfuncsubid int, - rngfuncname text - ); + getrngfunc6(1) as t1 (rngfuncid int, rngfuncsubid int, rngfuncname text); select * from - rows from (getrngfunc6(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text)) + rows from (getrngfunc6(1) as ( + rngfuncid int, rngfuncsubid int, rngfuncname text + )) with ordinality; create view vw_getrngfunc as select * from - getrngfunc6(1) as - ( - rngfuncid int, - rngfuncsubid int, - rngfuncname text - ); + getrngfunc6(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text); select * from vw_getrngfunc; @@ -505,9 +395,9 @@ create view vw_getrngfunc as select * from - rows from (getrngfunc6(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text)) + rows from (getrngfunc6(1) as ( + rngfuncid int, rngfuncsubid int, rngfuncname text + )) with ordinality; select * from vw_getrngfunc; @@ -517,39 +407,26 @@ drop view vw_getrngfunc; create function getrngfunc7(int) returns setof record language sql -as $function$ -SELECT * FROM rngfunc WHERE rngfuncid = $1; -$function$; +as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; select * from - getrngfunc7(1) - as t1 - ( - rngfuncid int, - rngfuncsubid int, - rngfuncname text - ); + getrngfunc7(1) as t1 (rngfuncid int, rngfuncsubid int, rngfuncname text); select * from - rows from (getrngfunc7(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text)) + rows from (getrngfunc7(1) as ( + rngfuncid int, rngfuncsubid int, rngfuncname text + )) with ordinality; create view vw_getrngfunc as select * from - getrngfunc7(1) as - ( - rngfuncid int, - rngfuncsubid int, - rngfuncname text - ); + getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text); select * from vw_getrngfunc; @@ -559,9 +436,9 @@ create view vw_getrngfunc as select * from - rows from (getrngfunc7(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text)) + rows from (getrngfunc7(1) as ( + rngfuncid int, rngfuncsubid int, rngfuncname text + )) with ordinality; select * from vw_getrngfunc; @@ -571,9 +448,7 @@ drop view vw_getrngfunc; create function getrngfunc8(int) returns int language plpgsql -as $function$ -DECLARE rngfuncint int; BEGIN SELECT rngfuncid into rngfuncint FROM rngfunc WHERE rngfuncid = $1; RETURN rngfuncint; END; -$function$; +as 'DECLARE rngfuncint int; BEGIN SELECT rngfuncid into rngfuncint FROM rngfunc WHERE rngfuncid = $1; RETURN rngfuncint; END;'; select * from getrngfunc8(1) as t1; @@ -587,12 +462,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc8(1) - with ordinality - as t1 (v, o); +as select * from getrngfunc8(1) with ordinality as t1 (v, o); select * from vw_getrngfunc; @@ -601,9 +471,7 @@ drop view vw_getrngfunc; create function getrngfunc9(int) returns rngfunc language plpgsql -as $function$ -DECLARE rngfunctup rngfunc%ROWTYPE; BEGIN SELECT * into rngfunctup FROM rngfunc WHERE rngfuncid = $1; RETURN rngfunctup; END; -$function$; +as 'DECLARE rngfunctup rngfunc%ROWTYPE; BEGIN SELECT * into rngfunctup FROM rngfunc WHERE rngfuncid = $1; RETURN rngfunctup; END;'; select * from getrngfunc9(1) as t1; @@ -617,12 +485,7 @@ select * from vw_getrngfunc; drop view vw_getrngfunc; create view vw_getrngfunc -as select - * -from - getrngfunc9(1) - with ordinality - as t1 (a, b, c, o); +as select * from getrngfunc9(1) with ordinality as t1 (a, b, c, o); select * from vw_getrngfunc; @@ -636,84 +499,34 @@ from getrngfunc3(1), getrngfunc4(1), getrngfunc5(1), - getrngfunc6(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text), - getrngfunc7(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text), + getrngfunc6(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text), + getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text), getrngfunc8(1), getrngfunc9(1)) with ordinality - as t1 - (a, - b, - c, - d, - e, - f, - g, - h, - i, - j, - k, - l, - m, - o, - p, - q, - r, - s, - t, - u); + as t1 (a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, t, u); select * from rows from (getrngfunc9(1), getrngfunc8(1), - getrngfunc7(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text), - getrngfunc6(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text), + getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text), + getrngfunc6(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text), getrngfunc5(1), getrngfunc4(1), getrngfunc3(1), getrngfunc2(1), getrngfunc1(1)) with ordinality - as t1 - (a, - b, - c, - d, - e, - f, - g, - h, - i, - j, - k, - l, - m, - o, - p, - q, - r, - s, - t, - u); + as t1 (a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, t, u); create temporary view vw_rngfunc as select * from rows from (getrngfunc9(1), - getrngfunc7(1) as (rngfuncid int, - rngfuncsubid int, - rngfuncname text), + getrngfunc7(1) as (rngfuncid int, rngfuncsubid int, rngfuncname text), getrngfunc1(1)) with ordinality as t1 (a, b, c, d, e, f, g, n); @@ -757,16 +570,12 @@ create type rngfunc_rescan_t as (i int, s bigint); create function rngfunc_sql(int, int) returns setof rngfunc_rescan_t language sql -as $function$ -SELECT i, nextval('rngfunc_rescan_seq1') FROM generate_series($1,$2) i; -$function$; +as 'SELECT i, nextval(''rngfunc_rescan_seq1'') FROM generate_series($1,$2) i;'; create function rngfunc_mat(int, int) returns setof rngfunc_rescan_t language plpgsql -as $function$ -begin for i in $1..$2 loop return next (i, nextval('rngfunc_rescan_seq2')); end loop; end; -$function$; +as 'begin for i in $1..$2 loop return next (i, nextval(''rngfunc_rescan_seq2'')); end loop; end;'; select setval('rngfunc_rescan_seq1', 1, false), @@ -789,9 +598,7 @@ select from (values (1), (2), (3)) as v (r) left outer join - rngfunc_sql(11, 13) - with ordinality - as f (i, s, o) + rngfunc_sql(11, 13) with ordinality as f (i, s, o) on r + i < 100; select @@ -815,9 +622,7 @@ select from (values (1), (2), (3)) as v (r) left outer join - rngfunc_mat(11, 13) - with ordinality - as f (i, s, o) + rngfunc_mat(11, 13) with ordinality as f (i, s, o) on r + i < 100; select @@ -848,9 +653,7 @@ select from (values (1), (2), (3)) as v (r) left outer join - generate_series(11, 13) - with ordinality - as f (i, o) + generate_series(11, 13) with ordinality as f (i, o) on r + i < 100; select @@ -866,9 +669,7 @@ select from (values (1), (2), (3)) as v (r) left outer join - unnest(array[10, 20, 30]) - with ordinality - as f (i, o) + unnest(array[10, 20, 30]) with ordinality as f (i, o) on r + i < 100; select @@ -885,9 +686,7 @@ select * from (values (1), (2), (3)) as v (r), - rngfunc_sql(10 + r, 13) - with ordinality - as f (i, s, o); + rngfunc_sql(10 + r, 13) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), @@ -903,9 +702,7 @@ select * from (values (1), (2), (3)) as v (r), - rngfunc_sql(11, 10 + r) - with ordinality - as f (i, s, o); + rngfunc_sql(11, 10 + r) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), @@ -914,10 +711,7 @@ select select * from - ( - values (11, 12), (13, 15), (16, 20) - ) - as v (r1, r2), + (values (11, 12), (13, 15), (16, 20)) as v (r1, r2), rngfunc_sql(r1, r2); select @@ -927,13 +721,8 @@ select select * from - ( - values (11, 12), (13, 15), (16, 20) - ) - as v (r1, r2), - rngfunc_sql(r1, r2) - with ordinality - as f (i, s, o); + (values (11, 12), (13, 15), (16, 20)) as v (r1, r2), + rngfunc_sql(r1, r2) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), @@ -949,9 +738,7 @@ select * from (values (1), (2), (3)) as v (r), - rngfunc_mat(10 + r, 13) - with ordinality - as f (i, s, o); + rngfunc_mat(10 + r, 13) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), @@ -967,9 +754,7 @@ select * from (values (1), (2), (3)) as v (r), - rngfunc_mat(11, 10 + r) - with ordinality - as f (i, s, o); + rngfunc_mat(11, 10 + r) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), @@ -978,10 +763,7 @@ select select * from - ( - values (11, 12), (13, 15), (16, 20) - ) - as v (r1, r2), + (values (11, 12), (13, 15), (16, 20)) as v (r1, r2), rngfunc_mat(r1, r2); select @@ -991,13 +773,8 @@ select select * from - ( - values (11, 12), (13, 15), (16, 20) - ) - as v (r1, r2), - rngfunc_mat(r1, r2) - with ordinality - as f (i, s, o); + (values (11, 12), (13, 15), (16, 20)) as v (r1, r2), + rngfunc_mat(r1, r2) with ordinality as f (i, s, o); select setval('rngfunc_rescan_seq1', 1, false), @@ -1007,8 +784,7 @@ select * from (values (1), (2), (3)) as v (r), - rows from (rngfunc_sql(11, 11), - rngfunc_mat(10 + r, 13)); + rows from (rngfunc_sql(11, 11), rngfunc_mat(10 + r, 13)); select setval('rngfunc_rescan_seq1', 1, false), @@ -1018,8 +794,7 @@ select * from (values (1), (2), (3)) as v (r), - rows from (rngfunc_sql(10 + r, 13), - rngfunc_mat(11, 11)); + rows from (rngfunc_sql(10 + r, 13), rngfunc_mat(11, 11)); select setval('rngfunc_rescan_seq1', 1, false), @@ -1029,8 +804,7 @@ select * from (values (1), (2), (3)) as v (r), - rows from (rngfunc_sql(10 + r, 13), - rngfunc_mat(10 + r, 13)); + rows from (rngfunc_sql(10 + r, 13), rngfunc_mat(10 + r, 13)); select setval('rngfunc_rescan_seq1', 1, false), @@ -1041,8 +815,7 @@ select from generate_series(1, 2) as r1, generate_series(r1, 3) as r2, - rows from (rngfunc_sql(10 + r1, 13), - rngfunc_mat(10 + r2, 13)); + rows from (rngfunc_sql(10 + r1, 13), rngfunc_mat(10 + r2, 13)); select * @@ -1054,24 +827,19 @@ select * from (values (1), (2), (3)) as v (r), - generate_series(10 + r, 20 - r) - with ordinality - as f (i, o); + generate_series(10 + r, 20 - r) with ordinality as f (i, o); select * from (values (1), (2), (3)) as v (r), - unnest(array[r * 10, r * 20, r * 30]) - as f (i); + unnest(array[r * 10, r * 20, r * 30]) as f (i); select * from (values (1), (2), (3)) as v (r), - unnest(array[r * 10, r * 20, r * 30]) - with ordinality - as f (i, o); + unnest(array[r * 10, r * 20, r * 30]) with ordinality as f (i, o); select * @@ -1180,9 +948,7 @@ drop sequence rngfunc_rescan_seq2; create function rngfunc(in f1 int, out f2 int) language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; select rngfunc(42); @@ -1193,36 +959,26 @@ select * from rngfunc(42) as p (x); create or replace function rngfunc(in f1 int, out f2 int) returns int language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; create or replace function rngfunc(in f1 int, out f2 int) returns double precision language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; create or replace function rngfunc(in f1 int, out f2 int, out f3 text) returns int language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; create or replace function rngfunc(in f1 int, out f2 int, out f3 text) returns record language sql -as $function$ -select $1+1 -$function$; +as 'select $1+1'; create or replace function rngfuncr(in f1 int, out f2 int, out text) language sql -as $function$ -select $1-1, $1::text || 'z' -$function$; +as $$select $1-1, $1::text || 'z'$$; select f1, rngfuncr(f1) from int4_tbl; @@ -1232,9 +988,7 @@ select * from rngfuncr(42) as p (a, b); create or replace function rngfuncb(in f1 int, inout f2 int, out text) language sql -as $function$ -select $2-1, $1::text || 'z' -$function$; +as $$select $2-1, $1::text || 'z'$$; select f1, rngfuncb(f1, f1 / 2) from int4_tbl; @@ -1244,15 +998,13 @@ select * from rngfuncb(42, 99) as p (a, b); drop function rngfunc(int); -drop function rngfuncr(int); +drop function rngfuncr(in f2 int, out f1 int, out text); -drop function rngfuncb(int, int); +drop function rngfuncb(in f1 int, inout f2 int); create function dup(f1 anyelement, out f2 anyelement, out f3 anyarray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; select dup(22); @@ -1264,17 +1016,13 @@ select * from dup(cast('xyz' as text)); create or replace function dup(inout f2 anyelement, out f3 anyarray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; drop function dup(anyelement); create or replace function dup(inout f2 anyelement, out f3 anyarray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; select dup(22); @@ -1282,9 +1030,7 @@ drop function dup(anyelement); create function bad(f1 int, out f2 anyelement, out f3 anyarray) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; create function dup( @@ -1294,9 +1040,7 @@ dup( out f4 anycompatiblearray ) language sql -as $function$ -select $1, $2 -$function$; +as 'select $1, $2'; select dup(22, array[44]); @@ -1306,7 +1050,7 @@ select dup(22, array[cast(44 as bigint)]); select *, pg_typeof(f3), pg_typeof(f4) from dup(22, array[cast(44 as bigint)]); -drop function dup(anycompatible, anycompatiblearray); +drop function dup(f1 anycompatible, f2 anycompatiblearray); create function dup( @@ -1316,9 +1060,7 @@ dup( out f4 anycompatiblerange ) language sql -as $function$ -select lower($1), array[lower($1), upper($1)], $1 -$function$; +as 'select lower($1), array[lower($1), upper($1)], $1'; select dup(int4range(4, 7)); @@ -1326,7 +1068,7 @@ select dup(numrange(4, 7)); select dup(textrange('aaa', 'bbb')); -drop function dup(anycompatiblerange); +drop function dup(f1 anycompatiblerange); create function bad( @@ -1335,18 +1077,14 @@ bad( out f3 anycompatiblearray ) language sql -as $function$ -select $1, array[$1,$1] -$function$; +as 'select $1, array[$1,$1]'; create or replace function rngfunc() returns table ( a int ) language sql -as $function$ -SELECT a FROM generate_series(1,5) a(a) -$function$; +as $$ SELECT a FROM generate_series(1,5) a(a) $$; select * from rngfunc(); @@ -1358,11 +1096,9 @@ returns table ( b int ) language sql -as $function$ -SELECT a, b +as $$ SELECT a, b FROM generate_series(1,$1) a(a), - generate_series(1,$1) b(b) -$function$; + generate_series(1,$1) b(b) $$; select * from rngfunc(3); @@ -1374,9 +1110,7 @@ returns table ( ) language sql stable -as $function$ -SELECT 'hello'::varchar(5) -$function$; +as $$ SELECT 'hello'::varchar(5) $$; select * from rngfunc() group by 1; @@ -1390,9 +1124,7 @@ create temporary table tt ( create function insert_tt(text) returns int language sql -as $function$ -insert into tt(data) values($1) returning f1 -$function$; +as $$ insert into tt(data) values($1) returning f1 $$; select insert_tt('foo'); @@ -1403,9 +1135,7 @@ select * from tt; create or replace function insert_tt(text) returns int language sql -as $function$ -insert into tt(data) values($1),($1||$1) returning f1 -$function$; +as $$ insert into tt(data) values($1),($1||$1) returning f1 $$; select insert_tt('fool'); @@ -1414,9 +1144,7 @@ select * from tt; create or replace function insert_tt2(text, text) returns setof int language sql -as $function$ -insert into tt(data) values($1),($2) returning f1 -$function$; +as $$ insert into tt(data) values($1),($2) returning f1 $$; select insert_tt2('foolish', 'barrish'); @@ -1431,12 +1159,11 @@ select * from tt; create function noticetrigger() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'noticetrigger % %', new.f1, new.data; return null; -end -$function$; +end $$; create trigger tnoticetrigger after insert @@ -1467,9 +1194,7 @@ select * from tt_log; create function rngfunc1(n int, out a text, out b text) returns setof record language sql -as $function$ -select 'foo ' || i, 'bar ' || i from generate_series(1,$1) i -$function$; +as $$ select 'foo ' || i, 'bar ' || i from generate_series(1,$1) i $$; set work_mem = '64kB'; @@ -1479,16 +1204,16 @@ reset work_mem; select t.a, t, t.a from rngfunc1(10000) as t limit 1; -drop function rngfunc1(int); +drop function rngfunc1(n int); create function array_to_set(anyarray) returns setof record language sql immutable strict -as $function$ -select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i -$function$; +as $$ + select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i +$$; select array_to_set(array['one', 'two']); @@ -1499,26 +1224,22 @@ select * from array_to_set(array['one', 'two']); select * from - array_to_set(array['one', 'two']) - as t - (f1 numeric(4, 2), f2 text); + array_to_set(array['one', 'two']) as t (f1 numeric(4, 2), f2 text); select * from array_to_set(array['one', 'two']) as t (f1 point, f2 text); select * from - array_to_set(array['one', 'two']) - as t - (f1 numeric(4, 2), f2 text); + array_to_set(array['one', 'two']) as t (f1 numeric(4, 2), f2 text); create or replace function array_to_set(anyarray) returns setof record language sql immutable -as $function$ -select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i -$function$; +as $$ + select i AS "index", $1[i] AS "value" from generate_subscripts($1, 1) i +$$; select array_to_set(array['one', 'two']); @@ -1527,34 +1248,30 @@ select * from array_to_set(array['one', 'two']) as t (f1 int, f2 text); select * from - array_to_set(array['one', 'two']) - as t - (f1 numeric(4, 2), f2 text); + array_to_set(array['one', 'two']) as t (f1 numeric(4, 2), f2 text); select * from array_to_set(array['one', 'two']) as t (f1 point, f2 text); select * from - array_to_set(array['one', 'two']) - as t - (f1 numeric(4, 2), f2 text); + array_to_set(array['one', 'two']) as t (f1 numeric(4, 2), f2 text); create temporary table rngfunc ( - f1 bigint, - f2 bigint + f1 int8, + f2 int8 ); create function testrngfunc() returns record language sql -as $function$ -insert into rngfunc values (1,2) returning *; -$function$; +as $$ + insert into rngfunc values (1,2) returning *; +$$; select testrngfunc(); -select * from testrngfunc() as t (f1 bigint, f2 bigint); +select * from testrngfunc() as t (f1 int8, f2 int8); select * from testrngfunc(); @@ -1563,13 +1280,13 @@ drop function testrngfunc(); create function testrngfunc() returns setof record language sql -as $function$ -insert into rngfunc values (1,2), (3,4) returning *; -$function$; +as $$ + insert into rngfunc values (1,2), (3,4) returning *; +$$; select testrngfunc(); -select * from testrngfunc() as t (f1 bigint, f2 bigint); +select * from testrngfunc() as t (f1 int8, f2 int8); select * from testrngfunc(); @@ -1581,9 +1298,9 @@ create function testrngfunc() returns rngfunc_type language sql immutable -as $function$ -select 7.136178319899999964, 7.136178319899999964; -$function$; +as $$ + select 7.136178319899999964, 7.136178319899999964; +$$; select testrngfunc(); @@ -1597,9 +1314,9 @@ create or replace function testrngfunc() returns rngfunc_type language sql volatile -as $function$ -select 7.136178319899999964, 7.136178319899999964; -$function$; +as $$ + select 7.136178319899999964, 7.136178319899999964; +$$; select testrngfunc(); @@ -1615,9 +1332,9 @@ create function testrngfunc() returns setof rngfunc_type language sql immutable -as $function$ -select 7.136178319899999964, 7.136178319899999964; -$function$; +as $$ + select 7.136178319899999964, 7.136178319899999964; +$$; select testrngfunc(); @@ -1631,9 +1348,9 @@ create or replace function testrngfunc() returns setof rngfunc_type language sql volatile -as $function$ -select 7.136178319899999964, 7.136178319899999964; -$function$; +as $$ + select 7.136178319899999964, 7.136178319899999964; +$$; select testrngfunc(); @@ -1647,9 +1364,9 @@ create or replace function testrngfunc() returns setof rngfunc_type language sql immutable -as $function$ -select 1, 2 union select 3, 4 order by 1; -$function$; +as $$ + select 1, 2 union select 3, 4 order by 1; +$$; select testrngfunc(); @@ -1659,11 +1376,11 @@ select * from testrngfunc(); select * from testrngfunc(); -select * from testrngfunc() as t (f1 bigint, f2 bigint); +select * from testrngfunc() as t (f1 int8, f2 int8); -select * from pg_get_keywords() as t (f1 bigint, f2 bigint); +select * from pg_get_keywords() as t (f1 int8, f2 int8); -select * from sin(3) as t (f1 bigint, f2 bigint); +select * from sin(3) as t (f1 int8, f2 int8); drop type rngfunc_type cascade; @@ -1671,9 +1388,9 @@ create temporary table users ( userid text, seq int, email text, - todrop boolean, + todrop bool, moredrop int, - enabled boolean + enabled bool ); insert into users values ('id', 1, 'email', true, 11, true); @@ -1687,9 +1404,7 @@ create or replace function get_first_user() returns users language sql stable -as $function$ -SELECT * FROM users ORDER BY userid LIMIT 1; -$function$; +as $$ SELECT * FROM users ORDER BY userid LIMIT 1; $$; select get_first_user(); @@ -1699,9 +1414,7 @@ create or replace function get_users() returns setof users language sql stable -as $function$ -SELECT * FROM users ORDER BY userid; -$function$; +as $$ SELECT * FROM users ORDER BY userid; $$; select get_users(); @@ -1717,9 +1430,7 @@ create temporary view usersview as select * from - rows from (get_users(), - generate_series(10, 11)) - with ordinality; + rows from (get_users(), generate_series(10, 11)) with ordinality; select * from usersview; @@ -1742,22 +1453,11 @@ where from pg_rewrite where - ev_class = cast('usersview' as regclass) and - rulename = '_RETURN' + ev_class = cast('usersview' as regclass) and rulename = '_RETURN' ) and refobjsubid = 5 -returning pg_describe_object( - classid, - objid, - objsubid -) -as obj, -pg_describe_object( - refclassid, - refobjid, - refobjsubid -) -as ref, +returning pg_describe_object(classid, objid, objsubid) as obj, +pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype; alter table users @@ -1781,22 +1481,11 @@ where from pg_rewrite where - ev_class = cast('usersview' as regclass) and - rulename = '_RETURN' + ev_class = cast('usersview' as regclass) and rulename = '_RETURN' ) and refobjsubid = 2 -returning pg_describe_object( - classid, - objid, - objsubid -) -as obj, -pg_describe_object( - refclassid, - refobjid, - refobjsubid -) -as ref, +returning pg_describe_object(classid, objid, objsubid) as obj, +pg_describe_object(refclassid, refobjid, refobjsubid) as ref, deptype; alter table users @@ -1818,9 +1507,7 @@ create or replace function rngfuncbar() returns setof text language sql stable -as $function$ -select 'foo'::varchar union all select 'bar'::varchar ; -$function$; +as $$ select 'foo'::varchar union all select 'bar'::varchar ; $$; select rngfuncbar(); @@ -1832,37 +1519,31 @@ drop function rngfuncbar(); create or replace function rngfuncbar(out int, out numeric) language sql -as $function$ -select (1, 2.1) -$function$; +as $$ select (1, 2.1) $$; select * from rngfuncbar(); create or replace function rngfuncbar(out int, out numeric) language sql -as $function$ -select (1, 2) -$function$; +as $$ select (1, 2) $$; select * from rngfuncbar(); create or replace function rngfuncbar(out int, out numeric) language sql -as $function$ -select (1, 2.1, 3) -$function$; +as $$ select (1, 2.1, 3) $$; select * from rngfuncbar(); drop function rngfuncbar(); create function extractq2(t int8_tbl) -returns bigint +returns int8 language sql immutable -as $function$ -select t.q2 -$function$; +as $$ + select t.q2 +$$; select x from int8_tbl, extractq2(int8_tbl) as f (x); @@ -1870,13 +1551,13 @@ select x from int8_tbl, extractq2(int8_tbl) as f (x); create function extractq2_2(t int8_tbl) returns table ( - ret1 bigint + ret1 int8 ) language sql immutable -as $function$ -select extractq2(t) offset 0 -$function$; +as $$ + select extractq2(t) offset 0 +$$; select x from int8_tbl, extractq2_2(int8_tbl) as f (x); @@ -1884,13 +1565,13 @@ select x from int8_tbl, extractq2_2(int8_tbl) as f (x); create function extractq2_2_opt(t int8_tbl) returns table ( - ret1 bigint + ret1 int8 ) language sql immutable -as $function$ -select extractq2(t) -$function$; +as $$ + select extractq2(t) +$$; select x from int8_tbl, extractq2_2_opt(int8_tbl) as f (x); @@ -1902,21 +1583,13 @@ select *, row_to_json(u) from - unnest( - array[cast((1, 'foo') as rngfunc2), - cast(null as rngfunc2)] - ) - as u; + unnest(array[cast((1, 'foo') as rngfunc2), cast(null as rngfunc2)]) as u; select *, row_to_json(u) from - unnest( - array[cast(null as rngfunc2), - cast(null as rngfunc2)] - ) - as u; + unnest(array[cast(null as rngfunc2), cast(null as rngfunc2)]) as u; select *, @@ -1938,44 +1611,26 @@ select from ( select - jsonb_path_query_array( - module -> 'lectures', - '$[*]' - ) - as lecture + jsonb_path_query_array(module -> 'lectures', '$[*]') as lecture from - unnest( - array[cast('{"lectures": [{"id": "1"}]}' - as jsonb)] - ) + unnest(array[cast('{"lectures": [{"id": "1"}]}' as jsonb)]) as unnested_modules (module) ) as ss, - jsonb_to_recordset(ss.lecture) - as j - (id text); + jsonb_to_recordset(ss.lecture) as j (id text); select * from ( select - jsonb_path_query_array( - module -> 'lectures', - '$[*]' - ) - as lecture + jsonb_path_query_array(module -> 'lectures', '$[*]') as lecture from - unnest( - array[cast('{"lectures": [{"id": "1"}]}' - as jsonb)] - ) + unnest(array[cast('{"lectures": [{"id": "1"}]}' as jsonb)]) as unnested_modules (module) ) as ss, - jsonb_to_recordset(ss.lecture) - as j - (id text); + jsonb_to_recordset(ss.lecture) as j (id text); with a (b) as (values (row(1, 2, 3))) select @@ -1989,17 +1644,13 @@ select * from a, - coalesce(b) - as c - (d int, e int, f int, g int); + coalesce(b) as c (d int, e int, f int, g int); with a (b) as (values (row(1, 2, 3))) select * from a, - coalesce(b) - as c - (d int, e int, f double precision); + coalesce(b) as c (d int, e int, f double precision); select * from int8_tbl, coalesce(row(1)) as (a int, b int); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_100.snap index 7a34ecc59..db8f0286a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_100.snap @@ -86,7 +86,7 @@ select * from pg_input_error_info('[2000-01-01,5874897-12-31]', 'daterange'); create table numrange_test (nr numrange); -create index "numrange_test_btree" on numrange_test using btree (nr); +create index numrange_test_btree on numrange_test using btree (nr); insert into numrange_test values ('[,)'); @@ -210,7 +210,7 @@ analyze numrange_test; create table numrange_test2 (nr numrange); -create index "numrange_test2_hash_idx" on numrange_test2 using hash (nr); +create index numrange_test2_hash_idx on numrange_test2 using hash (nr); insert into numrange_test2 values ('[, 5)'); @@ -262,7 +262,7 @@ drop table numrange_test2; create table textrange_test (tr textrange); -create index "textrange_test_btree" on textrange_test using btree (tr); +create index textrange_test_btree on textrange_test using btree (tr); insert into textrange_test values ('[,)'); @@ -328,7 +328,7 @@ select daterange(cast('2000-01-01' as date), cast('infinity' as date), '[]'); create table test_range_gist (ir int4range); -create index "test_range_gist_idx" on test_range_gist using gist (ir); +create index test_range_gist_idx on test_range_gist using gist (ir); insert into test_range_gist select int4range(g, g + 10) from generate_series(1, 2000) as g; @@ -352,113 +352,85 @@ set enable_indexscan = f; set enable_bitmapscan = f; -select COUNT(*) from test_range_gist where ir @> cast('empty' as int4range); +select count(*) from test_range_gist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_gist where ir = int4range(10, 20); +select count(*) from test_range_gist where ir = int4range(10, 20); -select COUNT(*) from test_range_gist where ir @> 10; +select count(*) from test_range_gist where ir @> 10; -select COUNT(*) from test_range_gist where ir @> int4range(10, 20); +select count(*) from test_range_gist where ir @> int4range(10, 20); -select COUNT(*) from test_range_gist where ir && int4range(10, 20); +select count(*) from test_range_gist where ir && int4range(10, 20); -select COUNT(*) from test_range_gist where ir <@ int4range(10, 50); +select count(*) from test_range_gist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_gist where ir << int4range(100, 500); +select count(*) from test_range_gist where ir << int4range(100, 500); -select COUNT(*) from test_range_gist where ir >> int4range(100, 500); +select count(*) from test_range_gist where ir >> int4range(100, 500); -select COUNT(*) from test_range_gist where ir &< int4range(100, 500); +select count(*) from test_range_gist where ir &< int4range(100, 500); -select COUNT(*) from test_range_gist where ir &> int4range(100, 500); +select count(*) from test_range_gist where ir &> int4range(100, 500); -select COUNT(*) from test_range_gist where ir -|- int4range(100, 500); +select count(*) from test_range_gist where ir -|- int4range(100, 500); -select COUNT(*) from test_range_gist where ir @> cast('{}' as int4multirange); +select count(*) from test_range_gist where ir @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + ir @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_range_gist where - ir && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + ir && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + ir <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir -|- int4multirange(int4range(100, 200), int4range(400, 500)); set enable_seqscan = f; @@ -466,229 +438,173 @@ set enable_indexscan = t; set enable_bitmapscan = f; -select COUNT(*) from test_range_gist where ir @> cast('empty' as int4range); +select count(*) from test_range_gist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_gist where ir = int4range(10, 20); +select count(*) from test_range_gist where ir = int4range(10, 20); -select COUNT(*) from test_range_gist where ir @> 10; +select count(*) from test_range_gist where ir @> 10; -select COUNT(*) from test_range_gist where ir @> int4range(10, 20); +select count(*) from test_range_gist where ir @> int4range(10, 20); -select COUNT(*) from test_range_gist where ir && int4range(10, 20); +select count(*) from test_range_gist where ir && int4range(10, 20); -select COUNT(*) from test_range_gist where ir <@ int4range(10, 50); +select count(*) from test_range_gist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_gist where ir << int4range(100, 500); +select count(*) from test_range_gist where ir << int4range(100, 500); -select COUNT(*) from test_range_gist where ir >> int4range(100, 500); +select count(*) from test_range_gist where ir >> int4range(100, 500); -select COUNT(*) from test_range_gist where ir &< int4range(100, 500); +select count(*) from test_range_gist where ir &< int4range(100, 500); -select COUNT(*) from test_range_gist where ir &> int4range(100, 500); +select count(*) from test_range_gist where ir &> int4range(100, 500); -select COUNT(*) from test_range_gist where ir -|- int4range(100, 500); +select count(*) from test_range_gist where ir -|- int4range(100, 500); -select COUNT(*) from test_range_gist where ir @> cast('{}' as int4multirange); +select count(*) from test_range_gist where ir @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + ir @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_range_gist where - ir && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + ir && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + ir <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir -|- int4multirange(int4range(100, 200), int4range(400, 500)); drop index test_range_gist_idx; -create index "test_range_gist_idx" on test_range_gist using gist (ir); +create index test_range_gist_idx on test_range_gist using gist (ir); -select COUNT(*) from test_range_gist where ir @> cast('empty' as int4range); +select count(*) from test_range_gist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_gist where ir = int4range(10, 20); +select count(*) from test_range_gist where ir = int4range(10, 20); -select COUNT(*) from test_range_gist where ir @> 10; +select count(*) from test_range_gist where ir @> 10; -select COUNT(*) from test_range_gist where ir @> int4range(10, 20); +select count(*) from test_range_gist where ir @> int4range(10, 20); -select COUNT(*) from test_range_gist where ir && int4range(10, 20); +select count(*) from test_range_gist where ir && int4range(10, 20); -select COUNT(*) from test_range_gist where ir <@ int4range(10, 50); +select count(*) from test_range_gist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_gist where ir << int4range(100, 500); +select count(*) from test_range_gist where ir << int4range(100, 500); -select COUNT(*) from test_range_gist where ir >> int4range(100, 500); +select count(*) from test_range_gist where ir >> int4range(100, 500); -select COUNT(*) from test_range_gist where ir &< int4range(100, 500); +select count(*) from test_range_gist where ir &< int4range(100, 500); -select COUNT(*) from test_range_gist where ir &> int4range(100, 500); +select count(*) from test_range_gist where ir &> int4range(100, 500); -select COUNT(*) from test_range_gist where ir -|- int4range(100, 500); +select count(*) from test_range_gist where ir -|- int4range(100, 500); -select COUNT(*) from test_range_gist where ir @> cast('{}' as int4multirange); +select count(*) from test_range_gist where ir @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + ir @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_range_gist where - ir && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + ir && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + ir <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir -|- int4multirange(int4range(100, 200), int4range(400, 500)); create table test_range_spgist (ir int4range); -create index "test_range_spgist_idx" on test_range_spgist using spgist (ir); +create index test_range_spgist_idx on test_range_spgist using spgist (ir); insert into test_range_spgist select int4range(g, g + 10) from generate_series(1, 2000) as g; @@ -699,16 +615,10 @@ insert into test_range_spgist select int4range(g, g + 10000) from generate_serie insert into test_range_spgist select cast('empty' as int4range) from generate_series(1, 500) as g; insert into test_range_spgist -select - int4range(null, g * 10, '(]') -from - generate_series(1, 100) as g; +select int4range(null, g * 10, '(]') from generate_series(1, 100) as g; insert into test_range_spgist -select - int4range(g * 10, null, '(]') -from - generate_series(1, 100) as g; +select int4range(g * 10, null, '(]') from generate_series(1, 100) as g; insert into test_range_spgist select int4range(g, g + 10) from generate_series(1, 2000) as g; @@ -718,27 +628,27 @@ set enable_indexscan = f; set enable_bitmapscan = f; -select COUNT(*) from test_range_spgist where ir @> cast('empty' as int4range); +select count(*) from test_range_spgist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_spgist where ir = int4range(10, 20); +select count(*) from test_range_spgist where ir = int4range(10, 20); -select COUNT(*) from test_range_spgist where ir @> 10; +select count(*) from test_range_spgist where ir @> 10; -select COUNT(*) from test_range_spgist where ir @> int4range(10, 20); +select count(*) from test_range_spgist where ir @> int4range(10, 20); -select COUNT(*) from test_range_spgist where ir && int4range(10, 20); +select count(*) from test_range_spgist where ir && int4range(10, 20); -select COUNT(*) from test_range_spgist where ir <@ int4range(10, 50); +select count(*) from test_range_spgist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_spgist where ir << int4range(100, 500); +select count(*) from test_range_spgist where ir << int4range(100, 500); -select COUNT(*) from test_range_spgist where ir >> int4range(100, 500); +select count(*) from test_range_spgist where ir >> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &< int4range(100, 500); +select count(*) from test_range_spgist where ir &< int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &> int4range(100, 500); +select count(*) from test_range_spgist where ir &> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir -|- int4range(100, 500); +select count(*) from test_range_spgist where ir -|- int4range(100, 500); set enable_seqscan = f; @@ -746,53 +656,53 @@ set enable_indexscan = t; set enable_bitmapscan = f; -select COUNT(*) from test_range_spgist where ir @> cast('empty' as int4range); +select count(*) from test_range_spgist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_spgist where ir = int4range(10, 20); +select count(*) from test_range_spgist where ir = int4range(10, 20); -select COUNT(*) from test_range_spgist where ir @> 10; +select count(*) from test_range_spgist where ir @> 10; -select COUNT(*) from test_range_spgist where ir @> int4range(10, 20); +select count(*) from test_range_spgist where ir @> int4range(10, 20); -select COUNT(*) from test_range_spgist where ir && int4range(10, 20); +select count(*) from test_range_spgist where ir && int4range(10, 20); -select COUNT(*) from test_range_spgist where ir <@ int4range(10, 50); +select count(*) from test_range_spgist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_spgist where ir << int4range(100, 500); +select count(*) from test_range_spgist where ir << int4range(100, 500); -select COUNT(*) from test_range_spgist where ir >> int4range(100, 500); +select count(*) from test_range_spgist where ir >> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &< int4range(100, 500); +select count(*) from test_range_spgist where ir &< int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &> int4range(100, 500); +select count(*) from test_range_spgist where ir &> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir -|- int4range(100, 500); +select count(*) from test_range_spgist where ir -|- int4range(100, 500); drop index test_range_spgist_idx; -create index "test_range_spgist_idx" on test_range_spgist using spgist (ir); +create index test_range_spgist_idx on test_range_spgist using spgist (ir); -select COUNT(*) from test_range_spgist where ir @> cast('empty' as int4range); +select count(*) from test_range_spgist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_spgist where ir = int4range(10, 20); +select count(*) from test_range_spgist where ir = int4range(10, 20); -select COUNT(*) from test_range_spgist where ir @> 10; +select count(*) from test_range_spgist where ir @> 10; -select COUNT(*) from test_range_spgist where ir @> int4range(10, 20); +select count(*) from test_range_spgist where ir @> int4range(10, 20); -select COUNT(*) from test_range_spgist where ir && int4range(10, 20); +select count(*) from test_range_spgist where ir && int4range(10, 20); -select COUNT(*) from test_range_spgist where ir <@ int4range(10, 50); +select count(*) from test_range_spgist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_spgist where ir << int4range(100, 500); +select count(*) from test_range_spgist where ir << int4range(100, 500); -select COUNT(*) from test_range_spgist where ir >> int4range(100, 500); +select count(*) from test_range_spgist where ir >> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &< int4range(100, 500); +select count(*) from test_range_spgist where ir &< int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &> int4range(100, 500); +select count(*) from test_range_spgist where ir &> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir -|- int4range(100, 500); +select count(*) from test_range_spgist where ir -|- int4range(100, 500); select ir from test_range_spgist where ir -|- int4range(10, 20) order by ir; @@ -804,21 +714,21 @@ reset enable_indexscan; reset enable_bitmapscan; -create table test_range_elem (i int); +create table test_range_elem (i int4); -create index "test_range_elem_idx" on test_range_elem using btree (i); +create index test_range_elem_idx on test_range_elem using btree (i); insert into test_range_elem select i from generate_series(1, 100) as i; set enable_seqscan = f; -select COUNT(*) from test_range_elem where i <@ int4range(10, 50); +select count(*) from test_range_elem where i <@ int4range(10, 50); create index on test_range_elem using spgist ((int4range(i, i + 10))); -select COUNT(*) from test_range_elem where int4range(i, i + 10) <@ int4range(10, 30); +select count(*) from test_range_elem where int4range(i, i + 10) <@ int4range(10, 30); -select COUNT(*) from test_range_elem where int4range(i, i + 10) <@ int4range(10, 30); +select count(*) from test_range_elem where int4range(i, i + 10) <@ int4range(10, 30); reset enable_seqscan; @@ -829,51 +739,25 @@ create table test_range_excl ( speaker int4range, during tsrange, exclude using gist (room with =, during with &&), - exclude using gist (speaker with =, - during with &&) + exclude using gist (speaker with =, during with &&) ); insert into test_range_excl -values - ( - int4range(123, 123, '[]'), - int4range(1, 1, '[]'), - '[2010-01-02 10:00, 2010-01-02 11:00)' - ); +values (int4range(123, 123, '[]'), int4range(1, 1, '[]'), '[2010-01-02 10:00, 2010-01-02 11:00)'); insert into test_range_excl -values - ( - int4range(123, 123, '[]'), - int4range(2, 2, '[]'), - '[2010-01-02 11:00, 2010-01-02 12:00)' - ); +values (int4range(123, 123, '[]'), int4range(2, 2, '[]'), '[2010-01-02 11:00, 2010-01-02 12:00)'); insert into test_range_excl -values - ( - int4range(123, 123, '[]'), - int4range(3, 3, '[]'), - '[2010-01-02 10:10, 2010-01-02 11:00)' - ); +values (int4range(123, 123, '[]'), int4range(3, 3, '[]'), '[2010-01-02 10:10, 2010-01-02 11:00)'); insert into test_range_excl -values - ( - int4range(124, 124, '[]'), - int4range(3, 3, '[]'), - '[2010-01-02 10:10, 2010-01-02 11:10)' - ); +values (int4range(124, 124, '[]'), int4range(3, 3, '[]'), '[2010-01-02 10:10, 2010-01-02 11:10)'); insert into test_range_excl -values - ( - int4range(125, 125, '[]'), - int4range(1, 1, '[]'), - '[2010-01-02 10:10, 2010-01-02 11:00)' - ); +values (int4range(125, 125, '[]'), int4range(1, 1, '[]'), '[2010-01-02 10:10, 2010-01-02 11:00)'); -select int8range(cast(10000000000 as bigint), cast(20000000000 as bigint), '(]'); +select int8range(cast(10000000000 as int8), cast(20000000000 as int8), '(]'); set time zone '-08'; @@ -883,9 +767,9 @@ select cast('[2010-01-01 01:00:00 -08, 2010-01-01 02:00:00 -05)' as tstzrange); set timezone to default; -create type bogus_float8range as range (subtype = double precision, subtype_diff = float4mi); +create type bogus_float8range as range (subtype = float8, subtype_diff = float4mi); -select cast('[123.001, 5.e9)' as float8range) @> cast(888.882 as double precision); +select cast('[123.001, 5.e9)' as float8range) @> cast(888.882 as float8); create table float8range_test ( f8r float8range, @@ -898,7 +782,7 @@ select * from float8range_test; drop table float8range_test; -create domain mydomain as int; +create domain mydomain as int4; create type mydomainrange as range (subtype = mydomain); @@ -916,9 +800,9 @@ select cast('[4,50)' as restrictedrange) @> 7; drop domain restrictedrange; -create type textrange1 as range (subtype = text, collation = "C"); +create type textrange1 as range (subtype = text, "collation" = "C"); -create type textrange2 as range (subtype = text, collation = "C"); +create type textrange2 as range (subtype = text, "collation" = "C"); select textrange1('a', 'Z') @> cast('b' as text); @@ -931,9 +815,7 @@ drop type textrange2; create function anyarray_anyrange_func(a anyarray, r anyrange) returns anyelement language sql -as $function$ -select $1[1] + lower($2); -$function$; +as 'select $1[1] + lower($2);'; select anyarray_anyrange_func(array[1, 2], int4range(10, 20)); @@ -944,23 +826,17 @@ drop function anyarray_anyrange_func(anyarray, anyrange); create function bogus_func(anyelement) returns anyrange language sql -as $function$ -select int4range(1,10) -$function$; +as 'select int4range(1,10)'; create function bogus_func(int) returns anyrange language sql -as $function$ -select int4range(1,10) -$function$; +as 'select int4range(1,10)'; create function range_add_bounds(anyrange) returns anyelement language sql -as $function$ -select lower($1) + upper($1) -$function$; +as 'select lower($1) + upper($1)'; select range_add_bounds(int4range(1, 17)); @@ -968,9 +844,7 @@ select range_add_bounds(numrange(1.0001, 123.123)); create function rangetypes_sql(q anyrange, b anyarray, out c anyelement) language sql -as $function$ -select upper($1) + $2[1] -$function$; +as $$ select upper($1) + $2[1] $$; select rangetypes_sql(int4range(1, 10), array[2, 20]); @@ -983,9 +857,7 @@ anycompatiblearray_anycompatiblerange_func( ) returns anycompatible language sql -as $function$ -select $1[1] + lower($2); -$function$; +as 'select $1[1] + lower($2);'; select anycompatiblearray_anycompatiblerange_func(array[1, 2], int4range(10, 20)); @@ -998,9 +870,7 @@ drop function anycompatiblearray_anycompatiblerange_func(anycompatiblearray, any create function bogus_func(anycompatible) returns anycompatiblerange language sql -as $function$ -select int4range(1,10) -$function$; +as 'select int4range(1,10)'; select array[numrange(1.1, 1.2), numrange(12.3, 155.5)]; @@ -1015,7 +885,7 @@ select * from i8r_array; drop table i8r_array; -create type arrayrange as range (subtype = int[]); +create type arrayrange as range (subtype = int4[]); select arrayrange(array[1, 2], array[2, 1]); @@ -1033,19 +903,14 @@ select *, row_to_json(upper(t)) as u from - ( - values - (two_ints_range(row(1, 2), row(3, 4))), - (two_ints_range(row(5, 6), row(7, 8))) - ) - as v (t); + (values (two_ints_range(row(1, 2), row(3, 4))), (two_ints_range(row(5, 6), row(7, 8)))) as v (t); alter type two_ints add attribute c two_ints_range; drop type two_ints cascade; -create type varbitrange as range (subtype = bit varying); +create type varbitrange as range (subtype = varbit); set enable_sort = off; @@ -1055,33 +920,25 @@ reset enable_sort; create function outparam_succeed(i anyrange, out r anyrange, out t text) language sql -as $function$ -select $1, 'foo'::text -$function$; +as $$ select $1, 'foo'::text $$; select * from outparam_succeed(int4range(1, 2)); create function outparam2_succeed(r anyrange, out lu anyarray, out ul anyarray) language sql -as $function$ -select array[lower($1), upper($1)], array[upper($1), lower($1)] -$function$; +as $$ select array[lower($1), upper($1)], array[upper($1), lower($1)] $$; select * from outparam2_succeed(int4range(1, 11)); create function outparam_succeed2(i anyrange, out r anyarray, out t text) language sql -as $function$ -select ARRAY[upper($1)], 'foo'::text -$function$; +as $$ select ARRAY[upper($1)], 'foo'::text $$; select * from outparam_succeed2(int4range(int4range(1, 2))); create function inoutparam_succeed(out i anyelement, inout r anyrange) language sql -as $function$ -select upper($1), $1 -$function$; +as $$ select upper($1), $1 $$; select * from inoutparam_succeed(int4range(1, 2)); @@ -1091,23 +948,17 @@ returns table ( u anyelement ) language sql -as $function$ -select lower($1), upper($1) -$function$; +as $$ select lower($1), upper($1) $$; select * from table_succeed(int4range(1, 11)); create function outparam_fail(i anyelement, out r anyrange, out t text) language sql -as $function$ -select '[1,10]', 'foo' -$function$; +as $$ select '[1,10]', 'foo' $$; create function inoutparam_fail(inout i anyelement, out r anyrange) language sql -as $function$ -select $1, '[1,10]' -$function$; +as $$ select $1, '[1,10]' $$; create function table_fail(i anyelement) returns table ( @@ -1115,9 +966,7 @@ returns table ( r anyrange ) language sql -as $function$ -select $1, '[1,10]' -$function$; +as $$ select $1, '[1,10]' $$; select current_date <@ cast('empty' as daterange); @@ -1139,7 +988,7 @@ select daterange('-Infinity', cast('1997-04-10' as date), '()') @> current_date; select daterange(cast('2002-09-25' as date), 'Infinity', '[]') @> current_date; -select NOW() <@ tstzrange('2024-01-20 00:00', '2024-01-21 00:00'); +select now() <@ tstzrange('2024-01-20 00:00', '2024-01-21 00:00'); select clock_timestamp() <@ tstzrange('2024-01-20 00:00', '2024-01-21 00:00'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_80.snap index a18d1f522..85bb9332c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_80.snap @@ -86,7 +86,7 @@ select * from pg_input_error_info('[2000-01-01,5874897-12-31]', 'daterange'); create table numrange_test (nr numrange); -create index "numrange_test_btree" on numrange_test using btree (nr); +create index numrange_test_btree on numrange_test using btree (nr); insert into numrange_test values ('[,)'); @@ -120,10 +120,7 @@ select from numrange_test where - range_contained_by( - numrange(-1e7, -10000.1), - nr - ); + range_contained_by(numrange(-1e7, -10000.1), nr); select * from numrange_test where 1.9 <@ nr; @@ -225,7 +222,7 @@ analyze numrange_test; create table numrange_test2 (nr numrange); -create index "numrange_test2_hash_idx" on numrange_test2 using hash (nr); +create index numrange_test2_hash_idx on numrange_test2 using hash (nr); insert into numrange_test2 values ('[, 5)'); @@ -277,7 +274,7 @@ drop table numrange_test2; create table textrange_test (tr textrange); -create index "textrange_test_btree" on textrange_test using btree (tr); +create index textrange_test_btree on textrange_test using btree (tr); insert into textrange_test values ('[,)'); @@ -350,49 +347,28 @@ select daterange(cast('2000-01-01' as date), cast('infinity' as date), '[]'); create table test_range_gist (ir int4range); -create index "test_range_gist_idx" on test_range_gist using gist (ir); +create index test_range_gist_idx on test_range_gist using gist (ir); insert into test_range_gist -select - int4range(g, g + 10) -from - generate_series(1, 2000) as g; +select int4range(g, g + 10) from generate_series(1, 2000) as g; insert into test_range_gist -select - cast('empty' as int4range) -from - generate_series(1, 500) as g; +select cast('empty' as int4range) from generate_series(1, 500) as g; insert into test_range_gist -select - int4range(g, g + 10000) -from - generate_series(1, 1000) as g; +select int4range(g, g + 10000) from generate_series(1, 1000) as g; insert into test_range_gist -select - cast('empty' as int4range) -from - generate_series(1, 500) as g; +select cast('empty' as int4range) from generate_series(1, 500) as g; insert into test_range_gist -select - int4range(null, g * 10, '(]') -from - generate_series(1, 100) as g; +select int4range(null, g * 10, '(]') from generate_series(1, 100) as g; insert into test_range_gist -select - int4range(g * 10, null, '(]') -from - generate_series(1, 100) as g; +select int4range(g * 10, null, '(]') from generate_series(1, 100) as g; insert into test_range_gist -select - int4range(g, g + 10) -from - generate_series(1, 2000) as g; +select int4range(g, g + 10) from generate_series(1, 2000) as g; analyze test_range_gist; @@ -402,113 +378,85 @@ set enable_indexscan = f; set enable_bitmapscan = f; -select COUNT(*) from test_range_gist where ir @> cast('empty' as int4range); +select count(*) from test_range_gist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_gist where ir = int4range(10, 20); +select count(*) from test_range_gist where ir = int4range(10, 20); -select COUNT(*) from test_range_gist where ir @> 10; +select count(*) from test_range_gist where ir @> 10; -select COUNT(*) from test_range_gist where ir @> int4range(10, 20); +select count(*) from test_range_gist where ir @> int4range(10, 20); -select COUNT(*) from test_range_gist where ir && int4range(10, 20); +select count(*) from test_range_gist where ir && int4range(10, 20); -select COUNT(*) from test_range_gist where ir <@ int4range(10, 50); +select count(*) from test_range_gist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_gist where ir << int4range(100, 500); +select count(*) from test_range_gist where ir << int4range(100, 500); -select COUNT(*) from test_range_gist where ir >> int4range(100, 500); +select count(*) from test_range_gist where ir >> int4range(100, 500); -select COUNT(*) from test_range_gist where ir &< int4range(100, 500); +select count(*) from test_range_gist where ir &< int4range(100, 500); -select COUNT(*) from test_range_gist where ir &> int4range(100, 500); +select count(*) from test_range_gist where ir &> int4range(100, 500); -select COUNT(*) from test_range_gist where ir -|- int4range(100, 500); +select count(*) from test_range_gist where ir -|- int4range(100, 500); -select COUNT(*) from test_range_gist where ir @> cast('{}' as int4multirange); +select count(*) from test_range_gist where ir @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + ir @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_range_gist where - ir && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + ir && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + ir <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir -|- int4multirange(int4range(100, 200), int4range(400, 500)); set enable_seqscan = f; @@ -516,271 +464,194 @@ set enable_indexscan = t; set enable_bitmapscan = f; -select COUNT(*) from test_range_gist where ir @> cast('empty' as int4range); +select count(*) from test_range_gist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_gist where ir = int4range(10, 20); +select count(*) from test_range_gist where ir = int4range(10, 20); -select COUNT(*) from test_range_gist where ir @> 10; +select count(*) from test_range_gist where ir @> 10; -select COUNT(*) from test_range_gist where ir @> int4range(10, 20); +select count(*) from test_range_gist where ir @> int4range(10, 20); -select COUNT(*) from test_range_gist where ir && int4range(10, 20); +select count(*) from test_range_gist where ir && int4range(10, 20); -select COUNT(*) from test_range_gist where ir <@ int4range(10, 50); +select count(*) from test_range_gist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_gist where ir << int4range(100, 500); +select count(*) from test_range_gist where ir << int4range(100, 500); -select COUNT(*) from test_range_gist where ir >> int4range(100, 500); +select count(*) from test_range_gist where ir >> int4range(100, 500); -select COUNT(*) from test_range_gist where ir &< int4range(100, 500); +select count(*) from test_range_gist where ir &< int4range(100, 500); -select COUNT(*) from test_range_gist where ir &> int4range(100, 500); +select count(*) from test_range_gist where ir &> int4range(100, 500); -select COUNT(*) from test_range_gist where ir -|- int4range(100, 500); +select count(*) from test_range_gist where ir -|- int4range(100, 500); -select COUNT(*) from test_range_gist where ir @> cast('{}' as int4multirange); +select count(*) from test_range_gist where ir @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + ir @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_range_gist where - ir && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + ir && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + ir <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir -|- int4multirange(int4range(100, 200), int4range(400, 500)); drop index test_range_gist_idx; -create index "test_range_gist_idx" on test_range_gist using gist (ir); +create index test_range_gist_idx on test_range_gist using gist (ir); -select COUNT(*) from test_range_gist where ir @> cast('empty' as int4range); +select count(*) from test_range_gist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_gist where ir = int4range(10, 20); +select count(*) from test_range_gist where ir = int4range(10, 20); -select COUNT(*) from test_range_gist where ir @> 10; +select count(*) from test_range_gist where ir @> 10; -select COUNT(*) from test_range_gist where ir @> int4range(10, 20); +select count(*) from test_range_gist where ir @> int4range(10, 20); -select COUNT(*) from test_range_gist where ir && int4range(10, 20); +select count(*) from test_range_gist where ir && int4range(10, 20); -select COUNT(*) from test_range_gist where ir <@ int4range(10, 50); +select count(*) from test_range_gist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_gist where ir << int4range(100, 500); +select count(*) from test_range_gist where ir << int4range(100, 500); -select COUNT(*) from test_range_gist where ir >> int4range(100, 500); +select count(*) from test_range_gist where ir >> int4range(100, 500); -select COUNT(*) from test_range_gist where ir &< int4range(100, 500); +select count(*) from test_range_gist where ir &< int4range(100, 500); -select COUNT(*) from test_range_gist where ir &> int4range(100, 500); +select count(*) from test_range_gist where ir &> int4range(100, 500); -select COUNT(*) from test_range_gist where ir -|- int4range(100, 500); +select count(*) from test_range_gist where ir -|- int4range(100, 500); -select COUNT(*) from test_range_gist where ir @> cast('{}' as int4multirange); +select count(*) from test_range_gist where ir @> cast('{}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir @> - int4multirange( - int4range(10, 20), - int4range(30, 40) - ); + ir @> int4multirange(int4range(10, 20), int4range(30, 40)); select - COUNT(*) + count(*) from test_range_gist where - ir && - cast('{(10,20),(30,40),(50,60)}' - as int4multirange); + ir && cast('{(10,20),(30,40),(50,60)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir <@ - cast('{(10,30),(40,60),(70,90)}' - as int4multirange); + ir <@ cast('{(10,30),(40,60),(70,90)}' as int4multirange); select - COUNT(*) + count(*) from test_range_gist where - ir << - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir << int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir >> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir >> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &< - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &< int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir &> - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir &> int4multirange(int4range(100, 200), int4range(400, 500)); select - COUNT(*) + count(*) from test_range_gist where - ir -|- - int4multirange( - int4range(100, 200), - int4range(400, 500) - ); + ir -|- int4multirange(int4range(100, 200), int4range(400, 500)); create table test_range_spgist (ir int4range); -create index "test_range_spgist_idx" on test_range_spgist using spgist (ir); +create index test_range_spgist_idx on test_range_spgist using spgist (ir); insert into test_range_spgist -select - int4range(g, g + 10) -from - generate_series(1, 2000) as g; +select int4range(g, g + 10) from generate_series(1, 2000) as g; insert into test_range_spgist -select - cast('empty' as int4range) -from - generate_series(1, 500) as g; +select cast('empty' as int4range) from generate_series(1, 500) as g; insert into test_range_spgist -select - int4range(g, g + 10000) -from - generate_series(1, 1000) as g; +select int4range(g, g + 10000) from generate_series(1, 1000) as g; insert into test_range_spgist -select - cast('empty' as int4range) -from - generate_series(1, 500) as g; +select cast('empty' as int4range) from generate_series(1, 500) as g; insert into test_range_spgist -select - int4range(null, g * 10, '(]') -from - generate_series(1, 100) as g; +select int4range(null, g * 10, '(]') from generate_series(1, 100) as g; insert into test_range_spgist -select - int4range(g * 10, null, '(]') -from - generate_series(1, 100) as g; +select int4range(g * 10, null, '(]') from generate_series(1, 100) as g; insert into test_range_spgist -select - int4range(g, g + 10) -from - generate_series(1, 2000) as g; +select int4range(g, g + 10) from generate_series(1, 2000) as g; set enable_seqscan = t; @@ -788,27 +659,27 @@ set enable_indexscan = f; set enable_bitmapscan = f; -select COUNT(*) from test_range_spgist where ir @> cast('empty' as int4range); +select count(*) from test_range_spgist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_spgist where ir = int4range(10, 20); +select count(*) from test_range_spgist where ir = int4range(10, 20); -select COUNT(*) from test_range_spgist where ir @> 10; +select count(*) from test_range_spgist where ir @> 10; -select COUNT(*) from test_range_spgist where ir @> int4range(10, 20); +select count(*) from test_range_spgist where ir @> int4range(10, 20); -select COUNT(*) from test_range_spgist where ir && int4range(10, 20); +select count(*) from test_range_spgist where ir && int4range(10, 20); -select COUNT(*) from test_range_spgist where ir <@ int4range(10, 50); +select count(*) from test_range_spgist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_spgist where ir << int4range(100, 500); +select count(*) from test_range_spgist where ir << int4range(100, 500); -select COUNT(*) from test_range_spgist where ir >> int4range(100, 500); +select count(*) from test_range_spgist where ir >> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &< int4range(100, 500); +select count(*) from test_range_spgist where ir &< int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &> int4range(100, 500); +select count(*) from test_range_spgist where ir &> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir -|- int4range(100, 500); +select count(*) from test_range_spgist where ir -|- int4range(100, 500); set enable_seqscan = f; @@ -816,53 +687,53 @@ set enable_indexscan = t; set enable_bitmapscan = f; -select COUNT(*) from test_range_spgist where ir @> cast('empty' as int4range); +select count(*) from test_range_spgist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_spgist where ir = int4range(10, 20); +select count(*) from test_range_spgist where ir = int4range(10, 20); -select COUNT(*) from test_range_spgist where ir @> 10; +select count(*) from test_range_spgist where ir @> 10; -select COUNT(*) from test_range_spgist where ir @> int4range(10, 20); +select count(*) from test_range_spgist where ir @> int4range(10, 20); -select COUNT(*) from test_range_spgist where ir && int4range(10, 20); +select count(*) from test_range_spgist where ir && int4range(10, 20); -select COUNT(*) from test_range_spgist where ir <@ int4range(10, 50); +select count(*) from test_range_spgist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_spgist where ir << int4range(100, 500); +select count(*) from test_range_spgist where ir << int4range(100, 500); -select COUNT(*) from test_range_spgist where ir >> int4range(100, 500); +select count(*) from test_range_spgist where ir >> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &< int4range(100, 500); +select count(*) from test_range_spgist where ir &< int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &> int4range(100, 500); +select count(*) from test_range_spgist where ir &> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir -|- int4range(100, 500); +select count(*) from test_range_spgist where ir -|- int4range(100, 500); drop index test_range_spgist_idx; -create index "test_range_spgist_idx" on test_range_spgist using spgist (ir); +create index test_range_spgist_idx on test_range_spgist using spgist (ir); -select COUNT(*) from test_range_spgist where ir @> cast('empty' as int4range); +select count(*) from test_range_spgist where ir @> cast('empty' as int4range); -select COUNT(*) from test_range_spgist where ir = int4range(10, 20); +select count(*) from test_range_spgist where ir = int4range(10, 20); -select COUNT(*) from test_range_spgist where ir @> 10; +select count(*) from test_range_spgist where ir @> 10; -select COUNT(*) from test_range_spgist where ir @> int4range(10, 20); +select count(*) from test_range_spgist where ir @> int4range(10, 20); -select COUNT(*) from test_range_spgist where ir && int4range(10, 20); +select count(*) from test_range_spgist where ir && int4range(10, 20); -select COUNT(*) from test_range_spgist where ir <@ int4range(10, 50); +select count(*) from test_range_spgist where ir <@ int4range(10, 50); -select COUNT(*) from test_range_spgist where ir << int4range(100, 500); +select count(*) from test_range_spgist where ir << int4range(100, 500); -select COUNT(*) from test_range_spgist where ir >> int4range(100, 500); +select count(*) from test_range_spgist where ir >> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &< int4range(100, 500); +select count(*) from test_range_spgist where ir &< int4range(100, 500); -select COUNT(*) from test_range_spgist where ir &> int4range(100, 500); +select count(*) from test_range_spgist where ir &> int4range(100, 500); -select COUNT(*) from test_range_spgist where ir -|- int4range(100, 500); +select count(*) from test_range_spgist where ir -|- int4range(100, 500); select ir from test_range_spgist where ir -|- int4range(10, 20) order by ir; @@ -874,33 +745,31 @@ reset enable_indexscan; reset enable_bitmapscan; -create table test_range_elem (i int); +create table test_range_elem (i int4); -create index "test_range_elem_idx" on test_range_elem using btree (i); +create index test_range_elem_idx on test_range_elem using btree (i); insert into test_range_elem select i from generate_series(1, 100) as i; set enable_seqscan = f; -select COUNT(*) from test_range_elem where i <@ int4range(10, 50); +select count(*) from test_range_elem where i <@ int4range(10, 50); create index on test_range_elem using spgist ((int4range(i, i + 10))); select - COUNT(*) + count(*) from test_range_elem where - int4range(i, i + 10) <@ - int4range(10, 30); + int4range(i, i + 10) <@ int4range(10, 30); select - COUNT(*) + count(*) from test_range_elem where - int4range(i, i + 10) <@ - int4range(10, 30); + int4range(i, i + 10) <@ int4range(10, 30); reset enable_seqscan; @@ -910,10 +779,8 @@ create table test_range_excl ( room int4range, speaker int4range, during tsrange, - exclude using gist (room with =, - during with &&), - exclude using gist (speaker with =, - during with &&) + exclude using gist (room with =, during with &&), + exclude using gist (speaker with =, during with &&) ); insert into test_range_excl @@ -956,12 +823,7 @@ values '[2010-01-02 10:10, 2010-01-02 11:00)' ); -select - int8range( - cast(10000000000 as bigint), - cast(20000000000 as bigint), - '(]' - ); +select int8range(cast(10000000000 as int8), cast(20000000000 as int8), '(]'); set time zone '-08'; @@ -972,13 +834,11 @@ select cast('[2010-01-01 01:00:00 -08, 2010-01-01 02:00:00 -05)' as tstzrange); set timezone to default; create type bogus_float8range as range ( - subtype = double precision, + subtype = float8, subtype_diff = float4mi ); -select - cast('[123.001, 5.e9)' as float8range) @> - cast(888.882 as double precision); +select cast('[123.001, 5.e9)' as float8range) @> cast(888.882 as float8); create table float8range_test ( f8r float8range, @@ -991,7 +851,7 @@ select * from float8range_test; drop table float8range_test; -create domain mydomain as int; +create domain mydomain as int4; create type mydomainrange as range (subtype = mydomain); @@ -1009,9 +869,9 @@ select cast('[4,50)' as restrictedrange) @> 7; drop domain restrictedrange; -create type textrange1 as range (subtype = text, collation = "C"); +create type textrange1 as range (subtype = text, "collation" = "C"); -create type textrange2 as range (subtype = text, collation = "C"); +create type textrange2 as range (subtype = text, "collation" = "C"); select textrange1('a', 'Z') @> cast('b' as text); @@ -1024,9 +884,7 @@ drop type textrange2; create function anyarray_anyrange_func(a anyarray, r anyrange) returns anyelement language sql -as $function$ -select $1[1] + lower($2); -$function$; +as 'select $1[1] + lower($2);'; select anyarray_anyrange_func(array[1, 2], int4range(10, 20)); @@ -1037,23 +895,17 @@ drop function anyarray_anyrange_func(anyarray, anyrange); create function bogus_func(anyelement) returns anyrange language sql -as $function$ -select int4range(1,10) -$function$; +as 'select int4range(1,10)'; create function bogus_func(int) returns anyrange language sql -as $function$ -select int4range(1,10) -$function$; +as 'select int4range(1,10)'; create function range_add_bounds(anyrange) returns anyelement language sql -as $function$ -select lower($1) + upper($1) -$function$; +as 'select lower($1) + upper($1)'; select range_add_bounds(int4range(1, 17)); @@ -1061,9 +913,7 @@ select range_add_bounds(numrange(1.0001, 123.123)); create function rangetypes_sql(q anyrange, b anyarray, out c anyelement) language sql -as $function$ -select upper($1) + $2[1] -$function$; +as $$ select upper($1) + $2[1] $$; select rangetypes_sql(int4range(1, 10), array[2, 20]); @@ -1076,27 +926,16 @@ anycompatiblearray_anycompatiblerange_func( ) returns anycompatible language sql -as $function$ -select $1[1] + lower($2); -$function$; +as 'select $1[1] + lower($2);'; select - anycompatiblearray_anycompatiblerange_func( - array[1, 2], - int4range(10, 20) - ); + anycompatiblearray_anycompatiblerange_func(array[1, 2], int4range(10, 20)); select - anycompatiblearray_anycompatiblerange_func( - array[1, 2], - numrange(10, 20) - ); + anycompatiblearray_anycompatiblerange_func(array[1, 2], numrange(10, 20)); select - anycompatiblearray_anycompatiblerange_func( - array[1.1, 2], - int4range(10, 20) - ); + anycompatiblearray_anycompatiblerange_func(array[1.1, 2], int4range(10, 20)); drop function anycompatiblearray_anycompatiblerange_func( @@ -1106,9 +945,7 @@ drop function create function bogus_func(anycompatible) returns anycompatiblerange language sql -as $function$ -select int4range(1,10) -$function$; +as 'select int4range(1,10)'; select array[numrange(1.1, 1.2), numrange(12.3, 155.5)]; @@ -1123,7 +960,7 @@ select * from i8r_array; drop table i8r_array; -create type arrayrange as range (subtype = int[]); +create type arrayrange as range (subtype = int4[]); select arrayrange(array[1, 2], array[2, 1]); @@ -1153,7 +990,7 @@ alter type two_ints drop type two_ints cascade; -create type varbitrange as range (subtype = bit varying); +create type varbitrange as range (subtype = varbit); set enable_sort = off; @@ -1165,33 +1002,25 @@ reset enable_sort; create function outparam_succeed(i anyrange, out r anyrange, out t text) language sql -as $function$ -select $1, 'foo'::text -$function$; +as $$ select $1, 'foo'::text $$; select * from outparam_succeed(int4range(1, 2)); create function outparam2_succeed(r anyrange, out lu anyarray, out ul anyarray) language sql -as $function$ -select array[lower($1), upper($1)], array[upper($1), lower($1)] -$function$; +as $$ select array[lower($1), upper($1)], array[upper($1), lower($1)] $$; select * from outparam2_succeed(int4range(1, 11)); create function outparam_succeed2(i anyrange, out r anyarray, out t text) language sql -as $function$ -select ARRAY[upper($1)], 'foo'::text -$function$; +as $$ select ARRAY[upper($1)], 'foo'::text $$; select * from outparam_succeed2(int4range(int4range(1, 2))); create function inoutparam_succeed(out i anyelement, inout r anyrange) language sql -as $function$ -select upper($1), $1 -$function$; +as $$ select upper($1), $1 $$; select * from inoutparam_succeed(int4range(1, 2)); @@ -1201,23 +1030,17 @@ returns table ( u anyelement ) language sql -as $function$ -select lower($1), upper($1) -$function$; +as $$ select lower($1), upper($1) $$; select * from table_succeed(int4range(1, 11)); create function outparam_fail(i anyelement, out r anyrange, out t text) language sql -as $function$ -select '[1,10]', 'foo' -$function$; +as $$ select '[1,10]', 'foo' $$; create function inoutparam_fail(inout i anyelement, out r anyrange) language sql -as $function$ -select $1, '[1,10]' -$function$; +as $$ select $1, '[1,10]' $$; create function table_fail(i anyelement) returns table ( @@ -1225,9 +1048,7 @@ returns table ( r anyrange ) language sql -as $function$ -select $1, '[1,10]' -$function$; +as $$ select $1, '[1,10]' $$; select current_date <@ cast('empty' as daterange); @@ -1249,7 +1070,7 @@ select daterange('-Infinity', cast('1997-04-10' as date), '()') @> current_date; select daterange(cast('2002-09-25' as date), 'Infinity', '[]') @> current_date; -select NOW() <@ tstzrange('2024-01-20 00:00', '2024-01-21 00:00'); +select now() <@ tstzrange('2024-01-20 00:00', '2024-01-21 00:00'); select clock_timestamp() <@ tstzrange('2024-01-20 00:00', '2024-01-21 00:00'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__regex_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__regex_100.snap index 8c43679ce..87204e3b1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__regex_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__regex_100.snap @@ -27,11 +27,11 @@ select 'abc abd abc' ~ '^(.+)( \1)+$' as f; select 'abc abc abd' ~ '^(.+)( \1)+$' as f; -select SUBSTRING('asd TO foo' from ' TO (([a-z0-9._]+|"([^"]+|"")+")+)'); +select substring('asd TO foo' from ' TO (([a-z0-9._]+|"([^"]+|"")+")+)'); -select SUBSTRING('a' from '((a))+'); +select substring('a' from '((a))+'); -select SUBSTRING('a' from '((a)+)'); +select substring('a' from '((a)+)'); select regexp_match('abc', ''); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__regex_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__regex_80.snap index 089336a60..8cb4828e0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__regex_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__regex_80.snap @@ -27,11 +27,11 @@ select 'abc abd abc' ~ '^(.+)( \1)+$' as f; select 'abc abc abd' ~ '^(.+)( \1)+$' as f; -select SUBSTRING('asd TO foo' from ' TO (([a-z0-9._]+|"([^"]+|"")+")+)'); +select substring('asd TO foo' from ' TO (([a-z0-9._]+|"([^"]+|"")+")+)'); -select SUBSTRING('a' from '((a))+'); +select substring('a' from '((a))+'); -select SUBSTRING('a' from '((a)+)'); +select substring('a' from '((a)+)'); select regexp_match('abc', ''); @@ -160,11 +160,7 @@ select 'Programmer' ~ '(\w).*?\1' as t; select regexp_matches('Programmer', '(\w)(.*?\1)', 'g'); select - regexp_matches( - 'foo/bar/baz', - '^([^/]+?)(?:/([^/]+?))(?:/([^/]+?))?$', - '' - ); + regexp_matches('foo/bar/baz', '^([^/]+?)(?:/([^/]+?))(?:/([^/]+?))?$', ''); select regexp_matches('llmmmfff', '^(l*)(.*)(f*)$'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__regproc_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__regproc_80.snap index 3c9ed2b15..48b000079 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__regproc_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__regproc_80.snap @@ -120,13 +120,11 @@ select cast(to_regnamespace('-') as oid); select cast(to_regdatabase('-') as oid); create table regrole_test ( - rolid oid - default cast('regress_regrole_test' as regrole) + rolid oid default cast('regress_regrole_test' as regrole) ); create table regdatabase_test ( - datid oid - default cast('template1' as regdatabase) + datid oid default cast('template1' as regdatabase) ); drop role regress_regrole_test; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__reloptions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__reloptions_100.snap index 5839e981b..94420d7c0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__reloptions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__reloptions_100.snap @@ -4,11 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/reloptions.sql snapshot_kind: text --- create table reloptions_test (i int) -with ( - fillfactor = 30, - autovacuum_enabled = 'false', - autovacuum_analyze_scale_factor = 0.2 -); +with (fillfactor = 30, autovacuum_enabled = 'false', autovacuum_analyze_scale_factor = 0.2); select reloptions from pg_class where oid = cast('reloptions_test' as regclass); @@ -45,8 +41,7 @@ create table reloptions_test2 (i int) with (fillfactor = 30, fillfactor = 40); create table reloptions_test2 (i int) with (fillfactor); alter table reloptions_test - set (fillfactor = 31, - autovacuum_analyze_scale_factor = 0.3); + set (fillfactor = 31, autovacuum_analyze_scale_factor = 0.3); select reloptions from pg_class where oid = cast('reloptions_test' as regclass); @@ -61,16 +56,14 @@ alter table reloptions_test select reloptions from pg_class where oid = cast('reloptions_test' as regclass); alter table reloptions_test - reset (autovacuum_enabled, - autovacuum_analyze_scale_factor); + reset (autovacuum_enabled, autovacuum_analyze_scale_factor); select reloptions from pg_class where - oid = cast('reloptions_test' as regclass) and - reloptions is null; + oid = cast('reloptions_test' as regclass) and reloptions is null; alter table reloptions_test reset (fillfactor = 12); @@ -91,17 +84,13 @@ create temporary table reloptions_test ( i int not null, j text ) -with ( - vacuum_truncate = 'false', - toast.vacuum_truncate = 'false', - autovacuum_enabled = 'false' -); +with (vacuum_truncate = 'false', toast.vacuum_truncate = 'false', autovacuum_enabled = 'false'); select reloptions from pg_class where oid = cast('reloptions_test' as regclass); insert into reloptions_test values (1, null), (null, null); -vacuum (FREEZE, DISABLE_PAGE_SKIPPING) reloptions_test; +vacuum (freeze, disable_page_skipping) reloptions_test; select pg_relation_size('reloptions_test') > 0; @@ -110,15 +99,7 @@ select from pg_class where - oid = - ( - select - reltoastrelid - from - pg_class - where - oid = cast('reloptions_test' as regclass) - ); + oid = (select reltoastrelid from pg_class where oid = cast('reloptions_test' as regclass)); alter table reloptions_test reset (vacuum_truncate); @@ -127,7 +108,7 @@ select reloptions from pg_class where oid = cast('reloptions_test' as regclass); insert into reloptions_test values (1, null), (null, null); -vacuum (FREEZE, DISABLE_PAGE_SKIPPING) reloptions_test; +vacuum (freeze, disable_page_skipping) reloptions_test; select pg_relation_size('reloptions_test') = 0; @@ -154,11 +135,7 @@ create table reloptions_test2 (i int) with (toast.not_existing_option = 42); drop table reloptions_test; create table reloptions_test (s varchar) -with ( - toast.autovacuum_vacuum_cost_delay = 23, - autovacuum_vacuum_cost_delay = 24, - fillfactor = 40 -); +with (toast.autovacuum_vacuum_cost_delay = 23, autovacuum_vacuum_cost_delay = 24, fillfactor = 40); select reloptions from pg_class where oid = cast('reloptions_test' as regclass); @@ -167,64 +144,27 @@ select from pg_class where - oid = - ( - select - reltoastrelid - from - pg_class - where - oid = cast('reloptions_test' as regclass) - ); - -create index "reloptions_test_idx" -on reloptions_test -using btree -( - s -) -with (fillfactor = 30); + oid = (select reltoastrelid from pg_class where oid = cast('reloptions_test' as regclass)); + +create index reloptions_test_idx on reloptions_test using btree (s) with (fillfactor = 30); select reloptions from pg_class where oid = cast('reloptions_test_idx' as regclass); -create index "reloptions_test_idx" -on reloptions_test -using btree -( - s -) -with (not_existing_option = 2); +create index reloptions_test_idx on reloptions_test using btree (s) with (not_existing_option = 2); -create index "reloptions_test_idx" -on reloptions_test -using btree -( - s -) +create index reloptions_test_idx on reloptions_test using btree (s) with (not_existing_ns.fillfactor = 2); -create index "reloptions_test_idx2" -on reloptions_test -using btree -( - s -) -with (fillfactor = 1); +create index reloptions_test_idx2 on reloptions_test using btree (s) with (fillfactor = 1); -create index "reloptions_test_idx2" -on reloptions_test -using btree -( - s -) -with (fillfactor = 130); +create index reloptions_test_idx2 on reloptions_test using btree (s) with (fillfactor = 130); alter index reloptions_test_idx set (fillfactor = 40); select reloptions from pg_class where oid = cast('reloptions_test_idx' as regclass); -create index "reloptions_test_idx3" on reloptions_test using btree (s); +create index reloptions_test_idx3 on reloptions_test using btree (s); alter index reloptions_test_idx3 set (fillfactor = 40); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__reloptions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__reloptions_80.snap index 92c585fda..bf48435b8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__reloptions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__reloptions_80.snap @@ -17,14 +17,10 @@ create table reloptions_test2 (i int) with (fillfactor = 2); create table reloptions_test2 (i int) with (fillfactor = 110); create table reloptions_test2 (i int) -with ( - autovacuum_analyze_scale_factor = -10.0 -); +with (autovacuum_analyze_scale_factor = -10.0); create table reloptions_test2 (i int) -with ( - autovacuum_analyze_scale_factor = 110.0 -); +with (autovacuum_analyze_scale_factor = 110.0); create table reloptions_test2 (i int) with (not_existing_option = 2); @@ -44,22 +40,17 @@ create table reloptions_test2 (i int) with (autovacuum_enabled = 30.5); create table reloptions_test2 (i int) with (autovacuum_enabled = 'string'); create table reloptions_test2 (i int) -with ( - autovacuum_analyze_scale_factor = 'string' -); +with (autovacuum_analyze_scale_factor = 'string'); create table reloptions_test2 (i int) -with ( - autovacuum_analyze_scale_factor = 'true' -); +with (autovacuum_analyze_scale_factor = 'true'); create table reloptions_test2 (i int) with (fillfactor = 30, fillfactor = 40); create table reloptions_test2 (i int) with (fillfactor); alter table reloptions_test - set (fillfactor = 31, - autovacuum_analyze_scale_factor = 0.3); + set (fillfactor = 31, autovacuum_analyze_scale_factor = 0.3); select reloptions from pg_class where oid = cast('reloptions_test' as regclass); @@ -74,17 +65,14 @@ alter table reloptions_test select reloptions from pg_class where oid = cast('reloptions_test' as regclass); alter table reloptions_test - reset (autovacuum_enabled, - autovacuum_analyze_scale_factor); + reset (autovacuum_enabled, autovacuum_analyze_scale_factor); select reloptions from pg_class where - oid = - cast('reloptions_test' as regclass) and - reloptions is null; + oid = cast('reloptions_test' as regclass) and reloptions is null; alter table reloptions_test reset (fillfactor = 12); @@ -92,8 +80,7 @@ alter table reloptions_test update pg_class set reloptions = '{fillfactor=13,autovacuum_enabled=false,illegal_option=4}' where - oid = - cast('reloptions_test' as regclass); + oid = cast('reloptions_test' as regclass); alter table reloptions_test reset (illegal_option); @@ -116,7 +103,7 @@ select reloptions from pg_class where oid = cast('reloptions_test' as regclass); insert into reloptions_test values (1, null), (null, null); -vacuum (FREEZE, DISABLE_PAGE_SKIPPING) reloptions_test; +vacuum (freeze, disable_page_skipping) reloptions_test; select pg_relation_size('reloptions_test') > 0; @@ -132,8 +119,7 @@ where from pg_class where - oid = - cast('reloptions_test' as regclass) + oid = cast('reloptions_test' as regclass) ); alter table reloptions_test @@ -143,24 +129,21 @@ select reloptions from pg_class where oid = cast('reloptions_test' as regclass); insert into reloptions_test values (1, null), (null, null); -vacuum (FREEZE, DISABLE_PAGE_SKIPPING) reloptions_test; +vacuum (freeze, disable_page_skipping) reloptions_test; select pg_relation_size('reloptions_test') = 0; drop table reloptions_test; create table reloptions_test (s varchar) -with ( - toast.autovacuum_vacuum_cost_delay = 23 -); +with (toast.autovacuum_vacuum_cost_delay = 23); select reltoastrelid as toast_oid from pg_class where - oid = - cast('reloptions_test' as regclass); + oid = cast('reloptions_test' as regclass); select reloptions from pg_class where oid = 'toast_oid'; @@ -199,16 +182,10 @@ where from pg_class where - oid = - cast('reloptions_test' as regclass) + oid = cast('reloptions_test' as regclass) ); -create index "reloptions_test_idx" -on reloptions_test -using btree -( - s -) +create index reloptions_test_idx on reloptions_test using btree (s) with (fillfactor = 30); select @@ -216,39 +193,18 @@ select from pg_class where - oid = - cast('reloptions_test_idx' as regclass); + oid = cast('reloptions_test_idx' as regclass); -create index "reloptions_test_idx" -on reloptions_test -using btree -( - s -) +create index reloptions_test_idx on reloptions_test using btree (s) with (not_existing_option = 2); -create index "reloptions_test_idx" -on reloptions_test -using btree -( - s -) +create index reloptions_test_idx on reloptions_test using btree (s) with (not_existing_ns.fillfactor = 2); -create index "reloptions_test_idx2" -on reloptions_test -using btree -( - s -) +create index reloptions_test_idx2 on reloptions_test using btree (s) with (fillfactor = 1); -create index "reloptions_test_idx2" -on reloptions_test -using btree -( - s -) +create index reloptions_test_idx2 on reloptions_test using btree (s) with (fillfactor = 130); alter index reloptions_test_idx @@ -259,10 +215,9 @@ select from pg_class where - oid = - cast('reloptions_test_idx' as regclass); + oid = cast('reloptions_test_idx' as regclass); -create index "reloptions_test_idx3" on reloptions_test using btree (s); +create index reloptions_test_idx3 on reloptions_test using btree (s); alter index reloptions_test_idx3 set (fillfactor = 40); @@ -272,5 +227,4 @@ select from pg_class where - oid = - cast('reloptions_test_idx3' as regclass); + oid = cast('reloptions_test_idx3' as regclass); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__replica_identity_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__replica_identity_100.snap index 8f1073a83..7c7937db7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__replica_identity_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__replica_identity_100.snap @@ -8,56 +8,36 @@ create table test_replica_identity ( keya text not null, keyb text not null, nonkey text, - constraint "test_replica_identity_unique_defer" unique (keya, - keyb) deferrable, - constraint "test_replica_identity_unique_nondefer" unique (keya, - keyb) + constraint test_replica_identity_unique_defer unique (keya, keyb) deferrable, + constraint test_replica_identity_unique_nondefer unique (keya, keyb) ); create table test_replica_identity_othertable (id serial primary key); -create table test_replica_identity_t3 (id serial constraint "pk" primary key deferrable); +create table test_replica_identity_t3 (id serial constraint pk primary key deferrable); -create index "test_replica_identity_keyab" on test_replica_identity using btree (keya, keyb); +create index test_replica_identity_keyab on test_replica_identity using btree (keya, keyb); -create unique -index "test_replica_identity_keyab_key" -on test_replica_identity -using btree -( +create unique index test_replica_identity_keyab_key on test_replica_identity using btree ( keya, keyb ); -create unique index "test_replica_identity_nonkey" -on test_replica_identity -using btree -( +create unique index test_replica_identity_nonkey on test_replica_identity using btree ( keya, nonkey ); -create index "test_replica_identity_hash" on test_replica_identity using hash (nonkey); +create index test_replica_identity_hash on test_replica_identity using hash (nonkey); -create unique index "test_replica_identity_expr" -on test_replica_identity -using btree -( +create unique index test_replica_identity_expr on test_replica_identity using btree ( keya, keyb, (3) ); -create unique -index "test_replica_identity_partial" -on test_replica_identity -using btree -( - keya, - keyb -) -where - keyb <> '3'; +create unique index test_replica_identity_partial on test_replica_identity using btree (keya, keyb) +where keyb <> '3'; select relreplident from pg_class where oid = cast('test_replica_identity' as regclass); @@ -66,39 +46,25 @@ select relreplident from pg_class where oid = cast('pg_class' as regclass); select relreplident from pg_class where oid = cast('pg_constraint' as regclass); alter table test_replica_identity - replica identity - using index - test_replica_identity_keyab; + replica identity using index test_replica_identity_keyab; alter table test_replica_identity - replica identity - using index - test_replica_identity_nonkey; + replica identity using index test_replica_identity_nonkey; alter table test_replica_identity - replica identity - using index - test_replica_identity_hash; + replica identity using index test_replica_identity_hash; alter table test_replica_identity - replica identity - using index - test_replica_identity_expr; + replica identity using index test_replica_identity_expr; alter table test_replica_identity - replica identity - using index - test_replica_identity_partial; + replica identity using index test_replica_identity_partial; alter table test_replica_identity - replica identity - using index - test_replica_identity_othertable_pkey; + replica identity using index test_replica_identity_othertable_pkey; alter table test_replica_identity - replica identity - using index - test_replica_identity_unique_defer; + replica identity using index test_replica_identity_unique_defer; alter table test_replica_identity_t3 replica identity using index pk; @@ -106,37 +72,27 @@ alter table test_replica_identity_t3 select relreplident from pg_class where oid = cast('test_replica_identity' as regclass); alter table test_replica_identity - replica identity - using index - test_replica_identity_pkey; + replica identity using index test_replica_identity_pkey; select relreplident from pg_class where oid = cast('test_replica_identity' as regclass); alter table test_replica_identity - replica identity - using index - test_replica_identity_unique_nondefer; + replica identity using index test_replica_identity_unique_nondefer; alter table test_replica_identity - replica identity - using index - test_replica_identity_keyab_key; + replica identity using index test_replica_identity_keyab_key; alter table test_replica_identity - replica identity - using index - test_replica_identity_keyab_key; + replica identity using index test_replica_identity_keyab_key; select relreplident from pg_class where oid = cast('test_replica_identity' as regclass); select - COUNT(*) + count(*) from pg_index where - indrelid = - cast('test_replica_identity' as regclass) and - indisreplident; + indrelid = cast('test_replica_identity' as regclass) and indisreplident; alter table test_replica_identity replica identity default; @@ -144,13 +100,11 @@ alter table test_replica_identity select relreplident from pg_class where oid = cast('test_replica_identity' as regclass); select - COUNT(*) + count(*) from pg_index where - indrelid = - cast('test_replica_identity' as regclass) and - indisreplident; + indrelid = cast('test_replica_identity' as regclass) and indisreplident; alter table test_replica_identity replica identity full; @@ -165,21 +119,17 @@ select relreplident from pg_class where oid = cast('test_replica_identity' as re create table test_replica_identity2 (id int unique not null); alter table test_replica_identity2 - replica identity - using index - test_replica_identity2_id_key; + replica identity using index test_replica_identity2_id_key; alter table test_replica_identity2 alter column id type bigint; create table test_replica_identity3 (id int not null); -create unique index "test_replica_identity3_id_key" on test_replica_identity3 using btree (id); +create unique index test_replica_identity3_id_key on test_replica_identity3 using btree (id); alter table test_replica_identity3 - replica identity - using index - test_replica_identity3_id_key; + replica identity using index test_replica_identity3_id_key; alter table test_replica_identity3 alter column id type bigint; @@ -194,7 +144,7 @@ alter table test_replica_identity3 alter column id drop not null; create table test_replica_identity4 (id int not null) -partition by LIST(id); +partition by list(id); create table test_replica_identity4_1 (id int not null); @@ -203,15 +153,13 @@ alter table only test_replica_identity4 test_replica_identity4_1 for values in (1); alter table only test_replica_identity4 - add constraint "test_replica_identity4_pkey" primary key (id); + add constraint test_replica_identity4_pkey primary key (id); alter table only test_replica_identity4 - replica identity - using index - test_replica_identity4_pkey; + replica identity using index test_replica_identity4_pkey; alter table only test_replica_identity4_1 - add constraint "test_replica_identity4_1_pkey" primary key (id); + add constraint test_replica_identity4_1_pkey primary key (id); alter index test_replica_identity4_pkey attach partition @@ -224,12 +172,10 @@ create table test_replica_identity5 ( primary key (b, c) ); -create unique index "test_replica_identity5_a_b_key" on test_replica_identity5 using btree (a, b); +create unique index test_replica_identity5_a_b_key on test_replica_identity5 using btree (a, b); alter table test_replica_identity5 - replica identity - using index - test_replica_identity5_a_b_key; + replica identity using index test_replica_identity5_a_b_key; alter table test_replica_identity5 drop constraint test_replica_identity5_pkey; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__replica_identity_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__replica_identity_80.snap index bffa4233f..81531bf39 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__replica_identity_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__replica_identity_80.snap @@ -8,121 +8,73 @@ create table test_replica_identity ( keya text not null, keyb text not null, nonkey text, - constraint "test_replica_identity_unique_defer" unique (keya, - keyb) deferrable, - constraint "test_replica_identity_unique_nondefer" unique (keya, - keyb) + constraint test_replica_identity_unique_defer unique (keya, keyb) deferrable, + constraint test_replica_identity_unique_nondefer unique (keya, keyb) ); create table test_replica_identity_othertable (id serial primary key); create table test_replica_identity_t3 ( - id serial - constraint "pk" primary key - deferrable + id serial constraint pk primary key deferrable ); -create index "test_replica_identity_keyab" -on test_replica_identity -using btree -( +create index test_replica_identity_keyab on test_replica_identity using btree ( keya, keyb ); -create unique -index "test_replica_identity_keyab_key" -on test_replica_identity -using btree -( - keya, - keyb -); +create unique index test_replica_identity_keyab_key + on test_replica_identity + using btree (keya, keyb); -create unique -index "test_replica_identity_nonkey" -on test_replica_identity -using btree -( - keya, - nonkey -); +create unique index test_replica_identity_nonkey + on test_replica_identity + using btree (keya, nonkey); -create index "test_replica_identity_hash" -on test_replica_identity -using hash -( +create index test_replica_identity_hash on test_replica_identity using hash ( nonkey ); -create unique -index "test_replica_identity_expr" -on test_replica_identity -using btree -( - keya, - keyb, - (3) -); +create unique index test_replica_identity_expr + on test_replica_identity + using btree (keya, keyb, (3)); -create unique -index "test_replica_identity_partial" -on test_replica_identity -using btree -( - keya, - keyb -) -where - keyb <> '3'; +create unique index test_replica_identity_partial + on test_replica_identity + using btree (keya, keyb) +where keyb <> '3'; select relreplident from pg_class where - oid = - cast('test_replica_identity' - as regclass); + oid = cast('test_replica_identity' as regclass); select relreplident from pg_class where oid = cast('pg_class' as regclass); select relreplident from pg_class where oid = cast('pg_constraint' as regclass); alter table test_replica_identity - replica identity - using index - test_replica_identity_keyab; + replica identity using index test_replica_identity_keyab; alter table test_replica_identity - replica identity - using index - test_replica_identity_nonkey; + replica identity using index test_replica_identity_nonkey; alter table test_replica_identity - replica identity - using index - test_replica_identity_hash; + replica identity using index test_replica_identity_hash; alter table test_replica_identity - replica identity - using index - test_replica_identity_expr; + replica identity using index test_replica_identity_expr; alter table test_replica_identity - replica identity - using index - test_replica_identity_partial; + replica identity using index test_replica_identity_partial; alter table test_replica_identity - replica identity - using index - test_replica_identity_othertable_pkey; + replica identity using index test_replica_identity_othertable_pkey; alter table test_replica_identity - replica identity - using index - test_replica_identity_unique_defer; + replica identity using index test_replica_identity_unique_defer; alter table test_replica_identity_t3 replica identity using index pk; @@ -132,57 +84,40 @@ select from pg_class where - oid = - cast('test_replica_identity' - as regclass); + oid = cast('test_replica_identity' as regclass); alter table test_replica_identity - replica identity - using index - test_replica_identity_pkey; + replica identity using index test_replica_identity_pkey; select relreplident from pg_class where - oid = - cast('test_replica_identity' - as regclass); + oid = cast('test_replica_identity' as regclass); alter table test_replica_identity - replica identity - using index - test_replica_identity_unique_nondefer; + replica identity using index test_replica_identity_unique_nondefer; alter table test_replica_identity - replica identity - using index - test_replica_identity_keyab_key; + replica identity using index test_replica_identity_keyab_key; alter table test_replica_identity - replica identity - using index - test_replica_identity_keyab_key; + replica identity using index test_replica_identity_keyab_key; select relreplident from pg_class where - oid = - cast('test_replica_identity' - as regclass); + oid = cast('test_replica_identity' as regclass); select - COUNT(*) + count(*) from pg_index where - indrelid = - cast('test_replica_identity' - as regclass) and - indisreplident; + indrelid = cast('test_replica_identity' as regclass) and indisreplident; alter table test_replica_identity replica identity default; @@ -192,19 +127,14 @@ select from pg_class where - oid = - cast('test_replica_identity' - as regclass); + oid = cast('test_replica_identity' as regclass); select - COUNT(*) + count(*) from pg_index where - indrelid = - cast('test_replica_identity' - as regclass) and - indisreplident; + indrelid = cast('test_replica_identity' as regclass) and indisreplident; alter table test_replica_identity replica identity full; @@ -214,9 +144,7 @@ select from pg_class where - oid = - cast('test_replica_identity' - as regclass); + oid = cast('test_replica_identity' as regclass); alter table test_replica_identity replica identity nothing; @@ -226,34 +154,24 @@ select from pg_class where - oid = - cast('test_replica_identity' - as regclass); + oid = cast('test_replica_identity' as regclass); create table test_replica_identity2 (id int unique not null); alter table test_replica_identity2 - replica identity - using index - test_replica_identity2_id_key; + replica identity using index test_replica_identity2_id_key; alter table test_replica_identity2 alter column id type bigint; create table test_replica_identity3 (id int not null); -create unique -index "test_replica_identity3_id_key" -on test_replica_identity3 -using btree -( - id -); +create unique index test_replica_identity3_id_key + on test_replica_identity3 + using btree (id); alter table test_replica_identity3 - replica identity - using index - test_replica_identity3_id_key; + replica identity using index test_replica_identity3_id_key; alter table test_replica_identity3 alter column id type bigint; @@ -268,25 +186,22 @@ alter table test_replica_identity3 alter column id drop not null; create table test_replica_identity4 (id int not null) -partition by LIST(id); +partition by list(id); create table test_replica_identity4_1 (id int not null); alter table only test_replica_identity4 attach partition - test_replica_identity4_1 - for values in (1); + test_replica_identity4_1 for values in (1); alter table only test_replica_identity4 - add constraint "test_replica_identity4_pkey" primary key (id); + add constraint test_replica_identity4_pkey primary key (id); alter table only test_replica_identity4 - replica identity - using index - test_replica_identity4_pkey; + replica identity using index test_replica_identity4_pkey; alter table only test_replica_identity4_1 - add constraint "test_replica_identity4_1_pkey" primary key (id); + add constraint test_replica_identity4_1_pkey primary key (id); alter index test_replica_identity4_pkey attach partition @@ -299,19 +214,12 @@ create table test_replica_identity5 ( primary key (b, c) ); -create unique -index "test_replica_identity5_a_b_key" -on test_replica_identity5 -using btree -( - a, - b -); +create unique index test_replica_identity5_a_b_key + on test_replica_identity5 + using btree (a, b); alter table test_replica_identity5 - replica identity - using index - test_replica_identity5_a_b_key; + replica identity using index test_replica_identity5_a_b_key; alter table test_replica_identity5 drop constraint test_replica_identity5_pkey; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__reserved_keyword_idents_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__reserved_keyword_idents_100.snap index 18de13a20..3698be4be 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__reserved_keyword_idents_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__reserved_keyword_idents_100.snap @@ -21,16 +21,7 @@ create collation "primary" from "default"; create index "primary" on t1 using btree (x); -create unique index "i1" -on t1 -using btree -( - x, - "primary" -) -tablespace "primary" -where - "primary"; +create unique index i1 on t1 using btree (x, "primary") tablespace "primary" where "primary"; cluster t1 using "primary"; @@ -97,7 +88,7 @@ drop tablespace "primary"; alter table all in tablespace "primary" set tablespace "select"; -create index "i2" on t1 using "primary" (x); +create index i2 on t1 using "primary" (x); create access method "primary" type index handler h; @@ -108,7 +99,7 @@ alter operator family of1 using "primary" add operator 1 = (int, int); create operator class oc1 for type int using "primary" as operator 1 =; alter table t1 - add constraint "e1" exclude using "primary" (x with =); + add constraint e1 exclude using "primary" (x with =); create transform for int language "primary" ( @@ -117,7 +108,7 @@ create transform for int language "primary" ); create table t3 (x int) -partition by LIST("primary"); +partition by list("primary"); alter table t1 replica identity using index "primary"; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__reserved_keyword_idents_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__reserved_keyword_idents_80.snap index 18de13a20..d7999b2b4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__reserved_keyword_idents_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__reserved_keyword_idents_80.snap @@ -21,16 +21,9 @@ create collation "primary" from "default"; create index "primary" on t1 using btree (x); -create unique index "i1" -on t1 -using btree -( - x, - "primary" -) +create unique index i1 on t1 using btree (x, "primary") tablespace "primary" -where - "primary"; +where "primary"; cluster t1 using "primary"; @@ -97,7 +90,7 @@ drop tablespace "primary"; alter table all in tablespace "primary" set tablespace "select"; -create index "i2" on t1 using "primary" (x); +create index i2 on t1 using "primary" (x); create access method "primary" type index handler h; @@ -108,7 +101,7 @@ alter operator family of1 using "primary" add operator 1 = (int, int); create operator class oc1 for type int using "primary" as operator 1 =; alter table t1 - add constraint "e1" exclude using "primary" (x with =); + add constraint e1 exclude using "primary" (x with =); create transform for int language "primary" ( @@ -117,7 +110,7 @@ create transform for int language "primary" ); create table t3 (x int) -partition by LIST("primary"); +partition by list("primary"); alter table t1 replica identity using index "primary"; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__returning_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__returning_100.snap index 196684756..1ca9e1840 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__returning_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__returning_100.snap @@ -9,10 +9,7 @@ create temporary table foo ( ); insert into foo (f2, f3) -values - ('test', default), - ('More', 11), - (upper('more'), 7 + 9) +values ('test', default), ('More', 11), (upper('more'), 7 + 9) returning *, f1 + f3 as sum; @@ -67,7 +64,7 @@ inherits (foo); insert into foochild values (123, 'child', 999, -123); alter table foo - add column f4 bigint default 99; + add column f4 int8 default 99; select * from foo; @@ -113,10 +110,7 @@ do instead create or replace rule voo_i as on insert to voo do instead - insert into foo - values (new.*, 57) - returning f1, - f2;; + insert into foo values (new.*, 57) returning f1, f2;; insert into voo values (13, 'zit2'); @@ -129,13 +123,7 @@ select * from voo; create or replace rule voo_u as on update to voo do instead - update foo - set f1 = new.f1, - f2 = new.f2 - where - f1 = old.f1 - returning f1, - f2;; + update foo set f1 = new.f1, f2 = new.f2 where f1 = old.f1 returning f1, f2;; update voo set f1 = f1 + 1 where f2 = 'zoo2'; @@ -148,11 +136,7 @@ select * from voo; create or replace rule voo_d as on delete to voo do instead - delete from foo - where - f1 = old.f1 - returning f1, - f2;; + delete from foo where f1 = old.f1 returning f1, f2;; delete from foo where f1 = 13; @@ -173,9 +157,7 @@ create function foo_f() returns setof foo language sql stable -as $function$ -SELECT * FROM foo OFFSET 0 -$function$; +as $$ SELECT * FROM foo OFFSET 0 $$; update foo set f2 = foo_f.f2 from foo_f() where foo_f.f1 = foo.f1 returning foo_f; @@ -183,15 +165,13 @@ select * from foo; drop function foo_f(); -create type foo_t as (f1 int, f2 text, f3 int, f4 bigint); +create type foo_t as (f1 int, f2 text, f3 int, f4 int8); create function foo_f() returns setof foo_t language sql stable -as $function$ -SELECT * FROM foo OFFSET 0 -$function$; +as $$ SELECT * FROM foo OFFSET 0 $$; update foo set f2 = foo_f.f2 from foo_f() where foo_f.f1 = foo.f1 returning foo_f; @@ -213,11 +193,7 @@ insert into joinme values ('zoo2', 54321); insert into joinme values ('other', 0); create temporary view joinview -as select - foo.*, - other -from - foo inner join joinme on f2 = f2j; +as select foo.*, other from foo inner join joinme on f2 = f2j; select * from joinview; @@ -273,7 +249,7 @@ new.ctid, new.*, *; -create unique index "foo_f1_idx" on foo using btree (f1); +create unique index foo_f1_idx on foo using btree (f1); update foo set f4 = 100 @@ -287,9 +263,7 @@ cast(new.tableoid as regclass), new.ctid, new.*, new, -cast(old.f4 as text) || '->' || -cast(new.f4 as text) -as change; +cast(old.f4 as text) || '->' || cast(new.f4 as text) as change; update foo set f4 = 100 @@ -303,9 +277,7 @@ cast(new.tableoid as regclass), new.ctid, new.*, new, -cast(old.f4 as text) || '->' || -cast(new.f4 as text) -as change; +cast(old.f4 as text) || '->' || cast(new.f4 as text) as change; delete from foo where @@ -331,124 +303,46 @@ new.*, insert into foo values (5, 'subquery test') -returning ( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +returning (select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; insert into foo values (5, 'subquery test') -returning ( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +returning (select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; update foo set f4 = 100 where f1 = 5 returning (select old.f4 = new.f4), -( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +(select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; update foo set f4 = 100 where f1 = 5 returning (select old.f4 = new.f4), -( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +(select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; delete from foo where f1 = 5 -returning ( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +returning (select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; delete from foo where f1 = 5 -returning ( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +returning (select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; create rule foo_del_rule as on delete to foo do instead - update foo - set f2 = f2 || ' (deleted)', - f3 = -1, - f4 = -1 - where - f1 = old.f1 - returning *;; + update foo set f2 = f2 || ' (deleted)', f3 = -1, f4 = -1 where f1 = old.f1 returning *;; delete from foo where f1 = 4 returning old.*, new.*, *; @@ -475,7 +369,7 @@ new.f3 - old.f3 as delta_f3; create function joinview_upd_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'UPDATE: % -> %', old, new; UPDATE foo SET f1 = new.f1, f3 = new.f3, f4 = new.f4 * 10 @@ -483,7 +377,7 @@ BEGIN RETURNING new.f1, new.f4 INTO new.f1, new.f4; -- should fail RETURN NEW; END; -$function$; +$$; create trigger joinview_upd_trig instead of update @@ -506,7 +400,7 @@ new.f3 - old.f3 as delta_f3; create or replace function joinview_upd_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'UPDATE: % -> %', old, new; UPDATE foo SET f1 = new.f1, f3 = new.f3, f4 = new.f4 * 10 @@ -514,7 +408,7 @@ BEGIN RETURNING WITH (new AS n) new.f1, n.f4 INTO new.f1, new.f4; -- now ok RETURN NEW; END; -$function$; +$$; update joinview set f3 = f3 + 1, @@ -579,10 +473,10 @@ drop table public.tt; create table foo_parted ( a int, - b double precision, + b float8, c text ) -partition by LIST(a); +partition by list(a); create table foo_part_s1 partition of foo_parted for values in (1); @@ -591,7 +485,7 @@ create table foo_part_s2 partition of foo_parted for values in (2); create table foo_part_d1 ( c text, a int, - b double precision + b float8 ); alter table foo_parted @@ -599,7 +493,7 @@ alter table foo_parted foo_part_d1 for values in (3); create table foo_part_d2 ( - b double precision, + b float8, c text, a int ); @@ -609,11 +503,7 @@ alter table foo_parted foo_part_d2 for values in (4); insert into foo_parted -values - (1, 17.1, 'P1'), - (2, 17.2, 'P2'), - (3, 17.3, 'P3'), - (4, 17.4, 'P4') +values (1, 17.1, 'P1'), (2, 17.2, 'P2'), (3, 17.3, 'P3'), (4, 17.4, 'P4') returning cast(old.tableoid as regclass), old.ctid, old.*, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__returning_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__returning_80.snap index d1e694e41..b1cd951f1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__returning_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__returning_80.snap @@ -9,10 +9,7 @@ create temporary table foo ( ); insert into foo (f2, f3) -values - ('test', default), - ('More', 11), - (upper('more'), 7 + 9) +values ('test', default), ('More', 11), (upper('more'), 7 + 9) returning *, f1 + f3 as sum; @@ -29,29 +26,23 @@ select * from foo; insert into foo select f1 + 10, f2, f3 + 99 from foo returning *, -f1 + 112 in (select q1 from int8_tbl) -as subplan, -exists (select * from int4_tbl) -as initplan; +f1 + 112 in (select q1 from int8_tbl) as subplan, +exists (select * from int4_tbl) as initplan; update foo set f3 = f3 * 2 where f1 > 10 returning *, -f1 + 112 in (select q1 from int8_tbl) -as subplan, -exists (select * from int4_tbl) -as initplan; +f1 + 112 in (select q1 from int8_tbl) as subplan, +exists (select * from int4_tbl) as initplan; delete from foo where f1 > 10 returning *, -f1 + 112 in (select q1 from int8_tbl) -as subplan, -exists (select * from int4_tbl) -as initplan; +f1 + 112 in (select q1 from int8_tbl) as subplan, +exists (select * from int4_tbl) as initplan; update foo set f3 = f3 * 2 @@ -78,7 +69,7 @@ inherits (foo); insert into foochild values (123, 'child', 999, -123); alter table foo - add column f4 bigint default 99; + add column f4 int8 default 99; select * from foo; @@ -119,17 +110,12 @@ insert into voo values (12, 'zoo') returning *, f1 * 2; create or replace rule voo_i as on insert to voo do instead - insert into foo - values (new.*, 57) - returning *;; + insert into foo values (new.*, 57) returning *;; create or replace rule voo_i as on insert to voo do instead - insert into foo - values (new.*, 57) - returning f1, - f2;; + insert into foo values (new.*, 57) returning f1, f2;; insert into voo values (13, 'zit2'); @@ -142,13 +128,7 @@ select * from voo; create or replace rule voo_u as on update to voo do instead - update foo - set f1 = new.f1, - f2 = new.f2 - where - f1 = old.f1 - returning f1, - f2;; + update foo set f1 = new.f1, f2 = new.f2 where f1 = old.f1 returning f1, f2;; update voo set f1 = f1 + 1 where f2 = 'zoo2'; @@ -161,11 +141,7 @@ select * from voo; create or replace rule voo_d as on delete to voo do instead - delete from foo - where - f1 = old.f1 - returning f1, - f2;; + delete from foo where f1 = old.f1 returning f1, f2;; delete from foo where f1 = 13; @@ -186,9 +162,7 @@ create function foo_f() returns setof foo language sql stable -as $function$ -SELECT * FROM foo OFFSET 0 -$function$; +as $$ SELECT * FROM foo OFFSET 0 $$; update foo set f2 = foo_f.f2 @@ -201,15 +175,13 @@ select * from foo; drop function foo_f(); -create type foo_t as (f1 int, f2 text, f3 int, f4 bigint); +create type foo_t as (f1 int, f2 text, f3 int, f4 int8); create function foo_f() returns setof foo_t language sql stable -as $function$ -SELECT * FROM foo OFFSET 0 -$function$; +as $$ SELECT * FROM foo OFFSET 0 $$; update foo set f2 = foo_f.f2 @@ -236,11 +208,7 @@ insert into joinme values ('zoo2', 54321); insert into joinme values ('other', 0); create temporary view joinview -as select - foo.*, - other -from - foo inner join joinme on f2 = f2j; +as select foo.*, other from foo inner join joinme on f2 = f2j; select * from joinview; @@ -275,10 +243,7 @@ insert into foo as bar default values returning bar.f3; truncate foo; insert into foo -values - (1, 'xxx', 10, 20), - (2, 'more', 42, 141), - (3, 'zoo2', 57, 99); +values (1, 'xxx', 10, 20), (2, 'more', 42, 141), (3, 'zoo2', 57, 99); insert into foo values (4) @@ -300,7 +265,7 @@ new.ctid, new.*, *; -create unique index "foo_f1_idx" on foo using btree (f1); +create unique index foo_f1_idx on foo using btree (f1); update foo set f4 = 100 @@ -314,9 +279,7 @@ cast(new.tableoid as regclass), new.ctid, new.*, new, -cast(old.f4 as text) || '->' || -cast(new.f4 as text) -as change; +cast(old.f4 as text) || '->' || cast(new.f4 as text) as change; update foo set f4 = 100 @@ -330,9 +293,7 @@ cast(new.tableoid as regclass), new.ctid, new.*, new, -cast(old.f4 as text) || '->' || -cast(new.f4 as text) -as change; +cast(old.f4 as text) || '->' || cast(new.f4 as text) as change; delete from foo where @@ -358,113 +319,41 @@ new.*, insert into foo values (5, 'subquery test') -returning ( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +returning (select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; insert into foo values (5, 'subquery test') -returning ( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +returning (select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; update foo set f4 = 100 where f1 = 5 returning (select old.f4 = new.f4), -( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +(select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; update foo set f4 = 100 where f1 = 5 returning (select old.f4 = new.f4), -( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +(select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; delete from foo where f1 = 5 -returning ( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +returning (select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; delete from foo where f1 = 5 -returning ( - select - MAX(old.f4 + x) - from - generate_series(1, 10) as x -) -as old_max, -( - select - MAX(new.f4 + x) - from - generate_series(1, 10) as x -) -as new_max; +returning (select max(old.f4 + x) from generate_series(1, 10) as x) as old_max, +(select max(new.f4 + x) from generate_series(1, 10) as x) as new_max; create rule foo_del_rule as on delete to foo @@ -502,7 +391,7 @@ new.f3 - old.f3 as delta_f3; create function joinview_upd_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'UPDATE: % -> %', old, new; UPDATE foo SET f1 = new.f1, f3 = new.f3, f4 = new.f4 * 10 @@ -510,7 +399,7 @@ BEGIN RETURNING new.f1, new.f4 INTO new.f1, new.f4; -- should fail RETURN NEW; END; -$function$; +$$; create trigger joinview_upd_trig instead of update @@ -533,7 +422,7 @@ new.f3 - old.f3 as delta_f3; create or replace function joinview_upd_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'UPDATE: % -> %', old, new; UPDATE foo SET f1 = new.f1, f3 = new.f3, f4 = new.f4 * 10 @@ -541,7 +430,7 @@ BEGIN RETURNING WITH (new AS n) new.f1, n.f4 INTO new.f1, new.f4; -- now ok RETURN NEW; END; -$function$; +$$; update joinview set f3 = f3 + 1, @@ -606,10 +495,10 @@ drop table public.tt; create table foo_parted ( a int, - b double precision, + b float8, c text ) -partition by LIST(a); +partition by list(a); create table foo_part_s1 partition of foo_parted for values in (1); @@ -618,7 +507,7 @@ create table foo_part_s2 partition of foo_parted for values in (2); create table foo_part_d1 ( c text, a int, - b double precision + b float8 ); alter table foo_parted @@ -626,7 +515,7 @@ alter table foo_parted foo_part_d1 for values in (3); create table foo_part_d2 ( - b double precision, + b float8, c text, a int ); @@ -636,11 +525,7 @@ alter table foo_parted foo_part_d2 for values in (4); insert into foo_parted -values - (1, 17.1, 'P1'), - (2, 17.2, 'P2'), - (3, 17.3, 'P3'), - (4, 17.4, 'P4') +values (1, 17.1, 'P1'), (2, 17.2, 'P2'), (3, 17.3, 'P3'), (4, 17.4, 'P4') returning cast(old.tableoid as regclass), old.ctid, old.*, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_100.snap index 240c21fcf..09b43a2cc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_100.snap @@ -36,25 +36,23 @@ create role regress_rls_group1 nologin; create role regress_rls_group2 nologin; -grant REGRESS_RLS_GROUP1 to regress_rls_bob; +grant regress_rls_group1 to regress_rls_bob; -grant REGRESS_RLS_GROUP2 to regress_rls_carol; +grant regress_rls_group2 to regress_rls_carol; -create schema "regress_rls_schema"; +create schema regress_rls_schema; grant all on schema regress_rls_schema to public; set search_path to regress_rls_schema; create or replace function f_leak(text) -returns boolean +returns bool language plpgsql cost 0.0000001 -as $function$ -BEGIN RAISE NOTICE 'f_leak => %', $1; RETURN true; END -$function$; +as 'BEGIN RAISE NOTICE ''f_leak => %'', $1; RETURN true; END'; -grant EXECUTE on function f_leak(text) to public; +grant execute on function f_leak(text) to public; set session authorization regress_rls_alice; @@ -63,7 +61,7 @@ create table uaccount ( seclv int ); -grant SELECT on table uaccount to public; +grant select on table uaccount to public; insert into uaccount values @@ -80,11 +78,7 @@ create table category ( grant all on table category to public; insert into category -values - (11, 'novel'), - (22, 'science fiction'), - (33, 'technology'), - (44, 'manga'); +values (11, 'novel'), (22, 'science fiction'), (33, 'technology'), (44, 'manga'); create table document ( did int primary key, @@ -100,40 +94,14 @@ insert into document values (1, 11, 1, 'regress_rls_bob', 'my first novel'), (2, 11, 2, 'regress_rls_bob', 'my second novel'), - ( - 3, 22, 2, 'regress_rls_bob', 'my science fiction' - ), + (3, 22, 2, 'regress_rls_bob', 'my science fiction'), (4, 44, 1, 'regress_rls_bob', 'my first manga'), (5, 44, 2, 'regress_rls_bob', 'my second manga'), - ( - 6, - 22, - 1, - 'regress_rls_carol', - 'great science fiction' - ), - ( - 7, - 33, - 2, - 'regress_rls_carol', - 'great technology book' - ), + (6, 22, 1, 'regress_rls_carol', 'great science fiction'), + (7, 33, 2, 'regress_rls_carol', 'great technology book'), (8, 44, 1, 'regress_rls_carol', 'great manga'), - ( - 9, - 22, - 1, - 'regress_rls_dave', - 'awesome science fiction' - ), - ( - 10, - 33, - 2, - 'regress_rls_dave', - 'awesome technology book' - ); + (9, 22, 1, 'regress_rls_dave', 'awesome science fiction'), + (10, 33, 2, 'regress_rls_dave', 'awesome technology book'); alter table document enable row level security; @@ -143,15 +111,7 @@ on document as permissive for all to public -using (dlevel <= -( - select - seclv - from - uaccount - where - pguser = current_user -)); +using (dlevel <= (select seclv from uaccount where pguser = current_user)); create policy p2r on document @@ -167,8 +127,7 @@ select from pg_policies where - schemaname = 'regress_rls_schema' and - tablename = 'document' + schemaname = 'regress_rls_schema' and tablename = 'document' order by policyname; set session authorization regress_rls_bob; @@ -239,10 +198,8 @@ as permissive for all to public using (case - when current_user = 'regress_rls_bob' - then cid in (11, 33) - when current_user = 'regress_rls_carol' - then cid in (22, 44) + when current_user = 'regress_rls_bob' then cid in (11, 33) + when current_user = 'regress_rls_carol' then cid in (22, 44) else false end); @@ -433,40 +390,14 @@ insert into part_document values (1, 11, 1, 'regress_rls_bob', 'my first novel'), (2, 11, 2, 'regress_rls_bob', 'my second novel'), - ( - 3, 99, 2, 'regress_rls_bob', 'my science textbook' - ), + (3, 99, 2, 'regress_rls_bob', 'my science textbook'), (4, 55, 1, 'regress_rls_bob', 'my first satire'), (5, 99, 2, 'regress_rls_bob', 'my history book'), - ( - 6, - 11, - 1, - 'regress_rls_carol', - 'great science fiction' - ), - ( - 7, - 99, - 2, - 'regress_rls_carol', - 'great technology book' - ), + (6, 11, 1, 'regress_rls_carol', 'great science fiction'), + (7, 99, 2, 'regress_rls_carol', 'great technology book'), (8, 55, 2, 'regress_rls_carol', 'great satire'), - ( - 9, - 11, - 1, - 'regress_rls_dave', - 'awesome science fiction' - ), - ( - 10, - 99, - 2, - 'regress_rls_dave', - 'awesome technology book' - ); + (9, 11, 1, 'regress_rls_dave', 'awesome science fiction'), + (10, 99, 2, 'regress_rls_dave', 'awesome technology book'); alter table part_document enable row level security; @@ -476,15 +407,7 @@ on part_document as permissive for all to public -using (dlevel <= -( - select - seclv - from - uaccount - where - pguser = current_user -)); +using (dlevel <= (select seclv from uaccount where pguser = current_user)); create policy pp1r on part_document as restrictive for all to regress_rls_dave using (cid < 55); @@ -493,8 +416,7 @@ select from pg_policies where - schemaname = 'regress_rls_schema' and - tablename like '%part_document%' + schemaname = 'regress_rls_schema' and tablename like '%part_document%' order by policyname; set session authorization regress_rls_bob; @@ -524,14 +446,7 @@ insert into part_document values (100, 99, 1, 'regress_rls_dave', 'testing pp1r' insert into part_document values (100, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); insert into part_document_satire -values - ( - 100, - 55, - 1, - 'regress_rls_dave', - 'testing RLS with partitions' - ); +values (100, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); select * from part_document where f_leak(dtitle) order by did; @@ -547,14 +462,7 @@ create policy pp3 on part_document_satire as restrictive for all to public using set session authorization regress_rls_dave; insert into part_document_satire -values - ( - 101, - 55, - 1, - 'regress_rls_dave', - 'testing RLS with partitions' - ); +values (101, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); select * from part_document_satire where f_leak(dtitle) order by did; @@ -627,14 +535,7 @@ on part_document as restrictive for all to public -using (( - select - dlevel <= seclv - from - uaccount - where - pguser = current_user -)); +using ((select dlevel <= seclv from uaccount where pguser = current_user)); set session authorization regress_rls_carol; @@ -777,7 +678,7 @@ create table s2 ( insert into s2 select x, public.fipshash(cast(x as text)) from generate_series(-6, 6) as x; -grant SELECT on table s1, s2 to regress_rls_bob; +grant select on table s1, s2 to regress_rls_bob; create policy p1 on s1 @@ -848,7 +749,7 @@ prepare p1 (int) as select * from t1 where a <= $1;; execute p1 (2); -explain (COSTS 'off') execute p1 (2); +explain (costs 'off') execute p1 (2); reset session_authorization; @@ -860,13 +761,13 @@ select * from t1 where f_leak(b); execute p1 (2); -explain (COSTS 'off') execute p1 (2); +explain (costs 'off') execute p1 (2); prepare p2 (int) as select * from t1 where a = $1;; execute p2 (2); -explain (COSTS 'off') execute p2 (2); +explain (costs 'off') execute p2 (2); set session authorization regress_rls_bob; @@ -874,7 +775,7 @@ set row_security = 'on'; execute p2 (2); -explain (COSTS 'off') execute p2 (2); +explain (costs 'off') execute p2 (2); set session authorization regress_rls_bob; @@ -908,11 +809,7 @@ update t2 as t2_1 set b = t2_2.b from t2 as t2_2 where - t2_1.a = 3 and - t2_2.a = t2_1.a and - t2_2.b = t2_1.b and - f_leak(t2_1.b) and - f_leak(t2_2.b) + t2_1.a = 3 and t2_2.a = t2_1.a and t2_2.b = t2_1.b and f_leak(t2_1.b) and f_leak(t2_2.b) returning *, t2_1, t2_2; @@ -921,11 +818,7 @@ update t2 as t2_1 set b = t2_2.b from t2 as t2_2 where - t2_1.a = 3 and - t2_2.a = t2_1.a and - t2_2.b = t2_1.b and - f_leak(t2_1.b) and - f_leak(t2_2.b) + t2_1.a = 3 and t2_2.a = t2_1.a and t2_2.b = t2_1.b and f_leak(t2_1.b) and f_leak(t2_2.b) returning *, t2_1, t2_2; @@ -934,11 +827,7 @@ update t1 as t1_1 set b = t1_2.b from t1 as t1_2 where - t1_1.a = 4 and - t1_2.a = t1_1.a and - t1_2.b = t1_1.b and - f_leak(t1_1.b) and - f_leak(t1_2.b) + t1_1.a = 4 and t1_2.a = t1_1.a and t1_2.b = t1_1.b and f_leak(t1_1.b) and f_leak(t1_2.b) returning *, t1_1, t1_2; @@ -947,11 +836,7 @@ update t1 as t1_1 set b = t1_2.b from t1 as t1_2 where - t1_1.a = 4 and - t1_2.a = t1_1.a and - t1_2.b = t1_1.b and - f_leak(t1_1.b) and - f_leak(t1_2.b) + t1_1.a = 4 and t1_2.a = t1_1.a and t1_2.b = t1_1.b and f_leak(t1_1.b) and f_leak(t1_2.b) returning *, t1_1, t1_2; @@ -1038,8 +923,7 @@ on document as permissive for update to public -using (cid = -(select cid from category where cname = 'novel')) +using (cid = (select cid from category where cname = 'novel')) with check (dauthor = current_user); set session authorization regress_rls_bob; @@ -1048,19 +932,8 @@ select * from document where did = 2; insert into document values - ( - 2, - (select cid from category where cname = 'novel'), - 1, - 'regress_rls_carol', - 'my first novel' - ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -dauthor = excluded.dauthor; + (2, (select cid from category where cname = 'novel'), 1, 'regress_rls_carol', 'my first novel') +on conflict (did) do update set dtitle = excluded.dtitle, dauthor = excluded.dauthor; insert into document values (33, 22, 1, 'regress_rls_bob', 'okay science fiction'); @@ -1073,26 +946,11 @@ values 'regress_rls_bob', 'Some novel, replaces sci-fi' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle; +on conflict (did) do update set dtitle = excluded.dtitle; insert into document -values - ( - 2, - (select cid from category where cname = 'novel'), - 1, - 'regress_rls_bob', - 'my first novel' - ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle +values (2, (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'my first novel') +on conflict (did) do update set dtitle = excluded.dtitle returning *; insert into document @@ -1104,12 +962,7 @@ values 'regress_rls_bob', 'some technology novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -cid = 33 +on conflict (did) do update set dtitle = excluded.dtitle, cid = 33 returning *; insert into document @@ -1121,12 +974,7 @@ values 'regress_rls_bob', 'some technology novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -cid = 33 +on conflict (did) do update set dtitle = excluded.dtitle, cid = 33 returning *; insert into document @@ -1138,58 +986,31 @@ values 'regress_rls_bob', 'some technology novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -cid = 33 +on conflict (did) do update set dtitle = excluded.dtitle, cid = 33 returning *; insert into document values ( 79, - ( - select - cid - from - category - where - cname = 'technology' - ), + (select cid from category where cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle +on conflict (did) do update set dtitle = excluded.dtitle returning *; insert into document values ( 79, - ( - select - cid - from - category - where - cname = 'technology' - ), + (select cid from category where cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle +on conflict (did) do update set dtitle = excluded.dtitle returning *; set session authorization regress_rls_alice; @@ -1205,8 +1026,7 @@ on document as permissive for update to public -using (cid = -(select cid from category where cname = 'novel')); +using (cid = (select cid from category where cname = 'novel')); set session authorization regress_rls_bob; @@ -1214,47 +1034,18 @@ insert into document values ( 79, - ( - select - cid - from - category - where - cname = 'technology' - ), + (select cid from category where cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle +on conflict (did) do update set dtitle = excluded.dtitle returning *; insert into document values - ( - 2, - ( - select - cid - from - category - where - cname = 'technology' - ), - 1, - 'regress_rls_bob', - 'my first novel' - ) -on conflict -(did) -do -update -set cid = excluded.cid, -dtitle = excluded.dtitle + (2, (select cid from category where cname = 'technology'), 1, 'regress_rls_bob', 'my first novel') +on conflict (did) do update set cid = excluded.cid, dtitle = excluded.dtitle returning *; set session authorization regress_rls_alice; @@ -1266,57 +1057,23 @@ on document as permissive for all to public -using (cid = -(select cid from category where cname = 'novel')) +using (cid = (select cid from category where cname = 'novel')) with check (dauthor = current_user); set session authorization regress_rls_bob; insert into document values - ( - 80, - (select cid from category where cname = 'novel'), - 1, - 'regress_rls_carol', - 'my first novel' - ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -cid = 33; + (80, (select cid from category where cname = 'novel'), 1, 'regress_rls_carol', 'my first novel') +on conflict (did) do update set dtitle = excluded.dtitle, cid = 33; insert into document -values - ( - 4, - (select cid from category where cname = 'novel'), - 1, - 'regress_rls_bob', - 'my first novel' - ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle; +values (4, (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'my first novel') +on conflict (did) do update set dtitle = excluded.dtitle; insert into document -values - ( - 1, - (select cid from category where cname = 'novel'), - 1, - 'regress_rls_bob', - 'my first novel' - ) -on conflict -(did) -do -update -set dauthor = 'regress_rls_carol'; +values (1, (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'my first novel') +on conflict (did) do update set dauthor = 'regress_rls_carol'; reset session_authorization; @@ -1334,8 +1091,7 @@ on document as permissive for update to public -using (cid = -(select cid from category where cname = 'novel')) +using (cid = (select cid from category where cname = 'novel')) with check (dlevel > 0); create policy p4 @@ -1343,8 +1099,7 @@ on document as permissive for delete to public -using (cid = -(select cid from category where cname = 'manga')); +using (cid = (select cid from category where cname = 'manga')); select * from document; @@ -1369,8 +1124,7 @@ on document as permissive for select to public -using (cid = -(select cid from category where cname = 'novel')); +using (cid = (select cid from category where cname = 'novel')); set session authorization regress_rls_bob; @@ -1394,7 +1148,7 @@ create table z2 ( b text ); -grant SELECT +grant select on table z1, z2 to regress_rls_group1, @@ -1419,4 +1173,4 @@ select * from z1 where f_leak(b); prepare plancache_test as select * from z1 where f_leak(b);; -explain (COSTS 'off') execute plancache_test; +explain (costs 'off') execute plancache_test; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_80.snap index 9b73fd023..3a3f4b9e5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_80.snap @@ -36,25 +36,23 @@ create role regress_rls_group1 nologin; create role regress_rls_group2 nologin; -grant REGRESS_RLS_GROUP1 to regress_rls_bob; +grant regress_rls_group1 to regress_rls_bob; -grant REGRESS_RLS_GROUP2 to regress_rls_carol; +grant regress_rls_group2 to regress_rls_carol; -create schema "regress_rls_schema"; +create schema regress_rls_schema; grant all on schema regress_rls_schema to public; set search_path to regress_rls_schema; create or replace function f_leak(text) -returns boolean +returns bool language plpgsql cost 0.0000001 -as $function$ -BEGIN RAISE NOTICE 'f_leak => %', $1; RETURN true; END -$function$; +as 'BEGIN RAISE NOTICE ''f_leak => %'', $1; RETURN true; END'; -grant EXECUTE on function f_leak(text) to public; +grant execute on function f_leak(text) to public; set session authorization regress_rls_alice; @@ -63,7 +61,7 @@ create table uaccount ( seclv int ); -grant SELECT on table uaccount to public; +grant select on table uaccount to public; insert into uaccount values @@ -98,76 +96,16 @@ grant all on table document to public; insert into document values - ( - 1, - 11, - 1, - 'regress_rls_bob', - 'my first novel' - ), - ( - 2, - 11, - 2, - 'regress_rls_bob', - 'my second novel' - ), - ( - 3, - 22, - 2, - 'regress_rls_bob', - 'my science fiction' - ), - ( - 4, - 44, - 1, - 'regress_rls_bob', - 'my first manga' - ), - ( - 5, - 44, - 2, - 'regress_rls_bob', - 'my second manga' - ), - ( - 6, - 22, - 1, - 'regress_rls_carol', - 'great science fiction' - ), - ( - 7, - 33, - 2, - 'regress_rls_carol', - 'great technology book' - ), - ( - 8, - 44, - 1, - 'regress_rls_carol', - 'great manga' - ), - ( - 9, - 22, - 1, - 'regress_rls_dave', - 'awesome science fiction' - ), - ( - 10, - 33, - 2, - 'regress_rls_dave', - 'awesome technology book' - ); + (1, 11, 1, 'regress_rls_bob', 'my first novel'), + (2, 11, 2, 'regress_rls_bob', 'my second novel'), + (3, 22, 2, 'regress_rls_bob', 'my science fiction'), + (4, 44, 1, 'regress_rls_bob', 'my first manga'), + (5, 44, 2, 'regress_rls_bob', 'my second manga'), + (6, 22, 1, 'regress_rls_carol', 'great science fiction'), + (7, 33, 2, 'regress_rls_carol', 'great technology book'), + (8, 44, 1, 'regress_rls_carol', 'great manga'), + (9, 22, 1, 'regress_rls_dave', 'awesome science fiction'), + (10, 33, 2, 'regress_rls_dave', 'awesome technology book'); alter table document enable row level security; @@ -177,15 +115,7 @@ on document as permissive for all to public -using (dlevel <= -( - select - seclv - from - uaccount - where - pguser = current_user -)); +using (dlevel <= (select seclv from uaccount where pguser = current_user)); create policy p2r on document @@ -206,8 +136,7 @@ select from pg_policies where - schemaname = 'regress_rls_schema' and - tablename = 'document' + schemaname = 'regress_rls_schema' and tablename = 'document' order by policyname; set session authorization regress_rls_bob; @@ -221,9 +150,7 @@ select * from document natural join category where f_leak(dtitle) order by did; select * from - document - tablesample bernoulli (50) - repeatable (0) + document tablesample bernoulli (50) repeatable (0) where f_leak(dtitle) order by did; @@ -237,9 +164,7 @@ select * from document natural join category where f_leak(dtitle) order by did; select * from - document - tablesample bernoulli (50) - repeatable (0) + document tablesample bernoulli (50) repeatable (0) where f_leak(dtitle) order by did; @@ -259,24 +184,10 @@ select * from document where f_leak(dtitle); select * from document natural join category where f_leak(dtitle); insert into document -values - ( - 100, - 44, - 1, - 'regress_rls_dave', - 'testing sorting of policies' - ); +values (100, 44, 1, 'regress_rls_dave', 'testing sorting of policies'); insert into document -values - ( - 100, - 55, - 1, - 'regress_rls_dave', - 'testing sorting of policies' - ); +values (100, 55, 1, 'regress_rls_dave', 'testing sorting of policies'); alter policy p1 on document using (true); @@ -310,10 +221,8 @@ as permissive for all to public using (case - when current_user = 'regress_rls_bob' - then cid in (11, 33) - when current_user = 'regress_rls_carol' - then cid in (22, 44) + when current_user = 'regress_rls_bob' then cid in (11, 33) + when current_user = 'regress_rls_carol' then cid in (22, 44) else false end); @@ -325,10 +234,7 @@ set session authorization regress_rls_bob; select * from - document as d - full outer join - category as c - on d.cid = c.cid + document as d full outer join category as c on d.cid = c.cid order by d.did, c.cid; @@ -339,10 +245,7 @@ set session authorization regress_rls_carol; select * from - document as d - full outer join - category as c - on d.cid = c.cid + document as d full outer join category as c on d.cid = c.cid order by d.did, c.cid; @@ -467,33 +370,13 @@ select * from t1 where f_leak(b) for share; select * from t1 where f_leak(b) for share; -select - a, - b, - cast(tableoid as regclass) -from - t2 +select a, b, cast(tableoid as regclass) from t2 union all -select - a, - b, - cast(tableoid as regclass) -from - t3; +select a, b, cast(tableoid as regclass) from t3; -select - a, - b, - cast(tableoid as regclass) -from - t2 +select a, b, cast(tableoid as regclass) from t2 union all -select - a, - b, - cast(tableoid as regclass) -from - t3; +select a, b, cast(tableoid as regclass) from t3; reset session_authorization; @@ -544,76 +427,16 @@ grant all on table part_document_nonfiction to public; insert into part_document values - ( - 1, - 11, - 1, - 'regress_rls_bob', - 'my first novel' - ), - ( - 2, - 11, - 2, - 'regress_rls_bob', - 'my second novel' - ), - ( - 3, - 99, - 2, - 'regress_rls_bob', - 'my science textbook' - ), - ( - 4, - 55, - 1, - 'regress_rls_bob', - 'my first satire' - ), - ( - 5, - 99, - 2, - 'regress_rls_bob', - 'my history book' - ), - ( - 6, - 11, - 1, - 'regress_rls_carol', - 'great science fiction' - ), - ( - 7, - 99, - 2, - 'regress_rls_carol', - 'great technology book' - ), - ( - 8, - 55, - 2, - 'regress_rls_carol', - 'great satire' - ), - ( - 9, - 11, - 1, - 'regress_rls_dave', - 'awesome science fiction' - ), - ( - 10, - 99, - 2, - 'regress_rls_dave', - 'awesome technology book' - ); + (1, 11, 1, 'regress_rls_bob', 'my first novel'), + (2, 11, 2, 'regress_rls_bob', 'my second novel'), + (3, 99, 2, 'regress_rls_bob', 'my science textbook'), + (4, 55, 1, 'regress_rls_bob', 'my first satire'), + (5, 99, 2, 'regress_rls_bob', 'my history book'), + (6, 11, 1, 'regress_rls_carol', 'great science fiction'), + (7, 99, 2, 'regress_rls_carol', 'great technology book'), + (8, 55, 2, 'regress_rls_carol', 'great satire'), + (9, 11, 1, 'regress_rls_dave', 'awesome science fiction'), + (10, 99, 2, 'regress_rls_dave', 'awesome technology book'); alter table part_document enable row level security; @@ -623,15 +446,7 @@ on part_document as permissive for all to public -using (dlevel <= -( - select - seclv - from - uaccount - where - pguser = current_user -)); +using (dlevel <= (select seclv from uaccount where pguser = current_user)); create policy pp1r on part_document @@ -645,8 +460,7 @@ select from pg_policies where - schemaname = 'regress_rls_schema' and - tablename like '%part_document%' + schemaname = 'regress_rls_schema' and tablename like '%part_document%' order by policyname; set session authorization regress_rls_bob; @@ -670,44 +484,16 @@ select * from part_document where f_leak(dtitle) order by did; select * from part_document where f_leak(dtitle); insert into part_document -values - ( - 100, - 11, - 5, - 'regress_rls_dave', - 'testing pp1' - ); +values (100, 11, 5, 'regress_rls_dave', 'testing pp1'); insert into part_document -values - ( - 100, - 99, - 1, - 'regress_rls_dave', - 'testing pp1r' - ); +values (100, 99, 1, 'regress_rls_dave', 'testing pp1r'); insert into part_document -values - ( - 100, - 55, - 1, - 'regress_rls_dave', - 'testing RLS with partitions' - ); +values (100, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); insert into part_document_satire -values - ( - 100, - 55, - 1, - 'regress_rls_dave', - 'testing RLS with partitions' - ); +values (100, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); select * from part_document where f_leak(dtitle) order by did; @@ -728,14 +514,7 @@ using (cid < 55); set session authorization regress_rls_dave; insert into part_document_satire -values - ( - 101, - 55, - 1, - 'regress_rls_dave', - 'testing RLS with partitions' - ); +values (101, 55, 1, 'regress_rls_dave', 'testing RLS with partitions'); select * from part_document_satire where f_leak(dtitle) order by did; @@ -808,26 +587,12 @@ on part_document as restrictive for all to public -using (( - select - dlevel <= seclv - from - uaccount - where - pguser = current_user -)); +using ((select dlevel <= seclv from uaccount where pguser = current_user)); set session authorization regress_rls_carol; insert into part_document -values - ( - 100, - 11, - 5, - 'regress_rls_carol', - 'testing pp3' - ); +values (100, 11, 5, 'regress_rls_carol', 'testing pp3'); set session authorization regress_rls_alice; @@ -848,15 +613,7 @@ on dependent as permissive for all to public -using (x = -( - select - d.x - from - dependee as d - where - d.y = y -)); +using (x = (select d.x from dependee as d where d.y = y)); drop table dependee; @@ -876,10 +633,7 @@ on rec1 as permissive for all to public -using (x = -( - select r.x from rec1 as r where y = r.y -)); +using (x = (select r.x from rec1 as r where y = r.y)); alter table rec1 enable row level security; @@ -969,11 +723,7 @@ create table s1 ( ); insert into s1 -select - x, - public.fipshash(cast(x as text)) -from - generate_series(-10, 10) as x; +select x, public.fipshash(cast(x as text)) from generate_series(-10, 10) as x; create table s2 ( x int, @@ -981,33 +731,23 @@ create table s2 ( ); insert into s2 -select - x, - public.fipshash(cast(x as text)) -from - generate_series(-6, 6) as x; +select x, public.fipshash(cast(x as text)) from generate_series(-6, 6) as x; -grant SELECT on table s1, s2 to regress_rls_bob; +grant select on table s1, s2 to regress_rls_bob; create policy p1 on s1 as permissive for all to public -using (a in -( - select x from s2 where y like '%2f%' -)); +using (a in (select x from s2 where y like '%2f%')); create policy p2 on s2 as permissive for all to public -using (x in -( - select a from s1 where b like '%22%' -)); +using (x in (select a from s1 where b like '%22%')); create policy p3 on s1 @@ -1069,7 +809,7 @@ prepare p1 (int) as select * from t1 where a <= $1;; execute p1 (2); -explain (COSTS 'off') execute p1 (2); +explain (costs 'off') execute p1 (2); reset session_authorization; @@ -1081,13 +821,13 @@ select * from t1 where f_leak(b); execute p1 (2); -explain (COSTS 'off') execute p1 (2); +explain (costs 'off') execute p1 (2); prepare p2 (int) as select * from t1 where a = $1;; execute p2 (2); -explain (COSTS 'off') execute p2 (2); +explain (costs 'off') execute p2 (2); set session authorization regress_rls_bob; @@ -1095,7 +835,7 @@ set row_security = 'on'; execute p2 (2); -explain (COSTS 'off') execute p2 (2); +explain (costs 'off') execute p2 (2); set session authorization regress_rls_bob; @@ -1123,55 +863,37 @@ update t2 set b = t2.b from t3 where - t2.a = 3 and - t3.a = 2 and - f_leak(t2.b) and - f_leak(t3.b); + t2.a = 3 and t3.a = 2 and f_leak(t2.b) and f_leak(t3.b); update t2 set b = t2.b from t3 where - t2.a = 3 and - t3.a = 2 and - f_leak(t2.b) and - f_leak(t3.b); + t2.a = 3 and t3.a = 2 and f_leak(t2.b) and f_leak(t3.b); update t1 set b = t1.b from t2 where - t1.a = 3 and - t2.a = 3 and - f_leak(t1.b) and - f_leak(t2.b); + t1.a = 3 and t2.a = 3 and f_leak(t1.b) and f_leak(t2.b); update t1 set b = t1.b from t2 where - t1.a = 3 and - t2.a = 3 and - f_leak(t1.b) and - f_leak(t2.b); + t1.a = 3 and t2.a = 3 and f_leak(t1.b) and f_leak(t2.b); update t2 set b = t2.b from t1 where - t1.a = 3 and - t2.a = 3 and - f_leak(t1.b) and - f_leak(t2.b); + t1.a = 3 and t2.a = 3 and f_leak(t1.b) and f_leak(t2.b); update t2 set b = t2.b from t1 where - t1.a = 3 and - t2.a = 3 and - f_leak(t1.b) and - f_leak(t2.b); + t1.a = 3 and t2.a = 3 and f_leak(t1.b) and f_leak(t2.b); update t2 as t2_1 set b = t2_2.b @@ -1251,11 +973,7 @@ create table b1 ( ); insert into b1 -select - x, - public.fipshash(cast(x as text)) -from - generate_series(-10, 10) as x; +select x, public.fipshash(cast(x as text)) from generate_series(-10, 10) as x; create policy p1 on b1 as permissive for all to public using (a % 2 = 0); @@ -1317,15 +1035,7 @@ on document as permissive for update to public -using (cid = -( - select - cid - from - category - where - cname = 'novel' -)) +using (cid = (select cid from category where cname = 'novel')) with check (dauthor = current_user); set session authorization regress_rls_bob; @@ -1336,14 +1046,7 @@ insert into document values ( 2, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_carol', 'my first novel' @@ -1356,176 +1059,89 @@ set dtitle = excluded.dtitle, dauthor = excluded.dauthor; insert into document -values - ( - 33, - 22, - 1, - 'regress_rls_bob', - 'okay science fiction' - ); +values (33, 22, 1, 'regress_rls_bob', 'okay science fiction'); insert into document values ( 33, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'Some novel, replaces sci-fi' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle; +on conflict (did) do update set dtitle = excluded.dtitle; insert into document values ( 2, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'my first novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle +on conflict (did) do update set dtitle = excluded.dtitle returning *; insert into document values ( 78, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'some technology novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -cid = 33 +on conflict (did) do update set dtitle = excluded.dtitle, cid = 33 returning *; insert into document values ( 78, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'some technology novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -cid = 33 +on conflict (did) do update set dtitle = excluded.dtitle, cid = 33 returning *; insert into document values ( 78, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'some technology novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -cid = 33 +on conflict (did) do update set dtitle = excluded.dtitle, cid = 33 returning *; insert into document values ( 79, - ( - select - cid - from - category - where - cname = 'technology' - ), + (select cid from category where cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle +on conflict (did) do update set dtitle = excluded.dtitle returning *; insert into document values ( 79, - ( - select - cid - from - category - where - cname = 'technology' - ), + (select cid from category where cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle +on conflict (did) do update set dtitle = excluded.dtitle returning *; set session authorization regress_rls_alice; @@ -1541,15 +1157,7 @@ on document as permissive for update to public -using (cid = -( - select - cid - from - category - where - cname = 'novel' -)); +using (cid = (select cid from category where cname = 'novel')); set session authorization regress_rls_bob; @@ -1557,47 +1165,24 @@ insert into document values ( 79, - ( - select - cid - from - category - where - cname = 'technology' - ), + (select cid from category where cname = 'technology'), 1, 'regress_rls_bob', 'technology book, can only insert' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle +on conflict (did) do update set dtitle = excluded.dtitle returning *; insert into document values ( 2, - ( - select - cid - from - category - where - cname = 'technology' - ), + (select cid from category where cname = 'technology'), 1, 'regress_rls_bob', 'my first novel' ) -on conflict -(did) -do -update -set cid = excluded.cid, -dtitle = excluded.dtitle +on conflict (did) do update set cid = excluded.cid, dtitle = excluded.dtitle returning *; set session authorization regress_rls_alice; @@ -1609,15 +1194,7 @@ on document as permissive for all to public -using (cid = -( - select - cid - from - category - where - cname = 'novel' -)) +using (cid = (select cid from category where cname = 'novel')) with check (dauthor = current_user); set session authorization regress_rls_bob; @@ -1626,68 +1203,34 @@ insert into document values ( 80, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_carol', 'my first novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle, -cid = 33; +on conflict (did) do update set dtitle = excluded.dtitle, cid = 33; insert into document values ( 4, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'my first novel' ) -on conflict -(did) -do -update -set dtitle = excluded.dtitle; +on conflict (did) do update set dtitle = excluded.dtitle; insert into document values ( 1, - ( - select - cid - from - category - where - cname = 'novel' - ), + (select cid from category where cname = 'novel'), 1, 'regress_rls_bob', 'my first novel' ) -on conflict -(did) -do -update -set dauthor = 'regress_rls_carol'; +on conflict (did) do update set dauthor = 'regress_rls_carol'; reset session_authorization; @@ -1710,15 +1253,7 @@ on document as permissive for update to public -using (cid = -( - select - cid - from - category - where - cname = 'novel' -)) +using (cid = (select cid from category where cname = 'novel')) with check (dlevel > 0); create policy p4 @@ -1726,15 +1261,7 @@ on document as permissive for delete to public -using (cid = -( - select - cid - from - category - where - cname = 'manga' -)); +using (cid = (select cid from category where cname = 'manga')); select * from document; @@ -1759,15 +1286,7 @@ on document as permissive for select to public -using (cid = -( - select - cid - from - category - where - cname = 'novel' -)); +using (cid = (select cid from category where cname = 'novel')); set session authorization regress_rls_bob; @@ -1791,7 +1310,7 @@ create table z2 ( b text ); -grant SELECT +grant select on table z1, z2 to regress_rls_group1, @@ -1826,4 +1345,4 @@ select * from z1 where f_leak(b); prepare plancache_test as select * from z1 where f_leak(b);; -explain (COSTS 'off') execute plancache_test; +explain (costs 'off') execute plancache_test; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowtypes_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowtypes_100.snap index a34e8968d..57b2e9073 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowtypes_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowtypes_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/rowtypes.sql --- -create type complex as (r double precision, i double precision); +create type complex as (r float8, i float8); create temporary table fullname ( first text, @@ -125,11 +125,11 @@ select row('ABC', 'DEF') ~>=~ row('DEF', 'ABC') as "false"; select row('ABC', 'DEF') ~~ row('DEF', 'ABC') as fail; -select row(1, 2) = row(1, cast(2 as bigint)); +select row(1, 2) = row(1, cast(2 as int8)); select row(1, 2) in (row(3, 4), row(1, 2)); -select row(1, 2) in (row(3, 4), row(1, cast(2 as bigint))); +select row(1, 2) in (row(3, 4), row(1, cast(2 as int8))); select unique1, @@ -137,11 +137,7 @@ select from tenk1 where - (unique1, unique2) < any - ( - select ten, ten from tenk1 where hundred < 3 - ) and - unique1 <= 20 + (unique1, unique2) < any (select ten, ten from tenk1 where hundred < 3) and unique1 <= 20 order by 1; select @@ -254,20 +250,14 @@ select from int8_tbl as i8 where - i8 - in ( - cast(row(123, 456) as int8_tbl), '(4567890123456789,123)' - ); + i8 in (cast(row(123, 456) as int8_tbl), '(4567890123456789,123)'); select * from int8_tbl as i8 where - i8 - in ( - cast(row(123, 456) as int8_tbl), '(4567890123456789,123)' - ); + i8 in (cast(row(123, 456) as int8_tbl), '(4567890123456789,123)'); select (row(1, 2.0)).f1; @@ -295,7 +285,7 @@ select row(1, 1.1) = any (array[row(7, 7.7), row(1, 1.1), row(0, 0.0)]); select row(1, 1.1) = any (array[row(7, 7.7), row(1, 1.0), row(0, 0.0)]); -create type cantcompare as (p point, r double precision); +create type cantcompare as (p point, r float8); create temporary table cc (f1 cantcompare); @@ -381,7 +371,7 @@ select cast(row(1, -3) as testtype1) *> cast(row(1, -2) as testtype1); select cast(row(1, -2) as testtype1) *< cast(row(1, 3) as testtype1); -create type testtype2 as (a smallint, b boolean); +create type testtype2 as (a smallint, b bool); select cast(row(1, true) as testtype2) *< cast(row(2, true) as testtype2); @@ -432,8 +422,7 @@ select q.d = row(row(4)) from unnest( - array[row(1, row(2), array[row(3)], row(row(4))), - row(2, row(3), array[row(4)], row(row(5)))] + array[row(1, row(2), array[row(3)], row(row(4))), row(2, row(3), array[row(4)], row(row(5)))] ) as q (a int, b record, c record[], d record); @@ -455,30 +444,25 @@ create type price_key as (id int); create function price_key_from_table(price) returns price_key language sql -as $function$ -SELECT $1.id -$function$; +as $$ + SELECT $1.id +$$; create function price_key_from_input(price_input) returns price_key language sql -as $function$ -SELECT $1.id -$function$; +as $$ + SELECT $1.id +$$; insert into price values (1, false, 42), (10, false, 100), (11, true, 17.99); update price set active = true, price = input_prices.price -from unnest( - cast(array[(10, 123.00), (11, 99.99)] - as price_input[]) -) -as input_prices +from unnest(cast(array[(10, 123.00), (11, 99.99)] as price_input[])) as input_prices where - price_key_from_table(price.*) = - price_key_from_input(input_prices.*); + price_key_from_table(price.*) = price_key_from_input(input_prices.*); select * from price; @@ -492,30 +476,30 @@ create temporary table compos ( create function fcompos1(v compos) returns void language sql -as $function$ +as $$ insert into compos values (v); -- fail -$function$; +$$; create function fcompos1(v compos) returns void language sql -as $function$ +as $$ insert into compos values (v.*); -$function$; +$$; create function fcompos2(v compos) returns void language sql -as $function$ +as $$ select fcompos1(v); -$function$; +$$; create function fcompos3(v compos) returns void language sql -as $function$ +as $$ select fcompos1(fcompos3.v.*); -$function$; +$$; select fcompos1(row(1, 'one')); @@ -550,9 +534,7 @@ select last(f) from fullname as f; create function longname(fullname) returns text language sql -as $function$ -select $1.first || ' ' || $1.last -$function$; +as $$select $1.first || ' ' || $1.last$$; select f.longname from fullname as f; @@ -584,45 +566,18 @@ select row_to_json(ss) from (select q1 as a, q2 as b from int8_tbl offset 0) as select row_to_json(q) from - ( - select - thousand, - tenthous - from - tenk1 - where - thousand = 42 and tenthous < 2000 - offset 0 - ) - as q; + (select thousand, tenthous from tenk1 where thousand = 42 and tenthous < 2000 offset 0) as q; select row_to_json(q) from - ( - select - thousand, - tenthous - from - tenk1 - where - thousand = 42 and tenthous < 2000 - offset 0 - ) - as q; + (select thousand, tenthous from tenk1 where thousand = 42 and tenthous < 2000 offset 0) as q; select row_to_json(q) from ( - select - thousand as x, - tenthous as y - from - tenk1 - where - thousand = 42 and tenthous < 2000 - offset 0 + select thousand as x, tenthous as y from tenk1 where thousand = 42 and tenthous < 2000 offset 0 ) as q; @@ -630,14 +585,7 @@ select row_to_json(q) from ( - select - thousand as x, - tenthous as y - from - tenk1 - where - thousand = 42 and tenthous < 2000 - offset 0 + select thousand as x, tenthous as y from tenk1 where thousand = 42 and tenthous < 2000 offset 0 ) as q (a, b); @@ -659,7 +607,7 @@ select row_to_json(cast(cast(tt3 as tt2) as tt1)) from tt3; select r, - r is null as isnull, + r is null as "isnull", r is not null as isnotnull from ( @@ -675,7 +623,7 @@ from select r, - r is null as isnull, + r is null as "isnull", r is not null as isnotnull from ( @@ -690,8 +638,7 @@ from as r (a, b); with -r (a, -b) +r (a, b) as materialized ( values (1, row(1, 2)), @@ -703,14 +650,13 @@ as materialized ( ) select r, - r is null as isnull, + r is null as "isnull", r is not null as isnotnull from r; with -r (a, -b) +r (a, b) as materialized ( values (1, row(1, 2)), @@ -722,58 +668,33 @@ as materialized ( ) select r, - r is null as isnull, + r is null as "isnull", r is not null as isnotnull from r; -with -cte (c) as materialized (select row(1, 2)), -cte2 (c) as (select * from cte) +with cte (c) as materialized (select row(1, 2)), cte2 (c) as (select * from cte) select * from cte2 as t where - ( - select - * - from - (select c as c1) as s - where - (select (c1).f1 > 0) - ) is not null; + (select * from (select c as c1) as s where (select (c1).f1 > 0)) is not null; -with -cte (c) as materialized (select row(1, 2)), -cte2 (c) as (select * from cte) +with cte (c) as materialized (select row(1, 2)), cte2 (c) as (select * from cte) select * from cte2 as t where - ( - select - * - from - (select c as c1) as s - where - (select (c1).f1 > 0) - ) is not null; + (select * from (select c as c1) as s where (select (c1).f1 > 0)) is not null; select 1 as one from cte2 as t where - ( - select - * - from - (select c as c1) as s - where - (select (c1).f1 > 0) - ) is not null; + (select * from (select c as c1) as s where (select (c1).f1 > 0)) is not null; select pg_get_viewdef('composite_v', true); @@ -785,26 +706,17 @@ select (ss.a).x, (ss.a).n from - ( - select - information_schema._pg_expandarray(array[1, 2]) - as a - ) - as ss + (select information_schema._pg_expandarray(array[1, 2]) as a) as ss where false; -with -cte (c) as materialized (select row(1, 2)), -cte2 (c) as (select * from cte) +with cte (c) as materialized (select row(1, 2)), cte2 (c) as (select * from cte) select (c).f1 from cte2 as t; -with -cte (c) as materialized (select row(1, 2)), -cte2 (c) as (select * from cte) +with cte (c) as materialized (select row(1, 2)), cte2 (c) as (select * from cte) select (c).f1 from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowtypes_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowtypes_80.snap index d15c4e47b..cd056585f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowtypes_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowtypes_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/rowtypes.sql --- -create type complex as (r double precision, i double precision); +create type complex as (r float8, i float8); create temporary table fullname ( first text, @@ -92,11 +92,7 @@ create temporary table pp (f1 text); insert into pp values (repeat('abcdefghijkl', 100000)); insert into people -select - cast(('Jim', f1, null) as fullname), - current_date -from - pp; +select cast(('Jim', f1, null) as fullname), current_date from pp; select (fn).first, substr((fn).last, 1, 20), length((fn).last) from people; @@ -130,11 +126,11 @@ select row('ABC', 'DEF') ~>=~ row('DEF', 'ABC') as "false"; select row('ABC', 'DEF') ~~ row('DEF', 'ABC') as fail; -select row(1, 2) = row(1, cast(2 as bigint)); +select row(1, 2) = row(1, cast(2 as int8)); select row(1, 2) in (row(3, 4), row(1, 2)); -select row(1, 2) in (row(3, 4), row(1, cast(2 as bigint))); +select row(1, 2) in (row(3, 4), row(1, cast(2 as int8))); select unique1, @@ -142,16 +138,7 @@ select from tenk1 where - (unique1, unique2) < any - ( - select - ten, - ten - from - tenk1 - where - hundred < 3 - ) and + (unique1, unique2) < any (select ten, ten from tenk1 where hundred < 3) and unique1 <= 20 order by 1; @@ -182,8 +169,7 @@ select from tenk1 where - (thousand, tenthous, four) > - (998, 5000, 3) + (thousand, tenthous, four) > (998, 5000, 3) order by thousand, tenthous; @@ -194,8 +180,7 @@ select from tenk1 where - (thousand, tenthous, four) > - (998, 5000, 3) + (thousand, tenthous, four) > (998, 5000, 3) order by thousand, tenthous; @@ -267,20 +252,14 @@ select from int8_tbl as i8 where - i8 - in ( - cast(row(123, 456) as int8_tbl), '(4567890123456789,123)' - ); + i8 in (cast(row(123, 456) as int8_tbl), '(4567890123456789,123)'); select * from int8_tbl as i8 where - i8 - in ( - cast(row(123, 456) as int8_tbl), '(4567890123456789,123)' - ); + i8 in (cast(row(123, 456) as int8_tbl), '(4567890123456789,123)'); select (row(1, 2.0)).f1; @@ -308,7 +287,7 @@ select row(1, 1.1) = any (array[row(7, 7.7), row(1, 1.1), row(0, 0.0)]); select row(1, 1.1) = any (array[row(7, 7.7), row(1, 1.0), row(0, 0.0)]); -create type cantcompare as (p point, r double precision); +create type cantcompare as (p point, r float8); create temporary table cc (f1 cantcompare); @@ -394,7 +373,7 @@ select cast(row(1, -3) as testtype1) *> cast(row(1, -2) as testtype1); select cast(row(1, -2) as testtype1) *< cast(row(1, 3) as testtype1); -create type testtype2 as (a smallint, b boolean); +create type testtype2 as (a smallint, b bool); select cast(row(1, true) as testtype2) *< cast(row(2, true) as testtype2); @@ -419,8 +398,7 @@ create type testtype4 as (a int, b point); select cast(row(1, '(1,2)') as testtype4) *< cast(row(1, '(1,3)') as testtype4); select - cast(row(1, '(1,2)') as testtype4) *<> - cast(row(1, '(1,3)') as testtype4); + cast(row(1, '(1,2)') as testtype4) *<> cast(row(1, '(1,3)') as testtype4); select cast(row(1, 2) as testtype1) *< cast(row(1, 'abc') as testtype3); @@ -437,12 +415,10 @@ create type testtype6 as (a int, b point); select cast(row(1, '(1,2)') as testtype6) *< cast(row(1, '(1,3)') as testtype6); select - cast(row(1, '(1,2)') as testtype6) *>= - cast(row(1, '(1,3)') as testtype6); + cast(row(1, '(1,2)') as testtype6) *>= cast(row(1, '(1,3)') as testtype6); select - cast(row(1, '(1,2)') as testtype6) *<> - cast(row(1, '(1,3)') as testtype6); + cast(row(1, '(1,2)') as testtype6) *<> cast(row(1, '(1,3)') as testtype6); select q.a, @@ -451,14 +427,8 @@ select q.d = row(row(4)) from unnest( - array[row(1, - row(2), - array[row(3)], - row(row(4))), - row(2, - row(3), - array[row(4)], - row(row(5)))] + array[row(1, row(2), array[row(3)], row(row(4))), + row(2, row(3), array[row(4)], row(row(5)))] ) as q (a int, b record, c record[], d record); @@ -480,30 +450,26 @@ create type price_key as (id int); create function price_key_from_table(price) returns price_key language sql -as $function$ -SELECT $1.id -$function$; +as $$ + SELECT $1.id +$$; create function price_key_from_input(price_input) returns price_key language sql -as $function$ -SELECT $1.id -$function$; +as $$ + SELECT $1.id +$$; insert into price values (1, false, 42), (10, false, 100), (11, true, 17.99); update price set active = true, price = input_prices.price -from unnest( - cast(array[(10, 123.00), (11, 99.99)] - as price_input[]) -) +from unnest(cast(array[(10, 123.00), (11, 99.99)] as price_input[])) as input_prices where - price_key_from_table(price.*) = - price_key_from_input(input_prices.*); + price_key_from_table(price.*) = price_key_from_input(input_prices.*); select * from price; @@ -517,30 +483,30 @@ create temporary table compos ( create function fcompos1(v compos) returns void language sql -as $function$ +as $$ insert into compos values (v); -- fail -$function$; +$$; create function fcompos1(v compos) returns void language sql -as $function$ +as $$ insert into compos values (v.*); -$function$; +$$; create function fcompos2(v compos) returns void language sql -as $function$ +as $$ select fcompos1(v); -$function$; +$$; create function fcompos3(v compos) returns void language sql -as $function$ +as $$ select fcompos1(fcompos3.v.*); -$function$; +$$; select fcompos1(row(1, 'one')); @@ -575,9 +541,7 @@ select last(f) from fullname as f; create function longname(fullname) returns text language sql -as $function$ -select $1.first || ' ' || $1.last -$function$; +as $$select $1.first || ' ' || $1.last$$; select f.longname from fullname as f; @@ -603,36 +567,17 @@ select row_to_json(ss) from (select q1 as a, q2 as b from int8_tbl) as ss; select row_to_json(ss) from - ( - select - q1 as a, - q2 as b - from - int8_tbl - offset 0 - ) - as ss; + (select q1 as a, q2 as b from int8_tbl offset 0) as ss; select row_to_json(ss) from - ( - select q1 as a, q2 as b from int8_tbl - ) - as ss (x, y); + (select q1 as a, q2 as b from int8_tbl) as ss (x, y); select row_to_json(ss) from - ( - select - q1 as a, - q2 as b - from - int8_tbl - offset 0 - ) - as ss (x, y); + (select q1 as a, q2 as b from int8_tbl offset 0) as ss (x, y); select row_to_json(q) @@ -712,7 +657,7 @@ select row_to_json(cast(cast(tt3 as tt2) as tt1)) from tt3; select r, - r is null as isnull, + r is null as "isnull", r is not null as isnotnull from ( @@ -728,7 +673,7 @@ from select r, - r is null as isnull, + r is null as "isnull", r is not null as isnotnull from ( @@ -743,8 +688,7 @@ from as r (a, b); with -r (a, -b) +r (a, b) as materialized ( values (1, row(1, 2)), @@ -756,14 +700,13 @@ as materialized ( ) select r, - r is null as isnull, + r is null as "isnull", r is not null as isnotnull from r; with -r (a, -b) +r (a, b) as materialized ( values (1, row(1, 2)), @@ -775,64 +718,33 @@ as materialized ( ) select r, - r is null as isnull, + r is null as "isnull", r is not null as isnotnull from r; -with -cte (c) -as materialized ( - select row(1, 2) -), -cte2 (c) as (select * from cte) +with cte (c) as materialized (select row(1, 2)), cte2 (c) as (select * from cte) select * from cte2 as t where - ( - select - * - from - (select c as c1) as s - where - (select (c1).f1 > 0) - ) is not null; + (select * from (select c as c1) as s where (select (c1).f1 > 0)) is not null; -with -cte (c) -as materialized ( - select row(1, 2) -), -cte2 (c) as (select * from cte) +with cte (c) as materialized (select row(1, 2)), cte2 (c) as (select * from cte) select * from cte2 as t where - ( - select - * - from - (select c as c1) as s - where - (select (c1).f1 > 0) - ) is not null; + (select * from (select c as c1) as s where (select (c1).f1 > 0)) is not null; select 1 as one from cte2 as t where - ( - select - * - from - (select c as c1) as s - where - (select (c1).f1 > 0) - ) is not null; + (select * from (select c as c1) as s where (select (c1).f1 > 0)) is not null; select pg_get_viewdef('composite_v', true); @@ -842,47 +754,23 @@ select (ss.a).x, (ss.a).n from - ( - select - information_schema._pg_expandarray( - array[1, 2] - ) - as a - ) - as ss; + (select information_schema._pg_expandarray(array[1, 2]) as a) as ss; select (ss.a).x, (ss.a).n from - ( - select - information_schema._pg_expandarray( - array[1, 2] - ) - as a - ) - as ss + (select information_schema._pg_expandarray(array[1, 2]) as a) as ss where false; -with -cte (c) -as materialized ( - select row(1, 2) -), -cte2 (c) as (select * from cte) +with cte (c) as materialized (select row(1, 2)), cte2 (c) as (select * from cte) select (c).f1 from cte2 as t; -with -cte (c) -as materialized ( - select row(1, 2) -), -cte2 (c) as (select * from cte) +with cte (c) as materialized (select row(1, 2)), cte2 (c) as (select * from cte) select (c).f1 from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rules_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rules_100.snap index 4d7e823e5..31f999ad6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rules_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rules_100.snap @@ -4,18 +4,18 @@ input_file: crates/pgls_pretty_print/tests/data/multi/rules.sql snapshot_kind: text --- create table rtest_t1 ( - a int, - b int + a int4, + b int4 ); create table rtest_t2 ( - a int, - b int + a int4, + b int4 ); create table rtest_t3 ( - a int, - b int + a int4, + b int4 ); create view rtest_v1 @@ -29,11 +29,7 @@ do instead create rule rtest_v1_upd as on update to rtest_v1 do instead - update rtest_t1 - set a = new.a, - b = new.b - where - a = old.a;; + update rtest_t1 set a = new.a, b = new.b where a = old.a;; create rule rtest_v1_del as on delete to rtest_v1 @@ -69,32 +65,19 @@ create table rtest_admin ( create rule rtest_sys_upd as on update to rtest_system do - (update rtest_interface - set sysname = new.sysname - where - sysname = old.sysname;; - update rtest_admin - set sysname = new.sysname - where - sysname = old.sysname;); + (update rtest_interface set sysname = new.sysname where sysname = old.sysname;; + update rtest_admin set sysname = new.sysname where sysname = old.sysname;); create rule rtest_sys_del as on delete to rtest_system do - (delete from rtest_interface - where - sysname = old.sysname;; - delete from rtest_admin - where - sysname = old.sysname;); + (delete from rtest_interface where sysname = old.sysname;; + delete from rtest_admin where sysname = old.sysname;); create rule rtest_pers_upd as on update to rtest_person do - update rtest_admin - set pname = new.pname - where - pname = old.pname;; + update rtest_admin set pname = new.pname where pname = old.pname;; create rule rtest_pers_del as on delete to rtest_person @@ -122,70 +105,46 @@ create table rtest_empmass ( create rule rtest_emp_ins as on insert to rtest_emp do - insert into rtest_emplog - values - ( - new.ename, - current_user, - 'hired', - new.salary, - '0.00' - );; + insert into rtest_emplog values (new.ename, current_user, 'hired', new.salary, '0.00');; create rule rtest_emp_upd as on update to rtest_emp where new.salary <> old.salary do - insert into rtest_emplog - values - ( - new.ename, - current_user, - 'honored', - new.salary, - old.salary - );; + insert into rtest_emplog values (new.ename, current_user, 'honored', new.salary, old.salary);; create rule rtest_emp_del as on delete to rtest_emp do - insert into rtest_emplog - values - ( - old.ename, - current_user, - 'fired', - '0.00', - old.salary - );; + insert into rtest_emplog values (old.ename, current_user, 'fired', '0.00', old.salary);; create table rtest_t4 ( - a int, + a int4, b text ); create table rtest_t5 ( - a int, + a int4, b text ); create table rtest_t6 ( - a int, + a int4, b text ); create table rtest_t7 ( - a int, + a int4, b text ); create table rtest_t8 ( - a int, + a int4, b text ); create table rtest_t9 ( - a int, + a int4, b text ); @@ -213,11 +172,11 @@ as on insert to rtest_t6 where do instead insert into rtest_t8 values (new.a, new.b);; -create table rtest_order1 (a int); +create table rtest_order1 (a int4); create table rtest_order2 ( - a int, - b int, + a int4, + b int4, c text ); @@ -226,65 +185,41 @@ create sequence rtest_seq; create rule rtest_order_r3 as on insert to rtest_order1 do instead - insert into rtest_order2 - values - ( - new.a, - nextval('rtest_seq'), - 'rule 3 - this should run 3rd' - );; + insert into rtest_order2 values (new.a, nextval('rtest_seq'), 'rule 3 - this should run 3rd');; create rule rtest_order_r4 as on insert to rtest_order1 where a < 100 do instead - insert into rtest_order2 - values - ( - new.a, - nextval('rtest_seq'), - 'rule 4 - this should run 4th' - );; + insert into rtest_order2 values (new.a, nextval('rtest_seq'), 'rule 4 - this should run 4th');; create rule rtest_order_r2 as on insert to rtest_order1 do - insert into rtest_order2 - values - ( - new.a, - nextval('rtest_seq'), - 'rule 2 - this should run 2nd' - );; + insert into rtest_order2 values (new.a, nextval('rtest_seq'), 'rule 2 - this should run 2nd');; create rule rtest_order_r1 as on insert to rtest_order1 do instead - insert into rtest_order2 - values - ( - new.a, - nextval('rtest_seq'), - 'rule 1 - this should run 1st' - );; + insert into rtest_order2 values (new.a, nextval('rtest_seq'), 'rule 1 - this should run 1st');; create table rtest_nothn1 ( - a int, + a int4, b text ); create table rtest_nothn2 ( - a int, + a int4, b text ); create table rtest_nothn3 ( - a int, + a int4, b text ); create table rtest_nothn4 ( - a int, + a int4, b text ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rules_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rules_80.snap index e55cf3639..417d501f7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rules_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rules_80.snap @@ -4,18 +4,18 @@ input_file: crates/pgls_pretty_print/tests/data/multi/rules.sql snapshot_kind: text --- create table rtest_t1 ( - a int, - b int + a int4, + b int4 ); create table rtest_t2 ( - a int, - b int + a int4, + b int4 ); create table rtest_t3 ( - a int, - b int + a int4, + b int4 ); create view rtest_v1 @@ -24,17 +24,12 @@ as select * from rtest_t1; create rule rtest_v1_ins as on insert to rtest_v1 do instead - insert into rtest_t1 - values (new.a, new.b);; + insert into rtest_t1 values (new.a, new.b);; create rule rtest_v1_upd as on update to rtest_v1 do instead - update rtest_t1 - set a = new.a, - b = new.b - where - a = old.a;; + update rtest_t1 set a = new.a, b = new.b where a = old.a;; create rule rtest_v1_del as on delete to rtest_v1 @@ -74,35 +69,23 @@ do set sysname = new.sysname where sysname = old.sysname;; - update rtest_admin - set sysname = new.sysname - where - sysname = old.sysname;); + update rtest_admin set sysname = new.sysname where sysname = old.sysname;); create rule rtest_sys_del as on delete to rtest_system do - (delete from rtest_interface - where - sysname = old.sysname;; - delete from rtest_admin - where - sysname = old.sysname;); + (delete from rtest_interface where sysname = old.sysname;; + delete from rtest_admin where sysname = old.sysname;); create rule rtest_pers_upd as on update to rtest_person do - update rtest_admin - set pname = new.pname - where - pname = old.pname;; + update rtest_admin set pname = new.pname where pname = old.pname;; create rule rtest_pers_del as on delete to rtest_person do - delete from rtest_admin - where - pname = old.pname;; + delete from rtest_admin where pname = old.pname;; create table rtest_emp ( ename char(20), @@ -126,69 +109,48 @@ create rule rtest_emp_ins as on insert to rtest_emp do insert into rtest_emplog - values - ( - new.ename, - current_user, - 'hired', - new.salary, - '0.00' - );; + values (new.ename, current_user, 'hired', new.salary, '0.00');; create rule rtest_emp_upd as on update to rtest_emp where new.salary <> old.salary do insert into rtest_emplog - values - ( - new.ename, - current_user, - 'honored', - new.salary, - old.salary - );; + values (new.ename, current_user, 'honored', new.salary, old.salary);; create rule rtest_emp_del as on delete to rtest_emp do insert into rtest_emplog - values - ( - old.ename, - current_user, - 'fired', - '0.00', - old.salary - );; + values (old.ename, current_user, 'fired', '0.00', old.salary);; create table rtest_t4 ( - a int, + a int4, b text ); create table rtest_t5 ( - a int, + a int4, b text ); create table rtest_t6 ( - a int, + a int4, b text ); create table rtest_t7 ( - a int, + a int4, b text ); create table rtest_t8 ( - a int, + a int4, b text ); create table rtest_t9 ( - a int, + a int4, b text ); @@ -196,35 +158,31 @@ create rule rtest_t4_ins1 as on insert to rtest_t4 where new.a >= 10 and new.a < 20 do instead - insert into rtest_t5 - values (new.a, new.b);; + insert into rtest_t5 values (new.a, new.b);; create rule rtest_t4_ins2 as on insert to rtest_t4 where new.a >= 20 and new.a < 30 do - insert into rtest_t6 - values (new.a, new.b);; + insert into rtest_t6 values (new.a, new.b);; create rule rtest_t5_ins as on insert to rtest_t5 where new.a > 15 do - insert into rtest_t7 - values (new.a, new.b);; + insert into rtest_t7 values (new.a, new.b);; create rule rtest_t6_ins as on insert to rtest_t6 where new.a > 25 do instead - insert into rtest_t8 - values (new.a, new.b);; + insert into rtest_t8 values (new.a, new.b);; -create table rtest_order1 (a int); +create table rtest_order1 (a int4); create table rtest_order2 ( - a int, - b int, + a int4, + b int4, c text ); @@ -234,64 +192,44 @@ create rule rtest_order_r3 as on insert to rtest_order1 do instead insert into rtest_order2 - values - ( - new.a, - nextval('rtest_seq'), - 'rule 3 - this should run 3rd' - );; + values (new.a, nextval('rtest_seq'), 'rule 3 - this should run 3rd');; create rule rtest_order_r4 as on insert to rtest_order1 where a < 100 do instead insert into rtest_order2 - values - ( - new.a, - nextval('rtest_seq'), - 'rule 4 - this should run 4th' - );; + values (new.a, nextval('rtest_seq'), 'rule 4 - this should run 4th');; create rule rtest_order_r2 as on insert to rtest_order1 do insert into rtest_order2 - values - ( - new.a, - nextval('rtest_seq'), - 'rule 2 - this should run 2nd' - );; + values (new.a, nextval('rtest_seq'), 'rule 2 - this should run 2nd');; create rule rtest_order_r1 as on insert to rtest_order1 do instead insert into rtest_order2 - values - ( - new.a, - nextval('rtest_seq'), - 'rule 1 - this should run 1st' - );; + values (new.a, nextval('rtest_seq'), 'rule 1 - this should run 1st');; create table rtest_nothn1 ( - a int, + a int4, b text ); create table rtest_nothn2 ( - a int, + a int4, b text ); create table rtest_nothn3 ( - a int, + a int4, b text ); create table rtest_nothn4 ( - a int, + a int4, b text ); @@ -311,8 +249,7 @@ create rule rtest_nothn_r3 as on insert to rtest_nothn2 where new.a >= 100 do instead - insert into rtest_nothn3 - values (new.a, new.b);; + insert into rtest_nothn3 values (new.a, new.b);; create rule rtest_nothn_r4 as on insert to rtest_nothn2 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sanity_check_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sanity_check_100.snap index 2c2a27ea9..af7143d28 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sanity_check_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sanity_check_100.snap @@ -9,10 +9,7 @@ select relname, nspname from - pg_class as c - left outer join - pg_namespace as n - on n.oid = relnamespace + pg_class as c left outer join pg_namespace as n on n.oid = relnamespace inner join pg_attribute as a on attrelid = c.oid and attname = 'oid' @@ -27,11 +24,7 @@ where from pg_index as i where - indrelid = c.oid and - indkey[0] = a.attnum and - indnatts = 1 and - indisunique and - indimmediate + indrelid = c.oid and indkey[0] = a.attnum and indnatts = 1 and indisunique and indimmediate ); select @@ -40,5 +33,4 @@ select from pg_class where - relkind in ('v', 'c', 'f', 'p', 'I') and - relfilenode <> 0; + relkind in ('v', 'c', 'f', 'p', 'I') and relfilenode <> 0; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sanity_check_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sanity_check_80.snap index 2c2a27ea9..215df96ce 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sanity_check_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sanity_check_80.snap @@ -9,10 +9,7 @@ select relname, nspname from - pg_class as c - left outer join - pg_namespace as n - on n.oid = relnamespace + pg_class as c left outer join pg_namespace as n on n.oid = relnamespace inner join pg_attribute as a on attrelid = c.oid and attname = 'oid' @@ -40,5 +37,4 @@ select from pg_class where - relkind in ('v', 'c', 'f', 'p', 'I') and - relfilenode <> 0; + relkind in ('v', 'c', 'f', 'p', 'I') and relfilenode <> 0; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__security_label_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__security_label_100.snap index c548852ba..4a7bb499e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__security_label_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__security_label_100.snap @@ -30,9 +30,7 @@ as select * from seclabel_tbl2; create function seclabel_four() returns int language sql -as $function$ -SELECT 4 -$function$; +as $$SELECT 4$$; create domain seclabel_domain as text; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__security_label_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__security_label_80.snap index c548852ba..4a7bb499e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__security_label_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__security_label_80.snap @@ -30,9 +30,7 @@ as select * from seclabel_tbl2; create function seclabel_four() returns int language sql -as $function$ -SELECT 4 -$function$; +as $$SELECT 4$$; create domain seclabel_domain as text; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_100.snap index 88bac949e..8ab3846b7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_100.snap @@ -82,10 +82,7 @@ select * from onek, - ( - values (147, 'RFAAAA'), (931, 'VJAAAA') - ) - as v (i, j) + (values (147, 'RFAAAA'), (931, 'VJAAAA')) as v (i, j) where onek.unique1 = v.i and onek.stringu1 = v.j; @@ -100,16 +97,7 @@ from select i from - ( - values - (10000), - (2), - (389), - (1000), - (2000), - ((select 10029)) - ) - as foo (i) + (values (10000), (2), (389), (1000), (2000), ((select 10029))) as foo (i) order by i asc limit 1 ) @@ -124,10 +112,7 @@ select from onek where - (unique1, ten) in - ( - values (1, 1), (20, 0), (99, 9), (17, 99) - ) + (unique1, ten) in (values (1, 1), (20, 0), (99, 9), (17, 99)) order by unique1; values (1, 2), (3, 4 + 4), (7, 77.7); @@ -154,7 +139,7 @@ select * from foo order by f1 desc; select * from foo order by f1 desc nulls last; -create index "fooi" on foo using btree (f1); +create index fooi on foo using btree (f1); set enable_sort = 'false'; @@ -168,7 +153,7 @@ select * from foo order by f1 desc nulls last; drop index fooi; -create index "fooi" on foo using btree (f1 desc); +create index fooi on foo using btree (f1 desc); select * from foo order by f1; @@ -180,7 +165,7 @@ select * from foo order by f1 desc nulls last; drop index fooi; -create index "fooi" on foo using btree (f1 desc nulls last); +create index fooi on foo using btree (f1 desc nulls last); select * from foo order by f1; @@ -238,9 +223,7 @@ create function sillysrf(int) returns setof int language sql immutable -as $function$ -values (1),(10),(2),($1) -$function$; +as 'values (1),(10),(2),($1)'; select sillysrf(42); @@ -256,9 +239,9 @@ create table list_parted_tbl ( a int, b int ) -partition by LIST(a); +partition by list(a); -create table list_parted_tbl1 partition of list_parted_tbl for values in (1) partition by LIST(b); +create table list_parted_tbl1 partition of list_parted_tbl for values in (1) partition by list(b); select * from list_parted_tbl; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_80.snap index d15218672..beecb4ff5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_80.snap @@ -103,13 +103,9 @@ select * from onek, - ( - values (147, 'RFAAAA'), (931, 'VJAAAA') - ) - as v (i, j) + (values (147, 'RFAAAA'), (931, 'VJAAAA')) as v (i, j) where - onek.unique1 = v.i and - onek.stringu1 = v.j; + onek.unique1 = v.i and onek.stringu1 = v.j; select * @@ -123,13 +119,7 @@ from i from ( - values - (10000), - (2), - (389), - (1000), - (2000), - ((select 10029)) + values (10000), (2), (389), (1000), (2000), ((select 10029)) ) as foo (i) order by i asc @@ -146,21 +136,12 @@ select from onek where - (unique1, ten) in - ( - values - (1, 1), - (20, 0), - (99, 9), - (17, 99) - ) + (unique1, ten) in (values (1, 1), (20, 0), (99, 9), (17, 99)) order by unique1; values (1, 2), (3, 4 + 4), (7, 77.7); -values (1, 2), (3, 4 + 4), (7, 77.7) -union all -select 2 + 2, 57 +values (1, 2), (3, 4 + 4), (7, 77.7) union all select 2 + 2, 57 union all select * from int8_tbl; @@ -184,7 +165,7 @@ select * from foo order by f1 desc; select * from foo order by f1 desc nulls last; -create index "fooi" on foo using btree (f1); +create index fooi on foo using btree (f1); set enable_sort = 'false'; @@ -198,7 +179,7 @@ select * from foo order by f1 desc nulls last; drop index fooi; -create index "fooi" on foo using btree (f1 desc); +create index fooi on foo using btree (f1 desc); select * from foo order by f1; @@ -210,7 +191,7 @@ select * from foo order by f1 desc nulls last; drop index fooi; -create index "fooi" on foo using btree (f1 desc nulls last); +create index fooi on foo using btree (f1 desc nulls last); select * from foo order by f1; @@ -260,10 +241,7 @@ select from onek2 where - ( - unique2 = 11 or unique1 = 0 - ) and - stringu1 < 'B'; + (unique2 = 11 or unique1 = 0) and stringu1 < 'B'; select unique1, @@ -271,10 +249,7 @@ select from onek2 where - ( - unique2 = 11 or unique1 = 0 - ) and - stringu1 < 'B'; + (unique2 = 11 or unique1 = 0) and stringu1 < 'B'; select unique1, @@ -282,8 +257,7 @@ select from onek2 where - (unique2 = 11 and stringu1 < 'B') or - unique1 = 0; + (unique2 = 11 and stringu1 < 'B') or unique1 = 0; select unique1, @@ -291,8 +265,7 @@ select from onek2 where - (unique2 = 11 and stringu1 < 'B') or - unique1 = 0; + (unique2 = 11 and stringu1 < 'B') or unique1 = 0; select 1 as x order by x; @@ -300,9 +273,7 @@ create function sillysrf(int) returns setof int language sql immutable -as $function$ -values (1),(10),(2),($1) -$function$; +as 'values (1),(10),(2),($1)'; select sillysrf(42); @@ -318,12 +289,12 @@ create table list_parted_tbl ( a int, b int ) -partition by LIST(a); +partition by list(a); create table list_parted_tbl1 partition of list_parted_tbl for values in (1) -partition by LIST(b); +partition by list(b); select * from list_parted_tbl; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_100.snap index 7c90a7927..0cc70229b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_100.snap @@ -12,9 +12,9 @@ select distinct two, string4, ten from onek order by two using <, string4 using select distinct p.age from person as p order by age using >; -select COUNT(*) from (select distinct two, four, two from tenk1) as ss; +select count(*) from (select distinct two, four, two from tenk1) as ss; -select COUNT(*) from (select distinct two, four, two from tenk1) as ss; +select count(*) from (select distinct two, four, two from tenk1) as ss; set work_mem = '64kB'; @@ -30,10 +30,7 @@ set jit_above_cost = default; create table distinct_group_2 as - select distinct - cast(g % 1000 as text) - from - generate_series(0, 9999) as g; + select distinct cast(g % 1000 as text) from generate_series(0, 9999) as g; set enable_seqscan = 0; @@ -55,30 +52,19 @@ set jit_above_cost = default; create table distinct_hash_2 as - select distinct - cast(g % 1000 as text) - from - generate_series(0, 9999) as g; + select distinct cast(g % 1000 as text) from generate_series(0, 9999) as g; set enable_sort = 'true'; set work_mem = default; -select * from distinct_hash_1 -except -select * from distinct_group_1 +select * from distinct_hash_1 except select * from distinct_group_1 union all -(select * from distinct_group_1 -except -select * from distinct_hash_1); +(select * from distinct_group_1 except select * from distinct_hash_1); -select * from distinct_hash_1 -except -select * from distinct_group_1 +select * from distinct_hash_1 except select * from distinct_group_1 union all -(select * from distinct_group_1 -except -select * from distinct_hash_1); +(select * from distinct_group_1 except select * from distinct_hash_1); drop table distinct_hash_1; @@ -103,24 +89,24 @@ select distinct four from tenk1; create or replace function distinct_func(a int) returns int language plpgsql -parallel UNSAFE -as $function$ -BEGIN +parallel unsafe +as $$ + BEGIN RETURN a; END; -$function$; +$$; select distinct distinct_func(1) from tenk1; create or replace function distinct_func(a int) returns int language plpgsql -parallel SAFE -as $function$ -BEGIN +parallel safe +as $$ + BEGIN RETURN a; END; -$function$; +$$; select distinct distinct_func(1) from tenk1; @@ -199,7 +185,7 @@ create table distinct_tbl ( insert into distinct_tbl select i % 10, i % 10 from generate_series(1, 1000) as i; -create index "distinct_tbl_x_y_idx" on distinct_tbl using btree (x, y); +create index distinct_tbl_x_y_idx on distinct_tbl using btree (x, y); analyze distinct_tbl; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_80.snap index a4628f8cf..d962cfe6a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_80.snap @@ -20,9 +20,9 @@ order by two using <, select distinct p.age from person as p order by age using >; -select COUNT(*) from (select distinct two, four, two from tenk1) as ss; +select count(*) from (select distinct two, four, two from tenk1) as ss; -select COUNT(*) from (select distinct two, four, two from tenk1) as ss; +select count(*) from (select distinct two, four, two from tenk1) as ss; set work_mem = '64kB'; @@ -34,19 +34,13 @@ select distinct g % 1000 from generate_series(0, 9999) as g; create table distinct_group_1 as - select distinct - g % 1000 - from - generate_series(0, 9999) as g; + select distinct g % 1000 from generate_series(0, 9999) as g; set jit_above_cost = default; create table distinct_group_2 as - select distinct - cast(g % 1000 as text) - from - generate_series(0, 9999) as g; + select distinct cast(g % 1000 as text) from generate_series(0, 9999) as g; set enable_seqscan = 0; @@ -64,39 +58,25 @@ select distinct g % 1000 from generate_series(0, 9999) as g; create table distinct_hash_1 as - select distinct - g % 1000 - from - generate_series(0, 9999) as g; + select distinct g % 1000 from generate_series(0, 9999) as g; set jit_above_cost = default; create table distinct_hash_2 as - select distinct - cast(g % 1000 as text) - from - generate_series(0, 9999) as g; + select distinct cast(g % 1000 as text) from generate_series(0, 9999) as g; set enable_sort = 'true'; set work_mem = default; -select * from distinct_hash_1 -except -select * from distinct_group_1 +select * from distinct_hash_1 except select * from distinct_group_1 union all -(select * from distinct_group_1 -except -select * from distinct_hash_1); +(select * from distinct_group_1 except select * from distinct_hash_1); -select * from distinct_hash_1 -except -select * from distinct_group_1 +select * from distinct_hash_1 except select * from distinct_group_1 union all -(select * from distinct_group_1 -except -select * from distinct_hash_1); +(select * from distinct_group_1 except select * from distinct_hash_1); drop table distinct_hash_1; @@ -121,24 +101,24 @@ select distinct four from tenk1; create or replace function distinct_func(a int) returns int language plpgsql -parallel UNSAFE -as $function$ -BEGIN +parallel unsafe +as $$ + BEGIN RETURN a; END; -$function$; +$$; select distinct distinct_func(1) from tenk1; create or replace function distinct_func(a int) returns int language plpgsql -parallel SAFE -as $function$ -BEGIN +parallel safe +as $$ + BEGIN RETURN a; END; -$function$; +$$; select distinct distinct_func(1) from tenk1; @@ -216,13 +196,9 @@ create table distinct_tbl ( ); insert into distinct_tbl -select - i % 10, - i % 10 -from - generate_series(1, 1000) as i; +select i % 10, i % 10 from generate_series(1, 1000) as i; -create index "distinct_tbl_x_y_idx" on distinct_tbl using btree (x, y); +create index distinct_tbl_x_y_idx on distinct_tbl using btree (x, y); analyze distinct_tbl; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_100.snap index f0e2791c2..5a5518717 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_100.snap @@ -50,7 +50,7 @@ create table distinct_on_tbl ( insert into distinct_on_tbl select i % 10, i % 10, i % 10 from generate_series(1, 1000) as i; -create index "distinct_on_tbl_x_y_idx" on distinct_on_tbl using btree (x, y); +create index distinct_on_tbl_x_y_idx on distinct_on_tbl using btree (x, y); analyze distinct_on_tbl; @@ -72,10 +72,7 @@ select distinct on (y, x) x, y from - ( - select * from distinct_on_tbl order by x, z, y - ) - as s + (select * from distinct_on_tbl order by x, z, y) as s order by y, x, z; @@ -84,10 +81,7 @@ select distinct on (y, x) x, y from - ( - select * from distinct_on_tbl order by x, z, y - ) - as s + (select * from distinct_on_tbl order by x, z, y) as s order by y, x, z; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_80.snap index 078fae5eb..c986288b7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_distinct_on_80.snap @@ -49,14 +49,9 @@ create table distinct_on_tbl ( ); insert into distinct_on_tbl -select - i % 10, - i % 10, - i % 10 -from - generate_series(1, 1000) as i; +select i % 10, i % 10, i % 10 from generate_series(1, 1000) as i; -create index "distinct_on_tbl_x_y_idx" on distinct_on_tbl using btree (x, y); +create index distinct_on_tbl_x_y_idx on distinct_on_tbl using btree (x, y); analyze distinct_on_tbl; @@ -70,19 +65,13 @@ select distinct on (y, x) x, y from - ( - select * from distinct_on_tbl order by x - ) - as s; + (select * from distinct_on_tbl order by x) as s; select distinct on (y, x) x, y from - ( - select * from distinct_on_tbl order by x - ) - as s; + (select * from distinct_on_tbl order by x) as s; select distinct on (y, x) x, y from distinct_on_tbl order by y; @@ -92,16 +81,7 @@ select distinct on (y, x) x, y from - ( - select - * - from - distinct_on_tbl - order by x, - z, - y - ) - as s + (select * from distinct_on_tbl order by x, z, y) as s order by y, x, z; @@ -110,16 +90,7 @@ select distinct on (y, x) x, y from - ( - select - * - from - distinct_on_tbl - order by x, - z, - y - ) - as s + (select * from distinct_on_tbl order by x, z, y) as s order by y, x, z; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_having_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_having_100.snap index 2413bc017..dcb63e86d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_having_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_having_100.snap @@ -30,27 +30,27 @@ insert into test_having values (8, 4, 'CCCC', 'I'); insert into test_having values (9, 4, 'CCCC', 'j'); -select b, c from test_having group by b, c having COUNT(*) = 1 order by b, c; +select b, c from test_having group by b, c having count(*) = 1 order by b, c; select b, c from test_having group by b, c having b = 3 order by b, c; select lower(c), - COUNT(c) + count(c) from test_having group by lower(c) having - COUNT(*) > 2 or MIN(a) = MAX(a) + count(*) > 2 or min(a) = max(a) order by lower(c); -select c, MAX(a) from test_having group by c having COUNT(*) > 2 or MIN(a) = MAX(a) order by c; +select c, max(a) from test_having group by c having count(*) > 2 or min(a) = max(a) order by c; -select MIN(a), MAX(a) from test_having having MIN(a) = MAX(a); +select min(a), max(a) from test_having having min(a) = max(a); -select MIN(a), MAX(a) from test_having having MIN(a) < MAX(a); +select min(a), max(a) from test_having having min(a) < max(a); -select a from test_having having MIN(a) < MAX(a); +select a from test_having having min(a) < max(a); select 1 as one from test_having having a > 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_having_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_having_80.snap index bafa62483..cddc22cfd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_having_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_having_80.snap @@ -30,35 +30,35 @@ insert into test_having values (8, 4, 'CCCC', 'I'); insert into test_having values (9, 4, 'CCCC', 'j'); -select b, c from test_having group by b, c having COUNT(*) = 1 order by b, c; +select b, c from test_having group by b, c having count(*) = 1 order by b, c; select b, c from test_having group by b, c having b = 3 order by b, c; select lower(c), - COUNT(c) + count(c) from test_having group by lower(c) having - COUNT(*) > 2 or MIN(a) = MAX(a) + count(*) > 2 or min(a) = max(a) order by lower(c); select c, - MAX(a) + max(a) from test_having group by c having - COUNT(*) > 2 or MIN(a) = MAX(a) + count(*) > 2 or min(a) = max(a) order by c; -select MIN(a), MAX(a) from test_having having MIN(a) = MAX(a); +select min(a), max(a) from test_having having min(a) = max(a); -select MIN(a), MAX(a) from test_having having MIN(a) < MAX(a); +select min(a), max(a) from test_having having min(a) < max(a); -select a from test_having having MIN(a) < MAX(a); +select a from test_having having min(a) < max(a); select 1 as one from test_having having a > 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_implicit_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_implicit_100.snap index 47bbc751e..aafb04e27 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_implicit_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_implicit_100.snap @@ -30,28 +30,28 @@ insert into test_missing_target values (8, 4, 'CCCC', 'I'); insert into test_missing_target values (9, 4, 'CCCC', 'j'); -select c, COUNT(*) from test_missing_target group by test_missing_target.c order by c; +select c, count(*) from test_missing_target group by test_missing_target.c order by c; -select COUNT(*) from test_missing_target group by test_missing_target.c order by c; +select count(*) from test_missing_target group by test_missing_target.c order by c; -select COUNT(*) from test_missing_target group by a order by b; +select count(*) from test_missing_target group by a order by b; -select COUNT(*) from test_missing_target group by b order by b; +select count(*) from test_missing_target group by b order by b; -select test_missing_target.b, COUNT(*) from test_missing_target group by b order by b; +select test_missing_target.b, count(*) from test_missing_target group by b order by b; select c from test_missing_target order by a; -select COUNT(*) from test_missing_target group by b order by b desc; +select count(*) from test_missing_target group by b order by b desc; -select COUNT(*) from test_missing_target order by 1 desc; +select count(*) from test_missing_target order by 1 desc; -select c, COUNT(*) from test_missing_target group by 1 order by 1; +select c, count(*) from test_missing_target group by 1 order by 1; -select c, COUNT(*) from test_missing_target group by 3; +select c, count(*) from test_missing_target group by 3; select - COUNT(*) + count(*) from test_missing_target as x, test_missing_target as y @@ -68,7 +68,7 @@ select a / 2, a / 2 from test_missing_target group by a / 2 order by a / 2; select x.b, - COUNT(*) + count(*) from test_missing_target as x, test_missing_target as y @@ -78,7 +78,7 @@ group by x.b order by x.b; select - COUNT(*) + count(*) from test_missing_target as x, test_missing_target as y @@ -90,7 +90,7 @@ order by x.b; create table test_missing_target2 as select - COUNT(*) + count(*) from test_missing_target as x, test_missing_target as y @@ -103,26 +103,26 @@ select * from test_missing_target2; select a % 2, - COUNT(b) + count(b) from test_missing_target group by test_missing_target.a % 2 order by test_missing_target.a % 2; select - COUNT(c) + count(c) from test_missing_target group by lower(test_missing_target.c) order by lower(test_missing_target.c); -select COUNT(a) from test_missing_target group by a order by b; +select count(a) from test_missing_target group by a order by b; -select COUNT(b) from test_missing_target group by b / 2 order by b / 2; +select count(b) from test_missing_target group by b / 2 order by b / 2; select lower(test_missing_target.c), - COUNT(c) + count(c) from test_missing_target group by lower(c) @@ -130,10 +130,10 @@ order by lower(c); select a from test_missing_target order by upper(d); -select COUNT(b) from test_missing_target group by (b + 1) / 2 order by (b + 1) / 2 desc; +select count(b) from test_missing_target group by (b + 1) / 2 order by (b + 1) / 2 desc; select - COUNT(x.a) + count(x.a) from test_missing_target as x, test_missing_target as y @@ -144,7 +144,7 @@ order by b / 2; select x.b / 2, - COUNT(x.b) + count(x.b) from test_missing_target as x, test_missing_target as y @@ -154,7 +154,7 @@ group by x.b / 2 order by x.b / 2; select - COUNT(b) + count(b) from test_missing_target as x, test_missing_target as y @@ -165,7 +165,7 @@ group by x.b / 2; create table test_missing_target3 as select - COUNT(x.b) + count(x.b) from test_missing_target as x, test_missing_target as y diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_implicit_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_implicit_80.snap index 0ccaf7c45..de7a8db13 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_implicit_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_implicit_80.snap @@ -32,26 +32,26 @@ insert into test_missing_target values (9, 4, 'CCCC', 'j'); select c, - COUNT(*) + count(*) from test_missing_target group by test_missing_target.c order by c; select - COUNT(*) + count(*) from test_missing_target group by test_missing_target.c order by c; -select COUNT(*) from test_missing_target group by a order by b; +select count(*) from test_missing_target group by a order by b; -select COUNT(*) from test_missing_target group by b order by b; +select count(*) from test_missing_target group by b order by b; select test_missing_target.b, - COUNT(*) + count(*) from test_missing_target group by b @@ -59,16 +59,16 @@ order by b; select c from test_missing_target order by a; -select COUNT(*) from test_missing_target group by b order by b desc; +select count(*) from test_missing_target group by b order by b desc; -select COUNT(*) from test_missing_target order by 1 desc; +select count(*) from test_missing_target order by 1 desc; -select c, COUNT(*) from test_missing_target group by 1 order by 1; +select c, count(*) from test_missing_target group by 1 order by 1; -select c, COUNT(*) from test_missing_target group by 3; +select c, count(*) from test_missing_target group by 3; select - COUNT(*) + count(*) from test_missing_target as x, test_missing_target as y @@ -85,7 +85,7 @@ select a / 2, a / 2 from test_missing_target group by a / 2 order by a / 2; select x.b, - COUNT(*) + count(*) from test_missing_target as x, test_missing_target as y @@ -95,7 +95,7 @@ group by x.b order by x.b; select - COUNT(*) + count(*) from test_missing_target as x, test_missing_target as y @@ -107,7 +107,7 @@ order by x.b; create table test_missing_target2 as select - COUNT(*) + count(*) from test_missing_target as x, test_missing_target as y @@ -120,26 +120,26 @@ select * from test_missing_target2; select a % 2, - COUNT(b) + count(b) from test_missing_target group by test_missing_target.a % 2 order by test_missing_target.a % 2; select - COUNT(c) + count(c) from test_missing_target group by lower(test_missing_target.c) order by lower(test_missing_target.c); -select COUNT(a) from test_missing_target group by a order by b; +select count(a) from test_missing_target group by a order by b; -select COUNT(b) from test_missing_target group by b / 2 order by b / 2; +select count(b) from test_missing_target group by b / 2 order by b / 2; select lower(test_missing_target.c), - COUNT(c) + count(c) from test_missing_target group by lower(c) @@ -148,14 +148,14 @@ order by lower(c); select a from test_missing_target order by upper(d); select - COUNT(b) + count(b) from test_missing_target group by (b + 1) / 2 order by (b + 1) / 2 desc; select - COUNT(x.a) + count(x.a) from test_missing_target as x, test_missing_target as y @@ -166,7 +166,7 @@ order by b / 2; select x.b / 2, - COUNT(x.b) + count(x.b) from test_missing_target as x, test_missing_target as y @@ -176,7 +176,7 @@ group by x.b / 2 order by x.b / 2; select - COUNT(b) + count(b) from test_missing_target as x, test_missing_target as y @@ -187,7 +187,7 @@ group by x.b / 2; create table test_missing_target3 as select - COUNT(x.b) + count(x.b) from test_missing_target as x, test_missing_target as y diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_into_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_into_100.snap index 28d34f246..7e0b23948 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_into_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_into_100.snap @@ -10,13 +10,13 @@ select * into sitmp1 from onek2 where onek2.unique1 < 2; drop table sitmp1; -create schema "selinto_schema"; +create schema selinto_schema; create user regress_selinto_user; alter default privileges for role regress_selinto_user -revoke INSERT on tables from regress_selinto_user; +revoke insert on tables from regress_selinto_user; grant all on schema selinto_schema to public; @@ -46,7 +46,7 @@ reset session_authorization; alter default privileges for role regress_selinto_user -grant INSERT on tables to regress_selinto_user; +grant insert on tables to regress_selinto_user; set session authorization regress_selinto_user; @@ -98,27 +98,25 @@ drop table ctas_nodata_4; create function make_table() returns void language sql -as $function$ -CREATE TABLE created_table AS SELECT * FROM int8_tbl; -$function$; +as $$ + CREATE TABLE created_table AS SELECT * FROM int8_tbl; +$$; select make_table(); select * from created_table; -do -$do$ +do $$ BEGIN EXECUTE 'EXPLAIN ANALYZE SELECT * INTO TABLE easi FROM int8_tbl'; EXECUTE 'EXPLAIN ANALYZE CREATE TABLE easi2 AS SELECT * FROM int8_tbl WITH NO DATA'; -END -$do$; +END$$; drop table created_table; drop table easi, easi2; -declare "foo" cursor for select 1 into int4_tbl;; +declare foo cursor for select 1 into int4_tbl;; copy (select 1 into frak union select 2) to 'blob'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_into_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_into_80.snap index d663b9c03..32c724769 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_into_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_into_80.snap @@ -10,15 +10,13 @@ select * into sitmp1 from onek2 where onek2.unique1 < 2; drop table sitmp1; -create schema "selinto_schema"; +create schema selinto_schema; create user regress_selinto_user; alter default privileges for role regress_selinto_user -revoke INSERT -on tables -from regress_selinto_user; +revoke insert on tables from regress_selinto_user; grant all on schema selinto_schema to public; @@ -52,9 +50,7 @@ reset session_authorization; alter default privileges for role regress_selinto_user -grant INSERT -on tables -to regress_selinto_user; +grant insert on tables to regress_selinto_user; set session authorization regress_selinto_user; @@ -75,9 +71,7 @@ insert into ctas_base values (1, 2); create table ctas_nodata (ii, jj, kk) as select i, j from ctas_base; -create table ctas_nodata (ii, -jj, -kk) +create table ctas_nodata (ii, jj, kk) as select i, j from ctas_base with no data; @@ -110,27 +104,25 @@ drop table ctas_nodata_4; create function make_table() returns void language sql -as $function$ -CREATE TABLE created_table AS SELECT * FROM int8_tbl; -$function$; +as $$ + CREATE TABLE created_table AS SELECT * FROM int8_tbl; +$$; select make_table(); select * from created_table; -do -$do$ +do $$ BEGIN EXECUTE 'EXPLAIN ANALYZE SELECT * INTO TABLE easi FROM int8_tbl'; EXECUTE 'EXPLAIN ANALYZE CREATE TABLE easi2 AS SELECT * FROM int8_tbl WITH NO DATA'; -END -$do$; +END$$; drop table created_table; drop table easi, easi2; -declare "foo" cursor for select 1 into int4_tbl;; +declare foo cursor for select 1 into int4_tbl;; copy (select 1 into frak union select 2) to 'blob'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_parallel_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_parallel_100.snap index 3ea48dc9a..15c873908 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_parallel_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_parallel_100.snap @@ -5,10 +5,8 @@ input_file: crates/pgls_pretty_print/tests/data/multi/select_parallel.sql select pg_stat_force_next_flush(); select - parallel_workers_to_launch - as parallel_workers_to_launch_before, - parallel_workers_launched - as parallel_workers_launched_before + parallel_workers_to_launch as parallel_workers_to_launch_before, + parallel_workers_launched as parallel_workers_launched_before from pg_stat_database where @@ -17,10 +15,8 @@ where create function sp_parallel_restricted(int) returns int language plpgsql -parallel RESTRICTED -as $function$ -begin return $1; end -$function$; +parallel restricted +as $$begin return $1; end$$; begin; @@ -32,9 +28,9 @@ set min_parallel_table_scan_size = 0; set max_parallel_workers_per_gather = 4; -select round(AVG(aa)), SUM(aa) from a_star; +select round(avg(aa)), sum(aa) from a_star; -select round(AVG(aa)), SUM(aa) from a_star as a1; +select round(avg(aa)), sum(aa) from a_star as a1; alter table c_star set (parallel_workers = 0); @@ -42,9 +38,9 @@ alter table c_star alter table d_star set (parallel_workers = 0); -select round(AVG(aa)), SUM(aa) from a_star; +select round(avg(aa)), sum(aa) from a_star; -select round(AVG(aa)), SUM(aa) from a_star as a2; +select round(avg(aa)), sum(aa) from a_star as a2; alter table a_star set (parallel_workers = 0); @@ -58,9 +54,9 @@ alter table e_star alter table f_star set (parallel_workers = 0); -select round(AVG(aa)), SUM(aa) from a_star; +select round(avg(aa)), sum(aa) from a_star; -select round(AVG(aa)), SUM(aa) from a_star as a3; +select round(avg(aa)), sum(aa) from a_star as a3; alter table a_star reset (parallel_workers); @@ -82,9 +78,9 @@ alter table f_star set enable_parallel_append = off; -select round(AVG(aa)), SUM(aa) from a_star; +select round(avg(aa)), sum(aa) from a_star; -select round(AVG(aa)), SUM(aa) from a_star as a4; +select round(avg(aa)), sum(aa) from a_star as a4; reset enable_parallel_append; @@ -92,9 +88,7 @@ create function sp_test_func() returns setof text language sql stable -as $function$ -select 'foo'::varchar union all select 'bar'::varchar -$function$; +as $$ select 'foo'::varchar union all select 'bar'::varchar $$; select sp_test_func() order by 1; @@ -109,19 +103,7 @@ create table part_pa_test_p1 partition of part_pa_test for values from (minvalue create table part_pa_test_p2 partition of part_pa_test for values from (0) to (maxvalue); select - ( - select - MAX( - ( - select - pa1.b - from - part_pa_test as pa1 - where - pa1.a = pa2.a - ) - ) - ) + (select max((select pa1.b from part_pa_test as pa1 where pa1.a = pa2.a))) from part_pa_test as pa2; @@ -129,15 +111,15 @@ drop table part_pa_test; set parallel_leader_participation = off; -select COUNT(*) from tenk1 where stringu1 = 'GRAAAA'; +select count(*) from tenk1 where stringu1 = 'GRAAAA'; -select COUNT(*) from tenk1 where stringu1 = 'GRAAAA'; +select count(*) from tenk1 where stringu1 = 'GRAAAA'; set max_parallel_workers = 0; -select COUNT(*) from tenk1 where stringu1 = 'GRAAAA'; +select count(*) from tenk1 where stringu1 = 'GRAAAA'; -select COUNT(*) from tenk1 where stringu1 = 'GRAAAA'; +select count(*) from tenk1 where stringu1 = 'GRAAAA'; reset max_parallel_workers; @@ -152,13 +134,13 @@ select length(stringu1) from tenk1 group by length(stringu1); select length(stringu1) from tenk1 group by length(stringu1); -select stringu1, COUNT(*) from tenk1 group by stringu1 order by stringu1; +select stringu1, count(*) from tenk1 group by stringu1 order by stringu1; -select SUM(sp_parallel_restricted(unique1)) from tenk1 group by sp_parallel_restricted(unique1); +select sum(sp_parallel_restricted(unique1)) from tenk1 group by sp_parallel_restricted(unique1); -prepare tenk1_count (int) as select COUNT(unique1) from tenk1 where hundred > $1;; +prepare tenk1_count (int) as select count(unique1) from tenk1 where hundred > $1;; -explain (COSTS 'off') execute tenk1_count (1); +explain (costs 'off') execute tenk1_count (1); execute tenk1_count (1); @@ -168,36 +150,18 @@ alter table tenk2 set (parallel_workers = 0); select - COUNT(*) + count(*) from tenk1 where - not (two, four) in - ( - select - hundred, - thousand - from - tenk2 - where - thousand > 100 - ); + not (two, four) in (select hundred, thousand from tenk2 where thousand > 100); select - COUNT(*) + count(*) from tenk1 where - not (two, four) in - ( - select - hundred, - thousand - from - tenk2 - where - thousand > 100 - ); + not (two, four) in (select hundred, thousand from tenk2 where thousand > 100); select * from tenk1 where not cast(unique1 + random() as int) in (select ten from tenk2); @@ -213,9 +177,9 @@ set enable_bitmapscan = off; alter table tenk2 set (parallel_workers = 2); -select COUNT(*) from tenk1 where tenk1.unique1 = (select MAX(tenk2.unique1) from tenk2); +select count(*) from tenk1 where tenk1.unique1 = (select max(tenk2.unique1) from tenk2); -select COUNT(*) from tenk1 where tenk1.unique1 = (select MAX(tenk2.unique1) from tenk2); +select count(*) from tenk1 where tenk1.unique1 = (select max(tenk2.unique1) from tenk2); reset enable_indexscan; @@ -232,54 +196,34 @@ set enable_bitmapscan = off; set random_page_cost = 2; -select COUNT(unique1) from tenk1 where hundred > 1; +select count(unique1) from tenk1 where hundred > 1; -select COUNT(unique1) from tenk1 where hundred > 1; +select count(unique1) from tenk1 where hundred > 1; select - COUNT(unique1) + count(unique1) from tenk1 where - hundred = any (cast(( - select - array_agg(i) - from - generate_series(1, 100, 15) as i - ) - as int[])); + hundred = any (cast((select array_agg(i) from generate_series(1, 100, 15) as i) as int[])); select - COUNT(unique1) + count(unique1) from tenk1 where - hundred = any (cast(( - select - array_agg(i) - from - generate_series(1, 100, 15) as i - ) - as int[])); + hundred = any (cast((select array_agg(i) from generate_series(1, 100, 15) as i) as int[])); -select COUNT(*) from tenk1 where thousand > 95; +select count(*) from tenk1 where thousand > 95; -select COUNT(*) from tenk1 where thousand > 95; +select count(*) from tenk1 where thousand > 95; set enable_material = 'false'; select * from - ( - select - COUNT(unique1) - from - tenk1 - where - hundred > 10 - ) - as ss + (select count(unique1) from tenk1 where hundred > 10) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -287,15 +231,7 @@ from select * from - ( - select - COUNT(unique1) - from - tenk1 - where - hundred > 10 - ) - as ss + (select count(unique1) from tenk1 where hundred > 10) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -303,10 +239,7 @@ from select * from - ( - select COUNT(*) from tenk1 where thousand > 99 - ) - as ss + (select count(*) from tenk1 where thousand > 99) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -314,10 +247,7 @@ from select * from - ( - select COUNT(*) from tenk1 where thousand > 99 - ) - as ss + (select count(*) from tenk1 where thousand > 99) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -335,37 +265,21 @@ alter table tenk2 set (parallel_workers = 1); select - COUNT(*) + count(*) from tenk1 left outer join - ( - select - tenk2.unique1 - from - tenk2 - order by 1 - limit 1000 - ) - as ss + (select tenk2.unique1 from tenk2 order by 1 limit 1000) as ss on tenk1.unique1 < ss.unique1 + 1 where tenk1.unique1 < 2; select - COUNT(*) + count(*) from tenk1 left outer join - ( - select - tenk2.unique1 - from - tenk2 - order by 1 - limit 1000 - ) - as ss + (select tenk2.unique1 from tenk2 order by 1 limit 1000) as ss on tenk1.unique1 < ss.unique1 + 1 where tenk1.unique1 < 2; @@ -394,19 +308,17 @@ set enable_mergejoin = off; set enable_material = off; -do -$do$ +do $$ BEGIN SET effective_io_concurrency = 50; EXCEPTION WHEN invalid_parameter_value THEN -END -$do$; +END $$; set work_mem = '64kB'; -select COUNT(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand = 0; +select count(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand = 0; -select COUNT(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand = 0; +select count(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand = 0; create table bmscantest ( a int, @@ -420,16 +332,16 @@ select from generate_series(1, 100000) as r; -create index "i_bmtest" on bmscantest using btree (a); +create index i_bmtest on bmscantest using btree (a); -select COUNT(*) from bmscantest where a > 1; +select count(*) from bmscantest where a > 1; reset enable_seqscan; alter table tenk2 set (parallel_workers = 0); -select COUNT(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand = 0; +select count(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand = 0; alter table tenk2 reset (parallel_workers); @@ -439,7 +351,7 @@ reset work_mem; create function explain_parallel_sort_stats() returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin for ln in @@ -452,7 +364,7 @@ begin return next ln; end loop; end; -$function$; +$$; select * from explain_parallel_sort_stats(); @@ -474,9 +386,9 @@ set enable_hashjoin = off; set enable_nestloop = off; -select COUNT(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1; +select count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1; -select COUNT(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1; +select count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1; reset enable_hashjoin; @@ -492,15 +404,7 @@ select from tenk1 as t1 left outer join - lateral ( - select - t1.unique1 as x, - * - from - tenk2 as t2 - order by 1 - ) - as t2 + lateral (select t1.unique1 as x, * from tenk2 as t2 order by 1) as t2 on true where t1.two > t2.two; @@ -510,33 +414,33 @@ alter table tenk2 set enable_hashagg = 'false'; -select COUNT(*) from tenk1 group by twenty; +select count(*) from tenk1 group by twenty; -select COUNT(*) from tenk1 group by twenty; +select count(*) from tenk1 group by twenty; create function sp_simple_func(var1 int) returns int language plpgsql -parallel SAFE -as $function$ +parallel safe +as $$ begin return var1 + 10; end; -$function$; +$$; select ten, sp_simple_func(ten) from tenk1 where ten < 100 order by ten; drop function sp_simple_func(int); -select COUNT(*), generate_series(1, 2) from tenk1 group by twenty; +select count(*), generate_series(1, 2) from tenk1 group by twenty; -select COUNT(*), generate_series(1, 2) from tenk1 group by twenty; +select count(*), generate_series(1, 2) from tenk1 group by twenty; set parallel_leader_participation = off; -select COUNT(*) from tenk1 group by twenty; +select count(*) from tenk1 group by twenty; -select COUNT(*) from tenk1 group by twenty; +select count(*) from tenk1 group by twenty; reset parallel_leader_participation; @@ -545,16 +449,7 @@ set enable_material = 'false'; select * from - ( - select - string4, - COUNT(unique2) - from - tenk1 - group by string4 - order by string4 - ) - as ss + (select string4, count(unique2) from tenk1 group by string4 order by string4) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -562,16 +457,7 @@ from select * from - ( - select - string4, - COUNT(unique2) - from - tenk1 - group by string4 - order by string4 - ) - as ss + (select string4, count(unique2) from tenk1 group by string4 order by string4) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -580,9 +466,9 @@ reset enable_material; reset enable_hashagg; -select AVG(cast(unique1 as bigint)) from tenk1; +select avg(cast(unique1 as int8)) from tenk1; -select AVG(cast(unique1 as bigint)) from tenk1; +select avg(cast(unique1 as int8)) from tenk1; select fivethous from tenk1 order by fivethous limit 4; @@ -608,10 +494,8 @@ create function parallel_safe_volatile(a int) returns int language plpgsql volatile -parallel SAFE -as $function$ -begin return a; end; -$function$; +parallel safe +as $$ begin return a; end; $$; select * from tenk1 where four = 2 order by four, hundred, parallel_safe_volatile(thousand); @@ -625,7 +509,7 @@ reset min_parallel_index_scan_size; reset enable_seqscan; -select COUNT(*) from tenk1 group by twenty, parallel_safe_volatile(two); +select count(*) from tenk1 group by twenty, parallel_safe_volatile(two); drop function parallel_safe_volatile(int); @@ -633,15 +517,15 @@ savepoint settings; set local debug_parallel_query = 1; -select cast(stringu1 as smallint) from tenk1 where unique1 = 1; +select cast(stringu1 as int2) from tenk1 where unique1 = 1; rollback to savepoint settings; create function make_record(n int) returns record language plpgsql -parallel SAFE -as $function$ +parallel safe +as $$ BEGIN RETURN CASE n WHEN 1 THEN ROW(1) @@ -651,7 +535,7 @@ BEGIN ELSE ROW(1, 2, 3, 4, 5) END; END; -$function$; +$$; savepoint settings; @@ -661,7 +545,7 @@ select make_record(x) from (select generate_series(1, 5) as x) as ss order by x; rollback to savepoint settings; -drop function make_record(int); +drop function make_record(n int); drop role if exists regress_parallel_worker; @@ -675,41 +559,25 @@ drop role regress_parallel_worker; set debug_parallel_query = 1; -select COUNT(*) from tenk1; +select count(*) from tenk1; reset debug_parallel_query; reset role; select - COUNT(*) + count(*) from tenk1 as a where - (unique1, two) in - ( - select - unique1, - ROW_NUMBER() over () - from - tenk1 as b - ); + (unique1, two) in (select unique1, row_number() over () from tenk1 as b); select * from tenk1 as a where - two in - ( - select - two - from - tenk1 as b - where - stringu1 like '%AAAA' - limit 3 - ); + two in (select two from tenk1 as b where stringu1 like '%AAAA' limit 3); savepoint settings; @@ -723,7 +591,7 @@ savepoint settings; set local debug_parallel_query = 1; -select cast(stringu1 || repeat('abcd', 5000) as smallint) from tenk1 where unique1 = 1; +select cast(stringu1 || repeat('abcd', 5000) as int2) from tenk1 where unique1 = 1; rollback to savepoint settings; @@ -731,53 +599,15 @@ savepoint settings; set local parallel_setup_cost = 10; -select - unique1 -from - tenk1 -where - fivethous = tenthous + 1 +select unique1 from tenk1 where fivethous = tenthous + 1 union all -select - unique1 -from - tenk1 -where - fivethous = tenthous + 1; +select unique1 from tenk1 where fivethous = tenthous + 1; rollback to savepoint settings; -select - unique1 -from - tenk1 -where - fivethous = - ( - select - unique1 - from - tenk1 - where - fivethous = 1 - limit 1 - ) +select unique1 from tenk1 where fivethous = (select unique1 from tenk1 where fivethous = 1 limit 1) union all -select - unique1 -from - tenk1 -where - fivethous = - ( - select - unique2 - from - tenk1 - where - fivethous = 1 - limit 1 - ) +select unique1 from tenk1 where fivethous = (select unique2 from tenk1 where fivethous = 1 limit 1) order by 1; select * from information_schema.foreign_data_wrapper_options order by 1, 2, 3; @@ -793,15 +623,13 @@ order by pathkey; create function make_some_array(int, int) returns int[] language plpgsql -parallel SAFE -as $function$ -declare x int[]; +parallel safe +as $$declare x int[]; begin x[1] := $1; x[2] := $2; return x; - end -$function$; + end$$; create table fooarr ( f1 text, @@ -813,7 +641,7 @@ insert into fooarr values ('1', array[1, 2], 'one'); prepare pstmt (text, int[]) as select * from fooarr where f1 = $1 and f2 = $2;; -explain (COSTS 'off') execute pstmt ('1', make_some_array(1, 2)); +explain (costs 'off') execute pstmt ('1', make_some_array(1, 2)); execute pstmt ('1', make_some_array(1, 2)); @@ -823,7 +651,7 @@ create view tenk1_vw_sec with (security_barrier) as select * from tenk1; -select 1 from tenk1_vw_sec where (select SUM(f1) from int4_tbl where f1 < unique1) < 100; +select 1 from tenk1_vw_sec where (select sum(f1) from int4_tbl where f1 < unique1) < 100; rollback; @@ -846,20 +674,16 @@ create role regress_parallel_worker; create function set_and_report_role() returns text language sql -parallel SAFE +parallel safe set role to regress_parallel_worker -as $function$ -select current_setting('role') -$function$; +as $$ select current_setting('role') $$; create function set_role_and_error(int) returns int language sql -parallel SAFE +parallel safe set role to regress_parallel_worker -as $function$ -select 1 / $1 -$function$; +as $$ select 1 / $1 $$; set debug_parallel_query = 0; @@ -883,32 +707,32 @@ drop role regress_parallel_worker; begin; -create function my_cmp(int, int) +create function my_cmp(int4, int4) returns int language sql -as $function$ -SELECT +as $$ + SELECT CASE WHEN $1 < $2 THEN -1 WHEN $1 > $2 THEN 1 ELSE 0 END; -$function$; +$$; -create table parallel_hang (i int); +create table parallel_hang (i int4); insert into parallel_hang select * from generate_series(1, 400) as gs; create operator class int4_custom_ops - for type int + for type int4 using btree - as operator 1 < (int, int), - operator 2 <= (int, int), - operator 3 = (int, int), - operator 4 >= (int, int), - operator 5 > (int, int), - function 1 my_cmp(int, int); + as operator 1 < (int4, int4), + operator 2 <= (int4, int4), + operator 3 = (int4, int4), + operator 4 >= (int4, int4), + operator 5 > (int4, int4), + function 1 my_cmp(int4, int4); -create unique index "parallel_hang_idx" on parallel_hang using btree (i int4_custom_ops); +create unique index parallel_hang_idx on parallel_hang using btree (i int4_custom_ops); set debug_parallel_query = 'on'; @@ -919,12 +743,8 @@ rollback; select pg_stat_force_next_flush(); select - parallel_workers_to_launch > - 'parallel_workers_to_launch_before' - as wrk_to_launch, - parallel_workers_launched > - 'parallel_workers_launched_before' - as wrk_launched + parallel_workers_to_launch > 'parallel_workers_to_launch_before' as wrk_to_launch, + parallel_workers_launched > 'parallel_workers_launched_before' as wrk_launched from pg_stat_database where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_parallel_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_parallel_80.snap index 3af5ec298..a85150fba 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_parallel_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_parallel_80.snap @@ -5,10 +5,8 @@ input_file: crates/pgls_pretty_print/tests/data/multi/select_parallel.sql select pg_stat_force_next_flush(); select - parallel_workers_to_launch - as parallel_workers_to_launch_before, - parallel_workers_launched - as parallel_workers_launched_before + parallel_workers_to_launch as parallel_workers_to_launch_before, + parallel_workers_launched as parallel_workers_launched_before from pg_stat_database where @@ -17,10 +15,8 @@ where create function sp_parallel_restricted(int) returns int language plpgsql -parallel RESTRICTED -as $function$ -begin return $1; end -$function$; +parallel restricted +as $$begin return $1; end$$; begin; @@ -32,9 +28,9 @@ set min_parallel_table_scan_size = 0; set max_parallel_workers_per_gather = 4; -select round(AVG(aa)), SUM(aa) from a_star; +select round(avg(aa)), sum(aa) from a_star; -select round(AVG(aa)), SUM(aa) from a_star as a1; +select round(avg(aa)), sum(aa) from a_star as a1; alter table c_star set (parallel_workers = 0); @@ -42,9 +38,9 @@ alter table c_star alter table d_star set (parallel_workers = 0); -select round(AVG(aa)), SUM(aa) from a_star; +select round(avg(aa)), sum(aa) from a_star; -select round(AVG(aa)), SUM(aa) from a_star as a2; +select round(avg(aa)), sum(aa) from a_star as a2; alter table a_star set (parallel_workers = 0); @@ -58,9 +54,9 @@ alter table e_star alter table f_star set (parallel_workers = 0); -select round(AVG(aa)), SUM(aa) from a_star; +select round(avg(aa)), sum(aa) from a_star; -select round(AVG(aa)), SUM(aa) from a_star as a3; +select round(avg(aa)), sum(aa) from a_star as a3; alter table a_star reset (parallel_workers); @@ -82,9 +78,9 @@ alter table f_star set enable_parallel_append = off; -select round(AVG(aa)), SUM(aa) from a_star; +select round(avg(aa)), sum(aa) from a_star; -select round(AVG(aa)), SUM(aa) from a_star as a4; +select round(avg(aa)), sum(aa) from a_star as a4; reset enable_parallel_append; @@ -92,9 +88,7 @@ create function sp_test_func() returns setof text language sql stable -as $function$ -select 'foo'::varchar union all select 'bar'::varchar -$function$; +as $$ select 'foo'::varchar union all select 'bar'::varchar $$; select sp_test_func() order by 1; @@ -113,19 +107,7 @@ partition of part_pa_test for values from (0) to (maxvalue); select - ( - select - MAX( - ( - select - pa1.b - from - part_pa_test as pa1 - where - pa1.a = pa2.a - ) - ) - ) + (select max((select pa1.b from part_pa_test as pa1 where pa1.a = pa2.a))) from part_pa_test as pa2; @@ -133,15 +115,15 @@ drop table part_pa_test; set parallel_leader_participation = off; -select COUNT(*) from tenk1 where stringu1 = 'GRAAAA'; +select count(*) from tenk1 where stringu1 = 'GRAAAA'; -select COUNT(*) from tenk1 where stringu1 = 'GRAAAA'; +select count(*) from tenk1 where stringu1 = 'GRAAAA'; set max_parallel_workers = 0; -select COUNT(*) from tenk1 where stringu1 = 'GRAAAA'; +select count(*) from tenk1 where stringu1 = 'GRAAAA'; -select COUNT(*) from tenk1 where stringu1 = 'GRAAAA'; +select count(*) from tenk1 where stringu1 = 'GRAAAA'; reset max_parallel_workers; @@ -162,24 +144,19 @@ select length(stringu1) from tenk1 group by length(stringu1); select length(stringu1) from tenk1 group by length(stringu1); -select stringu1, COUNT(*) from tenk1 group by stringu1 order by stringu1; +select stringu1, count(*) from tenk1 group by stringu1 order by stringu1; select - SUM(sp_parallel_restricted(unique1)) + sum(sp_parallel_restricted(unique1)) from tenk1 group by sp_parallel_restricted(unique1); prepare tenk1_count (int) -as select - COUNT(unique1) -from - tenk1 -where - hundred > $1;; +as select count(unique1) from tenk1 where hundred > $1;; -explain (COSTS 'off') execute tenk1_count (1); +explain (costs 'off') execute tenk1_count (1); execute tenk1_count (1); @@ -189,46 +166,25 @@ alter table tenk2 set (parallel_workers = 0); select - COUNT(*) + count(*) from tenk1 where - not (two, four) in - ( - select - hundred, - thousand - from - tenk2 - where - thousand > 100 - ); + not (two, four) in (select hundred, thousand from tenk2 where thousand > 100); select - COUNT(*) + count(*) from tenk1 where - not (two, four) in - ( - select - hundred, - thousand - from - tenk2 - where - thousand > 100 - ); + not (two, four) in (select hundred, thousand from tenk2 where thousand > 100); select * from tenk1 where - not cast(unique1 + random() as int) in - ( - select ten from tenk2 - ); + not cast(unique1 + random() as int) in (select ten from tenk2); alter table tenk2 reset (parallel_workers); @@ -243,20 +199,18 @@ alter table tenk2 set (parallel_workers = 2); select - COUNT(*) + count(*) from tenk1 where - tenk1.unique1 = - (select MAX(tenk2.unique1) from tenk2); + tenk1.unique1 = (select max(tenk2.unique1) from tenk2); select - COUNT(*) + count(*) from tenk1 where - tenk1.unique1 = - (select MAX(tenk2.unique1) from tenk2); + tenk1.unique1 = (select max(tenk2.unique1) from tenk2); reset enable_indexscan; @@ -273,54 +227,40 @@ set enable_bitmapscan = off; set random_page_cost = 2; -select COUNT(unique1) from tenk1 where hundred > 1; +select count(unique1) from tenk1 where hundred > 1; -select COUNT(unique1) from tenk1 where hundred > 1; +select count(unique1) from tenk1 where hundred > 1; select - COUNT(unique1) + count(unique1) from tenk1 where hundred = any (cast(( - select - array_agg(i) - from - generate_series(1, 100, 15) as i + select array_agg(i) from generate_series(1, 100, 15) as i ) as int[])); select - COUNT(unique1) + count(unique1) from tenk1 where hundred = any (cast(( - select - array_agg(i) - from - generate_series(1, 100, 15) as i + select array_agg(i) from generate_series(1, 100, 15) as i ) as int[])); -select COUNT(*) from tenk1 where thousand > 95; +select count(*) from tenk1 where thousand > 95; -select COUNT(*) from tenk1 where thousand > 95; +select count(*) from tenk1 where thousand > 95; set enable_material = 'false'; select * from - ( - select - COUNT(unique1) - from - tenk1 - where - hundred > 10 - ) - as ss + (select count(unique1) from tenk1 where hundred > 10) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -328,15 +268,7 @@ from select * from - ( - select - COUNT(unique1) - from - tenk1 - where - hundred > 10 - ) - as ss + (select count(unique1) from tenk1 where hundred > 10) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -344,15 +276,7 @@ from select * from - ( - select - COUNT(*) - from - tenk1 - where - thousand > 99 - ) - as ss + (select count(*) from tenk1 where thousand > 99) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -360,15 +284,7 @@ from select * from - ( - select - COUNT(*) - from - tenk1 - where - thousand > 99 - ) - as ss + (select count(*) from tenk1 where thousand > 99) as ss right outer join (values (1), (2), (3)) as v (x) on true; @@ -386,37 +302,21 @@ alter table tenk2 set (parallel_workers = 1); select - COUNT(*) + count(*) from tenk1 left outer join - ( - select - tenk2.unique1 - from - tenk2 - order by 1 - limit 1000 - ) - as ss + (select tenk2.unique1 from tenk2 order by 1 limit 1000) as ss on tenk1.unique1 < ss.unique1 + 1 where tenk1.unique1 < 2; select - COUNT(*) + count(*) from tenk1 left outer join - ( - select - tenk2.unique1 - from - tenk2 - order by 1 - limit 1000 - ) - as ss + (select tenk2.unique1 from tenk2 order by 1 limit 1000) as ss on tenk1.unique1 < ss.unique1 + 1 where tenk1.unique1 < 2; @@ -445,18 +345,16 @@ set enable_mergejoin = off; set enable_material = off; -do -$do$ +do $$ BEGIN SET effective_io_concurrency = 50; EXCEPTION WHEN invalid_parameter_value THEN -END -$do$; +END $$; set work_mem = '64kB'; select - COUNT(*) + count(*) from tenk1, tenk2 @@ -464,7 +362,7 @@ where tenk1.hundred > 1 and tenk2.thousand = 0; select - COUNT(*) + count(*) from tenk1, tenk2 @@ -483,9 +381,9 @@ select from generate_series(1, 100000) as r; -create index "i_bmtest" on bmscantest using btree (a); +create index i_bmtest on bmscantest using btree (a); -select COUNT(*) from bmscantest where a > 1; +select count(*) from bmscantest where a > 1; reset enable_seqscan; @@ -493,7 +391,7 @@ alter table tenk2 set (parallel_workers = 0); select - COUNT(*) + count(*) from tenk1, tenk2 @@ -508,7 +406,7 @@ reset work_mem; create function explain_parallel_sort_stats() returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin for ln in @@ -521,7 +419,7 @@ begin return next ln; end loop; end; -$function$; +$$; select * from explain_parallel_sort_stats(); @@ -543,9 +441,9 @@ set enable_hashjoin = off; set enable_nestloop = off; -select COUNT(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1; +select count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1; -select COUNT(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1; +select count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1; reset enable_hashjoin; @@ -561,15 +459,7 @@ select from tenk1 as t1 left outer join - lateral ( - select - t1.unique1 as x, - * - from - tenk2 as t2 - order by 1 - ) - as t2 + lateral (select t1.unique1 as x, * from tenk2 as t2 order by 1) as t2 on true where t1.two > t2.two; @@ -579,33 +469,33 @@ alter table tenk2 set enable_hashagg = 'false'; -select COUNT(*) from tenk1 group by twenty; +select count(*) from tenk1 group by twenty; -select COUNT(*) from tenk1 group by twenty; +select count(*) from tenk1 group by twenty; create function sp_simple_func(var1 int) returns int language plpgsql -parallel SAFE -as $function$ +parallel safe +as $$ begin return var1 + 10; end; -$function$; +$$; select ten, sp_simple_func(ten) from tenk1 where ten < 100 order by ten; drop function sp_simple_func(int); -select COUNT(*), generate_series(1, 2) from tenk1 group by twenty; +select count(*), generate_series(1, 2) from tenk1 group by twenty; -select COUNT(*), generate_series(1, 2) from tenk1 group by twenty; +select count(*), generate_series(1, 2) from tenk1 group by twenty; set parallel_leader_participation = off; -select COUNT(*) from tenk1 group by twenty; +select count(*) from tenk1 group by twenty; -select COUNT(*) from tenk1 group by twenty; +select count(*) from tenk1 group by twenty; reset parallel_leader_participation; @@ -615,13 +505,7 @@ select * from ( - select - string4, - COUNT(unique2) - from - tenk1 - group by string4 - order by string4 + select string4, count(unique2) from tenk1 group by string4 order by string4 ) as ss right outer join @@ -632,13 +516,7 @@ select * from ( - select - string4, - COUNT(unique2) - from - tenk1 - group by string4 - order by string4 + select string4, count(unique2) from tenk1 group by string4 order by string4 ) as ss right outer join @@ -649,9 +527,9 @@ reset enable_material; reset enable_hashagg; -select AVG(cast(unique1 as bigint)) from tenk1; +select avg(cast(unique1 as int8)) from tenk1; -select AVG(cast(unique1 as bigint)) from tenk1; +select avg(cast(unique1 as int8)) from tenk1; select fivethous from tenk1 order by fivethous limit 4; @@ -677,10 +555,8 @@ create function parallel_safe_volatile(a int) returns int language plpgsql volatile -parallel SAFE -as $function$ -begin return a; end; -$function$; +parallel safe +as $$ begin return a; end; $$; select * @@ -710,7 +586,7 @@ reset min_parallel_index_scan_size; reset enable_seqscan; -select COUNT(*) from tenk1 group by twenty, parallel_safe_volatile(two); +select count(*) from tenk1 group by twenty, parallel_safe_volatile(two); drop function parallel_safe_volatile(int); @@ -718,15 +594,15 @@ savepoint settings; set local debug_parallel_query = 1; -select cast(stringu1 as smallint) from tenk1 where unique1 = 1; +select cast(stringu1 as int2) from tenk1 where unique1 = 1; rollback to savepoint settings; create function make_record(n int) returns record language plpgsql -parallel SAFE -as $function$ +parallel safe +as $$ BEGIN RETURN CASE n WHEN 1 THEN ROW(1) @@ -736,7 +612,7 @@ BEGIN ELSE ROW(1, 2, 3, 4, 5) END; END; -$function$; +$$; savepoint settings; @@ -746,7 +622,7 @@ select make_record(x) from (select generate_series(1, 5) as x) as ss order by x; rollback to savepoint settings; -drop function make_record(int); +drop function make_record(n int); drop role if exists regress_parallel_worker; @@ -760,41 +636,25 @@ drop role regress_parallel_worker; set debug_parallel_query = 1; -select COUNT(*) from tenk1; +select count(*) from tenk1; reset debug_parallel_query; reset role; select - COUNT(*) + count(*) from tenk1 as a where - (unique1, two) in - ( - select - unique1, - ROW_NUMBER() over () - from - tenk1 as b - ); + (unique1, two) in (select unique1, row_number() over () from tenk1 as b); select * from tenk1 as a where - two in - ( - select - two - from - tenk1 as b - where - stringu1 like '%AAAA' - limit 3 - ); + two in (select two from tenk1 as b where stringu1 like '%AAAA' limit 3); savepoint settings; @@ -809,8 +669,7 @@ savepoint settings; set local debug_parallel_query = 1; select - cast(stringu1 || repeat('abcd', 5000) - as smallint) + cast(stringu1 || repeat('abcd', 5000) as int2) from tenk1 where @@ -822,19 +681,9 @@ savepoint settings; set local parallel_setup_cost = 10; -select - unique1 -from - tenk1 -where - fivethous = tenthous + 1 +select unique1 from tenk1 where fivethous = tenthous + 1 union all -select - unique1 -from - tenk1 -where - fivethous = tenthous + 1; +select unique1 from tenk1 where fivethous = tenthous + 1; rollback to savepoint settings; @@ -843,32 +692,14 @@ select from tenk1 where - fivethous = - ( - select - unique1 - from - tenk1 - where - fivethous = 1 - limit 1 - ) + fivethous = (select unique1 from tenk1 where fivethous = 1 limit 1) union all select unique1 from tenk1 where - fivethous = - ( - select - unique2 - from - tenk1 - where - fivethous = 1 - limit 1 - ) + fivethous = (select unique2 from tenk1 where fivethous = 1 limit 1) order by 1; select * from information_schema.foreign_data_wrapper_options order by 1, 2, 3; @@ -881,27 +712,21 @@ from order by tenthous; select - unnest(cast(array[] as int[])) + 1 - as pathkey + unnest(cast(array[] as int[])) + 1 as pathkey from - tenk1 as t1 - inner join - tenk1 as t2 - on true + tenk1 as t1 inner join tenk1 as t2 on true order by pathkey; create function make_some_array(int, int) returns int[] language plpgsql -parallel SAFE -as $function$ -declare x int[]; +parallel safe +as $$declare x int[]; begin x[1] := $1; x[2] := $2; return x; - end -$function$; + end$$; create table fooarr ( f1 text, @@ -913,7 +738,7 @@ insert into fooarr values ('1', array[1, 2], 'one'); prepare pstmt (text, int[]) as select * from fooarr where f1 = $1 and f2 = $2;; -explain (COSTS 'off') execute pstmt ('1', make_some_array(1, 2)); +explain (costs 'off') execute pstmt ('1', make_some_array(1, 2)); execute pstmt ('1', make_some_array(1, 2)); @@ -928,15 +753,7 @@ select from tenk1_vw_sec where - ( - select - SUM(f1) - from - int4_tbl - where - f1 < unique1 - ) < - 100; + (select sum(f1) from int4_tbl where f1 < unique1) < 100; rollback; @@ -959,20 +776,16 @@ create role regress_parallel_worker; create function set_and_report_role() returns text language sql -parallel SAFE +parallel safe set role to regress_parallel_worker -as $function$ -select current_setting('role') -$function$; +as $$ select current_setting('role') $$; create function set_role_and_error(int) returns int language sql -parallel SAFE +parallel safe set role to regress_parallel_worker -as $function$ -select 1 / $1 -$function$; +as $$ select 1 / $1 $$; set debug_parallel_query = 0; @@ -996,35 +809,32 @@ drop role regress_parallel_worker; begin; -create function my_cmp(int, int) +create function my_cmp(int4, int4) returns int language sql -as $function$ -SELECT +as $$ + SELECT CASE WHEN $1 < $2 THEN -1 WHEN $1 > $2 THEN 1 ELSE 0 END; -$function$; +$$; -create table parallel_hang (i int); +create table parallel_hang (i int4); insert into parallel_hang select * from generate_series(1, 400) as gs; create operator class int4_custom_ops - for type int + for type int4 using btree - as operator 1 < (int, int), - operator 2 <= (int, int), - operator 3 = (int, int), - operator 4 >= (int, int), - operator 5 > (int, int), - function 1 my_cmp(int, int); - -create unique index "parallel_hang_idx" -on parallel_hang -using btree -( + as operator 1 < (int4, int4), + operator 2 <= (int4, int4), + operator 3 = (int4, int4), + operator 4 >= (int4, int4), + operator 5 > (int4, int4), + function 1 my_cmp(int4, int4); + +create unique index parallel_hang_idx on parallel_hang using btree ( i int4_custom_ops ); @@ -1037,12 +847,9 @@ rollback; select pg_stat_force_next_flush(); select - parallel_workers_to_launch > - 'parallel_workers_to_launch_before' + parallel_workers_to_launch > 'parallel_workers_to_launch_before' as wrk_to_launch, - parallel_workers_launched > - 'parallel_workers_launched_before' - as wrk_launched + parallel_workers_launched > 'parallel_workers_launched_before' as wrk_launched from pg_stat_database where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_100.snap index 6a2436b7f..90d5db020 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_100.snap @@ -11,12 +11,10 @@ select * from toyemp where name = 'sharon'; create role regress_alice; create function f_leak(text) -returns boolean +returns bool language plpgsql cost 0.0000001 -as $function$ -BEGIN RAISE NOTICE 'f_leak => %', $1; RETURN true; END -$function$; +as 'BEGIN RAISE NOTICE ''f_leak => %'', $1; RETURN true; END'; create table customer ( cid int primary key, @@ -39,21 +37,9 @@ create table credit_usage ( insert into customer values - ( - 101, - 'regress_alice', - '+81-12-3456-7890', - 'passwd123' - ), - ( - 102, - 'regress_bob', - '+01-234-567-8901', - 'beafsteak' - ), - ( - 103, 'regress_eve', '+49-8765-43210', 'hamburger' - ); + (101, 'regress_alice', '+81-12-3456-7890', 'passwd123'), + (102, 'regress_bob', '+01-234-567-8901', 'beafsteak'), + (103, 'regress_eve', '+49-8765-43210', 'hamburger'); insert into credit_card values @@ -81,50 +67,30 @@ create view my_property_secure as select * from customer where name = current_user; create view my_credit_card_normal -as select - * -from - customer as l natural join credit_card as r -where - l.name = current_user; +as select * from customer as l natural join credit_card as r where l.name = current_user; create view my_credit_card_secure with (security_barrier) -as select - * -from - customer as l natural join credit_card as r -where - l.name = current_user; +as select * from customer as l natural join credit_card as r where l.name = current_user; create view my_credit_card_usage_normal -as select - * -from - my_credit_card_secure as l - natural join - credit_usage as r; +as select * from my_credit_card_secure as l natural join credit_usage as r; create view my_credit_card_usage_secure with (security_barrier) -as select - * -from - my_credit_card_secure as l - natural join - credit_usage as r; +as select * from my_credit_card_secure as l natural join credit_usage as r; -grant SELECT on table my_property_normal to public; +grant select on table my_property_normal to public; -grant SELECT on table my_property_secure to public; +grant select on table my_property_secure to public; -grant SELECT on table my_credit_card_normal to public; +grant select on table my_credit_card_normal to public; -grant SELECT on table my_credit_card_secure to public; +grant select on table my_credit_card_secure to public; -grant SELECT on table my_credit_card_usage_normal to public; +grant select on table my_credit_card_usage_normal to public; -grant SELECT on table my_credit_card_usage_secure to public; +grant select on table my_credit_card_usage_secure to public; set session authorization regress_alice; @@ -157,36 +123,28 @@ select from my_credit_card_usage_normal where - f_leak(cnum) and - ymd >= '2011-10-01' and - ymd < '2011-11-01'; + f_leak(cnum) and ymd >= '2011-10-01' and ymd < '2011-11-01'; select * from my_credit_card_usage_normal where - f_leak(cnum) and - ymd >= '2011-10-01' and - ymd < '2011-11-01'; + f_leak(cnum) and ymd >= '2011-10-01' and ymd < '2011-11-01'; select * from my_credit_card_usage_secure where - f_leak(cnum) and - ymd >= '2011-10-01' and - ymd < '2011-11-01'; + f_leak(cnum) and ymd >= '2011-10-01' and ymd < '2011-11-01'; select * from my_credit_card_usage_secure where - f_leak(cnum) and - ymd >= '2011-10-01' and - ymd < '2011-11-01'; + f_leak(cnum) and ymd >= '2011-10-01' and ymd < '2011-11-01'; prepare p1 as select * from my_property_normal where f_leak(passwd);; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_80.snap index d7f6670e4..46098575f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_80.snap @@ -11,12 +11,10 @@ select * from toyemp where name = 'sharon'; create role regress_alice; create function f_leak(text) -returns boolean +returns bool language plpgsql cost 0.0000001 -as $function$ -BEGIN RAISE NOTICE 'f_leak => %', $1; RETURN true; END -$function$; +as 'BEGIN RAISE NOTICE ''f_leak => %'', $1; RETURN true; END'; create table customer ( cid int primary key, @@ -39,24 +37,9 @@ create table credit_usage ( insert into customer values - ( - 101, - 'regress_alice', - '+81-12-3456-7890', - 'passwd123' - ), - ( - 102, - 'regress_bob', - '+01-234-567-8901', - 'beafsteak' - ), - ( - 103, - 'regress_eve', - '+49-8765-43210', - 'hamburger' - ); + (101, 'regress_alice', '+81-12-3456-7890', 'passwd123'), + (102, 'regress_bob', '+01-234-567-8901', 'beafsteak'), + (103, 'regress_eve', '+49-8765-43210', 'hamburger'); insert into credit_card values @@ -77,29 +60,17 @@ values (103, '2011-10-15', 480); create view my_property_normal -as select - * -from - customer -where - name = current_user; +as select * from customer where name = current_user; create view my_property_secure with (security_barrier) -as select - * -from - customer -where - name = current_user; +as select * from customer where name = current_user; create view my_credit_card_normal as select * from - customer as l - natural join - credit_card as r + customer as l natural join credit_card as r where l.name = current_user; @@ -108,40 +79,28 @@ create view my_credit_card_secure as select * from - customer as l - natural join - credit_card as r + customer as l natural join credit_card as r where l.name = current_user; create view my_credit_card_usage_normal -as select - * -from - my_credit_card_secure as l - natural join - credit_usage as r; +as select * from my_credit_card_secure as l natural join credit_usage as r; create view my_credit_card_usage_secure with (security_barrier) -as select - * -from - my_credit_card_secure as l - natural join - credit_usage as r; +as select * from my_credit_card_secure as l natural join credit_usage as r; -grant SELECT on table my_property_normal to public; +grant select on table my_property_normal to public; -grant SELECT on table my_property_secure to public; +grant select on table my_property_secure to public; -grant SELECT on table my_credit_card_normal to public; +grant select on table my_credit_card_normal to public; -grant SELECT on table my_credit_card_secure to public; +grant select on table my_credit_card_secure to public; -grant SELECT on table my_credit_card_usage_normal to public; +grant select on table my_credit_card_usage_normal to public; -grant SELECT on table my_credit_card_usage_secure to public; +grant select on table my_credit_card_usage_secure to public; set session authorization regress_alice; @@ -174,36 +133,28 @@ select from my_credit_card_usage_normal where - f_leak(cnum) and - ymd >= '2011-10-01' and - ymd < '2011-11-01'; + f_leak(cnum) and ymd >= '2011-10-01' and ymd < '2011-11-01'; select * from my_credit_card_usage_normal where - f_leak(cnum) and - ymd >= '2011-10-01' and - ymd < '2011-11-01'; + f_leak(cnum) and ymd >= '2011-10-01' and ymd < '2011-11-01'; select * from my_credit_card_usage_secure where - f_leak(cnum) and - ymd >= '2011-10-01' and - ymd < '2011-11-01'; + f_leak(cnum) and ymd >= '2011-10-01' and ymd < '2011-11-01'; select * from my_credit_card_usage_secure where - f_leak(cnum) and - ymd >= '2011-10-01' and - ymd < '2011-11-01'; + f_leak(cnum) and ymd >= '2011-10-01' and ymd < '2011-11-01'; prepare p1 as select * from my_property_normal where f_leak(passwd);; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sequence_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sequence_100.snap index 363e8ba37..e18105801 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sequence_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sequence_100.snap @@ -105,22 +105,8 @@ insert into serialtest2 (f1) values ('test_defaults'); insert into serialtest2 (f1, f2, f3, f4, f5, f6) values - ( - 'test_max_vals', - 2147483647, - 32767, - 32767, - 9223372036854775807, - 9223372036854775807 - ), - ( - 'test_min_vals', - -2147483648, - -32768, - -32768, - -9223372036854775808, - -9223372036854775808 - ); + ('test_max_vals', 2147483647, 32767, 32767, 9223372036854775807, 9223372036854775807), + ('test_min_vals', -2147483648, -32768, -32768, -9223372036854775808, -9223372036854775808); insert into serialtest2 (f1, f3) values ('bogus', -32769); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sequence_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sequence_80.snap index 45edd6df1..8862feaf2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sequence_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sequence_80.snap @@ -216,8 +216,7 @@ create temporary sequence myseq3; create temporary table t1 ( f1 serial, f2 int default nextval('myseq2'), - f3 int - default nextval(cast('myseq3' as text)) + f3 int default nextval(cast('myseq3' as text)) ); drop sequence t1_f1_seq; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__spgist_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__spgist_100.snap index 03e052d2a..e3ebb8e39 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__spgist_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__spgist_100.snap @@ -4,42 +4,24 @@ input_file: crates/pgls_pretty_print/tests/data/multi/spgist.sql snapshot_kind: text --- create table spgist_point_tbl ( - id int, + id int4, p point ); -create index "spgist_point_idx" -on spgist_point_tbl -using spgist -( - p -) -with (fillfactor = 75); +create index spgist_point_idx on spgist_point_tbl using spgist (p) with (fillfactor = 75); insert into spgist_point_tbl (id, p) -select - g, - point(g * 10, g * 10) -from - generate_series(1, 10) as g; +select g, point(g * 10, g * 10) from generate_series(1, 10) as g; delete from spgist_point_tbl where id < 5; vacuum spgist_point_tbl; insert into spgist_point_tbl (id, p) -select - g, - point(g * 10, g * 10) -from - generate_series(1, 10000) as g; +select g, point(g * 10, g * 10) from generate_series(1, 10000) as g; insert into spgist_point_tbl (id, p) -select - g + 100000, - point(g * 10 + 1, g * 10 + 1) -from - generate_series(1, 10000) as g; +select g + 100000, point(g * 10 + 1, g * 10 + 1) from generate_series(1, 10000) as g; delete from spgist_point_tbl where id % 2 = 1; @@ -60,71 +42,33 @@ from generate_series(1, 100, 5) as j, generate_series(1, 10) as s; -create index "spgist_box_idx" on spgist_box_tbl using spgist (b); +create index spgist_box_idx on spgist_box_tbl using spgist (b); select - COUNT(*) + count(*) from - ( - values - (point(5, 5)), - (point(8, 8)), - (point(12, 12)) - ) - as v (p) + (values (point(5, 5)), (point(8, 8)), (point(12, 12))) as v (p) where - exists - ( - select - * - from - spgist_box_tbl as b - where - b.b && box(v.p, v.p) - ); + exists (select * from spgist_box_tbl as b where b.b && box(v.p, v.p)); create table spgist_text_tbl ( - id int, + id int4, t text ); -create index "spgist_text_idx" on spgist_text_tbl using spgist (t); +create index spgist_text_idx on spgist_text_tbl using spgist (t); insert into spgist_text_tbl (id, t) -select - g, - 'f' || repeat('o', 100) || g -from - generate_series(1, 10000) as g +select g, 'f' || repeat('o', 100) || g from generate_series(1, 10000) as g union all -select - g, - 'baaaaaaaaaaaaaar' || g -from - generate_series(1, 1000) as g; +select g, 'baaaaaaaaaaaaaar' || g from generate_series(1, 1000) as g; insert into spgist_text_tbl (id, t) -select - -g, - 'f' || repeat('o', 100 - g) || 'surprise' -from - generate_series(1, 100) as g; - -create index "spgist_point_idx2" -on spgist_point_tbl -using spgist -( - p -) -with (fillfactor = 9); - -create index "spgist_point_idx2" -on spgist_point_tbl -using spgist -( - p -) -with (fillfactor = 101); +select -g, 'f' || repeat('o', 100 - g) || 'surprise' from generate_series(1, 100) as g; + +create index spgist_point_idx2 on spgist_point_tbl using spgist (p) with (fillfactor = 9); + +create index spgist_point_idx2 on spgist_point_tbl using spgist (p) with (fillfactor = 101); alter index spgist_point_idx set (fillfactor = 90); @@ -135,7 +79,7 @@ create domain spgist_text as varchar; create table spgist_domain_tbl (f1 spgist_text); -create index "spgist_domain_idx" on spgist_domain_tbl using spgist (f1); +create index spgist_domain_idx on spgist_domain_tbl using spgist (f1); insert into spgist_domain_tbl values ('fee'), ('fi'), ('fo'), ('fum'); @@ -148,11 +92,7 @@ create unlogged table spgist_unlogged_tbl ( b box ); -create index "spgist_unlogged_idx" on spgist_unlogged_tbl using spgist (b); +create index spgist_unlogged_idx on spgist_unlogged_tbl using spgist (b); insert into spgist_unlogged_tbl (b) -select - box(point(i, j)) -from - generate_series(1, 100, 5) as i, - generate_series(1, 10, 5) as j; +select box(point(i, j)) from generate_series(1, 100, 5) as i, generate_series(1, 10, 5) as j; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__spgist_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__spgist_80.snap index 5a8d11297..d2b2076cf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__spgist_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__spgist_80.snap @@ -4,35 +4,22 @@ input_file: crates/pgls_pretty_print/tests/data/multi/spgist.sql snapshot_kind: text --- create table spgist_point_tbl ( - id int, + id int4, p point ); -create index "spgist_point_idx" -on spgist_point_tbl -using spgist -( - p -) +create index spgist_point_idx on spgist_point_tbl using spgist (p) with (fillfactor = 75); insert into spgist_point_tbl (id, p) -select - g, - point(g * 10, g * 10) -from - generate_series(1, 10) as g; +select g, point(g * 10, g * 10) from generate_series(1, 10) as g; delete from spgist_point_tbl where id < 5; vacuum spgist_point_tbl; insert into spgist_point_tbl (id, p) -select - g, - point(g * 10, g * 10) -from - generate_series(1, 10000) as g; +select g, point(g * 10, g * 10) from generate_series(1, 10000) as g; insert into spgist_point_tbl (id, p) select @@ -60,71 +47,38 @@ from generate_series(1, 100, 5) as j, generate_series(1, 10) as s; -create index "spgist_box_idx" on spgist_box_tbl using spgist (b); +create index spgist_box_idx on spgist_box_tbl using spgist (b); select - COUNT(*) + count(*) from - ( - values - (point(5, 5)), - (point(8, 8)), - (point(12, 12)) - ) - as v (p) + (values (point(5, 5)), (point(8, 8)), (point(12, 12))) as v (p) where - exists - ( - select - * - from - spgist_box_tbl as b - where - b.b && box(v.p, v.p) - ); + exists (select * from spgist_box_tbl as b where b.b && box(v.p, v.p)); create table spgist_text_tbl ( - id int, + id int4, t text ); -create index "spgist_text_idx" on spgist_text_tbl using spgist (t); +create index spgist_text_idx on spgist_text_tbl using spgist (t); insert into spgist_text_tbl (id, t) -select - g, - 'f' || repeat('o', 100) || g -from - generate_series(1, 10000) as g +select g, 'f' || repeat('o', 100) || g from generate_series(1, 10000) as g union all -select - g, - 'baaaaaaaaaaaaaar' || g -from - generate_series(1, 1000) as g; +select g, 'baaaaaaaaaaaaaar' || g from generate_series(1, 1000) as g; insert into spgist_text_tbl (id, t) select -g, - 'f' || repeat('o', 100 - g) || - 'surprise' + 'f' || repeat('o', 100 - g) || 'surprise' from generate_series(1, 100) as g; -create index "spgist_point_idx2" -on spgist_point_tbl -using spgist -( - p -) +create index spgist_point_idx2 on spgist_point_tbl using spgist (p) with (fillfactor = 9); -create index "spgist_point_idx2" -on spgist_point_tbl -using spgist -( - p -) +create index spgist_point_idx2 on spgist_point_tbl using spgist (p) with (fillfactor = 101); alter index spgist_point_idx @@ -136,7 +90,7 @@ create domain spgist_text as varchar; create table spgist_domain_tbl (f1 spgist_text); -create index "spgist_domain_idx" on spgist_domain_tbl using spgist (f1); +create index spgist_domain_idx on spgist_domain_tbl using spgist (f1); insert into spgist_domain_tbl values ('fee'), ('fi'), ('fo'), ('fum'); @@ -149,7 +103,7 @@ create unlogged table spgist_unlogged_tbl ( b box ); -create index "spgist_unlogged_idx" on spgist_unlogged_tbl using spgist (b); +create index spgist_unlogged_idx on spgist_unlogged_tbl using spgist (b); insert into spgist_unlogged_tbl (b) select diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_100.snap index 8d329bf98..e88c5138a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_100.snap @@ -8,9 +8,9 @@ select json('{ "a" : 1 } '); select json('{ "a" : 1 } ' format json); -select json('{ "a" : 1 } ' format json encoding UTF8); +select json('{ "a" : 1 } ' format json encoding utf8); -select json(cast('{ "a" : 1 } ' as bytea) format json encoding UTF8); +select json(cast('{ "a" : 1 } ' as bytea) format json encoding utf8); select pg_typeof(json('{ "a" : 1 } ')); @@ -34,7 +34,7 @@ select json('123' format json); select json(cast('123' as bytea) format json); -select json(cast('123' as bytea) format json encoding UTF8); +select json(cast('123' as bytea) format json encoding utf8); select json('123' with unique keys); @@ -108,29 +108,29 @@ select json_object(returning text); select json_object(returning text format json); -select json_object(returning text format json encoding UTF8); +select json_object(returning text format json encoding utf8); select json_object(returning bytea); select json_object(returning bytea format json); -select json_object(returning bytea format json encoding UTF8); +select json_object(returning bytea format json encoding utf8); -select json_object(returning bytea format json encoding UTF16); +select json_object(returning bytea format json encoding utf16); -select json_object(returning bytea format json encoding UTF32); +select json_object(returning bytea format json encoding utf32); select json_object('foo' : cast(null as int) format json); -select json_object('foo' : cast(null as int) format json encoding UTF8); +select json_object('foo' : cast(null as int) format json encoding utf8); select json_object('foo' : cast(null as json) format json); -select json_object('foo' : cast(null as json) format json encoding UTF8); +select json_object('foo' : cast(null as json) format json encoding utf8); select json_object('foo' : cast(null as jsonb) format json); -select json_object('foo' : cast(null as jsonb) format json encoding UTF8); +select json_object('foo' : cast(null as jsonb) format json encoding utf8); select json_object(null : 1); @@ -222,9 +222,9 @@ create function mood_to_json(mood) returns json language sql immutable -as $function$ -SELECT to_json($1::text); -$function$; +as $$ + SELECT to_json($1::text); +$$; create cast (mood as json) with function mood_to_json(mood) as implicit; @@ -250,17 +250,17 @@ select json_array(returning text); select json_array(returning text format json); -select json_array(returning text format json encoding UTF8); +select json_array(returning text format json encoding utf8); select json_array(returning bytea); select json_array(returning bytea format json); -select json_array(returning bytea format json encoding UTF8); +select json_array(returning bytea format json encoding utf8); -select json_array(returning bytea format json encoding UTF16); +select json_array(returning bytea format json encoding utf16); -select json_array(returning bytea format json encoding UTF32); +select json_array(returning bytea format json encoding utf32); select json_array('aaa', @@ -287,13 +287,10 @@ select json_array(null, null, 'b' absent on null returning jsonb); select json_array(json_array('{ "a" : 123 }' absent on null returning text) absent on null); select - json_array(json_array('{ "a" : 123 }' format json - absent on null returning text) - absent on null); + json_array(json_array('{ "a" : 123 }' format json absent on null returning text) absent on null); select - json_array(json_array('{ "a" : 123 }' format json - absent on null returning text) format json + json_array(json_array('{ "a" : 123 }' format json absent on null returning text) format json absent on null); select json_array(select i from (values (1), (2), (null), (4)) as foo (i)); @@ -302,29 +299,14 @@ select json_array(select i from - ( - values - (cast(null as int[])), - ('{1,2}'), - (null), - (null), - ('{3,4}'), - (null) - ) - as foo (i)); + (values (cast(null as int[])), ('{1,2}'), (null), (null), ('{3,4}'), (null)) as foo (i)); select json_array(select i from ( - values - (cast(null as int[])), - ('{1,2}'), - (null), - (null), - ('{3,4}'), - (null) + values (cast(null as int[])), ('{1,2}'), (null), (null), ('{3,4}'), (null) ) as foo (i) returning jsonb); @@ -355,16 +337,13 @@ select json_arrayagg(i order by i desc absent on null) from generate_series(1, 5 select json_arrayagg(cast(cast(i as text) as json) absent on null) from generate_series(1, 5) as i; select - json_arrayagg(json_array(i, i + 1 absent on null returning text) format json - absent on null) + json_arrayagg(json_array(i, i + 1 absent on null returning text) format json absent on null) from generate_series(1, 5) as i; select json_arrayagg(null absent on null), - json_arrayagg(null - absent on null - returning jsonb) + json_arrayagg(null absent on null returning jsonb) from generate_series(1, 5); @@ -376,78 +355,28 @@ from select json_arrayagg(bar absent on null) as no_options, - json_arrayagg(bar absent on null returning jsonb) - as returning_jsonb, - json_arrayagg(bar absent on null) - as absent_on_null, - json_arrayagg(bar absent on null returning jsonb) - as absentonnull_returning_jsonb, + json_arrayagg(bar absent on null returning jsonb) as returning_jsonb, + json_arrayagg(bar absent on null) as absent_on_null, + json_arrayagg(bar absent on null returning jsonb) as absentonnull_returning_jsonb, json_arrayagg(bar null on null) as null_on_null, - json_arrayagg(bar null on null returning jsonb) - as nullonnull_returning_jsonb, - json_arrayagg(foo absent on null) - as row_no_options, - json_arrayagg(foo absent on null returning jsonb) - as row_returning_jsonb, - json_arrayagg(foo - order by bar - absent on null) - filter (where - bar > 2) - as row_filtered_agg, - json_arrayagg(foo - order by bar - absent on null - returning jsonb) - filter (where - bar > 2) + json_arrayagg(bar null on null returning jsonb) as nullonnull_returning_jsonb, + json_arrayagg(foo absent on null) as row_no_options, + json_arrayagg(foo absent on null returning jsonb) as row_returning_jsonb, + json_arrayagg(foo order by bar absent on null) filter (where bar > 2) as row_filtered_agg, + json_arrayagg(foo order by bar absent on null returning jsonb) filter (where bar > 2) as row_filtered_agg_returning_jsonb from - ( - values - (null), - (3), - (1), - (null), - (null), - (5), - (2), - (4), - (null) - ) - as foo (bar); + (values (null), (3), (1), (null), (null), (5), (2), (4), (null)) as foo (bar); select bar, - json_arrayagg(bar - absent on null) - filter (where - bar > 2) - over ( - partition by foo.bar % 2 - ) + json_arrayagg(bar absent on null) filter (where bar > 2) over (partition by foo.bar % 2) from - ( - values - (null), - (3), - (1), - (null), - (null), - (5), - (2), - (4), - (null), - (5), - (4) - ) - as foo (bar); + (values (null), (3), (1), (null), (null), (5), (2), (4), (null), (5), (4)) as foo (bar); select json_objectagg('key' : 1 null on null) is null, - json_objectagg('key' : 1 - null on null - returning jsonb) is null + json_objectagg('key' : 1 null on null returning jsonb) is null where false; @@ -457,9 +386,7 @@ select json_objectagg(null : 1 null on null returning jsonb); select json_objectagg(i : i null on null), - json_objectagg(i : i - null on null - returning jsonb) + json_objectagg(i : i null on null returning jsonb) from generate_series(1, 5) as i; @@ -467,139 +394,75 @@ select json_objectagg(k : v null on null), json_objectagg(k : v null on null), json_objectagg(k : v absent on null), - json_objectagg(k : v - null on null - returning jsonb), - json_objectagg(k : v - null on null - returning jsonb), - json_objectagg(k : v - absent on null - returning jsonb) + json_objectagg(k : v null on null returning jsonb), + json_objectagg(k : v null on null returning jsonb), + json_objectagg(k : v absent on null returning jsonb) from - ( - values (1, 1), (1, null), (2, null), (3, 3) - ) - as foo (k, v); + (values (1, 1), (1, null), (2, null), (3, 3)) as foo (k, v); select - json_objectagg(k : v - null on null - with unique keys) + json_objectagg(k : v null on null with unique keys) from (values (1, 1), (1, null), (2, 2)) as foo (k, v); select - json_objectagg(k : v - absent on null - with unique keys) + json_objectagg(k : v absent on null with unique keys) from (values (1, 1), (1, null), (2, 2)) as foo (k, v); select - json_objectagg(k : v - absent on null - with unique keys) + json_objectagg(k : v absent on null with unique keys) from - ( - values - (1, 1), - (0, null), - (3, null), - (2, 2), - (4, null) - ) - as foo (k, v); + (values (1, 1), (0, null), (3, null), (2, 2), (4, null)) as foo (k, v); select - json_objectagg(k : v - null on null - with unique keys - returning jsonb) + json_objectagg(k : v null on null with unique keys returning jsonb) from (values (1, 1), (1, null), (2, 2)) as foo (k, v); select - json_objectagg(k : v - absent on null - with unique keys - returning jsonb) + json_objectagg(k : v absent on null with unique keys returning jsonb) from (values (1, 1), (1, null), (2, 2)) as foo (k, v); select - json_objectagg(k : v - absent on null - with unique keys - returning jsonb) + json_objectagg(k : v absent on null with unique keys returning jsonb) from - ( - values - (1, 1), - (0, null), - (4, null), - (5, null), - (6, null), - (2, 2) - ) - as foo (k, v); + (values (1, 1), (0, null), (4, null), (5, null), (6, null), (2, 2)) as foo (k, v); select - json_objectagg(mod(i, 100) : cast(i as text) format json - null on null - with unique keys) + json_objectagg(mod(i, 100) : cast(i as text) format json null on null with unique keys) from generate_series(0, 199) as i; select json_object('foo' : '1' format json, 'bar' : 'baz' returning json); create view json_object_view -as select - json_object('foo' : '1' format json, - 'bar' : 'baz' returning json); +as select json_object('foo' : '1' format json, 'bar' : 'baz' returning json); drop view json_object_view; select to_json(a) as a, - json_objectagg(k : v - null on null - with unique keys) - over ( - order by k - ) + json_objectagg(k : v null on null with unique keys) over (order by k) from (values (1, 1), (2, 2)) as a (k, v); select to_json(a) as a, - json_objectagg(k : v - null on null - with unique keys) - over ( - order by k - ) + json_objectagg(k : v null on null with unique keys) over (order by k) from (values (1, 1), (1, 2), (2, 2)) as a (k, v); select to_json(a) as a, - json_objectagg(k : v - absent on null - with unique keys) - over ( - order by k - ) + json_objectagg(k : v absent on null with unique keys) over (order by k) from (values (1, 1), (1, null), (2, 2)) as a (k, v); select to_json(a) as a, - json_objectagg(k : v - absent on null) - over ( - order by k - ) + json_objectagg(k : v absent on null) over (order by k) from (values (1, 1), (1, null), (2, 2)) as a (k, v); @@ -620,10 +483,7 @@ from select json_array('1' format json, 2 absent on null returning json); create view json_array_view -as select - json_array('1' format json, - 2 - absent on null returning json); +as select json_array('1' format json, 2 absent on null returning json); drop view json_array_view; @@ -695,11 +555,7 @@ drop view json_arrayagg_view; select json_array(select i from (values (1), (2), (null), (4)) as foo (i) returning jsonb); create view json_array_subquery_view -as select - json_array(select - i - from - (values (1), (2), (null), (4)) as foo (i) returning jsonb); +as select json_array(select i from (values (1), (2), (null), (4)) as foo (i) returning jsonb); drop view json_array_subquery_view; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_80.snap index fbbeb12f5..50aba685e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_80.snap @@ -8,9 +8,9 @@ select json('{ "a" : 1 } '); select json('{ "a" : 1 } ' format json); -select json('{ "a" : 1 } ' format json encoding UTF8); +select json('{ "a" : 1 } ' format json encoding utf8); -select json(cast('{ "a" : 1 } ' as bytea) format json encoding UTF8); +select json(cast('{ "a" : 1 } ' as bytea) format json encoding utf8); select pg_typeof(json('{ "a" : 1 } ')); @@ -34,7 +34,7 @@ select json('123' format json); select json(cast('123' as bytea) format json); -select json(cast('123' as bytea) format json encoding UTF8); +select json(cast('123' as bytea) format json encoding utf8); select json('123' with unique keys); @@ -108,29 +108,29 @@ select json_object(returning text); select json_object(returning text format json); -select json_object(returning text format json encoding UTF8); +select json_object(returning text format json encoding utf8); select json_object(returning bytea); select json_object(returning bytea format json); -select json_object(returning bytea format json encoding UTF8); +select json_object(returning bytea format json encoding utf8); -select json_object(returning bytea format json encoding UTF16); +select json_object(returning bytea format json encoding utf16); -select json_object(returning bytea format json encoding UTF32); +select json_object(returning bytea format json encoding utf32); select json_object('foo' : cast(null as int) format json); -select json_object('foo' : cast(null as int) format json encoding UTF8); +select json_object('foo' : cast(null as int) format json encoding utf8); select json_object('foo' : cast(null as json) format json); -select json_object('foo' : cast(null as json) format json encoding UTF8); +select json_object('foo' : cast(null as json) format json encoding utf8); select json_object('foo' : cast(null as jsonb) format json); -select json_object('foo' : cast(null as jsonb) format json encoding UTF8); +select json_object('foo' : cast(null as jsonb) format json encoding utf8); select json_object(null : 1); @@ -170,8 +170,7 @@ select json_object('a' : '123', 'b' : json_object('a' : 111, 'b' : 'aaa')); select json_object('a' : '123', - 'b' : json_object('a' : 111, - 'b' : 'aaa' returning jsonb)); + 'b' : json_object('a' : 111, 'b' : 'aaa' returning jsonb)); select json_object('a' : json_object('b' : 1 returning text)); @@ -230,9 +229,9 @@ create function mood_to_json(mood) returns json language sql immutable -as $function$ -SELECT to_json($1::text); -$function$; +as $$ + SELECT to_json($1::text); +$$; create cast (mood as json) with function mood_to_json(mood) as implicit; @@ -258,17 +257,17 @@ select json_array(returning text); select json_array(returning text format json); -select json_array(returning text format json encoding UTF8); +select json_array(returning text format json encoding utf8); select json_array(returning bytea); select json_array(returning bytea format json); -select json_array(returning bytea format json encoding UTF8); +select json_array(returning bytea format json encoding utf8); -select json_array(returning bytea format json encoding UTF16); +select json_array(returning bytea format json encoding utf16); -select json_array(returning bytea format json encoding UTF32); +select json_array(returning bytea format json encoding utf32); select json_array('aaa', @@ -293,8 +292,7 @@ select json_array('a', null, 'b' absent on null returning jsonb); select json_array(null, null, 'b' absent on null returning jsonb); select - json_array(json_array('{ "a" : 123 }' - absent on null returning text) + json_array(json_array('{ "a" : 123 }' absent on null returning text) absent on null); select @@ -314,13 +312,7 @@ select i from ( - values - (cast(null as int[])), - ('{1,2}'), - (null), - (null), - ('{3,4}'), - (null) + values (cast(null as int[])), ('{1,2}'), (null), (null), ('{3,4}'), (null) ) as foo (i)); @@ -329,13 +321,7 @@ select i from ( - values - (cast(null as int[])), - ('{1,2}'), - (null), - (null), - ('{3,4}'), - (null) + values (cast(null as int[])), ('{1,2}'), (null), (null), ('{3,4}'), (null) ) as foo (i) returning jsonb); @@ -343,10 +329,7 @@ select json_array(select i from - ( - values (3), (1), (null), (2) - ) - as foo (i) + (values (3), (1), (null), (2)) as foo (i) order by i); select json_array(with x as (select 1) values (true)); @@ -359,87 +342,56 @@ select json_array(select * from (values (1, 2)) as foo (i, j)); select json_arrayagg(i absent on null) is null, - json_arrayagg(i - absent on null - returning jsonb) is null + json_arrayagg(i absent on null returning jsonb) is null from generate_series(1, 0) as i; select json_arrayagg(i absent on null), - json_arrayagg(i - absent on null - returning jsonb) + json_arrayagg(i absent on null returning jsonb) from generate_series(1, 5) as i; select - json_arrayagg(i - order by i desc - absent on null) + json_arrayagg(i order by i desc absent on null) from generate_series(1, 5) as i; select - json_arrayagg(cast(cast(i as text) as json) - absent on null) + json_arrayagg(cast(cast(i as text) as json) absent on null) from generate_series(1, 5) as i; select - json_arrayagg(json_array(i, - i + 1 - absent on null returning text) format json + json_arrayagg(json_array(i, i + 1 absent on null returning text) format json absent on null) from generate_series(1, 5) as i; select json_arrayagg(null absent on null), - json_arrayagg(null - absent on null - returning jsonb) + json_arrayagg(null absent on null returning jsonb) from generate_series(1, 5); select json_arrayagg(null null on null), - json_arrayagg(null - null on null - returning jsonb) + json_arrayagg(null null on null returning jsonb) from generate_series(1, 5); select - json_arrayagg(bar absent on null) - as no_options, - json_arrayagg(bar - absent on null - returning jsonb) - as returning_jsonb, - json_arrayagg(bar absent on null) - as absent_on_null, - json_arrayagg(bar - absent on null - returning jsonb) + json_arrayagg(bar absent on null) as no_options, + json_arrayagg(bar absent on null returning jsonb) as returning_jsonb, + json_arrayagg(bar absent on null) as absent_on_null, + json_arrayagg(bar absent on null returning jsonb) as absentonnull_returning_jsonb, - json_arrayagg(bar null on null) - as null_on_null, - json_arrayagg(bar - null on null - returning jsonb) + json_arrayagg(bar null on null) as null_on_null, + json_arrayagg(bar null on null returning jsonb) as nullonnull_returning_jsonb, - json_arrayagg(foo absent on null) - as row_no_options, - json_arrayagg(foo - absent on null - returning jsonb) - as row_returning_jsonb, - json_arrayagg(foo - order by bar - absent on null) - filter (where - bar > 2) + json_arrayagg(foo absent on null) as row_no_options, + json_arrayagg(foo absent on null returning jsonb) as row_returning_jsonb, + json_arrayagg(foo order by bar absent on null) filter (where bar > 2) as row_filtered_agg, json_arrayagg(foo order by bar @@ -449,19 +401,7 @@ select bar > 2) as row_filtered_agg_returning_jsonb from - ( - values - (null), - (3), - (1), - (null), - (null), - (5), - (2), - (4), - (null) - ) - as foo (bar); + (values (null), (3), (1), (null), (null), (5), (2), (4), (null)) as foo (bar); select bar, @@ -474,26 +414,13 @@ select ) from ( - values - (null), - (3), - (1), - (null), - (null), - (5), - (2), - (4), - (null), - (5), - (4) + values (null), (3), (1), (null), (null), (5), (2), (4), (null), (5), (4) ) as foo (bar); select json_objectagg('key' : 1 null on null) is null, - json_objectagg('key' : 1 - null on null - returning jsonb) is null + json_objectagg('key' : 1 null on null returning jsonb) is null where false; @@ -503,9 +430,7 @@ select json_objectagg(null : 1 null on null returning jsonb); select json_objectagg(i : i null on null), - json_objectagg(i : i - null on null - returning jsonb) + json_objectagg(i : i null on null returning jsonb) from generate_series(1, 5) as i; @@ -513,96 +438,42 @@ select json_objectagg(k : v null on null), json_objectagg(k : v null on null), json_objectagg(k : v absent on null), - json_objectagg(k : v - null on null - returning jsonb), - json_objectagg(k : v - null on null - returning jsonb), - json_objectagg(k : v - absent on null - returning jsonb) + json_objectagg(k : v null on null returning jsonb), + json_objectagg(k : v null on null returning jsonb), + json_objectagg(k : v absent on null returning jsonb) from - ( - values - (1, 1), - (1, null), - (2, null), - (3, 3) - ) - as foo (k, v); + (values (1, 1), (1, null), (2, null), (3, 3)) as foo (k, v); select - json_objectagg(k : v - null on null - with unique keys) + json_objectagg(k : v null on null with unique keys) from - ( - values (1, 1), (1, null), (2, 2) - ) - as foo (k, v); + (values (1, 1), (1, null), (2, 2)) as foo (k, v); select - json_objectagg(k : v - absent on null - with unique keys) + json_objectagg(k : v absent on null with unique keys) from - ( - values (1, 1), (1, null), (2, 2) - ) - as foo (k, v); + (values (1, 1), (1, null), (2, 2)) as foo (k, v); select - json_objectagg(k : v - absent on null - with unique keys) + json_objectagg(k : v absent on null with unique keys) from - ( - values - (1, 1), - (0, null), - (3, null), - (2, 2), - (4, null) - ) - as foo (k, v); + (values (1, 1), (0, null), (3, null), (2, 2), (4, null)) as foo (k, v); select - json_objectagg(k : v - null on null - with unique keys - returning jsonb) + json_objectagg(k : v null on null with unique keys returning jsonb) from - ( - values (1, 1), (1, null), (2, 2) - ) - as foo (k, v); + (values (1, 1), (1, null), (2, 2)) as foo (k, v); select - json_objectagg(k : v - absent on null - with unique keys - returning jsonb) + json_objectagg(k : v absent on null with unique keys returning jsonb) from - ( - values (1, 1), (1, null), (2, 2) - ) - as foo (k, v); + (values (1, 1), (1, null), (2, 2)) as foo (k, v); select - json_objectagg(k : v - absent on null - with unique keys - returning jsonb) + json_objectagg(k : v absent on null with unique keys returning jsonb) from ( - values - (1, 1), - (0, null), - (4, null), - (5, null), - (6, null), - (2, 2) + values (1, 1), (0, null), (4, null), (5, null), (6, null), (2, 2) ) as foo (k, v); @@ -616,63 +487,33 @@ from select json_object('foo' : '1' format json, 'bar' : 'baz' returning json); create view json_object_view -as select - json_object('foo' : '1' format json, - 'bar' : 'baz' returning json); +as select json_object('foo' : '1' format json, 'bar' : 'baz' returning json); drop view json_object_view; select to_json(a) as a, - json_objectagg(k : v - null on null - with unique keys) - over ( - order by k - ) + json_objectagg(k : v null on null with unique keys) over (order by k) from (values (1, 1), (2, 2)) as a (k, v); select to_json(a) as a, - json_objectagg(k : v - null on null - with unique keys) - over ( - order by k - ) + json_objectagg(k : v null on null with unique keys) over (order by k) from - ( - values (1, 1), (1, 2), (2, 2) - ) - as a (k, v); + (values (1, 1), (1, 2), (2, 2)) as a (k, v); select to_json(a) as a, - json_objectagg(k : v - absent on null - with unique keys) - over ( - order by k - ) + json_objectagg(k : v absent on null with unique keys) over (order by k) from - ( - values (1, 1), (1, null), (2, 2) - ) - as a (k, v); + (values (1, 1), (1, null), (2, 2)) as a (k, v); select to_json(a) as a, - json_objectagg(k : v - absent on null) - over ( - order by k - ) + json_objectagg(k : v absent on null) over (order by k) from - ( - values (1, 1), (1, null), (2, 2) - ) - as a (k, v); + (values (1, 1), (1, null), (2, 2)) as a (k, v); select to_json(a) as a, @@ -686,18 +527,12 @@ select unbounded following ) from - ( - values (1, 1), (1, null), (2, 2) - ) - as a (k, v); + (values (1, 1), (1, null), (2, 2)) as a (k, v); select json_array('1' format json, 2 absent on null returning json); create view json_array_view -as select - json_array('1' format json, - 2 - absent on null returning json); +as select json_array('1' format json, 2 absent on null returning json); drop view json_array_view; @@ -770,20 +605,14 @@ select json_array(select i from - ( - values (1), (2), (null), (4) - ) - as foo (i) returning jsonb); + (values (1), (2), (null), (4)) as foo (i) returning jsonb); create view json_array_subquery_view as select json_array(select i from - ( - values (1), (2), (null), (4) - ) - as foo (i) returning jsonb); + (values (1), (2), (null), (4)) as foo (i) returning jsonb); drop view json_array_subquery_view; @@ -820,12 +649,8 @@ values ('{}'), ('{ "a": 1, "b": null }'), ('{ "a": 1, "a": null }'), - ( - '{ "a": 1, "b": [{ "a": 1 }, { "a": 2 }] }' - ), - ( - '{ "a": 1, "b": [{ "a": 1, "b": 0, "a": 2 }] }' - ), + ('{ "a": 1, "b": [{ "a": 1 }, { "a": 2 }] }'), + ('{ "a": 1, "b": [{ "a": 1, "b": 0, "a": 2 }] }'), ('aaa'), ('{a:1}'), ('["a",]'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_jsontable_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_jsontable_100.snap index 81bf927f2..2ed6b6175 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_jsontable_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_jsontable_100.snap @@ -18,14 +18,7 @@ select * from json_table( cast(null as jsonb), '$' columns (v1 timestamp ) ) as select * from - json_table( - cast('"1.23"' as jsonb), - '$.a' - columns ( - js2 int path '$', - js2 int path '$' - ) - ); + json_table( cast('"1.23"' as jsonb), '$.a' columns (js2 int path '$', js2 int path '$' ) ); create type comp as (a int, b int); @@ -57,9 +50,7 @@ as ('1'), ('[]'), ('{}'), - ( - '[1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""]' - ); + ('[1, 1.23, "2", "aaaaaaa", "foo", null, false, true, {"aaa": 123}, "[1,2]", "\"str\""]'); select * @@ -367,26 +358,14 @@ select * from (values ('1'), ('"err"')) as vals (js), - json_table( - cast(vals.js as jsonb), - '$' - columns ( - a int path '$' - ) - ) as jt; + json_table( cast(vals.js as jsonb), '$' columns (a int path '$' ) ) as jt; select * from (values ('1'), ('"err"')) as vals (js) left outer join - json_table( - cast(vals.js as jsonb), - '$' - columns ( - a int path '$' error on error - ) - ) as jt + json_table( cast(vals.js as jsonb), '$' columns (a int path '$' error on error ) ) as jt on true; select @@ -394,25 +373,13 @@ select from (values ('1'), ('"err"')) as vals (js) left outer join - json_table( - cast(vals.js as jsonb), - '$' - columns ( - a int path '$' error on error - ) - ) as jt + json_table( cast(vals.js as jsonb), '$' columns (a int path '$' error on error ) ) as jt on true; select * from - json_table( - cast('1' as jsonb), - '$' - columns ( - a int path '$.a' error on empty - ) - ) as jt; + json_table( cast('1' as jsonb), '$' columns (a int path '$.a' error on empty ) ) as jt; select * @@ -474,24 +441,12 @@ from select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a int4 exists path '$.a' error on error - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a int4 exists path '$.a' error on error ) ); select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a int4 exists path '$' error on error - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a int4 exists path '$' error on error ) ); select * from json_table( cast('"a"' as jsonb), '$' columns (a int2 exists path '$.a' ) ); @@ -504,24 +459,12 @@ select * from json_table( cast('"a"' as jsonb), '$' columns (a char(3) exists pa select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a char(3) exists path '$.a' error on error - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a char(3) exists path '$.a' error on error ) ); select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a char(5) exists path '$.a' error on error - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a char(5) exists path '$.a' error on error ) ); select * from json_table( cast('"a"' as jsonb), '$' columns (a json exists path '$.a' ) ); @@ -533,63 +476,33 @@ create domain dint4_0 as int check (value <> 0); select a, - cast(a as boolean) + cast(a as bool) from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a dint4 exists path '$.a' - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a dint4 exists path '$.a' ) ); select a, - cast(a as boolean) + cast(a as bool) from - json_table( - cast('{"a":1}' as jsonb), - '$' - columns ( - a dint4_0 exists path '$.b' - ) - ); + json_table( cast('{"a":1}' as jsonb), '$' columns (a dint4_0 exists path '$.b' ) ); select a, - cast(a as boolean) + cast(a as bool) from - json_table( - cast('{"a":1}' as jsonb), - '$' - columns ( - a dint4_0 exists path '$.b' error on error - ) - ); + json_table( cast('{"a":1}' as jsonb), '$' columns (a dint4_0 exists path '$.b' error on error ) ); select a, - cast(a as boolean) + cast(a as bool) from - json_table( - cast('{"a":1}' as jsonb), - '$' - columns ( - a dint4_0 exists path '$.b' false on error - ) - ); + json_table( cast('{"a":1}' as jsonb), '$' columns (a dint4_0 exists path '$.b' false on error ) ); select a, - cast(a as boolean) + cast(a as bool) from - json_table( - cast('{"a":1}' as jsonb), - '$' - columns ( - a dint4_0 exists path '$.b' true on error - ) - ); + json_table( cast('{"a":1}' as jsonb), '$' columns (a dint4_0 exists path '$.b' true on error ) ); drop domain dint4, dint4_0; @@ -600,24 +513,12 @@ select * from json_table( cast('"world"' as jsonb), '$' columns (item text path select * from - json_table( - cast('"world"' as jsonb), - '$' - columns ( - item text format json path '$' keep quotes - ) - ); + json_table( cast('"world"' as jsonb), '$' columns (item text format json path '$' keep quotes ) ); select * from - json_table( - cast('"world"' as jsonb), - '$' - columns ( - item text format json path '$' omit quotes - ) - ); + json_table( cast('"world"' as jsonb), '$' columns (item text format json path '$' omit quotes ) ); select * @@ -754,25 +655,18 @@ from '$' columns ( nested path '$' as a columns (b int ), - nested path '$' - columns ( - nested path '$' as a columns (c int ) - ) + nested path '$' columns (nested path '$' as a columns (c int ) ) ) ) as jt; create temporary table jsonb_table_test (js jsonb); -insert into jsonb_table_test -values - ( - '[ +insert into jsonb_table_test values ('[ {"a": 1, "b": [], "c": []}, {"a": 2, "b": [1, 2, 3], "c": [10, null, 20]}, {"a": 3, "b": [1, 2], "c": []}, {"x": "4", "b": [1, 2], "c": 123} - ]' - ); + ]'); select jt.* @@ -784,16 +678,8 @@ from columns ( n for ordinality, a int path 'lax $.a' default -1 on empty, - nested path 'strict $.b[*]' as pb - columns ( - b_id for ordinality, - b int path '$' - ), - nested path 'strict $.c[*]' as pc - columns ( - c_id for ordinality, - c int path '$' - ) + nested path 'strict $.b[*]' as pb columns (b_id for ordinality, b int path '$' ), + nested path 'strict $.c[*]' as pc columns (c_id for ordinality, c int path '$' ) ) ) as jt; @@ -809,10 +695,7 @@ from y as y columns ( y text format json path '$', - nested path 'strict $[*] ? (@ == $y)' - columns ( - z int path '$' - ) + nested path 'strict $[*] ? (@ == $y)' columns (z int path '$' ) ) ) as jt; @@ -847,12 +730,8 @@ create table s (js jsonb); insert into s values - ( - '{"a":{"za":[{"z1": [11,2222]},{"z21": [22, 234,2345]},{"z22": [32, 204,145]}]},"c": 3}' - ), - ( - '{"a":{"za":[{"z1": [21,4222]},{"z21": [32, 134,1345]}]},"c": 10}' - ); + ('{"a":{"za":[{"z1": [11,2222]},{"z21": [22, 234,2345]},{"z22": [32, 204,145]}]},"c": 3}'), + ('{"a":{"za":[{"z1": [21,4222]},{"z21": [32, 134,1345]}]},"c": 10}'); select sub.* @@ -867,10 +746,7 @@ from xx int path '$.c', nested path '$.a.za[1]' columns ( - nested path '$.z21[*]' - columns ( - z21 int path '$?(@ >= $"x")' error on error - ) + nested path '$.z21[*]' columns (z21 int path '$?(@ >= $"x")' error on error ) ) ) ) as sub; @@ -887,32 +763,11 @@ from passing x as x, y as y columns ( - nested path '$.a.za[2]' - columns ( - nested path '$.z22[*]' as z22 - columns ( - c int path '$' - ) - ), - nested path '$.a.za[1]' - columns ( - d int[] path '$.z21' - ), - nested path '$.a.za[0]' - columns ( - nested path '$.z1[*]' as z1 - columns ( - a int path '$' - ) - ), + nested path '$.a.za[2]' columns (nested path '$.z22[*]' as z22 columns (c int path '$' ) ), + nested path '$.a.za[1]' columns (d int[] path '$.z21' ), + nested path '$.a.za[0]' columns (nested path '$.z1[*]' as z1 columns (a int path '$' ) ), xx1 int path '$.c', - nested path '$.a.za[1]' - columns ( - nested path '$.z21[*]' as z21 - columns ( - b int path '$' - ) - ), + nested path '$.a.za[1]' columns (nested path '$.z21[*]' as z21 columns (b int path '$' ) ), xx int path '$.c' ) ) as sub; @@ -932,17 +787,11 @@ from xx1 int path '$.c', nested path '$.a.za[0].z1[*]' columns ( - nested path '$ ?(@ >= ($"x" -2))' - columns ( - a int path '$' - ) + nested path '$ ?(@ >= ($"x" -2))' columns (a int path '$' ) ), nested path '$.a.za[0]' columns ( - nested path '$.z1[*] ? (@ >= ($"x" -2))' - columns ( - b int path '$' - ) + nested path '$.z1[*] ? (@ >= ($"x" -2))' columns (b int path '$' ) ) ) ) as sub; @@ -960,10 +809,7 @@ from y as y columns ( xx1 int path '$.c', - nested path '$.a.za[1]' - columns ( - nested path '$.z21[*]' columns (b int path '$' ) - ), + nested path '$.a.za[1]' columns (nested path '$.z21[*]' columns (b int path '$' ) ), nested path '$.a.za[1] ? (@.z21[*] >= ($"x"-1))' columns ( nested path '$.z21[*] ? (@ >= ($"y" + 3))' as z22 @@ -994,23 +840,11 @@ from y as y columns ( xx1 int path '$.c', - nested path '$.a.za[2]' - columns ( - nested path '$.z22[*]' as z22 - columns ( - c int path '$' - ) - ), - nested path '$.a.za[1]' - columns ( - d json path '$ ? (@.z21[*] == ($"x" -1))' - ), + nested path '$.a.za[2]' columns (nested path '$.z22[*]' as z22 columns (c int path '$' ) ), + nested path '$.a.za[1]' columns (d json path '$ ? (@.z21[*] == ($"x" -1))' ), nested path '$.a.za[0]' columns ( - nested path '$.z1[*] ? (@ >= ($"x" -2))' as z1 - columns ( - a int path '$' - ) + nested path '$.z1[*] ? (@ >= ($"x" -2))' as z1 columns (a int path '$' ) ), nested path '$.a.za[1]' columns ( @@ -1038,10 +872,7 @@ from xx1 int path '$.c', nested path '$.a.za[2]' columns ( - nested path '$.z22[*]' as z22 - columns ( - c int path '$' without wrapper omit quotes - ) + nested path '$.z22[*]' as z22 columns (c int path '$' without wrapper omit quotes ) ), nested path '$.a.za[1]' columns ( @@ -1049,10 +880,7 @@ from ), nested path '$.a.za[0]' columns ( - nested path '$.z1[*] ? (@ >= ($"x" -2))' as z1 - columns ( - a int path '$' keep quotes - ) + nested path '$.z1[*] ? (@ >= ($"x" -2))' as z1 columns (a int path '$' keep quotes ) ), nested path '$.a.za[1]' columns ( @@ -1077,56 +905,17 @@ select * from json_table( cast('1' as jsonb), '$' columns (a int omit quotes tru select * from json_table( cast('1' as jsonb), '$' columns (a int exists empty object on error ) ); create view json_table_view8 -as select - * -from - json_table( - '"a"', - '$' - columns ( - a text path '$' - ) - ); +as select * from json_table( '"a"', '$' columns (a text path '$' ) ); create view json_table_view9 -as select - * -from - json_table( - '"a"', - '$' - columns ( - a text path '$' - ) - error on error - ); +as select * from json_table( '"a"', '$' columns (a text path '$' ) error on error ); drop view json_table_view8, json_table_view9; create view json_table_view8 -as select - * -from - json_table( - '"a"', - '$' - columns ( - a text path '$' - ) - empty array on error - ); +as select * from json_table( '"a"', '$' columns (a text path '$' ) empty array on error ); create view json_table_view9 -as select - * -from - json_table( - '"a"', - '$' - columns ( - a text path '$' - ) - empty array on error - ); +as select * from json_table( '"a"', '$' columns (a text path '$' ) empty array on error ); drop view json_table_view8, json_table_view9; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_jsontable_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_jsontable_80.snap index 59efce391..f0b4ca731 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_jsontable_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_jsontable_80.snap @@ -18,14 +18,7 @@ from select * from - json_table( - '[]', - 'strict $.a' - columns ( - js2 int path '$' - ) - null on error - ); + json_table( '[]', 'strict $.a' columns (js2 int path '$' ) null on error ); select * @@ -42,14 +35,7 @@ from select * from - json_table( - '[]', - 'strict $.a' - columns ( - js2 int path '$' - ) - error on error - ); + json_table( '[]', 'strict $.a' columns (js2 int path '$' ) error on error ); select * @@ -65,13 +51,7 @@ from select * from - json_table( - cast(null as jsonb), - '$' - columns ( - v1 timestamp - ) - ) as f (v1, v2); + json_table( cast(null as jsonb), '$' columns (v1 timestamp ) ) as f (v1, v2); select * @@ -238,7 +218,8 @@ from cast('{"d1": "H"}' as jsonb), '$' columns ( - js1 jsonb_test_domain path '$.a2' default cast('foo' as jsonb_test_domain) on empty + js1 jsonb_test_domain path '$.a2' default cast('foo' + as jsonb_test_domain) on empty ) ); @@ -447,13 +428,7 @@ select * from (values ('1'), ('"err"')) as vals (js), - json_table( - cast(vals.js as jsonb), - '$' - columns ( - a int path '$' - ) - ) as jt; + json_table( cast(vals.js as jsonb), '$' columns (a int path '$' ) ) as jt; select * @@ -576,35 +551,17 @@ from select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a int2 exists path '$.a' - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a int2 exists path '$.a' ) ); select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a int8 exists path '$.a' - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a int8 exists path '$.a' ) ); select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a float4 exists path '$.a' - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a float4 exists path '$.a' ) ); select * @@ -642,24 +599,12 @@ from select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a json exists path '$.a' - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a json exists path '$.a' ) ); select * from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a jsonb exists path '$.a' - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a jsonb exists path '$.a' ) ); create domain dint4 as int; @@ -667,19 +612,13 @@ create domain dint4_0 as int check (value <> 0); select a, - cast(a as boolean) + cast(a as bool) from - json_table( - cast('"a"' as jsonb), - '$' - columns ( - a dint4 exists path '$.a' - ) - ); + json_table( cast('"a"' as jsonb), '$' columns (a dint4 exists path '$.a' ) ); select a, - cast(a as boolean) + cast(a as bool) from json_table( cast('{"a":1}' as jsonb), @@ -691,7 +630,7 @@ from select a, - cast(a as boolean) + cast(a as bool) from json_table( cast('{"a":1}' as jsonb), @@ -703,7 +642,7 @@ from select a, - cast(a as boolean) + cast(a as bool) from json_table( cast('{"a":1}' as jsonb), @@ -715,7 +654,7 @@ from select a, - cast(a as boolean) + cast(a as bool) from json_table( cast('{"a":1}' as jsonb), @@ -906,25 +845,18 @@ from '$' columns ( nested path '$' as a columns (b int ), - nested path '$' - columns ( - nested path '$' as a columns (c int ) - ) + nested path '$' columns (nested path '$' as a columns (c int ) ) ) ) as jt; create temporary table jsonb_table_test (js jsonb); -insert into jsonb_table_test -values - ( - '[ +insert into jsonb_table_test values ('[ {"a": 1, "b": [], "c": []}, {"a": 2, "b": [1, 2, 3], "c": [10, null, 20]}, {"a": 3, "b": [1, 2], "c": []}, {"x": "4", "b": [1, 2], "c": 123} - ]' - ); + ]'); select jt.* @@ -955,17 +887,13 @@ from generate_series(1, 3) as x, generate_series(1, 3) as y, json_table( - cast('[[1,2,3],[2,3,4,5],[3,4,5,6]]' - as jsonb), + cast('[[1,2,3],[2,3,4,5],[3,4,5,6]]' as jsonb), 'strict $[*] ? (@[*] <= $x)' passing x as x, y as y columns ( y text format json path '$', - nested path 'strict $[*] ? (@ == $y)' - columns ( - z int path '$' - ) + nested path 'strict $[*] ? (@ == $y)' columns (z int path '$' ) ) ) as jt; @@ -983,22 +911,13 @@ from nested path '$[1]' as p1 columns ( a1 int, - nested path '$[*]' as "p1 1" - columns ( - a11 text - ), + nested path '$[*]' as "p1 1" columns (a11 text ), b1 text ), nested path '$[2]' as p2 columns ( - nested path '$[*]' as "p2:1" - columns ( - a21 text - ), - nested path '$[*]' as p22 - columns ( - a22 text - ) + nested path '$[*]' as "p2:1" columns (a21 text ), + nested path '$[*]' as p22 columns (a22 text ) ) ) ); @@ -1012,9 +931,7 @@ values ( '{"a":{"za":[{"z1": [11,2222]},{"z21": [22, 234,2345]},{"z22": [32, 204,145]}]},"c": 3}' ), - ( - '{"a":{"za":[{"z1": [21,4222]},{"z21": [32, 134,1345]}]},"c": 10}' - ); + ('{"a":{"za":[{"z1": [21,4222]},{"z21": [32, 134,1345]}]},"c": 10}'); select sub.* @@ -1051,29 +968,17 @@ from columns ( nested path '$.a.za[2]' columns ( - nested path '$.z22[*]' as z22 - columns ( - c int path '$' - ) - ), - nested path '$.a.za[1]' - columns ( - d int[] path '$.z21' + nested path '$.z22[*]' as z22 columns (c int path '$' ) ), + nested path '$.a.za[1]' columns (d int[] path '$.z21' ), nested path '$.a.za[0]' columns ( - nested path '$.z1[*]' as z1 - columns ( - a int path '$' - ) + nested path '$.z1[*]' as z1 columns (a int path '$' ) ), xx1 int path '$.c', nested path '$.a.za[1]' columns ( - nested path '$.z21[*]' as z21 - columns ( - b int path '$' - ) + nested path '$.z21[*]' as z21 columns (b int path '$' ) ), xx int path '$.c' ) @@ -1094,17 +999,11 @@ from xx1 int path '$.c', nested path '$.a.za[0].z1[*]' columns ( - nested path '$ ?(@ >= ($"x" -2))' - columns ( - a int path '$' - ) + nested path '$ ?(@ >= ($"x" -2))' columns (a int path '$' ) ), nested path '$.a.za[0]' columns ( - nested path '$.z1[*] ? (@ >= ($"x" -2))' - columns ( - b int path '$' - ) + nested path '$.z1[*] ? (@ >= ($"x" -2))' columns (b int path '$' ) ) ) ) as sub; @@ -1124,10 +1023,7 @@ from xx1 int path '$.c', nested path '$.a.za[1]' columns ( - nested path '$.z21[*]' - columns ( - b int path '$' - ) + nested path '$.z21[*]' columns (b int path '$' ) ), nested path '$.a.za[1] ? (@.z21[*] >= ($"x"-1))' columns ( @@ -1161,10 +1057,7 @@ from xx1 int path '$.c', nested path '$.a.za[2]' columns ( - nested path '$.z22[*]' as z22 - columns ( - c int path '$' - ) + nested path '$.z22[*]' as z22 columns (c int path '$' ) ), nested path '$.a.za[1]' columns ( @@ -1172,10 +1065,7 @@ from ), nested path '$.a.za[0]' columns ( - nested path '$.z1[*] ? (@ >= ($"x" -2))' as z1 - columns ( - a int path '$' - ) + nested path '$.z1[*] ? (@ >= ($"x" -2))' as z1 columns (a int path '$' ) ), nested path '$.a.za[1]' columns ( @@ -1236,25 +1126,12 @@ drop table s; select * from - json_table( - cast('1' as jsonb), - '$' - columns ( - a int - ) - null on error - ); + json_table( cast('1' as jsonb), '$' columns (a int ) null on error ); select * from - json_table( - cast('1' as jsonb), - '$' - columns ( - a int true on empty - ) - ); + json_table( cast('1' as jsonb), '$' columns (a int true on empty ) ); select * @@ -1279,29 +1156,13 @@ from ); create view json_table_view8 -as select - * -from - json_table( - '"a"', - '$' - columns ( - a text path '$' - ) - ); +as select * from json_table( '"a"', '$' columns (a text path '$' ) ); create view json_table_view9 as select * from - json_table( - '"a"', - '$' - columns ( - a text path '$' - ) - error on error - ); + json_table( '"a"', '$' columns (a text path '$' ) error on error ); drop view json_table_view8, json_table_view9; @@ -1309,26 +1170,12 @@ create view json_table_view8 as select * from - json_table( - '"a"', - '$' - columns ( - a text path '$' - ) - empty array on error - ); + json_table( '"a"', '$' columns (a text path '$' ) empty array on error ); create view json_table_view9 as select * from - json_table( - '"a"', - '$' - columns ( - a text path '$' - ) - empty array on error - ); + json_table( '"a"', '$' columns (a text path '$' ) empty array on error ); drop view json_table_view8, json_table_view9; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_queryfuncs_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_queryfuncs_100.snap index dda1b7889..592c35dac 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_queryfuncs_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_queryfuncs_100.snap @@ -43,14 +43,10 @@ select json_exists(cast('{"a": 1, "b": 2}' as jsonb), '$.* ? (@ > $x)' passing 1 select json_exists(cast('{"a": 1, "b": 2}' as jsonb), '$.* ? (@ > $x)' passing '1' as x); select - json_exists(cast('{"a": 1, "b": 2}' as jsonb), '$.* ? (@ > $x && @ < $y)' - passing 0 as x, - 2 as y); + json_exists(cast('{"a": 1, "b": 2}' as jsonb), '$.* ? (@ > $x && @ < $y)' passing 0 as x, 2 as y); select - json_exists(cast('{"a": 1, "b": 2}' as jsonb), '$.* ? (@ > $x && @ < $y)' - passing 0 as x, - 1 as y); + json_exists(cast('{"a": 1, "b": 2}' as jsonb), '$.* ? (@ > $x && @ < $y)' passing 0 as x, 1 as y); select json_exists(cast('1' as jsonb), '$ > 2'); @@ -64,7 +60,7 @@ select json_value(cast('null' as jsonb), '$' returning int); select json_value(cast('true' as jsonb), '$'); -select json_value(cast('true' as jsonb), '$' returning boolean); +select json_value(cast('true' as jsonb), '$' returning bool); select json_value(cast('123' as jsonb), '$'); @@ -206,9 +202,7 @@ from select json_value(cast('null' as jsonb), '$a' passing cast(' (1, 2 )' as point) as a); select - json_value(cast('null' as jsonb), '$a' - passing cast(' (1, 2 )' as point) as a - returning point); + json_value(cast('null' as jsonb), '$a' passing cast(' (1, 2 )' as point) as a returning point); select json_value(cast('null' as jsonb), '$a' @@ -218,19 +212,16 @@ select select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts); + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts); select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts - returning timestamp with time zone); + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts + returning timestamptz); select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning timestamp); select @@ -245,9 +236,8 @@ select select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as time with time zone) as ts - returning time with time zone); + passing cast('2018-02-21 12:34:56 +10' as timetz) as ts + returning timetz); select json_value(cast('null' as jsonb), '$ts' @@ -256,14 +246,12 @@ select select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning json); select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning jsonb); select json_value('{"a": 1.234}', '$.a' returning int error on error); @@ -275,12 +263,9 @@ select json_value(cast(null as jsonb), '$'); select json_query(js, '$') as unspec, json_query(js, '$' without wrapper) as without, - json_query(js, '$' with conditional wrapper) - as "with cond", - json_query(js, '$' with unconditional wrapper) - as "with uncond", - json_query(js, '$' with unconditional wrapper) - as "with" + json_query(js, '$' with conditional wrapper) as "with cond", + json_query(js, '$' with unconditional wrapper) as "with uncond", + json_query(js, '$' with unconditional wrapper) as "with" from ( values @@ -295,17 +280,10 @@ from select json_query(js, 'strict $[*]') as unspec, - json_query(js, 'strict $[*]' without wrapper) - as without, - json_query(js, 'strict $[*]' - with conditional wrapper) - as "with cond", - json_query(js, 'strict $[*]' - with unconditional wrapper) - as "with uncond", - json_query(js, 'strict $[*]' - with unconditional wrapper) - as "with" + json_query(js, 'strict $[*]' without wrapper) as without, + json_query(js, 'strict $[*]' with conditional wrapper) as "with cond", + json_query(js, 'strict $[*]' with unconditional wrapper) as "with uncond", + json_query(js, 'strict $[*]' with unconditional wrapper) as "with" from ( values @@ -336,10 +314,7 @@ select json_query(cast('"aaa"' as jsonb), '$' omit quotes error on error); select json_query(cast('"aaa"' as jsonb), '$' returning json omit quotes error on error); select - json_query(cast('"aaa"' as jsonb), '$' - returning bytea format json - omit quotes - error on error); + json_query(cast('"aaa"' as jsonb), '$' returning bytea format json omit quotes error on error); select json_query(cast('"aaa"' as jsonb), '$' returning char(3) error on error); @@ -348,10 +323,7 @@ select json_query(cast('"aaa"' as jsonb), '$' returning char(3)); select json_query(cast('"aaa"' as jsonb), '$' returning char(3) omit quotes error on error); select - json_query(cast('"aaa"' as jsonb), '$.a' - returning char(2) - omit quotes - default 'bb' on empty); + json_query(cast('"aaa"' as jsonb), '$.a' returning char(2) omit quotes default 'bb' on empty); select json_query(cast('"aaa"' as jsonb), '$.a' @@ -452,9 +424,7 @@ select json_query(cast('[1,2]' as jsonb), '$' returning bytea format json); select json_query(cast('[1,2]' as jsonb), '$[*]' returning bytea empty object on error); select - json_query(cast('[1,2]' as jsonb), '$[*]' - returning bytea format json - empty object on error); + json_query(cast('[1,2]' as jsonb), '$[*]' returning bytea format json empty object on error); select json_query(cast('[1,2]' as jsonb), '$[*]' returning json empty object on error); @@ -464,27 +434,23 @@ select json_query(cast('[3,4]' as jsonb), '$[*]' returning bigint[] empty objec select json_query(cast('"[3,4]"' as jsonb), '$[*]' returning bigint[] empty object on error); -select json_query(cast('"123.1"' as jsonb), '$' returning smallint error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning int2 error on error); -select json_query(cast('"123.1"' as jsonb), '$' returning int error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning int4 error on error); -select json_query(cast('"123.1"' as jsonb), '$' returning bigint error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning int8 error on error); -select json_query(cast('"123.1"' as jsonb), '$' returning boolean error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning bool error on error); select json_query(cast('"123.1"' as jsonb), '$' returning numeric error on error); select json_query(cast('"123.1"' as jsonb), '$' returning real error on error); -select json_query(cast('"123.1"' as jsonb), '$' returning double precision error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning float8 error on error); -select json_query(cast('"123.1"' as jsonb), '$' returning smallint omit quotes error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning int2 omit quotes error on error); -select - json_query(cast('"123.1"' as jsonb), '$' - returning double precision - omit quotes - error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning float8 omit quotes error on error); select json_query(cast('[3,4]' as jsonb), '$[*]' returning anyarray empty object on error); @@ -545,8 +511,7 @@ select * from unnest( - (json_query(cast('{"jsa": [{"a": 1, "b": ["foo"]}, {"a": 2, "c": {}}, 123]}' - as jsonb), '$' + (json_query(cast('{"jsa": [{"a": 1, "b": ["foo"]}, {"a": 2, "c": {}}, 123]}' as jsonb), '$' returning sqljsonb_rec)).jsa ); @@ -571,9 +536,7 @@ select error on error); select - json_query(cast('[1,2,null,"3"]' as jsonb), '$[*]' - returning int[] - with unconditional wrapper); + json_query(cast('[1,2,null,"3"]' as jsonb), '$[*]' returning int[] with unconditional wrapper); select json_query(cast('[1,2,null,"a"]' as jsonb), '$[*]' @@ -582,16 +545,13 @@ select error on error); select - json_query(cast('[1,2,null,"a"]' as jsonb), '$[*]' - returning int[] - with unconditional wrapper); + json_query(cast('[1,2,null,"a"]' as jsonb), '$[*]' returning int[] with unconditional wrapper); select * from unnest( - json_query(cast('[{"a": 1, "t": ["foo", []]}, {"a": 2, "jb": [{}, true]}]' - as jsonb), '$' + json_query(cast('[{"a": 1, "t": ["foo", []]}, {"a": 2, "jb": [{}, true]}]' as jsonb), '$' returning sqljsonb_rec[]) ); @@ -607,46 +567,42 @@ select select json_query(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts); + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts); select json_query(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning json); select json_query(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning jsonb); create table test_jsonb_constraints ( js text, i int, x jsonb - default json_query(cast('[1,2]' as jsonb), '$[*]' - with unconditional wrapper) - constraint "test_jsonb_constraint1" check (js is json) - constraint "test_jsonb_constraint2" check (json_exists(cast(js as jsonb), '$.a' - passing i + 5 as int, - cast(i as text) as "TXT", - array[1, 2, 3] as arr)) - constraint "test_jsonb_constraint3" check (json_value(cast(js as jsonb), '$.a' - returning int - default '12' on empty - error on error) > - i) - constraint "test_jsonb_constraint4" check (json_query(cast(js as jsonb), '$.a' - with conditional wrapper - empty object on error) = - cast('[10]' as jsonb)) - constraint "test_jsonb_constraint5" check (json_query(cast(js as jsonb), '$.a' - returning char(5) - omit quotes - empty array on empty) > - 'a' collate "C") + default json_query(cast('[1,2]' as jsonb), '$[*]' with unconditional wrapper) + constraint test_jsonb_constraint1 check (js is json) + constraint test_jsonb_constraint2 check (json_exists(cast(js as jsonb), '$.a' + passing i + 5 as int, + cast(i as text) as "TXT", + array[1, 2, 3] as arr)) + constraint test_jsonb_constraint3 check (json_value(cast(js as jsonb), '$.a' + returning int + default '12' on empty + error on error) > + i) + constraint test_jsonb_constraint4 check (json_query(cast(js as jsonb), '$.a' + with conditional wrapper + empty object on error) = + cast('[10]' as jsonb)) + constraint test_jsonb_constraint5 check (json_query(cast(js as jsonb), '$.a' + returning char(5) + omit quotes + empty array on empty) > + 'a' collate "C") ); select @@ -662,8 +618,7 @@ select from pg_attrdef where - adrelid = - cast('test_jsonb_constraints' as regclass) + adrelid = cast('test_jsonb_constraints' as regclass) order by 1; insert into test_jsonb_constraints values ('', 1); @@ -699,10 +654,7 @@ create index on test_jsonb_mutability using btree ((json_query(js, '$.timestamp( create index on test_jsonb_mutability using btree ((json_query(js, '$.timestamp_tz()'))); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.date() < $.time_tz())')) ); @@ -710,89 +662,51 @@ create index on test_jsonb_mutability using btree ((json_query(js, '$.a ? (@.dat create index on test_jsonb_mutability using btree ((json_query(js, '$.a ? (@.time() < $.time())'))); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.time() < $.time_tz())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp() < $.timestamp_tz())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp_tz() < $.timestamp_tz())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.time() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.date() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp() < $.datetime("HH:MI"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp_tz() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp_tz() < $.datetime("HH:MI"))')) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.date() < $x' - passing cast('12:34' as time with time zone) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.date() < $x' passing cast('12:34' as timetz) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.date() < $x' - passing cast('1234' as int) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.date() < $x' passing cast('1234' as int) as x)) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp(2) < $.timestamp(3))')) ); @@ -800,139 +714,82 @@ create index on test_jsonb_mutability using btree ((json_query(js, '$.datetime() create index on test_jsonb_mutability using btree ((json_query(js, '$.a ? (@ < $.datetime())'))); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime() < $.datetime())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime("HH:MI TZH") < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime("HH:MI") < $.datetime("YY-MM-DD HH:MI"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime("HH:MI TZH") < $.datetime("YY-MM-DD HH:MI"))')) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.datetime("HH:MI TZH") < $x' - passing cast('12:34' as time with time zone) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.datetime("HH:MI TZH") < $x' passing cast('12:34' as timetz) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.datetime("HH:MI TZH") < $y' - passing cast('12:34' as time with time zone) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.datetime("HH:MI TZH") < $y' passing cast('12:34' as timetz) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.datetime() < $x' - passing cast('12:34' as time with time zone) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.datetime() < $x' passing cast('12:34' as timetz) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.datetime() < $x' - passing cast('1234' as int) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.datetime() < $x' passing cast('1234' as int) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.datetime() ? (@ == $x)' - passing cast('12:34' as time) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.datetime() ? (@ == $x)' passing cast('12:34' as time) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.datetime("YY-MM-DD") ? (@ == $x)' - passing cast('2020-07-14' as date) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.datetime("YY-MM-DD") ? (@ == $x)' passing cast('2020-07-14' as date) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$[1, $.a ? (@.datetime() == $x)]' - passing cast('12:34' as time) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$[1, $.a ? (@.datetime() == $x)]' passing cast('12:34' as time) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$[1, 0 to $.a ? (@.datetime() == $x)]' - passing cast('12:34' as time) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$[1, 0 to $.a ? (@.datetime() == $x)]' passing cast('12:34' as time) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$[1, $.a ? (@.datetime("HH:MI") == $x)]' - passing cast('12:34' as time) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$[1, $.a ? (@.datetime("HH:MI") == $x)]' passing cast('12:34' as time) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_value(js, '$' - default cast(random() as int) on error)) +create index on test_jsonb_mutability using btree ( + (json_value(js, '$' default cast(random() as int) on error)) ); create or replace function ret_setint() returns setof int language plpgsql immutable -as $function$ +as $$ BEGIN RETURN QUERY EXECUTE 'select 1 union all select 1'; END; -$function$; +$$; select json_query(js, '$' returning int default ret_setint() on error) from test_jsonb_mutability; select json_query(js, '$' returning int default b + 1 on error) from test_jsonb_mutability; select - json_query(js, '$' - returning int - default SUM(1) over () on error) + json_query(js, '$' returning int default sum(1) over () on error) from test_jsonb_mutability; @@ -972,9 +829,7 @@ select default cast((select '"1"') as queryfuncs_test_domain) on error); select - json_query('"a"', '$.a' - returning int - default cast(cast((select 1) as oid) as int) on error); + json_query('"a"', '$.a' returning int default cast(cast((select 1) as oid) as int) on error); select json_query('"a"', '$.a' @@ -994,8 +849,7 @@ inherits (someparent); select json_query('"a"', '$.a' returning someparent - default cast(cast((select '(1)') as somechild) - as someparent) on error); + default cast(cast((select '(1)') as somechild) as someparent) on error); drop domain queryfuncs_test_domain; @@ -1061,17 +915,13 @@ select json_value(cast('123' as jsonb), '$' returning queryfuncs_char2_chk defa drop domain queryfuncs_char2, queryfuncs_char2_chk; -create domain queryfuncs_d_varbit3 as bit varying(3) check (value <> '01'); +create domain queryfuncs_d_varbit3 as varbit(3) check (value <> '01'); select - json_value(cast('1234' as jsonb), '$' - returning queryfuncs_d_varbit3 - default '111111' on error); + json_value(cast('1234' as jsonb), '$' returning queryfuncs_d_varbit3 default '111111' on error); select - json_value(cast('1234' as jsonb), '$' - returning queryfuncs_d_varbit3 - default '010' on error); + json_value(cast('1234' as jsonb), '$' returning queryfuncs_d_varbit3 default '010' on error); select json_value(cast('1234' as jsonb), '$' returning queryfuncs_d_varbit3 default '01' on error); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_queryfuncs_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_queryfuncs_80.snap index e6620763f..fc6418851 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_queryfuncs_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sqljson_queryfuncs_80.snap @@ -68,7 +68,7 @@ select json_value(cast('null' as jsonb), '$' returning int); select json_value(cast('true' as jsonb), '$'); -select json_value(cast('true' as jsonb), '$' returning boolean); +select json_value(cast('true' as jsonb), '$' returning bool); select json_value(cast('123' as jsonb), '$'); @@ -93,16 +93,12 @@ select json_value(cast('"aaa"' as jsonb), '$' returning text); select json_value(cast('"aaa"' as jsonb), '$' returning char(5)); select - json_value(cast('"aaa"' as jsonb), '$' - returning char(2) - error on error); + json_value(cast('"aaa"' as jsonb), '$' returning char(2) error on error); select json_value(cast('"aaa"' as jsonb), '$' returning char(2)); select - json_value(cast('"aaa"' as jsonb), '$' - returning char(3) - error on error); + json_value(cast('"aaa"' as jsonb), '$' returning char(3) error on error); select json_value(cast('"aaa"' as jsonb), '$' returning json); @@ -121,9 +117,7 @@ select json_value(cast('"aaa"' as jsonb), '$' returning int); select json_value(cast('"aaa"' as jsonb), '$' returning int error on error); select - json_value(cast('"aaa"' as jsonb), '$' - returning int - default 111 on error); + json_value(cast('"aaa"' as jsonb), '$' returning int default 111 on error); select json_value(cast('"123"' as jsonb), '$' returning int) + 234; @@ -156,12 +150,14 @@ select default null on empty error on error); -create type rainbow as enum ('red', -'orange', -'yellow', -'green', -'blue', -'purple'); +create type rainbow as enum ( + 'red', + 'orange', + 'yellow', + 'green', + 'blue', + 'purple' +); create domain rgb as rainbow check (value in ('red', 'green', 'blue')); @@ -197,9 +193,7 @@ select json_value(cast('1' as jsonb), 'lax $.a' default 2 on error); select json_value(cast('1' as jsonb), 'lax $.a' default '2' on empty); select - json_value(cast('1' as jsonb), 'lax $.a' - null on empty - default '2' on error); + json_value(cast('1' as jsonb), 'lax $.a' null on empty default '2' on error); select json_value(cast('1' as jsonb), 'lax $.a' @@ -207,9 +201,7 @@ select default '3' on error); select - json_value(cast('1' as jsonb), 'lax $.a' - error on empty - default '3' on error); + json_value(cast('1' as jsonb), 'lax $.a' error on empty default '3' on error); select json_value(cast('[1,2]' as jsonb), '$[*]' error on error); @@ -259,19 +251,16 @@ select select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts); + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts); select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts - returning timestamp with time zone); + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts + returning timestamptz); select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning timestamp); select @@ -286,26 +275,22 @@ select select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as time with time zone) as ts - returning time with time zone); + passing cast('2018-02-21 12:34:56 +10' as timetz) as ts + returning timetz); select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamp) as ts returning timestamp); select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning json); select json_value(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning jsonb); select json_value('{"a": 1.234}', '$.a' returning int error on error); @@ -316,17 +301,10 @@ select json_value(cast(null as jsonb), '$'); select json_query(js, '$') as unspec, - json_query(js, '$' without wrapper) - as without, - json_query(js, '$' - with conditional wrapper) - as "with cond", - json_query(js, '$' - with unconditional wrapper) - as "with uncond", - json_query(js, '$' - with unconditional wrapper) - as "with" + json_query(js, '$' without wrapper) as without, + json_query(js, '$' with conditional wrapper) as "with cond", + json_query(js, '$' with unconditional wrapper) as "with uncond", + json_query(js, '$' with unconditional wrapper) as "with" from ( values @@ -341,18 +319,10 @@ from select json_query(js, 'strict $[*]') as unspec, - json_query(js, 'strict $[*]' - without wrapper) - as without, - json_query(js, 'strict $[*]' - with conditional wrapper) - as "with cond", - json_query(js, 'strict $[*]' - with unconditional wrapper) - as "with uncond", - json_query(js, 'strict $[*]' - with unconditional wrapper) - as "with" + json_query(js, 'strict $[*]' without wrapper) as without, + json_query(js, 'strict $[*]' with conditional wrapper) as "with cond", + json_query(js, 'strict $[*]' with unconditional wrapper) as "with uncond", + json_query(js, 'strict $[*]' with unconditional wrapper) as "with" from ( values @@ -393,9 +363,7 @@ select error on error); select - json_query(cast('"aaa"' as jsonb), '$' - returning char(3) - error on error); + json_query(cast('"aaa"' as jsonb), '$' returning char(3) error on error); select json_query(cast('"aaa"' as jsonb), '$' returning char(3)); @@ -418,14 +386,10 @@ select default cast('"bb"' as jsonb) on empty); select - json_query(cast('[1]' as jsonb), '$' - with unconditional wrapper - omit quotes); + json_query(cast('[1]' as jsonb), '$' with unconditional wrapper omit quotes); select - json_query(cast('[1]' as jsonb), '$' - with conditional wrapper - omit quotes); + json_query(cast('[1]' as jsonb), '$' with conditional wrapper omit quotes); select json_query(cast('["1"]' as jsonb), '$[*]' @@ -513,14 +477,10 @@ select json_query(cast('[]' as jsonb), '$[*]' default '"empty"' on empty); select json_query(cast('[]' as jsonb), '$[*]' error on empty null on error); select - json_query(cast('[]' as jsonb), '$[*]' - error on empty - empty array on error); + json_query(cast('[]' as jsonb), '$[*]' error on empty empty array on error); select - json_query(cast('[]' as jsonb), '$[*]' - error on empty - empty object on error); + json_query(cast('[]' as jsonb), '$[*]' error on empty empty object on error); select json_query(cast('[]' as jsonb), '$[*]' error on empty error on error); @@ -578,44 +538,31 @@ select returning bigint[] empty object on error); -select - json_query(cast('"123.1"' as jsonb), '$' - returning smallint - error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning int2 error on error); -select json_query(cast('"123.1"' as jsonb), '$' returning int error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning int4 error on error); -select - json_query(cast('"123.1"' as jsonb), '$' - returning bigint - error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning int8 error on error); -select - json_query(cast('"123.1"' as jsonb), '$' - returning boolean - error on error); +select json_query(cast('"123.1"' as jsonb), '$' returning bool error on error); select - json_query(cast('"123.1"' as jsonb), '$' - returning numeric - error on error); + json_query(cast('"123.1"' as jsonb), '$' returning numeric error on error); select json_query(cast('"123.1"' as jsonb), '$' returning real error on error); select - json_query(cast('"123.1"' as jsonb), '$' - returning double precision - error on error); + json_query(cast('"123.1"' as jsonb), '$' returning float8 error on error); select json_query(cast('"123.1"' as jsonb), '$' - returning smallint + returning int2 omit quotes error on error); select json_query(cast('"123.1"' as jsonb), '$' - returning double precision + returning float8 omit quotes error on error); @@ -640,20 +587,17 @@ from create type comp_abc as (a text, b int, c timestamp); select - json_query(cast('{"rec": "(abc,42,01.02.2003)"}' - as jsonb), '$.rec' + json_query(cast('{"rec": "(abc,42,01.02.2003)"}' as jsonb), '$.rec' returning comp_abc omit quotes); select - json_query(cast('{"rec": "(abc,42,01.02.2003)"}' - as jsonb), '$.rec' + json_query(cast('{"rec": "(abc,42,01.02.2003)"}' as jsonb), '$.rec' returning comp_abc keep quotes); select - json_query(cast('{"rec": "(abc,42,01.02.2003)"}' - as jsonb), '$.rec' + json_query(cast('{"rec": "(abc,42,01.02.2003)"}' as jsonb), '$.rec' returning comp_abc keep quotes error on error); @@ -735,12 +679,10 @@ from ); select - json_query(cast('{"a": 1}' as jsonb), '$.a' - returning sqljsonb_int_not_null); + json_query(cast('{"a": 1}' as jsonb), '$.a' returning sqljsonb_int_not_null); select - json_query(cast('{"a": 1}' as jsonb), '$.b' - returning sqljsonb_int_not_null); + json_query(cast('{"a": 1}' as jsonb), '$.b' returning sqljsonb_int_not_null); select json_query(cast('{"a": 1}' as jsonb), '$.b' @@ -750,46 +692,44 @@ select select json_query(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts); + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts); select json_query(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning json); select json_query(cast('null' as jsonb), '$ts' - passing cast('2018-02-21 12:34:56 +10' - as timestamp with time zone) as ts + passing cast('2018-02-21 12:34:56 +10' as timestamptz) as ts returning jsonb); create table test_jsonb_constraints ( js text, i int, x jsonb - default json_query(cast('[1,2]' as jsonb), '$[*]' - with unconditional wrapper) - constraint "test_jsonb_constraint1" check (js is json) - constraint "test_jsonb_constraint2" check (json_exists(cast(js as jsonb), '$.a' - passing i + 5 as int, - cast(i as text) as "TXT", - array[1, 2, 3] as arr)) - constraint "test_jsonb_constraint3" check (json_value(cast(js as jsonb), '$.a' - returning int - default '12' on empty - error on error) > - i) - constraint "test_jsonb_constraint4" check (json_query(cast(js as jsonb), '$.a' - with conditional wrapper - empty object on error) = - cast('[10]' as jsonb)) - constraint "test_jsonb_constraint5" check (json_query(cast(js as jsonb), '$.a' - returning char(5) - omit quotes - empty array on empty) > - 'a' collate "C") + default json_query(cast('[1,2]' as jsonb), '$[*]' + with unconditional wrapper) + constraint test_jsonb_constraint1 check (js is json) + constraint test_jsonb_constraint2 check (json_exists(cast(js + as jsonb), '$.a' + passing i + 5 as int, + cast(i as text) as "TXT", + array[1, 2, 3] as arr)) + constraint test_jsonb_constraint3 check (json_value(cast(js as jsonb), '$.a' + returning int + default '12' on empty + error on error) > + i) + constraint test_jsonb_constraint4 check (json_query(cast(js as jsonb), '$.a' + with conditional wrapper + empty object on error) = + cast('[10]' as jsonb)) + constraint test_jsonb_constraint5 check (json_query(cast(js as jsonb), '$.a' + returning char(5) + omit quotes + empty array on empty) > + 'a' collate "C") ); select @@ -805,9 +745,7 @@ select from pg_attrdef where - adrelid = - cast('test_jsonb_constraints' - as regclass) + adrelid = cast('test_jsonb_constraints' as regclass) order by 1; insert into test_jsonb_constraints values ('', 1); @@ -833,312 +771,188 @@ create index on test_jsonb_mutability using btree ((json_query(js, '$'))); create index on test_jsonb_mutability using btree ((json_query(js, '$.a[0]'))); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.time()')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.date()')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.time_tz()')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.timestamp()')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.timestamp_tz()')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.date() < $.time_tz())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.date() < $.time())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.time() < $.time())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.time() < $.time_tz())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp() < $.timestamp_tz())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp_tz() < $.timestamp_tz())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.time() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.date() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp() < $.datetime("HH:MI"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp_tz() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp_tz() < $.datetime("HH:MI"))')) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.date() < $x' - passing cast('12:34' as time with time zone) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.date() < $x' passing cast('12:34' as timetz) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.date() < $x' - passing cast('1234' as int) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.date() < $x' passing cast('1234' as int) as x)) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.timestamp(2) < $.timestamp(3))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.datetime()')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@ < $.datetime())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime() < $.datetime())')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime() < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime("HH:MI TZH") < $.datetime("HH:MI TZH"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime("HH:MI") < $.datetime("YY-MM-DD HH:MI"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.a ? (@.datetime("HH:MI TZH") < $.datetime("YY-MM-DD HH:MI"))')) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.datetime("HH:MI TZH") < $x' - passing cast('12:34' as time with time zone) as x)) + passing cast('12:34' as timetz) as x)) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.datetime("HH:MI TZH") < $y' - passing cast('12:34' as time with time zone) as x)) + passing cast('12:34' as timetz) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.datetime() < $x' - passing cast('12:34' as time with time zone) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.datetime() < $x' passing cast('12:34' as timetz) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_query(js, '$.datetime() < $x' - passing cast('1234' as int) as x)) +create index on test_jsonb_mutability using btree ( + (json_query(js, '$.datetime() < $x' passing cast('1234' as int) as x)) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.datetime() ? (@ == $x)' passing cast('12:34' as time) as x)) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$.datetime("YY-MM-DD") ? (@ == $x)' passing cast('2020-07-14' as date) as x)) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$[1, $.a ? (@.datetime() == $x)]' passing cast('12:34' as time) as x)) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$[1, 0 to $.a ? (@.datetime() == $x)]' passing cast('12:34' as time) as x)) ); -create index -on test_jsonb_mutability -using btree -( +create index on test_jsonb_mutability using btree ( (json_query(js, '$[1, $.a ? (@.datetime("HH:MI") == $x)]' passing cast('12:34' as time) as x)) ); -create index -on test_jsonb_mutability -using btree -( - (json_value(js, '$' - default cast(random() as int) on error)) +create index on test_jsonb_mutability using btree ( + (json_value(js, '$' default cast(random() as int) on error)) ); create or replace function ret_setint() returns setof int language plpgsql immutable -as $function$ +as $$ BEGIN RETURN QUERY EXECUTE 'select 1 union all select 1'; END; -$function$; +$$; select - json_query(js, '$' - returning int - default ret_setint() on error) + json_query(js, '$' returning int default ret_setint() on error) from test_jsonb_mutability; select - json_query(js, '$' - returning int - default b + 1 on error) + json_query(js, '$' returning int default b + 1 on error) from test_jsonb_mutability; select - json_query(js, '$' - returning int - default SUM(1) over () on error) + json_query(js, '$' returning int default sum(1) over () on error) from test_jsonb_mutability; select - json_query(js, '$' - returning int - default (select 1) on error) + json_query(js, '$' returning int default (select 1) on error) from test_jsonb_mutability; @@ -1176,8 +990,7 @@ select select json_query('"a"', '$.a' returning queryfuncs_test_domain - default cast((select '"1"') - as queryfuncs_test_domain) on error); + default cast((select '"1"') as queryfuncs_test_domain) on error); select json_query('"a"', '$.a' @@ -1187,8 +1000,7 @@ select select json_query('"a"', '$.a' returning int[] - default cast(cast((select '{1}') as oid[]) - as int[]) on error); + default cast(cast((select '{1}') as oid[]) as int[]) on error); select json_query('"a"', '$.a' @@ -1203,8 +1015,7 @@ inherits (someparent); select json_query('"a"', '$.a' returning someparent - default cast(cast((select '(1)') as somechild) - as someparent) on error); + default cast(cast((select '(1)') as somechild) as someparent) on error); drop domain queryfuncs_test_domain; @@ -1298,7 +1109,7 @@ select drop domain queryfuncs_char2, queryfuncs_char2_chk; -create domain queryfuncs_d_varbit3 as bit varying(3) check (value <> '01'); +create domain queryfuncs_d_varbit3 as varbit(3) check (value <> '01'); select json_value(cast('1234' as jsonb), '$' @@ -1318,9 +1129,7 @@ select select json_value(cast('"111"' as jsonb), '$' returning bit(2) error on error); select - json_value(cast('1234' as jsonb), '$' - returning bit(3) - default 1 on error); + json_value(cast('1234' as jsonb), '$' returning bit(3) default 1 on error); select json_value(cast('1234' as jsonb), '$' diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_100.snap index 714332498..f3e4252bb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_100.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/stats.sql --- -show "track_counts"; +show track_counts; select backend_type, @@ -140,11 +140,11 @@ insert into trunc_stats_test4 default values; rollback; -select COUNT(*) from tenk2; +select count(*) from tenk2; set enable_bitmapscan = off; -select COUNT(*) from tenk2 where unique1 = 1; +select count(*) from tenk2 where unique1 = 1; reset enable_bitmapscan; @@ -180,10 +180,8 @@ where st.relname = 'tenk2' and cl.relname = 'tenk2'; select - st.heap_blks_read + st.heap_blks_hit >= - pr.heap_blks + cl.relpages, - st.idx_blks_read + st.idx_blks_hit >= - pr.idx_blks + 1 + st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages, + st.idx_blks_read + st.idx_blks_hit >= pr.idx_blks + 1 from pg_statio_user_tables as st, pg_class as cl, @@ -198,24 +196,20 @@ commit; create function stats_test_func1() returns void language plpgsql -as $function$ -BEGIN END; -$function$; +as $$BEGIN END;$$; select cast(cast('stats_test_func1()' as regprocedure) as oid) as stats_test_func1_oid; create function stats_test_func2() returns void language plpgsql -as $function$ -BEGIN END; -$function$; +as $$BEGIN END;$$; select cast(cast('stats_test_func2()' as regprocedure) as oid) as stats_test_func2_oid; begin; -set local stats_fetch_consistency = 'none'; +set local stats_fetch_consistency = none; select pg_stat_get_function_calls('stats_test_func1_oid'); @@ -479,15 +473,15 @@ set local enable_indexscan = 'on'; set local enable_bitmapscan = off; -select COUNT(*) from test_last_scan where noidx_col = 1; +select count(*) from test_last_scan where noidx_col = 1; -select COUNT(*) from test_last_scan where noidx_col = 1; +select count(*) from test_last_scan where noidx_col = 1; set local enable_seqscan = off; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; select pg_stat_force_next_flush(); @@ -511,9 +505,9 @@ set local enable_indexscan = off; set local enable_bitmapscan = off; -select COUNT(*) from test_last_scan where noidx_col = 1; +select count(*) from test_last_scan where noidx_col = 1; -select COUNT(*) from test_last_scan where noidx_col = 1; +select count(*) from test_last_scan where noidx_col = 1; select pg_stat_force_next_flush(); @@ -547,9 +541,9 @@ set local enable_indexscan = 'on'; set local enable_bitmapscan = off; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; select pg_stat_force_next_flush(); @@ -583,9 +577,9 @@ set local enable_indexscan = off; set local enable_bitmapscan = 'on'; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; select pg_stat_force_next_flush(); @@ -602,8 +596,7 @@ where relid = cast('test_last_scan' as regclass); select - shobj_description(d.oid, 'pg_database') - as description_before + shobj_description(d.oid, 'pg_database') as description_before from pg_database as d where @@ -668,9 +661,7 @@ select pg_stat_force_next_flush(); select wal_bytes > 'backend_wal_bytes_before' from pg_stat_get_backend_wal(pg_backend_pid()); select - (current_schemas(true))[1] = - 'pg_temp_' || cast(beid as text) - as match + (current_schemas(true))[1] = 'pg_temp_' || cast(beid as text) as match from pg_stat_get_backend_idset() as beid where @@ -683,9 +674,7 @@ select stats_reset as slru_notify_reset_ts from pg_stat_slru where name = 'notif select pg_stat_reset_slru('commit_timestamp'); select - stats_reset > - cast('slru_commit_ts_reset_ts' - as timestamp with time zone) + stats_reset > cast('slru_commit_ts_reset_ts' as timestamptz) from pg_stat_slru where @@ -696,18 +685,14 @@ select stats_reset as slru_commit_ts_reset_ts from pg_stat_slru where name = 'co select pg_stat_reset_slru(); select - stats_reset > - cast('slru_commit_ts_reset_ts' - as timestamp with time zone) + stats_reset > cast('slru_commit_ts_reset_ts' as timestamptz) from pg_stat_slru where name = 'commit_timestamp'; select - stats_reset > - cast('slru_notify_reset_ts' - as timestamp with time zone) + stats_reset > cast('slru_notify_reset_ts' as timestamptz) from pg_stat_slru where @@ -717,47 +702,40 @@ select stats_reset as archiver_reset_ts from pg_stat_archiver; select pg_stat_reset_shared('archiver'); -select stats_reset > cast('archiver_reset_ts' as timestamp with time zone) from pg_stat_archiver; +select stats_reset > cast('archiver_reset_ts' as timestamptz) from pg_stat_archiver; select stats_reset as bgwriter_reset_ts from pg_stat_bgwriter; select pg_stat_reset_shared('bgwriter'); -select stats_reset > cast('bgwriter_reset_ts' as timestamp with time zone) from pg_stat_bgwriter; +select stats_reset > cast('bgwriter_reset_ts' as timestamptz) from pg_stat_bgwriter; select stats_reset as checkpointer_reset_ts from pg_stat_checkpointer; select pg_stat_reset_shared('checkpointer'); -select - stats_reset > - cast('checkpointer_reset_ts' - as timestamp with time zone) -from - pg_stat_checkpointer; +select stats_reset > cast('checkpointer_reset_ts' as timestamptz) from pg_stat_checkpointer; select stats_reset as recovery_prefetch_reset_ts from pg_stat_recovery_prefetch; select pg_stat_reset_shared('recovery_prefetch'); select - stats_reset > - cast('recovery_prefetch_reset_ts' - as timestamp with time zone) + stats_reset > cast('recovery_prefetch_reset_ts' as timestamptz) from pg_stat_recovery_prefetch; -select MAX(stats_reset) as slru_reset_ts from pg_stat_slru; +select max(stats_reset) as slru_reset_ts from pg_stat_slru; select pg_stat_reset_shared('slru'); -select MAX(stats_reset) > cast('slru_reset_ts' as timestamp with time zone) from pg_stat_slru; +select max(stats_reset) > cast('slru_reset_ts' as timestamptz) from pg_stat_slru; select stats_reset as wal_reset_ts from pg_stat_wal; select pg_stat_reset_shared('wal'); -select stats_reset > cast('wal_reset_ts' as timestamp with time zone) from pg_stat_wal; +select stats_reset > cast('wal_reset_ts' as timestamptz) from pg_stat_wal; select pg_stat_reset_shared('unknown'); @@ -768,8 +746,7 @@ select stats_reset as db_reset_ts from pg_stat_database where datname = (select select pg_stat_reset(); select - stats_reset > - cast('db_reset_ts' as timestamp with time zone) + stats_reset > cast('db_reset_ts' as timestamptz) from pg_stat_database where @@ -783,7 +760,7 @@ select pg_stat_get_snapshot_timestamp(); select pg_stat_get_function_calls(0); -select pg_stat_get_snapshot_timestamp() >= NOW(); +select pg_stat_get_snapshot_timestamp() >= now(); select pg_stat_clear_snapshot(); @@ -807,7 +784,7 @@ select pg_stat_get_function_calls(0); select pg_stat_get_snapshot_timestamp() is not null as snapshot_ok; -set local stats_fetch_consistency = 'none'; +set local stats_fetch_consistency = none; select pg_stat_get_snapshot_timestamp() is not null as snapshot_ok; @@ -827,7 +804,7 @@ select pg_stat_have_stats('database', 'dboid', 0); create table stats_test_tab1 as select generate_series(1, 10) as a; -create index "stats_test_idx1" on stats_test_tab1 using btree (a); +create index stats_test_idx1 on stats_test_tab1 using btree (a); select cast(cast('stats_test_idx1' as regclass) as oid) as stats_test_idx1_oid; @@ -845,7 +822,7 @@ select pg_stat_have_stats('relation', 'dboid', 'stats_test_idx1_oid'); begin; -create index "stats_test_idx1" on stats_test_tab1 using btree (a); +create index stats_test_idx1 on stats_test_tab1 using btree (a); select cast(cast('stats_test_idx1' as regclass) as oid) as stats_test_idx1_oid; @@ -857,7 +834,7 @@ rollback; select pg_stat_have_stats('relation', 'dboid', 'stats_test_idx1_oid'); -create index "stats_test_idx1" on stats_test_tab1 using btree (a); +create index stats_test_idx1 on stats_test_tab1 using btree (a); select cast(cast('stats_test_idx1' as regclass) as oid) as stats_test_idx1_oid; @@ -865,7 +842,7 @@ select a from stats_test_tab1 where a = 3; select pg_stat_have_stats('relation', 'dboid', 'stats_test_idx1_oid'); -reindex (CONCURRENTLY) index stats_test_idx1; +reindex (concurrently) index stats_test_idx1; select pg_stat_have_stats('relation', 'dboid', 'stats_test_idx1_oid'); @@ -892,32 +869,32 @@ select pg_stat_get_subscription_stats(null); select pid as checkpointer_pid from pg_stat_activity where backend_type = 'checkpointer'; select - SUM(extends) as io_sum_shared_before_extends + sum(extends) as io_sum_shared_before_extends from pg_stat_io where context = 'normal' and object = 'relation'; select - SUM(extends) as my_io_sum_shared_before_extends + sum(extends) as my_io_sum_shared_before_extends from pg_stat_get_backend_io(pg_backend_pid()) where context = 'normal' and object = 'relation'; -select SUM(writes) as writes, SUM(fsyncs) as fsyncs from pg_stat_io where object = 'relation'; +select sum(writes) as writes, sum(fsyncs) as fsyncs from pg_stat_io where object = 'relation'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_get_backend_io(pg_backend_pid()) where object = 'relation'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_io where @@ -930,7 +907,7 @@ insert into test_io_shared select i from generate_series(1, 100) as i; select pg_stat_force_next_flush(); select - SUM(extends) as io_sum_shared_after_extends + sum(extends) as io_sum_shared_after_extends from pg_stat_io where @@ -939,7 +916,7 @@ where select 'io_sum_shared_after_extends' > 'io_sum_shared_before_extends'; select - SUM(extends) as my_io_sum_shared_after_extends + sum(extends) as my_io_sum_shared_after_extends from pg_stat_get_backend_io(pg_backend_pid()) where @@ -951,18 +928,16 @@ checkpoint; checkpoint; -select SUM(writes) as writes, SUM(fsyncs) as fsyncs from pg_stat_io where object = 'relation'; +select sum(writes) as writes, sum(fsyncs) as fsyncs from pg_stat_io where object = 'relation'; select 'io_sum_shared_after_writes' > 'io_sum_shared_before_writes'; select - current_setting('fsync') = 'off' or - 'io_sum_shared_after_fsyncs' > - 'io_sum_shared_before_fsyncs'; + current_setting('fsync') = 'off' or 'io_sum_shared_after_fsyncs' > 'io_sum_shared_before_fsyncs'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_get_backend_io(pg_backend_pid()) where @@ -972,12 +947,11 @@ select 'my_io_sum_shared_after_writes' >= 'my_io_sum_shared_before_writes'; select current_setting('fsync') = 'off' or - 'my_io_sum_shared_after_fsyncs' >= - 'my_io_sum_shared_before_fsyncs'; + 'my_io_sum_shared_after_fsyncs' >= 'my_io_sum_shared_before_fsyncs'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_io where @@ -989,15 +963,11 @@ select 'io_sum_wal_normal_after_writes' > 'io_sum_wal_normal_before_writes'; select current_setting('fsync') = 'off' or - current_setting('wal_sync_method') - in ( - 'open_sync', 'open_datasync' - ) or - 'io_sum_wal_normal_after_fsyncs' > - 'io_sum_wal_normal_before_fsyncs'; + current_setting('wal_sync_method') in ('open_sync', 'open_datasync') or + 'io_sum_wal_normal_after_fsyncs' > 'io_sum_wal_normal_before_fsyncs'; select - SUM(reads) as io_sum_shared_before_reads + sum(reads) as io_sum_shared_before_reads from pg_stat_io where @@ -1008,14 +978,14 @@ begin; alter table test_io_shared set tablespace regress_tblspace; -select COUNT(*) from test_io_shared; +select count(*) from test_io_shared; commit; select pg_stat_force_next_flush(); select - SUM(reads) as io_sum_shared_after_reads + sum(reads) as io_sum_shared_after_reads from pg_stat_io where @@ -1024,7 +994,7 @@ where select 'io_sum_shared_after_reads' > 'io_sum_shared_before_reads'; select - SUM(hits) as io_sum_shared_before_hits + sum(hits) as io_sum_shared_before_hits from pg_stat_io where @@ -1040,16 +1010,16 @@ set local enable_hashjoin = off; set local enable_material = off; -select COUNT(*) from test_io_shared as t1 inner join test_io_shared as t2 using ("a"); +select count(*) from test_io_shared as t1 inner join test_io_shared as t2 using (a); -select COUNT(*) from test_io_shared as t1 inner join test_io_shared as t2 using ("a"); +select count(*) from test_io_shared as t1 inner join test_io_shared as t2 using (a); commit; select pg_stat_force_next_flush(); select - SUM(hits) as io_sum_shared_after_hits + sum(hits) as io_sum_shared_after_hits from pg_stat_io where @@ -1067,9 +1037,9 @@ create temporary table test_io_local ( ); select - SUM(extends) as extends, - SUM(evictions) as evictions, - SUM(writes) as writes + sum(extends) as extends, + sum(evictions) as evictions, + sum(writes) as writes from pg_stat_io where @@ -1077,38 +1047,34 @@ where insert into test_io_local select generate_series(1, 5000) as id, repeat('a', 200); -select pg_relation_size('test_io_local') / cast(current_setting('block_size') as bigint) > 100; +select pg_relation_size('test_io_local') / cast(current_setting('block_size') as int8) > 100; select - SUM(reads) as io_sum_local_before_reads + sum(reads) as io_sum_local_before_reads from pg_stat_io where context = 'normal' and object = 'temp relation'; -select COUNT(*) from test_io_local; +select count(*) from test_io_local; select pg_stat_force_next_flush(); select - SUM(evictions) as evictions, - SUM(reads) as reads, - SUM(writes) as writes, - SUM(extends) as extends + sum(evictions) as evictions, + sum(reads) as reads, + sum(writes) as writes, + sum(extends) as extends from pg_stat_io where context = 'normal' and object = 'temp relation'; select - 'io_sum_local_after_evictions' > - 'io_sum_local_before_evictions', - 'io_sum_local_after_reads' > - 'io_sum_local_before_reads', - 'io_sum_local_after_writes' > - 'io_sum_local_before_writes', - 'io_sum_local_after_extends' > - 'io_sum_local_before_extends'; + 'io_sum_local_after_evictions' > 'io_sum_local_before_evictions', + 'io_sum_local_after_reads' > 'io_sum_local_before_reads', + 'io_sum_local_after_writes' > 'io_sum_local_before_writes', + 'io_sum_local_after_extends' > 'io_sum_local_before_extends'; alter table test_io_local set tablespace regress_tblspace; @@ -1116,7 +1082,7 @@ alter table test_io_local select pg_stat_force_next_flush(); select - SUM(writes) as io_sum_local_new_tblspc_writes + sum(writes) as io_sum_local_new_tblspc_writes from pg_stat_io where @@ -1129,9 +1095,9 @@ reset temp_buffers; set wal_skip_threshold = '1 kB'; select - SUM(reuses) as reuses, - SUM(reads) as reads, - SUM(evictions) as evictions + sum(reuses) as reuses, + sum(reads) as reads, + sum(evictions) as evictions from pg_stat_io where @@ -1145,16 +1111,16 @@ with (autovacuum_enabled = 'false'); insert into test_io_vac_strategy select i, i from generate_series(1, 4500) as i; -vacuum (FULL) test_io_vac_strategy; +vacuum (full) test_io_vac_strategy; -vacuum (PARALLEL 0, BUFFER_USAGE_LIMIT 128) test_io_vac_strategy; +vacuum (parallel 0, buffer_usage_limit 128) test_io_vac_strategy; select pg_stat_force_next_flush(); select - SUM(reuses) as reuses, - SUM(reads) as reads, - SUM(evictions) as evictions + sum(reuses) as reuses, + sum(reads) as reads, + sum(evictions) as evictions from pg_stat_io where @@ -1163,16 +1129,13 @@ where select 'io_sum_vac_strategy_after_reads' > 'io_sum_vac_strategy_before_reads'; select - 'io_sum_vac_strategy_after_reuses' + - 'io_sum_vac_strategy_after_evictions' > - 'io_sum_vac_strategy_before_reuses' + - 'io_sum_vac_strategy_before_evictions'; + 'io_sum_vac_strategy_after_reuses' + 'io_sum_vac_strategy_after_evictions' > + 'io_sum_vac_strategy_before_reuses' + 'io_sum_vac_strategy_before_evictions'; reset wal_skip_threshold; select - SUM(extends) - as io_sum_bulkwrite_strategy_extends_before + sum(extends) as io_sum_bulkwrite_strategy_extends_before from pg_stat_io where @@ -1183,8 +1146,7 @@ create table test_io_bulkwrite_strategy as select i from generate_series(1, 100) select pg_stat_force_next_flush(); select - SUM(extends) - as io_sum_bulkwrite_strategy_extends_after + sum(extends) as io_sum_bulkwrite_strategy_extends_after from pg_stat_io where @@ -1195,23 +1157,17 @@ select 'io_sum_bulkwrite_strategy_extends_after' > 'io_sum_bulkwrite_strategy_ex select pg_stat_have_stats('io', 0, 0); select - SUM(evictions) + SUM(reuses) + SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + sum(writes) + + sum(writebacks) + + sum(hits) as io_stats_pre_reset from pg_stat_io; select - SUM(evictions) + SUM(reuses) + SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + sum(writes) + + sum(writebacks) + + sum(hits) as my_io_stats_pre_reset from pg_stat_get_backend_io(pg_backend_pid()); @@ -1219,12 +1175,9 @@ from select pg_stat_reset_shared('io'); select - SUM(evictions) + SUM(reuses) + SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + sum(writes) + + sum(writebacks) + + sum(hits) as io_stats_post_reset from pg_stat_io; @@ -1232,12 +1185,9 @@ from select 'io_stats_post_reset' < 'io_stats_pre_reset'; select - SUM(evictions) + SUM(reuses) + SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + sum(writes) + + sum(writebacks) + + sum(hits) as my_io_stats_post_reset from pg_stat_get_backend_io(pg_backend_pid()); @@ -1247,12 +1197,9 @@ select 'my_io_stats_pre_reset' <= 'my_io_stats_post_reset'; select pg_stat_reset_backend_stats(pg_backend_pid()); select - SUM(evictions) + SUM(reuses) + SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + sum(writes) + + sum(writebacks) + + sum(hits) as my_io_stats_post_backend_reset from pg_stat_get_backend_io(pg_backend_pid()); @@ -1273,12 +1220,12 @@ with (autovacuum_enabled = off, fillfactor = 70); insert into brin_hot select *, 0 from generate_series(1, 235); -create index "val_brin" on brin_hot using brin (val); +create index val_brin on brin_hot using brin (val); create function wait_for_hot_stats() returns void language plpgsql -as $function$ +as $$ DECLARE start_time timestamptz := clock_timestamp(); updated bool; @@ -1297,7 +1244,7 @@ BEGIN RAISE log 'wait_for_hot_stats delayed % seconds', EXTRACT(epoch FROM clock_timestamp() - start_time); END -$function$; +$$; update brin_hot set val = -3 where id = 42; @@ -1316,26 +1263,19 @@ create table brin_hot_2 ( insert into brin_hot_2 values (1, 100); -create index -on brin_hot_2 -using brin -( - b -) -where - a = 2; +create index on brin_hot_2 using brin (b) where a = 2; update brin_hot_2 set a = 2; select * from brin_hot_2 where a = 2 and b = 100; -select COUNT(*) from brin_hot_2 where a = 2 and b = 100; +select count(*) from brin_hot_2 where a = 2 and b = 100; set enable_seqscan = off; select * from brin_hot_2 where a = 2 and b = 100; -select COUNT(*) from brin_hot_2 where a = 2 and b = 100; +select count(*) from brin_hot_2 where a = 2 and b = 100; drop table brin_hot_2; @@ -1347,19 +1287,13 @@ with (fillfactor = 10); insert into brin_hot_3 select 1, repeat(' ', 500) from generate_series(1, 20); -create index -on brin_hot_3 -using brin -( - a -) -with (pages_per_range = 1); +create index on brin_hot_3 using brin (a) with (pages_per_range = 1); update brin_hot_3 set a = 2; select * from brin_hot_3 where a = 2; -select COUNT(*) from brin_hot_3 where a = 2; +select count(*) from brin_hot_3 where a = 2; drop table brin_hot_3; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_80.snap index 162bbedb6..2df0eeff9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/stats.sql --- -show "track_counts"; +show track_counts; select backend_type, @@ -35,18 +35,14 @@ as t.seq_tup_read, t.idx_scan, t.idx_tup_fetch, - b.heap_blks_read + b.heap_blks_hit - as heap_blks, - b.idx_blks_read + b.idx_blks_hit - as idx_blks, - pg_stat_get_snapshot_timestamp() - as snap_ts + b.heap_blks_read + b.heap_blks_hit as heap_blks, + b.idx_blks_read + b.idx_blks_hit as idx_blks, + pg_stat_get_snapshot_timestamp() as snap_ts from pg_catalog.pg_stat_user_tables as t, pg_catalog.pg_statio_user_tables as b where - t.relname = 'tenk2' and - b.relname = 'tenk2'; + t.relname = 'tenk2' and b.relname = 'tenk2'; commit; @@ -144,11 +140,11 @@ insert into trunc_stats_test4 default values; rollback; -select COUNT(*) from tenk2; +select count(*) from tenk2; set enable_bitmapscan = off; -select COUNT(*) from tenk2 where unique1 = 1; +select count(*) from tenk2 where unique1 = 1; reset enable_bitmapscan; @@ -173,8 +169,7 @@ order by relname; select st.seq_scan >= pr.seq_scan + 1, - st.seq_tup_read >= - pr.seq_tup_read + cl.reltuples, + st.seq_tup_read >= pr.seq_tup_read + cl.reltuples, st.idx_scan >= pr.idx_scan + 1, st.idx_tup_fetch >= pr.idx_tup_fetch + 1 from @@ -182,26 +177,20 @@ from pg_class as cl, prevstats as pr where - st.relname = 'tenk2' and - cl.relname = 'tenk2'; + st.relname = 'tenk2' and cl.relname = 'tenk2'; select - st.heap_blks_read + st.heap_blks_hit >= - pr.heap_blks + cl.relpages, - st.idx_blks_read + st.idx_blks_hit >= - pr.idx_blks + 1 + st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages, + st.idx_blks_read + st.idx_blks_hit >= pr.idx_blks + 1 from pg_statio_user_tables as st, pg_class as cl, prevstats as pr where - st.relname = 'tenk2' and - cl.relname = 'tenk2'; + st.relname = 'tenk2' and cl.relname = 'tenk2'; select - pr.snap_ts < - pg_stat_get_snapshot_timestamp() - as snapshot_newer + pr.snap_ts < pg_stat_get_snapshot_timestamp() as snapshot_newer from prevstats as pr; @@ -210,32 +199,24 @@ commit; create function stats_test_func1() returns void language plpgsql -as $function$ -BEGIN END; -$function$; +as $$BEGIN END;$$; select - cast(cast('stats_test_func1()' - as regprocedure) - as oid) + cast(cast('stats_test_func1()' as regprocedure) as oid) as stats_test_func1_oid; create function stats_test_func2() returns void language plpgsql -as $function$ -BEGIN END; -$function$; +as $$BEGIN END;$$; select - cast(cast('stats_test_func2()' - as regprocedure) - as oid) + cast(cast('stats_test_func2()' as regprocedure) as oid) as stats_test_func2_oid; begin; -set local stats_fetch_consistency = 'none'; +set local stats_fetch_consistency = none; select pg_stat_get_function_calls('stats_test_func1_oid'); @@ -378,8 +359,7 @@ create table drop_stats_test_xact (); insert into drop_stats_test_xact default values; select - cast(cast('drop_stats_test_xact' as regclass) - as oid) + cast(cast('drop_stats_test_xact' as regclass) as oid) as drop_stats_test_xact_oid; create table drop_stats_test_subxact (); @@ -387,9 +367,7 @@ create table drop_stats_test_subxact (); insert into drop_stats_test_subxact default values; select - cast(cast('drop_stats_test_subxact' - as regclass) - as oid) + cast(cast('drop_stats_test_subxact' as regclass) as oid) as drop_stats_test_subxact_oid; select pg_stat_force_next_flush(); @@ -532,8 +510,7 @@ select from pg_stat_all_tables where - relid = - cast('test_last_scan' as regclass); + relid = cast('test_last_scan' as regclass); commit; @@ -545,8 +522,7 @@ select from pg_stat_all_tables where - relid = - cast('test_last_scan' as regclass); + relid = cast('test_last_scan' as regclass); begin; @@ -556,15 +532,15 @@ set local enable_indexscan = 'on'; set local enable_bitmapscan = off; -select COUNT(*) from test_last_scan where noidx_col = 1; +select count(*) from test_last_scan where noidx_col = 1; -select COUNT(*) from test_last_scan where noidx_col = 1; +select count(*) from test_last_scan where noidx_col = 1; set local enable_seqscan = off; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; select pg_stat_force_next_flush(); @@ -576,8 +552,7 @@ select from pg_stat_all_tables where - relid = - cast('test_last_scan' as regclass); + relid = cast('test_last_scan' as regclass); select pg_sleep(0.1); @@ -589,9 +564,9 @@ set local enable_indexscan = off; set local enable_bitmapscan = off; -select COUNT(*) from test_last_scan where noidx_col = 1; +select count(*) from test_last_scan where noidx_col = 1; -select COUNT(*) from test_last_scan where noidx_col = 1; +select count(*) from test_last_scan where noidx_col = 1; select pg_stat_force_next_flush(); @@ -599,16 +574,13 @@ commit; select seq_scan, - 'test_last_seq' < last_seq_scan - as seq_ok, + 'test_last_seq' < last_seq_scan as seq_ok, idx_scan, - 'test_last_idx' = last_idx_scan - as idx_ok + 'test_last_idx' = last_idx_scan as idx_ok from pg_stat_all_tables where - relid = - cast('test_last_scan' as regclass); + relid = cast('test_last_scan' as regclass); select last_seq_scan as test_last_seq, @@ -616,8 +588,7 @@ select from pg_stat_all_tables where - relid = - cast('test_last_scan' as regclass); + relid = cast('test_last_scan' as regclass); select pg_sleep(0.1); @@ -629,9 +600,9 @@ set local enable_indexscan = 'on'; set local enable_bitmapscan = off; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; select pg_stat_force_next_flush(); @@ -639,16 +610,13 @@ commit; select seq_scan, - 'test_last_seq' = last_seq_scan - as seq_ok, + 'test_last_seq' = last_seq_scan as seq_ok, idx_scan, - 'test_last_idx' < last_idx_scan - as idx_ok + 'test_last_idx' < last_idx_scan as idx_ok from pg_stat_all_tables where - relid = - cast('test_last_scan' as regclass); + relid = cast('test_last_scan' as regclass); select last_seq_scan as test_last_seq, @@ -656,8 +624,7 @@ select from pg_stat_all_tables where - relid = - cast('test_last_scan' as regclass); + relid = cast('test_last_scan' as regclass); select pg_sleep(0.1); @@ -669,9 +636,9 @@ set local enable_indexscan = off; set local enable_bitmapscan = 'on'; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; -select COUNT(*) from test_last_scan where idx_col = 1; +select count(*) from test_last_scan where idx_col = 1; select pg_stat_force_next_flush(); @@ -679,20 +646,16 @@ commit; select seq_scan, - 'test_last_seq' = last_seq_scan - as seq_ok, + 'test_last_seq' = last_seq_scan as seq_ok, idx_scan, - 'test_last_idx' < last_idx_scan - as idx_ok + 'test_last_idx' < last_idx_scan as idx_ok from pg_stat_all_tables where - relid = - cast('test_last_scan' as regclass); + relid = cast('test_last_scan' as regclass); select - shobj_description(d.oid, 'pg_database') - as description_before + shobj_description(d.oid, 'pg_database') as description_before from pg_database as d where @@ -711,21 +674,17 @@ select from pg_stat_all_tables where - relid = - cast('pg_shdescription' as regclass); + relid = cast('pg_shdescription' as regclass); select - pg_stat_reset_single_table_counters( - cast('pg_shdescription' as regclass) - ); + pg_stat_reset_single_table_counters(cast('pg_shdescription' as regclass)); select n_tup_ins + n_tup_upd > 0 as has_data from pg_stat_all_tables where - relid = - cast('pg_shdescription' as regclass); + relid = cast('pg_shdescription' as regclass); select sessions as db_stat_sessions @@ -750,9 +709,7 @@ select wal_bytes as wal_bytes_before from pg_stat_wal; select wal_bytes as backend_wal_bytes_before from - pg_stat_get_backend_wal( - pg_backend_pid() - ); + pg_stat_get_backend_wal(pg_backend_pid()); create temporary table test_stats_temp as select 17; @@ -767,19 +724,14 @@ select pg_stat_force_next_flush(); select wal_bytes > 'backend_wal_bytes_before' from - pg_stat_get_backend_wal( - pg_backend_pid() - ); + pg_stat_get_backend_wal(pg_backend_pid()); select - (current_schemas(true))[1] = - 'pg_temp_' || cast(beid as text) - as match + (current_schemas(true))[1] = 'pg_temp_' || cast(beid as text) as match from pg_stat_get_backend_idset() as beid where - pg_stat_get_backend_pid(beid) = - pg_backend_pid(); + pg_stat_get_backend_pid(beid) = pg_backend_pid(); select stats_reset as slru_commit_ts_reset_ts @@ -798,9 +750,7 @@ where select pg_stat_reset_slru('commit_timestamp'); select - stats_reset > - cast('slru_commit_ts_reset_ts' - as timestamp with time zone) + stats_reset > cast('slru_commit_ts_reset_ts' as timestamptz) from pg_stat_slru where @@ -816,18 +766,14 @@ where select pg_stat_reset_slru(); select - stats_reset > - cast('slru_commit_ts_reset_ts' - as timestamp with time zone) + stats_reset > cast('slru_commit_ts_reset_ts' as timestamptz) from pg_stat_slru where name = 'commit_timestamp'; select - stats_reset > - cast('slru_notify_reset_ts' - as timestamp with time zone) + stats_reset > cast('slru_notify_reset_ts' as timestamptz) from pg_stat_slru where @@ -838,9 +784,7 @@ select stats_reset as archiver_reset_ts from pg_stat_archiver; select pg_stat_reset_shared('archiver'); select - stats_reset > - cast('archiver_reset_ts' - as timestamp with time zone) + stats_reset > cast('archiver_reset_ts' as timestamptz) from pg_stat_archiver; @@ -849,9 +793,7 @@ select stats_reset as bgwriter_reset_ts from pg_stat_bgwriter; select pg_stat_reset_shared('bgwriter'); select - stats_reset > - cast('bgwriter_reset_ts' - as timestamp with time zone) + stats_reset > cast('bgwriter_reset_ts' as timestamptz) from pg_stat_bgwriter; @@ -860,9 +802,7 @@ select stats_reset as checkpointer_reset_ts from pg_stat_checkpointer; select pg_stat_reset_shared('checkpointer'); select - stats_reset > - cast('checkpointer_reset_ts' - as timestamp with time zone) + stats_reset > cast('checkpointer_reset_ts' as timestamptz) from pg_stat_checkpointer; @@ -871,20 +811,16 @@ select stats_reset as recovery_prefetch_reset_ts from pg_stat_recovery_prefetch; select pg_stat_reset_shared('recovery_prefetch'); select - stats_reset > - cast('recovery_prefetch_reset_ts' - as timestamp with time zone) + stats_reset > cast('recovery_prefetch_reset_ts' as timestamptz) from pg_stat_recovery_prefetch; -select MAX(stats_reset) as slru_reset_ts from pg_stat_slru; +select max(stats_reset) as slru_reset_ts from pg_stat_slru; select pg_stat_reset_shared('slru'); select - MAX(stats_reset) > - cast('slru_reset_ts' - as timestamp with time zone) + max(stats_reset) > cast('slru_reset_ts' as timestamptz) from pg_stat_slru; @@ -892,12 +828,7 @@ select stats_reset as wal_reset_ts from pg_stat_wal; select pg_stat_reset_shared('wal'); -select - stats_reset > - cast('wal_reset_ts' - as timestamp with time zone) -from - pg_stat_wal; +select stats_reset > cast('wal_reset_ts' as timestamptz) from pg_stat_wal; select pg_stat_reset_shared('unknown'); @@ -913,9 +844,7 @@ where select pg_stat_reset(); select - stats_reset > - cast('db_reset_ts' - as timestamp with time zone) + stats_reset > cast('db_reset_ts' as timestamptz) from pg_stat_database where @@ -929,7 +858,7 @@ select pg_stat_get_snapshot_timestamp(); select pg_stat_get_function_calls(0); -select pg_stat_get_snapshot_timestamp() >= NOW(); +select pg_stat_get_snapshot_timestamp() >= now(); select pg_stat_clear_snapshot(); @@ -953,7 +882,7 @@ select pg_stat_get_function_calls(0); select pg_stat_get_snapshot_timestamp() is not null as snapshot_ok; -set local stats_fetch_consistency = 'none'; +set local stats_fetch_consistency = none; select pg_stat_get_snapshot_timestamp() is not null as snapshot_ok; @@ -973,7 +902,7 @@ select pg_stat_have_stats('database', 'dboid', 0); create table stats_test_tab1 as select generate_series(1, 10) as a; -create index "stats_test_idx1" on stats_test_tab1 using btree (a); +create index stats_test_idx1 on stats_test_tab1 using btree (a); select cast(cast('stats_test_idx1' as regclass) as oid) as stats_test_idx1_oid; @@ -991,7 +920,7 @@ select pg_stat_have_stats('relation', 'dboid', 'stats_test_idx1_oid'); begin; -create index "stats_test_idx1" on stats_test_tab1 using btree (a); +create index stats_test_idx1 on stats_test_tab1 using btree (a); select cast(cast('stats_test_idx1' as regclass) as oid) as stats_test_idx1_oid; @@ -1003,7 +932,7 @@ rollback; select pg_stat_have_stats('relation', 'dboid', 'stats_test_idx1_oid'); -create index "stats_test_idx1" on stats_test_tab1 using btree (a); +create index stats_test_idx1 on stats_test_tab1 using btree (a); select cast(cast('stats_test_idx1' as regclass) as oid) as stats_test_idx1_oid; @@ -1011,7 +940,7 @@ select a from stats_test_tab1 where a = 3; select pg_stat_have_stats('relation', 'dboid', 'stats_test_idx1_oid'); -reindex (CONCURRENTLY) index stats_test_idx1; +reindex (concurrently) index stats_test_idx1; select pg_stat_have_stats('relation', 'dboid', 'stats_test_idx1_oid'); @@ -1043,42 +972,38 @@ where backend_type = 'checkpointer'; select - SUM(extends) - as io_sum_shared_before_extends + sum(extends) as io_sum_shared_before_extends from pg_stat_io where - context = 'normal' and - object = 'relation'; + context = 'normal' and object = 'relation'; select - SUM(extends) - as my_io_sum_shared_before_extends + sum(extends) as my_io_sum_shared_before_extends from pg_stat_get_backend_io(pg_backend_pid()) where - context = 'normal' and - object = 'relation'; + context = 'normal' and object = 'relation'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_io where object = 'relation'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_get_backend_io(pg_backend_pid()) where object = 'relation'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_io where @@ -1091,24 +1016,20 @@ insert into test_io_shared select i from generate_series(1, 100) as i; select pg_stat_force_next_flush(); select - SUM(extends) - as io_sum_shared_after_extends + sum(extends) as io_sum_shared_after_extends from pg_stat_io where - context = 'normal' and - object = 'relation'; + context = 'normal' and object = 'relation'; select 'io_sum_shared_after_extends' > 'io_sum_shared_before_extends'; select - SUM(extends) - as my_io_sum_shared_after_extends + sum(extends) as my_io_sum_shared_after_extends from pg_stat_get_backend_io(pg_backend_pid()) where - context = 'normal' and - object = 'relation'; + context = 'normal' and object = 'relation'; select 'my_io_sum_shared_after_extends' > 'my_io_sum_shared_before_extends'; @@ -1117,8 +1038,8 @@ checkpoint; checkpoint; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_io where @@ -1128,12 +1049,11 @@ select 'io_sum_shared_after_writes' > 'io_sum_shared_before_writes'; select current_setting('fsync') = 'off' or - 'io_sum_shared_after_fsyncs' > - 'io_sum_shared_before_fsyncs'; + 'io_sum_shared_after_fsyncs' > 'io_sum_shared_before_fsyncs'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_get_backend_io(pg_backend_pid()) where @@ -1143,12 +1063,11 @@ select 'my_io_sum_shared_after_writes' >= 'my_io_sum_shared_before_writes'; select current_setting('fsync') = 'off' or - 'my_io_sum_shared_after_fsyncs' >= - 'my_io_sum_shared_before_fsyncs'; + 'my_io_sum_shared_after_fsyncs' >= 'my_io_sum_shared_before_fsyncs'; select - SUM(writes) as writes, - SUM(fsyncs) as fsyncs + sum(writes) as writes, + sum(fsyncs) as fsyncs from pg_stat_io where @@ -1160,49 +1079,42 @@ select 'io_sum_wal_normal_after_writes' > 'io_sum_wal_normal_before_writes'; select current_setting('fsync') = 'off' or - current_setting('wal_sync_method') - in ( - 'open_sync', 'open_datasync' - ) or - 'io_sum_wal_normal_after_fsyncs' > - 'io_sum_wal_normal_before_fsyncs'; + current_setting('wal_sync_method') in ('open_sync', 'open_datasync') or + 'io_sum_wal_normal_after_fsyncs' > 'io_sum_wal_normal_before_fsyncs'; select - SUM(reads) as io_sum_shared_before_reads + sum(reads) as io_sum_shared_before_reads from pg_stat_io where - context = 'normal' and - object = 'relation'; + context = 'normal' and object = 'relation'; begin; alter table test_io_shared set tablespace regress_tblspace; -select COUNT(*) from test_io_shared; +select count(*) from test_io_shared; commit; select pg_stat_force_next_flush(); select - SUM(reads) as io_sum_shared_after_reads + sum(reads) as io_sum_shared_after_reads from pg_stat_io where - context = 'normal' and - object = 'relation'; + context = 'normal' and object = 'relation'; select 'io_sum_shared_after_reads' > 'io_sum_shared_before_reads'; select - SUM(hits) as io_sum_shared_before_hits + sum(hits) as io_sum_shared_before_hits from pg_stat_io where - context = 'normal' and - object = 'relation'; + context = 'normal' and object = 'relation'; begin; @@ -1215,32 +1127,25 @@ set local enable_hashjoin = off; set local enable_material = off; select - COUNT(*) + count(*) from - test_io_shared as t1 - inner join - test_io_shared as t2 - using ("a"); + test_io_shared as t1 inner join test_io_shared as t2 using (a); select - COUNT(*) + count(*) from - test_io_shared as t1 - inner join - test_io_shared as t2 - using ("a"); + test_io_shared as t1 inner join test_io_shared as t2 using (a); commit; select pg_stat_force_next_flush(); select - SUM(hits) as io_sum_shared_after_hits + sum(hits) as io_sum_shared_after_hits from pg_stat_io where - context = 'normal' and - object = 'relation'; + context = 'normal' and object = 'relation'; select 'io_sum_shared_after_hits' > 'io_sum_shared_before_hits'; @@ -1254,58 +1159,48 @@ create temporary table test_io_local ( ); select - SUM(extends) as extends, - SUM(evictions) as evictions, - SUM(writes) as writes + sum(extends) as extends, + sum(evictions) as evictions, + sum(writes) as writes from pg_stat_io where - context = 'normal' and - object = 'temp relation'; + context = 'normal' and object = 'temp relation'; insert into test_io_local -select - generate_series(1, 5000) as id, - repeat('a', 200); +select generate_series(1, 5000) as id, repeat('a', 200); select pg_relation_size('test_io_local') / - cast(current_setting('block_size') - as bigint) > + cast(current_setting('block_size') as int8) > 100; select - SUM(reads) as io_sum_local_before_reads + sum(reads) as io_sum_local_before_reads from pg_stat_io where - context = 'normal' and - object = 'temp relation'; + context = 'normal' and object = 'temp relation'; -select COUNT(*) from test_io_local; +select count(*) from test_io_local; select pg_stat_force_next_flush(); select - SUM(evictions) as evictions, - SUM(reads) as reads, - SUM(writes) as writes, - SUM(extends) as extends + sum(evictions) as evictions, + sum(reads) as reads, + sum(writes) as writes, + sum(extends) as extends from pg_stat_io where - context = 'normal' and - object = 'temp relation'; + context = 'normal' and object = 'temp relation'; select - 'io_sum_local_after_evictions' > - 'io_sum_local_before_evictions', - 'io_sum_local_after_reads' > - 'io_sum_local_before_reads', - 'io_sum_local_after_writes' > - 'io_sum_local_before_writes', - 'io_sum_local_after_extends' > - 'io_sum_local_before_extends'; + 'io_sum_local_after_evictions' > 'io_sum_local_before_evictions', + 'io_sum_local_after_reads' > 'io_sum_local_before_reads', + 'io_sum_local_after_writes' > 'io_sum_local_before_writes', + 'io_sum_local_after_extends' > 'io_sum_local_before_extends'; alter table test_io_local set tablespace regress_tblspace; @@ -1313,13 +1208,11 @@ alter table test_io_local select pg_stat_force_next_flush(); select - SUM(writes) - as io_sum_local_new_tblspc_writes + sum(writes) as io_sum_local_new_tblspc_writes from pg_stat_io where - context = 'normal' and - object = 'temp relation'; + context = 'normal' and object = 'temp relation'; select 'io_sum_local_new_tblspc_writes' > 'io_sum_local_after_writes'; @@ -1328,9 +1221,9 @@ reset temp_buffers; set wal_skip_threshold = '1 kB'; select - SUM(reuses) as reuses, - SUM(reads) as reads, - SUM(evictions) as evictions + sum(reuses) as reuses, + sum(reads) as reads, + sum(evictions) as evictions from pg_stat_io where @@ -1344,16 +1237,16 @@ with (autovacuum_enabled = 'false'); insert into test_io_vac_strategy select i, i from generate_series(1, 4500) as i; -vacuum (FULL) test_io_vac_strategy; +vacuum (full) test_io_vac_strategy; -vacuum (PARALLEL 0, BUFFER_USAGE_LIMIT 128) test_io_vac_strategy; +vacuum (parallel 0, buffer_usage_limit 128) test_io_vac_strategy; select pg_stat_force_next_flush(); select - SUM(reuses) as reuses, - SUM(reads) as reads, - SUM(evictions) as evictions + sum(reuses) as reuses, + sum(reads) as reads, + sum(evictions) as evictions from pg_stat_io where @@ -1362,16 +1255,13 @@ where select 'io_sum_vac_strategy_after_reads' > 'io_sum_vac_strategy_before_reads'; select - 'io_sum_vac_strategy_after_reuses' + - 'io_sum_vac_strategy_after_evictions' > - 'io_sum_vac_strategy_before_reuses' + - 'io_sum_vac_strategy_before_evictions'; + 'io_sum_vac_strategy_after_reuses' + 'io_sum_vac_strategy_after_evictions' > + 'io_sum_vac_strategy_before_reuses' + 'io_sum_vac_strategy_before_evictions'; reset wal_skip_threshold; select - SUM(extends) - as io_sum_bulkwrite_strategy_extends_before + sum(extends) as io_sum_bulkwrite_strategy_extends_before from pg_stat_io where @@ -1379,16 +1269,12 @@ where create table test_io_bulkwrite_strategy as - select - i - from - generate_series(1, 100) as i; + select i from generate_series(1, 100) as i; select pg_stat_force_next_flush(); select - SUM(extends) - as io_sum_bulkwrite_strategy_extends_after + sum(extends) as io_sum_bulkwrite_strategy_extends_after from pg_stat_io where @@ -1401,25 +1287,19 @@ select select pg_stat_have_stats('io', 0, 0); select - SUM(evictions) + SUM(reuses) + - SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + + sum(writes) + + sum(writebacks) + + sum(hits) as io_stats_pre_reset from pg_stat_io; select - SUM(evictions) + SUM(reuses) + - SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + + sum(writes) + + sum(writebacks) + + sum(hits) as my_io_stats_pre_reset from pg_stat_get_backend_io(pg_backend_pid()); @@ -1427,13 +1307,10 @@ from select pg_stat_reset_shared('io'); select - SUM(evictions) + SUM(reuses) + - SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + + sum(writes) + + sum(writebacks) + + sum(hits) as io_stats_post_reset from pg_stat_io; @@ -1441,13 +1318,10 @@ from select 'io_stats_post_reset' < 'io_stats_pre_reset'; select - SUM(evictions) + SUM(reuses) + - SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + + sum(writes) + + sum(writebacks) + + sum(hits) as my_io_stats_post_reset from pg_stat_get_backend_io(pg_backend_pid()); @@ -1457,13 +1331,10 @@ select 'my_io_stats_pre_reset' <= 'my_io_stats_post_reset'; select pg_stat_reset_backend_stats(pg_backend_pid()); select - SUM(evictions) + SUM(reuses) + - SUM(extends) + - SUM(fsyncs) + - SUM(reads) + - SUM(writes) + - SUM(writebacks) + - SUM(hits) + sum(evictions) + sum(reuses) + sum(extends) + sum(fsyncs) + sum(reads) + + sum(writes) + + sum(writebacks) + + sum(hits) as my_io_stats_post_backend_reset from pg_stat_get_backend_io(pg_backend_pid()); @@ -1480,19 +1351,16 @@ create table brin_hot ( id int primary key, val int not null ) -with ( - autovacuum_enabled = off, - fillfactor = 70 -); +with (autovacuum_enabled = off, fillfactor = 70); insert into brin_hot select *, 0 from generate_series(1, 235); -create index "val_brin" on brin_hot using brin (val); +create index val_brin on brin_hot using brin (val); create function wait_for_hot_stats() returns void language plpgsql -as $function$ +as $$ DECLARE start_time timestamptz := clock_timestamp(); updated bool; @@ -1511,17 +1379,14 @@ BEGIN RAISE log 'wait_for_hot_stats delayed % seconds', EXTRACT(epoch FROM clock_timestamp() - start_time); END -$function$; +$$; update brin_hot set val = -3 where id = 42; select wait_for_hot_stats(); select - pg_stat_get_tuples_hot_updated( - cast(cast('brin_hot' as regclass) - as oid) - ); + pg_stat_get_tuples_hot_updated(cast(cast('brin_hot' as regclass) as oid)); drop table brin_hot; @@ -1534,26 +1399,19 @@ create table brin_hot_2 ( insert into brin_hot_2 values (1, 100); -create index -on brin_hot_2 -using brin -( - b -) -where - a = 2; +create index on brin_hot_2 using brin (b) where a = 2; update brin_hot_2 set a = 2; select * from brin_hot_2 where a = 2 and b = 100; -select COUNT(*) from brin_hot_2 where a = 2 and b = 100; +select count(*) from brin_hot_2 where a = 2 and b = 100; set enable_seqscan = off; select * from brin_hot_2 where a = 2 and b = 100; -select COUNT(*) from brin_hot_2 where a = 2 and b = 100; +select count(*) from brin_hot_2 where a = 2 and b = 100; drop table brin_hot_2; @@ -1565,29 +1423,20 @@ with (fillfactor = 10); insert into brin_hot_3 select 1, repeat(' ', 500) from generate_series(1, 20); -create index -on brin_hot_3 -using brin -( - a -) -with (pages_per_range = 1); +create index on brin_hot_3 using brin (a) with (pages_per_range = 1); update brin_hot_3 set a = 2; select * from brin_hot_3 where a = 2; -select COUNT(*) from brin_hot_3 where a = 2; +select count(*) from brin_hot_3 where a = 2; drop table brin_hot_3; set enable_seqscan = 'on'; create table table_fillfactor (n char(1000)) -with ( - fillfactor = 10, - autovacuum_enabled = off -); +with (fillfactor = 10, autovacuum_enabled = off); insert into table_fillfactor select 'x' from generate_series(1, 1000); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_100.snap index 21fe6178d..17ea5aeff 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_100.snap @@ -8,7 +8,7 @@ returns table ( actual int ) language plpgsql -as $function$ +as $$ declare ln text; tmp text[]; @@ -24,7 +24,7 @@ begin end if; end loop; end; -$function$; +$$; create table ext_stats_test ( x text, @@ -32,20 +32,20 @@ create table ext_stats_test ( z int ); -create statistics tst on "a", "b" from nonexistent; +create statistics tst on a, b from nonexistent; -create statistics tst on "a", "b" from ext_stats_test; +create statistics tst on a, b from ext_stats_test; -create statistics tst on "x", "x", "y" from ext_stats_test; +create statistics tst on x, x, y from ext_stats_test; -create statistics tst on "x", "x", "y", "x", "x", "y", "x", "x", "y" from ext_stats_test; +create statistics tst on x, x, y, x, x, y, x, x, y from ext_stats_test; create statistics tst -on "x", -"x", -"y", -"x", -"x", +on x, +x, +y, +x, +x, (x || 'x'), (y + 1), (x || 'x'), @@ -65,21 +65,21 @@ on (x || 'x'), (y + 1) from ext_stats_test; -create statistics tst on (x || 'x'), (x || 'x'), "y" from ext_stats_test; +create statistics tst on (x || 'x'), (x || 'x'), y from ext_stats_test; -create statistics tst (unrecognized) on "x", "y" from ext_stats_test; +create statistics tst (unrecognized) on x, y from ext_stats_test; -create statistics tst on "a" from (values (x)) as foo; +create statistics tst on a from (values (x)) as foo; -create statistics tst on "a" from foo natural join bar; +create statistics tst on a from foo natural join bar; -create statistics tst on "a" from (select * from ext_stats_test) as foo; +create statistics tst on a from (select * from ext_stats_test) as foo; -create statistics tst on "a" from ext_stats_test as s tablesample system (x); +create statistics tst on a from ext_stats_test as s tablesample system (x); -create statistics tst on "a" from xmltable( 'foo' passing 'bar' columns a text); +create statistics tst on a from xmltable( 'foo' passing 'bar' columns a text); -create statistics tst on "a" from json_table( cast('123' as jsonb), '$' columns (item int ) ); +create statistics tst on a from json_table( cast('123' as jsonb), '$' columns (item int ) ); create function tftest(int) returns table ( @@ -89,11 +89,11 @@ returns table ( language sql immutable strict -as $function$ +as $$ SELECT $1, $1+i FROM generate_series(1,5) g(i); -$function$; +$$; -create statistics alt_stat2 on "a" from tftest(1); +create statistics alt_stat2 on a from tftest(1); drop function tftest; @@ -101,23 +101,23 @@ create statistics tst on (y) from ext_stats_test; drop table ext_stats_test; -create statistics tst on "z" from ext_stats_test1; +create statistics tst on z from ext_stats_test1; create statistics tst on (z) from ext_stats_test1; create statistics tst on (z + 1) from ext_stats_test1; -create statistics tst (ndistinct) on "z" from ext_stats_test1; +create statistics tst (ndistinct) on z from ext_stats_test1; -create statistics tst on "tableoid" from ext_stats_test1; +create statistics tst on tableoid from ext_stats_test1; create statistics tst on (tableoid) from ext_stats_test1; create statistics tst on (cast(tableoid as int) + 1) from ext_stats_test1; -create statistics tst (ndistinct) on "xmin" from ext_stats_test1; +create statistics tst (ndistinct) on xmin from ext_stats_test1; -create statistics tst (ndistinct) on "w" from ext_stats_test1; +create statistics tst (ndistinct) on w from ext_stats_test1; drop table ext_stats_test1; @@ -127,7 +127,7 @@ create table ab1 ( c int ); -create statistics if not exists ab1_a_b_stats on "a", "b" from ab1; +create statistics if not exists ab1_a_b_stats on a, b from ab1; comment on statistics ab1_a_b_stats is 'new comment'; @@ -145,23 +145,23 @@ reset session_authorization; drop role regress_stats_ext; -create statistics if not exists ab1_a_b_stats on "a", "b" from ab1; +create statistics if not exists ab1_a_b_stats on a, b from ab1; drop statistics ab1_a_b_stats; -create schema "regress_schema_2"; +create schema regress_schema_2; -create statistics regress_schema_2.ab1_a_b_stats on "a", "b" from ab1; +create statistics regress_schema_2.ab1_a_b_stats on a, b from ab1; select pg_get_statisticsobjdef(oid) from pg_statistic_ext where stxname = 'ab1_a_b_stats'; drop statistics regress_schema_2.ab1_a_b_stats; -create statistics ab1_b_c_stats on "b", "c" from ab1; +create statistics ab1_b_c_stats on b, c from ab1; -create statistics ab1_a_b_c_stats on "a", "b", "c" from ab1; +create statistics ab1_a_b_c_stats on a, b, c from ab1; -create statistics ab1_b_a_stats on "b", "a" from ab1; +create statistics ab1_b_a_stats on b, a from ab1; alter table ab1 drop column a; @@ -182,7 +182,7 @@ alter table ab1 insert into ab1 select a, a % 23 from generate_series(1, 1000) as a; -create statistics ab1_a_b_stats on "a", "b" from ab1; +create statistics ab1_a_b_stats on a, b from ab1; analyze ab1; @@ -200,10 +200,7 @@ select stxdmcv, stxdinherit from - pg_statistic_ext as s - left outer join - pg_statistic_ext_data as d - on d.stxoid = s.oid + pg_statistic_ext as s left outer join pg_statistic_ext_data as d on d.stxoid = s.oid where s.stxname = 'ab1_a_b_stats'; @@ -229,7 +226,7 @@ inherits (ab1); insert into ab1 values (1, 1); -create statistics ab1_a_b_stats on "a", "b" from ab1; +create statistics ab1_a_b_stats on a, b from ab1; analyze ab1; @@ -252,15 +249,15 @@ insert into stxdinh1 select mod(a, 100), mod(a, 100) from generate_series(0, 999 insert into stxdinh2 select mod(a, 100), mod(a, 100) from generate_series(0, 999) as a; -vacuum (ANALYZE) stxdinh, stxdinh1, stxdinh2; +vacuum (analyze) stxdinh, stxdinh1, stxdinh2; select * from check_estimated_rows('SELECT a, b FROM stxdinh* GROUP BY 1, 2'); select * from check_estimated_rows('SELECT a, b FROM stxdinh* WHERE a = 0 AND b = 0'); -create statistics stxdinh on "a", "b" from stxdinh; +create statistics stxdinh on a, b from stxdinh; -vacuum (ANALYZE) stxdinh, stxdinh1, stxdinh2; +vacuum (analyze) stxdinh, stxdinh1, stxdinh2; select * from check_estimated_rows('SELECT a, b FROM stxdinh* GROUP BY 1, 2'); @@ -283,9 +280,9 @@ create table stxdinp1 partition of stxdinp for values from (1) to (100); insert into stxdinp select 1, a / 100, a / 100 from generate_series(1, 999) as a; -create statistics stxdinp on (a + 1), "a", "b" from stxdinp; +create statistics stxdinp on (a + 1), a, b from stxdinp; -vacuum (ANALYZE) stxdinp; +vacuum (analyze) stxdinp; select 1 from pg_statistic_ext where stxrelid = cast('stxdinp' as regclass); @@ -299,7 +296,7 @@ create table ab1 ( a int, b int, c timestamp, - d timestamp with time zone + d timestamptz ); create statistics ab1_exprstat_1 on (a + b) from ab1; @@ -308,7 +305,7 @@ create statistics ab1_exprstat_2 on (a + b) from ab1; select stxkind from pg_statistic_ext where stxname = 'ab1_exprstat_2'; -create statistics ab1_exprstat_3 on (a + b), "a" from ab1; +create statistics ab1_exprstat_3 on (a + b), a from ab1; select stxkind from pg_statistic_ext where stxname = 'ab1_exprstat_3'; @@ -316,16 +313,14 @@ create statistics ab1_exprstat_4 on (date_trunc('day', d)) from ab1; create statistics ab1_exprstat_5 on (date_trunc('day', c)) from ab1; -create statistics ab1_exprstat_6 on (case a when 1 then true else false end), "b" from ab1; +create statistics ab1_exprstat_6 on (case a when 1 then true else false end), b from ab1; insert into ab1 select x / 10, x / 3, - cast('2020-10-01' as timestamp) + - x * cast('1 day' as interval), - cast('2020-10-01' as timestamp with time zone) + - x * cast('1 day' as interval) + cast('2020-10-01' as timestamp) + x * cast('1 day' as interval), + cast('2020-10-01' as timestamptz) + x * cast('1 day' as interval) from generate_series(1, 100) as x; @@ -334,13 +329,11 @@ analyze ab1; select * from - check_estimated_rows( - 'SELECT * FROM ab1 WHERE (case a when 1 then true else false end) AND b=2' - ); + check_estimated_rows('SELECT * FROM ab1 WHERE (case a when 1 then true else false end) AND b=2'); drop table ab1; -create schema "tststats"; +create schema tststats; create table tststats.t ( a int, @@ -348,7 +341,7 @@ create table tststats.t ( c text ); -create index "ti" on tststats.t using btree (a, b); +create index ti on tststats.t using btree (a, b); create sequence tststats.s; @@ -374,26 +367,25 @@ partition by range(a, b); create table tststats.pt1 partition of tststats.pt for values from (-10, -10) to (10, 10); -create statistics tststats.s1 on "a", "b" from tststats.t; +create statistics tststats.s1 on a, b from tststats.t; -create statistics tststats.s2 on "a", "b" from tststats.ti; +create statistics tststats.s2 on a, b from tststats.ti; -create statistics tststats.s3 on "a", "b" from tststats.s; +create statistics tststats.s3 on a, b from tststats.s; -create statistics tststats.s4 on "a", "b" from tststats.v; +create statistics tststats.s4 on a, b from tststats.v; -create statistics tststats.s5 on "a", "b" from tststats.mv; +create statistics tststats.s5 on a, b from tststats.mv; -create statistics tststats.s6 on "a", "b" from tststats.ty; +create statistics tststats.s6 on a, b from tststats.ty; -create statistics tststats.s7 on "a", "b" from tststats.f; +create statistics tststats.s7 on a, b from tststats.f; -create statistics tststats.s8 on "a", "b" from tststats.pt; +create statistics tststats.s8 on a, b from tststats.pt; -create statistics tststats.s9 on "a", "b" from tststats.pt1; +create statistics tststats.s9 on a, b from tststats.pt1; -do -$do$ +do $$ DECLARE relname text := reltoastrelid::regclass FROM pg_class WHERE oid = 'tststats.t'::regclass; BEGIN @@ -401,7 +393,7 @@ BEGIN EXCEPTION WHEN wrong_object_type THEN RAISE NOTICE 'stats on toast table not created'; END; -$do$; +$$; drop schema tststats cascade; @@ -447,7 +439,7 @@ select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a+1 select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (a+1), (b+100)'); -create statistics s10 on "a", "b", "c" from ndistinct; +create statistics s10 on a, b, c from ndistinct; analyze ndistinct; @@ -458,8 +450,7 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY ctid, a, b'); @@ -501,8 +492,7 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); @@ -531,8 +521,7 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); @@ -569,8 +558,7 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a+1), (b+100)'); @@ -586,7 +574,7 @@ select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, ( select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (2*c)'); -create statistics s10 (ndistinct) on "a", "b", (2 * c) from ndistinct; +create statistics s10 (ndistinct) on a, b, (2 * c) from ndistinct; analyze ndistinct; @@ -597,8 +585,7 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); @@ -611,13 +598,7 @@ drop statistics s10; truncate ndistinct; insert into ndistinct (a, b, c, d) -select - mod(i, 3), - mod(i, 9), - mod(i, 5), - mod(i, 20) -from - generate_series(1, 1000) as s (i); +select mod(i, 3), mod(i, 9), mod(i, 5), mod(i, 20) from generate_series(1, 1000) as s (i); analyze ndistinct; @@ -635,9 +616,9 @@ select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1), c, (d - 1)'); -create statistics s11 (ndistinct) on "a", "b" from ndistinct; +create statistics s11 (ndistinct) on a, b from ndistinct; -create statistics s12 (ndistinct) on "c", "d" from ndistinct; +create statistics s12 (ndistinct) on c, d from ndistinct; analyze ndistinct; @@ -677,7 +658,7 @@ select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, ( drop statistics s12; -create statistics s12 (ndistinct) on "c", "d", (c * 10), (d - 1) from ndistinct; +create statistics s12 (ndistinct) on c, d, (c * 10), (d - 1) from ndistinct; analyze ndistinct; @@ -697,7 +678,7 @@ select * from check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, ( drop statistics s11; -create statistics s11 (ndistinct) on "a", "b", (a * 5), (b + 1) from ndistinct; +create statistics s11 (ndistinct) on a, b, (a * 5), (b + 1) from ndistinct; analyze ndistinct; @@ -719,9 +700,9 @@ drop statistics s11; drop statistics s12; -create statistics s11 (ndistinct) on "a", "b", (a * 5), (b + 1) from ndistinct; +create statistics s11 (ndistinct) on a, b, (a * 5), (b + 1) from ndistinct; -create statistics s12 (ndistinct) on "a", (b + 1), (c * 10) from ndistinct; +create statistics s12 (ndistinct) on a, (b + 1), (c * 10) from ndistinct; analyze ndistinct; @@ -754,65 +735,45 @@ create table functional_dependencies ( ) with (autovacuum_enabled = off); -create index "fdeps_ab_idx" on functional_dependencies using btree (a, b); +create index fdeps_ab_idx on functional_dependencies using btree (a, b); -create index "fdeps_abc_idx" on functional_dependencies using btree (a, b, c); +create index fdeps_abc_idx on functional_dependencies using btree (a, b, c); insert into functional_dependencies (a, b, c, filler1) -select - mod(i, 5), - mod(i, 7), - mod(i, 11), - i -from - generate_series(1, 1000) as s (i); +select mod(i, 5), mod(i, 7), mod(i, 11), i from generate_series(1, 1000) as s (i); analyze functional_dependencies; select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'''); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1'); -create statistics func_deps_stat (dependencies) on "a", "b", "c" from functional_dependencies; +create statistics func_deps_stat (dependencies) on a, b, c from functional_dependencies; analyze functional_dependencies; select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'''); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1'); truncate functional_dependencies; drop statistics func_deps_stat; insert into functional_dependencies (a, b, c, filler1) -select - i, - i, - i, - i -from - generate_series(1, 5000) as s (i); +select i, i, i, i from generate_series(1, 5000) as s (i); analyze functional_dependencies; @@ -858,36 +819,24 @@ truncate functional_dependencies; drop statistics func_deps_stat; insert into functional_dependencies (a, b, c, filler1) -select - mod(i, 100), - mod(i, 50), - mod(i, 25), - i -from - generate_series(1, 5000) as s (i); +select mod(i, 100), mod(i, 50), mod(i, 25), i from generate_series(1, 5000) as s (i); analyze functional_dependencies; select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'''); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1'); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a IN (1, 51) AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a IN (1, 51) AND b = ''1'''); select * @@ -1043,7 +992,7 @@ from 'SELECT * FROM functional_dependencies WHERE a IN (1, 2, 51, 52) AND b = ALL (ARRAY[''1'', ''2''])' ); -create statistics func_deps_stat (dependencies) on "a", "b", "c" from functional_dependencies; +create statistics func_deps_stat (dependencies) on a, b, c from functional_dependencies; analyze functional_dependencies; @@ -1052,23 +1001,17 @@ select dependencies from pg_stats_ext where statistics_name = 'func_deps_stat'; select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'''); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1'); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a IN (1, 51) AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a IN (1, 51) AND b = ''1'''); select * @@ -1230,18 +1173,14 @@ alter table functional_dependencies select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1'); analyze functional_dependencies; select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1' - ); + check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1'); drop statistics func_deps_stat; @@ -1615,36 +1554,24 @@ create table functional_dependencies_multi ( with (autovacuum_enabled = off); insert into functional_dependencies_multi (a, b, c, d) -select - mod(i, 7), - mod(i, 7), - mod(i, 11), - mod(i, 11) -from - generate_series(1, 5000) as s (i); +select mod(i, 7), mod(i, 7), mod(i, 11), mod(i, 11) from generate_series(1, 5000) as s (i); analyze functional_dependencies_multi; select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies_multi WHERE a = 0 AND b = 0' - ); + check_estimated_rows('SELECT * FROM functional_dependencies_multi WHERE a = 0 AND b = 0'); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies_multi WHERE 0 = a AND 0 = b' - ); + check_estimated_rows('SELECT * FROM functional_dependencies_multi WHERE 0 = a AND 0 = b'); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies_multi WHERE c = 0 AND d = 0' - ); + check_estimated_rows('SELECT * FROM functional_dependencies_multi WHERE c = 0 AND d = 0'); select * @@ -1662,14 +1589,14 @@ from create statistics functional_dependencies_multi_1 (dependencies) -on "a", -"b" +on a, +b from functional_dependencies_multi; create statistics functional_dependencies_multi_2 (dependencies) -on "c", -"d" +on c, +d from functional_dependencies_multi; analyze functional_dependencies_multi; @@ -1677,23 +1604,17 @@ analyze functional_dependencies_multi; select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies_multi WHERE a = 0 AND b = 0' - ); + check_estimated_rows('SELECT * FROM functional_dependencies_multi WHERE a = 0 AND b = 0'); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies_multi WHERE 0 = a AND 0 = b' - ); + check_estimated_rows('SELECT * FROM functional_dependencies_multi WHERE 0 = a AND 0 = b'); select * from - check_estimated_rows( - 'SELECT * FROM functional_dependencies_multi WHERE c = 0 AND d = 0' - ); + check_estimated_rows('SELECT * FROM functional_dependencies_multi WHERE c = 0 AND d = 0'); select * @@ -1724,13 +1645,7 @@ create table mcv_lists ( with (autovacuum_enabled = off); insert into mcv_lists (a, b, c, filler1) -select - mod(i, 37), - mod(i, 41), - mod(i, 43), - mod(i, 47) -from - generate_series(1, 5000) as s (i); +select mod(i, 37), mod(i, 41), mod(i, 43), mod(i, 47) from generate_series(1, 5000) as s (i); analyze mcv_lists; @@ -1738,7 +1653,7 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'' AND c = 1'); -create statistics mcv_lists_stats (mcv) on "a", "b", "c" from mcv_lists; +create statistics mcv_lists_stats (mcv) on a, b, c from mcv_lists; analyze mcv_lists; @@ -1757,9 +1672,7 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE mod(a,7) = 1 AND mod(b::int,11) = 1' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,7) = 1 AND mod(b::int,11) = 1'); select * @@ -1780,9 +1693,7 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE mod(a,7) = 1 AND mod(b::int,11) = 1' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,7) = 1 AND mod(b::int,11) = 1'); select * @@ -1828,16 +1739,12 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a < 5 AND ''1' select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a <= 4 AND b <= ''0'' AND c <= 4' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a <= 4 AND b <= ''0'' AND c <= 4'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 4 >= a AND ''0'' >= b AND 4 >= c' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 4 >= a AND ''0'' >= b AND 4 >= c'); select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 OR b = ''1'' OR c = 1'); @@ -1921,11 +1828,9 @@ from select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a = ANY (ARRAY[4,5]) AND 4 = ANY(ia)' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a = ANY (ARRAY[4,5]) AND 4 = ANY(ia)'); -create statistics mcv_lists_stats (mcv) on "a", "b", "c", "ia" from mcv_lists; +create statistics mcv_lists_stats (mcv) on a, b, c, ia from mcv_lists; analyze mcv_lists; @@ -1950,16 +1855,12 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a < 5 AND ''1' select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a <= 4 AND b <= ''0'' AND c <= 4' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a <= 4 AND b <= ''0'' AND c <= 4'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 4 >= a AND ''0'' >= b AND 4 >= c' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 4 >= a AND ''0'' >= b AND 4 >= c'); select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 OR b = ''1'' OR c = 1'); @@ -2050,9 +1951,7 @@ from select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a = ANY (ARRAY[4,5]) AND 4 = ANY(ia)' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a = ANY (ARRAY[4,5]) AND 4 = ANY(ia)'); alter table mcv_lists alter column d type varchar(64); @@ -2085,30 +1984,22 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE mod(a,20) = 1 AND mod(b::int,10) = 1' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,20) = 1 AND mod(b::int,10) = 1'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 = mod(a,20) AND 1 = mod(b::int,10)' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 = mod(a,20) AND 1 = mod(b::int,10)'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE mod(a,20) < 1 AND mod(b::int,10) < 1' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,20) < 1 AND mod(b::int,10) < 1'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 > mod(a,20) AND 1 > mod(b::int,10)' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 > mod(a,20) AND 1 > mod(b::int,10)'); select * @@ -2163,30 +2054,22 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE mod(a,20) = 1 AND mod(b::int,10) = 1' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,20) = 1 AND mod(b::int,10) = 1'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 = mod(a,20) AND 1 = mod(b::int,10)' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 = mod(a,20) AND 1 = mod(b::int,10)'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE mod(a,20) < 1 AND mod(b::int,10) < 1' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,20) < 1 AND mod(b::int,10) < 1'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 > mod(a,20) AND 1 > mod(b::int,10)' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 > mod(a,20) AND 1 > mod(b::int,10)'); select * @@ -2248,30 +2131,22 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE mod(a,20) = 1 AND mod(b::int,10) = 1' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,20) = 1 AND mod(b::int,10) = 1'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 = mod(a,20) AND 1 = mod(b::int,10)' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 = mod(a,20) AND 1 = mod(b::int,10)'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE mod(a,20) < 1 AND mod(b::int,10) < 1' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE mod(a,20) < 1 AND mod(b::int,10) < 1'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 > mod(a,20) AND 1 > mod(b::int,10)' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 > mod(a,20) AND 1 > mod(b::int,10)'); select * @@ -2328,18 +2203,9 @@ drop statistics mcv_lists_stats; insert into mcv_lists (a, b, c, filler1) select - case - when mod(i, 100) = 1 then null - else mod(i, 100) - end, - case - when mod(i, 50) = 1 then null - else mod(i, 50) - end, - case - when mod(i, 25) = 1 then null - else mod(i, 25) - end, + case when mod(i, 100) = 1 then null else mod(i, 100) end, + case when mod(i, 50) = 1 then null else mod(i, 50) end, + case when mod(i, 25) = 1 then null else mod(i, 25) end, i from generate_series(1, 5000) as s (i); @@ -2351,9 +2217,7 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL AND c IS NULL' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL AND c IS NULL'); select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NOT NULL'); @@ -2367,11 +2231,9 @@ from select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a IN (0, 1) AND b IN (''0'', ''1'')' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a IN (0, 1) AND b IN (''0'', ''1'')'); -create statistics mcv_lists_stats (mcv) on "a", "b", "c" from mcv_lists; +create statistics mcv_lists_stats (mcv) on a, b, c from mcv_lists; analyze mcv_lists; @@ -2380,9 +2242,7 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL AND c IS NULL' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL AND c IS NULL'); select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NOT NULL'); @@ -2396,9 +2256,7 @@ from select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a IN (0, 1) AND b IN (''0'', ''1'')' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a IN (0, 1) AND b IN (''0'', ''1'')'); truncate mcv_lists; @@ -2437,11 +2295,9 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 OR b = ' select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a IS NULL AND (b = ''x'' OR d = ''x'')' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND (b = ''x'' OR d = ''x'')'); -create statistics mcv_lists_stats (mcv) on "a", "b", "d" from mcv_lists; +create statistics mcv_lists_stats (mcv) on a, b, d from mcv_lists; analyze mcv_lists; @@ -2461,9 +2317,7 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 OR b = ' select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a IS NULL AND (b = ''x'' OR d = ''x'')' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND (b = ''x'' OR d = ''x'')'); create table mcv_lists_uuid ( a uuid, @@ -2496,7 +2350,7 @@ from 'SELECT * FROM mcv_lists_uuid WHERE a = ''e7f6c011-776e-8db7-cd33-0b54174fd76f'' AND b = ''e7f6c011-776e-8db7-cd33-0b54174fd76f'' AND c = ''e7f6c011-776e-8db7-cd33-0b54174fd76f''' ); -create statistics mcv_lists_uuid_stats (mcv) on "a", "b", "c" from mcv_lists_uuid; +create statistics mcv_lists_uuid_stats (mcv) on a, b, c from mcv_lists_uuid; analyze mcv_lists_uuid; @@ -2535,24 +2389,19 @@ select from generate_series(1, 5000) as s (i); -create statistics mcv_lists_arrays_stats (mcv) on "a", "b", "c" from mcv_lists_arrays; +create statistics mcv_lists_arrays_stats (mcv) on a, b, c from mcv_lists_arrays; analyze mcv_lists_arrays; create table mcv_lists_bool ( - a boolean, - b boolean, - c boolean + a bool, + b bool, + c bool ) with (autovacuum_enabled = off); insert into mcv_lists_bool (a, b, c) -select - mod(i, 2) = 0, - mod(i, 4) = 0, - mod(i, 8) = 0 -from - generate_series(1, 10000) as s (i); +select mod(i, 2) = 0, mod(i, 4) = 0, mod(i, 8) = 0 from generate_series(1, 10000) as s (i); analyze mcv_lists_bool; @@ -2564,7 +2413,7 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE NOT a AND select * from check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE NOT a AND b AND NOT c'); -create statistics mcv_lists_bool_stats (mcv) on "a", "b", "c" from mcv_lists_bool; +create statistics mcv_lists_bool_stats (mcv) on a, b, c from mcv_lists_bool; analyze mcv_lists_bool; @@ -2583,12 +2432,7 @@ create table mcv_lists_partial ( ); insert into mcv_lists_partial (a, b, c) -select - mod(i, 10), - mod(i, 10), - mod(i, 10) -from - generate_series(0, 999) as s (i); +select mod(i, 10), mod(i, 10), mod(i, 10) from generate_series(0, 999) as s (i); insert into mcv_lists_partial (a, b, c) select i, i, i from generate_series(0, 99) as s (i); @@ -2599,39 +2443,29 @@ analyze mcv_lists_partial; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 0 AND b = 0 AND c = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 0 AND b = 0 AND c = 0'); select * from check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 0 OR b = 0 OR c = 0'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 10 AND b = 10 AND c = 10' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 10 AND b = 10 AND c = 10'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 10 OR b = 10 OR c = 10' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 10 OR b = 10 OR c = 10'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 0 AND b = 0 AND c = 10' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 0 AND b = 0 AND c = 10'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 0 OR b = 0 OR c = 10' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 0 OR b = 0 OR c = 10'); select * @@ -2647,46 +2481,36 @@ from 'SELECT * FROM mcv_lists_partial WHERE (a = 0 AND b = 0) OR (a = 0 AND c = 0) OR (b = 0 AND c = 0)' ); -create statistics mcv_lists_partial_stats (mcv) on "a", "b", "c" from mcv_lists_partial; +create statistics mcv_lists_partial_stats (mcv) on a, b, c from mcv_lists_partial; analyze mcv_lists_partial; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 0 AND b = 0 AND c = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 0 AND b = 0 AND c = 0'); select * from check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 0 OR b = 0 OR c = 0'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 10 AND b = 10 AND c = 10' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 10 AND b = 10 AND c = 10'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 10 OR b = 10 OR c = 10' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 10 OR b = 10 OR c = 10'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 0 AND b = 0 AND c = 10' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 0 AND b = 0 AND c = 10'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_partial WHERE a = 0 OR b = 0 OR c = 10' - ); + check_estimated_rows('SELECT * FROM mcv_lists_partial WHERE a = 0 OR b = 0 OR c = 10'); select * @@ -2713,13 +2537,7 @@ create table mcv_lists_multi ( with (autovacuum_enabled = off); insert into mcv_lists_multi (a, b, c, d) -select - mod(i, 5), - mod(i, 5), - mod(i, 7), - mod(i, 7) -from - generate_series(1, 5000) as s (i); +select mod(i, 5), mod(i, 5), mod(i, 7), mod(i, 7) from generate_series(1, 5000) as s (i); analyze mcv_lists_multi; @@ -2734,9 +2552,7 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE b = 0 OR select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE a = 0 AND b = 0 AND c = 0 AND d = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE a = 0 AND b = 0 AND c = 0 AND d = 0'); select * @@ -2748,13 +2564,11 @@ from select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE a = 0 OR b = 0 OR c = 0 OR d = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE a = 0 OR b = 0 OR c = 0 OR d = 0'); -create statistics mcv_lists_multi_1 (mcv) on "a", "b" from mcv_lists_multi; +create statistics mcv_lists_multi_1 (mcv) on a, b from mcv_lists_multi; -create statistics mcv_lists_multi_2 (mcv) on "c", "d" from mcv_lists_multi; +create statistics mcv_lists_multi_2 (mcv) on c, d from mcv_lists_multi; analyze mcv_lists_multi; @@ -2769,9 +2583,7 @@ select * from check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE b = 0 OR select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE a = 0 AND b = 0 AND c = 0 AND d = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE a = 0 AND b = 0 AND c = 0 AND d = 0'); select * @@ -2783,9 +2595,7 @@ from select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE a = 0 OR b = 0 OR c = 0 OR d = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE a = 0 OR b = 0 OR c = 0 OR d = 0'); drop table mcv_lists_multi; @@ -2796,12 +2606,7 @@ create table expr_stats ( ); insert into expr_stats -select - mod(i, 10), - mod(i, 10), - mod(i, 10) -from - generate_series(1, 1000) as s (i); +select mod(i, 10), mod(i, 10), mod(i, 10) from generate_series(1, 1000) as s (i); analyze expr_stats; @@ -2828,44 +2633,27 @@ create table expr_stats ( ); insert into expr_stats -select - mod(i, 10), - mod(i, 10), - mod(i, 10) -from - generate_series(1, 1000) as s (i); +select mod(i, 10), mod(i, 10), mod(i, 10) from generate_series(1, 1000) as s (i); analyze expr_stats; select * from - check_estimated_rows( - 'SELECT * FROM expr_stats WHERE a = 0 AND (2*a) = 0 AND (3*b) = 0' - ); + check_estimated_rows('SELECT * FROM expr_stats WHERE a = 0 AND (2*a) = 0 AND (3*b) = 0'); select * from check_estimated_rows('SELECT * FROM expr_stats WHERE a = 3 AND b = 3 AND (a-b) = 0'); select * from check_estimated_rows('SELECT * FROM expr_stats WHERE a = 0 AND b = 1 AND (a-b) = 0'); -create statistics expr_stats_1 -(mcv) -on "a", -"b", -(2 * a), -(3 * b), -(a + b), -(a - b) -from expr_stats; +create statistics expr_stats_1 (mcv) on a, b, (2 * a), (3 * b), (a + b), (a - b) from expr_stats; analyze expr_stats; select * from - check_estimated_rows( - 'SELECT * FROM expr_stats WHERE a = 0 AND (2*a) = 0 AND (3*b) = 0' - ); + check_estimated_rows('SELECT * FROM expr_stats WHERE a = 0 AND (2*a) = 0 AND (3*b) = 0'); select * from check_estimated_rows('SELECT * FROM expr_stats WHERE a = 3 AND b = 3 AND (a-b) = 0'); @@ -2896,7 +2684,7 @@ from 'SELECT * FROM expr_stats WHERE a = 0 AND (b || c) <= ''z'' AND (c || b) >= ''0''' ); -create statistics expr_stats_1 (mcv) on "a", "b", (b || c), (c || b) from expr_stats; +create statistics expr_stats_1 (mcv) on a, b, (b || c), (c || b) from expr_stats; analyze expr_stats; @@ -2914,7 +2702,7 @@ create table expr_stats_incompatible_test ( c1 boolean not null ); -create statistics expr_stat_comp_1 on "c0", "c1" from expr_stats_incompatible_test; +create statistics expr_stat_comp_1 on c0, c1 from expr_stats_incompatible_test; insert into expr_stats_incompatible_test values (1234, false), (5678, true); @@ -2925,14 +2713,11 @@ select from only expr_stats_incompatible_test where - upper('x') like 'x' || cast('[0,1]' as int4range) and - ( - c0 in (0, 1) or c1 - ); + upper('x') like 'x' || cast('[0,1]' as int4range) and (c0 in (0, 1) or c1); drop table expr_stats_incompatible_test; -create schema "tststats"; +create schema tststats; create table tststats.priv_test_tbl ( a int, @@ -2940,13 +2725,9 @@ create table tststats.priv_test_tbl ( ); insert into tststats.priv_test_tbl -select - mod(i, 5), - mod(i, 10) -from - generate_series(1, 100) as s (i); +select mod(i, 5), mod(i, 10) from generate_series(1, 100) as s (i); -create statistics tststats.priv_test_stats (mcv) on "a", "b" from tststats.priv_test_tbl; +create statistics tststats.priv_test_stats (mcv) on a, b from tststats.priv_test_tbl; analyze tststats.priv_test_tbl; @@ -2955,11 +2736,11 @@ create table stts_t1 ( b int ); -create statistics (ndistinct) on "a", "b" from stts_t1; +create statistics (ndistinct) on a, b from stts_t1; -create statistics (ndistinct, dependencies) on "a", "b" from stts_t1; +create statistics (ndistinct, dependencies) on a, b from stts_t1; -create statistics (ndistinct, dependencies, mcv) on "a", "b" from stts_t1; +create statistics (ndistinct, dependencies, mcv) on a, b from stts_t1; create table stts_t2 ( a int, @@ -2967,7 +2748,7 @@ create table stts_t2 ( c int ); -create statistics on "b", "c" from stts_t2; +create statistics on b, c from stts_t2; create table stts_t3 ( col1 int, @@ -2975,15 +2756,15 @@ create table stts_t3 ( col3 int ); -create statistics stts_hoge on "col1", "col2", "col3" from stts_t3; +create statistics stts_hoge on col1, col2, col3 from stts_t3; -create schema "stts_s1"; +create schema stts_s1; -create schema "stts_s2"; +create schema stts_s2; -create statistics stts_s1.stts_foo on "col1", "col2" from stts_t3; +create statistics stts_s1.stts_foo on col1, col2 from stts_t3; -create statistics stts_s2.stts_yama (dependencies, mcv) on "col1", "col3" from stts_t3; +create statistics stts_s2.stts_yama (dependencies, mcv) on col1, col3 from stts_t3; insert into stts_t1 select i, i from generate_series(1, 100) as i; @@ -2991,9 +2772,9 @@ analyze stts_t1; set search_path to public, stts_s1, stts_s2, tststats; -create statistics (mcv) on "a", "b", (a + b), (a - b) from stts_t1; +create statistics (mcv) on a, b, (a + b), (a - b) from stts_t1; -create statistics (mcv) on "a", "b", (a + b), (a - b) from stts_t1; +create statistics (mcv) on a, b, (a + b), (a - b) from stts_t1; create statistics (mcv) on (a + b), (a - b) from stts_t1; @@ -3021,7 +2802,7 @@ reset search_path; create user regress_stats_user1; -grant USAGE on schema tststats to regress_stats_user1; +grant usage on schema tststats to regress_stats_user1; set session authorization regress_stats_user1; @@ -3030,25 +2811,23 @@ select * from tststats.priv_test_tbl; select * from tststats.priv_test_tbl where a = 1 and tststats.priv_test_tbl.* > (1, 1) is not null; create function op_leak(int, int) -returns boolean +returns bool language plpgsql -as $function$ -BEGIN RAISE NOTICE 'op_leak => %, %', $1, $2; RETURN $1 < $2; END -$function$; +as 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'; -create operator <<< (PROCEDURE = op_leak, LEFTARG = int, RIGHTARG = int, RESTRICT = scalarltsel); +create operator <<< (procedure = op_leak, leftarg = int, rightarg = int, restrict = scalarltsel); create function op_leak(record, record) -returns boolean +returns bool language plpgsql -as $function$ -BEGIN RAISE NOTICE 'op_leak => %, %', $1, $2; RETURN $1 < $2; END -$function$; +as 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'; -create operator <<< (PROCEDURE = op_leak, -LEFTARG = record, -RIGHTARG = record, -RESTRICT = scalarltsel); +create operator <<< ( + procedure = op_leak, + leftarg = record, + rightarg = record, + restrict = scalarltsel +); select * from tststats.priv_test_tbl where a <<< 0 and b <<< 0; @@ -3064,7 +2843,7 @@ create view tststats.priv_test_view with (security_barrier = 'true') as select * from tststats.priv_test_tbl where false; -grant SELECT, DELETE on table tststats.priv_test_view to regress_stats_user1; +grant select, delete on table tststats.priv_test_view to regress_stats_user1; set session authorization regress_stats_user1; @@ -3077,10 +2856,7 @@ select from tststats.priv_test_view as t where - a <<< 0 and - ( - b <<< 0 or t.* <<< (1, 1) is not null - ); + a <<< 0 and (b <<< 0 or t.* <<< (1, 1) is not null); delete from tststats.priv_test_view where a <<< 0 and b <<< 0; @@ -3096,7 +2872,7 @@ for all to public using (2 * a < 0); -grant SELECT, DELETE on table tststats.priv_test_tbl to regress_stats_user1; +grant select, delete on table tststats.priv_test_tbl to regress_stats_user1; set session authorization regress_stats_user1; @@ -3129,10 +2905,7 @@ select from tststats.priv_test_parent_tbl as t where - a <<< 0 and - ( - b <<< 0 or t.* <<< (1, 1) is not null - ); + a <<< 0 and (b <<< 0 or t.* <<< (1, 1) is not null); delete from tststats.priv_test_parent_tbl where a <<< 0 and b <<< 0; @@ -3148,7 +2921,7 @@ for all to public using (2 * a < 0); -grant SELECT, DELETE on table tststats.priv_test_parent_tbl to regress_stats_user1; +grant select, delete on table tststats.priv_test_parent_tbl to regress_stats_user1; set session authorization regress_stats_user1; @@ -3161,25 +2934,20 @@ select from tststats.priv_test_parent_tbl as t where - a <<< 0 and - ( - b <<< 0 or t.* <<< (1, 1) is not null - ); + a <<< 0 and (b <<< 0 or t.* <<< (1, 1) is not null); delete from tststats.priv_test_parent_tbl where a <<< 0 and b <<< 0; reset session_authorization; create table stats_ext_tbl ( - id int - primary key - generated by default as identity, + id int primary key generated by default as identity, col text ); insert into stats_ext_tbl (col) values ('secret'), ('secret'), ('very secret'); -create statistics s_col on "id", "col" from stats_ext_tbl; +create statistics s_col on id, col from stats_ext_tbl; create statistics s_expr on (mod(id, 2)), (lower(col)) from stats_ext_tbl; @@ -3252,27 +3020,17 @@ insert into grouping_unique (x) select gs from generate_series(1, 1000) as gs; analyze grouping_unique; -select - * -from - check_estimated_rows( - ' +select * from check_estimated_rows(' SELECT * FROM generate_series(1, 1) t1 LEFT JOIN ( SELECT x FROM grouping_unique t2 GROUP BY x) AS q1 ON t1.t1 = q1.x; -' - ); +'); drop table grouping_unique; create table sb_1 as - select - gs % 10 as x, - gs % 10 as y, - gs % 10 as z - from - generate_series(1, 1e4) as gs; + select gs % 10 as x, gs % 10 as y, gs % 10 as z from generate_series(1, 1e4) as gs; create table sb_2 as @@ -3288,7 +3046,7 @@ analyze sb_1, sb_2; select * from sb_1 as a, sb_2 as b where a.x = b.x and a.y = b.y and a.z = b.z; -create statistics extstat_sb_2 (ndistinct) on "x", "y", "z" from sb_2; +create statistics extstat_sb_2 (ndistinct) on x, y, z from sb_2; analyze sb_2; @@ -3307,13 +3065,11 @@ reset enable_nestloop; reset enable_mergejoin; create function extstat_small(x numeric) -returns boolean +returns bool language plpgsql immutable strict -as $function$ -BEGIN RETURN x < 1; END -$function$; +as $$ BEGIN RETURN x < 1; END $$; select * from check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)'); @@ -3325,4 +3081,4 @@ select * from check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)'); drop table sb_1, sb_2 cascade; -drop function extstat_small(numeric); +drop function extstat_small(x numeric); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_80.snap index a9237d638..13d5b19db 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_80.snap @@ -8,7 +8,7 @@ returns table ( actual int ) language plpgsql -as $function$ +as $$ declare ln text; tmp text[]; @@ -24,7 +24,7 @@ begin end if; end loop; end; -$function$; +$$; create table ext_stats_test ( x text, @@ -32,30 +32,20 @@ create table ext_stats_test ( z int ); -create statistics tst on "a", "b" from nonexistent; +create statistics tst on a, b from nonexistent; -create statistics tst on "a", "b" from ext_stats_test; +create statistics tst on a, b from ext_stats_test; -create statistics tst on "x", "x", "y" from ext_stats_test; +create statistics tst on x, x, y from ext_stats_test; -create statistics tst -on "x", -"x", -"y", -"x", -"x", -"y", -"x", -"x", -"y" -from ext_stats_test; +create statistics tst on x, x, y, x, x, y, x, x, y from ext_stats_test; create statistics tst -on "x", -"x", -"y", -"x", -"x", +on x, +x, +y, +x, +x, (x || 'x'), (y + 1), (x || 'x'), @@ -75,29 +65,23 @@ on (x || 'x'), (y + 1) from ext_stats_test; -create statistics tst on (x || 'x'), (x || 'x'), "y" from ext_stats_test; +create statistics tst on (x || 'x'), (x || 'x'), y from ext_stats_test; -create statistics tst (unrecognized) on "x", "y" from ext_stats_test; +create statistics tst (unrecognized) on x, y from ext_stats_test; -create statistics tst on "a" from (values (x)) as foo; +create statistics tst on a from (values (x)) as foo; -create statistics tst on "a" from foo natural join bar; +create statistics tst on a from foo natural join bar; -create statistics tst on "a" from (select * from ext_stats_test) as foo; +create statistics tst on a from (select * from ext_stats_test) as foo; -create statistics tst on "a" from ext_stats_test as s tablesample system (x); +create statistics tst on a from ext_stats_test as s tablesample system (x); -create statistics tst on "a" from xmltable( 'foo' passing 'bar' columns a text); +create statistics tst on a from xmltable( 'foo' passing 'bar' columns a text); create statistics tst -on "a" -from json_table( - cast('123' as jsonb), - '$' - columns ( - item int - ) -); +on a +from json_table( cast('123' as jsonb), '$' columns (item int ) ); create function tftest(int) returns table ( @@ -107,11 +91,11 @@ returns table ( language sql immutable strict -as $function$ +as $$ SELECT $1, $1+i FROM generate_series(1,5) g(i); -$function$; +$$; -create statistics alt_stat2 on "a" from tftest(1); +create statistics alt_stat2 on a from tftest(1); drop function tftest; @@ -119,23 +103,23 @@ create statistics tst on (y) from ext_stats_test; drop table ext_stats_test; -create statistics tst on "z" from ext_stats_test1; +create statistics tst on z from ext_stats_test1; create statistics tst on (z) from ext_stats_test1; create statistics tst on (z + 1) from ext_stats_test1; -create statistics tst (ndistinct) on "z" from ext_stats_test1; +create statistics tst (ndistinct) on z from ext_stats_test1; -create statistics tst on "tableoid" from ext_stats_test1; +create statistics tst on tableoid from ext_stats_test1; create statistics tst on (tableoid) from ext_stats_test1; create statistics tst on (cast(tableoid as int) + 1) from ext_stats_test1; -create statistics tst (ndistinct) on "xmin" from ext_stats_test1; +create statistics tst (ndistinct) on xmin from ext_stats_test1; -create statistics tst (ndistinct) on "w" from ext_stats_test1; +create statistics tst (ndistinct) on w from ext_stats_test1; drop table ext_stats_test1; @@ -145,7 +129,7 @@ create table ab1 ( c int ); -create statistics if not exists ab1_a_b_stats on "a", "b" from ab1; +create statistics if not exists ab1_a_b_stats on a, b from ab1; comment on statistics ab1_a_b_stats is 'new comment'; @@ -163,13 +147,13 @@ reset session_authorization; drop role regress_stats_ext; -create statistics if not exists ab1_a_b_stats on "a", "b" from ab1; +create statistics if not exists ab1_a_b_stats on a, b from ab1; drop statistics ab1_a_b_stats; -create schema "regress_schema_2"; +create schema regress_schema_2; -create statistics regress_schema_2.ab1_a_b_stats on "a", "b" from ab1; +create statistics regress_schema_2.ab1_a_b_stats on a, b from ab1; select pg_get_statisticsobjdef(oid) @@ -180,11 +164,11 @@ where drop statistics regress_schema_2.ab1_a_b_stats; -create statistics ab1_b_c_stats on "b", "c" from ab1; +create statistics ab1_b_c_stats on b, c from ab1; -create statistics ab1_a_b_c_stats on "a", "b", "c" from ab1; +create statistics ab1_a_b_c_stats on a, b, c from ab1; -create statistics ab1_b_a_stats on "b", "a" from ab1; +create statistics ab1_b_a_stats on b, a from ab1; alter table ab1 drop column a; @@ -205,7 +189,7 @@ alter table ab1 insert into ab1 select a, a % 23 from generate_series(1, 1000) as a; -create statistics ab1_a_b_stats on "a", "b" from ab1; +create statistics ab1_a_b_stats on a, b from ab1; analyze ab1; @@ -252,7 +236,7 @@ inherits (ab1); insert into ab1 values (1, 1); -create statistics ab1_a_b_stats on "a", "b" from ab1; +create statistics ab1_a_b_stats on a, b from ab1; analyze ab1; @@ -270,63 +254,43 @@ create table stxdinh2 () inherits (stxdinh); insert into stxdinh -select - mod(a, 50), - mod(a, 100) -from - generate_series(0, 1999) as a; +select mod(a, 50), mod(a, 100) from generate_series(0, 1999) as a; insert into stxdinh1 -select - mod(a, 100), - mod(a, 100) -from - generate_series(0, 999) as a; +select mod(a, 100), mod(a, 100) from generate_series(0, 999) as a; insert into stxdinh2 -select - mod(a, 100), - mod(a, 100) -from - generate_series(0, 999) as a; +select mod(a, 100), mod(a, 100) from generate_series(0, 999) as a; -vacuum (ANALYZE) stxdinh, stxdinh1, stxdinh2; +vacuum (analyze) stxdinh, stxdinh1, stxdinh2; select * from check_estimated_rows('SELECT a, b FROM stxdinh* GROUP BY 1, 2'); select * from - check_estimated_rows( - 'SELECT a, b FROM stxdinh* WHERE a = 0 AND b = 0' - ); + check_estimated_rows('SELECT a, b FROM stxdinh* WHERE a = 0 AND b = 0'); -create statistics stxdinh on "a", "b" from stxdinh; +create statistics stxdinh on a, b from stxdinh; -vacuum (ANALYZE) stxdinh, stxdinh1, stxdinh2; +vacuum (analyze) stxdinh, stxdinh1, stxdinh2; select * from check_estimated_rows('SELECT a, b FROM stxdinh* GROUP BY 1, 2'); select * from - check_estimated_rows( - 'SELECT a, b FROM stxdinh* WHERE a = 0 AND b = 0' - ); + check_estimated_rows('SELECT a, b FROM stxdinh* WHERE a = 0 AND b = 0'); select * from - check_estimated_rows( - 'SELECT a, b FROM ONLY stxdinh GROUP BY 1, 2' - ); + check_estimated_rows('SELECT a, b FROM ONLY stxdinh GROUP BY 1, 2'); select * from - check_estimated_rows( - 'SELECT a, b FROM ONLY stxdinh WHERE a = 0 AND b = 0' - ); + check_estimated_rows('SELECT a, b FROM ONLY stxdinh WHERE a = 0 AND b = 0'); drop table stxdinh, stxdinh1, stxdinh2; @@ -340,16 +304,11 @@ partition by range(i); create table stxdinp1 partition of stxdinp for values from (1) to (100); insert into stxdinp -select - 1, - a / 100, - a / 100 -from - generate_series(1, 999) as a; +select 1, a / 100, a / 100 from generate_series(1, 999) as a; -create statistics stxdinp on (a + 1), "a", "b" from stxdinp; +create statistics stxdinp on (a + 1), a, b from stxdinp; -vacuum (ANALYZE) stxdinp; +vacuum (analyze) stxdinp; select 1 from pg_statistic_ext where stxrelid = cast('stxdinp' as regclass); @@ -358,9 +317,7 @@ select * from check_estimated_rows('SELECT a, b FROM stxdinp GROUP BY 1, 2'); select * from - check_estimated_rows( - 'SELECT a + 1, b FROM ONLY stxdinp GROUP BY 1, 2' - ); + check_estimated_rows('SELECT a + 1, b FROM ONLY stxdinp GROUP BY 1, 2'); drop table stxdinp; @@ -368,7 +325,7 @@ create table ab1 ( a int, b int, c timestamp, - d timestamp with time zone + d timestamptz ); create statistics ab1_exprstat_1 on (a + b) from ab1; @@ -377,7 +334,7 @@ create statistics ab1_exprstat_2 on (a + b) from ab1; select stxkind from pg_statistic_ext where stxname = 'ab1_exprstat_2'; -create statistics ab1_exprstat_3 on (a + b), "a" from ab1; +create statistics ab1_exprstat_3 on (a + b), a from ab1; select stxkind from pg_statistic_ext where stxname = 'ab1_exprstat_3'; @@ -387,18 +344,15 @@ create statistics ab1_exprstat_5 on (date_trunc('day', c)) from ab1; create statistics ab1_exprstat_6 on (case a when 1 then true else false end), -"b" +b from ab1; insert into ab1 select x / 10, x / 3, - cast('2020-10-01' as timestamp) + - x * cast('1 day' as interval), - cast('2020-10-01' - as timestamp with time zone) + - x * cast('1 day' as interval) + cast('2020-10-01' as timestamp) + x * cast('1 day' as interval), + cast('2020-10-01' as timestamptz) + x * cast('1 day' as interval) from generate_series(1, 100) as x; @@ -413,7 +367,7 @@ from drop table ab1; -create schema "tststats"; +create schema tststats; create table tststats.t ( a int, @@ -421,7 +375,7 @@ create table tststats.t ( c text ); -create index "ti" on tststats.t using btree (a, b); +create index ti on tststats.t using btree (a, b); create sequence tststats.s; @@ -453,26 +407,25 @@ create table tststats.pt1 partition of tststats.pt for values from (-10, -10) to (10, 10); -create statistics tststats.s1 on "a", "b" from tststats.t; +create statistics tststats.s1 on a, b from tststats.t; -create statistics tststats.s2 on "a", "b" from tststats.ti; +create statistics tststats.s2 on a, b from tststats.ti; -create statistics tststats.s3 on "a", "b" from tststats.s; +create statistics tststats.s3 on a, b from tststats.s; -create statistics tststats.s4 on "a", "b" from tststats.v; +create statistics tststats.s4 on a, b from tststats.v; -create statistics tststats.s5 on "a", "b" from tststats.mv; +create statistics tststats.s5 on a, b from tststats.mv; -create statistics tststats.s6 on "a", "b" from tststats.ty; +create statistics tststats.s6 on a, b from tststats.ty; -create statistics tststats.s7 on "a", "b" from tststats.f; +create statistics tststats.s7 on a, b from tststats.f; -create statistics tststats.s8 on "a", "b" from tststats.pt; +create statistics tststats.s8 on a, b from tststats.pt; -create statistics tststats.s9 on "a", "b" from tststats.pt1; +create statistics tststats.s9 on a, b from tststats.pt1; -do -$do$ +do $$ DECLARE relname text := reltoastrelid::regclass FROM pg_class WHERE oid = 'tststats.t'::regclass; BEGIN @@ -480,7 +433,7 @@ BEGIN EXCEPTION WHEN wrong_object_type THEN RAISE NOTICE 'stats on toast table not created'; END; -$do$; +$$; drop schema tststats cascade; @@ -511,44 +464,32 @@ analyze ndistinct; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY b, c' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (a+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (a+1)'); select * @@ -571,7 +512,7 @@ from 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (a+1), (b+100)' ); -create statistics s10 on "a", "b", "c" from ndistinct; +create statistics s10 on a, b, c from ndistinct; analyze ndistinct; @@ -582,44 +523,32 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = - cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY ctid, a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY ctid, a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY b, c' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (a+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (a+1)'); select * @@ -645,16 +574,12 @@ from select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d'); truncate ndistinct; @@ -676,51 +601,37 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = - cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (a+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (a+1)'); select * @@ -752,51 +663,37 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = - cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, d' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, d'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (a+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (a+1)'); select * @@ -851,9 +748,7 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = - cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * @@ -881,25 +776,19 @@ drop statistics s10; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (2*c)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (2*c)'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (2*c)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (2*c)'); -create statistics s10 (ndistinct) on "a", "b", (2 * c) from ndistinct; +create statistics s10 (ndistinct) on a, b, (2 * c) from ndistinct; analyze ndistinct; @@ -910,30 +799,22 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxrelid = - cast('ndistinct' as regclass) and - d.stxoid = s.oid; + s.stxrelid = cast('ndistinct' as regclass) and d.stxoid = s.oid; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (2*c)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (2*c)'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (2*c)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (2*c)'); drop statistics s10; @@ -953,30 +834,22 @@ analyze ndistinct; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)'); select * @@ -988,9 +861,7 @@ from select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)'); select * @@ -999,39 +870,31 @@ from 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1), c, (d - 1)' ); -create statistics s11 (ndistinct) on "a", "b" from ndistinct; +create statistics s11 (ndistinct) on a, b from ndistinct; -create statistics s12 (ndistinct) on "c", "d" from ndistinct; +create statistics s12 (ndistinct) on c, d from ndistinct; analyze ndistinct; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)'); select * @@ -1043,9 +906,7 @@ from select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)'); select * @@ -1063,30 +924,22 @@ analyze ndistinct; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)'); select * @@ -1098,9 +951,7 @@ from select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)'); select * @@ -1111,37 +962,29 @@ from drop statistics s12; -create statistics s12 (ndistinct) on "c", "d", (c * 10), (d - 1) from ndistinct; +create statistics s12 (ndistinct) on c, d, (c * 10), (d - 1) from ndistinct; analyze ndistinct; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)'); select * @@ -1153,9 +996,7 @@ from select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)'); select * @@ -1166,37 +1007,29 @@ from drop statistics s11; -create statistics s11 (ndistinct) on "a", "b", (a * 5), (b + 1) from ndistinct; +create statistics s11 (ndistinct) on a, b, (a * 5), (b + 1) from ndistinct; analyze ndistinct; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)'); select * @@ -1208,9 +1041,7 @@ from select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)'); select * @@ -1223,39 +1054,31 @@ drop statistics s11; drop statistics s12; -create statistics s11 (ndistinct) on "a", "b", (a * 5), (b + 1) from ndistinct; +create statistics s11 (ndistinct) on a, b, (a * 5), (b + 1) from ndistinct; -create statistics s12 (ndistinct) on "a", (b + 1), (c * 10) from ndistinct; +create statistics s12 (ndistinct) on a, (b + 1), (c * 10) from ndistinct; analyze ndistinct; select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, (b+1)'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), b'); select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY (a*5), (b+1)'); select * @@ -1267,9 +1090,7 @@ from select * from - check_estimated_rows( - 'SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)' - ); + check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, (c*10)'); select * @@ -1293,9 +1114,9 @@ create table functional_dependencies ( ) with (autovacuum_enabled = off); -create index "fdeps_ab_idx" on functional_dependencies using btree (a, b); +create index fdeps_ab_idx on functional_dependencies using btree (a, b); -create index "fdeps_abc_idx" on functional_dependencies using btree (a, b, c); +create index fdeps_abc_idx on functional_dependencies using btree (a, b, c); insert into functional_dependencies (a, b, c, filler1) select @@ -1324,9 +1145,9 @@ from create statistics func_deps_stat (dependencies) -on "a", -"b", -"c" +on a, +b, +c from functional_dependencies; analyze functional_dependencies; @@ -1350,13 +1171,7 @@ truncate functional_dependencies; drop statistics func_deps_stat; insert into functional_dependencies (a, b, c, filler1) -select - i, - i, - i, - i -from - generate_series(1, 5000) as s (i); +select i, i, i, i from generate_series(1, 5000) as s (i); analyze functional_dependencies; @@ -1589,9 +1404,9 @@ from create statistics func_deps_stat (dependencies) -on "a", -"b", -"c" +on a, +b, +c from functional_dependencies; analyze functional_dependencies; @@ -2211,14 +2026,14 @@ from create statistics functional_dependencies_multi_1 (dependencies) -on "a", -"b" +on a, +b from functional_dependencies_multi; create statistics functional_dependencies_multi_2 (dependencies) -on "c", -"d" +on c, +d from functional_dependencies_multi; analyze functional_dependencies_multi; @@ -2286,9 +2101,7 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'''); select * @@ -2297,16 +2110,14 @@ from 'SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'' AND c = 1' ); -create statistics mcv_lists_stats (mcv) on "a", "b", "c" from mcv_lists; +create statistics mcv_lists_stats (mcv) on a, b, c from mcv_lists; analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'''); select * @@ -2320,13 +2131,7 @@ truncate mcv_lists; drop statistics mcv_lists_stats; insert into mcv_lists (a, b, c, filler1) -select - i, - i, - i, - i -from - generate_series(1, 1000) as s (i); +select i, i, i, i from generate_series(1, 1000) as s (i); analyze mcv_lists; @@ -2386,44 +2191,32 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'''); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 = a AND ''1'' = b' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 = a AND ''1'' = b'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a < 1 AND b < ''1''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a < 1 AND b < ''1'''); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 > a AND ''1'' > b' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 > a AND ''1'' > b'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a <= 0 AND b <= ''0''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a <= 0 AND b <= ''0'''); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 0 >= a AND ''0'' >= b' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 0 >= a AND ''0'' >= b'); select * @@ -2551,51 +2344,39 @@ from 'SELECT * FROM mcv_lists WHERE a = ANY (ARRAY[4,5]) AND 4 = ANY(ia)' ); -create statistics mcv_lists_stats (mcv) on "a", "b", "c", "ia" from mcv_lists; +create statistics mcv_lists_stats (mcv) on a, b, c, ia from mcv_lists; analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'''); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 = a AND ''1'' = b' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 = a AND ''1'' = b'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a < 1 AND b < ''1''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a < 1 AND b < ''1'''); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 1 > a AND ''1'' > b' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 1 > a AND ''1'' > b'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a <= 0 AND b <= ''0''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a <= 0 AND b <= ''0'''); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE 0 >= a AND ''0'' >= b' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE 0 >= a AND ''0'' >= b'); select * @@ -2739,8 +2520,7 @@ from pg_statistic_ext as s, pg_statistic_ext_data as d where - s.stxname = 'mcv_lists_stats' and - d.stxoid = s.oid; + s.stxname = 'mcv_lists_stats' and d.stxoid = s.oid; alter table mcv_lists alter column c type numeric; @@ -2748,31 +2528,21 @@ alter table mcv_lists select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'''); analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1'''); truncate mcv_lists; drop statistics mcv_lists_stats; insert into mcv_lists (a, b, c, filler1) -select - i, - i, - i, - i -from - generate_series(1, 1000) as s (i); +select i, i, i, i from generate_series(1, 1000) as s (i); analyze mcv_lists; @@ -3022,18 +2792,9 @@ drop statistics mcv_lists_stats; insert into mcv_lists (a, b, c, filler1) select - case - when mod(i, 100) = 1 then null - else mod(i, 100) - end, - case - when mod(i, 50) = 1 then null - else mod(i, 50) - end, - case - when mod(i, 25) = 1 then null - else mod(i, 25) - end, + case when mod(i, 100) = 1 then null else mod(i, 100) end, + case when mod(i, 50) = 1 then null else mod(i, 50) end, + case when mod(i, 25) = 1 then null else mod(i, 25) end, i from generate_series(1, 5000) as s (i); @@ -3043,9 +2804,7 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL'); select * @@ -3075,16 +2834,14 @@ from 'SELECT * FROM mcv_lists WHERE a IN (0, 1) AND b IN (''0'', ''1'')' ); -create statistics mcv_lists_stats (mcv) on "a", "b", "c" from mcv_lists; +create statistics mcv_lists_stats (mcv) on a, b, c from mcv_lists; analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL'); select * @@ -3117,12 +2874,7 @@ from truncate mcv_lists; insert into mcv_lists (a, b, c) -select - 1, - 2, - 3 -from - generate_series(1, 1000) as s (i); +select 1, 2, 3 from generate_series(1, 1000) as s (i); analyze mcv_lists; @@ -3133,8 +2885,7 @@ from pg_statistic_ext_data as d, pg_mcv_list_items(d.stxdmcv) as m where - s.stxname = 'mcv_lists_stats' and - d.stxoid = s.oid; + s.stxname = 'mcv_lists_stats' and d.stxoid = s.oid; truncate mcv_lists; @@ -3143,18 +2894,9 @@ drop statistics mcv_lists_stats; insert into mcv_lists (a, b, c, d) select null, - case - when mod(i, 2) = 0 then null - else 'x' - end, - case - when mod(i, 2) = 0 then null - else 0 - end, - case - when mod(i, 2) = 0 then null - else 'x' - end + case when mod(i, 2) = 0 then null else 'x' end, + case when mod(i, 2) = 0 then null else 0 end, + case when mod(i, 2) = 0 then null else 'x' end from generate_series(1, 5000) as s (i); @@ -3163,9 +2905,7 @@ analyze mcv_lists; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE b = ''x'' OR d = ''x''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE b = ''x'' OR d = ''x'''); select * @@ -3181,7 +2921,7 @@ from 'SELECT * FROM mcv_lists WHERE a IS NULL AND (b = ''x'' OR d = ''x'')' ); -create statistics mcv_lists_stats (mcv) on "a", "b", "d" from mcv_lists; +create statistics mcv_lists_stats (mcv) on a, b, d from mcv_lists; analyze mcv_lists; @@ -3192,15 +2932,12 @@ from pg_statistic_ext_data as d, pg_mcv_list_items(d.stxdmcv) as m where - s.stxname = 'mcv_lists_stats' and - d.stxoid = s.oid; + s.stxname = 'mcv_lists_stats' and d.stxoid = s.oid; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists WHERE b = ''x'' OR d = ''x''' - ); + check_estimated_rows('SELECT * FROM mcv_lists WHERE b = ''x'' OR d = ''x'''); select * @@ -3225,12 +2962,9 @@ with (autovacuum_enabled = off); insert into mcv_lists_uuid (a, b, c) select - cast(fipshash(cast(mod(i, 100) as text)) - as uuid), - cast(fipshash(cast(mod(i, 50) as text)) - as uuid), - cast(fipshash(cast(mod(i, 25) as text)) - as uuid) + cast(fipshash(cast(mod(i, 100) as text)) as uuid), + cast(fipshash(cast(mod(i, 50) as text)) as uuid), + cast(fipshash(cast(mod(i, 25) as text)) as uuid) from generate_series(1, 5000) as s (i); @@ -3250,12 +2984,7 @@ from 'SELECT * FROM mcv_lists_uuid WHERE a = ''e7f6c011-776e-8db7-cd33-0b54174fd76f'' AND b = ''e7f6c011-776e-8db7-cd33-0b54174fd76f'' AND c = ''e7f6c011-776e-8db7-cd33-0b54174fd76f''' ); -create statistics mcv_lists_uuid_stats -(mcv) -on "a", -"b", -"c" -from mcv_lists_uuid; +create statistics mcv_lists_uuid_stats (mcv) on a, b, c from mcv_lists_uuid; analyze mcv_lists_uuid; @@ -3294,19 +3023,14 @@ select from generate_series(1, 5000) as s (i); -create statistics mcv_lists_arrays_stats -(mcv) -on "a", -"b", -"c" -from mcv_lists_arrays; +create statistics mcv_lists_arrays_stats (mcv) on a, b, c from mcv_lists_arrays; analyze mcv_lists_arrays; create table mcv_lists_bool ( - a boolean, - b boolean, - c boolean + a bool, + b bool, + c bool ) with (autovacuum_enabled = off); @@ -3323,16 +3047,12 @@ analyze mcv_lists_bool; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_bool WHERE a AND b AND c' - ); + check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE a AND b AND c'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_bool WHERE NOT a AND b AND c' - ); + check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE NOT a AND b AND c'); select * @@ -3348,28 +3068,19 @@ from 'SELECT * FROM mcv_lists_bool WHERE NOT a AND b AND NOT c' ); -create statistics mcv_lists_bool_stats -(mcv) -on "a", -"b", -"c" -from mcv_lists_bool; +create statistics mcv_lists_bool_stats (mcv) on a, b, c from mcv_lists_bool; analyze mcv_lists_bool; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_bool WHERE a AND b AND c' - ); + check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE a AND b AND c'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_bool WHERE NOT a AND b AND c' - ); + check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE NOT a AND b AND c'); select * @@ -3392,28 +3103,13 @@ create table mcv_lists_partial ( ); insert into mcv_lists_partial (a, b, c) -select - mod(i, 10), - mod(i, 10), - mod(i, 10) -from - generate_series(0, 999) as s (i); +select mod(i, 10), mod(i, 10), mod(i, 10) from generate_series(0, 999) as s (i); insert into mcv_lists_partial (a, b, c) -select - i, - i, - i -from - generate_series(0, 99) as s (i); +select i, i, i from generate_series(0, 99) as s (i); insert into mcv_lists_partial (a, b, c) -select - i, - i, - i -from - generate_series(0, 3999) as s (i); +select i, i, i from generate_series(0, 3999) as s (i); analyze mcv_lists_partial; @@ -3475,9 +3171,9 @@ from create statistics mcv_lists_partial_stats (mcv) -on "a", -"b", -"c" +on a, +b, +c from mcv_lists_partial; analyze mcv_lists_partial; @@ -3562,30 +3258,22 @@ analyze mcv_lists_multi; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE a = 0 AND b = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE a = 0 AND b = 0'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE c = 0 AND d = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE c = 0 AND d = 0'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE b = 0 AND c = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE b = 0 AND c = 0'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE b = 0 OR c = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE b = 0 OR c = 0'); select * @@ -3608,39 +3296,31 @@ from 'SELECT * FROM mcv_lists_multi WHERE a = 0 OR b = 0 OR c = 0 OR d = 0' ); -create statistics mcv_lists_multi_1 (mcv) on "a", "b" from mcv_lists_multi; +create statistics mcv_lists_multi_1 (mcv) on a, b from mcv_lists_multi; -create statistics mcv_lists_multi_2 (mcv) on "c", "d" from mcv_lists_multi; +create statistics mcv_lists_multi_2 (mcv) on c, d from mcv_lists_multi; analyze mcv_lists_multi; select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE a = 0 AND b = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE a = 0 AND b = 0'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE c = 0 AND d = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE c = 0 AND d = 0'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE b = 0 AND c = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE b = 0 AND c = 0'); select * from - check_estimated_rows( - 'SELECT * FROM mcv_lists_multi WHERE b = 0 OR c = 0' - ); + check_estimated_rows('SELECT * FROM mcv_lists_multi WHERE b = 0 OR c = 0'); select * @@ -3762,8 +3442,8 @@ from create statistics expr_stats_1 (mcv) -on "a", -"b", +on a, +b, (2 * a), (3 * b), (a + b), @@ -3820,8 +3500,8 @@ from create statistics expr_stats_1 (mcv) -on "a", -"b", +on a, +b, (b || c), (c || b) from expr_stats; @@ -3842,10 +3522,7 @@ create table expr_stats_incompatible_test ( c1 boolean not null ); -create statistics expr_stat_comp_1 -on "c0", -"c1" -from expr_stats_incompatible_test; +create statistics expr_stat_comp_1 on c0, c1 from expr_stats_incompatible_test; insert into expr_stats_incompatible_test values (1234, false), (5678, true); @@ -3856,14 +3533,11 @@ select from only expr_stats_incompatible_test where - upper('x') like 'x' || cast('[0,1]' as int4range) and - ( - c0 in (0, 1) or c1 - ); + upper('x') like 'x' || cast('[0,1]' as int4range) and (c0 in (0, 1) or c1); drop table expr_stats_incompatible_test; -create schema "tststats"; +create schema tststats; create table tststats.priv_test_tbl ( a int, @@ -3871,16 +3545,12 @@ create table tststats.priv_test_tbl ( ); insert into tststats.priv_test_tbl -select - mod(i, 5), - mod(i, 10) -from - generate_series(1, 100) as s (i); +select mod(i, 5), mod(i, 10) from generate_series(1, 100) as s (i); create statistics tststats.priv_test_stats (mcv) -on "a", -"b" +on a, +b from tststats.priv_test_tbl; analyze tststats.priv_test_tbl; @@ -3890,11 +3560,11 @@ create table stts_t1 ( b int ); -create statistics (ndistinct) on "a", "b" from stts_t1; +create statistics (ndistinct) on a, b from stts_t1; -create statistics (ndistinct, dependencies) on "a", "b" from stts_t1; +create statistics (ndistinct, dependencies) on a, b from stts_t1; -create statistics (ndistinct, dependencies, mcv) on "a", "b" from stts_t1; +create statistics (ndistinct, dependencies, mcv) on a, b from stts_t1; create table stts_t2 ( a int, @@ -3902,7 +3572,7 @@ create table stts_t2 ( c int ); -create statistics on "b", "c" from stts_t2; +create statistics on b, c from stts_t2; create table stts_t3 ( col1 int, @@ -3910,19 +3580,18 @@ create table stts_t3 ( col3 int ); -create statistics stts_hoge on "col1", "col2", "col3" from stts_t3; +create statistics stts_hoge on col1, col2, col3 from stts_t3; -create schema "stts_s1"; +create schema stts_s1; -create schema "stts_s2"; +create schema stts_s2; -create statistics stts_s1.stts_foo on "col1", "col2" from stts_t3; +create statistics stts_s1.stts_foo on col1, col2 from stts_t3; create statistics stts_s2.stts_yama -(dependencies, -mcv) -on "col1", -"col3" +(dependencies, mcv) +on col1, +col3 from stts_t3; insert into stts_t1 select i, i from generate_series(1, 100) as i; @@ -3931,9 +3600,9 @@ analyze stts_t1; set search_path to public, stts_s1, stts_s2, tststats; -create statistics (mcv) on "a", "b", (a + b), (a - b) from stts_t1; +create statistics (mcv) on a, b, (a + b), (a - b) from stts_t1; -create statistics (mcv) on "a", "b", (a + b), (a - b) from stts_t1; +create statistics (mcv) on a, b, (a + b), (a - b) from stts_t1; create statistics (mcv) on (a + b), (a - b) from stts_t1; @@ -3961,7 +3630,7 @@ reset search_path; create user regress_stats_user1; -grant USAGE on schema tststats to regress_stats_user1; +grant usage on schema tststats to regress_stats_user1; set session authorization regress_stats_user1; @@ -3972,32 +3641,31 @@ select from tststats.priv_test_tbl where - a = 1 and - tststats.priv_test_tbl.* > (1, 1) is not null; + a = 1 and tststats.priv_test_tbl.* > (1, 1) is not null; create function op_leak(int, int) -returns boolean +returns bool language plpgsql -as $function$ -BEGIN RAISE NOTICE 'op_leak => %, %', $1, $2; RETURN $1 < $2; END -$function$; +as 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'; -create operator <<< (PROCEDURE = op_leak, -LEFTARG = int, -RIGHTARG = int, -RESTRICT = scalarltsel); +create operator <<< ( + procedure = op_leak, + leftarg = int, + rightarg = int, + restrict = scalarltsel +); create function op_leak(record, record) -returns boolean +returns bool language plpgsql -as $function$ -BEGIN RAISE NOTICE 'op_leak => %, %', $1, $2; RETURN $1 < $2; END -$function$; +as 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'; -create operator <<< (PROCEDURE = op_leak, -LEFTARG = record, -RIGHTARG = record, -RESTRICT = scalarltsel); +create operator <<< ( + procedure = op_leak, + leftarg = record, + rightarg = record, + restrict = scalarltsel +); select * from tststats.priv_test_tbl where a <<< 0 and b <<< 0; @@ -4008,10 +3676,7 @@ select from tststats.priv_test_tbl as t where - a <<< 0 and - ( - b <<< 0 or t.* <<< (1, 1) is not null - ); + a <<< 0 and (b <<< 0 or t.* <<< (1, 1) is not null); delete from tststats.priv_test_tbl where a <<< 0 and b <<< 0; @@ -4019,14 +3684,9 @@ reset session_authorization; create view tststats.priv_test_view with (security_barrier = 'true') -as select - * -from - tststats.priv_test_tbl -where - false; +as select * from tststats.priv_test_tbl where false; -grant SELECT, DELETE on table tststats.priv_test_view to regress_stats_user1; +grant select, delete on table tststats.priv_test_view to regress_stats_user1; set session authorization regress_stats_user1; @@ -4039,10 +3699,7 @@ select from tststats.priv_test_view as t where - a <<< 0 and - ( - b <<< 0 or t.* <<< (1, 1) is not null - ); + a <<< 0 and (b <<< 0 or t.* <<< (1, 1) is not null); delete from tststats.priv_test_view where a <<< 0 and b <<< 0; @@ -4058,7 +3715,7 @@ for all to public using (2 * a < 0); -grant SELECT, DELETE on table tststats.priv_test_tbl to regress_stats_user1; +grant select, delete on table tststats.priv_test_tbl to regress_stats_user1; set session authorization regress_stats_user1; @@ -4071,10 +3728,7 @@ select from tststats.priv_test_tbl as t where - a <<< 0 and - ( - b <<< 0 or t.* <<< (1, 1) is not null - ); + a <<< 0 and (b <<< 0 or t.* <<< (1, 1) is not null); delete from tststats.priv_test_tbl where a <<< 0 and b <<< 0; @@ -4099,10 +3753,7 @@ select from tststats.priv_test_parent_tbl as t where - a <<< 0 and - ( - b <<< 0 or t.* <<< (1, 1) is not null - ); + a <<< 0 and (b <<< 0 or t.* <<< (1, 1) is not null); delete from tststats.priv_test_parent_tbl where a <<< 0 and b <<< 0; @@ -4118,8 +3769,8 @@ for all to public using (2 * a < 0); -grant SELECT, -DELETE +grant select, +delete on table tststats.priv_test_parent_tbl to regress_stats_user1; @@ -4134,25 +3785,20 @@ select from tststats.priv_test_parent_tbl as t where - a <<< 0 and - ( - b <<< 0 or t.* <<< (1, 1) is not null - ); + a <<< 0 and (b <<< 0 or t.* <<< (1, 1) is not null); delete from tststats.priv_test_parent_tbl where a <<< 0 and b <<< 0; reset session_authorization; create table stats_ext_tbl ( - id int - primary key - generated by default as identity, + id int primary key generated by default as identity, col text ); insert into stats_ext_tbl (col) values ('secret'), ('secret'), ('very secret'); -create statistics s_col on "id", "col" from stats_ext_tbl; +create statistics s_col on id, col from stats_ext_tbl; create statistics s_expr on (mod(id, 2)), (lower(col)) from stats_ext_tbl; @@ -4225,16 +3871,11 @@ insert into grouping_unique (x) select gs from generate_series(1, 1000) as gs; analyze grouping_unique; -select - * -from - check_estimated_rows( - ' +select * from check_estimated_rows(' SELECT * FROM generate_series(1, 1) t1 LEFT JOIN ( SELECT x FROM grouping_unique t2 GROUP BY x) AS q1 ON t1.t1 = q1.x; -' - ); +'); drop table grouping_unique; @@ -4261,7 +3902,7 @@ analyze sb_1, sb_2; select * from sb_1 as a, sb_2 as b where a.x = b.x and a.y = b.y and a.z = b.z; -create statistics extstat_sb_2 (ndistinct) on "x", "y", "z" from sb_2; +create statistics extstat_sb_2 (ndistinct) on x, y, z from sb_2; analyze sb_2; @@ -4278,22 +3919,18 @@ from sb_1 left outer join sb_2 - on sb_2.x = sb_1.x and - sb_1.x = sb_2.x and - sb_1.y = sb_2.y; + on sb_2.x = sb_1.x and sb_1.x = sb_2.x and sb_1.y = sb_2.y; reset enable_nestloop; reset enable_mergejoin; create function extstat_small(x numeric) -returns boolean +returns bool language plpgsql immutable strict -as $function$ -BEGIN RETURN x < 1; END -$function$; +as $$ BEGIN RETURN x < 1; END $$; select * from check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)'); @@ -4305,4 +3942,4 @@ select * from check_estimated_rows('SELECT * FROM sb_2 WHERE extstat_small(y)'); drop table sb_1, sb_2 cascade; -drop function extstat_small(numeric); +drop function extstat_small(x numeric); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_import_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_import_100.snap index daf826255..db75fd92c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_import_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_import_100.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/stats_import.sql snapshot_kind: text --- -create schema "stats_import"; +create schema stats_import; create type stats_import.complex_type as (a int, b real, c text, d date, e jsonb); @@ -17,7 +17,7 @@ create table stats_import.test ( with (autovacuum_enabled = 'false'); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -32,7 +32,7 @@ select cast(27 as int) ); -create index "test_i" on stats_import.test using btree (id); +create index test_i on stats_import.test using btree (id); select relname, @@ -48,12 +48,13 @@ order by relname; select pg_clear_relation_stats('stats_import', 'test'); -select pg_restore_relation_stats('relname', 'test', 'relpages', cast(17 as int)); +select pg_catalog.pg_restore_relation_stats('relname', 'test', 'relpages', cast(17 as int)); -select pg_restore_relation_stats('schemaname', 'stats_import', 'relpages', cast(17 as int)); +select + pg_catalog.pg_restore_relation_stats('schemaname', 'stats_import', 'relpages', cast(17 as int)); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', cast(3.6 as double precision), 'relname', @@ -63,7 +64,7 @@ select ); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -73,7 +74,7 @@ select ); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -107,7 +108,7 @@ where begin; select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -121,18 +122,14 @@ select from pg_locks where - relation = cast('stats_import.test' as regclass) and - pid = pg_backend_pid() and - granted; + relation = cast('stats_import.test' as regclass) and pid = pg_backend_pid() and granted; select mode from pg_locks where - relation = cast('stats_import.test_i' as regclass) and - pid = pg_backend_pid() and - granted; + relation = cast('stats_import.test_i' as regclass) and pid = pg_backend_pid() and granted; commit; @@ -144,7 +141,7 @@ partition of stats_import.part_parent for values from (0) to (10) with (autovacuum_enabled = 'false'); -create index "part_parent_i" on stats_import.part_parent using btree (i); +create index part_parent_i on stats_import.part_parent using btree (i); analyze stats_import.part_parent; @@ -153,7 +150,7 @@ select relpages from pg_class where oid = cast('stats_import.part_parent' as reg begin; select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -167,20 +164,14 @@ select from pg_locks where - relation = - cast('stats_import.part_parent' as regclass) and - pid = pg_backend_pid() and - granted; + relation = cast('stats_import.part_parent' as regclass) and pid = pg_backend_pid() and granted; select mode from pg_locks where - relation = - cast('stats_import.part_parent_i' as regclass) and - pid = pg_backend_pid() and - granted; + relation = cast('stats_import.part_parent_i' as regclass) and pid = pg_backend_pid() and granted; commit; @@ -343,7 +334,7 @@ from where oid = cast('stats_import.test' as regclass); -select pg_clear_relation_stats("schemaname" := 'stats_import', "relname" := 'test'); +select pg_catalog.pg_clear_relation_stats(schemaname := 'stats_import', relname := 'test'); select relpages, @@ -356,17 +347,17 @@ where create sequence stats_import.testseq; -select pg_restore_relation_stats('schemaname', 'stats_import', 'relname', 'testseq'); +select pg_catalog.pg_restore_relation_stats('schemaname', 'stats_import', 'relname', 'testseq'); -select pg_clear_relation_stats("schemaname" := 'stats_import', "relname" := 'testseq'); +select pg_catalog.pg_clear_relation_stats(schemaname := 'stats_import', relname := 'testseq'); create view stats_import.testview as select * from stats_import.test; -select pg_clear_relation_stats("schemaname" := 'stats_import', "relname" := 'testview'); +select pg_catalog.pg_clear_relation_stats(schemaname := 'stats_import', relname := 'testview'); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'relname', 'test', 'attname', @@ -378,7 +369,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'nope', 'relname', @@ -392,7 +383,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'attname', @@ -404,7 +395,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -418,7 +409,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -432,7 +423,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -446,7 +437,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -464,7 +455,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -480,7 +471,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -492,7 +483,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -506,7 +497,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -520,7 +511,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -544,13 +535,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -568,13 +556,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -594,13 +579,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -620,13 +602,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -646,13 +625,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -674,13 +650,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -702,13 +675,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -728,13 +698,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -754,13 +721,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -778,13 +742,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -804,13 +765,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'tags'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -831,13 +789,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'tags'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -859,13 +814,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -885,13 +837,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'arange'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -911,13 +860,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'arange'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -937,13 +883,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'arange'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -955,8 +898,7 @@ select 'null_frac', cast(0.31 as real), 'range_bounds_histogram', - cast('{"[-1,1)","[0,4)","[1,4)","[1,100)"}' - as text) + cast('{"[-1,1)","[0,4)","[1,4)","[1,100)"}' as text) ); select @@ -964,13 +906,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -980,8 +919,7 @@ select 'inherited', cast(false as boolean), 'range_bounds_histogram', - cast('{"[-1,1)","[0,4)","[1,4)","[1,100)"}' - as text) + cast('{"[-1,1)","[0,4)","[1,4)","[1,100)"}' as text) ); select @@ -989,13 +927,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'arange'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1017,13 +952,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'arange'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1045,13 +977,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1071,13 +1000,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'tags'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1097,13 +1023,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'tags'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1123,13 +1046,10 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'tags'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1149,49 +1069,39 @@ select from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'id'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'id'; insert into stats_import.test select 1, 'one', - cast((1, - 1.1, - 'ONE', - '2001-01-01', - '{ "xkey": "xval" }') - as stats_import.complex_type), + cast((1, 1.1, 'ONE', '2001-01-01', '{ "xkey": "xval" }') as stats_import.complex_type), int4range(1, 4), array['red', 'green'] union all select 2, 'two', - cast((2, 2.2, 'TWO', '2002-02-02', '[true, 4, "six"]') - as stats_import.complex_type), + cast((2, 2.2, 'TWO', '2002-02-02', '[true, 4, "six"]') as stats_import.complex_type), int4range(1, 4), array['blue', 'yellow'] union all select 3, 'tre', - cast((3, 3.3, 'TRE', '2003-03-03', null) - as stats_import.complex_type), + cast((3, 3.3, 'TRE', '2003-03-03', null) as stats_import.complex_type), int4range(-1, 1), array['"orange"', 'purple', 'cyan'] union all select 4, 'four', null, int4range(0, 100), null; -create index "is_odd" on stats_import.test using btree (((comp).a % 2 = 1)); +create index is_odd on stats_import.test using btree (((comp).a % 2 = 1)); analyze stats_import.test; create table stats_import.test_clone (like stats_import.test) with (autovacuum_enabled = 'false'); -create index "is_odd_clone" on stats_import.test_clone using btree (((comp).a % 2 = 1)); +create index is_odd_clone on stats_import.test_clone using btree (((comp).a % 2 = 1)); select s.schemaname, @@ -1202,7 +1112,7 @@ select from pg_catalog.pg_stats as s inner join - lateral pg_restore_attribute_stats( + lateral pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1243,27 +1153,19 @@ from as r on true where - s.schemaname = 'stats_import' and - s.tablename in ('test', 'is_odd') + s.schemaname = 'stats_import' and s.tablename in ('test', 'is_odd') order by s.tablename, s.attname, s.inherited; select c.relname, - COUNT(*) as num_stats + count(*) as num_stats from - pg_class as c - inner join - pg_statistic as s - on s.starelid = c.oid + pg_class as c inner join pg_statistic as s on s.starelid = c.oid where - c.relnamespace = - cast('stats_import' as regnamespace) and - c.relname - in ( - 'test', 'test_clone', 'is_odd', 'is_odd_clone' - ) + c.relnamespace = cast('stats_import' as regnamespace) and + c.relname in ('test', 'test_clone', 'is_odd', 'is_odd_clone') group by c.relname order by c.relname; @@ -1345,8 +1247,7 @@ from pg_attribute as a on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.test_clone' as regclass); + s.starelid = cast('stats_import.test_clone' as regclass); select a.attname, @@ -1386,8 +1287,7 @@ from pg_attribute as a on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.test_clone' as regclass) + s.starelid = cast('stats_import.test_clone' as regclass) except select a.attname, @@ -1467,8 +1367,7 @@ from pg_attribute as a on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.is_odd' as regclass) + s.starelid = cast('stats_import.is_odd' as regclass) except select a.attname, @@ -1508,8 +1407,7 @@ from pg_attribute as a on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.is_odd_clone' as regclass); + s.starelid = cast('stats_import.is_odd_clone' as regclass); select a.attname, @@ -1549,8 +1447,7 @@ from pg_attribute as a on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.is_odd_clone' as regclass) + s.starelid = cast('stats_import.is_odd_clone' as regclass) except select a.attname, @@ -1590,36 +1487,29 @@ from pg_attribute as a on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.is_odd' as regclass); + s.starelid = cast('stats_import.is_odd' as regclass); select - COUNT(*) + count(*) from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'arange'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'arange'; select - pg_clear_attribute_stats( - "schemaname" := 'stats_import', - "relname" := 'test', - "attname" := 'arange', - "inherited" := false + pg_catalog.pg_clear_attribute_stats( + schemaname := 'stats_import', + relname := 'test', + attname := 'arange', + inherited := false ); select - COUNT(*) + count(*) from pg_stats where - schemaname = 'stats_import' and - tablename = 'test' and - inherited = false and - attname = 'arange'; + schemaname = 'stats_import' and tablename = 'test' and inherited = false and attname = 'arange'; create temporary table stats_temp (i int); @@ -1652,7 +1542,7 @@ where order by relname; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'pg_temp', 'relname', @@ -1671,10 +1561,7 @@ select from pg_stats where - schemaname like 'pg_temp%' and - tablename = 'stats_temp' and - inherited = false and - attname = 'i'; + schemaname like 'pg_temp%' and tablename = 'stats_temp' and inherited = false and attname = 'i'; drop table stats_temp; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_import_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_import_80.snap index 769a8d970..2b3498a9e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_import_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_import_80.snap @@ -2,7 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/stats_import.sql --- -create schema "stats_import"; +create schema stats_import; create type stats_import.complex_type as ( a int, @@ -22,7 +22,7 @@ create table stats_import.test ( with (autovacuum_enabled = 'false'); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -37,7 +37,7 @@ select cast(27 as int) ); -create index "test_i" on stats_import.test using btree (id); +create index test_i on stats_import.test using btree (id); select relname, @@ -48,14 +48,13 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass) + oid = cast('stats_import.test' as regclass) order by relname; select pg_clear_relation_stats('stats_import', 'test'); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'relname', 'test', 'relpages', @@ -63,7 +62,7 @@ select ); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relpages', @@ -71,7 +70,7 @@ select ); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', cast(3.6 as double precision), 'relname', @@ -81,7 +80,7 @@ select ); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -91,7 +90,7 @@ select ); select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -127,13 +126,12 @@ select from pg_class where - oid = - cast('stats_import.test_i' as regclass); + oid = cast('stats_import.test_i' as regclass); begin; select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -147,8 +145,7 @@ select from pg_locks where - relation = - cast('stats_import.test' as regclass) and + relation = cast('stats_import.test' as regclass) and pid = pg_backend_pid() and granted; @@ -157,8 +154,7 @@ select from pg_locks where - relation = - cast('stats_import.test_i' as regclass) and + relation = cast('stats_import.test_i' as regclass) and pid = pg_backend_pid() and granted; @@ -172,7 +168,7 @@ partition of stats_import.part_parent for values from (0) to (10) with (autovacuum_enabled = 'false'); -create index "part_parent_i" on stats_import.part_parent using btree (i); +create index part_parent_i on stats_import.part_parent using btree (i); analyze stats_import.part_parent; @@ -181,14 +177,12 @@ select from pg_class where - oid = - cast('stats_import.part_parent' - as regclass); + oid = cast('stats_import.part_parent' as regclass); begin; select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -202,9 +196,7 @@ select from pg_locks where - relation = - cast('stats_import.part_parent' - as regclass) and + relation = cast('stats_import.part_parent' as regclass) and pid = pg_backend_pid() and granted; @@ -213,9 +205,7 @@ select from pg_locks where - relation = - cast('stats_import.part_parent_i' - as regclass) and + relation = cast('stats_import.part_parent_i' as regclass) and pid = pg_backend_pid() and granted; @@ -226,9 +216,7 @@ select from pg_class where - oid = - cast('stats_import.part_parent_i' - as regclass); + oid = cast('stats_import.part_parent_i' as regclass); select pg_restore_relation_stats( @@ -256,8 +244,7 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass); + oid = cast('stats_import.test' as regclass); select pg_restore_relation_stats( @@ -277,8 +264,7 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass); + oid = cast('stats_import.test' as regclass); select pg_restore_relation_stats( @@ -298,8 +284,7 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass); + oid = cast('stats_import.test' as regclass); select pg_restore_relation_stats( @@ -319,8 +304,7 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass); + oid = cast('stats_import.test' as regclass); select pg_restore_relation_stats( @@ -342,8 +326,7 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass); + oid = cast('stats_import.test' as regclass); select pg_restore_relation_stats( @@ -369,8 +352,7 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass); + oid = cast('stats_import.test' as regclass); select pg_restore_relation_stats( @@ -391,13 +373,12 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass); + oid = cast('stats_import.test' as regclass); select - pg_clear_relation_stats( - "schemaname" := 'stats_import', - "relname" := 'test' + pg_catalog.pg_clear_relation_stats( + schemaname := 'stats_import', + relname := 'test' ); select @@ -407,13 +388,12 @@ select from pg_class where - oid = - cast('stats_import.test' as regclass); + oid = cast('stats_import.test' as regclass); create sequence stats_import.testseq; select - pg_restore_relation_stats( + pg_catalog.pg_restore_relation_stats( 'schemaname', 'stats_import', 'relname', @@ -421,22 +401,22 @@ select ); select - pg_clear_relation_stats( - "schemaname" := 'stats_import', - "relname" := 'testseq' + pg_catalog.pg_clear_relation_stats( + schemaname := 'stats_import', + relname := 'testseq' ); create view stats_import.testview as select * from stats_import.test; select - pg_clear_relation_stats( - "schemaname" := 'stats_import', - "relname" := 'testview' + pg_catalog.pg_clear_relation_stats( + schemaname := 'stats_import', + relname := 'testview' ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'relname', 'test', 'attname', @@ -448,7 +428,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'nope', 'relname', @@ -462,7 +442,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'attname', @@ -474,7 +454,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -488,7 +468,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -502,7 +482,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -516,7 +496,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -534,7 +514,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -550,7 +530,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -562,7 +542,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -576,7 +556,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -590,7 +570,7 @@ select ); select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -620,7 +600,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -644,7 +624,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -670,7 +650,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -696,7 +676,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -722,7 +702,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -750,7 +730,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -778,7 +758,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -804,7 +784,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -830,7 +810,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -854,7 +834,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -880,7 +860,7 @@ where attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -907,7 +887,7 @@ where attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -935,7 +915,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -961,7 +941,7 @@ where attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -987,7 +967,7 @@ where attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1013,7 +993,7 @@ where attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1025,8 +1005,7 @@ select 'null_frac', cast(0.31 as real), 'range_bounds_histogram', - cast('{"[-1,1)","[0,4)","[1,4)","[1,100)"}' - as text) + cast('{"[-1,1)","[0,4)","[1,4)","[1,100)"}' as text) ); select @@ -1040,7 +1019,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1050,8 +1029,7 @@ select 'inherited', cast(false as boolean), 'range_bounds_histogram', - cast('{"[-1,1)","[0,4)","[1,4)","[1,100)"}' - as text) + cast('{"[-1,1)","[0,4)","[1,4)","[1,100)"}' as text) ); select @@ -1065,7 +1043,7 @@ where attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1093,7 +1071,7 @@ where attname = 'arange'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1121,7 +1099,7 @@ where attname = 'id'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1147,7 +1125,7 @@ where attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1173,7 +1151,7 @@ where attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1199,7 +1177,7 @@ where attname = 'tags'; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1228,11 +1206,7 @@ insert into stats_import.test select 1, 'one', - cast((1, - 1.1, - 'ONE', - '2001-01-01', - '{ "xkey": "xval" }') + cast((1, 1.1, 'ONE', '2001-01-01', '{ "xkey": "xval" }') as stats_import.complex_type), int4range(1, 4), array['red', 'green'] @@ -1240,11 +1214,7 @@ union all select 2, 'two', - cast((2, - 2.2, - 'TWO', - '2002-02-02', - '[true, 4, "six"]') + cast((2, 2.2, 'TWO', '2002-02-02', '[true, 4, "six"]') as stats_import.complex_type), int4range(1, 4), array['blue', 'yellow'] @@ -1252,29 +1222,20 @@ union all select 3, 'tre', - cast((3, 3.3, 'TRE', '2003-03-03', null) - as stats_import.complex_type), + cast((3, 3.3, 'TRE', '2003-03-03', null) as stats_import.complex_type), int4range(-1, 1), array['"orange"', 'purple', 'cyan'] union all -select - 4, - 'four', - null, - int4range(0, 100), - null; +select 4, 'four', null, int4range(0, 100), null; -create index "is_odd" on stats_import.test using btree (((comp).a % 2 = 1)); +create index is_odd on stats_import.test using btree (((comp).a % 2 = 1)); analyze stats_import.test; create table stats_import.test_clone (like stats_import.test) with (autovacuum_enabled = 'false'); -create index "is_odd_clone" -on stats_import.test_clone -using btree -( +create index is_odd_clone on stats_import.test_clone using btree ( ((comp).a % 2 = 1) ); @@ -1287,7 +1248,7 @@ select from pg_catalog.pg_stats as s inner join - lateral pg_restore_attribute_stats( + lateral pg_catalog.pg_restore_attribute_stats( 'schemaname', 'stats_import', 'relname', @@ -1328,27 +1289,19 @@ from as r on true where - s.schemaname = 'stats_import' and - s.tablename in ('test', 'is_odd') + s.schemaname = 'stats_import' and s.tablename in ('test', 'is_odd') order by s.tablename, s.attname, s.inherited; select c.relname, - COUNT(*) as num_stats + count(*) as num_stats from - pg_class as c - inner join - pg_statistic as s - on s.starelid = c.oid + pg_class as c inner join pg_statistic as s on s.starelid = c.oid where - c.relnamespace = - cast('stats_import' as regnamespace) and - c.relname - in ( - 'test', 'test_clone', 'is_odd', 'is_odd_clone' - ) + c.relnamespace = cast('stats_import' as regnamespace) and + c.relname in ('test', 'test_clone', 'is_odd', 'is_odd_clone') group by c.relname order by c.relname; @@ -1388,11 +1341,9 @@ from pg_statistic as s inner join pg_attribute as a - on a.attrelid = s.starelid and - a.attnum = s.staattnum + on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.test' as regclass) + s.starelid = cast('stats_import.test' as regclass) except select a.attname, @@ -1430,12 +1381,9 @@ from pg_statistic as s inner join pg_attribute as a - on a.attrelid = s.starelid and - a.attnum = s.staattnum + on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.test_clone' - as regclass); + s.starelid = cast('stats_import.test_clone' as regclass); select a.attname, @@ -1473,12 +1421,9 @@ from pg_statistic as s inner join pg_attribute as a - on a.attrelid = s.starelid and - a.attnum = s.staattnum + on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.test_clone' - as regclass) + s.starelid = cast('stats_import.test_clone' as regclass) except select a.attname, @@ -1516,11 +1461,9 @@ from pg_statistic as s inner join pg_attribute as a - on a.attrelid = s.starelid and - a.attnum = s.staattnum + on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.test' as regclass); + s.starelid = cast('stats_import.test' as regclass); select a.attname, @@ -1558,11 +1501,9 @@ from pg_statistic as s inner join pg_attribute as a - on a.attrelid = s.starelid and - a.attnum = s.staattnum + on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.is_odd' as regclass) + s.starelid = cast('stats_import.is_odd' as regclass) except select a.attname, @@ -1600,12 +1541,9 @@ from pg_statistic as s inner join pg_attribute as a - on a.attrelid = s.starelid and - a.attnum = s.staattnum + on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.is_odd_clone' - as regclass); + s.starelid = cast('stats_import.is_odd_clone' as regclass); select a.attname, @@ -1643,12 +1581,9 @@ from pg_statistic as s inner join pg_attribute as a - on a.attrelid = s.starelid and - a.attnum = s.staattnum + on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.is_odd_clone' - as regclass) + s.starelid = cast('stats_import.is_odd_clone' as regclass) except select a.attname, @@ -1686,14 +1621,12 @@ from pg_statistic as s inner join pg_attribute as a - on a.attrelid = s.starelid and - a.attnum = s.staattnum + on a.attrelid = s.starelid and a.attnum = s.staattnum where - s.starelid = - cast('stats_import.is_odd' as regclass); + s.starelid = cast('stats_import.is_odd' as regclass); select - COUNT(*) + count(*) from pg_stats where @@ -1703,15 +1636,15 @@ where attname = 'arange'; select - pg_clear_attribute_stats( - "schemaname" := 'stats_import', - "relname" := 'test', - "attname" := 'arange', - "inherited" := false + pg_catalog.pg_clear_attribute_stats( + schemaname := 'stats_import', + relname := 'test', + attname := 'arange', + inherited := false ); select - COUNT(*) + count(*) from pg_stats where @@ -1747,12 +1680,11 @@ select from pg_class where - oid = - cast('pg_temp.stats_temp' as regclass) + oid = cast('pg_temp.stats_temp' as regclass) order by relname; select - pg_restore_attribute_stats( + pg_catalog.pg_restore_attribute_stats( 'schemaname', 'pg_temp', 'relname', diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__strings_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__strings_100.snap index 09c75b487..73788c0c1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__strings_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__strings_100.snap @@ -107,57 +107,57 @@ select cast(f1 as varchar) as "varchar(char)" from char_tbl; select cast(cast('namefield' as name) as varchar) as "varchar(name)"; -select btrim(' bunch o blanks ') = 'bunch o blanks' as "bunch o blanks"; +select trim(' bunch o blanks ') = 'bunch o blanks' as "bunch o blanks"; -select ltrim(' bunch o blanks ') = 'bunch o blanks ' as "bunch o blanks "; +select trim(leading ' bunch o blanks ') = 'bunch o blanks ' as "bunch o blanks "; -select rtrim(' bunch o blanks ') = ' bunch o blanks' as " bunch o blanks"; +select trim(trailing ' bunch o blanks ') = ' bunch o blanks' as " bunch o blanks"; -select btrim('xxxxxsome Xsxxxxx', 'x') = 'some Xs' as "some Xs"; +select trim('x' from 'xxxxxsome Xsxxxxx') = 'some Xs' as "some Xs"; -select SUBSTRING('1234567890' from 3) = '34567890' as "34567890"; +select substring('1234567890' from 3) = '34567890' as "34567890"; -select SUBSTRING('1234567890' from 4 for 3) = '456' as "456"; +select substring('1234567890' from 4 for 3) = '456' as "456"; -select SUBSTRING('string' from 2 for 2147483646) as tring; +select substring('string' from 2 for 2147483646) as tring; -select SUBSTRING('string' from -10 for 2147483646) as string; +select substring('string' from -10 for 2147483646) as string; -select SUBSTRING('string' from -10 for -2147483646) as error; +select substring('string' from -10 for -2147483646) as error; -select SUBSTRING('abcdefg' from 'a#"(b_d)#"%' for '#') as bcd; +select substring('abcdefg' from 'a#"(b_d)#"%' for '#') as bcd; -select SUBSTRING('abcdefg' from 'a#"(b_d)#"%' for '#') as bcd; +select substring('abcdefg' from 'a#"(b_d)#"%' for '#') as bcd; -select SUBSTRING('abcdefg' from '#"(b_d)#"%' for '#') is null as "True"; +select substring('abcdefg' from '#"(b_d)#"%' for '#') is null as "True"; -select SUBSTRING('abcdefg' from '%' for null) is null as "True"; +select substring('abcdefg' from '%' for null) is null as "True"; -select SUBSTRING(null from '%' for '#') is null as "True"; +select substring(null from '%' for '#') is null as "True"; -select SUBSTRING('abcdefg' from null for '#') is null as "True"; +select substring('abcdefg' from null for '#') is null as "True"; -select SUBSTRING('abcdefg' from 'a#"%#"g' for '#') as bcdef; +select substring('abcdefg' from 'a#"%#"g' for '#') as bcdef; -select SUBSTRING('abcdefg' from 'a*#"%#"g*' for '#') as abcdefg; +select substring('abcdefg' from 'a*#"%#"g*' for '#') as abcdefg; -select SUBSTRING('abcdefg' from 'a|b#"%#"g' for '#') as bcdef; +select substring('abcdefg' from 'a|b#"%#"g' for '#') as bcdef; -select SUBSTRING('abcdefg' from 'a#"%#"x|g' for '#') as bcdef; +select substring('abcdefg' from 'a#"%#"x|g' for '#') as bcdef; -select SUBSTRING('abcdefg' from 'a#"%|ab#"g' for '#') as bcdef; +select substring('abcdefg' from 'a#"%|ab#"g' for '#') as bcdef; -select SUBSTRING('abcdefg' from 'a*#"%#"g*#"x' for '#') as error; +select substring('abcdefg' from 'a*#"%#"g*#"x' for '#') as error; -select SUBSTRING('abcdefg' from 'a#"%g' for '#') as bcdefg; +select substring('abcdefg' from 'a#"%g' for '#') as bcdefg; -select SUBSTRING('abcdefg' from 'a%g' for '#') as abcdefg; +select substring('abcdefg' from 'a%g' for '#') as abcdefg; -select SUBSTRING('abcdefg' from 'c.e') as cde; +select substring('abcdefg' from 'c.e') as cde; -select SUBSTRING('abcdefg' from 'b(.*)f') as cde; +select substring('abcdefg' from 'b(.*)f') as cde; -select SUBSTRING('foo' from 'foo(bar)?') is null as t; +select substring('foo' from 'foo(bar)?') is null as t; select 'abcdefg' similar to '_bcd%' as "true"; @@ -362,50 +362,23 @@ select regexp_matches('foobarbequebaz', '(bar)(.+)?(beque)'); select regexp_matches('foobarbequebaz', 'barbeque'); select - regexp_matches( - 'foo' || chr(10) || 'bar' || chr(10) || 'bequq' || - chr(10) || - 'baz', - '^', - 'mg' - ); + regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '^', 'mg'); select - regexp_matches( - 'foo' || chr(10) || 'bar' || chr(10) || 'bequq' || - chr(10) || - 'baz', - '$', - 'mg' - ); + regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '$', 'mg'); select - regexp_matches( - '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || - '4' || - chr(10), - '^.?', - 'mg' - ); + regexp_matches('1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '^.?', 'mg'); select regexp_matches( - chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || - chr(10) || - '4' || - chr(10), + chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '.?$', 'mg' ); select - regexp_matches( - chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || - chr(10) || - '4', - '.?$', - 'mg' - ); + regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4', '.?$', 'mg'); select regexp_matches('foobarbequebaz', '(bar)(beque)', 'gz'); @@ -417,11 +390,7 @@ select foo, length(foo) from - regexp_split_to_table( - 'the quick brown fox jumps over the lazy dog', - '\s+' - ) - as foo; + regexp_split_to_table('the quick brown fox jumps over the lazy dog', '\s+') as foo; select regexp_split_to_array('the quick brown fox jumps over the lazy dog', '\s+'); @@ -429,11 +398,7 @@ select foo, length(foo) from - regexp_split_to_table( - 'the quick brown fox jumps over the lazy dog', - '\s*' - ) - as foo; + regexp_split_to_table('the quick brown fox jumps over the lazy dog', '\s*') as foo; select regexp_split_to_array('the quick brown fox jumps over the lazy dog', '\s*'); @@ -441,11 +406,7 @@ select foo, length(foo) from - regexp_split_to_table( - 'the quick brown fox jumps over the lazy dog', - '' - ) - as foo; + regexp_split_to_table('the quick brown fox jumps over the lazy dog', '') as foo; select regexp_split_to_array('the quick brown fox jumps over the lazy dog', ''); @@ -453,12 +414,7 @@ select foo, length(foo) from - regexp_split_to_table( - 'thE QUick bROWn FOx jUMPs ovEr The lazy dOG', - 'e', - 'i' - ) - as foo; + regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i') as foo; select regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i'); @@ -466,11 +422,7 @@ select foo, length(foo) from - regexp_split_to_table( - 'the quick brown fox jumps over the lazy dog', - 'nomatch' - ) - as foo; + regexp_split_to_table('the quick brown fox jumps over the lazy dog', 'nomatch') as foo; select regexp_split_to_array('the quick brown fox jumps over the lazy dog', 'nomatch'); @@ -490,12 +442,7 @@ select foo, length(foo) from - regexp_split_to_table( - 'thE QUick bROWn FOx jUMPs ovEr The lazy dOG', - 'e', - 'zippy' - ) - as foo; + regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'zippy') as foo; select regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'iz'); @@ -503,36 +450,31 @@ select foo, length(foo) from - regexp_split_to_table( - 'thE QUick bROWn FOx jUMPs ovEr The lazy dOG', - 'e', - 'g' - ) - as foo; + regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g') as foo; select regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g'); -select POSITION('4' in '1234567890') = '4' as "4"; +select position('4' in '1234567890') = '4' as "4"; -select POSITION('5' in '1234567890') = '5' as "5"; +select position('5' in '1234567890') = '5' as "5"; -select POSITION(cast('\x11' as bytea) in cast('' as bytea)) = 0 as "0"; +select position(cast('\x11' as bytea) in cast('' as bytea)) = 0 as "0"; -select POSITION(cast('\x33' as bytea) in cast('\x1122' as bytea)) = 0 as "0"; +select position(cast('\x33' as bytea) in cast('\x1122' as bytea)) = 0 as "0"; -select POSITION(cast('' as bytea) in cast('\x1122' as bytea)) = 1 as "1"; +select position(cast('' as bytea) in cast('\x1122' as bytea)) = 1 as "1"; -select POSITION(cast('\x22' as bytea) in cast('\x1122' as bytea)) = 2 as "2"; +select position(cast('\x22' as bytea) in cast('\x1122' as bytea)) = 2 as "2"; -select POSITION(cast('\x5678' as bytea) in cast('\x1234567890' as bytea)) = 3 as "3"; +select position(cast('\x5678' as bytea) in cast('\x1234567890' as bytea)) = 3 as "3"; -select OVERLAY('abcdef' placing '45' from 4) as abc45f; +select overlay('abcdef' placing '45' from 4) as abc45f; -select OVERLAY('yabadoo' placing 'daba' from 5) as yabadaba; +select overlay('yabadoo' placing 'daba' from 5) as yabadaba; -select OVERLAY('yabadoo' placing 'daba' from 5 for 0) as yabadabadoo; +select overlay('yabadoo' placing 'daba' from 5 for 0) as yabadabadoo; -select OVERLAY('babosa' placing 'ubb' from 2 for 4) as bubba; +select overlay('babosa' placing 'ubb' from 2 for 4) as bubba; select 'hawkeye' like 'h%' as "true"; @@ -570,74 +512,73 @@ select cast('abc' as bytea) like cast('_b_' as bytea) as "true"; select cast('abc' as bytea) not like cast('_b_' as bytea) as "false"; -select 'hawkeye' like like_escape('h%', '#') as "true"; +select 'hawkeye' like pg_catalog.like_escape('h%', '#') as "true"; -select 'hawkeye' not like like_escape('h%', '#') as "false"; +select 'hawkeye' not like pg_catalog.like_escape('h%', '#') as "false"; -select 'indio' like like_escape('ind_o', '$') as "true"; +select 'indio' like pg_catalog.like_escape('ind_o', '$') as "true"; -select 'indio' not like like_escape('ind_o', '$') as "false"; +select 'indio' not like pg_catalog.like_escape('ind_o', '$') as "false"; -select 'h%' like like_escape('h#%', '#') as "true"; +select 'h%' like pg_catalog.like_escape('h#%', '#') as "true"; -select 'h%' not like like_escape('h#%', '#') as "false"; +select 'h%' not like pg_catalog.like_escape('h#%', '#') as "false"; -select 'h%wkeye' like like_escape('h#%', '#') as "false"; +select 'h%wkeye' like pg_catalog.like_escape('h#%', '#') as "false"; -select 'h%wkeye' not like like_escape('h#%', '#') as "true"; +select 'h%wkeye' not like pg_catalog.like_escape('h#%', '#') as "true"; -select 'h%wkeye' like like_escape('h#%%', '#') as "true"; +select 'h%wkeye' like pg_catalog.like_escape('h#%%', '#') as "true"; -select 'h%wkeye' not like like_escape('h#%%', '#') as "false"; +select 'h%wkeye' not like pg_catalog.like_escape('h#%%', '#') as "false"; -select 'h%awkeye' like like_escape('h#%a%k%e', '#') as "true"; +select 'h%awkeye' like pg_catalog.like_escape('h#%a%k%e', '#') as "true"; -select 'h%awkeye' not like like_escape('h#%a%k%e', '#') as "false"; +select 'h%awkeye' not like pg_catalog.like_escape('h#%a%k%e', '#') as "false"; -select 'indio' like like_escape('_ndio', '$') as "true"; +select 'indio' like pg_catalog.like_escape('_ndio', '$') as "true"; -select 'indio' not like like_escape('_ndio', '$') as "false"; +select 'indio' not like pg_catalog.like_escape('_ndio', '$') as "false"; -select 'i_dio' like like_escape('i$_d_o', '$') as "true"; +select 'i_dio' like pg_catalog.like_escape('i$_d_o', '$') as "true"; -select 'i_dio' not like like_escape('i$_d_o', '$') as "false"; +select 'i_dio' not like pg_catalog.like_escape('i$_d_o', '$') as "false"; -select 'i_dio' like like_escape('i$_nd_o', '$') as "false"; +select 'i_dio' like pg_catalog.like_escape('i$_nd_o', '$') as "false"; -select 'i_dio' not like like_escape('i$_nd_o', '$') as "true"; +select 'i_dio' not like pg_catalog.like_escape('i$_nd_o', '$') as "true"; -select 'i_dio' like like_escape('i$_d%o', '$') as "true"; +select 'i_dio' like pg_catalog.like_escape('i$_d%o', '$') as "true"; -select 'i_dio' not like like_escape('i$_d%o', '$') as "false"; +select 'i_dio' not like pg_catalog.like_escape('i$_d%o', '$') as "false"; -select cast('a_c' as bytea) like like_escape(cast('a$__' as bytea), cast('$' as bytea)) as "true"; +select + cast('a_c' as bytea) like pg_catalog.like_escape(cast('a$__' as bytea), cast('$' as bytea)) + as "true"; select - cast('a_c' as bytea) not like like_escape( - cast('a$__' as bytea), - cast('$' as bytea) - ) + cast('a_c' as bytea) not like pg_catalog.like_escape(cast('a$__' as bytea), cast('$' as bytea)) as "false"; -select 'maca' like like_escape('m%aca', '%') as "true"; +select 'maca' like pg_catalog.like_escape('m%aca', '%') as "true"; -select 'maca' not like like_escape('m%aca', '%') as "false"; +select 'maca' not like pg_catalog.like_escape('m%aca', '%') as "false"; -select 'ma%a' like like_escape('m%a%%a', '%') as "true"; +select 'ma%a' like pg_catalog.like_escape('m%a%%a', '%') as "true"; -select 'ma%a' not like like_escape('m%a%%a', '%') as "false"; +select 'ma%a' not like pg_catalog.like_escape('m%a%%a', '%') as "false"; -select 'bear' like like_escape('b_ear', '_') as "true"; +select 'bear' like pg_catalog.like_escape('b_ear', '_') as "true"; -select 'bear' not like like_escape('b_ear', '_') as "false"; +select 'bear' not like pg_catalog.like_escape('b_ear', '_') as "false"; -select 'be_r' like like_escape('b_e__r', '_') as "true"; +select 'be_r' like pg_catalog.like_escape('b_e__r', '_') as "true"; -select 'be_r' not like like_escape('b_e__r', '_') as "false"; +select 'be_r' not like pg_catalog.like_escape('b_e__r', '_') as "false"; -select 'be_r' like like_escape('__e__r', '_') as "false"; +select 'be_r' like pg_catalog.like_escape('__e__r', '_') as "false"; -select 'be_r' not like like_escape('__e__r', '_') as "true"; +select 'be_r' not like pg_catalog.like_escape('__e__r', '_') as "true"; select 'hawkeye' ilike 'h%' as "true"; @@ -866,12 +807,7 @@ select to_bin(-cast(1234 as bigint)); select to_bin(256 * 256 * 256 - 1) as "111111111111111111111111"; select - to_bin( - cast(256 as bigint) * cast(256 as bigint) * - cast(256 as bigint) * - cast(256 as bigint) - - 1 - ) + to_bin(cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) - 1) as "11111111111111111111111111111111"; select to_oct(-1234) as "37777775456"; @@ -881,12 +817,7 @@ select to_oct(-cast(1234 as bigint)) as "1777777777777777775456"; select to_oct(256 * 256 * 256 - 1) as "77777777"; select - to_oct( - cast(256 as bigint) * cast(256 as bigint) * - cast(256 as bigint) * - cast(256 as bigint) - - 1 - ) + to_oct(cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) - 1) as "37777777777"; select to_hex(-1234) as fffffb2e; @@ -896,12 +827,7 @@ select to_hex(-cast(1234 as bigint)) as fffffffffffffb2e; select to_hex(256 * 256 * 256 - 1) as ffffff; select - to_hex( - cast(256 as bigint) * cast(256 as bigint) * - cast(256 as bigint) * - cast(256 as bigint) - - 1 - ) + to_hex(cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) - 1) as ffffffff; set bytea_output = hex; @@ -1017,80 +943,68 @@ select set_byte(cast('\x1234567890abcdef00' as bytea), 7, 11); select set_byte(cast('\x1234567890abcdef00' as bytea), 99, 11); select - cast(cast(4660 as smallint) as bytea) as "\x1234", - cast(cast(-4660 as smallint) as bytea) as "\xedcc"; + cast(cast(4660 as int2) as bytea) as "\x1234", + cast(cast(-4660 as int2) as bytea) as "\xedcc"; select - cast(cast(305419896 as int) as bytea) - as "\x12345678", - cast(cast(-305419896 as int) as bytea) - as "\xedcba988"; + cast(cast(305419896 as int4) as bytea) as "\x12345678", + cast(cast(-305419896 as int4) as bytea) as "\xedcba988"; select - cast(cast(0x1122334455667788 as bigint) as bytea) - as "\x1122334455667788", - cast(cast(-0x1122334455667788 as bigint) as bytea) - as "\xeeddccbbaa998878"; + cast(cast(0x1122334455667788 as int8) as bytea) as "\x1122334455667788", + cast(cast(-0x1122334455667788 as int8) as bytea) as "\xeeddccbbaa998878"; -select cast(cast('' as bytea) as smallint) as "0"; +select cast(cast('' as bytea) as int2) as "0"; -select cast(cast('\x12' as bytea) as smallint) as "18"; +select cast(cast('\x12' as bytea) as int2) as "18"; -select cast(cast('\x1234' as bytea) as smallint) as "4460"; +select cast(cast('\x1234' as bytea) as int2) as "4460"; -select cast(cast('\x123456' as bytea) as smallint); +select cast(cast('\x123456' as bytea) as int2); -select cast(cast('' as bytea) as int) as "0"; +select cast(cast('' as bytea) as int4) as "0"; -select cast(cast('\x12' as bytea) as int) as "18"; +select cast(cast('\x12' as bytea) as int4) as "18"; -select cast(cast('\x12345678' as bytea) as int) as "305419896"; +select cast(cast('\x12345678' as bytea) as int4) as "305419896"; -select cast(cast('\x123456789A' as bytea) as int); +select cast(cast('\x123456789A' as bytea) as int4); -select cast(cast('' as bytea) as bigint) as "0"; +select cast(cast('' as bytea) as int8) as "0"; -select cast(cast('\x12' as bytea) as bigint) as "18"; +select cast(cast('\x12' as bytea) as int8) as "18"; -select cast(cast('\x1122334455667788' as bytea) as bigint) as "1234605616436508552"; +select cast(cast('\x1122334455667788' as bytea) as int8) as "1234605616436508552"; -select cast(cast('\x112233445566778899' as bytea) as bigint); +select cast(cast('\x112233445566778899' as bytea) as int8); select - cast(cast('\x8000' as bytea) as smallint) - as "-32768", - cast(cast('\x7FFF' as bytea) as smallint) - as "32767"; + cast(cast('\x8000' as bytea) as int2) as "-32768", + cast(cast('\x7FFF' as bytea) as int2) as "32767"; select - cast(cast('\x80000000' as bytea) as int) - as "-2147483648", - cast(cast('\x7FFFFFFF' as bytea) as int) - as "2147483647"; + cast(cast('\x80000000' as bytea) as int4) as "-2147483648", + cast(cast('\x7FFFFFFF' as bytea) as int4) as "2147483647"; select - cast(cast('\x8000000000000000' as bytea) - as bigint) - as "-9223372036854775808", - cast(cast('\x7FFFFFFFFFFFFFFF' as bytea) - as bigint) - as "9223372036854775807"; + cast(cast('\x8000000000000000' as bytea) as int8) as "-9223372036854775808", + cast(cast('\x7FFFFFFFFFFFFFFF' as bytea) as int8) as "9223372036854775807"; set escape_string_warning = off; set standard_conforming_strings = off; -show "escape_string_warning"; +show escape_string_warning; -show "standard_conforming_strings"; +show standard_conforming_strings; set escape_string_warning = 'on'; set standard_conforming_strings = 'on'; -show "escape_string_warning"; +show escape_string_warning; -show "standard_conforming_strings"; +show standard_conforming_strings; select 'a\bcd' as f1, @@ -1148,21 +1062,21 @@ select repeat('Pg', 4); select repeat('Pg', -4); -select SUBSTRING(cast('1234567890' as bytea) from 3) as "34567890"; +select substring(cast('1234567890' as bytea) from 3) as "34567890"; -select SUBSTRING(cast('1234567890' as bytea) from 4 for 3) as "456"; +select substring(cast('1234567890' as bytea) from 4 for 3) as "456"; -select SUBSTRING(cast('string' as bytea) from 2 for 2147483646) as tring; +select substring(cast('string' as bytea) from 2 for 2147483646) as tring; -select SUBSTRING(cast('string' as bytea) from -10 for 2147483646) as string; +select substring(cast('string' as bytea) from -10 for 2147483646) as string; -select SUBSTRING(cast('string' as bytea) from -10 for -2147483646) as error; +select substring(cast('string' as bytea) from -10 for -2147483646) as error; -select btrim(cast('\000Tom\000' as bytea), cast('\000' as bytea)); +select trim(cast('\000' as bytea) from cast('\000Tom\000' as bytea)); -select ltrim(cast('\000Tom\000' as bytea), cast('\000' as bytea)); +select trim(leading cast('\000' as bytea) from cast('\000Tom\000' as bytea)); -select rtrim(cast('\000Tom\000' as bytea), cast('\000' as bytea)); +select trim(trailing cast('\000' as bytea) from cast('\000Tom\000' as bytea)); select btrim(cast('\000trim\000' as bytea), cast('\000' as bytea)); @@ -1171,20 +1085,14 @@ select btrim(cast('' as bytea), cast('\000' as bytea)); select btrim(cast('\000trim\000' as bytea), cast('' as bytea)); select - encode( - OVERLAY(cast('Th\000omas' as bytea) placing cast('Th\001omas' as bytea) from 2), - 'escape' - ); + encode(overlay(cast('Th\000omas' as bytea) placing cast('Th\001omas' as bytea) from 2), 'escape'); select - encode( - OVERLAY(cast('Th\000omas' as bytea) placing cast('\002\003' as bytea) from 8), - 'escape' - ); + encode(overlay(cast('Th\000omas' as bytea) placing cast('\002\003' as bytea) from 8), 'escape'); select encode( - OVERLAY(cast('Th\000omas' as bytea) placing cast('\002\003' as bytea) from 5 for 3), + overlay(cast('Th\000omas' as bytea) placing cast('\002\003' as bytea) from 5 for 3), 'escape' ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__strings_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__strings_80.snap index c1f47a06d..dd4c5e099 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__strings_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__strings_80.snap @@ -107,57 +107,60 @@ select cast(f1 as varchar) as "varchar(char)" from char_tbl; select cast(cast('namefield' as name) as varchar) as "varchar(name)"; -select btrim(' bunch o blanks ') = 'bunch o blanks' as "bunch o blanks"; +select trim(' bunch o blanks ') = 'bunch o blanks' as "bunch o blanks"; -select ltrim(' bunch o blanks ') = 'bunch o blanks ' as "bunch o blanks "; +select + trim(leading ' bunch o blanks ') = 'bunch o blanks ' as "bunch o blanks "; -select rtrim(' bunch o blanks ') = ' bunch o blanks' as " bunch o blanks"; +select + trim(trailing ' bunch o blanks ') = ' bunch o blanks' + as " bunch o blanks"; -select btrim('xxxxxsome Xsxxxxx', 'x') = 'some Xs' as "some Xs"; +select trim('x' from 'xxxxxsome Xsxxxxx') = 'some Xs' as "some Xs"; -select SUBSTRING('1234567890' from 3) = '34567890' as "34567890"; +select substring('1234567890' from 3) = '34567890' as "34567890"; -select SUBSTRING('1234567890' from 4 for 3) = '456' as "456"; +select substring('1234567890' from 4 for 3) = '456' as "456"; -select SUBSTRING('string' from 2 for 2147483646) as tring; +select substring('string' from 2 for 2147483646) as tring; -select SUBSTRING('string' from -10 for 2147483646) as string; +select substring('string' from -10 for 2147483646) as string; -select SUBSTRING('string' from -10 for -2147483646) as error; +select substring('string' from -10 for -2147483646) as error; -select SUBSTRING('abcdefg' from 'a#"(b_d)#"%' for '#') as bcd; +select substring('abcdefg' from 'a#"(b_d)#"%' for '#') as bcd; -select SUBSTRING('abcdefg' from 'a#"(b_d)#"%' for '#') as bcd; +select substring('abcdefg' from 'a#"(b_d)#"%' for '#') as bcd; -select SUBSTRING('abcdefg' from '#"(b_d)#"%' for '#') is null as "True"; +select substring('abcdefg' from '#"(b_d)#"%' for '#') is null as "True"; -select SUBSTRING('abcdefg' from '%' for null) is null as "True"; +select substring('abcdefg' from '%' for null) is null as "True"; -select SUBSTRING(null from '%' for '#') is null as "True"; +select substring(null from '%' for '#') is null as "True"; -select SUBSTRING('abcdefg' from null for '#') is null as "True"; +select substring('abcdefg' from null for '#') is null as "True"; -select SUBSTRING('abcdefg' from 'a#"%#"g' for '#') as bcdef; +select substring('abcdefg' from 'a#"%#"g' for '#') as bcdef; -select SUBSTRING('abcdefg' from 'a*#"%#"g*' for '#') as abcdefg; +select substring('abcdefg' from 'a*#"%#"g*' for '#') as abcdefg; -select SUBSTRING('abcdefg' from 'a|b#"%#"g' for '#') as bcdef; +select substring('abcdefg' from 'a|b#"%#"g' for '#') as bcdef; -select SUBSTRING('abcdefg' from 'a#"%#"x|g' for '#') as bcdef; +select substring('abcdefg' from 'a#"%#"x|g' for '#') as bcdef; -select SUBSTRING('abcdefg' from 'a#"%|ab#"g' for '#') as bcdef; +select substring('abcdefg' from 'a#"%|ab#"g' for '#') as bcdef; -select SUBSTRING('abcdefg' from 'a*#"%#"g*#"x' for '#') as error; +select substring('abcdefg' from 'a*#"%#"g*#"x' for '#') as error; -select SUBSTRING('abcdefg' from 'a#"%g' for '#') as bcdefg; +select substring('abcdefg' from 'a#"%g' for '#') as bcdefg; -select SUBSTRING('abcdefg' from 'a%g' for '#') as abcdefg; +select substring('abcdefg' from 'a%g' for '#') as abcdefg; -select SUBSTRING('abcdefg' from 'c.e') as cde; +select substring('abcdefg' from 'c.e') as cde; -select SUBSTRING('abcdefg' from 'b(.*)f') as cde; +select substring('abcdefg' from 'b(.*)f') as cde; -select SUBSTRING('foo' from 'foo(bar)?') is null as t; +select substring('foo' from 'foo(bar)?') is null as t; select 'abcdefg' similar to '_bcd%' as "true"; @@ -341,15 +344,7 @@ select regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 3); select regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 4); select - regexp_substr( - '1234567890', - '(123)(4(56)(78))', - 1, - 1, - 'i', - 5 - ) is null - as t; + regexp_substr('1234567890', '(123)(4(56)(78))', 1, 1, 'i', 5) is null as t; select regexp_substr('foo', 'foo(bar)?', 1, 1, '', 1) is null as t; @@ -377,41 +372,28 @@ select regexp_matches('foobarbequebaz', 'barbeque'); select regexp_matches( - 'foo' || chr(10) || 'bar' || chr(10) || - 'bequq' || - chr(10) || - 'baz', + 'foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '^', 'mg' ); select regexp_matches( - 'foo' || chr(10) || 'bar' || chr(10) || - 'bequq' || - chr(10) || - 'baz', + 'foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '$', 'mg' ); select regexp_matches( - '1' || chr(10) || '2' || chr(10) || '3' || - chr(10) || - '4' || - chr(10), + '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '^.?', 'mg' ); select regexp_matches( - chr(10) || '1' || chr(10) || '2' || - chr(10) || - '3' || - chr(10) || - '4' || + chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '.?$', 'mg' @@ -419,11 +401,7 @@ select select regexp_matches( - chr(10) || '1' || chr(10) || '2' || - chr(10) || - '3' || - chr(10) || - '4', + chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4', '.?$', 'mg' ); @@ -438,42 +416,27 @@ select foo, length(foo) from - regexp_split_to_table( - 'the quick brown fox jumps over the lazy dog', - '\s+' - ) + regexp_split_to_table('the quick brown fox jumps over the lazy dog', '\s+') as foo; select - regexp_split_to_array( - 'the quick brown fox jumps over the lazy dog', - '\s+' - ); + regexp_split_to_array('the quick brown fox jumps over the lazy dog', '\s+'); select foo, length(foo) from - regexp_split_to_table( - 'the quick brown fox jumps over the lazy dog', - '\s*' - ) + regexp_split_to_table('the quick brown fox jumps over the lazy dog', '\s*') as foo; select - regexp_split_to_array( - 'the quick brown fox jumps over the lazy dog', - '\s*' - ); + regexp_split_to_array('the quick brown fox jumps over the lazy dog', '\s*'); select foo, length(foo) from - regexp_split_to_table( - 'the quick brown fox jumps over the lazy dog', - '' - ) + regexp_split_to_table('the quick brown fox jumps over the lazy dog', '') as foo; select regexp_split_to_array('the quick brown fox jumps over the lazy dog', ''); @@ -482,11 +445,7 @@ select foo, length(foo) from - regexp_split_to_table( - 'thE QUick bROWn FOx jUMPs ovEr The lazy dOG', - 'e', - 'i' - ) + regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i') as foo; select @@ -546,11 +505,7 @@ select foo, length(foo) from - regexp_split_to_table( - 'thE QUick bROWn FOx jUMPs ovEr The lazy dOG', - 'e', - 'g' - ) + regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g') as foo; select @@ -560,30 +515,28 @@ select 'g' ); -select POSITION('4' in '1234567890') = '4' as "4"; +select position('4' in '1234567890') = '4' as "4"; -select POSITION('5' in '1234567890') = '5' as "5"; +select position('5' in '1234567890') = '5' as "5"; -select POSITION(cast('\x11' as bytea) in cast('' as bytea)) = 0 as "0"; +select position(cast('\x11' as bytea) in cast('' as bytea)) = 0 as "0"; -select POSITION(cast('\x33' as bytea) in cast('\x1122' as bytea)) = 0 as "0"; +select position(cast('\x33' as bytea) in cast('\x1122' as bytea)) = 0 as "0"; -select POSITION(cast('' as bytea) in cast('\x1122' as bytea)) = 1 as "1"; +select position(cast('' as bytea) in cast('\x1122' as bytea)) = 1 as "1"; -select POSITION(cast('\x22' as bytea) in cast('\x1122' as bytea)) = 2 as "2"; +select position(cast('\x22' as bytea) in cast('\x1122' as bytea)) = 2 as "2"; select - POSITION(cast('\x5678' as bytea) in cast('\x1234567890' as bytea)) = - 3 - as "3"; + position(cast('\x5678' as bytea) in cast('\x1234567890' as bytea)) = 3 as "3"; -select OVERLAY('abcdef' placing '45' from 4) as abc45f; +select overlay('abcdef' placing '45' from 4) as abc45f; -select OVERLAY('yabadoo' placing 'daba' from 5) as yabadaba; +select overlay('yabadoo' placing 'daba' from 5) as yabadaba; -select OVERLAY('yabadoo' placing 'daba' from 5 for 0) as yabadabadoo; +select overlay('yabadoo' placing 'daba' from 5 for 0) as yabadabadoo; -select OVERLAY('babosa' placing 'ubb' from 2 for 4) as bubba; +select overlay('babosa' placing 'ubb' from 2 for 4) as bubba; select 'hawkeye' like 'h%' as "true"; @@ -621,79 +574,79 @@ select cast('abc' as bytea) like cast('_b_' as bytea) as "true"; select cast('abc' as bytea) not like cast('_b_' as bytea) as "false"; -select 'hawkeye' like like_escape('h%', '#') as "true"; +select 'hawkeye' like pg_catalog.like_escape('h%', '#') as "true"; -select 'hawkeye' not like like_escape('h%', '#') as "false"; +select 'hawkeye' not like pg_catalog.like_escape('h%', '#') as "false"; -select 'indio' like like_escape('ind_o', '$') as "true"; +select 'indio' like pg_catalog.like_escape('ind_o', '$') as "true"; -select 'indio' not like like_escape('ind_o', '$') as "false"; +select 'indio' not like pg_catalog.like_escape('ind_o', '$') as "false"; -select 'h%' like like_escape('h#%', '#') as "true"; +select 'h%' like pg_catalog.like_escape('h#%', '#') as "true"; -select 'h%' not like like_escape('h#%', '#') as "false"; +select 'h%' not like pg_catalog.like_escape('h#%', '#') as "false"; -select 'h%wkeye' like like_escape('h#%', '#') as "false"; +select 'h%wkeye' like pg_catalog.like_escape('h#%', '#') as "false"; -select 'h%wkeye' not like like_escape('h#%', '#') as "true"; +select 'h%wkeye' not like pg_catalog.like_escape('h#%', '#') as "true"; -select 'h%wkeye' like like_escape('h#%%', '#') as "true"; +select 'h%wkeye' like pg_catalog.like_escape('h#%%', '#') as "true"; -select 'h%wkeye' not like like_escape('h#%%', '#') as "false"; +select 'h%wkeye' not like pg_catalog.like_escape('h#%%', '#') as "false"; -select 'h%awkeye' like like_escape('h#%a%k%e', '#') as "true"; +select 'h%awkeye' like pg_catalog.like_escape('h#%a%k%e', '#') as "true"; -select 'h%awkeye' not like like_escape('h#%a%k%e', '#') as "false"; +select 'h%awkeye' not like pg_catalog.like_escape('h#%a%k%e', '#') as "false"; -select 'indio' like like_escape('_ndio', '$') as "true"; +select 'indio' like pg_catalog.like_escape('_ndio', '$') as "true"; -select 'indio' not like like_escape('_ndio', '$') as "false"; +select 'indio' not like pg_catalog.like_escape('_ndio', '$') as "false"; -select 'i_dio' like like_escape('i$_d_o', '$') as "true"; +select 'i_dio' like pg_catalog.like_escape('i$_d_o', '$') as "true"; -select 'i_dio' not like like_escape('i$_d_o', '$') as "false"; +select 'i_dio' not like pg_catalog.like_escape('i$_d_o', '$') as "false"; -select 'i_dio' like like_escape('i$_nd_o', '$') as "false"; +select 'i_dio' like pg_catalog.like_escape('i$_nd_o', '$') as "false"; -select 'i_dio' not like like_escape('i$_nd_o', '$') as "true"; +select 'i_dio' not like pg_catalog.like_escape('i$_nd_o', '$') as "true"; -select 'i_dio' like like_escape('i$_d%o', '$') as "true"; +select 'i_dio' like pg_catalog.like_escape('i$_d%o', '$') as "true"; -select 'i_dio' not like like_escape('i$_d%o', '$') as "false"; +select 'i_dio' not like pg_catalog.like_escape('i$_d%o', '$') as "false"; select - cast('a_c' as bytea) like like_escape( + cast('a_c' as bytea) like pg_catalog.like_escape( cast('a$__' as bytea), cast('$' as bytea) ) as "true"; select - cast('a_c' as bytea) not like like_escape( + cast('a_c' as bytea) not like pg_catalog.like_escape( cast('a$__' as bytea), cast('$' as bytea) ) as "false"; -select 'maca' like like_escape('m%aca', '%') as "true"; +select 'maca' like pg_catalog.like_escape('m%aca', '%') as "true"; -select 'maca' not like like_escape('m%aca', '%') as "false"; +select 'maca' not like pg_catalog.like_escape('m%aca', '%') as "false"; -select 'ma%a' like like_escape('m%a%%a', '%') as "true"; +select 'ma%a' like pg_catalog.like_escape('m%a%%a', '%') as "true"; -select 'ma%a' not like like_escape('m%a%%a', '%') as "false"; +select 'ma%a' not like pg_catalog.like_escape('m%a%%a', '%') as "false"; -select 'bear' like like_escape('b_ear', '_') as "true"; +select 'bear' like pg_catalog.like_escape('b_ear', '_') as "true"; -select 'bear' not like like_escape('b_ear', '_') as "false"; +select 'bear' not like pg_catalog.like_escape('b_ear', '_') as "false"; -select 'be_r' like like_escape('b_e__r', '_') as "true"; +select 'be_r' like pg_catalog.like_escape('b_e__r', '_') as "true"; -select 'be_r' not like like_escape('b_e__r', '_') as "false"; +select 'be_r' not like pg_catalog.like_escape('b_e__r', '_') as "false"; -select 'be_r' like like_escape('__e__r', '_') as "false"; +select 'be_r' like pg_catalog.like_escape('__e__r', '_') as "false"; -select 'be_r' not like like_escape('__e__r', '_') as "true"; +select 'be_r' not like pg_catalog.like_escape('__e__r', '_') as "true"; select 'hawkeye' ilike 'h%' as "true"; @@ -746,18 +699,15 @@ select 'unknown' || ' and unknown' as "Concat unknown types"; select cast('text' as text) || ' and unknown' as "Concat text to unknown type"; select - cast('characters' as char(20)) || - ' and text' + cast('characters' as char(20)) || ' and text' as "Concat char to unknown type"; select - cast('text' as text) || - cast(' and characters' as char(20)) + cast('text' as text) || cast(' and characters' as char(20)) as "Concat text to char"; select - cast('text' as text) || - cast(' and varchar' as varchar) + cast('text' as text) || cast(' and varchar' as varchar) as "Concat text to varchar"; create table toasttest (f1 text); @@ -792,8 +742,7 @@ insert into toasttest values (repeat('1234567890', 300)); insert into toasttest values (repeat('1234567890', 300)); select - pg_relation_size(reltoastrelid) = 0 - as is_empty + pg_relation_size(reltoastrelid) = 0 as is_empty from pg_class where @@ -813,8 +762,7 @@ insert into toasttest values (repeat('1234567890', 300)); insert into toasttest values (repeat('1234567890', 300)); select - pg_relation_size(reltoastrelid) = 0 - as is_empty + pg_relation_size(reltoastrelid) = 0 as is_empty from pg_class where @@ -872,8 +820,7 @@ alter table toasttest insert into toasttest values (repeat('1234', 1000), repeat('5678', 30)); select - cast(reltoastrelid as regclass) - as reltoastname + cast(reltoastrelid as regclass) as reltoastname from pg_class where @@ -953,9 +900,7 @@ select to_bin(256 * 256 * 256 - 1) as "111111111111111111111111"; select to_bin( - cast(256 as bigint) * - cast(256 as bigint) * - cast(256 as bigint) * + cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) - 1 ) @@ -969,9 +914,7 @@ select to_oct(256 * 256 * 256 - 1) as "77777777"; select to_oct( - cast(256 as bigint) * - cast(256 as bigint) * - cast(256 as bigint) * + cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) - 1 ) @@ -985,9 +928,7 @@ select to_hex(256 * 256 * 256 - 1) as ffffff; select to_hex( - cast(256 as bigint) * - cast(256 as bigint) * - cast(256 as bigint) * + cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) * cast(256 as bigint) - 1 ) @@ -1032,21 +973,11 @@ select encode('\x1234567890abcdef00', 'hex'); select decode('1234567890abcdef00', 'hex'); select - encode( - cast('\x' || - repeat('1234567890abcdef0001', 7) - as bytea), - 'base64' - ); + encode(cast('\x' || repeat('1234567890abcdef0001', 7) as bytea), 'base64'); select decode( - encode( - cast('\x' || - repeat('1234567890abcdef0001', 7) - as bytea), - 'base64' - ), + encode(cast('\x' || repeat('1234567890abcdef0001', 7) as bytea), 'base64'), 'base64' ); @@ -1089,22 +1020,10 @@ select encode(decode(encode('\x00', 'base64url'), 'base64url'), 'base64url'); select encode(decode(encode('\x0001', 'base64url'), 'base64url'), 'base64url'); select - encode( - decode( - encode('\x000102', 'base64url'), - 'base64url' - ), - 'base64url' - ); + encode(decode(encode('\x000102', 'base64url'), 'base64url'), 'base64url'); select - encode( - decode( - encode('\x00010203', 'base64url'), - 'base64url' - ), - 'base64url' - ); + encode(decode(encode('\x00010203', 'base64url'), 'base64url'), 'base64url'); select decode('QQ@=', 'base64url'); @@ -1135,89 +1054,69 @@ select set_byte(cast('\x1234567890abcdef00' as bytea), 7, 11); select set_byte(cast('\x1234567890abcdef00' as bytea), 99, 11); select - cast(cast(4660 as smallint) as bytea) - as "\x1234", - cast(cast(-4660 as smallint) as bytea) - as "\xedcc"; + cast(cast(4660 as int2) as bytea) as "\x1234", + cast(cast(-4660 as int2) as bytea) as "\xedcc"; select - cast(cast(305419896 as int) as bytea) - as "\x12345678", - cast(cast(-305419896 as int) as bytea) - as "\xedcba988"; + cast(cast(305419896 as int4) as bytea) as "\x12345678", + cast(cast(-305419896 as int4) as bytea) as "\xedcba988"; select - cast(cast(0x1122334455667788 as bigint) - as bytea) - as "\x1122334455667788", - cast(cast(-0x1122334455667788 as bigint) - as bytea) - as "\xeeddccbbaa998878"; + cast(cast(0x1122334455667788 as int8) as bytea) as "\x1122334455667788", + cast(cast(-0x1122334455667788 as int8) as bytea) as "\xeeddccbbaa998878"; -select cast(cast('' as bytea) as smallint) as "0"; +select cast(cast('' as bytea) as int2) as "0"; -select cast(cast('\x12' as bytea) as smallint) as "18"; +select cast(cast('\x12' as bytea) as int2) as "18"; -select cast(cast('\x1234' as bytea) as smallint) as "4460"; +select cast(cast('\x1234' as bytea) as int2) as "4460"; -select cast(cast('\x123456' as bytea) as smallint); +select cast(cast('\x123456' as bytea) as int2); -select cast(cast('' as bytea) as int) as "0"; +select cast(cast('' as bytea) as int4) as "0"; -select cast(cast('\x12' as bytea) as int) as "18"; +select cast(cast('\x12' as bytea) as int4) as "18"; -select cast(cast('\x12345678' as bytea) as int) as "305419896"; +select cast(cast('\x12345678' as bytea) as int4) as "305419896"; -select cast(cast('\x123456789A' as bytea) as int); +select cast(cast('\x123456789A' as bytea) as int4); -select cast(cast('' as bytea) as bigint) as "0"; +select cast(cast('' as bytea) as int8) as "0"; -select cast(cast('\x12' as bytea) as bigint) as "18"; +select cast(cast('\x12' as bytea) as int8) as "18"; select - cast(cast('\x1122334455667788' as bytea) - as bigint) - as "1234605616436508552"; + cast(cast('\x1122334455667788' as bytea) as int8) as "1234605616436508552"; -select cast(cast('\x112233445566778899' as bytea) as bigint); +select cast(cast('\x112233445566778899' as bytea) as int8); select - cast(cast('\x8000' as bytea) - as smallint) - as "-32768", - cast(cast('\x7FFF' as bytea) - as smallint) - as "32767"; + cast(cast('\x8000' as bytea) as int2) as "-32768", + cast(cast('\x7FFF' as bytea) as int2) as "32767"; select - cast(cast('\x80000000' as bytea) as int) - as "-2147483648", - cast(cast('\x7FFFFFFF' as bytea) as int) - as "2147483647"; + cast(cast('\x80000000' as bytea) as int4) as "-2147483648", + cast(cast('\x7FFFFFFF' as bytea) as int4) as "2147483647"; select - cast(cast('\x8000000000000000' as bytea) - as bigint) - as "-9223372036854775808", - cast(cast('\x7FFFFFFFFFFFFFFF' as bytea) - as bigint) - as "9223372036854775807"; + cast(cast('\x8000000000000000' as bytea) as int8) as "-9223372036854775808", + cast(cast('\x7FFFFFFFFFFFFFFF' as bytea) as int8) as "9223372036854775807"; set escape_string_warning = off; set standard_conforming_strings = off; -show "escape_string_warning"; +show escape_string_warning; -show "standard_conforming_strings"; +show standard_conforming_strings; set escape_string_warning = 'on'; set standard_conforming_strings = 'on'; -show "escape_string_warning"; +show escape_string_warning; -show "standard_conforming_strings"; +show standard_conforming_strings; select 'a\bcd' as f1, @@ -1275,21 +1174,21 @@ select repeat('Pg', 4); select repeat('Pg', -4); -select SUBSTRING(cast('1234567890' as bytea) from 3) as "34567890"; +select substring(cast('1234567890' as bytea) from 3) as "34567890"; -select SUBSTRING(cast('1234567890' as bytea) from 4 for 3) as "456"; +select substring(cast('1234567890' as bytea) from 4 for 3) as "456"; -select SUBSTRING(cast('string' as bytea) from 2 for 2147483646) as tring; +select substring(cast('string' as bytea) from 2 for 2147483646) as tring; -select SUBSTRING(cast('string' as bytea) from -10 for 2147483646) as string; +select substring(cast('string' as bytea) from -10 for 2147483646) as string; -select SUBSTRING(cast('string' as bytea) from -10 for -2147483646) as error; +select substring(cast('string' as bytea) from -10 for -2147483646) as error; -select btrim(cast('\000Tom\000' as bytea), cast('\000' as bytea)); +select trim(cast('\000' as bytea) from cast('\000Tom\000' as bytea)); -select ltrim(cast('\000Tom\000' as bytea), cast('\000' as bytea)); +select trim(leading cast('\000' as bytea) from cast('\000Tom\000' as bytea)); -select rtrim(cast('\000Tom\000' as bytea), cast('\000' as bytea)); +select trim(trailing cast('\000' as bytea) from cast('\000Tom\000' as bytea)); select btrim(cast('\000trim\000' as bytea), cast('\000' as bytea)); @@ -1299,19 +1198,22 @@ select btrim(cast('\000trim\000' as bytea), cast('' as bytea)); select encode( - OVERLAY(cast('Th\000omas' as bytea) placing cast('Th\001omas' as bytea) from 2), + overlay(cast('Th\000omas' as bytea) placing cast('Th\001omas' + as bytea) from 2), 'escape' ); select encode( - OVERLAY(cast('Th\000omas' as bytea) placing cast('\002\003' as bytea) from 8), + overlay(cast('Th\000omas' as bytea) placing cast('\002\003' + as bytea) from 8), 'escape' ); select encode( - OVERLAY(cast('Th\000omas' as bytea) placing cast('\002\003' as bytea) from 5 for 3), + overlay(cast('Th\000omas' as bytea) placing cast('\002\003' + as bytea) from 5 for 3), 'escape' ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subscription_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subscription_100.snap index 6d14d18eb..4c377611a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subscription_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subscription_100.snap @@ -24,7 +24,9 @@ create subscription regress_testsub connection 'dbname=regress_doesnotexist' pub testpub, foo with (connect = 'false'); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false' +); comment on subscription regress_testsub is 'test subscription'; @@ -64,52 +66,78 @@ from where subname = 'regress_testsub'; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false' +); set session authorization regress_subscription_user2; -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication foo with (connect = 'false'); +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication foo with ( + connect = 'false' +); set session authorization regress_subscription_user; -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -copy_data = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -enabled = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -create_slot = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -enabled = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -enabled = 'false', -create_slot = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -enabled = 'false'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -create_slot = 'false'); - -create subscription regress_testsub3 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -connect = 'false'); +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + copy_data = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + enabled = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + create_slot = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + enabled = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + enabled = 'false', + create_slot = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + enabled = 'false' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + create_slot = 'false' +); + +create subscription regress_testsub3 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + connect = 'false' +); alter subscription regress_testsub3 enable; alter subscription regress_testsub3 refresh publication; -create subscription regress_testsub4 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -connect = 'false', -origin = foo); +create subscription regress_testsub4 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + connect = 'false', + origin = foo +); -create subscription regress_testsub4 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -connect = 'false', -origin = 'none'); +create subscription regress_testsub4 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + connect = 'false', + origin = 'none' +); alter subscription regress_testsub4 set (origin = 'any'); @@ -191,23 +219,31 @@ drop subscription if exists regress_testsub restrict; drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -binary = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + "binary" = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -binary = 'true'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + "binary" = 'true' +); -alter subscription regress_testsub set (binary = 'false'); +alter subscription regress_testsub set ("binary" = 'false'); alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -streaming = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + streaming = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -streaming = 'true'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + streaming = 'true' +); alter subscription regress_testsub set (streaming = parallel); @@ -233,9 +269,11 @@ alter subscription regress_testsub drop publication testpub1, testpub2; drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication mypub with (connect = 'false', -create_slot = 'false', -copy_data = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication mypub with ( + connect = 'false', + create_slot = 'false', + copy_data = 'false' +); alter subscription regress_testsub enable; @@ -254,9 +292,7 @@ commit; create function func() returns void language sql -as $function$ -ALTER SUBSCRIPTION regress_testsub SET PUBLICATION mypub WITH (refresh = true) -$function$; +as $$ ALTER SUBSCRIPTION regress_testsub SET PUBLICATION mypub WITH (refresh = true) $$; select func(); @@ -268,11 +304,15 @@ drop subscription regress_testsub restrict; drop function func; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -two_phase = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + two_phase = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -two_phase = 'true'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + two_phase = 'true' +); alter subscription regress_testsub set (streaming = 'true'); @@ -280,19 +320,25 @@ alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -streaming = 'true', -two_phase = 'true'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + streaming = 'true', + two_phase = 'true' +); alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -disable_on_error = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + disable_on_error = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -disable_on_error = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + disable_on_error = 'false' +); alter subscription regress_testsub set (disable_on_error = 'true'); @@ -300,21 +346,29 @@ alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -retain_dead_tuples = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + retain_dead_tuples = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -retain_dead_tuples = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + retain_dead_tuples = 'false' +); alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -max_retention_duration = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + max_retention_duration = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -max_retention_duration = 1000); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + max_retention_duration = 1000 +); alter subscription regress_testsub set (max_retention_duration = 0); @@ -324,32 +378,40 @@ drop subscription regress_testsub restrict; set session authorization regress_subscription_user3; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false' +); reset session_authorization; -grant CREATE on database regression to regress_subscription_user3; +grant create on database regression to regress_subscription_user3; set session authorization regress_subscription_user3; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false' +); reset session_authorization; -grant CREATE on database regression to regress_subscription_user3; +grant create on database regression to regress_subscription_user3; set session authorization regress_subscription_user3; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -password_required = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + password_required = 'false' +); reset session_authorization; -grant CREATE on database regression to regress_subscription_user3; +grant create on database regression to regress_subscription_user3; set session authorization regress_subscription_user3; -create subscription regress_testsub connection 'dbname=regress_doesnotexist password=regress_fakepassword' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist password=regress_fakepassword' publication testpub with ( + connect = 'false' +); alter subscription regress_testsub owner to regress_subscription_user; @@ -357,7 +419,7 @@ alter subscription regress_testsub rename to regress_testsub2; reset session_authorization; -revoke PG_CREATE_SUBSCRIPTION from regress_subscription_user3 restrict; +revoke pg_create_subscription from regress_subscription_user3 restrict; set session authorization regress_subscription_user3; @@ -365,7 +427,7 @@ alter subscription regress_testsub2 rename to regress_testsub; reset session_authorization; -revoke CREATE on database regression from regress_subscription_user3; +revoke create on database regression from regress_subscription_user3; set session authorization regress_subscription_user3; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subscription_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subscription_80.snap index 17f5a7bfd..96d2e8d2d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subscription_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subscription_80.snap @@ -14,7 +14,9 @@ set session authorization regress_subscription_user; begin; -create subscription regress_testsub connection 'testconn' publication testpub with (create_slot); +create subscription regress_testsub connection 'testconn' publication testpub with ( + create_slot +); commit; @@ -24,7 +26,9 @@ create subscription regress_testsub connection 'dbname=regress_doesnotexist' pub testpub, foo with (connect = 'false'); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false' +); comment on subscription regress_testsub is 'test subscription'; @@ -32,8 +36,7 @@ select obj_description(s.oid, 'pg_subscription') from pg_subscription as s; select subname, - stats_reset is null - as stats_reset_is_null + stats_reset is null as stats_reset_is_null from pg_stat_subscription_stats where @@ -48,8 +51,7 @@ where select subname, - stats_reset is null - as stats_reset_is_null + stats_reset is null as stats_reset_is_null from pg_stat_subscription_stats where @@ -76,52 +78,78 @@ from where subname = 'regress_testsub'; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false' +); set session authorization regress_subscription_user2; -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication foo with (connect = 'false'); +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication foo with ( + connect = 'false' +); set session authorization regress_subscription_user; -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -copy_data = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -enabled = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -create_slot = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -enabled = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -enabled = 'false', -create_slot = 'true'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -enabled = 'false'); - -create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -create_slot = 'false'); - -create subscription regress_testsub3 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -connect = 'false'); +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + copy_data = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + enabled = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + create_slot = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + enabled = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + enabled = 'false', + create_slot = 'true' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + enabled = 'false' +); + +create subscription regress_testsub2 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + create_slot = 'false' +); + +create subscription regress_testsub3 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + connect = 'false' +); alter subscription regress_testsub3 enable; alter subscription regress_testsub3 refresh publication; -create subscription regress_testsub4 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -connect = 'false', -origin = foo); +create subscription regress_testsub4 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + connect = 'false', + origin = foo +); -create subscription regress_testsub4 connection 'dbname=regress_doesnotexist' publication testpub with (slot_name = 'none', -connect = 'false', -origin = 'none'); +create subscription regress_testsub4 connection 'dbname=regress_doesnotexist' publication testpub with ( + slot_name = 'none', + connect = 'false', + origin = 'none' +); alter subscription regress_testsub4 set (origin = 'any'); @@ -204,23 +232,31 @@ drop subscription if exists regress_testsub restrict; drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -binary = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + "binary" = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -binary = 'true'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + "binary" = 'true' +); -alter subscription regress_testsub set (binary = 'false'); +alter subscription regress_testsub set ("binary" = 'false'); alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -streaming = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + streaming = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -streaming = 'true'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + streaming = 'true' +); alter subscription regress_testsub set (streaming = parallel); @@ -246,9 +282,11 @@ alter subscription regress_testsub drop publication testpub1, testpub2; drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication mypub with (connect = 'false', -create_slot = 'false', -copy_data = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication mypub with ( + connect = 'false', + create_slot = 'false', + copy_data = 'false' +); alter subscription regress_testsub enable; @@ -267,9 +305,7 @@ commit; create function func() returns void language sql -as $function$ -ALTER SUBSCRIPTION regress_testsub SET PUBLICATION mypub WITH (refresh = true) -$function$; +as $$ ALTER SUBSCRIPTION regress_testsub SET PUBLICATION mypub WITH (refresh = true) $$; select func(); @@ -281,11 +317,15 @@ drop subscription regress_testsub restrict; drop function func; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -two_phase = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + two_phase = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -two_phase = 'true'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + two_phase = 'true' +); alter subscription regress_testsub set (streaming = 'true'); @@ -293,19 +333,25 @@ alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -streaming = 'true', -two_phase = 'true'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + streaming = 'true', + two_phase = 'true' +); alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -disable_on_error = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + disable_on_error = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -disable_on_error = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + disable_on_error = 'false' +); alter subscription regress_testsub set (disable_on_error = 'true'); @@ -313,21 +359,29 @@ alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -retain_dead_tuples = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + retain_dead_tuples = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -retain_dead_tuples = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + retain_dead_tuples = 'false' +); alter subscription regress_testsub set (slot_name = 'none'); drop subscription regress_testsub restrict; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -max_retention_duration = foo); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + max_retention_duration = foo +); -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -max_retention_duration = 1000); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + max_retention_duration = 1000 +); alter subscription regress_testsub set (max_retention_duration = 0); @@ -337,32 +391,40 @@ drop subscription regress_testsub restrict; set session authorization regress_subscription_user3; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false' +); reset session_authorization; -grant CREATE on database regression to regress_subscription_user3; +grant create on database regression to regress_subscription_user3; set session authorization regress_subscription_user3; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false' +); reset session_authorization; -grant CREATE on database regression to regress_subscription_user3; +grant create on database regression to regress_subscription_user3; set session authorization regress_subscription_user3; -create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with (connect = 'false', -password_required = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist' publication testpub with ( + connect = 'false', + password_required = 'false' +); reset session_authorization; -grant CREATE on database regression to regress_subscription_user3; +grant create on database regression to regress_subscription_user3; set session authorization regress_subscription_user3; -create subscription regress_testsub connection 'dbname=regress_doesnotexist password=regress_fakepassword' publication testpub with (connect = 'false'); +create subscription regress_testsub connection 'dbname=regress_doesnotexist password=regress_fakepassword' publication testpub with ( + connect = 'false' +); alter subscription regress_testsub owner to regress_subscription_user; @@ -370,7 +432,7 @@ alter subscription regress_testsub rename to regress_testsub2; reset session_authorization; -revoke PG_CREATE_SUBSCRIPTION from regress_subscription_user3 restrict; +revoke pg_create_subscription from regress_subscription_user3 restrict; set session authorization regress_subscription_user3; @@ -378,7 +440,7 @@ alter subscription regress_testsub2 rename to regress_testsub; reset session_authorization; -revoke CREATE on database regression from regress_subscription_user3; +revoke create on database regression from regress_subscription_user3; set session authorization regress_subscription_user3; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_100.snap index 2beb0b1e3..454ccb459 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_100.snap @@ -61,15 +61,7 @@ select from subselect_tbl where - f1 in - ( - select - f2 - from - subselect_tbl - where - f2 in (select f1 from subselect_tbl) - ); + f1 in (select f2 from subselect_tbl where f2 in (select f1 from subselect_tbl)); select f1, @@ -77,16 +69,7 @@ select from subselect_tbl where - not (f1, f2) in - ( - select - f2, - cast(f3 as int) - from - subselect_tbl - where - f3 is not null - ); + not (f1, f2) in (select f2, cast(f3 as int4) from subselect_tbl where f3 is not null); select f1 as "Correlated Field", @@ -94,10 +77,7 @@ select from subselect_tbl as upper where - f1 in - ( - select f2 from subselect_tbl where f1 = upper.f1 - ); + f1 in (select f2 from subselect_tbl where f1 = upper.f1); select f1 as "Correlated Field", @@ -105,15 +85,7 @@ select from subselect_tbl as upper where - f1 in - ( - select - f2 - from - subselect_tbl - where - cast(upper.f2 as double precision) = f3 - ); + f1 in (select f2 from subselect_tbl where cast(upper.f2 as double precision) = f3); select f1 as "Correlated Field", @@ -121,31 +93,14 @@ select from subselect_tbl as upper where - f3 in - ( - select - upper.f1 + f2 - from - subselect_tbl - where - f2 = cast(f3 as int) - ); + f3 in (select upper.f1 + f2 from subselect_tbl where f2 = cast(f3 as int)); select f1 as "Correlated Field" from subselect_tbl where - (f1, f2) in - ( - select - f2, - cast(f3 as int) - from - subselect_tbl - where - f3 is not null - ); + (f1, f2) in (select f2, cast(f3 as int4) from subselect_tbl where f3 is not null); select row(1, 2) = (select f1, f2) as eq from subselect_tbl; @@ -157,9 +112,9 @@ select row(1, 2) = (select 3, 4) as eq from subselect_tbl; select row(1, 2) = (select f1, f2 from subselect_tbl); -select count from (select COUNT(distinct name) from road); +select count from (select count(distinct name) from road); -select COUNT(*) from (select distinct name from road); +select count(*) from (select distinct name from road); select * from (select * from int4_tbl), (values (123456)) where f1 = column1; @@ -167,9 +122,7 @@ create view view_unnamed_ss as select * from - ( - select * from (select abs(f1) as a1 from int4_tbl) - ), + (select * from (select abs(f1) as a1 from int4_tbl)), (select * from int8_tbl) where a1 < 10 and q1 > a1 @@ -198,17 +151,9 @@ select from subselect_tbl as ss where - not f1 in - ( - select - f1 + 1 - from - int4_tbl - where - f1 <> ss.f1 and f1 < 2147483647 - ); + not f1 in (select f1 + 1 from int4_tbl where f1 <> ss.f1 and f1 < 2147483647); -select q1, float8(COUNT(*)) / (select COUNT(*) from int8_tbl) from int8_tbl group by q1 order by q1; +select q1, float8(count(*)) / (select count(*) from int8_tbl) from int8_tbl group by q1 order by q1; select *, pg_typeof(f1) from (select 'foo' as f1 from generate_series(1, 3)) as ss order by 1; @@ -227,76 +172,29 @@ select from int4_tbl as o where - not exists - ( - select - 1 - from - int4_tbl as i - where - i.f1 = o.f1 - limit 1 - ); + not exists (select 1 from int4_tbl as i where i.f1 = o.f1 limit 1); select * from int4_tbl as o where exists (select 1 from int4_tbl as i where i.f1 = o.f1 limit 0); select - COUNT(*) + count(*) from - ( - select - 1 - from - tenk1 as a - where - unique1 in (select hundred from tenk1 as b) - ) - as ss; + (select 1 from tenk1 as a where unique1 in (select hundred from tenk1 as b)) as ss; select - COUNT(distinct ss.ten) + count(distinct ss.ten) from - ( - select - ten - from - tenk1 as a - where - unique1 in (select hundred from tenk1 as b) - ) - as ss; + (select ten from tenk1 as a where unique1 in (select hundred from tenk1 as b)) as ss; select - COUNT(*) + count(*) from - ( - select - 1 - from - tenk1 as a - where - unique1 in - ( - select distinct hundred from tenk1 as b - ) - ) - as ss; + (select 1 from tenk1 as a where unique1 in (select distinct hundred from tenk1 as b)) as ss; select - COUNT(distinct ss.ten) + count(distinct ss.ten) from - ( - select - ten - from - tenk1 as a - where - unique1 in - ( - select distinct hundred from tenk1 as b - ) - ) - as ss; + (select ten from tenk1 as a where unique1 in (select distinct hundred from tenk1 as b)) as ss; create temporary table foo (id int); @@ -322,18 +220,7 @@ select from foo where - id in - ( - select - id2 - from - ( - select id1, id2 from bar - union - select id1, id2 from bar - ) - as s - ); + id in (select id2 from (select id1, id2 from bar union select id1, id2 from bar) as s); select * from foo where id in (select id2 from (select distinct on (id2) id1, id2 from bar) as s); @@ -344,16 +231,7 @@ select from foo where - id in - ( - select - id2 - from - ( - select id2 from bar union select id2 from bar - ) - as s - ); + id in (select id2 from (select id2 from bar union select id2 from bar) as s); create table orderstest ( approver_ref int, @@ -386,14 +264,7 @@ insert into orderstest values (1, 1, false); create view orders_view as select *, - ( - select - case - when ord.approver_ref = 1 then '---' - else 'Approved' - end - ) - as "Approved", + (select case when ord.approver_ref = 1 then '---' else 'Approved' end) as "Approved", ( select case @@ -402,13 +273,7 @@ as select select case when ord.po_ref = 1 - then ( - select - case - when ord.approver_ref = 1 then '---' - else 'Approved' - end - ) + then (select case when ord.approver_ref = 1 then '---' else 'Approved' end) else 'PO' end ) @@ -418,11 +283,7 @@ as select case when ord.ordercanceled then 'Canceled' else case - when ord.po_ref = 1 - then case - when ord.approver_ref = 1 then '---' - else 'Approved' - end + when ord.po_ref = 1 then case when ord.approver_ref = 1 then '---' else 'Approved' end else 'PO' end end @@ -436,14 +297,14 @@ drop table orderstest cascade; create temporary table parts ( partnum text, - cost double precision + cost float8 ); create temporary table shipped ( ttype char(2), - ordnum int, + ordnum int4, partnum text, - value double precision + value float8 ); create temporary view shipped_view @@ -452,16 +313,12 @@ as select * from shipped where ttype = 'wt'; create rule shipped_view_insert as on insert to shipped_view do instead - insert into shipped - values ('wt', new.ordnum, new.partnum, new.value);; + insert into shipped values ('wt', new.ordnum, new.partnum, new.value);; insert into parts (partnum, cost) values (1, 1234.56); insert into shipped_view (ordnum, partnum, value) -values - ( - 0, 1, (select cost from parts where partnum = '1') - ); +values (0, 1, (select cost from parts where partnum = '1')); select * from shipped_view; @@ -479,8 +336,7 @@ set value = 11 from int4_tbl as a inner join int4_tbl as b -on a.f1 = - (select f1 from int4_tbl as c where c.f1 = b.f1) +on a.f1 = (select f1 from int4_tbl as c where c.f1 = b.f1) where ordnum = a.f1; @@ -490,36 +346,18 @@ select f1, ss1 as relabel from - ( - select - *, - ( - select SUM(f1) from int4_tbl as b where f1 >= a.f1 - ) - as ss1 - from - int4_tbl as a - ) - as ss; + (select *, (select sum(f1) from int4_tbl as b where f1 >= a.f1) as ss1 from int4_tbl as a) as ss; select * from ( select - MAX(unique1) + max(unique1) from tenk1 as a where - exists - ( - select - 1 - from - tenk1 as b - where - b.thousand = a.unique2 - ) + exists (select 1 from tenk1 as b where b.thousand = a.unique2) ) as ss; @@ -528,14 +366,11 @@ select from ( select - MIN(unique1) + min(unique1) from tenk1 as a where - not exists - ( - select 1 from tenk1 as b where b.unique2 = 10000 - ) + not exists (select 1 from tenk1 as b where b.unique2 = 10000) ) as ss; @@ -543,7 +378,7 @@ create temporary table numeric_table (num_col numeric); insert into numeric_table values (1), (1.000000000000000000001), (2), (3); -create temporary table float_table (float_col double precision); +create temporary table float_table (float_col float8); insert into float_table values (1), (2), (3); @@ -568,10 +403,7 @@ from semijoin_unique_tbl as t1, semijoin_unique_tbl as t2 where - (t1.a, t2.a) in - ( - select a, b from semijoin_unique_tbl as t3 - ) + (t1.a, t2.a) in (select a, b from semijoin_unique_tbl as t3) order by t1.a, t2.a; @@ -581,10 +413,7 @@ from semijoin_unique_tbl as t1, semijoin_unique_tbl as t2 where - (t1.a, t2.a) in - ( - select a + 1, b + 1 from semijoin_unique_tbl as t3 - ) + (t1.a, t2.a) in (select a + 1, b + 1 from semijoin_unique_tbl as t3) order by t1.a, t2.a; @@ -604,10 +433,7 @@ from semijoin_unique_tbl as t1, semijoin_unique_tbl as t2 where - (t1.a, t2.a) in - ( - select a, b from semijoin_unique_tbl as t3 - ) + (t1.a, t2.a) in (select a, b from semijoin_unique_tbl as t3) order by t1.a, t2.a; @@ -653,10 +479,7 @@ from unique_tbl_p as t1, unique_tbl_p as t2 where - (t1.a, t2.a) in - ( - select a, a from unique_tbl_p as t3 - ) + (t1.a, t2.a) in (select a, a from unique_tbl_p as t3) order by t1.a, t2.a; @@ -696,15 +519,7 @@ insert into tc values (1, 1); insert into tc values (2, 2); select - ( - select - MIN(tb.id) - from - tb - where - tb.aval = - (select ta.val from ta where ta.id = tc.aid) - ) + (select min(tb.id) from tb where tb.aval = (select ta.val from ta where ta.id = tc.aid)) as min_tb_id from tc; @@ -717,15 +532,7 @@ create temporary table t1 ( select * from - ( - select distinct - f1, - f2, - (select f2 from t1 as x where x.f1 = up.f1) as fs - from - t1 as up - ) - as ss + (select distinct f1, f2, (select f2 from t1 as x where x.f1 = up.f1) as fs from t1 as up) as ss group by f1, f2, fs; @@ -749,9 +556,9 @@ select 1 = any (array_agg(f1)) = any (select false) from int4_tbl; select 1 = any (array_agg(f1)) = any (select false) from int4_tbl; -select q from (select MAX(f1) from int4_tbl group by f1 order by f1) as q; +select q from (select max(f1) from int4_tbl group by f1 order by f1) as q; -with q as (select MAX(f1) from int4_tbl group by f1 order by f1) select q from q; +with q as (select max(f1) from int4_tbl group by f1 order by f1) select q from q; begin; @@ -764,14 +571,7 @@ where from int4_tbl inner join - ( - select - f1, - array(select q1 from int8_tbl) as arr - from - text_tbl - ) - as ss + (select f1, array(select q1 from int8_tbl) as arr from text_tbl) as ss on true where road.name = ss.f1 @@ -782,21 +582,13 @@ rollback; select (select sq1) as qq1 from - ( - select - exists (select 1 from int4_tbl where f1 = q2) - as sq1, - 42 as dummy - from - int8_tbl - ) - as sq0 + (select exists (select 1 from int4_tbl where f1 = q2) as sq1, 42 as dummy from int8_tbl) as sq0 inner join int4_tbl as i4 on dummy = i4.f1; create temporary table upsert ( - key int primary key, + key int4 primary key, val text ); @@ -808,29 +600,19 @@ on conflict (key) do update -set val = 'seen with subselect ' || -cast((select f1 from int4_tbl where f1 <> 0 limit 1) -as text); +set val = 'seen with subselect ' || cast((select f1 from int4_tbl where f1 <> 0 limit 1) as text); select * from upsert; -with -aa -as ( - select 'int4_tbl' as u from int4_tbl limit 1 -) +with aa as (select 'int4_tbl' as u from int4_tbl limit 1) insert into upsert values (1, 'x'), (999, 'y') -on conflict -(key) -do -update -set val = (select u from aa) +on conflict (key) do update set val = (select u from aa) returning *; create temporary table outer_7597 ( - f1 int, - f2 int + f1 int4, + f2 int4 ); insert into outer_7597 values (0, 0); @@ -842,8 +624,8 @@ insert into outer_7597 values (0, null); insert into outer_7597 values (1, null); create temporary table inner_7597 ( - c1 bigint, - c2 bigint + c1 int8, + c2 int8 ); insert into inner_7597 values (0, null); @@ -888,36 +670,30 @@ select * from int8_tbl where q1 in (select c1 from inner_text); begin; -create function bogus_int8_text_eq(bigint, text) +create function bogus_int8_text_eq(int8, text) returns boolean language sql -as $function$ -select $1::text = $2 -$function$; +as 'select $1::text = $2'; -create operator = (PROCEDURE = bogus_int8_text_eq, LEFTARG = bigint, RIGHTARG = text); +create operator = (procedure = bogus_int8_text_eq, leftarg = int8, rightarg = text); select * from int8_tbl where q1 in (select c1 from inner_text); select * from int8_tbl where q1 in (select c1 from inner_text); -create or replace function bogus_int8_text_eq(bigint, text) +create or replace function bogus_int8_text_eq(int8, text) returns boolean language sql -as $function$ -select $1::text = $2 and $1::text = $2 -$function$; +as 'select $1::text = $2 and $1::text = $2'; select * from int8_tbl where q1 in (select c1 from inner_text); select * from int8_tbl where q1 in (select c1 from inner_text); -create or replace function bogus_int8_text_eq(bigint, text) +create or replace function bogus_int8_text_eq(int8, text) returns boolean language sql -as $function$ -select $2 = $1::text -$function$; +as 'select $2 = $1::text'; select * from int8_tbl where q1 in (select c1 from inner_text); @@ -926,81 +702,39 @@ select * from int8_tbl where q1 in (select c1 from inner_text); rollback; select - COUNT(*) + count(*) from tenk1 as t where - exists - ( - select - 1 - from - tenk1 as k - where - k.unique1 = t.unique2 - ) or - ten < 0; + exists (select 1 from tenk1 as k where k.unique1 = t.unique2) or ten < 0; select - COUNT(*) + count(*) from tenk1 as t where - exists - ( - select - 1 - from - tenk1 as k - where - k.unique1 = t.unique2 - ) or - ten < 0; + exists (select 1 from tenk1 as k where k.unique1 = t.unique2) or ten < 0; select - COUNT(*) + count(*) from tenk1 as t where - ( - exists - ( - select - 1 - from - tenk1 as k - where - k.unique1 = t.unique2 - ) or - ten < 0 - ) and - thousand = 1; + (exists (select 1 from tenk1 as k where k.unique1 = t.unique2) or ten < 0) and thousand = 1; select - COUNT(*) + count(*) from tenk1 as t where - ( - exists - ( - select - 1 - from - tenk1 as k - where - k.unique1 = t.unique2 - ) or - ten < 0 - ) and - thousand = 1; + (exists (select 1 from tenk1 as k where k.unique1 = t.unique2) or ten < 0) and thousand = 1; create temporary table exists_tbl ( c1 int, c2 int, c3 int ) -partition by LIST(c1); +partition by list(c1); create temporary table exists_tbl_null partition of exists_tbl for values in (null); @@ -1015,22 +749,14 @@ select from exists_tbl as t1 where - exists - ( - select 1 from exists_tbl as t2 where t1.c1 = t2.c2 - ) or - c3 < 0; + exists (select 1 from exists_tbl as t2 where t1.c1 = t2.c2) or c3 < 0; select * from exists_tbl as t1 where - exists - ( - select 1 from exists_tbl as t2 where t1.c1 = t2.c2 - ) or - c3 < 0; + exists (select 1 from exists_tbl as t2 where t1.c1 = t2.c2) or c3 < 0; select a.thousand @@ -1046,38 +772,25 @@ where from tenk1 as c where - b.hundred = c.hundred and - not exists - ( - select - 1 - from - tenk1 as d - where - a.thousand = d.thousand - ) + b.hundred = c.hundred and not exists (select 1 from tenk1 as d where a.thousand = d.thousand) ); -select x, x from (select (select NOW()) as x from (values (1), (2)) as v (y)) as ss; +select x, x from (select (select now()) as x from (values (1), (2)) as v (y)) as ss; select x, x from (select (select random()) as x from (values (1), (2)) as v (y)) as ss; -select x, x from (select (select NOW() where y = y) as x from (values (1), (2)) as v (y)) as ss; +select x, x from (select (select now() where y = y) as x from (values (1), (2)) as v (y)) as ss; select x, x from (select (select random() where y = y) as x from (values (1), (2)) as v (y)) as ss; select - SUM(cast(ss.tst as int)) + sum(cast(ss.tst as int)) from onek as o inner join lateral ( select - i.ten in - ( - select f1 from int4_tbl where f1 <= o.hundred - ) - as tst, + i.ten in (select f1 from int4_tbl where f1 <= o.hundred) as tst, random() as r from onek as i @@ -1090,17 +803,13 @@ where o.ten = 0; select - SUM(cast(ss.tst as int)) + sum(cast(ss.tst as int)) from onek as o inner join lateral ( select - i.ten in - ( - select f1 from int4_tbl where f1 <= o.hundred - ) - as tst, + i.ten in (select f1 from int4_tbl where f1 <= o.hundred) as tst, random() as r from onek as i @@ -1117,24 +826,14 @@ begin; set local enable_sort = off; select - COUNT(*) + count(*) from onek as o inner join lateral ( - select - * - from - onek as i1 - where - i1.unique1 = o.unique1 + select * from onek as i1 where i1.unique1 = o.unique1 except - select - * - from - onek as i2 - where - i2.unique1 = o.unique2 + select * from onek as i2 where i2.unique1 = o.unique2 ) as ss on true @@ -1142,24 +841,14 @@ where o.ten = 1; select - COUNT(*) + count(*) from onek as o inner join lateral ( - select - * - from - onek as i1 - where - i1.unique1 = o.unique1 + select * from onek as i1 where i1.unique1 = o.unique1 except - select - * - from - onek as i2 - where - i2.unique1 = o.unique2 + select * from onek as i2 where i2.unique1 = o.unique2 ) as ss on true @@ -1173,24 +862,14 @@ begin; set local enable_hashagg = off; select - COUNT(*) + count(*) from onek as o inner join lateral ( - select - * - from - onek as i1 - where - i1.unique1 = o.unique1 + select * from onek as i1 where i1.unique1 = o.unique1 except - select - * - from - onek as i2 - where - i2.unique1 = o.unique2 + select * from onek as i2 where i2.unique1 = o.unique2 ) as ss on true @@ -1198,24 +877,14 @@ where o.ten = 1; select - COUNT(*) + count(*) from onek as o inner join lateral ( - select - * - from - onek as i1 - where - i1.unique1 = o.unique1 + select * from onek as i1 where i1.unique1 = o.unique1 except - select - * - from - onek as i2 - where - i2.unique1 = o.unique2 + select * from onek as i2 where i2.unique1 = o.unique2 ) as ss on true @@ -1225,19 +894,13 @@ where rollback; select - SUM(o.four), - SUM(ss.a) + sum(o.four), + sum(ss.a) from onek as o inner join lateral ( - with recursive - x (a) - as ( - select o.four as a - union - select a + 1 from x where a < 10 - ) + with recursive x (a) as (select o.four as a union select a + 1 from x where a < 10) select * from @@ -1249,19 +912,13 @@ where o.ten = 1; select - SUM(o.four), - SUM(ss.a) + sum(o.four), + sum(ss.a) from onek as o inner join lateral ( - with recursive - x (a) - as ( - select o.four as a - union - select a + 1 from x where a < 10 - ) + with recursive x (a) as (select o.four as a union select a + 1 from x where a < 10) select * from @@ -1288,10 +945,7 @@ select val.x from generate_series(1, 10) as s (i), - lateral ( - values ((select s.i + 1)), (s.i + 101) - ) - as val (x) + lateral (values ((select s.i + 1)), (s.i + 101)) as val (x) where s.i < 10 and (select val.x) < 110; @@ -1304,11 +958,7 @@ select from int4_tbl where - case - when f1 in (select unique1 from tenk1 as a) - then f1 - else null - end in + case when f1 in (select unique1 from tenk1 as a) then f1 else null end in ( select ten from tenk1 as b ); @@ -1318,11 +968,7 @@ select from int4_tbl where - case - when f1 in (select unique1 from tenk1 as a) - then f1 - else null - end in + case when f1 in (select unique1 from tenk1 as a) then f1 else null end in ( select ten from tenk1 as b ); @@ -1332,43 +978,17 @@ select from int4_tbl as o where - (f1, f1) in - ( - select - f1, - generate_series(1, 50) / 10 as g - from - int4_tbl as i - group by f1 - ); + (f1, f1) in (select f1, generate_series(1, 50) / 10 as g from int4_tbl as i group by f1); select * from int4_tbl as o where - (f1, f1) in - ( - select - f1, - generate_series(1, 50) / 10 as g - from - int4_tbl as i - group by f1 - ); + (f1, f1) in (select f1, generate_series(1, 50) / 10 as g from int4_tbl as i group by f1); select - ( - select - q - from - ( - select 1, 2, 3 where f1 > 0 - union all - select 4, 5, 6.0 where f1 <= 0 - ) - as q - ) + (select q from (select 1, 2, 3 where f1 > 0 union all select 4, 5, 6.0 where f1 <= 0) as q) from int4_tbl; @@ -1377,11 +997,7 @@ select from int4_tbl as i4, lateral ( - select - i4.f1 > 1 as b, - 1 as id - from - (select random() order by 1) as t1 + select i4.f1 > 1 as b, 1 as id from (select random() order by 1) as t1 union all select true as b, 2 as id ) @@ -1394,11 +1010,7 @@ select from int4_tbl as i4, lateral ( - select - i4.f1 > 1 as b, - 1 as id - from - (select random() order by 1) as t1 + select i4.f1 > 1 as b, 1 as id from (select random() order by 1) as t1 union all select true as b, 2 as id ) @@ -1413,21 +1025,20 @@ select * from (select distinct ten from tenk1) as ss where ten < 10 + nextval('t select nextval('ts1'); create function tattle(x int, y int) -returns boolean +returns bool language plpgsql volatile -as $function$ +as $$ begin raise notice 'x = %, y = %', x, y; return x > y; -end -$function$; +end$$; select * from (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, 8); select * from (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, 8); -alter function tattle(int, int) stable; +alter function tattle(x int, y int) stable; select * from (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, 8); @@ -1437,7 +1048,7 @@ select * from (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss whe select * from (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, u); -drop function tattle(int, int); +drop function tattle(x int, y int); create table sq_limit ( pk int primary key, @@ -1446,20 +1057,12 @@ create table sq_limit ( ); insert into sq_limit -values - (1, 1, 1), - (2, 2, 2), - (3, 3, 3), - (4, 4, 4), - (5, 1, 1), - (6, 2, 2), - (7, 3, 3), - (8, 4, 4); +values (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 1, 1), (6, 2, 2), (7, 3, 3), (8, 4, 4); create function explain_sq_limit() returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin for ln in @@ -1470,7 +1073,7 @@ begin return next ln; end loop; end; -$function$; +$$; select * from explain_sq_limit(); @@ -1482,14 +1085,9 @@ drop table sq_limit; begin; -declare "c1" scroll +declare c1 scroll cursor -for select - * -from - generate_series(1, 4) as i -where - i <> all (values (2), (3));; +for select * from generate_series(1, 4) as i where i <> all (values (2), (3));; move forward all from c1; @@ -1508,13 +1106,7 @@ select from json_tab as t1 left outer join - ( - select - json_array(1, a absent on null) - from - json_tab as t2 - ) - as s + (select json_array(1, a absent on null) from json_tab as t2) as s on false; select @@ -1522,13 +1114,7 @@ select from json_tab as t1 left outer join - ( - select - json_array(1, a absent on null) - from - json_tab as t2 - ) - as s + (select json_array(1, a absent on null) from json_tab as t2) as s on false; rollback; @@ -1539,8 +1125,7 @@ select from ( select - cast(relname as information_schema.sql_identifier) - as tname, + cast(relname as information_schema.sql_identifier) as tname, * from (select * from pg_class as c) as ss1 @@ -1558,8 +1143,7 @@ select from ( select - cast(relname as information_schema.sql_identifier) - as tname, + cast(relname as information_schema.sql_identifier) as tname, * from (select * from pg_class as c) as ss1 @@ -1573,36 +1157,22 @@ where select t1.ten, - SUM(x) + sum(x) from tenk1 as t1 left outer join - lateral ( - select - t1.ten + t2.ten as x, - t2.fivethous - from - tenk1 as t2 - ) - as ss + lateral (select t1.ten + t2.ten as x, t2.fivethous from tenk1 as t2) as ss on t1.unique1 = ss.fivethous group by t1.ten order by t1.ten; select t1.ten, - SUM(x) + sum(x) from tenk1 as t1 left outer join - lateral ( - select - t1.ten + t2.ten as x, - t2.fivethous - from - tenk1 as t2 - ) - as ss + lateral (select t1.ten + t2.ten as x, t2.fivethous from tenk1 as t2) as ss on t1.unique1 = ss.fivethous group by t1.ten order by t1.ten; @@ -1615,10 +1185,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select t2.q1 + t3.q1 as x, * from int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + t3.q1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -1632,10 +1199,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select t2.q1 + t3.q1 as x, * from int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + t3.q1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -1649,10 +1213,7 @@ from left outer join int8_tbl as t2 inner join - lateral ( - select t2.q1 + 1 as x, * from int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + 1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -1666,10 +1227,7 @@ from left outer join int8_tbl as t2 inner join - lateral ( - select t2.q1 + 1 as x, * from int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + 1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -1683,10 +1241,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select t2.q1 + 1 as x, * from int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + 1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -1700,10 +1255,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select t2.q1 + 1 as x, * from int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + 1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -1717,10 +1269,7 @@ from left outer join int8_tbl as t2 inner join - lateral ( - select t2.q2 as x, * from int8_tbl as t3 - ) - as ss + lateral (select t2.q2 as x, * from int8_tbl as t3) as ss on t2.q2 = ss.q1 on t1.q1 = t2.q1 order by 1, @@ -1734,10 +1283,7 @@ from left outer join int8_tbl as t2 inner join - lateral ( - select t2.q2 as x, * from int8_tbl as t3 - ) - as ss + lateral (select t2.q2 as x, * from int8_tbl as t3) as ss on t2.q2 = ss.q1 on t1.q1 = t2.q1 order by 1, @@ -1751,10 +1297,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select t2.q2 as x, * from int8_tbl as t3 - ) - as ss + lateral (select t2.q2 as x, * from int8_tbl as t3) as ss on t2.q2 = ss.q1 on t1.q1 = t2.q1 order by 1, @@ -1768,10 +1311,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select t2.q2 as x, * from int8_tbl as t3 - ) - as ss + lateral (select t2.q2 as x, * from int8_tbl as t3) as ss on t2.q2 = ss.q1 on t1.q1 = t2.q1 order by 1, @@ -1784,20 +1324,10 @@ from left outer join int8_tbl as t2 left outer join - ( - select - coalesce(q1, q1) as x, - * - from - int8_tbl as t3 - ) - as ss1 + (select coalesce(q1, q1) as x, * from int8_tbl as t3) as ss1 on t2.q1 = ss1.q2 inner join - lateral ( - select ss1.x as y, * from int8_tbl as t4 - ) - as ss2 + lateral (select ss1.x as y, * from int8_tbl as t4) as ss2 on t2.q2 = ss2.q1 on t1.q2 = ss2.q1 order by 1, @@ -1811,20 +1341,10 @@ from left outer join int8_tbl as t2 left outer join - ( - select - coalesce(q1, q1) as x, - * - from - int8_tbl as t3 - ) - as ss1 + (select coalesce(q1, q1) as x, * from int8_tbl as t3) as ss1 on t2.q1 = ss1.q2 inner join - lateral ( - select ss1.x as y, * from int8_tbl as t4 - ) - as ss2 + lateral (select ss1.x as y, * from int8_tbl as t4) as ss2 on t2.q2 = ss2.q1 on t1.q2 = ss2.q1 order by 1, @@ -1838,20 +1358,10 @@ from left outer join int8_tbl as t2 left outer join - ( - select - coalesce(q1, q1) as x, - * - from - int8_tbl as t3 - ) - as ss1 + (select coalesce(q1, q1) as x, * from int8_tbl as t3) as ss1 on t2.q1 = ss1.q2 left outer join - lateral ( - select ss1.x as y, * from int8_tbl as t4 - ) - as ss2 + lateral (select ss1.x as y, * from int8_tbl as t4) as ss2 on t2.q2 = ss2.q1 on t1.q2 = ss2.q1 order by 1, @@ -1865,20 +1375,10 @@ from left outer join int8_tbl as t2 left outer join - ( - select - coalesce(q1, q1) as x, - * - from - int8_tbl as t3 - ) - as ss1 + (select coalesce(q1, q1) as x, * from int8_tbl as t3) as ss1 on t2.q1 = ss1.q2 left outer join - lateral ( - select ss1.x as y, * from int8_tbl as t4 - ) - as ss2 + lateral (select ss1.x as y, * from int8_tbl as t4) as ss2 on t2.q2 = ss2.q1 on t1.q2 = ss2.q1 order by 1, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap index a33f08977..bf7516c04 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap @@ -68,12 +68,7 @@ from where f1 in ( - select - f2 - from - subselect_tbl - where - f2 in (select f1 from subselect_tbl) + select f2 from subselect_tbl where f2 in (select f1 from subselect_tbl) ); select @@ -84,13 +79,7 @@ from where not (f1, f2) in ( - select - f2, - cast(f3 as int) - from - subselect_tbl - where - f3 is not null + select f2, cast(f3 as int4) from subselect_tbl where f3 is not null ); select @@ -99,15 +88,7 @@ select from subselect_tbl as upper where - f1 in - ( - select - f2 - from - subselect_tbl - where - f1 = upper.f1 - ); + f1 in (select f2 from subselect_tbl where f1 = upper.f1); select f1 as "Correlated Field", @@ -117,12 +98,7 @@ from where f1 in ( - select - f2 - from - subselect_tbl - where - cast(upper.f2 as double precision) = f3 + select f2 from subselect_tbl where cast(upper.f2 as double precision) = f3 ); select @@ -131,15 +107,7 @@ select from subselect_tbl as upper where - f3 in - ( - select - upper.f1 + f2 - from - subselect_tbl - where - f2 = cast(f3 as int) - ); + f3 in (select upper.f1 + f2 from subselect_tbl where f2 = cast(f3 as int)); select f1 as "Correlated Field" @@ -148,13 +116,7 @@ from where (f1, f2) in ( - select - f2, - cast(f3 as int) - from - subselect_tbl - where - f3 is not null + select f2, cast(f3 as int4) from subselect_tbl where f3 is not null ); select row(1, 2) = (select f1, f2) as eq from subselect_tbl; @@ -167,9 +129,9 @@ select row(1, 2) = (select 3, 4) as eq from subselect_tbl; select row(1, 2) = (select f1, f2 from subselect_tbl); -select count from (select COUNT(distinct name) from road); +select count from (select count(distinct name) from road); -select COUNT(*) from (select distinct name from road); +select count(*) from (select distinct name from road); select * from (select * from int4_tbl), (values (123456)) where f1 = column1; @@ -177,12 +139,7 @@ create view view_unnamed_ss as select * from - ( - select - * - from - (select abs(f1) as a1 from int4_tbl) - ), + (select * from (select abs(f1) as a1 from int4_tbl)), (select * from int8_tbl) where a1 < 10 and q1 > a1 @@ -211,20 +168,11 @@ select from subselect_tbl as ss where - not f1 in - ( - select - f1 + 1 - from - int4_tbl - where - f1 <> ss.f1 and f1 < 2147483647 - ); + not f1 in (select f1 + 1 from int4_tbl where f1 <> ss.f1 and f1 < 2147483647); select q1, - float8(COUNT(*)) / - (select COUNT(*) from int8_tbl) + float8(count(*)) / (select count(*) from int8_tbl) from int8_tbl group by q1 @@ -234,13 +182,7 @@ select *, pg_typeof(f1) from - ( - select - 'foo' as f1 - from - generate_series(1, 3) - ) - as ss + (select 'foo' as f1 from generate_series(1, 3)) as ss order by 1; select '42' union all select '43'; @@ -256,83 +198,40 @@ select from int4_tbl as o where - exists - ( - select - 1 - from - int4_tbl as i - where - i.f1 = o.f1 - limit null - ); + exists (select 1 from int4_tbl as i where i.f1 = o.f1 limit null); select * from int4_tbl as o where - not exists - ( - select - 1 - from - int4_tbl as i - where - i.f1 = o.f1 - limit 1 - ); + not exists (select 1 from int4_tbl as i where i.f1 = o.f1 limit 1); select * from int4_tbl as o where - exists - ( - select - 1 - from - int4_tbl as i - where - i.f1 = o.f1 - limit 0 - ); + exists (select 1 from int4_tbl as i where i.f1 = o.f1 limit 0); select - COUNT(*) + count(*) from ( - select - 1 - from - tenk1 as a - where - unique1 in - ( - select hundred from tenk1 as b - ) + select 1 from tenk1 as a where unique1 in (select hundred from tenk1 as b) ) as ss; select - COUNT(distinct ss.ten) + count(distinct ss.ten) from ( - select - ten - from - tenk1 as a - where - unique1 in - ( - select hundred from tenk1 as b - ) + select ten from tenk1 as a where unique1 in (select hundred from tenk1 as b) ) as ss; select - COUNT(*) + count(*) from ( select @@ -340,15 +239,12 @@ from from tenk1 as a where - unique1 in - ( - select distinct hundred from tenk1 as b - ) + unique1 in (select distinct hundred from tenk1 as b) ) as ss; select - COUNT(distinct ss.ten) + count(distinct ss.ten) from ( select @@ -356,10 +252,7 @@ from from tenk1 as a where - unique1 in - ( - select distinct hundred from tenk1 as b - ) + unique1 in (select distinct hundred from tenk1 as b) ) as ss; @@ -383,35 +276,14 @@ select from foo where - id in - ( - select - id2 - from - (select distinct id1, id2 from bar) as s - ); + id in (select id2 from (select distinct id1, id2 from bar) as s); select * from foo where - id in - ( - select - id2 - from - ( - select - id1, - id2 - from - bar - group by id1, - id2 - ) - as s - ); + id in (select id2 from (select id1, id2 from bar group by id1, id2) as s); select * @@ -423,12 +295,7 @@ where select id2 from - ( - select id1, id2 from bar - union - select id1, id2 from bar - ) - as s + (select id1, id2 from bar union select id1, id2 from bar) as s ); select @@ -436,51 +303,21 @@ select from foo where - id in - ( - select - id2 - from - ( - select distinct on (id2) - id1, - id2 - from - bar - ) - as s - ); + id in (select id2 from (select distinct on (id2) id1, id2 from bar) as s); select * from foo where - id in - ( - select - id2 - from - (select id2 from bar group by id2) as s - ); + id in (select id2 from (select id2 from bar group by id2) as s); select * from foo where - id in - ( - select - id2 - from - ( - select id2 from bar - union - select id2 from bar - ) - as s - ); + id in (select id2 from (select id2 from bar union select id2 from bar) as s); create table orderstest ( approver_ref int, @@ -513,13 +350,7 @@ insert into orderstest values (1, 1, false); create view orders_view as select *, - ( - select - case - when ord.approver_ref = 1 then '---' - else 'Approved' - end - ) + (select case when ord.approver_ref = 1 then '---' else 'Approved' end) as "Approved", ( select @@ -531,10 +362,7 @@ as select when ord.po_ref = 1 then ( select - case - when ord.approver_ref = 1 then '---' - else 'Approved' - end + case when ord.approver_ref = 1 then '---' else 'Approved' end ) else 'PO' end @@ -546,10 +374,7 @@ as select when ord.ordercanceled then 'Canceled' else case when ord.po_ref = 1 - then case - when ord.approver_ref = 1 then '---' - else 'Approved' - end + then case when ord.approver_ref = 1 then '---' else 'Approved' end else 'PO' end end @@ -563,14 +388,14 @@ drop table orderstest cascade; create temporary table parts ( partnum text, - cost double precision + cost float8 ); create temporary table shipped ( ttype char(2), - ordnum int, + ordnum int4, partnum text, - value double precision + value float8 ); create temporary view shipped_view @@ -579,28 +404,12 @@ as select * from shipped where ttype = 'wt'; create rule shipped_view_insert as on insert to shipped_view do instead - insert into shipped - values - ( - 'wt', new.ordnum, new.partnum, new.value - );; + insert into shipped values ('wt', new.ordnum, new.partnum, new.value);; insert into parts (partnum, cost) values (1, 1234.56); insert into shipped_view (ordnum, partnum, value) -values - ( - 0, - 1, - ( - select - cost - from - parts - where - partnum = '1' - ) - ); +values (0, 1, (select cost from parts where partnum = '1')); select * from shipped_view; @@ -611,23 +420,14 @@ do instead set partnum = new.partnum, value = new.value where - ttype = new.ttype and - ordnum = new.ordnum;; + ttype = new.ttype and ordnum = new.ordnum;; update shipped_view set value = 11 from int4_tbl as a inner join int4_tbl as b -on a.f1 = - ( - select - f1 - from - int4_tbl as c - where - c.f1 = b.f1 - ) +on a.f1 = (select f1 from int4_tbl as c where c.f1 = b.f1) where ordnum = a.f1; @@ -640,15 +440,7 @@ from ( select *, - ( - select - SUM(f1) - from - int4_tbl as b - where - f1 >= a.f1 - ) - as ss1 + (select sum(f1) from int4_tbl as b where f1 >= a.f1) as ss1 from int4_tbl as a ) @@ -659,19 +451,11 @@ select from ( select - MAX(unique1) + max(unique1) from tenk1 as a where - exists - ( - select - 1 - from - tenk1 as b - where - b.thousand = a.unique2 - ) + exists (select 1 from tenk1 as b where b.thousand = a.unique2) ) as ss; @@ -680,19 +464,11 @@ select from ( select - MIN(unique1) + min(unique1) from tenk1 as a where - not exists - ( - select - 1 - from - tenk1 as b - where - b.unique2 = 10000 - ) + not exists (select 1 from tenk1 as b where b.unique2 = 10000) ) as ss; @@ -700,7 +476,7 @@ create temporary table numeric_table (num_col numeric); insert into numeric_table values (1), (1.000000000000000000001), (2), (3); -create temporary table float_table (float_col double precision); +create temporary table float_table (float_col float8); insert into float_table values (1), (2), (3); @@ -709,20 +485,14 @@ select from float_table where - float_col in - ( - select num_col from numeric_table - ); + float_col in (select num_col from numeric_table); select * from numeric_table where - num_col in - ( - select float_col from float_table - ); + num_col in (select float_col from float_table); create table semijoin_unique_tbl ( a int, @@ -730,11 +500,7 @@ create table semijoin_unique_tbl ( ); insert into semijoin_unique_tbl -select - i % 10, - i % 10 -from - generate_series(1, 1000) as i; +select i % 10, i % 10 from generate_series(1, 1000) as i; create index on semijoin_unique_tbl using btree (a, b); @@ -746,14 +512,7 @@ from semijoin_unique_tbl as t1, semijoin_unique_tbl as t2 where - (t1.a, t2.a) in - ( - select - a, - b - from - semijoin_unique_tbl as t3 - ) + (t1.a, t2.a) in (select a, b from semijoin_unique_tbl as t3) order by t1.a, t2.a; @@ -763,14 +522,7 @@ from semijoin_unique_tbl as t1, semijoin_unique_tbl as t2 where - (t1.a, t2.a) in - ( - select - a + 1, - b + 1 - from - semijoin_unique_tbl as t3 - ) + (t1.a, t2.a) in (select a + 1, b + 1 from semijoin_unique_tbl as t3) order by t1.a, t2.a; @@ -790,14 +542,7 @@ from semijoin_unique_tbl as t1, semijoin_unique_tbl as t2 where - (t1.a, t2.a) in - ( - select - a, - b - from - semijoin_unique_tbl as t3 - ) + (t1.a, t2.a) in (select a, b from semijoin_unique_tbl as t3) order by t1.a, t2.a; @@ -847,10 +592,7 @@ from unique_tbl_p as t1, unique_tbl_p as t2 where - (t1.a, t2.a) in - ( - select a, a from unique_tbl_p as t3 - ) + (t1.a, t2.a) in (select a, a from unique_tbl_p as t3) order by t1.a, t2.a; @@ -892,19 +634,11 @@ insert into tc values (2, 2); select ( select - MIN(tb.id) + min(tb.id) from tb where - tb.aval = - ( - select - ta.val - from - ta - where - ta.id = tc.aid - ) + tb.aval = (select ta.val from ta where ta.id = tc.aid) ) as min_tb_id from @@ -922,15 +656,7 @@ from select distinct f1, f2, - ( - select - f2 - from - t1 as x - where - x.f1 = up.f1 - ) - as fs + (select f2 from t1 as x where x.f1 = up.f1) as fs from t1 as up ) @@ -958,18 +684,9 @@ select 1 = any (array_agg(f1)) = any (select false) from int4_tbl; select 1 = any (array_agg(f1)) = any (select false) from int4_tbl; -select q from (select MAX(f1) from int4_tbl group by f1 order by f1) as q; - -with -q -as ( - select - MAX(f1) - from - int4_tbl - group by f1 - order by f1 -) +select q from (select max(f1) from int4_tbl group by f1 order by f1) as q; + +with q as (select max(f1) from int4_tbl group by f1 order by f1) select q from @@ -986,14 +703,7 @@ where from int4_tbl inner join - ( - select - f1, - array(select q1 from int8_tbl) as arr - from - text_tbl - ) - as ss + (select f1, array(select q1 from int8_tbl) as arr from text_tbl) as ss on true where road.name = ss.f1 @@ -1006,11 +716,7 @@ select from ( select - exists - ( - select 1 from int4_tbl where f1 = q2 - ) - as sq1, + exists (select 1 from int4_tbl where f1 = q2) as sq1, 42 as dummy from int8_tbl @@ -1021,17 +727,13 @@ from on dummy = i4.f1; create temporary table upsert ( - key int primary key, + key int4 primary key, val text ); insert into upsert values (1, 'val') -on conflict -(key) -do -update -set val = 'not seen'; +on conflict (key) do update set val = 'not seen'; insert into upsert values (1, 'val') @@ -1040,40 +742,19 @@ on conflict do update set val = 'seen with subselect ' || -cast(( - select - f1 - from - int4_tbl - where - f1 <> 0 - limit 1 -) -as text); +cast((select f1 from int4_tbl where f1 <> 0 limit 1) as text); select * from upsert; -with -aa -as ( - select - 'int4_tbl' as u - from - int4_tbl - limit 1 -) +with aa as (select 'int4_tbl' as u from int4_tbl limit 1) insert into upsert values (1, 'x'), (999, 'y') -on conflict -(key) -do -update -set val = (select u from aa) +on conflict (key) do update set val = (select u from aa) returning *; create temporary table outer_7597 ( - f1 int, - f2 int + f1 int4, + f2 int4 ); insert into outer_7597 values (0, 0); @@ -1085,8 +766,8 @@ insert into outer_7597 values (0, null); insert into outer_7597 values (1, null); create temporary table inner_7597 ( - c1 bigint, - c2 bigint + c1 int8, + c2 int8 ); insert into inner_7597 values (0, null); @@ -1120,17 +801,13 @@ select * from outer_text where not (f1, f2) in (select * from inner_text); select cast('foo' as text) in ( - select cast('bar' as name) - union all - select cast('bar' as name) + select cast('bar' as name) union all select cast('bar' as name) ); select cast('foo' as text) in ( - select cast('bar' as name) - union all - select cast('bar' as name) + select cast('bar' as name) union all select cast('bar' as name) ); select row(row(row(1))) = any (select row(row(1))); @@ -1140,47 +817,41 @@ select row(row(row(1))) = any (select row(row(1))); select cast('1' as text) in ( - select cast('1' as name) - union all - select cast('1' as name) + select cast('1' as name) union all select cast('1' as name) ); select * from int8_tbl where q1 in (select c1 from inner_text); begin; -create function bogus_int8_text_eq(bigint, text) +create function bogus_int8_text_eq(int8, text) returns boolean language sql -as $function$ -select $1::text = $2 -$function$; +as 'select $1::text = $2'; -create operator = (PROCEDURE = bogus_int8_text_eq, -LEFTARG = bigint, -RIGHTARG = text); +create operator = ( + procedure = bogus_int8_text_eq, + leftarg = int8, + rightarg = text +); select * from int8_tbl where q1 in (select c1 from inner_text); select * from int8_tbl where q1 in (select c1 from inner_text); -create or replace function bogus_int8_text_eq(bigint, text) +create or replace function bogus_int8_text_eq(int8, text) returns boolean language sql -as $function$ -select $1::text = $2 and $1::text = $2 -$function$; +as 'select $1::text = $2 and $1::text = $2'; select * from int8_tbl where q1 in (select c1 from inner_text); select * from int8_tbl where q1 in (select c1 from inner_text); -create or replace function bogus_int8_text_eq(bigint, text) +create or replace function bogus_int8_text_eq(int8, text) returns boolean language sql -as $function$ -select $2 = $1::text -$function$; +as 'select $2 = $1::text'; select * from int8_tbl where q1 in (select c1 from inner_text); @@ -1189,72 +860,36 @@ select * from int8_tbl where q1 in (select c1 from inner_text); rollback; select - COUNT(*) + count(*) from tenk1 as t where - exists - ( - select - 1 - from - tenk1 as k - where - k.unique1 = t.unique2 - ) or - ten < 0; + exists (select 1 from tenk1 as k where k.unique1 = t.unique2) or ten < 0; select - COUNT(*) + count(*) from tenk1 as t where - exists - ( - select - 1 - from - tenk1 as k - where - k.unique1 = t.unique2 - ) or - ten < 0; + exists (select 1 from tenk1 as k where k.unique1 = t.unique2) or ten < 0; select - COUNT(*) + count(*) from tenk1 as t where ( - exists - ( - select - 1 - from - tenk1 as k - where - k.unique1 = t.unique2 - ) or - ten < 0 + exists (select 1 from tenk1 as k where k.unique1 = t.unique2) or ten < 0 ) and thousand = 1; select - COUNT(*) + count(*) from tenk1 as t where ( - exists - ( - select - 1 - from - tenk1 as k - where - k.unique1 = t.unique2 - ) or - ten < 0 + exists (select 1 from tenk1 as k where k.unique1 = t.unique2) or ten < 0 ) and thousand = 1; @@ -1263,7 +898,7 @@ create temporary table exists_tbl ( c2 int, c3 int ) -partition by LIST(c1); +partition by list(c1); create temporary table exists_tbl_null partition of exists_tbl @@ -1280,32 +915,14 @@ select from exists_tbl as t1 where - exists - ( - select - 1 - from - exists_tbl as t2 - where - t1.c1 = t2.c2 - ) or - c3 < 0; + exists (select 1 from exists_tbl as t2 where t1.c1 = t2.c2) or c3 < 0; select * from exists_tbl as t1 where - exists - ( - select - 1 - from - exists_tbl as t2 - where - t1.c1 = t2.c2 - ) or - c3 < 0; + exists (select 1 from exists_tbl as t2 where t1.c1 = t2.c2) or c3 < 0; select a.thousand @@ -1322,50 +939,27 @@ where tenk1 as c where b.hundred = c.hundred and - not exists - ( - select - 1 - from - tenk1 as d - where - a.thousand = d.thousand - ) + not exists (select 1 from tenk1 as d where a.thousand = d.thousand) ); select x, x from - ( - select - (select NOW()) as x - from - (values (1), (2)) as v (y) - ) - as ss; + (select (select now()) as x from (values (1), (2)) as v (y)) as ss; select x, x from - ( - select - (select random()) as x - from - (values (1), (2)) as v (y) - ) - as ss; + (select (select random()) as x from (values (1), (2)) as v (y)) as ss; select x, x from ( - select - (select NOW() where y = y) as x - from - (values (1), (2)) as v (y) + select (select now() where y = y) as x from (values (1), (2)) as v (y) ) as ss; @@ -1374,30 +968,18 @@ select x from ( - select - (select random() where y = y) as x - from - (values (1), (2)) as v (y) + select (select random() where y = y) as x from (values (1), (2)) as v (y) ) as ss; select - SUM(cast(ss.tst as int)) + sum(cast(ss.tst as int)) from onek as o inner join lateral ( select - i.ten in - ( - select - f1 - from - int4_tbl - where - f1 <= o.hundred - ) - as tst, + i.ten in (select f1 from int4_tbl where f1 <= o.hundred) as tst, random() as r from onek as i @@ -1410,22 +992,13 @@ where o.ten = 0; select - SUM(cast(ss.tst as int)) + sum(cast(ss.tst as int)) from onek as o inner join lateral ( select - i.ten in - ( - select - f1 - from - int4_tbl - where - f1 <= o.hundred - ) - as tst, + i.ten in (select f1 from int4_tbl where f1 <= o.hundred) as tst, random() as r from onek as i @@ -1442,24 +1015,14 @@ begin; set local enable_sort = off; select - COUNT(*) + count(*) from onek as o inner join lateral ( - select - * - from - onek as i1 - where - i1.unique1 = o.unique1 + select * from onek as i1 where i1.unique1 = o.unique1 except - select - * - from - onek as i2 - where - i2.unique1 = o.unique2 + select * from onek as i2 where i2.unique1 = o.unique2 ) as ss on true @@ -1467,24 +1030,14 @@ where o.ten = 1; select - COUNT(*) + count(*) from onek as o inner join lateral ( - select - * - from - onek as i1 - where - i1.unique1 = o.unique1 + select * from onek as i1 where i1.unique1 = o.unique1 except - select - * - from - onek as i2 - where - i2.unique1 = o.unique2 + select * from onek as i2 where i2.unique1 = o.unique2 ) as ss on true @@ -1498,24 +1051,14 @@ begin; set local enable_hashagg = off; select - COUNT(*) + count(*) from onek as o inner join lateral ( - select - * - from - onek as i1 - where - i1.unique1 = o.unique1 + select * from onek as i1 where i1.unique1 = o.unique1 except - select - * - from - onek as i2 - where - i2.unique1 = o.unique2 + select * from onek as i2 where i2.unique1 = o.unique2 ) as ss on true @@ -1523,24 +1066,14 @@ where o.ten = 1; select - COUNT(*) + count(*) from onek as o inner join lateral ( - select - * - from - onek as i1 - where - i1.unique1 = o.unique1 + select * from onek as i1 where i1.unique1 = o.unique1 except - select - * - from - onek as i2 - where - i2.unique1 = o.unique2 + select * from onek as i2 where i2.unique1 = o.unique2 ) as ss on true @@ -1550,19 +1083,14 @@ where rollback; select - SUM(o.four), - SUM(ss.a) + sum(o.four), + sum(ss.a) from onek as o inner join lateral ( with recursive - x (a) - as ( - select o.four as a - union - select a + 1 from x where a < 10 - ) + x (a) as (select o.four as a union select a + 1 from x where a < 10) select * from @@ -1574,19 +1102,14 @@ where o.ten = 1; select - SUM(o.four), - SUM(ss.a) + sum(o.four), + sum(ss.a) from onek as o inner join lateral ( with recursive - x (a) - as ( - select o.four as a - union - select a + 1 from x where a < 10 - ) + x (a) as (select o.four as a union select a + 1 from x where a < 10) select * from @@ -1613,53 +1136,26 @@ select val.x from generate_series(1, 10) as s (i), - lateral ( - values ((select s.i + 1)), (s.i + 101) - ) - as val (x) + lateral (values ((select s.i + 1)), (s.i + 101)) as val (x) where s.i < 10 and (select val.x) < 110; select * from - ( - values - ( - not 3 in - ( - select * from (values (1), (2)) as ss1 - ) - ), - (false) - ) - as ss; + (values (not 3 in (select * from (values (1), (2)) as ss1)), (false)) as ss; select * from - ( - values - ( - not 3 in - ( - select * from (values (1), (2)) as ss1 - ) - ), - (false) - ) - as ss; + (values (not 3 in (select * from (values (1), (2)) as ss1)), (false)) as ss; select * from int4_tbl where - case - when f1 in (select unique1 from tenk1 as a) - then f1 - else null - end in + case when f1 in (select unique1 from tenk1 as a) then f1 else null end in ( select ten from tenk1 as b ); @@ -1669,11 +1165,7 @@ select from int4_tbl where - case - when f1 in (select unique1 from tenk1 as a) - then f1 - else null - end in + case when f1 in (select unique1 from tenk1 as a) then f1 else null end in ( select ten from tenk1 as b ); @@ -1685,12 +1177,7 @@ from where (f1, f1) in ( - select - f1, - generate_series(1, 50) / 10 as g - from - int4_tbl as i - group by f1 + select f1, generate_series(1, 50) / 10 as g from int4_tbl as i group by f1 ); select @@ -1700,12 +1187,7 @@ from where (f1, f1) in ( - select - f1, - generate_series(1, 50) / 10 as g - from - int4_tbl as i - group by f1 + select f1, generate_series(1, 50) / 10 as g from int4_tbl as i group by f1 ); select @@ -1714,9 +1196,7 @@ select q from ( - select 1, 2, 3 where f1 > 0 - union all - select 4, 5, 6.0 where f1 <= 0 + select 1, 2, 3 where f1 > 0 union all select 4, 5, 6.0 where f1 <= 0 ) as q ) @@ -1728,11 +1208,7 @@ select from int4_tbl as i4, lateral ( - select - i4.f1 > 1 as b, - 1 as id - from - (select random() order by 1) as t1 + select i4.f1 > 1 as b, 1 as id from (select random() order by 1) as t1 union all select true as b, 2 as id ) @@ -1745,11 +1221,7 @@ select from int4_tbl as i4, lateral ( - select - i4.f1 > 1 as b, - 1 as id - from - (select random() order by 1) as t1 + select i4.f1 > 1 as b, 1 as id from (select random() order by 1) as t1 union all select true as b, 2 as id ) @@ -1770,91 +1242,60 @@ order by 1; select nextval('ts1'); create function tattle(x int, y int) -returns boolean +returns bool language plpgsql volatile -as $function$ +as $$ begin raise notice 'x = %, y = %', x, y; return x > y; -end -$function$; +end$$; select * from - ( - select - 9 as x, - unnest(array[1, 2, 3, 11, 12, 13]) as u - ) - as ss + (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, 8); select * from - ( - select - 9 as x, - unnest(array[1, 2, 3, 11, 12, 13]) as u - ) - as ss + (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, 8); -alter function tattle(int, int) stable; +alter function tattle(x int, y int) stable; select * from - ( - select - 9 as x, - unnest(array[1, 2, 3, 11, 12, 13]) as u - ) - as ss + (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, 8); select * from - ( - select - 9 as x, - unnest(array[1, 2, 3, 11, 12, 13]) as u - ) - as ss + (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, 8); select * from - ( - select - 9 as x, - unnest(array[1, 2, 3, 11, 12, 13]) as u - ) - as ss + (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, u); select * from - ( - select - 9 as x, - unnest(array[1, 2, 3, 11, 12, 13]) as u - ) - as ss + (select 9 as x, unnest(array[1, 2, 3, 11, 12, 13]) as u) as ss where tattle(x, u); -drop function tattle(int, int); +drop function tattle(x int, y int); create table sq_limit ( pk int primary key, @@ -1876,7 +1317,7 @@ values create function explain_sq_limit() returns setof text language plpgsql -as $function$ +as $$ declare ln text; begin for ln in @@ -1887,7 +1328,7 @@ begin return next ln; end loop; end; -$function$; +$$; select * from explain_sq_limit(); @@ -1899,14 +1340,9 @@ drop table sq_limit; begin; -declare "c1" scroll +declare c1 scroll cursor -for select - * -from - generate_series(1, 4) as i -where - i <> all (values (2), (3));; +for select * from generate_series(1, 4) as i where i <> all (values (2), (3));; move forward all from c1; @@ -1925,13 +1361,7 @@ select from json_tab as t1 left outer join - ( - select - json_array(1, a absent on null) - from - json_tab as t2 - ) - as s + (select json_array(1, a absent on null) from json_tab as t2) as s on false; select @@ -1939,13 +1369,7 @@ select from json_tab as t1 left outer join - ( - select - json_array(1, a absent on null) - from - json_tab as t2 - ) - as s + (select json_array(1, a absent on null) from json_tab as t2) as s on false; rollback; @@ -1956,9 +1380,7 @@ select from ( select - cast(relname - as information_schema.sql_identifier) - as tname, + cast(relname as information_schema.sql_identifier) as tname, * from (select * from pg_class as c) as ss1 @@ -1976,9 +1398,7 @@ select from ( select - cast(relname - as information_schema.sql_identifier) - as tname, + cast(relname as information_schema.sql_identifier) as tname, * from (select * from pg_class as c) as ss1 @@ -1992,36 +1412,22 @@ where select t1.ten, - SUM(x) + sum(x) from tenk1 as t1 left outer join - lateral ( - select - t1.ten + t2.ten as x, - t2.fivethous - from - tenk1 as t2 - ) - as ss + lateral (select t1.ten + t2.ten as x, t2.fivethous from tenk1 as t2) as ss on t1.unique1 = ss.fivethous group by t1.ten order by t1.ten; select t1.ten, - SUM(x) + sum(x) from tenk1 as t1 left outer join - lateral ( - select - t1.ten + t2.ten as x, - t2.fivethous - from - tenk1 as t2 - ) - as ss + lateral (select t1.ten + t2.ten as x, t2.fivethous from tenk1 as t2) as ss on t1.unique1 = ss.fivethous group by t1.ten order by t1.ten; @@ -2034,14 +1440,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select - t2.q1 + t3.q1 as x, - * - from - int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + t3.q1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -2055,14 +1454,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select - t2.q1 + t3.q1 as x, - * - from - int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + t3.q1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -2076,14 +1468,7 @@ from left outer join int8_tbl as t2 inner join - lateral ( - select - t2.q1 + 1 as x, - * - from - int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + 1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -2097,14 +1482,7 @@ from left outer join int8_tbl as t2 inner join - lateral ( - select - t2.q1 + 1 as x, - * - from - int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + 1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -2118,14 +1496,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select - t2.q1 + 1 as x, - * - from - int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + 1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -2139,14 +1510,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select - t2.q1 + 1 as x, - * - from - int8_tbl as t3 - ) - as t3 + lateral (select t2.q1 + 1 as x, * from int8_tbl as t3) as t3 on t2.q2 = t3.q2 on t1.q2 = t2.q2 order by 1, @@ -2160,10 +1524,7 @@ from left outer join int8_tbl as t2 inner join - lateral ( - select t2.q2 as x, * from int8_tbl as t3 - ) - as ss + lateral (select t2.q2 as x, * from int8_tbl as t3) as ss on t2.q2 = ss.q1 on t1.q1 = t2.q1 order by 1, @@ -2177,10 +1538,7 @@ from left outer join int8_tbl as t2 inner join - lateral ( - select t2.q2 as x, * from int8_tbl as t3 - ) - as ss + lateral (select t2.q2 as x, * from int8_tbl as t3) as ss on t2.q2 = ss.q1 on t1.q1 = t2.q1 order by 1, @@ -2194,10 +1552,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select t2.q2 as x, * from int8_tbl as t3 - ) - as ss + lateral (select t2.q2 as x, * from int8_tbl as t3) as ss on t2.q2 = ss.q1 on t1.q1 = t2.q1 order by 1, @@ -2211,10 +1566,7 @@ from left outer join int8_tbl as t2 left outer join - lateral ( - select t2.q2 as x, * from int8_tbl as t3 - ) - as ss + lateral (select t2.q2 as x, * from int8_tbl as t3) as ss on t2.q2 = ss.q1 on t1.q1 = t2.q1 order by 1, @@ -2227,20 +1579,10 @@ from left outer join int8_tbl as t2 left outer join - ( - select - coalesce(q1, q1) as x, - * - from - int8_tbl as t3 - ) - as ss1 + (select coalesce(q1, q1) as x, * from int8_tbl as t3) as ss1 on t2.q1 = ss1.q2 inner join - lateral ( - select ss1.x as y, * from int8_tbl as t4 - ) - as ss2 + lateral (select ss1.x as y, * from int8_tbl as t4) as ss2 on t2.q2 = ss2.q1 on t1.q2 = ss2.q1 order by 1, @@ -2254,20 +1596,10 @@ from left outer join int8_tbl as t2 left outer join - ( - select - coalesce(q1, q1) as x, - * - from - int8_tbl as t3 - ) - as ss1 + (select coalesce(q1, q1) as x, * from int8_tbl as t3) as ss1 on t2.q1 = ss1.q2 inner join - lateral ( - select ss1.x as y, * from int8_tbl as t4 - ) - as ss2 + lateral (select ss1.x as y, * from int8_tbl as t4) as ss2 on t2.q2 = ss2.q1 on t1.q2 = ss2.q1 order by 1, @@ -2281,20 +1613,10 @@ from left outer join int8_tbl as t2 left outer join - ( - select - coalesce(q1, q1) as x, - * - from - int8_tbl as t3 - ) - as ss1 + (select coalesce(q1, q1) as x, * from int8_tbl as t3) as ss1 on t2.q1 = ss1.q2 left outer join - lateral ( - select ss1.x as y, * from int8_tbl as t4 - ) - as ss2 + lateral (select ss1.x as y, * from int8_tbl as t4) as ss2 on t2.q2 = ss2.q1 on t1.q2 = ss2.q1 order by 1, @@ -2308,34 +1630,17 @@ from left outer join int8_tbl as t2 left outer join - ( - select - coalesce(q1, q1) as x, - * - from - int8_tbl as t3 - ) - as ss1 + (select coalesce(q1, q1) as x, * from int8_tbl as t3) as ss1 on t2.q1 = ss1.q2 left outer join - lateral ( - select ss1.x as y, * from int8_tbl as t4 - ) - as ss2 + lateral (select ss1.x as y, * from int8_tbl as t4) as ss2 on t2.q2 = ss2.q1 on t1.q2 = ss2.q1 order by 1, 2, 3; -with -x -as ( - select - * - from - (select f1 from subselect_tbl) as ss -) +with x as (select * from (select f1 from subselect_tbl) as ss) select * from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sysviews_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sysviews_100.snap index 2bc8cbed9..6e83a3392 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sysviews_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sysviews_100.snap @@ -3,9 +3,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/sysviews.sql snapshot_kind: text --- -select COUNT(*) >= 0 as ok from pg_available_extension_versions; +select count(*) >= 0 as ok from pg_available_extension_versions; -select COUNT(*) >= 0 as ok from pg_available_extensions; +select count(*) >= 0 as ok from pg_available_extensions; select type, @@ -20,18 +20,13 @@ where begin; -declare "cur" +declare cur cursor for select left(a, 10), b from - ( - values - (repeat('a', 512 * 1024), 1), - (repeat('b', 512), 2) - ) - as v (a, b) + (values (repeat('a', 512 * 1024), 1), (repeat('b', 512), 2)) as v (a, b) order by v.a desc;; fetch next from cur; @@ -50,57 +45,50 @@ where rollback; -with -contexts -as ( - select * from pg_backend_memory_contexts -) +with contexts as (select * from pg_backend_memory_contexts) select - COUNT(*) > 1 + count(*) > 1 from contexts as c1, contexts as c2 where - c2.name = 'CacheMemoryContext' and - c1.path[c2.level] = c2.path[c2.level]; + c2.name = 'CacheMemoryContext' and c1.path[c2.level] = c2.path[c2.level]; -select COUNT(*) > 20 as ok from pg_config; +select count(*) > 20 as ok from pg_config; -select COUNT(*) = 0 as ok from pg_cursors; +select count(*) = 0 as ok from pg_cursors; -select COUNT(*) >= 0 as ok from pg_file_settings; +select count(*) >= 0 as ok from pg_file_settings; select - COUNT(*) > 0 as ok, - COUNT(*) filter (where error is not null) = 0 - as no_err + count(*) > 0 as ok, + count(*) filter (where error is not null) = 0 as no_err from pg_hba_file_rules; select - COUNT(*) >= 0 as ok, - COUNT(*) filter (where error is not null) = 0 - as no_err + count(*) >= 0 as ok, + count(*) filter (where error is not null) = 0 as no_err from pg_ident_file_mappings; -select COUNT(*) > 0 as ok from pg_locks; +select count(*) > 0 as ok from pg_locks; -select COUNT(*) = 0 as ok from pg_prepared_statements; +select count(*) = 0 as ok from pg_prepared_statements; -select COUNT(*) >= 0 as ok from pg_prepared_xacts; +select count(*) >= 0 as ok from pg_prepared_xacts; -select COUNT(*) > 0 as ok from pg_stat_slru; +select count(*) > 0 as ok from pg_stat_slru; -select COUNT(*) = 1 as ok from pg_stat_wal; +select count(*) = 1 as ok from pg_stat_wal; -select COUNT(*) = 0 as ok from pg_stat_wal_receiver; +select count(*) = 0 as ok from pg_stat_wal_receiver; select name, setting from pg_settings where name like 'enable%'; select type, - COUNT(*) > 0 as ok + count(*) > 0 as ok from pg_wait_events where @@ -108,16 +96,16 @@ where group by type order by type collate "C"; -select COUNT(distinct utc_offset) >= 24 as ok from pg_timezone_names; +select count(distinct utc_offset) >= 24 as ok from pg_timezone_names; -select COUNT(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; +select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; -set timezone_abbreviations = Australia; +set timezone_abbreviations = 'Australia'; -select COUNT(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; +select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; -set timezone_abbreviations = India; +set timezone_abbreviations = 'India'; -select COUNT(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; +select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; select * from pg_timezone_abbrevs where abbrev = 'LMT'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sysviews_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sysviews_80.snap index 2cf2ece62..6e83a3392 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__sysviews_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__sysviews_80.snap @@ -3,9 +3,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/sysviews.sql snapshot_kind: text --- -select COUNT(*) >= 0 as ok from pg_available_extension_versions; +select count(*) >= 0 as ok from pg_available_extension_versions; -select COUNT(*) >= 0 as ok from pg_available_extensions; +select count(*) >= 0 as ok from pg_available_extensions; select type, @@ -20,18 +20,13 @@ where begin; -declare "cur" +declare cur cursor for select left(a, 10), b from - ( - values - (repeat('a', 512 * 1024), 1), - (repeat('b', 512), 2) - ) - as v (a, b) + (values (repeat('a', 512 * 1024), 1), (repeat('b', 512), 2)) as v (a, b) order by v.a desc;; fetch next from cur; @@ -50,67 +45,50 @@ where rollback; -with -contexts -as ( - select * from pg_backend_memory_contexts -) +with contexts as (select * from pg_backend_memory_contexts) select - COUNT(*) > 1 + count(*) > 1 from contexts as c1, contexts as c2 where - c2.name = 'CacheMemoryContext' and - c1.path[c2.level] = c2.path[c2.level]; + c2.name = 'CacheMemoryContext' and c1.path[c2.level] = c2.path[c2.level]; -select COUNT(*) > 20 as ok from pg_config; +select count(*) > 20 as ok from pg_config; -select COUNT(*) = 0 as ok from pg_cursors; +select count(*) = 0 as ok from pg_cursors; -select COUNT(*) >= 0 as ok from pg_file_settings; +select count(*) >= 0 as ok from pg_file_settings; select - COUNT(*) > 0 as ok, - COUNT( - * - ) - filter (where - error is not null) = - 0 - as no_err + count(*) > 0 as ok, + count(*) filter (where error is not null) = 0 as no_err from pg_hba_file_rules; select - COUNT(*) >= 0 as ok, - COUNT( - * - ) - filter (where - error is not null) = - 0 - as no_err + count(*) >= 0 as ok, + count(*) filter (where error is not null) = 0 as no_err from pg_ident_file_mappings; -select COUNT(*) > 0 as ok from pg_locks; +select count(*) > 0 as ok from pg_locks; -select COUNT(*) = 0 as ok from pg_prepared_statements; +select count(*) = 0 as ok from pg_prepared_statements; -select COUNT(*) >= 0 as ok from pg_prepared_xacts; +select count(*) >= 0 as ok from pg_prepared_xacts; -select COUNT(*) > 0 as ok from pg_stat_slru; +select count(*) > 0 as ok from pg_stat_slru; -select COUNT(*) = 1 as ok from pg_stat_wal; +select count(*) = 1 as ok from pg_stat_wal; -select COUNT(*) = 0 as ok from pg_stat_wal_receiver; +select count(*) = 0 as ok from pg_stat_wal_receiver; select name, setting from pg_settings where name like 'enable%'; select type, - COUNT(*) > 0 as ok + count(*) > 0 as ok from pg_wait_events where @@ -118,16 +96,16 @@ where group by type order by type collate "C"; -select COUNT(distinct utc_offset) >= 24 as ok from pg_timezone_names; +select count(distinct utc_offset) >= 24 as ok from pg_timezone_names; -select COUNT(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; +select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; -set timezone_abbreviations = Australia; +set timezone_abbreviations = 'Australia'; -select COUNT(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; +select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; -set timezone_abbreviations = India; +set timezone_abbreviations = 'India'; -select COUNT(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; +select count(distinct utc_offset) >= 24 as ok from pg_timezone_abbrevs; select * from pg_timezone_abbrevs where abbrev = 'LMT'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablesample_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablesample_100.snap index 7318542fa..ac374e3ac 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablesample_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablesample_100.snap @@ -10,11 +10,7 @@ create table test_tablesample ( with (fillfactor = 10); insert into test_tablesample -select - i, - repeat(cast(i as text), 200) -from - generate_series(0, 9) as s (i); +select i, repeat(cast(i as text), 200) from generate_series(0, 9) as s (i); select t.id from test_tablesample as t tablesample system (50) repeatable (0); @@ -26,36 +22,23 @@ select id from test_tablesample tablesample bernoulli (50) repeatable (0); select id from test_tablesample tablesample bernoulli (5.5) repeatable (0); -select COUNT(*) from test_tablesample tablesample system (100); +select count(*) from test_tablesample tablesample system (100); -select COUNT(*) from test_tablesample tablesample system (100) repeatable (1 + 2); +select count(*) from test_tablesample tablesample system (100) repeatable (1 + 2); -select COUNT(*) from test_tablesample tablesample system (100) repeatable (0.4); +select count(*) from test_tablesample tablesample system (100) repeatable (0.4); create view test_tablesample_v1 -as select - id -from - test_tablesample - tablesample system (10 * 2) - repeatable (2); +as select id from test_tablesample tablesample system (10 * 2) repeatable (2); create view test_tablesample_v2 -as select - id -from - test_tablesample tablesample system (99); +as select id from test_tablesample tablesample system (99); begin; -declare "tablesample_cur" scroll +declare tablesample_cur scroll cursor -for select - id -from - test_tablesample - tablesample system (50) - repeatable (0);; +for select id from test_tablesample tablesample system (50) repeatable (0);; fetch absolute 1 from tablesample_cur; @@ -91,73 +74,51 @@ select id from test_tablesample tablesample system (50) repeatable (2); select * from test_tablesample_v1; -select COUNT(*) from person tablesample bernoulli (100); +select count(*) from person tablesample bernoulli (100); -select COUNT(*) from person tablesample bernoulli (100); +select count(*) from person tablesample bernoulli (100); -select COUNT(*) from person; +select count(*) from person; select - COUNT(*) + count(*) from - test_tablesample - tablesample bernoulli (cast(cast('1' as text) < cast('0' as text) as int)); + test_tablesample tablesample bernoulli (cast(cast('1' as text) < cast('0' as text) as int)); select * from (values (0), (100)) as v (pct), - lateral ( - select - COUNT(*) - from - tenk1 tablesample bernoulli (pct) - ) - as ss; + lateral (select count(*) from tenk1 tablesample bernoulli (pct)) as ss; select * from (values (0), (100)) as v (pct), - lateral ( - select - COUNT(*) - from - tenk1 tablesample system (pct) - ) - as ss; + lateral (select count(*) from tenk1 tablesample system (pct)) as ss; select pct, - COUNT(unique1) + count(unique1) from (values (0), (100)) as v (pct), - lateral ( - select * from tenk1 tablesample bernoulli (pct) - ) - as ss + lateral (select * from tenk1 tablesample bernoulli (pct)) as ss group by pct; select pct, - COUNT(unique1) + count(unique1) from (values (0), (100)) as v (pct), - lateral ( - select * from tenk1 tablesample bernoulli (pct) - ) - as ss + lateral (select * from tenk1 tablesample bernoulli (pct)) as ss group by pct; select pct, - COUNT(unique1) + count(unique1) from (values (0), (100)) as v (pct), - lateral ( - select * from tenk1 tablesample system (pct) - ) - as ss + lateral (select * from tenk1 tablesample system (pct)) as ss group by pct; select id from test_tablesample tablesample foobar (1); @@ -178,17 +139,14 @@ select id from test_tablesample_v1 tablesample bernoulli (1); insert into test_tablesample_v1 values (1); -with -query_select as (select * from test_tablesample) +with query_select as (select * from test_tablesample) select * from - query_select - tablesample bernoulli (5.5) - repeatable (1); + query_select tablesample bernoulli (5.5) repeatable (1); create table parted_sample (a int) -partition by LIST(a); +partition by list(a); create table parted_sample_1 partition of parted_sample for values in (1); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablesample_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablesample_80.snap index 801941fef..e4c5904a6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablesample_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablesample_80.snap @@ -10,11 +10,7 @@ create table test_tablesample ( with (fillfactor = 10); insert into test_tablesample -select - i, - repeat(cast(i as text), 200) -from - generate_series(0, 9) as s (i); +select i, repeat(cast(i as text), 200) from generate_series(0, 9) as s (i); select t.id from test_tablesample as t tablesample system (50) repeatable (0); @@ -26,41 +22,26 @@ select id from test_tablesample tablesample bernoulli (50) repeatable (0); select id from test_tablesample tablesample bernoulli (5.5) repeatable (0); -select COUNT(*) from test_tablesample tablesample system (100); +select count(*) from test_tablesample tablesample system (100); select - COUNT(*) + count(*) from - test_tablesample - tablesample system (100) - repeatable (1 + 2); + test_tablesample tablesample system (100) repeatable (1 + 2); -select COUNT(*) from test_tablesample tablesample system (100) repeatable (0.4); +select count(*) from test_tablesample tablesample system (100) repeatable (0.4); create view test_tablesample_v1 -as select - id -from - test_tablesample - tablesample system (10 * 2) - repeatable (2); +as select id from test_tablesample tablesample system (10 * 2) repeatable (2); create view test_tablesample_v2 -as select - id -from - test_tablesample tablesample system (99); +as select id from test_tablesample tablesample system (99); begin; -declare "tablesample_cur" scroll +declare tablesample_cur scroll cursor -for select - id -from - test_tablesample - tablesample system (50) - repeatable (0);; +for select id from test_tablesample tablesample system (50) repeatable (0);; fetch absolute 1 from tablesample_cur; @@ -96,83 +77,52 @@ select id from test_tablesample tablesample system (50) repeatable (2); select * from test_tablesample_v1; -select COUNT(*) from person tablesample bernoulli (100); +select count(*) from person tablesample bernoulli (100); -select COUNT(*) from person tablesample bernoulli (100); +select count(*) from person tablesample bernoulli (100); -select COUNT(*) from person; +select count(*) from person; select - COUNT(*) + count(*) from test_tablesample - tablesample bernoulli (cast(cast('1' as text) < cast('0' as text) - as int)); + tablesample bernoulli (cast(cast('1' as text) < cast('0' as text) as int)); select * from (values (0), (100)) as v (pct), - lateral ( - select - COUNT(*) - from - tenk1 tablesample bernoulli (pct) - ) - as ss; + lateral (select count(*) from tenk1 tablesample bernoulli (pct)) as ss; select * from (values (0), (100)) as v (pct), - lateral ( - select - COUNT(*) - from - tenk1 tablesample system (pct) - ) - as ss; + lateral (select count(*) from tenk1 tablesample system (pct)) as ss; select pct, - COUNT(unique1) + count(unique1) from (values (0), (100)) as v (pct), - lateral ( - select - * - from - tenk1 tablesample bernoulli (pct) - ) - as ss + lateral (select * from tenk1 tablesample bernoulli (pct)) as ss group by pct; select pct, - COUNT(unique1) + count(unique1) from (values (0), (100)) as v (pct), - lateral ( - select - * - from - tenk1 tablesample bernoulli (pct) - ) - as ss + lateral (select * from tenk1 tablesample bernoulli (pct)) as ss group by pct; select pct, - COUNT(unique1) + count(unique1) from (values (0), (100)) as v (pct), - lateral ( - select - * - from - tenk1 tablesample system (pct) - ) - as ss + lateral (select * from tenk1 tablesample system (pct)) as ss group by pct; select id from test_tablesample tablesample foobar (1); @@ -193,20 +143,14 @@ select id from test_tablesample_v1 tablesample bernoulli (1); insert into test_tablesample_v1 values (1); -with -query_select -as ( - select * from test_tablesample -) +with query_select as (select * from test_tablesample) select * from - query_select - tablesample bernoulli (5.5) - repeatable (1); + query_select tablesample bernoulli (5.5) repeatable (1); create table parted_sample (a int) -partition by LIST(a); +partition by list(a); create table parted_sample_1 partition of parted_sample for values in (1); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablespace_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablespace_100.snap index 611a42a24..f62c3573b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablespace_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablespace_100.snap @@ -18,11 +18,7 @@ select spcoptions from pg_tablespace where spcname = 'regress_tblspacewith'; drop tablespace regress_tblspacewith; select - regexp_replace( - pg_tablespace_location(oid), - '(pg_tblspc)/(\d+)', - '\1/NNN' - ) + regexp_replace(pg_tablespace_location(oid), '(pg_tblspc)/(\d+)', '\1/NNN') from pg_tablespace where @@ -36,25 +32,25 @@ alter tablespace regress_tblspace reset (random_page_cost = 2.0); alter tablespace regress_tblspace reset (random_page_cost, effective_io_concurrency); -reindex (TABLESPACE regress_tblspace) table pg_am; +reindex (tablespace regress_tblspace) table pg_am; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table pg_am; +reindex (tablespace regress_tblspace, concurrently) table pg_am; -reindex (TABLESPACE regress_tblspace) table pg_authid; +reindex (tablespace regress_tblspace) table pg_authid; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table pg_authid; +reindex (tablespace regress_tblspace, concurrently) table pg_authid; -reindex (TABLESPACE regress_tblspace) index pg_toast.pg_toast_1262_index; +reindex (tablespace regress_tblspace) index pg_toast.pg_toast_1262_index; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) index pg_toast.pg_toast_1262_index; +reindex (tablespace regress_tblspace, concurrently) index pg_toast.pg_toast_1262_index; -reindex (TABLESPACE regress_tblspace) table pg_toast.pg_toast_1262; +reindex (tablespace regress_tblspace) table pg_toast.pg_toast_1262; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table pg_toast.pg_toast_1262; +reindex (tablespace regress_tblspace, concurrently) table pg_toast.pg_toast_1262; -reindex (TABLESPACE pg_global) table pg_authid; +reindex (tablespace pg_global) table pg_authid; -reindex (TABLESPACE pg_global, CONCURRENTLY) table pg_authid; +reindex (tablespace pg_global, concurrently) table pg_authid; create table regress_tblspace_test_tbl ( num1 bigint, @@ -63,24 +59,19 @@ create table regress_tblspace_test_tbl ( ); insert into regress_tblspace_test_tbl (num1, num2, t) -select - round(random() * 100), - random(), - 'text' -from - generate_series(1, 10) as s (i); +select round(random() * 100), random(), 'text' from generate_series(1, 10) as s (i); -create index "regress_tblspace_test_tbl_idx" on regress_tblspace_test_tbl using btree (num1); +create index regress_tblspace_test_tbl_idx on regress_tblspace_test_tbl using btree (num1); -reindex (TABLESPACE pg_global) index regress_tblspace_test_tbl_idx; +reindex (tablespace pg_global) index regress_tblspace_test_tbl_idx; -reindex (TABLESPACE pg_global, CONCURRENTLY) index regress_tblspace_test_tbl_idx; +reindex (tablespace pg_global, concurrently) index regress_tblspace_test_tbl_idx; begin; -reindex (TABLESPACE regress_tblspace) index regress_tblspace_test_tbl_idx; +reindex (tablespace regress_tblspace) index regress_tblspace_test_tbl_idx; -reindex (TABLESPACE regress_tblspace) table regress_tblspace_test_tbl; +reindex (tablespace regress_tblspace) table regress_tblspace_test_tbl; rollback; @@ -90,8 +81,7 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace'; + c.reltablespace = s.oid and s.spcname = 'regress_tblspace'; select relfilenode as main_filenode from pg_class where relname = 'regress_tblspace_test_tbl_idx'; @@ -108,11 +98,10 @@ where pg_class as c, pg_index as i where - i.indrelid = c.reltoastrelid and - c.relname = 'regress_tblspace_test_tbl' + i.indrelid = c.reltoastrelid and c.relname = 'regress_tblspace_test_tbl' ); -reindex (TABLESPACE regress_tblspace) table regress_tblspace_test_tbl; +reindex (tablespace regress_tblspace) table regress_tblspace_test_tbl; select c.relname @@ -120,8 +109,7 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace' + c.reltablespace = s.oid and s.spcname = 'regress_tblspace' order by c.relname; alter table regress_tblspace_test_tbl @@ -136,8 +124,7 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace' + c.reltablespace = s.oid and s.spcname = 'regress_tblspace' order by c.relname; alter index regress_tblspace_test_tbl_idx @@ -149,11 +136,10 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace' + c.reltablespace = s.oid and s.spcname = 'regress_tblspace' order by c.relname; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table regress_tblspace_test_tbl; +reindex (tablespace regress_tblspace, concurrently) table regress_tblspace_test_tbl; select c.relname @@ -161,8 +147,7 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace' + c.reltablespace = s.oid and s.spcname = 'regress_tblspace' order by c.relname; select @@ -185,8 +170,7 @@ where pg_class as c, pg_index as i where - i.indrelid = c.reltoastrelid and - c.relname = 'regress_tblspace_test_tbl' + i.indrelid = c.reltoastrelid and c.relname = 'regress_tblspace_test_tbl' ); drop table regress_tblspace_test_tbl; @@ -200,7 +184,7 @@ partition by range(c1); create table tbspace_reindex_part_0 partition of tbspace_reindex_part for values from (0) to (10) -partition by LIST(c2); +partition by list(c2); create table tbspace_reindex_part_0_1 partition of tbspace_reindex_part_0 for values in (1); @@ -209,29 +193,29 @@ create table tbspace_reindex_part_0_2 partition of tbspace_reindex_part_0 for va create table tbspace_reindex_part_10 partition of tbspace_reindex_part for values from (10) to (20) -partition by LIST(c2); +partition by list(c2); -create index "tbspace_reindex_part_index" on only tbspace_reindex_part using btree (c1); +create index tbspace_reindex_part_index on only tbspace_reindex_part using btree (c1); -create index "tbspace_reindex_part_index_0" on only tbspace_reindex_part_0 using btree (c1); +create index tbspace_reindex_part_index_0 on only tbspace_reindex_part_0 using btree (c1); alter index tbspace_reindex_part_index attach partition tbspace_reindex_part_index_0; -create index "tbspace_reindex_part_index_10" on only tbspace_reindex_part_10 using btree (c1); +create index tbspace_reindex_part_index_10 on only tbspace_reindex_part_10 using btree (c1); alter index tbspace_reindex_part_index attach partition tbspace_reindex_part_index_10; -create index "tbspace_reindex_part_index_0_1" on only tbspace_reindex_part_0_1 using btree (c1); +create index tbspace_reindex_part_index_0_1 on only tbspace_reindex_part_0_1 using btree (c1); alter index tbspace_reindex_part_index_0 attach partition tbspace_reindex_part_index_0_1; -create index "tbspace_reindex_part_index_0_2" on only tbspace_reindex_part_0_2 using btree (c1); +create index tbspace_reindex_part_index_0_2 on only tbspace_reindex_part_0_2 using btree (c1); alter index tbspace_reindex_part_index_0 attach partition @@ -258,32 +242,27 @@ as where relname ~ 'tbspace_reindex_part_index'; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table tbspace_reindex_part; +reindex (tablespace regress_tblspace, concurrently) table tbspace_reindex_part; select b.relname, case - when a.relfilenode = b.relfilenode - then 'relfilenode is unchanged' + when a.relfilenode = b.relfilenode then 'relfilenode is unchanged' else 'relfilenode has changed' end as filenode, case - when a.reltablespace = b.reltablespace - then 'reltablespace is unchanged' + when a.reltablespace = b.reltablespace then 'reltablespace is unchanged' else 'reltablespace has changed' end as tbspace from - reindex_temp_before as b - inner join - pg_class as a - on b.relname = a.relname + reindex_temp_before as b inner join pg_class as a on b.relname = a.relname order by 1; drop table tbspace_reindex_part; -create schema "testschema"; +create schema testschema; create table testschema.foo (i int) tablespace regress_tblspace; @@ -322,16 +301,9 @@ from pg_catalog.pg_tablespace as t, pg_catalog.pg_class as c where - c.reltablespace = t.oid and - c.relname = 'asexecute'; - -create index "foo_idx" -on testschema.foo -using btree -( - i -) -tablespace regress_tblspace; + c.reltablespace = t.oid and c.relname = 'asexecute'; + +create index foo_idx on testschema.foo using btree (i) tablespace regress_tblspace; select relname, @@ -343,7 +315,7 @@ where c.reltablespace = t.oid and c.relname = 'foo_idx'; create table testschema.part (a int) -partition by LIST(a); +partition by list(a); set default_tablespace = pg_global; @@ -371,7 +343,7 @@ create table testschema.part_4 partition of testschema.part for values in (4) ta create table testschema.part_56 partition of testschema.part for values in (5, 6) -partition by LIST(a); +partition by list(a); alter table testschema.part set tablespace pg_default; @@ -379,12 +351,12 @@ alter table testschema.part create table testschema.part_78 partition of testschema.part for values in (7, 8) -partition by LIST(a); +partition by list(a); create table testschema.part_910 partition of testschema.part for values in (9, 10) -partition by LIST(a) +partition by list(a) tablespace regress_tblspace; reset default_tablespace; @@ -392,22 +364,18 @@ reset default_tablespace; create table testschema.part_78 partition of testschema.part for values in (7, 8) -partition by LIST(a); +partition by list(a); select relname, spcname from - pg_catalog.pg_class as c - inner join - pg_catalog.pg_namespace as n - on c.relnamespace = n.oid + pg_catalog.pg_class as c inner join pg_catalog.pg_namespace as n on c.relnamespace = n.oid left outer join pg_catalog.pg_tablespace as t on c.reltablespace = t.oid where - c.relname like 'part%' and - n.nspname = 'testschema' + c.relname like 'part%' and n.nspname = 'testschema' order by relname; reset default_tablespace; @@ -415,17 +383,11 @@ reset default_tablespace; drop table testschema.part; create table testschema.part (a int) -partition by LIST(a); +partition by list(a); create table testschema.part1 partition of testschema.part for values in (1); -create index "part_a_idx" -on testschema.part -using btree -( - a -) -tablespace regress_tblspace; +create index part_a_idx on testschema.part using btree (a) tablespace regress_tblspace; create table testschema.part2 partition of testschema.part for values in (2); @@ -436,34 +398,33 @@ from pg_catalog.pg_tablespace as t, pg_catalog.pg_class as c where - c.reltablespace = t.oid and - c.relname like 'part%_idx' + c.reltablespace = t.oid and c.relname like 'part%_idx' order by relname; create table testschema.dflt (a int primary key) -partition by LIST(a) +partition by list(a) tablespace pg_default; -create table testschema.dflt (a int primary key using index tablespace "pg_default") -partition by LIST(a); +create table testschema.dflt (a int primary key using index tablespace pg_default) +partition by list(a); set default_tablespace = pg_default; create table testschema.dflt (a int primary key) -partition by LIST(a) +partition by list(a) tablespace regress_tblspace; -create table testschema.dflt (a int primary key using index tablespace "regress_tblspace") -partition by LIST(a); +create table testschema.dflt (a int primary key using index tablespace regress_tblspace) +partition by list(a); -create table testschema.dflt (a int primary key using index tablespace "regress_tblspace") -partition by LIST(a) +create table testschema.dflt (a int primary key using index tablespace regress_tblspace) +partition by list(a) tablespace regress_tblspace; set default_tablespace = ''; create table testschema.dflt2 (a int primary key) -partition by LIST(a); +partition by list(a); drop table testschema.dflt, testschema.dflt2; @@ -471,22 +432,16 @@ create table testschema.test_default_tab (id bigint) tablespace regress_tblspace insert into testschema.test_default_tab values (1); -create index "test_index1" on testschema.test_default_tab using btree (id); +create index test_index1 on testschema.test_default_tab using btree (id); -create index "test_index2" -on testschema.test_default_tab -using btree -( - id -) +create index test_index2 on testschema.test_default_tab using btree (id) tablespace regress_tblspace; alter table testschema.test_default_tab - add constraint "test_index3" primary key (id); + add constraint test_index3 primary key (id); alter table testschema.test_default_tab - add constraint "test_index4" unique (id) - using index tablespace "regress_tblspace"; + add constraint test_index4 unique (id) using index tablespace regress_tblspace; set default_tablespace = regress_tblspace; @@ -514,7 +469,7 @@ create table testschema.test_default_tab_p ( id bigint, val bigint ) -partition by LIST(id) +partition by list(id) tablespace regress_tblspace; create table testschema.test_default_tab_p1 @@ -523,22 +478,16 @@ for values in (1); insert into testschema.test_default_tab_p values (1); -create index "test_index1" on testschema.test_default_tab_p using btree (val); +create index test_index1 on testschema.test_default_tab_p using btree (val); -create index "test_index2" -on testschema.test_default_tab_p -using btree -( - val -) +create index test_index2 on testschema.test_default_tab_p using btree (val) tablespace regress_tblspace; alter table testschema.test_default_tab_p - add constraint "test_index3" primary key (id); + add constraint test_index3 primary key (id); alter table testschema.test_default_tab_p - add constraint "test_index4" unique (id) - using index tablespace "regress_tblspace"; + add constraint test_index4 unique (id) using index tablespace regress_tblspace; set default_tablespace = regress_tblspace; @@ -569,12 +518,12 @@ insert into testschema.test_tab values (1); set default_tablespace = regress_tblspace; alter table testschema.test_tab - add constraint "test_tab_unique" unique (id); + add constraint test_tab_unique unique (id); set default_tablespace = ''; alter table testschema.test_tab - add constraint "test_tab_pkey" primary key (id); + add constraint test_tab_pkey primary key (id); select * from testschema.test_tab; @@ -589,13 +538,13 @@ create table testschema.test_tab ( set default_tablespace = regress_tblspace; alter table testschema.test_tab - add constraint "test_tab_unique" unique (a); + add constraint test_tab_unique unique (a); -create index "test_tab_a_idx" on testschema.test_tab using btree (a); +create index test_tab_a_idx on testschema.test_tab using btree (a); set default_tablespace = ''; -create index "test_tab_b_idx" on testschema.test_tab using btree (b); +create index test_tab_b_idx on testschema.test_tab using btree (b); alter table testschema.test_tab alter column b type bigint, @@ -605,7 +554,7 @@ drop table testschema.test_tab; create table testschema.atable as values (1), (2); -create unique index "anindex" on testschema.atable using btree (column1); +create unique index anindex on testschema.atable using btree (column1); alter table testschema.atable set tablespace regress_tblspace; @@ -626,7 +575,7 @@ insert into testschema.atable values (3); insert into testschema.atable values (1); -select COUNT(*) from testschema.atable; +select count(*) from testschema.atable; create materialized view testschema.amv as select * from testschema.atable; @@ -635,7 +584,7 @@ alter materialized view testschema.amv refresh materialized view testschema.amv; -select COUNT(*) from testschema.amv; +select count(*) from testschema.amv; create tablespace regress_badspace location '/no/such/location'; @@ -658,19 +607,13 @@ create role regress_tablespace_user1 login; create role regress_tablespace_user2 login; -grant USAGE on schema testschema to regress_tablespace_user2; +grant usage on schema testschema to regress_tablespace_user2; alter tablespace regress_tblspace owner to regress_tablespace_user1; create table testschema.tablespace_acl (c int); -create index "k" -on testschema.tablespace_acl -using btree -( - c -) -tablespace regress_tblspace; +create index k on testschema.tablespace_acl using btree (c) tablespace regress_tblspace; alter table testschema.tablespace_acl owner to regress_tablespace_user2; @@ -682,9 +625,9 @@ create table tablespace_table (i int) tablespace regress_tblspace; alter table testschema.tablespace_acl alter column c type bigint; -reindex (TABLESPACE regress_tblspace) table tablespace_table; +reindex (tablespace regress_tblspace) table tablespace_table; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table tablespace_table; +reindex (tablespace regress_tblspace, concurrently) table tablespace_table; reset role; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablespace_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablespace_80.snap index fb5aa49b8..49c10a362 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablespace_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tablespace_80.snap @@ -9,60 +9,56 @@ create tablespace regress_tblspace location ''; set allow_in_place_tablespaces = 'true'; -create tablespace regress_tblspacewith location '' with (some_nonexistent_parameter = 'true'); +create tablespace regress_tblspacewith location '' with ( + some_nonexistent_parameter = 'true' +); -create tablespace regress_tblspacewith location '' with (random_page_cost = 3.0); +create tablespace regress_tblspacewith location '' with ( + random_page_cost = 3.0 +); select spcoptions from pg_tablespace where spcname = 'regress_tblspacewith'; drop tablespace regress_tblspacewith; select - regexp_replace( - pg_tablespace_location(oid), - '(pg_tblspc)/(\d+)', - '\1/NNN' - ) + regexp_replace(pg_tablespace_location(oid), '(pg_tblspc)/(\d+)', '\1/NNN') from pg_tablespace where spcname = 'regress_tblspace'; alter tablespace regress_tblspace -set (random_page_cost = 1.0, -seq_page_cost = 1.1); +set (random_page_cost = 1.0, seq_page_cost = 1.1); alter tablespace regress_tblspace set (some_nonexistent_parameter = 'true'); alter tablespace regress_tblspace reset (random_page_cost = 2.0); alter tablespace regress_tblspace -reset (random_page_cost, -effective_io_concurrency); +reset (random_page_cost, effective_io_concurrency); -reindex (TABLESPACE regress_tblspace) table pg_am; +reindex (tablespace regress_tblspace) table pg_am; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table pg_am; +reindex (tablespace regress_tblspace, concurrently) table pg_am; -reindex (TABLESPACE regress_tblspace) table pg_authid; +reindex (tablespace regress_tblspace) table pg_authid; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table pg_authid; +reindex (tablespace regress_tblspace, concurrently) table pg_authid; -reindex (TABLESPACE regress_tblspace) index pg_toast.pg_toast_1262_index; +reindex (tablespace regress_tblspace) index pg_toast.pg_toast_1262_index; -reindex (TABLESPACE regress_tblspace, -CONCURRENTLY) +reindex (tablespace regress_tblspace, concurrently) index pg_toast.pg_toast_1262_index; -reindex (TABLESPACE regress_tblspace) table pg_toast.pg_toast_1262; +reindex (tablespace regress_tblspace) table pg_toast.pg_toast_1262; -reindex (TABLESPACE regress_tblspace, -CONCURRENTLY) +reindex (tablespace regress_tblspace, concurrently) table pg_toast.pg_toast_1262; -reindex (TABLESPACE pg_global) table pg_authid; +reindex (tablespace pg_global) table pg_authid; -reindex (TABLESPACE pg_global, CONCURRENTLY) table pg_authid; +reindex (tablespace pg_global, concurrently) table pg_authid; create table regress_tblspace_test_tbl ( num1 bigint, @@ -78,24 +74,20 @@ select from generate_series(1, 10) as s (i); -create index "regress_tblspace_test_tbl_idx" -on regress_tblspace_test_tbl -using btree -( - num1 -); +create index regress_tblspace_test_tbl_idx + on regress_tblspace_test_tbl + using btree (num1); -reindex (TABLESPACE pg_global) index regress_tblspace_test_tbl_idx; +reindex (tablespace pg_global) index regress_tblspace_test_tbl_idx; -reindex (TABLESPACE pg_global, -CONCURRENTLY) +reindex (tablespace pg_global, concurrently) index regress_tblspace_test_tbl_idx; begin; -reindex (TABLESPACE regress_tblspace) index regress_tblspace_test_tbl_idx; +reindex (tablespace regress_tblspace) index regress_tblspace_test_tbl_idx; -reindex (TABLESPACE regress_tblspace) table regress_tblspace_test_tbl; +reindex (tablespace regress_tblspace) table regress_tblspace_test_tbl; rollback; @@ -105,16 +97,14 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace'; + c.reltablespace = s.oid and s.spcname = 'regress_tblspace'; select relfilenode as main_filenode from pg_class where - relname = - 'regress_tblspace_test_tbl_idx'; + relname = 'regress_tblspace_test_tbl_idx'; select relfilenode as toast_filenode @@ -129,11 +119,10 @@ where pg_class as c, pg_index as i where - i.indrelid = c.reltoastrelid and - c.relname = 'regress_tblspace_test_tbl' + i.indrelid = c.reltoastrelid and c.relname = 'regress_tblspace_test_tbl' ); -reindex (TABLESPACE regress_tblspace) table regress_tblspace_test_tbl; +reindex (tablespace regress_tblspace) table regress_tblspace_test_tbl; select c.relname @@ -141,8 +130,7 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace' + c.reltablespace = s.oid and s.spcname = 'regress_tblspace' order by c.relname; alter table regress_tblspace_test_tbl @@ -157,8 +145,7 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace' + c.reltablespace = s.oid and s.spcname = 'regress_tblspace' order by c.relname; alter index regress_tblspace_test_tbl_idx @@ -170,12 +157,10 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace' + c.reltablespace = s.oid and s.spcname = 'regress_tblspace' order by c.relname; -reindex (TABLESPACE regress_tblspace, -CONCURRENTLY) +reindex (tablespace regress_tblspace, concurrently) table regress_tblspace_test_tbl; select @@ -184,22 +169,18 @@ from pg_class as c, pg_tablespace as s where - c.reltablespace = s.oid and - s.spcname = 'regress_tblspace' + c.reltablespace = s.oid and s.spcname = 'regress_tblspace' order by c.relname; select - relfilenode = 'main_filenode' - as main_same + relfilenode = 'main_filenode' as main_same from pg_class where - relname = - 'regress_tblspace_test_tbl_idx'; + relname = 'regress_tblspace_test_tbl_idx'; select - relfilenode = 'toast_filenode' - as toast_same + relfilenode = 'toast_filenode' as toast_same from pg_class where @@ -211,8 +192,7 @@ where pg_class as c, pg_index as i where - i.indrelid = c.reltoastrelid and - c.relname = 'regress_tblspace_test_tbl' + i.indrelid = c.reltoastrelid and c.relname = 'regress_tblspace_test_tbl' ); drop table regress_tblspace_test_tbl; @@ -226,7 +206,7 @@ partition by range(c1); create table tbspace_reindex_part_0 partition of tbspace_reindex_part for values from (0) to (10) -partition by LIST(c2); +partition by list(c2); create table tbspace_reindex_part_0_1 partition of tbspace_reindex_part_0 @@ -239,54 +219,39 @@ for values in (2); create table tbspace_reindex_part_10 partition of tbspace_reindex_part for values from (10) to (20) -partition by LIST(c2); +partition by list(c2); -create index "tbspace_reindex_part_index" -on only tbspace_reindex_part -using btree -( - c1 -); +create index tbspace_reindex_part_index + on only tbspace_reindex_part + using btree (c1); -create index "tbspace_reindex_part_index_0" -on only tbspace_reindex_part_0 -using btree -( - c1 -); +create index tbspace_reindex_part_index_0 + on only tbspace_reindex_part_0 + using btree (c1); alter index tbspace_reindex_part_index attach partition tbspace_reindex_part_index_0; -create index "tbspace_reindex_part_index_10" -on only tbspace_reindex_part_10 -using btree -( - c1 -); +create index tbspace_reindex_part_index_10 + on only tbspace_reindex_part_10 + using btree (c1); alter index tbspace_reindex_part_index attach partition tbspace_reindex_part_index_10; -create index "tbspace_reindex_part_index_0_1" -on only tbspace_reindex_part_0_1 -using btree -( - c1 -); +create index tbspace_reindex_part_index_0_1 + on only tbspace_reindex_part_0_1 + using btree (c1); alter index tbspace_reindex_part_index_0 attach partition tbspace_reindex_part_index_0_1; -create index "tbspace_reindex_part_index_0_2" -on only tbspace_reindex_part_0_2 -using btree -( - c1 -); +create index tbspace_reindex_part_index_0_2 + on only tbspace_reindex_part_0_2 + using btree (c1); alter index tbspace_reindex_part_index_0 attach partition @@ -297,9 +262,7 @@ select parentrelid, level from - pg_partition_tree( - 'tbspace_reindex_part_index' - ) + pg_partition_tree('tbspace_reindex_part_index') order by relid, level; @@ -315,32 +278,27 @@ as where relname ~ 'tbspace_reindex_part_index'; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table tbspace_reindex_part; +reindex (tablespace regress_tblspace, concurrently) table tbspace_reindex_part; select b.relname, case - when a.relfilenode = b.relfilenode - then 'relfilenode is unchanged' + when a.relfilenode = b.relfilenode then 'relfilenode is unchanged' else 'relfilenode has changed' end as filenode, case - when a.reltablespace = b.reltablespace - then 'reltablespace is unchanged' + when a.reltablespace = b.reltablespace then 'reltablespace is unchanged' else 'reltablespace has changed' end as tbspace from - reindex_temp_before as b - inner join - pg_class as a - on b.relname = a.relname + reindex_temp_before as b inner join pg_class as a on b.relname = a.relname order by 1; drop table tbspace_reindex_part; -create schema "testschema"; +create schema testschema; create table testschema.foo (i int) tablespace regress_tblspace; @@ -351,8 +309,7 @@ from pg_catalog.pg_tablespace as t, pg_catalog.pg_class as c where - c.reltablespace = t.oid and - c.relname = 'foo'; + c.reltablespace = t.oid and c.relname = 'foo'; insert into testschema.foo values (1); @@ -367,8 +324,7 @@ from pg_catalog.pg_tablespace as t, pg_catalog.pg_class as c where - c.reltablespace = t.oid and - c.relname = 'asselect'; + c.reltablespace = t.oid and c.relname = 'asselect'; prepare selectsource (int) as select $1;; @@ -384,15 +340,9 @@ from pg_catalog.pg_tablespace as t, pg_catalog.pg_class as c where - c.reltablespace = t.oid and - c.relname = 'asexecute'; - -create index "foo_idx" -on testschema.foo -using btree -( - i -) + c.reltablespace = t.oid and c.relname = 'asexecute'; + +create index foo_idx on testschema.foo using btree (i) tablespace regress_tblspace; select @@ -402,11 +352,10 @@ from pg_catalog.pg_tablespace as t, pg_catalog.pg_class as c where - c.reltablespace = t.oid and - c.relname = 'foo_idx'; + c.reltablespace = t.oid and c.relname = 'foo_idx'; create table testschema.part (a int) -partition by LIST(a); +partition by list(a); set default_tablespace = pg_global; @@ -437,7 +386,7 @@ tablespace pg_default; create table testschema.part_56 partition of testschema.part for values in (5, 6) -partition by LIST(a); +partition by list(a); alter table testschema.part set tablespace pg_default; @@ -445,12 +394,12 @@ alter table testschema.part create table testschema.part_78 partition of testschema.part for values in (7, 8) -partition by LIST(a); +partition by list(a); create table testschema.part_910 partition of testschema.part for values in (9, 10) -partition by LIST(a) +partition by list(a) tablespace regress_tblspace; reset default_tablespace; @@ -458,7 +407,7 @@ reset default_tablespace; create table testschema.part_78 partition of testschema.part for values in (7, 8) -partition by LIST(a); +partition by list(a); select relname, @@ -472,8 +421,7 @@ from pg_catalog.pg_tablespace as t on c.reltablespace = t.oid where - c.relname like 'part%' and - n.nspname = 'testschema' + c.relname like 'part%' and n.nspname = 'testschema' order by relname; reset default_tablespace; @@ -481,16 +429,11 @@ reset default_tablespace; drop table testschema.part; create table testschema.part (a int) -partition by LIST(a); +partition by list(a); create table testschema.part1 partition of testschema.part for values in (1); -create index "part_a_idx" -on testschema.part -using btree -( - a -) +create index part_a_idx on testschema.part using btree (a) tablespace regress_tblspace; create table testschema.part2 partition of testschema.part for values in (2); @@ -502,46 +445,39 @@ from pg_catalog.pg_tablespace as t, pg_catalog.pg_class as c where - c.reltablespace = t.oid and - c.relname like 'part%_idx' + c.reltablespace = t.oid and c.relname like 'part%_idx' order by relname; create table testschema.dflt (a int primary key) -partition by LIST(a) +partition by list(a) tablespace pg_default; create table testschema.dflt ( - a int - primary key - using index tablespace "pg_default" + a int primary key using index tablespace pg_default ) -partition by LIST(a); +partition by list(a); set default_tablespace = pg_default; create table testschema.dflt (a int primary key) -partition by LIST(a) +partition by list(a) tablespace regress_tblspace; create table testschema.dflt ( - a int - primary key - using index tablespace "regress_tblspace" + a int primary key using index tablespace regress_tblspace ) -partition by LIST(a); +partition by list(a); create table testschema.dflt ( - a int - primary key - using index tablespace "regress_tblspace" + a int primary key using index tablespace regress_tblspace ) -partition by LIST(a) +partition by list(a) tablespace regress_tblspace; set default_tablespace = ''; create table testschema.dflt2 (a int primary key) -partition by LIST(a); +partition by list(a); drop table testschema.dflt, testschema.dflt2; @@ -550,22 +486,17 @@ tablespace regress_tblspace; insert into testschema.test_default_tab values (1); -create index "test_index1" on testschema.test_default_tab using btree (id); +create index test_index1 on testschema.test_default_tab using btree (id); -create index "test_index2" -on testschema.test_default_tab -using btree -( - id -) +create index test_index2 on testschema.test_default_tab using btree (id) tablespace regress_tblspace; alter table testschema.test_default_tab - add constraint "test_index3" primary key (id); + add constraint test_index3 primary key (id); alter table testschema.test_default_tab - add constraint "test_index4" unique (id) - using index tablespace "regress_tblspace"; + add constraint test_index4 unique (id) + using index tablespace regress_tblspace; set default_tablespace = regress_tblspace; @@ -593,7 +524,7 @@ create table testschema.test_default_tab_p ( id bigint, val bigint ) -partition by LIST(id) +partition by list(id) tablespace regress_tblspace; create table testschema.test_default_tab_p1 @@ -602,22 +533,17 @@ for values in (1); insert into testschema.test_default_tab_p values (1); -create index "test_index1" on testschema.test_default_tab_p using btree (val); +create index test_index1 on testschema.test_default_tab_p using btree (val); -create index "test_index2" -on testschema.test_default_tab_p -using btree -( - val -) +create index test_index2 on testschema.test_default_tab_p using btree (val) tablespace regress_tblspace; alter table testschema.test_default_tab_p - add constraint "test_index3" primary key (id); + add constraint test_index3 primary key (id); alter table testschema.test_default_tab_p - add constraint "test_index4" unique (id) - using index tablespace "regress_tblspace"; + add constraint test_index4 unique (id) + using index tablespace regress_tblspace; set default_tablespace = regress_tblspace; @@ -648,12 +574,12 @@ insert into testschema.test_tab values (1); set default_tablespace = regress_tblspace; alter table testschema.test_tab - add constraint "test_tab_unique" unique (id); + add constraint test_tab_unique unique (id); set default_tablespace = ''; alter table testschema.test_tab - add constraint "test_tab_pkey" primary key (id); + add constraint test_tab_pkey primary key (id); select * from testschema.test_tab; @@ -668,13 +594,13 @@ create table testschema.test_tab ( set default_tablespace = regress_tblspace; alter table testschema.test_tab - add constraint "test_tab_unique" unique (a); + add constraint test_tab_unique unique (a); -create index "test_tab_a_idx" on testschema.test_tab using btree (a); +create index test_tab_a_idx on testschema.test_tab using btree (a); set default_tablespace = ''; -create index "test_tab_b_idx" on testschema.test_tab using btree (b); +create index test_tab_b_idx on testschema.test_tab using btree (b); alter table testschema.test_tab alter column b type bigint, @@ -684,7 +610,7 @@ drop table testschema.test_tab; create table testschema.atable as values (1), (2); -create unique index "anindex" on testschema.atable using btree (column1); +create unique index anindex on testschema.atable using btree (column1); alter table testschema.atable set tablespace regress_tblspace; @@ -705,7 +631,7 @@ insert into testschema.atable values (3); insert into testschema.atable values (1); -select COUNT(*) from testschema.atable; +select count(*) from testschema.atable; create materialized view testschema.amv as select * from testschema.atable; @@ -714,7 +640,7 @@ alter materialized view testschema.amv refresh materialized view testschema.amv; -select COUNT(*) from testschema.amv; +select count(*) from testschema.amv; create tablespace regress_badspace location '/no/such/location'; @@ -737,18 +663,13 @@ create role regress_tablespace_user1 login; create role regress_tablespace_user2 login; -grant USAGE on schema testschema to regress_tablespace_user2; +grant usage on schema testschema to regress_tablespace_user2; alter tablespace regress_tblspace owner to regress_tablespace_user1; create table testschema.tablespace_acl (c int); -create index "k" -on testschema.tablespace_acl -using btree -( - c -) +create index k on testschema.tablespace_acl using btree (c) tablespace regress_tblspace; alter table testschema.tablespace_acl @@ -761,9 +682,9 @@ create table tablespace_table (i int) tablespace regress_tblspace; alter table testschema.tablespace_acl alter column c type bigint; -reindex (TABLESPACE regress_tblspace) table tablespace_table; +reindex (tablespace regress_tblspace) table tablespace_table; -reindex (TABLESPACE regress_tblspace, CONCURRENTLY) table tablespace_table; +reindex (tablespace regress_tblspace, concurrently) table tablespace_table; reset role; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_100.snap index 1e6f21d5b..905d98210 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_100.snap @@ -4,11 +4,11 @@ input_file: crates/pgls_pretty_print/tests/data/multi/temp.sql --- create table temptest (col int); -create index "i_temptest" on temptest using btree (col); +create index i_temptest on temptest using btree (col); create temporary table temptest (tcol int); -create index "i_temptest" on temptest using btree (tcol); +create index i_temptest on temptest using btree (tcol); select * from temptest; @@ -94,16 +94,14 @@ select * from temptest; begin; -do -$do$ +do $$ begin execute format($cmd$ CREATE TEMP TABLE temptest (col text CHECK (col < %L)) ON COMMIT DROP $cmd$, (SELECT string_agg(g.i::text || ':' || random()::text, '|') FROM generate_series(1, 100) g(i))); -end -$do$; +end$$; select * from temptest; @@ -142,16 +140,12 @@ insert into whereami values ('temp'); create function public.whoami() returns text language sql -as $function$ -select 'public'::text -$function$; +as $$select 'public'::text$$; create function pg_temp.whoami() returns text language sql -as $function$ -select 'temp'::text -$function$; +as $$select 'temp'::text$$; select * from whereami; @@ -198,7 +192,7 @@ drop table temp_parted_oncommit; begin; create temporary table temp_parted_oncommit_test (a int) -partition by LIST(a) +partition by list(a) on commit drop; create temporary table temp_parted_oncommit_test2 @@ -267,18 +261,14 @@ begin; create function pg_temp.twophase_func() returns void language sql -as $function$ -select '2pc_func'::text -$function$; +as $$ select '2pc_func'::text $$; prepare transaction 'twophase_func'; create function pg_temp.twophase_func() returns void language sql -as $function$ -select '2pc_func'::text -$function$; +as $$ select '2pc_func'::text $$; begin; @@ -288,7 +278,7 @@ prepare transaction 'twophase_func'; begin; -create operator pg_temp.@@ (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4mi); +create operator pg_temp.@@ (leftarg = int4, rightarg = int4, procedure = int4mi); prepare transaction 'twophase_operator'; @@ -327,7 +317,7 @@ prepare transaction 'twophase_tab'; begin; -lock table twophase_tab in ACCESS EXCLUSIVE mode; +lock table twophase_tab in access exclusive mode; prepare transaction 'twophase_tab'; @@ -341,7 +331,7 @@ set search_path to pg_temp; begin; -select CURRENT_SCHEMA ~ 'pg_temp' as is_temp_schema; +select current_schema() ~ 'pg_temp' as is_temp_schema; prepare transaction 'twophase_search'; @@ -355,13 +345,13 @@ create temporary table test_temp ( insert into test_temp select generate_series(1, 10000) as id, repeat('a', 200), 0; -select pg_relation_size('test_temp') / cast(current_setting('block_size') as bigint) > 200; +select pg_relation_size('test_temp') / cast(current_setting('block_size') as int8) > 200; create function test_temp_pin(p_start int, p_end int) returns void language plpgsql -as $function$ -DECLARE +as $f$ + DECLARE cursorname text; query text; BEGIN @@ -374,7 +364,7 @@ DECLARE -- RAISE NOTICE '%: %', cursorname, query; END LOOP; END; -$function$; +$f$; begin; @@ -400,7 +390,7 @@ fetch next from c_3; select test_temp_pin(10, 94); -select COUNT(*), MAX(a) as max_a, MIN(a) as min_a, MAX(cnt) as max_cnt from test_temp; +select count(*), max(a) as max_a, min(a) as min_a, max(cnt) as max_cnt from test_temp; rollback; @@ -420,7 +410,7 @@ truncate test_temp; commit; -select COUNT(*), MAX(a) as max_a, MIN(a) as min_a, MAX(cnt) as max_cnt from test_temp; +select count(*), max(a) as max_a, min(a) as min_a, max(cnt) as max_cnt from test_temp; insert into test_temp (a, b, cnt) values (-1, '', 0); @@ -432,7 +422,7 @@ drop table test_temp; rollback; -select COUNT(*), MAX(a) as max_a, MIN(a) as min_a, MAX(cnt) as max_cnt from test_temp; +select count(*), max(a) as max_a, min(a) as min_a, max(cnt) as max_cnt from test_temp; update test_temp set cnt = cnt + 1 where a = -1; @@ -442,7 +432,7 @@ drop table test_temp; rollback; -select COUNT(*), MAX(a) as max_a, MIN(a) as min_a, MAX(cnt) as max_cnt from test_temp; +select count(*), max(a) as max_a, min(a) as min_a, max(cnt) as max_cnt from test_temp; update test_temp set cnt = cnt + 1 where a = -1; @@ -452,6 +442,6 @@ truncate test_temp; rollback; -select COUNT(*), MAX(a) as max_a, MIN(a) as min_a, MAX(cnt) as max_cnt from test_temp; +select count(*), max(a) as max_a, min(a) as min_a, max(cnt) as max_cnt from test_temp; drop function test_temp_pin(int, int); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_80.snap index d0c9458aa..2f210b72b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_80.snap @@ -4,11 +4,11 @@ input_file: crates/pgls_pretty_print/tests/data/multi/temp.sql --- create table temptest (col int); -create index "i_temptest" on temptest using btree (col); +create index i_temptest on temptest using btree (col); create temporary table temptest (tcol int); -create index "i_temptest" on temptest using btree (tcol); +create index i_temptest on temptest using btree (tcol); select * from temptest; @@ -94,16 +94,14 @@ select * from temptest; begin; -do -$do$ +do $$ begin execute format($cmd$ CREATE TEMP TABLE temptest (col text CHECK (col < %L)) ON COMMIT DROP $cmd$, (SELECT string_agg(g.i::text || ':' || random()::text, '|') FROM generate_series(1, 100) g(i))); -end -$do$; +end$$; select * from temptest; @@ -142,16 +140,12 @@ insert into whereami values ('temp'); create function public.whoami() returns text language sql -as $function$ -select 'public'::text -$function$; +as $$select 'public'::text$$; create function pg_temp.whoami() returns text language sql -as $function$ -select 'temp'::text -$function$; +as $$select 'temp'::text$$; select * from whereami; @@ -198,7 +192,7 @@ drop table temp_parted_oncommit; begin; create temporary table temp_parted_oncommit_test (a int) -partition by LIST(a) +partition by list(a) on commit drop; create temporary table temp_parted_oncommit_test2 @@ -273,18 +267,14 @@ begin; create function pg_temp.twophase_func() returns void language sql -as $function$ -select '2pc_func'::text -$function$; +as $$ select '2pc_func'::text $$; prepare transaction 'twophase_func'; create function pg_temp.twophase_func() returns void language sql -as $function$ -select '2pc_func'::text -$function$; +as $$ select '2pc_func'::text $$; begin; @@ -294,7 +284,11 @@ prepare transaction 'twophase_func'; begin; -create operator pg_temp.@@ (LEFTARG = int, RIGHTARG = int, PROCEDURE = int4mi); +create operator pg_temp.@@ ( + leftarg = int4, + rightarg = int4, + procedure = int4mi +); prepare transaction 'twophase_operator'; @@ -333,7 +327,7 @@ prepare transaction 'twophase_tab'; begin; -lock table twophase_tab in ACCESS EXCLUSIVE mode; +lock table twophase_tab in access exclusive mode; prepare transaction 'twophase_tab'; @@ -347,7 +341,7 @@ set search_path to pg_temp; begin; -select CURRENT_SCHEMA ~ 'pg_temp' as is_temp_schema; +select current_schema() ~ 'pg_temp' as is_temp_schema; prepare transaction 'twophase_search'; @@ -360,22 +354,17 @@ create temporary table test_temp ( ); insert into test_temp -select - generate_series(1, 10000) as id, - repeat('a', 200), - 0; +select generate_series(1, 10000) as id, repeat('a', 200), 0; select - pg_relation_size('test_temp') / - cast(current_setting('block_size') - as bigint) > + pg_relation_size('test_temp') / cast(current_setting('block_size') as int8) > 200; create function test_temp_pin(p_start int, p_end int) returns void language plpgsql -as $function$ -DECLARE +as $f$ + DECLARE cursorname text; query text; BEGIN @@ -388,7 +377,7 @@ DECLARE -- RAISE NOTICE '%: %', cursorname, query; END LOOP; END; -$function$; +$f$; begin; @@ -415,10 +404,10 @@ fetch next from c_3; select test_temp_pin(10, 94); select - COUNT(*), - MAX(a) as max_a, - MIN(a) as min_a, - MAX(cnt) as max_cnt + count(*), + max(a) as max_a, + min(a) as min_a, + max(cnt) as max_cnt from test_temp; @@ -441,10 +430,10 @@ truncate test_temp; commit; select - COUNT(*), - MAX(a) as max_a, - MIN(a) as min_a, - MAX(cnt) as max_cnt + count(*), + max(a) as max_a, + min(a) as min_a, + max(cnt) as max_cnt from test_temp; @@ -459,10 +448,10 @@ drop table test_temp; rollback; select - COUNT(*), - MAX(a) as max_a, - MIN(a) as min_a, - MAX(cnt) as max_cnt + count(*), + max(a) as max_a, + min(a) as min_a, + max(cnt) as max_cnt from test_temp; @@ -475,10 +464,10 @@ drop table test_temp; rollback; select - COUNT(*), - MAX(a) as max_a, - MIN(a) as min_a, - MAX(cnt) as max_cnt + count(*), + max(a) as max_a, + min(a) as min_a, + max(cnt) as max_cnt from test_temp; @@ -491,10 +480,10 @@ truncate test_temp; rollback; select - COUNT(*), - MAX(a) as max_a, - MIN(a) as min_a, - MAX(cnt) as max_cnt + count(*), + max(a) as max_a, + min(a) as min_a, + max(cnt) as max_cnt from test_temp; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__test_setup_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__test_setup_100.snap index e17220c4d..13598d332 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__test_setup_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__test_setup_100.snap @@ -16,39 +16,29 @@ insert into char_tbl (f1) values ('a'), ('ab'), ('abcd'), ('abcd '); vacuum char_tbl; -create table float8_tbl (f1 double precision); +create table float8_tbl (f1 float8); insert into float8_tbl (f1) -values - ('0.0'), - ('-34.84'), - ('-1004.30'), - ('-1.2345678901234e+200'), - ('-1.2345678901234e-200'); +values ('0.0'), ('-34.84'), ('-1004.30'), ('-1.2345678901234e+200'), ('-1.2345678901234e-200'); vacuum float8_tbl; -create table int2_tbl (f1 smallint); +create table int2_tbl (f1 int2); insert into int2_tbl (f1) values ('0 '), (' 1234 '), (' -1234'), ('32767'), ('-32767'); vacuum int2_tbl; -create table int4_tbl (f1 int); +create table int4_tbl (f1 int4); insert into int4_tbl (f1) -values - (' 0 '), - ('123456 '), - (' -123456'), - ('2147483647'), - ('-2147483647'); +values (' 0 '), ('123456 '), (' -123456'), ('2147483647'), ('-2147483647'); vacuum int4_tbl; create table int8_tbl ( - q1 bigint, - q2 bigint + q1 int8, + q2 int8 ); insert into int8_tbl @@ -89,19 +79,19 @@ insert into varchar_tbl (f1) values ('a'), ('ab'), ('abcd'), ('abcd '); vacuum varchar_tbl; create table onek ( - unique1 int, - unique2 int, - two int, - four int, - ten int, - twenty int, - hundred int, - thousand int, - twothousand int, - fivethous int, - tenthous int, - odd int, - even int, + unique1 int4, + unique2 int4, + two int4, + four int4, + ten int4, + twenty int4, + hundred int4, + thousand int4, + twothousand int4, + fivethous int4, + tenthous int4, + odd int4, + even int4, stringu1 name, stringu2 name, string4 name @@ -109,26 +99,26 @@ create table onek ( copy onek from 'filename'; -vacuum (ANALYZE) onek; +vacuum (analyze) onek; create table onek2 as select * from onek; -vacuum (ANALYZE) onek2; +vacuum (analyze) onek2; create table tenk1 ( - unique1 int, - unique2 int, - two int, - four int, - ten int, - twenty int, - hundred int, - thousand int, - twothousand int, - fivethous int, - tenthous int, - odd int, - even int, + unique1 int4, + unique2 int4, + two int4, + four int4, + ten int4, + twenty int4, + hundred int4, + thousand int4, + twothousand int4, + fivethous int4, + tenthous int4, + odd int4, + even int4, stringu1 name, stringu2 name, string4 name @@ -136,46 +126,45 @@ create table tenk1 ( copy tenk1 from 'filename'; -vacuum (ANALYZE) tenk1; +vacuum (analyze) tenk1; create table tenk2 as select * from tenk1; -vacuum (ANALYZE) tenk2; +vacuum (analyze) tenk2; create table person ( name text, - age int, + age int4, location point ); copy person from 'filename'; -vacuum (ANALYZE) person; +vacuum (analyze) person; create table emp ( - salary int, + salary int4, manager name ) inherits (person); copy emp from 'filename'; -vacuum (ANALYZE) emp; +vacuum (analyze) emp; -create table student (gpa double precision) +create table student (gpa float8) inherits (person); copy student from 'filename'; -vacuum (ANALYZE) student; +vacuum (analyze) student; -create table stud_emp (percent int) -inherits (emp, -student); +create table stud_emp (percent int4) +inherits (emp, student); copy stud_emp from 'filename'; -vacuum (ANALYZE) stud_emp; +vacuum (analyze) stud_emp; create table road ( name text, @@ -184,74 +173,74 @@ create table road ( copy road from 'filename'; -vacuum (ANALYZE) road; +vacuum (analyze) road; create table ihighway () inherits (road); insert into ihighway select * from only road where name ~ 'I- .*'; -vacuum (ANALYZE) ihighway; +vacuum (analyze) ihighway; create table shighway (surface text) inherits (road); insert into shighway select *, 'asphalt' from only road where name ~ 'State Hwy.*'; -vacuum (ANALYZE) shighway; +vacuum (analyze) shighway; create type stoplight as enum ('red', 'yellow', 'green'); -create type float8range as range (subtype = double precision, subtype_diff = float8mi); +create type float8range as range (subtype = float8, subtype_diff = float8mi); -create type textrange as range (subtype = text, collation = "C"); +create type textrange as range (subtype = text, "collation" = "C"); create function binary_coercible(oid, oid) -returns boolean +returns bool language c stable strict -parallel SAFE +parallel safe as 'regresslib', 'binary_coercible'; -create function part_hashint4_noop(value int, seed bigint) -returns bigint +create function part_hashint4_noop(value int4, seed int8) +returns int8 language sql immutable strict -parallel SAFE -as $function$ -select value + seed; -$function$; +parallel safe +as $$ + select value + seed; + $$; create operator class part_test_int4_ops - for type int + for type int4 using hash as operator 1 =, - function 2 part_hashint4_noop(int, bigint); + function 2 part_hashint4_noop(int4, int8); -create function part_hashtext_length(value text, seed bigint) -returns bigint +create function part_hashtext_length(value text, seed int8) +returns int8 language sql immutable strict -parallel SAFE -as $function$ -select length(coalesce(value, ''))::int8 -$function$; +parallel safe +as $$ + select length(coalesce(value, ''))::int8 + $$; create operator class part_test_text_ops for type text using hash as operator 1 =, - function 2 part_hashtext_length(text, bigint); + function 2 part_hashtext_length(text, int8); create function fipshash(bytea) returns text immutable leakproof strict -parallel SAFE +parallel safe return substr(encode(sha256($1), 'hex'), 1, 32); create function fipshash(text) @@ -259,9 +248,5 @@ returns text immutable leakproof strict -parallel SAFE -return substr( - encode(sha256(cast($1 as bytea)), 'hex'), - 1, - 32 -); +parallel safe +return substr(encode(sha256(cast($1 as bytea)), 'hex'), 1, 32); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__test_setup_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__test_setup_80.snap index 21a78420e..5346575f0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__test_setup_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__test_setup_80.snap @@ -16,7 +16,7 @@ insert into char_tbl (f1) values ('a'), ('ab'), ('abcd'), ('abcd '); vacuum char_tbl; -create table float8_tbl (f1 double precision); +create table float8_tbl (f1 float8); insert into float8_tbl (f1) values @@ -28,19 +28,14 @@ values vacuum float8_tbl; -create table int2_tbl (f1 smallint); +create table int2_tbl (f1 int2); insert into int2_tbl (f1) -values - ('0 '), - (' 1234 '), - (' -1234'), - ('32767'), - ('-32767'); +values ('0 '), (' 1234 '), (' -1234'), ('32767'), ('-32767'); vacuum int2_tbl; -create table int4_tbl (f1 int); +create table int4_tbl (f1 int4); insert into int4_tbl (f1) values @@ -53,8 +48,8 @@ values vacuum int4_tbl; create table int8_tbl ( - q1 bigint, - q2 bigint + q1 int8, + q2 int8 ); insert into int8_tbl @@ -63,9 +58,7 @@ values ('123 ', '4567890123456789'), ('4567890123456789', '123'), (+4567890123456789, '4567890123456789'), - ( - '+4567890123456789', '-4567890123456789' - ); + ('+4567890123456789', '-4567890123456789'); vacuum int8_tbl; @@ -97,19 +90,19 @@ insert into varchar_tbl (f1) values ('a'), ('ab'), ('abcd'), ('abcd '); vacuum varchar_tbl; create table onek ( - unique1 int, - unique2 int, - two int, - four int, - ten int, - twenty int, - hundred int, - thousand int, - twothousand int, - fivethous int, - tenthous int, - odd int, - even int, + unique1 int4, + unique2 int4, + two int4, + four int4, + ten int4, + twenty int4, + hundred int4, + thousand int4, + twothousand int4, + fivethous int4, + tenthous int4, + odd int4, + even int4, stringu1 name, stringu2 name, string4 name @@ -117,26 +110,26 @@ create table onek ( copy onek from 'filename'; -vacuum (ANALYZE) onek; +vacuum (analyze) onek; create table onek2 as select * from onek; -vacuum (ANALYZE) onek2; +vacuum (analyze) onek2; create table tenk1 ( - unique1 int, - unique2 int, - two int, - four int, - ten int, - twenty int, - hundred int, - thousand int, - twothousand int, - fivethous int, - tenthous int, - odd int, - even int, + unique1 int4, + unique2 int4, + two int4, + four int4, + ten int4, + twenty int4, + hundred int4, + thousand int4, + twothousand int4, + fivethous int4, + tenthous int4, + odd int4, + even int4, stringu1 name, stringu2 name, string4 name @@ -144,46 +137,45 @@ create table tenk1 ( copy tenk1 from 'filename'; -vacuum (ANALYZE) tenk1; +vacuum (analyze) tenk1; create table tenk2 as select * from tenk1; -vacuum (ANALYZE) tenk2; +vacuum (analyze) tenk2; create table person ( name text, - age int, + age int4, location point ); copy person from 'filename'; -vacuum (ANALYZE) person; +vacuum (analyze) person; create table emp ( - salary int, + salary int4, manager name ) inherits (person); copy emp from 'filename'; -vacuum (ANALYZE) emp; +vacuum (analyze) emp; -create table student (gpa double precision) +create table student (gpa float8) inherits (person); copy student from 'filename'; -vacuum (ANALYZE) student; +vacuum (analyze) student; -create table stud_emp (percent int) -inherits (emp, -student); +create table stud_emp (percent int4) +inherits (emp, student); copy stud_emp from 'filename'; -vacuum (ANALYZE) stud_emp; +vacuum (analyze) stud_emp; create table road ( name text, @@ -192,84 +184,75 @@ create table road ( copy road from 'filename'; -vacuum (ANALYZE) road; +vacuum (analyze) road; create table ihighway () inherits (road); insert into ihighway select * from only road where name ~ 'I- .*'; -vacuum (ANALYZE) ihighway; +vacuum (analyze) ihighway; create table shighway (surface text) inherits (road); insert into shighway -select - *, - 'asphalt' -from - only road -where - name ~ 'State Hwy.*'; +select *, 'asphalt' from only road where name ~ 'State Hwy.*'; -vacuum (ANALYZE) shighway; +vacuum (analyze) shighway; create type stoplight as enum ('red', 'yellow', 'green'); -create type float8range as range ( - subtype = double precision, - subtype_diff = float8mi -); +create type float8range as range (subtype = float8, subtype_diff = float8mi); -create type textrange as range (subtype = text, collation = "C"); +create type textrange as range (subtype = text, "collation" = "C"); create function binary_coercible(oid, oid) -returns boolean +returns bool language c stable strict -parallel SAFE +parallel safe as 'regresslib', 'binary_coercible'; -create function part_hashint4_noop(value int, seed bigint) -returns bigint +create function part_hashint4_noop(value int4, seed int8) +returns int8 language sql immutable strict -parallel SAFE -as $function$ -select value + seed; -$function$; +parallel safe +as $$ + select value + seed; + $$; create operator class part_test_int4_ops - for type int + for type int4 using hash as operator 1 =, - function 2 part_hashint4_noop(int, bigint); + function 2 part_hashint4_noop(int4, int8); -create function part_hashtext_length(value text, seed bigint) -returns bigint +create function part_hashtext_length(value text, seed int8) +returns int8 language sql immutable strict -parallel SAFE -as $function$ -select length(coalesce(value, ''))::int8 -$function$; +parallel safe +as $$ + select length(coalesce(value, ''))::int8 + $$; create operator class part_test_text_ops for type text using hash as operator 1 =, - function 2 part_hashtext_length(text, bigint); + function 2 part_hashtext_length(text, int8); create function fipshash(bytea) returns text immutable leakproof strict -parallel SAFE +parallel safe return substr(encode(sha256($1), 'hex'), 1, 32); create function fipshash(text) @@ -277,9 +260,5 @@ returns text immutable leakproof strict -parallel SAFE -return substr( - encode(sha256(cast($1 as bytea)), 'hex'), - 1, - 32 -); +parallel safe +return substr(encode(sha256(cast($1 as bytea)), 'hex'), 1, 32); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__text_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__text_80.snap index 620297e83..fd94d8a5d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__text_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__text_80.snap @@ -4,13 +4,11 @@ input_file: crates/pgls_pretty_print/tests/data/multi/text.sql snapshot_kind: text --- select - cast('this is a text string' as text) = - cast('this is a text string' as text) + cast('this is a text string' as text) = cast('this is a text string' as text) as "true"; select - cast('this is a text string' as text) = - cast('this is a text strin' as text) + cast('this is a text string' as text) = cast('this is a text strin' as text) as "false"; select * from text_tbl; @@ -136,10 +134,7 @@ select format('%2$s, %1$s', variadic array[1, 2]); select format('Hello', variadic cast(null as int[])); select - format( - string_agg('%s', ','), - variadic array_agg(i) - ) + format(string_agg('%s', ','), variadic array_agg(i)) from generate_series(1, 200) as g (i); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tid_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tid_100.snap index 0ca91ead2..35cf38f46 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tid_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tid_100.snap @@ -25,9 +25,9 @@ create table tid_tab (a int); insert into tid_tab values (1), (2); -select MIN(ctid) from tid_tab; +select min(ctid) from tid_tab; -select MAX(ctid) from tid_tab; +select max(ctid) from tid_tab; truncate tid_tab; @@ -51,7 +51,7 @@ select currtid2(cast('tid_seq' as text), cast('(0,1)' as tid)); drop sequence tid_seq; -create index "tid_ind" on tid_tab using btree (a); +create index tid_ind on tid_tab using btree (a); select currtid2(cast('tid_ind' as text), cast('(0,1)' as tid)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tid_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tid_80.snap index 2cca44d98..35cf38f46 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tid_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tid_80.snap @@ -7,8 +7,7 @@ select cast('(0,0)' as tid) as tid00, cast('(0,1)' as tid) as tid01, cast('(-1,0)' as tid) as tidm10, - cast('(4294967295,65535)' as tid) - as tidmax; + cast('(4294967295,65535)' as tid) as tidmax; select cast('(4294967296,1)' as tid); @@ -26,9 +25,9 @@ create table tid_tab (a int); insert into tid_tab values (1), (2); -select MIN(ctid) from tid_tab; +select min(ctid) from tid_tab; -select MAX(ctid) from tid_tab; +select max(ctid) from tid_tab; truncate tid_tab; @@ -52,7 +51,7 @@ select currtid2(cast('tid_seq' as text), cast('(0,1)' as tid)); drop sequence tid_seq; -create index "tid_ind" on tid_tab using btree (a); +create index tid_ind on tid_tab using btree (a); select currtid2(cast('tid_ind' as text), cast('(0,1)' as tid)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidrangescan_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidrangescan_100.snap index 395c034de..7dc4077cc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidrangescan_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidrangescan_100.snap @@ -22,12 +22,8 @@ insert into tidrangescan select i, repeat('x', 100) from generate_series(1, 200) delete from tidrangescan where - cast(SUBSTRING(cast(ctid as text) from ',(\d+)\)') - as int) > - 10 or - cast(SUBSTRING(cast(ctid as text) from '\((\d+),') - as int) > - 2; + cast(substring(cast(ctid as text) from ',(\d+)\)') as int) > 10 or + cast(substring(cast(ctid as text) from '\((\d+),') as int) > 2; vacuum tidrangescan; @@ -82,15 +78,7 @@ select t2.c from tidrangescan as t, - lateral ( - select - COUNT(*) as c - from - tidrangescan as t2 - where - t2.ctid <= t.ctid - ) - as t2 + lateral (select count(*) as c from tidrangescan as t2 where t2.ctid <= t.ctid) as t2 where t.ctid < '(1,0)'; @@ -99,31 +87,16 @@ select t2.c from tidrangescan as t, - lateral ( - select - COUNT(*) as c - from - tidrangescan as t2 - where - t2.ctid <= t.ctid - ) - as t2 + lateral (select count(*) as c from tidrangescan as t2 where t2.ctid <= t.ctid) as t2 where t.ctid < '(1,0)'; -explain (COSTS 'off') -declare "c" scroll -cursor -for select - ctid -from - tidrangescan -where - ctid < '(1,0)';; +explain (costs 'off') +declare c scroll cursor for select ctid from tidrangescan where ctid < '(1,0)';; begin; -declare "c" scroll cursor for select ctid from tidrangescan where ctid < '(1,0)';; +declare c scroll cursor for select ctid from tidrangescan where ctid < '(1,0)';; fetch next from c; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidrangescan_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidrangescan_80.snap index 7a3e43d70..151c93fcd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidrangescan_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidrangescan_80.snap @@ -19,22 +19,12 @@ select ctid from tidrangescan where ctid > '(9, 0)'; select ctid from tidrangescan where ctid > '(9, 0)'; insert into tidrangescan -select - i, - repeat('x', 100) -from - generate_series(1, 200) as s (i); +select i, repeat('x', 100) from generate_series(1, 200) as s (i); delete from tidrangescan where - cast(SUBSTRING(cast(ctid as text) - from ',(\d+)\)') - as int) > - 10 or - cast(SUBSTRING(cast(ctid as text) - from '\((\d+),') - as int) > - 2; + cast(substring(cast(ctid as text) from ',(\d+)\)') as int) > 10 or + cast(substring(cast(ctid as text) from '\((\d+),') as int) > 2; vacuum tidrangescan; @@ -96,12 +86,7 @@ select from tidrangescan as t, lateral ( - select - COUNT(*) as c - from - tidrangescan as t2 - where - t2.ctid <= t.ctid + select count(*) as c from tidrangescan as t2 where t2.ctid <= t.ctid ) as t2 where @@ -113,37 +98,18 @@ select from tidrangescan as t, lateral ( - select - COUNT(*) as c - from - tidrangescan as t2 - where - t2.ctid <= t.ctid + select count(*) as c from tidrangescan as t2 where t2.ctid <= t.ctid ) as t2 where t.ctid < '(1,0)'; -explain (COSTS 'off') -declare "c" scroll -cursor -for select - ctid -from - tidrangescan -where - ctid < '(1,0)';; +explain (costs 'off') +declare c scroll cursor for select ctid from tidrangescan where ctid < '(1,0)';; begin; -declare "c" scroll -cursor -for select - ctid -from - tidrangescan -where - ctid < '(1,0)';; +declare c scroll cursor for select ctid from tidrangescan where ctid < '(1,0)';; fetch next from c; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidscan_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidscan_100.snap index 9a1430862..f34471300 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidscan_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidscan_100.snap @@ -34,8 +34,7 @@ select from tidscan where - (id = 3 and ctid in ('(0,2)', '(0,3)')) or - (ctid = '(0,1)' and id = 1); + (id = 3 and ctid in ('(0,2)', '(0,3)')) or (ctid = '(0,1)' and id = 1); select ctid, @@ -43,8 +42,7 @@ select from tidscan where - (id = 3 and ctid in ('(0,2)', '(0,3)')) or - (ctid = '(0,1)' and id = 1); + (id = 3 and ctid in ('(0,2)', '(0,3)')) or (ctid = '(0,1)' and id = 1); set enable_hashjoin = off; @@ -54,10 +52,7 @@ select t2.ctid, t2.* from - tidscan as t1 - inner join - tidscan as t2 - on t1.ctid = t2.ctid + tidscan as t1 inner join tidscan as t2 on t1.ctid = t2.ctid where t1.id = 1; @@ -67,10 +62,7 @@ select t2.ctid, t2.* from - tidscan as t1 - inner join - tidscan as t2 - on t1.ctid = t2.ctid + tidscan as t1 inner join tidscan as t2 on t1.ctid = t2.ctid where t1.id = 1; @@ -80,10 +72,7 @@ select t2.ctid, t2.* from - tidscan as t1 - left outer join - tidscan as t2 - on t1.ctid = t2.ctid + tidscan as t1 left outer join tidscan as t2 on t1.ctid = t2.ctid where t1.id = 1; @@ -93,10 +82,7 @@ select t2.ctid, t2.* from - tidscan as t1 - left outer join - tidscan as t2 - on t1.ctid = t2.ctid + tidscan as t1 left outer join tidscan as t2 on t1.ctid = t2.ctid where t1.id = 1; @@ -104,15 +90,9 @@ reset enable_hashjoin; begin; -declare "c" +declare c cursor -for select - ctid, - * -from - tidscan -where - ctid = any (cast(array['(0,1)', '(0,2)'] as tid[]));; +for select ctid, * from tidscan where ctid = any (cast(array['(0,1)', '(0,2)'] as tid[]));; fetch forward all from c; @@ -124,7 +104,7 @@ rollback; begin; -declare "c" cursor for select ctid, * from tidscan;; +declare c cursor for select ctid, * from tidscan;; fetch next from c; @@ -144,15 +124,15 @@ update tidscan set id = -id where current of c returning *; rollback; -select COUNT(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; +select count(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; -select COUNT(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; +select count(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; set enable_hashjoin = off; -select COUNT(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; +select count(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; -select COUNT(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; +select count(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; reset enable_hashjoin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidscan_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidscan_80.snap index 7573f1ee4..040ceb539 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidscan_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tidscan_80.snap @@ -58,8 +58,7 @@ select from tidscan where - (id = 3 and ctid in ('(0,2)', '(0,3)')) or - (ctid = '(0,1)' and id = 1); + (id = 3 and ctid in ('(0,2)', '(0,3)')) or (ctid = '(0,1)' and id = 1); select ctid, @@ -67,8 +66,7 @@ select from tidscan where - (id = 3 and ctid in ('(0,2)', '(0,3)')) or - (ctid = '(0,1)' and id = 1); + (id = 3 and ctid in ('(0,2)', '(0,3)')) or (ctid = '(0,1)' and id = 1); set enable_hashjoin = off; @@ -78,10 +76,7 @@ select t2.ctid, t2.* from - tidscan as t1 - inner join - tidscan as t2 - on t1.ctid = t2.ctid + tidscan as t1 inner join tidscan as t2 on t1.ctid = t2.ctid where t1.id = 1; @@ -91,10 +86,7 @@ select t2.ctid, t2.* from - tidscan as t1 - inner join - tidscan as t2 - on t1.ctid = t2.ctid + tidscan as t1 inner join tidscan as t2 on t1.ctid = t2.ctid where t1.id = 1; @@ -104,10 +96,7 @@ select t2.ctid, t2.* from - tidscan as t1 - left outer join - tidscan as t2 - on t1.ctid = t2.ctid + tidscan as t1 left outer join tidscan as t2 on t1.ctid = t2.ctid where t1.id = 1; @@ -117,10 +106,7 @@ select t2.ctid, t2.* from - tidscan as t1 - left outer join - tidscan as t2 - on t1.ctid = t2.ctid + tidscan as t1 left outer join tidscan as t2 on t1.ctid = t2.ctid where t1.id = 1; @@ -128,7 +114,7 @@ reset enable_hashjoin; begin; -declare "c" +declare c cursor for select ctid, @@ -148,7 +134,7 @@ rollback; begin; -declare "c" cursor for select ctid, * from tidscan;; +declare c cursor for select ctid, * from tidscan;; fetch next from c; @@ -168,15 +154,15 @@ update tidscan set id = -id where current of c returning *; rollback; -select COUNT(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; +select count(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; -select COUNT(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; +select count(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; set enable_hashjoin = off; -select COUNT(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; +select count(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; -select COUNT(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; +select count(*) from tenk1 as t1 inner join tenk1 as t2 on t1.ctid = t2.ctid; reset enable_hashjoin; @@ -190,8 +176,7 @@ select from pg_locks where - pid = pg_backend_pid() and - mode = 'SIReadLock'; + pid = pg_backend_pid() and mode = 'SIReadLock'; rollback; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__time_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__time_100.snap index c3b296862..7772540bf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__time_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__time_100.snap @@ -65,23 +65,23 @@ select * from pg_input_error_info('15:36:39 America/New_York', 'time'); select f1 + cast('00:01' as time) as "Illegal" from time_tbl; -select EXTRACT('microsecond' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(microsecond from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('millisecond' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(millisecond from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('second' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(second from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('minute' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(minute from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('hour' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(hour from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('day' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(day from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('fortnight' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(fortnight from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('timezone' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(timezone from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('epoch' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(epoch from cast('2020-05-26 13:30:25.575401' as time)); select date_part('microsecond', cast('2020-05-26 13:30:25.575401' as time)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__time_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__time_80.snap index c3b296862..7772540bf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__time_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__time_80.snap @@ -65,23 +65,23 @@ select * from pg_input_error_info('15:36:39 America/New_York', 'time'); select f1 + cast('00:01' as time) as "Illegal" from time_tbl; -select EXTRACT('microsecond' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(microsecond from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('millisecond' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(millisecond from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('second' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(second from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('minute' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(minute from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('hour' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(hour from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('day' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(day from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('fortnight' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(fortnight from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('timezone' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(timezone from cast('2020-05-26 13:30:25.575401' as time)); -select EXTRACT('epoch' from cast('2020-05-26 13:30:25.575401' as time)); +select extract(epoch from cast('2020-05-26 13:30:25.575401' as time)); select date_part('microsecond', cast('2020-05-26 13:30:25.575401' as time)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamp_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamp_100.snap index fd10a4063..0eb8aa1b2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamp_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamp_100.snap @@ -17,11 +17,11 @@ insert into timestamp_tbl values ('tomorrow EST'); insert into timestamp_tbl values ('tomorrow zulu'); -select COUNT(*) as one from timestamp_tbl where d1 = cast('today' as timestamp); +select count(*) as one from timestamp_tbl where d1 = cast('today' as timestamp); -select COUNT(*) as three from timestamp_tbl where d1 = cast('tomorrow' as timestamp); +select count(*) as three from timestamp_tbl where d1 = cast('tomorrow' as timestamp); -select COUNT(*) as one from timestamp_tbl where d1 = cast('yesterday' as timestamp); +select count(*) as one from timestamp_tbl where d1 = cast('yesterday' as timestamp); commit; @@ -41,9 +41,9 @@ insert into timestamp_tbl values ('now'); select pg_sleep(0.1); -select COUNT(*) as two from timestamp_tbl where d1 = cast('now' as timestamp(2)); +select count(*) as two from timestamp_tbl where d1 = cast('now' as timestamp(2)); -select COUNT(d1) as three, COUNT(distinct d1) as two from timestamp_tbl; +select count(d1) as three, count(distinct d1) as two from timestamp_tbl; commit; @@ -245,12 +245,7 @@ select date_trunc('ago', cast('infinity' as timestamp)) as invalid_trunc; select str, interval, - date_trunc(str, ts) = - date_bin( - cast(interval as interval), - ts, - cast('2001-01-01' as timestamp) - ) + date_trunc(str, ts) = date_bin(cast(interval as interval), ts, cast('2001-01-01' as timestamp)) as equal from ( @@ -264,21 +259,12 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - (cast('2020-02-29 15:44:17.71393' as timestamp)) - ) - as ts (ts); + (values (cast('2020-02-29 15:44:17.71393' as timestamp))) as ts (ts); select str, interval, - date_trunc(str, ts) = - date_bin( - cast(interval as interval), - ts, - cast('2000-01-01 BC' as timestamp) - ) + date_trunc(str, ts) = date_bin(cast(interval as interval), ts, cast('2000-01-01 BC' as timestamp)) as equal from ( @@ -292,21 +278,12 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - (cast('0055-6-10 15:44:17.71393 BC' as timestamp)) - ) - as ts (ts); + (values (cast('0055-6-10 15:44:17.71393 BC' as timestamp))) as ts (ts); select str, interval, - date_trunc(str, ts) = - date_bin( - cast(interval as interval), - ts, - cast('2020-03-02' as timestamp) - ) + date_trunc(str, ts) = date_bin(cast(interval as interval), ts, cast('2020-03-02' as timestamp)) as equal from ( @@ -320,21 +297,12 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - (cast('2020-02-29 15:44:17.71393' as timestamp)) - ) - as ts (ts); + (values (cast('2020-02-29 15:44:17.71393' as timestamp))) as ts (ts); select str, interval, - date_trunc(str, ts) = - date_bin( - cast(interval as interval), - ts, - cast('0055-06-17 BC' as timestamp) - ) + date_trunc(str, ts) = date_bin(cast(interval as interval), ts, cast('0055-06-17 BC' as timestamp)) as equal from ( @@ -348,11 +316,7 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - (cast('0055-6-10 15:44:17.71393 BC' as timestamp)) - ) - as ts (ts); + (values (cast('0055-6-10 15:44:17.71393 BC' as timestamp))) as ts (ts); select interval, @@ -371,15 +335,8 @@ from ('250 microseconds') ) as intervals (interval), - ( - values - (cast('2020-02-11 15:44:17.71393' as timestamp)) - ) - as ts (ts), - ( - values (cast('2001-01-01' as timestamp)) - ) - as origin (origin); + (values (cast('2020-02-11 15:44:17.71393' as timestamp))) as ts (ts), + (values (cast('2001-01-01' as timestamp))) as origin (origin); select date_bin( @@ -449,9 +406,7 @@ select from timestamp_tbl where - d1 - between cast('1902-01-01' as timestamp) - and cast('2038-01-01' as timestamp); + d1 between cast('1902-01-01' as timestamp) and cast('2038-01-01' as timestamp); select d1 as timestamp, @@ -494,28 +449,26 @@ from select d1 as timestamp, - EXTRACT('microseconds' from d1) as microseconds, - EXTRACT('milliseconds' from d1) as milliseconds, - EXTRACT('seconds' from d1) as seconds, - round(EXTRACT('julian' from d1)) as julian, - EXTRACT('epoch' from d1) as epoch + extract(microseconds from d1) as microseconds, + extract(milliseconds from d1) as milliseconds, + extract(seconds from d1) as seconds, + round(extract(julian from d1)) as julian, + extract(epoch from d1) as epoch from timestamp_tbl; select date_part('epoch', cast('294270-01-01 00:00:00' as timestamp)); -select EXTRACT('epoch' from cast('294270-01-01 00:00:00' as timestamp)); +select extract(epoch from cast('294270-01-01 00:00:00' as timestamp)); -select EXTRACT('epoch' from cast('5000-01-01 00:00:00' as timestamp)); +select extract(epoch from cast('5000-01-01 00:00:00' as timestamp)); select - cast('294276-12-31 23:59:59' as timestamp) - - cast('1999-12-23 19:59:04.224193' as timestamp) + cast('294276-12-31 23:59:59' as timestamp) - cast('1999-12-23 19:59:04.224193' as timestamp) as ok; select - cast('294276-12-31 23:59:59' as timestamp) - - cast('1999-12-23 19:59:04.224192' as timestamp) + cast('294276-12-31 23:59:59' as timestamp) - cast('1999-12-23 19:59:04.224192' as timestamp) as overflows; select to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon') from timestamp_tbl; @@ -525,10 +478,7 @@ select to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM') from timest select to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J') from timestamp_tbl; select - to_char( - d1, - 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ' - ) + to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ') from timestamp_tbl; @@ -541,10 +491,7 @@ select to_char(d1, 'HH24--text--MI--text--SS') from timestamp_tbl; select to_char(d1, 'YYYYTH YYYYth Jth') from timestamp_tbl; 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' - ) + 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') from timestamp_tbl; @@ -553,10 +500,7 @@ select to_char(d1, 'IYYY IYY IY I IW IDDD ID') from timestamp_tbl; select to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID') from timestamp_tbl; select - to_char( - d, - 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US' - ) + to_char(d, 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US') from ( values diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamp_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamp_80.snap index 88f5b25c6..e48059fa1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamp_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamp_80.snap @@ -17,17 +17,17 @@ insert into timestamp_tbl values ('tomorrow EST'); insert into timestamp_tbl values ('tomorrow zulu'); -select COUNT(*) as one from timestamp_tbl where d1 = cast('today' as timestamp); +select count(*) as one from timestamp_tbl where d1 = cast('today' as timestamp); select - COUNT(*) as three + count(*) as three from timestamp_tbl where d1 = cast('tomorrow' as timestamp); select - COUNT(*) as one + count(*) as one from timestamp_tbl where @@ -52,13 +52,13 @@ insert into timestamp_tbl values ('now'); select pg_sleep(0.1); select - COUNT(*) as two + count(*) as two from timestamp_tbl where d1 = cast('now' as timestamp(2)); -select COUNT(d1) as three, COUNT(distinct d1) as two from timestamp_tbl; +select count(d1) as three, count(distinct d1) as two from timestamp_tbl; commit; @@ -151,10 +151,7 @@ select * from pg_input_error_info('garbage', 'timestamp'); select * from - pg_input_error_info( - '2001-01-01 00:00 Nehwon/Lankhmar', - 'timestamp' - ); + pg_input_error_info('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamp'); insert into timestamp_tbl values ('1997-06-10 18:32:01 PDT'); @@ -247,37 +244,24 @@ select d1 from timestamp_tbl where d1 <= cast('1997-01-02' as timestamp); select d1 from timestamp_tbl where d1 >= cast('1997-01-02' as timestamp); select - d1 - cast('1997-01-02' as timestamp) - as diff + d1 - cast('1997-01-02' as timestamp) as diff from timestamp_tbl where d1 between '1902-01-01' and '2038-01-01'; select - date_trunc( - 'week', - cast('2004-02-29 15:44:17.71393' - as timestamp) - ) + date_trunc('week', cast('2004-02-29 15:44:17.71393' as timestamp)) as week_trunc; select date_trunc('week', cast('infinity' as timestamp)) as inf_trunc; select - date_trunc( - 'timezone', - cast('2004-02-29 15:44:17.71393' - as timestamp) - ) + date_trunc('timezone', cast('2004-02-29 15:44:17.71393' as timestamp)) as notsupp_trunc; select - date_trunc( - 'timezone', - cast('infinity' as timestamp) - ) - as notsupp_inf_trunc; + date_trunc('timezone', cast('infinity' as timestamp)) as notsupp_inf_trunc; select date_trunc('ago', cast('infinity' as timestamp)) as invalid_trunc; @@ -285,11 +269,7 @@ select str, interval, date_trunc(str, ts) = - date_bin( - cast(interval as interval), - ts, - cast('2001-01-01' as timestamp) - ) + date_bin(cast(interval as interval), ts, cast('2001-01-01' as timestamp)) as equal from ( @@ -303,24 +283,13 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - ( - cast('2020-02-29 15:44:17.71393' - as timestamp) - ) - ) - as ts (ts); + (values (cast('2020-02-29 15:44:17.71393' as timestamp))) as ts (ts); select str, interval, date_trunc(str, ts) = - date_bin( - cast(interval as interval), - ts, - cast('2000-01-01 BC' as timestamp) - ) + date_bin(cast(interval as interval), ts, cast('2000-01-01 BC' as timestamp)) as equal from ( @@ -334,24 +303,13 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - ( - cast('0055-6-10 15:44:17.71393 BC' - as timestamp) - ) - ) - as ts (ts); + (values (cast('0055-6-10 15:44:17.71393 BC' as timestamp))) as ts (ts); select str, interval, date_trunc(str, ts) = - date_bin( - cast(interval as interval), - ts, - cast('2020-03-02' as timestamp) - ) + date_bin(cast(interval as interval), ts, cast('2020-03-02' as timestamp)) as equal from ( @@ -365,24 +323,13 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - ( - cast('2020-02-29 15:44:17.71393' - as timestamp) - ) - ) - as ts (ts); + (values (cast('2020-02-29 15:44:17.71393' as timestamp))) as ts (ts); select str, interval, date_trunc(str, ts) = - date_bin( - cast(interval as interval), - ts, - cast('0055-06-17 BC' as timestamp) - ) + date_bin(cast(interval as interval), ts, cast('0055-06-17 BC' as timestamp)) as equal from ( @@ -396,24 +343,13 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - ( - cast('0055-6-10 15:44:17.71393 BC' - as timestamp) - ) - ) - as ts (ts); + (values (cast('0055-6-10 15:44:17.71393 BC' as timestamp))) as ts (ts); select interval, ts, origin, - date_bin( - cast(interval as interval), - ts, - origin - ) + date_bin(cast(interval as interval), ts, origin) from ( values @@ -426,18 +362,8 @@ from ('250 microseconds') ) as intervals (interval), - ( - values - ( - cast('2020-02-11 15:44:17.71393' - as timestamp) - ) - ) - as ts (ts), - ( - values (cast('2001-01-01' as timestamp)) - ) - as origin (origin); + (values (cast('2020-02-11 15:44:17.71393' as timestamp))) as ts (ts), + (values (cast('2001-01-01' as timestamp))) as origin (origin); select date_bin( @@ -503,8 +429,7 @@ select ); select - d1 - cast('1997-01-02' as timestamp) - as diff + d1 - cast('1997-01-02' as timestamp) as diff from timestamp_tbl where @@ -545,8 +470,7 @@ select d1 as timestamp, date_part('decade', d1) as decade, date_part('century', d1) as century, - date_part('millennium', d1) - as millennium, + date_part('millennium', d1) as millennium, round(date_part('julian', d1)) as julian, date_part('epoch', d1) as epoch from @@ -554,58 +478,42 @@ from select d1 as timestamp, - EXTRACT('microseconds' from d1) - as microseconds, - EXTRACT('milliseconds' from d1) - as milliseconds, - EXTRACT('seconds' from d1) as seconds, - round(EXTRACT('julian' from d1)) - as julian, - EXTRACT('epoch' from d1) as epoch + extract(microseconds from d1) as microseconds, + extract(milliseconds from d1) as milliseconds, + extract(seconds from d1) as seconds, + round(extract(julian from d1)) as julian, + extract(epoch from d1) as epoch from timestamp_tbl; select date_part('epoch', cast('294270-01-01 00:00:00' as timestamp)); -select EXTRACT('epoch' from cast('294270-01-01 00:00:00' as timestamp)); +select extract(epoch from cast('294270-01-01 00:00:00' as timestamp)); -select EXTRACT('epoch' from cast('5000-01-01 00:00:00' as timestamp)); +select extract(epoch from cast('5000-01-01 00:00:00' as timestamp)); select - cast('294276-12-31 23:59:59' - as timestamp) - - cast('1999-12-23 19:59:04.224193' - as timestamp) + cast('294276-12-31 23:59:59' as timestamp) - + cast('1999-12-23 19:59:04.224193' as timestamp) as ok; select - cast('294276-12-31 23:59:59' - as timestamp) - - cast('1999-12-23 19:59:04.224192' - as timestamp) + cast('294276-12-31 23:59:59' as timestamp) - + cast('1999-12-23 19:59:04.224192' as timestamp) as overflows; select - to_char( - d1, - 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon' - ) + to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon') from timestamp_tbl; select - to_char( - d1, - 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM' - ) + to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM') from timestamp_tbl; select - to_char( - d1, - 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J' - ) + to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J') from timestamp_tbl; @@ -620,10 +528,7 @@ from select to_char(d1, 'HH HH12 HH24 MI SS SSSS') from timestamp_tbl; select - to_char( - d1, - '"HH:MI:SS is" HH:MI:SS "\"text between quote marks\""' - ) + to_char(d1, '"HH:MI:SS is" HH:MI:SS "\"text between quote marks\""') from timestamp_tbl; @@ -644,16 +549,11 @@ select to_char(d1, 'IYYY IYY IY I IW IDDD ID') from timestamp_tbl; select to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID') from timestamp_tbl; select - to_char( - d, - 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US' - ) + to_char(d, 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US') from ( values - ( - cast('2018-11-02 12:34:56' as timestamp) - ), + (cast('2018-11-02 12:34:56' as timestamp)), ('2018-11-02 12:34:56.78'), ('2018-11-02 12:34:56.78901'), ('2018-11-02 12:34:56.78901234') @@ -662,14 +562,8 @@ from select i, - to_char( - i * cast('1mon' as interval), - 'rm' - ), - to_char( - i * cast('1mon' as interval), - 'RM' - ) + to_char(i * cast('1mon' as interval), 'rm'), + to_char(i * cast('1mon' as interval), 'RM') from generate_series(-13, 13) as i; @@ -730,8 +624,7 @@ select cast('-infinity' as timestamp) - cast('-infinity' as timestamp); select cast('infinity' as timestamp) - cast('1995-08-06 12:12:12' as timestamp); select - cast('-infinity' as timestamp) - - cast('1995-08-06 12:12:12' as timestamp); + cast('-infinity' as timestamp) - cast('1995-08-06 12:12:12' as timestamp); select age(cast('infinity' as timestamp)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamptz_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamptz_100.snap index 26a7644b6..d0d35b136 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamptz_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamptz_100.snap @@ -17,32 +17,30 @@ insert into timestamptz_tbl values ('tomorrow EST'); insert into timestamptz_tbl values ('tomorrow zulu'); -select COUNT(*) as one from timestamptz_tbl where d1 = cast('today' as timestamp with time zone); +select count(*) as one from timestamptz_tbl where d1 = cast('today' as timestamp with time zone); -select COUNT(*) as one from timestamptz_tbl where d1 = cast('tomorrow' as timestamp with time zone); +select count(*) as one from timestamptz_tbl where d1 = cast('tomorrow' as timestamp with time zone); select - COUNT(*) as one + count(*) as one from timestamptz_tbl where d1 = cast('yesterday' as timestamp with time zone); select - COUNT(*) as one + count(*) as one from timestamptz_tbl where - d1 = - cast('tomorrow EST' as timestamp with time zone); + d1 = cast('tomorrow EST' as timestamp with time zone); select - COUNT(*) as one + count(*) as one from timestamptz_tbl where - d1 = - cast('tomorrow zulu' as timestamp with time zone); + d1 = cast('tomorrow zulu' as timestamp with time zone); commit; @@ -62,9 +60,9 @@ insert into timestamptz_tbl values ('now'); select pg_sleep(0.1); -select COUNT(*) as two from timestamptz_tbl where d1 = cast('now' as timestamp(2) with time zone); +select count(*) as two from timestamptz_tbl where d1 = cast('now' as timestamp(2) with time zone); -select COUNT(d1) as three, COUNT(distinct d1) as two from timestamptz_tbl; +select count(d1) as three, count(distinct d1) as two from timestamptz_tbl; commit; @@ -76,10 +74,7 @@ insert into timestamptz_tbl values ('infinity'); insert into timestamptz_tbl values ('epoch'); -select - cast('infinity' as timestamp with time zone) = - cast('+infinity' as timestamp with time zone) - as t; +select cast('infinity' as timestamptz) = cast('+infinity' as timestamptz) as t; insert into timestamptz_tbl values ('Mon Feb 10 17:32:01 1997 PST'); @@ -147,47 +142,47 @@ insert into timestamptz_tbl values ('1997.041 17:32:01 UTC'); insert into timestamptz_tbl values ('19970210 173201 America/New_York'); -select timezone('America/New_York', '19970210 173201'); +select ('19970210 173201' at time zone 'America/New_York'); insert into timestamptz_tbl values ('19970710 173201 America/New_York'); -select timezone('America/New_York', '19970710 173201'); +select ('19970710 173201' at time zone 'America/New_York'); insert into timestamptz_tbl values ('19970710 173201 America/Does_not_exist'); -select timezone('America/Does_not_exist', '19970710 173201'); +select ('19970710 173201' at time zone 'America/Does_not_exist'); -select cast('20500710 173201 Europe/Helsinki' as timestamp with time zone); +select cast('20500710 173201 Europe/Helsinki' as timestamptz); -select cast('20500110 173201 Europe/Helsinki' as timestamp with time zone); +select cast('20500110 173201 Europe/Helsinki' as timestamptz); -select cast('205000-07-10 17:32:01 Europe/Helsinki' as timestamp with time zone); +select cast('205000-07-10 17:32:01 Europe/Helsinki' as timestamptz); -select cast('205000-01-10 17:32:01 Europe/Helsinki' as timestamp with time zone); +select cast('205000-01-10 17:32:01 Europe/Helsinki' as timestamptz); -select cast('Jan 01 00:00:00 1000 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 1000 LMT' as timestamptz); -select cast('Jan 01 00:00:00 2024 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 2024 LMT' as timestamptz); set time zone 'Europe/London'; -select cast('Jan 01 00:00:00 1000 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 1000 LMT' as timestamptz); -select cast('Jan 01 00:00:00 2024 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 2024 LMT' as timestamptz); -set time zone UTC; +set time zone 'UTC'; -select cast('Jan 01 00:00:00 2024 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 2024 LMT' as timestamptz); -select cast('1912-01-01 00:00 MMT' as timestamp with time zone); +select cast('1912-01-01 00:00 MMT' as timestamptz); set time zone 'America/Montevideo'; -select cast('1912-01-01 00:00' as timestamp with time zone); +select cast('1912-01-01 00:00' as timestamptz); -select cast('1912-01-01 00:00 MMT' as timestamp with time zone); +select cast('1912-01-01 00:00 MMT' as timestamptz); -select timezone('UTC', cast('1912-01-01 00:00 MMT' as timestamp with time zone)); +select (cast('1912-01-01 00:00 MMT' as timestamptz) at time zone 'UTC'); reset timezone; @@ -269,33 +264,33 @@ insert into timestamptz_tbl values ('Feb 16 17:32:01 -0097'); insert into timestamptz_tbl values ('Feb 16 17:32:01 5097 BC'); -select cast('Wed Jul 11 10:51:14 America/New_York 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 America/New_York 2001' as timestamptz); -select cast('Wed Jul 11 10:51:14 GMT-4 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 GMT-4 2001' as timestamptz); -select cast('Wed Jul 11 10:51:14 GMT+4 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 GMT+4 2001' as timestamptz); -select cast('Wed Jul 11 10:51:14 PST-03:00 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 PST-03:00 2001' as timestamptz); -select cast('Wed Jul 11 10:51:14 PST+03:00 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 PST+03:00 2001' as timestamptz); select d1 from timestamptz_tbl; -select cast('4714-11-24 00:00:00+00 BC' as timestamp with time zone); +select cast('4714-11-24 00:00:00+00 BC' as timestamptz); -select cast('4714-11-23 16:00:00-08 BC' as timestamp with time zone); +select cast('4714-11-23 16:00:00-08 BC' as timestamptz); -select cast('Sun Nov 23 16:00:00 4714 PST BC' as timestamp with time zone); +select cast('Sun Nov 23 16:00:00 4714 PST BC' as timestamptz); -select cast('4714-11-23 23:59:59+00 BC' as timestamp with time zone); +select cast('4714-11-23 23:59:59+00 BC' as timestamptz); -select cast('294276-12-31 23:59:59+00' as timestamp with time zone); +select cast('294276-12-31 23:59:59+00' as timestamptz); -select cast('294276-12-31 15:59:59-08' as timestamp with time zone); +select cast('294276-12-31 15:59:59-08' as timestamptz); -select cast('294277-01-01 00:00:00+00' as timestamp with time zone); +select cast('294277-01-01 00:00:00+00' as timestamptz); -select cast('294277-12-31 16:00:00-08' as timestamp with time zone); +select cast('294277-12-31 16:00:00-08' as timestamptz); select d1 from timestamptz_tbl where d1 > cast('1997-01-02' as timestamp with time zone); @@ -310,30 +305,19 @@ select d1 from timestamptz_tbl where d1 <= cast('1997-01-02' as timestamp with t select d1 from timestamptz_tbl where d1 >= cast('1997-01-02' as timestamp with time zone); select - d1 - - cast('1997-01-02' as timestamp with time zone) - as diff + d1 - cast('1997-01-02' as timestamp with time zone) as diff from timestamptz_tbl where d1 between '1902-01-01' and '2038-01-01'; select - date_trunc( - 'week', - cast('2004-02-29 15:44:17.71393' - as timestamp with time zone) - ) - as week_trunc; + date_trunc('week', cast('2004-02-29 15:44:17.71393' as timestamp with time zone)) as week_trunc; select date_trunc('week', cast('infinity' as timestamp with time zone)) as inf_trunc; select - date_trunc( - 'timezone', - cast('2004-02-29 15:44:17.71393' - as timestamp with time zone) - ) + date_trunc('timezone', cast('2004-02-29 15:44:17.71393' as timestamp with time zone)) as notsupp_trunc; select date_trunc('timezone', cast('infinity' as timestamp with time zone)) as notsupp_inf_trunc; @@ -341,39 +325,17 @@ select date_trunc('timezone', cast('infinity' as timestamp with time zone)) as n select date_trunc('ago', cast('infinity' as timestamp with time zone)) as invalid_trunc; select - date_trunc( - 'day', - cast('2001-02-16 20:38:40+00' - as timestamp with time zone), - 'Australia/Sydney' - ) + date_trunc('day', cast('2001-02-16 20:38:40+00' as timestamp with time zone), 'Australia/Sydney') as sydney_trunc; select - date_trunc( - 'day', - cast('2001-02-16 20:38:40+00' - as timestamp with time zone), - 'GMT' - ) - as gmt_trunc; + date_trunc('day', cast('2001-02-16 20:38:40+00' as timestamp with time zone), 'GMT') as gmt_trunc; select - date_trunc( - 'day', - cast('2001-02-16 20:38:40+00' - as timestamp with time zone), - 'VET' - ) - as vet_trunc; + date_trunc('day', cast('2001-02-16 20:38:40+00' as timestamp with time zone), 'VET') as vet_trunc; select - date_trunc( - 'timezone', - cast('infinity' as timestamp with time zone), - 'GMT' - ) - as notsupp_zone_trunc; + date_trunc('timezone', cast('infinity' as timestamp with time zone), 'GMT') as notsupp_zone_trunc; select date_trunc('week', cast('infinity' as timestamp with time zone), 'GMT') as inf_zone_trunc; @@ -383,11 +345,7 @@ select str, interval, date_trunc(str, ts, 'Australia/Sydney') = - date_bin( - cast(interval as interval), - ts, - cast('2001-01-01+11' as timestamp with time zone) - ) + date_bin(cast(interval as interval), ts, cast('2001-01-01+11' as timestamp with time zone)) as equal from ( @@ -400,14 +358,7 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - ( - cast('2020-02-29 15:44:17.71393+00' - as timestamp with time zone) - ) - ) - as ts (ts); + (values (cast('2020-02-29 15:44:17.71393+00' as timestamptz))) as ts (ts); select interval, @@ -426,97 +377,74 @@ from ('250 microseconds') ) as intervals (interval), - ( - values - ( - cast('2020-02-11 15:44:17.71393' - as timestamp with time zone) - ) - ) - as ts (ts), - ( - values - (cast('2001-01-01' as timestamp with time zone)) - ) - as origin (origin); + (values (cast('2020-02-11 15:44:17.71393' as timestamptz))) as ts (ts), + (values (cast('2001-01-01' as timestamptz))) as origin (origin); select date_bin( cast('5 min' as interval), - cast('2020-02-01 01:01:01+00' - as timestamp with time zone), - cast('2020-02-01 00:02:30+00' - as timestamp with time zone) + cast('2020-02-01 01:01:01+00' as timestamptz), + cast('2020-02-01 00:02:30+00' as timestamptz) ); select date_bin( cast('30 minutes' as interval), - cast('2024-02-01 15:00:00' - as timestamp with time zone), - cast('2024-02-01 17:00:00' - as timestamp with time zone) + cast('2024-02-01 15:00:00' as timestamptz), + cast('2024-02-01 17:00:00' as timestamptz) ); select date_bin( cast('5 months' as interval), - cast('2020-02-01 01:01:01+00' - as timestamp with time zone), + cast('2020-02-01 01:01:01+00' as timestamp with time zone), cast('2001-01-01+00' as timestamp with time zone) ); select date_bin( cast('5 years' as interval), - cast('2020-02-01 01:01:01+00' - as timestamp with time zone), + cast('2020-02-01 01:01:01+00' as timestamp with time zone), cast('2001-01-01+00' as timestamp with time zone) ); select date_bin( cast('0 days' as interval), - cast('1970-01-01 01:00:00+00' - as timestamp with time zone), - cast('1970-01-01 00:00:00+00' - as timestamp with time zone) + cast('1970-01-01 01:00:00+00' as timestamp with time zone), + cast('1970-01-01 00:00:00+00' as timestamp with time zone) ); select date_bin( cast('-2 days' as interval), - cast('1970-01-01 01:00:00+00' - as timestamp with time zone), - cast('1970-01-01 00:00:00+00' - as timestamp with time zone) + cast('1970-01-01 01:00:00+00' as timestamp with time zone), + cast('1970-01-01 00:00:00+00' as timestamp with time zone) ); select date_bin( cast('15 minutes' as interval), - cast('294276-12-30' as timestamp with time zone), - cast('4000-12-20 BC' as timestamp with time zone) + cast('294276-12-30' as timestamptz), + cast('4000-12-20 BC' as timestamptz) ); select date_bin( cast('200000000 days' as interval), - cast('2024-02-01' as timestamp with time zone), - cast('2024-01-01' as timestamp with time zone) + cast('2024-02-01' as timestamptz), + cast('2024-01-01' as timestamptz) ); select date_bin( cast('365000 days' as interval), - cast('4400-01-01 BC' as timestamp with time zone), - cast('4000-01-01 BC' as timestamp with time zone) + cast('4400-01-01 BC' as timestamptz), + cast('4000-01-01 BC' as timestamptz) ); select - d1 - - cast('1997-01-02' as timestamp with time zone) - as diff + d1 - cast('1997-01-02' as timestamp with time zone) as diff from timestamptz_tbl where @@ -567,39 +495,34 @@ select d1 as timestamptz, date_part('timezone', d1) as timezone, date_part('timezone_hour', d1) as timezone_hour, - date_part('timezone_minute', d1) - as timezone_minute + date_part('timezone_minute', d1) as timezone_minute from timestamptz_tbl; select d1 as timestamp, - EXTRACT('microseconds' from d1) as microseconds, - EXTRACT('milliseconds' from d1) as milliseconds, - EXTRACT('seconds' from d1) as seconds, - round(EXTRACT('julian' from d1)) as julian, - EXTRACT('epoch' from d1) as epoch + extract(microseconds from d1) as microseconds, + extract(milliseconds from d1) as milliseconds, + extract(seconds from d1) as seconds, + round(extract(julian from d1)) as julian, + extract(epoch from d1) as epoch from timestamptz_tbl; -select date_part('epoch', cast('294270-01-01 00:00:00+00' as timestamp with time zone)); +select date_part('epoch', cast('294270-01-01 00:00:00+00' as timestamptz)); -select EXTRACT('epoch' from cast('294270-01-01 00:00:00+00' as timestamp with time zone)); +select extract(epoch from cast('294270-01-01 00:00:00+00' as timestamptz)); -select EXTRACT('epoch' from cast('5000-01-01 00:00:00+00' as timestamp with time zone)); +select extract(epoch from cast('5000-01-01 00:00:00+00' as timestamptz)); select - cast('294276-12-31 23:59:59 UTC' - as timestamp with time zone) - - cast('1999-12-23 19:59:04.224193 UTC' - as timestamp with time zone) + cast('294276-12-31 23:59:59 UTC' as timestamptz) - + cast('1999-12-23 19:59:04.224193 UTC' as timestamptz) as ok; select - cast('294276-12-31 23:59:59 UTC' - as timestamp with time zone) - - cast('1999-12-23 19:59:04.224192 UTC' - as timestamp with time zone) + cast('294276-12-31 23:59:59 UTC' as timestamptz) - + cast('1999-12-23 19:59:04.224192 UTC' as timestamptz) as overflows; select to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon') from timestamptz_tbl; @@ -609,10 +532,7 @@ select to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM') from timest select to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J') from timestamptz_tbl; select - to_char( - d1, - 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ' - ) + to_char(d1, 'FMY,YYY FMYYYY FMYYY FMYY FMY FMCC FMQ FMMM FMWW FMDDD FMDD FMD FMJ') from timestamptz_tbl; @@ -625,10 +545,7 @@ select to_char(d1, 'HH24--text--MI--text--SS') from timestamptz_tbl; select to_char(d1, 'YYYYTH YYYYth Jth') from timestamptz_tbl; 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' - ) + 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') from timestamptz_tbl; @@ -637,17 +554,11 @@ select to_char(d1, 'IYYY IYY IY I IW IDDD ID') from timestamptz_tbl; select to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID') from timestamptz_tbl; select - to_char( - d, - 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US' - ) + to_char(d, 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US') from ( values - ( - cast('2018-11-02 12:34:56' - as timestamp with time zone) - ), + (cast('2018-11-02 12:34:56' as timestamptz)), ('2018-11-02 12:34:56.78'), ('2018-11-02 12:34:56.78901'), ('2018-11-02 12:34:56.78901234') @@ -656,83 +567,83 @@ from set time zone '00:00'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '+02:00'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '-13:00'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '-00:30'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '00:30'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '-04:30'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '04:30'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '-04:15'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '04:15'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; reset timezone; set time zone '00:00'; -select to_char(NOW(), 'of') as "Of", to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as "Of", to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '+02:00'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '-13:00'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '-00:30'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '00:30'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '-04:30'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '04:30'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '-04:15'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '04:15'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; reset timezone; create table timestamptz_tst ( a int, - b timestamp with time zone + b timestamptz ); insert into timestamptz_tst values (1, 'Sat Mar 12 23:58:48 1000 IST'); @@ -793,29 +704,19 @@ select make_timestamptz(2014, 12, 10, 10, 10, 10, '-16'); select make_timestamptz(1973, 7, 15, 8, 15, 55.33, '+2') = - cast('1973-07-15 08:15:55.33+02' - as timestamp with time zone); + cast('1973-07-15 08:15:55.33+02' as timestamptz); select - make_timestamptz( - 2014, - 12, - 10, - 0, - 0, - 0, - 'Europe/Prague' - ) = - cast('2014-12-10 00:00:00 Europe/Prague' - as timestamp with time zone); + make_timestamptz(2014, 12, 10, 0, 0, 0, 'Europe/Prague') = + cast('2014-12-10 00:00:00 Europe/Prague' as timestamptz); -select timezone('UTC', make_timestamptz(2014, 12, 10, 0, 0, 0, 'Europe/Prague')); +select (make_timestamptz(2014, 12, 10, 0, 0, 0, 'Europe/Prague') at time zone 'UTC'); -select timezone('UTC', make_timestamptz(1881, 12, 10, 0, 0, 0, 'Asia/Singapore')); +select (make_timestamptz(1881, 12, 10, 0, 0, 0, 'Asia/Singapore') at time zone 'UTC'); -select timezone('UTC', make_timestamptz(1881, 12, 10, 0, 0, 0, 'Pacific/Honolulu')); +select (make_timestamptz(1881, 12, 10, 0, 0, 0, 'Pacific/Honolulu') at time zone 'UTC'); -select timezone('UTC', make_timestamptz(1881, 12, 10, 0, 0, 0, 'Europe/Paris')); +select (make_timestamptz(1881, 12, 10, 0, 0, 0, 'Europe/Paris') at time zone 'UTC'); select make_timestamptz(1910, 12, 24, 0, 0, 0, 'Nehwon/Lankhmar'); @@ -833,18 +734,15 @@ select * from generate_series( - cast('2020-01-01 00:00' - as timestamp with time zone), - cast('2020-01-02 03:00' - as timestamp with time zone), + cast('2020-01-01 00:00' as timestamptz), + cast('2020-01-02 03:00' as timestamptz), cast('1 hour' as interval) ); select generate_series( - cast('2022-01-01 00:00' - as timestamp with time zone), - cast('infinity' as timestamp with time zone), + cast('2022-01-01 00:00' as timestamptz), + cast('infinity' as timestamptz), cast('1 month' as interval) ) limit 10; @@ -853,59 +751,41 @@ select * from generate_series( - cast('2020-01-01 00:00' - as timestamp with time zone), - cast('2020-01-02 03:00' - as timestamp with time zone), + cast('2020-01-01 00:00' as timestamptz), + cast('2020-01-02 03:00' as timestamptz), cast('0 hour' as interval) ); select generate_series( - cast('1995-08-06 12:12:12' - as timestamp with time zone), - cast('1996-08-06 12:12:12' - as timestamp with time zone), + cast('1995-08-06 12:12:12' as timestamptz), + cast('1996-08-06 12:12:12' as timestamptz), cast('infinity' as interval) ); select generate_series( - cast('1995-08-06 12:12:12' - as timestamp with time zone), - cast('1996-08-06 12:12:12' - as timestamp with time zone), + cast('1995-08-06 12:12:12' as timestamptz), + cast('1996-08-06 12:12:12' as timestamptz), cast('-infinity' as interval) ); -set time zone UTC; +set time zone 'UTC'; -select - date_add( - cast('2022-10-30 00:00:00+01' - as timestamp with time zone), - cast('1 day' as interval) - ); +select date_add(cast('2022-10-30 00:00:00+01' as timestamptz), cast('1 day' as interval)); select date_add( - cast('2021-10-31 00:00:00+02' - as timestamp with time zone), + cast('2021-10-31 00:00:00+02' as timestamptz), cast('1 day' as interval), 'Europe/Warsaw' ); -select - date_subtract( - cast('2022-10-30 00:00:00+01' - as timestamp with time zone), - cast('1 day' as interval) - ); +select date_subtract(cast('2022-10-30 00:00:00+01' as timestamptz), cast('1 day' as interval)); select date_subtract( - cast('2021-10-31 00:00:00+02' - as timestamp with time zone), + cast('2021-10-31 00:00:00+02' as timestamptz), cast('1 day' as interval), 'Europe/Warsaw' ); @@ -914,129 +794,127 @@ select * from generate_series( - cast('2021-12-31 23:00:00+00' - as timestamp with time zone), - cast('2020-12-31 23:00:00+00' - as timestamp with time zone), + cast('2021-12-31 23:00:00+00' as timestamptz), + cast('2020-12-31 23:00:00+00' as timestamptz), cast('-1 month' as interval), 'Europe/Warsaw' ); reset timezone; -set time zone UTC; +set time zone 'UTC'; -select cast('2011-03-27 00:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 00:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 01:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 01:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 01:59:59 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 01:59:59 Europe/Moscow' as timestamptz); -select cast('2011-03-27 02:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 02:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 02:00:01 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 02:00:01 Europe/Moscow' as timestamptz); -select cast('2011-03-27 02:59:59 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 02:59:59 Europe/Moscow' as timestamptz); -select cast('2011-03-27 03:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 03:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 03:00:01 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 03:00:01 Europe/Moscow' as timestamptz); -select cast('2011-03-27 04:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 04:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 00:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 00:00:00 MSK' as timestamptz); -select cast('2011-03-27 01:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 01:00:00 MSK' as timestamptz); -select cast('2011-03-27 01:59:59 MSK' as timestamp with time zone); +select cast('2011-03-27 01:59:59 MSK' as timestamptz); -select cast('2011-03-27 02:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 02:00:00 MSK' as timestamptz); -select cast('2011-03-27 02:00:01 MSK' as timestamp with time zone); +select cast('2011-03-27 02:00:01 MSK' as timestamptz); -select cast('2011-03-27 02:59:59 MSK' as timestamp with time zone); +select cast('2011-03-27 02:59:59 MSK' as timestamptz); -select cast('2011-03-27 03:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 03:00:00 MSK' as timestamptz); -select cast('2011-03-27 03:00:01 MSK' as timestamp with time zone); +select cast('2011-03-27 03:00:01 MSK' as timestamptz); -select cast('2011-03-27 04:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 04:00:00 MSK' as timestamptz); -select cast('2014-10-26 00:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 00:00:00 Europe/Moscow' as timestamptz); -select cast('2014-10-26 00:59:59 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 00:59:59 Europe/Moscow' as timestamptz); -select cast('2014-10-26 01:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 01:00:00 Europe/Moscow' as timestamptz); -select cast('2014-10-26 01:00:01 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 01:00:01 Europe/Moscow' as timestamptz); -select cast('2014-10-26 02:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 02:00:00 Europe/Moscow' as timestamptz); -select cast('2014-10-26 00:00:00 MSK' as timestamp with time zone); +select cast('2014-10-26 00:00:00 MSK' as timestamptz); -select cast('2014-10-26 00:59:59 MSK' as timestamp with time zone); +select cast('2014-10-26 00:59:59 MSK' as timestamptz); -select cast('2014-10-26 01:00:00 MSK' as timestamp with time zone); +select cast('2014-10-26 01:00:00 MSK' as timestamptz); -select cast('2014-10-26 01:00:01 MSK' as timestamp with time zone); +select cast('2014-10-26 01:00:01 MSK' as timestamptz); -select cast('2014-10-26 02:00:00 MSK' as timestamp with time zone); +select cast('2014-10-26 02:00:00 MSK' as timestamptz); -select timezone('Europe/Moscow', cast('2011-03-27 00:00:00' as timestamp)); +select (cast('2011-03-27 00:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 01:00:00' as timestamp)); +select (cast('2011-03-27 01:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 01:59:59' as timestamp)); +select (cast('2011-03-27 01:59:59' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 02:00:00' as timestamp)); +select (cast('2011-03-27 02:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 02:00:01' as timestamp)); +select (cast('2011-03-27 02:00:01' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 02:59:59' as timestamp)); +select (cast('2011-03-27 02:59:59' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 03:00:00' as timestamp)); +select (cast('2011-03-27 03:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 03:00:01' as timestamp)); +select (cast('2011-03-27 03:00:01' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 04:00:00' as timestamp)); +select (cast('2011-03-27 04:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('MSK', cast('2011-03-27 00:00:00' as timestamp)); +select (cast('2011-03-27 00:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 01:00:00' as timestamp)); +select (cast('2011-03-27 01:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 01:59:59' as timestamp)); +select (cast('2011-03-27 01:59:59' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 02:00:00' as timestamp)); +select (cast('2011-03-27 02:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 02:00:01' as timestamp)); +select (cast('2011-03-27 02:00:01' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 02:59:59' as timestamp)); +select (cast('2011-03-27 02:59:59' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 03:00:00' as timestamp)); +select (cast('2011-03-27 03:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 03:00:01' as timestamp)); +select (cast('2011-03-27 03:00:01' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 04:00:00' as timestamp)); +select (cast('2011-03-27 04:00:00' as timestamp) at time zone 'MSK'); -select timezone('Europe/Moscow', cast('2014-10-26 00:00:00' as timestamp)); +select (cast('2014-10-26 00:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-26 00:59:59' as timestamp)); +select (cast('2014-10-26 00:59:59' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-26 01:00:00' as timestamp)); +select (cast('2014-10-26 01:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-26 01:00:01' as timestamp)); +select (cast('2014-10-26 01:00:01' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-26 02:00:00' as timestamp)); +select (cast('2014-10-26 02:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('MSK', cast('2014-10-26 00:00:00' as timestamp)); +select (cast('2014-10-26 00:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-26 00:59:59' as timestamp)); +select (cast('2014-10-26 00:59:59' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-26 01:00:00' as timestamp)); +select (cast('2014-10-26 01:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-26 01:00:01' as timestamp)); +select (cast('2014-10-26 01:00:01' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-26 02:00:00' as timestamp)); +select (cast('2014-10-26 02:00:00' as timestamp) at time zone 'MSK'); select make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); @@ -1058,112 +936,102 @@ select to_timestamp(cast('NaN' as double precision)); set time zone 'Europe/Moscow'; -select cast('2011-03-26 21:00:00 UTC' as timestamp with time zone); +select cast('2011-03-26 21:00:00 UTC' as timestamptz); -select cast('2011-03-26 22:00:00 UTC' as timestamp with time zone); +select cast('2011-03-26 22:00:00 UTC' as timestamptz); -select cast('2011-03-26 22:59:59 UTC' as timestamp with time zone); +select cast('2011-03-26 22:59:59 UTC' as timestamptz); -select cast('2011-03-26 23:00:00 UTC' as timestamp with time zone); +select cast('2011-03-26 23:00:00 UTC' as timestamptz); -select cast('2011-03-26 23:00:01 UTC' as timestamp with time zone); +select cast('2011-03-26 23:00:01 UTC' as timestamptz); -select cast('2011-03-26 23:59:59 UTC' as timestamp with time zone); +select cast('2011-03-26 23:59:59 UTC' as timestamptz); -select cast('2011-03-27 00:00:00 UTC' as timestamp with time zone); +select cast('2011-03-27 00:00:00 UTC' as timestamptz); -select cast('2014-10-25 21:00:00 UTC' as timestamp with time zone); +select cast('2014-10-25 21:00:00 UTC' as timestamptz); -select cast('2014-10-25 21:59:59 UTC' as timestamp with time zone); +select cast('2014-10-25 21:59:59 UTC' as timestamptz); -select cast('2014-10-25 22:00:00 UTC' as timestamp with time zone); +select cast('2014-10-25 22:00:00 UTC' as timestamptz); -select cast('2014-10-25 22:00:01 UTC' as timestamp with time zone); +select cast('2014-10-25 22:00:01 UTC' as timestamptz); -select cast('2014-10-25 23:00:00 UTC' as timestamp with time zone); +select cast('2014-10-25 23:00:00 UTC' as timestamptz); reset timezone; -select timezone('Europe/Moscow', cast('2011-03-26 21:00:00 UTC' as timestamp with time zone)); +select (cast('2011-03-26 21:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-26 22:00:00 UTC' as timestamp with time zone)); +select (cast('2011-03-26 22:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-26 22:59:59 UTC' as timestamp with time zone)); +select (cast('2011-03-26 22:59:59 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-26 23:00:00 UTC' as timestamp with time zone)); +select (cast('2011-03-26 23:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-26 23:00:01 UTC' as timestamp with time zone)); +select (cast('2011-03-26 23:00:01 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-26 23:59:59 UTC' as timestamp with time zone)); +select (cast('2011-03-26 23:59:59 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 00:00:00 UTC' as timestamp with time zone)); +select (cast('2011-03-27 00:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-25 21:00:00 UTC' as timestamp with time zone)); +select (cast('2014-10-25 21:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-25 21:59:59 UTC' as timestamp with time zone)); +select (cast('2014-10-25 21:59:59 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-25 22:00:00 UTC' as timestamp with time zone)); +select (cast('2014-10-25 22:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-25 22:00:01 UTC' as timestamp with time zone)); +select (cast('2014-10-25 22:00:01 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-25 23:00:00 UTC' as timestamp with time zone)); +select (cast('2014-10-25 23:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select timezone('MSK', cast('2011-03-26 21:00:00 UTC' as timestamp with time zone)); +select (cast('2011-03-26 21:00:00 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-26 22:00:00 UTC' as timestamp with time zone)); +select (cast('2011-03-26 22:00:00 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-26 22:59:59 UTC' as timestamp with time zone)); +select (cast('2011-03-26 22:59:59 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-26 23:00:00 UTC' as timestamp with time zone)); +select (cast('2011-03-26 23:00:00 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-26 23:00:01 UTC' as timestamp with time zone)); +select (cast('2011-03-26 23:00:01 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-26 23:59:59 UTC' as timestamp with time zone)); +select (cast('2011-03-26 23:59:59 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 00:00:00 UTC' as timestamp with time zone)); +select (cast('2011-03-27 00:00:00 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-25 21:00:00 UTC' as timestamp with time zone)); +select (cast('2014-10-25 21:00:00 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-25 21:59:59 UTC' as timestamp with time zone)); +select (cast('2014-10-25 21:59:59 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-25 22:00:00 UTC' as timestamp with time zone)); +select (cast('2014-10-25 22:00:00 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-25 22:00:01 UTC' as timestamp with time zone)); +select (cast('2014-10-25 22:00:01 UTC' as timestamptz) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-25 23:00:00 UTC' as timestamp with time zone)); +select (cast('2014-10-25 23:00:00 UTC' as timestamptz) at time zone 'MSK'); begin; set local time zone 'Europe/Paris'; -values (timezone(cast('1978-07-07 19:38 America/New_York' as timestamp with time zone))); +values ((cast('1978-07-07 19:38 America/New_York' as timestamp with time zone) at local)); -values (timezone(cast('1978-07-07 19:38' as timestamp))); +values ((cast('1978-07-07 19:38' as timestamp) at local)); set local time zone 'Australia/Sydney'; -values (timezone(cast('1978-07-07 19:38 America/New_York' as timestamp with time zone))); +values ((cast('1978-07-07 19:38 America/New_York' as timestamp with time zone) at local)); -values (timezone(cast('1978-07-07 19:38' as timestamp))); +values ((cast('1978-07-07 19:38' as timestamp) at local)); -set local time zone UTC; +set local time zone 'UTC'; create view timestamp_local_view as select - timezone( - cast('1978-07-07 19:38 America/New_York' - as timestamp with time zone) - ) - as ttz_at_local, - timezone( - cast('1978-07-07 19:38 America/New_York' - as timestamp with time zone) - ) - as ttz_func, - timezone(cast('1978-07-07 19:38' as timestamp)) - as t_at_local, - timezone(cast('1978-07-07 19:38' as timestamp)) - as t_func; + (cast('1978-07-07 19:38 America/New_York' as timestamp with time zone) at local) as ttz_at_local, + timezone(cast('1978-07-07 19:38 America/New_York' as timestamp with time zone)) as ttz_func, + (cast('1978-07-07 19:38' as timestamp) at local) as t_at_local, + timezone(cast('1978-07-07 19:38' as timestamp)) as t_func; select pg_get_viewdef('timestamp_local_view', true); @@ -1173,62 +1041,38 @@ drop view timestamp_local_view; commit; -create temporary table tmptz (f1 timestamp with time zone primary key); +create temporary table tmptz (f1 timestamptz primary key); insert into tmptz values ('2017-01-18 00:00+00'); -select * from tmptz where timezone('utc', f1) = '2017-01-18 00:00'; +select * from tmptz where (f1 at time zone 'utc') = '2017-01-18 00:00'; -select * from tmptz where timezone('utc', f1) = '2017-01-18 00:00'; +select * from tmptz where (f1 at time zone 'utc') = '2017-01-18 00:00'; -select cast('infinity' as timestamp with time zone) - cast('infinity' as timestamp with time zone); +select cast('infinity' as timestamptz) - cast('infinity' as timestamptz); -select cast('infinity' as timestamp with time zone) - cast('-infinity' as timestamp with time zone); +select cast('infinity' as timestamptz) - cast('-infinity' as timestamptz); -select cast('-infinity' as timestamp with time zone) - cast('infinity' as timestamp with time zone); +select cast('-infinity' as timestamptz) - cast('infinity' as timestamptz); -select - cast('-infinity' as timestamp with time zone) - - cast('-infinity' as timestamp with time zone); +select cast('-infinity' as timestamptz) - cast('-infinity' as timestamptz); -select - cast('infinity' as timestamp with time zone) - - cast('1995-08-06 12:12:12' - as timestamp with time zone); +select cast('infinity' as timestamptz) - cast('1995-08-06 12:12:12' as timestamptz); -select - cast('-infinity' as timestamp with time zone) - - cast('1995-08-06 12:12:12' - as timestamp with time zone); +select cast('-infinity' as timestamptz) - cast('1995-08-06 12:12:12' as timestamptz); -select age(cast('infinity' as timestamp with time zone)); +select age(cast('infinity' as timestamptz)); -select age(cast('-infinity' as timestamp with time zone)); +select age(cast('-infinity' as timestamptz)); -select - age( - cast('infinity' as timestamp with time zone), - cast('infinity' as timestamp with time zone) - ); +select age(cast('infinity' as timestamptz), cast('infinity' as timestamptz)); -select - age( - cast('infinity' as timestamp with time zone), - cast('-infinity' as timestamp with time zone) - ); +select age(cast('infinity' as timestamptz), cast('-infinity' as timestamptz)); -select - age( - cast('-infinity' as timestamp with time zone), - cast('infinity' as timestamp with time zone) - ); +select age(cast('-infinity' as timestamptz), cast('infinity' as timestamptz)); -select - age( - cast('-infinity' as timestamp with time zone), - cast('-infinity' as timestamp with time zone) - ); +select age(cast('-infinity' as timestamptz), cast('-infinity' as timestamptz)); -select cast('1999-12-31 24:00:00' as timestamp with time zone); +select cast('1999-12-31 24:00:00' as timestamptz); select make_timestamptz(1999, 12, 31, 24, 0, 0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamptz_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamptz_80.snap index 350c3e79b..eecf685aa 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamptz_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timestamptz_80.snap @@ -18,49 +18,39 @@ insert into timestamptz_tbl values ('tomorrow EST'); insert into timestamptz_tbl values ('tomorrow zulu'); select - COUNT(*) as one + count(*) as one from timestamptz_tbl where - d1 = - cast('today' - as timestamp with time zone); + d1 = cast('today' as timestamp with time zone); select - COUNT(*) as one + count(*) as one from timestamptz_tbl where - d1 = - cast('tomorrow' - as timestamp with time zone); + d1 = cast('tomorrow' as timestamp with time zone); select - COUNT(*) as one + count(*) as one from timestamptz_tbl where - d1 = - cast('yesterday' - as timestamp with time zone); + d1 = cast('yesterday' as timestamp with time zone); select - COUNT(*) as one + count(*) as one from timestamptz_tbl where - d1 = - cast('tomorrow EST' - as timestamp with time zone); + d1 = cast('tomorrow EST' as timestamp with time zone); select - COUNT(*) as one + count(*) as one from timestamptz_tbl where - d1 = - cast('tomorrow zulu' - as timestamp with time zone); + d1 = cast('tomorrow zulu' as timestamp with time zone); commit; @@ -81,15 +71,13 @@ insert into timestamptz_tbl values ('now'); select pg_sleep(0.1); select - COUNT(*) as two + count(*) as two from timestamptz_tbl where - d1 = - cast('now' - as timestamp(2) with time zone); + d1 = cast('now' as timestamp(2) with time zone); -select COUNT(d1) as three, COUNT(distinct d1) as two from timestamptz_tbl; +select count(d1) as three, count(distinct d1) as two from timestamptz_tbl; commit; @@ -101,12 +89,7 @@ insert into timestamptz_tbl values ('infinity'); insert into timestamptz_tbl values ('epoch'); -select - cast('infinity' - as timestamp with time zone) = - cast('+infinity' - as timestamp with time zone) - as t; +select cast('infinity' as timestamptz) = cast('+infinity' as timestamptz) as t; insert into timestamptz_tbl values ('Mon Feb 10 17:32:01 1997 PST'); @@ -174,56 +157,47 @@ insert into timestamptz_tbl values ('1997.041 17:32:01 UTC'); insert into timestamptz_tbl values ('19970210 173201 America/New_York'); -select timezone('America/New_York', '19970210 173201'); +select ('19970210 173201' at time zone 'America/New_York'); insert into timestamptz_tbl values ('19970710 173201 America/New_York'); -select timezone('America/New_York', '19970710 173201'); +select ('19970710 173201' at time zone 'America/New_York'); insert into timestamptz_tbl values ('19970710 173201 America/Does_not_exist'); -select timezone('America/Does_not_exist', '19970710 173201'); +select ('19970710 173201' at time zone 'America/Does_not_exist'); -select cast('20500710 173201 Europe/Helsinki' as timestamp with time zone); +select cast('20500710 173201 Europe/Helsinki' as timestamptz); -select cast('20500110 173201 Europe/Helsinki' as timestamp with time zone); +select cast('20500110 173201 Europe/Helsinki' as timestamptz); -select - cast('205000-07-10 17:32:01 Europe/Helsinki' - as timestamp with time zone); +select cast('205000-07-10 17:32:01 Europe/Helsinki' as timestamptz); -select - cast('205000-01-10 17:32:01 Europe/Helsinki' - as timestamp with time zone); +select cast('205000-01-10 17:32:01 Europe/Helsinki' as timestamptz); -select cast('Jan 01 00:00:00 1000 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 1000 LMT' as timestamptz); -select cast('Jan 01 00:00:00 2024 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 2024 LMT' as timestamptz); set time zone 'Europe/London'; -select cast('Jan 01 00:00:00 1000 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 1000 LMT' as timestamptz); -select cast('Jan 01 00:00:00 2024 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 2024 LMT' as timestamptz); -set time zone UTC; +set time zone 'UTC'; -select cast('Jan 01 00:00:00 2024 LMT' as timestamp with time zone); +select cast('Jan 01 00:00:00 2024 LMT' as timestamptz); -select cast('1912-01-01 00:00 MMT' as timestamp with time zone); +select cast('1912-01-01 00:00 MMT' as timestamptz); set time zone 'America/Montevideo'; -select cast('1912-01-01 00:00' as timestamp with time zone); +select cast('1912-01-01 00:00' as timestamptz); -select cast('1912-01-01 00:00 MMT' as timestamp with time zone); +select cast('1912-01-01 00:00 MMT' as timestamptz); -select - timezone( - 'UTC', - cast('1912-01-01 00:00 MMT' - as timestamp with time zone) - ); +select (cast('1912-01-01 00:00 MMT' as timestamptz) at time zone 'UTC'); reset timezone; @@ -238,10 +212,7 @@ select * from pg_input_error_info('garbage', 'timestamptz'); select * from - pg_input_error_info( - '2001-01-01 00:00 Nehwon/Lankhmar', - 'timestamptz' - ); + pg_input_error_info('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamptz'); insert into timestamptz_tbl values ('1997-06-10 18:32:01 PDT'); @@ -311,95 +282,78 @@ insert into timestamptz_tbl values ('Feb 16 17:32:01 -0097'); insert into timestamptz_tbl values ('Feb 16 17:32:01 5097 BC'); -select - cast('Wed Jul 11 10:51:14 America/New_York 2001' - as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 America/New_York 2001' as timestamptz); -select cast('Wed Jul 11 10:51:14 GMT-4 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 GMT-4 2001' as timestamptz); -select cast('Wed Jul 11 10:51:14 GMT+4 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 GMT+4 2001' as timestamptz); -select cast('Wed Jul 11 10:51:14 PST-03:00 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 PST-03:00 2001' as timestamptz); -select cast('Wed Jul 11 10:51:14 PST+03:00 2001' as timestamp with time zone); +select cast('Wed Jul 11 10:51:14 PST+03:00 2001' as timestamptz); select d1 from timestamptz_tbl; -select cast('4714-11-24 00:00:00+00 BC' as timestamp with time zone); +select cast('4714-11-24 00:00:00+00 BC' as timestamptz); -select cast('4714-11-23 16:00:00-08 BC' as timestamp with time zone); +select cast('4714-11-23 16:00:00-08 BC' as timestamptz); -select cast('Sun Nov 23 16:00:00 4714 PST BC' as timestamp with time zone); +select cast('Sun Nov 23 16:00:00 4714 PST BC' as timestamptz); -select cast('4714-11-23 23:59:59+00 BC' as timestamp with time zone); +select cast('4714-11-23 23:59:59+00 BC' as timestamptz); -select cast('294276-12-31 23:59:59+00' as timestamp with time zone); +select cast('294276-12-31 23:59:59+00' as timestamptz); -select cast('294276-12-31 15:59:59-08' as timestamp with time zone); +select cast('294276-12-31 15:59:59-08' as timestamptz); -select cast('294277-01-01 00:00:00+00' as timestamp with time zone); +select cast('294277-01-01 00:00:00+00' as timestamptz); -select cast('294277-12-31 16:00:00-08' as timestamp with time zone); +select cast('294277-12-31 16:00:00-08' as timestamptz); select d1 from timestamptz_tbl where - d1 > - cast('1997-01-02' - as timestamp with time zone); + d1 > cast('1997-01-02' as timestamp with time zone); select d1 from timestamptz_tbl where - d1 < - cast('1997-01-02' - as timestamp with time zone); + d1 < cast('1997-01-02' as timestamp with time zone); select d1 from timestamptz_tbl where - d1 = - cast('1997-01-02' - as timestamp with time zone); + d1 = cast('1997-01-02' as timestamp with time zone); select d1 from timestamptz_tbl where - d1 <> - cast('1997-01-02' - as timestamp with time zone); + d1 <> cast('1997-01-02' as timestamp with time zone); select d1 from timestamptz_tbl where - d1 <= - cast('1997-01-02' - as timestamp with time zone); + d1 <= cast('1997-01-02' as timestamp with time zone); select d1 from timestamptz_tbl where - d1 >= - cast('1997-01-02' - as timestamp with time zone); + d1 >= cast('1997-01-02' as timestamp with time zone); select - d1 - - cast('1997-01-02' - as timestamp with time zone) - as diff + d1 - cast('1997-01-02' as timestamp with time zone) as diff from timestamptz_tbl where @@ -408,48 +362,32 @@ where select date_trunc( 'week', - cast('2004-02-29 15:44:17.71393' - as timestamp with time zone) + cast('2004-02-29 15:44:17.71393' as timestamp with time zone) ) as week_trunc; select - date_trunc( - 'week', - cast('infinity' - as timestamp with time zone) - ) - as inf_trunc; + date_trunc('week', cast('infinity' as timestamp with time zone)) as inf_trunc; select date_trunc( 'timezone', - cast('2004-02-29 15:44:17.71393' - as timestamp with time zone) + cast('2004-02-29 15:44:17.71393' as timestamp with time zone) ) as notsupp_trunc; select - date_trunc( - 'timezone', - cast('infinity' - as timestamp with time zone) - ) + date_trunc('timezone', cast('infinity' as timestamp with time zone)) as notsupp_inf_trunc; select - date_trunc( - 'ago', - cast('infinity' - as timestamp with time zone) - ) + date_trunc('ago', cast('infinity' as timestamp with time zone)) as invalid_trunc; select date_trunc( 'day', - cast('2001-02-16 20:38:40+00' - as timestamp with time zone), + cast('2001-02-16 20:38:40+00' as timestamp with time zone), 'Australia/Sydney' ) as sydney_trunc; @@ -457,8 +395,7 @@ select select date_trunc( 'day', - cast('2001-02-16 20:38:40+00' - as timestamp with time zone), + cast('2001-02-16 20:38:40+00' as timestamp with time zone), 'GMT' ) as gmt_trunc; @@ -466,37 +403,21 @@ select select date_trunc( 'day', - cast('2001-02-16 20:38:40+00' - as timestamp with time zone), + cast('2001-02-16 20:38:40+00' as timestamp with time zone), 'VET' ) as vet_trunc; select - date_trunc( - 'timezone', - cast('infinity' - as timestamp with time zone), - 'GMT' - ) + date_trunc('timezone', cast('infinity' as timestamp with time zone), 'GMT') as notsupp_zone_trunc; select - date_trunc( - 'week', - cast('infinity' - as timestamp with time zone), - 'GMT' - ) + date_trunc('week', cast('infinity' as timestamp with time zone), 'GMT') as inf_zone_trunc; select - date_trunc( - 'ago', - cast('infinity' - as timestamp with time zone), - 'GMT' - ) + date_trunc('ago', cast('infinity' as timestamp with time zone), 'GMT') as invalid_zone_trunc; select @@ -506,8 +427,7 @@ select date_bin( cast(interval as interval), ts, - cast('2001-01-01+11' - as timestamp with time zone) + cast('2001-01-01+11' as timestamp with time zone) ) as equal from @@ -521,24 +441,13 @@ from ('microsecond', '1 us') ) as intervals (str, interval), - ( - values - ( - cast('2020-02-29 15:44:17.71393+00' - as timestamp with time zone) - ) - ) - as ts (ts); + (values (cast('2020-02-29 15:44:17.71393+00' as timestamptz))) as ts (ts); select interval, ts, origin, - date_bin( - cast(interval as interval), - ts, - origin - ) + date_bin(cast(interval as interval), ts, origin) from ( values @@ -551,117 +460,80 @@ from ('250 microseconds') ) as intervals (interval), - ( - values - ( - cast('2020-02-11 15:44:17.71393' - as timestamp with time zone) - ) - ) - as ts (ts), - ( - values - ( - cast('2001-01-01' - as timestamp with time zone) - ) - ) - as origin (origin); + (values (cast('2020-02-11 15:44:17.71393' as timestamptz))) as ts (ts), + (values (cast('2001-01-01' as timestamptz))) as origin (origin); select date_bin( cast('5 min' as interval), - cast('2020-02-01 01:01:01+00' - as timestamp with time zone), - cast('2020-02-01 00:02:30+00' - as timestamp with time zone) + cast('2020-02-01 01:01:01+00' as timestamptz), + cast('2020-02-01 00:02:30+00' as timestamptz) ); select date_bin( cast('30 minutes' as interval), - cast('2024-02-01 15:00:00' - as timestamp with time zone), - cast('2024-02-01 17:00:00' - as timestamp with time zone) + cast('2024-02-01 15:00:00' as timestamptz), + cast('2024-02-01 17:00:00' as timestamptz) ); select date_bin( cast('5 months' as interval), - cast('2020-02-01 01:01:01+00' - as timestamp with time zone), - cast('2001-01-01+00' - as timestamp with time zone) + cast('2020-02-01 01:01:01+00' as timestamp with time zone), + cast('2001-01-01+00' as timestamp with time zone) ); select date_bin( cast('5 years' as interval), - cast('2020-02-01 01:01:01+00' - as timestamp with time zone), - cast('2001-01-01+00' - as timestamp with time zone) + cast('2020-02-01 01:01:01+00' as timestamp with time zone), + cast('2001-01-01+00' as timestamp with time zone) ); select date_bin( cast('0 days' as interval), - cast('1970-01-01 01:00:00+00' - as timestamp with time zone), - cast('1970-01-01 00:00:00+00' - as timestamp with time zone) + cast('1970-01-01 01:00:00+00' as timestamp with time zone), + cast('1970-01-01 00:00:00+00' as timestamp with time zone) ); select date_bin( cast('-2 days' as interval), - cast('1970-01-01 01:00:00+00' - as timestamp with time zone), - cast('1970-01-01 00:00:00+00' - as timestamp with time zone) + cast('1970-01-01 01:00:00+00' as timestamp with time zone), + cast('1970-01-01 00:00:00+00' as timestamp with time zone) ); select date_bin( cast('15 minutes' as interval), - cast('294276-12-30' - as timestamp with time zone), - cast('4000-12-20 BC' - as timestamp with time zone) + cast('294276-12-30' as timestamptz), + cast('4000-12-20 BC' as timestamptz) ); select date_bin( cast('200000000 days' as interval), - cast('2024-02-01' - as timestamp with time zone), - cast('2024-01-01' - as timestamp with time zone) + cast('2024-02-01' as timestamptz), + cast('2024-01-01' as timestamptz) ); select date_bin( cast('365000 days' as interval), - cast('4400-01-01 BC' - as timestamp with time zone), - cast('4000-01-01 BC' - as timestamp with time zone) + cast('4400-01-01 BC' as timestamptz), + cast('4000-01-01 BC' as timestamptz) ); select - d1 - - cast('1997-01-02' - as timestamp with time zone) - as diff + d1 - cast('1997-01-02' as timestamp with time zone) as diff from timestamptz_tbl where d1 - between cast('1902-01-01' - as timestamp with time zone) - and cast('2038-01-01' - as timestamp with time zone); + between cast('1902-01-01' as timestamp with time zone) + and cast('2038-01-01' as timestamp with time zone); select d1 as timestamptz, @@ -696,8 +568,7 @@ select d1 as timestamptz, date_part('decade', d1) as decade, date_part('century', d1) as century, - date_part('millennium', d1) - as millennium, + date_part('millennium', d1) as millennium, round(date_part('julian', d1)) as julian, date_part('epoch', d1) as epoch from @@ -706,76 +577,49 @@ from select d1 as timestamptz, date_part('timezone', d1) as timezone, - date_part('timezone_hour', d1) - as timezone_hour, - date_part('timezone_minute', d1) - as timezone_minute + date_part('timezone_hour', d1) as timezone_hour, + date_part('timezone_minute', d1) as timezone_minute from timestamptz_tbl; select d1 as timestamp, - EXTRACT('microseconds' from d1) - as microseconds, - EXTRACT('milliseconds' from d1) - as milliseconds, - EXTRACT('seconds' from d1) as seconds, - round(EXTRACT('julian' from d1)) - as julian, - EXTRACT('epoch' from d1) as epoch + extract(microseconds from d1) as microseconds, + extract(milliseconds from d1) as milliseconds, + extract(seconds from d1) as seconds, + round(extract(julian from d1)) as julian, + extract(epoch from d1) as epoch from timestamptz_tbl; -select - date_part( - 'epoch', - cast('294270-01-01 00:00:00+00' - as timestamp with time zone) - ); +select date_part('epoch', cast('294270-01-01 00:00:00+00' as timestamptz)); -select - EXTRACT('epoch' from cast('294270-01-01 00:00:00+00' - as timestamp with time zone)); +select extract(epoch from cast('294270-01-01 00:00:00+00' as timestamptz)); -select - EXTRACT('epoch' from cast('5000-01-01 00:00:00+00' - as timestamp with time zone)); +select extract(epoch from cast('5000-01-01 00:00:00+00' as timestamptz)); select - cast('294276-12-31 23:59:59 UTC' - as timestamp with time zone) - - cast('1999-12-23 19:59:04.224193 UTC' - as timestamp with time zone) + cast('294276-12-31 23:59:59 UTC' as timestamptz) - + cast('1999-12-23 19:59:04.224193 UTC' as timestamptz) as ok; select - cast('294276-12-31 23:59:59 UTC' - as timestamp with time zone) - - cast('1999-12-23 19:59:04.224192 UTC' - as timestamp with time zone) + cast('294276-12-31 23:59:59 UTC' as timestamptz) - + cast('1999-12-23 19:59:04.224192 UTC' as timestamptz) as overflows; select - to_char( - d1, - 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon' - ) + to_char(d1, 'DAY Day day DY Dy dy MONTH Month month RM MON Mon mon') from timestamptz_tbl; select - to_char( - d1, - 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM' - ) + to_char(d1, 'FMDAY FMDay FMday FMMONTH FMMonth FMmonth FMRM') from timestamptz_tbl; select - to_char( - d1, - 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J' - ) + to_char(d1, 'Y,YYY YYYY YYY YY Y CC Q MM WW DDD DD D J') from timestamptz_tbl; @@ -790,10 +634,7 @@ from select to_char(d1, 'HH HH12 HH24 MI SS SSSS') from timestamptz_tbl; select - to_char( - d1, - '"HH:MI:SS is" HH:MI:SS "\"text between quote marks\""' - ) + to_char(d1, '"HH:MI:SS is" HH:MI:SS "\"text between quote marks\""') from timestamptz_tbl; @@ -812,25 +653,16 @@ from select to_char(d1, 'IYYY IYY IY I IW IDDD ID') from timestamptz_tbl; select - to_char( - d1, - 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID' - ) + to_char(d1, 'FMIYYY FMIYY FMIY FMI FMIW FMIDDD FMID') from timestamptz_tbl; select - to_char( - d, - 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US' - ) + to_char(d, 'FF1 FF2 FF3 FF4 FF5 FF6 ff1 ff2 ff3 ff4 ff5 ff6 MS US') from ( values - ( - cast('2018-11-02 12:34:56' - as timestamp with time zone) - ), + (cast('2018-11-02 12:34:56' as timestamptz)), ('2018-11-02 12:34:56.78'), ('2018-11-02 12:34:56.78901'), ('2018-11-02 12:34:56.78901234') @@ -839,83 +671,83 @@ from set time zone '00:00'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '+02:00'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '-13:00'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '-00:30'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '00:30'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '-04:30'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '04:30'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '-04:15'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; set time zone '04:15'; -select to_char(NOW(), 'OF') as "OF", to_char(NOW(), 'TZH:TZM') as "TZH:TZM"; +select to_char(now(), 'OF') as "OF", to_char(now(), 'TZH:TZM') as "TZH:TZM"; reset timezone; set time zone '00:00'; -select to_char(NOW(), 'of') as "Of", to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as "Of", to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '+02:00'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '-13:00'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '-00:30'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '00:30'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '-04:30'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '04:30'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '-04:15'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; set time zone '04:15'; -select to_char(NOW(), 'of') as of, to_char(NOW(), 'tzh:tzm') as "tzh:tzm"; +select to_char(now(), 'of') as of, to_char(now(), 'tzh:tzm') as "tzh:tzm"; reset timezone; create table timestamptz_tst ( a int, - b timestamp with time zone + b timestamptz ); insert into timestamptz_tst values (1, 'Sat Mar 12 23:58:48 1000 IST'); @@ -963,15 +795,7 @@ as ( ('+10:00:10') ) select - make_timestamptz( - 2010, - 2, - 27, - 3, - 45, - 0, - tz - ), + make_timestamptz(2010, 2, 27, 3, 45, 0, tz), tz from tzs; @@ -983,74 +807,40 @@ select make_timestamptz(2014, 12, 10, 10, 10, 10, '+16'); select make_timestamptz(2014, 12, 10, 10, 10, 10, '-16'); select - make_timestamptz( - 1973, - 7, - 15, - 8, - 15, - 55.33, - '+2' - ) = - cast('1973-07-15 08:15:55.33+02' - as timestamp with time zone); + make_timestamptz(1973, 7, 15, 8, 15, 55.33, '+2') = + cast('1973-07-15 08:15:55.33+02' as timestamptz); + +select + make_timestamptz(2014, 12, 10, 0, 0, 0, 'Europe/Prague') = + cast('2014-12-10 00:00:00 Europe/Prague' as timestamptz); + +select + (make_timestamptz(2014, 12, 10, 0, 0, 0, 'Europe/Prague') at time zone 'UTC'); select - make_timestamptz( - 2014, + (make_timestamptz( + 1881, 12, 10, 0, 0, 0, - 'Europe/Prague' - ) = - cast('2014-12-10 00:00:00 Europe/Prague' - as timestamp with time zone); - -select - timezone( - 'UTC', - make_timestamptz( - 2014, - 12, - 10, - 0, - 0, - 0, - 'Europe/Prague' - ) - ); + 'Asia/Singapore' + ) at time zone 'UTC'); select - timezone( - 'UTC', - make_timestamptz( - 1881, - 12, - 10, - 0, - 0, - 0, - 'Asia/Singapore' - ) - ); + (make_timestamptz( + 1881, + 12, + 10, + 0, + 0, + 0, + 'Pacific/Honolulu' + ) at time zone 'UTC'); select - timezone( - 'UTC', - make_timestamptz( - 1881, - 12, - 10, - 0, - 0, - 0, - 'Pacific/Honolulu' - ) - ); - -select timezone('UTC', make_timestamptz(1881, 12, 10, 0, 0, 0, 'Europe/Paris')); + (make_timestamptz(1881, 12, 10, 0, 0, 0, 'Europe/Paris') at time zone 'UTC'); select make_timestamptz(1910, 12, 24, 0, 0, 0, 'Nehwon/Lankhmar'); @@ -1068,19 +858,15 @@ select * from generate_series( - cast('2020-01-01 00:00' - as timestamp with time zone), - cast('2020-01-02 03:00' - as timestamp with time zone), + cast('2020-01-01 00:00' as timestamptz), + cast('2020-01-02 03:00' as timestamptz), cast('1 hour' as interval) ); select generate_series( - cast('2022-01-01 00:00' - as timestamp with time zone), - cast('infinity' - as timestamp with time zone), + cast('2022-01-01 00:00' as timestamptz), + cast('infinity' as timestamptz), cast('1 month' as interval) ) limit 10; @@ -1089,59 +875,49 @@ select * from generate_series( - cast('2020-01-01 00:00' - as timestamp with time zone), - cast('2020-01-02 03:00' - as timestamp with time zone), + cast('2020-01-01 00:00' as timestamptz), + cast('2020-01-02 03:00' as timestamptz), cast('0 hour' as interval) ); select generate_series( - cast('1995-08-06 12:12:12' - as timestamp with time zone), - cast('1996-08-06 12:12:12' - as timestamp with time zone), + cast('1995-08-06 12:12:12' as timestamptz), + cast('1996-08-06 12:12:12' as timestamptz), cast('infinity' as interval) ); select generate_series( - cast('1995-08-06 12:12:12' - as timestamp with time zone), - cast('1996-08-06 12:12:12' - as timestamp with time zone), + cast('1995-08-06 12:12:12' as timestamptz), + cast('1996-08-06 12:12:12' as timestamptz), cast('-infinity' as interval) ); -set time zone UTC; +set time zone 'UTC'; select date_add( - cast('2022-10-30 00:00:00+01' - as timestamp with time zone), + cast('2022-10-30 00:00:00+01' as timestamptz), cast('1 day' as interval) ); select date_add( - cast('2021-10-31 00:00:00+02' - as timestamp with time zone), + cast('2021-10-31 00:00:00+02' as timestamptz), cast('1 day' as interval), 'Europe/Warsaw' ); select date_subtract( - cast('2022-10-30 00:00:00+01' - as timestamp with time zone), + cast('2022-10-30 00:00:00+01' as timestamptz), cast('1 day' as interval) ); select date_subtract( - cast('2021-10-31 00:00:00+02' - as timestamp with time zone), + cast('2021-10-31 00:00:00+02' as timestamptz), cast('1 day' as interval), 'Europe/Warsaw' ); @@ -1150,129 +926,127 @@ select * from generate_series( - cast('2021-12-31 23:00:00+00' - as timestamp with time zone), - cast('2020-12-31 23:00:00+00' - as timestamp with time zone), + cast('2021-12-31 23:00:00+00' as timestamptz), + cast('2020-12-31 23:00:00+00' as timestamptz), cast('-1 month' as interval), 'Europe/Warsaw' ); reset timezone; -set time zone UTC; +set time zone 'UTC'; -select cast('2011-03-27 00:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 00:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 01:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 01:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 01:59:59 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 01:59:59 Europe/Moscow' as timestamptz); -select cast('2011-03-27 02:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 02:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 02:00:01 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 02:00:01 Europe/Moscow' as timestamptz); -select cast('2011-03-27 02:59:59 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 02:59:59 Europe/Moscow' as timestamptz); -select cast('2011-03-27 03:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 03:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 03:00:01 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 03:00:01 Europe/Moscow' as timestamptz); -select cast('2011-03-27 04:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2011-03-27 04:00:00 Europe/Moscow' as timestamptz); -select cast('2011-03-27 00:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 00:00:00 MSK' as timestamptz); -select cast('2011-03-27 01:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 01:00:00 MSK' as timestamptz); -select cast('2011-03-27 01:59:59 MSK' as timestamp with time zone); +select cast('2011-03-27 01:59:59 MSK' as timestamptz); -select cast('2011-03-27 02:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 02:00:00 MSK' as timestamptz); -select cast('2011-03-27 02:00:01 MSK' as timestamp with time zone); +select cast('2011-03-27 02:00:01 MSK' as timestamptz); -select cast('2011-03-27 02:59:59 MSK' as timestamp with time zone); +select cast('2011-03-27 02:59:59 MSK' as timestamptz); -select cast('2011-03-27 03:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 03:00:00 MSK' as timestamptz); -select cast('2011-03-27 03:00:01 MSK' as timestamp with time zone); +select cast('2011-03-27 03:00:01 MSK' as timestamptz); -select cast('2011-03-27 04:00:00 MSK' as timestamp with time zone); +select cast('2011-03-27 04:00:00 MSK' as timestamptz); -select cast('2014-10-26 00:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 00:00:00 Europe/Moscow' as timestamptz); -select cast('2014-10-26 00:59:59 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 00:59:59 Europe/Moscow' as timestamptz); -select cast('2014-10-26 01:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 01:00:00 Europe/Moscow' as timestamptz); -select cast('2014-10-26 01:00:01 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 01:00:01 Europe/Moscow' as timestamptz); -select cast('2014-10-26 02:00:00 Europe/Moscow' as timestamp with time zone); +select cast('2014-10-26 02:00:00 Europe/Moscow' as timestamptz); -select cast('2014-10-26 00:00:00 MSK' as timestamp with time zone); +select cast('2014-10-26 00:00:00 MSK' as timestamptz); -select cast('2014-10-26 00:59:59 MSK' as timestamp with time zone); +select cast('2014-10-26 00:59:59 MSK' as timestamptz); -select cast('2014-10-26 01:00:00 MSK' as timestamp with time zone); +select cast('2014-10-26 01:00:00 MSK' as timestamptz); -select cast('2014-10-26 01:00:01 MSK' as timestamp with time zone); +select cast('2014-10-26 01:00:01 MSK' as timestamptz); -select cast('2014-10-26 02:00:00 MSK' as timestamp with time zone); +select cast('2014-10-26 02:00:00 MSK' as timestamptz); -select timezone('Europe/Moscow', cast('2011-03-27 00:00:00' as timestamp)); +select (cast('2011-03-27 00:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 01:00:00' as timestamp)); +select (cast('2011-03-27 01:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 01:59:59' as timestamp)); +select (cast('2011-03-27 01:59:59' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 02:00:00' as timestamp)); +select (cast('2011-03-27 02:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 02:00:01' as timestamp)); +select (cast('2011-03-27 02:00:01' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 02:59:59' as timestamp)); +select (cast('2011-03-27 02:59:59' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 03:00:00' as timestamp)); +select (cast('2011-03-27 03:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 03:00:01' as timestamp)); +select (cast('2011-03-27 03:00:01' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2011-03-27 04:00:00' as timestamp)); +select (cast('2011-03-27 04:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('MSK', cast('2011-03-27 00:00:00' as timestamp)); +select (cast('2011-03-27 00:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 01:00:00' as timestamp)); +select (cast('2011-03-27 01:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 01:59:59' as timestamp)); +select (cast('2011-03-27 01:59:59' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 02:00:00' as timestamp)); +select (cast('2011-03-27 02:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 02:00:01' as timestamp)); +select (cast('2011-03-27 02:00:01' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 02:59:59' as timestamp)); +select (cast('2011-03-27 02:59:59' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 03:00:00' as timestamp)); +select (cast('2011-03-27 03:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 03:00:01' as timestamp)); +select (cast('2011-03-27 03:00:01' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2011-03-27 04:00:00' as timestamp)); +select (cast('2011-03-27 04:00:00' as timestamp) at time zone 'MSK'); -select timezone('Europe/Moscow', cast('2014-10-26 00:00:00' as timestamp)); +select (cast('2014-10-26 00:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-26 00:59:59' as timestamp)); +select (cast('2014-10-26 00:59:59' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-26 01:00:00' as timestamp)); +select (cast('2014-10-26 01:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-26 01:00:01' as timestamp)); +select (cast('2014-10-26 01:00:01' as timestamp) at time zone 'Europe/Moscow'); -select timezone('Europe/Moscow', cast('2014-10-26 02:00:00' as timestamp)); +select (cast('2014-10-26 02:00:00' as timestamp) at time zone 'Europe/Moscow'); -select timezone('MSK', cast('2014-10-26 00:00:00' as timestamp)); +select (cast('2014-10-26 00:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-26 00:59:59' as timestamp)); +select (cast('2014-10-26 00:59:59' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-26 01:00:00' as timestamp)); +select (cast('2014-10-26 01:00:00' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-26 01:00:01' as timestamp)); +select (cast('2014-10-26 01:00:01' as timestamp) at time zone 'MSK'); -select timezone('MSK', cast('2014-10-26 02:00:00' as timestamp)); +select (cast('2014-10-26 02:00:00' as timestamp) at time zone 'MSK'); select make_timestamptz(2014, 10, 26, 0, 0, 0, 'MSK'); @@ -1294,199 +1068,91 @@ select to_timestamp(cast('NaN' as double precision)); set time zone 'Europe/Moscow'; -select cast('2011-03-26 21:00:00 UTC' as timestamp with time zone); +select cast('2011-03-26 21:00:00 UTC' as timestamptz); -select cast('2011-03-26 22:00:00 UTC' as timestamp with time zone); +select cast('2011-03-26 22:00:00 UTC' as timestamptz); -select cast('2011-03-26 22:59:59 UTC' as timestamp with time zone); +select cast('2011-03-26 22:59:59 UTC' as timestamptz); -select cast('2011-03-26 23:00:00 UTC' as timestamp with time zone); +select cast('2011-03-26 23:00:00 UTC' as timestamptz); -select cast('2011-03-26 23:00:01 UTC' as timestamp with time zone); +select cast('2011-03-26 23:00:01 UTC' as timestamptz); -select cast('2011-03-26 23:59:59 UTC' as timestamp with time zone); +select cast('2011-03-26 23:59:59 UTC' as timestamptz); -select cast('2011-03-27 00:00:00 UTC' as timestamp with time zone); +select cast('2011-03-27 00:00:00 UTC' as timestamptz); -select cast('2014-10-25 21:00:00 UTC' as timestamp with time zone); +select cast('2014-10-25 21:00:00 UTC' as timestamptz); -select cast('2014-10-25 21:59:59 UTC' as timestamp with time zone); +select cast('2014-10-25 21:59:59 UTC' as timestamptz); -select cast('2014-10-25 22:00:00 UTC' as timestamp with time zone); +select cast('2014-10-25 22:00:00 UTC' as timestamptz); -select cast('2014-10-25 22:00:01 UTC' as timestamp with time zone); +select cast('2014-10-25 22:00:01 UTC' as timestamptz); -select cast('2014-10-25 23:00:00 UTC' as timestamp with time zone); +select cast('2014-10-25 23:00:00 UTC' as timestamptz); reset timezone; select - timezone( - 'Europe/Moscow', - cast('2011-03-26 21:00:00 UTC' - as timestamp with time zone) - ); + (cast('2011-03-26 21:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2011-03-26 22:00:00 UTC' - as timestamp with time zone) - ); + (cast('2011-03-26 22:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2011-03-26 22:59:59 UTC' - as timestamp with time zone) - ); + (cast('2011-03-26 22:59:59 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2011-03-26 23:00:00 UTC' - as timestamp with time zone) - ); + (cast('2011-03-26 23:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2011-03-26 23:00:01 UTC' - as timestamp with time zone) - ); + (cast('2011-03-26 23:00:01 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2011-03-26 23:59:59 UTC' - as timestamp with time zone) - ); + (cast('2011-03-26 23:59:59 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2011-03-27 00:00:00 UTC' - as timestamp with time zone) - ); + (cast('2011-03-27 00:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2014-10-25 21:00:00 UTC' - as timestamp with time zone) - ); + (cast('2014-10-25 21:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2014-10-25 21:59:59 UTC' - as timestamp with time zone) - ); + (cast('2014-10-25 21:59:59 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2014-10-25 22:00:00 UTC' - as timestamp with time zone) - ); + (cast('2014-10-25 22:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2014-10-25 22:00:01 UTC' - as timestamp with time zone) - ); + (cast('2014-10-25 22:00:01 UTC' as timestamptz) at time zone 'Europe/Moscow'); select - timezone( - 'Europe/Moscow', - cast('2014-10-25 23:00:00 UTC' - as timestamp with time zone) - ); + (cast('2014-10-25 23:00:00 UTC' as timestamptz) at time zone 'Europe/Moscow'); -select - timezone( - 'MSK', - cast('2011-03-26 21:00:00 UTC' - as timestamp with time zone) - ); +select (cast('2011-03-26 21:00:00 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2011-03-26 22:00:00 UTC' - as timestamp with time zone) - ); +select (cast('2011-03-26 22:00:00 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2011-03-26 22:59:59 UTC' - as timestamp with time zone) - ); +select (cast('2011-03-26 22:59:59 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2011-03-26 23:00:00 UTC' - as timestamp with time zone) - ); +select (cast('2011-03-26 23:00:00 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2011-03-26 23:00:01 UTC' - as timestamp with time zone) - ); +select (cast('2011-03-26 23:00:01 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2011-03-26 23:59:59 UTC' - as timestamp with time zone) - ); +select (cast('2011-03-26 23:59:59 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2011-03-27 00:00:00 UTC' - as timestamp with time zone) - ); +select (cast('2011-03-27 00:00:00 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2014-10-25 21:00:00 UTC' - as timestamp with time zone) - ); +select (cast('2014-10-25 21:00:00 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2014-10-25 21:59:59 UTC' - as timestamp with time zone) - ); +select (cast('2014-10-25 21:59:59 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2014-10-25 22:00:00 UTC' - as timestamp with time zone) - ); +select (cast('2014-10-25 22:00:00 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2014-10-25 22:00:01 UTC' - as timestamp with time zone) - ); +select (cast('2014-10-25 22:00:01 UTC' as timestamptz) at time zone 'MSK'); -select - timezone( - 'MSK', - cast('2014-10-25 23:00:00 UTC' - as timestamp with time zone) - ); +select (cast('2014-10-25 23:00:00 UTC' as timestamptz) at time zone 'MSK'); begin; @@ -1494,48 +1160,35 @@ set local time zone 'Europe/Paris'; values ( - timezone( - cast('1978-07-07 19:38 America/New_York' - as timestamp with time zone) - ) + (cast('1978-07-07 19:38 America/New_York' + as timestamp with time zone) at local) ); -values (timezone(cast('1978-07-07 19:38' as timestamp))); +values ((cast('1978-07-07 19:38' as timestamp) at local)); set local time zone 'Australia/Sydney'; values ( - timezone( - cast('1978-07-07 19:38 America/New_York' - as timestamp with time zone) - ) + (cast('1978-07-07 19:38 America/New_York' + as timestamp with time zone) at local) ); -values (timezone(cast('1978-07-07 19:38' as timestamp))); +values ((cast('1978-07-07 19:38' as timestamp) at local)); -set local time zone UTC; +set local time zone 'UTC'; create view timestamp_local_view as select - timezone( - cast('1978-07-07 19:38 America/New_York' - as timestamp with time zone) - ) + (cast('1978-07-07 19:38 America/New_York' + as timestamp with time zone) at local) as ttz_at_local, timezone( - cast('1978-07-07 19:38 America/New_York' - as timestamp with time zone) + cast('1978-07-07 19:38 America/New_York' as timestamp with time zone) ) as ttz_func, - timezone( - cast('1978-07-07 19:38' as timestamp) - ) - as t_at_local, - timezone( - cast('1978-07-07 19:38' as timestamp) - ) - as t_func; + (cast('1978-07-07 19:38' as timestamp) at local) as t_at_local, + timezone(cast('1978-07-07 19:38' as timestamp)) as t_func; select pg_get_viewdef('timestamp_local_view', true); @@ -1545,86 +1198,40 @@ drop view timestamp_local_view; commit; -create temporary table tmptz (f1 timestamp with time zone primary key); +create temporary table tmptz (f1 timestamptz primary key); insert into tmptz values ('2017-01-18 00:00+00'); -select * from tmptz where timezone('utc', f1) = '2017-01-18 00:00'; +select * from tmptz where (f1 at time zone 'utc') = '2017-01-18 00:00'; -select * from tmptz where timezone('utc', f1) = '2017-01-18 00:00'; +select * from tmptz where (f1 at time zone 'utc') = '2017-01-18 00:00'; -select - cast('infinity' - as timestamp with time zone) - - cast('infinity' - as timestamp with time zone); +select cast('infinity' as timestamptz) - cast('infinity' as timestamptz); -select - cast('infinity' - as timestamp with time zone) - - cast('-infinity' - as timestamp with time zone); +select cast('infinity' as timestamptz) - cast('-infinity' as timestamptz); -select - cast('-infinity' - as timestamp with time zone) - - cast('infinity' - as timestamp with time zone); +select cast('-infinity' as timestamptz) - cast('infinity' as timestamptz); -select - cast('-infinity' - as timestamp with time zone) - - cast('-infinity' - as timestamp with time zone); +select cast('-infinity' as timestamptz) - cast('-infinity' as timestamptz); select - cast('infinity' - as timestamp with time zone) - - cast('1995-08-06 12:12:12' - as timestamp with time zone); + cast('infinity' as timestamptz) - cast('1995-08-06 12:12:12' as timestamptz); select - cast('-infinity' - as timestamp with time zone) - - cast('1995-08-06 12:12:12' - as timestamp with time zone); + cast('-infinity' as timestamptz) - cast('1995-08-06 12:12:12' as timestamptz); -select age(cast('infinity' as timestamp with time zone)); +select age(cast('infinity' as timestamptz)); -select age(cast('-infinity' as timestamp with time zone)); +select age(cast('-infinity' as timestamptz)); -select - age( - cast('infinity' - as timestamp with time zone), - cast('infinity' - as timestamp with time zone) - ); +select age(cast('infinity' as timestamptz), cast('infinity' as timestamptz)); -select - age( - cast('infinity' - as timestamp with time zone), - cast('-infinity' - as timestamp with time zone) - ); +select age(cast('infinity' as timestamptz), cast('-infinity' as timestamptz)); -select - age( - cast('-infinity' - as timestamp with time zone), - cast('infinity' - as timestamp with time zone) - ); +select age(cast('-infinity' as timestamptz), cast('infinity' as timestamptz)); -select - age( - cast('-infinity' - as timestamp with time zone), - cast('-infinity' - as timestamp with time zone) - ); +select age(cast('-infinity' as timestamptz), cast('-infinity' as timestamptz)); -select cast('1999-12-31 24:00:00' as timestamp with time zone); +select cast('1999-12-31 24:00:00' as timestamptz); select make_timestamptz(1999, 12, 31, 24, 0, 0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timetz_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timetz_100.snap index 2056e75e7..ac7ef2e79 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timetz_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timetz_100.snap @@ -45,21 +45,21 @@ select f1 as "None" from timetz_tbl where f1 < '00:00-07'; select f1 as "Ten" from timetz_tbl where f1 >= '00:00-07'; -select cast('23:59:59.999999 PDT' as time with time zone); +select cast('23:59:59.999999 PDT' as timetz); -select cast('23:59:59.9999999 PDT' as time with time zone); +select cast('23:59:59.9999999 PDT' as timetz); -select cast('23:59:60 PDT' as time with time zone); +select cast('23:59:60 PDT' as timetz); -select cast('24:00:00 PDT' as time with time zone); +select cast('24:00:00 PDT' as timetz); -select cast('24:00:00.01 PDT' as time with time zone); +select cast('24:00:00.01 PDT' as timetz); -select cast('23:59:60.01 PDT' as time with time zone); +select cast('23:59:60.01 PDT' as timetz); -select cast('24:01:00 PDT' as time with time zone); +select cast('24:01:00 PDT' as timetz); -select cast('25:00:00 PDT' as time with time zone); +select cast('25:00:00 PDT' as timetz); select pg_input_is_valid('12:00:00 PDT', 'timetz'); @@ -73,31 +73,28 @@ select * from pg_input_error_info('15:36:39 America/New_York', 'timetz'); select f1 + cast('00:01' as time with time zone) as "Illegal" from timetz_tbl; -select EXTRACT('microsecond' from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); +select extract(microsecond from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); -select EXTRACT('millisecond' from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); +select extract(millisecond from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); -select EXTRACT('second' from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); +select extract(second from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); -select EXTRACT('minute' from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); +select extract(minute from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); -select EXTRACT('hour' from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); +select extract(hour from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); -select EXTRACT('day' from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); +select extract(day from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); -select EXTRACT('fortnight' from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); +select extract(fortnight from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); -select EXTRACT('timezone' from cast('2020-05-26 13:30:25.575401-04:30' as time with time zone)); +select extract(timezone from cast('2020-05-26 13:30:25.575401-04:30' as time with time zone)); -select - EXTRACT('timezone_hour' from cast('2020-05-26 13:30:25.575401-04:30' - as time with time zone)); +select extract(timezone_hour from cast('2020-05-26 13:30:25.575401-04:30' as time with time zone)); select - EXTRACT('timezone_minute' from cast('2020-05-26 13:30:25.575401-04:30' - as time with time zone)); + extract(timezone_minute from cast('2020-05-26 13:30:25.575401-04:30' as time with time zone)); -select EXTRACT('epoch' from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); +select extract(epoch from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select date_part('microsecond', cast('2020-05-26 13:30:25.575401-04' as time with time zone)); @@ -109,17 +106,15 @@ select date_part('epoch', cast('2020-05-26 13:30:25.575401-04' as time with time begin; -set local time zone UTC; +set local time zone 'UTC'; create view timetz_local_view as select f1 as dat, timezone(f1) as dat_func, - timezone(f1) as dat_at_local, - timezone(current_setting('TimeZone'), f1) - as dat_at_tz, - timezone(cast('00:00' as interval), f1) - as dat_at_int + (f1 at local) as dat_at_local, + (f1 at time zone current_setting('TimeZone')) as dat_at_tz, + (f1 at time zone cast('00:00' as interval)) as dat_at_int from timetz_tbl order by f1; @@ -130,9 +125,8 @@ select * from timetz_local_view; select f1 as dat, - timezone('UTC+10', f1) as dat_at_tz, - timezone(cast('-10:00' as interval), f1) - as dat_at_int + (f1 at time zone 'UTC+10') as dat_at_tz, + (f1 at time zone cast('-10:00' as interval)) as dat_at_int from timetz_tbl order by f1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timetz_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timetz_80.snap index fdd43117a..6ce8a2f8b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__timetz_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__timetz_80.snap @@ -45,21 +45,21 @@ select f1 as "None" from timetz_tbl where f1 < '00:00-07'; select f1 as "Ten" from timetz_tbl where f1 >= '00:00-07'; -select cast('23:59:59.999999 PDT' as time with time zone); +select cast('23:59:59.999999 PDT' as timetz); -select cast('23:59:59.9999999 PDT' as time with time zone); +select cast('23:59:59.9999999 PDT' as timetz); -select cast('23:59:60 PDT' as time with time zone); +select cast('23:59:60 PDT' as timetz); -select cast('24:00:00 PDT' as time with time zone); +select cast('24:00:00 PDT' as timetz); -select cast('24:00:00.01 PDT' as time with time zone); +select cast('24:00:00.01 PDT' as timetz); -select cast('23:59:60.01 PDT' as time with time zone); +select cast('23:59:60.01 PDT' as timetz); -select cast('24:01:00 PDT' as time with time zone); +select cast('24:01:00 PDT' as timetz); -select cast('25:00:00 PDT' as time with time zone); +select cast('25:00:00 PDT' as timetz); select pg_input_is_valid('12:00:00 PDT', 'timetz'); @@ -74,93 +74,84 @@ select * from pg_input_error_info('15:36:39 America/New_York', 'timetz'); select f1 + cast('00:01' as time with time zone) as "Illegal" from timetz_tbl; select - EXTRACT('microsecond' from cast('2020-05-26 13:30:25.575401-04' + extract(microsecond from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select - EXTRACT('millisecond' from cast('2020-05-26 13:30:25.575401-04' + extract(millisecond from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select - EXTRACT('second' from cast('2020-05-26 13:30:25.575401-04' + extract(second from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select - EXTRACT('minute' from cast('2020-05-26 13:30:25.575401-04' + extract(minute from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select - EXTRACT('hour' from cast('2020-05-26 13:30:25.575401-04' + extract(hour from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select - EXTRACT('day' from cast('2020-05-26 13:30:25.575401-04' + extract(day from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select - EXTRACT('fortnight' from cast('2020-05-26 13:30:25.575401-04' + extract(fortnight from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select - EXTRACT('timezone' from cast('2020-05-26 13:30:25.575401-04:30' + extract(timezone from cast('2020-05-26 13:30:25.575401-04:30' as time with time zone)); select - EXTRACT('timezone_hour' from cast('2020-05-26 13:30:25.575401-04:30' + extract(timezone_hour from cast('2020-05-26 13:30:25.575401-04:30' as time with time zone)); select - EXTRACT('timezone_minute' from cast('2020-05-26 13:30:25.575401-04:30' + extract(timezone_minute from cast('2020-05-26 13:30:25.575401-04:30' as time with time zone)); select - EXTRACT('epoch' from cast('2020-05-26 13:30:25.575401-04' + extract(epoch from cast('2020-05-26 13:30:25.575401-04' as time with time zone)); select date_part( 'microsecond', - cast('2020-05-26 13:30:25.575401-04' - as time with time zone) + cast('2020-05-26 13:30:25.575401-04' as time with time zone) ); select date_part( 'millisecond', - cast('2020-05-26 13:30:25.575401-04' - as time with time zone) + cast('2020-05-26 13:30:25.575401-04' as time with time zone) ); select date_part( 'second', - cast('2020-05-26 13:30:25.575401-04' - as time with time zone) + cast('2020-05-26 13:30:25.575401-04' as time with time zone) ); select date_part( 'epoch', - cast('2020-05-26 13:30:25.575401-04' - as time with time zone) + cast('2020-05-26 13:30:25.575401-04' as time with time zone) ); begin; -set local time zone UTC; +set local time zone 'UTC'; create view timetz_local_view as select f1 as dat, timezone(f1) as dat_func, - timezone(f1) as dat_at_local, - timezone( - current_setting('TimeZone'), - f1 - ) - as dat_at_tz, - timezone(cast('00:00' as interval), f1) - as dat_at_int + (f1 at local) as dat_at_local, + (f1 at time zone current_setting('TimeZone')) as dat_at_tz, + (f1 at time zone cast('00:00' as interval)) as dat_at_int from timetz_tbl order by f1; @@ -171,9 +162,8 @@ select * from timetz_local_view; select f1 as dat, - timezone('UTC+10', f1) as dat_at_tz, - timezone(cast('-10:00' as interval), f1) - as dat_at_int + (f1 at time zone 'UTC+10') as dat_at_tz, + (f1 at time zone cast('-10:00' as interval)) as dat_at_int from timetz_tbl order by f1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_100.snap index 7ff4f5111..f31005214 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_100.snap @@ -19,7 +19,7 @@ select a from xacttest where a > 100; begin; -create table disappear (a int); +create table disappear (a int4); delete from xacttest; @@ -33,7 +33,7 @@ select * from xacttest; begin isolation level serializable; -select COUNT(*) from xacttest; +select count(*) from xacttest; reset transaction_isolation; @@ -41,7 +41,7 @@ commit; begin read only; -select COUNT(*) from xacttest; +select count(*) from xacttest; reset transaction_read_only; @@ -49,7 +49,7 @@ commit; begin deferrable; -select COUNT(*) from xacttest; +select count(*) from xacttest; reset transaction_deferrable; @@ -59,9 +59,7 @@ create function errfunc() returns int language sql set transaction_read_only = 'on' -as $function$ -SELECT 1 -$function$; +as 'SELECT 1'; create table writetest (a int); @@ -69,81 +67,81 @@ create temporary table temptest (a int); begin; -set TRANSACTION isolation level serializable read only deferrable; +set transaction isolation level serializable read only deferrable; select * from writetest; -set TRANSACTION read write; +set transaction read write; commit; begin; -set TRANSACTION read only; +set transaction read only; -set TRANSACTION read write; +set transaction read write; -set TRANSACTION read only; +set transaction read only; select * from writetest; savepoint x; -set TRANSACTION read only; +set transaction read only; select * from writetest; -set TRANSACTION read only; +set transaction read only; -set TRANSACTION read write; +set transaction read write; commit; begin; -set TRANSACTION read write; +set transaction read write; savepoint x; -set TRANSACTION read write; +set transaction read write; -set TRANSACTION read only; +set transaction read only; select * from writetest; -set TRANSACTION read only; +set transaction read only; -set TRANSACTION read write; +set transaction read write; commit; begin; -set TRANSACTION read write; +set transaction read write; savepoint x; -set TRANSACTION read only; +set transaction read only; select * from writetest; rollback to savepoint x; -show "transaction_read_only"; +show transaction_read_only; savepoint y; -set TRANSACTION read only; +set transaction read only; select * from writetest; release savepoint y; -show "transaction_read_only"; +show transaction_read_only; commit; -set session CHARACTERISTICS as transaction read only; +set session characteristics as transaction read only; drop table writetest; @@ -169,7 +167,7 @@ drop table writetest; commit; -set session CHARACTERISTICS as transaction read write; +set session characteristics as transaction read write; create table trans_foobar (a int); @@ -431,7 +429,7 @@ select 1; begin; -declare "c" cursor for select unique2 from tenk1 order by unique2;; +declare c cursor for select unique2 from tenk1 order by unique2;; savepoint one; @@ -447,7 +445,7 @@ fetch forward 10 from c; close c; -declare "c" cursor for select unique2 / 0 from tenk1 order by unique2;; +declare c cursor for select unique2 / 0 from tenk1 order by unique2;; savepoint two; @@ -471,9 +469,7 @@ create or replace function max_xacttest() returns smallint language sql stable -as $function$ -select max(a) from xacttest -$function$; +as 'select max(a) from xacttest'; begin; @@ -487,9 +483,7 @@ create or replace function max_xacttest() returns smallint language sql volatile -as $function$ -select max(a) from xacttest -$function$; +as 'select max(a) from xacttest'; begin; @@ -503,9 +497,7 @@ create or replace function max_xacttest() returns smallint language plpgsql stable -as $function$ -begin return max(a) from xacttest; end -$function$; +as 'begin return max(a) from xacttest; end'; begin; @@ -519,9 +511,7 @@ create or replace function max_xacttest() returns smallint language plpgsql volatile -as $function$ -begin return max(a) from xacttest; end -$function$; +as 'begin return max(a) from xacttest; end'; begin; @@ -558,19 +548,18 @@ drop table trans_baz; drop table trans_barbaz; create function inverse(int) -returns double precision +returns float8 language plpgsql volatile -as $function$ +as $$ begin analyze revalidate_bug; return 1::float8/$1; exception when division_by_zero then return 0; -end -$function$; +end$$; -create table revalidate_bug (c double precision unique); +create table revalidate_bug (c float8 unique); insert into revalidate_bug values (1); @@ -590,7 +579,7 @@ insert into trans_abc values (5); insert into trans_abc values (10); -declare "foo" cursor for select * from trans_abc;; +declare foo cursor for select * from trans_abc;; fetch next from foo; @@ -610,7 +599,7 @@ insert into trans_abc values (10); insert into trans_abc values (15); -declare "foo" cursor for select * from trans_abc;; +declare foo cursor for select * from trans_abc;; fetch next from foo; @@ -624,31 +613,28 @@ fetch next from foo; rollback; -create function invert(x double precision) -returns double precision +create function invert(x float8) +returns float8 language plpgsql -as $function$ -begin return 1/x; end -$function$; +as $$ begin return 1/x; end $$; create function create_temp_tab() returns text language plpgsql -as $function$ +as $$ BEGIN CREATE TEMP TABLE new_table (f1 float8); -- case of interest is that we fail while holding an open -- relcache reference to new_table INSERT INTO new_table SELECT invert(0.0); RETURN 'foo'; -END -$function$; +END $$; begin; -declare "ok" cursor for select * from int8_tbl;; +declare ok cursor for select * from int8_tbl;; -declare "ctt" cursor for select create_temp_tab();; +declare ctt cursor for select create_temp_tab();; fetch next from ok; @@ -668,7 +654,7 @@ commit; drop function create_temp_tab(); -drop function invert(double precision); +drop function invert(x float8); create table trans_abc (a int); @@ -676,11 +662,11 @@ set default_transaction_read_only = 'on'; start transaction isolation level repeatable read read write deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values (1); @@ -688,11 +674,11 @@ insert into trans_abc values (2); commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values ('error'); @@ -700,11 +686,11 @@ insert into trans_abc values (3); commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values (4); @@ -712,11 +698,11 @@ commit; start transaction isolation level repeatable read read write deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; savepoint x; @@ -724,11 +710,11 @@ insert into trans_abc values ('error'); commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values (5); @@ -736,71 +722,71 @@ commit; start transaction isolation level repeatable read read write deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; savepoint x; commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; commit; start transaction isolation level read committed read write deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; savepoint x; commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; commit; start transaction isolation level serializable read write not deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values (6); rollback and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values ('error'); rollback and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; rollback; @@ -866,11 +852,11 @@ commit; commit and chain; -show "transaction_read_only"; +show transaction_read_only; rollback and chain; -show "transaction_read_only"; +show transaction_read_only; create table trans_abc (a int); @@ -884,13 +870,13 @@ rollback; commit and chain; -show "transaction_isolation"; +show transaction_isolation; commit; rollback and chain; -show "transaction_isolation"; +show transaction_isolation; rollback; @@ -898,11 +884,11 @@ set default_transaction_isolation = 'read committed'; commit and chain; -show "transaction_isolation"; +show transaction_isolation; rollback and chain; -show "transaction_isolation"; +show transaction_isolation; reset default_transaction_isolation; @@ -912,13 +898,13 @@ drop table trans_abc; begin isolation level repeatable read; -set transaction SNAPSHOT 'Incorrect Identifier'; +set transaction snapshot 'Incorrect Identifier'; rollback; begin isolation level repeatable read; -set transaction SNAPSHOT 'FFF-FFF-F'; +set transaction snapshot 'FFF-FFF-F'; rollback; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_80.snap index 357bb6275..47053da0e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_80.snap @@ -10,11 +10,7 @@ create table xacttest ( ); insert into xacttest -values - (56, 7.8), - (100, 99.097), - (0, 0.09561), - (42, 324.78); +values (56, 7.8), (100, 99.097), (0, 0.09561), (42, 324.78); insert into xacttest (a, b) values (777, 777.777); @@ -24,7 +20,7 @@ select a from xacttest where a > 100; begin; -create table disappear (a int); +create table disappear (a int4); delete from xacttest; @@ -38,7 +34,7 @@ select * from xacttest; begin isolation level serializable; -select COUNT(*) from xacttest; +select count(*) from xacttest; reset transaction_isolation; @@ -46,7 +42,7 @@ commit; begin read only; -select COUNT(*) from xacttest; +select count(*) from xacttest; reset transaction_read_only; @@ -54,7 +50,7 @@ commit; begin deferrable; -select COUNT(*) from xacttest; +select count(*) from xacttest; reset transaction_deferrable; @@ -64,9 +60,7 @@ create function errfunc() returns int language sql set transaction_read_only = 'on' -as $function$ -SELECT 1 -$function$; +as 'SELECT 1'; create table writetest (a int); @@ -74,81 +68,81 @@ create temporary table temptest (a int); begin; -set TRANSACTION isolation level serializable read only deferrable; +set transaction isolation level serializable read only deferrable; select * from writetest; -set TRANSACTION read write; +set transaction read write; commit; begin; -set TRANSACTION read only; +set transaction read only; -set TRANSACTION read write; +set transaction read write; -set TRANSACTION read only; +set transaction read only; select * from writetest; savepoint x; -set TRANSACTION read only; +set transaction read only; select * from writetest; -set TRANSACTION read only; +set transaction read only; -set TRANSACTION read write; +set transaction read write; commit; begin; -set TRANSACTION read write; +set transaction read write; savepoint x; -set TRANSACTION read write; +set transaction read write; -set TRANSACTION read only; +set transaction read only; select * from writetest; -set TRANSACTION read only; +set transaction read only; -set TRANSACTION read write; +set transaction read write; commit; begin; -set TRANSACTION read write; +set transaction read write; savepoint x; -set TRANSACTION read only; +set transaction read only; select * from writetest; rollback to savepoint x; -show "transaction_read_only"; +show transaction_read_only; savepoint y; -set TRANSACTION read only; +set transaction read only; select * from writetest; release savepoint y; -show "transaction_read_only"; +show transaction_read_only; commit; -set session CHARACTERISTICS as transaction read only; +set session characteristics as transaction read only; drop table writetest; @@ -162,8 +156,7 @@ update temptest set a = 0 from writetest where - temptest.a = 1 and - writetest.a = temptest.a; + temptest.a = 1 and writetest.a = temptest.a; update writetest set a = 0; @@ -179,7 +172,7 @@ drop table writetest; commit; -set session CHARACTERISTICS as transaction read write; +set session characteristics as transaction read write; create table trans_foobar (a int); @@ -459,7 +452,7 @@ select 1; begin; -declare "c" cursor for select unique2 from tenk1 order by unique2;; +declare c cursor for select unique2 from tenk1 order by unique2;; savepoint one; @@ -475,7 +468,7 @@ fetch forward 10 from c; close c; -declare "c" cursor for select unique2 / 0 from tenk1 order by unique2;; +declare c cursor for select unique2 / 0 from tenk1 order by unique2;; savepoint two; @@ -499,9 +492,7 @@ create or replace function max_xacttest() returns smallint language sql stable -as $function$ -select max(a) from xacttest -$function$; +as 'select max(a) from xacttest'; begin; @@ -515,9 +506,7 @@ create or replace function max_xacttest() returns smallint language sql volatile -as $function$ -select max(a) from xacttest -$function$; +as 'select max(a) from xacttest'; begin; @@ -531,9 +520,7 @@ create or replace function max_xacttest() returns smallint language plpgsql stable -as $function$ -begin return max(a) from xacttest; end -$function$; +as 'begin return max(a) from xacttest; end'; begin; @@ -547,9 +534,7 @@ create or replace function max_xacttest() returns smallint language plpgsql volatile -as $function$ -begin return max(a) from xacttest; end -$function$; +as 'begin return max(a) from xacttest; end'; begin; @@ -586,19 +571,18 @@ drop table trans_baz; drop table trans_barbaz; create function inverse(int) -returns double precision +returns float8 language plpgsql volatile -as $function$ +as $$ begin analyze revalidate_bug; return 1::float8/$1; exception when division_by_zero then return 0; -end -$function$; +end$$; -create table revalidate_bug (c double precision unique); +create table revalidate_bug (c float8 unique); insert into revalidate_bug values (1); @@ -618,7 +602,7 @@ insert into trans_abc values (5); insert into trans_abc values (10); -declare "foo" cursor for select * from trans_abc;; +declare foo cursor for select * from trans_abc;; fetch next from foo; @@ -638,7 +622,7 @@ insert into trans_abc values (10); insert into trans_abc values (15); -declare "foo" cursor for select * from trans_abc;; +declare foo cursor for select * from trans_abc;; fetch next from foo; @@ -652,31 +636,28 @@ fetch next from foo; rollback; -create function invert(x double precision) -returns double precision +create function invert(x float8) +returns float8 language plpgsql -as $function$ -begin return 1/x; end -$function$; +as $$ begin return 1/x; end $$; create function create_temp_tab() returns text language plpgsql -as $function$ +as $$ BEGIN CREATE TEMP TABLE new_table (f1 float8); -- case of interest is that we fail while holding an open -- relcache reference to new_table INSERT INTO new_table SELECT invert(0.0); RETURN 'foo'; -END -$function$; +END $$; begin; -declare "ok" cursor for select * from int8_tbl;; +declare ok cursor for select * from int8_tbl;; -declare "ctt" cursor for select create_temp_tab();; +declare ctt cursor for select create_temp_tab();; fetch next from ok; @@ -696,7 +677,7 @@ commit; drop function create_temp_tab(); -drop function invert(double precision); +drop function invert(x float8); create table trans_abc (a int); @@ -704,11 +685,11 @@ set default_transaction_read_only = 'on'; start transaction isolation level repeatable read read write deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values (1); @@ -716,11 +697,11 @@ insert into trans_abc values (2); commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values ('error'); @@ -728,11 +709,11 @@ insert into trans_abc values (3); commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values (4); @@ -740,11 +721,11 @@ commit; start transaction isolation level repeatable read read write deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; savepoint x; @@ -752,11 +733,11 @@ insert into trans_abc values ('error'); commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values (5); @@ -764,71 +745,71 @@ commit; start transaction isolation level repeatable read read write deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; savepoint x; commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; commit; start transaction isolation level read committed read write deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; savepoint x; commit and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; commit; start transaction isolation level serializable read write not deferrable; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values (6); rollback and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; insert into trans_abc values ('error'); rollback and chain; -show "transaction_isolation"; +show transaction_isolation; -show "transaction_read_only"; +show transaction_read_only; -show "transaction_deferrable"; +show transaction_deferrable; rollback; @@ -894,11 +875,11 @@ commit; commit and chain; -show "transaction_read_only"; +show transaction_read_only; rollback and chain; -show "transaction_read_only"; +show transaction_read_only; create table trans_abc (a int); @@ -912,13 +893,13 @@ rollback; commit and chain; -show "transaction_isolation"; +show transaction_isolation; commit; rollback and chain; -show "transaction_isolation"; +show transaction_isolation; rollback; @@ -926,11 +907,11 @@ set default_transaction_isolation = 'read committed'; commit and chain; -show "transaction_isolation"; +show transaction_isolation; rollback and chain; -show "transaction_isolation"; +show transaction_isolation; reset default_transaction_isolation; @@ -940,13 +921,13 @@ drop table trans_abc; begin isolation level repeatable read; -set transaction SNAPSHOT 'Incorrect Identifier'; +set transaction snapshot 'Incorrect Identifier'; rollback; begin isolation level repeatable read; -set transaction SNAPSHOT 'FFF-FFF-F'; +set transaction snapshot 'FFF-FFF-F'; rollback; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_100.snap index 76000f978..670c10b77 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_100.snap @@ -5,9 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/triggers.sql create function trigger_return_old() returns trigger language c -as $function$ -regresslib -$function$; +as 'regresslib'; create table trigtest ( f1 int, @@ -35,9 +33,7 @@ select * from trigtest; create function f1_times_10() returns trigger language plpgsql -as $function$ -begin new.f1 := new.f1 * 10; return new; end -$function$; +as $$ begin new.f1 := new.f1 * 10; return new; end $$; create trigger trigger_alpha before insert or update @@ -93,7 +89,7 @@ drop table trigtest; create table trigtest ( a int, - b boolean default true not null, + b bool default true not null, c text default 'xyzzy' not null ); @@ -137,12 +133,11 @@ create table main_table ( create function trigger_func() returns trigger language plpgsql -as $function$ +as ' BEGIN - RAISE NOTICE 'trigger_func(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL; + RAISE NOTICE ''trigger_func(%) called: action = %, when = %, level = %'', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL; RETURN NULL; -END; -$function$; +END;'; create trigger before_ins_stmt_trig before insert @@ -260,42 +255,37 @@ select from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_a'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_a'; select pg_get_triggerdef(oid, false) from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_a'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_a'; select pg_get_triggerdef(oid, true) from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_any'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_any'; alter trigger modified_a on main_table rename to modified_modified_a; select - COUNT(*) + count(*) from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_a'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_a'; select - COUNT(*) + count(*) from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_modified_a'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_modified_a'; drop trigger modified_modified_a on main_table; @@ -362,8 +352,7 @@ select from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'after_upd_a_b_row_trig'; + tgrelid = cast('main_table' as regclass) and tgname = 'after_upd_a_b_row_trig'; update main_table set a = 50; @@ -374,13 +363,13 @@ create table some_t (some_col boolean not null); create function dummy_update_func() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'dummy_update_func(%) called: action = %, old = %, new = %', TG_ARGV[0], TG_OP, OLD, NEW; RETURN NEW; END; -$function$; +$$; create trigger some_trig_before before update @@ -465,17 +454,16 @@ rollback; create table trigtest (i serial primary key); -create table trigtest2 (i int references trigtest (i) on DELETE cascade); +create table trigtest2 (i int references trigtest (i) on delete cascade); create function trigtest() returns trigger language plpgsql -as $function$ +as $$ begin raise notice '% % % %', TG_TABLE_NAME, TG_OP, TG_WHEN, TG_LEVEL; return new; -end; -$function$; +end;$$; create trigger trigtest_b_row_tg before insert or delete or update @@ -560,7 +548,8 @@ create table trigger_test ( create or replace function trigger_data() returns trigger language plpgsql -as $function$ +as $$ + declare argstr text; @@ -608,7 +597,7 @@ begin end if; end; -$function$; +$$; create trigger show_trigger_data_trig before insert or delete or update @@ -638,7 +627,7 @@ create table trigger_test ( create function mytrigger() returns trigger language plpgsql -as $function$ +as $$ begin if row(old.*) = row(new.*) then raise notice 'row % not changed', new.f1; @@ -646,8 +635,7 @@ begin raise notice 'row % changed', new.f1; end if; return new; -end -$function$; +end$$; create trigger t before update on trigger_test for each row execute function mytrigger(); @@ -664,7 +652,7 @@ update trigger_test set f3 = null; create or replace function mytrigger() returns trigger language plpgsql -as $function$ +as $$ begin if row(old.*) is distinct from row(new.*) then raise notice 'row % changed', new.f1; @@ -672,8 +660,7 @@ begin raise notice 'row % not changed', new.f1; end if; return new; -end -$function$; +end$$; update trigger_test set f3 = 'bar'; @@ -688,14 +675,14 @@ drop function mytrigger(); create function serializable_update_trig() returns trigger language plpgsql -as $function$ +as $$ declare rec record; begin new.description = 'updated in trigger'; return new; end; -$function$; +$$; create table serializable_update_tab ( id int, @@ -710,16 +697,11 @@ for each row execute function serializable_update_trig(); insert into serializable_update_tab -select - a, - repeat('xyzxz', 100), - 'new' -from - generate_series(1, 50) as a; +select a, repeat('xyzxz', 100), 'new' from generate_series(1, 50) as a; begin; -set TRANSACTION isolation level serializable; +set transaction isolation level serializable; update serializable_update_tab set description = 'no no', id = 1 where id = 1; @@ -759,7 +741,7 @@ as select a, b from main_table; create or replace function view_trigger() returns trigger language plpgsql -as $function$ +as $$ declare argstr text := ''; begin @@ -796,7 +778,7 @@ begin RETURN NULL; end; -$function$; +$$; create trigger invalid_trig before insert @@ -970,10 +952,7 @@ create table country_table ( ); insert into country_table (country_name, continent) -values - ('Japan', 'Asia'), - ('UK', 'Europe'), - ('USA', 'North America') +values ('Japan', 'Asia'), ('UK', 'Europe'), ('USA', 'North America') returning *; create table city_table ( @@ -991,15 +970,12 @@ as select country_name, continent from - city_table as ci - left outer join - country_table as co - on co.country_id = ci.country_id; + city_table as ci left outer join country_table as co on co.country_id = ci.country_id; create function city_insert() returns trigger language plpgsql -as $function$ +as $$ declare ctry_id int; begin @@ -1024,7 +1000,7 @@ begin RETURN NEW; end; -$function$; +$$; create trigger city_insert_trig instead of insert @@ -1035,13 +1011,13 @@ execute function city_insert(); create function city_delete() returns trigger language plpgsql -as $function$ +as $$ begin DELETE FROM city_table WHERE city_id = OLD.city_id; if NOT FOUND then RETURN NULL; end if; RETURN OLD; end; -$function$; +$$; create trigger city_delete_trig instead of delete @@ -1052,7 +1028,7 @@ execute function city_delete(); create function city_update() returns trigger language plpgsql -as $function$ +as $$ declare ctry_id int; begin @@ -1077,7 +1053,7 @@ begin if NOT FOUND then RETURN NULL; end if; RETURN NEW; end; -$function$; +$$; create trigger city_update_trig instead of update @@ -1118,8 +1094,7 @@ update city_view as v1 set country_name = v2.country_name from city_view as v2 where - v2.city_name = 'Birmingham' and - v1.city_name = 'London' + v2.city_name = 'Birmingham' and v1.city_name = 'London' returning *; delete from city_view where city_name = 'Birmingham' returning *; @@ -1127,14 +1102,12 @@ delete from city_view where city_name = 'Birmingham' returning *; create view european_city_view as select * from city_view where continent = 'Europe'; -select COUNT(*) from european_city_view; +select count(*) from european_city_view; create function no_op_trig_fn() returns trigger language plpgsql -as $function$ -begin RETURN NULL; end -$function$; +as 'begin RETURN NULL; end'; create trigger no_op_trig instead of insert or delete or update @@ -1152,14 +1125,7 @@ create rule european_city_insert_rule as on insert to european_city_view do instead insert into city_view - values - ( - new.city_id, - new.city_name, - new.population, - new.country_name, - new.continent - ) + values (new.city_id, new.city_name, new.population, new.country_name, new.continent) returning *;; create rule european_city_update_rule @@ -1176,10 +1142,7 @@ do instead create rule european_city_delete_rule as on delete to european_city_view do instead - delete from city_view - where - city_id = old.city_id - returning *;; + delete from city_view where city_id = old.city_id returning *;; insert into european_city_view (city_name, country_name) values ('Cambridge', 'USA') returning *; @@ -1223,21 +1186,21 @@ create table depth_c (id int not null primary key); create function depth_a_tf() returns trigger language plpgsql -as $function$ +as $$ begin raise notice '%: depth = %', tg_name, pg_trigger_depth(); insert into depth_b values (new.id); raise notice '%: depth = %', tg_name, pg_trigger_depth(); return new; end; -$function$; +$$; create trigger depth_a_tr before insert on depth_a for each row execute function depth_a_tf(); create function depth_b_tf() returns trigger language plpgsql -as $function$ +as $$ begin raise notice '%: depth = %', tg_name, pg_trigger_depth(); begin @@ -1252,14 +1215,14 @@ begin end if; return new; end; -$function$; +$$; create trigger depth_b_tr before insert on depth_b for each row execute function depth_b_tf(); create function depth_c_tf() returns trigger language plpgsql -as $function$ +as $$ begin raise notice '%: depth = %', tg_name, pg_trigger_depth(); if new.id = 1 then @@ -1268,7 +1231,7 @@ begin raise notice '%: depth = %', tg_name, pg_trigger_depth(); return new; end; -$function$; +$$; create trigger depth_c_tr before insert on depth_c for each row execute function depth_c_tf(); @@ -1308,7 +1271,7 @@ create temporary table child ( create function parent_upd_func() returns trigger language plpgsql -as $function$ +as $$ begin if old.val1 <> new.val1 then new.val2 = new.val1; @@ -1316,7 +1279,7 @@ begin end if; return new; end; -$function$; +$$; create trigger parent_upd_trig before update @@ -1327,12 +1290,12 @@ execute function parent_upd_func(); create function parent_del_func() returns trigger language plpgsql -as $function$ +as $$ begin delete from child where aid = old.aid; return old; end; -$function$; +$$; create trigger parent_del_trig before delete @@ -1343,24 +1306,24 @@ execute function parent_del_func(); create function child_ins_func() returns trigger language plpgsql -as $function$ +as $$ begin update parent set bcnt = bcnt + 1 where aid = new.aid; return new; end; -$function$; +$$; create trigger child_ins_trig after insert on child for each row execute function child_ins_func(); create function child_del_func() returns trigger language plpgsql -as $function$ +as $$ begin update parent set bcnt = bcnt - 1 where aid = old.aid; return old; end; -$function$; +$$; create trigger child_del_trig after delete on child for each row execute function child_del_func(); @@ -1387,7 +1350,7 @@ select * from child; create or replace function parent_del_func() returns trigger language plpgsql -as $function$ +as $$ begin delete from child where aid = old.aid; if found then @@ -1396,7 +1359,7 @@ begin end if; return old; end; -$function$; +$$; delete from parent where aid = 1; @@ -1424,7 +1387,7 @@ create temporary table self_ref_trigger ( create function self_ref_trigger_ins_func() returns trigger language plpgsql -as $function$ +as $$ begin if new.parent is not null then update self_ref_trigger set nchildren = nchildren + 1 @@ -1432,7 +1395,7 @@ begin end if; return new; end; -$function$; +$$; create trigger self_ref_trigger_ins_trig before insert @@ -1443,7 +1406,7 @@ execute function self_ref_trigger_ins_func(); create function self_ref_trigger_del_func() returns trigger language plpgsql -as $function$ +as $$ begin if old.parent is not null then update self_ref_trigger set nchildren = nchildren - 1 @@ -1451,7 +1414,7 @@ begin end if; return old; end; -$function$; +$$; create trigger self_ref_trigger_del_trig before delete @@ -1491,12 +1454,12 @@ inherits (stmt_trig_on_empty_upd); create function update_stmt_notice() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'updating %', TG_TABLE_NAME; return null; end; -$function$; +$$; create trigger before_stmt_trigger before update @@ -1526,12 +1489,11 @@ create table trigger_ddl_table ( create function trigger_ddl_func() returns trigger language plpgsql -as $function$ +as $$ begin alter table trigger_ddl_table add primary key (col1); return new; -end -$function$; +end$$; create trigger trigger_ddl_func before insert @@ -1544,12 +1506,11 @@ insert into trigger_ddl_table values (1, 42); create or replace function trigger_ddl_func() returns trigger language plpgsql -as $function$ +as $$ begin create index on trigger_ddl_table (col2); return new; -end -$function$; +end$$; insert into trigger_ddl_table values (1, 42); @@ -1558,14 +1519,14 @@ drop table trigger_ddl_table; drop function trigger_ddl_func(); create table upsert ( - key int primary key, + key int4 primary key, color text ); create function upsert_before_func() returns trigger language plpgsql -as $function$ +as $$ begin if (TG_OP = 'UPDATE') then raise warning 'before update (old): %', old.*::text; @@ -1580,7 +1541,7 @@ begin end if; return new; end; -$function$; +$$; create trigger upsert_before_trig before insert or update @@ -1591,7 +1552,7 @@ execute function upsert_before_func(); create function upsert_after_func() returns trigger language plpgsql -as $function$ +as $$ begin if (TG_OP = 'UPDATE') then raise warning 'after update (old): %', old.*::text; @@ -1601,7 +1562,7 @@ begin end if; return null; end; -$function$; +$$; create trigger upsert_after_trig after insert or update @@ -1611,67 +1572,35 @@ execute function upsert_after_func(); insert into upsert values (1, 'black') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (2, 'red') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (3, 'orange') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (4, 'green') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (5, 'purple') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (6, 'white') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (7, 'pink') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (8, 'yellow') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; select * from upsert; @@ -1689,9 +1618,7 @@ as select * from my_table; create function my_trigger_function() returns trigger language plpgsql -as $function$ -begin end; -$function$; +as $$ begin end; $$; create trigger my_trigger after update @@ -1707,14 +1634,12 @@ drop view my_view; drop table my_table; create table parted_trig (a int) -partition by LIST(a); +partition by list(a); create function trigger_nothing() returns trigger language plpgsql -as $function$ -begin end; -$function$; +as $$ begin end; $$; create trigger failed instead of update @@ -1868,14 +1793,14 @@ drop table trigpart; drop function trigger_nothing(); create table parted_stmt_trig (a int) -partition by LIST(a); +partition by list(a); create table parted_stmt_trig1 partition of parted_stmt_trig for values in (1); create table parted_stmt_trig2 partition of parted_stmt_trig for values in (2); create table parted2_stmt_trig (a int) -partition by LIST(a); +partition by list(a); create table parted2_stmt_trig1 partition of parted2_stmt_trig for values in (1); @@ -1884,15 +1809,15 @@ create table parted2_stmt_trig2 partition of parted2_stmt_trig for values in (2) create or replace function trigger_notice() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger % on % % % for %', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL; if TG_LEVEL = 'ROW' then return NEW; end if; return null; end; -$function$; + $$; create trigger trig_ins_before before insert @@ -2020,13 +1945,7 @@ on parted2_stmt_trig for each statement execute function trigger_notice(); -with -ins (a) -as ( - insert into parted2_stmt_trig - values (1), (2) - returning a -) +with ins (a) as (insert into parted2_stmt_trig values (1), (2) returning a) insert into parted_stmt_trig select a from ins returning cast(tableoid as regclass), @@ -2079,7 +1998,7 @@ insert into parted_trig values (50), (1500); drop table parted_trig; create table parted_trig (a int) -partition by LIST(a); +partition by list(a); create table parted_trig1 partition of parted_trig for values in (1); @@ -2090,8 +2009,8 @@ insert into parted_trig values (1); create or replace function trigger_notice() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger % on % % % for %', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL; if TG_LEVEL = 'ROW' then if TG_OP = 'DELETE' then @@ -2102,7 +2021,7 @@ begin end if; return null; end; -$function$; + $$; create trigger parted_trig_before_stmt before insert or delete or update @@ -2133,15 +2052,15 @@ update parted_trig set a = 2 where a = 1; drop table parted_trig; create table parted_trig (a int) -partition by LIST(a); +partition by list(a); create table parted_trig1 partition of parted_trig for values in (1); create or replace function trigger_notice() returns trigger language plpgsql -as $function$ -declare +as $$ + declare arg1 text = TG_ARGV[0]; arg2 integer = TG_ARGV[1]; begin @@ -2149,7 +2068,7 @@ declare TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL, arg1, arg2; return null; end; -$function$; + $$; create trigger aaa after insert @@ -2171,18 +2090,16 @@ insert into parted_trig values (1), (2), (3); drop table parted_trig; create function bark(text) -returns boolean +returns bool language plpgsql immutable -as $function$ -begin raise notice '% <- woof!', $1; return true; end; -$function$; +as $$ begin raise notice '% <- woof!', $1; return true; end; $$; create or replace function trigger_notice_ab() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger % on % % % for %: (a,b)=(%,%)', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL, NEW.a, NEW.b; @@ -2191,7 +2108,7 @@ begin end if; return null; end; -$function$; + $$; create table parted_irreg_ancestor ( fd text, @@ -2262,21 +2179,21 @@ create table parted ( b int, c text ) -partition by LIST(a); +partition by list(a); -create table parted_1 partition of parted for values in (1) partition by LIST(b); +create table parted_1 partition of parted for values in (1) partition by list(b); create table parted_1_1 partition of parted_1 for values in (1); create function parted_trigfunc() returns trigger language plpgsql -as $function$ +as $$ begin new.a = new.a + 1; return new; end; -$function$; +$$; insert into parted values (1, 1, 'uno uno v1'); @@ -2293,12 +2210,12 @@ update parted set c = c || 'v3'; create or replace function parted_trigfunc() returns trigger language plpgsql -as $function$ +as $$ begin new.b = new.b + 1; return new; end; -$function$; +$$; insert into parted values (1, 1, 'uno uno v4'); @@ -2307,12 +2224,12 @@ update parted set c = c || 'v5'; create or replace function parted_trigfunc() returns trigger language plpgsql -as $function$ +as $$ begin new.c = new.c || ' did '|| TG_OP; return new; end; -$function$; +$$; insert into parted values (1, 1, 'uno uno'); @@ -2333,12 +2250,12 @@ select cast(tableoid as regclass), * from parted; create or replace function parted_trigfunc2() returns trigger language plpgsql -as $function$ +as $$ begin new.a = new.a + 1; return new; end; -$function$; +$$; create trigger t2 before update on parted for each row execute function parted_trigfunc2(); @@ -2363,17 +2280,17 @@ create table parted ( b int, c text ) -partition by LIST((a + b)); +partition by list((a + b)); create or replace function parted_trigfunc() returns trigger language plpgsql -as $function$ +as $$ begin new.a = new.a + new.b; return new; end; -$function$; +$$; create table parted_1 partition of parted for values in (1, 2); @@ -2416,8 +2333,7 @@ create table parted1_constr ( alter table parted_constr attach partition - parted1_constr - for values from ('aaaa') to ('bbbb'); + parted1_constr for values from ('aaaa') to ('bbbb'); create constraint trigger parted_trig after insert @@ -2575,10 +2491,7 @@ select cast(c.conrelid as regclass), cast(c.confrelid as regclass) from - pg_trigger as t - inner join - pg_constraint as c - on t.tgconstraint = c.oid + pg_trigger as t inner join pg_constraint as c on t.tgconstraint = c.oid where tgname = 'parted_trigger' order by cast(cast(t.tgrelid as regclass) as text); @@ -2642,7 +2555,7 @@ partition by range(a); create table trg_clone1 partition of trg_clone for values from (0) to (1000); alter table trg_clone - add constraint "uniq" unique (a) deferrable; + add constraint uniq unique (a) deferrable; create table trg_clone2 partition of trg_clone for values from (1000) to (2000); @@ -2655,7 +2568,7 @@ create table trg_clone_3_3 partition of trg_clone3 for values from (2000) to (21 select cast(tgrelid as regclass), - COUNT(*) + count(*) from pg_trigger where @@ -2676,9 +2589,7 @@ inherits (parent); create function trig_nothing() returns trigger language plpgsql -as $function$ -begin return null; end -$function$; +as $$ begin return null; end $$; create trigger tg after insert on parent for each row execute function trig_nothing(); @@ -2694,10 +2605,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text); alter table only parent @@ -2710,16 +2618,13 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text); drop table parent, child1; create table parent (a int) -partition by LIST(a); +partition by list(a); create table child1 partition of parent for values in (1); @@ -2734,10 +2639,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgname; @@ -2754,10 +2656,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgname; @@ -2771,10 +2670,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgname; @@ -2788,10 +2684,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgname; @@ -2801,7 +2694,7 @@ create table parent ( a int primary key, f int references parent ) -partition by LIST(a); +partition by list(a); create table child1 partition of parent for values in (1); @@ -2813,10 +2706,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgfoid; @@ -2831,10 +2721,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgfoid; @@ -2848,9 +2735,7 @@ create table trgfire1 partition of trgfire for values from (1) to (10); create or replace function tgf() returns trigger language plpgsql -as $function$ -begin raise exception 'except'; end -$function$; +as $$ begin raise exception 'except'; end $$; create trigger tg after insert on trgfire for each row execute function tgf(); @@ -2873,14 +2758,14 @@ alter table trgfire insert into trgfire values (21); -create table trgfire4 partition of trgfire for values from (30) to (40) partition by LIST(i); +create table trgfire4 partition of trgfire for values from (30) to (40) partition by list(i); create table trgfire4_30 partition of trgfire4 for values in (30); insert into trgfire values (30); create table trgfire5 (like trgfire) -partition by LIST(i); +partition by list(i); create table trgfire5_40 partition of trgfire5 for values in (40); @@ -2896,15 +2781,7 @@ select from pg_trigger where - cast(tgrelid as regclass) in - ( - select - oid - from - pg_class - where - relname like 'trgfire%' - ) + cast(tgrelid as regclass) in (select oid from pg_class where relname like 'trgfire%') order by cast(cast(tgrelid as regclass) as text); alter table trgfire @@ -2927,45 +2804,45 @@ drop function tgf(); create or replace function dump_insert() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, new table = %', TG_NAME, (select string_agg(new_table::text, ', ' order by a) from new_table); return null; end; -$function$; +$$; create or replace function dump_update() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, old table = %, new table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by a) from old_table), (select string_agg(new_table::text, ', ' order by a) from new_table); return null; end; -$function$; +$$; create or replace function dump_delete() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, old table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by a) from old_table); return null; end; -$function$; +$$; create table parent ( a text, b int ) -partition by LIST(a); +partition by list(a); create table child1 partition of parent for values in ('AAA'); @@ -3093,10 +2970,7 @@ select from information_schema.triggers where - event_object_table - in ( - 'parent', 'child1', 'child2', 'child3' - ) + event_object_table in ('parent', 'child1', 'child2', 'child3') order by trigger_name collate "C", 2; @@ -3157,12 +3031,12 @@ copy parent (a, b) from stdout; create or replace function intercept_insert() returns trigger language plpgsql -as $function$ -begin +as $$ + begin new.b = new.b + 1000; return new; end; -$function$; +$$; create trigger intercept_insert_child3 before insert @@ -3182,7 +3056,7 @@ create table parent ( a text, b int ) -partition by LIST(a); +partition by list(a); create table child partition of parent for values in ('AAA'); @@ -3219,27 +3093,27 @@ drop table child, parent; create or replace function dump_update_new() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, new table = %', TG_NAME, (select string_agg(new_table::text, ', ' order by a) from new_table); return null; end; -$function$; +$$; create or replace function dump_update_old() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, old table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by a) from old_table); return null; end; -$function$; +$$; create table trans_tab_parent (a text) -partition by LIST(a); +partition by list(a); create table trans_tab_child1 partition of trans_tab_parent for values in ('AAA1', 'AAA2'); @@ -3537,37 +3411,21 @@ execute function dump_update(); insert into my_table values (1, 'AAA'), (2, 'BBB') -on conflict -(a) -do -update -set b = my_table.b || ':' || excluded.b; +on conflict (a) do update set b = my_table.b || ':' || excluded.b; insert into my_table -values - (1, 'AAA'), - (2, 'BBB'), - (3, 'CCC'), - (4, 'DDD') -on conflict -(a) -do -update -set b = my_table.b || ':' || excluded.b; +values (1, 'AAA'), (2, 'BBB'), (3, 'CCC'), (4, 'DDD') +on conflict (a) do update set b = my_table.b || ':' || excluded.b; insert into my_table values (3, 'CCC'), (4, 'DDD') -on conflict -(a) -do -update -set b = my_table.b || ':' || excluded.b; +on conflict (a) do update set b = my_table.b || ':' || excluded.b; create table iocdu_tt_parted ( a int primary key, b text ) -partition by LIST(a); +partition by list(a); create table iocdu_tt_parted1 partition of iocdu_tt_parted for values in (1); @@ -3594,31 +3452,15 @@ execute function dump_update(); insert into iocdu_tt_parted values (1, 'AAA'), (2, 'BBB') -on conflict -(a) -do -update -set b = iocdu_tt_parted.b || ':' || excluded.b; +on conflict (a) do update set b = iocdu_tt_parted.b || ':' || excluded.b; insert into iocdu_tt_parted -values - (1, 'AAA'), - (2, 'BBB'), - (3, 'CCC'), - (4, 'DDD') -on conflict -(a) -do -update -set b = iocdu_tt_parted.b || ':' || excluded.b; +values (1, 'AAA'), (2, 'BBB'), (3, 'CCC'), (4, 'DDD') +on conflict (a) do update set b = iocdu_tt_parted.b || ':' || excluded.b; insert into iocdu_tt_parted values (3, 'CCC'), (4, 'DDD') -on conflict -(a) -do -update -set b = iocdu_tt_parted.b || ':' || excluded.b; +on conflict (a) do update set b = iocdu_tt_parted.b || ':' || excluded.b; drop table iocdu_tt_parted; @@ -3643,12 +3485,10 @@ create table my_table (a int); create function make_bogus_matview() returns trigger language plpgsql -as $function$ -begin +as $$ begin create materialized view transition_test_mv as select * from new_table; return new; -end -$function$; +end $$; create trigger make_bogus_matview after insert @@ -3671,11 +3511,7 @@ create table refd_table ( create table trig_table ( a int, b text, - foreign key - (a) - references refd_table - on DELETE cascade - on UPDATE cascade + foreign key (a) references refd_table on delete cascade on update cascade ); create trigger trig_table_before_trig @@ -3709,13 +3545,7 @@ execute function dump_delete(); insert into refd_table values (1, 'one'), (2, 'two'), (3, 'three'); insert into trig_table -values - (1, 'one a'), - (1, 'one b'), - (2, 'two a'), - (2, 'two b'), - (3, 'three a'), - (3, 'three b'); +values (1, 'one a'), (1, 'one b'), (2, 'two a'), (2, 'two b'), (3, 'three a'), (3, 'three b'); update refd_table set a = 11 where b = 'one'; @@ -3743,7 +3573,7 @@ drop table trig_table; create table self_ref ( a int primary key, - b int references self_ref (a) on DELETE cascade + b int references self_ref (a) on delete cascade ); create trigger self_ref_before_trig @@ -3811,11 +3641,7 @@ create table merge_source_table ( ); insert into merge_source_table -values - (1, 'initial1'), - (2, 'initial2'), - (3, 'initial3'), - (4, 'initial4'); +values (1, 'initial1'), (2, 'initial2'), (3, 'initial3'), (4, 'initial4'); drop table merge_source_table, merge_target_table; @@ -3830,22 +3656,20 @@ create table my_table (id int); create function funca() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'hello from funcA'; return null; -end; -$function$; +end; $$; create function funcb() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'hello from funcB'; return null; -end; -$function$; +end; $$; create trigger my_trig after insert on my_table for each row execute function funca(); @@ -3918,14 +3742,12 @@ drop function funca(); drop function funcb(); create table trigger_parted (a int primary key) -partition by LIST(a); +partition by list(a); create function trigger_parted_trigfunc() returns trigger language plpgsql -as $function$ -begin end; -$function$; +as $$ begin end; $$; create trigger aft_row after insert or update @@ -3933,11 +3755,11 @@ on trigger_parted for each row execute function trigger_parted_trigfunc(); -create table trigger_parted_p1 partition of trigger_parted for values in (1) partition by LIST(a); +create table trigger_parted_p1 partition of trigger_parted for values in (1) partition by list(a); create table trigger_parted_p1_1 partition of trigger_parted_p1 for values in (1); -create table trigger_parted_p2 partition of trigger_parted for values in (2) partition by LIST(a); +create table trigger_parted_p2 partition of trigger_parted for values in (2) partition by list(a); create table trigger_parted_p2_2 partition of trigger_parted_p2 for values in (2); @@ -3951,11 +3773,7 @@ create table convslot_test_parent (col1 text primary key); create table convslot_test_child ( col1 text primary key, - foreign key - (col1) - references convslot_test_parent (col1) - on DELETE cascade - on UPDATE cascade + foreign key (col1) references convslot_test_parent (col1) on delete cascade on update cascade ); alter table convslot_test_child @@ -3972,26 +3790,24 @@ insert into convslot_test_child (col1) values ('3'); create function convslot_trig1() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'trigger = %, old_table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by col1) from old_table); return null; -end; -$function$; +end; $$; create function convslot_trig2() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'trigger = %, new table = %', TG_NAME, (select string_agg(new_table::text, ', ' order by col1) from new_table); return null; -end; -$function$; +end; $$; create trigger but_trigger after update @@ -4005,15 +3821,14 @@ update convslot_test_parent set col1 = col1 || '1'; create function convslot_trig3() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'trigger = %, old_table = %, new table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by col1) from old_table), (select string_agg(new_table::text, ', ' order by col1) from new_table); return null; -end; -$function$; +end; $$; create trigger but_trigger2 after update @@ -4060,9 +3875,7 @@ alter table convslot_test_parent create function convslot_trig4() returns trigger language plpgsql -as $function$ -begin raise exception 'BOOM!'; end -$function$; +as $$begin raise exception 'BOOM!'; end$$; create trigger convslot_test_parent_update after update @@ -4103,9 +3916,7 @@ create table cho partition of middle for values from (6) to (10); create function f() returns trigger language plpgsql -as $function$ -begin return new; end; -$function$; +as $$ begin return new; end; $$; create trigger a after insert on grandparent for each row execute function f(); @@ -4114,22 +3925,11 @@ alter trigger a on grandparent rename to b; select cast(tgrelid as regclass), tgname, - ( - select - tgname - from - pg_trigger as tr - where - tr.oid = pg_trigger.tgparentid - ) - as parent_tgname + (select tgname from pg_trigger as tr where tr.oid = pg_trigger.tgparentid) as parent_tgname from pg_trigger where - tgrelid in - ( - select relid from pg_partition_tree('grandparent') - ) + tgrelid in (select relid from pg_partition_tree('grandparent')) order by tgname, cast(cast(tgrelid as regclass) as text) collate "C"; @@ -4148,22 +3948,11 @@ alter trigger p on grandparent rename to q; select cast(tgrelid as regclass), tgname, - ( - select - tgname - from - pg_trigger as tr - where - tr.oid = pg_trigger.tgparentid - ) - as parent_tgname + (select tgname from pg_trigger as tr where tr.oid = pg_trigger.tgparentid) as parent_tgname from pg_trigger where - tgrelid in - ( - select relid from pg_partition_tree('grandparent') - ) + tgrelid in (select relid from pg_partition_tree('grandparent')) order by tgname, cast(cast(tgrelid as regclass) as text) collate "C"; @@ -4191,18 +3980,18 @@ create role regress_fn_owner; create function whoami() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'I am %', current_user; return null; end; -$function$; +$$; alter function whoami() owner to regress_fn_owner; create table defer_trig (id int); -grant INSERT on table defer_trig to public; +grant insert on table defer_trig to public; create constraint trigger whoami after insert @@ -4245,13 +4034,13 @@ alter function whoami() security invoker; create or replace function whoami() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'I am %', current_user; perform 1 / 0; return null; end; -$function$; +$$; begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_80.snap index 5cb9e5a79..8316b43c9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_80.snap @@ -5,9 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/triggers.sql create function trigger_return_old() returns trigger language c -as $function$ -regresslib -$function$; +as 'regresslib'; create table trigtest ( f1 int, @@ -35,9 +33,7 @@ select * from trigtest; create function f1_times_10() returns trigger language plpgsql -as $function$ -begin new.f1 := new.f1 * 10; return new; end -$function$; +as $$ begin new.f1 := new.f1 * 10; return new; end $$; create trigger trigger_alpha before insert or update @@ -93,7 +89,7 @@ drop table trigtest; create table trigtest ( a int, - b boolean default true not null, + b bool default true not null, c text default 'xyzzy' not null ); @@ -128,8 +124,7 @@ select * from trigtest; drop table trigtest; create table log_table ( - tstamp timestamp - default cast(timeofday() as timestamp) + tstamp timestamp default cast(timeofday() as timestamp) ); create table main_table ( @@ -140,12 +135,11 @@ create table main_table ( create function trigger_func() returns trigger language plpgsql -as $function$ +as ' BEGIN - RAISE NOTICE 'trigger_func(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL; + RAISE NOTICE ''trigger_func(%) called: action = %, when = %, level = %'', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL; RETURN NULL; -END; -$function$; +END;'; create trigger before_ins_stmt_trig before insert @@ -167,11 +161,7 @@ execute function trigger_func(after_upd_stmt); insert into main_table (a, b) values (5, 10) -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; create trigger after_upd_row_trig after update @@ -269,42 +259,37 @@ select from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_a'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_a'; select pg_get_triggerdef(oid, false) from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_a'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_a'; select pg_get_triggerdef(oid, true) from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_any'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_any'; alter trigger modified_a on main_table rename to modified_modified_a; select - COUNT(*) + count(*) from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_a'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_a'; select - COUNT(*) + count(*) from pg_trigger where - tgrelid = cast('main_table' as regclass) and - tgname = 'modified_modified_a'; + tgrelid = cast('main_table' as regclass) and tgname = 'modified_modified_a'; drop trigger modified_modified_a on main_table; @@ -326,8 +311,7 @@ create trigger oid_unchanged_trig after update on table_with_oids for each row -when (new.tableoid = old.tableoid and -new.tableoid <> 0) +when (new.tableoid = old.tableoid and new.tableoid <> 0) execute function trigger_func(after_upd_oid_unchanged); update table_with_oids set a = a + 1; @@ -384,13 +368,13 @@ create table some_t (some_col boolean not null); create function dummy_update_func() returns trigger language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'dummy_update_func(%) called: action = %, old = %, new = %', TG_ARGV[0], TG_OP, OLD, NEW; RETURN NEW; END; -$function$; +$$; create trigger some_trig_before before update @@ -475,17 +459,16 @@ rollback; create table trigtest (i serial primary key); -create table trigtest2 (i int references trigtest (i) on DELETE cascade); +create table trigtest2 (i int references trigtest (i) on delete cascade); create function trigtest() returns trigger language plpgsql -as $function$ +as $$ begin raise notice '% % % %', TG_TABLE_NAME, TG_OP, TG_WHEN, TG_LEVEL; return new; -end; -$function$; +end;$$; create trigger trigtest_b_row_tg before insert or delete or update @@ -570,7 +553,8 @@ create table trigger_test ( create or replace function trigger_data() returns trigger language plpgsql -as $function$ +as $$ + declare argstr text; @@ -618,7 +602,7 @@ begin end if; end; -$function$; +$$; create trigger show_trigger_data_trig before insert or delete or update @@ -648,7 +632,7 @@ create table trigger_test ( create function mytrigger() returns trigger language plpgsql -as $function$ +as $$ begin if row(old.*) = row(new.*) then raise notice 'row % not changed', new.f1; @@ -656,8 +640,7 @@ begin raise notice 'row % changed', new.f1; end if; return new; -end -$function$; +end$$; create trigger t before update @@ -678,7 +661,7 @@ update trigger_test set f3 = null; create or replace function mytrigger() returns trigger language plpgsql -as $function$ +as $$ begin if row(old.*) is distinct from row(new.*) then raise notice 'row % changed', new.f1; @@ -686,8 +669,7 @@ begin raise notice 'row % not changed', new.f1; end if; return new; -end -$function$; +end$$; update trigger_test set f3 = 'bar'; @@ -702,14 +684,14 @@ drop function mytrigger(); create function serializable_update_trig() returns trigger language plpgsql -as $function$ +as $$ declare rec record; begin new.description = 'updated in trigger'; return new; end; -$function$; +$$; create table serializable_update_tab ( id int, @@ -724,16 +706,11 @@ for each row execute function serializable_update_trig(); insert into serializable_update_tab -select - a, - repeat('xyzxz', 100), - 'new' -from - generate_series(1, 50) as a; +select a, repeat('xyzxz', 100), 'new' from generate_series(1, 50) as a; begin; -set TRANSACTION isolation level serializable; +set transaction isolation level serializable; update serializable_update_tab set description = 'no no', id = 1 where id = 1; @@ -773,7 +750,7 @@ as select a, b from main_table; create or replace function view_trigger() returns trigger language plpgsql -as $function$ +as $$ declare argstr text := ''; begin @@ -810,7 +787,7 @@ begin RETURN NULL; end; -$function$; +$$; create trigger invalid_trig before insert @@ -984,10 +961,7 @@ create table country_table ( ); insert into country_table (country_name, continent) -values - ('Japan', 'Asia'), - ('UK', 'Europe'), - ('USA', 'North America') +values ('Japan', 'Asia'), ('UK', 'Europe'), ('USA', 'North America') returning *; create table city_table ( @@ -1013,7 +987,7 @@ from create function city_insert() returns trigger language plpgsql -as $function$ +as $$ declare ctry_id int; begin @@ -1038,7 +1012,7 @@ begin RETURN NEW; end; -$function$; +$$; create trigger city_insert_trig instead of insert @@ -1049,13 +1023,13 @@ execute function city_insert(); create function city_delete() returns trigger language plpgsql -as $function$ +as $$ begin DELETE FROM city_table WHERE city_id = OLD.city_id; if NOT FOUND then RETURN NULL; end if; RETURN OLD; end; -$function$; +$$; create trigger city_delete_trig instead of delete @@ -1066,7 +1040,7 @@ execute function city_delete(); create function city_update() returns trigger language plpgsql -as $function$ +as $$ declare ctry_id int; begin @@ -1091,7 +1065,7 @@ begin if NOT FOUND then RETURN NULL; end if; RETURN NEW; end; -$function$; +$$; create trigger city_update_trig instead of update @@ -1114,14 +1088,7 @@ values (123456, 'New York') returning *; insert into city_view -values - ( - 234567, - 'Birmingham', - 1016800, - 'UK', - 'EU' - ) +values (234567, 'Birmingham', 1016800, 'UK', 'EU') returning *; update city_view set country_name = 'Japon' where city_name = 'Tokyo'; @@ -1159,28 +1126,20 @@ update city_view as v1 set country_name = v2.country_name from city_view as v2 where - v2.city_name = 'Birmingham' and - v1.city_name = 'London' + v2.city_name = 'Birmingham' and v1.city_name = 'London' returning *; delete from city_view where city_name = 'Birmingham' returning *; create view european_city_view -as select - * -from - city_view -where - continent = 'Europe'; +as select * from city_view where continent = 'Europe'; -select COUNT(*) from european_city_view; +select count(*) from european_city_view; create function no_op_trig_fn() returns trigger language plpgsql -as $function$ -begin RETURN NULL; end -$function$; +as 'begin RETURN NULL; end'; create trigger no_op_trig instead of insert or delete or update @@ -1222,10 +1181,7 @@ do instead create rule european_city_delete_rule as on delete to european_city_view do instead - delete from city_view - where - city_id = old.city_id - returning *;; + delete from city_view where city_id = old.city_id returning *;; insert into european_city_view (city_name, country_name) values ('Cambridge', 'USA') @@ -1279,14 +1235,14 @@ create table depth_c (id int not null primary key); create function depth_a_tf() returns trigger language plpgsql -as $function$ +as $$ begin raise notice '%: depth = %', tg_name, pg_trigger_depth(); insert into depth_b values (new.id); raise notice '%: depth = %', tg_name, pg_trigger_depth(); return new; end; -$function$; +$$; create trigger depth_a_tr before insert @@ -1297,7 +1253,7 @@ execute function depth_a_tf(); create function depth_b_tf() returns trigger language plpgsql -as $function$ +as $$ begin raise notice '%: depth = %', tg_name, pg_trigger_depth(); begin @@ -1312,7 +1268,7 @@ begin end if; return new; end; -$function$; +$$; create trigger depth_b_tr before insert @@ -1323,7 +1279,7 @@ execute function depth_b_tf(); create function depth_c_tf() returns trigger language plpgsql -as $function$ +as $$ begin raise notice '%: depth = %', tg_name, pg_trigger_depth(); if new.id = 1 then @@ -1332,7 +1288,7 @@ begin raise notice '%: depth = %', tg_name, pg_trigger_depth(); return new; end; -$function$; +$$; create trigger depth_c_tr before insert @@ -1376,7 +1332,7 @@ create temporary table child ( create function parent_upd_func() returns trigger language plpgsql -as $function$ +as $$ begin if old.val1 <> new.val1 then new.val2 = new.val1; @@ -1384,7 +1340,7 @@ begin end if; return new; end; -$function$; +$$; create trigger parent_upd_trig before update @@ -1395,12 +1351,12 @@ execute function parent_upd_func(); create function parent_del_func() returns trigger language plpgsql -as $function$ +as $$ begin delete from child where aid = old.aid; return old; end; -$function$; +$$; create trigger parent_del_trig before delete @@ -1411,12 +1367,12 @@ execute function parent_del_func(); create function child_ins_func() returns trigger language plpgsql -as $function$ +as $$ begin update parent set bcnt = bcnt + 1 where aid = new.aid; return new; end; -$function$; +$$; create trigger child_ins_trig after insert @@ -1427,12 +1383,12 @@ execute function child_ins_func(); create function child_del_func() returns trigger language plpgsql -as $function$ +as $$ begin update parent set bcnt = bcnt - 1 where aid = old.aid; return old; end; -$function$; +$$; create trigger child_del_trig after delete @@ -1463,7 +1419,7 @@ select * from child; create or replace function parent_del_func() returns trigger language plpgsql -as $function$ +as $$ begin delete from child where aid = old.aid; if found then @@ -1472,7 +1428,7 @@ begin end if; return old; end; -$function$; +$$; delete from parent where aid = 1; @@ -1500,7 +1456,7 @@ create temporary table self_ref_trigger ( create function self_ref_trigger_ins_func() returns trigger language plpgsql -as $function$ +as $$ begin if new.parent is not null then update self_ref_trigger set nchildren = nchildren + 1 @@ -1508,7 +1464,7 @@ begin end if; return new; end; -$function$; +$$; create trigger self_ref_trigger_ins_trig before insert @@ -1519,7 +1475,7 @@ execute function self_ref_trigger_ins_func(); create function self_ref_trigger_del_func() returns trigger language plpgsql -as $function$ +as $$ begin if old.parent is not null then update self_ref_trigger set nchildren = nchildren - 1 @@ -1527,7 +1483,7 @@ begin end if; return old; end; -$function$; +$$; create trigger self_ref_trigger_del_trig before delete @@ -1567,12 +1523,12 @@ inherits (stmt_trig_on_empty_upd); create function update_stmt_notice() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'updating %', TG_TABLE_NAME; return null; end; -$function$; +$$; create trigger before_stmt_trigger before update @@ -1602,12 +1558,11 @@ create table trigger_ddl_table ( create function trigger_ddl_func() returns trigger language plpgsql -as $function$ +as $$ begin alter table trigger_ddl_table add primary key (col1); return new; -end -$function$; +end$$; create trigger trigger_ddl_func before insert @@ -1620,12 +1575,11 @@ insert into trigger_ddl_table values (1, 42); create or replace function trigger_ddl_func() returns trigger language plpgsql -as $function$ +as $$ begin create index on trigger_ddl_table (col2); return new; -end -$function$; +end$$; insert into trigger_ddl_table values (1, 42); @@ -1634,14 +1588,14 @@ drop table trigger_ddl_table; drop function trigger_ddl_func(); create table upsert ( - key int primary key, + key int4 primary key, color text ); create function upsert_before_func() returns trigger language plpgsql -as $function$ +as $$ begin if (TG_OP = 'UPDATE') then raise warning 'before update (old): %', old.*::text; @@ -1656,7 +1610,7 @@ begin end if; return new; end; -$function$; +$$; create trigger upsert_before_trig before insert or update @@ -1667,7 +1621,7 @@ execute function upsert_before_func(); create function upsert_after_func() returns trigger language plpgsql -as $function$ +as $$ begin if (TG_OP = 'UPDATE') then raise warning 'after update (old): %', old.*::text; @@ -1677,7 +1631,7 @@ begin end if; return null; end; -$function$; +$$; create trigger upsert_after_trig after insert or update @@ -1687,67 +1641,35 @@ execute function upsert_after_func(); insert into upsert values (1, 'black') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (2, 'red') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (3, 'orange') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (4, 'green') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (5, 'purple') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (6, 'white') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (7, 'pink') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; insert into upsert values (8, 'yellow') -on conflict -(key) -do -update -set color = 'updated ' || upsert.color; +on conflict (key) do update set color = 'updated ' || upsert.color; select * from upsert; @@ -1765,9 +1687,7 @@ as select * from my_table; create function my_trigger_function() returns trigger language plpgsql -as $function$ -begin end; -$function$; +as $$ begin end; $$; create trigger my_trigger after update @@ -1783,14 +1703,12 @@ drop view my_view; drop table my_table; create table parted_trig (a int) -partition by LIST(a); +partition by list(a); create function trigger_nothing() returns trigger language plpgsql -as $function$ -begin end; -$function$; +as $$ begin end; $$; create trigger failed instead of update @@ -1827,8 +1745,7 @@ create table trigpart3 (like trigpart); alter table trigpart attach partition - trigpart3 - for values from (2000) to (3000); + trigpart3 for values from (2000) to (3000); create table trigpart4 partition of trigpart @@ -1841,8 +1758,7 @@ create table trigpart42 (like trigpart); alter table trigpart4 attach partition - trigpart42 - for values from (3500) to (4000); + trigpart42 for values from (3500) to (4000); select cast(tgrelid as regclass), @@ -1906,8 +1822,7 @@ drop table trigpart4; alter table trigpart attach partition - trigpart3 - for values from (2000) to (3000); + trigpart3 for values from (2000) to (3000); alter table trigpart detach partition @@ -1915,8 +1830,7 @@ alter table trigpart alter table trigpart attach partition - trigpart3 - for values from (2000) to (3000); + trigpart3 for values from (2000) to (3000); drop table trigpart3; @@ -1942,8 +1856,7 @@ execute function trigger_nothing(); alter table trigpart attach partition - trigpart3 - for values from (2000) to (3000); + trigpart3 for values from (2000) to (3000); drop table trigpart3; @@ -1964,14 +1877,14 @@ drop table trigpart; drop function trigger_nothing(); create table parted_stmt_trig (a int) -partition by LIST(a); +partition by list(a); create table parted_stmt_trig1 partition of parted_stmt_trig for values in (1); create table parted_stmt_trig2 partition of parted_stmt_trig for values in (2); create table parted2_stmt_trig (a int) -partition by LIST(a); +partition by list(a); create table parted2_stmt_trig1 partition of parted2_stmt_trig @@ -1984,15 +1897,15 @@ for values in (2); create or replace function trigger_notice() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger % on % % % for %', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL; if TG_LEVEL = 'ROW' then return NEW; end if; return null; end; -$function$; + $$; create trigger trig_ins_before before insert @@ -2120,23 +2033,13 @@ on parted2_stmt_trig for each statement execute function trigger_notice(); -with -ins (a) -as ( - insert into parted2_stmt_trig - values (1), (2) - returning a -) +with ins (a) as (insert into parted2_stmt_trig values (1), (2) returning a) insert into parted_stmt_trig select a from ins returning cast(tableoid as regclass), a; -with -upd -as ( - update parted2_stmt_trig set a = a -) +with upd as (update parted2_stmt_trig set a = a) update parted_stmt_trig set a = a; @@ -2209,7 +2112,7 @@ insert into parted_trig values (50), (1500); drop table parted_trig; create table parted_trig (a int) -partition by LIST(a); +partition by list(a); create table parted_trig1 partition of parted_trig for values in (1); @@ -2220,8 +2123,8 @@ insert into parted_trig values (1); create or replace function trigger_notice() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger % on % % % for %', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL; if TG_LEVEL = 'ROW' then if TG_OP = 'DELETE' then @@ -2232,7 +2135,7 @@ begin end if; return null; end; -$function$; + $$; create trigger parted_trig_before_stmt before insert or delete or update @@ -2263,15 +2166,15 @@ update parted_trig set a = 2 where a = 1; drop table parted_trig; create table parted_trig (a int) -partition by LIST(a); +partition by list(a); create table parted_trig1 partition of parted_trig for values in (1); create or replace function trigger_notice() returns trigger language plpgsql -as $function$ -declare +as $$ + declare arg1 text = TG_ARGV[0]; arg2 integer = TG_ARGV[1]; begin @@ -2279,7 +2182,7 @@ declare TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL, arg1, arg2; return null; end; -$function$; + $$; create trigger aaa after insert @@ -2301,18 +2204,16 @@ insert into parted_trig values (1), (2), (3); drop table parted_trig; create function bark(text) -returns boolean +returns bool language plpgsql immutable -as $function$ -begin raise notice '% <- woof!', $1; return true; end; -$function$; +as $$ begin raise notice '% <- woof!', $1; return true; end; $$; create or replace function trigger_notice_ab() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger % on % % % for %: (a,b)=(%,%)', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL, NEW.a, NEW.b; @@ -2321,7 +2222,7 @@ begin end if; return null; end; -$function$; + $$; create table parted_irreg_ancestor ( fd text, @@ -2351,8 +2252,7 @@ alter table parted_irreg alter table parted_irreg_ancestor attach partition - parted_irreg - for values from ('aaaa') to ('zzzz'); + parted_irreg for values from ('aaaa') to ('zzzz'); create table parted1_irreg ( b text, @@ -2365,8 +2265,7 @@ alter table parted1_irreg alter table parted_irreg attach partition - parted1_irreg - for values from ('aaaa') to ('bbbb'); + parted1_irreg for values from ('aaaa') to ('bbbb'); create trigger parted_trig after insert @@ -2394,24 +2293,24 @@ create table parted ( b int, c text ) -partition by LIST(a); +partition by list(a); create table parted_1 partition of parted for values in (1) -partition by LIST(b); +partition by list(b); create table parted_1_1 partition of parted_1 for values in (1); create function parted_trigfunc() returns trigger language plpgsql -as $function$ +as $$ begin new.a = new.a + 1; return new; end; -$function$; +$$; insert into parted values (1, 1, 'uno uno v1'); @@ -2428,12 +2327,12 @@ update parted set c = c || 'v3'; create or replace function parted_trigfunc() returns trigger language plpgsql -as $function$ +as $$ begin new.b = new.b + 1; return new; end; -$function$; +$$; insert into parted values (1, 1, 'uno uno v4'); @@ -2442,12 +2341,12 @@ update parted set c = c || 'v5'; create or replace function parted_trigfunc() returns trigger language plpgsql -as $function$ +as $$ begin new.c = new.c || ' did '|| TG_OP; return new; end; -$function$; +$$; insert into parted values (1, 1, 'uno uno'); @@ -2468,12 +2367,12 @@ select cast(tableoid as regclass), * from parted; create or replace function parted_trigfunc2() returns trigger language plpgsql -as $function$ +as $$ begin new.a = new.a + 1; return new; end; -$function$; +$$; create trigger t2 before update @@ -2502,17 +2401,17 @@ create table parted ( b int, c text ) -partition by LIST((a + b)); +partition by list((a + b)); create or replace function parted_trigfunc() returns trigger language plpgsql -as $function$ +as $$ begin new.a = new.a + new.b; return new; end; -$function$; +$$; create table parted_1 partition of parted for values in (1, 2); @@ -2550,8 +2449,7 @@ partition by range(b); alter table parted_constr_ancestor attach partition - parted_constr - for values from ('aaaa') to ('zzzz'); + parted_constr for values from ('aaaa') to ('zzzz'); create table parted1_constr ( a int, @@ -2560,8 +2458,7 @@ create table parted1_constr ( alter table parted_constr attach partition - parted1_constr - for values from ('aaaa') to ('bbbb'); + parted1_constr for values from ('aaaa') to ('bbbb'); create constraint trigger parted_trig after insert @@ -2615,8 +2512,7 @@ alter table parted_trigger_2 alter table parted_trigger attach partition - parted_trigger_2 - for values from (1000) to (2000); + parted_trigger_2 for values from (1000) to (2000); create trigger parted_trigger after update @@ -2641,8 +2537,7 @@ for values from (3) to (5); alter table parted_trigger attach partition - parted_trigger_3 - for values from (2000) to (3000); + parted_trigger_3 for values from (2000) to (3000); insert into parted_trigger values @@ -2691,8 +2586,7 @@ alter table parted_trigger_2 alter table parted_trigger attach partition - parted_trigger_2 - for values from (1000) to (2000); + parted_trigger_2 for values from (1000) to (2000); create constraint trigger parted_trigger after update @@ -2724,8 +2618,7 @@ for values from (3) to (5); alter table parted_trigger attach partition - parted_trigger_3 - for values from (2000) to (3000); + parted_trigger_3 for values from (2000) to (3000); select tgname, @@ -2735,14 +2628,10 @@ select cast(c.conrelid as regclass), cast(c.confrelid as regclass) from - pg_trigger as t - inner join - pg_constraint as c - on t.tgconstraint = c.oid + pg_trigger as t inner join pg_constraint as c on t.tgconstraint = c.oid where tgname = 'parted_trigger' -order by cast(cast(t.tgrelid as regclass) - as text); +order by cast(cast(t.tgrelid as regclass) as text); drop table parted_referenced, parted_trigger, unparted_trigger; @@ -2767,8 +2656,7 @@ alter table parted_trigger_2 alter table parted_trigger attach partition - parted_trigger_2 - for values from (1000) to (2000); + parted_trigger_2 for values from (1000) to (2000); create trigger parted_trigger after update of b @@ -2792,15 +2680,10 @@ for values from (4) to (8); alter table parted_trigger attach partition - parted_trigger_3 - for values from (2000) to (3000); + parted_trigger_3 for values from (2000) to (3000); insert into parted_trigger -values - (0, 'a'), - (1000, 'c'), - (2000, 'e'), - (2001, 'eeee'); +values (0, 'a'), (1000, 'c'), (2000, 'e'), (2001, 'eeee'); update parted_trigger set a = a + 2; @@ -2816,7 +2699,7 @@ partition by range(a); create table trg_clone1 partition of trg_clone for values from (0) to (1000); alter table trg_clone - add constraint "uniq" unique (a) deferrable; + add constraint uniq unique (a) deferrable; create table trg_clone2 partition of trg_clone for values from (1000) to (2000); @@ -2831,7 +2714,7 @@ for values from (2000) to (2100); select cast(tgrelid as regclass), - COUNT(*) + count(*) from pg_trigger where @@ -2852,9 +2735,7 @@ inherits (parent); create function trig_nothing() returns trigger language plpgsql -as $function$ -begin return null; end -$function$; +as $$ begin return null; end $$; create trigger tg after insert @@ -2878,10 +2759,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text); alter table only parent @@ -2894,16 +2772,13 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text); drop table parent, child1; create table parent (a int) -partition by LIST(a); +partition by list(a); create table child1 partition of parent for values in (1); @@ -2926,10 +2801,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgname; @@ -2946,10 +2818,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgname; @@ -2963,10 +2832,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgname; @@ -2980,10 +2846,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgname; @@ -2993,7 +2856,7 @@ create table parent ( a int primary key, f int references parent ) -partition by LIST(a); +partition by list(a); create table child1 partition of parent for values in (1); @@ -3005,10 +2868,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgfoid; @@ -3023,10 +2883,7 @@ select from pg_trigger where - tgrelid - in ( - cast('parent' as regclass), cast('child1' as regclass) - ) + tgrelid in (cast('parent' as regclass), cast('child1' as regclass)) order by cast(cast(tgrelid as regclass) as text), tgfoid; @@ -3040,9 +2897,7 @@ create table trgfire1 partition of trgfire for values from (1) to (10); create or replace function tgf() returns trigger language plpgsql -as $function$ -begin raise exception 'except'; end -$function$; +as $$ begin raise exception 'except'; end $$; create trigger tg after insert on trgfire for each row execute function tgf(); @@ -3068,14 +2923,14 @@ insert into trgfire values (21); create table trgfire4 partition of trgfire for values from (30) to (40) -partition by LIST(i); +partition by list(i); create table trgfire4_30 partition of trgfire4 for values in (30); insert into trgfire values (30); create table trgfire5 (like trgfire) -partition by LIST(i); +partition by list(i); create table trgfire5_40 partition of trgfire5 for values in (40); @@ -3093,12 +2948,7 @@ from where cast(tgrelid as regclass) in ( - select - oid - from - pg_class - where - relname like 'trgfire%' + select oid from pg_class where relname like 'trgfire%' ) order by cast(cast(tgrelid as regclass) as text); @@ -3122,45 +2972,45 @@ drop function tgf(); create or replace function dump_insert() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, new table = %', TG_NAME, (select string_agg(new_table::text, ', ' order by a) from new_table); return null; end; -$function$; +$$; create or replace function dump_update() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, old table = %, new table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by a) from old_table), (select string_agg(new_table::text, ', ' order by a) from new_table); return null; end; -$function$; +$$; create or replace function dump_delete() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, old table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by a) from old_table); return null; end; -$function$; +$$; create table parent ( a text, b int ) -partition by LIST(a); +partition by list(a); create table child1 partition of parent for values in ('AAA'); @@ -3288,10 +3138,7 @@ select from information_schema.triggers where - event_object_table - in ( - 'parent', 'child1', 'child2', 'child3' - ) + event_object_table in ('parent', 'child1', 'child2', 'child3') order by trigger_name collate "C", 2; @@ -3352,12 +3199,12 @@ copy parent (a, b) from stdout; create or replace function intercept_insert() returns trigger language plpgsql -as $function$ -begin +as $$ + begin new.b = new.b + 1000; return new; end; -$function$; +$$; create trigger intercept_insert_child3 before insert @@ -3377,7 +3224,7 @@ create table parent ( a text, b int ) -partition by LIST(a); +partition by list(a); create table child partition of parent for values in ('AAA'); @@ -3414,27 +3261,27 @@ drop table child, parent; create or replace function dump_update_new() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, new table = %', TG_NAME, (select string_agg(new_table::text, ', ' order by a) from new_table); return null; end; -$function$; +$$; create or replace function dump_update_old() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, old table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by a) from old_table); return null; end; -$function$; +$$; create table trans_tab_parent (a text) -partition by LIST(a); +partition by list(a); create table trans_tab_child1 partition of trans_tab_parent @@ -3702,8 +3549,7 @@ referencing new table as new_table for each statement execute function dump_insert(); -with -wcte as (insert into table1 values (42)) +with wcte as (insert into table1 values (42)) insert into table2 values ('hello world'); @@ -3739,37 +3585,21 @@ execute function dump_update(); insert into my_table values (1, 'AAA'), (2, 'BBB') -on conflict -(a) -do -update -set b = my_table.b || ':' || excluded.b; +on conflict (a) do update set b = my_table.b || ':' || excluded.b; insert into my_table -values - (1, 'AAA'), - (2, 'BBB'), - (3, 'CCC'), - (4, 'DDD') -on conflict -(a) -do -update -set b = my_table.b || ':' || excluded.b; +values (1, 'AAA'), (2, 'BBB'), (3, 'CCC'), (4, 'DDD') +on conflict (a) do update set b = my_table.b || ':' || excluded.b; insert into my_table values (3, 'CCC'), (4, 'DDD') -on conflict -(a) -do -update -set b = my_table.b || ':' || excluded.b; +on conflict (a) do update set b = my_table.b || ':' || excluded.b; create table iocdu_tt_parted ( a int primary key, b text ) -partition by LIST(a); +partition by list(a); create table iocdu_tt_parted1 partition of iocdu_tt_parted for values in (1); @@ -3796,31 +3626,15 @@ execute function dump_update(); insert into iocdu_tt_parted values (1, 'AAA'), (2, 'BBB') -on conflict -(a) -do -update -set b = iocdu_tt_parted.b || ':' || excluded.b; +on conflict (a) do update set b = iocdu_tt_parted.b || ':' || excluded.b; insert into iocdu_tt_parted -values - (1, 'AAA'), - (2, 'BBB'), - (3, 'CCC'), - (4, 'DDD') -on conflict -(a) -do -update -set b = iocdu_tt_parted.b || ':' || excluded.b; +values (1, 'AAA'), (2, 'BBB'), (3, 'CCC'), (4, 'DDD') +on conflict (a) do update set b = iocdu_tt_parted.b || ':' || excluded.b; insert into iocdu_tt_parted values (3, 'CCC'), (4, 'DDD') -on conflict -(a) -do -update -set b = iocdu_tt_parted.b || ':' || excluded.b; +on conflict (a) do update set b = iocdu_tt_parted.b || ':' || excluded.b; drop table iocdu_tt_parted; @@ -3845,12 +3659,10 @@ create table my_table (a int); create function make_bogus_matview() returns trigger language plpgsql -as $function$ -begin +as $$ begin create materialized view transition_test_mv as select * from new_table; return new; -end -$function$; +end $$; create trigger make_bogus_matview after insert @@ -3873,11 +3685,7 @@ create table refd_table ( create table trig_table ( a int, b text, - foreign key - (a) - references refd_table - on DELETE cascade - on UPDATE cascade + foreign key (a) references refd_table on delete cascade on update cascade ); create trigger trig_table_before_trig @@ -3945,9 +3753,7 @@ drop table trig_table; create table self_ref ( a int primary key, - b int - references self_ref (a) - on DELETE cascade + b int references self_ref (a) on delete cascade ); create trigger self_ref_before_trig @@ -4015,11 +3821,7 @@ create table merge_source_table ( ); insert into merge_source_table -values - (1, 'initial1'), - (2, 'initial2'), - (3, 'initial3'), - (4, 'initial4'); +values (1, 'initial1'), (2, 'initial2'), (3, 'initial3'), (4, 'initial4'); drop table merge_source_table, merge_target_table; @@ -4034,22 +3836,20 @@ create table my_table (id int); create function funca() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'hello from funcA'; return null; -end; -$function$; +end; $$; create function funcb() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'hello from funcB'; return null; -end; -$function$; +end; $$; create trigger my_trig after insert @@ -4162,14 +3962,12 @@ drop function funca(); drop function funcb(); create table trigger_parted (a int primary key) -partition by LIST(a); +partition by list(a); create function trigger_parted_trigfunc() returns trigger language plpgsql -as $function$ -begin end; -$function$; +as $$ begin end; $$; create trigger aft_row after insert or update @@ -4180,7 +3978,7 @@ execute function trigger_parted_trigfunc(); create table trigger_parted_p1 partition of trigger_parted for values in (1) -partition by LIST(a); +partition by list(a); create table trigger_parted_p1_1 partition of trigger_parted_p1 @@ -4189,7 +3987,7 @@ for values in (1); create table trigger_parted_p2 partition of trigger_parted for values in (2) -partition by LIST(a); +partition by list(a); create table trigger_parted_p2_2 partition of trigger_parted_p2 @@ -4205,11 +4003,10 @@ create table convslot_test_parent (col1 text primary key); create table convslot_test_child ( col1 text primary key, - foreign key - (col1) - references convslot_test_parent (col1) - on DELETE cascade - on UPDATE cascade + foreign key (col1) + references convslot_test_parent (col1) + on delete cascade + on update cascade ); alter table convslot_test_child @@ -4226,26 +4023,24 @@ insert into convslot_test_child (col1) values ('3'); create function convslot_trig1() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'trigger = %, old_table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by col1) from old_table); return null; -end; -$function$; +end; $$; create function convslot_trig2() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'trigger = %, new table = %', TG_NAME, (select string_agg(new_table::text, ', ' order by col1) from new_table); return null; -end; -$function$; +end; $$; create trigger but_trigger after update @@ -4259,15 +4054,14 @@ update convslot_test_parent set col1 = col1 || '1'; create function convslot_trig3() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'trigger = %, old_table = %, new table = %', TG_NAME, (select string_agg(old_table::text, ', ' order by col1) from old_table), (select string_agg(new_table::text, ', ' order by col1) from new_table); return null; -end; -$function$; +end; $$; create trigger but_trigger2 after update @@ -4309,15 +4103,12 @@ create table convslot_test_part ( alter table convslot_test_parent attach partition - convslot_test_part - for values from (1) to (1000); + convslot_test_part for values from (1) to (1000); create function convslot_trig4() returns trigger language plpgsql -as $function$ -begin raise exception 'BOOM!'; end -$function$; +as $$begin raise exception 'BOOM!'; end$$; create trigger convslot_test_parent_update after update @@ -4361,9 +4152,7 @@ create table cho partition of middle for values from (6) to (10); create function f() returns trigger language plpgsql -as $function$ -begin return new; end; -$function$; +as $$ begin return new; end; $$; create trigger a after insert on grandparent for each row execute function f(); @@ -4372,25 +4161,12 @@ alter trigger a on grandparent rename to b; select cast(tgrelid as regclass), tgname, - ( - select - tgname - from - pg_trigger as tr - where - tr.oid = pg_trigger.tgparentid - ) + (select tgname from pg_trigger as tr where tr.oid = pg_trigger.tgparentid) as parent_tgname from pg_trigger where - tgrelid in - ( - select - relid - from - pg_partition_tree('grandparent') - ) + tgrelid in (select relid from pg_partition_tree('grandparent')) order by tgname, cast(cast(tgrelid as regclass) as text) collate "C"; @@ -4413,25 +4189,12 @@ alter trigger p on grandparent rename to q; select cast(tgrelid as regclass), tgname, - ( - select - tgname - from - pg_trigger as tr - where - tr.oid = pg_trigger.tgparentid - ) + (select tgname from pg_trigger as tr where tr.oid = pg_trigger.tgparentid) as parent_tgname from pg_trigger where - tgrelid in - ( - select - relid - from - pg_partition_tree('grandparent') - ) + tgrelid in (select relid from pg_partition_tree('grandparent')) order by tgname, cast(cast(tgrelid as regclass) as text) collate "C"; @@ -4467,18 +4230,18 @@ create role regress_fn_owner; create function whoami() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'I am %', current_user; return null; end; -$function$; +$$; alter function whoami() owner to regress_fn_owner; create table defer_trig (id int); -grant INSERT on table defer_trig to public; +grant insert on table defer_trig to public; create constraint trigger whoami after insert @@ -4521,13 +4284,13 @@ alter function whoami() security invoker; create or replace function whoami() returns trigger language plpgsql -as $function$ +as $$ begin raise notice 'I am %', current_user; perform 1 / 0; return null; end; -$function$; +$$; begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__truncate_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__truncate_100.snap index 0c2639366..6c010c6d0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__truncate_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__truncate_100.snap @@ -82,11 +82,7 @@ truncate trunc_c, truncate_a, trunc_d, trunc_e; truncate trunc_c, truncate_a, trunc_d, trunc_e, trunc_b; -select * from truncate_a -union all -select * from trunc_c -union all -select * from trunc_b +select * from truncate_a union all select * from trunc_c union all select * from trunc_b union all select * from trunc_d; @@ -104,11 +100,7 @@ insert into trunc_e values (1, 1); truncate trunc_c cascade; -select * from truncate_a -union all -select * from trunc_c -union all -select * from trunc_b +select * from truncate_a union all select * from trunc_c union all select * from trunc_b union all select * from trunc_d; @@ -213,7 +205,7 @@ create table trunc_trigger_log ( create function trunctrigger() returns trigger language plpgsql -as $function$ +as $$ declare c bigint; begin execute 'select count(*) from ' || quote_ident(tg_table_name) into c; @@ -221,7 +213,7 @@ begin (TG_OP, TG_LEVEL, TG_WHEN, TG_ARGV[0], tg_table_name, c); return null; end; -$function$; +$$; insert into trunc_trigger_test values (1, 'foo', 'bar'), (2, 'baz', 'quux'); @@ -231,13 +223,13 @@ on trunc_trigger_test for each statement execute function trunctrigger("before trigger truncate"); -select COUNT(*) as "Row count in test table" from trunc_trigger_test; +select count(*) as "Row count in test table" from trunc_trigger_test; select * from trunc_trigger_log; truncate trunc_trigger_test; -select COUNT(*) as "Row count in test table" from trunc_trigger_test; +select count(*) as "Row count in test table" from trunc_trigger_test; select * from trunc_trigger_log; @@ -253,13 +245,13 @@ on trunc_trigger_test for each statement execute function trunctrigger("after trigger truncate"); -select COUNT(*) as "Row count in test table" from trunc_trigger_test; +select count(*) as "Row count in test table" from trunc_trigger_test; select * from trunc_trigger_log; truncate trunc_trigger_test; -select COUNT(*) as "Row count in test table" from trunc_trigger_test; +select count(*) as "Row count in test table" from trunc_trigger_test; select * from trunc_trigger_log; @@ -348,7 +340,7 @@ create table truncparted ( a int, b char(1) ) -partition by LIST(a); +partition by list(a); truncate only truncparted; @@ -365,24 +357,24 @@ drop table truncparted; create function tp_ins_data() returns void language plpgsql -as $function$ -BEGIN +as $$ + BEGIN INSERT INTO truncprim VALUES (1), (100), (150); INSERT INTO truncpart VALUES (1), (100), (150); END -$function$; +$$; create function tp_chk_data(out pktb regclass, out pkval int, out fktb regclass, out fkval int) returns setof record language plpgsql -as $function$ -BEGIN +as $$ + BEGIN RETURN QUERY SELECT pk.tableoid::regclass, pk.a, fk.tableoid::regclass, fk.a FROM truncprim pk FULL JOIN truncpart fk USING (a) ORDER BY 2, 4; END -$function$; +$$; create table truncprim (a int primary key); @@ -443,7 +435,7 @@ insert into trunc_a values (0), (5), (10), (15), (20), (25); create table ref_b ( b int primary key, - a int references trunc_a (a) on DELETE cascade + a int references trunc_a (a) on delete cascade ); insert into ref_b values (10, 0), (50, 5), (100, 10), (150, 15); @@ -456,7 +448,7 @@ drop table ref_b; create table ref_c ( c int primary key, - a int references trunc_a (a) on DELETE cascade + a int references trunc_a (a) on delete cascade ) partition by range(c); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__truncate_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__truncate_80.snap index 816a9a6ec..d2fa190f9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__truncate_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__truncate_80.snap @@ -82,9 +82,7 @@ truncate trunc_c, truncate_a, trunc_d, trunc_e; truncate trunc_c, truncate_a, trunc_d, trunc_e, trunc_b; -select * from truncate_a -union all -select * from trunc_c +select * from truncate_a union all select * from trunc_c union all select * from trunc_b union all @@ -104,9 +102,7 @@ insert into trunc_e values (1, 1); truncate trunc_c cascade; -select * from truncate_a -union all -select * from trunc_c +select * from truncate_a union all select * from trunc_c union all select * from trunc_b union all @@ -213,7 +209,7 @@ create table trunc_trigger_log ( create function trunctrigger() returns trigger language plpgsql -as $function$ +as $$ declare c bigint; begin execute 'select count(*) from ' || quote_ident(tg_table_name) into c; @@ -221,7 +217,7 @@ begin (TG_OP, TG_LEVEL, TG_WHEN, TG_ARGV[0], tg_table_name, c); return null; end; -$function$; +$$; insert into trunc_trigger_test values (1, 'foo', 'bar'), (2, 'baz', 'quux'); @@ -231,13 +227,13 @@ on trunc_trigger_test for each statement execute function trunctrigger("before trigger truncate"); -select COUNT(*) as "Row count in test table" from trunc_trigger_test; +select count(*) as "Row count in test table" from trunc_trigger_test; select * from trunc_trigger_log; truncate trunc_trigger_test; -select COUNT(*) as "Row count in test table" from trunc_trigger_test; +select count(*) as "Row count in test table" from trunc_trigger_test; select * from trunc_trigger_log; @@ -253,13 +249,13 @@ on trunc_trigger_test for each statement execute function trunctrigger("after trigger truncate"); -select COUNT(*) as "Row count in test table" from trunc_trigger_test; +select count(*) as "Row count in test table" from trunc_trigger_test; select * from trunc_trigger_log; truncate trunc_trigger_test; -select COUNT(*) as "Row count in test table" from trunc_trigger_test; +select count(*) as "Row count in test table" from trunc_trigger_test; select * from trunc_trigger_log; @@ -273,8 +269,7 @@ create sequence truncate_a_id1 start with 33; create table truncate_a ( id serial, - id1 int - default nextval('truncate_a_id1') + id1 int default nextval('truncate_a_id1') ); alter sequence truncate_a_id1 owned by truncate_a.id1; @@ -349,7 +344,7 @@ create table truncparted ( a int, b char(1) ) -partition by LIST(a); +partition by list(a); truncate only truncparted; @@ -366,12 +361,12 @@ drop table truncparted; create function tp_ins_data() returns void language plpgsql -as $function$ -BEGIN +as $$ + BEGIN INSERT INTO truncprim VALUES (1), (100), (150); INSERT INTO truncpart VALUES (1), (100), (150); END -$function$; +$$; create function tp_chk_data( @@ -382,14 +377,14 @@ tp_chk_data( ) returns setof record language plpgsql -as $function$ -BEGIN +as $$ + BEGIN RETURN QUERY SELECT pk.tableoid::regclass, pk.a, fk.tableoid::regclass, fk.a FROM truncprim pk FULL JOIN truncpart fk USING (a) ORDER BY 2, 4; END -$function$; +$$; create table truncprim (a int primary key); @@ -455,8 +450,7 @@ insert into trunc_a values (0), (5), (10), (15), (20), (25); create table ref_b ( b int primary key, - a int - references trunc_a (a) on DELETE cascade + a int references trunc_a (a) on delete cascade ); insert into ref_b values (10, 0), (50, 5), (100, 10), (150, 15); @@ -469,8 +463,7 @@ drop table ref_b; create table ref_c ( c int primary key, - a int - references trunc_a (a) on DELETE cascade + a int references trunc_a (a) on delete cascade ) partition by range(c); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsearch_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsearch_100.snap index 7a2e3536e..6e5a2e0af 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsearch_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsearch_100.snap @@ -9,11 +9,7 @@ select from pg_ts_parser where - prsnamespace = 0 or - prsstart = 0 or - prstoken = 0 or - prsend = 0 or - prslextype = 0; + prsnamespace = 0 or prsstart = 0 or prstoken = 0 or prsend = 0 or prslextype = 0; select oid, dictname from pg_ts_dict where dictnamespace = 0 or dictowner = 0 or dicttemplate = 0; @@ -26,14 +22,7 @@ select mapcfg, maptokentype, mapseqno from pg_ts_config_map where mapcfg = 0 or select * from - ( - select - oid as cfgid, - (ts_token_type(cfgparser)).tokid as tokid - from - pg_ts_config - ) - as tt + (select oid as cfgid, (ts_token_type(cfgparser)).tokid as tokid from pg_ts_config) as tt right outer join pg_ts_config_map as m on tt.cfgid = m.mapcfg and tt.tokid = m.maptokentype @@ -49,55 +38,55 @@ copy test_tsvector from 'filename'; analyze test_tsvector; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; -create index "wowidx" on test_tsvector using gist (a); +create index wowidx on test_tsvector using gist (a); set enable_seqscan = off; @@ -105,227 +94,227 @@ set enable_indexscan = 'on'; set enable_bitmapscan = off; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; set enable_indexscan = off; set enable_bitmapscan = 'on'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; -create index "wowidx1" on test_tsvector using gist (a tsvector_ops(foo = 1)); +create index wowidx1 on test_tsvector using gist (a tsvector_ops(foo = 1)); -create index "wowidx1" on test_tsvector using gist (a tsvector_ops(siglen = 0)); +create index wowidx1 on test_tsvector using gist (a tsvector_ops(siglen = 0)); -create index "wowidx1" on test_tsvector using gist (a tsvector_ops(siglen = 2048)); +create index wowidx1 on test_tsvector using gist (a tsvector_ops(siglen = 2048)); -create index "wowidx1" on test_tsvector using gist (a tsvector_ops(siglen = 100, foo = bar)); +create index wowidx1 on test_tsvector using gist (a tsvector_ops(siglen = 100, foo = bar)); -create index "wowidx1" on test_tsvector using gist (a tsvector_ops(siglen = 100, siglen = 200)); +create index wowidx1 on test_tsvector using gist (a tsvector_ops(siglen = 100, siglen = 200)); -create index "wowidx2" on test_tsvector using gist (a tsvector_ops(siglen = 1)); +create index wowidx2 on test_tsvector using gist (a tsvector_ops(siglen = 1)); drop index wowidx; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; drop index wowidx2; -create index "wowidx" on test_tsvector using gist (a tsvector_ops(siglen = 484)); +create index wowidx on test_tsvector using gist (a tsvector_ops(siglen = 484)); -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; reset enable_seqscan; @@ -335,67 +324,67 @@ reset enable_bitmapscan; drop index wowidx; -create index "wowidx" on test_tsvector using gin (a); +create index wowidx on test_tsvector using gin (a); set enable_seqscan = off; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; -select COUNT(*) from test_tsvector where a @@ '!qh'; +select count(*) from test_tsvector where a @@ '!qh'; -select COUNT(*) from test_tsvector where a @@ '!qh'; +select count(*) from test_tsvector where a @@ '!qh'; -select COUNT(*) from test_tsvector where a @@ 'wr' and a @@ '!qh'; +select count(*) from test_tsvector where a @@ 'wr' and a @@ '!qh'; -select COUNT(*) from test_tsvector where a @@ 'wr' and a @@ '!qh'; +select count(*) from test_tsvector where a @@ 'wr' and a @@ '!qh'; reset enable_seqscan; @@ -571,11 +560,7 @@ select to_tsquery('english', 'foo <-> a <-> the <-> bar'); select phraseto_tsquery('english', 'PostgreSQL can be extended by the user in many ways'); -select - ts_rank_cd( - to_tsvector( - 'english', - ' +select ts_rank_cd(to_tsvector('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -585,16 +570,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -' - ), - to_tsquery('english', 'paint&water') - ); +'), to_tsquery('english', 'paint&water')); -select - ts_rank_cd( - to_tsvector( - 'english', - ' +select ts_rank_cd(to_tsvector('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -604,16 +582,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -' - ), - to_tsquery('english', 'breath&motion&water') - ); +'), to_tsquery('english', 'breath&motion&water')); -select - ts_rank_cd( - to_tsvector( - 'english', - ' +select ts_rank_cd(to_tsvector('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -623,16 +594,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -' - ), - to_tsquery('english', 'ocean') - ); +'), to_tsquery('english', 'ocean')); -select - ts_rank_cd( - to_tsvector( - 'english', - ' +select ts_rank_cd(to_tsvector('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -642,24 +606,17 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -' - ), - to_tsquery('english', 'painted <-> Ship') - ); +'), to_tsquery('english', 'painted <-> Ship')); select ts_rank_cd(strip(to_tsvector('both stripped')), to_tsquery('both & stripped')); select ts_rank_cd( - to_tsvector('unstripped') || - strip(to_tsvector('stripped')), + to_tsvector('unstripped') || strip(to_tsvector('stripped')), to_tsquery('unstripped & stripped') ); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -669,14 +626,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'paint&water') - ); +', to_tsquery('english', 'paint&water')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -686,14 +638,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'breath&motion&water') - ); +', to_tsquery('english', 'breath&motion&water')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -703,14 +650,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'ocean') - ); +', to_tsquery('english', 'ocean')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -720,14 +662,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'day & drink') - ); +', to_tsquery('english', 'day & drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -737,14 +674,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'day | drink') - ); +', to_tsquery('english', 'day | drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -754,14 +686,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'day | !drink') - ); +', to_tsquery('english', 'day | !drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -771,14 +698,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'painted <-> Ship & drink') - ); +', to_tsquery('english', 'painted <-> Ship & drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -788,14 +710,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'painted <-> Ship | drink') - ); +', to_tsquery('english', 'painted <-> Ship | drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -805,14 +722,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'painted <-> Ship | !drink') - ); +', to_tsquery('english', 'painted <-> Ship | !drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -822,14 +734,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - phraseto_tsquery('english', 'painted Ocean') - ); +', phraseto_tsquery('english', 'painted Ocean')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -839,19 +746,13 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - phraseto_tsquery( - 'english', - 'idle as a painted Ship' - ) - ); +', phraseto_tsquery('english', 'idle as a painted Ship')); select ts_headline( 'english', 'Lorem ipsum urna. Nullam nullam ullamcorper urna.', - to_tsquery('english', 'Lorem') && - phraseto_tsquery('english', 'ullamcorper urna'), + to_tsquery('english', 'Lorem') && phraseto_tsquery('english', 'ullamcorper urna'), 'MaxWords=100, MinWords=1' ); @@ -863,10 +764,7 @@ select 'MaxWords=100, MinWords=5' ); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' @@ -877,10 +775,7 @@ ff-bg document.write(15); -', - to_tsquery('english', 'sea&foo'), - 'HighlightAll=true' - ); +', to_tsquery('english', 'sea&foo'), 'HighlightAll=true'); select ts_headline('simple', cast('1 2 3 1 3' as text), '1 <-> 3', 'MaxWords=2, MinWords=1'); @@ -888,10 +783,7 @@ select ts_headline('simple', cast('1 2 3 1 3' as text), '1 & 3', 'MaxWords=4, Mi select ts_headline('simple', cast('1 2 3 1 3' as text), '1 <-> 3', 'MaxWords=4, MinWords=1'); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -901,15 +793,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'ocean'), - 'MaxFragments=1' - ); +', to_tsquery('english', 'ocean'), 'MaxFragments=1'); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -919,15 +805,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'Coleridge & stuck'), - 'MaxFragments=2' - ); +', to_tsquery('english', 'Coleridge & stuck'), 'MaxFragments=2'); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -937,15 +817,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'ocean & seahorse'), - 'MaxFragments=1' - ); +', to_tsquery('english', 'ocean & seahorse'), 'MaxFragments=1'); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -955,17 +829,13 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'Coleridge & stuck'), - 'MaxFragments=2,FragmentDelimiter=***' - ); +', to_tsquery('english', 'Coleridge & stuck'), 'MaxFragments=2,FragmentDelimiter=***'); select ts_headline( 'english', 'Lorem ipsum urna. Nullam nullam ullamcorper urna.', - to_tsquery('english', 'Lorem') && - phraseto_tsquery('english', 'ullamcorper urna'), + to_tsquery('english', 'Lorem') && phraseto_tsquery('english', 'ullamcorper urna'), 'MaxFragments=100, MaxWords=100, MinWords=1' ); @@ -988,29 +858,29 @@ alter table test_tsquery update test_tsquery set sample = to_tsquery('english', cast(txtsample as text)); -select COUNT(*) from test_tsquery where keyword < 'new <-> york'; +select count(*) from test_tsquery where keyword < 'new <-> york'; -select COUNT(*) from test_tsquery where keyword <= 'new <-> york'; +select count(*) from test_tsquery where keyword <= 'new <-> york'; -select COUNT(*) from test_tsquery where keyword = 'new <-> york'; +select count(*) from test_tsquery where keyword = 'new <-> york'; -select COUNT(*) from test_tsquery where keyword >= 'new <-> york'; +select count(*) from test_tsquery where keyword >= 'new <-> york'; -select COUNT(*) from test_tsquery where keyword > 'new <-> york'; +select count(*) from test_tsquery where keyword > 'new <-> york'; -create unique index "bt_tsq" on test_tsquery using btree (keyword); +create unique index bt_tsq on test_tsquery using btree (keyword); set enable_seqscan = off; -select COUNT(*) from test_tsquery where keyword < 'new <-> york'; +select count(*) from test_tsquery where keyword < 'new <-> york'; -select COUNT(*) from test_tsquery where keyword <= 'new <-> york'; +select count(*) from test_tsquery where keyword <= 'new <-> york'; -select COUNT(*) from test_tsquery where keyword = 'new <-> york'; +select count(*) from test_tsquery where keyword = 'new <-> york'; -select COUNT(*) from test_tsquery where keyword >= 'new <-> york'; +select count(*) from test_tsquery where keyword >= 'new <-> york'; -select COUNT(*) from test_tsquery where keyword > 'new <-> york'; +select count(*) from test_tsquery where keyword > 'new <-> york'; reset enable_seqscan; @@ -1030,8 +900,7 @@ select ts_rewrite('moscow & hotel', cast('SELECT keyword, sample FROM test_tsque select ts_rewrite( 'bar & qq & foo & (new <-> york)', - cast('SELECT keyword, sample FROM test_tsquery' - as text) + cast('SELECT keyword, sample FROM test_tsquery' as text) ); select ts_rewrite('moscow', 'SELECT keyword, sample FROM test_tsquery'); @@ -1045,11 +914,7 @@ select ts_rewrite('1 & (2 <-> 3)', cast('SELECT keyword, sample FROM test_tsquer select ts_rewrite('1 & (2 <2> 3)', cast('SELECT keyword, sample FROM test_tsquery' as text)); select - ts_rewrite( - '5 <-> (1 & (2 <-> 3))', - cast('SELECT keyword, sample FROM test_tsquery' - as text) - ); + ts_rewrite('5 <-> (1 & (2 <-> 3))', cast('SELECT keyword, sample FROM test_tsquery' as text)); select ts_rewrite('5 <-> (6 | 8)', cast('SELECT keyword, sample FROM test_tsquery' as text)); @@ -1066,62 +931,36 @@ select keyword from test_tsquery where keyword <@ 'new'; select keyword from test_tsquery where keyword <@ 'moscow'; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow & hotel') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery( - 'english', - 'bar & qq & foo & (new <-> york)' - ) - as query; + to_tsquery('english', 'bar & qq & foo & (new <-> york)') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow & hotel') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery( - 'english', - 'bar & qq & foo & (new <-> york)' - ) - as query; + to_tsquery('english', 'bar & qq & foo & (new <-> york)') as query; -create index "qq" on test_tsquery using gist (keyword tsquery_ops); +create index qq on test_tsquery using gist (keyword tsquery_ops); set enable_seqscan = off; @@ -1134,60 +973,34 @@ select keyword from test_tsquery where keyword <@ 'new'; select keyword from test_tsquery where keyword <@ 'moscow'; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow & hotel') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery( - 'english', - 'bar & qq & foo & (new <-> york)' - ) - as query; + to_tsquery('english', 'bar & qq & foo & (new <-> york)') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow & hotel') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery( - 'english', - 'bar & qq & foo & (new <-> york)' - ) - as query; + to_tsquery('english', 'bar & qq & foo & (new <-> york)') as query; select ts_rewrite(tsquery_phrase('foo', 'foo'), 'foo', 'bar | baz'); @@ -1221,19 +1034,19 @@ execute function tsvector_update_trigger(a, "pg_catalog.english", t); -select COUNT(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); +select count(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); insert into test_tsvector (t) values ('345 qwerty'); -select COUNT(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); +select count(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); update test_tsvector set t = null where t = '345 qwerty'; -select COUNT(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); +select count(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); insert into test_tsvector (t) values ('345 qwerty'); -select COUNT(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); +select count(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); select * from test_tsquery, to_tsquery('new') as q where txtsample @@ q; @@ -1241,7 +1054,7 @@ select * from test_tsquery, to_tsquery('english', 'new') as q where txtsample @@ create temporary table pendtest (ts tsvector); -create index "pendtest_idx" on pendtest using gin (ts); +create index pendtest_idx on pendtest using gin (ts); insert into pendtest values (to_tsvector('Lore ipsam')); @@ -1263,7 +1076,7 @@ insert into phrase_index_test values ('A fat cat has just eaten a rat.'); insert into phrase_index_test values (to_tsvector('english', 'A fat cat has just eaten a rat.')); -create index "phrase_index_test_idx" on phrase_index_test using gin (fts); +create index phrase_index_test_idx on phrase_index_test using gin (fts); set enable_seqscan = off; @@ -1399,17 +1212,11 @@ select websearch_to_tsquery('english', '"a fat cat" ate a rat'); select to_tsvector('english', 'A fat cat ate a rat') @@ - websearch_to_tsquery( - 'english', - '"a fat cat" ate a rat' - ); + websearch_to_tsquery('english', '"a fat cat" ate a rat'); select to_tsvector('english', 'A fat grey cat ate a rat') @@ - websearch_to_tsquery( - 'english', - '"a fat cat" ate a rat' - ); + websearch_to_tsquery('english', '"a fat cat" ate a rat'); select websearch_to_tsquery(''''); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsearch_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsearch_80.snap index 595f6c0c9..4e0ff5778 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsearch_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsearch_80.snap @@ -21,9 +21,7 @@ select from pg_ts_dict where - dictnamespace = 0 or - dictowner = 0 or - dicttemplate = 0; + dictnamespace = 0 or dictowner = 0 or dicttemplate = 0; select oid, @@ -39,9 +37,7 @@ select from pg_ts_config where - cfgnamespace = 0 or - cfgowner = 0 or - cfgparser = 0; + cfgnamespace = 0 or cfgowner = 0 or cfgparser = 0; select mapcfg, @@ -58,16 +54,14 @@ from ( select oid as cfgid, - (ts_token_type(cfgparser)).tokid - as tokid + (ts_token_type(cfgparser)).tokid as tokid from pg_ts_config ) as tt right outer join pg_ts_config_map as m - on tt.cfgid = m.mapcfg and - tt.tokid = m.maptokentype + on tt.cfgid = m.mapcfg and tt.tokid = m.maptokentype where tt.cfgid is null or tt.tokid is null; @@ -80,55 +74,55 @@ copy test_tsvector from 'filename'; analyze test_tsvector; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; -create index "wowidx" on test_tsvector using gist (a); +create index wowidx on test_tsvector using gist (a); set enable_seqscan = off; @@ -136,249 +130,233 @@ set enable_indexscan = 'on'; set enable_bitmapscan = off; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; set enable_indexscan = off; set enable_bitmapscan = 'on'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; -create index "wowidx1" on test_tsvector using gist (a tsvector_ops(foo = 1)); +create index wowidx1 on test_tsvector using gist (a tsvector_ops(foo = 1)); -create index "wowidx1" on test_tsvector using gist (a tsvector_ops(siglen = 0)); +create index wowidx1 on test_tsvector using gist (a tsvector_ops(siglen = 0)); -create index "wowidx1" -on test_tsvector -using gist -( +create index wowidx1 on test_tsvector using gist ( a tsvector_ops(siglen = 2048) ); -create index "wowidx1" -on test_tsvector -using gist -( +create index wowidx1 on test_tsvector using gist ( a tsvector_ops(siglen = 100, foo = bar) ); -create index "wowidx1" -on test_tsvector -using gist -( - a - tsvector_ops(siglen = 100, - siglen = 200) +create index wowidx1 on test_tsvector using gist ( + a tsvector_ops(siglen = 100, siglen = 200) ); -create index "wowidx2" on test_tsvector using gist (a tsvector_ops(siglen = 1)); +create index wowidx2 on test_tsvector using gist (a tsvector_ops(siglen = 1)); drop index wowidx; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; drop index wowidx2; -create index "wowidx" -on test_tsvector -using gist -( - a tsvector_ops(siglen = 484) -); +create index wowidx on test_tsvector using gist (a tsvector_ops(siglen = 484)); -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; reset enable_seqscan; @@ -388,67 +366,67 @@ reset enable_bitmapscan; drop index wowidx; -create index "wowidx" on test_tsvector using gin (a); +create index wowidx on test_tsvector using gin (a); set enable_seqscan = off; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr|qh'; +select count(*) from test_tsvector where a @@ 'wr|qh'; -select COUNT(*) from test_tsvector where a @@ 'wr&qh'; +select count(*) from test_tsvector where a @@ 'wr&qh'; -select COUNT(*) from test_tsvector where a @@ 'eq&yt'; +select count(*) from test_tsvector where a @@ 'eq&yt'; -select COUNT(*) from test_tsvector where a @@ 'eq|yt'; +select count(*) from test_tsvector where a @@ 'eq|yt'; -select COUNT(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; +select count(*) from test_tsvector where a @@ '(eq&yt)|(wr&qh)'; -select COUNT(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; +select count(*) from test_tsvector where a @@ '(eq|yt)&(wr|qh)'; -select COUNT(*) from test_tsvector where a @@ 'w:*|q:*'; +select count(*) from test_tsvector where a @@ 'w:*|q:*'; -select COUNT(*) from test_tsvector where a @@ any ('{wr,qh}'); +select count(*) from test_tsvector where a @@ any ('{wr,qh}'); -select COUNT(*) from test_tsvector where a @@ 'no_such_lexeme'; +select count(*) from test_tsvector where a @@ 'no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ '!no_such_lexeme'; +select count(*) from test_tsvector where a @@ '!no_such_lexeme'; -select COUNT(*) from test_tsvector where a @@ 'pl <-> yh'; +select count(*) from test_tsvector where a @@ 'pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ 'yh <-> pl'; +select count(*) from test_tsvector where a @@ 'yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ 'qe <2> qt'; +select count(*) from test_tsvector where a @@ 'qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> yh'; +select count(*) from test_tsvector where a @@ '!pl <-> yh'; -select COUNT(*) from test_tsvector where a @@ '!pl <-> !yh'; +select count(*) from test_tsvector where a @@ '!pl <-> !yh'; -select COUNT(*) from test_tsvector where a @@ '!yh <-> pl'; +select count(*) from test_tsvector where a @@ '!yh <-> pl'; -select COUNT(*) from test_tsvector where a @@ '!qe <2> qt'; +select count(*) from test_tsvector where a @@ '!qe <2> qt'; -select COUNT(*) from test_tsvector where a @@ '!(pl <-> yh)'; +select count(*) from test_tsvector where a @@ '!(pl <-> yh)'; -select COUNT(*) from test_tsvector where a @@ '!(yh <-> pl)'; +select count(*) from test_tsvector where a @@ '!(yh <-> pl)'; -select COUNT(*) from test_tsvector where a @@ '!(qe <2> qt)'; +select count(*) from test_tsvector where a @@ '!(qe <2> qt)'; -select COUNT(*) from test_tsvector where a @@ 'wd:A'; +select count(*) from test_tsvector where a @@ 'wd:A'; -select COUNT(*) from test_tsvector where a @@ 'wd:D'; +select count(*) from test_tsvector where a @@ 'wd:D'; -select COUNT(*) from test_tsvector where a @@ '!wd:A'; +select count(*) from test_tsvector where a @@ '!wd:A'; -select COUNT(*) from test_tsvector where a @@ '!wd:D'; +select count(*) from test_tsvector where a @@ '!wd:D'; -select COUNT(*) from test_tsvector where a @@ '!qh'; +select count(*) from test_tsvector where a @@ '!qh'; -select COUNT(*) from test_tsvector where a @@ '!qh'; +select count(*) from test_tsvector where a @@ '!qh'; -select COUNT(*) from test_tsvector where a @@ 'wr' and a @@ '!qh'; +select count(*) from test_tsvector where a @@ 'wr' and a @@ '!qh'; -select COUNT(*) from test_tsvector where a @@ 'wr' and a @@ '!qh'; +select count(*) from test_tsvector where a @@ 'wr' and a @@ '!qh'; reset enable_seqscan; @@ -466,10 +444,7 @@ limit 10; select * from - ts_stat( - 'SELECT a FROM test_tsvector', - 'AB' - ) + ts_stat('SELECT a FROM test_tsvector', 'AB') order by ndoc desc, nentry desc, word; @@ -519,10 +494,7 @@ from select * from - ts_debug( - 'english', - 'http://www.harewoodsolutions.co.uk/press.aspx' - ); + ts_debug('english', 'http://www.harewoodsolutions.co.uk/press.aspx'); select * from ts_debug('english', 'http://aew.wer0c.ewr/id?ad=qwe&dw'); @@ -559,12 +531,10 @@ select to_tsquery('english', '(the|and&(i&1))&fghj'); select plainto_tsquery('english', 'the and z 1))& fghj'); select - plainto_tsquery('english', 'foo bar') && - plainto_tsquery('english', 'asd'); + plainto_tsquery('english', 'foo bar') && plainto_tsquery('english', 'asd'); select - plainto_tsquery('english', 'foo bar') || - plainto_tsquery('english', 'asd fg'); + plainto_tsquery('english', 'foo bar') || plainto_tsquery('english', 'asd fg'); select plainto_tsquery('english', 'foo bar') || @@ -656,11 +626,7 @@ select 'PostgreSQL can be extended by the user in many ways' ); -select - ts_rank_cd( - to_tsvector( - 'english', - ' +select ts_rank_cd(to_tsvector('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -670,16 +636,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -' - ), - to_tsquery('english', 'paint&water') - ); +'), to_tsquery('english', 'paint&water')); -select - ts_rank_cd( - to_tsvector( - 'english', - ' +select ts_rank_cd(to_tsvector('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -689,19 +648,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -' - ), - to_tsquery( - 'english', - 'breath&motion&water' - ) - ); +'), to_tsquery('english', 'breath&motion&water')); -select - ts_rank_cd( - to_tsvector( - 'english', - ' +select ts_rank_cd(to_tsvector('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -711,16 +660,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -' - ), - to_tsquery('english', 'ocean') - ); +'), to_tsquery('english', 'ocean')); -select - ts_rank_cd( - to_tsvector( - 'english', - ' +select ts_rank_cd(to_tsvector('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -730,13 +672,7 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -' - ), - to_tsquery( - 'english', - 'painted <-> Ship' - ) - ); +'), to_tsquery('english', 'painted <-> Ship')); select ts_rank_cd( @@ -746,15 +682,11 @@ select select ts_rank_cd( - to_tsvector('unstripped') || - strip(to_tsvector('stripped')), + to_tsvector('unstripped') || strip(to_tsvector('stripped')), to_tsquery('unstripped & stripped') ); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -764,14 +696,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'paint&water') - ); +', to_tsquery('english', 'paint&water')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -781,17 +708,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery( - 'english', - 'breath&motion&water' - ) - ); +', to_tsquery('english', 'breath&motion&water')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -801,14 +720,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'ocean') - ); +', to_tsquery('english', 'ocean')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -818,14 +732,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'day & drink') - ); +', to_tsquery('english', 'day & drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -835,14 +744,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'day | drink') - ); +', to_tsquery('english', 'day | drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -852,14 +756,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'day | !drink') - ); +', to_tsquery('english', 'day | !drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -869,17 +768,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery( - 'english', - 'painted <-> Ship & drink' - ) - ); +', to_tsquery('english', 'painted <-> Ship & drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -889,17 +780,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery( - 'english', - 'painted <-> Ship | drink' - ) - ); +', to_tsquery('english', 'painted <-> Ship | drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -909,17 +792,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery( - 'english', - 'painted <-> Ship | !drink' - ) - ); +', to_tsquery('english', 'painted <-> Ship | !drink')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -929,17 +804,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - phraseto_tsquery( - 'english', - 'painted Ocean' - ) - ); +', phraseto_tsquery('english', 'painted Ocean')); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -949,22 +816,14 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - phraseto_tsquery( - 'english', - 'idle as a painted Ship' - ) - ); +', phraseto_tsquery('english', 'idle as a painted Ship')); select ts_headline( 'english', 'Lorem ipsum urna. Nullam nullam ullamcorper urna.', to_tsquery('english', 'Lorem') && - phraseto_tsquery( - 'english', - 'ullamcorper urna' - ), + phraseto_tsquery('english', 'ullamcorper urna'), 'MaxWords=100, MinWords=1' ); @@ -972,17 +831,11 @@ select ts_headline( 'english', 'Lorem ipsum urna. Nullam nullam ullamcorper urna.', - phraseto_tsquery( - 'english', - 'ullamcorper urna' - ), + phraseto_tsquery('english', 'ullamcorper urna'), 'MaxWords=100, MinWords=5' ); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' @@ -993,10 +846,7 @@ ff-bg document.write(15); -', - to_tsquery('english', 'sea&foo'), - 'HighlightAll=true' - ); +', to_tsquery('english', 'sea&foo'), 'HighlightAll=true'); select ts_headline( @@ -1022,10 +872,7 @@ select 'MaxWords=4, MinWords=1' ); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -1035,15 +882,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery('english', 'ocean'), - 'MaxFragments=1' - ); +', to_tsquery('english', 'ocean'), 'MaxFragments=1'); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -1053,18 +894,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery( - 'english', - 'Coleridge & stuck' - ), - 'MaxFragments=2' - ); +', to_tsquery('english', 'Coleridge & stuck'), 'MaxFragments=2'); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -1074,18 +906,9 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery( - 'english', - 'ocean & seahorse' - ), - 'MaxFragments=1' - ); +', to_tsquery('english', 'ocean & seahorse'), 'MaxFragments=1'); -select - ts_headline( - 'english', - ' +select ts_headline('english', ' Day after day, day after day, We stuck, nor breath nor motion, As idle as a painted Ship @@ -1095,23 +918,14 @@ Water, water, every where Water, water, every where, Nor any drop to drink. S. T. Coleridge (1772-1834) -', - to_tsquery( - 'english', - 'Coleridge & stuck' - ), - 'MaxFragments=2,FragmentDelimiter=***' - ); +', to_tsquery('english', 'Coleridge & stuck'), 'MaxFragments=2,FragmentDelimiter=***'); select ts_headline( 'english', 'Lorem ipsum urna. Nullam nullam ullamcorper urna.', to_tsquery('english', 'Lorem') && - phraseto_tsquery( - 'english', - 'ullamcorper urna' - ), + phraseto_tsquery('english', 'ullamcorper urna'), 'MaxFragments=100, MaxWords=100, MinWords=1' ); @@ -1134,29 +948,29 @@ alter table test_tsquery update test_tsquery set sample = to_tsquery('english', cast(txtsample as text)); -select COUNT(*) from test_tsquery where keyword < 'new <-> york'; +select count(*) from test_tsquery where keyword < 'new <-> york'; -select COUNT(*) from test_tsquery where keyword <= 'new <-> york'; +select count(*) from test_tsquery where keyword <= 'new <-> york'; -select COUNT(*) from test_tsquery where keyword = 'new <-> york'; +select count(*) from test_tsquery where keyword = 'new <-> york'; -select COUNT(*) from test_tsquery where keyword >= 'new <-> york'; +select count(*) from test_tsquery where keyword >= 'new <-> york'; -select COUNT(*) from test_tsquery where keyword > 'new <-> york'; +select count(*) from test_tsquery where keyword > 'new <-> york'; -create unique index "bt_tsq" on test_tsquery using btree (keyword); +create unique index bt_tsq on test_tsquery using btree (keyword); set enable_seqscan = off; -select COUNT(*) from test_tsquery where keyword < 'new <-> york'; +select count(*) from test_tsquery where keyword < 'new <-> york'; -select COUNT(*) from test_tsquery where keyword <= 'new <-> york'; +select count(*) from test_tsquery where keyword <= 'new <-> york'; -select COUNT(*) from test_tsquery where keyword = 'new <-> york'; +select count(*) from test_tsquery where keyword = 'new <-> york'; -select COUNT(*) from test_tsquery where keyword >= 'new <-> york'; +select count(*) from test_tsquery where keyword >= 'new <-> york'; -select COUNT(*) from test_tsquery where keyword > 'new <-> york'; +select count(*) from test_tsquery where keyword > 'new <-> york'; reset enable_seqscan; @@ -1168,35 +982,24 @@ select ); select - ts_rewrite( - ts_rewrite( - 'new & !york ', - 'york', - '!jersey' - ), - 'jersey', - 'mexico' - ); + ts_rewrite(ts_rewrite('new & !york ', 'york', '!jersey'), 'jersey', 'mexico'); select ts_rewrite( 'moscow', - cast('SELECT keyword, sample FROM test_tsquery' - as text) + cast('SELECT keyword, sample FROM test_tsquery' as text) ); select ts_rewrite( 'moscow & hotel', - cast('SELECT keyword, sample FROM test_tsquery' - as text) + cast('SELECT keyword, sample FROM test_tsquery' as text) ); select ts_rewrite( 'bar & qq & foo & (new <-> york)', - cast('SELECT keyword, sample FROM test_tsquery' - as text) + cast('SELECT keyword, sample FROM test_tsquery' as text) ); select ts_rewrite('moscow', 'SELECT keyword, sample FROM test_tsquery'); @@ -1212,29 +1015,25 @@ select select ts_rewrite( '1 & (2 <-> 3)', - cast('SELECT keyword, sample FROM test_tsquery' - as text) + cast('SELECT keyword, sample FROM test_tsquery' as text) ); select ts_rewrite( '1 & (2 <2> 3)', - cast('SELECT keyword, sample FROM test_tsquery' - as text) + cast('SELECT keyword, sample FROM test_tsquery' as text) ); select ts_rewrite( '5 <-> (1 & (2 <-> 3))', - cast('SELECT keyword, sample FROM test_tsquery' - as text) + cast('SELECT keyword, sample FROM test_tsquery' as text) ); select ts_rewrite( '5 <-> (6 | 8)', - cast('SELECT keyword, sample FROM test_tsquery' - as text) + cast('SELECT keyword, sample FROM test_tsquery' as text) ); select ts_rewrite(to_tsquery('5 & (6 | 5)'), to_tsquery('5'), to_tsquery('')); @@ -1250,64 +1049,36 @@ select keyword from test_tsquery where keyword <@ 'new'; select keyword from test_tsquery where keyword <@ 'moscow'; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery('english', 'moscow & hotel') - as query; + to_tsquery('english', 'moscow & hotel') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery( - 'english', - 'bar & qq & foo & (new <-> york)' - ) - as query; + to_tsquery('english', 'bar & qq & foo & (new <-> york)') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery('english', 'moscow & hotel') - as query; + to_tsquery('english', 'moscow & hotel') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery( - 'english', - 'bar & qq & foo & (new <-> york)' - ) - as query; + to_tsquery('english', 'bar & qq & foo & (new <-> york)') as query; -create index "qq" on test_tsquery using gist (keyword tsquery_ops); +create index qq on test_tsquery using gist (keyword tsquery_ops); set enable_seqscan = off; @@ -1320,80 +1091,44 @@ select keyword from test_tsquery where keyword <@ 'new'; select keyword from test_tsquery where keyword <@ 'moscow'; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery('english', 'moscow & hotel') - as query; + to_tsquery('english', 'moscow & hotel') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery( - 'english', - 'bar & qq & foo & (new <-> york)' - ) - as query; + to_tsquery('english', 'bar & qq & foo & (new <-> york)') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from to_tsquery('english', 'moscow') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery('english', 'moscow & hotel') - as query; + to_tsquery('english', 'moscow & hotel') as query; select - ts_rewrite( - query, - 'SELECT keyword, sample FROM test_tsquery' - ) + ts_rewrite(query, 'SELECT keyword, sample FROM test_tsquery') from - to_tsquery( - 'english', - 'bar & qq & foo & (new <-> york)' - ) - as query; + to_tsquery('english', 'bar & qq & foo & (new <-> york)') as query; select ts_rewrite(tsquery_phrase('foo', 'foo'), 'foo', 'bar | baz'); select to_tsvector('foo bar') @@ - ts_rewrite( - tsquery_phrase('foo', 'foo'), - 'foo', - 'bar | baz' - ); + ts_rewrite(tsquery_phrase('foo', 'foo'), 'foo', 'bar | baz'); select to_tsvector('bar baz') @@ - ts_rewrite( - tsquery_phrase('foo', 'foo'), - 'foo', - 'bar | baz' - ); + ts_rewrite(tsquery_phrase('foo', 'foo'), 'foo', 'bar | baz'); reset enable_seqscan; @@ -1421,19 +1156,19 @@ execute function tsvector_update_trigger(a, "pg_catalog.english", t); -select COUNT(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); +select count(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); insert into test_tsvector (t) values ('345 qwerty'); -select COUNT(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); +select count(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); update test_tsvector set t = null where t = '345 qwerty'; -select COUNT(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); +select count(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); insert into test_tsvector (t) values ('345 qwerty'); -select COUNT(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); +select count(*) from test_tsvector where a @@ to_tsquery('345&qwerty'); select * from test_tsquery, to_tsquery('new') as q where txtsample @@ q; @@ -1447,7 +1182,7 @@ where create temporary table pendtest (ts tsvector); -create index "pendtest_idx" on pendtest using gin (ts); +create index pendtest_idx on pendtest using gin (ts); insert into pendtest values (to_tsvector('Lore ipsam')); @@ -1468,15 +1203,9 @@ create temporary table phrase_index_test (fts tsvector); insert into phrase_index_test values ('A fat cat has just eaten a rat.'); insert into phrase_index_test -values - ( - to_tsvector( - 'english', - 'A fat cat has just eaten a rat.' - ) - ); +values (to_tsvector('english', 'A fat cat has just eaten a rat.')); -create index "phrase_index_test_idx" on phrase_index_test using gin (fts); +create index phrase_index_test_idx on phrase_index_test using gin (fts); set enable_seqscan = off; @@ -1485,8 +1214,7 @@ select from phrase_index_test where - fts @@ - phraseto_tsquery('english', 'fat cat'); + fts @@ phraseto_tsquery('english', 'fat cat'); set enable_seqscan = 'on'; @@ -1621,24 +1349,12 @@ select websearch_to_tsquery('english', '"A the" OR just on'); select websearch_to_tsquery('english', '"a fat cat" ate a rat'); select - to_tsvector( - 'english', - 'A fat cat ate a rat' - ) @@ - websearch_to_tsquery( - 'english', - '"a fat cat" ate a rat' - ); + to_tsvector('english', 'A fat cat ate a rat') @@ + websearch_to_tsquery('english', '"a fat cat" ate a rat'); select - to_tsvector( - 'english', - 'A fat grey cat ate a rat' - ) @@ - websearch_to_tsquery( - 'english', - '"a fat cat" ate a rat' - ); + to_tsvector('english', 'A fat grey cat ate a rat') @@ + websearch_to_tsquery('english', '"a fat cat" ate a rat'); select websearch_to_tsquery(''''); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_100.snap index 82c0f3f2f..0bf727400 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_100.snap @@ -46,9 +46,9 @@ set enable_hashagg = 0; select few.dataa, - COUNT(*), - MIN(id), - MAX(id), + count(*), + min(id), + max(id), unnest(cast('{1,1,3}' as int[])) from few @@ -58,9 +58,9 @@ group by few.dataa; select few.dataa, - COUNT(*), - MIN(id), - MAX(id), + count(*), + min(id), + max(id), unnest(cast('{1,1,3}' as int[])) from few @@ -71,9 +71,9 @@ group by few.dataa, select few.dataa, - COUNT(*), - MIN(id), - MAX(id), + count(*), + min(id), + max(id), unnest(cast('{1,1,3}' as int[])) from few @@ -84,15 +84,15 @@ group by few.dataa, reset enable_hashagg; -select dataa, generate_series(1, 1), COUNT(*) from few group by 1 having COUNT(*) > 1; +select dataa, generate_series(1, 1), count(*) from few group by 1 having count(*) > 1; -select dataa, generate_series(1, 1), COUNT(*) from few group by 1, 2 having COUNT(*) > 1; +select dataa, generate_series(1, 1), count(*) from few group by 1, 2 having count(*) > 1; -select few.dataa, COUNT(*) from few where dataa = 'a' group by few.dataa order by 2; +select few.dataa, count(*) from few where dataa = 'a' group by few.dataa order by 2; select few.dataa, - COUNT(*) + count(*) from few where @@ -105,21 +105,18 @@ select q1, case when q1 > 0 then generate_series(1, 3) else 0 end from int8_tbl; select q1, coalesce(generate_series(1, 3), 0) from int8_tbl; -select MIN(generate_series(1, 3)) from few; +select min(generate_series(1, 3)) from few; -select SUM(cast(3 = any (select generate_series(1, 4)) as int)); +select sum(cast(3 = any (select generate_series(1, 4)) as int)); -select SUM(cast(3 = any (select LAG(x) over (order by x) from generate_series(1, 4) as x) as int)); +select sum(cast(3 = any (select lag(x) over (order by x) from generate_series(1, 4) as x) as int)); -select MIN(generate_series(1, 3)) over () from few; +select min(generate_series(1, 3)) over () from few; -select id, LAG(id) over (), COUNT(*) over (), generate_series(1, 3) from few; +select id, lag(id) over (), count(*) over (), generate_series(1, 3) from few; select - SUM(COUNT(*)) over ( - partition by generate_series(1, 3) - order by generate_series(1, 3) - ), + sum(count(*)) over (partition by generate_series(1, 3) order by generate_series(1, 3)), generate_series(1, 3) as g from few @@ -127,9 +124,9 @@ group by g; select few.dataa, - COUNT(*), - MIN(id), - MAX(id), + count(*), + min(id), + max(id), generate_series(1, 3) from few @@ -143,7 +140,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab); @@ -152,7 +149,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab) @@ -162,7 +159,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab) @@ -172,7 +169,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab, g); @@ -181,7 +178,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab, g) @@ -191,7 +188,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab, g) @@ -226,32 +223,14 @@ select distinct on (a) b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b); + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b); select distinct on (a) a, b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b) + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b) order by a, b desc; @@ -260,16 +239,7 @@ select distinct on (a) b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b) + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b) order by a, b desc, g desc; @@ -279,16 +249,7 @@ select distinct on (a, b, g) b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b) + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b) order by a, b desc, g desc; @@ -298,16 +259,7 @@ select distinct on (g) b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b); + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b); select a, generate_series(1, 2) from (values (1), (2), (3)) as r (a) limit 2 offset 2; @@ -317,7 +269,7 @@ select (select generate_series(1, 3) limit 1 offset few.id) from few; select (select generate_series(1, 3) limit 1 offset g.i) from generate_series(0, 3) as g (i); -create operator |@| (PROCEDURE = unnest, RIGHTARG = anyarray); +create operator |@| (procedure = unnest, rightarg = anyarray); select |@|array[1, 2, 3]; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_80.snap index 4b0b95671..31a128de8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tsrf_80.snap @@ -34,31 +34,13 @@ select * from few as f1, - ( - select - unnest(array[1, 2]) - from - few as f2 - where - false - offset 0 - ) - as ss; + (select unnest(array[1, 2]) from few as f2 where false offset 0) as ss; select * from few as f1, - ( - select - unnest(array[1, 2]) - from - few as f2 - where - false - offset 0 - ) - as ss; + (select unnest(array[1, 2]) from few as f2 where false offset 0) as ss; select few.id, generate_series(1, 3) as g from few order by id desc; @@ -78,9 +60,9 @@ set enable_hashagg = 0; select few.dataa, - COUNT(*), - MIN(id), - MAX(id), + count(*), + min(id), + max(id), unnest(cast('{1,1,3}' as int[])) from few @@ -90,9 +72,9 @@ group by few.dataa; select few.dataa, - COUNT(*), - MIN(id), - MAX(id), + count(*), + min(id), + max(id), unnest(cast('{1,1,3}' as int[])) from few @@ -103,9 +85,9 @@ group by few.dataa, select few.dataa, - COUNT(*), - MIN(id), - MAX(id), + count(*), + min(id), + max(id), unnest(cast('{1,1,3}' as int[])) from few @@ -119,27 +101,27 @@ reset enable_hashagg; select dataa, generate_series(1, 1), - COUNT(*) + count(*) from few group by 1 having - COUNT(*) > 1; + count(*) > 1; select dataa, generate_series(1, 1), - COUNT(*) + count(*) from few group by 1, 2 having - COUNT(*) > 1; + count(*) > 1; select few.dataa, - COUNT(*) + count(*) from few where @@ -149,7 +131,7 @@ order by 2; select few.dataa, - COUNT(*) + count(*) from few where @@ -162,28 +144,25 @@ select q1, case when q1 > 0 then generate_series(1, 3) else 0 end from int8_tbl; select q1, coalesce(generate_series(1, 3), 0) from int8_tbl; -select MIN(generate_series(1, 3)) from few; +select min(generate_series(1, 3)) from few; -select SUM(cast(3 = any (select generate_series(1, 4)) as int)); +select sum(cast(3 = any (select generate_series(1, 4)) as int)); select - SUM( + sum( cast(3 = any ( - select - LAG(x) over (order by x) - from - generate_series(1, 4) as x + select lag(x) over (order by x) from generate_series(1, 4) as x ) as int) ); -select MIN(generate_series(1, 3)) over () from few; +select min(generate_series(1, 3)) over () from few; -select id, LAG(id) over (), COUNT(*) over (), generate_series(1, 3) from few; +select id, lag(id) over (), count(*) over (), generate_series(1, 3) from few; select - SUM(COUNT(*)) over ( + sum(count(*)) over ( partition by generate_series(1, 3) order by generate_series(1, 3) ), @@ -194,9 +173,9 @@ group by g; select few.dataa, - COUNT(*), - MIN(id), - MAX(id), + count(*), + min(id), + max(id), generate_series(1, 3) from few @@ -210,7 +189,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab); @@ -219,7 +198,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab) @@ -229,7 +208,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab) @@ -239,7 +218,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab, g); @@ -248,7 +227,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab, g) @@ -258,7 +237,7 @@ select dataa, datab as b, generate_series(1, 2) as g, - COUNT(*) + count(*) from few group by cube (dataa, datab, g) @@ -293,32 +272,14 @@ select distinct on (a) b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b); + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b); select distinct on (a) a, b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b) + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b) order by a, b desc; @@ -327,16 +288,7 @@ select distinct on (a) b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b) + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b) order by a, b desc, g desc; @@ -346,16 +298,7 @@ select distinct on (a, b, g) b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b) + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b) order by a, b desc, g desc; @@ -365,16 +308,7 @@ select distinct on (g) b, generate_series(1, 3) as g from - ( - values - (3, 2), - (3, 1), - (1, 1), - (1, 4), - (5, 3), - (5, 1) - ) - as t (a, b); + (values (3, 2), (3, 1), (1, 1), (1, 4), (5, 3), (5, 1)) as t (a, b); select a, @@ -389,16 +323,11 @@ select 1 limit generate_series(1, 3); select (select generate_series(1, 3) limit 1 offset few.id) from few; select - ( - select - generate_series(1, 3) - limit 1 - offset g.i - ) + (select generate_series(1, 3) limit 1 offset g.i) from generate_series(0, 3) as g (i); -create operator |@| (PROCEDURE = unnest, RIGHTARG = anyarray); +create operator |@| (procedure = unnest, rightarg = anyarray); select |@|array[1, 2, 3]; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tstypes_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tstypes_100.snap index 11c00cc68..2cff1b7ae 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tstypes_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tstypes_100.snap @@ -414,39 +414,29 @@ select strip(cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' select strip(cast('base hidden rebel spaceship strike' as tsvector)); select - ts_delete( - to_tsvector( - 'english', - 'Rebel spaceships, striking from a hidden base' - ), - 'spaceship' - ); + ts_delete(to_tsvector('english', 'Rebel spaceships, striking from a hidden base'), 'spaceship'); select ts_delete( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector), + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector), 'base' ); select ts_delete( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector), + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector), 'bas' ); select ts_delete( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector), + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector), 'bases' ); select ts_delete( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector), + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector), 'spaceship' ); @@ -454,50 +444,43 @@ select ts_delete(cast('base hidden rebel spaceship strike' as tsvector), 'spaces select ts_delete( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector), + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector), array['spaceship', 'rebel'] ); select ts_delete( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector), + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector), array['spaceships', 'rebel'] ); select ts_delete( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector), + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector), array['spaceshi', 'rebel'] ); select ts_delete( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector), + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector), array['spaceship', 'leya', 'rebel'] ); select ts_delete( - cast('base hidden rebel spaceship strike' - as tsvector), + cast('base hidden rebel spaceship strike' as tsvector), array['spaceship', 'leya', 'rebel'] ); select ts_delete( - cast('base hidden rebel spaceship strike' - as tsvector), + cast('base hidden rebel spaceship strike' as tsvector), array['spaceship', 'leya', 'rebel', 'rebel'] ); select ts_delete( - cast('base hidden rebel spaceship strike' - as tsvector), + cast('base hidden rebel spaceship strike' as tsvector), array['spaceship', 'leya', 'rebel', '', null] ); @@ -508,10 +491,7 @@ select unnest(cast('base hidden rebel spaceship strike' as tsvector)); select * from - unnest( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector) - ); + unnest(cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector)); select * from unnest(cast('base hidden rebel spaceship strike' as tsvector)); @@ -519,15 +499,11 @@ select lexeme, positions[1] from - unnest( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector) - ); + unnest(cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector)); select tsvector_to_array( - cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' - as tsvector) + cast('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3' as tsvector) ); select tsvector_to_array(cast('base hidden rebel spaceship strike' as tsvector)); @@ -541,11 +517,7 @@ select array_to_tsvector(array['base', 'hidden', 'rebel', 'spaceship', '']); select array_to_tsvector(array['foo', 'bar', 'baz', 'bar']); select - setweight( - cast('w:12B w:13* w:12,5,6 a:1,3* a:3 w asd:1dc asd zxc:81,567,222A' - as tsvector), - 'c' - ); + setweight(cast('w:12B w:13* w:12,5,6 a:1,3* a:3 w asd:1dc asd zxc:81,567,222A' as tsvector), 'c'); select setweight(cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' as tsvector), 'c'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tstypes_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tstypes_80.snap index d9ed101dd..5d4506ae4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tstypes_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tstypes_80.snap @@ -29,10 +29,7 @@ select cast('''\\as'' ab\c ab\\c AB\\\c ab\\\\c' as tsvector); select tsvectorin( - tsvectorout( - cast('''\\as'' ab\c ab\\c AB\\\c ab\\\\c' - as tsvector) - ) + tsvectorout(cast('''\\as'' ab\c ab\\c AB\\\c ab\\\\c' as tsvector)) ); select '''w'':4A,3B,2C,1D,5 a:8'; @@ -198,36 +195,25 @@ select cast('a b:89 ca:23A,64b d:34c' as tsvector) @@ 'd:AC & c:*C' as "false"; select cast('a b:89 ca:23A,64b d:34c' as tsvector) @@ 'd:AC & c:*CB' as "true"; select - cast('a b:89 ca:23A,64b cb:80c d:34c' - as tsvector) @@ - 'd:AC & c:*C' + cast('a b:89 ca:23A,64b cb:80c d:34c' as tsvector) @@ 'd:AC & c:*C' as "true"; select - cast('a b:89 ca:23A,64c cb:80b d:34c' - as tsvector) @@ - 'd:AC & c:*C' + cast('a b:89 ca:23A,64c cb:80b d:34c' as tsvector) @@ 'd:AC & c:*C' as "true"; select - cast('a b:89 ca:23A,64c cb:80b d:34c' - as tsvector) @@ - 'd:AC & c:*B' + cast('a b:89 ca:23A,64c cb:80b d:34c' as tsvector) @@ 'd:AC & c:*B' as "true"; select - cast('wa:1D wb:2A' as tsvector) @@ - cast('w:*D & w:*A' as tsquery) - as "true"; + cast('wa:1D wb:2A' as tsvector) @@ cast('w:*D & w:*A' as tsquery) as "true"; select - cast('wa:1D wb:2A' as tsvector) @@ - cast('w:*D <-> w:*A' as tsquery) - as "true"; + cast('wa:1D wb:2A' as tsvector) @@ cast('w:*D <-> w:*A' as tsquery) as "true"; select - cast('wa:1A wb:2D' as tsvector) @@ - cast('w:*D <-> w:*A' as tsquery) + cast('wa:1A wb:2D' as tsvector) @@ cast('w:*D <-> w:*A' as tsquery) as "false"; select cast('wa:1A' as tsvector) @@ cast('w:*A' as tsquery) as "true"; @@ -249,25 +235,21 @@ select strip(cast('wa:1A' as tsvector)) @@ cast('!w:*D' as tsquery) as "false"; select cast('supernova' as tsvector) @@ cast('super' as tsquery) as "false"; select - cast('supeanova supernova' as tsvector) @@ - cast('super' as tsquery) + cast('supeanova supernova' as tsvector) @@ cast('super' as tsquery) as "false"; select - cast('supeznova supernova' as tsvector) @@ - cast('super' as tsquery) + cast('supeznova supernova' as tsvector) @@ cast('super' as tsquery) as "false"; select cast('supernova' as tsvector) @@ cast('super:*' as tsquery) as "true"; select - cast('supeanova supernova' as tsvector) @@ - cast('super:*' as tsquery) + cast('supeanova supernova' as tsvector) @@ cast('super:*' as tsquery) as "true"; select - cast('supeznova supernova' as tsvector) @@ - cast('super:*' as tsquery) + cast('supeznova supernova' as tsvector) @@ cast('super:*' as tsquery) as "true"; select to_tsvector('simple', '1 2 3 1') @@ '1 <-> 2' as "true"; @@ -458,10 +440,7 @@ select strip(cast('base hidden rebel spaceship strike' as tsvector)); select ts_delete( - to_tsvector( - 'english', - 'Rebel spaceships, striking from a hidden base' - ), + to_tsvector('english', 'Rebel spaceships, striking from a hidden base'), 'spaceship' ); @@ -495,8 +474,7 @@ select select ts_delete( - cast('base hidden rebel spaceship strike' - as tsvector), + cast('base hidden rebel spaceship strike' as tsvector), 'spaceship' ); @@ -530,30 +508,20 @@ select select ts_delete( - cast('base hidden rebel spaceship strike' - as tsvector), + cast('base hidden rebel spaceship strike' as tsvector), array['spaceship', 'leya', 'rebel'] ); select ts_delete( - cast('base hidden rebel spaceship strike' - as tsvector), - array['spaceship', - 'leya', - 'rebel', - 'rebel'] + cast('base hidden rebel spaceship strike' as tsvector), + array['spaceship', 'leya', 'rebel', 'rebel'] ); select ts_delete( - cast('base hidden rebel spaceship strike' - as tsvector), - array['spaceship', - 'leya', - 'rebel', - '', - null] + cast('base hidden rebel spaceship strike' as tsvector), + array['spaceship', 'leya', 'rebel', '', null] ); select @@ -590,19 +558,10 @@ select ); select - tsvector_to_array( - cast('base hidden rebel spaceship strike' - as tsvector) - ); + tsvector_to_array(cast('base hidden rebel spaceship strike' as tsvector)); select - array_to_tsvector( - array['base', - 'hidden', - 'rebel', - 'spaceship', - 'strike'] - ); + array_to_tsvector(array['base', 'hidden', 'rebel', 'spaceship', 'strike']); select array_to_tsvector(array['base', 'hidden', 'rebel', 'spaceship', null]); @@ -619,39 +578,34 @@ select select setweight( - cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' - as tsvector), + cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' as tsvector), 'c' ); select setweight( - cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' - as tsvector), + cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' as tsvector), 'c', '{a}' ); select setweight( - cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' - as tsvector), + cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' as tsvector), 'c', '{a}' ); select setweight( - cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' - as tsvector), + cast('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567' as tsvector), 'c', '{a,zxc}' ); select setweight( - cast('a asd w:5,6,12B,13A zxc' - as tsvector), + cast('a asd w:5,6,12B,13A zxc' as tsvector), 'c', array['a', 'zxc', '', null] ); @@ -667,7 +621,6 @@ select ts_filter(cast('base hidden rebel spaceship strike' as tsvector), '{a}'); select ts_filter( - cast('base hidden rebel spaceship strike' - as tsvector), + cast('base hidden rebel spaceship strike' as tsvector), '{a,b,NULL}' ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tuplesort_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tuplesort_100.snap index e975dac14..ee4a3f85c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tuplesort_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tuplesort_100.snap @@ -21,21 +21,13 @@ insert into abbrev_abort_uuids ( noabort_decreasing ) select - cast('00000000-0000-0000-0000-' || - to_char(g.i, '000000000000FM') - as uuid) - as abort_increasing, - cast('00000000-0000-0000-0000-' || - to_char(20000 - g.i, '000000000000FM') - as uuid) + cast('00000000-0000-0000-0000-' || to_char(g.i, '000000000000FM') as uuid) as abort_increasing, + cast('00000000-0000-0000-0000-' || to_char(20000 - g.i, '000000000000FM') as uuid) as abort_decreasing, - cast(to_char(g.i % 10009, '00000000FM') || - '-0000-0000-0000-' || - to_char(g.i, '000000000000FM') + cast(to_char(g.i % 10009, '00000000FM') || '-0000-0000-0000-' || to_char(g.i, '000000000000FM') as uuid) as noabort_increasing, - cast(to_char((20000 - g.i) % 10009, '00000000FM') || - '-0000-0000-0000-' || + cast(to_char((20000 - g.i) % 10009, '00000000FM') || '-0000-0000-0000-' || to_char(20000 - g.i, '000000000000FM') as uuid) as noabort_decreasing @@ -62,11 +54,7 @@ select from abbrev_abort_uuids where - ( - id < 10 or id > 19990 - ) and - id % 3 = 0 and - abort_increasing is not null; + (id < 10 or id > 19990) and id % 3 = 0 and abort_increasing is not null; select abort_increasing, @@ -116,17 +104,11 @@ from order by noabort_increasing nulls first limit 5; -create index "abbrev_abort_uuids__noabort_increasing_idx" -on abbrev_abort_uuids -using btree -( +create index abbrev_abort_uuids__noabort_increasing_idx on abbrev_abort_uuids using btree ( noabort_increasing ); -create index "abbrev_abort_uuids__noabort_decreasing_idx" -on abbrev_abort_uuids -using btree -( +create index abbrev_abort_uuids__noabort_decreasing_idx on abbrev_abort_uuids using btree ( noabort_decreasing ); @@ -166,17 +148,11 @@ from order by noabort_decreasing limit 5; -create index "abbrev_abort_uuids__abort_increasing_idx" -on abbrev_abort_uuids -using btree -( +create index abbrev_abort_uuids__abort_increasing_idx on abbrev_abort_uuids using btree ( abort_increasing ); -create index "abbrev_abort_uuids__abort_decreasing_idx" -on abbrev_abort_uuids -using btree -( +create index abbrev_abort_uuids__abort_decreasing_idx on abbrev_abort_uuids using btree ( abort_decreasing ); @@ -340,34 +316,21 @@ select left(a, 10), b from - ( - values - (repeat('a', 512 * 1024), 1), - (repeat('b', 512 * 1024), 2) - ) - as v (a, b) + (values (repeat('a', 512 * 1024), 1), (repeat('b', 512 * 1024), 2)) as v (a, b) order by v.a desc; begin; set local enable_indexscan = 'false'; -explain (COSTS 'off') -declare "c" scroll +explain (costs 'off') +declare c scroll cursor -for select - noabort_decreasing -from - abbrev_abort_uuids -order by noabort_decreasing;; +for select noabort_decreasing from abbrev_abort_uuids order by noabort_decreasing;; -declare "c" scroll +declare c scroll cursor -for select - noabort_decreasing -from - abbrev_abort_uuids -order by noabort_decreasing;; +for select noabort_decreasing from abbrev_abort_uuids order by noabort_decreasing;; fetch next from c; @@ -405,22 +368,14 @@ set local enable_indexscan = 'false'; set local work_mem = '100kB'; -explain (COSTS 'off') -declare "c" scroll +explain (costs 'off') +declare c scroll cursor -for select - noabort_decreasing -from - abbrev_abort_uuids -order by noabort_decreasing;; +for select noabort_decreasing from abbrev_abort_uuids order by noabort_decreasing;; -declare "c" scroll +declare c scroll cursor -for select - noabort_decreasing -from - abbrev_abort_uuids -order by noabort_decreasing;; +for select noabort_decreasing from abbrev_abort_uuids order by noabort_decreasing;; fetch next from c; @@ -454,39 +409,20 @@ commit; select (array_agg(id order by id desc nulls first))[0:5], - (array_agg( - abort_increasing order by abort_increasing desc nulls last - ))[0:5], - (array_agg( - cast(id as text) order by cast(id as text) desc nulls last - ))[0:5], + (array_agg(abort_increasing order by abort_increasing desc nulls last))[0:5], + (array_agg(cast(id as text) order by cast(id as text) desc nulls last))[0:5], percentile_disc(0.99) within group (order by id), percentile_disc(0.01) within group (order by id), - percentile_disc( - 0.8 - ) - within group (order by abort_increasing), - percentile_disc( - 0.2 - ) - within group (order by cast(id as text)), - RANK( + percentile_disc(0.8) within group (order by abort_increasing), + percentile_disc(0.2) within group (order by cast(id as text)), + rank( '00000000-0000-0000-0000-000000000000', '2', '2' ) - within group ( - order by noabort_increasing, - id, - cast(id as text) - ) + within group (order by noabort_increasing, id, cast(id as text)) from - ( - select * from abbrev_abort_uuids - union all - select null, null, null, null, null - ) - as s; + (select * from abbrev_abort_uuids union all select null, null, null, null, null) as s; begin; @@ -494,39 +430,20 @@ set local work_mem = '100kB'; select (array_agg(id order by id desc nulls first))[0:5], - (array_agg( - abort_increasing order by abort_increasing desc nulls last - ))[0:5], - (array_agg( - cast(id as text) order by cast(id as text) desc nulls last - ))[0:5], + (array_agg(abort_increasing order by abort_increasing desc nulls last))[0:5], + (array_agg(cast(id as text) order by cast(id as text) desc nulls last))[0:5], percentile_disc(0.99) within group (order by id), percentile_disc(0.01) within group (order by id), - percentile_disc( - 0.8 - ) - within group (order by abort_increasing), - percentile_disc( - 0.2 - ) - within group (order by cast(id as text)), - RANK( + percentile_disc(0.8) within group (order by abort_increasing), + percentile_disc(0.2) within group (order by cast(id as text)), + rank( '00000000-0000-0000-0000-000000000000', '2', '2' ) - within group ( - order by noabort_increasing, - id, - cast(id as text) - ) + within group (order by noabort_increasing, id, cast(id as text)) from - ( - select * from abbrev_abort_uuids - union all - select null, null, null, null, null - ) - as s; + (select * from abbrev_abort_uuids union all select null, null, null, null, null) as s; rollback; @@ -537,13 +454,7 @@ create temporary table test_mark_restore ( ); insert into test_mark_restore (col1, col2, col12) -select - a.i, - b.i, - a.i * b.i -from - generate_series(1, 500) as a (i), - generate_series(1, 5) as b (i); +select a.i, b.i, a.i * b.i from generate_series(1, 500) as a (i), generate_series(1, 5) as b (i); begin; @@ -553,8 +464,7 @@ set local enable_hashjoin = off; set local enable_material = off; -select - ' +select ' SELECT col12, count(distinct a.col1), count(distinct a.col2), count(distinct b.col1), count(distinct b.col2), count(*) FROM test_mark_restore a JOIN test_mark_restore b USING(col12) @@ -562,8 +472,7 @@ select HAVING count(*) > 1 ORDER BY 2 DESC, 1 DESC, 3 DESC, 4 DESC, 5 DESC, 6 DESC LIMIT 10 -' - as qry; +' as qry; set local work_mem = '100kB'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tuplesort_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tuplesort_80.snap index ad45200bf..6b85c8b44 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__tuplesort_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__tuplesort_80.snap @@ -21,24 +21,16 @@ insert into abbrev_abort_uuids ( noabort_decreasing ) select - cast('00000000-0000-0000-0000-' || - to_char(g.i, '000000000000FM') - as uuid) + cast('00000000-0000-0000-0000-' || to_char(g.i, '000000000000FM') as uuid) as abort_increasing, - cast('00000000-0000-0000-0000-' || - to_char(20000 - g.i, '000000000000FM') + cast('00000000-0000-0000-0000-' || to_char(20000 - g.i, '000000000000FM') as uuid) as abort_decreasing, - cast(to_char(g.i % 10009, '00000000FM') || - '-0000-0000-0000-' || + cast(to_char(g.i % 10009, '00000000FM') || '-0000-0000-0000-' || to_char(g.i, '000000000000FM') as uuid) as noabort_increasing, - cast(to_char( - (20000 - g.i) % 10009, - '00000000FM' - ) || - '-0000-0000-0000-' || + cast(to_char((20000 - g.i) % 10009, '00000000FM') || '-0000-0000-0000-' || to_char(20000 - g.i, '000000000000FM') as uuid) as noabort_decreasing @@ -65,11 +57,7 @@ select from abbrev_abort_uuids where - ( - id < 10 or id > 19990 - ) and - id % 3 = 0 and - abort_increasing is not null; + (id < 10 or id > 19990) and id % 3 = 0 and abort_increasing is not null; select abort_increasing, @@ -119,19 +107,13 @@ from order by noabort_increasing nulls first limit 5; -create index "abbrev_abort_uuids__noabort_increasing_idx" -on abbrev_abort_uuids -using btree -( - noabort_increasing -); +create index abbrev_abort_uuids__noabort_increasing_idx + on abbrev_abort_uuids + using btree (noabort_increasing); -create index "abbrev_abort_uuids__noabort_decreasing_idx" -on abbrev_abort_uuids -using btree -( - noabort_decreasing -); +create index abbrev_abort_uuids__noabort_decreasing_idx + on abbrev_abort_uuids + using btree (noabort_decreasing); select id, @@ -169,19 +151,13 @@ from order by noabort_decreasing limit 5; -create index "abbrev_abort_uuids__abort_increasing_idx" -on abbrev_abort_uuids -using btree -( - abort_increasing -); +create index abbrev_abort_uuids__abort_increasing_idx + on abbrev_abort_uuids + using btree (abort_increasing); -create index "abbrev_abort_uuids__abort_decreasing_idx" -on abbrev_abort_uuids -using btree -( - abort_decreasing -); +create index abbrev_abort_uuids__abort_decreasing_idx + on abbrev_abort_uuids + using btree (abort_decreasing); select id, @@ -344,9 +320,7 @@ select b from ( - values - (repeat('a', 512 * 1024), 1), - (repeat('b', 512 * 1024), 2) + values (repeat('a', 512 * 1024), 1), (repeat('b', 512 * 1024), 2) ) as v (a, b) order by v.a desc; @@ -355,8 +329,8 @@ begin; set local enable_indexscan = 'false'; -explain (COSTS 'off') -declare "c" scroll +explain (costs 'off') +declare c scroll cursor for select noabort_decreasing @@ -364,7 +338,7 @@ from abbrev_abort_uuids order by noabort_decreasing;; -declare "c" scroll +declare c scroll cursor for select noabort_decreasing @@ -408,8 +382,8 @@ set local enable_indexscan = 'false'; set local work_mem = '100kB'; -explain (COSTS 'off') -declare "c" scroll +explain (costs 'off') +declare c scroll cursor for select noabort_decreasing @@ -417,7 +391,7 @@ from abbrev_abort_uuids order by noabort_decreasing;; -declare "c" scroll +declare c scroll cursor for select noabort_decreasing @@ -456,41 +430,19 @@ fetch next from c; commit; select - (array_agg( - id order by id desc nulls first - ))[0:5], - (array_agg( - abort_increasing order by abort_increasing desc nulls last - ))[0:5], - (array_agg( - cast(id as text) order by cast(id as text) desc nulls last - ))[0:5], - percentile_disc( - 0.99 - ) - within group (order by id), - percentile_disc( - 0.01 - ) - within group (order by id), - percentile_disc( - 0.8 - ) - within group (order by abort_increasing), - percentile_disc( - 0.2 - ) - within group (order by cast(id as text)), - RANK( + (array_agg(id order by id desc nulls first))[0:5], + (array_agg(abort_increasing order by abort_increasing desc nulls last))[0:5], + (array_agg(cast(id as text) order by cast(id as text) desc nulls last))[0:5], + percentile_disc(0.99) within group (order by id), + percentile_disc(0.01) within group (order by id), + percentile_disc(0.8) within group (order by abort_increasing), + percentile_disc(0.2) within group (order by cast(id as text)), + rank( '00000000-0000-0000-0000-000000000000', '2', '2' ) - within group ( - order by noabort_increasing, - id, - cast(id as text) - ) + within group (order by noabort_increasing, id, cast(id as text)) from ( select * from abbrev_abort_uuids @@ -504,41 +456,19 @@ begin; set local work_mem = '100kB'; select - (array_agg( - id order by id desc nulls first - ))[0:5], - (array_agg( - abort_increasing order by abort_increasing desc nulls last - ))[0:5], - (array_agg( - cast(id as text) order by cast(id as text) desc nulls last - ))[0:5], - percentile_disc( - 0.99 - ) - within group (order by id), - percentile_disc( - 0.01 - ) - within group (order by id), - percentile_disc( - 0.8 - ) - within group (order by abort_increasing), - percentile_disc( - 0.2 - ) - within group (order by cast(id as text)), - RANK( + (array_agg(id order by id desc nulls first))[0:5], + (array_agg(abort_increasing order by abort_increasing desc nulls last))[0:5], + (array_agg(cast(id as text) order by cast(id as text) desc nulls last))[0:5], + percentile_disc(0.99) within group (order by id), + percentile_disc(0.01) within group (order by id), + percentile_disc(0.8) within group (order by abort_increasing), + percentile_disc(0.2) within group (order by cast(id as text)), + rank( '00000000-0000-0000-0000-000000000000', '2', '2' ) - within group ( - order by noabort_increasing, - id, - cast(id as text) - ) + within group (order by noabort_increasing, id, cast(id as text)) from ( select * from abbrev_abort_uuids @@ -572,8 +502,7 @@ set local enable_hashjoin = off; set local enable_material = off; -select - ' +select ' SELECT col12, count(distinct a.col1), count(distinct a.col2), count(distinct b.col1), count(distinct b.col2), count(*) FROM test_mark_restore a JOIN test_mark_restore b USING(col12) @@ -581,8 +510,7 @@ select HAVING count(*) > 1 ORDER BY 2 DESC, 1 DESC, 3 DESC, 4 DESC, 5 DESC, 6 DESC LIMIT 10 -' - as qry; +' as qry; set local work_mem = '100kB'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__txid_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__txid_100.snap index e060ef73f..c8ec8f79d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__txid_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__txid_100.snap @@ -130,7 +130,7 @@ begin; create function test_future_xid_status(bigint) returns void language plpgsql -as $function$ +as $$ BEGIN PERFORM txid_status($1); RAISE EXCEPTION 'didn''t ERROR at xid in the future as expected'; @@ -138,7 +138,7 @@ EXCEPTION WHEN invalid_parameter_value THEN RAISE NOTICE 'Got expected error for xid in the future'; END; -$function$; +$$; select test_future_xid_status('inprogress' + 10000); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__txid_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__txid_80.snap index 5eaac7eda..525c1abdf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__txid_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__txid_80.snap @@ -94,7 +94,8 @@ select txid_current_if_assigned() is null; select txid_current(); select - txid_current_if_assigned() is not distinct from cast('txid_current' as bigint); + txid_current_if_assigned() is not distinct from cast('txid_current' + as bigint); commit; @@ -133,7 +134,7 @@ begin; create function test_future_xid_status(bigint) returns void language plpgsql -as $function$ +as $$ BEGIN PERFORM txid_status($1); RAISE EXCEPTION 'didn''t ERROR at xid in the future as expected'; @@ -141,7 +142,7 @@ EXCEPTION WHEN invalid_parameter_value THEN RAISE NOTICE 'Got expected error for xid in the future'; END; -$function$; +$$; select test_future_xid_status('inprogress' + 10000); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__type_sanity_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__type_sanity_100.snap index 0078c9fbd..b1518e836 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__type_sanity_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__type_sanity_100.snap @@ -9,13 +9,8 @@ from pg_type as t1 where t1.typnamespace = 0 or - (t1.typlen <= 0 and - t1.typlen <> -1 and - t1.typlen <> -2) or - t1.typtype - not in ( - 'b', 'c', 'd', 'e', 'm', 'p', 'r' - ) or + (t1.typlen <= 0 and t1.typlen <> -1 and t1.typlen <> -2) or + t1.typtype not in ('b', 'c', 'd', 'e', 'm', 'p', 'r') or not t1.typisdefined or t1.typalign not in ('c', 's', 'i', 'd') or t1.typstorage not in ('p', 'x', 'e', 'm'); @@ -46,10 +41,7 @@ select from pg_type as t1 where - t1.typstorage <> 'p' and - ( - t1.typbyval or t1.typlen <> -1 - ); + t1.typstorage <> 'p' and (t1.typbyval or t1.typlen <> -1); select t1.oid, @@ -57,8 +49,7 @@ select from pg_type as t1 where - (t1.typtype = 'c' and t1.typrelid = 0) or - (t1.typtype <> 'c' and t1.typrelid <> 0); + (t1.typtype = 'c' and t1.typrelid = 0) or (t1.typtype <> 'c' and t1.typrelid <> 0); select t1.oid, @@ -75,9 +66,7 @@ where from pg_type as t2 where - t2.typname = cast('_' || t1.typname as name) and - t2.typelem = t1.oid and - t1.typarray = t2.oid + t2.typname = cast('_' || t1.typname as name) and t2.typelem = t1.oid and t1.typarray = t2.oid ) order by t1.oid; @@ -87,16 +76,11 @@ select t2.typname as arraytype, t2.typsubscript from - pg_type as t1 - left outer join - pg_type as t2 - on t1.typarray = t2.oid + pg_type as t1 left outer join pg_type as t2 on t1.typarray = t2.oid where t1.typarray <> 0 and ( - t2.oid is null or - t2.typsubscript <> - cast('array_subscript_handler' as regproc) + t2.oid is null or t2.typsubscript <> cast('array_subscript_handler' as regproc) ); select @@ -105,16 +89,7 @@ select from pg_type as t1 where - t1.typtype = 'r' and - not exists - ( - select - 1 - from - pg_range as r - where - rngtypid = t1.oid - ); + t1.typtype = 'r' and not exists (select 1 from pg_range as r where rngtypid = t1.oid); select t1.oid, @@ -123,10 +98,7 @@ select t2.typname, t2.typalign from - pg_type as t1 - left outer join - pg_range as r - on rngtypid = t1.oid + pg_type as t1 left outer join pg_range as r on rngtypid = t1.oid left outer join pg_type as t2 on rngsubtype = t2.oid @@ -134,10 +106,7 @@ where t1.typtype = 'r' and ( t1.typalign <> - case - when t2.typalign = 'd' then cast('d' as "char") - else cast('i' as "char") - end or + case when t2.typalign = 'd' then cast('d' as "char") else cast('i' as "char") end or t2.oid is null ); @@ -154,8 +123,7 @@ from where t1.typinput = p1.oid and not ( - (p1.pronargs = 1 and - p1.proargtypes[0] = cast('cstring' as regtype)) or + (p1.pronargs = 1 and p1.proargtypes[0] = cast('cstring' as regtype)) or (p1.pronargs = 2 and p1.proargtypes[0] = cast('cstring' as regtype) and p1.proargtypes[1] = cast('oid' as regtype)) or @@ -190,7 +158,8 @@ from pg_proc as p1 where t1.typinput = p1.oid and - t1.typelem <> 0 and t1.typlen < 0 and + t1.typelem <> 0 and + t1.typlen < 0 and not p1.oid = cast('array_in' as regproc) order by 1; @@ -203,8 +172,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typinput = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typinput = p1.oid and p1.provolatile not in ('i', 's'); select distinct typtype, typinput from pg_type as t1 where t1.typtype not in ('b', 'p') order by 1; @@ -223,9 +191,7 @@ where p1.pronargs = 1 and ( p1.proargtypes[0] = t1.oid or - (p1.oid = cast('array_out' as regproc) and - t1.typelem <> 0 and - t1.typlen = -1) + (p1.oid = cast('array_out' as regproc) and t1.typelem <> 0 and t1.typlen = -1) ) ) order by 1; @@ -239,11 +205,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typoutput = p1.oid and - not ( - p1.prorettype = cast('cstring' as regtype) and - not p1.proretset - ); + t1.typoutput = p1.oid and not (p1.prorettype = cast('cstring' as regtype) and not p1.proretset); select t1.oid, @@ -254,8 +216,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typoutput = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typoutput = p1.oid and p1.provolatile not in ('i', 's'); select distinct typtype, @@ -272,13 +233,9 @@ select t2.oid, t2.typname from - pg_type as t1 - left outer join - pg_type as t2 - on t1.typbasetype = t2.oid + pg_type as t1 left outer join pg_type as t2 on t1.typbasetype = t2.oid where - t1.typtype = 'd' and - t1.typoutput is distinct from t2.typoutput; + t1.typtype = 'd' and t1.typoutput is distinct from t2.typoutput; select t1.oid, @@ -291,8 +248,7 @@ from where t1.typreceive = p1.oid and not ( - (p1.pronargs = 1 and - p1.proargtypes[0] = cast('internal' as regtype)) or + (p1.pronargs = 1 and p1.proargtypes[0] = cast('internal' as regtype)) or (p1.pronargs = 2 and p1.proargtypes[0] = cast('internal' as regtype) and p1.proargtypes[1] = cast('oid' as regtype)) or @@ -327,7 +283,8 @@ from pg_proc as p1 where t1.typreceive = p1.oid and - t1.typelem <> 0 and t1.typlen < 0 and + t1.typelem <> 0 and + t1.typlen < 0 and not p1.oid = cast('array_recv' as regproc) order by 1; @@ -343,9 +300,7 @@ from pg_proc as p1, pg_proc as p2 where - t1.typinput = p1.oid and - t1.typreceive = p2.oid and - p1.pronargs <> p2.pronargs; + t1.typinput = p1.oid and t1.typreceive = p2.oid and p1.pronargs <> p2.pronargs; select t1.oid, @@ -356,8 +311,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typreceive = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typreceive = p1.oid and p1.provolatile not in ('i', 's'); select distinct typtype, @@ -383,9 +337,7 @@ where p1.pronargs = 1 and ( p1.proargtypes[0] = t1.oid or - (p1.oid = cast('array_send' as regproc) and - t1.typelem <> 0 and - t1.typlen = -1) + (p1.oid = cast('array_send' as regproc) and t1.typelem <> 0 and t1.typlen = -1) ) ) order by 1; @@ -399,11 +351,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typsend = p1.oid and - not ( - p1.prorettype = cast('bytea' as regtype) and - not p1.proretset - ); + t1.typsend = p1.oid and not (p1.prorettype = cast('bytea' as regtype) and not p1.proretset); select t1.oid, @@ -414,8 +362,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typsend = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typsend = p1.oid and p1.provolatile not in ('i', 's'); select distinct typtype, @@ -432,13 +379,9 @@ select t2.oid, t2.typname from - pg_type as t1 - left outer join - pg_type as t2 - on t1.typbasetype = t2.oid + pg_type as t1 left outer join pg_type as t2 on t1.typbasetype = t2.oid where - t1.typtype = 'd' and - t1.typsend is distinct from t2.typsend; + t1.typtype = 'd' and t1.typsend is distinct from t2.typsend; select t1.oid, @@ -466,8 +409,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typmodin = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typmodin = p1.oid and p1.provolatile not in ('i', 's'); select t1.oid, @@ -495,8 +437,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typmodout = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typmodout = p1.oid and p1.provolatile not in ('i', 's'); select t1.oid, @@ -507,11 +448,7 @@ from pg_type as t1, pg_type as t2 where - t1.typelem = t2.oid and - not ( - t1.typmodin = t2.typmodin and - t1.typmodout = t2.typmodout - ); + t1.typelem = t2.oid and not (t1.typmodin = t2.typmodin and t1.typmodout = t2.typmodout); select t1.oid, @@ -522,8 +459,7 @@ from pg_type as t1, pg_type as t2 where - t1.typarray = t2.oid and - not t1.typdelim = t2.typdelim; + t1.typarray = t2.oid and not t1.typdelim = t2.typdelim; select t1.oid, @@ -536,11 +472,7 @@ from pg_type as t2 where t1.typarray = t2.oid and - t2.typalign <> - case - when t1.typalign = 'd' then cast('d' as "char") - else cast('i' as "char") - end; + t2.typalign <> case when t1.typalign = 'd' then cast('d' as "char") else cast('i' as "char") end; select t1.oid, @@ -560,13 +492,8 @@ select from pg_type as t1 where - t1.typsubscript = - cast('array_subscript_handler' as regproc) and - not ( - t1.typelem <> 0 and - t1.typlen = -1 and - not t1.typbyval - ); + t1.typsubscript = cast('array_subscript_handler' as regproc) and + not (t1.typelem <> 0 and t1.typlen = -1 and not t1.typbyval); select t1.oid, @@ -577,13 +504,8 @@ select from pg_type as t1 where - t1.typsubscript = - cast('raw_array_subscript_handler' as regproc) and - not ( - t1.typelem <> 0 and - t1.typlen > 0 and - not t1.typbyval - ); + t1.typsubscript = cast('raw_array_subscript_handler' as regproc) and + not (t1.typelem <> 0 and t1.typlen > 0 and not t1.typbyval); select t1.oid, @@ -610,10 +532,7 @@ select t.typname, t.typanalyze from - pg_type as d - inner join - pg_type as t - on d.typbasetype = t.oid + pg_type as d inner join pg_type as t on d.typbasetype = t.oid where d.typanalyze <> t.typanalyze; @@ -622,14 +541,10 @@ select t.typname, t.typanalyze from - pg_type as t - left outer join - pg_range as r - on t.oid = r.rngtypid + pg_type as t left outer join pg_range as r on t.oid = r.rngtypid where t.typbasetype = 0 and - (t.typanalyze = cast('range_typanalyze' as regproc)) <> - (r.rngtypid is not null); + (t.typanalyze = cast('range_typanalyze' as regproc)) <> (r.rngtypid is not null); select t.oid, @@ -640,8 +555,7 @@ from where t.typbasetype = 0 and (t.typanalyze = cast('array_typanalyze' as regproc)) <> - (t.typsubscript = - cast('array_subscript_handler' as regproc)) + (t.typsubscript = cast('array_subscript_handler' as regproc)) order by 1; select @@ -650,10 +564,7 @@ select from pg_class as c1 where - relkind - not in ( - 'r', 'i', 'S', 't', 'v', 'm', 'c', 'f', 'p', 'I' - ) or + relkind not in ('r', 'i', 'S', 't', 'v', 'm', 'c', 'f', 'p', 'I') or relpersistence not in ('p', 'u', 't') or relreplident not in ('d', 'n', 'f', 'i'); @@ -663,8 +574,7 @@ select from pg_class as c1 where - c1.relkind not in ('S', 'v', 'f', 'c', 'p') and - c1.relam = 0; + c1.relkind not in ('S', 'v', 'f', 'c', 'p') and c1.relam = 0; select c1.oid, @@ -672,8 +582,7 @@ select from pg_class as c1 where - c1.relkind in ('S', 'v', 'f', 'c', 'p') and - c1.relam <> 0; + c1.relkind in ('S', 'v', 'f', 'c', 'p') and c1.relam <> 0; select pc.oid, @@ -681,10 +590,7 @@ select pa.amname, pa.amtype from - pg_class as pc - inner join - pg_am as pa - on pc.relam = pa.oid + pg_class as pc inner join pg_am as pa on pc.relam = pa.oid where pc.relkind in ('i', 'I') and pa.amtype <> 'i'; @@ -694,10 +600,7 @@ select pa.amname, pa.amtype from - pg_class as pc - inner join - pg_am as pa - on pc.relam = pa.oid + pg_class as pc inner join pg_am as pa on pc.relam = pa.oid where pc.relkind in ('r', 't', 'm') and pa.amtype <> 't'; @@ -731,14 +634,7 @@ from pg_class as c1 where c1.relnatts <> - ( - select - COUNT(*) - from - pg_attribute as a1 - where - a1.attrelid = c1.oid and a1.attnum > 0 - ); + (select count(*) from pg_attribute as a1 where a1.attrelid = c1.oid and a1.attnum > 0); select a1.attrelid, @@ -754,12 +650,11 @@ where a1.attlen <> t1.typlen or a1.attalign <> t1.typalign or a1.attbyval <> t1.typbyval or - (a1.attstorage <> t1.typstorage and - a1.attstorage <> 'p') + (a1.attstorage <> t1.typstorage and a1.attstorage <> 'p') ); create function is_catalog_text_unique_index_oid(oid) -returns boolean +returns bool language c strict as 'regresslib', 'is_catalog_text_unique_index_oid'; @@ -774,13 +669,7 @@ where indexrelid < 16384 and exists ( - select - 1 - from - pg_attribute - where - attrelid = indexrelid and - atttypid = cast('text' as regtype) + select 1 from pg_attribute where attrelid = indexrelid and atttypid = cast('text' as regtype) )); select @@ -789,9 +678,7 @@ select from pg_range as r where - r.rngtypid = 0 or - r.rngsubtype = 0 or - r.rngsubopc = 0; + r.rngtypid = 0 or r.rngsubtype = 0 or r.rngsubopc = 0; select r.rngtypid, @@ -799,10 +686,7 @@ select r.rngcollation, t.typcollation from - pg_range as r - inner join - pg_type as t - on t.oid = r.rngsubtype + pg_range as r inner join pg_type as t on t.oid = r.rngsubtype where (rngcollation = 0) <> (typcollation = 0); @@ -812,16 +696,12 @@ select o.opcmethod, o.opcname from - pg_range as r - inner join - pg_opclass as o - on o.oid = r.rngsubopc + pg_range as r inner join pg_opclass as o on o.oid = r.rngsubopc where o.opcmethod <> 403 or (o.opcintype <> r.rngsubtype and not ( - o.opcintype = - cast('pg_catalog.anyarray' as regtype) and + o.opcintype = cast('pg_catalog.anyarray' as regtype) and exists ( select @@ -831,8 +711,7 @@ where where oid = r.rngsubtype and typelem <> 0 and - typsubscript = - cast('array_subscript_handler' as regproc) + typsubscript = cast('array_subscript_handler' as regproc) ) )); @@ -841,24 +720,16 @@ select r.rngsubtype, p.proname from - pg_range as r - inner join - pg_proc as p - on p.oid = r.rngcanonical + pg_range as r inner join pg_proc as p on p.oid = r.rngcanonical where - pronargs <> 1 or - proargtypes[0] <> rngtypid or - prorettype <> rngtypid; + pronargs <> 1 or proargtypes[0] <> rngtypid or prorettype <> rngtypid; select r.rngtypid, r.rngsubtype, p.proname from - pg_range as r - inner join - pg_proc as p - on p.oid = r.rngsubdiff + pg_range as r inner join pg_proc as p on p.oid = r.rngsubdiff where pronargs <> 2 or proargtypes[0] <> rngsubtype or @@ -881,17 +752,15 @@ as cast('(1,1),(2,2)' as line), cast('((11,11),(12,12))' as lseg), cast('((11,11),(13,13))' as box), - cast('((11,12),(13,13),(14,14))' as path) - as openedpath, - cast('[(11,12),(13,13),(14,14)]' as path) - as closedpath, + cast('((11,12),(13,13),(14,14))' as path) as openedpath, + cast('[(11,12),(13,13),(14,14)]' as path) as closedpath, cast('((11,12),(13,13),(14,14))' as polygon), cast('1,1,1' as circle), cast('today' as date), cast('now' as time), cast('now' as timestamp), - cast('now' as time with time zone), - cast('now' as timestamp with time zone), + cast('now' as timetz), + cast('now' as timestamptz), cast('12 seconds' as interval), cast('{"reason":"because"}' as json), cast('{"when":"now"}' as jsonb), @@ -900,32 +769,29 @@ as cast('127.0.0.0/8' as cidr), cast('00:01:03:86:1c:ba' as macaddr8), cast('00:01:03:86:1c:ba' as macaddr), - cast(2 as smallint), - cast(4 as int), - cast(8 as bigint), - cast(4 as real), - cast('8' as double precision), + cast(2 as int2), + cast(4 as int4), + cast(8 as int8), + cast(4 as float4), + cast('8' as float8), cast(pi() as numeric), cast('foo' as "char"), cast('c' as bpchar), cast('abc' as varchar), cast('name' as name), cast('txt' as text), - cast(true as boolean), + cast(true as bool), cast('\xDEADBEEF' as bytea), cast(B'10001' as bit(1)), - cast(B'10001' as bit varying) as varbit, + cast(B'10001' as varbit) as varbit, cast('12.34' as money), cast('abc' as refcursor), cast('1 2' as int2vector), cast('1 2' as oidvector), - cast(format('%I=UC/%I', user, user) as aclitem) - as aclitem, - cast('a fat cat sat on a mat and ate a fat rat' - as tsvector), + cast(format('%I=UC/%I', user, user) as aclitem) as aclitem, + cast('a fat cat sat on a mat and ate a fat rat' as tsvector), cast('fat & rat' as tsquery), - cast('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' - as uuid), + cast('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' as uuid), cast('11' as xid8), cast('pg_class' as regclass), cast('regtype' as regtype) as type, @@ -950,16 +816,11 @@ as cast('(3,4)' as numrange), cast('{(3,4)}' as nummultirange), cast('(2020-01-02, 2021-02-03)' as daterange), - cast('{(2020-01-02, 2021-02-03)}' - as datemultirange), - cast('(2020-01-02 03:04:05, 2021-02-03 06:07:08)' - as tsrange), - cast('{(2020-01-02 03:04:05, 2021-02-03 06:07:08)}' - as tsmultirange), - cast('(2020-01-02 03:04:05, 2021-02-03 06:07:08)' - as tstzrange), - cast('{(2020-01-02 03:04:05, 2021-02-03 06:07:08)}' - as tstzmultirange); + cast('{(2020-01-02, 2021-02-03)}' as datemultirange), + cast('(2020-01-02 03:04:05, 2021-02-03 06:07:08)' as tsrange), + cast('{(2020-01-02 03:04:05, 2021-02-03 06:07:08)}' as tsmultirange), + cast('(2020-01-02 03:04:05, 2021-02-03 06:07:08)' as tstzrange), + cast('{(2020-01-02 03:04:05, 2021-02-03 06:07:08)}' as tstzmultirange); select oid, @@ -990,15 +851,7 @@ where 'pg_brin_minmax_multi_summary', 'xml'] as regtype[])) and - not exists - ( - select - 1 - from - pg_type as u - where - u.typarray = t.oid - ) and + not exists (select 1 from pg_type as u where u.typarray = t.oid) and not exists ( select @@ -1006,7 +859,5 @@ where from pg_attribute as a where - a.atttypid = t.oid and - a.attnum > 0 and - a.attrelid = cast('tab_core_types' as regclass) + a.atttypid = t.oid and a.attnum > 0 and a.attrelid = cast('tab_core_types' as regclass) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__type_sanity_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__type_sanity_80.snap index 8f76d63db..4876acd16 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__type_sanity_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__type_sanity_80.snap @@ -9,19 +9,11 @@ from pg_type as t1 where t1.typnamespace = 0 or - (t1.typlen <= 0 and - t1.typlen <> -1 and - t1.typlen <> -2) or - t1.typtype - not in ( - 'b', 'c', 'd', 'e', 'm', 'p', 'r' - ) or + (t1.typlen <= 0 and t1.typlen <> -1 and t1.typlen <> -2) or + t1.typtype not in ('b', 'c', 'd', 'e', 'm', 'p', 'r') or not t1.typisdefined or t1.typalign not in ('c', 's', 'i', 'd') or - t1.typstorage - not in ( - 'p', 'x', 'e', 'm' - ); + t1.typstorage not in ('p', 'x', 'e', 'm'); select t1.oid, @@ -49,10 +41,7 @@ select from pg_type as t1 where - t1.typstorage <> 'p' and - ( - t1.typbyval or t1.typlen <> -1 - ); + t1.typstorage <> 'p' and (t1.typbyval or t1.typlen <> -1); select t1.oid, @@ -78,8 +67,7 @@ where from pg_type as t2 where - t2.typname = - cast('_' || t1.typname as name) and + t2.typname = cast('_' || t1.typname as name) and t2.typelem = t1.oid and t1.typarray = t2.oid ) @@ -91,17 +79,12 @@ select t2.typname as arraytype, t2.typsubscript from - pg_type as t1 - left outer join - pg_type as t2 - on t1.typarray = t2.oid + pg_type as t1 left outer join pg_type as t2 on t1.typarray = t2.oid where t1.typarray <> 0 and ( t2.oid is null or - t2.typsubscript <> - cast('array_subscript_handler' - as regproc) + t2.typsubscript <> cast('array_subscript_handler' as regproc) ); select @@ -111,15 +94,7 @@ from pg_type as t1 where t1.typtype = 'r' and - not exists - ( - select - 1 - from - pg_range as r - where - rngtypid = t1.oid - ); + not exists (select 1 from pg_range as r where rngtypid = t1.oid); select t1.oid, @@ -128,10 +103,7 @@ select t2.typname, t2.typalign from - pg_type as t1 - left outer join - pg_range as r - on rngtypid = t1.oid + pg_type as t1 left outer join pg_range as r on rngtypid = t1.oid left outer join pg_type as t2 on rngsubtype = t2.oid @@ -140,8 +112,7 @@ where ( t1.typalign <> case - when t2.typalign = 'd' - then cast('d' as "char") + when t2.typalign = 'd' then cast('d' as "char") else cast('i' as "char") end or t2.oid is null @@ -166,21 +137,14 @@ from where t1.typinput = p1.oid and not ( - (p1.pronargs = 1 and - p1.proargtypes[0] = - cast('cstring' as regtype)) or + (p1.pronargs = 1 and p1.proargtypes[0] = cast('cstring' as regtype)) or (p1.pronargs = 2 and - p1.proargtypes[0] = - cast('cstring' as regtype) and - p1.proargtypes[1] = - cast('oid' as regtype)) or + p1.proargtypes[0] = cast('cstring' as regtype) and + p1.proargtypes[1] = cast('oid' as regtype)) or (p1.pronargs = 3 and - p1.proargtypes[0] = - cast('cstring' as regtype) and - p1.proargtypes[1] = - cast('oid' as regtype) and - p1.proargtypes[2] = - cast('int4' as regtype)) + p1.proargtypes[0] = cast('cstring' as regtype) and + p1.proargtypes[1] = cast('oid' as regtype) and + p1.proargtypes[2] = cast('int4' as regtype)) ); select @@ -195,10 +159,7 @@ where t1.typinput = p1.oid and t1.typtype in ('b', 'p') and not (t1.typelem <> 0 and t1.typlen < 0) and - not ( - p1.prorettype = t1.oid and - not p1.proretset - ) + not (p1.prorettype = t1.oid and not p1.proretset) order by 1; select @@ -211,7 +172,8 @@ from pg_proc as p1 where t1.typinput = p1.oid and - t1.typelem <> 0 and t1.typlen < 0 and + t1.typelem <> 0 and + t1.typlen < 0 and not p1.oid = cast('array_in' as regproc) order by 1; @@ -224,8 +186,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typinput = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typinput = p1.oid and p1.provolatile not in ('i', 's'); select distinct typtype, @@ -268,11 +229,7 @@ from pg_proc as p1 where t1.typoutput = p1.oid and - not ( - p1.prorettype = - cast('cstring' as regtype) and - not p1.proretset - ); + not (p1.prorettype = cast('cstring' as regtype) and not p1.proretset); select t1.oid, @@ -283,8 +240,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typoutput = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typoutput = p1.oid and p1.provolatile not in ('i', 's'); select distinct typtype, @@ -301,13 +257,9 @@ select t2.oid, t2.typname from - pg_type as t1 - left outer join - pg_type as t2 - on t1.typbasetype = t2.oid + pg_type as t1 left outer join pg_type as t2 on t1.typbasetype = t2.oid where - t1.typtype = 'd' and - t1.typoutput is distinct from t2.typoutput; + t1.typtype = 'd' and t1.typoutput is distinct from t2.typoutput; select t1.oid, @@ -320,21 +272,14 @@ from where t1.typreceive = p1.oid and not ( - (p1.pronargs = 1 and - p1.proargtypes[0] = - cast('internal' as regtype)) or + (p1.pronargs = 1 and p1.proargtypes[0] = cast('internal' as regtype)) or (p1.pronargs = 2 and - p1.proargtypes[0] = - cast('internal' as regtype) and - p1.proargtypes[1] = - cast('oid' as regtype)) or + p1.proargtypes[0] = cast('internal' as regtype) and + p1.proargtypes[1] = cast('oid' as regtype)) or (p1.pronargs = 3 and - p1.proargtypes[0] = - cast('internal' as regtype) and - p1.proargtypes[1] = - cast('oid' as regtype) and - p1.proargtypes[2] = - cast('int4' as regtype)) + p1.proargtypes[0] = cast('internal' as regtype) and + p1.proargtypes[1] = cast('oid' as regtype) and + p1.proargtypes[2] = cast('int4' as regtype)) ); select @@ -349,10 +294,7 @@ where t1.typreceive = p1.oid and t1.typtype in ('b', 'p') and not (t1.typelem <> 0 and t1.typlen < 0) and - not ( - p1.prorettype = t1.oid and - not p1.proretset - ) + not (p1.prorettype = t1.oid and not p1.proretset) order by 1; select @@ -365,7 +307,8 @@ from pg_proc as p1 where t1.typreceive = p1.oid and - t1.typelem <> 0 and t1.typlen < 0 and + t1.typelem <> 0 and + t1.typlen < 0 and not p1.oid = cast('array_recv' as regproc) order by 1; @@ -394,8 +337,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typreceive = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typreceive = p1.oid and p1.provolatile not in ('i', 's'); select distinct typtype, @@ -438,10 +380,7 @@ from pg_proc as p1 where t1.typsend = p1.oid and - not ( - p1.prorettype = cast('bytea' as regtype) and - not p1.proretset - ); + not (p1.prorettype = cast('bytea' as regtype) and not p1.proretset); select t1.oid, @@ -452,8 +391,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typsend = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typsend = p1.oid and p1.provolatile not in ('i', 's'); select distinct typtype, @@ -470,13 +408,9 @@ select t2.oid, t2.typname from - pg_type as t1 - left outer join - pg_type as t2 - on t1.typbasetype = t2.oid + pg_type as t1 left outer join pg_type as t2 on t1.typbasetype = t2.oid where - t1.typtype = 'd' and - t1.typsend is distinct from t2.typsend; + t1.typtype = 'd' and t1.typsend is distinct from t2.typsend; select t1.oid, @@ -490,8 +424,7 @@ where t1.typmodin = p1.oid and not ( p1.pronargs = 1 and - p1.proargtypes[0] = - cast('cstring[]' as regtype) and + p1.proargtypes[0] = cast('cstring[]' as regtype) and p1.prorettype = cast('int4' as regtype) and not p1.proretset ); @@ -505,8 +438,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typmodin = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typmodin = p1.oid and p1.provolatile not in ('i', 's'); select t1.oid, @@ -520,10 +452,8 @@ where t1.typmodout = p1.oid and not ( p1.pronargs = 1 and - p1.proargtypes[0] = - cast('int4' as regtype) and - p1.prorettype = - cast('cstring' as regtype) and + p1.proargtypes[0] = cast('int4' as regtype) and + p1.prorettype = cast('cstring' as regtype) and not p1.proretset ); @@ -536,8 +466,7 @@ from pg_type as t1, pg_proc as p1 where - t1.typmodout = p1.oid and - p1.provolatile not in ('i', 's'); + t1.typmodout = p1.oid and p1.provolatile not in ('i', 's'); select t1.oid, @@ -549,10 +478,7 @@ from pg_type as t2 where t1.typelem = t2.oid and - not ( - t1.typmodin = t2.typmodin and - t1.typmodout = t2.typmodout - ); + not (t1.typmodin = t2.typmodin and t1.typmodout = t2.typmodout); select t1.oid, @@ -563,8 +489,7 @@ from pg_type as t1, pg_type as t2 where - t1.typarray = t2.oid and - not t1.typdelim = t2.typdelim; + t1.typarray = t2.oid and not t1.typdelim = t2.typdelim; select t1.oid, @@ -579,8 +504,7 @@ where t1.typarray = t2.oid and t2.typalign <> case - when t1.typalign = 'd' - then cast('d' as "char") + when t1.typalign = 'd' then cast('d' as "char") else cast('i' as "char") end; @@ -602,14 +526,8 @@ select from pg_type as t1 where - t1.typsubscript = - cast('array_subscript_handler' - as regproc) and - not ( - t1.typelem <> 0 and - t1.typlen = -1 and - not t1.typbyval - ); + t1.typsubscript = cast('array_subscript_handler' as regproc) and + not (t1.typelem <> 0 and t1.typlen = -1 and not t1.typbyval); select t1.oid, @@ -620,14 +538,8 @@ select from pg_type as t1 where - t1.typsubscript = - cast('raw_array_subscript_handler' - as regproc) and - not ( - t1.typelem <> 0 and - t1.typlen > 0 and - not t1.typbyval - ); + t1.typsubscript = cast('raw_array_subscript_handler' as regproc) and + not (t1.typelem <> 0 and t1.typlen > 0 and not t1.typbyval); select t1.oid, @@ -641,8 +553,7 @@ where t1.typanalyze = p1.oid and not ( p1.pronargs = 1 and - p1.proargtypes[0] = - cast('internal' as regtype) and + p1.proargtypes[0] = cast('internal' as regtype) and p1.prorettype = cast('bool' as regtype) and not p1.proretset ); @@ -655,10 +566,7 @@ select t.typname, t.typanalyze from - pg_type as d - inner join - pg_type as t - on d.typbasetype = t.oid + pg_type as d inner join pg_type as t on d.typbasetype = t.oid where d.typanalyze <> t.typanalyze; @@ -667,14 +575,10 @@ select t.typname, t.typanalyze from - pg_type as t - left outer join - pg_range as r - on t.oid = r.rngtypid + pg_type as t left outer join pg_range as r on t.oid = r.rngtypid where t.typbasetype = 0 and - (t.typanalyze = - cast('range_typanalyze' as regproc)) <> + (t.typanalyze = cast('range_typanalyze' as regproc)) <> (r.rngtypid is not null); select @@ -685,11 +589,8 @@ from pg_type as t where t.typbasetype = 0 and - (t.typanalyze = - cast('array_typanalyze' as regproc)) <> - (t.typsubscript = - cast('array_subscript_handler' - as regproc)) + (t.typanalyze = cast('array_typanalyze' as regproc)) <> + (t.typsubscript = cast('array_subscript_handler' as regproc)) order by 1; select @@ -698,10 +599,7 @@ select from pg_class as c1 where - relkind - not in ( - 'r', 'i', 'S', 't', 'v', 'm', 'c', 'f', 'p', 'I' - ) or + relkind not in ('r', 'i', 'S', 't', 'v', 'm', 'c', 'f', 'p', 'I') or relpersistence not in ('p', 'u', 't') or relreplident not in ('d', 'n', 'f', 'i'); @@ -711,11 +609,7 @@ select from pg_class as c1 where - c1.relkind - not in ( - 'S', 'v', 'f', 'c', 'p' - ) and - c1.relam = 0; + c1.relkind not in ('S', 'v', 'f', 'c', 'p') and c1.relam = 0; select c1.oid, @@ -723,8 +617,7 @@ select from pg_class as c1 where - c1.relkind in ('S', 'v', 'f', 'c', 'p') and - c1.relam <> 0; + c1.relkind in ('S', 'v', 'f', 'c', 'p') and c1.relam <> 0; select pc.oid, @@ -732,13 +625,9 @@ select pa.amname, pa.amtype from - pg_class as pc - inner join - pg_am as pa - on pc.relam = pa.oid + pg_class as pc inner join pg_am as pa on pc.relam = pa.oid where - pc.relkind in ('i', 'I') and - pa.amtype <> 'i'; + pc.relkind in ('i', 'I') and pa.amtype <> 'i'; select pc.oid, @@ -746,13 +635,9 @@ select pa.amname, pa.amtype from - pg_class as pc - inner join - pg_am as pa - on pc.relam = pa.oid + pg_class as pc inner join pg_am as pa on pc.relam = pa.oid where - pc.relkind in ('r', 't', 'm') and - pa.amtype <> 't'; + pc.relkind in ('r', 't', 'm') and pa.amtype <> 't'; select a1.attrelid, @@ -775,8 +660,7 @@ from pg_attribute as a1, pg_class as c1 where - a1.attrelid = c1.oid and - a1.attnum > c1.relnatts; + a1.attrelid = c1.oid and a1.attnum > c1.relnatts; select c1.oid, @@ -787,7 +671,7 @@ where c1.relnatts <> ( select - COUNT(*) + count(*) from pg_attribute as a1 where @@ -808,12 +692,11 @@ where a1.attlen <> t1.typlen or a1.attalign <> t1.typalign or a1.attbyval <> t1.typbyval or - (a1.attstorage <> t1.typstorage and - a1.attstorage <> 'p') + (a1.attstorage <> t1.typstorage and a1.attstorage <> 'p') ); create function is_catalog_text_unique_index_oid(oid) -returns boolean +returns bool language c strict as 'regresslib', 'is_catalog_text_unique_index_oid'; @@ -823,9 +706,7 @@ select from pg_index where - is_catalog_text_unique_index_oid( - indexrelid - ) <> + is_catalog_text_unique_index_oid(indexrelid) <> (indisunique and indexrelid < 16384 and exists @@ -835,8 +716,7 @@ where from pg_attribute where - attrelid = indexrelid and - atttypid = cast('text' as regtype) + attrelid = indexrelid and atttypid = cast('text' as regtype) )); select @@ -845,9 +725,7 @@ select from pg_range as r where - r.rngtypid = 0 or - r.rngsubtype = 0 or - r.rngsubopc = 0; + r.rngtypid = 0 or r.rngsubtype = 0 or r.rngsubopc = 0; select r.rngtypid, @@ -855,10 +733,7 @@ select r.rngcollation, t.typcollation from - pg_range as r - inner join - pg_type as t - on t.oid = r.rngsubtype + pg_range as r inner join pg_type as t on t.oid = r.rngsubtype where (rngcollation = 0) <> (typcollation = 0); @@ -868,16 +743,12 @@ select o.opcmethod, o.opcname from - pg_range as r - inner join - pg_opclass as o - on o.oid = r.rngsubopc + pg_range as r inner join pg_opclass as o on o.oid = r.rngsubopc where o.opcmethod <> 403 or (o.opcintype <> r.rngsubtype and not ( - o.opcintype = - cast('pg_catalog.anyarray' as regtype) and + o.opcintype = cast('pg_catalog.anyarray' as regtype) and exists ( select @@ -887,9 +758,7 @@ where where oid = r.rngsubtype and typelem <> 0 and - typsubscript = - cast('array_subscript_handler' - as regproc) + typsubscript = cast('array_subscript_handler' as regproc) ) )); @@ -898,30 +767,21 @@ select r.rngsubtype, p.proname from - pg_range as r - inner join - pg_proc as p - on p.oid = r.rngcanonical + pg_range as r inner join pg_proc as p on p.oid = r.rngcanonical where - pronargs <> 1 or - proargtypes[0] <> rngtypid or - prorettype <> rngtypid; + pronargs <> 1 or proargtypes[0] <> rngtypid or prorettype <> rngtypid; select r.rngtypid, r.rngsubtype, p.proname from - pg_range as r - inner join - pg_proc as p - on p.oid = r.rngsubdiff + pg_range as r inner join pg_proc as p on p.oid = r.rngsubdiff where pronargs <> 2 or proargtypes[0] <> rngsubtype or proargtypes[1] <> rngsubtype or - prorettype <> - cast('pg_catalog.float8' as regtype); + prorettype <> cast('pg_catalog.float8' as regtype); select r.rngtypid, @@ -930,8 +790,7 @@ select from pg_range as r where - r.rngmultitypid is null or - r.rngmultitypid = 0; + r.rngmultitypid is null or r.rngmultitypid = 0; create table tab_core_types as @@ -940,20 +799,15 @@ as cast('(1,1),(2,2)' as line), cast('((11,11),(12,12))' as lseg), cast('((11,11),(13,13))' as box), - cast('((11,12),(13,13),(14,14))' - as path) - as openedpath, - cast('[(11,12),(13,13),(14,14)]' - as path) - as closedpath, - cast('((11,12),(13,13),(14,14))' - as polygon), + cast('((11,12),(13,13),(14,14))' as path) as openedpath, + cast('[(11,12),(13,13),(14,14)]' as path) as closedpath, + cast('((11,12),(13,13),(14,14))' as polygon), cast('1,1,1' as circle), cast('today' as date), cast('now' as time), cast('now' as timestamp), - cast('now' as time with time zone), - cast('now' as timestamp with time zone), + cast('now' as timetz), + cast('now' as timestamptz), cast('12 seconds' as interval), cast('{"reason":"because"}' as json), cast('{"when":"now"}' as jsonb), @@ -962,39 +816,34 @@ as cast('127.0.0.0/8' as cidr), cast('00:01:03:86:1c:ba' as macaddr8), cast('00:01:03:86:1c:ba' as macaddr), - cast(2 as smallint), - cast(4 as int), - cast(8 as bigint), - cast(4 as real), - cast('8' as double precision), + cast(2 as int2), + cast(4 as int4), + cast(8 as int8), + cast(4 as float4), + cast('8' as float8), cast(pi() as numeric), cast('foo' as "char"), cast('c' as bpchar), cast('abc' as varchar), cast('name' as name), cast('txt' as text), - cast(true as boolean), + cast(true as bool), cast('\xDEADBEEF' as bytea), cast(B'10001' as bit(1)), - cast(B'10001' as bit varying) as varbit, + cast(B'10001' as varbit) as varbit, cast('12.34' as money), cast('abc' as refcursor), cast('1 2' as int2vector), cast('1 2' as oidvector), - cast(format('%I=UC/%I', user, user) - as aclitem) - as aclitem, - cast('a fat cat sat on a mat and ate a fat rat' - as tsvector), + cast(format('%I=UC/%I', user, user) as aclitem) as aclitem, + cast('a fat cat sat on a mat and ate a fat rat' as tsvector), cast('fat & rat' as tsquery), - cast('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' - as uuid), + cast('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11' as uuid), cast('11' as xid8), cast('pg_class' as regclass), cast('regtype' as regtype) as type, cast('pg_monitor' as regrole), - cast(cast('pg_class' as regclass) - as oid), + cast(cast('pg_class' as regclass) as oid), cast('template1' as regdatabase), cast('(1,1)' as tid), cast('2' as xid), @@ -1002,34 +851,23 @@ as cast('10:20:10,14,15' as txid_snapshot), cast('10:20:10,14,15' as pg_snapshot), cast('16/B374D848' as pg_lsn), - cast(1 - as information_schema.cardinal_number), - cast('l' - as information_schema.character_data), - cast('n' - as information_schema.sql_identifier), - cast('now' - as information_schema.time_stamp), - cast('YES' - as information_schema.yes_or_no), + cast(1 as information_schema.cardinal_number), + cast('l' as information_schema.character_data), + cast('n' as information_schema.sql_identifier), + cast('now' as information_schema.time_stamp), + cast('YES' as information_schema.yes_or_no), cast('(1,2)' as int4range), cast('{(1,2)}' as int4multirange), cast('(3,4)' as int8range), cast('{(3,4)}' as int8multirange), cast('(3,4)' as numrange), cast('{(3,4)}' as nummultirange), - cast('(2020-01-02, 2021-02-03)' - as daterange), - cast('{(2020-01-02, 2021-02-03)}' - as datemultirange), - cast('(2020-01-02 03:04:05, 2021-02-03 06:07:08)' - as tsrange), - cast('{(2020-01-02 03:04:05, 2021-02-03 06:07:08)}' - as tsmultirange), - cast('(2020-01-02 03:04:05, 2021-02-03 06:07:08)' - as tstzrange), - cast('{(2020-01-02 03:04:05, 2021-02-03 06:07:08)}' - as tstzmultirange); + cast('(2020-01-02, 2021-02-03)' as daterange), + cast('{(2020-01-02, 2021-02-03)}' as datemultirange), + cast('(2020-01-02 03:04:05, 2021-02-03 06:07:08)' as tsrange), + cast('{(2020-01-02 03:04:05, 2021-02-03 06:07:08)}' as tsmultirange), + cast('(2020-01-02 03:04:05, 2021-02-03 06:07:08)' as tstzrange), + cast('{(2020-01-02 03:04:05, 2021-02-03 06:07:08)}' as tstzmultirange); select oid, @@ -1060,15 +898,7 @@ where 'pg_brin_minmax_multi_summary', 'xml'] as regtype[])) and - not exists - ( - select - 1 - from - pg_type as u - where - u.typarray = t.oid - ) and + not exists (select 1 from pg_type as u where u.typarray = t.oid) and not exists ( select @@ -1078,6 +908,5 @@ where where a.atttypid = t.oid and a.attnum > 0 and - a.attrelid = - cast('tab_core_types' as regclass) + a.attrelid = cast('tab_core_types' as regclass) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__typed_table_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__typed_table_100.snap index f5fc0fa1d..2a3af5abd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__typed_table_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__typed_table_100.snap @@ -15,9 +15,9 @@ select * from persons; create function get_all_persons() returns setof person_type language sql -as $function$ -SELECT * FROM persons; -$function$; +as $$ + SELECT * FROM persons; +$$; select * from get_all_persons(); @@ -68,9 +68,7 @@ insert into persons values (1, 'test'); create function namelen(person_type) returns int language sql -as $function$ -SELECT length($1.name) -$function$; +as $$ SELECT length($1.name) $$; select id, namelen(persons) from persons; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__typed_table_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__typed_table_80.snap index ff9e7ed5b..f494637a7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__typed_table_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__typed_table_80.snap @@ -15,9 +15,9 @@ select * from persons; create function get_all_persons() returns setof person_type language sql -as $function$ -SELECT * FROM persons; -$function$; +as $$ + SELECT * FROM persons; +$$; select * from get_all_persons(); @@ -84,9 +84,7 @@ insert into persons values (1, 'test'); create function namelen(person_type) returns int language sql -as $function$ -SELECT length($1.name) -$function$; +as $$ SELECT length($1.name) $$; select id, namelen(persons) from persons; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__unicode_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__unicode_100.snap index e72f78f32..45b547f51 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__unicode_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__unicode_100.snap @@ -13,43 +13,35 @@ select unicode_assigned('abc'); select unicode_assigned('abc􏿿'); -select NORMALIZE(''); +select normalize(''); -select NORMALIZE('äⓑc') = 'äⓑc' collate "C" as test_default; +select normalize('äⓑc') = 'äⓑc' collate "C" as test_default; -select NORMALIZE('äⓑc', NFC) = 'äⓑc' collate "C" as test_nfc; +select normalize('äⓑc', nfc) = 'äⓑc' collate "C" as test_nfc; -select NORMALIZE('äbc', NFC) = 'äbc' collate "C" as test_nfc_idem; +select normalize('äbc', nfc) = 'äbc' collate "C" as test_nfc_idem; -select NORMALIZE('äⓑc', NFD) = 'äⓑc' collate "C" as test_nfd; +select normalize('äⓑc', nfd) = 'äⓑc' collate "C" as test_nfd; -select NORMALIZE('äⓑc', NFKC) = 'äbc' collate "C" as test_nfkc; +select normalize('äⓑc', nfkc) = 'äbc' collate "C" as test_nfkc; -select NORMALIZE('äⓑc', NFKD) = 'äbc' collate "C" as test_nfkd; +select normalize('äⓑc', nfkd) = 'äbc' collate "C" as test_nfkd; select "normalize"('abc', 'def'); -select is_normalized('äⓑc') as test_default; +select ('äⓑc' is normalized) as test_default; -select is_normalized('äⓑc', 'NFC') as test_nfc; +select ('äⓑc' is nfc normalized) as test_nfc; select num, val, - is_normalized(val, 'NFC') as nfc, - is_normalized(val, 'NFD') as nfd, - is_normalized(val, 'NFKC') as nfkc, - is_normalized(val, 'NFKD') as nfkd + (val is nfc normalized) as nfc, + (val is nfd normalized) as nfd, + (val is nfkc normalized) as nfkc, + (val is nfkd normalized) as nfkd from - ( - values - (1, 'äbc'), - (2, 'äbc'), - (3, 'äⓑc'), - (4, 'äⓑc'), - (5, '') - ) - as vals (num, val) + (values (1, 'äbc'), (2, 'äbc'), (3, 'äⓑc'), (4, 'äⓑc'), (5, '')) as vals (num, val) order by num; select is_normalized('abc', 'def'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__unicode_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__unicode_80.snap index e72f78f32..c67dc51ee 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__unicode_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__unicode_80.snap @@ -13,41 +13,36 @@ select unicode_assigned('abc'); select unicode_assigned('abc􏿿'); -select NORMALIZE(''); +select normalize(''); -select NORMALIZE('äⓑc') = 'äⓑc' collate "C" as test_default; +select normalize('äⓑc') = 'äⓑc' collate "C" as test_default; -select NORMALIZE('äⓑc', NFC) = 'äⓑc' collate "C" as test_nfc; +select normalize('äⓑc', nfc) = 'äⓑc' collate "C" as test_nfc; -select NORMALIZE('äbc', NFC) = 'äbc' collate "C" as test_nfc_idem; +select normalize('äbc', nfc) = 'äbc' collate "C" as test_nfc_idem; -select NORMALIZE('äⓑc', NFD) = 'äⓑc' collate "C" as test_nfd; +select normalize('äⓑc', nfd) = 'äⓑc' collate "C" as test_nfd; -select NORMALIZE('äⓑc', NFKC) = 'äbc' collate "C" as test_nfkc; +select normalize('äⓑc', nfkc) = 'äbc' collate "C" as test_nfkc; -select NORMALIZE('äⓑc', NFKD) = 'äbc' collate "C" as test_nfkd; +select normalize('äⓑc', nfkd) = 'äbc' collate "C" as test_nfkd; select "normalize"('abc', 'def'); -select is_normalized('äⓑc') as test_default; +select ('äⓑc' is normalized) as test_default; -select is_normalized('äⓑc', 'NFC') as test_nfc; +select ('äⓑc' is nfc normalized) as test_nfc; select num, val, - is_normalized(val, 'NFC') as nfc, - is_normalized(val, 'NFD') as nfd, - is_normalized(val, 'NFKC') as nfkc, - is_normalized(val, 'NFKD') as nfkd + (val is nfc normalized) as nfc, + (val is nfd normalized) as nfd, + (val is nfkc normalized) as nfkc, + (val is nfkd normalized) as nfkd from ( - values - (1, 'äbc'), - (2, 'äbc'), - (3, 'äⓑc'), - (4, 'äⓑc'), - (5, '') + values (1, 'äbc'), (2, 'äbc'), (3, 'äⓑc'), (4, 'äⓑc'), (5, '') ) as vals (num, val) order by num; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__union_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__union_100.snap index b2d74e4d3..3f21507a7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__union_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__union_100.snap @@ -23,20 +23,15 @@ select 1.1 as two union select 2 order by 1; select 1 as two union select 2.2 order by 1; -select 1 as one union select cast(1.0 as double precision) order by 1; +select 1 as one union select cast(1.0 as float8) order by 1; select 1.1 as two union all select 2 order by 1; -select cast(1.0 as double precision) as two union all select 1 order by 1; +select cast(1.0 as float8) as two union all select 1 order by 1; select 1.1 as three union select 2 union select 3 order by 1; -select cast(1.1 as double precision) as two -union -select 2 -union -select cast(2.0 as double precision) -order by 1; +select cast(1.1 as float8) as two union select 2 union select cast(2.0 as float8) order by 1; select 1.1 as three union select 2 union all select 2 order by 1; @@ -50,19 +45,9 @@ select f1 as nine from float8_tbl union select f1 from int4_tbl order by 1; select f1 as ten from float8_tbl union all select f1 from int4_tbl; -select - f1 as five -from - float8_tbl -where - f1 between -1e6 and 1e6 +select f1 as five from float8_tbl where f1 between -1e6 and 1e6 union -select - f1 -from - int4_tbl -where - f1 between 0 and 1000000 +select f1 from int4_tbl where f1 between 0 and 1000000 order by 1; select cast(f1 as char(4)) as three from varchar_tbl union select f1 from char_tbl order by 1; @@ -71,11 +56,9 @@ select f1 as three from varchar_tbl union select cast(f1 as varchar) from char_t select f1 as eight from varchar_tbl union all select f1 from char_tbl; -select f1 as five from text_tbl +select f1 as five from text_tbl union select f1 from varchar_tbl union -select f1 from varchar_tbl -union -select rtrim(f1) from char_tbl +select trim(trailing f1) from char_tbl order by 1; select q1 from int8_tbl order by 1; @@ -106,13 +89,13 @@ select 1, 2, 3 union select 4, 5, 6 except select 4, 5, 6; set enable_hashagg = 'on'; -select COUNT(*) from (select unique1 from tenk1 union select fivethous from tenk1) as ss; +select count(*) from (select unique1 from tenk1 union select fivethous from tenk1) as ss; -select COUNT(*) from (select unique1 from tenk1 union select fivethous from tenk1) as ss; +select count(*) from (select unique1 from tenk1 union select fivethous from tenk1) as ss; -select COUNT(*) from (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; +select count(*) from (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; -select COUNT(*) from (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; +select count(*) from (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; set enable_indexscan = off; @@ -130,13 +113,13 @@ select * from int8_tbl order by 1, 2; set enable_hashagg = off; -select COUNT(*) from (select unique1 from tenk1 union select fivethous from tenk1) as ss; +select count(*) from (select unique1 from tenk1 union select fivethous from tenk1) as ss; -select COUNT(*) from (select unique1 from tenk1 union select fivethous from tenk1) as ss; +select count(*) from (select unique1 from tenk1 union select fivethous from tenk1) as ss; -select COUNT(*) from (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; +select count(*) from (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; -select COUNT(*) from (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; +select count(*) from (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; select unique1 from tenk1 except select unique2 from tenk1 where unique2 <> 10; @@ -148,279 +131,109 @@ reset enable_hashagg; set enable_hashagg = 'on'; -select - x -from - ( - values - (cast('11' as bit varying)), - (cast('10' as bit varying)) - ) - as _ (x) +select x from (values (cast('11' as varbit)), (cast('10' as varbit))) as _ (x) union -select - x -from - ( - values - (cast('11' as bit varying)), - (cast('10' as bit varying)) - ) - as _ (x); +select x from (values (cast('11' as varbit)), (cast('10' as varbit))) as _ (x); set enable_hashagg = off; -select - x -from - ( - values - (cast('11' as bit varying)), - (cast('10' as bit varying)) - ) - as _ (x) +select x from (values (cast('11' as varbit)), (cast('10' as varbit))) as _ (x) union -select - x -from - ( - values - (cast('11' as bit varying)), - (cast('10' as bit varying)) - ) - as _ (x); +select x from (values (cast('11' as varbit)), (cast('10' as varbit))) as _ (x); reset enable_hashagg; set enable_hashagg = 'on'; -select - x -from - (values (array[1, 2]), (array[1, 3])) as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) union -select - x -from - (values (array[1, 2]), (array[1, 4])) as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - (values (array[1, 2]), (array[1, 3])) as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) union -select - x -from - (values (array[1, 2]), (array[1, 4])) as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - (values (array[1, 2]), (array[1, 3])) as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) except -select - x -from - (values (array[1, 2]), (array[1, 4])) as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - (values (array[1, 2]), (array[1, 3])) as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) except -select - x -from - (values (array[1, 2]), (array[1, 4])) as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - ( - values - (array[cast('10' as bit varying)]), - (array[cast('11' as bit varying)]) - ) - as _ (x) +select x from (values (array[cast('10' as varbit)]), (array[cast('11' as varbit)])) as _ (x) union -select - x -from - ( - values - (array[cast('10' as bit varying)]), - (array[cast('01' as bit varying)]) - ) - as _ (x); +select x from (values (array[cast('10' as varbit)]), (array[cast('01' as varbit)])) as _ (x); -select - x -from - ( - values - (array[cast('10' as bit varying)]), - (array[cast('11' as bit varying)]) - ) - as _ (x) +select x from (values (array[cast('10' as varbit)]), (array[cast('11' as varbit)])) as _ (x) union -select - x -from - ( - values - (array[cast('10' as bit varying)]), - (array[cast('01' as bit varying)]) - ) - as _ (x); +select x from (values (array[cast('10' as varbit)]), (array[cast('01' as varbit)])) as _ (x); set enable_hashagg = off; -select - x -from - (values (array[1, 2]), (array[1, 3])) as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) union -select - x -from - (values (array[1, 2]), (array[1, 4])) as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - (values (array[1, 2]), (array[1, 3])) as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) union -select - x -from - (values (array[1, 2]), (array[1, 4])) as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - (values (array[1, 2]), (array[1, 3])) as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) except -select - x -from - (values (array[1, 2]), (array[1, 4])) as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - (values (array[1, 2]), (array[1, 3])) as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) except -select - x -from - (values (array[1, 2]), (array[1, 4])) as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); reset enable_hashagg; set enable_hashagg = 'on'; -select - x -from - (values (row(1, 2)), (row(1, 3))) as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) union -select - x -from - (values (row(1, 2)), (row(1, 4))) as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - (values (row(1, 2)), (row(1, 3))) as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) union -select - x -from - (values (row(1, 2)), (row(1, 4))) as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - (values (row(1, 2)), (row(1, 3))) as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) except -select - x -from - (values (row(1, 2)), (row(1, 4))) as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - (values (row(1, 2)), (row(1, 3))) as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) except -select - x -from - (values (row(1, 2)), (row(1, 4))) as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - ( - values - (row(cast('10' as bit varying))), - (row(cast('11' as bit varying))) - ) - as _ (x) +select x from (values (row(cast('10' as varbit))), (row(cast('11' as varbit)))) as _ (x) union -select - x -from - ( - values - (row(cast('10' as bit varying))), - (row(cast('01' as bit varying))) - ) - as _ (x); +select x from (values (row(cast('10' as varbit))), (row(cast('01' as varbit)))) as _ (x); -select - x -from - ( - values - (row(cast('10' as bit varying))), - (row(cast('11' as bit varying))) - ) - as _ (x) +select x from (values (row(cast('10' as varbit))), (row(cast('11' as varbit)))) as _ (x) union -select - x -from - ( - values - (row(cast('10' as bit varying))), - (row(cast('01' as bit varying))) - ) - as _ (x); +select x from (values (row(cast('10' as varbit))), (row(cast('01' as varbit)))) as _ (x); -create type ct1 as (f1 bit varying); +create type ct1 as (f1 varbit); select x from ( - values - (cast(row(cast('10' as bit varying)) as ct1)), - (cast(row(cast('11' as bit varying)) as ct1)) + values (cast(row(cast('10' as varbit)) as ct1)), (cast(row(cast('11' as varbit)) as ct1)) ) as _ (x) union @@ -428,9 +241,7 @@ select x from ( - values - (cast(row(cast('10' as bit varying)) as ct1)), - (cast(row(cast('01' as bit varying)) as ct1)) + values (cast(row(cast('10' as varbit)) as ct1)), (cast(row(cast('01' as varbit)) as ct1)) ) as _ (x); @@ -438,9 +249,7 @@ select x from ( - values - (cast(row(cast('10' as bit varying)) as ct1)), - (cast(row(cast('11' as bit varying)) as ct1)) + values (cast(row(cast('10' as varbit)) as ct1)), (cast(row(cast('11' as varbit)) as ct1)) ) as _ (x) union @@ -448,9 +257,7 @@ select x from ( - values - (cast(row(cast('10' as bit varying)) as ct1)), - (cast(row(cast('01' as bit varying)) as ct1)) + values (cast(row(cast('10' as varbit)) as ct1)), (cast(row(cast('01' as varbit)) as ct1)) ) as _ (x); @@ -458,49 +265,25 @@ drop type ct1; set enable_hashagg = off; -select - x -from - (values (row(1, 2)), (row(1, 3))) as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) union -select - x -from - (values (row(1, 2)), (row(1, 4))) as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - (values (row(1, 2)), (row(1, 3))) as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) union -select - x -from - (values (row(1, 2)), (row(1, 4))) as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - (values (row(1, 2)), (row(1, 3))) as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) except -select - x -from - (values (row(1, 2)), (row(1, 4))) as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - (values (row(1, 2)), (row(1, 3))) as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) except -select - x -from - (values (row(1, 2)), (row(1, 4))) as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select cast('123' as xid) union select cast('123' as xid); @@ -514,15 +297,10 @@ select q2 from int8_tbl union all select q2 from int8_tbl order by 1; select q1 from int8_tbl intersect -(select q2 from int8_tbl -union all -select q2 from int8_tbl) +(select q2 from int8_tbl union all select q2 from int8_tbl) order by 1; -(select q1 from int8_tbl -intersect -select q2 from int8_tbl -order by 1) +(select q1 from int8_tbl intersect select q2 from int8_tbl order by 1) union all select q2 from int8_tbl; @@ -530,10 +308,7 @@ select q1 from int8_tbl union all select q2 from int8_tbl except select q1 from select q1 from int8_tbl union all -(select q2 from int8_tbl -except -select q1 from int8_tbl -order by 1); +(select q2 from int8_tbl except select q1 from int8_tbl order by 1); select q1 from int8_tbl union all select q2 from int8_tbl except select q1 from int8_tbl order by 1; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__union_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__union_80.snap index 340ba9d02..80d61b6d1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__union_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__union_80.snap @@ -23,20 +23,17 @@ select 1.1 as two union select 2 order by 1; select 1 as two union select 2.2 order by 1; -select 1 as one union select cast(1.0 as double precision) order by 1; +select 1 as one union select cast(1.0 as float8) order by 1; select 1.1 as two union all select 2 order by 1; -select cast(1.0 as double precision) as two union all select 1 order by 1; +select cast(1.0 as float8) as two union all select 1 order by 1; select 1.1 as three union select 2 union select 3 order by 1; -select - cast(1.1 as double precision) as two -union -select 2 +select cast(1.1 as float8) as two union select 2 union -select cast(2.0 as double precision) +select cast(2.0 as float8) order by 1; select 1.1 as three union select 2 union all select 2 order by 1; @@ -51,25 +48,12 @@ select f1 as nine from float8_tbl union select f1 from int4_tbl order by 1; select f1 as ten from float8_tbl union all select f1 from int4_tbl; -select - f1 as five -from - float8_tbl -where - f1 between -1e6 and 1e6 +select f1 as five from float8_tbl where f1 between -1e6 and 1e6 union -select - f1 -from - int4_tbl -where - f1 between 0 and 1000000 +select f1 from int4_tbl where f1 between 0 and 1000000 order by 1; -select - cast(f1 as char(4)) as three -from - varchar_tbl +select cast(f1 as char(4)) as three from varchar_tbl union select f1 from char_tbl order by 1; @@ -81,11 +65,9 @@ order by 1; select f1 as eight from varchar_tbl union all select f1 from char_tbl; -select f1 as five from text_tbl +select f1 as five from text_tbl union select f1 from varchar_tbl union -select f1 from varchar_tbl -union -select rtrim(f1) from char_tbl +select trim(trailing f1) from char_tbl order by 1; select q1 from int8_tbl order by 1; @@ -117,44 +99,24 @@ select 1, 2, 3 union select 4, 5, 6 except select 4, 5, 6; set enable_hashagg = 'on'; select - COUNT(*) + count(*) from - ( - select unique1 from tenk1 - union - select fivethous from tenk1 - ) - as ss; + (select unique1 from tenk1 union select fivethous from tenk1) as ss; select - COUNT(*) + count(*) from - ( - select unique1 from tenk1 - union - select fivethous from tenk1 - ) - as ss; + (select unique1 from tenk1 union select fivethous from tenk1) as ss; select - COUNT(*) + count(*) from - ( - select unique1 from tenk1 - intersect - select fivethous from tenk1 - ) - as ss; + (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; select - COUNT(*) + count(*) from - ( - select unique1 from tenk1 - intersect - select fivethous from tenk1 - ) - as ss; + (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; set enable_indexscan = off; @@ -173,44 +135,24 @@ select * from int8_tbl order by 1, 2; set enable_hashagg = off; select - COUNT(*) + count(*) from - ( - select unique1 from tenk1 - union - select fivethous from tenk1 - ) - as ss; + (select unique1 from tenk1 union select fivethous from tenk1) as ss; select - COUNT(*) + count(*) from - ( - select unique1 from tenk1 - union - select fivethous from tenk1 - ) - as ss; + (select unique1 from tenk1 union select fivethous from tenk1) as ss; select - COUNT(*) + count(*) from - ( - select unique1 from tenk1 - intersect - select fivethous from tenk1 - ) - as ss; + (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; select - COUNT(*) + count(*) from - ( - select unique1 from tenk1 - intersect - select fivethous from tenk1 - ) - as ss; + (select unique1 from tenk1 intersect select fivethous from tenk1) as ss; select unique1 from tenk1 except select unique2 from tenk1 where unique2 <> 10; @@ -218,365 +160,147 @@ select unique1 from tenk1 except select unique2 from tenk1 where unique2 <> 10; select f1 from int4_tbl union all -(select unique1 from tenk1 -union -select unique2 from tenk1); +(select unique1 from tenk1 union select unique2 from tenk1); reset enable_hashagg; set enable_hashagg = 'on'; -select - x -from - ( - values - (cast('11' as bit varying)), - (cast('10' as bit varying)) - ) - as _ (x) +select x from (values (cast('11' as varbit)), (cast('10' as varbit))) as _ (x) union -select - x -from - ( - values - (cast('11' as bit varying)), - (cast('10' as bit varying)) - ) - as _ (x); +select x from (values (cast('11' as varbit)), (cast('10' as varbit))) as _ (x); set enable_hashagg = off; -select - x -from - ( - values - (cast('11' as bit varying)), - (cast('10' as bit varying)) - ) - as _ (x) +select x from (values (cast('11' as varbit)), (cast('10' as varbit))) as _ (x) union -select - x -from - ( - values - (cast('11' as bit varying)), - (cast('10' as bit varying)) - ) - as _ (x); +select x from (values (cast('11' as varbit)), (cast('10' as varbit))) as _ (x); reset enable_hashagg; set enable_hashagg = 'on'; -select - x -from - ( - values (array[1, 2]), (array[1, 3]) - ) - as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) union -select - x -from - ( - values (array[1, 2]), (array[1, 4]) - ) - as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - ( - values (array[1, 2]), (array[1, 3]) - ) - as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) union -select - x -from - ( - values (array[1, 2]), (array[1, 4]) - ) - as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - ( - values (array[1, 2]), (array[1, 3]) - ) - as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) except -select - x -from - ( - values (array[1, 2]), (array[1, 4]) - ) - as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - ( - values (array[1, 2]), (array[1, 3]) - ) - as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) except -select - x -from - ( - values (array[1, 2]), (array[1, 4]) - ) - as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from - ( - values - (array[cast('10' as bit varying)]), - (array[cast('11' as bit varying)]) - ) - as _ (x) + (values (array[cast('10' as varbit)]), (array[cast('11' as varbit)])) as _ (x) union select x from ( - values - (array[cast('10' as bit varying)]), - (array[cast('01' as bit varying)]) + values (array[cast('10' as varbit)]), (array[cast('01' as varbit)]) ) as _ (x); select x from - ( - values - (array[cast('10' as bit varying)]), - (array[cast('11' as bit varying)]) - ) - as _ (x) + (values (array[cast('10' as varbit)]), (array[cast('11' as varbit)])) as _ (x) union select x from ( - values - (array[cast('10' as bit varying)]), - (array[cast('01' as bit varying)]) + values (array[cast('10' as varbit)]), (array[cast('01' as varbit)]) ) as _ (x); set enable_hashagg = off; -select - x -from - ( - values (array[1, 2]), (array[1, 3]) - ) - as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) union -select - x -from - ( - values (array[1, 2]), (array[1, 4]) - ) - as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - ( - values (array[1, 2]), (array[1, 3]) - ) - as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) union -select - x -from - ( - values (array[1, 2]), (array[1, 4]) - ) - as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from (values (array[1, 2]), (array[1, 4])) as _ (x); select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - ( - values (array[1, 2]), (array[1, 3]) - ) - as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) except -select - x -from - ( - values (array[1, 2]), (array[1, 4]) - ) - as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); -select - x -from - ( - values (array[1, 2]), (array[1, 3]) - ) - as _ (x) +select x from (values (array[1, 2]), (array[1, 3])) as _ (x) except -select - x -from - ( - values (array[1, 2]), (array[1, 4]) - ) - as _ (x); +select x from (values (array[1, 2]), (array[1, 4])) as _ (x); reset enable_hashagg; set enable_hashagg = 'on'; -select - x -from - ( - values (row(1, 2)), (row(1, 3)) - ) - as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) union -select - x -from - ( - values (row(1, 2)), (row(1, 4)) - ) - as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - ( - values (row(1, 2)), (row(1, 3)) - ) - as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) union -select - x -from - ( - values (row(1, 2)), (row(1, 4)) - ) - as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - ( - values (row(1, 2)), (row(1, 3)) - ) - as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) except -select - x -from - ( - values (row(1, 2)), (row(1, 4)) - ) - as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - ( - values (row(1, 2)), (row(1, 3)) - ) - as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) except -select - x -from - ( - values (row(1, 2)), (row(1, 4)) - ) - as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from - ( - values - (row(cast('10' as bit varying))), - (row(cast('11' as bit varying))) - ) - as _ (x) + (values (row(cast('10' as varbit))), (row(cast('11' as varbit)))) as _ (x) union select x from - ( - values - (row(cast('10' as bit varying))), - (row(cast('01' as bit varying))) - ) - as _ (x); + (values (row(cast('10' as varbit))), (row(cast('01' as varbit)))) as _ (x); select x from - ( - values - (row(cast('10' as bit varying))), - (row(cast('11' as bit varying))) - ) - as _ (x) + (values (row(cast('10' as varbit))), (row(cast('11' as varbit)))) as _ (x) union select x from - ( - values - (row(cast('10' as bit varying))), - (row(cast('01' as bit varying))) - ) - as _ (x); + (values (row(cast('10' as varbit))), (row(cast('01' as varbit)))) as _ (x); -create type ct1 as (f1 bit varying); +create type ct1 as (f1 varbit); select x from ( values - ( - cast(row(cast('10' as bit varying)) - as ct1) - ), - ( - cast(row(cast('11' as bit varying)) - as ct1) - ) + (cast(row(cast('10' as varbit)) as ct1)), + (cast(row(cast('11' as varbit)) as ct1)) ) as _ (x) union @@ -585,14 +309,8 @@ select from ( values - ( - cast(row(cast('10' as bit varying)) - as ct1) - ), - ( - cast(row(cast('01' as bit varying)) - as ct1) - ) + (cast(row(cast('10' as varbit)) as ct1)), + (cast(row(cast('01' as varbit)) as ct1)) ) as _ (x); @@ -601,14 +319,8 @@ select from ( values - ( - cast(row(cast('10' as bit varying)) - as ct1) - ), - ( - cast(row(cast('11' as bit varying)) - as ct1) - ) + (cast(row(cast('10' as varbit)) as ct1)), + (cast(row(cast('11' as varbit)) as ct1)) ) as _ (x) union @@ -617,14 +329,8 @@ select from ( values - ( - cast(row(cast('10' as bit varying)) - as ct1) - ), - ( - cast(row(cast('01' as bit varying)) - as ct1) - ) + (cast(row(cast('10' as varbit)) as ct1)), + (cast(row(cast('01' as varbit)) as ct1)) ) as _ (x); @@ -632,73 +338,25 @@ drop type ct1; set enable_hashagg = off; -select - x -from - ( - values (row(1, 2)), (row(1, 3)) - ) - as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) union -select - x -from - ( - values (row(1, 2)), (row(1, 4)) - ) - as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - ( - values (row(1, 2)), (row(1, 3)) - ) - as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) union -select - x -from - ( - values (row(1, 2)), (row(1, 4)) - ) - as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - ( - values (row(1, 2)), (row(1, 3)) - ) - as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) except -select - x -from - ( - values (row(1, 2)), (row(1, 4)) - ) - as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); -select - x -from - ( - values (row(1, 2)), (row(1, 3)) - ) - as _ (x) +select x from (values (row(1, 2)), (row(1, 3))) as _ (x) except -select - x -from - ( - values (row(1, 2)), (row(1, 4)) - ) - as _ (x); +select x from (values (row(1, 2)), (row(1, 4))) as _ (x); select cast('123' as xid) union select cast('123' as xid); @@ -712,35 +370,23 @@ select q2 from int8_tbl union all select q2 from int8_tbl order by 1; select q1 from int8_tbl intersect -(select q2 from int8_tbl -union all -select q2 from int8_tbl) +(select q2 from int8_tbl union all select q2 from int8_tbl) order by 1; -(select q1 from int8_tbl -intersect -select q2 from int8_tbl -order by 1) +(select q1 from int8_tbl intersect select q2 from int8_tbl order by 1) union all select q2 from int8_tbl; -select q1 from int8_tbl -union all -select q2 from int8_tbl +select q1 from int8_tbl union all select q2 from int8_tbl except select q1 from int8_tbl order by 1; select q1 from int8_tbl union all -(select q2 from int8_tbl -except -select q1 from int8_tbl -order by 1); +(select q2 from int8_tbl except select q1 from int8_tbl order by 1); -select q1 from int8_tbl -union all -select q2 from int8_tbl +select q1 from int8_tbl union all select q2 from int8_tbl except select q1 from int8_tbl order by 1; @@ -751,12 +397,7 @@ select q1 from int8_tbl except select q2 from int8_tbl order by q2 limit 1; select q1 from int8_tbl except -(select - q2 -from - int8_tbl -order by q2 -limit 1) +(select q2 from int8_tbl order by q2 limit 1) order by 1; select * from int8_tbl; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__updatable_views_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__updatable_views_100.snap index 0b3c48dbd..9fbdd8d70 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__updatable_views_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__updatable_views_100.snap @@ -18,18 +18,16 @@ create view ro_view2 as select a, b from base_tbl group by a, b; create view ro_view3 -as select 1 from base_tbl having MAX(a) > 0; +as select 1 from base_tbl having max(a) > 0; create view ro_view4 -as select COUNT(*) from base_tbl; +as select count(*) from base_tbl; create view ro_view5 -as select a, RANK() over () from base_tbl; +as select a, rank() over () from base_tbl; create view ro_view6 -as select a, b from base_tbl -union -select -a, b from base_tbl; +as select a, b from base_tbl union select -a, b from base_tbl; select * from t; @@ -43,12 +41,7 @@ create view ro_view10 as select 1 as a; create view ro_view11 -as select - b1.a, - b2.b -from - base_tbl as b1, - base_tbl as b2; +as select b1.a, b2.b from base_tbl as b1, base_tbl as b2; create view ro_view12 as select * from generate_series(1, 10) as g (a); @@ -77,12 +70,7 @@ create view ro_view19 as select * from uv_seq; create view ro_view20 -as select - a, - b, - generate_series(1, a) as g -from - base_tbl; +as select a, b, generate_series(1, a) as g from base_tbl; select table_name, @@ -268,14 +256,7 @@ create table base_tbl ( insert into base_tbl select i, 'Row ' || i from generate_series(-2, 2) as g (i); create view rw_view1 -as select - *, - 'Const' as c, - (select concat('b: ', b)) as d -from - base_tbl -where - a > 0; +as select *, 'Const' as c, (select concat('b: ', b)) as d from base_tbl where a > 0; select table_name, is_insertable_into from information_schema.tables where table_name = 'rw_view1'; @@ -321,7 +302,7 @@ update rw_view1 set a = 6 where a = 5; delete from rw_view1 where a = 5; create table base_tbl_hist ( - ts timestamp with time zone default NOW(), + ts timestamptz default now(), a int, b text ); @@ -329,8 +310,7 @@ create table base_tbl_hist ( create rule base_tbl_log as on insert to rw_view1 do - insert into base_tbl_hist (a, b) - values (new.a, new.b);; + insert into base_tbl_hist (a, b) values (new.a, new.b);; select table_name, @@ -357,25 +337,10 @@ create table base_tbl ( insert into base_tbl select i, 'Row ' || i from generate_series(-2, 2) as g (i); create view rw_view1 -as select - b as bb, - a as aa, - 'Const1' as c -from - base_tbl -where - a > 0; +as select b as bb, a as aa, 'Const1' as c from base_tbl where a > 0; create view rw_view2 -as select - aa as aaa, - bb as bbb, - c as c1, - 'Const2' as c2 -from - rw_view1 -where - aa < 10; +as select aa as aaa, bb as bbb, c as c1, 'Const2' as c2 from rw_view1 where aa < 10; select table_name, is_insertable_into from information_schema.tables where table_name = 'rw_view2'; @@ -466,9 +431,7 @@ order by table_name, create rule rw_view1_ins_rule as on insert to rw_view1 do instead - insert into base_tbl - values (new.a, new.b) - returning *;; + insert into base_tbl values (new.a, new.b) returning *;; select table_name, @@ -503,11 +466,7 @@ order by table_name, create rule rw_view1_upd_rule as on update to rw_view1 do instead - update base_tbl - set b = new.b - where - a = old.a - returning new.*;; + update base_tbl set b = new.b where a = old.a returning new.*;; select table_name, @@ -542,10 +501,7 @@ order by table_name, create rule rw_view1_del_rule as on delete to rw_view1 do instead - delete from base_tbl - where - a = old.a - returning old.*;; + delete from base_tbl where a = old.a returning old.*;; select table_name, @@ -586,11 +542,7 @@ drop rule rw_view1_upd_rule on rw_view1; create rule rw_view1_upd_rule as on update to rw_view1 do instead - update base_tbl - set b = new.b - where - a = old.a - returning *;; + update base_tbl set b = new.b where a = old.a returning *;; update rw_view2 set b = 'Row three' where a = 3 returning old.*, new.*; @@ -614,23 +566,10 @@ create table base_tbl ( insert into base_tbl select i, 'Row ' || i from generate_series(-2, 2) as g (i); create view rw_view1 -as select - *, - 'Const1' as c1 -from - base_tbl -where - a > 0 -offset 0; +as select *, 'Const1' as c1 from base_tbl where a > 0 offset 0; create view rw_view2 -as select - *, - 'Const2' as c2 -from - rw_view1 -where - a < 10; +as select *, 'Const2' as c2 from rw_view1 where a < 10; select table_name, @@ -668,7 +607,7 @@ order by table_name, create function rw_view1_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF TG_OP = 'INSERT' THEN INSERT INTO base_tbl VALUES (NEW.a, NEW.b); @@ -683,7 +622,7 @@ BEGIN RETURN OLD; END IF; END; -$function$; +$$; create trigger rw_view1_ins_trig instead of insert @@ -849,9 +788,7 @@ as select b as bb, a as aa from base_tbl; create function rw_view1_aa(x rw_view1) returns int language sql -as $function$ -SELECT x.aa -$function$; +as $$ SELECT x.aa $$; update rw_view1 as v set bb = 'Updated row 2' @@ -892,13 +829,13 @@ as select b as bb, c as cc, a as aa from base_tbl; insert into rw_view1 values ('Row 2', 2.0, 2); -grant SELECT on table base_tbl to regress_view_user2; +grant select on table base_tbl to regress_view_user2; -grant SELECT on table rw_view1 to regress_view_user2; +grant select on table rw_view1 to regress_view_user2; -grant UPDATE (a, c) on table base_tbl to regress_view_user2; +grant update (a, c) on table base_tbl to regress_view_user2; -grant UPDATE (bb, cc) on table rw_view1 to regress_view_user2; +grant update (bb, cc) on table rw_view1 to regress_view_user2; reset session_authorization; @@ -941,7 +878,7 @@ reset session_authorization; set session authorization regress_view_user1; -grant INSERT, DELETE on table base_tbl to regress_view_user2; +grant insert, delete on table base_tbl to regress_view_user2; reset session_authorization; @@ -965,9 +902,9 @@ reset session_authorization; set session authorization regress_view_user1; -revoke INSERT, DELETE on table base_tbl from regress_view_user2; +revoke insert, delete on table base_tbl from regress_view_user2; -grant INSERT, DELETE on table rw_view1 to regress_view_user2; +grant insert, delete on table rw_view1 to regress_view_user2; reset session_authorization; @@ -1023,7 +960,7 @@ update rw_view2 set b = 'bar' where a = 1; reset session_authorization; -grant SELECT on table base_tbl to regress_view_user1; +grant select on table base_tbl to regress_view_user1; set session authorization regress_view_user1; @@ -1043,7 +980,7 @@ update rw_view2 set b = 'bar' where a = 1; set session authorization regress_view_user1; -grant SELECT on table rw_view1 to regress_view_user2; +grant select on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1055,7 +992,7 @@ update rw_view2 set b = 'bar' where a = 1; reset session_authorization; -grant UPDATE on table base_tbl to regress_view_user1; +grant update on table base_tbl to regress_view_user1; set session authorization regress_view_user1; @@ -1075,7 +1012,7 @@ update rw_view2 set b = 'bar' where a = 1; set session authorization regress_view_user1; -grant UPDATE on table rw_view1 to regress_view_user2; +grant update on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1087,7 +1024,7 @@ update rw_view2 set b = 'bar' where a = 1; reset session_authorization; -revoke UPDATE on table base_tbl from regress_view_user1; +revoke update on table base_tbl from regress_view_user1; set session authorization regress_view_user1; @@ -1127,9 +1064,9 @@ alter view rw_view1 insert into rw_view1 values ('Row 2', 2.0, 2); -grant SELECT on table rw_view1 to regress_view_user2; +grant select on table rw_view1 to regress_view_user2; -grant UPDATE (bb, cc) on table rw_view1 to regress_view_user2; +grant update (bb, cc) on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1151,9 +1088,9 @@ delete from rw_view1; set session authorization regress_view_user1; -grant SELECT on table base_tbl to regress_view_user2; +grant select on table base_tbl to regress_view_user2; -grant UPDATE (a, c) on table base_tbl to regress_view_user2; +grant update (a, c) on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -1173,7 +1110,7 @@ update rw_view1 set bb = bb; set session authorization regress_view_user1; -grant INSERT, DELETE on table base_tbl to regress_view_user2; +grant insert, delete on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -1187,9 +1124,9 @@ delete from rw_view1 where aa = 2; set session authorization regress_view_user1; -revoke INSERT, DELETE on table base_tbl from regress_view_user2; +revoke insert, delete on table base_tbl from regress_view_user2; -grant INSERT, DELETE on table rw_view1 to regress_view_user2; +grant insert, delete on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1199,7 +1136,7 @@ delete from rw_view1 where aa = 2; set session authorization regress_view_user1; -grant INSERT, DELETE on table base_tbl to regress_view_user2; +grant insert, delete on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -1236,14 +1173,9 @@ update rw_view1 set aa = aa; set session authorization regress_view_user2; create view rw_view2 -as select - cc as ccc, - aa as aaa, - bb as bbb -from - rw_view1; +as select cc as ccc, aa as aaa, bb as bbb from rw_view1; -grant SELECT, UPDATE on table rw_view2 to regress_view_user3; +grant select, update on table rw_view2 to regress_view_user3; select * from rw_view2; @@ -1251,9 +1183,9 @@ update rw_view2 set aaa = aaa; reset session_authorization; -grant SELECT on table base_tbl to regress_view_user1; +grant select on table base_tbl to regress_view_user1; -grant UPDATE (a, b) on table base_tbl to regress_view_user1; +grant update (a, b) on table base_tbl to regress_view_user1; set session authorization regress_view_user1; @@ -1277,9 +1209,9 @@ update rw_view2 set aaa = aaa; set session authorization regress_view_user1; -grant SELECT on table rw_view1 to regress_view_user2; +grant select on table rw_view1 to regress_view_user2; -grant UPDATE (bb, cc) on table rw_view1 to regress_view_user2; +grant update (bb, cc) on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1295,9 +1227,9 @@ update rw_view2 set bbb = bbb; reset session_authorization; -grant SELECT on table base_tbl to regress_view_user2; +grant select on table base_tbl to regress_view_user2; -grant UPDATE (a, c) on table base_tbl to regress_view_user2; +grant update (a, c) on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -1321,9 +1253,9 @@ update rw_view2 set ccc = ccc; reset session_authorization; -grant SELECT on table base_tbl to regress_view_user3; +grant select on table base_tbl to regress_view_user3; -grant UPDATE (a, c) on table base_tbl to regress_view_user3; +grant update (a, c) on table base_tbl to regress_view_user3; set session authorization regress_view_user3; @@ -1337,7 +1269,7 @@ update rw_view2 set ccc = ccc; reset session_authorization; -revoke SELECT, UPDATE on table base_tbl from regress_view_user1; +revoke select, update on table base_tbl from regress_view_user1; set session authorization regress_view_user1; @@ -1367,7 +1299,7 @@ update rw_view2 set ccc = ccc; reset session_authorization; -revoke SELECT, UPDATE on table base_tbl from regress_view_user2; +revoke select, update on table base_tbl from regress_view_user2; set session authorization regress_view_user2; @@ -1437,7 +1369,7 @@ insert into base_tbl values (2, 'Row 2'); create function rw_view1_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF TG_OP = 'INSERT' THEN UPDATE base_tbl SET b=NEW.b WHERE a=1; @@ -1445,7 +1377,7 @@ BEGIN END IF; RETURN NULL; END; -$function$; +$$; create trigger rw_view1_ins_trig after insert @@ -1513,16 +1445,7 @@ create table base_tbl (a double precision); insert into base_tbl select i / 10.0 from generate_series(1, 10) as g (i); create view rw_view1 -as select - ctid, - sin(a) as s, - a, - cos(a) as c -from - base_tbl -where - a <> 0 -order by abs(a); +as select ctid, sin(a) as s, a, cos(a) as c from base_tbl where a <> 0 order by abs(a); insert into rw_view1 values (null, null, 1.1, null); @@ -1539,14 +1462,7 @@ update rw_view1 set a = 1.05 where a = 1.1 returning s; delete from rw_view1 where a = 1.05; create view rw_view2 -as select - s, - c, - s / c as t, - a as base_a, - ctid -from - rw_view1; +as select s, c, s / c as t, a as base_a, ctid from rw_view1; insert into rw_view2 values (null, null, null, 1.1, null); @@ -1610,11 +1526,7 @@ select events & 8 <> 0 as ins, events & 16 <> 0 as del from - pg_relation_is_updatable( - cast('rw_view3' as regclass), - false - ) - as t (events); + pg_catalog.pg_relation_is_updatable(cast('rw_view3' as regclass), false) as t (events); drop table base_tbl cascade; @@ -1870,15 +1782,7 @@ create table ref_tbl (a int primary key); insert into ref_tbl select * from generate_series(1, 10); create view rw_view1 -as select - * -from - base_tbl as b -where - exists - ( - select 1 from ref_tbl as r where r.a = b.a - ) +as select * from base_tbl as b where exists (select 1 from ref_tbl as r where r.a = b.a) with cascaded check option; insert into rw_view1 values (5); @@ -1903,12 +1807,12 @@ create table base_tbl ( create function base_tbl_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.b := 10; RETURN NEW; END; -$function$; +$$; create trigger base_tbl_trig before insert or update @@ -1941,7 +1845,7 @@ as select a from base_tbl where a < b; create function rw_view1_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF TG_OP = 'INSERT' THEN INSERT INTO base_tbl VALUES (NEW.a, 10); @@ -1954,7 +1858,7 @@ BEGIN RETURN OLD; END IF; END; -$function$; +$$; create trigger rw_view1_trig instead of insert or delete or update @@ -2041,23 +1945,18 @@ create table base_tbl ( insert into base_tbl values ('Tom', 'public'), ('Dick', 'private'), ('Harry', 'public'); create view rw_view1 -as select - person -from - base_tbl -where - visibility = 'public'; +as select person from base_tbl where visibility = 'public'; create function snoop(anyelement) returns boolean language plpgsql cost 0.000001 -as $function$ +as $$ BEGIN RAISE NOTICE 'snooped value: %', $1; RETURN true; END; -$function$; +$$; create or replace function leakproof(anyelement) returns boolean @@ -2065,11 +1964,11 @@ language plpgsql immutable leakproof strict -as $function$ +as $$ BEGIN RETURN true; END; -$function$; +$$; select * from rw_view1 where snoop(person); @@ -2162,24 +2061,14 @@ insert into base_tbl values (1, 'Row 1', false), (2, 'Row 2', true); create rule base_tbl_ins_rule as on insert to base_tbl where - exists - ( - select 1 from base_tbl as t where t.id = new.id - ) + exists (select 1 from base_tbl as t where t.id = new.id) do instead - update base_tbl - set data = new.data, - deleted = false - where - id = new.id;; + update base_tbl set data = new.data, deleted = false where id = new.id;; create rule base_tbl_del_rule as on delete to base_tbl do instead - update base_tbl - set deleted = true - where - id = old.id;; + update base_tbl set deleted = true where id = old.id;; create view rw_view1 with (security_barrier = 'true') @@ -2205,7 +2094,7 @@ create table t1 ( c text ); -create index "t1_a_idx" on t1 using btree (a); +create index t1_a_idx on t1 using btree (a); insert into t1 select i, i, 't1' from generate_series(1, 10) as g (i); @@ -2214,7 +2103,7 @@ analyze t1; create table t11 (d text) inherits (t1); -create index "t11_a_idx" on t11 using btree (a); +create index t11_a_idx on t11 using btree (a); insert into t11 select i, i, 't11', 't11d' from generate_series(1, 10) as g (i); @@ -2223,27 +2112,19 @@ analyze t11; create table t12 (e int[]) inherits (t1); -create index "t12_a_idx" on t12 using btree (a); +create index t12_a_idx on t12 using btree (a); insert into t12 select i, i, 't12', cast('{1,2}' as int[]) from generate_series(1, 10) as g (i); analyze t12; create table t111 () -inherits (t11, -t12); +inherits (t11, t12); -create index "t111_a_idx" on t111 using btree (a); +create index t111_a_idx on t111 using btree (a); insert into t111 -select - i, - i, - 't111', - 't111d', - cast('{1,1,1}' as int[]) -from - generate_series(1, 10) as g (i); +select i, i, 't111', 't111d', cast('{1,1,1}' as int[]) from generate_series(1, 10) as g (i); analyze t111; @@ -2251,13 +2132,11 @@ create view v1 with (security_barrier = 'true') as select *, - (select d from t11 where t11.a = t1.a limit 1) - as d + (select d from t11 where t11.a = t1.a limit 1) as d from t1 where - a > 5 and - exists (select 1 from t12 where t12.a = t1.a); + a > 5 and exists (select 1 from t12 where t12.a = t1.a); select * from v1 where a = 3; @@ -2294,12 +2173,7 @@ create table tx2 (b int); create table tx3 (c int); create view vx1 -as select - a -from - tx1 -where - exists (select 1 from tx2 inner join tx3 on b = c); +as select a from tx1 where exists (select 1 from tx2 inner join tx3 on b = c); insert into vx1 values (1); @@ -2322,12 +2196,7 @@ create table tx2 (b int); create table tx3 (c int); create view vx1 -as select - a -from - tx1 -where - exists (select 1 from tx2 inner join tx3 on b = c); +as select a from tx1 where exists (select 1 from tx2 inner join tx3 on b = c); insert into vx1 values (1); @@ -2370,12 +2239,7 @@ alter table tx3 drop column d; create view vx1 -as select - a -from - tx1 -where - exists (select 1 from tx2 inner join tx3 on b = c); +as select a from tx1 where exists (select 1 from tx2 inner join tx3 on b = c); insert into vx1 values (1); @@ -2412,12 +2276,7 @@ with cascaded check option; create view v2 with (security_barrier = 'true') -as select - * -from - v1 -where - exists (select 1 from t2 where t2.cc = v1.c) +as select * from v1 where exists (select 1 from t2 where t2.cc = v1.c) with cascaded check option; insert into v2 values (2, 'two', 20); @@ -2531,15 +2390,11 @@ select events & 8 <> 0 as ins, events & 16 <> 0 as del from - pg_relation_is_updatable( - cast('uv_pt' as regclass), - false - ) - as t (events); + pg_catalog.pg_relation_is_updatable(cast('uv_pt' as regclass), false) as t (events); -select pg_column_is_updatable(cast('uv_pt' as regclass), cast(1 as smallint), false); +select pg_catalog.pg_column_is_updatable(cast('uv_pt' as regclass), cast(1 as smallint), false); -select pg_column_is_updatable(cast('uv_pt' as regclass), cast(2 as smallint), false); +select pg_catalog.pg_column_is_updatable(cast('uv_pt' as regclass), cast(2 as smallint), false); select table_name, @@ -2577,17 +2432,12 @@ drop view uv_ptv, uv_ptv_wco; drop table uv_pt, uv_pt1, uv_pt11; create table wcowrtest (a int) -partition by LIST(a); +partition by list(a); create table wcowrtest1 partition of wcowrtest for values in (1); create view wcowrtest_v -as select - * -from - wcowrtest -where - wcowrtest = cast('(2)' as wcowrtest) +as select * from wcowrtest where wcowrtest = cast('(2)' as wcowrtest) with cascaded check option; insert into wcowrtest_v values (1); @@ -2616,15 +2466,7 @@ create table sometable ( insert into sometable values (1, 'a'), (2, 'b'); create view wcowrtest_v2 -as select - * -from - wcowrtest as r -where - r in - ( - select s from sometable as s where r.a = s.a - ) +as select * from wcowrtest as r where r in (select s from sometable as s where r.a = s.a) with cascaded check option; insert into wcowrtest_v2 values (2, 'no such row in sometable'); @@ -2641,13 +2483,7 @@ create table uv_iocu_tab ( insert into uv_iocu_tab values ('xyxyxy', 0); create view uv_iocu_view -as select - b, - b + 1 as c, - a, - cast('2.0' as text) as two -from - uv_iocu_tab; +as select b, b + 1 as c, a, cast('2.0' as text) as two from uv_iocu_tab; insert into uv_iocu_view (a, b) values ('xyxyxy', 1) @@ -2661,33 +2497,17 @@ select * from uv_iocu_tab; insert into uv_iocu_view (a, b) values ('xyxyxy', 3) -on conflict -(a) -do -update -set b = cast(excluded.two as double precision); +on conflict (a) do update set b = cast(excluded.two as double precision); select * from uv_iocu_tab; insert into uv_iocu_view (a, b) values ('xyxyxy', 3) -on conflict -(a) -do -update -set b = excluded.b -where - excluded.c > 0; +on conflict (a) do update set b = excluded.b where excluded.c > 0; insert into uv_iocu_view (a, b) values ('xyxyxy', 3) -on conflict -(a) -do -update -set b = excluded.b -where - excluded.c > 0; +on conflict (a) do update set b = excluded.b where excluded.c > 0; select * from uv_iocu_tab; @@ -2701,12 +2521,7 @@ create table uv_iocu_tab ( ); create view uv_iocu_view -as select - b as bb, - a as aa, - cast(uv_iocu_tab as text) as cc -from - uv_iocu_tab; +as select b as bb, a as aa, cast(uv_iocu_tab as text) as cc from uv_iocu_tab; insert into uv_iocu_view (aa, bb) values (1, 'x'); @@ -2718,9 +2533,7 @@ do update set bb = 'Rejected: ' || excluded.* where - excluded.aa > 0 and - excluded.bb <> '' and - excluded.cc is not null; + excluded.aa > 0 and excluded.bb <> '' and excluded.cc is not null; insert into uv_iocu_view (aa, bb) values (1, 'y') @@ -2730,9 +2543,7 @@ do update set bb = 'Rejected: ' || excluded.* where - excluded.aa > 0 and - excluded.bb <> '' and - excluded.cc is not null; + excluded.aa > 0 and excluded.bb <> '' and excluded.cc is not null; select * from uv_iocu_view; @@ -2742,11 +2553,7 @@ insert into uv_iocu_view (aa, bb) values (1, 'x'); insert into uv_iocu_view (aa) values (1) -on conflict -(aa) -do -update -set bb = 'Rejected: ' || excluded.*; +on conflict (aa) do update set bb = 'Rejected: ' || excluded.*; select * from uv_iocu_view; @@ -2755,11 +2562,7 @@ alter table uv_iocu_tab insert into uv_iocu_view (aa) values (1) -on conflict -(aa) -do -update -set bb = 'Rejected: ' || excluded.*; +on conflict (aa) do update set bb = 'Rejected: ' || excluded.*; select * from uv_iocu_view; @@ -2768,11 +2571,7 @@ alter view uv_iocu_view insert into uv_iocu_view (aa) values (1) -on conflict -(aa) -do -update -set bb = 'Rejected: ' || excluded.*; +on conflict (aa) do update set bb = 'Rejected: ' || excluded.*; select * from uv_iocu_view; @@ -2799,11 +2598,11 @@ insert into base_tbl values (1, 'xxx', 1.0); create view rw_view1 as select b as bb, c as cc, a as aa from base_tbl; -grant SELECT (aa, bb) on table rw_view1 to regress_view_user2; +grant select (aa, bb) on table rw_view1 to regress_view_user2; -grant INSERT on table rw_view1 to regress_view_user2; +grant insert on table rw_view1 to regress_view_user2; -grant UPDATE (bb) on table rw_view1 to regress_view_user2; +grant update (bb) on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -2815,11 +2614,7 @@ insert into rw_view1 values ('yyy', 2.0, 1) on conflict (aa) do update set bb = insert into rw_view1 values ('zzz', 2.0, 1) -on conflict -(aa) -do -update -set bb = rw_view1.bb || 'xxx'; +on conflict (aa) do update set bb = rw_view1.bb || 'xxx'; insert into rw_view1 values ('zzz', 2.0, 1) on conflict (aa) do update set cc = 3.0; @@ -2829,11 +2624,11 @@ select * from base_tbl; set session authorization regress_view_user1; -grant SELECT (a, b) on table base_tbl to regress_view_user2; +grant select (a, b) on table base_tbl to regress_view_user2; -grant INSERT (a, b) on table base_tbl to regress_view_user2; +grant insert (a, b) on table base_tbl to regress_view_user2; -grant UPDATE (a, b) on table base_tbl to regress_view_user2; +grant update (a, b) on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -2907,9 +2702,7 @@ insert into base_tab_def values (2), (3); insert into base_tab_def values (4, default, default, default, default); insert into base_tab_def -values - (5, default, default, default, default), - (6, default, default, default, default); +values (5, default, default, default, default), (6, default, default, default, default); insert into base_tab_def_view values (11); @@ -2918,9 +2711,7 @@ insert into base_tab_def_view values (12), (13); insert into base_tab_def_view values (14, default, default, default, default); insert into base_tab_def_view -values - (15, default, default, default, default), - (16, default, default, default, default); +values (15, default, default, default, default), (16, default, default, default, default); insert into base_tab_def_view values (17), (default); @@ -2929,12 +2720,12 @@ select * from base_tab_def order by a; create function base_tab_def_view_instrig_func() returns trigger language plpgsql -as $function$ +as $$ begin insert into base_tab_def values (new.a, new.b, new.c, new.d, new.e); return new; end; -$function$; +$$; create trigger base_tab_def_view_instrig instead of insert @@ -2951,9 +2742,7 @@ insert into base_tab_def values (2), (3); insert into base_tab_def values (4, default, default, default, default); insert into base_tab_def -values - (5, default, default, default, default), - (6, default, default, default, default); +values (5, default, default, default, default), (6, default, default, default, default); insert into base_tab_def_view values (11); @@ -2962,9 +2751,7 @@ insert into base_tab_def_view values (12), (13); insert into base_tab_def_view values (14, default, default, default, default); insert into base_tab_def_view -values - (15, default, default, default, default), - (16, default, default, default, default); +values (15, default, default, default, default), (16, default, default, default, default); insert into base_tab_def_view values (17), (default); @@ -2977,8 +2764,7 @@ drop function base_tab_def_view_instrig_func; create rule base_tab_def_view_ins_rule as on insert to base_tab_def_view do instead - insert into base_tab_def - values (new.a, new.b, new.c, new.d, new.e);; + insert into base_tab_def values (new.a, new.b, new.c, new.d, new.e);; truncate base_tab_def; @@ -2989,9 +2775,7 @@ insert into base_tab_def values (2), (3); insert into base_tab_def values (4, default, default, default, default); insert into base_tab_def -values - (5, default, default, default, default), - (6, default, default, default, default); +values (5, default, default, default, default), (6, default, default, default, default); insert into base_tab_def_view values (11); @@ -3000,9 +2784,7 @@ insert into base_tab_def_view values (12), (13); insert into base_tab_def_view values (14, default, default, default, default); insert into base_tab_def_view -values - (15, default, default, default, default), - (16, default, default, default, default); +values (15, default, default, default, default), (16, default, default, default, default); insert into base_tab_def_view values (17), (default); @@ -3013,8 +2795,7 @@ drop rule base_tab_def_view_ins_rule on base_tab_def_view; create rule base_tab_def_view_ins_rule as on insert to base_tab_def_view do - insert into base_tab_def - values (new.a, new.b, new.c, new.d, new.e);; + insert into base_tab_def values (new.a, new.b, new.c, new.d, new.e);; truncate base_tab_def; @@ -3025,9 +2806,7 @@ insert into base_tab_def values (2), (3); insert into base_tab_def values (4, default, default, default, default); insert into base_tab_def -values - (5, default, default, default, default), - (6, default, default, default, default); +values (5, default, default, default, default), (6, default, default, default, default); insert into base_tab_def_view values (11); @@ -3036,9 +2815,7 @@ insert into base_tab_def_view values (12), (13); insert into base_tab_def_view values (14, default, default, default, default); insert into base_tab_def_view -values - (15, default, default, default, default), - (16, default, default, default, default); +values (15, default, default, default, default), (16, default, default, default, default); insert into base_tab_def_view values (17), (default); @@ -3053,9 +2830,7 @@ truncate base_tab_def; insert into base_tab_def_view values (1, default, default, default, default); insert into base_tab_def_view -values - (2, default, default, default, default), - (3, default, default, default, default); +values (2, default, default, default, default), (3, default, default, default, default); select * from base_tab_def order by a, e nulls first; @@ -3077,9 +2852,7 @@ alter view base_tab_view alter column c set default 'View default'; insert into base_tab_view (b[1], b[2], c, b[5], b[4], a, b[3]) -values - (1, 2, default, 5, 4, default, 3), - (10, 11, 'C value', 14, 13, 100, 12); +values (1, 2, default, 5, 4, default, 3), (10, 11, 'C value', 14, 13, 100, 12); select * from base_tab order by a; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__updatable_views_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__updatable_views_80.snap index 51aaedcc0..11099aa46 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__updatable_views_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__updatable_views_80.snap @@ -18,62 +18,36 @@ create view ro_view2 as select a, b from base_tbl group by a, b; create view ro_view3 -as select 1 from base_tbl having MAX(a) > 0; +as select 1 from base_tbl having max(a) > 0; create view ro_view4 -as select COUNT(*) from base_tbl; +as select count(*) from base_tbl; create view ro_view5 -as select a, RANK() over () from base_tbl; +as select a, rank() over () from base_tbl; create view ro_view6 -as select a, b from base_tbl -union -select -a, b from base_tbl; +as select a, b from base_tbl union select -a, b from base_tbl; select * from t; create view ro_view8 -as select - a, - b -from - base_tbl -order by a -offset 1; +as select a, b from base_tbl order by a offset 1; create view ro_view9 -as select - a, - b -from - base_tbl -order by a -limit 1; +as select a, b from base_tbl order by a limit 1; create view ro_view10 as select 1 as a; create view ro_view11 -as select - b1.a, - b2.b -from - base_tbl as b1, - base_tbl as b2; +as select b1.a, b2.b from base_tbl as b1, base_tbl as b2; create view ro_view12 -as select - * -from - generate_series(1, 10) as g (a); +as select * from generate_series(1, 10) as g (a); create view ro_view13 -as select - a, - b -from - (select * from base_tbl) as t; +as select a, b from (select * from base_tbl) as t; create view rw_view14 as select ctid, a, b from base_tbl; @@ -96,12 +70,7 @@ create view ro_view19 as select * from uv_seq; create view ro_view20 -as select - a, - b, - generate_series(1, a) as g -from - base_tbl; +as select a, b, generate_series(1, a) as g from base_tbl; select table_name, @@ -163,15 +132,13 @@ merge into ro_view13 as t using (values (2, 'Row 2')) as v (a, b) on t.a = v.a when matched then do nothing -when not matched by target -then do nothing; +when not matched by target then do nothing; merge into ro_view13 as t using (values (3, 'Row 3')) as v (a, b) on t.a = v.a when matched then do nothing -when not matched by target -then do nothing; +when not matched by target then do nothing; insert into rw_view14 values (null, 3, 'Row 3'); @@ -203,21 +170,13 @@ select * from rw_view15; insert into rw_view15 (a) values (3) -on conflict -(a) -do -update -set a = excluded.a; +on conflict (a) do update set a = excluded.a; select * from rw_view15; insert into rw_view15 (a) values (3) -on conflict -(a) -do -update -set upper = 'blarg'; +on conflict (a) do update set upper = 'blarg'; select * from rw_view15; @@ -267,17 +226,13 @@ create rule rw_view16_ins_rule as on insert to rw_view16 where new.a > 0 do instead - insert into base_tbl - values (new.a, new.b);; + insert into base_tbl values (new.a, new.b);; create rule rw_view16_upd_rule as on update to rw_view16 where old.a > 0 do instead - update base_tbl - set b = new.b - where - a = old.a;; + update base_tbl set b = new.b where a = old.a;; create rule rw_view16_del_rule as on delete to rw_view16 where @@ -364,8 +319,7 @@ update rw_view1 set a = 6 where a = 5; delete from rw_view1 where a = 5; create table base_tbl_hist ( - ts timestamp with time zone - default NOW(), + ts timestamptz default now(), a int, b text ); @@ -373,8 +327,7 @@ create table base_tbl_hist ( create rule base_tbl_log as on insert to rw_view1 do - insert into base_tbl_hist (a, b) - values (new.a, new.b);; + insert into base_tbl_hist (a, b) values (new.a, new.b);; select table_name, @@ -401,14 +354,7 @@ create table base_tbl ( insert into base_tbl select i, 'Row ' || i from generate_series(-2, 2) as g (i); create view rw_view1 -as select - b as bb, - a as aa, - 'Const1' as c -from - base_tbl -where - a > 0; +as select b as bb, a as aa, 'Const1' as c from base_tbl where a > 0; create view rw_view2 as select @@ -478,13 +424,7 @@ create table base_tbl ( insert into base_tbl select i, 'Row ' || i from generate_series(-2, 2) as g (i); create view rw_view1 -as select - * -from - base_tbl -where - a > 0 -offset 0; +as select * from base_tbl where a > 0 offset 0; create view rw_view2 as select * from rw_view1 where a < 10; @@ -522,9 +462,7 @@ order by table_name, create rule rw_view1_ins_rule as on insert to rw_view1 do instead - insert into base_tbl - values (new.a, new.b) - returning *;; + insert into base_tbl values (new.a, new.b) returning *;; select table_name, @@ -559,11 +497,7 @@ order by table_name, create rule rw_view1_upd_rule as on update to rw_view1 do instead - update base_tbl - set b = new.b - where - a = old.a - returning new.*;; + update base_tbl set b = new.b where a = old.a returning new.*;; select table_name, @@ -598,10 +532,7 @@ order by table_name, create rule rw_view1_del_rule as on delete to rw_view1 do instead - delete from base_tbl - where - a = old.a - returning old.*;; + delete from base_tbl where a = old.a returning old.*;; select table_name, @@ -642,11 +573,7 @@ drop rule rw_view1_upd_rule on rw_view1; create rule rw_view1_upd_rule as on update to rw_view1 do instead - update base_tbl - set b = new.b - where - a = old.a - returning *;; + update base_tbl set b = new.b where a = old.a returning *;; update rw_view2 set b = 'Row three' where a = 3 returning old.*, new.*; @@ -670,23 +597,10 @@ create table base_tbl ( insert into base_tbl select i, 'Row ' || i from generate_series(-2, 2) as g (i); create view rw_view1 -as select - *, - 'Const1' as c1 -from - base_tbl -where - a > 0 -offset 0; +as select *, 'Const1' as c1 from base_tbl where a > 0 offset 0; create view rw_view2 -as select - *, - 'Const2' as c2 -from - rw_view1 -where - a < 10; +as select *, 'Const2' as c2 from rw_view1 where a < 10; select table_name, @@ -724,7 +638,7 @@ order by table_name, create function rw_view1_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF TG_OP = 'INSERT' THEN INSERT INTO base_tbl VALUES (NEW.a, NEW.b); @@ -739,7 +653,7 @@ BEGIN RETURN OLD; END IF; END; -$function$; +$$; create trigger rw_view1_ins_trig instead of insert @@ -905,9 +819,7 @@ as select b as bb, a as aa from base_tbl; create function rw_view1_aa(x rw_view1) returns int language sql -as $function$ -SELECT x.aa -$function$; +as $$ SELECT x.aa $$; update rw_view1 as v set bb = 'Updated row 2' @@ -944,34 +856,24 @@ create table base_tbl ( insert into base_tbl values (1, 'Row 1', 1.0); create view rw_view1 -as select - b as bb, - c as cc, - a as aa -from - base_tbl; +as select b as bb, c as cc, a as aa from base_tbl; insert into rw_view1 values ('Row 2', 2.0, 2); -grant SELECT on table base_tbl to regress_view_user2; +grant select on table base_tbl to regress_view_user2; -grant SELECT on table rw_view1 to regress_view_user2; +grant select on table rw_view1 to regress_view_user2; -grant UPDATE (a, c) on table base_tbl to regress_view_user2; +grant update (a, c) on table base_tbl to regress_view_user2; -grant UPDATE (bb, cc) on table rw_view1 to regress_view_user2; +grant update (bb, cc) on table rw_view1 to regress_view_user2; reset session_authorization; set session authorization regress_view_user2; create view rw_view2 -as select - b as bb, - c as cc, - a as aa -from - base_tbl; +as select b as bb, c as cc, a as aa from base_tbl; select * from base_tbl; @@ -1007,7 +909,7 @@ reset session_authorization; set session authorization regress_view_user1; -grant INSERT, DELETE on table base_tbl to regress_view_user2; +grant insert, delete on table base_tbl to regress_view_user2; reset session_authorization; @@ -1031,9 +933,9 @@ reset session_authorization; set session authorization regress_view_user1; -revoke INSERT, DELETE on table base_tbl from regress_view_user2; +revoke insert, delete on table base_tbl from regress_view_user2; -grant INSERT, DELETE on table rw_view1 to regress_view_user2; +grant insert, delete on table rw_view1 to regress_view_user2; reset session_authorization; @@ -1089,7 +991,7 @@ update rw_view2 set b = 'bar' where a = 1; reset session_authorization; -grant SELECT on table base_tbl to regress_view_user1; +grant select on table base_tbl to regress_view_user1; set session authorization regress_view_user1; @@ -1109,7 +1011,7 @@ update rw_view2 set b = 'bar' where a = 1; set session authorization regress_view_user1; -grant SELECT on table rw_view1 to regress_view_user2; +grant select on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1121,7 +1023,7 @@ update rw_view2 set b = 'bar' where a = 1; reset session_authorization; -grant UPDATE on table base_tbl to regress_view_user1; +grant update on table base_tbl to regress_view_user1; set session authorization regress_view_user1; @@ -1141,7 +1043,7 @@ update rw_view2 set b = 'bar' where a = 1; set session authorization regress_view_user1; -grant UPDATE on table rw_view1 to regress_view_user2; +grant update on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1153,7 +1055,7 @@ update rw_view2 set b = 'bar' where a = 1; reset session_authorization; -revoke UPDATE on table base_tbl from regress_view_user1; +revoke update on table base_tbl from regress_view_user1; set session authorization regress_view_user1; @@ -1186,21 +1088,16 @@ create table base_tbl ( insert into base_tbl values (1, 'Row 1', 1.0); create view rw_view1 -as select - b as bb, - c as cc, - a as aa -from - base_tbl; +as select b as bb, c as cc, a as aa from base_tbl; alter view rw_view1 set (security_invoker = 'true'); insert into rw_view1 values ('Row 2', 2.0, 2); -grant SELECT on table rw_view1 to regress_view_user2; +grant select on table rw_view1 to regress_view_user2; -grant UPDATE (bb, cc) on table rw_view1 to regress_view_user2; +grant update (bb, cc) on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1222,9 +1119,9 @@ delete from rw_view1; set session authorization regress_view_user1; -grant SELECT on table base_tbl to regress_view_user2; +grant select on table base_tbl to regress_view_user2; -grant UPDATE (a, c) on table base_tbl to regress_view_user2; +grant update (a, c) on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -1244,7 +1141,7 @@ update rw_view1 set bb = bb; set session authorization regress_view_user1; -grant INSERT, DELETE on table base_tbl to regress_view_user2; +grant insert, delete on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -1258,9 +1155,9 @@ delete from rw_view1 where aa = 2; set session authorization regress_view_user1; -revoke INSERT, DELETE on table base_tbl from regress_view_user2; +revoke insert, delete on table base_tbl from regress_view_user2; -grant INSERT, DELETE on table rw_view1 to regress_view_user2; +grant insert, delete on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1270,7 +1167,7 @@ delete from rw_view1 where aa = 2; set session authorization regress_view_user1; -grant INSERT, DELETE on table base_tbl to regress_view_user2; +grant insert, delete on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -1295,12 +1192,7 @@ insert into base_tbl values (1, 'Row 1', 1.0); set session authorization regress_view_user1; create view rw_view1 -as select - b as bb, - c as cc, - a as aa -from - base_tbl; +as select b as bb, c as cc, a as aa from base_tbl; alter view rw_view1 set (security_invoker = 'true'); @@ -1312,14 +1204,9 @@ update rw_view1 set aa = aa; set session authorization regress_view_user2; create view rw_view2 -as select - cc as ccc, - aa as aaa, - bb as bbb -from - rw_view1; +as select cc as ccc, aa as aaa, bb as bbb from rw_view1; -grant SELECT, UPDATE on table rw_view2 to regress_view_user3; +grant select, update on table rw_view2 to regress_view_user3; select * from rw_view2; @@ -1327,9 +1214,9 @@ update rw_view2 set aaa = aaa; reset session_authorization; -grant SELECT on table base_tbl to regress_view_user1; +grant select on table base_tbl to regress_view_user1; -grant UPDATE (a, b) on table base_tbl to regress_view_user1; +grant update (a, b) on table base_tbl to regress_view_user1; set session authorization regress_view_user1; @@ -1353,9 +1240,9 @@ update rw_view2 set aaa = aaa; set session authorization regress_view_user1; -grant SELECT on table rw_view1 to regress_view_user2; +grant select on table rw_view1 to regress_view_user2; -grant UPDATE (bb, cc) on table rw_view1 to regress_view_user2; +grant update (bb, cc) on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; @@ -1371,9 +1258,9 @@ update rw_view2 set bbb = bbb; reset session_authorization; -grant SELECT on table base_tbl to regress_view_user2; +grant select on table base_tbl to regress_view_user2; -grant UPDATE (a, c) on table base_tbl to regress_view_user2; +grant update (a, c) on table base_tbl to regress_view_user2; set session authorization regress_view_user2; @@ -1397,9 +1284,9 @@ update rw_view2 set ccc = ccc; reset session_authorization; -grant SELECT on table base_tbl to regress_view_user3; +grant select on table base_tbl to regress_view_user3; -grant UPDATE (a, c) on table base_tbl to regress_view_user3; +grant update (a, c) on table base_tbl to regress_view_user3; set session authorization regress_view_user3; @@ -1413,7 +1300,7 @@ update rw_view2 set ccc = ccc; reset session_authorization; -revoke SELECT, UPDATE on table base_tbl from regress_view_user1; +revoke select, update on table base_tbl from regress_view_user1; set session authorization regress_view_user1; @@ -1443,7 +1330,7 @@ update rw_view2 set ccc = ccc; reset session_authorization; -revoke SELECT, UPDATE on table base_tbl from regress_view_user2; +revoke select, update on table base_tbl from regress_view_user2; set session authorization regress_view_user2; @@ -1513,7 +1400,7 @@ insert into base_tbl values (2, 'Row 2'); create function rw_view1_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF TG_OP = 'INSERT' THEN UPDATE base_tbl SET b=NEW.b WHERE a=1; @@ -1521,7 +1408,7 @@ BEGIN END IF; RETURN NULL; END; -$function$; +$$; create trigger rw_view1_ins_trig after insert @@ -1615,14 +1502,7 @@ update rw_view1 set a = 1.05 where a = 1.1 returning s; delete from rw_view1 where a = 1.05; create view rw_view2 -as select - s, - c, - s / c as t, - a as base_a, - ctid -from - rw_view1; +as select s, c, s / c as t, a as base_a, ctid from rw_view1; insert into rw_view2 values (null, null, null, 1.1, null); @@ -1639,13 +1519,7 @@ update rw_view2 set base_a = 1.05 where base_a = 1.1; delete from rw_view2 where base_a = 1.05 returning base_a, s, c, t; create view rw_view3 -as select - s, - c, - s / c as t, - ctid -from - rw_view1; +as select s, c, s / c as t, ctid from rw_view1; insert into rw_view3 values (null, null, null, null); @@ -1692,18 +1566,14 @@ select events & 8 <> 0 as ins, events & 16 <> 0 as del from - pg_relation_is_updatable( - cast('rw_view3' as regclass), - false - ) + pg_catalog.pg_relation_is_updatable(cast('rw_view3' as regclass), false) as t (events); drop table base_tbl cascade; create table base_tbl ( id int, - idplus1 int - generated always as (id + 1) stored + idplus1 int generated always as (id + 1) stored ); create view rw_view1 @@ -1964,15 +1834,7 @@ as select from base_tbl as b where - exists - ( - select - 1 - from - ref_tbl as r - where - r.a = b.a - ) + exists (select 1 from ref_tbl as r where r.a = b.a) with cascaded check option; insert into rw_view1 values (5); @@ -1997,12 +1859,12 @@ create table base_tbl ( create function base_tbl_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.b := 10; RETURN NEW; END; -$function$; +$$; create trigger base_tbl_trig before insert or update @@ -2035,7 +1897,7 @@ as select a from base_tbl where a < b; create function rw_view1_trig_fn() returns trigger language plpgsql -as $function$ +as $$ BEGIN IF TG_OP = 'INSERT' THEN INSERT INTO base_tbl VALUES (NEW.a, 10); @@ -2048,7 +1910,7 @@ BEGIN RETURN OLD; END IF; END; -$function$; +$$; create trigger rw_view1_trig instead of insert or delete or update @@ -2089,10 +1951,7 @@ do instead create rule rw_view1_upd_rule as on update to rw_view1 do instead - update base_tbl - set a = new.a - where - a = old.a;; + update base_tbl set a = new.a where a = old.a;; insert into rw_view2 values (-10); @@ -2136,29 +1995,21 @@ create table base_tbl ( ); insert into base_tbl -values - ('Tom', 'public'), - ('Dick', 'private'), - ('Harry', 'public'); +values ('Tom', 'public'), ('Dick', 'private'), ('Harry', 'public'); create view rw_view1 -as select - person -from - base_tbl -where - visibility = 'public'; +as select person from base_tbl where visibility = 'public'; create function snoop(anyelement) returns boolean language plpgsql cost 0.000001 -as $function$ +as $$ BEGIN RAISE NOTICE 'snooped value: %', $1; RETURN true; END; -$function$; +$$; create or replace function leakproof(anyelement) returns boolean @@ -2166,11 +2017,11 @@ language plpgsql immutable leakproof strict -as $function$ +as $$ BEGIN RETURN true; END; -$function$; +$$; select * from rw_view1 where snoop(person); @@ -2222,12 +2073,7 @@ delete from rw_view1 where not snoop(person); create view rw_view2 with (security_barrier = 'true') -as select - * -from - rw_view1 -where - snoop(person); +as select * from rw_view1 where snoop(person); select table_name, @@ -2280,39 +2126,18 @@ insert into base_tbl values (1, 'Row 1', false), (2, 'Row 2', true); create rule base_tbl_ins_rule as on insert to base_tbl where - exists - ( - select - 1 - from - base_tbl as t - where - t.id = new.id - ) + exists (select 1 from base_tbl as t where t.id = new.id) do instead - update base_tbl - set data = new.data, - deleted = false - where - id = new.id;; + update base_tbl set data = new.data, deleted = false where id = new.id;; create rule base_tbl_del_rule as on delete to base_tbl do instead - update base_tbl - set deleted = true - where - id = old.id;; + update base_tbl set deleted = true where id = old.id;; create view rw_view1 with (security_barrier = 'true') -as select - id, - data -from - base_tbl -where - not deleted; +as select id, data from base_tbl where not deleted; select * from rw_view1; @@ -2334,7 +2159,7 @@ create table t1 ( c text ); -create index "t1_a_idx" on t1 using btree (a); +create index t1_a_idx on t1 using btree (a); insert into t1 select i, i, 't1' from generate_series(1, 10) as g (i); @@ -2343,7 +2168,7 @@ analyze t1; create table t11 (d text) inherits (t1); -create index "t11_a_idx" on t11 using btree (a); +create index t11_a_idx on t11 using btree (a); insert into t11 select i, i, 't11', 't11d' from generate_series(1, 10) as g (i); @@ -2352,24 +2177,17 @@ analyze t11; create table t12 (e int[]) inherits (t1); -create index "t12_a_idx" on t12 using btree (a); +create index t12_a_idx on t12 using btree (a); insert into t12 -select - i, - i, - 't12', - cast('{1,2}' as int[]) -from - generate_series(1, 10) as g (i); +select i, i, 't12', cast('{1,2}' as int[]) from generate_series(1, 10) as g (i); analyze t12; create table t111 () -inherits (t11, -t12); +inherits (t11, t12); -create index "t111_a_idx" on t111 using btree (a); +create index t111_a_idx on t111 using btree (a); insert into t111 select @@ -2387,24 +2205,11 @@ create view v1 with (security_barrier = 'true') as select *, - ( - select - d - from - t11 - where - t11.a = t1.a - limit 1 - ) - as d + (select d from t11 where t11.a = t1.a limit 1) as d from t1 where - a > 5 and - exists - ( - select 1 from t12 where t12.a = t1.a - ); + a > 5 and exists (select 1 from t12 where t12.a = t1.a); select * from v1 where a = 3; @@ -2441,18 +2246,7 @@ create table tx2 (b int); create table tx3 (c int); create view vx1 -as select - a -from - tx1 -where - exists - ( - select - 1 - from - tx2 inner join tx3 on b = c - ); +as select a from tx1 where exists (select 1 from tx2 inner join tx3 on b = c); insert into vx1 values (1); @@ -2475,18 +2269,7 @@ create table tx2 (b int); create table tx3 (c int); create view vx1 -as select - a -from - tx1 -where - exists - ( - select - 1 - from - tx2 inner join tx3 on b = c - ); +as select a from tx1 where exists (select 1 from tx2 inner join tx3 on b = c); insert into vx1 values (1); @@ -2529,18 +2312,7 @@ alter table tx3 drop column d; create view vx1 -as select - a -from - tx1 -where - exists - ( - select - 1 - from - tx2 inner join tx3 on b = c - ); +as select a from tx1 where exists (select 1 from tx2 inner join tx3 on b = c); insert into vx1 values (1); @@ -2577,15 +2349,7 @@ with cascaded check option; create view v2 with (security_barrier = 'true') -as select - * -from - v1 -where - exists - ( - select 1 from t2 where t2.cc = v1.c - ) +as select * from v1 where exists (select 1 from t2 where t2.cc = v1.c) with cascaded check option; insert into v2 values (2, 'two', 20); @@ -2699,21 +2463,18 @@ select events & 8 <> 0 as ins, events & 16 <> 0 as del from - pg_relation_is_updatable( - cast('uv_pt' as regclass), - false - ) + pg_catalog.pg_relation_is_updatable(cast('uv_pt' as regclass), false) as t (events); select - pg_column_is_updatable( + pg_catalog.pg_column_is_updatable( cast('uv_pt' as regclass), cast(1 as smallint), false ); select - pg_column_is_updatable( + pg_catalog.pg_column_is_updatable( cast('uv_pt' as regclass), cast(2 as smallint), false @@ -2755,17 +2516,12 @@ drop view uv_ptv, uv_ptv_wco; drop table uv_pt, uv_pt1, uv_pt11; create table wcowrtest (a int) -partition by LIST(a); +partition by list(a); create table wcowrtest1 partition of wcowrtest for values in (1); create view wcowrtest_v -as select - * -from - wcowrtest -where - wcowrtest = cast('(2)' as wcowrtest) +as select * from wcowrtest where wcowrtest = cast('(2)' as wcowrtest) with cascaded check option; insert into wcowrtest_v values (1); @@ -2799,15 +2555,7 @@ as select from wcowrtest as r where - r in - ( - select - s - from - sometable as s - where - r.a = s.a - ) + r in (select s from sometable as s where r.a = s.a) with cascaded check option; insert into wcowrtest_v2 values (2, 'no such row in sometable'); @@ -2824,63 +2572,33 @@ create table uv_iocu_tab ( insert into uv_iocu_tab values ('xyxyxy', 0); create view uv_iocu_view -as select - b, - b + 1 as c, - a, - cast('2.0' as text) as two -from - uv_iocu_tab; +as select b, b + 1 as c, a, cast('2.0' as text) as two from uv_iocu_tab; insert into uv_iocu_view (a, b) values ('xyxyxy', 1) -on conflict -(a) -do -update -set b = uv_iocu_view.b; +on conflict (a) do update set b = uv_iocu_view.b; select * from uv_iocu_tab; insert into uv_iocu_view (a, b) values ('xyxyxy', 1) -on conflict -(a) -do -update -set b = excluded.b; +on conflict (a) do update set b = excluded.b; select * from uv_iocu_tab; insert into uv_iocu_view (a, b) values ('xyxyxy', 3) -on conflict -(a) -do -update -set b = cast(excluded.two as double precision); +on conflict (a) do update set b = cast(excluded.two as double precision); select * from uv_iocu_tab; insert into uv_iocu_view (a, b) values ('xyxyxy', 3) -on conflict -(a) -do -update -set b = excluded.b -where - excluded.c > 0; +on conflict (a) do update set b = excluded.b where excluded.c > 0; insert into uv_iocu_view (a, b) values ('xyxyxy', 3) -on conflict -(a) -do -update -set b = excluded.b -where - excluded.c > 0; +on conflict (a) do update set b = excluded.b where excluded.c > 0; select * from uv_iocu_tab; @@ -2894,12 +2612,7 @@ create table uv_iocu_tab ( ); create view uv_iocu_view -as select - b as bb, - a as aa, - cast(uv_iocu_tab as text) as cc -from - uv_iocu_tab; +as select b as bb, a as aa, cast(uv_iocu_tab as text) as cc from uv_iocu_tab; insert into uv_iocu_view (aa, bb) values (1, 'x'); @@ -2911,9 +2624,7 @@ do update set bb = 'Rejected: ' || excluded.* where - excluded.aa > 0 and - excluded.bb <> '' and - excluded.cc is not null; + excluded.aa > 0 and excluded.bb <> '' and excluded.cc is not null; insert into uv_iocu_view (aa, bb) values (1, 'y') @@ -2923,9 +2634,7 @@ do update set bb = 'Rejected: ' || excluded.* where - excluded.aa > 0 and - excluded.bb <> '' and - excluded.cc is not null; + excluded.aa > 0 and excluded.bb <> '' and excluded.cc is not null; select * from uv_iocu_view; @@ -2935,11 +2644,7 @@ insert into uv_iocu_view (aa, bb) values (1, 'x'); insert into uv_iocu_view (aa) values (1) -on conflict -(aa) -do -update -set bb = 'Rejected: ' || excluded.*; +on conflict (aa) do update set bb = 'Rejected: ' || excluded.*; select * from uv_iocu_view; @@ -2948,11 +2653,7 @@ alter table uv_iocu_tab insert into uv_iocu_view (aa) values (1) -on conflict -(aa) -do -update -set bb = 'Rejected: ' || excluded.*; +on conflict (aa) do update set bb = 'Rejected: ' || excluded.*; select * from uv_iocu_view; @@ -2961,21 +2662,13 @@ alter view uv_iocu_view insert into uv_iocu_view (aa) values (1) -on conflict -(aa) -do -update -set bb = 'Rejected: ' || excluded.*; +on conflict (aa) do update set bb = 'Rejected: ' || excluded.*; select * from uv_iocu_view; insert into uv_iocu_view (aa) values (1) -on conflict -(aa) -do -update -set cc = 'XXX'; +on conflict (aa) do update set cc = 'XXX'; drop view uv_iocu_view; @@ -2996,52 +2689,31 @@ create table base_tbl ( insert into base_tbl values (1, 'xxx', 1.0); create view rw_view1 -as select - b as bb, - c as cc, - a as aa -from - base_tbl; +as select b as bb, c as cc, a as aa from base_tbl; -grant SELECT (aa, bb) on table rw_view1 to regress_view_user2; +grant select (aa, bb) on table rw_view1 to regress_view_user2; -grant INSERT on table rw_view1 to regress_view_user2; +grant insert on table rw_view1 to regress_view_user2; -grant UPDATE (bb) on table rw_view1 to regress_view_user2; +grant update (bb) on table rw_view1 to regress_view_user2; set session authorization regress_view_user2; insert into rw_view1 values ('yyy', 2.0, 1) -on conflict -(aa) -do -update -set bb = excluded.cc; +on conflict (aa) do update set bb = excluded.cc; insert into rw_view1 values ('yyy', 2.0, 1) -on conflict -(aa) -do -update -set bb = rw_view1.cc; +on conflict (aa) do update set bb = rw_view1.cc; insert into rw_view1 values ('yyy', 2.0, 1) -on conflict -(aa) -do -update -set bb = excluded.bb; +on conflict (aa) do update set bb = excluded.bb; insert into rw_view1 values ('zzz', 2.0, 1) -on conflict -(aa) -do -update -set bb = rw_view1.bb || 'xxx'; +on conflict (aa) do update set bb = rw_view1.bb || 'xxx'; insert into rw_view1 values ('zzz', 2.0, 1) @@ -3053,40 +2725,27 @@ select * from base_tbl; set session authorization regress_view_user1; -grant SELECT (a, b) on table base_tbl to regress_view_user2; +grant select (a, b) on table base_tbl to regress_view_user2; -grant INSERT (a, b) on table base_tbl to regress_view_user2; +grant insert (a, b) on table base_tbl to regress_view_user2; -grant UPDATE (a, b) on table base_tbl to regress_view_user2; +grant update (a, b) on table base_tbl to regress_view_user2; set session authorization regress_view_user2; create view rw_view2 -as select - b as bb, - c as cc, - a as aa -from - base_tbl; +as select b as bb, c as cc, a as aa from base_tbl; insert into rw_view2 (aa, bb) values (1, 'xxx') -on conflict -(aa) -do -update -set bb = excluded.bb; +on conflict (aa) do update set bb = excluded.bb; create view rw_view3 as select b as bb, a as aa from base_tbl; insert into rw_view3 (aa, bb) values (1, 'xxx') -on conflict -(aa) -do -update -set bb = excluded.bb; +on conflict (aa) do update set bb = excluded.bb; reset session_authorization; @@ -3099,22 +2758,14 @@ as select aa, bb, cc from rw_view1; insert into rw_view4 (aa, bb) values (1, 'yyy') -on conflict -(aa) -do -update -set bb = excluded.bb; +on conflict (aa) do update set bb = excluded.bb; create view rw_view5 as select aa, bb from rw_view1; insert into rw_view5 (aa, bb) values (1, 'yyy') -on conflict -(aa) -do -update -set bb = excluded.bb; +on conflict (aa) do update set bb = excluded.bb; reset session_authorization; @@ -3182,12 +2833,12 @@ select * from base_tab_def order by a; create function base_tab_def_view_instrig_func() returns trigger language plpgsql -as $function$ +as $$ begin insert into base_tab_def values (new.a, new.b, new.c, new.d, new.e); return new; end; -$function$; +$$; create trigger base_tab_def_view_instrig instead of insert @@ -3230,9 +2881,7 @@ drop function base_tab_def_view_instrig_func; create rule base_tab_def_view_ins_rule as on insert to base_tab_def_view do instead - insert into base_tab_def - values - (new.a, new.b, new.c, new.d, new.e);; + insert into base_tab_def values (new.a, new.b, new.c, new.d, new.e);; truncate base_tab_def; @@ -3267,9 +2916,7 @@ drop rule base_tab_def_view_ins_rule on base_tab_def_view; create rule base_tab_def_view_ins_rule as on insert to base_tab_def_view do - insert into base_tab_def - values - (new.a, new.b, new.c, new.d, new.e);; + insert into base_tab_def values (new.a, new.b, new.c, new.d, new.e);; truncate base_tab_def; @@ -3332,9 +2979,7 @@ alter view base_tab_view alter column c set default 'View default'; insert into base_tab_view (b[1], b[2], c, b[5], b[4], a, b[3]) -values - (1, 2, default, 5, 4, default, 3), - (10, 11, 'C value', 14, 13, 100, 12); +values (1, 2, default, 5, 4, default, 3), (10, 11, 'C value', 14, 13, 100, 12); select * from base_tab order by a; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_100.snap index 4d3a3f64b..df60ea680 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_100.snap @@ -54,15 +54,7 @@ select * from update_test; update update_test set (c, b) = ('car', a + b), b = a + 1 where a = 10; update update_test -set (b, a) = ( - select - a, - b - from - update_test - where - b = 41 and c = 'car' -) +set (b, a) = (select a, b from update_test where b = 41 and c = 'car') where a = 100 and b = 20; @@ -76,9 +68,7 @@ set (b, a) = ( from update_test as i where - i.a = o.a and - i.b = o.b and - i.c is not distinct from o.c + i.a = o.a and i.b = o.b and i.c is not distinct from o.c ); select * from update_test; @@ -104,16 +94,12 @@ update update_test set c = repeat('x', 10000) where c = 'car'; select a, b, char_length(c) from update_test; update update_test as t -set (a, b) = ( - select b, a from update_test as s where s.a = t.a -) +set (a, b) = (select b, a from update_test as s where s.a = t.a) where current_user = session_user; update update_test as t -set (a, b) = ( - select b, a from update_test as s where s.a = t.a -) +set (a, b) = (select b, a from update_test as s where s.a = t.a) where current_user = session_user; @@ -124,11 +110,7 @@ insert into upsert_test values (1, 'Boo'), (3, 'Zoo'); with aaa as (select 1 as a, 'Foo' as b) insert into upsert_test values (1, 'Bar') -on conflict -(a) -do -update -set (b, a) = (select b, a from aaa) +on conflict (a) do update set (b, a) = (select b, a from aaa) returning *; insert into upsert_test @@ -137,15 +119,7 @@ on conflict (a) do update -set (b, a) = ( - select - b || ', Correlated', - a - from - upsert_test as i - where - i.a = upsert_test.a -) +set (b, a) = (select b || ', Correlated', a from upsert_test as i where i.a = upsert_test.a) returning *; insert into upsert_test @@ -154,15 +128,7 @@ on conflict (a) do update -set (b, a) = ( - select - b || ', Excluded', - a - from - upsert_test as i - where - i.a = excluded.a -) +set (b, a) = (select b || ', Excluded', a from upsert_test as i where i.a = excluded.a) returning *; insert into upsert_test @@ -171,18 +137,9 @@ on conflict (a) do update -set (b, a) = ( - select - b || ', Excluded', - a - from - upsert_test as i - where - i.a = excluded.a -) +set (b, a) = (select b || ', Excluded', a from upsert_test as i where i.a = excluded.a) returning cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_correct, +xmin = cast(pg_current_xact_id() as xid) as xmin_correct, xmax = 0 as xmax_correct; insert into upsert_test @@ -191,20 +148,10 @@ on conflict (a) do update -set (b, a) = ( - select - b || ', Excluded', - a - from - upsert_test as i - where - i.a = excluded.a -) +set (b, a) = (select b || ', Excluded', a from upsert_test as i where i.a = excluded.a) returning cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_correct, -xmax = cast(pg_current_xact_id() as xid) -as xmax_correct; +xmin = cast(pg_current_xact_id() as xid) as xmin_correct, +xmax = cast(pg_current_xact_id() as xid) as xmax_correct; drop table update_test; @@ -214,7 +161,7 @@ create table upsert_test ( a int primary key, b text ) -partition by LIST(a); +partition by list(a); create table upsert_test_1 partition of upsert_test for values in (1); @@ -232,27 +179,13 @@ insert into upsert_test values (1, 'Boo'), (2, 'Zoo'); with aaa as (select 1 as a, 'Foo' as b) insert into upsert_test values (1, 'Bar') -on conflict -(a) -do -update -set (b, a) = (select b, a from aaa) +on conflict (a) do update set (b, a) = (select b, a from aaa) returning *; with aaa as (select 1 as ctea, ' Foo' as cteb) insert into upsert_test values (1, 'Bar'), (2, 'Baz') -on conflict -(a) -do -update -set (b, a) = ( - select - upsert_test.b || cteb, - upsert_test.a - from - aaa -) +on conflict (a) do update set (b, a) = (select upsert_test.b || cteb, upsert_test.a from aaa) returning *; drop table upsert_test; @@ -276,8 +209,7 @@ create table part_b_20_b_30 ( alter table range_parted attach partition - part_b_20_b_30 - for values from ('b', 20) to ('b', 30); + part_b_20_b_30 for values from ('b', 20) to ('b', 30); create table part_b_10_b_20 ( e varchar, @@ -292,8 +224,7 @@ create table part_b_1_b_10 partition of range_parted for values from ('b', 1) to alter table range_parted attach partition - part_b_10_b_20 - for values from ('b', 10) to ('b', 20); + part_b_10_b_20 for values from ('b', 10) to ('b', 20); create table part_a_10_a_20 partition of range_parted for values from ('a', 10) to ('a', 20); @@ -369,12 +300,7 @@ create table mintab (c1 int); insert into mintab values (120); create view upview -as select - * -from - range_parted -where - (select c > c1 from mintab) +as select * from range_parted where (select c > c1 from mintab) with cascaded check option; update upview set c = 199 where b = 4; @@ -392,15 +318,15 @@ update range_parted set c = 95 where a = 'b' and b > 10 and c > 100 returning ra create function trans_updatetrigfunc() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, old table = %, new table = %', TG_NAME, (select string_agg(old_table::text, ', ' ORDER BY a) FROM old_table), (select string_agg(new_table::text, ', ' ORDER BY a) FROM new_table); return null; end; -$function$; +$$; create trigger trans_updatetrig after update @@ -438,12 +364,11 @@ drop trigger trans_inserttrig on range_parted; create function func_parted_mod_b() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.b = NEW.b + 1; return NEW; -END -$function$; +END $$; create trigger trig_c1_100 before insert or update @@ -508,12 +433,11 @@ reset session_authorization; create function func_d_1_15() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.c = NEW.c + 1; -- Make even numbers odd, or vice versa return NEW; -END -$function$; +END $$; create trigger trig_d_1_15 before insert on part_d_1_15 for each row execute function func_d_1_15(); @@ -557,8 +481,7 @@ as restrictive for update to public using (true) -with check (range_parted = -cast(row('b', 10, 112, 1, null) as range_parted)); +with check (range_parted = cast(row('b', 10, 112, 1, null) as range_parted)); set session authorization regress_range_parted_user; @@ -587,13 +510,13 @@ drop table mintab; create function trigfunc() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = % fired on table % during %', TG_NAME, TG_TABLE_NAME, TG_OP; return null; end; -$function$; +$$; create trigger parent_delete_trig after delete @@ -717,7 +640,7 @@ create table list_parted ( a text, b int ) -partition by LIST(a); +partition by list(a); create table list_part1 partition of list_parted for values in ('a', 'b'); @@ -737,7 +660,7 @@ create table utrtest ( a int, b text ) -partition by LIST(a); +partition by list(a); create table utr1 ( a int check (a in (1)), @@ -765,15 +688,13 @@ insert into utrtest values (1, 'foo') returning *, cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_ok; +xmin = cast(pg_current_xact_id() as xid) as xmin_ok; insert into utrtest values (2, 'bar') returning *, cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_ok; +xmin = cast(pg_current_xact_id() as xid) as xmin_ok; insert into utrtest values (2, 'bar') returning *, cast(tableoid as regclass); @@ -784,8 +705,7 @@ where a = s.x returning *, cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_ok; +xmin = cast(pg_current_xact_id() as xid) as xmin_ok; update utrtest set a = 3 - a @@ -794,8 +714,7 @@ where a = s.x returning *, cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_ok; +xmin = cast(pg_current_xact_id() as xid) as xmin_ok; update utrtest set a = 3 - a @@ -808,23 +727,22 @@ cast(tableoid as regclass); delete from utrtest returning *, cast(tableoid as regclass), -xmax = cast(pg_current_xact_id() as xid) -as xmax_ok; +xmax = cast(pg_current_xact_id() as xid) as xmax_ok; drop table utrtest; create table list_parted ( a numeric, b int, - c bigint + c int8 ) -partition by LIST(a); +partition by list(a); -create table sub_parted partition of list_parted for values in (1) partition by LIST(b); +create table sub_parted partition of list_parted for values in (1) partition by list(b); create table sub_part1 ( b int, - c bigint, + c int8, a numeric ); @@ -834,7 +752,7 @@ alter table sub_parted create table sub_part2 ( b int, - c bigint, + c int8, a numeric ); @@ -845,7 +763,7 @@ alter table sub_parted create table list_part1 ( a numeric, b int, - c bigint + c int8 ); alter table list_parted @@ -871,12 +789,11 @@ select cast(cast(tableoid as regclass) as text), * from list_parted where a = 2 create function func_parted_mod_b() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.b = 2; -- This is changing partition key column. return NEW; -END -$function$; +END $$; create trigger parted_mod_b before update @@ -895,12 +812,11 @@ drop trigger parted_mod_b on sub_part1; create or replace function func_parted_mod_b() returns trigger language plpgsql -as $function$ +as $$ BEGIN raise notice 'Trigger: Got OLD row %, but returning NULL', OLD; return NULL; -END -$function$; +END $$; create trigger trig_skip_delete before delete @@ -932,34 +848,31 @@ drop table non_parted; drop table list_parted; -create or replace function dummy_hashint4(a int, seed bigint) -returns bigint +create or replace function dummy_hashint4(a int4, seed int8) +returns int8 language plpgsql immutable -as $function$ -begin return (a + seed); end; -$function$; +as $$ begin return (a + seed); end; $$; create operator class custom_opclass - for type int + for type int4 using hash as operator 1 =, - function 2 dummy_hashint4(int, bigint); + function 2 dummy_hashint4(int4, int8); create table hash_parted ( a int, b int ) -partition by HASH(a custom_opclass, -b custom_opclass); +partition by hash(a custom_opclass, b custom_opclass); -create table hpart1 partition of hash_parted for values with (MODULUS 2, REMAINDER 1); +create table hpart1 partition of hash_parted for values with (modulus 2, remainder 1); -create table hpart2 partition of hash_parted for values with (MODULUS 4, REMAINDER 2); +create table hpart2 partition of hash_parted for values with (modulus 4, remainder 2); -create table hpart3 partition of hash_parted for values with (MODULUS 8, REMAINDER 0); +create table hpart3 partition of hash_parted for values with (modulus 8, remainder 0); -create table hpart4 partition of hash_parted for values with (MODULUS 8, REMAINDER 4); +create table hpart4 partition of hash_parted for values with (modulus 8, remainder 4); insert into hpart1 values (1, 1); @@ -977,4 +890,4 @@ drop table hash_parted; drop operator class custom_opclass using hash; -drop function dummy_hashint4(int, bigint); +drop function dummy_hashint4(a int4, seed int8); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_80.snap index 997195d20..4e1a7048a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_80.snap @@ -62,15 +62,7 @@ select * from update_test; update update_test set (c, b) = ('car', a + b), b = a + 1 where a = 10; update update_test -set (b, a) = ( - select - a, - b - from - update_test - where - b = 41 and c = 'car' -) +set (b, a) = (select a, b from update_test where b = 41 and c = 'car') where a = 100 and b = 20; @@ -84,9 +76,7 @@ set (b, a) = ( from update_test as i where - i.a = o.a and - i.b = o.b and - i.c is not distinct from o.c + i.a = o.a and i.b = o.b and i.c is not distinct from o.c ); select * from update_test; @@ -94,15 +84,7 @@ select * from update_test; update update_test set (b, a) = (select a + 1, b from update_test); update update_test -set (b, a) = ( - select - a + 1, - b - from - update_test - where - a = 1000 -) +set (b, a) = (select a + 1, b from update_test where a = 1000) where a = 11; @@ -127,28 +109,12 @@ update update_test set c = repeat('x', 10000) where c = 'car'; select a, b, char_length(c) from update_test; update update_test as t -set (a, b) = ( - select - b, - a - from - update_test as s - where - s.a = t.a -) +set (a, b) = (select b, a from update_test as s where s.a = t.a) where current_user = session_user; update update_test as t -set (a, b) = ( - select - b, - a - from - update_test as s - where - s.a = t.a -) +set (a, b) = (select b, a from update_test as s where s.a = t.a) where current_user = session_user; @@ -159,11 +125,7 @@ insert into upsert_test values (1, 'Boo'), (3, 'Zoo'); with aaa as (select 1 as a, 'Foo' as b) insert into upsert_test values (1, 'Bar') -on conflict -(a) -do -update -set (b, a) = (select b, a from aaa) +on conflict (a) do update set (b, a) = (select b, a from aaa) returning *; insert into upsert_test @@ -173,13 +135,7 @@ on conflict do update set (b, a) = ( - select - b || ', Correlated', - a - from - upsert_test as i - where - i.a = upsert_test.a + select b || ', Correlated', a from upsert_test as i where i.a = upsert_test.a ) returning *; @@ -190,13 +146,7 @@ on conflict do update set (b, a) = ( - select - b || ', Excluded', - a - from - upsert_test as i - where - i.a = excluded.a + select b || ', Excluded', a from upsert_test as i where i.a = excluded.a ) returning *; @@ -207,17 +157,10 @@ on conflict do update set (b, a) = ( - select - b || ', Excluded', - a - from - upsert_test as i - where - i.a = excluded.a + select b || ', Excluded', a from upsert_test as i where i.a = excluded.a ) returning cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_correct, +xmin = cast(pg_current_xact_id() as xid) as xmin_correct, xmax = 0 as xmax_correct; insert into upsert_test @@ -227,19 +170,11 @@ on conflict do update set (b, a) = ( - select - b || ', Excluded', - a - from - upsert_test as i - where - i.a = excluded.a + select b || ', Excluded', a from upsert_test as i where i.a = excluded.a ) returning cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_correct, -xmax = cast(pg_current_xact_id() as xid) -as xmax_correct; +xmin = cast(pg_current_xact_id() as xid) as xmin_correct, +xmax = cast(pg_current_xact_id() as xid) as xmax_correct; drop table update_test; @@ -249,7 +184,7 @@ create table upsert_test ( a int primary key, b text ) -partition by LIST(a); +partition by list(a); create table upsert_test_1 partition of upsert_test for values in (1); @@ -267,31 +202,17 @@ insert into upsert_test values (1, 'Boo'), (2, 'Zoo'); with aaa as (select 1 as a, 'Foo' as b) insert into upsert_test values (1, 'Bar') -on conflict -(a) -do -update -set (b, a) = (select b, a from aaa) +on conflict (a) do update set (b, a) = (select b, a from aaa) returning *; -with -aaa -as ( - select 1 as ctea, ' Foo' as cteb -) +with aaa as (select 1 as ctea, ' Foo' as cteb) insert into upsert_test values (1, 'Bar'), (2, 'Baz') on conflict (a) do update -set (b, a) = ( - select - upsert_test.b || cteb, - upsert_test.a - from - aaa -) +set (b, a) = (select upsert_test.b || cteb, upsert_test.a from aaa) returning *; drop table upsert_test; @@ -315,8 +236,7 @@ create table part_b_20_b_30 ( alter table range_parted attach partition - part_b_20_b_30 - for values from ('b', 20) to ('b', 30); + part_b_20_b_30 for values from ('b', 20) to ('b', 30); create table part_b_10_b_20 ( e varchar, @@ -333,8 +253,7 @@ for values from ('b', 1) to ('b', 10); alter table range_parted attach partition - part_b_10_b_20 - for values from ('b', 10) to ('b', 20); + part_b_10_b_20 for values from ('b', 10) to ('b', 20); create table part_a_10_a_20 partition of range_parted @@ -381,8 +300,7 @@ for values from (15) to (20); alter table part_b_10_b_20 attach partition - part_c_100_200 - for values from (100) to (200); + part_c_100_200 for values from (100) to (200); create table part_c_1_100 ( e varchar, @@ -394,8 +312,7 @@ create table part_c_1_100 ( alter table part_b_10_b_20 attach partition - part_c_1_100 - for values from (1) to (100); + part_c_1_100 for values from (1) to (100); update range_parted set c = c - 50 where c > 97; @@ -420,12 +337,7 @@ create table mintab (c1 int); insert into mintab values (120); create view upview -as select - * -from - range_parted -where - (select c > c1 from mintab) +as select * from range_parted where (select c > c1 from mintab) with cascaded check option; update upview set c = 199 where b = 4; @@ -448,15 +360,15 @@ returning range_parted, create function trans_updatetrigfunc() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = %, old table = %, new table = %', TG_NAME, (select string_agg(old_table::text, ', ' ORDER BY a) FROM old_table), (select string_agg(new_table::text, ', ' ORDER BY a) FROM new_table); return null; end; -$function$; +$$; create trigger trans_updatetrig after update @@ -494,12 +406,11 @@ drop trigger trans_inserttrig on range_parted; create function func_parted_mod_b() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.b = NEW.b + 1; return NEW; -END -$function$; +END $$; create trigger trig_c1_100 before insert or update @@ -569,12 +480,11 @@ reset session_authorization; create function func_d_1_15() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.c = NEW.c + 1; -- Make even numbers odd, or vice versa return NEW; -END -$function$; +END $$; create trigger trig_d_1_15 before insert @@ -606,9 +516,7 @@ as restrictive for update to public using (true) -with check (( - select range_parted.c <= c1 from mintab -)); +with check ((select range_parted.c <= c1 from mintab)); set session authorization regress_range_parted_user; @@ -624,9 +532,7 @@ as restrictive for update to public using (true) -with check (range_parted = -cast(row('b', 10, 112, 1, null) -as range_parted)); +with check (range_parted = cast(row('b', 10, 112, 1, null) as range_parted)); set session authorization regress_range_parted_user; @@ -655,13 +561,13 @@ drop table mintab; create function trigfunc() returns trigger language plpgsql -as $function$ -begin +as $$ + begin raise notice 'trigger = % fired on table % during %', TG_NAME, TG_TABLE_NAME, TG_OP; return null; end; -$function$; +$$; create trigger parent_delete_trig after delete @@ -785,7 +691,7 @@ create table list_parted ( a text, b int ) -partition by LIST(a); +partition by list(a); create table list_part1 partition of list_parted for values in ('a', 'b'); @@ -805,7 +711,7 @@ create table utrtest ( a int, b text ) -partition by LIST(a); +partition by list(a); create table utr1 ( a int check (a in (1)), @@ -833,15 +739,13 @@ insert into utrtest values (1, 'foo') returning *, cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_ok; +xmin = cast(pg_current_xact_id() as xid) as xmin_ok; insert into utrtest values (2, 'bar') returning *, cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_ok; +xmin = cast(pg_current_xact_id() as xid) as xmin_ok; insert into utrtest values (2, 'bar') returning *, cast(tableoid as regclass); @@ -852,8 +756,7 @@ where a = s.x returning *, cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_ok; +xmin = cast(pg_current_xact_id() as xid) as xmin_ok; update utrtest set a = 3 - a @@ -862,8 +765,7 @@ where a = s.x returning *, cast(tableoid as regclass), -xmin = cast(pg_current_xact_id() as xid) -as xmin_ok; +xmin = cast(pg_current_xact_id() as xid) as xmin_ok; update utrtest set a = 3 - a @@ -876,26 +778,25 @@ cast(tableoid as regclass); delete from utrtest returning *, cast(tableoid as regclass), -xmax = cast(pg_current_xact_id() as xid) -as xmax_ok; +xmax = cast(pg_current_xact_id() as xid) as xmax_ok; drop table utrtest; create table list_parted ( a numeric, b int, - c bigint + c int8 ) -partition by LIST(a); +partition by list(a); create table sub_parted partition of list_parted for values in (1) -partition by LIST(b); +partition by list(b); create table sub_part1 ( b int, - c bigint, + c int8, a numeric ); @@ -905,7 +806,7 @@ alter table sub_parted create table sub_part2 ( b int, - c bigint, + c int8, a numeric ); @@ -916,7 +817,7 @@ alter table sub_parted create table list_part1 ( a numeric, b int, - c bigint + c int8 ); alter table list_parted @@ -956,12 +857,11 @@ order by 1; create function func_parted_mod_b() returns trigger language plpgsql -as $function$ +as $$ BEGIN NEW.b = 2; -- This is changing partition key column. return NEW; -END -$function$; +END $$; create trigger parted_mod_b before update @@ -996,12 +896,11 @@ drop trigger parted_mod_b on sub_part1; create or replace function func_parted_mod_b() returns trigger language plpgsql -as $function$ +as $$ BEGIN raise notice 'Trigger: Got OLD row %, but returning NULL', OLD; return NULL; -END -$function$; +END $$; create trigger trig_skip_delete before delete @@ -1061,42 +960,39 @@ drop table non_parted; drop table list_parted; -create or replace function dummy_hashint4(a int, seed bigint) -returns bigint +create or replace function dummy_hashint4(a int4, seed int8) +returns int8 language plpgsql immutable -as $function$ -begin return (a + seed); end; -$function$; +as $$ begin return (a + seed); end; $$; create operator class custom_opclass - for type int + for type int4 using hash as operator 1 =, - function 2 dummy_hashint4(int, bigint); + function 2 dummy_hashint4(int4, int8); create table hash_parted ( a int, b int ) -partition by HASH(a custom_opclass, -b custom_opclass); +partition by hash(a custom_opclass, b custom_opclass); create table hpart1 partition of hash_parted -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); create table hpart2 partition of hash_parted -for values with (MODULUS 4, REMAINDER 2); +for values with (modulus 4, remainder 2); create table hpart3 partition of hash_parted -for values with (MODULUS 8, REMAINDER 0); +for values with (modulus 8, remainder 0); create table hpart4 partition of hash_parted -for values with (MODULUS 8, REMAINDER 4); +for values with (modulus 8, remainder 4); insert into hpart1 values (1, 1); @@ -1114,4 +1010,4 @@ drop table hash_parted; drop operator class custom_opclass using hash; -drop function dummy_hashint4(int, bigint); +drop function dummy_hashint4(a int4, seed int8); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_multi_assign_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_multi_assign_100.snap index 762bc7719..5bae39827 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_multi_assign_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_multi_assign_100.snap @@ -6,13 +6,13 @@ snapshot_kind: text create table ledger ( id int primary key, balance numeric, - updated_at timestamp with time zone + updated_at timestamptz ); create table adjustments ( id int, delta numeric, - seen_at timestamp with time zone + seen_at timestamptz ); update ledger @@ -22,12 +22,9 @@ where ledger.id = adjustments.id; insert into ledger as l (id, balance, updated_at) -values (1, 10, NOW()) +values (1, 10, now()) on conflict (id) do update -set (balance, updated_at) = ( - excluded.balance + l.balance, - excluded.updated_at -); +set (balance, updated_at) = (excluded.balance + l.balance, excluded.updated_at); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_multi_assign_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_multi_assign_80.snap index 762bc7719..5bae39827 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_multi_assign_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__update_multi_assign_80.snap @@ -6,13 +6,13 @@ snapshot_kind: text create table ledger ( id int primary key, balance numeric, - updated_at timestamp with time zone + updated_at timestamptz ); create table adjustments ( id int, delta numeric, - seen_at timestamp with time zone + seen_at timestamptz ); update ledger @@ -22,12 +22,9 @@ where ledger.id = adjustments.id; insert into ledger as l (id, balance, updated_at) -values (1, 10, NOW()) +values (1, 10, now()) on conflict (id) do update -set (balance, updated_at) = ( - excluded.balance + l.balance, - excluded.updated_at -); +set (balance, updated_at) = (excluded.balance + l.balance, excluded.updated_at); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__uuid_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__uuid_100.snap index ce8ecbd71..ad5b8996e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__uuid_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__uuid_100.snap @@ -5,12 +5,12 @@ snapshot_kind: text --- create table guid1 ( guid_field uuid, - text_field text default NOW() + text_field text default now() ); create table guid2 ( guid_field uuid, - text_field text default NOW() + text_field text default now() ); create table guid3 ( @@ -46,56 +46,52 @@ select guid_field from guid1 order by guid_field asc; select guid_field from guid1 order by guid_field desc; -select COUNT(*) from guid1 where guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'; +select count(*) from guid1 where guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'; -select COUNT(*) from guid1 where guid_field <> '11111111111111111111111111111111'; +select count(*) from guid1 where guid_field <> '11111111111111111111111111111111'; -select COUNT(*) from guid1 where guid_field < '22222222-2222-2222-2222-222222222222'; +select count(*) from guid1 where guid_field < '22222222-2222-2222-2222-222222222222'; -select COUNT(*) from guid1 where guid_field <= '22222222-2222-2222-2222-222222222222'; +select count(*) from guid1 where guid_field <= '22222222-2222-2222-2222-222222222222'; -select COUNT(*) from guid1 where guid_field > '22222222-2222-2222-2222-222222222222'; +select count(*) from guid1 where guid_field > '22222222-2222-2222-2222-222222222222'; -select COUNT(*) from guid1 where guid_field >= '22222222-2222-2222-2222-222222222222'; +select count(*) from guid1 where guid_field >= '22222222-2222-2222-2222-222222222222'; -create index "guid1_btree" on guid1 using btree (guid_field); +create index guid1_btree on guid1 using btree (guid_field); -create index "guid1_hash" on guid1 using hash (guid_field); +create index guid1_hash on guid1 using hash (guid_field); -create unique index "guid1_unique_btree" on guid1 using btree (guid_field); +create unique index guid1_unique_btree on guid1 using btree (guid_field); select - COUNT(*) + count(*) from guid1 where guid_field <> '11111111111111111111111111111111' or - guid_field <> - '3f3e3c3b-3a30-3938-3736-353433a2313e'; + guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'; select - COUNT(*) + count(*) from guid1 where - guid_field <= - '22222222-2222-2222-2222-222222222222' or + guid_field <= '22222222-2222-2222-2222-222222222222' or guid_field <= '11111111111111111111111111111111' or - guid_field <= - '3f3e3c3b-3a30-3938-3736-353433a2313e'; + guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'; select - COUNT(*) + count(*) from guid1 where - guid_field = - '3f3e3c3b-3a30-3938-3736-353433a2313e' or + guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' or guid_field = '11111111111111111111111111111111'; insert into guid1 (guid_field) values ('11111111-1111-1111-1111-111111111111'); -select COUNT(*) from pg_class where relkind = 'i' and relname like 'guid%'; +select count(*) from pg_class where relkind = 'i' and relname like 'guid%'; insert into guid1 (guid_field) values ('44444444-4444-4444-4444-444444444444'); @@ -105,15 +101,12 @@ insert into guid2 (guid_field) values ('{22222222-2222-2222-2222-222222222222}') insert into guid2 (guid_field) values ('3f3e3c3b3a3039383736353433a2313e'); -select COUNT(*) from guid1 as g1 inner join guid2 as g2 on g1.guid_field = g2.guid_field; +select count(*) from guid1 as g1 inner join guid2 as g2 on g1.guid_field = g2.guid_field; select - COUNT(*) + count(*) from - guid1 as g1 - left outer join - guid2 as g2 - on g1.guid_field = g2.guid_field + guid1 as g1 left outer join guid2 as g2 on g1.guid_field = g2.guid_field where g2.guid_field is null; @@ -123,7 +116,7 @@ insert into guid1 (guid_field) values (gen_random_uuid()); insert into guid1 (guid_field) values (gen_random_uuid()); -select COUNT(distinct guid_field) from guid1; +select count(distinct guid_field) from guid1; truncate guid1; @@ -131,7 +124,7 @@ insert into guid1 (guid_field) values (uuidv4()); insert into guid1 (guid_field) values (uuidv4()); -select COUNT(distinct guid_field) from guid1; +select count(distinct guid_field) from guid1; truncate guid1; @@ -141,7 +134,7 @@ insert into guid1 (guid_field) values (uuidv7()); insert into guid1 (guid_field) values (uuidv7(cast('1 day' as interval))); -select COUNT(distinct guid_field) from guid1; +select count(distinct guid_field) from guid1; insert into guid3 (guid_field) select uuidv7() from generate_series(1, 10); @@ -153,19 +146,16 @@ as ( select y, ts as ts, - LAG(ts) over (order by y) as prev_ts + lag(ts) over (order by y) as prev_ts from ( select y, - uuid_extract_timestamp( - uuidv7(cast(y || ' years' as interval)) - ) - as ts + uuid_extract_timestamp(uuidv7(cast(y || ' years' as interval))) as ts from generate_series( - 1970 - cast(EXTRACT('year' from NOW()) as int), - 10888 - cast(EXTRACT('year' from NOW()) as int) + 1970 - cast(extract(year from now()) as int), + 10888 - cast(extract(year from now()) as int) ) as y ) @@ -190,15 +180,11 @@ select uuid_extract_version(uuidv4()); select uuid_extract_version(uuidv7()); select - uuid_extract_timestamp( - 'C232AB00-9414-11EC-B3C8-9F6BDECED846' - ) = + uuid_extract_timestamp('C232AB00-9414-11EC-B3C8-9F6BDECED846') = 'Tuesday, February 22, 2022 2:22:22.00 PM GMT+05:00'; select - uuid_extract_timestamp( - '017F22E2-79B0-7CC3-98C4-DC0C0C07398F' - ) = + uuid_extract_timestamp('017F22E2-79B0-7CC3-98C4-DC0C0C07398F') = 'Tuesday, February 22, 2022 2:22:22.00 PM GMT+05:00'; select uuid_extract_timestamp(gen_random_uuid()); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__uuid_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__uuid_80.snap index 43ae6d636..5a0fcd08a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__uuid_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__uuid_80.snap @@ -5,12 +5,12 @@ snapshot_kind: text --- create table guid1 ( guid_field uuid, - text_field text default NOW() + text_field text default now() ); create table guid2 ( guid_field uuid, - text_field text default NOW() + text_field text default now() ); create table guid3 ( @@ -25,10 +25,7 @@ insert into guid1 (guid_field) values ('{11111111-1111-1111-1111-11111111111}'); insert into guid1 (guid_field) values ('111-11111-1111-1111-1111-111111111111'); insert into guid1 (guid_field) -values - ( - '{22222222-2222-2222-2222-222222222222 ' - ); +values ('{22222222-2222-2222-2222-222222222222 '); insert into guid1 (guid_field) values ('11111111-1111-1111-G111-111111111111'); @@ -41,10 +38,7 @@ select * from pg_input_error_info('11', 'uuid'); insert into guid1 (guid_field) values ('11111111-1111-1111-1111-111111111111'); insert into guid1 (guid_field) -values - ( - '{22222222-2222-2222-2222-222222222222}' - ); +values ('{22222222-2222-2222-2222-222222222222}'); insert into guid1 (guid_field) values ('3f3e3c3b3a3039383736353433a2313e'); @@ -55,122 +49,100 @@ select guid_field from guid1 order by guid_field asc; select guid_field from guid1 order by guid_field desc; select - COUNT(*) + count(*) from guid1 where - guid_field = - '3f3e3c3b-3a30-3938-3736-353433a2313e'; + guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e'; select - COUNT(*) + count(*) from guid1 where - guid_field <> - '11111111111111111111111111111111'; + guid_field <> '11111111111111111111111111111111'; select - COUNT(*) + count(*) from guid1 where - guid_field < - '22222222-2222-2222-2222-222222222222'; + guid_field < '22222222-2222-2222-2222-222222222222'; select - COUNT(*) + count(*) from guid1 where - guid_field <= - '22222222-2222-2222-2222-222222222222'; + guid_field <= '22222222-2222-2222-2222-222222222222'; select - COUNT(*) + count(*) from guid1 where - guid_field > - '22222222-2222-2222-2222-222222222222'; + guid_field > '22222222-2222-2222-2222-222222222222'; select - COUNT(*) + count(*) from guid1 where - guid_field >= - '22222222-2222-2222-2222-222222222222'; + guid_field >= '22222222-2222-2222-2222-222222222222'; -create index "guid1_btree" on guid1 using btree (guid_field); +create index guid1_btree on guid1 using btree (guid_field); -create index "guid1_hash" on guid1 using hash (guid_field); +create index guid1_hash on guid1 using hash (guid_field); -create unique index "guid1_unique_btree" on guid1 using btree (guid_field); +create unique index guid1_unique_btree on guid1 using btree (guid_field); select - COUNT(*) + count(*) from guid1 where - guid_field <> - '11111111111111111111111111111111' or - guid_field <> - '3f3e3c3b-3a30-3938-3736-353433a2313e'; + guid_field <> '11111111111111111111111111111111' or + guid_field <> '3f3e3c3b-3a30-3938-3736-353433a2313e'; select - COUNT(*) + count(*) from guid1 where - guid_field <= - '22222222-2222-2222-2222-222222222222' or - guid_field <= - '11111111111111111111111111111111' or - guid_field <= - '3f3e3c3b-3a30-3938-3736-353433a2313e'; + guid_field <= '22222222-2222-2222-2222-222222222222' or + guid_field <= '11111111111111111111111111111111' or + guid_field <= '3f3e3c3b-3a30-3938-3736-353433a2313e'; select - COUNT(*) + count(*) from guid1 where - guid_field = - '3f3e3c3b-3a30-3938-3736-353433a2313e' or - guid_field = - '11111111111111111111111111111111'; + guid_field = '3f3e3c3b-3a30-3938-3736-353433a2313e' or + guid_field = '11111111111111111111111111111111'; insert into guid1 (guid_field) values ('11111111-1111-1111-1111-111111111111'); -select COUNT(*) from pg_class where relkind = 'i' and relname like 'guid%'; +select count(*) from pg_class where relkind = 'i' and relname like 'guid%'; insert into guid1 (guid_field) values ('44444444-4444-4444-4444-444444444444'); insert into guid2 (guid_field) values ('11111111-1111-1111-1111-111111111111'); insert into guid2 (guid_field) -values - ( - '{22222222-2222-2222-2222-222222222222}' - ); +values ('{22222222-2222-2222-2222-222222222222}'); insert into guid2 (guid_field) values ('3f3e3c3b3a3039383736353433a2313e'); select - COUNT(*) + count(*) from - guid1 as g1 - inner join - guid2 as g2 - on g1.guid_field = g2.guid_field; + guid1 as g1 inner join guid2 as g2 on g1.guid_field = g2.guid_field; select - COUNT(*) + count(*) from - guid1 as g1 - left outer join - guid2 as g2 - on g1.guid_field = g2.guid_field + guid1 as g1 left outer join guid2 as g2 on g1.guid_field = g2.guid_field where g2.guid_field is null; @@ -180,7 +152,7 @@ insert into guid1 (guid_field) values (gen_random_uuid()); insert into guid1 (guid_field) values (gen_random_uuid()); -select COUNT(distinct guid_field) from guid1; +select count(distinct guid_field) from guid1; truncate guid1; @@ -188,7 +160,7 @@ insert into guid1 (guid_field) values (uuidv4()); insert into guid1 (guid_field) values (uuidv4()); -select COUNT(distinct guid_field) from guid1; +select count(distinct guid_field) from guid1; truncate guid1; @@ -198,7 +170,7 @@ insert into guid1 (guid_field) values (uuidv7()); insert into guid1 (guid_field) values (uuidv7(cast('1 day' as interval))); -select COUNT(distinct guid_field) from guid1; +select count(distinct guid_field) from guid1; insert into guid3 (guid_field) select uuidv7() from generate_series(1, 10); @@ -210,21 +182,16 @@ as ( select y, ts as ts, - LAG(ts) over (order by y) as prev_ts + lag(ts) over (order by y) as prev_ts from ( select y, - uuid_extract_timestamp( - uuidv7(cast(y || ' years' as interval)) - ) - as ts + uuid_extract_timestamp(uuidv7(cast(y || ' years' as interval))) as ts from generate_series( - 1970 - - cast(EXTRACT('year' from NOW()) as int), - 10888 - - cast(EXTRACT('year' from NOW()) as int) + 1970 - cast(extract(year from now()) as int), + 10888 - cast(extract(year from now()) as int) ) as y ) @@ -249,15 +216,11 @@ select uuid_extract_version(uuidv4()); select uuid_extract_version(uuidv7()); select - uuid_extract_timestamp( - 'C232AB00-9414-11EC-B3C8-9F6BDECED846' - ) = + uuid_extract_timestamp('C232AB00-9414-11EC-B3C8-9F6BDECED846') = 'Tuesday, February 22, 2022 2:22:22.00 PM GMT+05:00'; select - uuid_extract_timestamp( - '017F22E2-79B0-7CC3-98C4-DC0C0C07398F' - ) = + uuid_extract_timestamp('017F22E2-79B0-7CC3-98C4-DC0C0C07398F') = 'Tuesday, February 22, 2022 2:22:22.00 PM GMT+05:00'; select uuid_extract_timestamp(gen_random_uuid()); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_100.snap index 74548618b..013a31fd6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_100.snap @@ -30,13 +30,13 @@ insert into vactst select * from vactst; insert into vactst values (0); -select COUNT(*) from vactst; +select count(*) from vactst; delete from vactst where i <> 0; select * from vactst; -vacuum (FULL) vactst; +vacuum (full) vactst; update vactst set i = i + 1; @@ -64,19 +64,19 @@ insert into vactst select * from vactst; insert into vactst values (0); -select COUNT(*) from vactst; +select count(*) from vactst; delete from vactst where i <> 0; -vacuum (FULL) vactst; +vacuum (full) vactst; delete from vactst; select * from vactst; -vacuum (FULL, FREEZE) vactst; +vacuum (full, freeze) vactst; -vacuum (ANALYZE, FULL) vactst; +vacuum (analyze, full) vactst; create table vaccluster (i int primary key); @@ -89,17 +89,13 @@ create function do_analyze() returns void language sql volatile -as $function$ -ANALYZE pg_am -$function$; +as 'ANALYZE pg_am'; create function wrap_do_analyze(c int) returns int language sql immutable -as $function$ -SELECT $1 FROM public.do_analyze() -$function$; +as 'SELECT $1 FROM public.do_analyze()'; create index on vaccluster using btree ((wrap_do_analyze(i))); @@ -147,7 +143,7 @@ commit; begin; create table past_parted (i int) -partition by LIST(i); +partition by list(i); create table past_part partition of past_parted for values in (1); @@ -165,17 +161,17 @@ select reltuples, relhassubclass from pg_class where oid = cast('past_parted' as commit; -vacuum (FULL) pg_am; +vacuum (full) pg_am; -vacuum (FULL) pg_class; +vacuum (full) pg_class; -vacuum (FULL) pg_database; +vacuum (full) pg_database; -vacuum (FULL) vaccluster; +vacuum (full) vaccluster; -vacuum (FULL) vactst; +vacuum (full) vactst; -vacuum (DISABLE_PAGE_SKIPPING) vaccluster; +vacuum (disable_page_skipping) vaccluster; create table pvactst ( i int, @@ -186,17 +182,17 @@ with (autovacuum_enabled = off); insert into pvactst select i, array[1, 2, 3], point(i, i + 1) from generate_series(1, 1000) as i; -create index "btree_pvactst" on pvactst using btree (i); +create index btree_pvactst on pvactst using btree (i); -create index "hash_pvactst" on pvactst using hash (i); +create index hash_pvactst on pvactst using hash (i); -create index "brin_pvactst" on pvactst using brin (i); +create index brin_pvactst on pvactst using brin (i); -create index "gin_pvactst" on pvactst using gin (a); +create index gin_pvactst on pvactst using gin (a); -create index "gist_pvactst" on pvactst using gist (p); +create index gist_pvactst on pvactst using gist (p); -create index "spgist_pvactst" on pvactst using spgist (p); +create index spgist_pvactst on pvactst using spgist (p); create table pvactst2 (i int) with (autovacuum_enabled = off); @@ -208,41 +204,41 @@ create index on pvactst2 using btree (i); set min_parallel_index_scan_size = 0; -vacuum (PARALLEL 2) pvactst; +vacuum (parallel 2) pvactst; update pvactst set i = i where i < 1000; -vacuum (PARALLEL 2) pvactst; +vacuum (parallel 2) pvactst; update pvactst set i = i where i < 1000; -vacuum (PARALLEL 0) pvactst; +vacuum (parallel 0) pvactst; -vacuum (PARALLEL -1) pvactst; +vacuum (parallel -1) pvactst; -vacuum (PARALLEL 2, INDEX_CLEANUP "false") pvactst; +vacuum (parallel 2, index_cleanup "false") pvactst; -vacuum (PARALLEL 2, FULL "true") pvactst; +vacuum (parallel 2, full "true") pvactst; -vacuum (PARALLEL) pvactst; +vacuum (parallel) pvactst; set maintenance_work_mem = 64; -vacuum (PARALLEL 2) pvactst2; +vacuum (parallel 2) pvactst2; delete from pvactst2 where i < 1000; -vacuum (PARALLEL 2) pvactst2; +vacuum (parallel 2) pvactst2; reset maintenance_work_mem; create temporary table tmp (a int primary key); -create index "tmp_idx1" on tmp using btree (a); +create index tmp_idx1 on tmp using btree (a); -vacuum (PARALLEL 1, FULL "false") tmp; +vacuum (parallel 1, full "false") tmp; -vacuum (PARALLEL 0, FULL "true") tmp; +vacuum (parallel 0, full "true") tmp; reset min_parallel_index_scan_size; @@ -255,16 +251,16 @@ create table no_index_cleanup ( t text ); -create index "no_index_cleanup_idx" on no_index_cleanup using btree (t); +create index no_index_cleanup_idx on no_index_cleanup using btree (t); alter table no_index_cleanup alter column t set storage external; insert into no_index_cleanup (i, t) values (generate_series(1, 30), repeat('1234567890', 269)); -vacuum (INDEX_CLEANUP "true", FULL "true") no_index_cleanup; +vacuum (index_cleanup "true", full "true") no_index_cleanup; -vacuum (FULL "true") no_index_cleanup; +vacuum (full "true") no_index_cleanup; alter table no_index_cleanup set (vacuum_index_cleanup = 'false'); @@ -288,62 +284,57 @@ insert into no_index_cleanup (i, t) values (generate_series(31, 60), repeat('123 delete from no_index_cleanup where i < 45; alter table no_index_cleanup - set (vacuum_index_cleanup = off, - toast.vacuum_index_cleanup = yes); + set (vacuum_index_cleanup = off, toast.vacuum_index_cleanup = yes); vacuum no_index_cleanup; alter table no_index_cleanup - set (vacuum_index_cleanup = 'true', - toast.vacuum_index_cleanup = 'false'); + set (vacuum_index_cleanup = 'true', toast.vacuum_index_cleanup = 'false'); vacuum no_index_cleanup; -vacuum (INDEX_CLEANUP "false") vaccluster; +vacuum (index_cleanup "false") vaccluster; -vacuum (INDEX_CLEANUP auto) vactst; +vacuum (index_cleanup auto) vactst; -vacuum (INDEX_CLEANUP "false", FREEZE "true") vaccluster; +vacuum (index_cleanup "false", freeze "true") vaccluster; create temporary table vac_truncate_test ( i int not null, j text ) -with ( - vacuum_truncate = 'true', - autovacuum_enabled = 'false' -); +with (vacuum_truncate = 'true', autovacuum_enabled = 'false'); insert into vac_truncate_test values (1, null), (null, null); -vacuum (TRUNCATE "false", DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (truncate "false", disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') > 0; set vacuum_truncate = 'false'; -vacuum (DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') = 0; -vacuum (TRUNCATE "false", FULL "true") vac_truncate_test; +vacuum (truncate "false", full "true") vac_truncate_test; alter table vac_truncate_test reset (vacuum_truncate); insert into vac_truncate_test values (1, null), (null, null); -vacuum (DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') > 0; reset vacuum_truncate; -vacuum (TRUNCATE "false", DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (truncate "false", disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') > 0; -vacuum (DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') = 0; @@ -353,7 +344,7 @@ create table vacparted ( a int, b char(1) ) -partition by LIST(a); +partition by list(a); create table vacparted1 partition of vacparted for values in (1); @@ -361,13 +352,13 @@ insert into vacparted values (1, 'a'); update vacparted set b = 'b'; -vacuum (ANALYZE) vacparted; +vacuum (analyze) vacparted; -vacuum (FULL) vacparted; +vacuum (full) vacparted; -vacuum (FREEZE) vacparted; +vacuum (freeze) vacparted; -vacuum (ANALYZE) vacparted (a, b, a); +vacuum (analyze) vacparted (a, b, a); analyze vacparted (a, b, b); @@ -375,19 +366,19 @@ create table vacparted_i ( a int primary key, b varchar(100) ) -partition by HASH(a); +partition by hash(a); -create table vacparted_i1 partition of vacparted_i for values with (MODULUS 2, REMAINDER 0); +create table vacparted_i1 partition of vacparted_i for values with (modulus 2, remainder 0); -create table vacparted_i2 partition of vacparted_i for values with (MODULUS 2, REMAINDER 1); +create table vacparted_i2 partition of vacparted_i for values with (modulus 2, remainder 1); insert into vacparted_i select i, 'test_' || i from generate_series(1, 10) as i; -vacuum (ANALYZE) vacparted_i; +vacuum (analyze) vacparted_i; -vacuum (FULL) vacparted_i; +vacuum (full) vacparted_i; -vacuum (FREEZE) vacparted_i; +vacuum (freeze) vacparted_i; select relname, @@ -395,8 +386,7 @@ select from pg_class where - relname like 'vacparted_i%' and - relkind in ('p', 'r') + relname like 'vacparted_i%' and relkind in ('p', 'r') order by relname; drop table vacparted_i; @@ -405,17 +395,17 @@ vacuum vaccluster, vactst; vacuum vacparted, does_not_exist; -vacuum (FREEZE) vacparted, vaccluster, vactst; +vacuum (freeze) vacparted, vaccluster, vactst; -vacuum (FREEZE) does_not_exist, vaccluster; +vacuum (freeze) does_not_exist, vaccluster; -vacuum (ANALYZE) vactst, vacparted (a); +vacuum (analyze) vactst, vacparted (a); -vacuum (ANALYZE) vactst (does_not_exist), vacparted (b); +vacuum (analyze) vactst (does_not_exist), vacparted (b); -vacuum (FULL) vacparted, vactst; +vacuum (full) vacparted, vactst; -vacuum (FULL) vactst, vacparted (a, b), vaccluster (i); +vacuum (full) vactst, vacparted (a, b), vaccluster (i); analyze vactst, vacparted; @@ -437,7 +427,7 @@ create table only_parted ( a int, b text ) -partition by LIST(a); +partition by list(a); create table only_parted1 partition of only_parted for values in (1); @@ -450,10 +440,7 @@ select from pg_stat_user_tables where - relid - in ( - cast('only_parted' as regclass), cast('only_parted1' as regclass) - ) + relid in (cast('only_parted' as regclass), cast('only_parted1' as regclass)) order by relname; analyze only_parted; @@ -465,10 +452,7 @@ select from pg_stat_user_tables where - relid - in ( - cast('only_parted' as regclass), cast('only_parted1' as regclass) - ) + relid in (cast('only_parted' as regclass), cast('only_parted1' as regclass)) order by relname; drop table only_parted; @@ -490,10 +474,7 @@ select from pg_stat_user_tables where - relid - in ( - cast('only_inh_parent' as regclass), cast('only_inh_child' as regclass) - ) + relid in (cast('only_inh_parent' as regclass), cast('only_inh_child' as regclass)) order by relname; analyze only_inh_parent; @@ -505,10 +486,7 @@ select from pg_stat_user_tables where - relid - in ( - cast('only_inh_parent' as regclass), cast('only_inh_child' as regclass) - ) + relid in (cast('only_inh_parent' as regclass), cast('only_inh_child' as regclass)) order by relname; select @@ -518,10 +496,7 @@ select from pg_stat_user_tables where - relid - in ( - cast('only_inh_parent' as regclass), cast('only_inh_child' as regclass) - ) + relid in (cast('only_inh_parent' as regclass), cast('only_inh_child' as regclass)) order by relname; vacuum only_inh_parent; @@ -533,29 +508,26 @@ select from pg_stat_user_tables where - relid - in ( - cast('only_inh_parent' as regclass), cast('only_inh_child' as regclass) - ) + relid in (cast('only_inh_parent' as regclass), cast('only_inh_child' as regclass)) order by relname; drop table only_inh_parent cascade; -analyze (VERBOSE) does_not_exist; +analyze (verbose) does_not_exist; -analyze (NONEXISTENTARG) does_not_exit; +analyze (nonexistentarg) does_not_exit; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; -analyze (SKIP_LOCKED, VERBOSE) does_not_exist; +analyze (skip_locked, verbose) does_not_exist; -analyze (VERBOSE, SKIP_LOCKED) does_not_exist; +analyze (verbose, skip_locked) does_not_exist; -vacuum (SKIP_LOCKED) vactst; +vacuum (skip_locked) vactst; -vacuum (SKIP_LOCKED, FULL) vactst; +vacuum (skip_locked, full) vactst; -analyze (SKIP_LOCKED) vactst; +analyze (skip_locked) vactst; reset client_min_messages; @@ -585,37 +557,29 @@ alter table vac_option_tab create view vac_option_tab_counts as select - case - when c.relname is null then 'main' - else 'toast' - end - as rel, + case when c.relname is null then 'main' else 'toast' end as rel, s.vacuum_count from - pg_stat_all_tables as s - left outer join - pg_class as c - on s.relid = c.reltoastrelid + pg_stat_all_tables as s left outer join pg_class as c on s.relid = c.reltoastrelid where - c.relname = 'vac_option_tab' or - s.relname = 'vac_option_tab' + c.relname = 'vac_option_tab' or s.relname = 'vac_option_tab' order by rel; -vacuum (PROCESS_TOAST "true") vac_option_tab; +vacuum (process_toast "true") vac_option_tab; select * from vac_option_tab_counts; -vacuum (PROCESS_TOAST "false") vac_option_tab; +vacuum (process_toast "false") vac_option_tab; select * from vac_option_tab_counts; -vacuum (PROCESS_TOAST "false", FULL) vac_option_tab; +vacuum (process_toast "false", full) vac_option_tab; -vacuum (PROCESS_MAIN "false") vac_option_tab; +vacuum (process_main "false") vac_option_tab; select * from vac_option_tab_counts; -vacuum (PROCESS_MAIN "false", PROCESS_TOAST "false") vac_option_tab; +vacuum (process_main "false", process_toast "false") vac_option_tab; select * from vac_option_tab_counts; @@ -627,50 +591,46 @@ from pg_class as c, pg_class as t where - c.reltoastrelid = t.oid and - c.relname = 'vac_option_tab'; + c.reltoastrelid = t.oid and c.relname = 'vac_option_tab'; -vacuum (PROCESS_MAIN "false", FULL) vac_option_tab; +vacuum (process_main "false", full) vac_option_tab; select - relfilenode = 'main_filenode' - as is_same_main_filenode + relfilenode = 'main_filenode' as is_same_main_filenode from pg_class where relname = 'vac_option_tab'; select - t.relfilenode = 'toast_filenode' - as is_same_toast_filenode + t.relfilenode = 'toast_filenode' as is_same_toast_filenode from pg_class as c, pg_class as t where - c.reltoastrelid = t.oid and - c.relname = 'vac_option_tab'; + c.reltoastrelid = t.oid and c.relname = 'vac_option_tab'; -vacuum (BUFFER_USAGE_LIMIT "512 kB") vac_option_tab; +vacuum (buffer_usage_limit "512 kB") vac_option_tab; -analyze (BUFFER_USAGE_LIMIT "512 kB") vac_option_tab; +analyze (buffer_usage_limit "512 kB") vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT 0) vac_option_tab; +vacuum (buffer_usage_limit 0) vac_option_tab; -analyze (BUFFER_USAGE_LIMIT 0) vac_option_tab; +analyze (buffer_usage_limit 0) vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT 16777220) vac_option_tab; +vacuum (buffer_usage_limit 16777220) vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT 120) vac_option_tab; +vacuum (buffer_usage_limit 120) vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT 10000000000) vac_option_tab; +vacuum (buffer_usage_limit 10000000000) vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT "512 kB", FULL) vac_option_tab; +vacuum (buffer_usage_limit "512 kB", full) vac_option_tab; -vacuum (SKIP_DATABASE_STATS) vactst; +vacuum (skip_database_stats) vactst; -vacuum (ONLY_DATABASE_STATS); +vacuum (only_database_stats); -vacuum (ONLY_DATABASE_STATS) vactst; +vacuum (only_database_stats) vactst; drop view vac_option_tab_counts; @@ -687,7 +647,7 @@ drop table no_index_cleanup; create table vacowned (a int); create table vacowned_parted (a int) -partition by LIST(a); +partition by list(a); create table vacowned_part1 partition of vacowned_parted for values in (1); @@ -701,19 +661,19 @@ vacuum vacowned; analyze vacowned; -vacuum (ANALYZE) vacowned; +vacuum (analyze) vacowned; vacuum pg_catalog.pg_class; analyze pg_catalog.pg_class; -vacuum (ANALYZE) pg_catalog.pg_class; +vacuum (analyze) pg_catalog.pg_class; vacuum pg_catalog.pg_authid; analyze pg_catalog.pg_authid; -vacuum (ANALYZE) pg_catalog.pg_authid; +vacuum (analyze) pg_catalog.pg_authid; vacuum vacowned_parted; @@ -727,11 +687,11 @@ analyze vacowned_part1; analyze vacowned_part2; -vacuum (ANALYZE) vacowned_parted; +vacuum (analyze) vacowned_parted; -vacuum (ANALYZE) vacowned_part1; +vacuum (analyze) vacowned_part1; -vacuum (ANALYZE) vacowned_part2; +vacuum (analyze) vacowned_part2; reset role; @@ -755,11 +715,11 @@ analyze vacowned_part1; analyze vacowned_part2; -vacuum (ANALYZE) vacowned_parted; +vacuum (analyze) vacowned_parted; -vacuum (ANALYZE) vacowned_part1; +vacuum (analyze) vacowned_part1; -vacuum (ANALYZE) vacowned_part2; +vacuum (analyze) vacowned_part2; reset role; @@ -780,11 +740,11 @@ analyze vacowned_part1; analyze vacowned_part2; -vacuum (ANALYZE) vacowned_parted; +vacuum (analyze) vacowned_parted; -vacuum (ANALYZE) vacowned_part1; +vacuum (analyze) vacowned_part1; -vacuum (ANALYZE) vacowned_part2; +vacuum (analyze) vacowned_part2; reset role; @@ -808,11 +768,11 @@ analyze vacowned_part1; analyze vacowned_part2; -vacuum (ANALYZE) vacowned_parted; +vacuum (analyze) vacowned_parted; -vacuum (ANALYZE) vacowned_part1; +vacuum (analyze) vacowned_part1; -vacuum (ANALYZE) vacowned_part2; +vacuum (analyze) vacowned_part2; reset role; @@ -838,20 +798,18 @@ select pg_column_toast_chunk_id(f1) as id_2_chunk from vac_rewrite_toast where i select id, - pg_column_toast_chunk_id(f1) is null - as f1_chunk_null, + pg_column_toast_chunk_id(f1) is null as f1_chunk_null, substr(f1, 5, 10) as f1_data, pg_column_compression(f1) as f1_comp from vac_rewrite_toast order by id; -vacuum (FULL) vac_rewrite_toast; +vacuum (full) vac_rewrite_toast; select id, - pg_column_toast_chunk_id(f1) is null - as f1_chunk_null, + pg_column_toast_chunk_id(f1) is null as f1_chunk_null, substr(f1, 5, 10) as f1_data, pg_column_compression(f1) as f1_comp from @@ -859,8 +817,7 @@ from order by id; select - pg_column_toast_chunk_id(f1) = 'id_2_chunk' - as same_chunk + pg_column_toast_chunk_id(f1) = 'id_2_chunk' as same_chunk from vac_rewrite_toast where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_80.snap index 3e9ff128c..6cf2c8388 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_80.snap @@ -30,13 +30,13 @@ insert into vactst select * from vactst; insert into vactst values (0); -select COUNT(*) from vactst; +select count(*) from vactst; delete from vactst where i <> 0; select * from vactst; -vacuum (FULL) vactst; +vacuum (full) vactst; update vactst set i = i + 1; @@ -64,19 +64,19 @@ insert into vactst select * from vactst; insert into vactst values (0); -select COUNT(*) from vactst; +select count(*) from vactst; delete from vactst where i <> 0; -vacuum (FULL) vactst; +vacuum (full) vactst; delete from vactst; select * from vactst; -vacuum (FULL, FREEZE) vactst; +vacuum (full, freeze) vactst; -vacuum (ANALYZE, FULL) vactst; +vacuum (analyze, full) vactst; create table vaccluster (i int primary key); @@ -89,17 +89,13 @@ create function do_analyze() returns void language sql volatile -as $function$ -ANALYZE pg_am -$function$; +as 'ANALYZE pg_am'; create function wrap_do_analyze(c int) returns int language sql immutable -as $function$ -SELECT $1 FROM public.do_analyze() -$function$; +as 'SELECT $1 FROM public.do_analyze()'; create index on vaccluster using btree ((wrap_do_analyze(i))); @@ -140,8 +136,7 @@ select from pg_class where - oid = - cast('past_inh_parent' as regclass); + oid = cast('past_inh_parent' as regclass); drop table past_inh_child; @@ -153,15 +148,14 @@ select from pg_class where - oid = - cast('past_inh_parent' as regclass); + oid = cast('past_inh_parent' as regclass); commit; begin; create table past_parted (i int) -partition by LIST(i); +partition by list(i); create table past_part partition of past_parted for values in (1); @@ -191,17 +185,17 @@ where commit; -vacuum (FULL) pg_am; +vacuum (full) pg_am; -vacuum (FULL) pg_class; +vacuum (full) pg_class; -vacuum (FULL) pg_database; +vacuum (full) pg_database; -vacuum (FULL) vaccluster; +vacuum (full) vaccluster; -vacuum (FULL) vactst; +vacuum (full) vactst; -vacuum (DISABLE_PAGE_SKIPPING) vaccluster; +vacuum (disable_page_skipping) vaccluster; create table pvactst ( i int, @@ -211,24 +205,19 @@ create table pvactst ( with (autovacuum_enabled = off); insert into pvactst -select - i, - array[1, 2, 3], - point(i, i + 1) -from - generate_series(1, 1000) as i; +select i, array[1, 2, 3], point(i, i + 1) from generate_series(1, 1000) as i; -create index "btree_pvactst" on pvactst using btree (i); +create index btree_pvactst on pvactst using btree (i); -create index "hash_pvactst" on pvactst using hash (i); +create index hash_pvactst on pvactst using hash (i); -create index "brin_pvactst" on pvactst using brin (i); +create index brin_pvactst on pvactst using brin (i); -create index "gin_pvactst" on pvactst using gin (a); +create index gin_pvactst on pvactst using gin (a); -create index "gist_pvactst" on pvactst using gist (p); +create index gist_pvactst on pvactst using gist (p); -create index "spgist_pvactst" on pvactst using spgist (p); +create index spgist_pvactst on pvactst using spgist (p); create table pvactst2 (i int) with (autovacuum_enabled = off); @@ -240,41 +229,41 @@ create index on pvactst2 using btree (i); set min_parallel_index_scan_size = 0; -vacuum (PARALLEL 2) pvactst; +vacuum (parallel 2) pvactst; update pvactst set i = i where i < 1000; -vacuum (PARALLEL 2) pvactst; +vacuum (parallel 2) pvactst; update pvactst set i = i where i < 1000; -vacuum (PARALLEL 0) pvactst; +vacuum (parallel 0) pvactst; -vacuum (PARALLEL -1) pvactst; +vacuum (parallel -1) pvactst; -vacuum (PARALLEL 2, INDEX_CLEANUP "false") pvactst; +vacuum (parallel 2, index_cleanup "false") pvactst; -vacuum (PARALLEL 2, FULL "true") pvactst; +vacuum (parallel 2, full "true") pvactst; -vacuum (PARALLEL) pvactst; +vacuum (parallel) pvactst; set maintenance_work_mem = 64; -vacuum (PARALLEL 2) pvactst2; +vacuum (parallel 2) pvactst2; delete from pvactst2 where i < 1000; -vacuum (PARALLEL 2) pvactst2; +vacuum (parallel 2) pvactst2; reset maintenance_work_mem; create temporary table tmp (a int primary key); -create index "tmp_idx1" on tmp using btree (a); +create index tmp_idx1 on tmp using btree (a); -vacuum (PARALLEL 1, FULL "false") tmp; +vacuum (parallel 1, full "false") tmp; -vacuum (PARALLEL 0, FULL "true") tmp; +vacuum (parallel 0, full "true") tmp; reset min_parallel_index_scan_size; @@ -287,21 +276,17 @@ create table no_index_cleanup ( t text ); -create index "no_index_cleanup_idx" on no_index_cleanup using btree (t); +create index no_index_cleanup_idx on no_index_cleanup using btree (t); alter table no_index_cleanup alter column t set storage external; insert into no_index_cleanup (i, t) -values - ( - generate_series(1, 30), - repeat('1234567890', 269) - ); +values (generate_series(1, 30), repeat('1234567890', 269)); -vacuum (INDEX_CLEANUP "true", FULL "true") no_index_cleanup; +vacuum (index_cleanup "true", full "true") no_index_cleanup; -vacuum (FULL "true") no_index_cleanup; +vacuum (full "true") no_index_cleanup; alter table no_index_cleanup set (vacuum_index_cleanup = 'false'); @@ -321,71 +306,62 @@ alter table no_index_cleanup vacuum no_index_cleanup; insert into no_index_cleanup (i, t) -values - ( - generate_series(31, 60), - repeat('1234567890', 269) - ); +values (generate_series(31, 60), repeat('1234567890', 269)); delete from no_index_cleanup where i < 45; alter table no_index_cleanup - set (vacuum_index_cleanup = off, - toast.vacuum_index_cleanup = yes); + set (vacuum_index_cleanup = off, toast.vacuum_index_cleanup = yes); vacuum no_index_cleanup; alter table no_index_cleanup - set (vacuum_index_cleanup = 'true', - toast.vacuum_index_cleanup = 'false'); + set (vacuum_index_cleanup = 'true', toast.vacuum_index_cleanup = 'false'); vacuum no_index_cleanup; -vacuum (INDEX_CLEANUP "false") vaccluster; +vacuum (index_cleanup "false") vaccluster; -vacuum (INDEX_CLEANUP auto) vactst; +vacuum (index_cleanup auto) vactst; -vacuum (INDEX_CLEANUP "false", FREEZE "true") vaccluster; +vacuum (index_cleanup "false", freeze "true") vaccluster; create temporary table vac_truncate_test ( i int not null, j text ) -with ( - vacuum_truncate = 'true', - autovacuum_enabled = 'false' -); +with (vacuum_truncate = 'true', autovacuum_enabled = 'false'); insert into vac_truncate_test values (1, null), (null, null); -vacuum (TRUNCATE "false", DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (truncate "false", disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') > 0; set vacuum_truncate = 'false'; -vacuum (DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') = 0; -vacuum (TRUNCATE "false", FULL "true") vac_truncate_test; +vacuum (truncate "false", full "true") vac_truncate_test; alter table vac_truncate_test reset (vacuum_truncate); insert into vac_truncate_test values (1, null), (null, null); -vacuum (DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') > 0; reset vacuum_truncate; -vacuum (TRUNCATE "false", DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (truncate "false", disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') > 0; -vacuum (DISABLE_PAGE_SKIPPING) vac_truncate_test; +vacuum (disable_page_skipping) vac_truncate_test; select pg_relation_size('vac_truncate_test') = 0; @@ -395,7 +371,7 @@ create table vacparted ( a int, b char(1) ) -partition by LIST(a); +partition by list(a); create table vacparted1 partition of vacparted for values in (1); @@ -403,13 +379,13 @@ insert into vacparted values (1, 'a'); update vacparted set b = 'b'; -vacuum (ANALYZE) vacparted; +vacuum (analyze) vacparted; -vacuum (FULL) vacparted; +vacuum (full) vacparted; -vacuum (FREEZE) vacparted; +vacuum (freeze) vacparted; -vacuum (ANALYZE) vacparted (a, b, a); +vacuum (analyze) vacparted (a, b, a); analyze vacparted (a, b, b); @@ -417,23 +393,23 @@ create table vacparted_i ( a int primary key, b varchar(100) ) -partition by HASH(a); +partition by hash(a); create table vacparted_i1 partition of vacparted_i -for values with (MODULUS 2, REMAINDER 0); +for values with (modulus 2, remainder 0); create table vacparted_i2 partition of vacparted_i -for values with (MODULUS 2, REMAINDER 1); +for values with (modulus 2, remainder 1); insert into vacparted_i select i, 'test_' || i from generate_series(1, 10) as i; -vacuum (ANALYZE) vacparted_i; +vacuum (analyze) vacparted_i; -vacuum (FULL) vacparted_i; +vacuum (full) vacparted_i; -vacuum (FREEZE) vacparted_i; +vacuum (freeze) vacparted_i; select relname, @@ -441,8 +417,7 @@ select from pg_class where - relname like 'vacparted_i%' and - relkind in ('p', 'r') + relname like 'vacparted_i%' and relkind in ('p', 'r') order by relname; drop table vacparted_i; @@ -451,17 +426,17 @@ vacuum vaccluster, vactst; vacuum vacparted, does_not_exist; -vacuum (FREEZE) vacparted, vaccluster, vactst; +vacuum (freeze) vacparted, vaccluster, vactst; -vacuum (FREEZE) does_not_exist, vaccluster; +vacuum (freeze) does_not_exist, vaccluster; -vacuum (ANALYZE) vactst, vacparted (a); +vacuum (analyze) vactst, vacparted (a); -vacuum (ANALYZE) vactst (does_not_exist), vacparted (b); +vacuum (analyze) vactst (does_not_exist), vacparted (b); -vacuum (FULL) vacparted, vactst; +vacuum (full) vacparted, vactst; -vacuum (FULL) vactst, vacparted (a, b), vaccluster (i); +vacuum (full) vactst, vacparted (a, b), vaccluster (i); analyze vactst, vacparted; @@ -483,7 +458,7 @@ create table only_parted ( a int, b text ) -partition by LIST(a); +partition by list(a); create table only_parted1 partition of only_parted for values in (1); @@ -496,10 +471,7 @@ select from pg_stat_user_tables where - relid - in ( - cast('only_parted' as regclass), cast('only_parted1' as regclass) - ) + relid in (cast('only_parted' as regclass), cast('only_parted1' as regclass)) order by relname; analyze only_parted; @@ -511,10 +483,7 @@ select from pg_stat_user_tables where - relid - in ( - cast('only_parted' as regclass), cast('only_parted1' as regclass) - ) + relid in (cast('only_parted' as regclass), cast('only_parted1' as regclass)) order by relname; drop table only_parted; @@ -587,21 +556,21 @@ order by relname; drop table only_inh_parent cascade; -analyze (VERBOSE) does_not_exist; +analyze (verbose) does_not_exist; -analyze (NONEXISTENTARG) does_not_exit; +analyze (nonexistentarg) does_not_exit; -set client_min_messages = ERROR; +set client_min_messages = 'ERROR'; -analyze (SKIP_LOCKED, VERBOSE) does_not_exist; +analyze (skip_locked, verbose) does_not_exist; -analyze (VERBOSE, SKIP_LOCKED) does_not_exist; +analyze (verbose, skip_locked) does_not_exist; -vacuum (SKIP_LOCKED) vactst; +vacuum (skip_locked) vactst; -vacuum (SKIP_LOCKED, FULL) vactst; +vacuum (skip_locked, full) vactst; -analyze (SKIP_LOCKED) vactst; +analyze (skip_locked) vactst; reset client_min_messages; @@ -631,11 +600,7 @@ alter table vac_option_tab create view vac_option_tab_counts as select - case - when c.relname is null then 'main' - else 'toast' - end - as rel, + case when c.relname is null then 'main' else 'toast' end as rel, s.vacuum_count from pg_stat_all_tables as s @@ -643,25 +608,24 @@ from pg_class as c on s.relid = c.reltoastrelid where - c.relname = 'vac_option_tab' or - s.relname = 'vac_option_tab' + c.relname = 'vac_option_tab' or s.relname = 'vac_option_tab' order by rel; -vacuum (PROCESS_TOAST "true") vac_option_tab; +vacuum (process_toast "true") vac_option_tab; select * from vac_option_tab_counts; -vacuum (PROCESS_TOAST "false") vac_option_tab; +vacuum (process_toast "false") vac_option_tab; select * from vac_option_tab_counts; -vacuum (PROCESS_TOAST "false", FULL) vac_option_tab; +vacuum (process_toast "false", full) vac_option_tab; -vacuum (PROCESS_MAIN "false") vac_option_tab; +vacuum (process_main "false") vac_option_tab; select * from vac_option_tab_counts; -vacuum (PROCESS_MAIN "false", PROCESS_TOAST "false") vac_option_tab; +vacuum (process_main "false", process_toast "false") vac_option_tab; select * from vac_option_tab_counts; @@ -678,50 +642,46 @@ from pg_class as c, pg_class as t where - c.reltoastrelid = t.oid and - c.relname = 'vac_option_tab'; + c.reltoastrelid = t.oid and c.relname = 'vac_option_tab'; -vacuum (PROCESS_MAIN "false", FULL) vac_option_tab; +vacuum (process_main "false", full) vac_option_tab; select - relfilenode = 'main_filenode' - as is_same_main_filenode + relfilenode = 'main_filenode' as is_same_main_filenode from pg_class where relname = 'vac_option_tab'; select - t.relfilenode = 'toast_filenode' - as is_same_toast_filenode + t.relfilenode = 'toast_filenode' as is_same_toast_filenode from pg_class as c, pg_class as t where - c.reltoastrelid = t.oid and - c.relname = 'vac_option_tab'; + c.reltoastrelid = t.oid and c.relname = 'vac_option_tab'; -vacuum (BUFFER_USAGE_LIMIT "512 kB") vac_option_tab; +vacuum (buffer_usage_limit "512 kB") vac_option_tab; -analyze (BUFFER_USAGE_LIMIT "512 kB") vac_option_tab; +analyze (buffer_usage_limit "512 kB") vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT 0) vac_option_tab; +vacuum (buffer_usage_limit 0) vac_option_tab; -analyze (BUFFER_USAGE_LIMIT 0) vac_option_tab; +analyze (buffer_usage_limit 0) vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT 16777220) vac_option_tab; +vacuum (buffer_usage_limit 16777220) vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT 120) vac_option_tab; +vacuum (buffer_usage_limit 120) vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT 10000000000) vac_option_tab; +vacuum (buffer_usage_limit 10000000000) vac_option_tab; -vacuum (BUFFER_USAGE_LIMIT "512 kB", FULL) vac_option_tab; +vacuum (buffer_usage_limit "512 kB", full) vac_option_tab; -vacuum (SKIP_DATABASE_STATS) vactst; +vacuum (skip_database_stats) vactst; -vacuum (ONLY_DATABASE_STATS); +vacuum (only_database_stats); -vacuum (ONLY_DATABASE_STATS) vactst; +vacuum (only_database_stats) vactst; drop view vac_option_tab_counts; @@ -738,7 +698,7 @@ drop table no_index_cleanup; create table vacowned (a int); create table vacowned_parted (a int) -partition by LIST(a); +partition by list(a); create table vacowned_part1 partition of vacowned_parted for values in (1); @@ -752,19 +712,19 @@ vacuum vacowned; analyze vacowned; -vacuum (ANALYZE) vacowned; +vacuum (analyze) vacowned; vacuum pg_catalog.pg_class; analyze pg_catalog.pg_class; -vacuum (ANALYZE) pg_catalog.pg_class; +vacuum (analyze) pg_catalog.pg_class; vacuum pg_catalog.pg_authid; analyze pg_catalog.pg_authid; -vacuum (ANALYZE) pg_catalog.pg_authid; +vacuum (analyze) pg_catalog.pg_authid; vacuum vacowned_parted; @@ -778,11 +738,11 @@ analyze vacowned_part1; analyze vacowned_part2; -vacuum (ANALYZE) vacowned_parted; +vacuum (analyze) vacowned_parted; -vacuum (ANALYZE) vacowned_part1; +vacuum (analyze) vacowned_part1; -vacuum (ANALYZE) vacowned_part2; +vacuum (analyze) vacowned_part2; reset role; @@ -806,11 +766,11 @@ analyze vacowned_part1; analyze vacowned_part2; -vacuum (ANALYZE) vacowned_parted; +vacuum (analyze) vacowned_parted; -vacuum (ANALYZE) vacowned_part1; +vacuum (analyze) vacowned_part1; -vacuum (ANALYZE) vacowned_part2; +vacuum (analyze) vacowned_part2; reset role; @@ -831,11 +791,11 @@ analyze vacowned_part1; analyze vacowned_part2; -vacuum (ANALYZE) vacowned_parted; +vacuum (analyze) vacowned_parted; -vacuum (ANALYZE) vacowned_part1; +vacuum (analyze) vacowned_part1; -vacuum (ANALYZE) vacowned_part2; +vacuum (analyze) vacowned_part2; reset role; @@ -859,11 +819,11 @@ analyze vacowned_part1; analyze vacowned_part2; -vacuum (ANALYZE) vacowned_parted; +vacuum (analyze) vacowned_parted; -vacuum (ANALYZE) vacowned_part1; +vacuum (analyze) vacowned_part1; -vacuum (ANALYZE) vacowned_part2; +vacuum (analyze) vacowned_part2; reset role; @@ -886,8 +846,7 @@ alter table vac_rewrite_toast insert into vac_rewrite_toast values (2, repeat('a', 7000)); select - pg_column_toast_chunk_id(f1) - as id_2_chunk + pg_column_toast_chunk_id(f1) as id_2_chunk from vac_rewrite_toast where @@ -895,20 +854,18 @@ where select id, - pg_column_toast_chunk_id(f1) is null - as f1_chunk_null, + pg_column_toast_chunk_id(f1) is null as f1_chunk_null, substr(f1, 5, 10) as f1_data, pg_column_compression(f1) as f1_comp from vac_rewrite_toast order by id; -vacuum (FULL) vac_rewrite_toast; +vacuum (full) vac_rewrite_toast; select id, - pg_column_toast_chunk_id(f1) is null - as f1_chunk_null, + pg_column_toast_chunk_id(f1) is null as f1_chunk_null, substr(f1, 5, 10) as f1_data, pg_column_compression(f1) as f1_comp from @@ -916,9 +873,7 @@ from order by id; select - pg_column_toast_chunk_id(f1) = - 'id_2_chunk' - as same_chunk + pg_column_toast_chunk_id(f1) = 'id_2_chunk' as same_chunk from vac_rewrite_toast where diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_parallel_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_parallel_100.snap index 8fe33bb00..7d1f761a4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_parallel_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_parallel_100.snap @@ -10,11 +10,11 @@ create table parallel_vacuum_table (a int) with (autovacuum_enabled = off); insert into parallel_vacuum_table select i from generate_series(1, 10000) as i; -create index "regular_sized_index" on parallel_vacuum_table using btree (a); +create index regular_sized_index on parallel_vacuum_table using btree (a); -create index "typically_sized_index" on parallel_vacuum_table using btree (a); +create index typically_sized_index on parallel_vacuum_table using btree (a); -create index "vacuum_in_leader_small_index" on parallel_vacuum_table using btree ((1)); +create index vacuum_in_leader_small_index on parallel_vacuum_table using btree ((1)); select exists @@ -24,32 +24,22 @@ select from pg_class where - oid = - cast('vacuum_in_leader_small_index' as regclass) and - pg_relation_size(oid) < - pg_size_bytes( - current_setting('min_parallel_index_scan_size') - ) + oid = cast('vacuum_in_leader_small_index' as regclass) and + pg_relation_size(oid) < pg_size_bytes(current_setting('min_parallel_index_scan_size')) ) as leader_will_handle_small_index; select - COUNT(*) as trigger_parallel_vacuum_nindexes + count(*) as trigger_parallel_vacuum_nindexes from pg_class where - oid - in ( - cast('regular_sized_index' as regclass), cast('typically_sized_index' as regclass) - ) and - pg_relation_size(oid) >= - pg_size_bytes( - current_setting('min_parallel_index_scan_size') - ); + oid in (cast('regular_sized_index' as regclass), cast('typically_sized_index' as regclass)) and + pg_relation_size(oid) >= pg_size_bytes(current_setting('min_parallel_index_scan_size')); delete from parallel_vacuum_table; -vacuum (PARALLEL 4, INDEX_CLEANUP "on") parallel_vacuum_table; +vacuum (parallel 4, index_cleanup "on") parallel_vacuum_table; insert into parallel_vacuum_table select i from generate_series(1, 10000) as i; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_parallel_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_parallel_80.snap index ca07d69d9..283a4acf0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_parallel_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_parallel_80.snap @@ -11,14 +11,11 @@ create table parallel_vacuum_table (a int) with (autovacuum_enabled = off); insert into parallel_vacuum_table select i from generate_series(1, 10000) as i; -create index "regular_sized_index" on parallel_vacuum_table using btree (a); +create index regular_sized_index on parallel_vacuum_table using btree (a); -create index "typically_sized_index" on parallel_vacuum_table using btree (a); +create index typically_sized_index on parallel_vacuum_table using btree (a); -create index "vacuum_in_leader_small_index" -on parallel_vacuum_table -using btree -( +create index vacuum_in_leader_small_index on parallel_vacuum_table using btree ( (1) ); @@ -30,40 +27,28 @@ select from pg_class where - oid = - cast('vacuum_in_leader_small_index' - as regclass) and + oid = cast('vacuum_in_leader_small_index' as regclass) and pg_relation_size(oid) < - pg_size_bytes( - current_setting( - 'min_parallel_index_scan_size' - ) - ) + pg_size_bytes(current_setting('min_parallel_index_scan_size')) ) as leader_will_handle_small_index; select - COUNT(*) - as trigger_parallel_vacuum_nindexes + count(*) as trigger_parallel_vacuum_nindexes from pg_class where oid in ( cast('regular_sized_index' as regclass), - cast('typically_sized_index' - as regclass) + cast('typically_sized_index' as regclass) ) and pg_relation_size(oid) >= - pg_size_bytes( - current_setting( - 'min_parallel_index_scan_size' - ) - ); + pg_size_bytes(current_setting('min_parallel_index_scan_size')); delete from parallel_vacuum_table; -vacuum (PARALLEL 4, INDEX_CLEANUP "on") parallel_vacuum_table; +vacuum (parallel 4, index_cleanup "on") parallel_vacuum_table; insert into parallel_vacuum_table select i from generate_series(1, 10000) as i; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_100.snap index 015f2d715..750007808 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_100.snap @@ -26,19 +26,19 @@ select depname, empno, salary, - SUM(salary) over (partition by depname) + sum(salary) over (partition by depname) from empsalary order by depname, salary; -select depname, empno, salary, RANK() over (partition by depname order by salary) from empsalary; +select depname, empno, salary, rank() over (partition by depname order by salary) from empsalary; select four, ten, - SUM(SUM(four)) over (partition by four), - AVG(ten) + sum(sum(four)) over (partition by four), + avg(ten) from tenk1 group by four, @@ -46,13 +46,13 @@ group by four, order by four, ten; -select depname, empno, salary, SUM(salary) over w from empsalary window w as (partition by depname); +select depname, empno, salary, sum(salary) over w from empsalary window w as (partition by depname); select depname, empno, salary, - RANK() over w + rank() over w from empsalary window @@ -60,16 +60,16 @@ window partition by depname order by salary ) -order by RANK() over w; +order by rank() over w; -select COUNT(*) over () from tenk1 where unique2 < 10; +select count(*) over () from tenk1 where unique2 < 10; -select COUNT(*) over w from tenk1 where unique2 < 10 window w as (); +select count(*) over w from tenk1 where unique2 < 10 window w as (); select four from tenk1 where false window w as (partition by ten); select - SUM(four) over (partition by ten order by unique2) as sum_1, + sum(four) over (partition by ten order by unique2) as sum_1, ten, four from @@ -77,10 +77,10 @@ from where unique2 < 10; -select ROW_NUMBER() over (order by unique2) from tenk1 where unique2 < 10; +select row_number() over (order by unique2) from tenk1 where unique2 < 10; select - RANK() over (partition by four order by ten) as rank_1, + rank() over (partition by four order by ten) as rank_1, ten, four from @@ -88,10 +88,10 @@ from where unique2 < 10; -select DENSE_RANK() over (partition by four order by ten), ten, four from tenk1 where unique2 < 10; +select dense_rank() over (partition by four order by ten), ten, four from tenk1 where unique2 < 10; select - PERCENT_RANK() over (partition by four order by ten), + percent_rank() over (partition by four order by ten), ten, four from @@ -99,16 +99,16 @@ from where unique2 < 10; -select CUME_DIST() over (partition by four order by ten), ten, four from tenk1 where unique2 < 10; +select cume_dist() over (partition by four order by ten), ten, four from tenk1 where unique2 < 10; -select NTILE(3) over (order by ten, four), ten, four from tenk1 where unique2 < 10; +select ntile(3) over (order by ten, four), ten, four from tenk1 where unique2 < 10; -select NTILE(null) over (order by ten, four), ten, four from tenk1 limit 2; +select ntile(null) over (order by ten, four), ten, four from tenk1 limit 2; -select LAG(ten) over (partition by four order by ten), ten, four from tenk1 where unique2 < 10; +select lag(ten) over (partition by four order by ten), ten, four from tenk1 where unique2 < 10; select - LAG(ten, four) over (partition by four order by ten), + lag(ten, four) over (partition by four order by ten), ten, four from @@ -117,7 +117,7 @@ where unique2 < 10; select - LAG(ten, four, 0) over (partition by four order by ten), + lag(ten, four, 0) over (partition by four order by ten), ten, four from @@ -126,7 +126,7 @@ where unique2 < 10; select - LAG(ten, four, 0.7) over (partition by four order by ten), + lag(ten, four, 0.7) over (partition by four order by ten), ten, four from @@ -136,10 +136,10 @@ where order by four, ten; -select LEAD(ten) over (partition by four order by ten), ten, four from tenk1 where unique2 < 10; +select lead(ten) over (partition by four order by ten), ten, four from tenk1 where unique2 < 10; select - LEAD(ten * 2, 1) over (partition by four order by ten), + lead(ten * 2, 1) over (partition by four order by ten), ten, four from @@ -148,7 +148,7 @@ where unique2 < 10; select - LEAD(ten * 2, 1, -1) over (partition by four order by ten), + lead(ten * 2, 1, -1) over (partition by four order by ten), ten, four from @@ -157,7 +157,7 @@ where unique2 < 10; select - LEAD(ten * 2, 1, -1.4) over (partition by four order by ten), + lead(ten * 2, 1, -1.4) over (partition by four order by ten), ten, four from @@ -168,7 +168,7 @@ order by four, ten; select - FIRST_VALUE(ten) over (partition by four order by ten), + first_value(ten) over (partition by four order by ten), ten, four from @@ -176,56 +176,36 @@ from where unique2 < 10; -select LAST_VALUE(four) over (order by ten), ten, four from tenk1 where unique2 < 10; +select last_value(four) over (order by ten), ten, four from tenk1 where unique2 < 10; select - LAST_VALUE(ten) over (partition by four), + last_value(ten) over (partition by four), ten, four from - ( - select - * - from - tenk1 - where - unique2 < 10 - order by four, - ten - ) - as s + (select * from tenk1 where unique2 < 10 order by four, ten) as s order by four, ten; select - NTH_VALUE(ten, four + 1) over (partition by four), + nth_value(ten, four + 1) over (partition by four), ten, four from - ( - select - * - from - tenk1 - where - unique2 < 10 - order by four, - ten - ) - as s; + (select * from tenk1 where unique2 < 10 order by four, ten) as s; select ten, two, - SUM(hundred) as gsum, - SUM(SUM(hundred)) over (partition by two order by ten) as wsum + sum(hundred) as gsum, + sum(sum(hundred)) over (partition by two order by ten) as wsum from tenk1 group by ten, two; select - COUNT(*) over (partition by four), + count(*) over (partition by four), four from (select * from tenk1 where two = 1) as s @@ -233,8 +213,8 @@ where unique2 < 10; select - cast(COUNT(*) over (partition by four order by ten) + - SUM(hundred) over (partition by four order by ten) + cast(count(*) over (partition by four order by ten) + + sum(hundred) over (partition by four order by ten) as varchar) as cntsum from @@ -247,10 +227,10 @@ select from ( select - COUNT(*) over (partition by four order by ten) + - SUM(hundred) over (partition by two order by ten) as total, - COUNT(*) over (partition by four order by ten) as fourcount, - SUM(hundred) over (partition by two order by ten) as twosum + count(*) over (partition by four order by ten) + + sum(hundred) over (partition by two order by ten) as total, + count(*) over (partition by four order by ten) as fourcount, + sum(hundred) over (partition by two order by ten) as twosum from tenk1 ) @@ -258,13 +238,13 @@ from where total <> fourcount + twosum; -select AVG(four) over (partition by four order by thousand / 100) from tenk1 where unique2 < 10; +select avg(four) over (partition by four order by thousand / 100) from tenk1 where unique2 < 10; select ten, two, - SUM(hundred) as gsum, - SUM(SUM(hundred)) over win as wsum + sum(hundred) as gsum, + sum(sum(hundred)) over win as wsum from tenk1 group by ten, @@ -276,16 +256,16 @@ window ); select - SUM(salary), - ROW_NUMBER() over (order by depname), - SUM(SUM(salary)) over (order by depname desc) + sum(salary), + row_number() over (order by depname), + sum(sum(salary)) over (order by depname desc) from empsalary group by depname; select - SUM(salary) over w1, - COUNT(*) over w2 + sum(salary) over w1, + count(*) over w2 from empsalary window @@ -297,20 +277,17 @@ window ); select - LEAD( - ten, - (select two from tenk1 where s.unique2 = unique2) - ) over (partition by four order by ten) + lead(ten, (select two from tenk1 where s.unique2 = unique2)) over (partition by four order by ten) from tenk1 as s where unique2 < 10; -select COUNT(*) over (partition by four) from (select * from tenk1 where false) as s; +select count(*) over (partition by four) from (select * from tenk1 where false) as s; select - SUM(salary) over w, - RANK() over w + sum(salary) over w, + rank() over w from empsalary window @@ -325,81 +302,58 @@ select salary, bonus, depadj, - MIN(bonus) over (order by empno), - MAX(depadj) over () + min(bonus) over (order by empno), + max(depadj) over () from ( select *, - case - when enroll_date < '2008-01-01' - then 2008 - EXTRACT('year' from enroll_date) - end * - 500 + case when enroll_date < '2008-01-01' then 2008 - extract(year from enroll_date) end * 500 as bonus, - case - when AVG(salary) over (partition by depname) < salary - then 200 - end - as depadj + case when avg(salary) over (partition by depname) < salary then 200 end as depadj from empsalary ) as s; -select SUM(COUNT(f1)) over () from int4_tbl where f1 = 42; +select sum(count(f1)) over () from int4_tbl where f1 = 42; select ten, - SUM(unique1) + SUM(unique2) as res, - RANK() over (order by SUM(unique1) + SUM(unique2)) as rank + sum(unique1) + sum(unique2) as res, + rank() over (order by sum(unique1) + sum(unique2)) as rank from tenk1 group by ten order by ten; select - FIRST_VALUE(MAX(x)) over (), + first_value(max(x)) over (), y from - ( - select unique1 as x, ten + four as y from tenk1 - ) - as ss + (select unique1 as x, ten + four as y from tenk1) as ss group by y; select x, - LAG(x, 1) over (order by x), - LEAD(x, 3) over (order by x) + lag(x, 1) over (order by x), + lead(x, 3) over (order by x) from - ( - select - cast(x as numeric) as x - from - generate_series(1, 10) as x - ); + (select cast(x as numeric) as x from generate_series(1, 10) as x); select four, ten, - SUM(ten) over (partition by four order by ten), - LAST_VALUE(ten) over (partition by four order by ten) + sum(ten) over (partition by four order by ten), + last_value(ten) over (partition by four order by ten) from (select distinct ten, four from tenk1) as ss; select four, ten, - SUM(ten) over ( - partition by four - order by ten - range between - unbounded preceding - and - current row - ), - LAST_VALUE(ten) over ( + sum(ten) over (partition by four order by ten range between unbounded preceding and current row), + last_value(ten) over ( partition by four order by ten range between @@ -413,7 +367,7 @@ from select four, ten, - SUM(ten) over ( + sum(ten) over ( partition by four order by ten range between @@ -421,7 +375,7 @@ select and unbounded following ), - LAST_VALUE(ten) over ( + last_value(ten) over ( partition by four order by ten range between @@ -435,7 +389,7 @@ from select four, ten / 4 as two, - SUM(ten / 4) over ( + sum(ten / 4) over ( partition by four order by ten / 4 range between @@ -443,7 +397,7 @@ select and current row ), - LAST_VALUE(ten / 4) over ( + last_value(ten / 4) over ( partition by four order by ten / 4 range between @@ -457,7 +411,7 @@ from select four, ten / 4 as two, - SUM(ten / 4) over ( + sum(ten / 4) over ( partition by four order by ten / 4 rows between @@ -465,7 +419,7 @@ select and current row ), - LAST_VALUE(ten / 4) over ( + last_value(ten / 4) over ( partition by four order by ten / 4 rows between @@ -477,13 +431,7 @@ from (select distinct ten, four from tenk1) as ss; select - SUM(unique1) over ( - order by four - range between - current row - and - unbounded following - ), + sum(unique1) over (order by four range between current row and unbounded following), unique1, four from @@ -492,13 +440,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - current row - and - unbounded following - ), + sum(unique1) over ( rows between current row and unbounded following), unique1, four from @@ -507,7 +449,7 @@ where unique1 < 10; select - SUM(unique1) over ( rows between 2 preceding and 2 following), + sum(unique1) over ( rows between 2 preceding and 2 following), unique1, four from @@ -516,7 +458,7 @@ where unique1 < 10; select - SUM(unique1) over ( rows between 2 preceding and 2 following), + sum(unique1) over ( rows between 2 preceding and 2 following), unique1, four from @@ -525,14 +467,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 2 preceding - and - 2 following - exclude current row - ), + sum(unique1) over ( rows between 2 preceding and 2 following exclude current row), unique1, four from @@ -541,14 +476,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 2 preceding - and - 2 following - exclude group - ), + sum(unique1) over ( rows between 2 preceding and 2 following exclude group), unique1, four from @@ -557,14 +485,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 2 preceding - and - 2 following - exclude ties - ), + sum(unique1) over ( rows between 2 preceding and 2 following exclude ties), unique1, four from @@ -573,7 +494,7 @@ where unique1 < 10; select - FIRST_VALUE(unique1) over ( + first_value(unique1) over ( order by four rows between current row @@ -589,14 +510,7 @@ where unique1 < 10; select - FIRST_VALUE(unique1) over ( - order by four - rows between - current row - and - 2 following - exclude group - ), + first_value(unique1) over (order by four rows between current row and 2 following exclude group), unique1, four from @@ -605,14 +519,7 @@ where unique1 < 10; select - FIRST_VALUE(unique1) over ( - order by four - rows between - current row - and - 2 following - exclude ties - ), + first_value(unique1) over (order by four rows between current row and 2 following exclude ties), unique1, four from @@ -621,7 +528,7 @@ where unique1 < 10; select - LAST_VALUE(unique1) over ( + last_value(unique1) over ( order by four rows between current row @@ -637,14 +544,7 @@ where unique1 < 10; select - LAST_VALUE(unique1) over ( - order by four - rows between - current row - and - 2 following - exclude group - ), + last_value(unique1) over (order by four rows between current row and 2 following exclude group), unique1, four from @@ -653,14 +553,7 @@ where unique1 < 10; select - LAST_VALUE(unique1) over ( - order by four - rows between - current row - and - 2 following - exclude ties - ), + last_value(unique1) over (order by four rows between current row and 2 following exclude ties), unique1, four from @@ -669,7 +562,7 @@ where unique1 < 10; select - SUM(unique1) over ( rows between 2 preceding and 1 preceding), + sum(unique1) over ( rows between 2 preceding and 1 preceding), unique1, four from @@ -678,7 +571,7 @@ where unique1 < 10; select - SUM(unique1) over ( rows between 1 following and 3 following), + sum(unique1) over ( rows between 1 following and 3 following), unique1, four from @@ -687,13 +580,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - unbounded preceding - and - 1 following - ), + sum(unique1) over ( rows between unbounded preceding and 1 following), unique1, four from @@ -702,13 +589,7 @@ where unique1 < 10; select - SUM(unique1) over ( - w - range between - current row - and - unbounded following - ), + sum(unique1) over (w range between current row and unbounded following), unique1, four from @@ -721,14 +602,7 @@ window ); select - SUM(unique1) over ( - w - range between - unbounded preceding - and - current row - exclude current row - ), + sum(unique1) over (w range between unbounded preceding and current row exclude current row), unique1, four from @@ -741,14 +615,7 @@ window ); select - SUM(unique1) over ( - w - range between - unbounded preceding - and - current row - exclude group - ), + sum(unique1) over (w range between unbounded preceding and current row exclude group), unique1, four from @@ -761,14 +628,7 @@ window ); select - SUM(unique1) over ( - w - range between - unbounded preceding - and - current row - exclude ties - ), + sum(unique1) over (w range between unbounded preceding and current row exclude ties), unique1, four from @@ -781,9 +641,9 @@ window ); select - FIRST_VALUE(unique1) over w, - NTH_VALUE(unique1, 2) over w as nth_2, - LAST_VALUE(unique1) over w, + first_value(unique1) over w, + nth_value(unique1, 2) over w as nth_2, + last_value(unique1) over w, unique1, four from @@ -800,13 +660,10 @@ window ); select - SUM(unique1) over ( + sum(unique1) over ( order by unique1 rows - ( - select unique1 from tenk1 order by unique1 limit 1 - ) + - 1 preceding + (select unique1 from tenk1 order by unique1 limit 1) + 1 preceding ), unique1 from @@ -817,13 +674,7 @@ where create temporary view v_window as select i, - SUM(i) over ( - order by i - rows between - 1 preceding - and - 1 following - ) as sum_rows + sum(i) over (order by i rows between 1 preceding and 1 following) as sum_rows from generate_series(1, 10) as i; @@ -834,14 +685,7 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( - order by i - rows between - 1 preceding - and - 1 following - exclude current row - ) as sum_rows + sum(i) over (order by i rows between 1 preceding and 1 following exclude current row) as sum_rows from generate_series(1, 10) as i; @@ -852,14 +696,7 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( - order by i - rows between - 1 preceding - and - 1 following - exclude group - ) as sum_rows + sum(i) over (order by i rows between 1 preceding and 1 following exclude group) as sum_rows from generate_series(1, 10) as i; @@ -870,14 +707,7 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( - order by i - rows between - 1 preceding - and - 1 following - exclude ties - ) as sum_rows + sum(i) over (order by i rows between 1 preceding and 1 following exclude ties) as sum_rows from generate_series(1, 10) as i; @@ -888,13 +718,7 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( - order by i - rows between - 1 preceding - and - 1 following - ) as sum_rows + sum(i) over (order by i rows between 1 preceding and 1 following) as sum_rows from generate_series(1, 10) as i; @@ -905,13 +729,7 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( - order by i - groups between - 1 preceding - and - 1 following - ) as sum_rows + sum(i) over (order by i groups between 1 preceding and 1 following) as sum_rows from generate_series(1, 10) as i; @@ -924,30 +742,19 @@ drop view v_window; create temporary view v_window as select i, - MIN(i) over ( - order by i - range between - '1 day' preceding - and - '10 days' following - ) as min_i + min(i) over (order by i range between '1 day' preceding and '10 days' following) as min_i from - generate_series( - NOW(), - NOW() + cast('100 days' as interval), - '1 hour' - ) - as i; + generate_series(now(), now() + cast('100 days' as interval), '1 hour') as i; select pg_get_viewdef('v_window'); select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding ), unique1, four @@ -957,12 +764,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four desc range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding ), unique1, four @@ -972,12 +779,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding ), unique1, four @@ -987,12 +794,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding exclude current row ), unique1, @@ -1003,12 +810,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding exclude group ), unique1, @@ -1019,12 +826,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding exclude ties ), unique1, @@ -1035,12 +842,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(6 as smallint) following + cast(6 as int2) following exclude ties ), unique1, @@ -1051,12 +858,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(6 as smallint) following + cast(6 as int2) following exclude group ), unique1, @@ -1067,13 +874,13 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by four order by unique1 range between - cast(5 as bigint) preceding + cast(5 as int8) preceding and - cast(6 as smallint) following + cast(6 as int2) following ), unique1, four @@ -1083,13 +890,13 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by four order by unique1 range between - cast(5 as bigint) preceding + cast(5 as int8) preceding and - cast(6 as smallint) following + cast(6 as int2) following exclude current row ), unique1, @@ -1100,7 +907,7 @@ where unique1 < 10; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -1113,7 +920,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date desc range between cast('1 year' as interval) preceding @@ -1126,7 +933,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date desc range between cast('1 year' as interval) following @@ -1139,7 +946,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -1153,7 +960,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -1167,7 +974,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -1181,52 +988,22 @@ from empsalary; select - FIRST_VALUE(salary) over ( - order by salary - range between - 1000 preceding - and - 1000 following - ), - LEAD(salary) over ( - order by salary - range between - 1000 preceding - and - 1000 following - ), - NTH_VALUE(salary, 1) over ( - order by salary - range between - 1000 preceding - and - 1000 following - ), + first_value(salary) over (order by salary range between 1000 preceding and 1000 following), + lead(salary) over (order by salary range between 1000 preceding and 1000 following), + nth_value(salary, 1) over (order by salary range between 1000 preceding and 1000 following), salary from empsalary; select - LAST_VALUE(salary) over ( - order by salary - range between - 1000 preceding - and - 1000 following - ), - LAG(salary) over ( - order by salary - range between - 1000 preceding - and - 1000 following - ), + last_value(salary) over (order by salary range between 1000 preceding and 1000 following), + lag(salary) over (order by salary range between 1000 preceding and 1000 following), salary from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by salary range between 1000 following @@ -1234,15 +1011,8 @@ select 3000 following exclude current row ), - LEAD(salary) over ( - order by salary - range between - 1000 following - and - 3000 following - exclude ties - ), - NTH_VALUE(salary, 1) over ( + lead(salary) over (order by salary range between 1000 following and 3000 following exclude ties), + nth_value(salary, 1) over ( order by salary range between 1000 following @@ -1255,15 +1025,7 @@ from empsalary; select - LAST_VALUE(salary) over ( - order by salary - range between - 1000 following - and - 3000 following - exclude group - ), - LAG(salary) over ( + last_value(salary) over ( order by salary range between 1000 following @@ -1271,12 +1033,13 @@ select 3000 following exclude group ), + lag(salary) over (order by salary range between 1000 following and 3000 following exclude group), salary from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1284,7 +1047,7 @@ select cast('1 year' as interval) following exclude ties ), - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1297,7 +1060,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1305,7 +1068,7 @@ select cast('1 year' as interval) following exclude ties ), - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1319,7 +1082,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1327,7 +1090,7 @@ select cast('1 year' as interval) following exclude group ), - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1341,7 +1104,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1349,7 +1112,7 @@ select cast('1 year' as interval) following exclude current row ), - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1365,13 +1128,11 @@ from select x, y, - FIRST_VALUE(y) over w, - LAST_VALUE(y) over w + first_value(y) over w, + last_value(y) over w from ( - select x, x as y from generate_series(1, 5) as x - union all - select null, 42 + select x, x as y from generate_series(1, 5) as x union all select null, 42 union all select null, 43 ) @@ -1388,13 +1149,11 @@ window select x, y, - FIRST_VALUE(y) over w, - LAST_VALUE(y) over w + first_value(y) over w, + last_value(y) over w from ( - select x, x as y from generate_series(1, 5) as x - union all - select null, 42 + select x, x as y from generate_series(1, 5) as x union all select null, 42 union all select null, 43 ) @@ -1411,13 +1170,11 @@ window select x, y, - FIRST_VALUE(y) over w, - LAST_VALUE(y) over w + first_value(y) over w, + last_value(y) over w from ( - select x, x as y from generate_series(1, 5) as x - union all - select null, 42 + select x, x as y from generate_series(1, 5) as x union all select null, 42 union all select null, 43 ) @@ -1434,13 +1191,11 @@ window select x, y, - FIRST_VALUE(y) over w, - LAST_VALUE(y) over w + first_value(y) over w, + last_value(y) over w from ( - select x, x as y from generate_series(1, 5) as x - union all - select null, 42 + select x, x as y from generate_series(1, 5) as x union all select null, 42 union all select null, 43 ) @@ -1455,7 +1210,7 @@ window ); select - SUM(unique1) over ( rows between x preceding and x following), + sum(unique1) over ( rows between x preceding and x following), unique1, four from @@ -1472,24 +1227,18 @@ returns table ( c int ) language sql -as $function$ -SELECT sum(unique1) over (rows between x preceding and x following), +as $$ + SELECT sum(unique1) over (rows between x preceding and x following), unique1, four FROM tenk1 WHERE unique1 < 10; -$function$; +$$; select * from unbounded_syntax_test1a(2); select * from unbounded_syntax_test1b(2); select - SUM(unique1) over ( - - rows between - unbounded preceding - and - unbounded following - ), + sum(unique1) over ( rows between unbounded preceding and unbounded following), unique1, four from @@ -1506,11 +1255,11 @@ returns table ( c int ) language sql -as $function$ -SELECT sum(unique1) over (rows between unbounded preceding and unbounded following), +as $$ + SELECT sum(unique1) over (rows between unbounded preceding and unbounded following), unique1, four FROM tenk1 WHERE unique1 < 10; -$function$; +$$; select * from unbounded_syntax_test2a(2); @@ -1529,7 +1278,7 @@ immutable return x; select - SUM(unique1) over ( rows between 1 preceding and 1 following), + sum(unique1) over ( rows between 1 preceding and 1 following), unique1, four from @@ -1538,13 +1287,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - unbounded(1) preceding - and - unbounded(1) following - ), + sum(unique1) over ( rows between unbounded(1) preceding and unbounded(1) following), unique1, four from @@ -1553,13 +1296,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - unbounded.x preceding - and - unbounded.x following - ), + sum(unique1) over ( rows between unbounded.x preceding and unbounded.x following), unique1, four from @@ -1572,7 +1309,7 @@ drop function unbounded; select x, - LAST_VALUE(x) over ( + last_value(x) over ( order by cast(x as smallint) range between current row @@ -1584,7 +1321,7 @@ from select x, - LAST_VALUE(x) over ( + last_value(x) over ( order by cast(x as smallint) desc range between current row @@ -1596,64 +1333,32 @@ from select x, - LAST_VALUE(x) over ( - order by x - range between - current row - and - 4 following - ) + last_value(x) over (order by x range between current row and 4 following) from generate_series(2147483644, 2147483646) as x; select x, - LAST_VALUE(x) over ( - order by x desc - range between - current row - and - 5 following - ) + last_value(x) over (order by x desc range between current row and 5 following) from generate_series(-2147483646, -2147483644) as x; select x, - LAST_VALUE(x) over ( - order by x - range between - current row - and - 4 following - ) + last_value(x) over (order by x range between current row and 4 following) from - generate_series( - 9223372036854775804, - 9223372036854775806 - ) - as x; + generate_series(9223372036854775804, 9223372036854775806) as x; select x, - LAST_VALUE(x) over ( - order by x desc - range between - current row - and - 5 following - ) + last_value(x) over (order by x desc range between current row and 5 following) from - generate_series( - -9223372036854775806, - -9223372036854775804 - ) - as x; + generate_series(-9223372036854775806, -9223372036854775804) as x; create temporary table numerics ( id int, - f_float4 real, - f_float8 double precision, + f_float4 float4, + f_float8 float8, f_numeric numeric ); @@ -1673,8 +1378,8 @@ values select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1689,8 +1394,8 @@ window select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1699,14 +1404,14 @@ window range between 1 preceding and - cast(1.1 as real) following + cast(1.1 as float4) following ); select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1721,8 +1426,8 @@ window select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1737,8 +1442,8 @@ window select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1753,8 +1458,8 @@ window select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1769,8 +1474,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1785,8 +1490,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1795,14 +1500,14 @@ window range between 1 preceding and - cast(1.1 as double precision) following + cast(1.1 as float8) following ); select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1817,8 +1522,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1833,8 +1538,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1849,8 +1554,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1865,8 +1570,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1881,8 +1586,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1897,8 +1602,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1907,14 +1612,14 @@ window range between 1 preceding and - cast(1.1 as double precision) following + cast(1.1 as float8) following ); select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1929,8 +1634,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1945,8 +1650,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1961,8 +1666,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1977,116 +1682,32 @@ window create temporary table datetimes ( id int, f_time time, - f_timetz time with time zone, + f_timetz timetz, f_interval interval, - f_timestamptz timestamp with time zone, + f_timestamptz timestamptz, f_timestamp timestamp ); insert into datetimes values - ( - 0, - '10:00', - '10:00 BST', - '-infinity', - '-infinity', - '-infinity' - ), - ( - 1, - '11:00', - '11:00 BST', - '1 year', - '2000-10-19 10:23:54+01', - '2000-10-19 10:23:54' - ), - ( - 2, - '12:00', - '12:00 BST', - '2 years', - '2001-10-19 10:23:54+01', - '2001-10-19 10:23:54' - ), - ( - 3, - '13:00', - '13:00 BST', - '3 years', - '2001-10-19 10:23:54+01', - '2001-10-19 10:23:54' - ), - ( - 4, - '14:00', - '14:00 BST', - '4 years', - '2002-10-19 10:23:54+01', - '2002-10-19 10:23:54' - ), - ( - 5, - '15:00', - '15:00 BST', - '5 years', - '2003-10-19 10:23:54+01', - '2003-10-19 10:23:54' - ), - ( - 6, - '15:00', - '15:00 BST', - '5 years', - '2004-10-19 10:23:54+01', - '2004-10-19 10:23:54' - ), - ( - 7, - '17:00', - '17:00 BST', - '7 years', - '2005-10-19 10:23:54+01', - '2005-10-19 10:23:54' - ), - ( - 8, - '18:00', - '18:00 BST', - '8 years', - '2006-10-19 10:23:54+01', - '2006-10-19 10:23:54' - ), - ( - 9, - '19:00', - '19:00 BST', - '9 years', - '2007-10-19 10:23:54+01', - '2007-10-19 10:23:54' - ), - ( - 10, - '20:00', - '20:00 BST', - '10 years', - '2008-10-19 10:23:54+01', - '2008-10-19 10:23:54' - ), - ( - 11, - '21:00', - '21:00 BST', - 'infinity', - 'infinity', - 'infinity' - ); + (0, '10:00', '10:00 BST', '-infinity', '-infinity', '-infinity'), + (1, '11:00', '11:00 BST', '1 year', '2000-10-19 10:23:54+01', '2000-10-19 10:23:54'), + (2, '12:00', '12:00 BST', '2 years', '2001-10-19 10:23:54+01', '2001-10-19 10:23:54'), + (3, '13:00', '13:00 BST', '3 years', '2001-10-19 10:23:54+01', '2001-10-19 10:23:54'), + (4, '14:00', '14:00 BST', '4 years', '2002-10-19 10:23:54+01', '2002-10-19 10:23:54'), + (5, '15:00', '15:00 BST', '5 years', '2003-10-19 10:23:54+01', '2003-10-19 10:23:54'), + (6, '15:00', '15:00 BST', '5 years', '2004-10-19 10:23:54+01', '2004-10-19 10:23:54'), + (7, '17:00', '17:00 BST', '7 years', '2005-10-19 10:23:54+01', '2005-10-19 10:23:54'), + (8, '18:00', '18:00 BST', '8 years', '2006-10-19 10:23:54+01', '2006-10-19 10:23:54'), + (9, '19:00', '19:00 BST', '9 years', '2007-10-19 10:23:54+01', '2007-10-19 10:23:54'), + (10, '20:00', '20:00 BST', '10 years', '2008-10-19 10:23:54+01', '2008-10-19 10:23:54'), + (11, '21:00', '21:00 BST', 'infinity', 'infinity', 'infinity'); select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2101,8 +1722,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2117,8 +1738,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2133,8 +1754,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2149,8 +1770,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2165,8 +1786,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2181,8 +1802,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2197,8 +1818,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2213,8 +1834,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2229,8 +1850,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2245,8 +1866,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2261,8 +1882,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2277,8 +1898,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2293,8 +1914,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2309,8 +1930,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2325,8 +1946,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2341,8 +1962,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2357,8 +1978,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2373,8 +1994,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2389,8 +2010,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2405,8 +2026,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2421,8 +2042,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2437,8 +2058,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2453,8 +2074,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2469,8 +2090,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2485,8 +2106,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2501,8 +2122,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2517,8 +2138,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2533,8 +2154,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2549,8 +2170,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2565,8 +2186,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2581,8 +2202,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2597,8 +2218,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2613,8 +2234,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2629,8 +2250,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2643,7 +2264,7 @@ window ); select - SUM(salary) over ( + sum(salary) over ( order by enroll_date, salary range between @@ -2658,7 +2279,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( range between cast('1 year' as interval) preceding @@ -2672,7 +2293,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by depname range between cast('1 year' as interval) preceding @@ -2686,7 +2307,7 @@ from empsalary; select - MAX(enroll_date) over ( + max(enroll_date) over ( order by enroll_date range between 1 preceding @@ -2700,35 +2321,21 @@ from empsalary; select - MAX(enroll_date) over ( - order by salary - range between - -1 preceding - and - 2 following - exclude ties - ), + max(enroll_date) over (order by salary range between -1 preceding and 2 following exclude ties), salary, enroll_date from empsalary; select - MAX(enroll_date) over ( - order by salary - range between - 1 preceding - and - -2 following - exclude ties - ), + max(enroll_date) over (order by salary range between 1 preceding and -2 following exclude ties), salary, enroll_date from empsalary; select - MAX(enroll_date) over ( + max(enroll_date) over ( order by salary range between cast('1 year' as interval) preceding @@ -2742,7 +2349,7 @@ from empsalary; select - MAX(enroll_date) over ( + max(enroll_date) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -2756,13 +2363,7 @@ from empsalary; select - SUM(unique1) over ( - order by four - groups between - unbounded preceding - and - current row - ), + sum(unique1) over (order by four groups between unbounded preceding and current row), unique1, four from @@ -2771,13 +2372,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - unbounded preceding - and - unbounded following - ), + sum(unique1) over (order by four groups between unbounded preceding and unbounded following), unique1, four from @@ -2786,13 +2381,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - current row - and - unbounded following - ), + sum(unique1) over (order by four groups between current row and unbounded following), unique1, four from @@ -2801,13 +2390,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 1 preceding - and - unbounded following - ), + sum(unique1) over (order by four groups between 1 preceding and unbounded following), unique1, four from @@ -2816,13 +2399,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 1 following - and - unbounded following - ), + sum(unique1) over (order by four groups between 1 following and unbounded following), unique1, four from @@ -2831,13 +2408,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - unbounded preceding - and - 2 following - ), + sum(unique1) over (order by four groups between unbounded preceding and 2 following), unique1, four from @@ -2846,13 +2417,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 2 preceding - and - 1 preceding - ), + sum(unique1) over (order by four groups between 2 preceding and 1 preceding), unique1, four from @@ -2861,13 +2426,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 2 preceding - and - 1 following - ), + sum(unique1) over (order by four groups between 2 preceding and 1 following), unique1, four from @@ -2876,13 +2435,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 0 preceding - and - 0 following - ), + sum(unique1) over (order by four groups between 0 preceding and 0 following), unique1, four from @@ -2891,14 +2444,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 2 preceding - and - 1 following - exclude current row - ), + sum(unique1) over (order by four groups between 2 preceding and 1 following exclude current row), unique1, four from @@ -2907,14 +2453,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 2 preceding - and - 1 following - exclude group - ), + sum(unique1) over (order by four groups between 2 preceding and 1 following exclude group), unique1, four from @@ -2923,14 +2462,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 2 preceding - and - 1 following - exclude ties - ), + sum(unique1) over (order by four groups between 2 preceding and 1 following exclude ties), unique1, four from @@ -2939,14 +2471,7 @@ where unique1 < 10; select - SUM(unique1) over ( - partition by ten - order by four - groups between - 0 preceding - and - 0 following - ), + sum(unique1) over (partition by ten order by four groups between 0 preceding and 0 following), unique1, four, ten @@ -2956,7 +2481,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by ten order by four groups between @@ -2974,7 +2499,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by ten order by four groups between @@ -2992,7 +2517,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by ten order by four groups between @@ -3010,54 +2535,24 @@ where unique1 < 10; select - FIRST_VALUE(salary) over ( - order by enroll_date - groups between - 1 preceding - and - 1 following - ), - LEAD(salary) over ( - order by enroll_date - groups between - 1 preceding - and - 1 following - ), - NTH_VALUE(salary, 1) over ( - order by enroll_date - groups between - 1 preceding - and - 1 following - ), + first_value(salary) over (order by enroll_date groups between 1 preceding and 1 following), + lead(salary) over (order by enroll_date groups between 1 preceding and 1 following), + nth_value(salary, 1) over (order by enroll_date groups between 1 preceding and 1 following), salary, enroll_date from empsalary; select - LAST_VALUE(salary) over ( - order by enroll_date - groups between - 1 preceding - and - 1 following - ), - LAG(salary) over ( - order by enroll_date - groups between - 1 preceding - and - 1 following - ), + last_value(salary) over (order by enroll_date groups between 1 preceding and 1 following), + lag(salary) over (order by enroll_date groups between 1 preceding and 1 following), salary, enroll_date from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date groups between 1 following @@ -3065,15 +2560,8 @@ select 3 following exclude current row ), - LEAD(salary) over ( - order by enroll_date - groups between - 1 following - and - 3 following - exclude ties - ), - NTH_VALUE(salary, 1) over ( + lead(salary) over (order by enroll_date groups between 1 following and 3 following exclude ties), + nth_value(salary, 1) over ( order by enroll_date groups between 1 following @@ -3087,15 +2575,7 @@ from empsalary; select - LAST_VALUE(salary) over ( - order by enroll_date - groups between - 1 following - and - 3 following - exclude group - ), - LAG(salary) over ( + last_value(salary) over ( order by enroll_date groups between 1 following @@ -3103,19 +2583,16 @@ select 3 following exclude group ), + lag(salary) over (order by enroll_date groups between 1 following and 3 following exclude group), salary, enroll_date from empsalary; -with -cte (x) -as ( - select * from generate_series(1, 35, 2) -) +with cte (x) as (select * from generate_series(1, 35, 2)) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3127,14 +2604,10 @@ window 1 following ); -with -cte (x) -as ( - select * from generate_series(1, 35, 2) -) +with cte (x) as (select * from generate_series(1, 35, 2)) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3146,14 +2619,10 @@ window 1 following ); -with -cte (x) -as ( - select * from generate_series(1, 35, 2) -) +with cte (x) as (select * from generate_series(1, 35, 2)) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3168,13 +2637,11 @@ window with cte (x) as ( - select 1 union all select 1 union all select 1 - union all - select * from generate_series(5, 49, 2) + select 1 union all select 1 union all select 1 union all select * from generate_series(5, 49, 2) ) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3189,13 +2656,11 @@ window with cte (x) as ( - select 1 union all select 1 union all select 1 - union all - select * from generate_series(5, 49, 2) + select 1 union all select 1 union all select 1 union all select * from generate_series(5, 49, 2) ) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3210,13 +2675,11 @@ window with cte (x) as ( - select 1 union all select 1 union all select 1 - union all - select * from generate_series(5, 49, 2) + select 1 union all select 1 union all select 1 union all select * from generate_series(5, 49, 2) ) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3229,30 +2692,21 @@ window ); select - COUNT(*) over (partition by four) + count(*) over (partition by four) from - ( - select * from tenk1 union all select * from tenk2 - ) - as s + (select * from tenk1 union all select * from tenk2) as s limit 0; create temporary table t1 ( f1 int, - f2 bigint + f2 int8 ); insert into t1 values (1, 1), (1, 2), (2, 2); select f1, - SUM(f1) over ( - partition by f1 - range between - 1 preceding - and - 1 following - ) + sum(f1) over (partition by f1 range between 1 preceding and 1 following) from t1 where @@ -3260,14 +2714,7 @@ where select f1, - SUM(f1) over ( - partition by f1 - order by f2 - range between - 1 preceding - and - 1 following - ) + sum(f1) over (partition by f1 order by f2 range between 1 preceding and 1 following) from t1 where @@ -3275,14 +2722,7 @@ where select f1, - SUM(f1) over ( - partition by f1 - order by f2 - range between - 1 preceding - and - 1 following - ) + sum(f1) over (partition by f1 order by f2 range between 1 preceding and 1 following) from t1 where @@ -3290,15 +2730,7 @@ where select f1, - SUM(f1) over ( - partition by f1, - f1 - order by f2 - range between - 2 preceding - and - 1 preceding - ) + sum(f1) over (partition by f1, f1 order by f2 range between 2 preceding and 1 preceding) from t1 where @@ -3306,15 +2738,7 @@ where select f1, - SUM(f1) over ( - partition by f1, - f2 - order by f2 - range between - 1 following - and - 2 following - ) + sum(f1) over (partition by f1, f2 order by f2 range between 1 following and 2 following) from t1 where @@ -3322,13 +2746,7 @@ where select f1, - SUM(f1) over ( - partition by f1 - groups between - 1 preceding - and - 1 following - ) + sum(f1) over (partition by f1 groups between 1 preceding and 1 following) from t1 where @@ -3336,14 +2754,7 @@ where select f1, - SUM(f1) over ( - partition by f1 - order by f2 - groups between - 1 preceding - and - 1 following - ) + sum(f1) over (partition by f1 order by f2 groups between 1 preceding and 1 following) from t1 where @@ -3351,14 +2762,7 @@ where select f1, - SUM(f1) over ( - partition by f1 - order by f2 - groups between - 1 preceding - and - 1 following - ) + sum(f1) over (partition by f1 order by f2 groups between 1 preceding and 1 following) from t1 where @@ -3366,15 +2770,7 @@ where select f1, - SUM(f1) over ( - partition by f1, - f1 - order by f2 - groups between - 2 preceding - and - 1 preceding - ) + sum(f1) over (partition by f1, f1 order by f2 groups between 2 preceding and 1 preceding) from t1 where @@ -3382,54 +2778,40 @@ where select f1, - SUM(f1) over ( - partition by f1, - f2 - order by f2 - groups between - 1 following - and - 2 following - ) + sum(f1) over (partition by f1, f2 order by f2 groups between 1 following and 2 following) from t1 where f1 = f2; -select RANK() over (order by length('abc')); +select rank() over (order by length('abc')); -select RANK() over (order by RANK() over (order by random())); +select rank() over (order by rank() over (order by random())); -select * from empsalary where ROW_NUMBER() over (order by salary) < 10; +select * from empsalary where row_number() over (order by salary) < 10; -select * from empsalary inner join tenk1 on ROW_NUMBER() over (order by salary) < 10; +select * from empsalary inner join tenk1 on row_number() over (order by salary) < 10; -select RANK() over (order by 1), COUNT(*) from empsalary group by 1; +select rank() over (order by 1), count(*) from empsalary group by 1; -delete from empsalary where RANK() over (order by random()) > 10; +delete from empsalary where rank() over (order by random()) > 10; -delete from empsalary returning RANK() over (order by random()); +delete from empsalary returning rank() over (order by random()); -select COUNT(*) over w from tenk1 window w as (order by unique1), w as (order by unique1); +select count(*) over w from tenk1 window w as (order by unique1), w as (order by unique1); -select COUNT() over () from tenk1; +select count() over () from tenk1; select generate_series(1, 100) over () from empsalary; -select NTILE(0) over (order by ten), ten, four from tenk1; +select ntile(0) over (order by ten), ten, four from tenk1; -select NTH_VALUE(four, 0) over (order by ten), ten, four from tenk1; +select nth_value(four, 0) over (order by ten), ten, four from tenk1; select - SUM(salary), - ROW_NUMBER() over (order by depname), - SUM( - SUM( - salary - ) - filter (where - enroll_date > '2007-01-01') - ) + sum(salary), + row_number() over (order by depname), + sum(sum(salary) filter (where enroll_date > '2007-01-01')) filter (where depname <> 'sales') over (order by depname desc) as filtered_sum, depname @@ -3440,8 +2822,8 @@ group by depname; select empno, depname, - ROW_NUMBER() over (partition by depname order by enroll_date) as rn, - RANK() over ( + row_number() over (partition by depname order by enroll_date) as rn, + rank() over ( partition by depname order by enroll_date rows between @@ -3449,7 +2831,7 @@ select and unbounded following ) as rnk, - DENSE_RANK() over ( + dense_rank() over ( partition by depname order by enroll_date range between @@ -3457,7 +2839,7 @@ select and current row ) as drnk, - NTILE(10) over ( + ntile(10) over ( partition by depname order by enroll_date range between @@ -3465,7 +2847,7 @@ select and unbounded following ) as nt, - PERCENT_RANK() over ( + percent_rank() over ( partition by depname order by enroll_date rows between @@ -3473,7 +2855,7 @@ select and unbounded following ) as pr, - CUME_DIST() over ( + cume_dist() over ( partition by depname order by enroll_date range between @@ -3487,8 +2869,8 @@ from select empno, depname, - ROW_NUMBER() over (partition by depname order by enroll_date) as rn, - RANK() over ( + row_number() over (partition by depname order by enroll_date) as rn, + rank() over ( partition by depname order by enroll_date rows between @@ -3496,7 +2878,7 @@ select and unbounded following ) as rnk, - COUNT(*) over ( + count(*) over ( partition by depname order by enroll_date range between @@ -3510,8 +2892,8 @@ from select empno, depname, - ROW_NUMBER() over (partition by depname order by enroll_date) as rn, - RANK() over ( + row_number() over (partition by depname order by enroll_date) as rn, + rank() over ( partition by depname order by enroll_date rows between @@ -3519,7 +2901,7 @@ select and unbounded following ) as rnk, - COUNT(*) over ( + count(*) over ( partition by depname order by enroll_date range between @@ -3536,8 +2918,8 @@ from ( select depname, - SUM(salary) over (partition by depname) as depsalary, - MIN(salary) over (partition by depname || 'A', depname) as depminsalary + sum(salary) over (partition by depname) as depsalary, + min(salary) over (partition by depname || 'A', depname) as depminsalary from empsalary ) @@ -3551,8 +2933,8 @@ from ( select depname, - SUM(salary) over (partition by enroll_date) as enroll_salary, - MIN(salary) over (partition by depname) as depminsalary + sum(salary) over (partition by enroll_date) as enroll_salary, + min(salary) over (partition by depname) as depminsalary from empsalary ) @@ -3563,176 +2945,84 @@ where select * from - ( - select - empno, - ROW_NUMBER() over (order by empno) as rn - from - empsalary - ) - as emp + (select empno, row_number() over (order by empno) as rn from empsalary) as emp where rn < 3; select * from - ( - select - empno, - ROW_NUMBER() over (order by empno) as rn - from - empsalary - ) - as emp + (select empno, row_number() over (order by empno) as rn from empsalary) as emp where rn < 3; select * from - ( - select - empno, - ROW_NUMBER() over (order by empno) as rn - from - empsalary - ) - as emp + (select empno, row_number() over (order by empno) as rn from empsalary) as emp where 3 > rn; select * from - ( - select - empno, - ROW_NUMBER() over (order by empno) as rn - from - empsalary - ) - as emp + (select empno, row_number() over (order by empno) as rn from empsalary) as emp where 2 >= rn; select * from - ( - select - empno, - salary, - RANK() over (order by salary desc) as r - from - empsalary - ) - as emp + (select empno, salary, rank() over (order by salary desc) as r from empsalary) as emp where r <= 3; select * from - ( - select - empno, - salary, - RANK() over (order by salary desc) as r - from - empsalary - ) - as emp + (select empno, salary, rank() over (order by salary desc) as r from empsalary) as emp where r <= 3; select * from - ( - select - empno, - salary, - DENSE_RANK() over (order by salary desc) as dr - from - empsalary - ) - as emp + (select empno, salary, dense_rank() over (order by salary desc) as dr from empsalary) as emp where dr = 1; select * from - ( - select - empno, - salary, - DENSE_RANK() over (order by salary desc) as dr - from - empsalary - ) - as emp + (select empno, salary, dense_rank() over (order by salary desc) as dr from empsalary) as emp where dr = 1; select * from - ( - select - empno, - salary, - COUNT(*) over (order by salary desc) as c - from - empsalary - ) - as emp + (select empno, salary, count(*) over (order by salary desc) as c from empsalary) as emp where c <= 3; select * from - ( - select - empno, - salary, - COUNT(*) over (order by salary desc) as c - from - empsalary - ) - as emp + (select empno, salary, count(*) over (order by salary desc) as c from empsalary) as emp where c <= 3; select * from - ( - select - empno, - salary, - COUNT(empno) over (order by salary desc) as c - from - empsalary - ) - as emp + (select empno, salary, count(empno) over (order by salary desc) as c from empsalary) as emp where c <= 3; select * from - ( - select - empno, - salary, - COUNT(empno) over (order by salary desc) as c - from - empsalary - ) - as emp + (select empno, salary, count(empno) over (order by salary desc) as c from empsalary) as emp where c <= 3; @@ -3743,13 +3033,7 @@ from select empno, salary, - COUNT(*) over ( - order by salary desc - rows between - current row - and - unbounded following - ) as c + count(*) over (order by salary desc rows between current row and unbounded following) as c from empsalary ) @@ -3757,7 +3041,7 @@ from where c >= 3; -select * from (select empno, salary, COUNT(*) over () as c from empsalary) as emp where 11 <= c; +select * from (select empno, salary, count(*) over () as c from empsalary) as emp where 11 <= c; select * @@ -3766,8 +3050,8 @@ from select empno, salary, - COUNT(*) over (order by salary desc) as c, - DENSE_RANK() over (order by salary desc) as dr + count(*) over (order by salary desc) as c, + dense_rank() over (order by salary desc) as dr from empsalary ) @@ -3782,7 +3066,7 @@ from select empno, depname, - ROW_NUMBER() over (partition by depname order by empno) as rn + row_number() over (partition by depname order by empno) as rn from empsalary ) @@ -3797,7 +3081,7 @@ from select empno, depname, - ROW_NUMBER() over (partition by depname order by empno) as rn + row_number() over (partition by depname order by empno) as rn from empsalary ) @@ -3813,7 +3097,7 @@ from select empno, depname, - ROW_NUMBER() over (partition by depname order by empno) as rn + row_number() over (partition by depname order by empno) as rn from empsalary ) @@ -3829,7 +3113,7 @@ from empno, depname, salary, - COUNT(empno) over (partition by depname order by salary desc) as c + count(empno) over (partition by depname order by salary desc) as c from empsalary ) @@ -3845,7 +3129,7 @@ from empno, depname, salary, - COUNT(empno) over (partition by depname order by salary desc) as c + count(empno) over (partition by depname order by salary desc) as c from empsalary ) @@ -3856,16 +3140,7 @@ where select * from - ( - select - empno, - depname, - salary, - COUNT(empno) over () as c - from - empsalary - ) - as emp + (select empno, depname, salary, count(empno) over () as c from empsalary) as emp where c = 1; @@ -3874,8 +3149,8 @@ select from ( select - ROW_NUMBER() over (partition by salary) as rn, - LEAD(depname) over (partition by salary) || ' Department' as n_dep + row_number() over (partition by salary) as rn, + lead(depname) over (partition by salary) || ' Department' as n_dep from empsalary ) @@ -3889,11 +3164,11 @@ from ( select *, - COUNT(salary) over (partition by depname || '') as c1, - ROW_NUMBER() over (partition by depname) as rn, - COUNT(*) over (partition by depname) as c2, - COUNT(*) over (partition by '' || depname) as c3, - NTILE(2) over (partition by depname) as nt + count(salary) over (partition by depname || '') as c1, + row_number() over (partition by depname) as rn, + count(*) over (partition by depname) as c2, + count(*) over (partition by '' || depname) as c3, + ntile(2) over (partition by depname) as nt from empsalary ) @@ -3907,11 +3182,11 @@ from ( select *, - COUNT(salary) over (partition by depname || '') as c1, - ROW_NUMBER() over (partition by depname) as rn, - COUNT(*) over (partition by depname) as c2, - COUNT(*) over (partition by '' || depname) as c3, - NTILE(2) over (partition by depname) as nt + count(salary) over (partition by depname || '') as c1, + row_number() over (partition by depname) as rn, + count(*) over (partition by depname) as c2, + count(*) over (partition by '' || depname) as c3, + ntile(2) over (partition by depname) as nt from empsalary ) @@ -3924,12 +3199,9 @@ select from ( select - NTILE(e2.salary) over (partition by e1.depname) as c + ntile(e2.salary) over (partition by e1.depname) as c from - empsalary as e1 - left outer join - empsalary as e2 - on true + empsalary as e1 left outer join empsalary as e2 on true where e1.empno = e2.empno ) @@ -3940,13 +3212,7 @@ where select 1 from - ( - select - NTILE(s1.x) over () as c - from - (select (select 1) as x) as s1 - ) - as s + (select ntile(s1.x) over () as c from (select (select 1) as x) as s1) as s where s.c = 1; @@ -3957,13 +3223,7 @@ from select empno, salary, - COUNT(*) over ( - order by salary desc - rows between - current row - and - unbounded following - ) as c + count(*) over (order by salary desc rows between current row and unbounded following) as c from empsalary ) @@ -3974,45 +3234,21 @@ where select * from - ( - select - empno, - salary, - COUNT(*) over (order by salary) as c - from - empsalary - ) - as emp + (select empno, salary, count(*) over (order by salary) as c from empsalary) as emp where 3 <= c; select * from - ( - select - empno, - salary, - COUNT(random()) over (order by empno desc) as c - from - empsalary - ) - as emp + (select empno, salary, count(random()) over (order by empno desc) as c from empsalary) as emp where c = 1; select * from - ( - select - empno, - salary, - COUNT((select 1)) over (order by empno desc) as c - from - empsalary - ) - as emp + (select empno, salary, count((select 1)) over (order by empno desc) as c from empsalary) as emp where c = 1; @@ -4022,8 +3258,8 @@ from ( select depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over (partition by depname, empno order by enroll_date) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname, empno order by enroll_date) as depminsalary from empsalary ) @@ -4035,8 +3271,8 @@ select empno, enroll_date, depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over (partition by depname order by enroll_date) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname order by enroll_date) as depminsalary from empsalary order by depname, @@ -4046,8 +3282,8 @@ select empno, enroll_date, depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over (partition by depname order by enroll_date) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname order by enroll_date) as depminsalary from empsalary order by depname, @@ -4059,8 +3295,8 @@ select distinct empno, enroll_date, depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over (partition by depname order by enroll_date) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname order by enroll_date) as depminsalary from empsalary order by depname, @@ -4070,8 +3306,8 @@ select distinct empno, enroll_date, depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over (partition by depname order by enroll_date) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname order by enroll_date) as depminsalary from empsalary order by depname, @@ -4080,17 +3316,8 @@ order by depname, reset enable_hashagg; select - LEAD(1) over ( - partition by depname - order by salary, - enroll_date - ), - LAG(1) over ( - partition by depname - order by salary, - enroll_date, - empno - ) + lead(1) over (partition by depname order by salary, enroll_date), + lag(1) over (partition by depname order by salary, enroll_date, empno) from empsalary; @@ -4103,8 +3330,8 @@ from empno, salary, enroll_date, - ROW_NUMBER() over (partition by depname order by enroll_date) as first_emp, - ROW_NUMBER() over (partition by depname order by enroll_date desc) as last_emp + row_number() over (partition by depname order by enroll_date) as first_emp, + row_number() over (partition by depname order by enroll_date desc) as last_emp from empsalary ) @@ -4121,8 +3348,8 @@ from empno, salary, enroll_date, - ROW_NUMBER() over (partition by depname order by enroll_date) as first_emp, - ROW_NUMBER() over (partition by depname order by enroll_date desc) as last_emp + row_number() over (partition by depname order by enroll_date) as first_emp, + row_number() over (partition by depname order by enroll_date desc) as last_emp from empsalary ) @@ -4138,67 +3365,39 @@ language internal window immutable strict -as $function$ -window_nth_value -$function$; +as 'window_nth_value'; select - nth_value_def("n" := 2, "val" := ten) over (partition by four), + nth_value_def(n := 2, val := ten) over (partition by four), ten, four from - ( - select - * - from - tenk1 - where - unique2 < 10 - order by four, - ten - ) - as s; + (select * from tenk1 where unique2 < 10 order by four, ten) as s; select nth_value_def(ten) over (partition by four), ten, four from - ( - select - * - from - tenk1 - where - unique2 < 10 - order by four, - ten - ) - as s; + (select * from tenk1 where unique2 < 10 order by four, ten) as s; create function logging_sfunc_nonstrict(text, anyelement) returns text language sql immutable -as $function$ -SELECT COALESCE($1, '') || '*' || quote_nullable($2) -$function$; +as $$ SELECT COALESCE($1, '') || '*' || quote_nullable($2) $$; create function logging_msfunc_nonstrict(text, anyelement) returns text language sql immutable -as $function$ -SELECT COALESCE($1, '') || '+' || quote_nullable($2) -$function$; +as $$ SELECT COALESCE($1, '') || '+' || quote_nullable($2) $$; create function logging_minvfunc_nonstrict(text, anyelement) returns text language sql immutable -as $function$ -SELECT $1 || '-' || quote_nullable($2) -$function$; +as $$ SELECT $1 || '-' || quote_nullable($2) $$; create aggregate logging_agg_nonstrict ( anyelement @@ -4227,27 +3426,21 @@ returns text language sql immutable strict -as $function$ -SELECT $1 || '*' || quote_nullable($2) -$function$; +as $$ SELECT $1 || '*' || quote_nullable($2) $$; create function logging_msfunc_strict(text, anyelement) returns text language sql immutable strict -as $function$ -SELECT $1 || '+' || quote_nullable($2) -$function$; +as $$ SELECT $1 || '+' || quote_nullable($2) $$; create function logging_minvfunc_strict(text, anyelement) returns text language sql immutable strict -as $function$ -SELECT $1 || '-' || quote_nullable($2) -$function$; +as $$ SELECT $1 || '-' || quote_nullable($2) $$; create aggregate logging_agg_strict ( text @@ -4272,9 +3465,7 @@ create aggregate logging_agg_strict_initcond ( ); select - cast(p as text) || ',' || cast(i as text) || ':' || - coalesce(cast(v as text), 'NULL') - as row, + cast(p as text) || ',' || cast(i as text) || ':' || coalesce(cast(v as text), 'NULL') as row, logging_agg_nonstrict(v) over wnd as nstrict, logging_agg_nonstrict_initcond(v) over wnd as nstrict_init, logging_agg_strict(cast(v as text)) over wnd as strict, @@ -4307,21 +3498,12 @@ order by p, select cast(p as text) || ',' || cast(i as text) || ':' || - case - when f then coalesce(cast(v as text), 'NULL') - else '-' - end + case when f then coalesce(cast(v as text), 'NULL') else '-' end as row, logging_agg_nonstrict(v) filter (where f) over wnd as nstrict_filt, - logging_agg_nonstrict_initcond(v) - filter (where - f) over wnd as nstrict_init_filt, - logging_agg_strict(cast(v as text)) - filter (where - f) over wnd as strict_filt, - logging_agg_strict_initcond(v) - filter (where - f) over wnd as strict_init_filt + logging_agg_nonstrict_initcond(v) filter (where f) over wnd as nstrict_init_filt, + logging_agg_strict(cast(v as text)) filter (where f) over wnd as strict_filt, + logging_agg_strict_initcond(v) filter (where f) over wnd as strict_init_filt from ( values @@ -4349,14 +3531,10 @@ order by p, i; select - cast(i as text) || ':' || - coalesce(cast(v as text), 'NULL') - as row, + cast(i as text) || ':' || coalesce(cast(v as text), 'NULL') as row, logging_agg_strict(cast(v as text)) over wnd as inverse, - logging_agg_strict( - cast(v as text) || - case when random() < 0 then '?' else '' end - ) over wnd as noinverse + logging_agg_strict(cast(v as text) || case when random() < 0 then '?' else '' end) over wnd + as noinverse from (values (1, 'a'), (2, 'b'), (3, 'c')) as t (i, v) window @@ -4370,15 +3548,9 @@ window order by i; select - cast(i as text) || ':' || - coalesce(cast(v as text), 'NULL') - as row, - logging_agg_strict(cast(v as text)) - filter (where - true) over wnd as inverse, - logging_agg_strict(cast(v as text)) - filter (where - random() >= 0) over wnd as noinverse + cast(i as text) || ':' || coalesce(cast(v as text), 'NULL') as row, + logging_agg_strict(cast(v as text)) filter (where true) over wnd as inverse, + logging_agg_strict(cast(v as text)) filter (where random() >= 0) over wnd as noinverse from (values (1, 'a'), (2, 'b'), (3, 'c')) as t (i, v) window @@ -4405,60 +3577,38 @@ window ) order by i; -create function sum_int_randrestart_minvfunc(int, int) -returns int +create function sum_int_randrestart_minvfunc(int4, int4) +returns int4 language sql strict -as $function$ -SELECT CASE WHEN random() < 0.2 THEN NULL ELSE $1 - $2 END -$function$; +as $$ SELECT CASE WHEN random() < 0.2 THEN NULL ELSE $1 - $2 END $$; create aggregate sum_int_randomrestart ( - int + int4 ) ( - stype = int, + stype = int4, sfunc = int4pl, - mstype = int, + mstype = int4, msfunc = int4pl, minvfunc = sum_int_randrestart_minvfunc ); with -vs -as ( - select - i, - cast(random() * 100 as int) as v - from - generate_series(1, 100) as i -), +vs as (select i, cast(random() * 100 as int4) as v from generate_series(1, 100) as i), sum_following as ( select i, - SUM(v) over ( - order by i desc - rows between - unbounded preceding - and - current row - ) as s + sum(v) over (order by i desc rows between unbounded preceding and current row) as s from vs ) select distinct sum_following.s = sum_int_randomrestart(v) over fwd as eq1, -sum_following.s = sum_int_randomrestart(-v) over fwd as eq2, - 100 * 3 + (vs.i - 1) * 3 = - length( - logging_agg_nonstrict(cast('' as text)) over fwd - ) - as eq3 + 100 * 3 + (vs.i - 1) * 3 = length(logging_agg_nonstrict(cast('' as text)) over fwd) as eq3 from - vs - inner join - sum_following - on sum_following.i = vs.i + vs inner join sum_following on sum_following.i = vs.i window fwd as ( order by vs.i @@ -4470,101 +3620,48 @@ window select i, - AVG(cast(v as bigint)) over ( - order by i - rows between - current row - and - unbounded following - ) + avg(cast(v as bigint)) over (order by i rows between current row and unbounded following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - AVG(cast(v as int)) over ( - order by i - rows between - current row - and - unbounded following - ) + avg(cast(v as int)) over (order by i rows between current row and unbounded following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - AVG(cast(v as smallint)) over ( - order by i - rows between - current row - and - unbounded following - ) + avg(cast(v as smallint)) over (order by i rows between current row and unbounded following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - AVG(cast(v as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + avg(cast(v as numeric)) over (order by i rows between current row and unbounded following) from - ( - values (1, 1.5), (2, 2.5), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1.5), (2, 2.5), (3, null), (4, null)) as t (i, v); select i, - AVG(cast(v as interval)) over ( - order by i - rows between - current row - and - unbounded following - ) + avg(cast(v as interval)) over (order by i rows between current row and unbounded following) from - ( - values - (1, '1 sec'), - (2, '2 sec'), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, '1 sec'), (2, '2 sec'), (3, null), (4, null)) as t (i, v); select x, - AVG(x) over ( rows between current row and 1 following) as curr_next_avg, - AVG(x) over ( rows between 1 preceding and current row) as prev_curr_avg, - SUM(x) over ( rows between current row and 1 following) as curr_next_sum, - SUM(x) over ( rows between 1 preceding and current row) as prev_curr_sum + avg(x) over ( rows between current row and 1 following) as curr_next_avg, + avg(x) over ( rows between 1 preceding and current row) as prev_curr_avg, + sum(x) over ( rows between current row and 1 following) as curr_next_sum, + sum(x) over ( rows between 1 preceding and current row) as prev_curr_sum from ( values (cast(null as interval)), (cast('infinity' as interval)), - ( - '-2147483648 days -2147483648 months -9223372036854775807 usecs' - ), + ('-2147483648 days -2147483648 months -9223372036854775807 usecs'), (cast('-infinity' as interval)), - ( - '2147483647 days 2147483647 months 9223372036854775806 usecs' - ), + ('2147483647 days 2147483647 months 9223372036854775806 usecs'), (cast('infinity' as interval)), (cast('6 days' as interval)), (cast('7 days' as interval)), @@ -4575,16 +3672,13 @@ from select x, - AVG(x) over ( rows between current row and 2 following) + avg(x) over ( rows between current row and 2 following) from ( values (cast(null as interval)), (cast('3 days' as interval)), - ( - cast('infinity' as timestamp with time zone) - - NOW() - ), + (cast('infinity' as timestamptz) - now()), (cast('6 days' as interval)), (cast('-infinity' as interval)) ) @@ -4592,16 +3686,13 @@ from select x, - SUM(x) over ( rows between current row and 2 following) + sum(x) over ( rows between current row and 2 following) from ( values (cast(null as interval)), (cast('3 days' as interval)), - ( - cast('infinity' as timestamp with time zone) - - NOW() - ), + (cast('infinity' as timestamptz) - now()), (cast('6 days' as interval)), (cast('-infinity' as interval)) ) @@ -4609,490 +3700,146 @@ from select i, - SUM(cast(v as smallint)) over ( - order by i - rows between - current row - and - unbounded following - ) + sum(cast(v as smallint)) over (order by i rows between current row and unbounded following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as int)) over ( - order by i - rows between - current row - and - unbounded following - ) + sum(cast(v as int)) over (order by i rows between current row and unbounded following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as bigint)) over ( - order by i - rows between - current row - and - unbounded following - ) + sum(cast(v as bigint)) over (order by i rows between current row and unbounded following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as money)) over ( - order by i - rows between - current row - and - unbounded following - ) + sum(cast(v as money)) over (order by i rows between current row and unbounded following) from - ( - values - (1, '1.10'), - (2, '2.20'), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, '1.10'), (2, '2.20'), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as interval)) over ( - order by i - rows between - current row - and - unbounded following - ) + sum(cast(v as interval)) over (order by i rows between current row and unbounded following) from - ( - values - (1, '1 sec'), - (2, '2 sec'), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, '1 sec'), (2, '2 sec'), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + sum(cast(v as numeric)) over (order by i rows between current row and unbounded following) from - ( - values (1, 1.1), (2, 2.2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1.1), (2, 2.2), (3, null), (4, null)) as t (i, v); select - SUM(cast(n as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + sum(cast(n as numeric)) over (order by i rows between current row and unbounded following) from (values (1, 1.01), (2, 2), (3, 3)) as v (i, n); select i, - COUNT(v) over ( - order by i - rows between - current row - and - unbounded following - ) + count(v) over (order by i rows between current row and unbounded following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - COUNT(*) over ( - order by i - rows between - current row - and - unbounded following - ) + count(*) over (order by i rows between current row and unbounded following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select - var_pop(cast(n as bigint)) over ( - order by i - rows between - current row - and - unbounded following - ) + var_pop(cast(n as bigint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - var_pop(cast(n as int)) over ( - order by i - rows between - current row - and - unbounded following - ) + var_pop(cast(n as int)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - var_pop(cast(n as smallint)) over ( - order by i - rows between - current row - and - unbounded following - ) + var_pop(cast(n as smallint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - var_pop(cast(n as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + var_pop(cast(n as numeric)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - var_samp(cast(n as bigint)) over ( - order by i - rows between - current row - and - unbounded following - ) + var_samp(cast(n as bigint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - var_samp(cast(n as int)) over ( - order by i - rows between - current row - and - unbounded following - ) + var_samp(cast(n as int)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - var_samp(cast(n as smallint)) over ( - order by i - rows between - current row - and - unbounded following - ) + var_samp(cast(n as smallint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - var_samp(cast(n as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + var_samp(cast(n as numeric)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - variance(cast(n as bigint)) over ( - order by i - rows between - current row - and - unbounded following - ) + variance(cast(n as bigint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - variance(cast(n as int)) over ( - order by i - rows between - current row - and - unbounded following - ) + variance(cast(n as int)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - variance(cast(n as smallint)) over ( - order by i - rows between - current row - and - unbounded following - ) + variance(cast(n as smallint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - variance(cast(n as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + variance(cast(n as numeric)) over (order by i rows between current row and unbounded following) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - stddev_pop(cast(n as bigint)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev_pop(cast(n as bigint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) - ) - as r (i, n); + (values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300)) as r (i, n); select - stddev_pop(cast(n as int)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev_pop(cast(n as int)) over (order by i rows between current row and unbounded following) from - ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) - ) - as r (i, n); + (values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300)) as r (i, n); select - stddev_pop(cast(n as smallint)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev_pop(cast(n as smallint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) - ) - as r (i, n); + (values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300)) as r (i, n); select - stddev_pop(cast(n as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev_pop(cast(n as numeric)) over (order by i rows between current row and unbounded following) from - ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) - ) - as r (i, n); + (values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300)) as r (i, n); select - stddev_samp(cast(n as bigint)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev_samp(cast(n as bigint)) over (order by i rows between current row and unbounded following) from - ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) - ) - as r (i, n); + (values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300)) as r (i, n); select - stddev_samp(cast(n as int)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev_samp(cast(n as int)) over (order by i rows between current row and unbounded following) from - ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) - ) - as r (i, n); + (values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300)) as r (i, n); select stddev_samp(cast(n as smallint)) over ( @@ -5103,192 +3850,61 @@ select unbounded following ) from - ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) - ) - as r (i, n); + (values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300)) as r (i, n); select - stddev_samp(cast(n as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev_samp(cast(n as numeric)) over (order by i rows between current row and unbounded following) from - ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) - ) - as r (i, n); + (values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300)) as r (i, n); select - stddev(cast(n as bigint)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev(cast(n as bigint)) over (order by i rows between current row and unbounded following) from - ( - values - (0, null), - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (0, null), (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - stddev(cast(n as int)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev(cast(n as int)) over (order by i rows between current row and unbounded following) from - ( - values - (0, null), - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (0, null), (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - stddev(cast(n as smallint)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev(cast(n as smallint)) over (order by i rows between current row and unbounded following) from - ( - values - (0, null), - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (0, null), (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select - stddev(cast(n as numeric)) over ( - order by i - rows between - current row - and - unbounded following - ) + stddev(cast(n as numeric)) over (order by i rows between current row and unbounded following) from - ( - values - (0, null), - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (0, null), (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select i, - SUM(cast(v as int)) over ( - order by i - rows between - current row - and - current row - ) + sum(cast(v as int)) over (order by i rows between current row and current row) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as int)) over ( - order by i - rows between - current row - and - 1 following - ) + sum(cast(v as int)) over (order by i rows between current row and 1 following) from - ( - values (1, 1), (2, 2), (3, null), (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as int)) over ( - order by i - rows between - 1 preceding - and - 1 following - ) + sum(cast(v as int)) over (order by i rows between 1 preceding and 1 following) from - ( - values (1, 1), (2, 2), (3, 3), (4, 4) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, 3), (4, 4)) as t (i, v); select a, b, - SUM(b) over ( - order by a - rows between - 1 preceding - and - current row - ) + sum(b) over (order by a rows between 1 preceding and current row) from - ( - values - (1, cast(1 as numeric)), - (2, 2), - (3, 'NaN'), - (4, 3), - (5, 4) - ) - as t (a, b); + (values (1, cast(1 as numeric)), (2, 2), (3, 'NaN'), (4, 3), (5, 4)) as t (a, b); select to_char( - SUM(cast(n as double precision)) over ( - order by i - rows between - current row - and - 1 following - ), + sum(cast(n as float8)) over (order by i rows between current row and 1 following), '999999999999999999999D9' ) from @@ -5300,15 +3916,7 @@ select bool_and(b) over w, bool_or(b) over w from - ( - values - (1, true), - (2, true), - (3, false), - (4, false), - (5, true) - ) - as v (i, b) + (values (1, true), (2, true), (3, false), (4, false), (5, true)) as v (i, b) window w as ( order by i @@ -5319,53 +3927,29 @@ window ); select - COUNT(*) over (order by t1.unique1) + count(*) over (order by t1.unique1) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.tenthous + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.tenthous limit 1; select - COUNT(*) over () + count(*) over () from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.tenthous + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.tenthous where t2.two = 1 limit 1; select - COUNT(*) over ( - order by t1.unique1 - rows between - unbounded preceding - and - unbounded following - ) + count(*) over (order by t1.unique1 rows between unbounded preceding and unbounded following) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.tenthous + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.tenthous limit 1; select - COUNT(*) over ( - order by t1.unique1 - rows between - unbounded preceding - and - 10000 following - ) + count(*) over (order by t1.unique1 rows between unbounded preceding and 10000 following) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.tenthous + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.tenthous limit 1; select @@ -5385,11 +3969,11 @@ create function pg_temp.f(group_size bigint) returns setof int[] language sql stable -as $function$ -SELECT array_agg(s) OVER w +as $$ + SELECT array_agg(s) OVER w FROM generate_series(1,5) s WINDOW w AS (ORDER BY s ROWS BETWEEN CURRENT ROW AND GROUP_SIZE FOLLOWING) -$function$; +$$; select * from pg_temp.f(2); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_80.snap index 66e9631cc..2529f3c81 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_80.snap @@ -26,7 +26,7 @@ select depname, empno, salary, - SUM(salary) over (partition by depname) + sum(salary) over (partition by depname) from empsalary order by depname, @@ -36,15 +36,15 @@ select depname, empno, salary, - RANK() over (partition by depname order by salary) + rank() over (partition by depname order by salary) from empsalary; select four, ten, - SUM(SUM(four)) over (partition by four), - AVG(ten) + sum(sum(four)) over (partition by four), + avg(ten) from tenk1 group by four, @@ -56,7 +56,7 @@ select depname, empno, salary, - SUM(salary) over w + sum(salary) over w from empsalary window @@ -68,7 +68,7 @@ select depname, empno, salary, - RANK() over w + rank() over w from empsalary window @@ -76,16 +76,16 @@ window partition by depname order by salary ) -order by RANK() over w; +order by rank() over w; -select COUNT(*) over () from tenk1 where unique2 < 10; +select count(*) over () from tenk1 where unique2 < 10; -select COUNT(*) over w from tenk1 where unique2 < 10 window w as (); +select count(*) over w from tenk1 where unique2 < 10 window w as (); select four from tenk1 where false window w as (partition by ten); select - SUM(four) over (partition by ten order by unique2) as sum_1, + sum(four) over (partition by ten order by unique2) as sum_1, ten, four from @@ -93,10 +93,10 @@ from where unique2 < 10; -select ROW_NUMBER() over (order by unique2) from tenk1 where unique2 < 10; +select row_number() over (order by unique2) from tenk1 where unique2 < 10; select - RANK() over (partition by four order by ten) as rank_1, + rank() over (partition by four order by ten) as rank_1, ten, four from @@ -105,7 +105,7 @@ where unique2 < 10; select - DENSE_RANK() over (partition by four order by ten), + dense_rank() over (partition by four order by ten), ten, four from @@ -114,7 +114,7 @@ where unique2 < 10; select - PERCENT_RANK() over (partition by four order by ten), + percent_rank() over (partition by four order by ten), ten, four from @@ -123,7 +123,7 @@ where unique2 < 10; select - CUME_DIST() over (partition by four order by ten), + cume_dist() over (partition by four order by ten), ten, four from @@ -132,7 +132,7 @@ where unique2 < 10; select - NTILE(3) over (order by ten, four), + ntile(3) over (order by ten, four), ten, four from @@ -140,10 +140,10 @@ from where unique2 < 10; -select NTILE(null) over (order by ten, four), ten, four from tenk1 limit 2; +select ntile(null) over (order by ten, four), ten, four from tenk1 limit 2; select - LAG(ten) over (partition by four order by ten), + lag(ten) over (partition by four order by ten), ten, four from @@ -152,7 +152,7 @@ where unique2 < 10; select - LAG(ten, four) over (partition by four order by ten), + lag(ten, four) over (partition by four order by ten), ten, four from @@ -161,7 +161,7 @@ where unique2 < 10; select - LAG(ten, four, 0) over (partition by four order by ten), + lag(ten, four, 0) over (partition by four order by ten), ten, four from @@ -170,7 +170,7 @@ where unique2 < 10; select - LAG(ten, four, 0.7) over (partition by four order by ten), + lag(ten, four, 0.7) over (partition by four order by ten), ten, four from @@ -181,7 +181,7 @@ order by four, ten; select - LEAD(ten) over (partition by four order by ten), + lead(ten) over (partition by four order by ten), ten, four from @@ -190,7 +190,7 @@ where unique2 < 10; select - LEAD(ten * 2, 1) over (partition by four order by ten), + lead(ten * 2, 1) over (partition by four order by ten), ten, four from @@ -199,7 +199,7 @@ where unique2 < 10; select - LEAD(ten * 2, 1, -1) over (partition by four order by ten), + lead(ten * 2, 1, -1) over (partition by four order by ten), ten, four from @@ -208,7 +208,7 @@ where unique2 < 10; select - LEAD(ten * 2, 1, -1.4) over (partition by four order by ten), + lead(ten * 2, 1, -1.4) over (partition by four order by ten), ten, four from @@ -219,7 +219,7 @@ order by four, ten; select - FIRST_VALUE(ten) over (partition by four order by ten), + first_value(ten) over (partition by four order by ten), ten, four from @@ -228,7 +228,7 @@ where unique2 < 10; select - LAST_VALUE(four) over (order by ten), + last_value(four) over (order by ten), ten, four from @@ -237,53 +237,33 @@ where unique2 < 10; select - LAST_VALUE(ten) over (partition by four), + last_value(ten) over (partition by four), ten, four from - ( - select - * - from - tenk1 - where - unique2 < 10 - order by four, - ten - ) - as s + (select * from tenk1 where unique2 < 10 order by four, ten) as s order by four, ten; select - NTH_VALUE(ten, four + 1) over (partition by four), + nth_value(ten, four + 1) over (partition by four), ten, four from - ( - select - * - from - tenk1 - where - unique2 < 10 - order by four, - ten - ) - as s; + (select * from tenk1 where unique2 < 10 order by four, ten) as s; select ten, two, - SUM(hundred) as gsum, - SUM(SUM(hundred)) over (partition by two order by ten) as wsum + sum(hundred) as gsum, + sum(sum(hundred)) over (partition by two order by ten) as wsum from tenk1 group by ten, two; select - COUNT(*) over (partition by four), + count(*) over (partition by four), four from (select * from tenk1 where two = 1) as s @@ -291,8 +271,8 @@ where unique2 < 10; select - cast(COUNT(*) over (partition by four order by ten) + - SUM(hundred) over (partition by four order by ten) + cast(count(*) over (partition by four order by ten) + + sum(hundred) over (partition by four order by ten) as varchar) as cntsum from @@ -305,10 +285,10 @@ select from ( select - COUNT(*) over (partition by four order by ten) + - SUM(hundred) over (partition by two order by ten) as total, - COUNT(*) over (partition by four order by ten) as fourcount, - SUM(hundred) over (partition by two order by ten) as twosum + count(*) over (partition by four order by ten) + + sum(hundred) over (partition by two order by ten) as total, + count(*) over (partition by four order by ten) as fourcount, + sum(hundred) over (partition by two order by ten) as twosum from tenk1 ) @@ -317,10 +297,7 @@ where total <> fourcount + twosum; select - AVG(four) over ( - partition by four - order by thousand / 100 - ) + avg(four) over (partition by four order by thousand / 100) from tenk1 where @@ -329,8 +306,8 @@ where select ten, two, - SUM(hundred) as gsum, - SUM(SUM(hundred)) over win as wsum + sum(hundred) as gsum, + sum(sum(hundred)) over win as wsum from tenk1 group by ten, @@ -342,16 +319,16 @@ window ); select - SUM(salary), - ROW_NUMBER() over (order by depname), - SUM(SUM(salary)) over (order by depname desc) + sum(salary), + row_number() over (order by depname), + sum(sum(salary)) over (order by depname desc) from empsalary group by depname; select - SUM(salary) over w1, - COUNT(*) over w2 + sum(salary) over w1, + count(*) over w2 from empsalary window @@ -363,30 +340,23 @@ window ); select - LEAD( - ten, - ( - select - two - from - tenk1 - where - s.unique2 = unique2 - ) - ) over (partition by four order by ten) + lead(ten, (select two from tenk1 where s.unique2 = unique2)) over ( + partition by four + order by ten + ) from tenk1 as s where unique2 < 10; select - COUNT(*) over (partition by four) + count(*) over (partition by four) from (select * from tenk1 where false) as s; select - SUM(salary) over w, - RANK() over w + sum(salary) over w, + rank() over w from empsalary window @@ -401,80 +371,62 @@ select salary, bonus, depadj, - MIN(bonus) over (order by empno), - MAX(depadj) over () + min(bonus) over (order by empno), + max(depadj) over () from ( select *, case when enroll_date < '2008-01-01' - then 2008 - EXTRACT('year' from enroll_date) + then 2008 - extract(year from enroll_date) end * 500 as bonus, - case - when AVG(salary) over (partition by depname) < salary - then 200 - end + case when avg(salary) over (partition by depname) < salary then 200 end as depadj from empsalary ) as s; -select SUM(COUNT(f1)) over () from int4_tbl where f1 = 42; +select sum(count(f1)) over () from int4_tbl where f1 = 42; select ten, - SUM(unique1) + SUM(unique2) as res, - RANK() over (order by SUM(unique1) + SUM(unique2)) as rank + sum(unique1) + sum(unique2) as res, + rank() over (order by sum(unique1) + sum(unique2)) as rank from tenk1 group by ten order by ten; select - FIRST_VALUE(MAX(x)) over (), + first_value(max(x)) over (), y from - ( - select - unique1 as x, - ten + four as y - from - tenk1 - ) - as ss + (select unique1 as x, ten + four as y from tenk1) as ss group by y; select x, - LAG(x, 1) over (order by x), - LEAD(x, 3) over (order by x) + lag(x, 1) over (order by x), + lead(x, 3) over (order by x) from - ( - select - cast(x as numeric) as x - from - generate_series(1, 10) as x - ); + (select cast(x as numeric) as x from generate_series(1, 10) as x); select four, ten, - SUM(ten) over (partition by four order by ten), - LAST_VALUE(ten) over (partition by four order by ten) + sum(ten) over (partition by four order by ten), + last_value(ten) over (partition by four order by ten) from - ( - select distinct ten, four from tenk1 - ) - as ss; + (select distinct ten, four from tenk1) as ss; select four, ten, - SUM(ten) over ( + sum(ten) over ( partition by four order by ten range between @@ -482,7 +434,7 @@ select and current row ), - LAST_VALUE(ten) over ( + last_value(ten) over ( partition by four order by ten range between @@ -491,15 +443,12 @@ select current row ) from - ( - select distinct ten, four from tenk1 - ) - as ss; + (select distinct ten, four from tenk1) as ss; select four, ten, - SUM(ten) over ( + sum(ten) over ( partition by four order by ten range between @@ -507,7 +456,7 @@ select and unbounded following ), - LAST_VALUE(ten) over ( + last_value(ten) over ( partition by four order by ten range between @@ -516,15 +465,12 @@ select unbounded following ) from - ( - select distinct ten, four from tenk1 - ) - as ss; + (select distinct ten, four from tenk1) as ss; select four, ten / 4 as two, - SUM(ten / 4) over ( + sum(ten / 4) over ( partition by four order by ten / 4 range between @@ -532,7 +478,7 @@ select and current row ), - LAST_VALUE(ten / 4) over ( + last_value(ten / 4) over ( partition by four order by ten / 4 range between @@ -541,15 +487,12 @@ select current row ) from - ( - select distinct ten, four from tenk1 - ) - as ss; + (select distinct ten, four from tenk1) as ss; select four, ten / 4 as two, - SUM(ten / 4) over ( + sum(ten / 4) over ( partition by four order by ten / 4 rows between @@ -557,7 +500,7 @@ select and current row ), - LAST_VALUE(ten / 4) over ( + last_value(ten / 4) over ( partition by four order by ten / 4 rows between @@ -566,13 +509,10 @@ select current row ) from - ( - select distinct ten, four from tenk1 - ) - as ss; + (select distinct ten, four from tenk1) as ss; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between current row @@ -587,13 +527,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - current row - and - unbounded following - ), + sum(unique1) over ( rows between current row and unbounded following), unique1, four from @@ -602,13 +536,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 2 preceding - and - 2 following - ), + sum(unique1) over ( rows between 2 preceding and 2 following), unique1, four from @@ -617,13 +545,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 2 preceding - and - 2 following - ), + sum(unique1) over ( rows between 2 preceding and 2 following), unique1, four from @@ -632,7 +554,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( rows between 2 preceding @@ -648,14 +570,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 2 preceding - and - 2 following - exclude group - ), + sum(unique1) over ( rows between 2 preceding and 2 following exclude group), unique1, four from @@ -664,14 +579,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 2 preceding - and - 2 following - exclude ties - ), + sum(unique1) over ( rows between 2 preceding and 2 following exclude ties), unique1, four from @@ -680,7 +588,7 @@ where unique1 < 10; select - FIRST_VALUE(unique1) over ( + first_value(unique1) over ( order by four rows between current row @@ -696,7 +604,7 @@ where unique1 < 10; select - FIRST_VALUE(unique1) over ( + first_value(unique1) over ( order by four rows between current row @@ -712,7 +620,7 @@ where unique1 < 10; select - FIRST_VALUE(unique1) over ( + first_value(unique1) over ( order by four rows between current row @@ -728,7 +636,7 @@ where unique1 < 10; select - LAST_VALUE(unique1) over ( + last_value(unique1) over ( order by four rows between current row @@ -744,7 +652,7 @@ where unique1 < 10; select - LAST_VALUE(unique1) over ( + last_value(unique1) over ( order by four rows between current row @@ -760,7 +668,7 @@ where unique1 < 10; select - LAST_VALUE(unique1) over ( + last_value(unique1) over ( order by four rows between current row @@ -776,13 +684,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 2 preceding - and - 1 preceding - ), + sum(unique1) over ( rows between 2 preceding and 1 preceding), unique1, four from @@ -791,13 +693,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - 1 following - and - 3 following - ), + sum(unique1) over ( rows between 1 following and 3 following), unique1, four from @@ -806,13 +702,7 @@ where unique1 < 10; select - SUM(unique1) over ( - - rows between - unbounded preceding - and - 1 following - ), + sum(unique1) over ( rows between unbounded preceding and 1 following), unique1, four from @@ -821,13 +711,7 @@ where unique1 < 10; select - SUM(unique1) over ( - w - range between - current row - and - unbounded following - ), + sum(unique1) over (w range between current row and unbounded following), unique1, four from @@ -840,7 +724,7 @@ window ); select - SUM(unique1) over ( + sum(unique1) over ( w range between unbounded preceding @@ -860,7 +744,7 @@ window ); select - SUM(unique1) over ( + sum(unique1) over ( w range between unbounded preceding @@ -880,7 +764,7 @@ window ); select - SUM(unique1) over ( + sum(unique1) over ( w range between unbounded preceding @@ -900,9 +784,9 @@ window ); select - FIRST_VALUE(unique1) over w, - NTH_VALUE(unique1, 2) over w as nth_2, - LAST_VALUE(unique1) over w, + first_value(unique1) over w, + nth_value(unique1, 2) over w as nth_2, + last_value(unique1) over w, unique1, four from @@ -919,18 +803,10 @@ window ); select - SUM(unique1) over ( + sum(unique1) over ( order by unique1 rows - ( - select - unique1 - from - tenk1 - order by unique1 - limit 1 - ) + - 1 preceding + (select unique1 from tenk1 order by unique1 limit 1) + 1 preceding ), unique1 from @@ -941,13 +817,7 @@ where create temporary view v_window as select i, - SUM(i) over ( - order by i - rows between - 1 preceding - and - 1 following - ) as sum_rows + sum(i) over (order by i rows between 1 preceding and 1 following) as sum_rows from generate_series(1, 10) as i; @@ -958,7 +828,7 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( + sum(i) over ( order by i rows between 1 preceding @@ -976,7 +846,7 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( + sum(i) over ( order by i rows between 1 preceding @@ -994,14 +864,8 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( - order by i - rows between - 1 preceding - and - 1 following - exclude ties - ) as sum_rows + sum(i) over (order by i rows between 1 preceding and 1 following exclude ties) + as sum_rows from generate_series(1, 10) as i; @@ -1012,13 +876,7 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( - order by i - rows between - 1 preceding - and - 1 following - ) as sum_rows + sum(i) over (order by i rows between 1 preceding and 1 following) as sum_rows from generate_series(1, 10) as i; @@ -1029,13 +887,8 @@ select pg_get_viewdef('v_window'); create or replace temporary view v_window as select i, - SUM(i) over ( - order by i - groups between - 1 preceding - and - 1 following - ) as sum_rows + sum(i) over (order by i groups between 1 preceding and 1 following) + as sum_rows from generate_series(1, 10) as i; @@ -1048,7 +901,7 @@ drop view v_window; create temporary view v_window as select i, - MIN(i) over ( + min(i) over ( order by i range between '1 day' preceding @@ -1056,22 +909,17 @@ as select '10 days' following ) as min_i from - generate_series( - NOW(), - NOW() + cast('100 days' as interval), - '1 hour' - ) - as i; + generate_series(now(), now() + cast('100 days' as interval), '1 hour') as i; select pg_get_viewdef('v_window'); select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding ), unique1, four @@ -1081,12 +929,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four desc range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding ), unique1, four @@ -1096,12 +944,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding ), unique1, four @@ -1111,12 +959,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding exclude current row ), unique1, @@ -1127,12 +975,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding exclude group ), unique1, @@ -1143,12 +991,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(1 as smallint) preceding + cast(1 as int2) preceding exclude ties ), unique1, @@ -1159,12 +1007,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(6 as smallint) following + cast(6 as int2) following exclude ties ), unique1, @@ -1175,12 +1023,12 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four range between - cast(2 as bigint) preceding + cast(2 as int8) preceding and - cast(6 as smallint) following + cast(6 as int2) following exclude group ), unique1, @@ -1191,13 +1039,13 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by four order by unique1 range between - cast(5 as bigint) preceding + cast(5 as int8) preceding and - cast(6 as smallint) following + cast(6 as int2) following ), unique1, four @@ -1207,13 +1055,13 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by four order by unique1 range between - cast(5 as bigint) preceding + cast(5 as int8) preceding and - cast(6 as smallint) following + cast(6 as int2) following exclude current row ), unique1, @@ -1224,7 +1072,7 @@ where unique1 < 10; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -1237,7 +1085,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date desc range between cast('1 year' as interval) preceding @@ -1250,7 +1098,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date desc range between cast('1 year' as interval) following @@ -1263,7 +1111,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -1277,7 +1125,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -1291,7 +1139,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -1305,21 +1153,21 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by salary range between 1000 preceding and 1000 following ), - LEAD(salary) over ( + lead(salary) over ( order by salary range between 1000 preceding and 1000 following ), - NTH_VALUE(salary, 1) over ( + nth_value(salary, 1) over ( order by salary range between 1000 preceding @@ -1331,14 +1179,14 @@ from empsalary; select - LAST_VALUE(salary) over ( + last_value(salary) over ( order by salary range between 1000 preceding and 1000 following ), - LAG(salary) over ( + lag(salary) over ( order by salary range between 1000 preceding @@ -1350,7 +1198,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by salary range between 1000 following @@ -1358,7 +1206,7 @@ select 3000 following exclude current row ), - LEAD(salary) over ( + lead(salary) over ( order by salary range between 1000 following @@ -1366,7 +1214,7 @@ select 3000 following exclude ties ), - NTH_VALUE(salary, 1) over ( + nth_value(salary, 1) over ( order by salary range between 1000 following @@ -1379,7 +1227,7 @@ from empsalary; select - LAST_VALUE(salary) over ( + last_value(salary) over ( order by salary range between 1000 following @@ -1387,7 +1235,7 @@ select 3000 following exclude group ), - LAG(salary) over ( + lag(salary) over ( order by salary range between 1000 following @@ -1400,7 +1248,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1408,7 +1256,7 @@ select cast('1 year' as interval) following exclude ties ), - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1421,7 +1269,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1429,7 +1277,7 @@ select cast('1 year' as interval) following exclude ties ), - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1443,7 +1291,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1451,7 +1299,7 @@ select cast('1 year' as interval) following exclude group ), - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1465,7 +1313,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1473,7 +1321,7 @@ select cast('1 year' as interval) following exclude current row ), - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date range between unbounded preceding @@ -1489,17 +1337,11 @@ from select x, y, - FIRST_VALUE(y) over w, - LAST_VALUE(y) over w + first_value(y) over w, + last_value(y) over w from ( - select - x, - x as y - from - generate_series(1, 5) as x - union all - select null, 42 + select x, x as y from generate_series(1, 5) as x union all select null, 42 union all select null, 43 ) @@ -1516,17 +1358,11 @@ window select x, y, - FIRST_VALUE(y) over w, - LAST_VALUE(y) over w + first_value(y) over w, + last_value(y) over w from ( - select - x, - x as y - from - generate_series(1, 5) as x - union all - select null, 42 + select x, x as y from generate_series(1, 5) as x union all select null, 42 union all select null, 43 ) @@ -1543,17 +1379,11 @@ window select x, y, - FIRST_VALUE(y) over w, - LAST_VALUE(y) over w + first_value(y) over w, + last_value(y) over w from ( - select - x, - x as y - from - generate_series(1, 5) as x - union all - select null, 42 + select x, x as y from generate_series(1, 5) as x union all select null, 42 union all select null, 43 ) @@ -1570,17 +1400,11 @@ window select x, y, - FIRST_VALUE(y) over w, - LAST_VALUE(y) over w + first_value(y) over w, + last_value(y) over w from ( - select - x, - x as y - from - generate_series(1, 5) as x - union all - select null, 42 + select x, x as y from generate_series(1, 5) as x union all select null, 42 union all select null, 43 ) @@ -1595,13 +1419,7 @@ window ); select - SUM(unique1) over ( - - rows between - x preceding - and - x following - ), + sum(unique1) over ( rows between x preceding and x following), unique1, four from @@ -1618,24 +1436,18 @@ returns table ( c int ) language sql -as $function$ -SELECT sum(unique1) over (rows between x preceding and x following), +as $$ + SELECT sum(unique1) over (rows between x preceding and x following), unique1, four FROM tenk1 WHERE unique1 < 10; -$function$; +$$; select * from unbounded_syntax_test1a(2); select * from unbounded_syntax_test1b(2); select - SUM(unique1) over ( - - rows between - unbounded preceding - and - unbounded following - ), + sum(unique1) over ( rows between unbounded preceding and unbounded following), unique1, four from @@ -1652,11 +1464,11 @@ returns table ( c int ) language sql -as $function$ -SELECT sum(unique1) over (rows between unbounded preceding and unbounded following), +as $$ + SELECT sum(unique1) over (rows between unbounded preceding and unbounded following), unique1, four FROM tenk1 WHERE unique1 < 10; -$function$; +$$; select * from unbounded_syntax_test2a(2); @@ -1675,13 +1487,7 @@ immutable return x; select - SUM(unique1) over ( - - rows between - 1 preceding - and - 1 following - ), + sum(unique1) over ( rows between 1 preceding and 1 following), unique1, four from @@ -1690,7 +1496,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( rows between unbounded(1) preceding @@ -1705,7 +1511,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( rows between unbounded.x preceding @@ -1724,7 +1530,7 @@ drop function unbounded; select x, - LAST_VALUE(x) over ( + last_value(x) over ( order by cast(x as smallint) range between current row @@ -1736,7 +1542,7 @@ from select x, - LAST_VALUE(x) over ( + last_value(x) over ( order by cast(x as smallint) desc range between current row @@ -1748,77 +1554,38 @@ from select x, - LAST_VALUE(x) over ( - order by x - range between - current row - and - 4 following - ) + last_value(x) over (order by x range between current row and 4 following) from - generate_series(2147483644, 2147483646) - as x; + generate_series(2147483644, 2147483646) as x; select x, - LAST_VALUE(x) over ( - order by x desc - range between - current row - and - 5 following - ) + last_value(x) over (order by x desc range between current row and 5 following) from - generate_series( - -2147483646, - -2147483644 - ) - as x; + generate_series(-2147483646, -2147483644) as x; select x, - LAST_VALUE(x) over ( - order by x - range between - current row - and - 4 following - ) + last_value(x) over (order by x range between current row and 4 following) from - generate_series( - 9223372036854775804, - 9223372036854775806 - ) - as x; + generate_series(9223372036854775804, 9223372036854775806) as x; select x, - LAST_VALUE(x) over ( - order by x desc - range between - current row - and - 5 following - ) + last_value(x) over (order by x desc range between current row and 5 following) from - generate_series( - -9223372036854775806, - -9223372036854775804 - ) - as x; + generate_series(-9223372036854775806, -9223372036854775804) as x; create temporary table numerics ( id int, - f_float4 real, - f_float8 double precision, + f_float4 float4, + f_float8 float8, f_numeric numeric ); insert into numerics values - ( - 0, '-infinity', '-infinity', '-infinity' - ), + (0, '-infinity', '-infinity', '-infinity'), (1, -3, -3, -3), (2, -1, -1, -1), (3, 0, 0, 0), @@ -1832,8 +1599,8 @@ values select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1848,8 +1615,8 @@ window select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1858,14 +1625,14 @@ window range between 1 preceding and - cast(1.1 as real) following + cast(1.1 as float4) following ); select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1880,8 +1647,8 @@ window select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1896,8 +1663,8 @@ window select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1912,8 +1679,8 @@ window select id, f_float4, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1928,8 +1695,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1944,8 +1711,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1954,14 +1721,14 @@ window range between 1 preceding and - cast(1.1 as double precision) following + cast(1.1 as float8) following ); select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1976,8 +1743,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -1992,8 +1759,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2008,8 +1775,8 @@ window select id, f_float8, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2024,8 +1791,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2040,8 +1807,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2056,8 +1823,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2066,14 +1833,14 @@ window range between 1 preceding and - cast(1.1 as double precision) following + cast(1.1 as float8) following ); select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2088,8 +1855,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2104,8 +1871,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2120,8 +1887,8 @@ window select id, f_numeric, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from numerics window @@ -2136,22 +1903,15 @@ window create temporary table datetimes ( id int, f_time time, - f_timetz time with time zone, + f_timetz timetz, f_interval interval, - f_timestamptz timestamp with time zone, + f_timestamptz timestamptz, f_timestamp timestamp ); insert into datetimes values - ( - 0, - '10:00', - '10:00 BST', - '-infinity', - '-infinity', - '-infinity' - ), + (0, '10:00', '10:00 BST', '-infinity', '-infinity', '-infinity'), ( 1, '11:00', @@ -2232,20 +1992,13 @@ values '2008-10-19 10:23:54+01', '2008-10-19 10:23:54' ), - ( - 11, - '21:00', - '21:00 BST', - 'infinity', - 'infinity', - 'infinity' - ); + (11, '21:00', '21:00 BST', 'infinity', 'infinity', 'infinity'); select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2260,8 +2013,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2276,8 +2029,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2292,8 +2045,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2308,8 +2061,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2324,8 +2077,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2340,8 +2093,8 @@ window select id, f_time, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2356,8 +2109,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2372,8 +2125,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2388,8 +2141,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2404,8 +2157,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2420,8 +2173,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2436,8 +2189,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2452,8 +2205,8 @@ window select id, f_timetz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2468,8 +2221,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2484,8 +2237,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2500,8 +2253,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2516,8 +2269,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2532,8 +2285,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2548,8 +2301,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2564,8 +2317,8 @@ window select id, f_interval, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2580,8 +2333,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2596,8 +2349,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2612,8 +2365,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2628,8 +2381,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2644,8 +2397,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2660,8 +2413,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2676,8 +2429,8 @@ window select id, f_timestamptz, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2692,8 +2445,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2708,8 +2461,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2724,8 +2477,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2740,8 +2493,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2756,8 +2509,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2772,8 +2525,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2788,8 +2541,8 @@ window select id, f_timestamp, - FIRST_VALUE(id) over w, - LAST_VALUE(id) over w + first_value(id) over w, + last_value(id) over w from datetimes window @@ -2802,7 +2555,7 @@ window ); select - SUM(salary) over ( + sum(salary) over ( order by enroll_date, salary range between @@ -2817,7 +2570,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( range between cast('1 year' as interval) preceding @@ -2831,7 +2584,7 @@ from empsalary; select - SUM(salary) over ( + sum(salary) over ( order by depname range between cast('1 year' as interval) preceding @@ -2845,7 +2598,7 @@ from empsalary; select - MAX(enroll_date) over ( + max(enroll_date) over ( order by enroll_date range between 1 preceding @@ -2859,7 +2612,7 @@ from empsalary; select - MAX(enroll_date) over ( + max(enroll_date) over ( order by salary range between -1 preceding @@ -2873,7 +2626,7 @@ from empsalary; select - MAX(enroll_date) over ( + max(enroll_date) over ( order by salary range between 1 preceding @@ -2887,7 +2640,7 @@ from empsalary; select - MAX(enroll_date) over ( + max(enroll_date) over ( order by salary range between cast('1 year' as interval) preceding @@ -2901,7 +2654,7 @@ from empsalary; select - MAX(enroll_date) over ( + max(enroll_date) over ( order by enroll_date range between cast('1 year' as interval) preceding @@ -2915,7 +2668,7 @@ from empsalary; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between unbounded preceding @@ -2930,7 +2683,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between unbounded preceding @@ -2945,7 +2698,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between current row @@ -2960,7 +2713,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between 1 preceding @@ -2975,7 +2728,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between 1 following @@ -2990,7 +2743,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between unbounded preceding @@ -3005,13 +2758,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 2 preceding - and - 1 preceding - ), + sum(unique1) over (order by four groups between 2 preceding and 1 preceding), unique1, four from @@ -3020,13 +2767,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 2 preceding - and - 1 following - ), + sum(unique1) over (order by four groups between 2 preceding and 1 following), unique1, four from @@ -3035,13 +2776,7 @@ where unique1 < 10; select - SUM(unique1) over ( - order by four - groups between - 0 preceding - and - 0 following - ), + sum(unique1) over (order by four groups between 0 preceding and 0 following), unique1, four from @@ -3050,7 +2785,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between 2 preceding @@ -3066,7 +2801,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between 2 preceding @@ -3082,7 +2817,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( order by four groups between 2 preceding @@ -3098,7 +2833,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by ten order by four groups between @@ -3115,7 +2850,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by ten order by four groups between @@ -3133,7 +2868,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by ten order by four groups between @@ -3151,7 +2886,7 @@ where unique1 < 10; select - SUM(unique1) over ( + sum(unique1) over ( partition by ten order by four groups between @@ -3169,21 +2904,21 @@ where unique1 < 10; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date groups between 1 preceding and 1 following ), - LEAD(salary) over ( + lead(salary) over ( order by enroll_date groups between 1 preceding and 1 following ), - NTH_VALUE(salary, 1) over ( + nth_value(salary, 1) over ( order by enroll_date groups between 1 preceding @@ -3196,14 +2931,14 @@ from empsalary; select - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date groups between 1 preceding and 1 following ), - LAG(salary) over ( + lag(salary) over ( order by enroll_date groups between 1 preceding @@ -3216,7 +2951,7 @@ from empsalary; select - FIRST_VALUE(salary) over ( + first_value(salary) over ( order by enroll_date groups between 1 following @@ -3224,7 +2959,7 @@ select 3 following exclude current row ), - LEAD(salary) over ( + lead(salary) over ( order by enroll_date groups between 1 following @@ -3232,7 +2967,7 @@ select 3 following exclude ties ), - NTH_VALUE(salary, 1) over ( + nth_value(salary, 1) over ( order by enroll_date groups between 1 following @@ -3246,7 +2981,7 @@ from empsalary; select - LAST_VALUE(salary) over ( + last_value(salary) over ( order by enroll_date groups between 1 following @@ -3254,7 +2989,7 @@ select 3 following exclude group ), - LAG(salary) over ( + lag(salary) over ( order by enroll_date groups between 1 following @@ -3267,14 +3002,10 @@ select from empsalary; -with -cte (x) -as ( - select * from generate_series(1, 35, 2) -) +with cte (x) as (select * from generate_series(1, 35, 2)) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3286,14 +3017,10 @@ window 1 following ); -with -cte (x) -as ( - select * from generate_series(1, 35, 2) -) +with cte (x) as (select * from generate_series(1, 35, 2)) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3305,14 +3032,10 @@ window 1 following ); -with -cte (x) -as ( - select * from generate_series(1, 35, 2) -) +with cte (x) as (select * from generate_series(1, 35, 2)) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3327,15 +3050,13 @@ window with cte (x) as ( - select 1 union all select 1 - union all - select 1 + select 1 union all select 1 union all select 1 union all select * from generate_series(5, 49, 2) ) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3350,15 +3071,13 @@ window with cte (x) as ( - select 1 union all select 1 - union all - select 1 + select 1 union all select 1 union all select 1 union all select * from generate_series(5, 49, 2) ) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3373,15 +3092,13 @@ window with cte (x) as ( - select 1 union all select 1 - union all - select 1 + select 1 union all select 1 union all select 1 union all select * from generate_series(5, 49, 2) ) select x, - SUM(x) over w + sum(x) over w from cte window @@ -3394,32 +3111,21 @@ window ); select - COUNT(*) over (partition by four) + count(*) over (partition by four) from - ( - select * from tenk1 - union all - select * from tenk2 - ) - as s + (select * from tenk1 union all select * from tenk2) as s limit 0; create temporary table t1 ( f1 int, - f2 bigint + f2 int8 ); insert into t1 values (1, 1), (1, 2), (2, 2); select f1, - SUM(f1) over ( - partition by f1 - range between - 1 preceding - and - 1 following - ) + sum(f1) over (partition by f1 range between 1 preceding and 1 following) from t1 where @@ -3427,7 +3133,7 @@ where select f1, - SUM(f1) over ( + sum(f1) over ( partition by f1 order by f2 range between @@ -3442,7 +3148,7 @@ where select f1, - SUM(f1) over ( + sum(f1) over ( partition by f1 order by f2 range between @@ -3457,7 +3163,7 @@ where select f1, - SUM(f1) over ( + sum(f1) over ( partition by f1, f1 order by f2 @@ -3473,7 +3179,7 @@ where select f1, - SUM(f1) over ( + sum(f1) over ( partition by f1, f2 order by f2 @@ -3489,13 +3195,7 @@ where select f1, - SUM(f1) over ( - partition by f1 - groups between - 1 preceding - and - 1 following - ) + sum(f1) over (partition by f1 groups between 1 preceding and 1 following) from t1 where @@ -3503,7 +3203,7 @@ where select f1, - SUM(f1) over ( + sum(f1) over ( partition by f1 order by f2 groups between @@ -3518,7 +3218,7 @@ where select f1, - SUM(f1) over ( + sum(f1) over ( partition by f1 order by f2 groups between @@ -3533,7 +3233,7 @@ where select f1, - SUM(f1) over ( + sum(f1) over ( partition by f1, f1 order by f2 @@ -3549,7 +3249,7 @@ where select f1, - SUM(f1) over ( + sum(f1) over ( partition by f1, f2 order by f2 @@ -3563,28 +3263,25 @@ from where f1 = f2; -select RANK() over (order by length('abc')); +select rank() over (order by length('abc')); -select RANK() over (order by RANK() over (order by random())); +select rank() over (order by rank() over (order by random())); -select * from empsalary where ROW_NUMBER() over (order by salary) < 10; +select * from empsalary where row_number() over (order by salary) < 10; select * from - empsalary - inner join - tenk1 - on ROW_NUMBER() over (order by salary) < 10; + empsalary inner join tenk1 on row_number() over (order by salary) < 10; -select RANK() over (order by 1), COUNT(*) from empsalary group by 1; +select rank() over (order by 1), count(*) from empsalary group by 1; -delete from empsalary where RANK() over (order by random()) > 10; +delete from empsalary where rank() over (order by random()) > 10; -delete from empsalary returning RANK() over (order by random()); +delete from empsalary returning rank() over (order by random()); select - COUNT(*) over w + count(*) over w from tenk1 window @@ -3595,24 +3292,18 @@ window order by unique1 ); -select COUNT() over () from tenk1; +select count() over () from tenk1; select generate_series(1, 100) over () from empsalary; -select NTILE(0) over (order by ten), ten, four from tenk1; +select ntile(0) over (order by ten), ten, four from tenk1; -select NTH_VALUE(four, 0) over (order by ten), ten, four from tenk1; +select nth_value(four, 0) over (order by ten), ten, four from tenk1; select - SUM(salary), - ROW_NUMBER() over (order by depname), - SUM( - SUM( - salary - ) - filter (where - enroll_date > '2007-01-01') - ) + sum(salary), + row_number() over (order by depname), + sum(sum(salary) filter (where enroll_date > '2007-01-01')) filter (where depname <> 'sales') over (order by depname desc) as filtered_sum, depname @@ -3623,11 +3314,8 @@ group by depname; select empno, depname, - ROW_NUMBER() over ( - partition by depname - order by enroll_date - ) as rn, - RANK() over ( + row_number() over (partition by depname order by enroll_date) as rn, + rank() over ( partition by depname order by enroll_date rows between @@ -3635,7 +3323,7 @@ select and unbounded following ) as rnk, - DENSE_RANK() over ( + dense_rank() over ( partition by depname order by enroll_date range between @@ -3643,7 +3331,7 @@ select and current row ) as drnk, - NTILE(10) over ( + ntile(10) over ( partition by depname order by enroll_date range between @@ -3651,7 +3339,7 @@ select and unbounded following ) as nt, - PERCENT_RANK() over ( + percent_rank() over ( partition by depname order by enroll_date rows between @@ -3659,7 +3347,7 @@ select and unbounded following ) as pr, - CUME_DIST() over ( + cume_dist() over ( partition by depname order by enroll_date range between @@ -3673,11 +3361,8 @@ from select empno, depname, - ROW_NUMBER() over ( - partition by depname - order by enroll_date - ) as rn, - RANK() over ( + row_number() over (partition by depname order by enroll_date) as rn, + rank() over ( partition by depname order by enroll_date rows between @@ -3685,7 +3370,7 @@ select and unbounded following ) as rnk, - COUNT(*) over ( + count(*) over ( partition by depname order by enroll_date range between @@ -3699,11 +3384,8 @@ from select empno, depname, - ROW_NUMBER() over ( - partition by depname - order by enroll_date - ) as rn, - RANK() over ( + row_number() over (partition by depname order by enroll_date) as rn, + rank() over ( partition by depname order by enroll_date rows between @@ -3711,7 +3393,7 @@ select and unbounded following ) as rnk, - COUNT(*) over ( + count(*) over ( partition by depname order by enroll_date range between @@ -3728,8 +3410,8 @@ from ( select depname, - SUM(salary) over (partition by depname) as depsalary, - MIN(salary) over (partition by depname || 'A', depname) as depminsalary + sum(salary) over (partition by depname) as depsalary, + min(salary) over (partition by depname || 'A', depname) as depminsalary from empsalary ) @@ -3743,8 +3425,8 @@ from ( select depname, - SUM(salary) over (partition by enroll_date) as enroll_salary, - MIN(salary) over (partition by depname) as depminsalary + sum(salary) over (partition by enroll_date) as enroll_salary, + min(salary) over (partition by depname) as depminsalary from empsalary ) @@ -3755,56 +3437,28 @@ where select * from - ( - select - empno, - ROW_NUMBER() over (order by empno) as rn - from - empsalary - ) - as emp + (select empno, row_number() over (order by empno) as rn from empsalary) as emp where rn < 3; select * from - ( - select - empno, - ROW_NUMBER() over (order by empno) as rn - from - empsalary - ) - as emp + (select empno, row_number() over (order by empno) as rn from empsalary) as emp where rn < 3; select * from - ( - select - empno, - ROW_NUMBER() over (order by empno) as rn - from - empsalary - ) - as emp + (select empno, row_number() over (order by empno) as rn from empsalary) as emp where 3 > rn; select * from - ( - select - empno, - ROW_NUMBER() over (order by empno) as rn - from - empsalary - ) - as emp + (select empno, row_number() over (order by empno) as rn from empsalary) as emp where 2 >= rn; @@ -3812,12 +3466,7 @@ select * from ( - select - empno, - salary, - RANK() over (order by salary desc) as r - from - empsalary + select empno, salary, rank() over (order by salary desc) as r from empsalary ) as emp where @@ -3827,12 +3476,7 @@ select * from ( - select - empno, - salary, - RANK() over (order by salary desc) as r - from - empsalary + select empno, salary, rank() over (order by salary desc) as r from empsalary ) as emp where @@ -3845,7 +3489,7 @@ from select empno, salary, - DENSE_RANK() over (order by salary desc) as dr + dense_rank() over (order by salary desc) as dr from empsalary ) @@ -3860,7 +3504,7 @@ from select empno, salary, - DENSE_RANK() over (order by salary desc) as dr + dense_rank() over (order by salary desc) as dr from empsalary ) @@ -3875,7 +3519,7 @@ from select empno, salary, - COUNT(*) over (order by salary desc) as c + count(*) over (order by salary desc) as c from empsalary ) @@ -3890,7 +3534,7 @@ from select empno, salary, - COUNT(*) over (order by salary desc) as c + count(*) over (order by salary desc) as c from empsalary ) @@ -3905,7 +3549,7 @@ from select empno, salary, - COUNT(empno) over (order by salary desc) as c + count(empno) over (order by salary desc) as c from empsalary ) @@ -3920,7 +3564,7 @@ from select empno, salary, - COUNT(empno) over (order by salary desc) as c + count(empno) over (order by salary desc) as c from empsalary ) @@ -3935,7 +3579,7 @@ from select empno, salary, - COUNT(*) over ( + count(*) over ( order by salary desc rows between current row @@ -3952,15 +3596,7 @@ where select * from - ( - select - empno, - salary, - COUNT(*) over () as c - from - empsalary - ) - as emp + (select empno, salary, count(*) over () as c from empsalary) as emp where 11 <= c; @@ -3971,8 +3607,8 @@ from select empno, salary, - COUNT(*) over (order by salary desc) as c, - DENSE_RANK() over (order by salary desc) as dr + count(*) over (order by salary desc) as c, + dense_rank() over (order by salary desc) as dr from empsalary ) @@ -3987,7 +3623,7 @@ from select empno, depname, - ROW_NUMBER() over (partition by depname order by empno) as rn + row_number() over (partition by depname order by empno) as rn from empsalary ) @@ -4002,7 +3638,7 @@ from select empno, depname, - ROW_NUMBER() over (partition by depname order by empno) as rn + row_number() over (partition by depname order by empno) as rn from empsalary ) @@ -4018,7 +3654,7 @@ from select empno, depname, - ROW_NUMBER() over (partition by depname order by empno) as rn + row_number() over (partition by depname order by empno) as rn from empsalary ) @@ -4034,10 +3670,7 @@ from empno, depname, salary, - COUNT(empno) over ( - partition by depname - order by salary desc - ) as c + count(empno) over (partition by depname order by salary desc) as c from empsalary ) @@ -4053,10 +3686,7 @@ from empno, depname, salary, - COUNT(empno) over ( - partition by depname - order by salary desc - ) as c + count(empno) over (partition by depname order by salary desc) as c from empsalary ) @@ -4068,13 +3698,7 @@ select * from ( - select - empno, - depname, - salary, - COUNT(empno) over () as c - from - empsalary + select empno, depname, salary, count(empno) over () as c from empsalary ) as emp where @@ -4085,8 +3709,8 @@ select from ( select - ROW_NUMBER() over (partition by salary) as rn, - LEAD(depname) over (partition by salary) || ' Department' as n_dep + row_number() over (partition by salary) as rn, + lead(depname) over (partition by salary) || ' Department' as n_dep from empsalary ) @@ -4100,11 +3724,11 @@ from ( select *, - COUNT(salary) over (partition by depname || '') as c1, - ROW_NUMBER() over (partition by depname) as rn, - COUNT(*) over (partition by depname) as c2, - COUNT(*) over (partition by '' || depname) as c3, - NTILE(2) over (partition by depname) as nt + count(salary) over (partition by depname || '') as c1, + row_number() over (partition by depname) as rn, + count(*) over (partition by depname) as c2, + count(*) over (partition by '' || depname) as c3, + ntile(2) over (partition by depname) as nt from empsalary ) @@ -4118,11 +3742,11 @@ from ( select *, - COUNT(salary) over (partition by depname || '') as c1, - ROW_NUMBER() over (partition by depname) as rn, - COUNT(*) over (partition by depname) as c2, - COUNT(*) over (partition by '' || depname) as c3, - NTILE(2) over (partition by depname) as nt + count(salary) over (partition by depname || '') as c1, + row_number() over (partition by depname) as rn, + count(*) over (partition by depname) as c2, + count(*) over (partition by '' || depname) as c3, + ntile(2) over (partition by depname) as nt from empsalary ) @@ -4135,12 +3759,9 @@ select from ( select - NTILE(e2.salary) over (partition by e1.depname) as c + ntile(e2.salary) over (partition by e1.depname) as c from - empsalary as e1 - left outer join - empsalary as e2 - on true + empsalary as e1 left outer join empsalary as e2 on true where e1.empno = e2.empno ) @@ -4151,13 +3772,7 @@ where select 1 from - ( - select - NTILE(s1.x) over () as c - from - (select (select 1) as x) as s1 - ) - as s + (select ntile(s1.x) over () as c from (select (select 1) as x) as s1) as s where s.c = 1; @@ -4168,7 +3783,7 @@ from select empno, salary, - COUNT(*) over ( + count(*) over ( order by salary desc rows between current row @@ -4186,12 +3801,7 @@ select * from ( - select - empno, - salary, - COUNT(*) over (order by salary) as c - from - empsalary + select empno, salary, count(*) over (order by salary) as c from empsalary ) as emp where @@ -4204,7 +3814,7 @@ from select empno, salary, - COUNT(random()) over (order by empno desc) as c + count(random()) over (order by empno desc) as c from empsalary ) @@ -4219,7 +3829,7 @@ from select empno, salary, - COUNT((select 1)) over (order by empno desc) as c + count((select 1)) over (order by empno desc) as c from empsalary ) @@ -4233,12 +3843,9 @@ from ( select depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over ( - partition by depname, - empno - order by enroll_date - ) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname, empno order by enroll_date) + as depminsalary from empsalary ) @@ -4250,11 +3857,8 @@ select empno, enroll_date, depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over ( - partition by depname - order by enroll_date - ) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname order by enroll_date) as depminsalary from empsalary order by depname, @@ -4264,11 +3868,8 @@ select empno, enroll_date, depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over ( - partition by depname - order by enroll_date - ) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname order by enroll_date) as depminsalary from empsalary order by depname, @@ -4280,11 +3881,8 @@ select distinct empno, enroll_date, depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over ( - partition by depname - order by enroll_date - ) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname order by enroll_date) as depminsalary from empsalary order by depname, @@ -4294,11 +3892,8 @@ select distinct empno, enroll_date, depname, - SUM(salary) over (partition by depname order by empno) as depsalary, - MIN(salary) over ( - partition by depname - order by enroll_date - ) as depminsalary + sum(salary) over (partition by depname order by empno) as depsalary, + min(salary) over (partition by depname order by enroll_date) as depminsalary from empsalary order by depname, @@ -4307,17 +3902,8 @@ order by depname, reset enable_hashagg; select - LEAD(1) over ( - partition by depname - order by salary, - enroll_date - ), - LAG(1) over ( - partition by depname - order by salary, - enroll_date, - empno - ) + lead(1) over (partition by depname order by salary, enroll_date), + lag(1) over (partition by depname order by salary, enroll_date, empno) from empsalary; @@ -4330,14 +3916,10 @@ from empno, salary, enroll_date, - ROW_NUMBER() over ( - partition by depname - order by enroll_date - ) as first_emp, - ROW_NUMBER() over ( - partition by depname - order by enroll_date desc - ) as last_emp + row_number() over (partition by depname order by enroll_date) + as first_emp, + row_number() over (partition by depname order by enroll_date desc) + as last_emp from empsalary ) @@ -4354,14 +3936,10 @@ from empno, salary, enroll_date, - ROW_NUMBER() over ( - partition by depname - order by enroll_date - ) as first_emp, - ROW_NUMBER() over ( - partition by depname - order by enroll_date desc - ) as last_emp + row_number() over (partition by depname order by enroll_date) + as first_emp, + row_number() over (partition by depname order by enroll_date desc) + as last_emp from empsalary ) @@ -4377,67 +3955,39 @@ language internal window immutable strict -as $function$ -window_nth_value -$function$; +as 'window_nth_value'; select - nth_value_def("n" := 2, "val" := ten) over (partition by four), + nth_value_def(n := 2, val := ten) over (partition by four), ten, four from - ( - select - * - from - tenk1 - where - unique2 < 10 - order by four, - ten - ) - as s; + (select * from tenk1 where unique2 < 10 order by four, ten) as s; select nth_value_def(ten) over (partition by four), ten, four from - ( - select - * - from - tenk1 - where - unique2 < 10 - order by four, - ten - ) - as s; + (select * from tenk1 where unique2 < 10 order by four, ten) as s; create function logging_sfunc_nonstrict(text, anyelement) returns text language sql immutable -as $function$ -SELECT COALESCE($1, '') || '*' || quote_nullable($2) -$function$; +as $$ SELECT COALESCE($1, '') || '*' || quote_nullable($2) $$; create function logging_msfunc_nonstrict(text, anyelement) returns text language sql immutable -as $function$ -SELECT COALESCE($1, '') || '+' || quote_nullable($2) -$function$; +as $$ SELECT COALESCE($1, '') || '+' || quote_nullable($2) $$; create function logging_minvfunc_nonstrict(text, anyelement) returns text language sql immutable -as $function$ -SELECT $1 || '-' || quote_nullable($2) -$function$; +as $$ SELECT $1 || '-' || quote_nullable($2) $$; create aggregate logging_agg_nonstrict ( anyelement @@ -4466,27 +4016,21 @@ returns text language sql immutable strict -as $function$ -SELECT $1 || '*' || quote_nullable($2) -$function$; +as $$ SELECT $1 || '*' || quote_nullable($2) $$; create function logging_msfunc_strict(text, anyelement) returns text language sql immutable strict -as $function$ -SELECT $1 || '+' || quote_nullable($2) -$function$; +as $$ SELECT $1 || '+' || quote_nullable($2) $$; create function logging_minvfunc_strict(text, anyelement) returns text language sql immutable strict -as $function$ -SELECT $1 || '-' || quote_nullable($2) -$function$; +as $$ SELECT $1 || '-' || quote_nullable($2) $$; create aggregate logging_agg_strict ( text @@ -4511,9 +4055,7 @@ create aggregate logging_agg_strict_initcond ( ); select - cast(p as text) || ',' || - cast(i as text) || - ':' || + cast(p as text) || ',' || cast(i as text) || ':' || coalesce(cast(v as text), 'NULL') as row, logging_agg_nonstrict(v) over wnd as nstrict, @@ -4547,27 +4089,14 @@ order by p, i; select - cast(p as text) || ',' || - cast(i as text) || - ':' || - case - when f - then coalesce(cast(v as text), 'NULL') - else '-' - end + cast(p as text) || ',' || cast(i as text) || ':' || + case when f then coalesce(cast(v as text), 'NULL') else '-' end as row, - logging_agg_nonstrict(v) - filter (where - f) over wnd as nstrict_filt, - logging_agg_nonstrict_initcond(v) - filter (where - f) over wnd as nstrict_init_filt, - logging_agg_strict(cast(v as text)) - filter (where - f) over wnd as strict_filt, - logging_agg_strict_initcond(v) - filter (where - f) over wnd as strict_init_filt + logging_agg_nonstrict(v) filter (where f) over wnd as nstrict_filt, + logging_agg_nonstrict_initcond(v) filter (where f) over wnd + as nstrict_init_filt, + logging_agg_strict(cast(v as text)) filter (where f) over wnd as strict_filt, + logging_agg_strict_initcond(v) filter (where f) over wnd as strict_init_filt from ( values @@ -4595,22 +4124,13 @@ order by p, i; select - cast(i as text) || ':' || - coalesce(cast(v as text), 'NULL') - as row, + cast(i as text) || ':' || coalesce(cast(v as text), 'NULL') as row, logging_agg_strict(cast(v as text)) over wnd as inverse, logging_agg_strict( - cast(v as text) || - case - when random() < 0 then '?' - else '' - end + cast(v as text) || case when random() < 0 then '?' else '' end ) over wnd as noinverse from - ( - values (1, 'a'), (2, 'b'), (3, 'c') - ) - as t (i, v) + (values (1, 'a'), (2, 'b'), (3, 'c')) as t (i, v) window wnd as ( order by i @@ -4622,20 +4142,12 @@ window order by i; select - cast(i as text) || ':' || - coalesce(cast(v as text), 'NULL') - as row, - logging_agg_strict(cast(v as text)) - filter (where - true) over wnd as inverse, - logging_agg_strict(cast(v as text)) - filter (where - random() >= 0) over wnd as noinverse + cast(i as text) || ':' || coalesce(cast(v as text), 'NULL') as row, + logging_agg_strict(cast(v as text)) filter (where true) over wnd as inverse, + logging_agg_strict(cast(v as text)) filter (where random() >= 0) over wnd + as noinverse from - ( - values (1, 'a'), (2, 'b'), (3, 'c') - ) - as t (i, v) + (values (1, 'a'), (2, 'b'), (3, 'c')) as t (i, v) window wnd as ( order by i @@ -4649,10 +4161,7 @@ order by i; select logging_agg_strict(cast(v as text)) over wnd from - ( - values (1, 'a'), (2, 'b'), (3, 'c') - ) - as t (i, v) + (values (1, 'a'), (2, 'b'), (3, 'c')) as t (i, v) window wnd as ( order by i @@ -4663,20 +4172,18 @@ window ) order by i; -create function sum_int_randrestart_minvfunc(int, int) -returns int +create function sum_int_randrestart_minvfunc(int4, int4) +returns int4 language sql strict -as $function$ -SELECT CASE WHEN random() < 0.2 THEN NULL ELSE $1 - $2 END -$function$; +as $$ SELECT CASE WHEN random() < 0.2 THEN NULL ELSE $1 - $2 END $$; create aggregate sum_int_randomrestart ( - int + int4 ) ( - stype = int, + stype = int4, sfunc = int4pl, - mstype = int, + mstype = int4, msfunc = int4pl, minvfunc = sum_int_randrestart_minvfunc ); @@ -4684,17 +4191,13 @@ create aggregate sum_int_randomrestart ( with vs as ( - select - i, - cast(random() * 100 as int) as v - from - generate_series(1, 100) as i + select i, cast(random() * 100 as int4) as v from generate_series(1, 100) as i ), sum_following as ( select i, - SUM(v) over ( + sum(v) over ( order by i desc rows between unbounded preceding @@ -4708,15 +4211,10 @@ select distinct sum_following.s = sum_int_randomrestart(v) over fwd as eq1, -sum_following.s = sum_int_randomrestart(-v) over fwd as eq2, 100 * 3 + (vs.i - 1) * 3 = - length( - logging_agg_nonstrict(cast('' as text)) over fwd - ) + length(logging_agg_nonstrict(cast('' as text)) over fwd) as eq3 from - vs - inner join - sum_following - on sum_following.i = vs.i + vs inner join sum_following on sum_following.i = vs.i window fwd as ( order by vs.i @@ -4728,7 +4226,7 @@ window select i, - AVG(cast(v as bigint)) over ( + avg(cast(v as bigint)) over ( order by i rows between current row @@ -4736,18 +4234,11 @@ select unbounded following ) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - AVG(cast(v as int)) over ( + avg(cast(v as int)) over ( order by i rows between current row @@ -4755,18 +4246,11 @@ select unbounded following ) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - AVG(cast(v as smallint)) over ( + avg(cast(v as smallint)) over ( order by i rows between current row @@ -4774,18 +4258,11 @@ select unbounded following ) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - AVG(cast(v as numeric)) over ( + avg(cast(v as numeric)) over ( order by i rows between current row @@ -4793,18 +4270,11 @@ select unbounded following ) from - ( - values - (1, 1.5), - (2, 2.5), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1.5), (2, 2.5), (3, null), (4, null)) as t (i, v); select i, - AVG(cast(v as interval)) over ( + avg(cast(v as interval)) over ( order by i rows between current row @@ -4812,57 +4282,22 @@ select unbounded following ) from - ( - values - (1, '1 sec'), - (2, '2 sec'), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, '1 sec'), (2, '2 sec'), (3, null), (4, null)) as t (i, v); select x, - AVG(x) over ( - - rows between - current row - and - 1 following - ) as curr_next_avg, - AVG(x) over ( - - rows between - 1 preceding - and - current row - ) as prev_curr_avg, - SUM(x) over ( - - rows between - current row - and - 1 following - ) as curr_next_sum, - SUM(x) over ( - - rows between - 1 preceding - and - current row - ) as prev_curr_sum + avg(x) over ( rows between current row and 1 following) as curr_next_avg, + avg(x) over ( rows between 1 preceding and current row) as prev_curr_avg, + sum(x) over ( rows between current row and 1 following) as curr_next_sum, + sum(x) over ( rows between 1 preceding and current row) as prev_curr_sum from ( values (cast(null as interval)), (cast('infinity' as interval)), - ( - '-2147483648 days -2147483648 months -9223372036854775807 usecs' - ), + ('-2147483648 days -2147483648 months -9223372036854775807 usecs'), (cast('-infinity' as interval)), - ( - '2147483647 days 2147483647 months 9223372036854775806 usecs' - ), + ('2147483647 days 2147483647 months 9223372036854775806 usecs'), (cast('infinity' as interval)), (cast('6 days' as interval)), (cast('7 days' as interval)), @@ -4873,23 +4308,13 @@ from select x, - AVG(x) over ( - - rows between - current row - and - 2 following - ) + avg(x) over ( rows between current row and 2 following) from ( values (cast(null as interval)), (cast('3 days' as interval)), - ( - cast('infinity' - as timestamp with time zone) - - NOW() - ), + (cast('infinity' as timestamptz) - now()), (cast('6 days' as interval)), (cast('-infinity' as interval)) ) @@ -4897,23 +4322,13 @@ from select x, - SUM(x) over ( - - rows between - current row - and - 2 following - ) + sum(x) over ( rows between current row and 2 following) from ( values (cast(null as interval)), (cast('3 days' as interval)), - ( - cast('infinity' - as timestamp with time zone) - - NOW() - ), + (cast('infinity' as timestamptz) - now()), (cast('6 days' as interval)), (cast('-infinity' as interval)) ) @@ -4921,7 +4336,7 @@ from select i, - SUM(cast(v as smallint)) over ( + sum(cast(v as smallint)) over ( order by i rows between current row @@ -4929,18 +4344,11 @@ select unbounded following ) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as int)) over ( + sum(cast(v as int)) over ( order by i rows between current row @@ -4948,18 +4356,11 @@ select unbounded following ) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as bigint)) over ( + sum(cast(v as bigint)) over ( order by i rows between current row @@ -4967,18 +4368,11 @@ select unbounded following ) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as money)) over ( + sum(cast(v as money)) over ( order by i rows between current row @@ -4986,18 +4380,11 @@ select unbounded following ) from - ( - values - (1, '1.10'), - (2, '2.20'), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, '1.10'), (2, '2.20'), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as interval)) over ( + sum(cast(v as interval)) over ( order by i rows between current row @@ -5005,18 +4392,11 @@ select unbounded following ) from - ( - values - (1, '1 sec'), - (2, '2 sec'), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, '1 sec'), (2, '2 sec'), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as numeric)) over ( + sum(cast(v as numeric)) over ( order by i rows between current row @@ -5024,17 +4404,10 @@ select unbounded following ) from - ( - values - (1, 1.1), - (2, 2.2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1.1), (2, 2.2), (3, null), (4, null)) as t (i, v); select - SUM(cast(n as numeric)) over ( + sum(cast(n as numeric)) over ( order by i rows between current row @@ -5042,48 +4415,19 @@ select unbounded following ) from - ( - values (1, 1.01), (2, 2), (3, 3) - ) - as v (i, n); + (values (1, 1.01), (2, 2), (3, 3)) as v (i, n); select i, - COUNT(v) over ( - order by i - rows between - current row - and - unbounded following - ) + count(v) over (order by i rows between current row and unbounded following) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - COUNT(*) over ( - order by i - rows between - current row - and - unbounded following - ) + count(*) over (order by i rows between current row and unbounded following) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select var_pop(cast(n as bigint)) over ( @@ -5094,15 +4438,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select var_pop(cast(n as int)) over ( @@ -5113,15 +4449,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select var_pop(cast(n as smallint)) over ( @@ -5132,15 +4460,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select var_pop(cast(n as numeric)) over ( @@ -5151,15 +4471,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select var_samp(cast(n as bigint)) over ( @@ -5170,15 +4482,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select var_samp(cast(n as int)) over ( @@ -5189,15 +4493,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select var_samp(cast(n as smallint)) over ( @@ -5208,15 +4504,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select var_samp(cast(n as numeric)) over ( @@ -5227,15 +4515,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select variance(cast(n as bigint)) over ( @@ -5246,15 +4526,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select variance(cast(n as int)) over ( @@ -5265,15 +4537,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select variance(cast(n as smallint)) over ( @@ -5284,15 +4548,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select variance(cast(n as numeric)) over ( @@ -5303,15 +4559,7 @@ select unbounded following ) from - ( - values - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) - ) - as r (i, n); + (values (1, 600), (2, 470), (3, 170), (4, 430), (5, 300)) as r (i, n); select stddev_pop(cast(n as bigint)) over ( @@ -5323,13 +4571,7 @@ select ) from ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) + values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300) ) as r (i, n); @@ -5343,13 +4585,7 @@ select ) from ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) + values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300) ) as r (i, n); @@ -5363,13 +4599,7 @@ select ) from ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) + values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300) ) as r (i, n); @@ -5383,13 +4613,7 @@ select ) from ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) + values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300) ) as r (i, n); @@ -5403,13 +4627,7 @@ select ) from ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) + values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300) ) as r (i, n); @@ -5423,13 +4641,7 @@ select ) from ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) + values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300) ) as r (i, n); @@ -5443,13 +4655,7 @@ select ) from ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) + values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300) ) as r (i, n); @@ -5463,13 +4669,7 @@ select ) from ( - values - (1, null), - (2, 600), - (3, 470), - (4, 170), - (5, 430), - (6, 300) + values (1, null), (2, 600), (3, 470), (4, 170), (5, 430), (6, 300) ) as r (i, n); @@ -5483,13 +4683,7 @@ select ) from ( - values - (0, null), - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) + values (0, null), (1, 600), (2, 470), (3, 170), (4, 430), (5, 300) ) as r (i, n); @@ -5503,13 +4697,7 @@ select ) from ( - values - (0, null), - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) + values (0, null), (1, 600), (2, 470), (3, 170), (4, 430), (5, 300) ) as r (i, n); @@ -5523,13 +4711,7 @@ select ) from ( - values - (0, null), - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) + values (0, null), (1, 600), (2, 470), (3, 170), (4, 430), (5, 300) ) as r (i, n); @@ -5543,93 +4725,41 @@ select ) from ( - values - (0, null), - (1, 600), - (2, 470), - (3, 170), - (4, 430), - (5, 300) + values (0, null), (1, 600), (2, 470), (3, 170), (4, 430), (5, 300) ) as r (i, n); select i, - SUM(cast(v as int)) over ( - order by i - rows between - current row - and - current row - ) + sum(cast(v as int)) over (order by i rows between current row and current row) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as int)) over ( - order by i - rows between - current row - and - 1 following - ) + sum(cast(v as int)) over (order by i rows between current row and 1 following) from - ( - values - (1, 1), - (2, 2), - (3, null), - (4, null) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, null), (4, null)) as t (i, v); select i, - SUM(cast(v as int)) over ( - order by i - rows between - 1 preceding - and - 1 following - ) + sum(cast(v as int)) over (order by i rows between 1 preceding and 1 following) from - ( - values (1, 1), (2, 2), (3, 3), (4, 4) - ) - as t (i, v); + (values (1, 1), (2, 2), (3, 3), (4, 4)) as t (i, v); select a, b, - SUM(b) over ( - order by a - rows between - 1 preceding - and - current row - ) + sum(b) over (order by a rows between 1 preceding and current row) from ( - values - (1, cast(1 as numeric)), - (2, 2), - (3, 'NaN'), - (4, 3), - (5, 4) + values (1, cast(1 as numeric)), (2, 2), (3, 'NaN'), (4, 3), (5, 4) ) as t (a, b); select to_char( - SUM(cast(n as double precision)) over ( + sum(cast(n as float8)) over ( order by i rows between current row @@ -5647,15 +4777,7 @@ select bool_and(b) over w, bool_or(b) over w from - ( - values - (1, true), - (2, true), - (3, false), - (4, false), - (5, true) - ) - as v (i, b) + (values (1, true), (2, true), (3, false), (4, false), (5, true)) as v (i, b) window w as ( order by i @@ -5666,27 +4788,21 @@ window ); select - COUNT(*) over (order by t1.unique1) + count(*) over (order by t1.unique1) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.tenthous + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.tenthous limit 1; select - COUNT(*) over () + count(*) over () from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.tenthous + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.tenthous where t2.two = 1 limit 1; select - COUNT(*) over ( + count(*) over ( order by t1.unique1 rows between unbounded preceding @@ -5694,14 +4810,11 @@ select unbounded following ) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.tenthous + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.tenthous limit 1; select - COUNT(*) over ( + count(*) over ( order by t1.unique1 rows between unbounded preceding @@ -5709,10 +4822,7 @@ select 10000 following ) from - tenk1 as t1 - inner join - tenk1 as t2 - on t1.unique1 = t2.tenthous + tenk1 as t1 inner join tenk1 as t2 on t1.unique1 = t2.tenthous limit 1; select @@ -5732,11 +4842,11 @@ create function pg_temp.f(group_size bigint) returns setof int[] language sql stable -as $function$ -SELECT array_agg(s) OVER w +as $$ + SELECT array_agg(s) OVER w FROM generate_series(1,5) s WINDOW w AS (ORDER BY s ROWS BETWEEN CURRENT ROW AND GROUP_SIZE FOLLOWING) -$function$; +$$; select * from pg_temp.f(2); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__with_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__with_100.snap index 5f72a2289..bc08a1045 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__with_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__with_100.snap @@ -6,39 +6,23 @@ snapshot_kind: text with q1 (x, y) as (select 1, 2) select * from q1, q1 as q2; select - COUNT(*) + count(*) from ( - with - q1 (x) - as ( - select random() from generate_series(1, 5) - ) + with q1 (x) as (select random() from generate_series(1, 5)) select * from q1 union select * from q1 ) as ss; -with recursive -t (n) -as ( - values (1) - union all - select n + 1 from t where n < 100 -) +with recursive t (n) as (values (1) union all select n + 1 from t where n < 100) select - SUM(n) + sum(n) from t; -with recursive -t (n) -as ( - select (values (1)) - union all - select n + 1 from t where n < 5 -) +with recursive t (n) as (select (values (1)) union all select n + 1 from t where n < 5) select * from @@ -47,14 +31,9 @@ from with recursive t (n) as ( - values (cast('01' as bit varying)) + values (cast('01' as varbit)) union - select - n || cast('10' as bit varying) - from - t - where - n < cast('100' as bit varying) + select n || cast('10' as varbit) from t where n < cast('100' as varbit) ) select n @@ -65,13 +44,7 @@ create view nums ( n ) -as with recursive -nums (n) -as ( - values (1) - union all - select n + 1 from nums where n < 5 -) +as with recursive nums (n) as (values (1) union all select n + 1 from nums where n < 5) select n from @@ -83,13 +56,7 @@ create or replace view nums ( n ) -as with recursive -nums (n) -as ( - values (1) - union all - select n + 1 from nums where n < 6 -) +as with recursive nums (n) as (values (1) union all select n + 1 from nums where n < 6) select n from @@ -105,26 +72,14 @@ with recursive t (n) as (select 1 union select n + 1 from t) select * from t lim with q as (select 'foo' as x) select x, pg_typeof(x) from q; -with recursive -t (n) -as ( - select 'foo' - union all - select n || ' bar' from t where length(n) < 20 -) +with recursive t (n) as (select 'foo' union all select n || ' bar' from t where length(n) < 20) select n, pg_typeof(n) from t; -with recursive -t (n) -as ( - select '7' - union all - select n + 1 from t where n < 10 -) +with recursive t (n) as (select '7' union all select n + 1 from t where n < 10) select n, pg_typeof(n) @@ -149,15 +104,7 @@ as ( with recursive w6 (c6) as ( - with - w6 (c6) - as ( - with w8 (c8) as (select 1) select * from w8 - ) - select - * - from - w6 + with w6 (c6) as (with w8 (c8) as (select 1) select * from w8) select * from w6 ) select * @@ -215,16 +162,7 @@ as ( select 5 union (with - innermost5 - as ( - select 6 - union - (with innermost6 as (select 7) - select - * - from - innermost6) - ) + innermost5 as (select 6 union (with innermost6 as (select 7) select * from innermost6)) select * from @@ -280,13 +218,7 @@ insert into department values (7, 5, 'G'); with recursive subdepartment as ( - select - name as root_name, - * - from - department - where - name = 'A' + select name as root_name, * from department where name = 'A' union all select sd.root_name, @@ -304,10 +236,7 @@ from order by name; with recursive -subdepartment (level, -id, -parent_department, -name) +subdepartment (level, id, parent_department, name) as ( select 1, * from department where name = 'A' union all @@ -327,10 +256,7 @@ from order by name; with recursive -subdepartment (level, -id, -parent_department, -name) +subdepartment (level, id, parent_department, name) as ( select 1, * from department where name = 'A' union all @@ -351,11 +277,7 @@ where level >= 2 order by name; -with recursive -subdepartment -as ( - select * from department where name = 'A' -) +with recursive subdepartment as (select * from department where name = 'A') select * from @@ -365,24 +287,14 @@ order by name; with recursive subdepartment as ( - select - id, - parent_department, - name - from - department - where - name = 'A' + select id, parent_department, name from department where name = 'A' union select d.id, d.parent_department, d.name from - department as d - inner join - subdepartment as sd - on d.parent_department = sd.id + department as d inner join subdepartment as sd on d.parent_department = sd.id ) select * @@ -391,36 +303,20 @@ from order by name; select - COUNT(*) + count(*) from ( - with recursive - t (n) - as ( - select 1 - union all - select n + 1 from t where n < 500 - ) - select - * - from - t + with recursive t (n) as (select 1 union all select n + 1 from t where n < 500) select * from t ) as t where n < ( select - COUNT(*) + count(*) from ( - with recursive - t (n) - as ( - select 1 - union all - select n + 1 from t where n < 100 - ) + with recursive t (n) as (select 1 union all select n + 1 from t where n < 100) select * from @@ -433,23 +329,13 @@ where n < 100 ); -with -q1 (x, -y) -as ( - select - hundred, - SUM(ten) - from - tenk1 - group by hundred -) +with q1 (x, y) as (select hundred, sum(ten) from tenk1 group by hundred) select - COUNT(*) + count(*) from q1 where - y > (select SUM(y) / 100 from q1 as qsub); + y > (select sum(y) / 100 from q1 as qsub); select * from subdepartment; @@ -459,15 +345,10 @@ select pg_get_viewdef(cast('vsubdepartment' as regclass)); select pg_get_viewdef(cast('vsubdepartment' as regclass), true); -select SUM(n) from t; +select sum(n) from t; with recursive -q -as ( - select * from department - union all - (with x as (select * from q) select * from x) -) +q as (select * from department union all (with x as (select * from q) select * from x)) select * from @@ -480,12 +361,7 @@ as ( select * from department union all (with recursive - x - as ( - select * from department - union all - (select * from q union all select * from x) - ) + x as (select * from department union all (select * from q union all select * from x)) select * from @@ -524,16 +400,11 @@ values (16, 11); with recursive -t (id, -path) +t (id, path) as ( values (1, cast(array[] as int[])) union all - select - tree.id, - t.path || tree.id - from - tree inner join t on tree.parent_id = t.id + select tree.id, t.path || tree.id from tree inner join t on tree.parent_id = t.id ) select t1.*, @@ -542,48 +413,34 @@ from t as t1 inner join t as t2 - on t1.path[1] = t2.path[1] and - array_upper(t1.path, 1) = 1 and - array_upper(t2.path, 1) > 1 + on t1.path[1] = t2.path[1] and array_upper(t1.path, 1) = 1 and array_upper(t2.path, 1) > 1 order by t1.id, t2.id; with recursive -t (id, -path) +t (id, path) as ( values (1, cast(array[] as int[])) union all - select - tree.id, - t.path || tree.id - from - tree inner join t on tree.parent_id = t.id + select tree.id, t.path || tree.id from tree inner join t on tree.parent_id = t.id ) select t1.id, - COUNT(t2.*) + count(t2.*) from t as t1 inner join t as t2 - on t1.path[1] = t2.path[1] and - array_upper(t1.path, 1) = 1 and - array_upper(t2.path, 1) > 1 + on t1.path[1] = t2.path[1] and array_upper(t1.path, 1) = 1 and array_upper(t2.path, 1) > 1 group by t1.id order by t1.id; with recursive -t (id, -path) +t (id, path) as ( values (1, cast(array[] as int[])) union all - select - tree.id, - t.path || tree.id - from - tree inner join t on tree.parent_id = t.id + select tree.id, t.path || tree.id from tree inner join t on tree.parent_id = t.id ) select t1.id, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__with_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__with_80.snap index 957293305..c9397abd3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__with_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__with_80.snap @@ -6,42 +6,24 @@ snapshot_kind: text with q1 (x, y) as (select 1, 2) select * from q1, q1 as q2; select - COUNT(*) + count(*) from ( - with - q1 (x) - as ( - select - random() - from - generate_series(1, 5) - ) + with q1 (x) as (select random() from generate_series(1, 5)) select * from q1 union select * from q1 ) as ss; -with recursive -t (n) -as ( - values (1) - union all - select n + 1 from t where n < 100 -) +with recursive t (n) as (values (1) union all select n + 1 from t where n < 100) select - SUM(n) + sum(n) from t; with recursive -t (n) -as ( - select (values (1)) - union all - select n + 1 from t where n < 5 -) +t (n) as (select (values (1)) union all select n + 1 from t where n < 5) select * from @@ -50,14 +32,9 @@ from with recursive t (n) as ( - values (cast('01' as bit varying)) + values (cast('01' as varbit)) union - select - n || cast('10' as bit varying) - from - t - where - n < cast('100' as bit varying) + select n || cast('10' as varbit) from t where n < cast('100' as varbit) ) select n @@ -69,12 +46,7 @@ create view nums n ) as with recursive -nums (n) -as ( - values (1) - union all - select n + 1 from nums where n < 5 -) +nums (n) as (values (1) union all select n + 1 from nums where n < 5) select n from @@ -87,12 +59,7 @@ create or replace view nums n ) as with recursive -nums (n) -as ( - values (1) - union all - select n + 1 from nums where n < 6 -) +nums (n) as (values (1) union all select n + 1 from nums where n < 6) select n from @@ -102,22 +69,14 @@ select * from nums; with recursive t (n) as (select 1 union select 10 - n from t) select * from t; -with recursive -t (n) -as ( - values (1) union all select n + 1 from t -) +with recursive t (n) as (values (1) union all select n + 1 from t) select * from t limit 10; -with recursive -t (n) -as ( - select 1 union select n + 1 from t -) +with recursive t (n) as (select 1 union select n + 1 from t) select * from @@ -127,30 +86,14 @@ limit 10; with q as (select 'foo' as x) select x, pg_typeof(x) from q; with recursive -t (n) -as ( - select 'foo' - union all - select - n || ' bar' - from - t - where - length(n) < 20 -) +t (n) as (select 'foo' union all select n || ' bar' from t where length(n) < 20) select n, pg_typeof(n) from t; -with recursive -t (n) -as ( - select '7' - union all - select n + 1 from t where n < 10 -) +with recursive t (n) as (select '7' union all select n + 1 from t where n < 10) select n, pg_typeof(n) @@ -175,15 +118,7 @@ as ( with recursive w6 (c6) as ( - with - w6 (c6) - as ( - with w8 (c8) as (select 1) - select - * - from - w8 - ) + with w6 (c6) as (with w8 (c8) as (select 1) select * from w8) select * from @@ -249,11 +184,7 @@ as ( as ( select 6 union - (with innermost6 as (select 7) - select - * - from - innermost6) + (with innermost6 as (select 7) select * from innermost6) ) select * @@ -287,8 +218,7 @@ order by 1; create temporary table department ( id int primary key, - parent_department int - references department, + parent_department int references department, name text ); @@ -311,13 +241,7 @@ insert into department values (7, 5, 'G'); with recursive subdepartment as ( - select - name as root_name, - * - from - department - where - name = 'A' + select name as root_name, * from department where name = 'A' union all select sd.root_name, @@ -335,18 +259,9 @@ from order by name; with recursive -subdepartment (level, -id, -parent_department, -name) +subdepartment (level, id, parent_department, name) as ( - select - 1, - * - from - department - where - name = 'A' + select 1, * from department where name = 'A' union all select sd.level + 1, @@ -364,18 +279,9 @@ from order by name; with recursive -subdepartment (level, -id, -parent_department, -name) +subdepartment (level, id, parent_department, name) as ( - select - 1, - * - from - department - where - name = 'A' + select 1, * from department where name = 'A' union all select sd.level + 1, @@ -394,16 +300,7 @@ where level >= 2 order by name; -with recursive -subdepartment -as ( - select - * - from - department - where - name = 'A' -) +with recursive subdepartment as (select * from department where name = 'A') select * from @@ -413,14 +310,7 @@ order by name; with recursive subdepartment as ( - select - id, - parent_department, - name - from - department - where - name = 'A' + select id, parent_department, name from department where name = 'A' union select d.id, @@ -439,16 +329,11 @@ from order by name; select - COUNT(*) + count(*) from ( with recursive - t (n) - as ( - select 1 - union all - select n + 1 from t where n < 500 - ) + t (n) as (select 1 union all select n + 1 from t where n < 500) select * from @@ -459,16 +344,11 @@ where n < ( select - COUNT(*) + count(*) from ( with recursive - t (n) - as ( - select 1 - union all - select n + 1 from t where n < 100 - ) + t (n) as (select 1 union all select n + 1 from t where n < 100) select * from @@ -481,24 +361,13 @@ where n < 100 ); -with -q1 (x, -y) -as ( - select - hundred, - SUM(ten) - from - tenk1 - group by hundred -) +with q1 (x, y) as (select hundred, sum(ten) from tenk1 group by hundred) select - COUNT(*) + count(*) from q1 where - y > - (select SUM(y) / 100 from q1 as qsub); + y > (select sum(y) / 100 from q1 as qsub); select * from subdepartment; @@ -508,18 +377,14 @@ select pg_get_viewdef(cast('vsubdepartment' as regclass)); select pg_get_viewdef(cast('vsubdepartment' as regclass), true); -select SUM(n) from t; +select sum(n) from t; with recursive q as ( select * from department union all - (with x as (select * from q) - select - * - from - x) + (with x as (select * from q) select * from x) ) select * @@ -537,9 +402,7 @@ as ( as ( select * from department union all - (select * from q - union all - select * from x) + (select * from q union all select * from x) ) select * @@ -579,8 +442,7 @@ values (16, 11); with recursive -t (id, -path) +t (id, path) as ( values (1, cast(array[] as int[])) union all @@ -588,10 +450,7 @@ as ( tree.id, t.path || tree.id from - tree - inner join - t - on tree.parent_id = t.id + tree inner join t on tree.parent_id = t.id ) select t1.*, @@ -607,8 +466,7 @@ order by t1.id, t2.id; with recursive -t (id, -path) +t (id, path) as ( values (1, cast(array[] as int[])) union all @@ -616,14 +474,11 @@ as ( tree.id, t.path || tree.id from - tree - inner join - t - on tree.parent_id = t.id + tree inner join t on tree.parent_id = t.id ) select t1.id, - COUNT(t2.*) + count(t2.*) from t as t1 inner join @@ -635,8 +490,7 @@ group by t1.id order by t1.id; with recursive -t (id, -path) +t (id, path) as ( values (1, cast(array[] as int[])) union all @@ -644,32 +498,20 @@ as ( tree.id, t.path || tree.id from - tree - inner join - t - on tree.parent_id = t.id + tree inner join t on tree.parent_id = t.id ) select t1.id, t2.path, t2 from - t as t1 - inner join - t as t2 - on t1.id = t2.id; + t as t1 inner join t as t2 on t1.id = t2.id; create temporary table duplicates (a int not null); insert into duplicates values (1), (1); -with recursive -cte (a) -as ( - select a from duplicates - union - select a from cte -) +with recursive cte (a) as (select a from duplicates union select a from cte) select a from diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__without_overlaps_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__without_overlaps_100.snap index e451e0798..10c76d3eb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__without_overlaps_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__without_overlaps_100.snap @@ -43,7 +43,7 @@ select pg_get_constraintdef(oid) from pg_constraint where conname = 'temporal_rn select pg_get_indexdef(conindid, 0, true) from pg_constraint where conname = 'temporal_rng2_pk'; -create type textrange2 as range (subtype = text, collation = "C"); +create type textrange2 as range (subtype = text, "collation" = "C"); alter table temporal_rng3 drop constraint temporal_rng3_pk; @@ -72,7 +72,7 @@ select pg_get_indexdef(conindid, 0, true) from pg_constraint where conname = 'te drop table temporal_rng3; -create type textrange2 as range (subtype = text, collation = "C"); +create type textrange2 as range (subtype = text, "collation" = "C"); alter table temporal_rng3 drop constraint temporal_rng3_uq; @@ -91,10 +91,10 @@ create table temporal3 ( valid_at daterange ); -create index "idx_temporal3_uq" on temporal3 using gist (id, valid_at); +create index idx_temporal3_uq on temporal3 using gist (id, valid_at); alter table temporal3 - add constraint "temporal3_pk" primary key using index "idx_temporal3_uq"; + add constraint temporal3_pk primary key using index idx_temporal3_uq; drop table temporal3; @@ -103,10 +103,10 @@ create table temporal3 ( valid_at daterange ); -create index "idx_temporal3_uq" on temporal3 using gist (id, valid_at); +create index idx_temporal3_uq on temporal3 using gist (id, valid_at); alter table temporal3 - add constraint "temporal3_uq" unique using index "idx_temporal3_uq"; + add constraint temporal3_uq unique using index idx_temporal3_uq; drop table temporal3; @@ -115,10 +115,10 @@ create table temporal3 ( valid_at daterange ); -create unique index "idx_temporal3_uq" on temporal3 using btree (id, valid_at); +create unique index idx_temporal3_uq on temporal3 using btree (id, valid_at); alter table temporal3 - add constraint "temporal3_uq" unique using index "idx_temporal3_uq"; + add constraint temporal3_uq unique using index idx_temporal3_uq; drop table temporal3; @@ -179,21 +179,18 @@ select * from temporal_rng order by id, valid_at; update temporal_rng set id = '[11,12)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_rng set valid_at = '[2020-01-01,2021-01-01)' where - id = '[11,12)' and - valid_at @> cast('2018-01-15' as date); + id = '[11,12)' and valid_at @> cast('2018-01-15' as date); update temporal_rng set id = '[21,22)', valid_at = '[2018-01-02,2018-02-03)' where - id = '[11,12)' and - valid_at @> cast('2020-01-15' as date); + id = '[11,12)' and valid_at @> cast('2020-01-15' as date); select * from temporal_rng order by id, valid_at; @@ -270,21 +267,18 @@ select * from temporal_rng3 order by id, valid_at; update temporal_rng3 set id = '[11,12)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_rng3 set valid_at = '[2020-01-01,2021-01-01)' where - id = '[11,12)' and - valid_at @> cast('2018-01-15' as date); + id = '[11,12)' and valid_at @> cast('2018-01-15' as date); update temporal_rng3 set id = '[21,22)', valid_at = '[2018-01-02,2018-02-03)' where - id = '[11,12)' and - valid_at @> cast('2020-01-15' as date); + id = '[11,12)' and valid_at @> cast('2020-01-15' as date); update temporal_rng3 set id = null, @@ -296,8 +290,7 @@ update temporal_rng3 set id = '[1,2)', valid_at = null where - id is null and - valid_at @> cast('2020-06-01' as date); + id is null and valid_at @> cast('2020-06-01' as date); select * from temporal_rng3 order by id, valid_at; @@ -318,38 +311,16 @@ alter table temporal_mltrng drop constraint temporal_mltrng_pk; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[3,4)', - datemultirange(daterange('2018-01-01', null)) - ); +values ('[3,4)', datemultirange(daterange('2018-01-01', null))); alter table temporal_mltrng drop constraint temporal_mltrng_pk; @@ -357,13 +328,7 @@ alter table temporal_mltrng begin; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-01', '2018-01-05'))); rollback; @@ -376,56 +341,22 @@ rollback; delete from temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[3,4)', - datemultirange(daterange('2018-01-01', null)) - ); +values ('[3,4)', datemultirange(daterange('2018-01-01', null))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng (id, valid_at) -values - ( - null, - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values (null, datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng (id, valid_at) values ('[3,4)', null); @@ -436,37 +367,30 @@ select * from temporal_mltrng order by id, valid_at; update temporal_mltrng set id = '[11,12)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng set valid_at = '{[2020-01-01,2021-01-01)}' where - id = '[11,12)' and - valid_at @> cast('2018-01-15' as date); + id = '[11,12)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng set id = '[21,22)', valid_at = '{[2018-01-02,2018-02-03)}' where - id = '[11,12)' and - valid_at @> cast('2020-01-15' as date); + id = '[11,12)' and valid_at @> cast('2020-01-15' as date); select * from temporal_mltrng order by id, valid_at; update temporal_mltrng set id = '[1,2)', -valid_at = datemultirange( - daterange('2018-03-05', '2018-05-05') -) +valid_at = datemultirange(daterange('2018-03-05', '2018-05-05')) where id = '[21,22)'; update temporal_mltrng set id = null, -valid_at = datemultirange( - daterange('2018-03-05', '2018-05-05') -) +valid_at = datemultirange(daterange('2018-03-05', '2018-05-05')) where id = '[21,22)'; @@ -482,47 +406,19 @@ create table temporal_mltrng3 ( ); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[3,4)', - datemultirange(daterange('2018-01-01', null)) - ); +values ('[3,4)', datemultirange(daterange('2018-01-01', null))); insert into temporal_mltrng3 (id, valid_at) -values - ( - null, - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values (null, datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) values ('[3,4)', null); @@ -532,13 +428,7 @@ alter table temporal_mltrng3 begin; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-01', '2018-01-05'))); rollback; @@ -551,58 +441,24 @@ rollback; delete from temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[3,4)', - datemultirange(daterange('2018-01-01', null)) - ); +values ('[3,4)', datemultirange(daterange('2018-01-01', null))); insert into temporal_mltrng3 (id, valid_at) -values - ( - null, - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values (null, datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) values ('[3,4)', null); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) values ('[3,4)', '{}'); @@ -611,27 +467,22 @@ select * from temporal_mltrng3 order by id, valid_at; update temporal_mltrng3 set id = '[11,12)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng3 set valid_at = '{[2020-01-01,2021-01-01)}' where - id = '[11,12)' and - valid_at @> cast('2018-01-15' as date); + id = '[11,12)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng3 set id = '[21,22)', valid_at = '{[2018-01-02,2018-02-03)}' where - id = '[11,12)' and - valid_at @> cast('2020-01-15' as date); + id = '[11,12)' and valid_at @> cast('2020-01-15' as date); update temporal_mltrng3 set id = null, -valid_at = datemultirange( - daterange('2020-01-01', '2021-01-01') -) +valid_at = datemultirange(daterange('2020-01-01', '2021-01-01')) where id = '[21,22)'; @@ -639,15 +490,12 @@ update temporal_mltrng3 set id = '[1,2)', valid_at = null where - id is null and - valid_at @> cast('2020-06-01' as date); + id is null and valid_at @> cast('2020-06-01' as date); select * from temporal_mltrng3 order by id, valid_at; update temporal_mltrng3 -set valid_at = datemultirange( - daterange('2018-03-01', '2018-05-05') -) +set valid_at = datemultirange(daterange('2018-03-01', '2018-05-05')) where id = '[1,2)' and valid_at is null; @@ -661,18 +509,8 @@ drop table temporal_mltrng3; insert into temporal3 (id, valid_at, id2, name) values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01'), - '[7,8)', - 'foo' - ), - ( - '[2,3)', - daterange('2000-01-01', '2010-01-01'), - '[9,10)', - 'bar' - ); + ('[1,2)', daterange('2000-01-01', '2010-01-01'), '[7,8)', 'foo'), + ('[2,3)', daterange('2000-01-01', '2010-01-01'), '[9,10)', 'bar'); drop table temporal3; @@ -695,21 +533,9 @@ create table tp2 partition of temporal_partitioned for values in ('[3,4)', '[4,5 insert into temporal_partitioned (id, valid_at, name) values - ( - '[1,2)', - daterange('2000-01-01', '2000-02-01'), - 'one' - ), - ( - '[1,2)', - daterange('2000-02-01', '2000-03-01'), - 'one' - ), - ( - '[3,4)', - daterange('2000-01-01', '2010-01-01'), - 'three' - ); + ('[1,2)', daterange('2000-01-01', '2000-02-01'), 'one'), + ('[1,2)', daterange('2000-02-01', '2000-03-01'), 'one'), + ('[3,4)', daterange('2000-01-01', '2010-01-01'), 'three'); select * from temporal_partitioned order by id, valid_at; @@ -725,21 +551,9 @@ create table tp2 partition of temporal_partitioned for values in ('[3,4)', '[4,5 insert into temporal_partitioned (id, valid_at, name) values - ( - '[1,2)', - daterange('2000-01-01', '2000-02-01'), - 'one' - ), - ( - '[1,2)', - daterange('2000-02-01', '2000-03-01'), - 'one' - ), - ( - '[3,4)', - daterange('2000-01-01', '2010-01-01'), - 'three' - ); + ('[1,2)', daterange('2000-01-01', '2000-02-01'), 'one'), + ('[1,2)', daterange('2000-02-01', '2000-03-01'), 'one'), + ('[3,4)', daterange('2000-01-01', '2010-01-01'), 'three'); select * from temporal_partitioned order by id, valid_at; @@ -757,18 +571,15 @@ truncate temporal_rng; insert into temporal_rng (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict do nothing; insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict do nothing; insert into temporal_rng (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict do nothing; select * from temporal_rng order by id, valid_at; @@ -778,18 +589,15 @@ truncate temporal_rng; insert into temporal_rng (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict (id, valid_at) do nothing; insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict (id, valid_at) do nothing; insert into temporal_rng (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict (id, valid_at) do nothing; select * from temporal_rng order by id, valid_at; @@ -799,25 +607,16 @@ truncate temporal_rng; insert into temporal_rng (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) -on conflict -on constraint temporal_rng_pk -do nothing; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal_rng_pk do nothing; insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) -on conflict -on constraint temporal_rng_pk -do nothing; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict on constraint temporal_rng_pk do nothing; insert into temporal_rng (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) -on conflict -on constraint temporal_rng_pk -do nothing; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal_rng_pk do nothing; select * from temporal_rng order by id, valid_at; @@ -826,31 +625,16 @@ truncate temporal_rng; insert into temporal_rng (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[2,3)'; insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[3,4)'; insert into temporal_rng (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[4,5)'; select * from temporal_rng order by id, valid_at; @@ -859,31 +643,16 @@ truncate temporal_rng; insert into temporal_rng (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) -on conflict -on constraint temporal_rng_pk -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal_rng_pk do update set id = excluded.id + '[2,3)'; insert into temporal_rng (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) -on conflict -on constraint temporal_rng_pk -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict on constraint temporal_rng_pk do update set id = excluded.id + '[3,4)'; insert into temporal_rng (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) -on conflict -on constraint temporal_rng_pk -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal_rng_pk do update set id = excluded.id + '[4,5)'; select * from temporal_rng order by id, valid_at; @@ -892,18 +661,15 @@ truncate temporal3; insert into temporal3 (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict do nothing; insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict do nothing; insert into temporal3 (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict do nothing; select * from temporal3 order by id, valid_at; @@ -913,18 +679,15 @@ truncate temporal3; insert into temporal3 (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict (id, valid_at) do nothing; insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict (id, valid_at) do nothing; insert into temporal3 (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict (id, valid_at) do nothing; select * from temporal3 order by id, valid_at; @@ -934,18 +697,15 @@ truncate temporal3; insert into temporal3 (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict on constraint temporal3_uq do nothing; insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict on constraint temporal3_uq do nothing; insert into temporal3 (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict on constraint temporal3_uq do nothing; select * from temporal3 order by id, valid_at; @@ -955,31 +715,16 @@ truncate temporal3; insert into temporal3 (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[2,3)'; insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[3,4)'; insert into temporal3 (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[4,5)'; select * from temporal3 order by id, valid_at; @@ -988,31 +733,16 @@ truncate temporal3; insert into temporal3 (id, valid_at) values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2005-01-01', '2006-01-01')) -on conflict -on constraint temporal3_uq -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal3_uq do update set id = excluded.id + '[2,3)'; insert into temporal3 (id, valid_at) -values - ('[1,2)', daterange('2010-01-01', '2020-01-01')) -on conflict -on constraint temporal3_uq -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict on constraint temporal3_uq do update set id = excluded.id + '[3,4)'; insert into temporal3 (id, valid_at) -values - ('[2,3)', daterange('2005-01-01', '2006-01-01')) -on conflict -on constraint temporal3_uq -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal3_uq do update set id = excluded.id + '[4,5)'; select * from temporal3 order by id, valid_at; @@ -1021,42 +751,18 @@ drop table temporal3; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict do nothing; select * from temporal_mltrng order by id, valid_at; @@ -1064,42 +770,18 @@ select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict (id, valid_at) do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict (id, valid_at) do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict (id, valid_at) do nothing; select * from temporal_mltrng order by id, valid_at; @@ -1107,201 +789,75 @@ select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do nothing; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng_pk do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do nothing; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict on constraint temporal_mltrng_pk do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do nothing; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng_pk do nothing; select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[2,3)'; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[3,4)'; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[4,5)'; select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng_pk do update set id = excluded.id + '[2,3)'; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict on constraint temporal_mltrng_pk do update set id = excluded.id + '[3,4)'; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng_pk do update set id = excluded.id + '[4,5)'; select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict do nothing; select * from temporal_mltrng3 order by id, valid_at; @@ -1309,42 +865,18 @@ select * from temporal_mltrng3 order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict (id, valid_at) do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict (id, valid_at) do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict (id, valid_at) do nothing; select * from temporal_mltrng3 order by id, valid_at; @@ -1352,159 +884,57 @@ select * from temporal_mltrng3 order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do nothing; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng3_uq do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do nothing; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict on constraint temporal_mltrng3_uq do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do nothing; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng3_uq do nothing; select * from temporal_mltrng3 order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[2,3)'; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[3,4)'; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[4,5)'; select * from temporal_mltrng3 order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng3_uq do update set id = excluded.id + '[2,3)'; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict on constraint temporal_mltrng3_uq do update set id = excluded.id + '[3,4)'; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng3_uq do update set id = excluded.id + '[4,5)'; select * from temporal_mltrng3 order by id, valid_at; @@ -1560,53 +990,28 @@ alter table temporal_fk_rng2rng drop constraint temporal_fk_rng2rng_fk; insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-01'), - '[1,2)' - ); +values ('[1,2)', daterange('2018-01-02', '2018-02-01'), '[1,2)'); alter table temporal_fk_rng2rng drop constraint temporal_fk_rng2rng_fk; insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[2,3)', - daterange('2018-01-02', '2018-04-01'), - '[1,2)' - ); +values ('[2,3)', daterange('2018-01-02', '2018-04-01'), '[1,2)'); delete from temporal_fk_rng2rng; select pg_get_constraintdef(oid) from pg_constraint where conname = 'temporal_fk_rng2rng_fk'; insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-01'), - '[1,2)' - ); +values ('[1,2)', daterange('2018-01-02', '2018-02-01'), '[1,2)'); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[2,3)', - daterange('2018-01-02', '2018-04-01'), - '[1,2)' - ); +values ('[2,3)', daterange('2018-01-02', '2018-04-01'), '[1,2)'); insert into temporal_rng (id, valid_at) values ('[1,2)', daterange('2018-02-03', '2018-03-03')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[2,3)', - daterange('2018-01-02', '2018-04-01'), - '[1,2)' - ); +values ('[2,3)', daterange('2018-01-02', '2018-04-01'), '[1,2)'); update temporal_fk_rng2rng set valid_at = daterange('2018-01-02', '2018-02-20') where id = '[1,2)'; @@ -1622,15 +1027,10 @@ values ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); alter table temporal_fk_rng2rng - alter constraint "temporal_fk_rng2rng_fk" deferrable initially deferred; + alter constraint temporal_fk_rng2rng_fk deferrable initially deferred; delete from temporal_rng where id = '[5,6)'; @@ -1653,18 +1053,12 @@ values ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); update temporal_rng set valid_at = daterange('2016-02-01', '2016-03-01') where - id = '[5,6)' and - valid_at = daterange('2018-02-01', '2018-03-01'); + id = '[5,6)' and valid_at = daterange('2018-02-01', '2018-03-01'); insert into temporal_rng (id, valid_at) values @@ -1672,19 +1066,12 @@ values ('[6,7)', daterange('2018-02-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[4,5)', - daterange('2018-01-15', '2018-02-15'), - '[6,7)' - ); +values ('[4,5)', daterange('2018-01-15', '2018-02-15'), '[6,7)'); update temporal_rng set valid_at = case - when lower(valid_at) = '2018-01-01' - then daterange('2018-01-01', '2018-01-05') - when lower(valid_at) = '2018-02-01' - then daterange('2018-01-05', '2018-03-01') + when lower(valid_at) = '2018-01-01' then daterange('2018-01-01', '2018-01-05') + when lower(valid_at) = '2018-02-01' then daterange('2018-01-05', '2018-03-01') end where id = '[6,7)'; @@ -1696,82 +1083,62 @@ values insert into temporal_fk_rng2rng (id, valid_at, parent_id) values - ( - '[1,2)', - daterange('2018-01-15', '2018-02-01'), - '[1,2)' - ), - ( - '[2,3)', - daterange('2018-01-15', '2018-05-01'), - '[1,2)' - ); + ('[1,2)', daterange('2018-01-15', '2018-02-01'), '[1,2)'), + ('[2,3)', daterange('2018-01-15', '2018-05-01'), '[1,2)'); update temporal_rng set valid_at = daterange('2018-01-15', '2018-03-01') where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_rng set valid_at = daterange('2018-01-01', '2018-03-01') where - id = '[1,2)' and - valid_at @> cast('2018-01-25' as date); + id = '[1,2)' and valid_at @> cast('2018-01-25' as date); update temporal_rng set id = '[2,3)', valid_at = daterange('2018-01-15', '2018-03-01') where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_rng set id = '[2,3)' where id = '[1,2)' and valid_at @> cast('2018-01-15' as date); insert into temporal_rng (id, valid_at) values ('[2,3)', daterange('2018-01-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[5,6)', - daterange('2018-01-15', '2018-02-01'), - '[2,3)' - ); +values ('[5,6)', daterange('2018-01-15', '2018-02-01'), '[2,3)'); update temporal_rng set valid_at = daterange('2018-01-15', '2018-02-15') where id = '[2,3)'; update temporal_rng set valid_at = daterange('2016-01-01', '2016-02-01') where - id = '[5,6)' and - valid_at = daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); begin; alter table temporal_fk_rng2rng - alter constraint "temporal_fk_rng2rng_fk" deferrable initially deferred; + alter constraint temporal_fk_rng2rng_fk deferrable initially deferred; update temporal_rng set valid_at = daterange('2016-01-01', '2016-02-01') where - id = '[5,6)' and - valid_at = daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); commit; update temporal_rng set id = '[7,8)' where - id = '[5,6)' and - valid_at = daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); delete from temporal_fk_rng2rng where id = '[3,4)'; update temporal_rng set valid_at = daterange('2016-01-01', '2016-02-01') where - id = '[5,6)' and - valid_at = daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); truncate temporal_rng, temporal_fk_rng2rng; @@ -1790,12 +1157,7 @@ values ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); delete from temporal_rng where id = '[5,6)' and valid_at = daterange('2018-02-01', '2018-03-01'); @@ -1804,7 +1166,7 @@ delete from temporal_rng where id = '[5,6)' and valid_at = daterange('2018-01-01 begin; alter table temporal_fk_rng2rng - alter constraint "temporal_fk_rng2rng_fk" deferrable initially deferred; + alter constraint temporal_fk_rng2rng_fk deferrable initially deferred; delete from temporal_rng where id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); @@ -1822,34 +1184,19 @@ alter table temporal_fk_rng2rng insert into temporal_rng (id, valid_at) values ('[6,7)', daterange('2018-01-01', '2021-01-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[4,5)', - daterange('2018-01-01', '2021-01-01'), - '[6,7)' - ); +values ('[4,5)', daterange('2018-01-01', '2021-01-01'), '[6,7)'); insert into temporal_rng (id, valid_at) values ('[9,10)', daterange('2018-01-01', '2021-01-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[6,7)', - daterange('2018-01-01', '2021-01-01'), - '[9,10)' - ); +values ('[6,7)', daterange('2018-01-01', '2021-01-01'), '[9,10)'); insert into temporal_rng (id, valid_at) values ('[-1,-1]', daterange(null, null)); insert into temporal_rng (id, valid_at) values ('[12,13)', daterange('2018-01-01', '2021-01-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[8,9)', - daterange('2018-01-01', '2021-01-01'), - '[12,13)' - ); +values ('[8,9)', daterange('2018-01-01', '2021-01-01'), '[12,13)'); drop table temporal_mltrng; @@ -1870,109 +1217,46 @@ delete from temporal_fk_mltrng2mltrng; insert into temporal_mltrng (id, valid_at) values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ), - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ), - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ), - ( - '[3,4)', - datemultirange(daterange('2018-01-01', null)) - ); + ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))), + ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))), + ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))), + ('[3,4)', datemultirange(daterange('2018-01-01', null))); alter table temporal_fk_mltrng2mltrng drop constraint temporal_fk_mltrng2mltrng_fk; insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-01') - ), - '[1,2)' - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-01')), '[1,2)'); alter table temporal_fk_mltrng2mltrng drop constraint temporal_fk_mltrng2mltrng_fk; insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-02', '2018-04-01') - ), - '[1,2)' - ); +values ('[2,3)', datemultirange(daterange('2018-01-02', '2018-04-01')), '[1,2)'); delete from temporal_fk_mltrng2mltrng; select pg_get_constraintdef(oid) from pg_constraint where conname = 'temporal_fk_mltrng2mltrng_fk'; insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-01') - ), - '[1,2)' - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-01')), '[1,2)'); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-02', '2018-04-01') - ), - '[1,2)' - ); +values ('[2,3)', datemultirange(daterange('2018-01-02', '2018-04-01')), '[1,2)'); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-02-03', '2018-03-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-02-03', '2018-03-03'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-02', '2018-04-01') - ), - '[1,2)' - ); +values ('[2,3)', datemultirange(daterange('2018-01-02', '2018-04-01')), '[1,2)'); update temporal_fk_mltrng2mltrng -set valid_at = datemultirange( - daterange('2018-01-02', '2018-02-20') -) +set valid_at = datemultirange(daterange('2018-01-02', '2018-02-20')) where id = '[1,2)'; update temporal_fk_mltrng2mltrng -set valid_at = datemultirange( - daterange('2018-01-02', '2018-05-01') -) +set valid_at = datemultirange(daterange('2018-01-02', '2018-05-01')) where id = '[1,2)'; @@ -1982,31 +1266,14 @@ begin; insert into temporal_mltrng (id, valid_at) values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ), - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); + ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))), + ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); +values ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); alter table temporal_fk_mltrng2mltrng - alter constraint "temporal_fk_mltrng2mltrng_fk" deferrable initially deferred; + alter constraint temporal_fk_mltrng2mltrng_fk deferrable initially deferred; delete from temporal_mltrng where id = '[5,6)'; @@ -2018,18 +1285,10 @@ alter table temporal_fk_mltrng2mltrng drop constraint temporal_fk_mltrng2mltrng_fk; insert into temporal_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))); update temporal_mltrng -set valid_at = datemultirange( - daterange('2016-01-01', '2016-02-01') -) +set valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) where id = '[5,6)'; @@ -2037,205 +1296,96 @@ delete from temporal_mltrng where id = '[5,6)'; insert into temporal_mltrng (id, valid_at) values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ), - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); + ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))), + ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); +values ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); update temporal_mltrng -set valid_at = datemultirange( - daterange('2016-02-01', '2016-03-01') -) +set valid_at = datemultirange(daterange('2016-02-01', '2016-03-01')) where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-02-01', '2018-03-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-02-01', '2018-03-01')); insert into temporal_mltrng (id, valid_at) values - ( - '[6,7)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ), - ( - '[6,7)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); + ('[6,7)', datemultirange(daterange('2018-01-01', '2018-02-01'))), + ('[6,7)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[4,5)', - datemultirange( - daterange('2018-01-15', '2018-02-15') - ), - '[6,7)' - ); +values ('[4,5)', datemultirange(daterange('2018-01-15', '2018-02-15')), '[6,7)'); update temporal_mltrng set valid_at = case - when lower(valid_at) = '2018-01-01' - then datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - when lower(valid_at) = '2018-02-01' - then datemultirange( - daterange('2018-01-05', '2018-03-01') - ) + when lower(valid_at) = '2018-01-01' then datemultirange(daterange('2018-01-01', '2018-01-05')) + when lower(valid_at) = '2018-02-01' then datemultirange(daterange('2018-01-05', '2018-03-01')) end where id = '[6,7)'; insert into temporal_mltrng (id, valid_at) values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-03-01') - ) - ), - ( - '[1,2)', - datemultirange( - daterange('2018-03-01', '2018-06-01') - ) - ); + ('[1,2)', datemultirange(daterange('2018-01-01', '2018-03-01'))), + ('[1,2)', datemultirange(daterange('2018-03-01', '2018-06-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[1,2)', - datemultirange( - daterange('2018-01-15', '2018-02-01') - ), - '[1,2)' - ), - ( - '[2,3)', - datemultirange( - daterange('2018-01-15', '2018-05-01') - ), - '[1,2)' - ); + ('[1,2)', datemultirange(daterange('2018-01-15', '2018-02-01')), '[1,2)'), + ('[2,3)', datemultirange(daterange('2018-01-15', '2018-05-01')), '[1,2)'); update temporal_mltrng -set valid_at = datemultirange( - daterange('2018-01-15', '2018-03-01') -) +set valid_at = datemultirange(daterange('2018-01-15', '2018-03-01')) where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng -set valid_at = datemultirange( - daterange('2018-01-01', '2018-03-01') -) +set valid_at = datemultirange(daterange('2018-01-01', '2018-03-01')) where - id = '[1,2)' and - valid_at @> cast('2018-01-25' as date); + id = '[1,2)' and valid_at @> cast('2018-01-25' as date); update temporal_mltrng set id = '[2,3)', -valid_at = datemultirange( - daterange('2018-01-15', '2018-03-01') -) +valid_at = datemultirange(daterange('2018-01-15', '2018-03-01')) where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng set id = '[2,3)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-03-01') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[5,6)', - datemultirange( - daterange('2018-01-15', '2018-02-01') - ), - '[2,3)' - ); +values ('[5,6)', datemultirange(daterange('2018-01-15', '2018-02-01')), '[2,3)'); update temporal_mltrng -set valid_at = datemultirange( - daterange('2018-01-15', '2018-02-15') -) +set valid_at = datemultirange(daterange('2018-01-15', '2018-02-15')) where id = '[2,3)'; update temporal_mltrng -set valid_at = datemultirange( - daterange('2016-01-01', '2016-02-01') -) +set valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); begin; alter table temporal_fk_mltrng2mltrng - alter constraint "temporal_fk_mltrng2mltrng_fk" deferrable initially deferred; + alter constraint temporal_fk_mltrng2mltrng_fk deferrable initially deferred; update temporal_mltrng -set valid_at = datemultirange( - daterange('2016-01-01', '2016-02-01') -) +set valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); commit; update temporal_mltrng set id = '[7,8)' where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); truncate temporal_mltrng, temporal_fk_mltrng2mltrng; @@ -2245,159 +1395,70 @@ alter table temporal_fk_mltrng2mltrng truncate temporal_mltrng, temporal_fk_mltrng2mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))); delete from temporal_mltrng where id = '[5,6)'; insert into temporal_mltrng (id, valid_at) values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ), - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); + ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))), + ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); +values ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); delete from temporal_mltrng where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-02-01', '2018-03-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-02-01', '2018-03-01')); delete from temporal_mltrng where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); begin; alter table temporal_fk_mltrng2mltrng - alter constraint "temporal_fk_mltrng2mltrng_fk" deferrable initially deferred; + alter constraint temporal_fk_mltrng2mltrng_fk deferrable initially deferred; delete from temporal_mltrng where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); commit; create table tp1 partition of temporal_partitioned_rng -for values in ('[1,2)', -'[3,4)', -'[5,6)', -'[7,8)', -'[9,10)', -'[11,12)'); +for values in ('[1,2)', '[3,4)', '[5,6)', '[7,8)', '[9,10)', '[11,12)'); create table tp2 partition of temporal_partitioned_rng -for values in ('[2,3)', -'[4,5)', -'[6,7)', -'[8,9)', -'[10,11)', -'[12,13)'); +for values in ('[2,3)', '[4,5)', '[6,7)', '[8,9)', '[10,11)', '[12,13)'); insert into temporal_partitioned_rng (id, valid_at, name) values - ( - '[1,2)', - daterange('2000-01-01', '2000-02-01'), - 'one' - ), - ( - '[1,2)', - daterange('2000-02-01', '2000-03-01'), - 'one' - ), - ( - '[2,3)', - daterange('2000-01-01', '2010-01-01'), - 'two' - ); + ('[1,2)', daterange('2000-01-01', '2000-02-01'), 'one'), + ('[1,2)', daterange('2000-02-01', '2000-03-01'), 'one'), + ('[2,3)', daterange('2000-01-01', '2010-01-01'), 'two'); create table tfkp1 partition of temporal_partitioned_fk_rng2rng -for values in ('[1,2)', -'[3,4)', -'[5,6)', -'[7,8)', -'[9,10)', -'[11,12)'); +for values in ('[1,2)', '[3,4)', '[5,6)', '[7,8)', '[9,10)', '[11,12)'); create table tfkp2 partition of temporal_partitioned_fk_rng2rng -for values in ('[2,3)', -'[4,5)', -'[6,7)', -'[8,9)', -'[10,11)', -'[12,13)'); +for values in ('[2,3)', '[4,5)', '[6,7)', '[8,9)', '[10,11)', '[12,13)'); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) values - ( - '[1,2)', - daterange('2000-01-01', '2000-02-15'), - '[1,2)' - ), - ( - '[1,2)', - daterange('2001-01-01', '2002-01-01'), - '[2,3)' - ), - ( - '[2,3)', - daterange('2000-01-01', '2000-02-15'), - '[1,2)' - ); + ('[1,2)', daterange('2000-01-01', '2000-02-15'), '[1,2)'), + ('[1,2)', daterange('2001-01-01', '2002-01-01'), '[2,3)'), + ('[2,3)', daterange('2000-01-01', '2000-02-15'), '[1,2)'); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2010-01-01', '2010-02-15'), - '[1,2)' - ); +values ('[3,4)', daterange('2010-01-01', '2010-02-15'), '[1,2)'); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2000-01-01', '2000-02-15'), - '[3,4)' - ); +values ('[3,4)', daterange('2000-01-01', '2000-02-15'), '[3,4)'); update temporal_partitioned_fk_rng2rng set valid_at = daterange('2000-01-01', '2000-02-13') @@ -2416,8 +1477,7 @@ where truncate temporal_partitioned_rng, temporal_partitioned_fk_rng2rng; insert into temporal_partitioned_rng (id, valid_at) -values - ('[5,6)', daterange('2016-01-01', '2016-02-01')); +values ('[5,6)', daterange('2016-01-01', '2016-02-01')); update temporal_partitioned_rng set valid_at = daterange('2018-01-01', '2018-02-01') @@ -2425,56 +1485,39 @@ where id = '[5,6)'; insert into temporal_partitioned_rng (id, valid_at) -values - ('[5,6)', daterange('2018-02-01', '2018-03-01')); +values ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); update temporal_partitioned_rng set valid_at = daterange('2016-02-01', '2016-03-01') where - id = '[5,6)' and - valid_at = daterange('2018-02-01', '2018-03-01'); + id = '[5,6)' and valid_at = daterange('2018-02-01', '2018-03-01'); update temporal_partitioned_rng set valid_at = daterange('2016-01-01', '2016-02-01') where - id = '[5,6)' and - valid_at = daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); truncate temporal_partitioned_rng, temporal_partitioned_fk_rng2rng; insert into temporal_partitioned_rng (id, valid_at) -values - ('[5,6)', daterange('2018-01-01', '2018-02-01')); +values ('[5,6)', daterange('2018-01-01', '2018-02-01')); insert into temporal_partitioned_rng (id, valid_at) -values - ('[5,6)', daterange('2018-02-01', '2018-03-01')); +values ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); delete from temporal_partitioned_rng where - id = '[5,6)' and - valid_at = daterange('2018-02-01', '2018-03-01'); + id = '[5,6)' and valid_at = daterange('2018-02-01', '2018-03-01'); delete from temporal_partitioned_rng where - id = '[5,6)' and - valid_at = daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); drop table temporal_partitioned_fk_rng2rng; @@ -2482,138 +1525,94 @@ drop table temporal_partitioned_rng; create table tp1 partition of temporal_partitioned_mltrng -for values in ('[1,2)', -'[3,4)', -'[5,6)', -'[7,8)', -'[9,10)', -'[11,12)', -'[13,14)', -'[15,16)', -'[17,18)', -'[19,20)', -'[21,22)', -'[23,24)'); +for values in ( + '[1,2)', + '[3,4)', + '[5,6)', + '[7,8)', + '[9,10)', + '[11,12)', + '[13,14)', + '[15,16)', + '[17,18)', + '[19,20)', + '[21,22)', + '[23,24)' +); create table tp2 partition of temporal_partitioned_mltrng -for values in ('[0,1)', -'[2,3)', -'[4,5)', -'[6,7)', -'[8,9)', -'[10,11)', -'[12,13)', -'[14,15)', -'[16,17)', -'[18,19)', -'[20,21)', -'[22,23)', -'[24,25)'); +for values in ( + '[0,1)', + '[2,3)', + '[4,5)', + '[6,7)', + '[8,9)', + '[10,11)', + '[12,13)', + '[14,15)', + '[16,17)', + '[18,19)', + '[20,21)', + '[22,23)', + '[24,25)' +); insert into temporal_partitioned_mltrng (id, valid_at, name) values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2000-02-01') - ), - 'one' - ), - ( - '[1,2)', - datemultirange( - daterange('2000-02-01', '2000-03-01') - ), - 'one' - ), - ( - '[2,3)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ), - 'two' - ); + ('[1,2)', datemultirange(daterange('2000-01-01', '2000-02-01')), 'one'), + ('[1,2)', datemultirange(daterange('2000-02-01', '2000-03-01')), 'one'), + ('[2,3)', datemultirange(daterange('2000-01-01', '2010-01-01')), 'two'); create table tfkp1 partition of temporal_partitioned_fk_mltrng2mltrng -for values in ('[1,2)', -'[3,4)', -'[5,6)', -'[7,8)', -'[9,10)', -'[11,12)', -'[13,14)', -'[15,16)', -'[17,18)', -'[19,20)', -'[21,22)', -'[23,24)'); +for values in ( + '[1,2)', + '[3,4)', + '[5,6)', + '[7,8)', + '[9,10)', + '[11,12)', + '[13,14)', + '[15,16)', + '[17,18)', + '[19,20)', + '[21,22)', + '[23,24)' +); create table tfkp2 partition of temporal_partitioned_fk_mltrng2mltrng -for values in ('[0,1)', -'[2,3)', -'[4,5)', -'[6,7)', -'[8,9)', -'[10,11)', -'[12,13)', -'[14,15)', -'[16,17)', -'[18,19)', -'[20,21)', -'[22,23)', -'[24,25)'); +for values in ( + '[0,1)', + '[2,3)', + '[4,5)', + '[6,7)', + '[8,9)', + '[10,11)', + '[12,13)', + '[14,15)', + '[16,17)', + '[18,19)', + '[20,21)', + '[22,23)', + '[24,25)' +); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2000-02-15') - ), - '[1,2)' - ), - ( - '[1,2)', - datemultirange( - daterange('2001-01-01', '2002-01-01') - ), - '[2,3)' - ), - ( - '[2,3)', - datemultirange( - daterange('2000-01-01', '2000-02-15') - ), - '[1,2)' - ); + ('[1,2)', datemultirange(daterange('2000-01-01', '2000-02-15')), '[1,2)'), + ('[1,2)', datemultirange(daterange('2001-01-01', '2002-01-01')), '[2,3)'), + ('[2,3)', datemultirange(daterange('2000-01-01', '2000-02-15')), '[1,2)'); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[3,4)', - datemultirange( - daterange('2010-01-01', '2010-02-15') - ), - '[1,2)' - ); +values ('[3,4)', datemultirange(daterange('2010-01-01', '2010-02-15')), '[1,2)'); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[3,4)', - datemultirange( - daterange('2000-01-01', '2000-02-15') - ), - '[3,4)' - ); +values ('[3,4)', datemultirange(daterange('2000-01-01', '2000-02-15')), '[3,4)'); update temporal_partitioned_fk_mltrng2mltrng -set valid_at = datemultirange( - daterange('2000-01-01', '2000-02-13') -) +set valid_at = datemultirange(daterange('2000-01-01', '2000-02-13')) where id = '[2,3)'; @@ -2622,116 +1621,54 @@ update temporal_partitioned_fk_mltrng2mltrng set id = '[4,5)' where id = '[1,2)' update temporal_partitioned_fk_mltrng2mltrng set id = '[1,2)' where id = '[4,5)'; update temporal_partitioned_fk_mltrng2mltrng -set valid_at = datemultirange( - daterange('2000-01-01', '2000-04-01') -) +set valid_at = datemultirange(daterange('2000-01-01', '2000-04-01')) where id = '[1,2)'; truncate temporal_partitioned_mltrng, temporal_partitioned_fk_mltrng2mltrng; insert into temporal_partitioned_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2016-01-01', '2016-02-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2016-01-01', '2016-02-01'))); update temporal_partitioned_mltrng -set valid_at = datemultirange( - daterange('2018-01-01', '2018-02-01') -) +set valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')) where id = '[5,6)'; insert into temporal_partitioned_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); +values ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); update temporal_partitioned_mltrng -set valid_at = datemultirange( - daterange('2016-02-01', '2016-03-01') -) +set valid_at = datemultirange(daterange('2016-02-01', '2016-03-01')) where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-02-01', '2018-03-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-02-01', '2018-03-01')); update temporal_partitioned_mltrng -set valid_at = datemultirange( - daterange('2016-01-01', '2016-02-01') -) +set valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); truncate temporal_partitioned_mltrng, temporal_partitioned_fk_mltrng2mltrng; insert into temporal_partitioned_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))); insert into temporal_partitioned_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); +values ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); delete from temporal_partitioned_mltrng where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-02-01', '2018-03-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-02-01', '2018-03-01')); delete from temporal_partitioned_mltrng where - id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + id = '[5,6)' and valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); drop table temporal_partitioned_fk_mltrng2mltrng; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__without_overlaps_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__without_overlaps_80.snap index 423e6800b..4a3278983 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__without_overlaps_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__without_overlaps_80.snap @@ -63,7 +63,7 @@ from where conname = 'temporal_rng2_pk'; -create type textrange2 as range (subtype = text, collation = "C"); +create type textrange2 as range (subtype = text, "collation" = "C"); alter table temporal_rng3 drop constraint temporal_rng3_pk; @@ -132,7 +132,7 @@ where drop table temporal_rng3; -create type textrange2 as range (subtype = text, collation = "C"); +create type textrange2 as range (subtype = text, "collation" = "C"); alter table temporal_rng3 drop constraint temporal_rng3_uq; @@ -151,10 +151,10 @@ create table temporal3 ( valid_at daterange ); -create index "idx_temporal3_uq" on temporal3 using gist (id, valid_at); +create index idx_temporal3_uq on temporal3 using gist (id, valid_at); alter table temporal3 - add constraint "temporal3_pk" primary key using index "idx_temporal3_uq"; + add constraint temporal3_pk primary key using index idx_temporal3_uq; drop table temporal3; @@ -163,10 +163,10 @@ create table temporal3 ( valid_at daterange ); -create index "idx_temporal3_uq" on temporal3 using gist (id, valid_at); +create index idx_temporal3_uq on temporal3 using gist (id, valid_at); alter table temporal3 - add constraint "temporal3_uq" unique using index "idx_temporal3_uq"; + add constraint temporal3_uq unique using index idx_temporal3_uq; drop table temporal3; @@ -175,10 +175,10 @@ create table temporal3 ( valid_at daterange ); -create unique index "idx_temporal3_uq" on temporal3 using btree (id, valid_at); +create unique index idx_temporal3_uq on temporal3 using btree (id, valid_at); alter table temporal3 - add constraint "temporal3_uq" unique using index "idx_temporal3_uq"; + add constraint temporal3_uq unique using index idx_temporal3_uq; drop table temporal3; @@ -194,29 +194,16 @@ alter table temporal_rng drop constraint temporal_rng_pk; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-03') - ); +values ('[1,2)', daterange('2018-01-02', '2018-02-03')); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2018-03-03', '2018-04-04') - ); +values ('[1,2)', daterange('2018-03-03', '2018-04-04')); insert into temporal_rng (id, valid_at) -values - ( - '[2,3)', - daterange('2018-01-01', '2018-01-05') - ); +values ('[2,3)', daterange('2018-01-01', '2018-01-05')); insert into temporal_rng (id, valid_at) -values - ('[3,4)', daterange('2018-01-01', null)); +values ('[3,4)', daterange('2018-01-01', null)); alter table temporal_rng drop constraint temporal_rng_pk; @@ -224,11 +211,7 @@ alter table temporal_rng begin; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2018-01-01', '2018-01-05') - ); +values ('[1,2)', daterange('2018-01-01', '2018-01-05')); rollback; @@ -241,43 +224,22 @@ rollback; delete from temporal_rng; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-03') - ); +values ('[1,2)', daterange('2018-01-02', '2018-02-03')); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2018-03-03', '2018-04-04') - ); +values ('[1,2)', daterange('2018-03-03', '2018-04-04')); insert into temporal_rng (id, valid_at) -values - ( - '[2,3)', - daterange('2018-01-01', '2018-01-05') - ); +values ('[2,3)', daterange('2018-01-01', '2018-01-05')); insert into temporal_rng (id, valid_at) -values - ('[3,4)', daterange('2018-01-01', null)); +values ('[3,4)', daterange('2018-01-01', null)); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2018-01-01', '2018-01-05') - ); +values ('[1,2)', daterange('2018-01-01', '2018-01-05')); insert into temporal_rng (id, valid_at) -values - ( - null, - daterange('2018-01-01', '2018-01-05') - ); +values (null, daterange('2018-01-01', '2018-01-05')); insert into temporal_rng (id, valid_at) values ('[3,4)', null); @@ -288,21 +250,18 @@ select * from temporal_rng order by id, valid_at; update temporal_rng set id = '[11,12)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_rng set valid_at = '[2020-01-01,2021-01-01)' where - id = '[11,12)' and - valid_at @> cast('2018-01-15' as date); + id = '[11,12)' and valid_at @> cast('2018-01-15' as date); update temporal_rng set id = '[21,22)', valid_at = '[2018-01-02,2018-02-03)' where - id = '[11,12)' and - valid_at @> cast('2020-01-15' as date); + id = '[11,12)' and valid_at @> cast('2020-01-15' as date); select * from temporal_rng order by id, valid_at; @@ -330,36 +289,19 @@ create table temporal_rng3 ( ); insert into temporal_rng3 (id, valid_at) -values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-03') - ); +values ('[1,2)', daterange('2018-01-02', '2018-02-03')); insert into temporal_rng3 (id, valid_at) -values - ( - '[1,2)', - daterange('2018-03-03', '2018-04-04') - ); +values ('[1,2)', daterange('2018-03-03', '2018-04-04')); insert into temporal_rng3 (id, valid_at) -values - ( - '[2,3)', - daterange('2018-01-01', '2018-01-05') - ); +values ('[2,3)', daterange('2018-01-01', '2018-01-05')); insert into temporal_rng3 (id, valid_at) -values - ('[3,4)', daterange('2018-01-01', null)); +values ('[3,4)', daterange('2018-01-01', null)); insert into temporal_rng3 (id, valid_at) -values - ( - null, - daterange('2018-01-01', '2018-01-05') - ); +values (null, daterange('2018-01-01', '2018-01-05')); insert into temporal_rng3 (id, valid_at) values ('[3,4)', null); @@ -369,11 +311,7 @@ alter table temporal_rng3 begin; insert into temporal_rng3 (id, valid_at) -values - ( - '[1,2)', - daterange('2018-01-01', '2018-01-05') - ); +values ('[1,2)', daterange('2018-01-01', '2018-01-05')); rollback; @@ -386,45 +324,24 @@ rollback; delete from temporal_rng3; insert into temporal_rng3 (id, valid_at) -values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-03') - ); +values ('[1,2)', daterange('2018-01-02', '2018-02-03')); insert into temporal_rng3 (id, valid_at) -values - ( - '[1,2)', - daterange('2018-03-03', '2018-04-04') - ); +values ('[1,2)', daterange('2018-03-03', '2018-04-04')); insert into temporal_rng3 (id, valid_at) -values - ( - '[2,3)', - daterange('2018-01-01', '2018-01-05') - ); +values ('[2,3)', daterange('2018-01-01', '2018-01-05')); insert into temporal_rng3 (id, valid_at) -values - ('[3,4)', daterange('2018-01-01', null)); +values ('[3,4)', daterange('2018-01-01', null)); insert into temporal_rng3 (id, valid_at) -values - ( - null, - daterange('2018-01-01', '2018-01-05') - ); +values (null, daterange('2018-01-01', '2018-01-05')); insert into temporal_rng3 (id, valid_at) values ('[3,4)', null); insert into temporal_rng3 (id, valid_at) -values - ( - '[1,2)', - daterange('2018-01-01', '2018-01-05') - ); +values ('[1,2)', daterange('2018-01-01', '2018-01-05')); insert into temporal_rng3 (id, valid_at) values ('[3,4)', 'empty'); @@ -433,21 +350,18 @@ select * from temporal_rng3 order by id, valid_at; update temporal_rng3 set id = '[11,12)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_rng3 set valid_at = '[2020-01-01,2021-01-01)' where - id = '[11,12)' and - valid_at @> cast('2018-01-15' as date); + id = '[11,12)' and valid_at @> cast('2018-01-15' as date); update temporal_rng3 set id = '[21,22)', valid_at = '[2018-01-02,2018-02-03)' where - id = '[11,12)' and - valid_at @> cast('2020-01-15' as date); + id = '[11,12)' and valid_at @> cast('2020-01-15' as date); update temporal_rng3 set id = null, @@ -459,8 +373,7 @@ update temporal_rng3 set id = '[1,2)', valid_at = null where - id is null and - valid_at @> cast('2020-06-01' as date); + id is null and valid_at @> cast('2020-06-01' as date); select * from temporal_rng3 order by id, valid_at; @@ -488,40 +401,16 @@ alter table temporal_mltrng drop constraint temporal_mltrng_pk; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-01', null) - ) - ); +values ('[3,4)', datemultirange(daterange('2018-01-01', null))); alter table temporal_mltrng drop constraint temporal_mltrng_pk; @@ -529,13 +418,7 @@ alter table temporal_mltrng begin; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-01', '2018-01-05'))); rollback; @@ -548,58 +431,22 @@ rollback; delete from temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-01', null) - ) - ); +values ('[3,4)', datemultirange(daterange('2018-01-01', null))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng (id, valid_at) -values - ( - null, - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values (null, datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng (id, valid_at) values ('[3,4)', null); @@ -610,37 +457,30 @@ select * from temporal_mltrng order by id, valid_at; update temporal_mltrng set id = '[11,12)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng set valid_at = '{[2020-01-01,2021-01-01)}' where - id = '[11,12)' and - valid_at @> cast('2018-01-15' as date); + id = '[11,12)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng set id = '[21,22)', valid_at = '{[2018-01-02,2018-02-03)}' where - id = '[11,12)' and - valid_at @> cast('2020-01-15' as date); + id = '[11,12)' and valid_at @> cast('2020-01-15' as date); select * from temporal_mltrng order by id, valid_at; update temporal_mltrng set id = '[1,2)', -valid_at = datemultirange( - daterange('2018-03-05', '2018-05-05') -) +valid_at = datemultirange(daterange('2018-03-05', '2018-05-05')) where id = '[21,22)'; update temporal_mltrng set id = null, -valid_at = datemultirange( - daterange('2018-03-05', '2018-05-05') -) +valid_at = datemultirange(daterange('2018-03-05', '2018-05-05')) where id = '[21,22)'; @@ -656,49 +496,19 @@ create table temporal_mltrng3 ( ); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-01', null) - ) - ); +values ('[3,4)', datemultirange(daterange('2018-01-01', null))); insert into temporal_mltrng3 (id, valid_at) -values - ( - null, - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values (null, datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) values ('[3,4)', null); @@ -708,13 +518,7 @@ alter table temporal_mltrng3 begin; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-01', '2018-01-05'))); rollback; @@ -727,60 +531,24 @@ rollback; delete from temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[3,4)', - datemultirange( - daterange('2018-01-01', null) - ) - ); +values ('[3,4)', datemultirange(daterange('2018-01-01', null))); insert into temporal_mltrng3 (id, valid_at) -values - ( - null, - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values (null, datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) values ('[3,4)', null); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-01-01', '2018-01-05'))); insert into temporal_mltrng3 (id, valid_at) values ('[3,4)', '{}'); @@ -789,27 +557,22 @@ select * from temporal_mltrng3 order by id, valid_at; update temporal_mltrng3 set id = '[11,12)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng3 set valid_at = '{[2020-01-01,2021-01-01)}' where - id = '[11,12)' and - valid_at @> cast('2018-01-15' as date); + id = '[11,12)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng3 set id = '[21,22)', valid_at = '{[2018-01-02,2018-02-03)}' where - id = '[11,12)' and - valid_at @> cast('2020-01-15' as date); + id = '[11,12)' and valid_at @> cast('2020-01-15' as date); update temporal_mltrng3 set id = null, -valid_at = datemultirange( - daterange('2020-01-01', '2021-01-01') -) +valid_at = datemultirange(daterange('2020-01-01', '2021-01-01')) where id = '[21,22)'; @@ -817,15 +580,12 @@ update temporal_mltrng3 set id = '[1,2)', valid_at = null where - id is null and - valid_at @> cast('2020-06-01' as date); + id is null and valid_at @> cast('2020-06-01' as date); select * from temporal_mltrng3 order by id, valid_at; update temporal_mltrng3 -set valid_at = datemultirange( - daterange('2018-03-01', '2018-05-05') -) +set valid_at = datemultirange(daterange('2018-03-01', '2018-05-05')) where id = '[1,2)' and valid_at is null; @@ -846,18 +606,8 @@ drop table temporal_mltrng3; insert into temporal3 (id, valid_at, id2, name) values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01'), - '[7,8)', - 'foo' - ), - ( - '[2,3)', - daterange('2000-01-01', '2010-01-01'), - '[9,10)', - 'bar' - ); + ('[1,2)', daterange('2000-01-01', '2010-01-01'), '[7,8)', 'foo'), + ('[2,3)', daterange('2000-01-01', '2010-01-01'), '[9,10)', 'bar'); drop table temporal3; @@ -887,21 +637,9 @@ for values in ('[3,4)', '[4,5)'); insert into temporal_partitioned (id, valid_at, name) values - ( - '[1,2)', - daterange('2000-01-01', '2000-02-01'), - 'one' - ), - ( - '[1,2)', - daterange('2000-02-01', '2000-03-01'), - 'one' - ), - ( - '[3,4)', - daterange('2000-01-01', '2010-01-01'), - 'three' - ); + ('[1,2)', daterange('2000-01-01', '2000-02-01'), 'one'), + ('[1,2)', daterange('2000-02-01', '2000-03-01'), 'one'), + ('[3,4)', daterange('2000-01-01', '2010-01-01'), 'three'); select * from temporal_partitioned order by id, valid_at; @@ -921,21 +659,9 @@ for values in ('[3,4)', '[4,5)'); insert into temporal_partitioned (id, valid_at, name) values - ( - '[1,2)', - daterange('2000-01-01', '2000-02-01'), - 'one' - ), - ( - '[1,2)', - daterange('2000-02-01', '2000-03-01'), - 'one' - ), - ( - '[3,4)', - daterange('2000-01-01', '2010-01-01'), - 'three' - ); + ('[1,2)', daterange('2000-01-01', '2000-02-01'), 'one'), + ('[1,2)', daterange('2000-02-01', '2000-03-01'), 'one'), + ('[3,4)', daterange('2000-01-01', '2010-01-01'), 'three'); select * from temporal_partitioned order by id, valid_at; @@ -946,41 +672,23 @@ select * from tp2 order by id, valid_at; drop table temporal_partitioned; alter table temporal_rng - replica identity - using index - temporal_rng_pk; + replica identity using index temporal_rng_pk; truncate temporal_rng; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict do nothing; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict do nothing; insert into temporal_rng (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict do nothing; select * from temporal_rng order by id, valid_at; @@ -988,34 +696,18 @@ select * from temporal_rng order by id, valid_at; truncate temporal_rng; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict (id, valid_at) do nothing; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict (id, valid_at) do nothing; insert into temporal_rng (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict (id, valid_at) do nothing; select * from temporal_rng order by id, valid_at; @@ -1023,106 +715,48 @@ select * from temporal_rng order by id, valid_at; truncate temporal_rng; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -on constraint temporal_rng_pk -do nothing; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal_rng_pk do nothing; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) -on conflict -on constraint temporal_rng_pk -do nothing; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict on constraint temporal_rng_pk do nothing; insert into temporal_rng (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -on constraint temporal_rng_pk -do nothing; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal_rng_pk do nothing; select * from temporal_rng order by id, valid_at; truncate temporal_rng; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[2,3)'; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[3,4)'; insert into temporal_rng (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[4,5)'; select * from temporal_rng order by id, valid_at; truncate temporal_rng; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict on constraint temporal_rng_pk do @@ -1130,11 +764,7 @@ update set id = excluded.id + '[2,3)'; insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict on constraint temporal_rng_pk do @@ -1142,11 +772,7 @@ update set id = excluded.id + '[3,4)'; insert into temporal_rng (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict on constraint temporal_rng_pk do @@ -1158,34 +784,18 @@ select * from temporal_rng order by id, valid_at; truncate temporal3; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict do nothing; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict do nothing; insert into temporal3 (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict do nothing; select * from temporal3 order by id, valid_at; @@ -1193,34 +803,18 @@ select * from temporal3 order by id, valid_at; truncate temporal3; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) on conflict (id, valid_at) do nothing; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) on conflict (id, valid_at) do nothing; insert into temporal3 (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) on conflict (id, valid_at) do nothing; select * from temporal3 order by id, valid_at; @@ -1228,135 +822,57 @@ select * from temporal3 order by id, valid_at; truncate temporal3; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -on constraint temporal3_uq -do nothing; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal3_uq do nothing; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) -on conflict -on constraint temporal3_uq -do nothing; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict on constraint temporal3_uq do nothing; insert into temporal3 (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -on constraint temporal3_uq -do nothing; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal3_uq do nothing; select * from temporal3 order by id, valid_at; truncate temporal3; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[2,3)'; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[3,4)'; insert into temporal3 (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict (id, valid_at) do update set id = excluded.id + '[4,5)'; select * from temporal3 order by id, valid_at; truncate temporal3; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2000-01-01', '2010-01-01') - ); +values ('[1,2)', daterange('2000-01-01', '2010-01-01')); insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -on constraint temporal3_uq -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal3_uq do update set id = excluded.id + '[2,3)'; insert into temporal3 (id, valid_at) -values - ( - '[1,2)', - daterange('2010-01-01', '2020-01-01') - ) -on conflict -on constraint temporal3_uq -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', daterange('2010-01-01', '2020-01-01')) +on conflict on constraint temporal3_uq do update set id = excluded.id + '[3,4)'; insert into temporal3 (id, valid_at) -values - ( - '[2,3)', - daterange('2005-01-01', '2006-01-01') - ) -on conflict -on constraint temporal3_uq -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', daterange('2005-01-01', '2006-01-01')) +on conflict on constraint temporal3_uq do update set id = excluded.id + '[4,5)'; select * from temporal3 order by id, valid_at; @@ -1365,42 +881,18 @@ drop table temporal3; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict do nothing; select * from temporal_mltrng order by id, valid_at; @@ -1408,42 +900,18 @@ select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict (id, valid_at) do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict (id, valid_at) do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict (id, valid_at) do nothing; select * from temporal_mltrng order by id, valid_at; @@ -1451,126 +919,48 @@ select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do nothing; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng_pk do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do nothing; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict on constraint temporal_mltrng_pk do nothing; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng_pk -do nothing; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng_pk do nothing; select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[2,3)'; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[3,4)'; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[4,5)'; select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict on constraint temporal_mltrng_pk do @@ -1578,13 +968,7 @@ update set id = excluded.id + '[2,3)'; insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict on constraint temporal_mltrng_pk do @@ -1592,13 +976,7 @@ update set id = excluded.id + '[3,4)'; insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict on constraint temporal_mltrng_pk do @@ -1610,42 +988,18 @@ select * from temporal_mltrng order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict do nothing; select * from temporal_mltrng3 order by id, valid_at; @@ -1653,42 +1007,18 @@ select * from temporal_mltrng3 order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict (id, valid_at) do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict (id, valid_at) do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict (id, valid_at) do nothing; select * from temporal_mltrng3 order by id, valid_at; @@ -1696,126 +1026,48 @@ select * from temporal_mltrng3 order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do nothing; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng3_uq do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do nothing; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict on constraint temporal_mltrng3_uq do nothing; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -on constraint temporal_mltrng3_uq -do nothing; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict on constraint temporal_mltrng3_uq do nothing; select * from temporal_mltrng3 order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[2,3)'; +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[2,3)'; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[3,4)'; +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[3,4)'; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) -on conflict -(id, valid_at) -do -update -set id = excluded.id + '[4,5)'; +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) +on conflict (id, valid_at) do update set id = excluded.id + '[4,5)'; select * from temporal_mltrng3 order by id, valid_at; truncate temporal_mltrng3; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ) - ); +values ('[1,2)', datemultirange(daterange('2000-01-01', '2010-01-01'))); insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict on constraint temporal_mltrng3_uq do @@ -1823,13 +1075,7 @@ update set id = excluded.id + '[2,3)'; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2010-01-01', '2020-01-01') - ) - ) +values ('[1,2)', datemultirange(daterange('2010-01-01', '2020-01-01'))) on conflict on constraint temporal_mltrng3_uq do @@ -1837,13 +1083,7 @@ update set id = excluded.id + '[3,4)'; insert into temporal_mltrng3 (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2005-01-01', '2006-01-01') - ) - ) +values ('[2,3)', datemultirange(daterange('2005-01-01', '2006-01-01'))) on conflict on constraint temporal_mltrng3_uq do @@ -1898,41 +1138,22 @@ delete from temporal_rng; insert into temporal_rng (id, valid_at) values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-03') - ), - ( - '[1,2)', - daterange('2018-03-03', '2018-04-04') - ), - ( - '[2,3)', - daterange('2018-01-01', '2018-01-05') - ), + ('[1,2)', daterange('2018-01-02', '2018-02-03')), + ('[1,2)', daterange('2018-03-03', '2018-04-04')), + ('[2,3)', daterange('2018-01-01', '2018-01-05')), ('[3,4)', daterange('2018-01-01', null)); alter table temporal_fk_rng2rng drop constraint temporal_fk_rng2rng_fk; insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-01'), - '[1,2)' - ); +values ('[1,2)', daterange('2018-01-02', '2018-02-01'), '[1,2)'); alter table temporal_fk_rng2rng drop constraint temporal_fk_rng2rng_fk; insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[2,3)', - daterange('2018-01-02', '2018-04-01'), - '[1,2)' - ); +values ('[2,3)', daterange('2018-01-02', '2018-04-01'), '[1,2)'); delete from temporal_fk_rng2rng; @@ -1944,35 +1165,16 @@ where conname = 'temporal_fk_rng2rng_fk'; insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[1,2)', - daterange('2018-01-02', '2018-02-01'), - '[1,2)' - ); +values ('[1,2)', daterange('2018-01-02', '2018-02-01'), '[1,2)'); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[2,3)', - daterange('2018-01-02', '2018-04-01'), - '[1,2)' - ); +values ('[2,3)', daterange('2018-01-02', '2018-04-01'), '[1,2)'); insert into temporal_rng (id, valid_at) -values - ( - '[1,2)', - daterange('2018-02-03', '2018-03-03') - ); +values ('[1,2)', daterange('2018-02-03', '2018-03-03')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[2,3)', - daterange('2018-01-02', '2018-04-01'), - '[1,2)' - ); +values ('[2,3)', daterange('2018-01-02', '2018-04-01'), '[1,2)'); update temporal_fk_rng2rng set valid_at = daterange('2018-01-02', '2018-02-20') @@ -1990,25 +1192,14 @@ begin; insert into temporal_rng (id, valid_at) values - ( - '[5,6)', - daterange('2018-01-01', '2018-02-01') - ), - ( - '[5,6)', - daterange('2018-02-01', '2018-03-01') - ); + ('[5,6)', daterange('2018-01-01', '2018-02-01')), + ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); alter table temporal_fk_rng2rng - alter constraint "temporal_fk_rng2rng_fk" deferrable initially deferred; + alter constraint temporal_fk_rng2rng_fk deferrable initially deferred; delete from temporal_rng where id = '[5,6)'; @@ -2020,11 +1211,7 @@ alter table temporal_fk_rng2rng drop constraint temporal_fk_rng2rng_fk; insert into temporal_rng (id, valid_at) -values - ( - '[5,6)', - daterange('2018-01-01', '2018-02-01') - ); +values ('[5,6)', daterange('2018-01-01', '2018-02-01')); update temporal_rng set valid_at = daterange('2016-01-01', '2016-02-01') @@ -2035,122 +1222,69 @@ delete from temporal_rng where id = '[5,6)'; insert into temporal_rng (id, valid_at) values - ( - '[5,6)', - daterange('2018-01-01', '2018-02-01') - ), - ( - '[5,6)', - daterange('2018-02-01', '2018-03-01') - ); + ('[5,6)', daterange('2018-01-01', '2018-02-01')), + ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); update temporal_rng set valid_at = daterange('2016-02-01', '2016-03-01') where - id = '[5,6)' and - valid_at = - daterange('2018-02-01', '2018-03-01'); + id = '[5,6)' and valid_at = daterange('2018-02-01', '2018-03-01'); insert into temporal_rng (id, valid_at) values - ( - '[6,7)', - daterange('2018-01-01', '2018-02-01') - ), - ( - '[6,7)', - daterange('2018-02-01', '2018-03-01') - ); + ('[6,7)', daterange('2018-01-01', '2018-02-01')), + ('[6,7)', daterange('2018-02-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[4,5)', - daterange('2018-01-15', '2018-02-15'), - '[6,7)' - ); +values ('[4,5)', daterange('2018-01-15', '2018-02-15'), '[6,7)'); update temporal_rng set valid_at = case - when lower(valid_at) = '2018-01-01' - then daterange('2018-01-01', '2018-01-05') - when lower(valid_at) = '2018-02-01' - then daterange('2018-01-05', '2018-03-01') + when lower(valid_at) = '2018-01-01' then daterange('2018-01-01', '2018-01-05') + when lower(valid_at) = '2018-02-01' then daterange('2018-01-05', '2018-03-01') end where id = '[6,7)'; insert into temporal_rng (id, valid_at) values - ( - '[1,2)', - daterange('2018-01-01', '2018-03-01') - ), - ( - '[1,2)', - daterange('2018-03-01', '2018-06-01') - ); + ('[1,2)', daterange('2018-01-01', '2018-03-01')), + ('[1,2)', daterange('2018-03-01', '2018-06-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) values - ( - '[1,2)', - daterange('2018-01-15', '2018-02-01'), - '[1,2)' - ), - ( - '[2,3)', - daterange('2018-01-15', '2018-05-01'), - '[1,2)' - ); + ('[1,2)', daterange('2018-01-15', '2018-02-01'), '[1,2)'), + ('[2,3)', daterange('2018-01-15', '2018-05-01'), '[1,2)'); update temporal_rng set valid_at = daterange('2018-01-15', '2018-03-01') where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_rng set valid_at = daterange('2018-01-01', '2018-03-01') where - id = '[1,2)' and - valid_at @> cast('2018-01-25' as date); + id = '[1,2)' and valid_at @> cast('2018-01-25' as date); update temporal_rng set id = '[2,3)', valid_at = daterange('2018-01-15', '2018-03-01') where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_rng set id = '[2,3)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); insert into temporal_rng (id, valid_at) -values - ( - '[2,3)', - daterange('2018-01-01', '2018-03-01') - ); +values ('[2,3)', daterange('2018-01-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[5,6)', - daterange('2018-01-15', '2018-02-01'), - '[2,3)' - ); +values ('[5,6)', daterange('2018-01-15', '2018-02-01'), '[2,3)'); update temporal_rng set valid_at = daterange('2018-01-15', '2018-02-15') @@ -2160,39 +1294,31 @@ where update temporal_rng set valid_at = daterange('2016-01-01', '2016-02-01') where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); begin; alter table temporal_fk_rng2rng - alter constraint "temporal_fk_rng2rng_fk" deferrable initially deferred; + alter constraint temporal_fk_rng2rng_fk deferrable initially deferred; update temporal_rng set valid_at = daterange('2016-01-01', '2016-02-01') where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); commit; update temporal_rng set id = '[7,8)' where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); delete from temporal_fk_rng2rng where id = '[3,4)'; update temporal_rng set valid_at = daterange('2016-01-01', '2016-02-01') where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); truncate temporal_rng, temporal_fk_rng2rng; @@ -2202,55 +1328,34 @@ alter table temporal_fk_rng2rng truncate temporal_rng, temporal_fk_rng2rng; insert into temporal_rng (id, valid_at) -values - ( - '[5,6)', - daterange('2018-01-01', '2018-02-01') - ); +values ('[5,6)', daterange('2018-01-01', '2018-02-01')); delete from temporal_rng where id = '[5,6)'; insert into temporal_rng (id, valid_at) values - ( - '[5,6)', - daterange('2018-01-01', '2018-02-01') - ), - ( - '[5,6)', - daterange('2018-02-01', '2018-03-01') - ); + ('[5,6)', daterange('2018-01-01', '2018-02-01')), + ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); delete from temporal_rng where - id = '[5,6)' and - valid_at = - daterange('2018-02-01', '2018-03-01'); + id = '[5,6)' and valid_at = daterange('2018-02-01', '2018-03-01'); delete from temporal_rng where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); begin; alter table temporal_fk_rng2rng - alter constraint "temporal_fk_rng2rng_fk" deferrable initially deferred; + alter constraint temporal_fk_rng2rng_fk deferrable initially deferred; delete from temporal_rng where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); commit; @@ -2258,9 +1363,7 @@ delete from temporal_fk_rng2rng where id = '[3,4)'; delete from temporal_rng where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); truncate temporal_rng, temporal_fk_rng2rng; @@ -2268,53 +1371,25 @@ alter table temporal_fk_rng2rng drop constraint temporal_fk_rng2rng_fk; insert into temporal_rng (id, valid_at) -values - ( - '[6,7)', - daterange('2018-01-01', '2021-01-01') - ); +values ('[6,7)', daterange('2018-01-01', '2021-01-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[4,5)', - daterange('2018-01-01', '2021-01-01'), - '[6,7)' - ); +values ('[4,5)', daterange('2018-01-01', '2021-01-01'), '[6,7)'); insert into temporal_rng (id, valid_at) -values - ( - '[9,10)', - daterange('2018-01-01', '2021-01-01') - ); +values ('[9,10)', daterange('2018-01-01', '2021-01-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[6,7)', - daterange('2018-01-01', '2021-01-01'), - '[9,10)' - ); +values ('[6,7)', daterange('2018-01-01', '2021-01-01'), '[9,10)'); insert into temporal_rng (id, valid_at) -values - ('[-1,-1]', daterange(null, null)); +values ('[-1,-1]', daterange(null, null)); insert into temporal_rng (id, valid_at) -values - ( - '[12,13)', - daterange('2018-01-01', '2021-01-01') - ); +values ('[12,13)', daterange('2018-01-01', '2021-01-01')); insert into temporal_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[8,9)', - daterange('2018-01-01', '2021-01-01'), - '[12,13)' - ); +values ('[8,9)', daterange('2018-01-01', '2021-01-01'), '[12,13)'); drop table temporal_mltrng; @@ -2335,56 +1410,24 @@ delete from temporal_fk_mltrng2mltrng; insert into temporal_mltrng (id, valid_at) values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-03') - ) - ), - ( - '[1,2)', - datemultirange( - daterange('2018-03-03', '2018-04-04') - ) - ), - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-01-05') - ) - ), - ( - '[3,4)', - datemultirange( - daterange('2018-01-01', null) - ) - ); + ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-03'))), + ('[1,2)', datemultirange(daterange('2018-03-03', '2018-04-04'))), + ('[2,3)', datemultirange(daterange('2018-01-01', '2018-01-05'))), + ('[3,4)', datemultirange(daterange('2018-01-01', null))); alter table temporal_fk_mltrng2mltrng drop constraint temporal_fk_mltrng2mltrng_fk; insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-01') - ), - '[1,2)' - ); + ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-01')), '[1,2)'); alter table temporal_fk_mltrng2mltrng drop constraint temporal_fk_mltrng2mltrng_fk; insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[2,3)', - datemultirange( - daterange('2018-01-02', '2018-04-01') - ), - '[1,2)' - ); + ('[2,3)', datemultirange(daterange('2018-01-02', '2018-04-01')), '[1,2)'); delete from temporal_fk_mltrng2mltrng; @@ -2397,54 +1440,26 @@ where insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[1,2)', - datemultirange( - daterange('2018-01-02', '2018-02-01') - ), - '[1,2)' - ); + ('[1,2)', datemultirange(daterange('2018-01-02', '2018-02-01')), '[1,2)'); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[2,3)', - datemultirange( - daterange('2018-01-02', '2018-04-01') - ), - '[1,2)' - ); + ('[2,3)', datemultirange(daterange('2018-01-02', '2018-04-01')), '[1,2)'); insert into temporal_mltrng (id, valid_at) -values - ( - '[1,2)', - datemultirange( - daterange('2018-02-03', '2018-03-03') - ) - ); +values ('[1,2)', datemultirange(daterange('2018-02-03', '2018-03-03'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[2,3)', - datemultirange( - daterange('2018-01-02', '2018-04-01') - ), - '[1,2)' - ); + ('[2,3)', datemultirange(daterange('2018-01-02', '2018-04-01')), '[1,2)'); update temporal_fk_mltrng2mltrng -set valid_at = datemultirange( - daterange('2018-01-02', '2018-02-20') -) +set valid_at = datemultirange(daterange('2018-01-02', '2018-02-20')) where id = '[1,2)'; update temporal_fk_mltrng2mltrng -set valid_at = datemultirange( - daterange('2018-01-02', '2018-05-01') -) +set valid_at = datemultirange(daterange('2018-01-02', '2018-05-01')) where id = '[1,2)'; @@ -2454,31 +1469,15 @@ begin; insert into temporal_mltrng (id, valid_at) values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ), - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); + ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))), + ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); + ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); alter table temporal_fk_mltrng2mltrng - alter constraint "temporal_fk_mltrng2mltrng_fk" deferrable initially deferred; + alter constraint temporal_fk_mltrng2mltrng_fk deferrable initially deferred; delete from temporal_mltrng where id = '[5,6)'; @@ -2490,18 +1489,10 @@ alter table temporal_fk_mltrng2mltrng drop constraint temporal_fk_mltrng2mltrng_fk; insert into temporal_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))); update temporal_mltrng -set valid_at = datemultirange( - daterange('2016-01-01', '2016-02-01') -) +set valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) where id = '[5,6)'; @@ -2509,194 +1500,97 @@ delete from temporal_mltrng where id = '[5,6)'; insert into temporal_mltrng (id, valid_at) values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ), - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); + ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))), + ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); + ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); update temporal_mltrng -set valid_at = datemultirange( - daterange('2016-02-01', '2016-03-01') -) +set valid_at = datemultirange(daterange('2016-02-01', '2016-03-01')) where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-02-01', '2018-03-01') - ); + valid_at = datemultirange(daterange('2018-02-01', '2018-03-01')); insert into temporal_mltrng (id, valid_at) values - ( - '[6,7)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ), - ( - '[6,7)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); + ('[6,7)', datemultirange(daterange('2018-01-01', '2018-02-01'))), + ('[6,7)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[4,5)', - datemultirange( - daterange('2018-01-15', '2018-02-15') - ), - '[6,7)' - ); + ('[4,5)', datemultirange(daterange('2018-01-15', '2018-02-15')), '[6,7)'); update temporal_mltrng set valid_at = case when lower(valid_at) = '2018-01-01' - then datemultirange( - daterange('2018-01-01', '2018-01-05') - ) + then datemultirange(daterange('2018-01-01', '2018-01-05')) when lower(valid_at) = '2018-02-01' - then datemultirange( - daterange('2018-01-05', '2018-03-01') - ) + then datemultirange(daterange('2018-01-05', '2018-03-01')) end where id = '[6,7)'; insert into temporal_mltrng (id, valid_at) values - ( - '[1,2)', - datemultirange( - daterange('2018-01-01', '2018-03-01') - ) - ), - ( - '[1,2)', - datemultirange( - daterange('2018-03-01', '2018-06-01') - ) - ); + ('[1,2)', datemultirange(daterange('2018-01-01', '2018-03-01'))), + ('[1,2)', datemultirange(daterange('2018-03-01', '2018-06-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[1,2)', - datemultirange( - daterange('2018-01-15', '2018-02-01') - ), - '[1,2)' - ), - ( - '[2,3)', - datemultirange( - daterange('2018-01-15', '2018-05-01') - ), - '[1,2)' - ); + ('[1,2)', datemultirange(daterange('2018-01-15', '2018-02-01')), '[1,2)'), + ('[2,3)', datemultirange(daterange('2018-01-15', '2018-05-01')), '[1,2)'); update temporal_mltrng -set valid_at = datemultirange( - daterange('2018-01-15', '2018-03-01') -) +set valid_at = datemultirange(daterange('2018-01-15', '2018-03-01')) where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng -set valid_at = datemultirange( - daterange('2018-01-01', '2018-03-01') -) +set valid_at = datemultirange(daterange('2018-01-01', '2018-03-01')) where - id = '[1,2)' and - valid_at @> cast('2018-01-25' as date); + id = '[1,2)' and valid_at @> cast('2018-01-25' as date); update temporal_mltrng set id = '[2,3)', -valid_at = datemultirange( - daterange('2018-01-15', '2018-03-01') -) +valid_at = datemultirange(daterange('2018-01-15', '2018-03-01')) where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); update temporal_mltrng set id = '[2,3)' where - id = '[1,2)' and - valid_at @> cast('2018-01-15' as date); + id = '[1,2)' and valid_at @> cast('2018-01-15' as date); insert into temporal_mltrng (id, valid_at) -values - ( - '[2,3)', - datemultirange( - daterange('2018-01-01', '2018-03-01') - ) - ); +values ('[2,3)', datemultirange(daterange('2018-01-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[5,6)', - datemultirange( - daterange('2018-01-15', '2018-02-01') - ), - '[2,3)' - ); + ('[5,6)', datemultirange(daterange('2018-01-15', '2018-02-01')), '[2,3)'); update temporal_mltrng -set valid_at = datemultirange( - daterange('2018-01-15', '2018-02-15') -) +set valid_at = datemultirange(daterange('2018-01-15', '2018-02-15')) where id = '[2,3)'; update temporal_mltrng -set valid_at = datemultirange( - daterange('2016-01-01', '2016-02-01') -) +set valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); begin; alter table temporal_fk_mltrng2mltrng - alter constraint "temporal_fk_mltrng2mltrng_fk" deferrable initially deferred; + alter constraint temporal_fk_mltrng2mltrng_fk deferrable initially deferred; update temporal_mltrng -set valid_at = datemultirange( - daterange('2016-01-01', '2016-02-01') -) +set valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); commit; @@ -2704,10 +1598,7 @@ update temporal_mltrng set id = '[7,8)' where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); truncate temporal_mltrng, temporal_fk_mltrng2mltrng; @@ -2717,159 +1608,74 @@ alter table temporal_fk_mltrng2mltrng truncate temporal_mltrng, temporal_fk_mltrng2mltrng; insert into temporal_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))); delete from temporal_mltrng where id = '[5,6)'; insert into temporal_mltrng (id, valid_at) values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ), - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); + ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))), + ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); + ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); delete from temporal_mltrng where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-02-01', '2018-03-01') - ); + valid_at = datemultirange(daterange('2018-02-01', '2018-03-01')); delete from temporal_mltrng where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); begin; alter table temporal_fk_mltrng2mltrng - alter constraint "temporal_fk_mltrng2mltrng_fk" deferrable initially deferred; + alter constraint temporal_fk_mltrng2mltrng_fk deferrable initially deferred; delete from temporal_mltrng where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); commit; create table tp1 partition of temporal_partitioned_rng -for values in ('[1,2)', -'[3,4)', -'[5,6)', -'[7,8)', -'[9,10)', -'[11,12)'); +for values in ('[1,2)', '[3,4)', '[5,6)', '[7,8)', '[9,10)', '[11,12)'); create table tp2 partition of temporal_partitioned_rng -for values in ('[2,3)', -'[4,5)', -'[6,7)', -'[8,9)', -'[10,11)', -'[12,13)'); +for values in ('[2,3)', '[4,5)', '[6,7)', '[8,9)', '[10,11)', '[12,13)'); insert into temporal_partitioned_rng (id, valid_at, name) values - ( - '[1,2)', - daterange('2000-01-01', '2000-02-01'), - 'one' - ), - ( - '[1,2)', - daterange('2000-02-01', '2000-03-01'), - 'one' - ), - ( - '[2,3)', - daterange('2000-01-01', '2010-01-01'), - 'two' - ); + ('[1,2)', daterange('2000-01-01', '2000-02-01'), 'one'), + ('[1,2)', daterange('2000-02-01', '2000-03-01'), 'one'), + ('[2,3)', daterange('2000-01-01', '2010-01-01'), 'two'); create table tfkp1 partition of temporal_partitioned_fk_rng2rng -for values in ('[1,2)', -'[3,4)', -'[5,6)', -'[7,8)', -'[9,10)', -'[11,12)'); +for values in ('[1,2)', '[3,4)', '[5,6)', '[7,8)', '[9,10)', '[11,12)'); create table tfkp2 partition of temporal_partitioned_fk_rng2rng -for values in ('[2,3)', -'[4,5)', -'[6,7)', -'[8,9)', -'[10,11)', -'[12,13)'); +for values in ('[2,3)', '[4,5)', '[6,7)', '[8,9)', '[10,11)', '[12,13)'); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) values - ( - '[1,2)', - daterange('2000-01-01', '2000-02-15'), - '[1,2)' - ), - ( - '[1,2)', - daterange('2001-01-01', '2002-01-01'), - '[2,3)' - ), - ( - '[2,3)', - daterange('2000-01-01', '2000-02-15'), - '[1,2)' - ); + ('[1,2)', daterange('2000-01-01', '2000-02-15'), '[1,2)'), + ('[1,2)', daterange('2001-01-01', '2002-01-01'), '[2,3)'), + ('[2,3)', daterange('2000-01-01', '2000-02-15'), '[1,2)'); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2010-01-01', '2010-02-15'), - '[1,2)' - ); +values ('[3,4)', daterange('2010-01-01', '2010-02-15'), '[1,2)'); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2000-01-01', '2000-02-15'), - '[3,4)' - ); +values ('[3,4)', daterange('2000-01-01', '2000-02-15'), '[3,4)'); update temporal_partitioned_fk_rng2rng set valid_at = daterange('2000-01-01', '2000-02-13') @@ -2888,11 +1694,7 @@ where truncate temporal_partitioned_rng, temporal_partitioned_fk_rng2rng; insert into temporal_partitioned_rng (id, valid_at) -values - ( - '[5,6)', - daterange('2016-01-01', '2016-02-01') - ); +values ('[5,6)', daterange('2016-01-01', '2016-02-01')); update temporal_partitioned_rng set valid_at = daterange('2018-01-01', '2018-02-01') @@ -2900,69 +1702,39 @@ where id = '[5,6)'; insert into temporal_partitioned_rng (id, valid_at) -values - ( - '[5,6)', - daterange('2018-02-01', '2018-03-01') - ); +values ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); update temporal_partitioned_rng set valid_at = daterange('2016-02-01', '2016-03-01') where - id = '[5,6)' and - valid_at = - daterange('2018-02-01', '2018-03-01'); + id = '[5,6)' and valid_at = daterange('2018-02-01', '2018-03-01'); update temporal_partitioned_rng set valid_at = daterange('2016-01-01', '2016-02-01') where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); truncate temporal_partitioned_rng, temporal_partitioned_fk_rng2rng; insert into temporal_partitioned_rng (id, valid_at) -values - ( - '[5,6)', - daterange('2018-01-01', '2018-02-01') - ); +values ('[5,6)', daterange('2018-01-01', '2018-02-01')); insert into temporal_partitioned_rng (id, valid_at) -values - ( - '[5,6)', - daterange('2018-02-01', '2018-03-01') - ); +values ('[5,6)', daterange('2018-02-01', '2018-03-01')); insert into temporal_partitioned_fk_rng2rng (id, valid_at, parent_id) -values - ( - '[3,4)', - daterange('2018-01-05', '2018-01-10'), - '[5,6)' - ); +values ('[3,4)', daterange('2018-01-05', '2018-01-10'), '[5,6)'); delete from temporal_partitioned_rng where - id = '[5,6)' and - valid_at = - daterange('2018-02-01', '2018-03-01'); + id = '[5,6)' and valid_at = daterange('2018-02-01', '2018-03-01'); delete from temporal_partitioned_rng where - id = '[5,6)' and - valid_at = - daterange('2018-01-01', '2018-02-01'); + id = '[5,6)' and valid_at = daterange('2018-01-01', '2018-02-01'); drop table temporal_partitioned_fk_rng2rng; @@ -2970,138 +1742,96 @@ drop table temporal_partitioned_rng; create table tp1 partition of temporal_partitioned_mltrng -for values in ('[1,2)', -'[3,4)', -'[5,6)', -'[7,8)', -'[9,10)', -'[11,12)', -'[13,14)', -'[15,16)', -'[17,18)', -'[19,20)', -'[21,22)', -'[23,24)'); +for values in ( + '[1,2)', + '[3,4)', + '[5,6)', + '[7,8)', + '[9,10)', + '[11,12)', + '[13,14)', + '[15,16)', + '[17,18)', + '[19,20)', + '[21,22)', + '[23,24)' +); create table tp2 partition of temporal_partitioned_mltrng -for values in ('[0,1)', -'[2,3)', -'[4,5)', -'[6,7)', -'[8,9)', -'[10,11)', -'[12,13)', -'[14,15)', -'[16,17)', -'[18,19)', -'[20,21)', -'[22,23)', -'[24,25)'); +for values in ( + '[0,1)', + '[2,3)', + '[4,5)', + '[6,7)', + '[8,9)', + '[10,11)', + '[12,13)', + '[14,15)', + '[16,17)', + '[18,19)', + '[20,21)', + '[22,23)', + '[24,25)' +); insert into temporal_partitioned_mltrng (id, valid_at, name) values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2000-02-01') - ), - 'one' - ), - ( - '[1,2)', - datemultirange( - daterange('2000-02-01', '2000-03-01') - ), - 'one' - ), - ( - '[2,3)', - datemultirange( - daterange('2000-01-01', '2010-01-01') - ), - 'two' - ); + ('[1,2)', datemultirange(daterange('2000-01-01', '2000-02-01')), 'one'), + ('[1,2)', datemultirange(daterange('2000-02-01', '2000-03-01')), 'one'), + ('[2,3)', datemultirange(daterange('2000-01-01', '2010-01-01')), 'two'); create table tfkp1 partition of temporal_partitioned_fk_mltrng2mltrng -for values in ('[1,2)', -'[3,4)', -'[5,6)', -'[7,8)', -'[9,10)', -'[11,12)', -'[13,14)', -'[15,16)', -'[17,18)', -'[19,20)', -'[21,22)', -'[23,24)'); +for values in ( + '[1,2)', + '[3,4)', + '[5,6)', + '[7,8)', + '[9,10)', + '[11,12)', + '[13,14)', + '[15,16)', + '[17,18)', + '[19,20)', + '[21,22)', + '[23,24)' +); create table tfkp2 partition of temporal_partitioned_fk_mltrng2mltrng -for values in ('[0,1)', -'[2,3)', -'[4,5)', -'[6,7)', -'[8,9)', -'[10,11)', -'[12,13)', -'[14,15)', -'[16,17)', -'[18,19)', -'[20,21)', -'[22,23)', -'[24,25)'); +for values in ( + '[0,1)', + '[2,3)', + '[4,5)', + '[6,7)', + '[8,9)', + '[10,11)', + '[12,13)', + '[14,15)', + '[16,17)', + '[18,19)', + '[20,21)', + '[22,23)', + '[24,25)' +); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[1,2)', - datemultirange( - daterange('2000-01-01', '2000-02-15') - ), - '[1,2)' - ), - ( - '[1,2)', - datemultirange( - daterange('2001-01-01', '2002-01-01') - ), - '[2,3)' - ), - ( - '[2,3)', - datemultirange( - daterange('2000-01-01', '2000-02-15') - ), - '[1,2)' - ); + ('[1,2)', datemultirange(daterange('2000-01-01', '2000-02-15')), '[1,2)'), + ('[1,2)', datemultirange(daterange('2001-01-01', '2002-01-01')), '[2,3)'), + ('[2,3)', datemultirange(daterange('2000-01-01', '2000-02-15')), '[1,2)'); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[3,4)', - datemultirange( - daterange('2010-01-01', '2010-02-15') - ), - '[1,2)' - ); + ('[3,4)', datemultirange(daterange('2010-01-01', '2010-02-15')), '[1,2)'); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[3,4)', - datemultirange( - daterange('2000-01-01', '2000-02-15') - ), - '[3,4)' - ); + ('[3,4)', datemultirange(daterange('2000-01-01', '2000-02-15')), '[3,4)'); update temporal_partitioned_fk_mltrng2mltrng -set valid_at = datemultirange( - daterange('2000-01-01', '2000-02-13') -) +set valid_at = datemultirange(daterange('2000-01-01', '2000-02-13')) where id = '[2,3)'; @@ -3116,116 +1846,60 @@ where id = '[4,5)'; update temporal_partitioned_fk_mltrng2mltrng -set valid_at = datemultirange( - daterange('2000-01-01', '2000-04-01') -) +set valid_at = datemultirange(daterange('2000-01-01', '2000-04-01')) where id = '[1,2)'; truncate temporal_partitioned_mltrng, temporal_partitioned_fk_mltrng2mltrng; insert into temporal_partitioned_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2016-01-01', '2016-02-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2016-01-01', '2016-02-01'))); update temporal_partitioned_mltrng -set valid_at = datemultirange( - daterange('2018-01-01', '2018-02-01') -) +set valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')) where id = '[5,6)'; insert into temporal_partitioned_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); + ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); update temporal_partitioned_mltrng -set valid_at = datemultirange( - daterange('2016-02-01', '2016-03-01') -) +set valid_at = datemultirange(daterange('2016-02-01', '2016-03-01')) where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-02-01', '2018-03-01') - ); + valid_at = datemultirange(daterange('2018-02-01', '2018-03-01')); update temporal_partitioned_mltrng -set valid_at = datemultirange( - daterange('2016-01-01', '2016-02-01') -) +set valid_at = datemultirange(daterange('2016-01-01', '2016-02-01')) where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); truncate temporal_partitioned_mltrng, temporal_partitioned_fk_mltrng2mltrng; insert into temporal_partitioned_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-01-01', '2018-02-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-01-01', '2018-02-01'))); insert into temporal_partitioned_mltrng (id, valid_at) -values - ( - '[5,6)', - datemultirange( - daterange('2018-02-01', '2018-03-01') - ) - ); +values ('[5,6)', datemultirange(daterange('2018-02-01', '2018-03-01'))); insert into temporal_partitioned_fk_mltrng2mltrng (id, valid_at, parent_id) values - ( - '[3,4)', - datemultirange( - daterange('2018-01-05', '2018-01-10') - ), - '[5,6)' - ); + ('[3,4)', datemultirange(daterange('2018-01-05', '2018-01-10')), '[5,6)'); delete from temporal_partitioned_mltrng where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-02-01', '2018-03-01') - ); + valid_at = datemultirange(daterange('2018-02-01', '2018-03-01')); delete from temporal_partitioned_mltrng where id = '[5,6)' and - valid_at = - datemultirange( - daterange('2018-01-01', '2018-02-01') - ); + valid_at = datemultirange(daterange('2018-01-01', '2018-02-01')); drop table temporal_partitioned_fk_mltrng2mltrng; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__write_parallel_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__write_parallel_100.snap index c0bec89fe..68f5db1f1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__write_parallel_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__write_parallel_100.snap @@ -27,19 +27,11 @@ drop table parallel_write; create materialized view parallel_mat_view as - select - length(stringu1) - from - tenk1 - group by length(stringu1); + select length(stringu1) from tenk1 group by length(stringu1); create materialized view parallel_mat_view as - select - length(stringu1) - from - tenk1 - group by length(stringu1); + select length(stringu1) from tenk1 group by length(stringu1); create unique index on parallel_mat_view using btree (length); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__write_parallel_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__write_parallel_80.snap index 7f20f9dc8..56f956c54 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__write_parallel_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__write_parallel_80.snap @@ -15,19 +15,11 @@ set max_parallel_workers_per_gather = 4; create table parallel_write as - select - length(stringu1) - from - tenk1 - group by length(stringu1); + select length(stringu1) from tenk1 group by length(stringu1); create table parallel_write as - select - length(stringu1) - from - tenk1 - group by length(stringu1); + select length(stringu1) from tenk1 group by length(stringu1); drop table parallel_write; @@ -49,19 +41,11 @@ drop table parallel_write; create materialized view parallel_mat_view as - select - length(stringu1) - from - tenk1 - group by length(stringu1); + select length(stringu1) from tenk1 group by length(stringu1); create materialized view parallel_mat_view as - select - length(stringu1) - from - tenk1 - group by length(stringu1); + select length(stringu1) from tenk1 group by length(stringu1); create unique index on parallel_mat_view using btree (length); @@ -72,11 +56,7 @@ refresh materialized view concurrently parallel_mat_view; drop materialized view parallel_mat_view; prepare prep_stmt -as select - length(stringu1) -from - tenk1 -group by length(stringu1);; +as select length(stringu1) from tenk1 group by length(stringu1);; create table parallel_write as execute prep_stmt; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xid_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xid_100.snap index 7877647a7..144abc08a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xid_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xid_100.snap @@ -79,7 +79,7 @@ create table xid8_t1 (x xid8); insert into xid8_t1 values ('0'), ('010'), ('42'), ('0xffffffffffffffff'), ('-1'); -select MIN(x), MAX(x) from xid8_t1; +select min(x), max(x) from xid8_t1; create index on xid8_t1 using btree (x); @@ -141,10 +141,7 @@ order by nr; select id, - pg_visible_in_snapshot( - cast(cast(id as text) as xid8), - snap - ) + pg_visible_in_snapshot(cast(cast(id as text) as xid8), snap) from snapshot_test, generate_series(11, 21) as id @@ -153,10 +150,7 @@ where select id, - pg_visible_in_snapshot( - cast(cast(id as text) as xid8), - snap - ) + pg_visible_in_snapshot(cast(cast(id as text) as xid8), snap) from snapshot_test, generate_series(90, 160) as id @@ -230,7 +224,7 @@ begin; create function test_future_xid_status(xid8) returns void language plpgsql -as $function$ +as $$ BEGIN PERFORM pg_xact_status($1); RAISE EXCEPTION 'didn''t ERROR at xid in the future as expected'; @@ -238,7 +232,7 @@ EXCEPTION WHEN invalid_parameter_value THEN RAISE NOTICE 'Got expected error for xid in the future'; END; -$function$; +$$; select test_future_xid_status(cast(cast('inprogress' + 10000 as text) as xid8)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xid_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xid_80.snap index ccf61126f..8b7ae5cca 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xid_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xid_80.snap @@ -78,14 +78,9 @@ select xid8cmp('1', '2'), xid8cmp('2', '2'), xid8cmp('2', '1'); create table xid8_t1 (x xid8); insert into xid8_t1 -values - ('0'), - ('010'), - ('42'), - ('0xffffffffffffffff'), - ('-1'); +values ('0'), ('010'), ('42'), ('0xffffffffffffffff'), ('-1'); -select MIN(x), MAX(x) from xid8_t1; +select min(x), max(x) from xid8_t1; create index on xid8_t1 using btree (x); @@ -147,10 +142,7 @@ order by nr; select id, - pg_visible_in_snapshot( - cast(cast(id as text) as xid8), - snap - ) + pg_visible_in_snapshot(cast(cast(id as text) as xid8), snap) from snapshot_test, generate_series(11, 21) as id @@ -159,10 +151,7 @@ where select id, - pg_visible_in_snapshot( - cast(cast(id as text) as xid8), - snap - ) + pg_visible_in_snapshot(cast(cast(id as text) as xid8), snap) from snapshot_test, generate_series(90, 160) as id @@ -240,7 +229,7 @@ begin; create function test_future_xid_status(xid8) returns void language plpgsql -as $function$ +as $$ BEGIN PERFORM pg_xact_status($1); RAISE EXCEPTION 'didn''t ERROR at xid in the future as expected'; @@ -248,7 +237,7 @@ EXCEPTION WHEN invalid_parameter_value THEN RAISE NOTICE 'Got expected error for xid in the future'; END; -$function$; +$$; select test_future_xid_status(cast(cast('inprogress' + 10000 as text) as xid8)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xml_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xml_100.snap index 4842db081..fcb80e8ae 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xml_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xml_100.snap @@ -47,9 +47,7 @@ select xmlconcat('bad', '', null, ''); select - xmlconcat('', - null, - ''); + xmlconcat('', null, ''); select xmlconcat(null); @@ -169,76 +167,78 @@ select select xmlroot('', version no value); select - xmlroot(xmlelement(name gazonk, xmlattributes('val' as name, - 1 + 1 as num), xmlelement(name qux, 'foo')), version '1.0', standalone yes); + xmlroot(xmlelement(name gazonk, xmlattributes( + 'val' as name, + 1 + 1 as num + ), xmlelement(name qux, 'foo')), version '1.0', standalone yes); -select XMLSERIALIZE(CONTENT data as varchar(20)) from xmltest; +select xmlserialize(content data as varchar(20)) from xmltest; -select XMLSERIALIZE(CONTENT 'good' as char(10)); +select xmlserialize(content 'good' as char(10)); -select XMLSERIALIZE(DOCUMENT 'bad' as text); +select xmlserialize(document 'bad' as text); -select XMLSERIALIZE(DOCUMENT '42' as text INDENT); +select xmlserialize(document '42' as text indent); -select XMLSERIALIZE(CONTENT '42' as text INDENT); +select xmlserialize(content '42' as text indent); -select XMLSERIALIZE(DOCUMENT '42' as text); +select xmlserialize(document '42' as text); -select XMLSERIALIZE(CONTENT '42' as text); +select xmlserialize(content '42' as text); -select XMLSERIALIZE(DOCUMENT '7342' as text INDENT); +select xmlserialize(document '7342' as text indent); -select XMLSERIALIZE(CONTENT '7342' as text INDENT); +select xmlserialize(content '7342' as text indent); select - XMLSERIALIZE(DOCUMENT 'text node73text node42' as text INDENT); + xmlserialize(document 'text node73text node42' as text indent); select - XMLSERIALIZE(CONTENT 'text node73text node42' as text INDENT); + xmlserialize(content 'text node73text node42' as text indent); select - XMLSERIALIZE(DOCUMENT '42text node73' as text INDENT); + xmlserialize(document '42text node73' as text indent); select - XMLSERIALIZE(CONTENT '42text node73' as text INDENT); + xmlserialize(content '42text node73' as text indent); -select XMLSERIALIZE(DOCUMENT '' as text INDENT); +select xmlserialize(document '' as text indent); -select XMLSERIALIZE(CONTENT '' as text INDENT); +select xmlserialize(content '' as text indent); -select XMLSERIALIZE(DOCUMENT ' ' as text INDENT); +select xmlserialize(document ' ' as text indent); -select XMLSERIALIZE(CONTENT ' ' as text INDENT); +select xmlserialize(content ' ' as text indent); -select XMLSERIALIZE(DOCUMENT null as text INDENT); +select xmlserialize(document null as text indent); -select XMLSERIALIZE(CONTENT null as text INDENT); +select xmlserialize(content null as text indent); select - XMLSERIALIZE(DOCUMENT '73' as text INDENT); + xmlserialize(document '73' as text indent); select - XMLSERIALIZE(CONTENT '73' as text INDENT); + xmlserialize(content '73' as text indent); -select XMLSERIALIZE(DOCUMENT '' as text INDENT); +select xmlserialize(document '' as text indent); -select XMLSERIALIZE(CONTENT '' as text INDENT); +select xmlserialize(content '' as text indent); -select XMLSERIALIZE(DOCUMENT '' as text INDENT); +select xmlserialize(document '' as text indent); -select XMLSERIALIZE(CONTENT '' as text INDENT); +select xmlserialize(content '' as text indent); select - XMLSERIALIZE(DOCUMENT '42' as text) = - XMLSERIALIZE(DOCUMENT '42' as text); + xmlserialize(document '42' as text) = + xmlserialize(document '42' as text); select - XMLSERIALIZE(CONTENT '42' as text) = - XMLSERIALIZE(CONTENT '42' as text); + xmlserialize(content '42' as text) = + xmlserialize(content '42' as text); -select XMLSERIALIZE(DOCUMENT ' ' as text INDENT); +select xmlserialize(document ' ' as text indent); -select XMLSERIALIZE(CONTENT 'text node ' as text INDENT); +select xmlserialize(content 'text node ' as text indent); select cast('bar' as xml) is document; @@ -262,7 +262,7 @@ select xmlpi(name "123"); prepare foo (xml) as select xmlconcat('', $1);; -set xmloption = DOCUMENT; +set xmloption = 'DOCUMENT'; execute foo (''); @@ -270,7 +270,7 @@ execute foo ('bad'); select cast('' as xml); -set xmloption = CONTENT; +set xmloption = 'CONTENT'; execute foo (''); @@ -295,15 +295,10 @@ create view xmlview2 as select xmlconcat('hello', 'you'); create view xmlview3 -as select - xmlelement(name element, xmlattributes(1 as ":one:", - 'deuce' as two), 'content&'); +as select xmlelement(name element, xmlattributes(1 as ":one:", 'deuce' as two), 'content&'); create view xmlview4 -as select - xmlelement(name employee, xmlforest(name, age, salary as pay)) -from - emp; +as select xmlelement(name employee, xmlforest(name, age, salary as pay)) from emp; create view xmlview5 as select xmlparse(content 'x'); @@ -312,22 +307,19 @@ create view xmlview6 as select xmlpi(name foo, 'bar'); create view xmlview7 -as select - xmlroot(cast('' as xml), version no value, standalone yes); +as select xmlroot(cast('' as xml), version no value, standalone yes); create view xmlview8 -as select XMLSERIALIZE(CONTENT 'good' as char(10)); +as select xmlserialize(content 'good' as char(10)); create view xmlview9 -as select XMLSERIALIZE(CONTENT 'good' as text); +as select xmlserialize(content 'good' as text); create view xmlview10 -as select - XMLSERIALIZE(DOCUMENT '42' as text INDENT); +as select xmlserialize(document '42' as text indent); create view xmlview11 -as select - XMLSERIALIZE(DOCUMENT '42' as varchar); +as select xmlserialize(document '42' as varchar); select table_name, @@ -391,8 +383,7 @@ select xpath('/nosuchtag', ''); select xpath('root', ''); -do -$do$ +do $$ DECLARE xml_declaration text := ''; degree_symbol text; @@ -425,7 +416,7 @@ EXCEPTION OR feature_not_supported THEN RAISE LOG 'skip: %', SQLERRM; END -$do$; +$$; select xmlexists('//town[text() = ''Toronto'']' passing 'Bidford-on-AvonCwmbranBristol'); @@ -483,44 +474,36 @@ values as xml) ); -select COUNT(id) from xmltest where xmlexists('/menu/beer' passing data); +select count(id) from xmltest where xmlexists('/menu/beer' passing data); -select COUNT(id) from xmltest where xmlexists('/menu/beer' passing data); +select count(id) from xmltest where xmlexists('/menu/beer' passing data); -select COUNT(id) from xmltest where xmlexists('/menu/beers' passing data); +select count(id) from xmltest where xmlexists('/menu/beers' passing data); -select COUNT(id) from xmltest where xmlexists('/menu/beers/name[text() = ''Molson'']' passing data); +select count(id) from xmltest where xmlexists('/menu/beers/name[text() = ''Molson'']' passing data); -select COUNT(id) from xmltest where xpath_exists('/menu/beer', data); +select count(id) from xmltest where xpath_exists('/menu/beer', data); -select COUNT(id) from xmltest where xpath_exists('/menu/beers', data); +select count(id) from xmltest where xpath_exists('/menu/beers', data); -select COUNT(id) from xmltest where xpath_exists('/menu/beers/name[text() = ''Molson'']', data); +select count(id) from xmltest where xpath_exists('/menu/beers/name[text() = ''Molson'']', data); select - COUNT(id) + count(id) from xmltest where - xpath_exists( - '/myns:menu/myns:beer', - data, - array[array['myns', 'http://myns.com']] - ); + xpath_exists('/myns:menu/myns:beer', data, array[array['myns', 'http://myns.com']]); select - COUNT(id) + count(id) from xmltest where - xpath_exists( - '/myns:menu/myns:beers', - data, - array[array['myns', 'http://myns.com']] - ); + xpath_exists('/myns:menu/myns:beers', data, array[array['myns', 'http://myns.com']]); select - COUNT(id) + count(id) from xmltest where @@ -534,7 +517,7 @@ create table query (expr text); insert into query values ('/menu/beers/cost[text() = ''lots'']'); -select COUNT(id) from xmltest, query where xmlexists(expr passing data); +select count(id) from xmltest, query where xmlexists(expr passing data); select xml_is_well_formed_document('bar'); @@ -596,10 +579,7 @@ select create table xmldata (data xml); -insert into xmldata -values - ( - ' +insert into xmldata values (' AU Australia @@ -630,8 +610,7 @@ values Singapore 3791 -' - ); +'); select xmltable.* @@ -959,10 +938,7 @@ from where "COUNTRY_NAME" = 'Japan'; -insert into xmldata -values - ( - ' +insert into xmldata values (' CZ Czech Republic @@ -978,13 +954,9 @@ values France 2 -' - ); +'); -insert into xmldata -values - ( - ' +insert into xmldata values (' EG Egypt @@ -995,8 +967,7 @@ values Sudan 1 -' - ); +'); select xmltable.* @@ -1087,10 +1058,7 @@ as ( cast(procost as numeric), pronargs, array_to_string(proargnames, ',') as proargnames, - case - when proargtypes <> '' - then array_to_string(cast(proargtypes as oid[]), ',') - end + case when proargtypes <> '' then array_to_string(cast(proargtypes as oid[]), ',') end as proargtypes from pg_proc @@ -1100,12 +1068,7 @@ as ( y as ( select - xmlelement(name proc, xmlforest(proname, - proowner, - procost, - pronargs, - proargnames, - proargtypes)) + xmlelement(name proc, xmlforest(proname, proowner, procost, pronargs, proargnames, proargtypes)) as proc from x @@ -1142,10 +1105,7 @@ as ( cast(procost as numeric), pronargs, array_to_string(proargnames, ',') as proargnames, - case - when proargtypes <> '' - then array_to_string(cast(proargtypes as oid[]), ',') - end + case when proargtypes <> '' then array_to_string(cast(proargtypes as oid[]), ',') end as proargtypes from pg_proc @@ -1154,12 +1114,14 @@ y as ( select xmlelement(name data, xmlagg( - xmlelement(name proc, xmlforest(proname, - proowner, - procost, - pronargs, - proargnames, - proargtypes)) + xmlelement(name proc, xmlforest( + proname, + proowner, + procost, + pronargs, + proargnames, + proargtypes + )) )) as doc from @@ -1205,25 +1167,13 @@ select xmltable.* from xmltest2, - lateral xmltable( - - '/d/r' - passing x - columns - a int path '' || lower(_path) || 'c' - ); + lateral xmltable( '/d/r' passing x columns a int path '' || lower(_path) || 'c'); select xmltable.* from xmltest2, - lateral xmltable( - - ('/d/r/' || lower(_path) || 'c') - passing x - columns - a int path '.' - ); + lateral xmltable( ('/d/r/' || lower(_path) || 'c') passing x columns a int path '.'); select xmltable.* diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xml_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xml_80.snap index ddfe8dea4..374d36fb3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xml_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xml_80.snap @@ -27,10 +27,7 @@ select pg_input_is_valid('', 'xml'); select message from - pg_input_error_info( - '', - 'xml' - ); + pg_input_error_info('', 'xml'); select xmlcomment('test'); @@ -43,9 +40,11 @@ select xmlcomment('--test'); select xmlcomment('te st'); select - xmlconcat(xmlcomment('hello'), - xmlelement(name qux, 'foo'), - xmlcomment('world')); + xmlconcat( + xmlcomment('hello'), + xmlelement(name qux, 'foo'), + xmlcomment('world') + ); select xmlconcat('hello', 'you'); @@ -56,17 +55,18 @@ select xmlconcat('bad', '', null, ''); select - xmlconcat('', - null, - ''); + xmlconcat( + '', + null, + '' + ); select xmlconcat(null); select xmlconcat(null, null); select - xmlelement(name element, xmlattributes(1 as one, - 'deuce' as two), 'content'); + xmlelement(name element, xmlattributes(1 as one, 'deuce' as two), 'content'); select xmlelement(name element, xmlattributes('unnamed and wrong')); @@ -99,15 +99,18 @@ select xmlelement(name foo, cast('bar' as bytea)); select xmlelement(name foo, xmlattributes(true as bar)); select - xmlelement(name foo, xmlattributes(cast('2009-04-09 00:24:37' as timestamp) - as bar)); + xmlelement(name foo, xmlattributes( + cast('2009-04-09 00:24:37' as timestamp) as bar + )); select xmlelement(name foo, xmlattributes(cast('infinity' as timestamp) as bar)); select - xmlelement(name foo, xmlattributes('<>&"''' as funny, - cast('br' as xml) as funnier)); + xmlelement(name foo, xmlattributes( + '<>&"''' as funny, + cast('br' as xml) as funnier + )); select xmlparse(content ''); @@ -178,7 +181,8 @@ select as xml), version no value, standalone yes); select - xmlroot(xmlroot(cast('' as xml), version '1.0'), version '1.1', standalone no); + xmlroot(xmlroot(cast('' + as xml), version '1.0'), version '1.1', standalone no); select xmlroot('', version no value, standalone no); @@ -190,83 +194,85 @@ select xmlroot('', version no value); select - xmlroot(xmlelement(name gazonk, xmlattributes('val' as name, - 1 + 1 as num), xmlelement(name qux, 'foo')), version '1.0', standalone yes); + xmlroot(xmlelement(name gazonk, xmlattributes( + 'val' as name, + 1 + 1 as num + ), xmlelement(name qux, 'foo')), version '1.0', standalone yes); -select XMLSERIALIZE(CONTENT data as varchar(20)) from xmltest; +select xmlserialize(content data as varchar(20)) from xmltest; -select XMLSERIALIZE(CONTENT 'good' as char(10)); +select xmlserialize(content 'good' as char(10)); -select XMLSERIALIZE(DOCUMENT 'bad' as text); +select xmlserialize(document 'bad' as text); select - XMLSERIALIZE(DOCUMENT '42' as text INDENT); + xmlserialize(document '42' as text indent); select - XMLSERIALIZE(CONTENT '42' as text INDENT); + xmlserialize(content '42' as text indent); select - XMLSERIALIZE(DOCUMENT '42' as text); + xmlserialize(document '42' as text); select - XMLSERIALIZE(CONTENT '42' as text); + xmlserialize(content '42' as text); select - XMLSERIALIZE(DOCUMENT '7342' as text INDENT); + xmlserialize(document '7342' as text indent); select - XMLSERIALIZE(CONTENT '7342' as text INDENT); + xmlserialize(content '7342' as text indent); select - XMLSERIALIZE(DOCUMENT 'text node73text node42' as text INDENT); + xmlserialize(document 'text node73text node42' as text indent); select - XMLSERIALIZE(CONTENT 'text node73text node42' as text INDENT); + xmlserialize(content 'text node73text node42' as text indent); select - XMLSERIALIZE(DOCUMENT '42text node73' as text INDENT); + xmlserialize(document '42text node73' as text indent); select - XMLSERIALIZE(CONTENT '42text node73' as text INDENT); + xmlserialize(content '42text node73' as text indent); -select XMLSERIALIZE(DOCUMENT '' as text INDENT); +select xmlserialize(document '' as text indent); -select XMLSERIALIZE(CONTENT '' as text INDENT); +select xmlserialize(content '' as text indent); -select XMLSERIALIZE(DOCUMENT ' ' as text INDENT); +select xmlserialize(document ' ' as text indent); -select XMLSERIALIZE(CONTENT ' ' as text INDENT); +select xmlserialize(content ' ' as text indent); -select XMLSERIALIZE(DOCUMENT null as text INDENT); +select xmlserialize(document null as text indent); -select XMLSERIALIZE(CONTENT null as text INDENT); +select xmlserialize(content null as text indent); select - XMLSERIALIZE(DOCUMENT '73' as text INDENT); + xmlserialize(document '73' as text indent); select - XMLSERIALIZE(CONTENT '73' as text INDENT); + xmlserialize(content '73' as text indent); -select XMLSERIALIZE(DOCUMENT '' as text INDENT); +select xmlserialize(document '' as text indent); -select XMLSERIALIZE(CONTENT '' as text INDENT); +select xmlserialize(content '' as text indent); -select XMLSERIALIZE(DOCUMENT '' as text INDENT); +select xmlserialize(document '' as text indent); -select XMLSERIALIZE(CONTENT '' as text INDENT); +select xmlserialize(content '' as text indent); select - XMLSERIALIZE(DOCUMENT '42' as text) = - XMLSERIALIZE(DOCUMENT '42' as text); + xmlserialize(document '42' as text) = + xmlserialize(document '42' as text); select - XMLSERIALIZE(CONTENT '42' as text) = - XMLSERIALIZE(CONTENT '42' as text); + xmlserialize(content '42' as text) = + xmlserialize(content '42' as text); -select XMLSERIALIZE(DOCUMENT ' ' as text INDENT); +select xmlserialize(document ' ' as text indent); select - XMLSERIALIZE(CONTENT 'text node ' as text INDENT); + xmlserialize(content 'text node ' as text indent); select cast('bar' as xml) is document; @@ -290,7 +296,7 @@ select xmlpi(name "123"); prepare foo (xml) as select xmlconcat('', $1);; -set xmloption = DOCUMENT; +set xmloption = 'DOCUMENT'; execute foo (''); @@ -298,7 +304,7 @@ execute foo ('bad'); select cast('' as xml); -set xmloption = CONTENT; +set xmloption = 'CONTENT'; execute foo (''); @@ -326,8 +332,10 @@ as select xmlconcat('hello', 'you'); create view xmlview3 as select - xmlelement(name element, xmlattributes(1 as ":one:", - 'deuce' as two), 'content&'); + xmlelement(name element, xmlattributes( + 1 as ":one:", + 'deuce' as two + ), 'content&'); create view xmlview4 as select @@ -342,24 +350,19 @@ create view xmlview6 as select xmlpi(name foo, 'bar'); create view xmlview7 -as select - xmlroot(cast('' as xml), version no value, standalone yes); +as select xmlroot(cast('' as xml), version no value, standalone yes); create view xmlview8 -as select - XMLSERIALIZE(CONTENT 'good' as char(10)); +as select xmlserialize(content 'good' as char(10)); create view xmlview9 -as select - XMLSERIALIZE(CONTENT 'good' as text); +as select xmlserialize(content 'good' as text); create view xmlview10 -as select - XMLSERIALIZE(DOCUMENT '42' as text INDENT); +as select xmlserialize(document '42' as text indent); create view xmlview11 -as select - XMLSERIALIZE(DOCUMENT '42' as varchar); +as select xmlserialize(document '42' as varchar); select table_name, @@ -423,8 +426,7 @@ select xpath('/nosuchtag', ''); select xpath('root', ''); -do -$do$ +do $$ DECLARE xml_declaration text := ''; degree_symbol text; @@ -457,7 +459,7 @@ EXCEPTION OR feature_not_supported THEN RAISE LOG 'skip: %', SQLERRM; END -$do$; +$$; select xmlexists('//town[text() = ''Toronto'']' passing 'Bidford-on-AvonCwmbranBristol'); @@ -515,35 +517,32 @@ values as xml) ); -select COUNT(id) from xmltest where xmlexists('/menu/beer' passing data); +select count(id) from xmltest where xmlexists('/menu/beer' passing data); -select COUNT(id) from xmltest where xmlexists('/menu/beer' passing data); +select count(id) from xmltest where xmlexists('/menu/beer' passing data); -select COUNT(id) from xmltest where xmlexists('/menu/beers' passing data); +select count(id) from xmltest where xmlexists('/menu/beers' passing data); select - COUNT(id) + count(id) from xmltest where xmlexists('/menu/beers/name[text() = ''Molson'']' passing data); -select COUNT(id) from xmltest where xpath_exists('/menu/beer', data); +select count(id) from xmltest where xpath_exists('/menu/beer', data); -select COUNT(id) from xmltest where xpath_exists('/menu/beers', data); +select count(id) from xmltest where xpath_exists('/menu/beers', data); select - COUNT(id) + count(id) from xmltest where - xpath_exists( - '/menu/beers/name[text() = ''Molson'']', - data - ); + xpath_exists('/menu/beers/name[text() = ''Molson'']', data); select - COUNT(id) + count(id) from xmltest where @@ -554,7 +553,7 @@ where ); select - COUNT(id) + count(id) from xmltest where @@ -565,7 +564,7 @@ where ); select - COUNT(id) + count(id) from xmltest where @@ -579,7 +578,7 @@ create table query (expr text); insert into query values ('/menu/beers/cost[text() = ''lots'']'); -select COUNT(id) from xmltest, query where xmlexists(expr passing data); +select count(id) from xmltest, query where xmlexists(expr passing data); select xml_is_well_formed_document('bar'); @@ -649,10 +648,7 @@ select create table xmldata (data xml); -insert into xmldata -values - ( - ' +insert into xmldata values (' AU Australia @@ -683,8 +679,7 @@ values Singapore 3791 -' - ); +'); select xmltable.* @@ -775,13 +770,7 @@ from select * from - xmltable( - - '.' - passing '' - columns - a text path 'foo/namespace::node()' - ); + xmltable( '.' passing '' columns a text path 'foo/namespace::node()'); prepare pp as select @@ -1021,10 +1010,7 @@ from where "COUNTRY_NAME" = 'Japan'; -insert into xmldata -values - ( - ' +insert into xmldata values (' CZ Czech Republic @@ -1040,13 +1026,9 @@ values France 2 -' - ); +'); -insert into xmldata -values - ( - ' +insert into xmldata values (' EG Egypt @@ -1057,8 +1039,7 @@ values Sudan 1 -' - ); +'); select xmltable.* @@ -1148,14 +1129,10 @@ as ( proowner, cast(procost as numeric), pronargs, - array_to_string(proargnames, ',') - as proargnames, + array_to_string(proargnames, ',') as proargnames, case when proargtypes <> '' - then array_to_string( - cast(proargtypes as oid[]), - ',' - ) + then array_to_string(cast(proargtypes as oid[]), ',') end as proargtypes from @@ -1166,12 +1143,14 @@ as ( y as ( select - xmlelement(name proc, xmlforest(proname, - proowner, - procost, - pronargs, - proargnames, - proargtypes)) + xmlelement(name proc, xmlforest( + proname, + proowner, + procost, + pronargs, + proargnames, + proargtypes + )) as proc from x @@ -1207,14 +1186,10 @@ as ( proowner, cast(procost as numeric), pronargs, - array_to_string(proargnames, ',') - as proargnames, + array_to_string(proargnames, ',') as proargnames, case when proargtypes <> '' - then array_to_string( - cast(proargtypes as oid[]), - ',' - ) + then array_to_string(cast(proargtypes as oid[]), ',') end as proargtypes from @@ -1224,12 +1199,14 @@ y as ( select xmlelement(name data, xmlagg( - xmlelement(name proc, xmlforest(proname, - proowner, - procost, - pronargs, - proargnames, - proargtypes)) + xmlelement(name proc, xmlforest( + proname, + proowner, + procost, + pronargs, + proargnames, + proargtypes + )) )) as doc from @@ -1358,7 +1335,5 @@ select xmltext('foo & <"bar">'); select xmltext( - 'x' || cast('

73

' as xml) || .42 || - true || - cast('j' as char(1)) + 'x' || cast('

73

' as xml) || .42 || true || cast('j' as char(1)) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xmlmap_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xmlmap_100.snap index f71fd3837..ce23d2d41 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xmlmap_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xmlmap_100.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/xmlmap.sql snapshot_kind: text --- -create schema "testxmlschema"; +create schema testxmlschema; create table testxmlschema.test1 ( a int, @@ -23,13 +23,13 @@ create table testxmlschema.test2 ( u bigint, t real, s time, - stz time with time zone, + stz timetz, r timestamp, - rtz timestamp with time zone, + rtz timestamptz, q date, p xml, o testxmldomain, - n boolean, + n bool, m bytea, aaa text ); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xmlmap_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xmlmap_80.snap index 17d4e794a..fd521f057 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__xmlmap_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__xmlmap_80.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/xmlmap.sql snapshot_kind: text --- -create schema "testxmlschema"; +create schema testxmlschema; create table testxmlschema.test1 ( a int, @@ -23,13 +23,13 @@ create table testxmlschema.test2 ( u bigint, t real, s time, - stz time with time zone, + stz timetz, r timestamp, - rtz timestamp with time zone, + rtz timestamptz, q date, p xml, o testxmldomain, - n boolean, + n bool, m bytea, aaa text ); @@ -89,12 +89,7 @@ select table_to_xml_and_xmlschema('testxmlschema.test1', true, true, 'foo'); select query_to_xml('SELECT * FROM testxmlschema.test1', false, false, ''); select - query_to_xmlschema( - 'SELECT * FROM testxmlschema.test1', - false, - false, - '' - ); + query_to_xmlschema('SELECT * FROM testxmlschema.test1', false, false, ''); select query_to_xml_and_xmlschema( diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_0_100.snap index 234fad90e..e54c7a7ac 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_0_100.snap @@ -10,5 +10,4 @@ select from cte as t where - (r).column1 = (rr).column1 and - (select (c1).f1 > 0); + (r).column1 = (rr).column1 and (select (c1).f1 > 0); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_0_80.snap index 234fad90e..e54c7a7ac 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_0_80.snap @@ -10,5 +10,4 @@ select from cte as t where - (r).column1 = (rr).column1 and - (select (c1).f1 > 0); + (r).column1 = (rr).column1 and (select (c1).f1 > 0); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_2_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_2_100.snap index 9365c6521..be2b4cb98 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_2_100.snap @@ -2,11 +2,5 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/a_indirection_2.sql --- -explain (VERBOSE, COSTS 'off') -select - (r).column2 -from - ( - select r from (values (1, 2), (3, 4)) as r limit 1 - ) - as ss; +explain (verbose, costs 'off') +select (r).column2 from (select r from (values (1, 2), (3, 4)) as r limit 1) as ss; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_2_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_2_80.snap index f594b8bc0..a2d471189 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__a_indirection_2_80.snap @@ -2,15 +2,8 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/a_indirection_2.sql --- -explain (VERBOSE, COSTS 'off') +explain (verbose, costs 'off') select (r).column2 from - ( - select - r - from - (values (1, 2), (3, 4)) as r - limit 1 - ) - as ss; + (select r from (values (1, 2), (3, 4)) as r limit 1) as ss; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__aexpr_precedence_parentheses_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__aexpr_precedence_parentheses_0_100.snap index 7e2a48690..d33439b87 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__aexpr_precedence_parentheses_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__aexpr_precedence_parentheses_0_100.snap @@ -5,17 +5,12 @@ snapshot_kind: text --- select 100 * 3 + (vs.i - 1) * 3 as offset_a, - (metrics.total - metrics.used) / - (metrics.total + metrics.used) - as utilization, - cost + tax_rate * subtotal - - discount_rate * subtotal - as net_total + (metrics.total - metrics.used) / (metrics.total + metrics.used) as utilization, + cost + tax_rate * subtotal - discount_rate * subtotal as net_total from balances as vs, ledger as metrics, invoices where - (amount + fee) * (1 - discount) > - limit_value - buffer and + (amount + fee) * (1 - discount) > limit_value - buffer and (temperature - ambient) * factor > threshold; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__aexpr_precedence_parentheses_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__aexpr_precedence_parentheses_0_80.snap index 32a3d8f54..21265bd5c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__aexpr_precedence_parentheses_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__aexpr_precedence_parentheses_0_80.snap @@ -5,18 +5,13 @@ snapshot_kind: text --- select 100 * 3 + (vs.i - 1) * 3 as offset_a, - (metrics.total - metrics.used) / - (metrics.total + metrics.used) + (metrics.total - metrics.used) / (metrics.total + metrics.used) as utilization, - cost + tax_rate * subtotal - - discount_rate * subtotal - as net_total + cost + tax_rate * subtotal - discount_rate * subtotal as net_total from balances as vs, ledger as metrics, invoices where - (amount + fee) * (1 - discount) > - limit_value - buffer and - (temperature - ambient) * factor > - threshold; + (amount + fee) * (1 - discount) > limit_value - buffer and + (temperature - ambient) * factor > threshold; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__aggref_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__aggref_0_100.snap index 480f1cd1a..ba70ae470 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__aggref_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__aggref_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/aggref_0.sql snapshot_kind: text --- -select COUNT(*) from users; +select count(*) from users; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__aggref_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__aggref_0_80.snap index 480f1cd1a..ba70ae470 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__aggref_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__aggref_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/aggref_0.sql snapshot_kind: text --- -select COUNT(*) from users; +select count(*) from users; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_default_privileges_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_default_privileges_stmt_0_100.snap index f2c4be7c2..36e56c5ab 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_default_privileges_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_default_privileges_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_default_privileges_stmt_0.sql snapshot_kind: text --- -alter default privileges grant SELECT on tables to reader; +alter default privileges grant select on tables to reader; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_default_privileges_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_default_privileges_stmt_0_80.snap index f2c4be7c2..36e56c5ab 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_default_privileges_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_default_privileges_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_default_privileges_stmt_0.sql snapshot_kind: text --- -alter default privileges grant SELECT on tables to reader; +alter default privileges grant select on tables to reader; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_1_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_1_100.snap index d09615493..fd531b965 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_1_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_1_100.snap @@ -2,4 +2,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_function_stmt_1.sql --- -alter function add(int) called on null input parallel UNSAFE; +alter function add(int) called on null input parallel unsafe; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_1_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_1_80.snap index d09615493..fd531b965 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_1_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_1_80.snap @@ -2,4 +2,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_function_stmt_1.sql --- -alter function add(int) called on null input parallel UNSAFE; +alter function add(int) called on null input parallel unsafe; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_2_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_2_100.snap index bf9509cda..1b2981804 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_2_100.snap @@ -7,7 +7,7 @@ alter function my_schema.compute_totals(int, text) leakproof strict security definer - parallel SAFE + parallel safe cost 10 rows 5 set search_path to public, pg_temp diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_2_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_2_80.snap index bf9509cda..1b2981804 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_function_stmt_2_80.snap @@ -7,7 +7,7 @@ alter function my_schema.compute_totals(int, text) leakproof strict security definer - parallel SAFE + parallel safe cost 10 rows 5 set search_path to public, pg_temp diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_op_family_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_op_family_stmt_0_100.snap index 05fd23e3c..38c78f7e9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_op_family_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_op_family_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_op_family_stmt_0.sql snapshot_kind: text --- -alter operator family myopfamily using btree add operator 1 < (int, int); +alter operator family myopfamily using btree add operator 1 < (int4, int4); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_op_family_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_op_family_stmt_0_80.snap index 05fd23e3c..38c78f7e9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_op_family_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_op_family_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_op_family_stmt_0.sql snapshot_kind: text --- -alter operator family myopfamily using btree add operator 1 < (int, int); +alter operator family myopfamily using btree add operator 1 < (int4, int4); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_operator_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_operator_stmt_0_100.snap index 4cd120b7c..660367004 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_operator_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_operator_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_operator_stmt_0.sql snapshot_kind: text --- -alter operator + (int, int) owner to postgres; +alter operator + (int4, int4) owner to postgres; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_operator_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_operator_stmt_0_80.snap index 4cd120b7c..660367004 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_operator_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_operator_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_operator_stmt_0.sql snapshot_kind: text --- -alter operator + (int, int) owner to postgres; +alter operator + (int4, int4) owner to postgres; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_stmt_3_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_stmt_3_100.snap index fbe8f5e40..41c03d62c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_stmt_3_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__alter_table_stmt_3_100.snap @@ -3,10 +3,6 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/alter_table_stmt_3.sql --- alter table itest6 - alter column a - set generated by default - set increment by 2 - set start with 100 - restart, + alter column a set generated by default set increment by 2 set start with 100 restart, alter column b restart, alter column c restart with 5 set generated always; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__bool_expr_parentheses_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__bool_expr_parentheses_0_100.snap index cccee045d..5b46269de 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__bool_expr_parentheses_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__bool_expr_parentheses_0_100.snap @@ -7,10 +7,4 @@ select from demo where - ( - flag_a or flag_b - ) and - not (flag_c or flag_d) and - ( - (flag_e and flag_f) or flag_g - ); + (flag_a or flag_b) and not (flag_c or flag_d) and ((flag_e and flag_f) or flag_g); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_100.snap index f4dc406d9..2595534d8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_100.snap @@ -7,9 +7,5 @@ select from s.units where - (units.has_history or - units.has_shares or - units.has_calls) - is true and - (units.is_active and units.is_visible) - is not false; + (units.has_history or units.has_shares or units.has_calls) is true and + (units.is_active and units.is_visible) is not false; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_80.snap index f4dc406d9..2595534d8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__boolean_test_bool_expr_80.snap @@ -7,9 +7,5 @@ select from s.units where - (units.has_history or - units.has_shares or - units.has_calls) - is true and - (units.is_active and units.is_visible) - is not false; + (units.has_history or units.has_shares or units.has_calls) is true and + (units.is_active and units.is_visible) is not false; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__cast_operator_style_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__cast_operator_style_100.snap index ed3cc76d1..9484c3234 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__cast_operator_style_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__cast_operator_style_100.snap @@ -10,7 +10,7 @@ select (t.a + t.b)::int, (t.a || t.b)::text, t.a::text::bigint, - (select MAX(u.id) from s.u)::bigint, + (select max(u.id) from s.u)::bigint, case when t.a then 1 else 2 end::text from s.t; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__cast_operator_style_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__cast_operator_style_80.snap index ed3cc76d1..9484c3234 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__cast_operator_style_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__cast_operator_style_80.snap @@ -10,7 +10,7 @@ select (t.a + t.b)::int, (t.a || t.b)::text, t.a::text::bigint, - (select MAX(u.id) from s.u)::bigint, + (select max(u.id) from s.u)::bigint, case when t.a then 1 else 2 end::text from s.t; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__char_type_names_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__char_type_names_0_100.snap index 0c1d321ff..d0816216d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__char_type_names_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__char_type_names_0_100.snap @@ -10,5 +10,5 @@ create table t ( d char(3), e pg_catalog.bpchar, f pg_catalog."char", - g char(5) + g bpchar(5) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__char_type_names_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__char_type_names_0_80.snap index 0c1d321ff..d0816216d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__char_type_names_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__char_type_names_0_80.snap @@ -10,5 +10,5 @@ create table t ( d char(3), e pg_catalog.bpchar, f pg_catalog."char", - g char(5) + g bpchar(5) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__coalesce_expr_1_200.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__coalesce_expr_1_200.snap index 260d69b7d..daca3591c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__coalesce_expr_1_200.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__coalesce_expr_1_200.snap @@ -1,6 +1,5 @@ --- source: crates/pgls_pretty_print/tests/tests.rs -assertion_line: 184 input_file: crates/pgls_pretty_print/tests/data/single/coalesce_expr_1.sql --- SELECT @@ -9,9 +8,5 @@ FROM t LEFT OUTER JOIN payment_types AS source_payment_types - ON source_payment_types.value_en = - COALESCE( - rent_issuance_parameters_payment_types.value - , translating.leases.rent_issuance_parameters_payment_type - ) + ON source_payment_types.value_en = COALESCE(rent_issuance_parameters_payment_types.value, translating.leases.rent_issuance_parameters_payment_type) ; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__compact_clause_condition_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__compact_clause_condition_80.snap index 3d9dbb9df..5db2e7b33 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__compact_clause_condition_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__compact_clause_condition_80.snap @@ -5,6 +5,5 @@ input_file: crates/pgls_pretty_print/tests/data/single/compact_clause_condition. select staging.buildings.id from staging.buildings -where staging.buildings.construction_year > - 1950 and +where staging.buildings.construction_year > 1950 and staging.buildings.address_fk is not null; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__compact_from_clause_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__compact_from_clause_80.snap index 3f6b853f6..db0b319c7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__compact_from_clause_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__compact_from_clause_80.snap @@ -8,7 +8,5 @@ select from staging.buildings left outer join staging.addresses - on staging.addresses.id = - staging.buildings.address_fk -where staging.buildings.construction_year > - 1950; + on staging.addresses.id = staging.buildings.address_fk +where staging.buildings.construction_year > 1950; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_0_100.snap index c3164aa2f..e17cb4e41 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_0_100.snap @@ -14,12 +14,7 @@ as ( col as resorigcol, ord from - pg_constraint - left outer join - lateral unnest(conkey) - with ordinality - as _ (col, ord) - on true + pg_constraint left outer join lateral unnest(conkey) with ordinality as _ (col, ord) on true where contype in ('p', 'f') union @@ -31,12 +26,7 @@ as ( col, ord from - pg_constraint - left outer join - lateral unnest(confkey) - with ordinality - as _ (col, ord) - on true + pg_constraint left outer join lateral unnest(confkey) with ordinality as _ (col, ord) on true where contype = 'f' ), @@ -48,10 +38,7 @@ as ( c.relname as view_name, r.ev_action as view_definition from - pg_class as c - inner join - pg_namespace as n - on n.oid = c.relnamespace + pg_class as c inner join pg_namespace as n on n.oid = c.relnamespace inner join pg_rewrite as r on r.ev_class = c.oid @@ -149,10 +136,7 @@ as ( view_id, view_schema, view_name, - json_array_elements( - view_definition -> 0 -> 'targetList' - ) - as entry + json_array_elements(view_definition -> 0 -> 'targetList') as entry from transform_json ), @@ -168,23 +152,9 @@ as ( from target_entries ), -recursion (view_id, -view_schema, -view_name, -view_column, -resorigtbl, -resorigcol, -is_cycle, -path) +recursion (view_id, view_schema, view_name, view_column, resorigtbl, resorigcol, is_cycle, path) as ( - select - r.*, - false, - array[resorigtbl] - from - results as r - where - true + select r.*, false, array[resorigtbl] from results as r where true union all select view.view_id, @@ -199,8 +169,7 @@ as ( recursion as view inner join results as tab - on view.resorigtbl = tab.view_id and - view.resorigcol = tab.view_column + on view.resorigtbl = tab.view_id and view.resorigcol = tab.view_column where not is_cycle ), @@ -217,8 +186,7 @@ as ( recursion inner join pg_attribute as vcol - on vcol.attrelid = view_id and - vcol.attnum = view_column + on vcol.attrelid = view_id and vcol.attnum = view_column group by view_id, view_schema, view_name, @@ -240,19 +208,13 @@ select ) as column_dependencies from - repeated_references as rep - inner join - pks_fks - using ( - "resorigtbl", - "resorigcol") + repeated_references as rep inner join pks_fks using ( resorigtbl, resorigcol) inner join pg_class as tbl on tbl.oid = rep.resorigtbl inner join pg_attribute as col - on col.attrelid = tbl.oid and - col.attnum = rep.resorigcol + on col.attrelid = tbl.oid and col.attnum = rep.resorigcol inner join pg_namespace as sch on sch.oid = tbl.relnamespace @@ -264,10 +226,4 @@ group by sch.nspname, pks_fks.contype, pks_fks.ncol having - ncol = - array_length( - array_agg( - row(col.attname, view_columns) order by pks_fks.ord - ), - 1 - ); + ncol = array_length(array_agg(row(col.attname, view_columns) order by pks_fks.ord), 1); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_0_80.snap index 8a706b8d5..4bce7a692 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_0_80.snap @@ -16,9 +16,7 @@ as ( from pg_constraint left outer join - lateral unnest(conkey) - with ordinality - as _ (col, ord) + lateral unnest(conkey) with ordinality as _ (col, ord) on true where contype in ('p', 'f') @@ -33,9 +31,7 @@ as ( from pg_constraint left outer join - lateral unnest(confkey) - with ordinality - as _ (col, ord) + lateral unnest(confkey) with ordinality as _ (col, ord) on true where contype = 'f' @@ -48,10 +44,7 @@ as ( c.relname as view_name, r.ev_action as view_definition from - pg_class as c - inner join - pg_namespace as n - on n.oid = c.relnamespace + pg_class as c inner join pg_namespace as n on n.oid = c.relnamespace inner join pg_rewrite as r on r.ev_class = c.oid @@ -153,10 +146,7 @@ as ( view_id, view_schema, view_name, - json_array_elements( - view_definition -> 0 -> 'targetList' - ) - as entry + json_array_elements(view_definition -> 0 -> 'targetList') as entry from transform_json ), @@ -166,32 +156,24 @@ as ( view_id, view_schema, view_name, - cast(entry ->> 'resno' as int) - as view_column, - cast(entry ->> 'resorigtbl' as oid) - as resorigtbl, - cast(entry ->> 'resorigcol' as int) - as resorigcol + cast(entry ->> 'resno' as int) as view_column, + cast(entry ->> 'resorigtbl' as oid) as resorigtbl, + cast(entry ->> 'resorigcol' as int) as resorigcol from target_entries ), -recursion (view_id, -view_schema, -view_name, -view_column, -resorigtbl, -resorigcol, -is_cycle, -path) +recursion ( + view_id, + view_schema, + view_name, + view_column, + resorigtbl, + resorigcol, + is_cycle, + path +) as ( - select - r.*, - false, - array[resorigtbl] - from - results as r - where - true + select r.*, false, array[resorigtbl] from results as r where true union all select view.view_id, @@ -206,8 +188,7 @@ as ( recursion as view inner join results as tab - on view.resorigtbl = tab.view_id and - view.resorigcol = tab.view_column + on view.resorigtbl = tab.view_id and view.resorigcol = tab.view_column where not is_cycle ), @@ -224,8 +205,7 @@ as ( recursion inner join pg_attribute as vcol - on vcol.attrelid = view_id and - vcol.attnum = view_column + on vcol.attrelid = view_id and vcol.attnum = view_column group by view_id, view_schema, view_name, @@ -247,19 +227,13 @@ select ) as column_dependencies from - repeated_references as rep - inner join - pks_fks - using ( - "resorigtbl", - "resorigcol") + repeated_references as rep inner join pks_fks using ( resorigtbl, resorigcol) inner join pg_class as tbl on tbl.oid = rep.resorigtbl inner join pg_attribute as col - on col.attrelid = tbl.oid and - col.attnum = rep.resorigcol + on col.attrelid = tbl.oid and col.attnum = rep.resorigcol inner join pg_namespace as sch on sch.oid = tbl.relnamespace @@ -273,8 +247,6 @@ group by sch.nspname, having ncol = array_length( - array_agg( - row(col.attname, view_columns) order by pks_fks.ord - ), + array_agg(row(col.attname, view_columns) order by pks_fks.ord), 1 ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_0_100.snap index 43cc1533a..15669446f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_0_100.snap @@ -11,12 +11,7 @@ select col as resorigcol, ord from - pg_constraint - left outer join - lateral unnest(conkey) - with ordinality - as _ (col, ord) - on true + pg_constraint left outer join lateral unnest(conkey) with ordinality as _ (col, ord) on true where contype in ('p', 'f') union @@ -28,11 +23,6 @@ select col, ord from - pg_constraint - left outer join - lateral unnest(confkey) - with ordinality - as _ (col, ord) - on true + pg_constraint left outer join lateral unnest(confkey) with ordinality as _ (col, ord) on true where contype = 'f'; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_0_80.snap index 43cc1533a..d925cd351 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_0_80.snap @@ -13,9 +13,7 @@ select from pg_constraint left outer join - lateral unnest(conkey) - with ordinality - as _ (col, ord) + lateral unnest(conkey) with ordinality as _ (col, ord) on true where contype in ('p', 'f') @@ -30,9 +28,7 @@ select from pg_constraint left outer join - lateral unnest(confkey) - with ordinality - as _ (col, ord) + lateral unnest(confkey) with ordinality as _ (col, ord) on true where contype = 'f'; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_1_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_1_100.snap index e6a32ac02..972a759ad 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_1_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_1_100.snap @@ -9,10 +9,7 @@ select c.relname as view_name, r.ev_action as view_definition from - pg_class as c - inner join - pg_namespace as n - on n.oid = c.relnamespace + pg_class as c inner join pg_namespace as n on n.oid = c.relnamespace inner join pg_rewrite as r on r.ev_class = c.oid diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_1_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_1_80.snap index e6a32ac02..972a759ad 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_1_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_1_80.snap @@ -9,10 +9,7 @@ select c.relname as view_name, r.ev_action as view_definition from - pg_class as c - inner join - pg_namespace as n - on n.oid = c.relnamespace + pg_class as c inner join pg_namespace as n on n.oid = c.relnamespace inner join pg_rewrite as r on r.ev_class = c.oid diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_3_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_3_100.snap index 5862a6c7a..5ad5d5739 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_3_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_3_100.snap @@ -7,9 +7,6 @@ select view_id, view_schema, view_name, - json_array_elements( - view_definition -> 0 -> 'targetList' - ) - as entry + json_array_elements(view_definition -> 0 -> 'targetList') as entry from transform_json; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_3_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_3_80.snap index 5862a6c7a..5ad5d5739 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_3_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_3_80.snap @@ -7,9 +7,6 @@ select view_id, view_schema, view_name, - json_array_elements( - view_definition -> 0 -> 'targetList' - ) - as entry + json_array_elements(view_definition -> 0 -> 'targetList') as entry from transform_json; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_4_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_4_80.snap index c85abe319..79271a2f2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_4_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_4_80.snap @@ -7,11 +7,8 @@ select view_id, view_schema, view_name, - cast(entry ->> 'resno' as int) - as view_column, - cast(entry ->> 'resorigtbl' as oid) - as resorigtbl, - cast(entry ->> 'resorigcol' as int) - as resorigcol + cast(entry ->> 'resno' as int) as view_column, + cast(entry ->> 'resorigtbl' as oid) as resorigtbl, + cast(entry ->> 'resorigcol' as int) as resorigcol from target_entries; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_5_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_5_100.snap index d0e598a09..dd28fff8c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_5_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_5_100.snap @@ -3,14 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/complex_select_part_5.sql snapshot_kind: text --- -select - r.*, - false, - array[resorigtbl] -from - results as r -where - true +select r.*, false, array[resorigtbl] from results as r where true union all select view.view_id, @@ -25,7 +18,6 @@ from recursion as view inner join results as tab - on view.resorigtbl = tab.view_id and - view.resorigcol = tab.view_column + on view.resorigtbl = tab.view_id and view.resorigcol = tab.view_column where not is_cycle; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_5_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_5_80.snap index d0e598a09..dd28fff8c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_5_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_5_80.snap @@ -3,14 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/complex_select_part_5.sql snapshot_kind: text --- -select - r.*, - false, - array[resorigtbl] -from - results as r -where - true +select r.*, false, array[resorigtbl] from results as r where true union all select view.view_id, @@ -25,7 +18,6 @@ from recursion as view inner join results as tab - on view.resorigtbl = tab.view_id and - view.resorigcol = tab.view_column + on view.resorigtbl = tab.view_id and view.resorigcol = tab.view_column where not is_cycle; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_6_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_6_100.snap index d3a7f4441..eda2f3c60 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_6_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_6_100.snap @@ -11,11 +11,7 @@ select resorigcol, array_agg(attname) as view_columns from - recursion - inner join - pg_attribute as vcol - on vcol.attrelid = view_id and - vcol.attnum = view_column + recursion inner join pg_attribute as vcol on vcol.attrelid = view_id and vcol.attnum = view_column group by view_id, view_schema, view_name, diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_6_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_6_80.snap index d3a7f4441..4f80f3e2b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_6_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_6_80.snap @@ -14,8 +14,7 @@ from recursion inner join pg_attribute as vcol - on vcol.attrelid = view_id and - vcol.attnum = view_column + on vcol.attrelid = view_id and vcol.attnum = view_column group by view_id, view_schema, view_name, diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_7_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_7_100.snap index bdbe316b5..283facf8f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_7_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_7_100.snap @@ -18,19 +18,13 @@ select ) as column_dependencies from - repeated_references as rep - inner join - pks_fks - using ( - "resorigtbl", - "resorigcol") + repeated_references as rep inner join pks_fks using ( resorigtbl, resorigcol) inner join pg_class as tbl on tbl.oid = rep.resorigtbl inner join pg_attribute as col - on col.attrelid = tbl.oid and - col.attnum = rep.resorigcol + on col.attrelid = tbl.oid and col.attnum = rep.resorigcol inner join pg_namespace as sch on sch.oid = tbl.relnamespace @@ -42,10 +36,4 @@ group by sch.nspname, pks_fks.contype, pks_fks.ncol having - ncol = - array_length( - array_agg( - row(col.attname, view_columns) order by pks_fks.ord - ), - 1 - ); + ncol = array_length(array_agg(row(col.attname, view_columns) order by pks_fks.ord), 1); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_7_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_7_80.snap index bdbe316b5..494cb00e9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_7_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__complex_select_part_7_80.snap @@ -18,19 +18,13 @@ select ) as column_dependencies from - repeated_references as rep - inner join - pks_fks - using ( - "resorigtbl", - "resorigcol") + repeated_references as rep inner join pks_fks using ( resorigtbl, resorigcol) inner join pg_class as tbl on tbl.oid = rep.resorigtbl inner join pg_attribute as col - on col.attrelid = tbl.oid and - col.attnum = rep.resorigcol + on col.attrelid = tbl.oid and col.attnum = rep.resorigcol inner join pg_namespace as sch on sch.oid = tbl.relnamespace @@ -44,8 +38,6 @@ group by sch.nspname, having ncol = array_length( - array_agg( - row(col.attname, view_columns) order by pks_fks.ord - ), + array_agg(row(col.attname, view_columns) order by pks_fks.ord), 1 ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__constraint_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__constraint_0_100.snap index 8825b670b..b54a5f1d2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__constraint_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__constraint_0_100.snap @@ -5,5 +5,5 @@ input_file: crates/pgls_pretty_print/tests/data/single/constraint_0.sql create table deferred_excl ( f1 int, f2 int, - constraint "deferred_excl_con" exclude using btree (f1 with =) deferrable initially deferred + constraint deferred_excl_con exclude using btree (f1 with =) deferrable initially deferred ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__constraint_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__constraint_0_80.snap index 8825b670b..7e60fc078 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__constraint_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__constraint_0_80.snap @@ -5,5 +5,6 @@ input_file: crates/pgls_pretty_print/tests/data/single/constraint_0.sql create table deferred_excl ( f1 int, f2 int, - constraint "deferred_excl_con" exclude using btree (f1 with =) deferrable initially deferred + constraint deferred_excl_con exclude using btree (f1 with =) + deferrable initially deferred ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__copy_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__copy_stmt_0_100.snap index a18d2754b..a25884068 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__copy_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__copy_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/copy_stmt_0.sql snapshot_kind: text --- -copy users to '/tmp/users.csv' with (FORMAT 'csv', HEADER); +copy users to '/tmp/users.csv' with (format 'csv', header); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__copy_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__copy_stmt_0_80.snap index a18d2754b..a25884068 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__copy_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__copy_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/copy_stmt_0.sql snapshot_kind: text --- -copy users to '/tmp/users.csv' with (FORMAT 'csv', HEADER); +copy users to '/tmp/users.csv' with (format 'csv', header); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_event_trig_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_event_trig_stmt_0_100.snap index d63032611..f1c8f8f75 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_event_trig_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_event_trig_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_event_trig_stmt_0.sql snapshot_kind: text --- -create event trigger "my_event_trigger" on ddl_command_start execute function my_event_function(); +create event trigger my_event_trigger on ddl_command_start execute function my_event_function(); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_event_trig_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_event_trig_stmt_0_80.snap index 1ae785e3c..6fa4ce655 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_event_trig_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_event_trig_stmt_0_80.snap @@ -3,6 +3,6 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_event_trig_stmt_0.sql snapshot_kind: text --- -create event trigger "my_event_trigger" +create event trigger my_event_trigger on ddl_command_start execute function my_event_function(); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_100.snap index e470148e2..27db8ffc7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_100.snap @@ -5,6 +5,4 @@ input_file: crates/pgls_pretty_print/tests/data/single/create_function_stmt_0.sq create function add(a int, b int) returns int language sql -as $function$ -SELECT $1 + $2 -$function$; +as 'SELECT $1 + $2'; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_80.snap index e470148e2..27db8ffc7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_80.snap @@ -5,6 +5,4 @@ input_file: crates/pgls_pretty_print/tests/data/single/create_function_stmt_0.sq create function add(a int, b int) returns int language sql -as $function$ -SELECT $1 + $2 -$function$; +as 'SELECT $1 + $2'; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_100.snap index 5d5b449ba..2c931195c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_100.snap @@ -7,6 +7,4 @@ create function public.sql_func_with_transform(int) returns int language sql transform for type int, for type text -as $function$ -select $1 + 1 -$function$; +as 'select $1 + 1'; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_80.snap index 5d5b449ba..2c931195c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_80.snap @@ -7,6 +7,4 @@ create function public.sql_func_with_transform(int) returns int language sql transform for type int, for type text -as $function$ -select $1 + 1 -$function$; +as 'select $1 + 1'; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_op_class_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_op_class_stmt_0_100.snap index aa1ffec6e..37d45b619 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_op_class_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_op_class_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_op_class_stmt_0.sql snapshot_kind: text --- -create operator class myopclass for type int using btree as operator 1 <; +create operator class myopclass for type int4 using btree as operator 1 <; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_op_class_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_op_class_stmt_0_80.snap index aa1ffec6e..37d45b619 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_op_class_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_op_class_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_op_class_stmt_0.sql snapshot_kind: text --- -create operator class myopclass for type int using btree as operator 1 <; +create operator class myopclass for type int4 using btree as operator 1 <; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_range_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_range_stmt_0_100.snap index 8ee30e8f3..0ed380955 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_range_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_range_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_range_stmt_0.sql snapshot_kind: text --- -create type float8_range as range (subtype = double precision, subtype_diff = float8mi); +create type float8_range as range (subtype = float8, subtype_diff = float8mi); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_range_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_range_stmt_0_80.snap index a6b92e380..0ed380955 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_range_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_range_stmt_0_80.snap @@ -3,7 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_range_stmt_0.sql snapshot_kind: text --- -create type float8_range as range ( - subtype = double precision, - subtype_diff = float8mi -); +create type float8_range as range (subtype = float8, subtype_diff = float8mi); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_schema_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_schema_stmt_0_100.snap index 79d44b2ea..a7a0c713b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_schema_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_schema_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_schema_stmt_0.sql snapshot_kind: text --- -create schema "myschema"; +create schema myschema; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_schema_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_schema_stmt_0_80.snap index 79d44b2ea..a7a0c713b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_schema_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_schema_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_schema_stmt_0.sql snapshot_kind: text --- -create schema "myschema"; +create schema myschema; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stats_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stats_stmt_0_100.snap index 2cf24bfe1..d91602a34 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stats_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stats_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_stats_stmt_0.sql snapshot_kind: text --- -create statistics s1 on "a", "b" from t1; +create statistics s1 on a, b from t1; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stats_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stats_stmt_0_80.snap index 2cf24bfe1..d91602a34 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stats_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stats_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/create_stats_stmt_0.sql snapshot_kind: text --- -create statistics s1 on "a", "b" from t1; +create statistics s1 on a, b from t1; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stmt_cast_check_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stmt_cast_check_0_100.snap index 05f5a09b5..c35a1c922 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stmt_cast_check_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stmt_cast_check_0_100.snap @@ -7,10 +7,7 @@ create table t ( target_column text, from_value text, to_value text, - constraint "c2" check (type <> cast('es_value_changed' as public.my_enum) or - (target_column = cast('config' as text) and - from_value is null and to_value is null) or - (from_value is not null and - to_value is not null and - target_column in ('type', 'name'))) + constraint c2 check (type <> cast('es_value_changed' as public.my_enum) or + (target_column = cast('config' as text) and from_value is null and to_value is null) or + (from_value is not null and to_value is not null and target_column in ('type', 'name'))) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stmt_cast_check_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stmt_cast_check_0_80.snap index ce7f81a66..f9d79afe7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stmt_cast_check_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_stmt_cast_check_0_80.snap @@ -7,11 +7,10 @@ create table t ( target_column text, from_value text, to_value text, - constraint "c2" check (type <> - cast('es_value_changed' - as public.my_enum) or + constraint c2 check (type <> cast('es_value_changed' as public.my_enum) or (target_column = cast('config' as text) and - from_value is null and to_value is null) or + from_value is null and + to_value is null) or (from_value is not null and to_value is not null and target_column in ('type', 'name'))) diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_table_as_with_cte_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_table_as_with_cte_80.snap index 9ff789dc9..e875d23b2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_table_as_with_cte_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_table_as_with_cte_80.snap @@ -4,9 +4,4 @@ input_file: crates/pgls_pretty_print/tests/data/single/create_table_as_with_cte. --- create table s.t as - with - c as (select x.a from s.x order by x.a) - select - c.a - from - c; + with c as (select x.a from s.x order by x.a) select c.a from c; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__createdb_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__createdb_stmt_0_100.snap index ede4820e8..2f68da0c9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__createdb_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__createdb_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/createdb_stmt_0.sql snapshot_kind: text --- -create database "mydb"; +create database mydb; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__createdb_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__createdb_stmt_0_80.snap index ede4820e8..2f68da0c9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__createdb_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__createdb_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/createdb_stmt_0.sql snapshot_kind: text --- -create database "mydb"; +create database mydb; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__declare_cursor_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__declare_cursor_stmt_0_100.snap index e4517f405..41ddadea2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__declare_cursor_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__declare_cursor_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/declare_cursor_stmt_0.sql snapshot_kind: text --- -declare "mycursor" cursor for select * from mytable;; +declare mycursor cursor for select * from mytable;; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__declare_cursor_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__declare_cursor_stmt_0_80.snap index e4517f405..41ddadea2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__declare_cursor_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__declare_cursor_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/declare_cursor_stmt_0.sql snapshot_kind: text --- -declare "mycursor" cursor for select * from mytable;; +declare mycursor cursor for select * from mytable;; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__delete_with_cte_returning_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__delete_with_cte_returning_0_100.snap index aa76e76ca..fc7f4e7cd 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__delete_with_cte_returning_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__delete_with_cte_returning_0_100.snap @@ -3,16 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/delete_with_cte_returning_0.sql snapshot_kind: text --- -with -stale -as ( - select - id - from - sessions - where - last_seen < NOW() - cast('30 days' as interval) -) +with stale as (select id from sessions where last_seen < now() - cast('30 days' as interval)) delete from sessions using stale where diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__delete_with_cte_returning_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__delete_with_cte_returning_0_80.snap index 172eaaf0f..9a5b550b4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__delete_with_cte_returning_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__delete_with_cte_returning_0_80.snap @@ -6,13 +6,7 @@ snapshot_kind: text with stale as ( - select - id - from - sessions - where - last_seen < - NOW() - cast('30 days' as interval) + select id from sessions where last_seen < now() - cast('30 days' as interval) ) delete from sessions using stale diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_100.snap index aae6cc658..1fd170532 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_100.snap @@ -2,8 +2,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/do_stmt_0.sql --- -do -language plpgsql -$do$ -BEGIN NULL; END -$do$; +do language plpgsql 'BEGIN NULL; END'; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_80.snap index aae6cc658..1fd170532 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_80.snap @@ -2,8 +2,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/do_stmt_0.sql --- -do -language plpgsql -$do$ -BEGIN NULL; END -$do$; +do language plpgsql 'BEGIN NULL; END'; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__dollar_quoted_function_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__dollar_quoted_function_0_100.snap index f6800d5d0..bb261b7e6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__dollar_quoted_function_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__dollar_quoted_function_0_100.snap @@ -6,8 +6,8 @@ snapshot_kind: text create function test_func() returns void language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'Hello, world!'; END; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__dollar_quoted_function_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__dollar_quoted_function_0_80.snap index f6800d5d0..bb261b7e6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__dollar_quoted_function_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__dollar_quoted_function_0_80.snap @@ -6,8 +6,8 @@ snapshot_kind: text create function test_func() returns void language plpgsql -as $function$ +as $$ BEGIN RAISE NOTICE 'Hello, world!'; END; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__func_call_within_group_filter_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__func_call_within_group_filter_0_100.snap index b5cf1ea0b..a1d80128e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__func_call_within_group_filter_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__func_call_within_group_filter_0_100.snap @@ -4,11 +4,6 @@ input_file: crates/pgls_pretty_print/tests/data/single/func_call_within_group_fi snapshot_kind: text --- select - percentile_cont( - 0.75 - ) - within group (order by salary desc) - filter (where - salary is not null) + percentile_cont(0.75) within group (order by salary desc) filter (where salary is not null) from employees; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__function_argument_groups_default_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__function_argument_groups_default_100.snap index 5a0ce0951..56eabba28 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__function_argument_groups_default_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__function_argument_groups_default_100.snap @@ -9,8 +9,6 @@ select 'invoiceReference', format_invoice_number(invoices.series, invoices.issued_on), 'id', users.id ), - json_build_object( - 'profile', jsonb_build_object('name', users.name, 'age', users.age) - ) + json_build_object('profile', jsonb_build_object('name', users.name, 'age', users.age)) from users; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__function_argument_groups_default_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__function_argument_groups_default_80.snap index 597393d48..5c2ca8917 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__function_argument_groups_default_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__function_argument_groups_default_80.snap @@ -7,10 +7,7 @@ select 'amountTTC', to_amount(amount_ttc, invoices.currency), 'amountVAT', to_amount(amount_vat, invoices.currency), 'invoiceReference', - format_invoice_number( - invoices.series, - invoices.issued_on - ), + format_invoice_number(invoices.series, invoices.issued_on), 'id', users.id ), json_build_object( diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_role_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_role_stmt_0_100.snap index 86002f7b0..0f2154ab2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_role_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_role_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/grant_role_stmt_0.sql snapshot_kind: text --- -grant ADMIN to user1, user2; +grant admin to user1, user2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_role_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_role_stmt_0_80.snap index 86002f7b0..0f2154ab2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_role_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_role_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/grant_role_stmt_0.sql snapshot_kind: text --- -grant ADMIN to user1, user2; +grant admin to user1, user2; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_stmt_0_100.snap index e8008e86e..d1faa6992 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/grant_stmt_0.sql snapshot_kind: text --- -grant SELECT on table users to john; +grant select on table users to john; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_stmt_0_80.snap index e8008e86e..d1faa6992 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__grant_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/grant_stmt_0.sql snapshot_kind: text --- -grant SELECT on table users to john; +grant select on table users to john; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__index_elem_reserved_keyword_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__index_elem_reserved_keyword_0_100.snap index 1cadc3cc7..7293dc1f9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__index_elem_reserved_keyword_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__index_elem_reserved_keyword_0_100.snap @@ -2,13 +2,8 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/index_elem_reserved_keyword_0.sql --- -create unique -index "index_user_emails_on_user_id_and_primary" -on public.user_emails -using btree -( +create unique index index_user_emails_on_user_id_and_primary on public.user_emails using btree ( user_id, "primary" ) -where - "primary"; +where "primary"; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__index_elem_reserved_keyword_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__index_elem_reserved_keyword_0_80.snap index 1cadc3cc7..190f8a5c6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__index_elem_reserved_keyword_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__index_elem_reserved_keyword_0_80.snap @@ -2,13 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/index_elem_reserved_keyword_0.sql --- -create unique -index "index_user_emails_on_user_id_and_primary" -on public.user_emails -using btree -( - user_id, - "primary" -) -where - "primary"; +create unique index index_user_emails_on_user_id_and_primary + on public.user_emails + using btree (user_id, "primary") +where "primary"; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__index_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__index_stmt_0_100.snap index 1e15949e5..abd0b815d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__index_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__index_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/index_stmt_0.sql snapshot_kind: text --- -create index "idx_users_email" on users using btree (email); +create index idx_users_email on users using btree (email); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__index_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__index_stmt_0_80.snap index 1e15949e5..abd0b815d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__index_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__index_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/index_stmt_0.sql snapshot_kind: text --- -create index "idx_users_email" on users using btree (email); +create index idx_users_email on users using btree (email); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__insert_with_cte_returning_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__insert_with_cte_returning_0_80.snap index f3416953e..de9488524 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__insert_with_cte_returning_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__insert_with_cte_returning_0_80.snap @@ -3,8 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/insert_with_cte_returning_0.sql snapshot_kind: text --- -with -src as (select 1 as id, 'alpha' as name) +with src as (select 1 as id, 'alpha' as name) insert into audit.log (id, name) select id, name from src returning id, diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__json_table_nested_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__json_table_nested_0_80.snap index d043e4620..3ac82b896 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__json_table_nested_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__json_table_nested_0_80.snap @@ -7,8 +7,7 @@ select * from json_table( - cast('{"outer": [{"items": [1, null]}]}' - as jsonb), + cast('{"outer": [{"items": [1, null]}]}' as jsonb), '$.outer[*]' columns ( outer_row_id for ordinality, diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__leading_boolean_operators_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__leading_boolean_operators_80.snap index 1faaa3601..603af475c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__leading_boolean_operators_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__leading_boolean_operators_80.snap @@ -7,7 +7,6 @@ select from staging.buildings where - staging.buildings.construction_year > - 1950 + staging.buildings.construction_year > 1950 and staging.buildings.address_fk is not null and staging.buildings.identification_number is not null; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__lock_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__lock_stmt_0_100.snap index 1e0210e0e..8a550aff0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__lock_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__lock_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/lock_stmt_0.sql snapshot_kind: text --- -lock table users in ACCESS EXCLUSIVE mode; +lock table users in access exclusive mode; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__lock_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__lock_stmt_0_80.snap index 1e0210e0e..8a550aff0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__lock_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__lock_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/lock_stmt_0.sql snapshot_kind: text --- -lock table users in ACCESS EXCLUSIVE mode; +lock table users in access exclusive mode; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_action_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_action_0_100.snap index 82aa0b68e..4e803baa4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_action_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_action_0_100.snap @@ -7,6 +7,4 @@ merge into products as p using new_products as np on p.product_id = np.product_id when matched then update set price = np.price -when not matched by target -then insert (product_id, price) -values (np.product_id, np.price); +when not matched by target then insert (product_id, price) values (np.product_id, np.price); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_action_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_action_0_80.snap index 2e9ae0dab..82aa0b68e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_action_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_action_0_80.snap @@ -6,8 +6,7 @@ snapshot_kind: text merge into products as p using new_products as np on p.product_id = np.product_id -when matched -then update set price = np.price +when matched then update set price = np.price when not matched by target then insert (product_id, price) values (np.product_id, np.price); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_0_100.snap index 22a2ffbd8..5c62a2a04 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_0_100.snap @@ -7,6 +7,4 @@ merge into target_table as t using source_table as s on t.id = s.id when matched then update set value = s.value -when not matched by target -then insert (id, value) -values (s.id, s.value); +when not matched by target then insert (id, value) values (s.id, s.value); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_0_80.snap index 1028b7384..5c62a2a04 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_0_80.snap @@ -6,8 +6,5 @@ snapshot_kind: text merge into target_table as t using source_table as s on t.id = s.id -when matched -then update set value = s.value -when not matched by target -then insert (id, value) -values (s.id, s.value); +when matched then update set value = s.value +when not matched by target then insert (id, value) values (s.id, s.value); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_1_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_1_100.snap index e3ae06dd0..314a16625 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_1_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_1_100.snap @@ -3,17 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/merge_stmt_1.sql --- merge into itest15 as t -using ( - select 20 as s_a, 'inserted by merge' as s_b -) -as s +using (select 20 as s_a, 'inserted by merge' as s_b) as s on t.a = s.s_a -when not matched and - s.s_a > 10 -then insert (a, b) -overriding user value -values (s.s_a, s.s_b) -when not matched by target -then insert -overriding system value -values (s.s_a, s.s_b); +when not matched and s.s_a > 10 then insert (a, b) overriding user value values (s.s_a, s.s_b) +when not matched by target then insert overriding system value values (s.s_a, s.s_b); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_1_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_1_80.snap index 4295b2a85..40ddfc3b7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_1_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_1_80.snap @@ -3,12 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/merge_stmt_1.sql --- merge into itest15 as t -using ( - select - 20 as s_a, - 'inserted by merge' as s_b -) -as s +using (select 20 as s_a, 'inserted by merge' as s_b) as s on t.a = s.s_a when not matched and s.s_a > 10 diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_variants_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_variants_0_100.snap index 257784fb4..d193f791e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_variants_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_variants_0_100.snap @@ -6,9 +6,7 @@ snapshot_kind: text merge into inventories as t using staging_inventory as s on t.sku = s.sku -when matched and - s.operation = 'delete' -then delete +when matched and s.operation = 'delete' then delete when matched and s.operation = 'update' then update set quantity = s.quantity, @@ -18,6 +16,4 @@ when not matched and then insert (sku, quantity, created_at) values (s.sku, s.quantity, clock_timestamp()) when not matched by target then do nothing -when not matched by source and - t.discontinued is false -then delete; +when not matched by source and t.discontinued is false then delete; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_variants_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_variants_0_80.snap index 04a4ae1a4..d193f791e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_variants_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_stmt_variants_0_80.snap @@ -6,9 +6,7 @@ snapshot_kind: text merge into inventories as t using staging_inventory as s on t.sku = s.sku -when matched and - s.operation = 'delete' -then delete +when matched and s.operation = 'delete' then delete when matched and s.operation = 'update' then update set quantity = s.quantity, @@ -17,8 +15,5 @@ when not matched and s.operation = 'insert' then insert (sku, quantity, created_at) values (s.sku, s.quantity, clock_timestamp()) -when not matched by target -then do nothing -when not matched by source and - t.discontinued is false -then delete; +when not matched by target then do nothing +when not matched by source and t.discontinued is false then delete; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_support_func_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_support_func_0_100.snap index bb49ce682..0730e84ab 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_support_func_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_support_func_0_100.snap @@ -7,6 +7,4 @@ merge into products as p using new_products as np on p.product_id = np.product_id when matched then update set price = np.price -when not matched by target -then insert -values (np.product_id, np.price); +when not matched by target then insert values (np.product_id, np.price); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_support_func_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_support_func_0_80.snap index 17f709bf2..0730e84ab 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_support_func_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__merge_support_func_0_80.snap @@ -6,8 +6,5 @@ snapshot_kind: text merge into products as p using new_products as np on p.product_id = np.product_id -when matched -then update set price = np.price -when not matched by target -then insert -values (np.product_id, np.price); +when matched then update set price = np.price +when not matched by target then insert values (np.product_id, np.price); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__min_max_expr_1_200.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__min_max_expr_1_200.snap index 9500a2771..b2bd55163 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__min_max_expr_1_200.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__min_max_expr_1_200.snap @@ -1,6 +1,5 @@ --- source: crates/pgls_pretty_print/tests/tests.rs -assertion_line: 184 input_file: crates/pgls_pretty_print/tests/data/single/min_max_expr_1.sql --- SELECT @@ -9,10 +8,5 @@ FROM t LEFT OUTER JOIN payment_types AS source_payment_types - ON source_payment_types.value_en = - GREATEST( - rent_issuance_parameters_payment_types.value - , translating.leases.rent_issuance_parameters_payment_type - , staging.leases.payment_type_source - ) + ON source_payment_types.value_en = GREATEST(rent_issuance_parameters_payment_types.value, translating.leases.rent_issuance_parameters_payment_type, staging.leases.payment_type_source) ; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_0_100.snap index 54c2193b3..3f1153e85 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_0_100.snap @@ -6,8 +6,8 @@ snapshot_kind: text create function test_nested() returns void language plpgsql -as $function$ +as $$ BEGIN EXECUTE $inner$SELECT 1$inner$; END; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_0_80.snap index 54c2193b3..3f1153e85 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_0_80.snap @@ -6,8 +6,8 @@ snapshot_kind: text create function test_nested() returns void language plpgsql -as $function$ +as $$ BEGIN EXECUTE $inner$SELECT 1$inner$; END; -$function$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_100.snap index b43f67d04..39565e7d4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_100.snap @@ -6,8 +6,8 @@ snapshot_kind: text create function test_conflict() returns void language plpgsql -as $function$ +as $outer$ BEGIN EXECUTE $$SELECT 1$$; END; -$function$; +$outer$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_80.snap index b43f67d04..39565e7d4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_80.snap @@ -6,8 +6,8 @@ snapshot_kind: text create function test_conflict() returns void language plpgsql -as $function$ +as $outer$ BEGIN EXECUTE $$SELECT 1$$; END; -$function$; +$outer$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__pl_assign_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__pl_assign_stmt_0_100.snap index bba35552e..9f084229f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__pl_assign_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__pl_assign_stmt_0_100.snap @@ -2,11 +2,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/pl_assign_stmt_0.sql --- -do -$do$ +do $$ DECLARE x integer; BEGIN x := 42; -END -$do$; +END $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__pl_assign_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__pl_assign_stmt_0_80.snap index bba35552e..9f084229f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__pl_assign_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__pl_assign_stmt_0_80.snap @@ -2,11 +2,9 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/pl_assign_stmt_0.sql --- -do -$do$ +do $$ DECLARE x integer; BEGIN x := 42; -END -$do$; +END $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__range_table_func_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__range_table_func_0_100.snap index 332bb7f3c..85796a1f3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__range_table_func_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__range_table_func_0_100.snap @@ -6,10 +6,4 @@ snapshot_kind: text select * from - xmltable( - - '/root' - passing 'value' - columns - item text path 'item' - ); + xmltable( '/root' passing 'value' columns item text path 'item'); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__return_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__return_stmt_0_100.snap index 8af34909b..a69c19693 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__return_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__return_stmt_0_100.snap @@ -2,9 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/return_stmt_0.sql --- -do -$do$ +do $$ BEGIN RETURN; -END -$do$; +END $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__return_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__return_stmt_0_80.snap index 8af34909b..a69c19693 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__return_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__return_stmt_0_80.snap @@ -2,9 +2,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/return_stmt_0.sql --- -do -$do$ +do $$ BEGIN RETURN; -END -$do$; +END $$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rule_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rule_stmt_0_100.snap index 41d0e96a7..d2dd319dc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__rule_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rule_stmt_0_100.snap @@ -6,4 +6,4 @@ snapshot_kind: text create rule notify_me as on update to mytable do - notify "mytable_updated";; + notify mytable_updated;; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__rule_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__rule_stmt_0_80.snap index 41d0e96a7..d2dd319dc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__rule_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__rule_stmt_0_80.snap @@ -6,4 +6,4 @@ snapshot_kind: text create rule notify_me as on update to mytable do - notify "mytable_updated";; + notify mytable_updated;; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__table_func_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__table_func_0_100.snap index 109d39142..6f7a57e59 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__table_func_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__table_func_0_100.snap @@ -7,8 +7,7 @@ select * from json_table( - cast('{"employees":[{"name":"Al","age":1}]}' - as jsonb), + cast('{"employees":[{"name":"Al","age":1}]}' as jsonb), '$.employees[*]' columns ( name text path '$.name', diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__table_func_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__table_func_0_80.snap index 109d39142..6f7a57e59 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__table_func_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__table_func_0_80.snap @@ -7,8 +7,7 @@ select * from json_table( - cast('{"employees":[{"name":"Al","age":1}]}' - as jsonb), + cast('{"employees":[{"name":"Al","age":1}]}' as jsonb), '$.employees[*]' columns ( name text path '$.name', diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_100.snap index 2646f0a62..075797fe6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_100.snap @@ -5,6 +5,5 @@ input_file: crates/pgls_pretty_print/tests/data/single/unique_constraint_nulls_n create table s.expense_types ( expense_type_legacy_id text, legacy_branch_code text, - unique nulls not distinct (expense_type_legacy_id, - legacy_branch_code) + unique nulls not distinct (expense_type_legacy_id, legacy_branch_code) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_80.snap index 2646f0a62..075797fe6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__unique_constraint_nulls_not_distinct_80.snap @@ -5,6 +5,5 @@ input_file: crates/pgls_pretty_print/tests/data/single/unique_constraint_nulls_n create table s.expense_types ( expense_type_legacy_id text, legacy_branch_code text, - unique nulls not distinct (expense_type_legacy_id, - legacy_branch_code) + unique nulls not distinct (expense_type_legacy_id, legacy_branch_code) ); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__update_multi_assign_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__update_multi_assign_0_100.snap index ba86f3b34..6fc6149b4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__update_multi_assign_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__update_multi_assign_0_100.snap @@ -4,7 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/single/update_multi_assign_0.sql snapshot_kind: text --- update accounts -set (balance, updated_at) = (balance + delta, NOW()) +set (balance, updated_at) = (balance + delta, now()) from adjustments where accounts.id = adjustments.account_id; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__update_multi_assign_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__update_multi_assign_0_80.snap index ba86f3b34..6fc6149b4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__update_multi_assign_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__update_multi_assign_0_80.snap @@ -4,7 +4,7 @@ input_file: crates/pgls_pretty_print/tests/data/single/update_multi_assign_0.sql snapshot_kind: text --- update accounts -set (balance, updated_at) = (balance + delta, NOW()) +set (balance, updated_at) = (balance + delta, now()) from adjustments where accounts.id = adjustments.account_id; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__update_with_cte_returning_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__update_with_cte_returning_0_100.snap index 8f6d3fb7b..b42531d4b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__update_with_cte_returning_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__update_with_cte_returning_0_100.snap @@ -3,11 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/update_with_cte_returning_0.sql snapshot_kind: text --- -with -pending -as ( - select id from invoices where status = 'pending' -) +with pending as (select id from invoices where status = 'pending') update invoices as inv set status = 'processed' from pending diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__update_with_cte_returning_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__update_with_cte_returning_0_80.snap index 14be5d88c..b42531d4b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__update_with_cte_returning_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__update_with_cte_returning_0_80.snap @@ -3,16 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/update_with_cte_returning_0.sql snapshot_kind: text --- -with -pending -as ( - select - id - from - invoices - where - status = 'pending' -) +with pending as (select id from invoices where status = 'pending') update invoices as inv set status = 'processed' from pending diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__variable_show_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__variable_show_stmt_0_100.snap index 4a8dd0067..244511241 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__variable_show_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__variable_show_stmt_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/variable_show_stmt_0.sql snapshot_kind: text --- -show "search_path"; +show search_path; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__variable_show_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__variable_show_stmt_0_80.snap index 4a8dd0067..244511241 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__variable_show_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__variable_show_stmt_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/variable_show_stmt_0.sql snapshot_kind: text --- -show "search_path"; +show search_path; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_def_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_def_0_100.snap index 03a22c6d8..e080aba71 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_def_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_def_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/window_def_0.sql snapshot_kind: text --- -select id, name, ROW_NUMBER() over (partition by dept order by salary desc) from employees; +select id, name, row_number() over (partition by dept order by salary desc) from employees; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_def_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_def_0_80.snap index 3377201a3..e9b7353c7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_def_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_def_0_80.snap @@ -6,6 +6,6 @@ snapshot_kind: text select id, name, - ROW_NUMBER() over (partition by dept order by salary desc) + row_number() over (partition by dept order by salary desc) from employees; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_func_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_func_0_100.snap index 9e0d81c04..5b32ad6d7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_func_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_func_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/window_func_0.sql snapshot_kind: text --- -select ROW_NUMBER() over (order by id) from users; +select row_number() over (order by id) from users; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_func_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_func_0_80.snap index 9e0d81c04..5b32ad6d7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_func_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_func_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/window_func_0.sql snapshot_kind: text --- -select ROW_NUMBER() over (order by id) from users; +select row_number() over (order by id) from users; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_function_group_200.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_function_group_200.snap index c6ceb7d3c..5ff5393f5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__window_function_group_200.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__window_function_group_200.snap @@ -1,17 +1,11 @@ --- source: crates/pgls_pretty_print/tests/tests.rs -assertion_line: 184 input_file: crates/pgls_pretty_print/tests/data/single/window_function_group.sql --- SELECT accounting_lines.id - , COUNT(*) OVER ( - PARTITION BY accounting_lines.accounting_class - , COALESCE( - source.accounting_account_sub_account_source - , accounting_lines.accounting_account_sub_account - ) - ) > 1 AS is_shared_target_account + , count(*) OVER (PARTITION BY accounting_lines.accounting_class, COALESCE(source.accounting_account_sub_account_source, accounting_lines.accounting_account_sub_account)) > 1 + AS is_shared_target_account FROM accounting_lines ; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__xml_serialize_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__xml_serialize_0_100.snap index db90e5e32..0a392194c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__xml_serialize_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__xml_serialize_0_100.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/xml_serialize_0.sql snapshot_kind: text --- -select XMLSERIALIZE(CONTENT doc as text); +select xmlserialize(content doc as text); diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__xml_serialize_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__xml_serialize_0_80.snap index db90e5e32..0a392194c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__xml_serialize_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__xml_serialize_0_80.snap @@ -3,4 +3,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/xml_serialize_0.sql snapshot_kind: text --- -select XMLSERIALIZE(CONTENT doc as text); +select xmlserialize(content doc as text); diff --git a/crates/pgls_pretty_print/tests/source_fidelity.rs b/crates/pgls_pretty_print/tests/source_fidelity.rs new file mode 100644 index 000000000..a2468a0fc --- /dev/null +++ b/crates/pgls_pretty_print/tests/source_fidelity.rs @@ -0,0 +1,305 @@ +//! A formatter only changes whitespace, line breaks, keyword case and redundant quoting. These +//! cases come from formatting a pg_dump-style schema, where it used to rewrite what was written. + +use pgls_pretty_print::{FormatConfig, format_statement}; + +fn format(sql: &str) -> String { + let config = FormatConfig::default(); + let ast = pgls_query::parse(sql).unwrap().into_root().unwrap(); + let first = format_statement(&ast, sql, &config).unwrap().formatted; + + let ast = pgls_query::parse(&first).unwrap().into_root().unwrap(); + let second = format_statement(&ast, &first, &config).unwrap().formatted; + assert_eq!(second, first, "formatting is not idempotent"); + first +} + +#[test] +fn pg_catalog_qualification_is_kept() { + assert_eq!( + format( + r#"CREATE TABLE "public"."t" ("id" "uuid" DEFAULT pg_catalog.gen_random_uuid() NOT NULL, "n" "text" DEFAULT pg_catalog.lower('X'));"# + ), + "create table public.t ( + id uuid default pg_catalog.gen_random_uuid() not null, + n text default pg_catalog.lower('X') +);" + ); +} + +#[test] +fn pg_catalog_qualification_of_a_type_is_kept() { + assert_eq!( + format("SELECT CAST(x AS pg_catalog.text), CAST(y AS pg_catalog.int4), CAST(z AS int4)"), + "select cast(x as pg_catalog.text), cast(y as int), cast(z as int4);" + ); +} + +#[test] +fn sql_standard_syntax_stays_unqualified() { + assert_eq!( + format( + "SELECT EXTRACT(year FROM d), SUBSTRING(s FROM 2 FOR 3), TRIM(BOTH 'x' FROM s), \ + POSITION('a' IN s), (ts AT TIME ZONE 'UTC'), COLLATION FOR (s) FROM t" + ), + "select + extract(year from d), + substring(s from 2 for 3), + trim('x' from s), + position('a' in s), + (ts at time zone 'UTC'), + collation for (s) +from + t;" + ); +} + +#[test] +fn function_names_keep_their_case_and_quotes() { + assert_eq!( + format(r#"SELECT "now"(), NOW(), "MyFunc"(1), "coalesce"(a), public."select"(b)"#), + r#"select now(), now(), "MyFunc"(1), "coalesce"(a), public.select(b);"# + ); +} + +#[test] +fn dollar_quote_tag_and_body_are_kept() { + assert_eq!( + format( + r#"CREATE OR REPLACE FUNCTION "public"."reset_user_password"("p_user_id" "uuid", "p_password" "text") RETURNS boolean + LANGUAGE "plpgsql" SECURITY DEFINER + SET "search_path" TO '' + AS $$ +BEGIN + RETURN true; +END +$$;"# + ), + "create or replace function public.reset_user_password(p_user_id uuid, p_password text) +returns boolean +language plpgsql +security definer +set search_path to '' +as $$ +BEGIN + RETURN true; +END +$$;" + ); +} + +#[test] +fn a_custom_dollar_quote_tag_and_a_single_line_body_are_kept() { + assert_eq!( + format( + "CREATE FUNCTION f() RETURNS int LANGUAGE plpgsql AS $body$ begin return 1; end $body$" + ), + "create function f() +returns int +language plpgsql +as $body$ begin return 1; end $body$;" + ); + assert_eq!( + format("DO $do$ BEGIN PERFORM 1; END $do$"), + "do $do$ BEGIN PERFORM 1; END $do$;" + ); +} + +#[test] +fn a_quoted_body_keeps_its_quotes() { + assert_eq!( + format("CREATE FUNCTION f() RETURNS int LANGUAGE sql AS 'SELECT ''a''::text'"), + "create function f() +returns int +language sql +as 'SELECT ''a''::text';" + ); +} + +#[test] +fn signatures_keep_argument_names_and_modes() { + assert_eq!( + format( + r#"ALTER FUNCTION "public"."reset_user_password"("p_user_id" "uuid", "p_password" "text") OWNER TO "postgres";"# + ), + "alter function public.reset_user_password(p_user_id uuid, p_password text) owner to postgres;" + ); + assert_eq!( + format( + r#"REVOKE ALL ON FUNCTION "public"."reset_user_password"("p_user_id" "uuid", "p_password" "text") FROM PUBLIC;"# + ), + "revoke all on function public.reset_user_password(p_user_id uuid, p_password text) from public;" + ); + assert_eq!( + format( + r#"GRANT EXECUTE ON FUNCTION "public"."reset_user_password"("p_user_id" "uuid", "p_password" "text") TO "retool";"# + ), + "grant execute on function public.reset_user_password(p_user_id uuid, p_password text) to retool;" + ); + assert_eq!( + format("DROP FUNCTION f(IN a int, OUT b text, VARIADIC c int[])"), + "drop function f(in a int, out b text, variadic c int[]);" + ); +} + +#[test] +fn privileges_follow_the_keyword_case() { + assert_eq!( + format("GRANT SELECT, INSERT, USAGE, TRUNCATE ON TABLE t TO r"), + "grant select, insert, usage, truncate on table t to r;" + ); +} + +#[test] +fn constraint_and_index_names_lose_redundant_quotes_only() { + assert_eq!( + format( + r#"ALTER TABLE ONLY "public"."organisation_vocabulary" ADD CONSTRAINT "organisation_vocabulary_pkey" PRIMARY KEY ("id");"# + ), + "alter table only public.organisation_vocabulary + add constraint organisation_vocabulary_pkey primary key (id);" + ); + assert_eq!( + format(r#"CREATE INDEX "Idx_Mixed" ON "user" ("select", "Name")"#), + r#"create index "Idx_Mixed" on "user" using btree ("select", "Name");"# + ); +} + +#[test] +fn column_definitions_stay_on_one_line_when_they_fit() { + assert_eq!( + format( + r#"CREATE TABLE IF NOT EXISTS "public"."organisation_vocabulary" ( + "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL, + "organisation_id" "uuid" DEFAULT "private"."current_organisation_id"() NOT NULL, + "value" "extensions"."citext" NOT NULL, + "pronunciations" "text"[], + "language" "text" NOT NULL, + "intensity" numeric DEFAULT 0.5 NOT NULL, + "created_at" timestamp with time zone DEFAULT "now"() NOT NULL, + "updated_at" timestamp with time zone DEFAULT "now"() NOT NULL +);"# + ), + "create table if not exists public.organisation_vocabulary ( + id uuid default gen_random_uuid() not null, + organisation_id uuid default private.current_organisation_id() not null, + value extensions.citext not null, + pronunciations text[], + language text not null, + intensity numeric default 0.5 not null, + created_at timestamp with time zone default now() not null, + updated_at timestamp with time zone default now() not null +);" + ); +} + +#[test] +fn a_broken_column_definition_continues_one_level_deeper() { + assert_eq!( + format( + "CREATE TABLE t (organisation_id uuid DEFAULT private.current_organisation_id_of_the_signed_in_user_or_the_default() NOT NULL)" + ), + "create table t ( + organisation_id uuid + default private.current_organisation_id_of_the_signed_in_user_or_the_default() + not null +);" + ); +} + +#[test] +fn constraint_columns_break_inside_their_parentheses() { + assert_eq!( + format( + r#"ALTER TABLE ONLY "public"."organisation_vocabulary" + ADD CONSTRAINT "organisation_vocabulary_org_value_lang_unique" UNIQUE ("organisation_id", "value", "language");"# + ), + "alter table only public.organisation_vocabulary + add constraint organisation_vocabulary_org_value_lang_unique unique ( + organisation_id, + value, + language + );" + ); + assert_eq!( + format( + r#"ALTER TABLE ONLY "public"."vocabulary" ADD CONSTRAINT "vocabulary_unique" UNIQUE ("organisation_id", "value", "language");"# + ), + "alter table only public.vocabulary + add constraint vocabulary_unique unique (organisation_id, value, language);" + ); +} + +#[test] +fn create_index_keeps_its_head_opclass_and_short_predicate_together() { + assert_eq!( + format( + r#"CREATE INDEX "idx_contact_org_search" ON "public"."contact" USING gin ( + "organisation_id" extensions.uuid_ops, + ( public.search_text("display_name", "full_name", "username", "email", "sms", "whatsapp", "instagram", + "facebook", "google_business_messaging", "postal", "external_id", "secondary_external_id", "description") ) extensions.gin_trgm_ops +) +WHERE "deleted_at" IS NULL;"# + ), + "create index idx_contact_org_search on public.contact using gin ( + organisation_id extensions.uuid_ops, + (public.search_text( + display_name, + full_name, + username, + email, + sms, + whatsapp, + instagram, + facebook, + google_business_messaging, + postal, + external_id, + secondary_external_id, + description + )) extensions.gin_trgm_ops +) +where deleted_at is null;" + ); + assert_eq!( + format(r#"CREATE INDEX "idx_t_a" ON "public"."t" USING btree ("a") WHERE "b" IS NULL;"#), + "create index idx_t_a on public.t using btree (a) where b is null;" + ); +} + +#[test] +fn end_of_line_comments_stay_on_their_line() { + assert_eq!( + format( + r#"create table "public"."t" ( + "id" "uuid" not null, -- trailing comment on column + /* block comment */ "n" "text" +);"# + ), + "create table public.t ( + id uuid not null, -- trailing comment on column + /* block comment */ n text +);" + ); + assert_eq!( + format("select f(a, b), -- after a call\n c as x, -- after an alias\n d from t"), + "select + f(a, b), -- after a call + c as x, -- after an alias + d +from + t;" + ); +} + +#[test] +fn set_values_keep_their_case() { + assert_eq!( + format("SET search_path TO 'MySchema', public"), + "set search_path to 'MySchema', public;" + ); + assert_eq!( + format("SET datestyle = 'German'"), + "set datestyle = 'German';" + ); +} diff --git a/crates/pgls_pretty_print/tests/tests.rs b/crates/pgls_pretty_print/tests/tests.rs index c2cd8105d..cc7a34d02 100644 --- a/crates/pgls_pretty_print/tests/tests.rs +++ b/crates/pgls_pretty_print/tests/tests.rs @@ -153,7 +153,7 @@ fn test_single(fixture: Fixture<&str>) { // The emitter gets the fixture config, not the default one: an option that decides which // tokens exist is read here, before the renderer ever sees the events. - let mut emitter = EventEmitter::new(fixture_config.clone()); + let mut emitter = EventEmitter::new(fixture_config.clone()).with_source(&content); emit_node_enum(&ast, &mut emitter); let mut output = String::new(); @@ -242,7 +242,7 @@ fn test_multi(fixture: Fixture<&str>) { // The emitter gets the fixture config, not the default one: an option that decides // which tokens exist is read here, before the renderer ever sees the events. - let mut emitter = EventEmitter::new(fixture_config.clone()); + let mut emitter = EventEmitter::new(fixture_config.clone()).with_source(trimmed); emit_node_enum(&ast, &mut emitter); let mut output = String::new(); diff --git a/crates/pgls_pretty_print_codegen/src/keywords.rs b/crates/pgls_pretty_print_codegen/src/keywords.rs index 8e5c5aad6..a129b4b3e 100644 --- a/crates/pgls_pretty_print_codegen/src/keywords.rs +++ b/crates/pgls_pretty_print_codegen/src/keywords.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Ok, Result}; use std::path; -fn parse_header() -> Result> { +fn parse_header() -> Result> { // use the environment variable set by the build script to locate the kwlist.h file let kwlist_file = path::PathBuf::from(env!("PG_QUERY_KWLIST_PATH")); let data = std::fs::read_to_string(kwlist_file).context("Failed to read kwlist.h")?; @@ -19,9 +19,9 @@ fn parse_header() -> Result> { let row_items: Vec<&str> = line.split(',').collect(); match row_items[..] { - [name, _value, _category, _is_bare_label] => { + [name, _value, category, _is_bare_label] => { let name = name.trim().replace('\"', ""); - keywords.push(name); + keywords.push((name, category.trim().to_string())); } _ => anyhow::bail!("Problem reading kwlist.h row"), } @@ -33,11 +33,17 @@ fn parse_header() -> Result> { pub(crate) struct KeywordKinds { pub(crate) all_keywords: Vec, + /// Every keyword with its grammar category from kwlist.h, such as `RESERVED_KEYWORD`. + pub(crate) categories: Vec<(String, String)>, } pub(crate) fn keyword_kinds() -> Result { - let mut all_keywords = parse_header()?; - all_keywords.sort(); - - Ok(KeywordKinds { all_keywords }) + let mut categories = parse_header()?; + categories.sort(); + let all_keywords = categories.iter().map(|(name, _)| name.clone()).collect(); + + Ok(KeywordKinds { + all_keywords, + categories, + }) } diff --git a/crates/pgls_pretty_print_codegen/src/token_kind.rs b/crates/pgls_pretty_print_codegen/src/token_kind.rs index 137d804f1..75631424c 100644 --- a/crates/pgls_pretty_print_codegen/src/token_kind.rs +++ b/crates/pgls_pretty_print_codegen/src/token_kind.rs @@ -35,6 +35,7 @@ const LITERALS: &[&str] = &[ "IDENT", "BOOLEAN", "TYPE_IDENT", // Data type names (text, varchar, int, etc.) + "WORD", // Words read case-insensitively that are not keywords, such as privilege names ]; const VARIANT_DATA: &[(&str, &str)] = &[ @@ -52,12 +53,33 @@ const VARIANT_DATA: &[(&str, &str)] = &[ ("COMMENT", "String"), // /* comment text */ ("BOOLEAN", "bool"), // true, false ("TYPE_IDENT", "String"), // text, varchar, int (data type names) + ("WORD", "String"), // usage, maintain (rendered with the keyword case) ]; pub fn token_kind_mod() -> proc_macro2::TokenStream { let keywords = keyword_kinds().expect("Failed to get keyword kinds"); - let KeywordKinds { all_keywords, .. } = keywords; + let KeywordKinds { + all_keywords, + categories, + } = keywords; + + let category_match_arms: Vec = categories + .iter() + .map(|(name, category)| { + let variant = format_ident!( + "{}", + match category.as_str() { + "UNRESERVED_KEYWORD" => "Unreserved", + "COL_NAME_KEYWORD" => "ColName", + "TYPE_FUNC_NAME_KEYWORD" => "TypeFuncName", + "RESERVED_KEYWORD" => "Reserved", + other => panic!("unknown keyword category {other}"), + } + ); + quote! { #name => Some(KeywordCategory::#variant) } + }) + .collect(); let mut enum_variants: Vec = Vec::new(); let mut from_kw_match_arms: Vec = Vec::new(); @@ -124,6 +146,28 @@ pub fn token_kind_mod() -> proc_macro2::TokenStream { #(#enum_variants),*, } + /// The grammar category of a keyword, which decides where it can be used as a name. + #[derive(Clone, Copy, PartialEq, Eq, Debug)] + pub enum KeywordCategory { + /// Usable as any name. + Unreserved, + /// Usable as a column or table name, but not as a function or type name. + ColName, + /// Usable as a function or type name, but not as a column or table name. + TypeFuncName, + /// Only usable as a column label (after `AS`) or when quoted. + Reserved, + } + + /// Returns the category of `ident` when it is a keyword. `ident` must be lowercase, the + /// way the parser stores an unquoted name. + pub fn keyword_category(ident: &str) -> Option { + match ident { + #(#category_match_arms),*, + _ => None + } + } + impl TokenKind { pub(crate) fn from_keyword(ident: &str) -> Option { let lower_ident = ident.to_ascii_lowercase(); @@ -151,6 +195,10 @@ pub fn token_kind_mod() -> proc_macro2::TokenStream { crate::renderer::KeywordCase::Upper => type_name.to_uppercase(), crate::renderer::KeywordCase::Lower => type_name.to_lowercase(), }, + TokenKind::WORD(word) => match config.keyword_case { + crate::renderer::KeywordCase::Upper => word.to_uppercase(), + crate::renderer::KeywordCase::Lower => word.to_lowercase(), + }, TokenKind::STRING(s) => s.clone(), TokenKind::ESC_STRING(s) => s.clone(), TokenKind::DOLLAR_QUOTED_STRING(s) => s.clone(), diff --git a/crates/pgls_workspace/src/workspace/server.rs b/crates/pgls_workspace/src/workspace/server.rs index e66a8c225..400f19936 100644 --- a/crates/pgls_workspace/src/workspace/server.rs +++ b/crates/pgls_workspace/src/workspace/server.rs @@ -1104,7 +1104,12 @@ impl Workspace for WorkspaceServer { continue; }; - formatted_sql_fn_bodies.insert(parent_id, formatted); + // A body that formatting leaves alone keeps its own layout. A reformatted one + // goes on the lines between its dollar quotes. + if formatted.trim() == text.trim() { + continue; + } + formatted_sql_fn_bodies.insert(parent_id, format!("\n{formatted}\n")); } } @@ -1115,6 +1120,9 @@ impl Workspace for WorkspaceServer { let source = doc.get_document_content(); let mut last_end = 0usize; + // Formatting a range leaves everything outside its statements as written. + let normalize_gaps = params.range.is_none(); + for (id, stmt_range, text, ast_result) in format_candidates { if id.is_child() { continue; @@ -1123,9 +1131,19 @@ impl Workspace for WorkspaceServer { let stmt_start = usize::from(stmt_range.start()); let stmt_end = usize::from(stmt_range.end()); - // Preserve leading text, blank lines, and standalone comments that precede - // this statement. - formatted_output.push_str(&source[last_end..stmt_start]); + // Preserve the standalone comments that precede this statement, with at most one + // blank line between statements and none before the first. + let gap = &source[last_end..stmt_start]; + if normalize_gaps { + let position = if last_end == 0 { + GapPosition::Start + } else { + GapPosition::Between + }; + formatted_output.push_str(&normalize_gap(gap, position)); + } else { + formatted_output.push_str(gap); + } last_end = stmt_end; // Leave statements outside the requested range untouched. @@ -1197,7 +1215,16 @@ impl Workspace for WorkspaceServer { } // Preserve any trailing text or comments after the last statement. - formatted_output.push_str(&source[last_end..]); + if normalize_gaps { + let position = if last_end == 0 { + GapPosition::Whole + } else { + GapPosition::End + }; + formatted_output.push_str(&normalize_gap(&source[last_end..], position)); + } else { + formatted_output.push_str(&source[last_end..]); + } Ok(PullFormattingResult { original: doc.get_document_content().to_string(), @@ -1367,6 +1394,76 @@ fn is_dir(path: &Path) -> bool { path.is_dir() || (path.is_symlink() && fs::read_link(path).is_ok_and(|path| path.is_dir())) } +/// Where the text between two statements sits in the file. +#[derive(Clone, Copy, PartialEq, Eq)] +enum GapPosition { + /// Before the first statement. + Start, + /// Between two statements. + Between, + /// After the last statement. + End, + /// The whole file, which has no statement. + Whole, +} + +/// Normalizes the blank lines in the text between statements, which only holds whitespace and +/// comments: at most one blank line between two statements, and none at the start or the end of +/// the file. Comments and the line breaks around them are kept, and so is the final line break. +fn normalize_gap(gap: &str, position: GapPosition) -> String { + let at_start = matches!(position, GapPosition::Start | GapPosition::Whole); + let at_end = matches!(position, GapPosition::End | GapPosition::Whole); + + let mut lines: Vec<&str> = gap.split('\n').collect(); + // Without a line break the gap sits inside one line, between two statements for instance. + if lines.len() == 1 { + return match (at_start, at_end) { + (_, true) => gap.trim_end().to_string(), + (true, false) => String::new(), + (false, false) => gap.to_string(), + }; + } + + // The first line ends the line of the previous statement and the last one starts the line of + // the next statement. Only the lines in between are whole lines. + let first = lines.remove(0); + let last = lines.pop().unwrap_or_default(); + + let mut kept: Vec<&str> = Vec::new(); + if !(at_start && first.trim().is_empty()) { + kept.push(first); + } + // Whether the last kept line is a blank one, which the first line never is. + let mut follows_blank = false; + for line in lines { + let is_blank = line.trim().is_empty(); + if is_blank && (follows_blank || kept.is_empty()) { + continue; + } + kept.push(if is_blank { "" } else { line }); + follows_blank = is_blank; + } + + if at_end { + if follows_blank { + kept.pop(); + } + let mut result = kept.join("\n"); + if last.trim().is_empty() { + result.push('\n'); + } else { + if !kept.is_empty() { + result.push('\n'); + } + result.push_str(last); + } + return result; + } + + kept.push(last); + kept.join("\n") +} + /// Put psql named parameters back where the formatter printed their placeholders. /// /// The parser only ever sees placeholders, so the printed statement carries `$1` or a bare diff --git a/crates/pgls_workspace/src/workspace/server.tests.rs b/crates/pgls_workspace/src/workspace/server.tests.rs index a82fa8be7..be11f5d9c 100644 --- a/crates/pgls_workspace/src/workspace/server.tests.rs +++ b/crates/pgls_workspace/src/workspace/server.tests.rs @@ -1220,6 +1220,60 @@ async fn test_format_preserves_comment_in_sql_function_body() { ); } +#[tokio::test] +async fn test_format_normalizes_blank_lines_between_statements() { + let formatted = format_content("\n\n\nselect 1;\n\n\n\nselect 2;\n\n\n"); + assert_eq!(formatted, "select 1;\n\nselect 2;\n"); +} + +#[tokio::test] +async fn test_format_keeps_comments_when_normalizing_blank_lines() { + let formatted = format_content( + "\n\n-- header\n\n\nselect 1; -- one\n\n\n-- about two\nselect 2;\n\n\n-- footer\n\n", + ); + assert_eq!( + formatted, + "-- header\n\nselect 1; -- one\n\n-- about two\nselect 2;\n\n-- footer\n" + ); +} + +#[tokio::test] +async fn test_format_keeps_statements_on_one_line_apart() { + let formatted = format_content("select 1; select 2;"); + assert_eq!(formatted, "select 1; select 2;"); +} + +#[tokio::test] +async fn test_format_keeps_plpgsql_body_and_dollar_quote_tag() { + let content = "CREATE FUNCTION f() RETURNS boolean LANGUAGE plpgsql AS $$\nBEGIN\n RETURN true;\nEND\n$$;"; + let formatted = format_content(content); + assert_eq!( + formatted, + "create function f()\nreturns boolean\nlanguage plpgsql\nas $$\nBEGIN\n RETURN true;\nEND\n$$;" + ); +} + +#[tokio::test] +async fn test_format_keeps_formatted_sql_function_body_as_written() { + let content = "create function f() returns int language sql as $body$\n select 1;\n$body$;"; + let formatted = format_content(content); + assert_eq!( + formatted, + "create function f()\nreturns int\nlanguage sql\nas $body$\n select 1;\n$body$;" + ); +} + +#[tokio::test] +async fn test_format_puts_reformatted_sql_function_body_on_its_own_lines() { + let content = "create function f() returns int language sql as $body$SELECT 1$body$;"; + let formatted = format_content(content); + assert_eq!( + formatted, + "create function f()\nreturns int\nlanguage sql\nas $body$\nselect 1;\n$body$;" + ); + assert_eq!(format_content(&formatted), formatted); +} + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] async fn test_cstyle_comments(test_db: PgPool) { let mut conf = PartialConfiguration::init(); diff --git a/docs/features/formatting.md b/docs/features/formatting.md index d4fea5581..7d30242c2 100644 --- a/docs/features/formatting.md +++ b/docs/features/formatting.md @@ -2,11 +2,21 @@ > **Preview Feature**: The formatter is currently in preview. We'd love feedback from early adopters! Please report any issues or unexpected output at [GitHub Issues](https://github.com/supabase-community/postgres-language-server/issues). -## Known Limitations - The language server provides SQL formatting that produces consistent, readable code. Built on Postgres' own parser, the formatter ensures 100% syntax compatibility with your SQL. -Comments are not processed during formatting. They get removed before formatting and restored after. +## What the formatter changes + +The formatter changes whitespace, line breaks, the case of keywords, types and constants, and quotes that an identifier does not need. It does not change what is written: + +- Schema qualifiers stay as written, `pg_catalog.` included. +- Function bodies, their dollar-quote tags (`$$`, `$body$`, ...) and string literals are kept byte for byte. Only `language sql` bodies are reformatted, unless `skipFnBodies` is set. +- Function signatures keep their argument names and modes, in `ALTER FUNCTION`, `GRANT` and `DROP` as well. +- Identifiers that need quotes keep them: mixed case, reserved words such as `"user"`, and special characters. +- Comments stay where they were written, including comments at the end of a line. + +The formatter checks every statement: if the formatted statement would not parse to the same tree as the original, the statement is left as written and a diagnostic is reported. + +Between statements, the formatter keeps at most one blank line, and removes blank lines at the start and the end of the file. ## Configuration @@ -107,7 +117,7 @@ SELECT * FROM users WHERE active = TRUE; Format files using the CLI: ```bash -# Format and show diff +# Check formatting and show a diff for every statement that would change postgres-language-server format file.sql # Format and write changes @@ -117,10 +127,43 @@ postgres-language-server format file.sql --write postgres-language-server format migrations/ --write ``` +### Check mode + +Without `--write`, `format` does not modify any file. For every statement that would be reformatted it prints a diagnostic with the file path and a diff to stderr, followed by a summary (`Processed N files ... Found N errors.`). The command exits with a non-zero code if any file is not formatted or could not be formatted (e.g. because of a syntax error), and with `0` otherwise. This makes it suitable for CI: + +```bash +postgres-language-server format migrations/ +``` + +`--staged` and `--changed` (optionally with `--since=`) limit the run to the files staged for commit or changed compared to your default branch. + +### Formatting stdin + +Use `--stdin-file-path=` to format SQL piped through stdin, for example from an editor or a script. Only the formatted SQL is printed to stdout: + +```bash +echo "SELECT a,b FROM t;" | postgres-language-server format --stdin-file-path=query.sql +# select a, b from t; +``` + +The file doesn't need to exist. Its path is used to apply the project configuration (for example, a path matching `files.ignore` is printed back unchanged) and to label diagnostics. If a statement cannot be formatted, it is printed unchanged, its diagnostics are written to stderr, and the command exits with a non-zero code. When the formatter is disabled, the input is printed unchanged. `--stdin-file-path` cannot be combined with file paths, `--write`, `--staged` or `--changed`. + ## Editor Integration The formatter integrates with your editor via the Language Server Protocol. Use your editor's format document command (typically bound to a keyboard shortcut) to format SQL files. +## JavaScript API + +The `@postgres-language-server/wasm` package formats SQL in-process, with the same options as the `format` section of the configuration file: + +```typescript +import { format } from "@postgres-language-server/wasm"; + +const sql = await format('CREATE TABLE "public"."t" ("id" "uuid" NOT NULL)', { + keywordCase: "lower", +}); +``` + ## Ignoring Files Use the `ignore` and `include` options to control which files are formatted: From 0f338ff053ab8bf6f7bb23d8f010bf8448380fd5 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 12 Oct 2026 15:10:49 +0000 Subject: [PATCH 2/7] feat(cli): format stdin and report blank-line changes in check mode format --stdin-file-path= reads SQL from stdin, applies the configuration for and prints only the formatted SQL. Check mode now also fails for files whose only change is between statements. --- crates/pgls_cli/src/commands/check.rs | 22 +-- crates/pgls_cli/src/commands/format.rs | 28 +++- crates/pgls_cli/src/commands/mod.rs | 26 +++ crates/pgls_cli/src/execute/mod.rs | 1 - .../src/execute/process_file/format.rs | 14 ++ crates/pgls_cli/src/execute/stdin.rs | 73 ++++++++- crates/pgls_cli/src/lib.rs | 2 + crates/pgls_cli/tests/assert_format.rs | 149 ++++++++++++++++++ .../tests/fixtures/format/blank_lines.sql | 5 + .../tests/fixtures/format/formatted.sql | 1 + .../tests/fixtures/format/unformatted.sql | 1 + ...__format_stdin_rejects_paths_snapshot.snap | 11 ++ ...__format_stdin_rejects_write_snapshot.snap | 11 ++ .../assert_format__format_stdin_snapshot.snap | 11 ++ ...rmat_stdin_with_syntax_error_snapshot.snap | 22 +++ ...te_reports_extra_blank_lines_snapshot.snap | 24 +++ ...te_reports_unformatted_files_snapshot.snap | 20 +++ ..._succeeds_on_formatted_files_snapshot.snap | 8 + docs/reference/cli.md | 6 + 19 files changed, 407 insertions(+), 28 deletions(-) create mode 100644 crates/pgls_cli/tests/assert_format.rs create mode 100644 crates/pgls_cli/tests/fixtures/format/blank_lines.sql create mode 100644 crates/pgls_cli/tests/fixtures/format/formatted.sql create mode 100644 crates/pgls_cli/tests/fixtures/format/unformatted.sql create mode 100644 crates/pgls_cli/tests/snapshots/assert_format__format_stdin_rejects_paths_snapshot.snap create mode 100644 crates/pgls_cli/tests/snapshots/assert_format__format_stdin_rejects_write_snapshot.snap create mode 100644 crates/pgls_cli/tests/snapshots/assert_format__format_stdin_snapshot.snap create mode 100644 crates/pgls_cli/tests/snapshots/assert_format__format_stdin_with_syntax_error_snapshot.snap create mode 100644 crates/pgls_cli/tests/snapshots/assert_format__format_without_write_reports_extra_blank_lines_snapshot.snap create mode 100644 crates/pgls_cli/tests/snapshots/assert_format__format_without_write_reports_unformatted_files_snapshot.snap create mode 100644 crates/pgls_cli/tests/snapshots/assert_format__format_without_write_succeeds_on_formatted_files_snapshot.snap diff --git a/crates/pgls_cli/src/commands/check.rs b/crates/pgls_cli/src/commands/check.rs index 8a2b1cd6a..7553d1ce7 100644 --- a/crates/pgls_cli/src/commands/check.rs +++ b/crates/pgls_cli/src/commands/check.rs @@ -1,12 +1,11 @@ use crate::cli_options::CliOptions; -use crate::commands::get_files_to_process_with_cli_options; +use crate::commands::{get_files_to_process_with_cli_options, read_stdin_payload}; use crate::diagnostics::DatabaseUnavailable; -use crate::execute::{StdinPayload, run_files, run_stdin}; +use crate::execute::{run_files, run_stdin}; use crate::reporter::Report; use crate::{CliDiagnostic, CliSession, VcsIntegration}; use crate::{ExecutionConfig, ExecutionMode, VcsTargeting}; use pgls_configuration::PartialConfiguration; -use pgls_console::Console; use pgls_diagnostics::{Error, category}; use pgls_fs::FileSystem; use pgls_workspace::DynRef; @@ -49,7 +48,7 @@ pub fn check( let execution = ExecutionConfig::new(mode, max_diagnostics); if let Some(stdin_path) = args.stdin_file_path.as_deref() { - let payload = read_stdin_payload(stdin_path, session.console())?; + let payload = read_stdin_payload(stdin_path, session.console(), "check")?; run_stdin(&mut session, &execution, payload) } else { let database_error = check_database_connection(&session)?; @@ -99,21 +98,6 @@ fn resolve_paths( Ok(paths) } -fn read_stdin_payload( - path: &str, - console: &mut dyn Console, -) -> Result { - let input_code = console.read(); - if let Some(input_code) = input_code { - Ok(StdinPayload { - path: path.into(), - content: input_code, - }) - } else { - Err(CliDiagnostic::missing_argument("stdin", "check")) - } -} - fn enforce_exit_codes(cli_options: &CliOptions, payload: &Report) -> Result<(), CliDiagnostic> { let traversal = payload.traversal.as_ref(); let processed = traversal.map_or(0, |t| t.changed + t.unchanged); diff --git a/crates/pgls_cli/src/commands/format.rs b/crates/pgls_cli/src/commands/format.rs index cc7d5b4a3..df6095f83 100644 --- a/crates/pgls_cli/src/commands/format.rs +++ b/crates/pgls_cli/src/commands/format.rs @@ -1,6 +1,6 @@ use crate::cli_options::CliOptions; -use crate::commands::get_files_to_process_with_cli_options; -use crate::execute::run_files; +use crate::commands::{get_files_to_process_with_cli_options, read_stdin_payload}; +use crate::execute::{run_files, run_stdin}; use crate::reporter::Report; use crate::{CliDiagnostic, CliSession, VcsIntegration}; use crate::{ExecutionConfig, ExecutionMode, VcsTargeting}; @@ -14,6 +14,7 @@ pub struct FormatArgs { pub configuration: Option, pub paths: Vec, pub write: bool, + pub stdin_file_path: Option, pub staged: bool, pub changed: bool, pub since: Option, @@ -29,8 +30,6 @@ pub fn format( let configuration = session.prepare_with_config(cli_options, args.configuration.clone())?; session.setup_workspace(configuration.clone(), VcsIntegration::Enabled)?; - let paths = resolve_paths(session.fs(), &configuration, &args)?; - let vcs = VcsTargeting { staged: args.staged, changed: args.changed, @@ -42,6 +41,12 @@ pub fn format( }; let execution = ExecutionConfig::new(mode, u32::MAX); + if let Some(stdin_path) = args.stdin_file_path.as_deref() { + let payload = read_stdin_payload(stdin_path, session.console(), "format")?; + return run_stdin(&mut session, &execution, payload); + } + + let paths = resolve_paths(session.fs(), &configuration, &args)?; let report: Report = run_files(&mut session, &execution, paths)?; let exit_result = enforce_exit_codes(cli_options, &report); @@ -92,6 +97,21 @@ fn enforce_exit_codes(cli_options: &CliOptions, payload: &Report) -> Result<(), } fn validate_args(args: &FormatArgs) -> Result<(), CliDiagnostic> { + if args.stdin_file_path.is_some() { + let incompatible = [ + ("PATH", !args.paths.is_empty()), + ("write", args.write), + ("staged", args.staged), + ("changed", args.changed), + ]; + if let Some((argument, _)) = incompatible.iter().find(|(_, is_set)| *is_set) { + return Err(CliDiagnostic::incompatible_arguments( + "stdin-file-path", + *argument, + )); + } + } + if args.since.is_some() { if !args.changed { return Err(CliDiagnostic::incompatible_arguments("since", "changed")); diff --git a/crates/pgls_cli/src/commands/mod.rs b/crates/pgls_cli/src/commands/mod.rs index ea63f6276..9d609ec2d 100644 --- a/crates/pgls_cli/src/commands/mod.rs +++ b/crates/pgls_cli/src/commands/mod.rs @@ -1,9 +1,11 @@ use crate::changed::{get_changed_files, get_staged_files}; use crate::cli_options::{CliOptions, CliReporter, ColorsArg, cli_options}; +use crate::execute::StdinPayload; use crate::logging::LoggingKind; use crate::{CliDiagnostic, LoggingLevel, VERSION}; use bpaf::Bpaf; use pgls_configuration::{PartialConfiguration, partial_configuration}; +use pgls_console::Console; use pgls_fs::FileSystem; use pgls_workspace::DynRef; use std::ffi::OsString; @@ -87,6 +89,15 @@ pub enum PgLSCommand { #[bpaf(long("write"), switch)] write: bool, + /// Use this option when you want to format code piped from `stdin`, and print the output to `stdout`. + /// + /// The file doesn't need to exist on disk. The path is used to resolve the configuration + /// (e.g. ignored files) and to label diagnostics, which are printed to `stderr`. + /// + /// Example: `echo 'select 1' | postgres-language-server format --stdin-file-path=test.sql` + #[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)] + stdin_file_path: Option, + /// When set to true, only the files that have been staged (the ones prepared to be committed) /// will be formatted. This option should be used when working locally. #[bpaf(long("staged"), switch)] @@ -373,6 +384,21 @@ pub(crate) fn get_files_to_process_with_cli_options( } } +/// Reads the code piped to `stdin` for the given virtual file path. +pub(crate) fn read_stdin_payload( + path: &str, + console: &mut dyn Console, + subcommand: &str, +) -> Result { + match console.read() { + Some(content) => Ok(StdinPayload { + path: path.into(), + content, + }), + None => Err(CliDiagnostic::missing_argument("stdin", subcommand)), + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/pgls_cli/src/execute/mod.rs b/crates/pgls_cli/src/execute/mod.rs index b0485d362..3ef96fc9e 100644 --- a/crates/pgls_cli/src/execute/mod.rs +++ b/crates/pgls_cli/src/execute/mod.rs @@ -20,7 +20,6 @@ pub fn run_files( } pub struct StdinPayload { - #[allow(dead_code)] pub path: PathBuf, pub content: String, } diff --git a/crates/pgls_cli/src/execute/process_file/format.rs b/crates/pgls_cli/src/execute/process_file/format.rs index f1e9bc276..84dd610b1 100644 --- a/crates/pgls_cli/src/execute/process_file/format.rs +++ b/crates/pgls_cli/src/execute/process_file/format.rs @@ -62,6 +62,8 @@ fn format_with_guard<'ctx>( return Ok(FileStatus::Changed); } + let only_layout_between_statements = format_result.statements.is_empty(); + for stmt in format_result.statements { let diff = pgls_text_edit::TextEdit::from_unicode_words(&stmt.original, &stmt.formatted); let start_byte: usize = stmt.range.start().into(); @@ -76,6 +78,18 @@ fn format_with_guard<'ctx>( })); } + // Only the blank lines between statements change: show the whole file. + if only_layout_between_statements && format_result.original != format_result.formatted { + diagnostics.push(pgls_diagnostics::Error::from(FormatDiffDiagnostic { + file_name: path.display().to_string(), + diff: pgls_text_edit::TextEdit::from_unicode_words( + &format_result.original, + &format_result.formatted, + ), + start_line: 0, + })); + } + if diagnostics.is_empty() { Ok(FileStatus::Unchanged) } else { diff --git a/crates/pgls_cli/src/execute/stdin.rs b/crates/pgls_cli/src/execute/stdin.rs index d04a43039..3cea052d3 100644 --- a/crates/pgls_cli/src/execute/stdin.rs +++ b/crates/pgls_cli/src/execute/stdin.rs @@ -1,13 +1,78 @@ use crate::execute::StdinPayload; -use crate::execute::config::ExecutionConfig; +use crate::execute::config::{ExecutionConfig, ExecutionMode}; use crate::{CliDiagnostic, CliSession}; use pgls_console::{ConsoleExt, markup}; +use pgls_diagnostics::{DiagnosticExt, Error, PrintDiagnostic, category}; +use pgls_fs::PgLSPath; +use pgls_workspace::features::format::PullFileFormattingParams; +use pgls_workspace::workspace::{FileGuard, IsPathIgnoredParams, OpenFileParams}; pub(crate) fn process( session: &mut CliSession, - _config: &ExecutionConfig, + config: &ExecutionConfig, payload: StdinPayload, ) -> Result<(), CliDiagnostic> { - session.console().append(markup! {{payload.content}}); - Ok(()) + match config.mode { + ExecutionMode::Check { .. } => { + session.console().append(markup! {{payload.content}}); + Ok(()) + } + ExecutionMode::Format { .. } => format(session, payload), + } +} + +/// Formats the content read from stdin and prints only the formatted code to stdout. +/// +/// Diagnostics are printed to stderr. Statements that could not be formatted are kept as +/// they are, so stdout always contains the best-effort output. +fn format(session: &mut CliSession, payload: StdinPayload) -> Result<(), CliDiagnostic> { + let pgls_path = PgLSPath::new(&payload.path); + let workspace = session.workspace(); + + let is_ignored = workspace.is_path_ignored(IsPathIgnoredParams { + pgls_path: pgls_path.clone(), + })?; + if is_ignored { + session.console().append(markup! {{payload.content}}); + return Ok(()); + } + + let result = { + let guard = FileGuard::open( + workspace, + OpenFileParams { + path: pgls_path.clone(), + version: 0, + content: payload.content.clone(), + }, + )?; + guard.pull_file_formatting(PullFileFormattingParams { + path: pgls_path, + range: None, + })? + }; + + // The workspace returns an empty result when the formatter is disabled. + let output = if result.original == payload.content { + result.formatted + } else { + payload.content.clone() + }; + + let console = session.console(); + console.append(markup! {{output}}); + + if result.diagnostics.is_empty() { + return Ok(()); + } + + let file_name = payload.path.display().to_string(); + for diagnostic in result.diagnostics { + let diagnostic = Error::from(diagnostic) + .with_file_path(&file_name) + .with_file_source_code(&payload.content); + console.error(markup! {{PrintDiagnostic::simple(&diagnostic)}}); + } + + Err(CliDiagnostic::check_error(category!("format"))) } diff --git a/crates/pgls_cli/src/lib.rs b/crates/pgls_cli/src/lib.rs index 1270dc20e..4ac9d11c5 100644 --- a/crates/pgls_cli/src/lib.rs +++ b/crates/pgls_cli/src/lib.rs @@ -97,6 +97,7 @@ impl<'app> CliSession<'app> { configuration, paths, write, + stdin_file_path, staged, changed, since, @@ -107,6 +108,7 @@ impl<'app> CliSession<'app> { configuration, paths, write, + stdin_file_path, staged, changed, since, diff --git a/crates/pgls_cli/tests/assert_format.rs b/crates/pgls_cli/tests/assert_format.rs new file mode 100644 index 000000000..3a6c04914 --- /dev/null +++ b/crates/pgls_cli/tests/assert_format.rs @@ -0,0 +1,149 @@ +use assert_cmd::cargo_bin_cmd; +use insta::assert_snapshot; +use std::process::ExitStatus; + +const CONFIG_PATH: &str = "tests/fixtures/postgres-language-server.jsonc"; +const FORMATTED_PATH: &str = "tests/fixtures/format/formatted.sql"; +const UNFORMATTED_PATH: &str = "tests/fixtures/format/unformatted.sql"; +const BLANK_LINES_PATH: &str = "tests/fixtures/format/blank_lines.sql"; + +#[test] +#[cfg_attr( + target_os = "windows", + ignore = "snapshot expectations only validated on unix-like platforms" +)] +fn format_stdin_snapshot() { + assert_snapshot!(run_format_stdin( + &["--stdin-file-path", "virtual.sql"], + "SELECT a,b FROM t;\n\n-- keep me\nselect 1\n" + )); +} + +#[test] +#[cfg_attr( + target_os = "windows", + ignore = "snapshot expectations only validated on unix-like platforms" +)] +fn format_stdin_with_syntax_error_snapshot() { + assert_snapshot!(run_format_stdin( + &["--stdin-file-path", "virtual.sql"], + "SELECT a,b FROM t;\nselect from where;\n" + )); +} + +#[test] +#[cfg_attr( + target_os = "windows", + ignore = "snapshot expectations only validated on unix-like platforms" +)] +fn format_stdin_rejects_paths_snapshot() { + assert_snapshot!(run_format_stdin( + &["--stdin-file-path", "virtual.sql", UNFORMATTED_PATH], + "select 1;\n" + )); +} + +#[test] +#[cfg_attr( + target_os = "windows", + ignore = "snapshot expectations only validated on unix-like platforms" +)] +fn format_stdin_rejects_write_snapshot() { + assert_snapshot!(run_format_stdin( + &["--stdin-file-path", "virtual.sql", "--write"], + "select 1;\n" + )); +} + +#[test] +#[cfg_attr( + target_os = "windows", + ignore = "snapshot expectations only validated on unix-like platforms" +)] +fn format_without_write_reports_unformatted_files_snapshot() { + assert_snapshot!(run_format(&[FORMATTED_PATH, UNFORMATTED_PATH])); +} + +#[test] +#[cfg_attr( + target_os = "windows", + ignore = "snapshot expectations only validated on unix-like platforms" +)] +fn format_without_write_succeeds_on_formatted_files_snapshot() { + assert_snapshot!(run_format(&[FORMATTED_PATH])); +} + +#[test] +#[cfg_attr( + target_os = "windows", + ignore = "snapshot expectations only validated on unix-like platforms" +)] +fn format_without_write_reports_extra_blank_lines_snapshot() { + assert_snapshot!(run_format(&[BLANK_LINES_PATH])); +} + +fn run_format(args: &[&str]) -> String { + run_format_with(args, None) +} + +fn run_format_stdin(args: &[&str], stdin: &str) -> String { + run_format_with(args, Some(stdin)) +} + +fn run_format_with(args: &[&str], stdin: Option<&str>) -> String { + let mut cmd = cargo_bin_cmd!("postgres-language-server"); + if let Some(input) = stdin { + cmd.write_stdin(input); + } + + let mut full_args = vec![ + "format", + "--config-path", + CONFIG_PATH, + "--log-level", + "none", + ]; + full_args.extend_from_slice(args); + let output = cmd.args(full_args).output().expect("failed to run CLI"); + + normalize_output( + output.status, + &String::from_utf8_lossy(&output.stdout), + &String::from_utf8_lossy(&output.stderr), + ) +} + +/// Replaces the duration in the summary line (e.g. `Processed 1 file in 3.2ms.`). +fn normalize_durations(input: &str) -> String { + input + .lines() + .map(|line| { + let Some(start) = line.find(" in ").filter(|_| line.starts_with("Processed ")) else { + return line.to_string(); + }; + // The duration ends at the first period that is not a decimal point. + let rest = &line[start + 4..]; + let end = rest + .char_indices() + .find(|&(i, c)| { + c == '.' && !rest[i + 1..].starts_with(|c: char| c.is_ascii_digit()) + }) + .map_or(rest.len(), |(i, _)| i); + format!("{} in {}", &line[..start], &rest[end..]) + }) + .collect::>() + .join("\n") +} + +fn normalize_output(status: ExitStatus, stdout: &str, stderr: &str) -> String { + let status_label = if status.success() { + "success" + } else { + "failure" + }; + format!( + "status: {status_label}\nstdout:\n{}\nstderr:\n{}\n", + normalize_durations(stdout).trim_end(), + stderr.trim_end() + ) +} diff --git a/crates/pgls_cli/tests/fixtures/format/blank_lines.sql b/crates/pgls_cli/tests/fixtures/format/blank_lines.sql new file mode 100644 index 000000000..62e1fc12c --- /dev/null +++ b/crates/pgls_cli/tests/fixtures/format/blank_lines.sql @@ -0,0 +1,5 @@ +select 1; + + + +select 2; diff --git a/crates/pgls_cli/tests/fixtures/format/formatted.sql b/crates/pgls_cli/tests/fixtures/format/formatted.sql new file mode 100644 index 000000000..a2e369c73 --- /dev/null +++ b/crates/pgls_cli/tests/fixtures/format/formatted.sql @@ -0,0 +1 @@ +select a, b from t; diff --git a/crates/pgls_cli/tests/fixtures/format/unformatted.sql b/crates/pgls_cli/tests/fixtures/format/unformatted.sql new file mode 100644 index 000000000..fe0a20b6b --- /dev/null +++ b/crates/pgls_cli/tests/fixtures/format/unformatted.sql @@ -0,0 +1 @@ +SELECT a,b FROM t; diff --git a/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_rejects_paths_snapshot.snap b/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_rejects_paths_snapshot.snap new file mode 100644 index 000000000..70d1e9f48 --- /dev/null +++ b/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_rejects_paths_snapshot.snap @@ -0,0 +1,11 @@ +--- +source: crates/pgls_cli/tests/assert_format.rs +expression: "run_format_stdin(&[\"--stdin-file-path\", \"virtual.sql\", UNFORMATTED_PATH],\n\"select 1;\\n\")" +--- +status: failure +stdout: + +stderr: +flags/invalid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Incompatible arguments stdin-file-path and PATH diff --git a/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_rejects_write_snapshot.snap b/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_rejects_write_snapshot.snap new file mode 100644 index 000000000..8a739f4b4 --- /dev/null +++ b/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_rejects_write_snapshot.snap @@ -0,0 +1,11 @@ +--- +source: crates/pgls_cli/tests/assert_format.rs +expression: "run_format_stdin(&[\"--stdin-file-path\", \"virtual.sql\", \"--write\"],\n\"select 1;\\n\")" +--- +status: failure +stdout: + +stderr: +flags/invalid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Incompatible arguments stdin-file-path and write diff --git a/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_snapshot.snap b/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_snapshot.snap new file mode 100644 index 000000000..72a7ca646 --- /dev/null +++ b/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_snapshot.snap @@ -0,0 +1,11 @@ +--- +source: crates/pgls_cli/tests/assert_format.rs +expression: "run_format_stdin(&[\"--stdin-file-path\", \"virtual.sql\"],\n\"SELECT a,b FROM t;\\n\\n-- keep me\\nselect 1\\n\")" +--- +status: success +stdout: +select a, b from t; + +-- keep me +select 1; +stderr: diff --git a/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_with_syntax_error_snapshot.snap b/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_with_syntax_error_snapshot.snap new file mode 100644 index 000000000..ff50b09eb --- /dev/null +++ b/crates/pgls_cli/tests/snapshots/assert_format__format_stdin_with_syntax_error_snapshot.snap @@ -0,0 +1,22 @@ +--- +source: crates/pgls_cli/tests/assert_format.rs +expression: "run_format_stdin(&[\"--stdin-file-path\", \"virtual.sql\"],\n\"SELECT a,b FROM t;\\nselect from where;\\n\")" +--- +status: failure +stdout: +select a, b from t; +select from where; +stderr: +virtual.sql:2:1 syntax ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Invalid statement: syntax error at or near "where" + + 1 │ SELECT a,b FROM t; + > 2 │ select from where; + │ ^^^^^^^^^^^^^^^^^^ + 3 │ + + +format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Some errors were emitted while running checks. diff --git a/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_reports_extra_blank_lines_snapshot.snap b/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_reports_extra_blank_lines_snapshot.snap new file mode 100644 index 000000000..b7301f4af --- /dev/null +++ b/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_reports_extra_blank_lines_snapshot.snap @@ -0,0 +1,24 @@ +--- +source: crates/pgls_cli/tests/assert_format.rs +expression: "run_format(&[BLANK_LINES_PATH])" +--- +status: failure +stdout: +Processed 1 file in . No fixes applied. +Found 1 error. +stderr: +tests/fixtures/format/blank_lines.sql format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Statement could be formatted using `--write` + + 1 1 │ select 1; + 2 2 │ + 3 │ - + 4 │ - + 5 3 │ select 2; + 6 4 │ + + +format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Some errors were emitted while running checks. diff --git a/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_reports_unformatted_files_snapshot.snap b/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_reports_unformatted_files_snapshot.snap new file mode 100644 index 000000000..6c030cf1d --- /dev/null +++ b/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_reports_unformatted_files_snapshot.snap @@ -0,0 +1,20 @@ +--- +source: crates/pgls_cli/tests/assert_format.rs +expression: "run_format(&[FORMATTED_PATH, UNFORMATTED_PATH])" +--- +status: failure +stdout: +Processed 2 files in . No fixes applied. +Found 1 error. +stderr: +tests/fixtures/format/unformatted.sql format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Statement could be formatted using `--write` + + - SELECT·a,b·FROM·t; + + select·a,·b·from·t; + + +format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Some errors were emitted while running checks. diff --git a/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_succeeds_on_formatted_files_snapshot.snap b/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_succeeds_on_formatted_files_snapshot.snap new file mode 100644 index 000000000..0588e1422 --- /dev/null +++ b/crates/pgls_cli/tests/snapshots/assert_format__format_without_write_succeeds_on_formatted_files_snapshot.snap @@ -0,0 +1,8 @@ +--- +source: crates/pgls_cli/tests/assert_format.rs +expression: "run_format(&[FORMATTED_PATH])" +--- +status: success +stdout: +Processed 1 file in . No fixes applied. +stderr: diff --git a/docs/reference/cli.md b/docs/reference/cli.md index c9ff05345..fe6da651a 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -490,6 +490,12 @@ Formats the requested files. **Available options:** - **` --write`** — Write formatted output back to files +- **` --stdin-file-path`**=_`PATH`_ — + Use this option when you want to format code piped from `stdin`, and print the output to `stdout`. + + The file doesn't need to exist on disk. The path is used to resolve the configuration (e.g. ignored files) and to label diagnostics, which are printed to `stderr`. + + Example: `echo 'select 1' | postgres-language-server format --stdin-file-path=test.sql` - **` --staged`** — When set to true, only the files that have been staged (the ones prepared to be committed) will be formatted. This option should be used when working locally. - **` --changed`** — From f7543c88eb0b2ce189bbadbcdf945a9b684dbac8 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 12 Oct 2026 15:10:49 +0000 Subject: [PATCH 3/7] feat(wasm): expose the formatter Workspace.format, Workspace.formatSql and a top-level format() take the options of the format section of the configuration file. --- crates/pgls_wasm/build-wasm.sh | 2 + crates/pgls_wasm/src/error.rs | 3 + crates/pgls_wasm/src/ffi.rs | 120 +++++++++- crates/pgls_wasm/src/lib.rs | 224 ++++++++++++++++-- .../@postgres-language-server/wasm/README.md | 38 ++- .../wasm/src/index.ts | 4 +- .../wasm/src/types.ts | 63 +++++ .../wasm/src/workspace.ts | 75 +++++- .../wasm/tests/index.test.ts | 45 +++- 9 files changed, 548 insertions(+), 26 deletions(-) diff --git a/crates/pgls_wasm/build-wasm.sh b/crates/pgls_wasm/build-wasm.sh index adf3267fd..56e7935f5 100755 --- a/crates/pgls_wasm/build-wasm.sh +++ b/crates/pgls_wasm/build-wasm.sh @@ -82,6 +82,8 @@ EXPORTED_FUNCTIONS="[ '_pgls_insert_file', '_pgls_remove_file', '_pgls_lint', + '_pgls_format', + '_pgls_format_sql', '_pgls_complete', '_pgls_hover', '_pgls_parse', diff --git a/crates/pgls_wasm/src/error.rs b/crates/pgls_wasm/src/error.rs index d3420fc13..ddd1b5f2f 100644 --- a/crates/pgls_wasm/src/error.rs +++ b/crates/pgls_wasm/src/error.rs @@ -11,6 +11,8 @@ pub enum WasmError { InvalidSchema(String), /// SQL parsing error. ParseError(String), + /// Invalid options JSON. + InvalidOptions(String), /// Internal error. Internal(String), } @@ -21,6 +23,7 @@ impl fmt::Display for WasmError { WasmError::FileNotFound(msg) => write!(f, "File not found: {msg}"), WasmError::InvalidSchema(msg) => write!(f, "Invalid schema: {msg}"), WasmError::ParseError(msg) => write!(f, "Parse error: {msg}"), + WasmError::InvalidOptions(msg) => write!(f, "Invalid options: {msg}"), WasmError::Internal(msg) => write!(f, "Internal error: {msg}"), } } diff --git a/crates/pgls_wasm/src/ffi.rs b/crates/pgls_wasm/src/ffi.rs index a8a60f8c9..5fd0ab044 100644 --- a/crates/pgls_wasm/src/ffi.rs +++ b/crates/pgls_wasm/src/ffi.rs @@ -2,7 +2,7 @@ //! //! This module provides two independent APIs: //! -//! 1. **Workspace API** (`pgls_*` functions) - Direct access to parse, lint, complete, hover +//! 1. **Workspace API** (`pgls_*` functions) - Direct access to parse, lint, format, complete, hover //! 2. **Language Server API** (`pgls_lsp_*` functions) - LSP JSON-RPC message handling //! //! Each API has its own independent workspace. Choose one based on your use case: @@ -191,6 +191,81 @@ pub unsafe extern "C" fn pgls_lint(path: *const c_char) -> *mut c_char { }) } +/// Read an optional options JSON string. A null pointer means "use defaults". +/// +/// # Safety +/// The pointer must be null or point to a valid null-terminated string. +unsafe fn options_from_ptr<'a>(options: *const c_char) -> Result<&'a str, WasmError> { + if options.is_null() { + return Ok(""); + } + // SAFETY: Caller guarantees options is valid + unsafe { c_str_to_str(options) } + .ok_or_else(|| WasmError::InvalidOptions("Invalid options pointer".to_string())) +} + +/// Format a file in the workspace. +/// `options` is a JSON object mirroring the `format` section of the configuration file, +/// or NULL / an empty string for defaults. +/// Returns a JSON `FormatResult` (`{"formatted": ..., "diagnostics": [...]}`), +/// or an error message starting with "ERROR:". +/// The returned string must be freed with `pgls_free_string`. +/// +/// # Safety +/// The path pointer must be valid and point to a null-terminated UTF-8 string. +/// The options pointer must be NULL or point to a null-terminated UTF-8 string. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn pgls_format(path: *const c_char, options: *const c_char) -> *mut c_char { + // SAFETY: Caller guarantees path is valid + let path_str = match unsafe { c_str_to_str(path) } { + Some(s) => s, + None => return str_to_c_string("ERROR: Invalid path pointer"), + }; + // SAFETY: Caller guarantees options is NULL or valid + let options_str = match unsafe { options_from_ptr(options) } { + Ok(s) => s, + Err(e) => return str_to_c_string(&format!("ERROR: {e}")), + }; + + with_workspace(|ws| { + let result = ws + .format(path_str, options_str) + .map(|result| serde_json::to_string(&result).unwrap_or_else(|e| format!("ERROR: {e}"))); + result_to_c_string(result) + }) +} + +/// Format a SQL string without adding it to the workspace. +/// See `pgls_format` for the options and result format. +/// The returned string must be freed with `pgls_free_string`. +/// +/// # Safety +/// The sql pointer must be valid and point to a null-terminated UTF-8 string. +/// The options pointer must be NULL or point to a null-terminated UTF-8 string. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn pgls_format_sql( + sql: *const c_char, + options: *const c_char, +) -> *mut c_char { + // SAFETY: Caller guarantees sql is valid + let sql_str = match unsafe { c_str_to_str(sql) } { + Some(s) => s, + None => return str_to_c_string("ERROR: Invalid SQL pointer"), + }; + // SAFETY: Caller guarantees options is NULL or valid + let options_str = match unsafe { options_from_ptr(options) } { + Ok(s) => s, + Err(e) => return str_to_c_string(&format!("ERROR: {e}")), + }; + + with_workspace(|ws| { + let result = ws + .format_sql(sql_str, options_str) + .map(|result| serde_json::to_string(&result).unwrap_or_else(|e| format!("ERROR: {e}"))); + result_to_c_string(result) + }) +} + /// Get completions at a position in a file. /// Returns a JSON array of completion items, or an error message starting with "ERROR:". /// The returned string must be freed with `pgls_free_string`. @@ -393,6 +468,49 @@ mod tests { } } + #[test] + fn test_ffi_format() { + pgls_init(); + + unsafe { + let sql = CString::new(r#"CREATE TABLE "public"."t" ("id" "uuid" NOT NULL)"#).unwrap(); + let options = CString::new(r#"{"keywordCase":"upper"}"#).unwrap(); + let result = pgls_format_sql(sql.as_ptr(), options.as_ptr()); + assert!(!result.is_null()); + let result_str = CStr::from_ptr(result).to_str().unwrap(); + let parsed: serde_json::Value = serde_json::from_str(result_str).unwrap(); + assert_eq!( + parsed["formatted"], + "CREATE TABLE public.t (id uuid NOT NULL);" + ); + assert_eq!(parsed["diagnostics"], serde_json::json!([])); + pgls_free_string(result); + + // NULL options use defaults + let path = CString::new("/ffi-format.sql").unwrap(); + assert!(pgls_insert_file(path.as_ptr(), sql.as_ptr()).is_null()); + let result = pgls_format(path.as_ptr(), std::ptr::null()); + assert!(!result.is_null()); + let result_str = CStr::from_ptr(result).to_str().unwrap(); + let parsed: serde_json::Value = serde_json::from_str(result_str).unwrap(); + assert_eq!( + parsed["formatted"], + "create table public.t (id uuid not null);" + ); + pgls_free_string(result); + + // Invalid options + let options = CString::new("{\"keywordCase\":1}").unwrap(); + let result = pgls_format(path.as_ptr(), options.as_ptr()); + let result_str = CStr::from_ptr(result).to_str().unwrap(); + assert!( + result_str.starts_with("ERROR: Invalid options"), + "{result_str}" + ); + pgls_free_string(result); + } + } + #[test] fn test_ffi_split_statements() { pgls_init(); diff --git a/crates/pgls_wasm/src/lib.rs b/crates/pgls_wasm/src/lib.rs index 776d2207b..20a9cd741 100644 --- a/crates/pgls_wasm/src/lib.rs +++ b/crates/pgls_wasm/src/lib.rs @@ -22,14 +22,17 @@ use std::path::PathBuf; use pgls_analyse::RuleCategories; +use pgls_configuration::{PartialConfiguration, PartialFormatConfiguration}; use pgls_fs::PgLSPath; use pgls_text_size::TextSize; use pgls_workspace::Workspace as WorkspaceTrait; use pgls_workspace::features::completions::GetCompletionsParams; use pgls_workspace::features::diagnostics::PullFileDiagnosticsParams; +use pgls_workspace::features::format::PullFileFormattingParams; use pgls_workspace::features::on_hover::OnHoverParams; use pgls_workspace::workspace::{ ChangeFileParams, CloseFileParams, OpenFileParams, RegisterProjectFolderParams, + UpdateSettingsParams, }; use serde::{Deserialize, Serialize}; @@ -54,6 +57,50 @@ pub struct Diagnostic { pub severity: String, } +impl From for Diagnostic { + fn from(d: pgls_diagnostics::serde::Diagnostic) -> Self { + let span = d.span().unwrap_or_default(); + Diagnostic { + start: u32::from(span.start()), + end: u32::from(span.end()), + message: d.description_text().to_string(), + severity: match d.get_severity() { + pgls_diagnostics::Severity::Error | pgls_diagnostics::Severity::Fatal => { + "error".to_string() + } + pgls_diagnostics::Severity::Warning => "warning".to_string(), + pgls_diagnostics::Severity::Information => "info".to_string(), + pgls_diagnostics::Severity::Hint => "hint".to_string(), + }, + } + } +} + +/// Result of formatting SQL. +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct FormatResult { + /// The formatted SQL. Statements that could not be formatted are kept verbatim. + pub formatted: String, + /// Diagnostics for statements that could not be formatted. + pub diagnostics: Vec, +} + +/// Virtual path used by [`Workspace::format_sql`] for the transient document. +const FORMAT_SQL_PATH: &str = "/__pgls_format_sql__.sql"; + +/// Parse formatter options from JSON. +/// +/// The JSON mirrors the `format` section of `postgres-language-server.jsonc` +/// (camelCase keys, same defaults). An empty string means "use defaults". +fn parse_format_options(options_json: &str) -> Result { + if options_json.trim().is_empty() { + return Ok(PartialFormatConfiguration::default()); + } + serde_json::from_str(options_json) + .map_err(|e| WasmError::InvalidOptions(format!("Invalid format options: {e}"))) +} + /// Simple completion item for WASM output. #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -267,27 +314,92 @@ impl Workspace { let diagnostics = result .diagnostics .into_iter() - .map(|d| { - let span = d.span().unwrap_or_default(); - Diagnostic { - start: u32::from(span.start()), - end: u32::from(span.end()), - message: d.description_text().to_string(), - severity: match d.get_severity() { - pgls_diagnostics::Severity::Error | pgls_diagnostics::Severity::Fatal => { - "error".to_string() - } - pgls_diagnostics::Severity::Warning => "warning".to_string(), - pgls_diagnostics::Severity::Information => "info".to_string(), - pgls_diagnostics::Severity::Hint => "hint".to_string(), - }, - } - }) + .map(Diagnostic::from) .collect(); Ok(diagnostics) } + /// Format a file in the workspace. + /// + /// Formatting is always enabled for explicit calls, regardless of the + /// `enabled` value in the options. + /// + /// # Arguments + /// * `path` - The virtual file path to format + /// * `options_json` - Formatter options as JSON, mirroring the `format` section of the + /// configuration file (e.g. `{"keywordCase":"upper"}`). Pass an empty string for defaults. + /// + /// # Returns + /// The formatted SQL and diagnostics for statements that could not be formatted, + /// or an error if the file doesn't exist or the options are invalid. + pub fn format(&self, path: &str, options_json: &str) -> Result { + // Verify file exists + let _content = self.fs.read(path)?; + + self.format_open_document(PgLSPath::new(PathBuf::from(path)), options_json) + } + + /// Format a SQL string without adding it to the workspace. + /// + /// See [`Workspace::format`] for the options format. + pub fn format_sql(&self, sql: &str, options_json: &str) -> Result { + let pgls_path = PgLSPath::new(PathBuf::from(FORMAT_SQL_PATH)); + self.inner + .open_file(OpenFileParams { + path: pgls_path.clone(), + content: sql.into(), + version: 0, + }) + .map_err(|e| WasmError::Internal(format!("Failed to open document: {e}")))?; + + let result = self.format_open_document(pgls_path.clone(), options_json); + + let _ = self.inner.close_file(CloseFileParams { path: pgls_path }); + + result + } + + fn format_open_document( + &self, + path: PgLSPath, + options_json: &str, + ) -> Result { + let mut format = parse_format_options(options_json)?; + format.enabled = Some(true); + // File matching does not apply to in-memory formatting. + format.ignore = None; + format.include = None; + + self.inner + .update_settings(UpdateSettingsParams { + configuration: PartialConfiguration { + format: Some(format), + ..Default::default() + }, + vcs_base_path: None, + gitignore_matches: vec![], + workspace_directory: None, + }) + .map_err(|e| { + WasmError::InvalidOptions(format!("Failed to apply format options: {e}")) + })?; + + let result = self + .inner + .pull_file_formatting(PullFileFormattingParams { path, range: None }) + .map_err(|e| WasmError::Internal(format!("Format failed: {e}")))?; + + Ok(FormatResult { + formatted: result.formatted, + diagnostics: result + .diagnostics + .into_iter() + .map(Diagnostic::from) + .collect(), + }) + } + /// Get completions at a position in a file. /// /// Uses the full pgls_workspace completions engine. @@ -449,6 +561,86 @@ mod tests { assert_eq!(statements[1].sql, "SELECT 2;"); } + const FORMAT_INPUT: &str = r#"CREATE TABLE "public"."t" ("id" "uuid" NOT NULL)"#; + + #[test] + fn test_workspace_format_sql_keyword_case_upper() { + let workspace = Workspace::new(); + + let result = workspace + .format_sql(FORMAT_INPUT, r#"{"keywordCase":"upper"}"#) + .unwrap(); + assert!(result.diagnostics.is_empty(), "{:?}", result.diagnostics); + assert_eq!( + result.formatted, + "CREATE TABLE public.t (id uuid NOT NULL);" + ); + } + + #[test] + fn test_workspace_format_sql_defaults() { + let workspace = Workspace::new(); + + let result = workspace.format_sql(FORMAT_INPUT, "").unwrap(); + assert!(result.diagnostics.is_empty(), "{:?}", result.diagnostics); + assert_eq!( + result.formatted, + "create table public.t (id uuid not null);" + ); + + // Options from a previous call must not leak into the next one. + workspace + .format_sql(FORMAT_INPUT, r#"{"keywordCase":"upper"}"#) + .unwrap(); + let result = workspace.format_sql(FORMAT_INPUT, "{}").unwrap(); + assert_eq!( + result.formatted, + "create table public.t (id uuid not null);" + ); + } + + #[test] + fn test_workspace_format_ignores_enabled_false() { + let workspace = Workspace::new(); + + let result = workspace + .format_sql(FORMAT_INPUT, r#"{"enabled":false}"#) + .unwrap(); + assert_eq!( + result.formatted, + "create table public.t (id uuid not null);" + ); + } + + #[test] + fn test_workspace_format_file() { + let mut workspace = Workspace::new(); + workspace.insert_file("/format.sql", "select 1;\n\nSELEC 2;\n"); + + let result = workspace + .format("/format.sql", r#"{"keywordCase":"upper"}"#) + .unwrap(); + assert_eq!(result.formatted, "SELECT 1;\n\nSELEC 2;\n"); + assert_eq!(result.diagnostics.len(), 1); + assert_eq!(result.diagnostics[0].severity, "error"); + + assert!(workspace.format("/missing.sql", "").is_err()); + } + + #[test] + fn test_workspace_format_invalid_options() { + let workspace = Workspace::new(); + + assert!(matches!( + workspace.format_sql("select 1", r#"{"keywordCase":"shout"}"#), + Err(WasmError::InvalidOptions(_)) + )); + assert!(matches!( + workspace.format_sql("select 1", r#"{"unknownOption":true}"#), + Err(WasmError::InvalidOptions(_)) + )); + } + #[test] fn test_memory_fs() { let mut fs = MemoryFs::new(); diff --git a/packages/@postgres-language-server/wasm/README.md b/packages/@postgres-language-server/wasm/README.md index 9e504d0cb..feaa29394 100644 --- a/packages/@postgres-language-server/wasm/README.md +++ b/packages/@postgres-language-server/wasm/README.md @@ -14,10 +14,10 @@ bun add @postgres-language-server/wasm This package provides two separate APIs. Choose the one that fits your use case: -| API | Use Case | Import Path | -| ------------------ | ----------------------------------- | ------------------------------------------ | -| **Workspace** | Direct parse, lint, complete, hover | `@postgres-language-server/wasm/workspace` | -| **LanguageServer** | Full LSP JSON-RPC protocol | `@postgres-language-server/wasm/lsp` | +| API | Use Case | Import Path | +| ------------------ | ------------------------------------------- | ------------------------------------------ | +| **Workspace** | Direct parse, lint, format, complete, hover | `@postgres-language-server/wasm/workspace` | +| **LanguageServer** | Full LSP JSON-RPC protocol | `@postgres-language-server/wasm/lsp` | Each API manages its own workspace independently. Use one or the other, not both. @@ -49,6 +49,32 @@ const completions = workspace.complete("/query.sql", 14); // position after "FRO const hover = workspace.hover("/query.sql", 14); // position over "users" ``` +### Formatting + +Format SQL in-process. Options mirror the `format` section of +`postgres-language-server.jsonc` (same names and defaults, see `FormatOptions`). +Formatting is always enabled when you call a format function, regardless of `enabled`. + +```typescript +import { createWorkspace, format } from "@postgres-language-server/wasm"; + +// One-off: loads the WASM module on first use and returns the formatted SQL +const sql = await format('CREATE TABLE "public"."t" ("id" "uuid" NOT NULL)', { + keywordCase: "upper", +}); +// "CREATE TABLE public.t (id uuid NOT NULL);" + +// With a workspace: synchronous, and also returns diagnostics +const workspace = await createWorkspace(); +const result = workspace.formatSql("select 1;\n\nSELEC 2;", { lineWidth: 80 }); +result.formatted; // statements that cannot be formatted are kept verbatim +result.diagnostics; // one diagnostic per statement that could not be formatted + +// Format a file that was added with insertFile +workspace.insertFile("/query.sql", "select * from users"); +const { formatted } = workspace.format("/query.sql", { indentStyle: "tabs" }); +``` + ### With Schema For schema-aware completions and hover, provide your database schema. @@ -143,12 +169,16 @@ lsp.handleMessage({ | `insertFile(path, content)` | Add or update a file in the workspace | | `removeFile(path)` | Remove a file from the workspace | | `lint(path)` | Get diagnostics for a file | +| `format(path, options?)` | Format a file, returns `FormatResult` | +| `formatSql(sql, options?)` | Format a SQL string, returns `FormatResult` | | `complete(path, offset)` | Get completions at position | | `hover(path, offset)` | Get hover info at position | | `setSchema(json)` | Set database schema | | `clearSchema()` | Clear the current schema | | `version()` | Get library version | +The top-level `format(sql, options?)` function returns a `Promise` with the formatted SQL. + ### LanguageServer | Method | Description | diff --git a/packages/@postgres-language-server/wasm/src/index.ts b/packages/@postgres-language-server/wasm/src/index.ts index c3d6643e5..c4357d157 100644 --- a/packages/@postgres-language-server/wasm/src/index.ts +++ b/packages/@postgres-language-server/wasm/src/index.ts @@ -3,7 +3,7 @@ * * This package provides two independent APIs: * - * 1. **Workspace API** - Direct access to parse, lint, complete, hover + * 1. **Workspace API** - Direct access to parse, lint, format, complete, hover * ```ts * import { createWorkspace } from '@postgres-language-server/wasm/workspace'; * ``` @@ -25,6 +25,8 @@ export { loadWasm } from "./common.js"; export type { Diagnostic, CompletionItem, + FormatOptions, + FormatResult, SchemaCache, Statement, WorkspaceOptions, diff --git a/packages/@postgres-language-server/wasm/src/types.ts b/packages/@postgres-language-server/wasm/src/types.ts index 65075df23..19e474ea7 100644 --- a/packages/@postgres-language-server/wasm/src/types.ts +++ b/packages/@postgres-language-server/wasm/src/types.ts @@ -61,6 +61,67 @@ export interface Statement { end: number; } +/** + * Formatter options. + * + * Mirrors the `format` section of `postgres-language-server.jsonc` (same names + * and defaults). Omitted options use their defaults. Formatting is always + * enabled when calling a format function explicitly. + */ +export interface FormatOptions { + /** Maximum line width before breaking. Default: 100. */ + lineWidth?: number; + /** Number of spaces (or tab width) for indentation. Default: 2. */ + indentSize?: number; + /** Indentation style. Default: "spaces". */ + indentStyle?: "spaces" | "tabs"; + /** Keyword casing. Default: "lower". */ + keywordCase?: "upper" | "lower"; + /** Constant casing (NULL, TRUE, FALSE). Default: "lower". */ + constantCase?: "upper" | "lower"; + /** Data type casing (text, varchar, int). Default: "lower". */ + typeCase?: "upper" | "lower"; + /** Where a comma sits when a list breaks. Default: "trailing". */ + commaStyle?: "trailing" | "leading"; + /** Where a boolean operator sits when a condition breaks. Default: "trailing". */ + logicalOperatorPlacement?: "trailing" | "leading"; + /** + * How a statement is laid out: "fit" breaks only when a line would exceed the + * line width, "expanded" always breaks between clauses. Default: "fit". + */ + layout?: "fit" | "expanded"; + /** How an explicit cast is spelled: `CAST(x AS t)` or `x::t`. Default: "cast". */ + castStyle?: "cast" | "operator"; + /** + * Where the body of a clause starts: "break" for a new line, "compact" to keep + * the first element on the keyword line. Default: "break". + */ + clauseBodyStyle?: "break" | "compact"; + /** + * If `true`, the terminating semicolon goes on its own line when the statement + * spans several lines. Default: `false`. + */ + isolateSemicolon?: boolean; + /** + * Function names mapped to the number of adjacent arguments in one logical group + * (1-255). `json_build_object` and `jsonb_build_object` are grouped in pairs by + * default; configure a size of `1` to opt out. + */ + functionArgumentGroups?: Record; + /** If `true`, keep SQL function bodies verbatim. Default: `false`. */ + skipFnBodies?: boolean; +} + +/** + * The result of formatting SQL. + */ +export interface FormatResult { + /** The formatted SQL. Statements that could not be formatted are kept verbatim. */ + formatted: string; + /** Diagnostics for statements that could not be formatted. */ + diagnostics: Diagnostic[]; +} + /** * A JSON-RPC message (request, response, or notification). * This is the standard LSP message format. @@ -95,6 +156,8 @@ export interface PGLSModule { _pgls_insert_file(pathPtr: number, contentPtr: number): number; _pgls_remove_file(pathPtr: number): void; _pgls_lint(pathPtr: number): number; + _pgls_format(pathPtr: number, optionsPtr: number): number; + _pgls_format_sql(sqlPtr: number, optionsPtr: number): number; _pgls_complete(pathPtr: number, offset: number): number; _pgls_hover(pathPtr: number, offset: number): number; _pgls_parse(sqlPtr: number): number; diff --git a/packages/@postgres-language-server/wasm/src/workspace.ts b/packages/@postgres-language-server/wasm/src/workspace.ts index 81eab7d06..0c355242c 100644 --- a/packages/@postgres-language-server/wasm/src/workspace.ts +++ b/packages/@postgres-language-server/wasm/src/workspace.ts @@ -1,5 +1,5 @@ /** - * Workspace API - Direct access to parse, lint, complete, hover. + * Workspace API - Direct access to parse, lint, format, complete, hover. * * Use this for: * - Custom editor integrations @@ -13,6 +13,7 @@ * const workspace = await createWorkspace(); * workspace.insertFile('/query.sql', 'SELECT * FROM users;'); * const diagnostics = workspace.lint('/query.sql'); + * const { formatted } = workspace.format('/query.sql', { keywordCase: 'upper' }); * ``` */ @@ -20,17 +21,28 @@ import { allocateString, loadWasm, parseResult, readAndFreeString } from "./comm import type { CompletionItem, Diagnostic, + FormatOptions, + FormatResult, PGLSModule, SchemaCache, Statement, WorkspaceOptions, } from "./types.js"; -export type { Diagnostic, CompletionItem, SchemaCache, Statement, WorkspaceOptions, PGLSModule }; +export type { + Diagnostic, + CompletionItem, + FormatOptions, + FormatResult, + SchemaCache, + Statement, + WorkspaceOptions, + PGLSModule, +}; /** * The Workspace class provides a direct API for SQL parsing, linting, - * completions, and hover information. + * formatting, completions, and hover information. */ export class Workspace { private module: PGLSModule; @@ -107,6 +119,44 @@ export class Workspace { } } + /** + * Format a file in the workspace. + * + * Statements that cannot be formatted (e.g. syntax errors) are kept verbatim + * and reported in `diagnostics`. Throws if the file does not exist or the + * options are invalid. + */ + format(path: string, options?: FormatOptions): FormatResult { + const pathPtr = allocateString(this.module, path); + const optionsPtr = allocateString(this.module, JSON.stringify(options ?? {})); + try { + const resultPtr = this.module._pgls_format(pathPtr, optionsPtr); + const result = readAndFreeString(this.module, resultPtr); + return parseResult(result); + } finally { + this.module._free(pathPtr); + this.module._free(optionsPtr); + } + } + + /** + * Format a SQL string without adding it to the workspace. + * + * See {@link Workspace.format} for details. + */ + formatSql(sql: string, options?: FormatOptions): FormatResult { + const sqlPtr = allocateString(this.module, sql); + const optionsPtr = allocateString(this.module, JSON.stringify(options ?? {})); + try { + const resultPtr = this.module._pgls_format_sql(sqlPtr, optionsPtr); + const result = readAndFreeString(this.module, resultPtr); + return parseResult(result); + } finally { + this.module._free(sqlPtr); + this.module._free(optionsPtr); + } + } + /** * Get completions at a position in a file. */ @@ -195,4 +245,23 @@ export async function createWorkspace(options?: WorkspaceOptions): Promise { + const workspace = new Workspace(await loadWasm()); + return workspace.formatSql(sql, options).formatted; +} + export default createWorkspace; diff --git a/packages/@postgres-language-server/wasm/tests/index.test.ts b/packages/@postgres-language-server/wasm/tests/index.test.ts index 906773671..c0faa0f36 100644 --- a/packages/@postgres-language-server/wasm/tests/index.test.ts +++ b/packages/@postgres-language-server/wasm/tests/index.test.ts @@ -5,7 +5,7 @@ import { beforeAll, beforeEach, describe, expect, test } from "bun:test"; import { type LanguageServer, createLanguageServer } from "../src/lsp"; -import { type Workspace, createWorkspace } from "../src/workspace"; +import { type FormatOptions, type Workspace, createWorkspace, format } from "../src/workspace"; // ============================================================================= // Workspace API Tests @@ -280,6 +280,49 @@ alter table deal_type add column key text not null; }); }); +// ============================================================================= +// Format Tests +// ============================================================================= + +describe("Format", () => { + const sql = 'CREATE TABLE "public"."t" ("id" "uuid" NOT NULL)'; + let workspace: Workspace; + + beforeAll(async () => { + workspace = await createWorkspace(); + }); + + test("formatSql uses defaults", () => { + const result = workspace.formatSql(sql); + expect(result.formatted).toBe("create table public.t (id uuid not null);"); + expect(result.diagnostics).toEqual([]); + }); + + test("formatSql applies options", () => { + const result = workspace.formatSql(sql, { keywordCase: "upper" }); + expect(result.formatted).toBe("CREATE TABLE public.t (id uuid NOT NULL);"); + }); + + test("format formats a workspace file and reports unformattable statements", () => { + workspace.insertFile("/format.sql", "select 1;\n\nSELEC 2;\n"); + const result = workspace.format("/format.sql", { keywordCase: "upper" }); + expect(result.formatted).toBe("SELECT 1;\n\nSELEC 2;\n"); + expect(result.diagnostics.length).toBe(1); + }); + + test("format throws on invalid options", () => { + expect(() => + workspace.formatSql(sql, { keywordCase: "shout" } as unknown as FormatOptions), + ).toThrow(); + }); + + test("top-level format returns the formatted string", async () => { + expect(await format(sql, { keywordCase: "upper" })).toBe( + "CREATE TABLE public.t (id uuid NOT NULL);", + ); + }); +}); + // ============================================================================= // Language Server API Tests // ============================================================================= From bcb085229311fc73e33d68c744b57fcfd5b2c27b Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 12 Oct 2026 16:45:01 +0000 Subject: [PATCH 4/7] refactor(pretty-print): tidy up the formatter fixes - Merge emit_word into emit_keyword, which now spells any word in the keyword case - Measure a group's single-line form only until the line is full - Merge the emit_parenthesized_list imports into the existing ones - Print OVERLAPS operands as parenthesized lists, so they break inside the parentheses - Drop the stdin ignore check the workspace already performs --- crates/pgls_cli/src/execute/stdin.rs | 12 +- crates/pgls_pretty_print/src/emitter.rs | 17 +-- .../src/nodes/alter_publication_stmt.rs | 3 +- .../src/nodes/alter_subscription_stmt.rs | 3 +- .../src/nodes/alter_type_stmt.rs | 4 +- .../pgls_pretty_print/src/nodes/constraint.rs | 2 +- .../pgls_pretty_print/src/nodes/copy_stmt.rs | 5 +- .../src/nodes/create_event_trig_stmt.rs | 2 +- .../src/nodes/create_foreign_table_stmt.rs | 3 +- .../src/nodes/create_function_stmt.rs | 8 +- .../src/nodes/create_op_class_item.rs | 3 +- .../src/nodes/create_policy_stmt.rs | 2 +- .../src/nodes/create_publication_stmt.rs | 4 +- .../src/nodes/create_role_stmt.rs | 2 +- .../src/nodes/create_stats_stmt.rs | 6 +- .../src/nodes/create_stmt.rs | 3 +- .../src/nodes/create_subscription_stmt.rs | 3 +- .../pgls_pretty_print/src/nodes/def_elem.rs | 4 +- .../src/nodes/define_stmt.rs | 7 +- .../src/nodes/dropdb_stmt.rs | 2 +- .../src/nodes/explain_stmt.rs | 2 +- .../pgls_pretty_print/src/nodes/func_call.rs | 52 +++----- .../src/nodes/grant_role_stmt.rs | 2 +- .../pgls_pretty_print/src/nodes/grant_stmt.rs | 6 +- .../src/nodes/grouping_set.rs | 3 +- .../pgls_pretty_print/src/nodes/join_expr.rs | 3 +- .../src/nodes/json_value_expr.rs | 4 +- .../pgls_pretty_print/src/nodes/lock_stmt.rs | 2 +- crates/pgls_pretty_print/src/nodes/mod.rs | 4 +- .../src/nodes/partition_bound_spec.rs | 4 +- .../src/nodes/partition_spec.rs | 4 +- .../src/nodes/range_function.rs | 3 +- .../src/nodes/range_table_func.rs | 4 +- .../src/nodes/range_table_sample.rs | 4 +- .../src/nodes/reindex_stmt.rs | 2 +- crates/pgls_pretty_print/src/nodes/string.rs | 15 +-- .../src/nodes/table_like_clause.rs | 2 +- .../src/nodes/vacuum_stmt.rs | 5 +- .../src/nodes/variable_set_stmt.rs | 17 +-- .../pgls_pretty_print/src/nodes/view_stmt.rs | 3 +- .../pgls_pretty_print/src/nodes/xml_expr.rs | 4 +- .../src/nodes/xml_serialize.rs | 8 +- crates/pgls_pretty_print/src/renderer.rs | 91 ++++++------- .../multi/tests__create_view_80.snap | 6 +- .../snapshots/multi/tests__horology_100.snap | 108 +++++++++------ .../snapshots/multi/tests__horology_80.snap | 126 ++++++++++++------ 46 files changed, 298 insertions(+), 281 deletions(-) diff --git a/crates/pgls_cli/src/execute/stdin.rs b/crates/pgls_cli/src/execute/stdin.rs index 3cea052d3..41fdabe81 100644 --- a/crates/pgls_cli/src/execute/stdin.rs +++ b/crates/pgls_cli/src/execute/stdin.rs @@ -5,7 +5,7 @@ use pgls_console::{ConsoleExt, markup}; use pgls_diagnostics::{DiagnosticExt, Error, PrintDiagnostic, category}; use pgls_fs::PgLSPath; use pgls_workspace::features::format::PullFileFormattingParams; -use pgls_workspace::workspace::{FileGuard, IsPathIgnoredParams, OpenFileParams}; +use pgls_workspace::workspace::{FileGuard, OpenFileParams}; pub(crate) fn process( session: &mut CliSession, @@ -29,14 +29,6 @@ fn format(session: &mut CliSession, payload: StdinPayload) -> Result<(), CliDiag let pgls_path = PgLSPath::new(&payload.path); let workspace = session.workspace(); - let is_ignored = workspace.is_path_ignored(IsPathIgnoredParams { - pgls_path: pgls_path.clone(), - })?; - if is_ignored { - session.console().append(markup! {{payload.content}}); - return Ok(()); - } - let result = { let guard = FileGuard::open( workspace, @@ -52,7 +44,7 @@ fn format(session: &mut CliSession, payload: StdinPayload) -> Result<(), CliDiag })? }; - // The workspace returns an empty result when the formatter is disabled. + // The workspace returns an empty result for an ignored file or a disabled formatter. let output = if result.original == payload.content { result.formatted } else { diff --git a/crates/pgls_pretty_print/src/emitter.rs b/crates/pgls_pretty_print/src/emitter.rs index 223e7aa9a..3af4b482e 100644 --- a/crates/pgls_pretty_print/src/emitter.rs +++ b/crates/pgls_pretty_print/src/emitter.rs @@ -106,7 +106,7 @@ impl EventEmitter { } /// The source text of the first string literal at or after `location`. - pub fn source_string_literal_from(&self, location: i32) -> Option<&str> { + pub(crate) fn source_string_literal_from(&self, location: i32) -> Option<&str> { let source = self.source.as_ref()?; let location = usize::try_from(location).ok()?; let index = source @@ -142,16 +142,13 @@ impl EventEmitter { // A comment held for a comma follows it. Other tokens closing the item before the comma, // a parenthesis or an alias for instance, are written first. A statement never ends on a // comma, so the terminator flushes what is left. - if self.comments_after_separator.is_empty() { - self.events.push(LayoutEvent::Token(token)); - } else if matches!(token, TokenKind::COMMA) { - self.events.push(LayoutEvent::Token(token)); + let is_comma = matches!(token, TokenKind::COMMA); + if matches!(token, TokenKind::SEMICOLON) { + self.flush_comments_after_separator(); + } + self.events.push(LayoutEvent::Token(token)); + if is_comma { self.flush_comments_after_separator(); - } else { - if matches!(token, TokenKind::SEMICOLON) { - self.flush_comments_after_separator(); - } - self.events.push(LayoutEvent::Token(token)); } } diff --git a/crates/pgls_pretty_print/src/nodes/alter_publication_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_publication_stmt.rs index d5c9ea95b..00953a70e 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_publication_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_publication_stmt.rs @@ -2,8 +2,7 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; use pgls_query::protobuf::AlterPublicationStmt; -use super::node_list::emit_comma_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_comma_separated_list, emit_parenthesized_list}; pub(super) fn emit_alter_publication_stmt(e: &mut EventEmitter, n: &AlterPublicationStmt) { e.group_start(GroupKind::AlterPublicationStmt); diff --git a/crates/pgls_pretty_print/src/nodes/alter_subscription_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_subscription_stmt.rs index 4a3f89a9f..f7ac0662f 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_subscription_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_subscription_stmt.rs @@ -1,6 +1,5 @@ -use super::node_list::emit_parenthesized_list; use super::{ - node_list::emit_comma_separated_list, + node_list::{emit_comma_separated_list, emit_parenthesized_list}, string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}, }; use crate::{ diff --git a/crates/pgls_pretty_print/src/nodes/alter_type_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_type_stmt.rs index 6ebc71776..af09ff910 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_type_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_type_stmt.rs @@ -3,11 +3,9 @@ use pgls_query::{NodeEnum, protobuf::AlterTypeStmt}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_dot_separated_list, + nodes::node_list::{emit_dot_separated_list, emit_parenthesized_list}, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_alter_type_stmt(e: &mut EventEmitter, n: &AlterTypeStmt) { e.group_start(GroupKind::AlterTypeStmt); diff --git a/crates/pgls_pretty_print/src/nodes/constraint.rs b/crates/pgls_pretty_print/src/nodes/constraint.rs index cc32252b7..d6bed50e6 100644 --- a/crates/pgls_pretty_print/src/nodes/constraint.rs +++ b/crates/pgls_pretty_print/src/nodes/constraint.rs @@ -530,7 +530,7 @@ fn emit_foreign_key_action( // Caller handles line break - we just emit the action e.token(TokenKind::ON_KW); e.space(); - super::emit_word(e, event); + super::emit_keyword(e, event); e.space(); match action { diff --git a/crates/pgls_pretty_print/src/nodes/copy_stmt.rs b/crates/pgls_pretty_print/src/nodes/copy_stmt.rs index f5f4bf55c..fa16d35fd 100644 --- a/crates/pgls_pretty_print/src/nodes/copy_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/copy_stmt.rs @@ -1,6 +1,5 @@ -use super::node_list::emit_parenthesized_list; use super::{ - node_list::emit_comma_separated_list, + node_list::{emit_comma_separated_list, emit_parenthesized_list}, string::{emit_keyword, emit_single_quoted_str}, }; use crate::{ @@ -115,7 +114,7 @@ pub(super) fn emit_copy_stmt(e: &mut EventEmitter, n: &CopyStmt) { fn emit_copy_option(e: &mut EventEmitter, n: &pgls_query::protobuf::DefElem) { e.group_start(GroupKind::DefElem); - super::emit_word(e, &n.defname); + super::emit_keyword(e, &n.defname); // Handle the value based on its type if let Some(ref arg) = n.arg diff --git a/crates/pgls_pretty_print/src/nodes/create_event_trig_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_event_trig_stmt.rs index 3a319f28f..36562b065 100644 --- a/crates/pgls_pretty_print/src/nodes/create_event_trig_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_event_trig_stmt.rs @@ -43,7 +43,7 @@ pub(super) fn emit_create_event_trig_stmt(e: &mut EventEmitter, n: &CreateEventT // Each when clause is a DefElem with defname=tag and arg=List of values if let Some(pgls_query::NodeEnum::DefElem(def_elem)) = when.node.as_ref() { // Emit TAG name - super::emit_word(e, &def_elem.defname); + super::emit_keyword(e, &def_elem.defname); e.space(); e.token(TokenKind::IN_KW); e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/create_foreign_table_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_foreign_table_stmt.rs index cacb40bc7..6518f32d8 100644 --- a/crates/pgls_pretty_print/src/nodes/create_foreign_table_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_foreign_table_stmt.rs @@ -1,5 +1,4 @@ -use super::node_list::emit_comma_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_comma_separated_list, emit_parenthesized_list}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, diff --git a/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs index 2e5e72ac9..b734e885d 100644 --- a/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs @@ -184,7 +184,7 @@ pub(super) fn emit_function_parameter(e: &mut EventEmitter, fp: &FunctionParamet if super::string::needs_quoting_as_function_or_type_name(&fp.name) { super::emit_identifier(e, &fp.name); } else { - super::emit_identifier_maybe_quoted(e, &fp.name); + e.token(TokenKind::IDENT(fp.name.clone())); } e.space(); } @@ -329,7 +329,7 @@ pub(super) fn format_function_option( "IMMUTABLE" => e.token(TokenKind::IMMUTABLE_KW), "STABLE" => e.token(TokenKind::STABLE_KW), "VOLATILE" => e.token(TokenKind::VOLATILE_KW), - _ => super::emit_word(e, &s.sval), + _ => super::emit_keyword(e, &s.sval), } } else { super::emit_node(arg, e); @@ -394,7 +394,7 @@ pub(super) fn format_function_option( e.space(); if let Some(ref arg) = d.arg { if let Some(pgls_query::NodeEnum::String(s)) = &arg.node { - super::emit_word(e, &s.sval); + super::emit_keyword(e, &s.sval); } else { super::emit_node(arg, e); } @@ -465,7 +465,7 @@ pub(super) fn format_function_option( } _ => { // Default: emit option name and value - super::emit_word(e, &d.defname); + super::emit_keyword(e, &d.defname); if let Some(ref arg) = d.arg { e.space(); super::emit_node(arg, e); diff --git a/crates/pgls_pretty_print/src/nodes/create_op_class_item.rs b/crates/pgls_pretty_print/src/nodes/create_op_class_item.rs index f96fbec57..14be24579 100644 --- a/crates/pgls_pretty_print/src/nodes/create_op_class_item.rs +++ b/crates/pgls_pretty_print/src/nodes/create_op_class_item.rs @@ -2,8 +2,7 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind}; use pgls_query::protobuf::CreateOpClassItem; -use super::node_list::emit_dot_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_dot_separated_list, emit_parenthesized_list}; use super::object_with_args::{emit_object_name_only, emit_object_with_args}; pub(super) fn emit_create_op_class_item(e: &mut EventEmitter, n: &CreateOpClassItem) { diff --git a/crates/pgls_pretty_print/src/nodes/create_policy_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_policy_stmt.rs index 7e1d9f691..23ecee722 100644 --- a/crates/pgls_pretty_print/src/nodes/create_policy_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_policy_stmt.rs @@ -43,7 +43,7 @@ pub(super) fn emit_create_policy_stmt(e: &mut EventEmitter, n: &CreatePolicyStmt "INSERT" => e.token(TokenKind::INSERT_KW), "UPDATE" => e.token(TokenKind::UPDATE_KW), "DELETE" => e.token(TokenKind::DELETE_KW), - _ => super::emit_word(e, &n.cmd_name), + _ => super::emit_keyword(e, &n.cmd_name), } } diff --git a/crates/pgls_pretty_print/src/nodes/create_publication_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_publication_stmt.rs index d402105a4..e6500a58a 100644 --- a/crates/pgls_pretty_print/src/nodes/create_publication_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_publication_stmt.rs @@ -1,12 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, + nodes::node_list::{emit_comma_separated_list, emit_parenthesized_list}, }; use pgls_query::{NodeEnum, protobuf::CreatePublicationStmt}; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_create_publication_stmt(e: &mut EventEmitter, n: &CreatePublicationStmt) { e.group_start(GroupKind::CreatePublicationStmt); diff --git a/crates/pgls_pretty_print/src/nodes/create_role_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_role_stmt.rs index 48007cc4f..252100767 100644 --- a/crates/pgls_pretty_print/src/nodes/create_role_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_role_stmt.rs @@ -199,7 +199,7 @@ fn format_role_option(e: &mut EventEmitter, d: &pgls_query::protobuf::DefElem) { } // Default formatting for other options - super::emit_word(e, &d.defname); + super::emit_keyword(e, &d.defname); if let Some(ref arg) = d.arg { e.space(); super::emit_node(arg, e); diff --git a/crates/pgls_pretty_print/src/nodes/create_stats_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_stats_stmt.rs index 294b3f5b6..ed05a770d 100644 --- a/crates/pgls_pretty_print/src/nodes/create_stats_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_stats_stmt.rs @@ -1,12 +1,12 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::{node_list::emit_comma_separated_list, node_list::emit_dot_separated_list}, + nodes::node_list::{ + emit_comma_separated_list, emit_dot_separated_list, emit_parenthesized_list, + }, }; use pgls_query::{NodeEnum, protobuf::CreateStatsStmt}; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_create_stats_stmt(e: &mut EventEmitter, n: &CreateStatsStmt) { e.group_start(GroupKind::CreateStatsStmt); diff --git a/crates/pgls_pretty_print/src/nodes/create_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_stmt.rs index 039d6493c..2ffe49672 100644 --- a/crates/pgls_pretty_print/src/nodes/create_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_stmt.rs @@ -3,8 +3,7 @@ use pgls_query::protobuf::{CreateStmt, node::Node as NodeEnum}; use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; -use super::node_list::emit_comma_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_comma_separated_list, emit_parenthesized_list}; /// Emit a column override for typed tables (OF typename). /// These use the syntax: column_name WITH OPTIONS constraints diff --git a/crates/pgls_pretty_print/src/nodes/create_subscription_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_subscription_stmt.rs index 2d98acf39..338a565af 100644 --- a/crates/pgls_pretty_print/src/nodes/create_subscription_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_subscription_stmt.rs @@ -1,11 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, - nodes::node_list::emit_comma_separated_list, + nodes::node_list::{emit_comma_separated_list, emit_parenthesized_list}, }; use pgls_query::{NodeEnum, protobuf::CreateSubscriptionStmt}; -use super::node_list::emit_parenthesized_list; use super::string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}; pub(super) fn emit_create_subscription_stmt(e: &mut EventEmitter, n: &CreateSubscriptionStmt) { diff --git a/crates/pgls_pretty_print/src/nodes/def_elem.rs b/crates/pgls_pretty_print/src/nodes/def_elem.rs index a81e403fc..fddc2c1c1 100644 --- a/crates/pgls_pretty_print/src/nodes/def_elem.rs +++ b/crates/pgls_pretty_print/src/nodes/def_elem.rs @@ -123,7 +123,7 @@ pub(super) fn emit_grant_role_option(e: &mut EventEmitter, n: &DefElem) { }); // Emit the option name - super::emit_word(e, defname); + super::emit_keyword(e, defname); // Emit TRUE or FALSE if let Some(val) = is_true { @@ -293,7 +293,7 @@ pub(super) fn emit_role_option(e: &mut EventEmitter, n: &DefElem) { _ => { // Fallback for unknown role options if !n.defname.is_empty() { - super::emit_word(e, &n.defname); + super::emit_keyword(e, &n.defname); } if let Some(ref arg) = n.arg { e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/define_stmt.rs b/crates/pgls_pretty_print/src/nodes/define_stmt.rs index 9025078d7..c70377e7b 100644 --- a/crates/pgls_pretty_print/src/nodes/define_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/define_stmt.rs @@ -1,12 +1,13 @@ use pgls_query::NodeEnum; use pgls_query::protobuf::{DefElem, DefineStmt, List, Node, ObjectType}; -use super::node_list::emit_parenthesized_list; use super::string::emit_identifier_maybe_quoted; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::{emit_comma_separated_list, emit_dot_separated_list}, + nodes::node_list::{ + emit_comma_separated_list, emit_dot_separated_list, emit_parenthesized_list, + }, }; /// Emit collation definition (FROM clause or parenthesized options) @@ -208,7 +209,7 @@ fn emit_operator_name(e: &mut EventEmitter, defnames: &[Node]) { } fn emit_operator_def_elem(e: &mut EventEmitter, def: &DefElem) { - super::emit_word(e, &def.defname); + super::emit_keyword(e, &def.defname); if let Some(ref arg) = def.arg { e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs b/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs index 50e41784f..0639de92b 100644 --- a/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs @@ -32,7 +32,7 @@ pub(super) fn emit_dropdb_stmt(e: &mut EventEmitter, n: &DropdbStmt) { emit_parenthesized_list(e, &n.options, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { // Options like FORCE have just the name, no value - super::emit_word(emitter, &def.defname); + super::emit_keyword(emitter, &def.defname); } }); } diff --git a/crates/pgls_pretty_print/src/nodes/explain_stmt.rs b/crates/pgls_pretty_print/src/nodes/explain_stmt.rs index 7234f89f4..9dd6aa537 100644 --- a/crates/pgls_pretty_print/src/nodes/explain_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/explain_stmt.rs @@ -38,7 +38,7 @@ pub(super) fn emit_explain_stmt(e: &mut EventEmitter, n: &ExplainStmt) { fn emit_explain_option(e: &mut EventEmitter, node: &pgls_query::Node) { if let Some(NodeEnum::DefElem(def)) = &node.node { if !def.defname.is_empty() { - super::emit_word(e, &def.defname); + super::emit_keyword(e, &def.defname); } // Emit the option value if present (no equals sign for EXPLAIN) diff --git a/crates/pgls_pretty_print/src/nodes/func_call.rs b/crates/pgls_pretty_print/src/nodes/func_call.rs index 72a4d5402..0d10e40ca 100644 --- a/crates/pgls_pretty_print/src/nodes/func_call.rs +++ b/crates/pgls_pretty_print/src/nodes/func_call.rs @@ -1,7 +1,7 @@ use crate::{ CommaStyle, TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, + nodes::node_list::{emit_comma_separated_list, emit_parenthesized_list}, }; use pgls_query::{ Node, NodeEnum, @@ -10,7 +10,7 @@ use pgls_query::{ use super::string::{ emit_identifier, needs_quoting, needs_quoting_as_column_name, - needs_quoting_as_function_or_type_name, needs_quoting_except_keywords, + needs_quoting_as_function_or_type_name, needs_quoting_as_label, }; /// Get the last part of the function name (the actual function name without schema) @@ -272,7 +272,7 @@ fn emit_function_name(e: &mut EventEmitter, funcname: &[Node]) { && !matches!(*part, "overlay" | "substring") } else if index == parts.len() - 1 { // A qualified function name can be any word, keywords included. - needs_quoting_except_keywords(part) + needs_quoting_as_label(part) } else { needs_quoting_as_column_name(part) }; @@ -393,13 +393,9 @@ fn emit_sql_syntax_call(e: &mut EventEmitter, n: &FuncCall) -> bool { super::emit_node(string, e); e.token(TokenKind::R_PAREN); } - ("normalize", [string, rest @ ..]) if rest.len() <= 1 => { - let form = match rest { - [form] => match normalization_form(form) { - Some(form) => Some(form), - None => return false, - }, - _ => None, + ("normalize", [string, rest @ ..]) => { + let Some(form) = optional_normalization_form(rest) else { + return false; }; e.token(TokenKind::NORMALIZE_KW); e.token(TokenKind::L_PAREN); @@ -411,13 +407,9 @@ fn emit_sql_syntax_call(e: &mut EventEmitter, n: &FuncCall) -> bool { } e.token(TokenKind::R_PAREN); } - ("is_normalized", [string, rest @ ..]) if rest.len() <= 1 => { - let form = match rest { - [form] => match normalization_form(form) { - Some(form) => Some(form), - None => return false, - }, - _ => None, + ("is_normalized", [string, rest @ ..]) => { + let Some(form) = optional_normalization_form(rest) else { + return false; }; e.token(TokenKind::L_PAREN); emit_parenthesized_unless_simple(e, string); @@ -454,23 +446,13 @@ fn emit_sql_syntax_call(e: &mut EventEmitter, n: &FuncCall) -> bool { e.token(TokenKind::LOCAL_KW); e.token(TokenKind::R_PAREN); } - ("overlaps", [start1, end1, start2, end2]) => { + ("overlaps", [_, _, _, _]) => { e.token(TokenKind::L_PAREN); - e.token(TokenKind::L_PAREN); - super::emit_node(start1, e); - e.token(TokenKind::COMMA); - e.space(); - super::emit_node(end1, e); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &args[..2], super::emit_node); e.space(); e.token(TokenKind::OVERLAPS_KW); e.space(); - e.token(TokenKind::L_PAREN); - super::emit_node(start2, e); - e.token(TokenKind::COMMA); - e.space(); - super::emit_node(end2, e); - e.token(TokenKind::R_PAREN); + emit_parenthesized_list(e, &args[2..], super::emit_node); e.token(TokenKind::R_PAREN); } ("pg_collation_for", [expr]) => { @@ -500,6 +482,16 @@ fn emit_sql_syntax_call(e: &mut EventEmitter, n: &FuncCall) -> bool { true } +/// The optional normalization form argument of `NORMALIZE` and `IS NORMALIZED`: `Some(None)` when +/// there is none, `None` when the arguments are not a form the syntax can spell. +fn optional_normalization_form(args: &[Node]) -> Option> { + match args { + [] => Some(None), + [form] => normalization_form(form).map(Some), + _ => None, + } +} + /// The keyword of a Unicode normalization form, stored as the string `NFC`, `NFD`, `NFKC` or `NFKD`. fn normalization_form(node: &Node) -> Option { let Some(NodeEnum::AConst(a_const)) = &node.node else { diff --git a/crates/pgls_pretty_print/src/nodes/grant_role_stmt.rs b/crates/pgls_pretty_print/src/nodes/grant_role_stmt.rs index 2d1dc65a0..3eede2a3c 100644 --- a/crates/pgls_pretty_print/src/nodes/grant_role_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/grant_role_stmt.rs @@ -23,7 +23,7 @@ pub(super) fn emit_grant_role_stmt(e: &mut EventEmitter, n: &GrantRoleStmt) { if let Some(NodeEnum::DefElem(def)) = opt.node.as_ref() { e.space(); // Emit the option name - super::emit_word(e, &def.defname); + super::emit_keyword(e, &def.defname); e.space(); e.token(TokenKind::OPTION_KW); e.space(); diff --git a/crates/pgls_pretty_print/src/nodes/grant_stmt.rs b/crates/pgls_pretty_print/src/nodes/grant_stmt.rs index bfc809fe2..1834f7ae0 100644 --- a/crates/pgls_pretty_print/src/nodes/grant_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/grant_stmt.rs @@ -3,11 +3,9 @@ use pgls_query::protobuf::{DropBehavior, GrantStmt, GrantTargetType, ObjectType} use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, + nodes::node_list::{emit_comma_separated_list, emit_parenthesized_list}, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_grant_stmt(e: &mut EventEmitter, n: &GrantStmt) { emit_grant_stmt_impl(e, n, true); } @@ -243,7 +241,7 @@ fn emit_access_priv(e: &mut EventEmitter, priv_node: &pgls_query::protobuf::Acce if index > 0 { e.space(); } - super::emit_word(e, word); + super::emit_keyword(e, word); } } diff --git a/crates/pgls_pretty_print/src/nodes/grouping_set.rs b/crates/pgls_pretty_print/src/nodes/grouping_set.rs index 9be5eafe8..9a32a0d7d 100644 --- a/crates/pgls_pretty_print/src/nodes/grouping_set.rs +++ b/crates/pgls_pretty_print/src/nodes/grouping_set.rs @@ -4,8 +4,7 @@ use crate::{ }; use pgls_query::protobuf::{GroupingSet, GroupingSetKind}; -use super::node_list::emit_comma_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_comma_separated_list, emit_parenthesized_list}; pub(super) fn emit_grouping_set(e: &mut EventEmitter, n: &GroupingSet) { e.group_start(GroupKind::GroupingSet); diff --git a/crates/pgls_pretty_print/src/nodes/join_expr.rs b/crates/pgls_pretty_print/src/nodes/join_expr.rs index 491f57cbc..d2d8c110b 100644 --- a/crates/pgls_pretty_print/src/nodes/join_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/join_expr.rs @@ -3,8 +3,7 @@ use pgls_query::protobuf::{JoinExpr, JoinType}; use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; -use super::node_list::emit_comma_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_comma_separated_list, emit_parenthesized_list}; use super::string::emit_identifier_maybe_quoted; pub(super) fn emit_join_expr(e: &mut EventEmitter, n: &JoinExpr) { diff --git a/crates/pgls_pretty_print/src/nodes/json_value_expr.rs b/crates/pgls_pretty_print/src/nodes/json_value_expr.rs index b02a38a61..2eab3ee3a 100644 --- a/crates/pgls_pretty_print/src/nodes/json_value_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/json_value_expr.rs @@ -94,7 +94,7 @@ fn emit_json_format_with_prefix(e: &mut EventEmitter, format: &JsonFormat, prefi } e.token(TokenKind::FORMAT_KW); e.space(); - super::emit_word(e, "jsonb"); + super::emit_keyword(e, "jsonb"); wrote_any = true; } JsonFormatType::Undefined | JsonFormatType::JsFormatDefault => {} @@ -135,5 +135,5 @@ fn emit_encoding(e: &mut EventEmitter, label: &str, needs_space: bool) { } e.token(TokenKind::ENCODING_KW); e.space(); - super::emit_word(e, label); + super::emit_keyword(e, label); } diff --git a/crates/pgls_pretty_print/src/nodes/lock_stmt.rs b/crates/pgls_pretty_print/src/nodes/lock_stmt.rs index dfabeb6fb..02ef354d2 100644 --- a/crates/pgls_pretty_print/src/nodes/lock_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/lock_stmt.rs @@ -42,7 +42,7 @@ pub(super) fn emit_lock_stmt(e: &mut EventEmitter, n: &LockStmt) { 8 => "ACCESS EXCLUSIVE", _ => "ACCESS EXCLUSIVE", // default }; - super::emit_words(e, mode_str); + super::emit_keywords(e, mode_str); e.space(); e.token(TokenKind::MODE_KW); } diff --git a/crates/pgls_pretty_print/src/nodes/mod.rs b/crates/pgls_pretty_print/src/nodes/mod.rs index b2f44f645..6cb2e7b28 100644 --- a/crates/pgls_pretty_print/src/nodes/mod.rs +++ b/crates/pgls_pretty_print/src/nodes/mod.rs @@ -492,8 +492,8 @@ use sort_group_clause::emit_sort_group_clause; use sql_value_function::emit_sql_value_function; use stats_elem::emit_stats_elem; use string::{ - DollarQuoteHint, emit_body_literal, emit_identifier, emit_identifier_maybe_quoted, emit_string, - emit_string_identifier, emit_string_literal, emit_word, emit_words, + DollarQuoteHint, emit_body_literal, emit_identifier, emit_identifier_maybe_quoted, + emit_keyword, emit_keywords, emit_string, emit_string_identifier, emit_string_literal, }; use sub_link::emit_sub_link; use sub_plan::{emit_alternative_sub_plan, emit_sub_plan}; diff --git a/crates/pgls_pretty_print/src/nodes/partition_bound_spec.rs b/crates/pgls_pretty_print/src/nodes/partition_bound_spec.rs index c1eeaee32..b3bf2c11d 100644 --- a/crates/pgls_pretty_print/src/nodes/partition_bound_spec.rs +++ b/crates/pgls_pretty_print/src/nodes/partition_bound_spec.rs @@ -55,12 +55,12 @@ pub(super) fn emit_partition_bound_spec(e: &mut EventEmitter, n: &PartitionBound e.token(TokenKind::WITH_KW); e.space(); e.token(TokenKind::L_PAREN); - super::emit_word(e, "modulus"); + super::emit_keyword(e, "modulus"); e.space(); e.token(TokenKind::IDENT(n.modulus.to_string())); e.token(TokenKind::COMMA); e.space(); - super::emit_word(e, "remainder"); + super::emit_keyword(e, "remainder"); e.space(); e.token(TokenKind::IDENT(n.remainder.to_string())); e.token(TokenKind::R_PAREN); diff --git a/crates/pgls_pretty_print/src/nodes/partition_spec.rs b/crates/pgls_pretty_print/src/nodes/partition_spec.rs index 7f072d469..2e5e14cdc 100644 --- a/crates/pgls_pretty_print/src/nodes/partition_spec.rs +++ b/crates/pgls_pretty_print/src/nodes/partition_spec.rs @@ -16,9 +16,9 @@ pub(super) fn emit_partition_spec(e: &mut EventEmitter, n: &PartitionSpec) { // Emit partition strategy // PartitionStrategy: Undefined = 0, List = 1, Range = 2, Hash = 3 match n.strategy { - 1 => super::emit_word(e, "list"), + 1 => super::emit_keyword(e, "list"), 2 => e.token(TokenKind::RANGE_KW), - 3 => super::emit_word(e, "hash"), + 3 => super::emit_keyword(e, "hash"), _ => {} } diff --git a/crates/pgls_pretty_print/src/nodes/range_function.rs b/crates/pgls_pretty_print/src/nodes/range_function.rs index 1aa9875c1..4ee9a9712 100644 --- a/crates/pgls_pretty_print/src/nodes/range_function.rs +++ b/crates/pgls_pretty_print/src/nodes/range_function.rs @@ -3,8 +3,7 @@ use pgls_query::protobuf::RangeFunction; use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; -use super::node_list::emit_comma_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_comma_separated_list, emit_parenthesized_list}; /// Emits a function of a `FROM` item. A cast there must keep the `CAST(...)` spelling. fn emit_function(e: &mut EventEmitter, node: &pgls_query::Node) { diff --git a/crates/pgls_pretty_print/src/nodes/range_table_func.rs b/crates/pgls_pretty_print/src/nodes/range_table_func.rs index 93f730817..05baf1861 100644 --- a/crates/pgls_pretty_print/src/nodes/range_table_func.rs +++ b/crates/pgls_pretty_print/src/nodes/range_table_func.rs @@ -1,12 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, + nodes::node_list::{emit_comma_separated_list, emit_parenthesized_list}, }; use pgls_query::{NodeEnum, protobuf::RangeTableFunc}; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_range_table_func(e: &mut EventEmitter, n: &RangeTableFunc) { e.group_start(GroupKind::RangeTableFunc); diff --git a/crates/pgls_pretty_print/src/nodes/range_table_sample.rs b/crates/pgls_pretty_print/src/nodes/range_table_sample.rs index b926b850f..e8e819f3f 100644 --- a/crates/pgls_pretty_print/src/nodes/range_table_sample.rs +++ b/crates/pgls_pretty_print/src/nodes/range_table_sample.rs @@ -1,12 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_dot_separated_list, + nodes::node_list::{emit_dot_separated_list, emit_parenthesized_list}, }; use pgls_query::protobuf::RangeTableSample; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_range_table_sample(e: &mut EventEmitter, n: &RangeTableSample) { e.group_start(GroupKind::RangeTableSample); diff --git a/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs b/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs index 33565acb1..5a1abd6ae 100644 --- a/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs @@ -18,7 +18,7 @@ pub(super) fn emit_reindex_stmt(e: &mut EventEmitter, n: &ReindexStmt) { emit_parenthesized_list(e, &n.params, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { // Emit option name - super::emit_word(emitter, &def.defname); + super::emit_keyword(emitter, &def.defname); // Emit option value if present if let Some(ref arg) = def.arg { emitter.space(); diff --git a/crates/pgls_pretty_print/src/nodes/string.rs b/crates/pgls_pretty_print/src/nodes/string.rs index 0f4838715..caab0d6c3 100644 --- a/crates/pgls_pretty_print/src/nodes/string.rs +++ b/crates/pgls_pretty_print/src/nodes/string.rs @@ -65,25 +65,22 @@ pub(super) fn emit_type_identifier_maybe_quoted(e: &mut EventEmitter, value: &st } } -/// Emits a word the grammar reads case-insensitively, such as an option name, in the keyword case. -pub(super) fn emit_word(e: &mut EventEmitter, word: &str) { +/// Emits a word the grammar reads case-insensitively in the keyword case. It need not be a +/// keyword: option and privilege names such as `usage` are plain words. +pub(super) fn emit_keyword(e: &mut EventEmitter, word: &str) { match TokenKind::from_keyword(word) { Some(keyword) => e.token(keyword), None => e.token(TokenKind::WORD(word.to_string())), } } -pub(super) fn emit_keyword(e: &mut EventEmitter, keyword: &str) { - emit_word(e, keyword); -} - /// Emits words separated by spaces, such as `ACCESS EXCLUSIVE`, in the keyword case. -pub(super) fn emit_words(e: &mut EventEmitter, words: &str) { +pub(super) fn emit_keywords(e: &mut EventEmitter, words: &str) { for (index, word) in words.split(' ').enumerate() { if index > 0 { e.space(); } - emit_word(e, word); + emit_keyword(e, word); } } @@ -196,7 +193,7 @@ pub(super) fn needs_quoting_as_column_name(value: &str) -> bool { /// Whether a name that may be any word, keywords included, must be quoted. The grammar spells it /// as `ColLabel`, the trailing part of a qualified function name for instance. -pub(super) fn needs_quoting_except_keywords(value: &str) -> bool { +pub(super) fn needs_quoting_as_label(value: &str) -> bool { needs_quoting(value) && keyword_category(value).is_none() } diff --git a/crates/pgls_pretty_print/src/nodes/table_like_clause.rs b/crates/pgls_pretty_print/src/nodes/table_like_clause.rs index 1b9905d6c..71bfbdf67 100644 --- a/crates/pgls_pretty_print/src/nodes/table_like_clause.rs +++ b/crates/pgls_pretty_print/src/nodes/table_like_clause.rs @@ -57,7 +57,7 @@ pub(super) fn emit_table_like_clause(e: &mut EventEmitter, n: &TableLikeClause) e.line(LineType::SoftOrSpace); e.token(TokenKind::INCLUDING_KW); e.space(); - super::emit_word(e, name); + super::emit_keyword(e, name); } } } diff --git a/crates/pgls_pretty_print/src/nodes/vacuum_stmt.rs b/crates/pgls_pretty_print/src/nodes/vacuum_stmt.rs index e85af0b99..2e9d47af5 100644 --- a/crates/pgls_pretty_print/src/nodes/vacuum_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/vacuum_stmt.rs @@ -5,8 +5,7 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::node_list::emit_comma_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_comma_separated_list, emit_parenthesized_list}; pub(super) fn emit_vacuum_stmt(e: &mut EventEmitter, n: &VacuumStmt) { e.group_start(GroupKind::VacuumStmt); @@ -23,7 +22,7 @@ pub(super) fn emit_vacuum_stmt(e: &mut EventEmitter, n: &VacuumStmt) { emit_parenthesized_list(e, &n.options, |node, emitter| { if let Some(NodeEnum::DefElem(def)) = node.node.as_ref() { // Emit option name - super::emit_word(emitter, &def.defname); + super::emit_keyword(emitter, &def.defname); // Emit option value if present if let Some(ref arg) = def.arg { emitter.space(); diff --git a/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs b/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs index f664b9241..8915a742c 100644 --- a/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs @@ -21,7 +21,8 @@ fn emit_set_arg(node: &Node, e: &mut EventEmitter) { // Emit as identifier (no quotes) if it looks like a simple identifier // This includes schema names, role names, etc. - if is_simple_identifier(val) { + // An unquoted word is folded to lowercase: `SET datestyle = German` would set `german`. + if !super::string::needs_quoting(val) { e.group_start(GroupKind::String); e.token(TokenKind::IDENT(val.clone())); e.group_end(); @@ -34,12 +35,6 @@ fn emit_set_arg(node: &Node, e: &mut EventEmitter) { super::emit_node(node, e); } -/// Whether a string reads the same written as an unquoted word. An unquoted word is folded to -/// lowercase, so `SET datestyle = German` would set `german`. -fn is_simple_identifier(s: &str) -> bool { - !super::string::needs_quoting(s) -} - /// Emit a dot-separated variable name, quoting parts that need it fn emit_variable_name(e: &mut EventEmitter, name: &str) { let parts: Vec<&str> = name.split('.').collect(); @@ -47,7 +42,7 @@ fn emit_variable_name(e: &mut EventEmitter, name: &str) { if i > 0 { e.token(TokenKind::DOT); } - if is_simple_identifier(part) { + if !super::string::needs_quoting(part) { e.token(TokenKind::IDENT(part.to_string())); } else { // Quote the identifier @@ -226,7 +221,7 @@ fn emit_variable_set_stmt_inner(e: &mut EventEmitter, n: &VariableSetStmt) { // Special syntax: SET SESSION CHARACTERISTICS AS TRANSACTION ... e.token(TokenKind::SESSION_KW); e.space(); - super::emit_word(e, "characteristics"); + super::emit_keyword(e, "characteristics"); e.space(); e.token(TokenKind::AS_KW); e.space(); @@ -243,7 +238,7 @@ fn emit_variable_set_stmt_inner(e: &mut EventEmitter, n: &VariableSetStmt) { // SET TRANSACTION SNAPSHOT 'snapshot_id' e.token(TokenKind::TRANSACTION_KW); e.space(); - super::emit_word(e, "snapshot"); + super::emit_keyword(e, "snapshot"); e.space(); // The snapshot id is in args as a string if !n.args.is_empty() { @@ -361,7 +356,7 @@ fn emit_transaction_option(e: &mut EventEmitter, def: &pgls_query::protobuf::Def } _ => { // Unknown transaction option - emit as identifier - super::emit_word(e, &def.defname); + super::emit_keyword(e, &def.defname); if let Some(ref arg) = def.arg { e.space(); super::emit_node(arg, e); diff --git a/crates/pgls_pretty_print/src/nodes/view_stmt.rs b/crates/pgls_pretty_print/src/nodes/view_stmt.rs index 84c7734e7..561bca24f 100644 --- a/crates/pgls_pretty_print/src/nodes/view_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/view_stmt.rs @@ -5,8 +5,7 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::node_list::emit_comma_separated_list; -use super::node_list::emit_parenthesized_list; +use super::node_list::{emit_comma_separated_list, emit_parenthesized_list}; pub(super) fn emit_view_stmt(e: &mut EventEmitter, n: &ViewStmt) { emit_view_stmt_impl(e, n, true); diff --git a/crates/pgls_pretty_print/src/nodes/xml_expr.rs b/crates/pgls_pretty_print/src/nodes/xml_expr.rs index 00577c653..d25f9c9f6 100644 --- a/crates/pgls_pretty_print/src/nodes/xml_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/xml_expr.rs @@ -1,12 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, - nodes::node_list::emit_comma_separated_list, + nodes::node_list::{emit_comma_separated_list, emit_parenthesized_list}, }; use pgls_query::protobuf::{XmlExpr, XmlOptionType}; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_xml_expr(e: &mut EventEmitter, n: &XmlExpr) { e.group_start(GroupKind::XmlExpr); diff --git a/crates/pgls_pretty_print/src/nodes/xml_serialize.rs b/crates/pgls_pretty_print/src/nodes/xml_serialize.rs index 82c9ca638..a4847d91e 100644 --- a/crates/pgls_pretty_print/src/nodes/xml_serialize.rs +++ b/crates/pgls_pretty_print/src/nodes/xml_serialize.rs @@ -7,17 +7,17 @@ use pgls_query::protobuf::{XmlOptionType, XmlSerialize}; pub(super) fn emit_xml_serialize(e: &mut EventEmitter, n: &XmlSerialize) { e.group_start(GroupKind::XmlSerialize); - super::emit_word(e, "xmlserialize"); + super::emit_keyword(e, "xmlserialize"); e.token(TokenKind::L_PAREN); // XmlOptionType: XmloptionDocument=1, XmloptionContent=2 match n.xmloption() { XmlOptionType::XmloptionDocument => { - super::emit_word(e, "document"); + super::emit_keyword(e, "document"); e.space(); } _ => { - super::emit_word(e, "content"); + super::emit_keyword(e, "content"); e.space(); } } @@ -38,7 +38,7 @@ pub(super) fn emit_xml_serialize(e: &mut EventEmitter, n: &XmlSerialize) { // INDENT option if n.indent { e.space(); - super::emit_word(e, "indent"); + super::emit_keyword(e, "indent"); } e.token(TokenKind::R_PAREN); diff --git a/crates/pgls_pretty_print/src/renderer.rs b/crates/pgls_pretty_print/src/renderer.rs index 4edaf85b3..9f0e61cab 100644 --- a/crates/pgls_pretty_print/src/renderer.rs +++ b/crates/pgls_pretty_print/src/renderer.rs @@ -120,9 +120,7 @@ impl Renderer { group_events: &[LayoutEvent], trailing_width: usize, ) -> Result<(), std::fmt::Error> { - if let Some(single_line) = self.try_single_line(group_events) - && self.fits(&single_line, trailing_width) - { + if let Some(single_line) = self.single_line_if_fits(group_events, trailing_width) { self.write_text(&single_line)?; return Ok(()); } @@ -131,17 +129,6 @@ impl Renderer { self.render_events_with_breaks(&group_events[1..group_events.len() - 1], trailing_width) } - /// Whether `text` fits on the current line, followed by `trailing_width` columns that cannot - /// move to the next line. Only the first line of a text spanning several lines, a function - /// body for instance, sits on the current one. - fn fits(&self, text: &str, trailing_width: usize) -> bool { - let width = match text.split_once('\n') { - Some((first_line, _)) => first_line.len(), - None => text.len() + trailing_width, - }; - self.effective_line_length() + width <= self.config.max_line_length - } - /// The width of the text that follows a group without a break opportunity in between, such as /// the comma after a list item. `outer_trailing_width` is what follows the enclosing events. fn trailing_width(&self, events: &[LayoutEvent], outer_trailing_width: usize) -> usize { @@ -189,7 +176,7 @@ impl Renderer { LayoutEvent::Token(token) => { // This path is only taken when the enclosing group broke, so the statement // already spans several lines and the terminator can stand alone. A statement - // that fits is rendered by try_single_line, which never reaches this code, and + // that fits is rendered by single_line_if_fits, which never reaches this code, and // therefore keeps its semicolon attached. if self.config.isolate_semicolon && matches!(token, TokenKind::SEMICOLON) { self.write_line_break()?; @@ -241,52 +228,60 @@ impl Renderer { Ok(()) } - fn try_single_line(&self, group_events: &[LayoutEvent]) -> Option { + /// The group on one line, if it can be collapsed and fits on the current line followed by + /// `trailing_width` columns that cannot move to the next line. Only the first line of a text + /// spanning several lines, a function body for instance, sits on the current one. + /// + /// Measuring stops as soon as the line is full, so a large group that cannot fit is not + /// rendered in full for every level it is nested in. + fn single_line_if_fits( + &self, + group_events: &[LayoutEvent], + trailing_width: usize, + ) -> Option { + let available = self + .config + .max_line_length + .saturating_sub(self.effective_line_length()); let mut buffer = String::new(); - let mut has_hard_breaks = false; + // Set once the text reaches a line break, after which the width no longer matters. + let mut first_line_fits = false; for event in group_events { match event { - LayoutEvent::Token(token) => { - let text = token.render(&self.config); - buffer.push_str(&text); - } - LayoutEvent::Space => { - buffer.push(' '); - } - LayoutEvent::Line(LineType::Hard) => { - has_hard_breaks = true; - break; - } - LayoutEvent::Line(LineType::Soft) => { - // soft lines disappear in single-line mode (no space) - } - LayoutEvent::Line(LineType::SoftOrSpace) => { - buffer.push(' '); // Becomes space in single-line mode - } - LayoutEvent::Line(LineType::Fill) => { - buffer.push(' '); - } - LayoutEvent::Line(LineType::FillNoSpace) => {} + LayoutEvent::Token(token) => buffer.push_str(&token.render(&self.config)), + LayoutEvent::Space + | LayoutEvent::Line(LineType::SoftOrSpace) + | LayoutEvent::Line(LineType::Fill) => buffer.push(' '), + // Collapsing would push code behind a `--` comment or flatten a multi-line block + // comment into the surrounding expression. + LayoutEvent::Line(LineType::Hard) => return None, LayoutEvent::Comment { text, line_comment } => { if *line_comment || text.contains('\n') { - // Collapsing would push code behind a `--` comment or flatten a - // multi-line block comment into the surrounding expression. - has_hard_breaks = true; - break; + return None; } buffer.push_str(text); } - LayoutEvent::GroupStart { .. } | LayoutEvent::GroupEnd => { - // skip group markers for single line test - } - LayoutEvent::IndentStart | LayoutEvent::IndentEnd => { - // skip indent changes for single line test + LayoutEvent::Line(LineType::Soft | LineType::FillNoSpace) + | LayoutEvent::GroupStart { .. } + | LayoutEvent::GroupEnd + | LayoutEvent::IndentStart + | LayoutEvent::IndentEnd => {} + } + + if !first_line_fits { + match buffer.split_once('\n') { + Some((first_line, _)) if first_line.len() <= available => { + first_line_fits = true; + } + Some(_) => return None, + None if buffer.len() + trailing_width > available => return None, + None => {} } } } - if has_hard_breaks { None } else { Some(buffer) } + Some(buffer) } fn handle_line(&mut self, line_type: &LineType) -> Result<(), std::fmt::Error> { diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap index 98d801fbd..989d85076 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap @@ -1089,8 +1089,10 @@ as select ((cast('2022-12-01' as date) + cast('1 day' as interval)) at time zone 'UTC') as atz, extract(day from now()) as extr, - ((now(), cast('1 day' - as interval)) overlaps (current_timestamp(2), cast('1 day' as interval))) + ((now(), cast('1 day' as interval)) overlaps ( + current_timestamp(2), + cast('1 day' as interval) + )) as o, ('foo' is normalized) as isn, ('foo' is nfkc normalized) as isnn, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_100.snap index 76ce77037..8e855de9c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_100.snap @@ -461,89 +461,121 @@ order by 1, 2; select - ((cast('2000-11-27' as timestamp with time zone), cast('2000-11-28' - as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' - as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) + (( + cast('2000-11-27' as timestamp with time zone), + cast('2000-11-28' as timestamp with time zone) + ) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('2000-11-30' as timestamp with time zone) + )) as "True"; select - ((cast('2000-11-26' as timestamp with time zone), cast('2000-11-27' - as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' - as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) + (( + cast('2000-11-26' as timestamp with time zone), + cast('2000-11-27' as timestamp with time zone) + ) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('2000-11-30' as timestamp with time zone) + )) as "False"; select - ((cast('2000-11-27' as timestamp with time zone), cast('2000-11-28' - as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' - as timestamp with time zone), cast('1 day' as interval))) + (( + cast('2000-11-27' as timestamp with time zone), + cast('2000-11-28' as timestamp with time zone) + ) overlaps (cast('2000-11-27 12:00' as timestamp with time zone), cast('1 day' as interval))) as "True"; select - ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' - as interval)) overlaps (cast('2000-11-27 12:00' as timestamp with time zone), cast('2000-11-30' - as timestamp with time zone))) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('2000-11-30' as timestamp with time zone) + )) as "False"; select - ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' - as interval)) overlaps (cast('2000-11-27' as timestamp with time zone), cast('12 hours' - as interval))) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27' as timestamp with time zone), + cast('12 hours' as interval) + )) as "True"; select - ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' - as interval)) overlaps (cast('2000-11-27 12:00' as timestamp with time zone), cast('12 hours' - as interval))) + ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('12 hours' as interval) + )) as "False"; select - ((cast('2000-11-27' as timestamp), cast('2000-11-28' - as timestamp)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('2000-11-30' as timestamp))) + ((cast('2000-11-27' as timestamp), cast('2000-11-28' as timestamp)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('2000-11-30' as timestamp) + )) as "True"; select - ((cast('2000-11-26' as timestamp), cast('2000-11-27' - as timestamp)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('2000-11-30' as timestamp))) + ((cast('2000-11-26' as timestamp), cast('2000-11-27' as timestamp)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('2000-11-30' as timestamp) + )) as "False"; select - ((cast('2000-11-27' as timestamp), cast('2000-11-28' - as timestamp)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('1 day' as interval))) + ((cast('2000-11-27' as timestamp), cast('2000-11-28' as timestamp)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('1 day' as interval) + )) as "True"; select - ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps (cast('2000-11-27 12:00' - as timestamp), cast('2000-11-30' as timestamp))) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('2000-11-30' as timestamp) + )) as "False"; select - ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps (cast('2000-11-27' - as timestamp), cast('12 hours' as interval))) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27' as timestamp), + cast('12 hours' as interval) + )) as "True"; select - ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps (cast('2000-11-27 12:00' - as timestamp), cast('12 hours' as interval))) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('12 hours' as interval) + )) as "False"; select - ((cast('00:00' as time), cast('01:00' as time)) overlaps (cast('00:30' as time), cast('01:30' - as time))) + ((cast('00:00' as time), cast('01:00' as time)) overlaps ( + cast('00:30' as time), + cast('01:30' as time) + )) as "True"; select - ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('00:30' - as time), cast('1 hour' as interval))) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps ( + cast('00:30' as time), + cast('1 hour' as interval) + )) as "True"; select - ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('01:30' - as time), cast('1 hour' as interval))) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps ( + cast('01:30' as time), + cast('1 hour' as interval) + )) as "False"; select - ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('01:30' as time), cast('1 day' - as interval))) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps ( + cast('01:30' as time), + cast('1 day' as interval) + )) as "False"; create table temp_timestamp (f1 timestamp with time zone); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_80.snap index 3a6bd3676..a63c5fffc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__horology_80.snap @@ -524,95 +524,133 @@ order by 1, 2; select - ((cast('2000-11-27' as timestamp with time zone), cast('2000-11-28' - as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' - as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) + (( + cast('2000-11-27' as timestamp with time zone), + cast('2000-11-28' as timestamp with time zone) + ) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('2000-11-30' as timestamp with time zone) + )) as "True"; select - ((cast('2000-11-26' as timestamp with time zone), cast('2000-11-27' - as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' - as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) + (( + cast('2000-11-26' as timestamp with time zone), + cast('2000-11-27' as timestamp with time zone) + ) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('2000-11-30' as timestamp with time zone) + )) as "False"; select - ((cast('2000-11-27' as timestamp with time zone), cast('2000-11-28' - as timestamp with time zone)) overlaps (cast('2000-11-27 12:00' - as timestamp with time zone), cast('1 day' as interval))) + (( + cast('2000-11-27' as timestamp with time zone), + cast('2000-11-28' as timestamp with time zone) + ) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('1 day' as interval) + )) as "True"; select - ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' - as interval)) overlaps (cast('2000-11-27 12:00' - as timestamp with time zone), cast('2000-11-30' as timestamp with time zone))) + (( + cast('2000-11-27' as timestamp with time zone), + cast('12 hours' as interval) + ) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('2000-11-30' as timestamp with time zone) + )) as "False"; select - ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' - as interval)) overlaps (cast('2000-11-27' - as timestamp with time zone), cast('12 hours' as interval))) + (( + cast('2000-11-27' as timestamp with time zone), + cast('12 hours' as interval) + ) overlaps ( + cast('2000-11-27' as timestamp with time zone), + cast('12 hours' as interval) + )) as "True"; select - ((cast('2000-11-27' as timestamp with time zone), cast('12 hours' - as interval)) overlaps (cast('2000-11-27 12:00' - as timestamp with time zone), cast('12 hours' as interval))) + (( + cast('2000-11-27' as timestamp with time zone), + cast('12 hours' as interval) + ) overlaps ( + cast('2000-11-27 12:00' as timestamp with time zone), + cast('12 hours' as interval) + )) as "False"; select - ((cast('2000-11-27' as timestamp), cast('2000-11-28' - as timestamp)) overlaps (cast('2000-11-27 12:00' - as timestamp), cast('2000-11-30' as timestamp))) + ((cast('2000-11-27' as timestamp), cast('2000-11-28' as timestamp)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('2000-11-30' as timestamp) + )) as "True"; select - ((cast('2000-11-26' as timestamp), cast('2000-11-27' - as timestamp)) overlaps (cast('2000-11-27 12:00' - as timestamp), cast('2000-11-30' as timestamp))) + ((cast('2000-11-26' as timestamp), cast('2000-11-27' as timestamp)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('2000-11-30' as timestamp) + )) as "False"; select - ((cast('2000-11-27' as timestamp), cast('2000-11-28' - as timestamp)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('1 day' - as interval))) + ((cast('2000-11-27' as timestamp), cast('2000-11-28' as timestamp)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('1 day' as interval) + )) as "True"; select - ((cast('2000-11-27' as timestamp), cast('12 hours' - as interval)) overlaps (cast('2000-11-27 12:00' - as timestamp), cast('2000-11-30' as timestamp))) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('2000-11-30' as timestamp) + )) as "False"; select - ((cast('2000-11-27' as timestamp), cast('12 hours' - as interval)) overlaps (cast('2000-11-27' as timestamp), cast('12 hours' - as interval))) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27' as timestamp), + cast('12 hours' as interval) + )) as "True"; select - ((cast('2000-11-27' as timestamp), cast('12 hours' - as interval)) overlaps (cast('2000-11-27 12:00' as timestamp), cast('12 hours' - as interval))) + ((cast('2000-11-27' as timestamp), cast('12 hours' as interval)) overlaps ( + cast('2000-11-27 12:00' as timestamp), + cast('12 hours' as interval) + )) as "False"; select - ((cast('00:00' as time), cast('01:00' as time)) overlaps (cast('00:30' - as time), cast('01:30' as time))) + ((cast('00:00' as time), cast('01:00' as time)) overlaps ( + cast('00:30' as time), + cast('01:30' as time) + )) as "True"; select - ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('00:30' - as time), cast('1 hour' as interval))) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps ( + cast('00:30' as time), + cast('1 hour' as interval) + )) as "True"; select - ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('01:30' - as time), cast('1 hour' as interval))) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps ( + cast('01:30' as time), + cast('1 hour' as interval) + )) as "False"; select - ((cast('00:00' as time), cast('1 hour' as interval)) overlaps (cast('01:30' - as time), cast('1 day' as interval))) + ((cast('00:00' as time), cast('1 hour' as interval)) overlaps ( + cast('01:30' as time), + cast('1 day' as interval) + )) as "False"; create table temp_timestamp (f1 timestamp with time zone); From ff21e651912d6ab4d3b012b53a886afdf90c2e41 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 12 Oct 2026 16:49:09 +0000 Subject: [PATCH 5/7] refactor(workspace): simplify blank-line and SQL body handling in formatting Collapse blank lines with one pass over the gap and trim the start and end of the file at the call site, instead of a position-aware state machine. The layout of a reformatted SQL function body now lives in set_formatted_sql_fn_body. --- crates/pgls_workspace/src/workspace/server.rs | 121 ++++++------------ .../src/workspace/server/sql_function.rs | 81 +++++++----- 2 files changed, 84 insertions(+), 118 deletions(-) diff --git a/crates/pgls_workspace/src/workspace/server.rs b/crates/pgls_workspace/src/workspace/server.rs index 400f19936..6c51bdab8 100644 --- a/crates/pgls_workspace/src/workspace/server.rs +++ b/crates/pgls_workspace/src/workspace/server.rs @@ -1104,12 +1104,7 @@ impl Workspace for WorkspaceServer { continue; }; - // A body that formatting leaves alone keeps its own layout. A reformatted one - // goes on the lines between its dollar quotes. - if formatted.trim() == text.trim() { - continue; - } - formatted_sql_fn_bodies.insert(parent_id, format!("\n{formatted}\n")); + formatted_sql_fn_bodies.insert(parent_id, formatted); } } @@ -1121,7 +1116,7 @@ impl Workspace for WorkspaceServer { let mut last_end = 0usize; // Formatting a range leaves everything outside its statements as written. - let normalize_gaps = params.range.is_none(); + let collapses_blank_lines = params.range.is_none(); for (id, stmt_range, text, ast_result) in format_candidates { if id.is_child() { @@ -1134,13 +1129,13 @@ impl Workspace for WorkspaceServer { // Preserve the standalone comments that precede this statement, with at most one // blank line between statements and none before the first. let gap = &source[last_end..stmt_start]; - if normalize_gaps { - let position = if last_end == 0 { - GapPosition::Start + if collapses_blank_lines { + let gap = collapse_blank_lines(gap); + formatted_output.push_str(if last_end == 0 { + gap.trim_start() } else { - GapPosition::Between - }; - formatted_output.push_str(&normalize_gap(gap, position)); + &gap + }); } else { formatted_output.push_str(gap); } @@ -1158,7 +1153,7 @@ impl Workspace for WorkspaceServer { Ok(ast) => { let mut ast = ast; if let Some(formatted_sql_fn_body) = formatted_sql_fn_bodies.get(&id) { - sql_function::set_sql_fn_body(&mut ast, formatted_sql_fn_body); + sql_function::set_formatted_sql_fn_body(&mut ast, formatted_sql_fn_body); } match pgls_pretty_print::format_statement(&ast, &text, &config) { @@ -1214,16 +1209,22 @@ impl Workspace for WorkspaceServer { } } - // Preserve any trailing text or comments after the last statement. - if normalize_gaps { - let position = if last_end == 0 { - GapPosition::Whole + // Preserve any trailing text or comments after the last statement, without blank lines + // at the end of the file but with its final line break. + let rest = &source[last_end..]; + if collapses_blank_lines { + let rest = collapse_blank_lines(rest); + let rest = if last_end == 0 { + rest.trim() } else { - GapPosition::End + rest.trim_end() }; - formatted_output.push_str(&normalize_gap(&source[last_end..], position)); + formatted_output.push_str(rest); + if source.ends_with('\n') && !formatted_output.is_empty() { + formatted_output.push('\n'); + } } else { - formatted_output.push_str(&source[last_end..]); + formatted_output.push_str(rest); } Ok(PullFormattingResult { @@ -1394,74 +1395,28 @@ fn is_dir(path: &Path) -> bool { path.is_dir() || (path.is_symlink() && fs::read_link(path).is_ok_and(|path| path.is_dir())) } -/// Where the text between two statements sits in the file. -#[derive(Clone, Copy, PartialEq, Eq)] -enum GapPosition { - /// Before the first statement. - Start, - /// Between two statements. - Between, - /// After the last statement. - End, - /// The whole file, which has no statement. - Whole, -} - -/// Normalizes the blank lines in the text between statements, which only holds whitespace and -/// comments: at most one blank line between two statements, and none at the start or the end of -/// the file. Comments and the line breaks around them are kept, and so is the final line break. -fn normalize_gap(gap: &str, position: GapPosition) -> String { - let at_start = matches!(position, GapPosition::Start | GapPosition::Whole); - let at_end = matches!(position, GapPosition::End | GapPosition::Whole); - - let mut lines: Vec<&str> = gap.split('\n').collect(); - // Without a line break the gap sits inside one line, between two statements for instance. - if lines.len() == 1 { - return match (at_start, at_end) { - (_, true) => gap.trim_end().to_string(), - (true, false) => String::new(), - (false, false) => gap.to_string(), - }; - } - - // The first line ends the line of the previous statement and the last one starts the line of - // the next statement. Only the lines in between are whole lines. - let first = lines.remove(0); - let last = lines.pop().unwrap_or_default(); - - let mut kept: Vec<&str> = Vec::new(); - if !(at_start && first.trim().is_empty()) { - kept.push(first); - } - // Whether the last kept line is a blank one, which the first line never is. - let mut follows_blank = false; - for line in lines { +/// Keeps at most one blank line in `text`, which only holds whitespace and comments. +fn collapse_blank_lines(text: &str) -> String { + let mut result = String::with_capacity(text.len()); + // Line breaks since the last text that is not whitespace. Two make a blank line. + let mut line_breaks = 0; + for line in text.split_inclusive('\n') { let is_blank = line.trim().is_empty(); - if is_blank && (follows_blank || kept.is_empty()) { + let ends_line = line.ends_with('\n'); + if is_blank && ends_line { + line_breaks += 1; + if line_breaks <= 2 { + result.push('\n'); + } continue; } - kept.push(if is_blank { "" } else { line }); - follows_blank = is_blank; - } - if at_end { - if follows_blank { - kept.pop(); + result.push_str(line); + if !is_blank { + line_breaks = usize::from(ends_line); } - let mut result = kept.join("\n"); - if last.trim().is_empty() { - result.push('\n'); - } else { - if !kept.is_empty() { - result.push('\n'); - } - result.push_str(last); - } - return result; } - - kept.push(last); - kept.join("\n") + result } /// Put psql named parameters back where the formatter printed their placeholders. diff --git a/crates/pgls_workspace/src/workspace/server/sql_function.rs b/crates/pgls_workspace/src/workspace/server/sql_function.rs index 8ac74592c..02b9ff36c 100644 --- a/crates/pgls_workspace/src/workspace/server/sql_function.rs +++ b/crates/pgls_workspace/src/workspace/server/sql_function.rs @@ -123,50 +123,53 @@ pub fn get_sql_fn_body(ast: &pgls_query::NodeEnum, content: &str) -> Option' for LANGUAGE SQL functions. -/// Returns true when a body was replaced. -pub fn set_sql_fn_body(ast: &mut pgls_query::NodeEnum, new_body: &str) -> bool { - let create_fn = match ast { - pgls_query::NodeEnum::CreateFunctionStmt(cf) => cf, - _ => return false, +/// Puts the formatted body into `CREATE FUNCTION ... AS ''` for a `LANGUAGE sql` function. +/// +/// A reformatted body goes on lines of its own between the quotes. A body that formatting leaves +/// alone keeps the layout it was written with. Returns true when the body was replaced. +pub fn set_formatted_sql_fn_body(ast: &mut pgls_query::NodeEnum, formatted: &str) -> bool { + let Some(body) = sql_fn_body_mut(ast) else { + return false; }; - let language = pgls_query_ext::utils::find_option_value(create_fn, "language"); - if language.as_deref() != Some("sql") { + if body.trim() == formatted.trim() { return false; } - for option in &mut create_fn.options { - let Some(pgls_query::NodeEnum::DefElem(def_elem)) = option.node.as_mut() else { - continue; - }; + *body = format!("\n{formatted}\n"); + true +} - if def_elem.defname != "as" { - continue; - } +fn sql_fn_body_mut(ast: &mut pgls_query::NodeEnum) -> Option<&mut String> { + let pgls_query::NodeEnum::CreateFunctionStmt(create_fn) = ast else { + return None; + }; - let Some(arg) = def_elem.arg.as_mut() else { - continue; - }; + let language = pgls_query_ext::utils::find_option_value(create_fn, "language"); + if language.as_deref() != Some("sql") { + return None; + } - match arg.node.as_mut() { - Some(pgls_query::NodeEnum::String(s)) => { - s.sval = new_body.to_string(); - return true; + let def_elem = create_fn + .options + .iter_mut() + .find_map(|option| match option.node.as_mut() { + Some(pgls_query::NodeEnum::DefElem(def_elem)) if def_elem.defname == "as" => { + Some(def_elem) } - Some(pgls_query::NodeEnum::List(list)) => { - if list.items.len() == 1 - && let Some(pgls_query::NodeEnum::String(s)) = list.items[0].node.as_mut() - { - s.sval = new_body.to_string(); - return true; - } + _ => None, + })?; + + match def_elem.arg.as_mut()?.node.as_mut()? { + pgls_query::NodeEnum::String(s) => Some(&mut s.sval), + pgls_query::NodeEnum::List(list) if list.items.len() == 1 => { + match list.items[0].node.as_mut()? { + pgls_query::NodeEnum::String(s) => Some(&mut s.sval), + _ => None, } - _ => {} } + _ => None, } - - false } #[cfg(test)] @@ -266,8 +269,7 @@ mod tests { let mut ast = pgls_query::parse(input).unwrap().into_root().unwrap(); - let changed = set_sql_fn_body(&mut ast, "select $1 + $2;"); - assert!(changed); + assert!(set_formatted_sql_fn_body(&mut ast, "select $1 + $2;")); let create_fn = match &ast { pgls_query::NodeEnum::CreateFunctionStmt(stmt) => stmt, @@ -275,6 +277,15 @@ mod tests { }; let body = pgls_query_ext::utils::find_option_value(create_fn, "as"); - assert_eq!(body, Some("select $1 + $2;".to_string())); + assert_eq!(body, Some("\nselect $1 + $2;\n".to_string())); + } + + #[test] + fn an_unchanged_sql_function_body_keeps_its_layout() { + let input = "CREATE FUNCTION one() RETURNS integer AS $$\n select 1;\n$$ LANGUAGE SQL;"; + + let mut ast = pgls_query::parse(input).unwrap().into_root().unwrap(); + + assert!(!set_formatted_sql_fn_body(&mut ast, "select 1;")); } } From 093811021f65895387a5299e583f7f8a8a9ee303 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 12 Oct 2026 17:01:03 +0000 Subject: [PATCH 6/7] refactor(pretty-print): follow existing patterns in the formatter fixes - Import emit_parenthesized_list the way each file already imported node_list helpers, inline where it used full paths - Reuse emit_keywords for privilege names and emit_parenthesized_list for exclusion constraint elements - Reuse the self-contained expression check of casts for the operands of SQL-standard syntax - Spell EXTRACT fields with emit_keyword - Drop an unreachable branch for time zone types - Build the one-off WASM format workspace with createWorkspace --- .../src/nodes/access_priv.rs | 13 +--- .../src/nodes/alter_foreign_server_stmt.rs | 6 +- .../src/nodes/alter_operator_stmt.rs | 2 +- .../pgls_pretty_print/src/nodes/constraint.rs | 72 ++++++++----------- .../src/nodes/create_enum_stmt.rs | 3 +- .../src/nodes/create_foreign_server_stmt.rs | 6 +- .../src/nodes/create_table_as_stmt.rs | 6 +- .../src/nodes/create_table_space_stmt.rs | 3 +- .../src/nodes/create_user_mapping_stmt.rs | 3 +- .../src/nodes/dropdb_stmt.rs | 3 +- .../src/nodes/execute_stmt.rs | 3 +- .../pgls_pretty_print/src/nodes/func_call.rs | 29 ++------ .../pgls_pretty_print/src/nodes/grant_stmt.rs | 7 +- .../src/nodes/import_foreign_schema_stmt.rs | 6 +- .../pgls_pretty_print/src/nodes/index_elem.rs | 4 +- .../pgls_pretty_print/src/nodes/index_stmt.rs | 3 +- .../src/nodes/infer_clause.rs | 3 +- .../pgls_pretty_print/src/nodes/int_list.rs | 4 +- .../pgls_pretty_print/src/nodes/oid_list.rs | 4 +- .../src/nodes/on_conflict_expr.rs | 4 +- .../src/nodes/prepare_stmt.rs | 3 +- .../src/nodes/publication_table.rs | 4 +- .../src/nodes/reindex_stmt.rs | 3 +- .../src/nodes/row_compare_expr.rs | 3 +- .../src/nodes/table_sample_clause.rs | 3 +- .../pgls_pretty_print/src/nodes/type_cast.rs | 5 +- .../pgls_pretty_print/src/nodes/type_name.rs | 15 ++-- .../src/nodes/vacuum_relation.rs | 3 +- .../src/nodes/variable_set_stmt.rs | 8 +-- .../wasm/src/workspace.ts | 2 +- 30 files changed, 83 insertions(+), 150 deletions(-) diff --git a/crates/pgls_pretty_print/src/nodes/access_priv.rs b/crates/pgls_pretty_print/src/nodes/access_priv.rs index 6dae90d55..153ea1560 100644 --- a/crates/pgls_pretty_print/src/nodes/access_priv.rs +++ b/crates/pgls_pretty_print/src/nodes/access_priv.rs @@ -8,17 +8,8 @@ pub(super) fn emit_access_priv(e: &mut EventEmitter, n: &AccessPriv) { e.group_start(GroupKind::AccessPriv); if !n.priv_name.is_empty() { - // Privilege names are read case-insensitively, `alter system` being the only one of two - // words, so they follow the keyword case whether or not they are keywords. - for (index, word) in n.priv_name.split(' ').enumerate() { - if index > 0 { - e.space(); - } - match TokenKind::from_keyword(word) { - Some(keyword) => e.token(keyword), - None => e.token(TokenKind::WORD(word.to_string())), - } - } + // Privilege names, `alter system` included, follow the keyword case. + super::emit_keywords(e, &n.priv_name); } else { // Empty priv_name means ALL privileges e.token(TokenKind::ALL_KW); diff --git a/crates/pgls_pretty_print/src/nodes/alter_foreign_server_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_foreign_server_stmt.rs index 4c0907c38..31d60bea9 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_foreign_server_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_foreign_server_stmt.rs @@ -2,8 +2,10 @@ use crate::TokenKind; use crate::emitter::{EventEmitter, GroupKind, LineType}; use pgls_query::protobuf::AlterForeignServerStmt; -use super::node_list::emit_parenthesized_list; -use super::string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}; +use super::{ + node_list::emit_parenthesized_list, + string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}, +}; pub(super) fn emit_alter_foreign_server_stmt(e: &mut EventEmitter, n: &AlterForeignServerStmt) { e.group_start(GroupKind::AlterForeignServerStmt); diff --git a/crates/pgls_pretty_print/src/nodes/alter_operator_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_operator_stmt.rs index ae73438f7..6f9c86c6c 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_operator_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_operator_stmt.rs @@ -4,9 +4,9 @@ use pgls_query::protobuf::{AlterOperatorStmt, DefElem, List, ObjectWithArgs}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, + nodes::node_list::emit_parenthesized_list, }; -use super::node_list::emit_parenthesized_list; use super::string::emit_identifier_maybe_quoted; pub(super) fn emit_alter_operator_stmt(e: &mut EventEmitter, n: &AlterOperatorStmt) { diff --git a/crates/pgls_pretty_print/src/nodes/constraint.rs b/crates/pgls_pretty_print/src/nodes/constraint.rs index d6bed50e6..cccbd0885 100644 --- a/crates/pgls_pretty_print/src/nodes/constraint.rs +++ b/crates/pgls_pretty_print/src/nodes/constraint.rs @@ -293,48 +293,7 @@ pub(super) fn emit_constraint(e: &mut EventEmitter, n: &Constraint) { if !n.exclusions.is_empty() { e.space(); - e.group_start(GroupKind::List); - e.token(TokenKind::L_PAREN); - e.indent_start(); - e.line(LineType::Soft); - - for (idx, exclusion) in n.exclusions.iter().enumerate() { - if idx > 0 { - e.token(TokenKind::COMMA); - e.line(LineType::SoftOrSpace); - } - - let exclusion_list = assert_node_variant!(List, exclusion); - debug_assert!(exclusion_list.items.len() >= 2); - - if let Some(index_elem) = exclusion_list.items.first() { - super::emit_node(index_elem, e); - } - - if let Some(operators) = exclusion_list.items.get(1) { - e.space(); - e.token(TokenKind::WITH_KW); - e.space(); - - match operators.node.as_ref() { - Some(pgls_query::NodeEnum::List(op_list)) => { - for (op_idx, op) in op_list.items.iter().enumerate() { - if op_idx > 0 { - e.token(TokenKind::COMMA); - e.space(); - } - emit_exclusion_operator(e, op); - } - } - _ => emit_exclusion_operator(e, operators), - } - } - } - - e.indent_end(); - e.line(LineType::Soft); - e.token(TokenKind::R_PAREN); - e.group_end(); + emit_parenthesized_list(e, &n.exclusions, emit_exclusion); } // INCLUDE (columns) @@ -514,6 +473,35 @@ fn emit_deferrable(e: &mut EventEmitter, n: &Constraint, continued: &mut bool) { } } +/// Emits one element of an exclusion constraint: `column WITH operator`. +fn emit_exclusion(exclusion: &pgls_query::Node, e: &mut EventEmitter) { + let exclusion_list = assert_node_variant!(List, exclusion); + debug_assert!(exclusion_list.items.len() >= 2); + + if let Some(index_elem) = exclusion_list.items.first() { + super::emit_node(index_elem, e); + } + + if let Some(operators) = exclusion_list.items.get(1) { + e.space(); + e.token(TokenKind::WITH_KW); + e.space(); + + match operators.node.as_ref() { + Some(pgls_query::NodeEnum::List(op_list)) => { + for (op_idx, op) in op_list.items.iter().enumerate() { + if op_idx > 0 { + e.token(TokenKind::COMMA); + e.space(); + } + emit_exclusion_operator(e, op); + } + } + _ => emit_exclusion_operator(e, operators), + } + } +} + fn emit_exclusion_operator(e: &mut EventEmitter, node: &pgls_query::Node) { match node.node.as_ref() { Some(NodeEnum::String(s)) => e.token(TokenKind::IDENT(s.sval.clone())), diff --git a/crates/pgls_pretty_print/src/nodes/create_enum_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_enum_stmt.rs index 13668739e..01d60a4ba 100644 --- a/crates/pgls_pretty_print/src/nodes/create_enum_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_enum_stmt.rs @@ -3,10 +3,9 @@ use pgls_query::protobuf::CreateEnumStmt; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, + nodes::node_list::emit_parenthesized_list, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_create_enum_stmt(e: &mut EventEmitter, n: &CreateEnumStmt) { e.group_start(GroupKind::CreateEnumStmt); diff --git a/crates/pgls_pretty_print/src/nodes/create_foreign_server_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_foreign_server_stmt.rs index 847a87a23..854983fa3 100644 --- a/crates/pgls_pretty_print/src/nodes/create_foreign_server_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_foreign_server_stmt.rs @@ -4,8 +4,10 @@ use crate::{ }; use pgls_query::protobuf::CreateForeignServerStmt; -use super::node_list::emit_parenthesized_list; -use super::string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}; +use super::{ + node_list::emit_parenthesized_list, + string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}, +}; pub(super) fn emit_create_foreign_server_stmt(e: &mut EventEmitter, n: &CreateForeignServerStmt) { e.group_start(GroupKind::CreateForeignServerStmt); diff --git a/crates/pgls_pretty_print/src/nodes/create_table_as_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_table_as_stmt.rs index 2b191bd98..dd83774f2 100644 --- a/crates/pgls_pretty_print/src/nodes/create_table_as_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_table_as_stmt.rs @@ -5,8 +5,10 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::node_list::emit_parenthesized_list; -use super::{emit_node, select_stmt::emit_select_stmt_no_semicolon, string::emit_string}; +use super::{ + emit_node, node_list::emit_parenthesized_list, select_stmt::emit_select_stmt_no_semicolon, + string::emit_string, +}; pub(super) fn emit_create_table_as_stmt(e: &mut EventEmitter, n: &CreateTableAsStmt) { e.group_start(GroupKind::CreateTableAsStmt); diff --git a/crates/pgls_pretty_print/src/nodes/create_table_space_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_table_space_stmt.rs index d95ce9f7d..6d1042629 100644 --- a/crates/pgls_pretty_print/src/nodes/create_table_space_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_table_space_stmt.rs @@ -5,7 +5,6 @@ use crate::{ emitter::{EventEmitter, GroupKind}, }; -use super::node_list::emit_parenthesized_list; use super::string::{emit_identifier_maybe_quoted, emit_keyword, emit_single_quoted_str}; pub(super) fn emit_create_table_space_stmt(e: &mut EventEmitter, n: &CreateTableSpaceStmt) { @@ -39,7 +38,7 @@ pub(super) fn emit_create_table_space_stmt(e: &mut EventEmitter, n: &CreateTable e.space(); e.token(TokenKind::WITH_KW); e.space(); - emit_parenthesized_list(e, &n.options, super::emit_node); + super::node_list::emit_parenthesized_list(e, &n.options, super::emit_node); } e.token(TokenKind::SEMICOLON); diff --git a/crates/pgls_pretty_print/src/nodes/create_user_mapping_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_user_mapping_stmt.rs index 7f638db66..a0589e697 100644 --- a/crates/pgls_pretty_print/src/nodes/create_user_mapping_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_user_mapping_stmt.rs @@ -1,11 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, + nodes::node_list::emit_parenthesized_list, }; use pgls_query::protobuf::CreateUserMappingStmt; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_create_user_mapping_stmt(e: &mut EventEmitter, n: &CreateUserMappingStmt) { e.group_start(GroupKind::CreateUserMappingStmt); diff --git a/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs b/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs index 0639de92b..e4cd8d0dd 100644 --- a/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/dropdb_stmt.rs @@ -3,10 +3,9 @@ use pgls_query::{NodeEnum, protobuf::DropdbStmt}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, + nodes::node_list::emit_parenthesized_list, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_dropdb_stmt(e: &mut EventEmitter, n: &DropdbStmt) { e.group_start(GroupKind::DropdbStmt); diff --git a/crates/pgls_pretty_print/src/nodes/execute_stmt.rs b/crates/pgls_pretty_print/src/nodes/execute_stmt.rs index d8c09fd2e..4190dc5c7 100644 --- a/crates/pgls_pretty_print/src/nodes/execute_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/execute_stmt.rs @@ -6,7 +6,6 @@ use crate::{ }; use super::emit_node; -use super::node_list::emit_parenthesized_list; pub(super) fn emit_execute_stmt(e: &mut EventEmitter, n: &ExecuteStmt) { emit_execute_stmt_impl(e, n, true); @@ -25,7 +24,7 @@ fn emit_execute_stmt_impl(e: &mut EventEmitter, n: &ExecuteStmt, with_semicolon: if !n.params.is_empty() { e.line(LineType::SoftOrSpace); - emit_parenthesized_list(e, &n.params, emit_node); + super::node_list::emit_parenthesized_list(e, &n.params, emit_node); } if with_semicolon { diff --git a/crates/pgls_pretty_print/src/nodes/func_call.rs b/crates/pgls_pretty_print/src/nodes/func_call.rs index 0d10e40ca..6c211e9fc 100644 --- a/crates/pgls_pretty_print/src/nodes/func_call.rs +++ b/crates/pgls_pretty_print/src/nodes/func_call.rs @@ -314,7 +314,7 @@ fn emit_sql_syntax_call(e: &mut EventEmitter, n: &FuncCall) -> bool { ("extract", [field, source]) => { e.token(TokenKind::EXTRACT_KW); e.token(TokenKind::L_PAREN); - emit_word_or_literal(e, field); + emit_extract_field(e, field); e.space(); e.token(TokenKind::FROM_KW); e.space(); @@ -509,16 +509,13 @@ fn normalization_form(node: &Node) -> Option { } } -/// Emits the field of `EXTRACT`, stored as a string: as the word it was written as when it is one. -fn emit_word_or_literal(e: &mut EventEmitter, node: &Node) { +/// Emits the field of `EXTRACT`, stored as a string, as the word it was written as when it is one. +fn emit_extract_field(e: &mut EventEmitter, node: &Node) { if let Some(NodeEnum::AConst(a_const)) = &node.node && let Some(Val::Sval(field)) = &a_const.val && !needs_quoting(&field.sval) { - match TokenKind::from_keyword(&field.sval) { - Some(keyword) => e.token(keyword), - None => e.token(TokenKind::IDENT(field.sval.clone())), - } + super::emit_keyword(e, &field.sval); return; } @@ -528,23 +525,11 @@ fn emit_word_or_literal(e: &mut EventEmitter, node: &Node) { /// Emits an operand of SQL-standard syntax, in parentheses unless it is a single term that binds /// tighter than any operator. fn emit_parenthesized_unless_simple(e: &mut EventEmitter, node: &Node) { - let is_simple = match &node.node { - Some(NodeEnum::ColumnRef(_) | NodeEnum::ParamRef(_) | NodeEnum::TypeCast(_)) => true, - Some(NodeEnum::FuncCall(call)) => call.funcformat != CoercionForm::CoerceSqlSyntax as i32, - Some(NodeEnum::AConst(a_const)) => match &a_const.val { - Some(Val::Ival(integer)) => integer.ival >= 0, - Some(Val::Fval(float)) => !float.fval.starts_with('-'), - Some(Val::Sval(_) | Val::Bsval(_) | Val::Boolval(_)) => true, - None => true, - }, - _ => false, - }; - - if is_simple { - super::emit_node(node, e); - } else { + if super::type_cast::needs_parentheses(node) { e.token(TokenKind::L_PAREN); super::emit_node(node, e); e.token(TokenKind::R_PAREN); + } else { + super::emit_node(node, e); } } diff --git a/crates/pgls_pretty_print/src/nodes/grant_stmt.rs b/crates/pgls_pretty_print/src/nodes/grant_stmt.rs index 1834f7ae0..ec0a83e6d 100644 --- a/crates/pgls_pretty_print/src/nodes/grant_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/grant_stmt.rs @@ -237,12 +237,7 @@ fn emit_access_priv(e: &mut EventEmitter, priv_node: &pgls_query::protobuf::Acce if priv_node.priv_name.is_empty() && !priv_node.cols.is_empty() { e.token(TokenKind::ALL_KW); } else if !priv_node.priv_name.is_empty() { - for (index, word) in priv_node.priv_name.split(' ').enumerate() { - if index > 0 { - e.space(); - } - super::emit_keyword(e, word); - } + super::emit_keywords(e, &priv_node.priv_name); } // Handle column privileges diff --git a/crates/pgls_pretty_print/src/nodes/import_foreign_schema_stmt.rs b/crates/pgls_pretty_print/src/nodes/import_foreign_schema_stmt.rs index ce48a98ef..85168554b 100644 --- a/crates/pgls_pretty_print/src/nodes/import_foreign_schema_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/import_foreign_schema_stmt.rs @@ -5,8 +5,6 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_import_foreign_schema_stmt(e: &mut EventEmitter, n: &ImportForeignSchemaStmt) { e.group_start(GroupKind::ImportForeignSchemaStmt); @@ -35,7 +33,7 @@ pub(super) fn emit_import_foreign_schema_stmt(e: &mut EventEmitter, n: &ImportFo e.token(TokenKind::EXCEPT_KW); } e.space(); - emit_parenthesized_list(e, &n.table_list, super::emit_node); + super::node_list::emit_parenthesized_list(e, &n.table_list, super::emit_node); } // FROM SERVER @@ -61,7 +59,7 @@ pub(super) fn emit_import_foreign_schema_stmt(e: &mut EventEmitter, n: &ImportFo e.line(LineType::SoftOrSpace); e.token(TokenKind::OPTIONS_KW); e.space(); - emit_parenthesized_list(e, &n.options, |n, e| { + super::node_list::emit_parenthesized_list(e, &n.options, |n, e| { let def_elem = assert_node_variant!(DefElem, n); super::emit_options_def_elem(e, def_elem); }); diff --git a/crates/pgls_pretty_print/src/nodes/index_elem.rs b/crates/pgls_pretty_print/src/nodes/index_elem.rs index b40f4045c..6efe53a59 100644 --- a/crates/pgls_pretty_print/src/nodes/index_elem.rs +++ b/crates/pgls_pretty_print/src/nodes/index_elem.rs @@ -5,8 +5,6 @@ use crate::{ emitter::{EventEmitter, GroupKind}, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_index_elem(e: &mut EventEmitter, n: &IndexElem) { e.group_start(GroupKind::IndexElem); @@ -38,7 +36,7 @@ pub(super) fn emit_index_elem(e: &mut EventEmitter, n: &IndexElem) { // Optional opclass options (e.g., tsvector_ops(siglen = 1000)) if !n.opclassopts.is_empty() { - emit_parenthesized_list(e, &n.opclassopts, |node, emitter| { + super::node_list::emit_parenthesized_list(e, &n.opclassopts, |node, emitter| { if let Some(pgls_query::NodeEnum::DefElem(def)) = node.node.as_ref() { emitter.token(TokenKind::IDENT(def.defname.clone())); if let Some(ref arg) = def.arg { diff --git a/crates/pgls_pretty_print/src/nodes/index_stmt.rs b/crates/pgls_pretty_print/src/nodes/index_stmt.rs index 80ec5e9fb..3883122a0 100644 --- a/crates/pgls_pretty_print/src/nodes/index_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/index_stmt.rs @@ -3,10 +3,9 @@ use pgls_query::protobuf::IndexStmt; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, + nodes::node_list::emit_parenthesized_list, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_index_stmt(e: &mut EventEmitter, n: &IndexStmt) { emit_index_stmt_impl(e, n, true); } diff --git a/crates/pgls_pretty_print/src/nodes/infer_clause.rs b/crates/pgls_pretty_print/src/nodes/infer_clause.rs index 5e0215ae2..924d957b8 100644 --- a/crates/pgls_pretty_print/src/nodes/infer_clause.rs +++ b/crates/pgls_pretty_print/src/nodes/infer_clause.rs @@ -5,8 +5,7 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::node_list::emit_parenthesized_list; -use super::string::emit_identifier_maybe_quoted; +use super::{node_list::emit_parenthesized_list, string::emit_identifier_maybe_quoted}; pub(super) fn emit_infer_clause(e: &mut EventEmitter, n: &InferClause) { e.group_start(GroupKind::InferClause); diff --git a/crates/pgls_pretty_print/src/nodes/int_list.rs b/crates/pgls_pretty_print/src/nodes/int_list.rs index 63c1f17c0..178dc0430 100644 --- a/crates/pgls_pretty_print/src/nodes/int_list.rs +++ b/crates/pgls_pretty_print/src/nodes/int_list.rs @@ -2,12 +2,10 @@ use pgls_query::protobuf::IntList; use crate::emitter::{EventEmitter, GroupKind}; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_int_list(e: &mut EventEmitter, n: &IntList) { e.group_start(GroupKind::IntList); - emit_parenthesized_list(e, &n.items, super::emit_node); + super::node_list::emit_parenthesized_list(e, &n.items, super::emit_node); e.group_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/oid_list.rs b/crates/pgls_pretty_print/src/nodes/oid_list.rs index bdb439f52..d53364669 100644 --- a/crates/pgls_pretty_print/src/nodes/oid_list.rs +++ b/crates/pgls_pretty_print/src/nodes/oid_list.rs @@ -2,12 +2,10 @@ use pgls_query::protobuf::OidList; use crate::emitter::{EventEmitter, GroupKind}; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_oid_list(e: &mut EventEmitter, n: &OidList) { e.group_start(GroupKind::OidList); - emit_parenthesized_list(e, &n.items, super::emit_node); + super::node_list::emit_parenthesized_list(e, &n.items, super::emit_node); e.group_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/on_conflict_expr.rs b/crates/pgls_pretty_print/src/nodes/on_conflict_expr.rs index d9bed90a7..08c6d000b 100644 --- a/crates/pgls_pretty_print/src/nodes/on_conflict_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/on_conflict_expr.rs @@ -4,8 +4,6 @@ use crate::{ }; use pgls_query::protobuf::{OnConflictAction, OnConflictExpr}; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_on_conflict_expr(e: &mut EventEmitter, n: &OnConflictExpr) { e.group_start(GroupKind::OnConflictExpr); @@ -15,7 +13,7 @@ pub(super) fn emit_on_conflict_expr(e: &mut EventEmitter, n: &OnConflictExpr) { if !n.arbiter_elems.is_empty() { e.space(); - emit_parenthesized_list(e, &n.arbiter_elems, super::emit_node); + super::node_list::emit_parenthesized_list(e, &n.arbiter_elems, super::emit_node); } if n.constraint != 0 { diff --git a/crates/pgls_pretty_print/src/nodes/prepare_stmt.rs b/crates/pgls_pretty_print/src/nodes/prepare_stmt.rs index 369ae7bdf..2ead84d82 100644 --- a/crates/pgls_pretty_print/src/nodes/prepare_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/prepare_stmt.rs @@ -3,10 +3,9 @@ use pgls_query::protobuf::PrepareStmt; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, + nodes::node_list::emit_parenthesized_list, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_prepare_stmt(e: &mut EventEmitter, n: &PrepareStmt) { e.group_start(GroupKind::PrepareStmt); diff --git a/crates/pgls_pretty_print/src/nodes/publication_table.rs b/crates/pgls_pretty_print/src/nodes/publication_table.rs index 0281db1b1..2def8944a 100644 --- a/crates/pgls_pretty_print/src/nodes/publication_table.rs +++ b/crates/pgls_pretty_print/src/nodes/publication_table.rs @@ -4,8 +4,6 @@ use crate::{ }; use pgls_query::protobuf::PublicationTable; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_publication_table(e: &mut EventEmitter, n: &PublicationTable) { e.group_start(GroupKind::PublicationTable); @@ -15,7 +13,7 @@ pub(super) fn emit_publication_table(e: &mut EventEmitter, n: &PublicationTable) if !n.columns.is_empty() { e.space(); - emit_parenthesized_list(e, &n.columns, super::emit_node); + super::node_list::emit_parenthesized_list(e, &n.columns, super::emit_node); } if let Some(ref where_clause) = n.where_clause { diff --git a/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs b/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs index 5a1abd6ae..280ca5960 100644 --- a/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/reindex_stmt.rs @@ -3,10 +3,9 @@ use pgls_query::{NodeEnum, protobuf::ReindexStmt}; use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, + nodes::node_list::emit_parenthesized_list, }; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_reindex_stmt(e: &mut EventEmitter, n: &ReindexStmt) { e.group_start(GroupKind::ReindexStmt); diff --git a/crates/pgls_pretty_print/src/nodes/row_compare_expr.rs b/crates/pgls_pretty_print/src/nodes/row_compare_expr.rs index e4009a914..337d536f9 100644 --- a/crates/pgls_pretty_print/src/nodes/row_compare_expr.rs +++ b/crates/pgls_pretty_print/src/nodes/row_compare_expr.rs @@ -1,11 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, + nodes::node_list::emit_parenthesized_list, }; use pgls_query::protobuf::{RowCompareExpr, RowCompareType}; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_row_compare_expr(e: &mut EventEmitter, n: &RowCompareExpr) { e.group_start(GroupKind::RowCompareExpr); diff --git a/crates/pgls_pretty_print/src/nodes/table_sample_clause.rs b/crates/pgls_pretty_print/src/nodes/table_sample_clause.rs index b442f35e0..b1940f9be 100644 --- a/crates/pgls_pretty_print/src/nodes/table_sample_clause.rs +++ b/crates/pgls_pretty_print/src/nodes/table_sample_clause.rs @@ -1,11 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind, LineType}, + nodes::node_list::emit_parenthesized_list, }; use pgls_query::protobuf::TableSampleClause; -use super::node_list::emit_parenthesized_list; - pub(super) fn emit_table_sample_clause(e: &mut EventEmitter, clause: &TableSampleClause) { e.group_start(GroupKind::TableSampleClause); diff --git a/crates/pgls_pretty_print/src/nodes/type_cast.rs b/crates/pgls_pretty_print/src/nodes/type_cast.rs index d8e5482ac..e7bec813b 100644 --- a/crates/pgls_pretty_print/src/nodes/type_cast.rs +++ b/crates/pgls_pretty_print/src/nodes/type_cast.rs @@ -67,11 +67,12 @@ fn emit_operator_cast(e: &mut EventEmitter, n: &TypeCast) { } } -/// Whitelist of self contained expressions that can carry a `::` without parentheses. +/// Whitelist of self contained expressions that can carry a `::`, or be the operand of other +/// high-precedence syntax such as `AT TIME ZONE`, without parentheses. /// /// Anything absent from this list is parenthesised, which is always valid SQL. Listing the unsafe /// kinds instead would fail open on any node nobody thought about. -fn needs_parentheses(node: &Node) -> bool { +pub(super) fn needs_parentheses(node: &Node) -> bool { match node.node.as_ref() { Some(NodeEnum::AExpr(a_expr)) => a_expr.kind != AExprKind::AexprNullif as i32, // A negative constant is emitted with its sign, and `-1::int` casts 1 before negating it. diff --git a/crates/pgls_pretty_print/src/nodes/type_name.rs b/crates/pgls_pretty_print/src/nodes/type_name.rs index 967dc8949..317ebeee1 100644 --- a/crates/pgls_pretty_print/src/nodes/type_name.rs +++ b/crates/pgls_pretty_print/src/nodes/type_name.rs @@ -1,10 +1,10 @@ use crate::{ TokenKind, emitter::{EventEmitter, GroupKind}, + nodes::node_list::emit_parenthesized_list, }; use pgls_query::protobuf::{self, TypeName}; -use super::node_list::emit_parenthesized_list; use super::string::{ emit_identifier, emit_identifier_maybe_quoted, emit_type_identifier_maybe_quoted, needs_quoting_as_function_or_type_name, @@ -233,17 +233,12 @@ fn is_time_with_tz_type(name_parts: &[String]) -> bool { } fn emit_time_with_tz_type(e: &mut EventEmitter, n: &TypeName, name_parts: &[String]) { - let base_name = match name_parts { - [name] => name, - [schema, name] if is_pg_catalog(schema) => name, - _ => { - emit_normalized_type_name(e, name_parts); - return; - } + let [_, name] = name_parts else { + emit_normalized_type_name(e, name_parts); + return; }; - let lowered = base_name.to_ascii_lowercase(); - match lowered.as_str() { + match name.as_str() { "timetz" => { e.token(TokenKind::TIME_KW); // Emit precision if any diff --git a/crates/pgls_pretty_print/src/nodes/vacuum_relation.rs b/crates/pgls_pretty_print/src/nodes/vacuum_relation.rs index 52ba40216..53bd7d63c 100644 --- a/crates/pgls_pretty_print/src/nodes/vacuum_relation.rs +++ b/crates/pgls_pretty_print/src/nodes/vacuum_relation.rs @@ -3,7 +3,6 @@ use pgls_query::protobuf::VacuumRelation; use crate::emitter::{EventEmitter, GroupKind}; use super::emit_node; -use super::node_list::emit_parenthesized_list; pub(super) fn emit_vacuum_relation(e: &mut EventEmitter, n: &VacuumRelation) { e.group_start(GroupKind::VacuumRelation); @@ -15,7 +14,7 @@ pub(super) fn emit_vacuum_relation(e: &mut EventEmitter, n: &VacuumRelation) { // va_cols: specific columns to vacuum/analyze if !n.va_cols.is_empty() { e.space(); - emit_parenthesized_list(e, &n.va_cols, emit_node); + super::node_list::emit_parenthesized_list(e, &n.va_cols, emit_node); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs b/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs index 8915a742c..40923386c 100644 --- a/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/variable_set_stmt.rs @@ -14,14 +14,10 @@ fn emit_set_arg(node: &Node, e: &mut EventEmitter) { if let Some(NodeEnum::AConst(a_const)) = &node.node && let Some(pgls_query::protobuf::a_const::Val::Sval(s)) = &a_const.val { - // Check if this looks like it should be an identifier (not a quoted string) // In SET statements, simple identifiers like schema names are stored as string constants - // but should be emitted without quotes + // but should be emitted without quotes. A value that an unquoted word cannot spell keeps + // its quotes: unquoted, `SET datestyle = German` would set `german`. let val = &s.sval; - - // Emit as identifier (no quotes) if it looks like a simple identifier - // This includes schema names, role names, etc. - // An unquoted word is folded to lowercase: `SET datestyle = German` would set `german`. if !super::string::needs_quoting(val) { e.group_start(GroupKind::String); e.token(TokenKind::IDENT(val.clone())); diff --git a/packages/@postgres-language-server/wasm/src/workspace.ts b/packages/@postgres-language-server/wasm/src/workspace.ts index 0c355242c..0ff824554 100644 --- a/packages/@postgres-language-server/wasm/src/workspace.ts +++ b/packages/@postgres-language-server/wasm/src/workspace.ts @@ -260,7 +260,7 @@ export async function createWorkspace(options?: WorkspaceOptions): Promise { - const workspace = new Workspace(await loadWasm()); + const workspace = await createWorkspace(); return workspace.formatSql(sql, options).formatted; } From c763a6a8f94156f1f1a65a4d14b6b426d8982a86 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Tue, 13 Oct 2026 06:23:26 +0000 Subject: [PATCH 7/7] fix(pretty-print): dollar-quote every function body with $$ Instead of keeping each body's original quoting, quote every function and DO body the same way: $$, or $body$ when the body contains $$. The body itself is still written byte for byte. Without the original quoting to recover, the emitter no longer needs the statement source. --- crates/pgls_pretty_print/src/emitter.rs | 47 --- crates/pgls_pretty_print/src/lib.rs | 8 +- .../src/nodes/alter_function_stmt.rs | 8 +- .../src/nodes/create_function_stmt.rs | 17 +- crates/pgls_pretty_print/src/nodes/do_stmt.rs | 12 +- .../src/nodes/inline_code_block.rs | 4 +- crates/pgls_pretty_print/src/nodes/mod.rs | 4 +- crates/pgls_pretty_print/src/nodes/string.rs | 124 +----- .../tests/postgres_regress.rs | 14 +- .../multi/tests__alter_generic_100.snap | 16 +- .../multi/tests__alter_generic_80.snap | 16 +- .../multi/tests__alter_operator_100.snap | 2 +- .../multi/tests__alter_operator_80.snap | 2 +- .../snapshots/multi/tests__brin_100.snap | 4 +- .../tests/snapshots/multi/tests__brin_80.snap | 4 +- .../multi/tests__brin_bloom_100.snap | 4 +- .../snapshots/multi/tests__brin_bloom_80.snap | 4 +- .../multi/tests__brin_multi_100.snap | 4 +- .../snapshots/multi/tests__brin_multi_80.snap | 4 +- .../snapshots/multi/tests__case_100.snap | 12 +- .../tests/snapshots/multi/tests__case_80.snap | 12 +- .../multi/tests__collate.icu.utf8_100.snap | 2 +- .../multi/tests__collate.icu.utf8_80.snap | 2 +- .../multi/tests__collate.linux.utf8_100.snap | 2 +- .../multi/tests__collate.linux.utf8_80.snap | 2 +- .../snapshots/multi/tests__collate_100.snap | 4 +- .../snapshots/multi/tests__collate_80.snap | 4 +- .../multi/tests__compression_100.snap | 2 +- .../multi/tests__compression_80.snap | 2 +- .../multi/tests__compression_lz4_100.snap | 2 +- .../multi/tests__compression_lz4_80.snap | 2 +- .../snapshots/multi/tests__copy2_100.snap | 12 +- .../snapshots/multi/tests__copy2_80.snap | 12 +- .../multi/tests__create_aggregate_100.snap | 16 +- .../multi/tests__create_aggregate_80.snap | 16 +- .../multi/tests__create_cast_100.snap | 4 +- .../multi/tests__create_cast_80.snap | 4 +- .../multi/tests__create_function_c_100.snap | 4 +- .../multi/tests__create_function_c_80.snap | 4 +- .../multi/tests__create_function_sql_100.snap | 70 ++-- .../multi/tests__create_function_sql_80.snap | 70 ++-- .../multi/tests__create_index_100.snap | 8 +- .../multi/tests__create_index_80.snap | 8 +- .../multi/tests__create_type_100.snap | 34 +- .../multi/tests__create_type_80.snap | 34 +- .../multi/tests__create_view_100.snap | 2 +- .../multi/tests__create_view_80.snap | 2 +- .../snapshots/multi/tests__domain_100.snap | 4 +- .../snapshots/multi/tests__domain_80.snap | 4 +- .../multi/tests__equivclass_100.snap | 22 +- .../snapshots/multi/tests__equivclass_80.snap | 22 +- .../snapshots/multi/tests__explain_100.snap | 2 +- .../snapshots/multi/tests__explain_80.snap | 2 +- .../multi/tests__expressions_100.snap | 6 +- .../multi/tests__expressions_80.snap | 6 +- .../multi/tests__fast_default_100.snap | 6 +- .../multi/tests__fast_default_80.snap | 6 +- .../snapshots/multi/tests__float4_100.snap | 4 +- .../snapshots/multi/tests__float4_80.snap | 4 +- .../snapshots/multi/tests__float8_100.snap | 4 +- .../snapshots/multi/tests__float8_80.snap | 4 +- .../multi/tests__foreign_data_100.snap | 2 +- .../multi/tests__foreign_data_80.snap | 2 +- .../multi/tests__groupingsets_100.snap | 4 +- .../multi/tests__groupingsets_80.snap | 4 +- .../multi/tests__indirect_toast_100.snap | 2 +- .../multi/tests__indirect_toast_80.snap | 2 +- .../multi/tests__infinite_recurse_100.snap | 2 +- .../multi/tests__infinite_recurse_80.snap | 2 +- .../snapshots/multi/tests__inherit_100.snap | 2 +- .../snapshots/multi/tests__inherit_80.snap | 2 +- .../multi/tests__largeobject_100.snap | 2 +- .../multi/tests__largeobject_80.snap | 2 +- .../snapshots/multi/tests__lock_100.snap | 2 +- .../tests/snapshots/multi/tests__lock_80.snap | 2 +- .../snapshots/multi/tests__misc_100.snap | 26 +- .../tests/snapshots/multi/tests__misc_80.snap | 26 +- .../multi/tests__misc_functions_100.snap | 4 +- .../multi/tests__misc_functions_80.snap | 4 +- .../multi/tests__multirangetypes_100.snap | 14 +- .../multi/tests__multirangetypes_80.snap | 14 +- .../snapshots/multi/tests__oidjoins_100.snap | 4 +- .../snapshots/multi/tests__oidjoins_80.snap | 4 +- .../snapshots/multi/tests__plpgsql_100.snap | 374 +++++++++--------- .../snapshots/multi/tests__plpgsql_80.snap | 374 +++++++++--------- .../multi/tests__polymorphism_100.snap | 34 +- .../multi/tests__polymorphism_80.snap | 34 +- .../multi/tests__privileges_100.snap | 34 +- .../snapshots/multi/tests__privileges_80.snap | 34 +- .../multi/tests__rangefuncs_100.snap | 48 +-- .../snapshots/multi/tests__rangefuncs_80.snap | 48 +-- .../multi/tests__rangetypes_100.snap | 12 +- .../snapshots/multi/tests__rangetypes_80.snap | 12 +- .../multi/tests__rowsecurity_100.snap | 2 +- .../multi/tests__rowsecurity_80.snap | 2 +- .../snapshots/multi/tests__select_100.snap | 2 +- .../snapshots/multi/tests__select_80.snap | 2 +- .../multi/tests__select_views_100.snap | 2 +- .../multi/tests__select_views_80.snap | 2 +- .../snapshots/multi/tests__stats_ext_100.snap | 4 +- .../snapshots/multi/tests__stats_ext_80.snap | 4 +- .../snapshots/multi/tests__subselect_100.snap | 6 +- .../snapshots/multi/tests__subselect_80.snap | 6 +- .../snapshots/multi/tests__temp_100.snap | 4 +- .../tests/snapshots/multi/tests__temp_80.snap | 4 +- .../multi/tests__transactions_100.snap | 10 +- .../multi/tests__transactions_80.snap | 10 +- .../snapshots/multi/tests__triggers_100.snap | 10 +- .../snapshots/multi/tests__triggers_80.snap | 10 +- .../snapshots/multi/tests__vacuum_100.snap | 4 +- .../snapshots/multi/tests__vacuum_80.snap | 4 +- .../snapshots/multi/tests__window_100.snap | 2 +- .../snapshots/multi/tests__window_80.snap | 2 +- .../tests__create_function_stmt_0_100.snap | 2 +- .../tests__create_function_stmt_0_80.snap | 2 +- .../tests__create_function_stmt_2_100.snap | 2 +- .../tests__create_function_stmt_2_80.snap | 2 +- .../single/tests__do_stmt_0_100.snap | 2 +- .../snapshots/single/tests__do_stmt_0_80.snap | 2 +- ...__nested_dollar_quotes_conflict_0_100.snap | 4 +- ...s__nested_dollar_quotes_conflict_0_80.snap | 4 +- .../tests/source_fidelity.rs | 26 +- crates/pgls_pretty_print/tests/tests.rs | 4 +- .../src/workspace/server.tests.rs | 6 +- docs/features/formatting.md | 3 +- 125 files changed, 933 insertions(+), 1092 deletions(-) diff --git a/crates/pgls_pretty_print/src/emitter.rs b/crates/pgls_pretty_print/src/emitter.rs index 3af4b482e..5997c19bf 100644 --- a/crates/pgls_pretty_print/src/emitter.rs +++ b/crates/pgls_pretty_print/src/emitter.rs @@ -56,16 +56,6 @@ pub struct EventEmitter { leading_line_comments_require_break: bool, /// Line comments written after a list comma, waiting for the emitter to reach that comma. comments_after_separator: Vec, - /// The text the AST was parsed from. The AST drops how a literal was quoted, so this is where - /// a function body gets its dollar-quote tag back from. - source: Option, -} - -#[derive(Debug)] -struct Source { - text: String, - /// Byte ranges of the string literals in `text`, in source order. - string_literals: Vec<(usize, usize)>, } impl EventEmitter { @@ -77,45 +67,9 @@ impl EventEmitter { trailing_comments: HashMap::new(), leading_line_comments_require_break: false, comments_after_separator: Vec::new(), - source: None, } } - /// Attaches the text the AST was parsed from, so that literals keep the quoting they were - /// written with. Without it, a literal is quoted the default way. - pub fn with_source(mut self, sql: &str) -> Self { - let string_literals = pgls_query::scan(sql) - .map(|scan| { - scan.tokens - .iter() - .filter(|token| token.token == pgls_query::protobuf::Token::Sconst as i32) - .filter_map(|token| { - Some(( - usize::try_from(token.start).ok()?, - usize::try_from(token.end).ok()?, - )) - }) - .collect() - }) - .unwrap_or_default(); - self.source = Some(Source { - text: sql.to_string(), - string_literals, - }); - self - } - - /// The source text of the first string literal at or after `location`. - pub(crate) fn source_string_literal_from(&self, location: i32) -> Option<&str> { - let source = self.source.as_ref()?; - let location = usize::try_from(location).ok()?; - let index = source - .string_literals - .partition_point(|(start, _)| *start < location); - let (start, end) = *source.string_literals.get(index)?; - source.text.get(start..end) - } - // Later option PRs inspect this while deciding which layout events to emit. #[allow(dead_code)] pub fn config(&self) -> &FormatConfig { @@ -134,7 +88,6 @@ impl EventEmitter { trailing_comments, leading_line_comments_require_break: false, comments_after_separator: Vec::new(), - source: None, } } diff --git a/crates/pgls_pretty_print/src/lib.rs b/crates/pgls_pretty_print/src/lib.rs index 6cae330d2..b9f8369e1 100644 --- a/crates/pgls_pretty_print/src/lib.rs +++ b/crates/pgls_pretty_print/src/lib.rs @@ -216,7 +216,7 @@ pub fn format_statement( || !attached.unattached.is_empty(); if !has_comments { - return format_statement_once(ast, sql, config, attached); + return format_statement_once(ast, config, attached); } let mut current_sql = sql.to_string(); @@ -225,7 +225,7 @@ pub fn format_statement( let mut seen_layouts = HashSet::from([current_sql.clone()]); for pass in 1..=MAX_COMMENT_FORMAT_PASSES { - let result = format_statement_once(¤t_ast, ¤t_sql, config, attached)?; + let result = format_statement_once(¤t_ast, config, attached)?; if result.formatted == current_sql { return Ok(result); } @@ -254,7 +254,6 @@ pub fn format_statement( /// Formats a statement exactly once, including semantic verification. fn format_statement_once( ast: &NodeEnum, - sql: &str, config: &FormatConfig, attached: AttachedComments, ) -> Result { @@ -270,8 +269,7 @@ fn format_statement_once( config.clone(), attached.leading_by_location, attached.trailing_by_location, - ) - .with_source(sql); + ); nodes::emit_node_enum(ast, &mut emitter); let pending = emitter.pending_comments(); if pending > 0 { diff --git a/crates/pgls_pretty_print/src/nodes/alter_function_stmt.rs b/crates/pgls_pretty_print/src/nodes/alter_function_stmt.rs index fe7b15965..89e3d70d0 100644 --- a/crates/pgls_pretty_print/src/nodes/alter_function_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/alter_function_stmt.rs @@ -22,12 +22,6 @@ pub(super) fn emit_alter_function_stmt(e: &mut EventEmitter, n: &AlterFunctionSt emit_object_with_args(e, func); } - let dollar_hint = if n.objtype() == ObjectType::ObjectProcedure { - super::DollarQuoteHint::Procedure - } else { - super::DollarQuoteHint::Function - }; - // Actions (IMMUTABLE, SECURITY DEFINER, SET ..., etc.) are separated by whitespace, not commas. // Sort according to Postgres's canonical order if !n.actions.is_empty() { @@ -35,7 +29,7 @@ pub(super) fn emit_alter_function_stmt(e: &mut EventEmitter, n: &AlterFunctionSt for action in super::create_function_stmt::sort_function_options(&n.actions) { let def_elem = assert_node_variant!(DefElem, &action); e.line(LineType::SoftOrSpace); - super::create_function_stmt::format_function_option(e, def_elem, dollar_hint); + super::create_function_stmt::format_function_option(e, def_elem); } e.indent_end(); } diff --git a/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs b/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs index b734e885d..640598288 100644 --- a/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/create_function_stmt.rs @@ -83,19 +83,12 @@ pub(super) fn emit_create_function_stmt(e: &mut EventEmitter, n: &CreateFunction super::emit_type_name(e, return_type); } - // Determine the dollar quote hint based on whether this is a procedure or function - let dollar_hint = if n.is_procedure { - super::DollarQuoteHint::Procedure - } else { - super::DollarQuoteHint::Function - }; - // Options - sort according to Postgres's canonical order let sorted_options = sort_function_options(&n.options); for option in sorted_options { if let Some(pgls_query::NodeEnum::DefElem(def_elem)) = &option.node { e.line(LineType::Hard); - format_function_option(e, def_elem, dollar_hint); + format_function_option(e, def_elem); } } @@ -262,11 +255,7 @@ pub(super) fn sort_function_options( sorted } -pub(super) fn format_function_option( - e: &mut EventEmitter, - d: &pgls_query::protobuf::DefElem, - hint: super::DollarQuoteHint, -) { +pub(super) fn format_function_option(e: &mut EventEmitter, d: &pgls_query::protobuf::DefElem) { let defname_lower = d.defname.to_lowercase(); match defname_lower.as_str() { @@ -281,7 +270,7 @@ pub(super) fn format_function_option( // Single item: either library name (C) or SQL body (SQL/plpgsql) if let Some(pgls_query::NodeEnum::String(s)) = &list.items[0].node { // Use dollar quotes for function bodies (they handle embedded quotes better) - super::emit_body_literal(e, &s.sval, d.location, hint); + super::emit_body_literal(e, &s.sval); } else { super::emit_node(&list.items[0], e); } diff --git a/crates/pgls_pretty_print/src/nodes/do_stmt.rs b/crates/pgls_pretty_print/src/nodes/do_stmt.rs index 567f66b04..7abefc4c8 100644 --- a/crates/pgls_pretty_print/src/nodes/do_stmt.rs +++ b/crates/pgls_pretty_print/src/nodes/do_stmt.rs @@ -5,9 +5,7 @@ use crate::{ emitter::{EventEmitter, GroupKind, LineType}, }; -use super::string::{ - DollarQuoteHint, emit_body_literal, emit_identifier_maybe_quoted, emit_keyword, -}; +use super::string::{emit_body_literal, emit_identifier_maybe_quoted, emit_keyword}; pub(super) fn emit_do_stmt(e: &mut EventEmitter, n: &DoStmt) { e.group_start(GroupKind::DoStmt); @@ -71,14 +69,14 @@ pub(super) fn emit_do_stmt(e: &mut EventEmitter, n: &DoStmt) { e.space(); emit_identifier_maybe_quoted(e, lang); } - if let Some((code, location)) = &body { + if let Some((code, _)) = &body { e.line(LineType::SoftOrSpace); - emit_body_literal(e, code, *location, DollarQuoteHint::Do); + emit_body_literal(e, code); } } else { - if let Some((code, location)) = &body { + if let Some((code, _)) = &body { e.line(LineType::SoftOrSpace); - emit_body_literal(e, code, *location, DollarQuoteHint::Do); + emit_body_literal(e, code); } if let Some((lang, _)) = &language { e.line(LineType::SoftOrSpace); diff --git a/crates/pgls_pretty_print/src/nodes/inline_code_block.rs b/crates/pgls_pretty_print/src/nodes/inline_code_block.rs index 2f1e36918..7b2f538f2 100644 --- a/crates/pgls_pretty_print/src/nodes/inline_code_block.rs +++ b/crates/pgls_pretty_print/src/nodes/inline_code_block.rs @@ -2,14 +2,14 @@ use pgls_query::protobuf::InlineCodeBlock; use crate::emitter::{EventEmitter, GroupKind}; -use super::string::{DollarQuoteHint, emit_body_literal}; +use super::string::emit_body_literal; pub(super) fn emit_inline_code_block(e: &mut EventEmitter, n: &InlineCodeBlock) { e.group_start(GroupKind::InlineCodeBlock); if !n.source_text.is_empty() { // InlineCodeBlock is typically used for anonymous code blocks (like DO) - emit_body_literal(e, &n.source_text, -1, DollarQuoteHint::Do); + emit_body_literal(e, &n.source_text); } e.group_end(); diff --git a/crates/pgls_pretty_print/src/nodes/mod.rs b/crates/pgls_pretty_print/src/nodes/mod.rs index 6cb2e7b28..e69ef4a1d 100644 --- a/crates/pgls_pretty_print/src/nodes/mod.rs +++ b/crates/pgls_pretty_print/src/nodes/mod.rs @@ -492,8 +492,8 @@ use sort_group_clause::emit_sort_group_clause; use sql_value_function::emit_sql_value_function; use stats_elem::emit_stats_elem; use string::{ - DollarQuoteHint, emit_body_literal, emit_identifier, emit_identifier_maybe_quoted, - emit_keyword, emit_keywords, emit_string, emit_string_identifier, emit_string_literal, + emit_body_literal, emit_identifier, emit_identifier_maybe_quoted, emit_keyword, emit_keywords, + emit_string, emit_string_identifier, emit_string_literal, }; use sub_link::emit_sub_link; use sub_plan::{emit_alternative_sub_plan, emit_sub_plan}; diff --git a/crates/pgls_pretty_print/src/nodes/string.rs b/crates/pgls_pretty_print/src/nodes/string.rs index caab0d6c3..d4425b2e9 100644 --- a/crates/pgls_pretty_print/src/nodes/string.rs +++ b/crates/pgls_pretty_print/src/nodes/string.rs @@ -89,65 +89,23 @@ pub(super) fn emit_single_quoted_str(e: &mut EventEmitter, value: &str) { e.token(TokenKind::STRING(format!("'{escaped}'"))); } -/// Hint for what kind of dollar-quoted content we're emitting. -/// Used to pick a more meaningful delimiter tag. -#[derive(Debug, Clone, Copy)] -pub enum DollarQuoteHint { - /// Function body - prefer $function$ or $body$ - Function, - /// Procedure body - prefer $procedure$ or $body$ - Procedure, - /// DO block - prefer $do$ or $body$ - Do, -} - -/// Emits a function or `DO` body, whose string literal starts at or after `location`. -/// -/// A body that still reads as it does in the source is written back exactly as it was quoted -/// there, so the tag of `$$ ... $$` and every byte in between survive formatting. A body that -/// changed, or whose source is unknown, is dollar-quoted verbatim: with the tag of the source -/// literal when the new body allows it, or with a tag picked from `hint`. -pub(super) fn emit_body_literal( - e: &mut EventEmitter, - value: &str, - location: i32, - hint: DollarQuoteHint, -) { - let source_literal = e.source_string_literal_from(location); - - if let Some(literal) = source_literal - && decode_literal(literal).as_deref() == Some(value) - { - e.token(TokenKind::STRING(literal.to_string())); - return; - } - - let delimiter = source_literal - .and_then(dollar_quote_tag) - .filter(|tag| can_dollar_quote(value, tag)) - .map(str::to_string) - .unwrap_or_else(|| pick_dollar_delimiter(value, hint)); - e.token(TokenKind::DOLLAR_QUOTE_DELIMITER(delimiter.clone())); +/// Emits a function or `DO` body, dollar-quoted with `$$` so that every body in a file reads the +/// same, or with `$body$` when the body itself contains `$$`. Only the quotes change: the body is +/// written byte for byte, since Postgres stores it as the source of the function. +pub(super) fn emit_body_literal(e: &mut EventEmitter, value: &str) { + let tag = dollar_quote_tag(value); + e.token(TokenKind::DOLLAR_QUOTE_DELIMITER(tag.clone())); e.token(TokenKind::DOLLAR_QUOTE_BODY(value.to_string())); - e.token(TokenKind::DOLLAR_QUOTE_DELIMITER(delimiter)); -} - -/// The value of a plain or dollar-quoted string literal, `None` for any other form. -fn decode_literal(literal: &str) -> Option { - if let Some(tag) = dollar_quote_tag(literal) { - let body = literal.strip_prefix(tag)?.strip_suffix(tag)?; - return Some(body.to_string()); - } - - let body = literal.strip_prefix('\'')?.strip_suffix('\'')?; - Some(body.replace("''", "'")) + e.token(TokenKind::DOLLAR_QUOTE_DELIMITER(tag)); } -/// The opening tag of a dollar-quoted literal, `$$` or `$tag$`. -fn dollar_quote_tag(literal: &str) -> Option<&str> { - let rest = literal.strip_prefix('$')?; - let end = rest.find('$')?; - Some(&literal[..end + 2]) +/// The first of `$$`, `$body$`, `$body1$`, `$body2$`, ... that can quote `body`. +fn dollar_quote_tag(body: &str) -> String { + ["$$".to_string(), "$body$".to_string()] + .into_iter() + .chain((1..).map(|n| format!("$body{n}$"))) + .find(|tag| can_dollar_quote(body, tag)) + .expect("a numbered tag the body does not contain exists") } /// Whether `value` can be quoted with `tag`: the first occurrence of the tag after the opening one @@ -206,60 +164,6 @@ pub(super) fn needs_quoting_as_function_or_type_name(value: &str) -> bool { needs_quoting(value) || keyword_category(value) == Some(KeywordCategory::ColName) } -/// Pick a dollar quote delimiter that doesn't conflict with the body content. -/// Uses the hint to prefer context-appropriate tags. -fn pick_dollar_delimiter(body: &str, hint: DollarQuoteHint) -> String { - // Order tags based on the hint - put the most appropriate ones first - let preferred_tags: &[&str] = match hint { - DollarQuoteHint::Function => &[ - "$function$", - "$body$", - "$$", - "$procedure$", - "$do$", - "$sql$", - "$code$", - "$_$", - ], - DollarQuoteHint::Procedure => &[ - "$procedure$", - "$body$", - "$$", - "$function$", - "$do$", - "$sql$", - "$code$", - "$_$", - ], - DollarQuoteHint::Do => &[ - "$do$", - "$body$", - "$$", - "$function$", - "$procedure$", - "$sql$", - "$code$", - "$_$", - ], - }; - - for tag in preferred_tags { - if can_dollar_quote(body, tag) { - return (*tag).to_string(); - } - } - - // Fall back to numbered tags if all preferred ones conflict - let mut counter = 0usize; - loop { - let tag = format!("$f{counter}$"); - if can_dollar_quote(body, &tag) { - return tag; - } - counter += 1; - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/pgls_pretty_print/tests/postgres_regress.rs b/crates/pgls_pretty_print/tests/postgres_regress.rs index 09138f359..83edc806a 100644 --- a/crates/pgls_pretty_print/tests/postgres_regress.rs +++ b/crates/pgls_pretty_print/tests/postgres_regress.rs @@ -71,7 +71,7 @@ fn round_trip(sql: &str) -> Result<(), String> { let mut expected = ast.clone(); normalize_ast(&mut expected); for max_line_length in LINE_WIDTHS { - let output = catch_unwind(AssertUnwindSafe(|| format(&ast, sql, max_line_length))) + let output = catch_unwind(AssertUnwindSafe(|| format(&ast, max_line_length))) .map_err(|_| format!("formatter panicked at width {max_line_length}"))?; let reparsed = pgls_query::parse(&output) .map_err(|e| format!("output doesn't parse at width {max_line_length}: {e}\n{output}"))? @@ -84,10 +84,10 @@ fn round_trip(sql: &str) -> Result<(), String> { "output has a different AST at width {max_line_length}\n{output}" )); } - let reformatted = catch_unwind(AssertUnwindSafe(|| { - format(&reparsed, &output, max_line_length) - })) - .map_err(|_| format!("formatter panicked on its own output at width {max_line_length}"))?; + let reformatted = catch_unwind(AssertUnwindSafe(|| format(&reparsed, max_line_length))) + .map_err(|_| { + format!("formatter panicked on its own output at width {max_line_length}") + })?; if reformatted != output { return Err(format!( "formatting is not idempotent at width {max_line_length}\n{output}\n---\n{reformatted}" @@ -97,9 +97,9 @@ fn round_trip(sql: &str) -> Result<(), String> { Ok(()) } -fn format(ast: &pgls_query::NodeEnum, sql: &str, max_line_length: usize) -> String { +fn format(ast: &pgls_query::NodeEnum, max_line_length: usize) -> String { let config = FormatConfig::default(); - let mut emitter = EventEmitter::new(config.clone()).with_source(sql); + let mut emitter = EventEmitter::new(config.clone()); emit_node_enum(ast, &mut emitter); let mut output = String::new(); let config = RenderConfig { diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_100.snap index 1c7484c4c..b62bff801 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_100.snap @@ -36,12 +36,12 @@ set session authorization regress_alter_generic_user1; create function alt_func1(int) returns int language sql -as 'SELECT $1 + 1'; +as $$SELECT $1 + 1$$; create function alt_func2(int) returns int language sql -as 'SELECT $1 - 1'; +as $$SELECT $1 - 1$$; create aggregate alt_agg1 (sfunc1 = int4pl, basetype = int4, stype1 = int4, initcond = 0); @@ -80,12 +80,12 @@ set session authorization regress_alter_generic_user2; create function alt_func1(int) returns int language sql -as 'SELECT $1 + 2'; +as $$SELECT $1 + 2$$; create function alt_func2(int) returns int language sql -as 'SELECT $1 - 2'; +as $$SELECT $1 - 2$$; create aggregate alt_agg1 (sfunc1 = int4pl, basetype = int4, stype1 = int4, initcond = 100); @@ -512,7 +512,7 @@ create operator family alt_opf12 using btree; create function fn_opf12(int4, int2) returns bigint language sql -as 'SELECT NULL::BIGINT;'; +as $$SELECT NULL::BIGINT;$$; alter operator family alt_opf12 using btree add function 1 fn_opf12(int4, int2); @@ -527,7 +527,7 @@ create operator family alt_opf13 using hash; create function fn_opf13(int4) returns bigint language sql -as 'SELECT NULL::BIGINT;'; +as $$SELECT NULL::BIGINT;$$; alter operator family alt_opf13 using hash add function 1 fn_opf13(int4); @@ -542,7 +542,7 @@ create operator family alt_opf14 using btree; create function fn_opf14(int4) returns bigint language sql -as 'SELECT NULL::BIGINT;'; +as $$SELECT NULL::BIGINT;$$; alter operator family alt_opf14 using btree add function 1 fn_opf14(int4); @@ -557,7 +557,7 @@ create operator family alt_opf15 using hash; create function fn_opf15(int4, int2) returns bigint language sql -as 'SELECT NULL::BIGINT;'; +as $$SELECT NULL::BIGINT;$$; alter operator family alt_opf15 using hash add function 1 fn_opf15(int4, int2); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_80.snap index 739753541..7f29a268e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_generic_80.snap @@ -36,12 +36,12 @@ set session authorization regress_alter_generic_user1; create function alt_func1(int) returns int language sql -as 'SELECT $1 + 1'; +as $$SELECT $1 + 1$$; create function alt_func2(int) returns int language sql -as 'SELECT $1 - 1'; +as $$SELECT $1 - 1$$; create aggregate alt_agg1 ( sfunc1 = int4pl, @@ -90,12 +90,12 @@ set session authorization regress_alter_generic_user2; create function alt_func1(int) returns int language sql -as 'SELECT $1 + 2'; +as $$SELECT $1 + 2$$; create function alt_func2(int) returns int language sql -as 'SELECT $1 - 2'; +as $$SELECT $1 - 2$$; create aggregate alt_agg1 ( sfunc1 = int4pl, @@ -545,7 +545,7 @@ create operator family alt_opf12 using btree; create function fn_opf12(int4, int2) returns bigint language sql -as 'SELECT NULL::BIGINT;'; +as $$SELECT NULL::BIGINT;$$; alter operator family alt_opf12 using btree add function 1 fn_opf12(int4, int2); @@ -560,7 +560,7 @@ create operator family alt_opf13 using hash; create function fn_opf13(int4) returns bigint language sql -as 'SELECT NULL::BIGINT;'; +as $$SELECT NULL::BIGINT;$$; alter operator family alt_opf13 using hash add function 1 fn_opf13(int4); @@ -575,7 +575,7 @@ create operator family alt_opf14 using btree; create function fn_opf14(int4) returns bigint language sql -as 'SELECT NULL::BIGINT;'; +as $$SELECT NULL::BIGINT;$$; alter operator family alt_opf14 using btree add function 1 fn_opf14(int4); @@ -590,7 +590,7 @@ create operator family alt_opf15 using hash; create function fn_opf15(int4, int2) returns bigint language sql -as 'SELECT NULL::BIGINT;'; +as $$SELECT NULL::BIGINT;$$; alter operator family alt_opf15 using hash add function 1 fn_opf15(int4, int2); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_100.snap index d8f03f972..f9ef81291 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_100.snap @@ -13,7 +13,7 @@ returns float8 language internal stable strict -as 'contsel'; +as $$contsel$$; create operator === ( leftarg = boolean, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_80.snap index 114a7d065..3341f8f37 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__alter_operator_80.snap @@ -13,7 +13,7 @@ returns float8 language internal stable strict -as 'contsel'; +as $$contsel$$; create operator === ( leftarg = boolean, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_100.snap index 7e44f9831..b9bf41956 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_100.snap @@ -383,7 +383,7 @@ values '{100, 100, 100, 99, 96, 100, 100, 99, 96, 1, 99, 1}' ); -do $x$ +do $$ DECLARE r record; r2 record; @@ -462,7 +462,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$x$; +$$; reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_80.snap index 8e0866d80..a591acc51 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_80.snap @@ -440,7 +440,7 @@ values '{100, 100, 100, 99, 96, 100, 100, 99, 96, 1, 99, 1}' ); -do $x$ +do $$ DECLARE r record; r2 record; @@ -519,7 +519,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$x$; +$$; reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_100.snap index 649e78556..6573af629 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_100.snap @@ -160,7 +160,7 @@ values ('uuidcol', 'uuid', '{=}', '{52225222-5222-5222-5222-522252225222}', '{1}'), ('lsncol', 'pg_lsn', '{=, IS, IS NOT}', '{44/455222, NULL, NULL}', '{1, 25, 100}'); -do $x$ +do $$ DECLARE r record; r2 record; @@ -239,7 +239,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$x$; +$$; reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_80.snap index c0d30a691..5ae3ab8a4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_bloom_80.snap @@ -187,7 +187,7 @@ values '{1, 25, 100}' ); -do $x$ +do $$ DECLARE r record; r2 record; @@ -266,7 +266,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$x$; +$$; reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_100.snap index 4a9223ea1..a9ea2cfb5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_100.snap @@ -308,7 +308,7 @@ values '{100, 100, 1, 100, 100, 25, 100}' ); -do $x$ +do $$ DECLARE r record; r2 record; @@ -387,7 +387,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$x$; +$$; reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_80.snap index 2c55c2a0d..08fc152b9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__brin_multi_80.snap @@ -353,7 +353,7 @@ values '{100, 100, 1, 100, 100, 25, 100}' ); -do $x$ +do $$ DECLARE r record; r2 record; @@ -432,7 +432,7 @@ BEGIN IF count != r.matches THEN RAISE WARNING 'unexpected number of results % for %', count, r; END IF; END LOOP; END; -$x$; +$$; reset enable_seqscan; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_100.snap index bc40bb140..2cb5c6044 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_100.snap @@ -126,7 +126,7 @@ create function vol(text) returns text language plpgsql volatile -as 'begin return $1; end'; +as $$begin return $1; end$$; select case case vol('bar') @@ -145,12 +145,12 @@ create function volfoo(text) returns foodomain language plpgsql volatile -as 'begin return $1::foodomain; end'; +as $$begin return $1::foodomain; end$$; create function inline_eq(foodomain, foodomain) returns boolean language sql -as 'SELECT CASE $2::text WHEN $1::text THEN true ELSE false END'; +as $$SELECT CASE $2::text WHEN $1::text THEN true ELSE false END$$; create operator = (procedure = inline_eq, leftarg = foodomain, rightarg = foodomain); @@ -166,16 +166,16 @@ create function make_ad(int, int) returns arrdomain language plpgsql volatile -as 'declare x arrdomain; +as $$declare x arrdomain; begin x := array[$1,$2]; return x; - end'; + end$$; create function ad_eq(arrdomain, arrdomain) returns boolean language plpgsql -as 'begin return array_eq($1, $2); end'; +as $$begin return array_eq($1, $2); end$$; create operator = (procedure = ad_eq, leftarg = arrdomain, rightarg = arrdomain); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_80.snap index e34c883d1..df7105897 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__case_80.snap @@ -129,7 +129,7 @@ create function vol(text) returns text language plpgsql volatile -as 'begin return $1; end'; +as $$begin return $1; end$$; select case case vol('bar') @@ -148,12 +148,12 @@ create function volfoo(text) returns foodomain language plpgsql volatile -as 'begin return $1::foodomain; end'; +as $$begin return $1::foodomain; end$$; create function inline_eq(foodomain, foodomain) returns boolean language sql -as 'SELECT CASE $2::text WHEN $1::text THEN true ELSE false END'; +as $$SELECT CASE $2::text WHEN $1::text THEN true ELSE false END$$; create operator = ( procedure = inline_eq, @@ -177,16 +177,16 @@ create function make_ad(int, int) returns arrdomain language plpgsql volatile -as 'declare x arrdomain; +as $$declare x arrdomain; begin x := array[$1,$2]; return x; - end'; + end$$; create function ad_eq(arrdomain, arrdomain) returns boolean language plpgsql -as 'begin return array_eq($1, $2); end'; +as $$begin return array_eq($1, $2); end$$; create operator = ( procedure = ad_eq, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_100.snap index bb9f1f3a7..f4c10ccdf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_100.snap @@ -405,7 +405,7 @@ select * from unnest((select array_agg(b order by b) from collate_test3)) order create function dup(anyelement) returns anyelement language sql -as 'select $1'; +as $$select $1$$; select a, dup(b) from collate_test1 order by 2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_80.snap index 8b25ac11d..aa9babe80 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.icu.utf8_80.snap @@ -495,7 +495,7 @@ order by 1; create function dup(anyelement) returns anyelement language sql -as 'select $1'; +as $$select $1$$; select a, dup(b) from collate_test1 order by 2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_100.snap index 97a942184..84efe5712 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_100.snap @@ -423,7 +423,7 @@ select * from unnest((select array_agg(b order by b) from collate_test3)) order create function dup(anyelement) returns anyelement language sql -as 'select $1'; +as $$select $1$$; select a, dup(b) from collate_test1 order by 2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_80.snap index c474adcc8..7f2010702 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate.linux.utf8_80.snap @@ -491,7 +491,7 @@ order by 1; create function dup(anyelement) returns anyelement language sql -as 'select $1'; +as $$select $1$$; select a, dup(b) from collate_test1 order by 2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_100.snap index 222c5cf4f..0ea412e2e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_100.snap @@ -216,7 +216,7 @@ select a, cast(b as varchar) from collate_test2 order by 2; create function vc(text) returns text language sql -as 'select $1::varchar'; +as $$select $1::varchar$$; select a, b from collate_test1 order by a, vc(b); @@ -227,7 +227,7 @@ select * from unnest((select array_agg(b order by b) from collate_test2)) order create function dup(anyelement) returns anyelement language sql -as 'select $1'; +as $$select $1$$; select a, dup(b) from collate_test1 order by 2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_80.snap index 145d6247c..de63bcce1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__collate_80.snap @@ -279,7 +279,7 @@ select a, cast(b as varchar) from collate_test2 order by 2; create function vc(text) returns text language sql -as 'select $1::varchar'; +as $$select $1::varchar$$; select a, b from collate_test1 order by a, vc(b); @@ -298,7 +298,7 @@ order by 1; create function dup(anyelement) returns anyelement language sql -as 'select $1'; +as $$select $1$$; select a, dup(b) from collate_test1 order by 2; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_100.snap index 5c373d2d6..910b61bb5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_100.snap @@ -27,7 +27,7 @@ create table cmdata2 (f1 int compression pglz); create or replace function large_val() returns text language sql -as 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g'; +as $$select array_agg(fipshash(g::text))::text from generate_series(1, 256) g$$; create table cmdata2 (f1 text compression pglz); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_80.snap index 5c373d2d6..910b61bb5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_80.snap @@ -27,7 +27,7 @@ create table cmdata2 (f1 int compression pglz); create or replace function large_val() returns text language sql -as 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g'; +as $$select array_agg(fipshash(g::text))::text from generate_series(1, 256) g$$; create table cmdata2 (f1 text compression pglz); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_100.snap index 2fe4a2bf0..4dbeee4b5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_100.snap @@ -60,7 +60,7 @@ select pg_column_compression(f1) from cmmove2; create or replace function large_val_lz4() returns text language sql -as 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g'; +as $$select array_agg(fipshash(g::text))::text from generate_series(1, 256) g$$; create table cmdata2 (f1 text compression lz4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_80.snap index 3d1a7a9d8..de0af93ab 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__compression_lz4_80.snap @@ -60,7 +60,7 @@ select pg_column_compression(f1) from cmmove2; create or replace function large_val_lz4() returns text language sql -as 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g'; +as $$select array_agg(fipshash(g::text))::text from generate_series(1, 256) g$$; create table cmdata2 (f1 text compression lz4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_100.snap index 7dda8b3aa..8675c04bb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_100.snap @@ -13,22 +13,22 @@ create temporary table x ( create function fn_x_before() returns trigger language plpgsql -as ' +as $$ BEGIN - NEW.e := ''before trigger fired''::text; + NEW.e := 'before trigger fired'::text; return NEW; END; -'; +$$; create function fn_x_after() returns trigger language plpgsql -as ' +as $$ BEGIN - UPDATE x set e=''after trigger fired'' where c=''stuff''; + UPDATE x set e='after trigger fired' where c='stuff'; return NULL; END; -'; +$$; create trigger trg_x_after after insert on x for each row execute function fn_x_after(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_80.snap index ec1640d42..2fe933465 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__copy2_80.snap @@ -13,22 +13,22 @@ create temporary table x ( create function fn_x_before() returns trigger language plpgsql -as ' +as $$ BEGIN - NEW.e := ''before trigger fired''::text; + NEW.e := 'before trigger fired'::text; return NEW; END; -'; +$$; create function fn_x_after() returns trigger language plpgsql -as ' +as $$ BEGIN - UPDATE x set e=''after trigger fired'' where c=''stuff''; + UPDATE x set e='after trigger fired' where c='stuff'; return NULL; END; -'; +$$; create trigger trg_x_after after insert diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_100.snap index f28c44e19..cd2f6756a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_100.snap @@ -35,7 +35,7 @@ returns int8 language sql immutable strict -as 'select $1 + $2 + $3'; +as $$select $1 + $2 + $3$$; create aggregate sum2 (int8, int8) (sfunc = sum3, stype = int8, initcond = '0'); @@ -46,13 +46,13 @@ returns aggtype[] language sql immutable strict -as 'select array_append($1,ROW($2,$3,$4)::aggtype)'; +as $$select array_append($1,ROW($2,$3,$4)::aggtype)$$; create function aggfns_trans(aggtype[], int, int, text) returns aggtype[] language sql immutable -as 'select array_append($1,ROW($2,$3,$4)::aggtype)'; +as $$select array_append($1,ROW($2,$3,$4)::aggtype)$$; create aggregate aggfstr (int, int, text) (sfunc = aggf_trans, stype = aggtype[], initcond = '{}'); @@ -68,7 +68,7 @@ create aggregate aggfns ( create function least_accum(int8, int8) returns int8 language sql -as 'select least($1, $2)'; +as $$select least($1, $2)$$; create aggregate least_agg (int4) (stype = int8, sfunc = least_accum); @@ -77,7 +77,7 @@ drop function least_accum(int8, int8); create function least_accum(anycompatible, anycompatible) returns anycompatible language sql -as 'select least($1, $2)'; +as $$select least($1, $2)$$; create aggregate least_agg (int4) (stype = int8, sfunc = least_accum); @@ -88,14 +88,14 @@ drop function least_accum(anycompatible, anycompatible) cascade; create function least_accum(anyelement, variadic anyarray) returns anyelement language sql -as 'select least($1, min($2[i])) from generate_subscripts($2,1) g(i)'; +as $$select least($1, min($2[i])) from generate_subscripts($2,1) g(i)$$; create aggregate least_agg (variadic items anyarray) (stype = anyelement, sfunc = least_accum); create function cleast_accum(anycompatible, variadic anycompatiblearray) returns anycompatible language sql -as 'select least($1, min($2[i])) from generate_subscripts($2,1) g(i)'; +as $$select least($1, min($2[i])) from generate_subscripts($2,1) g(i)$$; create aggregate cleast_agg ( variadic items anycompatiblearray @@ -264,7 +264,7 @@ returns int8 language sql immutable strict -as 'select $1 + $2 + $3 + $4'; +as $$select $1 + $2 + $3 + $4$$; create or replace aggregate sum3 (int8, int8, int8) (stype = int8, sfunc = sum4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_80.snap index d24992b63..2d274e91a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_aggregate_80.snap @@ -58,7 +58,7 @@ returns int8 language sql immutable strict -as 'select $1 + $2 + $3'; +as $$select $1 + $2 + $3$$; create aggregate sum2 (int8, int8) (sfunc = sum3, stype = int8, initcond = '0'); @@ -69,13 +69,13 @@ returns aggtype[] language sql immutable strict -as 'select array_append($1,ROW($2,$3,$4)::aggtype)'; +as $$select array_append($1,ROW($2,$3,$4)::aggtype)$$; create function aggfns_trans(aggtype[], int, int, text) returns aggtype[] language sql immutable -as 'select array_append($1,ROW($2,$3,$4)::aggtype)'; +as $$select array_append($1,ROW($2,$3,$4)::aggtype)$$; create aggregate aggfstr ( int, int, text @@ -97,7 +97,7 @@ create aggregate aggfns ( create function least_accum(int8, int8) returns int8 language sql -as 'select least($1, $2)'; +as $$select least($1, $2)$$; create aggregate least_agg (int4) (stype = int8, sfunc = least_accum); @@ -106,7 +106,7 @@ drop function least_accum(int8, int8); create function least_accum(anycompatible, anycompatible) returns anycompatible language sql -as 'select least($1, $2)'; +as $$select least($1, $2)$$; create aggregate least_agg (int4) (stype = int8, sfunc = least_accum); @@ -117,7 +117,7 @@ drop function least_accum(anycompatible, anycompatible) cascade; create function least_accum(anyelement, variadic anyarray) returns anyelement language sql -as 'select least($1, min($2[i])) from generate_subscripts($2,1) g(i)'; +as $$select least($1, min($2[i])) from generate_subscripts($2,1) g(i)$$; create aggregate least_agg ( variadic items anyarray @@ -129,7 +129,7 @@ create aggregate least_agg ( create function cleast_accum(anycompatible, variadic anycompatiblearray) returns anycompatible language sql -as 'select least($1, min($2[i])) from generate_subscripts($2,1) g(i)'; +as $$select least($1, min($2[i])) from generate_subscripts($2,1) g(i)$$; create aggregate cleast_agg ( variadic items anycompatiblearray @@ -309,7 +309,7 @@ returns int8 language sql immutable strict -as 'select $1 + $2 + $3 + $4'; +as $$select $1 + $2 + $3 + $4$$; create or replace aggregate sum3 ( int8, int8, int8 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_100.snap index 66847c604..a7d96a590 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_100.snap @@ -9,14 +9,14 @@ returns casttesttype language internal immutable strict -as 'textin'; +as $$textin$$; create function casttesttype_out(casttesttype) returns cstring language internal immutable strict -as 'textout'; +as $$textout$$; create type casttesttype ( internallength = variable, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_80.snap index 692efe0a8..7575e7034 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_cast_80.snap @@ -9,14 +9,14 @@ returns casttesttype language internal immutable strict -as 'textin'; +as $$textin$$; create function casttesttype_out(casttesttype) returns cstring language internal immutable strict -as 'textout'; +as $$textout$$; create type casttesttype ( internallength = variable, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_100.snap index 94aa3a361..dd0b70c60 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_100.snap @@ -7,7 +7,7 @@ load 'regresslib'; create function test1(int) returns int language c -as 'nosuchfile'; +as $$nosuchfile$$; create function test1(int) returns int @@ -19,4 +19,4 @@ select regexp_replace('LAST_ERROR_MESSAGE', 'file ".*"', 'file "..."'); create function test1(int) returns int language internal -as 'nosuch'; +as $$nosuch$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_80.snap index 94aa3a361..dd0b70c60 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_c_80.snap @@ -7,7 +7,7 @@ load 'regresslib'; create function test1(int) returns int language c -as 'nosuchfile'; +as $$nosuchfile$$; create function test1(int) returns int @@ -19,4 +19,4 @@ select regexp_replace('LAST_ERROR_MESSAGE', 'file ".*"', 'file "..."'); create function test1(int) returns int language internal -as 'nosuch'; +as $$nosuch$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_100.snap index 889e4f874..89c89edfc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_100.snap @@ -13,17 +13,17 @@ set search_path to temp_func_test, public; create function functest_a_1(text, date) returns bool language sql -as 'SELECT $1 = ''abcd'' AND $2 > ''2001-01-01'''; +as $$SELECT $1 = 'abcd' AND $2 > '2001-01-01'$$; create function functest_a_2(text[]) returns int language sql -as 'SELECT $1[1]::int'; +as $$SELECT $1[1]::int$$; create function functest_a_3() returns bool language sql -as 'SELECT false'; +as $$SELECT false$$; select proname, @@ -48,25 +48,25 @@ select functest_a_3(); create function functest_b_1(int) returns bool language sql -as 'SELECT $1 > 0'; +as $$SELECT $1 > 0$$; create function functest_b_2(int) returns bool language sql immutable -as 'SELECT $1 > 0'; +as $$SELECT $1 > 0$$; create function functest_b_3(int) returns bool language sql stable -as 'SELECT $1 = 0'; +as $$SELECT $1 = 0$$; create function functest_b_4(int) returns bool language sql volatile -as 'SELECT $1 < 0'; +as $$SELECT $1 < 0$$; select proname, @@ -101,19 +101,19 @@ order by proname; create function functest_c_1(int) returns bool language sql -as 'SELECT $1 > 0'; +as $$SELECT $1 > 0$$; create function functest_c_2(int) returns bool language sql security definer -as 'SELECT $1 = 0'; +as $$SELECT $1 = 0$$; create function functest_c_3(int) returns bool language sql security invoker -as 'SELECT $1 < 0'; +as $$SELECT $1 < 0$$; select proname, @@ -150,13 +150,13 @@ order by proname; create function functest_e_1(int) returns bool language sql -as 'SELECT $1 > 100'; +as $$SELECT $1 > 100$$; create function functest_e_2(int) returns bool language sql leakproof -as 'SELECT $1 > 100'; +as $$SELECT $1 > 100$$; select proname, @@ -207,32 +207,32 @@ create function functest_e_3(int) returns bool language sql leakproof -as 'SELECT $1 < 200'; +as $$SELECT $1 < 200$$; reset session_authorization; create function functest_f_1(int) returns bool language sql -as 'SELECT $1 > 50'; +as $$SELECT $1 > 50$$; create function functest_f_2(int) returns bool language sql called on null input -as 'SELECT $1 = 50'; +as $$SELECT $1 = 50$$; create function functest_f_3(int) returns bool language sql strict -as 'SELECT $1 < 50'; +as $$SELECT $1 < 50$$; create function functest_f_4(int) returns bool language sql strict -as 'SELECT $1 = 50'; +as $$SELECT $1 = 50$$; select proname, @@ -371,17 +371,17 @@ drop table functest3 cascade; create function functest_is_1(a int, b int default 1, c text default 'foo') returns int language sql -as 'SELECT $1 + $2'; +as $$SELECT $1 + $2$$; create function functest_is_2(out a int, b int default 1) returns int language sql -as 'SELECT $1'; +as $$SELECT $1$$; create function functest_is_3(a int default 1, out b int) returns int language sql -as 'SELECT $1'; +as $$SELECT $1$$; select routine_name, @@ -405,19 +405,19 @@ drop function functest_is_1(int, int, text), functest_is_2(int), functest_is_3(i create function functest_is_4a() returns int language sql -as 'SELECT 1'; +as $$SELECT 1$$; create function functest_is_4b(x int default functest_is_4a()) returns int language sql -as 'SELECT x'; +as $$SELECT x$$; create sequence functest1; create function functest_is_5(x int default nextval('functest1')) returns int language sql -as 'SELECT x'; +as $$SELECT x$$; create function functest_is_6() returns int @@ -491,7 +491,7 @@ create function functest_b_2(bigint) returns bool language sql immutable -as 'SELECT $1 > 0'; +as $$SELECT $1 > 0$$; drop function functest_b_1; @@ -502,17 +502,17 @@ drop function functest_b_2; create function functest1(a int) returns int language sql -as 'SELECT $1'; +as $$SELECT $1$$; create or replace function functest1(a int) returns int language sql window -as 'SELECT $1'; +as $$SELECT $1$$; create or replace procedure functest1(a int) language sql -as 'SELECT $1'; +as $$SELECT $1$$; drop function functest1(a int); @@ -531,9 +531,9 @@ create function functest_sri1() returns setof int language sql stable -as ' +as $$ SELECT * FROM functest3; -'; +$$; select * from functest_sri1(); @@ -655,22 +655,22 @@ insert into pt values (1); create function test1(int) returns int language sql -as 'SELECT ''not an integer'';'; +as $$SELECT 'not an integer';$$; create function test1(int) returns int language sql -as 'not even SQL'; +as $$not even SQL$$; create function test1(int) returns int language sql -as 'SELECT 1, 2, 3;'; +as $$SELECT 1, 2, 3;$$; create function test1(int) returns int language sql -as 'SELECT $2;'; +as $$SELECT $2;$$; create function test1(int) returns int @@ -680,14 +680,14 @@ as 'a', 'b'; create function test1(int) returns int language sql -as ''; +as $$$$; set check_function_bodies = off; create function test1(anyelement) returns anyarray language sql -as ''; +as $$$$; select test1(0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_80.snap index a45693e58..1bf574f82 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_function_sql_80.snap @@ -13,17 +13,17 @@ set search_path to temp_func_test, public; create function functest_a_1(text, date) returns bool language sql -as 'SELECT $1 = ''abcd'' AND $2 > ''2001-01-01'''; +as $$SELECT $1 = 'abcd' AND $2 > '2001-01-01'$$; create function functest_a_2(text[]) returns int language sql -as 'SELECT $1[1]::int'; +as $$SELECT $1[1]::int$$; create function functest_a_3() returns bool language sql -as 'SELECT false'; +as $$SELECT false$$; select proname, @@ -48,25 +48,25 @@ select functest_a_3(); create function functest_b_1(int) returns bool language sql -as 'SELECT $1 > 0'; +as $$SELECT $1 > 0$$; create function functest_b_2(int) returns bool language sql immutable -as 'SELECT $1 > 0'; +as $$SELECT $1 > 0$$; create function functest_b_3(int) returns bool language sql stable -as 'SELECT $1 = 0'; +as $$SELECT $1 = 0$$; create function functest_b_4(int) returns bool language sql volatile -as 'SELECT $1 < 0'; +as $$SELECT $1 < 0$$; select proname, @@ -101,19 +101,19 @@ order by proname; create function functest_c_1(int) returns bool language sql -as 'SELECT $1 > 0'; +as $$SELECT $1 > 0$$; create function functest_c_2(int) returns bool language sql security definer -as 'SELECT $1 = 0'; +as $$SELECT $1 = 0$$; create function functest_c_3(int) returns bool language sql security invoker -as 'SELECT $1 < 0'; +as $$SELECT $1 < 0$$; select proname, @@ -150,13 +150,13 @@ order by proname; create function functest_e_1(int) returns bool language sql -as 'SELECT $1 > 100'; +as $$SELECT $1 > 100$$; create function functest_e_2(int) returns bool language sql leakproof -as 'SELECT $1 > 100'; +as $$SELECT $1 > 100$$; select proname, @@ -207,32 +207,32 @@ create function functest_e_3(int) returns bool language sql leakproof -as 'SELECT $1 < 200'; +as $$SELECT $1 < 200$$; reset session_authorization; create function functest_f_1(int) returns bool language sql -as 'SELECT $1 > 50'; +as $$SELECT $1 > 50$$; create function functest_f_2(int) returns bool language sql called on null input -as 'SELECT $1 = 50'; +as $$SELECT $1 = 50$$; create function functest_f_3(int) returns bool language sql strict -as 'SELECT $1 < 50'; +as $$SELECT $1 < 50$$; create function functest_f_4(int) returns bool language sql strict -as 'SELECT $1 = 50'; +as $$SELECT $1 = 50$$; select proname, @@ -371,17 +371,17 @@ drop table functest3 cascade; create function functest_is_1(a int, b int default 1, c text default 'foo') returns int language sql -as 'SELECT $1 + $2'; +as $$SELECT $1 + $2$$; create function functest_is_2(out a int, b int default 1) returns int language sql -as 'SELECT $1'; +as $$SELECT $1$$; create function functest_is_3(a int default 1, out b int) returns int language sql -as 'SELECT $1'; +as $$SELECT $1$$; select routine_name, @@ -408,19 +408,19 @@ drop function create function functest_is_4a() returns int language sql -as 'SELECT 1'; +as $$SELECT 1$$; create function functest_is_4b(x int default functest_is_4a()) returns int language sql -as 'SELECT x'; +as $$SELECT x$$; create sequence functest1; create function functest_is_5(x int default nextval('functest1')) returns int language sql -as 'SELECT x'; +as $$SELECT x$$; create function functest_is_6() returns int @@ -494,7 +494,7 @@ create function functest_b_2(bigint) returns bool language sql immutable -as 'SELECT $1 > 0'; +as $$SELECT $1 > 0$$; drop function functest_b_1; @@ -505,17 +505,17 @@ drop function functest_b_2; create function functest1(a int) returns int language sql -as 'SELECT $1'; +as $$SELECT $1$$; create or replace function functest1(a int) returns int language sql window -as 'SELECT $1'; +as $$SELECT $1$$; create or replace procedure functest1(a int) language sql -as 'SELECT $1'; +as $$SELECT $1$$; drop function functest1(a int); @@ -534,9 +534,9 @@ create function functest_sri1() returns setof int language sql stable -as ' +as $$ SELECT * FROM functest3; -'; +$$; select * from functest_sri1(); @@ -658,22 +658,22 @@ insert into pt values (1); create function test1(int) returns int language sql -as 'SELECT ''not an integer'';'; +as $$SELECT 'not an integer';$$; create function test1(int) returns int language sql -as 'not even SQL'; +as $$not even SQL$$; create function test1(int) returns int language sql -as 'SELECT 1, 2, 3;'; +as $$SELECT 1, 2, 3;$$; create function test1(int) returns int language sql -as 'SELECT $2;'; +as $$SELECT $2;$$; create function test1(int) returns int @@ -683,14 +683,14 @@ as 'a', 'b'; create function test1(int) returns int language sql -as ''; +as $$$$; set check_function_bodies = off; create function test1(anyelement) returns anyarray language sql -as ''; +as $$$$; select test1(0); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_100.snap index e77afc50c..b05bd3565 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_100.snap @@ -1626,7 +1626,7 @@ rollback; create or replace function create_relfilenode_part(relname text, indname text) returns void language plpgsql -as $func$ +as $$ BEGIN EXECUTE format(' CREATE TABLE %I AS @@ -1636,7 +1636,7 @@ as $func$ (SELECT relid FROM pg_partition_tree(''%I''));', relname, indname); END - $func$; + $$; create or replace function compare_relfilenode_part(tabname text) returns table ( @@ -1645,7 +1645,7 @@ returns table ( state text ) language plpgsql -as $func$ +as $$ BEGIN RETURN QUERY EXECUTE format( @@ -1657,7 +1657,7 @@ as $func$ FROM %I b JOIN pg_class a ON b.relname = a.relname ORDER BY 1;', tabname); END - $func$; + $$; select create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_80.snap index 8418409cc..8617d1dc5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_index_80.snap @@ -1964,7 +1964,7 @@ rollback; create or replace function create_relfilenode_part(relname text, indname text) returns void language plpgsql -as $func$ +as $$ BEGIN EXECUTE format(' CREATE TABLE %I AS @@ -1974,7 +1974,7 @@ as $func$ (SELECT relid FROM pg_partition_tree(''%I''));', relname, indname); END - $func$; + $$; create or replace function compare_relfilenode_part(tabname text) returns table ( @@ -1983,7 +1983,7 @@ returns table ( state text ) language plpgsql -as $func$ +as $$ BEGIN RETURN QUERY EXECUTE format( @@ -1995,7 +1995,7 @@ as $func$ FROM %I b JOIN pg_class a ON b.relname = a.relname ORDER BY 1;', tabname); END - $func$; + $$; select create_relfilenode_part('reindex_index_status', 'concur_reindex_part_index'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_100.snap index 402cec997..e6a36a0f4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_100.snap @@ -7,28 +7,28 @@ returns widget language c immutable strict -as 'regresslib'; +as $$regresslib$$; create function widget_out(widget) returns cstring language c immutable strict -as 'regresslib'; +as $$regresslib$$; create function int44in(cstring) returns city_budget language c immutable strict -as 'regresslib'; +as $$regresslib$$; create function int44out(city_budget) returns cstring language c immutable strict -as 'regresslib'; +as $$regresslib$$; create type widget ( internallength = 24, @@ -67,28 +67,28 @@ returns int42 language internal immutable strict -as 'int4in'; +as $$int4in$$; create function int42_out(int42) returns cstring language internal immutable strict -as 'int4out'; +as $$int4out$$; create function text_w_default_in(cstring) returns text_w_default language internal immutable strict -as 'textin'; +as $$textin$$; create function text_w_default_out(text_w_default) returns cstring language internal immutable strict -as 'textout'; +as $$textout$$; create type int42 ( internallength = 4, @@ -138,9 +138,9 @@ create type default_test_row as (f1 text_w_default, f2 int42); create function get_default_test() returns setof default_test_row language sql -as ' +as $$ SELECT * FROM default_test; -'; +$$; select * from get_default_test(); @@ -169,14 +169,14 @@ returns base_type language internal immutable strict -as 'boolin'; +as $$boolin$$; create function base_fn_out(base_type) returns cstring language internal immutable strict -as 'boolout'; +as $$boolout$$; create type base_type (input = base_fn_in, output = base_fn_out); @@ -225,7 +225,7 @@ create function pt_in_widget(point, widget) returns bool language c strict -as 'regresslib'; +as $$regresslib$$; create operator <% ( leftarg = point, @@ -260,7 +260,7 @@ language internal immutable strict parallel safe -as 'varcharin'; +as $$varcharin$$; create function myvarcharout(myvarchar) returns cstring @@ -268,7 +268,7 @@ language internal immutable strict parallel safe -as 'varcharout'; +as $$varcharout$$; create function myvarcharsend(myvarchar) returns bytea @@ -276,7 +276,7 @@ language internal stable strict parallel safe -as 'varcharsend'; +as $$varcharsend$$; create function myvarcharrecv(internal, oid, int) returns myvarchar @@ -284,7 +284,7 @@ language internal stable strict parallel safe -as 'varcharrecv'; +as $$varcharrecv$$; alter type myvarchar set (storage = extended); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_80.snap index da453ac37..9e78bbd62 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_type_80.snap @@ -7,28 +7,28 @@ returns widget language c immutable strict -as 'regresslib'; +as $$regresslib$$; create function widget_out(widget) returns cstring language c immutable strict -as 'regresslib'; +as $$regresslib$$; create function int44in(cstring) returns city_budget language c immutable strict -as 'regresslib'; +as $$regresslib$$; create function int44out(city_budget) returns cstring language c immutable strict -as 'regresslib'; +as $$regresslib$$; create type widget ( internallength = 24, @@ -67,28 +67,28 @@ returns int42 language internal immutable strict -as 'int4in'; +as $$int4in$$; create function int42_out(int42) returns cstring language internal immutable strict -as 'int4out'; +as $$int4out$$; create function text_w_default_in(cstring) returns text_w_default language internal immutable strict -as 'textin'; +as $$textin$$; create function text_w_default_out(text_w_default) returns cstring language internal immutable strict -as 'textout'; +as $$textout$$; create type int42 ( internallength = 4, @@ -148,9 +148,9 @@ create type default_test_row as (f1 text_w_default, f2 int42); create function get_default_test() returns setof default_test_row language sql -as ' +as $$ SELECT * FROM default_test; -'; +$$; select * from get_default_test(); @@ -179,14 +179,14 @@ returns base_type language internal immutable strict -as 'boolin'; +as $$boolin$$; create function base_fn_out(base_type) returns cstring language internal immutable strict -as 'boolout'; +as $$boolout$$; create type base_type (input = base_fn_in, output = base_fn_out); @@ -235,7 +235,7 @@ create function pt_in_widget(point, widget) returns bool language c strict -as 'regresslib'; +as $$regresslib$$; create operator <% ( leftarg = point, @@ -270,7 +270,7 @@ language internal immutable strict parallel safe -as 'varcharin'; +as $$varcharin$$; create function myvarcharout(myvarchar) returns cstring @@ -278,7 +278,7 @@ language internal immutable strict parallel safe -as 'varcharout'; +as $$varcharout$$; create function myvarcharsend(myvarchar) returns bytea @@ -286,7 +286,7 @@ language internal stable strict parallel safe -as 'varcharsend'; +as $$varcharsend$$; create function myvarcharrecv(internal, oid, int) returns myvarchar @@ -294,7 +294,7 @@ language internal stable strict parallel safe -as 'varcharrecv'; +as $$varcharrecv$$; alter type myvarchar set (storage = extended); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_100.snap index 27cd8a96b..814101fe4 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_100.snap @@ -6,7 +6,7 @@ create function interpt_pp(path, path) returns point language c strict -as 'regresslib'; +as $$regresslib$$; create table real_city ( pop int4, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap index 989d85076..00e3ad3c5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__create_view_80.snap @@ -6,7 +6,7 @@ create function interpt_pp(path, path) returns point language c strict -as 'regresslib'; +as $$regresslib$$; create table real_city ( pop int4, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_100.snap index 4e8bcabaf..a41318249 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_100.snap @@ -216,7 +216,7 @@ do instead create function makedcomp(r float8, i float8) returns dcomptype language sql -as 'select row(r, i)'; +as $$select row(r, i)$$; select makedcomp(1, 2); @@ -1024,7 +1024,7 @@ drop domain di; create function sql_is_distinct_from(anyelement, anyelement) returns boolean language sql -as 'select $1 is distinct from $2 limit 1'; +as $$select $1 is distinct from $2 limit 1$$; create domain inotnull as int check (sql_is_distinct_from(value, null)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_80.snap index 7cedf4bcf..f6e2867af 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__domain_80.snap @@ -224,7 +224,7 @@ do instead create function makedcomp(r float8, i float8) returns dcomptype language sql -as 'select row(r, i)'; +as $$select row(r, i)$$; select makedcomp(1, 2); @@ -1059,7 +1059,7 @@ drop domain di; create function sql_is_distinct_from(anyelement, anyelement) returns boolean language sql -as 'select $1 is distinct from $2 limit 1'; +as $$select $1 is distinct from $2 limit 1$$; create domain inotnull as int check (sql_is_distinct_from(value, null)); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_100.snap index cd294daba..b3e416d37 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_100.snap @@ -9,14 +9,14 @@ returns int8alias1 language internal immutable strict -as 'int8in'; +as $$int8in$$; create function int8alias1out(int8alias1) returns cstring language internal immutable strict -as 'int8out'; +as $$int8out$$; create type int8alias1 (input = int8alias1in, output = int8alias1out, "like" = int8); @@ -27,14 +27,14 @@ returns int8alias2 language internal immutable strict -as 'int8in'; +as $$int8in$$; create function int8alias2out(int8alias2) returns cstring language internal immutable strict -as 'int8out'; +as $$int8out$$; create type int8alias2 (input = int8alias2in, output = int8alias2out, "like" = int8); @@ -51,7 +51,7 @@ returns bool language internal immutable strict -as 'int8eq'; +as $$int8eq$$; create operator = ( procedure = int8alias1eq, @@ -70,7 +70,7 @@ returns bool language internal immutable strict -as 'int8eq'; +as $$int8eq$$; create operator = ( procedure = int8alias2eq, @@ -89,7 +89,7 @@ returns bool language internal immutable strict -as 'int8eq'; +as $$int8eq$$; create operator = ( procedure = int8alias1eq, @@ -107,7 +107,7 @@ returns bool language internal immutable strict -as 'int8eq'; +as $$int8eq$$; create operator = ( procedure = int8alias1eq, @@ -125,7 +125,7 @@ returns bool language internal immutable strict -as 'int8lt'; +as $$int8lt$$; create operator < (procedure = int8alias1lt, leftarg = int8alias1, rightarg = int8alias1); @@ -136,7 +136,7 @@ returns int language internal immutable strict -as 'btint8cmp'; +as $$btint8cmp$$; alter operator family integer_ops using btree add function 1 int8alias1cmp(int8, int8alias1); @@ -407,7 +407,7 @@ returns int language internal immutable strict -as 'hashint8'; +as $$hashint8$$; alter operator family integer_ops using hash add function 1 hashint8alias1(int8alias1); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_80.snap index 98e856c9b..44ed775f6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__equivclass_80.snap @@ -9,14 +9,14 @@ returns int8alias1 language internal immutable strict -as 'int8in'; +as $$int8in$$; create function int8alias1out(int8alias1) returns cstring language internal immutable strict -as 'int8out'; +as $$int8out$$; create type int8alias1 ( input = int8alias1in, @@ -31,14 +31,14 @@ returns int8alias2 language internal immutable strict -as 'int8in'; +as $$int8in$$; create function int8alias2out(int8alias2) returns cstring language internal immutable strict -as 'int8out'; +as $$int8out$$; create type int8alias2 ( input = int8alias2in, @@ -59,7 +59,7 @@ returns bool language internal immutable strict -as 'int8eq'; +as $$int8eq$$; create operator = ( procedure = int8alias1eq, @@ -79,7 +79,7 @@ returns bool language internal immutable strict -as 'int8eq'; +as $$int8eq$$; create operator = ( procedure = int8alias2eq, @@ -99,7 +99,7 @@ returns bool language internal immutable strict -as 'int8eq'; +as $$int8eq$$; create operator = ( procedure = int8alias1eq, @@ -118,7 +118,7 @@ returns bool language internal immutable strict -as 'int8eq'; +as $$int8eq$$; create operator = ( procedure = int8alias1eq, @@ -137,7 +137,7 @@ returns bool language internal immutable strict -as 'int8lt'; +as $$int8lt$$; create operator < ( procedure = int8alias1lt, @@ -153,7 +153,7 @@ returns int language internal immutable strict -as 'btint8cmp'; +as $$btint8cmp$$; alter operator family integer_ops using btree add function 1 int8alias1cmp(int8, int8alias1); @@ -465,7 +465,7 @@ returns int language internal immutable strict -as 'hashint8'; +as $$hashint8$$; alter operator family integer_ops using hash add function 1 hashint8alias1(int8alias1); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_100.snap index 8fd0248b6..215b92b23 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_100.snap @@ -156,7 +156,7 @@ create temporary table t1 (f1 float8); create function pg_temp.mysin(float8) returns float8 language plpgsql -as 'begin return sin($1); end'; +as $$begin return sin($1); end$$; select explain_filter('explain (verbose) select * from t1 where pg_temp.mysin(f1) < 0.5'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_80.snap index 8d49aab3a..ce397bf07 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__explain_80.snap @@ -195,7 +195,7 @@ create temporary table t1 (f1 float8); create function pg_temp.mysin(float8) returns float8 language plpgsql -as 'begin return sin($1); end'; +as $$begin return sin($1); end$$; select explain_filter( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_100.snap index a88757c44..c40a1af2e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_100.snap @@ -150,21 +150,21 @@ returns myint language internal immutable strict -as 'int4in'; +as $$int4in$$; create function myintout(myint) returns cstring language internal immutable strict -as 'int4out'; +as $$int4out$$; create function myinthash(myint) returns int language internal immutable strict -as 'hashint4'; +as $$hashint4$$; create type myint (input = myintin, output = myintout, "like" = int4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_80.snap index 24a20099e..a373deabf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__expressions_80.snap @@ -167,21 +167,21 @@ returns myint language internal immutable strict -as 'int4in'; +as $$int4in$$; create function myintout(myint) returns cstring language internal immutable strict -as 'int4out'; +as $$int4out$$; create function myinthash(myint) returns int language internal immutable strict -as 'hashint4'; +as $$hashint4$$; create type myint (input = myintin, output = myintout, "like" = int4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_100.snap index cd0272251..40e854d4f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_100.snap @@ -43,7 +43,7 @@ $$; create function log_rewrite() returns event_trigger language plpgsql -as $func$ +as $$ declare this_schema text; @@ -58,7 +58,7 @@ begin pg_event_trigger_table_rewrite_reason(); end if; end; -$func$; +$$; create table has_volatile as select * from generate_series(1, 10) as id; @@ -384,7 +384,7 @@ create function foolme(timestamptz default clock_timestamp()) returns timestamptz language sql immutable -as 'select $1'; +as $$select $1$$; alter table t add column c3 timestamptz default foolme(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_80.snap index 1af35acbd..4fc093bb3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__fast_default_80.snap @@ -43,7 +43,7 @@ $$; create function log_rewrite() returns event_trigger language plpgsql -as $func$ +as $$ declare this_schema text; @@ -58,7 +58,7 @@ begin pg_event_trigger_table_rewrite_reason(); end if; end; -$func$; +$$; create table has_volatile as select * from generate_series(1, 10) as id; @@ -392,7 +392,7 @@ create function foolme(timestamptz default clock_timestamp()) returns timestamptz language sql immutable -as 'select $1'; +as $$select $1$$; alter table t add column c3 timestamptz default foolme(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_100.snap index 5c7cdd644..373f9f534 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_100.snap @@ -187,14 +187,14 @@ returns xfloat4 language internal immutable strict -as 'int4in'; +as $$int4in$$; create function xfloat4out(xfloat4) returns cstring language internal immutable strict -as 'int4out'; +as $$int4out$$; create type xfloat4 (input = xfloat4in, output = xfloat4out, "like" = float4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_80.snap index b6f98fbad..798050ab6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float4_80.snap @@ -187,14 +187,14 @@ returns xfloat4 language internal immutable strict -as 'int4in'; +as $$int4in$$; create function xfloat4out(xfloat4) returns cstring language internal immutable strict -as 'int4out'; +as $$int4out$$; create type xfloat4 (input = xfloat4in, output = xfloat4out, "like" = float4); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_100.snap index a689ac8d3..34fad7525 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_100.snap @@ -426,14 +426,14 @@ returns xfloat8 language internal immutable strict -as 'int8in'; +as $$int8in$$; create function xfloat8out(xfloat8) returns cstring language internal immutable strict -as 'int8out'; +as $$int8out$$; create type xfloat8 (input = xfloat8in, output = xfloat8out, "like" = no_such_type); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_80.snap index 2f665862d..1e8c0aa20 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__float8_80.snap @@ -450,14 +450,14 @@ returns xfloat8 language internal immutable strict -as 'int8in'; +as $$int8in$$; create function xfloat8out(xfloat8) returns cstring language internal immutable strict -as 'int8out'; +as $$int8out$$; create type xfloat8 ( input = xfloat8in, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_100.snap index 09450bf1a..4a48273e8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_100.snap @@ -83,7 +83,7 @@ create foreign data wrapper foo validator postgresql_fdw_validator ; create function invalid_fdw_handler() returns int language sql -as 'SELECT 1;'; +as $$SELECT 1;$$; create foreign data wrapper test_fdw handler invalid_fdw_handler ; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_80.snap index b2cec8329..e5fcacdd8 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__foreign_data_80.snap @@ -83,7 +83,7 @@ create foreign data wrapper foo validator postgresql_fdw_validator ; create function invalid_fdw_handler() returns int language sql -as 'SELECT 1;'; +as $$SELECT 1;$$; create foreign data wrapper test_fdw handler invalid_fdw_handler ; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap index 0016dcc4a..584f30ef2 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_100.snap @@ -72,11 +72,11 @@ create temporary table gstest_empty ( create function gstest_data(v int, out a int, out b int) returns setof record language plpgsql -as $f$ +as $$ begin return query select v, i from generate_series(1,3) i; end; - $f$; + $$; set enable_hashagg = 'false'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap index f1b84154d..aaa801af7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__groupingsets_80.snap @@ -72,11 +72,11 @@ create temporary table gstest_empty ( create function gstest_data(v int, out a int, out b int) returns setof record language plpgsql -as $f$ +as $$ begin return query select v, i from generate_series(1,3) i; end; - $f$; + $$; set enable_hashagg = 'false'; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_100.snap index 877331f8a..b11a1532f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_100.snap @@ -6,7 +6,7 @@ create function make_tuple_indirect(record) returns record language c strict -as 'regresslib'; +as $$regresslib$$; set default_toast_compression = pglz; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_80.snap index 483be6768..df7a6737f 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__indirect_toast_80.snap @@ -6,7 +6,7 @@ create function make_tuple_indirect(record) returns record language c strict -as 'regresslib'; +as $$regresslib$$; set default_toast_compression = pglz; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_100.snap index 645f946c4..2f47b3bc5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_100.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/infinite_recurse.sql create function infinite_recurse() returns int language sql -as 'select infinite_recurse()'; +as $$select infinite_recurse()$$; select version() ~ 'powerpc64[^,]*-linux-gnu' as skip_test; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_80.snap index 645f946c4..2f47b3bc5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__infinite_recurse_80.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/infinite_recurse.sql create function infinite_recurse() returns int language sql -as 'select infinite_recurse()'; +as $$select infinite_recurse()$$; select version() ~ 'powerpc64[^,]*-linux-gnu' as skip_test; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_100.snap index e10dd07cf..8d316762e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_100.snap @@ -485,7 +485,7 @@ create table p2 (f1 text); create function p2text(p2) returns text language sql -as 'select $1.f1'; +as $$select $1.f1$$; create table c1 (f3 int) inherits (p1, p2); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_80.snap index 30ed05a5e..ca57fc887 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__inherit_80.snap @@ -508,7 +508,7 @@ create table p2 (f1 text); create function p2text(p2) returns text language sql -as 'select $1.f1'; +as $$select $1.f1$$; create table c1 (f3 int) inherits (p1, p2); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_100.snap index 318dd634b..a6b48a27e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_100.snap @@ -95,7 +95,7 @@ select lo_open(loid, cast(X'40000' as int)) from lotest_stash_values; rollback; -do 'dobody'; +do $$dobody$$; begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_80.snap index 15170640d..d7218fc79 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__largeobject_80.snap @@ -97,7 +97,7 @@ select lo_open(loid, cast(X'40000' as int)) from lotest_stash_values; rollback; -do 'dobody'; +do $$dobody$$; begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_100.snap index 23eb4c964..97785d132 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_100.snap @@ -331,6 +331,6 @@ reset search_path; create function test_atomic_ops() returns bool language c -as 'regresslib'; +as $$regresslib$$; select test_atomic_ops(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_80.snap index 23eb4c964..97785d132 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__lock_80.snap @@ -331,6 +331,6 @@ reset search_path; create function test_atomic_ops() returns bool language c -as 'regresslib'; +as $$regresslib$$; select test_atomic_ops(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_100.snap index c6272bdbf..8508641cf 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_100.snap @@ -6,13 +6,13 @@ create function overpaid(emp) returns bool language c strict -as 'regresslib'; +as $$regresslib$$; create function reverse_name(name) returns name language c strict -as 'regresslib'; +as $$regresslib$$; update onek set unique1 = onek.unique1 + 1; @@ -81,57 +81,57 @@ insert into equipment_r (name, hobby) values ('guts', 'skywalking'); create function hobbies(person) returns setof hobbies_r language sql -as 'select * from hobbies_r where person = $1.name'; +as $$select * from hobbies_r where person = $1.name$$; create function hobby_construct(text, text) returns hobbies_r language sql -as 'select $1 as name, $2 as hobby'; +as $$select $1 as name, $2 as hobby$$; create function hobby_construct_named(name text, hobby text) returns hobbies_r language sql -as 'select name, hobby'; +as $$select name, hobby$$; create function hobbies_by_name(hobbies_r.name%type) returns hobbies_r.person%type language sql -as 'select person from hobbies_r where name = $1'; +as $$select person from hobbies_r where name = $1$$; create function equipment(hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where hobby = $1.name'; +as $$select * from equipment_r where hobby = $1.name$$; create function equipment_named(hobby hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where equipment_r.hobby = equipment_named.hobby.name'; +as $$select * from equipment_r where equipment_r.hobby = equipment_named.hobby.name$$; create function equipment_named_ambiguous_1a(hobby hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where hobby = equipment_named_ambiguous_1a.hobby.name'; +as $$select * from equipment_r where hobby = equipment_named_ambiguous_1a.hobby.name$$; create function equipment_named_ambiguous_1b(hobby hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where equipment_r.hobby = hobby.name'; +as $$select * from equipment_r where equipment_r.hobby = hobby.name$$; create function equipment_named_ambiguous_1c(hobby hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where hobby = hobby.name'; +as $$select * from equipment_r where hobby = hobby.name$$; create function equipment_named_ambiguous_2a(hobby text) returns setof equipment_r language sql -as 'select * from equipment_r where hobby = equipment_named_ambiguous_2a.hobby'; +as $$select * from equipment_r where hobby = equipment_named_ambiguous_2a.hobby$$; create function equipment_named_ambiguous_2b(hobby text) returns setof equipment_r language sql -as 'select * from equipment_r where equipment_r.hobby = hobby'; +as $$select * from equipment_r where equipment_r.hobby = hobby$$; select p.name, name(p.hobbies) from only person as p; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_80.snap index 17aac5a0a..7fbc7619a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_80.snap @@ -6,13 +6,13 @@ create function overpaid(emp) returns bool language c strict -as 'regresslib'; +as $$regresslib$$; create function reverse_name(name) returns name language c strict -as 'regresslib'; +as $$regresslib$$; update onek set unique1 = onek.unique1 + 1; @@ -93,57 +93,57 @@ insert into equipment_r (name, hobby) values ('guts', 'skywalking'); create function hobbies(person) returns setof hobbies_r language sql -as 'select * from hobbies_r where person = $1.name'; +as $$select * from hobbies_r where person = $1.name$$; create function hobby_construct(text, text) returns hobbies_r language sql -as 'select $1 as name, $2 as hobby'; +as $$select $1 as name, $2 as hobby$$; create function hobby_construct_named(name text, hobby text) returns hobbies_r language sql -as 'select name, hobby'; +as $$select name, hobby$$; create function hobbies_by_name(hobbies_r.name%type) returns hobbies_r.person%type language sql -as 'select person from hobbies_r where name = $1'; +as $$select person from hobbies_r where name = $1$$; create function equipment(hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where hobby = $1.name'; +as $$select * from equipment_r where hobby = $1.name$$; create function equipment_named(hobby hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where equipment_r.hobby = equipment_named.hobby.name'; +as $$select * from equipment_r where equipment_r.hobby = equipment_named.hobby.name$$; create function equipment_named_ambiguous_1a(hobby hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where hobby = equipment_named_ambiguous_1a.hobby.name'; +as $$select * from equipment_r where hobby = equipment_named_ambiguous_1a.hobby.name$$; create function equipment_named_ambiguous_1b(hobby hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where equipment_r.hobby = hobby.name'; +as $$select * from equipment_r where equipment_r.hobby = hobby.name$$; create function equipment_named_ambiguous_1c(hobby hobbies_r) returns setof equipment_r language sql -as 'select * from equipment_r where hobby = hobby.name'; +as $$select * from equipment_r where hobby = hobby.name$$; create function equipment_named_ambiguous_2a(hobby text) returns setof equipment_r language sql -as 'select * from equipment_r where hobby = equipment_named_ambiguous_2a.hobby'; +as $$select * from equipment_r where hobby = equipment_named_ambiguous_2a.hobby$$; create function equipment_named_ambiguous_2b(hobby text) returns setof equipment_r language sql -as 'select * from equipment_r where equipment_r.hobby = hobby'; +as $$select * from equipment_r where equipment_r.hobby = hobby$$; select p.name, name(p.hobbies) from only person as p; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_100.snap index 3ba9648ae..90a0db345 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_100.snap @@ -102,7 +102,7 @@ returns text language c immutable strict -as 'regresslib'; +as $$regresslib$$; select test_canonicalize_path('/'); @@ -451,7 +451,7 @@ select gist_translate_cmptype_common(3); create function test_relpath() returns void language c -as 'regresslib'; +as $$regresslib$$; select test_relpath(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_80.snap index 823d003f5..39c363e22 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__misc_functions_80.snap @@ -125,7 +125,7 @@ returns text language c immutable strict -as 'regresslib'; +as $$regresslib$$; select test_canonicalize_path('/'); @@ -547,7 +547,7 @@ select gist_translate_cmptype_common(3); create function test_relpath() returns void language c -as 'regresslib'; +as $$regresslib$$; select test_relpath(); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_100.snap index 9c5dc4cb5..e2e3bda3d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_100.snap @@ -1304,7 +1304,7 @@ drop role regress_multirange_owner; create function anyarray_anymultirange_func(a anyarray, r anymultirange) returns anyelement language sql -as 'select $1[1] + lower($2);'; +as $$select $1[1] + lower($2);$$; select anyarray_anymultirange_func(array[1, 2], int4multirange(int4range(10, 20))); @@ -1315,17 +1315,17 @@ drop function anyarray_anymultirange_func(anyarray, anymultirange); create function bogus_func(anyelement) returns anymultirange language sql -as 'select int4multirange(int4range(1,10))'; +as $$select int4multirange(int4range(1,10))$$; create function bogus_func(int) returns anymultirange language sql -as 'select int4multirange(int4range(1,10))'; +as $$select int4multirange(int4range(1,10))$$; create function range_add_bounds(anymultirange) returns anyelement language sql -as 'select lower($1) + upper($1)'; +as $$select lower($1) + upper($1)$$; select range_add_bounds(int4multirange(int4range(1, 17))); @@ -1346,7 +1346,7 @@ anycompatiblearray_anycompatiblemultirange_func( ) returns anycompatible language sql -as 'select $1[1] + lower($2);'; +as $$select $1[1] + lower($2);$$; select anycompatiblearray_anycompatiblemultirange_func(array[1, 2], multirange(int4range(10, 20))); @@ -1365,7 +1365,7 @@ anycompatiblerange_anycompatiblemultirange_func( ) returns anycompatible language sql -as 'select lower($1) + lower($2);'; +as $$select lower($1) + lower($2);$$; select anycompatiblerange_anycompatiblemultirange_func(int4range(1, 2), multirange(int4range(10, 20))); @@ -1379,7 +1379,7 @@ drop function create function bogus_func(anycompatible) returns anycompatiblerange language sql -as 'select int4range(1,10)'; +as $$select int4range(1,10)$$; select array[nummultirange(numrange(1.1, 1.2)), nummultirange(numrange(12.3, 155.5))]; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_80.snap index f5958c363..c88898c0a 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__multirangetypes_80.snap @@ -1665,7 +1665,7 @@ drop role regress_multirange_owner; create function anyarray_anymultirange_func(a anyarray, r anymultirange) returns anyelement language sql -as 'select $1[1] + lower($2);'; +as $$select $1[1] + lower($2);$$; select anyarray_anymultirange_func(array[1, 2], int4multirange(int4range(10, 20))); @@ -1678,17 +1678,17 @@ drop function anyarray_anymultirange_func(anyarray, anymultirange); create function bogus_func(anyelement) returns anymultirange language sql -as 'select int4multirange(int4range(1,10))'; +as $$select int4multirange(int4range(1,10))$$; create function bogus_func(int) returns anymultirange language sql -as 'select int4multirange(int4range(1,10))'; +as $$select int4multirange(int4range(1,10))$$; create function range_add_bounds(anymultirange) returns anyelement language sql -as 'select lower($1) + upper($1)'; +as $$select lower($1) + upper($1)$$; select range_add_bounds(int4multirange(int4range(1, 17))); @@ -1714,7 +1714,7 @@ anycompatiblearray_anycompatiblemultirange_func( ) returns anycompatible language sql -as 'select $1[1] + lower($2);'; +as $$select $1[1] + lower($2);$$; select anycompatiblearray_anycompatiblemultirange_func( @@ -1746,7 +1746,7 @@ anycompatiblerange_anycompatiblemultirange_func( ) returns anycompatible language sql -as 'select lower($1) + lower($2);'; +as $$select lower($1) + lower($2);$$; select anycompatiblerange_anycompatiblemultirange_func( @@ -1768,7 +1768,7 @@ drop function create function bogus_func(anycompatible) returns anycompatiblerange language sql -as 'select int4range(1,10)'; +as $$select int4range(1,10)$$; select array[nummultirange(numrange(1.1, 1.2)), diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_100.snap index 3d80ace4b..71af281e7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_100.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/oidjoins.sql snapshot_kind: text --- -do $doblock$ +do $$ declare fk record; nkeys integer; @@ -48,4 +48,4 @@ begin end loop; end loop; end -$doblock$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_80.snap index 3d80ace4b..71af281e7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__oidjoins_80.snap @@ -3,7 +3,7 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/multi/oidjoins.sql snapshot_kind: text --- -do $doblock$ +do $$ declare fk record; nkeys integer; @@ -48,4 +48,4 @@ begin end loop; end loop; end -$doblock$; +$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_100.snap index 62f09effb..a709aff65 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_100.snap @@ -89,26 +89,26 @@ create unique index phone_name on phone using btree (slotname bpchar_ops); create function tg_room_au() returns trigger language plpgsql -as ' +as $$ begin if new.roomno != old.roomno then update WSlot set roomno = new.roomno where roomno = old.roomno; end if; return new; end; -'; +$$; create trigger tg_room_au after update on room for each row execute function tg_room_au(); create function tg_room_ad() returns trigger language plpgsql -as ' +as $$ begin delete from WSlot where roomno = old.roomno; return old; end; -'; +$$; create trigger tg_room_ad after delete on room for each row execute function tg_room_ad(); @@ -133,33 +133,33 @@ execute function tg_wslot_biu(); create function tg_pfield_au() returns trigger language plpgsql -as ' +as $$ begin if new.name != old.name then update PSlot set pfname = new.name where pfname = old.name; end if; return new; end; -'; +$$; create trigger tg_pfield_au after update on pfield for each row execute function tg_pfield_au(); create function tg_pfield_ad() returns trigger language plpgsql -as ' +as $$ begin delete from PSlot where pfname = old.name; return old; end; -'; +$$; create trigger tg_pfield_ad after delete on pfield for each row execute function tg_pfield_ad(); create function tg_pslot_biu() returns trigger language plpgsql -as $proc$ +as $body$ declare pfrec record; ps alias for new; @@ -170,7 +170,7 @@ begin end if; return ps; end; -$proc$; +$body$; create trigger tg_pslot_biu before insert or update @@ -181,14 +181,14 @@ execute function tg_pslot_biu(); create function tg_system_au() returns trigger language plpgsql -as ' +as $$ begin if new.name != old.name then update IFace set sysname = new.name where sysname = old.name; end if; return new; end; -'; +$$; create trigger tg_system_au after update on system for each row execute function tg_system_au(); @@ -224,28 +224,28 @@ execute function tg_iface_biu(); create function tg_hub_a() returns trigger language plpgsql -as ' +as $$ declare hname text; dummy integer; begin - if tg_op = ''INSERT'' then + if tg_op = 'INSERT' then dummy := tg_hub_adjustslots(new.name, 0, new.nslots); return new; end if; - if tg_op = ''UPDATE'' then + if tg_op = 'UPDATE' then if new.name != old.name then update HSlot set hubname = new.name where hubname = old.name; end if; dummy := tg_hub_adjustslots(new.name, old.nslots, new.nslots); return new; end if; - if tg_op = ''DELETE'' then + if tg_op = 'DELETE' then dummy := tg_hub_adjustslots(old.name, old.nslots, 0); return old; end if; end; -'; +$$; create trigger tg_hub_a after insert or delete or update @@ -256,7 +256,7 @@ execute function tg_hub_a(); create function tg_hub_adjustslots(hname bpchar, oldnslots int, newnslots int) returns int language plpgsql -as ' +as $$ begin if newnslots = oldnslots then return 0; @@ -267,11 +267,11 @@ begin end if; for i in oldnslots + 1 .. newnslots loop insert into HSlot (slotname, hubname, slotno, slotlink) - values (''HS.dummy'', hname, i, ''''); + values ('HS.dummy', hname, i, ''); end loop; return 0; end -'; +$$; comment on function tg_hub_adjustslots_wrong(bpchar, int, int) is 'function with args'; @@ -282,7 +282,7 @@ comment on function tg_hub_adjustslots(bpchar, int, int) is null; create function tg_hslot_biu() returns trigger language plpgsql -as ' +as $$ declare sname text; xname HSlot.slotname%TYPE; @@ -290,26 +290,26 @@ declare begin select into hubrec * from Hub where name = new.hubname; if not found then - raise exception ''no manual manipulation of HSlot''; + raise exception 'no manual manipulation of HSlot'; end if; if new.slotno < 1 or new.slotno > hubrec.nslots then - raise exception ''no manual manipulation of HSlot''; + raise exception 'no manual manipulation of HSlot'; end if; - if tg_op = ''UPDATE'' and new.hubname != old.hubname then + if tg_op = 'UPDATE' and new.hubname != old.hubname then if count(*) > 0 from Hub where name = old.hubname then - raise exception ''no manual manipulation of HSlot''; + raise exception 'no manual manipulation of HSlot'; end if; end if; - sname := ''HS.'' || trim(new.hubname); - sname := sname || ''.''; + sname := 'HS.' || trim(new.hubname); + sname := sname || '.'; sname := sname || new.slotno::text; if length(sname) > 20 then - raise exception ''HSlot slotname "%" too long (20 char max)'', sname; + raise exception 'HSlot slotname "%" too long (20 char max)', sname; end if; new.slotname := sname; return new; end; -'; +$$; create trigger tg_hslot_biu before insert or update @@ -320,7 +320,7 @@ execute function tg_hslot_biu(); create function tg_hslot_bd() returns trigger language plpgsql -as ' +as $$ declare hubrec record; begin @@ -331,23 +331,23 @@ begin if old.slotno > hubrec.nslots then return old; end if; - raise exception ''no manual manipulation of HSlot''; + raise exception 'no manual manipulation of HSlot'; end; -'; +$$; create trigger tg_hslot_bd before delete on hslot for each row execute function tg_hslot_bd(); create function tg_chkslotname() returns trigger language plpgsql -as ' +as $$ begin if substr(new.slotname, 1, 2) != tg_argv[0] then - raise exception ''slotname must begin with %'', tg_argv[0]; + raise exception 'slotname must begin with %', tg_argv[0]; end if; return new; end; -'; +$$; create trigger tg_chkslotname before insert @@ -382,14 +382,14 @@ execute function tg_chkslotname("PH"); create function tg_chkslotlink() returns trigger language plpgsql -as ' +as $$ begin if new.slotlink isnull then - new.slotlink := ''''; + new.slotlink := ''; end if; return new; end; -'; +$$; create trigger tg_chkslotlink before insert or update @@ -424,14 +424,14 @@ execute function tg_chkslotlink(); create function tg_chkbacklink() returns trigger language plpgsql -as ' +as $$ begin if new.backlink isnull then - new.backlink := ''''; + new.backlink := ''; end if; return new; end; -'; +$$; create trigger tg_chkbacklink before insert or update @@ -454,7 +454,7 @@ execute function tg_chkbacklink(); create function tg_pslot_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from PSlot where slotname = old.slotname; @@ -473,14 +473,14 @@ begin end if; return new; end; -'; +$$; create trigger tg_pslot_bu before update on pslot for each row execute function tg_pslot_bu(); create function tg_wslot_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from WSlot where slotname = old.slotname; @@ -499,14 +499,14 @@ begin end if; return new; end; -'; +$$; create trigger tg_wslot_bu before update on wslot for each row execute function tg_wslot_bu(); create function tg_pline_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from PLine where slotname = old.slotname; @@ -525,14 +525,14 @@ begin end if; return new; end; -'; +$$; create trigger tg_pline_bu before update on pline for each row execute function tg_pline_bu(); create function tg_iface_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from IFace where slotname = old.slotname; @@ -551,14 +551,14 @@ begin end if; return new; end; -'; +$$; create trigger tg_iface_bu before update on iface for each row execute function tg_iface_bu(); create function tg_hslot_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname or new.hubname != old.hubname then delete from HSlot where slotname = old.slotname; @@ -577,14 +577,14 @@ begin end if; return new; end; -'; +$$; create trigger tg_hslot_bu before update on hslot for each row execute function tg_hslot_bu(); create function tg_phone_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from PHone where slotname = old.slotname; @@ -601,46 +601,46 @@ begin end if; return new; end; -'; +$$; create trigger tg_phone_bu before update on phone for each row execute function tg_phone_bu(); create function tg_backlink_a() returns trigger language plpgsql -as ' +as $$ declare dummy integer; begin - if tg_op = ''INSERT'' then - if new.backlink != '''' then + if tg_op = 'INSERT' then + if new.backlink != '' then dummy := tg_backlink_set(new.backlink, new.slotname); end if; return new; end if; - if tg_op = ''UPDATE'' then + if tg_op = 'UPDATE' then if new.backlink != old.backlink then - if old.backlink != '''' then + if old.backlink != '' then dummy := tg_backlink_unset(old.backlink, old.slotname); end if; - if new.backlink != '''' then + if new.backlink != '' then dummy := tg_backlink_set(new.backlink, new.slotname); end if; else - if new.slotname != old.slotname and new.backlink != '''' then + if new.slotname != old.slotname and new.backlink != '' then dummy := tg_slotlink_set(new.backlink, new.slotname); end if; end if; return new; end if; - if tg_op = ''DELETE'' then - if old.backlink != '''' then + if tg_op = 'DELETE' then + if old.backlink != '' then dummy := tg_backlink_unset(old.backlink, old.slotname); end if; return old; end if; end; -'; +$$; create trigger tg_backlink_a after insert or delete or update @@ -663,7 +663,7 @@ execute function tg_backlink_a("PL"); create function tg_backlink_set(myname bpchar, blname bpchar) returns int language plpgsql -as ' +as $$ declare mytype char(2); link char(4); @@ -671,52 +671,52 @@ declare begin mytype := substr(myname, 1, 2); link := mytype || substr(blname, 1, 2); - if link = ''PLPL'' then + if link = 'PLPL' then raise exception - ''backlink between two phone lines does not make sense''; + 'backlink between two phone lines does not make sense'; end if; - if link in (''PLWS'', ''WSPL'') then + if link in ('PLWS', 'WSPL') then raise exception - ''direct link of phone line to wall slot not permitted''; + 'direct link of phone line to wall slot not permitted'; end if; - if mytype = ''PS'' then + if mytype = 'PS' then select into rec * from PSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.backlink != blname then update PSlot set backlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''WS'' then + if mytype = 'WS' then select into rec * from WSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.backlink != blname then update WSlot set backlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''PL'' then + if mytype = 'PL' then select into rec * from PLine where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.backlink != blname then update PLine set backlink = blname where slotname = myname; end if; return 0; end if; - raise exception ''illegal backlink beginning with %'', mytype; + raise exception 'illegal backlink beginning with %', mytype; end; -'; +$$; create function tg_backlink_unset(bpchar, bpchar) returns int language plpgsql -as ' +as $$ declare myname alias for $1; blname alias for $2; @@ -724,75 +724,75 @@ declare rec record; begin mytype := substr(myname, 1, 2); - if mytype = ''PS'' then + if mytype = 'PS' then select into rec * from PSlot where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update PSlot set backlink = '''' where slotname = myname; + update PSlot set backlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''WS'' then + if mytype = 'WS' then select into rec * from WSlot where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update WSlot set backlink = '''' where slotname = myname; + update WSlot set backlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''PL'' then + if mytype = 'PL' then select into rec * from PLine where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update PLine set backlink = '''' where slotname = myname; + update PLine set backlink = '' where slotname = myname; end if; return 0; end if; end -'; +$$; create function tg_slotlink_a() returns trigger language plpgsql -as ' +as $$ declare dummy integer; begin - if tg_op = ''INSERT'' then - if new.slotlink != '''' then + if tg_op = 'INSERT' then + if new.slotlink != '' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; return new; end if; - if tg_op = ''UPDATE'' then + if tg_op = 'UPDATE' then if new.slotlink != old.slotlink then - if old.slotlink != '''' then + if old.slotlink != '' then dummy := tg_slotlink_unset(old.slotlink, old.slotname); end if; - if new.slotlink != '''' then + if new.slotlink != '' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; else - if new.slotname != old.slotname and new.slotlink != '''' then + if new.slotname != old.slotname and new.slotlink != '' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; end if; return new; end if; - if tg_op = ''DELETE'' then - if old.slotlink != '''' then + if tg_op = 'DELETE' then + if old.slotlink != '' then dummy := tg_slotlink_unset(old.slotlink, old.slotname); end if; return old; end if; end; -'; +$$; create trigger tg_slotlink_a after insert or delete or update @@ -827,7 +827,7 @@ execute function tg_slotlink_a("PH"); create function tg_slotlink_set(bpchar, bpchar) returns int language plpgsql -as ' +as $$ declare myname alias for $1; blname alias for $2; @@ -837,80 +837,80 @@ declare begin mytype := substr(myname, 1, 2); link := mytype || substr(blname, 1, 2); - if link = ''PHPH'' then + if link = 'PHPH' then raise exception - ''slotlink between two phones does not make sense''; + 'slotlink between two phones does not make sense'; end if; - if link in (''PHHS'', ''HSPH'') then + if link in ('PHHS', 'HSPH') then raise exception - ''link of phone to hub does not make sense''; + 'link of phone to hub does not make sense'; end if; - if link in (''PHIF'', ''IFPH'') then + if link in ('PHIF', 'IFPH') then raise exception - ''link of phone to hub does not make sense''; + 'link of phone to hub does not make sense'; end if; - if link in (''PSWS'', ''WSPS'') then + if link in ('PSWS', 'WSPS') then raise exception - ''slotlink from patchslot to wallslot not permitted''; + 'slotlink from patchslot to wallslot not permitted'; end if; - if mytype = ''PS'' then + if mytype = 'PS' then select into rec * from PSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update PSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''WS'' then + if mytype = 'WS' then select into rec * from WSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update WSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''IF'' then + if mytype = 'IF' then select into rec * from IFace where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update IFace set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''HS'' then + if mytype = 'HS' then select into rec * from HSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update HSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''PH'' then + if mytype = 'PH' then select into rec * from PHone where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update PHone set slotlink = blname where slotname = myname; end if; return 0; end if; - raise exception ''illegal slotlink beginning with %'', mytype; + raise exception 'illegal slotlink beginning with %', mytype; end; -'; +$$; create function tg_slotlink_unset(bpchar, bpchar) returns int language plpgsql -as ' +as $$ declare myname alias for $1; blname alias for $2; @@ -918,63 +918,63 @@ declare rec record; begin mytype := substr(myname, 1, 2); - if mytype = ''PS'' then + if mytype = 'PS' then select into rec * from PSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update PSlot set slotlink = '''' where slotname = myname; + update PSlot set slotlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''WS'' then + if mytype = 'WS' then select into rec * from WSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update WSlot set slotlink = '''' where slotname = myname; + update WSlot set slotlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''IF'' then + if mytype = 'IF' then select into rec * from IFace where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update IFace set slotlink = '''' where slotname = myname; + update IFace set slotlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''HS'' then + if mytype = 'HS' then select into rec * from HSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update HSlot set slotlink = '''' where slotname = myname; + update HSlot set slotlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''PH'' then + if mytype = 'PH' then select into rec * from PHone where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update PHone set slotlink = '''' where slotname = myname; + update PHone set slotlink = '' where slotname = myname; end if; return 0; end if; end; -'; +$$; create function pslot_backlink_view(bpchar) returns text language plpgsql -as ' +as $$ <> declare rec record; @@ -983,41 +983,41 @@ declare begin select into rec * from PSlot where slotname = $1; if not found then - return ''''; + return ''; end if; - if rec.backlink = '''' then - return ''-''; + if rec.backlink = '' then + return '-'; end if; bltype := substr(rec.backlink, 1, 2); - if bltype = ''PL'' then + if bltype = 'PL' then declare rec record; begin select into rec * from PLine where slotname = "outer".rec.backlink; - retval := ''Phone line '' || trim(rec.phonenumber); - if rec.comment != '''' then - retval := retval || '' (''; + retval := 'Phone line ' || trim(rec.phonenumber); + if rec.comment != '' then + retval := retval || ' ('; retval := retval || rec.comment; - retval := retval || '')''; + retval := retval || ')'; end if; return retval; end; end if; - if bltype = ''WS'' then + if bltype = 'WS' then select into rec * from WSlot where slotname = rec.backlink; - retval := trim(rec.slotname) || '' in room ''; + retval := trim(rec.slotname) || ' in room '; retval := retval || trim(rec.roomno); - retval := retval || '' -> ''; + retval := retval || ' -> '; return retval || wslot_slotlink_view(rec.slotname); end if; return rec.backlink; end; -'; +$$; create function pslot_slotlink_view(bpchar) returns text language plpgsql -as ' +as $$ declare psrec record; sltype char(2); @@ -1025,33 +1025,33 @@ declare begin select into psrec * from PSlot where slotname = $1; if not found then - return ''''; + return ''; end if; - if psrec.slotlink = '''' then - return ''-''; + if psrec.slotlink = '' then + return '-'; end if; sltype := substr(psrec.slotlink, 1, 2); - if sltype = ''PS'' then - retval := trim(psrec.slotlink) || '' -> ''; + if sltype = 'PS' then + retval := trim(psrec.slotlink) || ' -> '; return retval || pslot_backlink_view(psrec.slotlink); end if; - if sltype = ''HS'' then + if sltype = 'HS' then retval := comment from Hub H, HSlot HS where HS.slotname = psrec.slotlink and H.name = HS.hubname; - retval := retval || '' slot ''; + retval := retval || ' slot '; retval := retval || slotno::text from HSlot where slotname = psrec.slotlink; return retval; end if; return psrec.slotlink; end; -'; +$$; create function wslot_slotlink_view(bpchar) returns text language plpgsql -as ' +as $$ declare rec record; sltype char(2); @@ -1059,42 +1059,42 @@ declare begin select into rec * from WSlot where slotname = $1; if not found then - return ''''; + return ''; end if; - if rec.slotlink = '''' then - return ''-''; + if rec.slotlink = '' then + return '-'; end if; sltype := substr(rec.slotlink, 1, 2); - if sltype = ''PH'' then + if sltype = 'PH' then select into rec * from PHone where slotname = rec.slotlink; - retval := ''Phone '' || trim(rec.slotname); - if rec.comment != '''' then - retval := retval || '' (''; + retval := 'Phone ' || trim(rec.slotname); + if rec.comment != '' then + retval := retval || ' ('; retval := retval || rec.comment; - retval := retval || '')''; + retval := retval || ')'; end if; return retval; end if; - if sltype = ''IF'' then + if sltype = 'IF' then declare syrow System%RowType; ifrow IFace%ROWTYPE; begin select into ifrow * from IFace where slotname = rec.slotlink; select into syrow * from System where name = ifrow.sysname; - retval := syrow.name || '' IF ''; + retval := syrow.name || ' IF '; retval := retval || ifrow.ifname; - if syrow.comment != '''' then - retval := retval || '' (''; + if syrow.comment != '' then + retval := retval || ' ('; retval := retval || syrow.comment; - retval := retval || '')''; + retval := retval || ')'; end if; return retval; end; end if; return rec.slotlink; end; -'; +$$; create view pfield_v1 as select @@ -1486,16 +1486,16 @@ insert into iface values ('IF', 'orion', 'ethernet_interface_name_too_long', '') create function recursion_test(int, int) returns text language plpgsql -as ' +as $$ DECLARE rslt text; BEGIN IF $1 <= 0 THEN rslt = CAST($2 AS TEXT); ELSE - rslt = CAST($1 AS TEXT) || '','' || recursion_test($1 - 1, $2); + rslt = CAST($1 AS TEXT) || ',' || recursion_test($1 - 1, $2); END IF; RETURN rslt; -END;'; +END;$$; select recursion_test(4, 3); @@ -1504,7 +1504,7 @@ create table found_test_tbl (a int); create function test_found() returns boolean language plpgsql -as ' +as $$ declare begin insert into found_test_tbl values (1); @@ -1537,7 +1537,7 @@ as ' insert into found_test_tbl values (6); end if; return true; - end;'; + end;$$; select test_found(); @@ -1546,7 +1546,7 @@ select * from found_test_tbl; create function test_table_func_rec() returns setof found_test_tbl language plpgsql -as ' +as $$ DECLARE rec RECORD; BEGIN @@ -1554,14 +1554,14 @@ BEGIN RETURN NEXT rec; END LOOP; RETURN; -END;'; +END;$$; select * from test_table_func_rec(); create function test_table_func_row() returns setof found_test_tbl language plpgsql -as ' +as $$ DECLARE row found_test_tbl%ROWTYPE; BEGIN @@ -1569,14 +1569,14 @@ BEGIN RETURN NEXT row; END LOOP; RETURN; -END;'; +END;$$; select * from test_table_func_row(); create function test_ret_set_scalar(int, int) returns setof int language plpgsql -as ' +as $$ DECLARE i int; BEGIN @@ -1584,14 +1584,14 @@ BEGIN RETURN NEXT i + 1; END LOOP; RETURN; -END;'; +END;$$; select * from test_ret_set_scalar(1, 10); create function test_ret_set_rec_dyn(int) returns setof record language plpgsql -as ' +as $$ DECLARE retval RECORD; BEGIN @@ -1600,12 +1600,12 @@ BEGIN RETURN NEXT retval; RETURN NEXT retval; ELSE - SELECT INTO retval 50, 5::numeric, ''xxx''::text; + SELECT INTO retval 50, 5::numeric, 'xxx'::text; RETURN NEXT retval; RETURN NEXT retval; END IF; RETURN; -END;'; +END;$$; select * from test_ret_set_rec_dyn(1500) as (a int, b int, c int); @@ -1614,7 +1614,7 @@ select * from test_ret_set_rec_dyn(5) as (a int, b numeric, c text); create function test_ret_rec_dyn(int) returns record language plpgsql -as ' +as $$ DECLARE retval RECORD; BEGIN @@ -1622,10 +1622,10 @@ BEGIN SELECT INTO retval 5, 10, 15; RETURN retval; ELSE - SELECT INTO retval 50, 5::numeric, ''xxx''::text; + SELECT INTO retval 50, 5::numeric, 'xxx'::text; RETURN retval; END IF; -END;'; +END;$$; select * from test_ret_rec_dyn(1500) as (a int, b int, c int); @@ -1898,7 +1898,7 @@ create table perform_test ( create function perform_simple_func(int) returns boolean language plpgsql -as ' +as $$ BEGIN IF $1 < 20 THEN INSERT INTO perform_test VALUES ($1, $1 + 10); @@ -1906,12 +1906,12 @@ BEGIN ELSE RETURN FALSE; END IF; -END;'; +END;$$; create function perform_test_func() returns void language plpgsql -as ' +as $$ BEGIN IF FOUND then INSERT INTO perform_test VALUES (100, 100); @@ -1930,7 +1930,7 @@ BEGIN END IF; RETURN; -END;'; +END;$$; select perform_test_func(); @@ -4302,7 +4302,7 @@ BEGIN END LOOP; END$$; -do $outer$ +do $body$ begin for i in 1..10 loop begin @@ -4319,7 +4319,7 @@ begin end; end loop; end; -$outer$; +$body$; do $$ declare x int := x + 1; -- error diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_80.snap index 59d769503..8cb86787c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__plpgsql_80.snap @@ -89,14 +89,14 @@ create unique index phone_name on phone using btree (slotname bpchar_ops); create function tg_room_au() returns trigger language plpgsql -as ' +as $$ begin if new.roomno != old.roomno then update WSlot set roomno = new.roomno where roomno = old.roomno; end if; return new; end; -'; +$$; create trigger tg_room_au after update @@ -107,12 +107,12 @@ execute function tg_room_au(); create function tg_room_ad() returns trigger language plpgsql -as ' +as $$ begin delete from WSlot where roomno = old.roomno; return old; end; -'; +$$; create trigger tg_room_ad after delete @@ -141,14 +141,14 @@ execute function tg_wslot_biu(); create function tg_pfield_au() returns trigger language plpgsql -as ' +as $$ begin if new.name != old.name then update PSlot set pfname = new.name where pfname = old.name; end if; return new; end; -'; +$$; create trigger tg_pfield_au after update @@ -159,12 +159,12 @@ execute function tg_pfield_au(); create function tg_pfield_ad() returns trigger language plpgsql -as ' +as $$ begin delete from PSlot where pfname = old.name; return old; end; -'; +$$; create trigger tg_pfield_ad after delete @@ -175,7 +175,7 @@ execute function tg_pfield_ad(); create function tg_pslot_biu() returns trigger language plpgsql -as $proc$ +as $body$ declare pfrec record; ps alias for new; @@ -186,7 +186,7 @@ begin end if; return ps; end; -$proc$; +$body$; create trigger tg_pslot_biu before insert or update @@ -197,14 +197,14 @@ execute function tg_pslot_biu(); create function tg_system_au() returns trigger language plpgsql -as ' +as $$ begin if new.name != old.name then update IFace set sysname = new.name where sysname = old.name; end if; return new; end; -'; +$$; create trigger tg_system_au after update @@ -244,28 +244,28 @@ execute function tg_iface_biu(); create function tg_hub_a() returns trigger language plpgsql -as ' +as $$ declare hname text; dummy integer; begin - if tg_op = ''INSERT'' then + if tg_op = 'INSERT' then dummy := tg_hub_adjustslots(new.name, 0, new.nslots); return new; end if; - if tg_op = ''UPDATE'' then + if tg_op = 'UPDATE' then if new.name != old.name then update HSlot set hubname = new.name where hubname = old.name; end if; dummy := tg_hub_adjustslots(new.name, old.nslots, new.nslots); return new; end if; - if tg_op = ''DELETE'' then + if tg_op = 'DELETE' then dummy := tg_hub_adjustslots(old.name, old.nslots, 0); return old; end if; end; -'; +$$; create trigger tg_hub_a after insert or delete or update @@ -276,7 +276,7 @@ execute function tg_hub_a(); create function tg_hub_adjustslots(hname bpchar, oldnslots int, newnslots int) returns int language plpgsql -as ' +as $$ begin if newnslots = oldnslots then return 0; @@ -287,11 +287,11 @@ begin end if; for i in oldnslots + 1 .. newnslots loop insert into HSlot (slotname, hubname, slotno, slotlink) - values (''HS.dummy'', hname, i, ''''); + values ('HS.dummy', hname, i, ''); end loop; return 0; end -'; +$$; comment on function tg_hub_adjustslots_wrong( bpchar, @@ -308,7 +308,7 @@ comment on function tg_hub_adjustslots(bpchar, int, int) is null; create function tg_hslot_biu() returns trigger language plpgsql -as ' +as $$ declare sname text; xname HSlot.slotname%TYPE; @@ -316,26 +316,26 @@ declare begin select into hubrec * from Hub where name = new.hubname; if not found then - raise exception ''no manual manipulation of HSlot''; + raise exception 'no manual manipulation of HSlot'; end if; if new.slotno < 1 or new.slotno > hubrec.nslots then - raise exception ''no manual manipulation of HSlot''; + raise exception 'no manual manipulation of HSlot'; end if; - if tg_op = ''UPDATE'' and new.hubname != old.hubname then + if tg_op = 'UPDATE' and new.hubname != old.hubname then if count(*) > 0 from Hub where name = old.hubname then - raise exception ''no manual manipulation of HSlot''; + raise exception 'no manual manipulation of HSlot'; end if; end if; - sname := ''HS.'' || trim(new.hubname); - sname := sname || ''.''; + sname := 'HS.' || trim(new.hubname); + sname := sname || '.'; sname := sname || new.slotno::text; if length(sname) > 20 then - raise exception ''HSlot slotname "%" too long (20 char max)'', sname; + raise exception 'HSlot slotname "%" too long (20 char max)', sname; end if; new.slotname := sname; return new; end; -'; +$$; create trigger tg_hslot_biu before insert or update @@ -346,7 +346,7 @@ execute function tg_hslot_biu(); create function tg_hslot_bd() returns trigger language plpgsql -as ' +as $$ declare hubrec record; begin @@ -357,9 +357,9 @@ begin if old.slotno > hubrec.nslots then return old; end if; - raise exception ''no manual manipulation of HSlot''; + raise exception 'no manual manipulation of HSlot'; end; -'; +$$; create trigger tg_hslot_bd before delete @@ -370,14 +370,14 @@ execute function tg_hslot_bd(); create function tg_chkslotname() returns trigger language plpgsql -as ' +as $$ begin if substr(new.slotname, 1, 2) != tg_argv[0] then - raise exception ''slotname must begin with %'', tg_argv[0]; + raise exception 'slotname must begin with %', tg_argv[0]; end if; return new; end; -'; +$$; create trigger tg_chkslotname before insert @@ -412,14 +412,14 @@ execute function tg_chkslotname("PH"); create function tg_chkslotlink() returns trigger language plpgsql -as ' +as $$ begin if new.slotlink isnull then - new.slotlink := ''''; + new.slotlink := ''; end if; return new; end; -'; +$$; create trigger tg_chkslotlink before insert or update @@ -454,14 +454,14 @@ execute function tg_chkslotlink(); create function tg_chkbacklink() returns trigger language plpgsql -as ' +as $$ begin if new.backlink isnull then - new.backlink := ''''; + new.backlink := ''; end if; return new; end; -'; +$$; create trigger tg_chkbacklink before insert or update @@ -484,7 +484,7 @@ execute function tg_chkbacklink(); create function tg_pslot_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from PSlot where slotname = old.slotname; @@ -503,7 +503,7 @@ begin end if; return new; end; -'; +$$; create trigger tg_pslot_bu before update @@ -514,7 +514,7 @@ execute function tg_pslot_bu(); create function tg_wslot_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from WSlot where slotname = old.slotname; @@ -533,7 +533,7 @@ begin end if; return new; end; -'; +$$; create trigger tg_wslot_bu before update @@ -544,7 +544,7 @@ execute function tg_wslot_bu(); create function tg_pline_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from PLine where slotname = old.slotname; @@ -563,7 +563,7 @@ begin end if; return new; end; -'; +$$; create trigger tg_pline_bu before update @@ -574,7 +574,7 @@ execute function tg_pline_bu(); create function tg_iface_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from IFace where slotname = old.slotname; @@ -593,7 +593,7 @@ begin end if; return new; end; -'; +$$; create trigger tg_iface_bu before update @@ -604,7 +604,7 @@ execute function tg_iface_bu(); create function tg_hslot_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname or new.hubname != old.hubname then delete from HSlot where slotname = old.slotname; @@ -623,7 +623,7 @@ begin end if; return new; end; -'; +$$; create trigger tg_hslot_bu before update @@ -634,7 +634,7 @@ execute function tg_hslot_bu(); create function tg_phone_bu() returns trigger language plpgsql -as ' +as $$ begin if new.slotname != old.slotname then delete from PHone where slotname = old.slotname; @@ -651,7 +651,7 @@ begin end if; return new; end; -'; +$$; create trigger tg_phone_bu before update @@ -662,39 +662,39 @@ execute function tg_phone_bu(); create function tg_backlink_a() returns trigger language plpgsql -as ' +as $$ declare dummy integer; begin - if tg_op = ''INSERT'' then - if new.backlink != '''' then + if tg_op = 'INSERT' then + if new.backlink != '' then dummy := tg_backlink_set(new.backlink, new.slotname); end if; return new; end if; - if tg_op = ''UPDATE'' then + if tg_op = 'UPDATE' then if new.backlink != old.backlink then - if old.backlink != '''' then + if old.backlink != '' then dummy := tg_backlink_unset(old.backlink, old.slotname); end if; - if new.backlink != '''' then + if new.backlink != '' then dummy := tg_backlink_set(new.backlink, new.slotname); end if; else - if new.slotname != old.slotname and new.backlink != '''' then + if new.slotname != old.slotname and new.backlink != '' then dummy := tg_slotlink_set(new.backlink, new.slotname); end if; end if; return new; end if; - if tg_op = ''DELETE'' then - if old.backlink != '''' then + if tg_op = 'DELETE' then + if old.backlink != '' then dummy := tg_backlink_unset(old.backlink, old.slotname); end if; return old; end if; end; -'; +$$; create trigger tg_backlink_a after insert or delete or update @@ -717,7 +717,7 @@ execute function tg_backlink_a("PL"); create function tg_backlink_set(myname bpchar, blname bpchar) returns int language plpgsql -as ' +as $$ declare mytype char(2); link char(4); @@ -725,52 +725,52 @@ declare begin mytype := substr(myname, 1, 2); link := mytype || substr(blname, 1, 2); - if link = ''PLPL'' then + if link = 'PLPL' then raise exception - ''backlink between two phone lines does not make sense''; + 'backlink between two phone lines does not make sense'; end if; - if link in (''PLWS'', ''WSPL'') then + if link in ('PLWS', 'WSPL') then raise exception - ''direct link of phone line to wall slot not permitted''; + 'direct link of phone line to wall slot not permitted'; end if; - if mytype = ''PS'' then + if mytype = 'PS' then select into rec * from PSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.backlink != blname then update PSlot set backlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''WS'' then + if mytype = 'WS' then select into rec * from WSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.backlink != blname then update WSlot set backlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''PL'' then + if mytype = 'PL' then select into rec * from PLine where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.backlink != blname then update PLine set backlink = blname where slotname = myname; end if; return 0; end if; - raise exception ''illegal backlink beginning with %'', mytype; + raise exception 'illegal backlink beginning with %', mytype; end; -'; +$$; create function tg_backlink_unset(bpchar, bpchar) returns int language plpgsql -as ' +as $$ declare myname alias for $1; blname alias for $2; @@ -778,75 +778,75 @@ declare rec record; begin mytype := substr(myname, 1, 2); - if mytype = ''PS'' then + if mytype = 'PS' then select into rec * from PSlot where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update PSlot set backlink = '''' where slotname = myname; + update PSlot set backlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''WS'' then + if mytype = 'WS' then select into rec * from WSlot where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update WSlot set backlink = '''' where slotname = myname; + update WSlot set backlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''PL'' then + if mytype = 'PL' then select into rec * from PLine where slotname = myname; if not found then return 0; end if; if rec.backlink = blname then - update PLine set backlink = '''' where slotname = myname; + update PLine set backlink = '' where slotname = myname; end if; return 0; end if; end -'; +$$; create function tg_slotlink_a() returns trigger language plpgsql -as ' +as $$ declare dummy integer; begin - if tg_op = ''INSERT'' then - if new.slotlink != '''' then + if tg_op = 'INSERT' then + if new.slotlink != '' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; return new; end if; - if tg_op = ''UPDATE'' then + if tg_op = 'UPDATE' then if new.slotlink != old.slotlink then - if old.slotlink != '''' then + if old.slotlink != '' then dummy := tg_slotlink_unset(old.slotlink, old.slotname); end if; - if new.slotlink != '''' then + if new.slotlink != '' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; else - if new.slotname != old.slotname and new.slotlink != '''' then + if new.slotname != old.slotname and new.slotlink != '' then dummy := tg_slotlink_set(new.slotlink, new.slotname); end if; end if; return new; end if; - if tg_op = ''DELETE'' then - if old.slotlink != '''' then + if tg_op = 'DELETE' then + if old.slotlink != '' then dummy := tg_slotlink_unset(old.slotlink, old.slotname); end if; return old; end if; end; -'; +$$; create trigger tg_slotlink_a after insert or delete or update @@ -881,7 +881,7 @@ execute function tg_slotlink_a("PH"); create function tg_slotlink_set(bpchar, bpchar) returns int language plpgsql -as ' +as $$ declare myname alias for $1; blname alias for $2; @@ -891,80 +891,80 @@ declare begin mytype := substr(myname, 1, 2); link := mytype || substr(blname, 1, 2); - if link = ''PHPH'' then + if link = 'PHPH' then raise exception - ''slotlink between two phones does not make sense''; + 'slotlink between two phones does not make sense'; end if; - if link in (''PHHS'', ''HSPH'') then + if link in ('PHHS', 'HSPH') then raise exception - ''link of phone to hub does not make sense''; + 'link of phone to hub does not make sense'; end if; - if link in (''PHIF'', ''IFPH'') then + if link in ('PHIF', 'IFPH') then raise exception - ''link of phone to hub does not make sense''; + 'link of phone to hub does not make sense'; end if; - if link in (''PSWS'', ''WSPS'') then + if link in ('PSWS', 'WSPS') then raise exception - ''slotlink from patchslot to wallslot not permitted''; + 'slotlink from patchslot to wallslot not permitted'; end if; - if mytype = ''PS'' then + if mytype = 'PS' then select into rec * from PSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update PSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''WS'' then + if mytype = 'WS' then select into rec * from WSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update WSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''IF'' then + if mytype = 'IF' then select into rec * from IFace where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update IFace set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''HS'' then + if mytype = 'HS' then select into rec * from HSlot where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update HSlot set slotlink = blname where slotname = myname; end if; return 0; end if; - if mytype = ''PH'' then + if mytype = 'PH' then select into rec * from PHone where slotname = myname; if not found then - raise exception ''% does not exist'', myname; + raise exception '% does not exist', myname; end if; if rec.slotlink != blname then update PHone set slotlink = blname where slotname = myname; end if; return 0; end if; - raise exception ''illegal slotlink beginning with %'', mytype; + raise exception 'illegal slotlink beginning with %', mytype; end; -'; +$$; create function tg_slotlink_unset(bpchar, bpchar) returns int language plpgsql -as ' +as $$ declare myname alias for $1; blname alias for $2; @@ -972,63 +972,63 @@ declare rec record; begin mytype := substr(myname, 1, 2); - if mytype = ''PS'' then + if mytype = 'PS' then select into rec * from PSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update PSlot set slotlink = '''' where slotname = myname; + update PSlot set slotlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''WS'' then + if mytype = 'WS' then select into rec * from WSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update WSlot set slotlink = '''' where slotname = myname; + update WSlot set slotlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''IF'' then + if mytype = 'IF' then select into rec * from IFace where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update IFace set slotlink = '''' where slotname = myname; + update IFace set slotlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''HS'' then + if mytype = 'HS' then select into rec * from HSlot where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update HSlot set slotlink = '''' where slotname = myname; + update HSlot set slotlink = '' where slotname = myname; end if; return 0; end if; - if mytype = ''PH'' then + if mytype = 'PH' then select into rec * from PHone where slotname = myname; if not found then return 0; end if; if rec.slotlink = blname then - update PHone set slotlink = '''' where slotname = myname; + update PHone set slotlink = '' where slotname = myname; end if; return 0; end if; end; -'; +$$; create function pslot_backlink_view(bpchar) returns text language plpgsql -as ' +as $$ <> declare rec record; @@ -1037,41 +1037,41 @@ declare begin select into rec * from PSlot where slotname = $1; if not found then - return ''''; + return ''; end if; - if rec.backlink = '''' then - return ''-''; + if rec.backlink = '' then + return '-'; end if; bltype := substr(rec.backlink, 1, 2); - if bltype = ''PL'' then + if bltype = 'PL' then declare rec record; begin select into rec * from PLine where slotname = "outer".rec.backlink; - retval := ''Phone line '' || trim(rec.phonenumber); - if rec.comment != '''' then - retval := retval || '' (''; + retval := 'Phone line ' || trim(rec.phonenumber); + if rec.comment != '' then + retval := retval || ' ('; retval := retval || rec.comment; - retval := retval || '')''; + retval := retval || ')'; end if; return retval; end; end if; - if bltype = ''WS'' then + if bltype = 'WS' then select into rec * from WSlot where slotname = rec.backlink; - retval := trim(rec.slotname) || '' in room ''; + retval := trim(rec.slotname) || ' in room '; retval := retval || trim(rec.roomno); - retval := retval || '' -> ''; + retval := retval || ' -> '; return retval || wslot_slotlink_view(rec.slotname); end if; return rec.backlink; end; -'; +$$; create function pslot_slotlink_view(bpchar) returns text language plpgsql -as ' +as $$ declare psrec record; sltype char(2); @@ -1079,33 +1079,33 @@ declare begin select into psrec * from PSlot where slotname = $1; if not found then - return ''''; + return ''; end if; - if psrec.slotlink = '''' then - return ''-''; + if psrec.slotlink = '' then + return '-'; end if; sltype := substr(psrec.slotlink, 1, 2); - if sltype = ''PS'' then - retval := trim(psrec.slotlink) || '' -> ''; + if sltype = 'PS' then + retval := trim(psrec.slotlink) || ' -> '; return retval || pslot_backlink_view(psrec.slotlink); end if; - if sltype = ''HS'' then + if sltype = 'HS' then retval := comment from Hub H, HSlot HS where HS.slotname = psrec.slotlink and H.name = HS.hubname; - retval := retval || '' slot ''; + retval := retval || ' slot '; retval := retval || slotno::text from HSlot where slotname = psrec.slotlink; return retval; end if; return psrec.slotlink; end; -'; +$$; create function wslot_slotlink_view(bpchar) returns text language plpgsql -as ' +as $$ declare rec record; sltype char(2); @@ -1113,42 +1113,42 @@ declare begin select into rec * from WSlot where slotname = $1; if not found then - return ''''; + return ''; end if; - if rec.slotlink = '''' then - return ''-''; + if rec.slotlink = '' then + return '-'; end if; sltype := substr(rec.slotlink, 1, 2); - if sltype = ''PH'' then + if sltype = 'PH' then select into rec * from PHone where slotname = rec.slotlink; - retval := ''Phone '' || trim(rec.slotname); - if rec.comment != '''' then - retval := retval || '' (''; + retval := 'Phone ' || trim(rec.slotname); + if rec.comment != '' then + retval := retval || ' ('; retval := retval || rec.comment; - retval := retval || '')''; + retval := retval || ')'; end if; return retval; end if; - if sltype = ''IF'' then + if sltype = 'IF' then declare syrow System%RowType; ifrow IFace%ROWTYPE; begin select into ifrow * from IFace where slotname = rec.slotlink; select into syrow * from System where name = ifrow.sysname; - retval := syrow.name || '' IF ''; + retval := syrow.name || ' IF '; retval := retval || ifrow.ifname; - if syrow.comment != '''' then - retval := retval || '' (''; + if syrow.comment != '' then + retval := retval || ' ('; retval := retval || syrow.comment; - retval := retval || '')''; + retval := retval || ')'; end if; return retval; end; end if; return rec.slotlink; end; -'; +$$; create view pfield_v1 as select @@ -1541,16 +1541,16 @@ values ('IF', 'orion', 'ethernet_interface_name_too_long', ''); create function recursion_test(int, int) returns text language plpgsql -as ' +as $$ DECLARE rslt text; BEGIN IF $1 <= 0 THEN rslt = CAST($2 AS TEXT); ELSE - rslt = CAST($1 AS TEXT) || '','' || recursion_test($1 - 1, $2); + rslt = CAST($1 AS TEXT) || ',' || recursion_test($1 - 1, $2); END IF; RETURN rslt; -END;'; +END;$$; select recursion_test(4, 3); @@ -1559,7 +1559,7 @@ create table found_test_tbl (a int); create function test_found() returns boolean language plpgsql -as ' +as $$ declare begin insert into found_test_tbl values (1); @@ -1592,7 +1592,7 @@ as ' insert into found_test_tbl values (6); end if; return true; - end;'; + end;$$; select test_found(); @@ -1601,7 +1601,7 @@ select * from found_test_tbl; create function test_table_func_rec() returns setof found_test_tbl language plpgsql -as ' +as $$ DECLARE rec RECORD; BEGIN @@ -1609,14 +1609,14 @@ BEGIN RETURN NEXT rec; END LOOP; RETURN; -END;'; +END;$$; select * from test_table_func_rec(); create function test_table_func_row() returns setof found_test_tbl language plpgsql -as ' +as $$ DECLARE row found_test_tbl%ROWTYPE; BEGIN @@ -1624,14 +1624,14 @@ BEGIN RETURN NEXT row; END LOOP; RETURN; -END;'; +END;$$; select * from test_table_func_row(); create function test_ret_set_scalar(int, int) returns setof int language plpgsql -as ' +as $$ DECLARE i int; BEGIN @@ -1639,14 +1639,14 @@ BEGIN RETURN NEXT i + 1; END LOOP; RETURN; -END;'; +END;$$; select * from test_ret_set_scalar(1, 10); create function test_ret_set_rec_dyn(int) returns setof record language plpgsql -as ' +as $$ DECLARE retval RECORD; BEGIN @@ -1655,12 +1655,12 @@ BEGIN RETURN NEXT retval; RETURN NEXT retval; ELSE - SELECT INTO retval 50, 5::numeric, ''xxx''::text; + SELECT INTO retval 50, 5::numeric, 'xxx'::text; RETURN NEXT retval; RETURN NEXT retval; END IF; RETURN; -END;'; +END;$$; select * from test_ret_set_rec_dyn(1500) as (a int, b int, c int); @@ -1669,7 +1669,7 @@ select * from test_ret_set_rec_dyn(5) as (a int, b numeric, c text); create function test_ret_rec_dyn(int) returns record language plpgsql -as ' +as $$ DECLARE retval RECORD; BEGIN @@ -1677,10 +1677,10 @@ BEGIN SELECT INTO retval 5, 10, 15; RETURN retval; ELSE - SELECT INTO retval 50, 5::numeric, ''xxx''::text; + SELECT INTO retval 50, 5::numeric, 'xxx'::text; RETURN retval; END IF; -END;'; +END;$$; select * from test_ret_rec_dyn(1500) as (a int, b int, c int); @@ -1972,7 +1972,7 @@ create table perform_test ( create function perform_simple_func(int) returns boolean language plpgsql -as ' +as $$ BEGIN IF $1 < 20 THEN INSERT INTO perform_test VALUES ($1, $1 + 10); @@ -1980,12 +1980,12 @@ BEGIN ELSE RETURN FALSE; END IF; -END;'; +END;$$; create function perform_test_func() returns void language plpgsql -as ' +as $$ BEGIN IF FOUND then INSERT INTO perform_test VALUES (100, 100); @@ -2004,7 +2004,7 @@ BEGIN END IF; RETURN; -END;'; +END;$$; select perform_test_func(); @@ -4378,7 +4378,7 @@ BEGIN END LOOP; END$$; -do $outer$ +do $body$ begin for i in 1..10 loop begin @@ -4395,7 +4395,7 @@ begin end; end loop; end; -$outer$; +$body$; do $$ declare x int := x + 1; -- error diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_100.snap index 542b19ac0..891182ecc 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_100.snap @@ -176,7 +176,7 @@ drop function polyf(a anyelement, b anyarray, c anycompatible, d anycompatible); create function polyf(anyrange) returns anymultirange language sql -as 'select multirange($1);'; +as $$select multirange($1);$$; select polyf(int4range(1, 10)); @@ -187,7 +187,7 @@ drop function polyf(anyrange); create function polyf(anymultirange) returns anyelement language sql -as 'select lower($1);'; +as $$select lower($1);$$; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -198,7 +198,7 @@ drop function polyf(anymultirange); create function polyf(anycompatiblerange) returns anycompatiblemultirange language sql -as 'select multirange($1);'; +as $$select multirange($1);$$; select polyf(int4range(1, 10)); @@ -209,7 +209,7 @@ drop function polyf(anycompatiblerange); create function polyf(anymultirange) returns anyrange language sql -as 'select range_merge($1);'; +as $$select range_merge($1);$$; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -220,7 +220,7 @@ drop function polyf(anymultirange); create function polyf(anycompatiblemultirange) returns anycompatiblerange language sql -as 'select range_merge($1);'; +as $$select range_merge($1);$$; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -231,7 +231,7 @@ drop function polyf(anycompatiblemultirange); create function polyf(anycompatiblemultirange) returns anycompatible language sql -as 'select lower($1);'; +as $$select lower($1);$$; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -242,48 +242,48 @@ drop function polyf(anycompatiblemultirange); create function stfp(anyarray) returns anyarray language sql -as 'select $1'; +as $$select $1$$; create function stfnp(int[]) returns int[] language sql -as 'select $1'; +as $$select $1$$; create function tfp(anyarray, anyelement) returns anyarray language sql -as 'select $1 || $2'; +as $$select $1 || $2$$; create function tfnp(int[], int) returns int[] language sql -as 'select $1 || $2'; +as $$select $1 || $2$$; create function tf1p(anyarray, int) returns anyarray language sql -as 'select $1'; +as $$select $1$$; create function tf2p(int[], anyelement) returns int[] language sql -as 'select $1'; +as $$select $1$$; create function sum3(anyelement, anyelement, anyelement) returns anyelement language sql strict -as 'select $1+$2+$3'; +as $$select $1+$2+$3$$; create function ffp(anyarray) returns anyarray language sql -as 'select $1'; +as $$select $1$$; create function ffnp(int[]) returns int[] language sql -as 'select $1'; +as $$select $1$$; create aggregate myaggp01a (*) (sfunc = stfnp, stype = int4[], finalfunc = ffp, initcond = '{}'); @@ -731,14 +731,14 @@ create function first_el_transfn(anyarray, anyelement) returns anyarray language sql immutable -as 'select $1 || $2'; +as $$select $1 || $2$$; create function first_el(anyarray) returns anyelement language sql immutable strict -as 'select $1[1]'; +as $$select $1[1]$$; create aggregate first_el_agg_f8 ( float8 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_80.snap index 9d56eacc8..7ee95d52d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__polymorphism_80.snap @@ -196,7 +196,7 @@ drop function polyf(a anyelement, b anyarray, c anycompatible, d anycompatible); create function polyf(anyrange) returns anymultirange language sql -as 'select multirange($1);'; +as $$select multirange($1);$$; select polyf(int4range(1, 10)); @@ -207,7 +207,7 @@ drop function polyf(anyrange); create function polyf(anymultirange) returns anyelement language sql -as 'select lower($1);'; +as $$select lower($1);$$; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -218,7 +218,7 @@ drop function polyf(anymultirange); create function polyf(anycompatiblerange) returns anycompatiblemultirange language sql -as 'select multirange($1);'; +as $$select multirange($1);$$; select polyf(int4range(1, 10)); @@ -229,7 +229,7 @@ drop function polyf(anycompatiblerange); create function polyf(anymultirange) returns anyrange language sql -as 'select range_merge($1);'; +as $$select range_merge($1);$$; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -240,7 +240,7 @@ drop function polyf(anymultirange); create function polyf(anycompatiblemultirange) returns anycompatiblerange language sql -as 'select range_merge($1);'; +as $$select range_merge($1);$$; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -251,7 +251,7 @@ drop function polyf(anycompatiblemultirange); create function polyf(anycompatiblemultirange) returns anycompatible language sql -as 'select lower($1);'; +as $$select lower($1);$$; select polyf(int4multirange(int4range(1, 10), int4range(20, 30))); @@ -262,48 +262,48 @@ drop function polyf(anycompatiblemultirange); create function stfp(anyarray) returns anyarray language sql -as 'select $1'; +as $$select $1$$; create function stfnp(int[]) returns int[] language sql -as 'select $1'; +as $$select $1$$; create function tfp(anyarray, anyelement) returns anyarray language sql -as 'select $1 || $2'; +as $$select $1 || $2$$; create function tfnp(int[], int) returns int[] language sql -as 'select $1 || $2'; +as $$select $1 || $2$$; create function tf1p(anyarray, int) returns anyarray language sql -as 'select $1'; +as $$select $1$$; create function tf2p(int[], anyelement) returns int[] language sql -as 'select $1'; +as $$select $1$$; create function sum3(anyelement, anyelement, anyelement) returns anyelement language sql strict -as 'select $1+$2+$3'; +as $$select $1+$2+$3$$; create function ffp(anyarray) returns anyarray language sql -as 'select $1'; +as $$select $1$$; create function ffnp(int[]) returns int[] language sql -as 'select $1'; +as $$select $1$$; create aggregate myaggp01a ( * @@ -916,14 +916,14 @@ create function first_el_transfn(anyarray, anyelement) returns anyarray language sql immutable -as 'select $1 || $2'; +as $$select $1 || $2$$; create function first_el(anyarray) returns anyelement language sql immutable strict -as 'select $1[1]'; +as $$select $1[1]$$; create aggregate first_el_agg_f8 ( float8 diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_100.snap index 950efcbc2..47fd78372 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_100.snap @@ -306,7 +306,7 @@ returns boolean language internal immutable strict -as 'int4lt'; +as $$int4lt$$; alter function leak(int, int) owner to regress_priv_user1; @@ -1186,18 +1186,18 @@ grant usage on language sql to regress_priv_user2; create function priv_testfunc1(int) returns int language sql -as 'select 2 * $1;'; +as $$select 2 * $1;$$; create function priv_testfunc2(int) returns int language sql -as 'select 3 * $1;'; +as $$select 3 * $1;$$; create aggregate priv_testagg1 (int) (sfunc = int4pl, stype = int4); create procedure priv_testproc1(int) language sql -as 'select $1;'; +as $$select $1;$$; revoke all on function priv_testfunc1(int), priv_testfunc2(int), priv_testagg1(int) from public; @@ -1231,7 +1231,7 @@ create function priv_testfunc4(boolean) returns text language sql security definer -as 'select col1 from atest2 where col2 = $1;'; +as $$select col1 from atest2 where col2 = $1;$$; grant execute on function priv_testfunc4(boolean) to regress_priv_user3; @@ -1242,7 +1242,7 @@ select priv_testfunc1(5), priv_testfunc2(5); create function priv_testfunc3(int) returns int language sql -as 'select 2 * $1;'; +as $$select 2 * $1;$$; select priv_testagg1(x) from (values (1), (2), (3)) as _ (x); @@ -1783,12 +1783,12 @@ set session authorization regress_sro_user; create function unwanted_grant() returns void language sql -as 'GRANT regress_priv_group2 TO regress_sro_user'; +as $$GRANT regress_priv_group2 TO regress_sro_user$$; create function mv_action() returns bool language sql -as 'DECLARE c CURSOR WITH HOLD FOR SELECT public.unwanted_grant(); SELECT true'; +as $$DECLARE c CURSOR WITH HOLD FOR SELECT public.unwanted_grant(); SELECT true$$; create materialized view sro_mv as select mv_action() with no data; @@ -1803,7 +1803,7 @@ create table sro_trojan_table (); create function sro_trojan() returns trigger language plpgsql -as 'BEGIN PERFORM public.unwanted_grant(); RETURN NULL; END'; +as $$BEGIN PERFORM public.unwanted_grant(); RETURN NULL; END$$; create constraint trigger t after insert @@ -1816,7 +1816,7 @@ execute function sro_trojan(); create or replace function mv_action() returns bool language sql -as 'INSERT INTO public.sro_trojan_table DEFAULT VALUES; SELECT true'; +as $$INSERT INTO public.sro_trojan_table DEFAULT VALUES; SELECT true$$; refresh materialized view sro_mv; @@ -1863,7 +1863,7 @@ create function dogrant_ok() returns void language sql security definer -as 'GRANT regress_priv_group2 TO regress_priv_user5'; +as $$GRANT regress_priv_group2 TO regress_priv_user5$$; grant regress_priv_group2 to regress_priv_user5; @@ -2373,13 +2373,13 @@ set role to regress_priv_user1; create function testns.foo() returns int language sql -as 'select 1'; +as $$select 1$$; create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int4); create procedure testns.bar() language sql -as 'select 1'; +as $$select 1$$; select has_function_privilege('regress_priv_user2', 'testns.foo()', 'EXECUTE'); @@ -2394,7 +2394,7 @@ drop function testns.foo(); create function testns.foo() returns int language sql -as 'select 1'; +as $$select 1$$; drop aggregate testns.agg1(int); @@ -2404,7 +2404,7 @@ drop procedure testns.bar(); create procedure testns.bar() language sql -as 'select 1'; +as $$select 1$$; select has_function_privilege('regress_priv_user2', 'testns.foo()', 'EXECUTE'); @@ -2483,13 +2483,13 @@ select has_table_privilege('regress_priv_user1', 'testns.t2', 'SELECT'); create function testns.priv_testfunc(int) returns int language sql -as 'select 3 * $1;'; +as $$select 3 * $1;$$; create aggregate testns.priv_testagg (int) (sfunc = int4pl, stype = int4); create procedure testns.priv_testproc(int) language sql -as 'select 3'; +as $$select 3$$; select has_function_privilege('regress_priv_user1', 'testns.priv_testfunc(int)', 'EXECUTE'); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_80.snap index cb2f2b869..a54f8d3b3 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__privileges_80.snap @@ -348,7 +348,7 @@ returns boolean language internal immutable strict -as 'int4lt'; +as $$int4lt$$; alter function leak(int, int) owner to regress_priv_user1; @@ -1355,18 +1355,18 @@ grant usage on language sql to regress_priv_user2; create function priv_testfunc1(int) returns int language sql -as 'select 2 * $1;'; +as $$select 2 * $1;$$; create function priv_testfunc2(int) returns int language sql -as 'select 3 * $1;'; +as $$select 3 * $1;$$; create aggregate priv_testagg1 (int) (sfunc = int4pl, stype = int4); create procedure priv_testproc1(int) language sql -as 'select $1;'; +as $$select $1;$$; revoke all on function priv_testfunc1(int), @@ -1404,7 +1404,7 @@ create function priv_testfunc4(boolean) returns text language sql security definer -as 'select col1 from atest2 where col2 = $1;'; +as $$select col1 from atest2 where col2 = $1;$$; grant execute on function priv_testfunc4(boolean) to regress_priv_user3; @@ -1415,7 +1415,7 @@ select priv_testfunc1(5), priv_testfunc2(5); create function priv_testfunc3(int) returns int language sql -as 'select 2 * $1;'; +as $$select 2 * $1;$$; select priv_testagg1(x) from (values (1), (2), (3)) as _ (x); @@ -1980,12 +1980,12 @@ set session authorization regress_sro_user; create function unwanted_grant() returns void language sql -as 'GRANT regress_priv_group2 TO regress_sro_user'; +as $$GRANT regress_priv_group2 TO regress_sro_user$$; create function mv_action() returns bool language sql -as 'DECLARE c CURSOR WITH HOLD FOR SELECT public.unwanted_grant(); SELECT true'; +as $$DECLARE c CURSOR WITH HOLD FOR SELECT public.unwanted_grant(); SELECT true$$; create materialized view sro_mv as select mv_action() with no data; @@ -2000,7 +2000,7 @@ create table sro_trojan_table (); create function sro_trojan() returns trigger language plpgsql -as 'BEGIN PERFORM public.unwanted_grant(); RETURN NULL; END'; +as $$BEGIN PERFORM public.unwanted_grant(); RETURN NULL; END$$; create constraint trigger t after insert @@ -2013,7 +2013,7 @@ execute function sro_trojan(); create or replace function mv_action() returns bool language sql -as 'INSERT INTO public.sro_trojan_table DEFAULT VALUES; SELECT true'; +as $$INSERT INTO public.sro_trojan_table DEFAULT VALUES; SELECT true$$; refresh materialized view sro_mv; @@ -2061,7 +2061,7 @@ create function dogrant_ok() returns void language sql security definer -as 'GRANT regress_priv_group2 TO regress_priv_user5'; +as $$GRANT regress_priv_group2 TO regress_priv_user5$$; grant regress_priv_group2 to regress_priv_user5; @@ -2600,13 +2600,13 @@ set role to regress_priv_user1; create function testns.foo() returns int language sql -as 'select 1'; +as $$select 1$$; create aggregate testns.agg1 (int) (sfunc = int4pl, stype = int4); create procedure testns.bar() language sql -as 'select 1'; +as $$select 1$$; select has_function_privilege('regress_priv_user2', 'testns.foo()', 'EXECUTE'); @@ -2622,7 +2622,7 @@ drop function testns.foo(); create function testns.foo() returns int language sql -as 'select 1'; +as $$select 1$$; drop aggregate testns.agg1(int); @@ -2632,7 +2632,7 @@ drop procedure testns.bar(); create procedure testns.bar() language sql -as 'select 1'; +as $$select 1$$; select has_function_privilege('regress_priv_user2', 'testns.foo()', 'EXECUTE'); @@ -2722,13 +2722,13 @@ select has_table_privilege('regress_priv_user1', 'testns.t2', 'SELECT'); create function testns.priv_testfunc(int) returns int language sql -as 'select 3 * $1;'; +as $$select 3 * $1;$$; create aggregate testns.priv_testagg (int) (sfunc = int4pl, stype = int4); create procedure testns.priv_testproc(int) language sql -as 'select 3'; +as $$select 3$$; select has_function_privilege( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_100.snap index 14ebb6298..e31ac2150 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_100.snap @@ -16,7 +16,7 @@ insert into rngfunc2 values (1, 111); create function rngfunct(int) returns setof rngfunc2 language sql -as 'SELECT * FROM rngfunc2 WHERE rngfuncid = $1 ORDER BY f2;'; +as $$SELECT * FROM rngfunc2 WHERE rngfuncid = $1 ORDER BY f2;$$; select * from rngfunct(1) with ordinality as z (a, b, ord); @@ -207,7 +207,7 @@ insert into rngfunc values (2, 1, 'Mary'); create function getrngfunc1(int) returns int language sql -as 'SELECT $1;'; +as $$SELECT $1;$$; select * from getrngfunc1(1) as t1; @@ -230,7 +230,7 @@ drop view vw_getrngfunc; create function getrngfunc2(int) returns setof int language sql -as 'SELECT rngfuncid FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT rngfuncid FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc2(1) as t1; @@ -253,7 +253,7 @@ drop view vw_getrngfunc; create function getrngfunc3(int) returns setof text language sql -as 'SELECT rngfuncname FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT rngfuncname FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc3(1) as t1; @@ -276,7 +276,7 @@ drop view vw_getrngfunc; create function getrngfunc4(int) returns rngfunc language sql -as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT * FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc4(1) as t1; @@ -299,7 +299,7 @@ drop view vw_getrngfunc; create function getrngfunc5(int) returns setof rngfunc language sql -as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT * FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc5(1) as t1; @@ -322,7 +322,7 @@ drop view vw_getrngfunc; create function getrngfunc6(int) returns record language sql -as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT * FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc6(1) as t1 (rngfuncid int, rngfuncsubid int, rngfuncname text); @@ -351,7 +351,7 @@ drop view vw_getrngfunc; create function getrngfunc7(int) returns setof record language sql -as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT * FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc7(1) as t1 (rngfuncid int, rngfuncsubid int, rngfuncname text); @@ -380,7 +380,7 @@ drop view vw_getrngfunc; create function getrngfunc8(int) returns int language plpgsql -as 'DECLARE rngfuncint int; BEGIN SELECT rngfuncid into rngfuncint FROM rngfunc WHERE rngfuncid = $1; RETURN rngfuncint; END;'; +as $$DECLARE rngfuncint int; BEGIN SELECT rngfuncid into rngfuncint FROM rngfunc WHERE rngfuncid = $1; RETURN rngfuncint; END;$$; select * from getrngfunc8(1) as t1; @@ -403,7 +403,7 @@ drop view vw_getrngfunc; create function getrngfunc9(int) returns rngfunc language plpgsql -as 'DECLARE rngfunctup rngfunc%ROWTYPE; BEGIN SELECT * into rngfunctup FROM rngfunc WHERE rngfuncid = $1; RETURN rngfunctup; END;'; +as $$DECLARE rngfunctup rngfunc%ROWTYPE; BEGIN SELECT * into rngfunctup FROM rngfunc WHERE rngfuncid = $1; RETURN rngfunctup; END;$$; select * from getrngfunc9(1) as t1; @@ -502,12 +502,12 @@ create type rngfunc_rescan_t as (i int, s bigint); create function rngfunc_sql(int, int) returns setof rngfunc_rescan_t language sql -as 'SELECT i, nextval(''rngfunc_rescan_seq1'') FROM generate_series($1,$2) i;'; +as $$SELECT i, nextval('rngfunc_rescan_seq1') FROM generate_series($1,$2) i;$$; create function rngfunc_mat(int, int) returns setof rngfunc_rescan_t language plpgsql -as 'begin for i in $1..$2 loop return next (i, nextval(''rngfunc_rescan_seq2'')); end loop; end;'; +as $$begin for i in $1..$2 loop return next (i, nextval('rngfunc_rescan_seq2')); end loop; end;$$; select setval('rngfunc_rescan_seq1', 1, false), setval('rngfunc_rescan_seq2', 1, false); @@ -798,7 +798,7 @@ drop sequence rngfunc_rescan_seq2; create function rngfunc(in f1 int, out f2 int) language sql -as 'select $1+1'; +as $$select $1+1$$; select rngfunc(42); @@ -809,22 +809,22 @@ select * from rngfunc(42) as p (x); create or replace function rngfunc(in f1 int, out f2 int) returns int language sql -as 'select $1+1'; +as $$select $1+1$$; create or replace function rngfunc(in f1 int, out f2 int) returns double precision language sql -as 'select $1+1'; +as $$select $1+1$$; create or replace function rngfunc(in f1 int, out f2 int, out f3 text) returns int language sql -as 'select $1+1'; +as $$select $1+1$$; create or replace function rngfunc(in f1 int, out f2 int, out f3 text) returns record language sql -as 'select $1+1'; +as $$select $1+1$$; create or replace function rngfuncr(in f1 int, out f2 int, out text) language sql @@ -854,7 +854,7 @@ drop function rngfuncb(in f1 int, inout f2 int); create function dup(f1 anyelement, out f2 anyelement, out f3 anyarray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; select dup(22); @@ -866,13 +866,13 @@ select * from dup(cast('xyz' as text)); create or replace function dup(inout f2 anyelement, out f3 anyarray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; drop function dup(anyelement); create or replace function dup(inout f2 anyelement, out f3 anyarray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; select dup(22); @@ -880,7 +880,7 @@ drop function dup(anyelement); create function bad(f1 int, out f2 anyelement, out f3 anyarray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; create function dup( @@ -890,7 +890,7 @@ dup( out f4 anycompatiblearray ) language sql -as 'select $1, $2'; +as $$select $1, $2$$; select dup(22, array[44]); @@ -910,7 +910,7 @@ dup( out f4 anycompatiblerange ) language sql -as 'select lower($1), array[lower($1), upper($1)], $1'; +as $$select lower($1), array[lower($1), upper($1)], $1$$; select dup(int4range(4, 7)); @@ -922,7 +922,7 @@ drop function dup(f1 anycompatiblerange); create function bad(f1 anyarray, out f2 anycompatible, out f3 anycompatiblearray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; create or replace function rngfunc() returns table ( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_80.snap index b0bae436d..d637f2feb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangefuncs_80.snap @@ -16,7 +16,7 @@ insert into rngfunc2 values (1, 111); create function rngfunct(int) returns setof rngfunc2 language sql -as 'SELECT * FROM rngfunc2 WHERE rngfuncid = $1 ORDER BY f2;'; +as $$SELECT * FROM rngfunc2 WHERE rngfuncid = $1 ORDER BY f2;$$; select * from rngfunct(1) with ordinality as z (a, b, ord); @@ -251,7 +251,7 @@ insert into rngfunc values (2, 1, 'Mary'); create function getrngfunc1(int) returns int language sql -as 'SELECT $1;'; +as $$SELECT $1;$$; select * from getrngfunc1(1) as t1; @@ -274,7 +274,7 @@ drop view vw_getrngfunc; create function getrngfunc2(int) returns setof int language sql -as 'SELECT rngfuncid FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT rngfuncid FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc2(1) as t1; @@ -297,7 +297,7 @@ drop view vw_getrngfunc; create function getrngfunc3(int) returns setof text language sql -as 'SELECT rngfuncname FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT rngfuncname FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc3(1) as t1; @@ -320,7 +320,7 @@ drop view vw_getrngfunc; create function getrngfunc4(int) returns rngfunc language sql -as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT * FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc4(1) as t1; @@ -343,7 +343,7 @@ drop view vw_getrngfunc; create function getrngfunc5(int) returns setof rngfunc language sql -as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT * FROM rngfunc WHERE rngfuncid = $1;$$; select * from getrngfunc5(1) as t1; @@ -366,7 +366,7 @@ drop view vw_getrngfunc; create function getrngfunc6(int) returns record language sql -as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT * FROM rngfunc WHERE rngfuncid = $1;$$; select * @@ -407,7 +407,7 @@ drop view vw_getrngfunc; create function getrngfunc7(int) returns setof record language sql -as 'SELECT * FROM rngfunc WHERE rngfuncid = $1;'; +as $$SELECT * FROM rngfunc WHERE rngfuncid = $1;$$; select * @@ -448,7 +448,7 @@ drop view vw_getrngfunc; create function getrngfunc8(int) returns int language plpgsql -as 'DECLARE rngfuncint int; BEGIN SELECT rngfuncid into rngfuncint FROM rngfunc WHERE rngfuncid = $1; RETURN rngfuncint; END;'; +as $$DECLARE rngfuncint int; BEGIN SELECT rngfuncid into rngfuncint FROM rngfunc WHERE rngfuncid = $1; RETURN rngfuncint; END;$$; select * from getrngfunc8(1) as t1; @@ -471,7 +471,7 @@ drop view vw_getrngfunc; create function getrngfunc9(int) returns rngfunc language plpgsql -as 'DECLARE rngfunctup rngfunc%ROWTYPE; BEGIN SELECT * into rngfunctup FROM rngfunc WHERE rngfuncid = $1; RETURN rngfunctup; END;'; +as $$DECLARE rngfunctup rngfunc%ROWTYPE; BEGIN SELECT * into rngfunctup FROM rngfunc WHERE rngfuncid = $1; RETURN rngfunctup; END;$$; select * from getrngfunc9(1) as t1; @@ -570,12 +570,12 @@ create type rngfunc_rescan_t as (i int, s bigint); create function rngfunc_sql(int, int) returns setof rngfunc_rescan_t language sql -as 'SELECT i, nextval(''rngfunc_rescan_seq1'') FROM generate_series($1,$2) i;'; +as $$SELECT i, nextval('rngfunc_rescan_seq1') FROM generate_series($1,$2) i;$$; create function rngfunc_mat(int, int) returns setof rngfunc_rescan_t language plpgsql -as 'begin for i in $1..$2 loop return next (i, nextval(''rngfunc_rescan_seq2'')); end loop; end;'; +as $$begin for i in $1..$2 loop return next (i, nextval('rngfunc_rescan_seq2')); end loop; end;$$; select setval('rngfunc_rescan_seq1', 1, false), @@ -948,7 +948,7 @@ drop sequence rngfunc_rescan_seq2; create function rngfunc(in f1 int, out f2 int) language sql -as 'select $1+1'; +as $$select $1+1$$; select rngfunc(42); @@ -959,22 +959,22 @@ select * from rngfunc(42) as p (x); create or replace function rngfunc(in f1 int, out f2 int) returns int language sql -as 'select $1+1'; +as $$select $1+1$$; create or replace function rngfunc(in f1 int, out f2 int) returns double precision language sql -as 'select $1+1'; +as $$select $1+1$$; create or replace function rngfunc(in f1 int, out f2 int, out f3 text) returns int language sql -as 'select $1+1'; +as $$select $1+1$$; create or replace function rngfunc(in f1 int, out f2 int, out f3 text) returns record language sql -as 'select $1+1'; +as $$select $1+1$$; create or replace function rngfuncr(in f1 int, out f2 int, out text) language sql @@ -1004,7 +1004,7 @@ drop function rngfuncb(in f1 int, inout f2 int); create function dup(f1 anyelement, out f2 anyelement, out f3 anyarray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; select dup(22); @@ -1016,13 +1016,13 @@ select * from dup(cast('xyz' as text)); create or replace function dup(inout f2 anyelement, out f3 anyarray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; drop function dup(anyelement); create or replace function dup(inout f2 anyelement, out f3 anyarray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; select dup(22); @@ -1030,7 +1030,7 @@ drop function dup(anyelement); create function bad(f1 int, out f2 anyelement, out f3 anyarray) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; create function dup( @@ -1040,7 +1040,7 @@ dup( out f4 anycompatiblearray ) language sql -as 'select $1, $2'; +as $$select $1, $2$$; select dup(22, array[44]); @@ -1060,7 +1060,7 @@ dup( out f4 anycompatiblerange ) language sql -as 'select lower($1), array[lower($1), upper($1)], $1'; +as $$select lower($1), array[lower($1), upper($1)], $1$$; select dup(int4range(4, 7)); @@ -1077,7 +1077,7 @@ bad( out f3 anycompatiblearray ) language sql -as 'select $1, array[$1,$1]'; +as $$select $1, array[$1,$1]$$; create or replace function rngfunc() returns table ( diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_100.snap index db8f0286a..7a47c6e64 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_100.snap @@ -815,7 +815,7 @@ drop type textrange2; create function anyarray_anyrange_func(a anyarray, r anyrange) returns anyelement language sql -as 'select $1[1] + lower($2);'; +as $$select $1[1] + lower($2);$$; select anyarray_anyrange_func(array[1, 2], int4range(10, 20)); @@ -826,17 +826,17 @@ drop function anyarray_anyrange_func(anyarray, anyrange); create function bogus_func(anyelement) returns anyrange language sql -as 'select int4range(1,10)'; +as $$select int4range(1,10)$$; create function bogus_func(int) returns anyrange language sql -as 'select int4range(1,10)'; +as $$select int4range(1,10)$$; create function range_add_bounds(anyrange) returns anyelement language sql -as 'select lower($1) + upper($1)'; +as $$select lower($1) + upper($1)$$; select range_add_bounds(int4range(1, 17)); @@ -857,7 +857,7 @@ anycompatiblearray_anycompatiblerange_func( ) returns anycompatible language sql -as 'select $1[1] + lower($2);'; +as $$select $1[1] + lower($2);$$; select anycompatiblearray_anycompatiblerange_func(array[1, 2], int4range(10, 20)); @@ -870,7 +870,7 @@ drop function anycompatiblearray_anycompatiblerange_func(anycompatiblearray, any create function bogus_func(anycompatible) returns anycompatiblerange language sql -as 'select int4range(1,10)'; +as $$select int4range(1,10)$$; select array[numrange(1.1, 1.2), numrange(12.3, 155.5)]; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_80.snap index 85bb9332c..609869cc6 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rangetypes_80.snap @@ -884,7 +884,7 @@ drop type textrange2; create function anyarray_anyrange_func(a anyarray, r anyrange) returns anyelement language sql -as 'select $1[1] + lower($2);'; +as $$select $1[1] + lower($2);$$; select anyarray_anyrange_func(array[1, 2], int4range(10, 20)); @@ -895,17 +895,17 @@ drop function anyarray_anyrange_func(anyarray, anyrange); create function bogus_func(anyelement) returns anyrange language sql -as 'select int4range(1,10)'; +as $$select int4range(1,10)$$; create function bogus_func(int) returns anyrange language sql -as 'select int4range(1,10)'; +as $$select int4range(1,10)$$; create function range_add_bounds(anyrange) returns anyelement language sql -as 'select lower($1) + upper($1)'; +as $$select lower($1) + upper($1)$$; select range_add_bounds(int4range(1, 17)); @@ -926,7 +926,7 @@ anycompatiblearray_anycompatiblerange_func( ) returns anycompatible language sql -as 'select $1[1] + lower($2);'; +as $$select $1[1] + lower($2);$$; select anycompatiblearray_anycompatiblerange_func(array[1, 2], int4range(10, 20)); @@ -945,7 +945,7 @@ drop function create function bogus_func(anycompatible) returns anycompatiblerange language sql -as 'select int4range(1,10)'; +as $$select int4range(1,10)$$; select array[numrange(1.1, 1.2), numrange(12.3, 155.5)]; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_100.snap index 09b43a2cc..48d9f85f9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_100.snap @@ -50,7 +50,7 @@ create or replace function f_leak(text) returns bool language plpgsql cost 0.0000001 -as 'BEGIN RAISE NOTICE ''f_leak => %'', $1; RETURN true; END'; +as $$BEGIN RAISE NOTICE 'f_leak => %', $1; RETURN true; END$$; grant execute on function f_leak(text) to public; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_80.snap index 3a3f4b9e5..226b2a177 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__rowsecurity_80.snap @@ -50,7 +50,7 @@ create or replace function f_leak(text) returns bool language plpgsql cost 0.0000001 -as 'BEGIN RAISE NOTICE ''f_leak => %'', $1; RETURN true; END'; +as $$BEGIN RAISE NOTICE 'f_leak => %', $1; RETURN true; END$$; grant execute on function f_leak(text) to public; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_100.snap index 8ab3846b7..b731aee4d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_100.snap @@ -223,7 +223,7 @@ create function sillysrf(int) returns setof int language sql immutable -as 'values (1),(10),(2),($1)'; +as $$values (1),(10),(2),($1)$$; select sillysrf(42); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_80.snap index beecb4ff5..0935ba3c9 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_80.snap @@ -273,7 +273,7 @@ create function sillysrf(int) returns setof int language sql immutable -as 'values (1),(10),(2),($1)'; +as $$values (1),(10),(2),($1)$$; select sillysrf(42); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_100.snap index 90d5db020..aecf9226b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_100.snap @@ -14,7 +14,7 @@ create function f_leak(text) returns bool language plpgsql cost 0.0000001 -as 'BEGIN RAISE NOTICE ''f_leak => %'', $1; RETURN true; END'; +as $$BEGIN RAISE NOTICE 'f_leak => %', $1; RETURN true; END$$; create table customer ( cid int primary key, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_80.snap index 46098575f..8b5ef355b 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__select_views_80.snap @@ -14,7 +14,7 @@ create function f_leak(text) returns bool language plpgsql cost 0.0000001 -as 'BEGIN RAISE NOTICE ''f_leak => %'', $1; RETURN true; END'; +as $$BEGIN RAISE NOTICE 'f_leak => %', $1; RETURN true; END$$; create table customer ( cid int primary key, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_100.snap index 17ea5aeff..97d94d05c 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_100.snap @@ -2813,14 +2813,14 @@ select * from tststats.priv_test_tbl where a = 1 and tststats.priv_test_tbl.* > create function op_leak(int, int) returns bool language plpgsql -as 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'; +as $$BEGIN RAISE NOTICE 'op_leak => %, %', $1, $2; RETURN $1 < $2; END$$; create operator <<< (procedure = op_leak, leftarg = int, rightarg = int, restrict = scalarltsel); create function op_leak(record, record) returns bool language plpgsql -as 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'; +as $$BEGIN RAISE NOTICE 'op_leak => %, %', $1, $2; RETURN $1 < $2; END$$; create operator <<< ( procedure = op_leak, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_80.snap index 13d5b19db..e181e3263 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__stats_ext_80.snap @@ -3646,7 +3646,7 @@ where create function op_leak(int, int) returns bool language plpgsql -as 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'; +as $$BEGIN RAISE NOTICE 'op_leak => %, %', $1, $2; RETURN $1 < $2; END$$; create operator <<< ( procedure = op_leak, @@ -3658,7 +3658,7 @@ create operator <<< ( create function op_leak(record, record) returns bool language plpgsql -as 'BEGIN RAISE NOTICE ''op_leak => %, %'', $1, $2; RETURN $1 < $2; END'; +as $$BEGIN RAISE NOTICE 'op_leak => %, %', $1, $2; RETURN $1 < $2; END$$; create operator <<< ( procedure = op_leak, diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_100.snap index 454ccb459..08e27cb57 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_100.snap @@ -673,7 +673,7 @@ begin; create function bogus_int8_text_eq(int8, text) returns boolean language sql -as 'select $1::text = $2'; +as $$select $1::text = $2$$; create operator = (procedure = bogus_int8_text_eq, leftarg = int8, rightarg = text); @@ -684,7 +684,7 @@ select * from int8_tbl where q1 in (select c1 from inner_text); create or replace function bogus_int8_text_eq(int8, text) returns boolean language sql -as 'select $1::text = $2 and $1::text = $2'; +as $$select $1::text = $2 and $1::text = $2$$; select * from int8_tbl where q1 in (select c1 from inner_text); @@ -693,7 +693,7 @@ select * from int8_tbl where q1 in (select c1 from inner_text); create or replace function bogus_int8_text_eq(int8, text) returns boolean language sql -as 'select $2 = $1::text'; +as $$select $2 = $1::text$$; select * from int8_tbl where q1 in (select c1 from inner_text); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap index bf7516c04..b2e91f0fb 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__subselect_80.snap @@ -827,7 +827,7 @@ begin; create function bogus_int8_text_eq(int8, text) returns boolean language sql -as 'select $1::text = $2'; +as $$select $1::text = $2$$; create operator = ( procedure = bogus_int8_text_eq, @@ -842,7 +842,7 @@ select * from int8_tbl where q1 in (select c1 from inner_text); create or replace function bogus_int8_text_eq(int8, text) returns boolean language sql -as 'select $1::text = $2 and $1::text = $2'; +as $$select $1::text = $2 and $1::text = $2$$; select * from int8_tbl where q1 in (select c1 from inner_text); @@ -851,7 +851,7 @@ select * from int8_tbl where q1 in (select c1 from inner_text); create or replace function bogus_int8_text_eq(int8, text) returns boolean language sql -as 'select $2 = $1::text'; +as $$select $2 = $1::text$$; select * from int8_tbl where q1 in (select c1 from inner_text); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_100.snap index 905d98210..70deaae2e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_100.snap @@ -350,7 +350,7 @@ select pg_relation_size('test_temp') / cast(current_setting('block_size') as int create function test_temp_pin(p_start int, p_end int) returns void language plpgsql -as $f$ +as $$ DECLARE cursorname text; query text; @@ -364,7 +364,7 @@ as $f$ -- RAISE NOTICE '%: %', cursorname, query; END LOOP; END; -$f$; +$$; begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_80.snap index 2f210b72b..6c499ef84 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__temp_80.snap @@ -363,7 +363,7 @@ select create function test_temp_pin(p_start int, p_end int) returns void language plpgsql -as $f$ +as $$ DECLARE cursorname text; query text; @@ -377,7 +377,7 @@ as $f$ -- RAISE NOTICE '%: %', cursorname, query; END LOOP; END; -$f$; +$$; begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_100.snap index f31005214..82f5e1c5e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_100.snap @@ -59,7 +59,7 @@ create function errfunc() returns int language sql set transaction_read_only = 'on' -as 'SELECT 1'; +as $$SELECT 1$$; create table writetest (a int); @@ -469,7 +469,7 @@ create or replace function max_xacttest() returns smallint language sql stable -as 'select max(a) from xacttest'; +as $$select max(a) from xacttest$$; begin; @@ -483,7 +483,7 @@ create or replace function max_xacttest() returns smallint language sql volatile -as 'select max(a) from xacttest'; +as $$select max(a) from xacttest$$; begin; @@ -497,7 +497,7 @@ create or replace function max_xacttest() returns smallint language plpgsql stable -as 'begin return max(a) from xacttest; end'; +as $$begin return max(a) from xacttest; end$$; begin; @@ -511,7 +511,7 @@ create or replace function max_xacttest() returns smallint language plpgsql volatile -as 'begin return max(a) from xacttest; end'; +as $$begin return max(a) from xacttest; end$$; begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_80.snap index 47053da0e..5d0d9ab1d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__transactions_80.snap @@ -60,7 +60,7 @@ create function errfunc() returns int language sql set transaction_read_only = 'on' -as 'SELECT 1'; +as $$SELECT 1$$; create table writetest (a int); @@ -492,7 +492,7 @@ create or replace function max_xacttest() returns smallint language sql stable -as 'select max(a) from xacttest'; +as $$select max(a) from xacttest$$; begin; @@ -506,7 +506,7 @@ create or replace function max_xacttest() returns smallint language sql volatile -as 'select max(a) from xacttest'; +as $$select max(a) from xacttest$$; begin; @@ -520,7 +520,7 @@ create or replace function max_xacttest() returns smallint language plpgsql stable -as 'begin return max(a) from xacttest; end'; +as $$begin return max(a) from xacttest; end$$; begin; @@ -534,7 +534,7 @@ create or replace function max_xacttest() returns smallint language plpgsql volatile -as 'begin return max(a) from xacttest; end'; +as $$begin return max(a) from xacttest; end$$; begin; diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_100.snap index 670c10b77..b6ec2b0d7 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_100.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/triggers.sql create function trigger_return_old() returns trigger language c -as 'regresslib'; +as $$regresslib$$; create table trigtest ( f1 int, @@ -133,11 +133,11 @@ create table main_table ( create function trigger_func() returns trigger language plpgsql -as ' +as $$ BEGIN - RAISE NOTICE ''trigger_func(%) called: action = %, when = %, level = %'', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL; + RAISE NOTICE 'trigger_func(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL; RETURN NULL; -END;'; +END;$$; create trigger before_ins_stmt_trig before insert @@ -1107,7 +1107,7 @@ select count(*) from european_city_view; create function no_op_trig_fn() returns trigger language plpgsql -as 'begin RETURN NULL; end'; +as $$begin RETURN NULL; end$$; create trigger no_op_trig instead of insert or delete or update diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_80.snap index 8316b43c9..544726cb1 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__triggers_80.snap @@ -5,7 +5,7 @@ input_file: crates/pgls_pretty_print/tests/data/multi/triggers.sql create function trigger_return_old() returns trigger language c -as 'regresslib'; +as $$regresslib$$; create table trigtest ( f1 int, @@ -135,11 +135,11 @@ create table main_table ( create function trigger_func() returns trigger language plpgsql -as ' +as $$ BEGIN - RAISE NOTICE ''trigger_func(%) called: action = %, when = %, level = %'', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL; + RAISE NOTICE 'trigger_func(%) called: action = %, when = %, level = %', TG_ARGV[0], TG_OP, TG_WHEN, TG_LEVEL; RETURN NULL; -END;'; +END;$$; create trigger before_ins_stmt_trig before insert @@ -1139,7 +1139,7 @@ select count(*) from european_city_view; create function no_op_trig_fn() returns trigger language plpgsql -as 'begin RETURN NULL; end'; +as $$begin RETURN NULL; end$$; create trigger no_op_trig instead of insert or delete or update diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_100.snap index 013a31fd6..bd6546157 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_100.snap @@ -89,13 +89,13 @@ create function do_analyze() returns void language sql volatile -as 'ANALYZE pg_am'; +as $$ANALYZE pg_am$$; create function wrap_do_analyze(c int) returns int language sql immutable -as 'SELECT $1 FROM public.do_analyze()'; +as $$SELECT $1 FROM public.do_analyze()$$; create index on vaccluster using btree ((wrap_do_analyze(i))); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_80.snap index 6cf2c8388..b4ab2e282 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__vacuum_80.snap @@ -89,13 +89,13 @@ create function do_analyze() returns void language sql volatile -as 'ANALYZE pg_am'; +as $$ANALYZE pg_am$$; create function wrap_do_analyze(c int) returns int language sql immutable -as 'SELECT $1 FROM public.do_analyze()'; +as $$SELECT $1 FROM public.do_analyze()$$; create index on vaccluster using btree ((wrap_do_analyze(i))); diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_100.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_100.snap index 750007808..95ec44041 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_100.snap @@ -3365,7 +3365,7 @@ language internal window immutable strict -as 'window_nth_value'; +as $$window_nth_value$$; select nth_value_def(n := 2, val := ten) over (partition by four), diff --git a/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_80.snap b/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_80.snap index 2529f3c81..99eb788d0 100644 --- a/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/multi/tests__window_80.snap @@ -3955,7 +3955,7 @@ language internal window immutable strict -as 'window_nth_value'; +as $$window_nth_value$$; select nth_value_def(n := 2, val := ten) over (partition by four), diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_100.snap index 27db8ffc7..d0275b50d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_100.snap @@ -5,4 +5,4 @@ input_file: crates/pgls_pretty_print/tests/data/single/create_function_stmt_0.sq create function add(a int, b int) returns int language sql -as 'SELECT $1 + $2'; +as $$SELECT $1 + $2$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_80.snap index 27db8ffc7..d0275b50d 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_0_80.snap @@ -5,4 +5,4 @@ input_file: crates/pgls_pretty_print/tests/data/single/create_function_stmt_0.sq create function add(a int, b int) returns int language sql -as 'SELECT $1 + $2'; +as $$SELECT $1 + $2$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_100.snap index 2c931195c..b34d7cbf5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_100.snap @@ -7,4 +7,4 @@ create function public.sql_func_with_transform(int) returns int language sql transform for type int, for type text -as 'select $1 + 1'; +as $$select $1 + 1$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_80.snap index 2c931195c..b34d7cbf5 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__create_function_stmt_2_80.snap @@ -7,4 +7,4 @@ create function public.sql_func_with_transform(int) returns int language sql transform for type int, for type text -as 'select $1 + 1'; +as $$select $1 + 1$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_100.snap index 1fd170532..932a39c8e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_100.snap @@ -2,4 +2,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/do_stmt_0.sql --- -do language plpgsql 'BEGIN NULL; END'; +do language plpgsql $$BEGIN NULL; END$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_80.snap index 1fd170532..932a39c8e 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__do_stmt_0_80.snap @@ -2,4 +2,4 @@ source: crates/pgls_pretty_print/tests/tests.rs input_file: crates/pgls_pretty_print/tests/data/single/do_stmt_0.sql --- -do language plpgsql 'BEGIN NULL; END'; +do language plpgsql $$BEGIN NULL; END$$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_100.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_100.snap index 39565e7d4..8071aff01 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_100.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_100.snap @@ -6,8 +6,8 @@ snapshot_kind: text create function test_conflict() returns void language plpgsql -as $outer$ +as $body$ BEGIN EXECUTE $$SELECT 1$$; END; -$outer$; +$body$; diff --git a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_80.snap b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_80.snap index 39565e7d4..8071aff01 100644 --- a/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_80.snap +++ b/crates/pgls_pretty_print/tests/snapshots/single/tests__nested_dollar_quotes_conflict_0_80.snap @@ -6,8 +6,8 @@ snapshot_kind: text create function test_conflict() returns void language plpgsql -as $outer$ +as $body$ BEGIN EXECUTE $$SELECT 1$$; END; -$outer$; +$body$; diff --git a/crates/pgls_pretty_print/tests/source_fidelity.rs b/crates/pgls_pretty_print/tests/source_fidelity.rs index a2468a0fc..32c79c414 100644 --- a/crates/pgls_pretty_print/tests/source_fidelity.rs +++ b/crates/pgls_pretty_print/tests/source_fidelity.rs @@ -63,7 +63,7 @@ fn function_names_keep_their_case_and_quotes() { } #[test] -fn dollar_quote_tag_and_body_are_kept() { +fn function_bodies_are_kept_byte_for_byte() { assert_eq!( format( r#"CREATE OR REPLACE FUNCTION "public"."reset_user_password"("p_user_id" "uuid", "p_password" "text") RETURNS boolean @@ -89,30 +89,34 @@ $$;" } #[test] -fn a_custom_dollar_quote_tag_and_a_single_line_body_are_kept() { +fn every_body_is_dollar_quoted_the_same_way() { assert_eq!( format( - "CREATE FUNCTION f() RETURNS int LANGUAGE plpgsql AS $body$ begin return 1; end $body$" + "CREATE FUNCTION f() RETURNS int LANGUAGE plpgsql AS $function$ begin return 1; end $function$" ), "create function f() returns int language plpgsql -as $body$ begin return 1; end $body$;" +as $$ begin return 1; end $$;" + ); + assert_eq!( + format("CREATE FUNCTION f() RETURNS text LANGUAGE sql AS 'SELECT ''a''::text'"), + "create function f() +returns text +language sql +as $$SELECT 'a'::text$$;" ); assert_eq!( format("DO $do$ BEGIN PERFORM 1; END $do$"), - "do $do$ BEGIN PERFORM 1; END $do$;" + "do $$ BEGIN PERFORM 1; END $$;" ); } #[test] -fn a_quoted_body_keeps_its_quotes() { +fn a_body_containing_the_default_tag_gets_another_one() { assert_eq!( - format("CREATE FUNCTION f() RETURNS int LANGUAGE sql AS 'SELECT ''a''::text'"), - "create function f() -returns int -language sql -as 'SELECT ''a''::text';" + format("DO $outer$ BEGIN EXECUTE $$SELECT 1$$; END $outer$"), + "do $body$ BEGIN EXECUTE $$SELECT 1$$; END $body$;" ); } diff --git a/crates/pgls_pretty_print/tests/tests.rs b/crates/pgls_pretty_print/tests/tests.rs index cc7a34d02..c2cd8105d 100644 --- a/crates/pgls_pretty_print/tests/tests.rs +++ b/crates/pgls_pretty_print/tests/tests.rs @@ -153,7 +153,7 @@ fn test_single(fixture: Fixture<&str>) { // The emitter gets the fixture config, not the default one: an option that decides which // tokens exist is read here, before the renderer ever sees the events. - let mut emitter = EventEmitter::new(fixture_config.clone()).with_source(&content); + let mut emitter = EventEmitter::new(fixture_config.clone()); emit_node_enum(&ast, &mut emitter); let mut output = String::new(); @@ -242,7 +242,7 @@ fn test_multi(fixture: Fixture<&str>) { // The emitter gets the fixture config, not the default one: an option that decides // which tokens exist is read here, before the renderer ever sees the events. - let mut emitter = EventEmitter::new(fixture_config.clone()).with_source(trimmed); + let mut emitter = EventEmitter::new(fixture_config.clone()); emit_node_enum(&ast, &mut emitter); let mut output = String::new(); diff --git a/crates/pgls_workspace/src/workspace/server.tests.rs b/crates/pgls_workspace/src/workspace/server.tests.rs index be11f5d9c..87f26e279 100644 --- a/crates/pgls_workspace/src/workspace/server.tests.rs +++ b/crates/pgls_workspace/src/workspace/server.tests.rs @@ -1244,7 +1244,7 @@ async fn test_format_keeps_statements_on_one_line_apart() { } #[tokio::test] -async fn test_format_keeps_plpgsql_body_and_dollar_quote_tag() { +async fn test_format_keeps_plpgsql_body() { let content = "CREATE FUNCTION f() RETURNS boolean LANGUAGE plpgsql AS $$\nBEGIN\n RETURN true;\nEND\n$$;"; let formatted = format_content(content); assert_eq!( @@ -1259,7 +1259,7 @@ async fn test_format_keeps_formatted_sql_function_body_as_written() { let formatted = format_content(content); assert_eq!( formatted, - "create function f()\nreturns int\nlanguage sql\nas $body$\n select 1;\n$body$;" + "create function f()\nreturns int\nlanguage sql\nas $$\n select 1;\n$$;" ); } @@ -1269,7 +1269,7 @@ async fn test_format_puts_reformatted_sql_function_body_on_its_own_lines() { let formatted = format_content(content); assert_eq!( formatted, - "create function f()\nreturns int\nlanguage sql\nas $body$\nselect 1;\n$body$;" + "create function f()\nreturns int\nlanguage sql\nas $$\nselect 1;\n$$;" ); assert_eq!(format_content(&formatted), formatted); } diff --git a/docs/features/formatting.md b/docs/features/formatting.md index 7d30242c2..ef9cd6b3b 100644 --- a/docs/features/formatting.md +++ b/docs/features/formatting.md @@ -9,7 +9,8 @@ The language server provides SQL formatting that produces consistent, readable c The formatter changes whitespace, line breaks, the case of keywords, types and constants, and quotes that an identifier does not need. It does not change what is written: - Schema qualifiers stay as written, `pg_catalog.` included. -- Function bodies, their dollar-quote tags (`$$`, `$body$`, ...) and string literals are kept byte for byte. Only `language sql` bodies are reformatted, unless `skipFnBodies` is set. +- Function and `DO` bodies are kept byte for byte, and always dollar-quoted with `$$` (or `$body$` when the body contains `$$`), whatever quotes they were written with. Only `language sql` bodies are reformatted, unless `skipFnBodies` is set. +- String literals are kept as written. - Function signatures keep their argument names and modes, in `ALTER FUNCTION`, `GRANT` and `DROP` as well. - Identifiers that need quotes keep them: mixed case, reserved words such as `"user"`, and special characters. - Comments stay where they were written, including comments at the end of a line.