postgresql

How can I get the INSERTED and UPDATED rows for an UPSERT operation in postgres

烈酒焚心 提交于 2021-02-16 09:34:09
问题 I've got an UPSERT Operation like this: INSERT INTO people (SELECT * FROM people_update) ON CONFLICT (name,surname) DO UPDATE SET age = EXCLUDED.age , street = EXCLUDED.street , city = EXCLUDED.city , postal = EXCLUDED.postal WHERE (people.age,people.street,people.city,people.postal) IS DISTINCT FROM (EXCLUDED.age,EXCLUDED.street,EXCLUDED.city,EXCLUDED.postal) RETURNING case when xmax::text::int > 0 then 'updated' else 'inserted' end,name,surname,age,street,city,postal; (name,surname) is a

How to split array into rows in Postgresql

本秂侑毒 提交于 2021-02-16 08:40:32
问题 When running this query: SELECT id,selected_placements FROM app_data.content_cards I get a table like this: +----+-------------------------------+ | id | selected_placements | +----+-------------------------------+ | 90 | {162,108,156,80,163,155,NULL} | +----+-------------------------------+ | 91 | {} | +----+-------------------------------+ What I want to do now is get this same information but with the arrays splitted into rows so I get a result like this: +----+---------------------+ | id

How to split array into rows in Postgresql

北战南征 提交于 2021-02-16 08:38:42
问题 When running this query: SELECT id,selected_placements FROM app_data.content_cards I get a table like this: +----+-------------------------------+ | id | selected_placements | +----+-------------------------------+ | 90 | {162,108,156,80,163,155,NULL} | +----+-------------------------------+ | 91 | {} | +----+-------------------------------+ What I want to do now is get this same information but with the arrays splitted into rows so I get a result like this: +----+---------------------+ | id

PostgreSQL recursive parent/child query

馋奶兔 提交于 2021-02-16 08:33:38
问题 I'm having some trouble working out the PostgreSQL documentation for recursive queries, and wonder if anyone might be able to offer a suggestion for the following. Here's the data: Table "public.subjects" Column | Type | Collation | Nullable | Default -------------------+-----------------------------+-----------+----------+-------------------------------------- id | bigint | | not null | nextval('subjects_id_seq'::regclass) name | character varying | | | Table "public.subject_associations"

PostgreSQL recursive parent/child query

老子叫甜甜 提交于 2021-02-16 08:32:00
问题 I'm having some trouble working out the PostgreSQL documentation for recursive queries, and wonder if anyone might be able to offer a suggestion for the following. Here's the data: Table "public.subjects" Column | Type | Collation | Nullable | Default -------------------+-----------------------------+-----------+----------+-------------------------------------- id | bigint | | not null | nextval('subjects_id_seq'::regclass) name | character varying | | | Table "public.subject_associations"

sqlalchemy raw sql query limit using connection.execute()

痞子三分冷 提交于 2021-02-16 06:28:51
问题 This python code should run statements on the database, but the sql statements are not executed: from sqlalchemy import * sql_file = open("test.sql","r") sql_query = sql_file.read() sql_file.close() engine = create_engine( 'postgresql+psycopg2://user:password@localhost/test', echo=False) conn = engine.connect() print sql_query result = conn.execute(sql_query) conn.close() The test.sql file contains SQL statements which create 89 tables. The tables are not created if I specify 89 tables, but

sqlalchemy raw sql query limit using connection.execute()

坚强是说给别人听的谎言 提交于 2021-02-16 06:25:49
问题 This python code should run statements on the database, but the sql statements are not executed: from sqlalchemy import * sql_file = open("test.sql","r") sql_query = sql_file.read() sql_file.close() engine = create_engine( 'postgresql+psycopg2://user:password@localhost/test', echo=False) conn = engine.connect() print sql_query result = conn.execute(sql_query) conn.close() The test.sql file contains SQL statements which create 89 tables. The tables are not created if I specify 89 tables, but

How to install wordpress with postgresql

╄→гoц情女王★ 提交于 2021-02-16 05:46:09
问题 I m newbie in wordpress. i just install wordpress 4.2.2. I want to install wordpress on heroku with postgresql. Before that i try to install wordpress with postgresql on my localhost. I follow the PG4WP installation steps but still my wordpress install with mysql database its not giving me option to install with postgresql. I am using Wordpress 4.2.2 version and for database i am using postgresql 9.1 回答1: It might be a little late, but the current answers are and were wrong. It is possible to

Spring的使用优点

蹲街弑〆低调 提交于 2021-02-15 17:50:20
spring事物配置,声明式事务管理和基于@Transactional注解的使用 spring支持编程式事务管理和声明式事务管理两种方式。 编程式事务 管理使用TransactionTemplate或者直接使用底层的PlatformTransactionManager。对于编程式事务管理,spring推荐使用TransactionTemplate。 声明式事务 管理建立在AOP之上的。 其本质是对方法前后进行拦截 ,然后在目标方法开始之前创建或者加入一个事务,在执行完目标方法之后根据执行情况提交或者回滚事务。 声明式事务最大的优点就是不需要通过编程的方式管理事务,这样就不需要在业务逻辑代码中掺杂事务管理的代码 ,只需在配置文件中做相关的事务规则声明(或通过基于@Transactional注解的方式),便可以将事务规则应用到业务逻辑中。 显然声明式事务管理要优于编程式事务管理,这正是spring倡导的非侵入式的开发方式。声明式事务管理使业务代码不受污染,一个普通的POJO对象,只要加上注解就可以获得完全的事务支持。和编程式事务相比,声明式事务唯一不足地方是,后者的最细粒度只能作用到方法级别,无法做到像编程式事务那样可以作用到代码块级别。但是即便有这样的需求,也存在很多变通的方法,比如,可以将需要进行事务管理的代码块独立为方法等等。 声明式事务管理也有两种常用的方式

oracle迁移到greenplum的方案

北慕城南 提交于 2021-02-15 09:53:20
oracle数据库是一种关系型数据库管理系统,在数据库领域一直处于领先的地位,适合于大型项目的开发;银行、电信、电商、金融等各领域都大量使用Oracle数据库。 greenplum是一款开源的分布式数据库存储解决方案,主要关注数据仓库和BI报表及多维查询等方面。采用了shared-nothing的大规模并行处理MPP架构。 目前我手头的工作是需要将oracle数据库迁移到greenplum库中,大概收集了一下资料。 因为greenplum数据库是基于postgresql的,所以可以使用oracle迁移到postgresql的方式来做。 先看一下官网: https://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL 官网上列举了所有oracle迁移到pg的可用工具。带锁的是收费的,不带锁的是开源的 本次采用的是ora2pg的工具来做。 安装这边就不提了,可以参照git官网的说明来安装 https://github.com/darold/ora2pg 我们的目的是要将oracle的表的表结构转换成pg的建表语句。数据的抽取我们需要另外想办法。 这个ora2pg工具主要是用配置文件来控制需要转换的东西。可以单独转换表结构,可以导出数据。也可以导出视图、索引、包结构等。 主要的配置文件内容如下: