postgresql-8.4

Get Column value of previous row in postgres “cannot use window function in UPDATE”

喜夏-厌秋 提交于 2019-12-25 02:50:48
问题 When i is greater than or equal to 3, I am trying to fetch the previous row value of that column and trying to use it in the current row calculation and I have tried using Lag function to do so but was not successful,was getting the error as "cannot use window function in UPDATE". Could some one help me out.Thanks! CREATE OR REPLACE FUNCTION vin_calc() RETURNS text AS $BODY$ DECLARE r res%rowtype; i integer default 0; x text; curs2 CURSOR FOR SELECT * FROM res; BEGIN open curs2; -- FOR r IN

pg upgrade saving database definition taking time

假装没事ソ 提交于 2019-12-24 14:27:08
问题 I am in process of a pg_upgrade from 8.4 to 9.3. I am using this technique: http://momjian.us/main/writings/pgsql/pg_upgrade.pdf The upgrade has been running since 250 hours, and it has been on the step saving database definition since 160 hours. This is the current output of strace last few lines: poll([{fd=5, events=POLLIN|. POLLERR}], 1, -1) = 1 ([{fd=5, revents=POLLIN}]) recvfrom(5, "T\0\0\0F \0\2reltoastrelid\0\0\0\4\353\0\n \0\0\0\32\0"..., 16384, 0, NULL, NULL) = 122 (5, "Q\0\0\0

Restart primary key numbers of existing rows after deleting most of a big table

一笑奈何 提交于 2019-12-24 12:07:32
问题 I am working with a PostgreSQL 8.4.13 database. Recently I had around around 86.5 million records in a table. I deleted almost all of them - only 5000 records are left now. I ran: vacuum full after deleting the rows and that returned disk space to the OS (thx to suggestion from fellow SO member) But I see that my id numbers are still stuck at millions. For ex: id | date_time | event_id | secs_since_1970 | value ---------+-------------------------+----------+-----------------+-----------

Use python to execute line in postgresql

爷,独闯天下 提交于 2019-12-24 00:53:01
问题 I have imported one shapefile named tc_bf25 using qgis, and the following is my python script typed in pyscripter, import sys import psycopg2 conn = psycopg2.connect("dbname = 'routing_template' user = 'postgres' host = 'localhost' password = '****'") cur = conn.cursor() query = """ ALTER TABLE tc_bf25 ADD COLUMN source integer; ALTER TABLE tc_bf25 ADD COLUMN target integer; SELECT assign_vertex_id('tc_bf25', 0.0001, 'the_geom', 'gid') ;""" cur.execute(query) query = """ CREATE OR REPLACE

ERROR: function unnest(integer[]) does not exist in postgresql

ぃ、小莉子 提交于 2019-12-23 20:01:16
问题 SELECT UNNEST(ARRAY[1,2,3,4]) While executing the above query I got the error like this: ERROR: function unnest(integer[]) does not exist in postgresql. I am using PostgreSQL 8.3 and I have installed the _int.sql package in my db for integer array operation. How to resolve this error? 回答1: unnest() is not part of the module intarray , but of standard PostgreSQL. However, you need version 8.4 or later for that. So you can resolve this by upgrading to a more recent version, preferably the

Incrementing a number in a loop in plpgsql

送分小仙女□ 提交于 2019-12-23 07:46:20
问题 I couldn't find this immediately from the examples. I want to increment a variable in a loop, in a function. For instance: DECLARE iterator float4; BEGIN iterator = 1; while iterator < 999 ..... iterator ++; END; How would this be done? I was looking at this document about flow control: http://www.postgresql.org/docs/8.4/static/plpgsql-control-structures.html And none of them seem to be relevant for me, unless these are absolutely the only ways to simulate incrementing a variable. 回答1: To

Postgres SSL error

放肆的年华 提交于 2019-12-23 07:25:42
问题 I'm trying to run a Drupal migration via SSH and drush (a command line shell), copying data from a postgres database to mysql. It works fine for a while (~5 mins or so), but then I get the error: SQLSTATE[HY000]: General error: 7 SSL [error] SYSCALL error: EOF detected The postgres database connection seems to have gone, and I just get errors: SQLSTATE[HY000]: General error: 7 no [error] connection to the server It works fine locally, so I think the problem must be with postgres and running a

How to get the total number of tables in postgresql?

空扰寡人 提交于 2019-12-21 06:48:17
问题 Is there any way by which I can get the total number of tables in a Postgresql database? The postgresql version I'm using is PostgreSQL 8.4.14. 回答1: select count(*) from information_schema.tables; Or if you want to find the number of tables only for a specific schema: select count(*) from information_schema.tables where table_schema = 'public'; 回答2: Just try to search in pg_stat... tables or information_schema you can find there very useful informations about your database. Example: select *

Cannot get log_min_duration_statement to work

冷暖自知 提交于 2019-12-21 02:45:08
问题 I have been googling for more than 2 hours, but I am really stuck with this one. I want PostgreSQL (I am using version 8.4 on Debian) to start logging slow queries only. To that extend I use the following configuration in postgresql.conf : log_destination = 'csvlog' logging_collector = on log_min_messages = log log_min_duration_statement = 1000 log_duration = on log_line_prefix = '%t ' log_statement = 'all' The rest of the configuration is all on default settings (commented out). The logging

currval has not yet been defined this session, how to get multi-session sequences?

人走茶凉 提交于 2019-12-20 11:06:51
问题 My objective is to get a primary key field automatically inserted when inserting new row in the table. How to get a sequence going from session to session in PostgreSQL? doubleemploi@hanbei:/home/yves$ psql -d test Mot de passe : psql (8.4.13) Saisissez « help » pour l''aide. test=> create sequence test001 start 10; CREATE SEQUENCE test=> select currval('test001'); ERREUR: la valeur courante (currval) de la séquence « test00 » n''est pas encore définie dans cette session --- current value not