创建一个postgresql函数,该功能返回字符串' fall',' spring'取决于年份
我需要创建一个函数,该功能根据一年的月份返回字符串“秋季”或“春季”。如果该函数被命名为getTerm,并且没有参数,则我想在这样的选择语句中使用它:
选择名称,className,从classtable
classtable保留我们提供的类的名称。结果集将包含如下的列:
-Jack,Data Systems,SP2022
-Jill,Web Quits,F2023
我使用了NOW()函数。我也可以使用提取物(从现在开始()()来获取我的当前季度。然后,使用“ if”或“ case”子句返回“春季”或“秋天”似乎很简单。我只是没有找到这样的函数的示例。
谁能建议一些示例代码?
I need to create a function that returns the string 'fall' or 'spring' depending on the month of the year. If the function was named getterm and took no parameters I would like to use it in a select statement like this:
select name, classname, getterm from classtable
where classtable holds the names of the classes we offer. The result set would include the columns as follows:
-Jack, Data Systems, Sp2022
-Jill, Web Stuff, F2023
I have used the now() function. I can also use extract(quarter from now()) to get my current quarter. It would seem simple then to use an 'if' or 'case' clause to return 'spring' or 'fall' based upon the quarters. I just haven't found any examples of a function like this.
Can anyone suggest some sample code ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个文档从这里
这在您的情况下转化为:
Per documentation from here CASE:
This translates in your case to:
谢谢Adrian ..我现在有工作功能:
Thank you to Adrian.. I now have the working function: