Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rjs95-008Uel-PR for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 02:45:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rjs92-004bns-Dm for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 02:45:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rjs91-004bnk-Nt for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2024 02:45:36 +0000 Received: from mail-ua1-x92e.google.com ([2607:f8b0:4864:20::92e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rjs8y-00438W-G2 for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2024 02:45:35 +0000 Received: by mail-ua1-x92e.google.com with SMTP id a1e0cc1a2514c-7db44846716so2022398241.2 for ; Mon, 11 Mar 2024 19:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710211532; x=1710816332; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=NnLLrXc01bVPA4U4tYNrCy3jymRolhRyUAGpe1FsqyM=; b=YWtzbdvx55l6w5pMHE2/v84rZpltEQoGHK4Obo82KEEKCe0RtMOFxP4PcJVlvdtvXg B2BwgxfPlbN9+kT9nC4vF09KKi1nmoLpMu0gFdJZVIl87G24Wu8aWgsbLvKseLYxFeD8 LEj4JqS+3y7IsPvXa3KAtsHeLbHxZwRZdWwaWfQNbVMUVM9FjKsQJXQdqjrpFp8rb71V +w89HllgWrzjk4gs9crA9dRSDu4bS4gJDdm6TieChsMjcH3JFxF5NhWQeRFMEtuYc3OF G4c583cllGwv4+MvLJZuLQkakLdahFml35c0sINJZJFdI7iHcnrxFhh3aM1uLBmXgyN3 Y3Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710211532; x=1710816332; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NnLLrXc01bVPA4U4tYNrCy3jymRolhRyUAGpe1FsqyM=; b=fEqp4ERCtq4d7Tc2s2TsVgMSp0R8T4PO/d8NlwMIOsUJzIoF6TFBuRUESIdqRbRI4F t5RffZkB0zwyfRXOW1mRkVXrf7wHo5hD3zM3wzBxhlX97DTItg3+hct/osZVsP7Xw56T 1Bn9g9g/GVQLs7ZI5J0WprZ0mm7Ze6aENqy+EnOYPrmOr7duidB9a2lgQiNzjuE0as/M MqqRAWB6Xkb8SuC69ofOUZdgRmNT3vZ0yNdBVv9gTKm4hG7QqBPKO+PJa8MlmEh5HdlY gvn04eMXVfDP3qfYV4HTrGSnG+w2f8lbtQKpyeCNQ+io9YLz3y1FkpfNCBN5z83m+Qf6 7ARg== X-Forwarded-Encrypted: i=1; AJvYcCXyq5PEYT3MQQjQlAHVohrTHUkwhQ70iA5jPwt2xM/drUy/cAF2DNZgI8dJACid6v7ekcrNEAxv1HkB55gX8awido8Ozna3fsrsVU7FwS9oxo35 X-Gm-Message-State: AOJu0YzptwWmc32v0ehI4S130ryWaUjGTJsDaKQtv88HnxUKVNNYO6Sh kkdWS8VAIJ18xBfS09lcF9qHa6+vFEWo/NayfQYnwmpcnDDIbtglryJ8rK3fD8/GcEZMUKZ32UJ 7HUU4DH08UyooqkpF2iNrY1wXa6rGlnu8u22K6Q== X-Google-Smtp-Source: AGHT+IG0eR4dcCX2eKJzWuZv0mvIA3Za4PHMJ9IwGKf7kk01hw073P8j59oqfPmllgbVYvupXFQtXV5Y7FvJ/q69o7I= X-Received: by 2002:a67:f1ce:0:b0:473:1d10:13e with SMTP id v14-20020a67f1ce000000b004731d10013emr444439vsm.9.1710211532462; Mon, 11 Mar 2024 19:45:32 -0700 (PDT) MIME-Version: 1.0 References: <596fefdd-6202-4228-b7c6-f240b1cbe06e@eisentraut.org> <35400587-6865-4a2c-9ea4-4761669478ea@eisentraut.org> <71b45adb-b496-4e58-b134-0a091014e63f@illuminatedcomputing.com> <7be8724a-5c25-46d7-8325-1bd8be6fa523@eisentraut.org> <0af6a323-f026-4cd9-adf1-941038cd00de@illuminatedcomputing.com> <88518c81-dcdc-4c5b-9200-146b74a520ab@eisentraut.org> <113f5e25-4455-4bdb-98ec-56275705cc4e@illuminatedcomputing.com> <7bd1c8f9-a91a-41a3-990e-0f796ba692ec@eisentraut.org> <6c3edb2c-bc45-4f19-babd-8f4edf39b384@illuminatedcomputing.com> <41b57948-f4d3-455f-8880-e0ce7e61ffc1@illuminatedcomputing.com> <0d977c63-f4a6-43ba-aad0-35c06c55df11@eisentraut.org> In-Reply-To: <0d977c63-f4a6-43ba-aad0-35c06c55df11@eisentraut.org> From: jian he Date: Tue, 12 Mar 2024 10:45:21 +0800 Message-ID: Subject: Re: SQL:2011 application time To: Peter Eisentraut Cc: Paul Jungwirth , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk + + If the last column is marked with PERIOD, + it is treated in a special way. + While the non-PERIOD columns are treated normally + (and there must be at least one of them), + the PERIOD column is not compared for equality. + Instead the constraint is considered satisfied + if the referenced table has matching records + (based on the non-PERIOD parts of the key) + whose combined PERIOD values completely cover + the referencing record's. + In other words, the reference must have a referent for its entire duration. + Normally this column would be a range or multirange type, + although any type whose GiST opclass has a "contained by" operator + and a referenced_agg support function is allowed. + (See .) + In addition the referenced table must have a primary key + or unique constraint declared with WITHOUT PORTION. + typo "referenced_agg", in the gist-extensibility.html page is "referencedagg" WITHOUT PORTION should be WITHOUT OVERLAPS + While the non-PERIOD columns are treated normally + (and there must be at least one of them), + the PERIOD column is not compared for equality. the above sentence didn't say what is "normally"? maybe we can do the following: + While the non-PERIOD columns are treated + normally for equality + (and there must be at least one of them), + the PERIOD column is not compared for equality. + +Datum +my_range_agg_transfn(PG_FUNCTION_ARGS) +{ + MemoryContext aggContext; + Oid rngtypoid; + ArrayBuildState *state; + + if (!AggCheckCallContext(fcinfo, &aggContext)) + elog(ERROR, "range_agg_transfn called in non-aggregate context"); + + rngtypoid = get_fn_expr_argtype(fcinfo->flinfo, 1); + if (!type_is_range(rngtypoid)) + elog(ERROR, "range_agg must be called with a range"); + + if (PG_ARGISNULL(0)) + state = initArrayResult(rngtypoid, aggContext, false); + else + state = (ArrayBuildState *) PG_GETARG_POINTER(0); + + /* skip NULLs */ + if (!PG_ARGISNULL(1)) + accumArrayResult(state, PG_GETARG_DATUM(1), false, rngtypoid, aggContext); + + PG_RETURN_POINTER(state); +} + +Datum +my_range_agg_finalfn(PG_FUNCTION_ARGS) +{ + MemoryContext aggContext; + Oid mltrngtypoid; + TypeCacheEntry *typcache; + ArrayBuildState *state; + int32 range_count; + RangeType **ranges; + int i; + + if (!AggCheckCallContext(fcinfo, &aggContext)) + elog(ERROR, "range_agg_finalfn called in non-aggregate context"); + + state = PG_ARGISNULL(0) ? NULL : (ArrayBuildState *) PG_GETARG_POINTER(0); + if (state == NULL) + /* This shouldn't be possible, but just in case.... */ + PG_RETURN_NULL(); + + /* Also return NULL if we had zero inputs, like other aggregates */ + range_count = state->nelems; + if (range_count == 0) + PG_RETURN_NULL(); + + mltrngtypoid = get_fn_expr_rettype(fcinfo->flinfo); + typcache = multirange_get_typcache(fcinfo, mltrngtypoid); + + ranges = palloc0(range_count * sizeof(RangeType *)); + for (i = 0; i < range_count; i++) + ranges[i] = DatumGetRangeTypeP(state->dvalues[i]); + + PG_RETURN_MULTIRANGE_P(make_multirange(mltrngtypoid, typcache->rngtype, range_count, ranges)); +} my_range_agg_transfn error message is inconsistent? `elog(ERROR, "range_agg_transfn called in non-aggregate context");` `elog(ERROR, "range_agg must be called with a range");` maybe just `my_range_agg_transfn`, instead of mention {range_agg_transfn|range_agg} similarly my_range_agg_finalfn error is also inconsistent. my_range_agg_finalfn need `type_is_multirange(mltrngtypoid)`?