postgresql-9.3

Query combinations with nested array of records in JSON datatype

半世苍凉 提交于 2019-11-26 21:24:17
问题 I'm working on a Rails application that utilizes the Postgres JSON data type. I have a JSON column called data in a table called reports . Let's say I have multiple entries like this: Entry 1: {"objects":[{"album": 1, "src":"fooA.png", "pos": "top"}, {"album": 2, "src":"barB.png", "pos": "top"}], "background":"background.png"} Entry 2: {"objects":[{"album": 1, "src":"fooA.png", "pos": "top"}, {"album": 2, "src":"barC.png", "pos": "top"}], "background":"bacakground.png"} Entry 3: {"objects":[{

Allow docker container to connect to a local/host postgres database

不想你离开。 提交于 2019-11-26 21:20:31
I've recently been playing around with Docker and QGIS and have installed a container following the instructions in this tutorial . Everything works great, although I am unable to connect to a localhost postgres database that contains all my GIS data. I figure this is because my postgres database is not configured to accept remote connections and have been editing the postgres conf files to allow remote connections using the instructions in this article . I'm still getting an error message when I try and connect to my database running QGIS in Docker: could not connect to server: Connection

Refresh a materialized view automatically using a rule or notify

大憨熊 提交于 2019-11-26 19:35:45
I have a materialized view on a PostgreSQL 9.3 database which seldom changes (about twice a day). But when it does, I'd like to update its data promptly. Here is what I was thinking about so far: There is a materialized view mat_view which gets its data from tables table1 and table2 using some join statement. Whenever something in table1 or table2 changes, I already have a trigger wich updates a little configuration table config consisting of table_name | mat_view_name | need_update -----------+---------------+------------ table1 | mat_view | TRUE/FALSE table2 | mat_view | TRUE/FALSE So if

PostgreSQL 9.3: Dynamic pivot table

偶尔善良 提交于 2019-11-26 18:39:41
问题 I have a table called as matrix which contains two columns namely cola and colb as shown below: Table : matrix create table matrix ( cola varchar(10), colb varchar(10) ); Insertion of rows : insert into matrix values('A1','B1'),('A2','B2'),('A3','B3'),('A4','B4'), ('A5','B5'),('A6','B6'),('A7','B7'),('A8','B8'), ('A9','B9'),('A10','B10'),('A11','B11'),('A12','B12'), ('A13','B13'),('A14','B14'),('A15','B15'),('A16','B16'), ('A17','B17'),('A18','B18'),('A19','B19'),('A20','B20'), ('A21','B21'),

Parallel unnest() and sort order in PostgreSQL

空扰寡人 提交于 2019-11-26 17:49:24
问题 I understand that using SELECT unnest(ARRAY[5,3,9]) as id without an ORDER BY clause, the order of the result set is not guaranteed. I could for example get: id -- 3 5 9 But what about the following request: SELECT unnest(ARRAY[5,3,9]) as id, unnest(ARRAY(select generate_series(1, array_length(ARRAY[5,3,9], 1)))) as idx ORDER BY idx ASC Is it guaranteed that the 2 unnest() calls (which have the same length) will unroll in parallel and that the index idx will indeed match the position of the

Dynamic pivot query using PostgreSQL 9.3

馋奶兔 提交于 2019-11-26 17:27:14
问题 I have a table named as Product : create table product ( ProductNumber varchar(10), ProductName varchar(10), SalesQuantity int, Salescountry varchar(10) ); Sample values: insert into product values ('P1', 'PenDrive', 50, 'US') , ('P2', 'Mouse', 100, 'UK') , ('P3', 'KeyBoard', 250, 'US') , ('P1', 'PenDrive', 300, 'US') , ('P2', 'Mouse', 450, 'UK') , ('P5', 'Dvd', 50, 'UAE'); I want to generate the Salescountry's names dynamically and show the sum of SalesQuantity sale in that Country. Expected

How to convert primary key from integer to serial?

别来无恙 提交于 2019-11-26 15:33:30
In a Postgres 9.3 table I have an integer as primary key with automatic sequence to increment, but I have reached the maximum for integer . How to convert it from integer to serial ? I tried: ALTER TABLE my_table ALTER COLUMN id SET DATA TYPE bigint; But the same does not work with the data type serial instead of bigint . Seems like I cannot convert to serial ? Erwin Brandstetter serial is a pseudo data type, not an actual data type. It's an integer underneath with some additional DDL commands executed automatically: Create a sequence (with matching name by default). Set the column NOT NULL

Import psycopg2 Library not loaded: libssl.1.0.0.dylib

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 09:17:40
问题 When I try to run the command: import psycopg2 I get the error: ImportError: dlopen(/Users/gwulfs/anaconda/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib Referenced from: /Users/gwulfs/anaconda/lib/python2.7/site-packages/psycopg2/_psycopg.so Reason: image not found So far I have tried brew install openssl and have referenced (with no luck): psycopg2 installation error - Library not loaded: libssl.dylib http://joshuakehn.com/2013/10/13/Postgresapp

Allow docker container to connect to a local/host postgres database

会有一股神秘感。 提交于 2019-11-26 08:58:06
问题 I\'ve recently been playing around with Docker and QGIS and have installed a container following the instructions in this tutorial. Everything works great, although I am unable to connect to a localhost postgres database that contains all my GIS data. I figure this is because my postgres database is not configured to accept remote connections and have been editing the postgres conf files to allow remote connections using the instructions in this article. I\'m still getting an error message

Query for element of array in JSON column

喜你入骨 提交于 2019-11-26 08:16:16
问题 Recently upgraded to using PostgreSQL 9.3.1 to leverage the JSONfunctionalities. In my table I have a json type column that has a structure like this: { \"id\": \"123\", \"name\": \"foo\", \"emails\":[ { \"id\": \"123\", \"address\": \"somethinghere\" }, { \"id\": \"456\", \"address\": \"soemthing\" } ] } This is just dummy data for the purpose of the question. Is it possible to query for a specific item in the emails array based on the id? Pretty much: \"return email where id=123)\"? 回答1: