GitHub user dosubot[bot] added a comment to the discussion: Error: column 
reference "session_id" is ambiguous while filtering bar chart

<!-- Greeting -->
Hi @prakhar2003! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the 
superset team.

<!-- Answer -->
This error happens because your SQL query returns two columns named 
session_pk_id (one from each table), so when Superset generates a filter like 
WHERE session_pk_id = '...', the database doesn't know which one you mean. 
Superset tries to de-duplicate columns by adding suffixes (like 
session_pk_id__1), but these are just labels in the result set—they aren't 
valid SQL column names you can use in filters, and table-qualified names (like 
perf.session_pk_id) aren't supported in filters for virtual datasets created 
from SQL Lab queries, which is why you see errors like "relation 'perf' does 
not exist" when you try them.

The only reliable fix is to explicitly alias your columns in the SQL query you 
use to define the dataset, so each column has a unique name. For example:

```sql
SELECT
  perf.session_pk_id AS perf_session_pk_id,
  session.session_pk_id AS session_session_pk_id,
  -- add other columns you need, each with a unique alias
  ...
FROM network_performance AS perf
INNER JOIN test_session AS session
  ON perf.session_pk_id = session.session_pk_id
```

Then, in your chart filters, use the unique column names (like 
perf_session_pk_id or session_session_pk_id). This avoids ambiguity and makes 
filtering work as expected. This is a known limitation of how Superset handles 
virtual datasets and column mapping—there isn't a built-in way to reference 
ambiguous columns or use table-qualified names in filters for these datasets at 
this time. For more technical details, see the backend code that manages 
dataset columns and filtering logic 
[here](https://github.com/apache/superset/blob/050ccdcb3dd84f3ae6e301d61021e72474e754d7/superset/connectors/sqla/models.py).


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/81f94399-4699-4a6c-92c7-b777905c1fb7?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/81f94399-4699-4a6c-92c7-b777905c1fb7?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/81f94399-4699-4a6c-92c7-b777905c1fb7?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/81f94399-4699-4a6c-92c7-b777905c1fb7?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/81f94399-4699-4a6c-92c7-b777905c1fb7?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/81f94399-4699-4a6c-92c7-b777905c1fb7?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/81f94399-4699-4a6c-92c7-b777905c1fb7?feedback_type=other)</sup>&nbsp;&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Sh
 are on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/34010)

GitHub link: 
https://github.com/apache/superset/discussions/34010#discussioncomment-13627741

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to