Projections for tables

In findOne and find, you can use the projection parameter to select specific columns to include or exclude from the response. The projection cannot mix inclusions and exclusions.

If projection is empty or unspecified, the Data API applies the default projection. For rows, the default projection includes all columns.

Over HTTP, the Data API always excludes null values in responses, regardless of projection For example, if find matches multiple rows, the response can include different columns for each row, depending on which columns are null in each row. You cannot forcibly include null values in the response.

The clients reconstruct returned rows by adding the columns omitted in the API response. Therefore, when using a client, rows from findOne and find operations always have the same columns, as specified by the projection, regardless of the presence of null values.

In order to optimize the response size and improve performance, DataStax recommends always providing an explicit projection tailored to the needs of the application.

Projection syntax

A projection is expressed as a mapping of column names to boolean values.

Use true mapping to include only the specified columns. For example, the following true mapping returns the columns name and email:

json
{ "name": true, "email": true }

Alternatively, use a false mapping to exclude the specified columns. All other non-excluded columns are returned. For example, the following false mapping returns all columns except name and email:

json
{ "name": false, "email": false }

The values in a projection map can be objects, booleans, decimals, or integers, but the Data API ultimately evaluates all of these as booleans.

For example, the following projection evaluates to true (include) for all four columns:

json
{ "column1": true, "column2": 1, "column3": 90.0, "column4": { "keep": "yes!" } }

Whereas this projection evaluates to false (exclude) for all four columns:

json
{ "column1": false, "column2": 0, "column3": 0.0, "column4": {} }

Passing null-like types (such as {}, null or 0) for the whole projection mapping is equivalent to not specifying a projection, causing the Data API to use the default projection.

A projection cannot mix include and exclude projections. It can contain only true or only false values for the given columns. For example, {"column1": true, "column2": false} is an invalid projection that results in an API error.

A projection cannot include or exclude sub-column values, such as keys in map columns.

To include all columns, you can use the wildcard projection { "*": true }. This is equivalent to the default projection. The Data API doesn’t support false wildcard projections for tables.

Projection examples by language

For the Python client, the projection can be any of the following:

  • A dictionary (dict[str, Any]) to include specific columns in the response, like {column_name: True}.

  • A dictionary (dict[str, Any]) to exclude specific columns from the response, like {column_name: False}.

  • A list or other iterable over key names that are implied to be included in the projection.

python
# The following two statements are equivalent:
document = table.find_one(
   {"user_id": 101},
   projection={"name": True, "city": True},
)
document = table.find_one(
   {"user_id": 101},
   projection=["name", "city"],
)

# Return the whole rows (default):
table.find({}, projection={'*': True}).to_list()

# Exclude certain columns:
table.find({}, projection={'name': False}).to_list()

For information about default projections and projection syntax, see the preceding explanation of projection clauses.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax | Privacy policy | Terms of use | Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com