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