From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id A66F428554 for ; Thu, 7 Mar 2019 09:40:26 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YuHN9VD272pN for ; Thu, 7 Mar 2019 09:40:26 -0500 (EST) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 62B6524216 for ; Thu, 7 Mar 2019 09:40:26 -0500 (EST) Subject: [tarantool-patches] Re: [PATCH 1/2] sql: derive collation for built-in functions References: <92715853-76c0-36ca-1bae-84a8a8939f7e@tarantool.org> <7CC1E113-479D-46FC-9A6F-6BE73E918FE7@tarantool.org> From: Vladislav Shpilevoy Message-ID: Date: Thu, 7 Mar 2019 17:40:24 +0300 MIME-Version: 1.0 In-Reply-To: <7CC1E113-479D-46FC-9A6F-6BE73E918FE7@tarantool.org> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: "n.pettik" , tarantool-patches@freelists.org >> For user-defined functions and for >> bind parameters it does not fit. How can you determine >> a function's result collation, if it is not builtin, and >> does not depend on arguments? > > In no way. We can extend signature of sql_create_function > and allow to pass collation to be applied to returning value. > But I am not sure that we should do this. Anyway, it wouldn't > help us with the initial issue: in our case collation is dependent > on one of arguments, so it *dynamically* changes. Hence, I > guess these problems are barely related. > > Also, inlining comment from P.Gulutzan: > (https://github.com/tarantool/tarantool/issues/3932) > > ‘’' > > It is true that user-defined functions will not know some things about > what an SQL caller is passing. We don't promise that they will, so I > think it is okay that it is the caller's responsibility to make sure > relevant information is passed explicitly. A possible issue is that the > function cannot use the utf8 module for all possible collations, but > that is not an SQL issue. > > ‘'' So do you mean that any string returned from a user defined function always has no any collation? I do not talk about Lua functions only. In future we are going to introduce SQL functions. > >> Does SQL standard allow to define user functions without >> a runtime defined collation? If SQL standard does not define >> SQL functions at all, then what other vendors do with that >> problem? > > There’s no such opportunity in ANSI, if I’m not mistaking. > Generally speaking, other vendors have procedural SQL. > And since PSQL is a part of SQL, there are no such problems: > collation is a part of string-like types. > It contradicts with your way of collation return. If PSQL states that collation is a part of string-like type, then it is possible to implement a function doing something like this: function my_func() if (rand() % 2 == 0) then return 'abc' collate 'unicode_ci'; return 'abc' collate 'unicode'; end; (I do not know PSQL syntax - the code above is pseudo- ). As I see, now we have no runtime defined collations at all - all of them are known during compilation. Struct Mem, storing function return value, even has no collation member. I guess, we can not implement runtime collations now.