Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I would like to know if it is possible to insert a 'null' string in a column which has NOT NULL constraint. I'm using postgresql.

The query would look like the below

INSERT INTO originators(originator, id, regexp)
VALUES ('null', 1, -1);

Here the originator column has NOT NULL constraint.

share|improve this question

closed as off topic by Jack Douglas Oct 4 '12 at 15:40

Questions on Database Administrators Stack Exchange are expected to relate to database administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Why don't you check it yourself? –  dezso Oct 4 '12 at 12:29
'null' is completely different than NULL. And the "NOT NULL" constraint is related only to the latter. –  Milen A. Radev Oct 4 '12 at 12:47
'null' is just like any other string, this doesn't need any special case. If you're having a problem it's because of a buggy (stupid) client or Pg driver for your language/tools. –  Craig Ringer Oct 4 '12 at 12:51
-1 since you could easily try the query you wrote and determine the answer quicker than adding a question here and waiting for the answer. –  Max Vernon Oct 4 '12 at 15:36
As implied by other comments this is too basic to be on-topic on dba.se - hence I will need to close it. Please don't let that discourage you from posting other questions. –  Jack Douglas Oct 4 '12 at 15:40
add comment

1 Answer

'NULL' is not the same as NULL, the first one is an string just like any other string, so your constraint (NOT NULL) won't work.

I think you are working with a programming language (like PHP or Java) that you put your value inside a string with a variable like

INSERT INTO originators(originator, id, regexp) 
VALUES ('$variable', $id, $regexp); 

so in this case you have to correct your code to prevent the quotes, or if you can't do that you constraint should be CHECK(upper(originator) != 'NULL').

share|improve this answer
Sorry again, I didn't see that you edit my answer and now I can't revert it. Don't worry I will correct it. thanks a lot. –  Hola Soy Edu Feliz Navidad Oct 4 '12 at 13:47
Deleted.... thanks. ;) –  Hola Soy Edu Feliz Navidad Oct 4 '12 at 14:16
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.