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

Asked

Viewed 782 times

1

I am 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 registered in the bank as null this wasn’t 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 just brings me this information, it doesn’t tell me if it was actually created the table as not null.

Verificação que está certo

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

1 answer

1


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

He’s looking for the column is_nullable, table information_schema.columns is it that indicates whether a column of a table is voidable or not. Obviously if you take only the name does not come this information.

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

I put in the Github for future reference.

Documentation of the column table.

  • please, how will I execute this command on my table?

  • 1

    You don’t know how to use a simple SELECT? So I have the impression that you are doing something that is above what you know, I would go for simpler things before trying to do something complex, because this is the basics of SQL. But I put it on for you.

  • thank you very much :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.