Bug #9050 Functions: SELECT and INSERT are allowed from within a FUNCTION
Submitted: 8 Mar 2005 14:15 Modified: 8 Mar 2005 17:11
Reporter: Disha Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.3-alpha-nt OS:Wnidows Server 2003
Assigned to: CPU Architecture:Any

[8 Mar 2005 14:15] Disha
Description:
We are able to use DML statements like SELECT, INSERT from within a function.

How to repeat:
Repro Steps : 	
1. Connect to the MySQL server as 'root'

2. Create a function fn1 by executing the following query

	Delimiter //
	Drop function if exists fn1//
	Create function fn1(a int) returns int
	Begin
		Declare b int;
		Set b=a;
		SELECT b;
		return b;
	End//
			
				
Expected Results :  The function creation should fail with the following error:
  	            ERROR 1314 (0A000): Statements like SELECT, INSERT, UPDATE (and others) are not allowed in a FUNCTION 

Actual Results :    The function creation SUCCEEDS without any errors.

Additional Info:  
If we call the function by assigning the value to a variable like 
		SET @x= Fn1(11)//
		SELECT @x//
the MySQL server crashes and connection with the MySQL server is lost. 

Also, if we call the function by using SELECT like
		SELECT fn1(33)//
we are presented with following error: ERROR 2027 (HY000) Malformed Packet
[8 Mar 2005 17:08] Alexander Keremidarski
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php
[8 Mar 2005 17:11] Alexander Keremidarski
Quoting the manual:

Note: Currently, stored functions created with CREATE FUNCTION may not contain references to tables. Please note that this includes some SET  statements, but excludes some SELECT statements.