```
DB Table: 
id       int(6)
message  char(5)

```

I have to add a record (message) to the DB table. In case of duplicate message(this message already exists with different id) I want to delete (or inactivate somehow) the both of the messages and get their ID's in reply.

Is it possible to perform with only one query? Any performance tips ?...

P.S. 
I use PostgreSQL. 

The main my problem I worried about, is a need to use locks when performing this with two or more queries...

Many thanks!