Re: Database views metadata always nullable columns

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: basuraspam - <basuraspam0(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Database views metadata always nullable columns
Date: 2017-06-02 15:59:12
Message-ID: CAKFQuwYz2CJ722HJ0J4RY5WT8V-q+EdTC4EFfTKGQMbbqn2oVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Jun 2, 2017 at 8:33 AM, basuraspam - <basuraspam0(at)gmail(dot)com> wrote:

> Hi Tom,
> I agree, it would be better including an example. The "issue" I
> reported is with database views not with tables. Taking your example as
> base:
>

​Since view columns cannot be specified NOT NULL (or have their own
constraints for that matter) reporting false here is accurate.​

That we don't parse the view and attempt to derive constraints from the
underlying query and tables, if any, is unsurprising.

i.e., should "CREATE VIEW test (col1) AS SELECT '1'::col1;

report NOT NULL for test.col1?

About the only SQL-visible automated way to do what you describe, to some
level of accuracy, is to EXPLAIN the view and extract the tables and
columns and look them up. That will fail for, say, SELECT * FROM tbl1 LEFT
JOIN tbl2, when looking at properties of columns from tbl2.

David J.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2017-06-02 16:07:17 Re: Database views metadata always nullable columns
Previous Message basuraspam - 2017-06-02 15:33:09 Re: Database views metadata always nullable columns