오늘은/오늘 배운 것
Sqlalchemy(Postgresql) 사용시 unique 적용시 condition 을 적용
한밀
2020. 7. 3. 22:28
Index( 'idx_index_table_unique', ref_id, unique=True, postgresql_where=("created_at > CAST('2018-01-01' AS timestamptz)"))
2018-01-01 이후에 생성되는 record 에 대해서만 ref_id 가 unique 한지 검사한다.
2018-01-01 의 의미는 그전에 입력했던 데이터들은 유일하지 않는데, 앞으로는 입력하는 데이터는 unique 검사를 하겠다는 의미임.