1use crate::binder;
2use crate::builtins::parse_builtins;
3use crate::db::{File, parse};
4use crate::offsets::token_from_offset;
5use crate::resolve;
6use rowan::{TextRange, TextSize};
7use salsa::Database as Db;
8use smallvec::{SmallVec, smallvec};
9use squawk_syntax::{
10 SyntaxKind,
11 ast::{self, AstNode},
12};
13
14#[salsa::tracked]
15pub fn goto_definition(db: &dyn Db, file: File, offset: TextSize) -> SmallVec<[Location; 1]> {
16 let parse = parse(db, file);
17 let source_file = &parse.tree();
18 let Some(token) = token_from_offset(source_file, offset) else {
19 return smallvec![];
20 };
21 let Some(parent) = token.parent() else {
22 return smallvec![];
23 };
24
25 if (token.kind() == SyntaxKind::WHEN_KW && parent.kind() == SyntaxKind::WHEN_CLAUSE)
27 || (token.kind() == SyntaxKind::ELSE_KW && parent.kind() == SyntaxKind::ELSE_CLAUSE)
28 || (token.kind() == SyntaxKind::END_KW && parent.kind() == SyntaxKind::CASE_EXPR)
29 {
30 for parent in token.parent_ancestors() {
31 if let Some(case_expr) = ast::CaseExpr::cast(parent)
32 && let Some(case_token) = case_expr.case_token()
33 {
34 return smallvec![Location::range(case_token.text_range())];
35 }
36 }
37 }
38
39 if ast::Commit::can_cast(parent.kind())
41 && let Some(begin_range) = find_preceding_begin(source_file, token.text_range().start())
42 {
43 return smallvec![Location::range(begin_range)];
44 }
45
46 if ast::Rollback::can_cast(parent.kind())
48 && let Some(begin_range) = find_preceding_begin(source_file, token.text_range().start())
49 {
50 return smallvec![Location::range(begin_range)];
51 }
52
53 if ast::Begin::can_cast(parent.kind())
55 && let Some(end_range) =
56 find_following_commit_or_rollback(source_file, token.text_range().end())
57 {
58 return smallvec![Location::range(end_range)];
59 }
60
61 if let Some(name) = ast::Name::cast(parent.clone()) {
62 return smallvec![Location::range(name.syntax().text_range())];
63 }
64
65 if let Some(name_ref) = ast::NameRef::cast(parent.clone()) {
66 for file_id in [FileId::Current, FileId::Builtins] {
67 let file = match file_id {
68 FileId::Current => source_file,
69 FileId::Builtins => &parse_builtins(db).tree(),
70 };
71 let binder_output = binder::bind(file);
73 let root = file.syntax();
74 if let Some(ptrs) = resolve::resolve_name_ref_ptrs(&binder_output, root, &name_ref) {
75 let ranges = ptrs
76 .iter()
77 .map(|ptr| ptr.to_node(file.syntax()).text_range())
78 .map(|range| Location {
79 file: file_id,
80 range,
81 })
82 .collect();
83 return ranges;
84 }
85 }
86 }
87
88 let type_node = ast::Type::cast(parent.clone()).or_else(|| {
89 if ast::Timezone::can_cast(parent.kind()) {
91 parent.parent().and_then(ast::Type::cast)
92 } else {
93 None
94 }
95 });
96 if let Some(ty) = type_node {
97 for file_id in [FileId::Current, FileId::Builtins] {
98 let file = match file_id {
99 FileId::Current => source_file,
100 FileId::Builtins => &parse_builtins(db).tree(),
101 };
102 let binder_output = binder::bind(file);
104 let position = token.text_range().start();
105 if let Some(ptr) = resolve::resolve_type_ptr_from_type(&binder_output, &ty, position) {
106 return smallvec![Location {
107 file: file_id,
108 range: ptr.to_node(file.syntax()).text_range(),
109 }];
110 }
111 }
112 }
113
114 smallvec![]
115}
116
117#[derive(Debug, PartialEq, Clone, Copy, Eq, PartialOrd, Ord)]
118pub enum FileId {
119 Current,
120 Builtins,
121}
122
123#[derive(Debug, Clone, PartialEq, Eq)]
124pub struct Location {
125 pub file: FileId,
126 pub range: TextRange,
127}
128
129impl Location {
130 fn range(range: TextRange) -> Location {
131 Location {
132 file: FileId::Current,
133 range,
134 }
135 }
136}
137
138fn find_preceding_begin(file: &ast::SourceFile, before: TextSize) -> Option<TextRange> {
139 let mut last_begin: Option<TextRange> = None;
140 for stmt in file.stmts() {
141 if let ast::Stmt::Begin(begin) = stmt {
142 let range = begin.syntax().text_range();
143 if range.end() <= before {
144 last_begin = Some(range);
145 }
146 }
147 }
148 last_begin
149}
150
151fn find_following_commit_or_rollback(file: &ast::SourceFile, after: TextSize) -> Option<TextRange> {
152 for stmt in file.stmts() {
153 let range = match &stmt {
154 ast::Stmt::Commit(commit) => commit.syntax().text_range(),
155 ast::Stmt::Rollback(rollback) => rollback.syntax().text_range(),
156 _ => continue,
157 };
158 if range.start() >= after {
159 return Some(range);
160 }
161 }
162 None
163}
164
165#[cfg(test)]
166mod test {
167 use crate::builtins::BUILTINS_SQL;
168 use crate::db::{Database, File};
169 use crate::goto_definition::{FileId, goto_definition};
170 use crate::test_utils::fixture;
171 use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle};
172 use insta::assert_snapshot;
173 use log::info;
174 use rowan::TextRange;
175
176 #[track_caller]
177 fn goto(sql: &str) -> String {
178 goto_(sql).expect("should always find a definition")
179 }
180
181 #[track_caller]
182 fn goto_(sql: &str) -> Option<String> {
183 info!("starting");
184 let (mut offset, sql) = fixture(sql);
185 offset = offset.checked_sub(1.into()).unwrap_or_default();
188 let db = Database::default();
189 let file = File::new(&db, sql.clone().into());
190 assert_eq!(crate::db::parse(&db, file).errors(), vec![]);
191 let results = goto_definition(&db, file, offset);
192 if !results.is_empty() {
193 let offset: usize = offset.into();
194 let mut current_dests = vec![];
195 let mut builtin_dests = vec![];
196 for (i, location) in results.iter().enumerate() {
197 let label_index = i + 2;
198 match location.file {
199 FileId::Current => current_dests.push((label_index, location.range)),
200 FileId::Builtins => builtin_dests.push((label_index, location.range)),
201 }
202 }
203
204 let has_builtins = !builtin_dests.is_empty();
205
206 let mut snippet = Snippet::source(&sql).fold(true);
207 if has_builtins {
208 snippet = snippet.path("current.sql");
210 } else {
211 snippet = annotate_destinations(snippet, current_dests);
212 }
213 snippet = snippet.annotation(
214 AnnotationKind::Context
215 .span(offset..offset + 1)
216 .label("1. source"),
217 );
218
219 let mut groups = vec![Level::INFO.primary_title("definition").element(snippet)];
220
221 if has_builtins {
222 let builtins_snippet = Snippet::source(BUILTINS_SQL).path("builtin.sql").fold(true);
223 let builtins_snippet = annotate_destinations(builtins_snippet, builtin_dests);
224 groups.push(
225 Level::INFO
226 .primary_title("definition")
227 .element(builtins_snippet),
228 );
229 }
230
231 let renderer = Renderer::plain().decor_style(DecorStyle::Unicode);
232 return Some(
233 renderer
234 .render(&groups)
235 .to_string()
236 .replace("info: definition", ""),
238 );
239 }
240 None
241 }
242
243 fn goto_not_found(sql: &str) {
244 assert!(goto_(sql).is_none(), "Should not find a definition");
245 }
246
247 fn annotate_destinations<'a>(
248 mut snippet: Snippet<'a, annotate_snippets::Annotation<'a>>,
249 destinations: Vec<(usize, TextRange)>,
250 ) -> Snippet<'a, annotate_snippets::Annotation<'a>> {
251 for (label_index, range) in destinations {
252 snippet = snippet.annotation(
253 AnnotationKind::Context
254 .span(range.into())
255 .label(format!("{}. destination", label_index)),
256 );
257 }
258
259 snippet
260 }
261
262 #[test]
263 fn goto_case_when() {
264 assert_snapshot!(goto("
265select case when$0 x > 1 then 1 else 2 end;
266"), @r"
267 ╭▸
268 2 │ select case when x > 1 then 1 else 2 end;
269 │ ┬─── ─ 1. source
270 │ │
271 ╰╴ 2. destination
272 ");
273 }
274
275 #[test]
276 fn goto_case_else() {
277 assert_snapshot!(goto("
278select case when x > 1 then 1 else$0 2 end;
279"), @r"
280 ╭▸
281 2 │ select case when x > 1 then 1 else 2 end;
282 ╰╴ ──── 2. destination ─ 1. source
283 ");
284 }
285
286 #[test]
287 fn goto_case_end() {
288 assert_snapshot!(goto("
289select case when x > 1 then 1 else 2 end$0;
290"), @r"
291 ╭▸
292 2 │ select case when x > 1 then 1 else 2 end;
293 ╰╴ ──── 2. destination ─ 1. source
294 ");
295 }
296
297 #[test]
298 fn goto_case_end_trailing_semi() {
299 assert_snapshot!(goto("
300select case when x > 1 then 1 else 2 end;$0
301"), @r"
302 ╭▸
303 2 │ select case when x > 1 then 1 else 2 end;
304 ╰╴ ──── 2. destination ─ 1. source
305 ");
306 }
307
308 #[test]
309 fn goto_case_then_not_found() {
310 goto_not_found(
311 "
312select case when x > 1 then$0 1 else 2 end;
313",
314 )
315 }
316
317 #[test]
318 fn rollback_to_begin() {
319 assert_snapshot!(goto(
320 "
321begin;
322select 1;
323rollback$0;
324",
325 ), @r"
326 ╭▸
327 2 │ begin;
328 │ ───── 2. destination
329 3 │ select 1;
330 4 │ rollback;
331 ╰╴ ─ 1. source
332 ");
333 }
334
335 #[test]
336 fn goto_drop_table() {
337 assert_snapshot!(goto("
338create table t();
339drop table t$0;
340"), @r"
341 ╭▸
342 2 │ create table t();
343 │ ─ 2. destination
344 3 │ drop table t;
345 ╰╴ ─ 1. source
346 ");
347 }
348
349 #[test]
350 fn goto_drop_foreign_table() {
351 assert_snapshot!(goto("
352create foreign table t(a int) server s;
353drop foreign table t$0;
354"), @r"
355 ╭▸
356 2 │ create foreign table t(a int) server s;
357 │ ─ 2. destination
358 3 │ drop foreign table t;
359 ╰╴ ─ 1. source
360 ");
361 }
362
363 #[test]
364 fn goto_definition_prefers_previous_token() {
365 assert_snapshot!(goto("
366create table t(a int);
367select t.$0a from t;
368"), @r"
369 ╭▸
370 2 │ create table t(a int);
371 │ ─ 2. destination
372 3 │ select t.a from t;
373 ╰╴ ─ 1. source
374 ");
375
376 assert_snapshot!(goto("
377create type ty as (a int, b int);
378with t as (select '(1,2)'::ty c)
379select (c)$0.a from t;
380"), @r"
381 ╭▸
382 3 │ with t as (select '(1,2)'::ty c)
383 │ ─ 2. destination
384 4 │ select (c).a from t;
385 ╰╴ ─ 1. source
386 ");
387 assert_snapshot!(goto("
388create function f() returns int as 'select 1' language sql;
389select f($0);
390"), @r"
391 ╭▸
392 2 │ create function f() returns int as 'select 1' language sql;
393 │ ─ 2. destination
394 3 │ select f();
395 ╰╴ ─ 1. source
396 ");
397
398 assert_snapshot!(goto("
399with t as (select array[1,2,3]::int[] c)
400select c[$01] from t;
401"), @r"
402 ╭▸
403 2 │ with t as (select array[1,2,3]::int[] c)
404 │ ─ 2. destination
405 3 │ select c[1] from t;
406 ╰╴ ─ 1. source
407 ");
408
409 assert_snapshot!(goto("
410with t as (select array[1,2,3]::int[] c, 1 b)
411select c[b]$0 from t;
412"), @r"
413 ╭▸
414 2 │ with t as (select array[1,2,3]::int[] c, 1 b)
415 │ ─ 2. destination
416 3 │ select c[b] from t;
417 ╰╴ ─ 1. source
418 ");
419 }
420
421 #[test]
422 fn goto_fetch_cursor() {
423 assert_snapshot!(goto("
424declare c scroll cursor for select * from t;
425fetch forward 5 from c$0;
426"), @r"
427 ╭▸
428 2 │ declare c scroll cursor for select * from t;
429 │ ─ 2. destination
430 3 │ fetch forward 5 from c;
431 ╰╴ ─ 1. source
432 ");
433 }
434
435 #[test]
436 fn goto_close_cursor() {
437 assert_snapshot!(goto("
438declare c scroll cursor for select * from t;
439close c$0;
440"), @r"
441 ╭▸
442 2 │ declare c scroll cursor for select * from t;
443 │ ─ 2. destination
444 3 │ close c;
445 ╰╴ ─ 1. source
446 ");
447 }
448
449 #[test]
450 fn goto_move_cursor() {
451 assert_snapshot!(goto("
452declare c scroll cursor for select * from t;
453move forward 10 from c$0;
454"), @r"
455 ╭▸
456 2 │ declare c scroll cursor for select * from t;
457 │ ─ 2. destination
458 3 │ move forward 10 from c;
459 ╰╴ ─ 1. source
460 ");
461 }
462
463 #[test]
464 fn goto_execute_prepared_statement() {
465 assert_snapshot!(goto("
466prepare stmt as select 1;
467execute stmt$0;
468"), @r"
469 ╭▸
470 2 │ prepare stmt as select 1;
471 │ ──── 2. destination
472 3 │ execute stmt;
473 ╰╴ ─ 1. source
474 ");
475 }
476
477 #[test]
478 fn goto_deallocate_prepared_statement() {
479 assert_snapshot!(goto("
480prepare stmt as select 1;
481deallocate stmt$0;
482"), @r"
483 ╭▸
484 2 │ prepare stmt as select 1;
485 │ ──── 2. destination
486 3 │ deallocate stmt;
487 ╰╴ ─ 1. source
488 ");
489 }
490
491 #[test]
492 fn goto_notify_channel() {
493 assert_snapshot!(goto("
494listen updates;
495notify updates$0;
496"), @r"
497 ╭▸
498 2 │ listen updates;
499 │ ─────── 2. destination
500 3 │ notify updates;
501 ╰╴ ─ 1. source
502 ");
503 }
504
505 #[test]
506 fn goto_unlisten_channel() {
507 assert_snapshot!(goto("
508listen updates;
509unlisten updates$0;
510"), @r"
511 ╭▸
512 2 │ listen updates;
513 │ ─────── 2. destination
514 3 │ unlisten updates;
515 ╰╴ ─ 1. source
516 ");
517 }
518
519 #[test]
520 fn goto_delete_where_current_of_cursor() {
521 assert_snapshot!(goto("
522declare c scroll cursor for select * from t;
523delete from t where current of c$0;
524"), @r"
525 ╭▸
526 2 │ declare c scroll cursor for select * from t;
527 │ ─ 2. destination
528 3 │ delete from t where current of c;
529 ╰╴ ─ 1. source
530 ");
531 }
532
533 #[test]
534 fn goto_update_where_current_of_cursor() {
535 assert_snapshot!(goto("
536declare c scroll cursor for select * from t;
537update t set a = a + 10 where current of c$0;
538"), @r"
539 ╭▸
540 2 │ declare c scroll cursor for select * from t;
541 │ ─ 2. destination
542 3 │ update t set a = a + 10 where current of c;
543 ╰╴ ─ 1. source
544 ");
545 }
546
547 #[test]
548 fn goto_with_table_star() {
549 assert_snapshot!(goto("
550with t as (select 1 a)
551select t$0.* from t;
552"), @r"
553 ╭▸
554 2 │ with t as (select 1 a)
555 │ ─ 2. destination
556 3 │ select t.* from t;
557 ╰╴ ─ 1. source
558 ");
559 }
560
561 #[test]
562 fn goto_cross_join_func_column() {
563 assert_snapshot!(goto(r#"
564with t(x) as (select $$[{"a":1,"b":2}]$$::json)
565select * from t, json_to_recordset(x$0) as r(a int, b int);
566"#), @r#"
567 ╭▸
568 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
569 │ ─ 2. destination
570 3 │ select * from t, json_to_recordset(x) as r(a int, b int);
571 ╰╴ ─ 1. source
572 "#);
573 }
574
575 #[test]
576 fn goto_cross_join_func_qualified_column_table() {
577 assert_snapshot!(goto(r#"
578with t(x) as (select $$[{"a":1,"b":2}]$$::json)
579select * from t, json_to_recordset(t$0.x) as r(a int, b int);
580"#), @r#"
581 ╭▸
582 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
583 │ ─ 2. destination
584 3 │ select * from t, json_to_recordset(t.x) as r(a int, b int);
585 ╰╴ ─ 1. source
586 "#);
587 }
588
589 #[test]
590 fn goto_cross_join_func_qualified_column_field() {
591 assert_snapshot!(goto(r#"
592with t(x) as (select $$[{"a":1,"b":2}]$$::json)
593select * from t, json_to_recordset(t.x$0) as r(a int, b int);
594"#), @r#"
595 ╭▸
596 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
597 │ ─ 2. destination
598 3 │ select * from t, json_to_recordset(t.x) as r(a int, b int);
599 ╰╴ ─ 1. source
600 "#);
601 }
602
603 #[test]
604 fn goto_lateral_values_alias_in_subquery() {
605 assert_snapshot!(goto("
606select u.n, x.val
607from (values (1), (2)) u(n)
608cross join lateral (select u$0.n * 10 as val) x;
609"), @r"
610 ╭▸
611 3 │ from (values (1), (2)) u(n)
612 │ ─ 2. destination
613 4 │ cross join lateral (select u.n * 10 as val) x;
614 ╰╴ ─ 1. source
615 ");
616 }
617
618 #[test]
619 fn goto_lateral_missing_not_found() {
620 goto_not_found(
626 "
627select u.n, x.val
628from (values (1), (2)) u(n)
629cross join (select u$0.n * 10 as val) x;
630",
631 );
632 }
633
634 #[test]
635 fn goto_lateral_deeply_nested_paren_expr_values_alias_in_subquery() {
636 assert_snapshot!(goto("
637select u.n, x.val
638from (values (1), (2)) u(n)
639cross join lateral ((((select u$0.n * 10 as val)))) x;
640"), @r"
641 ╭▸
642 3 │ from (values (1), (2)) u(n)
643 │ ─ 2. destination
644 4 │ cross join lateral ((((select u.n * 10 as val)))) x;
645 ╰╴ ─ 1. source
646 ");
647 }
648
649 #[test]
650 fn goto_lateral_deeply_nested_paren_expr_values_alias_column() {
651 assert_snapshot!(goto("
652select u.n, x.val$0
653from (values (1), (2)) u(n)
654cross join lateral ((((select u.n * 10 as val)))) x;
655"), @r"
656 ╭▸
657 2 │ select u.n, x.val
658 │ ─ 1. source
659 3 │ from (values (1), (2)) u(n)
660 4 │ cross join lateral ((((select u.n * 10 as val)))) x;
661 ╰╴ ─── 2. destination
662 ");
663 }
664
665 #[test]
666 fn goto_lateral_deeply_nested_paren_expr_missing_not_found() {
667 goto_not_found(
673 "
674select u.n, x.val
675from (values (1), (2)) u(n)
676cross join ((((select u$0.n * 10 as val)))) x;
677",
678 );
679 }
680
681 #[test]
682 fn goto_drop_sequence() {
683 assert_snapshot!(goto("
684create sequence s;
685drop sequence s$0;
686"), @r"
687 ╭▸
688 2 │ create sequence s;
689 │ ─ 2. destination
690 3 │ drop sequence s;
691 ╰╴ ─ 1. source
692 ");
693 }
694
695 #[test]
696 fn goto_drop_trigger() {
697 assert_snapshot!(goto("
698create trigger tr before insert on t for each row execute function f();
699drop trigger tr$0 on t;
700"), @r"
701 ╭▸
702 2 │ create trigger tr before insert on t for each row execute function f();
703 │ ── 2. destination
704 3 │ drop trigger tr on t;
705 ╰╴ ─ 1. source
706 ");
707 }
708
709 #[test]
710 fn goto_drop_policy() {
711 assert_snapshot!(goto("
712create table t(c int);
713create table u(c int);
714create policy p on t;
715create policy p on u;
716drop policy if exists p$0 on t;
717"), @r"
718 ╭▸
719 4 │ create policy p on t;
720 │ ─ 2. destination
721 5 │ create policy p on u;
722 6 │ drop policy if exists p on t;
723 ╰╴ ─ 1. source
724 ");
725 }
726
727 #[test]
728 fn goto_alter_policy() {
729 assert_snapshot!(goto("
730create table t(c int);
731create policy p on t;
732alter policy p$0 on t
733 with check (c > 1);
734"), @r"
735 ╭▸
736 3 │ create policy p on t;
737 │ ─ 2. destination
738 4 │ alter policy p on t
739 ╰╴ ─ 1. source
740 ");
741 }
742
743 #[test]
744 fn goto_alter_policy_column() {
745 assert_snapshot!(goto("
746create table t(c int);
747create policy p on t;
748alter policy p on t
749 with check (c$0 > 1);
750"), @r"
751 ╭▸
752 3 │ create policy p on t;
753 │ ─ 2. destination
754 4 │ alter policy p on t
755 5 │ with check (c > 1);
756 ╰╴ ─ 1. source
757 ");
758 }
759
760 #[test]
761 fn goto_create_policy_column() {
762 assert_snapshot!(goto("
763create table t(c int, d int);
764create policy p on t
765 with check (c$0 > d);
766"), @r"
767 ╭▸
768 2 │ create table t(c int, d int);
769 │ ─ 2. destination
770 3 │ create policy p on t
771 4 │ with check (c > d);
772 ╰╴ ─ 1. source
773 ");
774 }
775
776 #[test]
777 fn goto_create_policy_using_column() {
778 assert_snapshot!(goto("
779create table t(c int, d int);
780create policy p on t
781 using (c$0 > d and 1 < 2);
782"), @r"
783 ╭▸
784 2 │ create table t(c int, d int);
785 │ ─ 2. destination
786 3 │ create policy p on t
787 4 │ using (c > d and 1 < 2);
788 ╰╴ ─ 1. source
789 ");
790 }
791
792 #[test]
793 fn goto_create_policy_qualified_column_table() {
794 assert_snapshot!(goto("
795create table t(c int, d int);
796create policy p on t
797 with check (t$0.c > d);
798"), @r"
799 ╭▸
800 2 │ create table t(c int, d int);
801 │ ─ 2. destination
802 3 │ create policy p on t
803 4 │ with check (t.c > d);
804 ╰╴ ─ 1. source
805 ");
806 }
807
808 #[test]
809 fn goto_create_policy_qualified_column() {
810 assert_snapshot!(goto("
811create table t(c int, d int);
812create policy p on t
813 with check (t.c$0 > d);
814"), @r"
815 ╭▸
816 2 │ create table t(c int, d int);
817 │ ─ 2. destination
818 3 │ create policy p on t
819 4 │ with check (t.c > d);
820 ╰╴ ─ 1. source
821 ");
822 }
823
824 #[test]
825 fn goto_create_policy_field_style_function_call() {
826 assert_snapshot!(goto("
827create table t(c int);
828create function x(t) returns int8
829 as 'select 1'
830 language sql;
831create policy p on t
832 with check (t.c > 1 and t.x$0 > 0);
833"), @r"
834 ╭▸
835 3 │ create function x(t) returns int8
836 │ ─ 2. destination
837 ‡
838 7 │ with check (t.c > 1 and t.x > 0);
839 ╰╴ ─ 1. source
840 ");
841 }
842
843 #[test]
844 fn goto_alter_policy_qualified_column_table() {
845 assert_snapshot!(goto("
846create table t(c int, d int);
847alter policy p on t
848 with check (t$0.c > d);
849"), @r"
850 ╭▸
851 2 │ create table t(c int, d int);
852 │ ─ 2. destination
853 3 │ alter policy p on t
854 4 │ with check (t.c > d);
855 ╰╴ ─ 1. source
856 ");
857 }
858
859 #[test]
860 fn goto_alter_policy_qualified_column() {
861 assert_snapshot!(goto("
862create table t(c int, d int);
863alter policy p on t
864 with check (t.c$0 > d);
865"), @r"
866 ╭▸
867 2 │ create table t(c int, d int);
868 │ ─ 2. destination
869 3 │ alter policy p on t
870 4 │ with check (t.c > d);
871 ╰╴ ─ 1. source
872 ");
873 }
874
875 #[test]
876 fn goto_builtin_now() {
877 assert_snapshot!(goto("
878select now$0();
879"), @"
880 ╭▸ current.sql:2:10
881 │
882 2 │ select now();
883 │ ─ 1. source
884 ╰╴
885
886 ╭▸ builtin.sql:11089:28
887 │
888 11089 │ create function pg_catalog.now() returns timestamp with time zone
889 ╰╴ ─── 2. destination
890 ");
891 }
892
893 #[test]
894 fn goto_current_timestamp() {
895 assert_snapshot!(goto("
896select current_timestamp$0;
897"), @"
898 ╭▸ current.sql:2:24
899 │
900 2 │ select current_timestamp;
901 │ ─ 1. source
902 ╰╴
903
904 ╭▸ builtin.sql:11089:28
905 │
906 11089 │ create function pg_catalog.now() returns timestamp with time zone
907 ╰╴ ─── 2. destination
908 ");
909 }
910
911 #[test]
912 fn goto_current_user() {
913 assert_snapshot!(goto("
914create function pg_catalog.current_user() returns name
915 language internal;
916select current_user$0;
917"), @"
918 ╭▸
919 2 │ create function pg_catalog.current_user() returns name
920 │ ──────────── 2. destination
921 3 │ language internal;
922 4 │ select current_user;
923 ╰╴ ─ 1. source
924 "
925 );
926 }
927
928 #[test]
929 fn goto_user_keyword() {
930 assert_snapshot!(goto("
931create function pg_catalog.current_user() returns name
932 language internal;
933select user$0;
934"), @"
935 ╭▸
936 2 │ create function pg_catalog.current_user() returns name
937 │ ──────────── 2. destination
938 3 │ language internal;
939 4 │ select user;
940 ╰╴ ─ 1. source
941 "
942 );
943 }
944
945 #[test]
946 fn goto_session_user() {
947 assert_snapshot!(goto("
948create function pg_catalog.session_user() returns name
949 language internal;
950select session_user$0;
951"), @"
952 ╭▸
953 2 │ create function pg_catalog.session_user() returns name
954 │ ──────────── 2. destination
955 3 │ language internal;
956 4 │ select session_user;
957 ╰╴ ─ 1. source
958 "
959 );
960 }
961
962 #[test]
963 fn goto_current_schema() {
964 assert_snapshot!(goto("
965create function current_schema() returns name
966 language internal;
967select current_schema$0;
968"), @"
969 ╭▸
970 2 │ create function current_schema() returns name
971 │ ────────────── 2. destination
972 3 │ language internal;
973 4 │ select current_schema;
974 ╰╴ ─ 1. source
975 "
976 );
977 }
978
979 #[test]
980 fn goto_current_timestamp_cte_column() {
981 assert_snapshot!(goto("
982with t as (select 1 current_timestamp)
983select current_timestamp$0 from t;
984"), @r"
985 ╭▸
986 2 │ with t as (select 1 current_timestamp)
987 │ ───────────────── 2. destination
988 3 │ select current_timestamp from t;
989 ╰╴ ─ 1. source
990 ");
991 }
992
993 #[test]
994 fn goto_current_timestamp_in_where() {
995 assert_snapshot!(goto("
996create table t(created_at timestamptz);
997select * from t where current_timestamp$0 > t.created_at;
998"), @"
999 ╭▸ current.sql:3:39
1000 │
1001 3 │ select * from t where current_timestamp > t.created_at;
1002 │ ─ 1. source
1003 ╰╴
1004
1005 ╭▸ builtin.sql:11089:28
1006 │
1007 11089 │ create function pg_catalog.now() returns timestamp with time zone
1008 ╰╴ ─── 2. destination
1009 ");
1010 }
1011
1012 #[test]
1013 fn goto_create_policy_schema_qualified_table() {
1014 assert_snapshot!(goto("
1015create schema foo;
1016create table foo.t(c int);
1017create policy p on foo.t
1018 with check (foo.t$0.c > 1);
1019"), @r"
1020 ╭▸
1021 3 │ create table foo.t(c int);
1022 │ ─ 2. destination
1023 4 │ create policy p on foo.t
1024 5 │ with check (foo.t.c > 1);
1025 ╰╴ ─ 1. source
1026 ");
1027 }
1028
1029 #[test]
1030 fn goto_create_policy_unqualified_table_with_schema_on_table() {
1031 assert_snapshot!(goto("
1032create schema foo;
1033create table foo.t(c int);
1034create policy p on foo.t
1035 with check (t$0.c > 1);
1036"), @r"
1037 ╭▸
1038 3 │ create table foo.t(c int);
1039 │ ─ 2. destination
1040 4 │ create policy p on foo.t
1041 5 │ with check (t.c > 1);
1042 ╰╴ ─ 1. source
1043 ");
1044 }
1045
1046 #[test]
1047 fn goto_drop_event_trigger() {
1048 assert_snapshot!(goto("
1049create event trigger et on ddl_command_start execute function f();
1050drop event trigger et$0;
1051"), @r"
1052 ╭▸
1053 2 │ create event trigger et on ddl_command_start execute function f();
1054 │ ── 2. destination
1055 3 │ drop event trigger et;
1056 ╰╴ ─ 1. source
1057 ");
1058 }
1059
1060 #[test]
1061 fn goto_alter_event_trigger() {
1062 assert_snapshot!(goto("
1063create event trigger et on ddl_command_start execute function f();
1064alter event trigger et$0 disable;
1065"), @r"
1066 ╭▸
1067 2 │ create event trigger et on ddl_command_start execute function f();
1068 │ ── 2. destination
1069 3 │ alter event trigger et disable;
1070 ╰╴ ─ 1. source
1071 ");
1072 }
1073
1074 #[test]
1075 fn goto_create_event_trigger_function() {
1076 assert_snapshot!(goto("
1077create function f() returns event_trigger as 'select 1' language sql;
1078create event trigger et on ddl_command_start execute function f$0();
1079"), @r"
1080 ╭▸
1081 2 │ create function f() returns event_trigger as 'select 1' language sql;
1082 │ ─ 2. destination
1083 3 │ create event trigger et on ddl_command_start execute function f();
1084 ╰╴ ─ 1. source
1085 ");
1086 }
1087
1088 #[test]
1089 fn goto_create_event_trigger_procedure() {
1090 assert_snapshot!(goto("
1091create procedure p() language sql as 'select 1';
1092create event trigger tr
1093 on ddl_command_end
1094 execute procedure p$0();
1095"), @r"
1096 ╭▸
1097 2 │ create procedure p() language sql as 'select 1';
1098 │ ─ 2. destination
1099 ‡
1100 5 │ execute procedure p();
1101 ╰╴ ─ 1. source
1102 ");
1103 }
1104
1105 #[test]
1106 fn goto_create_trigger_function() {
1107 assert_snapshot!(goto("
1108create function f() returns trigger as 'select 1' language sql;
1109create trigger tr before insert on t for each row execute function f$0();
1110"), @r"
1111 ╭▸
1112 2 │ create function f() returns trigger as 'select 1' language sql;
1113 │ ─ 2. destination
1114 3 │ create trigger tr before insert on t for each row execute function f();
1115 ╰╴ ─ 1. source
1116 ");
1117 }
1118
1119 #[test]
1120 fn goto_create_trigger_procedure() {
1121 assert_snapshot!(goto("
1122create procedure a() language sql as 'select 1';
1123create trigger tr before truncate or delete or insert
1124on t
1125execute procedure a$0();
1126"), @r"
1127 ╭▸
1128 2 │ create procedure a() language sql as 'select 1';
1129 │ ─ 2. destination
1130 ‡
1131 5 │ execute procedure a();
1132 ╰╴ ─ 1. source
1133 ");
1134 }
1135
1136 #[test]
1137 fn goto_drop_trigger_table_specific() {
1138 assert_snapshot!(goto("
1139create table u(a int);
1140create trigger tr before truncate
1141on u
1142execute function noop();
1143
1144create table t(b int);
1145create trigger tr before truncate
1146on t
1147execute function noop();
1148
1149drop trigger tr$0 on t;
1150"), @r"
1151 ╭▸
1152 8 │ create trigger tr before truncate
1153 │ ── 2. destination
1154 ‡
1155 12 │ drop trigger tr on t;
1156 ╰╴ ─ 1. source
1157 ");
1158 }
1159
1160 #[test]
1161 fn goto_create_trigger_table() {
1162 assert_snapshot!(goto("
1163create table t(b int);
1164create trigger tr before truncate
1165on t$0
1166execute function noop();
1167"), @r"
1168 ╭▸
1169 2 │ create table t(b int);
1170 │ ─ 2. destination
1171 3 │ create trigger tr before truncate
1172 4 │ on t
1173 ╰╴ ─ 1. source
1174 ");
1175 }
1176
1177 #[test]
1178 fn goto_create_sequence_owned_by() {
1179 assert_snapshot!(goto("
1180create table t(c serial);
1181create sequence s
1182 owned by t.c$0;
1183"), @r"
1184 ╭▸
1185 2 │ create table t(c serial);
1186 │ ─ 2. destination
1187 3 │ create sequence s
1188 4 │ owned by t.c;
1189 ╰╴ ─ 1. source
1190 ");
1191 }
1192
1193 #[test]
1194 fn goto_drop_tablespace() {
1195 assert_snapshot!(goto("
1196create tablespace ts location '/tmp/ts';
1197drop tablespace ts$0;
1198"), @r"
1199 ╭▸
1200 2 │ create tablespace ts location '/tmp/ts';
1201 │ ── 2. destination
1202 3 │ drop tablespace ts;
1203 ╰╴ ─ 1. source
1204 ");
1205 }
1206
1207 #[test]
1208 fn goto_create_table_tablespace() {
1209 assert_snapshot!(goto("
1210create tablespace bar location '/tmp/ts';
1211create table t (a int) tablespace b$0ar;
1212"), @r"
1213 ╭▸
1214 2 │ create tablespace bar location '/tmp/ts';
1215 │ ─── 2. destination
1216 3 │ create table t (a int) tablespace bar;
1217 ╰╴ ─ 1. source
1218 ");
1219 }
1220
1221 #[test]
1222 fn goto_drop_database() {
1223 assert_snapshot!(goto("
1224create database mydb;
1225drop database my$0db;
1226"), @r"
1227 ╭▸
1228 2 │ create database mydb;
1229 │ ──── 2. destination
1230 3 │ drop database mydb;
1231 ╰╴ ─ 1. source
1232 ");
1233 }
1234
1235 #[test]
1236 fn goto_drop_role() {
1237 assert_snapshot!(goto("
1238create role reader;
1239drop role read$0er;
1240"), @r"
1241 ╭▸
1242 2 │ create role reader;
1243 │ ────── 2. destination
1244 3 │ drop role reader;
1245 ╰╴ ─ 1. source
1246 ");
1247 }
1248
1249 #[test]
1250 fn goto_alter_role() {
1251 assert_snapshot!(goto("
1252create role reader;
1253alter role read$0er rename to writer;
1254"), @r"
1255 ╭▸
1256 2 │ create role reader;
1257 │ ────── 2. destination
1258 3 │ alter role reader rename to writer;
1259 ╰╴ ─ 1. source
1260 ");
1261 }
1262
1263 #[test]
1264 fn goto_set_role() {
1265 assert_snapshot!(goto("
1266create role reader;
1267set role read$0er;
1268"), @r"
1269 ╭▸
1270 2 │ create role reader;
1271 │ ────── 2. destination
1272 3 │ set role reader;
1273 ╰╴ ─ 1. source
1274 ");
1275 }
1276
1277 #[test]
1278 fn goto_create_tablespace_owner_role() {
1279 assert_snapshot!(goto("
1280create role reader;
1281create tablespace t owner read$0er location 'foo';
1282"), @r"
1283 ╭▸
1284 2 │ create role reader;
1285 │ ────── 2. destination
1286 3 │ create tablespace t owner reader location 'foo';
1287 ╰╴ ─ 1. source
1288 ");
1289 }
1290
1291 #[test]
1292 fn goto_role_definition_returns_self() {
1293 assert_snapshot!(goto("
1294create role read$0er;
1295"), @r"
1296 ╭▸
1297 2 │ create role reader;
1298 │ ┬──┬──
1299 │ │ │
1300 │ │ 1. source
1301 ╰╴ 2. destination
1302 ");
1303 }
1304
1305 #[test]
1306 fn goto_drop_database_defined_after() {
1307 assert_snapshot!(goto("
1308drop database my$0db;
1309create database mydb;
1310"), @r"
1311 ╭▸
1312 2 │ drop database mydb;
1313 │ ─ 1. source
1314 3 │ create database mydb;
1315 ╰╴ ──── 2. destination
1316 ");
1317 }
1318
1319 #[test]
1320 fn goto_database_definition_returns_self() {
1321 assert_snapshot!(goto("
1322create database my$0db;
1323"), @r"
1324 ╭▸
1325 2 │ create database mydb;
1326 │ ┬┬──
1327 │ ││
1328 │ │1. source
1329 ╰╴ 2. destination
1330 ");
1331 }
1332
1333 #[test]
1334 fn goto_drop_server() {
1335 assert_snapshot!(goto("
1336create server myserver foreign data wrapper fdw;
1337drop server my$0server;
1338"), @r"
1339 ╭▸
1340 2 │ create server myserver foreign data wrapper fdw;
1341 │ ──────── 2. destination
1342 3 │ drop server myserver;
1343 ╰╴ ─ 1. source
1344 ");
1345 }
1346
1347 #[test]
1348 fn goto_drop_server_defined_after() {
1349 assert_snapshot!(goto("
1350drop server my$0server;
1351create server myserver foreign data wrapper fdw;
1352"), @r"
1353 ╭▸
1354 2 │ drop server myserver;
1355 │ ─ 1. source
1356 3 │ create server myserver foreign data wrapper fdw;
1357 ╰╴ ──────── 2. destination
1358 ");
1359 }
1360
1361 #[test]
1362 fn goto_alter_server() {
1363 assert_snapshot!(goto("
1364create server myserver foreign data wrapper fdw;
1365alter server my$0server options (add foo 'bar');
1366"), @r"
1367 ╭▸
1368 2 │ create server myserver foreign data wrapper fdw;
1369 │ ──────── 2. destination
1370 3 │ alter server myserver options (add foo 'bar');
1371 ╰╴ ─ 1. source
1372 ");
1373 }
1374
1375 #[test]
1376 fn goto_server_definition_returns_self() {
1377 assert_snapshot!(goto("
1378create server my$0server foreign data wrapper fdw;
1379"), @r"
1380 ╭▸
1381 2 │ create server myserver foreign data wrapper fdw;
1382 │ ┬┬──────
1383 │ ││
1384 │ │1. source
1385 ╰╴ 2. destination
1386 ");
1387 }
1388
1389 #[test]
1390 fn goto_drop_extension() {
1391 assert_snapshot!(goto("
1392create extension myext;
1393drop extension my$0ext;
1394"), @r"
1395 ╭▸
1396 2 │ create extension myext;
1397 │ ───── 2. destination
1398 3 │ drop extension myext;
1399 ╰╴ ─ 1. source
1400 ");
1401 }
1402
1403 #[test]
1404 fn goto_drop_extension_defined_after() {
1405 assert_snapshot!(goto("
1406drop extension my$0ext;
1407create extension myext;
1408"), @r"
1409 ╭▸
1410 2 │ drop extension myext;
1411 │ ─ 1. source
1412 3 │ create extension myext;
1413 ╰╴ ───── 2. destination
1414 ");
1415 }
1416
1417 #[test]
1418 fn goto_alter_extension() {
1419 assert_snapshot!(goto("
1420create extension myext;
1421alter extension my$0ext update to '2.0';
1422"), @r"
1423 ╭▸
1424 2 │ create extension myext;
1425 │ ───── 2. destination
1426 3 │ alter extension myext update to '2.0';
1427 ╰╴ ─ 1. source
1428 ");
1429 }
1430
1431 #[test]
1432 fn goto_extension_definition_returns_self() {
1433 assert_snapshot!(goto("
1434create extension my$0ext;
1435"), @r"
1436 ╭▸
1437 2 │ create extension myext;
1438 │ ┬┬───
1439 │ ││
1440 │ │1. source
1441 ╰╴ 2. destination
1442 ");
1443 }
1444
1445 #[test]
1446 fn goto_drop_sequence_with_schema() {
1447 assert_snapshot!(goto("
1448create sequence foo.s;
1449drop sequence foo.s$0;
1450"), @r"
1451 ╭▸
1452 2 │ create sequence foo.s;
1453 │ ─ 2. destination
1454 3 │ drop sequence foo.s;
1455 ╰╴ ─ 1. source
1456 ");
1457 }
1458
1459 #[test]
1460 fn goto_drop_table_with_schema() {
1461 assert_snapshot!(goto("
1462create table public.t();
1463drop table t$0;
1464"), @r"
1465 ╭▸
1466 2 │ create table public.t();
1467 │ ─ 2. destination
1468 3 │ drop table t;
1469 ╰╴ ─ 1. source
1470 ");
1471
1472 assert_snapshot!(goto("
1473create table foo.t();
1474drop table foo.t$0;
1475"), @r"
1476 ╭▸
1477 2 │ create table foo.t();
1478 │ ─ 2. destination
1479 3 │ drop table foo.t;
1480 ╰╴ ─ 1. source
1481 ");
1482
1483 goto_not_found(
1484 "
1485-- defaults to public schema
1486create table t();
1487drop table foo.t$0;
1488",
1489 );
1490 }
1491
1492 #[test]
1493 fn goto_drop_temp_table() {
1494 assert_snapshot!(goto("
1495create temp table t();
1496drop table t$0;
1497"), @r"
1498 ╭▸
1499 2 │ create temp table t();
1500 │ ─ 2. destination
1501 3 │ drop table t;
1502 ╰╴ ─ 1. source
1503 ");
1504 }
1505
1506 #[test]
1507 fn goto_drop_temporary_table() {
1508 assert_snapshot!(goto("
1509create temporary table t();
1510drop table t$0;
1511"), @r"
1512 ╭▸
1513 2 │ create temporary table t();
1514 │ ─ 2. destination
1515 3 │ drop table t;
1516 ╰╴ ─ 1. source
1517 ");
1518 }
1519
1520 #[test]
1521 fn goto_drop_temp_table_with_pg_temp_schema() {
1522 assert_snapshot!(goto("
1523create temp table t();
1524drop table pg_temp.t$0;
1525"), @r"
1526 ╭▸
1527 2 │ create temp table t();
1528 │ ─ 2. destination
1529 3 │ drop table pg_temp.t;
1530 ╰╴ ─ 1. source
1531 ");
1532 }
1533
1534 #[test]
1535 fn goto_table_definition_returns_self() {
1536 assert_snapshot!(goto("
1537create table t$0(x bigint, y bigint);
1538"), @r"
1539 ╭▸
1540 2 │ create table t(x bigint, y bigint);
1541 │ ┬
1542 │ │
1543 │ 2. destination
1544 ╰╴ 1. source
1545 ");
1546 }
1547
1548 #[test]
1549 fn goto_foreign_table_column() {
1550 assert_snapshot!(goto("
1551create foreign table ft(a int)
1552 server s;
1553
1554select a$0 from ft;
1555"), @r"
1556 ╭▸
1557 2 │ create foreign table ft(a int)
1558 │ ─ 2. destination
1559 ‡
1560 5 │ select a from ft;
1561 ╰╴ ─ 1. source
1562 ");
1563 }
1564
1565 #[test]
1566 fn goto_foreign_table_definition() {
1567 assert_snapshot!(goto("
1568create foreign table ft(a int)
1569 server s;
1570
1571select a from ft$0;
1572"), @r"
1573 ╭▸
1574 2 │ create foreign table ft(a int)
1575 │ ── 2. destination
1576 ‡
1577 5 │ select a from ft;
1578 ╰╴ ─ 1. source
1579 ");
1580 }
1581
1582 #[test]
1583 fn goto_foreign_table_server_name() {
1584 assert_snapshot!(goto("
1585create server myserver foreign data wrapper fdw;
1586create foreign table ft(a int)
1587 server my$0server;
1588"), @r"
1589 ╭▸
1590 2 │ create server myserver foreign data wrapper fdw;
1591 │ ──────── 2. destination
1592 3 │ create foreign table ft(a int)
1593 4 │ server myserver;
1594 ╰╴ ─ 1. source
1595 ");
1596 }
1597
1598 #[test]
1599 fn goto_foreign_table_server_name_defined_after() {
1600 assert_snapshot!(goto("
1601create foreign table ft(a int)
1602 server my$0server;
1603create server myserver foreign data wrapper fdw;
1604"), @r"
1605 ╭▸
1606 3 │ server myserver;
1607 │ ─ 1. source
1608 4 │ create server myserver foreign data wrapper fdw;
1609 ╰╴ ──────── 2. destination
1610 ");
1611 }
1612
1613 #[test]
1614 fn goto_user_mapping_server_name() {
1615 assert_snapshot!(goto("
1616create server myserver foreign data wrapper fdw;
1617create user mapping for current_user server my$0server;
1618"), @r"
1619 ╭▸
1620 2 │ create server myserver foreign data wrapper fdw;
1621 │ ──────── 2. destination
1622 3 │ create user mapping for current_user server myserver;
1623 ╰╴ ─ 1. source
1624 ");
1625 }
1626
1627 #[test]
1628 fn goto_foreign_key_references_table() {
1629 assert_snapshot!(goto("
1630create table foo(id int);
1631create table bar(
1632 id int,
1633 foo_id int,
1634 foreign key (foo_id) references foo$0(id)
1635);
1636"), @r"
1637 ╭▸
1638 2 │ create table foo(id int);
1639 │ ─── 2. destination
1640 ‡
1641 6 │ foreign key (foo_id) references foo(id)
1642 ╰╴ ─ 1. source
1643 ");
1644 }
1645
1646 #[test]
1647 fn goto_foreign_key_on_delete_set_null_column() {
1648 assert_snapshot!(goto("
1649create table users (
1650 user_id integer not null,
1651 primary key (user_id)
1652);
1653
1654create table posts (
1655 post_id integer not null,
1656 author_id integer,
1657 primary key (post_id),
1658 foreign key (author_id) references users on delete set null (author_id$0)
1659);
1660"), @r"
1661 ╭▸
1662 9 │ author_id integer,
1663 │ ───────── 2. destination
1664 10 │ primary key (post_id),
1665 11 │ foreign key (author_id) references users on delete set null (author_id)
1666 ╰╴ ─ 1. source
1667 ");
1668 }
1669
1670 #[test]
1671 fn goto_references_constraint_table() {
1672 assert_snapshot!(goto("
1673create table t (
1674 id serial primary key
1675);
1676
1677create table u (
1678 id serial primary key,
1679 t_id int references t$0
1680);
1681"), @r"
1682 ╭▸
1683 2 │ create table t (
1684 │ ─ 2. destination
1685 ‡
1686 8 │ t_id int references t
1687 ╰╴ ─ 1. source
1688 ");
1689 }
1690
1691 #[test]
1692 fn goto_references_constraint_column() {
1693 assert_snapshot!(goto("
1694create table t (
1695 id serial primary key
1696);
1697
1698create table u (
1699 id serial primary key,
1700 t_id int references t(id$0)
1701);
1702"), @r"
1703 ╭▸
1704 3 │ id serial primary key
1705 │ ── 2. destination
1706 ‡
1707 8 │ t_id int references t(id)
1708 ╰╴ ─ 1. source
1709 ");
1710 }
1711
1712 #[test]
1713 fn goto_foreign_key_references_column() {
1714 assert_snapshot!(goto("
1715create table foo(id int);
1716create table bar(
1717 id int,
1718 foo_id int,
1719 foreign key (foo_id) references foo(id$0)
1720);
1721"), @r"
1722 ╭▸
1723 2 │ create table foo(id int);
1724 │ ── 2. destination
1725 ‡
1726 6 │ foreign key (foo_id) references foo(id)
1727 ╰╴ ─ 1. source
1728 ");
1729 }
1730
1731 #[test]
1732 fn goto_foreign_key_local_column() {
1733 assert_snapshot!(goto("
1734create table bar(
1735 id int,
1736 foo_id int,
1737 foreign key (foo_id$0) references foo(id)
1738);
1739"), @r"
1740 ╭▸
1741 4 │ foo_id int,
1742 │ ────── 2. destination
1743 5 │ foreign key (foo_id) references foo(id)
1744 ╰╴ ─ 1. source
1745 ");
1746 }
1747
1748 #[test]
1749 fn goto_alter_table_foreign_key_local_column() {
1750 assert_snapshot!(goto("
1751create table t (
1752 id bigserial primary key
1753);
1754
1755create table u (
1756 id bigserial primary key,
1757 t_id bigint
1758);
1759
1760alter table u
1761 add constraint fooo_fkey
1762 foreign key (t_id$0) references t (id);
1763"), @r"
1764 ╭▸
1765 8 │ t_id bigint
1766 │ ──── 2. destination
1767 ‡
1768 13 │ foreign key (t_id) references t (id);
1769 ╰╴ ─ 1. source
1770 ");
1771 }
1772
1773 #[test]
1774 fn goto_check_constraint_column() {
1775 assert_snapshot!(goto("
1776create table t (
1777 b int check (b > 10),
1778 c int check (c$0 > 10) no inherit
1779);
1780"), @r"
1781 ╭▸
1782 4 │ c int check (c > 10) no inherit
1783 │ ┬ ─ 1. source
1784 │ │
1785 ╰╴ 2. destination
1786 ");
1787 }
1788
1789 #[test]
1790 fn goto_generated_column() {
1791 assert_snapshot!(goto("
1792create table t (
1793 a int,
1794 b int generated always as (
1795 a$0 * 2
1796 ) stored
1797);
1798"), @r"
1799 ╭▸
1800 3 │ a int,
1801 │ ─ 2. destination
1802 4 │ b int generated always as (
1803 5 │ a * 2
1804 ╰╴ ─ 1. source
1805 ");
1806 }
1807
1808 #[test]
1809 fn goto_generated_column_function_call() {
1810 assert_snapshot!(goto("
1811create function pg_catalog.lower(text) returns text
1812 language internal;
1813
1814create table articles (
1815 id serial primary key,
1816 title text not null,
1817 body text not null,
1818 title_lower text generated always as (
1819 lower$0(title)
1820 ) stored
1821);
1822"), @r"
1823 ╭▸
1824 2 │ create function pg_catalog.lower(text) returns text
1825 │ ───── 2. destination
1826 ‡
1827 10 │ lower(title)
1828 ╰╴ ─ 1. source
1829 ");
1830 }
1831
1832 #[test]
1833 fn goto_index_expr_function_call() {
1834 assert_snapshot!(goto("
1835create function lower(text) returns text language internal;
1836create table articles (
1837 id serial primary key,
1838 title text not null
1839);
1840create index on articles (lower$0(title));
1841"), @r"
1842 ╭▸
1843 2 │ create function lower(text) returns text language internal;
1844 │ ───── 2. destination
1845 ‡
1846 7 │ create index on articles (lower(title));
1847 ╰╴ ─ 1. source
1848 ");
1849 }
1850
1851 #[test]
1852 fn goto_exclude_constraint_expr_function_call() {
1853 assert_snapshot!(goto("
1854create function lower(text) returns text language internal;
1855create table articles (
1856 title text not null,
1857 exclude using btree (lower$0(title) with =)
1858);
1859"), @r"
1860 ╭▸
1861 2 │ create function lower(text) returns text language internal;
1862 │ ───── 2. destination
1863 ‡
1864 5 │ exclude using btree (lower(title) with =)
1865 ╰╴ ─ 1. source
1866 ");
1867 }
1868
1869 #[test]
1870 fn goto_partition_by_expr_function_call() {
1871 assert_snapshot!(goto("
1872create function lower(text) returns text language internal;
1873create table articles (
1874 id serial primary key,
1875 title text not null
1876) partition by range (lower$0(title));
1877"), @r"
1878 ╭▸
1879 2 │ create function lower(text) returns text language internal;
1880 │ ───── 2. destination
1881 ‡
1882 6 │ ) partition by range (lower(title));
1883 ╰╴ ─ 1. source
1884 ");
1885 }
1886
1887 #[test]
1888 fn goto_table_check_constraint_column() {
1889 assert_snapshot!(goto("
1890create table t (
1891 a int,
1892 b text,
1893 check (a$0 > b)
1894);
1895"), @r"
1896 ╭▸
1897 3 │ a int,
1898 │ ─ 2. destination
1899 4 │ b text,
1900 5 │ check (a > b)
1901 ╰╴ ─ 1. source
1902 ");
1903 }
1904
1905 #[test]
1906 fn goto_table_unique_constraint_column() {
1907 assert_snapshot!(goto("
1908create table t (
1909 a int,
1910 b text,
1911 unique (a$0)
1912);
1913"), @r"
1914 ╭▸
1915 3 │ a int,
1916 │ ─ 2. destination
1917 4 │ b text,
1918 5 │ unique (a)
1919 ╰╴ ─ 1. source
1920 ");
1921 }
1922
1923 #[test]
1924 fn goto_table_primary_key_constraint_column() {
1925 assert_snapshot!(goto("
1926create table t (
1927 id bigint generated always as identity,
1928 inserted_at timestamptz not null default now(),
1929 primary key (id, inserted_at$0)
1930);
1931"), @r"
1932 ╭▸
1933 4 │ inserted_at timestamptz not null default now(),
1934 │ ─────────── 2. destination
1935 5 │ primary key (id, inserted_at)
1936 ╰╴ ─ 1. source
1937 ");
1938 }
1939
1940 #[test]
1941 fn goto_table_not_null_constraint_column() {
1942 assert_snapshot!(goto("
1943create table t (
1944 id integer,
1945 name text,
1946 not null name$0
1947);
1948"), @r"
1949 ╭▸
1950 4 │ name text,
1951 │ ──── 2. destination
1952 5 │ not null name
1953 ╰╴ ─ 1. source
1954 ");
1955 }
1956
1957 #[test]
1958 fn goto_table_exclude_constraint_column() {
1959 assert_snapshot!(goto("
1960create table circles (
1961 c circle,
1962 exclude using gist (c$0 with &&)
1963);
1964"), @r"
1965 ╭▸
1966 3 │ c circle,
1967 │ ─ 2. destination
1968 4 │ exclude using gist (c with &&)
1969 ╰╴ ─ 1. source
1970 ");
1971 }
1972
1973 #[test]
1974 fn goto_table_exclude_constraint_include_column() {
1975 assert_snapshot!(goto("
1976create table t (
1977 a int,
1978 b text,
1979 exclude using btree ( a with > )
1980 include (a$0, b)
1981);
1982"), @r"
1983 ╭▸
1984 3 │ a int,
1985 │ ─ 2. destination
1986 ‡
1987 6 │ include (a, b)
1988 ╰╴ ─ 1. source
1989 ");
1990 }
1991
1992 #[test]
1993 fn goto_table_exclude_constraint_where_column() {
1994 assert_snapshot!(goto("
1995create table t (
1996 a int,
1997 b text,
1998 exclude using btree ( a with > )
1999 where ( a$0 > 10 and b like '%foo' )
2000);
2001"), @r"
2002 ╭▸
2003 3 │ a int,
2004 │ ─ 2. destination
2005 ‡
2006 6 │ where ( a > 10 and b like '%foo' )
2007 ╰╴ ─ 1. source
2008 ");
2009 }
2010
2011 #[test]
2012 fn goto_table_partition_by_column() {
2013 assert_snapshot!(goto("
2014create table t (
2015 id bigint generated always as identity,
2016 inserted_at timestamptz not null default now()
2017) partition by range (inserted_at$0);
2018"), @r"
2019 ╭▸
2020 4 │ inserted_at timestamptz not null default now()
2021 │ ─────────── 2. destination
2022 5 │ ) partition by range (inserted_at);
2023 ╰╴ ─ 1. source
2024 ");
2025 }
2026
2027 #[test]
2028 fn goto_table_partition_of_table() {
2029 assert_snapshot!(goto("
2030create table t ();
2031create table t_2026_01_02 partition of t$0
2032 for values from ('2026-01-02') to ('2026-01-03');
2033"), @r"
2034 ╭▸
2035 2 │ create table t ();
2036 │ ─ 2. destination
2037 3 │ create table t_2026_01_02 partition of t
2038 ╰╴ ─ 1. source
2039 ");
2040 }
2041
2042 #[test]
2043 fn goto_table_partition_of_cycle() {
2044 goto_not_found(
2045 "
2046create table part1 partition of part2
2047 for values from ('2026-01-02') to ('2026-01-03');
2048create table part2 partition of part1
2049 for values from ('2026-01-02') to ('2026-01-03');
2050select a$0 from part2;
2051",
2052 );
2053 }
2054
2055 #[test]
2056 fn goto_partition_table_column() {
2057 assert_snapshot!(goto("
2058create table part (
2059 a int,
2060 inserted_at timestamptz not null default now()
2061) partition by range (inserted_at);
2062create table part_2026_01_02 partition of part
2063 for values from ('2026-01-02') to ('2026-01-03');
2064select a$0 from part_2026_01_02;
2065"), @r"
2066 ╭▸
2067 3 │ a int,
2068 │ ─ 2. destination
2069 ‡
2070 8 │ select a from part_2026_01_02;
2071 ╰╴ ─ 1. source
2072 ");
2073 }
2074
2075 #[test]
2076 fn goto_alter_index_attach_partition() {
2077 assert_snapshot!(goto("
2078create table t (
2079 inserted_at timestamptz not null default now()
2080) partition by range (inserted_at);
2081create table part partition of t
2082 for values from ('2026-01-02') to ('2026-01-03');
2083alter index t attach partition part$0;
2084"), @r"
2085 ╭▸
2086 5 │ create table part partition of t
2087 │ ──── 2. destination
2088 6 │ for values from ('2026-01-02') to ('2026-01-03');
2089 7 │ alter index t attach partition part;
2090 ╰╴ ─ 1. source
2091 ");
2092 }
2093
2094 #[test]
2095 fn goto_create_table_like_clause() {
2096 assert_snapshot!(goto("
2097create table large_data_table(a text);
2098create table t (
2099 a text,
2100 like large_data_table$0,
2101 b integer
2102);
2103"), @r"
2104 ╭▸
2105 2 │ create table large_data_table(a text);
2106 │ ──────────────── 2. destination
2107 ‡
2108 5 │ like large_data_table,
2109 ╰╴ ─ 1. source
2110 ");
2111 }
2112
2113 #[test]
2114 fn goto_create_table_inherits() {
2115 assert_snapshot!(goto("
2116create table bar(a int);
2117create table t (a int)
2118inherits (foo.bar, bar$0, buzz);
2119"), @r"
2120 ╭▸
2121 2 │ create table bar(a int);
2122 │ ─── 2. destination
2123 3 │ create table t (a int)
2124 4 │ inherits (foo.bar, bar, buzz);
2125 ╰╴ ─ 1. source
2126 ");
2127 }
2128
2129 #[test]
2130 fn goto_create_table_like_clause_columns() {
2131 assert_snapshot!(goto("
2132create table t(a int, b int);
2133create table u(like t, c int);
2134select a$0, c from u;
2135"), @r"
2136 ╭▸
2137 2 │ create table t(a int, b int);
2138 │ ─ 2. destination
2139 3 │ create table u(like t, c int);
2140 4 │ select a, c from u;
2141 ╰╴ ─ 1. source
2142 ");
2143 }
2144
2145 #[test]
2146 fn goto_create_table_like_clause_local_column() {
2147 assert_snapshot!(goto("
2148create table t(a int, b int);
2149create table u(like t, c int);
2150select a, c$0 from u;
2151"), @r"
2152 ╭▸
2153 3 │ create table u(like t, c int);
2154 │ ─ 2. destination
2155 4 │ select a, c from u;
2156 ╰╴ ─ 1. source
2157 ");
2158 }
2159
2160 #[test]
2161 fn goto_create_table_like_clause_multi() {
2162 assert_snapshot!(goto("
2163create table t(a int, b int);
2164create table u(x int, y int);
2165create table k(like t, like u, c int);
2166select y$0 from k;
2167"), @r"
2168 ╭▸
2169 3 │ create table u(x int, y int);
2170 │ ─ 2. destination
2171 4 │ create table k(like t, like u, c int);
2172 5 │ select y from k;
2173 ╰╴ ─ 1. source
2174 ");
2175 }
2176
2177 #[test]
2178 fn goto_create_table_inherits_column() {
2179 assert_snapshot!(goto("
2180create table t (
2181 a int, b text
2182);
2183create table u (
2184 c int
2185) inherits (t);
2186select a$0 from u;
2187"), @r"
2188 ╭▸
2189 3 │ a int, b text
2190 │ ─ 2. destination
2191 ‡
2192 8 │ select a from u;
2193 ╰╴ ─ 1. source
2194 ");
2195 }
2196
2197 #[test]
2198 fn goto_create_table_inherits_local_column() {
2199 assert_snapshot!(goto("
2200create table t (
2201 a int, b text
2202);
2203create table u (
2204 c int
2205) inherits (t);
2206select c$0 from u;
2207"), @r"
2208 ╭▸
2209 6 │ c int
2210 │ ─ 2. destination
2211 7 │ ) inherits (t);
2212 8 │ select c from u;
2213 ╰╴ ─ 1. source
2214 ");
2215 }
2216
2217 #[test]
2218 fn goto_create_table_inherits_multiple_parents() {
2219 assert_snapshot!(goto("
2220create table t1 (
2221 a int
2222);
2223create table t2 (
2224 b text
2225);
2226create table u (
2227 c int
2228) inherits (t1, t2);
2229select b$0 from u;
2230"), @r"
2231 ╭▸
2232 6 │ b text
2233 │ ─ 2. destination
2234 ‡
2235 11 │ select b from u;
2236 ╰╴ ─ 1. source
2237 ");
2238 }
2239
2240 #[test]
2241 fn goto_create_foreign_table_inherits_column() {
2242 assert_snapshot!(goto("
2243create server myserver foreign data wrapper postgres_fdw;
2244create table t (
2245 a int, b text
2246);
2247create foreign table u (
2248 c int
2249) inherits (t) server myserver;
2250select a$0 from u;
2251"), @r"
2252 ╭▸
2253 4 │ a int, b text
2254 │ ─ 2. destination
2255 ‡
2256 9 │ select a from u;
2257 ╰╴ ─ 1. source
2258 ");
2259 }
2260
2261 #[test]
2262 fn goto_drop_temp_table_shadows_public() {
2263 assert_snapshot!(goto("
2265create table t();
2266create temp table t();
2267drop table t$0;
2268"), @r"
2269 ╭▸
2270 2 │ create table t();
2271 │ ─ 2. destination
2272 3 │ create temp table t();
2273 4 │ drop table t;
2274 ╰╴ ─ 1. source
2275 ");
2276 }
2277
2278 #[test]
2279 fn goto_drop_public_table_when_temp_exists() {
2280 assert_snapshot!(goto("
2282create table t();
2283create temp table t();
2284drop table public.t$0;
2285"), @r"
2286 ╭▸
2287 2 │ create table t();
2288 │ ─ 2. destination
2289 3 │ create temp table t();
2290 4 │ drop table public.t;
2291 ╰╴ ─ 1. source
2292 ");
2293 }
2294
2295 #[test]
2296 fn goto_drop_table_defined_after() {
2297 assert_snapshot!(goto("
2298drop table t$0;
2299create table t();
2300"), @r"
2301 ╭▸
2302 2 │ drop table t;
2303 │ ─ 1. source
2304 3 │ create table t();
2305 ╰╴ ─ 2. destination
2306 ");
2307 }
2308
2309 #[test]
2310 fn goto_drop_type() {
2311 assert_snapshot!(goto("
2312create type t as enum ('a', 'b');
2313drop type t$0;
2314"), @r"
2315 ╭▸
2316 2 │ create type t as enum ('a', 'b');
2317 │ ─ 2. destination
2318 3 │ drop type t;
2319 ╰╴ ─ 1. source
2320 ");
2321 }
2322
2323 #[test]
2324 fn goto_drop_type_with_schema() {
2325 assert_snapshot!(goto("
2326create type public.t as enum ('a', 'b');
2327drop type t$0;
2328"), @r"
2329 ╭▸
2330 2 │ create type public.t as enum ('a', 'b');
2331 │ ─ 2. destination
2332 3 │ drop type t;
2333 ╰╴ ─ 1. source
2334 ");
2335
2336 assert_snapshot!(goto("
2337create type foo.t as enum ('a', 'b');
2338drop type foo.t$0;
2339"), @r"
2340 ╭▸
2341 2 │ create type foo.t as enum ('a', 'b');
2342 │ ─ 2. destination
2343 3 │ drop type foo.t;
2344 ╰╴ ─ 1. source
2345 ");
2346
2347 goto_not_found(
2348 "
2349create type t as enum ('a', 'b');
2350drop type foo.t$0;
2351",
2352 );
2353 }
2354
2355 #[test]
2356 fn goto_drop_type_defined_after() {
2357 assert_snapshot!(goto("
2358drop type t$0;
2359create type t as enum ('a', 'b');
2360"), @r"
2361 ╭▸
2362 2 │ drop type t;
2363 │ ─ 1. source
2364 3 │ create type t as enum ('a', 'b');
2365 ╰╴ ─ 2. destination
2366 ");
2367 }
2368
2369 #[test]
2370 fn goto_drop_type_composite() {
2371 assert_snapshot!(goto("
2372create type person as (name text, age int);
2373drop type person$0;
2374"), @r"
2375 ╭▸
2376 2 │ create type person as (name text, age int);
2377 │ ────── 2. destination
2378 3 │ drop type person;
2379 ╰╴ ─ 1. source
2380 ");
2381 }
2382
2383 #[test]
2384 fn goto_create_table_type_reference() {
2385 assert_snapshot!(goto("
2386create type person_info as (name text, email text);
2387create table users(id int, member person_info$0);
2388"), @"
2389 ╭▸
2390 2 │ create type person_info as (name text, email text);
2391 │ ─────────── 2. destination
2392 3 │ create table users(id int, member person_info);
2393 ╰╴ ─ 1. source
2394 ");
2395 }
2396
2397 #[test]
2398 fn goto_function_param_table_type() {
2399 assert_snapshot!(goto("
2400create table t(a int, b int);
2401create function b(t$0) returns int as 'select 1' language sql;
2402"), @r"
2403 ╭▸
2404 2 │ create table t(a int, b int);
2405 │ ─ 2. destination
2406 3 │ create function b(t) returns int as 'select 1' language sql;
2407 ╰╴ ─ 1. source
2408 ");
2409 }
2410
2411 #[test]
2412 fn goto_function_param_time_type() {
2413 assert_snapshot!(goto("
2414create type timestamp;
2415create function f(timestamp$0 without time zone) returns text language internal;
2416"), @r"
2417 ╭▸
2418 2 │ create type timestamp;
2419 │ ───────── 2. destination
2420 3 │ create function f(timestamp without time zone) returns text language internal;
2421 ╰╴ ─ 1. source
2422 ");
2423 }
2424
2425 #[test]
2426 fn goto_function_param_time_type_no_timezone() {
2427 assert_snapshot!(goto("
2428create type time;
2429create function f(time$0) returns text language internal;
2430"), @r"
2431 ╭▸
24322 │ create type time;
2433 │ ──── 2. destination
24343 │ create function f(time) returns text language internal;
2435 ╰╴ ─ 1. source
2436");
2437 }
2438
2439 #[test]
2440 fn goto_create_table_type_reference_enum() {
2441 assert_snapshot!(goto("
2442create type mood as enum ('sad', 'ok', 'happy');
2443create table users(id int, mood mood$0);
2444"), @r"
2445 ╭▸
2446 2 │ create type mood as enum ('sad', 'ok', 'happy');
2447 │ ──── 2. destination
2448 3 │ create table users(id int, mood mood);
2449 ╰╴ ─ 1. source
2450 ");
2451 }
2452
2453 #[test]
2454 fn goto_create_table_type_reference_range() {
2455 assert_snapshot!(goto("
2456create type int4_range as range (subtype = int4);
2457create table metrics(id int, span int4_range$0);
2458"), @r"
2459 ╭▸
2460 2 │ create type int4_range as range (subtype = int4);
2461 │ ────────── 2. destination
2462 3 │ create table metrics(id int, span int4_range);
2463 ╰╴ ─ 1. source
2464 ");
2465 }
2466
2467 #[test]
2468 fn goto_create_table_type_reference_input_output() {
2469 assert_snapshot!(goto("
2470create type myint (input = myintin, output = myintout, like = int4);
2471create table data(id int, value myint$0);
2472"), @r"
2473 ╭▸
2474 2 │ create type myint (input = myintin, output = myintout, like = int4);
2475 │ ───── 2. destination
2476 3 │ create table data(id int, value myint);
2477 ╰╴ ─ 1. source
2478 ");
2479 }
2480
2481 #[test]
2482 fn goto_composite_type_field() {
2483 assert_snapshot!(goto("
2484create type person_info as (name text, email text);
2485create table users(id int, member person_info);
2486select (member).name$0 from users;
2487"), @"
2488 ╭▸
2489 2 │ create type person_info as (name text, email text);
2490 │ ──── 2. destination
2491 3 │ create table users(id int, member person_info);
2492 4 │ select (member).name from users;
2493 ╰╴ ─ 1. source
2494 ");
2495 }
2496
2497 #[test]
2498 fn goto_drop_type_range() {
2499 assert_snapshot!(goto("
2500create type int4_range as range (subtype = int4);
2501drop type int4_range$0;
2502"), @r"
2503 ╭▸
2504 2 │ create type int4_range as range (subtype = int4);
2505 │ ────────── 2. destination
2506 3 │ drop type int4_range;
2507 ╰╴ ─ 1. source
2508 ");
2509 }
2510
2511 #[test]
2512 fn goto_drop_domain() {
2513 assert_snapshot!(goto("
2514create domain posint as integer check (value > 0);
2515drop domain posint$0;
2516"), @r"
2517 ╭▸
2518 2 │ create domain posint as integer check (value > 0);
2519 │ ────── 2. destination
2520 3 │ drop domain posint;
2521 ╰╴ ─ 1. source
2522 ");
2523 }
2524
2525 #[test]
2526 fn goto_cast_to_domain() {
2527 assert_snapshot!(goto("
2528create domain posint as integer check (value > 0);
2529select 1::posint$0;
2530"), @r"
2531 ╭▸
2532 2 │ create domain posint as integer check (value > 0);
2533 │ ────── 2. destination
2534 3 │ select 1::posint;
2535 ╰╴ ─ 1. source
2536 ");
2537 }
2538
2539 #[test]
2540 fn goto_drop_type_domain() {
2541 assert_snapshot!(goto("
2542create domain posint as integer check (value > 0);
2543drop type posint$0;
2544"), @r"
2545 ╭▸
2546 2 │ create domain posint as integer check (value > 0);
2547 │ ────── 2. destination
2548 3 │ drop type posint;
2549 ╰╴ ─ 1. source
2550 ");
2551 }
2552
2553 #[test]
2554 fn goto_drop_view() {
2555 assert_snapshot!(goto("
2556create view v as select 1;
2557drop view v$0;
2558"), @r"
2559 ╭▸
2560 2 │ create view v as select 1;
2561 │ ─ 2. destination
2562 3 │ drop view v;
2563 ╰╴ ─ 1. source
2564 ");
2565 }
2566
2567 #[test]
2568 fn goto_drop_materialized_view() {
2569 assert_snapshot!(goto("
2570create materialized view v as select 1;
2571drop materialized view v$0;
2572"), @r"
2573 ╭▸
2574 2 │ create materialized view v as select 1;
2575 │ ─ 2. destination
2576 3 │ drop materialized view v;
2577 ╰╴ ─ 1. source
2578 ");
2579 }
2580
2581 #[test]
2582 fn goto_drop_view_with_schema() {
2583 assert_snapshot!(goto("
2584create view public.v as select 1;
2585drop view v$0;
2586"), @r"
2587 ╭▸
2588 2 │ create view public.v as select 1;
2589 │ ─ 2. destination
2590 3 │ drop view v;
2591 ╰╴ ─ 1. source
2592 ");
2593
2594 assert_snapshot!(goto("
2595create view foo.v as select 1;
2596drop view foo.v$0;
2597"), @r"
2598 ╭▸
2599 2 │ create view foo.v as select 1;
2600 │ ─ 2. destination
2601 3 │ drop view foo.v;
2602 ╰╴ ─ 1. source
2603 ");
2604
2605 goto_not_found(
2606 "
2607create view v as select 1;
2608drop view foo.v$0;
2609",
2610 );
2611 }
2612
2613 #[test]
2614 fn goto_drop_temp_view() {
2615 assert_snapshot!(goto("
2616create temp view v as select 1;
2617drop view v$0;
2618"), @r"
2619 ╭▸
2620 2 │ create temp view v as select 1;
2621 │ ─ 2. destination
2622 3 │ drop view v;
2623 ╰╴ ─ 1. source
2624 ");
2625 }
2626
2627 #[test]
2628 fn goto_select_from_view() {
2629 assert_snapshot!(goto("
2630create view v as select 1;
2631select * from v$0;
2632"), @r"
2633 ╭▸
2634 2 │ create view v as select 1;
2635 │ ─ 2. destination
2636 3 │ select * from v;
2637 ╰╴ ─ 1. source
2638 ");
2639 }
2640
2641 #[test]
2642 fn goto_select_from_materialized_view() {
2643 assert_snapshot!(goto("
2644create materialized view v as select 1;
2645select * from v$0;
2646"), @r"
2647 ╭▸
2648 2 │ create materialized view v as select 1;
2649 │ ─ 2. destination
2650 3 │ select * from v;
2651 ╰╴ ─ 1. source
2652 ");
2653 }
2654
2655 #[test]
2656 fn goto_select_from_view_with_schema() {
2657 assert_snapshot!(goto("
2658create view public.v as select 1;
2659select * from public.v$0;
2660"), @r"
2661 ╭▸
2662 2 │ create view public.v as select 1;
2663 │ ─ 2. destination
2664 3 │ select * from public.v;
2665 ╰╴ ─ 1. source
2666 ");
2667 }
2668
2669 #[test]
2670 fn goto_view_column() {
2671 assert_snapshot!(goto("
2672create view v as select 1 as a;
2673select a$0 from v;
2674"), @r"
2675 ╭▸
2676 2 │ create view v as select 1 as a;
2677 │ ─ 2. destination
2678 3 │ select a from v;
2679 ╰╴ ─ 1. source
2680 ");
2681 }
2682
2683 #[test]
2684 fn goto_view_column_qualified() {
2685 assert_snapshot!(goto("
2686create view v as select 1 as a;
2687select v.a$0 from v;
2688"), @r"
2689 ╭▸
2690 2 │ create view v as select 1 as a;
2691 │ ─ 2. destination
2692 3 │ select v.a from v;
2693 ╰╴ ─ 1. source
2694 ");
2695 }
2696
2697 #[test]
2698 fn goto_create_table_as_column() {
2699 assert_snapshot!(goto("
2700create table t as select 1 a;
2701select a$0 from t;
2702"), @r"
2703 ╭▸
2704 2 │ create table t as select 1 a;
2705 │ ─ 2. destination
2706 3 │ select a from t;
2707 ╰╴ ─ 1. source
2708 ");
2709 }
2710
2711 #[test]
2712 fn goto_select_from_create_table_as() {
2713 assert_snapshot!(goto("
2714create table t as select 1 a;
2715select a from t$0;
2716"), @r"
2717 ╭▸
2718 2 │ create table t as select 1 a;
2719 │ ─ 2. destination
2720 3 │ select a from t;
2721 ╰╴ ─ 1. source
2722 ");
2723 }
2724
2725 #[test]
2726 fn goto_view_with_explicit_column_list() {
2727 assert_snapshot!(goto("
2728create view v(col1) as select 1;
2729select * from v$0;
2730"), @r"
2731 ╭▸
2732 2 │ create view v(col1) as select 1;
2733 │ ─ 2. destination
2734 3 │ select * from v;
2735 ╰╴ ─ 1. source
2736 ");
2737 }
2738
2739 #[test]
2740 fn goto_view_column_with_explicit_column_list() {
2741 assert_snapshot!(goto("
2742 create view v(col1) as select 1;
2743 select col1$0 from v;
2744 "), @r"
2745 ╭▸
2746 2 │ create view v(col1) as select 1;
2747 │ ──── 2. destination
2748 3 │ select col1 from v;
2749 ╰╴ ─ 1. source
2750 ");
2751 }
2752
2753 #[test]
2754 fn goto_view_column_with_schema() {
2755 assert_snapshot!(goto("
2756create view public.v as select 1 as a;
2757select a$0 from public.v;
2758"), @r"
2759 ╭▸
2760 2 │ create view public.v as select 1 as a;
2761 │ ─ 2. destination
2762 3 │ select a from public.v;
2763 ╰╴ ─ 1. source
2764 ");
2765 }
2766
2767 #[test]
2768 fn goto_view_multiple_columns() {
2769 assert_snapshot!(goto("
2770create view v as select 1 as a, 2 as b;
2771select b$0 from v;
2772"), @r"
2773 ╭▸
2774 2 │ create view v as select 1 as a, 2 as b;
2775 │ ─ 2. destination
2776 3 │ select b from v;
2777 ╰╴ ─ 1. source
2778 ");
2779 }
2780
2781 #[test]
2782 fn goto_view_column_from_table() {
2783 assert_snapshot!(goto("
2784create table t(x int, y int);
2785create view v as select x, y from t;
2786select x$0 from v;
2787"), @r"
2788 ╭▸
2789 3 │ create view v as select x, y from t;
2790 │ ─ 2. destination
2791 4 │ select x from v;
2792 ╰╴ ─ 1. source
2793 ");
2794 }
2795
2796 #[test]
2797 fn goto_view_column_with_table_preference() {
2798 assert_snapshot!(goto("
2799create table v(a int);
2800create view vw as select 1 as a;
2801select a$0 from v;
2802"), @r"
2803 ╭▸
2804 2 │ create table v(a int);
2805 │ ─ 2. destination
2806 3 │ create view vw as select 1 as a;
2807 4 │ select a from v;
2808 ╰╴ ─ 1. source
2809 ");
2810 }
2811
2812 #[test]
2813 fn goto_cast_operator() {
2814 assert_snapshot!(goto("
2815create type foo as enum ('a', 'b');
2816select x::foo$0;
2817"), @r"
2818 ╭▸
2819 2 │ create type foo as enum ('a', 'b');
2820 │ ─── 2. destination
2821 3 │ select x::foo;
2822 ╰╴ ─ 1. source
2823 ");
2824 }
2825
2826 #[test]
2827 fn goto_cast_function() {
2828 assert_snapshot!(goto("
2829create type bar as enum ('x', 'y');
2830select cast(x as bar$0);
2831"), @r"
2832 ╭▸
2833 2 │ create type bar as enum ('x', 'y');
2834 │ ─── 2. destination
2835 3 │ select cast(x as bar);
2836 ╰╴ ─ 1. source
2837 ");
2838 }
2839
2840 #[test]
2841 fn goto_cast_with_schema() {
2842 assert_snapshot!(goto("
2843create type public.baz as enum ('m', 'n');
2844select x::public.baz$0;
2845"), @r"
2846 ╭▸
2847 2 │ create type public.baz as enum ('m', 'n');
2848 │ ─── 2. destination
2849 3 │ select x::public.baz;
2850 ╰╴ ─ 1. source
2851 ");
2852 }
2853
2854 #[test]
2855 fn goto_cast_timestamp_without_time_zone() {
2856 assert_snapshot!(goto("
2857create type pg_catalog.timestamp;
2858select ''::timestamp without$0 time zone;
2859"), @r"
2860 ╭▸
2861 2 │ create type pg_catalog.timestamp;
2862 │ ───────── 2. destination
2863 3 │ select ''::timestamp without time zone;
2864 ╰╴ ─ 1. source
2865 ");
2866 }
2867
2868 #[test]
2869 fn goto_cast_timestamp_with_time_zone() {
2870 assert_snapshot!(goto("
2871create type pg_catalog.timestamptz;
2872select ''::timestamp with$0 time zone;
2873"), @r"
2874 ╭▸
2875 2 │ create type pg_catalog.timestamptz;
2876 │ ─────────── 2. destination
2877 3 │ select ''::timestamp with time zone;
2878 ╰╴ ─ 1. source
2879 ");
2880 }
2881
2882 #[test]
2883 fn goto_cast_multirange_type_from_range() {
2884 assert_snapshot!(goto("
2885create type floatrange as range (
2886 subtype = float8,
2887 subtype_diff = float8mi
2888);
2889select '{[1.234, 5.678]}'::floatmultirange$0;
2890"), @r"
2891 ╭▸
2892 2 │ create type floatrange as range (
2893 │ ────────── 2. destination
2894 ‡
2895 6 │ select '{[1.234, 5.678]}'::floatmultirange;
2896 ╰╴ ─ 1. source
2897 ");
2898 }
2899
2900 #[test]
2901 fn goto_cast_multirange_special_type_name_string() {
2902 assert_snapshot!(goto("
2903create type floatrange as range (
2904 subtype = float8,
2905 subtype_diff = float8mi,
2906 multirange_type_name = 'floatmulirangething'
2907);
2908select '{[1.234, 5.678]}'::floatmulirangething$0;
2909"), @r"
2910 ╭▸
2911 2 │ create type floatrange as range (
2912 │ ────────── 2. destination
2913 ‡
2914 7 │ select '{[1.234, 5.678]}'::floatmulirangething;
2915 ╰╴ ─ 1. source
2916 ");
2917 }
2918
2919 #[test]
2920 fn goto_cast_multirange_special_type_name_ident() {
2921 assert_snapshot!(goto("
2922create type floatrange as range (
2923 subtype = float8,
2924 subtype_diff = float8mi,
2925 multirange_type_name = floatrangemutirange
2926);
2927select '{[1.234, 5.678]}'::floatrangemutirange$0;
2928"), @r"
2929 ╭▸
2930 2 │ create type floatrange as range (
2931 │ ────────── 2. destination
2932 ‡
2933 7 │ select '{[1.234, 5.678]}'::floatrangemutirange;
2934 ╰╴ ─ 1. source
2935 ");
2936 }
2937
2938 #[test]
2939 fn goto_cast_multirange_edge_case_type_from_range() {
2940 assert_snapshot!(goto("
2942create type floatrangerange as range (
2943 subtype = float8,
2944 subtype_diff = float8mi
2945);
2946select '{[1.234, 5.678]}'::floatmultirangerange$0;
2947"), @r"
2948 ╭▸
2949 2 │ create type floatrangerange as range (
2950 │ ─────────────── 2. destination
2951 ‡
2952 6 │ select '{[1.234, 5.678]}'::floatmultirangerange;
2953 ╰╴ ─ 1. source
2954 ");
2955 }
2956
2957 #[test]
2958 fn goto_cast_boolean_falls_back_to_bool() {
2959 assert_snapshot!(goto("
2960create type pg_catalog.bool;
2961select '1'::boolean$0;
2962"), @"
2963 ╭▸
2964 2 │ create type pg_catalog.bool;
2965 │ ──── 2. destination
2966 3 │ select '1'::boolean;
2967 ╰╴ ─ 1. source
2968 ");
2969 }
2970
2971 #[test]
2972 fn goto_cast_decimal_falls_back_to_numeric() {
2973 assert_snapshot!(goto("
2974create type pg_catalog.numeric;
2975select 1::decimal$0(10, 2);
2976"), @"
2977 ╭▸
2978 2 │ create type pg_catalog.numeric;
2979 │ ─────── 2. destination
2980 3 │ select 1::decimal(10, 2);
2981 ╰╴ ─ 1. source
2982 ");
2983 }
2984
2985 #[test]
2986 fn goto_cast_float_falls_back_to_float8() {
2987 assert_snapshot!(goto("
2988create type pg_catalog.float8;
2989select 1::float$0;
2990"), @"
2991 ╭▸
2992 2 │ create type pg_catalog.float8;
2993 │ ────── 2. destination
2994 3 │ select 1::float;
2995 ╰╴ ─ 1. source
2996 ");
2997 }
2998
2999 #[test]
3000 fn goto_cast_bigint_falls_back_to_int8() {
3001 assert_snapshot!(goto("
3002create type pg_catalog.int8;
3003select 1::bigint$0;
3004"), @r"
3005 ╭▸
3006 2 │ create type pg_catalog.int8;
3007 │ ──── 2. destination
3008 3 │ select 1::bigint;
3009 ╰╴ ─ 1. source
3010 ");
3011 }
3012
3013 #[test]
3014 fn goto_cast_real_falls_back_to_float4() {
3015 assert_snapshot!(goto("
3016create type pg_catalog.float4;
3017select 1::real$0;
3018"), @"
3019 ╭▸
3020 2 │ create type pg_catalog.float4;
3021 │ ────── 2. destination
3022 3 │ select 1::real;
3023 ╰╴ ─ 1. source
3024 ");
3025 }
3026
3027 #[test]
3028 fn goto_cast_bigint_prefers_user_type() {
3029 assert_snapshot!(goto("
3030create type bigint;
3031create type pg_catalog.int8;
3032select 1::bigint$0;
3033"), @r"
3034 ╭▸
3035 2 │ create type bigint;
3036 │ ────── 2. destination
3037 3 │ create type pg_catalog.int8;
3038 4 │ select 1::bigint;
3039 ╰╴ ─ 1. source
3040 ");
3041 }
3042
3043 #[test]
3044 fn goto_cast_smallserial_falls_back_to_int2() {
3045 assert_snapshot!(goto("
3046create type pg_catalog.int2;
3047select 1::smallserial$0;
3048"), @r"
3049 ╭▸
3050 2 │ create type pg_catalog.int2;
3051 │ ──── 2. destination
3052 3 │ select 1::smallserial;
3053 ╰╴ ─ 1. source
3054 ");
3055 }
3056
3057 #[test]
3058 fn goto_cast_serial2_falls_back_to_int2() {
3059 assert_snapshot!(goto("
3060create type pg_catalog.int2;
3061select 1::serial2$0;
3062"), @r"
3063 ╭▸
3064 2 │ create type pg_catalog.int2;
3065 │ ──── 2. destination
3066 3 │ select 1::serial2;
3067 ╰╴ ─ 1. source
3068 ");
3069 }
3070
3071 #[test]
3072 fn goto_cast_serial_falls_back_to_int4() {
3073 assert_snapshot!(goto("
3074create type pg_catalog.int4;
3075select 1::serial$0;
3076"), @r"
3077 ╭▸
3078 2 │ create type pg_catalog.int4;
3079 │ ──── 2. destination
3080 3 │ select 1::serial;
3081 ╰╴ ─ 1. source
3082 ");
3083 }
3084
3085 #[test]
3086 fn goto_cast_serial4_falls_back_to_int4() {
3087 assert_snapshot!(goto("
3088create type pg_catalog.int4;
3089select 1::serial4$0;
3090"), @r"
3091 ╭▸
3092 2 │ create type pg_catalog.int4;
3093 │ ──── 2. destination
3094 3 │ select 1::serial4;
3095 ╰╴ ─ 1. source
3096 ");
3097 }
3098
3099 #[test]
3100 fn goto_cast_bigserial_falls_back_to_int8() {
3101 assert_snapshot!(goto("
3102create type pg_catalog.int8;
3103select 1::bigserial$0;
3104"), @r"
3105 ╭▸
3106 2 │ create type pg_catalog.int8;
3107 │ ──── 2. destination
3108 3 │ select 1::bigserial;
3109 ╰╴ ─ 1. source
3110 ");
3111 }
3112
3113 #[test]
3114 fn goto_cast_serial8_falls_back_to_int8() {
3115 assert_snapshot!(goto("
3116create type pg_catalog.int8;
3117select 1::serial8$0;
3118"), @r"
3119 ╭▸
3120 2 │ create type pg_catalog.int8;
3121 │ ──── 2. destination
3122 3 │ select 1::serial8;
3123 ╰╴ ─ 1. source
3124 ");
3125 }
3126
3127 #[test]
3128 fn goto_cast_int_falls_back_to_int4() {
3129 assert_snapshot!(goto("
3130create type pg_catalog.int4;
3131select 1::int$0;
3132"), @r"
3133 ╭▸
3134 2 │ create type pg_catalog.int4;
3135 │ ──── 2. destination
3136 3 │ select 1::int;
3137 ╰╴ ─ 1. source
3138 ");
3139 }
3140
3141 #[test]
3142 fn goto_cast_integer_falls_back_to_int4() {
3143 assert_snapshot!(goto("
3144create type pg_catalog.int4;
3145select 1::integer$0;
3146"), @r"
3147 ╭▸
3148 2 │ create type pg_catalog.int4;
3149 │ ──── 2. destination
3150 3 │ select 1::integer;
3151 ╰╴ ─ 1. source
3152 ");
3153 }
3154
3155 #[test]
3156 fn goto_cast_smallint_falls_back_to_int2() {
3157 assert_snapshot!(goto("
3158create type pg_catalog.int2;
3159select 1::smallint$0;
3160"), @r"
3161 ╭▸
3162 2 │ create type pg_catalog.int2;
3163 │ ──── 2. destination
3164 3 │ select 1::smallint;
3165 ╰╴ ─ 1. source
3166 ");
3167 }
3168
3169 #[test]
3170 fn goto_cast_double_precision_falls_back_to_float8() {
3171 assert_snapshot!(goto("
3172create type pg_catalog.float8;
3173select '1'::double precision[]$0;
3174"), @r"
3175 ╭▸
3176 2 │ create type pg_catalog.float8;
3177 │ ────── 2. destination
3178 3 │ select '1'::double precision[];
3179 ╰╴ ─ 1. source
3180 ");
3181 }
3182
3183 #[test]
3184 fn goto_cast_varchar_with_modifier() {
3185 assert_snapshot!(goto("
3186create type pg_catalog.varchar;
3187select '1'::varchar$0(1);
3188"), @r"
3189 ╭▸
3190 2 │ create type pg_catalog.varchar;
3191 │ ─────── 2. destination
3192 3 │ select '1'::varchar(1);
3193 ╰╴ ─ 1. source
3194 ");
3195 }
3196
3197 #[test]
3198 fn goto_cast_composite_type() {
3199 assert_snapshot!(goto("
3200create type person_info as (name varchar(50), age int);
3201select ('Alice', 30)::person_info$0;
3202"), @r"
3203 ╭▸
3204 2 │ create type person_info as (name varchar(50), age int);
3205 │ ─────────── 2. destination
3206 3 │ select ('Alice', 30)::person_info;
3207 ╰╴ ─ 1. source
3208 ");
3209 }
3210
3211 #[test]
3212 fn goto_cast_composite_type_in_cte() {
3213 assert_snapshot!(goto("
3214create type person_info as (name varchar(50), age int);
3215with team as (
3216 select 1 as id, ('Alice', 30)::person_info$0 as member
3217)
3218select * from team;
3219"), @r"
3220 ╭▸
3221 2 │ create type person_info as (name varchar(50), age int);
3222 │ ─────────── 2. destination
3223 3 │ with team as (
3224 4 │ select 1 as id, ('Alice', 30)::person_info as member
3225 ╰╴ ─ 1. source
3226 ");
3227 }
3228
3229 #[test]
3230 fn goto_composite_type_field_name() {
3231 assert_snapshot!(goto("
3232create type person_info as (name varchar(50), age int);
3233with team as (
3234 select 1 as id, ('Alice', 30)::person_info as member
3235)
3236select (member).name$0, (member).age from team;
3237"), @r"
3238 ╭▸
3239 2 │ create type person_info as (name varchar(50), age int);
3240 │ ──── 2. destination
3241 ‡
3242 6 │ select (member).name, (member).age from team;
3243 ╰╴ ─ 1. source
3244 ");
3245 }
3246
3247 #[test]
3248 fn goto_composite_type_field_in_where() {
3249 assert_snapshot!(goto("
3250create type person_info as (name varchar(50), age int);
3251with team as (
3252 select 1 as id, ('Alice', 30)::person_info as member
3253 union all
3254 select 2, ('Bob', 25)::person_info
3255)
3256select (member).name, (member).age
3257from team
3258where (member).age$0 >= 18;
3259"), @r"
3260 ╭▸
3261 2 │ create type person_info as (name varchar(50), age int);
3262 │ ─── 2. destination
3263 ‡
3264 10 │ where (member).age >= 18;
3265 ╰╴ ─ 1. source
3266 ");
3267 }
3268
3269 #[test]
3270 fn goto_composite_type_field_base() {
3271 assert_snapshot!(goto("
3272create type person_info as (name varchar(50), age int);
3273with team as (
3274 select 1 as id, ('Alice', 30)::person_info as member
3275)
3276select (member$0).age from team;
3277"), @r"
3278 ╭▸
3279 4 │ select 1 as id, ('Alice', 30)::person_info as member
3280 │ ────── 2. destination
3281 5 │ )
3282 6 │ select (member).age from team;
3283 ╰╴ ─ 1. source
3284 ");
3285 }
3286
3287 #[test]
3288 fn goto_composite_type_field_nested_parens() {
3289 assert_snapshot!(goto("
3290create type person_info as (name varchar(50), age int);
3291with team as (
3292 select 1 as id, ('Alice', 30)::person_info as member
3293)
3294select ((((member))).name$0) from team;
3295"), @r"
3296 ╭▸
3297 2 │ create type person_info as (name varchar(50), age int);
3298 │ ──── 2. destination
3299 ‡
3300 6 │ select ((((member))).name) from team;
3301 ╰╴ ─ 1. source
3302 ");
3303 }
3304
3305 #[test]
3306 fn begin_to_rollback() {
3307 assert_snapshot!(goto(
3308 "
3309begin$0;
3310select 1;
3311rollback;
3312commit;
3313",
3314 ), @r"
3315 ╭▸
3316 2 │ begin;
3317 │ ─ 1. source
3318 3 │ select 1;
3319 4 │ rollback;
3320 ╰╴──────── 2. destination
3321 ");
3322 }
3323
3324 #[test]
3325 fn commit_to_begin() {
3326 assert_snapshot!(goto(
3327 "
3328begin;
3329select 1;
3330commit$0;
3331",
3332 ), @r"
3333 ╭▸
3334 2 │ begin;
3335 │ ───── 2. destination
3336 3 │ select 1;
3337 4 │ commit;
3338 ╰╴ ─ 1. source
3339 ");
3340 }
3341
3342 #[test]
3343 fn begin_to_commit() {
3344 assert_snapshot!(goto(
3345 "
3346begin$0;
3347select 1;
3348commit;
3349",
3350 ), @r"
3351 ╭▸
3352 2 │ begin;
3353 │ ─ 1. source
3354 3 │ select 1;
3355 4 │ commit;
3356 ╰╴────── 2. destination
3357 ");
3358 }
3359
3360 #[test]
3361 fn commit_to_start_transaction() {
3362 assert_snapshot!(goto(
3363 "
3364start transaction;
3365select 1;
3366commit$0;
3367",
3368 ), @r"
3369 ╭▸
3370 2 │ start transaction;
3371 │ ───────────────── 2. destination
3372 3 │ select 1;
3373 4 │ commit;
3374 ╰╴ ─ 1. source
3375 ");
3376 }
3377
3378 #[test]
3379 fn start_transaction_to_commit() {
3380 assert_snapshot!(goto(
3381 "
3382start$0 transaction;
3383select 1;
3384commit;
3385",
3386 ), @r"
3387 ╭▸
3388 2 │ start transaction;
3389 │ ─ 1. source
3390 3 │ select 1;
3391 4 │ commit;
3392 ╰╴────── 2. destination
3393 ");
3394 }
3395
3396 #[test]
3397 fn goto_with_search_path() {
3398 assert_snapshot!(goto(r#"
3399set search_path to "foo", public;
3400create table foo.t();
3401drop table t$0;
3402"#), @r"
3403 ╭▸
3404 3 │ create table foo.t();
3405 │ ─ 2. destination
3406 4 │ drop table t;
3407 ╰╴ ─ 1. source
3408 ");
3409 }
3410
3411 #[test]
3412 fn goto_with_search_path_and_unspecified_table() {
3413 assert_snapshot!(goto(r#"
3414set search_path to foo,bar;
3415create table t();
3416drop table foo.t$0;
3417"#), @r"
3418 ╭▸
3419 3 │ create table t();
3420 │ ─ 2. destination
3421 4 │ drop table foo.t;
3422 ╰╴ ─ 1. source
3423 ");
3424 }
3425
3426 #[test]
3427 fn goto_column_not_in_cte_but_in_table() {
3428 goto_not_found(
3430 r"
3431create table t (c int);
3432with t as (select 1 a)
3433select c$0 from t;
3434",
3435 );
3436 }
3437
3438 #[test]
3439 fn goto_with_search_path_empty() {
3440 goto_not_found(
3441 r#"
3442set search_path = '';
3443create table t();
3444drop table t$0;
3445"#,
3446 );
3447 }
3448
3449 #[test]
3450 fn goto_with_search_path_like_variable() {
3451 goto_not_found(
3453 "
3454set bar.search_path to foo, public;
3455create table foo.t();
3456drop table t$0;
3457",
3458 )
3459 }
3460
3461 #[test]
3462 fn goto_with_search_path_second_schema() {
3463 assert_snapshot!(goto("
3464set search_path to foo, bar, public;
3465create table bar.t();
3466drop table t$0;
3467"), @r"
3468 ╭▸
3469 3 │ create table bar.t();
3470 │ ─ 2. destination
3471 4 │ drop table t;
3472 ╰╴ ─ 1. source
3473 ");
3474 }
3475
3476 #[test]
3477 fn goto_with_search_path_skips_first() {
3478 assert_snapshot!(goto("
3479set search_path to foo, bar, public;
3480create table foo.t();
3481create table bar.t();
3482drop table t$0;
3483"), @r"
3484 ╭▸
3485 3 │ create table foo.t();
3486 │ ─ 2. destination
3487 4 │ create table bar.t();
3488 5 │ drop table t;
3489 ╰╴ ─ 1. source
3490 ");
3491 }
3492
3493 #[test]
3494 fn goto_without_search_path_uses_default() {
3495 assert_snapshot!(goto("
3496create table foo.t();
3497create table public.t();
3498drop table t$0;
3499"), @r"
3500 ╭▸
3501 3 │ create table public.t();
3502 │ ─ 2. destination
3503 4 │ drop table t;
3504 ╰╴ ─ 1. source
3505 ");
3506 }
3507
3508 #[test]
3509 fn goto_with_set_schema() {
3510 assert_snapshot!(goto("
3511set schema 'myschema';
3512create table myschema.t();
3513drop table t$0;
3514"), @r"
3515 ╭▸
3516 3 │ create table myschema.t();
3517 │ ─ 2. destination
3518 4 │ drop table t;
3519 ╰╴ ─ 1. source
3520 ");
3521 }
3522
3523 #[test]
3524 fn goto_with_set_schema_ignores_other_schemas() {
3525 assert_snapshot!(goto("
3526set schema 'myschema';
3527create table public.t();
3528create table myschema.t();
3529drop table t$0;
3530"), @r"
3531 ╭▸
3532 4 │ create table myschema.t();
3533 │ ─ 2. destination
3534 5 │ drop table t;
3535 ╰╴ ─ 1. source
3536 ");
3537 }
3538
3539 #[test]
3540 fn goto_with_search_path_changed_twice() {
3541 assert_snapshot!(goto("
3542set search_path to foo;
3543create table foo.t();
3544set search_path to bar;
3545create table bar.t();
3546drop table t$0;
3547"), @r"
3548 ╭▸
3549 5 │ create table bar.t();
3550 │ ─ 2. destination
3551 6 │ drop table t;
3552 ╰╴ ─ 1. source
3553 ");
3554
3555 assert_snapshot!(goto("
3556set search_path to foo;
3557create table foo.t();
3558drop table t$0;
3559set search_path to bar;
3560create table bar.t();
3561drop table t;
3562"), @r"
3563 ╭▸
3564 3 │ create table foo.t();
3565 │ ─ 2. destination
3566 4 │ drop table t;
3567 ╰╴ ─ 1. source
3568 ");
3569 }
3570
3571 #[test]
3572 fn goto_with_empty_search_path() {
3573 goto_not_found(
3574 "
3575set search_path to '';
3576create table public.t();
3577drop table t$0;
3578",
3579 )
3580 }
3581
3582 #[test]
3583 fn goto_with_search_path_uppercase() {
3584 assert_snapshot!(goto("
3585SET SEARCH_PATH TO foo;
3586create table foo.t();
3587drop table t$0;
3588"), @r"
3589 ╭▸
3590 3 │ create table foo.t();
3591 │ ─ 2. destination
3592 4 │ drop table t;
3593 ╰╴ ─ 1. source
3594 ");
3595 }
3596
3597 #[test]
3598 fn goto_table_stmt() {
3599 assert_snapshot!(goto("
3600create table t();
3601table t$0;
3602"), @r"
3603 ╭▸
3604 2 │ create table t();
3605 │ ─ 2. destination
3606 3 │ table t;
3607 ╰╴ ─ 1. source
3608 ");
3609 }
3610
3611 #[test]
3612 fn goto_table_stmt_with_schema() {
3613 assert_snapshot!(goto("
3614create table public.t();
3615table public.t$0;
3616"), @r"
3617 ╭▸
3618 2 │ create table public.t();
3619 │ ─ 2. destination
3620 3 │ table public.t;
3621 ╰╴ ─ 1. source
3622 ");
3623 }
3624
3625 #[test]
3626 fn goto_table_stmt_with_search_path() {
3627 assert_snapshot!(goto("
3628set search_path to foo;
3629create table foo.t();
3630table t$0;
3631"), @r"
3632 ╭▸
3633 3 │ create table foo.t();
3634 │ ─ 2. destination
3635 4 │ table t;
3636 ╰╴ ─ 1. source
3637 ");
3638 }
3639
3640 #[test]
3641 fn goto_drop_index() {
3642 assert_snapshot!(goto("
3643create index idx_name on t(x);
3644drop index idx_name$0;
3645"), @r"
3646 ╭▸
3647 2 │ create index idx_name on t(x);
3648 │ ──────── 2. destination
3649 3 │ drop index idx_name;
3650 ╰╴ ─ 1. source
3651 ");
3652 }
3653
3654 #[test]
3655 fn goto_drop_index_with_schema() {
3656 assert_snapshot!(goto(r#"
3657set search_path to public;
3658create index idx_name on t(x);
3659drop index public.idx_name$0;
3660"#), @r"
3661 ╭▸
3662 3 │ create index idx_name on t(x);
3663 │ ──────── 2. destination
3664 4 │ drop index public.idx_name;
3665 ╰╴ ─ 1. source
3666 ");
3667 }
3668
3669 #[test]
3670 fn goto_drop_index_defined_after() {
3671 assert_snapshot!(goto("
3672drop index idx_name$0;
3673create index idx_name on t(x);
3674"), @r"
3675 ╭▸
3676 2 │ drop index idx_name;
3677 │ ─ 1. source
3678 3 │ create index idx_name on t(x);
3679 ╰╴ ──────── 2. destination
3680 ");
3681 }
3682
3683 #[test]
3684 fn goto_index_definition_returns_self() {
3685 assert_snapshot!(goto("
3686create index idx_name$0 on t(x);
3687"), @r"
3688 ╭▸
3689 2 │ create index idx_name on t(x);
3690 │ ┬──────┬
3691 │ │ │
3692 │ │ 1. source
3693 ╰╴ 2. destination
3694 ");
3695 }
3696
3697 #[test]
3698 fn goto_drop_index_with_search_path() {
3699 assert_snapshot!(goto(r#"
3700create index idx_name on t(x);
3701set search_path to bar;
3702create index idx_name on f(x);
3703set search_path to default;
3704drop index idx_name$0;
3705"#), @r"
3706 ╭▸
3707 2 │ create index idx_name on t(x);
3708 │ ──────── 2. destination
3709 ‡
3710 6 │ drop index idx_name;
3711 ╰╴ ─ 1. source
3712 ");
3713 }
3714
3715 #[test]
3716 fn goto_drop_index_multiple() {
3717 assert_snapshot!(goto("
3718create index idx1 on t(x);
3719create index idx2 on t(y);
3720drop index idx1, idx2$0;
3721"), @r"
3722 ╭▸
3723 3 │ create index idx2 on t(y);
3724 │ ──── 2. destination
3725 4 │ drop index idx1, idx2;
3726 ╰╴ ─ 1. source
3727 ");
3728 }
3729
3730 #[test]
3731 fn goto_create_index_table() {
3732 assert_snapshot!(goto("
3733create table users(id int);
3734create index idx_users on users$0(id);
3735"), @r"
3736 ╭▸
3737 2 │ create table users(id int);
3738 │ ───── 2. destination
3739 3 │ create index idx_users on users(id);
3740 ╰╴ ─ 1. source
3741 ");
3742 }
3743
3744 #[test]
3745 fn goto_create_index_table_with_schema() {
3746 assert_snapshot!(goto("
3747create table public.users(id int);
3748create index idx_users on public.users$0(id);
3749"), @r"
3750 ╭▸
3751 2 │ create table public.users(id int);
3752 │ ───── 2. destination
3753 3 │ create index idx_users on public.users(id);
3754 ╰╴ ─ 1. source
3755 ");
3756 }
3757
3758 #[test]
3759 fn goto_create_index_table_with_search_path() {
3760 assert_snapshot!(goto(r#"
3761set search_path to foo;
3762create table foo.users(id int);
3763create index idx_users on users$0(id);
3764"#), @r"
3765 ╭▸
3766 3 │ create table foo.users(id int);
3767 │ ───── 2. destination
3768 4 │ create index idx_users on users(id);
3769 ╰╴ ─ 1. source
3770 ");
3771 }
3772
3773 #[test]
3774 fn goto_create_index_temp_table() {
3775 assert_snapshot!(goto("
3776create temp table users(id int);
3777create index idx_users on users$0(id);
3778"), @r"
3779 ╭▸
3780 2 │ create temp table users(id int);
3781 │ ───── 2. destination
3782 3 │ create index idx_users on users(id);
3783 ╰╴ ─ 1. source
3784 ");
3785 }
3786
3787 #[test]
3788 fn goto_create_index_column() {
3789 assert_snapshot!(goto("
3790create table users(id int, email text);
3791create index idx_email on users(email$0);
3792"), @r"
3793 ╭▸
3794 2 │ create table users(id int, email text);
3795 │ ───── 2. destination
3796 3 │ create index idx_email on users(email);
3797 ╰╴ ─ 1. source
3798 ");
3799 }
3800
3801 #[test]
3802 fn goto_create_index_first_column() {
3803 assert_snapshot!(goto("
3804create table users(id int, email text);
3805create index idx_id on users(id$0);
3806"), @r"
3807 ╭▸
3808 2 │ create table users(id int, email text);
3809 │ ── 2. destination
3810 3 │ create index idx_id on users(id);
3811 ╰╴ ─ 1. source
3812 ");
3813 }
3814
3815 #[test]
3816 fn goto_create_index_multiple_columns() {
3817 assert_snapshot!(goto("
3818create table users(id int, email text, name text);
3819create index idx_users on users(id, email$0, name);
3820"), @r"
3821 ╭▸
3822 2 │ create table users(id int, email text, name text);
3823 │ ───── 2. destination
3824 3 │ create index idx_users on users(id, email, name);
3825 ╰╴ ─ 1. source
3826 ");
3827 }
3828
3829 #[test]
3830 fn goto_create_index_column_with_schema() {
3831 assert_snapshot!(goto("
3832create table public.users(id int, email text);
3833create index idx_email on public.users(email$0);
3834"), @r"
3835 ╭▸
3836 2 │ create table public.users(id int, email text);
3837 │ ───── 2. destination
3838 3 │ create index idx_email on public.users(email);
3839 ╰╴ ─ 1. source
3840 ");
3841 }
3842
3843 #[test]
3844 fn goto_create_index_column_temp_table() {
3845 assert_snapshot!(goto("
3846create temp table users(id int, email text);
3847create index idx_email on users(email$0);
3848"), @r"
3849 ╭▸
3850 2 │ create temp table users(id int, email text);
3851 │ ───── 2. destination
3852 3 │ create index idx_email on users(email);
3853 ╰╴ ─ 1. source
3854 ");
3855 }
3856
3857 #[test]
3858 fn goto_drop_function() {
3859 assert_snapshot!(goto("
3860create function foo() returns int as $$ select 1 $$ language sql;
3861drop function foo$0();
3862"), @r"
3863 ╭▸
3864 2 │ create function foo() returns int as $$ select 1 $$ language sql;
3865 │ ─── 2. destination
3866 3 │ drop function foo();
3867 ╰╴ ─ 1. source
3868 ");
3869 }
3870
3871 #[test]
3872 fn goto_drop_function_with_schema() {
3873 assert_snapshot!(goto("
3874set search_path to public;
3875create function foo() returns int as $$ select 1 $$ language sql;
3876drop function public.foo$0();
3877"), @r"
3878 ╭▸
3879 3 │ create function foo() returns int as $$ select 1 $$ language sql;
3880 │ ─── 2. destination
3881 4 │ drop function public.foo();
3882 ╰╴ ─ 1. source
3883 ");
3884 }
3885
3886 #[test]
3887 fn goto_drop_function_defined_after() {
3888 assert_snapshot!(goto("
3889drop function foo$0();
3890create function foo() returns int as $$ select 1 $$ language sql;
3891"), @r"
3892 ╭▸
3893 2 │ drop function foo();
3894 │ ─ 1. source
3895 3 │ create function foo() returns int as $$ select 1 $$ language sql;
3896 ╰╴ ─── 2. destination
3897 ");
3898 }
3899
3900 #[test]
3901 fn goto_function_definition_returns_self() {
3902 assert_snapshot!(goto("
3903create function foo$0() returns int as $$ select 1 $$ language sql;
3904"), @r"
3905 ╭▸
3906 2 │ create function foo() returns int as $$ select 1 $$ language sql;
3907 │ ┬─┬
3908 │ │ │
3909 │ │ 1. source
3910 ╰╴ 2. destination
3911 ");
3912 }
3913
3914 #[test]
3915 fn goto_drop_function_with_search_path() {
3916 assert_snapshot!(goto("
3917create function foo() returns int as $$ select 1 $$ language sql;
3918set search_path to bar;
3919create function foo() returns int as $$ select 1 $$ language sql;
3920set search_path to default;
3921drop function foo$0();
3922"), @r"
3923 ╭▸
3924 2 │ create function foo() returns int as $$ select 1 $$ language sql;
3925 │ ─── 2. destination
3926 ‡
3927 6 │ drop function foo();
3928 ╰╴ ─ 1. source
3929 ");
3930 }
3931
3932 #[test]
3933 fn goto_drop_function_multiple() {
3934 assert_snapshot!(goto("
3935create function foo() returns int as $$ select 1 $$ language sql;
3936create function bar() returns int as $$ select 1 $$ language sql;
3937drop function foo(), bar$0();
3938"), @r"
3939 ╭▸
3940 3 │ create function bar() returns int as $$ select 1 $$ language sql;
3941 │ ─── 2. destination
3942 4 │ drop function foo(), bar();
3943 ╰╴ ─ 1. source
3944 ");
3945 }
3946
3947 #[test]
3948 fn goto_drop_function_overloaded() {
3949 assert_snapshot!(goto("
3950create function add(complex) returns complex as $$ select null $$ language sql;
3951create function add(bigint) returns bigint as $$ select 1 $$ language sql;
3952drop function add$0(complex);
3953"), @r"
3954 ╭▸
3955 2 │ create function add(complex) returns complex as $$ select null $$ language sql;
3956 │ ─── 2. destination
3957 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
3958 4 │ drop function add(complex);
3959 ╰╴ ─ 1. source
3960 ");
3961 }
3962
3963 #[test]
3964 fn goto_drop_function_second_overload() {
3965 assert_snapshot!(goto("
3966create function add(complex) returns complex as $$ select null $$ language sql;
3967create function add(bigint) returns bigint as $$ select 1 $$ language sql;
3968drop function add$0(bigint);
3969"), @r"
3970 ╭▸
3971 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
3972 │ ─── 2. destination
3973 4 │ drop function add(bigint);
3974 ╰╴ ─ 1. source
3975 ");
3976 }
3977
3978 #[test]
3979 fn goto_select_function_call() {
3980 assert_snapshot!(goto("
3981create function foo() returns int as $$ select 1 $$ language sql;
3982select foo$0();
3983"), @r"
3984 ╭▸
3985 2 │ create function foo() returns int as $$ select 1 $$ language sql;
3986 │ ─── 2. destination
3987 3 │ select foo();
3988 ╰╴ ─ 1. source
3989 ");
3990 }
3991
3992 #[test]
3993 fn goto_select_column_from_function_return_table() {
3994 assert_snapshot!(goto(r#"
3995create function dup(int) returns table(f1 int, f2 text)
3996 as ''
3997 language sql;
3998
3999select f1$0 from dup(42);
4000"#), @r"
4001 ╭▸
4002 2 │ create function dup(int) returns table(f1 int, f2 text)
4003 │ ── 2. destination
4004 ‡
4005 6 │ select f1 from dup(42);
4006 ╰╴ ─ 1. source
4007 ");
4008 }
4009
4010 #[test]
4011 fn goto_select_column_from_function_return_table_with_schema() {
4012 assert_snapshot!(goto(r#"
4013create function myschema.dup(int) returns table(f1 int, f2 text)
4014 as ''
4015 language sql;
4016create function otherschema.dup(int) returns table(f1 int, f2 text)
4017 as ''
4018 language sql;
4019
4020select f1$0 from myschema.dup(42);
4021"#), @r"
4022 ╭▸
4023 2 │ create function myschema.dup(int) returns table(f1 int, f2 text)
4024 │ ── 2. destination
4025 ‡
4026 9 │ select f1 from myschema.dup(42);
4027 ╰╴ ─ 1. source
4028 ");
4029 }
4030
4031 #[test]
4032 fn goto_select_column_from_function_return_table_paren() {
4033 assert_snapshot!(goto(r#"
4034create function dup(int) returns table(f1 int, f2 text)
4035 as ''
4036 language sql;
4037
4038select (dup(42)).f2$0;
4039"#), @r"
4040 ╭▸
4041 2 │ create function dup(int) returns table(f1 int, f2 text)
4042 │ ── 2. destination
4043 ‡
4044 6 │ select (dup(42)).f2;
4045 ╰╴ ─ 1. source
4046 ");
4047 }
4048
4049 #[test]
4050 fn goto_select_column_from_function_return_table_qualified() {
4051 assert_snapshot!(goto(r#"
4052create function dup(int) returns table(f1 int, f2 text)
4053 as ''
4054 language sql;
4055
4056select dup.f1$0 from dup(42);
4057"#), @r"
4058 ╭▸
4059 2 │ create function dup(int) returns table(f1 int, f2 text)
4060 │ ── 2. destination
4061 ‡
4062 6 │ select dup.f1 from dup(42);
4063 ╰╴ ─ 1. source
4064 ");
4065 }
4066
4067 #[test]
4068 fn goto_select_column_from_function_return_table_qualified_function_name() {
4069 assert_snapshot!(goto(r#"
4070create function dup(int) returns table(f1 int, f2 text)
4071 as ''
4072 language sql;
4073
4074select dup$0.f1 from dup(42);
4075"#), @r"
4076 ╭▸
4077 2 │ create function dup(int) returns table(f1 int, f2 text)
4078 │ ─── 2. destination
4079 ‡
4080 6 │ select dup.f1 from dup(42);
4081 ╰╴ ─ 1. source
4082 ");
4083 }
4084
4085 #[test]
4086 fn goto_select_column_from_function_return_table_qualified_function_name_with_alias() {
4087 assert_snapshot!(goto(r#"
4088create function dup(int) returns table(f1 int, f2 text)
4089 as ''
4090 language sql;
4091
4092select dup$0.f2 from dup(42) as dup;
4093"#), @r"
4094 ╭▸
4095 6 │ select dup.f2 from dup(42) as dup;
4096 ╰╴ ─ 1. source ─── 2. destination
4097 ");
4098 }
4099
4100 #[test]
4101 fn goto_select_column_from_function_return_table_alias_list() {
4102 assert_snapshot!(goto(r#"
4103create function dup(int) returns table(f1 int, f2 text)
4104 as ''
4105 language sql;
4106
4107select a$0 from dup(42) t(a, b);
4108"#), @r"
4109 ╭▸
4110 6 │ select a from dup(42) t(a, b);
4111 ╰╴ ─ 1. source ─ 2. destination
4112 ");
4113 }
4114
4115 #[test]
4116 fn goto_select_column_from_function_return_table_alias_list_qualified_partial() {
4117 assert_snapshot!(goto(r#"
4118create function dup(int) returns table(f1 int, f2 text)
4119 as ''
4120 language sql;
4121
4122select u.f2$0 from dup(42) as u(x);
4123"#), @r"
4124 ╭▸
4125 2 │ create function dup(int) returns table(f1 int, f2 text)
4126 │ ── 2. destination
4127 ‡
4128 6 │ select u.f2 from dup(42) as u(x);
4129 ╰╴ ─ 1. source
4130 ");
4131 }
4132
4133 #[test]
4134 fn goto_select_column_from_function_return_table_alias_list_unqualified_partial() {
4135 assert_snapshot!(goto(r#"
4136create function dup(int) returns table(f1 int, f2 text)
4137 as ''
4138 language sql;
4139
4140select f2$0 from dup(42) as u(x);
4141"#), @r"
4142 ╭▸
4143 2 │ create function dup(int) returns table(f1 int, f2 text)
4144 │ ── 2. destination
4145 ‡
4146 6 │ select f2 from dup(42) as u(x);
4147 ╰╴ ─ 1. source
4148 ");
4149 }
4150
4151 #[test]
4152 fn goto_select_column_from_function_return_table_alias_list_unqualified_not_found() {
4153 goto_not_found(
4154 r#"
4155create function dup(int) returns table(f1 int, f2 text)
4156 as ''
4157 language sql;
4158
4159select f2$0 from dup(42) as u(x, y);
4160"#,
4161 );
4162 }
4163
4164 #[test]
4165 fn goto_select_aggregate_call() {
4166 assert_snapshot!(goto("
4167create aggregate foo(int) (
4168 sfunc = int4pl,
4169 stype = int,
4170 initcond = '0'
4171);
4172
4173select foo$0(1);
4174"), @r"
4175 ╭▸
4176 2 │ create aggregate foo(int) (
4177 │ ─── 2. destination
4178 ‡
4179 8 │ select foo(1);
4180 ╰╴ ─ 1. source
4181 ");
4182 }
4183
4184 #[test]
4185 fn goto_create_aggregate_sfunc() {
4186 assert_snapshot!(goto("
4187create function pg_catalog.int8inc(bigint) returns bigint
4188 language internal;
4189
4190create aggregate pg_catalog.count(*) (
4191 sfunc = int8inc$0,
4192 stype = bigint,
4193 combinefunc = int8pl,
4194 initcond = '0'
4195);
4196"), @r"
4197 ╭▸
4198 2 │ create function pg_catalog.int8inc(bigint) returns bigint
4199 │ ─────── 2. destination
4200 ‡
4201 6 │ sfunc = int8inc,
4202 ╰╴ ─ 1. source
4203 "
4204 );
4205 }
4206
4207 #[test]
4208 fn goto_create_aggregate_combinefunc() {
4209 assert_snapshot!(goto("
4210create function pg_catalog.int8pl(bigint, bigint) returns bigint
4211 language internal;
4212
4213create aggregate pg_catalog.count(*) (
4214 sfunc = int8inc,
4215 stype = bigint,
4216 combinefunc = int8pl$0,
4217 initcond = '0'
4218);
4219"), @r"
4220 ╭▸
4221 2 │ create function pg_catalog.int8pl(bigint, bigint) returns bigint
4222 │ ────── 2. destination
4223 ‡
4224 8 │ combinefunc = int8pl,
4225 ╰╴ ─ 1. source
4226 "
4227 );
4228 }
4229
4230 #[test]
4231 fn goto_default_constraint_function_call() {
4232 assert_snapshot!(goto("
4233create function f() returns int as 'select 1' language sql;
4234create table t(
4235 a int default f$0()
4236);
4237"), @r"
4238 ╭▸
4239 2 │ create function f() returns int as 'select 1' language sql;
4240 │ ─ 2. destination
4241 3 │ create table t(
4242 4 │ a int default f()
4243 ╰╴ ─ 1. source
4244 ");
4245 }
4246
4247 #[test]
4248 fn goto_select_function_call_with_schema() {
4249 assert_snapshot!(goto("
4250create function public.foo() returns int as $$ select 1 $$ language sql;
4251select public.foo$0();
4252"), @r"
4253 ╭▸
4254 2 │ create function public.foo() returns int as $$ select 1 $$ language sql;
4255 │ ─── 2. destination
4256 3 │ select public.foo();
4257 ╰╴ ─ 1. source
4258 ");
4259 }
4260
4261 #[test]
4262 fn goto_select_function_call_with_search_path() {
4263 assert_snapshot!(goto("
4264set search_path to myschema;
4265create function foo() returns int as $$ select 1 $$ language sql;
4266select myschema.foo$0();
4267"), @r"
4268 ╭▸
4269 3 │ create function foo() returns int as $$ select 1 $$ language sql;
4270 │ ─── 2. destination
4271 4 │ select myschema.foo();
4272 ╰╴ ─ 1. source
4273 ");
4274 }
4275
4276 #[test]
4277 fn goto_function_call_style_column_access() {
4278 assert_snapshot!(goto("
4279create table t(a int, b int);
4280select a$0(t) from t;
4281"), @r"
4282 ╭▸
4283 2 │ create table t(a int, b int);
4284 │ ─ 2. destination
4285 3 │ select a(t) from t;
4286 ╰╴ ─ 1. source
4287 ");
4288 }
4289
4290 #[test]
4291 fn goto_function_call_style_column_access_with_function_precedence() {
4292 assert_snapshot!(goto("
4293create table t(a int, b int);
4294create function b(t) returns int as 'select 1' LANGUAGE sql;
4295select b$0(t) from t;
4296"), @r"
4297 ╭▸
4298 3 │ create function b(t) returns int as 'select 1' LANGUAGE sql;
4299 │ ─ 2. destination
4300 4 │ select b(t) from t;
4301 ╰╴ ─ 1. source
4302 ");
4303 }
4304
4305 #[test]
4306 fn goto_function_call_style_column_access_table_arg() {
4307 assert_snapshot!(goto("
4308create table t(a int, b int);
4309select a(t$0) from t;
4310"), @r"
4311 ╭▸
4312 2 │ create table t(a int, b int);
4313 │ ─ 2. destination
4314 3 │ select a(t) from t;
4315 ╰╴ ─ 1. source
4316 ");
4317 }
4318
4319 #[test]
4320 fn goto_function_call_style_column_access_table_arg_with_function() {
4321 assert_snapshot!(goto("
4322create table t(a int, b int);
4323create function b(t) returns int as 'select 1' LANGUAGE sql;
4324select b(t$0) from t;
4325"), @r"
4326 ╭▸
4327 2 │ create table t(a int, b int);
4328 │ ─ 2. destination
4329 3 │ create function b(t) returns int as 'select 1' LANGUAGE sql;
4330 4 │ select b(t) from t;
4331 ╰╴ ─ 1. source
4332 ");
4333 }
4334
4335 #[test]
4336 fn goto_function_call_multiple_args_not_column_access() {
4337 goto_not_found(
4338 "
4339create table t(a int, b int);
4340select a$0(t, 1) from t;
4341",
4342 );
4343 }
4344
4345 #[test]
4346 fn goto_function_call_nested() {
4347 assert_snapshot!(goto("
4348create function f() returns int8
4349 as 'select 1'
4350 language sql;
4351select format('foo%d', f$0());
4352"), @r"
4353 ╭▸
4354 2 │ create function f() returns int8
4355 │ ─ 2. destination
4356 ‡
4357 5 │ select format('foo%d', f());
4358 ╰╴ ─ 1. source
4359 ");
4360 }
4361
4362 #[test]
4363 fn goto_field_style_function_call() {
4364 assert_snapshot!(goto("
4365create table t(a int);
4366create function b(t) returns int as 'select 1' language sql;
4367select t.b$0 from t;
4368"), @r"
4369 ╭▸
4370 3 │ create function b(t) returns int as 'select 1' language sql;
4371 │ ─ 2. destination
4372 4 │ select t.b from t;
4373 ╰╴ ─ 1. source
4374 ");
4375 }
4376
4377 #[test]
4378 fn goto_field_style_function_call_column_precedence() {
4379 assert_snapshot!(goto("
4380create table t(a int, b int);
4381create function b(t) returns int as 'select 1' language sql;
4382select t.b$0 from t;
4383"), @r"
4384 ╭▸
4385 2 │ create table t(a int, b int);
4386 │ ─ 2. destination
4387 3 │ create function b(t) returns int as 'select 1' language sql;
4388 4 │ select t.b from t;
4389 ╰╴ ─ 1. source
4390 ");
4391 }
4392
4393 #[test]
4394 fn goto_field_style_function_call_table_ref() {
4395 assert_snapshot!(goto("
4396create table t(a int);
4397create function b(t) returns int as 'select 1' language sql;
4398select t$0.b from t;
4399"), @r"
4400 ╭▸
4401 2 │ create table t(a int);
4402 │ ─ 2. destination
4403 3 │ create function b(t) returns int as 'select 1' language sql;
4404 4 │ select t.b from t;
4405 ╰╴ ─ 1. source
4406 ");
4407 }
4408
4409 #[test]
4410 fn goto_function_call_style_in_where() {
4411 assert_snapshot!(goto("
4412create table t(a int, b int);
4413select * from t where a$0(t) > 0;
4414"), @r"
4415 ╭▸
4416 2 │ create table t(a int, b int);
4417 │ ─ 2. destination
4418 3 │ select * from t where a(t) > 0;
4419 ╰╴ ─ 1. source
4420 ");
4421 }
4422
4423 #[test]
4424 fn goto_function_call_style_in_where_function_precedence() {
4425 assert_snapshot!(goto("
4426create table t(a int, b int);
4427create function b(t) returns int as 'select 1' language sql;
4428select * from t where b$0(t) > 0;
4429"), @r"
4430 ╭▸
4431 3 │ create function b(t) returns int as 'select 1' language sql;
4432 │ ─ 2. destination
4433 4 │ select * from t where b(t) > 0;
4434 ╰╴ ─ 1. source
4435 ");
4436 }
4437
4438 #[test]
4439 fn goto_field_style_function_call_in_where() {
4440 assert_snapshot!(goto("
4441create table t(a int);
4442create function b(t) returns int as 'select 1' language sql;
4443select * from t where t.b$0 > 0;
4444"), @r"
4445 ╭▸
4446 3 │ create function b(t) returns int as 'select 1' language sql;
4447 │ ─ 2. destination
4448 4 │ select * from t where t.b > 0;
4449 ╰╴ ─ 1. source
4450 ");
4451 }
4452
4453 #[test]
4454 fn goto_field_style_in_where_column_precedence() {
4455 assert_snapshot!(goto("
4456create table t(a int, b int);
4457create function b(t) returns int as 'select 1' language sql;
4458select * from t where t.b$0 > 0;
4459"), @r"
4460 ╭▸
4461 2 │ create table t(a int, b int);
4462 │ ─ 2. destination
4463 3 │ create function b(t) returns int as 'select 1' language sql;
4464 4 │ select * from t where t.b > 0;
4465 ╰╴ ─ 1. source
4466 ");
4467 }
4468
4469 #[test]
4470 fn goto_function_call_style_table_arg_in_where() {
4471 assert_snapshot!(goto("
4472create table t(a int);
4473select * from t where a(t$0) > 2;
4474"), @r"
4475 ╭▸
4476 2 │ create table t(a int);
4477 │ ─ 2. destination
4478 3 │ select * from t where a(t) > 2;
4479 ╰╴ ─ 1. source
4480 ");
4481 }
4482
4483 #[test]
4484 fn goto_qualified_table_ref_in_where() {
4485 assert_snapshot!(goto("
4486create table t(a int);
4487create function b(t) returns int as 'select 1' language sql;
4488select * from t where t$0.b > 2;
4489"), @r"
4490 ╭▸
4491 2 │ create table t(a int);
4492 │ ─ 2. destination
4493 3 │ create function b(t) returns int as 'select 1' language sql;
4494 4 │ select * from t where t.b > 2;
4495 ╰╴ ─ 1. source
4496 ");
4497 }
4498
4499 #[test]
4500 fn goto_function_call_style_in_order_by() {
4501 assert_snapshot!(goto("
4502create table t(a int, b int);
4503create function b(t) returns int as 'select 1' language sql;
4504select * from t order by b$0(t);
4505"), @r"
4506 ╭▸
4507 3 │ create function b(t) returns int as 'select 1' language sql;
4508 │ ─ 2. destination
4509 4 │ select * from t order by b(t);
4510 ╰╴ ─ 1. source
4511 ");
4512 }
4513
4514 #[test]
4515 fn goto_field_style_in_order_by() {
4516 assert_snapshot!(goto("
4517create table t(a int);
4518create function b(t) returns int as 'select 1' language sql;
4519select * from t order by t.b$0;
4520"), @r"
4521 ╭▸
4522 3 │ create function b(t) returns int as 'select 1' language sql;
4523 │ ─ 2. destination
4524 4 │ select * from t order by t.b;
4525 ╰╴ ─ 1. source
4526 ");
4527 }
4528
4529 #[test]
4530 fn goto_function_call_style_in_group_by() {
4531 assert_snapshot!(goto("
4532create table t(a int, b int);
4533select * from t group by a$0(t);
4534"), @r"
4535 ╭▸
4536 2 │ create table t(a int, b int);
4537 │ ─ 2. destination
4538 3 │ select * from t group by a(t);
4539 ╰╴ ─ 1. source
4540 ");
4541 }
4542
4543 #[test]
4544 fn goto_field_style_in_group_by() {
4545 assert_snapshot!(goto("
4546create table t(a int);
4547create function b(t) returns int as 'select 1' language sql;
4548select * from t group by t.b$0;
4549"), @r"
4550 ╭▸
4551 3 │ create function b(t) returns int as 'select 1' language sql;
4552 │ ─ 2. destination
4553 4 │ select * from t group by t.b;
4554 ╰╴ ─ 1. source
4555 ");
4556 }
4557
4558 #[test]
4559 fn goto_cte_table() {
4560 assert_snapshot!(goto("
4561with x as (select 1 as a)
4562select a from x$0;
4563"), @r"
4564 ╭▸
4565 2 │ with x as (select 1 as a)
4566 │ ─ 2. destination
4567 3 │ select a from x;
4568 ╰╴ ─ 1. source
4569 ");
4570 }
4571
4572 #[test]
4573 fn goto_cte_column() {
4574 assert_snapshot!(goto("
4575with x as (select 1 as a)
4576select a$0 from x;
4577"), @r"
4578 ╭▸
4579 2 │ with x as (select 1 as a)
4580 │ ─ 2. destination
4581 3 │ select a from x;
4582 ╰╴ ─ 1. source
4583 ");
4584 }
4585
4586 #[test]
4587 fn goto_cte_qualified_column_prefers_cte_over_table() {
4588 assert_snapshot!(goto("
4589create table u(id int, b int);
4590with u as (select 1 id, 2 b)
4591select u.id$0 from u;
4592"), @r"
4593 ╭▸
4594 3 │ with u as (select 1 id, 2 b)
4595 │ ── 2. destination
4596 4 │ select u.id from u;
4597 ╰╴ ─ 1. source
4598 ");
4599 }
4600
4601 #[test]
4602 fn goto_subquery_qualified_column() {
4603 assert_snapshot!(goto("
4604select t.a$0 from (select 1 a) t;
4605"), @r"
4606 ╭▸
4607 2 │ select t.a from (select 1 a) t;
4608 ╰╴ ─ 1. source ─ 2. destination
4609 ");
4610 }
4611
4612 #[test]
4613 fn goto_cte_multiple_columns() {
4614 assert_snapshot!(goto("
4615with x as (select 1 as a, 2 as b)
4616select b$0 from x;
4617"), @r"
4618 ╭▸
4619 2 │ with x as (select 1 as a, 2 as b)
4620 │ ─ 2. destination
4621 3 │ select b from x;
4622 ╰╴ ─ 1. source
4623 ");
4624 }
4625
4626 #[test]
4627 fn goto_cte_nested() {
4628 assert_snapshot!(goto("
4629with x as (select 1 as a),
4630 y as (select a from x)
4631select a$0 from y;
4632"), @r"
4633 ╭▸
4634 3 │ y as (select a from x)
4635 │ ─ 2. destination
4636 4 │ select a from y;
4637 ╰╴ ─ 1. source
4638 ");
4639 }
4640
4641 #[test]
4642 fn goto_cte_unnamed_column() {
4643 assert_snapshot!(goto(r#"
4644with x as (select 1)
4645select "?column?"$0 from x;
4646"#), @r#"
4647 ╭▸
4648 2 │ with x as (select 1)
4649 │ ─ 2. destination
4650 3 │ select "?column?" from x;
4651 ╰╴ ─ 1. source
4652 "#);
4653 }
4654
4655 #[test]
4656 fn goto_cte_star_expansion() {
4657 assert_snapshot!(goto("
4658with t as (select 1 a),
4659 y as (select * from t)
4660select a$0 from y;
4661"), @r"
4662 ╭▸
4663 2 │ with t as (select 1 a),
4664 │ ─ 2. destination
4665 3 │ y as (select * from t)
4666 4 │ select a from y;
4667 ╰╴ ─ 1. source
4668 ");
4669 }
4670
4671 #[test]
4672 fn goto_cte_qualified_star_join_column() {
4673 assert_snapshot!(goto("
4674create table u(id int, b int);
4675create table t(id int, a int);
4676
4677with k as (
4678 select u.* from t join u on a = b
4679)
4680select b$0 from k;
4681"), @r"
4682 ╭▸
4683 2 │ create table u(id int, b int);
4684 │ ─ 2. destination
4685 ‡
4686 8 │ select b from k;
4687 ╰╴ ─ 1. source
4688 ");
4689 }
4690
4691 #[test]
4692 fn goto_cte_qualified_star_join_column_with_partial_column_list() {
4693 assert_snapshot!(goto("
4694with
4695 u as (
4696 select 1 id, 2 b
4697 ),
4698 t as (
4699 select 1 id, 2 a
4700 ),
4701 k(x) as (
4702 select u.* from t join u on a = b
4703 )
4704select b$0 from k;
4705"), @r"
4706 ╭▸
4707 4 │ select 1 id, 2 b
4708 │ ─ 2. destination
4709 ‡
4710 12 │ select b from k;
4711 ╰╴ ─ 1. source
4712 ");
4713 }
4714
4715 #[test]
4716 fn goto_cte_reference_inside_cte() {
4717 assert_snapshot!(goto("
4718with t as (select 1 a),
4719 y as (select a$0 from t)
4720select a from y;
4721"), @r"
4722 ╭▸
4723 2 │ with t as (select 1 a),
4724 │ ─ 2. destination
4725 3 │ y as (select a from t)
4726 ╰╴ ─ 1. source
4727 ");
4728 }
4729
4730 #[test]
4731 fn goto_recursive_cte_reference_inside_cte() {
4732 assert_snapshot!(goto("
4733with recursive nums as (
4734 select 1 as n
4735 union all
4736 select n + 1 from nums$0 where n < 5
4737)
4738select * from nums;
4739"), @r"
4740 ╭▸
4741 2 │ with recursive nums as (
4742 │ ──── 2. destination
4743 ‡
4744 5 │ select n + 1 from nums where n < 5
4745 ╰╴ ─ 1. source
4746 ");
4747 }
4748
4749 #[test]
4750 fn goto_cte_with_column_list() {
4751 assert_snapshot!(goto("
4752with t(a) as (select 1)
4753select a$0 from t;
4754"), @r"
4755 ╭▸
4756 2 │ with t(a) as (select 1)
4757 │ ─ 2. destination
4758 3 │ select a from t;
4759 ╰╴ ─ 1. source
4760 ");
4761 }
4762
4763 #[test]
4764 fn goto_cte_with_partial_column_list() {
4765 assert_snapshot!(goto("
4766with t(x) as (select 1 as a, 2 as b)
4767select b$0 from t;
4768"), @r"
4769 ╭▸
4770 2 │ with t(x) as (select 1 as a, 2 as b)
4771 │ ─ 2. destination
4772 3 │ select b from t;
4773 ╰╴ ─ 1. source
4774 ");
4775 }
4776
4777 #[test]
4778 fn goto_cte_with_partial_column_list_renamed() {
4779 assert_snapshot!(goto("
4780with t(x) as (select 1 as a, 2 as b)
4781select x$0 from t;
4782"), @r"
4783 ╭▸
4784 2 │ with t(x) as (select 1 as a, 2 as b)
4785 │ ─ 2. destination
4786 3 │ select x from t;
4787 ╰╴ ─ 1. source
4788 ");
4789 }
4790
4791 #[test]
4792 fn goto_cte_insert_returning_star_column() {
4793 assert_snapshot!(goto("
4794create table t(a int, b int);
4795with inserted as (
4796 insert into t values (1, 2), (3, 4)
4797 returning *
4798)
4799select a$0 from inserted;
4800"), @r"
4801 ╭▸
4802 2 │ create table t(a int, b int);
4803 │ ─ 2. destination
4804 ‡
4805 7 │ select a from inserted;
4806 ╰╴ ─ 1. source
4807 ");
4808 }
4809
4810 #[test]
4811 fn goto_cte_delete_returning_star_column() {
4812 assert_snapshot!(goto("
4813create table t(a int, b int);
4814with deleted as (
4815 delete from t
4816 returning *
4817)
4818select a$0 from deleted;
4819"), @r"
4820 ╭▸
4821 2 │ create table t(a int, b int);
4822 │ ─ 2. destination
4823 ‡
4824 7 │ select a from deleted;
4825 ╰╴ ─ 1. source
4826 ");
4827 }
4828
4829 #[test]
4830 fn goto_cte_update_returning_star_column() {
4831 assert_snapshot!(goto("
4832create table t(a int, b int);
4833with updated as (
4834 update t set a = 42
4835 returning *
4836)
4837select a$0 from updated;
4838"), @r"
4839 ╭▸
4840 2 │ create table t(a int, b int);
4841 │ ─ 2. destination
4842 ‡
4843 7 │ select a from updated;
4844 ╰╴ ─ 1. source
4845 ");
4846 }
4847
4848 #[test]
4849 fn goto_cte_update_returning_column_list_overwrites_column() {
4850 goto_not_found(
4851 "
4852create table t(a int, b int);
4853with updated(c) as (
4854 update t set a = 10
4855 returning a
4856)
4857select a$0 from updated;
4858",
4859 );
4860 }
4861
4862 #[test]
4863 fn goto_cte_column_list_overwrites_column() {
4864 goto_not_found(
4865 "
4866with t(x) as (select 1 as a)
4867select a$0 from t;
4868",
4869 );
4870 }
4871
4872 #[test]
4873 fn goto_cte_shadows_table() {
4874 assert_snapshot!(goto("
4875create table t(a int);
4876with t as (select a$0 from t)
4877select a from t;
4878"), @r"
4879 ╭▸
4880 2 │ create table t(a int);
4881 │ ─ 2. destination
4882 3 │ with t as (select a from t)
4883 ╰╴ ─ 1. source
4884 ");
4885 }
4886
4887 #[test]
4888 fn goto_subquery_column() {
4889 assert_snapshot!(goto("
4890select a$0 from (select 1 a);
4891"), @r"
4892 ╭▸
4893 2 │ select a from (select 1 a);
4894 ╰╴ ─ 1. source ─ 2. destination
4895 ");
4896 }
4897
4898 #[test]
4899 fn goto_subquery_column_with_as() {
4900 assert_snapshot!(goto("
4901select a$0 from (select 1 as a);
4902"), @r"
4903 ╭▸
4904 2 │ select a from (select 1 as a);
4905 ╰╴ ─ 1. source ─ 2. destination
4906 ");
4907 }
4908
4909 #[test]
4910 fn goto_subquery_compound_select_column() {
4911 assert_snapshot!(goto("
4912select c$0 from (select 1 c union select 2 c);
4913"), @r"
4914 ╭▸
4915 2 │ select c from (select 1 c union select 2 c);
4916 ╰╴ ─ 1. source ─ 2. destination
4917 ");
4918 }
4919
4920 #[test]
4921 fn goto_subquery_compound_select_column_with_nested_parens() {
4922 assert_snapshot!(goto("
4923with t as (
4924 select 1 as c
4925)
4926select c$0 from ((select * from t) union all (select * from t));
4927"), @r"
4928 ╭▸
4929 3 │ select 1 as c
4930 │ ─ 2. destination
4931 4 │ )
4932 5 │ select c from ((select * from t) union all (select * from t));
4933 ╰╴ ─ 1. source
4934 ");
4935 }
4936
4937 #[test]
4938 fn goto_subquery_column_multiple_columns() {
4939 assert_snapshot!(goto("
4940select b$0 from (select 1 a, 2 b);
4941"), @r"
4942 ╭▸
4943 2 │ select b from (select 1 a, 2 b);
4944 ╰╴ ─ 1. source ─ 2. destination
4945 ");
4946 }
4947
4948 #[test]
4949 fn goto_subquery_column_nested_parens() {
4950 assert_snapshot!(goto("
4951select a$0 from ((select 1 a));
4952"), @r"
4953 ╭▸
4954 2 │ select a from ((select 1 a));
4955 ╰╴ ─ 1. source ─ 2. destination
4956 ");
4957 }
4958
4959 #[test]
4960 fn goto_subquery_column_star_table() {
4961 assert_snapshot!(goto("
4962create table foo.t(a int);
4963select a$0 from (select * from foo.t);
4964"), @r"
4965 ╭▸
4966 2 │ create table foo.t(a int);
4967 │ ─ 2. destination
4968 3 │ select a from (select * from foo.t);
4969 ╰╴ ─ 1. source
4970 ");
4971 }
4972
4973 #[test]
4974 fn goto_subquery_column_qualified_star_join() {
4975 assert_snapshot!(goto("
4976create table t(a int);
4977create table u(b int);
4978select b$0 from (select u.* from t join u on a = b);
4979"), @r"
4980 ╭▸
4981 3 │ create table u(b int);
4982 │ ─ 2. destination
4983 4 │ select b from (select u.* from t join u on a = b);
4984 ╰╴ ─ 1. source
4985 ");
4986 }
4987
4988 #[test]
4989 fn goto_subquery_column_qualified_star_join_not_found() {
4990 goto_not_found(
4991 "
4992create table t(a int);
4993create table u(b int);
4994select a$0 from (select u.* from t join u on a = b);
4995",
4996 );
4997 }
4998
4999 #[test]
5000 fn goto_subquery_column_alias_list() {
5001 assert_snapshot!(goto("
5002select c$0, t.c from (select 1) t(c);
5003"), @r"
5004 ╭▸
5005 2 │ select c, t.c from (select 1) t(c);
5006 ╰╴ ─ 1. source ─ 2. destination
5007 ");
5008 }
5009
5010 #[test]
5011 fn goto_subquery_column_alias_list_qualified() {
5012 assert_snapshot!(goto("
5013select t.c$0 from (select 1) t(c);
5014"), @r"
5015 ╭▸
5016 2 │ select t.c from (select 1) t(c);
5017 ╰╴ ─ 1. source ─ 2. destination
5018 ");
5019 }
5020
5021 #[test]
5022 fn goto_subquery_column_alias_list_multiple() {
5023 assert_snapshot!(goto("
5024select b$0 from (select 1, 2) t(a, b);
5025"), @r"
5026 ╭▸
5027 2 │ select b from (select 1, 2) t(a, b);
5028 ╰╴ ─ 1. source ─ 2. destination
5029 ");
5030 }
5031
5032 #[test]
5033 fn goto_cte_column_alias_list() {
5034 assert_snapshot!(goto("
5035with x as (select 1)
5036select c$0 from x t(c);
5037"), @r"
5038 ╭▸
5039 3 │ select c from x t(c);
5040 │ ┬ ─ 2. destination
5041 │ │
5042 ╰╴ 1. source
5043 ");
5044 }
5045
5046 #[test]
5047 fn goto_cte_column_alias_list_qualified() {
5048 assert_snapshot!(goto("
5049with x as (select 1)
5050select t.c$0 from x t(c);
5051"), @r"
5052 ╭▸
5053 3 │ select t.c from x t(c);
5054 │ ┬ ─ 2. destination
5055 │ │
5056 ╰╴ 1. source
5057 ");
5058 }
5059
5060 #[test]
5061 fn goto_cte_column_alias_list_multiple() {
5062 assert_snapshot!(goto("
5063with x as (select 1, 2)
5064select b$0 from x t(a, b);
5065"), @r"
5066 ╭▸
5067 3 │ select b from x t(a, b);
5068 ╰╴ ─ 1. source ─ 2. destination
5069 ");
5070 }
5071
5072 #[test]
5073 fn goto_values_column_alias_list() {
5074 assert_snapshot!(goto("
5075select c$0 from (values (1)) t(c);
5076"), @r"
5077 ╭▸
5078 2 │ select c from (values (1)) t(c);
5079 ╰╴ ─ 1. source ─ 2. destination
5080 ");
5081 }
5082
5083 #[test]
5084 fn goto_values_column_alias_list_qualified() {
5085 assert_snapshot!(goto("
5086select t.c$0 from (values (1)) t(c);
5087"), @r"
5088 ╭▸
5089 2 │ select t.c from (values (1)) t(c);
5090 ╰╴ ─ 1. source ─ 2. destination
5091 ");
5092 }
5093
5094 #[test]
5095 fn goto_values_column_alias_list_multiple() {
5096 assert_snapshot!(goto("
5097select b$0 from (values (1, 2)) t(a, b);
5098"), @r"
5099 ╭▸
5100 2 │ select b from (values (1, 2)) t(a, b);
5101 ╰╴ ─ 1. source ─ 2. destination
5102 ");
5103 }
5104
5105 #[test]
5106 fn goto_values_column_alias_list_nested_parens() {
5107 assert_snapshot!(goto("
5108select n$0
5109from ((values (1), (2))) u(n);
5110"), @r"
5111 ╭▸
5112 2 │ select n
5113 │ ─ 1. source
5114 3 │ from ((values (1), (2))) u(n);
5115 ╰╴ ─ 2. destination
5116 ");
5117 }
5118
5119 #[test]
5120 fn goto_table_expr_column() {
5121 assert_snapshot!(goto("
5122create table t(a int, b int);
5123select a$0 from (table t);
5124"), @r"
5125 ╭▸
5126 2 │ create table t(a int, b int);
5127 │ ─ 2. destination
5128 3 │ select a from (table t);
5129 ╰╴ ─ 1. source
5130 ");
5131 }
5132
5133 #[test]
5134 fn goto_table_expr_column_with_cte() {
5135 assert_snapshot!(goto("
5136with x as (select 1 a)
5137select a$0 from (table x);
5138"), @r"
5139 ╭▸
5140 2 │ with x as (select 1 a)
5141 │ ─ 2. destination
5142 3 │ select a from (table x);
5143 ╰╴ ─ 1. source
5144 ");
5145 }
5146
5147 #[test]
5148 fn goto_table_expr_cte_table() {
5149 assert_snapshot!(goto("
5150with t as (select 1 a, 2 b)
5151select * from (table t$0);
5152"), @r"
5153 ╭▸
5154 2 │ with t as (select 1 a, 2 b)
5155 │ ─ 2. destination
5156 3 │ select * from (table t);
5157 ╰╴ ─ 1. source
5158 ");
5159 }
5160
5161 #[test]
5162 fn goto_table_expr_partial_column_alias_list() {
5163 assert_snapshot!(goto("
5164with t as (select 1 a, 2 b)
5165select c, b$0 from (table t) u(c);
5166"), @r"
5167 ╭▸
5168 2 │ with t as (select 1 a, 2 b)
5169 │ ─ 2. destination
5170 3 │ select c, b from (table t) u(c);
5171 ╰╴ ─ 1. source
5172 ");
5173 }
5174
5175 #[test]
5176 fn goto_subquery_partial_column_alias_list() {
5177 assert_snapshot!(goto("
5178select x, b$0 from (select 1 a, 2 b) t(x);
5179"), @r"
5180 ╭▸
5181 2 │ select x, b from (select 1 a, 2 b) t(x);
5182 ╰╴ ─ 1. source ─ 2. destination
5183 ");
5184 }
5185
5186 #[test]
5187 fn goto_subquery_alias_with_column_list_table_ref() {
5188 assert_snapshot!(goto("
5189with t as (select 1 a, 2 b)
5190select z$0 from (select * from t) as z(x, y);
5191"), @"
5192 ╭▸
5193 3 │ select z from (select * from t) as z(x, y);
5194 ╰╴ ─ 1. source ─ 2. destination
5195 ");
5196 }
5197
5198 #[test]
5199 fn goto_subquery_alias_with_column_list_table_ref_shadows_column() {
5200 assert_snapshot!(goto("
5201with t as (select 1 a, 2 b)
5202select z$0 from (select a as z, b from t) as z(x, y);
5203"), @"
5204 ╭▸
5205 3 │ select z from (select a as z, b from t) as z(x, y);
5206 ╰╴ ─ 1. source ─ 2. destination
5207 ");
5208 }
5209
5210 #[test]
5211 fn goto_subquery_nested_paren_alias_with_column_list_table_ref() {
5212 assert_snapshot!(goto("
5213with t as (select 1 a, 2 b, 3 c)
5214select z$0 from ((select * from t)) as z(x, y);
5215"), @"
5216 ╭▸
5217 3 │ select z from ((select * from t)) as z(x, y);
5218 ╰╴ ─ 1. source ─ 2. destination
5219 ");
5220 }
5221
5222 #[test]
5223 fn goto_table_expr_values_cte_partial_alias() {
5224 assert_snapshot!(goto("
5225with t as (values (1, 2), (3, 4))
5226select column2$0 from (table t) u(a);
5227"), @r"
5228 ╭▸
5229 2 │ with t as (values (1, 2), (3, 4))
5230 │ ─ 2. destination
5231 3 │ select column2 from (table t) u(a);
5232 ╰╴ ─ 1. source
5233 ");
5234 }
5235
5236 #[test]
5237 fn goto_cte_with_table_expr() {
5238 assert_snapshot!(goto("
5239create table t(a int, b int);
5240with u as (table t)
5241select a$0 from u;
5242"), @r"
5243 ╭▸
5244 2 │ create table t(a int, b int);
5245 │ ─ 2. destination
5246 3 │ with u as (table t)
5247 4 │ select a from u;
5248 ╰╴ ─ 1. source
5249 ");
5250 }
5251
5252 #[test]
5253 fn goto_cte_with_table_expr_nested() {
5254 assert_snapshot!(goto("
5255with t as (select 1 a, 2 b),
5256 u as (table t)
5257select b$0 from u;
5258"), @r"
5259 ╭▸
5260 2 │ with t as (select 1 a, 2 b),
5261 │ ─ 2. destination
5262 3 │ u as (table t)
5263 4 │ select b from u;
5264 ╰╴ ─ 1. source
5265 ");
5266 }
5267
5268 #[test]
5269 fn goto_insert_table() {
5270 assert_snapshot!(goto("
5271create table users(id int, email text);
5272insert into users$0(id, email) values (1, 'test@example.com');
5273"), @r"
5274 ╭▸
5275 2 │ create table users(id int, email text);
5276 │ ───── 2. destination
5277 3 │ insert into users(id, email) values (1, 'test@example.com');
5278 ╰╴ ─ 1. source
5279 ");
5280 }
5281
5282 #[test]
5283 fn goto_insert_table_with_schema() {
5284 assert_snapshot!(goto("
5285create table public.users(id int, email text);
5286insert into public.users$0(id, email) values (1, 'test@example.com');
5287"), @r"
5288 ╭▸
5289 2 │ create table public.users(id int, email text);
5290 │ ───── 2. destination
5291 3 │ insert into public.users(id, email) values (1, 'test@example.com');
5292 ╰╴ ─ 1. source
5293 ");
5294 }
5295
5296 #[test]
5297 fn goto_insert_column() {
5298 assert_snapshot!(goto("
5299create table users(id int, email text);
5300insert into users(id$0, email) values (1, 'test@example.com');
5301"), @r"
5302 ╭▸
5303 2 │ create table users(id int, email text);
5304 │ ── 2. destination
5305 3 │ insert into users(id, email) values (1, 'test@example.com');
5306 ╰╴ ─ 1. source
5307 ");
5308 }
5309
5310 #[test]
5311 fn goto_insert_column_second() {
5312 assert_snapshot!(goto("
5313create table users(id int, email text);
5314insert into users(id, email$0) values (1, 'test@example.com');
5315"), @r"
5316 ╭▸
5317 2 │ create table users(id int, email text);
5318 │ ───── 2. destination
5319 3 │ insert into users(id, email) values (1, 'test@example.com');
5320 ╰╴ ─ 1. source
5321 ");
5322 }
5323
5324 #[test]
5325 fn goto_insert_column_with_schema() {
5326 assert_snapshot!(goto("
5327create table public.users(id int, email text);
5328insert into public.users(email$0) values ('test@example.com');
5329"), @r"
5330 ╭▸
5331 2 │ create table public.users(id int, email text);
5332 │ ───── 2. destination
5333 3 │ insert into public.users(email) values ('test@example.com');
5334 ╰╴ ─ 1. source
5335 ");
5336 }
5337
5338 #[test]
5339 fn goto_insert_table_with_search_path() {
5340 assert_snapshot!(goto("
5341set search_path to foo;
5342create table foo.users(id int, email text);
5343insert into users$0(id, email) values (1, 'test@example.com');
5344"), @r"
5345 ╭▸
5346 3 │ create table foo.users(id int, email text);
5347 │ ───── 2. destination
5348 4 │ insert into users(id, email) values (1, 'test@example.com');
5349 ╰╴ ─ 1. source
5350 ");
5351 }
5352
5353 #[test]
5354 fn goto_insert_column_with_search_path() {
5355 assert_snapshot!(goto("
5356set search_path to myschema;
5357create table myschema.users(id int, email text, name text);
5358insert into users(email$0, name) values ('test@example.com', 'Test');
5359"), @r"
5360 ╭▸
5361 3 │ create table myschema.users(id int, email text, name text);
5362 │ ───── 2. destination
5363 4 │ insert into users(email, name) values ('test@example.com', 'Test');
5364 ╰╴ ─ 1. source
5365 ");
5366 }
5367
5368 #[test]
5369 fn goto_delete_table() {
5370 assert_snapshot!(goto("
5371create table users(id int, email text);
5372delete from users$0 where id = 1;
5373"), @r"
5374 ╭▸
5375 2 │ create table users(id int, email text);
5376 │ ───── 2. destination
5377 3 │ delete from users where id = 1;
5378 ╰╴ ─ 1. source
5379 ");
5380 }
5381
5382 #[test]
5383 fn goto_delete_table_with_schema() {
5384 assert_snapshot!(goto("
5385create table public.users(id int, email text);
5386delete from public.users$0 where id = 1;
5387"), @r"
5388 ╭▸
5389 2 │ create table public.users(id int, email text);
5390 │ ───── 2. destination
5391 3 │ delete from public.users where id = 1;
5392 ╰╴ ─ 1. source
5393 ");
5394 }
5395
5396 #[test]
5397 fn goto_delete_table_with_search_path() {
5398 assert_snapshot!(goto("
5399set search_path to foo;
5400create table foo.users(id int, email text);
5401delete from users$0 where id = 1;
5402"), @r"
5403 ╭▸
5404 3 │ create table foo.users(id int, email text);
5405 │ ───── 2. destination
5406 4 │ delete from users where id = 1;
5407 ╰╴ ─ 1. source
5408 ");
5409 }
5410
5411 #[test]
5412 fn goto_delete_temp_table() {
5413 assert_snapshot!(goto("
5414create temp table users(id int, email text);
5415delete from users$0 where id = 1;
5416"), @r"
5417 ╭▸
5418 2 │ create temp table users(id int, email text);
5419 │ ───── 2. destination
5420 3 │ delete from users where id = 1;
5421 ╰╴ ─ 1. source
5422 ");
5423 }
5424
5425 #[test]
5426 fn goto_delete_where_column() {
5427 assert_snapshot!(goto("
5428create table users(id int, email text);
5429delete from users where id$0 = 1;
5430"), @r"
5431 ╭▸
5432 2 │ create table users(id int, email text);
5433 │ ── 2. destination
5434 3 │ delete from users where id = 1;
5435 ╰╴ ─ 1. source
5436 ");
5437 }
5438
5439 #[test]
5440 fn goto_delete_where_column_second() {
5441 assert_snapshot!(goto("
5442create table users(id int, email text);
5443delete from users where email$0 = 'test@example.com';
5444"), @r"
5445 ╭▸
5446 2 │ create table users(id int, email text);
5447 │ ───── 2. destination
5448 3 │ delete from users where email = 'test@example.com';
5449 ╰╴ ─ 1. source
5450 ");
5451 }
5452
5453 #[test]
5454 fn goto_delete_where_column_with_schema() {
5455 assert_snapshot!(goto("
5456create table public.users(id int, email text, name text);
5457delete from public.users where name$0 = 'Test';
5458"), @r"
5459 ╭▸
5460 2 │ create table public.users(id int, email text, name text);
5461 │ ──── 2. destination
5462 3 │ delete from public.users where name = 'Test';
5463 ╰╴ ─ 1. source
5464 ");
5465 }
5466
5467 #[test]
5468 fn goto_delete_where_column_with_search_path() {
5469 assert_snapshot!(goto("
5470set search_path to myschema;
5471create table myschema.users(id int, email text, active boolean);
5472delete from users where active$0 = true;
5473"), @r"
5474 ╭▸
5475 3 │ create table myschema.users(id int, email text, active boolean);
5476 │ ────── 2. destination
5477 4 │ delete from users where active = true;
5478 ╰╴ ─ 1. source
5479 ");
5480 }
5481
5482 #[test]
5483 fn goto_delete_where_multiple_columns() {
5484 assert_snapshot!(goto("
5485create table users(id int, email text, active boolean);
5486delete from users where id$0 = 1 and active = true;
5487"), @r"
5488 ╭▸
5489 2 │ create table users(id int, email text, active boolean);
5490 │ ── 2. destination
5491 3 │ delete from users where id = 1 and active = true;
5492 ╰╴ ─ 1. source
5493 ");
5494 }
5495
5496 #[test]
5497 fn goto_delete_using_table() {
5498 assert_snapshot!(goto("
5499create table t(id int, f_id int);
5500create table f(id int, name text);
5501delete from t using f$0 where f_id = f.id and f.name = 'foo';
5502"), @r"
5503 ╭▸
5504 3 │ create table f(id int, name text);
5505 │ ─ 2. destination
5506 4 │ delete from t using f where f_id = f.id and f.name = 'foo';
5507 ╰╴ ─ 1. source
5508 ");
5509 }
5510
5511 #[test]
5512 fn goto_delete_using_table_with_schema() {
5513 assert_snapshot!(goto("
5514create table t(id int, f_id int);
5515create table public.f(id int, name text);
5516delete from t using public.f$0 where f_id = f.id;
5517"), @r"
5518 ╭▸
5519 3 │ create table public.f(id int, name text);
5520 │ ─ 2. destination
5521 4 │ delete from t using public.f where f_id = f.id;
5522 ╰╴ ─ 1. source
5523 ");
5524 }
5525
5526 #[test]
5527 fn goto_delete_using_column_in_where() {
5528 assert_snapshot!(goto("
5529create table t(id int, f_id int);
5530create table f(id int, name text);
5531delete from t using f where f_id = f.id$0 and f.name = 'foo';
5532"), @r"
5533 ╭▸
5534 2 │ create table t(id int, f_id int);
5535 │ ── 2. destination
5536 3 │ create table f(id int, name text);
5537 4 │ delete from t using f where f_id = f.id and f.name = 'foo';
5538 ╰╴ ─ 1. source
5539 ");
5540 }
5541
5542 #[test]
5543 fn goto_select_from_table() {
5544 assert_snapshot!(goto("
5545create table users(id int, email text);
5546select * from users$0;
5547"), @r"
5548 ╭▸
5549 2 │ create table users(id int, email text);
5550 │ ───── 2. destination
5551 3 │ select * from users;
5552 ╰╴ ─ 1. source
5553 ");
5554 }
5555
5556 #[test]
5557 fn goto_select_from_table_with_schema() {
5558 assert_snapshot!(goto("
5559create table public.users(id int, email text);
5560select * from public.users$0;
5561"), @r"
5562 ╭▸
5563 2 │ create table public.users(id int, email text);
5564 │ ───── 2. destination
5565 3 │ select * from public.users;
5566 ╰╴ ─ 1. source
5567 ");
5568 }
5569
5570 #[test]
5571 fn goto_select_from_table_with_search_path() {
5572 assert_snapshot!(goto("
5573set search_path to foo;
5574create table foo.users(id int, email text);
5575select * from users$0;
5576"), @r"
5577 ╭▸
5578 3 │ create table foo.users(id int, email text);
5579 │ ───── 2. destination
5580 4 │ select * from users;
5581 ╰╴ ─ 1. source
5582 ");
5583 }
5584
5585 #[test]
5586 fn goto_select_from_temp_table() {
5587 assert_snapshot!(goto("
5588create temp table users(id int, email text);
5589select * from users$0;
5590"), @r"
5591 ╭▸
5592 2 │ create temp table users(id int, email text);
5593 │ ───── 2. destination
5594 3 │ select * from users;
5595 ╰╴ ─ 1. source
5596 ");
5597 }
5598
5599 #[test]
5600 fn goto_select_from_table_defined_after() {
5601 assert_snapshot!(goto("
5602select * from users$0;
5603create table users(id int, email text);
5604"), @r"
5605 ╭▸
5606 2 │ select * from users;
5607 │ ─ 1. source
5608 3 │ create table users(id int, email text);
5609 ╰╴ ───── 2. destination
5610 ");
5611 }
5612
5613 #[test]
5614 fn goto_select_column() {
5615 assert_snapshot!(goto("
5616create table users(id int, email text);
5617select id$0 from users;
5618"), @r"
5619 ╭▸
5620 2 │ create table users(id int, email text);
5621 │ ── 2. destination
5622 3 │ select id from users;
5623 ╰╴ ─ 1. source
5624 ");
5625 }
5626
5627 #[test]
5628 fn goto_select_column_second() {
5629 assert_snapshot!(goto("
5630create table users(id int, email text);
5631select id, email$0 from users;
5632"), @r"
5633 ╭▸
5634 2 │ create table users(id int, email text);
5635 │ ───── 2. destination
5636 3 │ select id, email from users;
5637 ╰╴ ─ 1. source
5638 ");
5639 }
5640
5641 #[test]
5642 fn goto_select_column_with_schema() {
5643 assert_snapshot!(goto("
5644create table public.users(id int, email text);
5645select email$0 from public.users;
5646"), @r"
5647 ╭▸
5648 2 │ create table public.users(id int, email text);
5649 │ ───── 2. destination
5650 3 │ select email from public.users;
5651 ╰╴ ─ 1. source
5652 ");
5653 }
5654
5655 #[test]
5656 fn goto_select_column_with_search_path() {
5657 assert_snapshot!(goto("
5658set search_path to foo;
5659create table foo.users(id int, email text);
5660select id$0 from users;
5661"), @r"
5662 ╭▸
5663 3 │ create table foo.users(id int, email text);
5664 │ ── 2. destination
5665 4 │ select id from users;
5666 ╰╴ ─ 1. source
5667 ");
5668 }
5669
5670 #[test]
5671 fn goto_select_table_as_column() {
5672 assert_snapshot!(goto("
5673create table t(x bigint, y bigint);
5674select t$0 from t;
5675"), @r"
5676 ╭▸
5677 2 │ create table t(x bigint, y bigint);
5678 │ ─ 2. destination
5679 3 │ select t from t;
5680 ╰╴ ─ 1. source
5681 ");
5682 }
5683
5684 #[test]
5685 fn goto_select_table_star_expansion() {
5686 assert_snapshot!(goto("
5687create table t(id int, a int);
5688select t$0.* from t;
5689"), @r"
5690 ╭▸
5691 2 │ create table t(id int, a int);
5692 │ ─ 2. destination
5693 3 │ select t.* from t;
5694 ╰╴ ─ 1. source
5695 ");
5696 }
5697
5698 #[test]
5699 fn goto_select_table_as_column_with_schema() {
5700 assert_snapshot!(goto("
5701create table public.t(x bigint, y bigint);
5702select t$0 from public.t;
5703"), @r"
5704 ╭▸
5705 2 │ create table public.t(x bigint, y bigint);
5706 │ ─ 2. destination
5707 3 │ select t from public.t;
5708 ╰╴ ─ 1. source
5709 ");
5710 }
5711
5712 #[test]
5713 fn goto_select_table_as_column_with_search_path() {
5714 assert_snapshot!(goto("
5715set search_path to foo;
5716create table foo.users(id int, email text);
5717select users$0 from users;
5718"), @r"
5719 ╭▸
5720 3 │ create table foo.users(id int, email text);
5721 │ ───── 2. destination
5722 4 │ select users from users;
5723 ╰╴ ─ 1. source
5724 ");
5725 }
5726
5727 #[test]
5728 fn goto_select_column_with_same_name_as_table() {
5729 assert_snapshot!(goto("
5730create table t(t int);
5731select t$0 from t;
5732"), @r"
5733 ╭▸
5734 2 │ create table t(t int);
5735 │ ─ 2. destination
5736 3 │ select t from t;
5737 ╰╴ ─ 1. source
5738 ");
5739 }
5740
5741 #[test]
5742 fn goto_drop_schema() {
5743 assert_snapshot!(goto("
5744create schema foo;
5745drop schema foo$0;
5746"), @r"
5747 ╭▸
5748 2 │ create schema foo;
5749 │ ─── 2. destination
5750 3 │ drop schema foo;
5751 ╰╴ ─ 1. source
5752 ");
5753 }
5754
5755 #[test]
5756 fn goto_create_schema_authorization() {
5757 assert_snapshot!(goto("
5758create schema authorization foo$0;
5759"), @r"
5760 ╭▸
5761 2 │ create schema authorization foo;
5762 │ ┬─┬
5763 │ │ │
5764 │ │ 1. source
5765 ╰╴ 2. destination
5766 ");
5767 }
5768
5769 #[test]
5770 fn goto_drop_schema_authorization() {
5771 assert_snapshot!(goto("
5772create schema authorization foo;
5773drop schema foo$0;
5774"), @r"
5775 ╭▸
5776 2 │ create schema authorization foo;
5777 │ ─── 2. destination
5778 3 │ drop schema foo;
5779 ╰╴ ─ 1. source
5780 ");
5781 }
5782
5783 #[test]
5784 fn goto_drop_schema_defined_after() {
5785 assert_snapshot!(goto("
5786drop schema foo$0;
5787create schema foo;
5788"), @r"
5789 ╭▸
5790 2 │ drop schema foo;
5791 │ ─ 1. source
5792 3 │ create schema foo;
5793 ╰╴ ─── 2. destination
5794 ");
5795 }
5796
5797 #[test]
5798 fn goto_schema_qualifier_in_table() {
5799 assert_snapshot!(goto("
5800create schema foo;
5801create table foo$0.t(a int);
5802"), @r"
5803 ╭▸
5804 2 │ create schema foo;
5805 │ ─── 2. destination
5806 3 │ create table foo.t(a int);
5807 ╰╴ ─ 1. source
5808 ");
5809 }
5810
5811 #[test]
5812 fn goto_schema_qualifier_in_drop_table() {
5813 assert_snapshot!(goto("
5814create schema foo;
5815create table foo.t(a int);
5816drop table foo$0.t;
5817"), @r"
5818 ╭▸
5819 2 │ create schema foo;
5820 │ ─── 2. destination
5821 3 │ create table foo.t(a int);
5822 4 │ drop table foo.t;
5823 ╰╴ ─ 1. source
5824 ");
5825 }
5826
5827 #[test]
5828 fn goto_schema_qualifier_multiple_schemas() {
5829 assert_snapshot!(goto("
5830create schema foo;
5831create schema bar;
5832create table bar$0.t(a int);
5833"), @r"
5834 ╭▸
5835 3 │ create schema bar;
5836 │ ─── 2. destination
5837 4 │ create table bar.t(a int);
5838 ╰╴ ─ 1. source
5839 ");
5840 }
5841
5842 #[test]
5843 fn goto_schema_qualifier_in_function_call() {
5844 assert_snapshot!(goto(r#"
5845create schema foo;
5846create function foo.bar() returns int as $$ begin return 1; end; $$ language plpgsql;
5847select foo$0.bar();
5848"#), @r"
5849 ╭▸
5850 2 │ create schema foo;
5851 │ ─── 2. destination
5852 3 │ create function foo.bar() returns int as $$ begin return 1; end; $$ language plpgsql;
5853 4 │ select foo.bar();
5854 ╰╴ ─ 1. source
5855 ");
5856 }
5857
5858 #[test]
5859 fn goto_schema_qualifier_in_function_call_from_clause() {
5860 assert_snapshot!(goto(r#"
5861create schema myschema;
5862create function myschema.get_data() returns table(id int) as $$ begin return query select 1; end; $$ language plpgsql;
5863select * from myschema$0.get_data();
5864"#), @r"
5865 ╭▸
5866 2 │ create schema myschema;
5867 │ ──────── 2. destination
5868 3 │ create function myschema.get_data() returns table(id int) as $$ begin return query select 1; end; $$ language plpgsql;
5869 4 │ select * from myschema.get_data();
5870 ╰╴ ─ 1. source
5871 ");
5872 }
5873
5874 #[test]
5875 fn goto_schema_qualifier_in_select_from() {
5876 assert_snapshot!(goto("
5877create schema foo;
5878create table foo.t(x int);
5879select x from foo$0.t;
5880"), @r"
5881 ╭▸
5882 2 │ create schema foo;
5883 │ ─── 2. destination
5884 3 │ create table foo.t(x int);
5885 4 │ select x from foo.t;
5886 ╰╴ ─ 1. source
5887 ");
5888 }
5889
5890 #[test]
5891 fn goto_qualified_column_table() {
5892 assert_snapshot!(goto("
5893create table t(a int);
5894select t$0.a from t;
5895"), @r"
5896 ╭▸
5897 2 │ create table t(a int);
5898 │ ─ 2. destination
5899 3 │ select t.a from t;
5900 ╰╴ ─ 1. source
5901 ");
5902 }
5903
5904 #[test]
5905 fn goto_qualified_column_column() {
5906 assert_snapshot!(goto("
5907create table t(a int);
5908select t.a$0 from t;
5909"), @r"
5910 ╭▸
5911 2 │ create table t(a int);
5912 │ ─ 2. destination
5913 3 │ select t.a from t;
5914 ╰╴ ─ 1. source
5915 ");
5916 }
5917
5918 #[test]
5919 fn goto_three_part_qualified_column_schema() {
5920 assert_snapshot!(goto("
5921create schema foo;
5922create table foo.t(a int);
5923select foo$0.t.a from t;
5924"), @r"
5925 ╭▸
5926 2 │ create schema foo;
5927 │ ─── 2. destination
5928 3 │ create table foo.t(a int);
5929 4 │ select foo.t.a from t;
5930 ╰╴ ─ 1. source
5931 ");
5932 }
5933
5934 #[test]
5935 fn goto_three_part_qualified_column_table() {
5936 assert_snapshot!(goto("
5937create schema foo;
5938create table foo.t(a int);
5939select foo.t$0.a from t;
5940"), @r"
5941 ╭▸
5942 3 │ create table foo.t(a int);
5943 │ ─ 2. destination
5944 4 │ select foo.t.a from t;
5945 ╰╴ ─ 1. source
5946 ");
5947 }
5948
5949 #[test]
5950 fn goto_three_part_qualified_column_column() {
5951 assert_snapshot!(goto("
5952create schema foo;
5953create table foo.t(a int);
5954select foo.t.a$0 from t;
5955"), @r"
5956 ╭▸
5957 3 │ create table foo.t(a int);
5958 │ ─ 2. destination
5959 4 │ select foo.t.a from t;
5960 ╰╴ ─ 1. source
5961 ");
5962 }
5963
5964 #[test]
5965 fn goto_cte_values_column1() {
5966 assert_snapshot!(goto("
5967with t as (
5968 values (1, 2), (3, 4)
5969)
5970select column1$0, column2 from t;
5971"), @r"
5972 ╭▸
5973 3 │ values (1, 2), (3, 4)
5974 │ ─ 2. destination
5975 4 │ )
5976 5 │ select column1, column2 from t;
5977 ╰╴ ─ 1. source
5978 ");
5979 }
5980
5981 #[test]
5982 fn goto_cte_values_column2() {
5983 assert_snapshot!(goto("
5984with t as (
5985 values (1, 2), (3, 4)
5986)
5987select column1, column2$0 from t;
5988"), @r"
5989 ╭▸
5990 3 │ values (1, 2), (3, 4)
5991 │ ─ 2. destination
5992 4 │ )
5993 5 │ select column1, column2 from t;
5994 ╰╴ ─ 1. source
5995 ");
5996 }
5997
5998 #[test]
5999 fn goto_cte_values_single_column() {
6000 assert_snapshot!(goto("
6001with t as (
6002 values (1), (2), (3)
6003)
6004select column1$0 from t;
6005"), @r"
6006 ╭▸
6007 3 │ values (1), (2), (3)
6008 │ ─ 2. destination
6009 4 │ )
6010 5 │ select column1 from t;
6011 ╰╴ ─ 1. source
6012 ");
6013 }
6014
6015 #[test]
6016 fn goto_cte_values_multiple_rows() {
6017 assert_snapshot!(goto("
6018with t as (
6019 values
6020 (1, 2, 3),
6021 (4, 5, 6),
6022 (7, 8, 9)
6023)
6024select column3$0 from t;
6025"), @r"
6026 ╭▸
6027 4 │ (1, 2, 3),
6028 │ ─ 2. destination
6029 ‡
6030 8 │ select column3 from t;
6031 ╰╴ ─ 1. source
6032 ");
6033 }
6034
6035 #[test]
6036 fn goto_cte_values_uppercase_column_names() {
6037 assert_snapshot!(goto("
6038with t as (
6039 values (1, 2), (3, 4)
6040)
6041select COLUMN1$0, COLUMN2 from t;
6042"), @r"
6043 ╭▸
6044 3 │ values (1, 2), (3, 4)
6045 │ ─ 2. destination
6046 4 │ )
6047 5 │ select COLUMN1, COLUMN2 from t;
6048 ╰╴ ─ 1. source
6049 ");
6050 }
6051
6052 #[test]
6053 fn goto_qualified_column_with_schema_in_from_table() {
6054 assert_snapshot!(goto("
6055create table foo.t(a int, b int);
6056select t$0.a from foo.t;
6057"), @r"
6058 ╭▸
6059 2 │ create table foo.t(a int, b int);
6060 │ ─ 2. destination
6061 3 │ select t.a from foo.t;
6062 ╰╴ ─ 1. source
6063 ");
6064 }
6065
6066 #[test]
6067 fn goto_qualified_column_with_schema_in_from_column() {
6068 assert_snapshot!(goto("
6069create table foo.t(a int, b int);
6070select t.a$0 from foo.t;
6071"), @r"
6072 ╭▸
6073 2 │ create table foo.t(a int, b int);
6074 │ ─ 2. destination
6075 3 │ select t.a from foo.t;
6076 ╰╴ ─ 1. source
6077 ");
6078 }
6079
6080 #[test]
6081 fn goto_cte_union_all_column() {
6082 assert_snapshot!(goto("
6083with t as (
6084 select 1 as a, 2 as b
6085 union all
6086 select 3, 4
6087)
6088select a$0, b from t;
6089"), @r"
6090 ╭▸
6091 3 │ select 1 as a, 2 as b
6092 │ ─ 2. destination
6093 ‡
6094 7 │ select a, b from t;
6095 ╰╴ ─ 1. source
6096 ");
6097 }
6098
6099 #[test]
6100 fn goto_cte_union_all_column_second() {
6101 assert_snapshot!(goto("
6102with t as (
6103 select 1 as a, 2 as b
6104 union all
6105 select 3, 4
6106)
6107select a, b$0 from t;
6108"), @r"
6109 ╭▸
6110 3 │ select 1 as a, 2 as b
6111 │ ─ 2. destination
6112 ‡
6113 7 │ select a, b from t;
6114 ╰╴ ─ 1. source
6115 ");
6116 }
6117
6118 #[test]
6119 fn goto_cte_union_column() {
6120 assert_snapshot!(goto("
6121with t as (
6122 select 1 as a, 2 as b
6123 union
6124 select 3, 4
6125)
6126select a$0 from t;
6127"), @r"
6128 ╭▸
6129 3 │ select 1 as a, 2 as b
6130 │ ─ 2. destination
6131 ‡
6132 7 │ select a from t;
6133 ╰╴ ─ 1. source
6134 ");
6135 }
6136
6137 #[test]
6138 fn goto_cte_insert_returning_column() {
6139 assert_snapshot!(goto("
6140create table t(a int, b int);
6141with inserted as (
6142 insert into t values (1, 2), (3, 4)
6143 returning a, b
6144)
6145select a$0 from inserted;
6146"), @r"
6147 ╭▸
6148 5 │ returning a, b
6149 │ ─ 2. destination
6150 6 │ )
6151 7 │ select a from inserted;
6152 ╰╴ ─ 1. source
6153 ");
6154 }
6155
6156 #[test]
6157 fn goto_cte_insert_returning_aliased_column() {
6158 assert_snapshot!(goto("
6159create table t(a int, b int);
6160with inserted as (
6161 insert into t values (1, 2), (3, 4)
6162 returning a as x
6163)
6164select x$0 from inserted;
6165"), @r"
6166 ╭▸
6167 5 │ returning a as x
6168 │ ─ 2. destination
6169 6 │ )
6170 7 │ select x from inserted;
6171 ╰╴ ─ 1. source
6172 ");
6173 }
6174
6175 #[test]
6176 fn goto_drop_aggregate() {
6177 assert_snapshot!(goto("
6178create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6179drop aggregate myavg$0(int);
6180"), @r"
6181 ╭▸
6182 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6183 │ ───── 2. destination
6184 3 │ drop aggregate myavg(int);
6185 ╰╴ ─ 1. source
6186 ");
6187 }
6188
6189 #[test]
6190 fn goto_drop_aggregate_with_schema() {
6191 assert_snapshot!(goto("
6192set search_path to public;
6193create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6194drop aggregate public.myavg$0(int);
6195"), @r"
6196 ╭▸
6197 3 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6198 │ ───── 2. destination
6199 4 │ drop aggregate public.myavg(int);
6200 ╰╴ ─ 1. source
6201 ");
6202 }
6203
6204 #[test]
6205 fn goto_drop_aggregate_defined_after() {
6206 assert_snapshot!(goto("
6207drop aggregate myavg$0(int);
6208create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6209"), @r"
6210 ╭▸
6211 2 │ drop aggregate myavg(int);
6212 │ ─ 1. source
6213 3 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6214 ╰╴ ───── 2. destination
6215 ");
6216 }
6217
6218 #[test]
6219 fn goto_aggregate_definition_returns_self() {
6220 assert_snapshot!(goto("
6221create aggregate myavg$0(int) (sfunc = int4_avg_accum, stype = _int8);
6222"), @r"
6223 ╭▸
6224 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6225 │ ┬───┬
6226 │ │ │
6227 │ │ 1. source
6228 ╰╴ 2. destination
6229 ");
6230 }
6231
6232 #[test]
6233 fn goto_drop_aggregate_with_search_path() {
6234 assert_snapshot!(goto("
6235create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6236set search_path to bar;
6237create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6238set search_path to default;
6239drop aggregate myavg$0(int);
6240"), @r"
6241 ╭▸
6242 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6243 │ ───── 2. destination
6244 ‡
6245 6 │ drop aggregate myavg(int);
6246 ╰╴ ─ 1. source
6247 ");
6248 }
6249
6250 #[test]
6251 fn goto_drop_aggregate_multiple() {
6252 assert_snapshot!(goto("
6253create aggregate avg1(int) (sfunc = int4_avg_accum, stype = _int8);
6254create aggregate avg2(int) (sfunc = int4_avg_accum, stype = _int8);
6255drop aggregate avg1(int), avg2$0(int);
6256"), @r"
6257 ╭▸
6258 3 │ create aggregate avg2(int) (sfunc = int4_avg_accum, stype = _int8);
6259 │ ──── 2. destination
6260 4 │ drop aggregate avg1(int), avg2(int);
6261 ╰╴ ─ 1. source
6262 ");
6263 }
6264
6265 #[test]
6266 fn goto_drop_aggregate_overloaded() {
6267 assert_snapshot!(goto("
6268create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
6269create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
6270drop aggregate sum$0(complex);
6271"), @r"
6272 ╭▸
6273 2 │ create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
6274 │ ─── 2. destination
6275 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
6276 4 │ drop aggregate sum(complex);
6277 ╰╴ ─ 1. source
6278 ");
6279 }
6280
6281 #[test]
6282 fn goto_drop_aggregate_second_overload() {
6283 assert_snapshot!(goto("
6284create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
6285create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
6286drop aggregate sum$0(bigint);
6287"), @r"
6288 ╭▸
6289 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
6290 │ ─── 2. destination
6291 4 │ drop aggregate sum(bigint);
6292 ╰╴ ─ 1. source
6293 ");
6294 }
6295
6296 #[test]
6297 fn goto_drop_routine_function() {
6298 assert_snapshot!(goto("
6299create function foo() returns int as $$ select 1 $$ language sql;
6300drop routine foo$0();
6301"), @r"
6302 ╭▸
6303 2 │ create function foo() returns int as $$ select 1 $$ language sql;
6304 │ ─── 2. destination
6305 3 │ drop routine foo();
6306 ╰╴ ─ 1. source
6307 ");
6308 }
6309
6310 #[test]
6311 fn goto_drop_routine_aggregate() {
6312 assert_snapshot!(goto("
6313create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6314drop routine myavg$0(int);
6315"), @r"
6316 ╭▸
6317 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
6318 │ ───── 2. destination
6319 3 │ drop routine myavg(int);
6320 ╰╴ ─ 1. source
6321 ");
6322 }
6323
6324 #[test]
6325 fn goto_drop_routine_with_schema() {
6326 assert_snapshot!(goto("
6327set search_path to public;
6328create function foo() returns int as $$ select 1 $$ language sql;
6329drop routine public.foo$0();
6330"), @r"
6331 ╭▸
6332 3 │ create function foo() returns int as $$ select 1 $$ language sql;
6333 │ ─── 2. destination
6334 4 │ drop routine public.foo();
6335 ╰╴ ─ 1. source
6336 ");
6337 }
6338
6339 #[test]
6340 fn goto_drop_routine_defined_after() {
6341 assert_snapshot!(goto("
6342drop routine foo$0();
6343create function foo() returns int as $$ select 1 $$ language sql;
6344"), @r"
6345 ╭▸
6346 2 │ drop routine foo();
6347 │ ─ 1. source
6348 3 │ create function foo() returns int as $$ select 1 $$ language sql;
6349 ╰╴ ─── 2. destination
6350 ");
6351 }
6352
6353 #[test]
6354 fn goto_drop_routine_with_search_path() {
6355 assert_snapshot!(goto("
6356create function foo() returns int as $$ select 1 $$ language sql;
6357set search_path to bar;
6358create function foo() returns int as $$ select 1 $$ language sql;
6359set search_path to default;
6360drop routine foo$0();
6361"), @r"
6362 ╭▸
6363 2 │ create function foo() returns int as $$ select 1 $$ language sql;
6364 │ ─── 2. destination
6365 ‡
6366 6 │ drop routine foo();
6367 ╰╴ ─ 1. source
6368 ");
6369 }
6370
6371 #[test]
6372 fn goto_drop_routine_overloaded() {
6373 assert_snapshot!(goto("
6374create function add(complex) returns complex as $$ select null $$ language sql;
6375create function add(bigint) returns bigint as $$ select 1 $$ language sql;
6376drop routine add$0(complex);
6377"), @r"
6378 ╭▸
6379 2 │ create function add(complex) returns complex as $$ select null $$ language sql;
6380 │ ─── 2. destination
6381 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
6382 4 │ drop routine add(complex);
6383 ╰╴ ─ 1. source
6384 ");
6385 }
6386
6387 #[test]
6388 fn goto_drop_routine_second_overload() {
6389 assert_snapshot!(goto("
6390create function add(complex) returns complex as $$ select null $$ language sql;
6391create function add(bigint) returns bigint as $$ select 1 $$ language sql;
6392drop routine add$0(bigint);
6393"), @r"
6394 ╭▸
6395 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
6396 │ ─── 2. destination
6397 4 │ drop routine add(bigint);
6398 ╰╴ ─ 1. source
6399 ");
6400 }
6401
6402 #[test]
6403 fn goto_drop_routine_aggregate_overloaded() {
6404 assert_snapshot!(goto("
6405create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
6406create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
6407drop routine sum$0(complex);
6408"), @r"
6409 ╭▸
6410 2 │ create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
6411 │ ─── 2. destination
6412 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
6413 4 │ drop routine sum(complex);
6414 ╰╴ ─ 1. source
6415 ");
6416 }
6417
6418 #[test]
6419 fn goto_drop_routine_multiple() {
6420 assert_snapshot!(goto("
6421create function foo() returns int as $$ select 1 $$ language sql;
6422create function bar() returns int as $$ select 1 $$ language sql;
6423drop routine foo(), bar$0();
6424"), @r"
6425 ╭▸
6426 3 │ create function bar() returns int as $$ select 1 $$ language sql;
6427 │ ─── 2. destination
6428 4 │ drop routine foo(), bar();
6429 ╰╴ ─ 1. source
6430 ");
6431 }
6432
6433 #[test]
6434 fn goto_drop_procedure() {
6435 assert_snapshot!(goto("
6436create procedure foo() language sql as $$ select 1 $$;
6437drop procedure foo$0();
6438"), @r"
6439 ╭▸
6440 2 │ create procedure foo() language sql as $$ select 1 $$;
6441 │ ─── 2. destination
6442 3 │ drop procedure foo();
6443 ╰╴ ─ 1. source
6444 ");
6445 }
6446
6447 #[test]
6448 fn goto_drop_procedure_with_schema() {
6449 assert_snapshot!(goto("
6450set search_path to public;
6451create procedure foo() language sql as $$ select 1 $$;
6452drop procedure public.foo$0();
6453"), @r"
6454 ╭▸
6455 3 │ create procedure foo() language sql as $$ select 1 $$;
6456 │ ─── 2. destination
6457 4 │ drop procedure public.foo();
6458 ╰╴ ─ 1. source
6459 ");
6460 }
6461
6462 #[test]
6463 fn goto_drop_procedure_defined_after() {
6464 assert_snapshot!(goto("
6465drop procedure foo$0();
6466create procedure foo() language sql as $$ select 1 $$;
6467"), @r"
6468 ╭▸
6469 2 │ drop procedure foo();
6470 │ ─ 1. source
6471 3 │ create procedure foo() language sql as $$ select 1 $$;
6472 ╰╴ ─── 2. destination
6473 ");
6474 }
6475
6476 #[test]
6477 fn goto_drop_procedure_with_search_path() {
6478 assert_snapshot!(goto("
6479create procedure foo() language sql as $$ select 1 $$;
6480set search_path to bar;
6481create procedure foo() language sql as $$ select 1 $$;
6482set search_path to default;
6483drop procedure foo$0();
6484"), @r"
6485 ╭▸
6486 2 │ create procedure foo() language sql as $$ select 1 $$;
6487 │ ─── 2. destination
6488 ‡
6489 6 │ drop procedure foo();
6490 ╰╴ ─ 1. source
6491 ");
6492 }
6493
6494 #[test]
6495 fn goto_drop_procedure_overloaded() {
6496 assert_snapshot!(goto("
6497create procedure add(complex) language sql as $$ select null $$;
6498create procedure add(bigint) language sql as $$ select 1 $$;
6499drop procedure add$0(complex);
6500"), @r"
6501 ╭▸
6502 2 │ create procedure add(complex) language sql as $$ select null $$;
6503 │ ─── 2. destination
6504 3 │ create procedure add(bigint) language sql as $$ select 1 $$;
6505 4 │ drop procedure add(complex);
6506 ╰╴ ─ 1. source
6507 ");
6508 }
6509
6510 #[test]
6511 fn goto_drop_procedure_second_overload() {
6512 assert_snapshot!(goto("
6513create procedure add(complex) language sql as $$ select null $$;
6514create procedure add(bigint) language sql as $$ select 1 $$;
6515drop procedure add$0(bigint);
6516"), @r"
6517 ╭▸
6518 3 │ create procedure add(bigint) language sql as $$ select 1 $$;
6519 │ ─── 2. destination
6520 4 │ drop procedure add(bigint);
6521 ╰╴ ─ 1. source
6522 ");
6523 }
6524
6525 #[test]
6526 fn goto_drop_procedure_multiple() {
6527 assert_snapshot!(goto("
6528create procedure foo() language sql as $$ select 1 $$;
6529create procedure bar() language sql as $$ select 1 $$;
6530drop procedure foo(), bar$0();
6531"), @r"
6532 ╭▸
6533 3 │ create procedure bar() language sql as $$ select 1 $$;
6534 │ ─── 2. destination
6535 4 │ drop procedure foo(), bar();
6536 ╰╴ ─ 1. source
6537 ");
6538 }
6539
6540 #[test]
6541 fn goto_procedure_definition_returns_self() {
6542 assert_snapshot!(goto("
6543create procedure foo$0() language sql as $$ select 1 $$;
6544"), @r"
6545 ╭▸
6546 2 │ create procedure foo() language sql as $$ select 1 $$;
6547 │ ┬─┬
6548 │ │ │
6549 │ │ 1. source
6550 ╰╴ 2. destination
6551 ");
6552 }
6553
6554 #[test]
6555 fn goto_call_procedure() {
6556 assert_snapshot!(goto("
6557create procedure foo() language sql as $$ select 1 $$;
6558call foo$0();
6559"), @r"
6560 ╭▸
6561 2 │ create procedure foo() language sql as $$ select 1 $$;
6562 │ ─── 2. destination
6563 3 │ call foo();
6564 ╰╴ ─ 1. source
6565 ");
6566 }
6567
6568 #[test]
6569 fn goto_call_procedure_with_schema() {
6570 assert_snapshot!(goto("
6571create procedure public.foo() language sql as $$ select 1 $$;
6572call public.foo$0();
6573"), @r"
6574 ╭▸
6575 2 │ create procedure public.foo() language sql as $$ select 1 $$;
6576 │ ─── 2. destination
6577 3 │ call public.foo();
6578 ╰╴ ─ 1. source
6579 ");
6580 }
6581
6582 #[test]
6583 fn goto_call_procedure_with_search_path() {
6584 assert_snapshot!(goto("
6585set search_path to myschema;
6586create procedure foo() language sql as $$ select 1 $$;
6587call myschema.foo$0();
6588"), @r"
6589 ╭▸
6590 3 │ create procedure foo() language sql as $$ select 1 $$;
6591 │ ─── 2. destination
6592 4 │ call myschema.foo();
6593 ╰╴ ─ 1. source
6594 ");
6595 }
6596
6597 #[test]
6598 fn goto_drop_routine_procedure() {
6599 assert_snapshot!(goto("
6600create procedure foo() language sql as $$ select 1 $$;
6601drop routine foo$0();
6602"), @r"
6603 ╭▸
6604 2 │ create procedure foo() language sql as $$ select 1 $$;
6605 │ ─── 2. destination
6606 3 │ drop routine foo();
6607 ╰╴ ─ 1. source
6608 ");
6609 }
6610
6611 #[test]
6612 fn goto_drop_routine_prefers_function_over_procedure() {
6613 assert_snapshot!(goto("
6614create function foo() returns int as $$ select 1 $$ language sql;
6615create procedure foo() language sql as $$ select 1 $$;
6616drop routine foo$0();
6617"), @r"
6618 ╭▸
6619 2 │ create function foo() returns int as $$ select 1 $$ language sql;
6620 │ ─── 2. destination
6621 3 │ create procedure foo() language sql as $$ select 1 $$;
6622 4 │ drop routine foo();
6623 ╰╴ ─ 1. source
6624 ");
6625 }
6626
6627 #[test]
6628 fn goto_drop_routine_prefers_aggregate_over_procedure() {
6629 assert_snapshot!(goto("
6630create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
6631create procedure foo(int) language sql as $$ select 1 $$;
6632drop routine foo$0(int);
6633"), @r"
6634 ╭▸
6635 2 │ create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
6636 │ ─── 2. destination
6637 3 │ create procedure foo(int) language sql as $$ select 1 $$;
6638 4 │ drop routine foo(int);
6639 ╰╴ ─ 1. source
6640 ");
6641 }
6642
6643 #[test]
6644 fn goto_table_alias_in_qualified_column() {
6645 assert_snapshot!(goto("
6646create table t(a int8, b text);
6647select f$0.a from t as f;
6648"), @r"
6649 ╭▸
6650 3 │ select f.a from t as f;
6651 ╰╴ ─ 1. source ─ 2. destination
6652 ");
6653 }
6654
6655 #[test]
6656 fn goto_column_through_table_alias() {
6657 assert_snapshot!(goto("
6658create table t(a int8, b text);
6659select f.a$0 from t as f;
6660"), @r"
6661 ╭▸
6662 2 │ create table t(a int8, b text);
6663 │ ─ 2. destination
6664 3 │ select f.a from t as f;
6665 ╰╴ ─ 1. source
6666 ");
6667 }
6668
6669 #[test]
6670 fn goto_cte_alias_renamed_column() {
6671 assert_snapshot!(goto("
6672with t as (select 1 a, 2 b)
6673select f.x$0 from t as f(x);
6674"), @r"
6675 ╭▸
6676 3 │ select f.x from t as f(x);
6677 ╰╴ ─ 1. source ─ 2. destination
6678 ");
6679 }
6680
6681 #[test]
6682 fn goto_cte_alias_unrenamed_column() {
6683 assert_snapshot!(goto("
6684with t as (select 1 a, 2 b)
6685select f.b$0 from t as f(x);
6686"), @r"
6687 ╭▸
6688 2 │ with t as (select 1 a, 2 b)
6689 │ ─ 2. destination
6690 3 │ select f.b from t as f(x);
6691 ╰╴ ─ 1. source
6692 ");
6693 }
6694
6695 #[test]
6696 fn goto_join_table() {
6697 assert_snapshot!(goto("
6698create table users(id int, email text);
6699create table messages(id int, user_id int, message text);
6700select * from users join messages$0 on users.id = messages.user_id;
6701"), @r"
6702 ╭▸
6703 3 │ create table messages(id int, user_id int, message text);
6704 │ ──────── 2. destination
6705 4 │ select * from users join messages on users.id = messages.user_id;
6706 ╰╴ ─ 1. source
6707 ");
6708 }
6709
6710 #[test]
6711 fn goto_join_qualified_column_from_joined_table() {
6712 assert_snapshot!(goto("
6713create table users(id int, email text);
6714create table messages(id int, user_id int, message text);
6715select messages.user_id$0 from users join messages on users.id = messages.user_id;
6716"), @r"
6717 ╭▸
6718 3 │ create table messages(id int, user_id int, message text);
6719 │ ─────── 2. destination
6720 4 │ select messages.user_id from users join messages on users.id = messages.user_id;
6721 ╰╴ ─ 1. source
6722 ");
6723 }
6724
6725 #[test]
6726 fn goto_join_qualified_column_from_base_table() {
6727 assert_snapshot!(goto("
6728create table users(id int, email text);
6729create table messages(id int, user_id int, message text);
6730select users.id$0 from users join messages on users.id = messages.user_id;
6731"), @r"
6732 ╭▸
6733 2 │ create table users(id int, email text);
6734 │ ── 2. destination
6735 3 │ create table messages(id int, user_id int, message text);
6736 4 │ select users.id from users join messages on users.id = messages.user_id;
6737 ╰╴ ─ 1. source
6738 ");
6739 }
6740
6741 #[test]
6742 fn goto_join_multiple_joins() {
6743 assert_snapshot!(goto("
6744create table users(id int, name text);
6745create table messages(id int, user_id int, message text);
6746create table comments(id int, message_id int, text text);
6747select comments.text$0 from users
6748 join messages on users.id = messages.user_id
6749 join comments on messages.id = comments.message_id;
6750"), @r"
6751 ╭▸
6752 4 │ create table comments(id int, message_id int, text text);
6753 │ ──── 2. destination
6754 5 │ select comments.text from users
6755 ╰╴ ─ 1. source
6756 ");
6757 }
6758
6759 #[test]
6760 fn goto_join_with_aliases() {
6761 assert_snapshot!(goto("
6762create table users(id int, name text);
6763create table messages(id int, user_id int, message text);
6764select m.message$0 from users as u join messages as m on u.id = m.user_id;
6765"), @r"
6766 ╭▸
6767 3 │ create table messages(id int, user_id int, message text);
6768 │ ─────── 2. destination
6769 4 │ select m.message from users as u join messages as m on u.id = m.user_id;
6770 ╰╴ ─ 1. source
6771 ");
6772 }
6773
6774 #[test]
6775 fn goto_join_unqualified_column() {
6776 assert_snapshot!(goto("
6777create table users(id int, email text);
6778create table messages(id int, user_id int, message text);
6779select message$0 from users join messages on users.id = messages.user_id;
6780"), @r"
6781 ╭▸
6782 3 │ create table messages(id int, user_id int, message text);
6783 │ ─────── 2. destination
6784 4 │ select message from users join messages on users.id = messages.user_id;
6785 ╰╴ ─ 1. source
6786 ");
6787 }
6788
6789 #[test]
6790 fn goto_join_with_many_tables() {
6791 assert_snapshot!(goto("
6792create table users(id int, email text);
6793create table messages(id int, user_id int, message text);
6794create table logins(id int, user_id int, at timestamptz);
6795create table posts(id int, user_id int, post text);
6796
6797select post$0
6798 from users
6799 join messages
6800 on users.id = messages.user_id
6801 join logins
6802 on users.id = logins.user_id
6803 join posts
6804 on users.id = posts.user_id
6805"), @r"
6806 ╭▸
6807 5 │ create table posts(id int, user_id int, post text);
6808 │ ──── 2. destination
6809 6 │
6810 7 │ select post
6811 ╰╴ ─ 1. source
6812 ");
6813 }
6814
6815 #[test]
6816 fn goto_join_with_schema() {
6817 assert_snapshot!(goto("
6818create schema foo;
6819create table foo.users(id int, email text);
6820create table foo.messages(id int, user_id int, message text);
6821select foo.messages.message$0 from foo.users join foo.messages on foo.users.id = foo.messages.user_id;
6822"), @r"
6823 ╭▸
6824 4 │ create table foo.messages(id int, user_id int, message text);
6825 │ ─────── 2. destination
6826 5 │ select foo.messages.message from foo.users join foo.messages on foo.users.id = foo.messages.user_id;
6827 ╰╴ ─ 1. source
6828 ");
6829 }
6830
6831 #[test]
6832 fn goto_join_left_join() {
6833 assert_snapshot!(goto("
6834create table users(id int, email text);
6835create table messages(id int, user_id int, message text);
6836select messages.message$0 from users left join messages on users.id = messages.user_id;
6837"), @r"
6838 ╭▸
6839 3 │ create table messages(id int, user_id int, message text);
6840 │ ─────── 2. destination
6841 4 │ select messages.message from users left join messages on users.id = messages.user_id;
6842 ╰╴ ─ 1. source
6843 ");
6844 }
6845
6846 #[test]
6847 fn goto_join_on_table_qualifier() {
6848 assert_snapshot!(goto("
6849create table t(a int);
6850create table u(a int);
6851select * from t join u on u$0.a = t.a;
6852"), @r"
6853 ╭▸
6854 3 │ create table u(a int);
6855 │ ─ 2. destination
6856 4 │ select * from t join u on u.a = t.a;
6857 ╰╴ ─ 1. source
6858 ");
6859 }
6860
6861 #[test]
6862 fn goto_join_on_column() {
6863 assert_snapshot!(goto("
6864create table t(a int);
6865create table u(a int);
6866select * from t join u on u.a$0 = t.a;
6867"), @r"
6868 ╭▸
6869 3 │ create table u(a int);
6870 │ ─ 2. destination
6871 4 │ select * from t join u on u.a = t.a;
6872 ╰╴ ─ 1. source
6873 ");
6874 }
6875
6876 #[test]
6877 fn goto_join_using_column() {
6878 assert_snapshot!(goto("
6879create table t(a int);
6880create table u(a int);
6881select * from t join u using (a$0);
6882"), @r"
6883 ╭▸
6884 2 │ create table t(a int);
6885 │ ─ 2. destination
6886 3 │ create table u(a int);
6887 │ ─ 3. destination
6888 4 │ select * from t join u using (a);
6889 ╰╴ ─ 1. source
6890 ");
6891 }
6892
6893 #[test]
6894 fn goto_insert_select_cte_column() {
6895 assert_snapshot!(goto("
6896create table users(id int, email text);
6897with new_data as (
6898 select 1 as id, 'test@example.com' as email
6899)
6900insert into users (id, email)
6901select id$0, email from new_data;
6902"), @r"
6903 ╭▸
6904 4 │ select 1 as id, 'test@example.com' as email
6905 │ ── 2. destination
6906 ‡
6907 7 │ select id, email from new_data;
6908 ╰╴ ─ 1. source
6909 ");
6910 }
6911
6912 #[test]
6913 fn goto_insert_select_cte_column_second() {
6914 assert_snapshot!(goto("
6915create table users(id int, email text);
6916with new_data as (
6917 select 1 as id, 'test@example.com' as email
6918)
6919insert into users (id, email)
6920select id, email$0 from new_data;
6921"), @r"
6922 ╭▸
6923 4 │ select 1 as id, 'test@example.com' as email
6924 │ ───── 2. destination
6925 ‡
6926 7 │ select id, email from new_data;
6927 ╰╴ ─ 1. source
6928 ");
6929 }
6930
6931 #[test]
6932 fn goto_insert_select_cte_table() {
6933 assert_snapshot!(goto("
6934create table users(id int, email text);
6935with new_data as (
6936 select 1 as id, 'test@example.com' as email
6937)
6938insert into users (id, email)
6939select id, email from new_data$0;
6940"), @r"
6941 ╭▸
6942 3 │ with new_data as (
6943 │ ──────── 2. destination
6944 ‡
6945 7 │ select id, email from new_data;
6946 ╰╴ ─ 1. source
6947 ");
6948 }
6949
6950 #[test]
6951 fn goto_delete_cte_column() {
6952 assert_snapshot!(goto("
6953create table users(id int, email text);
6954with old_data as (
6955 select 1 as id
6956)
6957delete from users where id in (select id$0 from old_data);
6958"), @r"
6959 ╭▸
6960 4 │ select 1 as id
6961 │ ── 2. destination
6962 5 │ )
6963 6 │ delete from users where id in (select id from old_data);
6964 ╰╴ ─ 1. source
6965 ");
6966 }
6967
6968 #[test]
6969 fn goto_update_table() {
6970 assert_snapshot!(goto("
6971create table users(id int, email text);
6972update users$0 set email = 'new@example.com';
6973"), @r"
6974 ╭▸
6975 2 │ create table users(id int, email text);
6976 │ ───── 2. destination
6977 3 │ update users set email = 'new@example.com';
6978 ╰╴ ─ 1. source
6979 ");
6980 }
6981
6982 #[test]
6983 fn goto_update_table_with_schema() {
6984 assert_snapshot!(goto("
6985create table public.users(id int, email text);
6986update public.users$0 set email = 'new@example.com';
6987"), @r"
6988 ╭▸
6989 2 │ create table public.users(id int, email text);
6990 │ ───── 2. destination
6991 3 │ update public.users set email = 'new@example.com';
6992 ╰╴ ─ 1. source
6993 ");
6994 }
6995
6996 #[test]
6997 fn goto_update_table_with_search_path() {
6998 assert_snapshot!(goto("
6999set search_path to foo;
7000create table foo.users(id int, email text);
7001update users$0 set email = 'new@example.com';
7002"), @r"
7003 ╭▸
7004 3 │ create table foo.users(id int, email text);
7005 │ ───── 2. destination
7006 4 │ update users set email = 'new@example.com';
7007 ╰╴ ─ 1. source
7008 ");
7009 }
7010
7011 #[test]
7012 fn goto_update_where_column() {
7013 assert_snapshot!(goto("
7014create table users(id int, email text);
7015update users set email = 'new@example.com' where id$0 = 1;
7016"), @r"
7017 ╭▸
7018 2 │ create table users(id int, email text);
7019 │ ── 2. destination
7020 3 │ update users set email = 'new@example.com' where id = 1;
7021 ╰╴ ─ 1. source
7022 ");
7023 }
7024
7025 #[test]
7026 fn goto_update_where_column_with_schema() {
7027 assert_snapshot!(goto("
7028create table public.users(id int, email text);
7029update public.users set email = 'new@example.com' where id$0 = 1;
7030"), @r"
7031 ╭▸
7032 2 │ create table public.users(id int, email text);
7033 │ ── 2. destination
7034 3 │ update public.users set email = 'new@example.com' where id = 1;
7035 ╰╴ ─ 1. source
7036 ");
7037 }
7038
7039 #[test]
7040 fn goto_update_where_column_with_search_path() {
7041 assert_snapshot!(goto("
7042set search_path to foo;
7043create table foo.users(id int, email text);
7044update users set email = 'new@example.com' where id$0 = 1;
7045"), @r"
7046 ╭▸
7047 3 │ create table foo.users(id int, email text);
7048 │ ── 2. destination
7049 4 │ update users set email = 'new@example.com' where id = 1;
7050 ╰╴ ─ 1. source
7051 ");
7052 }
7053
7054 #[test]
7055 fn goto_update_set_column() {
7056 assert_snapshot!(goto("
7057create table users(id int, email text);
7058update users set email$0 = 'new@example.com' where id = 1;
7059"), @r"
7060 ╭▸
7061 2 │ create table users(id int, email text);
7062 │ ───── 2. destination
7063 3 │ update users set email = 'new@example.com' where id = 1;
7064 ╰╴ ─ 1. source
7065 ");
7066 }
7067
7068 #[test]
7069 fn goto_update_set_column_with_schema() {
7070 assert_snapshot!(goto("
7071create table public.users(id int, email text);
7072update public.users set email$0 = 'new@example.com' where id = 1;
7073"), @r"
7074 ╭▸
7075 2 │ create table public.users(id int, email text);
7076 │ ───── 2. destination
7077 3 │ update public.users set email = 'new@example.com' where id = 1;
7078 ╰╴ ─ 1. source
7079 ");
7080 }
7081
7082 #[test]
7083 fn goto_update_set_column_with_search_path() {
7084 assert_snapshot!(goto("
7085set search_path to foo;
7086create table foo.users(id int, email text);
7087update users set email$0 = 'new@example.com' where id = 1;
7088"), @r"
7089 ╭▸
7090 3 │ create table foo.users(id int, email text);
7091 │ ───── 2. destination
7092 4 │ update users set email = 'new@example.com' where id = 1;
7093 ╰╴ ─ 1. source
7094 ");
7095 }
7096
7097 #[test]
7098 fn goto_update_from_table() {
7099 assert_snapshot!(goto("
7100create table users(id int, email text);
7101create table messages(id int, user_id int, email text);
7102update users set email = messages.email from messages$0 where users.id = messages.user_id;
7103"), @r"
7104 ╭▸
7105 3 │ create table messages(id int, user_id int, email text);
7106 │ ──────── 2. destination
7107 4 │ update users set email = messages.email from messages where users.id = messages.user_id;
7108 ╰╴ ─ 1. source
7109 ");
7110 }
7111
7112 #[test]
7113 fn goto_update_from_table_with_schema() {
7114 assert_snapshot!(goto("
7115create table users(id int, email text);
7116create table public.messages(id int, user_id int, email text);
7117update users set email = messages.email from public.messages$0 where users.id = messages.user_id;
7118"), @r"
7119 ╭▸
7120 3 │ create table public.messages(id int, user_id int, email text);
7121 │ ──────── 2. destination
7122 4 │ update users set email = messages.email from public.messages where users.id = messages.user_id;
7123 ╰╴ ─ 1. source
7124 ");
7125 }
7126
7127 #[test]
7128 fn goto_update_from_table_with_search_path() {
7129 assert_snapshot!(goto("
7130set search_path to foo;
7131create table users(id int, email text);
7132create table foo.messages(id int, user_id int, email text);
7133update users set email = messages.email from messages$0 where users.id = messages.user_id;
7134"), @r"
7135 ╭▸
7136 4 │ create table foo.messages(id int, user_id int, email text);
7137 │ ──────── 2. destination
7138 5 │ update users set email = messages.email from messages where users.id = messages.user_id;
7139 ╰╴ ─ 1. source
7140 ");
7141 }
7142
7143 #[test]
7144 fn goto_update_with_cte_table() {
7145 assert_snapshot!(goto("
7146create table users(id int, email text);
7147with new_data as (
7148 select 1 as id, 'new@example.com' as email
7149)
7150update users set email = new_data.email from new_data$0 where users.id = new_data.id;
7151"), @r"
7152 ╭▸
7153 3 │ with new_data as (
7154 │ ──────── 2. destination
7155 ‡
7156 6 │ update users set email = new_data.email from new_data where users.id = new_data.id;
7157 ╰╴ ─ 1. source
7158 ");
7159 }
7160
7161 #[test]
7162 fn goto_update_with_cte_column_in_set() {
7163 assert_snapshot!(goto("
7164create table users(id int, email text);
7165with new_data as (
7166 select 1 as id, 'new@example.com' as email
7167)
7168update users set email = new_data.email$0 from new_data where users.id = new_data.id;
7169"), @r"
7170 ╭▸
7171 4 │ select 1 as id, 'new@example.com' as email
7172 │ ───── 2. destination
7173 5 │ )
7174 6 │ update users set email = new_data.email from new_data where users.id = new_data.id;
7175 ╰╴ ─ 1. source
7176 ");
7177 }
7178
7179 #[test]
7180 fn goto_update_with_cte_column_in_where() {
7181 assert_snapshot!(goto("
7182create table users(id int, email text);
7183with new_data as (
7184 select 1 as id, 'new@example.com' as email
7185)
7186update users set email = new_data.email from new_data where new_data.id$0 = users.id;
7187"), @r"
7188 ╭▸
7189 4 │ select 1 as id, 'new@example.com' as email
7190 │ ── 2. destination
7191 5 │ )
7192 6 │ update users set email = new_data.email from new_data where new_data.id = users.id;
7193 ╰╴ ─ 1. source
7194 ");
7195 }
7196
7197 #[test]
7198 fn goto_update_with_cte_values() {
7199 assert_snapshot!(goto("
7200create table users(id int, email text);
7201with new_data as (
7202 values (1, 'new@example.com')
7203)
7204update users set email = new_data.column2$0 from new_data where users.id = new_data.column1;
7205"), @r"
7206 ╭▸
7207 4 │ values (1, 'new@example.com')
7208 │ ───────────────── 2. destination
7209 5 │ )
7210 6 │ update users set email = new_data.column2 from new_data where users.id = new_data.column1;
7211 ╰╴ ─ 1. source
7212 ");
7213 }
7214
7215 #[test]
7216 fn goto_truncate_table() {
7217 assert_snapshot!(goto("
7218create table t();
7219truncate table t$0;
7220"), @r"
7221 ╭▸
7222 2 │ create table t();
7223 │ ─ 2. destination
7224 3 │ truncate table t;
7225 ╰╴ ─ 1. source
7226 ");
7227 }
7228
7229 #[test]
7230 fn goto_truncate_table_without_table_keyword() {
7231 assert_snapshot!(goto("
7232create table t();
7233truncate t$0;
7234"), @r"
7235 ╭▸
7236 2 │ create table t();
7237 │ ─ 2. destination
7238 3 │ truncate t;
7239 ╰╴ ─ 1. source
7240 ");
7241 }
7242
7243 #[test]
7244 fn goto_truncate_multiple_tables() {
7245 assert_snapshot!(goto("
7246create table t1();
7247create table t2();
7248truncate t1, t2$0;
7249"), @r"
7250 ╭▸
7251 3 │ create table t2();
7252 │ ── 2. destination
7253 4 │ truncate t1, t2;
7254 ╰╴ ─ 1. source
7255 ");
7256 }
7257
7258 #[test]
7259 fn goto_lock_table() {
7260 assert_snapshot!(goto("
7261create table t();
7262lock table t$0;
7263"), @r"
7264 ╭▸
7265 2 │ create table t();
7266 │ ─ 2. destination
7267 3 │ lock table t;
7268 ╰╴ ─ 1. source
7269 ");
7270 }
7271
7272 #[test]
7273 fn goto_lock_table_without_table_keyword() {
7274 assert_snapshot!(goto("
7275create table t();
7276lock t$0;
7277"), @r"
7278 ╭▸
7279 2 │ create table t();
7280 │ ─ 2. destination
7281 3 │ lock t;
7282 ╰╴ ─ 1. source
7283 ");
7284 }
7285
7286 #[test]
7287 fn goto_lock_multiple_tables() {
7288 assert_snapshot!(goto("
7289create table t1();
7290create table t2();
7291lock t1, t2$0;
7292"), @r"
7293 ╭▸
7294 3 │ create table t2();
7295 │ ── 2. destination
7296 4 │ lock t1, t2;
7297 ╰╴ ─ 1. source
7298 ");
7299 }
7300
7301 #[test]
7302 fn goto_vacuum_table() {
7303 assert_snapshot!(goto("
7304create table users(id int, email text);
7305vacuum users$0;
7306"), @r"
7307 ╭▸
7308 2 │ create table users(id int, email text);
7309 │ ───── 2. destination
7310 3 │ vacuum users;
7311 ╰╴ ─ 1. source
7312 ");
7313 }
7314
7315 #[test]
7316 fn goto_vacuum_multiple_tables() {
7317 assert_snapshot!(goto("
7318create table t1();
7319create table t2();
7320vacuum t1, t2$0;
7321"), @r"
7322 ╭▸
7323 3 │ create table t2();
7324 │ ── 2. destination
7325 4 │ vacuum t1, t2;
7326 ╰╴ ─ 1. source
7327 ");
7328 }
7329
7330 #[test]
7331 fn goto_alter_table() {
7332 assert_snapshot!(goto("
7333create table users(id int, email text);
7334alter table users$0 alter email set not null;
7335"), @r"
7336 ╭▸
7337 2 │ create table users(id int, email text);
7338 │ ───── 2. destination
7339 3 │ alter table users alter email set not null;
7340 ╰╴ ─ 1. source
7341 ");
7342 }
7343
7344 #[test]
7345 fn goto_alter_table_column() {
7346 assert_snapshot!(goto("
7347create table users(id int, email text);
7348alter table users alter email$0 set not null;
7349"), @r"
7350 ╭▸
7351 2 │ create table users(id int, email text);
7352 │ ───── 2. destination
7353 3 │ alter table users alter email set not null;
7354 ╰╴ ─ 1. source
7355 ");
7356 }
7357
7358 #[test]
7359 fn goto_alter_table_column_with_column_keyword() {
7360 assert_snapshot!(goto("
7361create table users(id int, email text);
7362alter table users alter column email$0 set not null;
7363"), @r"
7364 ╭▸
7365 2 │ create table users(id int, email text);
7366 │ ───── 2. destination
7367 3 │ alter table users alter column email set not null;
7368 ╰╴ ─ 1. source
7369 ");
7370 }
7371
7372 #[test]
7373 fn goto_alter_table_add_column() {
7374 assert_snapshot!(goto("
7375create table users(id int);
7376alter table users$0 add column email text;
7377"), @r"
7378 ╭▸
7379 2 │ create table users(id int);
7380 │ ───── 2. destination
7381 3 │ alter table users add column email text;
7382 ╰╴ ─ 1. source
7383 ");
7384 }
7385
7386 #[test]
7387 fn goto_alter_table_drop_column() {
7388 assert_snapshot!(goto("
7389create table users(id int, email text);
7390alter table users drop column email$0;
7391"), @r"
7392 ╭▸
7393 2 │ create table users(id int, email text);
7394 │ ───── 2. destination
7395 3 │ alter table users drop column email;
7396 ╰╴ ─ 1. source
7397 ");
7398 }
7399
7400 #[test]
7401 fn goto_alter_table_drop_column_table_name() {
7402 assert_snapshot!(goto("
7403create table users(id int, email text);
7404alter table users$0 drop column email;
7405"), @r"
7406 ╭▸
7407 2 │ create table users(id int, email text);
7408 │ ───── 2. destination
7409 3 │ alter table users drop column email;
7410 ╰╴ ─ 1. source
7411 ");
7412 }
7413
7414 #[test]
7415 fn goto_alter_table_add_constraint_using_index() {
7416 assert_snapshot!(goto("
7417create table u(id int);
7418create index my_index on u (id);
7419alter table u add constraint uq unique using index my_in$0dex;
7420"), @r"
7421 ╭▸
7422 3 │ create index my_index on u (id);
7423 │ ──────── 2. destination
7424 4 │ alter table u add constraint uq unique using index my_index;
7425 ╰╴ ─ 1. source
7426 ");
7427 }
7428
7429 #[test]
7430 fn goto_alter_table_owner_to_role() {
7431 assert_snapshot!(goto("
7432create role reader;
7433create table t(id int);
7434alter table t owner to read$0er;
7435"), @r"
7436 ╭▸
7437 2 │ create role reader;
7438 │ ────── 2. destination
7439 3 │ create table t(id int);
7440 4 │ alter table t owner to reader;
7441 ╰╴ ─ 1. source
7442 ");
7443 }
7444
7445 #[test]
7446 fn goto_alter_table_set_tablespace() {
7447 assert_snapshot!(goto("
7448create tablespace ts location '/tmp/ts';
7449create table t(id int);
7450alter table t set tablespace t$0s;
7451"), @r"
7452 ╭▸
7453 2 │ create tablespace ts location '/tmp/ts';
7454 │ ── 2. destination
7455 3 │ create table t(id int);
7456 4 │ alter table t set tablespace ts;
7457 ╰╴ ─ 1. source
7458 ");
7459 }
7460
7461 #[test]
7462 fn goto_alter_table_set_schema() {
7463 assert_snapshot!(goto("
7464create schema foo;
7465create table t(id int);
7466alter table t set schema fo$0o;
7467"), @r"
7468 ╭▸
7469 2 │ create schema foo;
7470 │ ─── 2. destination
7471 3 │ create table t(id int);
7472 4 │ alter table t set schema foo;
7473 ╰╴ ─ 1. source
7474 ");
7475 }
7476
7477 #[test]
7478 fn goto_alter_table_attach_partition() {
7479 assert_snapshot!(goto("
7480create table parent (id int) partition by range (id);
7481create table child (id int);
7482alter table parent attach partition ch$0ild for values from (1) to (10);
7483"), @r"
7484 ╭▸
7485 3 │ create table child (id int);
7486 │ ───── 2. destination
7487 4 │ alter table parent attach partition child for values from (1) to (10);
7488 ╰╴ ─ 1. source
7489 ");
7490 }
7491
7492 #[test]
7493 fn goto_alter_table_detach_partition() {
7494 assert_snapshot!(goto("
7495create table parent (id int) partition by range (id);
7496create table child partition of parent for values from (1) to (10);
7497alter table parent detach partition ch$0ild;
7498"), @r"
7499 ╭▸
7500 3 │ create table child partition of parent for values from (1) to (10);
7501 │ ───── 2. destination
7502 4 │ alter table parent detach partition child;
7503 ╰╴ ─ 1. source
7504 ");
7505 }
7506
7507 #[test]
7508 fn goto_comment_on_table() {
7509 assert_snapshot!(goto("
7510create table t(id int);
7511comment on table t$0 is '';
7512"), @r"
7513 ╭▸
7514 2 │ create table t(id int);
7515 │ ─ 2. destination
7516 3 │ comment on table t is '';
7517 ╰╴ ─ 1. source
7518 ");
7519 }
7520
7521 #[test]
7522 fn goto_comment_on_column() {
7523 assert_snapshot!(goto("
7524create table t(id int);
7525comment on column t.id$0 is '';
7526"), @r"
7527 ╭▸
7528 2 │ create table t(id int);
7529 │ ── 2. destination
7530 3 │ comment on column t.id is '';
7531 ╰╴ ─ 1. source
7532 ");
7533 }
7534
7535 #[test]
7536 fn goto_refresh_materialized_view() {
7537 assert_snapshot!(goto("
7538create materialized view mv as select 1;
7539refresh materialized view mv$0;
7540"), @r"
7541 ╭▸
7542 2 │ create materialized view mv as select 1;
7543 │ ── 2. destination
7544 3 │ refresh materialized view mv;
7545 ╰╴ ─ 1. source
7546 ");
7547 }
7548
7549 #[test]
7550 fn goto_refresh_materialized_view_concurrently() {
7551 assert_snapshot!(goto("
7552create materialized view mv as select 1;
7553refresh materialized view concurrently mv$0;
7554"), @r"
7555 ╭▸
7556 2 │ create materialized view mv as select 1;
7557 │ ── 2. destination
7558 3 │ refresh materialized view concurrently mv;
7559 ╰╴ ─ 1. source
7560 ");
7561 }
7562
7563 #[test]
7564 fn goto_reindex_table() {
7565 assert_snapshot!(goto("
7566create table users(id int);
7567reindex table users$0;
7568"), @r"
7569 ╭▸
7570 2 │ create table users(id int);
7571 │ ───── 2. destination
7572 3 │ reindex table users;
7573 ╰╴ ─ 1. source
7574 ");
7575 }
7576
7577 #[test]
7578 fn goto_reindex_index() {
7579 assert_snapshot!(goto("
7580create table t(c int);
7581create index idx on t(c);
7582reindex index idx$0;
7583"), @r"
7584 ╭▸
7585 3 │ create index idx on t(c);
7586 │ ─── 2. destination
7587 4 │ reindex index idx;
7588 ╰╴ ─ 1. source
7589 ");
7590 }
7591
7592 #[test]
7593 fn goto_select_exists_column() {
7594 assert_snapshot!(goto("
7595select exists$0 from (
7596 select exists(select 1)
7597);
7598"), @r"
7599 ╭▸
7600 2 │ select exists from (
7601 │ ─ 1. source
7602 3 │ select exists(select 1)
7603 ╰╴ ──────────────── 2. destination
7604 ");
7605 }
7606
7607 #[test]
7608 fn goto_reindex_schema() {
7609 assert_snapshot!(goto("
7610create schema app;
7611reindex schema app$0;
7612"), @r"
7613 ╭▸
7614 2 │ create schema app;
7615 │ ─── 2. destination
7616 3 │ reindex schema app;
7617 ╰╴ ─ 1. source
7618 ");
7619 }
7620
7621 #[test]
7622 fn goto_reindex_database() {
7623 assert_snapshot!(goto("
7624create database appdb;
7625reindex database appdb$0;
7626"), @r"
7627 ╭▸
7628 2 │ create database appdb;
7629 │ ───── 2. destination
7630 3 │ reindex database appdb;
7631 ╰╴ ─ 1. source
7632 ");
7633 }
7634
7635 #[test]
7636 fn goto_reindex_system() {
7637 assert_snapshot!(goto("
7638create database systemdb;
7639reindex system systemdb$0;
7640"), @r"
7641 ╭▸
7642 2 │ create database systemdb;
7643 │ ──────── 2. destination
7644 3 │ reindex system systemdb;
7645 ╰╴ ─ 1. source
7646 ");
7647 }
7648
7649 #[test]
7650 fn goto_merge_returning_aliased_column() {
7651 assert_snapshot!(goto(
7652 "
7653create table t(a int, b int);
7654with u(x, y) as (
7655 select 1, 2
7656),
7657merged as (
7658 merge into t
7659 using u
7660 on t.a = u.x
7661 when matched then
7662 do nothing
7663 when not matched then
7664 do nothing
7665 returning a as x, b as y
7666)
7667select x$0 from merged;
7668",
7669 ), @r"
7670 ╭▸
7671 14 │ returning a as x, b as y
7672 │ ─ 2. destination
7673 15 │ )
7674 16 │ select x from merged;
7675 ╰╴ ─ 1. source
7676 ");
7677 }
7678
7679 #[test]
7680 fn goto_cte_update_returning_column() {
7681 assert_snapshot!(goto("
7682create table t(a int, b int);
7683with updated(c) as (
7684 update t set a = 10
7685 returning a, b
7686)
7687select c, b$0 from updated;"
7688 ), @r"
7689 ╭▸
7690 5 │ returning a, b
7691 │ ─ 2. destination
7692 6 │ )
7693 7 │ select c, b from updated;
7694 ╰╴ ─ 1. source
7695 ");
7696 }
7697
7698 #[test]
7699 fn goto_update_returning_column_to_table_def() {
7700 assert_snapshot!(goto("
7701create table t(a int, b int);
7702with updated(c) as (
7703 update t set a = 10
7704 returning a, b$0
7705)
7706select c, b from updated;"
7707 ), @r"
7708 ╭▸
7709 2 │ create table t(a int, b int);
7710 │ ─ 2. destination
7711 ‡
7712 5 │ returning a, b
7713 ╰╴ ─ 1. source
7714 ");
7715 }
7716
7717 #[test]
7718 fn goto_insert_returning_column_to_table_def() {
7719 assert_snapshot!(goto("
7720create table t(a int, b int);
7721with inserted as (
7722 insert into t values (1, 2)
7723 returning a$0, b
7724)
7725select a, b from inserted;"
7726 ), @r"
7727 ╭▸
7728 2 │ create table t(a int, b int);
7729 │ ─ 2. destination
7730 ‡
7731 5 │ returning a, b
7732 ╰╴ ─ 1. source
7733 ");
7734 }
7735
7736 #[test]
7737 fn goto_delete_returning_column_to_table_def() {
7738 assert_snapshot!(goto("
7739create table t(a int, b int);
7740with deleted as (
7741 delete from t
7742 returning a, b$0
7743)
7744select a, b from deleted;"
7745 ), @r"
7746 ╭▸
7747 2 │ create table t(a int, b int);
7748 │ ─ 2. destination
7749 ‡
7750 5 │ returning a, b
7751 ╰╴ ─ 1. source
7752 ");
7753 }
7754
7755 #[test]
7756 fn goto_update_returning_qualified_star_table() {
7757 assert_snapshot!(goto("
7758create table t(a int, b int);
7759update t set a = 10
7760returning t$0.*;"
7761 ), @r"
7762 ╭▸
7763 2 │ create table t(a int, b int);
7764 │ ─ 2. destination
7765 3 │ update t set a = 10
7766 4 │ returning t.*;
7767 ╰╴ ─ 1. source
7768 ");
7769 }
7770
7771 #[test]
7772 fn goto_insert_returning_qualified_star_table() {
7773 assert_snapshot!(goto("
7774create table t(a int, b int);
7775insert into t values (1, 2)
7776returning t$0.*;"
7777 ), @r"
7778 ╭▸
7779 2 │ create table t(a int, b int);
7780 │ ─ 2. destination
7781 3 │ insert into t values (1, 2)
7782 4 │ returning t.*;
7783 ╰╴ ─ 1. source
7784 ");
7785 }
7786
7787 #[test]
7788 fn goto_delete_returning_qualified_star_table() {
7789 assert_snapshot!(goto("
7790create table t(a int, b int);
7791delete from t
7792returning t$0.*;"
7793 ), @r"
7794 ╭▸
7795 2 │ create table t(a int, b int);
7796 │ ─ 2. destination
7797 3 │ delete from t
7798 4 │ returning t.*;
7799 ╰╴ ─ 1. source
7800 ");
7801 }
7802
7803 #[test]
7804 fn goto_update_alias_in_set_clause() {
7805 assert_snapshot!(goto("
7806create table t(a int, b int);
7807update t as f set f$0.a = 10;"
7808 ), @r"
7809 ╭▸
7810 3 │ update t as f set f.a = 10;
7811 │ ┬ ─ 1. source
7812 │ │
7813 ╰╴ 2. destination
7814 ");
7815 }
7816
7817 #[test]
7818 fn goto_update_alias_in_where_clause() {
7819 assert_snapshot!(goto("
7820create table t(a int, b int);
7821update t as f set a = 10 where f$0.b = 5;"
7822 ), @r"
7823 ╭▸
7824 3 │ update t as f set a = 10 where f.b = 5;
7825 ╰╴ ─ 2. destination ─ 1. source
7826 ");
7827 }
7828
7829 #[test]
7830 fn goto_update_alias_in_from_clause() {
7831 assert_snapshot!(goto("
7832create table t(a int, b int);
7833create table u(c int);
7834update t as f set a = 10 from u where f$0.b = u.c;"
7835 ), @r"
7836 ╭▸
7837 4 │ update t as f set a = 10 from u where f.b = u.c;
7838 ╰╴ ─ 2. destination ─ 1. source
7839 ");
7840 }
7841
7842 #[test]
7843 fn goto_insert_alias_in_on_conflict() {
7844 assert_snapshot!(goto("
7845create table t(a int primary key, b int);
7846insert into t as f values (1, 2) on conflict (f$0.a) do nothing;"
7847 ), @r"
7848 ╭▸
7849 3 │ insert into t as f values (1, 2) on conflict (f.a) do nothing;
7850 ╰╴ ─ 2. destination ─ 1. source
7851 ");
7852 }
7853
7854 #[test]
7855 fn goto_insert_alias_in_returning() {
7856 assert_snapshot!(goto("
7857create table t(a int, b int);
7858insert into t as f values (1, 2) returning f$0.a;"
7859 ), @r"
7860 ╭▸
7861 3 │ insert into t as f values (1, 2) returning f.a;
7862 ╰╴ ─ 2. destination ─ 1. source
7863 ");
7864 }
7865
7866 #[test]
7867 fn goto_insert_alias_returning_column() {
7868 assert_snapshot!(goto("
7869create table t(a int, b int);
7870insert into t as f values (1, 2) returning f.a$0;"
7871 ), @r"
7872 ╭▸
7873 2 │ create table t(a int, b int);
7874 │ ─ 2. destination
7875 3 │ insert into t as f values (1, 2) returning f.a;
7876 ╰╴ ─ 1. source
7877 ");
7878 }
7879
7880 #[test]
7881 fn goto_insert_on_conflict_target_column() {
7882 assert_snapshot!(goto("
7883create table t(c text);
7884insert into t values ('c') on conflict (c$0) do nothing;"
7885 ), @r"
7886 ╭▸
7887 2 │ create table t(c text);
7888 │ ─ 2. destination
7889 3 │ insert into t values ('c') on conflict (c) do nothing;
7890 ╰╴ ─ 1. source
7891 ");
7892 }
7893
7894 #[test]
7895 fn goto_insert_on_conflict_set_column() {
7896 assert_snapshot!(goto("
7897create table t(c text, d text);
7898insert into t values ('c', 'd') on conflict (c) do update set c$0 = excluded.c;"
7899 ), @r"
7900 ╭▸
7901 2 │ create table t(c text, d text);
7902 │ ─ 2. destination
7903 3 │ insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c;
7904 ╰╴ ─ 1. source
7905 ");
7906 }
7907
7908 #[test]
7909 fn goto_insert_on_conflict_excluded_column() {
7910 assert_snapshot!(goto("
7911create table t(c text, d text);
7912insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c$0;"
7913 ), @r"
7914 ╭▸
7915 2 │ create table t(c text, d text);
7916 │ ─ 2. destination
7917 3 │ insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c;
7918 ╰╴ ─ 1. source
7919 ");
7920 }
7921
7922 #[test]
7923 fn goto_insert_on_conflict_qualified_function() {
7924 assert_snapshot!(goto("
7925create function foo.lower(text) returns text
7926 language internal;
7927create table t(c text);
7928insert into t values ('c')
7929 on conflict (foo.lower$0(c))
7930 do nothing;"
7931 ), @r"
7932 ╭▸
7933 2 │ create function foo.lower(text) returns text
7934 │ ───── 2. destination
7935 ‡
7936 6 │ on conflict (foo.lower(c))
7937 ╰╴ ─ 1. source
7938 ");
7939 }
7940
7941 #[test]
7942 fn goto_delete_from_alias() {
7943 assert_snapshot!(goto("
7944create table t(a int, b int);
7945delete from t as f where f$0.a = 10;"
7946 ), @r"
7947 ╭▸
7948 3 │ delete from t as f where f.a = 10;
7949 │ ┬ ─ 1. source
7950 │ │
7951 ╰╴ 2. destination
7952 ");
7953 }
7954
7955 #[test]
7956 fn goto_delete_from_alias_column() {
7957 assert_snapshot!(goto("
7958create table t(a int, b int);
7959delete from t as f where f.a$0 = 10;"
7960 ), @r"
7961 ╭▸
7962 2 │ create table t(a int, b int);
7963 │ ─ 2. destination
7964 3 │ delete from t as f where f.a = 10;
7965 ╰╴ ─ 1. source
7966 ");
7967 }
7968
7969 #[test]
7970 fn goto_delete_from_alias_returning() {
7971 assert_snapshot!(goto("
7972create table t(a int, b int);
7973delete from t as f returning f$0.a"
7974 ), @r"
7975 ╭▸
7976 3 │ delete from t as f returning f.a
7977 │ ┬ ─ 1. source
7978 │ │
7979 ╰╴ 2. destination
7980 ");
7981
7982 assert_snapshot!(goto("
7983create table t(a int, b int);
7984delete from t as f returning f.a$0"
7985 ), @r"
7986 ╭▸
7987 2 │ create table t(a int, b int);
7988 │ ─ 2. destination
7989 3 │ delete from t as f returning f.a
7990 ╰╴ ─ 1. source
7991 ");
7992 }
7993
7994 #[test]
7995 fn goto_merge_alias_on_table() {
7996 assert_snapshot!(goto("
7997create table t(a int, b int);
7998create table u(a int, b int);
7999merge into t as f
8000 using u on u.a = f$0.a
8001 when matched then do nothing;
8002"
8003
8004 ), @r"
8005 ╭▸
8006 4 │ merge into t as f
8007 │ ─ 2. destination
8008 5 │ using u on u.a = f.a
8009 ╰╴ ─ 1. source
8010 ");
8011 }
8012
8013 #[test]
8014 fn goto_merge_alias_on_column() {
8015 assert_snapshot!(goto("
8016create table t(a int, b int);
8017create table u(a int, b int);
8018merge into t as f
8019 using u on u.a = f.a$0
8020 when matched then do nothing;
8021"
8022
8023 ), @r"
8024 ╭▸
8025 2 │ create table t(a int, b int);
8026 │ ─ 2. destination
8027 ‡
8028 5 │ using u on u.a = f.a
8029 ╰╴ ─ 1. source
8030 ");
8031 }
8032
8033 #[test]
8034 fn goto_merge_alias_returning() {
8035 assert_snapshot!(goto("
8036create table t(a int, b int);
8037create table u(a int, b int);
8038merge into t as f
8039 using u on u.a = f.a
8040 when matched then do nothing
8041 returning f$0.a;
8042"
8043
8044 ), @r"
8045 ╭▸
8046 4 │ merge into t as f
8047 │ ─ 2. destination
8048 ‡
8049 7 │ returning f.a;
8050 ╰╴ ─ 1. source
8051 ");
8052
8053 assert_snapshot!(goto("
8054create table t(a int, b int);
8055create table u(a int, b int);
8056merge into t as f
8057 using u on u.a = f.a
8058 when matched then do nothing
8059 returning f.a$0;
8060"
8061 ), @r"
8062 ╭▸
8063 2 │ create table t(a int, b int);
8064 │ ─ 2. destination
8065 ‡
8066 7 │ returning f.a;
8067 ╰╴ ─ 1. source
8068 ");
8069 }
8070
8071 #[test]
8072 fn goto_merge_using_table_in_when_clause() {
8073 assert_snapshot!(goto("
8074create table t(a int, b int);
8075create table u(a int, b int);
8076merge into t
8077 using u on true
8078 when matched and u$0.a = t.a
8079 then do nothing;
8080"
8081 ), @r"
8082 ╭▸
8083 3 │ create table u(a int, b int);
8084 │ ─ 2. destination
8085 ‡
8086 6 │ when matched and u.a = t.a
8087 ╰╴ ─ 1. source
8088 ");
8089 }
8090
8091 #[test]
8092 fn goto_merge_using_table_column_in_when_clause() {
8093 assert_snapshot!(goto("
8094create table t(a int, b int);
8095create table u(a int, b int);
8096merge into t
8097 using u on true
8098 when matched and u.a$0 = t.a
8099 then do nothing;
8100"
8101 ), @r"
8102 ╭▸
8103 3 │ create table u(a int, b int);
8104 │ ─ 2. destination
8105 ‡
8106 6 │ when matched and u.a = t.a
8107 ╰╴ ─ 1. source
8108 ");
8109 }
8110
8111 #[test]
8112 fn goto_merge_unqualified_column_target_table() {
8113 assert_snapshot!(goto("
8114create table x(a int, b int);
8115create table y(c int, d int);
8116merge into x
8117 using y
8118 on true
8119 when matched and a$0 = c
8120 then do nothing;
8121"
8122 ), @r"
8123 ╭▸
8124 2 │ create table x(a int, b int);
8125 │ ─ 2. destination
8126 ‡
8127 7 │ when matched and a = c
8128 ╰╴ ─ 1. source
8129 ");
8130 }
8131
8132 #[test]
8133 fn goto_merge_unqualified_column_source_table() {
8134 assert_snapshot!(goto("
8135create table x(a int, b int);
8136create table y(c int, d int);
8137merge into x
8138 using y
8139 on true
8140 when matched and a = c$0
8141 then do nothing;
8142"
8143 ), @r"
8144 ╭▸
8145 3 │ create table y(c int, d int);
8146 │ ─ 2. destination
8147 ‡
8148 7 │ when matched and a = c
8149 ╰╴ ─ 1. source
8150 ");
8151 }
8152
8153 #[test]
8154 fn goto_merge_into_table() {
8155 assert_snapshot!(goto("
8156create table x(a int, b int);
8157create table y(c int, d int);
8158merge into x$0
8159 using y
8160 on true
8161 when matched and a = c
8162 then do nothing;
8163"
8164 ), @r"
8165 ╭▸
8166 2 │ create table x(a int, b int);
8167 │ ─ 2. destination
8168 3 │ create table y(c int, d int);
8169 4 │ merge into x
8170 ╰╴ ─ 1. source
8171 ");
8172 }
8173
8174 #[test]
8175 fn goto_merge_using_clause_table() {
8176 assert_snapshot!(goto("
8177create table x(a int, b int);
8178create table y(c int, d int);
8179merge into x
8180 using y$0
8181 on true
8182 when matched and a = c
8183 then do nothing;
8184"
8185 ), @r"
8186 ╭▸
8187 3 │ create table y(c int, d int);
8188 │ ─ 2. destination
8189 4 │ merge into x
8190 5 │ using y
8191 ╰╴ ─ 1. source
8192 ");
8193 }
8194
8195 #[test]
8196 fn goto_merge_using_clause_alias() {
8197 assert_snapshot!(goto("
8198create table x(a int, b int);
8199create table y(c int, d int);
8200merge into x as g
8201 using y as k
8202 on true
8203 when matched and a = k.c$0
8204 then do nothing;
8205"
8206 ), @r"
8207 ╭▸
8208 3 │ create table y(c int, d int);
8209 │ ─ 2. destination
8210 ‡
8211 7 │ when matched and a = k.c
8212 ╰╴ ─ 1. source
8213 ");
8214 }
8215
8216 #[test]
8217 fn goto_merge_on_clause_unqualified_source_column() {
8218 assert_snapshot!(goto("
8219create table x(a int, b int);
8220create table y(c int, d int);
8221merge into x as g
8222 using y as k
8223 on g.a = c$0 and a = c
8224 when matched and g.a = k.c
8225 then do nothing;
8226"
8227 ), @r"
8228 ╭▸
8229 3 │ create table y(c int, d int);
8230 │ ─ 2. destination
8231 ‡
8232 6 │ on g.a = c and a = c
8233 ╰╴ ─ 1. source
8234 ");
8235 }
8236
8237 #[test]
8238 fn goto_merge_returning_old_table() {
8239 assert_snapshot!(goto("
8240create table x(a int, b int);
8241create table y(c int, d int);
8242merge into x as g
8243 using y as k
8244 on g.a = c and a = k.c
8245 when matched and g.a = k.c
8246 then do nothing
8247 returning old$0.a, new.a;
8248"
8249 ), @r"
8250 ╭▸
8251 2 │ create table x(a int, b int);
8252 │ ─ 2. destination
8253 ‡
8254 9 │ returning old.a, new.a;
8255 ╰╴ ─ 1. source
8256 ");
8257 }
8258
8259 #[test]
8260 fn goto_merge_returning_old_column() {
8261 assert_snapshot!(goto("
8262create table x(a int, b int);
8263create table y(c int, d int);
8264merge into x as g
8265 using y as k
8266 on g.a = c and a = k.c
8267 when matched and g.a = k.c
8268 then do nothing
8269 returning old.a$0, new.a;
8270"
8271 ), @r"
8272 ╭▸
8273 2 │ create table x(a int, b int);
8274 │ ─ 2. destination
8275 ‡
8276 9 │ returning old.a, new.a;
8277 ╰╴ ─ 1. source
8278 ");
8279 }
8280
8281 #[test]
8282 fn goto_merge_returning_new_table() {
8283 assert_snapshot!(goto("
8284create table x(a int, b int);
8285create table y(c int, d int);
8286merge into x as g
8287 using y as k
8288 on g.a = c and a = k.c
8289 when matched and g.a = k.c
8290 then do nothing
8291 returning old.a, new$0.a;
8292"
8293 ), @r"
8294 ╭▸
8295 2 │ create table x(a int, b int);
8296 │ ─ 2. destination
8297 ‡
8298 9 │ returning old.a, new.a;
8299 ╰╴ ─ 1. source
8300 ");
8301 }
8302
8303 #[test]
8304 fn goto_merge_returning_new_column() {
8305 assert_snapshot!(goto("
8306create table x(a int, b int);
8307create table y(c int, d int);
8308merge into x as g
8309 using y as k
8310 on g.a = c and a = k.c
8311 when matched and g.a = k.c
8312 then do nothing
8313 returning old.a, new.a$0;
8314"
8315 ), @r"
8316 ╭▸
8317 2 │ create table x(a int, b int);
8318 │ ─ 2. destination
8319 ‡
8320 9 │ returning old.a, new.a;
8321 ╰╴ ─ 1. source
8322 ");
8323 }
8324
8325 #[test]
8326 fn goto_merge_with_tables_named_old_new_old_table() {
8327 assert_snapshot!(goto("
8328create table old(a int, b int);
8329create table new(c int, d int);
8330merge into old
8331 using new
8332 on true
8333 when matched
8334 then do nothing
8335 returning old$0.a, new.d;
8336"
8337 ), @r"
8338 ╭▸
8339 2 │ create table old(a int, b int);
8340 │ ─── 2. destination
8341 ‡
8342 9 │ returning old.a, new.d;
8343 ╰╴ ─ 1. source
8344 ");
8345 }
8346
8347 #[test]
8348 fn goto_merge_with_tables_named_old_new_old_column() {
8349 assert_snapshot!(goto("
8350create table old(a int, b int);
8351create table new(c int, d int);
8352merge into old
8353 using new
8354 on true
8355 when matched
8356 then do nothing
8357 returning old.a$0, new.d;
8358"
8359 ), @r"
8360 ╭▸
8361 2 │ create table old(a int, b int);
8362 │ ─ 2. destination
8363 ‡
8364 9 │ returning old.a, new.d;
8365 ╰╴ ─ 1. source
8366 ");
8367 }
8368
8369 #[test]
8370 fn goto_merge_with_tables_named_old_new_new_table() {
8371 assert_snapshot!(goto("
8372create table old(a int, b int);
8373create table new(c int, d int);
8374merge into old
8375 using new
8376 on true
8377 when matched
8378 then do nothing
8379 returning old.a, new$0.d;
8380"
8381 ), @r"
8382 ╭▸
8383 3 │ create table new(c int, d int);
8384 │ ─── 2. destination
8385 ‡
8386 9 │ returning old.a, new.d;
8387 ╰╴ ─ 1. source
8388 ");
8389 }
8390
8391 #[test]
8392 fn goto_merge_with_tables_named_old_new_new_column() {
8393 assert_snapshot!(goto("
8394create table old(a int, b int);
8395create table new(c int, d int);
8396merge into old
8397 using new
8398 on true
8399 when matched
8400 then do nothing
8401 returning old.a, new.d$0;
8402"
8403 ), @r"
8404 ╭▸
8405 3 │ create table new(c int, d int);
8406 │ ─ 2. destination
8407 ‡
8408 9 │ returning old.a, new.d;
8409 ╰╴ ─ 1. source
8410 ");
8411 }
8412
8413 #[test]
8414 fn goto_merge_returning_with_aliases_before_table() {
8415 assert_snapshot!(goto("
8416create table x(a int, b int);
8417create table y(c int, d int);
8418merge into x
8419 using y on true
8420 when matched then do nothing
8421 returning
8422 with (old as before, new as after)
8423 before$0.a, after.a;
8424"
8425 ), @r"
8426 ╭▸
8427 8 │ with (old as before, new as after)
8428 │ ────── 2. destination
8429 9 │ before.a, after.a;
8430 ╰╴ ─ 1. source
8431 ");
8432 }
8433
8434 #[test]
8435 fn goto_merge_returning_with_aliases_before_column() {
8436 assert_snapshot!(goto("
8437create table x(a int, b int);
8438create table y(c int, d int);
8439merge into x
8440 using y on true
8441 when matched then do nothing
8442 returning
8443 with (old as before, new as after)
8444 before.a$0, after.a;
8445"
8446 ), @r"
8447 ╭▸
8448 2 │ create table x(a int, b int);
8449 │ ─ 2. destination
8450 ‡
8451 9 │ before.a, after.a;
8452 ╰╴ ─ 1. source
8453 ");
8454 }
8455
8456 #[test]
8457 fn goto_merge_returning_with_aliases_after_table() {
8458 assert_snapshot!(goto("
8459create table x(a int, b int);
8460create table y(c int, d int);
8461merge into x
8462 using y on true
8463 when matched then do nothing
8464 returning
8465 with (old as before, new as after)
8466 before.a, after$0.a;
8467"
8468 ), @r"
8469 ╭▸
8470 8 │ with (old as before, new as after)
8471 │ ───── 2. destination
8472 9 │ before.a, after.a;
8473 ╰╴ ─ 1. source
8474 ");
8475 }
8476
8477 #[test]
8478 fn goto_merge_returning_with_aliases_after_column() {
8479 assert_snapshot!(goto("
8480create table x(a int, b int);
8481create table y(c int, d int);
8482merge into x
8483 using y on true
8484 when matched then do nothing
8485 returning
8486 with (old as before, new as after)
8487 before.a, after.a$0;
8488"
8489 ), @r"
8490 ╭▸
8491 2 │ create table x(a int, b int);
8492 │ ─ 2. destination
8493 ‡
8494 9 │ before.a, after.a;
8495 ╰╴ ─ 1. source
8496 ");
8497 }
8498
8499 #[test]
8500 fn goto_merge_when_not_matched_insert_values_qualified_column() {
8501 assert_snapshot!(goto("
8502create table inventory (
8503 product_id int,
8504 quantity int,
8505 updated_at timestamp
8506);
8507create table orders (
8508 id int,
8509 product_id int,
8510 qty int
8511);
8512merge into inventory as t
8513using orders as o
8514 on t.product_id = o.product_id
8515when matched then
8516 do nothing
8517when not matched then
8518 insert values (o$0.product_id, o.qty, now());
8519"
8520 ), @r"
8521 ╭▸
8522 13 │ using orders as o
8523 │ ─ 2. destination
8524 ‡
8525 18 │ insert values (o.product_id, o.qty, now());
8526 ╰╴ ─ 1. source
8527 ");
8528 }
8529
8530 #[test]
8531 fn goto_merge_when_not_matched_insert_values_qualified_column_field() {
8532 assert_snapshot!(goto("
8533create table inventory (
8534 product_id int,
8535 quantity int,
8536 updated_at timestamp
8537);
8538create table orders (
8539 id int,
8540 product_id int,
8541 qty int
8542);
8543merge into inventory as t
8544using orders as o
8545 on t.product_id = o.product_id
8546when matched then
8547 do nothing
8548when not matched then
8549 insert values (o.product_id$0, o.qty, now());
8550"
8551 ), @r"
8552 ╭▸
8553 9 │ product_id int,
8554 │ ────────── 2. destination
8555 ‡
8556 18 │ insert values (o.product_id, o.qty, now());
8557 ╰╴ ─ 1. source
8558 ");
8559 }
8560
8561 #[test]
8562 fn goto_merge_when_not_matched_insert_values_unqualified_column() {
8563 assert_snapshot!(goto("
8564create table inventory (
8565 product_id int,
8566 quantity int
8567);
8568create table orders (
8569 product_id int,
8570 qty int
8571);
8572merge into inventory as t
8573using orders as o
8574 on t.product_id = o.product_id
8575when not matched then
8576 insert values (product_id$0, qty);
8577"
8578 ), @r"
8579 ╭▸
8580 7 │ product_id int,
8581 │ ────────── 2. destination
8582 ‡
8583 14 │ insert values (product_id, qty);
8584 ╰╴ ─ 1. source
8585 ");
8586 }
8587
8588 #[test]
8589 fn goto_insert_returning_old_table() {
8590 assert_snapshot!(goto("
8591create table t(a int, b int);
8592insert into t values (1, 2), (3, 4)
8593returning old$0.a, new.b;
8594"
8595 ), @r"
8596 ╭▸
8597 2 │ create table t(a int, b int);
8598 │ ─ 2. destination
8599 3 │ insert into t values (1, 2), (3, 4)
8600 4 │ returning old.a, new.b;
8601 ╰╴ ─ 1. source
8602 ");
8603 }
8604
8605 #[test]
8606 fn goto_insert_returning_old_column() {
8607 assert_snapshot!(goto("
8608create table t(a int, b int);
8609insert into t values (1, 2), (3, 4)
8610returning old.a$0, new.b;
8611"
8612 ), @r"
8613 ╭▸
8614 2 │ create table t(a int, b int);
8615 │ ─ 2. destination
8616 3 │ insert into t values (1, 2), (3, 4)
8617 4 │ returning old.a, new.b;
8618 ╰╴ ─ 1. source
8619 ");
8620 }
8621
8622 #[test]
8623 fn goto_insert_returning_new_table() {
8624 assert_snapshot!(goto("
8625create table t(a int, b int);
8626insert into t values (1, 2), (3, 4)
8627returning old.a, new$0.b;
8628"
8629 ), @r"
8630 ╭▸
8631 2 │ create table t(a int, b int);
8632 │ ─ 2. destination
8633 3 │ insert into t values (1, 2), (3, 4)
8634 4 │ returning old.a, new.b;
8635 ╰╴ ─ 1. source
8636 ");
8637 }
8638
8639 #[test]
8640 fn goto_insert_returning_new_column() {
8641 assert_snapshot!(goto("
8642create table t(a int, b int);
8643insert into t values (1, 2), (3, 4)
8644returning old.a, new.b$0;
8645"
8646 ), @r"
8647 ╭▸
8648 2 │ create table t(a int, b int);
8649 │ ─ 2. destination
8650 3 │ insert into t values (1, 2), (3, 4)
8651 4 │ returning old.a, new.b;
8652 ╰╴ ─ 1. source
8653 ");
8654 }
8655
8656 #[test]
8657 fn goto_update_returning_old_table() {
8658 assert_snapshot!(goto("
8659create table t(a int, b int);
8660update t set a = 42
8661returning old$0.a, new.b;
8662"
8663 ), @r"
8664 ╭▸
8665 2 │ create table t(a int, b int);
8666 │ ─ 2. destination
8667 3 │ update t set a = 42
8668 4 │ returning old.a, new.b;
8669 ╰╴ ─ 1. source
8670 ");
8671 }
8672
8673 #[test]
8674 fn goto_update_returning_old_column() {
8675 assert_snapshot!(goto("
8676create table t(a int, b int);
8677update t set a = 42
8678returning old.a$0, new.b;
8679"
8680 ), @r"
8681 ╭▸
8682 2 │ create table t(a int, b int);
8683 │ ─ 2. destination
8684 3 │ update t set a = 42
8685 4 │ returning old.a, new.b;
8686 ╰╴ ─ 1. source
8687 ");
8688 }
8689
8690 #[test]
8691 fn goto_update_returning_new_table() {
8692 assert_snapshot!(goto("
8693create table t(a int, b int);
8694update t set a = 42
8695returning old.a, new$0.b;
8696"
8697 ), @r"
8698 ╭▸
8699 2 │ create table t(a int, b int);
8700 │ ─ 2. destination
8701 3 │ update t set a = 42
8702 4 │ returning old.a, new.b;
8703 ╰╴ ─ 1. source
8704 ");
8705 }
8706
8707 #[test]
8708 fn goto_update_returning_new_column() {
8709 assert_snapshot!(goto("
8710create table t(a int, b int);
8711update t set a = 42
8712returning old.a, new.b$0;
8713"
8714 ), @r"
8715 ╭▸
8716 2 │ create table t(a int, b int);
8717 │ ─ 2. destination
8718 3 │ update t set a = 42
8719 4 │ returning old.a, new.b;
8720 ╰╴ ─ 1. source
8721 ");
8722 }
8723
8724 #[test]
8725 fn goto_delete_returning_old_table() {
8726 assert_snapshot!(goto("
8727create table t(a int, b int);
8728delete from t
8729returning old$0.a, new.b;
8730"
8731 ), @r"
8732 ╭▸
8733 2 │ create table t(a int, b int);
8734 │ ─ 2. destination
8735 3 │ delete from t
8736 4 │ returning old.a, new.b;
8737 ╰╴ ─ 1. source
8738 ");
8739 }
8740
8741 #[test]
8742 fn goto_delete_returning_old_column() {
8743 assert_snapshot!(goto("
8744create table t(a int, b int);
8745delete from t
8746returning old.a$0, new.b;
8747"
8748 ), @r"
8749 ╭▸
8750 2 │ create table t(a int, b int);
8751 │ ─ 2. destination
8752 3 │ delete from t
8753 4 │ returning old.a, new.b;
8754 ╰╴ ─ 1. source
8755 ");
8756 }
8757
8758 #[test]
8759 fn goto_delete_returning_new_table() {
8760 assert_snapshot!(goto("
8761create table t(a int, b int);
8762delete from t
8763returning old.a, new$0.b;
8764"
8765 ), @r"
8766 ╭▸
8767 2 │ create table t(a int, b int);
8768 │ ─ 2. destination
8769 3 │ delete from t
8770 4 │ returning old.a, new.b;
8771 ╰╴ ─ 1. source
8772 ");
8773 }
8774
8775 #[test]
8776 fn goto_delete_returning_new_column() {
8777 assert_snapshot!(goto("
8778create table t(a int, b int);
8779delete from t
8780returning old.a, new.b$0;
8781"
8782 ), @r"
8783 ╭▸
8784 2 │ create table t(a int, b int);
8785 │ ─ 2. destination
8786 3 │ delete from t
8787 4 │ returning old.a, new.b;
8788 ╰╴ ─ 1. source
8789 ");
8790 }
8791
8792 #[test]
8793 fn goto_insert_as_old_alias() {
8794 assert_snapshot!(goto("
8795create table t(a int, b int);
8796insert into t as old values (1, 2)
8797returning old$0.a, new.a;
8798"
8799 ), @r"
8800 ╭▸
8801 3 │ insert into t as old values (1, 2)
8802 │ ─── 2. destination
8803 4 │ returning old.a, new.a;
8804 ╰╴ ─ 1. source
8805 ");
8806 }
8807
8808 #[test]
8809 fn goto_delete_as_old_alias() {
8810 assert_snapshot!(goto("
8811create table t(a int, b int);
8812delete from t as old
8813returning old$0.a, new.a;
8814"
8815 ), @r"
8816 ╭▸
8817 3 │ delete from t as old
8818 │ ─── 2. destination
8819 4 │ returning old.a, new.a;
8820 ╰╴ ─ 1. source
8821 ");
8822 }
8823
8824 #[test]
8825 fn goto_update_as_old_alias() {
8826 assert_snapshot!(goto("
8827create table t(a int, b int);
8828update t as old set a = 42
8829returning old$0.a, new.a;
8830"
8831 ), @r"
8832 ╭▸
8833 3 │ update t as old set a = 42
8834 │ ─── 2. destination
8835 4 │ returning old.a, new.a;
8836 ╰╴ ─ 1. source
8837 ");
8838 }
8839
8840 #[test]
8841 fn goto_merge_returning_cte_column_unqualified() {
8842 assert_snapshot!(goto("
8843create table t(a int, b int);
8844with u(x, y) as (
8845 select 1, 2
8846)
8847merge into t
8848 using u on true
8849when matched then
8850 do nothing
8851when not matched then
8852 do nothing
8853returning x$0, u.y;
8854"
8855 ), @r"
8856 ╭▸
8857 3 │ with u(x, y) as (
8858 │ ─ 2. destination
8859 ‡
8860 12 │ returning x, u.y;
8861 ╰╴ ─ 1. source
8862 ");
8863 }
8864
8865 #[test]
8866 fn goto_merge_returning_cte_column_qualified_table() {
8867 assert_snapshot!(goto("
8868create table t(a int, b int);
8869with u(x, y) as (
8870 select 1, 2
8871)
8872merge into t
8873 using u on true
8874when matched then
8875 do nothing
8876when not matched then
8877 do nothing
8878returning x, u$0.y;
8879"
8880 ), @r"
8881 ╭▸
8882 3 │ with u(x, y) as (
8883 │ ─ 2. destination
8884 ‡
8885 12 │ returning x, u.y;
8886 ╰╴ ─ 1. source
8887 ");
8888 }
8889
8890 #[test]
8891 fn goto_merge_returning_cte_column_qualified_column() {
8892 assert_snapshot!(goto("
8893create table t(a int, b int);
8894with u(x, y) as (
8895 select 1, 2
8896)
8897merge into t
8898 using u on true
8899when matched then
8900 do nothing
8901when not matched then
8902 do nothing
8903returning x, u.y$0;
8904"
8905 ), @r"
8906 ╭▸
8907 3 │ with u(x, y) as (
8908 │ ─ 2. destination
8909 ‡
8910 12 │ returning x, u.y;
8911 ╰╴ ─ 1. source
8912 ");
8913 }
8914
8915 #[test]
8916 fn goto_overlay_with_cte_column() {
8917 assert_snapshot!(goto("
8918with t as (
8919 select '1' a, '2' b, 3 start
8920)
8921select overlay(a placing b$0 from start) from t;
8922 "), @r"
8923 ╭▸
8924 3 │ select '1' a, '2' b, 3 start
8925 │ ─ 2. destination
8926 4 │ )
8927 5 │ select overlay(a placing b from start) from t;
8928 ╰╴ ─ 1. source
8929 ");
8930 }
8931
8932 #[test]
8933 fn goto_overlay_with_cte_column_first_arg() {
8934 assert_snapshot!(goto("
8935with t as (
8936 select '1' a, '2' b, 3 start
8937)
8938select overlay(a$0 placing b from start) from t;
8939 "), @r"
8940 ╭▸
8941 3 │ select '1' a, '2' b, 3 start
8942 │ ─ 2. destination
8943 4 │ )
8944 5 │ select overlay(a placing b from start) from t;
8945 ╰╴ ─ 1. source
8946 ");
8947 }
8948
8949 #[test]
8950 fn goto_overlay_with_cte_column_from_arg() {
8951 assert_snapshot!(goto("
8952with t as (
8953 select '1' a, '2' b, 3 start
8954)
8955select overlay(a placing b from start$0) from t;
8956 "), @r"
8957 ╭▸
8958 3 │ select '1' a, '2' b, 3 start
8959 │ ───── 2. destination
8960 4 │ )
8961 5 │ select overlay(a placing b from start) from t;
8962 ╰╴ ─ 1. source
8963 ");
8964 }
8965
8966 #[test]
8967 fn goto_named_arg_to_param() {
8968 assert_snapshot!(goto("
8969create function foo(bar_param int) returns int as 'select 1' language sql;
8970select foo(bar_param$0 := 5);
8971"), @r"
8972 ╭▸
8973 2 │ create function foo(bar_param int) returns int as 'select 1' language sql;
8974 │ ───────── 2. destination
8975 3 │ select foo(bar_param := 5);
8976 ╰╴ ─ 1. source
8977 ");
8978 }
8979
8980 #[test]
8981 fn goto_named_arg_schema_qualified() {
8982 assert_snapshot!(goto("
8983create schema s;
8984create function s.foo(my_param int) returns int as 'select 1' language sql;
8985select s.foo(my_param$0 := 10);
8986"), @r"
8987 ╭▸
8988 3 │ create function s.foo(my_param int) returns int as 'select 1' language sql;
8989 │ ──────── 2. destination
8990 4 │ select s.foo(my_param := 10);
8991 ╰╴ ─ 1. source
8992 ");
8993 }
8994
8995 #[test]
8996 fn goto_named_arg_multiple_params() {
8997 assert_snapshot!(goto("
8998create function foo(a int, b int, c int) returns int as 'select 1' language sql;
8999select foo(b$0 := 2, a := 1);
9000"), @r"
9001 ╭▸
9002 2 │ create function foo(a int, b int, c int) returns int as 'select 1' language sql;
9003 │ ─ 2. destination
9004 3 │ select foo(b := 2, a := 1);
9005 ╰╴ ─ 1. source
9006 ");
9007 }
9008
9009 #[test]
9010 fn goto_named_arg_procedure() {
9011 assert_snapshot!(goto("
9012create procedure proc(param_x int) as 'select 1' language sql;
9013call proc(param_x$0 := 42);
9014"), @r"
9015 ╭▸
9016 2 │ create procedure proc(param_x int) as 'select 1' language sql;
9017 │ ─────── 2. destination
9018 3 │ call proc(param_x := 42);
9019 ╰╴ ─ 1. source
9020 ");
9021 }
9022
9023 #[test]
9024 fn goto_named_arg_not_found_unnamed_param() {
9025 goto_not_found(
9026 "
9027create function foo(int) returns int as 'select 1' language sql;
9028select foo(bar$0 := 5);
9029",
9030 );
9031 }
9032
9033 #[test]
9034 fn goto_named_arg_not_found_wrong_name() {
9035 goto_not_found(
9036 "
9037create function foo(correct_param int) returns int as 'select 1' language sql;
9038select foo(wrong_param$0 := 5);
9039",
9040 );
9041 }
9042
9043 #[test]
9044 fn goto_operator_function_ref() {
9045 assert_snapshot!(goto("
9046create function pg_catalog.tsvector_concat(tsvector, tsvector) returns tsvector language internal;
9047create operator pg_catalog.|| (leftarg = tsvector, rightarg = tsvector, function = pg_catalog.tsvector_concat$0);
9048"), @r"
9049 ╭▸
9050 2 │ create function pg_catalog.tsvector_concat(tsvector, tsvector) returns tsvector language internal;
9051 │ ─────────────── 2. destination
9052 3 │ create operator pg_catalog.|| (leftarg = tsvector, rightarg = tsvector, function = pg_catalog.tsvector_concat);
9053 ╰╴ ─ 1. source
9054 ");
9055 }
9056
9057 #[test]
9058 fn goto_operator_procedure_ref() {
9059 assert_snapshot!(goto("
9060create function f(int, int) returns int language internal;
9061create operator ||| (leftarg = int, rightarg = int, procedure = f$0);
9062"), @r"
9063 ╭▸
9064 2 │ create function f(int, int) returns int language internal;
9065 │ ─ 2. destination
9066 3 │ create operator ||| (leftarg = int, rightarg = int, procedure = f);
9067 ╰╴ ─ 1. source
9068 ");
9069 }
9070
9071 #[test]
9072 fn goto_cte_window_partition_column_from_create_table_if_not_exists() {
9073 assert_snapshot!(goto("
9074create table t (
9075 id bigint primary key,
9076 group_col text not null,
9077 update_date date not null
9078);
9079
9080with row_number_added as (
9081 select
9082 *,
9083 row_number() over (
9084 partition by group_col$0
9085 order by update_date desc
9086 ) as rn
9087 from t
9088)
9089select * from row_number_added
9090"), @"
9091 ╭▸
9092 4 │ group_col text not null,
9093 │ ───────── 2. destination
9094 ‡
9095 12 │ partition by group_col
9096 ╰╴ ─ 1. source
9097 ");
9098 }
9099
9100 #[test]
9101 fn goto_cte_window_order_column_from_create_table_if_not_exists() {
9102 assert_snapshot!(goto("
9103create table t (
9104 id bigint primary key,
9105 group_col text not null,
9106 update_date date not null
9107);
9108
9109with row_number_added as (
9110 select
9111 *,
9112 row_number() over (
9113 partition by group_col
9114 order by update_date$0 desc
9115 ) as rn
9116 from t
9117)
9118select * from row_number_added
9119"), @"
9120 ╭▸
9121 5 │ update_date date not null
9122 │ ─────────── 2. destination
9123 ‡
9124 13 │ order by update_date desc
9125 ╰╴ ─ 1. source
9126 ");
9127 }
9128
9129 #[test]
9130 fn goto_cte_window_partition_function_call_from_create_table() {
9131 assert_snapshot!(goto("
9132create function length(text) returns int language internal;
9133
9134create table t (
9135 id bigint primary key,
9136 group_col text not null,
9137 update_date date not null
9138);
9139
9140with row_number_added as (
9141 select
9142 *,
9143 row_number() over (
9144 partition by length$0(group_col)
9145 order by update_date$0 desc
9146 ) as rn
9147 from t
9148)
9149select * from row_number_added
9150"), @"
9151 ╭▸
9152 2 │ create function length(text) returns int language internal;
9153 │ ────── 2. destination
9154 ‡
9155 14 │ partition by length(group_col)
9156 ╰╴ ─ 1. source
9157 ");
9158 }
9159
9160 #[test]
9161 fn goto_select_window_def_reuse() {
9162 assert_snapshot!(goto("
9163create table tbl (
9164 id bigint primary key,
9165 group_col text not null,
9166 update_date date not null,
9167 value text
9168);
9169select
9170 id,
9171 group_col,
9172 row_number() over w as rn,
9173 lag(value) over w$0 as prev_value
9174from tbl
9175window w as (
9176 partition by group_col
9177 order by update_date desc
9178);
9179"), @r"
9180 ╭▸
9181 12 │ lag(value) over w as prev_value
9182 │ ─ 1. source
9183 13 │ from tbl
9184 14 │ window w as (
9185 ╰╴ ─ 2. destination
9186 ");
9187 }
9188
9189 #[test]
9190 fn goto_cast_float_with_small_arg() {
9191 assert_snapshot!(goto("
9192create type pg_catalog.float4;
9193select '1'::float$0(8);
9194"), @"
9195 ╭▸
9196 2 │ create type pg_catalog.float4;
9197 │ ────── 2. destination
9198 3 │ select '1'::float(8);
9199 ╰╴ ─ 1. source
9200 ");
9201 }
9202
9203 #[test]
9204 fn goto_cast_float_with_large_arg() {
9205 assert_snapshot!(goto("
9206create type pg_catalog.float8;
9207select '1'::float$0(25);
9208"), @"
9209 ╭▸
9210 2 │ create type pg_catalog.float8;
9211 │ ────── 2. destination
9212 3 │ select '1'::float(25);
9213 ╰╴ ─ 1. source
9214 ");
9215 }
9216
9217 #[test]
9218 fn goto_cast_dec_with_modifier() {
9219 assert_snapshot!(goto("
9220create type pg_catalog.numeric;
9221select '10'::dec$0(10, 2);
9222"), @"
9223 ╭▸
9224 2 │ create type pg_catalog.numeric;
9225 │ ─────── 2. destination
9226 3 │ select '10'::dec(10, 2);
9227 ╰╴ ─ 1. source
9228 ");
9229 }
9230
9231 #[test]
9232 fn goto_cast_dec() {
9233 assert_snapshot!(goto("
9234create type pg_catalog.numeric;
9235select '10'::dec$0;
9236"), @"
9237 ╭▸
9238 2 │ create type pg_catalog.numeric;
9239 │ ─────── 2. destination
9240 3 │ select '10'::dec;
9241 ╰╴ ─ 1. source
9242 ");
9243 }
9244}