I'm new to snowflake. And I need to know about the recursive view in snowflake. Can someone explain it with an example. And why recursive views are used. Non-Materialized view only
I need a really good example. Thank u in advance
CREATE OR REPLACE TABLE employees (title VARCHAR, employee_ID INTEGER, manager_ID INTEGER);
INSERT INTO employees (title, employee_ID, manager_ID) VALUES
('President', 1, NULL), -- The President has no manager.
('Vice President Engineering', 10, 1),
('Programmer', 100, 10),
('QA Engineer', 101, 10),
('Vice President HR', 20, 1),
('Health Insurance Analyst', 200, 20);
CREATE or replace RECURSIVE VIEW employee_hierarchy_02 (title, employee_ID, manager_ID, "MGR_EMP_ID (SHOULD BE SAME)", "MGR TITLE") AS (
-- Start at the top of the hierarchy ...
SELECT title, employee_ID, manager_ID, NULL AS "MGR_EMP_ID (SHOULD BE SAME)", 'President' AS "MGR TITLE"
FROM employees
WHERE title = 'President'
UNION all
-- ... and work our way down one level at a time.
SELECT employees.title,
employees.employee_ID,
employees.manager_ID,
employee_hierarchy_02.employee_id AS "MGR_EMP_ID (SHOULD BE SAME)",
employee_hierarchy_02.title AS "MGR TITLE"
FROM employees INNER JOIN employee_hierarchy_02
WHERE employee_hierarchy_02.employee_ID = employees.manager_ID
);
what the above really means