E
E
Ekaterina Shundeeva2020-09-13 16:44:33
PostgreSQL
Ekaterina Shundeeva, 2020-09-13 16:44:33

PostgreSQL throws an error that it doesn't know the generic expression. What's wrong?

Others!
Help me please.

Essence: there is a certain DB in which there is a table without primary key and numbering of lines.
There are duplicate rows in this table.
It is necessary to write a sql query that would remove duplicates.

The work is being done in Postgresql, version 11.9.

After searching the Internet, I came across this article: https ://vc.ru/dev/134435-sposoby-udaleniya-dublika...

in our case, the table does not have a primary key, the second option was chosen, namely through the ROW_number () window function.

Here is an example of my code:
WITH D AS
(
select s.*,
row_number () over (Partition by s.*
) as numbering
from sales s
)
delete FROM D
WHERE numbering > 1;

After that, Postgre throws the following error: "ERROR: ERROR: relation "d" does not exist
LINE 8: delete FROM D"

Although if you try to select this generic expression, there are no errors.
WITH D AS
(
select s.*,
row_number () over (Partition by s.*
) as numbering
from sales s
)
select * from D

Can you please tell me what is causing this error?
I'm still quite new to this.

Thank you all in advance :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-09-13
@skateiko

CTE cannot be used with DELETE.

R
Ruslan., 2020-09-13
@LaRN

Maybe it will be faster instead of delete to write:
SELECT * FROM D
WHERE numbering > 1;
And store the select result in a temporary table.
After that to bang all these lines and to interpose already on one copy of each of the temporary table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question