postgresql

Finding the histogram size for a given table PostgreSQL

£可爱£侵袭症+ 提交于 2021-01-28 11:40:25
问题 I have a PostgreSQL table named census . I have performed the ANALYSE command on the table, and the statistics are recorded in pg_stats . There are other entries in this pg_stats from other database tables as can be expected. However, I wanted to know the space consumed for storing the histogram_bounds for the census table alone. Is there a good and fast way for it? PS: I have tried dumping the pg_stats table onto the disk to measure the memory using select * into copy_table from census where

Finding Gaps in Timestamps for Multiple Users in PostgreSQL

帅比萌擦擦* 提交于 2021-01-28 11:39:27
问题 I am working with a dataset containing Check-In and Check-Out times for multiple office rooms over the last 5 years. One of the projects I was asked to work on was calculating the amount of time each room is busy and vacant over various time ranges (daily, weekly, monthly, etc.) assuming normal operational hours (8am to 5pm). A sample of the dataset for two days looks like this: room_id start_dt end_dt Room: Room 3 2019-05-04 09:00:00 2019-05-04 11:30:00 Room: Room 3 2019-05-04 11:30:00 2019

How to add 2 points with distance between them (SRID = 32636)?

£可爱£侵袭症+ 提交于 2021-01-28 11:36:08
问题 I'm using python 3.6 and postgres DB I have a table name: test_table with the following fields: name ( text ), geo ( geometry ) the srid of geo field is 32636 I want to write a python function which get point X (wkt) and return point Y with distance of 10 meters between the points. i.e: The X and Y are in WKT format How can I calculate the point Y with X is the input ? It seems that I can't use euclidean distance , because the srid is 32636 so how can I do it ? 回答1: You could cast your

Micronaut not connecting to db in yml

佐手、 提交于 2021-01-28 11:24:25
问题 I have created a new environment for my application and called it docker. I'm trying stuff out so I set it like this: application-docker.yml micronaut: application: name: time server: netty: access-logger: enabled: true logger-name: access-logger datasources: default: url: jdbc:postgresql://db:5432/postgres driverClassName: org.postgresql.Driver username: postgres password: postgres schema-generate: CREATE_DROP dialect: POSTGRES schema: time jpa.default.properties.hibernate.hbm2ddl.auto:

Hibernate optimistic locking different behavior between Postgres and MariaDb

两盒软妹~` 提交于 2021-01-28 11:21:29
问题 I just discovered that my application behaves differently when I use optimistic locking with a Postgresql or a MariaDB database and I am wondering if somebody can explain what happens and how could I make the application work in the same way with MariaDB? I use Postgresl 10.5 and MariaDB 10.3.10 with InnoDB engine and default settings. I use Spring framework version 5.1.0 and Hibernate 5.3.6. So my code looks like this: @Entity @Getter @Setter @NoArgsConstructor public class Bla { @Id

Access OpenShift forwarded ports from remote host

浪尽此生 提交于 2021-01-28 11:05:43
问题 I would like to connect to a PostgreSQL (9.6) cluster that runs inside OpenShift (3.9) using port forwarding as described here. To this end I set up and sanity-check port forwarding on a jump host (outside the OpenShift cluster) like this: oc port-forward $pod 5432:5432 netstat -ln | grep 5432 # "tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN" psql -U postgres -h localhost # OK psql -U postgres -h $(hostname -i) # error: "connection refused" So it looks as if port forwarding listens only for

Default Value in a column when insert a new row

扶醉桌前 提交于 2021-01-28 11:00:34
问题 I have the table Photographies with the columns: Name, Author, Date, Updated date. I would like to set Update date as default current_date when a new record is inserted or when a record is updated. How should I proceed with this? 回答1: Welcome to SO. Take a look at triggers. Basically you only need to create a function to perform the updated .. CREATE OR REPLACE FUNCTION update_date() RETURNS trigger AS $BODY$ BEGIN NEW.updated = current_date; RETURN NEW; END; $BODY$ LANGUAGE 'plpgsql'; .. and

Error seeding JSON data with sequelize into PostgreSQL database

荒凉一梦 提交于 2021-01-28 11:00:11
问题 Occurs when I run the sequelize-cli command sequelize db:seed:all When I try and seed an object as JSON I get the following error: ERROR: Invalid value { viewId: null, dateRanges: [ { startDate: null, endDate: null } ], samplingLevel: 'DEFAULT', dimensions: [ { name: 'ga:channelGrouping' } ], metrics: [ { expression: 'ga:users' } ] } This is my model module.exports = (Sequelize, DataTypes) => { const Report = Sequelize.define('Report', { name: { type: DataTypes.STRING, allowNull: false,

Is there a way to set the max width of a column when displaying JSONB results in psql?

大兔子大兔子 提交于 2021-01-28 09:15:37
问题 I have a problem that is somewhat similar to this question: Is there a way to set the max width of a column when displaying query results in psql?. I have a number of tables in Postgres with large JSONB documents. When I use psql from Emacs, it grinds to a halt trying to display fields with these documents. Ideally, I just want to see the first X characters of a document when I select * from a given table. I tried: \pset columns 20 To no avail. Is there some permutation of columns and format

Is there a way to set the max width of a column when displaying JSONB results in psql?

耗尽温柔 提交于 2021-01-28 09:11:01
问题 I have a problem that is somewhat similar to this question: Is there a way to set the max width of a column when displaying query results in psql?. I have a number of tables in Postgres with large JSONB documents. When I use psql from Emacs, it grinds to a halt trying to display fields with these documents. Ideally, I just want to see the first X characters of a document when I select * from a given table. I tried: \pset columns 20 To no avail. Is there some permutation of columns and format