Skip to main content
Question

How to run a custom data export query?


Forum|alt.badge.img+5

Apologies if this is a basic question.

I’m recording a custom subscriber attribute called 'charity’ against my customers, which stores the name of a charity they have chosen, to which I am going to donate 10% of the subscription revenue I get. So now, I’m trying to create a report of total revenue subscription in the past year, grouped by the charity, so I know how much to donate to who.

I figured based on this forum question that I can achieve this using scheduled data exports. So, I have just finished setting up a scheduled data export integration to a Google Cloud bucket.

I see in the documentation lots of examples of custom queries in Postgres, which looks ideal. But this is where I’m stuck. I assume these queries can be used to modify the data I get in the scheduled data export - but where do I enter the query SQL? eg I can’t see anywhere in the query integration settings where it says something like 'run this query’. I must be misunderstanding how this works.

3 replies

Forum|alt.badge.img+5
  • Author
  • Member
  • 9 replies
  • March 25, 2025

After a good night’s sleep, and after getting my first data export, I think I get it - I think you’re supposed to feed these .csv files into your own sql database and then you run the example queries on the database (?)


kaitlin
RevenueCat Staff
Forum|alt.badge.img+6
  • RevenueCat Staff
  • 386 replies
  • March 31, 2025

Hi ​@James Allen,

Yes, you’re exactly right! There’s any number of database services that you could use - RevenueCat will export to Amazon, Google Cloud, and Azure Blob (Microsoft), who all have their own version of a SQL tool and will likely make it easy to feed the CSV file in, but you can also find other open-source or third party services that you may like as well. 

Let us know if we can elaborate at all!


Forum|alt.badge.img+5
  • Author
  • Member
  • 9 replies
  • April 4, 2025

Thanks ​@kaitlin, I ended up using a simple sqlite database. In case this is useful for future readers, this is how I did it on mac:

brew install sqlite3
sqlite3 ./report.db
sqlite> DROP TABLE transactions;
sqlite> .mode csv
sqlite> .separator ,
sqlite> .import transactions.csv transactions

Then I can run queries. Some of the syntax in the examples have to be translated from Postgres to Sqlite, for example changing json_extract_path_text to JSON_EXTRACT. So to get a count of which of my customers has chosen each charity:

SELECT 
  COUNT(*), 
  JSON_EXTRACT(custom_attributes, '$.charity.value') AS charity 
FROM customers 
WHERE instr(custom_attributes, 'charity') > 0 
GROUP BY charity;

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings