use super::keyword::{
POSTGRES_AS_LABEL_KEYWORDS, POSTGRES_COL_NAME_KEYWORDS, POSTGRES_RESERVED_KEYWORDS,
POSTGRES_TYPE_FUNC_NAME_KEYWORDS,
};
use super::{
AccessControlSyntax, AggregateCallSyntax, CallSyntax, CaretOperator, Casing,
ColumnDefinitionSyntax, CommentSyntax, ConstraintSyntax, CreateTableClauseSyntax,
DoubleAmpersand, ExistenceGuards, ExpressionSyntax, FeatureSet, GroupingSyntax,
IdentifierQuote, IdentifierSyntax, IndexAlterSyntax, JoinSyntax, Keyword, KeywordOperators,
KeywordSet, MaintenanceSyntax, MutationSyntax, NullOrdering, NumericLiteralSyntax,
OperatorSyntax, ParameterSyntax, PipeOperator, PredicateSyntax, QueryTailSyntax,
STANDARD_BYTE_CLASSES, SelectSyntax, SessionVariableSyntax, ShowSyntax, StatementDdlGates,
StringFuncForms, StringLiteralSyntax, TableExpressionSyntax, TableFactorSyntax, TargetSpelling,
TransactionSyntax, TypeNameSyntax, UtilitySyntax, ViewSequenceClauseSyntax,
};
use crate::precedence::{STANDARD_BINDING_POWERS, STANDARD_SET_OPERATION_BINDING_POWERS};
pub const STANDARD_IDENTIFIER_QUOTES: &[IdentifierQuote] = &[IdentifierQuote::Symmetric('"')];
pub const RESERVED_COLUMN_NAME: KeywordSet =
POSTGRES_TYPE_FUNC_NAME_KEYWORDS.union(POSTGRES_RESERVED_KEYWORDS);
pub const POSTGRES_NON_GENERIC_FUNCTION_KEYWORDS: KeywordSet = KeywordSet::from_keywords(&[
Keyword::Between,
Keyword::Bigint,
Keyword::Bit,
Keyword::Boolean,
Keyword::Char,
Keyword::Character,
Keyword::Dec,
Keyword::Decimal,
Keyword::Float,
Keyword::Inout,
Keyword::Int,
Keyword::Integer,
Keyword::Interval,
Keyword::JsonExists,
Keyword::JsonObjectagg,
Keyword::JsonQuery,
Keyword::JsonTable,
Keyword::JsonValue,
Keyword::MergeAction,
Keyword::National,
Keyword::Nchar,
Keyword::None,
Keyword::Numeric,
Keyword::Operator,
Keyword::Out,
Keyword::Position,
Keyword::Precision,
Keyword::Real,
Keyword::Setof,
Keyword::Smallint,
Keyword::Time,
Keyword::Timestamp,
Keyword::Treat,
Keyword::Values,
Keyword::Varchar,
Keyword::Xmlattributes,
Keyword::Xmlelement,
Keyword::Xmlexists,
Keyword::Xmlnamespaces,
Keyword::Xmlparse,
Keyword::Xmlpi,
Keyword::Xmlroot,
Keyword::Xmlserialize,
Keyword::Xmltable,
]);
pub const RESERVED_FUNCTION_NAME: KeywordSet =
POSTGRES_RESERVED_KEYWORDS.union(POSTGRES_NON_GENERIC_FUNCTION_KEYWORDS);
pub const RESERVED_SET_VALUE_WORDS: KeywordSet = POSTGRES_RESERVED_KEYWORDS;
pub const RESERVED_TYPE_NAME: KeywordSet =
POSTGRES_COL_NAME_KEYWORDS.union(POSTGRES_RESERVED_KEYWORDS);
pub const RESERVED_BARE_ALIAS: KeywordSet = POSTGRES_AS_LABEL_KEYWORDS;
impl CommentSyntax {
pub const ANSI: Self = Self {
line_comment_hash: false,
line_comment_ends_at_carriage_return: false,
nested_block_comments: true,
versioned_comments: None,
unterminated_block_comment_at_eof: false,
};
}
impl StringLiteralSyntax {
pub const ANSI: Self = Self {
escape_strings: false,
dollar_quoted_strings: false,
national_strings: false,
double_quoted_strings: false,
backslash_escapes: false,
unicode_strings: false,
bit_string_literals: false,
blob_literals: false,
charset_introducers: false,
same_line_adjacent_concat: false,
};
}
impl NumericLiteralSyntax {
pub const ANSI: Self = Self {
hex_integers: false,
octal_integers: false,
binary_integers: false,
underscore_separators: false,
radix_leading_underscore: false,
money_literals: false,
reject_trailing_junk: false,
};
}
impl ParameterSyntax {
pub const ANSI: Self = Self {
positional_dollar: false,
positional_dollar_large: false,
anonymous_question: false,
named_colon: false,
named_at: false,
named_dollar: false,
numbered_question: false,
};
}
impl SessionVariableSyntax {
pub const ANSI: Self = Self {
user_variables: false,
system_variables: false,
variable_assignment: false,
};
}
impl IdentifierSyntax {
pub const ANSI: Self = Self {
non_ascii: super::NonAsciiIdentifierSyntax::UnicodeAlphanumeric,
dollar_in_identifiers: false,
string_literal_identifiers: false,
string_literal_table_names: false,
empty_quoted_identifiers: false,
};
}
impl TableExpressionSyntax {
pub const ANSI: Self = Self {
only: false,
table_sample: false,
parenthesized_joins: true,
table_alias_column_lists: true,
join_using_alias: false,
index_hints: false,
table_hints: false,
partition_selection: false,
base_table_alias_column_lists: true,
string_literal_aliases: false,
aliased_parenthesized_join: true,
bare_table_alias_is_bare_label: false,
table_version: false,
table_json_path: false,
indexed_by: false,
prefix_colon_alias: false,
};
}
impl JoinSyntax {
pub const ANSI: Self = Self {
stacked_join_qualifiers: true,
full_outer_join: true,
natural_cross_join: false,
straight_join: false,
asof_join: false,
positional_join: false,
semi_anti_join: false,
sided_semi_anti_join: false,
apply_join: false,
recursive_search_cycle: false,
recursive_union_rejects_order_limit: false,
recursive_using_key: false,
};
}
impl TableFactorSyntax {
pub const ANSI: Self = Self {
lateral: false,
table_functions: false,
rows_from: false,
unnest: false,
unnest_with_offset: false,
table_function_ordinality: false,
special_function_table_source: true,
pivot: false,
unpivot: false,
show_ref: false,
from_values: false,
json_table: false,
xml_table: false,
table_expr_factor: false,
pivot_value_sources: false,
match_recognize: false,
open_json: false,
};
}
impl MutationSyntax {
pub const ANSI: Self = Self {
insert_ignore: false,
insert_overwrite: false,
returning: false,
on_conflict: false,
on_duplicate_key_update: false,
multi_column_assignment: false,
update_tuple_value_row_arity: false,
where_current_of: false,
merge: true,
replace_into: false,
insert_set: false,
update_delete_tails: false,
joined_update_delete: false,
or_conflict_action: false,
insert_column_matching: false,
delete_using: true,
update_from: true,
delete_using_target_alias: true,
cte_before_insert: true,
cte_before_merge: false,
data_modifying_ctes: false,
merge_when_not_matched_by: false,
merge_insert_default_values: false,
merge_insert_overriding: true,
merge_insert_multirow: false,
merge_update_set_star: false,
merge_insert_star_by_name: false,
merge_error_action: false,
update_set_qualified_column: true,
};
}
impl StatementDdlGates {
pub const ANSI: Self = Self {
colocation_groups: false,
create_trigger: false,
create_macro: false,
create_secret: false,
create_type: false,
create_virtual_table: false,
create_sequence: false,
extension_ddl: false,
transform_ddl: false,
alter_system: false,
tablespace_ddl: false,
logfile_group_ddl: false,
schemas: true,
schema_elements: false,
databases: true,
drop_database: false,
materialized_views: true,
routines: true,
or_replace: true,
create_or_replace_table: false,
compound_statements: false,
alter_database: false,
alter_database_options: false,
server_definition: false,
alter_instance: false,
spatial_reference_system: false,
resource_group: false,
alter_sequence: false,
alter_object_set_schema: false,
};
}
impl ViewSequenceClauseSyntax {
pub const ANSI: Self = Self {
materialized_view_to: false,
create_sequence_cache: false,
temporary_views: true,
recursive_views: false,
view_definition_options: false,
};
}
impl CreateTableClauseSyntax {
pub const ANSI: Self = Self {
table_options: false,
without_rowid_table_option: false,
strict_table_option: false,
storage_parameters: true,
on_commit: true,
create_table_as_with_data: true,
create_table_as_execute: false,
declarative_partitioning: false,
table_inheritance: false,
like_source_table: false,
statement_level_table_like: false,
unlogged_tables: false,
table_access_method: false,
without_oids: false,
typed_tables: false,
};
}
impl ColumnDefinitionSyntax {
pub const ANSI: Self = Self {
generated_column_shorthand: false,
column_conflict_resolution_clause: false,
typeless_column_definitions: false,
typeless_generated_columns: false,
joined_autoincrement_attribute: false,
inline_primary_key_ordering: false,
named_column_collate_constraint: false,
identity_columns: true,
compact_identity_columns: false,
default_expression_requires_parens: false,
column_default_requires_b_expr: false,
column_collation: false,
column_storage: false,
};
}
impl ConstraintSyntax {
pub const ANSI: Self = Self {
deferrable_constraints: true,
named_inline_non_check_constraints: true,
bare_constraint_name: false,
exclusion_constraints: false,
constraint_no_inherit_not_valid: false,
index_constraint_parameters: false,
constraint_column_collate_order: false,
referential_action_cascade_set: true,
check_constraint_subqueries: true,
};
}
impl IndexAlterSyntax {
pub const ANSI: Self = Self {
rename_constraint: false,
alter_table_set_options: false,
drop_primary_key: false,
alter_column_add_identity: false,
index_storage_parameters: false,
drop_behavior: true,
index_drop_on_table: false,
index_concurrently: false,
index_using_method: false,
partial_index: false,
index_if_not_exists: true,
index_nulls_order: true,
alter_table_extended: true,
alter_nested_column_paths: false,
alter_existence_guards: true,
alter_column_set_data_type: true,
routine_arg_types: true,
routine_arg_defaults: true,
routine_arg_modes: true,
routine_language_string: false,
alter_table_multiple_actions: true,
};
}
impl ExistenceGuards {
pub const ANSI: Self = Self {
if_exists: false,
view_if_not_exists: false,
create_database_if_not_exists: false,
};
}
impl SelectSyntax {
pub const ANSI: Self = Self {
distinct_on: false,
select_into: false,
empty_target_list: false,
qualify: false,
alias_string_literals: false,
bare_alias_string_literals: false,
union_by_name: false,
wildcard_modifiers: false,
wildcard_replace: false,
intersect_all: true,
except_all: true,
qualified_wildcard_alias: false,
from_first: false,
explicit_table: true,
parenthesized_query_operands: true,
values_rows_require_equal_arity: false,
values_row_constructor: true,
as_alias_rejects_reserved: false,
trailing_comma: false,
prefix_colon_alias: false,
lateral_view_clause: false,
connect_by_clause: false,
};
}
impl QueryTailSyntax {
pub const ANSI: Self = Self {
fetch_first: true,
limit_offset_comma: false,
locking_clauses: false,
key_lock_strengths: false,
stacked_locking_clauses: false,
using_sample: false,
leading_offset: true,
limit_expressions: true,
limit_percent: false,
with_ties_requires_order_by: false,
pipe_syntax: false,
limit_by_clause: false,
settings_clause: false,
format_clause: false,
for_xml_json_clause: false,
};
}
impl GroupingSyntax {
pub const ANSI: Self = Self {
grouping_sets: true,
with_rollup: false,
order_by_using: false,
group_by_all: false,
group_by_set_quantifier: false,
order_by_all: false,
};
}
impl UtilitySyntax {
pub const ANSI: Self = Self {
copy: false,
copy_into: false,
stage_references: false,
comment_on: false,
comment_if_exists: false,
pragma: false,
attach: false,
kill: false,
handler_statements: false,
plugin_component_statements: false,
shutdown: false,
restart: false,
clone: false,
import_table: false,
help_statement: false,
binlog: false,
key_cache_statements: false,
use_statement: false,
use_qualified_name: false,
use_string_literal_name: false,
prepared_statements: false,
prepare_typed_parameters: false,
prepared_statements_from: false,
call: false,
call_bare_name: false,
load_extension: false,
load_bare_name: false,
load_data: false,
reset_scope: false,
detach_if_exists: false,
do_statement: false,
do_expression_list: false,
lock_tables: false,
lock_instance: false,
rename_statement: false,
signal_diagnostics: false,
export_import_database: false,
update_extensions: false,
flush: false,
purge_binary_logs: false,
replication_statements: false,
};
}
impl TransactionSyntax {
pub const ANSI: Self = Self {
start_transaction: true,
start_transaction_block_optional: false,
transaction_work_keyword: true,
begin_transaction_keyword: true,
commit_transaction_keyword: true,
rollback_transaction_keyword: true,
transaction_name: false,
begin_transaction_modes: true,
transaction_savepoints: true,
set_transaction: true,
transaction_isolation_mode: true,
transaction_access_mode: true,
transaction_deferrable_mode: true,
start_transaction_isolation_mode: true,
start_transaction_deferrable_mode: true,
start_transaction_consistent_snapshot: false,
transaction_multiple_modes: true,
transaction_modes_require_commas: false,
transaction_modes_reject_duplicates: false,
abort_transaction_alias: false,
end_transaction_alias: false,
transaction_release: false,
transaction_chain: true,
release_savepoint_keyword_optional: true,
begin_transaction_mode: false,
xa_transactions: false,
};
}
impl ShowSyntax {
pub const ANSI: Self = Self {
describe: false,
describe_summarize: false,
session_statements: true,
set_value_reserved_words: RESERVED_SET_VALUE_WORDS,
set_value_on_keyword: true,
set_value_null_keyword: false,
show_tables: false,
show_columns: false,
show_create_table: false,
show_functions: false,
show_routine_status: false,
show_verbose: false,
show_admin: false,
};
}
impl MaintenanceSyntax {
pub const ANSI: Self = Self {
vacuum: false,
vacuum_analyze: false,
reindex: false,
analyze: false,
analyze_columns: false,
checkpoint: false,
checkpoint_database: false,
table_maintenance: false,
};
}
impl AccessControlSyntax {
pub const ANSI: Self = Self {
alter_role_rename: false,
access_control: true,
access_control_extended_objects: true,
user_role_management: false,
access_control_account_grants: false,
};
}
impl TypeNameSyntax {
pub const ANSI: Self = Self {
extended_scalar_type_names: false,
enum_type: false,
set_type: false,
numeric_modifiers: false,
integer_display_width: false,
composite_types: false,
varchar_requires_length: false,
zoned_temporal_types: true,
empty_type_parens: false,
character_set_annotation: false,
signed_type_modifier: false,
nullable_type: false,
low_cardinality_type: false,
fixed_string_type: false,
datetime64_type: false,
nested_type: false,
bit_width_integer_names: false,
liberal_type_names: false,
string_type_modifiers: false,
angle_bracket_types: false,
};
}
impl ExpressionSyntax {
pub const ANSI: Self = Self {
typecast_operator: false,
subscript: false,
slice_step: false,
collate: false,
at_time_zone: false,
semi_structured_access: false,
array_constructor: false,
multidim_array_literals: false,
collection_literals: false,
row_constructor: false,
struct_constructor: false,
field_selection: false,
field_wildcard: false,
typed_string_literals: true,
typed_interval_literal: true,
relaxed_interval_syntax: false,
mysql_interval_operator: false,
positional_column: false,
lambda_keyword: false,
};
}
impl OperatorSyntax {
pub const ANSI: Self = Self {
operator_construct: false,
containment_operators: false,
json_arrow_operators: false,
jsonb_operators: false,
double_equals: false,
integer_divide_slash: false,
starts_with_operator: false,
is_general_equality: false,
truth_value_tests: true,
null_safe_equals: false,
lambda_expressions: false,
bitwise_operators: false,
quantified_comparisons: true,
quantified_comparison_lists: false,
quantified_arbitrary_operator: false,
custom_operators: false,
null_test_postfix: false,
postfix_operators: false,
};
}
impl CallSyntax {
pub const ANSI: Self = Self {
named_argument: false,
utc_special_functions: false,
columns_expression: false,
extract_from_syntax: true,
try_cast: false,
restricted_cast_targets: false,
extract_string_field: false,
method_chaining: false,
sqljson_constructors_require_argument: false,
sqljson_expression_functions: false,
xml_expression_functions: false,
variadic_argument: false,
merge_action_function: false,
convert_function: false,
};
}
impl StringFuncForms {
pub const ANSI: Self = Self {
substring_from_for: true,
substring_leading_for: false,
substring_similar: false,
substring_plain_call_requires_2_or_3_args: false,
substr_from_for: false,
position_in: true,
position_asymmetric_operands: false,
overlay_placing: true,
overlay_requires_placing: true,
trim_from: true,
trim_list_syntax: false,
collation_for_expression: false,
ceil_to_field: false,
floor_to_field: false,
match_against: false,
};
}
impl AggregateCallSyntax {
pub const ANSI: Self = Self {
group_concat_separator: false,
within_group: true,
aggregate_filter: true,
filter_optional_where: false,
aggregate_args_require_adjacent_paren: false,
null_treatment: false,
aggregate_calls_reject_empty_arguments: false,
over_requires_windowable_function: false,
window_function_tail: false,
standalone_argument_order_by: false,
};
}
impl PredicateSyntax {
pub const ANSI: Self = Self {
is_distinct_from: true,
like: true,
ilike: false,
similar_to: false,
overlaps_period_predicate: false,
unparenthesized_in_list: false,
pattern_match_quantifier: false,
between_symmetric: false,
is_normalized: false,
empty_in_list: false,
null_test_two_word_postfix: false,
};
}
impl FeatureSet {
pub const ANSI: Self = Self {
identifier_casing: Casing::Upper,
identifier_quotes: STANDARD_IDENTIFIER_QUOTES,
default_null_ordering: NullOrdering::NullsLast,
reserved_column_name: RESERVED_COLUMN_NAME,
reserved_function_name: RESERVED_FUNCTION_NAME,
reserved_type_name: RESERVED_TYPE_NAME,
reserved_bare_alias: RESERVED_BARE_ALIAS,
reserved_as_label: KeywordSet::EMPTY,
catalog_qualified_names: true,
byte_classes: STANDARD_BYTE_CLASSES,
binding_powers: STANDARD_BINDING_POWERS,
set_operation_powers: STANDARD_SET_OPERATION_BINDING_POWERS,
string_literals: StringLiteralSyntax::ANSI,
numeric_literals: NumericLiteralSyntax::ANSI,
parameters: ParameterSyntax::ANSI,
session_variables: SessionVariableSyntax::ANSI,
identifier_syntax: IdentifierSyntax::ANSI,
table_expressions: TableExpressionSyntax::ANSI,
join_syntax: JoinSyntax::ANSI,
table_factor_syntax: TableFactorSyntax::ANSI,
expression_syntax: ExpressionSyntax::ANSI,
operator_syntax: OperatorSyntax::ANSI,
call_syntax: CallSyntax::ANSI,
string_func_forms: StringFuncForms::ANSI,
aggregate_call_syntax: AggregateCallSyntax::ANSI,
predicate_syntax: PredicateSyntax::ANSI,
pipe_operator: PipeOperator::StringConcat,
double_ampersand: DoubleAmpersand::Unsupported,
keyword_operators: KeywordOperators::Unsupported,
caret_operator: CaretOperator::Unsupported,
hash_bitwise_xor: false,
comment_syntax: CommentSyntax::ANSI,
mutation_syntax: MutationSyntax::ANSI,
statement_ddl_gates: StatementDdlGates::ANSI,
view_sequence_clause_syntax: ViewSequenceClauseSyntax::ANSI,
create_table_clause_syntax: CreateTableClauseSyntax::ANSI,
column_definition_syntax: ColumnDefinitionSyntax::ANSI,
constraint_syntax: ConstraintSyntax::ANSI,
index_alter_syntax: IndexAlterSyntax::ANSI,
existence_guards: ExistenceGuards::ANSI,
select_syntax: SelectSyntax::ANSI,
query_tail_syntax: QueryTailSyntax::ANSI,
grouping_syntax: GroupingSyntax::ANSI,
utility_syntax: UtilitySyntax::ANSI,
transaction_syntax: TransactionSyntax::ANSI,
show_syntax: ShowSyntax::ANSI,
maintenance_syntax: MaintenanceSyntax::ANSI,
access_control_syntax: AccessControlSyntax::ANSI,
type_name_syntax: TypeNameSyntax::ANSI,
target_spelling: TargetSpelling::Ansi,
};
}
pub const ANSI: FeatureSet = FeatureSet::ANSI;
const _: () = assert!(FeatureSet::ANSI.is_lexically_consistent());
const _: () = assert!(FeatureSet::ANSI.has_satisfied_feature_dependencies());
const _: () = assert!(FeatureSet::ANSI.has_no_grammar_conflict());
#[cfg(test)]
mod tests {
use super::Keyword;
use super::*;
#[test]
fn per_position_sets_are_data_driven_and_position_specific() {
assert!(RESERVED_COLUMN_NAME.contains(Keyword::Join));
assert!(!RESERVED_FUNCTION_NAME.contains(Keyword::Join));
assert!(!RESERVED_TYPE_NAME.contains(Keyword::Join));
assert!(!RESERVED_COLUMN_NAME.contains(Keyword::Coalesce));
assert!(!RESERVED_FUNCTION_NAME.contains(Keyword::Coalesce));
assert!(RESERVED_TYPE_NAME.contains(Keyword::Coalesce));
assert!(RESERVED_COLUMN_NAME.contains(Keyword::Select));
assert!(RESERVED_FUNCTION_NAME.contains(Keyword::Select));
assert!(RESERVED_TYPE_NAME.contains(Keyword::Select));
assert!(!RESERVED_BARE_ALIAS.contains(Keyword::Select));
for keyword in [Keyword::Over, Keyword::Filter] {
assert!(!RESERVED_COLUMN_NAME.contains(keyword));
assert!(!RESERVED_FUNCTION_NAME.contains(keyword));
assert!(!RESERVED_TYPE_NAME.contains(keyword));
assert!(RESERVED_BARE_ALIAS.contains(keyword));
}
}
}