Permalink
Browse files

Feature CORE-5620 - Builtin functions FIRST_DAY and LAST_DAY.

  • Loading branch information...
asfernandes committed Nov 1, 2017
1 parent 2dc7249 commit a2556be6418ddab226afe4a745be413ed440f5b8
@@ -265,7 +265,7 @@ CEIL | CEILING
--------------
Function:
Returns a value representing the smallest integer that is greater
Returns a value representing the smallest integer that is greater
than or equal to the input argument.
Format:
@@ -429,12 +429,32 @@ Example:
select exp(x) from y;
---------
FIRST_DAY
---------
Function:
Returns the first day of the year/month/week of a given date/timestamp value.
Format:
FIRST_DAY( OF { YEAR | MONTH | WEEK } FROM <date_or_timestamp> )
Notes:
1) The first day of the week is considered as Sunday, per the same rules of EXTRACT with WEEKDAY.
2) When a timestamp is passed the return value preserves the time part.
Example:
select first_day(of month from current_date) from rdb$database;
select first_day(of year from current_timestamp) from rdb$database;
select first_day(of week from date '2017-11-01') from rdb$database;
-----
FLOOR
-----
Function:
Returns a value representing the largest integer that is less
Returns a value representing the largest integer that is less
than or equal to the input argument.
Format:
@@ -490,6 +510,26 @@ Example:
select hash(x using sha256) from y;
--------
LAST_DAY
--------
Function:
Returns the last day of the year/month/week of a given date/timestamp value.
Format:
LAST_DAY( OF { YEAR | MONTH | WEEK } FROM <date_or_timestamp> )
Notes:
1) The last day of the week is considered as Saturday, per the same rules of EXTRACT with WEEKDAY.
2) When a timestamp is passed the return value preserves the time part.
Example:
select last_day(of month from current_date) from rdb$database;
select last_day(of year from current_timestamp) from rdb$database;
select last_day(of week from date '2017-11-01') from rdb$database;
----
LEFT
----
@@ -802,7 +842,7 @@ SIGN
----
Function:
Returns 1, 0, or -1 depending on whether the input value is positive, zero or
Returns 1, 0, or -1 depending on whether the input value is positive, zero or
negative, respectively.
Format:
@@ -1722,6 +1722,10 @@ C --
PARAMETER (GDS__decfloat_trap = 335545154)
INTEGER*4 GDS__decfloat_round
PARAMETER (GDS__decfloat_round = 335545155)
INTEGER*4 GDS__sysf_invalid_first_last_part
PARAMETER (GDS__sysf_invalid_first_last_part = 335545156)
INTEGER*4 GDS__sysf_invalid_date_timestamp
PARAMETER (GDS__sysf_invalid_date_timestamp = 335545157)
INTEGER*4 GDS__gfix_db_name
PARAMETER (GDS__gfix_db_name = 335740929)
INTEGER*4 GDS__gfix_invalid_sw
@@ -1717,6 +1717,10 @@
gds_decfloat_trap = 335545154;
isc_decfloat_round = 335545155;
gds_decfloat_round = 335545155;
isc_sysf_invalid_first_last_part = 335545156;
gds_sysf_invalid_first_last_part = 335545156;
isc_sysf_invalid_date_timestamp = 335545157;
gds_sysf_invalid_date_timestamp = 335545157;
isc_gfix_db_name = 335740929;
gds_gfix_db_name = 335740929;
isc_gfix_invalid_sw = 335740930;
View
@@ -599,9 +599,11 @@ using namespace Firebird;
%token <metaNamePtr> DECFLOAT
%token <metaNamePtr> DEFINER
%token <metaNamePtr> EXCLUDE
%token <metaNamePtr> FIRST_DAY
%token <metaNamePtr> FOLLOWING
%token <metaNamePtr> IDLE
%token <metaNamePtr> INVOKER
%token <metaNamePtr> LAST_DAY
%token <metaNamePtr> MESSAGE
%token <metaNamePtr> NATIVE
%token <metaNamePtr> NORMALIZE_DECFLOAT
@@ -7778,6 +7780,12 @@ system_function_special_syntax
newNode<ValueListNode>(MAKE_const_slong($3))->add($5)->add($7));
$$->dsqlSpecialSyntax = true;
}
| FIRST_DAY '(' of_first_last_day_part FROM value ')'
{
$$ = newNode<SysFuncCallNode>(*$1,
newNode<ValueListNode>(MAKE_const_slong($3))->add($5));
$$->dsqlSpecialSyntax = true;
}
| HASH '(' value ')'
{ $$ = newNode<SysFuncCallNode>(*$1, newNode<ValueListNode>($3)); }
| HASH '(' value USING valid_symbol_name ')'
@@ -7786,6 +7794,12 @@ system_function_special_syntax
newNode<ValueListNode>($3)->add(MAKE_str_constant(newIntlString($5->c_str()), CS_ASCII)));
$$->dsqlSpecialSyntax = true;
}
| LAST_DAY '(' of_first_last_day_part FROM value ')'
{
$$ = newNode<SysFuncCallNode>(*$1,
newNode<ValueListNode>(MAKE_const_slong($3))->add($5));
$$->dsqlSpecialSyntax = true;
}
| OVERLAY '(' value PLACING value FROM value FOR value ')'
{
$$ = newNode<SysFuncCallNode>(*$1,
@@ -7812,6 +7826,13 @@ system_function_special_syntax
}
;
%type <blrOp> of_first_last_day_part
of_first_last_day_part
: OF YEAR { $$ = blr_extract_year; }
| OF MONTH { $$ = blr_extract_month; }
| OF WEEK { $$ = blr_extract_week; }
;
%type <valueExprNode> string_value_function
string_value_function
: substring_function
@@ -8462,9 +8483,11 @@ non_reserved_word
| DECFLOAT
| DEFINER
| EXCLUDE
| FIRST_DAY
| FOLLOWING
| IDLE
| INVOKER
| LAST_DAY
| MESSAGE
| NATIVE
| NORMALIZE_DECFLOAT
@@ -857,6 +857,8 @@ static const struct {
{"expression_eval_index", 335545153},
{"decfloat_trap", 335545154},
{"decfloat_round", 335545155},
{"sysf_invalid_first_last_part", 335545156},
{"sysf_invalid_date_timestamp", 335545157},
{"gfix_db_name", 335740929},
{"gfix_invalid_sw", 335740930},
{"gfix_incmp_sw", 335740932},
@@ -891,6 +891,8 @@ const ISC_STATUS isc_sysf_invalid_hash_algorithm = 335545152L;
const ISC_STATUS isc_expression_eval_index = 335545153L;
const ISC_STATUS isc_decfloat_trap = 335545154L;
const ISC_STATUS isc_decfloat_round = 335545155L;
const ISC_STATUS isc_sysf_invalid_first_last_part = 335545156L;
const ISC_STATUS isc_sysf_invalid_date_timestamp = 335545157L;
const ISC_STATUS isc_gfix_db_name = 335740929L;
const ISC_STATUS isc_gfix_invalid_sw = 335740930L;
const ISC_STATUS isc_gfix_incmp_sw = 335740932L;
@@ -1365,7 +1367,7 @@ const ISC_STATUS isc_trace_switch_user_only = 337182757L;
const ISC_STATUS isc_trace_switch_param_miss = 337182758L;
const ISC_STATUS isc_trace_param_act_notcompat = 337182759L;
const ISC_STATUS isc_trace_mandatory_switch_miss = 337182760L;
const ISC_STATUS isc_err_max = 1309;
const ISC_STATUS isc_err_max = 1311;
#else /* c definitions */
@@ -2226,6 +2228,8 @@ const ISC_STATUS isc_err_max = 1309;
#define isc_expression_eval_index 335545153L
#define isc_decfloat_trap 335545154L
#define isc_decfloat_round 335545155L
#define isc_sysf_invalid_first_last_part 335545156L
#define isc_sysf_invalid_date_timestamp 335545157L
#define isc_gfix_db_name 335740929L
#define isc_gfix_invalid_sw 335740930L
#define isc_gfix_incmp_sw 335740932L
@@ -2700,7 +2704,7 @@ const ISC_STATUS isc_err_max = 1309;
#define isc_trace_switch_param_miss 337182758L
#define isc_trace_param_act_notcompat 337182759L
#define isc_trace_mandatory_switch_miss 337182760L
#define isc_err_max 1309
#define isc_err_max 1311
#endif
View
@@ -860,6 +860,8 @@ Data source : @4"}, /* eds_statement */
{335545153, "Expression evaluation error for index \"@1\" on table \"@2\""}, /* expression_eval_index */
{335545154, "Invalid decfloat trap state @1"}, /* decfloat_trap */
{335545155, "Invalid decfloat rounding mode @1"}, /* decfloat_round */
{335545156, "Invalid part @1 to calculate the @1 of a DATE/TIMESTAMP"}, /* sysf_invalid_first_last_part */
{335545157, "Expected DATE/TIMESTAMP value in @1"}, /* sysf_invalid_date_timestamp */
{335740929, "data base file name (@1) already given"}, /* gfix_db_name */
{335740930, "invalid switch @1"}, /* gfix_invalid_sw */
{335740932, "incompatible switch combination"}, /* gfix_incmp_sw */
@@ -856,6 +856,8 @@ static const struct {
{335545153, -901}, /* 833 expression_eval_index */
{335545154, -901}, /* 834 decfloat_trap */
{335545155, -901}, /* 835 decfloat_round */
{335545156, -833}, /* 836 sysf_invalid_first_last_part */
{335545157, -833}, /* 837 sysf_invalid_date_timestamp */
{335740929, -901}, /* 1 gfix_db_name */
{335740930, -901}, /* 2 gfix_invalid_sw */
{335740932, -901}, /* 4 gfix_incmp_sw */
@@ -856,6 +856,8 @@ static const struct {
{335545153, "42000"}, // 833 expression_eval_index
{335545154, "42000"}, // 834 decfloat_trap
{335545155, "42000"}, // 835 decfloat_round
{335545156, "42000"}, // 836 sysf_invalid_first_last_part
{335545157, "42000"}, // 837 sysf_invalid_date_timestamp
{335740929, "00000"}, // 1 gfix_db_name
{335740930, "00000"}, // 2 gfix_invalid_sw
{335740932, "00000"}, // 4 gfix_incmp_sw
Oops, something went wrong.

0 comments on commit a2556be

Please sign in to comment.