0

Here's my query for reference:

with weekly_periods as (
  select ticket_id,
         start_time_in_minutes_from_week,
         raw_delta_in_minutes,
         schedule_id,
         week_number,
         greatest(0, start_time_in_minutes_from_week - week_number * (7*24*60)) as ticket_week_start_time,
         least(start_time_in_minutes_from_week + raw_delta_in_minutes - week_number * (7*24*60), (7*24*60)) as ticket_week_end_time
  from ticket_solved_time, unnest(generate_array(0, floor((start_time_in_minutes_from_week + raw_delta_in_minutes) / (7*24*60)), 1)) as week_number
)

I have tried generate_series and also the array functions, but I am not too familiar with the PostgreSQL syntax.

3
  • It sounds like you answered your own question, right? The function is called generate_series in PostgreSQL. What is it that you are trying to do? Please provide sample input data and expected output. Commented Aug 2, 2018 at 18:59
  • Did you tried just ... from ticket_solved_time, generate_series(0, floor((start_time_in_minutes_from_week + raw_delta_in_minutes) / (7*24*60)), 1) as week_number? Note that the step value 1 is default in this case so it could be omitted. Commented Aug 2, 2018 at 19:09
  • I have tried exactly that and it causes an error. Commented Aug 2, 2018 at 19:32

1 Answer 1

2

You can use something like below in PostgreSQL to generate random integer array for example

select array_agg(round(random() * (max - min)) + min) 
from generate_series(0, elements)     

Note: generate_series function has many signatures that allow you to control what you will get out

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.