Can someone kindly tell how to use custom sql feature in metric field in charts? Is is similar to writing sql queries in SQL editor in superset? Can this feature work with postgresql?

Comment From: issue-label-bot[bot]

Issue-Label Bot is automatically applying the label #question to this issue, with a confidence of 0.88. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Comment From: betodealmeida

The custom SQL allows you to define a metric using any valid expression for the DB you're targeting, and it works with all DVs. For example, if you're using Postgres with the GIS extension you could define a metric that is the area of a given geometry by using the following expression in the custom SQL tab:

ST_Area(geom)

When clicking "Run Query" Superset will compose a query that would look like:

SELECT ST_Area(geom) AS `ST_Area(geom)`
...

You can inspect the query generated by going into the hamburger menu in the top right and clicking "View query":

Screen Shot 2019-12-03 at 2 21 35 PM

Comment From: hemantaggarwal

Thanks for the detailed explanation.

Comment From: Yaswanth-Perumalla

How to display columns with alias names in raw records and also how to write a custom SQL query. If I write like a normal SQL query(select customer_id as cid), it is showing like Expected text or file-like object, got . If I try to edit the label, its getting saved with original name. Screenshot 2022-11-18 at 3 44 39 PM

Comment From: Jayen16

How to display columns with alias names in raw records and also how to write a custom SQL query. If I write like a normal SQL query(select customer_id as cid), it is showing like Expected text or file-like object, got . If I try to edit the label, its getting saved with original name. Screenshot 2022-11-18 at 3 44 39 PM

try use case statement.. if you want to have the sub queries in custom sql, create a dataset in sql lab