postgresql-9.4

Is it mandatory parameter recover_target_timeline='latest' in switchover and switchback in PostgreSQL 9.4.1?

吃可爱长大的小学妹 提交于 2019-12-20 06:14:25
问题 I have followed below steps for switchover and switchback. Step 1:- Disconnect application services from 10.x.x.10 and do the following @Master(10.x.x.10) pg_ctl -D /DATA_VEC/pgdata stop --mode=fast @DR(20.x.x.20) promote DR as read write mode Step 2:- Start master as DR from new primary @Master(10.x.x.10) create recovery.conf standby_mode = 'on' primary_conninfo = 'user= password= host=20.x.x.20 port=9999 trigger_file = '/tmp/node1' restore_command = 'cp /DATA_VEC/restore/%f "%p"' pg_ctl -D

Update certain array elements of a json array in PostgreSQL 9.4

坚强是说给别人听的谎言 提交于 2019-12-19 19:44:00
问题 I have a table like this; CREATE TABLE test ( id BIGSERIAL PRIMARY KEY, data JSONB ); INSERT INTO test(data) VALUES('[1,2,"a",4,"8",6]'); -- id = 1 INSERT INTO test(data) VALUES('[1,2,"b",4,"7",6]'); -- id = 2 How to update element data->1 and data->3 into something else without PL/* ? 回答1: You cannot manipulate selected elements of a json / jsonb type directly. Functionality for that is still missing in Postgres 9.4 (see @Craig's comment). You have to do 3 steps: Unnest / decompose the JSON

Is it possible to define global variables in postgresql

感情迁移 提交于 2019-12-17 19:45:47
问题 I am using postgresql 9.4 and while writing functions I want to use self-defined error_codes (int). However I may want to change the exact numeric values later . For instance -1 means USER_NOT_FOUND. -2 means USER_DOES_NOT_HAVE_PERMISSION. I can define these in a table codes_table(code_name::text, code_value::integer) and use them in functions as follows (SELECT codes_table.code_value FROM codes_table WHERE codes_table.code_name = 'USER_NOT_FOUND') Is there another way for this. Maybe global

How to perform update operations on columns of type JSONB in Postgres 9.4

跟風遠走 提交于 2019-12-17 03:24:14
问题 Looking through the documentation for the Postgres 9.4 datatype JSONB, it is not immediately obvious to me how to do updates on JSONB columns. Documentation for JSONB types and functions: http://www.postgresql.org/docs/9.4/static/functions-json.html http://www.postgresql.org/docs/9.4/static/datatype-json.html As an examples, I have this basic table structure: CREATE TABLE test(id serial, data jsonb); Inserting is easy, as in: INSERT INTO test(data) values ('{"name": "my-name", "tags": ["tag1"

Trying to construct PostgreSQL Query to extract from JSON a text value in an object, in an array, in an object, in an array, in an object

﹥>﹥吖頭↗ 提交于 2019-12-13 20:21:10
问题 I am constructing an interface between a PostgreSQL system and a SQL Server system and am attempting to "flatten" the structure of the JSON data to facilitate this. I'm very experienced in SQL Server but I'm new to both PostgreSQL and JSON. The JSON contains essentially two types of structure: those of type "text" or "textarea" where the value I want is in an object named value (the first two cases below) and those of type "select" where the value object points to an id object in a lower

jsonb with psycopg2 RealDictCursor

谁都会走 提交于 2019-12-13 14:31:11
问题 I have a postgresql 9.4 (aka mongodb killer ;-) ) and this simple schema : CREATE TABLE test (id SERIAL, name text, misc jsonb); now i populate this, if i make a select it will show something like id | name | misc 1 | user1 | { "age" : 23, "size" : "M" } 2 | user2 | { "age" : 30, "size" : "XL" } now, if i make a request with psycopg2, cur.execute("SELECT * FROM test;") rows = list(cur) i'll end up with [ { 'id' : 1, 'name' : 'user1', 'misc' : '{ "age" : 23, "size" : "M" }' }, { 'id2' : 2,

How to make the Primary Key have X digits in PostgreSQL?

落花浮王杯 提交于 2019-12-13 07:35:21
问题 I am fairly new to SQL but have been working hard to learn. I am currently stuck on an issue with setting a primary key to have 8 digits no matter what. I tried using INT(8) but that didn't work. Also AUTO_INCREMENT doesn't work in PostgreSQL but I saw there were a couple of data types that auto increment but I still have the issue of the keys not being long enough. Basically I want to have numbers represent User IDs, starting at 10000000 and moving up. 00000001 and up would work too, it

Delete a record if the associated Join entry does not exist

江枫思渺然 提交于 2019-12-13 07:26:20
问题 I'm trying to delete a record from a table if the parent table record does not exist. The table in question are merchants and merchant_configurations merchant_configurations has a foreign key ( merchant_id ) reference to merchant table primary key ( id ) Here how the 2 tables looks == merchant_configurations id integer merchant_id integer config_options hstore Merchant table == merchants id integer name string Now, select query to retrieve all those merchant_configurations record for whose

postgresql trigger to make name unique

送分小仙女□ 提交于 2019-12-13 07:05:42
问题 I'm using postgres 9.4; I have a table with a unique index. I would like to mutate the name by adding a suffix to ensure the name is unique. I have created a "before" trigger which computes a suffix. It works well in autocommit mode. However, if two items with the same name are inserted in the same transaction, they both get the same unique suffix. What is the best way to accomplish my task? Is there a way to handle it with a trigger, or should I ... hmm... wrap the insert or update in a

Expand multiple rows result of `jsonb_array_elements` to tsvector inside a PL/pgSQL procedure

試著忘記壹切 提交于 2019-12-13 06:33:09
问题 overflowers, I have a JSON array items like this (PostgreSQL 9.4): [{name: "foo"}, {name: "bar"}, {name: "baz"}] What I want is to concatenate all item's name into a tsvector -typed column so that I can create index on that column. And if I run: SELECT to_tsvector(array_to_string(array(SELECT jsonb_array_elements(items)->>'name' FROM store), ',')) I can get an expected result: 'foo': 1 'bar': 2 'baz': 3 But I got stuck at something like this: CREATE OR REPLACE FUNCTION update_tsv() RETURNS