Skip to content

UNION not returning correct result #1415

Closed

Description

@umquat

AlaSQL is based on unpaid voluntary work. Thank you for taking the time to make it better.

Question about how to ...

Something is not working as expected:

  • Describe the problem

    UNION does not work.

  • Provide code that replicates the problem

data1=[{a:'abc'},{a:'xyz'}]
data2=[{a:'123'},{a:'987'}]

alasql("select * from :a union select * from :b",{a:data1,b:data2})

--- FF 95.01 Linux

[
  {},
  {},
  {
    "a": "abc"
  },
  {
    "a": "xyz"
  }
]

alasql.version
"1.7.3-develop-0be167bcundefined"

----- Chrome 97.0 Linux


[
    {},
    {},
    {
        "a": "abc"
    },
    {
        "a": "xyz"
    }
]

alasql.version
'1.7.3-develop-0be167bcundefined'

---- Node


> data1=[{a:'abc'},{a:'xyz'}]
[ { a: 'abc' }, { a: 'xyz' } ]
> data2=[{a:'123'},{a:'987'}]
[ { a: '123' }, { a: '987' } ]
> 
> alasql("select * from :a union select * from :b",{a:data1,b:data2})
[ {}, {}, { a: 'abc' }, { a: 'xyz' } ]
> alasql.version
'1.7.3-develop-0be167bcundefined'

---- How does it work in sqlite3

sqlite> create table one(a text);
sqlite> create table two(a text);
sqlite> insert into a values('abc'),('def');
sqlite> insert into two values('xyz'),('123');
sqlite> select * from one union select * from two;
123
abc
def
xyz



Maybe I'm using alasql incorrectly? I tried looking at some documentation in the wiki but the section on union is quite spartan.

Anyway, thanks a lot!

Activity

  1. mathiasrw commented on Sep 24, 2022

    @mathiasrw
    Member

    It should work - but does not...

  2. Tisamu commented on Oct 13, 2022

    @Tisamu

    I would like to take the issue, could it be assigned to me ? 👍
    ( Here is a correct jsfiddle relative to this issue btw : http://jsfiddle.net/7pdhe9ng/ )

    Thanks !

  3. mathiasrw commented on Oct 14, 2022

    @mathiasrw
    Member

    Sure!

  4. mathiasrw commented on Oct 26, 2022

    @mathiasrw
    Member

    @Tisamu Any ideas on how to approach this issue?

  5. Tisamu commented on Oct 26, 2022

    @Tisamu

    Hello, sorry for giving no news.

    Yep I've debugged a bit and it seems that the params of the first table are not passed to the union compilation method.

    I'm still trying to understand all the compilation process of the query so I'm not sure where is the problem precisely.

    I'm gonna work more on it this weekend. 😄

  6. mathiasrw commented on Oct 27, 2022

    @mathiasrw
    Member

    I have not dived into where this might be - but a few hints to debug: Its often good to understand the compiled function that is constructed to execute the query.

    Idea:

    Replicate the problem in the CLI version of alasql.

    node bin/alasql-cli.js 'select * from @[{x:true}, {x:3}] UNION select * from @[{x:false}, {x:9}]'
    [
      {},
      {},
      {
        "x": true
      },
      {
        "x": 3
      }
    ]
    

    In the file dist/alasql.fs.js >THIS FILE WILL BE OVERWRITTEN IF YOU yarn build OR yarn test!< you find where the compiled function to be executed is created.

    It could be here forexample

    image

    Then you run your CLI command with the inspect flag

    node --inspect-brk bin/alasql-cli.js 'select * from @[{x:true}, {x:3}] UNION select * from @[{x:false}, {x:9}]'
    

    Then you open chrome and go to chrome://inspect/#devices and click "inspect"

    image

    Now click here to start running

    image

    Then - if you placed the debugger; correctly you can inspect and follow what is happening. Happy hunting.

    (nope - the place I inserted the debugger; did not stop the execution meaning that its not the right place...)


    Please remember to move any changes to the proper files in src/ folder. Too many times have I found a fix and forgot I was live editing in the build destination and had to redo the details.

  7. Tisamu commented on Oct 27, 2022

    @Tisamu

    Nice ! Thanks for the tips. 😄

  8. changed the title [-]Problems with the UNION :)[/-] [+]UNION not returning correct result[/+] on Oct 27, 2022
  9. Tisamu commented on Nov 3, 2022

    @Tisamu

    Well, sorry but I've a bit busy those weeks, not sure if I will be able to fix it soon. ☹️

    Feel free to un-assign me the issue if someone else wanna take it.

  10. mathiasrw commented on Nov 3, 2022

    @mathiasrw
    Member

    Thank you for leaning in. Let me know if you leant something you want to share with others.

  11. mathiasrw commented on Dec 27, 2022

    @mathiasrw
    Member

    Any luck @Tisamu ?

  12. added a commit that references this issue on Feb 6, 2023
  13. added a commit that references this issue on Jul 11, 2024
    4287740
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions