Questions tagged [notnull]

This tag refers to an object or type that is not null (none).

Use this tag for questions related to not-null types or objects (i.e. detecting them, handling them, etc.).

295 questions
21
votes
2 answers

SQL Not Empty instead of Not NULL

I am using postgreSQL. I have a column that: NOT NULL However when I want to insert a row with an empty string as like: '' it doesn't give me an error and accepts. How can I check insert value should be not empty? (Neither empty nor null) PS: My…
kamaci
  • 72,915
  • 69
  • 228
  • 366
20
votes
3 answers

Make a column nullable in DB2 when Data Capture is enabled

I'm using db2 version 9.7* and it seems impossible to make a NOT NULL column nullable in any straightforward way. Unfortunately the solution of using a more developer friendly database is not available. Basically, in MySQL speak, I want to do…
lukewm
  • 21,433
  • 6
  • 26
  • 28
16
votes
4 answers

What's the point of adding NOT NULL to primary key field in MySQL?

What's the point of adding NOT NULL to a primary key field? Primary key is already not null + unique. Here is an example: CREATE TABLE student ( id int(11) AUTO_INCREMENT NOT NULL, name varchar(255), PRIMARY KEY(id) ) Why not to define it…
Ben
  • 25,389
  • 34
  • 109
  • 165
14
votes
1 answer

Library support for Scala's NotNull trait

Notice: As of Scala 2.11, NotNull is deprecated. As far as I understand, if you want a reference type to be non-nullable you have to mixin the magic NotNull trait, and the compiler will automatically prevent you from putting null-able values in it.…
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
12
votes
5 answers

Insert default value when null is inserted

I have an Oracle database, and a table with several not null columns, all with default values. I would like to use one insert statement for any data I want to insert, and don't bother to check if the values inserted are nulls or not. Is there any…
SWilk
  • 3,261
  • 8
  • 30
  • 51
12
votes
1 answer

Need clarification on the meaning of Resharper NotNullAttribute

Consider the following code: public static void Foo() { Bar(null); } public static void Bar([NotNull] string s) { if (s == null) throw new ArgumentNullException("s"); } The [NotNull] attribute is…
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
11
votes
4 answers

Rails ActiveModel Serializers render not null attributes

I want to use a serializer that renders not null attributes class PersonSerializer < ActiveModel::Serializer attributes :id, :name, :phone, :address, :email end Is this possible. Many thanks. Solution: class PersonSerializer <…
10
votes
3 answers

IntelliJ IDEA complains about null check for @NotNull parameter

I want to use Jetbrains @Nullable/@NotNull Annotations in my project. I have a class with a @NotNull field. The constructor naturally does not accept null but throws an exception instead. Of course the parameter of this constructor is also be…
Euro
  • 618
  • 2
  • 8
  • 12
9
votes
4 answers

Select all if parameter is null in stored procedure

I want to create a procedure in SQL Server that will select and join two tables. The parameters @company, @from and @to are always set but @serie_type can be NULL. If @serie_type is not NULL i just want to include the specified types, simple AND…
Andreas
  • 6,958
  • 10
  • 38
  • 52
9
votes
2 answers

@Nullable and SonarQube 'Conditionally executed blocks should be reachable' warning

Package has following package-info.java: @ParametersAreNonnullByDefault package foo; import javax.annotation.ParametersAreNonnullByDefault; Class has the following method: private static String toIsoString(@Nullable Instant dateTime) { return…
maximdim
  • 8,041
  • 3
  • 33
  • 48
9
votes
3 answers

Preventing null (or empty string values in the db)

I'm using PostgreSQL and GORM in my Go app. I thought that using the sql tab of sql:"not null" would do the trick of preventing a null entry, but when go initializes structs with a string type then it defaults to an empty string which is not the…
Joff
  • 11,247
  • 16
  • 60
  • 103
8
votes
1 answer

Insert Null value To an inet field in postgresql

I am trying to insert values to a table which contains two columns with inet types. When I try to insert a NULL value to these columns I get an error saying ERROR: invalid input syntax for type inet: "" Actually I am triyng to do this from python…
Alptugay
  • 1,676
  • 4
  • 22
  • 29
8
votes
1 answer

@NotNull constraint for primitives, why?

Just encountered a bug, where the issue was that i had: @Column(name = "ACTIVE") @NotNull private boolean active; In my code I had forgot to set the value but it still "worked" as the default of boolean is false. I have now changed it to Boolean so…
Viktor Mellgren
  • 4,318
  • 3
  • 42
  • 75
7
votes
1 answer

When does a NOT NULL constraint run and can it wait until the transaction is going to commit?

I have a table being populated during an ETL routine a column at a time. The mandatory columns (which are foreign keys) are set first and at once, so the initial state of the table is: key | fkey | a -------|--------|------- 1 | 1 |…
villasv
  • 6,304
  • 2
  • 44
  • 78
7
votes
3 answers

java/beans validation - collection/map does not contain nulls

There is the @NotNull annotation which validates that a certain object is not null. There is the @NotEmpty annotation which validates that a certain collection/map/string/... is not empty. Is there also an annotation which valides that a certain…
user4460845
1
2
3
19 20