Skip to content

SQL ADD and REMOVE operators are not supported on lists #822

Closed

Description

@lvca

This part was totally missing in the SQL engine, and also from OrientDB... Instead of using ADD and REMOVE, we're going to use the more natural syntax with + and - to respectively add and remove element from a collection.

Same for += and -=. Exampls:

insert into test set listStrings = ['this', 'is', 'a', 'test'], listNumbers = [1,2,3]"
update test set listStrings += '!', listNumbers += 9"

update test set listStrings = listStrings + '!', listNumbers = listNumbers + 9"

The same will work with maps:

insert into test set map = {'name':'Jay'}
update test set map += { 'last': 'Miner'}
update test set map += [ 'country', 'USA']

update test set map -= { 'last': 'Miner'} // REMOVE ALL THE ENTRIES THAT MATCH BOTH KEY AND VALUE PAIRS
update test set map -= [ 'country' ] // TO REMOVE BY KEY, JUST USE COLLECTION OF KEYS

Activity

  1. self-assigned this
    on Feb 2, 2023
  2. added
    enhancement
    on Feb 2, 2023
  3. added this to the 23.2.1 milestone on Feb 2, 2023
  4. modified the milestones: 23.2.1, 23.1.2 on Feb 2, 2023
  5. topofocus commented on Feb 3, 2023

    @topofocus

    Maps got a add functionality in the past

    update #{rid} set #{map}.`#{key}` = #{value}
    

    adds the key/value-pair to a embedded map

    works even with

    update #17.0 set a_map.{backtick}10.4.2023{backtick} = "sometext"

    implemented it recently in the ruby-adapter

    I wanted to ask, how to add date-values as key to a map.
    This is hopefully supported after the changes

  6. lvca commented on Feb 3, 2023

    @lvca
    MemberAuthor

    I wasn't sure that syntax taken from OrientDB was still working! Maps, by choice, can only have strings as keys. You could convert the date->long->string, like "232723723723723". Or by doing the .toString() to a LocalDateTime produces a string in, I believe, the ISO format.

  7. topofocus commented on Feb 3, 2023

    @topofocus

    Thats interesting. Thanks for clarification.

  8. topofocus commented on Mar 7, 2023

    @topofocus

    The case seems not completely solved:

    The Map is exchanged, not updated:

    s = Strategie.last    => #244:1
    s. default
     => 
    {:GLE=>{:"100K"=>6},                                                                            
     :UBaE=>{:"100K"=>6},                                                                           
     :F=>{:"50K"=>9},                                                                               
     :UBBE=>{:"100K"=>6},                                                                           
     :GE=>{:"100K"=>10}}                                                                            
    update #244:1 set default.F += { '100K': 14 } 
     => {:count=>1}                           
    s= s.refresh
    s.default
     => 
    {:GLE=>{:"100K"=>6},                                                                                                
     :UBaE=>{:"100K"=>6},                                                                                               
     :F=>{:"100K"=>14},            <<---  what happened to the :"50K" entry?                                                                                     
     :UBBE=>{:"100K"=>6},                                                                                               
     :GE=>{:"100K"=>10}}         ``
    

    The expected output:

    {:GLE=>{:"100K"=>6},                                                                                                
     :UBaE=>{:"100K"=>6},                                                                                               
     :F=>{ :"50K" => 9, :"100K"=>14},                                                                                       
     :UBBE=>{:"100K"=>6},                                                                                               
     :GE=>{:"100K"=>10}}         ``
    

    Or do I miss something?

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

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions