postgresql

Find out number of months between 2 dates

做~自己de王妃 提交于 2021-02-19 05:02:55
问题 select (age('2012-11-30 00:00:00'::timestamp, '2012-10-31 00:00:00'::timestamp)), (age('2012-12-31 00:00:00'::timestamp, '2012-10-31 00:00:00'::timestamp)), (age('2013-01-31 00:00:00'::timestamp, '2012-10-31 00:00:00'::timestamp)), (age('2013-02-28 00:00:00'::timestamp, '2012-10-31 00:00:00'::timestamp)) which gives the followings: 0 years 0 mons 30 days 0 hours 0 mins 0.00 secs 0 years 2 mons 0 days 0 hours 0 mins 0.00 secs 0 years 3 mons 0 days 0 hours 0 mins 0.00 secs 0 years 3 mons 28

SQLAlchemy cannot connect to Postgresql on localhost

。_饼干妹妹 提交于 2021-02-19 04:24:45
问题 I'm sure this is such an easy error to fix, if I could only find where it is. This is the error from the Flask app: 11:58:18 web.1 | ERROR:xxxxxx.core:Exception on / [GET] 11:58:18 web.1 | Traceback (most recent call last): 11:58:18 web.1 | File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app 11:58:18 web.1 | response = self.full_dispatch_request() 11:58:18 web.1 | File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request 11:58:18 web

Postgresql: Unique constraint over Union of 2 columns

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-19 02:59:07
问题 I have the following tables: TRANSACTIONS id | amount ------------------ 1 | 100 2 | -100 3 | 250 4 | -250 TRANSACTION_LINKS id | send_tx | receive_tx --------------------------- 1 | 2 | 1 2 | 4 | 2 The send_tx and receive_tx columns in the transaction links table use foreign keys pointing to the ID of the transactions table. This is how I create the transaction links table CREATE TABLE IF NOT EXISTS transaction_links ( id BIGSERIAL PRIMARY KEY, send_id INT NOT NULL UNIQUE REFERENCES

How do I change the max column width in PostgreSQL?

為{幸葍}努か 提交于 2021-02-19 02:36:05
问题 I have simple SQL query that selects a few rows from one table. One of the columns contains very long strings. I would like to set a maximum column width so that it is easier to read. I don't have access to environment variables through \pset. 来源: https://stackoverflow.com/questions/48481809/how-do-i-change-the-max-column-width-in-postgresql

flyway unable to connect to postgres container within docker-entrypoint-initdb.d script

依然范特西╮ 提交于 2021-02-19 02:15:38
问题 I'm trying to extend the postgres Docker image to potentially (via an environment variable flag) execute flyway DB migrations on DB init. My Dockerfile is here: FROM postgres:9.6 # Install curl and java (for Flyway) RUN set -x \ && apt-get update \ && apt-get install -y --no-install-recommends ca-certificates curl openjdk-8-jre # Install Flyway ENV FLYWAY_VERSION 4.2.0 ENV FLYWAY_INSTALL_DIR /usr/src/flyway ENV FLYWAY_CONF ${FLYWAY_INSTALL_DIR}/flyway-${FLYWAY_VERSION}/conf/flyway.conf ENV

flyway unable to connect to postgres container within docker-entrypoint-initdb.d script

ε祈祈猫儿з 提交于 2021-02-19 02:14:43
问题 I'm trying to extend the postgres Docker image to potentially (via an environment variable flag) execute flyway DB migrations on DB init. My Dockerfile is here: FROM postgres:9.6 # Install curl and java (for Flyway) RUN set -x \ && apt-get update \ && apt-get install -y --no-install-recommends ca-certificates curl openjdk-8-jre # Install Flyway ENV FLYWAY_VERSION 4.2.0 ENV FLYWAY_INSTALL_DIR /usr/src/flyway ENV FLYWAY_CONF ${FLYWAY_INSTALL_DIR}/flyway-${FLYWAY_VERSION}/conf/flyway.conf ENV

flyway unable to connect to postgres container within docker-entrypoint-initdb.d script

江枫思渺然 提交于 2021-02-19 02:13:20
问题 I'm trying to extend the postgres Docker image to potentially (via an environment variable flag) execute flyway DB migrations on DB init. My Dockerfile is here: FROM postgres:9.6 # Install curl and java (for Flyway) RUN set -x \ && apt-get update \ && apt-get install -y --no-install-recommends ca-certificates curl openjdk-8-jre # Install Flyway ENV FLYWAY_VERSION 4.2.0 ENV FLYWAY_INSTALL_DIR /usr/src/flyway ENV FLYWAY_CONF ${FLYWAY_INSTALL_DIR}/flyway-${FLYWAY_VERSION}/conf/flyway.conf ENV

How to filter postgres array column with the JPA criteria API?

大憨熊 提交于 2021-02-18 23:01:48
问题 I am using: Hibernate 4.3.5 Spring JPA 1.6.0 Javax Persistence API 2.1 The "refcodemailing" column is defined as an array of int: int[] My entity object: @Entity @Table public class CalendarEvent implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id = 0; @Convert(converter = IntegerArrayConverter.class) @Column(name = "refcodemailing") private final List<Integer> mailingCodes = new ArrayList<>(); // .... } I am trying to filter the column array with the

How do I SQL query for words with punctuation in Postgresql?

情到浓时终转凉″ 提交于 2021-02-18 22:45:23
问题 If I have strings/phrases like this stored in the database: What are Q-type Operations? Programmer's Guide A.B.C's of Coding Is there a way to pass a query parameter in like "Programmers" or "abc" or "q-type" and have it find "Programmer's" , "A.B.C" and "Q-type" ? 回答1: tsvector Use the tsvector type, which is part of the PostgreSQL text-search feature. postgres> select 'What are Q-type Operations?'::tsvector; tsvector ------------------------------------- 'Operations?' 'Q-type' 'What' 'are'

Avoid exclusive access locks on referenced tables when DROPping in PostgreSQL

感情迁移 提交于 2021-02-18 22:45:22
问题 Why does dropping a table in PostgreSQL require ACCESS EXCLUSIVE locks on any referenced tables? How can I reduce this to an ACCESS SHARED lock or no lock at all? i.e. is there a way to drop a relation without locking the referenced table? I can't find any mention of which locks are required in the documentation, but unless I explicitly get locks in the correct order when dropping multiple tables during concurrent operations, I can see deadlocks waiting on an AccessExclusiveLock in the logs,