EvgSkv / logica

Logica is a logic programming language that compiles to SQL. It runs on DuckDB, Google BigQuery, PostgreSQL and SQLite.
https://logica.dev
Apache License 2.0
1.89k stars 95 forks source link

how to express array_agg(x order by t)? #181

Closed jiamo closed 3 years ago

jiamo commented 3 years ago

In such query

GroupEvents1(user_pseudo_id, events? List= custom_event_name) distinct :-
    Events(user_pseudo_id:, custom_event_name:, event_timestamp:);

I want to get events with order by event_timestamp still find no answer in document?

It will be the same situation in Functional aggregation:

GroupEvents2(user_pseudo_id) List=  custom_event_name  :-
    Events(user_pseudo_id:, custom_event_name:, event_timestamp:);
EvgSkv commented 3 years ago

This is done with Array aggregate operator. I've updated tutorial to mention it.

In your Functional example it would be like so:

GroupEvents2(user_pseudo_id) Array= event_timestamp -> custom_event_name :-
    Events(user_pseudo_id:, custom_event_name:, event_timestamp:);

Let me know if you have further questions.

jiamo commented 3 years ago

Thanks.