pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aron Widforss <pgsql-general@antarkt.is>
To: pgsql-general@postgresql.org
Subject: Multiple unnests in query
Date: Mon, 13 Nov 2017 02:22:58 +0100
Message-ID: <1510536178.2747282.1170204616.4A024CB2@webmail.messagingengine.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>

Good night,

Is this first query expected behavior? If so, what is the rationale? I
would have expected nine rows returned (as in my second example).

Regards,
Aron Widforss

SELECT
  unnest(ARRAY[1, 1, 2]) AS unnested1,
  unnest(ARRAY[3, 3, 4]) AS unnested2
;
 unnested1 | unnested2 
-----------+-----------
         1 |         3
         1 |         3
         2 |         4
(3 rows)

SELECT
  unnest(ARRAY[1, 1, 2]) AS unnested1,
  sec
FROM (SELECT 3 AS sec UNION ALL
      SELECT 3 AS sec UNION ALL
      SELECT 4 AS sec) test
;
 unnested1 | sec 
-----------+-----
         1 |   3
         1 |   3
         2 |   3
         1 |   3
         1 |   3
         2 |   3
         1 |   4
         1 |   4
         2 |   4
(9 rows)


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



view thread (2+ messages)  latest in thread

Message-ID: <1510536178.2747282.1170204616.4A024CB2@webmail.messagingengine.com>
Permalink:  ../1510536178.2747282.1170204616.4A024CB2@webmail.messagingengine.com/
Also on:    postgresql.org/message-id/1510536178.2747282.1170204616.4A024CB2@webmail.messagingengine.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: pgsql-general@antarkt.is
  Subject: Re: Multiple unnests in query
  In-Reply-To: <1510536178.2747282.1170204616.4A024CB2@webmail.messagingengine.com>
  References: <1510536178.2747282.1170204616.4A024CB2@webmail.messagingengine.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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