Setting Nullability
Setting nullability is possible using three different methods:- GAdmin
- Native API (using the /create/type endpoint)
- SQL
SQL
When creating a table in SQL, columns are nullable by default, but can be set as nullable explicitly with the modifierNULL. Non-nullable columns
need to be defined explicitly with NOT NULL.
In the following example, all columns except for id are nullable:
REST
When creating a type schema via REST, a call to /create/type needs to be made, where nullability of each column is specified in two places:-
As a union between the type of the nullable column and the keyword
null: -
In the
propertieslist, with each nullable column being assigned thenullableproperty:
ex_null_rest is created with
a nullable column, null_col. To create this type schema, call the
/create/type endpoint with the following payload:
The
type_definition is passed in as a JSON string, so all quotes
within it must be escaped.curl might look like this, where the above JSON
payload is in a file named create_null_type.json:
C++
C#
Java
JavaScript
Node.js
Python
Creating a Table with Nullable Columns
To create a table with a nullable column:Creating a Type with Nullable Fields
To create a type, from which multiple tables can be instantiated, either theGPUdbRecordType object or a JSON string can be used.
GPUdbRecordType
JSON
When using a JSON string to create a type, one needs to specify
nullability at the column property level but also at the type
definition level as a union between the type of the column and
null.Using Nulls
Null values can be used in expressions much like any other value. Null functions can also be used on column names in expressions to test for and evaluate null column values. The native API null functions can be found here; the SQL null functions can be found here.Examples
Given tableemployees, you can query to see which employees have not input
their phone number into the employee record database using the SQL statement
budget, you can create a projection to track if a
department’s budget has changed since last year using the NULLIF() function.
For example, in Python:
Aggregates and Nulls
There are two points of note when attempting to perform aggregation/grouping operations on a table or view that contains null values.- Null values are ignored in every aggregation calculation except for certain
instances of
COUNT()usage, e.g., counting the amount of records in a table or view (COUNT(*)) will include records with null values even if all the values in a record are null; however, counting the values in a column (COUNT(column_name)) will ignore null values - Aggregating against an empty table results in 0 records for the
countand null values for the other calculations (e.g.,SUM,MIN,VAR_POP)
Example
Given the following tablesurvey_response: