From: | "Milen A(dot) Radev" <milen(at)radev(dot)net> |
---|---|
To: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: Who knows this SELECT in PostgreSQL |
Date: | 2009-06-06 17:59:11 |
Message-ID: | h0eapc$bbl$1@ger.gmane.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Michael Monnerie написа:
> Dear gurus, I'm sure someone knows immediately how to translate this
> mysql to postgresql:
>
> SELECT GROUP_CONCAT(dbmail_messageblks.messageblk
> ORDER BY dbmail_messageblks.is_header DESC SEPARATOR '')
> FROM dbmail_messages
> JOIN dbmail_messageblks ON
> (dbmail_messages.physmessage_id=dbmail_messageblks.physmessage_id)
> WHERE dbmail_messages.message_idnr='${MSG_UID}'
> GROUP BY dbmail_messages.message_idnr"
>
> It should simply return the whole message which can be truncated to
> pieces into dbmail_messageblks and return it as a single entity. I found
> this for mysql and would like to rewrite the shell script to postgresql,
> but am stuck at this select.
>
> mfg zmi
CREATE AGGREGATE public.array_agg(ANYELEMENT) (
SFUNC = ARRAY_APPEND,
STYPE = ANYARRAY,
INITCOND = '{}'
);
SELECT
ARRAY_TO_STRING(public.ARRAY_AGG(b.messageblk),'') AS the_message
FROM
dbmail_messages AS m
JOIN
dbmail_messageblks AS b
ON
(m.physmessage_id = b.physmessage_id)
WHERE
m.message_idnr = '${MSG_UID}'
GROUP BY
m.message_idnr;
If you can wait for or want to test version 8.4 (which is in Beta
right now and would be released relatively soon) you can skip the
creation of the aggregate.
--
Milen A. Radev
From | Date | Subject | |
---|---|---|---|
Next Message | Lutz Steinborn | 2009-06-08 06:28:59 | nonremovable row versions |
Previous Message | Michael Monnerie | 2009-06-06 15:14:36 | Who knows this SELECT in PostgreSQL |