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