Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,31 @@ select (x * 2) + 4;

related: https://eslint.style/rules/no-extra-parens

### Rule: no-constant-condition

```sql
select a from t where false = true;
-- ^^^^^^^^^^^^ constant condition

select case when 1 = 2 then 2 else 3 end;
-- ^^^^^ constant condition
```

related: https://eslint.org/docs/latest/rules/no-constant-condition

### Rule: with query missing returning clause

```sql
create table t(a int, b int);
create table u(a int, b int);
with x as (merge into t
using u on true
when matched then do nothing)
select * from x;
-- Query 1 ERROR at Line 19: : ERROR: WITH query "x" does not have a RETURNING clause
-- LINE 6: select * from x;
```

### Rule: dialect: now() to dest

should support various fixes so people can write in one dialect of SQL and have it easily convert to the other one
Expand Down
4 changes: 4 additions & 0 deletions crates/squawk_ide/src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub(crate) enum NameRefClass {
ReindexSchema,
ReindexDatabase,
ReindexSystem,
AttachPartition,
}

pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass> {
Expand Down Expand Up @@ -335,6 +336,9 @@ pub(crate) fn classify_name_ref(name_ref: &ast::NameRef) -> Option<NameRefClass>
if ast::AlterTable::can_cast(ancestor.kind()) {
return Some(NameRefClass::AlterTable);
}
if ast::AttachPartition::can_cast(ancestor.kind()) {
return Some(NameRefClass::AttachPartition);
}
if ast::Refresh::can_cast(ancestor.kind()) {
return Some(NameRefClass::RefreshMaterializedView);
}
Expand Down
184 changes: 184 additions & 0 deletions crates/squawk_ide/src/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,58 @@ create table t_2026_01_02 partition of t$0
");
}

#[test]
fn goto_table_partition_of_cycle() {
goto_not_found(
"
create table part1 partition of part2
for values from ('2026-01-02') to ('2026-01-03');
create table part2 partition of part1
for values from ('2026-01-02') to ('2026-01-03');
select a$0 from part2;
",
);
}

#[test]
fn goto_partition_table_column() {
assert_snapshot!(goto("
create table part (
a int,
inserted_at timestamptz not null default now()
) partition by range (inserted_at);
create table part_2026_01_02 partition of part
for values from ('2026-01-02') to ('2026-01-03');
select a$0 from part_2026_01_02;
"), @r"
╭▸
3 │ a int,
│ ─ 2. destination
8 │ select a from part_2026_01_02;
╰╴ ─ 1. source
");
}

#[test]
fn goto_alter_index_attach_partition() {
assert_snapshot!(goto("
create table t (
inserted_at timestamptz not null default now()
) partition by range (inserted_at);
create table part partition of t
for values from ('2026-01-02') to ('2026-01-03');
alter index t attach partition part$0;
"), @r"
╭▸
5 │ create table part partition of t
│ ──── 2. destination
6 │ for values from ('2026-01-02') to ('2026-01-03');
7 │ alter index t attach partition part;
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_table_like_clause() {
assert_snapshot!(goto("
Expand Down Expand Up @@ -1000,6 +1052,138 @@ inherits (foo.bar, bar$0, buzz);
");
}

#[test]
fn goto_create_table_like_clause_columns() {
assert_snapshot!(goto("
create table t(a int, b int);
create table u(like t, c int);
select a$0, c from u;
"), @r"
╭▸
2 │ create table t(a int, b int);
│ ─ 2. destination
3 │ create table u(like t, c int);
4 │ select a, c from u;
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_table_like_clause_local_column() {
assert_snapshot!(goto("
create table t(a int, b int);
create table u(like t, c int);
select a, c$0 from u;
"), @r"
╭▸
3 │ create table u(like t, c int);
│ ─ 2. destination
4 │ select a, c from u;
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_table_like_clause_multi() {
assert_snapshot!(goto("
create table t(a int, b int);
create table u(x int, y int);
create table k(like t, like u, c int);
select y$0 from k;
"), @r"
╭▸
3 │ create table u(x int, y int);
│ ─ 2. destination
4 │ create table k(like t, like u, c int);
5 │ select y from k;
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_table_inherits_column() {
assert_snapshot!(goto("
create table t (
a int, b text
);
create table u (
c int
) inherits (t);
select a$0 from u;
"), @r"
╭▸
3 │ a int, b text
│ ─ 2. destination
8 │ select a from u;
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_table_inherits_local_column() {
assert_snapshot!(goto("
create table t (
a int, b text
);
create table u (
c int
) inherits (t);
select c$0 from u;
"), @r"
╭▸
6 │ c int
│ ─ 2. destination
7 │ ) inherits (t);
8 │ select c from u;
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_table_inherits_multiple_parents() {
assert_snapshot!(goto("
create table t1 (
a int
);
create table t2 (
b text
);
create table u (
c int
) inherits (t1, t2);
select b$0 from u;
"), @r"
╭▸
6 │ b text
│ ─ 2. destination
11 │ select b from u;
╰╴ ─ 1. source
");
}

#[test]
fn goto_create_foreign_table_inherits_column() {
assert_snapshot!(goto("
create server myserver foreign data wrapper postgres_fdw;
create table t (
a int, b text
);
create foreign table u (
c int
) inherits (t) server myserver;
select a$0 from u;
"), @r"
╭▸
4 │ a int, b text
│ ─ 2. destination
9 │ select a from u;
╰╴ ─ 1. source
");
}

#[test]
fn goto_drop_temp_table_shadows_public() {
// temp tables shadow public tables when no schema is specified
Expand Down
Loading
Loading