最快检查 PostgreSQL 中是否存在行 [英] Fastest check if row exists in PostgreSQL

查看:47
本文介绍了最快检查 PostgreSQL 中是否存在行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆行需要插入到表中,但这些插入总是分批完成的.所以我想检查表中是否存在批处理中的一行,因为这样我就知道它们都被插入了.

I have a bunch of rows that I need to insert into table, but these inserts are always done in batches. So I want to check if a single row from the batch exists in the table because then I know they all were inserted.

所以它不是主键检查,但应该没有太大关系.我想只检查单行,所以 count(*) 可能不好,所以它类似于 exists 我猜.

So its not a primary key check, but shouldn't matter too much. I would like to only check single row so count(*) probably isn't good, so its something like exists I guess.

但由于我对 PostgreSQL 还很陌生,所以我宁愿询问了解的人.

But since I'm fairly new to PostgreSQL I'd rather ask people who know.

我的批次包含具有以下结构的行:

My batch contains rows with following structure:

userid | rightid | remaining_count

因此,如果表中包含任何带有提供的 userid 的行,则意味着它们都存在于那里.

So if table contains any rows with provided userid it means they all are present there.

推荐答案

使用 EXISTS 关键字进行 TRUE/FALSE 返回:

Use the EXISTS key word for TRUE / FALSE return:

select exists(select 1 from contact where id=12)

这篇关于最快检查 PostgreSQL 中是否存在行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆