Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
Constraint on columns based on single column not firing

I made a constraint where to mark the column completed to true some of the other columns would have to have a value.

But for some reason the constraint does not complain when I leave a specified column blank when completed is marked true. I have also purposely inserted NULL a specified column and still no constraint.

Any ideas?

CREATE TABLE info (
  id bigserial PRIMARY KEY,
  created_at timestamptz default current_timestamp,
  posted_by text REFERENCES users ON UPDATE CASCADE ON DELETE CASCADE,
  title character varying(31),
  lat numeric,
  lng numeric,
  contact_email text,
  cost money,
  description text,
  active boolean DEFAULT false,
  activated_date date,
  deactivated_date date,
  completed boolean DEFAULT false,
  images jsonb,

  CONSTRAINT columns_null_check CHECK (
  (completed = true
  AND posted_by != NULL
  AND title != NULL
  AND lat != NULL
  AND lng != NULL
  AND contact_email != NULL
  AND cost != NULL
  AND description != NULL
  AND images != NULL) OR completed = false)
);
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

In Chapter 9. Functions and Operators:

To check whether a value is or is not null, use the predicates:

expression IS NULL
expression IS NOT NULL

or the equivalent, but nonstandard, predicates:

expression ISNULL
expression NOTNULL

Therefore you can not use value != NULL to check null values, you can only use value IS NULL and value IS NOT NULL.

For boolean values they are the same:

Boolean values can also be tested using the predicates

boolean_expression IS TRUE
boolean_expression IS NOT TRUE
boolean_expression IS FALSE
boolean_expression IS NOT FALSE
boolean_expression IS UNKNOWN
boolean_expression IS NOT UNKNOWN
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda