operator *=
operator *=
От:
Sascha Ziemann <szi@khs-ag.de>
Дата:
Hi,
I have two tables "user_t" and "email_alias_t". The "user_t" table
has the two fields "last_name" and "linux_login" and the
"email_alias_t" table has the two fields "login" and "alias".
In some rows in the "user_t" table the entry "linux_login" is NULL.
Now I need all rows from "user_t" and for those rows which have a
"linux_login" I need the "alias" column from "email_alias_t".
My SQL book descibes the *= operator which should be used for those
queries but Postgres does not have it. I found out that it is
possible to do the select with a union. This union:
select last_name, direct_inward_number, linux_login, alias
from user_t, email_alias_t
where last_name LIKE 'Ni%' AND linux_login = login
union
select last_name, direct_inward_number, linux_login, linux_login
from user_t
where last_name LIKE 'Ni%' AND linux_login = NULL
order by 1;
produces the right output:
last_name|direct_inward_number|linux_login|alias
---------+--------------------+-----------+-----------------
Niebisch | 2608|jni00514 |niebisch.jaroslaw
Nienaß | 1365| |
Nilles | 2478|pni00423 |nilles.peter
Nix | 2358|yni00155 |nix.yvonne
My question: Is such a union the only way to emulate the *= operator
in Postgres or is there a better way?
bis später...
Sascha
Re: [GENERAL] operator *=
От:
Karel Zak - Zakkr <zakkr@zf.jcu.cz>
Дата:
On 9 Dec 1999, Sascha Ziemann wrote: > Hi, > > I have two tables "user_t" and "email_alias_t". The "user_t" table > has the two fields "last_name" and "linux_login" and the > "email_alias_t" table has the two fields "login" and "alias". > > In some rows in the "user_t" table the entry "linux_login" is NULL. > > Now I need all rows from "user_t" and for those rows which have a > "linux_login" I need the "alias" column from "email_alias_t". > > My SQL book descibes the *= operator which should be used for those > queries but Postgres does not have it. I found out that it is > possible to do the select with a union. This union: In the PostgreSQL exist a operator *= , but is used for a array (text[] ..etc), (now is distributed in the contrib tree). I not sure, if I good undertend you, but good resolution for your problem is prabably JOIN. But it not implement in PgSQL now (it will in 7.0) :-( Karel