skip to Main Content

I have a file that contains multiple select queries.
I run these on a weekly basis to generate internal company reports

For example (these are not the actual queries):

-- Select number of users
SELECT count(id) from users;

-- Select number of active users
SELECT count(id) from users where active = true;

-- Select number of logins this week
SELECT count(id) from users where last_login > current_date - interval '1 week';

--- etc...

Is there a way, in DataGrip, to run all of these queries and export them to csv files?

I am able to run each query and then export the dataset, however, is a time consuming process doing this one by one.

2

Answers


  1. I believe there isn’t a convenient way.

    As a workaround, will combining all queries into one solve your problem?
    It’s not the most elegant way, but you’ll get all the data displaying in a single result:

    SELECT
        (SELECT COUNT(id) FROM users) AS "Number of users",
        (SELECT COUNT(id) FROM users WHERE active = TRUE) as "Number of active users",
        (SELECT COUNT(id) FROM users WHERE last_login > CURRENT_DATE - INTERVAL '1 week') as "Number of logins this week"
    
    Login or Signup to reply.
  2. It’s possible. Select all queries and then use Execute To Files:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search