pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Arrays and count ()
3+ messages / 2 participants
[nested] [flat]

* Arrays and count ()
@ 1999-04-27 13:48  Mr M Pacey <M.Pacey@liverpool.ac.uk>
  0 siblings, 0 replies; 3+ messages in thread

From: Mr M Pacey @ 1999-04-27 13:48 UTC (permalink / raw)
  To: pgsql-sql

I'm having difficulties formulating what I thought was a simple
query in 6.3.2. I have a table defined like this:

create table sentence
(
  typenum int4,
  wordpos int4,
  words text[],
  tags  text[]
);

What I'd like to do is, e.g. select all instances of tags[1] and
display the frequency values for each unique (distinct) entry.

The query I tried was:

select sentence.tags[1], count (*) from sentence group by
sentence.tags[1];

Which fails to parse.

Trying to work backwards I try constructing a related command:

select count (sentence.tags[1]) from sentence;

And am treated to the error message:

PQexec() -- Request was sent to backend, but backend closed the channel
before responding.
        This probably means the backend terminated abnormally before or
while processing the request.

Is this a bug, or am I completely failing to understand one or more
of the concepts involved here?

Mike Pacey.

P.S. Please cc any reply directly to me, as I'm not currently subbed to
the list.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Arrays and count()
@ 1999-04-27 14:04  Mr M Pacey <M.Pacey@liverpool.ac.uk>
  0 siblings, 1 reply; 3+ messages in thread

From: Mr M Pacey @ 1999-04-27 14:04 UTC (permalink / raw)
  To: pgsql-sql

I'm having difficulties formulating what I thought was a simple
query in 6.3.2. I have a table defined like this:

create table sentence
(
  typenum int4,
  wordpos int4,
  words text[],
  tags  text[]
);

What I'd like to do is, e.g. select all instances of tags[1] and
display the frequency values for each unique (distinct) entry.
The query I tried was:

select sentence.tags[1], count (*) from sentence group by
sentence.tags[1];

Which fails to parse. Trying to work backwards I try constructing a
related command:

select count (sentence.tags[1]) from sentence;

And am treated to the error message:

PQexec() -- Request was sent to backend, but backend closed the channel
before responding.
        This probably means the backend terminated abnormally before or
while processing the request.

Is this a bug, or am I completely failing to understand one or more
of the concepts involved here?

Mike Pacey.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [SQL] Arrays and count()
@ 1999-04-27 15:07  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Mr M Pacey <M.Pacey@liverpool.ac.uk>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 1999-04-27 15:07 UTC (permalink / raw)
  To: Mr M Pacey <M.Pacey@liverpool.ac.uk>; +Cc: pgsql-sql

Mr M Pacey <M.Pacey@liverpool.ac.uk> writes:
> select sentence.tags[1], count (*) from sentence group by
> sentence.tags[1];

> Which fails to parse.

Yes, I get 'Illegal use of aggregates or non-group column in target
list' with current sources.  Without having looked, my guess is that
the system is too dumb to realize that the same array element is being
named at both places (ie, it's not exploiting the fact that the
subscripts are constant).  Not sure how hard this might be to fix.

> select count (sentence.tags[1]) from sentence;
> PQexec() -- Request was sent to backend, but backend closed the channel
> before responding.

Still crashes in 6.5-current :-(.  Will look into it.

As a workaround, you could probably select the tag data into a temporary
table and then do the group by on the temp table...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~1999-04-27 15:07 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-04-27 13:48 Arrays and count () Mr M Pacey <M.Pacey@liverpool.ac.uk>
1999-04-27 14:04 Arrays and count() Mr M Pacey <M.Pacey@liverpool.ac.uk>
1999-04-27 15:07 ` Re: [SQL] Arrays and count() Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox