postgresql

Query where foreign key column can be NULL

帅比萌擦擦* 提交于 2021-01-27 04:16:37
问题 I want to get data if orgid = 2 or if there is no row at all for the uid . orgid is an integer . The closest thing I could think of is to do IS NULL but I'm not getting data for the uid that doesn't have an orgid row. Any idea? select u.uid,u.fname,u.lname from u inner join u_org on u.uid = u_org.uid inner join login on u.uid = login.uid where u_org.orgid=2 or u_org.orgid is NULL and login.access != 4; Basically the OR is if u_org.orgid row doesn't exist. 回答1: If there is "no row at all for

org.hibernate.type.TextType and Oracle

亡梦爱人 提交于 2021-01-27 04:08:54
问题 We use Hibernate as a JPA provider and we have a class with a large object field marked with @Lob @Type( type = "org.hibernate.type.TextType" ) private String someString; The column is created as SOMESTRING LONG() This works flawlessly with PostgreSQL and MySQL. With Oracle when persisting the object entityManager.persist( object ); we get an org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update exception. Removing the @Type( type = "org.hibernate.type.TextType" )

pg备份还原工具--barman

廉价感情. 提交于 2021-01-27 04:01:19
一、系统 [root@barman ~]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m [root@barman ~]# uname -a Linux barman 2.6.32-431.11.2.el6.x86_64 #1 SMP Tue Mar 25 19:59:55 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux # cat /etc/hosts 192.168.100.146 barman 192.168.100.147 pg 二、安装 2.1 简介 Barman (backup and recovery manager) is an administration tool for disaster recovery of PostgreSQL servers written in Python. Barman can perform remote backups of multiple servers in business critical environments, and helps DBAs during the recovery phase. Barman’s most wanted features include: backup catalogues

postgresql也很强大,为何mysql成为主流?

痞子三分冷 提交于 2021-01-26 19:02:55
今天在知乎上看到一个问题的告赞回答,觉得说的挺好的,转发一下。 作者:大宽宽 链接:https://www.zhihu.com/question/31955622/answer/1625152059 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 mysql和postgres的早期完全是两个极端。mysql更像是个“基本上满足关系数据库语法的大号KV”,对关系型数据库的高级功能支持的很不好。我入行时接触的MySQL 5.1和MyISAM存储引擎,不支持ACID,但有如下几点在当时的互联网公司看来是非常合适: 互联网公司为了扩展,长期的经验是,仅仅把数据库当作是一个“存储”,而非存储+核心数据逻辑的计算节点。大量的计算都在业务服务器上进行,而业务服务器可以无限水平扩展,而无需担心有状态的数据迁移问题; 因为没有提供很多高级功能和数据一致性的保障,mysql对于简单的sql支持的反而更加直接,在速度上有很大的优势; 对于OLTP,完全不需要复杂的数据处理功能。简单的select ... from ... where id = xxx; insert into xxx;update xxx set xxx=xxx where id = xxxx是OLTP的主流功能。基于这些功能的ORM的出现大大的提高了生产效率;对于OLAP

PostgreSQL忘记postgres账号的密码怎么办?

旧城冷巷雨未停 提交于 2021-01-26 10:25:57
PostgreSQL数据库中,假如你忘记了postgres账号的密码或者由于工作交接问题,等交接到你手头的时候,没有postgres账号密码,那怎么办呢?其实不用慌,像MySQL、SQL Server等数据库一样,只要你拥有操作系统权限,修改postgres超级账号的密码也非常方便简单。下面测试环境为CentOS Linux release 7.2.1511 (Core), PostgreSQL数据库版本为9.5。其它不同版本的操作其实是一样的,只是略有细微差别。 1:定位 pg_hba.conf 文件位置 首先找到 pg_hba.conf 文件的位置,具体有下面这些方法: 方法 1 : locate 定位 pg_hba.conf 文件的位置 $ locate pg_hba.conf /usr/pgsql-9.5/share/pg_hba.conf.sample /var/lib/pgsql/9.5/data/pg_hba.conf 方法 2 : find 命令查找。 $ find / -name "pg_hba.conf" 2>%1 | grep -v "Permission denied" /var/lib/pgsql/9.5/data/pg_hba.conf 2 :修改 pg_hba.conf 配置文件 修改 pg_hba.conf 前最好做一个备份,这是一个良好的习惯

Postgres 12 case-insensitive compare

牧云@^-^@ 提交于 2021-01-26 08:49:06
问题 I'm attempting to move a SQL Server DB which is used by a C# application (+EF6) to Postgres 12 but I'm not having much luck with getting case-insensitive string comparisons working. The existing SQL Server db uses SQL_Latin1_General_CP1_CI_AS collation which means all WHERE clauses don't have to worry about case. I understand that CIText was the way to do this previously, but is now superseded by non-deterministic collations. I created such a collation; CREATE COLLATION ci (provider = icu,

API 分页设计与实现探讨

我的梦境 提交于 2021-01-26 07:10:07
对于设计和实现 API 来说,当结果集包含成千上万条记录时,返回一个查询的所有结果可能是一个挑战,它给服务器、客户端和网络带来了不必要的压力,于是就有了分页的功能。 通常我们通过一个 offset 偏移量或者页码来进行分页,然后通过 API 实现类似请求: GET /api/products?page= 10 { "items" : [.. .100 products]} 如果要继续访问后续数据,则修改分页参数即可。 GET /api/products?page= 11 { "items" : [...another 100 products]} 在使用 offset 的情况下,通常使用 ?offset=1000 和 ?offset=1100 这种大家都熟悉的方法。它要么直接调用 OFFSET 1000 LIMIT 100 的 SQL 查询数据库,要么使用 LIMIT 乘以 page 作为查询参数。无论如何, 这是一个次优的解决方案 ,因为无论哪种数据库都要跳过前面 offset 指定的 1000 行。而跳过额外的offset,不管是 PostgreSQL,ElasticSearch还是 MongoDB 都存在额外开销,数据库需要对它们进行排序,计数,然后将前面不用的数据扔掉。 粉丝福利: 手撸了 50 个 Java 项目实战后,我超神了! 这是一种低效的方法,但由于它使用简单

How can users like and unlike each others post using sequelize postgres nodejs?

蹲街弑〆低调 提交于 2021-01-26 03:02:32
问题 I am trying to implement that users can like each others post. Here is my Likes model: const Likes = db.define("Likes", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, PostId: { type: Sequelize.INTEGER, references: { model: "Post", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, userId: { type: Sequelize.INTEGER, references: { model: "User", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, createdAt: { allowNull: false, type:

How can users like and unlike each others post using sequelize postgres nodejs?

試著忘記壹切 提交于 2021-01-26 03:01:19
问题 I am trying to implement that users can like each others post. Here is my Likes model: const Likes = db.define("Likes", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, PostId: { type: Sequelize.INTEGER, references: { model: "Post", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, userId: { type: Sequelize.INTEGER, references: { model: "User", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, createdAt: { allowNull: false, type:

How can users like and unlike each others post using sequelize postgres nodejs?

醉酒当歌 提交于 2021-01-26 03:01:18
问题 I am trying to implement that users can like each others post. Here is my Likes model: const Likes = db.define("Likes", { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, PostId: { type: Sequelize.INTEGER, references: { model: "Post", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, userId: { type: Sequelize.INTEGER, references: { model: "User", key: "id", }, onUpdate: "cascade", onDelete: "cascade", }, createdAt: { allowNull: false, type: