postgresql

How can I get past this problem recreating a pg_logical subscription?

你。 提交于 2021-02-11 12:47:12
问题 I'm having a problem dropping and creating subscriptions - I think these messages are saying it exists on the replica and not the primary: db=# CREATE SUBSCRIPTION sub db-# CONNECTION 'dbname=db host=some.domain.com user=logical_replicator password=xxxxxxx' db-# PUBLICATION pub; ERROR: subscription "sub" already exists db=# DROP subscription sub; ERROR: could not drop the replication slot "sub" on publisher DETAIL: The error was: ERROR: replication slot "sub" does not exist How can I get this

How can I get past this problem recreating a pg_logical subscription?

跟風遠走 提交于 2021-02-11 12:45:53
问题 I'm having a problem dropping and creating subscriptions - I think these messages are saying it exists on the replica and not the primary: db=# CREATE SUBSCRIPTION sub db-# CONNECTION 'dbname=db host=some.domain.com user=logical_replicator password=xxxxxxx' db-# PUBLICATION pub; ERROR: subscription "sub" already exists db=# DROP subscription sub; ERROR: could not drop the replication slot "sub" on publisher DETAIL: The error was: ERROR: replication slot "sub" does not exist How can I get this

What's the problem with deleting a row from database?

倖福魔咒の 提交于 2021-02-11 12:38:10
问题 I want to delete a row from my database, but it doesn't work. I've got 2 exception: - NumberFormatException: null (it's for the parseInt part in the Servlet) - PSQLException: ERROR: relation "patients" does not exist... but it does exist! Can u help me to solve my problem? DB.java (just the method) public int deletePatient(int patID) { try { if (conn != null) { String delete = "DELETE FROM \"Patients\" WHERE Patients.PatientID = ?"; PreparedStatement pstmt = conn.prepareStatement(delete);

Play + Anorm + Postgres - load json value into a case class

不问归期 提交于 2021-02-11 12:35:58
问题 I am using anorm to query and save elements into my postgres database. I have a json column which I want to read as class of my own. So for example if I have the following class case class Table(id: Long, name:String, myJsonColumn:Option[MyClass]) case class MyClass(site: Option[String], user:Option[String]) I am trying to write the following update: DB.withConnection { implicit conn => val updated = SQL( """UPDATE employee |SET name = {name}, my_json_column = {myClass} |WHERE id = {id} """

Django Psycopg2 Error When Running Migrations in Testing

痞子三分冷 提交于 2021-02-11 12:31:27
问题 I developed a basic version of a Django app in SQLite3. Then, it came time to switch it to Postgres and put in production. When doing so, I noticed that I was able to create and run migrations for the new database. However, when trying to run tests for the Postgres version, I run into an issue. Here it is. I run tests with coverage run --source='.' manage.py test ; however, the same thing happens when running via python manage.py test Creating test database for alias 'default'... Got an error

Insert data in database depending by relation

徘徊边缘 提交于 2021-02-11 12:28:00
问题 I am using typeorm, Nest Js and postgresql database. I have the next entities: import {Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, JoinColumn, OneToOne} from 'typeorm'; import {User} from "./user.entity"; import {MetaImages} from "./meta-images.entity"; @Entity() export class Cars { @PrimaryGeneratedColumn({name: "carId"}) carId: number; @OneToMany(() => CarsColors, c => c.carId, { cascade: true }) carsColors: CarsColors[]; } /// Colors Entity @Entity() export class

Postgres: which index to add

雨燕双飞 提交于 2021-02-11 12:24:26
问题 I have a table mainly used by this query (only 3 columns are in use here, meter , timeStampUtc and createdOnUtc , but there are other in the table), which starts to take too long: select rank() over (order by mr.meter, mr."timeStampUtc") as row_name , max(mr."createdOnUtc") over (partition by mr.meter, mr."timeStampUtc") as "createdOnUtc" from "MeterReading" mr where "createdOnUtc" >= '2021-01-01' order by row_name ; (this is the minimal query to show my issue. It might not make too much

Postgres timestamp with microseconds

拜拜、爱过 提交于 2021-02-11 12:18:28
问题 I have a column in a table with datatype set as timestamp without time zone . I need the time part with microseconds(6 digits), but sometimes if the last digit is zero, the microseconds part ignores it. I am able to query it with the below query to get 6 digits select to_char(now(), 'yyyy-mm-dd hh:mi:us'); 2020-07-16 12:05:598000 The above output is in text/char format but I need it in timestamp without time zone datatype with all 6 digits for microseconds even if one or some of the last

Postgresql - Count freuency of array or jsonb object

有些话、适合烂在心里 提交于 2021-02-11 12:15:20
问题 In pg, there is a tags field of type varchar , containing tags separated by ] , e.g 'a]b]c' . Need to count occurrences of these tags across multiple rows. Currently , I know how to: Convert the raw string into pg array ['a', 'b', 'c'] and if the column is given as jsonb object {'a':1, 'b':1, 'c':1} , could count frequency via jsonb functions. But I don't know how to convert pg array ['a', 'b', 'c'] into jsonb object {'a':1, 'b':1, 'c':1} , or just count frequency on array elements directly.

Why does my query involving division and COUNT always result in 1?

∥☆過路亽.° 提交于 2021-02-11 10:47:41
问题 I've simplified this down a bit since the literal data is pretty massive but a very simple example will suffice. I'm working on a query where because of the massive amount of data, I'm looking to do some aggregation in one shot instead of many many steps. I have two tables <<customers>> id | first_name | last_name 1 | Reed | Richards 2 | Johnny | Storm 3 | Peter | Parker <<purchases>> id | cid | date 1 | 1 | 2017-01-09 2 | 2 | 2017-01-09 3 | 2 | 2017-01-09 4 | 3 | 2017-01-09 When I run the