postgresql

postgres crosstab, ERROR: The provided SQL must return 3 columns

北城以北 提交于 2021-02-10 20:51:42
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |

postgres crosstab, ERROR: The provided SQL must return 3 columns

让人想犯罪 __ 提交于 2021-02-10 20:50:42
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |

Using Postgres domains to simplify function input validation

巧了我就是萌 提交于 2021-02-10 20:46:24
问题 Using Postgres 11.5, I've been looking at CREATE DOMAIN since yesterday, and would like to clarify how they can/can't help with function parameters. Ideally, I'd like to use a domain to screen parameter inputs easily, but with a helpful error response. As an example, I'm using a simple first-case, a domain that blocks null and empty strings: CREATE DOMAIN text_not_empty AS text NOT NULL CHECK (value <> ''); I tried this out as a field type for a table, and it's great. When we don't allow

Using Postgres domains to simplify function input validation

霸气de小男生 提交于 2021-02-10 20:45:06
问题 Using Postgres 11.5, I've been looking at CREATE DOMAIN since yesterday, and would like to clarify how they can/can't help with function parameters. Ideally, I'd like to use a domain to screen parameter inputs easily, but with a helpful error response. As an example, I'm using a simple first-case, a domain that blocks null and empty strings: CREATE DOMAIN text_not_empty AS text NOT NULL CHECK (value <> ''); I tried this out as a field type for a table, and it's great. When we don't allow

delete old PostgreSQL data directory in win7

纵然是瞬间 提交于 2021-02-10 20:31:49
问题 i'm not able to delete my old data directory in windows 7. i already uninstalled PostgreSQL, but there's still the system service user account "postgres", who's the only one with access-rights to the folder. possible solution would be to develop a service, running as "postgres" user, which deletes the folder, but there must be an easier way? 回答1: I haven't used Windows 7, but if I recall correctly, there should be a way to start an explorer session (the filemanager, not IE) under the Postgres

Can Debezium Capture Changes of a Postges Materialized View

醉酒当歌 提交于 2021-02-10 20:24:40
问题 We are currently trying to use Debezium for capturing changes of 4 tables in a Postgres database. We are currently aware that for this use case we could use a kafka-streams app to join/aggregate tables for a KTable, however we want to keep kafka-stream topology simple, so the idea would be to use a Materialized View from Postgres and capture it changes. Is it possible to do this, if so than how should we configure it? Kafka Connect Source Configuration: { "name": "campaign-db-source-connector

Update query too slow on Postgres 9.1

旧时模样 提交于 2021-02-10 18:51:59
问题 My problem is that I have a very slow update query on a table with 14 million rows. I tried different things to tune my server which brought good performance but not for update queries. I have two tables: T1 with 4 columns and 3 indexes on it (530 rows) T2 with 15 columns and 3 indexes on it (14 millions rows) I want to update the field vid (type integer) in T2 by the same value of vid in T1 by joining the two tables on a text field stxt. Here is my query and its output: explain analyse

How to get postgresql_query results from Ansible

半腔热情 提交于 2021-02-10 18:37:17
问题 I'm trying to print the output of PostgreSQL query that is run by Ansible. Unfortunately I'm not sure how to get ahold of the return value. - name: Get specific tables postgresql_query: db: "{{ database_name }}" login_host: "{{ my_host }}" login_user: "{{ my_user }}" login_password: "{{ my_password }}" query: SELECT * FROM pg_tables t WHERE t.tableowner = current_user Googling just says to use register: , but the PostgreSQL ansible module does not have a register param: fatal: [xx.xxx.xx.xx]:

Is INSERT … SELECT an atomic transaction?

梦想与她 提交于 2021-02-10 18:15:40
问题 I use a query like this: INSERT INTO table SELECT * FROM table2 t2 JOIN ... ... WHERE table2.date < now() - '1 day'::INTERVAL FOR UPDATE OF t2 SKIP LOCKED ON CONFLICT (...) DO UPDATE SET ... RETURNING *; My question is about FOR UPDATE t2 SKIP LOCKED . Should I use it here? Or will Postgres lock these rows automatically with INSERT SELECT ON CONFLICT till the end of the transaction? My goal is to prevent other apps from (concurrently) capturing rows with the inner SELECT which are already

Get all posts with sum of votes and if current user voted each post

纵然是瞬间 提交于 2021-02-10 17:50:07
问题 If have the following two PostgreSQL tables: Post table: postid | title | author | created Vote table: postid | username | vote where vote is equal to 1 if the user voted the post up, 0 if the user did not vote and -1 if the user voted the post down. I want to receive now for every post its title, author, created date, sum of all votes and the vote of the current logged in user. I wrote a query to receive everything except the vote of the current user like this: SELECT post.postID as postID,