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

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

create table amsterdam
   id       integer primary key, 
   payload  jsonb not null default '{}'::jsonb
| improve this answer | |

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;
| improve this answer | |
  • 2
    How is this different from the existing accepted answer? – mustaccio Jul 4 '19 at 18:25
  • 2
    The captain here! alter vs create – Valery Bugakov Nov 10 '19 at 11:17

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.