postgresql

Relational DB in microservices

我的未来我决定 提交于 2021-02-10 15:07:03
问题 I have a monolithic application that currently uses a PostgreSQL DB and the schemas are set up as you would expect for most relational databases with various table data being linked back to the user via FKs on the user_id . I'm trying to learn more about microservices am trying to migrate my python API to a microservice architecture. I have a reasonable understanding of how I'm going to break up the larger app into smaller parts, however, I'm not entirely clear on how I'm supposed to deal

Relational DB in microservices

被刻印的时光 ゝ 提交于 2021-02-10 15:05:13
问题 I have a monolithic application that currently uses a PostgreSQL DB and the schemas are set up as you would expect for most relational databases with various table data being linked back to the user via FKs on the user_id . I'm trying to learn more about microservices am trying to migrate my python API to a microservice architecture. I have a reasonable understanding of how I'm going to break up the larger app into smaller parts, however, I'm not entirely clear on how I'm supposed to deal

How can I speed up this PostgreSQL UPDATE FROM sql query? It currently takes days to finish running

只谈情不闲聊 提交于 2021-02-10 14:55:18
问题 How can I speed up the PostgreSQL UPDATE FROM sql query below? It currently takes days to finish running. UPDATE import_parts ip SET part_part_id = pp.id FROM parts.part_parts pp WHERE pp.upc = ip.upc AND (ip.status is null or ip.status != '6'); And why does it takes days to run in the first place? Most of the time, I manually kill the query because it takes too long to run like more than 24 hours. Last time it successfully finished running, it took almost 38 hours. import_parts table has

Filter column names from existing table for SQL DDL statement

醉酒当歌 提交于 2021-02-10 14:53:18
问题 Is it possible to filter on column names themselves in psql? I want to generate a limited version of the original table (with several hundred columns) in a separate schema a la (pseudocode): create table why.am_i_doing_this select * from original.table where column_name_of_the_table not in ('column_1', 'column_2' ); 回答1: Build the DDL command dynamically. You can do it in two steps: Build statement: SELECT 'CREATE TABLE why.am_i_doing_this AS SELECT ' || string_agg(column_name, ', ' ORDER BY

postgres generate array using slide window

╄→гoц情女王★ 提交于 2021-02-10 14:41:09
问题 I'm trying to figure out how to a query to generate an ARRAY given a sliding window over a character column with Postgre. For example, if I have this: pid <chr> 1 WP_096038768.1 2 WP_013465871.1 3 WP_058155244.1 4 WP_011329269.1 5 WP_058374608.1 6 WP_089368983.1 7 WP_096739105.1 8 WP_089346667.1 9 WP_096041177.1 10 WP_010553306.1 ... I want a sliding window of size 1 before and after the row. The result is this: pid g <chr> <chr> 1 WP_013465871.1 WP_096038768.1,WP_013465871.1,WP_058155244.1 2

Optimistic locking queue

你离开我真会死。 提交于 2021-02-10 13:16:54
问题 I'm writing an application in Node.js using PostgreSQL as database. But I have some problems. I have a table with information about resources in region: CREATE TABLE regions_indexes ( id integer NOT NULL, resource_type integer NOT NULL, current_resource integer, maximum_resource integer, CONSTRAINT regions_indexes_pkey PRIMARY KEY (id, resource_type) ) Users clicks on button, application calculates various parameters based on current_resource and then do current_resource - $calc_value.

Optimistic locking queue

半腔热情 提交于 2021-02-10 13:16:01
问题 I'm writing an application in Node.js using PostgreSQL as database. But I have some problems. I have a table with information about resources in region: CREATE TABLE regions_indexes ( id integer NOT NULL, resource_type integer NOT NULL, current_resource integer, maximum_resource integer, CONSTRAINT regions_indexes_pkey PRIMARY KEY (id, resource_type) ) Users clicks on button, application calculates various parameters based on current_resource and then do current_resource - $calc_value.

Optimistic locking queue

拈花ヽ惹草 提交于 2021-02-10 13:14:38
问题 I'm writing an application in Node.js using PostgreSQL as database. But I have some problems. I have a table with information about resources in region: CREATE TABLE regions_indexes ( id integer NOT NULL, resource_type integer NOT NULL, current_resource integer, maximum_resource integer, CONSTRAINT regions_indexes_pkey PRIMARY KEY (id, resource_type) ) Users clicks on button, application calculates various parameters based on current_resource and then do current_resource - $calc_value.

PostgreSQL update query with “lag()” window function

十年热恋 提交于 2021-02-10 11:54:37
问题 I have a task involving Postgresql database. I am not very experienced with SQL. I have a table with weekly turnover of trade products. For each week, the following information is provided: product, week number, weekly turnover (may be positive or negative, depending on weather more of the product has been purchased or sold). I have added a column with closing balance for each week. I have a closing balance in the table for all product for first week (week_number = 0), but "null" for all

PostgreSQL update query with “lag()” window function

拜拜、爱过 提交于 2021-02-10 11:54:27
问题 I have a task involving Postgresql database. I am not very experienced with SQL. I have a table with weekly turnover of trade products. For each week, the following information is provided: product, week number, weekly turnover (may be positive or negative, depending on weather more of the product has been purchased or sold). I have added a column with closing balance for each week. I have a closing balance in the table for all product for first week (week_number = 0), but "null" for all