postgresql-9.6

postgis not available for all postgres users

余生颓废 提交于 2019-12-20 05:18:11
问题 When creating a new user on our Potgis enabled database I run into the strange issue that that new user cannot access the postgis extension while earlier created users can. With my user account I get the following output: mydb => SELECT postgis_version(); postgis_version --------------------------------------- 2.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 (1 row) With the new user I get the following: mydb => SELECT postgis_version() mydb-> ; ERROR: function postgis_version() does not exist LINE 1:

How can I fire a trigger at the end of a chain of updates?

China☆狼群 提交于 2019-12-13 13:06:43
问题 I have a couple of tables that interact with each other using triggers, and the current way I've been handling the trigger execution uses pg_trigger_depth() < 2 which is ugly. I really want the final trigger to run only once and at the end after all the per row stuff has happened. Unfortunately, CONSTRAINT TRIGGER s are FOR EACH ROW only, and FOR STATEMENT triggers actually fire once per statement within the triggers, not just once per initial statement that started it. I've looked through

Unnesting a list of JSON objects in PostgreSQL

时光怂恿深爱的人放手 提交于 2019-12-13 02:16:54
问题 I have a TEXT column in my PostgreSQL (9.6) database containing a list of one or more dictionnaries, like those ones. [{"line_total_excl_vat": "583.3300", "account": "", "subtitle": "", "product_id": 5532548, "price_per_unit": "583.3333", "line_total_incl_vat": "700.0000", "text": "PROD0008", "amount": "1.0000", "vat_rate": "20"}] or [{"line_total_excl_vat": "500.0000", "account": "", "subtitle": "", "product_id": "", "price_per_unit": "250.0000", "line_total_incl_vat": "600.0000", "text":

PostgreSQL aggregate JSON recordset keys by row

半世苍凉 提交于 2019-12-12 18:33:17
问题 I have data stored in JSON arrays for each row in a PostgreSQL table like so: id data ------------------------------------------------- 1 [{"a": 1, "b": 2}, {"a": 3, "b":2}] 2 [{"a": 5, "b": 8}, {"a": 9, "b":0}] How can I get the sum of specific keys in the recordsets grouped by id? Here is an example of the desired result set: id a b ------------------------------------------------- 1 4 4 2 14 8 Update: I should also mention that the data column is a jsonb data type. 回答1: select id, sum(a),

How To Restrict Delete using PL/pgSQL trigger?

穿精又带淫゛_ 提交于 2019-12-12 18:13:32
问题 If the client user is trying to delete more than 5 records from a Table i want to restrict that using a trigger. I have a basic idea to do that but i don't know how to implement the Idea. I appreciate any HELP. Basic Idea : In Trigger IF TG_OP = Delete and the count of records to be deleted are more than 5 then Restrict. CREATE TRIGGER adjust_count_trigger BEFORE DELETE ON schemaname.tablename FOR EACH ROW EXECUTE PROCEDURE public.adjust_count(); CREATE OR REPLACE FUNCTION adjust_count()

Postgresql sharding with citus extension not working

可紊 提交于 2019-12-12 05:53:11
问题 I am using Postgresql with citus extension for sharding and unable to shard tables like below. Below table has a primary key and 2 unique keys. I am trying to shard against column with primary key i.e pid . Note : I am not allowed to change the table structure. These tables are created by tool. CREATE TABLE person ( pid bigint NOT NULL, name character varying(100), address_pid bigint NOT NULL, address_type character varying(100), CONSTRAINT id_pkey PRIMARY KEY (pid), CONSTRAINT addr_id UNIQUE

jBPM 7.3.0 persistence with Postgres 9.6

只愿长相守 提交于 2019-12-12 05:00:02
问题 I'm trying to set the persistence in jbpm-installer-7.3.0.Final with Postgres 9.6. After MANY attempts, I am able to start the server and the console without errors, but from the workbench interface, I'm unable to use Processes or Tasks. It shows a popup saying: Process Definitions could not be loaded. Check if the jBPM Capabilities are enabled and if the remote server is correctly set up. in the Wildfly deployment console I can see: [org.jbpm.workbench.ks.integration.KieServerDataSetManager]

Update key value in jsonb array of objects

走远了吗. 提交于 2019-12-11 16:18:24
问题 I have the following table company with a jsonb column named log : - |code | log ----------------------------------------------------------------------------- |K50 | [{"date": "2002-02-06", "type": "Chg Name", "oldvalue": "TEH "}, {"date": "2003-08-26", "type": "Chg Name", "oldvalue": "TEOA "}] |C44 | [{"date": "2003-05-07", "type": "Chg Name", "oldvalue": "CDE "}] How to trim the trailing blanks in the oldvalue ? 回答1: You can do it with a mix of jsonb functions and operators: UPDATE company

Azure PostgreSQL Server Service Collation Create Error

妖精的绣舞 提交于 2019-12-10 18:29:22
问题 I'm trying to import my current existing database to postgre instance that is running on Azure PostgreSQL Server I already configured my azure postgresql server parameters to use encoding as UTF8 (I'm not sure that it's applying without restart but even if i don't have option to restart it) I'm trying to do this action with this command: sudo -u postgres pg_dump --encoding="UTF-8" --no-owner DBNAME | psql --host=xxx.postgres.database.azure.com --port=5432 --username=xxx@yyy --dbname=DBNAME

Why cannot create partitioning table

穿精又带淫゛_ 提交于 2019-12-10 18:13:13
问题 I'm trying to create simple table with partitions. this is my command: CREATE TABLE measurement ( city_id int not null, logdate date not null, peaktemp int, unitsales int ) PARTITION BY RANGE (logdate); this is the error I got: SQL Error [42601]: ERROR: syntax error at or near "PARTITION" Unable to understand with is the problem.. I am using PostgreSQL 9.6.3 回答1: "Declarative table partitioning", that is partitioning as a first-class feature of the DBMS with its own syntax, was added in