How to write a constraint concerning a max number of rows in postgresql?

前端 未结 4 1314
渐次进展
渐次进展 2020-12-01 13:57

I think this is a pretty common problem.

I\'ve got a table user(id INT ...) and a table photo(id BIGINT, owner INT). owner is a reference o

4条回答
  •  佛祖请我去吃肉
    2020-12-01 14:58

    A better alternative would be to check the number of rows when you do the insert:

    insert into photos(id,owner) 
    select 1,2 from dual
    where (select count(*) from photos where id=1) < 10
    

提交回复
热议问题