Closed raddevon closed 5 months ago
@raddevon The issue was with the []
, please explicitly type your empty arrays for now.
I have found the following workaround for this issue. In order to either add Doc to the queue at position 2 or add position 2 to his positions if he is already in the queue (clone the Doc!), you can do this:
with
doc := assert_single((
select Person
filter .name = 'Doc'
)),
queue := (
select Queue {
id,
doc_position := (
select .people {
ps := (@position, Queue.id)
}
filter .id = doc.id
)
}
filter .id = <uuid>$queue_id
),
ps := assert_single(queue.doc_position.ps.0) ?? [],
result := (update queue
set {
people += (
select doc {
@position := ps ++ [2]
}
)
})
select assert_single(result)
I think it is rather noisy so if you have a better solution, please post!
Also I do not really understand why I get additional results from other Queues if I do not add the Queue.id
to the tuple (and later throw it away by only using .0
). If someone could explain this, that would also be great!
Steps to Reproduce:
insert Person {name := 'Doc'};
)insert Queue {people := (select Person {@position := [1]})};
)update Queue set {people += (select .people {@position := (@position ?? []) ++ [2]} filter .name = 'Doc')};
Schema:
A single person may have multiple positions in a queue. Imagine a presale for event tickets that allows each person to purchase multiple tickets, but they must obtain a new position in the queue for each ticket. (I never said it was a well-designed event presale 😅) The goal here is to come up with a query that, without knowing whether a given person is already in the queue, could either add them to it with the desired position or add the desired new position to their existing
position
link property array. My idea was to coalesce the existing link property value with an empty set and concatenate an array with the new value with the result. That ended in an ISE: