Skip to content

feat(query): support age function - #18142

Merged
sundy-li merged 2 commits into
databendlabs:mainfrom
TCeason:age
Jun 12, 2025
Merged

feat(query): support age function#18142
sundy-li merged 2 commits into
databendlabs:mainfrom
TCeason:age

Conversation

@TCeason

@TCeason TCeason commented Jun 12, 2025

Copy link
Copy Markdown
Collaborator

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  1. support age function

Syntax

-- Subtract arguments, producing a “symbolic” result that uses years and months, rather than just days
age ( timestamp, timestamp ) → interval
-- Subtract argument from current_date (at midnight)
age ( timestamp ) → interval

e.g.

set timezone='America/New_York';

select age('2025-04-10'::date, '1957-06-13'::date);
----
67 years 9 months 27 days

select age('1957-06-13'::timestamp);
----
67 years 11 months 28 days
  1. fix to_month(IntervalType);

In main:

select to_month(to_interval('12 months'))
----
12

In pr:

select to_month(to_interval('12 months'))
----
0
  1. fix date convert timestamp

In main:

set timezone='America/New_York'

select '1990-05-15'::date::timestamp;
----
1990-05-15 01:00:00.000000

In pr:

set timezone='America/New_York';

select '1990-05-15'::date::timestamp;
----
1990-05-15 00:00:00.000000

Fix:
#18108
#18139
#18138

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@TCeason
TCeason marked this pull request as draft June 12, 2025 02:33
@github-actions github-actions Bot added the pr-feature this PR introduces a new feature to the codebase label Jun 12, 2025
@TCeason
TCeason force-pushed the age branch 2 times, most recently from b8c164d to a869e3b Compare June 12, 2025 03:21
1. support age function

**Syntax**

```sql
-- Subtract arguments, producing a “symbolic” result that uses years and months, rather than just days
-- age(timestamp '2001-04-10', timestamp '1957-06-13') → 43 years 9 months 27 days
age ( timestamp, timestamp ) → interval
-- Subtract argument from current_date (at midnight)
age ( timestamp ) → interval
```

2. fix to_month(IntervalType);

In main:
select to_month(to_interval('12 months'))
----
12

In pr:
select to_month(to_interval('12 months'))
----
0

3. fix date convert timestamp

In main:

set timezone='America/New_York'

select '1990-05-15'::date::timestamp;
----
1990-05-15 01:00:00.000000

In pr:

```sql
set timezone='America/New_York';

select '1990-05-15'::date::timestamp;
----

```

Fix:
databendlabs#18108
databendlabs#18139
databendlabs#18138
@TCeason
TCeason marked this pull request as ready for review June 12, 2025 06:50
@sundy-li
sundy-li merged commit 11b55fa into databendlabs:main Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature this PR introduces a new feature to the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants