Re: Subselect with no records results in final empty set

From: "Sterpu Victor" <victor(at)caido(dot)ro>
To: "Sterpu Victor" <victor(at)caido(dot)ro>, "David G Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Subselect with no records results in final empty set
Date: 2015-01-29 20:36:07
Message-ID: em4ee6f5f5-70d5-4c7a-9e7b-118da98bb586@victor-pc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I changed the final query to
SELECT * FROM
(SELECT 1 AS t1, 2 AS t2) AS t1
LEFT JOIN (SELECT * FROM atc WHERE id = '1231222') AS t2 ON (1=1)

ON(null) never matched.

------ Original Message ------
From: "Sterpu Victor" <victor(at)caido(dot)ro>
To: "David G Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>;
pgsql-general(at)postgresql(dot)org
Sent: 1/29/2015 10:22:28 PM
Subject: Re: [GENERAL] Subselect with no records results in final empty
set

>It works as you sugested, this is the syntax I used:
>SELECT * FROM
>(SELECT 1 AS t1, 2 AS t2) AS t1
>LEFT JOIN (SELECT * FROM atc WHERE id = '1231222') AS t2 ON (null)
>
>Thank you.
>
>------ Original Message ------
>From: "David G Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
>To: pgsql-general(at)postgresql(dot)org
>Sent: 1/29/2015 10:03:38 PM
>Subject: Re: [GENERAL] Subselect with no records results in final empty
>set
>
>>Sterpu Victor wrote
>>> Hello
>>>
>>> I have this select where the last subselect will return a empty set
>>>and
>>> because of this the whole select will be empty.
>>> How can I change this syntax so I will have a row result even if the
>>> last select is empty?
>>>
>>> SELECT * FROM (SELECT 1 AS t1, 2 AS t2) as t, (SELECT 3 AS t3) as s,
>>> (SELECT * FROM atc WHERE id = '1231222' LIMIT 1 OFFSET 0) AS s3;
>>
>>Use explicit join syntax; and then pick the "LEFT [OUTER] JOIN"
>>variant.
>>
>>SELECT
>>FROM t
>>LEFT JOIN s3 ON (TRUE)
>>
>>David J.
>>
>>
>>
>>--
>>View this message in context:
>>http://postgresql.nabble.com/Subselect-with-no-records-results-in-final-empty-set-tp5836011p5836014.html
>>Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>>
>>
>>--
>>Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
>>To make changes to your subscription:
>>http://www.postgresql.org/mailpref/pgsql-general
>
>
>---
>This email has been checked for viruses by Avast antivirus software.
>http://www.avast.com
>
>
>
>-- Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-general

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2015-01-29 20:39:14 Re: Subselect with no records results in final empty set
Previous Message Alex Hunsaker 2015-01-29 20:30:10 Re: segmentation fault postgres 9.3.5 core dump perlu related ?