-
Notifications
You must be signed in to change notification settings - Fork 179
Description
In working with SQL views, I struggled to find a way to ensure that code blocks that create views run before code blocks that use those views. I settled on the pattern below, but I'm wondering if there is an alternative way to accomplish the same.
This SQL block creates a view. The id directive allows another code block to depend on it running first.
```sql id=[testView]
CREATE OR REPLACE VIEW test_view AS SELECT 'it works' AS testing;
SELECT 'test_view' AS name;
```This SQL block depends on the one above. It uses query_table to refer to the view name from the SELECT above (rather than selecting from test_view by name).
```sql
SELECT * from query_table(${testView.name});
```I'm wondering if I am missing documentation on a code block directive that might be used to indicate that one code block depends on another.
I think I also found that SQL code blocks run from bottom to top if they otherwise don't have references that would sort them in a different order - but I don't know if this is guaranteed.