postgresql-9.3

Centos 7 environment variables for Postgres service

99封情书 提交于 2020-01-13 10:06:15
问题 Recently I had the problem of starting a postgresql service with custom PGDATA path. It tried to look in the default data directory (/var/lib/pgsql/9.3/data/) which was not initialized and therefore triggered these errors. It appears the problem is that the service starter on Centos 7 strips all the environment variables, including PGDATA. Interesting thread on the issue Is there a way to configure service postgresql-9.3 start to use custom environment variables? Are there configuration files

Centos 7 environment variables for Postgres service

狂风中的少年 提交于 2020-01-13 10:03:13
问题 Recently I had the problem of starting a postgresql service with custom PGDATA path. It tried to look in the default data directory (/var/lib/pgsql/9.3/data/) which was not initialized and therefore triggered these errors. It appears the problem is that the service starter on Centos 7 strips all the environment variables, including PGDATA. Interesting thread on the issue Is there a way to configure service postgresql-9.3 start to use custom environment variables? Are there configuration files

Wrong JDBC driver being used?

做~自己de王妃 提交于 2020-01-11 06:04:31
问题 I have a method that inserts a record into a Postgres DB and returns the identity field generated for said record. The problem is, if I include the Redshift driver in my POM file, that driver is getting used instead of the Postgres driver - and the Redshift driver doesn't allow returning the identity value. The code is: try { Class.forName( "org.postgresql.Driver" ).newInstance(); Connection connection = DriverManager.getConnection( "jdbc:postgresql://localhost:5433/postgres", "postgres",

How to connect to localhost with postgres_fdw?

旧城冷巷雨未停 提交于 2020-01-11 02:36:10
问题 The idea is that I have local database named northwind , and with postgres_fdw I want to connect with another database named test on localhost (remote connection simulation, for situations like when table in my database is updated, do something in other database like save to history etc..). So I opened psql console and type: CREATE SERVER app_db FOREIGN DATA WRAPPER postgres_fdw OPTIONS (dbname 'test', host 'localhost:5432'); As i found in A Look at Foreign Data Wrappers link. Next I also

PostgreSQL tsrange: is it correct for lower_inf('(-infinity,today)'::tsrange) to be false?

∥☆過路亽.° 提交于 2020-01-10 02:10:49
问题 In the course of writing a program that accepts tsrange literals from the user, which are then plugged into various SQL queries, today I was testing some tsranges to see how they are interpreted by PostgreSQL 9.3.5. This one, in particular, behaves strangely: '(-infinity,today)'::tsrange The lower_inf function says the lower bound is not infinite (!) test=> SELECT lower_inf('(-infinity,today)'::tsrange); lower_inf ----------- f (1 row) Yet PostgreSQL reports that this tsrange contains a

get two rows from two different select statements

我是研究僧i 提交于 2020-01-07 02:25:21
问题 I have a table something like below: table_a k | id | results -------------------- a | 1 | mango b | 1 | orange c | 2 | apple d | 2 | banana a | 2 | mango I have two select statements ans there results as below: first select select k, id, results from table_a where id = 1 Results: k | id | results -------------------- a | 1 | mango b | 1 | orange second select select k, id, results from table_a where id = 2 Results: k | id | results -------------------- c | 2 | apple d | 2 | banana a | 2 |

In Postgres, how do I COUNT and WHERE in the same query, then do math on result?

喜夏-厌秋 提交于 2020-01-06 04:37:25
问题 I have a large DB of SALES_ORDERS , that I need to determine the % each SELLING_AGENT had in the ORDER . Learning postgresql, and this is just a sample, of ~500k rows of data. Each ORDER# could be composed of dozens of SALE_ITEM s (but only composed of 'SALE_ITEM_1' and 'SALE_ITEM_2' ). I thought I could try doing a SUM SELECT something like this: SELECT (SUM(sale_item_1)+sum(sale_item_2)) as total_person_sale FROM SALES_ORDER WHERE orderNumber LIKE orderNumber GROUP by SELLING_AGENT But

SELECT multiple rows and columns into a record variable

Deadly 提交于 2020-01-04 12:22:40
问题 In a plpgsql function, how can multiple rows and columns be selected into a record variable? For example, I would like to SELECT multiple instances of two columns ( yearinteger and value ) into a record variable ( yearvalues ). *EDIT - the following code is just part of a longer function, I need the variable yearvalues to contain multiple rows and columns from a table from which I can create further variables from CREATE OR REPLACE FUNCTION fn_function () RETURNS TABLE () AS $$ DECLARE year c

SELECT multiple rows and columns into a record variable

百般思念 提交于 2020-01-04 12:22:17
问题 In a plpgsql function, how can multiple rows and columns be selected into a record variable? For example, I would like to SELECT multiple instances of two columns ( yearinteger and value ) into a record variable ( yearvalues ). *EDIT - the following code is just part of a longer function, I need the variable yearvalues to contain multiple rows and columns from a table from which I can create further variables from CREATE OR REPLACE FUNCTION fn_function () RETURNS TABLE () AS $$ DECLARE year c

Postgres Rules Preventing CTE Queries

痞子三分冷 提交于 2020-01-03 10:46:32
问题 Using Postgres 9.3: I am attempting to automatically populate a table when an insert is performed on another table. This seems like a good use for rules, but after adding the rule to the first table, I am no longer able to perform inserts into the second table using the writable CTE. Here is an example: CREATE TABLE foo ( id INT PRIMARY KEY ); CREATE TABLE bar ( id INT PRIMARY KEY REFERENCES foo ); CREATE RULE insertFoo AS ON INSERT TO foo DO INSERT INTO bar VALUES (NEW.id); WITH a AS (SELECT