1use crate::db::{File, list_files, parse};
2use crate::file::InFile;
3use crate::location::{Location, LocationKind};
4use crate::offsets::token_from_offset;
5use crate::resolve;
6use rowan::{TextRange, TextSize};
7use salsa::Database as Db;
8use smallvec::{SmallVec, smallvec};
9use squawk_syntax::{
10 SyntaxKind, SyntaxToken,
11 ast::{self, AstNode},
12};
13
14fn special_syntax_function_name(token: &SyntaxToken) -> Option<&'static str> {
15 let parent = token.parent()?;
16 match token.kind() {
17 SyntaxKind::EXTRACT_KW if ast::ExtractFn::can_cast(parent.kind()) => Some("extract"),
18 SyntaxKind::SUBSTRING_KW if ast::SubstringFn::can_cast(parent.kind()) => Some("substring"),
19 SyntaxKind::POSITION_KW if ast::PositionFn::can_cast(parent.kind()) => Some("position"),
20 SyntaxKind::OVERLAY_KW if ast::OverlayFn::can_cast(parent.kind()) => Some("overlay"),
21 SyntaxKind::XMLEXISTS_KW if ast::XmlExistsFn::can_cast(parent.kind()) => Some("xmlexists"),
22 SyntaxKind::TRIM_KW => match ast::TrimFn::cast(parent)?.trim_side() {
23 None | Some(ast::TrimSide::TrimBoth(_)) => Some("btrim"),
24 Some(ast::TrimSide::TrimLeading(_)) => Some("ltrim"),
25 Some(ast::TrimSide::TrimTrailing(_)) => Some("rtrim"),
26 },
27 SyntaxKind::COLLATION_KW | SyntaxKind::FOR_KW
28 if ast::CollationForFn::can_cast(parent.kind()) =>
29 {
30 Some("pg_collation_for")
31 }
32 SyntaxKind::IS_KW | SyntaxKind::NOT_KW | SyntaxKind::NORMALIZED_KW
33 if ast::IsNormalized::can_cast(parent.kind())
34 || ast::IsNotNormalized::can_cast(parent.kind()) =>
35 {
36 Some("is_normalized")
37 }
38 SyntaxKind::OVERLAPS_KW if ast::BinExpr::can_cast(parent.kind()) => Some("overlaps"),
39 SyntaxKind::AT_KW | SyntaxKind::TIME_KW | SyntaxKind::ZONE_KW
40 if ast::AtTimeZone::can_cast(parent.kind()) =>
41 {
42 Some("timezone")
43 }
44 SyntaxKind::AT_KW | SyntaxKind::LOCAL_KW if ast::AtLocal::can_cast(parent.kind()) => {
45 Some("timezone")
46 }
47 _ => None,
48 }
49}
50
51fn resolve_in_files(
52 db: &dyn Db,
53 origin_file: File,
54 mut resolve: impl FnMut(File) -> Option<SmallVec<[Location; 1]>>,
55) -> Option<SmallVec<[Location; 1]>> {
56 for definition_file in list_files(db, origin_file) {
57 if let Some(locations) = resolve(definition_file) {
58 return Some(locations);
59 }
60 }
61 None
62}
63
64pub fn goto_definition(db: &dyn Db, position: InFile<TextSize>) -> SmallVec<[Location; 1]> {
65 let file = position.file_id;
66 let Some(token) = token_from_offset(db, position) else {
67 return smallvec![];
68 };
69 let Some(parent) = token.parent() else {
70 return smallvec![];
71 };
72
73 if (token.kind() == SyntaxKind::WHEN_KW && parent.kind() == SyntaxKind::WHEN_CLAUSE)
75 || (token.kind() == SyntaxKind::ELSE_KW && parent.kind() == SyntaxKind::ELSE_CLAUSE)
76 || (token.kind() == SyntaxKind::END_KW && parent.kind() == SyntaxKind::CASE_EXPR)
77 {
78 for parent in token.parent_ancestors() {
79 if let Some(case_expr) = ast::CaseExpr::cast(parent)
80 && let Some(case_token) = case_expr.case_token()
81 {
82 return smallvec![Location::new(
83 file,
84 case_token.text_range(),
85 LocationKind::CaseExpr
86 )];
87 }
88 }
89 }
90
91 if let Some(function_name) = special_syntax_function_name(&token) {
92 return resolve_in_files(db, file, |definition_file| {
93 resolve::resolve_function_name(
94 db,
95 InFile::new(definition_file, token.text_range().start()),
96 function_name,
97 )
98 })
99 .unwrap_or_default();
100 }
101
102 if ast::Commit::can_cast(parent.kind())
104 && let Some(begin_range) = find_preceding_begin(db, position)
105 {
106 return smallvec![Location::new(file, begin_range, LocationKind::CommitBegin)];
107 }
108
109 if ast::Rollback::can_cast(parent.kind())
111 && let Some(begin_range) = find_preceding_begin(db, position)
112 {
113 return smallvec![Location::new(file, begin_range, LocationKind::CommitBegin)];
114 }
115
116 if ast::Begin::can_cast(parent.kind())
118 && let Some(end_range) = find_following_commit_or_rollback(db, position)
119 {
120 return smallvec![Location::new(file, end_range, LocationKind::CommitEnd)];
121 }
122
123 if let Some(name) = ast::AnyName::cast(parent.clone())
124 && matches!(
125 &name,
126 ast::AnyName::AccessMethod(_)
127 | ast::AnyName::Channel(_)
128 | ast::AnyName::ColumnName(_)
129 | ast::AnyName::CompositeField(_)
130 | ast::AnyName::ConstraintName(_)
131 | ast::AnyName::CteName(_)
132 | ast::AnyName::Cursor(_)
133 | ast::AnyName::Database(_)
134 | ast::AnyName::EventTrigger(_)
135 | ast::AnyName::Extension(_)
136 | ast::AnyName::ForeignDataWrapper(_)
137 | ast::AnyName::JsonPathName(_)
138 | ast::AnyName::Language(_)
139 | ast::AnyName::ParamName(_)
140 | ast::AnyName::PathSegment(_)
141 | ast::AnyName::Policy(_)
142 | ast::AnyName::PreparedStatement(_)
143 | ast::AnyName::Publication(_)
144 | ast::AnyName::Role(_)
145 | ast::AnyName::Rule(_)
146 | ast::AnyName::Savepoint(_)
147 | ast::AnyName::Schema(_)
148 | ast::AnyName::Server(_)
149 | ast::AnyName::Subscription(_)
150 | ast::AnyName::TableAlias(_)
151 | ast::AnyName::Tablespace(_)
152 | ast::AnyName::TransitionRelationName(_)
153 | ast::AnyName::Trigger(_)
154 | ast::AnyName::Window(_)
155 )
156 && let Some(location) = Location::from_node(file, name.syntax())
157 {
158 return smallvec![location];
159 }
160
161 if let Some(name_ref) = ast::AnyNameRef::cast(parent.clone()) {
162 let locations = match name_ref {
165 ast::AnyNameRef::AccessMethodRef(name_ref) => {
166 resolve_in_files(db, file, |definition_file| {
167 resolve::resolve_access_method_ref(db, InFile::new(definition_file, &name_ref))
168 })
169 }
170 ast::AnyNameRef::BindParamNameRef(_) => None,
171 ast::AnyNameRef::ChannelRef(name_ref) => {
172 resolve_in_files(db, file, |definition_file| {
173 resolve::resolve_channel_ref(db, InFile::new(definition_file, &name_ref))
174 })
175 }
176 ast::AnyNameRef::ColumnNameRef(name_ref) => {
177 resolve_in_files(db, file, |definition_file| {
178 resolve::resolve_name_ref(db, InFile::new(definition_file, &name_ref))
179 })
180 }
181 ast::AnyNameRef::CompositeFieldRef(name_ref) => {
182 resolve_in_files(db, file, |definition_file| {
183 resolve::resolve_name_ref(db, InFile::new(definition_file, &name_ref))
184 })
185 }
186 ast::AnyNameRef::CursorRef(name_ref) => resolve_in_files(db, file, |definition_file| {
187 resolve::resolve_cursor_ref(db, InFile::new(definition_file, &name_ref))
188 }),
189 ast::AnyNameRef::DatabaseRef(name_ref) => {
190 resolve_in_files(db, file, |definition_file| {
191 resolve::resolve_database_ref(db, InFile::new(definition_file, &name_ref))
192 })
193 }
194 ast::AnyNameRef::ElementTableRef(_) => None,
195 ast::AnyNameRef::EventTriggerRef(name_ref) => {
196 resolve_in_files(db, file, |definition_file| {
197 resolve::resolve_event_trigger_ref(db, InFile::new(definition_file, &name_ref))
198 })
199 }
200 ast::AnyNameRef::ExtensionRef(name_ref) => {
201 resolve_in_files(db, file, |definition_file| {
202 resolve::resolve_extension_ref(db, InFile::new(definition_file, &name_ref))
203 })
204 }
205 ast::AnyNameRef::ForeignDataWrapperRef(name_ref) => {
206 resolve_in_files(db, file, |definition_file| {
207 resolve::resolve_foreign_data_wrapper_ref(
208 db,
209 InFile::new(definition_file, &name_ref),
210 )
211 })
212 }
213 ast::AnyNameRef::JsonPathNameRef(name_ref) => {
214 return resolve::resolve_json_path_name_ref(file, &name_ref).unwrap_or_default();
215 }
216 ast::AnyNameRef::LabelRef(_) => None,
217 ast::AnyNameRef::LanguageRef(name_ref) => {
218 resolve_in_files(db, file, |definition_file| {
219 resolve::resolve_language_ref(db, InFile::new(definition_file, &name_ref))
220 })
221 }
222 ast::AnyNameRef::NameRef(name_ref) => resolve_in_files(db, file, |definition_file| {
223 resolve::resolve_name_ref(db, InFile::new(definition_file, &name_ref))
224 }),
225 ast::AnyNameRef::ParamNameRef(name_ref) => {
226 resolve_in_files(db, file, |definition_file| {
227 resolve::resolve_param_name_ref(db, InFile::new(definition_file, &name_ref))
228 })
229 }
230 ast::AnyNameRef::PathSegmentRef(name_ref) => {
231 resolve_in_files(db, file, |definition_file| {
232 resolve::resolve_name_ref(db, InFile::new(definition_file, &name_ref))
233 })
234 }
235 ast::AnyNameRef::PolicyRef(name_ref) => resolve_in_files(db, file, |definition_file| {
236 resolve::resolve_policy_ref(db, InFile::new(definition_file, &name_ref))
237 }),
238 ast::AnyNameRef::PreparedStatementRef(name_ref) => {
239 resolve_in_files(db, file, |definition_file| {
240 resolve::resolve_prepared_statement_ref(
241 db,
242 InFile::new(definition_file, &name_ref),
243 )
244 })
245 }
246 ast::AnyNameRef::PropertyNameRef(_) => None,
247 ast::AnyNameRef::PublicationRef(name_ref) => {
248 resolve_in_files(db, file, |definition_file| {
249 resolve::resolve_publication_ref(db, InFile::new(definition_file, &name_ref))
250 })
251 }
252 ast::AnyNameRef::RemoteTableNameRef(_) => None,
253 ast::AnyNameRef::RoleRef(name_ref) => resolve_in_files(db, file, |definition_file| {
254 resolve::resolve_role_ref(db, InFile::new(definition_file, &name_ref))
255 }),
256 ast::AnyNameRef::RuleRef(name_ref) => resolve_in_files(db, file, |definition_file| {
257 resolve::resolve_rule_ref(db, InFile::new(definition_file, &name_ref))
258 }),
259 ast::AnyNameRef::SavepointRef(name_ref) => {
260 resolve_in_files(db, file, |definition_file| {
261 resolve::resolve_savepoint_ref(db, InFile::new(definition_file, &name_ref))
262 })
263 }
264 ast::AnyNameRef::SchemaRef(name_ref) => resolve_in_files(db, file, |definition_file| {
265 resolve::resolve_schema_ref(db, InFile::new(definition_file, &name_ref))
266 }),
267 ast::AnyNameRef::ServerRef(name_ref) => resolve_in_files(db, file, |definition_file| {
268 resolve::resolve_server_ref(db, InFile::new(definition_file, &name_ref))
269 }),
270 ast::AnyNameRef::SubscriptionRef(name_ref) => {
271 resolve_in_files(db, file, |definition_file| {
272 resolve::resolve_subscription_ref(db, InFile::new(definition_file, &name_ref))
273 })
274 }
275 ast::AnyNameRef::TablespaceRef(name_ref) => {
276 resolve_in_files(db, file, |definition_file| {
277 resolve::resolve_tablespace_ref(db, InFile::new(definition_file, &name_ref))
278 })
279 }
280 ast::AnyNameRef::TriggerRef(name_ref) => {
281 resolve_in_files(db, file, |definition_file| {
282 resolve::resolve_trigger_ref(db, InFile::new(definition_file, &name_ref))
283 })
284 }
285 ast::AnyNameRef::VertexTableRef(name_ref) => {
286 resolve_in_files(db, file, |definition_file| {
287 resolve::resolve_vertex_table_ref(db, InFile::new(definition_file, &name_ref))
288 })
289 }
290 ast::AnyNameRef::WindowRef(name_ref) => {
291 return resolve::resolve_window_ref(file, &name_ref).unwrap_or_default();
292 }
293 };
294 if let Some(locations) = locations {
295 return locations;
296 }
297 }
298
299 if let Some(config_value_name) = ast::ConfigValueName::cast(parent.clone()) {
300 for definition_file in list_files(db, file) {
301 if let Some(locations) = resolve::resolve_config_value_name(
302 db,
303 InFile::new(definition_file, &config_value_name),
304 ) {
305 return locations;
306 }
307 }
308 }
309
310 if let Some(literal) = ast::Literal::cast(parent.clone()) {
311 for definition_file in list_files(db, file) {
312 if let Some(locations) =
313 resolve::resolve_literal(db, InFile::new(definition_file, &literal))
314 {
315 return locations;
316 }
317 }
318 }
319
320 if let Some(custom_op) = ast::CustomOp::cast(parent.clone()) {
321 for definition_file in list_files(db, file) {
322 if let Some(locations) =
323 resolve::resolve_custom_op(db, InFile::new(definition_file, &custom_op))
324 {
325 return locations;
326 }
327 }
328 }
329
330 let type_node = ast::Type::cast(parent.clone()).or_else(|| {
331 if ast::Timezone::can_cast(parent.kind()) {
333 parent.parent().and_then(ast::Type::cast)
334 } else {
335 None
336 }
337 });
338 if let Some(ty) = type_node {
339 for definition_file in list_files(db, file) {
340 if let Some(ptr) =
341 resolve::resolve_type_ptr_from_type(db, InFile::new(definition_file, &ty))
344 {
345 return smallvec![Location {
346 file: definition_file,
347 range: ptr.text_range(),
348 kind: LocationKind::Type,
349 }];
350 }
351 }
352 }
353
354 smallvec![]
355}
356
357fn find_preceding_begin(db: &dyn Db, position: InFile<TextSize>) -> Option<TextRange> {
358 let mut last_begin: Option<TextRange> = None;
359 for stmt in parse(db, position.file_id).tree().stmts() {
360 if let ast::Stmt::Begin(begin) = stmt {
361 let range = begin.syntax().text_range();
362 if range.end() <= position.value {
363 last_begin = Some(range);
364 }
365 }
366 }
367 last_begin
368}
369
370fn find_following_commit_or_rollback(db: &dyn Db, position: InFile<TextSize>) -> Option<TextRange> {
371 for stmt in parse(db, position.file_id).tree().stmts() {
372 let range = match &stmt {
373 ast::Stmt::Commit(commit) => commit.syntax().text_range(),
374 ast::Stmt::Rollback(rollback) => rollback.syntax().text_range(),
375 _ => continue,
376 };
377 if range.start() >= position.value {
378 return Some(range);
379 }
380 }
381 None
382}
383
384#[cfg(test)]
385mod test {
386 use crate::builtins::builtins_file;
387 use crate::db::File;
388
389 use crate::goto_definition::goto_definition;
390 use crate::test_utils::Fixture;
391 use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet, renderer::DecorStyle};
392 use insta::assert_snapshot;
393 use rowan::TextRange;
394 use rustc_hash::FxHashMap;
395
396 #[must_use]
397 #[track_caller]
398 fn goto(sql: &str) -> String {
399 goto_(sql).expect("should always find a definition")
400 }
401
402 #[track_caller]
403 fn goto_(sql: &str) -> Option<String> {
404 let fixture = Fixture::new(sql);
405 let marker = fixture.marker();
408 let offset = marker.offset_before();
409 let source_span = marker.range();
410 let db = fixture.db();
411 let current_file = offset.file_id;
412
413 let results = goto_definition(db, offset);
414 if results.is_empty() {
415 return None;
416 }
417
418 let mut file_paths = FxHashMap::default();
419 file_paths.insert(current_file, "current.sql");
420 file_paths.insert(builtins_file(db), "builtins.sql");
421
422 let mut dests_by_file: FxHashMap<File, Vec<(usize, TextRange)>> = FxHashMap::default();
423 for (i, location) in results.iter().enumerate() {
424 dests_by_file
425 .entry(location.file)
426 .or_default()
427 .push((i + 2, location.range));
428 }
429
430 let multi_file = dests_by_file.len() > 1 || !dests_by_file.contains_key(¤t_file);
431
432 let mut snippet = Snippet::source(current_file.content(db).as_ref()).fold(true);
433 if multi_file {
434 snippet = snippet.path(*file_paths.get(¤t_file).unwrap());
435 }
436 if let Some(current_dests) = dests_by_file.remove(¤t_file) {
437 snippet = annotate_destinations(snippet, current_dests);
438 }
439 snippet = snippet.annotation(AnnotationKind::Context.span(source_span).label("1. source"));
440
441 let mut groups = vec![Level::INFO.primary_title("definition").element(snippet)];
442
443 for (dest_file, dests) in dests_by_file {
444 let path = file_paths.get(&dest_file).unwrap();
445 let other_snippet = Snippet::source(dest_file.content(db).as_ref())
446 .path(*path)
447 .fold(true);
448 let other_snippet = annotate_destinations(other_snippet, dests);
449 groups.push(
450 Level::INFO
451 .primary_title("definition")
452 .element(other_snippet),
453 );
454 }
455
456 let renderer = Renderer::plain().decor_style(DecorStyle::Unicode);
457 Some(
458 renderer
459 .render(&groups)
460 .to_string()
461 .replace("info: definition", ""),
463 )
464 }
465
466 fn goto_not_found(sql: &str) {
467 assert!(goto_(sql).is_none(), "Should not find a definition");
468 }
469
470 fn annotate_destinations<'a>(
471 mut snippet: Snippet<'a, annotate_snippets::Annotation<'a>>,
472 destinations: Vec<(usize, TextRange)>,
473 ) -> Snippet<'a, annotate_snippets::Annotation<'a>> {
474 for (label_index, range) in destinations {
475 snippet = snippet.annotation(
476 AnnotationKind::Context
477 .span(range.into())
478 .label(format!("{label_index}. destination")),
479 );
480 }
481
482 snippet
483 }
484
485 #[test]
486 fn goto_case_when() {
487 assert_snapshot!(goto("
488select case when$0 x > 1 then 1 else 2 end;
489"), @r"
490 ╭▸
491 2 │ select case when x > 1 then 1 else 2 end;
492 │ ┬─── ─ 1. source
493 │ │
494 ╰╴ 2. destination
495 ");
496 }
497
498 #[test]
499 fn goto_case_else() {
500 assert_snapshot!(goto("
501select case when x > 1 then 1 else$0 2 end;
502"), @r"
503 ╭▸
504 2 │ select case when x > 1 then 1 else 2 end;
505 ╰╴ ──── 2. destination ─ 1. source
506 ");
507 }
508
509 #[test]
510 fn goto_case_end() {
511 assert_snapshot!(goto("
512select case when x > 1 then 1 else 2 end$0;
513"), @r"
514 ╭▸
515 2 │ select case when x > 1 then 1 else 2 end;
516 ╰╴ ──── 2. destination ─ 1. source
517 ");
518 }
519
520 #[test]
521 fn goto_case_end_trailing_semi() {
522 assert_snapshot!(goto("
523select case when x > 1 then 1 else 2 end;$0
524"), @r"
525 ╭▸
526 2 │ select case when x > 1 then 1 else 2 end;
527 ╰╴ ──── 2. destination ─ 1. source
528 ");
529 }
530
531 #[test]
532 fn goto_case_then_not_found() {
533 goto_not_found(
534 "
535select case when x > 1 then$0 1 else 2 end;
536",
537 )
538 }
539
540 #[test]
541 fn rollback_to_begin() {
542 assert_snapshot!(goto(
543 "
544begin;
545select 1;
546rollback$0;
547",
548 ), @"
549 ╭▸
550 2 │ begin;
551 │ ────── 2. destination
552 3 │ select 1;
553 4 │ rollback;
554 ╰╴ ─ 1. source
555 ");
556 }
557
558 #[test]
559 fn goto_drop_table() {
560 assert_snapshot!(goto("
561create table t();
562drop table t$0;
563"), @r"
564 ╭▸
565 2 │ create table t();
566 │ ─ 2. destination
567 3 │ drop table t;
568 ╰╴ ─ 1. source
569 ");
570 }
571
572 #[test]
573 fn goto_drop_foreign_table() {
574 assert_snapshot!(goto("
575create foreign table t(a int) server s;
576drop foreign table t$0;
577"), @r"
578 ╭▸
579 2 │ create foreign table t(a int) server s;
580 │ ─ 2. destination
581 3 │ drop foreign table t;
582 ╰╴ ─ 1. source
583 ");
584 }
585
586 #[test]
587 fn goto_definition_prefers_previous_token() {
588 assert_snapshot!(goto("
589create table t(a int);
590select t.$0a from t;
591"), @r"
592 ╭▸
593 2 │ create table t(a int);
594 │ ─ 2. destination
595 3 │ select t.a from t;
596 ╰╴ ─ 1. source
597 ");
598
599 assert_snapshot!(goto("
600create type ty as (a int, b int);
601with t as (select '(1,2)'::ty c)
602select (c)$0.a from t;
603"), @r"
604 ╭▸
605 3 │ with t as (select '(1,2)'::ty c)
606 │ ─ 2. destination
607 4 │ select (c).a from t;
608 ╰╴ ─ 1. source
609 ");
610 assert_snapshot!(goto("
611create function f() returns int as 'select 1' language sql;
612select f($0);
613"), @r"
614 ╭▸
615 2 │ create function f() returns int as 'select 1' language sql;
616 │ ─ 2. destination
617 3 │ select f();
618 ╰╴ ─ 1. source
619 ");
620
621 assert_snapshot!(goto("
622with t as (select array[1,2,3]::int[] c)
623select c[$01] from t;
624"), @r"
625 ╭▸
626 2 │ with t as (select array[1,2,3]::int[] c)
627 │ ─ 2. destination
628 3 │ select c[1] from t;
629 ╰╴ ─ 1. source
630 ");
631
632 assert_snapshot!(goto("
633with t as (select array[1,2,3]::int[] c, 1 b)
634select c[b]$0 from t;
635"), @r"
636 ╭▸
637 2 │ with t as (select array[1,2,3]::int[] c, 1 b)
638 │ ─ 2. destination
639 3 │ select c[b] from t;
640 ╰╴ ─ 1. source
641 ");
642 }
643
644 #[test]
645 fn goto_fetch_cursor() {
646 assert_snapshot!(goto("
647declare c scroll cursor for select * from t;
648fetch forward 5 from c$0;
649"), @r"
650 ╭▸
651 2 │ declare c scroll cursor for select * from t;
652 │ ─ 2. destination
653 3 │ fetch forward 5 from c;
654 ╰╴ ─ 1. source
655 ");
656 }
657
658 #[test]
659 fn goto_close_cursor() {
660 assert_snapshot!(goto("
661declare c scroll cursor for select * from t;
662close c$0;
663"), @r"
664 ╭▸
665 2 │ declare c scroll cursor for select * from t;
666 │ ─ 2. destination
667 3 │ close c;
668 ╰╴ ─ 1. source
669 ");
670 }
671
672 #[test]
673 fn goto_move_cursor() {
674 assert_snapshot!(goto("
675declare c scroll cursor for select * from t;
676move forward 10 from c$0;
677"), @r"
678 ╭▸
679 2 │ declare c scroll cursor for select * from t;
680 │ ─ 2. destination
681 3 │ move forward 10 from c;
682 ╰╴ ─ 1. source
683 ");
684 }
685
686 #[test]
687 fn goto_execute_prepared_statement() {
688 assert_snapshot!(goto("
689prepare stmt as select 1;
690execute stmt$0;
691"), @r"
692 ╭▸
693 2 │ prepare stmt as select 1;
694 │ ──── 2. destination
695 3 │ execute stmt;
696 ╰╴ ─ 1. source
697 ");
698 }
699
700 #[test]
701 fn goto_deallocate_prepared_statement() {
702 assert_snapshot!(goto("
703prepare stmt as select 1;
704deallocate stmt$0;
705"), @r"
706 ╭▸
707 2 │ prepare stmt as select 1;
708 │ ──── 2. destination
709 3 │ deallocate stmt;
710 ╰╴ ─ 1. source
711 ");
712 }
713
714 #[test]
715 fn goto_notify_channel() {
716 assert_snapshot!(goto("
717listen updates;
718notify updates$0;
719"), @r"
720 ╭▸
721 2 │ listen updates;
722 │ ─────── 2. destination
723 3 │ notify updates;
724 ╰╴ ─ 1. source
725 ");
726 }
727
728 #[test]
729 fn goto_unlisten_channel() {
730 assert_snapshot!(goto("
731listen updates;
732unlisten updates$0;
733"), @r"
734 ╭▸
735 2 │ listen updates;
736 │ ─────── 2. destination
737 3 │ unlisten updates;
738 ╰╴ ─ 1. source
739 ");
740 }
741
742 #[test]
743 fn goto_rollback_to_savepoint() {
744 assert_snapshot!(goto("
745begin;
746savepoint sp;
747rollback to savepoint sp$0;
748"), @"
749 ╭▸
750 3 │ savepoint sp;
751 │ ── 2. destination
752 4 │ rollback to savepoint sp;
753 ╰╴ ─ 1. source
754 ");
755 }
756
757 #[test]
758 fn goto_rollback_to_savepoint_without_savepoint_keyword() {
759 assert_snapshot!(goto("
760begin;
761savepoint sp;
762rollback to sp$0;
763"), @"
764 ╭▸
765 3 │ savepoint sp;
766 │ ── 2. destination
767 4 │ rollback to sp;
768 ╰╴ ─ 1. source
769 ");
770 }
771
772 #[test]
773 fn goto_rollback_to_most_recent_savepoint_with_same_name() {
774 assert_snapshot!(goto("
775begin;
776savepoint sp;
777savepoint sp;
778rollback to sp$0;
779"), @"
780 ╭▸
781 4 │ savepoint sp;
782 │ ── 2. destination
783 5 │ rollback to sp;
784 ╰╴ ─ 1. source
785 ");
786 }
787
788 #[test]
789 fn goto_rollback_keeps_target_savepoint() {
790 assert_snapshot!(goto("
791begin;
792savepoint sp;
793rollback to sp;
794rollback to sp$0;
795"), @"
796 ╭▸
797 3 │ savepoint sp;
798 │ ── 2. destination
799 4 │ rollback to sp;
800 5 │ rollback to sp;
801 ╰╴ ─ 1. source
802 ");
803 }
804
805 #[test]
806 fn goto_rollback_discards_later_savepoints() {
807 goto_not_found(
808 "
809begin;
810savepoint keep;
811savepoint discarded;
812rollback to keep;
813release savepoint discarded$0;
814",
815 );
816 }
817
818 #[test]
819 fn goto_commit_discards_savepoints() {
820 goto_not_found(
821 "
822begin;
823savepoint sp;
824commit;
825release savepoint sp$0;
826",
827 );
828 }
829
830 #[test]
831 fn goto_prepare_transaction_discards_savepoints() {
832 goto_not_found(
833 "
834begin;
835savepoint sp;
836prepare transaction 'foo';
837release savepoint sp$0;
838",
839 );
840 }
841
842 #[test]
843 fn goto_bare_rollback_discards_savepoints() {
844 goto_not_found(
845 "
846begin;
847savepoint sp;
848rollback;
849release savepoint sp$0;
850",
851 );
852 }
853
854 #[test]
855 fn goto_release_savepoint() {
856 assert_snapshot!(goto("
857begin;
858savepoint sp;
859release savepoint sp$0;
860"), @"
861 ╭▸
862 3 │ savepoint sp;
863 │ ── 2. destination
864 4 │ release savepoint sp;
865 ╰╴ ─ 1. source
866 ");
867 }
868
869 #[test]
870 fn goto_delete_where_current_of_cursor() {
871 assert_snapshot!(goto("
872declare c scroll cursor for select * from t;
873delete from t where current of c$0;
874"), @r"
875 ╭▸
876 2 │ declare c scroll cursor for select * from t;
877 │ ─ 2. destination
878 3 │ delete from t where current of c;
879 ╰╴ ─ 1. source
880 ");
881 }
882
883 #[test]
884 fn goto_update_where_current_of_cursor() {
885 assert_snapshot!(goto("
886declare c scroll cursor for select * from t;
887update t set a = a + 10 where current of c$0;
888"), @r"
889 ╭▸
890 2 │ declare c scroll cursor for select * from t;
891 │ ─ 2. destination
892 3 │ update t set a = a + 10 where current of c;
893 ╰╴ ─ 1. source
894 ");
895 }
896
897 #[test]
898 fn goto_with_table_star() {
899 assert_snapshot!(goto("
900with t as (select 1 a)
901select t$0.* from t;
902"), @r"
903 ╭▸
904 2 │ with t as (select 1 a)
905 │ ─ 2. destination
906 3 │ select t.* from t;
907 ╰╴ ─ 1. source
908 ");
909 }
910
911 #[test]
912 fn goto_cte_shadowed_table_star_column_count_not_found() {
913 goto_not_found(
914 "
915create table t(a int, b int);
916with
917 t as (
918 select 1
919 ),
920 -- yy overrides y since there's only 1 column in the *
921 u(x, yy) as (
922 select *, 2 y, 3 z from t
923 )
924select y$0 from u;
925",
926 );
927 }
928
929 #[test]
930 fn goto_cross_join_func_column() {
931 assert_snapshot!(goto(r#"
932with t(x) as (select $$[{"a":1,"b":2}]$$::json)
933select * from t, json_to_recordset(x$0) as r(a int, b int);
934"#), @r#"
935 ╭▸
936 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
937 │ ─ 2. destination
938 3 │ select * from t, json_to_recordset(x) as r(a int, b int);
939 ╰╴ ─ 1. source
940 "#);
941 }
942
943 #[test]
944 fn goto_cross_join_func_qualified_column_table() {
945 assert_snapshot!(goto(r#"
946with t(x) as (select $$[{"a":1,"b":2}]$$::json)
947select * from t, json_to_recordset(t$0.x) as r(a int, b int);
948"#), @r#"
949 ╭▸
950 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
951 │ ─ 2. destination
952 3 │ select * from t, json_to_recordset(t.x) as r(a int, b int);
953 ╰╴ ─ 1. source
954 "#);
955 }
956
957 #[test]
958 fn goto_cross_join_func_qualified_column_field() {
959 assert_snapshot!(goto(r#"
960with t(x) as (select $$[{"a":1,"b":2}]$$::json)
961select * from t, json_to_recordset(t.x$0) as r(a int, b int);
962"#), @r#"
963 ╭▸
964 2 │ with t(x) as (select $$[{"a":1,"b":2}]$$::json)
965 │ ─ 2. destination
966 3 │ select * from t, json_to_recordset(t.x) as r(a int, b int);
967 ╰╴ ─ 1. source
968 "#);
969 }
970
971 #[test]
972 fn goto_lateral_values_alias_in_subquery() {
973 assert_snapshot!(goto("
974select u.n, x.val
975from (values (1), (2)) u(n)
976cross join lateral (select u$0.n * 10 as val) x;
977"), @r"
978 ╭▸
979 3 │ from (values (1), (2)) u(n)
980 │ ─ 2. destination
981 4 │ cross join lateral (select u.n * 10 as val) x;
982 ╰╴ ─ 1. source
983 ");
984 }
985
986 #[test]
987 fn goto_correlated_subquery_outer_column() {
988 assert_snapshot!(goto("
989create table foo (id int);
990create table bar (fid int);
991select * from bar b where exists (select 1 from foo where foo.id = b.fid$0);
992"), @"
993 ╭▸
994 3 │ create table bar (fid int);
995 │ ─── 2. destination
996 4 │ select * from bar b where exists (select 1 from foo where foo.id = b.fid);
997 ╰╴ ─ 1. source
998 ");
999 }
1000
1001 #[test]
1002 fn goto_update_set_correlated_subquery_column() {
1003 assert_snapshot!(goto("create table foo(a int, b int); update foo set a = (select b$0);"), @"
1004 ╭▸
1005 1 │ create table foo(a int, b int); update foo set a = (select b);
1006 ╰╴ ─ 2. destination ─ 1. source
1007 ");
1008 }
1009
1010 #[test]
1011 fn goto_delete_where_correlated_subquery_column() {
1012 assert_snapshot!(goto("create table foo(a int, b int); delete from foo where a = (select b$0);"), @"
1013 ╭▸
1014 1 │ create table foo(a int, b int); delete from foo where a = (select b);
1015 ╰╴ ─ 2. destination ─ 1. source
1016 ");
1017 }
1018
1019 #[test]
1020 fn goto_multi_level_nested_select_outer_column() {
1021 assert_snapshot!(goto("create table foo(a int); select (select (select a$0)) from foo;"), @"
1022 ╭▸
1023 1 │ create table foo(a int); select (select (select a)) from foo;
1024 ╰╴ ─ 2. destination ─ 1. source
1025 ");
1026 }
1027
1028 #[test]
1029 fn goto_lateral_missing_not_found() {
1030 goto_not_found(
1036 "
1037select u.n, x.val
1038from (values (1), (2)) u(n)
1039cross join (select u$0.n * 10 as val) x;
1040",
1041 );
1042 }
1043
1044 #[test]
1045 fn goto_lateral_deeply_nested_paren_expr_values_alias_in_subquery() {
1046 assert_snapshot!(goto("
1047select u.n, x.val
1048from (values (1), (2)) u(n)
1049cross join lateral ((((select u$0.n * 10 as val)))) x;
1050"), @r"
1051 ╭▸
1052 3 │ from (values (1), (2)) u(n)
1053 │ ─ 2. destination
1054 4 │ cross join lateral ((((select u.n * 10 as val)))) x;
1055 ╰╴ ─ 1. source
1056 ");
1057 }
1058
1059 #[test]
1060 fn goto_lateral_deeply_nested_paren_expr_values_alias_column() {
1061 assert_snapshot!(goto("
1062select u.n, x.val$0
1063from (values (1), (2)) u(n)
1064cross join lateral ((((select u.n * 10 as val)))) x;
1065"), @r"
1066 ╭▸
1067 2 │ select u.n, x.val
1068 │ ─ 1. source
1069 3 │ from (values (1), (2)) u(n)
1070 4 │ cross join lateral ((((select u.n * 10 as val)))) x;
1071 ╰╴ ─── 2. destination
1072 ");
1073 }
1074
1075 #[test]
1076 fn goto_lateral_deeply_nested_paren_expr_missing_not_found() {
1077 goto_not_found(
1083 "
1084select u.n, x.val
1085from (values (1), (2)) u(n)
1086cross join ((((select u$0.n * 10 as val)))) x;
1087",
1088 );
1089 }
1090
1091 #[test]
1092 fn goto_aliased_join_expr_qualified_column() {
1093 assert_snapshot!(goto("
1094create table t(a int, b int);
1095create table u(a int, c int);
1096select j.b$0 from (t join u using(a)) as j;
1097"), @"
1098 ╭▸
1099 2 │ create table t(a int, b int);
1100 │ ─ 2. destination
1101 3 │ create table u(a int, c int);
1102 4 │ select j.b from (t join u using(a)) as j;
1103 ╰╴ ─ 1. source
1104 ");
1105 }
1106
1107 #[test]
1108 fn goto_aliased_join_expr_qualified_merged_column() {
1109 assert_snapshot!(goto("
1110create table t(a int, b int);
1111create table u(a int, c int);
1112select j.a$0 from (t join u using(a)) as j;
1113"), @"
1114 ╭▸
1115 2 │ create table t(a int, b int);
1116 │ ─ 2. destination
1117 3 │ create table u(a int, c int);
1118 4 │ select j.a from (t join u using(a)) as j;
1119 ╰╴ ─ 1. source
1120 ");
1121 }
1122
1123 #[test]
1124 fn goto_aliased_join_expr_qualified_right_column() {
1125 assert_snapshot!(goto("
1126create table t(a int, b int);
1127create table u(a int, c int);
1128select j.c$0 from (t join u using(a)) as j;
1129"), @"
1130 ╭▸
1131 3 │ create table u(a int, c int);
1132 │ ─ 2. destination
1133 4 │ select j.c from (t join u using(a)) as j;
1134 ╰╴ ─ 1. source
1135 ");
1136 }
1137
1138 #[test]
1139 fn goto_unaliased_paren_join_qualified_column_target_list() {
1140 assert_snapshot!(goto("
1141create table t (a int);
1142create table u (b int);
1143select t.a$0 from (t join u on t.a = u.b);
1144"), @"
1145 ╭▸
1146 2 │ create table t (a int);
1147 │ ─ 2. destination
1148 3 │ create table u (b int);
1149 4 │ select t.a from (t join u on t.a = u.b);
1150 ╰╴ ─ 1. source
1151 ");
1152 }
1153
1154 #[test]
1155 fn goto_unaliased_paren_join_qualified_column_where_clause() {
1156 assert_snapshot!(goto("
1157create table t (a int);
1158create table u (b int);
1159select 1 from (t join u on t.a = u.b) where t.a$0 = 1;
1160"), @"
1161 ╭▸
1162 2 │ create table t (a int);
1163 │ ─ 2. destination
1164 3 │ create table u (b int);
1165 4 │ select 1 from (t join u on t.a = u.b) where t.a = 1;
1166 ╰╴ ─ 1. source
1167 ");
1168 }
1169
1170 #[test]
1171 fn goto_unaliased_paren_join_qualified_column_own_on_clause() {
1172 assert_snapshot!(goto("
1173create table t (a int);
1174create table u (b int);
1175select 1 from (t join u on t.a$0 = u.b);
1176"), @"
1177 ╭▸
1178 2 │ create table t (a int);
1179 │ ─ 2. destination
1180 3 │ create table u (b int);
1181 4 │ select 1 from (t join u on t.a = u.b);
1182 ╰╴ ─ 1. source
1183 ");
1184 }
1185
1186 #[test]
1187 fn goto_unaliased_paren_join_qualified_column_outer_on_clause() {
1188 assert_snapshot!(goto("
1189create table t (a int);
1190create table u (b int);
1191create table v (c int);
1192select 1 from (t join u on t.a = u.b) join v on t.a$0 = v.c;
1193"), @"
1194 ╭▸
1195 2 │ create table t (a int);
1196 │ ─ 2. destination
1197 ‡
1198 5 │ select 1 from (t join u on t.a = u.b) join v on t.a = v.c;
1199 ╰╴ ─ 1. source
1200 ");
1201 }
1202
1203 #[test]
1204 fn goto_fully_wrapped_paren_join_qualified_column_left() {
1205 assert_snapshot!(goto("
1206create table t (a int);
1207create table u (b int);
1208create table v (c int);
1209select 1 from ((t join u on t.a = u.b) join v on v.c = t.a$0);
1210"), @"
1211 ╭▸
1212 2 │ create table t (a int);
1213 │ ─ 2. destination
1214 ‡
1215 5 │ select 1 from ((t join u on t.a = u.b) join v on v.c = t.a);
1216 ╰╴ ─ 1. source
1217 ");
1218 }
1219
1220 #[test]
1221 fn goto_fully_wrapped_paren_join_qualified_column_right() {
1222 assert_snapshot!(goto("
1223create table t (a int);
1224create table u (b int);
1225create table v (c int);
1226select 1 from ((t join u on t.a = u.b) join v on v.c$0 = t.a);
1227"), @"
1228 ╭▸
1229 4 │ create table v (c int);
1230 │ ─ 2. destination
1231 5 │ select 1 from ((t join u on t.a = u.b) join v on v.c = t.a);
1232 ╰╴ ─ 1. source
1233 ");
1234 }
1235
1236 #[test]
1237 fn goto_ambiguous_unqualified_column_comma_join() {
1238 assert_snapshot!(goto("
1239create table t(a int);
1240create table u(a int);
1241select a$0 from t, u;
1242"), @"
1243 ╭▸
1244 2 │ create table t(a int);
1245 │ ─ 2. destination
1246 3 │ create table u(a int);
1247 │ ─ 3. destination
1248 4 │ select a from t, u;
1249 ╰╴ ─ 1. source
1250 ");
1251 }
1252
1253 #[test]
1254 fn goto_join_using_output_column() {
1255 assert_snapshot!(goto("
1256create table t(a int, b int);
1257create table u(a int, c int);
1258select a$0 from t join u using(a);
1259"), @"
1260 ╭▸
1261 2 │ create table t(a int, b int);
1262 │ ─ 2. destination
1263 3 │ create table u(a int, c int);
1264 │ ─ 3. destination
1265 4 │ select a from t join u using(a);
1266 ╰╴ ─ 1. source
1267 ");
1268 }
1269
1270 #[test]
1271 fn goto_natural_join_output_column() {
1272 assert_snapshot!(goto("
1273create table t(a int, b int);
1274create table u(a int, c int);
1275select a$0 from t natural join u;
1276"), @"
1277 ╭▸
1278 2 │ create table t(a int, b int);
1279 │ ─ 2. destination
1280 3 │ create table u(a int, c int);
1281 │ ─ 3. destination
1282 4 │ select a from t natural join u;
1283 ╰╴ ─ 1. source
1284 ");
1285 }
1286
1287 #[test]
1288 fn goto_lateral_cte_ref_after_lateral_not_found() {
1289 goto_not_found(
1294 "
1295with
1296 d as (select 1 id, 2 amount),
1297 c as (select 2 id)
1298select r.amount
1299from
1300 d,
1301 lateral (
1302 select d.amount
1303 from d
1304 where d.id = c$0.id
1305 limit 1
1306 ) r,
1307 c;
1308",
1309 );
1310 }
1311
1312 #[test]
1313 fn goto_cte_forward_ref_not_found() {
1314 goto_not_found(
1317 "
1318 with
1319 a as (select * from b$0),
1320 b as (select 1 x)
1321 select * from a;
1322",
1323 );
1324 }
1325
1326 #[test]
1327 fn goto_cte_forward_ref_ignored() {
1328 assert_snapshot!(goto("
1329create table b(c int);
1330with
1331 a as (select c$0 from b),
1332 b as (select 1 c)
1333select c from a;
1334"), @"
1335 ╭▸
1336 2 │ create table b(c int);
1337 │ ─ 2. destination
1338 3 │ with
1339 4 │ a as (select c from b),
1340 ╰╴ ─ 1. source
1341 ");
1342 }
1343
1344 #[test]
1345 fn goto_cte_forward_ref_ignored_inside_table_query() {
1346 assert_snapshot!(goto("
1347create table b(c int);
1348with
1349 a as (table b),
1350 b as (select 1 c)
1351select c$0 from a;
1352"), @"
1353 ╭▸
1354 2 │ create table b(c int);
1355 │ ─ 2. destination
1356 ‡
1357 6 │ select c from a;
1358 ╰╴ ─ 1. source
1359 ");
1360 }
1361
1362 #[test]
1363 fn goto_cte_forward_ref_ignored_inside_create_table_as_star() {
1364 assert_snapshot!(goto("
1365create table b(c int);
1366create table ct as
1367 with
1368 a as (select * from b),
1369 b as (select 1 c)
1370 select * from a;
1371select c$0 from ct;
1372"), @"
1373 ╭▸
1374 2 │ create table b(c int);
1375 │ ─ 2. destination
1376 ‡
1377 8 │ select c from ct;
1378 ╰╴ ─ 1. source
1379 ");
1380 }
1381
1382 #[test]
1383 fn goto_cte_forward_ref_ignored_inside_create_table_as_table() {
1384 assert_snapshot!(goto("
1385create table b(c int);
1386create table made as
1387 with
1388 a as (table b),
1389 b as (select 1 c)
1390 table a;
1391select c$0 from made;
1392"), @"
1393 ╭▸
1394 2 │ create table b(c int);
1395 │ ─ 2. destination
1396 ‡
1397 8 │ select c from made;
1398 ╰╴ ─ 1. source
1399 ");
1400 }
1401
1402 #[test]
1403 fn goto_cte_star_over_subquery_from_item() {
1404 assert_snapshot!(goto("
1405create table t(c int);
1406with
1407 a as (select * from (select c from t))
1408select c$0 from a;
1409"), @"
1410 ╭▸
1411 4 │ a as (select * from (select c from t))
1412 │ ─ 2. destination
1413 5 │ select c from a;
1414 ╰╴ ─ 1. source
1415 ");
1416 }
1417
1418 #[test]
1419 fn goto_outer_cte_visible_inside_inner_with() {
1420 assert_snapshot!(goto("
1421with outer_cte as (select 1 c)
1422select * from (
1423 with inner_cte as (select 2 d)
1424 select c$0 from outer_cte
1425) s;
1426"), @"
1427 ╭▸
1428 2 │ with outer_cte as (select 1 c)
1429 │ ─ 2. destination
1430 ‡
1431 5 │ select c from outer_cte
1432 ╰╴ ─ 1. source
1433 ");
1434 }
1435
1436 #[test]
1437 fn goto_inner_cte_forward_ref_falls_back_to_outer_cte() {
1438 assert_snapshot!(goto("
1439with t as (select 1 c)
1440select * from (
1441 with
1442 x as (select c$0 from t),
1443 t as (select 2 c)
1444 select c from x
1445) s;
1446"), @"
1447 ╭▸
1448 2 │ with t as (select 1 c)
1449 │ ─ 2. destination
1450 ‡
1451 5 │ x as (select c from t),
1452 ╰╴ ─ 1. source
1453 ");
1454 }
1455
1456 #[test]
1457 fn goto_recursive_inner_cte_forward_ref_shadows_outer_cte() {
1458 assert_snapshot!(goto("
1459with t as (select 1 c)
1460select * from (
1461 with recursive
1462 x as (select c$0 from t),
1463 t as (select 2 c)
1464 select c from x
1465) s;
1466"), @"
1467 ╭▸
1468 5 │ x as (select c from t),
1469 │ ─ 1. source
1470 6 │ t as (select 2 c)
1471 ╰╴ ─ 2. destination
1472 ");
1473 }
1474
1475 #[test]
1476 fn goto_cte_forward_ref_ignored_for_qualified_star() {
1477 assert_snapshot!(goto("
1478create table b(c int);
1479with
1480 a as (select b.* from b),
1481 b as (select 1 c)
1482select c$0 from a;
1483"), @"
1484 ╭▸
1485 2 │ create table b(c int);
1486 │ ─ 2. destination
1487 ‡
1488 6 │ select c from a;
1489 ╰╴ ─ 1. source
1490 ");
1491 }
1492
1493 #[test]
1494 fn goto_cte_forward_ref_ignored_for_star_column_count() {
1495 assert_snapshot!(goto("
1496create table b(x int, yy int);
1497with
1498 a(x, yy) as (select *, 2 y, 3 z from b),
1499 b as (select 1 only_col)
1500select y$0 from a;
1501"), @"
1502 ╭▸
1503 4 │ a(x, yy) as (select *, 2 y, 3 z from b),
1504 │ ─ 2. destination
1505 5 │ b as (select 1 only_col)
1506 6 │ select y from a;
1507 ╰╴ ─ 1. source
1508 ");
1509 }
1510
1511 #[test]
1512 fn goto_cte_forward_ref_ignored_inside_subquery_table() {
1513 assert_snapshot!(goto("
1514create table b(c int);
1515with
1516 a as (select * from (table b) q),
1517 b as (select 1 c)
1518select c$0 from a;
1519"), @"
1520 ╭▸
1521 2 │ create table b(c int);
1522 │ ─ 2. destination
1523 ‡
1524 6 │ select c from a;
1525 ╰╴ ─ 1. source
1526 ");
1527 }
1528
1529 #[test]
1530 fn goto_drop_sequence() {
1531 assert_snapshot!(goto("
1532create sequence s;
1533drop sequence s$0;
1534"), @r"
1535 ╭▸
1536 2 │ create sequence s;
1537 │ ─ 2. destination
1538 3 │ drop sequence s;
1539 ╰╴ ─ 1. source
1540 ");
1541 }
1542
1543 #[test]
1544 fn goto_drop_constraint() {
1545 assert_snapshot!(goto("
1546create table t(id int constraint id_positive check (id > 0));
1547alter table t drop constraint id_positive$0;
1548"), @"
1549 ╭▸
1550 2 │ create table t(id int constraint id_positive check (id > 0));
1551 │ ─────────── 2. destination
1552 3 │ alter table t drop constraint id_positive;
1553 ╰╴ ─ 1. source
1554 ");
1555 }
1556
1557 #[test]
1558 fn goto_comment_on_constraint() {
1559 assert_snapshot!(goto("
1560create table t(id int constraint id_positive check (id > 0));
1561comment on constraint id_positive$0 on t is 'positive id';
1562"), @"
1563 ╭▸
1564 2 │ create table t(id int constraint id_positive check (id > 0));
1565 │ ─────────── 2. destination
1566 3 │ comment on constraint id_positive on t is 'positive id';
1567 ╰╴ ─ 1. source
1568 ");
1569 }
1570
1571 #[test]
1572 fn goto_comment_on_constraint_table() {
1573 assert_snapshot!(goto("
1574create table t(id int constraint id_positive check (id > 0));
1575comment on constraint id_positive on t$0 is 'positive id';
1576"), @"
1577 ╭▸
1578 2 │ create table t(id int constraint id_positive check (id > 0));
1579 │ ─ 2. destination
1580 3 │ comment on constraint id_positive on t is 'positive id';
1581 ╰╴ ─ 1. source
1582 ");
1583 }
1584
1585 #[test]
1586 fn goto_drop_constraint_with_same_name_on_multiple_tables() {
1587 assert_snapshot!(goto("
1588create table t(id int constraint id_positive check (id > 0));
1589create table u(id int constraint id_positive check (id > 0));
1590alter table u drop constraint id_positive$0;
1591"), @"
1592 ╭▸
1593 3 │ create table u(id int constraint id_positive check (id > 0));
1594 │ ─────────── 2. destination
1595 4 │ alter table u drop constraint id_positive;
1596 ╰╴ ─ 1. source
1597 ");
1598 }
1599
1600 #[test]
1601 fn goto_alter_table_add_constraint() {
1602 assert_snapshot!(goto("
1603create table t(id int);
1604alter table t add constraint id_positive check (id > 0);
1605comment on constraint id_positive$0 on t is 'positive id';
1606"), @"
1607 ╭▸
1608 3 │ alter table t add constraint id_positive check (id > 0);
1609 │ ─────────── 2. destination
1610 4 │ comment on constraint id_positive on t is 'positive id';
1611 ╰╴ ─ 1. source
1612 ");
1613 }
1614
1615 #[test]
1616 fn goto_on_conflict_constraint() {
1617 assert_snapshot!(goto("
1618create table t(id int constraint t_id_key unique);
1619insert into t values (1) on conflict on constraint t_id_key$0 do nothing;
1620"), @"
1621 ╭▸
1622 2 │ create table t(id int constraint t_id_key unique);
1623 │ ──────── 2. destination
1624 3 │ insert into t values (1) on conflict on constraint t_id_key do nothing;
1625 ╰╴ ─ 1. source
1626 ");
1627 }
1628
1629 #[test]
1630 fn goto_drop_trigger() {
1631 assert_snapshot!(goto("
1632create trigger tr before insert on t for each row execute function f();
1633drop trigger tr$0 on t;
1634"), @r"
1635 ╭▸
1636 2 │ create trigger tr before insert on t for each row execute function f();
1637 │ ── 2. destination
1638 3 │ drop trigger tr on t;
1639 ╰╴ ─ 1. source
1640 ");
1641 }
1642
1643 #[test]
1644 fn goto_create_rule_table() {
1645 assert_snapshot!(goto("
1646create table t(a int);
1647create rule r as on select to t$0 do instead nothing;
1648"), @"
1649 ╭▸
1650 2 │ create table t(a int);
1651 │ ─ 2. destination
1652 3 │ create rule r as on select to t do instead nothing;
1653 ╰╴ ─ 1. source
1654 ");
1655 }
1656
1657 #[test]
1658 fn goto_drop_rule() {
1659 assert_snapshot!(goto("
1660create table t(a int);
1661create rule r as on select to t do instead nothing;
1662drop rule r$0 on t;
1663"), @"
1664 ╭▸
1665 3 │ create rule r as on select to t do instead nothing;
1666 │ ─ 2. destination
1667 4 │ drop rule r on t;
1668 ╰╴ ─ 1. source
1669 ");
1670 }
1671
1672 #[test]
1673 fn goto_alter_rule() {
1674 assert_snapshot!(goto("
1675create table t(a int);
1676create rule r as on select to t do instead nothing;
1677alter rule r$0 on t rename to r2;
1678"), @"
1679 ╭▸
1680 3 │ create rule r as on select to t do instead nothing;
1681 │ ─ 2. destination
1682 4 │ alter rule r on t rename to r2;
1683 ╰╴ ─ 1. source
1684 ");
1685 }
1686
1687 #[test]
1688 fn goto_alter_table_enable_trigger() {
1689 assert_snapshot!(goto("
1690create table t(a int);
1691create function f() returns trigger language plpgsql as $$ begin return new; end $$;
1692create trigger tr before insert on t for each row execute function f();
1693alter table t enable trigger tr$0;
1694"), @"
1695 ╭▸
1696 4 │ create trigger tr before insert on t for each row execute function f();
1697 │ ── 2. destination
1698 5 │ alter table t enable trigger tr;
1699 ╰╴ ─ 1. source
1700 ");
1701 }
1702
1703 #[test]
1704 fn goto_alter_table_disable_trigger() {
1705 assert_snapshot!(goto("
1706create table t(a int);
1707create function f() returns trigger language plpgsql as $$ begin return new; end $$;
1708create trigger tr before insert on t for each row execute function f();
1709alter table t disable trigger tr$0;
1710"), @"
1711 ╭▸
1712 4 │ create trigger tr before insert on t for each row execute function f();
1713 │ ── 2. destination
1714 5 │ alter table t disable trigger tr;
1715 ╰╴ ─ 1. source
1716 ");
1717 }
1718
1719 #[test]
1720 fn goto_alter_table_enable_rule() {
1721 assert_snapshot!(goto("
1722create table t(a int);
1723create rule r as on insert to t do instead nothing;
1724alter table t enable rule r$0;
1725"), @"
1726 ╭▸
1727 3 │ create rule r as on insert to t do instead nothing;
1728 │ ─ 2. destination
1729 4 │ alter table t enable rule r;
1730 ╰╴ ─ 1. source
1731 ");
1732 }
1733
1734 #[test]
1735 fn goto_alter_table_disable_rule() {
1736 assert_snapshot!(goto("
1737create table t(a int);
1738create rule r as on insert to t do instead nothing;
1739alter table t disable rule r$0;
1740"), @"
1741 ╭▸
1742 3 │ create rule r as on insert to t do instead nothing;
1743 │ ─ 2. destination
1744 4 │ alter table t disable rule r;
1745 ╰╴ ─ 1. source
1746 ");
1747 }
1748
1749 #[test]
1750 fn goto_drop_policy() {
1751 assert_snapshot!(goto("
1752create table t(c int);
1753create table u(c int);
1754create policy p on t;
1755create policy p on u;
1756drop policy if exists p$0 on t;
1757"), @r"
1758 ╭▸
1759 4 │ create policy p on t;
1760 │ ─ 2. destination
1761 5 │ create policy p on u;
1762 6 │ drop policy if exists p on t;
1763 ╰╴ ─ 1. source
1764 ");
1765 }
1766
1767 #[test]
1768 fn goto_alter_policy() {
1769 assert_snapshot!(goto("
1770create table t(c int);
1771create policy p on t;
1772alter policy p$0 on t
1773 with check (c > 1);
1774"), @r"
1775 ╭▸
1776 3 │ create policy p on t;
1777 │ ─ 2. destination
1778 4 │ alter policy p on t
1779 ╰╴ ─ 1. source
1780 ");
1781 }
1782
1783 #[test]
1784 fn goto_alter_policy_column() {
1785 assert_snapshot!(goto("
1786create table t(c int);
1787create policy p on t;
1788alter policy p on t
1789 with check (c$0 > 1);
1790"), @"
1791 ╭▸
1792 2 │ create table t(c int);
1793 │ ─ 2. destination
1794 ‡
1795 5 │ with check (c > 1);
1796 ╰╴ ─ 1. source
1797 ");
1798 }
1799
1800 #[test]
1801 fn goto_create_policy_column() {
1802 assert_snapshot!(goto("
1803create table t(c int, d int);
1804create policy p on t
1805 with check (c$0 > d);
1806"), @r"
1807 ╭▸
1808 2 │ create table t(c int, d int);
1809 │ ─ 2. destination
1810 3 │ create policy p on t
1811 4 │ with check (c > d);
1812 ╰╴ ─ 1. source
1813 ");
1814 }
1815
1816 #[test]
1817 fn goto_create_policy_using_column() {
1818 assert_snapshot!(goto("
1819create table t(c int, d int);
1820create policy p on t
1821 using (c$0 > d and 1 < 2);
1822"), @r"
1823 ╭▸
1824 2 │ create table t(c int, d int);
1825 │ ─ 2. destination
1826 3 │ create policy p on t
1827 4 │ using (c > d and 1 < 2);
1828 ╰╴ ─ 1. source
1829 ");
1830 }
1831
1832 #[test]
1833 fn goto_create_policy_qualified_column_table() {
1834 assert_snapshot!(goto("
1835create table t(c int, d int);
1836create policy p on t
1837 with check (t$0.c > d);
1838"), @r"
1839 ╭▸
1840 2 │ create table t(c int, d int);
1841 │ ─ 2. destination
1842 3 │ create policy p on t
1843 4 │ with check (t.c > d);
1844 ╰╴ ─ 1. source
1845 ");
1846 }
1847
1848 #[test]
1849 fn goto_create_policy_qualified_column() {
1850 assert_snapshot!(goto("
1851create table t(c int, d int);
1852create policy p on t
1853 with check (t.c$0 > d);
1854"), @r"
1855 ╭▸
1856 2 │ create table t(c int, d int);
1857 │ ─ 2. destination
1858 3 │ create policy p on t
1859 4 │ with check (t.c > d);
1860 ╰╴ ─ 1. source
1861 ");
1862 }
1863
1864 #[test]
1865 fn goto_create_policy_field_style_function_call() {
1866 assert_snapshot!(goto("
1867create table t(c int);
1868create function x(t) returns int8
1869 as 'select 1'
1870 language sql;
1871create policy p on t
1872 with check (t.c > 1 and t.x$0 > 0);
1873"), @r"
1874 ╭▸
1875 3 │ create function x(t) returns int8
1876 │ ─ 2. destination
1877 ‡
1878 7 │ with check (t.c > 1 and t.x > 0);
1879 ╰╴ ─ 1. source
1880 ");
1881 }
1882
1883 #[test]
1884 fn goto_function_param_in_begin_atomic_body() {
1885 assert_snapshot!(goto("
1886create function f(a int) returns int
1887begin atomic
1888 select a$0;
1889end;
1890"), @"
1891 ╭▸
1892 2 │ create function f(a int) returns int
1893 │ ─ 2. destination
1894 3 │ begin atomic
1895 4 │ select a;
1896 ╰╴ ─ 1. source
1897 ");
1898 }
1899
1900 #[test]
1901 fn goto_function_param_in_begin_atomic_predicate() {
1902 assert_snapshot!(goto("
1903create table t (id int);
1904create function f(x int) returns int begin atomic
1905 select id from t where id = x$0;
1906end;
1907"), @"
1908 ╭▸
1909 3 │ create function f(x int) returns int begin atomic
1910 │ ─ 2. destination
1911 4 │ select id from t where id = x;
1912 ╰╴ ─ 1. source
1913 ");
1914 }
1915
1916 #[test]
1917 fn goto_function_param_in_sql_body_return_expr() {
1918 assert_snapshot!(goto("
1919create function f(x int) returns int language sql return x$0 + 1;
1920"), @"
1921 ╭▸
1922 2 │ create function f(x int) returns int language sql return x + 1;
1923 ╰╴ ─ 2. destination ─ 1. source
1924 ");
1925 }
1926
1927 #[test]
1928 fn goto_function_param_self_qualified_in_sql_body_return_expr() {
1929 assert_snapshot!(goto("
1930create function f(x int) returns int language sql return f.x$0 + 1;
1931"), @"
1932 ╭▸
1933 2 │ create function f(x int) returns int language sql return f.x + 1;
1934 ╰╴ ─ 2. destination ─ 1. source
1935 ");
1936 }
1937
1938 #[test]
1939 fn goto_function_param_bogus_qualified_in_sql_body_return_expr() {
1940 goto_not_found(
1941 "
1942create function f(x int) returns int language sql return bogus.x$0 + 1;
1943",
1944 );
1945 }
1946
1947 #[test]
1948 fn goto_positional_param_in_sql_body_return_expr() {
1949 assert_snapshot!(goto("
1950create function f(x int) returns int language sql return $1$0 + 1;
1951"), @"
1952 ╭▸
1953 2 │ create function f(x int) returns int language sql return $1 + 1;
1954 ╰╴ ─ 2. destination ─ 1. source
1955 ");
1956 }
1957
1958 #[test]
1959 fn goto_positional_param_in_begin_atomic_body() {
1960 assert_snapshot!(goto("
1961create function f(x int) returns int language sql begin atomic
1962 select $1$0 + 1;
1963end;
1964"), @"
1965 ╭▸
1966 2 │ create function f(x int) returns int language sql begin atomic
1967 │ ─ 2. destination
1968 3 │ select $1 + 1;
1969 ╰╴ ─ 1. source
1970 ");
1971 }
1972
1973 #[test]
1974 fn goto_positional_param_unnamed_param() {
1975 assert_snapshot!(goto("
1976create function f(int) returns int language sql return $1$0;
1977"), @"
1978 ╭▸
1979 2 │ create function f(int) returns int language sql return $1;
1980 ╰╴ ─── 2. destination ─ 1. source
1981 ");
1982 }
1983
1984 #[test]
1985 fn goto_positional_param_second_of_two() {
1986 assert_snapshot!(goto("
1987create function f(int, text) returns int language sql return $2$0;
1988"), @"
1989 ╭▸
1990 2 │ create function f(int, text) returns int language sql return $2;
1991 ╰╴ ──── 2. destination ─ 1. source
1992 ");
1993 }
1994
1995 #[test]
1996 fn goto_function_param_in_later_param_default() {
1997 assert_snapshot!(goto("
1998create function f(a int default 1, b int default a$0) returns int
1999begin atomic select 1; end;
2000"), @"
2001 ╭▸
2002 2 │ create function f(a int default 1, b int default a) returns int
2003 ╰╴ ─ 2. destination ─ 1. source
2004 ");
2005 }
2006
2007 #[test]
2008 fn goto_alter_policy_qualified_column_table() {
2009 assert_snapshot!(goto("
2010create table t(c int, d int);
2011alter policy p on t
2012 with check (t$0.c > d);
2013"), @r"
2014 ╭▸
2015 2 │ create table t(c int, d int);
2016 │ ─ 2. destination
2017 3 │ alter policy p on t
2018 4 │ with check (t.c > d);
2019 ╰╴ ─ 1. source
2020 ");
2021 }
2022
2023 #[test]
2024 fn goto_alter_policy_qualified_column() {
2025 assert_snapshot!(goto("
2026create table t(c int, d int);
2027alter policy p on t
2028 with check (t.c$0 > d);
2029"), @r"
2030 ╭▸
2031 2 │ create table t(c int, d int);
2032 │ ─ 2. destination
2033 3 │ alter policy p on t
2034 4 │ with check (t.c > d);
2035 ╰╴ ─ 1. source
2036 ");
2037 }
2038
2039 #[test]
2040 fn goto_builtin_now() {
2041 assert_snapshot!(goto("
2042-- include-builtins
2043select now$0();
2044"), @"
2045 ╭▸ current.sql:3:10
2046 │
2047 3 │ select now();
2048 │ ─ 1. source
2049 ╰╴
2050
2051 ╭▸ builtins.sql:11089:28
2052 │
2053 11089 │ create function pg_catalog.now() returns timestamp with time zone
2054 ╰╴ ─── 2. destination
2055 ");
2056 }
2057
2058 #[test]
2059 fn goto_builtin_extract() {
2060 assert_snapshot!(goto("
2061-- include-builtins
2062select extract$0(year from now());
2063"), @"
2064 ╭▸ current.sql:3:14
2065 │
2066 3 │ select extract(year from now());
2067 │ ─ 1. source
2068 ╰╴
2069
2070 ╭▸ builtins.sql:6309:28
2071 │
2072 6309 │ create function pg_catalog.extract(text, date) returns numeric
2073 ╰╴ ─────── 2. destination
2074 ");
2075 }
2076
2077 #[test]
2078 fn goto_builtin_substring() {
2079 assert_snapshot!(goto("
2080-- include-builtins
2081select substring$0('abc' from 2);
2082"), @"
2083 ╭▸ current.sql:3:16
2084 │
2085 3 │ select substring('abc' from 2);
2086 │ ─ 1. source
2087 ╰╴
2088
2089 ╭▸ builtins.sql:15183:28
2090 │
2091 15183 │ create function pg_catalog.substring(bit, integer) returns bit
2092 ╰╴ ───────── 2. destination
2093 ");
2094 }
2095
2096 #[test]
2097 fn goto_builtin_position() {
2098 assert_snapshot!(goto("
2099-- include-builtins
2100select position$0('b' in 'abc');
2101"), @"
2102 ╭▸ current.sql:3:15
2103 │
2104 3 │ select position('b' in 'abc');
2105 │ ─ 1. source
2106 ╰╴
2107
2108 ╭▸ builtins.sql:13749:28
2109 │
2110 13749 │ create function pg_catalog.position(bit, bit) returns integer
2111 ╰╴ ──────── 2. destination
2112 ");
2113 }
2114
2115 #[test]
2116 fn goto_builtin_overlay() {
2117 assert_snapshot!(goto("
2118-- include-builtins
2119select overlay$0('abc' placing 'x' from 2);
2120"), @"
2121 ╭▸ current.sql:3:14
2122 │
2123 3 │ select overlay('abc' placing 'x' from 2);
2124 │ ─ 1. source
2125 ╰╴
2126
2127 ╭▸ builtins.sql:11609:28
2128 │
2129 11609 │ create function pg_catalog.overlay(bit, bit, integer) returns bit
2130 ╰╴ ─────── 2. destination
2131 ");
2132 }
2133
2134 #[test]
2135 fn goto_builtin_xmlexists() {
2136 assert_snapshot!(goto("
2137-- include-builtins
2138select xmlexists$0('//town[text() = ''Toronto'']' passing by value '<town>Toronto</town>'::xml);
2139"), @"
2140 ╭▸ current.sql:3:16
2141 │
2142 3 │ select xmlexists('//town[text() = ''Toronto'']' passing by value '<town>Toronto</town>'::xml);
2143 │ ─ 1. source
2144 ╰╴
2145
2146 ╭▸ builtins.sql:17434:28
2147 │
2148 17434 │ create function pg_catalog.xmlexists(text, xml) returns boolean
2149 ╰╴ ───────── 2. destination
2150 ");
2151 }
2152
2153 #[test]
2154 fn goto_builtin_system_user() {
2155 assert_snapshot!(goto("
2156-- include-builtins
2157select system_user$0;
2158"), @"
2159 ╭▸ current.sql:3:18
2160 │
2161 3 │ select system_user;
2162 │ ─ 1. source
2163 ╰╴
2164
2165 ╭▸ builtins.sql:15282:28
2166 │
2167 15282 │ create function pg_catalog.system_user() returns text
2168 ╰╴ ─────────── 2. destination
2169 ");
2170 }
2171
2172 #[test]
2173 fn goto_builtin_trim_both() {
2174 assert_snapshot!(goto("
2175-- include-builtins
2176select trim$0(both 'x' from 'xxhixx');
2177"), @"
2178 ╭▸ current.sql:3:11
2179 │
2180 3 │ select trim(both 'x' from 'xxhixx');
2181 │ ─ 1. source
2182 ╰╴
2183
2184 ╭▸ builtins.sql:5005:28
2185 │
2186 5005 │ create function pg_catalog.btrim(bytea, bytea) returns bytea
2187 ╰╴ ───── 2. destination
2188 ");
2189 }
2190
2191 #[test]
2192 fn goto_builtin_trim_leading() {
2193 assert_snapshot!(goto("
2194-- include-builtins
2195select trim$0(leading 'x' from 'xxhi');
2196"), @"
2197 ╭▸ current.sql:3:11
2198 │
2199 3 │ select trim(leading 'x' from 'xxhi');
2200 │ ─ 1. source
2201 ╰╴
2202
2203 ╭▸ builtins.sql:10077:28
2204 │
2205 10077 │ create function pg_catalog.ltrim(bytea, bytea) returns bytea
2206 ╰╴ ───── 2. destination
2207 ");
2208 }
2209
2210 #[test]
2211 fn goto_builtin_trim_trailing() {
2212 assert_snapshot!(goto("
2213-- include-builtins
2214select trim$0(trailing 'x' from 'hixx');
2215"), @"
2216 ╭▸ current.sql:3:11
2217 │
2218 3 │ select trim(trailing 'x' from 'hixx');
2219 │ ─ 1. source
2220 ╰╴
2221
2222 ╭▸ builtins.sql:14633:28
2223 │
2224 14633 │ create function pg_catalog.rtrim(bytea, bytea) returns bytea
2225 ╰╴ ───── 2. destination
2226 ");
2227 }
2228
2229 #[test]
2230 fn goto_builtin_collation_for() {
2231 assert_snapshot!(goto("
2232-- include-builtins
2233select collation$0 for ('x');
2234"), @r#"
2235 ╭▸ current.sql:3:16
2236 │
2237 3 │ select collation for ('x');
2238 │ ─ 1. source
2239 ╰╴
2240
2241 ╭▸ builtins.sql:11861:28
2242 │
2243 11861 │ create function pg_catalog.pg_collation_for("any") returns text
2244 ╰╴ ──────────────── 2. destination
2245 "#);
2246 }
2247
2248 #[test]
2249 fn goto_builtin_is_normalized() {
2250 assert_snapshot!(goto("
2251-- include-builtins
2252select 'abc' is normalized$0;
2253"), @"
2254 ╭▸ current.sql:3:26
2255 │
2256 3 │ select 'abc' is normalized;
2257 │ ─ 1. source
2258 ╰╴
2259
2260 ╭▸ builtins.sql:8965:28
2261 │
2262 8965 │ create function pg_catalog.is_normalized(text, text DEFAULT 'NFC'::text) returns boolean
2263 ╰╴ ───────────── 2. destination
2264 ");
2265 }
2266
2267 #[test]
2268 fn goto_builtin_overlaps() {
2269 assert_snapshot!(goto("
2270-- include-builtins
2271select (date '2026-01-01', date '2026-01-02') overlaps$0 (date '2026-01-02', date '2026-01-03');
2272"), @"
2273 ╭▸ current.sql:3:54
2274 │
2275 3 │ select (date '2026-01-01', date '2026-01-02') overlaps (date '2026-01-02', date '2026-01-03');
2276 │ ─ 1. source
2277 ╰╴
2278
2279 ╭▸ builtins.sql:11557:28
2280 │
2281 11557 │ create function pg_catalog.overlaps(time with time zone, time with time zone, time with time zone, time with time zone) returns boo…
2282 ╰╴ ──────── 2. destination
2283 ");
2284 }
2285
2286 #[test]
2287 fn goto_builtin_at_time_zone() {
2288 assert_snapshot!(goto("
2289-- include-builtins
2290select timestamp '2026-01-01' at time zone$0 'UTC';
2291"), @"
2292 ╭▸ current.sql:3:42
2293 │
2294 3 │ select timestamp '2026-01-01' at time zone 'UTC';
2295 │ ─ 1. source
2296 ╰╴
2297
2298 ╭▸ builtins.sql:16074:28
2299 │
2300 16074 │ create function pg_catalog.timezone(interval, time with time zone) returns time with time zone
2301 ╰╴ ──────── 2. destination
2302 ");
2303 }
2304
2305 #[test]
2306 fn goto_builtin_at_local() {
2307 assert_snapshot!(goto("
2308-- include-builtins
2309select timestamptz '2026-01-01 UTC' at local$0;
2310"), @"
2311 ╭▸ current.sql:3:44
2312 │
2313 3 │ select timestamptz '2026-01-01 UTC' at local;
2314 │ ─ 1. source
2315 ╰╴
2316
2317 ╭▸ builtins.sql:16074:28
2318 │
2319 16074 │ create function pg_catalog.timezone(interval, time with time zone) returns time with time zone
2320 ╰╴ ──────── 2. destination
2321 ");
2322 }
2323
2324 #[test]
2325 fn goto_builtin_current_role() {
2326 assert_snapshot!(goto("
2327-- include-builtins
2328select current_role$0;
2329"), @"
2330 ╭▸ current.sql:3:19
2331 │
2332 3 │ select current_role;
2333 │ ─ 1. source
2334 ╰╴
2335
2336 ╭▸ builtins.sql:5692:28
2337 │
2338 5692 │ create function pg_catalog.current_user() returns name
2339 ╰╴ ──────────── 2. destination
2340 ");
2341 }
2342
2343 #[test]
2344 fn goto_builtin_current_catalog() {
2345 assert_snapshot!(goto("
2346-- include-builtins
2347select current_catalog$0;
2348"), @"
2349 ╭▸ current.sql:3:22
2350 │
2351 3 │ select current_catalog;
2352 │ ─ 1. source
2353 ╰╴
2354
2355 ╭▸ builtins.sql:5668:28
2356 │
2357 5668 │ create function pg_catalog.current_database() returns name
2358 ╰╴ ──────────────── 2. destination
2359 ");
2360 }
2361
2362 #[test]
2363 fn goto_current_timestamp() {
2364 assert_snapshot!(goto("
2365-- include-builtins
2366select current_timestamp$0;
2367"), @"
2368 ╭▸ current.sql:3:24
2369 │
2370 3 │ select current_timestamp;
2371 │ ─ 1. source
2372 ╰╴
2373
2374 ╭▸ builtins.sql:11089:28
2375 │
2376 11089 │ create function pg_catalog.now() returns timestamp with time zone
2377 ╰╴ ─── 2. destination
2378 ");
2379 }
2380
2381 #[test]
2382 fn goto_current_user() {
2383 assert_snapshot!(goto("
2384create function pg_catalog.current_user() returns name
2385 language internal;
2386select current_user$0;
2387"), @"
2388 ╭▸
2389 2 │ create function pg_catalog.current_user() returns name
2390 │ ──────────── 2. destination
2391 3 │ language internal;
2392 4 │ select current_user;
2393 ╰╴ ─ 1. source
2394 "
2395 );
2396 }
2397
2398 #[test]
2399 fn goto_user_keyword() {
2400 assert_snapshot!(goto("
2401create function pg_catalog.current_user() returns name
2402 language internal;
2403select user$0;
2404"), @"
2405 ╭▸
2406 2 │ create function pg_catalog.current_user() returns name
2407 │ ──────────── 2. destination
2408 3 │ language internal;
2409 4 │ select user;
2410 ╰╴ ─ 1. source
2411 "
2412 );
2413 }
2414
2415 #[test]
2416 fn goto_session_user() {
2417 assert_snapshot!(goto("
2418create function pg_catalog.session_user() returns name
2419 language internal;
2420select session_user$0;
2421"), @"
2422 ╭▸
2423 2 │ create function pg_catalog.session_user() returns name
2424 │ ──────────── 2. destination
2425 3 │ language internal;
2426 4 │ select session_user;
2427 ╰╴ ─ 1. source
2428 "
2429 );
2430 }
2431
2432 #[test]
2433 fn goto_current_schema() {
2434 assert_snapshot!(goto("
2435create function current_schema() returns name
2436 language internal;
2437select current_schema$0;
2438"), @"
2439 ╭▸
2440 2 │ create function current_schema() returns name
2441 │ ────────────── 2. destination
2442 3 │ language internal;
2443 4 │ select current_schema;
2444 ╰╴ ─ 1. source
2445 "
2446 );
2447 }
2448
2449 #[test]
2450 fn goto_current_timestamp_cte_column() {
2451 assert_snapshot!(goto("
2452with t as (select 1 current_timestamp)
2453select current_timestamp$0 from t;
2454"), @r"
2455 ╭▸
2456 2 │ with t as (select 1 current_timestamp)
2457 │ ───────────────── 2. destination
2458 3 │ select current_timestamp from t;
2459 ╰╴ ─ 1. source
2460 ");
2461 }
2462
2463 #[test]
2464 fn goto_cte_casing() {
2465 goto_not_found(
2467 "
2468 with t as (select 1 Äpfel)
2469 select äpfel$0 from t;
2470 ",
2471 );
2472 }
2473
2474 #[test]
2475 fn goto_cte_emoji() {
2476 assert_snapshot!(goto(
2477 "
2478 with t as (select 1 🦀)
2479 select 🦀$0 from t;
2480 "), @"
2481 ╭▸
2482 2 │ with t as (select 1 🦀)
2483 │ ── 2. destination
2484 3 │ select 🦀 from t;
2485 ╰╴ ── 1. source
2486 ");
2487 }
2488
2489 #[test]
2490 fn goto_current_timestamp_in_where() {
2491 assert_snapshot!(goto("
2492-- include-builtins
2493create table t(created_at timestamptz);
2494select * from t where current_timestamp$0 > t.created_at;
2495"), @"
2496 ╭▸ current.sql:4:39
2497 │
2498 4 │ select * from t where current_timestamp > t.created_at;
2499 │ ─ 1. source
2500 ╰╴
2501
2502 ╭▸ builtins.sql:11089:28
2503 │
2504 11089 │ create function pg_catalog.now() returns timestamp with time zone
2505 ╰╴ ─── 2. destination
2506 ");
2507 }
2508
2509 #[test]
2510 fn goto_create_policy_schema_qualified_table() {
2511 assert_snapshot!(goto("
2512create schema foo;
2513create table foo.t(c int);
2514create policy p on foo.t
2515 with check (foo.t$0.c > 1);
2516"), @r"
2517 ╭▸
2518 3 │ create table foo.t(c int);
2519 │ ─ 2. destination
2520 4 │ create policy p on foo.t
2521 5 │ with check (foo.t.c > 1);
2522 ╰╴ ─ 1. source
2523 ");
2524 }
2525
2526 #[test]
2527 fn goto_create_policy_unqualified_table_with_schema_on_table() {
2528 assert_snapshot!(goto("
2529create schema foo;
2530create table foo.t(c int);
2531create policy p on foo.t
2532 with check (t$0.c > 1);
2533"), @r"
2534 ╭▸
2535 3 │ create table foo.t(c int);
2536 │ ─ 2. destination
2537 4 │ create policy p on foo.t
2538 5 │ with check (t.c > 1);
2539 ╰╴ ─ 1. source
2540 ");
2541 }
2542
2543 #[test]
2544 fn goto_drop_event_trigger() {
2545 assert_snapshot!(goto("
2546create event trigger et on ddl_command_start execute function f();
2547drop event trigger et$0;
2548"), @r"
2549 ╭▸
2550 2 │ create event trigger et on ddl_command_start execute function f();
2551 │ ── 2. destination
2552 3 │ drop event trigger et;
2553 ╰╴ ─ 1. source
2554 ");
2555 }
2556
2557 #[test]
2558 fn goto_alter_event_trigger() {
2559 assert_snapshot!(goto("
2560create event trigger et on ddl_command_start execute function f();
2561alter event trigger et$0 disable;
2562"), @r"
2563 ╭▸
2564 2 │ create event trigger et on ddl_command_start execute function f();
2565 │ ── 2. destination
2566 3 │ alter event trigger et disable;
2567 ╰╴ ─ 1. source
2568 ");
2569 }
2570
2571 #[test]
2572 fn goto_create_event_trigger_function() {
2573 assert_snapshot!(goto("
2574create function f() returns event_trigger as 'select 1' language sql;
2575create event trigger et on ddl_command_start execute function f$0();
2576"), @r"
2577 ╭▸
2578 2 │ create function f() returns event_trigger as 'select 1' language sql;
2579 │ ─ 2. destination
2580 3 │ create event trigger et on ddl_command_start execute function f();
2581 ╰╴ ─ 1. source
2582 ");
2583 }
2584
2585 #[test]
2586 fn goto_create_event_trigger_procedure() {
2587 assert_snapshot!(goto("
2588create function p() returns event_trigger language sql as 'select 1';
2589create event trigger tr
2590 on ddl_command_end
2591 execute procedure p$0();
2592"), @"
2593 ╭▸
2594 2 │ create function p() returns event_trigger language sql as 'select 1';
2595 │ ─ 2. destination
2596 ‡
2597 5 │ execute procedure p();
2598 ╰╴ ─ 1. source
2599 ");
2600 }
2601
2602 #[test]
2603 fn goto_create_trigger_function() {
2604 assert_snapshot!(goto("
2605create function f() returns trigger as 'select 1' language sql;
2606create trigger tr before insert on t for each row execute function f$0();
2607"), @r"
2608 ╭▸
2609 2 │ create function f() returns trigger as 'select 1' language sql;
2610 │ ─ 2. destination
2611 3 │ create trigger tr before insert on t for each row execute function f();
2612 ╰╴ ─ 1. source
2613 ");
2614 }
2615
2616 #[test]
2617 fn goto_create_trigger_procedure() {
2618 assert_snapshot!(goto("
2619create function a() returns trigger language sql as 'select 1';
2620create trigger tr before truncate or delete or insert
2621on t
2622execute procedure a$0();
2623"), @"
2624 ╭▸
2625 2 │ create function a() returns trigger language sql as 'select 1';
2626 │ ─ 2. destination
2627 ‡
2628 5 │ execute procedure a();
2629 ╰╴ ─ 1. source
2630 ");
2631 }
2632
2633 #[test]
2634 fn goto_drop_trigger_table_specific() {
2635 assert_snapshot!(goto("
2636create table u(a int);
2637create trigger tr before truncate
2638on u
2639execute function noop();
2640
2641create table t(b int);
2642create trigger tr before truncate
2643on t
2644execute function noop();
2645
2646drop trigger tr$0 on t;
2647"), @r"
2648 ╭▸
2649 8 │ create trigger tr before truncate
2650 │ ── 2. destination
2651 ‡
2652 12 │ drop trigger tr on t;
2653 ╰╴ ─ 1. source
2654 ");
2655 }
2656
2657 #[test]
2658 fn goto_create_trigger_table() {
2659 assert_snapshot!(goto("
2660create table t(b int);
2661create trigger tr before truncate
2662on t$0
2663execute function noop();
2664"), @r"
2665 ╭▸
2666 2 │ create table t(b int);
2667 │ ─ 2. destination
2668 3 │ create trigger tr before truncate
2669 4 │ on t
2670 ╰╴ ─ 1. source
2671 ");
2672 }
2673
2674 #[test]
2675 fn goto_create_constraint_trigger_from_table() {
2676 assert_snapshot!(goto("
2677create table t(id int);
2678create table ref_t(id int);
2679create constraint trigger trg after insert on t from ref_t$0 for each row execute function f();
2680"), @"
2681 ╭▸
2682 3 │ create table ref_t(id int);
2683 │ ───── 2. destination
2684 4 │ create constraint trigger trg after insert on t from ref_t for each row execute function f();
2685 ╰╴ ─ 1. source
2686 ");
2687 }
2688
2689 #[test]
2690 fn goto_create_trigger_when_new_column() {
2691 assert_snapshot!(goto("
2692create table foo (id int);
2693create trigger tr before insert on foo for each row when (new.id$0 > 0) execute function f();
2694"), @"
2695 ╭▸
2696 2 │ create table foo (id int);
2697 │ ── 2. destination
2698 3 │ create trigger tr before insert on foo for each row when (new.id > 0) execute function f();
2699 ╰╴ ─ 1. source
2700 ");
2701 }
2702
2703 #[test]
2704 fn goto_create_trigger_when_old_column() {
2705 assert_snapshot!(goto("
2706create table foo (id int);
2707create trigger tr after update on foo for each row when (old.id$0 > 0) execute function f();
2708"), @"
2709 ╭▸
2710 2 │ create table foo (id int);
2711 │ ── 2. destination
2712 3 │ create trigger tr after update on foo for each row when (old.id > 0) execute function f();
2713 ╰╴ ─ 1. source
2714 ");
2715 }
2716
2717 #[test]
2718 fn goto_create_trigger_when_new_table() {
2719 assert_snapshot!(goto("
2720create table foo (id int);
2721create trigger tr before insert on foo for each row when (new$0.id > 0) execute function f();
2722"), @"
2723 ╭▸
2724 2 │ create table foo (id int);
2725 │ ─── 2. destination
2726 3 │ create trigger tr before insert on foo for each row when (new.id > 0) execute function f();
2727 ╰╴ ─ 1. source
2728 ");
2729 }
2730
2731 #[test]
2732 fn goto_create_rule_old_column() {
2733 assert_snapshot!(goto("
2734create table t(id int);
2735create rule r as on update to t where old.id$0 = new.id do instead nothing;
2736"), @"
2737 ╭▸
2738 2 │ create table t(id int);
2739 │ ── 2. destination
2740 3 │ create rule r as on update to t where old.id = new.id do instead nothing;
2741 ╰╴ ─ 1. source
2742 ");
2743 }
2744
2745 #[test]
2746 fn goto_create_rule_new_column() {
2747 assert_snapshot!(goto("
2748create table t(id int);
2749create rule r as on update to t where old.id = new.id$0 do instead nothing;
2750"), @"
2751 ╭▸
2752 2 │ create table t(id int);
2753 │ ── 2. destination
2754 3 │ create rule r as on update to t where old.id = new.id do instead nothing;
2755 ╰╴ ─ 1. source
2756 ");
2757 }
2758
2759 #[test]
2760 fn goto_create_rule_old_table() {
2761 assert_snapshot!(goto("
2762create table t(id int);
2763create rule r as on update to t where old$0.id = new.id do instead nothing;
2764"), @"
2765 ╭▸
2766 2 │ create table t(id int);
2767 │ ─ 2. destination
2768 3 │ create rule r as on update to t where old.id = new.id do instead nothing;
2769 ╰╴ ─ 1. source
2770 ");
2771 }
2772
2773 #[test]
2774 fn goto_create_trigger_update_of_column() {
2775 assert_snapshot!(goto("
2776create table t(id int, updated_at timestamptz);
2777create trigger tr before update of updated_at$0 on t for each row execute function f();
2778"), @"
2779 ╭▸
2780 2 │ create table t(id int, updated_at timestamptz);
2781 │ ────────── 2. destination
2782 3 │ create trigger tr before update of updated_at on t for each row execute function f();
2783 ╰╴ ─ 1. source
2784 ");
2785 }
2786
2787 #[test]
2788 fn goto_create_sequence_owned_by() {
2789 assert_snapshot!(goto("
2790create table t(c serial);
2791create sequence s
2792 owned by t.c$0;
2793"), @r"
2794 ╭▸
2795 2 │ create table t(c serial);
2796 │ ─ 2. destination
2797 3 │ create sequence s
2798 4 │ owned by t.c;
2799 ╰╴ ─ 1. source
2800 ");
2801 }
2802
2803 #[test]
2804 fn goto_create_sequence_owned_by_table() {
2805 assert_snapshot!(goto("
2806create table t(c serial);
2807create sequence s
2808 owned by t$0.c;
2809"), @"
2810 ╭▸
2811 2 │ create table t(c serial);
2812 │ ─ 2. destination
2813 3 │ create sequence s
2814 4 │ owned by t.c;
2815 ╰╴ ─ 1. source
2816 ");
2817 }
2818
2819 #[test]
2820 fn goto_alter_sequence_owned_by_table() {
2821 assert_snapshot!(goto("
2822create table t(c serial);
2823create sequence s;
2824alter sequence s owned by t$0.c;
2825"), @"
2826 ╭▸
2827 2 │ create table t(c serial);
2828 │ ─ 2. destination
2829 3 │ create sequence s;
2830 4 │ alter sequence s owned by t.c;
2831 ╰╴ ─ 1. source
2832 ");
2833 }
2834
2835 #[test]
2836 fn goto_drop_tablespace() {
2837 assert_snapshot!(goto("
2838create tablespace ts location '/tmp/ts';
2839drop tablespace ts$0;
2840"), @r"
2841 ╭▸
2842 2 │ create tablespace ts location '/tmp/ts';
2843 │ ── 2. destination
2844 3 │ drop tablespace ts;
2845 ╰╴ ─ 1. source
2846 ");
2847 }
2848
2849 #[test]
2850 fn goto_create_table_tablespace() {
2851 assert_snapshot!(goto("
2852create tablespace bar location '/tmp/ts';
2853create table t (a int) tablespace b$0ar;
2854"), @r"
2855 ╭▸
2856 2 │ create tablespace bar location '/tmp/ts';
2857 │ ─── 2. destination
2858 3 │ create table t (a int) tablespace bar;
2859 ╰╴ ─ 1. source
2860 ");
2861 }
2862
2863 #[test]
2864 fn goto_drop_database() {
2865 assert_snapshot!(goto("
2866create database mydb;
2867drop database my$0db;
2868"), @r"
2869 ╭▸
2870 2 │ create database mydb;
2871 │ ──── 2. destination
2872 3 │ drop database mydb;
2873 ╰╴ ─ 1. source
2874 ");
2875 }
2876
2877 #[test]
2878 fn goto_drop_role() {
2879 assert_snapshot!(goto("
2880create role reader;
2881drop role read$0er;
2882"), @r"
2883 ╭▸
2884 2 │ create role reader;
2885 │ ────── 2. destination
2886 3 │ drop role reader;
2887 ╰╴ ─ 1. source
2888 ");
2889 }
2890
2891 #[test]
2892 fn goto_alter_role() {
2893 assert_snapshot!(goto("
2894create role reader;
2895alter role read$0er rename to writer;
2896"), @r"
2897 ╭▸
2898 2 │ create role reader;
2899 │ ────── 2. destination
2900 3 │ alter role reader rename to writer;
2901 ╰╴ ─ 1. source
2902 ");
2903 }
2904
2905 #[test]
2906 fn goto_set_role() {
2907 assert_snapshot!(goto("
2908create role reader;
2909set role read$0er;
2910"), @r"
2911 ╭▸
2912 2 │ create role reader;
2913 │ ────── 2. destination
2914 3 │ set role reader;
2915 ╰╴ ─ 1. source
2916 ");
2917 }
2918
2919 #[test]
2920 fn goto_create_tablespace_owner_role() {
2921 assert_snapshot!(goto("
2922create role reader;
2923create tablespace t owner read$0er location 'foo';
2924"), @r"
2925 ╭▸
2926 2 │ create role reader;
2927 │ ────── 2. destination
2928 3 │ create tablespace t owner reader location 'foo';
2929 ╰╴ ─ 1. source
2930 ");
2931 }
2932
2933 #[test]
2934 fn goto_role_definition_returns_self() {
2935 assert_snapshot!(goto("
2936create role read$0er;
2937"), @r"
2938 ╭▸
2939 2 │ create role reader;
2940 │ ┬──┬──
2941 │ │ │
2942 │ │ 1. source
2943 ╰╴ 2. destination
2944 ");
2945 }
2946
2947 #[test]
2948 fn goto_drop_database_defined_after() {
2949 assert_snapshot!(goto("
2950drop database my$0db;
2951create database mydb;
2952"), @r"
2953 ╭▸
2954 2 │ drop database mydb;
2955 │ ─ 1. source
2956 3 │ create database mydb;
2957 ╰╴ ──── 2. destination
2958 ");
2959 }
2960
2961 #[test]
2962 fn goto_database_definition_returns_self() {
2963 assert_snapshot!(goto("
2964create database my$0db;
2965"), @r"
2966 ╭▸
2967 2 │ create database mydb;
2968 │ ┬┬──
2969 │ ││
2970 │ │1. source
2971 ╰╴ 2. destination
2972 ");
2973 }
2974
2975 #[test]
2976 fn goto_drop_server() {
2977 assert_snapshot!(goto("
2978create server myserver foreign data wrapper fdw;
2979drop server my$0server;
2980"), @r"
2981 ╭▸
2982 2 │ create server myserver foreign data wrapper fdw;
2983 │ ──────── 2. destination
2984 3 │ drop server myserver;
2985 ╰╴ ─ 1. source
2986 ");
2987 }
2988
2989 #[test]
2990 fn goto_drop_server_defined_after() {
2991 assert_snapshot!(goto("
2992drop server my$0server;
2993create server myserver foreign data wrapper fdw;
2994"), @r"
2995 ╭▸
2996 2 │ drop server myserver;
2997 │ ─ 1. source
2998 3 │ create server myserver foreign data wrapper fdw;
2999 ╰╴ ──────── 2. destination
3000 ");
3001 }
3002
3003 #[test]
3004 fn goto_alter_server() {
3005 assert_snapshot!(goto("
3006create server myserver foreign data wrapper fdw;
3007alter server my$0server options (add foo 'bar');
3008"), @r"
3009 ╭▸
3010 2 │ create server myserver foreign data wrapper fdw;
3011 │ ──────── 2. destination
3012 3 │ alter server myserver options (add foo 'bar');
3013 ╰╴ ─ 1. source
3014 ");
3015 }
3016
3017 #[test]
3018 fn goto_server_definition_returns_self() {
3019 assert_snapshot!(goto("
3020create server my$0server foreign data wrapper fdw;
3021"), @r"
3022 ╭▸
3023 2 │ create server myserver foreign data wrapper fdw;
3024 │ ┬┬──────
3025 │ ││
3026 │ │1. source
3027 ╰╴ 2. destination
3028 ");
3029 }
3030
3031 #[test]
3032 fn goto_drop_extension() {
3033 assert_snapshot!(goto("
3034create extension myext;
3035drop extension my$0ext;
3036"), @r"
3037 ╭▸
3038 2 │ create extension myext;
3039 │ ───── 2. destination
3040 3 │ drop extension myext;
3041 ╰╴ ─ 1. source
3042 ");
3043 }
3044
3045 #[test]
3046 fn goto_drop_extension_defined_after() {
3047 assert_snapshot!(goto("
3048drop extension my$0ext;
3049create extension myext;
3050"), @r"
3051 ╭▸
3052 2 │ drop extension myext;
3053 │ ─ 1. source
3054 3 │ create extension myext;
3055 ╰╴ ───── 2. destination
3056 ");
3057 }
3058
3059 #[test]
3060 fn goto_alter_extension() {
3061 assert_snapshot!(goto("
3062create extension myext;
3063alter extension my$0ext update to '2.0';
3064"), @r"
3065 ╭▸
3066 2 │ create extension myext;
3067 │ ───── 2. destination
3068 3 │ alter extension myext update to '2.0';
3069 ╰╴ ─ 1. source
3070 ");
3071 }
3072
3073 #[test]
3074 fn goto_create_extension_with_schema() {
3075 assert_snapshot!(goto("
3076create schema ext_schema;
3077create extension hstore with schema ext_sche$0ma;
3078"), @"
3079 ╭▸
3080 2 │ create schema ext_schema;
3081 │ ────────── 2. destination
3082 3 │ create extension hstore with schema ext_schema;
3083 ╰╴ ─ 1. source
3084 ");
3085 }
3086
3087 #[test]
3088 fn goto_alter_extension_add_table() {
3089 assert_snapshot!(goto("
3090create extension e;
3091create table t(id int);
3092alter extension e add table t$0;
3093"), @"
3094 ╭▸
3095 3 │ create table t(id int);
3096 │ ─ 2. destination
3097 4 │ alter extension e add table t;
3098 ╰╴ ─ 1. source
3099 ");
3100 }
3101
3102 #[test]
3103 fn goto_alter_extension_add_foreign_table() {
3104 assert_snapshot!(goto("
3105create extension e;
3106create foreign table t(id int) server s;
3107alter extension e add foreign table t$0;
3108"), @"
3109 ╭▸
3110 3 │ create foreign table t(id int) server s;
3111 │ ─ 2. destination
3112 4 │ alter extension e add foreign table t;
3113 ╰╴ ─ 1. source
3114 ");
3115 }
3116
3117 #[test]
3118 fn goto_alter_default_privileges_in_schema() {
3119 assert_snapshot!(goto("
3120create schema myschema;
3121create role bob;
3122alter default privileges in schema myschema$0
3123 grant select on tables to bob;
3124"), @"
3125 ╭▸
3126 2 │ create schema myschema;
3127 │ ──────── 2. destination
3128 3 │ create role bob;
3129 4 │ alter default privileges in schema myschema
3130 ╰╴ ─ 1. source
3131 ");
3132 }
3133
3134 #[test]
3135 fn goto_alter_publication() {
3136 assert_snapshot!(goto("
3137create table t(id int);
3138create publication pub for table t;
3139alter publication pub$0 add table t;
3140"), @"
3141 ╭▸
3142 3 │ create publication pub for table t;
3143 │ ─── 2. destination
3144 4 │ alter publication pub add table t;
3145 ╰╴ ─ 1. source
3146 ");
3147 }
3148
3149 #[test]
3150 fn goto_alter_subscription() {
3151 assert_snapshot!(goto("
3152create subscription sub connection $$host=localhost$$ publication pub;
3153alter subscription sub$0 refresh publication;
3154"), @"
3155 ╭▸
3156 2 │ create subscription sub connection $$host=localhost$$ publication pub;
3157 │ ─── 2. destination
3158 3 │ alter subscription sub refresh publication;
3159 ╰╴ ─ 1. source
3160 ");
3161 }
3162
3163 #[test]
3164 fn goto_drop_language() {
3165 assert_snapshot!(goto("
3166create language plpythonu;
3167drop language plpythonu$0;
3168"), @"
3169 ╭▸
3170 2 │ create language plpythonu;
3171 │ ───────── 2. destination
3172 3 │ drop language plpythonu;
3173 ╰╴ ─ 1. source
3174 ");
3175 }
3176
3177 #[test]
3178 fn goto_create_function_language_option() {
3179 assert_snapshot!(goto("
3180create language mylang;
3181create function f() returns int language mylang$0 as $$x$$;
3182"), @"
3183 ╭▸
3184 2 │ create language mylang;
3185 │ ────── 2. destination
3186 3 │ create function f() returns int language mylang as $$x$$;
3187 ╰╴ ─ 1. source
3188 ");
3189 }
3190
3191 #[test]
3192 fn goto_create_procedure_language_option() {
3193 assert_snapshot!(goto("
3194create language mylang;
3195create procedure p() language mylang$0 as $$x$$;
3196"), @"
3197 ╭▸
3198 2 │ create language mylang;
3199 │ ────── 2. destination
3200 3 │ create procedure p() language mylang as $$x$$;
3201 ╰╴ ─ 1. source
3202 ");
3203 }
3204
3205 #[test]
3206 fn goto_create_function_support_option() {
3207 assert_snapshot!(goto("
3208create function sf(internal) returns internal language c as $$x$$;
3209create function f(int) returns int language sql support sf$0 as $$select 1$$;
3210"), @"
3211 ╭▸
3212 2 │ create function sf(internal) returns internal language c as $$x$$;
3213 │ ── 2. destination
3214 3 │ create function f(int) returns int language sql support sf as $$select 1$$;
3215 ╰╴ ─ 1. source
3216 ");
3217 }
3218
3219 #[test]
3220 fn goto_create_transform_language_option() {
3221 assert_snapshot!(goto("
3222create language mylang;
3223create type typ as (x int);
3224create transform for typ language mylang$0
3225 (from sql with function int4(typ));
3226"), @"
3227 ╭▸
3228 2 │ create language mylang;
3229 │ ────── 2. destination
3230 3 │ create type typ as (x int);
3231 4 │ create transform for typ language mylang
3232 ╰╴ ─ 1. source
3233 ");
3234 }
3235
3236 #[test]
3237 fn goto_collate_in_column() {
3238 assert_snapshot!(goto("
3239create collation mycoll (locale = 'C');
3240create table t(name text collate mycoll$0);
3241"), @"
3242 ╭▸
3243 2 │ create collation mycoll (locale = 'C');
3244 │ ────── 2. destination
3245 3 │ create table t(name text collate mycoll);
3246 ╰╴ ─ 1. source
3247 ");
3248 }
3249
3250 #[test]
3251 fn goto_collate_in_order_by() {
3252 assert_snapshot!(goto("
3253create collation c from \"C\";
3254create table t(a text);
3255select a from t order by a collate c$0;
3256"), @r#"
3257 ╭▸
3258 2 │ create collation c from "C";
3259 │ ─ 2. destination
3260 3 │ create table t(a text);
3261 4 │ select a from t order by a collate c;
3262 ╰╴ ─ 1. source
3263 "#);
3264 }
3265
3266 #[test]
3267 fn goto_collate_in_index_expr() {
3268 assert_snapshot!(goto("
3269create collation c from \"C\";
3270create table t(a text);
3271create index idx on t (a collate c$0);
3272"), @r#"
3273 ╭▸
3274 2 │ create collation c from "C";
3275 │ ─ 2. destination
3276 3 │ create table t(a text);
3277 4 │ create index idx on t (a collate c);
3278 ╰╴ ─ 1. source
3279 "#);
3280 }
3281
3282 #[test]
3283 fn goto_create_collation_from() {
3284 assert_snapshot!(goto("
3285create collation c1 (locale = 'C');
3286create collation c2 from c1$0;
3287"), @"
3288 ╭▸
3289 2 │ create collation c1 (locale = 'C');
3290 │ ── 2. destination
3291 3 │ create collation c2 from c1;
3292 ╰╴ ─ 1. source
3293 ");
3294 }
3295
3296 #[test]
3297 fn goto_create_server_foreign_data_wrapper() {
3298 assert_snapshot!(goto("
3299create foreign data wrapper fdw;
3300create server srv foreign data wrapper fdw$0;
3301"), @"
3302 ╭▸
3303 2 │ create foreign data wrapper fdw;
3304 │ ─── 2. destination
3305 3 │ create server srv foreign data wrapper fdw;
3306 ╰╴ ─ 1. source
3307 ");
3308 }
3309
3310 #[test]
3311 fn goto_alter_sequence() {
3312 assert_snapshot!(goto("
3313create sequence s;
3314alter sequence s$0 restart with 1;
3315"), @"
3316 ╭▸
3317 2 │ create sequence s;
3318 │ ─ 2. destination
3319 3 │ alter sequence s restart with 1;
3320 ╰╴ ─ 1. source
3321 ");
3322 }
3323
3324 #[test]
3325 fn goto_alter_view() {
3326 assert_snapshot!(goto("
3327create view v as select 1 as id;
3328alter view v$0 rename to v2;
3329"), @"
3330 ╭▸
3331 2 │ create view v as select 1 as id;
3332 │ ─ 2. destination
3333 3 │ alter view v rename to v2;
3334 ╰╴ ─ 1. source
3335 ");
3336 }
3337
3338 #[test]
3339 fn goto_alter_materialized_view() {
3340 assert_snapshot!(goto("
3341create materialized view mv as select 1 as id;
3342alter materialized view mv$0 rename to mv2;
3343"), @"
3344 ╭▸
3345 2 │ create materialized view mv as select 1 as id;
3346 │ ── 2. destination
3347 3 │ alter materialized view mv rename to mv2;
3348 ╰╴ ─ 1. source
3349 ");
3350 }
3351
3352 #[test]
3353 fn goto_alter_type() {
3354 assert_snapshot!(goto("
3355create type address as (city text);
3356alter type address$0 add attribute zip text;
3357"), @"
3358 ╭▸
3359 2 │ create type address as (city text);
3360 │ ─────── 2. destination
3361 3 │ alter type address add attribute zip text;
3362 ╰╴ ─ 1. source
3363 ");
3364 }
3365
3366 #[test]
3367 fn goto_alter_domain() {
3368 assert_snapshot!(goto("
3369create domain email as text;
3370alter domain email$0 set not null;
3371"), @"
3372 ╭▸
3373 2 │ create domain email as text;
3374 │ ───── 2. destination
3375 3 │ alter domain email set not null;
3376 ╰╴ ─ 1. source
3377 ");
3378 }
3379
3380 #[test]
3381 fn goto_alter_function() {
3382 assert_snapshot!(goto("
3383create function f(a int) returns int language sql as $$ select a $$;
3384alter function f$0(int) owner to me;
3385"), @"
3386 ╭▸
3387 2 │ create function f(a int) returns int language sql as $$ select a $$;
3388 │ ─ 2. destination
3389 3 │ alter function f(int) owner to me;
3390 ╰╴ ─ 1. source
3391 ");
3392 }
3393
3394 #[test]
3395 fn goto_alter_procedure() {
3396 assert_snapshot!(goto("
3397create procedure p(a int) language sql as $$ select 1 $$;
3398alter procedure p$0(int) rename to q;
3399"), @"
3400 ╭▸
3401 2 │ create procedure p(a int) language sql as $$ select 1 $$;
3402 │ ─ 2. destination
3403 3 │ alter procedure p(int) rename to q;
3404 ╰╴ ─ 1. source
3405 ");
3406 }
3407
3408 #[test]
3409 fn goto_alter_routine() {
3410 assert_snapshot!(goto("
3411create function f() returns int language sql as $$ select 1 $$;
3412alter routine f$0 rename to g;
3413"), @"
3414 ╭▸
3415 2 │ create function f() returns int language sql as $$ select 1 $$;
3416 │ ─ 2. destination
3417 3 │ alter routine f rename to g;
3418 ╰╴ ─ 1. source
3419 ");
3420 }
3421
3422 #[test]
3423 fn goto_alter_aggregate() {
3424 assert_snapshot!(goto("
3425create aggregate agg (int) (sfunc = f, stype = int8);
3426alter aggregate agg$0(int) rename to agg2;
3427"), @"
3428 ╭▸
3429 2 │ create aggregate agg (int) (sfunc = f, stype = int8);
3430 │ ─── 2. destination
3431 3 │ alter aggregate agg(int) rename to agg2;
3432 ╰╴ ─ 1. source
3433 ");
3434 }
3435
3436 #[test]
3437 fn goto_alter_index() {
3438 assert_snapshot!(goto("
3439create table t(id int);
3440create index idx on t(id);
3441alter index idx$0 rename to idx2;
3442"), @"
3443 ╭▸
3444 3 │ create index idx on t(id);
3445 │ ─── 2. destination
3446 4 │ alter index idx rename to idx2;
3447 ╰╴ ─ 1. source
3448 ");
3449 }
3450
3451 #[test]
3452 fn goto_alter_schema() {
3453 assert_snapshot!(goto("
3454create schema app;
3455alter schema app$0 rename to app2;
3456"), @"
3457 ╭▸
3458 2 │ create schema app;
3459 │ ─── 2. destination
3460 3 │ alter schema app rename to app2;
3461 ╰╴ ─ 1. source
3462 ");
3463 }
3464
3465 #[test]
3466 fn goto_create_schema_element_unqualified_table_ref() {
3467 assert_snapshot!(goto("
3468create schema app
3469 create table users(id int)
3470 create view v as
3471 select id from users$0;
3472"), @"
3473 ╭▸
3474 3 │ create table users(id int)
3475 │ ───── 2. destination
3476 4 │ create view v as
3477 5 │ select id from users;
3478 ╰╴ ─ 1. source
3479 ");
3480 }
3481
3482 #[test]
3483 fn goto_create_schema_element_unqualified_column_ref() {
3484 assert_snapshot!(goto("
3485create schema app
3486 create table users(id int)
3487 create view v as
3488 select id$0 from users;
3489"), @"
3490 ╭▸
3491 3 │ create table users(id int)
3492 │ ── 2. destination
3493 4 │ create view v as
3494 5 │ select id from users;
3495 ╰╴ ─ 1. source
3496 ");
3497 }
3498
3499 #[test]
3500 fn goto_alter_database() {
3501 assert_snapshot!(goto("
3502create database appdb;
3503alter database appdb$0 owner to alice;
3504"), @"
3505 ╭▸
3506 2 │ create database appdb;
3507 │ ───── 2. destination
3508 3 │ alter database appdb owner to alice;
3509 ╰╴ ─ 1. source
3510 ");
3511 }
3512
3513 #[test]
3514 fn goto_alter_tablespace() {
3515 assert_snapshot!(goto("
3516create tablespace fast location '/tmp/fast';
3517alter tablespace fast$0 rename to faster;
3518"), @"
3519 ╭▸
3520 2 │ create tablespace fast location '/tmp/fast';
3521 │ ──── 2. destination
3522 3 │ alter tablespace fast rename to faster;
3523 ╰╴ ─ 1. source
3524 ");
3525 }
3526
3527 #[test]
3528 fn goto_alter_trigger() {
3529 assert_snapshot!(goto("
3530create trigger trg before insert on t for each row execute function f();
3531alter trigger trg$0 on t rename to trg2;
3532"), @"
3533 ╭▸
3534 2 │ create trigger trg before insert on t for each row execute function f();
3535 │ ─── 2. destination
3536 3 │ alter trigger trg on t rename to trg2;
3537 ╰╴ ─ 1. source
3538 ");
3539 }
3540
3541 #[test]
3542 fn goto_alter_foreign_table() {
3543 assert_snapshot!(goto("
3544create foreign table ft(id int) server myserver;
3545alter foreign table ft$0 owner to alice;
3546"), @"
3547 ╭▸
3548 2 │ create foreign table ft(id int) server myserver;
3549 │ ── 2. destination
3550 3 │ alter foreign table ft owner to alice;
3551 ╰╴ ─ 1. source
3552 ");
3553 }
3554
3555 #[test]
3556 fn goto_extension_definition_returns_self() {
3557 assert_snapshot!(goto("
3558create extension my$0ext;
3559"), @r"
3560 ╭▸
3561 2 │ create extension myext;
3562 │ ┬┬───
3563 │ ││
3564 │ │1. source
3565 ╰╴ 2. destination
3566 ");
3567 }
3568
3569 #[test]
3570 fn goto_drop_sequence_with_schema() {
3571 assert_snapshot!(goto("
3572create sequence foo.s;
3573drop sequence foo.s$0;
3574"), @r"
3575 ╭▸
3576 2 │ create sequence foo.s;
3577 │ ─ 2. destination
3578 3 │ drop sequence foo.s;
3579 ╰╴ ─ 1. source
3580 ");
3581 }
3582
3583 #[test]
3584 fn goto_drop_table_with_schema() {
3585 assert_snapshot!(goto("
3586create table public.t();
3587drop table t$0;
3588"), @r"
3589 ╭▸
3590 2 │ create table public.t();
3591 │ ─ 2. destination
3592 3 │ drop table t;
3593 ╰╴ ─ 1. source
3594 ");
3595
3596 assert_snapshot!(goto("
3597create table foo.t();
3598drop table foo.t$0;
3599"), @r"
3600 ╭▸
3601 2 │ create table foo.t();
3602 │ ─ 2. destination
3603 3 │ drop table foo.t;
3604 ╰╴ ─ 1. source
3605 ");
3606
3607 goto_not_found(
3608 "
3609-- defaults to public schema
3610create table t();
3611drop table foo.t$0;
3612",
3613 );
3614 }
3615
3616 #[test]
3617 fn goto_drop_temp_table() {
3618 assert_snapshot!(goto("
3619create temp table t();
3620drop table t$0;
3621"), @r"
3622 ╭▸
3623 2 │ create temp table t();
3624 │ ─ 2. destination
3625 3 │ drop table t;
3626 ╰╴ ─ 1. source
3627 ");
3628 }
3629
3630 #[test]
3631 fn goto_drop_temporary_table() {
3632 assert_snapshot!(goto("
3633create temporary table t();
3634drop table t$0;
3635"), @r"
3636 ╭▸
3637 2 │ create temporary table t();
3638 │ ─ 2. destination
3639 3 │ drop table t;
3640 ╰╴ ─ 1. source
3641 ");
3642 }
3643
3644 #[test]
3645 fn goto_drop_temp_table_with_pg_temp_schema() {
3646 assert_snapshot!(goto("
3647create temp table t();
3648drop table pg_temp.t$0;
3649"), @r"
3650 ╭▸
3651 2 │ create temp table t();
3652 │ ─ 2. destination
3653 3 │ drop table pg_temp.t;
3654 ╰╴ ─ 1. source
3655 ");
3656 }
3657
3658 #[test]
3659 fn goto_table_definition_returns_self() {
3660 assert_snapshot!(goto("
3661create table t$0(x bigint, y bigint);
3662"), @r"
3663 ╭▸
3664 2 │ create table t(x bigint, y bigint);
3665 │ ┬
3666 │ │
3667 │ 2. destination
3668 ╰╴ 1. source
3669 ");
3670 }
3671
3672 #[test]
3673 fn goto_foreign_table_column() {
3674 assert_snapshot!(goto("
3675create foreign table ft(a int)
3676 server s;
3677
3678select a$0 from ft;
3679"), @r"
3680 ╭▸
3681 2 │ create foreign table ft(a int)
3682 │ ─ 2. destination
3683 ‡
3684 5 │ select a from ft;
3685 ╰╴ ─ 1. source
3686 ");
3687 }
3688
3689 #[test]
3690 fn goto_foreign_table_definition() {
3691 assert_snapshot!(goto("
3692create foreign table ft(a int)
3693 server s;
3694
3695select a from ft$0;
3696"), @r"
3697 ╭▸
3698 2 │ create foreign table ft(a int)
3699 │ ── 2. destination
3700 ‡
3701 5 │ select a from ft;
3702 ╰╴ ─ 1. source
3703 ");
3704 }
3705
3706 #[test]
3707 fn goto_foreign_table_server_name() {
3708 assert_snapshot!(goto("
3709create server myserver foreign data wrapper fdw;
3710create foreign table ft(a int)
3711 server my$0server;
3712"), @r"
3713 ╭▸
3714 2 │ create server myserver foreign data wrapper fdw;
3715 │ ──────── 2. destination
3716 3 │ create foreign table ft(a int)
3717 4 │ server myserver;
3718 ╰╴ ─ 1. source
3719 ");
3720 }
3721
3722 #[test]
3723 fn goto_foreign_table_server_name_defined_after() {
3724 assert_snapshot!(goto("
3725create foreign table ft(a int)
3726 server my$0server;
3727create server myserver foreign data wrapper fdw;
3728"), @r"
3729 ╭▸
3730 3 │ server myserver;
3731 │ ─ 1. source
3732 4 │ create server myserver foreign data wrapper fdw;
3733 ╰╴ ──────── 2. destination
3734 ");
3735 }
3736
3737 #[test]
3738 fn goto_user_mapping_server_name() {
3739 assert_snapshot!(goto("
3740create server myserver foreign data wrapper fdw;
3741create user mapping for current_user server my$0server;
3742"), @r"
3743 ╭▸
3744 2 │ create server myserver foreign data wrapper fdw;
3745 │ ──────── 2. destination
3746 3 │ create user mapping for current_user server myserver;
3747 ╰╴ ─ 1. source
3748 ");
3749 }
3750
3751 #[test]
3752 fn goto_foreign_key_references_table() {
3753 assert_snapshot!(goto("
3754create table foo(id int);
3755create table bar(
3756 id int,
3757 foo_id int,
3758 foreign key (foo_id) references foo$0(id)
3759);
3760"), @r"
3761 ╭▸
3762 2 │ create table foo(id int);
3763 │ ─── 2. destination
3764 ‡
3765 6 │ foreign key (foo_id) references foo(id)
3766 ╰╴ ─ 1. source
3767 ");
3768 }
3769
3770 #[test]
3771 fn goto_foreign_key_on_delete_set_null_column() {
3772 assert_snapshot!(goto("
3773create table users (
3774 user_id integer not null,
3775 primary key (user_id)
3776);
3777
3778create table posts (
3779 post_id integer not null,
3780 author_id integer,
3781 primary key (post_id),
3782 foreign key (author_id) references users on delete set null (author_id$0)
3783);
3784"), @r"
3785 ╭▸
3786 9 │ author_id integer,
3787 │ ───────── 2. destination
3788 10 │ primary key (post_id),
3789 11 │ foreign key (author_id) references users on delete set null (author_id)
3790 ╰╴ ─ 1. source
3791 ");
3792 }
3793
3794 #[test]
3795 fn goto_references_constraint_table() {
3796 assert_snapshot!(goto("
3797create table t (
3798 id serial primary key
3799);
3800
3801create table u (
3802 id serial primary key,
3803 t_id int references t$0
3804);
3805"), @r"
3806 ╭▸
3807 2 │ create table t (
3808 │ ─ 2. destination
3809 ‡
3810 8 │ t_id int references t
3811 ╰╴ ─ 1. source
3812 ");
3813 }
3814
3815 #[test]
3816 fn goto_references_constraint_column() {
3817 assert_snapshot!(goto("
3818create table t (
3819 id serial primary key
3820);
3821
3822create table u (
3823 id serial primary key,
3824 t_id int references t(id$0)
3825);
3826"), @r"
3827 ╭▸
3828 3 │ id serial primary key
3829 │ ── 2. destination
3830 ‡
3831 8 │ t_id int references t(id)
3832 ╰╴ ─ 1. source
3833 ");
3834 }
3835
3836 #[test]
3837 fn goto_foreign_key_references_column() {
3838 assert_snapshot!(goto("
3839create table foo(id int);
3840create table bar(
3841 id int,
3842 foo_id int,
3843 foreign key (foo_id) references foo(id$0)
3844);
3845"), @r"
3846 ╭▸
3847 2 │ create table foo(id int);
3848 │ ── 2. destination
3849 ‡
3850 6 │ foreign key (foo_id) references foo(id)
3851 ╰╴ ─ 1. source
3852 ");
3853 }
3854
3855 #[test]
3856 fn goto_foreign_key_local_column() {
3857 assert_snapshot!(goto("
3858create table bar(
3859 id int,
3860 foo_id int,
3861 foreign key (foo_id$0) references foo(id)
3862);
3863"), @r"
3864 ╭▸
3865 4 │ foo_id int,
3866 │ ────── 2. destination
3867 5 │ foreign key (foo_id) references foo(id)
3868 ╰╴ ─ 1. source
3869 ");
3870 }
3871
3872 #[test]
3873 fn goto_alter_table_foreign_key_local_column() {
3874 assert_snapshot!(goto("
3875create table t (
3876 id bigserial primary key
3877);
3878
3879create table u (
3880 id bigserial primary key,
3881 t_id bigint
3882);
3883
3884alter table u
3885 add constraint fooo_fkey
3886 foreign key (t_id$0) references t (id);
3887"), @r"
3888 ╭▸
3889 8 │ t_id bigint
3890 │ ──── 2. destination
3891 ‡
3892 13 │ foreign key (t_id) references t (id);
3893 ╰╴ ─ 1. source
3894 ");
3895 }
3896
3897 #[test]
3898 fn goto_check_constraint_column() {
3899 assert_snapshot!(goto("
3900create table t (
3901 b int check (b > 10),
3902 c int check (c$0 > 10) no inherit
3903);
3904"), @r"
3905 ╭▸
3906 4 │ c int check (c > 10) no inherit
3907 │ ┬ ─ 1. source
3908 │ │
3909 ╰╴ 2. destination
3910 ");
3911 }
3912
3913 #[test]
3914 fn goto_generated_column() {
3915 assert_snapshot!(goto("
3916create table t (
3917 a int,
3918 b int generated always as (
3919 a$0 * 2
3920 ) stored
3921);
3922"), @r"
3923 ╭▸
3924 3 │ a int,
3925 │ ─ 2. destination
3926 4 │ b int generated always as (
3927 5 │ a * 2
3928 ╰╴ ─ 1. source
3929 ");
3930 }
3931
3932 #[test]
3933 fn goto_generated_column_function_call() {
3934 assert_snapshot!(goto("
3935create function pg_catalog.lower(text) returns text
3936 language internal;
3937
3938create table articles (
3939 id serial primary key,
3940 title text not null,
3941 body text not null,
3942 title_lower text generated always as (
3943 lower$0(title)
3944 ) stored
3945);
3946"), @r"
3947 ╭▸
3948 2 │ create function pg_catalog.lower(text) returns text
3949 │ ───── 2. destination
3950 ‡
3951 10 │ lower(title)
3952 ╰╴ ─ 1. source
3953 ");
3954 }
3955
3956 #[test]
3957 fn goto_index_expr_function_call() {
3958 assert_snapshot!(goto("
3959create function lower(text) returns text language internal;
3960create table articles (
3961 id serial primary key,
3962 title text not null
3963);
3964create index on articles (lower$0(title));
3965"), @r"
3966 ╭▸
3967 2 │ create function lower(text) returns text language internal;
3968 │ ───── 2. destination
3969 ‡
3970 7 │ create index on articles (lower(title));
3971 ╰╴ ─ 1. source
3972 ");
3973 }
3974
3975 #[test]
3976 fn goto_exclude_constraint_expr_function_call() {
3977 assert_snapshot!(goto("
3978create function lower(text) returns text language internal;
3979create table articles (
3980 title text not null,
3981 exclude using btree (lower$0(title) with =)
3982);
3983"), @r"
3984 ╭▸
3985 2 │ create function lower(text) returns text language internal;
3986 │ ───── 2. destination
3987 ‡
3988 5 │ exclude using btree (lower(title) with =)
3989 ╰╴ ─ 1. source
3990 ");
3991 }
3992
3993 #[test]
3994 fn goto_partition_by_expr_function_call() {
3995 assert_snapshot!(goto("
3996create function lower(text) returns text language internal;
3997create table articles (
3998 id serial primary key,
3999 title text not null
4000) partition by range (lower$0(title));
4001"), @r"
4002 ╭▸
4003 2 │ create function lower(text) returns text language internal;
4004 │ ───── 2. destination
4005 ‡
4006 6 │ ) partition by range (lower(title));
4007 ╰╴ ─ 1. source
4008 ");
4009 }
4010
4011 #[test]
4012 fn goto_table_check_constraint_column() {
4013 assert_snapshot!(goto("
4014create table t (
4015 a int,
4016 b text,
4017 check (a$0 > b)
4018);
4019"), @r"
4020 ╭▸
4021 3 │ a int,
4022 │ ─ 2. destination
4023 4 │ b text,
4024 5 │ check (a > b)
4025 ╰╴ ─ 1. source
4026 ");
4027 }
4028
4029 #[test]
4030 fn goto_table_unique_constraint_column() {
4031 assert_snapshot!(goto("
4032create table t (
4033 a int,
4034 b text,
4035 unique (a$0)
4036);
4037"), @r"
4038 ╭▸
4039 3 │ a int,
4040 │ ─ 2. destination
4041 4 │ b text,
4042 5 │ unique (a)
4043 ╰╴ ─ 1. source
4044 ");
4045 }
4046
4047 #[test]
4048 fn goto_table_primary_key_constraint_column() {
4049 assert_snapshot!(goto("
4050create table t (
4051 id bigint generated always as identity,
4052 inserted_at timestamptz not null default now(),
4053 primary key (id, inserted_at$0)
4054);
4055"), @r"
4056 ╭▸
4057 4 │ inserted_at timestamptz not null default now(),
4058 │ ─────────── 2. destination
4059 5 │ primary key (id, inserted_at)
4060 ╰╴ ─ 1. source
4061 ");
4062 }
4063
4064 #[test]
4065 fn goto_table_not_null_constraint_column() {
4066 assert_snapshot!(goto("
4067create table t (
4068 id integer,
4069 name text,
4070 not null name$0
4071);
4072"), @r"
4073 ╭▸
4074 4 │ name text,
4075 │ ──── 2. destination
4076 5 │ not null name
4077 ╰╴ ─ 1. source
4078 ");
4079 }
4080
4081 #[test]
4082 fn goto_table_exclude_constraint_column() {
4083 assert_snapshot!(goto("
4084create table circles (
4085 c circle,
4086 exclude using gist (c$0 with &&)
4087);
4088"), @r"
4089 ╭▸
4090 3 │ c circle,
4091 │ ─ 2. destination
4092 4 │ exclude using gist (c with &&)
4093 ╰╴ ─ 1. source
4094 ");
4095 }
4096
4097 #[test]
4098 fn goto_table_exclude_constraint_include_column() {
4099 assert_snapshot!(goto("
4100create table t (
4101 a int,
4102 b text,
4103 exclude using btree ( a with > )
4104 include (a$0, b)
4105);
4106"), @r"
4107 ╭▸
4108 3 │ a int,
4109 │ ─ 2. destination
4110 ‡
4111 6 │ include (a, b)
4112 ╰╴ ─ 1. source
4113 ");
4114 }
4115
4116 #[test]
4117 fn goto_table_exclude_constraint_where_column() {
4118 assert_snapshot!(goto("
4119create table t (
4120 a int,
4121 b text,
4122 exclude using btree ( a with > )
4123 where ( a$0 > 10 and b like '%foo' )
4124);
4125"), @r"
4126 ╭▸
4127 3 │ a int,
4128 │ ─ 2. destination
4129 ‡
4130 6 │ where ( a > 10 and b like '%foo' )
4131 ╰╴ ─ 1. source
4132 ");
4133 }
4134
4135 #[test]
4136 fn goto_table_partition_by_column() {
4137 assert_snapshot!(goto("
4138create table t (
4139 id bigint generated always as identity,
4140 inserted_at timestamptz not null default now()
4141) partition by range (inserted_at$0);
4142"), @r"
4143 ╭▸
4144 4 │ inserted_at timestamptz not null default now()
4145 │ ─────────── 2. destination
4146 5 │ ) partition by range (inserted_at);
4147 ╰╴ ─ 1. source
4148 ");
4149 }
4150
4151 #[test]
4152 fn goto_table_partition_of_table() {
4153 assert_snapshot!(goto("
4154create table t ();
4155create table t_2026_01_02 partition of t$0
4156 for values from ('2026-01-02') to ('2026-01-03');
4157"), @r"
4158 ╭▸
4159 2 │ create table t ();
4160 │ ─ 2. destination
4161 3 │ create table t_2026_01_02 partition of t
4162 ╰╴ ─ 1. source
4163 ");
4164 }
4165
4166 #[test]
4167 fn goto_table_partition_of_cycle() {
4168 goto_not_found(
4169 "
4170create table part1 partition of part2
4171 for values from ('2026-01-02') to ('2026-01-03');
4172create table part2 partition of part1
4173 for values from ('2026-01-02') to ('2026-01-03');
4174select a$0 from part2;
4175",
4176 );
4177 }
4178
4179 #[test]
4180 fn goto_partition_table_column() {
4181 assert_snapshot!(goto("
4182create table part (
4183 a int,
4184 inserted_at timestamptz not null default now()
4185) partition by range (inserted_at);
4186create table part_2026_01_02 partition of part
4187 for values from ('2026-01-02') to ('2026-01-03');
4188select a$0 from part_2026_01_02;
4189"), @r"
4190 ╭▸
4191 3 │ a int,
4192 │ ─ 2. destination
4193 ‡
4194 8 │ select a from part_2026_01_02;
4195 ╰╴ ─ 1. source
4196 ");
4197 }
4198
4199 #[test]
4200 fn goto_partition_table_qualified_column() {
4201 assert_snapshot!(goto("
4202create table part (
4203 a int,
4204 inserted_at timestamptz not null default now()
4205) partition by range (inserted_at);
4206create table part_2026_01_02 partition of part
4207 for values from ('2026-01-02') to ('2026-01-03');
4208select part_2026_01_02.a$0 from part_2026_01_02;
4209"), @"
4210 ╭▸
4211 3 │ a int,
4212 │ ─ 2. destination
4213 ‡
4214 8 │ select part_2026_01_02.a from part_2026_01_02;
4215 ╰╴ ─ 1. source
4216 ");
4217 }
4218
4219 #[test]
4220 fn goto_partition_table_qualified_column_multi_level() {
4221 assert_snapshot!(goto("
4222create table p (a int) partition by list (a);
4223create table m partition of p for values in (1) partition by list (a);
4224create table c partition of m for values in (2);
4225select c.a$0 from c;
4226"), @"
4227 ╭▸
4228 2 │ create table p (a int) partition by list (a);
4229 │ ─ 2. destination
4230 ‡
4231 5 │ select c.a from c;
4232 ╰╴ ─ 1. source
4233 ");
4234 }
4235
4236 #[test]
4237 fn goto_alter_index_attach_partition() {
4238 assert_snapshot!(goto("
4239create table t (
4240 inserted_at timestamptz not null default now()
4241) partition by range (inserted_at);
4242create table part partition of t
4243 for values from ('2026-01-02') to ('2026-01-03');
4244create index parent_idx on t (inserted_at);
4245create index child_idx on part (inserted_at);
4246alter index parent_idx attach partition child_$0idx;
4247"), @"
4248 ╭▸
4249 8 │ create index child_idx on part (inserted_at);
4250 │ ───────── 2. destination
4251 9 │ alter index parent_idx attach partition child_idx;
4252 ╰╴ ─ 1. source
4253 ");
4254 }
4255
4256 #[test]
4257 fn goto_create_table_like_clause() {
4258 assert_snapshot!(goto("
4259create table large_data_table(a text);
4260create table t (
4261 a text,
4262 like large_data_table$0,
4263 b integer
4264);
4265"), @r"
4266 ╭▸
4267 2 │ create table large_data_table(a text);
4268 │ ──────────────── 2. destination
4269 ‡
4270 5 │ like large_data_table,
4271 ╰╴ ─ 1. source
4272 ");
4273 }
4274
4275 #[test]
4276 fn goto_create_table_like_view() {
4277 assert_snapshot!(goto("
4278create view v as select 1 a, 2 b;
4279create table t (like v);
4280select a$0 from t;
4281"), @"
4282 ╭▸
4283 2 │ create view v as select 1 a, 2 b;
4284 │ ─ 2. destination
4285 3 │ create table t (like v);
4286 4 │ select a from t;
4287 ╰╴ ─ 1. source
4288 ");
4289 }
4290
4291 #[test]
4292 fn goto_view_select_star_column_gap() {
4293 assert_snapshot!(goto("
4294create table t(a int, b int);
4295create view v as select * from t;
4296select a$0 from v;
4297"), @"
4298 ╭▸
4299 2 │ create table t(a int, b int);
4300 │ ─ 2. destination
4301 3 │ create view v as select * from t;
4302 4 │ select a from v;
4303 ╰╴ ─ 1. source
4304 ");
4305 }
4306
4307 #[test]
4308 fn goto_view_table_query_column_gap() {
4309 assert_snapshot!(goto("
4310create table t(a int);
4311create view v as table t;
4312select a$0 from v;
4313"), @"
4314 ╭▸
4315 2 │ create table t(a int);
4316 │ ─ 2. destination
4317 3 │ create view v as table t;
4318 4 │ select a from v;
4319 ╰╴ ─ 1. source
4320 ");
4321 }
4322
4323 #[test]
4324 fn goto_view_values_query_column_gap() {
4325 assert_snapshot!(goto("
4326create view v as values (1, 2);
4327select column2$0 from v;
4328"), @"
4329 ╭▸
4330 2 │ create view v as values (1, 2);
4331 │ ─ 2. destination
4332 3 │ select column2 from v;
4333 ╰╴ ─ 1. source
4334 ");
4335 }
4336
4337 #[test]
4338 fn goto_view_compound_table_query_column() {
4339 assert_snapshot!(goto("
4340create table t(a int);
4341create view v as table t union table t;
4342select a$0 from v;
4343"), @"
4344 ╭▸
4345 2 │ create table t(a int);
4346 │ ─ 2. destination
4347 3 │ create view v as table t union table t;
4348 4 │ select a from v;
4349 ╰╴ ─ 1. source
4350 ");
4351 }
4352
4353 #[test]
4354 fn goto_view_compound_values_query_column() {
4355 assert_snapshot!(goto("
4356create view v as values (1, 2) union values (3, 4);
4357select column2$0 from v;
4358"), @"
4359 ╭▸
4360 2 │ create view v as values (1, 2) union values (3, 4);
4361 │ ─ 2. destination
4362 3 │ select column2 from v;
4363 ╰╴ ─ 1. source
4364 ");
4365 }
4366
4367 #[test]
4368 fn goto_view_table_query_column_count_gap() {
4369 assert_snapshot!(goto("
4370create table t(a int, b int);
4371create view v as table t;
4372select b$0 from (select * from v) u(a);
4373"), @"
4374 ╭▸
4375 2 │ create table t(a int, b int);
4376 │ ─ 2. destination
4377 3 │ create view v as table t;
4378 4 │ select b from (select * from v) u(a);
4379 ╰╴ ─ 1. source
4380 ");
4381 }
4382
4383 #[test]
4384 fn goto_view_values_query_column_count_gap() {
4385 assert_snapshot!(goto("
4386create view v as values (1, 2);
4387select column2$0 from (select * from v) u(a);
4388"), @"
4389 ╭▸
4390 2 │ create view v as values (1, 2);
4391 │ ─ 2. destination
4392 3 │ select column2 from (select * from v) u(a);
4393 ╰╴ ─ 1. source
4394 ");
4395 }
4396
4397 #[test]
4398 fn goto_values_partial_alias_remaining_column_gap() {
4399 assert_snapshot!(goto("
4400select column2$0 from (values (1, 2)) v(a);
4401"), @"
4402 ╭▸
4403 2 │ select column2 from (values (1, 2)) v(a);
4404 ╰╴ ─ 1. source ─ 2. destination
4405 ");
4406 }
4407
4408 #[test]
4409 fn goto_create_table_inherits() {
4410 assert_snapshot!(goto("
4411create table bar(a int);
4412create table t (a int)
4413inherits (foo.bar, bar$0, buzz);
4414"), @r"
4415 ╭▸
4416 2 │ create table bar(a int);
4417 │ ─── 2. destination
4418 3 │ create table t (a int)
4419 4 │ inherits (foo.bar, bar, buzz);
4420 ╰╴ ─ 1. source
4421 ");
4422 }
4423
4424 #[test]
4425 fn goto_create_table_inherits_builtin() {
4426 assert_snapshot!(goto("
4427-- include-builtins
4428create table t ()
4429inherits (information_schema.sql_features);
4430select feature_name$0 from t;
4431"), @"
4432 ╭▸ current.sql:5:19
4433 │
4434 5 │ select feature_name from t;
4435 │ ─ 1. source
4436 ╰╴
4437
4438 ╭▸ builtins.sql:437:3
4439 │
4440 437 │ feature_name information_schema.character_data,
4441 ╰╴ ──────────── 2. destination
4442 ");
4443 }
4444
4445 #[test]
4446 fn goto_create_table_like_clause_columns() {
4447 assert_snapshot!(goto("
4448create table t(a int, b int);
4449create table u(like t, c int);
4450select a$0, c from u;
4451"), @r"
4452 ╭▸
4453 2 │ create table t(a int, b int);
4454 │ ─ 2. destination
4455 3 │ create table u(like t, c int);
4456 4 │ select a, c from u;
4457 ╰╴ ─ 1. source
4458 ");
4459 }
4460
4461 #[test]
4462 fn goto_create_table_like_clause_local_column() {
4463 assert_snapshot!(goto("
4464create table t(a int, b int);
4465create table u(like t, c int);
4466select a, c$0 from u;
4467"), @r"
4468 ╭▸
4469 3 │ create table u(like t, c int);
4470 │ ─ 2. destination
4471 4 │ select a, c from u;
4472 ╰╴ ─ 1. source
4473 ");
4474 }
4475
4476 #[test]
4477 fn goto_create_table_like_clause_multi() {
4478 assert_snapshot!(goto("
4479create table t(a int, b int);
4480create table u(x int, y int);
4481create table k(like t, like u, c int);
4482select y$0 from k;
4483"), @r"
4484 ╭▸
4485 3 │ create table u(x int, y int);
4486 │ ─ 2. destination
4487 4 │ create table k(like t, like u, c int);
4488 5 │ select y from k;
4489 ╰╴ ─ 1. source
4490 ");
4491 }
4492
4493 #[test]
4494 fn goto_create_table_inherits_column() {
4495 assert_snapshot!(goto("
4496create table t (
4497 a int, b text
4498);
4499create table u (
4500 c int
4501) inherits (t);
4502select a$0 from u;
4503"), @r"
4504 ╭▸
4505 3 │ a int, b text
4506 │ ─ 2. destination
4507 ‡
4508 8 │ select a from u;
4509 ╰╴ ─ 1. source
4510 ");
4511 }
4512
4513 #[test]
4514 fn goto_create_table_inherits_local_column() {
4515 assert_snapshot!(goto("
4516create table t (
4517 a int, b text
4518);
4519create table u (
4520 c int
4521) inherits (t);
4522select c$0 from u;
4523"), @r"
4524 ╭▸
4525 6 │ c int
4526 │ ─ 2. destination
4527 7 │ ) inherits (t);
4528 8 │ select c from u;
4529 ╰╴ ─ 1. source
4530 ");
4531 }
4532
4533 #[test]
4534 fn goto_create_table_inherits_multiple_parents() {
4535 assert_snapshot!(goto("
4536create table t1 (
4537 a int
4538);
4539create table t2 (
4540 b text
4541);
4542create table u (
4543 c int
4544) inherits (t1, t2);
4545select b$0 from u;
4546"), @r"
4547 ╭▸
4548 6 │ b text
4549 │ ─ 2. destination
4550 ‡
4551 11 │ select b from u;
4552 ╰╴ ─ 1. source
4553 ");
4554 }
4555
4556 #[test]
4557 fn goto_create_foreign_table_inherits_column() {
4558 assert_snapshot!(goto("
4559create server myserver foreign data wrapper postgres_fdw;
4560create table t (
4561 a int, b text
4562);
4563create foreign table u (
4564 c int
4565) inherits (t) server myserver;
4566select a$0 from u;
4567"), @r"
4568 ╭▸
4569 4 │ a int, b text
4570 │ ─ 2. destination
4571 ‡
4572 9 │ select a from u;
4573 ╰╴ ─ 1. source
4574 ");
4575 }
4576
4577 #[test]
4578 fn goto_drop_temp_table_shadows_public() {
4579 assert_snapshot!(goto("
4581create table t();
4582create temp table t();
4583drop table t$0;
4584"), @"
4585 ╭▸
4586 3 │ create temp table t();
4587 │ ─ 2. destination
4588 4 │ drop table t;
4589 ╰╴ ─ 1. source
4590 ");
4591 }
4592
4593 #[test]
4594 fn goto_drop_public_table_when_temp_exists() {
4595 assert_snapshot!(goto("
4597create table t();
4598create temp table t();
4599drop table public.t$0;
4600"), @r"
4601 ╭▸
4602 2 │ create table t();
4603 │ ─ 2. destination
4604 3 │ create temp table t();
4605 4 │ drop table public.t;
4606 ╰╴ ─ 1. source
4607 ");
4608 }
4609
4610 #[test]
4611 fn goto_drop_table_defined_after() {
4612 assert_snapshot!(goto("
4613drop table t$0;
4614create table t();
4615"), @r"
4616 ╭▸
4617 2 │ drop table t;
4618 │ ─ 1. source
4619 3 │ create table t();
4620 ╰╴ ─ 2. destination
4621 ");
4622 }
4623
4624 #[test]
4625 fn goto_drop_type() {
4626 assert_snapshot!(goto("
4627create type t as enum ('a', 'b');
4628drop type t$0;
4629"), @r"
4630 ╭▸
4631 2 │ create type t as enum ('a', 'b');
4632 │ ─ 2. destination
4633 3 │ drop type t;
4634 ╰╴ ─ 1. source
4635 ");
4636 }
4637
4638 #[test]
4639 fn goto_drop_type_with_schema() {
4640 assert_snapshot!(goto("
4641create type public.t as enum ('a', 'b');
4642drop type t$0;
4643"), @r"
4644 ╭▸
4645 2 │ create type public.t as enum ('a', 'b');
4646 │ ─ 2. destination
4647 3 │ drop type t;
4648 ╰╴ ─ 1. source
4649 ");
4650
4651 assert_snapshot!(goto("
4652create type foo.t as enum ('a', 'b');
4653drop type foo.t$0;
4654"), @r"
4655 ╭▸
4656 2 │ create type foo.t as enum ('a', 'b');
4657 │ ─ 2. destination
4658 3 │ drop type foo.t;
4659 ╰╴ ─ 1. source
4660 ");
4661
4662 goto_not_found(
4663 "
4664create type t as enum ('a', 'b');
4665drop type foo.t$0;
4666",
4667 );
4668 }
4669
4670 #[test]
4671 fn goto_drop_type_defined_after() {
4672 assert_snapshot!(goto("
4673drop type t$0;
4674create type t as enum ('a', 'b');
4675"), @r"
4676 ╭▸
4677 2 │ drop type t;
4678 │ ─ 1. source
4679 3 │ create type t as enum ('a', 'b');
4680 ╰╴ ─ 2. destination
4681 ");
4682 }
4683
4684 #[test]
4685 fn goto_drop_type_composite() {
4686 assert_snapshot!(goto("
4687create type person as (name text, age int);
4688drop type person$0;
4689"), @r"
4690 ╭▸
4691 2 │ create type person as (name text, age int);
4692 │ ────── 2. destination
4693 3 │ drop type person;
4694 ╰╴ ─ 1. source
4695 ");
4696 }
4697
4698 #[test]
4699 fn goto_create_table_type_reference() {
4700 assert_snapshot!(goto("
4701create type person_info as (name text, email text);
4702create table users(id int, member person_info$0);
4703"), @"
4704 ╭▸
4705 2 │ create type person_info as (name text, email text);
4706 │ ─────────── 2. destination
4707 3 │ create table users(id int, member person_info);
4708 ╰╴ ─ 1. source
4709 ");
4710 }
4711
4712 #[test]
4713 fn goto_function_param_table_type() {
4714 assert_snapshot!(goto("
4715create table t(a int, b int);
4716create function b(t$0) returns int as 'select 1' language sql;
4717"), @r"
4718 ╭▸
4719 2 │ create table t(a int, b int);
4720 │ ─ 2. destination
4721 3 │ create function b(t) returns int as 'select 1' language sql;
4722 ╰╴ ─ 1. source
4723 ");
4724 }
4725
4726 #[test]
4727 fn goto_function_param_time_type() {
4728 assert_snapshot!(goto("
4729create type timestamp;
4730create function f(timestamp$0 without time zone) returns text language internal;
4731"), @r"
4732 ╭▸
4733 2 │ create type timestamp;
4734 │ ───────── 2. destination
4735 3 │ create function f(timestamp without time zone) returns text language internal;
4736 ╰╴ ─ 1. source
4737 ");
4738 }
4739
4740 #[test]
4741 fn goto_function_param_time_type_no_timezone() {
4742 assert_snapshot!(goto("
4743create type time;
4744create function f(time$0) returns text language internal;
4745"), @r"
4746 ╭▸
47472 │ create type time;
4748 │ ──── 2. destination
47493 │ create function f(time) returns text language internal;
4750 ╰╴ ─ 1. source
4751");
4752 }
4753
4754 #[test]
4755 fn goto_create_table_type_reference_enum() {
4756 assert_snapshot!(goto("
4757create type mood as enum ('sad', 'ok', 'happy');
4758create table users(id int, mood mood$0);
4759"), @r"
4760 ╭▸
4761 2 │ create type mood as enum ('sad', 'ok', 'happy');
4762 │ ──── 2. destination
4763 3 │ create table users(id int, mood mood);
4764 ╰╴ ─ 1. source
4765 ");
4766 }
4767
4768 #[test]
4769 fn goto_create_table_type_reference_range() {
4770 assert_snapshot!(goto("
4771create type int4_range as range (subtype = int4);
4772create table metrics(id int, span int4_range$0);
4773"), @r"
4774 ╭▸
4775 2 │ create type int4_range as range (subtype = int4);
4776 │ ────────── 2. destination
4777 3 │ create table metrics(id int, span int4_range);
4778 ╰╴ ─ 1. source
4779 ");
4780 }
4781
4782 #[test]
4783 fn goto_create_table_type_reference_input_output() {
4784 assert_snapshot!(goto("
4785create type myint (input = myintin, output = myintout, like = int4);
4786create table data(id int, value myint$0);
4787"), @r"
4788 ╭▸
4789 2 │ create type myint (input = myintin, output = myintout, like = int4);
4790 │ ───── 2. destination
4791 3 │ create table data(id int, value myint);
4792 ╰╴ ─ 1. source
4793 ");
4794 }
4795
4796 #[test]
4797 fn goto_composite_type_field() {
4798 assert_snapshot!(goto("
4799create type person_info as (name text, email text);
4800create table users(id int, member person_info);
4801select (member).name$0 from users;
4802"), @"
4803 ╭▸
4804 2 │ create type person_info as (name text, email text);
4805 │ ──── 2. destination
4806 3 │ create table users(id int, member person_info);
4807 4 │ select (member).name from users;
4808 ╰╴ ─ 1. source
4809 ");
4810 }
4811
4812 #[test]
4813 fn goto_alter_type_drop_attribute() {
4814 assert_snapshot!(goto("
4815create type address as (city text, zip text);
4816alter type address drop attribute city$0;
4817"), @"
4818 ╭▸
4819 2 │ create type address as (city text, zip text);
4820 │ ──── 2. destination
4821 3 │ alter type address drop attribute city;
4822 ╰╴ ─ 1. source
4823 ");
4824 }
4825
4826 #[test]
4827 fn goto_alter_type_rename_attribute() {
4828 assert_snapshot!(goto("
4829create type address as (city text, zip text);
4830alter type address rename attribute city$0 to town;
4831"), @"
4832 ╭▸
4833 2 │ create type address as (city text, zip text);
4834 │ ──── 2. destination
4835 3 │ alter type address rename attribute city to town;
4836 ╰╴ ─ 1. source
4837 ");
4838 }
4839
4840 #[test]
4841 fn goto_alter_type_alter_attribute() {
4842 assert_snapshot!(goto("
4843create type address as (city text, zip text);
4844alter type address alter attribute city$0 set data type varchar;
4845"), @"
4846 ╭▸
4847 2 │ create type address as (city text, zip text);
4848 │ ──── 2. destination
4849 3 │ alter type address alter attribute city set data type varchar;
4850 ╰╴ ─ 1. source
4851 ");
4852 }
4853
4854 #[test]
4855 fn goto_drop_type_range() {
4856 assert_snapshot!(goto("
4857create type int4_range as range (subtype = int4);
4858drop type int4_range$0;
4859"), @r"
4860 ╭▸
4861 2 │ create type int4_range as range (subtype = int4);
4862 │ ────────── 2. destination
4863 3 │ drop type int4_range;
4864 ╰╴ ─ 1. source
4865 ");
4866 }
4867
4868 #[test]
4869 fn goto_drop_domain() {
4870 assert_snapshot!(goto("
4871create domain posint as integer check (value > 0);
4872drop domain posint$0;
4873"), @r"
4874 ╭▸
4875 2 │ create domain posint as integer check (value > 0);
4876 │ ────── 2. destination
4877 3 │ drop domain posint;
4878 ╰╴ ─ 1. source
4879 ");
4880 }
4881
4882 #[test]
4883 fn goto_cast_to_domain() {
4884 assert_snapshot!(goto("
4885create domain posint as integer check (value > 0);
4886select 1::posint$0;
4887"), @r"
4888 ╭▸
4889 2 │ create domain posint as integer check (value > 0);
4890 │ ────── 2. destination
4891 3 │ select 1::posint;
4892 ╰╴ ─ 1. source
4893 ");
4894 }
4895
4896 #[test]
4897 fn goto_drop_type_domain() {
4898 assert_snapshot!(goto("
4899create domain posint as integer check (value > 0);
4900drop type posint$0;
4901"), @r"
4902 ╭▸
4903 2 │ create domain posint as integer check (value > 0);
4904 │ ────── 2. destination
4905 3 │ drop type posint;
4906 ╰╴ ─ 1. source
4907 ");
4908 }
4909
4910 #[test]
4911 fn goto_drop_view() {
4912 assert_snapshot!(goto("
4913create view v as select 1;
4914drop view v$0;
4915"), @r"
4916 ╭▸
4917 2 │ create view v as select 1;
4918 │ ─ 2. destination
4919 3 │ drop view v;
4920 ╰╴ ─ 1. source
4921 ");
4922 }
4923
4924 #[test]
4925 fn goto_drop_materialized_view() {
4926 assert_snapshot!(goto("
4927create materialized view v as select 1;
4928drop materialized view v$0;
4929"), @r"
4930 ╭▸
4931 2 │ create materialized view v as select 1;
4932 │ ─ 2. destination
4933 3 │ drop materialized view v;
4934 ╰╴ ─ 1. source
4935 ");
4936 }
4937
4938 #[test]
4939 fn goto_drop_view_with_schema() {
4940 assert_snapshot!(goto("
4941create view public.v as select 1;
4942drop view v$0;
4943"), @r"
4944 ╭▸
4945 2 │ create view public.v as select 1;
4946 │ ─ 2. destination
4947 3 │ drop view v;
4948 ╰╴ ─ 1. source
4949 ");
4950
4951 assert_snapshot!(goto("
4952create view foo.v as select 1;
4953drop view foo.v$0;
4954"), @r"
4955 ╭▸
4956 2 │ create view foo.v as select 1;
4957 │ ─ 2. destination
4958 3 │ drop view foo.v;
4959 ╰╴ ─ 1. source
4960 ");
4961
4962 goto_not_found(
4963 "
4964create view v as select 1;
4965drop view foo.v$0;
4966",
4967 );
4968 }
4969
4970 #[test]
4971 fn goto_drop_temp_view() {
4972 assert_snapshot!(goto("
4973create temp view v as select 1;
4974drop view v$0;
4975"), @r"
4976 ╭▸
4977 2 │ create temp view v as select 1;
4978 │ ─ 2. destination
4979 3 │ drop view v;
4980 ╰╴ ─ 1. source
4981 ");
4982 }
4983
4984 #[test]
4985 fn goto_select_from_view() {
4986 assert_snapshot!(goto("
4987create view v as select 1;
4988select * from v$0;
4989"), @r"
4990 ╭▸
4991 2 │ create view v as select 1;
4992 │ ─ 2. destination
4993 3 │ select * from v;
4994 ╰╴ ─ 1. source
4995 ");
4996 }
4997
4998 #[test]
4999 fn goto_select_from_materialized_view() {
5000 assert_snapshot!(goto("
5001create materialized view v as select 1;
5002select * from v$0;
5003"), @r"
5004 ╭▸
5005 2 │ create materialized view v as select 1;
5006 │ ─ 2. destination
5007 3 │ select * from v;
5008 ╰╴ ─ 1. source
5009 ");
5010 }
5011
5012 #[test]
5013 fn goto_select_from_view_with_schema() {
5014 assert_snapshot!(goto("
5015create view public.v as select 1;
5016select * from public.v$0;
5017"), @r"
5018 ╭▸
5019 2 │ create view public.v as select 1;
5020 │ ─ 2. destination
5021 3 │ select * from public.v;
5022 ╰╴ ─ 1. source
5023 ");
5024 }
5025
5026 #[test]
5027 fn goto_view_column() {
5028 assert_snapshot!(goto("
5029create view v as select 1 as a;
5030select a$0 from v;
5031"), @r"
5032 ╭▸
5033 2 │ create view v as select 1 as a;
5034 │ ─ 2. destination
5035 3 │ select a from v;
5036 ╰╴ ─ 1. source
5037 ");
5038 }
5039
5040 #[test]
5041 fn goto_view_column_qualified() {
5042 assert_snapshot!(goto("
5043create view v as select 1 as a;
5044select v.a$0 from v;
5045"), @r"
5046 ╭▸
5047 2 │ create view v as select 1 as a;
5048 │ ─ 2. destination
5049 3 │ select v.a from v;
5050 ╰╴ ─ 1. source
5051 ");
5052 }
5053
5054 #[test]
5055 fn goto_materialized_view_column_with_explicit_column_list() {
5056 assert_snapshot!(goto("
5057create materialized view mv (x, y) as select 1 as a, 2 as b;
5058select x$0 from mv;
5059"), @r"
5060 ╭▸
5061 2 │ create materialized view mv (x, y) as select 1 as a, 2 as b;
5062 │ ─ 2. destination
5063 3 │ select x from mv;
5064 ╰╴ ─ 1. source
5065 ");
5066 }
5067
5068 #[test]
5069 fn goto_view_table_qualifier() {
5070 assert_snapshot!(goto("
5071create view v as select 1 id, 2 b;
5072select v$0.id from v;
5073"), @"
5074 ╭▸
5075 2 │ create view v as select 1 id, 2 b;
5076 │ ─ 2. destination
5077 3 │ select v.id from v;
5078 ╰╴ ─ 1. source
5079 ");
5080 }
5081
5082 #[test]
5083 fn goto_select_into_column() {
5084 assert_snapshot!(goto("
5085select 1 a into t;
5086select a$0 from t;
5087"), @"
5088 ╭▸
5089 2 │ select 1 a into t;
5090 │ ─ 2. destination
5091 3 │ select a from t;
5092 ╰╴ ─ 1. source
5093 ");
5094 }
5095
5096 #[test]
5097 fn goto_select_into_table() {
5098 assert_snapshot!(goto("
5099select 1 a into t;
5100select a from t$0;
5101"), @"
5102 ╭▸
5103 2 │ select 1 a into t;
5104 │ ─ 2. destination
5105 3 │ select a from t;
5106 ╰╴ ─ 1. source
5107 ");
5108 }
5109
5110 #[test]
5111 fn goto_select_into_select_star() {
5112 assert_snapshot!(goto("
5113create table t(a bigint);
5114select * into u from t;
5115select a$0 from u;
5116"), @"
5117 ╭▸
5118 2 │ create table t(a bigint);
5119 │ ─ 2. destination
5120 3 │ select * into u from t;
5121 4 │ select a from u;
5122 ╰╴ ─ 1. source
5123 ");
5124 }
5125
5126 #[test]
5127 fn goto_select_into_source_table() {
5128 assert_snapshot!(goto("
5129create table t(a int);
5130select a into u from t$0;
5131"), @"
5132 ╭▸
5133 2 │ create table t(a int);
5134 │ ─ 2. destination
5135 3 │ select a into u from t;
5136 ╰╴ ─ 1. source
5137 ");
5138 }
5139
5140 #[test]
5141 fn goto_select_into_target_list_column() {
5142 assert_snapshot!(goto("
5143create table t(a int);
5144select a$0 into u from t;
5145"), @"
5146 ╭▸
5147 2 │ create table t(a int);
5148 │ ─ 2. destination
5149 3 │ select a into u from t;
5150 ╰╴ ─ 1. source
5151 ");
5152 }
5153
5154 #[test]
5155 fn goto_select_into_where_column() {
5156 assert_snapshot!(goto("
5157create table t(a int);
5158select a into u from t where a$0 > 0;
5159"), @"
5160 ╭▸
5161 2 │ create table t(a int);
5162 │ ─ 2. destination
5163 3 │ select a into u from t where a > 0;
5164 ╰╴ ─ 1. source
5165 ");
5166 }
5167
5168 #[test]
5169 fn goto_select_into_qualified_column() {
5170 assert_snapshot!(goto("
5171create table t(a int);
5172select t.a$0 into u from t;
5173"), @"
5174 ╭▸
5175 2 │ create table t(a int);
5176 │ ─ 2. destination
5177 3 │ select t.a into u from t;
5178 ╰╴ ─ 1. source
5179 ");
5180 }
5181
5182 #[test]
5183 fn goto_create_table_as_column() {
5184 assert_snapshot!(goto("
5185create table t as select 1 a;
5186select a$0 from t;
5187"), @r"
5188 ╭▸
5189 2 │ create table t as select 1 a;
5190 │ ─ 2. destination
5191 3 │ select a from t;
5192 ╰╴ ─ 1. source
5193 ");
5194 }
5195
5196 #[test]
5197 fn goto_create_table_as_table() {
5198 assert_snapshot!(goto("
5199create table t(a bigint);
5200create table u as table t;
5201select a$0 from u;
5202"), @"
5203 ╭▸
5204 2 │ create table t(a bigint);
5205 │ ─ 2. destination
5206 3 │ create table u as table t;
5207 4 │ select a from u;
5208 ╰╴ ─ 1. source
5209 ");
5210 }
5211
5212 #[test]
5213 fn goto_create_table_as_select_star() {
5214 assert_snapshot!(goto("
5215create table t(a bigint);
5216create table u as select * from t;
5217select a$0 from u;
5218"), @"
5219 ╭▸
5220 2 │ create table t(a bigint);
5221 │ ─ 2. destination
5222 3 │ create table u as select * from t;
5223 4 │ select a from u;
5224 ╰╴ ─ 1. source
5225 ");
5226 }
5227
5228 #[test]
5229 fn goto_create_table_as_values() {
5230 assert_snapshot!(goto("
5231create table k as values (1, 2);
5232select column1$0 from k;
5233"), @"
5234 ╭▸
5235 2 │ create table k as values (1, 2);
5236 │ ─ 2. destination
5237 3 │ select column1 from k;
5238 ╰╴ ─ 1. source
5239 ");
5240 }
5241
5242 #[test]
5243 fn goto_create_table_as_compound_table_query_column() {
5244 assert_snapshot!(goto("
5245create table t(a int);
5246create table u as table t union table t;
5247select a$0 from u;
5248"), @"
5249 ╭▸
5250 2 │ create table t(a int);
5251 │ ─ 2. destination
5252 3 │ create table u as table t union table t;
5253 4 │ select a from u;
5254 ╰╴ ─ 1. source
5255 ");
5256 }
5257
5258 #[test]
5259 fn goto_create_table_as_compound_values_query_column() {
5260 assert_snapshot!(goto("
5261create table u as values (1, 2) union values (3, 4);
5262select column2$0 from u;
5263"), @"
5264 ╭▸
5265 2 │ create table u as values (1, 2) union values (3, 4);
5266 │ ─ 2. destination
5267 3 │ select column2 from u;
5268 ╰╴ ─ 1. source
5269 ");
5270 }
5271
5272 #[test]
5273 fn goto_create_table_as_paren_table_query_column() {
5274 assert_snapshot!(goto("
5275create table t(a int);
5276create table u as (table t);
5277select a$0 from u;
5278"), @"
5279 ╭▸
5280 2 │ create table t(a int);
5281 │ ─ 2. destination
5282 3 │ create table u as (table t);
5283 4 │ select a from u;
5284 ╰╴ ─ 1. source
5285 ");
5286 }
5287
5288 #[test]
5289 fn goto_create_table_as_paren_values_query_column() {
5290 assert_snapshot!(goto("
5291create table u as (values (1, 2));
5292select column2$0 from u;
5293"), @"
5294 ╭▸
5295 2 │ create table u as (values (1, 2));
5296 │ ─ 2. destination
5297 3 │ select column2 from u;
5298 ╰╴ ─ 1. source
5299 ");
5300 }
5301
5302 #[test]
5303 fn goto_create_table_as_values_column_count_gap() {
5304 assert_snapshot!(goto("
5305create table u as values (1, 2);
5306select column2$0 from (select * from u) x(a);
5307"), @"
5308 ╭▸
5309 2 │ create table u as values (1, 2);
5310 │ ─ 2. destination
5311 3 │ select column2 from (select * from u) x(a);
5312 ╰╴ ─ 1. source
5313 ");
5314 }
5315
5316 #[test]
5317 fn goto_select_from_create_table_as() {
5318 assert_snapshot!(goto("
5319create table t as select 1 a;
5320select a from t$0;
5321"), @r"
5322 ╭▸
5323 2 │ create table t as select 1 a;
5324 │ ─ 2. destination
5325 3 │ select a from t;
5326 ╰╴ ─ 1. source
5327 ");
5328 }
5329
5330 #[test]
5331 fn goto_like_view_definition() {
5332 assert_snapshot!(goto("
5333create view v as select 1 a;
5334create table t (like v$0);
5335"), @"
5336 ╭▸
5337 2 │ create view v as select 1 a;
5338 │ ─ 2. destination
5339 3 │ create table t (like v);
5340 ╰╴ ─ 1. source
5341 ");
5342 }
5343
5344 #[test]
5345 fn goto_view_with_explicit_column_list() {
5346 assert_snapshot!(goto("
5347create view v(col1) as select 1;
5348select * from v$0;
5349"), @r"
5350 ╭▸
5351 2 │ create view v(col1) as select 1;
5352 │ ─ 2. destination
5353 3 │ select * from v;
5354 ╰╴ ─ 1. source
5355 ");
5356 }
5357
5358 #[test]
5359 fn goto_view_column_with_explicit_column_list() {
5360 assert_snapshot!(goto("
5361 create view v(col1) as select 1;
5362 select col1$0 from v;
5363 "), @r"
5364 ╭▸
5365 2 │ create view v(col1) as select 1;
5366 │ ──── 2. destination
5367 3 │ select col1 from v;
5368 ╰╴ ─ 1. source
5369 ");
5370 }
5371
5372 #[test]
5373 fn goto_create_table_as_with_explicit_column_list() {
5374 assert_snapshot!(goto("
5375create table t (a int);
5376create table t2 (x) as select a from t;
5377select x$0 from t2;
5378"), @"
5379 ╭▸
5380 3 │ create table t2 (x) as select a from t;
5381 │ ─ 2. destination
5382 4 │ select x from t2;
5383 ╰╴ ─ 1. source
5384 ");
5385 }
5386
5387 #[test]
5388 fn goto_create_table_as_explicit_column_list_shorter_than_select() {
5389 assert_snapshot!(goto("
5390create table t2 (x) as select 1 a, 2 b;
5391select b$0 from t2;
5392"), @"
5393 ╭▸
5394 2 │ create table t2 (x) as select 1 a, 2 b;
5395 │ ─ 2. destination
5396 3 │ select b from t2;
5397 ╰╴ ─ 1. source
5398 ");
5399 }
5400
5401 #[test]
5402 fn goto_create_table_as_explicit_column_list_shadows_select_column() {
5403 goto_not_found(
5404 "
5405create table t (a int);
5406create table t2 (x) as select a from t;
5407select a$0 from t2;
5408",
5409 );
5410 }
5411
5412 #[test]
5413 fn goto_view_column_with_schema() {
5414 assert_snapshot!(goto("
5415create view public.v as select 1 as a;
5416select a$0 from public.v;
5417"), @r"
5418 ╭▸
5419 2 │ create view public.v as select 1 as a;
5420 │ ─ 2. destination
5421 3 │ select a from public.v;
5422 ╰╴ ─ 1. source
5423 ");
5424 }
5425
5426 #[test]
5427 fn goto_view_multiple_columns() {
5428 assert_snapshot!(goto("
5429create view v as select 1 as a, 2 as b;
5430select b$0 from v;
5431"), @r"
5432 ╭▸
5433 2 │ create view v as select 1 as a, 2 as b;
5434 │ ─ 2. destination
5435 3 │ select b from v;
5436 ╰╴ ─ 1. source
5437 ");
5438 }
5439
5440 #[test]
5441 fn goto_view_column_from_table() {
5442 assert_snapshot!(goto("
5443create table t(x int, y int);
5444create view v as select x, y from t;
5445select x$0 from v;
5446"), @r"
5447 ╭▸
5448 3 │ create view v as select x, y from t;
5449 │ ─ 2. destination
5450 4 │ select x from v;
5451 ╰╴ ─ 1. source
5452 ");
5453 }
5454
5455 #[test]
5456 fn goto_view_column_with_table_preference() {
5457 assert_snapshot!(goto("
5458create table v(a int);
5459create view vw as select 1 as a;
5460select a$0 from v;
5461"), @r"
5462 ╭▸
5463 2 │ create table v(a int);
5464 │ ─ 2. destination
5465 3 │ create view vw as select 1 as a;
5466 4 │ select a from v;
5467 ╰╴ ─ 1. source
5468 ");
5469 }
5470
5471 #[test]
5472 fn goto_cast_operator() {
5473 assert_snapshot!(goto("
5474create type foo as enum ('a', 'b');
5475select x::foo$0;
5476"), @r"
5477 ╭▸
5478 2 │ create type foo as enum ('a', 'b');
5479 │ ─── 2. destination
5480 3 │ select x::foo;
5481 ╰╴ ─ 1. source
5482 ");
5483 }
5484
5485 #[test]
5486 fn goto_cast_function() {
5487 assert_snapshot!(goto("
5488create type bar as enum ('x', 'y');
5489select cast(x as bar$0);
5490"), @r"
5491 ╭▸
5492 2 │ create type bar as enum ('x', 'y');
5493 │ ─── 2. destination
5494 3 │ select cast(x as bar);
5495 ╰╴ ─ 1. source
5496 ");
5497 }
5498
5499 #[test]
5500 fn goto_cast_with_schema() {
5501 assert_snapshot!(goto("
5502create type public.baz as enum ('m', 'n');
5503select x::public.baz$0;
5504"), @r"
5505 ╭▸
5506 2 │ create type public.baz as enum ('m', 'n');
5507 │ ─── 2. destination
5508 3 │ select x::public.baz;
5509 ╰╴ ─ 1. source
5510 ");
5511 }
5512
5513 #[test]
5514 fn goto_cast_timestamp_without_time_zone() {
5515 assert_snapshot!(goto("
5516create type pg_catalog.timestamp;
5517select ''::timestamp without$0 time zone;
5518"), @r"
5519 ╭▸
5520 2 │ create type pg_catalog.timestamp;
5521 │ ───────── 2. destination
5522 3 │ select ''::timestamp without time zone;
5523 ╰╴ ─ 1. source
5524 ");
5525 }
5526
5527 #[test]
5528 fn goto_cast_timestamp_with_time_zone() {
5529 assert_snapshot!(goto("
5530create type pg_catalog.timestamptz;
5531select ''::timestamp with$0 time zone;
5532"), @r"
5533 ╭▸
5534 2 │ create type pg_catalog.timestamptz;
5535 │ ─────────── 2. destination
5536 3 │ select ''::timestamp with time zone;
5537 ╰╴ ─ 1. source
5538 ");
5539 }
5540
5541 #[test]
5542 fn goto_cast_multirange_type_from_range() {
5543 assert_snapshot!(goto("
5544create type floatrange as range (
5545 subtype = float8,
5546 subtype_diff = float8mi
5547);
5548select '{[1.234, 5.678]}'::floatmultirange$0;
5549"), @r"
5550 ╭▸
5551 2 │ create type floatrange as range (
5552 │ ────────── 2. destination
5553 ‡
5554 6 │ select '{[1.234, 5.678]}'::floatmultirange;
5555 ╰╴ ─ 1. source
5556 ");
5557 }
5558
5559 #[test]
5560 fn goto_cast_multirange_special_type_name_string() {
5561 assert_snapshot!(goto("
5562create type floatrange as range (
5563 subtype = float8,
5564 subtype_diff = float8mi,
5565 multirange_type_name = 'floatmulirangething'
5566);
5567select '{[1.234, 5.678]}'::floatmulirangething$0;
5568"), @r"
5569 ╭▸
5570 2 │ create type floatrange as range (
5571 │ ────────── 2. destination
5572 ‡
5573 7 │ select '{[1.234, 5.678]}'::floatmulirangething;
5574 ╰╴ ─ 1. source
5575 ");
5576 }
5577
5578 #[test]
5579 fn goto_cast_multirange_special_type_name_ident() {
5580 assert_snapshot!(goto("
5581create type floatrange as range (
5582 subtype = float8,
5583 subtype_diff = float8mi,
5584 multirange_type_name = floatrangemutirange
5585);
5586select '{[1.234, 5.678]}'::floatrangemutirange$0;
5587"), @r"
5588 ╭▸
5589 2 │ create type floatrange as range (
5590 │ ────────── 2. destination
5591 ‡
5592 7 │ select '{[1.234, 5.678]}'::floatrangemutirange;
5593 ╰╴ ─ 1. source
5594 ");
5595 }
5596
5597 #[test]
5598 fn goto_cast_multirange_edge_case_type_from_range() {
5599 assert_snapshot!(goto("
5601create type floatrangerange as range (
5602 subtype = float8,
5603 subtype_diff = float8mi
5604);
5605select '{[1.234, 5.678]}'::floatmultirangerange$0;
5606"), @r"
5607 ╭▸
5608 2 │ create type floatrangerange as range (
5609 │ ─────────────── 2. destination
5610 ‡
5611 6 │ select '{[1.234, 5.678]}'::floatmultirangerange;
5612 ╰╴ ─ 1. source
5613 ");
5614 }
5615
5616 #[test]
5617 fn goto_cast_boolean_falls_back_to_bool() {
5618 assert_snapshot!(goto("
5619create type pg_catalog.bool;
5620select '1'::boolean$0;
5621"), @"
5622 ╭▸
5623 2 │ create type pg_catalog.bool;
5624 │ ──── 2. destination
5625 3 │ select '1'::boolean;
5626 ╰╴ ─ 1. source
5627 ");
5628 }
5629
5630 #[test]
5631 fn goto_cast_decimal_falls_back_to_numeric() {
5632 assert_snapshot!(goto("
5633create type pg_catalog.numeric;
5634select 1::decimal$0(10, 2);
5635"), @"
5636 ╭▸
5637 2 │ create type pg_catalog.numeric;
5638 │ ─────── 2. destination
5639 3 │ select 1::decimal(10, 2);
5640 ╰╴ ─ 1. source
5641 ");
5642 }
5643
5644 #[test]
5645 fn goto_cast_float_falls_back_to_float8() {
5646 assert_snapshot!(goto("
5647create type pg_catalog.float8;
5648select 1::float$0;
5649"), @"
5650 ╭▸
5651 2 │ create type pg_catalog.float8;
5652 │ ────── 2. destination
5653 3 │ select 1::float;
5654 ╰╴ ─ 1. source
5655 ");
5656 }
5657
5658 #[test]
5659 fn goto_cast_bigint_falls_back_to_int8() {
5660 assert_snapshot!(goto("
5661create type pg_catalog.int8;
5662select 1::bigint$0;
5663"), @r"
5664 ╭▸
5665 2 │ create type pg_catalog.int8;
5666 │ ──── 2. destination
5667 3 │ select 1::bigint;
5668 ╰╴ ─ 1. source
5669 ");
5670 }
5671
5672 #[test]
5673 fn goto_cast_real_falls_back_to_float4() {
5674 assert_snapshot!(goto("
5675create type pg_catalog.float4;
5676select 1::real$0;
5677"), @"
5678 ╭▸
5679 2 │ create type pg_catalog.float4;
5680 │ ────── 2. destination
5681 3 │ select 1::real;
5682 ╰╴ ─ 1. source
5683 ");
5684 }
5685
5686 #[test]
5687 fn goto_cast_bigint_prefers_user_type() {
5688 assert_snapshot!(goto("
5689create type bigint;
5690create type pg_catalog.int8;
5691select 1::bigint$0;
5692"), @r"
5693 ╭▸
5694 2 │ create type bigint;
5695 │ ────── 2. destination
5696 3 │ create type pg_catalog.int8;
5697 4 │ select 1::bigint;
5698 ╰╴ ─ 1. source
5699 ");
5700 }
5701
5702 #[test]
5703 fn goto_cast_smallserial_falls_back_to_int2() {
5704 assert_snapshot!(goto("
5705create type pg_catalog.int2;
5706select 1::smallserial$0;
5707"), @r"
5708 ╭▸
5709 2 │ create type pg_catalog.int2;
5710 │ ──── 2. destination
5711 3 │ select 1::smallserial;
5712 ╰╴ ─ 1. source
5713 ");
5714 }
5715
5716 #[test]
5717 fn goto_cast_serial2_falls_back_to_int2() {
5718 assert_snapshot!(goto("
5719create type pg_catalog.int2;
5720select 1::serial2$0;
5721"), @r"
5722 ╭▸
5723 2 │ create type pg_catalog.int2;
5724 │ ──── 2. destination
5725 3 │ select 1::serial2;
5726 ╰╴ ─ 1. source
5727 ");
5728 }
5729
5730 #[test]
5731 fn goto_cast_serial_falls_back_to_int4() {
5732 assert_snapshot!(goto("
5733create type pg_catalog.int4;
5734select 1::serial$0;
5735"), @r"
5736 ╭▸
5737 2 │ create type pg_catalog.int4;
5738 │ ──── 2. destination
5739 3 │ select 1::serial;
5740 ╰╴ ─ 1. source
5741 ");
5742 }
5743
5744 #[test]
5745 fn goto_cast_serial4_falls_back_to_int4() {
5746 assert_snapshot!(goto("
5747create type pg_catalog.int4;
5748select 1::serial4$0;
5749"), @r"
5750 ╭▸
5751 2 │ create type pg_catalog.int4;
5752 │ ──── 2. destination
5753 3 │ select 1::serial4;
5754 ╰╴ ─ 1. source
5755 ");
5756 }
5757
5758 #[test]
5759 fn goto_cast_bigserial_falls_back_to_int8() {
5760 assert_snapshot!(goto("
5761create type pg_catalog.int8;
5762select 1::bigserial$0;
5763"), @r"
5764 ╭▸
5765 2 │ create type pg_catalog.int8;
5766 │ ──── 2. destination
5767 3 │ select 1::bigserial;
5768 ╰╴ ─ 1. source
5769 ");
5770 }
5771
5772 #[test]
5773 fn goto_cast_serial8_falls_back_to_int8() {
5774 assert_snapshot!(goto("
5775create type pg_catalog.int8;
5776select 1::serial8$0;
5777"), @r"
5778 ╭▸
5779 2 │ create type pg_catalog.int8;
5780 │ ──── 2. destination
5781 3 │ select 1::serial8;
5782 ╰╴ ─ 1. source
5783 ");
5784 }
5785
5786 #[test]
5787 fn goto_cast_int_falls_back_to_int4() {
5788 assert_snapshot!(goto("
5789create type pg_catalog.int4;
5790select 1::int$0;
5791"), @r"
5792 ╭▸
5793 2 │ create type pg_catalog.int4;
5794 │ ──── 2. destination
5795 3 │ select 1::int;
5796 ╰╴ ─ 1. source
5797 ");
5798 }
5799
5800 #[test]
5801 fn goto_cast_integer_falls_back_to_int4() {
5802 assert_snapshot!(goto("
5803create type pg_catalog.int4;
5804select 1::integer$0;
5805"), @r"
5806 ╭▸
5807 2 │ create type pg_catalog.int4;
5808 │ ──── 2. destination
5809 3 │ select 1::integer;
5810 ╰╴ ─ 1. source
5811 ");
5812 }
5813
5814 #[test]
5815 fn goto_cast_smallint_falls_back_to_int2() {
5816 assert_snapshot!(goto("
5817create type pg_catalog.int2;
5818select 1::smallint$0;
5819"), @r"
5820 ╭▸
5821 2 │ create type pg_catalog.int2;
5822 │ ──── 2. destination
5823 3 │ select 1::smallint;
5824 ╰╴ ─ 1. source
5825 ");
5826 }
5827
5828 #[test]
5829 fn goto_cast_double_precision_falls_back_to_float8() {
5830 assert_snapshot!(goto("
5831create type pg_catalog.float8;
5832select '1'::double precision[]$0;
5833"), @r"
5834 ╭▸
5835 2 │ create type pg_catalog.float8;
5836 │ ────── 2. destination
5837 3 │ select '1'::double precision[];
5838 ╰╴ ─ 1. source
5839 ");
5840 }
5841
5842 #[test]
5843 fn goto_cast_varchar_with_modifier() {
5844 assert_snapshot!(goto("
5845create type pg_catalog.varchar;
5846select '1'::varchar$0(1);
5847"), @r"
5848 ╭▸
5849 2 │ create type pg_catalog.varchar;
5850 │ ─────── 2. destination
5851 3 │ select '1'::varchar(1);
5852 ╰╴ ─ 1. source
5853 ");
5854 }
5855
5856 #[test]
5857 fn goto_cast_composite_type() {
5858 assert_snapshot!(goto("
5859create type person_info as (name varchar(50), age int);
5860select ('Alice', 30)::person_info$0;
5861"), @r"
5862 ╭▸
5863 2 │ create type person_info as (name varchar(50), age int);
5864 │ ─────────── 2. destination
5865 3 │ select ('Alice', 30)::person_info;
5866 ╰╴ ─ 1. source
5867 ");
5868 }
5869
5870 #[test]
5871 fn goto_cast_composite_type_in_cte() {
5872 assert_snapshot!(goto("
5873create type person_info as (name varchar(50), age int);
5874with team as (
5875 select 1 as id, ('Alice', 30)::person_info$0 as member
5876)
5877select * from team;
5878"), @r"
5879 ╭▸
5880 2 │ create type person_info as (name varchar(50), age int);
5881 │ ─────────── 2. destination
5882 3 │ with team as (
5883 4 │ select 1 as id, ('Alice', 30)::person_info as member
5884 ╰╴ ─ 1. source
5885 ");
5886 }
5887
5888 #[test]
5889 fn goto_composite_type_field_name() {
5890 assert_snapshot!(goto("
5891create type person_info as (name varchar(50), age int);
5892with team as (
5893 select 1 as id, ('Alice', 30)::person_info as member
5894)
5895select (member).name$0, (member).age from team;
5896"), @r"
5897 ╭▸
5898 2 │ create type person_info as (name varchar(50), age int);
5899 │ ──── 2. destination
5900 ‡
5901 6 │ select (member).name, (member).age from team;
5902 ╰╴ ─ 1. source
5903 ");
5904 }
5905
5906 #[test]
5907 fn goto_composite_type_field_in_where() {
5908 assert_snapshot!(goto("
5909create type person_info as (name varchar(50), age int);
5910with team as (
5911 select 1 as id, ('Alice', 30)::person_info as member
5912 union all
5913 select 2, ('Bob', 25)::person_info
5914)
5915select (member).name, (member).age
5916from team
5917where (member).age$0 >= 18;
5918"), @r"
5919 ╭▸
5920 2 │ create type person_info as (name varchar(50), age int);
5921 │ ─── 2. destination
5922 ‡
5923 10 │ where (member).age >= 18;
5924 ╰╴ ─ 1. source
5925 ");
5926 }
5927
5928 #[test]
5929 fn goto_composite_type_field_base() {
5930 assert_snapshot!(goto("
5931create type person_info as (name varchar(50), age int);
5932with team as (
5933 select 1 as id, ('Alice', 30)::person_info as member
5934)
5935select (member$0).age from team;
5936"), @r"
5937 ╭▸
5938 4 │ select 1 as id, ('Alice', 30)::person_info as member
5939 │ ────── 2. destination
5940 5 │ )
5941 6 │ select (member).age from team;
5942 ╰╴ ─ 1. source
5943 ");
5944 }
5945
5946 #[test]
5947 fn goto_composite_type_field_nested_parens() {
5948 assert_snapshot!(goto("
5949create type person_info as (name varchar(50), age int);
5950with team as (
5951 select 1 as id, ('Alice', 30)::person_info as member
5952)
5953select ((((member))).name$0) from team;
5954"), @r"
5955 ╭▸
5956 2 │ create type person_info as (name varchar(50), age int);
5957 │ ──── 2. destination
5958 ‡
5959 6 │ select ((((member))).name) from team;
5960 ╰╴ ─ 1. source
5961 ");
5962 }
5963
5964 #[test]
5965 fn goto_nested_composite_type_field() {
5966 assert_snapshot!(goto("
5967create type inner_t as (x int);
5968create type outer_t as (i inner_t);
5969create table t (v outer_t);
5970select ((v).i).x$0 from t;
5971"), @"
5972 ╭▸
5973 2 │ create type inner_t as (x int);
5974 │ ─ 2. destination
5975 ‡
5976 5 │ select ((v).i).x from t;
5977 ╰╴ ─ 1. source
5978 ");
5979 }
5980
5981 #[test]
5982 fn goto_whole_row_field_access() {
5983 assert_snapshot!(goto("
5984create table t (a int);
5985select (t).a$0 from t;
5986"), @"
5987 ╭▸
5988 2 │ create table t (a int);
5989 │ ─ 2. destination
5990 3 │ select (t).a from t;
5991 ╰╴ ─ 1. source
5992 ");
5993 }
5994
5995 #[test]
5996 fn begin_to_rollback() {
5997 assert_snapshot!(goto(
5998 "
5999begin$0;
6000select 1;
6001rollback;
6002commit;
6003",
6004 ), @"
6005 ╭▸
6006 2 │ begin;
6007 │ ─ 1. source
6008 3 │ select 1;
6009 4 │ rollback;
6010 ╰╴───────── 2. destination
6011 ");
6012 }
6013
6014 #[test]
6015 fn commit_to_begin() {
6016 assert_snapshot!(goto(
6017 "
6018begin;
6019select 1;
6020commit$0;
6021",
6022 ), @"
6023 ╭▸
6024 2 │ begin;
6025 │ ────── 2. destination
6026 3 │ select 1;
6027 4 │ commit;
6028 ╰╴ ─ 1. source
6029 ");
6030 }
6031
6032 #[test]
6033 fn begin_to_commit() {
6034 assert_snapshot!(goto(
6035 "
6036begin$0;
6037select 1;
6038commit;
6039",
6040 ), @"
6041 ╭▸
6042 2 │ begin;
6043 │ ─ 1. source
6044 3 │ select 1;
6045 4 │ commit;
6046 ╰╴─────── 2. destination
6047 ");
6048 }
6049
6050 #[test]
6051 fn commit_to_start_transaction() {
6052 assert_snapshot!(goto(
6053 "
6054start transaction;
6055select 1;
6056commit$0;
6057",
6058 ), @"
6059 ╭▸
6060 2 │ start transaction;
6061 │ ────────────────── 2. destination
6062 3 │ select 1;
6063 4 │ commit;
6064 ╰╴ ─ 1. source
6065 ");
6066 }
6067
6068 #[test]
6069 fn start_transaction_to_commit() {
6070 assert_snapshot!(goto(
6071 "
6072start$0 transaction;
6073select 1;
6074commit;
6075",
6076 ), @"
6077 ╭▸
6078 2 │ start transaction;
6079 │ ─ 1. source
6080 3 │ select 1;
6081 4 │ commit;
6082 ╰╴─────── 2. destination
6083 ");
6084 }
6085
6086 #[test]
6087 fn commit_prepared_to_prepare_transaction() {
6088 assert_snapshot!(goto(
6089 "
6090prepare transaction 'foo';
6091select 1;
6092commit prepared 'foo'$0;
6093",
6094 ), @"
6095 ╭▸
6096 2 │ prepare transaction 'foo';
6097 │ ───── 2. destination
6098 3 │ select 1;
6099 4 │ commit prepared 'foo';
6100 ╰╴ ─ 1. source
6101 ");
6102 }
6103
6104 #[test]
6105 fn rollback_prepared_to_prepare_transaction() {
6106 assert_snapshot!(goto(
6107 "
6108prepare transaction 'foo';
6109rollback prepared 'foo'$0;
6110",
6111 ), @"
6112 ╭▸
6113 2 │ prepare transaction 'foo';
6114 │ ───── 2. destination
6115 3 │ rollback prepared 'foo';
6116 ╰╴ ─ 1. source
6117 ");
6118 }
6119
6120 #[test]
6121 fn commit_prepared_to_most_recent_prepare_transaction() {
6122 assert_snapshot!(goto(
6123 "
6124prepare transaction 'foo';
6125commit prepared 'foo';
6126prepare transaction 'foo';
6127commit prepared 'foo'$0;
6128",
6129 ), @"
6130 ╭▸
6131 4 │ prepare transaction 'foo';
6132 │ ───── 2. destination
6133 5 │ commit prepared 'foo';
6134 ╰╴ ─ 1. source
6135 ");
6136 }
6137
6138 #[test]
6139 fn commit_prepared_before_prepare_transaction() {
6140 goto_not_found(
6141 "
6142commit prepared 'foo'$0;
6143prepare transaction 'foo';
6144",
6145 );
6146 }
6147
6148 #[test]
6149 fn commit_prepared_frees_transaction_id() {
6150 goto_not_found(
6151 "
6152prepare transaction 'foo';
6153commit prepared 'foo';
6154commit prepared 'foo'$0;
6155",
6156 );
6157 }
6158
6159 #[test]
6160 fn commit_prepared_matches_escaped_transaction_id() {
6161 assert_snapshot!(goto(
6162 r#"
6163prepare transaction e'fo\u006f';
6164commit prepared 'foo'$0;
6165"#,
6166 ), @r"
6167 ╭▸
6168 2 │ prepare transaction e'fo\u006f';
6169 │ ─────────── 2. destination
6170 3 │ commit prepared 'foo';
6171 ╰╴ ─ 1. source
6172 ");
6173 }
6174
6175 #[test]
6176 fn commit_prepared_matches_dollar_quoted_transaction_id() {
6177 assert_snapshot!(goto(
6178 "
6179prepare transaction $$foo$$;
6180commit prepared 'foo'$0;
6181",
6182 ), @"
6183 ╭▸
6184 2 │ prepare transaction $$foo$$;
6185 │ ─────── 2. destination
6186 3 │ commit prepared 'foo';
6187 ╰╴ ─ 1. source
6188 ");
6189 }
6190
6191 #[test]
6192 fn commit_prepared_with_unknown_transaction_id() {
6193 goto_not_found(
6194 "
6195begin;
6196prepare transaction 'foo';
6197commit prepared 'bar'$0;
6198",
6199 );
6200 }
6201
6202 #[test]
6203 fn commit_prepared_ignores_enclosing_begin() {
6204 goto_not_found(
6205 "
6206begin;
6207commit prepared 'foo'$0;
6208",
6209 );
6210 }
6211
6212 #[test]
6213 fn goto_with_search_path() {
6214 assert_snapshot!(goto(r#"
6215set search_path to "foo", public;
6216create table foo.t();
6217drop table t$0;
6218"#), @r"
6219 ╭▸
6220 3 │ create table foo.t();
6221 │ ─ 2. destination
6222 4 │ drop table t;
6223 ╰╴ ─ 1. source
6224 ");
6225 }
6226
6227 #[test]
6228 fn goto_with_search_path_and_unspecified_table() {
6229 assert_snapshot!(goto(r#"
6230set search_path to foo,bar;
6231create table t();
6232drop table foo.t$0;
6233"#), @r"
6234 ╭▸
6235 3 │ create table t();
6236 │ ─ 2. destination
6237 4 │ drop table foo.t;
6238 ╰╴ ─ 1. source
6239 ");
6240 }
6241
6242 #[test]
6243 fn goto_with_search_path_from_current() {
6244 assert_snapshot!(goto(r#"
6245set search_path to foo;
6246set search_path from current;
6247create table foo.t();
6248drop table t$0;
6249"#), @"
6250 ╭▸
6251 4 │ create table foo.t();
6252 │ ─ 2. destination
6253 5 │ drop table t;
6254 ╰╴ ─ 1. source
6255 ");
6256 }
6257
6258 #[test]
6259 fn goto_with_search_path_via_set_config() {
6260 assert_snapshot!(goto(r#"
6261select set_config('search_path', 'foo, public', false);
6262create table foo.t();
6263drop table t$0;
6264"#), @"
6265 ╭▸
6266 3 │ create table foo.t();
6267 │ ─ 2. destination
6268 4 │ drop table t;
6269 ╰╴ ─ 1. source
6270 ");
6271 }
6272
6273 #[test]
6274 fn goto_with_search_path_via_set_config_unrelated_setting() {
6275 goto_not_found(
6276 r#"
6277select set_config('work_mem', '64MB', false);
6278create table foo.t();
6279drop table t$0;
6280"#,
6281 );
6282 }
6283
6284 #[test]
6285 fn goto_with_search_path_via_set_config_user_defined_function() {
6286 goto_not_found(
6287 r#"
6288create function set_config(text, text, boolean) returns text as $$ select $2 $$ language sql;
6289select set_config('search_path', 'foo', false);
6290create table foo.t();
6291drop table t$0;
6292"#,
6293 );
6294 }
6295
6296 #[test]
6297 fn goto_with_search_path_via_set_config_user_defined_function_outside_search_path() {
6298 assert_snapshot!(goto(r#"
6299create schema other;
6300create function other.set_config(text, text, boolean) returns text as $$ select $2 $$ language sql;
6301select set_config('search_path', 'foo', false);
6302create table foo.t();
6303drop table t$0;
6304"#), @"
6305 ╭▸
6306 5 │ create table foo.t();
6307 │ ─ 2. destination
6308 6 │ drop table t;
6309 ╰╴ ─ 1. source
6310 ");
6311 }
6312
6313 #[test]
6314 fn goto_with_search_path_via_set_config_pg_catalog_qualified() {
6315 assert_snapshot!(goto(r#"
6316select pg_catalog.set_config('search_path', 'foo', false);
6317create table foo.t();
6318drop table t$0;
6319"#), @"
6320 ╭▸
6321 3 │ create table foo.t();
6322 │ ─ 2. destination
6323 4 │ drop table t;
6324 ╰╴ ─ 1. source
6325 ");
6326 }
6327
6328 #[test]
6329 fn goto_with_search_path_via_set_config_non_pg_catalog_qualified() {
6330 goto_not_found(
6331 r#"
6332select public.set_config('search_path', 'foo', false);
6333create table foo.t();
6334drop table t$0;
6335"#,
6336 );
6337 }
6338
6339 #[test]
6340 fn goto_column_not_in_cte_but_in_table() {
6341 goto_not_found(
6343 r"
6344create table t (c int);
6345with t as (select 1 a)
6346select c$0 from t;
6347",
6348 );
6349 }
6350
6351 #[test]
6352 fn goto_with_search_path_empty() {
6353 goto_not_found(
6354 r#"
6355set search_path = '';
6356create table t();
6357drop table t$0;
6358"#,
6359 );
6360 }
6361
6362 #[test]
6363 fn goto_with_search_path_like_variable() {
6364 goto_not_found(
6366 "
6367set bar.search_path to foo, public;
6368create table foo.t();
6369drop table t$0;
6370",
6371 )
6372 }
6373
6374 #[test]
6375 fn goto_with_search_path_second_schema() {
6376 assert_snapshot!(goto("
6377set search_path to foo, bar, public;
6378create table bar.t();
6379drop table t$0;
6380"), @r"
6381 ╭▸
6382 3 │ create table bar.t();
6383 │ ─ 2. destination
6384 4 │ drop table t;
6385 ╰╴ ─ 1. source
6386 ");
6387 }
6388
6389 #[test]
6390 fn goto_with_search_path_skips_first() {
6391 assert_snapshot!(goto("
6392set search_path to foo, bar, public;
6393create table foo.t();
6394create table bar.t();
6395drop table t$0;
6396"), @r"
6397 ╭▸
6398 3 │ create table foo.t();
6399 │ ─ 2. destination
6400 4 │ create table bar.t();
6401 5 │ drop table t;
6402 ╰╴ ─ 1. source
6403 ");
6404 }
6405
6406 #[test]
6407 fn goto_without_search_path_uses_default() {
6408 assert_snapshot!(goto("
6409create table foo.t();
6410create table public.t();
6411drop table t$0;
6412"), @r"
6413 ╭▸
6414 3 │ create table public.t();
6415 │ ─ 2. destination
6416 4 │ drop table t;
6417 ╰╴ ─ 1. source
6418 ");
6419 }
6420
6421 #[test]
6422 fn goto_with_set_schema() {
6423 assert_snapshot!(goto("
6424set schema 'myschema';
6425create table myschema.t();
6426drop table t$0;
6427"), @r"
6428 ╭▸
6429 3 │ create table myschema.t();
6430 │ ─ 2. destination
6431 4 │ drop table t;
6432 ╰╴ ─ 1. source
6433 ");
6434 }
6435
6436 #[test]
6437 fn goto_with_set_schema_ignores_other_schemas() {
6438 assert_snapshot!(goto("
6439set schema 'myschema';
6440create table public.t();
6441create table myschema.t();
6442drop table t$0;
6443"), @r"
6444 ╭▸
6445 4 │ create table myschema.t();
6446 │ ─ 2. destination
6447 5 │ drop table t;
6448 ╰╴ ─ 1. source
6449 ");
6450 }
6451
6452 #[test]
6453 fn goto_search_path_schema_name() {
6454 assert_snapshot!(goto("
6455create schema app;
6456set search_path to app$0;
6457"), @"
6458 ╭▸
6459 2 │ create schema app;
6460 │ ─── 2. destination
6461 3 │ set search_path to app;
6462 ╰╴ ─ 1. source
6463 ");
6464 }
6465
6466 #[test]
6467 fn goto_search_path_schema_name_quoted() {
6468 assert_snapshot!(goto(r#"
6469create schema app;
6470set search_path to "app$0";
6471"#), @r#"
6472 ╭▸
6473 2 │ create schema app;
6474 │ ─── 2. destination
6475 3 │ set search_path to "app";
6476 ╰╴ ─ 1. source
6477 "#);
6478 }
6479
6480 #[test]
6481 fn goto_search_path_schema_name_string_literal() {
6482 assert_snapshot!(goto(r#"
6483create schema app;
6484set search_path to 'app$0';
6485"#), @"
6486 ╭▸
6487 2 │ create schema app;
6488 │ ─── 2. destination
6489 3 │ set search_path to 'app';
6490 ╰╴ ─ 1. source
6491 ");
6492 }
6493
6494 #[test]
6495 fn goto_search_path_schema_name_second_item() {
6496 assert_snapshot!(goto("
6497create schema app;
6498set search_path to public, app$0;
6499"), @"
6500 ╭▸
6501 2 │ create schema app;
6502 │ ─── 2. destination
6503 3 │ set search_path to public, app;
6504 ╰╴ ─ 1. source
6505 ");
6506 }
6507
6508 #[test]
6509 fn goto_search_path_schema_name_not_the_param_name() {
6510 goto_not_found(
6511 "
6512create schema search_path;
6513set search_path$0 to app;
6514",
6515 );
6516 }
6517
6518 #[test]
6519 fn goto_alter_role_set_search_path() {
6520 assert_snapshot!(goto("
6521create schema app;
6522create role app;
6523create role r;
6524alter role r set search_path = app$0;
6525"), @"
6526 ╭▸
6527 2 │ create schema app;
6528 │ ─── 2. destination
6529 ‡
6530 5 │ alter role r set search_path = app;
6531 ╰╴ ─ 1. source
6532 ");
6533 }
6534
6535 #[test]
6536 fn goto_alter_database_set_search_path() {
6537 assert_snapshot!(goto("
6538create schema app;
6539alter database d set search_path = app$0;
6540"), @"
6541 ╭▸
6542 2 │ create schema app;
6543 │ ─── 2. destination
6544 3 │ alter database d set search_path = app;
6545 ╰╴ ─ 1. source
6546 ");
6547 }
6548
6549 #[test]
6550 fn goto_create_function_set_search_path() {
6551 assert_snapshot!(goto("
6552create schema app;
6553create function f() returns int language sql as $$ select 1 $$ set search_path = app$0;
6554"), @"
6555 ╭▸
6556 2 │ create schema app;
6557 │ ─── 2. destination
6558 3 │ create function f() returns int language sql as $$ select 1 $$ set search_path = app;
6559 ╰╴ ─ 1. source
6560 ");
6561 }
6562
6563 #[test]
6564 fn goto_function_own_set_search_path_resolves_body_call() {
6565 assert_snapshot!(goto("
6566create schema bar;
6567create function bar.foo() returns int language sql begin atomic select 1; end;
6568create function caller() returns int language sql set search_path = bar begin atomic select foo$0(); end;
6569"), @"
6570 ╭▸
6571 3 │ create function bar.foo() returns int language sql begin atomic select 1; end;
6572 │ ─── 2. destination
6573 4 │ create function caller() returns int language sql set search_path = bar begin atomic select foo(); end;
6574 ╰╴ ─ 1. source
6575 ");
6576 }
6577
6578 #[test]
6579 fn goto_function_own_set_search_path_does_not_leak_after_body() {
6580 assert_snapshot!(goto("
6581create schema bar;
6582create table bar.t(id int);
6583create table public.t(id int);
6584create function caller() returns int language sql set search_path = bar begin atomic select 1; end;
6585select * from t$0;
6586"), @"
6587 ╭▸
6588 4 │ create table public.t(id int);
6589 │ ─ 2. destination
6590 5 │ create function caller() returns int language sql set search_path = bar begin atomic select 1; end;
6591 6 │ select * from t;
6592 ╰╴ ─ 1. source
6593 ");
6594 }
6595
6596 #[test]
6597 fn goto_function_set_search_path_from_current_resolves_body_call() {
6598 assert_snapshot!(goto("
6599create schema app;
6600create function app.target() returns int language sql return 1;
6601set search_path to app;
6602create function caller() returns int language sql set search_path from current begin atomic select tar$0get(); end;
6603"), @"
6604 ╭▸
6605 3 │ create function app.target() returns int language sql return 1;
6606 │ ────── 2. destination
6607 4 │ set search_path to app;
6608 5 │ create function caller() returns int language sql set search_path from current begin atomic select target(); end;
6609 ╰╴ ─ 1. source
6610 ");
6611 }
6612
6613 #[test]
6614 fn goto_procedure_own_set_search_path_resolves_body_call() {
6615 assert_snapshot!(goto("
6616create schema bar;
6617create function bar.foo() returns int language sql begin atomic select 1; end;
6618create procedure caller() language sql set search_path = bar begin atomic select foo$0(); end;
6619"), @"
6620 ╭▸
6621 3 │ create function bar.foo() returns int language sql begin atomic select 1; end;
6622 │ ─── 2. destination
6623 4 │ create procedure caller() language sql set search_path = bar begin atomic select foo(); end;
6624 ╰╴ ─ 1. source
6625 ");
6626 }
6627
6628 #[test]
6629 fn goto_alter_function_set_search_path() {
6630 assert_snapshot!(goto("
6631create schema app;
6632create function f() returns int language sql as $$ select 1 $$;
6633alter function f() set search_path = app$0;
6634"), @"
6635 ╭▸
6636 2 │ create schema app;
6637 │ ─── 2. destination
6638 3 │ create function f() returns int language sql as $$ select 1 $$;
6639 4 │ alter function f() set search_path = app;
6640 ╰╴ ─ 1. source
6641 ");
6642 }
6643
6644 #[test]
6645 fn goto_set_schema_literal() {
6646 assert_snapshot!(goto("
6647create schema app;
6648set schema 'app$0';
6649"), @"
6650 ╭▸
6651 2 │ create schema app;
6652 │ ─── 2. destination
6653 3 │ set schema 'app';
6654 ╰╴ ─ 1. source
6655 ");
6656 }
6657
6658 #[test]
6659 fn goto_with_search_path_changed_twice() {
6660 assert_snapshot!(goto("
6661set search_path to foo;
6662create table foo.t();
6663set search_path to bar;
6664create table bar.t();
6665drop table t$0;
6666"), @r"
6667 ╭▸
6668 5 │ create table bar.t();
6669 │ ─ 2. destination
6670 6 │ drop table t;
6671 ╰╴ ─ 1. source
6672 ");
6673
6674 assert_snapshot!(goto("
6675set search_path to foo;
6676create table foo.t();
6677drop table t$0;
6678set search_path to bar;
6679create table bar.t();
6680drop table t;
6681"), @r"
6682 ╭▸
6683 3 │ create table foo.t();
6684 │ ─ 2. destination
6685 4 │ drop table t;
6686 ╰╴ ─ 1. source
6687 ");
6688 }
6689
6690 #[test]
6691 fn goto_with_empty_search_path() {
6692 goto_not_found(
6693 "
6694set search_path to '';
6695create table public.t();
6696drop table t$0;
6697",
6698 )
6699 }
6700
6701 #[test]
6702 fn goto_with_search_path_uppercase() {
6703 assert_snapshot!(goto("
6704SET SEARCH_PATH TO foo;
6705create table foo.t();
6706drop table t$0;
6707"), @r"
6708 ╭▸
6709 3 │ create table foo.t();
6710 │ ─ 2. destination
6711 4 │ drop table t;
6712 ╰╴ ─ 1. source
6713 ");
6714 }
6715
6716 #[test]
6717 fn goto_table_stmt() {
6718 assert_snapshot!(goto("
6719create table t();
6720table t$0;
6721"), @r"
6722 ╭▸
6723 2 │ create table t();
6724 │ ─ 2. destination
6725 3 │ table t;
6726 ╰╴ ─ 1. source
6727 ");
6728 }
6729
6730 #[test]
6731 fn goto_table_stmt_with_schema() {
6732 assert_snapshot!(goto("
6733create table public.t();
6734table public.t$0;
6735"), @r"
6736 ╭▸
6737 2 │ create table public.t();
6738 │ ─ 2. destination
6739 3 │ table public.t;
6740 ╰╴ ─ 1. source
6741 ");
6742 }
6743
6744 #[test]
6745 fn goto_table_stmt_with_search_path() {
6746 assert_snapshot!(goto("
6747set search_path to foo;
6748create table foo.t();
6749table t$0;
6750"), @r"
6751 ╭▸
6752 3 │ create table foo.t();
6753 │ ─ 2. destination
6754 4 │ table t;
6755 ╰╴ ─ 1. source
6756 ");
6757 }
6758
6759 #[test]
6760 fn goto_drop_index() {
6761 assert_snapshot!(goto("
6762create index idx_name on t(x);
6763drop index idx_name$0;
6764"), @r"
6765 ╭▸
6766 2 │ create index idx_name on t(x);
6767 │ ──────── 2. destination
6768 3 │ drop index idx_name;
6769 ╰╴ ─ 1. source
6770 ");
6771 }
6772
6773 #[test]
6774 fn goto_drop_index_with_schema() {
6775 assert_snapshot!(goto(r#"
6776set search_path to public;
6777create index idx_name on t(x);
6778drop index public.idx_name$0;
6779"#), @r"
6780 ╭▸
6781 3 │ create index idx_name on t(x);
6782 │ ──────── 2. destination
6783 4 │ drop index public.idx_name;
6784 ╰╴ ─ 1. source
6785 ");
6786 }
6787
6788 #[test]
6789 fn goto_drop_index_defined_after() {
6790 assert_snapshot!(goto("
6791drop index idx_name$0;
6792create index idx_name on t(x);
6793"), @r"
6794 ╭▸
6795 2 │ drop index idx_name;
6796 │ ─ 1. source
6797 3 │ create index idx_name on t(x);
6798 ╰╴ ──────── 2. destination
6799 ");
6800 }
6801
6802 #[test]
6803 fn goto_index_definition_returns_self() {
6804 assert_snapshot!(goto("
6805create index idx_name$0 on t(x);
6806"), @r"
6807 ╭▸
6808 2 │ create index idx_name on t(x);
6809 │ ┬──────┬
6810 │ │ │
6811 │ │ 1. source
6812 ╰╴ 2. destination
6813 ");
6814 }
6815
6816 #[test]
6817 fn goto_drop_index_with_search_path() {
6818 assert_snapshot!(goto(r#"
6819create index idx_name on t(x);
6820set search_path to bar;
6821create index idx_name on f(x);
6822set search_path to default;
6823drop index idx_name$0;
6824"#), @r"
6825 ╭▸
6826 2 │ create index idx_name on t(x);
6827 │ ──────── 2. destination
6828 ‡
6829 6 │ drop index idx_name;
6830 ╰╴ ─ 1. source
6831 ");
6832 }
6833
6834 #[test]
6835 fn goto_drop_index_schema_qualified() {
6836 assert_snapshot!(goto("
6837create schema a;
6838create schema b;
6839create table a.t(id int);
6840create table b.t(id int);
6841create index idx on a.t(id);
6842create index idx on b.t(id);
6843drop index b.idx$0;
6844"), @"
6845 ╭▸
6846 7 │ create index idx on b.t(id);
6847 │ ─── 2. destination
6848 8 │ drop index b.idx;
6849 ╰╴ ─ 1. source
6850 ");
6851 }
6852
6853 #[test]
6854 fn goto_drop_index_multiple() {
6855 assert_snapshot!(goto("
6856create index idx1 on t(x);
6857create index idx2 on t(y);
6858drop index idx1, idx2$0;
6859"), @r"
6860 ╭▸
6861 3 │ create index idx2 on t(y);
6862 │ ──── 2. destination
6863 4 │ drop index idx1, idx2;
6864 ╰╴ ─ 1. source
6865 ");
6866 }
6867
6868 #[test]
6869 fn goto_create_index_table() {
6870 assert_snapshot!(goto("
6871create table users(id int);
6872create index idx_users on users$0(id);
6873"), @r"
6874 ╭▸
6875 2 │ create table users(id int);
6876 │ ───── 2. destination
6877 3 │ create index idx_users on users(id);
6878 ╰╴ ─ 1. source
6879 ");
6880 }
6881
6882 #[test]
6883 fn goto_create_index_table_with_schema() {
6884 assert_snapshot!(goto("
6885create table public.users(id int);
6886create index idx_users on public.users$0(id);
6887"), @r"
6888 ╭▸
6889 2 │ create table public.users(id int);
6890 │ ───── 2. destination
6891 3 │ create index idx_users on public.users(id);
6892 ╰╴ ─ 1. source
6893 ");
6894 }
6895
6896 #[test]
6897 fn goto_create_index_table_with_search_path() {
6898 assert_snapshot!(goto(r#"
6899set search_path to foo;
6900create table foo.users(id int);
6901create index idx_users on users$0(id);
6902"#), @r"
6903 ╭▸
6904 3 │ create table foo.users(id int);
6905 │ ───── 2. destination
6906 4 │ create index idx_users on users(id);
6907 ╰╴ ─ 1. source
6908 ");
6909 }
6910
6911 #[test]
6912 fn goto_create_index_temp_table() {
6913 assert_snapshot!(goto("
6914create temp table users(id int);
6915create index idx_users on users$0(id);
6916"), @r"
6917 ╭▸
6918 2 │ create temp table users(id int);
6919 │ ───── 2. destination
6920 3 │ create index idx_users on users(id);
6921 ╰╴ ─ 1. source
6922 ");
6923 }
6924
6925 #[test]
6926 fn goto_create_index_column() {
6927 assert_snapshot!(goto("
6928create table users(id int, email text);
6929create index idx_email on users(email$0);
6930"), @r"
6931 ╭▸
6932 2 │ create table users(id int, email text);
6933 │ ───── 2. destination
6934 3 │ create index idx_email on users(email);
6935 ╰╴ ─ 1. source
6936 ");
6937 }
6938
6939 #[test]
6940 fn goto_create_index_first_column() {
6941 assert_snapshot!(goto("
6942create table users(id int, email text);
6943create index idx_id on users(id$0);
6944"), @r"
6945 ╭▸
6946 2 │ create table users(id int, email text);
6947 │ ── 2. destination
6948 3 │ create index idx_id on users(id);
6949 ╰╴ ─ 1. source
6950 ");
6951 }
6952
6953 #[test]
6954 fn goto_create_index_multiple_columns() {
6955 assert_snapshot!(goto("
6956create table users(id int, email text, name text);
6957create index idx_users on users(id, email$0, name);
6958"), @r"
6959 ╭▸
6960 2 │ create table users(id int, email text, name text);
6961 │ ───── 2. destination
6962 3 │ create index idx_users on users(id, email, name);
6963 ╰╴ ─ 1. source
6964 ");
6965 }
6966
6967 #[test]
6968 fn goto_create_index_column_with_schema() {
6969 assert_snapshot!(goto("
6970create table public.users(id int, email text);
6971create index idx_email on public.users(email$0);
6972"), @r"
6973 ╭▸
6974 2 │ create table public.users(id int, email text);
6975 │ ───── 2. destination
6976 3 │ create index idx_email on public.users(email);
6977 ╰╴ ─ 1. source
6978 ");
6979 }
6980
6981 #[test]
6982 fn goto_create_index_column_temp_table() {
6983 assert_snapshot!(goto("
6984create temp table users(id int, email text);
6985create index idx_email on users(email$0);
6986"), @r"
6987 ╭▸
6988 2 │ create temp table users(id int, email text);
6989 │ ───── 2. destination
6990 3 │ create index idx_email on users(email);
6991 ╰╴ ─ 1. source
6992 ");
6993 }
6994
6995 #[test]
6996 fn goto_create_index_include_column() {
6997 assert_snapshot!(goto("
6998create table users(id int, email text);
6999create index idx on users(id) include (email$0);
7000"), @r"
7001 ╭▸
7002 2 │ create table users(id int, email text);
7003 │ ───── 2. destination
7004 3 │ create index idx on users(id) include (email);
7005 ╰╴ ─ 1. source
7006 ");
7007 }
7008
7009 #[test]
7010 fn goto_create_index_where_column() {
7011 assert_snapshot!(goto("
7012create table users(id int, email text);
7013create index idx on users(id) where email$0 is not null;
7014"), @r"
7015 ╭▸
7016 2 │ create table users(id int, email text);
7017 │ ───── 2. destination
7018 3 │ create index idx on users(id) where email is not null;
7019 ╰╴ ─ 1. source
7020 ");
7021 }
7022
7023 #[test]
7024 fn goto_drop_function() {
7025 assert_snapshot!(goto("
7026create function foo() returns int as $$ select 1 $$ language sql;
7027drop function foo$0();
7028"), @r"
7029 ╭▸
7030 2 │ create function foo() returns int as $$ select 1 $$ language sql;
7031 │ ─── 2. destination
7032 3 │ drop function foo();
7033 ╰╴ ─ 1. source
7034 ");
7035 }
7036
7037 #[test]
7038 fn goto_drop_function_with_schema() {
7039 assert_snapshot!(goto("
7040set search_path to public;
7041create function foo() returns int as $$ select 1 $$ language sql;
7042drop function public.foo$0();
7043"), @r"
7044 ╭▸
7045 3 │ create function foo() returns int as $$ select 1 $$ language sql;
7046 │ ─── 2. destination
7047 4 │ drop function public.foo();
7048 ╰╴ ─ 1. source
7049 ");
7050 }
7051
7052 #[test]
7053 fn goto_drop_function_defined_after() {
7054 assert_snapshot!(goto("
7055drop function foo$0();
7056create function foo() returns int as $$ select 1 $$ language sql;
7057"), @r"
7058 ╭▸
7059 2 │ drop function foo();
7060 │ ─ 1. source
7061 3 │ create function foo() returns int as $$ select 1 $$ language sql;
7062 ╰╴ ─── 2. destination
7063 ");
7064 }
7065
7066 #[test]
7067 fn goto_function_definition_returns_self() {
7068 assert_snapshot!(goto("
7069create function foo$0() returns int as $$ select 1 $$ language sql;
7070"), @r"
7071 ╭▸
7072 2 │ create function foo() returns int as $$ select 1 $$ language sql;
7073 │ ┬─┬
7074 │ │ │
7075 │ │ 1. source
7076 ╰╴ 2. destination
7077 ");
7078 }
7079
7080 #[test]
7081 fn goto_drop_function_with_search_path() {
7082 assert_snapshot!(goto("
7083create function foo() returns int as $$ select 1 $$ language sql;
7084set search_path to bar;
7085create function foo() returns int as $$ select 1 $$ language sql;
7086set search_path to default;
7087drop function foo$0();
7088"), @r"
7089 ╭▸
7090 2 │ create function foo() returns int as $$ select 1 $$ language sql;
7091 │ ─── 2. destination
7092 ‡
7093 6 │ drop function foo();
7094 ╰╴ ─ 1. source
7095 ");
7096 }
7097
7098 #[test]
7099 fn goto_drop_function_multiple() {
7100 assert_snapshot!(goto("
7101create function foo() returns int as $$ select 1 $$ language sql;
7102create function bar() returns int as $$ select 1 $$ language sql;
7103drop function foo(), bar$0();
7104"), @r"
7105 ╭▸
7106 3 │ create function bar() returns int as $$ select 1 $$ language sql;
7107 │ ─── 2. destination
7108 4 │ drop function foo(), bar();
7109 ╰╴ ─ 1. source
7110 ");
7111 }
7112
7113 #[test]
7114 fn goto_drop_function_overloaded() {
7115 assert_snapshot!(goto("
7116create function add(complex) returns complex as $$ select null $$ language sql;
7117create function add(bigint) returns bigint as $$ select 1 $$ language sql;
7118drop function add$0(complex);
7119"), @r"
7120 ╭▸
7121 2 │ create function add(complex) returns complex as $$ select null $$ language sql;
7122 │ ─── 2. destination
7123 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
7124 4 │ drop function add(complex);
7125 ╰╴ ─ 1. source
7126 ");
7127 }
7128
7129 #[test]
7130 fn goto_drop_function_second_overload() {
7131 assert_snapshot!(goto("
7132create function add(complex) returns complex as $$ select null $$ language sql;
7133create function add(bigint) returns bigint as $$ select 1 $$ language sql;
7134drop function add$0(bigint);
7135"), @r"
7136 ╭▸
7137 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
7138 │ ─── 2. destination
7139 4 │ drop function add(bigint);
7140 ╰╴ ─ 1. source
7141 ");
7142 }
7143
7144 #[test]
7145 fn goto_select_function_call() {
7146 assert_snapshot!(goto("
7147create function foo() returns int as $$ select 1 $$ language sql;
7148select foo$0();
7149"), @r"
7150 ╭▸
7151 2 │ create function foo() returns int as $$ select 1 $$ language sql;
7152 │ ─── 2. destination
7153 3 │ select foo();
7154 ╰╴ ─ 1. source
7155 ");
7156 }
7157
7158 #[test]
7159 fn goto_select_column_from_function_return_table() {
7160 assert_snapshot!(goto(r#"
7161create function dup(int) returns table(f1 int, f2 text)
7162 as ''
7163 language sql;
7164
7165select f1$0 from dup(42);
7166"#), @r"
7167 ╭▸
7168 2 │ create function dup(int) returns table(f1 int, f2 text)
7169 │ ── 2. destination
7170 ‡
7171 6 │ select f1 from dup(42);
7172 ╰╴ ─ 1. source
7173 ");
7174 }
7175
7176 #[test]
7177 fn goto_select_column_from_function_return_table_with_schema() {
7178 assert_snapshot!(goto(r#"
7179create function myschema.dup(int) returns table(f1 int, f2 text)
7180 as ''
7181 language sql;
7182create function otherschema.dup(int) returns table(f1 int, f2 text)
7183 as ''
7184 language sql;
7185
7186select f1$0 from myschema.dup(42);
7187"#), @r"
7188 ╭▸
7189 2 │ create function myschema.dup(int) returns table(f1 int, f2 text)
7190 │ ── 2. destination
7191 ‡
7192 9 │ select f1 from myschema.dup(42);
7193 ╰╴ ─ 1. source
7194 ");
7195 }
7196
7197 #[test]
7198 fn goto_select_column_from_function_return_table_paren() {
7199 assert_snapshot!(goto(r#"
7200create function dup(int) returns table(f1 int, f2 text)
7201 as ''
7202 language sql;
7203
7204select (dup(42)).f2$0;
7205"#), @r"
7206 ╭▸
7207 2 │ create function dup(int) returns table(f1 int, f2 text)
7208 │ ── 2. destination
7209 ‡
7210 6 │ select (dup(42)).f2;
7211 ╰╴ ─ 1. source
7212 ");
7213 }
7214
7215 #[test]
7216 fn goto_select_column_from_function_return_table_qualified() {
7217 assert_snapshot!(goto(r#"
7218create function dup(int) returns table(f1 int, f2 text)
7219 as ''
7220 language sql;
7221
7222select dup.f1$0 from dup(42);
7223"#), @r"
7224 ╭▸
7225 2 │ create function dup(int) returns table(f1 int, f2 text)
7226 │ ── 2. destination
7227 ‡
7228 6 │ select dup.f1 from dup(42);
7229 ╰╴ ─ 1. source
7230 ");
7231 }
7232
7233 #[test]
7234 fn goto_select_column_from_function_return_table_qualified_function_name() {
7235 assert_snapshot!(goto(r#"
7236create function dup(int) returns table(f1 int, f2 text)
7237 as ''
7238 language sql;
7239
7240select dup$0.f1 from dup(42);
7241"#), @r"
7242 ╭▸
7243 2 │ create function dup(int) returns table(f1 int, f2 text)
7244 │ ─── 2. destination
7245 ‡
7246 6 │ select dup.f1 from dup(42);
7247 ╰╴ ─ 1. source
7248 ");
7249 }
7250
7251 #[test]
7252 fn goto_select_column_from_function_return_table_qualified_function_name_with_alias() {
7253 assert_snapshot!(goto(r#"
7254create function dup(int) returns table(f1 int, f2 text)
7255 as ''
7256 language sql;
7257
7258select dup$0.f2 from dup(42) as dup;
7259"#), @r"
7260 ╭▸
7261 6 │ select dup.f2 from dup(42) as dup;
7262 ╰╴ ─ 1. source ─── 2. destination
7263 ");
7264 }
7265
7266 #[test]
7267 fn goto_select_column_from_function_return_table_alias_list() {
7268 assert_snapshot!(goto(r#"
7269create function dup(int) returns table(f1 int, f2 text)
7270 as ''
7271 language sql;
7272
7273select a$0 from dup(42) t(a, b);
7274"#), @r"
7275 ╭▸
7276 6 │ select a from dup(42) t(a, b);
7277 ╰╴ ─ 1. source ─ 2. destination
7278 ");
7279 }
7280
7281 #[test]
7282 fn goto_select_column_from_function_return_table_alias_list_qualified_partial() {
7283 assert_snapshot!(goto(r#"
7284create function dup(int) returns table(f1 int, f2 text)
7285 as ''
7286 language sql;
7287
7288select u.f2$0 from dup(42) as u(x);
7289"#), @r"
7290 ╭▸
7291 2 │ create function dup(int) returns table(f1 int, f2 text)
7292 │ ── 2. destination
7293 ‡
7294 6 │ select u.f2 from dup(42) as u(x);
7295 ╰╴ ─ 1. source
7296 ");
7297 }
7298
7299 #[test]
7300 fn goto_select_column_from_function_return_table_alias_list_unqualified_partial() {
7301 assert_snapshot!(goto(r#"
7302create function dup(int) returns table(f1 int, f2 text)
7303 as ''
7304 language sql;
7305
7306select f2$0 from dup(42) as u(x);
7307"#), @r"
7308 ╭▸
7309 2 │ create function dup(int) returns table(f1 int, f2 text)
7310 │ ── 2. destination
7311 ‡
7312 6 │ select f2 from dup(42) as u(x);
7313 ╰╴ ─ 1. source
7314 ");
7315 }
7316
7317 #[test]
7318 fn goto_select_column_from_function_return_table_alias_list_unqualified_not_found() {
7319 goto_not_found(
7320 r#"
7321create function dup(int) returns table(f1 int, f2 text)
7322 as ''
7323 language sql;
7324
7325select f2$0 from dup(42) as u(x, y);
7326"#,
7327 );
7328 }
7329
7330 #[test]
7331 fn goto_select_column_from_function_returns_setof_table() {
7332 assert_snapshot!(goto("
7333create table users (id int, name text);
7334create function f() returns setof users
7335 language sql begin atomic select * from users; end;
7336select id$0 from f();
7337"), @"
7338 ╭▸
7339 2 │ create table users (id int, name text);
7340 │ ── 2. destination
7341 ‡
7342 5 │ select id from f();
7343 ╰╴ ─ 1. source
7344 ");
7345 }
7346
7347 #[test]
7348 fn goto_select_column_from_function_returns_setof_table_qualified() {
7349 assert_snapshot!(goto("
7350create table users (id int, name text);
7351create function f() returns setof users
7352 language sql begin atomic select * from users; end;
7353select f.id$0 from f();
7354"), @"
7355 ╭▸
7356 2 │ create table users (id int, name text);
7357 │ ── 2. destination
7358 ‡
7359 5 │ select f.id from f();
7360 ╰╴ ─ 1. source
7361 ");
7362 }
7363
7364 #[test]
7365 fn goto_select_column_from_function_returns_setof_composite_type() {
7366 assert_snapshot!(goto("
7367create type pt as (x int, y int);
7368create function f() returns setof pt language sql begin atomic select 1, 2; end;
7369select x$0 from f();
7370"), @"
7371 ╭▸
7372 2 │ create type pt as (x int, y int);
7373 │ ─ 2. destination
7374 3 │ create function f() returns setof pt language sql begin atomic select 1, 2; end;
7375 4 │ select x from f();
7376 ╰╴ ─ 1. source
7377 ");
7378 }
7379
7380 #[test]
7381 fn goto_select_column_from_scalar_setof_function_alias() {
7382 assert_snapshot!(goto("
7383create function nums() returns setof int language sql as $$ values (1) $$;
7384select n$0 from nums() as n;
7385"), @"
7386 ╭▸
7387 3 │ select n from nums() as n;
7388 ╰╴ ─ 1. source ─ 2. destination
7389 ");
7390 }
7391
7392 #[test]
7393 fn goto_select_column_from_scalar_setof_function_no_alias() {
7394 assert_snapshot!(goto("
7395create function nums() returns setof int language sql as $$ values (1) $$;
7396select nums$0 from nums();
7397"), @"
7398 ╭▸
7399 3 │ select nums from nums();
7400 │ ┬ ──── 2. destination
7401 │ │
7402 ╰╴ 1. source
7403 ");
7404 }
7405
7406 #[test]
7407 fn goto_select_column_from_scalar_setof_function_alias_with_column_list() {
7408 assert_snapshot!(goto("
7409create function nums() returns setof int language sql as $$ values (1) $$;
7410select x$0 from nums() as n(x);
7411"), @"
7412 ╭▸
7413 3 │ select x from nums() as n(x);
7414 ╰╴ ─ 1. source ─ 2. destination
7415 ");
7416 }
7417
7418 #[test]
7419 fn goto_select_column_from_function_out_param() {
7420 assert_snapshot!(goto("
7421create function f(out id int, out nm text) returns setof record
7422 language sql begin atomic select 1, 2; end;
7423select id$0 from f();
7424"), @"
7425 ╭▸
7426 2 │ create function f(out id int, out nm text) returns setof record
7427 │ ── 2. destination
7428 3 │ language sql begin atomic select 1, 2; end;
7429 4 │ select id from f();
7430 ╰╴ ─ 1. source
7431 ");
7432 }
7433
7434 #[test]
7435 fn goto_select_column_from_rows_from() {
7436 assert_snapshot!(goto("
7437create function f() returns table(a int) language sql begin atomic select 1; end;
7438select a$0 from rows from (f());
7439"), @"
7440 ╭▸
7441 2 │ create function f() returns table(a int) language sql begin atomic select 1; end;
7442 │ ─ 2. destination
7443 3 │ select a from rows from (f());
7444 ╰╴ ─ 1. source
7445 ");
7446 }
7447
7448 #[test]
7449 fn goto_select_column_from_xmltable() {
7450 assert_snapshot!(goto("
7451create table t (x xml);
7452select b$0 from t, xmltable(
7453 '/r' passing x
7454 columns b int
7455);
7456"), @"
7457 ╭▸
7458 3 │ select b from t, xmltable(
7459 │ ─ 1. source
7460 4 │ '/r' passing x
7461 5 │ columns b int
7462 ╰╴ ─ 2. destination
7463 ");
7464 }
7465
7466 #[test]
7467 fn goto_select_column_from_xmltable_aliased() {
7468 assert_snapshot!(goto("
7469create table t (x xml);
7470select xt.b$0 from t, xmltable(
7471 '/r' passing x
7472 columns b int
7473) as xt;
7474"), @"
7475 ╭▸
7476 3 │ select xt.b from t, xmltable(
7477 │ ─ 1. source
7478 4 │ '/r' passing x
7479 5 │ columns b int
7480 ╰╴ ─ 2. destination
7481 ");
7482 }
7483
7484 #[test]
7485 fn goto_xmltable_passing_clause_qualified_column() {
7486 assert_snapshot!(goto("
7487create table t (x xml);
7488select 1 from t, xmltable(
7489 '/r' passing t.x$0
7490 columns b int
7491);
7492"), @"
7493 ╭▸
7494 2 │ create table t (x xml);
7495 │ ─ 2. destination
7496 3 │ select 1 from t, xmltable(
7497 4 │ '/r' passing t.x
7498 ╰╴ ─ 1. source
7499 ");
7500 }
7501
7502 #[test]
7503 fn goto_select_column_from_json_table() {
7504 assert_snapshot!(goto("
7505create table t (j jsonb);
7506select b$0 from t, json_table(
7507 t.j, '$[*]'
7508 columns (b int path '$')
7509);
7510"), @"
7511 ╭▸
7512 3 │ select b from t, json_table(
7513 │ ─ 1. source
7514 4 │ t.j, '$[*]'
7515 5 │ columns (b int path '$')
7516 ╰╴ ─ 2. destination
7517 ");
7518 }
7519
7520 #[test]
7521 fn goto_json_table_context_item_qualified_column() {
7522 assert_snapshot!(goto("
7523create table t (j jsonb);
7524select 1 from t, json_table(
7525 t.j$0, '$[*]'
7526 columns (b int path '$')
7527);
7528"), @"
7529 ╭▸
7530 2 │ create table t (j jsonb);
7531 │ ─ 2. destination
7532 3 │ select 1 from t, json_table(
7533 4 │ t.j, '$[*]'
7534 ╰╴ ─ 1. source
7535 ");
7536 }
7537
7538 #[test]
7539 fn goto_json_table_plan_root_path() {
7540 assert_snapshot!(goto("
7541select * from json_table(
7542 '{}'::jsonb, '$' as root
7543 columns (
7544 nested path '$.items[*]' as items columns (
7545 value text path '$'
7546 )
7547 )
7548 plan (ro$0ot outer items)
7549);
7550"), @"
7551 ╭▸
7552 3 │ '{}'::jsonb, '$' as root
7553 │ ──── 2. destination
7554 ‡
7555 9 │ plan (root outer items)
7556 ╰╴ ─ 1. source
7557 ");
7558 }
7559
7560 #[test]
7561 fn goto_json_table_plan_nested_path() {
7562 assert_snapshot!(goto("
7563select * from json_table(
7564 '{}'::jsonb, '$' as root
7565 columns (
7566 nested path '$.items[*]' as items columns (
7567 value text path '$'
7568 )
7569 )
7570 plan (root outer ite$0ms)
7571);
7572"), @"
7573 ╭▸
7574 5 │ nested path '$.items[*]' as items columns (
7575 │ ───── 2. destination
7576 ‡
7577 9 │ plan (root outer items)
7578 ╰╴ ─ 1. source
7579 ");
7580 }
7581
7582 #[test]
7583 fn goto_fn_call_column_from_cte() {
7584 assert_snapshot!(goto("
7585with cte as (select 1 as a)
7586select a$0(cte) from cte;
7587"), @"
7588 ╭▸
7589 2 │ with cte as (select 1 as a)
7590 │ ─ 2. destination
7591 3 │ select a(cte) from cte;
7592 ╰╴ ─ 1. source
7593 ");
7594 }
7595
7596 #[test]
7597 fn goto_fn_call_column_from_view() {
7598 assert_snapshot!(goto("
7599create view v as select 1 as a;
7600select a$0(v) from v;
7601"), @"
7602 ╭▸
7603 2 │ create view v as select 1 as a;
7604 │ ─ 2. destination
7605 3 │ select a(v) from v;
7606 ╰╴ ─ 1. source
7607 ");
7608 }
7609
7610 #[test]
7611 fn goto_select_aggregate_call() {
7612 assert_snapshot!(goto("
7613create aggregate foo(int) (
7614 sfunc = int4pl,
7615 stype = int,
7616 initcond = '0'
7617);
7618
7619select foo$0(1);
7620"), @r"
7621 ╭▸
7622 2 │ create aggregate foo(int) (
7623 │ ─── 2. destination
7624 ‡
7625 8 │ select foo(1);
7626 ╰╴ ─ 1. source
7627 ");
7628 }
7629
7630 #[test]
7631 fn goto_create_aggregate_sfunc() {
7632 assert_snapshot!(goto("
7633create function pg_catalog.int8inc(bigint) returns bigint
7634 language internal;
7635
7636create aggregate pg_catalog.count(*) (
7637 sfunc = int8inc$0,
7638 stype = bigint,
7639 combinefunc = int8pl,
7640 initcond = '0'
7641);
7642"), @r"
7643 ╭▸
7644 2 │ create function pg_catalog.int8inc(bigint) returns bigint
7645 │ ─────── 2. destination
7646 ‡
7647 6 │ sfunc = int8inc,
7648 ╰╴ ─ 1. source
7649 "
7650 );
7651 }
7652
7653 #[test]
7654 fn goto_create_aggregate_combinefunc() {
7655 assert_snapshot!(goto("
7656create function pg_catalog.int8pl(bigint, bigint) returns bigint
7657 language internal;
7658
7659create aggregate pg_catalog.count(*) (
7660 sfunc = int8inc,
7661 stype = bigint,
7662 combinefunc = int8pl$0,
7663 initcond = '0'
7664);
7665"), @r"
7666 ╭▸
7667 2 │ create function pg_catalog.int8pl(bigint, bigint) returns bigint
7668 │ ────── 2. destination
7669 ‡
7670 8 │ combinefunc = int8pl,
7671 ╰╴ ─ 1. source
7672 "
7673 );
7674 }
7675
7676 #[test]
7677 fn goto_default_constraint_function_call() {
7678 assert_snapshot!(goto("
7679create function f() returns int as 'select 1' language sql;
7680create table t(
7681 a int default f$0()
7682);
7683"), @r"
7684 ╭▸
7685 2 │ create function f() returns int as 'select 1' language sql;
7686 │ ─ 2. destination
7687 3 │ create table t(
7688 4 │ a int default f()
7689 ╰╴ ─ 1. source
7690 ");
7691 }
7692
7693 #[test]
7694 fn goto_select_function_call_with_schema() {
7695 assert_snapshot!(goto("
7696create function public.foo() returns int as $$ select 1 $$ language sql;
7697select public.foo$0();
7698"), @r"
7699 ╭▸
7700 2 │ create function public.foo() returns int as $$ select 1 $$ language sql;
7701 │ ─── 2. destination
7702 3 │ select public.foo();
7703 ╰╴ ─ 1. source
7704 ");
7705 }
7706
7707 #[test]
7708 fn goto_select_function_call_with_search_path() {
7709 assert_snapshot!(goto("
7710set search_path to myschema;
7711create function foo() returns int as $$ select 1 $$ language sql;
7712select myschema.foo$0();
7713"), @r"
7714 ╭▸
7715 3 │ create function foo() returns int as $$ select 1 $$ language sql;
7716 │ ─── 2. destination
7717 4 │ select myschema.foo();
7718 ╰╴ ─ 1. source
7719 ");
7720 }
7721
7722 #[test]
7723 fn goto_function_call_style_column_access() {
7724 assert_snapshot!(goto("
7725create table t(a int, b int);
7726select a$0(t) from t;
7727"), @r"
7728 ╭▸
7729 2 │ create table t(a int, b int);
7730 │ ─ 2. destination
7731 3 │ select a(t) from t;
7732 ╰╴ ─ 1. source
7733 ");
7734 }
7735
7736 #[test]
7737 fn goto_function_call_style_column_access_with_function_precedence() {
7738 assert_snapshot!(goto("
7739create table t(a int, b int);
7740create function b(t) returns int as 'select 1' LANGUAGE sql;
7741select b$0(t) from t;
7742"), @r"
7743 ╭▸
7744 3 │ create function b(t) returns int as 'select 1' LANGUAGE sql;
7745 │ ─ 2. destination
7746 4 │ select b(t) from t;
7747 ╰╴ ─ 1. source
7748 ");
7749 }
7750
7751 #[test]
7752 fn goto_function_call_style_column_access_table_arg() {
7753 assert_snapshot!(goto("
7754create table t(a int, b int);
7755select a(t$0) from t;
7756"), @r"
7757 ╭▸
7758 2 │ create table t(a int, b int);
7759 │ ─ 2. destination
7760 3 │ select a(t) from t;
7761 ╰╴ ─ 1. source
7762 ");
7763 }
7764
7765 #[test]
7766 fn goto_function_call_style_column_access_table_arg_with_function() {
7767 assert_snapshot!(goto("
7768create table t(a int, b int);
7769create function b(t) returns int as 'select 1' LANGUAGE sql;
7770select b(t$0) from t;
7771"), @r"
7772 ╭▸
7773 2 │ create table t(a int, b int);
7774 │ ─ 2. destination
7775 3 │ create function b(t) returns int as 'select 1' LANGUAGE sql;
7776 4 │ select b(t) from t;
7777 ╰╴ ─ 1. source
7778 ");
7779 }
7780
7781 #[test]
7782 fn goto_function_call_multiple_args_not_column_access() {
7783 goto_not_found(
7784 "
7785create table t(a int, b int);
7786select a$0(t, 1) from t;
7787",
7788 );
7789 }
7790
7791 #[test]
7792 fn goto_function_call_nested() {
7793 assert_snapshot!(goto("
7794create function f() returns int8
7795 as 'select 1'
7796 language sql;
7797select format('foo%d', f$0());
7798"), @r"
7799 ╭▸
7800 2 │ create function f() returns int8
7801 │ ─ 2. destination
7802 ‡
7803 5 │ select format('foo%d', f());
7804 ╰╴ ─ 1. source
7805 ");
7806 }
7807
7808 #[test]
7809 fn goto_field_style_function_call() {
7810 assert_snapshot!(goto("
7811create table t(a int);
7812create function b(t) returns int as 'select 1' language sql;
7813select t.b$0 from t;
7814"), @r"
7815 ╭▸
7816 3 │ create function b(t) returns int as 'select 1' language sql;
7817 │ ─ 2. destination
7818 4 │ select t.b from t;
7819 ╰╴ ─ 1. source
7820 ");
7821 }
7822
7823 #[test]
7824 fn goto_field_style_function_call_column_precedence() {
7825 assert_snapshot!(goto("
7826create table t(a int, b int);
7827create function b(t) returns int as 'select 1' language sql;
7828select t.b$0 from t;
7829"), @r"
7830 ╭▸
7831 2 │ create table t(a int, b int);
7832 │ ─ 2. destination
7833 3 │ create function b(t) returns int as 'select 1' language sql;
7834 4 │ select t.b from t;
7835 ╰╴ ─ 1. source
7836 ");
7837 }
7838
7839 #[test]
7840 fn goto_field_style_function_call_table_ref() {
7841 assert_snapshot!(goto("
7842create table t(a int);
7843create function b(t) returns int as 'select 1' language sql;
7844select t$0.b from t;
7845"), @r"
7846 ╭▸
7847 2 │ create table t(a int);
7848 │ ─ 2. destination
7849 3 │ create function b(t) returns int as 'select 1' language sql;
7850 4 │ select t.b from t;
7851 ╰╴ ─ 1. source
7852 ");
7853 }
7854
7855 #[test]
7856 fn goto_function_call_style_in_where() {
7857 assert_snapshot!(goto("
7858create table t(a int, b int);
7859select * from t where a$0(t) > 0;
7860"), @r"
7861 ╭▸
7862 2 │ create table t(a int, b int);
7863 │ ─ 2. destination
7864 3 │ select * from t where a(t) > 0;
7865 ╰╴ ─ 1. source
7866 ");
7867 }
7868
7869 #[test]
7870 fn goto_function_call_style_in_where_function_precedence() {
7871 assert_snapshot!(goto("
7872create table t(a int, b int);
7873create function b(t) returns int as 'select 1' language sql;
7874select * from t where b$0(t) > 0;
7875"), @r"
7876 ╭▸
7877 3 │ create function b(t) returns int as 'select 1' language sql;
7878 │ ─ 2. destination
7879 4 │ select * from t where b(t) > 0;
7880 ╰╴ ─ 1. source
7881 ");
7882 }
7883
7884 #[test]
7885 fn goto_field_style_function_call_in_where() {
7886 assert_snapshot!(goto("
7887create table t(a int);
7888create function b(t) returns int as 'select 1' language sql;
7889select * from t where t.b$0 > 0;
7890"), @r"
7891 ╭▸
7892 3 │ create function b(t) returns int as 'select 1' language sql;
7893 │ ─ 2. destination
7894 4 │ select * from t where t.b > 0;
7895 ╰╴ ─ 1. source
7896 ");
7897 }
7898
7899 #[test]
7900 fn goto_field_style_in_where_column_precedence() {
7901 assert_snapshot!(goto("
7902create table t(a int, b int);
7903create function b(t) returns int as 'select 1' language sql;
7904select * from t where t.b$0 > 0;
7905"), @r"
7906 ╭▸
7907 2 │ create table t(a int, b int);
7908 │ ─ 2. destination
7909 3 │ create function b(t) returns int as 'select 1' language sql;
7910 4 │ select * from t where t.b > 0;
7911 ╰╴ ─ 1. source
7912 ");
7913 }
7914
7915 #[test]
7916 fn goto_function_call_style_table_arg_in_where() {
7917 assert_snapshot!(goto("
7918create table t(a int);
7919select * from t where a(t$0) > 2;
7920"), @r"
7921 ╭▸
7922 2 │ create table t(a int);
7923 │ ─ 2. destination
7924 3 │ select * from t where a(t) > 2;
7925 ╰╴ ─ 1. source
7926 ");
7927 }
7928
7929 #[test]
7930 fn goto_qualified_table_ref_in_where() {
7931 assert_snapshot!(goto("
7932create table t(a int);
7933create function b(t) returns int as 'select 1' language sql;
7934select * from t where t$0.b > 2;
7935"), @r"
7936 ╭▸
7937 2 │ create table t(a int);
7938 │ ─ 2. destination
7939 3 │ create function b(t) returns int as 'select 1' language sql;
7940 4 │ select * from t where t.b > 2;
7941 ╰╴ ─ 1. source
7942 ");
7943 }
7944
7945 #[test]
7946 fn goto_function_call_style_in_order_by() {
7947 assert_snapshot!(goto("
7948create table t(a int, b int);
7949create function b(t) returns int as 'select 1' language sql;
7950select * from t order by b$0(t);
7951"), @r"
7952 ╭▸
7953 3 │ create function b(t) returns int as 'select 1' language sql;
7954 │ ─ 2. destination
7955 4 │ select * from t order by b(t);
7956 ╰╴ ─ 1. source
7957 ");
7958 }
7959
7960 #[test]
7961 fn goto_field_style_in_order_by() {
7962 assert_snapshot!(goto("
7963create table t(a int);
7964create function b(t) returns int as 'select 1' language sql;
7965select * from t order by t.b$0;
7966"), @r"
7967 ╭▸
7968 3 │ create function b(t) returns int as 'select 1' language sql;
7969 │ ─ 2. destination
7970 4 │ select * from t order by t.b;
7971 ╰╴ ─ 1. source
7972 ");
7973 }
7974
7975 #[test]
7976 fn goto_function_call_style_in_group_by() {
7977 assert_snapshot!(goto("
7978create table t(a int, b int);
7979select * from t group by a$0(t);
7980"), @r"
7981 ╭▸
7982 2 │ create table t(a int, b int);
7983 │ ─ 2. destination
7984 3 │ select * from t group by a(t);
7985 ╰╴ ─ 1. source
7986 ");
7987 }
7988
7989 #[test]
7990 fn goto_field_style_in_group_by() {
7991 assert_snapshot!(goto("
7992create table t(a int);
7993create function b(t) returns int as 'select 1' language sql;
7994select * from t group by t.b$0;
7995"), @r"
7996 ╭▸
7997 3 │ create function b(t) returns int as 'select 1' language sql;
7998 │ ─ 2. destination
7999 4 │ select * from t group by t.b;
8000 ╰╴ ─ 1. source
8001 ");
8002 }
8003
8004 #[test]
8005 fn goto_select_alias_order_by_column_name_conflict() {
8006 assert_snapshot!(goto("
8010with t as (select 2 a)
8011select 1 a from t
8012order by a$0;
8013"), @"
8014 ╭▸
8015 3 │ select 1 a from t
8016 │ ─ 2. destination
8017 4 │ order by a;
8018 ╰╴ ─ 1. source
8019 ");
8020 }
8021
8022 #[test]
8023 fn goto_select_alias_not_picked_window_order_by() {
8024 assert_snapshot!(goto("
8025with t as (select 4 a union select 2 a)
8026-- should go to the column def, not the alias
8027select 2 a, a, row_number() over (order by a$0) from t;
8028"), @"
8029 ╭▸
8030 2 │ with t as (select 4 a union select 2 a)
8031 │ ─ 2. destination
8032 3 │ -- should go to the column def, not the alias
8033 4 │ select 2 a, a, row_number() over (order by a) from t;
8034 ╰╴ ─ 1. source
8035 ");
8036 }
8037
8038 #[test]
8039 fn goto_select_alias_group_by_alias_func() {
8040 assert_snapshot!(goto("
8041with t as (select 'x'::text as name)
8042select lower(name) from t
8043group by lower$0;
8044"), @"
8045 ╭▸
8046 3 │ select lower(name) from t
8047 │ ───── 2. destination
8048 4 │ group by lower;
8049 ╰╴ ─ 1. source
8050 ");
8051 }
8052
8053 #[test]
8054 fn goto_select_alias_order_by_alias_func() {
8055 assert_snapshot!(goto("
8056with t as (select 'x'::text as name)
8057select lower(name) from t
8058order by lower$0;
8059"), @"
8060 ╭▸
8061 3 │ select lower(name) from t
8062 │ ───── 2. destination
8063 4 │ order by lower;
8064 ╰╴ ─ 1. source
8065 ");
8066 }
8067
8068 #[test]
8069 fn goto_select_alias_group_by_column_name_conflict() {
8070 assert_snapshot!(goto("
8074with t as (select 2 a)
8075select 1 a from t
8076group by a$0;
8077"), @"
8078 ╭▸
8079 2 │ with t as (select 2 a)
8080 │ ─ 2. destination
8081 3 │ select 1 a from t
8082 4 │ group by a;
8083 ╰╴ ─ 1. source
8084 ");
8085 }
8086
8087 #[test]
8088 fn goto_select_alias_in_group_by_with_cte() {
8089 assert_snapshot!(goto("
8090with t as (select 2 b)
8091select 1 a from t
8092group by a$0;
8093"), @"
8094 ╭▸
8095 3 │ select 1 a from t
8096 │ ─ 2. destination
8097 4 │ group by a;
8098 ╰╴ ─ 1. source
8099 ");
8100 }
8101
8102 #[test]
8103 fn goto_select_alias_in_group_by_rollup() {
8104 assert_snapshot!(goto("
8105create table t (a int);
8106select a as x from t
8107group by rollup(x$0);
8108"), @"
8109 ╭▸
8110 3 │ select a as x from t
8111 │ ─ 2. destination
8112 4 │ group by rollup(x);
8113 ╰╴ ─ 1. source
8114 ");
8115 }
8116
8117 #[test]
8118 fn goto_select_alias_in_group_by_cube() {
8119 assert_snapshot!(goto("
8120create table t (a int);
8121select a as x from t
8122group by cube(x$0);
8123"), @"
8124 ╭▸
8125 3 │ select a as x from t
8126 │ ─ 2. destination
8127 4 │ group by cube(x);
8128 ╰╴ ─ 1. source
8129 ");
8130 }
8131
8132 #[test]
8133 fn goto_select_alias_in_group_by_grouping_sets() {
8134 assert_snapshot!(goto("
8135create table t (a int);
8136select a as x from t
8137group by grouping sets ((x$0));
8138"), @"
8139 ╭▸
8140 3 │ select a as x from t
8141 │ ─ 2. destination
8142 4 │ group by grouping sets ((x));
8143 ╰╴ ─ 1. source
8144 ");
8145 }
8146
8147 #[test]
8148 fn goto_select_alias_in_distinct_on() {
8149 assert_snapshot!(goto("
8150create table t (a int);
8151select distinct on (x$0) a as x from t;
8152"), @"
8153 ╭▸
8154 3 │ select distinct on (x) a as x from t;
8155 │ ┬ ─ 2. destination
8156 │ │
8157 ╰╴ 1. source
8158 ");
8159 }
8160
8161 #[test]
8162 fn goto_select_alias_expr_in_order_by_not_found() {
8163 goto_not_found(
8164 "
8165with t as (select 2 b)
8166select 1 a from t
8167order by a$0 + 1
8168",
8169 );
8170 }
8171
8172 #[test]
8173 fn goto_select_alias_expr_in_group_by_expr_not_found() {
8174 goto_not_found(
8175 "
8176with t as (select 2 b)
8177select 1 a from t
8178group by a$0 + 1
8179",
8180 );
8181 }
8182
8183 #[test]
8184 fn goto_update_alias_hides_table_name() {
8185 goto_not_found(
8186 "
8187create table t(a int);
8188update t as u set a = t$0.a;
8189",
8190 );
8191 }
8192
8193 #[test]
8194 fn goto_update_alias_hides_table_name_qualified_column() {
8195 goto_not_found(
8196 "
8197create table t(a int);
8198update t as u set a = t.a$0;
8199",
8200 );
8201 }
8202
8203 #[test]
8204 fn goto_insert_alias_hides_table_name() {
8205 goto_not_found(
8206 "
8207create table t(a int);
8208insert into t as u values (1) returning t$0.a;
8209",
8210 );
8211 }
8212
8213 #[test]
8214 fn goto_delete_alias_hides_table_name() {
8215 goto_not_found(
8216 "
8217create table t(a int);
8218delete from t as u where t$0.a = 1;
8219",
8220 );
8221 }
8222
8223 #[test]
8224 fn goto_delete_alias_hides_table_name_qualified_column() {
8225 goto_not_found(
8226 "
8227create table t(a int);
8228delete from t as u where t.a$0 = 1;
8229",
8230 );
8231 }
8232
8233 #[test]
8234 fn goto_merge_alias_hides_target_table_name() {
8235 goto_not_found(
8236 "
8237create table t(a int);
8238create table s(a int);
8239merge into t as u
8240 using s on t$0.a = s.a
8241 when matched then do nothing;
8242",
8243 );
8244 }
8245
8246 #[test]
8247 fn goto_merge_using_alias_hides_table_name() {
8248 goto_not_found(
8249 "
8250create table t(a int);
8251create table s(a int);
8252merge into t
8253 using s as u on s$0.a = t.a
8254 when matched then do nothing;
8255",
8256 );
8257 }
8258
8259 #[test]
8260 fn goto_merge_using_subquery_source_column() {
8261 assert_snapshot!(goto("
8262create table t(id int, val int);
8263merge into t
8264 using (select 1 as id, 2 as val) as s
8265 on t.id = s.id$0
8266 when not matched then
8267 insert (id, val) values (s.id, s.val);
8268"), @"
8269 ╭▸
8270 4 │ using (select 1 as id, 2 as val) as s
8271 │ ── 2. destination
8272 5 │ on t.id = s.id
8273 ╰╴ ─ 1. source
8274 ");
8275 }
8276
8277 #[test]
8278 fn goto_select_alias_in_order_by_with_cte() {
8279 assert_snapshot!(goto("
8280with t as (select 2 b)
8281select 1 a from t
8282order by a$0;
8283"), @"
8284 ╭▸
8285 3 │ select 1 a from t
8286 │ ─ 2. destination
8287 4 │ order by a;
8288 ╰╴ ─ 1. source
8289 ");
8290 }
8291
8292 #[test]
8293 fn goto_cte_table() {
8294 assert_snapshot!(goto("
8295with x as (select 1 as a)
8296select a from x$0;
8297"), @r"
8298 ╭▸
8299 2 │ with x as (select 1 as a)
8300 │ ─ 2. destination
8301 3 │ select a from x;
8302 ╰╴ ─ 1. source
8303 ");
8304 }
8305
8306 #[test]
8307 fn goto_cte_shadows_table_in_from() {
8308 assert_snapshot!(goto("
8309create table x(a int);
8310with x as (select 1 a)
8311select a from x$0;
8312"), @"
8313 ╭▸
8314 3 │ with x as (select 1 a)
8315 │ ─ 2. destination
8316 4 │ select a from x;
8317 ╰╴ ─ 1. source
8318 ");
8319 }
8320
8321 #[test]
8322 fn goto_cte_shadows_view_column() {
8323 assert_snapshot!(goto("
8324create view x as select 1 a;
8325with x as (select 2 a)
8326select a$0 from x;
8327"), @"
8328 ╭▸
8329 3 │ with x as (select 2 a)
8330 │ ─ 2. destination
8331 4 │ select a from x;
8332 ╰╴ ─ 1. source
8333 ");
8334 }
8335
8336 #[test]
8337 fn goto_cte_column() {
8338 assert_snapshot!(goto("
8339with x as (select 1 as a)
8340select a$0 from x;
8341"), @r"
8342 ╭▸
8343 2 │ with x as (select 1 as a)
8344 │ ─ 2. destination
8345 3 │ select a from x;
8346 ╰╴ ─ 1. source
8347 ");
8348 }
8349
8350 #[test]
8351 fn goto_cte_qualified_column_prefers_cte_over_table() {
8352 assert_snapshot!(goto("
8353create table u(id int, b int);
8354with u as (select 1 id, 2 b)
8355select u.id$0 from u;
8356"), @r"
8357 ╭▸
8358 3 │ with u as (select 1 id, 2 b)
8359 │ ── 2. destination
8360 4 │ select u.id from u;
8361 ╰╴ ─ 1. source
8362 ");
8363 }
8364
8365 #[test]
8366 fn goto_qualified_table_ref_prefers_schema_qualified_from_item_over_cte() {
8367 assert_snapshot!(goto("
8368create schema s;
8369create table s.t(a int);
8370with t as (select 1 a)
8371select t$0.a from s.t;
8372"), @r"
8373 ╭▸
8374 3 │ create table s.t(a int);
8375 │ ─ 2. destination
8376 4 │ with t as (select 1 a)
8377 5 │ select t.a from s.t;
8378 ╰╴ ─ 1. source
8379 ");
8380 }
8381
8382 #[test]
8383 fn goto_subquery_qualified_column() {
8384 assert_snapshot!(goto("
8385select t.a$0 from (select 1 a) t;
8386"), @r"
8387 ╭▸
8388 2 │ select t.a from (select 1 a) t;
8389 ╰╴ ─ 1. source ─ 2. destination
8390 ");
8391 }
8392
8393 #[test]
8394 fn goto_cte_multiple_columns() {
8395 assert_snapshot!(goto("
8396with x as (select 1 as a, 2 as b)
8397select b$0 from x;
8398"), @r"
8399 ╭▸
8400 2 │ with x as (select 1 as a, 2 as b)
8401 │ ─ 2. destination
8402 3 │ select b from x;
8403 ╰╴ ─ 1. source
8404 ");
8405 }
8406
8407 #[test]
8408 fn goto_cte_nested() {
8409 assert_snapshot!(goto("
8410with x as (select 1 as a),
8411 y as (select a from x)
8412select a$0 from y;
8413"), @r"
8414 ╭▸
8415 3 │ y as (select a from x)
8416 │ ─ 2. destination
8417 4 │ select a from y;
8418 ╰╴ ─ 1. source
8419 ");
8420 }
8421
8422 #[test]
8423 fn goto_cte_unnamed_column() {
8424 assert_snapshot!(goto(r#"
8425with x as (select 1)
8426select "?column?"$0 from x;
8427"#), @r#"
8428 ╭▸
8429 2 │ with x as (select 1)
8430 │ ─ 2. destination
8431 3 │ select "?column?" from x;
8432 ╰╴ ─ 1. source
8433 "#);
8434 }
8435
8436 #[test]
8437 fn goto_cte_star_expansion() {
8438 assert_snapshot!(goto("
8439with t as (select 1 a),
8440 y as (select * from t)
8441select a$0 from y;
8442"), @r"
8443 ╭▸
8444 2 │ with t as (select 1 a),
8445 │ ─ 2. destination
8446 3 │ y as (select * from t)
8447 4 │ select a from y;
8448 ╰╴ ─ 1. source
8449 ");
8450 }
8451
8452 #[test]
8453 fn goto_cte_qualified_star_join_column() {
8454 assert_snapshot!(goto("
8455create table u(id int, b int);
8456create table t(id int, a int);
8457
8458with k as (
8459 select u.* from t join u on a = b
8460)
8461select b$0 from k;
8462"), @r"
8463 ╭▸
8464 2 │ create table u(id int, b int);
8465 │ ─ 2. destination
8466 ‡
8467 8 │ select b from k;
8468 ╰╴ ─ 1. source
8469 ");
8470 }
8471
8472 #[test]
8473 fn goto_cte_qualified_star_join_column_with_partial_column_list() {
8474 assert_snapshot!(goto("
8475with
8476 u as (
8477 select 1 id, 2 b
8478 ),
8479 t as (
8480 select 1 id, 2 a
8481 ),
8482 k(x) as (
8483 select u.* from t join u on a = b
8484 )
8485select b$0 from k;
8486"), @r"
8487 ╭▸
8488 4 │ select 1 id, 2 b
8489 │ ─ 2. destination
8490 ‡
8491 12 │ select b from k;
8492 ╰╴ ─ 1. source
8493 ");
8494 }
8495
8496 #[test]
8497 fn goto_cte_reference_inside_cte() {
8498 assert_snapshot!(goto("
8499with t as (select 1 a),
8500 y as (select a$0 from t)
8501select a from y;
8502"), @r"
8503 ╭▸
8504 2 │ with t as (select 1 a),
8505 │ ─ 2. destination
8506 3 │ y as (select a from t)
8507 ╰╴ ─ 1. source
8508 ");
8509 }
8510
8511 #[test]
8512 fn goto_recursive_cte_reference_inside_cte() {
8513 assert_snapshot!(goto("
8514with recursive nums as (
8515 select 1 as n
8516 union all
8517 select n + 1 from nums$0 where n < 5
8518)
8519select * from nums;
8520"), @r"
8521 ╭▸
8522 2 │ with recursive nums as (
8523 │ ──── 2. destination
8524 ‡
8525 5 │ select n + 1 from nums where n < 5
8526 ╰╴ ─ 1. source
8527 ");
8528 }
8529
8530 #[test]
8531 fn goto_cte_search_clause_set_column() {
8532 assert_snapshot!(goto("
8533with recursive r as (select 1 as id)
8534 search depth first by id set ord
8535select ord$0 from r;
8536"), @"
8537 ╭▸
8538 3 │ search depth first by id set ord
8539 │ ─── 2. destination
8540 4 │ select ord from r;
8541 ╰╴ ─ 1. source
8542 ");
8543 }
8544
8545 #[test]
8546 fn goto_cte_search_clause_set_column_qualified() {
8547 assert_snapshot!(goto("
8548with recursive r as (select 1 as id)
8549 search depth first by id set ord
8550select r.ord$0 from r;
8551"), @"
8552 ╭▸
8553 3 │ search depth first by id set ord
8554 │ ─── 2. destination
8555 4 │ select r.ord from r;
8556 ╰╴ ─ 1. source
8557 ");
8558 }
8559
8560 #[test]
8561 fn goto_cte_cycle_clause_set_column() {
8562 assert_snapshot!(goto("
8563with recursive r as (select 1 as id)
8564 cycle id set is_cycle using path
8565select is_cycle$0 from r;
8566"), @"
8567 ╭▸
8568 3 │ cycle id set is_cycle using path
8569 │ ──────── 2. destination
8570 4 │ select is_cycle from r;
8571 ╰╴ ─ 1. source
8572 ");
8573 }
8574
8575 #[test]
8576 fn goto_cte_cycle_clause_path_column() {
8577 assert_snapshot!(goto("
8578with recursive r as (select 1 as id)
8579 cycle id set is_cycle using path
8580select path$0 from r;
8581"), @"
8582 ╭▸
8583 3 │ cycle id set is_cycle using path
8584 │ ──── 2. destination
8585 4 │ select path from r;
8586 ╰╴ ─ 1. source
8587 ");
8588 }
8589
8590 #[test]
8591 fn goto_cte_with_column_list() {
8592 assert_snapshot!(goto("
8593with t(a) as (select 1)
8594select a$0 from t;
8595"), @r"
8596 ╭▸
8597 2 │ with t(a) as (select 1)
8598 │ ─ 2. destination
8599 3 │ select a from t;
8600 ╰╴ ─ 1. source
8601 ");
8602 }
8603
8604 #[test]
8605 fn goto_cte_with_partial_column_list() {
8606 assert_snapshot!(goto("
8607with t(x) as (select 1 as a, 2 as b)
8608select b$0 from t;
8609"), @r"
8610 ╭▸
8611 2 │ with t(x) as (select 1 as a, 2 as b)
8612 │ ─ 2. destination
8613 3 │ select b from t;
8614 ╰╴ ─ 1. source
8615 ");
8616 }
8617
8618 #[test]
8619 fn goto_cte_with_partial_column_list_renamed() {
8620 assert_snapshot!(goto("
8621with t(x) as (select 1 as a, 2 as b)
8622select x$0 from t;
8623"), @r"
8624 ╭▸
8625 2 │ with t(x) as (select 1 as a, 2 as b)
8626 │ ─ 2. destination
8627 3 │ select x from t;
8628 ╰╴ ─ 1. source
8629 ");
8630 }
8631
8632 #[test]
8633 fn goto_cte_insert_returning_star_column() {
8634 assert_snapshot!(goto("
8635create table t(a int, b int);
8636with inserted as (
8637 insert into t values (1, 2), (3, 4)
8638 returning *
8639)
8640select a$0 from inserted;
8641"), @r"
8642 ╭▸
8643 2 │ create table t(a int, b int);
8644 │ ─ 2. destination
8645 ‡
8646 7 │ select a from inserted;
8647 ╰╴ ─ 1. source
8648 ");
8649 }
8650
8651 #[test]
8652 fn goto_cte_returning_qualified_star_column_gap() {
8653 assert_snapshot!(goto("
8654create table t(a int, b int);
8655with changed as (
8656 insert into t values (1, 2)
8657 returning new.*
8658)
8659select a$0 from changed;
8660"), @"
8661 ╭▸
8662 2 │ create table t(a int, b int);
8663 │ ─ 2. destination
8664 ‡
8665 7 │ select a from changed;
8666 ╰╴ ─ 1. source
8667 ");
8668 }
8669
8670 #[test]
8671 fn goto_cte_delete_returning_star_column() {
8672 assert_snapshot!(goto("
8673create table t(a int, b int);
8674with deleted as (
8675 delete from t
8676 returning *
8677)
8678select a$0 from deleted;
8679"), @r"
8680 ╭▸
8681 2 │ create table t(a int, b int);
8682 │ ─ 2. destination
8683 ‡
8684 7 │ select a from deleted;
8685 ╰╴ ─ 1. source
8686 ");
8687 }
8688
8689 #[test]
8690 fn goto_cte_update_returning_star_column() {
8691 assert_snapshot!(goto("
8692create table t(a int, b int);
8693with updated as (
8694 update t set a = 42
8695 returning *
8696)
8697select a$0 from updated;
8698"), @r"
8699 ╭▸
8700 2 │ create table t(a int, b int);
8701 │ ─ 2. destination
8702 ‡
8703 7 │ select a from updated;
8704 ╰╴ ─ 1. source
8705 ");
8706 }
8707
8708 #[test]
8709 fn goto_cte_update_returning_column_list_overwrites_column() {
8710 goto_not_found(
8711 "
8712create table t(a int, b int);
8713with updated(c) as (
8714 update t set a = 10
8715 returning a
8716)
8717select a$0 from updated;
8718",
8719 );
8720 }
8721
8722 #[test]
8723 fn goto_cte_column_list_overwrites_column() {
8724 goto_not_found(
8725 "
8726with t(x) as (select 1 as a)
8727select a$0 from t;
8728",
8729 );
8730 }
8731
8732 #[test]
8733 fn goto_cte_shadows_table() {
8734 assert_snapshot!(goto("
8735create table t(a int);
8736with t as (select a$0 from t)
8737select a from t;
8738"), @r"
8739 ╭▸
8740 2 │ create table t(a int);
8741 │ ─ 2. destination
8742 3 │ with t as (select a from t)
8743 ╰╴ ─ 1. source
8744 ");
8745 }
8746
8747 #[test]
8748 fn goto_subquery_column() {
8749 assert_snapshot!(goto("
8750select a$0 from (select 1 a);
8751"), @r"
8752 ╭▸
8753 2 │ select a from (select 1 a);
8754 ╰╴ ─ 1. source ─ 2. destination
8755 ");
8756 }
8757
8758 #[test]
8759 fn goto_subquery_star_partial_alias_masks_original_column_gap() {
8760 goto_not_found(
8761 "
8762create table t(a int, b int);
8763select a$0 from (select * from t) u(x);
8764",
8765 );
8766 }
8767
8768 #[test]
8769 fn goto_subquery_column_with_as() {
8770 assert_snapshot!(goto("
8771select a$0 from (select 1 as a);
8772"), @r"
8773 ╭▸
8774 2 │ select a from (select 1 as a);
8775 ╰╴ ─ 1. source ─ 2. destination
8776 ");
8777 }
8778
8779 #[test]
8780 fn goto_subquery_compound_select_column() {
8781 assert_snapshot!(goto("
8782select c$0 from (select 1 c union select 2 c);
8783"), @r"
8784 ╭▸
8785 2 │ select c from (select 1 c union select 2 c);
8786 ╰╴ ─ 1. source ─ 2. destination
8787 ");
8788 }
8789
8790 #[test]
8791 fn goto_subquery_compound_table_query_column() {
8792 assert_snapshot!(goto("
8793create table t(a int);
8794select a$0 from (table t union table t) u;
8795"), @"
8796 ╭▸
8797 2 │ create table t(a int);
8798 │ ─ 2. destination
8799 3 │ select a from (table t union table t) u;
8800 ╰╴ ─ 1. source
8801 ");
8802 }
8803
8804 #[test]
8805 fn goto_subquery_table_query_whole_row_alias() {
8806 assert_snapshot!(goto("
8807create table t(a int);
8808select t$0 from (table t) t;
8809"), @"
8810 ╭▸
8811 3 │ select t from (table t) t;
8812 ╰╴ ─ 1. source ─ 2. destination
8813 ");
8814 }
8815
8816 #[test]
8817 fn goto_subquery_compound_table_query_whole_row_alias() {
8818 assert_snapshot!(goto("
8819create table t(a int);
8820select t$0 from (table t union table t) t;
8821"), @"
8822 ╭▸
8823 3 │ select t from (table t union table t) t;
8824 ╰╴ ─ 1. source ─ 2. destination
8825 ");
8826 }
8827
8828 #[test]
8829 fn goto_subquery_compound_values_query_column() {
8830 assert_snapshot!(goto("
8831select column2$0 from (values (1, 2) union values (3, 4)) u;
8832"), @"
8833 ╭▸
8834 2 │ select column2 from (values (1, 2) union values (3, 4)) u;
8835 ╰╴ ─ 1. source ─ 2. destination
8836 ");
8837 }
8838
8839 #[test]
8840 fn goto_cte_compound_table_query_column() {
8841 assert_snapshot!(goto("
8842create table t(a int);
8843with u as (table t union table t)
8844select a$0 from u;
8845"), @"
8846 ╭▸
8847 2 │ create table t(a int);
8848 │ ─ 2. destination
8849 3 │ with u as (table t union table t)
8850 4 │ select a from u;
8851 ╰╴ ─ 1. source
8852 ");
8853 }
8854
8855 #[test]
8856 fn goto_cte_compound_values_query_column() {
8857 assert_snapshot!(goto("
8858with u as (values (1, 2) union values (3, 4))
8859select column2$0 from u;
8860"), @"
8861 ╭▸
8862 2 │ with u as (values (1, 2) union values (3, 4))
8863 │ ─ 2. destination
8864 3 │ select column2 from u;
8865 ╰╴ ─ 1. source
8866 ");
8867 }
8868
8869 #[test]
8870 fn goto_subquery_compound_select_column_order_by() {
8871 assert_snapshot!(goto("
8872with t as (select 1 a)
8873select 2 a from t union select 1 order by a$0;
8874"), @"
8875 ╭▸
8876 3 │ select 2 a from t union select 1 order by a;
8877 ╰╴ ─ 2. destination ─ 1. source
8878 ");
8879 }
8880
8881 #[test]
8882 fn goto_compound_table_query_column_order_by() {
8883 assert_snapshot!(goto("
8884create table t(a int);
8885table t union table t order by a$0;
8886"), @"
8887 ╭▸
8888 2 │ create table t(a int);
8889 │ ─ 2. destination
8890 3 │ table t union table t order by a;
8891 ╰╴ ─ 1. source
8892 ");
8893 }
8894
8895 #[test]
8896 fn goto_subquery_compound_select_column_with_nested_parens() {
8897 assert_snapshot!(goto("
8898with t as (
8899 select 1 as c
8900)
8901select c$0 from ((select * from t) union all (select * from t));
8902"), @r"
8903 ╭▸
8904 3 │ select 1 as c
8905 │ ─ 2. destination
8906 4 │ )
8907 5 │ select c from ((select * from t) union all (select * from t));
8908 ╰╴ ─ 1. source
8909 ");
8910 }
8911
8912 #[test]
8913 fn goto_subquery_column_multiple_columns() {
8914 assert_snapshot!(goto("
8915select b$0 from (select 1 a, 2 b);
8916"), @r"
8917 ╭▸
8918 2 │ select b from (select 1 a, 2 b);
8919 ╰╴ ─ 1. source ─ 2. destination
8920 ");
8921 }
8922
8923 #[test]
8924 fn goto_subquery_column_nested_parens() {
8925 assert_snapshot!(goto("
8926select a$0 from ((select 1 a));
8927"), @r"
8928 ╭▸
8929 2 │ select a from ((select 1 a));
8930 ╰╴ ─ 1. source ─ 2. destination
8931 ");
8932 }
8933
8934 #[test]
8935 fn goto_subquery_column_star_table() {
8936 assert_snapshot!(goto("
8937create table foo.t(a int);
8938select a$0 from (select * from foo.t);
8939"), @r"
8940 ╭▸
8941 2 │ create table foo.t(a int);
8942 │ ─ 2. destination
8943 3 │ select a from (select * from foo.t);
8944 ╰╴ ─ 1. source
8945 ");
8946 }
8947
8948 #[test]
8949 fn goto_subquery_column_qualified_star_join() {
8950 assert_snapshot!(goto("
8951create table t(a int);
8952create table u(b int);
8953select b$0 from (select u.* from t join u on a = b);
8954"), @r"
8955 ╭▸
8956 3 │ create table u(b int);
8957 │ ─ 2. destination
8958 4 │ select b from (select u.* from t join u on a = b);
8959 ╰╴ ─ 1. source
8960 ");
8961 }
8962
8963 #[test]
8964 fn goto_subquery_column_qualified_star_join_not_found() {
8965 goto_not_found(
8966 "
8967create table t(a int);
8968create table u(b int);
8969select a$0 from (select u.* from t join u on a = b);
8970",
8971 );
8972 }
8973
8974 #[test]
8975 fn goto_subquery_column_alias_list() {
8976 assert_snapshot!(goto("
8977select c$0, t.c from (select 1) t(c);
8978"), @r"
8979 ╭▸
8980 2 │ select c, t.c from (select 1) t(c);
8981 ╰╴ ─ 1. source ─ 2. destination
8982 ");
8983 }
8984
8985 #[test]
8986 fn goto_subquery_column_alias_list_qualified() {
8987 assert_snapshot!(goto("
8988select t.c$0 from (select 1) t(c);
8989"), @r"
8990 ╭▸
8991 2 │ select t.c from (select 1) t(c);
8992 ╰╴ ─ 1. source ─ 2. destination
8993 ");
8994 }
8995
8996 #[test]
8997 fn goto_subquery_column_alias_list_multiple() {
8998 assert_snapshot!(goto("
8999select b$0 from (select 1, 2) t(a, b);
9000"), @r"
9001 ╭▸
9002 2 │ select b from (select 1, 2) t(a, b);
9003 ╰╴ ─ 1. source ─ 2. destination
9004 ");
9005 }
9006
9007 #[test]
9008 fn goto_cte_column_alias_list() {
9009 assert_snapshot!(goto("
9010with x as (select 1)
9011select c$0 from x t(c);
9012"), @r"
9013 ╭▸
9014 3 │ select c from x t(c);
9015 │ ┬ ─ 2. destination
9016 │ │
9017 ╰╴ 1. source
9018 ");
9019 }
9020
9021 #[test]
9022 fn goto_cte_column_alias_list_qualified() {
9023 assert_snapshot!(goto("
9024with x as (select 1)
9025select t.c$0 from x t(c);
9026"), @r"
9027 ╭▸
9028 3 │ select t.c from x t(c);
9029 │ ┬ ─ 2. destination
9030 │ │
9031 ╰╴ 1. source
9032 ");
9033 }
9034
9035 #[test]
9036 fn goto_cte_column_alias_list_multiple() {
9037 assert_snapshot!(goto("
9038with x as (select 1, 2)
9039select b$0 from x t(a, b);
9040"), @r"
9041 ╭▸
9042 3 │ select b from x t(a, b);
9043 ╰╴ ─ 1. source ─ 2. destination
9044 ");
9045 }
9046
9047 #[test]
9048 fn goto_values_column_alias_list() {
9049 assert_snapshot!(goto("
9050select c$0 from (values (1)) t(c);
9051"), @r"
9052 ╭▸
9053 2 │ select c from (values (1)) t(c);
9054 ╰╴ ─ 1. source ─ 2. destination
9055 ");
9056 }
9057
9058 #[test]
9059 fn goto_values_column_alias_list_qualified() {
9060 assert_snapshot!(goto("
9061select t.c$0 from (values (1)) t(c);
9062"), @r"
9063 ╭▸
9064 2 │ select t.c from (values (1)) t(c);
9065 ╰╴ ─ 1. source ─ 2. destination
9066 ");
9067 }
9068
9069 #[test]
9070 fn goto_values_column_alias_list_multiple() {
9071 assert_snapshot!(goto("
9072select b$0 from (values (1, 2)) t(a, b);
9073"), @r"
9074 ╭▸
9075 2 │ select b from (values (1, 2)) t(a, b);
9076 ╰╴ ─ 1. source ─ 2. destination
9077 ");
9078 }
9079
9080 #[test]
9081 fn goto_values_column_alias_list_nested_parens() {
9082 assert_snapshot!(goto("
9083select n$0
9084from ((values (1), (2))) u(n);
9085"), @r"
9086 ╭▸
9087 2 │ select n
9088 │ ─ 1. source
9089 3 │ from ((values (1), (2))) u(n);
9090 ╰╴ ─ 2. destination
9091 ");
9092 }
9093
9094 #[test]
9095 fn goto_table_expr_column() {
9096 assert_snapshot!(goto("
9097create table t(a int, b int);
9098select a$0 from (table t);
9099"), @r"
9100 ╭▸
9101 2 │ create table t(a int, b int);
9102 │ ─ 2. destination
9103 3 │ select a from (table t);
9104 ╰╴ ─ 1. source
9105 ");
9106 }
9107
9108 #[test]
9109 fn goto_table_expr_column_with_cte() {
9110 assert_snapshot!(goto("
9111with x as (select 1 a)
9112select a$0 from (table x);
9113"), @r"
9114 ╭▸
9115 2 │ with x as (select 1 a)
9116 │ ─ 2. destination
9117 3 │ select a from (table x);
9118 ╰╴ ─ 1. source
9119 ");
9120 }
9121
9122 #[test]
9123 fn goto_table_expr_cte_table() {
9124 assert_snapshot!(goto("
9125with t as (select 1 a, 2 b)
9126select * from (table t$0);
9127"), @r"
9128 ╭▸
9129 2 │ with t as (select 1 a, 2 b)
9130 │ ─ 2. destination
9131 3 │ select * from (table t);
9132 ╰╴ ─ 1. source
9133 ");
9134 }
9135
9136 #[test]
9137 fn goto_table_expr_partial_column_alias_list() {
9138 assert_snapshot!(goto("
9139with t as (select 1 a, 2 b)
9140select c, b$0 from (table t) u(c);
9141"), @r"
9142 ╭▸
9143 2 │ with t as (select 1 a, 2 b)
9144 │ ─ 2. destination
9145 3 │ select c, b from (table t) u(c);
9146 ╰╴ ─ 1. source
9147 ");
9148 }
9149
9150 #[test]
9151 fn goto_subquery_partial_column_alias_list() {
9152 assert_snapshot!(goto("
9153select x, b$0 from (select 1 a, 2 b) t(x);
9154"), @r"
9155 ╭▸
9156 2 │ select x, b from (select 1 a, 2 b) t(x);
9157 ╰╴ ─ 1. source ─ 2. destination
9158 ");
9159 }
9160
9161 #[test]
9162 fn goto_subquery_alias_with_column_list_table_ref() {
9163 assert_snapshot!(goto("
9164with t as (select 1 a, 2 b)
9165select z$0 from (select * from t) as z(x, y);
9166"), @"
9167 ╭▸
9168 3 │ select z from (select * from t) as z(x, y);
9169 ╰╴ ─ 1. source ─ 2. destination
9170 ");
9171 }
9172
9173 #[test]
9174 fn goto_subquery_alias_with_column_list_table_ref_shadows_column() {
9175 assert_snapshot!(goto("
9176with t as (select 1 a, 2 b)
9177select z$0 from (select a as z, b from t) as z(x, y);
9178"), @"
9179 ╭▸
9180 3 │ select z from (select a as z, b from t) as z(x, y);
9181 ╰╴ ─ 1. source ─ 2. destination
9182 ");
9183 }
9184
9185 #[test]
9186 fn goto_subquery_nested_paren_alias_with_column_list_table_ref() {
9187 assert_snapshot!(goto("
9188with t as (select 1 a, 2 b, 3 c)
9189select z$0 from ((select * from t)) as z(x, y);
9190"), @"
9191 ╭▸
9192 3 │ select z from ((select * from t)) as z(x, y);
9193 ╰╴ ─ 1. source ─ 2. destination
9194 ");
9195 }
9196
9197 #[test]
9198 fn goto_table_expr_values_cte_partial_alias() {
9199 assert_snapshot!(goto("
9200with t as (values (1, 2), (3, 4))
9201select column2$0 from (table t) u(a);
9202"), @r"
9203 ╭▸
9204 2 │ with t as (values (1, 2), (3, 4))
9205 │ ─ 2. destination
9206 3 │ select column2 from (table t) u(a);
9207 ╰╴ ─ 1. source
9208 ");
9209 }
9210
9211 #[test]
9212 fn goto_cte_with_table_expr() {
9213 assert_snapshot!(goto("
9214create table t(a int, b int);
9215with u as (table t)
9216select a$0 from u;
9217"), @r"
9218 ╭▸
9219 2 │ create table t(a int, b int);
9220 │ ─ 2. destination
9221 3 │ with u as (table t)
9222 4 │ select a from u;
9223 ╰╴ ─ 1. source
9224 ");
9225 }
9226
9227 #[test]
9228 fn goto_cte_with_table_expr_nested() {
9229 assert_snapshot!(goto("
9230with t as (select 1 a, 2 b),
9231 u as (table t)
9232select b$0 from u;
9233"), @r"
9234 ╭▸
9235 2 │ with t as (select 1 a, 2 b),
9236 │ ─ 2. destination
9237 3 │ u as (table t)
9238 4 │ select b from u;
9239 ╰╴ ─ 1. source
9240 ");
9241 }
9242
9243 #[test]
9244 fn goto_cte_paren_table_query_column() {
9245 assert_snapshot!(goto("
9246create table t(a int);
9247with u as ((table t))
9248select a$0 from u;
9249"), @"
9250 ╭▸
9251 2 │ create table t(a int);
9252 │ ─ 2. destination
9253 3 │ with u as ((table t))
9254 4 │ select a from u;
9255 ╰╴ ─ 1. source
9256 ");
9257 }
9258
9259 #[test]
9260 fn goto_cte_paren_values_query_column() {
9261 assert_snapshot!(goto("
9262with u as ((values (1, 2)))
9263select column2$0 from u;
9264"), @"
9265 ╭▸
9266 2 │ with u as ((values (1, 2)))
9267 │ ─ 2. destination
9268 3 │ select column2 from u;
9269 ╰╴ ─ 1. source
9270 ");
9271 }
9272
9273 #[test]
9274 fn goto_cte_table_query_column_count_gap() {
9275 assert_snapshot!(goto("
9276create table t(a int, b int);
9277with u as (table t)
9278select b$0 from (select * from u) x(a);
9279"), @"
9280 ╭▸
9281 2 │ create table t(a int, b int);
9282 │ ─ 2. destination
9283 3 │ with u as (table t)
9284 4 │ select b from (select * from u) x(a);
9285 ╰╴ ─ 1. source
9286 ");
9287 }
9288
9289 #[test]
9290 fn goto_insert_table() {
9291 assert_snapshot!(goto("
9292create table users(id int, email text);
9293insert into users$0(id, email) values (1, 'test@example.com');
9294"), @r"
9295 ╭▸
9296 2 │ create table users(id int, email text);
9297 │ ───── 2. destination
9298 3 │ insert into users(id, email) values (1, 'test@example.com');
9299 ╰╴ ─ 1. source
9300 ");
9301 }
9302
9303 #[test]
9304 fn goto_insert_table_with_schema() {
9305 assert_snapshot!(goto("
9306create table public.users(id int, email text);
9307insert into public.users$0(id, email) values (1, 'test@example.com');
9308"), @r"
9309 ╭▸
9310 2 │ create table public.users(id int, email text);
9311 │ ───── 2. destination
9312 3 │ insert into public.users(id, email) values (1, 'test@example.com');
9313 ╰╴ ─ 1. source
9314 ");
9315 }
9316
9317 #[test]
9318 fn goto_insert_view() {
9319 assert_snapshot!(goto("
9320create table users as select 1 id, 'joe' name, 'joe@example.com' email, 'active' status;
9321create view active_users as
9322 select id, name, email
9323 from users
9324 where status = 'active';
9325insert into active_users$0 (name, email)
9326values ('Alice', 'alice@example.com');
9327"), @"
9328 ╭▸
9329 3 │ create view active_users as
9330 │ ──────────── 2. destination
9331 ‡
9332 7 │ insert into active_users (name, email)
9333 ╰╴ ─ 1. source
9334 ");
9335 }
9336
9337 #[test]
9338 fn goto_insert_column() {
9339 assert_snapshot!(goto("
9340create table users(id int, email text);
9341insert into users(id$0, email) values (1, 'test@example.com');
9342"), @r"
9343 ╭▸
9344 2 │ create table users(id int, email text);
9345 │ ── 2. destination
9346 3 │ insert into users(id, email) values (1, 'test@example.com');
9347 ╰╴ ─ 1. source
9348 ");
9349 }
9350
9351 #[test]
9352 fn goto_insert_column_second() {
9353 assert_snapshot!(goto("
9354create table users(id int, email text);
9355insert into users(id, email$0) values (1, 'test@example.com');
9356"), @r"
9357 ╭▸
9358 2 │ create table users(id int, email text);
9359 │ ───── 2. destination
9360 3 │ insert into users(id, email) values (1, 'test@example.com');
9361 ╰╴ ─ 1. source
9362 ");
9363 }
9364
9365 #[test]
9366 fn goto_insert_column_with_schema() {
9367 assert_snapshot!(goto("
9368create table public.users(id int, email text);
9369insert into public.users(email$0) values ('test@example.com');
9370"), @r"
9371 ╭▸
9372 2 │ create table public.users(id int, email text);
9373 │ ───── 2. destination
9374 3 │ insert into public.users(email) values ('test@example.com');
9375 ╰╴ ─ 1. source
9376 ");
9377 }
9378
9379 #[test]
9380 fn goto_insert_table_with_search_path() {
9381 assert_snapshot!(goto("
9382set search_path to foo;
9383create table foo.users(id int, email text);
9384insert into users$0(id, email) values (1, 'test@example.com');
9385"), @r"
9386 ╭▸
9387 3 │ create table foo.users(id int, email text);
9388 │ ───── 2. destination
9389 4 │ insert into users(id, email) values (1, 'test@example.com');
9390 ╰╴ ─ 1. source
9391 ");
9392 }
9393
9394 #[test]
9395 fn goto_insert_column_with_search_path() {
9396 assert_snapshot!(goto("
9397set search_path to myschema;
9398create table myschema.users(id int, email text, name text);
9399insert into users(email$0, name) values ('test@example.com', 'Test');
9400"), @r"
9401 ╭▸
9402 3 │ create table myschema.users(id int, email text, name text);
9403 │ ───── 2. destination
9404 4 │ insert into users(email, name) values ('test@example.com', 'Test');
9405 ╰╴ ─ 1. source
9406 ");
9407 }
9408
9409 #[test]
9410 fn goto_delete_table() {
9411 assert_snapshot!(goto("
9412create table users(id int, email text);
9413delete from users$0 where id = 1;
9414"), @r"
9415 ╭▸
9416 2 │ create table users(id int, email text);
9417 │ ───── 2. destination
9418 3 │ delete from users where id = 1;
9419 ╰╴ ─ 1. source
9420 ");
9421 }
9422
9423 #[test]
9424 fn goto_delete_table_with_schema() {
9425 assert_snapshot!(goto("
9426create table public.users(id int, email text);
9427delete from public.users$0 where id = 1;
9428"), @r"
9429 ╭▸
9430 2 │ create table public.users(id int, email text);
9431 │ ───── 2. destination
9432 3 │ delete from public.users where id = 1;
9433 ╰╴ ─ 1. source
9434 ");
9435 }
9436
9437 #[test]
9438 fn goto_delete_table_with_search_path() {
9439 assert_snapshot!(goto("
9440set search_path to foo;
9441create table foo.users(id int, email text);
9442delete from users$0 where id = 1;
9443"), @r"
9444 ╭▸
9445 3 │ create table foo.users(id int, email text);
9446 │ ───── 2. destination
9447 4 │ delete from users where id = 1;
9448 ╰╴ ─ 1. source
9449 ");
9450 }
9451
9452 #[test]
9453 fn goto_delete_temp_table() {
9454 assert_snapshot!(goto("
9455create temp table users(id int, email text);
9456delete from users$0 where id = 1;
9457"), @r"
9458 ╭▸
9459 2 │ create temp table users(id int, email text);
9460 │ ───── 2. destination
9461 3 │ delete from users where id = 1;
9462 ╰╴ ─ 1. source
9463 ");
9464 }
9465
9466 #[test]
9467 fn goto_delete_where_column() {
9468 assert_snapshot!(goto("
9469create table users(id int, email text);
9470delete from users where id$0 = 1;
9471"), @r"
9472 ╭▸
9473 2 │ create table users(id int, email text);
9474 │ ── 2. destination
9475 3 │ delete from users where id = 1;
9476 ╰╴ ─ 1. source
9477 ");
9478 }
9479
9480 #[test]
9481 fn goto_delete_where_column_second() {
9482 assert_snapshot!(goto("
9483create table users(id int, email text);
9484delete from users where email$0 = 'test@example.com';
9485"), @r"
9486 ╭▸
9487 2 │ create table users(id int, email text);
9488 │ ───── 2. destination
9489 3 │ delete from users where email = 'test@example.com';
9490 ╰╴ ─ 1. source
9491 ");
9492 }
9493
9494 #[test]
9495 fn goto_delete_where_column_with_schema() {
9496 assert_snapshot!(goto("
9497create table public.users(id int, email text, name text);
9498delete from public.users where name$0 = 'Test';
9499"), @r"
9500 ╭▸
9501 2 │ create table public.users(id int, email text, name text);
9502 │ ──── 2. destination
9503 3 │ delete from public.users where name = 'Test';
9504 ╰╴ ─ 1. source
9505 ");
9506 }
9507
9508 #[test]
9509 fn goto_delete_where_column_with_search_path() {
9510 assert_snapshot!(goto("
9511set search_path to myschema;
9512create table myschema.users(id int, email text, active boolean);
9513delete from users where active$0 = true;
9514"), @r"
9515 ╭▸
9516 3 │ create table myschema.users(id int, email text, active boolean);
9517 │ ────── 2. destination
9518 4 │ delete from users where active = true;
9519 ╰╴ ─ 1. source
9520 ");
9521 }
9522
9523 #[test]
9524 fn goto_delete_where_multiple_columns() {
9525 assert_snapshot!(goto("
9526create table users(id int, email text, active boolean);
9527delete from users where id$0 = 1 and active = true;
9528"), @r"
9529 ╭▸
9530 2 │ create table users(id int, email text, active boolean);
9531 │ ── 2. destination
9532 3 │ delete from users where id = 1 and active = true;
9533 ╰╴ ─ 1. source
9534 ");
9535 }
9536
9537 #[test]
9538 fn goto_delete_using_table() {
9539 assert_snapshot!(goto("
9540create table t(id int, f_id int);
9541create table f(id int, name text);
9542delete from t using f$0 where f_id = f.id and f.name = 'foo';
9543"), @r"
9544 ╭▸
9545 3 │ create table f(id int, name text);
9546 │ ─ 2. destination
9547 4 │ delete from t using f where f_id = f.id and f.name = 'foo';
9548 ╰╴ ─ 1. source
9549 ");
9550 }
9551
9552 #[test]
9553 fn goto_delete_using_table_with_schema() {
9554 assert_snapshot!(goto("
9555create table t(id int, f_id int);
9556create table public.f(id int, name text);
9557delete from t using public.f$0 where f_id = f.id;
9558"), @r"
9559 ╭▸
9560 3 │ create table public.f(id int, name text);
9561 │ ─ 2. destination
9562 4 │ delete from t using public.f where f_id = f.id;
9563 ╰╴ ─ 1. source
9564 ");
9565 }
9566
9567 #[test]
9568 fn goto_delete_using_column_in_where() {
9569 assert_snapshot!(goto("
9570create table t(id int, f_id int);
9571create table f(id int, name text);
9572delete from t using f where f_id = f.id$0 and f.name = 'foo';
9573"), @"
9574 ╭▸
9575 3 │ create table f(id int, name text);
9576 │ ── 2. destination
9577 4 │ delete from t using f where f_id = f.id and f.name = 'foo';
9578 ╰╴ ─ 1. source
9579 ");
9580 }
9581
9582 #[test]
9583 fn goto_delete_using_source_alias_qualifier() {
9584 assert_snapshot!(goto("
9585create table target(id int);
9586create table src(y int);
9587delete from target using src s where s$0.y = target.id;
9588"), @"
9589 ╭▸
9590 4 │ delete from target using src s where s.y = target.id;
9591 │ ┬ ─ 1. source
9592 │ │
9593 ╰╴ 2. destination
9594 ");
9595 }
9596
9597 #[test]
9598 fn goto_delete_using_source_alias_column() {
9599 assert_snapshot!(goto("
9600create table target(id int);
9601create table src(y int);
9602delete from target using src s where s.y$0 = target.id;
9603"), @"
9604 ╭▸
9605 3 │ create table src(y int);
9606 │ ─ 2. destination
9607 4 │ delete from target using src s where s.y = target.id;
9608 ╰╴ ─ 1. source
9609 ");
9610 }
9611
9612 #[test]
9613 fn goto_select_from_table() {
9614 assert_snapshot!(goto("
9615create table users(id int, email text);
9616select * from users$0;
9617"), @r"
9618 ╭▸
9619 2 │ create table users(id int, email text);
9620 │ ───── 2. destination
9621 3 │ select * from users;
9622 ╰╴ ─ 1. source
9623 ");
9624 }
9625
9626 #[test]
9627 fn goto_select_from_table_with_schema() {
9628 assert_snapshot!(goto("
9629create table public.users(id int, email text);
9630select * from public.users$0;
9631"), @r"
9632 ╭▸
9633 2 │ create table public.users(id int, email text);
9634 │ ───── 2. destination
9635 3 │ select * from public.users;
9636 ╰╴ ─ 1. source
9637 ");
9638 }
9639
9640 #[test]
9641 fn goto_select_from_table_with_search_path() {
9642 assert_snapshot!(goto("
9643set search_path to foo;
9644create table foo.users(id int, email text);
9645select * from users$0;
9646"), @r"
9647 ╭▸
9648 3 │ create table foo.users(id int, email text);
9649 │ ───── 2. destination
9650 4 │ select * from users;
9651 ╰╴ ─ 1. source
9652 ");
9653 }
9654
9655 #[test]
9656 fn goto_select_from_temp_table() {
9657 assert_snapshot!(goto("
9658create temp table users(id int, email text);
9659select * from users$0;
9660"), @r"
9661 ╭▸
9662 2 │ create temp table users(id int, email text);
9663 │ ───── 2. destination
9664 3 │ select * from users;
9665 ╰╴ ─ 1. source
9666 ");
9667 }
9668
9669 #[test]
9670 fn goto_select_from_table_defined_after() {
9671 assert_snapshot!(goto("
9672select * from users$0;
9673create table users(id int, email text);
9674"), @r"
9675 ╭▸
9676 2 │ select * from users;
9677 │ ─ 1. source
9678 3 │ create table users(id int, email text);
9679 ╰╴ ───── 2. destination
9680 ");
9681 }
9682
9683 #[test]
9684 fn goto_select_column() {
9685 assert_snapshot!(goto("
9686create table users(id int, email text);
9687select id$0 from users;
9688"), @r"
9689 ╭▸
9690 2 │ create table users(id int, email text);
9691 │ ── 2. destination
9692 3 │ select id from users;
9693 ╰╴ ─ 1. source
9694 ");
9695 }
9696
9697 #[test]
9698 fn goto_select_column_second() {
9699 assert_snapshot!(goto("
9700create table users(id int, email text);
9701select id, email$0 from users;
9702"), @r"
9703 ╭▸
9704 2 │ create table users(id int, email text);
9705 │ ───── 2. destination
9706 3 │ select id, email from users;
9707 ╰╴ ─ 1. source
9708 ");
9709 }
9710
9711 #[test]
9712 fn goto_select_column_with_schema() {
9713 assert_snapshot!(goto("
9714create table public.users(id int, email text);
9715select email$0 from public.users;
9716"), @r"
9717 ╭▸
9718 2 │ create table public.users(id int, email text);
9719 │ ───── 2. destination
9720 3 │ select email from public.users;
9721 ╰╴ ─ 1. source
9722 ");
9723 }
9724
9725 #[test]
9726 fn goto_select_column_with_search_path() {
9727 assert_snapshot!(goto("
9728set search_path to foo;
9729create table foo.users(id int, email text);
9730select id$0 from users;
9731"), @r"
9732 ╭▸
9733 3 │ create table foo.users(id int, email text);
9734 │ ── 2. destination
9735 4 │ select id from users;
9736 ╰╴ ─ 1. source
9737 ");
9738 }
9739
9740 #[test]
9741 fn goto_select_table_as_column() {
9742 assert_snapshot!(goto("
9743create table t(x bigint, y bigint);
9744select t$0 from t;
9745"), @r"
9746 ╭▸
9747 2 │ create table t(x bigint, y bigint);
9748 │ ─ 2. destination
9749 3 │ select t from t;
9750 ╰╴ ─ 1. source
9751 ");
9752 }
9753
9754 #[test]
9755 fn goto_select_table_star_expansion() {
9756 assert_snapshot!(goto("
9757create table t(id int, a int);
9758select t$0.* from t;
9759"), @r"
9760 ╭▸
9761 2 │ create table t(id int, a int);
9762 │ ─ 2. destination
9763 3 │ select t.* from t;
9764 ╰╴ ─ 1. source
9765 ");
9766 }
9767
9768 #[test]
9769 fn goto_select_table_as_column_with_schema() {
9770 assert_snapshot!(goto("
9771create table public.t(x bigint, y bigint);
9772select t$0 from public.t;
9773"), @r"
9774 ╭▸
9775 2 │ create table public.t(x bigint, y bigint);
9776 │ ─ 2. destination
9777 3 │ select t from public.t;
9778 ╰╴ ─ 1. source
9779 ");
9780 }
9781
9782 #[test]
9783 fn goto_select_table_as_column_with_search_path() {
9784 assert_snapshot!(goto("
9785set search_path to foo;
9786create table foo.users(id int, email text);
9787select users$0 from users;
9788"), @r"
9789 ╭▸
9790 3 │ create table foo.users(id int, email text);
9791 │ ───── 2. destination
9792 4 │ select users from users;
9793 ╰╴ ─ 1. source
9794 ");
9795 }
9796
9797 #[test]
9798 fn goto_select_column_with_same_name_as_table() {
9799 assert_snapshot!(goto("
9800create table t(t int);
9801select t$0 from t;
9802"), @r"
9803 ╭▸
9804 2 │ create table t(t int);
9805 │ ─ 2. destination
9806 3 │ select t from t;
9807 ╰╴ ─ 1. source
9808 ");
9809 }
9810
9811 #[test]
9812 fn goto_select_view_name_from_view() {
9813 assert_snapshot!(goto("
9814create view boop as select 1 a;
9815select boop$0 from boop;
9816"), @"
9817 ╭▸
9818 2 │ create view boop as select 1 a;
9819 │ ──── 2. destination
9820 3 │ select boop from boop;
9821 ╰╴ ─ 1. source
9822 ");
9823 }
9824
9825 #[test]
9826 fn goto_drop_schema() {
9827 assert_snapshot!(goto("
9828create schema foo;
9829drop schema foo$0;
9830"), @r"
9831 ╭▸
9832 2 │ create schema foo;
9833 │ ─── 2. destination
9834 3 │ drop schema foo;
9835 ╰╴ ─ 1. source
9836 ");
9837 }
9838
9839 #[test]
9840 fn goto_create_schema_authorization() {
9841 assert_snapshot!(goto("
9842create schema authorization foo$0;
9843"), @r"
9844 ╭▸
9845 2 │ create schema authorization foo;
9846 │ ┬─┬
9847 │ │ │
9848 │ │ 1. source
9849 ╰╴ 2. destination
9850 ");
9851 }
9852
9853 #[test]
9854 fn goto_drop_schema_authorization() {
9855 assert_snapshot!(goto("
9856create schema authorization foo;
9857drop schema foo$0;
9858"), @r"
9859 ╭▸
9860 2 │ create schema authorization foo;
9861 │ ─── 2. destination
9862 3 │ drop schema foo;
9863 ╰╴ ─ 1. source
9864 ");
9865 }
9866
9867 #[test]
9868 fn goto_drop_schema_defined_after() {
9869 assert_snapshot!(goto("
9870drop schema foo$0;
9871create schema foo;
9872"), @r"
9873 ╭▸
9874 2 │ drop schema foo;
9875 │ ─ 1. source
9876 3 │ create schema foo;
9877 ╰╴ ─── 2. destination
9878 ");
9879 }
9880
9881 #[test]
9882 fn goto_create_schema_embedded_table() {
9883 assert_snapshot!(goto("
9884create schema app create table users(id int);
9885select id from app.users$0;
9886"), @"
9887 ╭▸
9888 2 │ create schema app create table users(id int);
9889 │ ───── 2. destination
9890 3 │ select id from app.users;
9891 ╰╴ ─ 1. source
9892 ");
9893 }
9894
9895 #[test]
9896 fn goto_create_schema_embedded_table_column() {
9897 assert_snapshot!(goto("
9898create schema app create table users(id int);
9899select id$0 from app.users;
9900"), @"
9901 ╭▸
9902 2 │ create schema app create table users(id int);
9903 │ ── 2. destination
9904 3 │ select id from app.users;
9905 ╰╴ ─ 1. source
9906 ");
9907 }
9908
9909 #[test]
9910 fn goto_create_schema_embedded_view() {
9911 assert_snapshot!(goto("
9912create schema app create table users(id int) create view v as select 1;
9913select 1 from app.v$0;
9914"), @"
9915 ╭▸
9916 2 │ create schema app create table users(id int) create view v as select 1;
9917 │ ─ 2. destination
9918 3 │ select 1 from app.v;
9919 ╰╴ ─ 1. source
9920 ");
9921 }
9922
9923 #[test]
9924 fn goto_schema_qualifier_in_table() {
9925 assert_snapshot!(goto("
9926create schema foo;
9927create table foo$0.t(a int);
9928"), @r"
9929 ╭▸
9930 2 │ create schema foo;
9931 │ ─── 2. destination
9932 3 │ create table foo.t(a int);
9933 ╰╴ ─ 1. source
9934 ");
9935 }
9936
9937 #[test]
9938 fn goto_schema_qualifier_in_drop_table() {
9939 assert_snapshot!(goto("
9940create schema foo;
9941create table foo.t(a int);
9942drop table foo$0.t;
9943"), @r"
9944 ╭▸
9945 2 │ create schema foo;
9946 │ ─── 2. destination
9947 3 │ create table foo.t(a int);
9948 4 │ drop table foo.t;
9949 ╰╴ ─ 1. source
9950 ");
9951 }
9952
9953 #[test]
9954 fn goto_schema_qualifier_multiple_schemas() {
9955 assert_snapshot!(goto("
9956create schema foo;
9957create schema bar;
9958create table bar$0.t(a int);
9959"), @r"
9960 ╭▸
9961 3 │ create schema bar;
9962 │ ─── 2. destination
9963 4 │ create table bar.t(a int);
9964 ╰╴ ─ 1. source
9965 ");
9966 }
9967
9968 #[test]
9969 fn goto_schema_qualifier_in_function_call() {
9970 assert_snapshot!(goto(r#"
9971create schema foo;
9972create function foo.bar() returns int as $$ begin return 1; end; $$ language plpgsql;
9973select foo$0.bar();
9974"#), @r"
9975 ╭▸
9976 2 │ create schema foo;
9977 │ ─── 2. destination
9978 3 │ create function foo.bar() returns int as $$ begin return 1; end; $$ language plpgsql;
9979 4 │ select foo.bar();
9980 ╰╴ ─ 1. source
9981 ");
9982 }
9983
9984 #[test]
9985 fn goto_schema_qualifier_in_function_call_from_clause() {
9986 assert_snapshot!(goto(r#"
9987create schema myschema;
9988create function myschema.get_data() returns table(id int) as $$ begin return query select 1; end; $$ language plpgsql;
9989select * from myschema$0.get_data();
9990"#), @r"
9991 ╭▸
9992 2 │ create schema myschema;
9993 │ ──────── 2. destination
9994 3 │ create function myschema.get_data() returns table(id int) as $$ begin return query select 1; end; $$ language plpgsql;
9995 4 │ select * from myschema.get_data();
9996 ╰╴ ─ 1. source
9997 ");
9998 }
9999
10000 #[test]
10001 fn goto_schema_qualifier_in_select_from() {
10002 assert_snapshot!(goto("
10003create schema foo;
10004create table foo.t(x int);
10005select x from foo$0.t;
10006"), @r"
10007 ╭▸
10008 2 │ create schema foo;
10009 │ ─── 2. destination
10010 3 │ create table foo.t(x int);
10011 4 │ select x from foo.t;
10012 ╰╴ ─ 1. source
10013 ");
10014 }
10015
10016 #[test]
10017 fn goto_qualified_column_table() {
10018 assert_snapshot!(goto("
10019create table t(a int);
10020select t$0.a from t;
10021"), @r"
10022 ╭▸
10023 2 │ create table t(a int);
10024 │ ─ 2. destination
10025 3 │ select t.a from t;
10026 ╰╴ ─ 1. source
10027 ");
10028 }
10029
10030 #[test]
10031 fn goto_qualified_column_column() {
10032 assert_snapshot!(goto("
10033create table t(a int);
10034select t.a$0 from t;
10035"), @r"
10036 ╭▸
10037 2 │ create table t(a int);
10038 │ ─ 2. destination
10039 3 │ select t.a from t;
10040 ╰╴ ─ 1. source
10041 ");
10042 }
10043
10044 #[test]
10045 fn goto_three_part_qualified_column_schema() {
10046 assert_snapshot!(goto("
10047create schema foo;
10048create table foo.t(a int);
10049select foo$0.t.a from t;
10050"), @r"
10051 ╭▸
10052 2 │ create schema foo;
10053 │ ─── 2. destination
10054 3 │ create table foo.t(a int);
10055 4 │ select foo.t.a from t;
10056 ╰╴ ─ 1. source
10057 ");
10058 }
10059
10060 #[test]
10061 fn goto_three_part_qualified_column_table() {
10062 assert_snapshot!(goto("
10063create schema foo;
10064create table foo.t(a int);
10065select foo.t$0.a from t;
10066"), @r"
10067 ╭▸
10068 3 │ create table foo.t(a int);
10069 │ ─ 2. destination
10070 4 │ select foo.t.a from t;
10071 ╰╴ ─ 1. source
10072 ");
10073 }
10074
10075 #[test]
10076 fn goto_three_part_qualified_column_column() {
10077 assert_snapshot!(goto("
10078create schema foo;
10079create table foo.t(a int);
10080select foo.t.a$0 from t;
10081"), @r"
10082 ╭▸
10083 3 │ create table foo.t(a int);
10084 │ ─ 2. destination
10085 4 │ select foo.t.a from t;
10086 ╰╴ ─ 1. source
10087 ");
10088 }
10089
10090 #[test]
10091 fn goto_cte_values_column1() {
10092 assert_snapshot!(goto("
10093with t as (
10094 values (1, 2), (3, 4)
10095)
10096select column1$0, column2 from t;
10097"), @r"
10098 ╭▸
10099 3 │ values (1, 2), (3, 4)
10100 │ ─ 2. destination
10101 4 │ )
10102 5 │ select column1, column2 from t;
10103 ╰╴ ─ 1. source
10104 ");
10105 }
10106
10107 #[test]
10108 fn goto_cte_values_column2() {
10109 assert_snapshot!(goto("
10110with t as (
10111 values (1, 2), (3, 4)
10112)
10113select column1, column2$0 from t;
10114"), @r"
10115 ╭▸
10116 3 │ values (1, 2), (3, 4)
10117 │ ─ 2. destination
10118 4 │ )
10119 5 │ select column1, column2 from t;
10120 ╰╴ ─ 1. source
10121 ");
10122 }
10123
10124 #[test]
10125 fn goto_cte_values_single_column() {
10126 assert_snapshot!(goto("
10127with t as (
10128 values (1), (2), (3)
10129)
10130select column1$0 from t;
10131"), @r"
10132 ╭▸
10133 3 │ values (1), (2), (3)
10134 │ ─ 2. destination
10135 4 │ )
10136 5 │ select column1 from t;
10137 ╰╴ ─ 1. source
10138 ");
10139 }
10140
10141 #[test]
10142 fn goto_cte_values_multiple_rows() {
10143 assert_snapshot!(goto("
10144with t as (
10145 values
10146 (1, 2, 3),
10147 (4, 5, 6),
10148 (7, 8, 9)
10149)
10150select column3$0 from t;
10151"), @r"
10152 ╭▸
10153 4 │ (1, 2, 3),
10154 │ ─ 2. destination
10155 ‡
10156 8 │ select column3 from t;
10157 ╰╴ ─ 1. source
10158 ");
10159 }
10160
10161 #[test]
10162 fn goto_cte_values_uppercase_column_names() {
10163 assert_snapshot!(goto("
10164with t as (
10165 values (1, 2), (3, 4)
10166)
10167select COLUMN1$0, COLUMN2 from t;
10168"), @r"
10169 ╭▸
10170 3 │ values (1, 2), (3, 4)
10171 │ ─ 2. destination
10172 4 │ )
10173 5 │ select COLUMN1, COLUMN2 from t;
10174 ╰╴ ─ 1. source
10175 ");
10176 }
10177
10178 #[test]
10179 fn goto_cte_values_with_explicit_column_list_column1_not_found() {
10180 goto_not_found(
10181 "
10182with t(a, b) as (
10183 values (1, 2), (3, 4)
10184)
10185select column1$0 from t;
10186",
10187 );
10188 }
10189
10190 #[test]
10191 fn goto_qualified_column_with_schema_in_from_table() {
10192 assert_snapshot!(goto("
10193create table foo.t(a int, b int);
10194select t$0.a from foo.t;
10195"), @r"
10196 ╭▸
10197 2 │ create table foo.t(a int, b int);
10198 │ ─ 2. destination
10199 3 │ select t.a from foo.t;
10200 ╰╴ ─ 1. source
10201 ");
10202 }
10203
10204 #[test]
10205 fn goto_qualified_column_with_schema_in_from_column() {
10206 assert_snapshot!(goto("
10207create table foo.t(a int, b int);
10208select t.a$0 from foo.t;
10209"), @r"
10210 ╭▸
10211 2 │ create table foo.t(a int, b int);
10212 │ ─ 2. destination
10213 3 │ select t.a from foo.t;
10214 ╰╴ ─ 1. source
10215 ");
10216 }
10217
10218 #[test]
10219 fn goto_cte_union_all_column() {
10220 assert_snapshot!(goto("
10221with t as (
10222 select 1 as a, 2 as b
10223 union all
10224 select 3, 4
10225)
10226select a$0, b from t;
10227"), @r"
10228 ╭▸
10229 3 │ select 1 as a, 2 as b
10230 │ ─ 2. destination
10231 ‡
10232 7 │ select a, b from t;
10233 ╰╴ ─ 1. source
10234 ");
10235 }
10236
10237 #[test]
10238 fn goto_cte_union_all_column_second() {
10239 assert_snapshot!(goto("
10240with t as (
10241 select 1 as a, 2 as b
10242 union all
10243 select 3, 4
10244)
10245select a, b$0 from t;
10246"), @r"
10247 ╭▸
10248 3 │ select 1 as a, 2 as b
10249 │ ─ 2. destination
10250 ‡
10251 7 │ select a, b from t;
10252 ╰╴ ─ 1. source
10253 ");
10254 }
10255
10256 #[test]
10257 fn goto_cte_union_column() {
10258 assert_snapshot!(goto("
10259with t as (
10260 select 1 as a, 2 as b
10261 union
10262 select 3, 4
10263)
10264select a$0 from t;
10265"), @r"
10266 ╭▸
10267 3 │ select 1 as a, 2 as b
10268 │ ─ 2. destination
10269 ‡
10270 7 │ select a from t;
10271 ╰╴ ─ 1. source
10272 ");
10273 }
10274
10275 #[test]
10276 fn goto_cte_insert_returning_column() {
10277 assert_snapshot!(goto("
10278create table t(a int, b int);
10279with inserted as (
10280 insert into t values (1, 2), (3, 4)
10281 returning a, b
10282)
10283select a$0 from inserted;
10284"), @r"
10285 ╭▸
10286 5 │ returning a, b
10287 │ ─ 2. destination
10288 6 │ )
10289 7 │ select a from inserted;
10290 ╰╴ ─ 1. source
10291 ");
10292 }
10293
10294 #[test]
10295 fn goto_cte_insert_returning_aliased_column() {
10296 assert_snapshot!(goto("
10297create table t(a int, b int);
10298with inserted as (
10299 insert into t values (1, 2), (3, 4)
10300 returning a as x
10301)
10302select x$0 from inserted;
10303"), @r"
10304 ╭▸
10305 5 │ returning a as x
10306 │ ─ 2. destination
10307 6 │ )
10308 7 │ select x from inserted;
10309 ╰╴ ─ 1. source
10310 ");
10311 }
10312
10313 #[test]
10314 fn goto_drop_aggregate() {
10315 assert_snapshot!(goto("
10316create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10317drop aggregate myavg$0(int);
10318"), @r"
10319 ╭▸
10320 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10321 │ ───── 2. destination
10322 3 │ drop aggregate myavg(int);
10323 ╰╴ ─ 1. source
10324 ");
10325 }
10326
10327 #[test]
10328 fn goto_drop_aggregate_with_schema() {
10329 assert_snapshot!(goto("
10330set search_path to public;
10331create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10332drop aggregate public.myavg$0(int);
10333"), @r"
10334 ╭▸
10335 3 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10336 │ ───── 2. destination
10337 4 │ drop aggregate public.myavg(int);
10338 ╰╴ ─ 1. source
10339 ");
10340 }
10341
10342 #[test]
10343 fn goto_drop_aggregate_defined_after() {
10344 assert_snapshot!(goto("
10345drop aggregate myavg$0(int);
10346create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10347"), @r"
10348 ╭▸
10349 2 │ drop aggregate myavg(int);
10350 │ ─ 1. source
10351 3 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10352 ╰╴ ───── 2. destination
10353 ");
10354 }
10355
10356 #[test]
10357 fn goto_aggregate_definition_returns_self() {
10358 assert_snapshot!(goto("
10359create aggregate myavg$0(int) (sfunc = int4_avg_accum, stype = _int8);
10360"), @r"
10361 ╭▸
10362 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10363 │ ┬───┬
10364 │ │ │
10365 │ │ 1. source
10366 ╰╴ 2. destination
10367 ");
10368 }
10369
10370 #[test]
10371 fn goto_drop_aggregate_with_search_path() {
10372 assert_snapshot!(goto("
10373create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10374set search_path to bar;
10375create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10376set search_path to default;
10377drop aggregate myavg$0(int);
10378"), @r"
10379 ╭▸
10380 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10381 │ ───── 2. destination
10382 ‡
10383 6 │ drop aggregate myavg(int);
10384 ╰╴ ─ 1. source
10385 ");
10386 }
10387
10388 #[test]
10389 fn goto_drop_aggregate_multiple() {
10390 assert_snapshot!(goto("
10391create aggregate avg1(int) (sfunc = int4_avg_accum, stype = _int8);
10392create aggregate avg2(int) (sfunc = int4_avg_accum, stype = _int8);
10393drop aggregate avg1(int), avg2$0(int);
10394"), @r"
10395 ╭▸
10396 3 │ create aggregate avg2(int) (sfunc = int4_avg_accum, stype = _int8);
10397 │ ──── 2. destination
10398 4 │ drop aggregate avg1(int), avg2(int);
10399 ╰╴ ─ 1. source
10400 ");
10401 }
10402
10403 #[test]
10404 fn goto_drop_aggregate_overloaded() {
10405 assert_snapshot!(goto("
10406create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
10407create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
10408drop aggregate sum$0(complex);
10409"), @r"
10410 ╭▸
10411 2 │ create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
10412 │ ─── 2. destination
10413 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
10414 4 │ drop aggregate sum(complex);
10415 ╰╴ ─ 1. source
10416 ");
10417 }
10418
10419 #[test]
10420 fn goto_drop_aggregate_second_overload() {
10421 assert_snapshot!(goto("
10422create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
10423create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
10424drop aggregate sum$0(bigint);
10425"), @r"
10426 ╭▸
10427 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
10428 │ ─── 2. destination
10429 4 │ drop aggregate sum(bigint);
10430 ╰╴ ─ 1. source
10431 ");
10432 }
10433
10434 #[test]
10435 fn goto_drop_routine_function() {
10436 assert_snapshot!(goto("
10437create function foo() returns int as $$ select 1 $$ language sql;
10438drop routine foo$0();
10439"), @r"
10440 ╭▸
10441 2 │ create function foo() returns int as $$ select 1 $$ language sql;
10442 │ ─── 2. destination
10443 3 │ drop routine foo();
10444 ╰╴ ─ 1. source
10445 ");
10446 }
10447
10448 #[test]
10449 fn goto_drop_routine_aggregate() {
10450 assert_snapshot!(goto("
10451create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10452drop routine myavg$0(int);
10453"), @r"
10454 ╭▸
10455 2 │ create aggregate myavg(int) (sfunc = int4_avg_accum, stype = _int8);
10456 │ ───── 2. destination
10457 3 │ drop routine myavg(int);
10458 ╰╴ ─ 1. source
10459 ");
10460 }
10461
10462 #[test]
10463 fn goto_drop_routine_with_schema() {
10464 assert_snapshot!(goto("
10465set search_path to public;
10466create function foo() returns int as $$ select 1 $$ language sql;
10467drop routine public.foo$0();
10468"), @r"
10469 ╭▸
10470 3 │ create function foo() returns int as $$ select 1 $$ language sql;
10471 │ ─── 2. destination
10472 4 │ drop routine public.foo();
10473 ╰╴ ─ 1. source
10474 ");
10475 }
10476
10477 #[test]
10478 fn goto_drop_routine_defined_after() {
10479 assert_snapshot!(goto("
10480drop routine foo$0();
10481create function foo() returns int as $$ select 1 $$ language sql;
10482"), @r"
10483 ╭▸
10484 2 │ drop routine foo();
10485 │ ─ 1. source
10486 3 │ create function foo() returns int as $$ select 1 $$ language sql;
10487 ╰╴ ─── 2. destination
10488 ");
10489 }
10490
10491 #[test]
10492 fn goto_drop_routine_with_search_path() {
10493 assert_snapshot!(goto("
10494create function foo() returns int as $$ select 1 $$ language sql;
10495set search_path to bar;
10496create function foo() returns int as $$ select 1 $$ language sql;
10497set search_path to default;
10498drop routine foo$0();
10499"), @r"
10500 ╭▸
10501 2 │ create function foo() returns int as $$ select 1 $$ language sql;
10502 │ ─── 2. destination
10503 ‡
10504 6 │ drop routine foo();
10505 ╰╴ ─ 1. source
10506 ");
10507 }
10508
10509 #[test]
10510 fn goto_drop_routine_overloaded() {
10511 assert_snapshot!(goto("
10512create function add(complex) returns complex as $$ select null $$ language sql;
10513create function add(bigint) returns bigint as $$ select 1 $$ language sql;
10514drop routine add$0(complex);
10515"), @r"
10516 ╭▸
10517 2 │ create function add(complex) returns complex as $$ select null $$ language sql;
10518 │ ─── 2. destination
10519 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
10520 4 │ drop routine add(complex);
10521 ╰╴ ─ 1. source
10522 ");
10523 }
10524
10525 #[test]
10526 fn goto_drop_routine_second_overload() {
10527 assert_snapshot!(goto("
10528create function add(complex) returns complex as $$ select null $$ language sql;
10529create function add(bigint) returns bigint as $$ select 1 $$ language sql;
10530drop routine add$0(bigint);
10531"), @r"
10532 ╭▸
10533 3 │ create function add(bigint) returns bigint as $$ select 1 $$ language sql;
10534 │ ─── 2. destination
10535 4 │ drop routine add(bigint);
10536 ╰╴ ─ 1. source
10537 ");
10538 }
10539
10540 #[test]
10541 fn goto_drop_routine_aggregate_overloaded() {
10542 assert_snapshot!(goto("
10543create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
10544create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
10545drop routine sum$0(complex);
10546"), @r"
10547 ╭▸
10548 2 │ create aggregate sum(complex) (sfunc = complex_add, stype = complex, initcond = '(0,0)');
10549 │ ─── 2. destination
10550 3 │ create aggregate sum(bigint) (sfunc = bigint_add, stype = bigint, initcond = '0');
10551 4 │ drop routine sum(complex);
10552 ╰╴ ─ 1. source
10553 ");
10554 }
10555
10556 #[test]
10557 fn goto_drop_routine_multiple() {
10558 assert_snapshot!(goto("
10559create function foo() returns int as $$ select 1 $$ language sql;
10560create function bar() returns int as $$ select 1 $$ language sql;
10561drop routine foo(), bar$0();
10562"), @r"
10563 ╭▸
10564 3 │ create function bar() returns int as $$ select 1 $$ language sql;
10565 │ ─── 2. destination
10566 4 │ drop routine foo(), bar();
10567 ╰╴ ─ 1. source
10568 ");
10569 }
10570
10571 #[test]
10572 fn goto_drop_procedure() {
10573 assert_snapshot!(goto("
10574create procedure foo() language sql as $$ select 1 $$;
10575drop procedure foo$0();
10576"), @r"
10577 ╭▸
10578 2 │ create procedure foo() language sql as $$ select 1 $$;
10579 │ ─── 2. destination
10580 3 │ drop procedure foo();
10581 ╰╴ ─ 1. source
10582 ");
10583 }
10584
10585 #[test]
10586 fn goto_drop_procedure_with_schema() {
10587 assert_snapshot!(goto("
10588set search_path to public;
10589create procedure foo() language sql as $$ select 1 $$;
10590drop procedure public.foo$0();
10591"), @r"
10592 ╭▸
10593 3 │ create procedure foo() language sql as $$ select 1 $$;
10594 │ ─── 2. destination
10595 4 │ drop procedure public.foo();
10596 ╰╴ ─ 1. source
10597 ");
10598 }
10599
10600 #[test]
10601 fn goto_drop_procedure_defined_after() {
10602 assert_snapshot!(goto("
10603drop procedure foo$0();
10604create procedure foo() language sql as $$ select 1 $$;
10605"), @r"
10606 ╭▸
10607 2 │ drop procedure foo();
10608 │ ─ 1. source
10609 3 │ create procedure foo() language sql as $$ select 1 $$;
10610 ╰╴ ─── 2. destination
10611 ");
10612 }
10613
10614 #[test]
10615 fn goto_drop_procedure_with_search_path() {
10616 assert_snapshot!(goto("
10617create procedure foo() language sql as $$ select 1 $$;
10618set search_path to bar;
10619create procedure foo() language sql as $$ select 1 $$;
10620set search_path to default;
10621drop procedure foo$0();
10622"), @r"
10623 ╭▸
10624 2 │ create procedure foo() language sql as $$ select 1 $$;
10625 │ ─── 2. destination
10626 ‡
10627 6 │ drop procedure foo();
10628 ╰╴ ─ 1. source
10629 ");
10630 }
10631
10632 #[test]
10633 fn goto_drop_procedure_overloaded() {
10634 assert_snapshot!(goto("
10635create procedure add(complex) language sql as $$ select null $$;
10636create procedure add(bigint) language sql as $$ select 1 $$;
10637drop procedure add$0(complex);
10638"), @r"
10639 ╭▸
10640 2 │ create procedure add(complex) language sql as $$ select null $$;
10641 │ ─── 2. destination
10642 3 │ create procedure add(bigint) language sql as $$ select 1 $$;
10643 4 │ drop procedure add(complex);
10644 ╰╴ ─ 1. source
10645 ");
10646 }
10647
10648 #[test]
10649 fn goto_drop_procedure_second_overload() {
10650 assert_snapshot!(goto("
10651create procedure add(complex) language sql as $$ select null $$;
10652create procedure add(bigint) language sql as $$ select 1 $$;
10653drop procedure add$0(bigint);
10654"), @r"
10655 ╭▸
10656 3 │ create procedure add(bigint) language sql as $$ select 1 $$;
10657 │ ─── 2. destination
10658 4 │ drop procedure add(bigint);
10659 ╰╴ ─ 1. source
10660 ");
10661 }
10662
10663 #[test]
10664 fn goto_drop_procedure_multiple() {
10665 assert_snapshot!(goto("
10666create procedure foo() language sql as $$ select 1 $$;
10667create procedure bar() language sql as $$ select 1 $$;
10668drop procedure foo(), bar$0();
10669"), @r"
10670 ╭▸
10671 3 │ create procedure bar() language sql as $$ select 1 $$;
10672 │ ─── 2. destination
10673 4 │ drop procedure foo(), bar();
10674 ╰╴ ─ 1. source
10675 ");
10676 }
10677
10678 #[test]
10679 fn goto_procedure_definition_returns_self() {
10680 assert_snapshot!(goto("
10681create procedure foo$0() language sql as $$ select 1 $$;
10682"), @r"
10683 ╭▸
10684 2 │ create procedure foo() language sql as $$ select 1 $$;
10685 │ ┬─┬
10686 │ │ │
10687 │ │ 1. source
10688 ╰╴ 2. destination
10689 ");
10690 }
10691
10692 #[test]
10693 fn goto_call_procedure() {
10694 assert_snapshot!(goto("
10695create procedure foo() language sql as $$ select 1 $$;
10696call foo$0();
10697"), @r"
10698 ╭▸
10699 2 │ create procedure foo() language sql as $$ select 1 $$;
10700 │ ─── 2. destination
10701 3 │ call foo();
10702 ╰╴ ─ 1. source
10703 ");
10704 }
10705
10706 #[test]
10707 fn goto_call_procedure_with_schema() {
10708 assert_snapshot!(goto("
10709create procedure public.foo() language sql as $$ select 1 $$;
10710call public.foo$0();
10711"), @r"
10712 ╭▸
10713 2 │ create procedure public.foo() language sql as $$ select 1 $$;
10714 │ ─── 2. destination
10715 3 │ call public.foo();
10716 ╰╴ ─ 1. source
10717 ");
10718 }
10719
10720 #[test]
10721 fn goto_call_procedure_with_search_path() {
10722 assert_snapshot!(goto("
10723set search_path to myschema;
10724create procedure foo() language sql as $$ select 1 $$;
10725call myschema.foo$0();
10726"), @r"
10727 ╭▸
10728 3 │ create procedure foo() language sql as $$ select 1 $$;
10729 │ ─── 2. destination
10730 4 │ call myschema.foo();
10731 ╰╴ ─ 1. source
10732 ");
10733 }
10734
10735 #[test]
10736 fn goto_drop_routine_procedure() {
10737 assert_snapshot!(goto("
10738create procedure foo() language sql as $$ select 1 $$;
10739drop routine foo$0();
10740"), @r"
10741 ╭▸
10742 2 │ create procedure foo() language sql as $$ select 1 $$;
10743 │ ─── 2. destination
10744 3 │ drop routine foo();
10745 ╰╴ ─ 1. source
10746 ");
10747 }
10748
10749 #[test]
10750 fn goto_drop_routine_prefers_function_over_procedure() {
10751 assert_snapshot!(goto("
10752create function foo() returns int as $$ select 1 $$ language sql;
10753create procedure foo() language sql as $$ select 1 $$;
10754drop routine foo$0();
10755"), @r"
10756 ╭▸
10757 2 │ create function foo() returns int as $$ select 1 $$ language sql;
10758 │ ─── 2. destination
10759 3 │ create procedure foo() language sql as $$ select 1 $$;
10760 4 │ drop routine foo();
10761 ╰╴ ─ 1. source
10762 ");
10763 }
10764
10765 #[test]
10766 fn goto_drop_routine_prefers_aggregate_over_procedure() {
10767 assert_snapshot!(goto("
10768create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
10769create procedure foo(int) language sql as $$ select 1 $$;
10770drop routine foo$0(int);
10771"), @r"
10772 ╭▸
10773 2 │ create aggregate foo(int) (sfunc = int4_avg_accum, stype = _int8);
10774 │ ─── 2. destination
10775 3 │ create procedure foo(int) language sql as $$ select 1 $$;
10776 4 │ drop routine foo(int);
10777 ╰╴ ─ 1. source
10778 ");
10779 }
10780
10781 #[test]
10782 fn goto_table_alias_in_qualified_column() {
10783 assert_snapshot!(goto("
10784create table t(a int8, b text);
10785select f$0.a from t as f;
10786"), @r"
10787 ╭▸
10788 3 │ select f.a from t as f;
10789 ╰╴ ─ 1. source ─ 2. destination
10790 ");
10791 }
10792
10793 #[test]
10794 fn goto_column_through_table_alias() {
10795 assert_snapshot!(goto("
10796create table t(a int8, b text);
10797select f.a$0 from t as f;
10798"), @r"
10799 ╭▸
10800 2 │ create table t(a int8, b text);
10801 │ ─ 2. destination
10802 3 │ select f.a from t as f;
10803 ╰╴ ─ 1. source
10804 ");
10805 }
10806
10807 #[test]
10808 fn goto_cte_alias_renamed_column() {
10809 assert_snapshot!(goto("
10810with t as (select 1 a, 2 b)
10811select f.x$0 from t as f(x);
10812"), @r"
10813 ╭▸
10814 3 │ select f.x from t as f(x);
10815 ╰╴ ─ 1. source ─ 2. destination
10816 ");
10817 }
10818
10819 #[test]
10820 fn goto_cte_alias_unrenamed_column() {
10821 assert_snapshot!(goto("
10822with t as (select 1 a, 2 b)
10823select f.b$0 from t as f(x);
10824"), @r"
10825 ╭▸
10826 2 │ with t as (select 1 a, 2 b)
10827 │ ─ 2. destination
10828 3 │ select f.b from t as f(x);
10829 ╰╴ ─ 1. source
10830 ");
10831 }
10832
10833 #[test]
10834 fn goto_join_table() {
10835 assert_snapshot!(goto("
10836create table users(id int, email text);
10837create table messages(id int, user_id int, message text);
10838select * from users join messages$0 on users.id = messages.user_id;
10839"), @r"
10840 ╭▸
10841 3 │ create table messages(id int, user_id int, message text);
10842 │ ──────── 2. destination
10843 4 │ select * from users join messages on users.id = messages.user_id;
10844 ╰╴ ─ 1. source
10845 ");
10846 }
10847
10848 #[test]
10849 fn goto_join_qualified_column_from_joined_table() {
10850 assert_snapshot!(goto("
10851create table users(id int, email text);
10852create table messages(id int, user_id int, message text);
10853select messages.user_id$0 from users join messages on users.id = messages.user_id;
10854"), @r"
10855 ╭▸
10856 3 │ create table messages(id int, user_id int, message text);
10857 │ ─────── 2. destination
10858 4 │ select messages.user_id from users join messages on users.id = messages.user_id;
10859 ╰╴ ─ 1. source
10860 ");
10861 }
10862
10863 #[test]
10864 fn goto_join_qualified_column_from_base_table() {
10865 assert_snapshot!(goto("
10866create table users(id int, email text);
10867create table messages(id int, user_id int, message text);
10868select users.id$0 from users join messages on users.id = messages.user_id;
10869"), @r"
10870 ╭▸
10871 2 │ create table users(id int, email text);
10872 │ ── 2. destination
10873 3 │ create table messages(id int, user_id int, message text);
10874 4 │ select users.id from users join messages on users.id = messages.user_id;
10875 ╰╴ ─ 1. source
10876 ");
10877 }
10878
10879 #[test]
10880 fn goto_join_multiple_joins() {
10881 assert_snapshot!(goto("
10882create table users(id int, name text);
10883create table messages(id int, user_id int, message text);
10884create table comments(id int, message_id int, text text);
10885select comments.text$0 from users
10886 join messages on users.id = messages.user_id
10887 join comments on messages.id = comments.message_id;
10888"), @r"
10889 ╭▸
10890 4 │ create table comments(id int, message_id int, text text);
10891 │ ──── 2. destination
10892 5 │ select comments.text from users
10893 ╰╴ ─ 1. source
10894 ");
10895 }
10896
10897 #[test]
10898 fn goto_join_with_aliases() {
10899 assert_snapshot!(goto("
10900create table users(id int, name text);
10901create table messages(id int, user_id int, message text);
10902select m.message$0 from users as u join messages as m on u.id = m.user_id;
10903"), @r"
10904 ╭▸
10905 3 │ create table messages(id int, user_id int, message text);
10906 │ ─────── 2. destination
10907 4 │ select m.message from users as u join messages as m on u.id = m.user_id;
10908 ╰╴ ─ 1. source
10909 ");
10910 }
10911
10912 #[test]
10913 fn goto_alias_hides_table_name() {
10914 goto_not_found(
10915 "
10916create table t(a int);
10917select t$0.a from t as u;
10918",
10919 );
10920 }
10921
10922 #[test]
10923 fn goto_join_unqualified_column() {
10924 assert_snapshot!(goto("
10925create table users(id int, email text);
10926create table messages(id int, user_id int, message text);
10927select message$0 from users join messages on users.id = messages.user_id;
10928"), @r"
10929 ╭▸
10930 3 │ create table messages(id int, user_id int, message text);
10931 │ ─────── 2. destination
10932 4 │ select message from users join messages on users.id = messages.user_id;
10933 ╰╴ ─ 1. source
10934 ");
10935 }
10936
10937 #[test]
10938 fn goto_join_with_many_tables() {
10939 assert_snapshot!(goto("
10940create table users(id int, email text);
10941create table messages(id int, user_id int, message text);
10942create table logins(id int, user_id int, at timestamptz);
10943create table posts(id int, user_id int, post text);
10944
10945select post$0
10946 from users
10947 join messages
10948 on users.id = messages.user_id
10949 join logins
10950 on users.id = logins.user_id
10951 join posts
10952 on users.id = posts.user_id
10953"), @r"
10954 ╭▸
10955 5 │ create table posts(id int, user_id int, post text);
10956 │ ──── 2. destination
10957 6 │
10958 7 │ select post
10959 ╰╴ ─ 1. source
10960 ");
10961 }
10962
10963 #[test]
10964 fn goto_join_with_schema() {
10965 assert_snapshot!(goto("
10966create schema foo;
10967create table foo.users(id int, email text);
10968create table foo.messages(id int, user_id int, message text);
10969select foo.messages.message$0 from foo.users join foo.messages on foo.users.id = foo.messages.user_id;
10970"), @r"
10971 ╭▸
10972 4 │ create table foo.messages(id int, user_id int, message text);
10973 │ ─────── 2. destination
10974 5 │ select foo.messages.message from foo.users join foo.messages on foo.users.id = foo.messages.user_id;
10975 ╰╴ ─ 1. source
10976 ");
10977 }
10978
10979 #[test]
10980 fn goto_join_left_join() {
10981 assert_snapshot!(goto("
10982create table users(id int, email text);
10983create table messages(id int, user_id int, message text);
10984select messages.message$0 from users left join messages on users.id = messages.user_id;
10985"), @r"
10986 ╭▸
10987 3 │ create table messages(id int, user_id int, message text);
10988 │ ─────── 2. destination
10989 4 │ select messages.message from users left join messages on users.id = messages.user_id;
10990 ╰╴ ─ 1. source
10991 ");
10992 }
10993
10994 #[test]
10995 fn goto_join_on_table_qualifier() {
10996 assert_snapshot!(goto("
10997create table t(a int);
10998create table u(a int);
10999select * from t join u on u$0.a = t.a;
11000"), @r"
11001 ╭▸
11002 3 │ create table u(a int);
11003 │ ─ 2. destination
11004 4 │ select * from t join u on u.a = t.a;
11005 ╰╴ ─ 1. source
11006 ");
11007 }
11008
11009 #[test]
11010 fn goto_join_on_column() {
11011 assert_snapshot!(goto("
11012create table t(a int);
11013create table u(a int);
11014select * from t join u on u.a$0 = t.a;
11015"), @r"
11016 ╭▸
11017 3 │ create table u(a int);
11018 │ ─ 2. destination
11019 4 │ select * from t join u on u.a = t.a;
11020 ╰╴ ─ 1. source
11021 ");
11022 }
11023
11024 #[test]
11025 fn goto_join_using_column() {
11026 assert_snapshot!(goto("
11027create table t(a int);
11028create table u(a int);
11029select * from t join u using (a$0);
11030"), @r"
11031 ╭▸
11032 2 │ create table t(a int);
11033 │ ─ 2. destination
11034 3 │ create table u(a int);
11035 │ ─ 3. destination
11036 4 │ select * from t join u using (a);
11037 ╰╴ ─ 1. source
11038 ");
11039 }
11040
11041 #[test]
11042 fn goto_join_using_alias_column() {
11043 assert_snapshot!(goto("
11044create table a(x int);
11045create table b(x int);
11046select j.x$0 from a join b using (x) as j;
11047"), @"
11048 ╭▸
11049 2 │ create table a(x int);
11050 │ ─ 2. destination
11051 3 │ create table b(x int);
11052 │ ─ 3. destination
11053 4 │ select j.x from a join b using (x) as j;
11054 ╰╴ ─ 1. source
11055 ");
11056 }
11057
11058 #[test]
11059 fn goto_join_using_alias_table() {
11060 assert_snapshot!(goto("
11061create table a(x int);
11062create table b(x int);
11063select j$0.x from a join b using (x) as j;
11064"), @"
11065 ╭▸
11066 4 │ select j.x from a join b using (x) as j;
11067 ╰╴ ─ 1. source ─ 2. destination
11068 ");
11069 }
11070
11071 #[test]
11072 fn goto_insert_select_cte_column() {
11073 assert_snapshot!(goto("
11074create table users(id int, email text);
11075with new_data as (
11076 select 1 as id, 'test@example.com' as email
11077)
11078insert into users (id, email)
11079select id$0, email from new_data;
11080"), @r"
11081 ╭▸
11082 4 │ select 1 as id, 'test@example.com' as email
11083 │ ── 2. destination
11084 ‡
11085 7 │ select id, email from new_data;
11086 ╰╴ ─ 1. source
11087 ");
11088 }
11089
11090 #[test]
11091 fn goto_insert_select_cte_column_second() {
11092 assert_snapshot!(goto("
11093create table users(id int, email text);
11094with new_data as (
11095 select 1 as id, 'test@example.com' as email
11096)
11097insert into users (id, email)
11098select id, email$0 from new_data;
11099"), @r"
11100 ╭▸
11101 4 │ select 1 as id, 'test@example.com' as email
11102 │ ───── 2. destination
11103 ‡
11104 7 │ select id, email from new_data;
11105 ╰╴ ─ 1. source
11106 ");
11107 }
11108
11109 #[test]
11110 fn goto_insert_select_cte_table() {
11111 assert_snapshot!(goto("
11112create table users(id int, email text);
11113with new_data as (
11114 select 1 as id, 'test@example.com' as email
11115)
11116insert into users (id, email)
11117select id, email from new_data$0;
11118"), @r"
11119 ╭▸
11120 3 │ with new_data as (
11121 │ ──────── 2. destination
11122 ‡
11123 7 │ select id, email from new_data;
11124 ╰╴ ─ 1. source
11125 ");
11126 }
11127
11128 #[test]
11129 fn goto_delete_cte_column() {
11130 assert_snapshot!(goto("
11131create table users(id int, email text);
11132with old_data as (
11133 select 1 as id
11134)
11135delete from users where id in (select id$0 from old_data);
11136"), @r"
11137 ╭▸
11138 4 │ select 1 as id
11139 │ ── 2. destination
11140 5 │ )
11141 6 │ delete from users where id in (select id from old_data);
11142 ╰╴ ─ 1. source
11143 ");
11144 }
11145
11146 #[test]
11147 fn goto_update_table() {
11148 assert_snapshot!(goto("
11149create table users(id int, email text);
11150update users$0 set email = 'new@example.com';
11151"), @r"
11152 ╭▸
11153 2 │ create table users(id int, email text);
11154 │ ───── 2. destination
11155 3 │ update users set email = 'new@example.com';
11156 ╰╴ ─ 1. source
11157 ");
11158 }
11159
11160 #[test]
11161 fn goto_update_table_with_schema() {
11162 assert_snapshot!(goto("
11163create table public.users(id int, email text);
11164update public.users$0 set email = 'new@example.com';
11165"), @r"
11166 ╭▸
11167 2 │ create table public.users(id int, email text);
11168 │ ───── 2. destination
11169 3 │ update public.users set email = 'new@example.com';
11170 ╰╴ ─ 1. source
11171 ");
11172 }
11173
11174 #[test]
11175 fn goto_update_table_with_search_path() {
11176 assert_snapshot!(goto("
11177set search_path to foo;
11178create table foo.users(id int, email text);
11179update users$0 set email = 'new@example.com';
11180"), @r"
11181 ╭▸
11182 3 │ create table foo.users(id int, email text);
11183 │ ───── 2. destination
11184 4 │ update users set email = 'new@example.com';
11185 ╰╴ ─ 1. source
11186 ");
11187 }
11188
11189 #[test]
11190 fn goto_update_where_column() {
11191 assert_snapshot!(goto("
11192create table users(id int, email text);
11193update users set email = 'new@example.com' where id$0 = 1;
11194"), @r"
11195 ╭▸
11196 2 │ create table users(id int, email text);
11197 │ ── 2. destination
11198 3 │ update users set email = 'new@example.com' where id = 1;
11199 ╰╴ ─ 1. source
11200 ");
11201 }
11202
11203 #[test]
11204 fn goto_update_where_column_with_schema() {
11205 assert_snapshot!(goto("
11206create table public.users(id int, email text);
11207update public.users set email = 'new@example.com' where id$0 = 1;
11208"), @r"
11209 ╭▸
11210 2 │ create table public.users(id int, email text);
11211 │ ── 2. destination
11212 3 │ update public.users set email = 'new@example.com' where id = 1;
11213 ╰╴ ─ 1. source
11214 ");
11215 }
11216
11217 #[test]
11218 fn goto_update_where_column_with_search_path() {
11219 assert_snapshot!(goto("
11220set search_path to foo;
11221create table foo.users(id int, email text);
11222update users set email = 'new@example.com' where id$0 = 1;
11223"), @r"
11224 ╭▸
11225 3 │ create table foo.users(id int, email text);
11226 │ ── 2. destination
11227 4 │ update users set email = 'new@example.com' where id = 1;
11228 ╰╴ ─ 1. source
11229 ");
11230 }
11231
11232 #[test]
11233 fn goto_update_set_column() {
11234 assert_snapshot!(goto("
11235create table users(id int, email text);
11236update users set email$0 = 'new@example.com' where id = 1;
11237"), @r"
11238 ╭▸
11239 2 │ create table users(id int, email text);
11240 │ ───── 2. destination
11241 3 │ update users set email = 'new@example.com' where id = 1;
11242 ╰╴ ─ 1. source
11243 ");
11244 }
11245
11246 #[test]
11247 fn goto_update_set_column_with_schema() {
11248 assert_snapshot!(goto("
11249create table public.users(id int, email text);
11250update public.users set email$0 = 'new@example.com' where id = 1;
11251"), @r"
11252 ╭▸
11253 2 │ create table public.users(id int, email text);
11254 │ ───── 2. destination
11255 3 │ update public.users set email = 'new@example.com' where id = 1;
11256 ╰╴ ─ 1. source
11257 ");
11258 }
11259
11260 #[test]
11261 fn goto_update_set_column_with_search_path() {
11262 assert_snapshot!(goto("
11263set search_path to foo;
11264create table foo.users(id int, email text);
11265update users set email$0 = 'new@example.com' where id = 1;
11266"), @r"
11267 ╭▸
11268 3 │ create table foo.users(id int, email text);
11269 │ ───── 2. destination
11270 4 │ update users set email = 'new@example.com' where id = 1;
11271 ╰╴ ─ 1. source
11272 ");
11273 }
11274
11275 #[test]
11276 fn goto_update_from_table() {
11277 assert_snapshot!(goto("
11278create table users(id int, email text);
11279create table messages(id int, user_id int, email text);
11280update users set email = messages.email from messages$0 where users.id = messages.user_id;
11281"), @r"
11282 ╭▸
11283 3 │ create table messages(id int, user_id int, email text);
11284 │ ──────── 2. destination
11285 4 │ update users set email = messages.email from messages where users.id = messages.user_id;
11286 ╰╴ ─ 1. source
11287 ");
11288 }
11289
11290 #[test]
11291 fn goto_update_from_table_qualifier_in_set() {
11292 assert_snapshot!(goto("
11293create table target(id int, x int);
11294create table src(id int, y int);
11295update target set x = src$0.y from src where src.id = target.id;
11296"), @"
11297 ╭▸
11298 3 │ create table src(id int, y int);
11299 │ ─── 2. destination
11300 4 │ update target set x = src.y from src where src.id = target.id;
11301 ╰╴ ─ 1. source
11302 ");
11303 }
11304
11305 #[test]
11306 fn goto_update_set_target_resolves_to_target_table() {
11307 assert_snapshot!(goto("
11308create table t (a int);
11309create table u (a int);
11310update t set a$0 = u.a from u;
11311"), @"
11312 ╭▸
11313 2 │ create table t (a int);
11314 │ ─ 2. destination
11315 3 │ create table u (a int);
11316 4 │ update t set a = u.a from u;
11317 ╰╴ ─ 1. source
11318 ");
11319 }
11320
11321 #[test]
11322 fn goto_update_set_target_tuple_resolves_to_target_table() {
11323 assert_snapshot!(goto("
11324create table t (a int, b int);
11325create table u (a int);
11326update t set (a$0, b) = (u.a, 1) from u;
11327"), @"
11328 ╭▸
11329 2 │ create table t (a int, b int);
11330 │ ─ 2. destination
11331 3 │ create table u (a int);
11332 4 │ update t set (a, b) = (u.a, 1) from u;
11333 ╰╴ ─ 1. source
11334 ");
11335 }
11336
11337 #[test]
11338 fn goto_update_from_table_with_schema() {
11339 assert_snapshot!(goto("
11340create table users(id int, email text);
11341create table public.messages(id int, user_id int, email text);
11342update users set email = messages.email from public.messages$0 where users.id = messages.user_id;
11343"), @r"
11344 ╭▸
11345 3 │ create table public.messages(id int, user_id int, email text);
11346 │ ──────── 2. destination
11347 4 │ update users set email = messages.email from public.messages where users.id = messages.user_id;
11348 ╰╴ ─ 1. source
11349 ");
11350 }
11351
11352 #[test]
11353 fn goto_update_from_table_with_search_path() {
11354 assert_snapshot!(goto("
11355set search_path to foo;
11356create table users(id int, email text);
11357create table foo.messages(id int, user_id int, email text);
11358update users set email = messages.email from messages$0 where users.id = messages.user_id;
11359"), @r"
11360 ╭▸
11361 4 │ create table foo.messages(id int, user_id int, email text);
11362 │ ──────── 2. destination
11363 5 │ update users set email = messages.email from messages where users.id = messages.user_id;
11364 ╰╴ ─ 1. source
11365 ");
11366 }
11367
11368 #[test]
11369 fn goto_update_with_cte_table() {
11370 assert_snapshot!(goto("
11371create table users(id int, email text);
11372with new_data as (
11373 select 1 as id, 'new@example.com' as email
11374)
11375update users set email = new_data.email from new_data$0 where users.id = new_data.id;
11376"), @r"
11377 ╭▸
11378 3 │ with new_data as (
11379 │ ──────── 2. destination
11380 ‡
11381 6 │ update users set email = new_data.email from new_data where users.id = new_data.id;
11382 ╰╴ ─ 1. source
11383 ");
11384 }
11385
11386 #[test]
11387 fn goto_update_with_cte_column_in_set() {
11388 assert_snapshot!(goto("
11389create table users(id int, email text);
11390with new_data as (
11391 select 1 as id, 'new@example.com' as email
11392)
11393update users set email = new_data.email$0 from new_data where users.id = new_data.id;
11394"), @r"
11395 ╭▸
11396 4 │ select 1 as id, 'new@example.com' as email
11397 │ ───── 2. destination
11398 5 │ )
11399 6 │ update users set email = new_data.email from new_data where users.id = new_data.id;
11400 ╰╴ ─ 1. source
11401 ");
11402 }
11403
11404 #[test]
11405 fn goto_update_with_cte_column_in_where() {
11406 assert_snapshot!(goto("
11407create table users(id int, email text);
11408with new_data as (
11409 select 1 as id, 'new@example.com' as email
11410)
11411update users set email = new_data.email from new_data where new_data.id$0 = users.id;
11412"), @r"
11413 ╭▸
11414 4 │ select 1 as id, 'new@example.com' as email
11415 │ ── 2. destination
11416 5 │ )
11417 6 │ update users set email = new_data.email from new_data where new_data.id = users.id;
11418 ╰╴ ─ 1. source
11419 ");
11420 }
11421
11422 #[test]
11423 fn goto_update_with_cte_values() {
11424 assert_snapshot!(goto("
11425create table users(id int, email text);
11426with new_data as (
11427 values (1, 'new@example.com')
11428)
11429update users set email = new_data.column2$0 from new_data where users.id = new_data.column1;
11430"), @r"
11431 ╭▸
11432 4 │ values (1, 'new@example.com')
11433 │ ───────────────── 2. destination
11434 5 │ )
11435 6 │ update users set email = new_data.column2 from new_data where users.id = new_data.column1;
11436 ╰╴ ─ 1. source
11437 ");
11438 }
11439
11440 #[test]
11441 fn goto_truncate_table() {
11442 assert_snapshot!(goto("
11443create table t();
11444truncate table t$0;
11445"), @r"
11446 ╭▸
11447 2 │ create table t();
11448 │ ─ 2. destination
11449 3 │ truncate table t;
11450 ╰╴ ─ 1. source
11451 ");
11452 }
11453
11454 #[test]
11455 fn goto_truncate_table_without_table_keyword() {
11456 assert_snapshot!(goto("
11457create table t();
11458truncate t$0;
11459"), @r"
11460 ╭▸
11461 2 │ create table t();
11462 │ ─ 2. destination
11463 3 │ truncate t;
11464 ╰╴ ─ 1. source
11465 ");
11466 }
11467
11468 #[test]
11469 fn goto_truncate_multiple_tables() {
11470 assert_snapshot!(goto("
11471create table t1();
11472create table t2();
11473truncate t1, t2$0;
11474"), @r"
11475 ╭▸
11476 3 │ create table t2();
11477 │ ── 2. destination
11478 4 │ truncate t1, t2;
11479 ╰╴ ─ 1. source
11480 ");
11481 }
11482
11483 #[test]
11484 fn goto_lock_table() {
11485 assert_snapshot!(goto("
11486create table t();
11487lock table t$0;
11488"), @r"
11489 ╭▸
11490 2 │ create table t();
11491 │ ─ 2. destination
11492 3 │ lock table t;
11493 ╰╴ ─ 1. source
11494 ");
11495 }
11496
11497 #[test]
11498 fn goto_lock_table_without_table_keyword() {
11499 assert_snapshot!(goto("
11500create table t();
11501lock t$0;
11502"), @r"
11503 ╭▸
11504 2 │ create table t();
11505 │ ─ 2. destination
11506 3 │ lock t;
11507 ╰╴ ─ 1. source
11508 ");
11509 }
11510
11511 #[test]
11512 fn goto_lock_multiple_tables() {
11513 assert_snapshot!(goto("
11514create table t1();
11515create table t2();
11516lock t1, t2$0;
11517"), @r"
11518 ╭▸
11519 3 │ create table t2();
11520 │ ── 2. destination
11521 4 │ lock t1, t2;
11522 ╰╴ ─ 1. source
11523 ");
11524 }
11525
11526 #[test]
11527 fn goto_vacuum_table() {
11528 assert_snapshot!(goto("
11529create table users(id int, email text);
11530vacuum users$0;
11531"), @r"
11532 ╭▸
11533 2 │ create table users(id int, email text);
11534 │ ───── 2. destination
11535 3 │ vacuum users;
11536 ╰╴ ─ 1. source
11537 ");
11538 }
11539
11540 #[test]
11541 fn goto_vacuum_multiple_tables() {
11542 assert_snapshot!(goto("
11543create table t1();
11544create table t2();
11545vacuum t1, t2$0;
11546"), @r"
11547 ╭▸
11548 3 │ create table t2();
11549 │ ── 2. destination
11550 4 │ vacuum t1, t2;
11551 ╰╴ ─ 1. source
11552 ");
11553 }
11554
11555 #[test]
11556 fn goto_vacuum_column() {
11557 assert_snapshot!(goto("
11558create table users(id int, email text);
11559vacuum users (id$0);
11560"), @"
11561 ╭▸
11562 2 │ create table users(id int, email text);
11563 │ ── 2. destination
11564 3 │ vacuum users (id);
11565 ╰╴ ─ 1. source
11566 ");
11567 }
11568
11569 #[test]
11570 fn goto_analyze_table() {
11571 assert_snapshot!(goto("
11572create table users(id int, email text);
11573analyze users$0;
11574"), @"
11575 ╭▸
11576 2 │ create table users(id int, email text);
11577 │ ───── 2. destination
11578 3 │ analyze users;
11579 ╰╴ ─ 1. source
11580 ");
11581 }
11582
11583 #[test]
11584 fn goto_analyze_column() {
11585 assert_snapshot!(goto("
11586create table users(id int, email text);
11587analyze users (id$0);
11588"), @"
11589 ╭▸
11590 2 │ create table users(id int, email text);
11591 │ ── 2. destination
11592 3 │ analyze users (id);
11593 ╰╴ ─ 1. source
11594 ");
11595 }
11596
11597 #[test]
11598 fn goto_alter_table() {
11599 assert_snapshot!(goto("
11600create table users(id int, email text);
11601alter table users$0 alter email set not null;
11602"), @r"
11603 ╭▸
11604 2 │ create table users(id int, email text);
11605 │ ───── 2. destination
11606 3 │ alter table users alter email set not null;
11607 ╰╴ ─ 1. source
11608 ");
11609 }
11610
11611 #[test]
11612 fn goto_alter_table_column() {
11613 assert_snapshot!(goto("
11614create table users(id int, email text);
11615alter table users alter email$0 set not null;
11616"), @r"
11617 ╭▸
11618 2 │ create table users(id int, email text);
11619 │ ───── 2. destination
11620 3 │ alter table users alter email set not null;
11621 ╰╴ ─ 1. source
11622 ");
11623 }
11624
11625 #[test]
11626 fn goto_alter_table_column_with_column_keyword() {
11627 assert_snapshot!(goto("
11628create table users(id int, email text);
11629alter table users alter column email$0 set not null;
11630"), @r"
11631 ╭▸
11632 2 │ create table users(id int, email text);
11633 │ ───── 2. destination
11634 3 │ alter table users alter column email set not null;
11635 ╰╴ ─ 1. source
11636 ");
11637 }
11638
11639 #[test]
11640 fn goto_alter_table_rename_column() {
11641 assert_snapshot!(goto("
11642create table users(id int, email text);
11643alter table users rename column email$0 to email_address;
11644"), @"
11645 ╭▸
11646 2 │ create table users(id int, email text);
11647 │ ───── 2. destination
11648 3 │ alter table users rename column email to email_address;
11649 ╰╴ ─ 1. source
11650 ");
11651 }
11652
11653 #[test]
11654 fn goto_alter_view_alter_column() {
11655 assert_snapshot!(goto("
11656create table t(a int);
11657create view v as select a from t;
11658alter view v alter column a$0 set default 1;
11659"), @"
11660 ╭▸
11661 3 │ create view v as select a from t;
11662 │ ─ 2. destination
11663 4 │ alter view v alter column a set default 1;
11664 ╰╴ ─ 1. source
11665 ");
11666 }
11667
11668 #[test]
11669 fn goto_alter_view_rename_column() {
11670 assert_snapshot!(goto("
11671create table t(a int);
11672create view v as select a from t;
11673alter view v rename column a$0 to b;
11674"), @"
11675 ╭▸
11676 3 │ create view v as select a from t;
11677 │ ─ 2. destination
11678 4 │ alter view v rename column a to b;
11679 ╰╴ ─ 1. source
11680 ");
11681 }
11682
11683 #[test]
11684 fn goto_alter_materialized_view_rename_column() {
11685 assert_snapshot!(goto("
11686create table t(a int);
11687create materialized view mv as select a from t;
11688alter materialized view mv rename column a$0 to b;
11689"), @"
11690 ╭▸
11691 3 │ create materialized view mv as select a from t;
11692 │ ─ 2. destination
11693 4 │ alter materialized view mv rename column a to b;
11694 ╰╴ ─ 1. source
11695 ");
11696 }
11697
11698 #[test]
11699 fn goto_alter_table_add_column() {
11700 assert_snapshot!(goto("
11701create table users(id int);
11702alter table users$0 add column email text;
11703"), @r"
11704 ╭▸
11705 2 │ create table users(id int);
11706 │ ───── 2. destination
11707 3 │ alter table users add column email text;
11708 ╰╴ ─ 1. source
11709 ");
11710 }
11711
11712 #[test]
11713 fn goto_alter_table_drop_column() {
11714 assert_snapshot!(goto("
11715create table users(id int, email text);
11716alter table users drop column email$0;
11717"), @r"
11718 ╭▸
11719 2 │ create table users(id int, email text);
11720 │ ───── 2. destination
11721 3 │ alter table users drop column email;
11722 ╰╴ ─ 1. source
11723 ");
11724 }
11725
11726 #[test]
11727 fn goto_alter_table_drop_column_table_name() {
11728 assert_snapshot!(goto("
11729create table users(id int, email text);
11730alter table users$0 drop column email;
11731"), @r"
11732 ╭▸
11733 2 │ create table users(id int, email text);
11734 │ ───── 2. destination
11735 3 │ alter table users drop column email;
11736 ╰╴ ─ 1. source
11737 ");
11738 }
11739
11740 #[test]
11741 fn goto_alter_table_add_constraint_using_index() {
11742 assert_snapshot!(goto("
11743create table u(id int);
11744create index my_index on u (id);
11745alter table u add constraint uq unique using index my_in$0dex;
11746"), @r"
11747 ╭▸
11748 3 │ create index my_index on u (id);
11749 │ ──────── 2. destination
11750 4 │ alter table u add constraint uq unique using index my_index;
11751 ╰╴ ─ 1. source
11752 ");
11753 }
11754
11755 #[test]
11756 fn goto_alter_table_owner_to_role() {
11757 assert_snapshot!(goto("
11758create role reader;
11759create table t(id int);
11760alter table t owner to read$0er;
11761"), @r"
11762 ╭▸
11763 2 │ create role reader;
11764 │ ────── 2. destination
11765 3 │ create table t(id int);
11766 4 │ alter table t owner to reader;
11767 ╰╴ ─ 1. source
11768 ");
11769 }
11770
11771 #[test]
11772 fn goto_alter_table_set_tablespace() {
11773 assert_snapshot!(goto("
11774create tablespace ts location '/tmp/ts';
11775create table t(id int);
11776alter table t set tablespace t$0s;
11777"), @r"
11778 ╭▸
11779 2 │ create tablespace ts location '/tmp/ts';
11780 │ ── 2. destination
11781 3 │ create table t(id int);
11782 4 │ alter table t set tablespace ts;
11783 ╰╴ ─ 1. source
11784 ");
11785 }
11786
11787 #[test]
11788 fn goto_alter_table_all_in_tablespace() {
11789 assert_snapshot!(goto("
11790create tablespace ts location '/tmp/ts';
11791alter table all in tablespace t$0s set tablespace pg_default;
11792"), @"
11793 ╭▸
11794 2 │ create tablespace ts location '/tmp/ts';
11795 │ ── 2. destination
11796 3 │ alter table all in tablespace ts set tablespace pg_default;
11797 ╰╴ ─ 1. source
11798 ");
11799 }
11800
11801 #[test]
11802 fn goto_alter_materialized_view_all_in_tablespace() {
11803 assert_snapshot!(goto("
11804create tablespace ts location '/tmp/ts';
11805alter materialized view all in tablespace t$0s set tablespace pg_default;
11806"), @"
11807 ╭▸
11808 2 │ create tablespace ts location '/tmp/ts';
11809 │ ── 2. destination
11810 3 │ alter materialized view all in tablespace ts set tablespace pg_default;
11811 ╰╴ ─ 1. source
11812 ");
11813 }
11814
11815 #[test]
11816 fn goto_alter_index_all_in_tablespace() {
11817 assert_snapshot!(goto("
11818create tablespace ts location '/tmp/ts';
11819alter index all in tablespace t$0s set tablespace pg_default;
11820"), @"
11821 ╭▸
11822 2 │ create tablespace ts location '/tmp/ts';
11823 │ ── 2. destination
11824 3 │ alter index all in tablespace ts set tablespace pg_default;
11825 ╰╴ ─ 1. source
11826 ");
11827 }
11828
11829 #[test]
11830 fn goto_create_database_owner() {
11831 assert_snapshot!(goto("
11832create role r;
11833create database d owner r$0;
11834"), @"
11835 ╭▸
11836 2 │ create role r;
11837 │ ─ 2. destination
11838 3 │ create database d owner r;
11839 ╰╴ ─ 1. source
11840 ");
11841 }
11842
11843 #[test]
11844 fn goto_create_database_template() {
11845 assert_snapshot!(goto("
11846create database tmpl;
11847create database d template tmpl$0;
11848"), @"
11849 ╭▸
11850 2 │ create database tmpl;
11851 │ ──── 2. destination
11852 3 │ create database d template tmpl;
11853 ╰╴ ─ 1. source
11854 ");
11855 }
11856
11857 #[test]
11858 fn goto_create_database_tablespace() {
11859 assert_snapshot!(goto("
11860create tablespace ts location '/tmp';
11861create database d tablespace ts$0;
11862"), @"
11863 ╭▸
11864 2 │ create tablespace ts location '/tmp';
11865 │ ── 2. destination
11866 3 │ create database d tablespace ts;
11867 ╰╴ ─ 1. source
11868 ");
11869 }
11870
11871 #[test]
11872 fn goto_alter_table_set_schema() {
11873 assert_snapshot!(goto("
11874create schema foo;
11875create table t(id int);
11876alter table t set schema fo$0o;
11877"), @r"
11878 ╭▸
11879 2 │ create schema foo;
11880 │ ─── 2. destination
11881 3 │ create table t(id int);
11882 4 │ alter table t set schema foo;
11883 ╰╴ ─ 1. source
11884 ");
11885 }
11886
11887 #[test]
11888 fn goto_alter_table_attach_partition() {
11889 assert_snapshot!(goto("
11890create table parent (id int) partition by range (id);
11891create table child (id int);
11892alter table parent attach partition ch$0ild for values from (1) to (10);
11893"), @r"
11894 ╭▸
11895 3 │ create table child (id int);
11896 │ ───── 2. destination
11897 4 │ alter table parent attach partition child for values from (1) to (10);
11898 ╰╴ ─ 1. source
11899 ");
11900 }
11901
11902 #[test]
11903 fn goto_alter_table_detach_partition() {
11904 assert_snapshot!(goto("
11905create table parent (id int) partition by range (id);
11906create table child partition of parent for values from (1) to (10);
11907alter table parent detach partition ch$0ild;
11908"), @r"
11909 ╭▸
11910 3 │ create table child partition of parent for values from (1) to (10);
11911 │ ───── 2. destination
11912 4 │ alter table parent detach partition child;
11913 ╰╴ ─ 1. source
11914 ");
11915 }
11916
11917 #[test]
11918 fn goto_comment_on_table() {
11919 assert_snapshot!(goto("
11920create table t(id int);
11921comment on table t$0 is '';
11922"), @r"
11923 ╭▸
11924 2 │ create table t(id int);
11925 │ ─ 2. destination
11926 3 │ comment on table t is '';
11927 ╰╴ ─ 1. source
11928 ");
11929 }
11930
11931 #[test]
11932 fn goto_comment_on_column() {
11933 assert_snapshot!(goto("
11934create table t(id int);
11935comment on column t.id$0 is '';
11936"), @"
11937 ╭▸
11938 2 │ create table t(id int);
11939 │ ── 2. destination
11940 3 │ comment on column t.id is '';
11941 ╰╴ ─ 1. source
11942 ");
11943 }
11944
11945 #[test]
11946 fn goto_comment_on_column_table_qualifier() {
11947 assert_snapshot!(goto("
11948create table t(id int);
11949comment on column t$0.id is '';
11950"), @"
11951 ╭▸
11952 2 │ create table t(id int);
11953 │ ─ 2. destination
11954 3 │ comment on column t.id is '';
11955 ╰╴ ─ 1. source
11956 ");
11957 }
11958
11959 #[test]
11960 fn goto_comment_on_column_composite_type_attribute() {
11961 assert_snapshot!(goto("
11962create type address as (city text, zip text);
11963comment on column address.city$0 is 'x';
11964"), @"
11965 ╭▸
11966 2 │ create type address as (city text, zip text);
11967 │ ──── 2. destination
11968 3 │ comment on column address.city is 'x';
11969 ╰╴ ─ 1. source
11970 ");
11971 }
11972
11973 #[test]
11974 fn goto_comment_on_view() {
11975 assert_snapshot!(goto("
11976create view v as select 1;
11977comment on view v$0 is '';
11978"), @"
11979 ╭▸
11980 2 │ create view v as select 1;
11981 │ ─ 2. destination
11982 3 │ comment on view v is '';
11983 ╰╴ ─ 1. source
11984 ");
11985 }
11986
11987 #[test]
11988 fn goto_comment_on_materialized_view() {
11989 assert_snapshot!(goto("
11990create materialized view mv as select 1;
11991comment on materialized view mv$0 is '';
11992"), @"
11993 ╭▸
11994 2 │ create materialized view mv as select 1;
11995 │ ── 2. destination
11996 3 │ comment on materialized view mv is '';
11997 ╰╴ ─ 1. source
11998 ");
11999 }
12000
12001 #[test]
12002 fn goto_comment_on_sequence() {
12003 assert_snapshot!(goto("
12004create sequence s;
12005comment on sequence s$0 is '';
12006"), @"
12007 ╭▸
12008 2 │ create sequence s;
12009 │ ─ 2. destination
12010 3 │ comment on sequence s is '';
12011 ╰╴ ─ 1. source
12012 ");
12013 }
12014
12015 #[test]
12016 fn goto_comment_on_type() {
12017 assert_snapshot!(goto("
12018create type t as (a int);
12019comment on type t$0 is '';
12020"), @"
12021 ╭▸
12022 2 │ create type t as (a int);
12023 │ ─ 2. destination
12024 3 │ comment on type t is '';
12025 ╰╴ ─ 1. source
12026 ");
12027 }
12028
12029 #[test]
12030 fn goto_comment_on_function() {
12031 assert_snapshot!(goto("
12032create function f() returns int language sql as 'select 1';
12033comment on function f$0 is '';
12034"), @"
12035 ╭▸
12036 2 │ create function f() returns int language sql as 'select 1';
12037 │ ─ 2. destination
12038 3 │ comment on function f is '';
12039 ╰╴ ─ 1. source
12040 ");
12041 }
12042
12043 #[test]
12044 fn goto_comment_on_index() {
12045 assert_snapshot!(goto("
12046create table foo(id int);
12047create index i on foo(id);
12048comment on index i$0 is '';
12049"), @"
12050 ╭▸
12051 3 │ create index i on foo(id);
12052 │ ─ 2. destination
12053 4 │ comment on index i is '';
12054 ╰╴ ─ 1. source
12055 ");
12056 }
12057
12058 #[test]
12059 fn goto_comment_on_trigger() {
12060 assert_snapshot!(goto("
12061create table t(a int);
12062create function f() returns trigger language plpgsql as $$
12063begin
12064 return new;
12065end
12066$$;
12067create trigger tr
12068 before insert on t
12069 for each row
12070 execute function f();
12071comment on trigger tr$0 on t is 'x';
12072"), @"
12073 ╭▸
12074 8 │ create trigger tr
12075 │ ── 2. destination
12076 ‡
12077 12 │ comment on trigger tr on t is 'x';
12078 ╰╴ ─ 1. source
12079 ");
12080 }
12081
12082 #[test]
12083 fn goto_comment_on_policy() {
12084 assert_snapshot!(goto("
12085create table t(a int);
12086create policy p on t using (a > 0);
12087comment on policy p$0 on t is 'x';
12088"), @"
12089 ╭▸
12090 3 │ create policy p on t using (a > 0);
12091 │ ─ 2. destination
12092 4 │ comment on policy p on t is 'x';
12093 ╰╴ ─ 1. source
12094 ");
12095 }
12096
12097 #[test]
12098 fn goto_comment_on_rule() {
12099 assert_snapshot!(goto("
12100create table t(a int);
12101create rule r as on select to t do instead nothing;
12102comment on rule r$0 on t is 'x';
12103"), @"
12104 ╭▸
12105 3 │ create rule r as on select to t do instead nothing;
12106 │ ─ 2. destination
12107 4 │ comment on rule r on t is 'x';
12108 ╰╴ ─ 1. source
12109 ");
12110 }
12111
12112 #[test]
12113 fn goto_comment_on_publication() {
12114 assert_snapshot!(goto("
12115create publication pub;
12116comment on publication pub$0 is 'x';
12117"), @"
12118 ╭▸
12119 2 │ create publication pub;
12120 │ ─── 2. destination
12121 3 │ comment on publication pub is 'x';
12122 ╰╴ ─ 1. source
12123 ");
12124 }
12125
12126 #[test]
12127 fn goto_comment_on_subscription() {
12128 assert_snapshot!(goto("
12129create subscription sub connection $$host=localhost$$ publication pub;
12130comment on subscription sub$0 is 'x';
12131"), @"
12132 ╭▸
12133 2 │ create subscription sub connection $$host=localhost$$ publication pub;
12134 │ ─── 2. destination
12135 3 │ comment on subscription sub is 'x';
12136 ╰╴ ─ 1. source
12137 ");
12138 }
12139
12140 #[test]
12141 fn goto_comment_on_foreign_data_wrapper() {
12142 assert_snapshot!(goto("
12143create foreign data wrapper fdw;
12144comment on foreign data wrapper fdw$0 is 'x';
12145"), @"
12146 ╭▸
12147 2 │ create foreign data wrapper fdw;
12148 │ ─── 2. destination
12149 3 │ comment on foreign data wrapper fdw is 'x';
12150 ╰╴ ─ 1. source
12151 ");
12152 }
12153
12154 #[test]
12155 fn goto_comment_on_language() {
12156 assert_snapshot!(goto("
12157create language plfoo;
12158comment on language plfoo$0 is 'x';
12159"), @"
12160 ╭▸
12161 2 │ create language plfoo;
12162 │ ───── 2. destination
12163 3 │ comment on language plfoo is 'x';
12164 ╰╴ ─ 1. source
12165 ");
12166 }
12167
12168 #[test]
12169 fn goto_comment_on_collation() {
12170 assert_snapshot!(goto("
12171create collation mycoll (locale = 'C');
12172comment on collation mycoll$0 is 'x';
12173"), @"
12174 ╭▸
12175 2 │ create collation mycoll (locale = 'C');
12176 │ ────── 2. destination
12177 3 │ comment on collation mycoll is 'x';
12178 ╰╴ ─ 1. source
12179 ");
12180 }
12181
12182 #[test]
12183 fn goto_drop_conversion() {
12184 assert_snapshot!(goto("
12185create conversion conv for 'UTF8' to 'LATIN1' from utf8_to_latin1;
12186drop conversion con$0v;
12187"), @"
12188 ╭▸
12189 2 │ create conversion conv for 'UTF8' to 'LATIN1' from utf8_to_latin1;
12190 │ ──── 2. destination
12191 3 │ drop conversion conv;
12192 ╰╴ ─ 1. source
12193 ");
12194 }
12195
12196 #[test]
12197 fn goto_comment_on_conversion() {
12198 assert_snapshot!(goto("
12199create conversion conv for 'UTF8' to 'LATIN1' from utf8_to_latin1;
12200comment on conversion con$0v is 'x';
12201"), @"
12202 ╭▸
12203 2 │ create conversion conv for 'UTF8' to 'LATIN1' from utf8_to_latin1;
12204 │ ──── 2. destination
12205 3 │ comment on conversion conv is 'x';
12206 ╰╴ ─ 1. source
12207 ");
12208 }
12209
12210 #[test]
12211 fn goto_create_conversion_from_function() {
12212 assert_snapshot!(goto("
12213create function my_conv(integer, integer, cstring, internal, integer) returns void language c as $$x$$;
12214create conversion my_conv_obj for 'UTF8' to 'LATIN1' from my_co$0nv;
12215"), @"
12216 ╭▸
12217 2 │ create function my_conv(integer, integer, cstring, internal, integer) returns void language c as $$x$$;
12218 │ ─────── 2. destination
12219 3 │ create conversion my_conv_obj for 'UTF8' to 'LATIN1' from my_conv;
12220 ╰╴ ─ 1. source
12221 ");
12222 }
12223
12224 #[test]
12225 fn goto_drop_text_search_dictionary() {
12226 assert_snapshot!(goto("
12227create text search dictionary english_stem (template = snowball, language = english);
12228drop text search dictionary english_st$0em;
12229"), @"
12230 ╭▸
12231 2 │ create text search dictionary english_stem (template = snowball, language = english);
12232 │ ──────────── 2. destination
12233 3 │ drop text search dictionary english_stem;
12234 ╰╴ ─ 1. source
12235 ");
12236 }
12237
12238 #[test]
12239 fn goto_alter_text_search_dictionary() {
12240 assert_snapshot!(goto("
12241create text search dictionary english_stem (template = snowball, language = english);
12242alter text search dictionary english_st$0em rename to stemmer;
12243"), @"
12244 ╭▸
12245 2 │ create text search dictionary english_stem (template = snowball, language = english);
12246 │ ──────────── 2. destination
12247 3 │ alter text search dictionary english_stem rename to stemmer;
12248 ╰╴ ─ 1. source
12249 ");
12250 }
12251
12252 #[test]
12253 fn goto_drop_text_search_configuration() {
12254 assert_snapshot!(goto("
12255create text search configuration my_config (parser = pg_catalog.default);
12256drop text search configuration my_conf$0ig;
12257"), @"
12258 ╭▸
12259 2 │ create text search configuration my_config (parser = pg_catalog.default);
12260 │ ───────── 2. destination
12261 3 │ drop text search configuration my_config;
12262 ╰╴ ─ 1. source
12263 ");
12264 }
12265
12266 #[test]
12267 fn goto_alter_text_search_configuration() {
12268 assert_snapshot!(goto("
12269create text search configuration my_config (parser = pg_catalog.default);
12270alter text search configuration my_conf$0ig rename to my_config2;
12271"), @"
12272 ╭▸
12273 2 │ create text search configuration my_config (parser = pg_catalog.default);
12274 │ ───────── 2. destination
12275 3 │ alter text search configuration my_config rename to my_config2;
12276 ╰╴ ─ 1. source
12277 ");
12278 }
12279
12280 #[test]
12281 fn goto_drop_text_search_parser() {
12282 assert_snapshot!(goto("
12283create text search parser my_parser (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
12284drop text search parser my_pars$0er;
12285"), @"
12286 ╭▸
12287 2 │ create text search parser my_parser (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
12288 │ ───────── 2. destination
12289 3 │ drop text search parser my_parser;
12290 ╰╴ ─ 1. source
12291 ");
12292 }
12293
12294 #[test]
12295 fn goto_alter_text_search_parser() {
12296 assert_snapshot!(goto("
12297create text search parser my_parser (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
12298alter text search parser my_pars$0er rename to my_parser2;
12299"), @"
12300 ╭▸
12301 2 │ create text search parser my_parser (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
12302 │ ───────── 2. destination
12303 3 │ alter text search parser my_parser rename to my_parser2;
12304 ╰╴ ─ 1. source
12305 ");
12306 }
12307
12308 #[test]
12309 fn goto_drop_text_search_template() {
12310 assert_snapshot!(goto("
12311create text search template my_template (init = dsimple_init, lexize = dsimple_lexize);
12312drop text search template my_temp$0late;
12313"), @"
12314 ╭▸
12315 2 │ create text search template my_template (init = dsimple_init, lexize = dsimple_lexize);
12316 │ ─────────── 2. destination
12317 3 │ drop text search template my_template;
12318 ╰╴ ─ 1. source
12319 ");
12320 }
12321
12322 #[test]
12323 fn goto_alter_text_search_template() {
12324 assert_snapshot!(goto("
12325create text search template my_template (init = dsimple_init, lexize = dsimple_lexize);
12326alter text search template my_temp$0late rename to my_template2;
12327"), @"
12328 ╭▸
12329 2 │ create text search template my_template (init = dsimple_init, lexize = dsimple_lexize);
12330 │ ─────────── 2. destination
12331 3 │ alter text search template my_template rename to my_template2;
12332 ╰╴ ─ 1. source
12333 ");
12334 }
12335
12336 #[test]
12337 fn goto_create_text_search_parser_function_option() {
12338 assert_snapshot!(goto("
12339create function start_fn(internal, int) returns internal language c as $$x$$;
12340create text search parser p (start = start_$0fn, gettoken = g, end = e, lextypes = l);
12341"), @"
12342 ╭▸
12343 2 │ create function start_fn(internal, int) returns internal language c as $$x$$;
12344 │ ──────── 2. destination
12345 3 │ create text search parser p (start = start_fn, gettoken = g, end = e, lextypes = l);
12346 ╰╴ ─ 1. source
12347 ");
12348 }
12349
12350 #[test]
12351 fn goto_create_text_search_template_function_option() {
12352 assert_snapshot!(goto("
12353create function init_fn(internal) returns internal language c as $$x$$;
12354create text search template t (init = init_$0fn, lexize = lex_fn);
12355"), @"
12356 ╭▸
12357 2 │ create function init_fn(internal) returns internal language c as $$x$$;
12358 │ ─────── 2. destination
12359 3 │ create text search template t (init = init_fn, lexize = lex_fn);
12360 ╰╴ ─ 1. source
12361 ");
12362 }
12363
12364 #[test]
12365 fn goto_create_text_search_configuration_parser_option() {
12366 assert_snapshot!(goto("
12367create text search parser my_parser (start = s, gettoken = g, end = e, lextypes = l);
12368create text search configuration cfg (parser = my_par$0ser);
12369"), @"
12370 ╭▸
12371 2 │ create text search parser my_parser (start = s, gettoken = g, end = e, lextypes = l);
12372 │ ───────── 2. destination
12373 3 │ create text search configuration cfg (parser = my_parser);
12374 ╰╴ ─ 1. source
12375 ");
12376 }
12377
12378 #[test]
12379 fn goto_create_text_search_configuration_copy_option() {
12380 assert_snapshot!(goto("
12381create text search configuration src (parser = pg_catalog.default);
12382create text search configuration cfg (copy = sr$0c);
12383"), @"
12384 ╭▸
12385 2 │ create text search configuration src (parser = pg_catalog.default);
12386 │ ─── 2. destination
12387 3 │ create text search configuration cfg (copy = src);
12388 ╰╴ ─ 1. source
12389 ");
12390 }
12391
12392 #[test]
12393 fn goto_create_text_search_dictionary_template_option() {
12394 assert_snapshot!(goto("
12395create text search template my_template (init = i, lexize = l);
12396create text search dictionary dict (template = my_temp$0late);
12397"), @"
12398 ╭▸
12399 2 │ create text search template my_template (init = i, lexize = l);
12400 │ ─────────── 2. destination
12401 3 │ create text search dictionary dict (template = my_template);
12402 ╰╴ ─ 1. source
12403 ");
12404 }
12405
12406 #[test]
12407 fn goto_alter_text_search_configuration_add_mapping_dictionary() {
12408 assert_snapshot!(goto("
12409create text search dictionary dict (template = pg_catalog.simple);
12410create text search configuration cfg (parser = pg_catalog.default);
12411alter text search configuration cfg add mapping for asciiword with dic$0t;
12412"), @"
12413 ╭▸
12414 2 │ create text search dictionary dict (template = pg_catalog.simple);
12415 │ ──── 2. destination
12416 3 │ create text search configuration cfg (parser = pg_catalog.default);
12417 4 │ alter text search configuration cfg add mapping for asciiword with dict;
12418 ╰╴ ─ 1. source
12419 ");
12420 }
12421
12422 #[test]
12423 fn goto_alter_text_search_configuration_alter_mapping_with_dictionary() {
12424 assert_snapshot!(goto("
12425create text search dictionary d1 (template = pg_catalog.simple);
12426create text search configuration cfg (parser = pg_catalog.default);
12427alter text search configuration cfg alter mapping for asciiword with d$01;
12428"), @"
12429 ╭▸
12430 2 │ create text search dictionary d1 (template = pg_catalog.simple);
12431 │ ── 2. destination
12432 3 │ create text search configuration cfg (parser = pg_catalog.default);
12433 4 │ alter text search configuration cfg alter mapping for asciiword with d1;
12434 ╰╴ ─ 1. source
12435 ");
12436 }
12437
12438 #[test]
12439 fn goto_alter_text_search_configuration_alter_mapping_replace_dictionary() {
12440 assert_snapshot!(goto("
12441create text search dictionary d1 (template = pg_catalog.simple);
12442create text search dictionary d2 (template = pg_catalog.simple);
12443create text search configuration cfg (parser = pg_catalog.default);
12444alter text search configuration cfg alter mapping replace d1 with d$02;
12445"), @"
12446 ╭▸
12447 3 │ create text search dictionary d2 (template = pg_catalog.simple);
12448 │ ── 2. destination
12449 4 │ create text search configuration cfg (parser = pg_catalog.default);
12450 5 │ alter text search configuration cfg alter mapping replace d1 with d2;
12451 ╰╴ ─ 1. source
12452 ");
12453 }
12454
12455 #[test]
12456 fn goto_drop_access_method() {
12457 assert_snapshot!(goto("
12458create access method heap2 type table handler heap_tableam_handler;
12459drop access method hea$0p2;
12460"), @"
12461 ╭▸
12462 2 │ create access method heap2 type table handler heap_tableam_handler;
12463 │ ───── 2. destination
12464 3 │ drop access method heap2;
12465 ╰╴ ─ 1. source
12466 ");
12467 }
12468
12469 #[test]
12470 fn goto_set_access_method() {
12471 assert_snapshot!(goto("
12472create access method heap2 type table handler heap_tableam_handler;
12473alter table t set access method hea$0p2;
12474"), @"
12475 ╭▸
12476 2 │ create access method heap2 type table handler heap_tableam_handler;
12477 │ ───── 2. destination
12478 3 │ alter table t set access method heap2;
12479 ╰╴ ─ 1. source
12480 ");
12481 }
12482
12483 #[test]
12484 fn goto_drop_operator_family() {
12485 assert_snapshot!(goto("
12486create operator family my_family using btree;
12487drop operator family my_fami$0ly using btree;
12488"), @"
12489 ╭▸
12490 2 │ create operator family my_family using btree;
12491 │ ───────── 2. destination
12492 3 │ drop operator family my_family using btree;
12493 ╰╴ ─ 1. source
12494 ");
12495 }
12496
12497 #[test]
12498 fn goto_alter_operator_family() {
12499 assert_snapshot!(goto("
12500create operator family my_family using btree;
12501alter operator family my_fami$0ly using btree owner to someone;
12502"), @"
12503 ╭▸
12504 2 │ create operator family my_family using btree;
12505 │ ───────── 2. destination
12506 3 │ alter operator family my_family using btree owner to someone;
12507 ╰╴ ─ 1. source
12508 ");
12509 }
12510
12511 #[test]
12512 fn goto_comment_on_operator_family() {
12513 assert_snapshot!(goto("
12514create operator family my_family using btree;
12515comment on operator family my_fami$0ly using btree is 'hi';
12516"), @"
12517 ╭▸
12518 2 │ create operator family my_family using btree;
12519 │ ───────── 2. destination
12520 3 │ comment on operator family my_family using btree is 'hi';
12521 ╰╴ ─ 1. source
12522 ");
12523 }
12524
12525 #[test]
12526 fn goto_comment_on_operator_class() {
12527 assert_snapshot!(goto("
12528create operator class my_opclass for type int using btree as operator 1 < (int, int);
12529comment on operator class my_opcla$0ss using btree is 'hi';
12530"), @"
12531 ╭▸
12532 2 │ create operator class my_opclass for type int using btree as operator 1 < (int, int);
12533 │ ────────── 2. destination
12534 3 │ comment on operator class my_opclass using btree is 'hi';
12535 ╰╴ ─ 1. source
12536 ");
12537 }
12538
12539 #[test]
12540 fn goto_drop_operator_class() {
12541 assert_snapshot!(goto("
12542create operator class my_opclass for type int using btree as operator 1 < (int, int);
12543drop operator class my_opcla$0ss using btree;
12544"), @"
12545 ╭▸
12546 2 │ create operator class my_opclass for type int using btree as operator 1 < (int, int);
12547 │ ────────── 2. destination
12548 3 │ drop operator class my_opclass using btree;
12549 ╰╴ ─ 1. source
12550 ");
12551 }
12552
12553 #[test]
12554 fn goto_alter_operator_class() {
12555 assert_snapshot!(goto("
12556create operator class my_opclass for type int using btree as operator 1 < (int, int);
12557alter operator class my_opcla$0ss using btree owner to someone;
12558"), @"
12559 ╭▸
12560 2 │ create operator class my_opclass for type int using btree as operator 1 < (int, int);
12561 │ ────────── 2. destination
12562 3 │ alter operator class my_opclass using btree owner to someone;
12563 ╰╴ ─ 1. source
12564 ");
12565 }
12566
12567 #[test]
12568 fn goto_create_index_using_access_method() {
12569 assert_snapshot!(goto("
12570create function my_handler(internal) returns index_am_handler language c as $$x$$;
12571create access method my_am type index handler my_handler;
12572create table t(id int);
12573create index on t using my_a$0m (id);
12574"), @"
12575 ╭▸
12576 3 │ create access method my_am type index handler my_handler;
12577 │ ───── 2. destination
12578 4 │ create table t(id int);
12579 5 │ create index on t using my_am (id);
12580 ╰╴ ─ 1. source
12581 ");
12582 }
12583
12584 #[test]
12585 fn goto_create_table_using_access_method() {
12586 assert_snapshot!(goto("
12587create function my_handler(internal) returns table_am_handler language c as $$x$$;
12588create access method my_am type table handler my_handler;
12589create table t(id int) using my_a$0m;
12590"), @"
12591 ╭▸
12592 3 │ create access method my_am type table handler my_handler;
12593 │ ───── 2. destination
12594 4 │ create table t(id int) using my_am;
12595 ╰╴ ─ 1. source
12596 ");
12597 }
12598
12599 #[test]
12600 fn goto_create_operator_family_using_access_method() {
12601 assert_snapshot!(goto("
12602create function my_handler(internal) returns index_am_handler language c as $$x$$;
12603create access method my_am type index handler my_handler;
12604create operator family fam using my_a$0m;
12605"), @"
12606 ╭▸
12607 3 │ create access method my_am type index handler my_handler;
12608 │ ───── 2. destination
12609 4 │ create operator family fam using my_am;
12610 ╰╴ ─ 1. source
12611 ");
12612 }
12613
12614 #[test]
12615 fn goto_create_operator_class_using_access_method() {
12616 assert_snapshot!(goto("
12617create function my_handler(internal) returns index_am_handler language c as $$x$$;
12618create access method my_am type index handler my_handler;
12619create operator class my_opclass for type int using my_a$0m as storage int;
12620"), @"
12621 ╭▸
12622 3 │ create access method my_am type index handler my_handler;
12623 │ ───── 2. destination
12624 4 │ create operator class my_opclass for type int using my_am as storage int;
12625 ╰╴ ─ 1. source
12626 ");
12627 }
12628
12629 #[test]
12630 fn goto_create_operator_class_family() {
12631 assert_snapshot!(goto("
12632create function h(internal) returns index_am_handler language c as $$x$$;
12633create access method fam type index handler h;
12634create operator family fam using btree;
12635create operator class ops for type int using btree family fa$0m as operator 1 <;
12636"), @"
12637 ╭▸
12638 4 │ create operator family fam using btree;
12639 │ ─── 2. destination
12640 5 │ create operator class ops for type int using btree family fam as operator 1 <;
12641 ╰╴ ─ 1. source
12642 ");
12643 }
12644
12645 #[test]
12646 fn goto_create_operator_class_for_order_by_family() {
12647 assert_snapshot!(goto("
12648create operator family sort_fam using btree;
12649create operator class ops for type int using gist as operator 1 <-> for order by sort_f$0am;
12650"), @"
12651 ╭▸
12652 2 │ create operator family sort_fam using btree;
12653 │ ──────── 2. destination
12654 3 │ create operator class ops for type int using gist as operator 1 <-> for order by sort_fam;
12655 ╰╴ ─ 1. source
12656 ");
12657 }
12658
12659 #[test]
12660 fn goto_insert_on_conflict_operator_class() {
12661 assert_snapshot!(goto("
12662create operator class my_ops for type int using btree as operator 1 <;
12663create table t(a int);
12664insert into t values (1) on conflict (a my_o$0ps) do nothing;
12665"), @"
12666 ╭▸
12667 2 │ create operator class my_ops for type int using btree as operator 1 <;
12668 │ ────── 2. destination
12669 3 │ create table t(a int);
12670 4 │ insert into t values (1) on conflict (a my_ops) do nothing;
12671 ╰╴ ─ 1. source
12672 ");
12673 }
12674
12675 #[test]
12676 fn goto_create_index_operator_class() {
12677 assert_snapshot!(goto("
12678create operator class public.my_ops for type int using btree as operator 1 <, function 1 btint4cmp(int,int);
12679create table t(a int);
12680create index idx on t (a public.my_o$0ps);
12681"), @"
12682 ╭▸
12683 2 │ create operator class public.my_ops for type int using btree as operator 1 <, function 1 btint4cmp(int,int);
12684 │ ────── 2. destination
12685 3 │ create table t(a int);
12686 4 │ create index idx on t (a public.my_ops);
12687 ╰╴ ─ 1. source
12688 ");
12689 }
12690
12691 #[test]
12692 fn goto_alter_operator_family_using_access_method() {
12693 assert_snapshot!(goto("
12694create function my_handler(internal) returns index_am_handler language c as $$x$$;
12695create access method my_am type index handler my_handler;
12696create operator family fam using my_am;
12697alter operator family fam using my_a$0m owner to someone;
12698"), @"
12699 ╭▸
12700 3 │ create access method my_am type index handler my_handler;
12701 │ ───── 2. destination
12702 4 │ create operator family fam using my_am;
12703 5 │ alter operator family fam using my_am owner to someone;
12704 ╰╴ ─ 1. source
12705 ");
12706 }
12707
12708 #[test]
12709 fn goto_drop_operator_class_using_access_method() {
12710 assert_snapshot!(goto("
12711create function my_handler(internal) returns index_am_handler language c as $$x$$;
12712create access method my_am type index handler my_handler;
12713create operator class my_opclass for type int using my_am as storage int;
12714drop operator class my_opclass using my_a$0m;
12715"), @"
12716 ╭▸
12717 3 │ create access method my_am type index handler my_handler;
12718 │ ───── 2. destination
12719 4 │ create operator class my_opclass for type int using my_am as storage int;
12720 5 │ drop operator class my_opclass using my_am;
12721 ╰╴ ─ 1. source
12722 ");
12723 }
12724
12725 #[test]
12726 fn goto_operator_class_function_option() {
12727 assert_snapshot!(goto("
12728create function my_cmp(int, int) returns int language sql as $$select 0$$;
12729create operator class my_opclass for type int using btree as function 1 my_cm$0p(int, int);
12730"), @"
12731 ╭▸
12732 2 │ create function my_cmp(int, int) returns int language sql as $$select 0$$;
12733 │ ────── 2. destination
12734 3 │ create operator class my_opclass for type int using btree as function 1 my_cmp(int, int);
12735 ╰╴ ─ 1. source
12736 ");
12737 }
12738
12739 #[test]
12740 fn goto_drop_operator_class_explicit_schema() {
12741 assert_snapshot!(goto("
12742create schema app;
12743create operator class app.my_ops for type int using btree as storage int;
12744drop operator class app.my_o$0ps using btree;
12745"), @"
12746 ╭▸
12747 3 │ create operator class app.my_ops for type int using btree as storage int;
12748 │ ────── 2. destination
12749 4 │ drop operator class app.my_ops using btree;
12750 ╰╴ ─ 1. source
12751 ");
12752 }
12753
12754 #[test]
12755 fn goto_drop_operator_class_wrong_explicit_schema_not_found() {
12756 goto_not_found(
12757 "
12758create schema app;
12759create operator class app.my_ops for type int using btree as storage int;
12760set search_path to app;
12761drop operator class public.my_o$0ps using btree;
12762",
12763 );
12764 }
12765
12766 #[test]
12767 fn goto_drop_collation_explicit_schema() {
12768 assert_snapshot!(goto(r#"
12769create schema app;
12770create collation app.coll (locale = 'C');
12771drop collation app.co$0ll;
12772"#), @"
12773 ╭▸
12774 3 │ create collation app.coll (locale = 'C');
12775 │ ──── 2. destination
12776 4 │ drop collation app.coll;
12777 ╰╴ ─ 1. source
12778 ");
12779 }
12780
12781 #[test]
12782 fn goto_drop_text_search_configuration_explicit_schema() {
12783 assert_snapshot!(goto("
12784create schema app;
12785create text search configuration app.cfg (parser = pg_catalog.default);
12786drop text search configuration app.c$0fg;
12787"), @"
12788 ╭▸
12789 3 │ create text search configuration app.cfg (parser = pg_catalog.default);
12790 │ ─── 2. destination
12791 4 │ drop text search configuration app.cfg;
12792 ╰╴ ─ 1. source
12793 ");
12794 }
12795
12796 #[test]
12797 fn goto_drop_text_search_configuration_wrong_explicit_schema_not_found() {
12798 goto_not_found(
12799 "
12800create schema app;
12801create text search configuration app.cfg (parser = pg_catalog.default);
12802set search_path to app;
12803drop text search configuration public.c$0fg;
12804",
12805 );
12806 }
12807
12808 #[test]
12809 fn goto_grant_table_explicit_schema() {
12810 assert_snapshot!(goto("
12811create schema app;
12812create table app.t(a int);
12813grant select on app.t$0 to public;
12814"), @"
12815 ╭▸
12816 3 │ create table app.t(a int);
12817 │ ─ 2. destination
12818 4 │ grant select on app.t to public;
12819 ╰╴ ─ 1. source
12820 ");
12821 }
12822
12823 #[test]
12824 fn goto_grant_table_wrong_explicit_schema_not_found() {
12825 goto_not_found(
12826 "
12827create schema app;
12828create table app.t(a int);
12829set search_path to app;
12830grant select on public.t$0 to public;
12831",
12832 );
12833 }
12834
12835 #[test]
12836 fn goto_security_label_table() {
12837 assert_snapshot!(goto("
12838create table foo(id int);
12839security label on table foo$0 is 'x';
12840"), @"
12841 ╭▸
12842 2 │ create table foo(id int);
12843 │ ─── 2. destination
12844 3 │ security label on table foo is 'x';
12845 ╰╴ ─ 1. source
12846 ");
12847 }
12848
12849 #[test]
12850 fn goto_security_label_column() {
12851 assert_snapshot!(goto("
12852create table foo(id int);
12853security label on column foo.id$0 is 'x';
12854"), @"
12855 ╭▸
12856 2 │ create table foo(id int);
12857 │ ── 2. destination
12858 3 │ security label on column foo.id is 'x';
12859 ╰╴ ─ 1. source
12860 ");
12861 }
12862
12863 #[test]
12864 fn goto_security_label_column_table_qualifier() {
12865 assert_snapshot!(goto("
12866create table foo(id int);
12867security label on column foo$0.id is 'x';
12868"), @"
12869 ╭▸
12870 2 │ create table foo(id int);
12871 │ ─── 2. destination
12872 3 │ security label on column foo.id is 'x';
12873 ╰╴ ─ 1. source
12874 ");
12875 }
12876
12877 #[test]
12878 fn goto_security_label_view() {
12879 assert_snapshot!(goto("
12880create view v as select 1;
12881security label on view v$0 is 'x';
12882"), @"
12883 ╭▸
12884 2 │ create view v as select 1;
12885 │ ─ 2. destination
12886 3 │ security label on view v is 'x';
12887 ╰╴ ─ 1. source
12888 ");
12889 }
12890
12891 #[test]
12892 fn goto_security_label_type() {
12893 assert_snapshot!(goto("
12894create type t as (a int);
12895security label on type t$0 is 'x';
12896"), @"
12897 ╭▸
12898 2 │ create type t as (a int);
12899 │ ─ 2. destination
12900 3 │ security label on type t is 'x';
12901 ╰╴ ─ 1. source
12902 ");
12903 }
12904
12905 #[test]
12906 fn goto_security_label_function() {
12907 assert_snapshot!(goto("
12908create function f() returns int language sql as 'select 1';
12909security label on function f$0() is 'x';
12910"), @"
12911 ╭▸
12912 2 │ create function f() returns int language sql as 'select 1';
12913 │ ─ 2. destination
12914 3 │ security label on function f() is 'x';
12915 ╰╴ ─ 1. source
12916 ");
12917 }
12918
12919 #[test]
12920 fn goto_security_label_provider_unresolved() {
12921 goto_not_found(
12922 "
12923create table foo(id int);
12924security label for prov$0 on table foo is 'x';
12925",
12926 );
12927 }
12928
12929 #[test]
12930 fn goto_refresh_materialized_view() {
12931 assert_snapshot!(goto("
12932create materialized view mv as select 1;
12933refresh materialized view mv$0;
12934"), @r"
12935 ╭▸
12936 2 │ create materialized view mv as select 1;
12937 │ ── 2. destination
12938 3 │ refresh materialized view mv;
12939 ╰╴ ─ 1. source
12940 ");
12941 }
12942
12943 #[test]
12944 fn goto_refresh_materialized_view_concurrently() {
12945 assert_snapshot!(goto("
12946create materialized view mv as select 1;
12947refresh materialized view concurrently mv$0;
12948"), @r"
12949 ╭▸
12950 2 │ create materialized view mv as select 1;
12951 │ ── 2. destination
12952 3 │ refresh materialized view concurrently mv;
12953 ╰╴ ─ 1. source
12954 ");
12955 }
12956
12957 #[test]
12958 fn goto_reindex_table() {
12959 assert_snapshot!(goto("
12960create table users(id int);
12961reindex table users$0;
12962"), @r"
12963 ╭▸
12964 2 │ create table users(id int);
12965 │ ───── 2. destination
12966 3 │ reindex table users;
12967 ╰╴ ─ 1. source
12968 ");
12969 }
12970
12971 #[test]
12972 fn goto_reindex_index() {
12973 assert_snapshot!(goto("
12974create table t(c int);
12975create index idx on t(c);
12976reindex index idx$0;
12977"), @r"
12978 ╭▸
12979 3 │ create index idx on t(c);
12980 │ ─── 2. destination
12981 4 │ reindex index idx;
12982 ╰╴ ─ 1. source
12983 ");
12984 }
12985
12986 #[test]
12987 fn goto_cluster_table() {
12988 assert_snapshot!(goto("
12989create table foo(id int);
12990cluster foo$0;
12991"), @"
12992 ╭▸
12993 2 │ create table foo(id int);
12994 │ ─── 2. destination
12995 3 │ cluster foo;
12996 ╰╴ ─ 1. source
12997 ");
12998 }
12999
13000 #[test]
13001 fn goto_cluster_using_index() {
13002 assert_snapshot!(goto("
13003create table foo(id int);
13004create index i on foo(id);
13005cluster foo using i$0;
13006"), @"
13007 ╭▸
13008 3 │ create index i on foo(id);
13009 │ ─ 2. destination
13010 4 │ cluster foo using i;
13011 ╰╴ ─ 1. source
13012 ");
13013 }
13014
13015 #[test]
13016 fn goto_alter_table_cluster_on() {
13017 assert_snapshot!(goto("
13018create table t(a int);
13019create index idx on t(a);
13020alter table t cluster on idx$0;
13021"), @"
13022 ╭▸
13023 3 │ create index idx on t(a);
13024 │ ─── 2. destination
13025 4 │ alter table t cluster on idx;
13026 ╰╴ ─ 1. source
13027 ");
13028 }
13029
13030 #[test]
13031 fn goto_alter_table_replica_identity_using_index() {
13032 assert_snapshot!(goto("
13033create table t(a int);
13034create unique index idx on t(a);
13035alter table t replica identity using index idx$0;
13036"), @"
13037 ╭▸
13038 3 │ create unique index idx on t(a);
13039 │ ─── 2. destination
13040 4 │ alter table t replica identity using index idx;
13041 ╰╴ ─ 1. source
13042 ");
13043 }
13044
13045 #[test]
13046 fn goto_copy_table() {
13047 assert_snapshot!(goto("
13048create table foo (id int);
13049copy foo$0 to stdout;
13050"), @"
13051 ╭▸
13052 2 │ create table foo (id int);
13053 │ ─── 2. destination
13054 3 │ copy foo to stdout;
13055 ╰╴ ─ 1. source
13056 ");
13057 }
13058
13059 #[test]
13060 fn goto_copy_column() {
13061 assert_snapshot!(goto("
13062create table foo (id int);
13063copy foo (id$0) to stdout;
13064"), @"
13065 ╭▸
13066 2 │ create table foo (id int);
13067 │ ── 2. destination
13068 3 │ copy foo (id) to stdout;
13069 ╰╴ ─ 1. source
13070 ");
13071 }
13072
13073 #[test]
13074 fn goto_select_exists_column() {
13075 assert_snapshot!(goto("
13076select exists$0 from (
13077 select exists(select 1)
13078);
13079"), @r"
13080 ╭▸
13081 2 │ select exists from (
13082 │ ─ 1. source
13083 3 │ select exists(select 1)
13084 ╰╴ ──────────────── 2. destination
13085 ");
13086 }
13087
13088 #[test]
13089 fn goto_reindex_schema() {
13090 assert_snapshot!(goto("
13091create schema app;
13092reindex schema app$0;
13093"), @r"
13094 ╭▸
13095 2 │ create schema app;
13096 │ ─── 2. destination
13097 3 │ reindex schema app;
13098 ╰╴ ─ 1. source
13099 ");
13100 }
13101
13102 #[test]
13103 fn goto_reindex_database() {
13104 assert_snapshot!(goto("
13105create database appdb;
13106reindex database appdb$0;
13107"), @r"
13108 ╭▸
13109 2 │ create database appdb;
13110 │ ───── 2. destination
13111 3 │ reindex database appdb;
13112 ╰╴ ─ 1. source
13113 ");
13114 }
13115
13116 #[test]
13117 fn goto_reindex_system() {
13118 assert_snapshot!(goto("
13119create database systemdb;
13120reindex system systemdb$0;
13121"), @r"
13122 ╭▸
13123 2 │ create database systemdb;
13124 │ ──────── 2. destination
13125 3 │ reindex system systemdb;
13126 ╰╴ ─ 1. source
13127 ");
13128 }
13129
13130 #[test]
13131 fn goto_merge_returning_aliased_column() {
13132 assert_snapshot!(goto(
13133 "
13134create table t(a int, b int);
13135with u(x, y) as (
13136 select 1, 2
13137),
13138merged as (
13139 merge into t
13140 using u
13141 on t.a = u.x
13142 when matched then
13143 do nothing
13144 when not matched then
13145 do nothing
13146 returning a as x, b as y
13147)
13148select x$0 from merged;
13149",
13150 ), @r"
13151 ╭▸
13152 14 │ returning a as x, b as y
13153 │ ─ 2. destination
13154 15 │ )
13155 16 │ select x from merged;
13156 ╰╴ ─ 1. source
13157 ");
13158 }
13159
13160 #[test]
13161 fn goto_cte_update_returning_column() {
13162 assert_snapshot!(goto("
13163create table t(a int, b int);
13164with updated(c) as (
13165 update t set a = 10
13166 returning a, b
13167)
13168select c, b$0 from updated;"
13169 ), @r"
13170 ╭▸
13171 5 │ returning a, b
13172 │ ─ 2. destination
13173 6 │ )
13174 7 │ select c, b from updated;
13175 ╰╴ ─ 1. source
13176 ");
13177 }
13178
13179 #[test]
13180 fn goto_update_returning_column_to_table_def() {
13181 assert_snapshot!(goto("
13182create table t(a int, b int);
13183with updated(c) as (
13184 update t set a = 10
13185 returning a, b$0
13186)
13187select c, b from updated;"
13188 ), @r"
13189 ╭▸
13190 2 │ create table t(a int, b int);
13191 │ ─ 2. destination
13192 ‡
13193 5 │ returning a, b
13194 ╰╴ ─ 1. source
13195 ");
13196 }
13197
13198 #[test]
13199 fn goto_insert_returning_column_to_table_def() {
13200 assert_snapshot!(goto("
13201create table t(a int, b int);
13202with inserted as (
13203 insert into t values (1, 2)
13204 returning a$0, b
13205)
13206select a, b from inserted;"
13207 ), @r"
13208 ╭▸
13209 2 │ create table t(a int, b int);
13210 │ ─ 2. destination
13211 ‡
13212 5 │ returning a, b
13213 ╰╴ ─ 1. source
13214 ");
13215 }
13216
13217 #[test]
13218 fn goto_delete_returning_column_to_table_def() {
13219 assert_snapshot!(goto("
13220create table t(a int, b int);
13221with deleted as (
13222 delete from t
13223 returning a, b$0
13224)
13225select a, b from deleted;"
13226 ), @r"
13227 ╭▸
13228 2 │ create table t(a int, b int);
13229 │ ─ 2. destination
13230 ‡
13231 5 │ returning a, b
13232 ╰╴ ─ 1. source
13233 ");
13234 }
13235
13236 #[test]
13237 fn goto_update_returning_qualified_star_table() {
13238 assert_snapshot!(goto("
13239create table t(a int, b int);
13240update t set a = 10
13241returning t$0.*;"
13242 ), @r"
13243 ╭▸
13244 2 │ create table t(a int, b int);
13245 │ ─ 2. destination
13246 3 │ update t set a = 10
13247 4 │ returning t.*;
13248 ╰╴ ─ 1. source
13249 ");
13250 }
13251
13252 #[test]
13253 fn goto_insert_returning_qualified_star_table() {
13254 assert_snapshot!(goto("
13255create table t(a int, b int);
13256insert into t values (1, 2)
13257returning t$0.*;"
13258 ), @r"
13259 ╭▸
13260 2 │ create table t(a int, b int);
13261 │ ─ 2. destination
13262 3 │ insert into t values (1, 2)
13263 4 │ returning t.*;
13264 ╰╴ ─ 1. source
13265 ");
13266 }
13267
13268 #[test]
13269 fn goto_delete_returning_qualified_star_table() {
13270 assert_snapshot!(goto("
13271create table t(a int, b int);
13272delete from t
13273returning t$0.*;"
13274 ), @r"
13275 ╭▸
13276 2 │ create table t(a int, b int);
13277 │ ─ 2. destination
13278 3 │ delete from t
13279 4 │ returning t.*;
13280 ╰╴ ─ 1. source
13281 ");
13282 }
13283
13284 #[test]
13285 fn goto_update_alias_in_set_clause() {
13286 goto_not_found(
13291 "
13292create table t(a int, b int);
13293update t as f set f$0.a = 10;",
13294 );
13295 }
13296
13297 #[test]
13298 fn goto_update_set_clause_subfield() {
13299 goto_not_found(
13301 "
13302create table t(a point, b int);
13303update t set a.x$0 = 10;",
13304 );
13305 }
13306
13307 #[test]
13308 fn goto_update_set_clause_composite_type_subfield() {
13309 assert_snapshot!(goto(
13310 "
13311create type coordinate as (
13312 x double precision,
13313 y double precision
13314);
13315create table t (
13316 a coordinate,
13317 b integer
13318);
13319update t set a.x$0 = 10;",
13320 ), @"
13321 ╭▸
13322 3 │ x double precision,
13323 │ ─ 2. destination
13324 ‡
13325 10 │ update t set a.x = 10;
13326 ╰╴ ─ 1. source
13327 ");
13328 }
13329
13330 #[test]
13331 fn goto_update_set_clause_composite_type_col_name() {
13332 assert_snapshot!(goto(
13333 "
13334create type coordinate as (
13335 x double precision,
13336 y double precision
13337);
13338create table t (
13339 a coordinate,
13340 b integer
13341);
13342update t set a$0.x = 10;",
13343 ), @"
13344 ╭▸
13345 7 │ a coordinate,
13346 │ ─ 2. destination
13347 ‡
13348 10 │ update t set a.x = 10;
13349 ╰╴ ─ 1. source
13350 ");
13351 }
13352
13353 #[test]
13354 fn goto_update_alias_in_where_clause() {
13355 assert_snapshot!(goto("
13356create table t(a int, b int);
13357update t as f set a = 10 where f$0.b = 5;"
13358 ), @r"
13359 ╭▸
13360 3 │ update t as f set a = 10 where f.b = 5;
13361 ╰╴ ─ 2. destination ─ 1. source
13362 ");
13363 }
13364
13365 #[test]
13366 fn goto_update_alias_in_from_clause() {
13367 assert_snapshot!(goto("
13368create table t(a int, b int);
13369create table u(c int);
13370update t as f set a = 10 from u where f$0.b = u.c;"
13371 ), @r"
13372 ╭▸
13373 4 │ update t as f set a = 10 from u where f.b = u.c;
13374 ╰╴ ─ 2. destination ─ 1. source
13375 ");
13376 }
13377
13378 #[test]
13379 fn goto_insert_alias_in_on_conflict() {
13380 assert_snapshot!(goto("
13381create table t(a int primary key, b int);
13382insert into t as f values (1, 2) on conflict (f$0.a) do nothing;"
13383 ), @r"
13384 ╭▸
13385 3 │ insert into t as f values (1, 2) on conflict (f.a) do nothing;
13386 ╰╴ ─ 2. destination ─ 1. source
13387 ");
13388 }
13389
13390 #[test]
13391 fn goto_insert_alias_in_returning() {
13392 assert_snapshot!(goto("
13393create table t(a int, b int);
13394insert into t as f values (1, 2) returning f$0.a;"
13395 ), @r"
13396 ╭▸
13397 3 │ insert into t as f values (1, 2) returning f.a;
13398 ╰╴ ─ 2. destination ─ 1. source
13399 ");
13400 }
13401
13402 #[test]
13403 fn goto_insert_alias_returning_column() {
13404 assert_snapshot!(goto("
13405create table t(a int, b int);
13406insert into t as f values (1, 2) returning f.a$0;"
13407 ), @r"
13408 ╭▸
13409 2 │ create table t(a int, b int);
13410 │ ─ 2. destination
13411 3 │ insert into t as f values (1, 2) returning f.a;
13412 ╰╴ ─ 1. source
13413 ");
13414 }
13415
13416 #[test]
13417 fn goto_insert_on_conflict_target_column() {
13418 assert_snapshot!(goto("
13419create table t(c text);
13420insert into t values ('c') on conflict (c$0) do nothing;"
13421 ), @r"
13422 ╭▸
13423 2 │ create table t(c text);
13424 │ ─ 2. destination
13425 3 │ insert into t values ('c') on conflict (c) do nothing;
13426 ╰╴ ─ 1. source
13427 ");
13428 }
13429
13430 #[test]
13431 fn goto_insert_on_conflict_set_column() {
13432 assert_snapshot!(goto("
13433create table t(c text, d text);
13434insert into t values ('c', 'd') on conflict (c) do update set c$0 = excluded.c;"
13435 ), @r"
13436 ╭▸
13437 2 │ create table t(c text, d text);
13438 │ ─ 2. destination
13439 3 │ insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c;
13440 ╰╴ ─ 1. source
13441 ");
13442 }
13443
13444 #[test]
13445 fn goto_insert_on_conflict_excluded_column() {
13446 assert_snapshot!(goto("
13447create table t(c text, d text);
13448insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c$0;"
13449 ), @r"
13450 ╭▸
13451 2 │ create table t(c text, d text);
13452 │ ─ 2. destination
13453 3 │ insert into t values ('c', 'd') on conflict (c) do update set c = excluded.c;
13454 ╰╴ ─ 1. source
13455 ");
13456 }
13457
13458 #[test]
13459 fn goto_insert_on_conflict_qualified_function() {
13460 assert_snapshot!(goto("
13461create function foo.lower(text) returns text
13462 language internal;
13463create table t(c text);
13464insert into t values ('c')
13465 on conflict (foo.lower$0(c))
13466 do nothing;"
13467 ), @r"
13468 ╭▸
13469 2 │ create function foo.lower(text) returns text
13470 │ ───── 2. destination
13471 ‡
13472 6 │ on conflict (foo.lower(c))
13473 ╰╴ ─ 1. source
13474 ");
13475 }
13476
13477 #[test]
13478 fn goto_delete_from_alias() {
13479 assert_snapshot!(goto("
13480create table t(a int, b int);
13481delete from t as f where f$0.a = 10;"
13482 ), @r"
13483 ╭▸
13484 3 │ delete from t as f where f.a = 10;
13485 │ ┬ ─ 1. source
13486 │ │
13487 ╰╴ 2. destination
13488 ");
13489 }
13490
13491 #[test]
13492 fn goto_delete_from_alias_column() {
13493 assert_snapshot!(goto("
13494create table t(a int, b int);
13495delete from t as f where f.a$0 = 10;"
13496 ), @r"
13497 ╭▸
13498 2 │ create table t(a int, b int);
13499 │ ─ 2. destination
13500 3 │ delete from t as f where f.a = 10;
13501 ╰╴ ─ 1. source
13502 ");
13503 }
13504
13505 #[test]
13506 fn goto_delete_from_alias_returning() {
13507 assert_snapshot!(goto("
13508create table t(a int, b int);
13509delete from t as f returning f$0.a"
13510 ), @r"
13511 ╭▸
13512 3 │ delete from t as f returning f.a
13513 │ ┬ ─ 1. source
13514 │ │
13515 ╰╴ 2. destination
13516 ");
13517
13518 assert_snapshot!(goto("
13519create table t(a int, b int);
13520delete from t as f returning f.a$0"
13521 ), @r"
13522 ╭▸
13523 2 │ create table t(a int, b int);
13524 │ ─ 2. destination
13525 3 │ delete from t as f returning f.a
13526 ╰╴ ─ 1. source
13527 ");
13528 }
13529
13530 #[test]
13531 fn goto_merge_alias_on_table() {
13532 assert_snapshot!(goto("
13533create table t(a int, b int);
13534create table u(a int, b int);
13535merge into t as f
13536 using u on u.a = f$0.a
13537 when matched then do nothing;
13538"
13539
13540 ), @r"
13541 ╭▸
13542 4 │ merge into t as f
13543 │ ─ 2. destination
13544 5 │ using u on u.a = f.a
13545 ╰╴ ─ 1. source
13546 ");
13547 }
13548
13549 #[test]
13550 fn goto_merge_alias_on_column() {
13551 assert_snapshot!(goto("
13552create table t(a int, b int);
13553create table u(a int, b int);
13554merge into t as f
13555 using u on u.a = f.a$0
13556 when matched then do nothing;
13557"
13558
13559 ), @r"
13560 ╭▸
13561 2 │ create table t(a int, b int);
13562 │ ─ 2. destination
13563 ‡
13564 5 │ using u on u.a = f.a
13565 ╰╴ ─ 1. source
13566 ");
13567 }
13568
13569 #[test]
13570 fn goto_merge_alias_returning() {
13571 assert_snapshot!(goto("
13572create table t(a int, b int);
13573create table u(a int, b int);
13574merge into t as f
13575 using u on u.a = f.a
13576 when matched then do nothing
13577 returning f$0.a;
13578"
13579
13580 ), @r"
13581 ╭▸
13582 4 │ merge into t as f
13583 │ ─ 2. destination
13584 ‡
13585 7 │ returning f.a;
13586 ╰╴ ─ 1. source
13587 ");
13588
13589 assert_snapshot!(goto("
13590create table t(a int, b int);
13591create table u(a int, b int);
13592merge into t as f
13593 using u on u.a = f.a
13594 when matched then do nothing
13595 returning f.a$0;
13596"
13597 ), @r"
13598 ╭▸
13599 2 │ create table t(a int, b int);
13600 │ ─ 2. destination
13601 ‡
13602 7 │ returning f.a;
13603 ╰╴ ─ 1. source
13604 ");
13605 }
13606
13607 #[test]
13608 fn goto_merge_using_table_in_when_clause() {
13609 assert_snapshot!(goto("
13610create table t(a int, b int);
13611create table u(a int, b int);
13612merge into t
13613 using u on true
13614 when matched and u$0.a = t.a
13615 then do nothing;
13616"
13617 ), @r"
13618 ╭▸
13619 3 │ create table u(a int, b int);
13620 │ ─ 2. destination
13621 ‡
13622 6 │ when matched and u.a = t.a
13623 ╰╴ ─ 1. source
13624 ");
13625 }
13626
13627 #[test]
13628 fn goto_merge_using_table_column_in_when_clause() {
13629 assert_snapshot!(goto("
13630create table t(a int, b int);
13631create table u(a int, b int);
13632merge into t
13633 using u on true
13634 when matched and u.a$0 = t.a
13635 then do nothing;
13636"
13637 ), @r"
13638 ╭▸
13639 3 │ create table u(a int, b int);
13640 │ ─ 2. destination
13641 ‡
13642 6 │ when matched and u.a = t.a
13643 ╰╴ ─ 1. source
13644 ");
13645 }
13646
13647 #[test]
13648 fn goto_merge_unqualified_column_target_table() {
13649 assert_snapshot!(goto("
13650create table x(a int, b int);
13651create table y(c int, d int);
13652merge into x
13653 using y
13654 on true
13655 when matched and a$0 = c
13656 then do nothing;
13657"
13658 ), @r"
13659 ╭▸
13660 2 │ create table x(a int, b int);
13661 │ ─ 2. destination
13662 ‡
13663 7 │ when matched and a = c
13664 ╰╴ ─ 1. source
13665 ");
13666 }
13667
13668 #[test]
13669 fn goto_merge_unqualified_column_source_table() {
13670 assert_snapshot!(goto("
13671create table x(a int, b int);
13672create table y(c int, d int);
13673merge into x
13674 using y
13675 on true
13676 when matched and a = c$0
13677 then do nothing;
13678"
13679 ), @r"
13680 ╭▸
13681 3 │ create table y(c int, d int);
13682 │ ─ 2. destination
13683 ‡
13684 7 │ when matched and a = c
13685 ╰╴ ─ 1. source
13686 ");
13687 }
13688
13689 #[test]
13690 fn goto_merge_update_set_target_column() {
13691 assert_snapshot!(goto("
13692create table target(id int, val int);
13693create table source(id int, val int);
13694merge into target using source on target.id = source.id
13695 when matched then update set val$0 = source.val;
13696"
13697 ), @"
13698 ╭▸
13699 2 │ create table target(id int, val int);
13700 │ ─── 2. destination
13701 ‡
13702 5 │ when matched then update set val = source.val;
13703 ╰╴ ─ 1. source
13704 ");
13705 }
13706
13707 #[test]
13708 fn goto_merge_update_set_source_expr_column() {
13709 assert_snapshot!(goto("
13710create table target(id int, val int);
13711create table source(id int, val int);
13712merge into target using source on target.id = source.id
13713 when matched then update set val = source.val$0;
13714"
13715 ), @"
13716 ╭▸
13717 3 │ create table source(id int, val int);
13718 │ ─── 2. destination
13719 4 │ merge into target using source on target.id = source.id
13720 5 │ when matched then update set val = source.val;
13721 ╰╴ ─ 1. source
13722 ");
13723 }
13724
13725 #[test]
13726 fn goto_merge_insert_column_list_target_column() {
13727 assert_snapshot!(goto("
13728create table target(id int, val int);
13729create table source(id int, val int);
13730merge into target using source on target.id = source.id
13731 when not matched then insert (val$0) values(source.val);
13732"
13733 ), @"
13734 ╭▸
13735 2 │ create table target(id int, val int);
13736 │ ─── 2. destination
13737 ‡
13738 5 │ when not matched then insert (val) values(source.val);
13739 ╰╴ ─ 1. source
13740 ");
13741 }
13742
13743 #[test]
13744 fn goto_merge_into_table() {
13745 assert_snapshot!(goto("
13746create table x(a int, b int);
13747create table y(c int, d int);
13748merge into x$0
13749 using y
13750 on true
13751 when matched and a = c
13752 then do nothing;
13753"
13754 ), @r"
13755 ╭▸
13756 2 │ create table x(a int, b int);
13757 │ ─ 2. destination
13758 3 │ create table y(c int, d int);
13759 4 │ merge into x
13760 ╰╴ ─ 1. source
13761 ");
13762 }
13763
13764 #[test]
13765 fn goto_merge_using_clause_table() {
13766 assert_snapshot!(goto("
13767create table x(a int, b int);
13768create table y(c int, d int);
13769merge into x
13770 using y$0
13771 on true
13772 when matched and a = c
13773 then do nothing;
13774"
13775 ), @r"
13776 ╭▸
13777 3 │ create table y(c int, d int);
13778 │ ─ 2. destination
13779 4 │ merge into x
13780 5 │ using y
13781 ╰╴ ─ 1. source
13782 ");
13783 }
13784
13785 #[test]
13786 fn goto_merge_using_clause_alias() {
13787 assert_snapshot!(goto("
13788create table x(a int, b int);
13789create table y(c int, d int);
13790merge into x as g
13791 using y as k
13792 on true
13793 when matched and a = k.c$0
13794 then do nothing;
13795"
13796 ), @r"
13797 ╭▸
13798 3 │ create table y(c int, d int);
13799 │ ─ 2. destination
13800 ‡
13801 7 │ when matched and a = k.c
13802 ╰╴ ─ 1. source
13803 ");
13804 }
13805
13806 #[test]
13807 fn goto_merge_on_clause_unqualified_source_column() {
13808 assert_snapshot!(goto("
13809create table x(a int, b int);
13810create table y(c int, d int);
13811merge into x as g
13812 using y as k
13813 on g.a = c$0 and a = c
13814 when matched and g.a = k.c
13815 then do nothing;
13816"
13817 ), @r"
13818 ╭▸
13819 3 │ create table y(c int, d int);
13820 │ ─ 2. destination
13821 ‡
13822 6 │ on g.a = c and a = c
13823 ╰╴ ─ 1. source
13824 ");
13825 }
13826
13827 #[test]
13828 fn goto_merge_returning_old_table() {
13829 assert_snapshot!(goto("
13830create table x(a int, b int);
13831create table y(c int, d int);
13832merge into x as g
13833 using y as k
13834 on g.a = c and a = k.c
13835 when matched and g.a = k.c
13836 then do nothing
13837 returning old$0.a, new.a;
13838"
13839 ), @r"
13840 ╭▸
13841 2 │ create table x(a int, b int);
13842 │ ─ 2. destination
13843 ‡
13844 9 │ returning old.a, new.a;
13845 ╰╴ ─ 1. source
13846 ");
13847 }
13848
13849 #[test]
13850 fn goto_merge_returning_old_column() {
13851 assert_snapshot!(goto("
13852create table x(a int, b int);
13853create table y(c int, d int);
13854merge into x as g
13855 using y as k
13856 on g.a = c and a = k.c
13857 when matched and g.a = k.c
13858 then do nothing
13859 returning old.a$0, new.a;
13860"
13861 ), @r"
13862 ╭▸
13863 2 │ create table x(a int, b int);
13864 │ ─ 2. destination
13865 ‡
13866 9 │ returning old.a, new.a;
13867 ╰╴ ─ 1. source
13868 ");
13869 }
13870
13871 #[test]
13872 fn goto_merge_returning_new_table() {
13873 assert_snapshot!(goto("
13874create table x(a int, b int);
13875create table y(c int, d int);
13876merge into x as g
13877 using y as k
13878 on g.a = c and a = k.c
13879 when matched and g.a = k.c
13880 then do nothing
13881 returning old.a, new$0.a;
13882"
13883 ), @r"
13884 ╭▸
13885 2 │ create table x(a int, b int);
13886 │ ─ 2. destination
13887 ‡
13888 9 │ returning old.a, new.a;
13889 ╰╴ ─ 1. source
13890 ");
13891 }
13892
13893 #[test]
13894 fn goto_merge_returning_new_column() {
13895 assert_snapshot!(goto("
13896create table x(a int, b int);
13897create table y(c int, d int);
13898merge into x as g
13899 using y as k
13900 on g.a = c and a = k.c
13901 when matched and g.a = k.c
13902 then do nothing
13903 returning old.a, new.a$0;
13904"
13905 ), @r"
13906 ╭▸
13907 2 │ create table x(a int, b int);
13908 │ ─ 2. destination
13909 ‡
13910 9 │ returning old.a, new.a;
13911 ╰╴ ─ 1. source
13912 ");
13913 }
13914
13915 #[test]
13916 fn goto_merge_with_tables_named_old_new_old_table() {
13917 assert_snapshot!(goto("
13918create table old(a int, b int);
13919create table new(c int, d int);
13920merge into old
13921 using new
13922 on true
13923 when matched
13924 then do nothing
13925 returning old$0.a, new.d;
13926"
13927 ), @r"
13928 ╭▸
13929 2 │ create table old(a int, b int);
13930 │ ─── 2. destination
13931 ‡
13932 9 │ returning old.a, new.d;
13933 ╰╴ ─ 1. source
13934 ");
13935 }
13936
13937 #[test]
13938 fn goto_merge_with_tables_named_old_new_old_column() {
13939 assert_snapshot!(goto("
13940create table old(a int, b int);
13941create table new(c int, d int);
13942merge into old
13943 using new
13944 on true
13945 when matched
13946 then do nothing
13947 returning old.a$0, new.d;
13948"
13949 ), @r"
13950 ╭▸
13951 2 │ create table old(a int, b int);
13952 │ ─ 2. destination
13953 ‡
13954 9 │ returning old.a, new.d;
13955 ╰╴ ─ 1. source
13956 ");
13957 }
13958
13959 #[test]
13960 fn goto_merge_with_tables_named_old_new_new_table() {
13961 assert_snapshot!(goto("
13962create table old(a int, b int);
13963create table new(c int, d int);
13964merge into old
13965 using new
13966 on true
13967 when matched
13968 then do nothing
13969 returning old.a, new$0.d;
13970"
13971 ), @r"
13972 ╭▸
13973 3 │ create table new(c int, d int);
13974 │ ─── 2. destination
13975 ‡
13976 9 │ returning old.a, new.d;
13977 ╰╴ ─ 1. source
13978 ");
13979 }
13980
13981 #[test]
13982 fn goto_merge_with_tables_named_old_new_new_column() {
13983 assert_snapshot!(goto("
13984create table old(a int, b int);
13985create table new(c int, d int);
13986merge into old
13987 using new
13988 on true
13989 when matched
13990 then do nothing
13991 returning old.a, new.d$0;
13992"
13993 ), @r"
13994 ╭▸
13995 3 │ create table new(c int, d int);
13996 │ ─ 2. destination
13997 ‡
13998 9 │ returning old.a, new.d;
13999 ╰╴ ─ 1. source
14000 ");
14001 }
14002
14003 #[test]
14004 fn goto_merge_returning_with_aliases_before_table() {
14005 assert_snapshot!(goto("
14006create table x(a int, b int);
14007create table y(c int, d int);
14008merge into x
14009 using y on true
14010 when matched then do nothing
14011 returning
14012 with (old as before, new as after)
14013 before$0.a, after.a;
14014"
14015 ), @r"
14016 ╭▸
14017 8 │ with (old as before, new as after)
14018 │ ────── 2. destination
14019 9 │ before.a, after.a;
14020 ╰╴ ─ 1. source
14021 ");
14022 }
14023
14024 #[test]
14025 fn goto_merge_returning_with_aliases_before_column() {
14026 assert_snapshot!(goto("
14027create table x(a int, b int);
14028create table y(c int, d int);
14029merge into x
14030 using y on true
14031 when matched then do nothing
14032 returning
14033 with (old as before, new as after)
14034 before.a$0, after.a;
14035"
14036 ), @r"
14037 ╭▸
14038 2 │ create table x(a int, b int);
14039 │ ─ 2. destination
14040 ‡
14041 9 │ before.a, after.a;
14042 ╰╴ ─ 1. source
14043 ");
14044 }
14045
14046 #[test]
14047 fn goto_merge_returning_with_aliases_after_table() {
14048 assert_snapshot!(goto("
14049create table x(a int, b int);
14050create table y(c int, d int);
14051merge into x
14052 using y on true
14053 when matched then do nothing
14054 returning
14055 with (old as before, new as after)
14056 before.a, after$0.a;
14057"
14058 ), @r"
14059 ╭▸
14060 8 │ with (old as before, new as after)
14061 │ ───── 2. destination
14062 9 │ before.a, after.a;
14063 ╰╴ ─ 1. source
14064 ");
14065 }
14066
14067 #[test]
14068 fn goto_merge_returning_with_aliases_after_column() {
14069 assert_snapshot!(goto("
14070create table x(a int, b int);
14071create table y(c int, d int);
14072merge into x
14073 using y on true
14074 when matched then do nothing
14075 returning
14076 with (old as before, new as after)
14077 before.a, after.a$0;
14078"
14079 ), @r"
14080 ╭▸
14081 2 │ create table x(a int, b int);
14082 │ ─ 2. destination
14083 ‡
14084 9 │ before.a, after.a;
14085 ╰╴ ─ 1. source
14086 ");
14087 }
14088
14089 #[test]
14090 fn goto_merge_when_not_matched_insert_values_qualified_column() {
14091 assert_snapshot!(goto("
14092create table inventory (
14093 product_id int,
14094 quantity int,
14095 updated_at timestamp
14096);
14097create table orders (
14098 id int,
14099 product_id int,
14100 qty int
14101);
14102merge into inventory as t
14103using orders as o
14104 on t.product_id = o.product_id
14105when matched then
14106 do nothing
14107when not matched then
14108 insert values (o$0.product_id, o.qty, now());
14109"
14110 ), @r"
14111 ╭▸
14112 13 │ using orders as o
14113 │ ─ 2. destination
14114 ‡
14115 18 │ insert values (o.product_id, o.qty, now());
14116 ╰╴ ─ 1. source
14117 ");
14118 }
14119
14120 #[test]
14121 fn goto_merge_when_not_matched_insert_values_qualified_column_field() {
14122 assert_snapshot!(goto("
14123create table inventory (
14124 product_id int,
14125 quantity int,
14126 updated_at timestamp
14127);
14128create table orders (
14129 id int,
14130 product_id int,
14131 qty int
14132);
14133merge into inventory as t
14134using orders as o
14135 on t.product_id = o.product_id
14136when matched then
14137 do nothing
14138when not matched then
14139 insert values (o.product_id$0, o.qty, now());
14140"
14141 ), @r"
14142 ╭▸
14143 9 │ product_id int,
14144 │ ────────── 2. destination
14145 ‡
14146 18 │ insert values (o.product_id, o.qty, now());
14147 ╰╴ ─ 1. source
14148 ");
14149 }
14150
14151 #[test]
14152 fn goto_merge_when_not_matched_insert_values_unqualified_column() {
14153 assert_snapshot!(goto("
14154create table inventory (
14155 product_id int,
14156 quantity int
14157);
14158create table orders (
14159 product_id int,
14160 qty int
14161);
14162merge into inventory as t
14163using orders as o
14164 on t.product_id = o.product_id
14165when not matched then
14166 insert values (product_id$0, qty);
14167"
14168 ), @r"
14169 ╭▸
14170 7 │ product_id int,
14171 │ ────────── 2. destination
14172 ‡
14173 14 │ insert values (product_id, qty);
14174 ╰╴ ─ 1. source
14175 ");
14176 }
14177
14178 #[test]
14179 fn goto_insert_returning_old_table() {
14180 assert_snapshot!(goto("
14181create table t(a int, b int);
14182insert into t values (1, 2), (3, 4)
14183returning old$0.a, new.b;
14184"
14185 ), @r"
14186 ╭▸
14187 2 │ create table t(a int, b int);
14188 │ ─ 2. destination
14189 3 │ insert into t values (1, 2), (3, 4)
14190 4 │ returning old.a, new.b;
14191 ╰╴ ─ 1. source
14192 ");
14193 }
14194
14195 #[test]
14196 fn goto_insert_returning_old_column() {
14197 assert_snapshot!(goto("
14198create table t(a int, b int);
14199insert into t values (1, 2), (3, 4)
14200returning old.a$0, new.b;
14201"
14202 ), @r"
14203 ╭▸
14204 2 │ create table t(a int, b int);
14205 │ ─ 2. destination
14206 3 │ insert into t values (1, 2), (3, 4)
14207 4 │ returning old.a, new.b;
14208 ╰╴ ─ 1. source
14209 ");
14210 }
14211
14212 #[test]
14213 fn goto_insert_returning_new_table() {
14214 assert_snapshot!(goto("
14215create table t(a int, b int);
14216insert into t values (1, 2), (3, 4)
14217returning old.a, new$0.b;
14218"
14219 ), @r"
14220 ╭▸
14221 2 │ create table t(a int, b int);
14222 │ ─ 2. destination
14223 3 │ insert into t values (1, 2), (3, 4)
14224 4 │ returning old.a, new.b;
14225 ╰╴ ─ 1. source
14226 ");
14227 }
14228
14229 #[test]
14230 fn goto_insert_returning_new_column() {
14231 assert_snapshot!(goto("
14232create table t(a int, b int);
14233insert into t values (1, 2), (3, 4)
14234returning old.a, new.b$0;
14235"
14236 ), @r"
14237 ╭▸
14238 2 │ create table t(a int, b int);
14239 │ ─ 2. destination
14240 3 │ insert into t values (1, 2), (3, 4)
14241 4 │ returning old.a, new.b;
14242 ╰╴ ─ 1. source
14243 ");
14244 }
14245
14246 #[test]
14247 fn goto_update_returning_old_table() {
14248 assert_snapshot!(goto("
14249create table t(a int, b int);
14250update t set a = 42
14251returning old$0.a, new.b;
14252"
14253 ), @r"
14254 ╭▸
14255 2 │ create table t(a int, b int);
14256 │ ─ 2. destination
14257 3 │ update t set a = 42
14258 4 │ returning old.a, new.b;
14259 ╰╴ ─ 1. source
14260 ");
14261 }
14262
14263 #[test]
14264 fn goto_update_returning_old_column() {
14265 assert_snapshot!(goto("
14266create table t(a int, b int);
14267update t set a = 42
14268returning old.a$0, new.b;
14269"
14270 ), @r"
14271 ╭▸
14272 2 │ create table t(a int, b int);
14273 │ ─ 2. destination
14274 3 │ update t set a = 42
14275 4 │ returning old.a, new.b;
14276 ╰╴ ─ 1. source
14277 ");
14278 }
14279
14280 #[test]
14281 fn goto_update_returning_new_table() {
14282 assert_snapshot!(goto("
14283create table t(a int, b int);
14284update t set a = 42
14285returning old.a, new$0.b;
14286"
14287 ), @r"
14288 ╭▸
14289 2 │ create table t(a int, b int);
14290 │ ─ 2. destination
14291 3 │ update t set a = 42
14292 4 │ returning old.a, new.b;
14293 ╰╴ ─ 1. source
14294 ");
14295 }
14296
14297 #[test]
14298 fn goto_update_returning_new_column() {
14299 assert_snapshot!(goto("
14300create table t(a int, b int);
14301update t set a = 42
14302returning old.a, new.b$0;
14303"
14304 ), @r"
14305 ╭▸
14306 2 │ create table t(a int, b int);
14307 │ ─ 2. destination
14308 3 │ update t set a = 42
14309 4 │ returning old.a, new.b;
14310 ╰╴ ─ 1. source
14311 ");
14312 }
14313
14314 #[test]
14315 fn goto_delete_returning_old_table() {
14316 assert_snapshot!(goto("
14317create table t(a int, b int);
14318delete from t
14319returning old$0.a, new.b;
14320"
14321 ), @r"
14322 ╭▸
14323 2 │ create table t(a int, b int);
14324 │ ─ 2. destination
14325 3 │ delete from t
14326 4 │ returning old.a, new.b;
14327 ╰╴ ─ 1. source
14328 ");
14329 }
14330
14331 #[test]
14332 fn goto_delete_returning_old_column() {
14333 assert_snapshot!(goto("
14334create table t(a int, b int);
14335delete from t
14336returning old.a$0, new.b;
14337"
14338 ), @r"
14339 ╭▸
14340 2 │ create table t(a int, b int);
14341 │ ─ 2. destination
14342 3 │ delete from t
14343 4 │ returning old.a, new.b;
14344 ╰╴ ─ 1. source
14345 ");
14346 }
14347
14348 #[test]
14349 fn goto_delete_returning_new_table() {
14350 assert_snapshot!(goto("
14351create table t(a int, b int);
14352delete from t
14353returning old.a, new$0.b;
14354"
14355 ), @r"
14356 ╭▸
14357 2 │ create table t(a int, b int);
14358 │ ─ 2. destination
14359 3 │ delete from t
14360 4 │ returning old.a, new.b;
14361 ╰╴ ─ 1. source
14362 ");
14363 }
14364
14365 #[test]
14366 fn goto_delete_returning_new_column() {
14367 assert_snapshot!(goto("
14368create table t(a int, b int);
14369delete from t
14370returning old.a, new.b$0;
14371"
14372 ), @r"
14373 ╭▸
14374 2 │ create table t(a int, b int);
14375 │ ─ 2. destination
14376 3 │ delete from t
14377 4 │ returning old.a, new.b;
14378 ╰╴ ─ 1. source
14379 ");
14380 }
14381
14382 #[test]
14383 fn goto_insert_as_old_alias() {
14384 assert_snapshot!(goto("
14385create table t(a int, b int);
14386insert into t as old values (1, 2)
14387returning old$0.a, new.a;
14388"
14389 ), @r"
14390 ╭▸
14391 3 │ insert into t as old values (1, 2)
14392 │ ─── 2. destination
14393 4 │ returning old.a, new.a;
14394 ╰╴ ─ 1. source
14395 ");
14396 }
14397
14398 #[test]
14399 fn goto_delete_as_old_alias() {
14400 assert_snapshot!(goto("
14401create table t(a int, b int);
14402delete from t as old
14403returning old$0.a, new.a;
14404"
14405 ), @r"
14406 ╭▸
14407 3 │ delete from t as old
14408 │ ─── 2. destination
14409 4 │ returning old.a, new.a;
14410 ╰╴ ─ 1. source
14411 ");
14412 }
14413
14414 #[test]
14415 fn goto_update_as_old_alias() {
14416 assert_snapshot!(goto("
14417create table t(a int, b int);
14418update t as old set a = 42
14419returning old$0.a, new.a;
14420"
14421 ), @r"
14422 ╭▸
14423 3 │ update t as old set a = 42
14424 │ ─── 2. destination
14425 4 │ returning old.a, new.a;
14426 ╰╴ ─ 1. source
14427 ");
14428 }
14429
14430 #[test]
14431 fn goto_merge_returning_cte_column_unqualified() {
14432 assert_snapshot!(goto("
14433create table t(a int, b int);
14434with u(x, y) as (
14435 select 1, 2
14436)
14437merge into t
14438 using u on true
14439when matched then
14440 do nothing
14441when not matched then
14442 do nothing
14443returning x$0, u.y;
14444"
14445 ), @r"
14446 ╭▸
14447 3 │ with u(x, y) as (
14448 │ ─ 2. destination
14449 ‡
14450 12 │ returning x, u.y;
14451 ╰╴ ─ 1. source
14452 ");
14453 }
14454
14455 #[test]
14456 fn goto_merge_returning_cte_column_qualified_table() {
14457 assert_snapshot!(goto("
14458create table t(a int, b int);
14459with u(x, y) as (
14460 select 1, 2
14461)
14462merge into t
14463 using u on true
14464when matched then
14465 do nothing
14466when not matched then
14467 do nothing
14468returning x, u$0.y;
14469"
14470 ), @r"
14471 ╭▸
14472 3 │ with u(x, y) as (
14473 │ ─ 2. destination
14474 ‡
14475 12 │ returning x, u.y;
14476 ╰╴ ─ 1. source
14477 ");
14478 }
14479
14480 #[test]
14481 fn goto_merge_returning_cte_column_qualified_column() {
14482 assert_snapshot!(goto("
14483create table t(a int, b int);
14484with u(x, y) as (
14485 select 1, 2
14486)
14487merge into t
14488 using u on true
14489when matched then
14490 do nothing
14491when not matched then
14492 do nothing
14493returning x, u.y$0;
14494"
14495 ), @r"
14496 ╭▸
14497 3 │ with u(x, y) as (
14498 │ ─ 2. destination
14499 ‡
14500 12 │ returning x, u.y;
14501 ╰╴ ─ 1. source
14502 ");
14503 }
14504
14505 #[test]
14506 fn goto_overlay_with_cte_column() {
14507 assert_snapshot!(goto("
14508with t as (
14509 select '1' a, '2' b, 3 start
14510)
14511select overlay(a placing b$0 from start) from t;
14512 "), @r"
14513 ╭▸
14514 3 │ select '1' a, '2' b, 3 start
14515 │ ─ 2. destination
14516 4 │ )
14517 5 │ select overlay(a placing b from start) from t;
14518 ╰╴ ─ 1. source
14519 ");
14520 }
14521
14522 #[test]
14523 fn goto_overlay_with_cte_column_first_arg() {
14524 assert_snapshot!(goto("
14525with t as (
14526 select '1' a, '2' b, 3 start
14527)
14528select overlay(a$0 placing b from start) from t;
14529 "), @r"
14530 ╭▸
14531 3 │ select '1' a, '2' b, 3 start
14532 │ ─ 2. destination
14533 4 │ )
14534 5 │ select overlay(a placing b from start) from t;
14535 ╰╴ ─ 1. source
14536 ");
14537 }
14538
14539 #[test]
14540 fn goto_overlay_with_cte_column_from_arg() {
14541 assert_snapshot!(goto("
14542with t as (
14543 select '1' a, '2' b, 3 start
14544)
14545select overlay(a placing b from start$0) from t;
14546 "), @r"
14547 ╭▸
14548 3 │ select '1' a, '2' b, 3 start
14549 │ ───── 2. destination
14550 4 │ )
14551 5 │ select overlay(a placing b from start) from t;
14552 ╰╴ ─ 1. source
14553 ");
14554 }
14555
14556 #[test]
14557 fn goto_named_arg_to_param() {
14558 assert_snapshot!(goto("
14559create function foo(bar_param int) returns int as 'select 1' language sql;
14560select foo(bar_param$0 := 5);
14561"), @r"
14562 ╭▸
14563 2 │ create function foo(bar_param int) returns int as 'select 1' language sql;
14564 │ ───────── 2. destination
14565 3 │ select foo(bar_param := 5);
14566 ╰╴ ─ 1. source
14567 ");
14568 }
14569
14570 #[test]
14571 fn goto_named_arg_schema_qualified() {
14572 assert_snapshot!(goto("
14573create schema s;
14574create function s.foo(my_param int) returns int as 'select 1' language sql;
14575select s.foo(my_param$0 := 10);
14576"), @r"
14577 ╭▸
14578 3 │ create function s.foo(my_param int) returns int as 'select 1' language sql;
14579 │ ──────── 2. destination
14580 4 │ select s.foo(my_param := 10);
14581 ╰╴ ─ 1. source
14582 ");
14583 }
14584
14585 #[test]
14586 fn goto_named_arg_multiple_params() {
14587 assert_snapshot!(goto("
14588create function foo(a int, b int, c int) returns int as 'select 1' language sql;
14589select foo(b$0 := 2, a := 1);
14590"), @r"
14591 ╭▸
14592 2 │ create function foo(a int, b int, c int) returns int as 'select 1' language sql;
14593 │ ─ 2. destination
14594 3 │ select foo(b := 2, a := 1);
14595 ╰╴ ─ 1. source
14596 ");
14597 }
14598
14599 #[test]
14600 fn goto_named_arg_procedure() {
14601 assert_snapshot!(goto("
14602create procedure proc(param_x int) as 'select 1' language sql;
14603call proc(param_x$0 := 42);
14604"), @r"
14605 ╭▸
14606 2 │ create procedure proc(param_x int) as 'select 1' language sql;
14607 │ ─────── 2. destination
14608 3 │ call proc(param_x := 42);
14609 ╰╴ ─ 1. source
14610 ");
14611 }
14612
14613 #[test]
14614 fn goto_named_arg_not_found_unnamed_param() {
14615 goto_not_found(
14616 "
14617create function foo(int) returns int as 'select 1' language sql;
14618select foo(bar$0 := 5);
14619",
14620 );
14621 }
14622
14623 #[test]
14624 fn goto_named_arg_not_found_wrong_name() {
14625 goto_not_found(
14626 "
14627create function foo(correct_param int) returns int as 'select 1' language sql;
14628select foo(wrong_param$0 := 5);
14629",
14630 );
14631 }
14632
14633 #[test]
14634 fn goto_operator_function_ref() {
14635 assert_snapshot!(goto("
14636create function pg_catalog.tsvector_concat(tsvector, tsvector) returns tsvector language internal;
14637create operator pg_catalog.|| (leftarg = tsvector, rightarg = tsvector, function = pg_catalog.tsvector_concat$0);
14638"), @r"
14639 ╭▸
14640 2 │ create function pg_catalog.tsvector_concat(tsvector, tsvector) returns tsvector language internal;
14641 │ ─────────────── 2. destination
14642 3 │ create operator pg_catalog.|| (leftarg = tsvector, rightarg = tsvector, function = pg_catalog.tsvector_concat);
14643 ╰╴ ─ 1. source
14644 ");
14645 }
14646
14647 #[test]
14648 fn goto_operator_procedure_ref() {
14649 assert_snapshot!(goto("
14650create function f(int, int) returns int language internal;
14651create operator ||| (leftarg = int, rightarg = int, procedure = f$0);
14652"), @r"
14653 ╭▸
14654 2 │ create function f(int, int) returns int language internal;
14655 │ ─ 2. destination
14656 3 │ create operator ||| (leftarg = int, rightarg = int, procedure = f);
14657 ╰╴ ─ 1. source
14658 ");
14659 }
14660
14661 #[test]
14662 fn goto_operator_expr_usage() {
14663 assert_snapshot!(goto("
14664create operator === (leftarg = int, rightarg = int, function = int4eq);
14665select 1 ===$0 2;
14666"), @"
14667 ╭▸
14668 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14669 │ ─── 2. destination
14670 3 │ select 1 === 2;
14671 ╰╴ ─ 1. source
14672 ");
14673 }
14674
14675 #[test]
14676 fn goto_operator_explicit_operator_call() {
14677 assert_snapshot!(goto("
14678create operator === (leftarg = int, rightarg = int, function = int4eq);
14679select 1 operator(===$0) 2;
14680"), @"
14681 ╭▸
14682 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14683 │ ─── 2. destination
14684 3 │ select 1 operator(===) 2;
14685 ╰╴ ─ 1. source
14686 ");
14687 }
14688
14689 #[test]
14690 fn goto_drop_operator() {
14691 assert_snapshot!(goto("
14692create operator === (leftarg = int, rightarg = int, function = int4eq);
14693drop operator ===$0 (int, int);
14694"), @"
14695 ╭▸
14696 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14697 │ ─── 2. destination
14698 3 │ drop operator === (int, int);
14699 ╰╴ ─ 1. source
14700 ");
14701 }
14702
14703 #[test]
14704 fn goto_alter_operator_set_schema() {
14705 assert_snapshot!(goto("
14706create operator === (leftarg = int, rightarg = int, function = int4eq);
14707alter operator ===$0 (int, int) set schema public;
14708"), @"
14709 ╭▸
14710 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14711 │ ─── 2. destination
14712 3 │ alter operator === (int, int) set schema public;
14713 ╰╴ ─ 1. source
14714 ");
14715 }
14716
14717 #[test]
14718 fn goto_comment_on_operator() {
14719 assert_snapshot!(goto("
14720create operator === (leftarg = int, rightarg = int, function = int4eq);
14721comment on operator ===$0 (int, int) is 'x';
14722"), @"
14723 ╭▸
14724 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14725 │ ─── 2. destination
14726 3 │ comment on operator === (int, int) is 'x';
14727 ╰╴ ─ 1. source
14728 ");
14729 }
14730
14731 #[test]
14732 fn goto_operator_class_operator_member() {
14733 assert_snapshot!(goto("
14734create operator === (leftarg = int, rightarg = int, function = int4eq);
14735create operator class c for type int using btree as operator 1 ===$0;
14736"), @"
14737 ╭▸
14738 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14739 │ ─── 2. destination
14740 3 │ create operator class c for type int using btree as operator 1 ===;
14741 ╰╴ ─ 1. source
14742 ");
14743 }
14744
14745 #[test]
14746 fn goto_operator_family_operator_member() {
14747 assert_snapshot!(goto("
14748create operator === (leftarg = int, rightarg = int, function = int4eq);
14749create operator family fam using btree;
14750alter operator family fam using btree add operator 1 ===$0 (int, int);
14751"), @"
14752 ╭▸
14753 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14754 │ ─── 2. destination
14755 3 │ create operator family fam using btree;
14756 4 │ alter operator family fam using btree add operator 1 === (int, int);
14757 ╰╴ ─ 1. source
14758 ");
14759 }
14760
14761 #[test]
14762 fn goto_operator_exclude_constraint() {
14763 assert_snapshot!(goto("
14764create operator === (leftarg = int, rightarg = int, function = int4eq);
14765create table t (a int, exclude (a with ===$0));
14766"), @"
14767 ╭▸
14768 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14769 │ ─── 2. destination
14770 3 │ create table t (a int, exclude (a with ===));
14771 ╰╴ ─ 1. source
14772 ");
14773 }
14774
14775 #[test]
14776 fn goto_operator_commutator_option() {
14777 assert_snapshot!(goto("
14778create operator === (leftarg = int, rightarg = int, function = int4eq);
14779create operator ==== (leftarg = int, rightarg = int, function = int4eq, commutator = ===$0);
14780"), @"
14781 ╭▸
14782 2 │ create operator === (leftarg = int, rightarg = int, function = int4eq);
14783 │ ─── 2. destination
14784 3 │ create operator ==== (leftarg = int, rightarg = int, function = int4eq, commutator = ===);
14785 ╰╴ ─ 1. source
14786 ");
14787 }
14788
14789 #[test]
14790 fn goto_operator_schema_qualified() {
14791 assert_snapshot!(goto("
14792create operator public.=== (leftarg = int, rightarg = int, function = int4eq);
14793drop operator public.===$0 (int, int);
14794"), @"
14795 ╭▸
14796 2 │ create operator public.=== (leftarg = int, rightarg = int, function = int4eq);
14797 │ ────────── 2. destination
14798 3 │ drop operator public.=== (int, int);
14799 ╰╴ ─ 1. source
14800 ");
14801 }
14802
14803 #[test]
14804 fn goto_create_cast_function_ref() {
14805 assert_snapshot!(goto("
14806create type a as enum ('x');
14807create type b as enum ('x');
14808create function a_to_b(a) returns b language sql as $$ select 'x'::b $$;
14809create cast (a as b) with function a_to_b$0(a);
14810"), @"
14811 ╭▸
14812 4 │ create function a_to_b(a) returns b language sql as $$ select 'x'::b $$;
14813 │ ────── 2. destination
14814 5 │ create cast (a as b) with function a_to_b(a);
14815 ╰╴ ─ 1. source
14816 ");
14817 }
14818
14819 #[test]
14820 fn goto_create_type_range_subtype_diff_function_ref() {
14821 assert_snapshot!(goto("
14822create function int_diff(int, int) returns float8 language sql as $$ select 0::float8 $$;
14823create type int_range as range (subtype = int, subtype_diff = int_diff$0);
14824"), @"
14825 ╭▸
14826 2 │ create function int_diff(int, int) returns float8 language sql as $$ select 0::float8 $$;
14827 │ ──────── 2. destination
14828 3 │ create type int_range as range (subtype = int, subtype_diff = int_diff);
14829 ╰╴ ─ 1. source
14830 ");
14831 }
14832
14833 #[test]
14834 fn goto_cte_window_partition_column_from_create_table_if_not_exists() {
14835 assert_snapshot!(goto("
14836create table t (
14837 id bigint primary key,
14838 group_col text not null,
14839 update_date date not null
14840);
14841
14842with row_number_added as (
14843 select
14844 *,
14845 row_number() over (
14846 partition by group_col$0
14847 order by update_date desc
14848 ) as rn
14849 from t
14850)
14851select * from row_number_added
14852"), @"
14853 ╭▸
14854 4 │ group_col text not null,
14855 │ ───────── 2. destination
14856 ‡
14857 12 │ partition by group_col
14858 ╰╴ ─ 1. source
14859 ");
14860 }
14861
14862 #[test]
14863 fn goto_cte_window_order_column_from_create_table_if_not_exists() {
14864 assert_snapshot!(goto("
14865create table t (
14866 id bigint primary key,
14867 group_col text not null,
14868 update_date date not null
14869);
14870
14871with row_number_added as (
14872 select
14873 *,
14874 row_number() over (
14875 partition by group_col
14876 order by update_date$0 desc
14877 ) as rn
14878 from t
14879)
14880select * from row_number_added
14881"), @"
14882 ╭▸
14883 5 │ update_date date not null
14884 │ ─────────── 2. destination
14885 ‡
14886 13 │ order by update_date desc
14887 ╰╴ ─ 1. source
14888 ");
14889 }
14890
14891 #[test]
14892 fn goto_cte_window_partition_function_call_from_create_table() {
14893 assert_snapshot!(goto("
14894create function length(text) returns int language internal;
14895
14896create table t (
14897 id bigint primary key,
14898 group_col text not null,
14899 update_date date not null
14900);
14901
14902with row_number_added as (
14903 select
14904 *,
14905 row_number() over (
14906 partition by length$0(group_col)
14907 order by update_date$0 desc
14908 ) as rn
14909 from t
14910)
14911select * from row_number_added
14912"), @"
14913 ╭▸
14914 2 │ create function length(text) returns int language internal;
14915 │ ────── 2. destination
14916 ‡
14917 14 │ partition by length(group_col)
14918 ╰╴ ─ 1. source
14919 ");
14920 }
14921
14922 #[test]
14923 fn goto_select_window_def_reuse() {
14924 assert_snapshot!(goto("
14925create table tbl (
14926 id bigint primary key,
14927 group_col text not null,
14928 update_date date not null,
14929 value text
14930);
14931select
14932 id,
14933 group_col,
14934 row_number() over w as rn,
14935 lag(value) over w$0 as prev_value
14936from tbl
14937window w as (
14938 partition by group_col
14939 order by update_date desc
14940);
14941"), @r"
14942 ╭▸
14943 12 │ lag(value) over w as prev_value
14944 │ ─ 1. source
14945 13 │ from tbl
14946 14 │ window w as (
14947 ╰╴ ─ 2. destination
14948 ");
14949 }
14950
14951 #[test]
14952 fn goto_window_base_name_in_inline_over() {
14953 assert_snapshot!(goto("
14954create table t(a int);
14955select row_number() over (w1$0 order by a)
14956from t
14957window w1 as (partition by a);
14958"), @"
14959 ╭▸
14960 3 │ select row_number() over (w1 order by a)
14961 │ ─ 1. source
14962 4 │ from t
14963 5 │ window w1 as (partition by a);
14964 ╰╴ ── 2. destination
14965 ");
14966 }
14967
14968 #[test]
14969 fn goto_window_base_name_in_window_def() {
14970 assert_snapshot!(goto("
14971create table t(a int);
14972select row_number() over w2
14973from t
14974window w1 as (partition by a), w2 as (w1$0 order by a);
14975"), @"
14976 ╭▸
14977 5 │ window w1 as (partition by a), w2 as (w1 order by a);
14978 ╰╴ ── 2. destination ─ 1. source
14979 ");
14980 }
14981
14982 #[test]
14983 fn goto_cast_float_with_small_arg() {
14984 assert_snapshot!(goto("
14985create type pg_catalog.float4;
14986select '1'::float$0(8);
14987"), @"
14988 ╭▸
14989 2 │ create type pg_catalog.float4;
14990 │ ────── 2. destination
14991 3 │ select '1'::float(8);
14992 ╰╴ ─ 1. source
14993 ");
14994 }
14995
14996 #[test]
14997 fn goto_cast_float_with_large_arg() {
14998 assert_snapshot!(goto("
14999create type pg_catalog.float8;
15000select '1'::float$0(25);
15001"), @"
15002 ╭▸
15003 2 │ create type pg_catalog.float8;
15004 │ ────── 2. destination
15005 3 │ select '1'::float(25);
15006 ╰╴ ─ 1. source
15007 ");
15008 }
15009
15010 #[test]
15011 fn goto_cast_dec_with_modifier() {
15012 assert_snapshot!(goto("
15013create type pg_catalog.numeric;
15014select '10'::dec$0(10, 2);
15015"), @"
15016 ╭▸
15017 2 │ create type pg_catalog.numeric;
15018 │ ─────── 2. destination
15019 3 │ select '10'::dec(10, 2);
15020 ╰╴ ─ 1. source
15021 ");
15022 }
15023
15024 #[test]
15025 fn goto_cast_dec() {
15026 assert_snapshot!(goto("
15027create type pg_catalog.numeric;
15028select '10'::dec$0;
15029"), @"
15030 ╭▸
15031 2 │ create type pg_catalog.numeric;
15032 │ ─────── 2. destination
15033 3 │ select '10'::dec;
15034 ╰╴ ─ 1. source
15035 ");
15036 }
15037
15038 #[test]
15039 fn goto_create_property_graph() {
15040 assert_snapshot!(goto("
15041create table buzz.boo(a int, b int);
15042create property graph foo.bar
15043 vertex tables (buzz.boo$0 key (a, b) no properties)
15044 edge tables (foo.bar key (x, y)
15045 source key (a, b) references k (t, y)
15046 destination key (q, t) references a (r, j)
15047 properties all columns);
15048"), @"
15049 ╭▸
15050 2 │ create table buzz.boo(a int, b int);
15051 │ ─── 2. destination
15052 3 │ create property graph foo.bar
15053 4 │ vertex tables (buzz.boo key (a, b) no properties)
15054 ╰╴ ─ 1. source
15055 ");
15056
15057 assert_snapshot!(goto("
15058create table foo.bar(x int, y int);
15059create property graph g
15060 vertex tables (boo key (a, b) no properties)
15061 edge tables (foo.bar$0 key (x, y)
15062 source key (a, b) references k (t, y)
15063 destination key (q, t) references a (r, j)
15064 properties all columns);
15065"), @"
15066 ╭▸
15067 2 │ create table foo.bar(x int, y int);
15068 │ ─── 2. destination
15069 ‡
15070 5 │ edge tables (foo.bar key (x, y)
15071 ╰╴ ─ 1. source
15072 ");
15073 }
15074
15075 #[test]
15076 fn goto_create_property_graph_sources_table() {
15077 assert_snapshot!(goto("
15078create table v1 (
15079 id int8 primary key,
15080 name text
15081);
15082
15083create table v2 (
15084 id int8 primary key,
15085 name text
15086);
15087
15088create table v3 (
15089 id int8 primary key,
15090 name text
15091);
15092
15093create table e1 (
15094 id int8 primary key,
15095 source_id int8 references v1,
15096 destination_id int8 references v2
15097);
15098
15099create table e2 (
15100 id int8 primary key,
15101 source_id int8 references v1,
15102 destination_id int8 references v3
15103);
15104
15105create property graph g1
15106 vertex tables (v1 as source_vertex, v2 as destination_vertex, v3)
15107 edge tables (
15108 e1 source source_vertex$0 destination destination_vertex,
15109 e2 source source_vertex destination v3);
15110"), @"
15111 ╭▸
15112 30 │ vertex tables (v1 as source_vertex, v2 as destination_vertex, v3)
15113 │ ───────────── 2. destination
15114 31 │ edge tables (
15115 32 │ e1 source source_vertex destination destination_vertex,
15116 ╰╴ ─ 1. source
15117 "
15118 );
15119
15120 assert_snapshot!(goto("
15121create table v1 (
15122 id int8 primary key,
15123 name text
15124);
15125
15126create table v2 (
15127 id int8 primary key,
15128 name text
15129);
15130
15131create table v3 (
15132 id int8 primary key,
15133 name text
15134);
15135
15136create table e1 (
15137 id int8 primary key,
15138 source_id int8 references v1,
15139 destination_id int8 references v2
15140);
15141
15142create table e2 (
15143 id int8 primary key,
15144 source_id int8 references v1,
15145 destination_id int8 references v3
15146);
15147
15148create property graph g1
15149 vertex tables (v1, v2, v3)
15150 edge tables (
15151 e1 source v1 destination v2,
15152 e2 source v1 destination v3$0);
15153"), @"
15154 ╭▸
15155 12 │ create table v3 (
15156 │ ── 2. destination
15157 ‡
15158 33 │ e2 source v1 destination v3);
15159 ╰╴ ─ 1. source
15160 "
15161 );
15162 }
15163
15164 #[test]
15165 fn goto_create_property_graph_references_table() {
15166 assert_snapshot!(goto("
15167create table v1 (id int8 primary key);
15168create table v2 (id int8 primary key);
15169create table e1 (
15170 id int8 primary key,
15171 source_id int8 references v1,
15172 destination_id int8 references v2
15173);
15174
15175create property graph g1
15176 vertex tables (v1 as source_vertex, v2)
15177 edge tables (
15178 e1
15179 source key (source_id) references source_vertex$0 (id)
15180 destination key (destination_id) references v2 (id)
15181 );
15182"), @"
15183 ╭▸
15184 11 │ vertex tables (v1 as source_vertex, v2)
15185 │ ───────────── 2. destination
15186 ‡
15187 14 │ source key (source_id) references source_vertex (id)
15188 ╰╴ ─ 1. source
15189 "
15190 );
15191 }
15192
15193 #[test]
15194 fn goto_create_property_graph_vertex_key_column() {
15195 assert_snapshot!(goto("
15196create table v1 (
15197 id int8 primary key,
15198 name text
15199);
15200
15201create property graph g1
15202 vertex tables (v1 key (id$0));
15203"), @"
15204 ╭▸
15205 3 │ id int8 primary key,
15206 │ ── 2. destination
15207 ‡
15208 8 │ vertex tables (v1 key (id));
15209 ╰╴ ─ 1. source
15210 ");
15211 }
15212
15213 #[test]
15214 fn goto_create_property_graph_edge_source_key_column() {
15215 assert_snapshot!(goto("
15216create table v1 (id int8 primary key);
15217create table v2 (id int8 primary key);
15218create table e1 (
15219 id int8 primary key,
15220 source_id int8 references v1,
15221 destination_id int8 references v2
15222);
15223
15224create property graph g1
15225 vertex tables (v1, v2)
15226 edge tables (
15227 e1 key (id)
15228 source key (source_id$0) references v1 (id)
15229 destination key (destination_id) references v2 (id));
15230"), @"
15231 ╭▸
15232 6 │ source_id int8 references v1,
15233 │ ───────── 2. destination
15234 ‡
15235 14 │ source key (source_id) references v1 (id)
15236 ╰╴ ─ 1. source
15237 ");
15238 }
15239
15240 #[test]
15241 fn goto_create_property_graph_edge_source_references_column() {
15242 assert_snapshot!(goto("
15243create table v1 (id int8 primary key);
15244create table v2 (id int8 primary key);
15245create table e1 (
15246 id int8 primary key,
15247 source_id int8 references v1,
15248 destination_id int8 references v2
15249);
15250
15251create property graph g1
15252 vertex tables (v1 as source_vertex, v2)
15253 edge tables (
15254 e1 key (id)
15255 source key (source_id) references source_vertex (id$0)
15256 destination key (destination_id) references v2 (id));
15257"), @"
15258 ╭▸
15259 2 │ create table v1 (id int8 primary key);
15260 │ ── 2. destination
15261 ‡
15262 14 │ source key (source_id) references source_vertex (id)
15263 ╰╴ ─ 1. source
15264 ");
15265 }
15266
15267 #[test]
15268 fn goto_create_property_graph_edge_destination_key_column() {
15269 assert_snapshot!(goto("
15270create table v1 (id int8 primary key);
15271create table v2 (id int8 primary key);
15272create table e1 (
15273 id int8 primary key,
15274 source_id int8 references v1,
15275 destination_id int8 references v2
15276);
15277
15278create property graph g1
15279 vertex tables (v1, v2)
15280 edge tables (
15281 e1 key (id)
15282 source key (source_id) references v1 (id)
15283 destination key (destination_id$0) references v2 (id));
15284"), @"
15285 ╭▸
15286 7 │ destination_id int8 references v2
15287 │ ────────────── 2. destination
15288 ‡
15289 15 │ destination key (destination_id) references v2 (id));
15290 ╰╴ ─ 1. source
15291 ");
15292 }
15293
15294 #[test]
15295 fn goto_create_property_graph_edge_destination_references_column() {
15296 assert_snapshot!(goto("
15297create table v1 (id int8 primary key);
15298create table v2 (id int8 primary key);
15299create table e1 (
15300 id int8 primary key,
15301 source_id int8 references v1,
15302 destination_id int8 references v2
15303);
15304
15305create property graph g1
15306 vertex tables (v1, v2)
15307 edge tables (
15308 e1 key (id)
15309 source key (source_id) references v1 (id)
15310 destination key (destination_id) references v2 (id$0));
15311"), @"
15312 ╭▸
15313 3 │ create table v2 (id int8 primary key);
15314 │ ── 2. destination
15315 ‡
15316 15 │ destination key (destination_id) references v2 (id));
15317 ╰╴ ─ 1. source
15318 ");
15319 }
15320
15321 #[test]
15322 fn goto_create_property_graph_vertex_properties_column() {
15323 assert_snapshot!(goto("
15324create table v1 (
15325 id int8 primary key,
15326 name text
15327);
15328
15329create property graph g1
15330 vertex tables (v1 properties (id$0, name));
15331"), @"
15332 ╭▸
15333 3 │ id int8 primary key,
15334 │ ── 2. destination
15335 ‡
15336 8 │ vertex tables (v1 properties (id, name));
15337 ╰╴ ─ 1. source
15338 ");
15339
15340 assert_snapshot!(goto("
15341create table v1 (
15342 id int8 primary key,
15343 name text
15344);
15345
15346create property graph g1
15347 vertex tables (v1 properties (id, nam$0e));
15348"), @"
15349 ╭▸
15350 4 │ name text
15351 │ ──── 2. destination
15352 ‡
15353 8 │ vertex tables (v1 properties (id, name));
15354 ╰╴ ─ 1. source
15355 ");
15356 }
15357
15358 #[test]
15359 fn goto_create_property_graph_edge_properties_column() {
15360 assert_snapshot!(goto("
15361create table v1 (id int8 primary key);
15362create table v2 (id int8 primary key);
15363create table e1 (
15364 id int8 primary key,
15365 source_id int8 references v1,
15366 destination_id int8 references v2
15367);
15368
15369create property graph g1
15370 vertex tables (v1, v2)
15371 edge tables (
15372 e1
15373 source v1
15374 destination v2
15375 properties (id, source_id$0, destination_id));
15376"), @"
15377 ╭▸
15378 6 │ source_id int8 references v1,
15379 │ ───────── 2. destination
15380 ‡
15381 16 │ properties (id, source_id, destination_id));
15382 ╰╴ ─ 1. source
15383 ");
15384 }
15385
15386 #[test]
15387 fn goto_drop_property_graph() {
15388 assert_snapshot!(goto("
15389create property graph foo.bar vertex tables (t key (a) no properties);
15390drop property graph foo.ba$0r;
15391"), @"
15392 ╭▸
15393 2 │ create property graph foo.bar vertex tables (t key (a) no properties);
15394 │ ─── 2. destination
15395 3 │ drop property graph foo.bar;
15396 ╰╴ ─ 1. source
15397 ");
15398 }
15399
15400 #[test]
15401 fn goto_alter_property_graph() {
15402 assert_snapshot!(goto("
15403create property graph foo.bar vertex tables (t key (a) no properties);
15404alter property graph foo.ba$0r rename to baz;
15405"), @"
15406 ╭▸
15407 2 │ create property graph foo.bar vertex tables (t key (a) no properties);
15408 │ ─── 2. destination
15409 3 │ alter property graph foo.bar rename to baz;
15410 ╰╴ ─ 1. source
15411 ");
15412 }
15413
15414 #[test]
15415 fn goto_graph_table_fn() {
15416 assert_snapshot!(goto("
15417create property graph myshop vertex tables (t key (a) no properties);
15418select 1 from graph_table (myshop$0
15419 match (n is t)
15420 columns (1 as x));
15421"), @"
15422 ╭▸
15423 2 │ create property graph myshop vertex tables (t key (a) no properties);
15424 │ ────── 2. destination
15425 3 │ select 1 from graph_table (myshop
15426 ╰╴ ─ 1. source
15427 ");
15428 }
15429
15430 #[test]
15431 fn goto_create_function_param_percent_type_column() {
15432 assert_snapshot!(goto("
15433create schema s;
15434create table s.t (a int, b text);
15435create function f(x s.t.a$0%type) returns s.t.b%type
15436 as $$ select 'hello'::text $$ language sql;
15437"), @"
15438 ╭▸
15439 3 │ create table s.t (a int, b text);
15440 │ ─ 2. destination
15441 4 │ create function f(x s.t.a%type) returns s.t.b%type
15442 ╰╴ ─ 1. source
15443 ");
15444 }
15445
15446 #[test]
15447 fn goto_create_function_param_percent_type_table() {
15448 assert_snapshot!(goto("
15449create schema s;
15450create table s.t (a int, b text);
15451create function f(x s.t$0.a%type) returns s.t.b%type
15452 as $$ select 'hello'::text $$ language sql;
15453"), @"
15454 ╭▸
15455 3 │ create table s.t (a int, b text);
15456 │ ─ 2. destination
15457 4 │ create function f(x s.t.a%type) returns s.t.b%type
15458 ╰╴ ─ 1. source
15459 ");
15460 }
15461
15462 #[test]
15463 fn goto_create_function_param_percent_type_schema() {
15464 assert_snapshot!(goto("
15465create schema s;
15466create table s.t (a int, b text);
15467create function f(x s$0.t.a%type) returns s.t.b%type
15468 as $$ select 'hello'::text $$ language sql;
15469"), @"
15470 ╭▸
15471 2 │ create schema s;
15472 │ ─ 2. destination
15473 3 │ create table s.t (a int, b text);
15474 4 │ create function f(x s.t.a%type) returns s.t.b%type
15475 ╰╴ ─ 1. source
15476 ");
15477 }
15478
15479 #[test]
15480 fn goto_create_function_returns_percent_type_column() {
15481 assert_snapshot!(goto("
15482create schema s;
15483create table s.t (a int, b text);
15484create function f(x s.t.a%type) returns s.t.b$0%type
15485 as $$ select 'hello'::text $$ language sql;
15486"), @"
15487 ╭▸
15488 3 │ create table s.t (a int, b text);
15489 │ ─ 2. destination
15490 4 │ create function f(x s.t.a%type) returns s.t.b%type
15491 ╰╴ ─ 1. source
15492 ");
15493 }
15494
15495 #[test]
15496 fn goto_create_function_param_percent_type_two_part() {
15497 assert_snapshot!(goto("
15498create table t (a int, b text);
15499create function f(x t.a$0%type) returns t.b%type
15500 as $$ select 'hello'::text $$ language sql;
15501"), @"
15502 ╭▸
15503 2 │ create table t (a int, b text);
15504 │ ─ 2. destination
15505 3 │ create function f(x t.a%type) returns t.b%type
15506 ╰╴ ─ 1. source
15507 ");
15508 }
15509
15510 #[test]
15511 fn goto_grant_table() {
15512 assert_snapshot!(goto("
15513create table foo (id int);
15514grant select on foo$0 to bob;
15515"), @"
15516 ╭▸
15517 2 │ create table foo (id int);
15518 │ ─── 2. destination
15519 3 │ grant select on foo to bob;
15520 ╰╴ ─ 1. source
15521 ");
15522 }
15523
15524 #[test]
15525 fn goto_grant_table_keyword() {
15526 assert_snapshot!(goto("
15527create table foo (id int);
15528grant select on table foo$0 to bob;
15529"), @"
15530 ╭▸
15531 2 │ create table foo (id int);
15532 │ ─── 2. destination
15533 3 │ grant select on table foo to bob;
15534 ╰╴ ─ 1. source
15535 ");
15536 }
15537
15538 #[test]
15539 fn goto_revoke_table() {
15540 assert_snapshot!(goto("
15541create table foo (id int);
15542revoke select on foo$0 from bob;
15543"), @"
15544 ╭▸
15545 2 │ create table foo (id int);
15546 │ ─── 2. destination
15547 3 │ revoke select on foo from bob;
15548 ╰╴ ─ 1. source
15549 ");
15550 }
15551
15552 #[test]
15553 fn goto_grant_column() {
15554 assert_snapshot!(goto("
15555create table foo (id int);
15556grant select (id$0) on foo to bob;
15557"), @"
15558 ╭▸
15559 2 │ create table foo (id int);
15560 │ ── 2. destination
15561 3 │ grant select (id) on foo to bob;
15562 ╰╴ ─ 1. source
15563 ");
15564 }
15565
15566 #[test]
15567 fn goto_grant_sequence() {
15568 assert_snapshot!(goto("
15569create sequence s;
15570grant usage on sequence s$0 to bob;
15571"), @"
15572 ╭▸
15573 2 │ create sequence s;
15574 │ ─ 2. destination
15575 3 │ grant usage on sequence s to bob;
15576 ╰╴ ─ 1. source
15577 ");
15578 }
15579
15580 #[test]
15581 fn goto_grant_function() {
15582 assert_snapshot!(goto("
15583create function f() returns int language sql as 'select 1';
15584grant execute on function f$0 to bob;
15585"), @"
15586 ╭▸
15587 2 │ create function f() returns int language sql as 'select 1';
15588 │ ─ 2. destination
15589 3 │ grant execute on function f to bob;
15590 ╰╴ ─ 1. source
15591 ");
15592 }
15593
15594 #[test]
15595 fn goto_grant_schema() {
15596 assert_snapshot!(goto("
15597create schema myschema;
15598grant usage on schema myschema$0 to bob;
15599"), @"
15600 ╭▸
15601 2 │ create schema myschema;
15602 │ ──────── 2. destination
15603 3 │ grant usage on schema myschema to bob;
15604 ╰╴ ─ 1. source
15605 ");
15606 }
15607
15608 #[test]
15609 fn goto_grant_view() {
15610 assert_snapshot!(goto("
15611create view v as select 1;
15612grant select on v$0 to bob;
15613"), @"
15614 ╭▸
15615 2 │ create view v as select 1;
15616 │ ─ 2. destination
15617 3 │ grant select on v to bob;
15618 ╰╴ ─ 1. source
15619 ");
15620 }
15621
15622 #[test]
15623 fn goto_grant_domain() {
15624 assert_snapshot!(goto("
15625create domain d as int;
15626grant usage on domain d$0 to bob;
15627"), @"
15628 ╭▸
15629 2 │ create domain d as int;
15630 │ ─ 2. destination
15631 3 │ grant usage on domain d to bob;
15632 ╰╴ ─ 1. source
15633 ");
15634 }
15635
15636 #[test]
15637 fn goto_grant_language() {
15638 assert_snapshot!(goto("
15639create language mylang handler h;
15640grant usage on language mylang$0 to bob;
15641"), @"
15642 ╭▸
15643 2 │ create language mylang handler h;
15644 │ ────── 2. destination
15645 3 │ grant usage on language mylang to bob;
15646 ╰╴ ─ 1. source
15647 ");
15648 }
15649
15650 #[test]
15651 fn goto_grant_foreign_server() {
15652 assert_snapshot!(goto("
15653create foreign data wrapper fdw;
15654create server s foreign data wrapper fdw;
15655grant usage on foreign server s$0 to bob;
15656"), @"
15657 ╭▸
15658 3 │ create server s foreign data wrapper fdw;
15659 │ ─ 2. destination
15660 4 │ grant usage on foreign server s to bob;
15661 ╰╴ ─ 1. source
15662 ");
15663 }
15664
15665 #[test]
15666 fn goto_grant_foreign_data_wrapper() {
15667 assert_snapshot!(goto("
15668create foreign data wrapper w;
15669grant usage on foreign data wrapper w$0 to bob;
15670"), @"
15671 ╭▸
15672 2 │ create foreign data wrapper w;
15673 │ ─ 2. destination
15674 3 │ grant usage on foreign data wrapper w to bob;
15675 ╰╴ ─ 1. source
15676 ");
15677 }
15678
15679 #[test]
15680 fn goto_grant_all_tables_in_schema() {
15681 assert_snapshot!(goto("
15682create schema sc;
15683grant select on all tables in schema sc$0 to bob;
15684"), @"
15685 ╭▸
15686 2 │ create schema sc;
15687 │ ── 2. destination
15688 3 │ grant select on all tables in schema sc to bob;
15689 ╰╴ ─ 1. source
15690 ");
15691 }
15692
15693 #[test]
15694 fn goto_create_statistics_column() {
15695 assert_snapshot!(goto("
15696create table t(a int, b int);
15697create statistics st on a$0, b from t;
15698"), @"
15699 ╭▸
15700 2 │ create table t(a int, b int);
15701 │ ─ 2. destination
15702 3 │ create statistics st on a, b from t;
15703 ╰╴ ─ 1. source
15704 ");
15705 }
15706
15707 #[test]
15708 fn goto_create_statistics_table() {
15709 assert_snapshot!(goto("
15710create table t(a int, b int);
15711create statistics st on a, b from t$0;
15712"), @"
15713 ╭▸
15714 2 │ create table t(a int, b int);
15715 │ ─ 2. destination
15716 3 │ create statistics st on a, b from t;
15717 ╰╴ ─ 1. source
15718 ");
15719 }
15720
15721 #[test]
15722 fn goto_create_statistics_schema_qualified_table() {
15723 assert_snapshot!(goto("
15724create schema s;
15725create table s.t(a int, b int);
15726create statistics st on a, b from s.t$0;
15727"), @"
15728 ╭▸
15729 3 │ create table s.t(a int, b int);
15730 │ ─ 2. destination
15731 4 │ create statistics st on a, b from s.t;
15732 ╰╴ ─ 1. source
15733 ");
15734 }
15735
15736 #[test]
15737 fn goto_drop_statistics() {
15738 assert_snapshot!(goto("
15739create table t(a int);
15740create statistics s on a from t;
15741drop statistics s$0;
15742"), @"
15743 ╭▸
15744 3 │ create statistics s on a from t;
15745 │ ─ 2. destination
15746 4 │ drop statistics s;
15747 ╰╴ ─ 1. source
15748 ");
15749 }
15750
15751 #[test]
15752 fn goto_alter_statistics() {
15753 assert_snapshot!(goto("
15754create table t(a int);
15755create statistics s on a from t;
15756alter statistics s$0 set statistics 100;
15757"), @"
15758 ╭▸
15759 3 │ create statistics s on a from t;
15760 │ ─ 2. destination
15761 4 │ alter statistics s set statistics 100;
15762 ╰╴ ─ 1. source
15763 ");
15764 }
15765
15766 #[test]
15767 fn goto_comment_on_statistics() {
15768 assert_snapshot!(goto("
15769create table t(a int);
15770create statistics s on a from t;
15771comment on statistics s$0 is '';
15772"), @"
15773 ╭▸
15774 3 │ create statistics s on a from t;
15775 │ ─ 2. destination
15776 4 │ comment on statistics s is '';
15777 ╰╴ ─ 1. source
15778 ");
15779 }
15780
15781 #[test]
15782 fn goto_create_publication_table() {
15783 assert_snapshot!(goto("
15784create table t(a int);
15785create publication pub for table t$0;
15786"), @"
15787 ╭▸
15788 2 │ create table t(a int);
15789 │ ─ 2. destination
15790 3 │ create publication pub for table t;
15791 ╰╴ ─ 1. source
15792 ");
15793 }
15794
15795 #[test]
15796 fn goto_create_publication_column() {
15797 assert_snapshot!(goto("
15798create table t(a int, b int);
15799create publication pub for table t (a$0, b);
15800"), @"
15801 ╭▸
15802 2 │ create table t(a int, b int);
15803 │ ─ 2. destination
15804 3 │ create publication pub for table t (a, b);
15805 ╰╴ ─ 1. source
15806 ");
15807 }
15808
15809 #[test]
15810 fn goto_create_publication_where_column() {
15811 assert_snapshot!(goto("
15812create table t(a int, b int);
15813create publication pub for table t where (a$0 > 1);
15814"), @"
15815 ╭▸
15816 2 │ create table t(a int, b int);
15817 │ ─ 2. destination
15818 3 │ create publication pub for table t where (a > 1);
15819 ╰╴ ─ 1. source
15820 ");
15821 }
15822
15823 #[test]
15824 fn goto_count_star_filter_column() {
15825 assert_snapshot!(goto("
15826create table t (a int);
15827select count(*) filter (where a$0 > 0) from t;
15828"), @"
15829 ╭▸
15830 2 │ create table t (a int);
15831 │ ─ 2. destination
15832 3 │ select count(*) filter (where a > 0) from t;
15833 ╰╴ ─ 1. source
15834 ");
15835 }
15836
15837 #[test]
15838 fn goto_with_ordinality_implicit_column() {
15839 assert_snapshot!(goto("
15840select ordinality$0 from unnest(array[1,2]) with ordinality;
15841"), @"
15842 ╭▸
15843 2 │ select ordinality from unnest(array[1,2]) with ordinality;
15844 ╰╴ ─ 1. source ────────── 2. destination
15845 ");
15846 }
15847
15848 #[test]
15849 fn goto_with_ordinality_qualified_implicit_column() {
15850 assert_snapshot!(goto("
15851select u.ordinality$0 from unnest(array[1,2]) with ordinality as u;
15852"), @"
15853 ╭▸
15854 2 │ select u.ordinality from unnest(array[1,2]) with ordinality as u;
15855 ╰╴ ─ 1. source ────────── 2. destination
15856 ");
15857 }
15858
15859 #[test]
15860 fn goto_with_ordinality_explicit_alias_column() {
15861 assert_snapshot!(goto("
15862select o$0 from unnest(array[1,2]) with ordinality as u(x, o);
15863"), @"
15864 ╭▸
15865 2 │ select o from unnest(array[1,2]) with ordinality as u(x, o);
15866 ╰╴ ─ 1. source ─ 2. destination
15867 ");
15868 }
15869
15870 #[test]
15871 fn goto_rows_from_with_ordinality_implicit_column() {
15872 assert_snapshot!(goto("
15873select ordinality$0 from rows from (unnest(array[1,2])) with ordinality;
15874"), @"
15875 ╭▸
15876 2 │ select ordinality from rows from (unnest(array[1,2])) with ordinality;
15877 ╰╴ ─ 1. source ────────── 2. destination
15878 ");
15879 }
15880
15881 #[test]
15882 fn goto_rows_from_alias_column_with_per_item_column_def_list() {
15883 assert_snapshot!(goto("
15884select z.q$0 from rows from (unnest(array[1,2]) as (x int)) as z(q);
15885"), @"
15886 ╭▸
15887 2 │ select z.q from rows from (unnest(array[1,2]) as (x int)) as z(q);
15888 ╰╴ ─ 1. source ─ 2. destination
15889 ");
15890 }
15891
15892 #[test]
15893 fn goto_rows_from_column_def_after_partial_item_alias() {
15894 assert_snapshot!(goto("
15895create function f_rec() returns record as $$ select 1 $$ language sql;
15896select x$0 from rows from (unnest(array[1,2]), f_rec() as (x int)) as z(c1);
15897"), @"
15898 ╭▸
15899 3 │ select x from rows from (unnest(array[1,2]), f_rec() as (x int)) as z(c1);
15900 ╰╴ ─ 1. source ─ 2. destination
15901 ");
15902 }
15903
15904 #[test]
15905 fn goto_rows_from_applies_outer_alias_skip_across_items() {
15906 assert_snapshot!(goto("
15907create function f() returns record as $$ select 1 $$ language sql;
15908create function g() returns record as $$ select 1 $$ language sql;
15909select y$0 from rows from (f() as (x int), g() as (y int)) as z(q);
15910"), @"
15911 ╭▸
15912 4 │ select y from rows from (f() as (x int), g() as (y int)) as z(q);
15913 ╰╴ ─ 1. source ─ 2. destination
15914 ");
15915 }
15916
15917 #[test]
15918 fn goto_rows_from_per_item_column_def_list_column() {
15919 assert_snapshot!(goto("
15920select x$0 from rows from (unnest(array[1,2]) as (x int));
15921"), @"
15922 ╭▸
15923 2 │ select x from rows from (unnest(array[1,2]) as (x int));
15924 ╰╴ ─ 1. source ─ 2. destination
15925 ");
15926 }
15927
15928 #[test]
15929 fn goto_rows_from_column_after_outer_alias_for_composite_return() {
15930 assert_snapshot!(goto("
15931create type pair as (a int, b int);
15932create function f() returns setof pair as $$ select 1, 2 $$ language sql;
15933create function g() returns table(y int) as $$ select 3 $$ language sql;
15934select y$0 from rows from (f(), g()) as z(q, r);
15935"), @"
15936 ╭▸
15937 4 │ create function g() returns table(y int) as $$ select 3 $$ language sql;
15938 │ ─ 2. destination
15939 5 │ select y from rows from (f(), g()) as z(q, r);
15940 ╰╴ ─ 1. source
15941 ");
15942 }
15943}