Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread Tom Lane
"Glen M. Witherington" writes: > And here's the query I want to do, efficiently: > SELECT * FROM c > JOIN b ON b.id = c.b_id > JOIN a ON a.id = b.a_id > WHERE a.id = 3 > ORDER BY b.created_at DESC > LIMIT 10 At least for that dummy data, this seems sufficient: regression=# create index on b

[GENERAL] date type changing to timestamp without time zone in postgres 9.4

2015-05-30 Thread Rishi Gokhale
When I create a table with a column whose type is date the type gets forced to timestamp without timezone after it gets created ops=# CREATE TABLE test ( ops(# namevarchar(40) NOT NULL, ops(# start date NOT NULL ops(# ); CREATE TABLE ops=# \d test; Table "public.

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread Glen M. Witherington
On Sat, May 30, 2015, at 11:33 PM, David G. Johnston wrote: > This is one problem with using made up surrogate keys... > > The PK of A is a component of both the PK of B and the PK of C but you throw > that information away by using serial fields for PKs instead.  You should > have unique ind

Re: [GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread David G. Johnston
On Saturday, May 30, 2015, Glen M. Witherington wrote: > Sorry about the horrendous subject, let me explain by example: > > Let's take this schema: > > > ``` > CREATE TABLE a ( > id bigserial PRIMARY KEY, > created_at timestamp with time zone NOT NULL DEFAULT NOW() > ); > > CREATE TABLE b(

[GENERAL] Curious case of huge simple btree indexes bloat.

2015-05-30 Thread Maxim Boguk
Hi, On the one of databases under my support I found very curious case of the almost endless index bloat (index size stabilises around 100x of the original size). Graph of one index size history attached (other indexes have an similar time/size graphs). The table have 5 indexes and they all have

[GENERAL] Efficient sorting the results of a join, without denormalization

2015-05-30 Thread Glen M. Witherington
Sorry about the horrendous subject, let me explain by example: Let's take this schema: ``` CREATE TABLE a ( id bigserial PRIMARY KEY, created_at timestamp with time zone NOT NULL DEFAULT NOW() ); CREATE TABLE b( id bigserial PRIMARY KEY, a_id bigint NOT NULL REFERENCES a(id), create

Re: [HACKERS] Re: [GENERAL] 9.4.1 -> 9.4.2 problem: could not access status of transaction 1

2015-05-30 Thread Andres Freund
On 2015-05-30 00:52:37 -0300, Alvaro Herrera wrote: > Andres Freund wrote: > > > I considered for a second whether the solution for that could be to not > > truncate while inconsistent - but I think that doesn't solve anything as > > then we can end up with directories where every single offsets/me

Re: [GENERAL] replacing jsonb field value

2015-05-30 Thread Glyn Astill
- Original Message - > From: Andreas Kretschmer > To: pgsql-general@postgresql.org > Cc: > Sent: Saturday, 30 May 2015, 13:10 > Subject: Re: [GENERAL] replacing jsonb field value > > Michael Paquier wrote: > >> >> Append the new value to it the existing field, jsonb has as proper

Re: [GENERAL] How to retrieve Comment text using SQL, not psql?

2015-05-30 Thread Melvin Davidson
>select obj_description('table1'::regclass, 'pg_class'); That will only show the table comment. My query shows that table comment AND any column comments! On Sat, May 30, 2015 at 9:37 AM, Adrian Klaver wrote: > On 05/30/2015 04:48 AM, Bob Futrelle wrote: > >> Using pgAdmin3 I've tried this and

Re: [GENERAL] How to retrieve Comment text using SQL, not psql?

2015-05-30 Thread Adrian Klaver
On 05/30/2015 04:48 AM, Bob Futrelle wrote: Using pgAdmin3 I've tried this and variations on it. All are rejected. select COMMENT ON TABLE articlestats No answer here, http://www.postgresql.org/docs/9.3/static/sql-comment.html pgAdmin3 had no problem with entering a comment:

Re: [GENERAL] How to retrieve Comment text using SQL, not psql?

2015-05-30 Thread Melvin Davidson
This will give the comment on your table and any column: SELECT DISTINCT ON (c.relname) n.nspname as schema, c.relname, a.rolname as owner, 0 as col_seq, '' as column, d.description as comment FROM pg_class c LEFT JOIN pg_attribute col ON (col.attrelid

Re: [GENERAL] replacing jsonb field value

2015-05-30 Thread Andreas Kretschmer
Michael Paquier wrote: > > Append the new value to it the existing field, jsonb has as property > to enforce key uniqueness, and uses the last value scanned for a given > key. can you show a simple example, how to append a jsonb to an jsonb-field? Maybe i'm blind, but i can't find how it works.

Re: [GENERAL] How to retrieve Comment text using SQL, not psql?

2015-05-30 Thread Pavel Stehule
Hi you can call function obj_description http://stackoverflow.com/questions/11493978/how-to-retrieve-the-comment-of-a-postgresql-database http://www.postgresql.org/docs/9.1/static/functions-info.html For tables SELECT pg_catalog.obj_description('tablename'::regclass, 'pg_class') as "Description

[GENERAL] How to retrieve Comment text using SQL, not psql?

2015-05-30 Thread Bob Futrelle
Using pgAdmin3 I've tried this and variations on it. All are rejected. select COMMENT ON TABLE articlestats No answer here, http://www.postgresql.org/docs/9.3/static/sql-comment.html pgAdmin3 had no problem with entering a comment: COMMENT ON TABLE articlestats IS 'Comprehensive data for e

Re: [GENERAL] replacing jsonb field value

2015-05-30 Thread Michael Paquier
On Sat, May 30, 2015 at 11:52 AM, john.tiger wrote: > using 9.4.2 > > suppose we have > create table test (id serial primary key, data jsonb); > insert into test (data) values ({"a":1, "b":2}) > > want to replace "b" with 3 > > okay, we are retrieving entire record > res = select * from test where