Re: Extract especific text from a sql statement

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Extract especific text from a sql statement
Date: 2014-10-01 19:52:36
Message-ID: CANu8FixAUS_etohM+OBXWB0VPrMQp1KNVkogFk_2rdwnRcNaPA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You already have most of the result columns, so the following should do it.

SELECT pc.cod,
pc.val,
pi.qtd,
COALESCE(pc.name, 'empty') AS name,
lower(coalesce(pc.email, 'empty')) as email,
status,
c1.relname,
c2.relname,
pc.startdate
FROM pc
INNER JOIN pi on (pc.cod = pi.cod)
JOIN pg_class c1 ON (c1.relname = 'pc' AND c1.relkind = 'r'
JOIN pg_class c2 ON (c2.relname = 'pi' AND c2.relkind = 'r'
WHERE pc.startdate > CURRENT_DATE
order by 1 desc;

Learn the catalogs and you will learn to be a good dba.

Melvin Davidson

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G Johnston 2014-10-01 20:10:13 Re: Extract especific text from a sql statement
Previous Message David G Johnston 2014-10-01 18:40:18 Re: Is there a way to get both the plan and the results?