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

How to create a sequence for a table which was created by selecting data from...

I have created a new table by selecting data from an existing table: CREATE TABLE polygon2 AS SELECT gid, geom FROM polygon1; CREATE SEQUENCE polygon2_gid_seq; SELECT SETVAL('polygon2_gid_seq', (SELECT...

View Article


Mysterious inequality behavior when comparing date strings

Can someone explain this mysterious Postgres behavior? I’m performing the following queries at the psql command line. mydb=> select '20150526' > '2015-05-25'; -[ RECORD 1 ] ?column? | t mydb=>...

View Article


Get 10th and 90th percentile by customer

I have a table which contains customers and scores (based on different factors, irrelevant in this case; a customer can have multiple scores), which looks like this: customer_id | score |...

View Article

To manage pointers to big binary files in Partial index of PostgreSQL?

Assume you have binary data files of size > 1GB. These files contains events each marked by 585 in hex. I convert the binary to hex by xxd -ps data.raw | sed ':a;N;$!ba;s/n//g'. I can get wanted hex...

View Article

Image may be NSFW.
Clik here to view.

How to find similar (but different) names with the same soundex value?

I got the output with the same name and same soundex value, but I want the result which has similar name and same soundex value. Can anyone help me to do this?

View Article


Minimizing SELECT latency in PostgreSQL

I am evaluating Postgres 9.4 performance on a machine with Intel i7 quad-core 3.6 GHz CPU, 8 GB ram, and 7400 rpm HDD (no RAID) running Linux Mint. The DB schema has the following table: Table...

View Article

Subquery magic in PostgreSQL

I have a query: update product_product set (write_date, default_code) = (LOCALTIMESTAMP, 'update') where product_tmpl_id in ( select distinct product_tmpl_id from product_template where type='import');...

View Article

Would like to know why this query is behaving this way?

I have an emp table, with schema and some initial values like below: emp_id | name | last_name | role_id --------+------+-----------+--------- 1 | hell | bell | 1 2 | well | tell | 2 (2 rows) And...

View Article


Raster and Geometry ST_Intersects slows when add buffer in PostGIS

I have a table containing rasters for the whole of the UK, the below query is very fast (0.1 seconds) and gets all of the rasters that are intersected by the line between a start point and an end...

View Article


Multiple LEFT JOIN in PostgreSQL

I got a “nice” problem with a query in PostgreSQL with a multiple join SELECT DISTINCT "Monitoraggio_L001_L008_2015_aprile"."ID", "Monitoraggio_L001_L008_2015_aprile"."Ordine",...

View Article

Efficient structure for querying membership in many-to-many relationship...

I’m working on an application with a PostgreSQL back end. There is a many-to-many relationship between items in one table and tags in another table. The specs require that the application be able to...

View Article

PostgreSQL partial index unused when created on a table with existing data

In PostgreSQL 9.3, I am attempting to create an efficient index on a rarely-used (0.00001% of total records) boolean column. To that end, I discovered this post on SO:...

View Article

How to calculate shift hours in postgres?

I have table like below where (I=In) and (O=Out): id | date | time | status | employee_id ----+------------+----------+--------+------------- 1 | 2015-07-01 | 11:00:00 | O | 1 2 | 2015-07-01 | 08:00:00...

View Article


Is it recommended to install extensions into pg_catalog schema?

Since objects in pg_catalog schema are implicitly in the search_path (docs), would it be recommended to install extensions in that schema?

View Article

How to atomically replace table data in PostgreSQL

I want to replace the entire contents of a table, without affecting any incoming SELECT statements during the process. The use case is to have a table which stores mailbox information that is regularly...

View Article


postgres fetch record from partitions without the check constraints

I am using postgres 9.4, I have a messages table that has 100M records, messages belongs to one feed_id, so I decided to partition the tables by posted_at. Table "public.messages" Column | Type |...

View Article

What's the greatest value for postgres maintenance_work_mem?

I set 1960MB successfully for maintenance_work_mem, and got about 30% performance improvement on my COPY batch inserts. So I’m trying to run the import with even more mem (my machine has 32GB)....

View Article


Compare two databases

I want to compare two PostgreSQL database dumps. The output of pg_dump is not sorted. This makes tools like diff useless. Background: We update the way we set up a custom database. After our...

View Article

Get min and max row from table

From a table with the columns: id(pk), type_id, book_id, title_id, page_id, lines(int4), created_at(date) How can I select the row with min(lines) and max(lines) for (type_id, book_id, title_id,...

View Article

Challenges with Key with Gaps?

I had a mistake with a trigger which resulted in errors in PostgreSQL 9.4.3 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit. Each time during the error, the primary key of...

View Article
Browsing all 1138 articles
Browse latest View live