Replicating / Updating Materialized views across databases

2023-04-23 Thread Alex Magnum
Hi, I have large centralized master database for which I created a few materialized views exclusively used by Web sites running in different regions on their own servers. To avoid having to connect to and pull data from across the globe I am thinking about running small postgres instances in each

Re: Error with Insert from View with ON Conflict

2021-11-04 Thread Alex Magnum
Steve, Peter, thanks . Below query works. the view is used to generate the stats and not using the table http_ping_uptime_stats . So my interpretation was that I need to alias the view for the UPDATE to know where the value is coming from as both have the same name. That obviously did not work. I

Error with Insert from View with ON Conflict

2021-11-03 Thread Alex Magnum
Hi, I am trying to do an upsert using a view but for some reason get errors. All works fine without the ON CONFLICT INSERT INTO http_stats SELECT * FROM view_http_stats AS V WHERE month =date_trunc('month',now()) ON CONFLICT (url,ip,month) DO UPDATE SET last_update = now(), checks

Removing Last field from CSV string

2020-05-16 Thread Alex Magnum
Hi, I have a string that I want to cut to 60 char and then remove the last field and comma. substring('Class V,Class VI,Class VII,Competitive Exam,Class VIII,Class X,Class XI,Class IX,Class XII',1,60); substring | Class V,Class VI,Class VII,Competitive Exam,Class VIII*,Class* Now I try to remov

Re: Recursive Queries

2020-04-16 Thread Alex Magnum
thanks for the suggestion. tablefunc extension might be the easiest one On Thu, Apr 16, 2020 at 9:46 PM Edward Macnaghten wrote: > On 16/04/2020 14:36, Edward Macnaghten wrote: > > On 16/04/2020 09:35, Alex Magnum wrote: > >> Hi, > >> I have a simple table with singu

Recursive Queries

2020-04-16 Thread Alex Magnum
Hi, I have a simple table with singup timestamps What I would like to do is to create a table as shown below that displays the counts per our for the past n dates. I can do this with a function but is there an easy way to use recursive queries? * Counts per hour for given date* *HR 2020-

Re: Coalesce 2 Arrays

2019-06-24 Thread Alex Magnum
Yes, they are. On Tue, Jun 25, 2019 at 4:33 AM Rob Sargent wrote: > > > On Jun 24, 2019, at 2:31 PM, Alex Magnum wrote: > > Hi, > I have two arrays which I need to combine based on the individual values; > i could do a coalesce for each field but was wondering if the

Coalesce 2 Arrays

2019-06-24 Thread Alex Magnum
Hi, I have two arrays which I need to combine based on the individual values; i could do a coalesce for each field but was wondering if there is an easier way array_a{a, null,c, d,null,f,null} primary array_b{null,2 ,null,4,5 ,6,null} secondary result {a, 2, c, d,5, f,null) Any

Using random() in update produces same random value for all

2018-01-14 Thread Alex Magnum
Hi, i am trying to update a table with some random dates but that does not seem to work. UPDATE table SET last_update=now()::date-(SELECT (random() * 5)::INTEGER + 1) The updated field is always set to the same. Is there a way to make it random for every record? I could run it through a funct