Quantcast
Channel: Question and Answer » postgresql
Browsing all 1138 articles
Browse latest View live

Does updating a jsonb column trigger updates on all expression indexes on...

I am using the jsonb type in PostgreSQL. I frequently make updates of the following kind (where jdoc is a jsonb column): UPDATE my_table SET jdoc = jdoc || '{a: "Hello World!"}'::jsonb WHERE id = 123 I...

View Article


How to store the result of multiple select queries into one csv file?

How to store the result of all of the queries below into one CSV file in PostgreSQL by executing one COPY (……) to…. statement. select id,name from first; select id,salary,father_name from second;...

View Article


Grouping data by year based on two timestamp columns

My data table has the following columns: id INTEGER, name TEXT, created TIMESTAMP, deleted TIMESTAMP I want to product a report of the count of each name (which can appear several times in the table)...

View Article

CartoDB – PostgreSQL row_number() using PostGIS ST_Distance

I’m currently working on a query that should return a subset (i.e. “new”) CartoDB table sorted by proximity to a given point. I want to display labels on the map corresponding to the closest, second...

View Article

PostgreSQL optimistic reads (equivalent to SQL Server's Read Committed Snapshot)

Does PostgreSQL provide a built-in optimistic concurrency control mechanism such as SQL Server’s Read Committed Snapshot Isolation? Readers can read all the rows without blocking, but writes will block...

View Article


Postgres, promoting slave to master issue

We had the following setup in place db01 -> Master Postgres 9.3 db02 -> Slave Postgres 9.3 Master data got corrupted (logically) and as soon as it was identified we shutdown the server. Dev team...

View Article

Use specific array column in the where clause

Having a function that returns an array and in a query we use the function to return results such as: {"TUNDUMA GOING (BORDER)","ARRIVAL DATE",09/01/2016,22,"AT CHECKPOINT"} {"TUNDUMA RETURN...

View Article

Postgres CTE query for a single row not optimized

From my database I am trying to get a weighted sum of a user’s stats, and I will only be querying the table one or two users at a time, so I wrote it as a view. Since it’s a view, I pretend to...

View Article


Postgres 8.1 logging slow queries twice

For every slow query logged, there is another STATEMENT follows it in my log file. 2016-03-22 11:11:23 KST [9998]: [1-1] LOG: duration: 4796.936 ms statement: SELECT 1 FROM DUAL 2016-03-22 11:11:23 KST...

View Article


Cursor help on large spatial query in PostgreSQL

I have two very large tables on which I want to perform a spatial query. UPDATE table_a SET att_1 = b.att_1, att_2 = b.att_2 FROM table_a AS a JOIN table_b AS b ON ST_Contains(a.geom,b.geom); I am...

View Article

How can I restrict users to see only tables they can SELECT from

I have a redshift database with many schemas and tables. I created a group of users and granted them with permissions to view (select) tables in some particular schema: CREATE GROUP data_viewers; GRANT...

View Article

Combining 2 SELECT queries and printing the results in PostgreSQL

I have 2 queries which I want to use together to produce one output result to the user. The output describes to the user the journey to take to from A to B. I keep getting a syntax error when I try to...

View Article

Set a default value for a jsonb property in PostgreSQL

Let’s say that I have a jsonb column with documents like: { "lead": "The lead", "video": "An URL to the video" } In some cases I also need to store the name of a picture that’s uploaded to the server...

View Article


Two names for a column

I have a column named foo in a table. I have constructed queries in scripts, which use this name. I would now like to rename the column in the table to bar. This will break the scripts (there are...

View Article

Why would adding LIMIT 200 cause a query to slow down?

I am trying to debug a slow query on a PostgreSQL 9.1.13 database, and I am a bit at loss. The exact query generated by the ORM framework is: SELECT "core_product"."sales_price",...

View Article


How to check point intersection with bbox made from two points?

I have two points which represents lower left and upper right point of BBOX. I have one point which SHOULD be somewhere inside and I want to test it. I have all of them as ‘geometry(POINT, 4326)’ data...

View Article

How can I add the PostGIS extension?

I’m experiencing difficulties when trying to add the PostGIS extension to PostgreSQL. I wasn’t able to add the extension during the installation because of an error. Now I’m trying to add the extension...

View Article


Use array of composite type as function parameter and access it

I have created a type Books in Postgres which has 2 numeric fields and 2 varchar fields. I want to send an array of Books to a function to INSERT those values in a matching table. This is my type:...

View Article

QGIS Add feature python script

New to python, and been looking at this for a while, trying to write a scrip to automate a process we need to carry out in QGIS a few thousand times. As part of this I need to create a feature into an...

View Article

Poor Query performance in postgresql 9.3

I have a simple query which is taking about 2 minutes to complete. select distinct a.statename, a.districtname, count(b.rel_globalid) as samplescollected from fulladmin a join gridpoint_attach_view b...

View Article
Browsing all 1138 articles
Browse latest View live