postgresql-9.5

PostgreSQL: Checking for NEW and OLD in a function for a trigger

喜你入骨 提交于 2021-02-08 03:54:45
问题 I want to create a trigger which counts rows and updates a field in an other table. My current solution works for INSERT statements but failes when I DELETE a row. My current function: CREATE OR REPLACE FUNCTION update_table_count() RETURNS trigger AS $$ DECLARE updatecount INT; BEGIN Select count(*) into updatecount From source_table Where id = new.id; Update dest_table set count=updatecount Where id = new.id; RETURN NEW; END; $$ LANGUAGE 'plpgsql'; The trigger is a pretty basic one, looking

PostgreSQL: Checking for NEW and OLD in a function for a trigger

狂风中的少年 提交于 2021-02-08 03:54:13
问题 I want to create a trigger which counts rows and updates a field in an other table. My current solution works for INSERT statements but failes when I DELETE a row. My current function: CREATE OR REPLACE FUNCTION update_table_count() RETURNS trigger AS $$ DECLARE updatecount INT; BEGIN Select count(*) into updatecount From source_table Where id = new.id; Update dest_table set count=updatecount Where id = new.id; RETURN NEW; END; $$ LANGUAGE 'plpgsql'; The trigger is a pretty basic one, looking

Merge in postgres

与世无争的帅哥 提交于 2021-01-29 19:07:04
问题 Am trying to convert below oracle query to postgres, MERGE INTO table1 g USING (SELECT distinct g.CDD , d.SGR from table2 g, table3 d where g.IDF = d.IDF) f ON (g.SGR = f.SGR and g.CDD = f.CDD) WHEN NOT MATCHED THEN INSERT (SGR, CDD) VALUES (f.SGR, f.CDD); I made changes as below compatible to postgres: WITH f AS ( SELECT distinct g.CDD , d.SGR from table2 g, table3 d where g.IDF = d.IDF ), upd AS ( update table1 g set SGR = f.SGR , CDD = f.CDD FROM f where g.SGR = f.SGR and g.CDD = f.CDD

Postgresql syntax in ms access

独自空忆成欢 提交于 2021-01-29 07:21:01
问题 I was reading this link: Does PostgreSQL support "accent insensitive" collations? about how to use accent insensitive queries. and this link PostgreSQL: How to make "case-insensitive" query about using case insensitive queries. Tested a query in pgAdmin: SELECT * FROM Customers WHERE unaccent(Customers.customername) ILIKE unaccent('abc%') and it works fine. It gives me the expected results. However, my front end is in MS Access 2016, is there a way to send this query to Postgres from within

PostgreSQL dates function output to a french language

我是研究僧i 提交于 2021-01-28 06:23:01
问题 How can I output the result of PostgreSQL dates function as to_char to french language, for example the output of: select to_char(current_date, 'Day') ; should be (a french name for a day): Mardi instead of english of day (e.g. Monady) 回答1: You would need to set the display of date/time (LC_TIME) to french, and to query not the Day but rather the localizable day TMDay using the TM prefix. show LC_TIME; SET LC_TIME = 'French'; select to_char(current_date, 'TMDay') ; to_char --------- Mardi (1

docker-compose up postgresql error, chown: changing ownership of ‘/var/lib/postgresql/data’: Operation not permitted

穿精又带淫゛_ 提交于 2021-01-28 05:54:04
问题 I'm working in a project and we use docker. The project was fine until last friday and today I started my computer (mac mini - macOS Sierra version 10.12.5 (16F73)) with an error. I'm trying to run docker-compose -f dev.yml -f docker-compose.yml up , but when I execute this it returns the following message : db_1 | chmod: changing permissions of ‘/var/lib/postgresql/data’: Operation not permitted . I had deleted all the docker containers and images docker rm $(docker ps -a -q) docker rmi $

PostgreSQL query with dynamic number of columns

不打扰是莪最后的温柔 提交于 2021-01-27 18:29:31
问题 I am trying to find a method to return a record set with a dynamic number of columns. I can write one query that will produce the list of column names I need as such: SELECT DISTINCT name FROM tests WHERE group = 'basic'; This will return a short list like 'poke', 'prod', 'hit', 'drop', etc. Then I want a table produced showing a series of tests where each of those tests were run. Every morning we look at what the developers have been doing and poke and prod at it so each test will be run for

Is the server running on host “localhost” (127.0.0.1) and accepting TCP/IP connections on port 5432?

夙愿已清 提交于 2020-12-26 07:57:28
问题 I tried to deploy my Django project on Heroku but everytime I try 'heroku run python3 manage.py migrate' I get this error: /app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. """) Traceback (most recent call last): File "