Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

join fails when both sides have column named "source" #5015

Open
2 tasks done
priithaamer opened this issue Nov 20, 2024 · 2 comments
Open
2 tasks done

join fails when both sides have column named "source" #5015

priithaamer opened this issue Nov 20, 2024 · 2 comments
Labels
bug Invalid compiler output or panic

Comments

@priithaamer
Copy link

priithaamer commented Nov 20, 2024

What happened?

When joining together two tables where both tables contain column named source, compile fails with Ambiguous name error.

I've tried to wrap the column name with whatever i could come up, even good old backtick does not help.

PRQL input

prql target:sql.postgres

let a = (
  from events_a
  select {
    event_id,
    source,
  }
)

let b = (
  from events_b
  select {
    event_id,
    source,
  }
)

from a
join b (==event_id)
select {
  event_id = a.event_id,
  source_a = a.source,
}

SQL output

prql target:sql.postgres
Ambiguous name

Expected SQL output

No response

MVCE confirmation

  • Minimal example
  • New issue

Anything else?

Smallest example i could come up with is to join table with itself

prql target:sql.postgres

let a = (
  from events_a
  select {
    event_id,
    source,
  }
)

from a
join a (==event_id)
select {
  event_id = a.event_id,
}
@priithaamer priithaamer added the bug Invalid compiler output or panic label Nov 20, 2024
@priithaamer priithaamer changed the title join fails when both sides with column named "source" join fails when both sides have column named "source" Nov 20, 2024
@max-sixty
Copy link
Member

Yes, nice example. What should source be in the final result though — from a or b?

Would we instead want to join on event_id and source?

@priithaamer
Copy link
Author

Yes, nice example. What should source be in the final result though — from a or b?

Would we instead want to join on event_id and source?

Hi, thanks for the reply. In final result it should work the same way it does if you rename source to anything else. If i rename source to source2 it works. It looks like something somewhere inside PRQL considers source special to have it break. It is not listed under reserved keywords though.

So when this fails:

prql target:sql.postgres

let a = (
  from events_a
  select {
    event_id,
    source,
  }
)

from a
join a (==event_id)
select {
  event_id = a.event_id,
}

This compiles just fine:

prql target:sql.postgres

let a = (
  from events_a
  select {
    event_id,
    source2,
  }
)

from a
join a (==event_id)
select {
  event_id = a.event_id,
}

into:

WITH a AS (
  SELECT
    event_id,
    source2
  FROM
    events_a
)
SELECT
  table_0.event_id
FROM
  a
  JOIN a AS table_0 ON a.event_id = table_0.event_id

-- Generated by PRQL compiler version:0.13.2 (https://prql-lang.org)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Invalid compiler output or panic
Projects
None yet
Development

No branches or pull requests

2 participants