if the partition key is included in the WHERE clause of a SELECT query, the query planner will ensure that only relevant shards are searched. Otherwise, if no WHERE clause on the partition key is specified, all partitons are returned by default.
For performance reasons (especially on big tables), it is recommended to always include the partition key in SELECT queries as part of the WHERE clause, to prevent all partitions from being scanned (unless that is intended).
In most cases, the partition key is derived from another column using a generated column, as in this example:
CREATE TABLE "doc"."partition_test" (
"ts" TIMESTAMP WITH TIME ZONE,
"ts_month" TIMESTAMP WITH TIME ZONE GENERATED ALWAYS AS date_trunc('month', "ts"),
PARTITIONED BY ("ts_month");
In that case, you can also run queries with a WHERE condition on ts. The query planner detects that ts_month can be derived from ts. So a query like SELECT * FROM doc.partition_test WHERE ts = '2022-07-15' will also be executed efficiently on relevant partitions only. Specifying ts_month explicitly is not needed.
There are some more details in this part of the documentation: