postgresql

Postgres turn on log_statement programmatically

I want to turn on logging of all SQL statements that modify the database. I could get that on my own machine by setting the log_statement flag in the configuration file, but it needs to be enabled on the user's machine. How do you enable it from program code? (I'm using Python with psycopg2 if it matters.) ...

psycopg2 can't find my python26 installation

I believe it's because I installed python using SciPy, so apparently it's not in the registry where the psycopg2 installer is looking. Anyway to fix this without installing python26 over the existing install? I'm not sure if that will corrupt it. EDIT: My PYTHONPATH looks like the following: 'C:\\Python26\\scripts', 'C:\\Python26\\lib\...

Error using to_char // to_timestamp

Hello, I have a database in PostgreSQL and I'm developing an application in PHP using this database. The problem is that when I execute the following query I get a nice result in phpPgAdmin but in my PHP application I get an error. The query: SELECT t.t_name, t.t_firstname FROM teachers AS t WHERE t.id_teacher IN ( SE...

PostgreSQL equivalent to "SET SESSION query_cache_type = ON/OFF";

I just wanted to know what's the equivalent query in PostgreSQL to MySQL's SET SESSION query_cache_type = ON SET SESSION query_cache_type = OFF ...

How to pass in password to pg_dump?

I'm trying to create a cronjob to back up my database every night before something catastrophic happens. It looks like this command should meet my needs: 0 3 * * * pg_dump dbname | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz Except after running that, it expects me to type in a password. I can't do that if I run it from cron. How can...

What is the best PHP framework for building a website around a heavily relational PostgreSQL database?

First of all, the framework of choice needs to have excellent support for PostgreSQL. I don't care about MySQL because it doesn't have half of the features the application I will be porting requires. (And when I say excellent support, I mean that their approach to database drivers has not been solely trained in MySQL). The ideal framew...

postgres stored procedure problem

Hi all, Ich have a problem in postgres function: CREATE OR REPLACE FUNCTION getVar(id bigint) RETURNS TABLE (repoid bigint, suf VARCHAR, nam VARCHAR) AS $$ declare rec record; BEGIN FOR rec IN (WITH RECURSIVE children(repoobjectid,variant_of_object_fk, suffix, variantname) AS ...

In postgresql return result of a function in a rule when performing INSERT INTO RETURNING

I have a View that has several fields. When i INSERT INTO a view I run a function based on INSERT parametrs. The function returns a value. How can I retrieve The value from rule? INSERT RETURNING Gives me: ERROR: cannot perform INSERT RETURNING on relation "full_subntes" HINT: You need an unconditional ON INSERT DO INSTEAD rule wi...

PostgreSQL Invalid Value for Parameter Warning

In PostgreSQL 8.4.3, I get this error when logging on to one of my databases (adus): WARNING: invalid value for parameter "default_text_search_config": "tsc_markets" which makes sense since executing the command \dF does not list any such configuration (and only lists the defaults). However, when I ask psql to show me the current va...

Why is postgresql update query so slow sometimes, even with index

i have a simple update query (foo column type is BOOLEAN (default false)): update tablename set foo = true where id = 234; which "id" is set to (primary) key, and if i run "explain analyze" i got: Index Cond: (id = 234) Total runtime: 0.358 ms but still, i have plenty of unexplained queries at slow log (pgfouine), which took more t...

Rails: three most recent comments with unique users

what would I put in the named scope :by_unique_users so that I can do Comment.recent.by_unique_users.limit(3), and only get one comment per user? class User has_many :comments end class Comment belongs_to :user named_scope :recent, :order => 'comments.created_at DESC' named_scope :limit, lambda { |limit| {:limit => limit}} na...

Basic SQL Select in Postgresql fails

I am doing a select * on a postgresql table, and everything looks good. But if I do: SELECT Name from People It says: ERROR: column People.Name does not exist SQL state: 42703 Character: 8 But the name column shows up during select *. I've tried: SELECT People.Name from People as well, with the same result. Am I missing somethi...

Generating Running Sum of Ratings in SQL

I have a rating table. It boils down to: rating_value created +2 april 3rd -5 april 20th So, every time someone gets rated, I track that rating event in the database. I want to generate a rating history/time graph where the rating is the sum of all ratings up to that point in time on a graph. I.E. A person's r...

Distribute budget over for ranked components in SQL

Assume I have a budget of $10 (any integer) and I want to distribute it over records which have rank field with varying needs. Example: rank Req. Fulfilled? 1 $3 Y 2 $4 Y 3 $2 Y 4 $3 N Those ranks from 1 to 3 should be fulfilled because they are within b...

Postgres trigger help

Hi, Iam new to postgres,i wrote a trigger which is not working kindly look into it and suggest what went wrong. In this trigger my intention was to update the order column if the new record was inserted in between the order already existed. CREATE OR REPLACE FUNCTION client_template.check_attribute_order() RETURNS trigger AS $BODY$ DE...

Random Page Cost and Planning

A query (see below) that extracts climate data from weather stations within a given radius of a city using the dates for which those weather stations actually have data. The query uses the table's only index, rather effectively: CREATE UNIQUE INDEX measurement_001_stc_idx ON climate.measurement_001 USING btree (station_id, taken, ...

Simple aggregating query very slow in PostgreSql, any way to improve?

HI I have a table which holds files and their types such as CREATE TABLE files ( id SERIAL PRIMARY KEY, name VARCHAR(255), filetype VARCHAR(255), ... ); and another table for holding file properties such as CREATE TABLE properties ( id SERIAL PRIMARY KEY, file_id INTEGER CONS...

PostgreSQL character varying length limit

I am using character varying data type in PostgreSQL. I was not able to find this information in PostgreSQL manual. What is max limit of characters in character varying data type? ...

Python and Postgresql

Hi all, if you wanted to manipulate the data in a table in a postgresql database using some python (maybe running a little analysis on the result set using scipy) and then wanted to export that data back into another table in the same database, how would you go about the implementation? Is the only/best way to do this to simply run the...

PostgreSQL - How to convert seconds in a numeric field to HH:MM:SS

I'm new to PostgreSQL (I have been using MS SQL for many years) and need to convert a numeric column which contains a time in seconds to HH:MM:SS format. I have Googled and found that to_char(interval '1000s', 'HH24:MI:SS') works so I am attempting to use this with my field name: to_char(fieldname, 'HH24:MI:SS') gives an error cannot u...