Skip to main content

squawk_ide/
goto_definition.rs

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