I m a beginner and trying to insert JSON values into the database using a tutorial
I have created the table using the following command
CREATE TABLE table_name( id character varying(50),
data json NOT NULL,
active boolean NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
CONSTRAINT table_name_pkey PRIMARY KEY (id)
);
The table is created with table_name.
Now I am trying to insert the values into the database:
INSERT INTO table_name
SELECT id,data,active,created_at,updated_at
FROM json_populate_record (NULL::table_name,
'{
"id": "1",
"data":{
"key":"value"
},
"active":true,
"created_at": SELECT NOW(),
"updated_at": SELECT NOW()
}'
);
It throws the following error
ERROR: Invalid input syntax for type JSON '{
Could anyone help me to resolve and insert the JSON values into the DB?