postgresql-8.3

Postgres function much slower when using input variables

跟風遠走 提交于 2019-12-01 00:20:44
I have a function in Postgres 8.3.5 that selects data from multiple tables and dumps the result in a single table: create or replace function test_function_2(startdate timestamp, enddate timestamp) returns void as $$ begin delete from cl_final_report; INSERT INTO cl_final_report SELECT b.batchkey AS batchnumber, pv.productkey, p.name AS productname, avg(r.value) AS avgchemlean, sum(r.auxvalue) AS totalweight, max(o.time) AS timecompleted FROM result r LEFT JOIN physicalvalue pv ON r.physicalvaluekey = pv.physicalvaluekey LEFT JOIN product p ON pv.productkey = p.productkey LEFT JOIN object o ON

Postgres function much slower when using input variables

柔情痞子 提交于 2019-11-30 19:46:08
问题 I have a function in Postgres 8.3.5 that selects data from multiple tables and dumps the result in a single table: create or replace function test_function_2(startdate timestamp, enddate timestamp) returns void as $$ begin delete from cl_final_report; INSERT INTO cl_final_report SELECT b.batchkey AS batchnumber, pv.productkey, p.name AS productname, avg(r.value) AS avgchemlean, sum(r.auxvalue) AS totalweight, max(o.time) AS timecompleted FROM result r LEFT JOIN physicalvalue pv ON r

How to select more than 1 record per day?

瘦欲@ 提交于 2019-11-28 01:28:44
This is a postgresql problem. PostgreSQL 8.3.3 on i686-redhat-linux-gnu, compiled by GCC gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-9). The table looks like: date_time other_column 2012-11-01 00:00:00 ... 2012-11-02 01:00:00 ... 2012-11-02 02:00:00 ... 2012-11-02 03:00:00 ... 2012-11-02 04:00:00 ... 2012-11-03 05:00:00 ... 2012-11-03 06:00:00 ... 2012-11-05 00:00:00 ... 2012-11-07 00:00:00 ... 2012-11-07 00:00:00 ... ... I want to select at most 3 records per day from a specific date range. For example, I want to select at most 3 records from 2012-11-02 to 2012-11-05. The expected result would be

How to declare a variable in a PostgreSQL query

ぐ巨炮叔叔 提交于 2019-11-26 01:29:07
问题 How do I declare a variable for use in a PostgreSQL 8.3 query? In MS SQL Server I can do this: DECLARE @myvar INT SET @myvar = 5 SELECT * FROM somewhere WHERE something = @myvar How do I do the same in PostgreSQL? According to the documentation variables are declared simply as \"name type;\", but this gives me a syntax error: myvar INTEGER; Could someone give me an example of the correct syntax? 回答1: There is no such feature in PostgreSQL. You can do it only in pl/PgSQL (or other pl/*), but