postgresql-9.4

Go sql - prepared statement scope

夙愿已清 提交于 2020-01-11 12:21:26
问题 I'm building an API using the Go (1.6.x) sql package along with with PostGres (9.4). Should my prepared statements have application or request scope? Having read the docs it would seem more efficient to scope them at the application level to reduce the number of preparation phases. However, perhaps there are other considerations and prepared statements are not designed to live that long? 回答1: Prepared statements are so that you can execute repetitive SQL commands which may only differ in

Use variable set by psql meta-command inside of DO block

£可爱£侵袭症+ 提交于 2020-01-10 05:11:21
问题 Here's what I would like to do: \set values foo,bar,baz DO $$ DECLARE value TEXT; values TEXT[] := string_to_array(:'values', ','); BEGIN FOREACH value IN ARRAY values LOOP raise notice 'v: %', value; END LOOP; END $$ LANGUAGE plpgsql; Which results in the following error: ERROR: syntax error at or near ":" SELECT string_to_array(:'values', ',') INTO values... ^ Here's the solution I have currently, but it feels hacky: \set values foo,bar,baz PREPARE get_values AS SELECT string_to_array(:

How avoid the scan in the main table

橙三吉。 提交于 2020-01-07 06:31:10
问题 I have a table partitioned using inherit in multiple tables for days. There is one insert trigger to insert the data to the proper table, so in theory the avl table shouldnt have any data CREATE OR REPLACE FUNCTION avl_db.avl_insert_trigger() RETURNS trigger AS $BODY$ BEGIN IF ( NEW.event_time >= '2017-06-01 00:00:00' AND NEW.event_time < '2017-06-02 00:00:00' ) THEN INSERT INTO avl_db.avl_20170601 VALUES (NEW.*); ELSEIF ( NEW.event_time >= '2017-06-02 00:00:00' AND NEW.event_time < '2017-06

How to subscribe new user to notifications?

限于喜欢 提交于 2020-01-07 05:36:29
问题 I have set up SonarQube 5.2 installation, and I want to enable notifications for new users by default. What I mean is these checkboxes in user profile. I couldn't find an answer in the documentation, the available plugins, the Internet, if anybody had a similar question. What I have found so far is user properties in the SQ database: sonar=# select * from properties where user_id=6; id | prop_key | resource_id | text_value | user_id ----+-------------------------------------------------------

Does JSONB make PostgreSQL arrays useless?

被刻印的时光 ゝ 提交于 2020-01-01 04:19:32
问题 Suppose that you want to store "tags" on your object (say, a post). With release 9.4 you have 3 main choices: tags as text[] tags as jsonb tags as text (and you store a JSON string as text) In many cases, 3rd would be out of question since it wouldn't allow query conditional to 'tags' value. In my current development, I don't need such queries, tags are only there to be shown on posts list, not to filter posts. So, choice is mostly between text[] and jsonb . Both can be queried. What would

how to use jsonb in rails

做~自己de王妃 提交于 2019-12-30 07:26:06
问题 I have a rails project with Postgresql 9.4 as backend. I have column like this: t.json :slot_details, null: false, default: {} How do I change this to JSONB from JSON? Should I add index and that will be changed to JSONB? 回答1: For migrating this, you can do the following. Payload in this case was originally a json field. class AlterJsonbToJsonAndBack < ActiveRecord::Migration def up change_column :dynamics, :payload, 'jsonb USING CAST(payload AS jsonb)' end def down change_column :dynamics,

Appending (pushing) and removing from a JSON array in PostgreSQL 9.2, 9.3, and 9.4?

给你一囗甜甜゛ 提交于 2019-12-29 05:25:18
问题 For versions greater than 9.5 see this question I have created a table in PostgreSQL using this: CREATE TEMP TABLE jsontesting AS SELECT id, jsondata::jsonb FROM ( VALUES (1, '["abra","value","mango", "apple", "sample"]'), (2, '["japan","china","india", "russia", "australia"]'), (3, '["must", "match"]'), (4, '["abra","value","true", "apple", "sample"]'), (5, '["abra","false","mango", "apple", "sample"]'), (6, '["string","value","mango", "apple", "sample"]'), (7, '["must", "watch"]') ) AS t(id

restrict the number of connections in postgres using an ip address

旧城冷巷雨未停 提交于 2019-12-25 18:21:33
问题 Is it possible to restrict the number of connections in postgres, using the ip address of machine, since i'm not able to find which ip address is tagged to which user / role. 回答1: implicitly you can do it with pgbouncer - at least 1.7 version supports hba file, so you can bond db+user+ip and set limit for db+user in ini file. This way limiting connections to IP or network. explicitly you can try using HAProxy's or just IPTABLES (I think prefered way) lastly you can write some monkey job that

Postgres Match All array values to same column with and condition

不问归期 提交于 2019-12-25 07:49:44
问题 I have table table_a with following columns id event_id 1 101 1 102 1 103 2 105 2 103 2 106 I want to search (101, 103) with and conditions similar to IN query with OR condition let say id is foreign of another table event_categories having relation like this. id parent_id 101 null 102 101 103 101 104 null 105 104 so I want to fetch records from table_a based on AND with parent event category, OR within sub-event categories of that parent. Attached screenshot for more clarification For

Unable to connect to pgsql database with Java REST-API on local Tomcat server. Stack contains ExceptionInInitializerError and IllegalStateException

与世无争的帅哥 提交于 2019-12-24 19:09:24
问题 I am developing a REST-API and currently trying to fix an issue. The issue is that the REST-API is Unable to connect to pgsql database, when I go to my web page in chrome. To show this issue, I'll post a stripped down version of my stack with some explanation, describing the origin and functionality of the involved Java classes and XML. Afterwards, I'll show some code of the involved XML files and java classes. I'll look forward to your answers and feedback on my first post. UPDATE: at the