How to know that the attribute is not null in the PostgreSQL database?

1

I'm developing a Java system with Spring Boot and created the table as not null as you can see:

CREATE TABLE categoria (
    codigo BIGSERIAL,
    nome VARCHAR(50) NOT NULL,
    PRIMARY KEY(codigo)
); 

The problem was that getting a bank account as null was not supposed to happen, I did a brief search on the internet and find this command to know the description of my table;

SELECT column_name FROM information_schema.columns WHERE table_name ='categoria';

But it only brings me this information, it does not tell me if the table was actually created as not null .

How do I know if the table is as not null ?

    
asked by anonymous 15.11.2017 / 08:06

1 answer

1

I'll answer what you asked though the question should be about what you're doing wrong to have accepted NULL .

You are looking for the is_nullable column, the information_schema.columns table is the one that indicates whether a table column is nullable or not. Obviously if you just get the name does not come this information.

SELECT column_name, is_nullable FROM information_schema.columns WHERE table_name = 'categoria';

Column table documentation .

    
15.11.2017 / 10:42