postgresql-9.4

FATAL: password authentication failed for user “root” postgresql

拥有回忆 提交于 2019-12-11 05:24:24
问题 I use PostgreSQL and Django (format Heroku) and have error FATAL: password authentication failed for user "root" Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line utility.execute() File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/core/management/__init__.py

“ERROR: column … specified more than once” in VIEW definition

前提是你 提交于 2019-12-11 05:14:07
问题 This is a follow-up question to an earlier one. I have a stored function f1 that takes two arguments returns a table with 5 columns; for now the returned values are constant, later they will be calculated from the arguments. I also have a table t1 with two columns that correspond in type to f1 's arguments. I would now like to define a view v1 that contains the union of all rows returned from f1 for all argument pairs stored in t1 . For the given example values the result should be: +---+---+

real-time sync between local Postgres instance and Azure Cloud Postgres instance

守給你的承諾、 提交于 2019-12-11 04:47:10
问题 I need to set up real time sync process between a on premise postgresql instance with cloud postgresql instance. Please let me know what are all the options available through which i can achieve it. Do i have to use any specific tool or it can be managed through replication . Please advice 回答1: Use PgPool http://www.pgpool.net/mediawiki/index.php/Main_Page from their web page: pgpool-II can manage multiple PostgreSQL servers. Using the replication function enables creating a realtime backup

Pass array of tags to a plpgsql function and use it in WHERE condition

和自甴很熟 提交于 2019-12-11 04:41:36
问题 I'd like to create a function that returns items based on their tags . However, I do not know how to format an array in the IN() clause. I believe that is why I get no result. Here is what I got: CREATE OR REPLACE FUNCTION getItemsByTag(tags text[]) RETURNS TABLE (id bigint, title text, tag text[]) AS $$ BEGIN IF array_length(tags, 1) > 0 THEN EXECUTE format(' SELECT d.id, d.title, array_agg(t.title) FROM items d INNER JOIN item_tags dt ON dt.item_id = d.id INNER JOIN tags t ON t.id = dt.tag

PostgreSQL 9.4 - Use custom operator in EXCLUDE constraint

倾然丶 夕夏残阳落幕 提交于 2019-12-11 01:13:42
问题 After reviewing this answer, I have created the following custom operators: CREATE OR REPLACE FUNCTION is_not_distinct_from( ANYELEMENT, ANYELEMENT ) RETURNS BOOLEAN AS $$ SELECT $1 IS NOT DISTINCT FROM $2; $$ LANGUAGE sql IMMUTABLE; CREATE OPERATOR =!= ( PROCEDURE = is_not_distinct_from(anyelement,anyelement), LEFTARG = anyelement, RIGHTARG = anyelement, COMMUTATOR = =!=, NEGATOR = <!> ); CREATE OR REPLACE FUNCTION is_distinct_from( ANYELEMENT, ANYELEMENT ) RETURNS BOOLEAN AS $$ SELECT $1 IS

FULL OUTER JOIN to merge tables with PostgreSQL

[亡魂溺海] 提交于 2019-12-11 00:58:27
问题 Following this post, I still have an issue when I apply the answer given by @Vao Tsun to a bigger dataset made this time of 4 tables instead of 2 tables in the related post mentionned above. Here are my datasets: -- Table 'brcht' (empty) insee | annee | nb -------+--------+----- -- Table 'cana' insee | annee | nb -------+--------+----- 036223 | 2017 | 1 086001 | 2016 | 2 -- Table 'font' (empty) insee | annee | nb -------+--------+----- -- Table 'nr' insee | annee | nb -------+--------+-----

postgreSQL sorting with timestamps

时间秒杀一切 提交于 2019-12-11 00:25:04
问题 I have the following SQL statement: SELECT * FROM schema."table" WHERE "TimeStamp"::timestamp >= '2016-03-09 03:00:05' ORDER BY "TimeStamp"::date asc LIMIT 15 What do I expect it to do? Giving out 15 rows of the table, where the timestamp is the same and bigger than that date, in ascending order. But postgres sends the rows in the wrong order. The first item is on the last position. So has anyone an idea why the result is this strange? 回答1: Use simply ORDER BY "TimeStamp" (without casting to

Merge tables with PostgreSQL

a 夏天 提交于 2019-12-10 23:53:02
问题 The title of this question is not accurate but I didn't know how to summarize it. Please feel free to write it again if you can! Here is an extract of two tables: Table table_a code | year | nb_a ------+--------+------ A1 | 2017 | 1 A2 | 2012 | 2 A3 | 2014 | 2 Table table_b code | year | nb_b ------+--------+------ A1 | 2013 | 1 A1 | 2014 | 1 A2 | 2012 | 1 I need to merge these tables in order to get this output: code | year | nb_a | nb_b | total ------+--------+------+------+------- A1 |

How do I configure a grails domain class attribute to be stored as (postgres 9.4) jsonb?

时光毁灭记忆、已成空白 提交于 2019-12-10 17:38:07
问题 I've tried to configure a domain class like this: class Test { String data static constraints = { } static mapping = { data type: 'jsonb' } } This throws an exception (the reason, in the end, being Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: jsonb, at table: test, for columns: [org.hibernate.mapping.Column(data)] ). I also tried column: 'data', sqlType: 'jsonb' , which creates a text column named data . How do I correctly

Postgres: foreign key to foreign table

百般思念 提交于 2019-12-10 14:11:50
问题 I have a foreign table, for example: CREATE FOREIGN TABLE film ( id varchar(40) NOT NULL, title varchar(40) NOT NULL, did integer NOT NULL, date_prod date, kind varchar(10), len interval hour to minute ) SERVER film_server; with id as the primary key for that table (set in the remote database). I would like to have a local table reference the foreign table, and set a foreign key constraint on the local table -- for example: CREATE TABLE actor ( id varchar(40) NOT NULL, name varchar(40) NOT