Skip to main content
The semantic data layer is an experimental feature, suggested to advanced users.

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 PandasAI, 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

  1. Mutual Exclusivity:
    • A schema cannot define both table and view simultaneously.
    • If view is true, then the schema represents a view.
  2. Column Format:
    • For views:
      • All columns must follow the format [table].[column].
      • from and to fields in relations must follow the [table].[column] format.
      • Example: loans.payment_amount, heart.condition.
  3. Relationships for Views:
    • Each table referenced in columns must have at least one relationship defined in relations.
    • Relationships must specify from and to attributes in the [table].[column] format.
    • Relations define how different tables in your view are connected.
  4. 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 and to) must be compatible types.