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