Getting Query Backing a View in Clickhouse

Recently I inherited a clickhouse cluster and needed to look into the query backing a materialized view. Since the view wasn't defined in the code I had to obtain it from clickhouse itself. However I wasn't able to find in the clickhouse cloud UI and a quick google search wasn't helpful either.

Then I remembered that relational databases hold that information inside the information schema tables, so I checked to see if something like that is available in clickhouse. Indeed it is, and here's the query to get the query behind a view:

SELECT
  table_schema, table_name, view_definition
FROM
  information_schema.views;
Share:

If you've come this far with the article you may want to know a thing or two about me if you don't already. You can also read other blog posts or about stuff I've learned recently.

This website is open source. If you've come across a mistake please let me know there. For other types of feedback you can reach out to me through email or social-media.

🚧The website is still under construction!🚧