Skip to content

Add RIGHT() and LEFT() SQL string functions #590

Closed
Stars1233/alasql
#23

Description

@mathiasrw

Add RIGHT() and LEFT() string functions from SQL

Spawned from #588

Activity

  1. mmaraz commented on May 6, 2017

    @mmaraz

    +1

  2. garynewelluk commented on Oct 13, 2019

    @garynewelluk
    Contributor

    Presumably these functions only work on varchars and it throws an error if the length supplied is greater than the length of the returned value....

    ie

    create table myTable (id int, name varchar(10))
    
    insert into myTable (id, name) values (1,'test')
    
    select left(name,3) from myTable  returns 'tes'
    select right(name,3) from myTable returns 'est'
    select left(name,5) throws error
    select right(name,5) throws error
    select left(name,0) throws error
    select right(name,0) throws error
    
  3. rrameshkumar76 commented on Sep 21, 2023

    @rrameshkumar76
    Contributor

    @mathiasrw Is the issue here missing left and right or the error given below ?

    it('A) left right', function() {
    		var data = [{prop: 'abcdef'}];
    		var res = alasql('SELECT left(prop,1) FROM ? ', [data]);
    		console.log(res);
    
    	});
    

    This throws error

    SELECT left(prop,1) FROM ? 
    -------^
    Expecting 'LITERAL', 'BRALITERAL', 'EOF'
    

    If this issue is still valid let me know , I can take a look

  4. mathiasrw commented on Sep 21, 2023

    @mathiasrw
    MemberAuthor

    Yep. Still relevant.

  5. rrameshkumar76 commented on Sep 21, 2023

    @rrameshkumar76
    Contributor

    @mathiasrw I guess the tricky part is left and right are keywords else where in left/right joins.

    if i add a function with slightly diff name like leftstring/rightString they just work versus left/right.

    I will see what can be done about this

  6. mathiasrw commented on Sep 22, 2023

    @mathiasrw
    MemberAuthor

    Yes.

    You will need to add the keywords specificly as part of acceptable function names, this way it becomes valid to have those tokens as function names instead of just strings (right now the token LEFT will only be acceptable in relation to join)

  7. added a commit that references this issue on Nov 19, 2025
    c554575
  8. added a commit that references this issue on Nov 20, 2025
    f57ad42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions