Reports: Ad-hoc database queries

Maintained by Tim at Lone Pine Koala Sanctuary Tim Hunt, at the OU (Perry building) Mahmoud Kassaei
This report plugin allows Administrators to set up arbitrary database queries to act as ad-hoc reports. Reports can be of two types, either run on demand, or scheduled to run automatically. Other users with the right capability can go in and see a list of queries that they have access to. Results can be viewed on-screen or downloaded as CSV.
2325 sites
90 fans

This report, created by The Open University, lets Administrators set up arbitrary SQL select queries that anyone with the appropriate permissions can then run. Reports can be set to be runnable on-demand, or automatically run weekly or monthly.

The results are displayed as a fairly plain HTML table, and can also be downloaded as CSV.

The idea is that this lets you quicly set up ad-hoc reports, without having to create a whole new admin report plugin.


Screenshot #0


Tim at Lone Pine Koala Sanctuary
Tim Hunt (Lead maintainer)
at the OU (Perry building)
Mahmoud Kassaei: Developer
Please login to view contributors details and/or to contact them

Comments RSS


  • Panthers fan
    Wed, 4 Jul 2018, 9:39 PM
    A couple of questions about changing run time of scheduled reports

    For reference, all my ad-hoc scheduled tasks run at 10 minutes after every hour and all reports have the "Scheduled, Daily" option.

    Question 1 - if a report is set to "Scheduled, daily" and it fails to run for some reason at, say, 7:10am, how would I "reset" it so that scheduled tasks can run it again later the same day?

    Question 2 - what is the latest time I can edit a report, and change the time, so that it is still run? For example, if I edit a scheduled report that was scheduled to run at 7:10am and save it at 7:08am, will it be run at 7:10am?

    Just wondering for debugging purposes. Thanks again for a great plugin that, quite frankly, my group could not do without.

  • Tim at Lone Pine Koala Sanctuary
    Wed, 4 Jul 2018, 10:30 PM
    Reports run when cron triggers the scheduled task. That is unlikely to be exactly on the hour.

    I am afraid that the only way to find out exactly how it works is to read the code starting at (It is not particularly complicated.)
  • Picture of Mark Heeling
    Wed, 26 Sep 2018, 3:25 PM
    Hi is it possible to add a extra roll to report_customsql?
  • Tim at Lone Pine Koala Sanctuary
    Wed, 26 Sep 2018, 4:19 PM
    Well, technically you need to ask 'Is it possible to add extra capabilities ...'. The only way to do that is to edit the code. Specifically you would need to add them to this list:

    You also need to remember that these reports live in the System context, and only a few roles are assigned in that context. (E.g. Teacher role only exists inside a particular course, and these reports are outside all courses.)
  • Picture of Naomi Quirke
    Mon, 29 Oct 2018, 12:16 PM
    Since I updated to version 2018080900, I've noticed that the links don't display as links anymore, just as html text. For example I used the code (postgreSQL): select '' || c.fullname || '' "Course"
    Has some setting changed that I need to review?
  • Picture of Naomi Quirke
    Mon, 29 Oct 2018, 12:20 PM
    Oops sorry that didn't work I used the code without the spaces select ' < a h r e f = " % % WWWROOT % % / course / view . php % % Q % % id = ' || CAST (c . id AS VARCHAR) || '">' || c.fullname || '< / a >' "Course"
  • Tim at Lone Pine Koala Sanctuary
    Mon, 29 Oct 2018, 7:10 PM
    Sorry, known issue that we have not yet had time to fix.
  • Picture of Olli Savolainen
    Fri, 23 Nov 2018, 3:27 PM
    Hi. Does this do paging for the query results html table?
  • Tim at Lone Pine Koala Sanctuary
    Fri, 23 Nov 2018, 4:41 PM
    No, by design. There is a hard limit of 5000 rows on what one query can return, so it is just simpler to run the query once and show all the results.
  • Picture of Olli Savolainen
    Fri, 23 Nov 2018, 8:25 PM
    Thanks Tim.
  • Picture of Tim Tarbotton
    Thu, 29 Nov 2018, 5:38 AM
    Hello, I want to setup automatic reports to show a list of students and their activity completion for a specific course, from a specific group or cohort. I know you can run a completion report on a course in moodle but I can't see a way to filter by cohort of group therefore I see 1000's of activity completion records. Will this plugin provide me with a solution to generating custom reports? Appreciate the advice. Tim
  • Picture of Rachel Grzymkowski
    Fri, 30 Nov 2018, 11:24 PM
    Hello. I'm a new user trying to schedule a report to export to a shared drive path/directory. I am receiving an error that it does not exist. Is there any documentation that exist. Also, is there any hope that the hard limit of 5000 on the rows could be raised?
  • Picture of Blair F.
    Wed, 9 Jan 2019, 1:31 AM
    Has anyone written or used a query to search for a string *anywhere* in Moodle? I just can't figure out how to do it.
  • Picture of Jon Scherbatskoy
    Wed, 16 Jan 2019, 4:19 AM
    Is there a way to pick the day I want to have an automatic report run? I have reports that I need every wednesday, others that are needed on the 5th and 20th of each month, etc. Currently it looks like I can only pick every day, 1st of week, 1st of month. Running Moodle 3.5 with Ad-hoc 2018080900.
    Please update so we can schedule automatic running of reports but we can pick the different days to run. It is ok if I have to schedule the same report twice to run once on the 5th and the second copy on the 20th (for example).
  • Tim at Lone Pine Koala Sanctuary
    Fri, 18 Jan 2019, 10:44 PM
    We don't particuarlly need that functionality, so we are unlikely to develop it ourselves. However, if you can find someone to develop it, we are always grateful to receive pull requests.
Please login to post comments