Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
后面是删除,类似于: CREATE OR REPLACE FUNCTION linearly_decrement_offset(location_in text) RETURNS void AS $BODY$ declare l_insert_ts timestamp; --- a local variable to hold the value BEGIN -- this select assumes that location_in is unique -- (and thus the select returns exactly one row) -- otherwise the select .. into will throw an error select ts_insert into l_insert_ts from tempoffset WHERE location = location_in; IF l_insert_ts <= (now() at time zone 'utc') - '15 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '30 minutes'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor * 0.75 WHERE tempoffset.location = location_in; ELSIF l_insert_ts <= (now() at time zone 'utc') - '30 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '45 minutes'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor* 0.5 WHERE tempoffset.location = location_in; ELSIF l_insert_ts <= (now() at time zone 'utc') - '45 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '1 hour'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor * 0.25 WHERE tempoffset.location = location_in; ELSIF tempoffset.ts_insert < (now() at time zone 'utc') - '1 hour'::interval THEN DELETE FROM tempoffset; END IF; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; $BODY$ BEGIN update tempoffset set offset_factor = offset_factor * when tempoffset.ts_insert >= (now() at time zone 'utc') - '15 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '30 minutes'::interval) then 0.75 when tempoffset.ts_insert >= (now() at time zone 'utc') - '30 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '45 minutes'::interval) then 0.50 when tempoffset.ts_insert >= (now() at time zone 'utc') - '45 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '60 minutes'::interval) then 0.25; delete from tempoffset where tempoffset.ts_insert < (now() at time zone 'utc') - '15 minutes'::interval or tempoffset.ts_insert > (now() at time zone 'utc') - '60 minutes'::interval); END; $BODY$ $BODY$ 开始 更新tempoffset 设置偏移系数=偏移系数* 当tempoffset.ts_insert>=(现在()时区为“utc”)-“15分钟”::间隔 和tempoffset.ts_insert=(现在()时区为“utc”)-“30分钟”::间隔 和tempoffset.ts_insert=(现在()时区为“utc”)-“45分钟”::间隔 和tempoffset.ts_insert_Sql_Postgresql_Plpgsql - Fatal编程技术网

后面是删除,类似于: CREATE OR REPLACE FUNCTION linearly_decrement_offset(location_in text) RETURNS void AS $BODY$ declare l_insert_ts timestamp; --- a local variable to hold the value BEGIN -- this select assumes that location_in is unique -- (and thus the select returns exactly one row) -- otherwise the select .. into will throw an error select ts_insert into l_insert_ts from tempoffset WHERE location = location_in; IF l_insert_ts <= (now() at time zone 'utc') - '15 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '30 minutes'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor * 0.75 WHERE tempoffset.location = location_in; ELSIF l_insert_ts <= (now() at time zone 'utc') - '30 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '45 minutes'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor* 0.5 WHERE tempoffset.location = location_in; ELSIF l_insert_ts <= (now() at time zone 'utc') - '45 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '1 hour'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor * 0.25 WHERE tempoffset.location = location_in; ELSIF tempoffset.ts_insert < (now() at time zone 'utc') - '1 hour'::interval THEN DELETE FROM tempoffset; END IF; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; $BODY$ BEGIN update tempoffset set offset_factor = offset_factor * when tempoffset.ts_insert >= (now() at time zone 'utc') - '15 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '30 minutes'::interval) then 0.75 when tempoffset.ts_insert >= (now() at time zone 'utc') - '30 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '45 minutes'::interval) then 0.50 when tempoffset.ts_insert >= (now() at time zone 'utc') - '45 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '60 minutes'::interval) then 0.25; delete from tempoffset where tempoffset.ts_insert < (now() at time zone 'utc') - '15 minutes'::interval or tempoffset.ts_insert > (now() at time zone 'utc') - '60 minutes'::interval); END; $BODY$ $BODY$ 开始 更新tempoffset 设置偏移系数=偏移系数* 当tempoffset.ts_insert>=(现在()时区为“utc”)-“15分钟”::间隔 和tempoffset.ts_insert=(现在()时区为“utc”)-“30分钟”::间隔 和tempoffset.ts_insert=(现在()时区为“utc”)-“45分钟”::间隔 和tempoffset.ts_insert

后面是删除,类似于: CREATE OR REPLACE FUNCTION linearly_decrement_offset(location_in text) RETURNS void AS $BODY$ declare l_insert_ts timestamp; --- a local variable to hold the value BEGIN -- this select assumes that location_in is unique -- (and thus the select returns exactly one row) -- otherwise the select .. into will throw an error select ts_insert into l_insert_ts from tempoffset WHERE location = location_in; IF l_insert_ts <= (now() at time zone 'utc') - '15 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '30 minutes'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor * 0.75 WHERE tempoffset.location = location_in; ELSIF l_insert_ts <= (now() at time zone 'utc') - '30 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '45 minutes'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor* 0.5 WHERE tempoffset.location = location_in; ELSIF l_insert_ts <= (now() at time zone 'utc') - '45 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '1 hour'::interval THEN UPDATE tempoffset SET offset_factor = offset_factor * 0.25 WHERE tempoffset.location = location_in; ELSIF tempoffset.ts_insert < (now() at time zone 'utc') - '1 hour'::interval THEN DELETE FROM tempoffset; END IF; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; $BODY$ BEGIN update tempoffset set offset_factor = offset_factor * when tempoffset.ts_insert >= (now() at time zone 'utc') - '15 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '30 minutes'::interval) then 0.75 when tempoffset.ts_insert >= (now() at time zone 'utc') - '30 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '45 minutes'::interval) then 0.50 when tempoffset.ts_insert >= (now() at time zone 'utc') - '45 minutes'::interval AND tempoffset.ts_insert < (now() at time zone 'utc') - '60 minutes'::interval) then 0.25; delete from tempoffset where tempoffset.ts_insert < (now() at time zone 'utc') - '15 minutes'::interval or tempoffset.ts_insert > (now() at time zone 'utc') - '60 minutes'::interval); END; $BODY$ $BODY$ 开始 更新tempoffset 设置偏移系数=偏移系数* 当tempoffset.ts_insert>=(现在()时区为“utc”)-“15分钟”::间隔 和tempoffset.ts_insert=(现在()时区为“utc”)-“30分钟”::间隔 和tempoffset.ts_insert=(现在()时区为“utc”)-“45分钟”::间隔 和tempoffset.ts_insert,sql,postgresql,plpgsql,Sql,Postgresql,Plpgsql,对不起,我没有测试它,我以前没有在乘法中使用when/then。但是,这将按适当的系数更新tempoffset表,或者如果时间未括在括号内,则数据将被删除。我觉得这两个字母的括号倒过来了,但是,也许我弄错了 -g请注意,您可能可以使用类似1-width\u bucket(…)*0.25的方法来简化此过程。也不太清楚为什么要将其存储在临时表中而不是动态计算。请显示完整的create function语句。@没有名称的\u horse\u更新了描述您不能在这样的IF语句中使用表的列。那是哪一排的?您

对不起,我没有测试它,我以前没有在乘法中使用when/then。但是,这将按适当的系数更新tempoffset表,或者如果时间未括在括号内,则数据将被删除。我觉得这两个字母的括号倒过来了,但是,也许我弄错了



-g

请注意,您可能可以使用类似
1-width\u bucket(…)*0.25
的方法来简化此过程。也不太清楚为什么要将其存储在临时表中而不是动态计算。请显示完整的
create function
语句。@没有名称的\u horse\u更新了描述您不能在这样的IF语句中使用表的列。那是哪一排的?您需要运行
select
查询以从表中检索数据。虽然这看起来好像你根本不需要if。这可能在一个update语句中完成(除了
delete
)。你到底想用它达到什么目的?@a_horse_,没有名字,我正试图从
tempoffset
表中线性减少
offset\u因子
值。因此,例如,如果现有值比当前查询早15分钟,但小于30分钟,则将
offset\u factor
值减少25%,以此类推。我正在尝试为iOS应用程序实现REST API。请注意,您可能可以使用类似
1-width_bucket(…)*0.25
的方法来简化此过程。也不太清楚为什么要将其存储在临时表中而不是动态计算。请显示完整的
create function
语句。@没有名称的\u horse\u更新了描述您不能在这样的IF语句中使用表的列。那是哪一排的?您需要运行
select
查询以从表中检索数据。虽然这看起来好像你根本不需要if。这可能在一个update语句中完成(除了
delete
)。你到底想用它达到什么目的?@a_horse_,没有名字,我正试图从
tempoffset
表中线性减少
offset\u因子
值。因此,例如,如果现有值比当前查询早15分钟,但小于30分钟,则将
offset\u factor
值减少25%,以此类推。我正在尝试为iOS应用程序实现REST API。请注意,您可能可以使用类似
1-width_bucket(…)*0.25
的方法来简化此过程。也不太清楚为什么要将其存储在临时表中而不是动态计算。请显示完整的
create function
语句。@没有名称的\u horse\u更新了描述您不能在这样的IF语句中使用表的列。那是哪一排的?您需要运行
select
查询以从表中检索数据。虽然这看起来好像你根本不需要if。这可能在一个update语句中完成(除了
delete
)。你到底想用它达到什么目的?@a_horse_,没有名字,我正试图从
tempoffset
表中线性减少
offset\u因子
值。因此,例如,如果现有值比当前查询早15分钟,但小于30分钟,则将
offset\u factor
值减少25%,以此类推。我正在尝试为iOS应用程序实现REST API。请注意,您可能可以使用类似
1-width_bucket(…)*0.25
的方法来简化此过程。也不太清楚为什么要将其存储在临时表中而不是动态计算。请显示完整的
create function
语句。@没有名称的\u horse\u更新了描述您不能在这样的IF语句中使用表的列。那是哪一排的?您需要运行
select
查询以从表中检索数据。虽然这看起来好像你根本不需要if。这可能在一个update语句中完成(除了
delete
)。你到底想用它达到什么目的?@a_horse_,没有名字,我正试图从
tempoffset
表中线性减少
offset\u因子
值。因此,例如,如果现有值比当前查询早15分钟,但小于30分钟,则将
offset\u factor
值减少25%,以此类推。我正在尝试为iOS应用程序实现REST API。介于::和interval之间的空格。我只想验证您是否意识到在您的注释中,在::interval之间没有空格。但是,您提供的代码在15分钟行上有一个空格,其他代码没有。啊,我没有看到,因为您没有将示例格式化为
code
。但是,空间并没有什么不同<代码>'15分钟'::interval'与
'15分钟':interval
一样好:尝试切换错误的第一个。SQL和PL/pgSQL中的“lower or equal”运算符是::和interval之间的空格
CREATE OR REPLACE FUNCTION linearly_decrement_offset(location_in text)
RETURNS void AS
$BODY$
declare
   l_insert_ts timestamp;  --- a local variable to hold the value
BEGIN

   -- this select assumes that location_in is unique 
   -- (and thus the select returns exactly one row)
   -- otherwise the select .. into will throw an error
   select ts_insert
      into l_insert_ts
   from tempoffset
   WHERE location = location_in;

    IF l_insert_ts <= (now() at time zone 'utc') - '15 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '30 minutes'::interval THEN
        UPDATE tempoffset
            SET offset_factor = offset_factor * 0.75
            WHERE tempoffset.location = location_in;
    ELSIF l_insert_ts <= (now() at time zone 'utc') - '30 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '45 minutes'::interval THEN
        UPDATE tempoffset
            SET offset_factor = offset_factor* 0.5
            WHERE tempoffset.location = location_in;
    ELSIF l_insert_ts <= (now() at time zone 'utc') - '45 minutes'::interval AND l_insert_ts > (now() at time zone 'utc') - '1 hour'::interval THEN
        UPDATE tempoffset
            SET offset_factor = offset_factor * 0.25
            WHERE tempoffset.location = location_in;
    ELSIF tempoffset.ts_insert < (now() at time zone 'utc') - '1 hour'::interval THEN
        DELETE FROM tempoffset;
    END IF;

END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
$BODY$
BEGIN

update tempoffset
set offset_factor = offset_factor *
   when tempoffset.ts_insert >= (now() at time zone 'utc') - '15 minutes'::interval
    AND tempoffset.ts_insert < (now() at time zone 'utc') - '30 minutes'::interval) then 0.75
   when tempoffset.ts_insert >= (now() at time zone 'utc') - '30 minutes'::interval
    AND tempoffset.ts_insert < (now() at time zone 'utc') - '45 minutes'::interval) then 0.50
   when tempoffset.ts_insert >= (now() at time zone 'utc') - '45 minutes'::interval
    AND tempoffset.ts_insert < (now() at time zone 'utc') - '60 minutes'::interval) then 0.25;

delete from tempoffset where tempoffset.ts_insert < (now() at time zone 'utc') - '15 minutes'::interval or
            tempoffset.ts_insert > (now() at time zone 'utc') - '60 minutes'::interval);


END;
$BODY$