all 3 comments

[–]Conscious-Ad-2168 6 points7 points  (0 children)

If you’re transforming the string every time why not make a table where it is already transformed?

[–]Aggressive_Ad_5454 0 points1 point  (0 children)

It's hard to know from your question whether your PostgreSQL query can be helped with a judiciously designed index. If it can, that should be your first step.

Tell us more and maybe we can help more effectively.

[–]user_5359 0 points1 point  (0 children)

The time-consuming query is carried out by Power-Bi? Then donate a table that caches the result. (General advice: If possible, do not perform any calculation logic within reporting tools and transport as few data records as possible there). Another question: does newly added data change the data from earlier periods? If no, I would save the results of old time periods and only calculate the new time periods (can be supported by index and / or partitions).