6

I am unable to find in the documentation how to create a JSONB column in PostgreSQL that has a DEFAULT value of an empty json document.

How the above can be stated in the CREATE TABLE definition ?

  • what's an empty json document? "" contrains a string {} contains an object null contains a null ? – Jasen May 19 '18 at 2:58
16

That's the same as with any other default value:

create table amsterdam
(
   id       integer primary key, 
   payload  jsonb not null default '{}'::jsonb
);
0

If you are altering an already existing table, then the syntax is as follows:

alter table TABLE add column COLUMN jsonb not null default '{}'::jsonb;
  • 2
    How is this different from the existing accepted answer? – mustaccio Jul 4 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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