ESQL pass a stats column to next stage

I need to find the first and the last inserts of sources in events:

FROM *.events.* | KEEP @timestamp,source 
| stats latest=max(@timestamp) by source

FROM *.events.* | KEEP @timestamp,source
| stats first=min(@timestamp) by source

Now I create two dataframes and merge them based on source

But can a do this in ESQL:

Not working examples:

# ROW can only take constants:
FROM *.events.* | KEEP @timestamp,source 
| ROW latest=max(@timestamp), first=min(@timestamp)

# stats cut off @timestamp
FROM *.events.* | KEEP @timestamp,source 
| stats latest=max(@timestamp) by source 
| stats first=min(@timestamp) by source

Hello Morten,

You can do multiple aggregations with a single STATS:

FROM *.events.*
| KEEP @timestamp,source 
| STATS earliest=min(@timestamp), latest=max(@timestamp) by source 

Is this what you are looking for?

Best regards
Wolfram

Thanks, somehow I tried that variation, but got errors, but cut and pasted your entry and it works, Thanks

first seem to be a protected keyword:

mismatched input 'first' expecting {QUOTED_STRING, INTEGER_LITERAL, DECIMAL_LITERAL, 'false', '(', 'not', 'null', '?', 'true', '+', '-', NAMED_OR_POSITIONAL_PARAM, OPENING_BRACKET, UNQUOTED_IDENTIFIER, QUOTED_IDENTIFIER}")