postgresources – Telegram
#json #constraint

create table books(k serial primary key, doc jsonb not null);

insert into books(doc) values
('
{ "ISBN" : 4582546494267,
"noscript" : "Macbeth",
"author" :
{"given_name": "William",
"family_name": "Shakespeare"},
"year" : 1623
}
');

alter table books
add constraint books_doc_is_object
check(
jsonb_typeof(doc) is not null and
jsonb_typeof(doc) = 'object'
);

alter table books
add constraint books_doc_isbn_ok
check(
doc->>'ISBN' is not null and
jsonb_typeof(doc->'ISBN') = 'number' and
(doc->>'ISBN')::bigint > 0 and
length(doc->>'ISBN') = 13
);
Forwarded from @yarosh_log
Channel name was changed to «postgresources»
Channel photo updated
Detecting which #index types are available for my column type

SELECT DISTINCT
a.amname
FROM
pg_type t
JOIN pg_opclass o ON o.opcintype = t.oid
JOIN pg_am a ON a.oid = o.opcmethod
WHERE
t.typname = 'int4';

amname
--------
btree
hash
brin
(3 rows)