postgresql-9.3

Postgres Rules Preventing CTE Queries

大兔子大兔子 提交于 2020-01-03 10:46:29
问题 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

postgresql 9.3 log slow queries

断了今生、忘了曾经 提交于 2020-01-02 05:29:12
问题 I am using Rails application with Postgres 9.3 database and doing some performance fixes. I would like to know how to find out slowest queries in log files. let say queries taking more then 30ms. 回答1: In postgresql.conf you should uncomment line #log_min_duration_statement = -1 and change its value to 30. This way queries longer than 30ms will be logged 来源: https://stackoverflow.com/questions/41746897/postgresql-9-3-log-slow-queries

Querying count on daily basis with date constraints over multiple weeks

こ雲淡風輕ζ 提交于 2019-12-30 05:14:28
问题 I'm trying to find the # active users over time on a daily basis. A user is active when he has made more than 10 requests per week for 4 consecutive weeks . ie. On Oct 31, 2014, a user is active if he has made more than 10 requests in total per week between: Oct 24-Oct 30, 2014 AND Oct 17-Oct 23, 2014 AND Oct 10-Oct 16, 2014 AND Oct 3-Oct 9, 2014 I have a table of requests : CREATE TABLE requests ( id text PRIMARY KEY, -- id of the request amount bigint, -- sum of requests made by accounts_id

PostgreSQL epoch time conversion

三世轮回 提交于 2019-12-25 14:13:23
问题 I am using the postgresSQL function to_timestamp(double precision) to convert from epoch time to normal timestamp but I am facing a problem where the timestamp is incorrect SELECT to_timestamp(1428058548491); produces "47223-05-17 12:08:11.000064+02" while it should be 4/3/2015, 12:55:48 PM GMT+2:00 DST SELCT to_timestamp(1428058557697); produces "47223-05-17 14:41:36.999936+02" while it should be 4/3/2015, 12:55:57 as can be seen the dates have been converted totally incorrect 回答1: As was

How to rewrite a SELECT … CROSS JOIN LATERAL … statement for older PostgreSQL versions?

ぃ、小莉子 提交于 2019-12-25 13:13:55
问题 I am faced with a query similar to this: SELECT * FROM invoicable_interval i, LATERAL partition_into_months(i.start_date, i.stop_or_current_date) p; ... where partition_into_months is defined similar to this: CREATE FUNCTION partition_into_months(start_date DATE, stop_date DATE) RETURNS TABLE (start_date DATE, stop_date DATE, days INT) AS $$ ... $$ LANGUAGE sql IMMUTABLE; So I am doing a cross join with a variable interval for the secondary table, hence the (redundant) keyword LATERAL. This

How to rewrite a SELECT … CROSS JOIN LATERAL … statement for older PostgreSQL versions?

五迷三道 提交于 2019-12-25 13:12:41
问题 I am faced with a query similar to this: SELECT * FROM invoicable_interval i, LATERAL partition_into_months(i.start_date, i.stop_or_current_date) p; ... where partition_into_months is defined similar to this: CREATE FUNCTION partition_into_months(start_date DATE, stop_date DATE) RETURNS TABLE (start_date DATE, stop_date DATE, days INT) AS $$ ... $$ LANGUAGE sql IMMUTABLE; So I am doing a cross join with a variable interval for the secondary table, hence the (redundant) keyword LATERAL. This

How to rewrite a SELECT … CROSS JOIN LATERAL … statement for older PostgreSQL versions?

寵の児 提交于 2019-12-25 13:12:13
问题 I am faced with a query similar to this: SELECT * FROM invoicable_interval i, LATERAL partition_into_months(i.start_date, i.stop_or_current_date) p; ... where partition_into_months is defined similar to this: CREATE FUNCTION partition_into_months(start_date DATE, stop_date DATE) RETURNS TABLE (start_date DATE, stop_date DATE, days INT) AS $$ ... $$ LANGUAGE sql IMMUTABLE; So I am doing a cross join with a variable interval for the secondary table, hence the (redundant) keyword LATERAL. This

Empty file after download

橙三吉。 提交于 2019-12-25 06:24:19
问题 I tried to implement file store in PostgreSQL using OID: public void upload() throws SQLException, GSSException { if (file != null) { try { InputStream inputStream = file.getInputStream(); Connection conn = ds.getConnection(); PreparedStatement ps = null; boolean committed = false; try { conn.setAutoCommit(false); ps = conn.prepareStatement("INSERT INTO PROCEDURE_FILES (ID, PROCEDURE_ID, FILE_NAME, FILE) " + " VALUES (?, ?, ?, ?)"); ps.setInt(1, obj.number); ps.setInt(2, obj.number); ps

Syntax error at or near ;

故事扮演 提交于 2019-12-25 04:26:40
问题 I have many trigger functions, and for some there is a strange error: " Syntax error at or near ; " Here is my code: CREATE OR REPLACE FUNCTION zajisti_vyplnenost() RETURNS trigger AS $$ BEGIN IF NEW.typ_vztahu != 1 THEN RETURN NEW; END IF; IF NEW.nad.typ_sj = 1 THEN IF NEW.nad.vrstva.vypln = true THEN ELSE RAISE EXCEPTION 'Totožné stratigrafické jednotky musejí být stejného typu!'; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql; CREATE TRIGGER zajisti_vyplnenost BEFORE INSERT OR UPDATE ON s

glassfish 4.0 admin console connection pool ping fails

穿精又带淫゛_ 提交于 2019-12-25 04:19:58
问题 With this error: Ping Connection Pool failed for postgreSQLPool. Connection could not be allocated because: FATAL: database "/localhost:5432/mydatabase" does not exist Pool configuration is as follows: Pool Name: postgreSQLPool Resource Type: javax.sql.ConnectionPoolDataSource Datasource Classname: org.postgresql.ds.PGConnectionPoolDataSource portNumber: 5432 databaseName: myDatabase datasourceName: myDatabaseDS roleName: myRole networkProtocol: jdbc:postgresql: serverName: //localhost user: