From f5292136c72fe520d5b4db926dfb6d0cd41ce099 Mon Sep 17 00:00:00 2001 From: surister Date: Mon, 25 Mar 2024 16:54:39 +0100 Subject: [PATCH] Fix many dialect compatability issues. --- cratedb_tableau_jdbc/dialect.tdd | 353 +++++++++++++++---------------- 1 file changed, 170 insertions(+), 183 deletions(-) diff --git a/cratedb_tableau_jdbc/dialect.tdd b/cratedb_tableau_jdbc/dialect.tdd index 79b145d..d9ada51 100644 --- a/cratedb_tableau_jdbc/dialect.tdd +++ b/cratedb_tableau_jdbc/dialect.tdd @@ -81,7 +81,7 @@ - 0 AND %2 > 0 AND %2 <> 1 THEN LOG(CAST(%2 AS NUMERIC),CAST(%1 AS NUMERIC)) ELSE NULL END)]]> + 0 AND %2 > 0 AND %2 <> 1 THEN LOG(CAST(%1 AS NUMERIC),CAST(%2 AS NUMERIC)) ELSE NULL END)]]> @@ -124,8 +124,7 @@ PI() - - %2 THEN NULL ELSE POWER(%1,%2) END)]]> + %2 THEN NULL ELSE POWER(%1,%2) END)]]> @@ -202,18 +201,16 @@ (CASE WHEN %3 IS NULL THEN NULL - WHEN 0 = STRPOS(SUBSTR(CAST(%1 AS TEXT),GREATEST(1,CAST(FLOOR(%3) AS - INTEGER))),CAST(%2 AS TEXT)) THEN 0 - ELSE (STRPOS(SUBSTR(CAST(%1 AS TEXT),GREATEST(1,CAST(FLOOR(%3)AS INTEGER))),CAST(%2 - AS TEXT)) + GREATEST(1,CAST(FLOOR(%3) AS INTEGER)) - 1) END) + WHEN 0 = STRPOS(SUBSTR(CAST(%1 AS TEXT),GREATEST(1,CAST(FLOOR(%3) AS INTEGER))),CAST(%2 AS TEXT)) THEN 0 + ELSE (STRPOS(SUBSTR(CAST(%1 AS TEXT),GREATEST(1,CAST(FLOOR(%3)AS INTEGER))),CAST(%2 AS TEXT)) + + GREATEST(1,CAST(FLOOR(%3) AS INTEGER)) - 1) END) - (CASE WHEN %2 >= 0 THEN SUBSTR(CAST(%1 AS TEXT), 1, CAST(FLOOR(%2) AS - INTEGER)) ELSE NULL END) + (CASE WHEN %2 >= 0 THEN SUBSTR(CAST(%1 AS TEXT), 1, CAST(FLOOR(%2) AS INTEGER)) ELSE NULL END) @@ -227,7 +224,12 @@ - LTRIM(CAST(%1 AS TEXT), ' ') + + CASE LTRIM(%1) + WHEN '' THEN NULL + ELSE LTRIM(%1) + END + @@ -240,15 +242,15 @@ - (CASE WHEN %2 IS NULL THEN NULL ELSE SUBSTR(CAST(%1 AS TEXT), - GREATEST(1,CAST(FLOOR(%2) AS INTEGER))) END) + (CASE WHEN %2 IS NULL THEN NULL ELSE SUBSTR(CAST(%1 AS TEXT), GREATEST(1,CAST(FLOOR(%2) AS + INTEGER))) END) - (CASE WHEN %2 IS NULL THEN NULL ELSE SUBSTR(CAST(%1 AS TEXT), - GREATEST(1,CAST(FLOOR(%2) AS INTEGER)), GREATEST(0,CAST(FLOOR(%3) AS INTEGER))) END) + (CASE WHEN %2 IS NULL THEN NULL ELSE SUBSTR(CAST(%1 AS TEXT), GREATEST(1,CAST(FLOOR(%2) AS + INTEGER)), GREATEST(0,CAST(FLOOR(%3) AS INTEGER))) END) @@ -291,31 +293,39 @@ - (CASE WHEN %2 >= 0 THEN SUBSTR(CAST(%1 AS TEXT), (LENGTH(CAST(%1 AS TEXT)) - - CAST(FLOOR(%2) AS INTEGER) + 1) ) ELSE NULL END) + (CASE WHEN %2 >= 0 THEN SUBSTR(CAST(%1 AS TEXT), (LENGTH(CAST(%1 AS TEXT)) - CAST(FLOOR(%2) AS + INTEGER) + 1) ) ELSE NULL END) - RTRIM(CAST(%1 AS TEXT), ' ') + + CASE RTRIM(%1) + WHEN '' THEN NULL + ELSE RTRIM(%1) + END + - (CASE WHEN %1 >= 0 THEN REPEAT(' ', CAST(FLOOR(%1) AS INTEGER)) - ELSE NULL END) + (CASE WHEN %1 >= 0 THEN REPEAT(' ', CAST(FLOOR(%1) AS INTEGER)) ELSE NULL END) - (SUBSTR(LTRIM(CAST(%1 AS TEXT), ' '), 1, LENGTH(CAST(%2 AS TEXT))) = - CAST(%2 AS TEXT)) + (SUBSTR(LTRIM(CAST(%1 AS TEXT), ' '), 1, LENGTH(CAST(%2 AS TEXT))) = CAST(%2 AS TEXT)) - BTRIM(CAST(%1 AS TEXT), ' ') + + CASE BTRIM(%1) + WHEN '' THEN NULL + ELSE BTRIM(%1) + END + @@ -375,8 +385,8 @@ CURRENT_DATE - CAST(FLOOR((7 + EXTRACT(DOY FROM %1) - 1 + EXTRACT(DOW FROM DATE_TRUNC('YEAR', - %1))) / 7) AS INTEGER) + CAST(FLOOR((7 + EXTRACT(DOY FROM %1) - 1 + EXTRACT(DOW FROM DATE_TRUNC('YEAR', %1))) / 7) + AS INTEGER) @@ -385,9 +395,7 @@ - date_trunc('day', CAST('1900-01-01' AS DATE) + %1 * - INTERVAL '1 DAY') - + %1 :: DATE @@ -399,7 +407,7 @@ - (CAST('1900-01-01 00:00:00' AS TIMESTAMP) + %1 * INTERVAL '1 DAY') + %1 :: TIMESTAMP @@ -651,8 +659,7 @@ COVAR_POP(%1, %2) - (CASE WHEN %1 IS NULL THEN NULL WHEN %2 IS NULL THEN NULL ELSE 0.0 END) - + (CASE WHEN %1 IS NULL THEN NULL WHEN %2 IS NULL THEN NULL ELSE 0.0 END) @@ -722,8 +729,8 @@ - (CASE WHEN COUNT(%1) = 1 THEN 0.0 WHEN COUNT(%1) > 0 THEN (STDDEV(%1) * - SQRT(COUNT(%1) - 1) / SQRT(COUNT(%1)) ) ELSE NULL END) + (CASE WHEN COUNT(%1) = 1 THEN 0.0 WHEN COUNT(%1) > 0 THEN (STDDEV(%1) * SQRT(COUNT(%1) - 1) / + SQRT(COUNT(%1)) ) ELSE NULL END) (CASE WHEN %1 IS NULL THEN NULL ELSE 0.0 END) @@ -744,8 +751,8 @@ - (CASE WHEN COUNT(%1) = 1 THEN 0.0 WHEN COUNT(%1) > 0 THEN POWER(STDDEV(%1) * - SQRT(COUNT(%1) - 1) / SQRT(COUNT(%1)), 2) ELSE NULL END) + (CASE WHEN COUNT(%1) = 1 THEN 0.0 WHEN COUNT(%1) > 0 THEN POWER(STDDEV(%1) * SQRT(COUNT(%1) - 1) + / SQRT(COUNT(%1)), 2) ELSE NULL END) (CASE WHEN %1 IS NULL THEN NULL ELSE 0.0 END) @@ -775,9 +782,7 @@ - (CASE WHEN %2 = 0 THEN NULL ELSE %1 - FLOOR(ABS(%1)/ABS(%2)) * ABS(%2) * - SIGN(%1) END) - + (CASE WHEN %2 = 0 THEN NULL ELSE %1 - FLOOR(ABS(%1)/ABS(%2)) * ABS(%2) * SIGN(%1) END) @@ -860,8 +865,7 @@ - (CASE WHEN %2 = 0 THEN NULL ELSE CAST(%1 AS DOUBLE PRECISION) / %2 END) - + (CASE WHEN %2 = 0 THEN NULL ELSE CAST(%1 AS DOUBLE PRECISION) / %2 END) @@ -946,8 +950,7 @@ - - %2 THEN NULL ELSE POWER(%1,%2) END)]]> + %2 THEN NULL ELSE POWER(%1,%2) END)]]> @@ -972,107 +975,114 @@ CAST(TRUNC(EXTRACT(ISODOW FROM %1)) AS INTEGER) + TRY_CAST(%1 AS DATE) IS NOT NULL + (%3 + %2 * INTERVAL '1 %1') - (%3 + %2 * 3 * INTERVAL '1 MONTH') + (%3 :: TIMESTAMP + %2 * 3 * INTERVAL '1 month') (%3 + %2 * INTERVAL '1 WEEK') (%3 + %2 * INTERVAL '1 DAY') - (%3 + (((CAST(DATE_TRUNC('DAY', CAST((DATE('1753-01-04') - + ((EXTRACT(ISOYEAR FROM CAST(%3 AS TIMESTAMP)) + %2) - 1753) * INTERVAL '1 - YEAR') AS TIMESTAMP)) AS DATE) - (((7 + CAST(EXTRACT(DOW FROM (DATE('1753-01-04') - + ((EXTRACT(ISOYEAR FROM CAST(%3 AS TIMESTAMP)) + %2) - 1753) * INTERVAL '1 - YEAR')) AS BIGINT) - 1) % 7) * INTERVAL '1 DAY')) + (CAST(%3 AS DATE) - - TO_DATE(TO_CHAR(%3, 'IYYY-01'), 'IYYY-IW')) * INTERVAL '1 - DAY') - CAST(%3 AS DATE))) - - (%3 + (((CAST(DATE_TRUNC('DAY', CAST((DATE('1753-01-04') - + ((CAST(((EXTRACT(ISOYEAR FROM CAST(%3 AS TIMESTAMP)) * 4 + - (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS BIGINT) / 13, 3) + 1)) + %2) AS INT) / 4) - - 1753) * INTERVAL '1 YEAR') AS TIMESTAMP)) AS DATE) - (((7 + - CAST(EXTRACT(DOW FROM (DATE('1753-01-04') + ((CAST(((EXTRACT(ISOYEAR FROM - CAST(%3 AS TIMESTAMP)) * 4 + (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS BIGINT) / - 13, 3) + 1)) + %2) AS INT) / 4) - 1753) * INTERVAL '1 YEAR')) AS BIGINT) - - 1) % 7) * INTERVAL '1 DAY')) + (((CAST(((EXTRACT(ISOYEAR FROM CAST(%3 AS - TIMESTAMP)) * 4 + (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS BIGINT) / 13, 3) + 1)) - + %2) AS INT) % 4) - 1) * 91 + (CAST(%3 AS DATE) - TO_DATE(TO_CHAR(%3, 'IYYY-') - || (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS BIGINT) / 13, 3) * 13 + 1), 'IYYY-IW'))) + (%3 + (((CAST(DATE_TRUNC('DAY', CAST((DATE('1753-01-04') + + ((EXTRACT(ISOYEAR FROM CAST(%3 AS TIMESTAMP)) + %2) - 1753) * INTERVAL '1 YEAR') AS + TIMESTAMP)) AS DATE) - (((7 + CAST(EXTRACT(DOW FROM (DATE('1753-01-04') + ((EXTRACT(ISOYEAR + FROM CAST(%3 AS TIMESTAMP)) + %2) - 1753) * INTERVAL '1 YEAR')) AS BIGINT) - 1) % 7) * + INTERVAL '1 DAY')) + (CAST(%3 AS DATE) - TO_DATE(TO_CHAR(%3, 'IYYY-01'), 'IYYY-IW')) * INTERVAL '1 DAY') - CAST(%3 AS DATE))) + (%3 + (((CAST(DATE_TRUNC('DAY', CAST((DATE('1753-01-04') + + ((CAST(((EXTRACT(ISOYEAR FROM CAST(%3 AS TIMESTAMP)) * 4 + (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS + BIGINT) / 13, 3) + 1)) + %2) AS INT) / 4) - 1753) * INTERVAL '1 YEAR') AS TIMESTAMP)) AS DATE) + - (((7 + CAST(EXTRACT(DOW FROM (DATE('1753-01-04') + ((CAST(((EXTRACT(ISOYEAR FROM CAST(%3 AS + TIMESTAMP)) * 4 + (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS BIGINT) / 13, 3) + 1)) + %2) AS INT) / 4) - + 1753) * INTERVAL '1 YEAR')) AS BIGINT) - 1) % 7) * INTERVAL '1 DAY')) + + (((CAST(((EXTRACT(ISOYEAR FROM CAST(%3 AS TIMESTAMP)) * 4 + (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS + BIGINT) / 13, 3) + 1)) + %2) AS INT) % 4) - 1) * 91 + (CAST(%3 AS DATE) - TO_DATE(TO_CHAR(%3, 'IYYY-') + || (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS BIGINT) / 13, 3) * 13 + 1), 'IYYY-IW'))) * + INTERVAL '1 DAY') - CAST(%3 AS DATE))) + + + %3 :: TIMESTAMP + INTERVAL '%2 %1' + + + + - CAST( FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 86400) - - FLOOR(EXTRACT(EPOCH FROM CAST(%2 AS TIMESTAMP)) / 86400) AS BIGINT) + CAST( FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 86400) - FLOOR(EXTRACT(EPOCH FROM CAST(%2 + AS TIMESTAMP)) / 86400) AS BIGINT) - CAST( EXTRACT(YEAR FROM CAST(%3 AS TIMESTAMP)) - EXTRACT(YEAR FROM - CAST(%2 AS TIMESTAMP)) AS BIGINT) + CAST( EXTRACT(YEAR FROM CAST(%3 AS TIMESTAMP)) - EXTRACT(YEAR FROM CAST(%2 AS + TIMESTAMP)) AS BIGINT) - CAST( (4 * EXTRACT(YEAR FROM CAST(%3 AS TIMESTAMP)) + - EXTRACT(QUARTER FROM CAST(%3 AS TIMESTAMP))) - (4 * EXTRACT(YEAR FROM CAST(%2 AS - TIMESTAMP)) + EXTRACT(QUARTER FROM CAST(%2 AS TIMESTAMP))) AS BIGINT) + CAST( (4 * EXTRACT(YEAR FROM CAST(%3 AS TIMESTAMP)) + EXTRACT(QUARTER FROM CAST(%3 + AS TIMESTAMP))) - (4 * EXTRACT(YEAR FROM CAST(%2 AS TIMESTAMP)) + EXTRACT(QUARTER FROM CAST(%2 AS + TIMESTAMP))) AS BIGINT) - CAST( (12 * EXTRACT(YEAR FROM CAST(%3 AS TIMESTAMP)) + - EXTRACT(MONTH FROM CAST(%3 AS TIMESTAMP))) - (12 * EXTRACT(YEAR FROM CAST(%2 AS - TIMESTAMP)) + EXTRACT(MONTH FROM CAST(%2 AS TIMESTAMP))) AS BIGINT) + CAST( (12 * EXTRACT(YEAR FROM CAST(%3 AS TIMESTAMP)) + EXTRACT(MONTH FROM CAST(%3 AS + TIMESTAMP))) - (12 * EXTRACT(YEAR FROM CAST(%2 AS TIMESTAMP)) + EXTRACT(MONTH FROM CAST(%2 AS + TIMESTAMP))) AS BIGINT) - CAST( FLOOR(( (FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / - 86400) - EXTRACT(DOW FROM CAST(%3 AS TIMESTAMP)) ) - (FLOOR(EXTRACT(EPOCH FROM - CAST(%2 AS TIMESTAMP)) / 86400)- EXTRACT(DOW FROM CAST(%2 AS TIMESTAMP)) ) ) / 7) AS - BIGINT) + CAST( FLOOR(( (FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 86400) - EXTRACT(DOW + FROM CAST(%3 AS TIMESTAMP)) ) - (FLOOR(EXTRACT(EPOCH FROM CAST(%2 AS TIMESTAMP)) / 86400)- EXTRACT(DOW + FROM CAST(%2 AS TIMESTAMP)) ) ) / 7) AS BIGINT) - CAST( FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 3600) - - FLOOR(EXTRACT(EPOCH FROM CAST(%2 AS TIMESTAMP)) / 3600) AS BIGINT) + CAST( FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 3600) - FLOOR(EXTRACT(EPOCH + FROM CAST(%2 AS TIMESTAMP)) / 3600) AS BIGINT) - CAST( FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 60) - - FLOOR(EXTRACT(EPOCH FROM CAST(%2 AS TIMESTAMP)) / 60) AS BIGINT) + CAST( FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 60) - FLOOR(EXTRACT(EPOCH + FROM CAST(%2 AS TIMESTAMP)) / 60) AS BIGINT) - CAST( EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) - EXTRACT(EPOCH - FROM CAST(%2 AS TIMESTAMP)) AS BIGINT) + CAST( EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) - EXTRACT(EPOCH FROM CAST(%2 AS + TIMESTAMP)) AS BIGINT) - CAST( FLOOR(( (FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) - / 86400) - ((7 + CAST(EXTRACT(DOW FROM %3) AS BIGINT) - 1) % 7)) - - (FLOOR(EXTRACT(EPOCH FROM CAST(%2 AS TIMESTAMP)) / 86400) - ((7 + CAST(EXTRACT(DOW - FROM %2) AS BIGINT) - 1) % 7)) ) / 7) AS BIGINT) + CAST( FLOOR(( (FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 86400) - ((7 + + CAST(EXTRACT(DOW FROM %3) AS BIGINT) - 1) % 7)) - (FLOOR(EXTRACT(EPOCH FROM CAST(%2 AS TIMESTAMP)) / + 86400) - ((7 + CAST(EXTRACT(DOW FROM %2) AS BIGINT) - 1) % 7)) ) / 7) AS BIGINT) - CAST( FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / - 86400) - FLOOR(EXTRACT(EPOCH FROM CAST(%2 AS TIMESTAMP)) / 86400) AS BIGINT) + CAST( FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 86400) - + FLOOR(EXTRACT(EPOCH FROM CAST(%2 AS TIMESTAMP)) / 86400) AS BIGINT) - CAST( EXTRACT(ISOYEAR FROM CAST(%3 AS TIMESTAMP)) - - EXTRACT(ISOYEAR FROM CAST(%2 AS TIMESTAMP)) AS BIGINT) + CAST( EXTRACT(ISOYEAR FROM CAST(%3 AS TIMESTAMP)) - EXTRACT(ISOYEAR FROM CAST(%2 AS + TIMESTAMP)) AS BIGINT) - CAST((4 * EXTRACT(ISOYEAR FROM %3) + - (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS BIGINT) / 13, 3) + 1)) - (4 * - EXTRACT(ISOYEAR FROM %2) + (LEAST(CAST((EXTRACT(WEEK FROM %2) - 1) AS BIGINT) / 13, - 3) + 1)) AS BIGINT) + CAST((4 * EXTRACT(ISOYEAR FROM %3) + (LEAST(CAST((EXTRACT(WEEK FROM %3) - 1) AS + BIGINT) / 13, 3) + 1)) - (4 * EXTRACT(ISOYEAR FROM %2) + (LEAST(CAST((EXTRACT(WEEK FROM %2) - 1) AS + BIGINT) / 13, 3) + 1)) AS BIGINT) - CAST( FLOOR(( (FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / - 86400) - ((7 + CAST(EXTRACT(DOW FROM %3) AS BIGINT) - 1) % 7)) - - (FLOOR(EXTRACT(EPOCH FROM CAST(CAST(%2 AS TIMESTAMP) AS TIMESTAMP)) / 86400) - ((7 + - CAST(EXTRACT(DOW FROM CAST(%2 AS TIMESTAMP)) AS BIGINT) - 1) % 7)) ) / 7) AS BIGINT) + CAST( FLOOR(( (FLOOR(EXTRACT(EPOCH FROM CAST(%3 AS TIMESTAMP)) / 86400) - ((7 + + CAST(EXTRACT(DOW FROM %3) AS BIGINT) - 1) % 7)) - (FLOOR(EXTRACT(EPOCH FROM CAST(CAST(%2 AS TIMESTAMP) + AS TIMESTAMP)) / 86400) - ((7 + CAST(EXTRACT(DOW FROM CAST(%2 AS TIMESTAMP)) AS BIGINT) - 1) % 7)) ) / + 7) AS BIGINT) + + EXTRACT(DAY FROM %2::TIMESTAMP - %3::TIMESTAMP) * -1 + + + + TO_CHAR(%2, '%1') - CAST(FLOOR((7 + EXTRACT(DOY FROM %2) - 1 + EXTRACT(DOW FROM - DATE_TRUNC('YEAR', %2))) / 7) AS TEXT) + CAST(FLOOR((7 + EXTRACT(DOY FROM %2) - 1 + EXTRACT(DOW FROM DATE_TRUNC('YEAR', + %2))) / 7) AS TEXT) - CAST((LEAST(CAST((EXTRACT(WEEK FROM %2) - 1) AS BIGINT) / - 13, 3) + 1) AS TEXT) + CAST((LEAST(CAST((EXTRACT(WEEK FROM %2) - 1) AS BIGINT) / 13, 3) + 1) AS TEXT) TO_CHAR(%2, 'IW') TO_CHAR(%2, 'ID') @@ -1081,13 +1091,18 @@ - CAST(FLOOR((7 + EXTRACT(DOY FROM %2) - 1 + (CAST(7 + EXTRACT(DOW - FROM DATE_TRUNC('YEAR', %2)) - %3 AS BIGINT) % 7) ) / 7) AS TEXT) + CAST(FLOOR((7 + EXTRACT(DOY FROM %2) - 1 + (CAST(7 + EXTRACT(DOW FROM DATE_TRUNC('YEAR', + %2)) - %3 AS BIGINT) % 7) ) / 7) AS TEXT) + + EXTRACT(%1 FROM %2)::STRING + + + TO_TIMESTAMP(%2, %1) @@ -1096,12 +1111,10 @@ CAST(TRUNC(EXTRACT(%1 FROM %2)) AS INTEGER) (1 + CAST(EXTRACT(DOW FROM %2) AS INTEGER)) - CAST(FLOOR((7 + EXTRACT(DOY FROM %2) - 1 + EXTRACT(DOW FROM - DATE_TRUNC('YEAR', %2))) / 7) AS INTEGER) - - (LEAST(CAST((EXTRACT(WEEK FROM %2) - 1) AS BIGINT) / 13, 3) - + 1) + CAST(FLOOR((7 + EXTRACT(DOY FROM %2) - 1 + EXTRACT(DOW FROM DATE_TRUNC('YEAR', + %2))) / 7) AS INTEGER) + (LEAST(CAST((EXTRACT(WEEK FROM %2) - 1) AS BIGINT) / 13, 3) + 1) CAST(TRUNC(EXTRACT(WEEK FROM %2)) AS INTEGER) CAST(TRUNC(EXTRACT(ISODOW FROM %2)) AS INTEGER) CAST(TRUNC(EXTRACT(ISOYEAR FROM %2)) AS INTEGER) @@ -1109,39 +1122,42 @@ - CAST(FLOOR((7 + EXTRACT(DOY FROM %2) - 1 + (CAST(7 + EXTRACT(DOW - FROM DATE_TRUNC('YEAR', %2)) - %3 AS BIGINT) % 7)) / 7) AS INTEGER) + CAST(FLOOR((7 + EXTRACT(DOY FROM %2) - 1 + (CAST(7 + EXTRACT(DOW FROM DATE_TRUNC('YEAR', + %2)) - %3 AS BIGINT) % 7)) / 7) AS INTEGER) - - DATE_TRUNC( '%1', CAST(%2 AS TIMESTAMP) ) - CAST(DATE_TRUNC('QUARTER', CAST(%2 AS DATE)) AS - DATE) - - CAST((DATE_TRUNC( 'DAY', CAST(%2 AS DATE) ) + - (-EXTRACT(DOW FROM %2) * INTERVAL '1 DAY')) AS DATE) - - TO_DATE(TO_CHAR(%2, 'IYYY-') || - (LEAST(CAST((EXTRACT(WEEK FROM %2) - 1) AS BIGINT) / 13, 3) * 13 + 1), 'IYYY-IW') - - DATE_TRUNC('WEEK', CAST(%2 AS TIMESTAMP)) - DATE_TRUNC( 'DAY', CAST(%2 AS TIMESTAMP) ) - - TO_DATE(TO_CHAR(%2, 'IYYY-01'), - 'IYYY-IW') + + + EXTRACT(%1 FROM (%2::TIMESTAMP)) :: BIGINT - + - (CAST(DATE_TRUNC( 'DAY', CAST(%2 AS TIMESTAMP)) AS DATE) - - (((7 + CAST(EXTRACT(DOW FROM %2) AS BIGINT) - %3) % 7) * INTERVAL '1 DAY')) - + DATE_TRUNC('%1', %2)::TIMESTAMP + DATE_FORMAT('%j', %2) :: TIMESTAMP + + + + + DATE_TRUNC('%1', %2)::TIMESTAMP + DATE_FORMAT('%j', %2) :: TIMESTAMP + + + + + DATE_TRUNC('%1', %2)::TIMESTAMP + DATE_FORMAT('%j', %2) :: TIMESTAMP + + + DATE_TRUNC('%1', %2)::TIMESTAMP + + @@ -1200,55 +1216,29 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + @@ -1365,8 +1355,7 @@ - + @@ -1378,10 +1367,8 @@ - - + + - + \ No newline at end of file