Postgres中的LAST_DAY函数 [英] LAST_DAY function in postgres

查看:2013
本文介绍了Postgres中的LAST_DAY函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

postgres中是否有任何与Oracle函数LAST_DAY()等效的函数。

Is there any function(s) in postgres equivalent to Oracle function LAST_DAY().

我需要在postgres中获取最后一天(包括月份和年份)

I need to get last day in postgres (including month and year)

推荐答案

好,在postgres中,似乎没有等效于 LAST_DAY()在oracle中可用。

Well, In postgres, it seems there's no such function equivalent to LAST_DAY() available in oracle.

如果需要,您可以通过以下方式拥有自己的内容:

If you need to, you can have your own in the following ways as a

SELECT (date_trunc('MONTH', now()) + INTERVAL '1 MONTH - 1 day')::date;



plsql函数



plsql Function

        CREATE OR REPLACE FUNCTION last_day(date)
        RETURNS date AS
        $$
        SELECT (date_trunc('MONTH', $1) + INTERVAL '1 MONTH - 1 day')::date;
        $$ LANGUAGE 'sql'
        IMMUTABLE STRICT;

希望这会有所帮助。

这篇关于Postgres中的LAST_DAY函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆