1use crate::db::{list_files, parse};
2use crate::file::InFile;
3use crate::location::{Location, LocationKind};
4use crate::offsets::token_from_offset;
5use crate::resolve;
6use rowan::{TextRange, TextSize};
7use salsa::Database as Db;
8use smallvec::{SmallVec, smallvec};
9use squawk_syntax::{
10 SyntaxKind,
11 ast::{self, AstNode},
12};
13
14pub fn goto_definition(db: &dyn Db, position: InFile<TextSize>) -> SmallVec<[Location; 1]> {
15 let file = position.file_id;
16 let Some(token) = token_from_offset(db, position) else {
17 return smallvec![];
18 };
19 let Some(parent) = token.parent() else {
20 return smallvec![];
21 };
22
23 if (token.kind() == SyntaxKind::WHEN_KW && parent.kind() == SyntaxKind::WHEN_CLAUSE)
25 || (token.kind() == SyntaxKind::ELSE_KW && parent.kind() == SyntaxKind::ELSE_CLAUSE)
26 || (token.kind() == SyntaxKind::END_KW && parent.kind() == SyntaxKind::CASE_EXPR)
27 {
28 for parent in token.parent_ancestors() {
29 if let Some(case_expr) = ast::CaseExpr::cast(parent)
30 && let Some(case_token) = case_expr.case_token()
31 {
32 return smallvec![Location::new(
33 file,
34 case_token.text_range(),
35 LocationKind::CaseExpr
36 )];
37 }
38 }
39 }
40
41 if ast::Commit::can_cast(parent.kind())
43 && let Some(begin_range) = find_preceding_begin(db, position)
44 {
45 return smallvec![Location::new(file, begin_range, LocationKind::CommitBegin)];
46 }
47
48 if ast::Rollback::can_cast(parent.kind())
50 && let Some(begin_range) = find_preceding_begin(db, position)
51 {
52 return smallvec![Location::new(file, begin_range, LocationKind::CommitBegin)];
53 }
54
55 if ast::Begin::can_cast(parent.kind())
57 && let Some(end_range) = find_following_commit_or_rollback(db, position)
58 {
59 return smallvec![Location::new(file, end_range, LocationKind::CommitEnd)];
60 }
61
62 if let Some(name) = ast::Name::cast(parent.clone())
63 && let Some(location) = Location::from_node(file, name.syntax())
64 {
65 return smallvec![location];
66 }
67
68 if let Some(name_ref) = ast::NameRef::cast(parent.clone()) {
69 for definition_file in list_files(db, file) {
70 if let Some(locations) =
71 resolve::resolve_name_ref(db, InFile::new(definition_file, &name_ref))
74 {
75 return locations;
76 }
77 }
78 }
79
80 if let Some(literal) = ast::Literal::cast(parent.clone()) {
81 for definition_file in list_files(db, file) {
82 if let Some(locations) =
83 resolve::resolve_literal(db, InFile::new(definition_file, &literal))
84 {
85 return locations;
86 }
87 }
88 }
89
90 if let Some(custom_op) = ast::CustomOp::cast(parent.clone()) {
91 for definition_file in list_files(db, file) {
92 if let Some(locations) =
93 resolve::resolve_custom_op(db, InFile::new(definition_file, &custom_op))
94 {
95 return locations;
96 }
97 }
98 }
99
100 let type_node = ast::Type::cast(parent.clone()).or_else(|| {
101 if ast::Timezone::can_cast(parent.kind()) {
103 parent.parent().and_then(ast::Type::cast)
104 } else {
105 None
106 }
107 });
108 if let Some(ty) = type_node {
109 for definition_file in list_files(db, file) {
110 if let Some(ptr) =
111 resolve::resolve_type_ptr_from_type(db, InFile::new(definition_file, &ty))
114 {
115 return smallvec![Location {
116 file: definition_file,
117 range: ptr.text_range(),
118 kind: LocationKind::Type,
119 }];
120 }
121 }
122 }
123
124 smallvec![]
125}
126
127fn find_preceding_begin(db: &dyn Db, position: InFile<TextSize>) -> Option<TextRange> {
128 let mut last_begin: Option<TextRange> = None;
129 for stmt in parse(db, position.file_id).tree().stmts() {
130 if let ast::Stmt::Begin(begin) = stmt {
131 let range = begin.syntax().text_range();
132 if range.end() <= position.value {
133 last_begin = Some(range);
134 }
135 }
136 }
137 last_begin
138}
139
140fn find_following_commit_or_rollback(db: &dyn Db, position: InFile<TextSize>) -> Option<TextRange> {
141 for stmt in parse(db, position.file_id).tree().stmts() {
142 let range = match &stmt {
143 ast::Stmt::Commit(commit) => commit.syntax().text_range(),
144 ast::Stmt::Rollback(rollback) => rollback.syntax().text_range(),
145 _ => continue,
146 };
147 if range.start() >= position.value {
148 return Some(range);
149 }
150 }
151 None
152}
153
154#[cfg(test)]
155mod test {
156 use crate::builtins::builtins_file;
157 use crate::db::File;
158
159 use crate::goto_definition::goto_definition;
160 use crate::test_utils::Fixture;
161 use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle};
162 use insta::assert_snapshot;
163 use rowan::TextRange;
164 use rustc_hash::FxHashMap;
165
166 #[must_use]
167 #[track_caller]
168 fn goto(sql: &str) -> String {
169 goto_(sql).expect("should always find a definition")
170 }
171
172 #[track_caller]
173 fn goto_(sql: &str) -> Option<String> {
174 let fixture = Fixture::new(sql);
175 let marker = fixture.marker();
178 let offset = marker.offset_before();
179 let source_span = marker.range();
180 let db = fixture.db();
181 let current_file = offset.file_id;
182
183 let results = goto_definition(db, offset);
184 if results.is_empty() {
185 return None;
186 }
187
188 let mut file_paths = FxHashMap::default();
189 file_paths.insert(current_file, "current.sql");
190 file_paths.insert(builtins_file(db), "builtins.sql");
191
192 let mut dests_by_file: FxHashMap<File, Vec<(usize, TextRange)>> = FxHashMap::default();
193 for (i, location) in results.iter().enumerate() {
194 dests_by_file
195 .entry(location.file)
196 .or_default()
197 .push((i + 2, location.range));
198 }
199
200 let multi_file = dests_by_file.len() > 1 || !dests_by_file.contains_key(¤t_file);
201
202 let mut snippet = Snippet::source(current_file.content(db).as_ref()).fold(true);
203 if multi_file {
204 snippet = snippet.path(*file_paths.get(¤t_file).unwrap());
205 }
206 if let Some(current_dests) = dests_by_file.remove(¤t_file) {
207 snippet = annotate_destinations(snippet, current_dests);
208 }
209 snippet = snippet.annotation(AnnotationKind::Context.span(source_span).label("1. source"));
210
211 let mut groups = vec![Level::INFO.primary_title("definition").element(snippet)];
212
213 for (dest_file, dests) in dests_by_file {
214 let path = file_paths.get(&dest_file).unwrap();
215 let other_snippet = Snippet::source(dest_file.content(db).as_ref())
216 .path(*path)
217 .fold(true);
218 let other_snippet = annotate_destinations(other_snippet, dests);
219 groups.push(
220 Level::INFO
221 .primary_title("definition")
222 .element(other_snippet),
223 );
224 }
225
226 let renderer = Renderer::plain().decor_style(DecorStyle::Unicode);
227 Some(
228 renderer
229 .render(&groups)
230 .to_string()
231 .replace("info: definition", ""),
233 )
234 }
235
236 fn goto_not_found(sql: &str) {
237 assert!(goto_(sql).is_none(), "Should not find a definition");
238 }
239
240 fn annotate_destinations<'a>(
241 mut snippet: Snippet<'a, annotate_snippets::Annotation<'a>>,
242 destinations: Vec<(usize, TextRange)>,
243 ) -> Snippet<'a, annotate_snippets::Annotation<'a>> {
244 for (label_index, range) in destinations {
245 snippet = snippet.annotation(
246 AnnotationKind::Context
247 .span(range.into())
248 .label(format!("{label_index}. destination")),
249 );
250 }
251
252 snippet
253 }
254
255 #[test]
256 fn goto_case_when() {
257 assert_snapshot!(goto("
258select case when$0 x > 1 then 1 else 2 end;
259"), @r"
260 ╭▸
261 2 │ select case when x > 1 then 1 else 2 end;
262 │ ┬─── ─ 1. source
263 │ │
264 ╰╴ 2. destination
265 ");
266 }
267
268 #[test]
269 fn goto_case_else() {
270 assert_snapshot!(goto("
271select case when x > 1 then 1 else$0 2 end;
272"), @r"
273 ╭▸
274 2 │ select case when x > 1 then 1 else 2 end;
275 ╰╴ ──── 2. destination ─ 1. source
276 ");
277 }
278
279 #[test]
280 fn goto_case_end() {
281 assert_snapshot!(goto("
282select case when x > 1 then 1 else 2 end$0;
283"), @r"
284 ╭▸
285 2 │ select case when x > 1 then 1 else 2 end;
286 ╰╴ ──── 2. destination ─ 1. source
287 ");
288 }
289
290 #[test]
291 fn goto_case_end_trailing_semi() {
292 assert_snapshot!(goto("
293select case when x > 1 then 1 else 2 end;$0
294"), @r"
295 ╭▸
296 2 │ select case when x > 1 then 1 else 2 end;
297 ╰╴ ──── 2. destination ─ 1. source
298 ");
299 }
300
301 #[test]
302 fn goto_case_then_not_found() {
303 goto_not_found(
304 "
305select case when x > 1 then$0 1 else 2 end;
306",
307 )
308 }
309
310 #[test]
311 fn rollback_to_begin() {
312 assert_snapshot!(goto(
313 "
314begin;
315select 1;
316rollback$0;
317",
318 ), @"
319 ╭▸
320 2 │ begin;
321 │ ────── 2. destination
322 3 │ select 1;
323 4 │ rollback;
324 ╰╴ ─ 1. source
325 ");
326 }
327
328 #[test]
329 fn goto_drop_table() {
330 assert_snapshot!(goto("
331create table t();
332drop table t$0;
333"), @r"
334 ╭▸
335 2 │ create table t();
336 │ ─ 2. destination
337 3 │ drop table t;
338 ╰╴ ─ 1. source
339 ");
340 }
341
342 #[test]
343 fn goto_drop_foreign_table() {
344 assert_snapshot!(goto("
345create foreign table t(a int) server s;
346drop foreign table t$0;
347"), @r"
348 ╭▸
349 2 │ create foreign table t(a int) server s;
350 │ ─ 2. destination
351 3 │ drop foreign table t;
352 ╰╴ ─ 1. source
353 ");
354 }
355
356 #[test]
357 fn goto_definition_prefers_previous_token() {
358 assert_snapshot!(goto("
359create table t(a int);
360select t.$0a from t;
361"), @r"
362 ╭▸
363 2 │ create table t(a int);
364 │ ─ 2. destination
365 3 │ select t.a from t;
366 ╰╴ ─ 1. source
367 ");
368
369 assert_snapshot!(goto("
370create type ty as (a int, b int);
371with t as (select '(1,2)'::ty c)
372select (c)$0.a from t;
373"), @r"
374 ╭▸
375 3 │ with t as (select '(1,2)'::ty c)
376 │ ─ 2. destination
377 4 │ select (c).a from t;
378 ╰╴ ─ 1. source
379 ");
380 assert_snapshot!(goto("
381create function f() returns int as 'select 1' language sql;
382select f($0);
383"), @r"
384 ╭▸
385 2 │ create function f() returns int as 'select 1' language sql;
386 │ ─ 2. destination
387 3 │ select f();
388 ╰╴ ─ 1. source
389 ");
390
391 assert_snapshot!(goto("
392with t as (select array[1,2,3]::int[] c)
393select c[$01] from t;
394"), @r"
395 ╭▸
396 2 │ with t as (select array[1,2,3]::int[] c)
397 │ ─ 2. destination
398 3 │ select c[1] from t;
399 ╰╴ ─ 1. source
400 ");
401
402 assert_snapshot!(goto("
403with t as (select array[1,2,3]::int[] c, 1 b)
404select c[b]$0 from t;
405"), @r"
406 ╭▸
407 2 │ with t as (select array[1,2,3]::int[] c, 1 b)
408 │ ─ 2. destination
409 3 │ select c[b] from t;
410 ╰╴ ─ 1. source
411 ");
412 }
413
414 #[test]
415 fn goto_fetch_cursor() {
416 assert_snapshot!(goto("
417declare c scroll cursor for select * from t;
418fetch forward 5 from c$0;
419"), @r"
420 ╭▸
421 2 │ declare c scroll cursor for select * from t;
422 │ ─ 2. destination
423 3 │ fetch forward 5 from c;
424 ╰╴ ─ 1. source
425 ");
426 }
427
428 #[test]
429 fn goto_close_cursor() {
430 assert_snapshot!(goto("
431declare c scroll cursor for select * from t;
432close c$0;
433"), @r"
434 ╭▸
435 2 │ declare c scroll cursor for select * from t;
436 │ ─ 2. destination
437 3 │ close c;
438 ╰╴ ─ 1. source
439 ");
440 }
441
442 #[test]
443 fn goto_move_cursor() {
444 assert_snapshot!(goto("
445declare c scroll cursor for select * from t;
446move forward 10 from c$0;
447"), @r"
448 ╭▸
449 2 │ declare c scroll cursor for select * from t;
450 │ ─ 2. destination
451 3 │ move forward 10 from c;
452 ╰╴ ─ 1. source
453 ");
454 }
455
456 #[test]
457 fn goto_execute_prepared_statement() {
458 assert_snapshot!(goto("
459prepare stmt as select 1;
460execute stmt$0;
461"), @r"
462 ╭▸
463 2 │ prepare stmt as select 1;
464 │ ──── 2. destination
465 3 │ execute stmt;
466 ╰╴ ─ 1. source
467 ");
468 }
469
470 #[test]
471 fn goto_deallocate_prepared_statement() {
472 assert_snapshot!(goto("
473prepare stmt as select 1;
474deallocate stmt$0;
475"), @r"
476 ╭▸
477 2 │ prepare stmt as select 1;
478 │ ──── 2. destination
479 3 │ deallocate stmt;
480 ╰╴ ─ 1. source
481 ");
482 }
483
484 #[test]
485 fn goto_notify_channel() {
486 assert_snapshot!(goto("
487listen updates;
488notify updates$0;
489"), @r"
490 ╭▸
491 2 │ listen updates;
492 │ ─────── 2. destination
493 3 │ notify updates;
494 ╰╴ ─ 1. source
495 ");
496 }
497
498 #[test]
499 fn goto_unlisten_channel() {
500 assert_snapshot!(goto("
501listen updates;
502unlisten updates$0;
503"), @r"
504 ╭▸
505 2 │ listen updates;
506 │ ─────── 2. destination
507 3 │ unlisten updates;
508 ╰╴ ─ 1. source
509 ");
510 }
511
512 #[test]
513 fn goto_rollback_to_savepoint() {
514 assert_snapshot!(goto("
515begin;
516savepoint sp;
517rollback to savepoint sp$0;
518"), @"
519 ╭▸
520 3 │ savepoint sp;
521 │ ── 2. destination
522 4 │ rollback to savepoint sp;
523 ╰╴ ─ 1. source
524 ");
525 }
526
527 #[test]
528 fn goto_release_savepoint() {
529 assert_snapshot!(goto("
530begin;
531savepoint sp;
532release savepoint sp$0;
533"), @"
534 ╭▸
535 3 │ savepoint sp;
536 │ ── 2. destination
537 4 │ release savepoint sp;
538 ╰╴ ─ 1. source
539 ");
540 }
541
542 #[test]
543 fn goto_delete_where_current_of_cursor() {
544 assert_snapshot!(goto("
545declare c scroll cursor for select * from t;
546delete from t where current of c$0;
547"), @r"
548 ╭▸
549 2 │ declare c scroll cursor for select * from t;
550 │ ─ 2. destination
551 3 │ delete from t where current of c;
552 ╰╴ ─ 1. source
553 ");
554 }
555
556 #[test]
557 fn goto_update_where_current_of_cursor() {
558 assert_snapshot!(goto("
559declare c scroll cursor for select * from t;
560update t set a = a + 10 where current of c$0;
561"), @r"
562 ╭▸
563 2 │ declare c scroll cursor for select * from t;
564 │ ─ 2. destination
565 3 │ update t set a = a + 10 where current of c;
566 ╰╴ ─ 1. source
567 ");
568 }
569
570 #[test]
571 fn goto_with_table_star() {
572 assert_snapshot!(goto("
573with t as (select 1 a)
574select t$0.* from t;
575"), @r"
576 ╭▸
577 2 │ with t as (select 1 a)
578 │ ─ 2. destination
579 3 │ select t.* from t;
580 ╰╴ ─ 1. source
581 ");
582 }
583
584 #[test]
585 fn goto_cte_shadowed_table_star_column_count_not_found() {
586 goto_not_found(
587 "
588create table t(a int, b int);
589with
590 t as (
591 select 1
592 ),
593 -- yy overrides y since there's only 1 column in the *
594 u(x, yy) as (
595 select *, 2 y, 3 z from t
596 )
597select y$0 from u;
598",
599 );
600 }
601
602 #[test]
603 fn goto_cross_join_func_column() {
604 assert_snapshot!(goto(r#"
605with t(x) as (select $$[{"a":1,"b":2}]$$::json)
606select * from t, json_to_recordset(x$0) as r(a int, b int);
607"#), @r#"
608 ╭▸
609 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
610 │ ─ 2. destination
611 3 │ select * from t, json_to_recordset(x) as r(a int, b int);
612 ╰╴ ─ 1. source
613 "#);
614 }
615
616 #[test]
617 fn goto_cross_join_func_qualified_column_table() {
618 assert_snapshot!(goto(r#"
619with t(x) as (select $$[{"a":1,"b":2}]$$::json)
620select * from t, json_to_recordset(t$0.x) as r(a int, b int);
621"#), @r#"
622 ╭▸
623 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
624 │ ─ 2. destination
625 3 │ select * from t, json_to_recordset(t.x) as r(a int, b int);
626 ╰╴ ─ 1. source
627 "#);
628 }
629
630 #[test]
631 fn goto_cross_join_func_qualified_column_field() {
632 assert_snapshot!(goto(r#"
633with t(x) as (select $$[{"a":1,"b":2}]$$::json)
634select * from t, json_to_recordset(t.x$0) as r(a int, b int);
635"#), @r#"
636 ╭▸
637 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
638 │ ─ 2. destination
639 3 │ select * from t, json_to_recordset(t.x) as r(a int, b int);
640 ╰╴ ─ 1. source
641 "#);
642 }
643
644 #[test]
645 fn goto_lateral_values_alias_in_subquery() {
646 assert_snapshot!(goto("
647select u.n, x.val
648from (values (1), (2)) u(n)
649cross join lateral (select u$0.n * 10 as val) x;
650"), @r"
651 ╭▸
652 3 │ from (values (1), (2)) u(n)
653 │ ─ 2. destination
654 4 │ cross join lateral (select u.n * 10 as val) x;
655 ╰╴ ─ 1. source
656 ");
657 }
658
659 #[test]
660 fn goto_correlated_subquery_outer_column() {
661 assert_snapshot!(goto("
662create table foo (id int);
663create table bar (fid int);
664select * from bar b where exists (select 1 from foo where foo.id = b.fid$0);
665"), @"
666 ╭▸
667 3 │ create table bar (fid int);
668 │ ─── 2. destination
669 4 │ select * from bar b where exists (select 1 from foo where foo.id = b.fid);
670 ╰╴ ─ 1. source
671 ");
672 }
673
674 #[test]
675 fn goto_update_set_correlated_subquery_column() {
676 assert_snapshot!(goto("create table foo(a int, b int); update foo set a = (select b$0);"), @"
677 ╭▸
678 1 │ create table foo(a int, b int); update foo set a = (select b);
679 ╰╴ ─ 2. destination ─ 1. source
680 ");
681 }
682
683 #[test]
684 fn goto_delete_where_correlated_subquery_column() {
685 assert_snapshot!(goto("create table foo(a int, b int); delete from foo where a = (select b$0);"), @"
686 ╭▸
687 1 │ create table foo(a int, b int); delete from foo where a = (select b);
688 ╰╴ ─ 2. destination ─ 1. source
689 ");
690 }
691
692 #[test]
693 fn goto_multi_level_nested_select_outer_column() {
694 assert_snapshot!(goto("create table foo(a int); select (select (select a$0)) from foo;"), @"
695 ╭▸
696 1 │ create table foo(a int); select (select (select a)) from foo;
697 ╰╴ ─ 2. destination ─ 1. source
698 ");
699 }
700
701 #[test]
702 fn goto_lateral_missing_not_found() {
703 goto_not_found(
709 "
710select u.n, x.val
711from (values (1), (2)) u(n)
712cross join (select u$0.n * 10 as val) x;
713",
714 );
715 }
716
717 #[test]
718 fn goto_lateral_deeply_nested_paren_expr_values_alias_in_subquery() {
719 assert_snapshot!(goto("
720select u.n, x.val
721from (values (1), (2)) u(n)
722cross join lateral ((((select u$0.n * 10 as val)))) x;
723"), @r"
724 ╭▸
725 3 │ from (values (1), (2)) u(n)
726 │ ─ 2. destination
727 4 │ cross join lateral ((((select u.n * 10 as val)))) x;
728 ╰╴ ─ 1. source
729 ");
730 }
731
732 #[test]
733 fn goto_lateral_deeply_nested_paren_expr_values_alias_column() {
734 assert_snapshot!(goto("
735select u.n, x.val$0
736from (values (1), (2)) u(n)
737cross join lateral ((((select u.n * 10 as val)))) x;
738"), @r"
739 ╭▸
740 2 │ select u.n, x.val
741 │ ─ 1. source
742 3 │ from (values (1), (2)) u(n)
743 4 │ cross join lateral ((((select u.n * 10 as val)))) x;
744 ╰╴ ─── 2. destination
745 ");
746 }
747
748 #[test]
749 fn goto_lateral_deeply_nested_paren_expr_missing_not_found() {
750 goto_not_found(
756 "
757select u.n, x.val
758from (values (1), (2)) u(n)
759cross join ((((select u$0.n * 10 as val)))) x;
760",
761 );
762 }
763
764 #[test]
765 fn goto_aliased_join_expr_qualified_column() {
766 assert_snapshot!(goto("
767create table t(a int, b int);
768create table u(a int, c int);
769select j.b$0 from (t join u using(a)) as j;
770"), @"
771 ╭▸
772 2 │ create table t(a int, b int);
773 │ ─ 2. destination
774 3 │ create table u(a int, c int);
775 4 │ select j.b from (t join u using(a)) as j;
776 ╰╴ ─ 1. source
777 ");
778 }
779
780 #[test]
781 fn goto_aliased_join_expr_qualified_merged_column() {
782 assert_snapshot!(goto("
783create table t(a int, b int);
784create table u(a int, c int);
785select j.a$0 from (t join u using(a)) as j;
786"), @"
787 ╭▸
788 2 │ create table t(a int, b int);
789 │ ─ 2. destination
790 3 │ create table u(a int, c int);
791 4 │ select j.a from (t join u using(a)) as j;
792 ╰╴ ─ 1. source
793 ");
794 }
795
796 #[test]
797 fn goto_aliased_join_expr_qualified_right_column() {
798 assert_snapshot!(goto("
799create table t(a int, b int);
800create table u(a int, c int);
801select j.c$0 from (t join u using(a)) as j;
802"), @"
803 ╭▸
804 3 │ create table u(a int, c int);
805 │ ─ 2. destination
806 4 │ select j.c from (t join u using(a)) as j;
807 ╰╴ ─ 1. source
808 ");
809 }
810
811 #[test]
812 fn goto_unaliased_paren_join_qualified_column_target_list() {
813 assert_snapshot!(goto("
814create table t (a int);
815create table u (b int);
816select t.a$0 from (t join u on t.a = u.b);
817"), @"
818 ╭▸
819 2 │ create table t (a int);
820 │ ─ 2. destination
821 3 │ create table u (b int);
822 4 │ select t.a from (t join u on t.a = u.b);
823 ╰╴ ─ 1. source
824 ");
825 }
826
827 #[test]
828 fn goto_unaliased_paren_join_qualified_column_where_clause() {
829 assert_snapshot!(goto("
830create table t (a int);
831create table u (b int);
832select 1 from (t join u on t.a = u.b) where t.a$0 = 1;
833"), @"
834 ╭▸
835 2 │ create table t (a int);
836 │ ─ 2. destination
837 3 │ create table u (b int);
838 4 │ select 1 from (t join u on t.a = u.b) where t.a = 1;
839 ╰╴ ─ 1. source
840 ");
841 }
842
843 #[test]
844 fn goto_unaliased_paren_join_qualified_column_own_on_clause() {
845 assert_snapshot!(goto("
846create table t (a int);
847create table u (b int);
848select 1 from (t join u on t.a$0 = u.b);
849"), @"
850 ╭▸
851 2 │ create table t (a int);
852 │ ─ 2. destination
853 3 │ create table u (b int);
854 4 │ select 1 from (t join u on t.a = u.b);
855 ╰╴ ─ 1. source
856 ");
857 }
858
859 #[test]
860 fn goto_unaliased_paren_join_qualified_column_outer_on_clause() {
861 assert_snapshot!(goto("
862create table t (a int);
863create table u (b int);
864create table v (c int);
865select 1 from (t join u on t.a = u.b) join v on t.a$0 = v.c;
866"), @"
867 ╭▸
868 2 │ create table t (a int);
869 │ ─ 2. destination
870 ‡
871 5 │ select 1 from (t join u on t.a = u.b) join v on t.a = v.c;
872 ╰╴ ─ 1. source
873 ");
874 }
875
876 #[test]
877 fn goto_fully_wrapped_paren_join_qualified_column_left() {
878 assert_snapshot!(goto("
879create table t (a int);
880create table u (b int);
881create table v (c int);
882select 1 from ((t join u on t.a = u.b) join v on v.c = t.a$0);
883"), @"
884 ╭▸
885 2 │ create table t (a int);
886 │ ─ 2. destination
887 ‡
888 5 │ select 1 from ((t join u on t.a = u.b) join v on v.c = t.a);
889 ╰╴ ─ 1. source
890 ");
891 }
892
893 #[test]
894 fn goto_fully_wrapped_paren_join_qualified_column_right() {
895 assert_snapshot!(goto("
896create table t (a int);
897create table u (b int);
898create table v (c int);
899select 1 from ((t join u on t.a = u.b) join v on v.c$0 = t.a);
900"), @"
901 ╭▸
902 4 │ create table v (c int);
903 │ ─ 2. destination
904 5 │ select 1 from ((t join u on t.a = u.b) join v on v.c = t.a);
905 ╰╴ ─ 1. source
906 ");
907 }
908
909 #[test]
910 fn goto_ambiguous_unqualified_column_comma_join() {
911 assert_snapshot!(goto("
912create table t(a int);
913create table u(a int);
914select a$0 from t, u;
915"), @"
916 ╭▸
917 2 │ create table t(a int);
918 │ ─ 2. destination
919 3 │ create table u(a int);
920 │ ─ 3. destination
921 4 │ select a from t, u;
922 ╰╴ ─ 1. source
923 ");
924 }
925
926 #[test]
927 fn goto_join_using_output_column() {
928 assert_snapshot!(goto("
929create table t(a int, b int);
930create table u(a int, c int);
931select a$0 from t join u using(a);
932"), @"
933 ╭▸
934 2 │ create table t(a int, b int);
935 │ ─ 2. destination
936 3 │ create table u(a int, c int);
937 │ ─ 3. destination
938 4 │ select a from t join u using(a);
939 ╰╴ ─ 1. source
940 ");
941 }
942
943 #[test]
944 fn goto_natural_join_output_column() {
945 assert_snapshot!(goto("
946create table t(a int, b int);
947create table u(a int, c int);
948select a$0 from t natural join u;
949"), @"
950 ╭▸
951 2 │ create table t(a int, b int);
952 │ ─ 2. destination
953 3 │ create table u(a int, c int);
954 │ ─ 3. destination
955 4 │ select a from t natural join u;
956 ╰╴ ─ 1. source
957 ");
958 }
959
960 #[test]
961 fn goto_lateral_cte_ref_after_lateral_not_found() {
962 goto_not_found(
967 "
968with
969 d as (select 1 id, 2 amount),
970 c as (select 2 id)
971select r.amount
972from
973 d,
974 lateral (
975 select d.amount
976 from d
977 where d.id = c$0.id
978 limit 1
979 ) r,
980 c;
981",
982 );
983 }
984
985 #[test]
986 fn goto_cte_forward_ref_not_found() {
987 goto_not_found(
990 "
991 with
992 a as (select * from b$0),
993 b as (select 1 x)
994 select * from a;
995",
996 );
997 }
998
999 #[test]
1000 fn goto_cte_forward_ref_ignored() {
1001 assert_snapshot!(goto("
1002create table b(c int);
1003with
1004 a as (select c$0 from b),
1005 b as (select 1 c)
1006select c from a;
1007"), @"
1008 ╭▸
1009 2 │ create table b(c int);
1010 │ ─ 2. destination
1011 3 │ with
1012 4 │ a as (select c from b),
1013 ╰╴ ─ 1. source
1014 ");
1015 }
1016
1017 #[test]
1018 fn goto_cte_forward_ref_ignored_inside_table_query() {
1019 assert_snapshot!(goto("
1020create table b(c int);
1021with
1022 a as (table b),
1023 b as (select 1 c)
1024select c$0 from a;
1025"), @"
1026 ╭▸
1027 2 │ create table b(c int);
1028 │ ─ 2. destination
1029 ‡
1030 6 │ select c from a;
1031 ╰╴ ─ 1. source
1032 ");
1033 }
1034
1035 #[test]
1036 fn goto_cte_forward_ref_ignored_inside_create_table_as_star() {
1037 assert_snapshot!(goto("
1038create table b(c int);
1039create table ct as
1040 with
1041 a as (select * from b),
1042 b as (select 1 c)
1043 select * from a;
1044select c$0 from ct;
1045"), @"
1046 ╭▸
1047 2 │ create table b(c int);
1048 │ ─ 2. destination
1049 ‡
1050 8 │ select c from ct;
1051 ╰╴ ─ 1. source
1052 ");
1053 }
1054
1055 #[test]
1056 fn goto_cte_forward_ref_ignored_inside_create_table_as_table() {
1057 assert_snapshot!(goto("
1058create table b(c int);
1059create table made as
1060 with
1061 a as (table b),
1062 b as (select 1 c)
1063 table a;
1064select c$0 from made;
1065"), @"
1066 ╭▸
1067 2 │ create table b(c int);
1068 │ ─ 2. destination
1069 ‡
1070 8 │ select c from made;
1071 ╰╴ ─ 1. source
1072 ");
1073 }
1074
1075 #[test]
1076 fn goto_cte_star_over_subquery_from_item() {
1077 assert_snapshot!(goto("
1078create table t(c int);
1079with
1080 a as (select * from (select c from t))
1081select c$0 from a;
1082"), @"
1083 ╭▸
1084 4 │ a as (select * from (select c from t))
1085 │ ─ 2. destination
1086 5 │ select c from a;
1087 ╰╴ ─ 1. source
1088 ");
1089 }
1090
1091 #[test]
1092 fn goto_outer_cte_visible_inside_inner_with() {
1093 assert_snapshot!(goto("
1094with outer_cte as (select 1 c)
1095select * from (
1096 with inner_cte as (select 2 d)
1097 select c$0 from outer_cte
1098) s;
1099"), @"
1100 ╭▸
1101 2 │ with outer_cte as (select 1 c)
1102 │ ─ 2. destination
1103 ‡
1104 5 │ select c from outer_cte
1105 ╰╴ ─ 1. source
1106 ");
1107 }
1108
1109 #[test]
1110 fn goto_inner_cte_forward_ref_falls_back_to_outer_cte() {
1111 assert_snapshot!(goto("
1112with t as (select 1 c)
1113select * from (
1114 with
1115 x as (select c$0 from t),
1116 t as (select 2 c)
1117 select c from x
1118) s;
1119"), @"
1120 ╭▸
1121 2 │ with t as (select 1 c)
1122 │ ─ 2. destination
1123 ‡
1124 5 │ x as (select c from t),
1125 ╰╴ ─ 1. source
1126 ");
1127 }
1128
1129 #[test]
1130 fn goto_recursive_inner_cte_forward_ref_shadows_outer_cte() {
1131 assert_snapshot!(goto("
1132with t as (select 1 c)
1133select * from (
1134 with recursive
1135 x as (select c$0 from t),
1136 t as (select 2 c)
1137 select c from x
1138) s;
1139"), @"
1140 ╭▸
1141 5 │ x as (select c from t),
1142 │ ─ 1. source
1143 6 │ t as (select 2 c)
1144 ╰╴ ─ 2. destination
1145 ");
1146 }
1147
1148 #[test]
1149 fn goto_cte_forward_ref_ignored_for_qualified_star() {
1150 assert_snapshot!(goto("
1151create table b(c int);
1152with
1153 a as (select b.* from b),
1154 b as (select 1 c)
1155select c$0 from a;
1156"), @"
1157 ╭▸
1158 2 │ create table b(c int);
1159 │ ─ 2. destination
1160 ‡
1161 6 │ select c from a;
1162 ╰╴ ─ 1. source
1163 ");
1164 }
1165
1166 #[test]
1167 fn goto_cte_forward_ref_ignored_for_star_column_count() {
1168 assert_snapshot!(goto("
1169create table b(x int, yy int);
1170with
1171 a(x, yy) as (select *, 2 y, 3 z from b),
1172 b as (select 1 only_col)
1173select y$0 from a;
1174"), @"
1175 ╭▸
1176 4 │ a(x, yy) as (select *, 2 y, 3 z from b),
1177 │ ─ 2. destination
1178 5 │ b as (select 1 only_col)
1179 6 │ select y from a;
1180 ╰╴ ─ 1. source
1181 ");
1182 }
1183
1184 #[test]
1185 fn goto_cte_forward_ref_ignored_inside_subquery_table() {
1186 assert_snapshot!(goto("
1187create table b(c int);
1188with
1189 a as (select * from (table b) q),
1190 b as (select 1 c)
1191select c$0 from a;
1192"), @"
1193 ╭▸
1194 2 │ create table b(c int);
1195 │ ─ 2. destination
1196 ‡
1197 6 │ select c from a;
1198 ╰╴ ─ 1. source
1199 ");
1200 }
1201
1202 #[test]
1203 fn goto_drop_sequence() {
1204 assert_snapshot!(goto("
1205create sequence s;
1206drop sequence s$0;
1207"), @r"
1208 ╭▸
1209 2 │ create sequence s;
1210 │ ─ 2. destination
1211 3 │ drop sequence s;
1212 ╰╴ ─ 1. source
1213 ");
1214 }
1215
1216 #[test]
1217 fn goto_drop_constraint() {
1218 assert_snapshot!(goto("
1219create table t(id int constraint id_positive check (id > 0));
1220alter table t drop constraint id_positive$0;
1221"), @"
1222 ╭▸
1223 2 │ create table t(id int constraint id_positive check (id > 0));
1224 │ ─────────── 2. destination
1225 3 │ alter table t drop constraint id_positive;
1226 ╰╴ ─ 1. source
1227 ");
1228 }
1229
1230 #[test]
1231 fn goto_comment_on_constraint() {
1232 assert_snapshot!(goto("
1233create table t(id int constraint id_positive check (id > 0));
1234comment on constraint id_positive$0 on t is 'positive id';
1235"), @"
1236 ╭▸
1237 2 │ create table t(id int constraint id_positive check (id > 0));
1238 │ ─────────── 2. destination
1239 3 │ comment on constraint id_positive on t is 'positive id';
1240 ╰╴ ─ 1. source
1241 ");
1242 }
1243
1244 #[test]
1245 fn goto_comment_on_constraint_table() {
1246 assert_snapshot!(goto("
1247create table t(id int constraint id_positive check (id > 0));
1248comment on constraint id_positive on t$0 is 'positive id';
1249"), @"
1250 ╭▸
1251 2 │ create table t(id int constraint id_positive check (id > 0));
1252 │ ─ 2. destination
1253 3 │ comment on constraint id_positive on t is 'positive id';
1254 ╰╴ ─ 1. source
1255 ");
1256 }
1257
1258 #[test]
1259 fn goto_drop_constraint_with_same_name_on_multiple_tables() {
1260 assert_snapshot!(goto("
1261create table t(id int constraint id_positive check (id > 0));
1262create table u(id int constraint id_positive check (id > 0));
1263alter table u drop constraint id_positive$0;
1264"), @"
1265 ╭▸
1266 3 │ create table u(id int constraint id_positive check (id > 0));
1267 │ ─────────── 2. destination
1268 4 │ alter table u drop constraint id_positive;
1269 ╰╴ ─ 1. source
1270 ");
1271 }
1272
1273 #[test]
1274 fn goto_alter_table_add_constraint() {
1275 assert_snapshot!(goto("
1276create table t(id int);
1277alter table t add constraint id_positive check (id > 0);
1278comment on constraint id_positive$0 on t is 'positive id';
1279"), @"
1280 ╭▸
1281 3 │ alter table t add constraint id_positive check (id > 0);
1282 │ ─────────── 2. destination
1283 4 │ comment on constraint id_positive on t is 'positive id';
1284 ╰╴ ─ 1. source
1285 ");
1286 }
1287
1288 #[test]
1289 fn goto_on_conflict_constraint() {
1290 assert_snapshot!(goto("
1291create table t(id int constraint t_id_key unique);
1292insert into t values (1) on conflict on constraint t_id_key$0 do nothing;
1293"), @"
1294 ╭▸
1295 2 │ create table t(id int constraint t_id_key unique);
1296 │ ──────── 2. destination
1297 3 │ insert into t values (1) on conflict on constraint t_id_key do nothing;
1298 ╰╴ ─ 1. source
1299 ");
1300 }
1301
1302 #[test]
1303 fn goto_drop_trigger() {
1304 assert_snapshot!(goto("
1305create trigger tr before insert on t for each row execute function f();
1306drop trigger tr$0 on t;
1307"), @r"
1308 ╭▸
1309 2 │ create trigger tr before insert on t for each row execute function f();
1310 │ ── 2. destination
1311 3 │ drop trigger tr on t;
1312 ╰╴ ─ 1. source
1313 ");
1314 }
1315
1316 #[test]
1317 fn goto_create_rule_table() {
1318 assert_snapshot!(goto("
1319create table t(a int);
1320create rule r as on select to t$0 do instead nothing;
1321"), @"
1322 ╭▸
1323 2 │ create table t(a int);
1324 │ ─ 2. destination
1325 3 │ create rule r as on select to t do instead nothing;
1326 ╰╴ ─ 1. source
1327 ");
1328 }
1329
1330 #[test]
1331 fn goto_drop_rule() {
1332 assert_snapshot!(goto("
1333create table t(a int);
1334create rule r as on select to t do instead nothing;
1335drop rule r$0 on t;
1336"), @"
1337 ╭▸
1338 3 │ create rule r as on select to t do instead nothing;
1339 │ ─ 2. destination
1340 4 │ drop rule r on t;
1341 ╰╴ ─ 1. source
1342 ");
1343 }
1344
1345 #[test]
1346 fn goto_alter_rule() {
1347 assert_snapshot!(goto("
1348create table t(a int);
1349create rule r as on select to t do instead nothing;
1350alter rule r$0 on t rename to r2;
1351"), @"
1352 ╭▸
1353 3 │ create rule r as on select to t do instead nothing;
1354 │ ─ 2. destination
1355 4 │ alter rule r on t rename to r2;
1356 ╰╴ ─ 1. source
1357 ");
1358 }
1359
1360 #[test]
1361 fn goto_alter_table_enable_trigger() {
1362 assert_snapshot!(goto("
1363create table t(a int);
1364create function f() returns trigger language plpgsql as $$ begin return new; end $$;
1365create trigger tr before insert on t for each row execute function f();
1366alter table t enable trigger tr$0;
1367"), @"
1368 ╭▸
1369 4 │ create trigger tr before insert on t for each row execute function f();
1370 │ ── 2. destination
1371 5 │ alter table t enable trigger tr;
1372 ╰╴ ─ 1. source
1373 ");
1374 }
1375
1376 #[test]
1377 fn goto_alter_table_disable_trigger() {
1378 assert_snapshot!(goto("
1379create table t(a int);
1380create function f() returns trigger language plpgsql as $$ begin return new; end $$;
1381create trigger tr before insert on t for each row execute function f();
1382alter table t disable trigger tr$0;
1383"), @"
1384 ╭▸
1385 4 │ create trigger tr before insert on t for each row execute function f();
1386 │ ── 2. destination
1387 5 │ alter table t disable trigger tr;
1388 ╰╴ ─ 1. source
1389 ");
1390 }
1391
1392 #[test]
1393 fn goto_alter_table_enable_rule() {
1394 assert_snapshot!(goto("
1395create table t(a int);
1396create rule r as on insert to t do instead nothing;
1397alter table t enable rule r$0;
1398"), @"
1399 ╭▸
1400 3 │ create rule r as on insert to t do instead nothing;
1401 │ ─ 2. destination
1402 4 │ alter table t enable rule r;
1403 ╰╴ ─ 1. source
1404 ");
1405 }
1406
1407 #[test]
1408 fn goto_alter_table_disable_rule() {
1409 assert_snapshot!(goto("
1410create table t(a int);
1411create rule r as on insert to t do instead nothing;
1412alter table t disable rule r$0;
1413"), @"
1414 ╭▸
1415 3 │ create rule r as on insert to t do instead nothing;
1416 │ ─ 2. destination
1417 4 │ alter table t disable rule r;
1418 ╰╴ ─ 1. source
1419 ");
1420 }
1421
1422 #[test]
1423 fn goto_drop_policy() {
1424 assert_snapshot!(goto("
1425create table t(c int);
1426create table u(c int);
1427create policy p on t;
1428create policy p on u;
1429drop policy if exists p$0 on t;
1430"), @r"
1431 ╭▸
1432 4 │ create policy p on t;
1433 │ ─ 2. destination
1434 5 │ create policy p on u;
1435 6 │ drop policy if exists p on t;
1436 ╰╴ ─ 1. source
1437 ");
1438 }
1439
1440 #[test]
1441 fn goto_alter_policy() {
1442 assert_snapshot!(goto("
1443create table t(c int);
1444create policy p on t;
1445alter policy p$0 on t
1446 with check (c > 1);
1447"), @r"
1448 ╭▸
1449 3 │ create policy p on t;
1450 │ ─ 2. destination
1451 4 │ alter policy p on t
1452 ╰╴ ─ 1. source
1453 ");
1454 }
1455
1456 #[test]
1457 fn goto_alter_policy_column() {
1458 assert_snapshot!(goto("
1459create table t(c int);
1460create policy p on t;
1461alter policy p on t
1462 with check (c$0 > 1);
1463"), @"
1464 ╭▸
1465 2 │ create table t(c int);
1466 │ ─ 2. destination
1467 ‡
1468 5 │ with check (c > 1);
1469 ╰╴ ─ 1. source
1470 ");
1471 }
1472
1473 #[test]
1474 fn goto_create_policy_column() {
1475 assert_snapshot!(goto("
1476create table t(c int, d int);
1477create policy p on t
1478 with check (c$0 > d);
1479"), @r"
1480 ╭▸
1481 2 │ create table t(c int, d int);
1482 │ ─ 2. destination
1483 3 │ create policy p on t
1484 4 │ with check (c > d);
1485 ╰╴ ─ 1. source
1486 ");
1487 }
1488
1489 #[test]
1490 fn goto_create_policy_using_column() {
1491 assert_snapshot!(goto("
1492create table t(c int, d int);
1493create policy p on t
1494 using (c$0 > d and 1 < 2);
1495"), @r"
1496 ╭▸
1497 2 │ create table t(c int, d int);
1498 │ ─ 2. destination
1499 3 │ create policy p on t
1500 4 │ using (c > d and 1 < 2);
1501 ╰╴ ─ 1. source
1502 ");
1503 }
1504
1505 #[test]
1506 fn goto_create_policy_qualified_column_table() {
1507 assert_snapshot!(goto("
1508create table t(c int, d int);
1509create policy p on t
1510 with check (t$0.c > d);
1511"), @r"
1512 ╭▸
1513 2 │ create table t(c int, d int);
1514 │ ─ 2. destination
1515 3 │ create policy p on t
1516 4 │ with check (t.c > d);
1517 ╰╴ ─ 1. source
1518 ");
1519 }
1520
1521 #[test]
1522 fn goto_create_policy_qualified_column() {
1523 assert_snapshot!(goto("
1524create table t(c int, d int);
1525create policy p on t
1526 with check (t.c$0 > d);
1527"), @r"
1528 ╭▸
1529 2 │ create table t(c int, d int);
1530 │ ─ 2. destination
1531 3 │ create policy p on t
1532 4 │ with check (t.c > d);
1533 ╰╴ ─ 1. source
1534 ");
1535 }
1536
1537 #[test]
1538 fn goto_create_policy_field_style_function_call() {
1539 assert_snapshot!(goto("
1540create table t(c int);
1541create function x(t) returns int8
1542 as 'select 1'
1543 language sql;
1544create policy p on t
1545 with check (t.c > 1 and t.x$0 > 0);
1546"), @r"
1547 ╭▸
1548 3 │ create function x(t) returns int8
1549 │ ─ 2. destination
1550 ‡
1551 7 │ with check (t.c > 1 and t.x > 0);
1552 ╰╴ ─ 1. source
1553 ");
1554 }
1555
1556 #[test]
1557 fn goto_function_param_in_begin_atomic_body() {
1558 assert_snapshot!(goto("
1559create function f(a int) returns int
1560begin atomic
1561 select a$0;
1562end;
1563"), @"
1564 ╭▸
1565 2 │ create function f(a int) returns int
1566 │ ─ 2. destination
1567 3 │ begin atomic
1568 4 │ select a;
1569 ╰╴ ─ 1. source
1570 ");
1571 }
1572
1573 #[test]
1574 fn goto_function_param_in_begin_atomic_predicate() {
1575 assert_snapshot!(goto("
1576create table t (id int);
1577create function f(x int) returns int begin atomic
1578 select id from t where id = x$0;
1579end;
1580"), @"
1581 ╭▸
1582 3 │ create function f(x int) returns int begin atomic
1583 │ ─ 2. destination
1584 4 │ select id from t where id = x;
1585 ╰╴ ─ 1. source
1586 ");
1587 }
1588
1589 #[test]
1590 fn goto_function_param_in_sql_body_return_expr() {
1591 assert_snapshot!(goto("
1592create function f(x int) returns int language sql return x$0 + 1;
1593"), @"
1594 ╭▸
1595 2 │ create function f(x int) returns int language sql return x + 1;
1596 ╰╴ ─ 2. destination ─ 1. source
1597 ");
1598 }
1599
1600 #[test]
1601 fn goto_function_param_self_qualified_in_sql_body_return_expr() {
1602 assert_snapshot!(goto("
1603create function f(x int) returns int language sql return f.x$0 + 1;
1604"), @"
1605 ╭▸
1606 2 │ create function f(x int) returns int language sql return f.x + 1;
1607 ╰╴ ─ 2. destination ─ 1. source
1608 ");
1609 }
1610
1611 #[test]
1612 fn goto_function_param_bogus_qualified_in_sql_body_return_expr() {
1613 goto_not_found(
1614 "
1615create function f(x int) returns int language sql return bogus.x$0 + 1;
1616",
1617 );
1618 }
1619
1620 #[test]
1621 fn goto_positional_param_in_sql_body_return_expr() {
1622 assert_snapshot!(goto("
1623create function f(x int) returns int language sql return $1$0 + 1;
1624"), @"
1625 ╭▸
1626 2 │ create function f(x int) returns int language sql return $1 + 1;
1627 ╰╴ ─ 2. destination ─ 1. source
1628 ");
1629 }
1630
1631 #[test]
1632 fn goto_positional_param_in_begin_atomic_body() {
1633 assert_snapshot!(goto("
1634create function f(x int) returns int language sql begin atomic
1635 select $1$0 + 1;
1636end;
1637"), @"
1638 ╭▸
1639 2 │ create function f(x int) returns int language sql begin atomic
1640 │ ─ 2. destination
1641 3 │ select $1 + 1;
1642 ╰╴ ─ 1. source
1643 ");
1644 }
1645
1646 #[test]
1647 fn goto_positional_param_unnamed_param() {
1648 assert_snapshot!(goto("
1649create function f(int) returns int language sql return $1$0;
1650"), @"
1651 ╭▸
1652 2 │ create function f(int) returns int language sql return $1;
1653 ╰╴ ─── 2. destination ─ 1. source
1654 ");
1655 }
1656
1657 #[test]
1658 fn goto_positional_param_second_of_two() {
1659 assert_snapshot!(goto("
1660create function f(int, text) returns int language sql return $2$0;
1661"), @"
1662 ╭▸
1663 2 │ create function f(int, text) returns int language sql return $2;
1664 ╰╴ ──── 2. destination ─ 1. source
1665 ");
1666 }
1667
1668 #[test]
1669 fn goto_function_param_in_later_param_default() {
1670 assert_snapshot!(goto("
1671create function f(a int default 1, b int default a$0) returns int
1672begin atomic select 1; end;
1673"), @"
1674 ╭▸
1675 2 │ create function f(a int default 1, b int default a) returns int
1676 ╰╴ ─ 2. destination ─ 1. source
1677 ");
1678 }
1679
1680 #[test]
1681 fn goto_alter_policy_qualified_column_table() {
1682 assert_snapshot!(goto("
1683create table t(c int, d int);
1684alter policy p on t
1685 with check (t$0.c > d);
1686"), @r"
1687 ╭▸
1688 2 │ create table t(c int, d int);
1689 │ ─ 2. destination
1690 3 │ alter policy p on t
1691 4 │ with check (t.c > d);
1692 ╰╴ ─ 1. source
1693 ");
1694 }
1695
1696 #[test]
1697 fn goto_alter_policy_qualified_column() {
1698 assert_snapshot!(goto("
1699create table t(c int, d int);
1700alter policy p on t
1701 with check (t.c$0 > d);
1702"), @r"
1703 ╭▸
1704 2 │ create table t(c int, d int);
1705 │ ─ 2. destination
1706 3 │ alter policy p on t
1707 4 │ with check (t.c > d);
1708 ╰╴ ─ 1. source
1709 ");
1710 }
1711
1712 #[test]
1713 fn goto_builtin_now() {
1714 assert_snapshot!(goto("
1715-- include-builtins
1716select now$0();
1717"), @"
1718 ╭▸ current.sql:3:10
1719 │
1720 3 │ select now();
1721 │ ─ 1. source
1722 ╰╴
1723
1724 ╭▸ builtins.sql:11089:28
1725 │
1726 11089 │ create function pg_catalog.now() returns timestamp with time zone
1727 ╰╴ ─── 2. destination
1728 ");
1729 }
1730
1731 #[test]
1732 fn goto_current_timestamp() {
1733 assert_snapshot!(goto("
1734-- include-builtins
1735select current_timestamp$0;
1736"), @"
1737 ╭▸ current.sql:3:24
1738 │
1739 3 │ select current_timestamp;
1740 │ ─ 1. source
1741 ╰╴
1742
1743 ╭▸ builtins.sql:11089:28
1744 │
1745 11089 │ create function pg_catalog.now() returns timestamp with time zone
1746 ╰╴ ─── 2. destination
1747 ");
1748 }
1749
1750 #[test]
1751 fn goto_current_user() {
1752 assert_snapshot!(goto("
1753create function pg_catalog.current_user() returns name
1754 language internal;
1755select current_user$0;
1756"), @"
1757 ╭▸
1758 2 │ create function pg_catalog.current_user() returns name
1759 │ ──────────── 2. destination
1760 3 │ language internal;
1761 4 │ select current_user;
1762 ╰╴ ─ 1. source
1763 "
1764 );
1765 }
1766
1767 #[test]
1768 fn goto_user_keyword() {
1769 assert_snapshot!(goto("
1770create function pg_catalog.current_user() returns name
1771 language internal;
1772select user$0;
1773"), @"
1774 ╭▸
1775 2 │ create function pg_catalog.current_user() returns name
1776 │ ──────────── 2. destination
1777 3 │ language internal;
1778 4 │ select user;
1779 ╰╴ ─ 1. source
1780 "
1781 );
1782 }
1783
1784 #[test]
1785 fn goto_session_user() {
1786 assert_snapshot!(goto("
1787create function pg_catalog.session_user() returns name
1788 language internal;
1789select session_user$0;
1790"), @"
1791 ╭▸
1792 2 │ create function pg_catalog.session_user() returns name
1793 │ ──────────── 2. destination
1794 3 │ language internal;
1795 4 │ select session_user;
1796 ╰╴ ─ 1. source
1797 "
1798 );
1799 }
1800
1801 #[test]
1802 fn goto_current_schema() {
1803 assert_snapshot!(goto("
1804create function current_schema() returns name
1805 language internal;
1806select current_schema$0;
1807"), @"
1808 ╭▸
1809 2 │ create function current_schema() returns name
1810 │ ────────────── 2. destination
1811 3 │ language internal;
1812 4 │ select current_schema;
1813 ╰╴ ─ 1. source
1814 "
1815 );
1816 }
1817
1818 #[test]
1819 fn goto_current_timestamp_cte_column() {
1820 assert_snapshot!(goto("
1821with t as (select 1 current_timestamp)
1822select current_timestamp$0 from t;
1823"), @r"
1824 ╭▸
1825 2 │ with t as (select 1 current_timestamp)
1826 │ ───────────────── 2. destination
1827 3 │ select current_timestamp from t;
1828 ╰╴ ─ 1. source
1829 ");
1830 }
1831
1832 #[test]
1833 fn goto_cte_casing() {
1834 goto_not_found(
1836 "
1837 with t as (select 1 Äpfel)
1838 select äpfel$0 from t;
1839 ",
1840 );
1841 }
1842
1843 #[test]
1844 fn goto_cte_emoji() {
1845 assert_snapshot!(goto(
1846 "
1847 with t as (select 1 🦀)
1848 select 🦀$0 from t;
1849 "), @"
1850 ╭▸
1851 2 │ with t as (select 1 🦀)
1852 │ ── 2. destination
1853 3 │ select 🦀 from t;
1854 ╰╴ ── 1. source
1855 ");
1856 }
1857
1858 #[test]
1859 fn goto_current_timestamp_in_where() {
1860 assert_snapshot!(goto("
1861-- include-builtins
1862create table t(created_at timestamptz);
1863select * from t where current_timestamp$0 > t.created_at;
1864"), @"
1865 ╭▸ current.sql:4:39
1866 │
1867 4 │ select * from t where current_timestamp > t.created_at;
1868 │ ─ 1. source
1869 ╰╴
1870
1871 ╭▸ builtins.sql:11089:28
1872 │
1873 11089 │ create function pg_catalog.now() returns timestamp with time zone
1874 ╰╴ ─── 2. destination
1875 ");
1876 }
1877
1878 #[test]
1879 fn goto_create_policy_schema_qualified_table() {
1880 assert_snapshot!(goto("
1881create schema foo;
1882create table foo.t(c int);
1883create policy p on foo.t
1884 with check (foo.t$0.c > 1);
1885"), @r"
1886 ╭▸
1887 3 │ create table foo.t(c int);
1888 │ ─ 2. destination
1889 4 │ create policy p on foo.t
1890 5 │ with check (foo.t.c > 1);
1891 ╰╴ ─ 1. source
1892 ");
1893 }
1894
1895 #[test]
1896 fn goto_create_policy_unqualified_table_with_schema_on_table() {
1897 assert_snapshot!(goto("
1898create schema foo;
1899create table foo.t(c int);
1900create policy p on foo.t
1901 with check (t$0.c > 1);
1902"), @r"
1903 ╭▸
1904 3 │ create table foo.t(c int);
1905 │ ─ 2. destination
1906 4 │ create policy p on foo.t
1907 5 │ with check (t.c > 1);
1908 ╰╴ ─ 1. source
1909 ");
1910 }
1911
1912 #[test]
1913 fn goto_drop_event_trigger() {
1914 assert_snapshot!(goto("
1915create event trigger et on ddl_command_start execute function f();
1916drop event trigger et$0;
1917"), @r"
1918 ╭▸
1919 2 │ create event trigger et on ddl_command_start execute function f();
1920 │ ── 2. destination
1921 3 │ drop event trigger et;
1922 ╰╴ ─ 1. source
1923 ");
1924 }
1925
1926 #[test]
1927 fn goto_alter_event_trigger() {
1928 assert_snapshot!(goto("
1929create event trigger et on ddl_command_start execute function f();
1930alter event trigger et$0 disable;
1931"), @r"
1932 ╭▸
1933 2 │ create event trigger et on ddl_command_start execute function f();
1934 │ ── 2. destination
1935 3 │ alter event trigger et disable;
1936 ╰╴ ─ 1. source
1937 ");
1938 }
1939
1940 #[test]
1941 fn goto_create_event_trigger_function() {
1942 assert_snapshot!(goto("
1943create function f() returns event_trigger as 'select 1' language sql;
1944create event trigger et on ddl_command_start execute function f$0();
1945"), @r"
1946 ╭▸
1947 2 │ create function f() returns event_trigger as 'select 1' language sql;
1948 │ ─ 2. destination
1949 3 │ create event trigger et on ddl_command_start execute function f();
1950 ╰╴ ─ 1. source
1951 ");
1952 }
1953
1954 #[test]
1955 fn goto_create_event_trigger_procedure() {
1956 assert_snapshot!(goto("
1957create procedure p() language sql as 'select 1';
1958create event trigger tr
1959 on ddl_command_end
1960 execute procedure p$0();
1961"), @r"
1962 ╭▸
1963 2 │ create procedure p() language sql as 'select 1';
1964 │ ─ 2. destination
1965 ‡
1966 5 │ execute procedure p();
1967 ╰╴ ─ 1. source
1968 ");
1969 }
1970
1971 #[test]
1972 fn goto_create_trigger_function() {
1973 assert_snapshot!(goto("
1974create function f() returns trigger as 'select 1' language sql;
1975create trigger tr before insert on t for each row execute function f$0();
1976"), @r"
1977 ╭▸
1978 2 │ create function f() returns trigger as 'select 1' language sql;
1979 │ ─ 2. destination
1980 3 │ create trigger tr before insert on t for each row execute function f();
1981 ╰╴ ─ 1. source
1982 ");
1983 }
1984
1985 #[test]
1986 fn goto_create_trigger_procedure() {
1987 assert_snapshot!(goto("
1988create procedure a() language sql as 'select 1';
1989create trigger tr before truncate or delete or insert
1990on t
1991execute procedure a$0();
1992"), @r"
1993 ╭▸
1994 2 │ create procedure a() language sql as 'select 1';
1995 │ ─ 2. destination
1996 ‡
1997 5 │ execute procedure a();
1998 ╰╴ ─ 1. source
1999 ");
2000 }
2001
2002 #[test]
2003 fn goto_drop_trigger_table_specific() {
2004 assert_snapshot!(goto("
2005create table u(a int);
2006create trigger tr before truncate
2007on u
2008execute function noop();
2009
2010create table t(b int);
2011create trigger tr before truncate
2012on t
2013execute function noop();
2014
2015drop trigger tr$0 on t;
2016"), @r"
2017 ╭▸
2018 8 │ create trigger tr before truncate
2019 │ ── 2. destination
2020 ‡
2021 12 │ drop trigger tr on t;
2022 ╰╴ ─ 1. source
2023 ");
2024 }
2025
2026 #[test]
2027 fn goto_create_trigger_table() {
2028 assert_snapshot!(goto("
2029create table t(b int);
2030create trigger tr before truncate
2031on t$0
2032execute function noop();
2033"), @r"
2034 ╭▸
2035 2 │ create table t(b int);
2036 │ ─ 2. destination
2037 3 │ create trigger tr before truncate
2038 4 │ on t
2039 ╰╴ ─ 1. source
2040 ");
2041 }
2042
2043 #[test]
2044 fn goto_create_constraint_trigger_from_table() {
2045 assert_snapshot!(goto("
2046create table t(id int);
2047create table ref_t(id int);
2048create constraint trigger trg after insert on t from ref_t$0 for each row execute function f();
2049"), @"
2050 ╭▸
2051 3 │ create table ref_t(id int);
2052 │ ───── 2. destination
2053 4 │ create constraint trigger trg after insert on t from ref_t for each row execute function f();
2054 ╰╴ ─ 1. source
2055 ");
2056 }
2057
2058 #[test]
2059 fn goto_create_trigger_when_new_column() {
2060 assert_snapshot!(goto("
2061create table foo (id int);
2062create trigger tr before insert on foo for each row when (new.id$0 > 0) execute function f();
2063"), @"
2064 ╭▸
2065 2 │ create table foo (id int);
2066 │ ── 2. destination
2067 3 │ create trigger tr before insert on foo for each row when (new.id > 0) execute function f();
2068 ╰╴ ─ 1. source
2069 ");
2070 }
2071
2072 #[test]
2073 fn goto_create_trigger_when_old_column() {
2074 assert_snapshot!(goto("
2075create table foo (id int);
2076create trigger tr after update on foo for each row when (old.id$0 > 0) execute function f();
2077"), @"
2078 ╭▸
2079 2 │ create table foo (id int);
2080 │ ── 2. destination
2081 3 │ create trigger tr after update on foo for each row when (old.id > 0) execute function f();
2082 ╰╴ ─ 1. source
2083 ");
2084 }
2085
2086 #[test]
2087 fn goto_create_trigger_when_new_table() {
2088 assert_snapshot!(goto("
2089create table foo (id int);
2090create trigger tr before insert on foo for each row when (new$0.id > 0) execute function f();
2091"), @"
2092 ╭▸
2093 2 │ create table foo (id int);
2094 │ ─── 2. destination
2095 3 │ create trigger tr before insert on foo for each row when (new.id > 0) execute function f();
2096 ╰╴ ─ 1. source
2097 ");
2098 }
2099
2100 #[test]
2101 fn goto_create_rule_old_column() {
2102 assert_snapshot!(goto("
2103create table t(id int);
2104create rule r as on update to t where old.id$0 = new.id do instead nothing;
2105"), @"
2106 ╭▸
2107 2 │ create table t(id int);
2108 │ ── 2. destination
2109 3 │ create rule r as on update to t where old.id = new.id do instead nothing;
2110 ╰╴ ─ 1. source
2111 ");
2112 }
2113
2114 #[test]
2115 fn goto_create_rule_new_column() {
2116 assert_snapshot!(goto("
2117create table t(id int);
2118create rule r as on update to t where old.id = new.id$0 do instead nothing;
2119"), @"
2120 ╭▸
2121 2 │ create table t(id int);
2122 │ ── 2. destination
2123 3 │ create rule r as on update to t where old.id = new.id do instead nothing;
2124 ╰╴ ─ 1. source
2125 ");
2126 }
2127
2128 #[test]
2129 fn goto_create_rule_old_table() {
2130 assert_snapshot!(goto("
2131create table t(id int);
2132create rule r as on update to t where old$0.id = new.id do instead nothing;
2133"), @"
2134 ╭▸
2135 2 │ create table t(id int);
2136 │ ─ 2. destination
2137 3 │ create rule r as on update to t where old.id = new.id do instead nothing;
2138 ╰╴ ─ 1. source
2139 ");
2140 }
2141
2142 #[test]
2143 fn goto_create_trigger_update_of_column() {
2144 assert_snapshot!(goto("
2145create table t(id int, updated_at timestamptz);
2146create trigger tr before update of updated_at$0 on t for each row execute function f();
2147"), @"
2148 ╭▸
2149 2 │ create table t(id int, updated_at timestamptz);
2150 │ ────────── 2. destination
2151 3 │ create trigger tr before update of updated_at on t for each row execute function f();
2152 ╰╴ ─ 1. source
2153 ");
2154 }
2155
2156 #[test]
2157 fn goto_create_sequence_owned_by() {
2158 assert_snapshot!(goto("
2159create table t(c serial);
2160create sequence s
2161 owned by t.c$0;
2162"), @r"
2163 ╭▸
2164 2 │ create table t(c serial);
2165 │ ─ 2. destination
2166 3 │ create sequence s
2167 4 │ owned by t.c;
2168 ╰╴ ─ 1. source
2169 ");
2170 }
2171
2172 #[test]
2173 fn goto_create_sequence_owned_by_table() {
2174 assert_snapshot!(goto("
2175create table t(c serial);
2176create sequence s
2177 owned by t$0.c;
2178"), @"
2179 ╭▸
2180 2 │ create table t(c serial);
2181 │ ─ 2. destination
2182 3 │ create sequence s
2183 4 │ owned by t.c;
2184 ╰╴ ─ 1. source
2185 ");
2186 }
2187
2188 #[test]
2189 fn goto_alter_sequence_owned_by_table() {
2190 assert_snapshot!(goto("
2191create table t(c serial);
2192create sequence s;
2193alter sequence s owned by t$0.c;
2194"), @"
2195 ╭▸
2196 2 │ create table t(c serial);
2197 │ ─ 2. destination
2198 3 │ create sequence s;
2199 4 │ alter sequence s owned by t.c;
2200 ╰╴ ─ 1. source
2201 ");
2202 }
2203
2204 #[test]
2205 fn goto_drop_tablespace() {
2206 assert_snapshot!(goto("
2207create tablespace ts location '/tmp/ts';
2208drop tablespace ts$0;
2209"), @r"
2210 ╭▸
2211 2 │ create tablespace ts location '/tmp/ts';
2212 │ ── 2. destination
2213 3 │ drop tablespace ts;
2214 ╰╴ ─ 1. source
2215 ");
2216 }
2217
2218 #[test]
2219 fn goto_create_table_tablespace() {
2220 assert_snapshot!(goto("
2221create tablespace bar location '/tmp/ts';
2222create table t (a int) tablespace b$0ar;
2223"), @r"
2224 ╭▸
2225 2 │ create tablespace bar location '/tmp/ts';
2226 │ ─── 2. destination
2227 3 │ create table t (a int) tablespace bar;
2228 ╰╴ ─ 1. source
2229 ");
2230 }
2231
2232 #[test]
2233 fn goto_drop_database() {
2234 assert_snapshot!(goto("
2235create database mydb;
2236drop database my$0db;
2237"), @r"
2238 ╭▸
2239 2 │ create database mydb;
2240 │ ──── 2. destination
2241 3 │ drop database mydb;
2242 ╰╴ ─ 1. source
2243 ");
2244 }
2245
2246 #[test]
2247 fn goto_drop_role() {
2248 assert_snapshot!(goto("
2249create role reader;
2250drop role read$0er;
2251"), @r"
2252 ╭▸
2253 2 │ create role reader;
2254 │ ────── 2. destination
2255 3 │ drop role reader;
2256 ╰╴ ─ 1. source
2257 ");
2258 }
2259
2260 #[test]
2261 fn goto_alter_role() {
2262 assert_snapshot!(goto("
2263create role reader;
2264alter role read$0er rename to writer;
2265"), @r"
2266 ╭▸
2267 2 │ create role reader;
2268 │ ────── 2. destination
2269 3 │ alter role reader rename to writer;
2270 ╰╴ ─ 1. source
2271 ");
2272 }
2273
2274 #[test]
2275 fn goto_set_role() {
2276 assert_snapshot!(goto("
2277create role reader;
2278set role read$0er;
2279"), @r"
2280 ╭▸
2281 2 │ create role reader;
2282 │ ────── 2. destination
2283 3 │ set role reader;
2284 ╰╴ ─ 1. source
2285 ");
2286 }
2287
2288 #[test]
2289 fn goto_create_tablespace_owner_role() {
2290 assert_snapshot!(goto("
2291create role reader;
2292create tablespace t owner read$0er location 'foo';
2293"), @r"
2294 ╭▸
2295 2 │ create role reader;
2296 │ ────── 2. destination
2297 3 │ create tablespace t owner reader location 'foo';
2298 ╰╴ ─ 1. source
2299 ");
2300 }
2301
2302 #[test]
2303 fn goto_role_definition_returns_self() {
2304 assert_snapshot!(goto("
2305create role read$0er;
2306"), @r"
2307 ╭▸
2308 2 │ create role reader;
2309 │ ┬──┬──
2310 │ │ │
2311 │ │ 1. source
2312 ╰╴ 2. destination
2313 ");
2314 }
2315
2316 #[test]
2317 fn goto_drop_database_defined_after() {
2318 assert_snapshot!(goto("
2319drop database my$0db;
2320create database mydb;
2321"), @r"
2322 ╭▸
2323 2 │ drop database mydb;
2324 │ ─ 1. source
2325 3 │ create database mydb;
2326 ╰╴ ──── 2. destination
2327 ");
2328 }
2329
2330 #[test]
2331 fn goto_database_definition_returns_self() {
2332 assert_snapshot!(goto("
2333create database my$0db;
2334"), @r"
2335 ╭▸
2336 2 │ create database mydb;
2337 │ ┬┬──
2338 │ ││
2339 │ │1. source
2340 ╰╴ 2. destination
2341 ");
2342 }
2343
2344 #[test]
2345 fn goto_drop_server() {
2346 assert_snapshot!(goto("
2347create server myserver foreign data wrapper fdw;
2348drop server my$0server;
2349"), @r"
2350 ╭▸
2351 2 │ create server myserver foreign data wrapper fdw;
2352 │ ──────── 2. destination
2353 3 │ drop server myserver;
2354 ╰╴ ─ 1. source
2355 ");
2356 }
2357
2358 #[test]
2359 fn goto_drop_server_defined_after() {
2360 assert_snapshot!(goto("
2361drop server my$0server;
2362create server myserver foreign data wrapper fdw;
2363"), @r"
2364 ╭▸
2365 2 │ drop server myserver;
2366 │ ─ 1. source
2367 3 │ create server myserver foreign data wrapper fdw;
2368 ╰╴ ──────── 2. destination
2369 ");
2370 }
2371
2372 #[test]
2373 fn goto_alter_server() {
2374 assert_snapshot!(goto("
2375create server myserver foreign data wrapper fdw;
2376alter server my$0server options (add foo 'bar');
2377"), @r"
2378 ╭▸
2379 2 │ create server myserver foreign data wrapper fdw;
2380 │ ──────── 2. destination
2381 3 │ alter server myserver options (add foo 'bar');
2382 ╰╴ ─ 1. source
2383 ");
2384 }
2385
2386 #[test]
2387 fn goto_server_definition_returns_self() {
2388 assert_snapshot!(goto("
2389create server my$0server foreign data wrapper fdw;
2390"), @r"
2391 ╭▸
2392 2 │ create server myserver foreign data wrapper fdw;
2393 │ ┬┬──────
2394 │ ││
2395 │ │1. source
2396 ╰╴ 2. destination
2397 ");
2398 }
2399
2400 #[test]
2401 fn goto_drop_extension() {
2402 assert_snapshot!(goto("
2403create extension myext;
2404drop extension my$0ext;
2405"), @r"
2406 ╭▸
2407 2 │ create extension myext;
2408 │ ───── 2. destination
2409 3 │ drop extension myext;
2410 ╰╴ ─ 1. source
2411 ");
2412 }
2413
2414 #[test]
2415 fn goto_drop_extension_defined_after() {
2416 assert_snapshot!(goto("
2417drop extension my$0ext;
2418create extension myext;
2419"), @r"
2420 ╭▸
2421 2 │ drop extension myext;
2422 │ ─ 1. source
2423 3 │ create extension myext;
2424 ╰╴ ───── 2. destination
2425 ");
2426 }
2427
2428 #[test]
2429 fn goto_alter_extension() {
2430 assert_snapshot!(goto("
2431create extension myext;
2432alter extension my$0ext update to '2.0';
2433"), @r"
2434 ╭▸
2435 2 │ create extension myext;
2436 │ ───── 2. destination
2437 3 │ alter extension myext update to '2.0';
2438 ╰╴ ─ 1. source
2439 ");
2440 }
2441
2442 #[test]
2443 fn goto_create_extension_with_schema() {
2444 assert_snapshot!(goto("
2445create schema ext_schema;
2446create extension hstore with schema ext_sche$0ma;
2447"), @"
2448 ╭▸
2449 2 │ create schema ext_schema;
2450 │ ────────── 2. destination
2451 3 │ create extension hstore with schema ext_schema;
2452 ╰╴ ─ 1. source
2453 ");
2454 }
2455
2456 #[test]
2457 fn goto_alter_extension_add_table() {
2458 assert_snapshot!(goto("
2459create extension e;
2460create table t(id int);
2461alter extension e add table t$0;
2462"), @"
2463 ╭▸
2464 3 │ create table t(id int);
2465 │ ─ 2. destination
2466 4 │ alter extension e add table t;
2467 ╰╴ ─ 1. source
2468 ");
2469 }
2470
2471 #[test]
2472 fn goto_alter_extension_add_foreign_table() {
2473 assert_snapshot!(goto("
2474create extension e;
2475create foreign table t(id int) server s;
2476alter extension e add foreign table t$0;
2477"), @"
2478 ╭▸
2479 3 │ create foreign table t(id int) server s;
2480 │ ─ 2. destination
2481 4 │ alter extension e add foreign table t;
2482 ╰╴ ─ 1. source
2483 ");
2484 }
2485
2486 #[test]
2487 fn goto_alter_default_privileges_in_schema() {
2488 assert_snapshot!(goto("
2489create schema myschema;
2490create role bob;
2491alter default privileges in schema myschema$0
2492 grant select on tables to bob;
2493"), @"
2494 ╭▸
2495 2 │ create schema myschema;
2496 │ ──────── 2. destination
2497 3 │ create role bob;
2498 4 │ alter default privileges in schema myschema
2499 ╰╴ ─ 1. source
2500 ");
2501 }
2502
2503 #[test]
2504 fn goto_alter_publication() {
2505 assert_snapshot!(goto("
2506create table t(id int);
2507create publication pub for table t;
2508alter publication pub$0 add table t;
2509"), @"
2510 ╭▸
2511 3 │ create publication pub for table t;
2512 │ ─── 2. destination
2513 4 │ alter publication pub add table t;
2514 ╰╴ ─ 1. source
2515 ");
2516 }
2517
2518 #[test]
2519 fn goto_alter_subscription() {
2520 assert_snapshot!(goto("
2521create subscription sub connection $$host=localhost$$ publication pub;
2522alter subscription sub$0 refresh publication;
2523"), @"
2524 ╭▸
2525 2 │ create subscription sub connection $$host=localhost$$ publication pub;
2526 │ ─── 2. destination
2527 3 │ alter subscription sub refresh publication;
2528 ╰╴ ─ 1. source
2529 ");
2530 }
2531
2532 #[test]
2533 fn goto_drop_language() {
2534 assert_snapshot!(goto("
2535create language plpythonu;
2536drop language plpythonu$0;
2537"), @"
2538 ╭▸
2539 2 │ create language plpythonu;
2540 │ ───────── 2. destination
2541 3 │ drop language plpythonu;
2542 ╰╴ ─ 1. source
2543 ");
2544 }
2545
2546 #[test]
2547 fn goto_create_function_language_option() {
2548 assert_snapshot!(goto("
2549create language mylang;
2550create function f() returns int language mylang$0 as $$x$$;
2551"), @"
2552 ╭▸
2553 2 │ create language mylang;
2554 │ ────── 2. destination
2555 3 │ create function f() returns int language mylang as $$x$$;
2556 ╰╴ ─ 1. source
2557 ");
2558 }
2559
2560 #[test]
2561 fn goto_create_procedure_language_option() {
2562 assert_snapshot!(goto("
2563create language mylang;
2564create procedure p() language mylang$0 as $$x$$;
2565"), @"
2566 ╭▸
2567 2 │ create language mylang;
2568 │ ────── 2. destination
2569 3 │ create procedure p() language mylang as $$x$$;
2570 ╰╴ ─ 1. source
2571 ");
2572 }
2573
2574 #[test]
2575 fn goto_create_function_support_option() {
2576 assert_snapshot!(goto("
2577create function sf(internal) returns internal language c as $$x$$;
2578create function f(int) returns int language sql support sf$0 as $$select 1$$;
2579"), @"
2580 ╭▸
2581 2 │ create function sf(internal) returns internal language c as $$x$$;
2582 │ ── 2. destination
2583 3 │ create function f(int) returns int language sql support sf as $$select 1$$;
2584 ╰╴ ─ 1. source
2585 ");
2586 }
2587
2588 #[test]
2589 fn goto_create_transform_language_option() {
2590 assert_snapshot!(goto("
2591create language mylang;
2592create type typ as (x int);
2593create transform for typ language mylang$0
2594 (from sql with function int4(typ));
2595"), @"
2596 ╭▸
2597 2 │ create language mylang;
2598 │ ────── 2. destination
2599 3 │ create type typ as (x int);
2600 4 │ create transform for typ language mylang
2601 ╰╴ ─ 1. source
2602 ");
2603 }
2604
2605 #[test]
2606 fn goto_collate_in_column() {
2607 assert_snapshot!(goto("
2608create collation mycoll (locale = 'C');
2609create table t(name text collate mycoll$0);
2610"), @"
2611 ╭▸
2612 2 │ create collation mycoll (locale = 'C');
2613 │ ────── 2. destination
2614 3 │ create table t(name text collate mycoll);
2615 ╰╴ ─ 1. source
2616 ");
2617 }
2618
2619 #[test]
2620 fn goto_collate_in_order_by() {
2621 assert_snapshot!(goto("
2622create collation c from \"C\";
2623create table t(a text);
2624select a from t order by a collate c$0;
2625"), @r#"
2626 ╭▸
2627 2 │ create collation c from "C";
2628 │ ─ 2. destination
2629 3 │ create table t(a text);
2630 4 │ select a from t order by a collate c;
2631 ╰╴ ─ 1. source
2632 "#);
2633 }
2634
2635 #[test]
2636 fn goto_collate_in_index_expr() {
2637 assert_snapshot!(goto("
2638create collation c from \"C\";
2639create table t(a text);
2640create index idx on t (a collate c$0);
2641"), @r#"
2642 ╭▸
2643 2 │ create collation c from "C";
2644 │ ─ 2. destination
2645 3 │ create table t(a text);
2646 4 │ create index idx on t (a collate c);
2647 ╰╴ ─ 1. source
2648 "#);
2649 }
2650
2651 #[test]
2652 fn goto_create_collation_from() {
2653 assert_snapshot!(goto("
2654create collation c1 (locale = 'C');
2655create collation c2 from c1$0;
2656"), @"
2657 ╭▸
2658 2 │ create collation c1 (locale = 'C');
2659 │ ── 2. destination
2660 3 │ create collation c2 from c1;
2661 ╰╴ ─ 1. source
2662 ");
2663 }
2664
2665 #[test]
2666 fn goto_create_server_foreign_data_wrapper() {
2667 assert_snapshot!(goto("
2668create foreign data wrapper fdw;
2669create server srv foreign data wrapper fdw$0;
2670"), @"
2671 ╭▸
2672 2 │ create foreign data wrapper fdw;
2673 │ ─── 2. destination
2674 3 │ create server srv foreign data wrapper fdw;
2675 ╰╴ ─ 1. source
2676 ");
2677 }
2678
2679 #[test]
2680 fn goto_alter_sequence() {
2681 assert_snapshot!(goto("
2682create sequence s;
2683alter sequence s$0 restart with 1;
2684"), @"
2685 ╭▸
2686 2 │ create sequence s;
2687 │ ─ 2. destination
2688 3 │ alter sequence s restart with 1;
2689 ╰╴ ─ 1. source
2690 ");
2691 }
2692
2693 #[test]
2694 fn goto_alter_view() {
2695 assert_snapshot!(goto("
2696create view v as select 1 as id;
2697alter view v$0 rename to v2;
2698"), @"
2699 ╭▸
2700 2 │ create view v as select 1 as id;
2701 │ ─ 2. destination
2702 3 │ alter view v rename to v2;
2703 ╰╴ ─ 1. source
2704 ");
2705 }
2706
2707 #[test]
2708 fn goto_alter_materialized_view() {
2709 assert_snapshot!(goto("
2710create materialized view mv as select 1 as id;
2711alter materialized view mv$0 rename to mv2;
2712"), @"
2713 ╭▸
2714 2 │ create materialized view mv as select 1 as id;
2715 │ ── 2. destination
2716 3 │ alter materialized view mv rename to mv2;
2717 ╰╴ ─ 1. source
2718 ");
2719 }
2720
2721 #[test]
2722 fn goto_alter_type() {
2723 assert_snapshot!(goto("
2724create type address as (city text);
2725alter type address$0 add attribute zip text;
2726"), @"
2727 ╭▸
2728 2 │ create type address as (city text);
2729 │ ─────── 2. destination
2730 3 │ alter type address add attribute zip text;
2731 ╰╴ ─ 1. source
2732 ");
2733 }
2734
2735 #[test]
2736 fn goto_alter_domain() {
2737 assert_snapshot!(goto("
2738create domain email as text;
2739alter domain email$0 set not null;
2740"), @"
2741 ╭▸
2742 2 │ create domain email as text;
2743 │ ───── 2. destination
2744 3 │ alter domain email set not null;
2745 ╰╴ ─ 1. source
2746 ");
2747 }
2748
2749 #[test]
2750 fn goto_alter_function() {
2751 assert_snapshot!(goto("
2752create function f(a int) returns int language sql as $$ select a $$;
2753alter function f$0(int) owner to me;
2754"), @"
2755 ╭▸
2756 2 │ create function f(a int) returns int language sql as $$ select a $$;
2757 │ ─ 2. destination
2758 3 │ alter function f(int) owner to me;
2759 ╰╴ ─ 1. source
2760 ");
2761 }
2762
2763 #[test]
2764 fn goto_alter_procedure() {
2765 assert_snapshot!(goto("
2766create procedure p(a int) language sql as $$ select 1 $$;
2767alter procedure p$0(int) rename to q;
2768"), @"
2769 ╭▸
2770 2 │ create procedure p(a int) language sql as $$ select 1 $$;
2771 │ ─ 2. destination
2772 3 │ alter procedure p(int) rename to q;
2773 ╰╴ ─ 1. source
2774 ");
2775 }
2776
2777 #[test]
2778 fn goto_alter_routine() {
2779 assert_snapshot!(goto("
2780create function f() returns int language sql as $$ select 1 $$;
2781alter routine f$0 rename to g;
2782"), @"
2783 ╭▸
2784 2 │ create function f() returns int language sql as $$ select 1 $$;
2785 │ ─ 2. destination
2786 3 │ alter routine f rename to g;
2787 ╰╴ ─ 1. source
2788 ");
2789 }
2790
2791 #[test]
2792 fn goto_alter_aggregate() {
2793 assert_snapshot!(goto("
2794create aggregate agg (int) (sfunc = f, stype = int8);
2795alter aggregate agg$0(int) rename to agg2;
2796"), @"
2797 ╭▸
2798 2 │ create aggregate agg (int) (sfunc = f, stype = int8);
2799 │ ─── 2. destination
2800 3 │ alter aggregate agg(int) rename to agg2;
2801 ╰╴ ─ 1. source
2802 ");
2803 }
2804
2805 #[test]
2806 fn goto_alter_index() {
2807 assert_snapshot!(goto("
2808create table t(id int);
2809create index idx on t(id);
2810alter index idx$0 rename to idx2;
2811"), @"
2812 ╭▸
2813 3 │ create index idx on t(id);
2814 │ ─── 2. destination
2815 4 │ alter index idx rename to idx2;
2816 ╰╴ ─ 1. source
2817 ");
2818 }
2819
2820 #[test]
2821 fn goto_alter_schema() {
2822 assert_snapshot!(goto("
2823create schema app;
2824alter schema app$0 rename to app2;
2825"), @"
2826 ╭▸
2827 2 │ create schema app;
2828 │ ─── 2. destination
2829 3 │ alter schema app rename to app2;
2830 ╰╴ ─ 1. source
2831 ");
2832 }
2833
2834 #[test]
2835 fn goto_create_schema_element_unqualified_table_ref() {
2836 assert_snapshot!(goto("
2837create schema app
2838 create table users(id int)
2839 create view v as
2840 select id from users$0;
2841"), @"
2842 ╭▸
2843 3 │ create table users(id int)
2844 │ ───── 2. destination
2845 4 │ create view v as
2846 5 │ select id from users;
2847 ╰╴ ─ 1. source
2848 ");
2849 }
2850
2851 #[test]
2852 fn goto_create_schema_element_unqualified_column_ref() {
2853 assert_snapshot!(goto("
2854create schema app
2855 create table users(id int)
2856 create view v as
2857 select id$0 from users;
2858"), @"
2859 ╭▸
2860 3 │ create table users(id int)
2861 │ ── 2. destination
2862 4 │ create view v as
2863 5 │ select id from users;
2864 ╰╴ ─ 1. source
2865 ");
2866 }
2867
2868 #[test]
2869 fn goto_alter_database() {
2870 assert_snapshot!(goto("
2871create database appdb;
2872alter database appdb$0 owner to alice;
2873"), @"
2874 ╭▸
2875 2 │ create database appdb;
2876 │ ───── 2. destination
2877 3 │ alter database appdb owner to alice;
2878 ╰╴ ─ 1. source
2879 ");
2880 }
2881
2882 #[test]
2883 fn goto_alter_tablespace() {
2884 assert_snapshot!(goto("
2885create tablespace fast location '/tmp/fast';
2886alter tablespace fast$0 rename to faster;
2887"), @"
2888 ╭▸
2889 2 │ create tablespace fast location '/tmp/fast';
2890 │ ──── 2. destination
2891 3 │ alter tablespace fast rename to faster;
2892 ╰╴ ─ 1. source
2893 ");
2894 }
2895
2896 #[test]
2897 fn goto_alter_trigger() {
2898 assert_snapshot!(goto("
2899create trigger trg before insert on t for each row execute function f();
2900alter trigger trg$0 on t rename to trg2;
2901"), @"
2902 ╭▸
2903 2 │ create trigger trg before insert on t for each row execute function f();
2904 │ ─── 2. destination
2905 3 │ alter trigger trg on t rename to trg2;
2906 ╰╴ ─ 1. source
2907 ");
2908 }
2909
2910 #[test]
2911 fn goto_alter_foreign_table() {
2912 assert_snapshot!(goto("
2913create foreign table ft(id int) server myserver;
2914alter foreign table ft$0 owner to alice;
2915"), @"
2916 ╭▸
2917 2 │ create foreign table ft(id int) server myserver;
2918 │ ── 2. destination
2919 3 │ alter foreign table ft owner to alice;
2920 ╰╴ ─ 1. source
2921 ");
2922 }
2923
2924 #[test]
2925 fn goto_extension_definition_returns_self() {
2926 assert_snapshot!(goto("
2927create extension my$0ext;
2928"), @r"
2929 ╭▸
2930 2 │ create extension myext;
2931 │ ┬┬───
2932 │ ││
2933 │ │1. source
2934 ╰╴ 2. destination
2935 ");
2936 }
2937
2938 #[test]
2939 fn goto_drop_sequence_with_schema() {
2940 assert_snapshot!(goto("
2941create sequence foo.s;
2942drop sequence foo.s$0;
2943"), @r"
2944 ╭▸
2945 2 │ create sequence foo.s;
2946 │ ─ 2. destination
2947 3 │ drop sequence foo.s;
2948 ╰╴ ─ 1. source
2949 ");
2950 }
2951
2952 #[test]
2953 fn goto_drop_table_with_schema() {
2954 assert_snapshot!(goto("
2955create table public.t();
2956drop table t$0;
2957"), @r"
2958 ╭▸
2959 2 │ create table public.t();
2960 │ ─ 2. destination
2961 3 │ drop table t;
2962 ╰╴ ─ 1. source
2963 ");
2964
2965 assert_snapshot!(goto("
2966create table foo.t();
2967drop table foo.t$0;
2968"), @r"
2969 ╭▸
2970 2 │ create table foo.t();
2971 │ ─ 2. destination
2972 3 │ drop table foo.t;
2973 ╰╴ ─ 1. source
2974 ");
2975
2976 goto_not_found(
2977 "
2978-- defaults to public schema
2979create table t();
2980drop table foo.t$0;
2981",
2982 );
2983 }
2984
2985 #[test]
2986 fn goto_drop_temp_table() {
2987 assert_snapshot!(goto("
2988create temp table t();
2989drop table t$0;
2990"), @r"
2991 ╭▸
2992 2 │ create temp table t();
2993 │ ─ 2. destination
2994 3 │ drop table t;
2995 ╰╴ ─ 1. source
2996 ");
2997 }
2998
2999 #[test]
3000 fn goto_drop_temporary_table() {
3001 assert_snapshot!(goto("
3002create temporary table t();
3003drop table t$0;
3004"), @r"
3005 ╭▸
3006 2 │ create temporary table t();
3007 │ ─ 2. destination
3008 3 │ drop table t;
3009 ╰╴ ─ 1. source
3010 ");
3011 }
3012
3013 #[test]
3014 fn goto_drop_temp_table_with_pg_temp_schema() {
3015 assert_snapshot!(goto("
3016create temp table t();
3017drop table pg_temp.t$0;
3018"), @r"
3019 ╭▸
3020 2 │ create temp table t();
3021 │ ─ 2. destination
3022 3 │ drop table pg_temp.t;
3023 ╰╴ ─ 1. source
3024 ");
3025 }
3026
3027 #[test]
3028 fn goto_table_definition_returns_self() {
3029 assert_snapshot!(goto("
3030create table t$0(x bigint, y bigint);
3031"), @r"
3032 ╭▸
3033 2 │ create table t(x bigint, y bigint);
3034 │ ┬
3035 │ │
3036 │ 2. destination
3037 ╰╴ 1. source
3038 ");
3039 }
3040
3041 #[test]
3042 fn goto_foreign_table_column() {
3043 assert_snapshot!(goto("
3044create foreign table ft(a int)
3045 server s;
3046
3047select a$0 from ft;
3048"), @r"
3049 ╭▸
3050 2 │ create foreign table ft(a int)
3051 │ ─ 2. destination
3052 ‡
3053 5 │ select a from ft;
3054 ╰╴ ─ 1. source
3055 ");
3056 }
3057
3058 #[test]
3059 fn goto_foreign_table_definition() {
3060 assert_snapshot!(goto("
3061create foreign table ft(a int)
3062 server s;
3063
3064select a from ft$0;
3065"), @r"
3066 ╭▸
3067 2 │ create foreign table ft(a int)
3068 │ ── 2. destination
3069 ‡
3070 5 │ select a from ft;
3071 ╰╴ ─ 1. source
3072 ");
3073 }
3074
3075 #[test]
3076 fn goto_foreign_table_server_name() {
3077 assert_snapshot!(goto("
3078create server myserver foreign data wrapper fdw;
3079create foreign table ft(a int)
3080 server my$0server;
3081"), @r"
3082 ╭▸
3083 2 │ create server myserver foreign data wrapper fdw;
3084 │ ──────── 2. destination
3085 3 │ create foreign table ft(a int)
3086 4 │ server myserver;
3087 ╰╴ ─ 1. source
3088 ");
3089 }
3090
3091 #[test]
3092 fn goto_foreign_table_server_name_defined_after() {
3093 assert_snapshot!(goto("
3094create foreign table ft(a int)
3095 server my$0server;
3096create server myserver foreign data wrapper fdw;
3097"), @r"
3098 ╭▸
3099 3 │ server myserver;
3100 │ ─ 1. source
3101 4 │ create server myserver foreign data wrapper fdw;
3102 ╰╴ ──────── 2. destination
3103 ");
3104 }
3105
3106 #[test]
3107 fn goto_user_mapping_server_name() {
3108 assert_snapshot!(goto("
3109create server myserver foreign data wrapper fdw;
3110create user mapping for current_user server my$0server;
3111"), @r"
3112 ╭▸
3113 2 │ create server myserver foreign data wrapper fdw;
3114 │ ──────── 2. destination
3115 3 │ create user mapping for current_user server myserver;
3116 ╰╴ ─ 1. source
3117 ");
3118 }
3119
3120 #[test]
3121 fn goto_foreign_key_references_table() {
3122 assert_snapshot!(goto("
3123create table foo(id int);
3124create table bar(
3125 id int,
3126 foo_id int,
3127 foreign key (foo_id) references foo$0(id)
3128);
3129"), @r"
3130 ╭▸
3131 2 │ create table foo(id int);
3132 │ ─── 2. destination
3133 ‡
3134 6 │ foreign key (foo_id) references foo(id)
3135 ╰╴ ─ 1. source
3136 ");
3137 }
3138
3139 #[test]
3140 fn goto_foreign_key_on_delete_set_null_column() {
3141 assert_snapshot!(goto("
3142create table users (
3143 user_id integer not null,
3144 primary key (user_id)
3145);
3146
3147create table posts (
3148 post_id integer not null,
3149 author_id integer,
3150 primary key (post_id),
3151 foreign key (author_id) references users on delete set null (author_id$0)
3152);
3153"), @r"
3154 ╭▸
3155 9 │ author_id integer,
3156 │ ───────── 2. destination
3157 10 │ primary key (post_id),
3158 11 │ foreign key (author_id) references users on delete set null (author_id)
3159 ╰╴ ─ 1. source
3160 ");
3161 }
3162
3163 #[test]
3164 fn goto_references_constraint_table() {
3165 assert_snapshot!(goto("
3166create table t (
3167 id serial primary key
3168);
3169
3170create table u (
3171 id serial primary key,
3172 t_id int references t$0
3173);
3174"), @r"
3175 ╭▸
3176 2 │ create table t (
3177 │ ─ 2. destination
3178 ‡
3179 8 │ t_id int references t
3180 ╰╴ ─ 1. source
3181 ");
3182 }
3183
3184 #[test]
3185 fn goto_references_constraint_column() {
3186 assert_snapshot!(goto("
3187create table t (
3188 id serial primary key
3189);
3190
3191create table u (
3192 id serial primary key,
3193 t_id int references t(id$0)
3194);
3195"), @r"
3196 ╭▸
3197 3 │ id serial primary key
3198 │ ── 2. destination
3199 ‡
3200 8 │ t_id int references t(id)
3201 ╰╴ ─ 1. source
3202 ");
3203 }
3204
3205 #[test]
3206 fn goto_foreign_key_references_column() {
3207 assert_snapshot!(goto("
3208create table foo(id int);
3209create table bar(
3210 id int,
3211 foo_id int,
3212 foreign key (foo_id) references foo(id$0)
3213);
3214"), @r"
3215 ╭▸
3216 2 │ create table foo(id int);
3217 │ ── 2. destination
3218 ‡
3219 6 │ foreign key (foo_id) references foo(id)
3220 ╰╴ ─ 1. source
3221 ");
3222 }
3223
3224 #[test]
3225 fn goto_foreign_key_local_column() {
3226 assert_snapshot!(goto("
3227create table bar(
3228 id int,
3229 foo_id int,
3230 foreign key (foo_id$0) references foo(id)
3231);
3232"), @r"
3233 ╭▸
3234 4 │ foo_id int,
3235 │ ────── 2. destination
3236 5 │ foreign key (foo_id) references foo(id)
3237 ╰╴ ─ 1. source
3238 ");
3239 }
3240
3241 #[test]
3242 fn goto_alter_table_foreign_key_local_column() {
3243 assert_snapshot!(goto("
3244create table t (
3245 id bigserial primary key
3246);
3247
3248create table u (
3249 id bigserial primary key,
3250 t_id bigint
3251);
3252
3253alter table u
3254 add constraint fooo_fkey
3255 foreign key (t_id$0) references t (id);
3256"), @r"
3257 ╭▸
3258 8 │ t_id bigint
3259 │ ──── 2. destination
3260 ‡
3261 13 │ foreign key (t_id) references t (id);
3262 ╰╴ ─ 1. source
3263 ");
3264 }
3265
3266 #[test]
3267 fn goto_check_constraint_column() {
3268 assert_snapshot!(goto("
3269create table t (
3270 b int check (b > 10),
3271 c int check (c$0 > 10) no inherit
3272);
3273"), @r"
3274 ╭▸
3275 4 │ c int check (c > 10) no inherit
3276 │ ┬ ─ 1. source
3277 │ │
3278 ╰╴ 2. destination
3279 ");
3280 }
3281
3282 #[test]
3283 fn goto_generated_column() {
3284 assert_snapshot!(goto("
3285create table t (
3286 a int,
3287 b int generated always as (
3288 a$0 * 2
3289 ) stored
3290);
3291"), @r"
3292 ╭▸
3293 3 │ a int,
3294 │ ─ 2. destination
3295 4 │ b int generated always as (
3296 5 │ a * 2
3297 ╰╴ ─ 1. source
3298 ");
3299 }
3300
3301 #[test]
3302 fn goto_generated_column_function_call() {
3303 assert_snapshot!(goto("
3304create function pg_catalog.lower(text) returns text
3305 language internal;
3306
3307create table articles (
3308 id serial primary key,
3309 title text not null,
3310 body text not null,
3311 title_lower text generated always as (
3312 lower$0(title)
3313 ) stored
3314);
3315"), @r"
3316 ╭▸
3317 2 │ create function pg_catalog.lower(text) returns text
3318 │ ───── 2. destination
3319 ‡
3320 10 │ lower(title)
3321 ╰╴ ─ 1. source
3322 ");
3323 }
3324
3325 #[test]
3326 fn goto_index_expr_function_call() {
3327 assert_snapshot!(goto("
3328create function lower(text) returns text language internal;
3329create table articles (
3330 id serial primary key,
3331 title text not null
3332);
3333create index on articles (lower$0(title));
3334"), @r"
3335 ╭▸
3336 2 │ create function lower(text) returns text language internal;
3337 │ ───── 2. destination
3338 ‡
3339 7 │ create index on articles (lower(title));
3340 ╰╴ ─ 1. source
3341 ");
3342 }
3343
3344 #[test]
3345 fn goto_exclude_constraint_expr_function_call() {
3346 assert_snapshot!(goto("
3347create function lower(text) returns text language internal;
3348create table articles (
3349 title text not null,
3350 exclude using btree (lower$0(title) with =)
3351);
3352"), @r"
3353 ╭▸
3354 2 │ create function lower(text) returns text language internal;
3355 │ ───── 2. destination
3356 ‡
3357 5 │ exclude using btree (lower(title) with =)
3358 ╰╴ ─ 1. source
3359 ");
3360 }
3361
3362 #[test]
3363 fn goto_partition_by_expr_function_call() {
3364 assert_snapshot!(goto("
3365create function lower(text) returns text language internal;
3366create table articles (
3367 id serial primary key,
3368 title text not null
3369) partition by range (lower$0(title));
3370"), @r"
3371 ╭▸
3372 2 │ create function lower(text) returns text language internal;
3373 │ ───── 2. destination
3374 ‡
3375 6 │ ) partition by range (lower(title));
3376 ╰╴ ─ 1. source
3377 ");
3378 }
3379
3380 #[test]
3381 fn goto_table_check_constraint_column() {
3382 assert_snapshot!(goto("
3383create table t (
3384 a int,
3385 b text,
3386 check (a$0 > b)
3387);
3388"), @r"
3389 ╭▸
3390 3 │ a int,
3391 │ ─ 2. destination
3392 4 │ b text,
3393 5 │ check (a > b)
3394 ╰╴ ─ 1. source
3395 ");
3396 }
3397
3398 #[test]
3399 fn goto_table_unique_constraint_column() {
3400 assert_snapshot!(goto("
3401create table t (
3402 a int,
3403 b text,
3404 unique (a$0)
3405);
3406"), @r"
3407 ╭▸
3408 3 │ a int,
3409 │ ─ 2. destination
3410 4 │ b text,
3411 5 │ unique (a)
3412 ╰╴ ─ 1. source
3413 ");
3414 }
3415
3416 #[test]
3417 fn goto_table_primary_key_constraint_column() {
3418 assert_snapshot!(goto("
3419create table t (
3420 id bigint generated always as identity,
3421 inserted_at timestamptz not null default now(),
3422 primary key (id, inserted_at$0)
3423);
3424"), @r"
3425 ╭▸
3426 4 │ inserted_at timestamptz not null default now(),
3427 │ ─────────── 2. destination
3428 5 │ primary key (id, inserted_at)
3429 ╰╴ ─ 1. source
3430 ");
3431 }
3432
3433 #[test]
3434 fn goto_table_not_null_constraint_column() {
3435 assert_snapshot!(goto("
3436create table t (
3437 id integer,
3438 name text,
3439 not null name$0
3440);
3441"), @r"
3442 ╭▸
3443 4 │ name text,
3444 │ ──── 2. destination
3445 5 │ not null name
3446 ╰╴ ─ 1. source
3447 ");
3448 }
3449
3450 #[test]
3451 fn goto_table_exclude_constraint_column() {
3452 assert_snapshot!(goto("
3453create table circles (
3454 c circle,
3455 exclude using gist (c$0 with &&)
3456);
3457"), @r"
3458 ╭▸
3459 3 │ c circle,
3460 │ ─ 2. destination
3461 4 │ exclude using gist (c with &&)
3462 ╰╴ ─ 1. source
3463 ");
3464 }
3465
3466 #[test]
3467 fn goto_table_exclude_constraint_include_column() {
3468 assert_snapshot!(goto("
3469create table t (
3470 a int,
3471 b text,
3472 exclude using btree ( a with > )
3473 include (a$0, b)
3474);
3475"), @r"
3476 ╭▸
3477 3 │ a int,
3478 │ ─ 2. destination
3479 ‡
3480 6 │ include (a, b)
3481 ╰╴ ─ 1. source
3482 ");
3483 }
3484
3485 #[test]
3486 fn goto_table_exclude_constraint_where_column() {
3487 assert_snapshot!(goto("
3488create table t (
3489 a int,
3490 b text,
3491 exclude using btree ( a with > )
3492 where ( a$0 > 10 and b like '%foo' )
3493);
3494"), @r"
3495 ╭▸
3496 3 │ a int,
3497 │ ─ 2. destination
3498 ‡
3499 6 │ where ( a > 10 and b like '%foo' )
3500 ╰╴ ─ 1. source
3501 ");
3502 }
3503
3504 #[test]
3505 fn goto_table_partition_by_column() {
3506 assert_snapshot!(goto("
3507create table t (
3508 id bigint generated always as identity,
3509 inserted_at timestamptz not null default now()
3510) partition by range (inserted_at$0);
3511"), @r"
3512 ╭▸
3513 4 │ inserted_at timestamptz not null default now()
3514 │ ─────────── 2. destination
3515 5 │ ) partition by range (inserted_at);
3516 ╰╴ ─ 1. source
3517 ");
3518 }
3519
3520 #[test]
3521 fn goto_table_partition_of_table() {
3522 assert_snapshot!(goto("
3523create table t ();
3524create table t_2026_01_02 partition of t$0
3525 for values from ('2026-01-02') to ('2026-01-03');
3526"), @r"
3527 ╭▸
3528 2 │ create table t ();
3529 │ ─ 2. destination
3530 3 │ create table t_2026_01_02 partition of t
3531 ╰╴ ─ 1. source
3532 ");
3533 }
3534
3535 #[test]
3536 fn goto_table_partition_of_cycle() {
3537 goto_not_found(
3538 "
3539create table part1 partition of part2
3540 for values from ('2026-01-02') to ('2026-01-03');
3541create table part2 partition of part1
3542 for values from ('2026-01-02') to ('2026-01-03');
3543select a$0 from part2;
3544",
3545 );
3546 }
3547
3548 #[test]
3549 fn goto_partition_table_column() {
3550 assert_snapshot!(goto("
3551create table part (
3552 a int,
3553 inserted_at timestamptz not null default now()
3554) partition by range (inserted_at);
3555create table part_2026_01_02 partition of part
3556 for values from ('2026-01-02') to ('2026-01-03');
3557select a$0 from part_2026_01_02;
3558"), @r"
3559 ╭▸
3560 3 │ a int,
3561 │ ─ 2. destination
3562 ‡
3563 8 │ select a from part_2026_01_02;
3564 ╰╴ ─ 1. source
3565 ");
3566 }
3567
3568 #[test]
3569 fn goto_partition_table_qualified_column() {
3570 assert_snapshot!(goto("
3571create table part (
3572 a int,
3573 inserted_at timestamptz not null default now()
3574) partition by range (inserted_at);
3575create table part_2026_01_02 partition of part
3576 for values from ('2026-01-02') to ('2026-01-03');
3577select part_2026_01_02.a$0 from part_2026_01_02;
3578"), @"
3579 ╭▸
3580 3 │ a int,
3581 │ ─ 2. destination
3582 ‡
3583 8 │ select part_2026_01_02.a from part_2026_01_02;
3584 ╰╴ ─ 1. source
3585 ");
3586 }
3587
3588 #[test]
3589 fn goto_partition_table_qualified_column_multi_level() {
3590 assert_snapshot!(goto("
3591create table p (a int) partition by list (a);
3592create table m partition of p for values in (1) partition by list (a);
3593create table c partition of m for values in (2);
3594select c.a$0 from c;
3595"), @"
3596 ╭▸
3597 2 │ create table p (a int) partition by list (a);
3598 │ ─ 2. destination
3599 ‡
3600 5 │ select c.a from c;
3601 ╰╴ ─ 1. source
3602 ");
3603 }
3604
3605 #[test]
3606 fn goto_alter_index_attach_partition() {
3607 assert_snapshot!(goto("
3608create table t (
3609 inserted_at timestamptz not null default now()
3610) partition by range (inserted_at);
3611create table part partition of t
3612 for values from ('2026-01-02') to ('2026-01-03');
3613create index parent_idx on t (inserted_at);
3614create index child_idx on part (inserted_at);
3615alter index parent_idx attach partition child_$0idx;
3616"), @"
3617 ╭▸
3618 8 │ create index child_idx on part (inserted_at);
3619 │ ───────── 2. destination
3620 9 │ alter index parent_idx attach partition child_idx;
3621 ╰╴ ─ 1. source
3622 ");
3623 }
3624
3625 #[test]
3626 fn goto_create_table_like_clause() {
3627 assert_snapshot!(goto("
3628create table large_data_table(a text);
3629create table t (
3630 a text,
3631 like large_data_table$0,
3632 b integer
3633);
3634"), @r"
3635 ╭▸
3636 2 │ create table large_data_table(a text);
3637 │ ──────────────── 2. destination
3638 ‡
3639 5 │ like large_data_table,
3640 ╰╴ ─ 1. source
3641 ");
3642 }
3643
3644 #[test]
3645 fn goto_create_table_like_view() {
3646 assert_snapshot!(goto("
3647create view v as select 1 a, 2 b;
3648create table t (like v);
3649select a$0 from t;
3650"), @"
3651 ╭▸
3652 2 │ create view v as select 1 a, 2 b;
3653 │ ─ 2. destination
3654 3 │ create table t (like v);
3655 4 │ select a from t;
3656 ╰╴ ─ 1. source
3657 ");
3658 }
3659
3660 #[test]
3661 fn goto_view_select_star_column_gap() {
3662 assert_snapshot!(goto("
3663create table t(a int, b int);
3664create view v as select * from t;
3665select a$0 from v;
3666"), @"
3667 ╭▸
3668 2 │ create table t(a int, b int);
3669 │ ─ 2. destination
3670 3 │ create view v as select * from t;
3671 4 │ select a from v;
3672 ╰╴ ─ 1. source
3673 ");
3674 }
3675
3676 #[test]
3677 fn goto_view_table_query_column_gap() {
3678 assert_snapshot!(goto("
3679create table t(a int);
3680create view v as table t;
3681select a$0 from v;
3682"), @"
3683 ╭▸
3684 2 │ create table t(a int);
3685 │ ─ 2. destination
3686 3 │ create view v as table t;
3687 4 │ select a from v;
3688 ╰╴ ─ 1. source
3689 ");
3690 }
3691
3692 #[test]
3693 fn goto_view_values_query_column_gap() {
3694 assert_snapshot!(goto("
3695create view v as values (1, 2);
3696select column2$0 from v;
3697"), @"
3698 ╭▸
3699 2 │ create view v as values (1, 2);
3700 │ ─ 2. destination
3701 3 │ select column2 from v;
3702 ╰╴ ─ 1. source
3703 ");
3704 }
3705
3706 #[test]
3707 fn goto_view_compound_table_query_column() {
3708 assert_snapshot!(goto("
3709create table t(a int);
3710create view v as table t union table t;
3711select a$0 from v;
3712"), @"
3713 ╭▸
3714 2 │ create table t(a int);
3715 │ ─ 2. destination
3716 3 │ create view v as table t union table t;
3717 4 │ select a from v;
3718 ╰╴ ─ 1. source
3719 ");
3720 }
3721
3722 #[test]
3723 fn goto_view_compound_values_query_column() {
3724 assert_snapshot!(goto("
3725create view v as values (1, 2) union values (3, 4);
3726select column2$0 from v;
3727"), @"
3728 ╭▸
3729 2 │ create view v as values (1, 2) union values (3, 4);
3730 │ ─ 2. destination
3731 3 │ select column2 from v;
3732 ╰╴ ─ 1. source
3733 ");
3734 }
3735
3736 #[test]
3737 fn goto_view_table_query_column_count_gap() {
3738 assert_snapshot!(goto("
3739create table t(a int, b int);
3740create view v as table t;
3741select b$0 from (select * from v) u(a);
3742"), @"
3743 ╭▸
3744 2 │ create table t(a int, b int);
3745 │ ─ 2. destination
3746 3 │ create view v as table t;
3747 4 │ select b from (select * from v) u(a);
3748 ╰╴ ─ 1. source
3749 ");
3750 }
3751
3752 #[test]
3753 fn goto_view_values_query_column_count_gap() {
3754 assert_snapshot!(goto("
3755create view v as values (1, 2);
3756select column2$0 from (select * from v) u(a);
3757"), @"
3758 ╭▸
3759 2 │ create view v as values (1, 2);
3760 │ ─ 2. destination
3761 3 │ select column2 from (select * from v) u(a);
3762 ╰╴ ─ 1. source
3763 ");
3764 }
3765
3766 #[test]
3767 fn goto_values_partial_alias_remaining_column_gap() {
3768 assert_snapshot!(goto("
3769select column2$0 from (values (1, 2)) v(a);
3770"), @"
3771 ╭▸
3772 2 │ select column2 from (values (1, 2)) v(a);
3773 ╰╴ ─ 1. source ─ 2. destination
3774 ");
3775 }
3776
3777 #[test]
3778 fn goto_create_table_inherits() {
3779 assert_snapshot!(goto("
3780create table bar(a int);
3781create table t (a int)
3782inherits (foo.bar, bar$0, buzz);
3783"), @r"
3784 ╭▸
3785 2 │ create table bar(a int);
3786 │ ─── 2. destination
3787 3 │ create table t (a int)
3788 4 │ inherits (foo.bar, bar, buzz);
3789 ╰╴ ─ 1. source
3790 ");
3791 }
3792
3793 #[test]
3794 fn goto_create_table_inherits_builtin() {
3795 assert_snapshot!(goto("
3796-- include-builtins
3797create table t ()
3798inherits (information_schema.sql_features);
3799select feature_name$0 from t;
3800"), @"
3801 ╭▸ current.sql:5:19
3802 │
3803 5 │ select feature_name from t;
3804 │ ─ 1. source
3805 ╰╴
3806
3807 ╭▸ builtins.sql:437:3
3808 │
3809 437 │ feature_name information_schema.character_data,
3810 ╰╴ ──────────── 2. destination
3811 ");
3812 }
3813
3814 #[test]
3815 fn goto_create_table_like_clause_columns() {
3816 assert_snapshot!(goto("
3817create table t(a int, b int);
3818create table u(like t, c int);
3819select a$0, c from u;
3820"), @r"
3821 ╭▸
3822 2 │ create table t(a int, b int);
3823 │ ─ 2. destination
3824 3 │ create table u(like t, c int);
3825 4 │ select a, c from u;
3826 ╰╴ ─ 1. source
3827 ");
3828 }
3829
3830 #[test]
3831 fn goto_create_table_like_clause_local_column() {
3832 assert_snapshot!(goto("
3833create table t(a int, b int);
3834create table u(like t, c int);
3835select a, c$0 from u;
3836"), @r"
3837 ╭▸
3838 3 │ create table u(like t, c int);
3839 │ ─ 2. destination
3840 4 │ select a, c from u;
3841 ╰╴ ─ 1. source
3842 ");
3843 }
3844
3845 #[test]
3846 fn goto_create_table_like_clause_multi() {
3847 assert_snapshot!(goto("
3848create table t(a int, b int);
3849create table u(x int, y int);
3850create table k(like t, like u, c int);
3851select y$0 from k;
3852"), @r"
3853 ╭▸
3854 3 │ create table u(x int, y int);
3855 │ ─ 2. destination
3856 4 │ create table k(like t, like u, c int);
3857 5 │ select y from k;
3858 ╰╴ ─ 1. source
3859 ");
3860 }
3861
3862 #[test]
3863 fn goto_create_table_inherits_column() {
3864 assert_snapshot!(goto("
3865create table t (
3866 a int, b text
3867);
3868create table u (
3869 c int
3870) inherits (t);
3871select a$0 from u;
3872"), @r"
3873 ╭▸
3874 3 │ a int, b text
3875 │ ─ 2. destination
3876 ‡
3877 8 │ select a from u;
3878 ╰╴ ─ 1. source
3879 ");
3880 }
3881
3882 #[test]
3883 fn goto_create_table_inherits_local_column() {
3884 assert_snapshot!(goto("
3885create table t (
3886 a int, b text
3887);
3888create table u (
3889 c int
3890) inherits (t);
3891select c$0 from u;
3892"), @r"
3893 ╭▸
3894 6 │ c int
3895 │ ─ 2. destination
3896 7 │ ) inherits (t);
3897 8 │ select c from u;
3898 ╰╴ ─ 1. source
3899 ");
3900 }
3901
3902 #[test]
3903 fn goto_create_table_inherits_multiple_parents() {
3904 assert_snapshot!(goto("
3905create table t1 (
3906 a int
3907);
3908create table t2 (
3909 b text
3910);
3911create table u (
3912 c int
3913) inherits (t1, t2);
3914select b$0 from u;
3915"), @r"
3916 ╭▸
3917 6 │ b text
3918 │ ─ 2. destination
3919 ‡
3920 11 │ select b from u;
3921 ╰╴ ─ 1. source
3922 ");
3923 }
3924
3925 #[test]
3926 fn goto_create_foreign_table_inherits_column() {
3927 assert_snapshot!(goto("
3928create server myserver foreign data wrapper postgres_fdw;
3929create table t (
3930 a int, b text
3931);
3932create foreign table u (
3933 c int
3934) inherits (t) server myserver;
3935select a$0 from u;
3936"), @r"
3937 ╭▸
3938 4 │ a int, b text
3939 │ ─ 2. destination
3940 ‡
3941 9 │ select a from u;
3942 ╰╴ ─ 1. source
3943 ");
3944 }
3945
3946 #[test]
3947 fn goto_drop_temp_table_shadows_public() {
3948 assert_snapshot!(goto("
3950create table t();
3951create temp table t();
3952drop table t$0;
3953"), @"
3954 ╭▸
3955 3 │ create temp table t();
3956 │ ─ 2. destination
3957 4 │ drop table t;
3958 ╰╴ ─ 1. source
3959 ");
3960 }
3961
3962 #[test]
3963 fn goto_drop_public_table_when_temp_exists() {
3964 assert_snapshot!(goto("
3966create table t();
3967create temp table t();
3968drop table public.t$0;
3969"), @r"
3970 ╭▸
3971 2 │ create table t();
3972 │ ─ 2. destination
3973 3 │ create temp table t();
3974 4 │ drop table public.t;
3975 ╰╴ ─ 1. source
3976 ");
3977 }
3978
3979 #[test]
3980 fn goto_drop_table_defined_after() {
3981 assert_snapshot!(goto("
3982drop table t$0;
3983create table t();
3984"), @r"
3985 ╭▸
3986 2 │ drop table t;
3987 │ ─ 1. source
3988 3 │ create table t();
3989 ╰╴ ─ 2. destination
3990 ");
3991 }
3992
3993 #[test]
3994 fn goto_drop_type() {
3995 assert_snapshot!(goto("
3996create type t as enum ('a', 'b');
3997drop type t$0;
3998"), @r"
3999 ╭▸
4000 2 │ create type t as enum ('a', 'b');
4001 │ ─ 2. destination
4002 3 │ drop type t;
4003 ╰╴ ─ 1. source
4004 ");
4005 }
4006
4007 #[test]
4008 fn goto_drop_type_with_schema() {
4009 assert_snapshot!(goto("
4010create type public.t as enum ('a', 'b');
4011drop type t$0;
4012"), @r"
4013 ╭▸
4014 2 │ create type public.t as enum ('a', 'b');
4015 │ ─ 2. destination
4016 3 │ drop type t;
4017 ╰╴ ─ 1. source
4018 ");
4019
4020 assert_snapshot!(goto("
4021create type foo.t as enum ('a', 'b');
4022drop type foo.t$0;
4023"), @r"
4024 ╭▸
4025 2 │ create type foo.t as enum ('a', 'b');
4026 │ ─ 2. destination
4027 3 │ drop type foo.t;
4028 ╰╴ ─ 1. source
4029 ");
4030
4031 goto_not_found(
4032 "
4033create type t as enum ('a', 'b');
4034drop type foo.t$0;
4035",
4036 );
4037 }
4038
4039 #[test]
4040 fn goto_drop_type_defined_after() {
4041 assert_snapshot!(goto("
4042drop type t$0;
4043create type t as enum ('a', 'b');
4044"), @r"
4045 ╭▸
4046 2 │ drop type t;
4047 │ ─ 1. source
4048 3 │ create type t as enum ('a', 'b');
4049 ╰╴ ─ 2. destination
4050 ");
4051 }
4052
4053 #[test]
4054 fn goto_drop_type_composite() {
4055 assert_snapshot!(goto("
4056create type person as (name text, age int);
4057drop type person$0;
4058"), @r"
4059 ╭▸
4060 2 │ create type person as (name text, age int);
4061 │ ────── 2. destination
4062 3 │ drop type person;
4063 ╰╴ ─ 1. source
4064 ");
4065 }
4066
4067 #[test]
4068 fn goto_create_table_type_reference() {
4069 assert_snapshot!(goto("
4070create type person_info as (name text, email text);
4071create table users(id int, member person_info$0);
4072"), @"
4073 ╭▸
4074 2 │ create type person_info as (name text, email text);
4075 │ ─────────── 2. destination
4076 3 │ create table users(id int, member person_info);
4077 ╰╴ ─ 1. source
4078 ");
4079 }
4080
4081 #[test]
4082 fn goto_function_param_table_type() {
4083 assert_snapshot!(goto("
4084create table t(a int, b int);
4085create function b(t$0) returns int as 'select 1' language sql;
4086"), @r"
4087 ╭▸
4088 2 │ create table t(a int, b int);
4089 │ ─ 2. destination
4090 3 │ create function b(t) returns int as 'select 1' language sql;
4091 ╰╴ ─ 1. source
4092 ");
4093 }
4094
4095 #[test]
4096 fn goto_function_param_time_type() {
4097 assert_snapshot!(goto("
4098create type timestamp;
4099create function f(timestamp$0 without time zone) returns text language internal;
4100"), @r"
4101 ╭▸
4102 2 │ create type timestamp;
4103 │ ───────── 2. destination
4104 3 │ create function f(timestamp without time zone) returns text language internal;
4105 ╰╴ ─ 1. source
4106 ");
4107 }
4108
4109 #[test]
4110 fn goto_function_param_time_type_no_timezone() {
4111 assert_snapshot!(goto("
4112create type time;
4113create function f(time$0) returns text language internal;
4114"), @r"
4115 ╭▸
41162 │ create type time;
4117 │ ──── 2. destination
41183 │ create function f(time) returns text language internal;
4119 ╰╴ ─ 1. source
4120");
4121 }
4122
4123 #[test]
4124 fn goto_create_table_type_reference_enum() {
4125 assert_snapshot!(goto("
4126create type mood as enum ('sad', 'ok', 'happy');
4127create table users(id int, mood mood$0);
4128"), @r"
4129 ╭▸
4130 2 │ create type mood as enum ('sad', 'ok', 'happy');
4131 │ ──── 2. destination
4132 3 │ create table users(id int, mood mood);
4133 ╰╴ ─ 1. source
4134 ");
4135 }
4136
4137 #[test]
4138 fn goto_create_table_type_reference_range() {
4139 assert_snapshot!(goto("
4140create type int4_range as range (subtype = int4);
4141create table metrics(id int, span int4_range$0);
4142"), @r"
4143 ╭▸
4144 2 │ create type int4_range as range (subtype = int4);
4145 │ ────────── 2. destination
4146 3 │ create table metrics(id int, span int4_range);
4147 ╰╴ ─ 1. source
4148 ");
4149 }
4150
4151 #[test]
4152 fn goto_create_table_type_reference_input_output() {
4153 assert_snapshot!(goto("
4154create type myint (input = myintin, output = myintout, like = int4);
4155create table data(id int, value myint$0);
4156"), @r"
4157 ╭▸
4158 2 │ create type myint (input = myintin, output = myintout, like = int4);
4159 │ ───── 2. destination
4160 3 │ create table data(id int, value myint);
4161 ╰╴ ─ 1. source
4162 ");
4163 }
4164
4165 #[test]
4166 fn goto_composite_type_field() {
4167 assert_snapshot!(goto("
4168create type person_info as (name text, email text);
4169create table users(id int, member person_info);
4170select (member).name$0 from users;
4171"), @"
4172 ╭▸
4173 2 │ create type person_info as (name text, email text);
4174 │ ──── 2. destination
4175 3 │ create table users(id int, member person_info);
4176 4 │ select (member).name from users;
4177 ╰╴ ─ 1. source
4178 ");
4179 }
4180
4181 #[test]
4182 fn goto_alter_type_drop_attribute() {
4183 assert_snapshot!(goto("
4184create type address as (city text, zip text);
4185alter type address drop attribute city$0;
4186"), @"
4187 ╭▸
4188 2 │ create type address as (city text, zip text);
4189 │ ──── 2. destination
4190 3 │ alter type address drop attribute city;
4191 ╰╴ ─ 1. source
4192 ");
4193 }
4194
4195 #[test]
4196 fn goto_alter_type_rename_attribute() {
4197 assert_snapshot!(goto("
4198create type address as (city text, zip text);
4199alter type address rename attribute city$0 to town;
4200"), @"
4201 ╭▸
4202 2 │ create type address as (city text, zip text);
4203 │ ──── 2. destination
4204 3 │ alter type address rename attribute city to town;
4205 ╰╴ ─ 1. source
4206 ");
4207 }
4208
4209 #[test]
4210 fn goto_alter_type_alter_attribute() {
4211 assert_snapshot!(goto("
4212create type address as (city text, zip text);
4213alter type address alter attribute city$0 set data type varchar;
4214"), @"
4215 ╭▸
4216 2 │ create type address as (city text, zip text);
4217 │ ──── 2. destination
4218 3 │ alter type address alter attribute city set data type varchar;
4219 ╰╴ ─ 1. source
4220 ");
4221 }
4222
4223 #[test]
4224 fn goto_drop_type_range() {
4225 assert_snapshot!(goto("
4226create type int4_range as range (subtype = int4);
4227drop type int4_range$0;
4228"), @r"
4229 ╭▸
4230 2 │ create type int4_range as range (subtype = int4);
4231 │ ────────── 2. destination
4232 3 │ drop type int4_range;
4233 ╰╴ ─ 1. source
4234 ");
4235 }
4236
4237 #[test]
4238 fn goto_drop_domain() {
4239 assert_snapshot!(goto("
4240create domain posint as integer check (value > 0);
4241drop domain posint$0;
4242"), @r"
4243 ╭▸
4244 2 │ create domain posint as integer check (value > 0);
4245 │ ────── 2. destination
4246 3 │ drop domain posint;
4247 ╰╴ ─ 1. source
4248 ");
4249 }
4250
4251 #[test]
4252 fn goto_cast_to_domain() {
4253 assert_snapshot!(goto("
4254create domain posint as integer check (value > 0);
4255select 1::posint$0;
4256"), @r"
4257 ╭▸
4258 2 │ create domain posint as integer check (value > 0);
4259 │ ────── 2. destination
4260 3 │ select 1::posint;
4261 ╰╴ ─ 1. source
4262 ");
4263 }
4264
4265 #[test]
4266 fn goto_drop_type_domain() {
4267 assert_snapshot!(goto("
4268create domain posint as integer check (value > 0);
4269drop type posint$0;
4270"), @r"
4271 ╭▸
4272 2 │ create domain posint as integer check (value > 0);
4273 │ ────── 2. destination
4274 3 │ drop type posint;
4275 ╰╴ ─ 1. source
4276 ");
4277 }
4278
4279 #[test]
4280 fn goto_drop_view() {
4281 assert_snapshot!(goto("
4282create view v as select 1;
4283drop view v$0;
4284"), @r"
4285 ╭▸
4286 2 │ create view v as select 1;
4287 │ ─ 2. destination
4288 3 │ drop view v;
4289 ╰╴ ─ 1. source
4290 ");
4291 }
4292
4293 #[test]
4294 fn goto_drop_materialized_view() {
4295 assert_snapshot!(goto("
4296create materialized view v as select 1;
4297drop materialized view v$0;
4298"), @r"
4299 ╭▸
4300 2 │ create materialized view v as select 1;
4301 │ ─ 2. destination
4302 3 │ drop materialized view v;
4303 ╰╴ ─ 1. source
4304 ");
4305 }
4306
4307 #[test]
4308 fn goto_drop_view_with_schema() {
4309 assert_snapshot!(goto("
4310create view public.v as select 1;
4311drop view v$0;
4312"), @r"
4313 ╭▸
4314 2 │ create view public.v as select 1;
4315 │ ─ 2. destination
4316 3 │ drop view v;
4317 ╰╴ ─ 1. source
4318 ");
4319
4320 assert_snapshot!(goto("
4321create view foo.v as select 1;
4322drop view foo.v$0;
4323"), @r"
4324 ╭▸
4325 2 │ create view foo.v as select 1;
4326 │ ─ 2. destination
4327 3 │ drop view foo.v;
4328 ╰╴ ─ 1. source
4329 ");
4330
4331 goto_not_found(
4332 "
4333create view v as select 1;
4334drop view foo.v$0;
4335",
4336 );
4337 }
4338
4339 #[test]
4340 fn goto_drop_temp_view() {
4341 assert_snapshot!(goto("
4342create temp view v as select 1;
4343drop view v$0;
4344"), @r"
4345 ╭▸
4346 2 │ create temp view v as select 1;
4347 │ ─ 2. destination
4348 3 │ drop view v;
4349 ╰╴ ─ 1. source
4350 ");
4351 }
4352
4353 #[test]
4354 fn goto_select_from_view() {
4355 assert_snapshot!(goto("
4356create view v as select 1;
4357select * from v$0;
4358"), @r"
4359 ╭▸
4360 2 │ create view v as select 1;
4361 │ ─ 2. destination
4362 3 │ select * from v;
4363 ╰╴ ─ 1. source
4364 ");
4365 }
4366
4367 #[test]
4368 fn goto_select_from_materialized_view() {
4369 assert_snapshot!(goto("
4370create materialized view v as select 1;
4371select * from v$0;
4372"), @r"
4373 ╭▸
4374 2 │ create materialized view v as select 1;
4375 │ ─ 2. destination
4376 3 │ select * from v;
4377 ╰╴ ─ 1. source
4378 ");
4379 }
4380
4381 #[test]
4382 fn goto_select_from_view_with_schema() {
4383 assert_snapshot!(goto("
4384create view public.v as select 1;
4385select * from public.v$0;
4386"), @r"
4387 ╭▸
4388 2 │ create view public.v as select 1;
4389 │ ─ 2. destination
4390 3 │ select * from public.v;
4391 ╰╴ ─ 1. source
4392 ");
4393 }
4394
4395 #[test]
4396 fn goto_view_column() {
4397 assert_snapshot!(goto("
4398create view v as select 1 as a;
4399select a$0 from v;
4400"), @r"
4401 ╭▸
4402 2 │ create view v as select 1 as a;
4403 │ ─ 2. destination
4404 3 │ select a from v;
4405 ╰╴ ─ 1. source
4406 ");
4407 }
4408
4409 #[test]
4410 fn goto_view_column_qualified() {
4411 assert_snapshot!(goto("
4412create view v as select 1 as a;
4413select v.a$0 from v;
4414"), @r"
4415 ╭▸
4416 2 │ create view v as select 1 as a;
4417 │ ─ 2. destination
4418 3 │ select v.a from v;
4419 ╰╴ ─ 1. source
4420 ");
4421 }
4422
4423 #[test]
4424 fn goto_materialized_view_column_with_explicit_column_list() {
4425 assert_snapshot!(goto("
4426create materialized view mv (x, y) as select 1 as a, 2 as b;
4427select x$0 from mv;
4428"), @r"
4429 ╭▸
4430 2 │ create materialized view mv (x, y) as select 1 as a, 2 as b;
4431 │ ─ 2. destination
4432 3 │ select x from mv;
4433 ╰╴ ─ 1. source
4434 ");
4435 }
4436
4437 #[test]
4438 fn goto_view_table_qualifier() {
4439 assert_snapshot!(goto("
4440create view v as select 1 id, 2 b;
4441select v$0.id from v;
4442"), @"
4443 ╭▸
4444 2 │ create view v as select 1 id, 2 b;
4445 │ ─ 2. destination
4446 3 │ select v.id from v;
4447 ╰╴ ─ 1. source
4448 ");
4449 }
4450
4451 #[test]
4452 fn goto_select_into_column() {
4453 assert_snapshot!(goto("
4454select 1 a into t;
4455select a$0 from t;
4456"), @"
4457 ╭▸
4458 2 │ select 1 a into t;
4459 │ ─ 2. destination
4460 3 │ select a from t;
4461 ╰╴ ─ 1. source
4462 ");
4463 }
4464
4465 #[test]
4466 fn goto_select_into_table() {
4467 assert_snapshot!(goto("
4468select 1 a into t;
4469select a from t$0;
4470"), @"
4471 ╭▸
4472 2 │ select 1 a into t;
4473 │ ─ 2. destination
4474 3 │ select a from t;
4475 ╰╴ ─ 1. source
4476 ");
4477 }
4478
4479 #[test]
4480 fn goto_select_into_select_star() {
4481 assert_snapshot!(goto("
4482create table t(a bigint);
4483select * into u from t;
4484select a$0 from u;
4485"), @"
4486 ╭▸
4487 2 │ create table t(a bigint);
4488 │ ─ 2. destination
4489 3 │ select * into u from t;
4490 4 │ select a from u;
4491 ╰╴ ─ 1. source
4492 ");
4493 }
4494
4495 #[test]
4496 fn goto_select_into_source_table() {
4497 assert_snapshot!(goto("
4498create table t(a int);
4499select a into u from t$0;
4500"), @"
4501 ╭▸
4502 2 │ create table t(a int);
4503 │ ─ 2. destination
4504 3 │ select a into u from t;
4505 ╰╴ ─ 1. source
4506 ");
4507 }
4508
4509 #[test]
4510 fn goto_select_into_target_list_column() {
4511 assert_snapshot!(goto("
4512create table t(a int);
4513select a$0 into u from t;
4514"), @"
4515 ╭▸
4516 2 │ create table t(a int);
4517 │ ─ 2. destination
4518 3 │ select a into u from t;
4519 ╰╴ ─ 1. source
4520 ");
4521 }
4522
4523 #[test]
4524 fn goto_select_into_where_column() {
4525 assert_snapshot!(goto("
4526create table t(a int);
4527select a into u from t where a$0 > 0;
4528"), @"
4529 ╭▸
4530 2 │ create table t(a int);
4531 │ ─ 2. destination
4532 3 │ select a into u from t where a > 0;
4533 ╰╴ ─ 1. source
4534 ");
4535 }
4536
4537 #[test]
4538 fn goto_select_into_qualified_column() {
4539 assert_snapshot!(goto("
4540create table t(a int);
4541select t.a$0 into u from t;
4542"), @"
4543 ╭▸
4544 2 │ create table t(a int);
4545 │ ─ 2. destination
4546 3 │ select t.a into u from t;
4547 ╰╴ ─ 1. source
4548 ");
4549 }
4550
4551 #[test]
4552 fn goto_create_table_as_column() {
4553 assert_snapshot!(goto("
4554create table t as select 1 a;
4555select a$0 from t;
4556"), @r"
4557 ╭▸
4558 2 │ create table t as select 1 a;
4559 │ ─ 2. destination
4560 3 │ select a from t;
4561 ╰╴ ─ 1. source
4562 ");
4563 }
4564
4565 #[test]
4566 fn goto_create_table_as_table() {
4567 assert_snapshot!(goto("
4568create table t(a bigint);
4569create table u as table t;
4570select a$0 from u;
4571"), @"
4572 ╭▸
4573 2 │ create table t(a bigint);
4574 │ ─ 2. destination
4575 3 │ create table u as table t;
4576 4 │ select a from u;
4577 ╰╴ ─ 1. source
4578 ");
4579 }
4580
4581 #[test]
4582 fn goto_create_table_as_select_star() {
4583 assert_snapshot!(goto("
4584create table t(a bigint);
4585create table u as select * from t;
4586select a$0 from u;
4587"), @"
4588 ╭▸
4589 2 │ create table t(a bigint);
4590 │ ─ 2. destination
4591 3 │ create table u as select * from t;
4592 4 │ select a from u;
4593 ╰╴ ─ 1. source
4594 ");
4595 }
4596
4597 #[test]
4598 fn goto_create_table_as_values() {
4599 assert_snapshot!(goto("
4600create table k as values (1, 2);
4601select column1$0 from k;
4602"), @"
4603 ╭▸
4604 2 │ create table k as values (1, 2);
4605 │ ─ 2. destination
4606 3 │ select column1 from k;
4607 ╰╴ ─ 1. source
4608 ");
4609 }
4610
4611 #[test]
4612 fn goto_create_table_as_compound_table_query_column() {
4613 assert_snapshot!(goto("
4614create table t(a int);
4615create table u as table t union table t;
4616select a$0 from u;
4617"), @"
4618 ╭▸
4619 2 │ create table t(a int);
4620 │ ─ 2. destination
4621 3 │ create table u as table t union table t;
4622 4 │ select a from u;
4623 ╰╴ ─ 1. source
4624 ");
4625 }
4626
4627 #[test]
4628 fn goto_create_table_as_compound_values_query_column() {
4629 assert_snapshot!(goto("
4630create table u as values (1, 2) union values (3, 4);
4631select column2$0 from u;
4632"), @"
4633 ╭▸
4634 2 │ create table u as values (1, 2) union values (3, 4);
4635 │ ─ 2. destination
4636 3 │ select column2 from u;
4637 ╰╴ ─ 1. source
4638 ");
4639 }
4640
4641 #[test]
4642 fn goto_create_table_as_paren_table_query_column() {
4643 assert_snapshot!(goto("
4644create table t(a int);
4645create table u as (table t);
4646select a$0 from u;
4647"), @"
4648 ╭▸
4649 2 │ create table t(a int);
4650 │ ─ 2. destination
4651 3 │ create table u as (table t);
4652 4 │ select a from u;
4653 ╰╴ ─ 1. source
4654 ");
4655 }
4656
4657 #[test]
4658 fn goto_create_table_as_paren_values_query_column() {
4659 assert_snapshot!(goto("
4660create table u as (values (1, 2));
4661select column2$0 from u;
4662"), @"
4663 ╭▸
4664 2 │ create table u as (values (1, 2));
4665 │ ─ 2. destination
4666 3 │ select column2 from u;
4667 ╰╴ ─ 1. source
4668 ");
4669 }
4670
4671 #[test]
4672 fn goto_create_table_as_values_column_count_gap() {
4673 assert_snapshot!(goto("
4674create table u as values (1, 2);
4675select column2$0 from (select * from u) x(a);
4676"), @"
4677 ╭▸
4678 2 │ create table u as values (1, 2);
4679 │ ─ 2. destination
4680 3 │ select column2 from (select * from u) x(a);
4681 ╰╴ ─ 1. source
4682 ");
4683 }
4684
4685 #[test]
4686 fn goto_select_from_create_table_as() {
4687 assert_snapshot!(goto("
4688create table t as select 1 a;
4689select a from t$0;
4690"), @r"
4691 ╭▸
4692 2 │ create table t as select 1 a;
4693 │ ─ 2. destination
4694 3 │ select a from t;
4695 ╰╴ ─ 1. source
4696 ");
4697 }
4698
4699 #[test]
4700 fn goto_like_view_definition() {
4701 assert_snapshot!(goto("
4702create view v as select 1 a;
4703create table t (like v$0);
4704"), @"
4705 ╭▸
4706 2 │ create view v as select 1 a;
4707 │ ─ 2. destination
4708 3 │ create table t (like v);
4709 ╰╴ ─ 1. source
4710 ");
4711 }
4712
4713 #[test]
4714 fn goto_view_with_explicit_column_list() {
4715 assert_snapshot!(goto("
4716create view v(col1) as select 1;
4717select * from v$0;
4718"), @r"
4719 ╭▸
4720 2 │ create view v(col1) as select 1;
4721 │ ─ 2. destination
4722 3 │ select * from v;
4723 ╰╴ ─ 1. source
4724 ");
4725 }
4726
4727 #[test]
4728 fn goto_view_column_with_explicit_column_list() {
4729 assert_snapshot!(goto("
4730 create view v(col1) as select 1;
4731 select col1$0 from v;
4732 "), @r"
4733 ╭▸
4734 2 │ create view v(col1) as select 1;
4735 │ ──── 2. destination
4736 3 │ select col1 from v;
4737 ╰╴ ─ 1. source
4738 ");
4739 }
4740
4741 #[test]
4742 fn goto_create_table_as_with_explicit_column_list() {
4743 assert_snapshot!(goto("
4744create table t (a int);
4745create table t2 (x) as select a from t;
4746select x$0 from t2;
4747"), @"
4748 ╭▸
4749 3 │ create table t2 (x) as select a from t;
4750 │ ─ 2. destination
4751 4 │ select x from t2;
4752 ╰╴ ─ 1. source
4753 ");
4754 }
4755
4756 #[test]
4757 fn goto_create_table_as_explicit_column_list_shorter_than_select() {
4758 assert_snapshot!(goto("
4759create table t2 (x) as select 1 a, 2 b;
4760select b$0 from t2;
4761"), @"
4762 ╭▸
4763 2 │ create table t2 (x) as select 1 a, 2 b;
4764 │ ─ 2. destination
4765 3 │ select b from t2;
4766 ╰╴ ─ 1. source
4767 ");
4768 }
4769
4770 #[test]
4771 fn goto_create_table_as_explicit_column_list_shadows_select_column() {
4772 goto_not_found(
4773 "
4774create table t (a int);
4775create table t2 (x) as select a from t;
4776select a$0 from t2;
4777",
4778 );
4779 }
4780
4781 #[test]
4782 fn goto_view_column_with_schema() {
4783 assert_snapshot!(goto("
4784create view public.v as select 1 as a;
4785select a$0 from public.v;
4786"), @r"
4787 ╭▸
4788 2 │ create view public.v as select 1 as a;
4789 │ ─ 2. destination
4790 3 │ select a from public.v;
4791 ╰╴ ─ 1. source
4792 ");
4793 }
4794
4795 #[test]
4796 fn goto_view_multiple_columns() {
4797 assert_snapshot!(goto("
4798create view v as select 1 as a, 2 as b;
4799select b$0 from v;
4800"), @r"
4801 ╭▸
4802 2 │ create view v as select 1 as a, 2 as b;
4803 │ ─ 2. destination
4804 3 │ select b from v;
4805 ╰╴ ─ 1. source
4806 ");
4807 }
4808
4809 #[test]
4810 fn goto_view_column_from_table() {
4811 assert_snapshot!(goto("
4812create table t(x int, y int);
4813create view v as select x, y from t;
4814select x$0 from v;
4815"), @r"
4816 ╭▸
4817 3 │ create view v as select x, y from t;
4818 │ ─ 2. destination
4819 4 │ select x from v;
4820 ╰╴ ─ 1. source
4821 ");
4822 }
4823
4824 #[test]
4825 fn goto_view_column_with_table_preference() {
4826 assert_snapshot!(goto("
4827create table v(a int);
4828create view vw as select 1 as a;
4829select a$0 from v;
4830"), @r"
4831 ╭▸
4832 2 │ create table v(a int);
4833 │ ─ 2. destination
4834 3 │ create view vw as select 1 as a;
4835 4 │ select a from v;
4836 ╰╴ ─ 1. source
4837 ");
4838 }
4839
4840 #[test]
4841 fn goto_cast_operator() {
4842 assert_snapshot!(goto("
4843create type foo as enum ('a', 'b');
4844select x::foo$0;
4845"), @r"
4846 ╭▸
4847 2 │ create type foo as enum ('a', 'b');
4848 │ ─── 2. destination
4849 3 │ select x::foo;
4850 ╰╴ ─ 1. source
4851 ");
4852 }
4853
4854 #[test]
4855 fn goto_cast_function() {
4856 assert_snapshot!(goto("
4857create type bar as enum ('x', 'y');
4858select cast(x as bar$0);
4859"), @r"
4860 ╭▸
4861 2 │ create type bar as enum ('x', 'y');
4862 │ ─── 2. destination
4863 3 │ select cast(x as bar);
4864 ╰╴ ─ 1. source
4865 ");
4866 }
4867
4868 #[test]
4869 fn goto_cast_with_schema() {
4870 assert_snapshot!(goto("
4871create type public.baz as enum ('m', 'n');
4872select x::public.baz$0;
4873"), @r"
4874 ╭▸
4875 2 │ create type public.baz as enum ('m', 'n');
4876 │ ─── 2. destination
4877 3 │ select x::public.baz;
4878 ╰╴ ─ 1. source
4879 ");
4880 }
4881
4882 #[test]
4883 fn goto_cast_timestamp_without_time_zone() {
4884 assert_snapshot!(goto("
4885create type pg_catalog.timestamp;
4886select ''::timestamp without$0 time zone;
4887"), @r"
4888 ╭▸
4889 2 │ create type pg_catalog.timestamp;
4890 │ ───────── 2. destination
4891 3 │ select ''::timestamp without time zone;
4892 ╰╴ ─ 1. source
4893 ");
4894 }
4895
4896 #[test]
4897 fn goto_cast_timestamp_with_time_zone() {
4898 assert_snapshot!(goto("
4899create type pg_catalog.timestamptz;
4900select ''::timestamp with$0 time zone;
4901"), @r"
4902 ╭▸
4903 2 │ create type pg_catalog.timestamptz;
4904 │ ─────────── 2. destination
4905 3 │ select ''::timestamp with time zone;
4906 ╰╴ ─ 1. source
4907 ");
4908 }
4909
4910 #[test]
4911 fn goto_cast_multirange_type_from_range() {
4912 assert_snapshot!(goto("
4913create type floatrange as range (
4914 subtype = float8,
4915 subtype_diff = float8mi
4916);
4917select '{[1.234, 5.678]}'::floatmultirange$0;
4918"), @r"
4919 ╭▸
4920 2 │ create type floatrange as range (
4921 │ ────────── 2. destination
4922 ‡
4923 6 │ select '{[1.234, 5.678]}'::floatmultirange;
4924 ╰╴ ─ 1. source
4925 ");
4926 }
4927
4928 #[test]
4929 fn goto_cast_multirange_special_type_name_string() {
4930 assert_snapshot!(goto("
4931create type floatrange as range (
4932 subtype = float8,
4933 subtype_diff = float8mi,
4934 multirange_type_name = 'floatmulirangething'
4935);
4936select '{[1.234, 5.678]}'::floatmulirangething$0;
4937"), @r"
4938 ╭▸
4939 2 │ create type floatrange as range (
4940 │ ────────── 2. destination
4941 ‡
4942 7 │ select '{[1.234, 5.678]}'::floatmulirangething;
4943 ╰╴ ─ 1. source
4944 ");
4945 }
4946
4947 #[test]
4948 fn goto_cast_multirange_special_type_name_ident() {
4949 assert_snapshot!(goto("
4950create type floatrange as range (
4951 subtype = float8,
4952 subtype_diff = float8mi,
4953 multirange_type_name = floatrangemutirange
4954);
4955select '{[1.234, 5.678]}'::floatrangemutirange$0;
4956"), @r"
4957 ╭▸
4958 2 │ create type floatrange as range (
4959 │ ────────── 2. destination
4960 ‡
4961 7 │ select '{[1.234, 5.678]}'::floatrangemutirange;
4962 ╰╴ ─ 1. source
4963 ");
4964 }
4965
4966 #[test]
4967 fn goto_cast_multirange_edge_case_type_from_range() {
4968 assert_snapshot!(goto("
4970create type floatrangerange as range (
4971 subtype = float8,
4972 subtype_diff = float8mi
4973);
4974select '{[1.234, 5.678]}'::floatmultirangerange$0;
4975"), @r"
4976 ╭▸
4977 2 │ create type floatrangerange as range (
4978 │ ─────────────── 2. destination
4979 ‡
4980 6 │ select '{[1.234, 5.678]}'::floatmultirangerange;
4981 ╰╴ ─ 1. source
4982 ");
4983 }
4984
4985 #[test]
4986 fn goto_cast_boolean_falls_back_to_bool() {
4987 assert_snapshot!(goto("
4988create type pg_catalog.bool;
4989select '1'::boolean$0;
4990"), @"
4991 ╭▸
4992 2 │ create type pg_catalog.bool;
4993 │ ──── 2. destination
4994 3 │ select '1'::boolean;
4995 ╰╴ ─ 1. source
4996 ");
4997 }
4998
4999 #[test]
5000 fn goto_cast_decimal_falls_back_to_numeric() {
5001 assert_snapshot!(goto("
5002create type pg_catalog.numeric;
5003select 1::decimal$0(10, 2);
5004"), @"
5005 ╭▸
5006 2 │ create type pg_catalog.numeric;
5007 │ ─────── 2. destination
5008 3 │ select 1::decimal(10, 2);
5009 ╰╴ ─ 1. source
5010 ");
5011 }
5012
5013 #[test]
5014 fn goto_cast_float_falls_back_to_float8() {
5015 assert_snapshot!(goto("
5016create type pg_catalog.float8;
5017select 1::float$0;
5018"), @"
5019 ╭▸
5020 2 │ create type pg_catalog.float8;
5021 │ ────── 2. destination
5022 3 │ select 1::float;
5023 ╰╴ ─ 1. source
5024 ");
5025 }
5026
5027 #[test]
5028 fn goto_cast_bigint_falls_back_to_int8() {
5029 assert_snapshot!(goto("
5030create type pg_catalog.int8;
5031select 1::bigint$0;
5032"), @r"
5033 ╭▸
5034 2 │ create type pg_catalog.int8;
5035 │ ──── 2. destination
5036 3 │ select 1::bigint;
5037 ╰╴ ─ 1. source
5038 ");
5039 }
5040
5041 #[test]
5042 fn goto_cast_real_falls_back_to_float4() {
5043 assert_snapshot!(goto("
5044create type pg_catalog.float4;
5045select 1::real$0;
5046"), @"
5047 ╭▸
5048 2 │ create type pg_catalog.float4;
5049 │ ────── 2. destination
5050 3 │ select 1::real;
5051 ╰╴ ─ 1. source
5052 ");
5053 }
5054
5055 #[test]
5056 fn goto_cast_bigint_prefers_user_type() {
5057 assert_snapshot!(goto("
5058create type bigint;
5059create type pg_catalog.int8;
5060select 1::bigint$0;
5061"), @r"
5062 ╭▸
5063 2 │ create type bigint;
5064 │ ────── 2. destination
5065 3 │ create type pg_catalog.int8;
5066 4 │ select 1::bigint;
5067 ╰╴ ─ 1. source
5068 ");
5069 }
5070
5071 #[test]
5072 fn goto_cast_smallserial_falls_back_to_int2() {
5073 assert_snapshot!(goto("
5074create type pg_catalog.int2;
5075select 1::smallserial$0;
5076"), @r"
5077 ╭▸
5078 2 │ create type pg_catalog.int2;
5079 │ ──── 2. destination
5080 3 │ select 1::smallserial;
5081 ╰╴ ─ 1. source
5082 ");
5083 }
5084
5085 #[test]
5086 fn goto_cast_serial2_falls_back_to_int2() {
5087 assert_snapshot!(goto("
5088create type pg_catalog.int2;
5089select 1::serial2$0;
5090"), @r"
5091 ╭▸
5092 2 │ create type pg_catalog.int2;
5093 │ ──── 2. destination
5094 3 │ select 1::serial2;
5095 ╰╴ ─ 1. source
5096 ");
5097 }
5098
5099 #[test]
5100 fn goto_cast_serial_falls_back_to_int4() {
5101 assert_snapshot!(goto("
5102create type pg_catalog.int4;
5103select 1::serial$0;
5104"), @r"
5105 ╭▸
5106 2 │ create type pg_catalog.int4;
5107 │ ──── 2. destination
5108 3 │ select 1::serial;
5109 ╰╴ ─ 1. source
5110 ");
5111 }
5112
5113 #[test]
5114 fn goto_cast_serial4_falls_back_to_int4() {
5115 assert_snapshot!(goto("
5116create type pg_catalog.int4;
5117select 1::serial4$0;
5118"), @r"
5119 ╭▸
5120 2 │ create type pg_catalog.int4;
5121 │ ──── 2. destination
5122 3 │ select 1::serial4;
5123 ╰╴ ─ 1. source
5124 ");
5125 }
5126
5127 #[test]
5128 fn goto_cast_bigserial_falls_back_to_int8() {
5129 assert_snapshot!(goto("
5130create type pg_catalog.int8;
5131select 1::bigserial$0;
5132"), @r"
5133 ╭▸
5134 2 │ create type pg_catalog.int8;
5135 │ ──── 2. destination
5136 3 │ select 1::bigserial;
5137 ╰╴ ─ 1. source
5138 ");
5139 }
5140
5141 #[test]
5142 fn goto_cast_serial8_falls_back_to_int8() {
5143 assert_snapshot!(goto("
5144create type pg_catalog.int8;
5145select 1::serial8$0;
5146"), @r"
5147 ╭▸
5148 2 │ create type pg_catalog.int8;
5149 │ ──── 2. destination
5150 3 │ select 1::serial8;
5151 ╰╴ ─ 1. source
5152 ");
5153 }
5154
5155 #[test]
5156 fn goto_cast_int_falls_back_to_int4() {
5157 assert_snapshot!(goto("
5158create type pg_catalog.int4;
5159select 1::int$0;
5160"), @r"
5161 ╭▸
5162 2 │ create type pg_catalog.int4;
5163 │ ──── 2. destination
5164 3 │ select 1::int;
5165 ╰╴ ─ 1. source
5166 ");
5167 }
5168
5169 #[test]
5170 fn goto_cast_integer_falls_back_to_int4() {
5171 assert_snapshot!(goto("
5172create type pg_catalog.int4;
5173select 1::integer$0;
5174"), @r"
5175 ╭▸
5176 2 │ create type pg_catalog.int4;
5177 │ ──── 2. destination
5178 3 │ select 1::integer;
5179 ╰╴ ─ 1. source
5180 ");
5181 }
5182
5183 #[test]
5184 fn goto_cast_smallint_falls_back_to_int2() {
5185 assert_snapshot!(goto("
5186create type pg_catalog.int2;
5187select 1::smallint$0;
5188"), @r"
5189 ╭▸
5190 2 │ create type pg_catalog.int2;
5191 │ ──── 2. destination
5192 3 │ select 1::smallint;
5193 ╰╴ ─ 1. source
5194 ");
5195 }
5196
5197 #[test]
5198 fn goto_cast_double_precision_falls_back_to_float8() {
5199 assert_snapshot!(goto("
5200create type pg_catalog.float8;
5201select '1'::double precision[]$0;
5202"), @r"
5203 ╭▸
5204 2 │ create type pg_catalog.float8;
5205 │ ────── 2. destination
5206 3 │ select '1'::double precision[];
5207 ╰╴ ─ 1. source
5208 ");
5209 }
5210
5211 #[test]
5212 fn goto_cast_varchar_with_modifier() {
5213 assert_snapshot!(goto("
5214create type pg_catalog.varchar;
5215select '1'::varchar$0(1);
5216"), @r"
5217 ╭▸
5218 2 │ create type pg_catalog.varchar;
5219 │ ─────── 2. destination
5220 3 │ select '1'::varchar(1);
5221 ╰╴ ─ 1. source
5222 ");
5223 }
5224
5225 #[test]
5226 fn goto_cast_composite_type() {
5227 assert_snapshot!(goto("
5228create type person_info as (name varchar(50), age int);
5229select ('Alice', 30)::person_info$0;
5230"), @r"
5231 ╭▸
5232 2 │ create type person_info as (name varchar(50), age int);
5233 │ ─────────── 2. destination
5234 3 │ select ('Alice', 30)::person_info;
5235 ╰╴ ─ 1. source
5236 ");
5237 }
5238
5239 #[test]
5240 fn goto_cast_composite_type_in_cte() {
5241 assert_snapshot!(goto("
5242create type person_info as (name varchar(50), age int);
5243with team as (
5244 select 1 as id, ('Alice', 30)::person_info$0 as member
5245)
5246select * from team;
5247"), @r"
5248 ╭▸
5249 2 │ create type person_info as (name varchar(50), age int);
5250 │ ─────────── 2. destination
5251 3 │ with team as (
5252 4 │ select 1 as id, ('Alice', 30)::person_info as member
5253 ╰╴ ─ 1. source
5254 ");
5255 }
5256
5257 #[test]
5258 fn goto_composite_type_field_name() {
5259 assert_snapshot!(goto("
5260create type person_info as (name varchar(50), age int);
5261with team as (
5262 select 1 as id, ('Alice', 30)::person_info as member
5263)
5264select (member).name$0, (member).age from team;
5265"), @r"
5266 ╭▸
5267 2 │ create type person_info as (name varchar(50), age int);
5268 │ ──── 2. destination
5269 ‡
5270 6 │ select (member).name, (member).age from team;
5271 ╰╴ ─ 1. source
5272 ");
5273 }
5274
5275 #[test]
5276 fn goto_composite_type_field_in_where() {
5277 assert_snapshot!(goto("
5278create type person_info as (name varchar(50), age int);
5279with team as (
5280 select 1 as id, ('Alice', 30)::person_info as member
5281 union all
5282 select 2, ('Bob', 25)::person_info
5283)
5284select (member).name, (member).age
5285from team
5286where (member).age$0 >= 18;
5287"), @r"
5288 ╭▸
5289 2 │ create type person_info as (name varchar(50), age int);
5290 │ ─── 2. destination
5291 ‡
5292 10 │ where (member).age >= 18;
5293 ╰╴ ─ 1. source
5294 ");
5295 }
5296
5297 #[test]
5298 fn goto_composite_type_field_base() {
5299 assert_snapshot!(goto("
5300create type person_info as (name varchar(50), age int);
5301with team as (
5302 select 1 as id, ('Alice', 30)::person_info as member
5303)
5304select (member$0).age from team;
5305"), @r"
5306 ╭▸
5307 4 │ select 1 as id, ('Alice', 30)::person_info as member
5308 │ ────── 2. destination
5309 5 │ )
5310 6 │ select (member).age from team;
5311 ╰╴ ─ 1. source
5312 ");
5313 }
5314
5315 #[test]
5316 fn goto_composite_type_field_nested_parens() {
5317 assert_snapshot!(goto("
5318create type person_info as (name varchar(50), age int);
5319with team as (
5320 select 1 as id, ('Alice', 30)::person_info as member
5321)
5322select ((((member))).name$0) from team;
5323"), @r"
5324 ╭▸
5325 2 │ create type person_info as (name varchar(50), age int);
5326 │ ──── 2. destination
5327 ‡
5328 6 │ select ((((member))).name) from team;
5329 ╰╴ ─ 1. source
5330 ");
5331 }
5332
5333 #[test]
5334 fn goto_whole_row_field_access() {
5335 assert_snapshot!(goto("
5336create table t (a int);
5337select (t).a$0 from t;
5338"), @"
5339 ╭▸
5340 2 │ create table t (a int);
5341 │ ─ 2. destination
5342 3 │ select (t).a from t;
5343 ╰╴ ─ 1. source
5344 ");
5345 }
5346
5347 #[test]
5348 fn begin_to_rollback() {
5349 assert_snapshot!(goto(
5350 "
5351begin$0;
5352select 1;
5353rollback;
5354commit;
5355",
5356 ), @"
5357 ╭▸
5358 2 │ begin;
5359 │ ─ 1. source
5360 3 │ select 1;
5361 4 │ rollback;
5362 ╰╴───────── 2. destination
5363 ");
5364 }
5365
5366 #[test]
5367 fn commit_to_begin() {
5368 assert_snapshot!(goto(
5369 "
5370begin;
5371select 1;
5372commit$0;
5373",
5374 ), @"
5375 ╭▸
5376 2 │ begin;
5377 │ ────── 2. destination
5378 3 │ select 1;
5379 4 │ commit;
5380 ╰╴ ─ 1. source
5381 ");
5382 }
5383
5384 #[test]
5385 fn begin_to_commit() {
5386 assert_snapshot!(goto(
5387 "
5388begin$0;
5389select 1;
5390commit;
5391",
5392 ), @"
5393 ╭▸
5394 2 │ begin;
5395 │ ─ 1. source
5396 3 │ select 1;
5397 4 │ commit;
5398 ╰╴─────── 2. destination
5399 ");
5400 }
5401
5402 #[test]
5403 fn commit_to_start_transaction() {
5404 assert_snapshot!(goto(
5405 "
5406start transaction;
5407select 1;
5408commit$0;
5409",
5410 ), @"
5411 ╭▸
5412 2 │ start transaction;
5413 │ ────────────────── 2. destination
5414 3 │ select 1;
5415 4 │ commit;
5416 ╰╴ ─ 1. source
5417 ");
5418 }
5419
5420 #[test]
5421 fn start_transaction_to_commit() {
5422 assert_snapshot!(goto(
5423 "
5424start$0 transaction;
5425select 1;
5426commit;
5427",
5428 ), @"
5429 ╭▸
5430 2 │ start transaction;
5431 │ ─ 1. source
5432 3 │ select 1;
5433 4 │ commit;
5434 ╰╴─────── 2. destination
5435 ");
5436 }
5437
5438 #[test]
5439 fn goto_with_search_path() {
5440 assert_snapshot!(goto(r#"
5441set search_path to "foo", public;
5442create table foo.t();
5443drop table t$0;
5444"#), @r"
5445 ╭▸
5446 3 │ create table foo.t();
5447 │ ─ 2. destination
5448 4 │ drop table t;
5449 ╰╴ ─ 1. source
5450 ");
5451 }
5452
5453 #[test]
5454 fn goto_with_search_path_and_unspecified_table() {
5455 assert_snapshot!(goto(r#"
5456set search_path to foo,bar;
5457create table t();
5458drop table foo.t$0;
5459"#), @r"
5460 ╭▸
5461 3 │ create table t();
5462 │ ─ 2. destination
5463 4 │ drop table foo.t;
5464 ╰╴ ─ 1. source
5465 ");
5466 }
5467
5468 #[test]
5469 fn goto_with_search_path_via_set_config() {
5470 assert_snapshot!(goto(r#"
5471select set_config('search_path', 'foo, public', false);
5472create table foo.t();
5473drop table t$0;
5474"#), @"
5475 ╭▸
5476 3 │ create table foo.t();
5477 │ ─ 2. destination
5478 4 │ drop table t;
5479 ╰╴ ─ 1. source
5480 ");
5481 }
5482
5483 #[test]
5484 fn goto_with_search_path_via_set_config_unrelated_setting() {
5485 goto_not_found(
5486 r#"
5487select set_config('work_mem', '64MB', false);
5488create table foo.t();
5489drop table t$0;
5490"#,
5491 );
5492 }
5493
5494 #[test]
5495 fn goto_with_search_path_via_set_config_user_defined_function() {
5496 goto_not_found(
5497 r#"
5498create function set_config(text, text, boolean) returns text as $$ select $2 $$ language sql;
5499select set_config('search_path', 'foo', false);
5500create table foo.t();
5501drop table t$0;
5502"#,
5503 );
5504 }
5505
5506 #[test]
5507 fn goto_with_search_path_via_set_config_user_defined_function_outside_search_path() {
5508 assert_snapshot!(goto(r#"
5509create schema other;
5510create function other.set_config(text, text, boolean) returns text as $$ select $2 $$ language sql;
5511select set_config('search_path', 'foo', false);
5512create table foo.t();
5513drop table t$0;
5514"#), @"
5515 ╭▸
5516 5 │ create table foo.t();
5517 │ ─ 2. destination
5518 6 │ drop table t;
5519 ╰╴ ─ 1. source
5520 ");
5521 }
5522
5523 #[test]
5524 fn goto_with_search_path_via_set_config_pg_catalog_qualified() {
5525 assert_snapshot!(goto(r#"
5526select pg_catalog.set_config('search_path', 'foo', false);
5527create table foo.t();
5528drop table t$0;
5529"#), @"
5530 ╭▸
5531 3 │ create table foo.t();
5532 │ ─ 2. destination
5533 4 │ drop table t;
5534 ╰╴ ─ 1. source
5535 ");
5536 }
5537
5538 #[test]
5539 fn goto_with_search_path_via_set_config_non_pg_catalog_qualified() {
5540 goto_not_found(
5541 r#"
5542select public.set_config('search_path', 'foo', false);
5543create table foo.t();
5544drop table t$0;
5545"#,
5546 );
5547 }
5548
5549 #[test]
5550 fn goto_column_not_in_cte_but_in_table() {
5551 goto_not_found(
5553 r"
5554create table t (c int);
5555with t as (select 1 a)
5556select c$0 from t;
5557",
5558 );
5559 }
5560
5561 #[test]
5562 fn goto_with_search_path_empty() {
5563 goto_not_found(
5564 r#"
5565set search_path = '';
5566create table t();
5567drop table t$0;
5568"#,
5569 );
5570 }
5571
5572 #[test]
5573 fn goto_with_search_path_like_variable() {
5574 goto_not_found(
5576 "
5577set bar.search_path to foo, public;
5578create table foo.t();
5579drop table t$0;
5580",
5581 )
5582 }
5583
5584 #[test]
5585 fn goto_with_search_path_second_schema() {
5586 assert_snapshot!(goto("
5587set search_path to foo, bar, public;
5588create table bar.t();
5589drop table t$0;
5590"), @r"
5591 ╭▸
5592 3 │ create table bar.t();
5593 │ ─ 2. destination
5594 4 │ drop table t;
5595 ╰╴ ─ 1. source
5596 ");
5597 }
5598
5599 #[test]
5600 fn goto_with_search_path_skips_first() {
5601 assert_snapshot!(goto("
5602set search_path to foo, bar, public;
5603create table foo.t();
5604create table bar.t();
5605drop table t$0;
5606"), @r"
5607 ╭▸
5608 3 │ create table foo.t();
5609 │ ─ 2. destination
5610 4 │ create table bar.t();
5611 5 │ drop table t;
5612 ╰╴ ─ 1. source
5613 ");
5614 }
5615
5616 #[test]
5617 fn goto_without_search_path_uses_default() {
5618 assert_snapshot!(goto("
5619create table foo.t();
5620create table public.t();
5621drop table t$0;
5622"), @r"
5623 ╭▸
5624 3 │ create table public.t();
5625 │ ─ 2. destination
5626 4 │ drop table t;
5627 ╰╴ ─ 1. source
5628 ");
5629 }
5630
5631 #[test]
5632 fn goto_with_set_schema() {
5633 assert_snapshot!(goto("
5634set schema 'myschema';
5635create table myschema.t();
5636drop table t$0;
5637"), @r"
5638 ╭▸
5639 3 │ create table myschema.t();
5640 │ ─ 2. destination
5641 4 │ drop table t;
5642 ╰╴ ─ 1. source
5643 ");
5644 }
5645
5646 #[test]
5647 fn goto_with_set_schema_ignores_other_schemas() {
5648 assert_snapshot!(goto("
5649set schema 'myschema';
5650create table public.t();
5651create table myschema.t();
5652drop table t$0;
5653"), @r"
5654 ╭▸
5655 4 │ create table myschema.t();
5656 │ ─ 2. destination
5657 5 │ drop table t;
5658 ╰╴ ─ 1. source
5659 ");
5660 }
5661
5662 #[test]
5663 fn goto_search_path_schema_name() {
5664 assert_snapshot!(goto("
5665create schema app;
5666set search_path to app$0;
5667"), @"
5668 ╭▸
5669 2 │ create schema app;
5670 │ ─── 2. destination
5671 3 │ set search_path to app;
5672 ╰╴ ─ 1. source
5673 ");
5674 }
5675
5676 #[test]
5677 fn goto_search_path_schema_name_quoted() {
5678 assert_snapshot!(goto(r#"
5679create schema app;
5680set search_path to "app$0";
5681"#), @r#"
5682 ╭▸
5683 2 │ create schema app;
5684 │ ─── 2. destination
5685 3 │ set search_path to "app";
5686 ╰╴ ─ 1. source
5687 "#);
5688 }
5689
5690 #[test]
5691 fn goto_search_path_schema_name_string_literal() {
5692 assert_snapshot!(goto(r#"
5693create schema app;
5694set search_path to 'app$0';
5695"#), @"
5696 ╭▸
5697 2 │ create schema app;
5698 │ ─── 2. destination
5699 3 │ set search_path to 'app';
5700 ╰╴ ─ 1. source
5701 ");
5702 }
5703
5704 #[test]
5705 fn goto_search_path_schema_name_second_item() {
5706 assert_snapshot!(goto("
5707create schema app;
5708set search_path to public, app$0;
5709"), @"
5710 ╭▸
5711 2 │ create schema app;
5712 │ ─── 2. destination
5713 3 │ set search_path to public, app;
5714 ╰╴ ─ 1. source
5715 ");
5716 }
5717
5718 #[test]
5719 fn goto_search_path_schema_name_not_the_param_name() {
5720 goto_not_found(
5721 "
5722create schema search_path;
5723set search_path$0 to app;
5724",
5725 );
5726 }
5727
5728 #[test]
5729 fn goto_alter_role_set_search_path() {
5730 assert_snapshot!(goto("
5731create schema app;
5732create role app;
5733create role r;
5734alter role r set search_path = app$0;
5735"), @"
5736 ╭▸
5737 2 │ create schema app;
5738 │ ─── 2. destination
5739 ‡
5740 5 │ alter role r set search_path = app;
5741 ╰╴ ─ 1. source
5742 ");
5743 }
5744
5745 #[test]
5746 fn goto_alter_database_set_search_path() {
5747 assert_snapshot!(goto("
5748create schema app;
5749alter database d set search_path = app$0;
5750"), @"
5751 ╭▸
5752 2 │ create schema app;
5753 │ ─── 2. destination
5754 3 │ alter database d set search_path = app;
5755 ╰╴ ─ 1. source
5756 ");
5757 }
5758
5759 #[test]
5760 fn goto_create_function_set_search_path() {
5761 assert_snapshot!(goto("
5762create schema app;
5763create function f() returns int language sql as $$ select 1 $$ set search_path = app$0;
5764"), @"
5765 ╭▸
5766 2 │ create schema app;
5767 │ ─── 2. destination
5768 3 │ create function f() returns int language sql as $$ select 1 $$ set search_path = app;
5769 ╰╴ ─ 1. source
5770 ");
5771 }
5772
5773 #[test]
5774 fn goto_function_own_set_search_path_resolves_body_call() {
5775 assert_snapshot!(goto("
5776create schema bar;
5777create function bar.foo() returns int language sql begin atomic select 1; end;
5778create function caller() returns int language sql set search_path = bar begin atomic select foo$0(); end;
5779"), @"
5780 ╭▸
5781 3 │ create function bar.foo() returns int language sql begin atomic select 1; end;
5782 │ ─── 2. destination
5783 4 │ create function caller() returns int language sql set search_path = bar begin atomic select foo(); end;
5784 ╰╴ ─ 1. source
5785 ");
5786 }
5787
5788 #[test]
5789 fn goto_function_own_set_search_path_does_not_leak_after_body() {
5790 assert_snapshot!(goto("
5791create schema bar;
5792create table bar.t(id int);
5793create table public.t(id int);
5794create function caller() returns int language sql set search_path = bar begin atomic select 1; end;
5795select * from t$0;
5796"), @"
5797 ╭▸
5798 4 │ create table public.t(id int);
5799 │ ─ 2. destination
5800 5 │ create function caller() returns int language sql set search_path = bar begin atomic select 1; end;
5801 6 │ select * from t;
5802 ╰╴ ─ 1. source
5803 ");
5804 }
5805
5806 #[test]
5807 fn goto_function_set_search_path_from_current_resolves_body_call() {
5808 assert_snapshot!(goto("
5809create schema app;
5810create function app.target() returns int language sql return 1;
5811set search_path to app;
5812create function caller() returns int language sql set search_path from current begin atomic select tar$0get(); end;
5813"), @"
5814 ╭▸
5815 3 │ create function app.target() returns int language sql return 1;
5816 │ ────── 2. destination
5817 4 │ set search_path to app;
5818 5 │ create function caller() returns int language sql set search_path from current begin atomic select target(); end;
5819 ╰╴ ─ 1. source
5820 ");
5821 }
5822
5823 #[test]
5824 fn goto_procedure_own_set_search_path_resolves_body_call() {
5825 assert_snapshot!(goto("
5826create schema bar;
5827create function bar.foo() returns int language sql begin atomic select 1; end;
5828create procedure caller() language sql set search_path = bar begin atomic select foo$0(); end;
5829"), @"
5830 ╭▸
5831 3 │ create function bar.foo() returns int language sql begin atomic select 1; end;
5832 │ ─── 2. destination
5833 4 │ create procedure caller() language sql set search_path = bar begin atomic select foo(); end;
5834 ╰╴ ─ 1. source
5835 ");
5836 }
5837
5838 #[test]
5839 fn goto_alter_function_set_search_path() {
5840 assert_snapshot!(goto("
5841create schema app;
5842create function f() returns int language sql as $$ select 1 $$;
5843alter function f() set search_path = app$0;
5844"), @"
5845 ╭▸
5846 2 │ create schema app;
5847 │ ─── 2. destination
5848 3 │ create function f() returns int language sql as $$ select 1 $$;
5849 4 │ alter function f() set search_path = app;
5850 ╰╴ ─ 1. source
5851 ");
5852 }
5853
5854 #[test]
5855 fn goto_set_schema_literal() {
5856 assert_snapshot!(goto("
5857create schema app;
5858set schema 'app$0';
5859"), @"
5860 ╭▸
5861 2 │ create schema app;
5862 │ ─── 2. destination
5863 3 │ set schema 'app';
5864 ╰╴ ─ 1. source
5865 ");
5866 }
5867
5868 #[test]
5869 fn goto_with_search_path_changed_twice() {
5870 assert_snapshot!(goto("
5871set search_path to foo;
5872create table foo.t();
5873set search_path to bar;
5874create table bar.t();
5875drop table t$0;
5876"), @r"
5877 ╭▸
5878 5 │ create table bar.t();
5879 │ ─ 2. destination
5880 6 │ drop table t;
5881 ╰╴ ─ 1. source
5882 ");
5883
5884 assert_snapshot!(goto("
5885set search_path to foo;
5886create table foo.t();
5887drop table t$0;
5888set search_path to bar;
5889create table bar.t();
5890drop table t;
5891"), @r"
5892 ╭▸
5893 3 │ create table foo.t();
5894 │ ─ 2. destination
5895 4 │ drop table t;
5896 ╰╴ ─ 1. source
5897 ");
5898 }
5899
5900 #[test]
5901 fn goto_with_empty_search_path() {
5902 goto_not_found(
5903 "
5904set search_path to '';
5905create table public.t();
5906drop table t$0;
5907",
5908 )
5909 }
5910
5911 #[test]
5912 fn goto_with_search_path_uppercase() {
5913 assert_snapshot!(goto("
5914SET SEARCH_PATH TO foo;
5915create table foo.t();
5916drop table t$0;
5917"), @r"
5918 ╭▸
5919 3 │ create table foo.t();
5920 │ ─ 2. destination
5921 4 │ drop table t;
5922 ╰╴ ─ 1. source
5923 ");
5924 }
5925
5926 #[test]
5927 fn goto_table_stmt() {
5928 assert_snapshot!(goto("
5929create table t();
5930table t$0;
5931"), @r"
5932 ╭▸
5933 2 │ create table t();
5934 │ ─ 2. destination
5935 3 │ table t;
5936 ╰╴ ─ 1. source
5937 ");
5938 }
5939
5940 #[test]
5941 fn goto_table_stmt_with_schema() {
5942 assert_snapshot!(goto("
5943create table public.t();
5944table public.t$0;
5945"), @r"
5946 ╭▸
5947 2 │ create table public.t();
5948 │ ─ 2. destination
5949 3 │ table public.t;
5950 ╰╴ ─ 1. source
5951 ");
5952 }
5953
5954 #[test]
5955 fn goto_table_stmt_with_search_path() {
5956 assert_snapshot!(goto("
5957set search_path to foo;
5958create table foo.t();
5959table t$0;
5960"), @r"
5961 ╭▸
5962 3 │ create table foo.t();
5963 │ ─ 2. destination
5964 4 │ table t;
5965 ╰╴ ─ 1. source
5966 ");
5967 }
5968
5969 #[test]
5970 fn goto_drop_index() {
5971 assert_snapshot!(goto("
5972create index idx_name on t(x);
5973drop index idx_name$0;
5974"), @r"
5975 ╭▸
5976 2 │ create index idx_name on t(x);
5977 │ ──────── 2. destination
5978 3 │ drop index idx_name;
5979 ╰╴ ─ 1. source
5980 ");
5981 }
5982
5983 #[test]
5984 fn goto_drop_index_with_schema() {
5985 assert_snapshot!(goto(r#"
5986set search_path to public;
5987create index idx_name on t(x);
5988drop index public.idx_name$0;
5989"#), @r"
5990 ╭▸
5991 3 │ create index idx_name on t(x);
5992 │ ──────── 2. destination
5993 4 │ drop index public.idx_name;
5994 ╰╴ ─ 1. source
5995 ");
5996 }
5997
5998 #[test]
5999 fn goto_drop_index_defined_after() {
6000 assert_snapshot!(goto("
6001drop index idx_name$0;
6002create index idx_name on t(x);
6003"), @r"
6004 ╭▸
6005 2 │ drop index idx_name;
6006 │ ─ 1. source
6007 3 │ create index idx_name on t(x);
6008 ╰╴ ──────── 2. destination
6009 ");
6010 }
6011
6012 #[test]
6013 fn goto_index_definition_returns_self() {
6014 assert_snapshot!(goto("
6015create index idx_name$0 on t(x);
6016"), @r"
6017 ╭▸
6018 2 │ create index idx_name on t(x);
6019 │ ┬──────┬
6020 │ │ │
6021 │ │ 1. source
6022 ╰╴ 2. destination
6023 ");
6024 }
6025
6026 #[test]
6027 fn goto_drop_index_with_search_path() {
6028 assert_snapshot!(goto(r#"
6029create index idx_name on t(x);
6030set search_path to bar;
6031create index idx_name on f(x);
6032set search_path to default;
6033drop index idx_name$0;
6034"#), @r"
6035 ╭▸
6036 2 │ create index idx_name on t(x);
6037 │ ──────── 2. destination
6038 ‡
6039 6 │ drop index idx_name;
6040 ╰╴ ─ 1. source
6041 ");
6042 }
6043
6044 #[test]
6045 fn goto_drop_index_schema_qualified() {
6046 assert_snapshot!(goto("
6047create schema a;
6048create schema b;
6049create table a.t(id int);
6050create table b.t(id int);
6051create index idx on a.t(id);
6052create index idx on b.t(id);
6053drop index b.idx$0;
6054"), @"
6055 ╭▸
6056 7 │ create index idx on b.t(id);
6057 │ ─── 2. destination
6058 8 │ drop index b.idx;
6059 ╰╴ ─ 1. source
6060 ");
6061 }
6062
6063 #[test]
6064 fn goto_drop_index_multiple() {
6065 assert_snapshot!(goto("
6066create index idx1 on t(x);
6067create index idx2 on t(y);
6068drop index idx1, idx2$0;
6069"), @r"
6070 ╭▸
6071 3 │ create index idx2 on t(y);
6072 │ ──── 2. destination
6073 4 │ drop index idx1, idx2;
6074 ╰╴ ─ 1. source
6075 ");
6076 }
6077
6078 #[test]
6079 fn goto_create_index_table() {
6080 assert_snapshot!(goto("
6081create table users(id int);
6082create index idx_users on users$0(id);
6083"), @r"
6084 ╭▸
6085 2 │ create table users(id int);
6086 │ ───── 2. destination
6087 3 │ create index idx_users on users(id);
6088 ╰╴ ─ 1. source
6089 ");
6090 }
6091
6092 #[test]
6093 fn goto_create_index_table_with_schema() {
6094 assert_snapshot!(goto("
6095create table public.users(id int);
6096create index idx_users on public.users$0(id);
6097"), @r"
6098 ╭▸
6099 2 │ create table public.users(id int);
6100 │ ───── 2. destination
6101 3 │ create index idx_users on public.users(id);
6102 ╰╴ ─ 1. source
6103 ");
6104 }
6105
6106 #[test]
6107 fn goto_create_index_table_with_search_path() {
6108 assert_snapshot!(goto(r#"
6109set search_path to foo;
6110create table foo.users(id int);
6111create index idx_users on users$0(id);
6112"#), @r"
6113 ╭▸
6114 3 │ create table foo.users(id int);
6115 │ ───── 2. destination
6116 4 │ create index idx_users on users(id);
6117 ╰╴ ─ 1. source
6118 ");
6119 }
6120
6121 #[test]
6122 fn goto_create_index_temp_table() {
6123 assert_snapshot!(goto("
6124create temp table users(id int);
6125create index idx_users on users$0(id);
6126"), @r"
6127 ╭▸
6128 2 │ create temp table users(id int);
6129 │ ───── 2. destination
6130 3 │ create index idx_users on users(id);
6131 ╰╴ ─ 1. source
6132 ");
6133 }
6134
6135 #[test]
6136 fn goto_create_index_column() {
6137 assert_snapshot!(goto("
6138create table users(id int, email text);
6139create index idx_email on users(email$0);
6140"), @r"
6141 ╭▸
6142 2 │ create table users(id int, email text);
6143 │ ───── 2. destination
6144 3 │ create index idx_email on users(email);
6145 ╰╴ ─ 1. source
6146 ");
6147 }
6148
6149 #[test]
6150 fn goto_create_index_first_column() {
6151 assert_snapshot!(goto("
6152create table users(id int, email text);
6153create index idx_id on users(id$0);
6154"), @r"
6155 ╭▸
6156 2 │ create table users(id int, email text);
6157 │ ── 2. destination
6158 3 │ create index idx_id on users(id);
6159 ╰╴ ─ 1. source
6160 ");
6161 }
6162
6163 #[test]
6164 fn goto_create_index_multiple_columns() {
6165 assert_snapshot!(goto("
6166create table users(id int, email text, name text);
6167create index idx_users on users(id, email$0, name);
6168"), @r"
6169 ╭▸
6170 2 │ create table users(id int, email text, name text);
6171 │ ───── 2. destination
6172 3 │ create index idx_users on users(id, email, name);
6173 ╰╴ ─ 1. source
6174 ");
6175 }
6176
6177 #[test]
6178 fn goto_create_index_column_with_schema() {
6179 assert_snapshot!(goto("
6180create table public.users(id int, email text);
6181create index idx_email on public.users(email$0);
6182"), @r"
6183 ╭▸
6184 2 │ create table public.users(id int, email text);
6185 │ ───── 2. destination
6186 3 │ create index idx_email on public.users(email);
6187 ╰╴ ─ 1. source
6188 ");
6189 }
6190
6191 #[test]
6192 fn goto_create_index_column_temp_table() {
6193 assert_snapshot!(goto("
6194create temp table users(id int, email text);
6195create index idx_email on users(email$0);
6196"), @r"
6197 ╭▸
6198 2 │ create temp table users(id int, email text);
6199 │ ───── 2. destination
6200 3 │ create index idx_email on users(email);
6201 ╰╴ ─ 1. source
6202 ");
6203 }
6204
6205 #[test]
6206 fn goto_create_index_include_column() {
6207 assert_snapshot!(goto("
6208create table users(id int, email text);
6209create index idx on users(id) include (email$0);
6210"), @r"
6211 ╭▸
6212 2 │ create table users(id int, email text);
6213 │ ───── 2. destination
6214 3 │ create index idx on users(id) include (email);
6215 ╰╴ ─ 1. source
6216 ");
6217 }
6218
6219 #[test]
6220 fn goto_create_index_where_column() {
6221 assert_snapshot!(goto("
6222create table users(id int, email text);
6223create index idx on users(id) where email$0 is not null;
6224"), @r"
6225 ╭▸
6226 2 │ create table users(id int, email text);
6227 │ ───── 2. destination
6228 3 │ create index idx on users(id) where email is not null;
6229 ╰╴ ─ 1. source
6230 ");
6231 }
6232
6233 #[test]
6234 fn goto_drop_function() {
6235 assert_snapshot!(goto("
6236create function foo() returns int as $$ select 1 $$ language sql;
6237drop function foo$0();
6238"), @r"
6239 ╭▸
6240 2 │ create function foo() returns int as $$ select 1 $$ language sql;
6241 │ ─── 2. destination
6242 3 │ drop function foo();
6243 ╰╴ ─ 1. source
6244 ");
6245 }
6246
6247 #[test]
6248 fn goto_drop_function_with_schema() {
6249 assert_snapshot!(goto("
6250set search_path to public;
6251create function foo() returns int as $$ select 1 $$ language sql;
6252drop function public.foo$0();
6253"), @r"
6254 ╭▸
6255 3 │ create function foo() returns int as $$ select 1 $$ language sql;
6256 │ ─── 2. destination
6257 4 │ drop function public.foo();
6258 ╰╴ ─ 1. source
6259 ");
6260 }
6261
6262 #[test]
6263 fn goto_drop_function_defined_after() {
6264 assert_snapshot!(goto("
6265drop function foo$0();
6266create function foo() returns int as $$ select 1 $$ language sql;
6267"), @r"
6268 ╭▸
6269 2 │ drop function foo();
6270 │ ─ 1. source
6271 3 │ create function foo() returns int as $$ select 1 $$ language sql;
6272 ╰╴ ─── 2. destination
6273 ");
6274 }
6275
6276 #[test]
6277 fn goto_function_definition_returns_self() {
6278 assert_snapshot!(goto("
6279create function foo$0() returns int as $$ select 1 $$ language sql;
6280"), @r"
6281 ╭▸
6282 2 │ create function foo() returns int as $$ select 1 $$ language sql;
6283 │ ┬─┬
6284 │ │ │
6285 │ │ 1. source
6286 ╰╴ 2. destination
6287 ");
6288 }
6289
6290 #[test]
6291 fn goto_drop_function_with_search_path() {
6292 assert_snapshot!(goto("
6293create function foo() returns int as $$ select 1 $$ language sql;
6294set search_path to bar;
6295create function foo() returns int as $$ select 1 $$ language sql;
6296set search_path to default;
6297drop function foo$0();
6298"), @r"
6299 ╭▸
6300 2 │ create function foo() returns int as $$ select 1 $$ language sql;
6301 │ ─── 2. destination
6302 ‡
6303 6 │ drop function foo();
6304 ╰╴ ─ 1. source
6305 ");
6306 }
6307
6308 #[test]
6309 fn goto_drop_function_multiple() {
6310 assert_snapshot!(goto("
6311create function foo() returns int as $$ select 1 $$ language sql;
6312create function bar() returns int as $$ select 1 $$ language sql;
6313drop function foo(), bar$0();
6314"), @r"
6315 ╭▸
6316 3 │ create function bar() returns int as $$ select 1 $$ language sql;
6317 │ ─── 2. destination
6318 4 │ drop function foo(), bar();
6319 ╰╴ ─ 1. source
6320 ");
6321 }
6322
6323 #[test]
6324 fn goto_drop_function_overloaded() {
6325 assert_snapshot!(goto("
6326create function add(complex) returns complex as $$ select null $$ language sql;
6327create function add(bigint) returns bigint as $$ select 1 $$ language sql;
6328drop function add$0(complex);
6329"), @r"
6330 ╭▸
6331 2 │ create function add(complex) returns complex as $$ select null $$ language sql;
6332 │ ─── 2. destination
6333 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
6334 4 │ drop function add(complex);
6335 ╰╴ ─ 1. source
6336 ");
6337 }
6338
6339 #[test]
6340 fn goto_drop_function_second_overload() {
6341 assert_snapshot!(goto("
6342create function add(complex) returns complex as $$ select null $$ language sql;
6343create function add(bigint) returns bigint as $$ select 1 $$ language sql;
6344drop function add$0(bigint);
6345"), @r"
6346 ╭▸
6347 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
6348 │ ─── 2. destination
6349 4 │ drop function add(bigint);
6350 ╰╴ ─ 1. source
6351 ");
6352 }
6353
6354 #[test]
6355 fn goto_select_function_call() {
6356 assert_snapshot!(goto("
6357create function foo() returns int as $$ select 1 $$ language sql;
6358select foo$0();
6359"), @r"
6360 ╭▸
6361 2 │ create function foo() returns int as $$ select 1 $$ language sql;
6362 │ ─── 2. destination
6363 3 │ select foo();
6364 ╰╴ ─ 1. source
6365 ");
6366 }
6367
6368 #[test]
6369 fn goto_select_column_from_function_return_table() {
6370 assert_snapshot!(goto(r#"
6371create function dup(int) returns table(f1 int, f2 text)
6372 as ''
6373 language sql;
6374
6375select f1$0 from dup(42);
6376"#), @r"
6377 ╭▸
6378 2 │ create function dup(int) returns table(f1 int, f2 text)
6379 │ ── 2. destination
6380 ‡
6381 6 │ select f1 from dup(42);
6382 ╰╴ ─ 1. source
6383 ");
6384 }
6385
6386 #[test]
6387 fn goto_select_column_from_function_return_table_with_schema() {
6388 assert_snapshot!(goto(r#"
6389create function myschema.dup(int) returns table(f1 int, f2 text)
6390 as ''
6391 language sql;
6392create function otherschema.dup(int) returns table(f1 int, f2 text)
6393 as ''
6394 language sql;
6395
6396select f1$0 from myschema.dup(42);
6397"#), @r"
6398 ╭▸
6399 2 │ create function myschema.dup(int) returns table(f1 int, f2 text)
6400 │ ── 2. destination
6401 ‡
6402 9 │ select f1 from myschema.dup(42);
6403 ╰╴ ─ 1. source
6404 ");
6405 }
6406
6407 #[test]
6408 fn goto_select_column_from_function_return_table_paren() {
6409 assert_snapshot!(goto(r#"
6410create function dup(int) returns table(f1 int, f2 text)
6411 as ''
6412 language sql;
6413
6414select (dup(42)).f2$0;
6415"#), @r"
6416 ╭▸
6417 2 │ create function dup(int) returns table(f1 int, f2 text)
6418 │ ── 2. destination
6419 ‡
6420 6 │ select (dup(42)).f2;
6421 ╰╴ ─ 1. source
6422 ");
6423 }
6424
6425 #[test]
6426 fn goto_select_column_from_function_return_table_qualified() {
6427 assert_snapshot!(goto(r#"
6428create function dup(int) returns table(f1 int, f2 text)
6429 as ''
6430 language sql;
6431
6432select dup.f1$0 from dup(42);
6433"#), @r"
6434 ╭▸
6435 2 │ create function dup(int) returns table(f1 int, f2 text)
6436 │ ── 2. destination
6437 ‡
6438 6 │ select dup.f1 from dup(42);
6439 ╰╴ ─ 1. source
6440 ");
6441 }
6442
6443 #[test]
6444 fn goto_select_column_from_function_return_table_qualified_function_name() {
6445 assert_snapshot!(goto(r#"
6446create function dup(int) returns table(f1 int, f2 text)
6447 as ''
6448 language sql;
6449
6450select dup$0.f1 from dup(42);
6451"#), @r"
6452 ╭▸
6453 2 │ create function dup(int) returns table(f1 int, f2 text)
6454 │ ─── 2. destination
6455 ‡
6456 6 │ select dup.f1 from dup(42);
6457 ╰╴ ─ 1. source
6458 ");
6459 }
6460
6461 #[test]
6462 fn goto_select_column_from_function_return_table_qualified_function_name_with_alias() {
6463 assert_snapshot!(goto(r#"
6464create function dup(int) returns table(f1 int, f2 text)
6465 as ''
6466 language sql;
6467
6468select dup$0.f2 from dup(42) as dup;
6469"#), @r"
6470 ╭▸
6471 6 │ select dup.f2 from dup(42) as dup;
6472 ╰╴ ─ 1. source ─── 2. destination
6473 ");
6474 }
6475
6476 #[test]
6477 fn goto_select_column_from_function_return_table_alias_list() {
6478 assert_snapshot!(goto(r#"
6479create function dup(int) returns table(f1 int, f2 text)
6480 as ''
6481 language sql;
6482
6483select a$0 from dup(42) t(a, b);
6484"#), @r"
6485 ╭▸
6486 6 │ select a from dup(42) t(a, b);
6487 ╰╴ ─ 1. source ─ 2. destination
6488 ");
6489 }
6490
6491 #[test]
6492 fn goto_select_column_from_function_return_table_alias_list_qualified_partial() {
6493 assert_snapshot!(goto(r#"
6494create function dup(int) returns table(f1 int, f2 text)
6495 as ''
6496 language sql;
6497
6498select u.f2$0 from dup(42) as u(x);
6499"#), @r"
6500 ╭▸
6501 2 │ create function dup(int) returns table(f1 int, f2 text)
6502 │ ── 2. destination
6503 ‡
6504 6 │ select u.f2 from dup(42) as u(x);
6505 ╰╴ ─ 1. source
6506 ");
6507 }
6508
6509 #[test]
6510 fn goto_select_column_from_function_return_table_alias_list_unqualified_partial() {
6511 assert_snapshot!(goto(r#"
6512create function dup(int) returns table(f1 int, f2 text)
6513 as ''
6514 language sql;
6515
6516select f2$0 from dup(42) as u(x);
6517"#), @r"
6518 ╭▸
6519 2 │ create function dup(int) returns table(f1 int, f2 text)
6520 │ ── 2. destination
6521 ‡
6522 6 │ select f2 from dup(42) as u(x);
6523 ╰╴ ─ 1. source
6524 ");
6525 }
6526
6527 #[test]
6528 fn goto_select_column_from_function_return_table_alias_list_unqualified_not_found() {
6529 goto_not_found(
6530 r#"
6531create function dup(int) returns table(f1 int, f2 text)
6532 as ''
6533 language sql;
6534
6535select f2$0 from dup(42) as u(x, y);
6536"#,
6537 );
6538 }
6539
6540 #[test]
6541 fn goto_select_column_from_function_returns_setof_table() {
6542 assert_snapshot!(goto("
6543create table users (id int, name text);
6544create function f() returns setof users
6545 language sql begin atomic select * from users; end;
6546select id$0 from f();
6547"), @"
6548 ╭▸
6549 2 │ create table users (id int, name text);
6550 │ ── 2. destination
6551 ‡
6552 5 │ select id from f();
6553 ╰╴ ─ 1. source
6554 ");
6555 }
6556
6557 #[test]
6558 fn goto_select_column_from_function_returns_setof_table_qualified() {
6559 assert_snapshot!(goto("
6560create table users (id int, name text);
6561create function f() returns setof users
6562 language sql begin atomic select * from users; end;
6563select f.id$0 from f();
6564"), @"
6565 ╭▸
6566 2 │ create table users (id int, name text);
6567 │ ── 2. destination
6568 ‡
6569 5 │ select f.id from f();
6570 ╰╴ ─ 1. source
6571 ");
6572 }
6573
6574 #[test]
6575 fn goto_select_column_from_function_returns_setof_composite_type() {
6576 assert_snapshot!(goto("
6577create type pt as (x int, y int);
6578create function f() returns setof pt language sql begin atomic select 1, 2; end;
6579select x$0 from f();
6580"), @"
6581 ╭▸
6582 2 │ create type pt as (x int, y int);
6583 │ ─ 2. destination
6584 3 │ create function f() returns setof pt language sql begin atomic select 1, 2; end;
6585 4 │ select x from f();
6586 ╰╴ ─ 1. source
6587 ");
6588 }
6589
6590 #[test]
6591 fn goto_select_column_from_scalar_setof_function_alias() {
6592 assert_snapshot!(goto("
6593create function nums() returns setof int language sql as $$ values (1) $$;
6594select n$0 from nums() as n;
6595"), @"
6596 ╭▸
6597 3 │ select n from nums() as n;
6598 ╰╴ ─ 1. source ─ 2. destination
6599 ");
6600 }
6601
6602 #[test]
6603 fn goto_select_column_from_scalar_setof_function_no_alias() {
6604 assert_snapshot!(goto("
6605create function nums() returns setof int language sql as $$ values (1) $$;
6606select nums$0 from nums();
6607"), @"
6608 ╭▸
6609 3 │ select nums from nums();
6610 │ ┬ ──── 2. destination
6611 │ │
6612 ╰╴ 1. source
6613 ");
6614 }
6615
6616 #[test]
6617 fn goto_select_column_from_scalar_setof_function_alias_with_column_list() {
6618 assert_snapshot!(goto("
6619create function nums() returns setof int language sql as $$ values (1) $$;
6620select x$0 from nums() as n(x);
6621"), @"
6622 ╭▸
6623 3 │ select x from nums() as n(x);
6624 ╰╴ ─ 1. source ─ 2. destination
6625 ");
6626 }
6627
6628 #[test]
6629 fn goto_select_column_from_function_out_param() {
6630 assert_snapshot!(goto("
6631create function f(out id int, out nm text) returns setof record
6632 language sql begin atomic select 1, 2; end;
6633select id$0 from f();
6634"), @"
6635 ╭▸
6636 2 │ create function f(out id int, out nm text) returns setof record
6637 │ ── 2. destination
6638 3 │ language sql begin atomic select 1, 2; end;
6639 4 │ select id from f();
6640 ╰╴ ─ 1. source
6641 ");
6642 }
6643
6644 #[test]
6645 fn goto_select_column_from_rows_from() {
6646 assert_snapshot!(goto("
6647create function f() returns table(a int) language sql begin atomic select 1; end;
6648select a$0 from rows from (f());
6649"), @"
6650 ╭▸
6651 2 │ create function f() returns table(a int) language sql begin atomic select 1; end;
6652 │ ─ 2. destination
6653 3 │ select a from rows from (f());
6654 ╰╴ ─ 1. source
6655 ");
6656 }
6657
6658 #[test]
6659 fn goto_select_column_from_xmltable() {
6660 assert_snapshot!(goto("
6661create table t (x xml);
6662select b$0 from t, xmltable(
6663 '/r' passing x
6664 columns b int
6665);
6666"), @"
6667 ╭▸
6668 3 │ select b from t, xmltable(
6669 │ ─ 1. source
6670 4 │ '/r' passing x
6671 5 │ columns b int
6672 ╰╴ ─ 2. destination
6673 ");
6674 }
6675
6676 #[test]
6677 fn goto_select_column_from_xmltable_aliased() {
6678 assert_snapshot!(goto("
6679create table t (x xml);
6680select xt.b$0 from t, xmltable(
6681 '/r' passing x
6682 columns b int
6683) as xt;
6684"), @"
6685 ╭▸
6686 3 │ select xt.b from t, xmltable(
6687 │ ─ 1. source
6688 4 │ '/r' passing x
6689 5 │ columns b int
6690 ╰╴ ─ 2. destination
6691 ");
6692 }
6693
6694 #[test]
6695 fn goto_xmltable_passing_clause_qualified_column() {
6696 assert_snapshot!(goto("
6697create table t (x xml);
6698select 1 from t, xmltable(
6699 '/r' passing t.x$0
6700 columns b int
6701);
6702"), @"
6703 ╭▸
6704 2 │ create table t (x xml);
6705 │ ─ 2. destination
6706 3 │ select 1 from t, xmltable(
6707 4 │ '/r' passing t.x
6708 ╰╴ ─ 1. source
6709 ");
6710 }
6711
6712 #[test]
6713 fn goto_select_column_from_json_table() {
6714 assert_snapshot!(goto("
6715create table t (j jsonb);
6716select b$0 from t, json_table(
6717 t.j, '$[*]'
6718 columns (b int path '$')
6719);
6720"), @"
6721 ╭▸
6722 3 │ select b from t, json_table(
6723 │ ─ 1. source
6724 4 │ t.j, '$[*]'
6725 5 │ columns (b int path '$')
6726 ╰╴ ─ 2. destination
6727 ");
6728 }
6729
6730 #[test]
6731 fn goto_json_table_context_item_qualified_column() {
6732 assert_snapshot!(goto("
6733create table t (j jsonb);
6734select 1 from t, json_table(
6735 t.j$0, '$[*]'
6736 columns (b int path '$')
6737);
6738"), @"
6739 ╭▸
6740 2 │ create table t (j jsonb);
6741 │ ─ 2. destination
6742 3 │ select 1 from t, json_table(
6743 4 │ t.j, '$[*]'
6744 ╰╴ ─ 1. source
6745 ");
6746 }
6747
6748 #[test]
6749 fn goto_fn_call_column_from_cte() {
6750 assert_snapshot!(goto("
6751with cte as (select 1 as a)
6752select a$0(cte) from cte;
6753"), @"
6754 ╭▸
6755 2 │ with cte as (select 1 as a)
6756 │ ─ 2. destination
6757 3 │ select a(cte) from cte;
6758 ╰╴ ─ 1. source
6759 ");
6760 }
6761
6762 #[test]
6763 fn goto_fn_call_column_from_view() {
6764 assert_snapshot!(goto("
6765create view v as select 1 as a;
6766select a$0(v) from v;
6767"), @"
6768 ╭▸
6769 2 │ create view v as select 1 as a;
6770 │ ─ 2. destination
6771 3 │ select a(v) from v;
6772 ╰╴ ─ 1. source
6773 ");
6774 }
6775
6776 #[test]
6777 fn goto_select_aggregate_call() {
6778 assert_snapshot!(goto("
6779create aggregate foo(int) (
6780 sfunc = int4pl,
6781 stype = int,
6782 initcond = '0'
6783);
6784
6785select foo$0(1);
6786"), @r"
6787 ╭▸
6788 2 │ create aggregate foo(int) (
6789 │ ─── 2. destination
6790 ‡
6791 8 │ select foo(1);
6792 ╰╴ ─ 1. source
6793 ");
6794 }
6795
6796 #[test]
6797 fn goto_create_aggregate_sfunc() {
6798 assert_snapshot!(goto("
6799create function pg_catalog.int8inc(bigint) returns bigint
6800 language internal;
6801
6802create aggregate pg_catalog.count(*) (
6803 sfunc = int8inc$0,
6804 stype = bigint,
6805 combinefunc = int8pl,
6806 initcond = '0'
6807);
6808"), @r"
6809 ╭▸
6810 2 │ create function pg_catalog.int8inc(bigint) returns bigint
6811 │ ─────── 2. destination
6812 ‡
6813 6 │ sfunc = int8inc,
6814 ╰╴ ─ 1. source
6815 "
6816 );
6817 }
6818
6819 #[test]
6820 fn goto_create_aggregate_combinefunc() {
6821 assert_snapshot!(goto("
6822create function pg_catalog.int8pl(bigint, bigint) returns bigint
6823 language internal;
6824
6825create aggregate pg_catalog.count(*) (
6826 sfunc = int8inc,
6827 stype = bigint,
6828 combinefunc = int8pl$0,
6829 initcond = '0'
6830);
6831"), @r"
6832 ╭▸
6833 2 │ create function pg_catalog.int8pl(bigint, bigint) returns bigint
6834 │ ────── 2. destination
6835 ‡
6836 8 │ combinefunc = int8pl,
6837 ╰╴ ─ 1. source
6838 "
6839 );
6840 }
6841
6842 #[test]
6843 fn goto_default_constraint_function_call() {
6844 assert_snapshot!(goto("
6845create function f() returns int as 'select 1' language sql;
6846create table t(
6847 a int default f$0()
6848);
6849"), @r"
6850 ╭▸
6851 2 │ create function f() returns int as 'select 1' language sql;
6852 │ ─ 2. destination
6853 3 │ create table t(
6854 4 │ a int default f()
6855 ╰╴ ─ 1. source
6856 ");
6857 }
6858
6859 #[test]
6860 fn goto_select_function_call_with_schema() {
6861 assert_snapshot!(goto("
6862create function public.foo() returns int as $$ select 1 $$ language sql;
6863select public.foo$0();
6864"), @r"
6865 ╭▸
6866 2 │ create function public.foo() returns int as $$ select 1 $$ language sql;
6867 │ ─── 2. destination
6868 3 │ select public.foo();
6869 ╰╴ ─ 1. source
6870 ");
6871 }
6872
6873 #[test]
6874 fn goto_select_function_call_with_search_path() {
6875 assert_snapshot!(goto("
6876set search_path to myschema;
6877create function foo() returns int as $$ select 1 $$ language sql;
6878select myschema.foo$0();
6879"), @r"
6880 ╭▸
6881 3 │ create function foo() returns int as $$ select 1 $$ language sql;
6882 │ ─── 2. destination
6883 4 │ select myschema.foo();
6884 ╰╴ ─ 1. source
6885 ");
6886 }
6887
6888 #[test]
6889 fn goto_function_call_style_column_access() {
6890 assert_snapshot!(goto("
6891create table t(a int, b int);
6892select a$0(t) from t;
6893"), @r"
6894 ╭▸
6895 2 │ create table t(a int, b int);
6896 │ ─ 2. destination
6897 3 │ select a(t) from t;
6898 ╰╴ ─ 1. source
6899 ");
6900 }
6901
6902 #[test]
6903 fn goto_function_call_style_column_access_with_function_precedence() {
6904 assert_snapshot!(goto("
6905create table t(a int, b int);
6906create function b(t) returns int as 'select 1' LANGUAGE sql;
6907select b$0(t) from t;
6908"), @r"
6909 ╭▸
6910 3 │ create function b(t) returns int as 'select 1' LANGUAGE sql;
6911 │ ─ 2. destination
6912 4 │ select b(t) from t;
6913 ╰╴ ─ 1. source
6914 ");
6915 }
6916
6917 #[test]
6918 fn goto_function_call_style_column_access_table_arg() {
6919 assert_snapshot!(goto("
6920create table t(a int, b int);
6921select a(t$0) from t;
6922"), @r"
6923 ╭▸
6924 2 │ create table t(a int, b int);
6925 │ ─ 2. destination
6926 3 │ select a(t) from t;
6927 ╰╴ ─ 1. source
6928 ");
6929 }
6930
6931 #[test]
6932 fn goto_function_call_style_column_access_table_arg_with_function() {
6933 assert_snapshot!(goto("
6934create table t(a int, b int);
6935create function b(t) returns int as 'select 1' LANGUAGE sql;
6936select b(t$0) from t;
6937"), @r"
6938 ╭▸
6939 2 │ create table t(a int, b int);
6940 │ ─ 2. destination
6941 3 │ create function b(t) returns int as 'select 1' LANGUAGE sql;
6942 4 │ select b(t) from t;
6943 ╰╴ ─ 1. source
6944 ");
6945 }
6946
6947 #[test]
6948 fn goto_function_call_multiple_args_not_column_access() {
6949 goto_not_found(
6950 "
6951create table t(a int, b int);
6952select a$0(t, 1) from t;
6953",
6954 );
6955 }
6956
6957 #[test]
6958 fn goto_function_call_nested() {
6959 assert_snapshot!(goto("
6960create function f() returns int8
6961 as 'select 1'
6962 language sql;
6963select format('foo%d', f$0());
6964"), @r"
6965 ╭▸
6966 2 │ create function f() returns int8
6967 │ ─ 2. destination
6968 ‡
6969 5 │ select format('foo%d', f());
6970 ╰╴ ─ 1. source
6971 ");
6972 }
6973
6974 #[test]
6975 fn goto_field_style_function_call() {
6976 assert_snapshot!(goto("
6977create table t(a int);
6978create function b(t) returns int as 'select 1' language sql;
6979select t.b$0 from t;
6980"), @r"
6981 ╭▸
6982 3 │ create function b(t) returns int as 'select 1' language sql;
6983 │ ─ 2. destination
6984 4 │ select t.b from t;
6985 ╰╴ ─ 1. source
6986 ");
6987 }
6988
6989 #[test]
6990 fn goto_field_style_function_call_column_precedence() {
6991 assert_snapshot!(goto("
6992create table t(a int, b int);
6993create function b(t) returns int as 'select 1' language sql;
6994select t.b$0 from t;
6995"), @r"
6996 ╭▸
6997 2 │ create table t(a int, b int);
6998 │ ─ 2. destination
6999 3 │ create function b(t) returns int as 'select 1' language sql;
7000 4 │ select t.b from t;
7001 ╰╴ ─ 1. source
7002 ");
7003 }
7004
7005 #[test]
7006 fn goto_field_style_function_call_table_ref() {
7007 assert_snapshot!(goto("
7008create table t(a int);
7009create function b(t) returns int as 'select 1' language sql;
7010select t$0.b from t;
7011"), @r"
7012 ╭▸
7013 2 │ create table t(a int);
7014 │ ─ 2. destination
7015 3 │ create function b(t) returns int as 'select 1' language sql;
7016 4 │ select t.b from t;
7017 ╰╴ ─ 1. source
7018 ");
7019 }
7020
7021 #[test]
7022 fn goto_function_call_style_in_where() {
7023 assert_snapshot!(goto("
7024create table t(a int, b int);
7025select * from t where a$0(t) > 0;
7026"), @r"
7027 ╭▸
7028 2 │ create table t(a int, b int);
7029 │ ─ 2. destination
7030 3 │ select * from t where a(t) > 0;
7031 ╰╴ ─ 1. source
7032 ");
7033 }
7034
7035 #[test]
7036 fn goto_function_call_style_in_where_function_precedence() {
7037 assert_snapshot!(goto("
7038create table t(a int, b int);
7039create function b(t) returns int as 'select 1' language sql;
7040select * from t where b$0(t) > 0;
7041"), @r"
7042 ╭▸
7043 3 │ create function b(t) returns int as 'select 1' language sql;
7044 │ ─ 2. destination
7045 4 │ select * from t where b(t) > 0;
7046 ╰╴ ─ 1. source
7047 ");
7048 }
7049
7050 #[test]
7051 fn goto_field_style_function_call_in_where() {
7052 assert_snapshot!(goto("
7053create table t(a int);
7054create function b(t) returns int as 'select 1' language sql;
7055select * from t where t.b$0 > 0;
7056"), @r"
7057 ╭▸
7058 3 │ create function b(t) returns int as 'select 1' language sql;
7059 │ ─ 2. destination
7060 4 │ select * from t where t.b > 0;
7061 ╰╴ ─ 1. source
7062 ");
7063 }
7064
7065 #[test]
7066 fn goto_field_style_in_where_column_precedence() {
7067 assert_snapshot!(goto("
7068create table t(a int, b int);
7069create function b(t) returns int as 'select 1' language sql;
7070select * from t where t.b$0 > 0;
7071"), @r"
7072 ╭▸
7073 2 │ create table t(a int, b int);
7074 │ ─ 2. destination
7075 3 │ create function b(t) returns int as 'select 1' language sql;
7076 4 │ select * from t where t.b > 0;
7077 ╰╴ ─ 1. source
7078 ");
7079 }
7080
7081 #[test]
7082 fn goto_function_call_style_table_arg_in_where() {
7083 assert_snapshot!(goto("
7084create table t(a int);
7085select * from t where a(t$0) > 2;
7086"), @r"
7087 ╭▸
7088 2 │ create table t(a int);
7089 │ ─ 2. destination
7090 3 │ select * from t where a(t) > 2;
7091 ╰╴ ─ 1. source
7092 ");
7093 }
7094
7095 #[test]
7096 fn goto_qualified_table_ref_in_where() {
7097 assert_snapshot!(goto("
7098create table t(a int);
7099create function b(t) returns int as 'select 1' language sql;
7100select * from t where t$0.b > 2;
7101"), @r"
7102 ╭▸
7103 2 │ create table t(a int);
7104 │ ─ 2. destination
7105 3 │ create function b(t) returns int as 'select 1' language sql;
7106 4 │ select * from t where t.b > 2;
7107 ╰╴ ─ 1. source
7108 ");
7109 }
7110
7111 #[test]
7112 fn goto_function_call_style_in_order_by() {
7113 assert_snapshot!(goto("
7114create table t(a int, b int);
7115create function b(t) returns int as 'select 1' language sql;
7116select * from t order by b$0(t);
7117"), @r"
7118 ╭▸
7119 3 │ create function b(t) returns int as 'select 1' language sql;
7120 │ ─ 2. destination
7121 4 │ select * from t order by b(t);
7122 ╰╴ ─ 1. source
7123 ");
7124 }
7125
7126 #[test]
7127 fn goto_field_style_in_order_by() {
7128 assert_snapshot!(goto("
7129create table t(a int);
7130create function b(t) returns int as 'select 1' language sql;
7131select * from t order by t.b$0;
7132"), @r"
7133 ╭▸
7134 3 │ create function b(t) returns int as 'select 1' language sql;
7135 │ ─ 2. destination
7136 4 │ select * from t order by t.b;
7137 ╰╴ ─ 1. source
7138 ");
7139 }
7140
7141 #[test]
7142 fn goto_function_call_style_in_group_by() {
7143 assert_snapshot!(goto("
7144create table t(a int, b int);
7145select * from t group by a$0(t);
7146"), @r"
7147 ╭▸
7148 2 │ create table t(a int, b int);
7149 │ ─ 2. destination
7150 3 │ select * from t group by a(t);
7151 ╰╴ ─ 1. source
7152 ");
7153 }
7154
7155 #[test]
7156 fn goto_field_style_in_group_by() {
7157 assert_snapshot!(goto("
7158create table t(a int);
7159create function b(t) returns int as 'select 1' language sql;
7160select * from t group by t.b$0;
7161"), @r"
7162 ╭▸
7163 3 │ create function b(t) returns int as 'select 1' language sql;
7164 │ ─ 2. destination
7165 4 │ select * from t group by t.b;
7166 ╰╴ ─ 1. source
7167 ");
7168 }
7169
7170 #[test]
7171 fn goto_select_alias_order_by_column_name_conflict() {
7172 assert_snapshot!(goto("
7176with t as (select 2 a)
7177select 1 a from t
7178order by a$0;
7179"), @"
7180 ╭▸
7181 3 │ select 1 a from t
7182 │ ─ 2. destination
7183 4 │ order by a;
7184 ╰╴ ─ 1. source
7185 ");
7186 }
7187
7188 #[test]
7189 fn goto_select_alias_not_picked_window_order_by() {
7190 assert_snapshot!(goto("
7191with t as (select 4 a union select 2 a)
7192-- should go to the column def, not the alias
7193select 2 a, a, row_number() over (order by a$0) from t;
7194"), @"
7195 ╭▸
7196 2 │ with t as (select 4 a union select 2 a)
7197 │ ─ 2. destination
7198 3 │ -- should go to the column def, not the alias
7199 4 │ select 2 a, a, row_number() over (order by a) from t;
7200 ╰╴ ─ 1. source
7201 ");
7202 }
7203
7204 #[test]
7205 fn goto_select_alias_group_by_alias_func() {
7206 assert_snapshot!(goto("
7207with t as (select 'x'::text as name)
7208select lower(name) from t
7209group by lower$0;
7210"), @"
7211 ╭▸
7212 3 │ select lower(name) from t
7213 │ ───── 2. destination
7214 4 │ group by lower;
7215 ╰╴ ─ 1. source
7216 ");
7217 }
7218
7219 #[test]
7220 fn goto_select_alias_order_by_alias_func() {
7221 assert_snapshot!(goto("
7222with t as (select 'x'::text as name)
7223select lower(name) from t
7224order by lower$0;
7225"), @"
7226 ╭▸
7227 3 │ select lower(name) from t
7228 │ ───── 2. destination
7229 4 │ order by lower;
7230 ╰╴ ─ 1. source
7231 ");
7232 }
7233
7234 #[test]
7235 fn goto_select_alias_group_by_column_name_conflict() {
7236 assert_snapshot!(goto("
7240with t as (select 2 a)
7241select 1 a from t
7242group by a$0;
7243"), @"
7244 ╭▸
7245 2 │ with t as (select 2 a)
7246 │ ─ 2. destination
7247 3 │ select 1 a from t
7248 4 │ group by a;
7249 ╰╴ ─ 1. source
7250 ");
7251 }
7252
7253 #[test]
7254 fn goto_select_alias_in_group_by_with_cte() {
7255 assert_snapshot!(goto("
7256with t as (select 2 b)
7257select 1 a from t
7258group by a$0;
7259"), @"
7260 ╭▸
7261 3 │ select 1 a from t
7262 │ ─ 2. destination
7263 4 │ group by a;
7264 ╰╴ ─ 1. source
7265 ");
7266 }
7267
7268 #[test]
7269 fn goto_select_alias_in_group_by_rollup() {
7270 assert_snapshot!(goto("
7271create table t (a int);
7272select a as x from t
7273group by rollup(x$0);
7274"), @"
7275 ╭▸
7276 3 │ select a as x from t
7277 │ ─ 2. destination
7278 4 │ group by rollup(x);
7279 ╰╴ ─ 1. source
7280 ");
7281 }
7282
7283 #[test]
7284 fn goto_select_alias_in_group_by_cube() {
7285 assert_snapshot!(goto("
7286create table t (a int);
7287select a as x from t
7288group by cube(x$0);
7289"), @"
7290 ╭▸
7291 3 │ select a as x from t
7292 │ ─ 2. destination
7293 4 │ group by cube(x);
7294 ╰╴ ─ 1. source
7295 ");
7296 }
7297
7298 #[test]
7299 fn goto_select_alias_in_group_by_grouping_sets() {
7300 assert_snapshot!(goto("
7301create table t (a int);
7302select a as x from t
7303group by grouping sets ((x$0));
7304"), @"
7305 ╭▸
7306 3 │ select a as x from t
7307 │ ─ 2. destination
7308 4 │ group by grouping sets ((x));
7309 ╰╴ ─ 1. source
7310 ");
7311 }
7312
7313 #[test]
7314 fn goto_select_alias_in_distinct_on() {
7315 assert_snapshot!(goto("
7316create table t (a int);
7317select distinct on (x$0) a as x from t;
7318"), @"
7319 ╭▸
7320 3 │ select distinct on (x) a as x from t;
7321 │ ┬ ─ 2. destination
7322 │ │
7323 ╰╴ 1. source
7324 ");
7325 }
7326
7327 #[test]
7328 fn goto_select_alias_expr_in_order_by_not_found() {
7329 goto_not_found(
7330 "
7331with t as (select 2 b)
7332select 1 a from t
7333order by a$0 + 1
7334",
7335 );
7336 }
7337
7338 #[test]
7339 fn goto_select_alias_expr_in_group_by_expr_not_found() {
7340 goto_not_found(
7341 "
7342with t as (select 2 b)
7343select 1 a from t
7344group by a$0 + 1
7345",
7346 );
7347 }
7348
7349 #[test]
7350 fn goto_update_alias_hides_table_name() {
7351 goto_not_found(
7352 "
7353create table t(a int);
7354update t as u set a = t$0.a;
7355",
7356 );
7357 }
7358
7359 #[test]
7360 fn goto_insert_alias_hides_table_name() {
7361 goto_not_found(
7362 "
7363create table t(a int);
7364insert into t as u values (1) returning t$0.a;
7365",
7366 );
7367 }
7368
7369 #[test]
7370 fn goto_delete_alias_hides_table_name() {
7371 goto_not_found(
7372 "
7373create table t(a int);
7374delete from t as u where t$0.a = 1;
7375",
7376 );
7377 }
7378
7379 #[test]
7380 fn goto_merge_alias_hides_target_table_name() {
7381 goto_not_found(
7382 "
7383create table t(a int);
7384create table s(a int);
7385merge into t as u
7386 using s on t$0.a = s.a
7387 when matched then do nothing;
7388",
7389 );
7390 }
7391
7392 #[test]
7393 fn goto_merge_using_alias_hides_table_name() {
7394 goto_not_found(
7395 "
7396create table t(a int);
7397create table s(a int);
7398merge into t
7399 using s as u on s$0.a = t.a
7400 when matched then do nothing;
7401",
7402 );
7403 }
7404
7405 #[test]
7406 fn goto_merge_using_subquery_source_column() {
7407 assert_snapshot!(goto("
7408create table t(id int, val int);
7409merge into t
7410 using (select 1 as id, 2 as val) as s
7411 on t.id = s.id$0
7412 when not matched then
7413 insert (id, val) values (s.id, s.val);
7414"), @"
7415 ╭▸
7416 4 │ using (select 1 as id, 2 as val) as s
7417 │ ── 2. destination
7418 5 │ on t.id = s.id
7419 ╰╴ ─ 1. source
7420 ");
7421 }
7422
7423 #[test]
7424 fn goto_select_alias_in_order_by_with_cte() {
7425 assert_snapshot!(goto("
7426with t as (select 2 b)
7427select 1 a from t
7428order by a$0;
7429"), @"
7430 ╭▸
7431 3 │ select 1 a from t
7432 │ ─ 2. destination
7433 4 │ order by a;
7434 ╰╴ ─ 1. source
7435 ");
7436 }
7437
7438 #[test]
7439 fn goto_cte_table() {
7440 assert_snapshot!(goto("
7441with x as (select 1 as a)
7442select a from x$0;
7443"), @r"
7444 ╭▸
7445 2 │ with x as (select 1 as a)
7446 │ ─ 2. destination
7447 3 │ select a from x;
7448 ╰╴ ─ 1. source
7449 ");
7450 }
7451
7452 #[test]
7453 fn goto_cte_shadows_table_in_from() {
7454 assert_snapshot!(goto("
7455create table x(a int);
7456with x as (select 1 a)
7457select a from x$0;
7458"), @"
7459 ╭▸
7460 3 │ with x as (select 1 a)
7461 │ ─ 2. destination
7462 4 │ select a from x;
7463 ╰╴ ─ 1. source
7464 ");
7465 }
7466
7467 #[test]
7468 fn goto_cte_shadows_view_column() {
7469 assert_snapshot!(goto("
7470create view x as select 1 a;
7471with x as (select 2 a)
7472select a$0 from x;
7473"), @"
7474 ╭▸
7475 3 │ with x as (select 2 a)
7476 │ ─ 2. destination
7477 4 │ select a from x;
7478 ╰╴ ─ 1. source
7479 ");
7480 }
7481
7482 #[test]
7483 fn goto_cte_column() {
7484 assert_snapshot!(goto("
7485with x as (select 1 as a)
7486select a$0 from x;
7487"), @r"
7488 ╭▸
7489 2 │ with x as (select 1 as a)
7490 │ ─ 2. destination
7491 3 │ select a from x;
7492 ╰╴ ─ 1. source
7493 ");
7494 }
7495
7496 #[test]
7497 fn goto_cte_qualified_column_prefers_cte_over_table() {
7498 assert_snapshot!(goto("
7499create table u(id int, b int);
7500with u as (select 1 id, 2 b)
7501select u.id$0 from u;
7502"), @r"
7503 ╭▸
7504 3 │ with u as (select 1 id, 2 b)
7505 │ ── 2. destination
7506 4 │ select u.id from u;
7507 ╰╴ ─ 1. source
7508 ");
7509 }
7510
7511 #[test]
7512 fn goto_qualified_table_ref_prefers_schema_qualified_from_item_over_cte() {
7513 assert_snapshot!(goto("
7514create schema s;
7515create table s.t(a int);
7516with t as (select 1 a)
7517select t$0.a from s.t;
7518"), @r"
7519 ╭▸
7520 3 │ create table s.t(a int);
7521 │ ─ 2. destination
7522 4 │ with t as (select 1 a)
7523 5 │ select t.a from s.t;
7524 ╰╴ ─ 1. source
7525 ");
7526 }
7527
7528 #[test]
7529 fn goto_subquery_qualified_column() {
7530 assert_snapshot!(goto("
7531select t.a$0 from (select 1 a) t;
7532"), @r"
7533 ╭▸
7534 2 │ select t.a from (select 1 a) t;
7535 ╰╴ ─ 1. source ─ 2. destination
7536 ");
7537 }
7538
7539 #[test]
7540 fn goto_cte_multiple_columns() {
7541 assert_snapshot!(goto("
7542with x as (select 1 as a, 2 as b)
7543select b$0 from x;
7544"), @r"
7545 ╭▸
7546 2 │ with x as (select 1 as a, 2 as b)
7547 │ ─ 2. destination
7548 3 │ select b from x;
7549 ╰╴ ─ 1. source
7550 ");
7551 }
7552
7553 #[test]
7554 fn goto_cte_nested() {
7555 assert_snapshot!(goto("
7556with x as (select 1 as a),
7557 y as (select a from x)
7558select a$0 from y;
7559"), @r"
7560 ╭▸
7561 3 │ y as (select a from x)
7562 │ ─ 2. destination
7563 4 │ select a from y;
7564 ╰╴ ─ 1. source
7565 ");
7566 }
7567
7568 #[test]
7569 fn goto_cte_unnamed_column() {
7570 assert_snapshot!(goto(r#"
7571with x as (select 1)
7572select "?column?"$0 from x;
7573"#), @r#"
7574 ╭▸
7575 2 │ with x as (select 1)
7576 │ ─ 2. destination
7577 3 │ select "?column?" from x;
7578 ╰╴ ─ 1. source
7579 "#);
7580 }
7581
7582 #[test]
7583 fn goto_cte_star_expansion() {
7584 assert_snapshot!(goto("
7585with t as (select 1 a),
7586 y as (select * from t)
7587select a$0 from y;
7588"), @r"
7589 ╭▸
7590 2 │ with t as (select 1 a),
7591 │ ─ 2. destination
7592 3 │ y as (select * from t)
7593 4 │ select a from y;
7594 ╰╴ ─ 1. source
7595 ");
7596 }
7597
7598 #[test]
7599 fn goto_cte_qualified_star_join_column() {
7600 assert_snapshot!(goto("
7601create table u(id int, b int);
7602create table t(id int, a int);
7603
7604with k as (
7605 select u.* from t join u on a = b
7606)
7607select b$0 from k;
7608"), @r"
7609 ╭▸
7610 2 │ create table u(id int, b int);
7611 │ ─ 2. destination
7612 ‡
7613 8 │ select b from k;
7614 ╰╴ ─ 1. source
7615 ");
7616 }
7617
7618 #[test]
7619 fn goto_cte_qualified_star_join_column_with_partial_column_list() {
7620 assert_snapshot!(goto("
7621with
7622 u as (
7623 select 1 id, 2 b
7624 ),
7625 t as (
7626 select 1 id, 2 a
7627 ),
7628 k(x) as (
7629 select u.* from t join u on a = b
7630 )
7631select b$0 from k;
7632"), @r"
7633 ╭▸
7634 4 │ select 1 id, 2 b
7635 │ ─ 2. destination
7636 ‡
7637 12 │ select b from k;
7638 ╰╴ ─ 1. source
7639 ");
7640 }
7641
7642 #[test]
7643 fn goto_cte_reference_inside_cte() {
7644 assert_snapshot!(goto("
7645with t as (select 1 a),
7646 y as (select a$0 from t)
7647select a from y;
7648"), @r"
7649 ╭▸
7650 2 │ with t as (select 1 a),
7651 │ ─ 2. destination
7652 3 │ y as (select a from t)
7653 ╰╴ ─ 1. source
7654 ");
7655 }
7656
7657 #[test]
7658 fn goto_recursive_cte_reference_inside_cte() {
7659 assert_snapshot!(goto("
7660with recursive nums as (
7661 select 1 as n
7662 union all
7663 select n + 1 from nums$0 where n < 5
7664)
7665select * from nums;
7666"), @r"
7667 ╭▸
7668 2 │ with recursive nums as (
7669 │ ──── 2. destination
7670 ‡
7671 5 │ select n + 1 from nums where n < 5
7672 ╰╴ ─ 1. source
7673 ");
7674 }
7675
7676 #[test]
7677 fn goto_cte_search_clause_set_column() {
7678 assert_snapshot!(goto("
7679with recursive r as (select 1 as id)
7680 search depth first by id set ord
7681select ord$0 from r;
7682"), @"
7683 ╭▸
7684 3 │ search depth first by id set ord
7685 │ ─── 2. destination
7686 4 │ select ord from r;
7687 ╰╴ ─ 1. source
7688 ");
7689 }
7690
7691 #[test]
7692 fn goto_cte_search_clause_set_column_qualified() {
7693 assert_snapshot!(goto("
7694with recursive r as (select 1 as id)
7695 search depth first by id set ord
7696select r.ord$0 from r;
7697"), @"
7698 ╭▸
7699 3 │ search depth first by id set ord
7700 │ ─── 2. destination
7701 4 │ select r.ord from r;
7702 ╰╴ ─ 1. source
7703 ");
7704 }
7705
7706 #[test]
7707 fn goto_cte_cycle_clause_set_column() {
7708 assert_snapshot!(goto("
7709with recursive r as (select 1 as id)
7710 cycle id set is_cycle using path
7711select is_cycle$0 from r;
7712"), @"
7713 ╭▸
7714 3 │ cycle id set is_cycle using path
7715 │ ──────── 2. destination
7716 4 │ select is_cycle from r;
7717 ╰╴ ─ 1. source
7718 ");
7719 }
7720
7721 #[test]
7722 fn goto_cte_cycle_clause_path_column() {
7723 assert_snapshot!(goto("
7724with recursive r as (select 1 as id)
7725 cycle id set is_cycle using path
7726select path$0 from r;
7727"), @"
7728 ╭▸
7729 3 │ cycle id set is_cycle using path
7730 │ ──── 2. destination
7731 4 │ select path from r;
7732 ╰╴ ─ 1. source
7733 ");
7734 }
7735
7736 #[test]
7737 fn goto_cte_with_column_list() {
7738 assert_snapshot!(goto("
7739with t(a) as (select 1)
7740select a$0 from t;
7741"), @r"
7742 ╭▸
7743 2 │ with t(a) as (select 1)
7744 │ ─ 2. destination
7745 3 │ select a from t;
7746 ╰╴ ─ 1. source
7747 ");
7748 }
7749
7750 #[test]
7751 fn goto_cte_with_partial_column_list() {
7752 assert_snapshot!(goto("
7753with t(x) as (select 1 as a, 2 as b)
7754select b$0 from t;
7755"), @r"
7756 ╭▸
7757 2 │ with t(x) as (select 1 as a, 2 as b)
7758 │ ─ 2. destination
7759 3 │ select b from t;
7760 ╰╴ ─ 1. source
7761 ");
7762 }
7763
7764 #[test]
7765 fn goto_cte_with_partial_column_list_renamed() {
7766 assert_snapshot!(goto("
7767with t(x) as (select 1 as a, 2 as b)
7768select x$0 from t;
7769"), @r"
7770 ╭▸
7771 2 │ with t(x) as (select 1 as a, 2 as b)
7772 │ ─ 2. destination
7773 3 │ select x from t;
7774 ╰╴ ─ 1. source
7775 ");
7776 }
7777
7778 #[test]
7779 fn goto_cte_insert_returning_star_column() {
7780 assert_snapshot!(goto("
7781create table t(a int, b int);
7782with inserted as (
7783 insert into t values (1, 2), (3, 4)
7784 returning *
7785)
7786select a$0 from inserted;
7787"), @r"
7788 ╭▸
7789 2 │ create table t(a int, b int);
7790 │ ─ 2. destination
7791 ‡
7792 7 │ select a from inserted;
7793 ╰╴ ─ 1. source
7794 ");
7795 }
7796
7797 #[test]
7798 fn goto_cte_returning_qualified_star_column_gap() {
7799 assert_snapshot!(goto("
7800create table t(a int, b int);
7801with changed as (
7802 insert into t values (1, 2)
7803 returning new.*
7804)
7805select a$0 from changed;
7806"), @"
7807 ╭▸
7808 2 │ create table t(a int, b int);
7809 │ ─ 2. destination
7810 ‡
7811 7 │ select a from changed;
7812 ╰╴ ─ 1. source
7813 ");
7814 }
7815
7816 #[test]
7817 fn goto_cte_delete_returning_star_column() {
7818 assert_snapshot!(goto("
7819create table t(a int, b int);
7820with deleted as (
7821 delete from t
7822 returning *
7823)
7824select a$0 from deleted;
7825"), @r"
7826 ╭▸
7827 2 │ create table t(a int, b int);
7828 │ ─ 2. destination
7829 ‡
7830 7 │ select a from deleted;
7831 ╰╴ ─ 1. source
7832 ");
7833 }
7834
7835 #[test]
7836 fn goto_cte_update_returning_star_column() {
7837 assert_snapshot!(goto("
7838create table t(a int, b int);
7839with updated as (
7840 update t set a = 42
7841 returning *
7842)
7843select a$0 from updated;
7844"), @r"
7845 ╭▸
7846 2 │ create table t(a int, b int);
7847 │ ─ 2. destination
7848 ‡
7849 7 │ select a from updated;
7850 ╰╴ ─ 1. source
7851 ");
7852 }
7853
7854 #[test]
7855 fn goto_cte_update_returning_column_list_overwrites_column() {
7856 goto_not_found(
7857 "
7858create table t(a int, b int);
7859with updated(c) as (
7860 update t set a = 10
7861 returning a
7862)
7863select a$0 from updated;
7864",
7865 );
7866 }
7867
7868 #[test]
7869 fn goto_cte_column_list_overwrites_column() {
7870 goto_not_found(
7871 "
7872with t(x) as (select 1 as a)
7873select a$0 from t;
7874",
7875 );
7876 }
7877
7878 #[test]
7879 fn goto_cte_shadows_table() {
7880 assert_snapshot!(goto("
7881create table t(a int);
7882with t as (select a$0 from t)
7883select a from t;
7884"), @r"
7885 ╭▸
7886 2 │ create table t(a int);
7887 │ ─ 2. destination
7888 3 │ with t as (select a from t)
7889 ╰╴ ─ 1. source
7890 ");
7891 }
7892
7893 #[test]
7894 fn goto_subquery_column() {
7895 assert_snapshot!(goto("
7896select a$0 from (select 1 a);
7897"), @r"
7898 ╭▸
7899 2 │ select a from (select 1 a);
7900 ╰╴ ─ 1. source ─ 2. destination
7901 ");
7902 }
7903
7904 #[test]
7905 fn goto_subquery_star_partial_alias_masks_original_column_gap() {
7906 goto_not_found(
7907 "
7908create table t(a int, b int);
7909select a$0 from (select * from t) u(x);
7910",
7911 );
7912 }
7913
7914 #[test]
7915 fn goto_subquery_column_with_as() {
7916 assert_snapshot!(goto("
7917select a$0 from (select 1 as a);
7918"), @r"
7919 ╭▸
7920 2 │ select a from (select 1 as a);
7921 ╰╴ ─ 1. source ─ 2. destination
7922 ");
7923 }
7924
7925 #[test]
7926 fn goto_subquery_compound_select_column() {
7927 assert_snapshot!(goto("
7928select c$0 from (select 1 c union select 2 c);
7929"), @r"
7930 ╭▸
7931 2 │ select c from (select 1 c union select 2 c);
7932 ╰╴ ─ 1. source ─ 2. destination
7933 ");
7934 }
7935
7936 #[test]
7937 fn goto_subquery_compound_table_query_column() {
7938 assert_snapshot!(goto("
7939create table t(a int);
7940select a$0 from (table t union table t) u;
7941"), @"
7942 ╭▸
7943 2 │ create table t(a int);
7944 │ ─ 2. destination
7945 3 │ select a from (table t union table t) u;
7946 ╰╴ ─ 1. source
7947 ");
7948 }
7949
7950 #[test]
7951 fn goto_subquery_table_query_whole_row_alias() {
7952 assert_snapshot!(goto("
7953create table t(a int);
7954select t$0 from (table t) t;
7955"), @"
7956 ╭▸
7957 3 │ select t from (table t) t;
7958 ╰╴ ─ 1. source ─ 2. destination
7959 ");
7960 }
7961
7962 #[test]
7963 fn goto_subquery_compound_table_query_whole_row_alias() {
7964 assert_snapshot!(goto("
7965create table t(a int);
7966select t$0 from (table t union table t) t;
7967"), @"
7968 ╭▸
7969 3 │ select t from (table t union table t) t;
7970 ╰╴ ─ 1. source ─ 2. destination
7971 ");
7972 }
7973
7974 #[test]
7975 fn goto_subquery_compound_values_query_column() {
7976 assert_snapshot!(goto("
7977select column2$0 from (values (1, 2) union values (3, 4)) u;
7978"), @"
7979 ╭▸
7980 2 │ select column2 from (values (1, 2) union values (3, 4)) u;
7981 ╰╴ ─ 1. source ─ 2. destination
7982 ");
7983 }
7984
7985 #[test]
7986 fn goto_cte_compound_table_query_column() {
7987 assert_snapshot!(goto("
7988create table t(a int);
7989with u as (table t union table t)
7990select a$0 from u;
7991"), @"
7992 ╭▸
7993 2 │ create table t(a int);
7994 │ ─ 2. destination
7995 3 │ with u as (table t union table t)
7996 4 │ select a from u;
7997 ╰╴ ─ 1. source
7998 ");
7999 }
8000
8001 #[test]
8002 fn goto_cte_compound_values_query_column() {
8003 assert_snapshot!(goto("
8004with u as (values (1, 2) union values (3, 4))
8005select column2$0 from u;
8006"), @"
8007 ╭▸
8008 2 │ with u as (values (1, 2) union values (3, 4))
8009 │ ─ 2. destination
8010 3 │ select column2 from u;
8011 ╰╴ ─ 1. source
8012 ");
8013 }
8014
8015 #[test]
8016 fn goto_subquery_compound_select_column_order_by() {
8017 assert_snapshot!(goto("
8018with t as (select 1 a)
8019select 2 a from t union select 1 order by a$0;
8020"), @"
8021 ╭▸
8022 3 │ select 2 a from t union select 1 order by a;
8023 ╰╴ ─ 2. destination ─ 1. source
8024 ");
8025 }
8026
8027 #[test]
8028 fn goto_compound_table_query_column_order_by() {
8029 assert_snapshot!(goto("
8030create table t(a int);
8031table t union table t order by a$0;
8032"), @"
8033 ╭▸
8034 2 │ create table t(a int);
8035 │ ─ 2. destination
8036 3 │ table t union table t order by a;
8037 ╰╴ ─ 1. source
8038 ");
8039 }
8040
8041 #[test]
8042 fn goto_subquery_compound_select_column_with_nested_parens() {
8043 assert_snapshot!(goto("
8044with t as (
8045 select 1 as c
8046)
8047select c$0 from ((select * from t) union all (select * from t));
8048"), @r"
8049 ╭▸
8050 3 │ select 1 as c
8051 │ ─ 2. destination
8052 4 │ )
8053 5 │ select c from ((select * from t) union all (select * from t));
8054 ╰╴ ─ 1. source
8055 ");
8056 }
8057
8058 #[test]
8059 fn goto_subquery_column_multiple_columns() {
8060 assert_snapshot!(goto("
8061select b$0 from (select 1 a, 2 b);
8062"), @r"
8063 ╭▸
8064 2 │ select b from (select 1 a, 2 b);
8065 ╰╴ ─ 1. source ─ 2. destination
8066 ");
8067 }
8068
8069 #[test]
8070 fn goto_subquery_column_nested_parens() {
8071 assert_snapshot!(goto("
8072select a$0 from ((select 1 a));
8073"), @r"
8074 ╭▸
8075 2 │ select a from ((select 1 a));
8076 ╰╴ ─ 1. source ─ 2. destination
8077 ");
8078 }
8079
8080 #[test]
8081 fn goto_subquery_column_star_table() {
8082 assert_snapshot!(goto("
8083create table foo.t(a int);
8084select a$0 from (select * from foo.t);
8085"), @r"
8086 ╭▸
8087 2 │ create table foo.t(a int);
8088 │ ─ 2. destination
8089 3 │ select a from (select * from foo.t);
8090 ╰╴ ─ 1. source
8091 ");
8092 }
8093
8094 #[test]
8095 fn goto_subquery_column_qualified_star_join() {
8096 assert_snapshot!(goto("
8097create table t(a int);
8098create table u(b int);
8099select b$0 from (select u.* from t join u on a = b);
8100"), @r"
8101 ╭▸
8102 3 │ create table u(b int);
8103 │ ─ 2. destination
8104 4 │ select b from (select u.* from t join u on a = b);
8105 ╰╴ ─ 1. source
8106 ");
8107 }
8108
8109 #[test]
8110 fn goto_subquery_column_qualified_star_join_not_found() {
8111 goto_not_found(
8112 "
8113create table t(a int);
8114create table u(b int);
8115select a$0 from (select u.* from t join u on a = b);
8116",
8117 );
8118 }
8119
8120 #[test]
8121 fn goto_subquery_column_alias_list() {
8122 assert_snapshot!(goto("
8123select c$0, t.c from (select 1) t(c);
8124"), @r"
8125 ╭▸
8126 2 │ select c, t.c from (select 1) t(c);
8127 ╰╴ ─ 1. source ─ 2. destination
8128 ");
8129 }
8130
8131 #[test]
8132 fn goto_subquery_column_alias_list_qualified() {
8133 assert_snapshot!(goto("
8134select t.c$0 from (select 1) t(c);
8135"), @r"
8136 ╭▸
8137 2 │ select t.c from (select 1) t(c);
8138 ╰╴ ─ 1. source ─ 2. destination
8139 ");
8140 }
8141
8142 #[test]
8143 fn goto_subquery_column_alias_list_multiple() {
8144 assert_snapshot!(goto("
8145select b$0 from (select 1, 2) t(a, b);
8146"), @r"
8147 ╭▸
8148 2 │ select b from (select 1, 2) t(a, b);
8149 ╰╴ ─ 1. source ─ 2. destination
8150 ");
8151 }
8152
8153 #[test]
8154 fn goto_cte_column_alias_list() {
8155 assert_snapshot!(goto("
8156with x as (select 1)
8157select c$0 from x t(c);
8158"), @r"
8159 ╭▸
8160 3 │ select c from x t(c);
8161 │ ┬ ─ 2. destination
8162 │ │
8163 ╰╴ 1. source
8164 ");
8165 }
8166
8167 #[test]
8168 fn goto_cte_column_alias_list_qualified() {
8169 assert_snapshot!(goto("
8170with x as (select 1)
8171select t.c$0 from x t(c);
8172"), @r"
8173 ╭▸
8174 3 │ select t.c from x t(c);
8175 │ ┬ ─ 2. destination
8176 │ │
8177 ╰╴ 1. source
8178 ");
8179 }
8180
8181 #[test]
8182 fn goto_cte_column_alias_list_multiple() {
8183 assert_snapshot!(goto("
8184with x as (select 1, 2)
8185select b$0 from x t(a, b);
8186"), @r"
8187 ╭▸
8188 3 │ select b from x t(a, b);
8189 ╰╴ ─ 1. source ─ 2. destination
8190 ");
8191 }
8192
8193 #[test]
8194 fn goto_values_column_alias_list() {
8195 assert_snapshot!(goto("
8196select c$0 from (values (1)) t(c);
8197"), @r"
8198 ╭▸
8199 2 │ select c from (values (1)) t(c);
8200 ╰╴ ─ 1. source ─ 2. destination
8201 ");
8202 }
8203
8204 #[test]
8205 fn goto_values_column_alias_list_qualified() {
8206 assert_snapshot!(goto("
8207select t.c$0 from (values (1)) t(c);
8208"), @r"
8209 ╭▸
8210 2 │ select t.c from (values (1)) t(c);
8211 ╰╴ ─ 1. source ─ 2. destination
8212 ");
8213 }
8214
8215 #[test]
8216 fn goto_values_column_alias_list_multiple() {
8217 assert_snapshot!(goto("
8218select b$0 from (values (1, 2)) t(a, b);
8219"), @r"
8220 ╭▸
8221 2 │ select b from (values (1, 2)) t(a, b);
8222 ╰╴ ─ 1. source ─ 2. destination
8223 ");
8224 }
8225
8226 #[test]
8227 fn goto_values_column_alias_list_nested_parens() {
8228 assert_snapshot!(goto("
8229select n$0
8230from ((values (1), (2))) u(n);
8231"), @r"
8232 ╭▸
8233 2 │ select n
8234 │ ─ 1. source
8235 3 │ from ((values (1), (2))) u(n);
8236 ╰╴ ─ 2. destination
8237 ");
8238 }
8239
8240 #[test]
8241 fn goto_table_expr_column() {
8242 assert_snapshot!(goto("
8243create table t(a int, b int);
8244select a$0 from (table t);
8245"), @r"
8246 ╭▸
8247 2 │ create table t(a int, b int);
8248 │ ─ 2. destination
8249 3 │ select a from (table t);
8250 ╰╴ ─ 1. source
8251 ");
8252 }
8253
8254 #[test]
8255 fn goto_table_expr_column_with_cte() {
8256 assert_snapshot!(goto("
8257with x as (select 1 a)
8258select a$0 from (table x);
8259"), @r"
8260 ╭▸
8261 2 │ with x as (select 1 a)
8262 │ ─ 2. destination
8263 3 │ select a from (table x);
8264 ╰╴ ─ 1. source
8265 ");
8266 }
8267
8268 #[test]
8269 fn goto_table_expr_cte_table() {
8270 assert_snapshot!(goto("
8271with t as (select 1 a, 2 b)
8272select * from (table t$0);
8273"), @r"
8274 ╭▸
8275 2 │ with t as (select 1 a, 2 b)
8276 │ ─ 2. destination
8277 3 │ select * from (table t);
8278 ╰╴ ─ 1. source
8279 ");
8280 }
8281
8282 #[test]
8283 fn goto_table_expr_partial_column_alias_list() {
8284 assert_snapshot!(goto("
8285with t as (select 1 a, 2 b)
8286select c, b$0 from (table t) u(c);
8287"), @r"
8288 ╭▸
8289 2 │ with t as (select 1 a, 2 b)
8290 │ ─ 2. destination
8291 3 │ select c, b from (table t) u(c);
8292 ╰╴ ─ 1. source
8293 ");
8294 }
8295
8296 #[test]
8297 fn goto_subquery_partial_column_alias_list() {
8298 assert_snapshot!(goto("
8299select x, b$0 from (select 1 a, 2 b) t(x);
8300"), @r"
8301 ╭▸
8302 2 │ select x, b from (select 1 a, 2 b) t(x);
8303 ╰╴ ─ 1. source ─ 2. destination
8304 ");
8305 }
8306
8307 #[test]
8308 fn goto_subquery_alias_with_column_list_table_ref() {
8309 assert_snapshot!(goto("
8310with t as (select 1 a, 2 b)
8311select z$0 from (select * from t) as z(x, y);
8312"), @"
8313 ╭▸
8314 3 │ select z from (select * from t) as z(x, y);
8315 ╰╴ ─ 1. source ─ 2. destination
8316 ");
8317 }
8318
8319 #[test]
8320 fn goto_subquery_alias_with_column_list_table_ref_shadows_column() {
8321 assert_snapshot!(goto("
8322with t as (select 1 a, 2 b)
8323select z$0 from (select a as z, b from t) as z(x, y);
8324"), @"
8325 ╭▸
8326 3 │ select z from (select a as z, b from t) as z(x, y);
8327 ╰╴ ─ 1. source ─ 2. destination
8328 ");
8329 }
8330
8331 #[test]
8332 fn goto_subquery_nested_paren_alias_with_column_list_table_ref() {
8333 assert_snapshot!(goto("
8334with t as (select 1 a, 2 b, 3 c)
8335select z$0 from ((select * from t)) as z(x, y);
8336"), @"
8337 ╭▸
8338 3 │ select z from ((select * from t)) as z(x, y);
8339 ╰╴ ─ 1. source ─ 2. destination
8340 ");
8341 }
8342
8343 #[test]
8344 fn goto_table_expr_values_cte_partial_alias() {
8345 assert_snapshot!(goto("
8346with t as (values (1, 2), (3, 4))
8347select column2$0 from (table t) u(a);
8348"), @r"
8349 ╭▸
8350 2 │ with t as (values (1, 2), (3, 4))
8351 │ ─ 2. destination
8352 3 │ select column2 from (table t) u(a);
8353 ╰╴ ─ 1. source
8354 ");
8355 }
8356
8357 #[test]
8358 fn goto_cte_with_table_expr() {
8359 assert_snapshot!(goto("
8360create table t(a int, b int);
8361with u as (table t)
8362select a$0 from u;
8363"), @r"
8364 ╭▸
8365 2 │ create table t(a int, b int);
8366 │ ─ 2. destination
8367 3 │ with u as (table t)
8368 4 │ select a from u;
8369 ╰╴ ─ 1. source
8370 ");
8371 }
8372
8373 #[test]
8374 fn goto_cte_with_table_expr_nested() {
8375 assert_snapshot!(goto("
8376with t as (select 1 a, 2 b),
8377 u as (table t)
8378select b$0 from u;
8379"), @r"
8380 ╭▸
8381 2 │ with t as (select 1 a, 2 b),
8382 │ ─ 2. destination
8383 3 │ u as (table t)
8384 4 │ select b from u;
8385 ╰╴ ─ 1. source
8386 ");
8387 }
8388
8389 #[test]
8390 fn goto_cte_paren_table_query_column() {
8391 assert_snapshot!(goto("
8392create table t(a int);
8393with u as ((table t))
8394select a$0 from u;
8395"), @"
8396 ╭▸
8397 2 │ create table t(a int);
8398 │ ─ 2. destination
8399 3 │ with u as ((table t))
8400 4 │ select a from u;
8401 ╰╴ ─ 1. source
8402 ");
8403 }
8404
8405 #[test]
8406 fn goto_cte_paren_values_query_column() {
8407 assert_snapshot!(goto("
8408with u as ((values (1, 2)))
8409select column2$0 from u;
8410"), @"
8411 ╭▸
8412 2 │ with u as ((values (1, 2)))
8413 │ ─ 2. destination
8414 3 │ select column2 from u;
8415 ╰╴ ─ 1. source
8416 ");
8417 }
8418
8419 #[test]
8420 fn goto_cte_table_query_column_count_gap() {
8421 assert_snapshot!(goto("
8422create table t(a int, b int);
8423with u as (table t)
8424select b$0 from (select * from u) x(a);
8425"), @"
8426 ╭▸
8427 2 │ create table t(a int, b int);
8428 │ ─ 2. destination
8429 3 │ with u as (table t)
8430 4 │ select b from (select * from u) x(a);
8431 ╰╴ ─ 1. source
8432 ");
8433 }
8434
8435 #[test]
8436 fn goto_insert_table() {
8437 assert_snapshot!(goto("
8438create table users(id int, email text);
8439insert into users$0(id, email) values (1, 'test@example.com');
8440"), @r"
8441 ╭▸
8442 2 │ create table users(id int, email text);
8443 │ ───── 2. destination
8444 3 │ insert into users(id, email) values (1, 'test@example.com');
8445 ╰╴ ─ 1. source
8446 ");
8447 }
8448
8449 #[test]
8450 fn goto_insert_table_with_schema() {
8451 assert_snapshot!(goto("
8452create table public.users(id int, email text);
8453insert into public.users$0(id, email) values (1, 'test@example.com');
8454"), @r"
8455 ╭▸
8456 2 │ create table public.users(id int, email text);
8457 │ ───── 2. destination
8458 3 │ insert into public.users(id, email) values (1, 'test@example.com');
8459 ╰╴ ─ 1. source
8460 ");
8461 }
8462
8463 #[test]
8464 fn goto_insert_view() {
8465 assert_snapshot!(goto("
8466create table users as select 1 id, 'joe' name, 'joe@example.com' email, 'active' status;
8467create view active_users as
8468 select id, name, email
8469 from users
8470 where status = 'active';
8471insert into active_users$0 (name, email)
8472values ('Alice', 'alice@example.com');
8473"), @"
8474 ╭▸
8475 3 │ create view active_users as
8476 │ ──────────── 2. destination
8477 ‡
8478 7 │ insert into active_users (name, email)
8479 ╰╴ ─ 1. source
8480 ");
8481 }
8482
8483 #[test]
8484 fn goto_insert_column() {
8485 assert_snapshot!(goto("
8486create table users(id int, email text);
8487insert into users(id$0, email) values (1, 'test@example.com');
8488"), @r"
8489 ╭▸
8490 2 │ create table users(id int, email text);
8491 │ ── 2. destination
8492 3 │ insert into users(id, email) values (1, 'test@example.com');
8493 ╰╴ ─ 1. source
8494 ");
8495 }
8496
8497 #[test]
8498 fn goto_insert_column_second() {
8499 assert_snapshot!(goto("
8500create table users(id int, email text);
8501insert into users(id, email$0) values (1, 'test@example.com');
8502"), @r"
8503 ╭▸
8504 2 │ create table users(id int, email text);
8505 │ ───── 2. destination
8506 3 │ insert into users(id, email) values (1, 'test@example.com');
8507 ╰╴ ─ 1. source
8508 ");
8509 }
8510
8511 #[test]
8512 fn goto_insert_column_with_schema() {
8513 assert_snapshot!(goto("
8514create table public.users(id int, email text);
8515insert into public.users(email$0) values ('test@example.com');
8516"), @r"
8517 ╭▸
8518 2 │ create table public.users(id int, email text);
8519 │ ───── 2. destination
8520 3 │ insert into public.users(email) values ('test@example.com');
8521 ╰╴ ─ 1. source
8522 ");
8523 }
8524
8525 #[test]
8526 fn goto_insert_table_with_search_path() {
8527 assert_snapshot!(goto("
8528set search_path to foo;
8529create table foo.users(id int, email text);
8530insert into users$0(id, email) values (1, 'test@example.com');
8531"), @r"
8532 ╭▸
8533 3 │ create table foo.users(id int, email text);
8534 │ ───── 2. destination
8535 4 │ insert into users(id, email) values (1, 'test@example.com');
8536 ╰╴ ─ 1. source
8537 ");
8538 }
8539
8540 #[test]
8541 fn goto_insert_column_with_search_path() {
8542 assert_snapshot!(goto("
8543set search_path to myschema;
8544create table myschema.users(id int, email text, name text);
8545insert into users(email$0, name) values ('test@example.com', 'Test');
8546"), @r"
8547 ╭▸
8548 3 │ create table myschema.users(id int, email text, name text);
8549 │ ───── 2. destination
8550 4 │ insert into users(email, name) values ('test@example.com', 'Test');
8551 ╰╴ ─ 1. source
8552 ");
8553 }
8554
8555 #[test]
8556 fn goto_delete_table() {
8557 assert_snapshot!(goto("
8558create table users(id int, email text);
8559delete from users$0 where id = 1;
8560"), @r"
8561 ╭▸
8562 2 │ create table users(id int, email text);
8563 │ ───── 2. destination
8564 3 │ delete from users where id = 1;
8565 ╰╴ ─ 1. source
8566 ");
8567 }
8568
8569 #[test]
8570 fn goto_delete_table_with_schema() {
8571 assert_snapshot!(goto("
8572create table public.users(id int, email text);
8573delete from public.users$0 where id = 1;
8574"), @r"
8575 ╭▸
8576 2 │ create table public.users(id int, email text);
8577 │ ───── 2. destination
8578 3 │ delete from public.users where id = 1;
8579 ╰╴ ─ 1. source
8580 ");
8581 }
8582
8583 #[test]
8584 fn goto_delete_table_with_search_path() {
8585 assert_snapshot!(goto("
8586set search_path to foo;
8587create table foo.users(id int, email text);
8588delete from users$0 where id = 1;
8589"), @r"
8590 ╭▸
8591 3 │ create table foo.users(id int, email text);
8592 │ ───── 2. destination
8593 4 │ delete from users where id = 1;
8594 ╰╴ ─ 1. source
8595 ");
8596 }
8597
8598 #[test]
8599 fn goto_delete_temp_table() {
8600 assert_snapshot!(goto("
8601create temp table users(id int, email text);
8602delete from users$0 where id = 1;
8603"), @r"
8604 ╭▸
8605 2 │ create temp table users(id int, email text);
8606 │ ───── 2. destination
8607 3 │ delete from users where id = 1;
8608 ╰╴ ─ 1. source
8609 ");
8610 }
8611
8612 #[test]
8613 fn goto_delete_where_column() {
8614 assert_snapshot!(goto("
8615create table users(id int, email text);
8616delete from users where id$0 = 1;
8617"), @r"
8618 ╭▸
8619 2 │ create table users(id int, email text);
8620 │ ── 2. destination
8621 3 │ delete from users where id = 1;
8622 ╰╴ ─ 1. source
8623 ");
8624 }
8625
8626 #[test]
8627 fn goto_delete_where_column_second() {
8628 assert_snapshot!(goto("
8629create table users(id int, email text);
8630delete from users where email$0 = 'test@example.com';
8631"), @r"
8632 ╭▸
8633 2 │ create table users(id int, email text);
8634 │ ───── 2. destination
8635 3 │ delete from users where email = 'test@example.com';
8636 ╰╴ ─ 1. source
8637 ");
8638 }
8639
8640 #[test]
8641 fn goto_delete_where_column_with_schema() {
8642 assert_snapshot!(goto("
8643create table public.users(id int, email text, name text);
8644delete from public.users where name$0 = 'Test';
8645"), @r"
8646 ╭▸
8647 2 │ create table public.users(id int, email text, name text);
8648 │ ──── 2. destination
8649 3 │ delete from public.users where name = 'Test';
8650 ╰╴ ─ 1. source
8651 ");
8652 }
8653
8654 #[test]
8655 fn goto_delete_where_column_with_search_path() {
8656 assert_snapshot!(goto("
8657set search_path to myschema;
8658create table myschema.users(id int, email text, active boolean);
8659delete from users where active$0 = true;
8660"), @r"
8661 ╭▸
8662 3 │ create table myschema.users(id int, email text, active boolean);
8663 │ ────── 2. destination
8664 4 │ delete from users where active = true;
8665 ╰╴ ─ 1. source
8666 ");
8667 }
8668
8669 #[test]
8670 fn goto_delete_where_multiple_columns() {
8671 assert_snapshot!(goto("
8672create table users(id int, email text, active boolean);
8673delete from users where id$0 = 1 and active = true;
8674"), @r"
8675 ╭▸
8676 2 │ create table users(id int, email text, active boolean);
8677 │ ── 2. destination
8678 3 │ delete from users where id = 1 and active = true;
8679 ╰╴ ─ 1. source
8680 ");
8681 }
8682
8683 #[test]
8684 fn goto_delete_using_table() {
8685 assert_snapshot!(goto("
8686create table t(id int, f_id int);
8687create table f(id int, name text);
8688delete from t using f$0 where f_id = f.id and f.name = 'foo';
8689"), @r"
8690 ╭▸
8691 3 │ create table f(id int, name text);
8692 │ ─ 2. destination
8693 4 │ delete from t using f where f_id = f.id and f.name = 'foo';
8694 ╰╴ ─ 1. source
8695 ");
8696 }
8697
8698 #[test]
8699 fn goto_delete_using_table_with_schema() {
8700 assert_snapshot!(goto("
8701create table t(id int, f_id int);
8702create table public.f(id int, name text);
8703delete from t using public.f$0 where f_id = f.id;
8704"), @r"
8705 ╭▸
8706 3 │ create table public.f(id int, name text);
8707 │ ─ 2. destination
8708 4 │ delete from t using public.f where f_id = f.id;
8709 ╰╴ ─ 1. source
8710 ");
8711 }
8712
8713 #[test]
8714 fn goto_delete_using_column_in_where() {
8715 assert_snapshot!(goto("
8716create table t(id int, f_id int);
8717create table f(id int, name text);
8718delete from t using f where f_id = f.id$0 and f.name = 'foo';
8719"), @"
8720 ╭▸
8721 3 │ create table f(id int, name text);
8722 │ ── 2. destination
8723 4 │ delete from t using f where f_id = f.id and f.name = 'foo';
8724 ╰╴ ─ 1. source
8725 ");
8726 }
8727
8728 #[test]
8729 fn goto_delete_using_source_alias_qualifier() {
8730 assert_snapshot!(goto("
8731create table target(id int);
8732create table src(y int);
8733delete from target using src s where s$0.y = target.id;
8734"), @"
8735 ╭▸
8736 4 │ delete from target using src s where s.y = target.id;
8737 │ ┬ ─ 1. source
8738 │ │
8739 ╰╴ 2. destination
8740 ");
8741 }
8742
8743 #[test]
8744 fn goto_delete_using_source_alias_column() {
8745 assert_snapshot!(goto("
8746create table target(id int);
8747create table src(y int);
8748delete from target using src s where s.y$0 = target.id;
8749"), @"
8750 ╭▸
8751 3 │ create table src(y int);
8752 │ ─ 2. destination
8753 4 │ delete from target using src s where s.y = target.id;
8754 ╰╴ ─ 1. source
8755 ");
8756 }
8757
8758 #[test]
8759 fn goto_select_from_table() {
8760 assert_snapshot!(goto("
8761create table users(id int, email text);
8762select * from users$0;
8763"), @r"
8764 ╭▸
8765 2 │ create table users(id int, email text);
8766 │ ───── 2. destination
8767 3 │ select * from users;
8768 ╰╴ ─ 1. source
8769 ");
8770 }
8771
8772 #[test]
8773 fn goto_select_from_table_with_schema() {
8774 assert_snapshot!(goto("
8775create table public.users(id int, email text);
8776select * from public.users$0;
8777"), @r"
8778 ╭▸
8779 2 │ create table public.users(id int, email text);
8780 │ ───── 2. destination
8781 3 │ select * from public.users;
8782 ╰╴ ─ 1. source
8783 ");
8784 }
8785
8786 #[test]
8787 fn goto_select_from_table_with_search_path() {
8788 assert_snapshot!(goto("
8789set search_path to foo;
8790create table foo.users(id int, email text);
8791select * from users$0;
8792"), @r"
8793 ╭▸
8794 3 │ create table foo.users(id int, email text);
8795 │ ───── 2. destination
8796 4 │ select * from users;
8797 ╰╴ ─ 1. source
8798 ");
8799 }
8800
8801 #[test]
8802 fn goto_select_from_temp_table() {
8803 assert_snapshot!(goto("
8804create temp table users(id int, email text);
8805select * from users$0;
8806"), @r"
8807 ╭▸
8808 2 │ create temp table users(id int, email text);
8809 │ ───── 2. destination
8810 3 │ select * from users;
8811 ╰╴ ─ 1. source
8812 ");
8813 }
8814
8815 #[test]
8816 fn goto_select_from_table_defined_after() {
8817 assert_snapshot!(goto("
8818select * from users$0;
8819create table users(id int, email text);
8820"), @r"
8821 ╭▸
8822 2 │ select * from users;
8823 │ ─ 1. source
8824 3 │ create table users(id int, email text);
8825 ╰╴ ───── 2. destination
8826 ");
8827 }
8828
8829 #[test]
8830 fn goto_select_column() {
8831 assert_snapshot!(goto("
8832create table users(id int, email text);
8833select id$0 from users;
8834"), @r"
8835 ╭▸
8836 2 │ create table users(id int, email text);
8837 │ ── 2. destination
8838 3 │ select id from users;
8839 ╰╴ ─ 1. source
8840 ");
8841 }
8842
8843 #[test]
8844 fn goto_select_column_second() {
8845 assert_snapshot!(goto("
8846create table users(id int, email text);
8847select id, email$0 from users;
8848"), @r"
8849 ╭▸
8850 2 │ create table users(id int, email text);
8851 │ ───── 2. destination
8852 3 │ select id, email from users;
8853 ╰╴ ─ 1. source
8854 ");
8855 }
8856
8857 #[test]
8858 fn goto_select_column_with_schema() {
8859 assert_snapshot!(goto("
8860create table public.users(id int, email text);
8861select email$0 from public.users;
8862"), @r"
8863 ╭▸
8864 2 │ create table public.users(id int, email text);
8865 │ ───── 2. destination
8866 3 │ select email from public.users;
8867 ╰╴ ─ 1. source
8868 ");
8869 }
8870
8871 #[test]
8872 fn goto_select_column_with_search_path() {
8873 assert_snapshot!(goto("
8874set search_path to foo;
8875create table foo.users(id int, email text);
8876select id$0 from users;
8877"), @r"
8878 ╭▸
8879 3 │ create table foo.users(id int, email text);
8880 │ ── 2. destination
8881 4 │ select id from users;
8882 ╰╴ ─ 1. source
8883 ");
8884 }
8885
8886 #[test]
8887 fn goto_select_table_as_column() {
8888 assert_snapshot!(goto("
8889create table t(x bigint, y bigint);
8890select t$0 from t;
8891"), @r"
8892 ╭▸
8893 2 │ create table t(x bigint, y bigint);
8894 │ ─ 2. destination
8895 3 │ select t from t;
8896 ╰╴ ─ 1. source
8897 ");
8898 }
8899
8900 #[test]
8901 fn goto_select_table_star_expansion() {
8902 assert_snapshot!(goto("
8903create table t(id int, a int);
8904select t$0.* from t;
8905"), @r"
8906 ╭▸
8907 2 │ create table t(id int, a int);
8908 │ ─ 2. destination
8909 3 │ select t.* from t;
8910 ╰╴ ─ 1. source
8911 ");
8912 }
8913
8914 #[test]
8915 fn goto_select_table_as_column_with_schema() {
8916 assert_snapshot!(goto("
8917create table public.t(x bigint, y bigint);
8918select t$0 from public.t;
8919"), @r"
8920 ╭▸
8921 2 │ create table public.t(x bigint, y bigint);
8922 │ ─ 2. destination
8923 3 │ select t from public.t;
8924 ╰╴ ─ 1. source
8925 ");
8926 }
8927
8928 #[test]
8929 fn goto_select_table_as_column_with_search_path() {
8930 assert_snapshot!(goto("
8931set search_path to foo;
8932create table foo.users(id int, email text);
8933select users$0 from users;
8934"), @r"
8935 ╭▸
8936 3 │ create table foo.users(id int, email text);
8937 │ ───── 2. destination
8938 4 │ select users from users;
8939 ╰╴ ─ 1. source
8940 ");
8941 }
8942
8943 #[test]
8944 fn goto_select_column_with_same_name_as_table() {
8945 assert_snapshot!(goto("
8946create table t(t int);
8947select t$0 from t;
8948"), @r"
8949 ╭▸
8950 2 │ create table t(t int);
8951 │ ─ 2. destination
8952 3 │ select t from t;
8953 ╰╴ ─ 1. source
8954 ");
8955 }
8956
8957 #[test]
8958 fn goto_select_view_name_from_view() {
8959 assert_snapshot!(goto("
8960create view boop as select 1 a;
8961select boop$0 from boop;
8962"), @"
8963 ╭▸
8964 2 │ create view boop as select 1 a;
8965 │ ──── 2. destination
8966 3 │ select boop from boop;
8967 ╰╴ ─ 1. source
8968 ");
8969 }
8970
8971 #[test]
8972 fn goto_drop_schema() {
8973 assert_snapshot!(goto("
8974create schema foo;
8975drop schema foo$0;
8976"), @r"
8977 ╭▸
8978 2 │ create schema foo;
8979 │ ─── 2. destination
8980 3 │ drop schema foo;
8981 ╰╴ ─ 1. source
8982 ");
8983 }
8984
8985 #[test]
8986 fn goto_create_schema_authorization() {
8987 assert_snapshot!(goto("
8988create schema authorization foo$0;
8989"), @r"
8990 ╭▸
8991 2 │ create schema authorization foo;
8992 │ ┬─┬
8993 │ │ │
8994 │ │ 1. source
8995 ╰╴ 2. destination
8996 ");
8997 }
8998
8999 #[test]
9000 fn goto_drop_schema_authorization() {
9001 assert_snapshot!(goto("
9002create schema authorization foo;
9003drop schema foo$0;
9004"), @r"
9005 ╭▸
9006 2 │ create schema authorization foo;
9007 │ ─── 2. destination
9008 3 │ drop schema foo;
9009 ╰╴ ─ 1. source
9010 ");
9011 }
9012
9013 #[test]
9014 fn goto_drop_schema_defined_after() {
9015 assert_snapshot!(goto("
9016drop schema foo$0;
9017create schema foo;
9018"), @r"
9019 ╭▸
9020 2 │ drop schema foo;
9021 │ ─ 1. source
9022 3 │ create schema foo;
9023 ╰╴ ─── 2. destination
9024 ");
9025 }
9026
9027 #[test]
9028 fn goto_create_schema_embedded_table() {
9029 assert_snapshot!(goto("
9030create schema app create table users(id int);
9031select id from app.users$0;
9032"), @"
9033 ╭▸
9034 2 │ create schema app create table users(id int);
9035 │ ───── 2. destination
9036 3 │ select id from app.users;
9037 ╰╴ ─ 1. source
9038 ");
9039 }
9040
9041 #[test]
9042 fn goto_create_schema_embedded_table_column() {
9043 assert_snapshot!(goto("
9044create schema app create table users(id int);
9045select id$0 from app.users;
9046"), @"
9047 ╭▸
9048 2 │ create schema app create table users(id int);
9049 │ ── 2. destination
9050 3 │ select id from app.users;
9051 ╰╴ ─ 1. source
9052 ");
9053 }
9054
9055 #[test]
9056 fn goto_create_schema_embedded_view() {
9057 assert_snapshot!(goto("
9058create schema app create table users(id int) create view v as select 1;
9059select 1 from app.v$0;
9060"), @"
9061 ╭▸
9062 2 │ create schema app create table users(id int) create view v as select 1;
9063 │ ─ 2. destination
9064 3 │ select 1 from app.v;
9065 ╰╴ ─ 1. source
9066 ");
9067 }
9068
9069 #[test]
9070 fn goto_schema_qualifier_in_table() {
9071 assert_snapshot!(goto("
9072create schema foo;
9073create table foo$0.t(a int);
9074"), @r"
9075 ╭▸
9076 2 │ create schema foo;
9077 │ ─── 2. destination
9078 3 │ create table foo.t(a int);
9079 ╰╴ ─ 1. source
9080 ");
9081 }
9082
9083 #[test]
9084 fn goto_schema_qualifier_in_drop_table() {
9085 assert_snapshot!(goto("
9086create schema foo;
9087create table foo.t(a int);
9088drop table foo$0.t;
9089"), @r"
9090 ╭▸
9091 2 │ create schema foo;
9092 │ ─── 2. destination
9093 3 │ create table foo.t(a int);
9094 4 │ drop table foo.t;
9095 ╰╴ ─ 1. source
9096 ");
9097 }
9098
9099 #[test]
9100 fn goto_schema_qualifier_multiple_schemas() {
9101 assert_snapshot!(goto("
9102create schema foo;
9103create schema bar;
9104create table bar$0.t(a int);
9105"), @r"
9106 ╭▸
9107 3 │ create schema bar;
9108 │ ─── 2. destination
9109 4 │ create table bar.t(a int);
9110 ╰╴ ─ 1. source
9111 ");
9112 }
9113
9114 #[test]
9115 fn goto_schema_qualifier_in_function_call() {
9116 assert_snapshot!(goto(r#"
9117create schema foo;
9118create function foo.bar() returns int as $$ begin return 1; end; $$ language plpgsql;
9119select foo$0.bar();
9120"#), @r"
9121 ╭▸
9122 2 │ create schema foo;
9123 │ ─── 2. destination
9124 3 │ create function foo.bar() returns int as $$ begin return 1; end; $$ language plpgsql;
9125 4 │ select foo.bar();
9126 ╰╴ ─ 1. source
9127 ");
9128 }
9129
9130 #[test]
9131 fn goto_schema_qualifier_in_function_call_from_clause() {
9132 assert_snapshot!(goto(r#"
9133create schema myschema;
9134create function myschema.get_data() returns table(id int) as $$ begin return query select 1; end; $$ language plpgsql;
9135select * from myschema$0.get_data();
9136"#), @r"
9137 ╭▸
9138 2 │ create schema myschema;
9139 │ ──────── 2. destination
9140 3 │ create function myschema.get_data() returns table(id int) as $$ begin return query select 1; end; $$ language plpgsql;
9141 4 │ select * from myschema.get_data();
9142 ╰╴ ─ 1. source
9143 ");
9144 }
9145
9146 #[test]
9147 fn goto_schema_qualifier_in_select_from() {
9148 assert_snapshot!(goto("
9149create schema foo;
9150create table foo.t(x int);
9151select x from foo$0.t;
9152"), @r"
9153 ╭▸
9154 2 │ create schema foo;
9155 │ ─── 2. destination
9156 3 │ create table foo.t(x int);
9157 4 │ select x from foo.t;
9158 ╰╴ ─ 1. source
9159 ");
9160 }
9161
9162 #[test]
9163 fn goto_qualified_column_table() {
9164 assert_snapshot!(goto("
9165create table t(a int);
9166select t$0.a from t;
9167"), @r"
9168 ╭▸
9169 2 │ create table t(a int);
9170 │ ─ 2. destination
9171 3 │ select t.a from t;
9172 ╰╴ ─ 1. source
9173 ");
9174 }
9175
9176 #[test]
9177 fn goto_qualified_column_column() {
9178 assert_snapshot!(goto("
9179create table t(a int);
9180select t.a$0 from t;
9181"), @r"
9182 ╭▸
9183 2 │ create table t(a int);
9184 │ ─ 2. destination
9185 3 │ select t.a from t;
9186 ╰╴ ─ 1. source
9187 ");
9188 }
9189
9190 #[test]
9191 fn goto_three_part_qualified_column_schema() {
9192 assert_snapshot!(goto("
9193create schema foo;
9194create table foo.t(a int);
9195select foo$0.t.a from t;
9196"), @r"
9197 ╭▸
9198 2 │ create schema foo;
9199 │ ─── 2. destination
9200 3 │ create table foo.t(a int);
9201 4 │ select foo.t.a from t;
9202 ╰╴ ─ 1. source
9203 ");
9204 }
9205
9206 #[test]
9207 fn goto_three_part_qualified_column_table() {
9208 assert_snapshot!(goto("
9209create schema foo;
9210create table foo.t(a int);
9211select foo.t$0.a from t;
9212"), @r"
9213 ╭▸
9214 3 │ create table foo.t(a int);
9215 │ ─ 2. destination
9216 4 │ select foo.t.a from t;
9217 ╰╴ ─ 1. source
9218 ");
9219 }
9220
9221 #[test]
9222 fn goto_three_part_qualified_column_column() {
9223 assert_snapshot!(goto("
9224create schema foo;
9225create table foo.t(a int);
9226select foo.t.a$0 from t;
9227"), @r"
9228 ╭▸
9229 3 │ create table foo.t(a int);
9230 │ ─ 2. destination
9231 4 │ select foo.t.a from t;
9232 ╰╴ ─ 1. source
9233 ");
9234 }
9235
9236 #[test]
9237 fn goto_cte_values_column1() {
9238 assert_snapshot!(goto("
9239with t as (
9240 values (1, 2), (3, 4)
9241)
9242select column1$0, column2 from t;
9243"), @r"
9244 ╭▸
9245 3 │ values (1, 2), (3, 4)
9246 │ ─ 2. destination
9247 4 │ )
9248 5 │ select column1, column2 from t;
9249 ╰╴ ─ 1. source
9250 ");
9251 }
9252
9253 #[test]
9254 fn goto_cte_values_column2() {
9255 assert_snapshot!(goto("
9256with t as (
9257 values (1, 2), (3, 4)
9258)
9259select column1, column2$0 from t;
9260"), @r"
9261 ╭▸
9262 3 │ values (1, 2), (3, 4)
9263 │ ─ 2. destination
9264 4 │ )
9265 5 │ select column1, column2 from t;
9266 ╰╴ ─ 1. source
9267 ");
9268 }
9269
9270 #[test]
9271 fn goto_cte_values_single_column() {
9272 assert_snapshot!(goto("
9273with t as (
9274 values (1), (2), (3)
9275)
9276select column1$0 from t;
9277"), @r"
9278 ╭▸
9279 3 │ values (1), (2), (3)
9280 │ ─ 2. destination
9281 4 │ )
9282 5 │ select column1 from t;
9283 ╰╴ ─ 1. source
9284 ");
9285 }
9286
9287 #[test]
9288 fn goto_cte_values_multiple_rows() {
9289 assert_snapshot!(goto("
9290with t as (
9291 values
9292 (1, 2, 3),
9293 (4, 5, 6),
9294 (7, 8, 9)
9295)
9296select column3$0 from t;
9297"), @r"
9298 ╭▸
9299 4 │ (1, 2, 3),
9300 │ ─ 2. destination
9301 ‡
9302 8 │ select column3 from t;
9303 ╰╴ ─ 1. source
9304 ");
9305 }
9306
9307 #[test]
9308 fn goto_cte_values_uppercase_column_names() {
9309 assert_snapshot!(goto("
9310with t as (
9311 values (1, 2), (3, 4)
9312)
9313select COLUMN1$0, COLUMN2 from t;
9314"), @r"
9315 ╭▸
9316 3 │ values (1, 2), (3, 4)
9317 │ ─ 2. destination
9318 4 │ )
9319 5 │ select COLUMN1, COLUMN2 from t;
9320 ╰╴ ─ 1. source
9321 ");
9322 }
9323
9324 #[test]
9325 fn goto_cte_values_with_explicit_column_list_column1_not_found() {
9326 goto_not_found(
9327 "
9328with t(a, b) as (
9329 values (1, 2), (3, 4)
9330)
9331select column1$0 from t;
9332",
9333 );
9334 }
9335
9336 #[test]
9337 fn goto_qualified_column_with_schema_in_from_table() {
9338 assert_snapshot!(goto("
9339create table foo.t(a int, b int);
9340select t$0.a from foo.t;
9341"), @r"
9342 ╭▸
9343 2 │ create table foo.t(a int, b int);
9344 │ ─ 2. destination
9345 3 │ select t.a from foo.t;
9346 ╰╴ ─ 1. source
9347 ");
9348 }
9349
9350 #[test]
9351 fn goto_qualified_column_with_schema_in_from_column() {
9352 assert_snapshot!(goto("
9353create table foo.t(a int, b int);
9354select t.a$0 from foo.t;
9355"), @r"
9356 ╭▸
9357 2 │ create table foo.t(a int, b int);
9358 │ ─ 2. destination
9359 3 │ select t.a from foo.t;
9360 ╰╴ ─ 1. source
9361 ");
9362 }
9363
9364 #[test]
9365 fn goto_cte_union_all_column() {
9366 assert_snapshot!(goto("
9367with t as (
9368 select 1 as a, 2 as b
9369 union all
9370 select 3, 4
9371)
9372select a$0, b from t;
9373"), @r"
9374 ╭▸
9375 3 │ select 1 as a, 2 as b
9376 │ ─ 2. destination
9377 ‡
9378 7 │ select a, b from t;
9379 ╰╴ ─ 1. source
9380 ");
9381 }
9382
9383 #[test]
9384 fn goto_cte_union_all_column_second() {
9385 assert_snapshot!(goto("
9386with t as (
9387 select 1 as a, 2 as b
9388 union all
9389 select 3, 4
9390)
9391select a, b$0 from t;
9392"), @r"
9393 ╭▸
9394 3 │ select 1 as a, 2 as b
9395 │ ─ 2. destination
9396 ‡
9397 7 │ select a, b from t;
9398 ╰╴ ─ 1. source
9399 ");
9400 }
9401
9402 #[test]
9403 fn goto_cte_union_column() {
9404 assert_snapshot!(goto("
9405with t as (
9406 select 1 as a, 2 as b
9407 union
9408 select 3, 4
9409)
9410select a$0 from t;
9411"), @r"
9412 ╭▸
9413 3 │ select 1 as a, 2 as b
9414 │ ─ 2. destination
9415 ‡
9416 7 │ select a from t;
9417 ╰╴ ─ 1. source
9418 ");
9419 }
9420
9421 #[test]
9422 fn goto_cte_insert_returning_column() {
9423 assert_snapshot!(goto("
9424create table t(a int, b int);
9425with inserted as (
9426 insert into t values (1, 2), (3, 4)
9427 returning a, b
9428)
9429select a$0 from inserted;
9430"), @r"
9431 ╭▸
9432 5 │ returning a, b
9433 │ ─ 2. destination
9434 6 │ )
9435 7 │ select a from inserted;
9436 ╰╴ ─ 1. source
9437 ");
9438 }
9439
9440 #[test]
9441 fn goto_cte_insert_returning_aliased_column() {
9442 assert_snapshot!(goto("
9443create table t(a int, b int);
9444with inserted as (
9445 insert into t values (1, 2), (3, 4)
9446 returning a as x
9447)
9448select x$0 from inserted;
9449"), @r"
9450 ╭▸
9451 5 │ returning a as x
9452 │ ─ 2. destination
9453 6 │ )
9454 7 │ select x from inserted;
9455 ╰╴ ─ 1. source
9456 ");
9457 }
9458
9459 #[test]
9460 fn goto_drop_aggregate() {
9461 assert_snapshot!(goto("
9462create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9463drop aggregate myavg$0(int);
9464"), @r"
9465 ╭▸
9466 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9467 │ ───── 2. destination
9468 3 │ drop aggregate myavg(int);
9469 ╰╴ ─ 1. source
9470 ");
9471 }
9472
9473 #[test]
9474 fn goto_drop_aggregate_with_schema() {
9475 assert_snapshot!(goto("
9476set search_path to public;
9477create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9478drop aggregate public.myavg$0(int);
9479"), @r"
9480 ╭▸
9481 3 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9482 │ ───── 2. destination
9483 4 │ drop aggregate public.myavg(int);
9484 ╰╴ ─ 1. source
9485 ");
9486 }
9487
9488 #[test]
9489 fn goto_drop_aggregate_defined_after() {
9490 assert_snapshot!(goto("
9491drop aggregate myavg$0(int);
9492create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9493"), @r"
9494 ╭▸
9495 2 │ drop aggregate myavg(int);
9496 │ ─ 1. source
9497 3 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9498 ╰╴ ───── 2. destination
9499 ");
9500 }
9501
9502 #[test]
9503 fn goto_aggregate_definition_returns_self() {
9504 assert_snapshot!(goto("
9505create aggregate myavg$0(int) (sfunc = int4_avg_accum, stype = _int8);
9506"), @r"
9507 ╭▸
9508 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9509 │ ┬───┬
9510 │ │ │
9511 │ │ 1. source
9512 ╰╴ 2. destination
9513 ");
9514 }
9515
9516 #[test]
9517 fn goto_drop_aggregate_with_search_path() {
9518 assert_snapshot!(goto("
9519create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9520set search_path to bar;
9521create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9522set search_path to default;
9523drop aggregate myavg$0(int);
9524"), @r"
9525 ╭▸
9526 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9527 │ ───── 2. destination
9528 ‡
9529 6 │ drop aggregate myavg(int);
9530 ╰╴ ─ 1. source
9531 ");
9532 }
9533
9534 #[test]
9535 fn goto_drop_aggregate_multiple() {
9536 assert_snapshot!(goto("
9537create aggregate avg1(int) (sfunc = int4_avg_accum, stype = _int8);
9538create aggregate avg2(int) (sfunc = int4_avg_accum, stype = _int8);
9539drop aggregate avg1(int), avg2$0(int);
9540"), @r"
9541 ╭▸
9542 3 │ create aggregate avg2(int) (sfunc = int4_avg_accum, stype = _int8);
9543 │ ──── 2. destination
9544 4 │ drop aggregate avg1(int), avg2(int);
9545 ╰╴ ─ 1. source
9546 ");
9547 }
9548
9549 #[test]
9550 fn goto_drop_aggregate_overloaded() {
9551 assert_snapshot!(goto("
9552create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
9553create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
9554drop aggregate sum$0(complex);
9555"), @r"
9556 ╭▸
9557 2 │ create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
9558 │ ─── 2. destination
9559 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
9560 4 │ drop aggregate sum(complex);
9561 ╰╴ ─ 1. source
9562 ");
9563 }
9564
9565 #[test]
9566 fn goto_drop_aggregate_second_overload() {
9567 assert_snapshot!(goto("
9568create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
9569create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
9570drop aggregate sum$0(bigint);
9571"), @r"
9572 ╭▸
9573 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
9574 │ ─── 2. destination
9575 4 │ drop aggregate sum(bigint);
9576 ╰╴ ─ 1. source
9577 ");
9578 }
9579
9580 #[test]
9581 fn goto_drop_routine_function() {
9582 assert_snapshot!(goto("
9583create function foo() returns int as $$ select 1 $$ language sql;
9584drop routine foo$0();
9585"), @r"
9586 ╭▸
9587 2 │ create function foo() returns int as $$ select 1 $$ language sql;
9588 │ ─── 2. destination
9589 3 │ drop routine foo();
9590 ╰╴ ─ 1. source
9591 ");
9592 }
9593
9594 #[test]
9595 fn goto_drop_routine_aggregate() {
9596 assert_snapshot!(goto("
9597create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9598drop routine myavg$0(int);
9599"), @r"
9600 ╭▸
9601 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
9602 │ ───── 2. destination
9603 3 │ drop routine myavg(int);
9604 ╰╴ ─ 1. source
9605 ");
9606 }
9607
9608 #[test]
9609 fn goto_drop_routine_with_schema() {
9610 assert_snapshot!(goto("
9611set search_path to public;
9612create function foo() returns int as $$ select 1 $$ language sql;
9613drop routine public.foo$0();
9614"), @r"
9615 ╭▸
9616 3 │ create function foo() returns int as $$ select 1 $$ language sql;
9617 │ ─── 2. destination
9618 4 │ drop routine public.foo();
9619 ╰╴ ─ 1. source
9620 ");
9621 }
9622
9623 #[test]
9624 fn goto_drop_routine_defined_after() {
9625 assert_snapshot!(goto("
9626drop routine foo$0();
9627create function foo() returns int as $$ select 1 $$ language sql;
9628"), @r"
9629 ╭▸
9630 2 │ drop routine foo();
9631 │ ─ 1. source
9632 3 │ create function foo() returns int as $$ select 1 $$ language sql;
9633 ╰╴ ─── 2. destination
9634 ");
9635 }
9636
9637 #[test]
9638 fn goto_drop_routine_with_search_path() {
9639 assert_snapshot!(goto("
9640create function foo() returns int as $$ select 1 $$ language sql;
9641set search_path to bar;
9642create function foo() returns int as $$ select 1 $$ language sql;
9643set search_path to default;
9644drop routine foo$0();
9645"), @r"
9646 ╭▸
9647 2 │ create function foo() returns int as $$ select 1 $$ language sql;
9648 │ ─── 2. destination
9649 ‡
9650 6 │ drop routine foo();
9651 ╰╴ ─ 1. source
9652 ");
9653 }
9654
9655 #[test]
9656 fn goto_drop_routine_overloaded() {
9657 assert_snapshot!(goto("
9658create function add(complex) returns complex as $$ select null $$ language sql;
9659create function add(bigint) returns bigint as $$ select 1 $$ language sql;
9660drop routine add$0(complex);
9661"), @r"
9662 ╭▸
9663 2 │ create function add(complex) returns complex as $$ select null $$ language sql;
9664 │ ─── 2. destination
9665 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
9666 4 │ drop routine add(complex);
9667 ╰╴ ─ 1. source
9668 ");
9669 }
9670
9671 #[test]
9672 fn goto_drop_routine_second_overload() {
9673 assert_snapshot!(goto("
9674create function add(complex) returns complex as $$ select null $$ language sql;
9675create function add(bigint) returns bigint as $$ select 1 $$ language sql;
9676drop routine add$0(bigint);
9677"), @r"
9678 ╭▸
9679 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
9680 │ ─── 2. destination
9681 4 │ drop routine add(bigint);
9682 ╰╴ ─ 1. source
9683 ");
9684 }
9685
9686 #[test]
9687 fn goto_drop_routine_aggregate_overloaded() {
9688 assert_snapshot!(goto("
9689create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
9690create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
9691drop routine sum$0(complex);
9692"), @r"
9693 ╭▸
9694 2 │ create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
9695 │ ─── 2. destination
9696 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
9697 4 │ drop routine sum(complex);
9698 ╰╴ ─ 1. source
9699 ");
9700 }
9701
9702 #[test]
9703 fn goto_drop_routine_multiple() {
9704 assert_snapshot!(goto("
9705create function foo() returns int as $$ select 1 $$ language sql;
9706create function bar() returns int as $$ select 1 $$ language sql;
9707drop routine foo(), bar$0();
9708"), @r"
9709 ╭▸
9710 3 │ create function bar() returns int as $$ select 1 $$ language sql;
9711 │ ─── 2. destination
9712 4 │ drop routine foo(), bar();
9713 ╰╴ ─ 1. source
9714 ");
9715 }
9716
9717 #[test]
9718 fn goto_drop_procedure() {
9719 assert_snapshot!(goto("
9720create procedure foo() language sql as $$ select 1 $$;
9721drop procedure foo$0();
9722"), @r"
9723 ╭▸
9724 2 │ create procedure foo() language sql as $$ select 1 $$;
9725 │ ─── 2. destination
9726 3 │ drop procedure foo();
9727 ╰╴ ─ 1. source
9728 ");
9729 }
9730
9731 #[test]
9732 fn goto_drop_procedure_with_schema() {
9733 assert_snapshot!(goto("
9734set search_path to public;
9735create procedure foo() language sql as $$ select 1 $$;
9736drop procedure public.foo$0();
9737"), @r"
9738 ╭▸
9739 3 │ create procedure foo() language sql as $$ select 1 $$;
9740 │ ─── 2. destination
9741 4 │ drop procedure public.foo();
9742 ╰╴ ─ 1. source
9743 ");
9744 }
9745
9746 #[test]
9747 fn goto_drop_procedure_defined_after() {
9748 assert_snapshot!(goto("
9749drop procedure foo$0();
9750create procedure foo() language sql as $$ select 1 $$;
9751"), @r"
9752 ╭▸
9753 2 │ drop procedure foo();
9754 │ ─ 1. source
9755 3 │ create procedure foo() language sql as $$ select 1 $$;
9756 ╰╴ ─── 2. destination
9757 ");
9758 }
9759
9760 #[test]
9761 fn goto_drop_procedure_with_search_path() {
9762 assert_snapshot!(goto("
9763create procedure foo() language sql as $$ select 1 $$;
9764set search_path to bar;
9765create procedure foo() language sql as $$ select 1 $$;
9766set search_path to default;
9767drop procedure foo$0();
9768"), @r"
9769 ╭▸
9770 2 │ create procedure foo() language sql as $$ select 1 $$;
9771 │ ─── 2. destination
9772 ‡
9773 6 │ drop procedure foo();
9774 ╰╴ ─ 1. source
9775 ");
9776 }
9777
9778 #[test]
9779 fn goto_drop_procedure_overloaded() {
9780 assert_snapshot!(goto("
9781create procedure add(complex) language sql as $$ select null $$;
9782create procedure add(bigint) language sql as $$ select 1 $$;
9783drop procedure add$0(complex);
9784"), @r"
9785 ╭▸
9786 2 │ create procedure add(complex) language sql as $$ select null $$;
9787 │ ─── 2. destination
9788 3 │ create procedure add(bigint) language sql as $$ select 1 $$;
9789 4 │ drop procedure add(complex);
9790 ╰╴ ─ 1. source
9791 ");
9792 }
9793
9794 #[test]
9795 fn goto_drop_procedure_second_overload() {
9796 assert_snapshot!(goto("
9797create procedure add(complex) language sql as $$ select null $$;
9798create procedure add(bigint) language sql as $$ select 1 $$;
9799drop procedure add$0(bigint);
9800"), @r"
9801 ╭▸
9802 3 │ create procedure add(bigint) language sql as $$ select 1 $$;
9803 │ ─── 2. destination
9804 4 │ drop procedure add(bigint);
9805 ╰╴ ─ 1. source
9806 ");
9807 }
9808
9809 #[test]
9810 fn goto_drop_procedure_multiple() {
9811 assert_snapshot!(goto("
9812create procedure foo() language sql as $$ select 1 $$;
9813create procedure bar() language sql as $$ select 1 $$;
9814drop procedure foo(), bar$0();
9815"), @r"
9816 ╭▸
9817 3 │ create procedure bar() language sql as $$ select 1 $$;
9818 │ ─── 2. destination
9819 4 │ drop procedure foo(), bar();
9820 ╰╴ ─ 1. source
9821 ");
9822 }
9823
9824 #[test]
9825 fn goto_procedure_definition_returns_self() {
9826 assert_snapshot!(goto("
9827create procedure foo$0() language sql as $$ select 1 $$;
9828"), @r"
9829 ╭▸
9830 2 │ create procedure foo() language sql as $$ select 1 $$;
9831 │ ┬─┬
9832 │ │ │
9833 │ │ 1. source
9834 ╰╴ 2. destination
9835 ");
9836 }
9837
9838 #[test]
9839 fn goto_call_procedure() {
9840 assert_snapshot!(goto("
9841create procedure foo() language sql as $$ select 1 $$;
9842call foo$0();
9843"), @r"
9844 ╭▸
9845 2 │ create procedure foo() language sql as $$ select 1 $$;
9846 │ ─── 2. destination
9847 3 │ call foo();
9848 ╰╴ ─ 1. source
9849 ");
9850 }
9851
9852 #[test]
9853 fn goto_call_procedure_with_schema() {
9854 assert_snapshot!(goto("
9855create procedure public.foo() language sql as $$ select 1 $$;
9856call public.foo$0();
9857"), @r"
9858 ╭▸
9859 2 │ create procedure public.foo() language sql as $$ select 1 $$;
9860 │ ─── 2. destination
9861 3 │ call public.foo();
9862 ╰╴ ─ 1. source
9863 ");
9864 }
9865
9866 #[test]
9867 fn goto_call_procedure_with_search_path() {
9868 assert_snapshot!(goto("
9869set search_path to myschema;
9870create procedure foo() language sql as $$ select 1 $$;
9871call myschema.foo$0();
9872"), @r"
9873 ╭▸
9874 3 │ create procedure foo() language sql as $$ select 1 $$;
9875 │ ─── 2. destination
9876 4 │ call myschema.foo();
9877 ╰╴ ─ 1. source
9878 ");
9879 }
9880
9881 #[test]
9882 fn goto_drop_routine_procedure() {
9883 assert_snapshot!(goto("
9884create procedure foo() language sql as $$ select 1 $$;
9885drop routine foo$0();
9886"), @r"
9887 ╭▸
9888 2 │ create procedure foo() language sql as $$ select 1 $$;
9889 │ ─── 2. destination
9890 3 │ drop routine foo();
9891 ╰╴ ─ 1. source
9892 ");
9893 }
9894
9895 #[test]
9896 fn goto_drop_routine_prefers_function_over_procedure() {
9897 assert_snapshot!(goto("
9898create function foo() returns int as $$ select 1 $$ language sql;
9899create procedure foo() language sql as $$ select 1 $$;
9900drop routine foo$0();
9901"), @r"
9902 ╭▸
9903 2 │ create function foo() returns int as $$ select 1 $$ language sql;
9904 │ ─── 2. destination
9905 3 │ create procedure foo() language sql as $$ select 1 $$;
9906 4 │ drop routine foo();
9907 ╰╴ ─ 1. source
9908 ");
9909 }
9910
9911 #[test]
9912 fn goto_drop_routine_prefers_aggregate_over_procedure() {
9913 assert_snapshot!(goto("
9914create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
9915create procedure foo(int) language sql as $$ select 1 $$;
9916drop routine foo$0(int);
9917"), @r"
9918 ╭▸
9919 2 │ create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
9920 │ ─── 2. destination
9921 3 │ create procedure foo(int) language sql as $$ select 1 $$;
9922 4 │ drop routine foo(int);
9923 ╰╴ ─ 1. source
9924 ");
9925 }
9926
9927 #[test]
9928 fn goto_table_alias_in_qualified_column() {
9929 assert_snapshot!(goto("
9930create table t(a int8, b text);
9931select f$0.a from t as f;
9932"), @r"
9933 ╭▸
9934 3 │ select f.a from t as f;
9935 ╰╴ ─ 1. source ─ 2. destination
9936 ");
9937 }
9938
9939 #[test]
9940 fn goto_column_through_table_alias() {
9941 assert_snapshot!(goto("
9942create table t(a int8, b text);
9943select f.a$0 from t as f;
9944"), @r"
9945 ╭▸
9946 2 │ create table t(a int8, b text);
9947 │ ─ 2. destination
9948 3 │ select f.a from t as f;
9949 ╰╴ ─ 1. source
9950 ");
9951 }
9952
9953 #[test]
9954 fn goto_cte_alias_renamed_column() {
9955 assert_snapshot!(goto("
9956with t as (select 1 a, 2 b)
9957select f.x$0 from t as f(x);
9958"), @r"
9959 ╭▸
9960 3 │ select f.x from t as f(x);
9961 ╰╴ ─ 1. source ─ 2. destination
9962 ");
9963 }
9964
9965 #[test]
9966 fn goto_cte_alias_unrenamed_column() {
9967 assert_snapshot!(goto("
9968with t as (select 1 a, 2 b)
9969select f.b$0 from t as f(x);
9970"), @r"
9971 ╭▸
9972 2 │ with t as (select 1 a, 2 b)
9973 │ ─ 2. destination
9974 3 │ select f.b from t as f(x);
9975 ╰╴ ─ 1. source
9976 ");
9977 }
9978
9979 #[test]
9980 fn goto_join_table() {
9981 assert_snapshot!(goto("
9982create table users(id int, email text);
9983create table messages(id int, user_id int, message text);
9984select * from users join messages$0 on users.id = messages.user_id;
9985"), @r"
9986 ╭▸
9987 3 │ create table messages(id int, user_id int, message text);
9988 │ ──────── 2. destination
9989 4 │ select * from users join messages on users.id = messages.user_id;
9990 ╰╴ ─ 1. source
9991 ");
9992 }
9993
9994 #[test]
9995 fn goto_join_qualified_column_from_joined_table() {
9996 assert_snapshot!(goto("
9997create table users(id int, email text);
9998create table messages(id int, user_id int, message text);
9999select messages.user_id$0 from users join messages on users.id = messages.user_id;
10000"), @r"
10001 ╭▸
10002 3 │ create table messages(id int, user_id int, message text);
10003 │ ─────── 2. destination
10004 4 │ select messages.user_id from users join messages on users.id = messages.user_id;
10005 ╰╴ ─ 1. source
10006 ");
10007 }
10008
10009 #[test]
10010 fn goto_join_qualified_column_from_base_table() {
10011 assert_snapshot!(goto("
10012create table users(id int, email text);
10013create table messages(id int, user_id int, message text);
10014select users.id$0 from users join messages on users.id = messages.user_id;
10015"), @r"
10016 ╭▸
10017 2 │ create table users(id int, email text);
10018 │ ── 2. destination
10019 3 │ create table messages(id int, user_id int, message text);
10020 4 │ select users.id from users join messages on users.id = messages.user_id;
10021 ╰╴ ─ 1. source
10022 ");
10023 }
10024
10025 #[test]
10026 fn goto_join_multiple_joins() {
10027 assert_snapshot!(goto("
10028create table users(id int, name text);
10029create table messages(id int, user_id int, message text);
10030create table comments(id int, message_id int, text text);
10031select comments.text$0 from users
10032 join messages on users.id = messages.user_id
10033 join comments on messages.id = comments.message_id;
10034"), @r"
10035 ╭▸
10036 4 │ create table comments(id int, message_id int, text text);
10037 │ ──── 2. destination
10038 5 │ select comments.text from users
10039 ╰╴ ─ 1. source
10040 ");
10041 }
10042
10043 #[test]
10044 fn goto_join_with_aliases() {
10045 assert_snapshot!(goto("
10046create table users(id int, name text);
10047create table messages(id int, user_id int, message text);
10048select m.message$0 from users as u join messages as m on u.id = m.user_id;
10049"), @r"
10050 ╭▸
10051 3 │ create table messages(id int, user_id int, message text);
10052 │ ─────── 2. destination
10053 4 │ select m.message from users as u join messages as m on u.id = m.user_id;
10054 ╰╴ ─ 1. source
10055 ");
10056 }
10057
10058 #[test]
10059 fn goto_alias_hides_table_name() {
10060 goto_not_found(
10061 "
10062create table t(a int);
10063select t$0.a from t as u;
10064",
10065 );
10066 }
10067
10068 #[test]
10069 fn goto_join_unqualified_column() {
10070 assert_snapshot!(goto("
10071create table users(id int, email text);
10072create table messages(id int, user_id int, message text);
10073select message$0 from users join messages on users.id = messages.user_id;
10074"), @r"
10075 ╭▸
10076 3 │ create table messages(id int, user_id int, message text);
10077 │ ─────── 2. destination
10078 4 │ select message from users join messages on users.id = messages.user_id;
10079 ╰╴ ─ 1. source
10080 ");
10081 }
10082
10083 #[test]
10084 fn goto_join_with_many_tables() {
10085 assert_snapshot!(goto("
10086create table users(id int, email text);
10087create table messages(id int, user_id int, message text);
10088create table logins(id int, user_id int, at timestamptz);
10089create table posts(id int, user_id int, post text);
10090
10091select post$0
10092 from users
10093 join messages
10094 on users.id = messages.user_id
10095 join logins
10096 on users.id = logins.user_id
10097 join posts
10098 on users.id = posts.user_id
10099"), @r"
10100 ╭▸
10101 5 │ create table posts(id int, user_id int, post text);
10102 │ ──── 2. destination
10103 6 │
10104 7 │ select post
10105 ╰╴ ─ 1. source
10106 ");
10107 }
10108
10109 #[test]
10110 fn goto_join_with_schema() {
10111 assert_snapshot!(goto("
10112create schema foo;
10113create table foo.users(id int, email text);
10114create table foo.messages(id int, user_id int, message text);
10115select foo.messages.message$0 from foo.users join foo.messages on foo.users.id = foo.messages.user_id;
10116"), @r"
10117 ╭▸
10118 4 │ create table foo.messages(id int, user_id int, message text);
10119 │ ─────── 2. destination
10120 5 │ select foo.messages.message from foo.users join foo.messages on foo.users.id = foo.messages.user_id;
10121 ╰╴ ─ 1. source
10122 ");
10123 }
10124
10125 #[test]
10126 fn goto_join_left_join() {
10127 assert_snapshot!(goto("
10128create table users(id int, email text);
10129create table messages(id int, user_id int, message text);
10130select messages.message$0 from users left join messages on users.id = messages.user_id;
10131"), @r"
10132 ╭▸
10133 3 │ create table messages(id int, user_id int, message text);
10134 │ ─────── 2. destination
10135 4 │ select messages.message from users left join messages on users.id = messages.user_id;
10136 ╰╴ ─ 1. source
10137 ");
10138 }
10139
10140 #[test]
10141 fn goto_join_on_table_qualifier() {
10142 assert_snapshot!(goto("
10143create table t(a int);
10144create table u(a int);
10145select * from t join u on u$0.a = t.a;
10146"), @r"
10147 ╭▸
10148 3 │ create table u(a int);
10149 │ ─ 2. destination
10150 4 │ select * from t join u on u.a = t.a;
10151 ╰╴ ─ 1. source
10152 ");
10153 }
10154
10155 #[test]
10156 fn goto_join_on_column() {
10157 assert_snapshot!(goto("
10158create table t(a int);
10159create table u(a int);
10160select * from t join u on u.a$0 = t.a;
10161"), @r"
10162 ╭▸
10163 3 │ create table u(a int);
10164 │ ─ 2. destination
10165 4 │ select * from t join u on u.a = t.a;
10166 ╰╴ ─ 1. source
10167 ");
10168 }
10169
10170 #[test]
10171 fn goto_join_using_column() {
10172 assert_snapshot!(goto("
10173create table t(a int);
10174create table u(a int);
10175select * from t join u using (a$0);
10176"), @r"
10177 ╭▸
10178 2 │ create table t(a int);
10179 │ ─ 2. destination
10180 3 │ create table u(a int);
10181 │ ─ 3. destination
10182 4 │ select * from t join u using (a);
10183 ╰╴ ─ 1. source
10184 ");
10185 }
10186
10187 #[test]
10188 fn goto_join_using_alias_column() {
10189 assert_snapshot!(goto("
10190create table a(x int);
10191create table b(x int);
10192select j.x$0 from a join b using (x) as j;
10193"), @"
10194 ╭▸
10195 2 │ create table a(x int);
10196 │ ─ 2. destination
10197 3 │ create table b(x int);
10198 │ ─ 3. destination
10199 4 │ select j.x from a join b using (x) as j;
10200 ╰╴ ─ 1. source
10201 ");
10202 }
10203
10204 #[test]
10205 fn goto_join_using_alias_table() {
10206 assert_snapshot!(goto("
10207create table a(x int);
10208create table b(x int);
10209select j$0.x from a join b using (x) as j;
10210"), @"
10211 ╭▸
10212 4 │ select j.x from a join b using (x) as j;
10213 ╰╴ ─ 1. source ─ 2. destination
10214 ");
10215 }
10216
10217 #[test]
10218 fn goto_insert_select_cte_column() {
10219 assert_snapshot!(goto("
10220create table users(id int, email text);
10221with new_data as (
10222 select 1 as id, 'test@example.com' as email
10223)
10224insert into users (id, email)
10225select id$0, email from new_data;
10226"), @r"
10227 ╭▸
10228 4 │ select 1 as id, 'test@example.com' as email
10229 │ ── 2. destination
10230 ‡
10231 7 │ select id, email from new_data;
10232 ╰╴ ─ 1. source
10233 ");
10234 }
10235
10236 #[test]
10237 fn goto_insert_select_cte_column_second() {
10238 assert_snapshot!(goto("
10239create table users(id int, email text);
10240with new_data as (
10241 select 1 as id, 'test@example.com' as email
10242)
10243insert into users (id, email)
10244select id, email$0 from new_data;
10245"), @r"
10246 ╭▸
10247 4 │ select 1 as id, 'test@example.com' as email
10248 │ ───── 2. destination
10249 ‡
10250 7 │ select id, email from new_data;
10251 ╰╴ ─ 1. source
10252 ");
10253 }
10254
10255 #[test]
10256 fn goto_insert_select_cte_table() {
10257 assert_snapshot!(goto("
10258create table users(id int, email text);
10259with new_data as (
10260 select 1 as id, 'test@example.com' as email
10261)
10262insert into users (id, email)
10263select id, email from new_data$0;
10264"), @r"
10265 ╭▸
10266 3 │ with new_data as (
10267 │ ──────── 2. destination
10268 ‡
10269 7 │ select id, email from new_data;
10270 ╰╴ ─ 1. source
10271 ");
10272 }
10273
10274 #[test]
10275 fn goto_delete_cte_column() {
10276 assert_snapshot!(goto("
10277create table users(id int, email text);
10278with old_data as (
10279 select 1 as id
10280)
10281delete from users where id in (select id$0 from old_data);
10282"), @r"
10283 ╭▸
10284 4 │ select 1 as id
10285 │ ── 2. destination
10286 5 │ )
10287 6 │ delete from users where id in (select id from old_data);
10288 ╰╴ ─ 1. source
10289 ");
10290 }
10291
10292 #[test]
10293 fn goto_update_table() {
10294 assert_snapshot!(goto("
10295create table users(id int, email text);
10296update users$0 set email = 'new@example.com';
10297"), @r"
10298 ╭▸
10299 2 │ create table users(id int, email text);
10300 │ ───── 2. destination
10301 3 │ update users set email = 'new@example.com';
10302 ╰╴ ─ 1. source
10303 ");
10304 }
10305
10306 #[test]
10307 fn goto_update_table_with_schema() {
10308 assert_snapshot!(goto("
10309create table public.users(id int, email text);
10310update public.users$0 set email = 'new@example.com';
10311"), @r"
10312 ╭▸
10313 2 │ create table public.users(id int, email text);
10314 │ ───── 2. destination
10315 3 │ update public.users set email = 'new@example.com';
10316 ╰╴ ─ 1. source
10317 ");
10318 }
10319
10320 #[test]
10321 fn goto_update_table_with_search_path() {
10322 assert_snapshot!(goto("
10323set search_path to foo;
10324create table foo.users(id int, email text);
10325update users$0 set email = 'new@example.com';
10326"), @r"
10327 ╭▸
10328 3 │ create table foo.users(id int, email text);
10329 │ ───── 2. destination
10330 4 │ update users set email = 'new@example.com';
10331 ╰╴ ─ 1. source
10332 ");
10333 }
10334
10335 #[test]
10336 fn goto_update_where_column() {
10337 assert_snapshot!(goto("
10338create table users(id int, email text);
10339update users set email = 'new@example.com' where id$0 = 1;
10340"), @r"
10341 ╭▸
10342 2 │ create table users(id int, email text);
10343 │ ── 2. destination
10344 3 │ update users set email = 'new@example.com' where id = 1;
10345 ╰╴ ─ 1. source
10346 ");
10347 }
10348
10349 #[test]
10350 fn goto_update_where_column_with_schema() {
10351 assert_snapshot!(goto("
10352create table public.users(id int, email text);
10353update public.users set email = 'new@example.com' where id$0 = 1;
10354"), @r"
10355 ╭▸
10356 2 │ create table public.users(id int, email text);
10357 │ ── 2. destination
10358 3 │ update public.users set email = 'new@example.com' where id = 1;
10359 ╰╴ ─ 1. source
10360 ");
10361 }
10362
10363 #[test]
10364 fn goto_update_where_column_with_search_path() {
10365 assert_snapshot!(goto("
10366set search_path to foo;
10367create table foo.users(id int, email text);
10368update users set email = 'new@example.com' where id$0 = 1;
10369"), @r"
10370 ╭▸
10371 3 │ create table foo.users(id int, email text);
10372 │ ── 2. destination
10373 4 │ update users set email = 'new@example.com' where id = 1;
10374 ╰╴ ─ 1. source
10375 ");
10376 }
10377
10378 #[test]
10379 fn goto_update_set_column() {
10380 assert_snapshot!(goto("
10381create table users(id int, email text);
10382update users set email$0 = 'new@example.com' where id = 1;
10383"), @r"
10384 ╭▸
10385 2 │ create table users(id int, email text);
10386 │ ───── 2. destination
10387 3 │ update users set email = 'new@example.com' where id = 1;
10388 ╰╴ ─ 1. source
10389 ");
10390 }
10391
10392 #[test]
10393 fn goto_update_set_column_with_schema() {
10394 assert_snapshot!(goto("
10395create table public.users(id int, email text);
10396update public.users set email$0 = 'new@example.com' where id = 1;
10397"), @r"
10398 ╭▸
10399 2 │ create table public.users(id int, email text);
10400 │ ───── 2. destination
10401 3 │ update public.users set email = 'new@example.com' where id = 1;
10402 ╰╴ ─ 1. source
10403 ");
10404 }
10405
10406 #[test]
10407 fn goto_update_set_column_with_search_path() {
10408 assert_snapshot!(goto("
10409set search_path to foo;
10410create table foo.users(id int, email text);
10411update users set email$0 = 'new@example.com' where id = 1;
10412"), @r"
10413 ╭▸
10414 3 │ create table foo.users(id int, email text);
10415 │ ───── 2. destination
10416 4 │ update users set email = 'new@example.com' where id = 1;
10417 ╰╴ ─ 1. source
10418 ");
10419 }
10420
10421 #[test]
10422 fn goto_update_from_table() {
10423 assert_snapshot!(goto("
10424create table users(id int, email text);
10425create table messages(id int, user_id int, email text);
10426update users set email = messages.email from messages$0 where users.id = messages.user_id;
10427"), @r"
10428 ╭▸
10429 3 │ create table messages(id int, user_id int, email text);
10430 │ ──────── 2. destination
10431 4 │ update users set email = messages.email from messages where users.id = messages.user_id;
10432 ╰╴ ─ 1. source
10433 ");
10434 }
10435
10436 #[test]
10437 fn goto_update_from_table_qualifier_in_set() {
10438 assert_snapshot!(goto("
10439create table target(id int, x int);
10440create table src(id int, y int);
10441update target set x = src$0.y from src where src.id = target.id;
10442"), @"
10443 ╭▸
10444 3 │ create table src(id int, y int);
10445 │ ─── 2. destination
10446 4 │ update target set x = src.y from src where src.id = target.id;
10447 ╰╴ ─ 1. source
10448 ");
10449 }
10450
10451 #[test]
10452 fn goto_update_set_target_resolves_to_target_table() {
10453 assert_snapshot!(goto("
10454create table t (a int);
10455create table u (a int);
10456update t set a$0 = u.a from u;
10457"), @"
10458 ╭▸
10459 2 │ create table t (a int);
10460 │ ─ 2. destination
10461 3 │ create table u (a int);
10462 4 │ update t set a = u.a from u;
10463 ╰╴ ─ 1. source
10464 ");
10465 }
10466
10467 #[test]
10468 fn goto_update_set_target_tuple_resolves_to_target_table() {
10469 assert_snapshot!(goto("
10470create table t (a int, b int);
10471create table u (a int);
10472update t set (a$0, b) = (u.a, 1) from u;
10473"), @"
10474 ╭▸
10475 2 │ create table t (a int, b int);
10476 │ ─ 2. destination
10477 3 │ create table u (a int);
10478 4 │ update t set (a, b) = (u.a, 1) from u;
10479 ╰╴ ─ 1. source
10480 ");
10481 }
10482
10483 #[test]
10484 fn goto_update_from_table_with_schema() {
10485 assert_snapshot!(goto("
10486create table users(id int, email text);
10487create table public.messages(id int, user_id int, email text);
10488update users set email = messages.email from public.messages$0 where users.id = messages.user_id;
10489"), @r"
10490 ╭▸
10491 3 │ create table public.messages(id int, user_id int, email text);
10492 │ ──────── 2. destination
10493 4 │ update users set email = messages.email from public.messages where users.id = messages.user_id;
10494 ╰╴ ─ 1. source
10495 ");
10496 }
10497
10498 #[test]
10499 fn goto_update_from_table_with_search_path() {
10500 assert_snapshot!(goto("
10501set search_path to foo;
10502create table users(id int, email text);
10503create table foo.messages(id int, user_id int, email text);
10504update users set email = messages.email from messages$0 where users.id = messages.user_id;
10505"), @r"
10506 ╭▸
10507 4 │ create table foo.messages(id int, user_id int, email text);
10508 │ ──────── 2. destination
10509 5 │ update users set email = messages.email from messages where users.id = messages.user_id;
10510 ╰╴ ─ 1. source
10511 ");
10512 }
10513
10514 #[test]
10515 fn goto_update_with_cte_table() {
10516 assert_snapshot!(goto("
10517create table users(id int, email text);
10518with new_data as (
10519 select 1 as id, 'new@example.com' as email
10520)
10521update users set email = new_data.email from new_data$0 where users.id = new_data.id;
10522"), @r"
10523 ╭▸
10524 3 │ with new_data as (
10525 │ ──────── 2. destination
10526 ‡
10527 6 │ update users set email = new_data.email from new_data where users.id = new_data.id;
10528 ╰╴ ─ 1. source
10529 ");
10530 }
10531
10532 #[test]
10533 fn goto_update_with_cte_column_in_set() {
10534 assert_snapshot!(goto("
10535create table users(id int, email text);
10536with new_data as (
10537 select 1 as id, 'new@example.com' as email
10538)
10539update users set email = new_data.email$0 from new_data where users.id = new_data.id;
10540"), @r"
10541 ╭▸
10542 4 │ select 1 as id, 'new@example.com' as email
10543 │ ───── 2. destination
10544 5 │ )
10545 6 │ update users set email = new_data.email from new_data where users.id = new_data.id;
10546 ╰╴ ─ 1. source
10547 ");
10548 }
10549
10550 #[test]
10551 fn goto_update_with_cte_column_in_where() {
10552 assert_snapshot!(goto("
10553create table users(id int, email text);
10554with new_data as (
10555 select 1 as id, 'new@example.com' as email
10556)
10557update users set email = new_data.email from new_data where new_data.id$0 = users.id;
10558"), @r"
10559 ╭▸
10560 4 │ select 1 as id, 'new@example.com' as email
10561 │ ── 2. destination
10562 5 │ )
10563 6 │ update users set email = new_data.email from new_data where new_data.id = users.id;
10564 ╰╴ ─ 1. source
10565 ");
10566 }
10567
10568 #[test]
10569 fn goto_update_with_cte_values() {
10570 assert_snapshot!(goto("
10571create table users(id int, email text);
10572with new_data as (
10573 values (1, 'new@example.com')
10574)
10575update users set email = new_data.column2$0 from new_data where users.id = new_data.column1;
10576"), @r"
10577 ╭▸
10578 4 │ values (1, 'new@example.com')
10579 │ ───────────────── 2. destination
10580 5 │ )
10581 6 │ update users set email = new_data.column2 from new_data where users.id = new_data.column1;
10582 ╰╴ ─ 1. source
10583 ");
10584 }
10585
10586 #[test]
10587 fn goto_truncate_table() {
10588 assert_snapshot!(goto("
10589create table t();
10590truncate table t$0;
10591"), @r"
10592 ╭▸
10593 2 │ create table t();
10594 │ ─ 2. destination
10595 3 │ truncate table t;
10596 ╰╴ ─ 1. source
10597 ");
10598 }
10599
10600 #[test]
10601 fn goto_truncate_table_without_table_keyword() {
10602 assert_snapshot!(goto("
10603create table t();
10604truncate t$0;
10605"), @r"
10606 ╭▸
10607 2 │ create table t();
10608 │ ─ 2. destination
10609 3 │ truncate t;
10610 ╰╴ ─ 1. source
10611 ");
10612 }
10613
10614 #[test]
10615 fn goto_truncate_multiple_tables() {
10616 assert_snapshot!(goto("
10617create table t1();
10618create table t2();
10619truncate t1, t2$0;
10620"), @r"
10621 ╭▸
10622 3 │ create table t2();
10623 │ ── 2. destination
10624 4 │ truncate t1, t2;
10625 ╰╴ ─ 1. source
10626 ");
10627 }
10628
10629 #[test]
10630 fn goto_lock_table() {
10631 assert_snapshot!(goto("
10632create table t();
10633lock table t$0;
10634"), @r"
10635 ╭▸
10636 2 │ create table t();
10637 │ ─ 2. destination
10638 3 │ lock table t;
10639 ╰╴ ─ 1. source
10640 ");
10641 }
10642
10643 #[test]
10644 fn goto_lock_table_without_table_keyword() {
10645 assert_snapshot!(goto("
10646create table t();
10647lock t$0;
10648"), @r"
10649 ╭▸
10650 2 │ create table t();
10651 │ ─ 2. destination
10652 3 │ lock t;
10653 ╰╴ ─ 1. source
10654 ");
10655 }
10656
10657 #[test]
10658 fn goto_lock_multiple_tables() {
10659 assert_snapshot!(goto("
10660create table t1();
10661create table t2();
10662lock t1, t2$0;
10663"), @r"
10664 ╭▸
10665 3 │ create table t2();
10666 │ ── 2. destination
10667 4 │ lock t1, t2;
10668 ╰╴ ─ 1. source
10669 ");
10670 }
10671
10672 #[test]
10673 fn goto_vacuum_table() {
10674 assert_snapshot!(goto("
10675create table users(id int, email text);
10676vacuum users$0;
10677"), @r"
10678 ╭▸
10679 2 │ create table users(id int, email text);
10680 │ ───── 2. destination
10681 3 │ vacuum users;
10682 ╰╴ ─ 1. source
10683 ");
10684 }
10685
10686 #[test]
10687 fn goto_vacuum_multiple_tables() {
10688 assert_snapshot!(goto("
10689create table t1();
10690create table t2();
10691vacuum t1, t2$0;
10692"), @r"
10693 ╭▸
10694 3 │ create table t2();
10695 │ ── 2. destination
10696 4 │ vacuum t1, t2;
10697 ╰╴ ─ 1. source
10698 ");
10699 }
10700
10701 #[test]
10702 fn goto_vacuum_column() {
10703 assert_snapshot!(goto("
10704create table users(id int, email text);
10705vacuum users (id$0);
10706"), @"
10707 ╭▸
10708 2 │ create table users(id int, email text);
10709 │ ── 2. destination
10710 3 │ vacuum users (id);
10711 ╰╴ ─ 1. source
10712 ");
10713 }
10714
10715 #[test]
10716 fn goto_analyze_table() {
10717 assert_snapshot!(goto("
10718create table users(id int, email text);
10719analyze users$0;
10720"), @"
10721 ╭▸
10722 2 │ create table users(id int, email text);
10723 │ ───── 2. destination
10724 3 │ analyze users;
10725 ╰╴ ─ 1. source
10726 ");
10727 }
10728
10729 #[test]
10730 fn goto_analyze_column() {
10731 assert_snapshot!(goto("
10732create table users(id int, email text);
10733analyze users (id$0);
10734"), @"
10735 ╭▸
10736 2 │ create table users(id int, email text);
10737 │ ── 2. destination
10738 3 │ analyze users (id);
10739 ╰╴ ─ 1. source
10740 ");
10741 }
10742
10743 #[test]
10744 fn goto_alter_table() {
10745 assert_snapshot!(goto("
10746create table users(id int, email text);
10747alter table users$0 alter email set not null;
10748"), @r"
10749 ╭▸
10750 2 │ create table users(id int, email text);
10751 │ ───── 2. destination
10752 3 │ alter table users alter email set not null;
10753 ╰╴ ─ 1. source
10754 ");
10755 }
10756
10757 #[test]
10758 fn goto_alter_table_column() {
10759 assert_snapshot!(goto("
10760create table users(id int, email text);
10761alter table users alter email$0 set not null;
10762"), @r"
10763 ╭▸
10764 2 │ create table users(id int, email text);
10765 │ ───── 2. destination
10766 3 │ alter table users alter email set not null;
10767 ╰╴ ─ 1. source
10768 ");
10769 }
10770
10771 #[test]
10772 fn goto_alter_table_column_with_column_keyword() {
10773 assert_snapshot!(goto("
10774create table users(id int, email text);
10775alter table users alter column email$0 set not null;
10776"), @r"
10777 ╭▸
10778 2 │ create table users(id int, email text);
10779 │ ───── 2. destination
10780 3 │ alter table users alter column email set not null;
10781 ╰╴ ─ 1. source
10782 ");
10783 }
10784
10785 #[test]
10786 fn goto_alter_table_rename_column() {
10787 assert_snapshot!(goto("
10788create table users(id int, email text);
10789alter table users rename column email$0 to email_address;
10790"), @"
10791 ╭▸
10792 2 │ create table users(id int, email text);
10793 │ ───── 2. destination
10794 3 │ alter table users rename column email to email_address;
10795 ╰╴ ─ 1. source
10796 ");
10797 }
10798
10799 #[test]
10800 fn goto_alter_view_alter_column() {
10801 assert_snapshot!(goto("
10802create table t(a int);
10803create view v as select a from t;
10804alter view v alter column a$0 set default 1;
10805"), @"
10806 ╭▸
10807 3 │ create view v as select a from t;
10808 │ ─ 2. destination
10809 4 │ alter view v alter column a set default 1;
10810 ╰╴ ─ 1. source
10811 ");
10812 }
10813
10814 #[test]
10815 fn goto_alter_view_rename_column() {
10816 assert_snapshot!(goto("
10817create table t(a int);
10818create view v as select a from t;
10819alter view v rename column a$0 to b;
10820"), @"
10821 ╭▸
10822 3 │ create view v as select a from t;
10823 │ ─ 2. destination
10824 4 │ alter view v rename column a to b;
10825 ╰╴ ─ 1. source
10826 ");
10827 }
10828
10829 #[test]
10830 fn goto_alter_materialized_view_rename_column() {
10831 assert_snapshot!(goto("
10832create table t(a int);
10833create materialized view mv as select a from t;
10834alter materialized view mv rename column a$0 to b;
10835"), @"
10836 ╭▸
10837 3 │ create materialized view mv as select a from t;
10838 │ ─ 2. destination
10839 4 │ alter materialized view mv rename column a to b;
10840 ╰╴ ─ 1. source
10841 ");
10842 }
10843
10844 #[test]
10845 fn goto_alter_table_add_column() {
10846 assert_snapshot!(goto("
10847create table users(id int);
10848alter table users$0 add column email text;
10849"), @r"
10850 ╭▸
10851 2 │ create table users(id int);
10852 │ ───── 2. destination
10853 3 │ alter table users add column email text;
10854 ╰╴ ─ 1. source
10855 ");
10856 }
10857
10858 #[test]
10859 fn goto_alter_table_drop_column() {
10860 assert_snapshot!(goto("
10861create table users(id int, email text);
10862alter table users drop column email$0;
10863"), @r"
10864 ╭▸
10865 2 │ create table users(id int, email text);
10866 │ ───── 2. destination
10867 3 │ alter table users drop column email;
10868 ╰╴ ─ 1. source
10869 ");
10870 }
10871
10872 #[test]
10873 fn goto_alter_table_drop_column_table_name() {
10874 assert_snapshot!(goto("
10875create table users(id int, email text);
10876alter table users$0 drop column email;
10877"), @r"
10878 ╭▸
10879 2 │ create table users(id int, email text);
10880 │ ───── 2. destination
10881 3 │ alter table users drop column email;
10882 ╰╴ ─ 1. source
10883 ");
10884 }
10885
10886 #[test]
10887 fn goto_alter_table_add_constraint_using_index() {
10888 assert_snapshot!(goto("
10889create table u(id int);
10890create index my_index on u (id);
10891alter table u add constraint uq unique using index my_in$0dex;
10892"), @r"
10893 ╭▸
10894 3 │ create index my_index on u (id);
10895 │ ──────── 2. destination
10896 4 │ alter table u add constraint uq unique using index my_index;
10897 ╰╴ ─ 1. source
10898 ");
10899 }
10900
10901 #[test]
10902 fn goto_alter_table_owner_to_role() {
10903 assert_snapshot!(goto("
10904create role reader;
10905create table t(id int);
10906alter table t owner to read$0er;
10907"), @r"
10908 ╭▸
10909 2 │ create role reader;
10910 │ ────── 2. destination
10911 3 │ create table t(id int);
10912 4 │ alter table t owner to reader;
10913 ╰╴ ─ 1. source
10914 ");
10915 }
10916
10917 #[test]
10918 fn goto_alter_table_set_tablespace() {
10919 assert_snapshot!(goto("
10920create tablespace ts location '/tmp/ts';
10921create table t(id int);
10922alter table t set tablespace t$0s;
10923"), @r"
10924 ╭▸
10925 2 │ create tablespace ts location '/tmp/ts';
10926 │ ── 2. destination
10927 3 │ create table t(id int);
10928 4 │ alter table t set tablespace ts;
10929 ╰╴ ─ 1. source
10930 ");
10931 }
10932
10933 #[test]
10934 fn goto_alter_table_all_in_tablespace() {
10935 assert_snapshot!(goto("
10936create tablespace ts location '/tmp/ts';
10937alter table all in tablespace t$0s set tablespace pg_default;
10938"), @"
10939 ╭▸
10940 2 │ create tablespace ts location '/tmp/ts';
10941 │ ── 2. destination
10942 3 │ alter table all in tablespace ts set tablespace pg_default;
10943 ╰╴ ─ 1. source
10944 ");
10945 }
10946
10947 #[test]
10948 fn goto_alter_materialized_view_all_in_tablespace() {
10949 assert_snapshot!(goto("
10950create tablespace ts location '/tmp/ts';
10951alter materialized view all in tablespace t$0s set tablespace pg_default;
10952"), @"
10953 ╭▸
10954 2 │ create tablespace ts location '/tmp/ts';
10955 │ ── 2. destination
10956 3 │ alter materialized view all in tablespace ts set tablespace pg_default;
10957 ╰╴ ─ 1. source
10958 ");
10959 }
10960
10961 #[test]
10962 fn goto_alter_index_all_in_tablespace() {
10963 assert_snapshot!(goto("
10964create tablespace ts location '/tmp/ts';
10965alter index all in tablespace t$0s set tablespace pg_default;
10966"), @"
10967 ╭▸
10968 2 │ create tablespace ts location '/tmp/ts';
10969 │ ── 2. destination
10970 3 │ alter index all in tablespace ts set tablespace pg_default;
10971 ╰╴ ─ 1. source
10972 ");
10973 }
10974
10975 #[test]
10976 fn goto_create_database_owner() {
10977 assert_snapshot!(goto("
10978create role r;
10979create database d owner r$0;
10980"), @"
10981 ╭▸
10982 2 │ create role r;
10983 │ ─ 2. destination
10984 3 │ create database d owner r;
10985 ╰╴ ─ 1. source
10986 ");
10987 }
10988
10989 #[test]
10990 fn goto_create_database_template() {
10991 assert_snapshot!(goto("
10992create database tmpl;
10993create database d template tmpl$0;
10994"), @"
10995 ╭▸
10996 2 │ create database tmpl;
10997 │ ──── 2. destination
10998 3 │ create database d template tmpl;
10999 ╰╴ ─ 1. source
11000 ");
11001 }
11002
11003 #[test]
11004 fn goto_create_database_tablespace() {
11005 assert_snapshot!(goto("
11006create tablespace ts location '/tmp';
11007create database d tablespace ts$0;
11008"), @"
11009 ╭▸
11010 2 │ create tablespace ts location '/tmp';
11011 │ ── 2. destination
11012 3 │ create database d tablespace ts;
11013 ╰╴ ─ 1. source
11014 ");
11015 }
11016
11017 #[test]
11018 fn goto_alter_table_set_schema() {
11019 assert_snapshot!(goto("
11020create schema foo;
11021create table t(id int);
11022alter table t set schema fo$0o;
11023"), @r"
11024 ╭▸
11025 2 │ create schema foo;
11026 │ ─── 2. destination
11027 3 │ create table t(id int);
11028 4 │ alter table t set schema foo;
11029 ╰╴ ─ 1. source
11030 ");
11031 }
11032
11033 #[test]
11034 fn goto_alter_table_attach_partition() {
11035 assert_snapshot!(goto("
11036create table parent (id int) partition by range (id);
11037create table child (id int);
11038alter table parent attach partition ch$0ild for values from (1) to (10);
11039"), @r"
11040 ╭▸
11041 3 │ create table child (id int);
11042 │ ───── 2. destination
11043 4 │ alter table parent attach partition child for values from (1) to (10);
11044 ╰╴ ─ 1. source
11045 ");
11046 }
11047
11048 #[test]
11049 fn goto_alter_table_detach_partition() {
11050 assert_snapshot!(goto("
11051create table parent (id int) partition by range (id);
11052create table child partition of parent for values from (1) to (10);
11053alter table parent detach partition ch$0ild;
11054"), @r"
11055 ╭▸
11056 3 │ create table child partition of parent for values from (1) to (10);
11057 │ ───── 2. destination
11058 4 │ alter table parent detach partition child;
11059 ╰╴ ─ 1. source
11060 ");
11061 }
11062
11063 #[test]
11064 fn goto_comment_on_table() {
11065 assert_snapshot!(goto("
11066create table t(id int);
11067comment on table t$0 is '';
11068"), @r"
11069 ╭▸
11070 2 │ create table t(id int);
11071 │ ─ 2. destination
11072 3 │ comment on table t is '';
11073 ╰╴ ─ 1. source
11074 ");
11075 }
11076
11077 #[test]
11078 fn goto_comment_on_column() {
11079 assert_snapshot!(goto("
11080create table t(id int);
11081comment on column t.id$0 is '';
11082"), @"
11083 ╭▸
11084 2 │ create table t(id int);
11085 │ ── 2. destination
11086 3 │ comment on column t.id is '';
11087 ╰╴ ─ 1. source
11088 ");
11089 }
11090
11091 #[test]
11092 fn goto_comment_on_column_table_qualifier() {
11093 assert_snapshot!(goto("
11094create table t(id int);
11095comment on column t$0.id is '';
11096"), @"
11097 ╭▸
11098 2 │ create table t(id int);
11099 │ ─ 2. destination
11100 3 │ comment on column t.id is '';
11101 ╰╴ ─ 1. source
11102 ");
11103 }
11104
11105 #[test]
11106 fn goto_comment_on_column_composite_type_attribute() {
11107 assert_snapshot!(goto("
11108create type address as (city text, zip text);
11109comment on column address.city$0 is 'x';
11110"), @"
11111 ╭▸
11112 2 │ create type address as (city text, zip text);
11113 │ ──── 2. destination
11114 3 │ comment on column address.city is 'x';
11115 ╰╴ ─ 1. source
11116 ");
11117 }
11118
11119 #[test]
11120 fn goto_comment_on_view() {
11121 assert_snapshot!(goto("
11122create view v as select 1;
11123comment on view v$0 is '';
11124"), @"
11125 ╭▸
11126 2 │ create view v as select 1;
11127 │ ─ 2. destination
11128 3 │ comment on view v is '';
11129 ╰╴ ─ 1. source
11130 ");
11131 }
11132
11133 #[test]
11134 fn goto_comment_on_materialized_view() {
11135 assert_snapshot!(goto("
11136create materialized view mv as select 1;
11137comment on materialized view mv$0 is '';
11138"), @"
11139 ╭▸
11140 2 │ create materialized view mv as select 1;
11141 │ ── 2. destination
11142 3 │ comment on materialized view mv is '';
11143 ╰╴ ─ 1. source
11144 ");
11145 }
11146
11147 #[test]
11148 fn goto_comment_on_sequence() {
11149 assert_snapshot!(goto("
11150create sequence s;
11151comment on sequence s$0 is '';
11152"), @"
11153 ╭▸
11154 2 │ create sequence s;
11155 │ ─ 2. destination
11156 3 │ comment on sequence s is '';
11157 ╰╴ ─ 1. source
11158 ");
11159 }
11160
11161 #[test]
11162 fn goto_comment_on_type() {
11163 assert_snapshot!(goto("
11164create type t as (a int);
11165comment on type t$0 is '';
11166"), @"
11167 ╭▸
11168 2 │ create type t as (a int);
11169 │ ─ 2. destination
11170 3 │ comment on type t is '';
11171 ╰╴ ─ 1. source
11172 ");
11173 }
11174
11175 #[test]
11176 fn goto_comment_on_function() {
11177 assert_snapshot!(goto("
11178create function f() returns int language sql as 'select 1';
11179comment on function f$0 is '';
11180"), @"
11181 ╭▸
11182 2 │ create function f() returns int language sql as 'select 1';
11183 │ ─ 2. destination
11184 3 │ comment on function f is '';
11185 ╰╴ ─ 1. source
11186 ");
11187 }
11188
11189 #[test]
11190 fn goto_comment_on_index() {
11191 assert_snapshot!(goto("
11192create table foo(id int);
11193create index i on foo(id);
11194comment on index i$0 is '';
11195"), @"
11196 ╭▸
11197 3 │ create index i on foo(id);
11198 │ ─ 2. destination
11199 4 │ comment on index i is '';
11200 ╰╴ ─ 1. source
11201 ");
11202 }
11203
11204 #[test]
11205 fn goto_comment_on_trigger() {
11206 assert_snapshot!(goto("
11207create table t(a int);
11208create function f() returns trigger language plpgsql as $$
11209begin
11210 return new;
11211end
11212$$;
11213create trigger tr
11214 before insert on t
11215 for each row
11216 execute function f();
11217comment on trigger tr$0 on t is 'x';
11218"), @"
11219 ╭▸
11220 8 │ create trigger tr
11221 │ ── 2. destination
11222 ‡
11223 12 │ comment on trigger tr on t is 'x';
11224 ╰╴ ─ 1. source
11225 ");
11226 }
11227
11228 #[test]
11229 fn goto_comment_on_policy() {
11230 assert_snapshot!(goto("
11231create table t(a int);
11232create policy p on t using (a > 0);
11233comment on policy p$0 on t is 'x';
11234"), @"
11235 ╭▸
11236 3 │ create policy p on t using (a > 0);
11237 │ ─ 2. destination
11238 4 │ comment on policy p on t is 'x';
11239 ╰╴ ─ 1. source
11240 ");
11241 }
11242
11243 #[test]
11244 fn goto_comment_on_rule() {
11245 assert_snapshot!(goto("
11246create table t(a int);
11247create rule r as on select to t do instead nothing;
11248comment on rule r$0 on t is 'x';
11249"), @"
11250 ╭▸
11251 3 │ create rule r as on select to t do instead nothing;
11252 │ ─ 2. destination
11253 4 │ comment on rule r on t is 'x';
11254 ╰╴ ─ 1. source
11255 ");
11256 }
11257
11258 #[test]
11259 fn goto_comment_on_publication() {
11260 assert_snapshot!(goto("
11261create publication pub;
11262comment on publication pub$0 is 'x';
11263"), @"
11264 ╭▸
11265 2 │ create publication pub;
11266 │ ─── 2. destination
11267 3 │ comment on publication pub is 'x';
11268 ╰╴ ─ 1. source
11269 ");
11270 }
11271
11272 #[test]
11273 fn goto_comment_on_subscription() {
11274 assert_snapshot!(goto("
11275create subscription sub connection $$host=localhost$$ publication pub;
11276comment on subscription sub$0 is 'x';
11277"), @"
11278 ╭▸
11279 2 │ create subscription sub connection $$host=localhost$$ publication pub;
11280 │ ─── 2. destination
11281 3 │ comment on subscription sub is 'x';
11282 ╰╴ ─ 1. source
11283 ");
11284 }
11285
11286 #[test]
11287 fn goto_comment_on_foreign_data_wrapper() {
11288 assert_snapshot!(goto("
11289create foreign data wrapper fdw;
11290comment on foreign data wrapper fdw$0 is 'x';
11291"), @"
11292 ╭▸
11293 2 │ create foreign data wrapper fdw;
11294 │ ─── 2. destination
11295 3 │ comment on foreign data wrapper fdw is 'x';
11296 ╰╴ ─ 1. source
11297 ");
11298 }
11299
11300 #[test]
11301 fn goto_comment_on_language() {
11302 assert_snapshot!(goto("
11303create language plfoo;
11304comment on language plfoo$0 is 'x';
11305"), @"
11306 ╭▸
11307 2 │ create language plfoo;
11308 │ ───── 2. destination
11309 3 │ comment on language plfoo is 'x';
11310 ╰╴ ─ 1. source
11311 ");
11312 }
11313
11314 #[test]
11315 fn goto_comment_on_collation() {
11316 assert_snapshot!(goto("
11317create collation mycoll (locale = 'C');
11318comment on collation mycoll$0 is 'x';
11319"), @"
11320 ╭▸
11321 2 │ create collation mycoll (locale = 'C');
11322 │ ────── 2. destination
11323 3 │ comment on collation mycoll is 'x';
11324 ╰╴ ─ 1. source
11325 ");
11326 }
11327
11328 #[test]
11329 fn goto_drop_conversion() {
11330 assert_snapshot!(goto("
11331create conversion conv for 'UTF8' to 'LATIN1' from utf8_to_latin1;
11332drop conversion con$0v;
11333"), @"
11334 ╭▸
11335 2 │ create conversion conv for 'UTF8' to 'LATIN1' from utf8_to_latin1;
11336 │ ──── 2. destination
11337 3 │ drop conversion conv;
11338 ╰╴ ─ 1. source
11339 ");
11340 }
11341
11342 #[test]
11343 fn goto_comment_on_conversion() {
11344 assert_snapshot!(goto("
11345create conversion conv for 'UTF8' to 'LATIN1' from utf8_to_latin1;
11346comment on conversion con$0v is 'x';
11347"), @"
11348 ╭▸
11349 2 │ create conversion conv for 'UTF8' to 'LATIN1' from utf8_to_latin1;
11350 │ ──── 2. destination
11351 3 │ comment on conversion conv is 'x';
11352 ╰╴ ─ 1. source
11353 ");
11354 }
11355
11356 #[test]
11357 fn goto_create_conversion_from_function() {
11358 assert_snapshot!(goto("
11359create function my_conv(integer, integer, cstring, internal, integer) returns void language c as $$x$$;
11360create conversion my_conv_obj for 'UTF8' to 'LATIN1' from my_co$0nv;
11361"), @"
11362 ╭▸
11363 2 │ create function my_conv(integer, integer, cstring, internal, integer) returns void language c as $$x$$;
11364 │ ─────── 2. destination
11365 3 │ create conversion my_conv_obj for 'UTF8' to 'LATIN1' from my_conv;
11366 ╰╴ ─ 1. source
11367 ");
11368 }
11369
11370 #[test]
11371 fn goto_drop_text_search_dictionary() {
11372 assert_snapshot!(goto("
11373create text search dictionary english_stem (template = snowball, language = english);
11374drop text search dictionary english_st$0em;
11375"), @"
11376 ╭▸
11377 2 │ create text search dictionary english_stem (template = snowball, language = english);
11378 │ ──────────── 2. destination
11379 3 │ drop text search dictionary english_stem;
11380 ╰╴ ─ 1. source
11381 ");
11382 }
11383
11384 #[test]
11385 fn goto_alter_text_search_dictionary() {
11386 assert_snapshot!(goto("
11387create text search dictionary english_stem (template = snowball, language = english);
11388alter text search dictionary english_st$0em rename to stemmer;
11389"), @"
11390 ╭▸
11391 2 │ create text search dictionary english_stem (template = snowball, language = english);
11392 │ ──────────── 2. destination
11393 3 │ alter text search dictionary english_stem rename to stemmer;
11394 ╰╴ ─ 1. source
11395 ");
11396 }
11397
11398 #[test]
11399 fn goto_drop_text_search_configuration() {
11400 assert_snapshot!(goto("
11401create text search configuration my_config (parser = pg_catalog.default);
11402drop text search configuration my_conf$0ig;
11403"), @"
11404 ╭▸
11405 2 │ create text search configuration my_config (parser = pg_catalog.default);
11406 │ ───────── 2. destination
11407 3 │ drop text search configuration my_config;
11408 ╰╴ ─ 1. source
11409 ");
11410 }
11411
11412 #[test]
11413 fn goto_alter_text_search_configuration() {
11414 assert_snapshot!(goto("
11415create text search configuration my_config (parser = pg_catalog.default);
11416alter text search configuration my_conf$0ig rename to my_config2;
11417"), @"
11418 ╭▸
11419 2 │ create text search configuration my_config (parser = pg_catalog.default);
11420 │ ───────── 2. destination
11421 3 │ alter text search configuration my_config rename to my_config2;
11422 ╰╴ ─ 1. source
11423 ");
11424 }
11425
11426 #[test]
11427 fn goto_drop_text_search_parser() {
11428 assert_snapshot!(goto("
11429create text search parser my_parser (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
11430drop text search parser my_pars$0er;
11431"), @"
11432 ╭▸
11433 2 │ create text search parser my_parser (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
11434 │ ───────── 2. destination
11435 3 │ drop text search parser my_parser;
11436 ╰╴ ─ 1. source
11437 ");
11438 }
11439
11440 #[test]
11441 fn goto_alter_text_search_parser() {
11442 assert_snapshot!(goto("
11443create text search parser my_parser (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
11444alter text search parser my_pars$0er rename to my_parser2;
11445"), @"
11446 ╭▸
11447 2 │ create text search parser my_parser (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
11448 │ ───────── 2. destination
11449 3 │ alter text search parser my_parser rename to my_parser2;
11450 ╰╴ ─ 1. source
11451 ");
11452 }
11453
11454 #[test]
11455 fn goto_drop_text_search_template() {
11456 assert_snapshot!(goto("
11457create text search template my_template (init = dsimple_init, lexize = dsimple_lexize);
11458drop text search template my_temp$0late;
11459"), @"
11460 ╭▸
11461 2 │ create text search template my_template (init = dsimple_init, lexize = dsimple_lexize);
11462 │ ─────────── 2. destination
11463 3 │ drop text search template my_template;
11464 ╰╴ ─ 1. source
11465 ");
11466 }
11467
11468 #[test]
11469 fn goto_alter_text_search_template() {
11470 assert_snapshot!(goto("
11471create text search template my_template (init = dsimple_init, lexize = dsimple_lexize);
11472alter text search template my_temp$0late rename to my_template2;
11473"), @"
11474 ╭▸
11475 2 │ create text search template my_template (init = dsimple_init, lexize = dsimple_lexize);
11476 │ ─────────── 2. destination
11477 3 │ alter text search template my_template rename to my_template2;
11478 ╰╴ ─ 1. source
11479 ");
11480 }
11481
11482 #[test]
11483 fn goto_create_text_search_parser_function_option() {
11484 assert_snapshot!(goto("
11485create function start_fn(internal, int) returns internal language c as $$x$$;
11486create text search parser p (start = start_$0fn, gettoken = g, end = e, lextypes = l);
11487"), @"
11488 ╭▸
11489 2 │ create function start_fn(internal, int) returns internal language c as $$x$$;
11490 │ ──────── 2. destination
11491 3 │ create text search parser p (start = start_fn, gettoken = g, end = e, lextypes = l);
11492 ╰╴ ─ 1. source
11493 ");
11494 }
11495
11496 #[test]
11497 fn goto_create_text_search_template_function_option() {
11498 assert_snapshot!(goto("
11499create function init_fn(internal) returns internal language c as $$x$$;
11500create text search template t (init = init_$0fn, lexize = lex_fn);
11501"), @"
11502 ╭▸
11503 2 │ create function init_fn(internal) returns internal language c as $$x$$;
11504 │ ─────── 2. destination
11505 3 │ create text search template t (init = init_fn, lexize = lex_fn);
11506 ╰╴ ─ 1. source
11507 ");
11508 }
11509
11510 #[test]
11511 fn goto_create_text_search_configuration_parser_option() {
11512 assert_snapshot!(goto("
11513create text search parser my_parser (start = s, gettoken = g, end = e, lextypes = l);
11514create text search configuration cfg (parser = my_par$0ser);
11515"), @"
11516 ╭▸
11517 2 │ create text search parser my_parser (start = s, gettoken = g, end = e, lextypes = l);
11518 │ ───────── 2. destination
11519 3 │ create text search configuration cfg (parser = my_parser);
11520 ╰╴ ─ 1. source
11521 ");
11522 }
11523
11524 #[test]
11525 fn goto_create_text_search_configuration_copy_option() {
11526 assert_snapshot!(goto("
11527create text search configuration src (parser = pg_catalog.default);
11528create text search configuration cfg (copy = sr$0c);
11529"), @"
11530 ╭▸
11531 2 │ create text search configuration src (parser = pg_catalog.default);
11532 │ ─── 2. destination
11533 3 │ create text search configuration cfg (copy = src);
11534 ╰╴ ─ 1. source
11535 ");
11536 }
11537
11538 #[test]
11539 fn goto_create_text_search_dictionary_template_option() {
11540 assert_snapshot!(goto("
11541create text search template my_template (init = i, lexize = l);
11542create text search dictionary dict (template = my_temp$0late);
11543"), @"
11544 ╭▸
11545 2 │ create text search template my_template (init = i, lexize = l);
11546 │ ─────────── 2. destination
11547 3 │ create text search dictionary dict (template = my_template);
11548 ╰╴ ─ 1. source
11549 ");
11550 }
11551
11552 #[test]
11553 fn goto_alter_text_search_configuration_add_mapping_dictionary() {
11554 assert_snapshot!(goto("
11555create text search dictionary dict (template = pg_catalog.simple);
11556create text search configuration cfg (parser = pg_catalog.default);
11557alter text search configuration cfg add mapping for asciiword with dic$0t;
11558"), @"
11559 ╭▸
11560 2 │ create text search dictionary dict (template = pg_catalog.simple);
11561 │ ──── 2. destination
11562 3 │ create text search configuration cfg (parser = pg_catalog.default);
11563 4 │ alter text search configuration cfg add mapping for asciiword with dict;
11564 ╰╴ ─ 1. source
11565 ");
11566 }
11567
11568 #[test]
11569 fn goto_alter_text_search_configuration_alter_mapping_with_dictionary() {
11570 assert_snapshot!(goto("
11571create text search dictionary d1 (template = pg_catalog.simple);
11572create text search configuration cfg (parser = pg_catalog.default);
11573alter text search configuration cfg alter mapping for asciiword with d$01;
11574"), @"
11575 ╭▸
11576 2 │ create text search dictionary d1 (template = pg_catalog.simple);
11577 │ ── 2. destination
11578 3 │ create text search configuration cfg (parser = pg_catalog.default);
11579 4 │ alter text search configuration cfg alter mapping for asciiword with d1;
11580 ╰╴ ─ 1. source
11581 ");
11582 }
11583
11584 #[test]
11585 fn goto_alter_text_search_configuration_alter_mapping_replace_dictionary() {
11586 assert_snapshot!(goto("
11587create text search dictionary d1 (template = pg_catalog.simple);
11588create text search dictionary d2 (template = pg_catalog.simple);
11589create text search configuration cfg (parser = pg_catalog.default);
11590alter text search configuration cfg alter mapping replace d1 with d$02;
11591"), @"
11592 ╭▸
11593 3 │ create text search dictionary d2 (template = pg_catalog.simple);
11594 │ ── 2. destination
11595 4 │ create text search configuration cfg (parser = pg_catalog.default);
11596 5 │ alter text search configuration cfg alter mapping replace d1 with d2;
11597 ╰╴ ─ 1. source
11598 ");
11599 }
11600
11601 #[test]
11602 fn goto_drop_access_method() {
11603 assert_snapshot!(goto("
11604create access method heap2 type table handler heap_tableam_handler;
11605drop access method hea$0p2;
11606"), @"
11607 ╭▸
11608 2 │ create access method heap2 type table handler heap_tableam_handler;
11609 │ ───── 2. destination
11610 3 │ drop access method heap2;
11611 ╰╴ ─ 1. source
11612 ");
11613 }
11614
11615 #[test]
11616 fn goto_set_access_method() {
11617 assert_snapshot!(goto("
11618create access method heap2 type table handler heap_tableam_handler;
11619alter table t set access method hea$0p2;
11620"), @"
11621 ╭▸
11622 2 │ create access method heap2 type table handler heap_tableam_handler;
11623 │ ───── 2. destination
11624 3 │ alter table t set access method heap2;
11625 ╰╴ ─ 1. source
11626 ");
11627 }
11628
11629 #[test]
11630 fn goto_drop_operator_family() {
11631 assert_snapshot!(goto("
11632create operator family my_family using btree;
11633drop operator family my_fami$0ly using btree;
11634"), @"
11635 ╭▸
11636 2 │ create operator family my_family using btree;
11637 │ ───────── 2. destination
11638 3 │ drop operator family my_family using btree;
11639 ╰╴ ─ 1. source
11640 ");
11641 }
11642
11643 #[test]
11644 fn goto_alter_operator_family() {
11645 assert_snapshot!(goto("
11646create operator family my_family using btree;
11647alter operator family my_fami$0ly using btree owner to someone;
11648"), @"
11649 ╭▸
11650 2 │ create operator family my_family using btree;
11651 │ ───────── 2. destination
11652 3 │ alter operator family my_family using btree owner to someone;
11653 ╰╴ ─ 1. source
11654 ");
11655 }
11656
11657 #[test]
11658 fn goto_comment_on_operator_family() {
11659 assert_snapshot!(goto("
11660create operator family my_family using btree;
11661comment on operator family my_fami$0ly using btree is 'hi';
11662"), @"
11663 ╭▸
11664 2 │ create operator family my_family using btree;
11665 │ ───────── 2. destination
11666 3 │ comment on operator family my_family using btree is 'hi';
11667 ╰╴ ─ 1. source
11668 ");
11669 }
11670
11671 #[test]
11672 fn goto_comment_on_operator_class() {
11673 assert_snapshot!(goto("
11674create operator class my_opclass for type int using btree as operator 1 < (int, int);
11675comment on operator class my_opcla$0ss using btree is 'hi';
11676"), @"
11677 ╭▸
11678 2 │ create operator class my_opclass for type int using btree as operator 1 < (int, int);
11679 │ ────────── 2. destination
11680 3 │ comment on operator class my_opclass using btree is 'hi';
11681 ╰╴ ─ 1. source
11682 ");
11683 }
11684
11685 #[test]
11686 fn goto_drop_operator_class() {
11687 assert_snapshot!(goto("
11688create operator class my_opclass for type int using btree as operator 1 < (int, int);
11689drop operator class my_opcla$0ss using btree;
11690"), @"
11691 ╭▸
11692 2 │ create operator class my_opclass for type int using btree as operator 1 < (int, int);
11693 │ ────────── 2. destination
11694 3 │ drop operator class my_opclass using btree;
11695 ╰╴ ─ 1. source
11696 ");
11697 }
11698
11699 #[test]
11700 fn goto_alter_operator_class() {
11701 assert_snapshot!(goto("
11702create operator class my_opclass for type int using btree as operator 1 < (int, int);
11703alter operator class my_opcla$0ss using btree owner to someone;
11704"), @"
11705 ╭▸
11706 2 │ create operator class my_opclass for type int using btree as operator 1 < (int, int);
11707 │ ────────── 2. destination
11708 3 │ alter operator class my_opclass using btree owner to someone;
11709 ╰╴ ─ 1. source
11710 ");
11711 }
11712
11713 #[test]
11714 fn goto_create_index_using_access_method() {
11715 assert_snapshot!(goto("
11716create function my_handler(internal) returns index_am_handler language c as $$x$$;
11717create access method my_am type index handler my_handler;
11718create table t(id int);
11719create index on t using my_a$0m (id);
11720"), @"
11721 ╭▸
11722 3 │ create access method my_am type index handler my_handler;
11723 │ ───── 2. destination
11724 4 │ create table t(id int);
11725 5 │ create index on t using my_am (id);
11726 ╰╴ ─ 1. source
11727 ");
11728 }
11729
11730 #[test]
11731 fn goto_create_table_using_access_method() {
11732 assert_snapshot!(goto("
11733create function my_handler(internal) returns table_am_handler language c as $$x$$;
11734create access method my_am type table handler my_handler;
11735create table t(id int) using my_a$0m;
11736"), @"
11737 ╭▸
11738 3 │ create access method my_am type table handler my_handler;
11739 │ ───── 2. destination
11740 4 │ create table t(id int) using my_am;
11741 ╰╴ ─ 1. source
11742 ");
11743 }
11744
11745 #[test]
11746 fn goto_create_operator_family_using_access_method() {
11747 assert_snapshot!(goto("
11748create function my_handler(internal) returns index_am_handler language c as $$x$$;
11749create access method my_am type index handler my_handler;
11750create operator family fam using my_a$0m;
11751"), @"
11752 ╭▸
11753 3 │ create access method my_am type index handler my_handler;
11754 │ ───── 2. destination
11755 4 │ create operator family fam using my_am;
11756 ╰╴ ─ 1. source
11757 ");
11758 }
11759
11760 #[test]
11761 fn goto_create_operator_class_using_access_method() {
11762 assert_snapshot!(goto("
11763create function my_handler(internal) returns index_am_handler language c as $$x$$;
11764create access method my_am type index handler my_handler;
11765create operator class my_opclass for type int using my_a$0m as storage int;
11766"), @"
11767 ╭▸
11768 3 │ create access method my_am type index handler my_handler;
11769 │ ───── 2. destination
11770 4 │ create operator class my_opclass for type int using my_am as storage int;
11771 ╰╴ ─ 1. source
11772 ");
11773 }
11774
11775 #[test]
11776 fn goto_create_operator_class_family() {
11777 assert_snapshot!(goto("
11778create function h(internal) returns index_am_handler language c as $$x$$;
11779create access method fam type index handler h;
11780create operator family fam using btree;
11781create operator class ops for type int using btree family fa$0m as operator 1 <;
11782"), @"
11783 ╭▸
11784 4 │ create operator family fam using btree;
11785 │ ─── 2. destination
11786 5 │ create operator class ops for type int using btree family fam as operator 1 <;
11787 ╰╴ ─ 1. source
11788 ");
11789 }
11790
11791 #[test]
11792 fn goto_create_operator_class_for_order_by_family() {
11793 assert_snapshot!(goto("
11794create operator family sort_fam using btree;
11795create operator class ops for type int using gist as operator 1 <-> for order by sort_f$0am;
11796"), @"
11797 ╭▸
11798 2 │ create operator family sort_fam using btree;
11799 │ ──────── 2. destination
11800 3 │ create operator class ops for type int using gist as operator 1 <-> for order by sort_fam;
11801 ╰╴ ─ 1. source
11802 ");
11803 }
11804
11805 #[test]
11806 fn goto_insert_on_conflict_operator_class() {
11807 assert_snapshot!(goto("
11808create operator class my_ops for type int using btree as operator 1 <;
11809create table t(a int);
11810insert into t values (1) on conflict (a my_o$0ps) do nothing;
11811"), @"
11812 ╭▸
11813 2 │ create operator class my_ops for type int using btree as operator 1 <;
11814 │ ────── 2. destination
11815 3 │ create table t(a int);
11816 4 │ insert into t values (1) on conflict (a my_ops) do nothing;
11817 ╰╴ ─ 1. source
11818 ");
11819 }
11820
11821 #[test]
11822 fn goto_create_index_operator_class() {
11823 assert_snapshot!(goto("
11824create operator class public.my_ops for type int using btree as operator 1 <, function 1 btint4cmp(int,int);
11825create table t(a int);
11826create index idx on t (a public.my_o$0ps);
11827"), @"
11828 ╭▸
11829 2 │ create operator class public.my_ops for type int using btree as operator 1 <, function 1 btint4cmp(int,int);
11830 │ ────── 2. destination
11831 3 │ create table t(a int);
11832 4 │ create index idx on t (a public.my_ops);
11833 ╰╴ ─ 1. source
11834 ");
11835 }
11836
11837 #[test]
11838 fn goto_alter_operator_family_using_access_method() {
11839 assert_snapshot!(goto("
11840create function my_handler(internal) returns index_am_handler language c as $$x$$;
11841create access method my_am type index handler my_handler;
11842create operator family fam using my_am;
11843alter operator family fam using my_a$0m owner to someone;
11844"), @"
11845 ╭▸
11846 3 │ create access method my_am type index handler my_handler;
11847 │ ───── 2. destination
11848 4 │ create operator family fam using my_am;
11849 5 │ alter operator family fam using my_am owner to someone;
11850 ╰╴ ─ 1. source
11851 ");
11852 }
11853
11854 #[test]
11855 fn goto_drop_operator_class_using_access_method() {
11856 assert_snapshot!(goto("
11857create function my_handler(internal) returns index_am_handler language c as $$x$$;
11858create access method my_am type index handler my_handler;
11859create operator class my_opclass for type int using my_am as storage int;
11860drop operator class my_opclass using my_a$0m;
11861"), @"
11862 ╭▸
11863 3 │ create access method my_am type index handler my_handler;
11864 │ ───── 2. destination
11865 4 │ create operator class my_opclass for type int using my_am as storage int;
11866 5 │ drop operator class my_opclass using my_am;
11867 ╰╴ ─ 1. source
11868 ");
11869 }
11870
11871 #[test]
11872 fn goto_operator_class_function_option() {
11873 assert_snapshot!(goto("
11874create function my_cmp(int, int) returns int language sql as $$select 0$$;
11875create operator class my_opclass for type int using btree as function 1 my_cm$0p(int, int);
11876"), @"
11877 ╭▸
11878 2 │ create function my_cmp(int, int) returns int language sql as $$select 0$$;
11879 │ ────── 2. destination
11880 3 │ create operator class my_opclass for type int using btree as function 1 my_cmp(int, int);
11881 ╰╴ ─ 1. source
11882 ");
11883 }
11884
11885 #[test]
11886 fn goto_drop_operator_class_explicit_schema() {
11887 assert_snapshot!(goto("
11888create schema app;
11889create operator class app.my_ops for type int using btree as storage int;
11890drop operator class app.my_o$0ps using btree;
11891"), @"
11892 ╭▸
11893 3 │ create operator class app.my_ops for type int using btree as storage int;
11894 │ ────── 2. destination
11895 4 │ drop operator class app.my_ops using btree;
11896 ╰╴ ─ 1. source
11897 ");
11898 }
11899
11900 #[test]
11901 fn goto_drop_operator_class_wrong_explicit_schema_not_found() {
11902 goto_not_found(
11903 "
11904create schema app;
11905create operator class app.my_ops for type int using btree as storage int;
11906set search_path to app;
11907drop operator class public.my_o$0ps using btree;
11908",
11909 );
11910 }
11911
11912 #[test]
11913 fn goto_drop_collation_explicit_schema() {
11914 assert_snapshot!(goto(r#"
11915create schema app;
11916create collation app.coll (locale = 'C');
11917drop collation app.co$0ll;
11918"#), @"
11919 ╭▸
11920 3 │ create collation app.coll (locale = 'C');
11921 │ ──── 2. destination
11922 4 │ drop collation app.coll;
11923 ╰╴ ─ 1. source
11924 ");
11925 }
11926
11927 #[test]
11928 fn goto_drop_text_search_configuration_explicit_schema() {
11929 assert_snapshot!(goto("
11930create schema app;
11931create text search configuration app.cfg (parser = pg_catalog.default);
11932drop text search configuration app.c$0fg;
11933"), @"
11934 ╭▸
11935 3 │ create text search configuration app.cfg (parser = pg_catalog.default);
11936 │ ─── 2. destination
11937 4 │ drop text search configuration app.cfg;
11938 ╰╴ ─ 1. source
11939 ");
11940 }
11941
11942 #[test]
11943 fn goto_drop_text_search_configuration_wrong_explicit_schema_not_found() {
11944 goto_not_found(
11945 "
11946create schema app;
11947create text search configuration app.cfg (parser = pg_catalog.default);
11948set search_path to app;
11949drop text search configuration public.c$0fg;
11950",
11951 );
11952 }
11953
11954 #[test]
11955 fn goto_grant_table_explicit_schema() {
11956 assert_snapshot!(goto("
11957create schema app;
11958create table app.t(a int);
11959grant select on app.t$0 to public;
11960"), @"
11961 ╭▸
11962 3 │ create table app.t(a int);
11963 │ ─ 2. destination
11964 4 │ grant select on app.t to public;
11965 ╰╴ ─ 1. source
11966 ");
11967 }
11968
11969 #[test]
11970 fn goto_grant_table_wrong_explicit_schema_not_found() {
11971 goto_not_found(
11972 "
11973create schema app;
11974create table app.t(a int);
11975set search_path to app;
11976grant select on public.t$0 to public;
11977",
11978 );
11979 }
11980
11981 #[test]
11982 fn goto_security_label_table() {
11983 assert_snapshot!(goto("
11984create table foo(id int);
11985security label on table foo$0 is 'x';
11986"), @"
11987 ╭▸
11988 2 │ create table foo(id int);
11989 │ ─── 2. destination
11990 3 │ security label on table foo is 'x';
11991 ╰╴ ─ 1. source
11992 ");
11993 }
11994
11995 #[test]
11996 fn goto_security_label_column() {
11997 assert_snapshot!(goto("
11998create table foo(id int);
11999security label on column foo.id$0 is 'x';
12000"), @"
12001 ╭▸
12002 2 │ create table foo(id int);
12003 │ ── 2. destination
12004 3 │ security label on column foo.id is 'x';
12005 ╰╴ ─ 1. source
12006 ");
12007 }
12008
12009 #[test]
12010 fn goto_security_label_column_table_qualifier() {
12011 assert_snapshot!(goto("
12012create table foo(id int);
12013security label on column foo$0.id is 'x';
12014"), @"
12015 ╭▸
12016 2 │ create table foo(id int);
12017 │ ─── 2. destination
12018 3 │ security label on column foo.id is 'x';
12019 ╰╴ ─ 1. source
12020 ");
12021 }
12022
12023 #[test]
12024 fn goto_security_label_view() {
12025 assert_snapshot!(goto("
12026create view v as select 1;
12027security label on view v$0 is 'x';
12028"), @"
12029 ╭▸
12030 2 │ create view v as select 1;
12031 │ ─ 2. destination
12032 3 │ security label on view v is 'x';
12033 ╰╴ ─ 1. source
12034 ");
12035 }
12036
12037 #[test]
12038 fn goto_security_label_type() {
12039 assert_snapshot!(goto("
12040create type t as (a int);
12041security label on type t$0 is 'x';
12042"), @"
12043 ╭▸
12044 2 │ create type t as (a int);
12045 │ ─ 2. destination
12046 3 │ security label on type t is 'x';
12047 ╰╴ ─ 1. source
12048 ");
12049 }
12050
12051 #[test]
12052 fn goto_security_label_function() {
12053 assert_snapshot!(goto("
12054create function f() returns int language sql as 'select 1';
12055security label on function f$0() is 'x';
12056"), @"
12057 ╭▸
12058 2 │ create function f() returns int language sql as 'select 1';
12059 │ ─ 2. destination
12060 3 │ security label on function f() is 'x';
12061 ╰╴ ─ 1. source
12062 ");
12063 }
12064
12065 #[test]
12066 fn goto_security_label_provider_unresolved() {
12067 goto_not_found(
12068 "
12069create table foo(id int);
12070security label for prov$0 on table foo is 'x';
12071",
12072 );
12073 }
12074
12075 #[test]
12076 fn goto_refresh_materialized_view() {
12077 assert_snapshot!(goto("
12078create materialized view mv as select 1;
12079refresh materialized view mv$0;
12080"), @r"
12081 ╭▸
12082 2 │ create materialized view mv as select 1;
12083 │ ── 2. destination
12084 3 │ refresh materialized view mv;
12085 ╰╴ ─ 1. source
12086 ");
12087 }
12088
12089 #[test]
12090 fn goto_refresh_materialized_view_concurrently() {
12091 assert_snapshot!(goto("
12092create materialized view mv as select 1;
12093refresh materialized view concurrently mv$0;
12094"), @r"
12095 ╭▸
12096 2 │ create materialized view mv as select 1;
12097 │ ── 2. destination
12098 3 │ refresh materialized view concurrently mv;
12099 ╰╴ ─ 1. source
12100 ");
12101 }
12102
12103 #[test]
12104 fn goto_reindex_table() {
12105 assert_snapshot!(goto("
12106create table users(id int);
12107reindex table users$0;
12108"), @r"
12109 ╭▸
12110 2 │ create table users(id int);
12111 │ ───── 2. destination
12112 3 │ reindex table users;
12113 ╰╴ ─ 1. source
12114 ");
12115 }
12116
12117 #[test]
12118 fn goto_reindex_index() {
12119 assert_snapshot!(goto("
12120create table t(c int);
12121create index idx on t(c);
12122reindex index idx$0;
12123"), @r"
12124 ╭▸
12125 3 │ create index idx on t(c);
12126 │ ─── 2. destination
12127 4 │ reindex index idx;
12128 ╰╴ ─ 1. source
12129 ");
12130 }
12131
12132 #[test]
12133 fn goto_cluster_table() {
12134 assert_snapshot!(goto("
12135create table foo(id int);
12136cluster foo$0;
12137"), @"
12138 ╭▸
12139 2 │ create table foo(id int);
12140 │ ─── 2. destination
12141 3 │ cluster foo;
12142 ╰╴ ─ 1. source
12143 ");
12144 }
12145
12146 #[test]
12147 fn goto_cluster_using_index() {
12148 assert_snapshot!(goto("
12149create table foo(id int);
12150create index i on foo(id);
12151cluster foo using i$0;
12152"), @"
12153 ╭▸
12154 3 │ create index i on foo(id);
12155 │ ─ 2. destination
12156 4 │ cluster foo using i;
12157 ╰╴ ─ 1. source
12158 ");
12159 }
12160
12161 #[test]
12162 fn goto_alter_table_cluster_on() {
12163 assert_snapshot!(goto("
12164create table t(a int);
12165create index idx on t(a);
12166alter table t cluster on idx$0;
12167"), @"
12168 ╭▸
12169 3 │ create index idx on t(a);
12170 │ ─── 2. destination
12171 4 │ alter table t cluster on idx;
12172 ╰╴ ─ 1. source
12173 ");
12174 }
12175
12176 #[test]
12177 fn goto_alter_table_replica_identity_using_index() {
12178 assert_snapshot!(goto("
12179create table t(a int);
12180create unique index idx on t(a);
12181alter table t replica identity using index idx$0;
12182"), @"
12183 ╭▸
12184 3 │ create unique index idx on t(a);
12185 │ ─── 2. destination
12186 4 │ alter table t replica identity using index idx;
12187 ╰╴ ─ 1. source
12188 ");
12189 }
12190
12191 #[test]
12192 fn goto_copy_table() {
12193 assert_snapshot!(goto("
12194create table foo (id int);
12195copy foo$0 to stdout;
12196"), @"
12197 ╭▸
12198 2 │ create table foo (id int);
12199 │ ─── 2. destination
12200 3 │ copy foo to stdout;
12201 ╰╴ ─ 1. source
12202 ");
12203 }
12204
12205 #[test]
12206 fn goto_copy_column() {
12207 assert_snapshot!(goto("
12208create table foo (id int);
12209copy foo (id$0) to stdout;
12210"), @"
12211 ╭▸
12212 2 │ create table foo (id int);
12213 │ ── 2. destination
12214 3 │ copy foo (id) to stdout;
12215 ╰╴ ─ 1. source
12216 ");
12217 }
12218
12219 #[test]
12220 fn goto_select_exists_column() {
12221 assert_snapshot!(goto("
12222select exists$0 from (
12223 select exists(select 1)
12224);
12225"), @r"
12226 ╭▸
12227 2 │ select exists from (
12228 │ ─ 1. source
12229 3 │ select exists(select 1)
12230 ╰╴ ──────────────── 2. destination
12231 ");
12232 }
12233
12234 #[test]
12235 fn goto_reindex_schema() {
12236 assert_snapshot!(goto("
12237create schema app;
12238reindex schema app$0;
12239"), @r"
12240 ╭▸
12241 2 │ create schema app;
12242 │ ─── 2. destination
12243 3 │ reindex schema app;
12244 ╰╴ ─ 1. source
12245 ");
12246 }
12247
12248 #[test]
12249 fn goto_reindex_database() {
12250 assert_snapshot!(goto("
12251create database appdb;
12252reindex database appdb$0;
12253"), @r"
12254 ╭▸
12255 2 │ create database appdb;
12256 │ ───── 2. destination
12257 3 │ reindex database appdb;
12258 ╰╴ ─ 1. source
12259 ");
12260 }
12261
12262 #[test]
12263 fn goto_reindex_system() {
12264 assert_snapshot!(goto("
12265create database systemdb;
12266reindex system systemdb$0;
12267"), @r"
12268 ╭▸
12269 2 │ create database systemdb;
12270 │ ──────── 2. destination
12271 3 │ reindex system systemdb;
12272 ╰╴ ─ 1. source
12273 ");
12274 }
12275
12276 #[test]
12277 fn goto_merge_returning_aliased_column() {
12278 assert_snapshot!(goto(
12279 "
12280create table t(a int, b int);
12281with u(x, y) as (
12282 select 1, 2
12283),
12284merged as (
12285 merge into t
12286 using u
12287 on t.a = u.x
12288 when matched then
12289 do nothing
12290 when not matched then
12291 do nothing
12292 returning a as x, b as y
12293)
12294select x$0 from merged;
12295",
12296 ), @r"
12297 ╭▸
12298 14 │ returning a as x, b as y
12299 │ ─ 2. destination
12300 15 │ )
12301 16 │ select x from merged;
12302 ╰╴ ─ 1. source
12303 ");
12304 }
12305
12306 #[test]
12307 fn goto_cte_update_returning_column() {
12308 assert_snapshot!(goto("
12309create table t(a int, b int);
12310with updated(c) as (
12311 update t set a = 10
12312 returning a, b
12313)
12314select c, b$0 from updated;"
12315 ), @r"
12316 ╭▸
12317 5 │ returning a, b
12318 │ ─ 2. destination
12319 6 │ )
12320 7 │ select c, b from updated;
12321 ╰╴ ─ 1. source
12322 ");
12323 }
12324
12325 #[test]
12326 fn goto_update_returning_column_to_table_def() {
12327 assert_snapshot!(goto("
12328create table t(a int, b int);
12329with updated(c) as (
12330 update t set a = 10
12331 returning a, b$0
12332)
12333select c, b from updated;"
12334 ), @r"
12335 ╭▸
12336 2 │ create table t(a int, b int);
12337 │ ─ 2. destination
12338 ‡
12339 5 │ returning a, b
12340 ╰╴ ─ 1. source
12341 ");
12342 }
12343
12344 #[test]
12345 fn goto_insert_returning_column_to_table_def() {
12346 assert_snapshot!(goto("
12347create table t(a int, b int);
12348with inserted as (
12349 insert into t values (1, 2)
12350 returning a$0, b
12351)
12352select a, b from inserted;"
12353 ), @r"
12354 ╭▸
12355 2 │ create table t(a int, b int);
12356 │ ─ 2. destination
12357 ‡
12358 5 │ returning a, b
12359 ╰╴ ─ 1. source
12360 ");
12361 }
12362
12363 #[test]
12364 fn goto_delete_returning_column_to_table_def() {
12365 assert_snapshot!(goto("
12366create table t(a int, b int);
12367with deleted as (
12368 delete from t
12369 returning a, b$0
12370)
12371select a, b from deleted;"
12372 ), @r"
12373 ╭▸
12374 2 │ create table t(a int, b int);
12375 │ ─ 2. destination
12376 ‡
12377 5 │ returning a, b
12378 ╰╴ ─ 1. source
12379 ");
12380 }
12381
12382 #[test]
12383 fn goto_update_returning_qualified_star_table() {
12384 assert_snapshot!(goto("
12385create table t(a int, b int);
12386update t set a = 10
12387returning t$0.*;"
12388 ), @r"
12389 ╭▸
12390 2 │ create table t(a int, b int);
12391 │ ─ 2. destination
12392 3 │ update t set a = 10
12393 4 │ returning t.*;
12394 ╰╴ ─ 1. source
12395 ");
12396 }
12397
12398 #[test]
12399 fn goto_insert_returning_qualified_star_table() {
12400 assert_snapshot!(goto("
12401create table t(a int, b int);
12402insert into t values (1, 2)
12403returning t$0.*;"
12404 ), @r"
12405 ╭▸
12406 2 │ create table t(a int, b int);
12407 │ ─ 2. destination
12408 3 │ insert into t values (1, 2)
12409 4 │ returning t.*;
12410 ╰╴ ─ 1. source
12411 ");
12412 }
12413
12414 #[test]
12415 fn goto_delete_returning_qualified_star_table() {
12416 assert_snapshot!(goto("
12417create table t(a int, b int);
12418delete from t
12419returning t$0.*;"
12420 ), @r"
12421 ╭▸
12422 2 │ create table t(a int, b int);
12423 │ ─ 2. destination
12424 3 │ delete from t
12425 4 │ returning t.*;
12426 ╰╴ ─ 1. source
12427 ");
12428 }
12429
12430 #[test]
12431 fn goto_update_alias_in_set_clause() {
12432 assert_snapshot!(goto("
12433create table t(a int, b int);
12434update t as f set f$0.a = 10;"
12435 ), @r"
12436 ╭▸
12437 3 │ update t as f set f.a = 10;
12438 │ ┬ ─ 1. source
12439 │ │
12440 ╰╴ 2. destination
12441 ");
12442 }
12443
12444 #[test]
12445 fn goto_update_alias_in_where_clause() {
12446 assert_snapshot!(goto("
12447create table t(a int, b int);
12448update t as f set a = 10 where f$0.b = 5;"
12449 ), @r"
12450 ╭▸
12451 3 │ update t as f set a = 10 where f.b = 5;
12452 ╰╴ ─ 2. destination ─ 1. source
12453 ");
12454 }
12455
12456 #[test]
12457 fn goto_update_alias_in_from_clause() {
12458 assert_snapshot!(goto("
12459create table t(a int, b int);
12460create table u(c int);
12461update t as f set a = 10 from u where f$0.b = u.c;"
12462 ), @r"
12463 ╭▸
12464 4 │ update t as f set a = 10 from u where f.b = u.c;
12465 ╰╴ ─ 2. destination ─ 1. source
12466 ");
12467 }
12468
12469 #[test]
12470 fn goto_insert_alias_in_on_conflict() {
12471 assert_snapshot!(goto("
12472create table t(a int primary key, b int);
12473insert into t as f values (1, 2) on conflict (f$0.a) do nothing;"
12474 ), @r"
12475 ╭▸
12476 3 │ insert into t as f values (1, 2) on conflict (f.a) do nothing;
12477 ╰╴ ─ 2. destination ─ 1. source
12478 ");
12479 }
12480
12481 #[test]
12482 fn goto_insert_alias_in_returning() {
12483 assert_snapshot!(goto("
12484create table t(a int, b int);
12485insert into t as f values (1, 2) returning f$0.a;"
12486 ), @r"
12487 ╭▸
12488 3 │ insert into t as f values (1, 2) returning f.a;
12489 ╰╴ ─ 2. destination ─ 1. source
12490 ");
12491 }
12492
12493 #[test]
12494 fn goto_insert_alias_returning_column() {
12495 assert_snapshot!(goto("
12496create table t(a int, b int);
12497insert into t as f values (1, 2) returning f.a$0;"
12498 ), @r"
12499 ╭▸
12500 2 │ create table t(a int, b int);
12501 │ ─ 2. destination
12502 3 │ insert into t as f values (1, 2) returning f.a;
12503 ╰╴ ─ 1. source
12504 ");
12505 }
12506
12507 #[test]
12508 fn goto_insert_on_conflict_target_column() {
12509 assert_snapshot!(goto("
12510create table t(c text);
12511insert into t values ('c') on conflict (c$0) do nothing;"
12512 ), @r"
12513 ╭▸
12514 2 │ create table t(c text);
12515 │ ─ 2. destination
12516 3 │ insert into t values ('c') on conflict (c) do nothing;
12517 ╰╴ ─ 1. source
12518 ");
12519 }
12520
12521 #[test]
12522 fn goto_insert_on_conflict_set_column() {
12523 assert_snapshot!(goto("
12524create table t(c text, d text);
12525insert into t values ('c', 'd') on conflict (c) do update set c$0 = excluded.c;"
12526 ), @r"
12527 ╭▸
12528 2 │ create table t(c text, d text);
12529 │ ─ 2. destination
12530 3 │ insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c;
12531 ╰╴ ─ 1. source
12532 ");
12533 }
12534
12535 #[test]
12536 fn goto_insert_on_conflict_excluded_column() {
12537 assert_snapshot!(goto("
12538create table t(c text, d text);
12539insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c$0;"
12540 ), @r"
12541 ╭▸
12542 2 │ create table t(c text, d text);
12543 │ ─ 2. destination
12544 3 │ insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c;
12545 ╰╴ ─ 1. source
12546 ");
12547 }
12548
12549 #[test]
12550 fn goto_insert_on_conflict_qualified_function() {
12551 assert_snapshot!(goto("
12552create function foo.lower(text) returns text
12553 language internal;
12554create table t(c text);
12555insert into t values ('c')
12556 on conflict (foo.lower$0(c))
12557 do nothing;"
12558 ), @r"
12559 ╭▸
12560 2 │ create function foo.lower(text) returns text
12561 │ ───── 2. destination
12562 ‡
12563 6 │ on conflict (foo.lower(c))
12564 ╰╴ ─ 1. source
12565 ");
12566 }
12567
12568 #[test]
12569 fn goto_delete_from_alias() {
12570 assert_snapshot!(goto("
12571create table t(a int, b int);
12572delete from t as f where f$0.a = 10;"
12573 ), @r"
12574 ╭▸
12575 3 │ delete from t as f where f.a = 10;
12576 │ ┬ ─ 1. source
12577 │ │
12578 ╰╴ 2. destination
12579 ");
12580 }
12581
12582 #[test]
12583 fn goto_delete_from_alias_column() {
12584 assert_snapshot!(goto("
12585create table t(a int, b int);
12586delete from t as f where f.a$0 = 10;"
12587 ), @r"
12588 ╭▸
12589 2 │ create table t(a int, b int);
12590 │ ─ 2. destination
12591 3 │ delete from t as f where f.a = 10;
12592 ╰╴ ─ 1. source
12593 ");
12594 }
12595
12596 #[test]
12597 fn goto_delete_from_alias_returning() {
12598 assert_snapshot!(goto("
12599create table t(a int, b int);
12600delete from t as f returning f$0.a"
12601 ), @r"
12602 ╭▸
12603 3 │ delete from t as f returning f.a
12604 │ ┬ ─ 1. source
12605 │ │
12606 ╰╴ 2. destination
12607 ");
12608
12609 assert_snapshot!(goto("
12610create table t(a int, b int);
12611delete from t as f returning f.a$0"
12612 ), @r"
12613 ╭▸
12614 2 │ create table t(a int, b int);
12615 │ ─ 2. destination
12616 3 │ delete from t as f returning f.a
12617 ╰╴ ─ 1. source
12618 ");
12619 }
12620
12621 #[test]
12622 fn goto_merge_alias_on_table() {
12623 assert_snapshot!(goto("
12624create table t(a int, b int);
12625create table u(a int, b int);
12626merge into t as f
12627 using u on u.a = f$0.a
12628 when matched then do nothing;
12629"
12630
12631 ), @r"
12632 ╭▸
12633 4 │ merge into t as f
12634 │ ─ 2. destination
12635 5 │ using u on u.a = f.a
12636 ╰╴ ─ 1. source
12637 ");
12638 }
12639
12640 #[test]
12641 fn goto_merge_alias_on_column() {
12642 assert_snapshot!(goto("
12643create table t(a int, b int);
12644create table u(a int, b int);
12645merge into t as f
12646 using u on u.a = f.a$0
12647 when matched then do nothing;
12648"
12649
12650 ), @r"
12651 ╭▸
12652 2 │ create table t(a int, b int);
12653 │ ─ 2. destination
12654 ‡
12655 5 │ using u on u.a = f.a
12656 ╰╴ ─ 1. source
12657 ");
12658 }
12659
12660 #[test]
12661 fn goto_merge_alias_returning() {
12662 assert_snapshot!(goto("
12663create table t(a int, b int);
12664create table u(a int, b int);
12665merge into t as f
12666 using u on u.a = f.a
12667 when matched then do nothing
12668 returning f$0.a;
12669"
12670
12671 ), @r"
12672 ╭▸
12673 4 │ merge into t as f
12674 │ ─ 2. destination
12675 ‡
12676 7 │ returning f.a;
12677 ╰╴ ─ 1. source
12678 ");
12679
12680 assert_snapshot!(goto("
12681create table t(a int, b int);
12682create table u(a int, b int);
12683merge into t as f
12684 using u on u.a = f.a
12685 when matched then do nothing
12686 returning f.a$0;
12687"
12688 ), @r"
12689 ╭▸
12690 2 │ create table t(a int, b int);
12691 │ ─ 2. destination
12692 ‡
12693 7 │ returning f.a;
12694 ╰╴ ─ 1. source
12695 ");
12696 }
12697
12698 #[test]
12699 fn goto_merge_using_table_in_when_clause() {
12700 assert_snapshot!(goto("
12701create table t(a int, b int);
12702create table u(a int, b int);
12703merge into t
12704 using u on true
12705 when matched and u$0.a = t.a
12706 then do nothing;
12707"
12708 ), @r"
12709 ╭▸
12710 3 │ create table u(a int, b int);
12711 │ ─ 2. destination
12712 ‡
12713 6 │ when matched and u.a = t.a
12714 ╰╴ ─ 1. source
12715 ");
12716 }
12717
12718 #[test]
12719 fn goto_merge_using_table_column_in_when_clause() {
12720 assert_snapshot!(goto("
12721create table t(a int, b int);
12722create table u(a int, b int);
12723merge into t
12724 using u on true
12725 when matched and u.a$0 = t.a
12726 then do nothing;
12727"
12728 ), @r"
12729 ╭▸
12730 3 │ create table u(a int, b int);
12731 │ ─ 2. destination
12732 ‡
12733 6 │ when matched and u.a = t.a
12734 ╰╴ ─ 1. source
12735 ");
12736 }
12737
12738 #[test]
12739 fn goto_merge_unqualified_column_target_table() {
12740 assert_snapshot!(goto("
12741create table x(a int, b int);
12742create table y(c int, d int);
12743merge into x
12744 using y
12745 on true
12746 when matched and a$0 = c
12747 then do nothing;
12748"
12749 ), @r"
12750 ╭▸
12751 2 │ create table x(a int, b int);
12752 │ ─ 2. destination
12753 ‡
12754 7 │ when matched and a = c
12755 ╰╴ ─ 1. source
12756 ");
12757 }
12758
12759 #[test]
12760 fn goto_merge_unqualified_column_source_table() {
12761 assert_snapshot!(goto("
12762create table x(a int, b int);
12763create table y(c int, d int);
12764merge into x
12765 using y
12766 on true
12767 when matched and a = c$0
12768 then do nothing;
12769"
12770 ), @r"
12771 ╭▸
12772 3 │ create table y(c int, d int);
12773 │ ─ 2. destination
12774 ‡
12775 7 │ when matched and a = c
12776 ╰╴ ─ 1. source
12777 ");
12778 }
12779
12780 #[test]
12781 fn goto_merge_update_set_target_column() {
12782 assert_snapshot!(goto("
12783create table target(id int, val int);
12784create table source(id int, val int);
12785merge into target using source on target.id = source.id
12786 when matched then update set val$0 = source.val;
12787"
12788 ), @"
12789 ╭▸
12790 2 │ create table target(id int, val int);
12791 │ ─── 2. destination
12792 ‡
12793 5 │ when matched then update set val = source.val;
12794 ╰╴ ─ 1. source
12795 ");
12796 }
12797
12798 #[test]
12799 fn goto_merge_update_set_source_expr_column() {
12800 assert_snapshot!(goto("
12801create table target(id int, val int);
12802create table source(id int, val int);
12803merge into target using source on target.id = source.id
12804 when matched then update set val = source.val$0;
12805"
12806 ), @"
12807 ╭▸
12808 3 │ create table source(id int, val int);
12809 │ ─── 2. destination
12810 4 │ merge into target using source on target.id = source.id
12811 5 │ when matched then update set val = source.val;
12812 ╰╴ ─ 1. source
12813 ");
12814 }
12815
12816 #[test]
12817 fn goto_merge_insert_column_list_target_column() {
12818 assert_snapshot!(goto("
12819create table target(id int, val int);
12820create table source(id int, val int);
12821merge into target using source on target.id = source.id
12822 when not matched then insert (val$0) values(source.val);
12823"
12824 ), @"
12825 ╭▸
12826 2 │ create table target(id int, val int);
12827 │ ─── 2. destination
12828 ‡
12829 5 │ when not matched then insert (val) values(source.val);
12830 ╰╴ ─ 1. source
12831 ");
12832 }
12833
12834 #[test]
12835 fn goto_merge_into_table() {
12836 assert_snapshot!(goto("
12837create table x(a int, b int);
12838create table y(c int, d int);
12839merge into x$0
12840 using y
12841 on true
12842 when matched and a = c
12843 then do nothing;
12844"
12845 ), @r"
12846 ╭▸
12847 2 │ create table x(a int, b int);
12848 │ ─ 2. destination
12849 3 │ create table y(c int, d int);
12850 4 │ merge into x
12851 ╰╴ ─ 1. source
12852 ");
12853 }
12854
12855 #[test]
12856 fn goto_merge_using_clause_table() {
12857 assert_snapshot!(goto("
12858create table x(a int, b int);
12859create table y(c int, d int);
12860merge into x
12861 using y$0
12862 on true
12863 when matched and a = c
12864 then do nothing;
12865"
12866 ), @r"
12867 ╭▸
12868 3 │ create table y(c int, d int);
12869 │ ─ 2. destination
12870 4 │ merge into x
12871 5 │ using y
12872 ╰╴ ─ 1. source
12873 ");
12874 }
12875
12876 #[test]
12877 fn goto_merge_using_clause_alias() {
12878 assert_snapshot!(goto("
12879create table x(a int, b int);
12880create table y(c int, d int);
12881merge into x as g
12882 using y as k
12883 on true
12884 when matched and a = k.c$0
12885 then do nothing;
12886"
12887 ), @r"
12888 ╭▸
12889 3 │ create table y(c int, d int);
12890 │ ─ 2. destination
12891 ‡
12892 7 │ when matched and a = k.c
12893 ╰╴ ─ 1. source
12894 ");
12895 }
12896
12897 #[test]
12898 fn goto_merge_on_clause_unqualified_source_column() {
12899 assert_snapshot!(goto("
12900create table x(a int, b int);
12901create table y(c int, d int);
12902merge into x as g
12903 using y as k
12904 on g.a = c$0 and a = c
12905 when matched and g.a = k.c
12906 then do nothing;
12907"
12908 ), @r"
12909 ╭▸
12910 3 │ create table y(c int, d int);
12911 │ ─ 2. destination
12912 ‡
12913 6 │ on g.a = c and a = c
12914 ╰╴ ─ 1. source
12915 ");
12916 }
12917
12918 #[test]
12919 fn goto_merge_returning_old_table() {
12920 assert_snapshot!(goto("
12921create table x(a int, b int);
12922create table y(c int, d int);
12923merge into x as g
12924 using y as k
12925 on g.a = c and a = k.c
12926 when matched and g.a = k.c
12927 then do nothing
12928 returning old$0.a, new.a;
12929"
12930 ), @r"
12931 ╭▸
12932 2 │ create table x(a int, b int);
12933 │ ─ 2. destination
12934 ‡
12935 9 │ returning old.a, new.a;
12936 ╰╴ ─ 1. source
12937 ");
12938 }
12939
12940 #[test]
12941 fn goto_merge_returning_old_column() {
12942 assert_snapshot!(goto("
12943create table x(a int, b int);
12944create table y(c int, d int);
12945merge into x as g
12946 using y as k
12947 on g.a = c and a = k.c
12948 when matched and g.a = k.c
12949 then do nothing
12950 returning old.a$0, new.a;
12951"
12952 ), @r"
12953 ╭▸
12954 2 │ create table x(a int, b int);
12955 │ ─ 2. destination
12956 ‡
12957 9 │ returning old.a, new.a;
12958 ╰╴ ─ 1. source
12959 ");
12960 }
12961
12962 #[test]
12963 fn goto_merge_returning_new_table() {
12964 assert_snapshot!(goto("
12965create table x(a int, b int);
12966create table y(c int, d int);
12967merge into x as g
12968 using y as k
12969 on g.a = c and a = k.c
12970 when matched and g.a = k.c
12971 then do nothing
12972 returning old.a, new$0.a;
12973"
12974 ), @r"
12975 ╭▸
12976 2 │ create table x(a int, b int);
12977 │ ─ 2. destination
12978 ‡
12979 9 │ returning old.a, new.a;
12980 ╰╴ ─ 1. source
12981 ");
12982 }
12983
12984 #[test]
12985 fn goto_merge_returning_new_column() {
12986 assert_snapshot!(goto("
12987create table x(a int, b int);
12988create table y(c int, d int);
12989merge into x as g
12990 using y as k
12991 on g.a = c and a = k.c
12992 when matched and g.a = k.c
12993 then do nothing
12994 returning old.a, new.a$0;
12995"
12996 ), @r"
12997 ╭▸
12998 2 │ create table x(a int, b int);
12999 │ ─ 2. destination
13000 ‡
13001 9 │ returning old.a, new.a;
13002 ╰╴ ─ 1. source
13003 ");
13004 }
13005
13006 #[test]
13007 fn goto_merge_with_tables_named_old_new_old_table() {
13008 assert_snapshot!(goto("
13009create table old(a int, b int);
13010create table new(c int, d int);
13011merge into old
13012 using new
13013 on true
13014 when matched
13015 then do nothing
13016 returning old$0.a, new.d;
13017"
13018 ), @r"
13019 ╭▸
13020 2 │ create table old(a int, b int);
13021 │ ─── 2. destination
13022 ‡
13023 9 │ returning old.a, new.d;
13024 ╰╴ ─ 1. source
13025 ");
13026 }
13027
13028 #[test]
13029 fn goto_merge_with_tables_named_old_new_old_column() {
13030 assert_snapshot!(goto("
13031create table old(a int, b int);
13032create table new(c int, d int);
13033merge into old
13034 using new
13035 on true
13036 when matched
13037 then do nothing
13038 returning old.a$0, new.d;
13039"
13040 ), @r"
13041 ╭▸
13042 2 │ create table old(a int, b int);
13043 │ ─ 2. destination
13044 ‡
13045 9 │ returning old.a, new.d;
13046 ╰╴ ─ 1. source
13047 ");
13048 }
13049
13050 #[test]
13051 fn goto_merge_with_tables_named_old_new_new_table() {
13052 assert_snapshot!(goto("
13053create table old(a int, b int);
13054create table new(c int, d int);
13055merge into old
13056 using new
13057 on true
13058 when matched
13059 then do nothing
13060 returning old.a, new$0.d;
13061"
13062 ), @r"
13063 ╭▸
13064 3 │ create table new(c int, d int);
13065 │ ─── 2. destination
13066 ‡
13067 9 │ returning old.a, new.d;
13068 ╰╴ ─ 1. source
13069 ");
13070 }
13071
13072 #[test]
13073 fn goto_merge_with_tables_named_old_new_new_column() {
13074 assert_snapshot!(goto("
13075create table old(a int, b int);
13076create table new(c int, d int);
13077merge into old
13078 using new
13079 on true
13080 when matched
13081 then do nothing
13082 returning old.a, new.d$0;
13083"
13084 ), @r"
13085 ╭▸
13086 3 │ create table new(c int, d int);
13087 │ ─ 2. destination
13088 ‡
13089 9 │ returning old.a, new.d;
13090 ╰╴ ─ 1. source
13091 ");
13092 }
13093
13094 #[test]
13095 fn goto_merge_returning_with_aliases_before_table() {
13096 assert_snapshot!(goto("
13097create table x(a int, b int);
13098create table y(c int, d int);
13099merge into x
13100 using y on true
13101 when matched then do nothing
13102 returning
13103 with (old as before, new as after)
13104 before$0.a, after.a;
13105"
13106 ), @r"
13107 ╭▸
13108 8 │ with (old as before, new as after)
13109 │ ────── 2. destination
13110 9 │ before.a, after.a;
13111 ╰╴ ─ 1. source
13112 ");
13113 }
13114
13115 #[test]
13116 fn goto_merge_returning_with_aliases_before_column() {
13117 assert_snapshot!(goto("
13118create table x(a int, b int);
13119create table y(c int, d int);
13120merge into x
13121 using y on true
13122 when matched then do nothing
13123 returning
13124 with (old as before, new as after)
13125 before.a$0, after.a;
13126"
13127 ), @r"
13128 ╭▸
13129 2 │ create table x(a int, b int);
13130 │ ─ 2. destination
13131 ‡
13132 9 │ before.a, after.a;
13133 ╰╴ ─ 1. source
13134 ");
13135 }
13136
13137 #[test]
13138 fn goto_merge_returning_with_aliases_after_table() {
13139 assert_snapshot!(goto("
13140create table x(a int, b int);
13141create table y(c int, d int);
13142merge into x
13143 using y on true
13144 when matched then do nothing
13145 returning
13146 with (old as before, new as after)
13147 before.a, after$0.a;
13148"
13149 ), @r"
13150 ╭▸
13151 8 │ with (old as before, new as after)
13152 │ ───── 2. destination
13153 9 │ before.a, after.a;
13154 ╰╴ ─ 1. source
13155 ");
13156 }
13157
13158 #[test]
13159 fn goto_merge_returning_with_aliases_after_column() {
13160 assert_snapshot!(goto("
13161create table x(a int, b int);
13162create table y(c int, d int);
13163merge into x
13164 using y on true
13165 when matched then do nothing
13166 returning
13167 with (old as before, new as after)
13168 before.a, after.a$0;
13169"
13170 ), @r"
13171 ╭▸
13172 2 │ create table x(a int, b int);
13173 │ ─ 2. destination
13174 ‡
13175 9 │ before.a, after.a;
13176 ╰╴ ─ 1. source
13177 ");
13178 }
13179
13180 #[test]
13181 fn goto_merge_when_not_matched_insert_values_qualified_column() {
13182 assert_snapshot!(goto("
13183create table inventory (
13184 product_id int,
13185 quantity int,
13186 updated_at timestamp
13187);
13188create table orders (
13189 id int,
13190 product_id int,
13191 qty int
13192);
13193merge into inventory as t
13194using orders as o
13195 on t.product_id = o.product_id
13196when matched then
13197 do nothing
13198when not matched then
13199 insert values (o$0.product_id, o.qty, now());
13200"
13201 ), @r"
13202 ╭▸
13203 13 │ using orders as o
13204 │ ─ 2. destination
13205 ‡
13206 18 │ insert values (o.product_id, o.qty, now());
13207 ╰╴ ─ 1. source
13208 ");
13209 }
13210
13211 #[test]
13212 fn goto_merge_when_not_matched_insert_values_qualified_column_field() {
13213 assert_snapshot!(goto("
13214create table inventory (
13215 product_id int,
13216 quantity int,
13217 updated_at timestamp
13218);
13219create table orders (
13220 id int,
13221 product_id int,
13222 qty int
13223);
13224merge into inventory as t
13225using orders as o
13226 on t.product_id = o.product_id
13227when matched then
13228 do nothing
13229when not matched then
13230 insert values (o.product_id$0, o.qty, now());
13231"
13232 ), @r"
13233 ╭▸
13234 9 │ product_id int,
13235 │ ────────── 2. destination
13236 ‡
13237 18 │ insert values (o.product_id, o.qty, now());
13238 ╰╴ ─ 1. source
13239 ");
13240 }
13241
13242 #[test]
13243 fn goto_merge_when_not_matched_insert_values_unqualified_column() {
13244 assert_snapshot!(goto("
13245create table inventory (
13246 product_id int,
13247 quantity int
13248);
13249create table orders (
13250 product_id int,
13251 qty int
13252);
13253merge into inventory as t
13254using orders as o
13255 on t.product_id = o.product_id
13256when not matched then
13257 insert values (product_id$0, qty);
13258"
13259 ), @r"
13260 ╭▸
13261 7 │ product_id int,
13262 │ ────────── 2. destination
13263 ‡
13264 14 │ insert values (product_id, qty);
13265 ╰╴ ─ 1. source
13266 ");
13267 }
13268
13269 #[test]
13270 fn goto_insert_returning_old_table() {
13271 assert_snapshot!(goto("
13272create table t(a int, b int);
13273insert into t values (1, 2), (3, 4)
13274returning old$0.a, new.b;
13275"
13276 ), @r"
13277 ╭▸
13278 2 │ create table t(a int, b int);
13279 │ ─ 2. destination
13280 3 │ insert into t values (1, 2), (3, 4)
13281 4 │ returning old.a, new.b;
13282 ╰╴ ─ 1. source
13283 ");
13284 }
13285
13286 #[test]
13287 fn goto_insert_returning_old_column() {
13288 assert_snapshot!(goto("
13289create table t(a int, b int);
13290insert into t values (1, 2), (3, 4)
13291returning old.a$0, new.b;
13292"
13293 ), @r"
13294 ╭▸
13295 2 │ create table t(a int, b int);
13296 │ ─ 2. destination
13297 3 │ insert into t values (1, 2), (3, 4)
13298 4 │ returning old.a, new.b;
13299 ╰╴ ─ 1. source
13300 ");
13301 }
13302
13303 #[test]
13304 fn goto_insert_returning_new_table() {
13305 assert_snapshot!(goto("
13306create table t(a int, b int);
13307insert into t values (1, 2), (3, 4)
13308returning old.a, new$0.b;
13309"
13310 ), @r"
13311 ╭▸
13312 2 │ create table t(a int, b int);
13313 │ ─ 2. destination
13314 3 │ insert into t values (1, 2), (3, 4)
13315 4 │ returning old.a, new.b;
13316 ╰╴ ─ 1. source
13317 ");
13318 }
13319
13320 #[test]
13321 fn goto_insert_returning_new_column() {
13322 assert_snapshot!(goto("
13323create table t(a int, b int);
13324insert into t values (1, 2), (3, 4)
13325returning old.a, new.b$0;
13326"
13327 ), @r"
13328 ╭▸
13329 2 │ create table t(a int, b int);
13330 │ ─ 2. destination
13331 3 │ insert into t values (1, 2), (3, 4)
13332 4 │ returning old.a, new.b;
13333 ╰╴ ─ 1. source
13334 ");
13335 }
13336
13337 #[test]
13338 fn goto_update_returning_old_table() {
13339 assert_snapshot!(goto("
13340create table t(a int, b int);
13341update t set a = 42
13342returning old$0.a, new.b;
13343"
13344 ), @r"
13345 ╭▸
13346 2 │ create table t(a int, b int);
13347 │ ─ 2. destination
13348 3 │ update t set a = 42
13349 4 │ returning old.a, new.b;
13350 ╰╴ ─ 1. source
13351 ");
13352 }
13353
13354 #[test]
13355 fn goto_update_returning_old_column() {
13356 assert_snapshot!(goto("
13357create table t(a int, b int);
13358update t set a = 42
13359returning old.a$0, new.b;
13360"
13361 ), @r"
13362 ╭▸
13363 2 │ create table t(a int, b int);
13364 │ ─ 2. destination
13365 3 │ update t set a = 42
13366 4 │ returning old.a, new.b;
13367 ╰╴ ─ 1. source
13368 ");
13369 }
13370
13371 #[test]
13372 fn goto_update_returning_new_table() {
13373 assert_snapshot!(goto("
13374create table t(a int, b int);
13375update t set a = 42
13376returning old.a, new$0.b;
13377"
13378 ), @r"
13379 ╭▸
13380 2 │ create table t(a int, b int);
13381 │ ─ 2. destination
13382 3 │ update t set a = 42
13383 4 │ returning old.a, new.b;
13384 ╰╴ ─ 1. source
13385 ");
13386 }
13387
13388 #[test]
13389 fn goto_update_returning_new_column() {
13390 assert_snapshot!(goto("
13391create table t(a int, b int);
13392update t set a = 42
13393returning old.a, new.b$0;
13394"
13395 ), @r"
13396 ╭▸
13397 2 │ create table t(a int, b int);
13398 │ ─ 2. destination
13399 3 │ update t set a = 42
13400 4 │ returning old.a, new.b;
13401 ╰╴ ─ 1. source
13402 ");
13403 }
13404
13405 #[test]
13406 fn goto_delete_returning_old_table() {
13407 assert_snapshot!(goto("
13408create table t(a int, b int);
13409delete from t
13410returning old$0.a, new.b;
13411"
13412 ), @r"
13413 ╭▸
13414 2 │ create table t(a int, b int);
13415 │ ─ 2. destination
13416 3 │ delete from t
13417 4 │ returning old.a, new.b;
13418 ╰╴ ─ 1. source
13419 ");
13420 }
13421
13422 #[test]
13423 fn goto_delete_returning_old_column() {
13424 assert_snapshot!(goto("
13425create table t(a int, b int);
13426delete from t
13427returning old.a$0, new.b;
13428"
13429 ), @r"
13430 ╭▸
13431 2 │ create table t(a int, b int);
13432 │ ─ 2. destination
13433 3 │ delete from t
13434 4 │ returning old.a, new.b;
13435 ╰╴ ─ 1. source
13436 ");
13437 }
13438
13439 #[test]
13440 fn goto_delete_returning_new_table() {
13441 assert_snapshot!(goto("
13442create table t(a int, b int);
13443delete from t
13444returning old.a, new$0.b;
13445"
13446 ), @r"
13447 ╭▸
13448 2 │ create table t(a int, b int);
13449 │ ─ 2. destination
13450 3 │ delete from t
13451 4 │ returning old.a, new.b;
13452 ╰╴ ─ 1. source
13453 ");
13454 }
13455
13456 #[test]
13457 fn goto_delete_returning_new_column() {
13458 assert_snapshot!(goto("
13459create table t(a int, b int);
13460delete from t
13461returning old.a, new.b$0;
13462"
13463 ), @r"
13464 ╭▸
13465 2 │ create table t(a int, b int);
13466 │ ─ 2. destination
13467 3 │ delete from t
13468 4 │ returning old.a, new.b;
13469 ╰╴ ─ 1. source
13470 ");
13471 }
13472
13473 #[test]
13474 fn goto_insert_as_old_alias() {
13475 assert_snapshot!(goto("
13476create table t(a int, b int);
13477insert into t as old values (1, 2)
13478returning old$0.a, new.a;
13479"
13480 ), @r"
13481 ╭▸
13482 3 │ insert into t as old values (1, 2)
13483 │ ─── 2. destination
13484 4 │ returning old.a, new.a;
13485 ╰╴ ─ 1. source
13486 ");
13487 }
13488
13489 #[test]
13490 fn goto_delete_as_old_alias() {
13491 assert_snapshot!(goto("
13492create table t(a int, b int);
13493delete from t as old
13494returning old$0.a, new.a;
13495"
13496 ), @r"
13497 ╭▸
13498 3 │ delete from t as old
13499 │ ─── 2. destination
13500 4 │ returning old.a, new.a;
13501 ╰╴ ─ 1. source
13502 ");
13503 }
13504
13505 #[test]
13506 fn goto_update_as_old_alias() {
13507 assert_snapshot!(goto("
13508create table t(a int, b int);
13509update t as old set a = 42
13510returning old$0.a, new.a;
13511"
13512 ), @r"
13513 ╭▸
13514 3 │ update t as old set a = 42
13515 │ ─── 2. destination
13516 4 │ returning old.a, new.a;
13517 ╰╴ ─ 1. source
13518 ");
13519 }
13520
13521 #[test]
13522 fn goto_merge_returning_cte_column_unqualified() {
13523 assert_snapshot!(goto("
13524create table t(a int, b int);
13525with u(x, y) as (
13526 select 1, 2
13527)
13528merge into t
13529 using u on true
13530when matched then
13531 do nothing
13532when not matched then
13533 do nothing
13534returning x$0, u.y;
13535"
13536 ), @r"
13537 ╭▸
13538 3 │ with u(x, y) as (
13539 │ ─ 2. destination
13540 ‡
13541 12 │ returning x, u.y;
13542 ╰╴ ─ 1. source
13543 ");
13544 }
13545
13546 #[test]
13547 fn goto_merge_returning_cte_column_qualified_table() {
13548 assert_snapshot!(goto("
13549create table t(a int, b int);
13550with u(x, y) as (
13551 select 1, 2
13552)
13553merge into t
13554 using u on true
13555when matched then
13556 do nothing
13557when not matched then
13558 do nothing
13559returning x, u$0.y;
13560"
13561 ), @r"
13562 ╭▸
13563 3 │ with u(x, y) as (
13564 │ ─ 2. destination
13565 ‡
13566 12 │ returning x, u.y;
13567 ╰╴ ─ 1. source
13568 ");
13569 }
13570
13571 #[test]
13572 fn goto_merge_returning_cte_column_qualified_column() {
13573 assert_snapshot!(goto("
13574create table t(a int, b int);
13575with u(x, y) as (
13576 select 1, 2
13577)
13578merge into t
13579 using u on true
13580when matched then
13581 do nothing
13582when not matched then
13583 do nothing
13584returning x, u.y$0;
13585"
13586 ), @r"
13587 ╭▸
13588 3 │ with u(x, y) as (
13589 │ ─ 2. destination
13590 ‡
13591 12 │ returning x, u.y;
13592 ╰╴ ─ 1. source
13593 ");
13594 }
13595
13596 #[test]
13597 fn goto_overlay_with_cte_column() {
13598 assert_snapshot!(goto("
13599with t as (
13600 select '1' a, '2' b, 3 start
13601)
13602select overlay(a placing b$0 from start) from t;
13603 "), @r"
13604 ╭▸
13605 3 │ select '1' a, '2' b, 3 start
13606 │ ─ 2. destination
13607 4 │ )
13608 5 │ select overlay(a placing b from start) from t;
13609 ╰╴ ─ 1. source
13610 ");
13611 }
13612
13613 #[test]
13614 fn goto_overlay_with_cte_column_first_arg() {
13615 assert_snapshot!(goto("
13616with t as (
13617 select '1' a, '2' b, 3 start
13618)
13619select overlay(a$0 placing b from start) from t;
13620 "), @r"
13621 ╭▸
13622 3 │ select '1' a, '2' b, 3 start
13623 │ ─ 2. destination
13624 4 │ )
13625 5 │ select overlay(a placing b from start) from t;
13626 ╰╴ ─ 1. source
13627 ");
13628 }
13629
13630 #[test]
13631 fn goto_overlay_with_cte_column_from_arg() {
13632 assert_snapshot!(goto("
13633with t as (
13634 select '1' a, '2' b, 3 start
13635)
13636select overlay(a placing b from start$0) from t;
13637 "), @r"
13638 ╭▸
13639 3 │ select '1' a, '2' b, 3 start
13640 │ ───── 2. destination
13641 4 │ )
13642 5 │ select overlay(a placing b from start) from t;
13643 ╰╴ ─ 1. source
13644 ");
13645 }
13646
13647 #[test]
13648 fn goto_named_arg_to_param() {
13649 assert_snapshot!(goto("
13650create function foo(bar_param int) returns int as 'select 1' language sql;
13651select foo(bar_param$0 := 5);
13652"), @r"
13653 ╭▸
13654 2 │ create function foo(bar_param int) returns int as 'select 1' language sql;
13655 │ ───────── 2. destination
13656 3 │ select foo(bar_param := 5);
13657 ╰╴ ─ 1. source
13658 ");
13659 }
13660
13661 #[test]
13662 fn goto_named_arg_schema_qualified() {
13663 assert_snapshot!(goto("
13664create schema s;
13665create function s.foo(my_param int) returns int as 'select 1' language sql;
13666select s.foo(my_param$0 := 10);
13667"), @r"
13668 ╭▸
13669 3 │ create function s.foo(my_param int) returns int as 'select 1' language sql;
13670 │ ──────── 2. destination
13671 4 │ select s.foo(my_param := 10);
13672 ╰╴ ─ 1. source
13673 ");
13674 }
13675
13676 #[test]
13677 fn goto_named_arg_multiple_params() {
13678 assert_snapshot!(goto("
13679create function foo(a int, b int, c int) returns int as 'select 1' language sql;
13680select foo(b$0 := 2, a := 1);
13681"), @r"
13682 ╭▸
13683 2 │ create function foo(a int, b int, c int) returns int as 'select 1' language sql;
13684 │ ─ 2. destination
13685 3 │ select foo(b := 2, a := 1);
13686 ╰╴ ─ 1. source
13687 ");
13688 }
13689
13690 #[test]
13691 fn goto_named_arg_procedure() {
13692 assert_snapshot!(goto("
13693create procedure proc(param_x int) as 'select 1' language sql;
13694call proc(param_x$0 := 42);
13695"), @r"
13696 ╭▸
13697 2 │ create procedure proc(param_x int) as 'select 1' language sql;
13698 │ ─────── 2. destination
13699 3 │ call proc(param_x := 42);
13700 ╰╴ ─ 1. source
13701 ");
13702 }
13703
13704 #[test]
13705 fn goto_named_arg_not_found_unnamed_param() {
13706 goto_not_found(
13707 "
13708create function foo(int) returns int as 'select 1' language sql;
13709select foo(bar$0 := 5);
13710",
13711 );
13712 }
13713
13714 #[test]
13715 fn goto_named_arg_not_found_wrong_name() {
13716 goto_not_found(
13717 "
13718create function foo(correct_param int) returns int as 'select 1' language sql;
13719select foo(wrong_param$0 := 5);
13720",
13721 );
13722 }
13723
13724 #[test]
13725 fn goto_operator_function_ref() {
13726 assert_snapshot!(goto("
13727create function pg_catalog.tsvector_concat(tsvector, tsvector) returns tsvector language internal;
13728create operator pg_catalog.|| (leftarg = tsvector, rightarg = tsvector, function = pg_catalog.tsvector_concat$0);
13729"), @r"
13730 ╭▸
13731 2 │ create function pg_catalog.tsvector_concat(tsvector, tsvector) returns tsvector language internal;
13732 │ ─────────────── 2. destination
13733 3 │ create operator pg_catalog.|| (leftarg = tsvector, rightarg = tsvector, function = pg_catalog.tsvector_concat);
13734 ╰╴ ─ 1. source
13735 ");
13736 }
13737
13738 #[test]
13739 fn goto_operator_procedure_ref() {
13740 assert_snapshot!(goto("
13741create function f(int, int) returns int language internal;
13742create operator ||| (leftarg = int, rightarg = int, procedure = f$0);
13743"), @r"
13744 ╭▸
13745 2 │ create function f(int, int) returns int language internal;
13746 │ ─ 2. destination
13747 3 │ create operator ||| (leftarg = int, rightarg = int, procedure = f);
13748 ╰╴ ─ 1. source
13749 ");
13750 }
13751
13752 #[test]
13753 fn goto_operator_expr_usage() {
13754 assert_snapshot!(goto("
13755create operator === (leftarg = int, rightarg = int, function = int4eq);
13756select 1 ===$0 2;
13757"), @"
13758 ╭▸
13759 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13760 │ ─── 2. destination
13761 3 │ select 1 === 2;
13762 ╰╴ ─ 1. source
13763 ");
13764 }
13765
13766 #[test]
13767 fn goto_operator_explicit_operator_call() {
13768 assert_snapshot!(goto("
13769create operator === (leftarg = int, rightarg = int, function = int4eq);
13770select 1 operator(===$0) 2;
13771"), @"
13772 ╭▸
13773 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13774 │ ─── 2. destination
13775 3 │ select 1 operator(===) 2;
13776 ╰╴ ─ 1. source
13777 ");
13778 }
13779
13780 #[test]
13781 fn goto_drop_operator() {
13782 assert_snapshot!(goto("
13783create operator === (leftarg = int, rightarg = int, function = int4eq);
13784drop operator ===$0 (int, int);
13785"), @"
13786 ╭▸
13787 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13788 │ ─── 2. destination
13789 3 │ drop operator === (int, int);
13790 ╰╴ ─ 1. source
13791 ");
13792 }
13793
13794 #[test]
13795 fn goto_alter_operator_set_schema() {
13796 assert_snapshot!(goto("
13797create operator === (leftarg = int, rightarg = int, function = int4eq);
13798alter operator ===$0 (int, int) set schema public;
13799"), @"
13800 ╭▸
13801 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13802 │ ─── 2. destination
13803 3 │ alter operator === (int, int) set schema public;
13804 ╰╴ ─ 1. source
13805 ");
13806 }
13807
13808 #[test]
13809 fn goto_comment_on_operator() {
13810 assert_snapshot!(goto("
13811create operator === (leftarg = int, rightarg = int, function = int4eq);
13812comment on operator ===$0 (int, int) is 'x';
13813"), @"
13814 ╭▸
13815 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13816 │ ─── 2. destination
13817 3 │ comment on operator === (int, int) is 'x';
13818 ╰╴ ─ 1. source
13819 ");
13820 }
13821
13822 #[test]
13823 fn goto_operator_class_operator_member() {
13824 assert_snapshot!(goto("
13825create operator === (leftarg = int, rightarg = int, function = int4eq);
13826create operator class c for type int using btree as operator 1 ===$0;
13827"), @"
13828 ╭▸
13829 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13830 │ ─── 2. destination
13831 3 │ create operator class c for type int using btree as operator 1 ===;
13832 ╰╴ ─ 1. source
13833 ");
13834 }
13835
13836 #[test]
13837 fn goto_operator_family_operator_member() {
13838 assert_snapshot!(goto("
13839create operator === (leftarg = int, rightarg = int, function = int4eq);
13840create operator family fam using btree;
13841alter operator family fam using btree add operator 1 ===$0 (int, int);
13842"), @"
13843 ╭▸
13844 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13845 │ ─── 2. destination
13846 3 │ create operator family fam using btree;
13847 4 │ alter operator family fam using btree add operator 1 === (int, int);
13848 ╰╴ ─ 1. source
13849 ");
13850 }
13851
13852 #[test]
13853 fn goto_operator_exclude_constraint() {
13854 assert_snapshot!(goto("
13855create operator === (leftarg = int, rightarg = int, function = int4eq);
13856create table t (a int, exclude (a with ===$0));
13857"), @"
13858 ╭▸
13859 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13860 │ ─── 2. destination
13861 3 │ create table t (a int, exclude (a with ===));
13862 ╰╴ ─ 1. source
13863 ");
13864 }
13865
13866 #[test]
13867 fn goto_operator_commutator_option() {
13868 assert_snapshot!(goto("
13869create operator === (leftarg = int, rightarg = int, function = int4eq);
13870create operator ==== (leftarg = int, rightarg = int, function = int4eq, commutator = ===$0);
13871"), @"
13872 ╭▸
13873 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
13874 │ ─── 2. destination
13875 3 │ create operator ==== (leftarg = int, rightarg = int, function = int4eq, commutator = ===);
13876 ╰╴ ─ 1. source
13877 ");
13878 }
13879
13880 #[test]
13881 fn goto_operator_schema_qualified() {
13882 assert_snapshot!(goto("
13883create operator public.=== (leftarg = int, rightarg = int, function = int4eq);
13884drop operator public.===$0 (int, int);
13885"), @"
13886 ╭▸
13887 2 │ create operator public.=== (leftarg = int, rightarg = int, function = int4eq);
13888 │ ────────── 2. destination
13889 3 │ drop operator public.=== (int, int);
13890 ╰╴ ─ 1. source
13891 ");
13892 }
13893
13894 #[test]
13895 fn goto_create_cast_function_ref() {
13896 assert_snapshot!(goto("
13897create type a as enum ('x');
13898create type b as enum ('x');
13899create function a_to_b(a) returns b language sql as $$ select 'x'::b $$;
13900create cast (a as b) with function a_to_b$0(a);
13901"), @"
13902 ╭▸
13903 4 │ create function a_to_b(a) returns b language sql as $$ select 'x'::b $$;
13904 │ ────── 2. destination
13905 5 │ create cast (a as b) with function a_to_b(a);
13906 ╰╴ ─ 1. source
13907 ");
13908 }
13909
13910 #[test]
13911 fn goto_create_type_range_subtype_diff_function_ref() {
13912 assert_snapshot!(goto("
13913create function int_diff(int, int) returns float8 language sql as $$ select 0::float8 $$;
13914create type int_range as range (subtype = int, subtype_diff = int_diff$0);
13915"), @"
13916 ╭▸
13917 2 │ create function int_diff(int, int) returns float8 language sql as $$ select 0::float8 $$;
13918 │ ──────── 2. destination
13919 3 │ create type int_range as range (subtype = int, subtype_diff = int_diff);
13920 ╰╴ ─ 1. source
13921 ");
13922 }
13923
13924 #[test]
13925 fn goto_cte_window_partition_column_from_create_table_if_not_exists() {
13926 assert_snapshot!(goto("
13927create table t (
13928 id bigint primary key,
13929 group_col text not null,
13930 update_date date not null
13931);
13932
13933with row_number_added as (
13934 select
13935 *,
13936 row_number() over (
13937 partition by group_col$0
13938 order by update_date desc
13939 ) as rn
13940 from t
13941)
13942select * from row_number_added
13943"), @"
13944 ╭▸
13945 4 │ group_col text not null,
13946 │ ───────── 2. destination
13947 ‡
13948 12 │ partition by group_col
13949 ╰╴ ─ 1. source
13950 ");
13951 }
13952
13953 #[test]
13954 fn goto_cte_window_order_column_from_create_table_if_not_exists() {
13955 assert_snapshot!(goto("
13956create table t (
13957 id bigint primary key,
13958 group_col text not null,
13959 update_date date not null
13960);
13961
13962with row_number_added as (
13963 select
13964 *,
13965 row_number() over (
13966 partition by group_col
13967 order by update_date$0 desc
13968 ) as rn
13969 from t
13970)
13971select * from row_number_added
13972"), @"
13973 ╭▸
13974 5 │ update_date date not null
13975 │ ─────────── 2. destination
13976 ‡
13977 13 │ order by update_date desc
13978 ╰╴ ─ 1. source
13979 ");
13980 }
13981
13982 #[test]
13983 fn goto_cte_window_partition_function_call_from_create_table() {
13984 assert_snapshot!(goto("
13985create function length(text) returns int language internal;
13986
13987create table t (
13988 id bigint primary key,
13989 group_col text not null,
13990 update_date date not null
13991);
13992
13993with row_number_added as (
13994 select
13995 *,
13996 row_number() over (
13997 partition by length$0(group_col)
13998 order by update_date$0 desc
13999 ) as rn
14000 from t
14001)
14002select * from row_number_added
14003"), @"
14004 ╭▸
14005 2 │ create function length(text) returns int language internal;
14006 │ ────── 2. destination
14007 ‡
14008 14 │ partition by length(group_col)
14009 ╰╴ ─ 1. source
14010 ");
14011 }
14012
14013 #[test]
14014 fn goto_select_window_def_reuse() {
14015 assert_snapshot!(goto("
14016create table tbl (
14017 id bigint primary key,
14018 group_col text not null,
14019 update_date date not null,
14020 value text
14021);
14022select
14023 id,
14024 group_col,
14025 row_number() over w as rn,
14026 lag(value) over w$0 as prev_value
14027from tbl
14028window w as (
14029 partition by group_col
14030 order by update_date desc
14031);
14032"), @r"
14033 ╭▸
14034 12 │ lag(value) over w as prev_value
14035 │ ─ 1. source
14036 13 │ from tbl
14037 14 │ window w as (
14038 ╰╴ ─ 2. destination
14039 ");
14040 }
14041
14042 #[test]
14043 fn goto_window_base_name_in_inline_over() {
14044 assert_snapshot!(goto("
14045create table t(a int);
14046select row_number() over (w1$0 order by a)
14047from t
14048window w1 as (partition by a);
14049"), @"
14050 ╭▸
14051 3 │ select row_number() over (w1 order by a)
14052 │ ─ 1. source
14053 4 │ from t
14054 5 │ window w1 as (partition by a);
14055 ╰╴ ── 2. destination
14056 ");
14057 }
14058
14059 #[test]
14060 fn goto_window_base_name_in_window_def() {
14061 assert_snapshot!(goto("
14062create table t(a int);
14063select row_number() over w2
14064from t
14065window w1 as (partition by a), w2 as (w1$0 order by a);
14066"), @"
14067 ╭▸
14068 5 │ window w1 as (partition by a), w2 as (w1 order by a);
14069 ╰╴ ── 2. destination ─ 1. source
14070 ");
14071 }
14072
14073 #[test]
14074 fn goto_cast_float_with_small_arg() {
14075 assert_snapshot!(goto("
14076create type pg_catalog.float4;
14077select '1'::float$0(8);
14078"), @"
14079 ╭▸
14080 2 │ create type pg_catalog.float4;
14081 │ ────── 2. destination
14082 3 │ select '1'::float(8);
14083 ╰╴ ─ 1. source
14084 ");
14085 }
14086
14087 #[test]
14088 fn goto_cast_float_with_large_arg() {
14089 assert_snapshot!(goto("
14090create type pg_catalog.float8;
14091select '1'::float$0(25);
14092"), @"
14093 ╭▸
14094 2 │ create type pg_catalog.float8;
14095 │ ────── 2. destination
14096 3 │ select '1'::float(25);
14097 ╰╴ ─ 1. source
14098 ");
14099 }
14100
14101 #[test]
14102 fn goto_cast_dec_with_modifier() {
14103 assert_snapshot!(goto("
14104create type pg_catalog.numeric;
14105select '10'::dec$0(10, 2);
14106"), @"
14107 ╭▸
14108 2 │ create type pg_catalog.numeric;
14109 │ ─────── 2. destination
14110 3 │ select '10'::dec(10, 2);
14111 ╰╴ ─ 1. source
14112 ");
14113 }
14114
14115 #[test]
14116 fn goto_cast_dec() {
14117 assert_snapshot!(goto("
14118create type pg_catalog.numeric;
14119select '10'::dec$0;
14120"), @"
14121 ╭▸
14122 2 │ create type pg_catalog.numeric;
14123 │ ─────── 2. destination
14124 3 │ select '10'::dec;
14125 ╰╴ ─ 1. source
14126 ");
14127 }
14128
14129 #[test]
14130 fn goto_create_property_graph() {
14131 assert_snapshot!(goto("
14132create table buzz.boo(a int, b int);
14133create property graph foo.bar
14134 vertex tables (buzz.boo$0 key (a, b) no properties)
14135 edge tables (foo.bar key (x, y)
14136 source key (a, b) references k (t, y)
14137 destination key (q, t) references a (r, j)
14138 properties all columns);
14139"), @"
14140 ╭▸
14141 2 │ create table buzz.boo(a int, b int);
14142 │ ─── 2. destination
14143 3 │ create property graph foo.bar
14144 4 │ vertex tables (buzz.boo key (a, b) no properties)
14145 ╰╴ ─ 1. source
14146 ");
14147
14148 assert_snapshot!(goto("
14149create table foo.bar(x int, y int);
14150create property graph g
14151 vertex tables (boo key (a, b) no properties)
14152 edge tables (foo.bar$0 key (x, y)
14153 source key (a, b) references k (t, y)
14154 destination key (q, t) references a (r, j)
14155 properties all columns);
14156"), @"
14157 ╭▸
14158 2 │ create table foo.bar(x int, y int);
14159 │ ─── 2. destination
14160 ‡
14161 5 │ edge tables (foo.bar key (x, y)
14162 ╰╴ ─ 1. source
14163 ");
14164 }
14165
14166 #[test]
14167 fn goto_create_property_graph_sources_table() {
14168 assert_snapshot!(goto("
14169create table v1 (
14170 id int8 primary key,
14171 name text
14172);
14173
14174create table v2 (
14175 id int8 primary key,
14176 name text
14177);
14178
14179create table v3 (
14180 id int8 primary key,
14181 name text
14182);
14183
14184create table e1 (
14185 id int8 primary key,
14186 source_id int8 references v1,
14187 destination_id int8 references v2
14188);
14189
14190create table e2 (
14191 id int8 primary key,
14192 source_id int8 references v1,
14193 destination_id int8 references v3
14194);
14195
14196create property graph g1
14197 vertex tables (v1 as source_vertex, v2 as destination_vertex, v3)
14198 edge tables (
14199 e1 source source_vertex$0 destination destination_vertex,
14200 e2 source source_vertex destination v3);
14201"), @"
14202 ╭▸
14203 30 │ vertex tables (v1 as source_vertex, v2 as destination_vertex, v3)
14204 │ ───────────── 2. destination
14205 31 │ edge tables (
14206 32 │ e1 source source_vertex destination destination_vertex,
14207 ╰╴ ─ 1. source
14208 "
14209 );
14210
14211 assert_snapshot!(goto("
14212create table v1 (
14213 id int8 primary key,
14214 name text
14215);
14216
14217create table v2 (
14218 id int8 primary key,
14219 name text
14220);
14221
14222create table v3 (
14223 id int8 primary key,
14224 name text
14225);
14226
14227create table e1 (
14228 id int8 primary key,
14229 source_id int8 references v1,
14230 destination_id int8 references v2
14231);
14232
14233create table e2 (
14234 id int8 primary key,
14235 source_id int8 references v1,
14236 destination_id int8 references v3
14237);
14238
14239create property graph g1
14240 vertex tables (v1, v2, v3)
14241 edge tables (
14242 e1 source v1 destination v2,
14243 e2 source v1 destination v3$0);
14244"), @"
14245 ╭▸
14246 12 │ create table v3 (
14247 │ ── 2. destination
14248 ‡
14249 33 │ e2 source v1 destination v3);
14250 ╰╴ ─ 1. source
14251 "
14252 );
14253 }
14254
14255 #[test]
14256 fn goto_create_property_graph_references_table() {
14257 assert_snapshot!(goto("
14258create table v1 (id int8 primary key);
14259create table v2 (id int8 primary key);
14260create table e1 (
14261 id int8 primary key,
14262 source_id int8 references v1,
14263 destination_id int8 references v2
14264);
14265
14266create property graph g1
14267 vertex tables (v1 as source_vertex, v2)
14268 edge tables (
14269 e1
14270 source key (source_id) references source_vertex$0 (id)
14271 destination key (destination_id) references v2 (id)
14272 );
14273"), @"
14274 ╭▸
14275 11 │ vertex tables (v1 as source_vertex, v2)
14276 │ ───────────── 2. destination
14277 ‡
14278 14 │ source key (source_id) references source_vertex (id)
14279 ╰╴ ─ 1. source
14280 "
14281 );
14282 }
14283
14284 #[test]
14285 fn goto_create_property_graph_vertex_key_column() {
14286 assert_snapshot!(goto("
14287create table v1 (
14288 id int8 primary key,
14289 name text
14290);
14291
14292create property graph g1
14293 vertex tables (v1 key (id$0));
14294"), @"
14295 ╭▸
14296 3 │ id int8 primary key,
14297 │ ── 2. destination
14298 ‡
14299 8 │ vertex tables (v1 key (id));
14300 ╰╴ ─ 1. source
14301 ");
14302 }
14303
14304 #[test]
14305 fn goto_create_property_graph_edge_source_key_column() {
14306 assert_snapshot!(goto("
14307create table v1 (id int8 primary key);
14308create table v2 (id int8 primary key);
14309create table e1 (
14310 id int8 primary key,
14311 source_id int8 references v1,
14312 destination_id int8 references v2
14313);
14314
14315create property graph g1
14316 vertex tables (v1, v2)
14317 edge tables (
14318 e1 key (id)
14319 source key (source_id$0) references v1 (id)
14320 destination key (destination_id) references v2 (id));
14321"), @"
14322 ╭▸
14323 6 │ source_id int8 references v1,
14324 │ ───────── 2. destination
14325 ‡
14326 14 │ source key (source_id) references v1 (id)
14327 ╰╴ ─ 1. source
14328 ");
14329 }
14330
14331 #[test]
14332 fn goto_create_property_graph_edge_source_references_column() {
14333 assert_snapshot!(goto("
14334create table v1 (id int8 primary key);
14335create table v2 (id int8 primary key);
14336create table e1 (
14337 id int8 primary key,
14338 source_id int8 references v1,
14339 destination_id int8 references v2
14340);
14341
14342create property graph g1
14343 vertex tables (v1 as source_vertex, v2)
14344 edge tables (
14345 e1 key (id)
14346 source key (source_id) references source_vertex (id$0)
14347 destination key (destination_id) references v2 (id));
14348"), @"
14349 ╭▸
14350 2 │ create table v1 (id int8 primary key);
14351 │ ── 2. destination
14352 ‡
14353 14 │ source key (source_id) references source_vertex (id)
14354 ╰╴ ─ 1. source
14355 ");
14356 }
14357
14358 #[test]
14359 fn goto_create_property_graph_edge_destination_key_column() {
14360 assert_snapshot!(goto("
14361create table v1 (id int8 primary key);
14362create table v2 (id int8 primary key);
14363create table e1 (
14364 id int8 primary key,
14365 source_id int8 references v1,
14366 destination_id int8 references v2
14367);
14368
14369create property graph g1
14370 vertex tables (v1, v2)
14371 edge tables (
14372 e1 key (id)
14373 source key (source_id) references v1 (id)
14374 destination key (destination_id$0) references v2 (id));
14375"), @"
14376 ╭▸
14377 7 │ destination_id int8 references v2
14378 │ ────────────── 2. destination
14379 ‡
14380 15 │ destination key (destination_id) references v2 (id));
14381 ╰╴ ─ 1. source
14382 ");
14383 }
14384
14385 #[test]
14386 fn goto_create_property_graph_edge_destination_references_column() {
14387 assert_snapshot!(goto("
14388create table v1 (id int8 primary key);
14389create table v2 (id int8 primary key);
14390create table e1 (
14391 id int8 primary key,
14392 source_id int8 references v1,
14393 destination_id int8 references v2
14394);
14395
14396create property graph g1
14397 vertex tables (v1, v2)
14398 edge tables (
14399 e1 key (id)
14400 source key (source_id) references v1 (id)
14401 destination key (destination_id) references v2 (id$0));
14402"), @"
14403 ╭▸
14404 3 │ create table v2 (id int8 primary key);
14405 │ ── 2. destination
14406 ‡
14407 15 │ destination key (destination_id) references v2 (id));
14408 ╰╴ ─ 1. source
14409 ");
14410 }
14411
14412 #[test]
14413 fn goto_create_property_graph_vertex_properties_column() {
14414 assert_snapshot!(goto("
14415create table v1 (
14416 id int8 primary key,
14417 name text
14418);
14419
14420create property graph g1
14421 vertex tables (v1 properties (id$0, name));
14422"), @"
14423 ╭▸
14424 3 │ id int8 primary key,
14425 │ ── 2. destination
14426 ‡
14427 8 │ vertex tables (v1 properties (id, name));
14428 ╰╴ ─ 1. source
14429 ");
14430
14431 assert_snapshot!(goto("
14432create table v1 (
14433 id int8 primary key,
14434 name text
14435);
14436
14437create property graph g1
14438 vertex tables (v1 properties (id, nam$0e));
14439"), @"
14440 ╭▸
14441 4 │ name text
14442 │ ──── 2. destination
14443 ‡
14444 8 │ vertex tables (v1 properties (id, name));
14445 ╰╴ ─ 1. source
14446 ");
14447 }
14448
14449 #[test]
14450 fn goto_create_property_graph_edge_properties_column() {
14451 assert_snapshot!(goto("
14452create table v1 (id int8 primary key);
14453create table v2 (id int8 primary key);
14454create table e1 (
14455 id int8 primary key,
14456 source_id int8 references v1,
14457 destination_id int8 references v2
14458);
14459
14460create property graph g1
14461 vertex tables (v1, v2)
14462 edge tables (
14463 e1
14464 source v1
14465 destination v2
14466 properties (id, source_id$0, destination_id));
14467"), @"
14468 ╭▸
14469 6 │ source_id int8 references v1,
14470 │ ───────── 2. destination
14471 ‡
14472 16 │ properties (id, source_id, destination_id));
14473 ╰╴ ─ 1. source
14474 ");
14475 }
14476
14477 #[test]
14478 fn goto_drop_property_graph() {
14479 assert_snapshot!(goto("
14480create property graph foo.bar vertex tables (t key (a) no properties);
14481drop property graph foo.ba$0r;
14482"), @"
14483 ╭▸
14484 2 │ create property graph foo.bar vertex tables (t key (a) no properties);
14485 │ ─── 2. destination
14486 3 │ drop property graph foo.bar;
14487 ╰╴ ─ 1. source
14488 ");
14489 }
14490
14491 #[test]
14492 fn goto_alter_property_graph() {
14493 assert_snapshot!(goto("
14494create property graph foo.bar vertex tables (t key (a) no properties);
14495alter property graph foo.ba$0r rename to baz;
14496"), @"
14497 ╭▸
14498 2 │ create property graph foo.bar vertex tables (t key (a) no properties);
14499 │ ─── 2. destination
14500 3 │ alter property graph foo.bar rename to baz;
14501 ╰╴ ─ 1. source
14502 ");
14503 }
14504
14505 #[test]
14506 fn goto_graph_table_fn() {
14507 assert_snapshot!(goto("
14508create property graph myshop vertex tables (t key (a) no properties);
14509select 1 from graph_table (myshop$0
14510 match (n is t)
14511 columns (1 as x));
14512"), @"
14513 ╭▸
14514 2 │ create property graph myshop vertex tables (t key (a) no properties);
14515 │ ────── 2. destination
14516 3 │ select 1 from graph_table (myshop
14517 ╰╴ ─ 1. source
14518 ");
14519 }
14520
14521 #[test]
14522 fn goto_create_function_param_percent_type_column() {
14523 assert_snapshot!(goto("
14524create schema s;
14525create table s.t (a int, b text);
14526create function f(x s.t.a$0%type) returns s.t.b%type
14527 as $$ select 'hello'::text $$ language sql;
14528"), @"
14529 ╭▸
14530 3 │ create table s.t (a int, b text);
14531 │ ─ 2. destination
14532 4 │ create function f(x s.t.a%type) returns s.t.b%type
14533 ╰╴ ─ 1. source
14534 ");
14535 }
14536
14537 #[test]
14538 fn goto_create_function_param_percent_type_table() {
14539 assert_snapshot!(goto("
14540create schema s;
14541create table s.t (a int, b text);
14542create function f(x s.t$0.a%type) returns s.t.b%type
14543 as $$ select 'hello'::text $$ language sql;
14544"), @"
14545 ╭▸
14546 3 │ create table s.t (a int, b text);
14547 │ ─ 2. destination
14548 4 │ create function f(x s.t.a%type) returns s.t.b%type
14549 ╰╴ ─ 1. source
14550 ");
14551 }
14552
14553 #[test]
14554 fn goto_create_function_param_percent_type_schema() {
14555 assert_snapshot!(goto("
14556create schema s;
14557create table s.t (a int, b text);
14558create function f(x s$0.t.a%type) returns s.t.b%type
14559 as $$ select 'hello'::text $$ language sql;
14560"), @"
14561 ╭▸
14562 2 │ create schema s;
14563 │ ─ 2. destination
14564 3 │ create table s.t (a int, b text);
14565 4 │ create function f(x s.t.a%type) returns s.t.b%type
14566 ╰╴ ─ 1. source
14567 ");
14568 }
14569
14570 #[test]
14571 fn goto_create_function_returns_percent_type_column() {
14572 assert_snapshot!(goto("
14573create schema s;
14574create table s.t (a int, b text);
14575create function f(x s.t.a%type) returns s.t.b$0%type
14576 as $$ select 'hello'::text $$ language sql;
14577"), @"
14578 ╭▸
14579 3 │ create table s.t (a int, b text);
14580 │ ─ 2. destination
14581 4 │ create function f(x s.t.a%type) returns s.t.b%type
14582 ╰╴ ─ 1. source
14583 ");
14584 }
14585
14586 #[test]
14587 fn goto_create_function_param_percent_type_two_part() {
14588 assert_snapshot!(goto("
14589create table t (a int, b text);
14590create function f(x t.a$0%type) returns t.b%type
14591 as $$ select 'hello'::text $$ language sql;
14592"), @"
14593 ╭▸
14594 2 │ create table t (a int, b text);
14595 │ ─ 2. destination
14596 3 │ create function f(x t.a%type) returns t.b%type
14597 ╰╴ ─ 1. source
14598 ");
14599 }
14600
14601 #[test]
14602 fn goto_grant_table() {
14603 assert_snapshot!(goto("
14604create table foo (id int);
14605grant select on foo$0 to bob;
14606"), @"
14607 ╭▸
14608 2 │ create table foo (id int);
14609 │ ─── 2. destination
14610 3 │ grant select on foo to bob;
14611 ╰╴ ─ 1. source
14612 ");
14613 }
14614
14615 #[test]
14616 fn goto_grant_table_keyword() {
14617 assert_snapshot!(goto("
14618create table foo (id int);
14619grant select on table foo$0 to bob;
14620"), @"
14621 ╭▸
14622 2 │ create table foo (id int);
14623 │ ─── 2. destination
14624 3 │ grant select on table foo to bob;
14625 ╰╴ ─ 1. source
14626 ");
14627 }
14628
14629 #[test]
14630 fn goto_revoke_table() {
14631 assert_snapshot!(goto("
14632create table foo (id int);
14633revoke select on foo$0 from bob;
14634"), @"
14635 ╭▸
14636 2 │ create table foo (id int);
14637 │ ─── 2. destination
14638 3 │ revoke select on foo from bob;
14639 ╰╴ ─ 1. source
14640 ");
14641 }
14642
14643 #[test]
14644 fn goto_grant_column() {
14645 assert_snapshot!(goto("
14646create table foo (id int);
14647grant select (id$0) on foo to bob;
14648"), @"
14649 ╭▸
14650 2 │ create table foo (id int);
14651 │ ── 2. destination
14652 3 │ grant select (id) on foo to bob;
14653 ╰╴ ─ 1. source
14654 ");
14655 }
14656
14657 #[test]
14658 fn goto_grant_sequence() {
14659 assert_snapshot!(goto("
14660create sequence s;
14661grant usage on sequence s$0 to bob;
14662"), @"
14663 ╭▸
14664 2 │ create sequence s;
14665 │ ─ 2. destination
14666 3 │ grant usage on sequence s to bob;
14667 ╰╴ ─ 1. source
14668 ");
14669 }
14670
14671 #[test]
14672 fn goto_grant_function() {
14673 assert_snapshot!(goto("
14674create function f() returns int language sql as 'select 1';
14675grant execute on function f$0 to bob;
14676"), @"
14677 ╭▸
14678 2 │ create function f() returns int language sql as 'select 1';
14679 │ ─ 2. destination
14680 3 │ grant execute on function f to bob;
14681 ╰╴ ─ 1. source
14682 ");
14683 }
14684
14685 #[test]
14686 fn goto_grant_schema() {
14687 assert_snapshot!(goto("
14688create schema myschema;
14689grant usage on schema myschema$0 to bob;
14690"), @"
14691 ╭▸
14692 2 │ create schema myschema;
14693 │ ──────── 2. destination
14694 3 │ grant usage on schema myschema to bob;
14695 ╰╴ ─ 1. source
14696 ");
14697 }
14698
14699 #[test]
14700 fn goto_grant_view() {
14701 assert_snapshot!(goto("
14702create view v as select 1;
14703grant select on v$0 to bob;
14704"), @"
14705 ╭▸
14706 2 │ create view v as select 1;
14707 │ ─ 2. destination
14708 3 │ grant select on v to bob;
14709 ╰╴ ─ 1. source
14710 ");
14711 }
14712
14713 #[test]
14714 fn goto_grant_domain() {
14715 assert_snapshot!(goto("
14716create domain d as int;
14717grant usage on domain d$0 to bob;
14718"), @"
14719 ╭▸
14720 2 │ create domain d as int;
14721 │ ─ 2. destination
14722 3 │ grant usage on domain d to bob;
14723 ╰╴ ─ 1. source
14724 ");
14725 }
14726
14727 #[test]
14728 fn goto_grant_language() {
14729 assert_snapshot!(goto("
14730create language mylang handler h;
14731grant usage on language mylang$0 to bob;
14732"), @"
14733 ╭▸
14734 2 │ create language mylang handler h;
14735 │ ────── 2. destination
14736 3 │ grant usage on language mylang to bob;
14737 ╰╴ ─ 1. source
14738 ");
14739 }
14740
14741 #[test]
14742 fn goto_grant_foreign_server() {
14743 assert_snapshot!(goto("
14744create foreign data wrapper fdw;
14745create server s foreign data wrapper fdw;
14746grant usage on foreign server s$0 to bob;
14747"), @"
14748 ╭▸
14749 3 │ create server s foreign data wrapper fdw;
14750 │ ─ 2. destination
14751 4 │ grant usage on foreign server s to bob;
14752 ╰╴ ─ 1. source
14753 ");
14754 }
14755
14756 #[test]
14757 fn goto_grant_foreign_data_wrapper() {
14758 assert_snapshot!(goto("
14759create foreign data wrapper w;
14760grant usage on foreign data wrapper w$0 to bob;
14761"), @"
14762 ╭▸
14763 2 │ create foreign data wrapper w;
14764 │ ─ 2. destination
14765 3 │ grant usage on foreign data wrapper w to bob;
14766 ╰╴ ─ 1. source
14767 ");
14768 }
14769
14770 #[test]
14771 fn goto_grant_all_tables_in_schema() {
14772 assert_snapshot!(goto("
14773create schema sc;
14774grant select on all tables in schema sc$0 to bob;
14775"), @"
14776 ╭▸
14777 2 │ create schema sc;
14778 │ ── 2. destination
14779 3 │ grant select on all tables in schema sc to bob;
14780 ╰╴ ─ 1. source
14781 ");
14782 }
14783
14784 #[test]
14785 fn goto_create_statistics_column() {
14786 assert_snapshot!(goto("
14787create table t(a int, b int);
14788create statistics st on a$0, b from t;
14789"), @"
14790 ╭▸
14791 2 │ create table t(a int, b int);
14792 │ ─ 2. destination
14793 3 │ create statistics st on a, b from t;
14794 ╰╴ ─ 1. source
14795 ");
14796 }
14797
14798 #[test]
14799 fn goto_create_statistics_table() {
14800 assert_snapshot!(goto("
14801create table t(a int, b int);
14802create statistics st on a, b from t$0;
14803"), @"
14804 ╭▸
14805 2 │ create table t(a int, b int);
14806 │ ─ 2. destination
14807 3 │ create statistics st on a, b from t;
14808 ╰╴ ─ 1. source
14809 ");
14810 }
14811
14812 #[test]
14813 fn goto_create_statistics_schema_qualified_table() {
14814 assert_snapshot!(goto("
14815create schema s;
14816create table s.t(a int, b int);
14817create statistics st on a, b from s.t$0;
14818"), @"
14819 ╭▸
14820 3 │ create table s.t(a int, b int);
14821 │ ─ 2. destination
14822 4 │ create statistics st on a, b from s.t;
14823 ╰╴ ─ 1. source
14824 ");
14825 }
14826
14827 #[test]
14828 fn goto_drop_statistics() {
14829 assert_snapshot!(goto("
14830create table t(a int);
14831create statistics s on a from t;
14832drop statistics s$0;
14833"), @"
14834 ╭▸
14835 3 │ create statistics s on a from t;
14836 │ ─ 2. destination
14837 4 │ drop statistics s;
14838 ╰╴ ─ 1. source
14839 ");
14840 }
14841
14842 #[test]
14843 fn goto_alter_statistics() {
14844 assert_snapshot!(goto("
14845create table t(a int);
14846create statistics s on a from t;
14847alter statistics s$0 set statistics 100;
14848"), @"
14849 ╭▸
14850 3 │ create statistics s on a from t;
14851 │ ─ 2. destination
14852 4 │ alter statistics s set statistics 100;
14853 ╰╴ ─ 1. source
14854 ");
14855 }
14856
14857 #[test]
14858 fn goto_comment_on_statistics() {
14859 assert_snapshot!(goto("
14860create table t(a int);
14861create statistics s on a from t;
14862comment on statistics s$0 is '';
14863"), @"
14864 ╭▸
14865 3 │ create statistics s on a from t;
14866 │ ─ 2. destination
14867 4 │ comment on statistics s is '';
14868 ╰╴ ─ 1. source
14869 ");
14870 }
14871
14872 #[test]
14873 fn goto_create_publication_table() {
14874 assert_snapshot!(goto("
14875create table t(a int);
14876create publication pub for table t$0;
14877"), @"
14878 ╭▸
14879 2 │ create table t(a int);
14880 │ ─ 2. destination
14881 3 │ create publication pub for table t;
14882 ╰╴ ─ 1. source
14883 ");
14884 }
14885
14886 #[test]
14887 fn goto_create_publication_column() {
14888 assert_snapshot!(goto("
14889create table t(a int, b int);
14890create publication pub for table t (a$0, b);
14891"), @"
14892 ╭▸
14893 2 │ create table t(a int, b int);
14894 │ ─ 2. destination
14895 3 │ create publication pub for table t (a, b);
14896 ╰╴ ─ 1. source
14897 ");
14898 }
14899
14900 #[test]
14901 fn goto_create_publication_where_column() {
14902 assert_snapshot!(goto("
14903create table t(a int, b int);
14904create publication pub for table t where (a$0 > 1);
14905"), @"
14906 ╭▸
14907 2 │ create table t(a int, b int);
14908 │ ─ 2. destination
14909 3 │ create publication pub for table t where (a > 1);
14910 ╰╴ ─ 1. source
14911 ");
14912 }
14913
14914 #[test]
14915 fn goto_count_star_filter_column() {
14916 assert_snapshot!(goto("
14917create table t (a int);
14918select count(*) filter (where a$0 > 0) from t;
14919"), @"
14920 ╭▸
14921 2 │ create table t (a int);
14922 │ ─ 2. destination
14923 3 │ select count(*) filter (where a > 0) from t;
14924 ╰╴ ─ 1. source
14925 ");
14926 }
14927
14928 #[test]
14929 fn goto_with_ordinality_implicit_column() {
14930 assert_snapshot!(goto("
14931select ordinality$0 from unnest(array[1,2]) with ordinality;
14932"), @"
14933 ╭▸
14934 2 │ select ordinality from unnest(array[1,2]) with ordinality;
14935 ╰╴ ─ 1. source ────────── 2. destination
14936 ");
14937 }
14938
14939 #[test]
14940 fn goto_with_ordinality_qualified_implicit_column() {
14941 assert_snapshot!(goto("
14942select u.ordinality$0 from unnest(array[1,2]) with ordinality as u;
14943"), @"
14944 ╭▸
14945 2 │ select u.ordinality from unnest(array[1,2]) with ordinality as u;
14946 ╰╴ ─ 1. source ────────── 2. destination
14947 ");
14948 }
14949
14950 #[test]
14951 fn goto_with_ordinality_explicit_alias_column() {
14952 assert_snapshot!(goto("
14953select o$0 from unnest(array[1,2]) with ordinality as u(x, o);
14954"), @"
14955 ╭▸
14956 2 │ select o from unnest(array[1,2]) with ordinality as u(x, o);
14957 ╰╴ ─ 1. source ─ 2. destination
14958 ");
14959 }
14960
14961 #[test]
14962 fn goto_rows_from_with_ordinality_implicit_column() {
14963 assert_snapshot!(goto("
14964select ordinality$0 from rows from (unnest(array[1,2])) with ordinality;
14965"), @"
14966 ╭▸
14967 2 │ select ordinality from rows from (unnest(array[1,2])) with ordinality;
14968 ╰╴ ─ 1. source ────────── 2. destination
14969 ");
14970 }
14971}