;doc: Queries: discuss transaction vs posting queries; cleanups
This commit is contained in:
parent
ee87ba7f5f
commit
87c7f61670
@ -5243,11 +5243,11 @@ The same would be true with the argument `--depth assets=1 --depth savings=2`.
|
|||||||
|
|
||||||
# Queries
|
# Queries
|
||||||
|
|
||||||
Most hledger commands accept query arguments, which restrict their scope and let you report on a precise subset of your data.
|
Many hledger commands accept query arguments,
|
||||||
Here's a quick overview of hledger's query language:
|
which restrict their scope and let you report on a precise subset of your data.
|
||||||
|
Here's a quick overview of hledger's queries:
|
||||||
|
|
||||||
- An argument with no recognised query prefix is interpreted as
|
- By default, a query argument is treated as a case-insensitive substring pattern for matching [account names](#account-names).
|
||||||
a case-insensitive substring pattern for matching [account names](#account-names).
|
|
||||||
Eg:
|
Eg:
|
||||||
|
|
||||||
`dining groceries`\
|
`dining groceries`\
|
||||||
@ -5275,6 +5275,7 @@ Here's a quick overview of hledger's query language:
|
|||||||
`cur:USD`\
|
`cur:USD`\
|
||||||
`cur:\\$`\
|
`cur:\\$`\
|
||||||
`amt:'>0'`\
|
`amt:'>0'`\
|
||||||
|
`acct:groceries` (but `acct:` is the default, so we usually don't bother writing it) \
|
||||||
|
|
||||||
- To negate a query, add a `not:` prefix:
|
- To negate a query, add a `not:` prefix:
|
||||||
|
|
||||||
@ -5282,13 +5283,30 @@ Here's a quick overview of hledger's query language:
|
|||||||
`not:desc:'opening|closing'`\
|
`not:desc:'opening|closing'`\
|
||||||
`not:cur:USD`\
|
`not:cur:USD`\
|
||||||
|
|
||||||
- If you provide multiple query terms as command line arguments,
|
- Multiple query terms can be combined, as [space-separated queries](#space-separated-queries)
|
||||||
the terms with different types will be AND-ed, while
|
Eg: `hledger print date:2022 desc:amazon desc:amzn`
|
||||||
the terms with the same type will be OR-ed (mostly).\
|
(show transactions dated in 2022 whose description contains "amazon" or "amzn").\
|
||||||
So, `hledger print date:2022 desc:amazon desc:amzn`
|
|
||||||
means "show transactions where the date is in 2022 AND the description contains (amazon OR amzn)".
|
|
||||||
More flexible query combining is described below.
|
|
||||||
|
|
||||||
|
- Or more flexibly as [boolean queries](#boolean-queries).
|
||||||
|
Eg: `hledger print expr:'date:2022 and (desc:amazon or desc:amzn) and not date:202210'`\
|
||||||
|
|
||||||
|
All hledger commands use the same query language, but different commands may interpret the query in different ways,
|
||||||
|
and this is worth keeping in mind.
|
||||||
|
We haven't described the commands yet (that's coming in [PART 4: COMMANDS](#part-4-commands) below)
|
||||||
|
but here's the gist of it:
|
||||||
|
|
||||||
|
- Transaction-oriented commands
|
||||||
|
(`print`, `aregister`, `close`, `import`, `descriptions`..)
|
||||||
|
try to match [transactions](#transactions) (including the transaction's postings).
|
||||||
|
|
||||||
|
- Posting-oriented commands
|
||||||
|
(`register`, `balance`, `balancesheet`, `incomestatement`, `accounts`..)
|
||||||
|
try to match [postings](#postings).
|
||||||
|
Postings inherit their transaction's attributes for querying purposes,
|
||||||
|
so transaction fields like date or description can still be referenced in a posting query.
|
||||||
|
|
||||||
|
- A few commands match in more specific ways.
|
||||||
|
(Eg `aregister`, which has a special first argument.)
|
||||||
|
|
||||||
## Query types
|
## Query types
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user