当前位置:网站首页>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
边栏推荐
- The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"
- Chain ide -- the infrastructure of the metauniverse
- The automatic control system of pump station has powerful functions and diverse application scenarios
- Format character%* s
- false sharing
- Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.
- Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
- Advanced learning of MySQL -- Application -- storage engine
- Network byte order
- Remote work guide
猜你喜欢
The boss said: whoever wants to use double to define the amount of goods, just pack up and go
Lichuang EDA learning notes 14: PCB board canvas settings
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
Li Chuang EDA learning notes IX: layers
The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"
Backpropagation formula derivation [Li Hongyi deep learning version]
On Valentine's day, I code a programmer's exclusive Bing Dwen Dwen (including the source code for free)
17. File i/o buffer
Final consistency of MESI cache in CPU -- why does CPU need cache
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
随机推荐
Sword finger offer 14- I. cut rope
Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
求esp32C3板子連接mssql方法
[software implementation series] software implementation interview questions with SQL joint query diagram
Write the first CUDA program
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
Chain ide -- the infrastructure of the metauniverse
C # learning notes: structure of CS documents
Talking about custom conditions and handling errors in MySQL Foundation
Design and implementation of redis 7.0 multi part AOF
Introduction to graphics: graphic painting (I)
A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
Mysql to PostgreSQL real-time data synchronization practice sharing
Keepalived set the master not to recapture the VIP after fault recovery (it is invalid to solve nopreempt)
Global and Chinese market of digital impression system 2022-2028: Research Report on technology, participants, trends, market size and share
Override and virtual of classes in C #
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
What are the conditions for the opening of Tiktok live broadcast preview?
Leetcode 110 balanced binary tree