Re: [GENERAL] SQL help - multiple aggregates

2016-08-18 Thread Ladislav Lenart
way (by creating an aggregate function, perhaps) Perhaps the following is what you need (not tested!): SELECT custid , sum(CASE WHEN vendid = 415 THEN 1 ELSE 0 END) AS c415 , sum(CASE WHEN vendid = 983 THEN 1 ELSE 0 END) AS c983 , sum(CASE WHEN vendid = 1256 THEN 1 ELSE 0 END) AS

Re: [GENERAL] consolidating data with window functions

2016-08-02 Thread Ladislav Lenart
null), (5, 'e', 3), (6, 'f', null), (7, 'g', null), (8, 'h', 4), (9, 'i', null), (10, 'j', 5) ) AS t(a,b,c) ) , grouped_source AS ( SELECT source.* ,

Re: [GENERAL] using a postgres table as a multi-writer multi-updater queue

2015-11-23 Thread Ladislav Lenart
t. Also, if you aim on 9.5 (not released yet), it will introduce: SELECT... FOR UPDATE SKIP LOCKED -- this is new which supports exactly this use-case (i.e. to implement a job queue). HTH, Ladislav Lenart -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] to pg

2015-09-25 Thread Ladislav Lenart
ut a partial unique index as documented here: http://www.postgresql.org/docs/9.4/static/indexes-partial.html I.e.: CREATE UNIQUE INDEX ON pick (load_id) WHERE picked = 'y'; HTH, Ladislav Lenart -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To m

[GENERAL] [Q] Serializable

2015-09-24 Thread Ladislav Lenart
read/write dependencies among transactions)? This is on 9.4. Thank you in advance, Ladislav Lenart -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] UPDATE an updatable view

2015-08-28 Thread Ladislav Lenart
ke of completeness... If the value (empname in the above example) can be NULL, the compare does not work, because SELECT NULL = NULL returns NULL which is treated as FALSE. But I am sure you know this :-) HTH, Ladislav Lenart -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] newsfeed type query

2015-04-30 Thread Ladislav Lenart
t; in the subselect and the sheer size of the tables, even when we could handle > it > as an index-only scan. > > > On Apr 29, 2015, at 1:18 PM, Ladislav Lenart wrote: > >> I would expect the overall query to return only 60F nad 55F as the most >> recent >>

Re: [GENERAL] newsfeed type query

2015-04-29 Thread Ladislav Lenart
On 29.4.2015 18:54, Jonathan Vanasco wrote: > > On Apr 29, 2015, at 12:25 PM, Ladislav Lenart wrote: > >> Could you please explain to me the error(s) in my reasoning? > > Let me just flip your list in reverse... and add in some elements (marked > with a *): > &

Re: [GENERAL] newsfeed type query

2015-04-29 Thread Ladislav Lenart
s usage of the CTE is also of a different format that I've > used in the past. > > I think i'll be able to patch together some performance improvements now, > that will last until the database structure changes. > > > On Apr 29, 2015, at 6:54 AM, Ladislav Lenart

Re: [GENERAL] newsfeed type query

2015-04-29 Thread Ladislav Lenart
ublish DESC > LIMIT 10 > ; I think you can propagate ORDER BY and LIMIT also to the subqueries of the UNION, i.e.: select... from ( ( select... from posting where... -- friends order by timestamp_publish desc limit 10 ) union (

Re: [GENERAL] newsfeed type query

2015-04-29 Thread Ladislav Lenart
group_id in ( select group_id from memberships where user_id = ? ) ) t group by t.posting_id ) select posting.*, posting_ids.from_friend, posting_ids.from_group, posting_ids.from_friend or posting_ids.from_group as from_any, posting_ids.from_friend and posting_ids

Re: [GENERAL] [Q] Update from a table

2013-12-05 Thread Ladislav Lenart
On 5.12.2013 15:14, Tom Lane wrote: > Ladislav Lenart writes: >> What happens if I issue UPDATE SET FROM... but with incomplete/buggy WHERE >> condition and thus SEVERAL rows from the from_list match ONE row to update? > > Any given row will be updated at most once. Howev

[GENERAL] [Q] Update from a table

2013-12-05 Thread Ladislav Lenart
Hello. What happens if I issue UPDATE SET FROM... but with incomplete/buggy WHERE condition and thus SEVERAL rows from the from_list match ONE row to update? Thank you in advance, Ladislav Lenart -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your

Re: [GENERAL] [Q] Table aliasing

2013-10-04 Thread Ladislav Lenart
On 4.10.2013 15:11, David Johnston wrote: > Ladislav Lenart wrote >> * Should I alias one of the references to deal? >> * The above query works the same both with and without an alias, so is it >> simply >> a matter of taste / good practice? >> * Where can I fin

[GENERAL] [Q] Table aliasing

2013-10-04 Thread Ladislav Lenart
Hello. I have a noob question about table aliases in SQL. Suppose the following query: SELECT * FROM deal WHERE deal.id IN ( SELECT DISTINCT deal.id FROM deal JOIN partner_share ON deal.id = partner_share.deal_id JOIN partner ONshare.partne

Re: [GENERAL] [PG9.1] CTE usage

2013-09-16 Thread Ladislav Lenart
On 16.9.2013 17:30, David Johnston wrote: > Ladislav Lenart wrote >> Hello all. >> >> I am curious about the following usage of CTEs: >> >> Imagine three tables: >> * item (id, item_type1_id, item_type2_id, ...) >> * item_type1 (id, ...) >> * i

Re: [GENERAL] [PG9.1] CTE usage

2013-09-16 Thread Ladislav Lenart
On 16.9.2013 17:12, Adrian Klaver wrote: > On 09/16/2013 07:38 AM, Ladislav Lenart wrote: >> On 16.9.2013 15:50, Adrian Klaver wrote: >>> On 09/16/2013 04:57 AM, Ladislav Lenart wrote: >>>> On 16.9.2013 13:26, Alban Hertroys wrote: >>> > >>>

Re: [GENERAL] [PG9.1] CTE usage

2013-09-16 Thread Ladislav Lenart
On 16.9.2013 15:50, Adrian Klaver wrote: > On 09/16/2013 04:57 AM, Ladislav Lenart wrote: >> On 16.9.2013 13:26, Alban Hertroys wrote: > >>> >>> Wouldn't it be much easier to define an FK constraint with ON DELETE >>> CASCADE? >>> With tha

Re: [GENERAL] [PG9.1] CTE usage

2013-09-16 Thread Ladislav Lenart
WHERE item_typeX.id NOT IN ( SELECT item_typeX_id FROM ok_items WHERE item_typeX_id IS NOT NULL ) ) everything works as it should. Ladislav Lenart On 16.9.2013 13:57, Ladislav Lenart wrote: > On 16.9.2013 13:26, Alban Hertroys wrote: >> On 16 September 2013 11:

Re: [GENERAL] [PG9.1] CTE usage

2013-09-16 Thread Ladislav Lenart
On 16.9.2013 13:26, Alban Hertroys wrote: > On 16 September 2013 11:58, Ladislav Lenart wrote: >> Hello all. >> >> I am curious about the following usage of CTEs: >> >> Imagine three tables: >> * item (id, item_type1_id, item_type2_id, ...) >>

[GENERAL] [PG9.1] CTE usage

2013-09-16 Thread Ladislav Lenart
Thank you in advance, Ladislav Lenart -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] Circular references

2013-06-21 Thread Ladislav Lenart
Hello. I think this CAN happen in practice when the constraints are DEFERRED, because as such are checked at COMMIT time. HTH, Ladislav Lenart On 21.6.2013 05:08, Tom Lane wrote: > Melvin Call writes: >> I was given a dump of an existing remote schema and database, and the >>