[Solved] Insert max numeric value in Postgres column

There are no built-in features to limit numeric values in the described manner. You can create and use a function to implement this behavior: create or replace function limited_numeric(val numeric, prec int, scale int) returns numeric language sql immutable as $$ select least(mx, val) from ( select format(‘%s.%s’, repeat(‘9’, prec- scale), repeat(‘9’, scale))::numeric as mx … Read more

[Solved] Backup/Restore on CloudSQL instances

Here I address you questions: 1. Any way to check the size of existing databases in CloudSQL instances? Yes, there is. This depends on the database engine you are using(mysql, postgres or mssql) For mysql, you can run: SELECT table_schema “DB Name”, ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) “DB Size in MB” FROM … Read more

[Solved] I have a table with a status however I want it to change status every 10 minutes. I’m using Postgresql

I can see what you’re after although there is a big omission: What happens when the status has reached ‘Z’ and it is time to update? More on that later. Your request has 2 components, actually getting a process to run and a rolling update procedure (script) for the status. Well, Postgres has no native … Read more

[Solved] Get a list of requests

Introduction Write an introduction on Get a list of requests Solution Code Solution Get a list of requests with maxes as (select client_id, max(calls.call_datetime) latest_call from calls group by client_id) select tasks.client_id, title from tasks inner join maxes on maxes.client_id = tasks.client_id where created_datetime > maxes.latest_call If I understood correctly, this should be it 0 … Read more

[Solved] PostgreSQL query to split based on Strings & Concatenate them into new individual columns

Use string_to_array to split the string into multiple elements that can be accessed individually: select rules[1] as rule_1, rules[2] as rule_2, rules[3] as rule_3, rules[4] as rule_4, rules[5] as rule_5, rules[6] as rule_6 from ( select string_to_array(rules, ‘|’) as rules from rulebook ) t 1 solved PostgreSQL query to split based on Strings & Concatenate … Read more

[Solved] COUNT and GROUP BY doesn’t works as expected [closed]

What exactly you want to count? Only consumed? Or consumed by goal? If the second option, you need group by statment. SELECT count(consumed) as count FROM (some select) alias Or SELECT count(consumed) as count, goal FROM (some select) alias Group by goal solved COUNT and GROUP BY doesn’t works as expected [closed]

[Solved] How to get a road path which can be travelled in 10 minutes from a location

pgr_drivingDistance uses the cost value you provide, and in the units you implicitly specify, meaning that when you add a column <traveling_time> (note that I use seconds in my example) as the time needed to traverse an edge (given the length and speed limit) and select that as cost, the functions result will represent the … Read more