xtdb icon indicating copy to clipboard operation
xtdb copied to clipboard

Handle duplicate column names in PG wire

Open mbutlerw opened this issue 3 years ago • 2 comments

(from @refset, https://github.com/xtdb/xtdb/issues/2318)

It looks like account.name is being returned twice instead of user.name:

jdt=> SELECT account.name, account.id, user.account_id, user.name FROM account LEFT JOIN user ON account.id = user.account_id WHERE account.name = 'a0';
 name | id | account_id | name 
------+----+------------+------
 "a0" | 0  | 0          | "a0"
 "a0" | 0  | 0          | "a0"
(2 rows)

jdt=> SELECT user.account_id, user.name FROM user;
 account_id |  name  
------------+--------
 0          | "u0a0"
 0          | "u1a0"
 1          | "u2a1"
 1          | "u3a1"
(4 rows)

mbutlerw avatar Nov 28 '22 11:11 mbutlerw

pgwire currently uses open-sql-async and an internal analyser fn to get the col-names out - if it could use the same prepare-ra API as FSQL this would be a lot simpler, but this isn't as easy a refactoring as I'd like, for various reasons. let's include this in the prios rather than me trying to quick-fix it

jarohen avatar Nov 29 '22 11:11 jarohen

I just checked out the current state of this and it now returns an error rather than incorrect result:

jdt=> INSERT INTO docs (_id, foo) VALUES (1, 'bar');
INSERT INTO docs2 (_id, foo) VALUES (1, 'baz');
INSERT 0 0
INSERT 0 0
jdt=> SELECT docs._id, docs2._id FROM docs JOIN docs2 ON docs._id = docs2._id
jdt-> ;
ERROR:  Errors planning SQL statement:
  - Duplicate column projection: xt$id
jdt=> SELECT docs.foo, docs2.foo FROM docs JOIN docs2 ON docs._id = docs2._id
;
ERROR:  Errors planning SQL statement:
  - Duplicate column projection: foo
jdt=> 

That probably means this issue can now be closed in favour of https://github.com/xtdb/xtdb/issues/2318 (which already implies pgwire must work)

refset avatar Jun 21 '24 17:06 refset