MYSQL Error Code: 1442. Can’t update table in stored function/trigger because it is already used by statement which invoked

I think this could be simplified a lot to this:

CREATE TRIGGER Tr_Trip_insert BEFORE INSERT ON map_vehicle_person 
FOR EACH ROW
SET NEW.trip_id = COALESCE(NEW.trip_id, DATE_FORMAT(NOW() '%Y%m%d%h%m%s');

As the error tells you, you cannot INSERT/UPDATE/DELETE a table in a trigger that is the same table that spawned the trigger itself. This has too high a risk that it will cause an infinite loop.

But you can SET NEW.trip_id in a BEFORE trigger. As far as I can tell from your logic, you want to set that column on the row with the most recent id, so I guess you want to update the new row that spawned the insert trigger.

I had to make some assumptions about what you are trying to do. If I’m not correct, please describe more clearly what your intention is for this trigger.

visas – Instead of bank statement, can I provide brokerage statement?

I’m a citizen of a non-EU/US country. For a visa application, I am required to provide bank statements, signed and sealed, according to the information on the embassy’s website

Main question: Since I keep little money in any bank, can I provide brokerage statements instead?

Side questions:

Would it be a problem if my broker is US based? Address on the statement is local and its where I reside. The broker is a publicly listed company.

Can this document be virtual somehow?

mysql – Can I use assignment operator `:=` on a local variable in a SELECT statement?

From my understanding the only difference between user variables @var and local variables like var is the latter are scoped between the BEGIN and END statements of a procedure whereas user variables exist for use in the connection as long as the connection remains open. So I would like to use local variables since I don’t care if the variables exist after the procedure is done. Actually I would prefer they didn’t exist outside of the procedure.

I am trying to use the following query:

DROP TABLE IF EXISTS my_test_table;
CREATE TABLE my_test_table(var INT DEFAULT 0);
INSERT INTO my_test_table VALUES (3);

DELIMITER //
DROP PROCEDURE IF EXISTS my_sp_test_function;
CREATE PROCEDURE my_sp_test_function() 
BEGIN
    DECLARE localVar INT DEFAULT 1;
    #SET @userVar = 1; ### If we swap this line for the one above the query works. ###

    SELECT
        localVar := t.var + 1 AS return_var
        #@userVar := t.var + 1 AS return_var
    FROM my_test_table AS t; 
END; //
DELIMITER ;

CALL my_sp_test_function();

but getting a syntax error near “:= t.var + 1”. If we change the DECLARE localVar line to SET @userVar this exact query works. So is there a syntax fix I can make or a different technique I can use to save off a variable from a select statement while using local variables?

My if statement not executing properly (skipping if) C++

I’m trying to code blackjack and I’m done, but I have this one issue. For the dealer taking more cards it’s supposed to keep taking more cards until the "dealerTotal" is 17 or higher. But, I have the problem that the dealer will always only take one card and then stand. This code worked before and would keep taking another card until it was over 16. But, now it doesn’t work, and I’ve used some version diff checking and nothing is different.

if (playerTotal <= 21)
        {
            cout << endl;
            cout << "The dealer's two cards are: " << dealercard1 << " & " << dealercard2 << endl;
            cout << "The dealer's total is: " << dealerTotal << endl;

            while (loop == 1) // will keep looping until it breaks (over 17)
            {

                if (dealerTotal < 17)
                {
                    dealercardNew = rand() % 13 + 1;
                    cout << endl;
                    cout << "The dealer's new card is: " << dealercardNew << endl;
                    if (dealercardNew > 10) // sets jack, queen and king to 10
                    {
                        dealercardNew = 10;
                    }
                    dealerTotal = dealerTotal + dealercardNew; // adding new card to total

                    cout << "The dealer's new total is: " << dealerTotal << endl;

                    if (dealerTotal > 21) // dealer loss
                    {
                        cout << "The dealer's deck went Bust!" << endl;
                        break;
                    }

                    if (dealerTotal > 17 || dealerTotal == 17)
                    {
                        cout << "The Dealer chose to stand with: " << dealerTotal << endl;
                        break;
                    }
                }

                else (dealerTotal > 17 || dealerTotal == 17)
                    cout << "The Dealer chose to stand with: " << dealerTotal << endl;
                break; 


            }
        }

I have Tried removing the last else and turning it into an else if but both do not work.

Removing the else entirely makes it not do anything after the total is read out

Adding else if didnt do anything that i could notice.

The two initial cards are created using this code if helpful:

 srand(time(NULL));
        Pcard1 = rand() % 13 + 1;
        Pcard2 = rand() % 13 + 1;
        dealercard1 = rand() % 13 + 1;
        dealercard2 = rand() % 13 + 1;

8 – Get the value of a field to do an if statement Twig

I am trying to generate a PDF with Entity Print. Until then all is well.

In my Twig page, I try to make conditional displays. But I can’t get the conditions to work.

I render my fields using {{ content.field_custom }} and that also works fine.

But the condition don’t work , when I do something like :

{% if content.field_custom == 'John' %} ...

or

{% set field = content.field_custom %}
{% if field == 'John' %}
   <p>Hello</p>
{% endif %}

I need to do this in the fields twig template, can someone help me?

Many thanks

ux field – Understanding the problem statement

I have given the following problem statement to come up with a solution. The solution must be a short format communication platform meant for workplaces (TikTok/Instagram Stories). However, I struggle to understand the approach. I have been doing a competitor analysis but couldn’t find any similar competitors. Appreciate it if any of you can provide ideas or a couple of low fidelity ideas to get started.

enter image description here

Graph Theory statement proof

I can’t figure out how can I solve this problem

Let b1, b2, . . . , bk be positive integers with sum less than n. Prove that then b1!b2! . . . bk! < n!
holds.

postgresql – Why is OR statement slower than UNION

Database version: Postgresql 12.6

I have a table with 600000 records.

The table has columns:

  • name (varchar)
  • location_type (int) enum values: (1,2,3)
  • ancestry (varchar)

Indexes:

The ancestry column is a way to build a tree where every row has an ancestry containing all parent ids separated by “https://dba.stackexchange.com/”

Consider the following example:

id name ancestry
1 root null
5 node ‘1’
12 node ‘1/5’
22 leaf ‘1/5/12’

The following query takes 686 ms to execute:

SELECT * FROM geolocations
WHERE EXISTS (
   SELECT 1 FROM geolocations g2
   WHERE g2.ancestry = 
      CONCAT(geolocations.ancestry, "https://dba.stackexchange.com/", geolocations.id)
)

This query runs in 808 ms seconds:

SELECT * FROM geolocations
WHERE location_type = 2

When combining both queried with an OR it takes around 4 seconds 475 ms to finish if it ever finishes.

SELECT * FROM geolocations
WHERE EXISTS (
   SELECT 1 FROM geolocations g2
   WHERE g2.ancestry = 
      CONCAT(geolocations.ancestry, "https://dba.stackexchange.com/", geolocations.id)
) OR location_type = 2

Explain:

(
  {
    "Plan": {
      "Node Type": "Seq Scan",
      "Parallel Aware": false,
      "Relation Name": "geolocations",
      "Alias": "geolocations",
      "Startup Cost": 0,
      "Total Cost": 2760473.54,
      "Plan Rows": 582910,
      "Plan Width": 68,
      "Filter": "((SubPlan 1) OR (location_type = 2))",
      "Plans": (
        {
          "Node Type": "Index Only Scan",
          "Parent Relationship": "SubPlan",
          "Subplan Name": "SubPlan 1",
          "Parallel Aware": false,
          "Scan Direction": "Forward",
          "Index Name": "index_geolocations_on_ancestry",
          "Relation Name": "geolocations",
          "Alias": "g2",
          "Startup Cost": 0.43,
          "Total Cost": 124.91,
          "Plan Rows": 30,
          "Plan Width": 0,
          "Index Cond": "(ancestry = concat(geolocations.ancestry, "https://dba.stackexchange.com/", geolocations.id))"
        }
      )
    },
    "JIT": {
      "Worker Number": -1,
      "Functions": 8,
      "Options": {
        "Inlining": true,
        "Optimization": true,
        "Expressions": true,
        "Deforming": true
      }
    }
  }
)

While combining them with a union takes 1 sec 916 ms

SELECT * FROM geolocations
WHERE EXISTS (
   SELECT 1 FROM geolocations g2
   WHERE g2.ancestry = 
      CONCAT(geolocations.ancestry, "https://dba.stackexchange.com/", geolocations.id)
) UNION SELECT * FROM geolocations WHERE location_type = 2

Explain

(
  {
    "Plan": {
      "Node Type": "Unique",
      "Parallel Aware": false,
      "Startup Cost": 308693.44,
      "Total Cost": 332506.74,
      "Plan Rows": 865938,
      "Plan Width": 188,
      "Plans": (
        {
          "Node Type": "Sort",
          "Parent Relationship": "Outer",
          "Parallel Aware": false,
          "Startup Cost": 308693.44,
          "Total Cost": 310858.29,
          "Plan Rows": 865938,
          "Plan Width": 188,
          "Sort Key": (
            "geolocations.id",
            "geolocations.name",
            "geolocations.location_type",
            "geolocations.pricing",
            "geolocations.ancestry",
            "geolocations.geolocationable_id",
            "geolocations.geolocationable_type",
            "geolocations.created_at",
            "geolocations.updated_at",
            "geolocations.info"
          ),
          "Plans": (
            {
              "Node Type": "Append",
              "Parent Relationship": "Outer",
              "Parallel Aware": false,
              "Startup Cost": 15851.41,
              "Total Cost": 63464.05,
              "Plan Rows": 865938,
              "Plan Width": 188,
              "Subplans Removed": 0,
              "Plans": (
                {
                  "Node Type": "Hash Join",
                  "Parent Relationship": "Member",
                  "Parallel Aware": false,
                  "Join Type": "Inner",
                  "Startup Cost": 15851.41,
                  "Total Cost": 35074.94,
                  "Plan Rows": 299882,
                  "Plan Width": 68,
                  "Inner Unique": true,
                  "Hash Cond": "(concat(geolocations.ancestry, "https://dba.stackexchange.com/", geolocations.id) = (g2.ancestry)::text)",
                  "Plans": (
                    {
                      "Node Type": "Seq Scan",
                      "Parent Relationship": "Outer",
                      "Parallel Aware": false,
                      "Relation Name": "geolocations",
                      "Alias": "geolocations",
                      "Startup Cost": 0,
                      "Total Cost": 13900.63,
                      "Plan Rows": 599763,
                      "Plan Width": 68
                    },
                    {
                      "Node Type": "Hash",
                      "Parent Relationship": "Inner",
                      "Parallel Aware": false,
                      "Startup Cost": 15600.65,
                      "Total Cost": 15600.65,
                      "Plan Rows": 20061,
                      "Plan Width": 12,
                      "Plans": (
                        {
                          "Node Type": "Aggregate",
                          "Strategy": "Hashed",
                          "Partial Mode": "Simple",
                          "Parent Relationship": "Outer",
                          "Parallel Aware": false,
                          "Startup Cost": 15400.04,
                          "Total Cost": 15600.65,
                          "Plan Rows": 20061,
                          "Plan Width": 12,
                          "Group Key": (
                            "(g2.ancestry)::text"
                          ),
                          "Plans": (
                            {
                              "Node Type": "Seq Scan",
                              "Parent Relationship": "Outer",
                              "Parallel Aware": false,
                              "Relation Name": "geolocations",
                              "Alias": "g2",
                              "Startup Cost": 0,
                              "Total Cost": 13900.63,
                              "Plan Rows": 599763,
                              "Plan Width": 12
                            }
                          )
                        }
                      )
                    }
                  )
                },
                {
                  "Node Type": "Seq Scan",
                  "Parent Relationship": "Member",
                  "Parallel Aware": false,
                  "Relation Name": "geolocations",
                  "Alias": "geolocations_1",
                  "Startup Cost": 0,
                  "Total Cost": 15400.04,
                  "Plan Rows": 566056,
                  "Plan Width": 68,
                  "Filter": "(location_type = 2)"
                }
              )
            }
          )
        }
      )
    },
    "JIT": {
      "Worker Number": -1,
      "Functions": 15,
      "Options": {
        "Inlining": false,
        "Optimization": false,
        "Expressions": true,
        "Deforming": true
      }
    }
  }
)

My question is, why does postgresql execute the OR query much slower?

Bank statement requirements for student visa in Netherlands

I am a Chinese student who is going to study in Amsterdam in September. I am likely to travel from the UK, where I am currently studying.

On the website, where it asks for evidence of financial support, it mentions requiring a number of things on my sponsor’s bank statement, and ends in “email and/or website” (of the bank). I cannot get a bank statement with this – it seems like quite an odd request, I have asked some friends and most of their statements do not have either of these things on it. I am wondering if anyone has any experience with this – are they strict with this or will it be okay if I submit a bank statement without this?

postgresql – Why is OR statement slow in postgres when used with EXISTS

I have a table with 600000 records. My query is filtering by two columns one being indexed and it’s called ancestry and the other being type and it has 3 values (1,2,3) and it is not indexed.

When running the first part alone it takes 1 second to get the results. The query being:

SELECT * FROM geolocations
WHERE EXISTS (
   SELECT 1 FROM geolocations g2
   WHERE g2.ancestry = 
      CONCAT(geolocations.ancestry, "https://dba.stackexchange.com/", geolocations.id)
)

The other query runs in 0.7 seconds:

SELECT * FROM geolocations
WHERE location_type = 2

When combining both queried with an OR it takes around 70 seconds to finish if it ever finishes. I ended up using a union and it returns result in less than 2 seconds which is logical to me.

My question is, what exactly in the way postgres executes the original OR query that makes it this slow?