Мне нужно преобразовать следующий код функции tsql в функцию plpgsql, и я понятия не имею, как:
BEGIN
DECLARE @StartDate DATETIME
DECLARE @ResultDate DATETIME
SET @StartDate = CONVERT(DATETIME, 0)
SET @ResultDate =
CASE @Type
WHEN 0 THEN DATEADD(mi, FLOOR(DATEDIFF(mi, @StartDate, @Date) / CAST(@Interval AS FLOAT)) * @Interval, @StartDate)
WHEN 1 THEN DATEADD(mi, CEILING(DATEDIFF(mi, @StartDate, @Date) / CAST(@Interval AS FLOAT)) * @Interval, @StartDate)
ELSE @Date
END
RETURN @ResultDate
Вот полная кавычка:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[GetIntervalDate]
(
@Date DATETIME,
@Type INT,
@Interval INT
)
RETURNS DATETIME
AS
BEGIN
DECLARE @StartDate DATETIME
DECLARE @ResultDate DATETIME
SET @StartDate = CONVERT(DATETIME, 0)
SET @ResultDate =
CASE @Type
WHEN 0 THEN DATEADD(mi, FLOOR(DATEDIFF(mi, @StartDate, @Date) / CAST(@Interval AS FLOAT)) * @Interval, @StartDate)
WHEN 1 THEN DATEADD(mi, CEILING(DATEDIFF(mi, @StartDate, @Date) / CAST(@Interval AS FLOAT)) * @Interval, @StartDate)
ELSE @Date
END
RETURN @ResultDate
END