Why the "quotation marks" in the INT data?

3

In the MySQL Workbench , when we do not enter a record by query , and manually, when giving APPLY , the query is displayed before execution.

Example of a query consisting of MySQL Workbench :

INSERT INTO 'nomedobanco'.'tabela' ('id', 'resumo', 'descricao', 'grupo', 'solicitante', 'atendente', 'status') 
VALUES ('171', 'Teste', 'Testando', '7', '1', '2', 'N');

How would it work:

INSERT INTO 'nomedobanco'.'tabela' ('id', 'resumo', 'descricao', 'grupo', 'solicitante', 'atendente', 'status') 
VALUES (171, 'Teste', 'Testando', 7, 1, 2, 'N');

Questions

  • Why MySQL Workbench puts quotation marks in INT values?
    • Does it not identify the type of fields and end up inserting everything "as string"?
asked by anonymous 13.09.2018 / 11:58

1 answer

1

First of all this is not an exclusive of Workbench . I used other tools and SqlYog for example, does exactly the same thing.

This is to optimize the query generation. Because MySql does not claim to receive integer values in quotation marks, these programs use this artifact so that you do not need to check the column type to set the value between quotation marks.

But be careful when using this artifice. In the case of INSERT and SET of UPDATE , that is, assignments, I do not see much problem. But in WHERE you may have some problems related to query performance. This is because, when comparing text with number, MySql performs a type conversion, so in these cases, it is best to use numbers without quotation marks, if compared to numbers.

  

Note that Workbench also places numeric values in quotation marks in comparisons.

In% w / w it probably also performs this conversion, but since the amount of data is usually small it becomes irrelevant (not true for all cases).

    
25.09.2018 / 21:50