3

I want to select a saved query as datasource in my charts but Superset only displays views and tables as data sources.

What is required to select a query as a datasource?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ranga B.
  • 627
  • 10
  • 20

2 Answers2

13

In SQL Lab, after you execute the query, you have an option to visualize the query, and then you are able to create a chart using the query, save it, and use it in a Dashboard once saved. Not very intuitive, I had to look for it too ;-)

Ana GH
  • 1,397
  • 1
  • 9
  • 19
  • Thank you. But this approach has the disadvantage that modifications to the query result in another query name (the id of the part that supersets adds changes) and changes are to reflected into any charts that use the query already. – Ranga B. Feb 02 '21 at 16:15
  • 1
    Yep, I haven't found any other way to do it. Maybe someone else knows how to do it, but I don't think it's implemented yet. – Ana GH Feb 02 '21 at 16:19
  • Do you use Version 1.0 of Superset or any previous version? My expectation is that Superset V1.0 brought some improvements regarding this behaviour. Still on V0.37.2 – Ranga B. Feb 02 '21 at 16:21
  • 1
    Last I tested, I used 0.38, but I don't think I have seen anything related to this in the 1.0 announcement (I've just skipped over the change log, so don't take my word on it) – Ana GH Feb 02 '21 at 16:25
  • 3
    Once you've created the first virtual dataset in SQL Lab you can simply edit the dataset to update the SQL, and the change will be reflected in all charts that use the virtual dataset. – Beto Dealmeida Feb 02 '21 at 17:23
  • Yes @RangaB., with version 1.0 or 1.1 of Superset this has changed a bit, but not much, you can use SQL Lab to build Virtual Datasources with your query, to use the same as physical tables/views in your database, look for more information about it in Superset documentation. – Ana GH Nov 08 '21 at 18:02
1

IDK if it is still relevant but you can query the dataset. This can be very useful when you're doing nested queries. You can do this with the help of jinja templating. make sure you have enabled them in the config file

select * from {{dataset(233)}}
Machine
  • 103
  • 7