Skip to main content

squawk_ide/
goto_definition.rs

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