sql - PostgreSQL if temporary table is dropped query is empty -


I am working on a simple homework assignment where I have to get some data which complies with some parameters and then The second goes to the query on the query that was selected in the previous query.

I am creating a temporary table and generating it with the results of the first query and then run another query on the table. Then I leave the table.

Here's the problem: If I leave the table, the second question is empty because the result is abandoned. I do not understand this. I do not use a temporary table for selection, only for data validation. And even if the table is dropped at the end of the query query, the query is empty. If I do not leave the table, then it works fine but if I run the query again, it says that the table is present. What am I doing wrong here. Here's the code:

  Select the temporary table TMP from the edge where the weight> 100; Choose Graph from TMP, Graph Grapho = tmp.no and gesm (graph. Gno) & gt; = Select all from the graph (SELECT gsum (graph.gno) gname, gsum (graph.gno););    

Temporary tables are unique for each session, they are created in a special temporary schema. In only one session and only till the end of the session (unless previously dropped) appear.

This is the first schema in the temporary schema interactively (schema pg_catalog after system), so it is effectively the other table of the same name Hides.

Existing permanent tables with the same name are not visible to the current session, whereas a temporary table is present, unless they are referred to by the schema qualified name.

Once you leave the temporary table, the next table becomes visible again with the same name in the search_path and its current < There is no matching value in the code> gno column, so the result is empty.

It should be because, if such a table does not exist, you will not get the empty result for the next attempt, but will receive an error message

In addition, your second query should be:

  SELECT gname, gsum (graph.gno) Use the Tmp JOIN article (GNO) WHERE gsum (graph.gno) = (SELECT max (From the graph.gno) graph);  

Clear JOIN with syntax and simplified WHERE condition. Assume gsum () is a plain function, not a composite function.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -