Release: 1.4.53 | Release Date: July 29, 2024

# SQLAlchemy 1.4 Documentation

# Querying Data, Loading Objects

The following sections refer to techniques for emitting SELECT statements within an ORM context. This involves primarily statements that return instances of ORM mapped objects, but also involves calling forms that deliver individual column or groups of columns as well.

For an introduction to querying with the SQLAlchemy ORM, one of the following tutorials should be consulted:

- SQLAlchemy 1.4 / 2.0 Tutorial - for 2.0 style usage

- Object Relational Tutorial (1.x API) - for 1.x style usage.

As SQLAlchemy 1.4 represents a transition from 1.x to 2.0 style, the below sections are currently mixed as far as which style they are using.

- ORM Querying Guide
  - SELECT statements
    - Selecting ORM Entities and Attributes
    - Selecting Entities from Subqueries
    - Selecting Entities from UNIONs and other set operations
    - Joins
    - Special Relationship Operators
    - ORM Loader Options
    - ORM Execution Options
  - ORM Update / Delete with Arbitrary WHERE clause
  - Inspecting entities and columns from ORM-enabled SELECT and DML statements
- Loading Columns
  - Deferred Column Loading
    - Deferred Column Loader Query Options
    - Deferred Loading across Multiple Entities
    - Load Only and Wildcard Options
    - Raiseload for Deferred Columns
    - Column Deferral API
  - Column Bundles
- Relationship Loading Techniques
  - Configuring Loader Strategies at Mapping Time
  - Relationship Loading with Loader Options
    - Adding Criteria to loader options
    - Specifying Sub-Options with Load.options()
  - Lazy Loading
    - Preventing unwanted lazy loads using raiseload
  - Joined Eager Loading
    - Joined eager loading and result set batching
    - The Zen of Joined Eager Loading
  - Subquery Eager Loading
    - The Importance of Ordering
  - Select IN loading
  - What Kind of Loading to Use ?
  - Polymorphic Eager Loading
  - Wildcard Loading Strategies
    - Per-Entity Wildcard Loading Strategies
  - Routing Explicit Joins/Statements into Eagerly Loaded Collections
    - Using contains_eager() to load a custom-filtered collection result
  - Creating Custom Load Rules
  - Relationship Loader API
    - `contains_eager()`
    - `defaultload()`
    - `eagerload()`
    - `immediateload()`
    - `joinedload()`
    - `lazyload()`
    - `Load`
    - `noload()`
    - `raiseload()`
    - `selectinload()`
    - `subqueryload()`
- Loading Inheritance Hierarchies
  - Using with_polymorphic
    - Using aliasing with with_polymorphic
    - Referring to Specific Subclass Attributes
    - Setting with_polymorphic at mapper configuration time
    - Setting with_polymorphic against a query
  - Polymorphic Selectin Loading
    - Combining selectin and with_polymorphic
  - Referring to specific subtypes on relationships
    - Eager Loading of Specific or Polymorphic Subtypes
  - Loading objects with joined table inheritance
  - Loading objects with single table inheritance
  - Inheritance Loading API
    - `with_polymorphic()`
    - `selectin_polymorphic()`
- Query API
  - The Query Object
    - `Query`
  - ORM-Specific Query Constructs
    - `aliased()`
    - `AliasedClass`
    - `AliasedInsp`
    - `Bundle`
    - `with_loader_criteria()`
    - `join()`
    - `outerjoin()`
    - `with_parent()`