Re: Why does this array query fail?

From: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why does this array query fail?
Date: 2013-09-17 22:48:47
Message-ID: CAD3a31VL0BCu-fkUDx29cVZoDoc_XoPp_0-HtejkKwQ2-TX0gA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks again David. I think that's all making sense to me now, except I
want to follow up on your last point:

Yes, un-nesting can make the problem go away though it too is unusual. For the
> most part either use relations/sets or use arrays (for a specific
> component of the schema). Your example mixes the two which makes using
> that part of the schema difficult.

I'm not sure exactly what you're saying here, but it's important to me
because I've recently had to do a lot with arrays, and continue to have to
do so. What I'm working with is similar to the example I gave you, but let
me be more concrete.

I'm working with a social service agency. Every time they see a client
they fill out an "encounter" record. Part of what is tracked is what kind
of services were provided, which is stored as an array of "service codes"
within the encounter. The encounter also has a date.

So I frequently have to provide information like "what were all the types
of services this client received during the last quarter?" or "show me all
the clients who received service X last year." I've learned enough to use
ANY, array_agg and unnest to get through these queries, but if I'm going
about this wrong or there's a better way to do it I'd love to know about it!

Ken

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lonni J Friedman 2013-09-17 22:49:26 Re: upgrade from 9.2.x to 9.3 causes significant performance degradation
Previous Message Andres Freund 2013-09-17 22:47:26 Re: upgrade from 9.2.x to 9.3 causes significant performance degradation