Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions testdata/diff/create_view/add_view/diff.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,33 @@ CREATE OR REPLACE VIEW text_search_view AS
to_tsvector('english'::regconfig, (((COALESCE(first_name, ''::character varying)::text || ' '::text) || COALESCE(last_name, ''::character varying)::text) || ' '::text) || COALESCE(bio, ''::text)) AS search_vector
FROM employees
WHERE status::text = 'active'::text;

CREATE OR REPLACE VIEW union_subquery_view AS
SELECT id,
name,
source_type,
CASE
WHEN source_type = 'employee'::text THEN 'active'::text
WHEN source_type = 'department'::text THEN 'organizational'::text
ELSE 'unknown'::text
END AS category
FROM ((
SELECT employees.id,
employees.name,
'employee'::text AS source_type
FROM employees
WHERE employees.status::text = 'active'::text
UNION
SELECT departments.id,
departments.name,
'department'::text AS source_type
FROM departments
WHERE departments.manager_id IS NOT NULL
) UNION ALL
SELECT employees.id,
COALESCE((employees.first_name::text || ' '::text) || employees.last_name::text, employees.name::text) AS name,
'employee_full'::text AS source_type
FROM employees
WHERE employees.priority > 10) combined_data
WHERE id IS NOT NULL
ORDER BY source_type, id;
39 changes: 39 additions & 0 deletions testdata/diff/create_view/add_view/new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,42 @@ FROM monthly_stats ms
CROSS JOIN departments d
LEFT JOIN employee_summary es ON d.id = es.department_id
ORDER BY ms.month_start DESC, d.name;

-- View testing UNION and UNION ALL in subqueries (regression test for issue #104)
CREATE VIEW public.union_subquery_view AS
SELECT
id,
name,
source_type,
-- Additional columns from the union result
CASE
WHEN source_type = 'employee' THEN 'active'
WHEN source_type = 'department' THEN 'organizational'
ELSE 'unknown'
END AS category
FROM (
-- Simple UNION combining employees and departments (main issue from #104)
SELECT
id,
name,
'employee' AS source_type
FROM employees
WHERE status = 'active'
UNION
SELECT
id,
name,
'department' AS source_type
FROM departments
WHERE manager_id IS NOT NULL
-- UNION ALL variant (keep duplicates)
UNION ALL
SELECT
id,
COALESCE(first_name || ' ' || last_name, name) AS name,
'employee_full' AS source_type
FROM employees
WHERE priority > 10
) AS combined_data
WHERE id IS NOT NULL
ORDER BY source_type, id;
6 changes: 6 additions & 0 deletions testdata/diff/create_view/add_view/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
"type": "view",
"operation": "create",
"path": "public.text_search_view"
},
{
"sql": "CREATE OR REPLACE VIEW union_subquery_view AS\n SELECT id,\n name,\n source_type,\n CASE\n WHEN source_type = 'employee'::text THEN 'active'::text\n WHEN source_type = 'department'::text THEN 'organizational'::text\n ELSE 'unknown'::text\n END AS category\n FROM ((\n SELECT employees.id,\n employees.name,\n 'employee'::text AS source_type\n FROM employees\n WHERE employees.status::text = 'active'::text\n UNION\n SELECT departments.id,\n departments.name,\n 'department'::text AS source_type\n FROM departments\n WHERE departments.manager_id IS NOT NULL\n ) UNION ALL\n SELECT employees.id,\n COALESCE((employees.first_name::text || ' '::text) || employees.last_name::text, employees.name::text) AS name,\n 'employee_full'::text AS source_type\n FROM employees\n WHERE employees.priority > 10) combined_data\n WHERE id IS NOT NULL\n ORDER BY source_type, id;",
"type": "view",
"operation": "create",
"path": "public.union_subquery_view"
}
]
}
Expand Down
30 changes: 30 additions & 0 deletions testdata/diff/create_view/add_view/plan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,33 @@ CREATE OR REPLACE VIEW text_search_view AS
to_tsvector('english'::regconfig, (((COALESCE(first_name, ''::character varying)::text || ' '::text) || COALESCE(last_name, ''::character varying)::text) || ' '::text) || COALESCE(bio, ''::text)) AS search_vector
FROM employees
WHERE status::text = 'active'::text;

CREATE OR REPLACE VIEW union_subquery_view AS
SELECT id,
name,
source_type,
CASE
WHEN source_type = 'employee'::text THEN 'active'::text
WHEN source_type = 'department'::text THEN 'organizational'::text
ELSE 'unknown'::text
END AS category
FROM ((
SELECT employees.id,
employees.name,
'employee'::text AS source_type
FROM employees
WHERE employees.status::text = 'active'::text
UNION
SELECT departments.id,
departments.name,
'department'::text AS source_type
FROM departments
WHERE departments.manager_id IS NOT NULL
) UNION ALL
SELECT employees.id,
COALESCE((employees.first_name::text || ' '::text) || employees.last_name::text, employees.name::text) AS name,
'employee_full'::text AS source_type
FROM employees
WHERE employees.priority > 10) combined_data
WHERE id IS NOT NULL
ORDER BY source_type, id;
35 changes: 33 additions & 2 deletions testdata/diff/create_view/add_view/plan.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Plan: 4 to add.
Plan: 5 to add.

Summary by type:
views: 4 to add
views: 5 to add

Views:
+ array_operators_view
+ cte_with_case_view
+ nullif_functions_view
+ text_search_view
+ union_subquery_view

DDL to be executed:
--------------------------------------------------
Expand Down Expand Up @@ -80,3 +81,33 @@ CREATE OR REPLACE VIEW text_search_view AS
to_tsvector('english'::regconfig, (((COALESCE(first_name, ''::character varying)::text || ' '::text) || COALESCE(last_name, ''::character varying)::text) || ' '::text) || COALESCE(bio, ''::text)) AS search_vector
FROM employees
WHERE status::text = 'active'::text;

CREATE OR REPLACE VIEW union_subquery_view AS
SELECT id,
name,
source_type,
CASE
WHEN source_type = 'employee'::text THEN 'active'::text
WHEN source_type = 'department'::text THEN 'organizational'::text
ELSE 'unknown'::text
END AS category
FROM ((
SELECT employees.id,
employees.name,
'employee'::text AS source_type
FROM employees
WHERE employees.status::text = 'active'::text
UNION
SELECT departments.id,
departments.name,
'department'::text AS source_type
FROM departments
WHERE departments.manager_id IS NOT NULL
) UNION ALL
SELECT employees.id,
COALESCE((employees.first_name::text || ' '::text) || employees.last_name::text, employees.name::text) AS name,
'employee_full'::text AS source_type
FROM employees
WHERE employees.priority > 10) combined_data
WHERE id IS NOT NULL
ORDER BY source_type, id;