Having started working with PostgresSQL, I encountered a misunderstanding of the difference between the concepts of one request and one call to the server .

I used to think that if I put at the end of each script ; then I automatically receive two hits and two queries, and generally thought it was synonymous. For example:

 INSERT INTO table_01 (...) VALUES (...); INSERT INTO table_02 (...) VALUES (...); 

But then the older comrades told me that they were not synonyms, but different things.

If I enter two different scripts at once, do I always make two hits? Or not? Please help me figure out how this works?

  1. What is meant by request?
  2. What is meant by appeal?
  3. What are the main differences which account is important when connecting an application to the database?

    3 answers 3

    12)

    If you do this:

     connection.execute( "INSERT INTO table_01 (...) VALUES (...);" ); connection.execute( "INSERT INTO table_02 (...) VALUES (...);" ); 

    These are two requests and two requests.

    And if so:

     connection.execute( "INSERT INTO table_01 (...) VALUES (...);INSERT INTO table_02 (...) VALUES (...);" ); 

    That requests all the same two, and the appeal one.

    3) In the first case, after each execute you will receive one answer. Those. Only 2 answers, and in each one "value". In the second case, you will get one array (well, not exactly an array, but in this case it doesn't matter) from the answers, where there will be 2 pieces of them (answers), one value in each answer. The difference is in how to get answers (for example, how to understand, both requests are completed without errors, one - again, which one, - or none).

    And basically - you need to start by checking whether the connector can serve multi-requests at all.

      It seems to me that the request is when you send your instructions to the server.

      Accordingly, if you send a packet of requests from two instructions (as in the example), then you tell the server to "execute this" => this is one call to the server.

      The server also opens this package on its side and performs 2 requests.

        General concept

        Let's see the general meaning of the word query:

        request is:

        1) Requesting, asking for any. information, explanations, etc. to business

        If we delve into the use of this word, we will probably come to the conclusion that in one reference to something, there can be several requests, if there is such a possibility.

        Although in essence, in common usage these are practical synonyms.

        Analogy in real life

        We give an analogy with a person, suppose you want to disturb someone with your question. Approach the person and speak:

        • Tell me please, where can I find the nearest coffee house?

        How many calls and requests are there? Right one! You once turned to the man.

        • Tell me please, where can I find the nearest coffee house? And I wonder where there is a museum?

        Yeah, there is still one appeal to a person, but there are already two requests. Then consider the situation from another plan:

        • Tell me where can I find the nearest coffee house?
        • The nearest coffee shop is at the end of this street.
        • Thank! Tell me more, where can I find a grocery store?

        How many calls and requests did you make to a person? Two each. That's right.

        Database

        It also works in the database, you access the database, but you can send several requests at once in one call to reduce data transfer costs, if there is a possibility in the driver, if no further actions in the code depend on the execution of this request.

        If there are a lot of queries on INSERT, then it is probably better to fit them into one construct in order to speed up the insertion.

         INSERT INTO table VALUES (1,2,3,4), (1,2,3,4); 

        Unless of course this is supported by the database syntax, then there will be one query and one hit.