I have a function with a conditional result. Based on the argument value it should either return varchar
or int
or uuid
or timestamp
.
What should the return type of that function be?
SQL is strictly typed. The simple solution is to return one text
field . Every value can be cast to text
. (You might add a second return column holding the type name as meta information.)
Alternatively, return four typed fields (varchar, int, uuid, timestamp)
, and only fill one of them, depending on the result.
A polymorphic function would only be an option if you can tell the return type at call time and pass typed input accordingly.
Related:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.