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

Cannot use filename in column disambiguation, must use alias #277

Open
redsaz opened this issue Oct 15, 2021 · 1 comment
Open

Cannot use filename in column disambiguation, must use alias #277

redsaz opened this issue Oct 15, 2021 · 1 comment

Comments

@redsaz
Copy link

redsaz commented Oct 15, 2021

Description

When there are two or more tables in a query, and those two tables have an identical column name, the column needs to be disambiguated somehow.

Example 1: In most (all?) SQL DBs, one can use an alias, as shown here:

SELECT low.temperature, high.temperature FROM daily_lows low JOIN daily_highs high ON low.day = high.day;

Example 2: In most SQL DBs (or, at least mysql and postgres), one can use the table name directly:

SELECT daily_lows.temperature, daily_highs.temperature FROM daily_lows JOIN daily_highs ON daily_lows.day = daily_highs.day;

However, in q, only Example 1 works. Being able to refer to the filename to disambiguate columns would help those expecting q to behave similar to other SQL engines.

Steps to reproduce

  1. Create a file, daily_lows:
day,temperature
1,10
2,11
3,12
  1. Create a file, daily_highs:
1,20
2,21
3,22
  1. Query the file with aliases to verify the files work: q-text-as-data -d, -H 'SELECT low.temperature, high.temperature FROM daily_lows low JOIN daily_highs high ON low.day = high.day;'
  2. Query the file without aliases: q-text-as-data -d, -H 'SELECT daily_lows.temperature, daily_highs.temperature FROM daily_lows JOIN daily_highs ON daily_lows.day = daily_highs.day;'

Actual results

The second query fails to find the columns:

query error: no such column: daily_lows.temperature
Warning - There seems to be a "no such column" error, and -H (header line) exists. Please make sure that you are using the column names from the header line and not the default (cXX) column names. Another issue might be that the file contains a BOM. Files that are encoded with UTF8 and contain a BOM can be read by specifying `-e utf-9-sig` in the command line. Support for non-UTF8 encoding will be provided in the future.

Expected results

The second query works just like the first:

10,20
11,21
12,22

Notes

This issue may be a duplicate of #87 "Allow access to the original filename in queries" but I wasn't sure since there was no description.

@harelba
Copy link
Owner

harelba commented Oct 16, 2021

Hi, sorry for the late response. I'm focused on packaging in order to release a new major version 3.0.0 with lots of big changes.

I'll dive into this right after the release is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants