python中的SQLLite类型转换

2024-04-27 03:51:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python还不熟悉。 我正在将表数据从AWS Redshift移到内存中的sqllite数据库中 Python。你知道吗

请参考下表结构:

红移表:

s0 1

上一列中我的值字段在红移时是十进制的。你知道吗

当我尝试将数据带到sqllite时,我发现从Redshift得到的结果中包含Decimal关键字,因此我无法将其插入到sqllite表中,该表也被标记为Decimal(这里是我前面提出的同一问题的link)。因此,我将数据类型更改为varchar(30),以便我的值可以放入sqllite表中。你知道吗

我的内存sqllite表请参考下面的表结构:

内存sqllite表

enter image description here

现在,我想在python脚本中基于时间戳对列值求和,但无法得到预期的结果。你知道吗

以下是我在Redshift中使用的查询,以获取总和,并获得预期的输出:

select sum(value) from table where id = 9831 and item_date = '2018-11-01' and to_char(item_datetime, 'HH24MI') between '0000' and '2359';

下面是我在脚本中使用的查询,用于将value列强制转换为decimal,并将itemu datetime转换为strftime,以获得所需的输出:

select sum(CAST(value as decimal)) from table where id = 9831 and item_date = '2018-11-01' and strftime(item_datetime, 'HH24MI') between '0000' and '2359';

但是我得到的输出是None。 有人能解释我的行为和我做错了什么吗? 如何处理这个问题?你知道吗


Tags: and数据内存from脚本redshiftdatetimevalue