Am using postgres 10.3
My jsonb field linkage in the table test_linkages has this typical schema
{
"activity_5640": {
"in_scope": 109,
"out_activity": 5640
},
"activity_8032": {
"in_scope": 110,
"out_activity": 8032
},
"root": {
"in_common_site": 7862,
"in_sub_project": 123,
"in_wbs": "ABC.40125",
"out_network": 97573314
}
}
How do I enforce for e.g. linkage->'root'->'in_sub_project' to always be integer or numeric?
I know how to enforce for non null.
ALTER TABLE test_linkages ADD CONSTRAINT sub_project_must_exist CHECK (linkage->'root' ? 'in_sub_project');
But I want to enforce it to always be numeric or integer
I know there are only 4 types that Postgres supports in a json document
I know I can enforce the type at the code level, but I was hoping to enforce it at the database level somehow
