Posts

Showing posts from November, 2022

How to round minute in SQL (Databricks) or PostgreSQL to nearest hour

Image
To round minute to nearest hour you have to use: date_trunc('hour', 'YOUR DATE_TIME' + interval '30 minute') DATE_TRUNC function rounds to the hour that appears in the string, so if we add +30 minutes when you have a HH:30+, this should round to next hour and when you have HH:-30 this will round to the hour that appears in your string. So if hour is: '2022-11-21 00:05:00', the new time will be: '2022-11-21 00:00:00' But if hour is: '2022-11-21 00:55:00', the new time will be: '2022-11-21 01:00:00' Between 0 and 30 minutes: Rounds to the same hour in your date_time Between 31 and 59 minutes: Rounds to the next hour based on your date_time

Find() query a mongoDB aggIndex with LIKE operator containing pipe "|" character

Image
Use something like this: db.getCollection("YOURTABLE").find( { aggIndex : /^FIRST_INDEX \| SECOND_INDEX.*/i } ); When we have a pipe character: | and we try to find() something with this pipe, the mongoDB shell understand it's like an OR statement. So we just have to add "\" before the pipe |. For LIKE I used /^TEXT.*/i and it works great! Using LIKE (SQL): aggIndex LIKE 'FIRST_INDEX|SECOND_INDEX%'; LIKE in MongoDB: aggIndex : /^FIRST_INDEX \| SECOND_INDEX.*/i The /^ determines the beginning. The .*/i determines that we shall have more characters after this point, independently if they are lower or upper case. It works for deleteMany() too.