Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Postgres empty SELECT clause "affects rows"

I stumbled upon Postgres behaviour, which I do not understand. I enter this simple query. Please notice that there’s no expression in SELECT clause:

SELECT FROM (VALUES (1), (2), (3)) AS data(value);

Server replies with

Query executed OK, 3 rows affected.

According to the documentation for SELECT statement, the empty clause seems to be perfectly valid, but I can’t understand, what affected rows mean in this case. EXPLAIN gives me simple "values scan" query plan. When I change SELECT to SELECT *, the query works as expected and returns table with three rows.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What does that SELECT <nothing> FROM ... do?
My Postgres version is 9.5.

>Solution :

PostgreSQL allows empty SELECT lists (the SQL standard does not allow that).

"3 rows affected" must be something that your client says when it receives a result set with three rows. The result set does contain three rows, even if they contain no column. Perhaps your client displays the result set as if it were empty, but it isn’t.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading