diff --git a/PLAN.md b/PLAN.md index c2f6d222..1f535bb3 100644 --- a/PLAN.md +++ b/PLAN.md @@ -704,8 +704,6 @@ name: nullable varchar(255) The name of the user in the system. ``` -- https://r.ena.to/blog/optimizing-postgres-table-layout-for-maximum-efficiency/ - rust analyzer gives: ``` @@ -714,13 +712,21 @@ Error { pub(crate) msg: String, } size = 24 (0x18), align = 0x8, needs Drop ``` -does alignment make sense to have with postgres? +other fields? + +- alignment + + - https://r.ena.to/blog/optimizing-postgres-table-layout-for-maximum-efficiency/ + +- common values and distribution + + - https://observablehq.com/documentation/cells/data-table#data-table-cell -maybe have common values and distribution somehow? +- index size on hover -show index size on hover too? + - https://www.peterbe.com/plog/index-size-postgresql -- https://www.peterbe.com/plog/index-size-postgresql +- data staleness -- if you have a daily batch job to calculate data, we could expose the staleness date #### Table diff --git a/crates/squawk_parser/src/grammar.rs b/crates/squawk_parser/src/grammar.rs index 263a9864..e431fb10 100644 --- a/crates/squawk_parser/src/grammar.rs +++ b/crates/squawk_parser/src/grammar.rs @@ -1814,6 +1814,7 @@ fn arg_expr(p: &mut Parser<'_>) -> Option { p.eat(VARIADIC_KW); let r = Restrictions { order_by_allowed: true, + as_allowed: true, ..Restrictions::default() }; expr_bp(p, 1, &r) @@ -2300,6 +2301,7 @@ fn current_op(p: &Parser<'_>, r: &Restrictions) -> (u8, SyntaxKind, Associativit PERCENT if p.next_not_joined_op(0) => (9, PERCENT, Left), // symbol // and AND_KW if !r.and_disabled => (2, AND_KW, Left), + AS_KW if r.as_allowed => (7, AS_KW, Left), // / SLASH if p.next_not_joined_op(0) => (9, SLASH, Left), // symbol // * @@ -2326,6 +2328,7 @@ const OVERLAPPING_TOKENS: TokenSet = TokenSet::new(&[OR_KW, AND_KW, IS_KW, COLLA #[derive(Default)] struct Restrictions { order_by_allowed: bool, + as_allowed: bool, in_disabled: bool, is_disabled: bool, not_disabled: bool, @@ -2383,7 +2386,7 @@ fn expr_bp(p: &mut Parser<'_>, bp: u8, r: &Restrictions) -> Option) { ast::PrefixExpr(it) => validate_prefix_expr(it, errors), ast::ArrayExpr(it) => validate_array_expr(it, errors), ast::DropAggregate(it) => validate_drop_aggregate(it, errors), + ast::CallExpr(it) => validate_call_expr(it, errors), ast::JoinExpr(it) => validate_join_expr(it, errors), ast::Literal(it) => validate_literal(it, errors), ast::NonStandardParam(it) => validate_non_standard_param(it, errors), @@ -27,6 +28,20 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec) { } } +fn validate_call_expr(it: ast::CallExpr, acc: &mut Vec) { + let Some(arg_list) = it.arg_list() else { + return; + }; + for arg in arg_list.args() { + if let ast::Expr::CastExpr(cast_expr) = &arg { + acc.push(SyntaxError::new( + "Invalid cast. Use `cast`, `treat`, or `::` instead.", + cast_expr.syntax().text_range(), + )); + } + } +} + fn validate_create_table(it: ast::CreateTable, acc: &mut Vec) { let Some(arg_list) = it.table_arg_list() else { return; diff --git a/crates/squawk_syntax/test_data/validation/call_expr.sql b/crates/squawk_syntax/test_data/validation/call_expr.sql new file mode 100644 index 00000000..6b60386e --- /dev/null +++ b/crates/squawk_syntax/test_data/validation/call_expr.sql @@ -0,0 +1,2 @@ +-- Trino/Snowflake/Databricks extension that Postgres doesn't support +select try_cast(x as int);