0 votes
1 view
in SQL by (20.3k points)

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.

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.

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

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

1 Answer

0 votes
by (40.3k points)

Use the EXISTS keyword for a TRUE / FALSE return like this:

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

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !