1. A computer implemented method comprising: a SQL compiler rewriting a certain query that includes a first function to generate a rewritten query, wherein the certain query applies certain data to said first function, wherein rewriting the certain query includes: during compile time, said SQL compiler determining that said certain data is dynamically typed; and in response to determining that said certain data is dynamically typed, said SQL compiler replacing said first function with a user-defined polymorphic function that is able to handle a range of data types and performs type checking when computed at run time, said rewritten query applying said certain data to said user-defined polymorphic function and typing said certain data as a global data type representing a plurality of specific data types; wherein said method is performed by one or more computing devices.