operator *= - Mailing list pgsql-general

From Sascha Ziemann
Subject operator *=
Date
Msg-id m3emcw9s75.fsf@intra.do.khs-ag.de
Whole thread Raw
Responses Re: [GENERAL] operator *=
List pgsql-general
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

pgsql-general by date:

Previous
From: Stuart Rison
Date:
Subject: Re: [GENERAL] get the previous assigned sequence value
Next
From: Adriaan Joubert
Date:
Subject: Re: [GENERAL] get the previous assigned sequence value