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 ?
asked May 17, 2018 at 8:45
2 Answers 2
That's the same as with any other default value:
create table amsterdam
(
id integer primary key,
payload jsonb not null default '{}'::jsonb
);
answered May 17, 2018 at 9:02
user1822user1822
If you are altering an already existing table, then the syntax is as follows:
ALTER TABLE my_table ADD COLUMN my_column JSONB NOT NULL DEFAULT '{}'::jsonb;
-
2How is this different from the existing accepted answer?mustaccio– mustaccio2019年07月04日 18:25:08 +00:00Commented Jul 4, 2019 at 18:25
-
3The captain here!
alter
vscreate
Valery Bugakov– Valery Bugakov2019年11月10日 11:17:20 +00:00Commented Nov 10, 2019 at 11:17
lang-sql
""
contrains a string{}
contains an objectnull
contains a null ?