0

I want to remove duplicate rows in a table but I don't want to create a new table.

I have create a stored procedure for this, but it is not returning the current result, and this stored procedure will create a temp table, it will be dropped though.

create procedure test_procedure()
language plpgsql
as $$
DECLARE
    _temp_table character varying(20) := 'TempTable';
BEGIN
SELECT * INTO _temp_table FROM A group by col1,col2; -- this will remove duplicate rows, as A only has 2 cols
delete from A;
insert into A select * from _temp_table ;
drop table _temp_table ;
end; $$
2
  • Does your table have any primary key? Commented Nov 11, 2022 at 6:24
  • no, it does not have any primary key Commented Nov 11, 2022 at 6:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.