Bug #862: strange select results

Started by PostgreSQL Bugs Listover 23 years ago2 messagesbugs
Jump to latest
#1PostgreSQL Bugs List
pgsql-bugs@postgresql.org

Krzysztof Wo�nica (kw@b3.4it.pl) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
strange select results

Long Description
I have created an view. When I select fields separately all looks ok but when I try to select 3 fields for concatention (f1 || f2 || f3) the resul is empty when f3 is empty. I think it is not expected bahaviour.

Sample Code
the view:
SELECT person.id, person.sex, person.salutation, person.firstname, person.secondname, person.lastname, person.birthday, person.number, person.nip, (SELECT ((((((((address.street || ' '::text) || btrim((address.building)::text, ' '::text)) || '/'::text) || btrim((address.apartament)::text, ' '::text)) || ', '::text) || address.city) || ', '::text) || (address.country)::text) FROM address WHERE (((address.personid = person.id) AND (((address.fromdate < '2003-01-02'::date) OR (address.todate IS NULL)) AND ((address.todate > '2003-01-02'::date) OR (address.todate IS NULL)))) AND (address."primary" = 't'::bool)) LIMIT 1) AS address, (SELECT contact.howto FROM contact WHERE (((contact.personid = person.id) AND ((contact."type" = 'cel'::bpchar) OR (contact."type" = 'pho'::bpchar))) AND (((contact.fromdate < '2003-01-02'::date) OR (contact.fromdate IS NULL)) AND ((contact.todate > '2003-01-02'::date) OR (contact.todate IS NULL)))) LIMIT 1) AS phone, (SELECT contact.howto FROM contact
WHERE (((contact.personid = person.id) AND (contact."type" = 'eml'::bpchar)) AND (((contact.fromdate < '2003-01-02'::date) OR (contact.fromdate IS NULL)) AND ((contact.todate > '2003-01-02'::date) OR (contact.todate IS NULL)))) LIMIT 1) AS email FROM person;

forvhost=# select id, lastname, address from person_list;
id | lastname | address
-----+---------------------------------------+--------------------------------
2 | KKKKKKK |
1 | WWWWW |
92 | JJJJJJJJ | Kj Ji 1/1, Radom, PL
93 | KAZKAZ |
94 | 4IT S.A. |
96 | Kowalski |
(6 rows)

forvhost=# select id, (lastname || '; ' || (address)::text)::text from person_list;
id | text
-----+--------------------------------------------
2 |
1 |
92 | JJJJJJJJ; Kj Ji 1/1, Radom, PL
93 |
94 |
96 |
(6 rows)

No file was uploaded with this report

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: PostgreSQL Bugs List (#1)
Re: Bug #862: strange select results

pgsql-bugs@postgresql.org writes:

I have created an view. When I select fields separately all looks ok but when I try to select 3 fields for concatention (f1 || f2 || f3) the resul is empty when f3 is empty. I think it is not expected bahaviour.

That's the way NULLs are defined to work by the SQL specification.
There is a big difference between NULL and an empty string --- don't use
one when you mean the other.

regards, tom lane