当前位置:网站首页>This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
2022-07-04 02:43:00 【Mr.zhou_ Zxy】
Origin of problem :
topic :
surface : Employee
+-------------+------+
| Column Name | Type |
+-------------+------+
| id | int |
| salary | int |
+-------------+------+
Id Is the primary key column of the table .
Each row of the table contains information about the employee's salary .
Write a SQL Query to report Employee No n High wages . If there is no n A maximum wage , The query should be reported as null .
The query result format is as follows .
Example 1:
Input :
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
n = 2
Output :
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200 |
+------------------------+
Example 2:
Input :
Employee surface :
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
+----+--------+
n = 2
Output :
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| null |
+------------------------+
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/nth-highest-salary
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Explain :
-- function
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
set N = N - 1;
RETURN (
select ifnull((select distinct Salary from Employee order by Salary desc limit N,1),null)
as getNthHighestSalary
);
END
-- perform
select getNthHighestSalary(2)
Problems arise :
Problem analysis :
That's because it turns on bin-log journal , We must determine the following points in the function
deterministic Not sure of
no sql No, SQL sentence
reads sql data Read only data
modifies sql data Modifying data
contains sql contain SQL sentence
Because in function in , Only deterministic ,no sql,reads sql data Be supported . So open bin-log Must be after function Specify the parameters
Problem solving :
show variables like ‘log_bin_trust_function_creators’;
set global log_bin_trust_function_creators = 1
show variables like ‘log_bin_trust_function_creators’;
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
set N = N - 1;
RETURN (
select ifnull((select distinct Salary from Employee order by Salary desc limit N,1),null)
as getNthHighestSalary
);
END
select getNthHighestSalary(2)
Add :
Using the above method will fail after the database is restarted , The following methods can be used for long-term effectiveness
[email protected]_zxy ~]# vim /etc/my.cnf
Add at the end
log_bin_trust_function_creators = 1
边栏推荐
- Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends
- Network communication basic kit -- IPv4 socket structure
- Comment la transformation numérique du crédit d'information de la Chine passe - t - elle du ciel au bout des doigts?
- Global and Chinese market of small batteries 2022-2028: Research Report on technology, participants, trends, market size and share
- Learn these super practical Google browser skills, girls casually flirt
- Dans la recherche de l'intelligence humaine ai, Meta a misé sur l'apprentissage auto - supervisé
- WP collection plug-in free WordPress collection hang up plug-in
- Ai aide à la recherche de plagiat dans le design artistique! L'équipe du professeur Liu Fang a été embauchée par ACM mm, une conférence multimédia de haut niveau.
- Career development direction
- Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
猜你喜欢
LV1 tire pressure monitoring
[Yugong series] February 2022 attack and defense world advanced question misc-84 (MySQL)
Database concept and installation
From the 18th line to the first line, the new story of the network security industry
17. File i/o buffer
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
Save Private Ryan - map building + voltage dp+deque+ shortest circuit
Crawler practice website image batch download
FRP intranet penetration
Ai aide à la recherche de plagiat dans le design artistique! L'équipe du professeur Liu Fang a été embauchée par ACM mm, une conférence multimédia de haut niveau.
随机推荐
The difference between lambda expressions and anonymous inner classes
Learn these super practical Google browser skills, girls casually flirt
Save Private Ryan - map building + voltage dp+deque+ shortest circuit
What is the intelligent monitoring system of sewage lifting pump station and does it play a big role
[untitled] the relationship between the metauniverse and digital collections
Bugku Zhi, you have to stop him
Global and Chinese market of thin film deposition systems 2022-2028: Research Report on technology, participants, trends, market size and share
中電資訊-信貸業務數字化轉型如何從星空到指尖?
Yyds dry goods inventory override and virtual of classes in C
A. Min Max Swap
Comment la transformation numérique du crédit d'information de la Chine passe - t - elle du ciel au bout des doigts?
Li Chuang EDA learning notes IX: layers
Imperial cms7.5 imitation "D9 download station" software application download website source code
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
Question C: Huffman tree
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
[software implementation series] software implementation interview questions with SQL joint query diagram
16. System and process information
Network communication basic kit -- IPv4 socket structure