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

SELECT field on joined tables gives unexpected undefined #1985

Open
radegran opened this issue Nov 2, 2024 · 3 comments
Open

SELECT field on joined tables gives unexpected undefined #1985

radegran opened this issue Nov 2, 2024 · 3 comments

Comments

@radegran
Copy link

radegran commented Nov 2, 2024

Repro steps

const users =  [{UserId: '1', UserName: 'User'}]
const orders = [{UserId: '1', Text: 'Order text'}]

const expected = alasql(`
  SELECT *
  FROM ? u 
  JOIN ? o 
  ON u.UserId = o.UserId`, 
  [users, orders])

const unexpected = alasql(`
  SELECT UserName,Text 
  FROM ? u 
  JOIN ? o 
  ON u.UserId = o.UserId`, 
  [users, orders])
  
console.log({expected, unexpected}); 
// {
//   expected: [{
//     Text: "Order text",                       <- "Text" field is there ...
//     UserId: "1",
//     UserName: "User"
// }],
//   unexpected: [{
//     Text: undefined,                          <- ... but it is undefined when selected
//     UserName: "User"
//   }]
// }

JSFiddle

https://jsfiddle.net/0nhuqp9f/

@mathiasrw
Copy link
Member

Great bug. nice find.

@psy-duck1
Copy link

Hey there, i'm interested in this issue will you please assign this to me.

@psy-duck1
Copy link

const users =  [{UserId: '1', UserName: 'User'}]
const orders = [{UserId: '1', Text: 'Order text'}]

const expected = alasql(`
	SELECT *
  FROM ? u 
  JOIN ? o 
  ON u.UserId = o.UserId`, 
  [users, orders])

const unexpected = alasql(`
	SELECT u.UserName, o.Text 
  FROM ? u 
  JOIN ? o 
  ON u.UserId = o.UserId`, 
  [users, orders])
  
console.log({expected, unexpected}); 
// {
//  expected: [{
//  Text: "Order text",
//  UserId: "1",
//  UserName: "User"
// }],
// unexpected: [{
//  Text: "Order text",
//  UserName: "User"
// }]
// }

this will resolve the issue as AlasQL doesn't automatically include other columns from the joined tables. Only the explicitly selected columns are returned so if we specify the table it will not give error

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

No branches or pull requests

3 participants