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

In Postgres, is it possible for me to have a table partitioning constraint...

Say I have the following schema for my Postgres database: CREATE TABLE sources ( source TEXT NOT NULL, PRIMARY KEY (source) ); CREATE TABLE ipaddrs ( addr INET ) INHERITS (source): CREATE TABLE domains...

View Article


Is it worth it to run VACUUM on a table that only receives INSERTs?

In a 2015 re:Invent talk, AWS mentioned that vacuum should be run not only after updates or deletes but also after inserts. Here is the relevant part of the talk:...

View Article


How to design a database

The file which contains the day to day activities of each employee. And it shows the detailed description of employee what they done at work time. So these files are prepared by employee. Now, my...

View Article

dumping database with “compressed data is corrupt” errors

I’m using pg_dump to dump a large (396 GB) PostgreSQL database: pg_dump --clean --create mydatabase After running for a day, a statement fails with ERROR: compressed data is corrupt and pg_dump exits....

View Article

Can not connect to psql

anybody can help with this error? search search and search and nothing solution not works from all the web…. psql: could not connect to server: No such file or directory Is the server running locally...

View Article


Read only postgres table, except by trigger

Suppose the following situation: I have a product_stock table and a stock_transaction_log table. Currently whenever there is an increase/decrease in a product’s stock, I update the product_stock table...

View Article

Select column values linked to exact set of values in another column

Given the below chats_users table in Postgres 9.5, with integer columns chat_id and user_id, I want to find the chat_id associated with an exact set of user_ids, for example: user_id IN (1, 3) =>...

View Article

Started using UUID's as primary key, would like to execute union of entities...

Some of my newer tables are now using UUID type fields as PKey and older tables are still using bigserial. I have several tables (let’s call them entities) I would like to query returning the primary...

View Article


Speeding up a GROUP BY, HAVING COUNT query

I’m trying to speed up this query in Postgres 9.4: SELECT "groupingsFrameHash", COUNT(*) AS nb FROM "public"."zrac_c1e350bb-a7fc-4f6b-9f49-92dfd1873876" GROUP BY "groupingsFrameHash" HAVING COUNT(*)...

View Article


Incorrect Query Result

I have a table with the following data: unit_codes kind | code ------------------------- UNIT | PS3b UNIT | PS3B UNIT | PS3C If I run this select I get the correct result. select * from unit_codes...

View Article

Postgres: querying jsonb array with an array

My products table has a jsonb column called ‘specs’. This specs hash will often have an array field, let’s call it ‘spec_options’. When querying this table, I need to find any product that has certain...

View Article

Calculate rolling sum over 7 consecutive day period on PostgreSQL

I need to get the rolling sum over a period of 7 days for each row (1 row per day). For example: | Date | Count | 7-Day Rolling Sum | ------------------------------------------ | 2016-02-01 | 1 | 1 |...

View Article

Why is PL/Python untrusted?

According to the docs: PL/Python is only available as an “untrusted” language, meaning it does not offer any way of restricting what users can do in it and is therefore named plpythonu. A trusted...

View Article


Is there a way to SELECT n ON (like DISTINCT ON, but more than one of each)

I have a table us_customers that looks like this (with hundreds of thousands of rows): +----------+----------+ | id | us_state | +----------+----------+ | 12345678 | MA | | 23456781 | AL | | 34567812 |...

View Article

Simplify geometries but keep them contiguous

I have several detailed contiguous areas. I need to turn each one into KML, but when I do so, the end result is too large (in terms of memory). Using PostGIS I need to simplify these geometries but...

View Article


Limit crosstab query based on join from outer query

In my database I have two tables, assessments, and responses, in a 1:N relationship. I have a query that looks a little something like this WITH "cross_responses" AS (select * from crosstab( $$select...

View Article

Postgres query running faster, when running on more data

* Update * After several days, I re tried the query. Suddenly the performance was similar for older date_id’s (using in (X,X) and =X), however, the problem still persists with new date_id’s. I guess...

View Article


can we call CRUD operations as service methods?

I was asked this question by one of my superiors. The usual operations we do on database table from Service layer in java is Create, Update, Retrieve, Delete. These operations are basically services,...

View Article

Postgis Functional Index on st_pointonsurface() Ignored

If I define the following table… CREATE TABLE tbl_vast_importance( id bigserial PRIMARY KEY, geom geometry(MultiPolygon,4326) ); CREATE INDEX ON tbl_vast_importance USING GIST (geom); CREATE INDEX ON...

View Article

PostgreSQL UNIQUE constraint error message

On Appendix A: PostgreSQL error codes, it says: For some types of errors, the server reports the name of a database object (a table, table column, data type, or constraint) associated with the error;...

View Article
Browsing all 1138 articles
Browse latest View live