我想获取具有最大SnapshotCreateTime的快照的SnapshotIdentifier,并通过ClusterIdentifier对其进行过滤。这是我正在使用的命令:
aws redshift describe-cluster-snapshots --region us-west-2 |
jq -r '.Snapshots[]
| select(.ClusterIdentifier == "dev-cluster")
| max_by(.SnapshotCreateTime)
| .SnapshotIdentifier '
Run Code Online (Sandbox Code Playgroud)
这是json
{
"Snapshots": [
{
"EstimatedSecondsToCompletion": 0,
"OwnerAccount": "45645641155",
"CurrentBackupRateInMegaBytesPerSecond": 6.2857,
"ActualIncrementalBackupSizeInMegaBytes": 22.0,
"NumberOfNodes": 3,
"Status": "available",
"VpcId": "myvpc",
"ClusterVersion": "1.0",
"Tags": [],
"MasterUsername": "ayxbizops",
"TotalBackupSizeInMegaBytes": 192959.0,
"DBName": "dev",
"BackupProgressInMegaBytes": 22.0,
"ClusterCreateTime": "2016-09-06T15:56:08.170Z",
"RestorableNodeTypes": [
"dc1.large"
],
"EncryptedWithHSM": false,
"ClusterIdentifier": "dev-cluster",
"SnapshotCreateTime": "2016-09-06T16:00:25.595Z",
"AvailabilityZone": "us-west-2c",
"NodeType": "dc1.large",
"Encrypted": false,
"ElapsedTimeInSeconds": 3,
"SnapshotType": "manual",
"Port": 5439,
"SnapshotIdentifier": "thismorning"
}
]
}
Run Code Online (Sandbox Code Playgroud) 我有一个返回时间戳数组的函数。我想将这些时间戳转换为 yyyy-mm-dd 格式的日期。我想展平返回的数组列,但我得到:
SQL compilation error: Unknown function FLATTEN
Run Code Online (Sandbox Code Playgroud)
当我跑步时:
with cte as (SELECT
array_construct('2021-09-10'::date,'2021-09-11'::date,'2021-09-12'::date) AS array
,'2021-09-11'::date AS max_date
,date_filter
(
'2021-09-12'::date,
array_construct('2021-09-10'::date,'2021-09-11'::date,'2021-09-12'::date)
) as dates )
select flatten(cte.dates) from cte
Run Code Online (Sandbox Code Playgroud)
功能是:
CREATE OR REPLACE FUNCTION date_filter (max_date DATE, date_list ARRAY)
RETURNS ARRAY
LANGUAGE JAVASCRIPT
AS $$
var dates = DATE_LIST;
return dates.filter(date => date < MAX_DATE);
$$
;
Run Code Online (Sandbox Code Playgroud) 我试图根据过去 18 个月内的访问次数将客户与“首选”商家联系起来,决胜局是最近的访问日期。我在决胜局方面遇到了一些麻烦。如果有两条记录根据某个 MemberID 的访问次数均排名第 1,我想将该 MemberID 的记录上的 IsFirst 位列设置为 1。我该怎么做呢?