Skip to content

Support calculated(virtual) fields in the query builder #2359

Description

@maxpatiiuk

The Sp6 query builder supports querying on calculated fields.
The Sp7 query builder appears to not support them.

From @grantfitzsimmons:

Example Calculated Fields:

Preparation

  • actualCountAmt
  • isOnLoan

Loan #1193

  • totalPreps
  • totalItems
  • unresolvedPreps
  • unresolvedItems
  • resolvedPreps
  • resolvedItems

Accession #4802

  • totalCountAmt
  • actualTotalCountAmt
  • actualCountAmt
  • collectionObjectCount
  • preparationCount

Exchange Out, Disposal, Gift, and Deaccession #2521

  • totalPreps
  • totalItems

image

Reported by CSIRO

From Asana: https://app.asana.com/0/1201972579963460/1203248913489633

See also #1193

Activity

  1. benanhalt commented on Oct 27, 2022

    @benanhalt
    Contributor

    Probably using database views would be the most principled way of doing this. Then Specify queries and other APIs could access these fields in a consistent way as if they were normal fields. There would need to be a way to add the views to the database. Presumably this could be done using custom Django migrations. Also there would need to be some way to cause the backend to use the views when retrieving data from such tables but continue to issue updates and inserts to the underlying bare tables. MySQL does support updatable and insertable views, but I wouldn't bet on them being fit for use.

  2. added
    2 - QueriesIssues that are related to the query builder or queries in general
    on Jul 2, 2023
  3. changed the title [-]Support calculated fields in the query builder[/-] [+]Support calculated(virtual) fields in the query builder[/+] on Sep 30, 2023
  4. maxpatiiuk commented on Sep 30, 2023

    @maxpatiiuk
    MemberAuthor

    From @grantfitzsimmons:

    This includes isOnLoan and actualCountAmt

    The "Is on Loan" indicator that you can see in the preparation section of a form is not currently a field option in the query builder:

    image

    Requested By: Dan Baker at CSIRO (Asana)

  5. added
    1 - EnhancementImprovements or extensions to existing behavior
    and removed
    1 - RequestA request made by a member of the community
    on Dec 20, 2024
  6. bhumikaguptaa commented on Sep 3, 2025

    @bhumikaguptaa
  7. specifysoftware commented on Sep 12, 2025

    @specifysoftware
    Collaborator

    This issue has been mentioned on Specify Community Forum. There might be relevant details there:

    https://discourse.specifysoftware.org/t/count-rows-from-the-query-builder/2787/2

  8. specifysoftware commented on Dec 1, 2025

    @specifysoftware
    Collaborator

    This issue has been mentioned on Specify Community Forum. There might be relevant details there:

    https://discourse.specifysoftware.org/t/show-calculated-virtual-fields-in-the-statistics-page/3178/1

  9. grantfitzsimmons commented on May 14, 2026

    @grantfitzsimmons
    Member

    We had a crash today in PRI's database due to the virtual count amount fields being present in a query, but Specify 7 being unable to return them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

1 - EnhancementImprovements or extensions to existing behavior2 - QueriesIssues that are related to the query builder or queries in generalSeparationFrom6

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions