Data layer
Working with Views
Learn how to work with views in PandaAI
PandaAI 3.0 is currently in beta. This documentation reflects the latest features and functionality, which may evolve before the final release.
What are views?
Views are a feature of SQL databases that allow you to define logical subsets of data that can be used in queries. In PandaAI, you can define views in your semantic layer schema to organize and structure your data. Views are particularly useful when you want to:
- Combine data from multiple datasets
- Create a simplified or filtered view of your data
- Define relationships between different datasets
Creating Views
You can create views either through YAML configuration or programmatically using Python.
Python Code Example
YAML Configuration
Example Configuration
Constraints
-
Mutual Exclusivity:
- A schema cannot define both
table
andview
simultaneously. - If
view
istrue
, then the schema represents a view.
- A schema cannot define both
-
Column Format:
- For views:
- All columns must follow the format
[table].[column]
. from
andto
fields inrelations
must follow the[table].[column]
format.- Example:
loans.payment_amount
,heart.condition
.
- All columns must follow the format
- For views:
-
Relationships for Views:
- Each table referenced in
columns
must have at least one relationship defined inrelations
. - Relationships must specify
from
andto
attributes in the[table].[column]
format. - Relations define how different tables in your view are connected.
- Each table referenced in
-
Dataset Requirements:
- All referenced datasets must exist before creating the view.
- The columns specified in the view must exist in their respective source datasets.
- The columns used in relations (
from
andto
) must be compatible types.
Was this page helpful?