postgresql

Deal with Postgresql Error -canceling statement due to conflict with recovery- in psycopg2

拈花ヽ惹草 提交于 2021-01-27 05:26:26
问题 I'm creating a reporting engine that makes a couple of long queries over a standby server and process the result with pandas. Everything works fine but sometimes I have some issues with the execution of those queries using a psycopg2 cursor: the query is cancelled with the following message: ERROR: cancelling statement due to conflict with recovery Detail: User query might have needed to see row versions that must be removed I was investigating this issue PostgreSQL ERROR: canceling statement

Deal with Postgresql Error -canceling statement due to conflict with recovery- in psycopg2

烂漫一生 提交于 2021-01-27 05:25:46
问题 I'm creating a reporting engine that makes a couple of long queries over a standby server and process the result with pandas. Everything works fine but sometimes I have some issues with the execution of those queries using a psycopg2 cursor: the query is cancelled with the following message: ERROR: cancelling statement due to conflict with recovery Detail: User query might have needed to see row versions that must be removed I was investigating this issue PostgreSQL ERROR: canceling statement

Why can't two tables have an index of the same name?

左心房为你撑大大i 提交于 2021-01-27 05:25:21
问题 I'm creating indexes on two separate tables in the same DB (PostgreSQL), and I got an error saying that an index already exists. This was true, however, the index existed on a different table. After changing the name, it worked. I'm wondering why this is the case? Why are databases designed such that two tables can't have the same name of an index? I found two sources that answer this, although the answers are different. One is for MySQL, the other is for Postgres: In postgres how do I add

Why does JSON null not cast to SQL null in postgres?

谁都会走 提交于 2021-01-27 05:24:34
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

Why does JSON null not cast to SQL null in postgres?

杀马特。学长 韩版系。学妹 提交于 2021-01-27 05:24:09
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

Why does JSON null not cast to SQL null in postgres?

我的梦境 提交于 2021-01-27 05:23:01
问题 So the following PostgreSQL snippet returns null , as it should: select ('{"id": null}'::json->'id') Intuitively, one would expect the following statement to return null or an empty string: select ('{"id": null}'::json->'id')::TEXT Instead it returns the string "null". Why? Additionally, select ('{"id": null}'::json->'id')::INTEGER returns cannot cast type json to integer and select ('{"id": null}'::json->'id')::TEXT::INTEGER returns invalid input syntax for integer: "null" . (The use case

PostgreSQL How to get average of sum of certain rows

a 夏天 提交于 2021-01-27 04:55:50
问题 I apologize if the title isn't very apt, but I had a little trouble formulating a concise title. Anyway, I have a table that keeps a log of states a person is in. It looks like: id, login, state, duration, started_at 1, pdiddy, working, 1200, 2018-05-25 08:30:00 2, pdiddy, lunch, 120, 2018-05-25 9:00:00 3, pdiddy, on_call, 65, 2018-05-25 12:30:00 4, pdiddy, available, 1115, 2018-05-25 12:30:00 5, pdiddy, working, 143, 2018-05-25 12:30:00 6, pdiddy, break1, 150, 2018-05-25 12:30:00 7, pdiddy,

Count the number of attributes that are NULL for a row

柔情痞子 提交于 2021-01-27 04:38:34
问题 I want to add a new column to a table to record the number of attributes whose value are null for each tuple (row). How can I use SQL to get the number? for example, if a tuple is like this: Name | Age | Sex -----+-----+----- Blice| 100 | null I want to update the tuple as this: Name | Age | Sex | nNULL -----+-----+-----+-------- Blice| 100 | null| 1 Also, because I'm writing a PL/pgSQL function and the table name is obtained from argument, I don't know the schema of a table beforehand. That

Postegresql slow connect time on Windows

↘锁芯ラ 提交于 2021-01-27 04:27:28
问题 I noticed that the connection to PostgreSQL is pretty slow. import psycopg2 import time start_time = time.time() try: db = psycopg2.connect("dbname='xx' user='xxx' host='127.0.0.1' password='xxx' port='5433'") except Exception as e: print(e) exit(1) print('connect time', time.time() - start_time) Usual connect time is 2.5-3.5 seconds. connect time 3.3095390796661377 Its pretty much default configuration of freshly installed PostgreSQL. I turned off log_hostname but it changed nothing. I have

How am I supposed to use a Postgresql docker image/container?

↘锁芯ラ 提交于 2021-01-27 04:17:29
问题 I'm new to docker. I'm still trying to wrap my head around all this. I'm building a node application (REST api), using Postgresql to store my data. I've spent a few days learning about docker, but I'm not sure whether I'm doing things the way I'm supposed to. So here are my questions: I'm using the official docker postgres 9.5 image as base to build my own (my Dockerfile only adds plpython on top of it, and installs a custom python module for use within plpython stored procedures). I created