postgresql

Exclude overlapping periods in time aggregate function

℡╲_俬逩灬. 提交于 2021-01-28 05:28:08
问题 I have a table containing each a start and and end date: DROP TABLE temp_period; CREATE TABLE public.temp_period ( id integer NOT NULL, "startDate" date, "endDate" date ); INSERT INTO temp_period(id,"startDate","endDate") VALUES(1,'2010-01-01','2010-03-31'); INSERT INTO temp_period(id,"startDate","endDate") VALUES(2,'2013-05-17','2013-07-18'); INSERT INTO temp_period(id,"startDate","endDate") VALUES(3,'2010-02-15','2010-05-31'); INSERT INTO temp_period(id,"startDate","endDate") VALUES(7,'2014

org.apache.kafka.connect.errors.ConnectException: An exception occurred in the change event producer. This connector will be stopped

大兔子大兔子 提交于 2021-01-28 05:14:34
问题 Using postgres source connector in kafka. It works properly for some time and suddently stops with above error. Please assist if someone knows this issue. 回答1: This happens if the database is not available and the only way to fix it to restart the connector. I would advise you to check the database logs and see if database is going down or refusing connection to Kafka Connect 来源: https://stackoverflow.com/questions/60450498/org-apache-kafka-connect-errors-connectexception-an-exception

PostgreSQL: Identifying return visitors based on date - joins or window functions?

纵然是瞬间 提交于 2021-01-28 05:11:46
问题 I am looking to identify return visitors to a website within a 7 day window. A data sample and attempt at solving are included below: visitor_id(integer) session_id(integer) event_sequence(integer) d_date(date) Sample raw data: +-----------+-------------+----------------+-------------+ | visitor_id| session_id | event_sequence | d_date | +-----------+-------------+----------------+-------------+ | 1 | 1 | 1 | 2017-01-01 | | 1 | 1 | 2 | 2017-01-01 | | 1 | 1 | 3 | 2017-01-01 | | 1 | 2 | 1 |

Generate auto ID in postgresql

為{幸葍}努か 提交于 2021-01-28 05:11:05
问题 User Table: ID Name 1 usr1 2 usr2 3 usr3 In the above table, ID is a primary key. My requirement is while inserting data into the table, I would like to specify only the name like INSERT INTO user VALUES('usr4') . After execute the query, Is there any way to automatically create ID for 'usr4'? I tried with serial data type. For that also we have to specify the keyword default like INSERT INTO user VALUES(default,'usr4') . So, is there any way to do like INSERT INTO user VALUES('usr4') . NOTE:

UPDATE with jsonb_set() only affects one object in nested array

≯℡__Kan透↙ 提交于 2021-01-28 04:56:31
问题 Trying to update all elements of a nested array in a jsonb column, but only one element is updated. My query: update table_ set value_ = jsonb_set(value_,cte.json_path,cte.namevalue,false) FROM ( select vals2->'ao'->'sc'->'name' as namevalue, ('{iProps,'||index1-1||',value,rules,'||index2-1||',ao,sc}')::text[] as json_path from table_, jsonb_array_elements(value_->'iProps') with ordinality arr1(vals1,index1), jsonb_array_elements(vals1->'value'->'rules') with ordinality arr2(vals2,index2) )

Pad row with default if values not found PostgresSQL

拥有回忆 提交于 2021-01-28 04:43:58
问题 I wanted to return the last 7 days of user_activity, but for those empty days I want to add 0 as value Say I have this table actions | id | date ------------------------ 67 | 123 | 2019-07-7 90 | 123 | 2019-07-9 100 | 123 | 2019-07-10 50 | 123 | 2019-07-13 30 | 123 | 2019-07-15 and this should be the expected output , for the last 7 days actions | id | date ------------------------ 90 | 123 | 2019-07-9 100 | 123 | 2019-07-10 0 | 123 | 2019-07-11 <--- padded 0 | 123 | 2019-07-12 <--- padded 50

How to generate a hash of the result set in Postgress?

主宰稳场 提交于 2021-01-28 04:43:55
问题 I have two databases for logging stuff, which I want to check for synchronization. The solution approved is to send periodically (lets say hourly) a select to both, generate a hash of the result set and compare them. If they match then great, otherwise generate some alarms. Currently I'm doing it by (bash script): log_table="SELECT column1, column2, column3 FROM log_table where to_char(timestamp, '$ts_format') = '$tx_moment'"; PSQL="psql -t -q -h $_gp_host -U $_gp_user -d log_schema -c ";

Postgis + boost::geometry + C++

荒凉一梦 提交于 2021-01-28 04:41:24
问题 I have the following wtk: POLYGON((0 0, 10 0, 10 11, 11 10, 0 10)) In boost::geometry we can get this polygon representation using boost::geometry::dsv(polygon," "," "," "); How I can apply postgis st_makevalid function to a boost::geometry polygon? I suppose it something like: #include "libpq/libpq-fs.h" #include "../libpq-fe.h" . . . std::string geom = "POLYGON" + boost::geometry::dsv(multipoly," "," "," "); res = PQexecParams(conn, "SELECT st_makevalid(geom) FROM .... I do not want to

How to deploy Postgresql on Kubernetes with NFS volume

拜拜、爱过 提交于 2021-01-28 03:56:29
问题 I'm using the below manifest to deploy postgresql on kubernetes within NFS persistent volume: apiVersion: v1 kind: PersistentVolume metadata: name: nfs2 spec: capacity: storage: 6Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain nfs: server: 10.139.82.123 path: /nfsfileshare/postgres --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: nfs2 spec: accessModes: - ReadWriteMany resources: requests: storage: 6Gi --- apiVersion: v1 kind: Service metadata: name: db

column does not exist error even when using the 'as' keyword [duplicate]

二次信任 提交于 2021-01-28 03:53:44
问题 This question already has answers here : Using an Alias column in the where clause in Postgresql (6 answers) Column doesn't exist? (1 answer) Closed 1 year ago . I get this error: ERROR: column "errors" does not exist LINE 11: where errors >= 1 even that i checked the result with select. I'm using postgresql server, i have a table named log like the following: Column | Type | Modifiers --------+--------------------------+-------------------------------------------------- path | text | ip |