Re: [SQL] Database views metadata always nullable columns - Mailing list pgsql-sql

From David G. Johnston
Subject Re: [SQL] Database views metadata always nullable columns
Date
Msg-id CAKFQuwYz2CJ722HJ0J4RY5WT8V-q+EdTC4EFfTKGQMbbqn2oVw@mail.gmail.com
Whole thread Raw
In response to Re: [SQL] Database views metadata always nullable columns  (basuraspam - <basuraspam0@gmail.com>)
List pgsql-sql
On Fri, Jun 2, 2017 at 8:33 AM, basuraspam - <basuraspam0@gmail.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.

pgsql-sql by date:

Previous
From: basuraspam -
Date:
Subject: Re: [SQL] Database views metadata always nullable columns
Next
From: Tom Lane
Date:
Subject: Re: [SQL] Database views metadata always nullable columns