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

Results table names all additional unnamed columns "?column? (1)" and conflates their output #1276

Open
1 task done
kit-transue opened this issue Jan 11, 2024 · 1 comment
Labels

Comments

@kit-transue
Copy link

Describe the bug

If a query returns more than two unnamed columns, the results table mistakenly uses the values from only the last column for all the unnamed columns after the first.

To Reproduce
Steps to reproduce the behavior:

  1. In a .sql file (the default connection log is excellent)
  2. Add the SQL: "SELECT 1, 2, 3;"
  3. Run on a connection
  4. Observe: results table names the column headers: "?column?", "?column? (1)", "?column? (1)"
  5. Observe: results row shows values: 1, 3, 3. (The first 3--in the second column--is unexpected)

Expected behavior

  • The results table shows three column headers: "?column?", "?column? (1)", "?column? (2)"
  • The single results row shows values 1, 2, 3.

Screenshots
Attached showing "3" as wrong value in middle column of results table; column header wrong for last column in results table.

Desktop (please complete the following information):

  • SQLTools Version: v0.28.1
  • VS Code Version: 1.85.1
  • OS: macOS (local w/ DevContainer); GitHub Codespace
  • Driver:
    • PostgreSQL/Cockroach 0.5.2
  • Database version:
    • PostgreSQL v16.1
SQLTools-3unnamed-columns
@kit-transue
Copy link
Author

This is a result of PostgreSQL's naming of anonymous columns or aggregate functions:

postgres=# select sum(a), sum(b), sum(c) FROM (select 1 a, 2 b, 3 c);
 sum | sum | sum 
-----+-----+-----
   1 |   2 |   3
(1 row)

Other engines may generate distinct column names with aggregate functions:

sqlite> select sum(a), sum(b), sum(c) FROM (select 1 a, 2 b, 3 c);
sum(a)|sum(b)|sum(c)
1|2|3

I don't know if the columns names will always be distinct, and the error can be induced by forcing the columns to collide:

SELECT 1 AS count, 2 AS count, 3 AS count;
SQLTools-SQLite-forced-column-collision

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

No branches or pull requests

1 participant