[MDEV-8812] Giving an alias to function argument (now can make the query to fail) Created: 2015-09-17  Updated: 2017-05-30  Resolved: 2017-05-30

Status: Closed
Project: MariaDB Server
Component/s: Parser
Fix Version/s: N/A

Type: Task Priority: Minor
Reporter: Olivier Bertrand Assignee: Sergei Golubchik
Resolution: Won't Fix Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-8822 Aliases for UDF arguments in MariaDB KB Open

 Description   

The query, calling a UDF:

select Json_Object(5 as "five", 7 as "seven");

works fine; however, this one:

select greatest(5 as "five", 7 as "seven");

fails saying: "Incorrect parameters in the call to native function "greatest".

Indeed, in this case, aliases are useless but why flag this as an error? Perhaps a warning saying that these aliases are ignored would be acceptable.

BTW: The MariaDB documentation on aliases (in the tutorial) does not say anything about aliasing function arguments. This is an important feature for UDF's as it correspond to the attribute of arguments.



 Comments   
Comment by Elena Stepanova [ 2015-09-20 ]

I created a subtask (MDEV-8822) for the documentation shortage.

Aliases for function arguments is a feature request, so the issue has been switched from Bug to Task.
Looking at the SQL standard, I am not sure it should be implemented. If I read it right, it says that a function call can indeed have AS ... clause, but it would be AS UDT type rather than AS alias.
Not having UDT types in the current implementation is one thing, but using the syntax for something different is another.
However, I'm never sure I understand the standard correctly, so I'll keep it open till serg says his word.

Comment by Sergei Golubchik [ 2017-05-30 ]

As far as I can see, AS UDT only applies to stored routines, not to built-in functions. AS xxx in built-in functions is non-standard and doesn't serve any useful (or useless, fwiw) purpose.

In UDFs it's non-standard and very non-conventional and inconsistent. But it's a historical feature that we preserve for compatibility reasons. I don't see why it should work for other (not UDF) functions, if it's useless there. Especially, as it might conflict with future extensions (like AS UDT).

Comment by Olivier Bertrand [ 2017-05-30 ]

I agree on this, I was just suggesting to treat it as a warning instead of a syntax error.

By the way, as I commented in MDEV-12877, there is a problem about the "type" of a function result. For instance, some of the new JSON functions return a String but somewhere MariaDB test to know if this is a JSON item or not. Actually I don't know what criterium they use but it fails in some case.

In the JSON UDFs, I am using the alias to test this and I don't know what I could use if this was not kept in future versions. For instance, using alias is what enables a function like JSON_MAKE_OBJECT to make a JSON object from values retrieved from a table, the alias being the column name. For instance:

SELECT JSON_MAKE_OBJECT(name, title) FROM employee WHERE name = 'Smith';

Returns:

{"name":"Smith", "title":"Engineer"}

I don' think this can be achieved with a native function.

Generated at Thu Feb 08 07:29:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.