-- Add the check constraint
alter table public.test_partition_10_25 add constraint test_partition_10_25_constraint CHECK (id >= 10 AND id <25) NOT VALID;
update pg_constraint pgc
SET convalidated = true
FROM pg_class c
WHERE
c.oid = pgc.conrelid
AND connamespace = 'public'::regnamespace::oid
AND c.relname = 'test_partition_10_25'
AND conname = 'test_partition_10_25_constraint';
["slug" being an entity attribute]
Spring Data offers an existsBy query method, which we can define in the PostRepository, as follows:
1
2
3
4
5
6
@Repository
public interface PostRepository
extends JpaRepository<Post, Long> {
boolean existsBySlug(String slug);
}
[another] option to emulate existence is using a CASE WHEN EXISTS native SQL query:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Repository
public interface PostRepository
extends JpaRepository<Post, Long> {
@Query(value = """
SELECT
CASE WHEN EXISTS (
SELECT 1
FROM post
WHERE slug = :slug
)
THEN 'true'
ELSE 'false'
END
""",
nativeQuery = true
)
boolean existsBySlugWithCase(@Param("slug") String slug);
}
A. Islam, M. Islam, M. Alam, and S. Ullah. International Journal of Computer Science, Engineering and Information Technology (IJCSEIT), 1 (4):
01-13(October 2011)
G. Hua, M. Zhang, Y. Liu, S. Ma, and L. Ru. Proceedings of the 20th international conference companion on World wide web, page 59--60. New York, NY, USA, ACM, (2011)
K. Punera, and S. Merugu. Proceedings of the 19th ACM international conference on Information and knowledge management, page 989--998. New York, NY, USA, ACM, (2010)
G. Dupret, and C. Liao. Proceedings of the third ACM international conference on Web search and data mining, page 181--190. New York, NY, USA, ACM, (2010)
Y. Yue, Y. Gao, O. Chapelle, Y. Zhang, and T. Joachims. Proceeding of the 33rd international ACM SIGIR conference on Research and development in information retrieval, page 507--514. New York, NY, USA, ACM, (2010)
U. Ozertem, R. Jones, and B. Dumoulin. Proceedings of the 20th international conference on World wide web, page 397--406. New York, NY, USA, ACM, (2011)