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