postgresql

Get apps with the highest review count since a dynamic series of days

三世轮回 提交于 2021-01-28 21:41:12
问题 I have two tables, apps and reviews (simplified for the sake of discussion): apps table id int reviews table id int review_date date app_id int (foreign key that points to apps) 2 questions: 1. How can I write a query / function to answer the following question?: Given a series of dates from the earliest reviews.review_date to the latest reviews.review_date (incrementing by a day), for each date, D , which apps had the most reviews if the app's earliest review was on or later than D ? I think

array_append function is not working

走远了吗. 提交于 2021-01-28 21:07:47
问题 I need to append an item to existed array in postgresql. I wrote this code (plpgsql function): perform array_append (arrayA::integer[],id); Since it didn't work I tried: raise notice '%', arrayA; perform array_append (arrayA::integer[],id); raise notice '%', arrayA; It gives: NOTICE: <NULL> NOTICE: <NULL> Why the array isn't updated? 回答1: PERFORM query discard the results. array_append doesn't update the array you specify in the first parameter. It only reads the its values. You should change

array_append function is not working

此生再无相见时 提交于 2021-01-28 20:45:47
问题 I need to append an item to existed array in postgresql. I wrote this code (plpgsql function): perform array_append (arrayA::integer[],id); Since it didn't work I tried: raise notice '%', arrayA; perform array_append (arrayA::integer[],id); raise notice '%', arrayA; It gives: NOTICE: <NULL> NOTICE: <NULL> Why the array isn't updated? 回答1: PERFORM query discard the results. array_append doesn't update the array you specify in the first parameter. It only reads the its values. You should change

Override serial sequence in PostgreSql with Entity Framework (C#)

走远了吗. 提交于 2021-01-28 20:18:48
问题 How do I override the serial/sequence in an ID field when adding records with Entity Framework on a PostgreSQL database? The serial/sequence auto incrementing ID works fine, when adding records, but I need to write a migration script where the old records I migrate must maintain their old ID's. It works fine if I just shoot an INSERT query directly to the server, but when doing with with Entity Framework, they just start from 1, 2, 3 etc. 回答1: You should to reset sequence in the database

The type initializer for 'Npgsql.TypeMapping.GlobalTypeMapper' threw an exception

风格不统一 提交于 2021-01-28 20:10:58
问题 Using Visual Studio 2017 try using the Server Explorer to add a connection to a Postgres database. Click Test connection. The issue An error is shown with: The type initializer for 'Npgsql.TypeMapping.GlobalTypeMapper' threw an exception. Before that I installed System.Runtime.CompilerServices.Unsafe v4.5.2 and System.Numerics.Vectors v4.4.0 to fix the error message "Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1" and Could not load file or assembly

Concatenate JSON rows

▼魔方 西西 提交于 2021-01-28 20:09:21
问题 I have the following table with sample records: create table jtest ( id int, jcol json ); insert into jtest values(1,'{"name":"Jack","address1":"HNO 123"}'); insert into jtest values(1,'{"address2":"STREET1"}'); insert into jtest values(1,'{"address3":"UK"}'); select * from jtest; id jcol ------------------------------------------- 1 {"name":"Jack","address":"HNO 123 UK"} 1 {"address2":"STREET1"} 1 {"address3":"UK"} Expected result: id jcol ----------------------------------------------------

Docker dpage/pgadmin4 error: specified user does not exist

孤人 提交于 2021-01-28 20:08:01
问题 This is the docker-compose.yml file: version: '3' services: ############################ # Setup database container # ############################ postgres_db: image: postgres restart: always ports: - ${POSTGRES_PORT}:${POSTGRES_PORT} environment: - POSTGRES_USER=${POSTGRES_USER} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - PGDATA=/var/lib/postgresql/data/pgdata - POSTGRES_DB=${POSTGRES_DB} volumes: - ./data:/var/lib/postgresql/data networks: - db_network pgadmin: image: dpage/pgadmin4:4.19

Postgresql: count records by time intervals

与世无争的帅哥 提交于 2021-01-28 19:31:54
问题 I am trying to use the following SQL statement with postgresql to generate some report: WITH GRID AS ( SELECT START_TIME, LEAD(START_TIME) OVER (ORDER BY START_TIME) AS END_TIME FROM ( SELECT GENERATE_SERIES('2015-08-01 12:00:00', '2015-09-01 12:00:00', INTERVAL '1 day') AS START_TIME FROM MY_TABLE ) x ) SELECT START_TIME, COUNT(MY_TABLE._ID) AS COUNT FROM GRID LEFT JOIN MY_TABLE ON MY_TABLE.CREATED >= GRID.START_TIME AND MY_TABLE.CREATED < GRID.END_TIME WHERE MY_TABLE.COMPANY_ID = '1001' AND

PostgreSQL ST_AsMVT to VectorTiles to Leaflet Layer

雨燕双飞 提交于 2021-01-28 19:21:02
问题 I'm trying to create vector tiles from a PostgreSQL database and serve them via flask to a Leaflet map. I've followed this medium.com article which got me nearly all the way. However, when i open the page with the Leaflet map on it I get the following in the browser console: index.js:191 Uncaught Error: Unimplemented type: 4 at Pbf.skip (index.js:191) at Pbf.readFields (index.js:41) at new VectorTile$1 (vectortile.js:8) at FileReader. (Leaflet.VectorGrid.Protobuf.js:124) to create the tiles I

WAL buffers fills before the transaction commits

怎甘沉沦 提交于 2021-01-28 19:11:42
问题 I have been going around the crash recovery mechanism in Postgresql and this hit me. In WAL logging, At the transaction START, based on the queries, WAL Buffers are filled with XLOG records. At transaction COMMIT, the WAL buffer gets flushed. Now, Assume that i start a transaction with series of inserts. When the existing WAL segments gets filled, it creates new ones. But what happens, when i do bulk insert or copy heavy data or something (say 4-5GB), and the WAL Buffer(1-2GB) gets filled