Why columns in views are always nullable? I'm using postgreSQL. Why the fields in the views always are nullable? I get that in some situation computed columns can be NULL, but in the below snippet I only &quot;forward&quot; those data.
I noticed that MySQL behaves like I'd have, and I don't need special feature from psql, so I think I'll switch to MySQL.
But I really wonder WHY postgreSQL doesn't behave &quot;normally&quot;?
It is quite annoying when you are working with system like SQLx in Rust bridging SQL and Rust types since you cannot rely on this tool when you refers to views in your Rust code.
postgres=# CREATE TABLE a( field INT NOT NULL);
CREATE TABLE
postgres=# CREATE VIEW b AS SELECT field FROM a;
CREATE VIEW

postgres=# SELECT column_name,is_nullable, data_type           
FROM information_schema.columns
WHERE table_name ='a';
 column_name | is_nullable | data_type 
-------------+-------------+-----------
 field       | NO          | integer
(1 row)

postgres=# SELECT column_name,is_nullable, data_type
FROM information_schema.columns
WHERE table_name ='b';
 column_name | is_nullable | data_type 
-------------+-------------+-----------
 field       | YES         | integer
(1 row)
It sounds like this is just the way it is in PostgreSQL (which I understand is a sucky answer). It seems like under certain conditions for certain versions of PostgreSQL, a view's column may be attributed as non-nullable. This StackOverflow answer gives the example where if the field is a primary key of the base table, in a vanilla view, it is showing as non-nullable in the view's schema.
I suppose PostgreSQL has some strict requirements on what it assumes can truly be non-nullable in a view definition.