2010/6/21 Andrus :
> if there is no searched primary key row in ko database, select should also
> return empty row.
>
> To get this result I added right join:
>
> SELECT somecolumns
> FROM ko
> RIGHT JOIN (SELECT 1) _forceonerow ON true
> LEFT JOIN t1 ON t1.primarykey= ko.t1foreignkwey
> ...
> LEFT
Martin,
Also I too am confused by "empty row". Are you trying to loop through the
results in code and it fails if there are no rows at all?
Or some other equally odd thing? =)
Anyway here is an example UNION that I think would work (but note, this row
will always be included even when your sta
Brett Mc Bride wrote:
> My understanding of UNION ALL is that it won't sort the rows...?
> [...]
It doesn't, but that's not promised for every data set, ev-
ery PostgreSQL version, every phase of the moon. To quote
http://www.postgresql.org/docs/8.4/interactive/queries-union.html>:
| UNION effe
NERAL] How to force select to return exactly one row
Brett Mc Bride wrote:
> How about:
> SELECT * from (
> SELECT somecolumns
> FROM ko
> LEFT JOIN t1 ON t1.primarykey= ko.t1foreignkwey
> ...
> LEFT JOIN tn ON tn.primarykey= ko.tnforeignkwey
> WHERE ko.primarykey=
Brett Mc Bride wrote:
> How about:
> SELECT * from (
> SELECT somecolumns
> FROM ko
> LEFT JOIN t1 ON t1.primarykey= ko.t1foreignkwey
> ...
> LEFT JOIN tn ON tn.primarykey= ko.tnforeignkwey
> WHERE ko.primarykey='someprimarykeyvalue'
> UNION ALL
> SELECT default_value
> )
> LIMIT 1;
> [...]
...
general-ow...@postgresql.org
[mailto:pgsql-general-ow...@postgresql.org] On Behalf Of Andrus
Sent: Tuesday, 22 June 2010 5:08 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] How to force select to return exactly one row
Autogenerated select statement contains 0 .. n left joins:
SELECT somecolumn
Use a case staement to test for a null output, & return whatever you want in
the event of it being null, else the actual value:
from the top of my head, something like:
SELECT case when
(select somecolumns
FROM ko
RIGHT JOIN (SELECT 1) _forceonerow ON true
LEFT JOIN t1 ON t1.primarykey= ko.
ust return only one column
>
> How to use your suggestion if select returns lot of columns ?
>
> Andrus.
>
>
>
>
>
> - Original Message -----
> *From:* Martin
> *To:* Andrus
> *Cc:* pgsql-general@postgresql.org
> *Sent:* Monday, June 21, 2010
"Andrus" wrote:
> Autogenerated select statement contains 0 .. n left joins:
> SELECT somecolumns
> FROM ko
> LEFT JOIN t1 ON t1.primarykey= ko.t1foreignkwey
> ...
> LEFT JOIN tn ON tn.primarykey= ko.tnforeignkwey
> WHERE ko.primarykey='someprimarykeyvalue';
> This select can return only 0 or 1
: Andrus
Cc: pgsql-general@postgresql.org
Sent: Monday, June 21, 2010 10:14 PM
Subject: Re: [GENERAL] How to force select to return exactly one row
Try wrapping the entire statement in a COALESCE((statement), );
-m
2010/6/21 Andrus
Autogenerated select statement contains 0
Try wrapping the entire statement in a COALESCE((statement),
);
-m
2010/6/21 Andrus
>
> Autogenerated select statement contains 0 .. n left joins:
>
> SELECT somecolumns
> FROM ko
> LEFT JOIN t1 ON t1.primarykey= ko.t1foreignkwey
> ...
> LEFT JOIN tn ON tn.primarykey= ko.tnforeignkwey
> WHERE k
Autogenerated select statement contains 0 .. n left joins:
SELECT somecolumns
FROM ko
LEFT JOIN t1 ON t1.primarykey= ko.t1foreignkwey
...
LEFT JOIN tn ON tn.primarykey= ko.tnforeignkwey
WHERE ko.primarykey='someprimarykeyvalue';
This select can return only 0 or 1 rows depending if ko row with p
12 matches
Mail list logo