|
28 | 28 | import uuid |
29 | 29 |
|
30 | 30 | from edb import buildmeta |
| 31 | +from edb.common import typeutils |
31 | 32 | from edb.common import uuidgen |
32 | 33 | from edb.schema import casts as s_casts |
33 | 34 | from edb.schema import constraints as s_constr |
@@ -609,3 +610,180 @@ def get_sql_value_function_op(op: pgast.SQLValueFunctionOP) -> str: |
609 | 610 | OP.CURRENT_SCHEMA: "current_schema", |
610 | 611 | } |
611 | 612 | return NAMES[op] |
| 613 | + |
| 614 | + |
| 615 | +# Settings that are enums or bools and should not be quoted. |
| 616 | +# Can be retrived from PostgreSQL with: |
| 617 | +# SELECt name FROM pg_catalog.pg_settings WHERE vartype IN ('enum', 'bool'); |
| 618 | +ENUM_SETTINGS = { |
| 619 | + 'allow_alter_system', |
| 620 | + 'allow_in_place_tablespaces', |
| 621 | + 'allow_system_table_mods', |
| 622 | + 'archive_mode', |
| 623 | + 'array_nulls', |
| 624 | + 'autovacuum', |
| 625 | + 'backslash_quote', |
| 626 | + 'bytea_output', |
| 627 | + 'check_function_bodies', |
| 628 | + 'client_min_messages', |
| 629 | + 'compute_query_id', |
| 630 | + 'constraint_exclusion', |
| 631 | + 'data_checksums', |
| 632 | + 'data_sync_retry', |
| 633 | + 'debug_assertions', |
| 634 | + 'debug_logical_replication_streaming', |
| 635 | + 'debug_parallel_query', |
| 636 | + 'debug_pretty_print', |
| 637 | + 'debug_print_parse', |
| 638 | + 'debug_print_plan', |
| 639 | + 'debug_print_rewritten', |
| 640 | + 'default_toast_compression', |
| 641 | + 'default_transaction_deferrable', |
| 642 | + 'default_transaction_isolation', |
| 643 | + 'default_transaction_read_only', |
| 644 | + 'dynamic_shared_memory_type', |
| 645 | + 'edb_stat_statements.save', |
| 646 | + 'edb_stat_statements.track', |
| 647 | + 'edb_stat_statements.track_planning', |
| 648 | + 'edb_stat_statements.track_utility', |
| 649 | + 'enable_async_append', |
| 650 | + 'enable_bitmapscan', |
| 651 | + 'enable_gathermerge', |
| 652 | + 'enable_group_by_reordering', |
| 653 | + 'enable_hashagg', |
| 654 | + 'enable_hashjoin', |
| 655 | + 'enable_incremental_sort', |
| 656 | + 'enable_indexonlyscan', |
| 657 | + 'enable_indexscan', |
| 658 | + 'enable_material', |
| 659 | + 'enable_memoize', |
| 660 | + 'enable_mergejoin', |
| 661 | + 'enable_nestloop', |
| 662 | + 'enable_parallel_append', |
| 663 | + 'enable_parallel_hash', |
| 664 | + 'enable_partition_pruning', |
| 665 | + 'enable_partitionwise_aggregate', |
| 666 | + 'enable_partitionwise_join', |
| 667 | + 'enable_presorted_aggregate', |
| 668 | + 'enable_seqscan', |
| 669 | + 'enable_sort', |
| 670 | + 'enable_tidscan', |
| 671 | + 'escape_string_warning', |
| 672 | + 'event_triggers', |
| 673 | + 'exit_on_error', |
| 674 | + 'fsync', |
| 675 | + 'full_page_writes', |
| 676 | + 'geqo', |
| 677 | + 'gss_accept_delegation', |
| 678 | + 'hot_standby', |
| 679 | + 'hot_standby_feedback', |
| 680 | + 'huge_pages', |
| 681 | + 'huge_pages_status', |
| 682 | + 'icu_validation_level', |
| 683 | + 'ignore_checksum_failure', |
| 684 | + 'ignore_invalid_pages', |
| 685 | + 'ignore_system_indexes', |
| 686 | + 'in_hot_standby', |
| 687 | + 'integer_datetimes', |
| 688 | + 'intervalstyle', |
| 689 | + 'jit', |
| 690 | + 'jit_debugging_support', |
| 691 | + 'jit_dump_bitcode', |
| 692 | + 'jit_expressions', |
| 693 | + 'jit_profiling_support', |
| 694 | + 'jit_tuple_deforming', |
| 695 | + 'krb_caseins_users', |
| 696 | + 'lo_compat_privileges', |
| 697 | + 'log_checkpoints', |
| 698 | + 'log_connections', |
| 699 | + 'log_disconnections', |
| 700 | + 'log_duration', |
| 701 | + 'log_error_verbosity', |
| 702 | + 'log_executor_stats', |
| 703 | + 'log_hostname', |
| 704 | + 'log_lock_waits', |
| 705 | + 'log_min_error_statement', |
| 706 | + 'log_min_messages', |
| 707 | + 'log_parser_stats', |
| 708 | + 'log_planner_stats', |
| 709 | + 'log_recovery_conflict_waits', |
| 710 | + 'log_replication_commands', |
| 711 | + 'log_statement', |
| 712 | + 'log_statement_stats', |
| 713 | + 'log_truncate_on_rotation', |
| 714 | + 'logging_collector', |
| 715 | + 'parallel_leader_participation', |
| 716 | + 'password_encryption', |
| 717 | + 'plan_cache_mode', |
| 718 | + 'quote_all_identifiers', |
| 719 | + 'recovery_init_sync_method', |
| 720 | + 'recovery_prefetch', |
| 721 | + 'recovery_target_action', |
| 722 | + 'recovery_target_inclusive', |
| 723 | + 'remove_temp_files_after_crash', |
| 724 | + 'restart_after_crash', |
| 725 | + 'row_security', |
| 726 | + 'send_abort_for_crash', |
| 727 | + 'send_abort_for_kill', |
| 728 | + 'session_replication_role', |
| 729 | + 'shared_memory_type', |
| 730 | + 'ssl', |
| 731 | + 'ssl_max_protocol_version', |
| 732 | + 'ssl_min_protocol_version', |
| 733 | + 'ssl_passphrase_command_supports_reload', |
| 734 | + 'ssl_prefer_server_ciphers', |
| 735 | + 'standard_conforming_strings', |
| 736 | + 'stats_fetch_consistency', |
| 737 | + 'summarize_wal', |
| 738 | + 'sync_replication_slots', |
| 739 | + 'synchronize_seqscans', |
| 740 | + 'synchronous_commit', |
| 741 | + 'syslog_facility', |
| 742 | + 'syslog_sequence_numbers', |
| 743 | + 'syslog_split_messages', |
| 744 | + 'trace_connection_negotiation', |
| 745 | + 'trace_notify', |
| 746 | + 'trace_sort', |
| 747 | + 'track_activities', |
| 748 | + 'track_commit_timestamp', |
| 749 | + 'track_counts', |
| 750 | + 'track_functions', |
| 751 | + 'track_io_timing', |
| 752 | + 'track_wal_io_timing', |
| 753 | + 'transaction_deferrable', |
| 754 | + 'transaction_isolation', |
| 755 | + 'transaction_read_only', |
| 756 | + 'transform_null_equals', |
| 757 | + 'update_process_title', |
| 758 | + 'wal_compression', |
| 759 | + 'wal_init_zero', |
| 760 | + 'wal_level', |
| 761 | + 'wal_log_hints', |
| 762 | + 'wal_receiver_create_temp_slot', |
| 763 | + 'wal_recycle', |
| 764 | + 'wal_sync_method', |
| 765 | + 'xmlbinary', |
| 766 | + 'xmloption', |
| 767 | + 'zero_damaged_pages', |
| 768 | +} |
| 769 | + |
| 770 | + |
| 771 | +def setting_to_sql(name, setting): |
| 772 | + is_enum = name.lower() in ENUM_SETTINGS |
| 773 | + |
| 774 | + assert typeutils.is_container(setting) |
| 775 | + return ', '.join(setting_val_to_sql(v, is_enum) for v in setting) |
| 776 | + |
| 777 | + |
| 778 | +def setting_val_to_sql(val: str | int | float, is_enum: bool): |
| 779 | + if isinstance(val, str): |
| 780 | + if is_enum: |
| 781 | + # special case: no quoting |
| 782 | + return val |
| 783 | + # quote as identifier |
| 784 | + return quote_ident(val) |
| 785 | + if isinstance(val, int): |
| 786 | + return str(val) |
| 787 | + if isinstance(val, float): |
| 788 | + return str(val) |
| 789 | + raise NotImplementedError('cannot convert setting to SQL: ', val) |
0 commit comments