postgresql

Rails: prevent division by zero with postgres

筅森魡賤 提交于 2021-01-28 12:57:37
问题 I have my rails app with a postgre database and I'm trying to get some indicators, with the following statement Negotiation.find(:all, :conditions => conditions_hash('negotiation'), :select => 'sum(payment_term * amount_after_annualised_base) / sum(amount_after_annualised_base) as pt').first how can I make sure that sum(amount_after_annualised_base) is not 0 (thus doesn't throw a "division by zero" error)? I've found this, but not sure it is correct / the best / most efficient way.

用最少人力玩转万亿级数据,我用的就是MongoDB!

。_饼干妹妹 提交于 2021-01-28 12:40:07
本文根据杨亚洲老师在〖deeplus直播第258期〗线上分享演讲内容整理而成。 (文末有获取本期PPT&回放的方式,不要错过) 杨亚洲 OPPO MongoDB负责人 负责OPPO数万亿级数据量文档数据库MongoDB内核研发、性能优化及运维工作,一直专注于分布式缓存、高性能服务端、数据库、中间件等相关研发。 本文主要 分享内容如下: MongoDB在OPPO互联网推广经验分享-如何把一个淘汰边缘的数据库逐步变为公司主流数据库; 谈谈当前国内对MongoDB误解(丢数据、不安全、难维护)? MongoDB跨机房多活方案-实现成本、性能、一致性"三丰收"; MongoDB线程模型瓶颈及其优化方法; 并行迁移:MongoDB内核扩容迁移速率数倍/数十倍提升优化实践; 百万级高并发读写/千亿级数据量MongoDB集群性能数倍提升优化实践; 万亿级数据量MongoDB集群性能数十倍提升优化实践; 磁盘800%节省-记某服务接口千亿级数据迁移MongoDB,近百台SSD服务器节省原理; 展望:借助MongoDB完善的分布式、高可用、机房多活等功能,如何实现NoSQL、NewSQL融合; 其他-那些年我们踩过的坑。 一、如何把MongoDB从淘汰边缘变为公司主流数据库? 背景 入职前多个大数据量业务使用MongoDB,使用中经常超时抖动; 多个核心业务忍受不了抖动的痛苦,准备迁移回MySQL;

Changing data type to float and rounding to 2 decimal digits

早过忘川 提交于 2021-01-28 12:39:29
问题 Tables: people(id, name) job (id, people_id, job_title, salary) Goal: Display each unique job, the total average salary (FLOAT and rounded to 2 decimal places) , the total people and the total salary (Float and rounded to 2 decimal places) and order by highest average salary. So the challenge is to keep the cast type as float while rounding it to 2 decimal places. I've gotten to where I've rounded it 2 decimal places but it's not float. I've gotten it to where it's float but I can't round it

How to Import Big XML File (~10GB) into PostgreSQL

坚强是说给别人听的谎言 提交于 2021-01-28 12:37:30
问题 I have a XML file of about 10GB, I dont know the content of the file but I would like to import it into my database to make it easy to view. How can I import an xml file to my PostgreSQL database? (Is this even possible with such a large file?) I Hope you guys can help me out :) 回答1: Convert XML file into CSV file. Also, when converting, split it to 100Mb-1Gb parts for easier batching. Create the table with columns you defined in the CSV file. Upload the file(s) into Postgres with COPY

How to Import Big XML File (~10GB) into PostgreSQL

喜欢而已 提交于 2021-01-28 12:32:17
问题 I have a XML file of about 10GB, I dont know the content of the file but I would like to import it into my database to make it easy to view. How can I import an xml file to my PostgreSQL database? (Is this even possible with such a large file?) I Hope you guys can help me out :) 回答1: Convert XML file into CSV file. Also, when converting, split it to 100Mb-1Gb parts for easier batching. Create the table with columns you defined in the CSV file. Upload the file(s) into Postgres with COPY

Delegate System.Action<dynamic,int> does not take `1' arguments

爷,独闯天下 提交于 2021-01-28 12:20:18
问题 I am trying to build the PostgreSqlGeneration code from this repository on Mono. Unfortunately I get an error I do not understand. In the PostgreSqlMigrationSqlGenerator class the following method gives the build error "delegate System.Action does not take `1' arguments": private void GenerateStatements(IEnumerable<MigrationOperation> migrationOperations) { Check.NotNull(migrationOperations, "migrationOperations"); DetectHistoryRebuild(migrationOperations).Each<dynamic>(o => Generate(o)); //

How to insert foreign key in sequelize model

試著忘記壹切 提交于 2021-01-28 12:12:04
问题 I have a User model and a Houses model in sequelize. I also have a UserHouse model that contains {user_id, house_id}. How do I populate values in the UserHouse model. I went through the sequelize documentation but could not get a clear idea. I need to know, how to insert user_id and house_id in UserHouse model. I also cannot understand what associations should I use between these models. Any help will be appreciated. Edited : One More issue: I have one more model HouseInfo that stores house

Finding the histogram size for a given table PostgreSQL

僤鯓⒐⒋嵵緔 提交于 2021-01-28 11:51:16
问题 I have a PostgreSQL table named census . I have performed the ANALYSE command on the table, and the statistics are recorded in pg_stats . There are other entries in this pg_stats from other database tables as can be expected. However, I wanted to know the space consumed for storing the histogram_bounds for the census table alone. Is there a good and fast way for it? PS: I have tried dumping the pg_stats table onto the disk to measure the memory using select * into copy_table from census where

Finding Gaps in Timestamps for Multiple Users in PostgreSQL

好久不见. 提交于 2021-01-28 11:48:59
问题 I am working with a dataset containing Check-In and Check-Out times for multiple office rooms over the last 5 years. One of the projects I was asked to work on was calculating the amount of time each room is busy and vacant over various time ranges (daily, weekly, monthly, etc.) assuming normal operational hours (8am to 5pm). A sample of the dataset for two days looks like this: room_id start_dt end_dt Room: Room 3 2019-05-04 09:00:00 2019-05-04 11:30:00 Room: Room 3 2019-05-04 11:30:00 2019

Best practice to identify a jsonb null in plpgsql

删除回忆录丶 提交于 2021-01-28 11:47:16
问题 I'm aware that variants of this question have been asked before: Why can't NULL be converted to JSON's null in postgreSQL? Why does JSON null not cast to SQL null in postgres? perhaps others... What I wasn't able to glean from the above links is whether there is a best practice. Consider the following code: DO $$ DECLARE _main_jsonb jsonb = '{"i_am_null": null, "a_string": "null"}'; _sub_jsonb jsonb; BEGIN SELECT (_main_jsonb->'i_am_null') INTO _sub_jsonb; IF _sub_jsonb IS NULL THEN RAISE