- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章postgresql数据库使用说明_实现时间范围查询由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
按照日期查询通常有好几种方法:
按照日期范围查询有好几种方法,日期字段类型一般为:
1
|
Timestamp
without timezone
|
方法一:
1
2
|
select
*
from
user_info
where
create_date
>=
'2015-07-01'
and
create_date <
'2015-08-15'
;
|
方法二:
1
2
|
select
*
from
user_info
where
create_date
between
'2015-07-01'
and
'2015-08-15'
;
|
方法三:
1
2
|
select
*
from
user_info
where
create_date
>=
'2015-07-01'
::
timestamp
and
create_date <
'2015-08-15'
::
timestamp
;
|
方法四:
1
2
|
select
*
from
user_info
where
create_date
between
to_date(
'2015-07-01'
,
'YYYY-MM-DD'
)
and
to_date(
'2015-08-15'
,
'YYYY-MM-DD'
);
|
pandas.to_sql 遇到主键重复的,怎么能够跳过继续执行呢,其实很简单,就一条一条的插入就可以了,因为to_sql还没有很好的解决办法.
具体的代码如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
for
exchange
in
exchange_list.items():
if exchange[1]==
True
:
pass
else
:
continue
sql =
""
" SELECT * FROM %s WHERE "
time
" BETWEEN '2019-07-05 18:48' AND '2019-07-09' "
""
% (exchange[0])
data = pd.read_sql(sql=sql, con=conn)
print(data.head())
for
i
in
range(len(data)):
#sql =
"SELECT * FROM `%s` WHERE `key` = '{}'"
%(exchange).format(row.
Key
)
#found = pd.read_sql(sql, con=conn2)
#if len(found) == 0:
try:
data.iloc[i:i + 1].to_sql(
name
=exchange[0],
index
=
False
,if_exists=
'append'
, con=conn2)
except
Exception
as
e:
print(e)
pass
|
pandas.to_sql 无法设置主键,这个是肯定的,能做的办法就是在to_sql之前先使用创建表的方法,创建一张表 。
建表的代码如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/*
Create
SEQUENCE
for
table
*/
DROP
SEQUENCE
IF EXISTS @exchangeName_id_seq;
CREATE
SEQUENCE
@exchangeName_id_seq
START
WITH
1
INCREMENT
BY
1
NO
MINVALUE
NO
MAXVALUE
CACHE 1;
/*
Create
Table
structure
for
table
*/
DROP
TABLE
IF EXISTS
"public"
.
"@exchangeName"
;
CREATE
TABLE
"public"
.
"@exchangeName"
(
"id"
int4
NOT
NULL
DEFAULT
nextval(
'@exchangeName_id_seq'
::regclass),
"time"
timestamp
(6)
NOT
NULL
,
"open"
float8,
"high"
float8,
"low"
float8,
"close"
float8,
"volume"
float8,
"info"
varchar
COLLATE
"pg_catalog"
.
"default"
NOT
NULL
)
;
/*
Create
Primary
Key
structure
for
table
*/
ALTER
TABLE
"public"
.
"@exchangeName"
DROP
CONSTRAINT
IF EXISTS
"@exchangeName_pkey"
;
ALTER
TABLE
"public"
.
"@exchangeName"
ADD
CONSTRAINT
"@exchangeName_pkey"
PRIMARY
KEY
(
"time"
,
"info"
);
|
补充:postgresql 数据库时间间隔数据查询 。
当前时间向前推一天:
1
|
SELECT
current_timestamp
- interval
'1 day'
|
当前时间向前推一个月:
1
|
SELECT
current_timestamp
- interval
'1 month'
|
当前时间向前推一年:
1
|
SELECT
current_timestamp
- interval
'1 year'
|
当前时间向前推一小时:
1
|
SELECT
current_timestamp
- interval
'1 hour'
|
当前时间向前推一分钟:
1
|
SELECT
current_timestamp
- interval
'1 min'
|
当前时间向前推60秒:
1
|
SELECT
current_timestamp
- interval
'60 second'
|
以上为个人经验,希望能给大家一个参考,也希望大家多多支持我。如有错误或未考虑完全的地方,望不吝赐教.
原文链接:https://blog.csdn.net/m0_37876745/article/details/95496642 。
最后此篇关于postgresql数据库使用说明_实现时间范围查询的文章就讲到这里了,如果你想了解更多关于postgresql数据库使用说明_实现时间范围查询的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
过去几天我一直试图解决这个问题,但我做不到。我正在尝试生成 _ _ _ 形式的随机数。 _ _ _ _ 小数点前 3 位,然后是 4 位小数。 非常感谢任何帮助。谢谢, 院长 最佳答案 您发布的代码有
我的方法有问题。我需要从主类调用的方法的输出打印我: 需要这个输出:_ _ _ _ _ 我知道我可以将 System 的静态方法放入循环中,但这不是我想要的解决方案。我需要它来打印主类中方法的输出。
我正在学习 Scala,有一个非常基本的问题。考虑以下两个使用占位符语法的表达式 - // Syntax A val fnA = (_: Int, _: Int) => _ / _ // Synta
我正在使用图书馆 URLEmbeddedView 它在其库中定义了以下代码: func addConstraints(with view: UIView, center: CGPoint, multi
我一直在许多受人尊敬的文档中看到这个相当令人尴尬的事情:_|_ 或 (_|_) 找不到它的定义(Google 不能很好地处理符号)。那到底是什么呢? 最佳答案 来自 here :- Bottom Th
,_,( ){ ,_,| ,_,&};,_, 不知道是什么意思... 看起来像一个 bash 命令,但它可能是 s bash shell 指令或其他东西如果有人可以帮助理解这一点,我们将不胜感激。当我
所以我正在尝试构建一个函数,它接受一个元组列表并找到具有最大第二个元素的元组。但是我遇到了模式匹配错误。 这是我的代码。 resultTuple :: [((Int,Int),Int)] ->
我在 try Flow 编辑器中重现了我的情况,可以访问 here . 以下是链接发生问题时的代码: /* @flow */ type PayloadType = 1 | 2 | 3; type Tr
我在plfa读到这样一段代码。 import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong; s
这个问题在这里已经有了答案: Swift 3.0: compiler error when calling global func min(T,T) in Array or Dictionary e
是否有理由使用一个而不是另一个?似乎 _.some 和 _.map 更易于使用或适用于更多情况(根据我非常有限的经验),但从阅读它来看,它们听起来好像应该做同样的事情。我敢肯定还有其他这样的例子,我很
在 Xcode 7 Beta 中开始使用 Swift 2 后,出现错误 cannot invoke。是什么导致了这个问题? 我试图通过以下两个问题找出我的问题,但我仍然收到错误:Question 1
所以我玩了一会儿,试图写一些关于存在和变化的东西,我遇到了这段有趣的代码。 final case class Box[+T](val value: T) { def >>=[U](f: T =>
Here is the screenshot for the error. 遵循本教程 https://developers.google.com/places/ios-api/start 在本教程中
我正在为许多标准的 Underscore.js 函数重写底层代码,以提高我的 JavaScript 技能,但我有点受困于 _.every/ _.全部。似乎在库本身中,_.every/_.all 函数仅
我在 shell 脚本中多次看到他们在 if 比较中使用 "_",如下所示: if [ "_$str" = "_" ]; then ....; fi 上面的代码通过比较 if [ "_$str"= "
我正在尝试快速过滤字典: var data: [String: String] = [:] data = data.filter { $0.1 == "Test" } 上面的过滤器代码在 Swift
我在 Entity Framework 核心映射方面遇到了问题。我收到此异常“不支持从‘付款’到‘购买。付款’的关系,因为拥有的实体类型‘购买’不能位于非所有权关系的主要方面。”在调试此功能的测试时。
我正在尝试模拟groovy.sql.Sql调用(查询,params [],闭包)类。 下面是我正在尝试在DatabaseService类文件中的方法。 public void getUsers(Lis
在阅读 dart 代码时,我经常看到一些仅使用下划线 _ 参数调用的函数。这让我困扰了一段时间,由于 flutter 改进了它的分析消息,我有了一些线索......但我觉得我并没有真正理解这个概念:-
我是一名优秀的程序员,十分优秀!