C# 无法使用C NHibernate运行TimescaleDB drop_chunks查询
这可能是一个初学者的问题 因此,我需要以编程方式从PostgreSQL中清除已经确定的时间间隔中的旧数据,例如超过3个月的传感器数据。我已经成功地使用pgAdmin在PostgreSQL中运行了查询,但是通过NHibernate IQuery.ExecuteUpdate命令以编程方式运行,它会给我错误消息C# 无法使用C NHibernate运行TimescaleDB drop_chunks查询,c#,nhibernate,timescaledb,C#,Nhibernate,Timescaledb,这可能是一个初学者的问题 因此,我需要以编程方式从PostgreSQL中清除已经确定的时间间隔中的旧数据,例如超过3个月的传感器数据。我已经成功地使用pgAdmin在PostgreSQL中运行了查询,但是通过NHibernate IQuery.ExecuteUpdate命令以编程方式运行,它会给我错误消息 {"could not execute native bulk manipulation query:SELECT drop_chunks('2020-05-15 17:59:30.636':
{"could not execute native bulk manipulation query:SELECT drop_chunks('2020-05-15 17:59:30.636'::timestamp, 'attribute_value', 'hm_attr');[SQL: SQL not available]"}
以下是完整的堆栈跟踪:
at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)
at NHibernate.Impl.StatelessSessionImpl.ExecuteNativeUpdate(NativeSQLQuerySpecification nativeSQLQuerySpecification, QueryParameters queryParameters)
at NHibernate.Impl.SqlQueryImpl.ExecuteUpdate()
at Platform.Server.Kernel.Persistence.clExecuteQuery.ExecuteSqlCommand(clQueryItem QueryItem, IStatelessSession Session) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\Query\clExecuteQuery.cs:line 184
at Platform.Server.Kernel.Persistence.PersistenceManager.ExecuteSQL(String SqlCommand, Object[] ParametersValues) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\PersistenceManager.cs:line 362
at NHibernate.Impl.AbstractQueryImpl.VerifyParameters(Boolean reserveFirstParameter)
at NHibernate.Impl.SqlQueryImpl.VerifyParameters()
at NHibernate.Impl.SqlQueryImpl.List()
at Platform.Server.Kernel.Persistence.clExecuteQuery.ExecuteQueryInternal(Object[] Parameters, IQuery Query) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\Query\clExecuteQuery.cs:line 476
at Platform.Server.Kernel.Persistence.clExecuteQuery.ExecuteQuery(clQueryItem QueryItem, IStatelessSession Session) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\Query\clExecuteQuery.cs:line 247
at Platform.Server.Kernel.Persistence.PersistenceManager.SelectSQL(String SQL_Expression, Object[] ParametersValues) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\PersistenceManager.cs:line 674
at Platform.Server.Kernel.Persistence.PersistenceManager.PurgeTimescaleExpiredChunks(Type EntityType, DateTime PurgeItemsOlderThanThisDate) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\PersistenceManager.cs:line 1098
at Platform.Server.SystemBase.TemporalData.AttributeValueHandler.PurgeExpiredItems(String ExpiringProperty, DateTime PurgeItemsOlderThanThisDate) in C:\git\smartmine\Server\Platform\SystemBase\TemporalDataManager\AttributeValue\AttributeValueHandler.cs:line 615
at Platform.Server.SystemBase.Data.clDataManager.ExecutePurge(DateTime PurgeStart) in C:\git\smartmine\Server\Platform\SystemBase\DataManager\clDataManager.cs:line 976
例外情况是:
The given key was not present in the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at NHibernate.Param.NamedParameterSpecification.SetEffectiveType(QueryParameters queryParameters)
at NHibernate.Param.ParametersBackTrackExtensions.ResetEffectiveExpectedType(IEnumerable`1 parameterSpecs, QueryParameters queryParameters)
at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)
我尝试过的另一种方法是使用返回
Not all named parameters have been set: [':timestamp'] [SELECT drop_chunks('2020-05-15 18:13:08.841'::timestamp, 'attribute_value', 'hm_attr');]
使用以下堆栈跟踪:
at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)
at NHibernate.Impl.StatelessSessionImpl.ExecuteNativeUpdate(NativeSQLQuerySpecification nativeSQLQuerySpecification, QueryParameters queryParameters)
at NHibernate.Impl.SqlQueryImpl.ExecuteUpdate()
at Platform.Server.Kernel.Persistence.clExecuteQuery.ExecuteSqlCommand(clQueryItem QueryItem, IStatelessSession Session) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\Query\clExecuteQuery.cs:line 184
at Platform.Server.Kernel.Persistence.PersistenceManager.ExecuteSQL(String SqlCommand, Object[] ParametersValues) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\PersistenceManager.cs:line 362
at NHibernate.Impl.AbstractQueryImpl.VerifyParameters(Boolean reserveFirstParameter)
at NHibernate.Impl.SqlQueryImpl.VerifyParameters()
at NHibernate.Impl.SqlQueryImpl.List()
at Platform.Server.Kernel.Persistence.clExecuteQuery.ExecuteQueryInternal(Object[] Parameters, IQuery Query) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\Query\clExecuteQuery.cs:line 476
at Platform.Server.Kernel.Persistence.clExecuteQuery.ExecuteQuery(clQueryItem QueryItem, IStatelessSession Session) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\Query\clExecuteQuery.cs:line 247
at Platform.Server.Kernel.Persistence.PersistenceManager.SelectSQL(String SQL_Expression, Object[] ParametersValues) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\PersistenceManager.cs:line 674
at Platform.Server.Kernel.Persistence.PersistenceManager.PurgeTimescaleExpiredChunks(Type EntityType, DateTime PurgeItemsOlderThanThisDate) in C:\git\smartmine\Server\Platform\Kernel\PersistenceManager\PersistenceManager.cs:line 1098
at Platform.Server.SystemBase.TemporalData.AttributeValueHandler.PurgeExpiredItems(String ExpiringProperty, DateTime PurgeItemsOlderThanThisDate) in C:\git\smartmine\Server\Platform\SystemBase\TemporalDataManager\AttributeValue\AttributeValueHandler.cs:line 615
at Platform.Server.SystemBase.Data.clDataManager.ExecutePurge(DateTime PurgeStart) in C:\git\smartmine\Server\Platform\SystemBase\DataManager\clDataManager.cs:line 976
TimescaleDB API版本:0.9.2文档说,这显然不包括从NHibernate运行东西。我很难找到关于这个查询API的NHibernate文档,因为我所找到的都是类似于这里的SELECT*标准可用性
同样,这可能是一个初学者的问题,如果我误解了什么,请原谅。非常感谢您的帮助,提前谢谢 结果是,我预料到了这个过程中的日期时间转换问题。基本上,我遇到了TimescaleDB错误
Cannot call drop_chunks with a date on hypertables with a time type of: timestamp without time zone
因为,正如错误所述,我的基本hypertable的日期类型实际上是
timestamp without timezone
不知怎的,正因为如此,在我把日期定为
'2020-05-15 17:59:30.636'::timestamp
我已经预料到了日期转换的错误,并通过添加.ToString调用和其他过度工程化的过程弄乱了格式
通过简单地将原始日期作为参数传递就解决了这个问题,所以代码看起来很简单
SELECT drop_chunks(:p0, :p1, :p2)
其中:p0是一个DateTime变量,:p1是表名,:p2是模式名,当然区分大小写 结果是,我预料到了这个过程中的日期时间转换问题。基本上,我遇到了TimescaleDB错误
Cannot call drop_chunks with a date on hypertables with a time type of: timestamp without time zone
因为,正如错误所述,我的基本hypertable的日期类型实际上是
timestamp without timezone
不知怎的,正因为如此,在我把日期定为
'2020-05-15 17:59:30.636'::timestamp
我已经预料到了日期转换的错误,并通过添加.ToString调用和其他过度工程化的过程弄乱了格式
通过简单地将原始日期作为参数传递就解决了这个问题,所以代码看起来很简单
SELECT drop_chunks(:p0, :p1, :p2)
其中:p0是一个DateTime变量,:p1是表名,:p2是模式名,当然区分大小写