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

查看:81
本文介绍了最快检查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天全站免登陆