courses/sql-orbit/constraints
● videoINMS Data Import

Concept: Constraints

Free for everyone
This video is free for everyone

Watch the whole thing, no account needed. If it clicks, grab PostgreSQL Fundamentals for lifetime access to every lesson.

Buy the course$49
SECTION
INMS Data Import
NEXT UP
Transformation, Part 2
COURSE
PostgreSQL Fundamentals
28 lessons
About this lesson

We have a number of constraints on our table and we really should understand what they do at a deeper level. In this video we'll dive into the constraint code below.

<span class="hljs-keyword">create table</span> inms(
  id bigserial <span class="hljs-keyword">primary key</span>,
  created_at <span class="hljs-type">timestamp</span> <span class="hljs-keyword">not null</span>,
  altitude <span class="hljs-type">numeric</span>(<span class="hljs-number">9</span>,<span class="hljs-number">2</span>) <span class="hljs-keyword">not null</span> <span class="hljs-keyword">check</span>(altitude <span class="hljs-operator">&gt;</span> <span class="hljs-number">0</span>),
  source text <span class="hljs-keyword">not null</span> <span class="hljs-keyword">check</span>(source <span class="hljs-keyword">in</span>(<span class="hljs-string">&#x27;osi&#x27;</span>,<span class="hljs-string">&#x27;csn&#x27;</span>,<span class="hljs-string">&#x27;osnb&#x27;</span>,<span class="hljs-string">&#x27;osnt&#x27;</span>))
  mass <span class="hljs-type">numeric</span>(<span class="hljs-number">6</span>,<span class="hljs-number">3</span>) <span class="hljs-keyword">not null</span> <span class="hljs-keyword">check</span>(mass <span class="hljs-operator">&gt;=</span><span class="hljs-number">0.125</span> <span class="hljs-keyword">and</span> mass <span class="hljs-operator">&lt;</span> <span class="hljs-number">100</span>),
  high_sensitivity_count <span class="hljs-type">int</span> <span class="hljs-keyword">not null</span> <span class="hljs-keyword">check</span>(high_sensitivity_count <span class="hljs-operator">&gt;</span> <span class="hljs-number">0</span>),
  low_sensitivity_count <span class="hljs-type">int</span> <span class="hljs-keyword">not null</span> <span class="hljs-keyword">check</span>(low_sensitivity_count <span class="hljs-operator">&gt;</span> <span class="hljs-number">0</span>)
);