postgresql

Min and Max values grouping by consecutive ranges

霸气de小男生 提交于 2021-01-29 05:13:43
问题 I have a table that informs me a error type and line number that error occurred. (The process is irrelevant at this moment). I need to group by error type and show line start and line end for each error type, resulting of a range of each error type. I need to consider gaps of lines My table and queries was: create table errors ( err_type varchar(10), line integer); insert into errors values ('type_A', 1),('type_A', 2),('type_A', 3), ('type_A', 6),('type_A', 7), ('type_B', 9),('type_B', 10), (

How do I use regular expressions in PostgreSQL to remove the end of a field matching pattern?

China☆狼群 提交于 2021-01-29 04:57:14
问题 How can I simplify this PostgreSQL? Basically I want to check if the fields end with (1) or just (1) and replace and repeat from numbers from 1-30. I assume it can be done with regular expressions somehow, but I haven't got it working. UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,' (1)')) WHERE name LIKE '% (1)'; UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,'(1)')) WHERE name LIKE '%(1)'; UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,

How do I use regular expressions in PostgreSQL to remove the end of a field matching pattern?

给你一囗甜甜゛ 提交于 2021-01-29 04:52:21
问题 How can I simplify this PostgreSQL? Basically I want to check if the fields end with (1) or just (1) and replace and repeat from numbers from 1-30. I assume it can be done with regular expressions somehow, but I haven't got it working. UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,' (1)')) WHERE name LIKE '% (1)'; UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,'(1)')) WHERE name LIKE '%(1)'; UPDATE discogs.artist_meta SET name = substr(name,0, strpos(name,

生产级harbor可用的搭建

ぐ巨炮叔叔 提交于 2021-01-29 04:23:32
生产级harbor可用的搭建 Harbor简介 Harbor 是一个用于存储和分发 Docker镜像 的企业级 Registry 服务器,通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。 作为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。 提升用户使用Registry构建和运行环境传输镜像的效率。 Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有Registry中, 确保数据和知识产权在公司内部网络中管控。 另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。 高可用架构:双主复制 主从同步 harbor官方默认提供主从复制的方案来解决镜像同步问题,通过复制的方式,我们可以实时将测试环境harbor仓库的镜像同步到生产环境harbor,类似于如下流程: 在实际生产运维的中,往往需要把镜像发布到几十或上百台集群节点上。这时,单个Registry已经无法满足大量节点的下载需求,因此要配置多个Registry实例做负载均衡。手工维护多个Registry实例上的镜像,将是十分繁琐的事情。Harbor可以支持一主多从的镜像发布模式,可以解决大规模镜像发布的难题: 只要往一台Harbor上发布,镜像就会像"仙女散花"般地同步到多个Registry中

Counting null values between dates

拈花ヽ惹草 提交于 2021-01-29 03:37:35
问题 I'm trying to calculate the number of null values between dates. My table looks like this: transaction_date transaction_sale 10/1/2018 NULL 11/1/2018 33 12/1/2018 NULL 1/1/2019 NULL 2/1/2019 NULL 3/1/2019 2 4/1/2019 NULL 5/1/2019 NULL 6/1/2019 10 I'm looking to get the following output: transaction_date transaction_sale count 10/1/2018 NULL NULL 11/1/2018 33 1 12/1/2018 NULL NULL 1/1/2019 NULL NULL 2/1/2019 NULL NULL 3/1/2019 2 3 4/1/2019 NULL NULL 5/1/2019 NULL NULL 6/1/2019 10 2 回答1: count(

PostgreSQL/performance one general cursor or create for every query

倖福魔咒の 提交于 2021-01-29 03:23:04
问题 I am building a script to store some data in a database. First time I'm using PostgeSQL and everything goes well and as planned. I was thinking about the usage of the Cursor in PostgreSQl and what if I am making a lot of them while one is enough. But I don't want to pass the cursor to all my SQL functions. Here's my simplified example. dbConn, dbCurs = openDataBase(config) doSomeThing(dbCurs, name, age, listOfJohns) def doSomething(dbCurs, name, age, listOfPoeple): listOfPoeple

Performing a join across multiple heterogenous databases e.g. PostgreSQL and MySQL

坚强是说给别人听的谎言 提交于 2021-01-29 03:12:36
问题 There's a project I'm working on, kind of a distributed Database thing. I started by creating the conceptual schema, and I've partitioned the tables such that I may require to perform joins between tables in MySQL and PostgreSQL. I know I can write some sort of middleware that will break down the SQL queries and issue sub-queries targeting individual DBs, and them merge the results, but I'd like to do do this using SQL if possible. My search so far has yielded this (Federated storage engine

PGSQL Trigger Function Write Exception to Log Table

喜欢而已 提交于 2021-01-29 02:53:37
问题 Background I'm new to PostgreSQL and I'm having some issues with this trigger function, which I've obviously simplified considerably below. I could ask to help fix the query, but I think I can handle that, and what I'm more concerned about is that I have a lot of functions like this and I need a way to be able to have visibility into why it's failing, and which ones are failing. Question How can I catch exceptions that happen within this function and write them to some kind of log table so I

Cannot update table via sqlalchemy

时光毁灭记忆、已成空白 提交于 2021-01-29 02:47:30
问题 I'm trying to update a row after a select instance = session.query(Scouts).filter(Scouts.camp == camp, Scouts.user == user,Scouts.gender == gender).first() instance.number_of_visits += 1 session.commit() My Scouts class looks like: class Scouts(Base): __tablename__ = 'scouts' camp = Column(String, primary_key=True) user = Column(Integer) gender = Column(String) number_of_visits = Column(Integer) def __init__(self, camp, user, gender, number_of_visits): self.camp = camp self.user = user self

Cannot update table via sqlalchemy

霸气de小男生 提交于 2021-01-29 02:45:29
问题 I'm trying to update a row after a select instance = session.query(Scouts).filter(Scouts.camp == camp, Scouts.user == user,Scouts.gender == gender).first() instance.number_of_visits += 1 session.commit() My Scouts class looks like: class Scouts(Base): __tablename__ = 'scouts' camp = Column(String, primary_key=True) user = Column(Integer) gender = Column(String) number_of_visits = Column(Integer) def __init__(self, camp, user, gender, number_of_visits): self.camp = camp self.user = user self