postgresql

Getting COUNT from sqlalchemy

拟墨画扇 提交于 2020-12-20 08:08:11
问题 I have: res = db.engine.execute('select count(id) from sometable') The returned object is sqlalchemy.engine.result.ResultProxy . How do I get count value from res ? Res is not accessed by index but I have figured this out as: count=None for i in res: count = res[0] break There must be an easier way right? What is it? I didn't discover it yet. Note: The db is a postgres db. 回答1: While the other answers work, SQLAlchemy provides a shortcut for scalar queries as ResultProxy.scalar(): count = db

PostgreSQL

前提是你 提交于 2020-12-20 06:07:23
PostgreSQL连接数据库的两种方式 PostgreSQL在安装时自带了 pgAdmin 和 psql , pgAdmin 是可视化工具, psql 是命令行工具。 虽然pgAdmin操作起来会更加直观简单,但是在restore和backup db的时候,效率和性能会比较低下,如果db过于庞大,还会导致pgAdmin内存溢出。 推荐使用psql来连接数据库进行备份和恢复db,同样大小的db,使用psql来restore会比pgAdmin快上数倍! <!-- more --> psql连接数据库 直接连接到指定的数据库 psql -h <dbserver_IP> -p<dbserver_port> -d <database_Name> -U <db user> 如果host是localhost,可以不指定该参数,当不指定端口号时会使用默认的端口号 5432 ,或者你可以通过 -p 来指定其他端口号。 比如你想连接本地的db: test:5432 ,用户名是 postgres ,可以使用如下的命令: psql -d test -U postgres 如果有密码的话会提示你输入密码,连接数据库后就可以直接通过sql语句来进行相关的操作了。 先登陆psql控制台,再连接指定的数据库 psql命令也可以不指定某个数据库,如下: psql -h <dbserver_IP> -p

ICML 2017大热论文:Wasserstein GAN | 经典论文复现

蓝咒 提交于 2020-12-19 07:22:07
ICML 2017大热论文:Wasserstein GAN | 经典论文复现 作者:文永明 学校 :中山大学 方向: 机器人视觉 尊重原创作品,转载请注明来处: https://www.cnblogs.com/ManWingming/p/11502938.html 最近笔者复现了 Wasserstein GAN ,简称 WGAN。 Wasserstein GAN 这篇论文来自 Martin Arjovsky 等人,发表于 2017 年 1 月。 论文作者用了两篇论文来阐述 Goodfellow 提出的原始 GAN 所存在的问题,第一篇是 WGAN 前作 Towards Principled Methods for Training Generative Adversarial Networks ,从根本上分析 GAN 存在的问题。随后,作者又在 Wasserstein GAN 中引入了 Wasserstein 距离,提出改进的方向,并且给出了改进的算法实现流程。 原始GAN存在的问题 原始的 GAN 很难训练,训练过程通常是启发式的,需要精心设计的网络架构,不具有通用性,并且生成器和判别器的 loss 无法指示训练进程,还存在生成样本缺乏多样性等问题。 在 WGAN 前作中,论文作者分析出原始 GAN 两种形式各自存在的问题, 其中一种形式等价于在最优判别器下

How to get the conversations for each user and include the messages?

痴心易碎 提交于 2020-12-18 07:57:10
问题 I am trying to get the conversations of each user to show them on my inbox screen in my front-end. I am able to post messages to the database, but when I try to getting them, I keep getting [SequelizeEagerLoadingError]: Message is not associated to Conversation! Can someone please have a look at my code. Here is my get request: router.get('/', auth, (req, res) => { Conversation.findAll({ where: { [Op.or]: [ { user1: { [Op.eq]: req.user.id }, user2: { [Op.eq]: req.user.id }, }, ], }, include:

postgresql+postgis+pgrouting安装(windows10)

只谈情不闲聊 提交于 2020-12-18 03:14:00
注:a. 以下安装皆指windows系统   b.只要安装了postgis,pgrouting自带就安装上了 一。postgresql版本10.9,posttgis版本2.5,pgrouting版本2.6( 三者版本必须对应!!! ) --查看postgresql版本 show server_version; --查看postgis版本 SELECT PostGIS_full_version(); --查看pgrouting版本 select pgr_version(); 二。安装文件下载地址( 点我下载 ),提取码:j2f8,下载文件名称:postgresql-10.9-2-windows-x64.exe,postgis-bundle-pg10x64-setup-2.5.2-1.exe 三。windows7,windows8安装参考   https://blog.csdn.net/antma/article/details/83579920 四。windows10安装步骤如下   4-1.postgresql安装:按照  上述所说的windows7,windows8安装方式正常安装 https://blog.csdn.net/antma/article/details/83579920 注:很大概率会报错: Problem running post-install step.

死锁及常见死锁模型

别等时光非礼了梦想. 提交于 2020-12-17 08:27:21
Ⅰ、死锁的概念 两个或两个以上的事务在执行过程中,因争夺资源而造成的一种互相等待的现象 最常见:AB-BA 稍微复杂:A-B B-C C-A形成如下图的循环 tips: lock wait time out 和 dead lock不是一回事 1.1 死锁的处理机制 锁超时 --innodb_lock_wait_timeout 让一个超时另一个执行,但这个机制在数据库中是不用的 自动死锁检测 通过锁的信息链表和事务等待链表构造出一个等待图(wait-for graph),如下: t1 t2 t3 t4 是事务列表,四个事务之间的边表示等待关系——edge,每个节点(事务)和每个edge加进去的时候会判断下有没有回路,如果有,就那啥,懂的吧? 检测到了后会很聪明地选择其中一个事务回滚,那选择哪个呢? 根据undo的量判断,回滚量少的,不记得是5.5还是5.6开始才有这个机制,之前的数据库版本是直接回滚后面一个事务,比较挫 5.6版本对图的死锁检测部分的内核算法进行了优化,原来是递归的方式做的,现在通过重写,非递归,提升了性能,所以大并发时5.6性能比5.5好很多,这块也有功劳 Ⅱ、死锁演示 2.1 先模拟下场景 begin: session1: select a for update; session2: begin: select b for update; select a for

100G以太网光口的FPGA测试实例

天涯浪子 提交于 2020-12-17 08:25:29
100G光口测试采用C50测试仪和Xilinx的VCU118开发板测试,经过测试发现,Xilinx自带的100G IP核仍然无法跑到满速,跟10G一样,也是只跑到99%的负载率。另外,工具的版本和License的申请都需要特别留意。欢迎感兴趣的同学们留言讨论。 一、软硬件环境、IP核及对应License 1、软硬件环境 软件环境为VIVADO2019.1,不建议采用VIVADO 2018.2,原因在于2018.2中的该IP核没有AXI总线,只有LBUS总线,LBUS总线使用起来需要进行总线的聚合与分拆(数据总线分为4路,每路位宽为128bit),较为繁琐,所以建议使用2019.1中的AXI总线的IP核。 硬件环境为采用TestCenter C50测试仪的100G光口连接VCU118开发板上的100G光口进行测试。 连接图(必须用100G专用光纤) VCU118开发板 C50网络分析仪(两个100G光口、4个五速光口(40G、20G和十百千)、16个十百千自适应电口) 2、100G IP核 所使用的IP核是UltraScale+ 100G Ethernet subsystem。 IP核配置界面如下图所示: 因环境选择的是Xilinx官方开发板,所以此处可以进行选择,参考时钟为全是qsfp1 si570 clock。 选择四通道(CAUI4),线速率默认为4lanes * 25

Linux 下连接sqlserver(下)

╄→尐↘猪︶ㄣ 提交于 2020-12-16 04:27:08
基于ODBC开发 odbc接口环境部署好后,就可以开始进行开发了,微软官网有详细的接口操作说明,但odbc接口还是太底层,操作起来比较麻烦,这里采用数据库的封装类soci来实现快速开发。 soci是一个用C++封装的数据库访问库,通过“前端(应用程序)/核心/后端(数据库适配)”模式支持firebird,mysql,sqlite3,oracle,postgresql,odbc多种数据库 安装soci git clone https://github.com/SOCI/soci.git cd soci mkdir build cd build cmake .. make sudo make install 注: 一般来说采用默认项就可以了,也可以为cmake附带一些参数: 1、设置自定义的安装目录: -DCMAKE_INSTALL_PREFIX=$HOME/local 2、指定自定义编译程序: -DCMAKE_C_COMPILER=gcc 3、如果你用的较高版本的编译器,默认是开启c++11的,如果cmake得到的SOCI_CXX11为OFF,你可以自行开启 -DSOCI_CXX11=ON, 否则后续使用时将会出现不一致的情况。 执行cmake 你会得到以下信息: 编码 这里有两种方案 1、使用dsn文件进行连接 2、指定连接字符串进行连接 soci是基于odbc进行封装的

Postgres table to two-dimensional array

为君一笑 提交于 2020-12-16 04:16:51
问题 I would like to convert a table with three columns to a two-dimensional array of type integer[][] . There are two columns to indicate each of the two dimensions of the array ( x and y in the example) and one integer column to indicate the value. All possible combinations of x and y are accounted for in the data, though it would be nice if a possible solution could substitute NULL for missing combinations of x and y . The table looks as such: DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( x

Postgres table to two-dimensional array

拈花ヽ惹草 提交于 2020-12-16 04:15:24
问题 I would like to convert a table with three columns to a two-dimensional array of type integer[][] . There are two columns to indicate each of the two dimensions of the array ( x and y in the example) and one integer column to indicate the value. All possible combinations of x and y are accounted for in the data, though it would be nice if a possible solution could substitute NULL for missing combinations of x and y . The table looks as such: DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( x