Skip to content

The [OPEN ON <date>] [CLOSE [ON <date>]] [CLEAR]] are not available in the #table form of the query #274

@Ev2geny

Description

@Ev2geny

It is my understanding from this discussion, that the [OPEN ON <date>] [CLOSE [ON <date>]] [CLEAR]] features shall also be available in the SELECT query, when using the #table query form. However this is not the case at the moment:

Example: suppose we have the following: ledger

2020-01-01 open Assets:Bank USD
2020-01-01 open Assets:Cash
2020-01-01 open Equity:Initial-Balance
2020-01-01 open Expenses:Food

2020-01-01 * "Initial Balance"
    Assets:Bank          1000.00 USD
    Equity:Initial-Balance


2020-01-02 * "Buy Groceries 2020-01-02"
    Assets:Bank          
    Expenses:Food        1.00 USD

2020-01-03 * "Buy Groceries 2020-01-03"
    Assets:Bank          
    Expenses:Food        10.00 USD

2020-01-04 * "Buy Groceries 2020-01-04"
    Assets:Bank          
    Expenses:Food        100.00 USD

Then this query works

beanquery> select *  FROM OPEN ON 2020-01-03
   date     f  p                            narration                               position  
----------  -  -  --------------------------------------------------------------  ------------
2020-01-02  S     Opening balance for 'Assets:Bank' (Summarization)                 999.00 USD
2020-01-02  S     Opening balance for 'Assets:Bank' (Summarization)                -999.00 USD
2020-01-02  S     Opening balance for 'Equity:Earnings:Previous' (Summarization)      1.00 USD
2020-01-02  S     Opening balance for 'Equity:Earnings:Previous' (Summarization)     -1.00 USD
2020-01-02  S     Opening balance for 'Equity:Initial-Balance' (Summarization)    -1000.00 USD
2020-01-02  S     Opening balance for 'Equity:Initial-Balance' (Summarization)     1000.00 USD
2020-01-03  *     Buy Groceries 2020-01-03                                          -10.00 USD
2020-01-03  *     Buy Groceries 2020-01-03                                           10.00 USD
2020-01-04  *     Buy Groceries 2020-01-04                                         -100.00 USD
2020-01-04  *     Buy Groceries 2020-01-04                                          100.00 USD
beanquery>

However this one does not work

beanquery> select *  FROM #postings OPEN ON 2020-01-03
error: syntax error
| select *  FROM #postings OPEN ON 2020-01-03
|                          ^
beanquery>

If I check at the beanquery/parser/bql.ebnf language definition file then for me it looks, that it icomes already from there, that OPEN ON, CLOSE ON and CLEAR only work in the traditional (not the #table) format

select::Select
    = 'SELECT' ['DISTINCT' distinct:`True`] targets:(','.{ target }+ | asterisk)
      ['FROM' from_clause:(_table | subselect | from)]
      ['WHERE' where_clause:expression]
      ['GROUP' 'BY' group_by:groupby]
      ['ORDER' 'BY' order_by:','.{order}+]
      ['PIVOT' 'BY' pivot_by:pivotby]
      ['LIMIT' limit:integer]
    ;

subselect
    = '(' @:select ')'
    ;

from::From
    =
    | 'OPEN' ~ 'ON' open:date ['CLOSE' ('ON' close:date | {} close:`True`)] ['CLEAR' clear:`True`]
    | 'CLOSE' ~ ('ON' close:date | {} close:`True`) ['CLEAR' clear:`True`]
    | 'CLEAR' ~ clear:`True`
    | expression:expression ['OPEN' 'ON' open:date] ['CLOSE' ('ON' close:date | {} close:`True`)] ['CLEAR' clear:`True`]
    ;

_table::Table
    =
    | name:/#([a-zA-Z_][a-zA-Z0-9_]*)?/
    | name:quoted_identifier
    ;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions