This page provides information about standards and guidelines for queries to the CUL FOLIO Canned Reports Directory. 
Some of these standards are adapted from the Open Library Foundation's FOLIO Analytics report repository.


Easy Access to Report Filters

Most queries include parameters that allow those running the reports to adapt the result set to their needs. For instance, if you are 
interested in a report showing loan activity for one library location, you can include that location in the parameters to filter your results.


Filter parameters are include at the top of the query in the WITH statement. For example, 

WITH parameters AS (
SELECT
/* enter invoice payment start date and end date in YYYY-MM-DD format */
'2021-07-01' :: DATE AS start_date,
'2022-06-30' :: DATE AS end_date,
/* enter fund group name as 'Central, Humanities, Area Studies, Rare & Distinctive, Law, Sciences, or Social Sciences' */
''::VARCHAR AS fund_group_filter,
/* enter one or more fund codes separated by commas, as in 'math, music' */
''::VARCHAR AS fund_code_filter,
/* enter one or more fund types separated by commas, as in 'restricted, unrestricted' */
''::VARCHAR AS fund_type_filter,
),

Naming Queries

All canned reports developed for the CUL FOLIO Analytics repository are coded with "CR"
followed by a 3-digit number and a short title with words separated by underscores,
as shown in these examples:

* CR104 claims_returned
* CR123 open_orders
* CR130 fund_expenditures_by_po_line


Including a README.md file

Each canned query must be submitted with an associated README.md file. The README.md file
documents the purpose of the query, lists the main tables used in the query, and provides
instructions for using the query.


SQL Style

Structuring a Query

  1. header comment section
  2. parameters (using WITH statement)
  3. additional WITH statements to label subqueries (see services_usage query for example) - optional
  4. primary query - example of basic structure
    1. SELECT
    2. FROM
    3. WHERE
    4. ORDER BY
  5. (add link to good PostgreSQL dictionary)

Details on Specific Strategies