postgresql

SQL request to find the n last records of each one of a user's friends

Hi, I have a User model which has friends (User.friends with a user_id/friend_id join table called followings). Each user has events (the events table has a user_id column). For an activity feed, I want to get an array with the last 20 events of the friends of the user. Right now I'm calling the last 20 events for each friend, sorting ...

Measuring total CPU time of a program that uses precompiled libraries (C++, Linux)

Hi everyone, I am currently stumbled into this problem and I'd love to hear some suggestions from you. I have a C++ program that uses a precompiled library to make some queries to PostgreSQL database. Now the problem is I want to find out the total (combined) cpu time it takes to do all routines described in the source code of the prog...

How do I create an index in PostgreSQL based on lowercase only?

How would I set up an index based on lower case only? Even though the actual field contains both upper and lower case letters. Also, can I run a query and have only the lower case index value returned? Thanks-- ...

Rails/Postgresql: getting "password authentication failed for user postgres" error on production server

Rails 3.0.1/Ruby 1.9.2 with Postgresql 8.4 work great on my home machine, however I'm getting this error on a Ubuntu server. I'm sure that the password I upplied in the database.yml file is correct, because when I log in as "postgres", it lets me in: sudo -u postgres psql template1 Password: psql (8.4.5) I have edited the "pg...

Export to CSV and Compress with GZIP in postgres

Hello, I need to export a big table to csv file and compress it. I can export it using COPY command from postgres like - COPY foo_table to '/tmp/foo_table.csv' delimiters',' CSV HEADER; And then can compress it using gzip like - gzip -c foo_table.csv > foo.gz The problem with this approach is, I need to create this int...

Should Class Structure Mirror DB Structure?

Sorry if this is noobish, but I'm new to development and am teaching myself. Let's say I've got 2 tables BioData Name (string) Birthdate (datetime) BloodType (int) BloodTypes BloodTypeId (int) BloodTypeName (string) When I pull a record, i'll use a join, so that I pull the BloodTypeName and not just ID. Now, should my class stru...

Equivalent of FOUND_ROWS() function in Postgresql

I am doing some standard paging in my application, returning 20 rows from the database at a time using PostgreSQL's standard OFFSET and LIMIT keywords. For instance, to get page 1: SELECT stuff FROM table WHERE condition ORDER BY stuff OFFSET 0 LIMIT 20 It is a requirement of the application that we also show to the user the total nu...

Migrating from MySQL > PostgreSQL (PHP/Doctrine)

I have a system with 25 tables. I ran a utility to basically get all my data to a postgres table, but now I'm getting a lot of errors in the front end of my website after I switched the db driver. How can I go about completely migrating my current PHP/Doctrine MySQL system to work with Postgres? ...

How to dump data from mysql database to postgresql database?

I have done the depot application using mysql... Now i am in need to use postgres... So i need to dump data from mysql database "depot_development" to postgres database "depot_develop"... ...

Using the "pg" gem with Rails 3 ... why am I getting this error in Netbeans when I do a "bundle install"???

At my wits end with this! My current set up is: - Ruby 1.9.2 - Rails 3.0.1 - pg (0.9.0) My $PATH right now looks like this: /Users/fjones/.rvm/gems/ruby-1.9.2-p0/bin:/Users/fjones/.rvm/gems/ruby-1.9.2-p0@global/bin:/Users/fjones/.rvm/rubies/ruby-1.9.2-p0/bin:/Users/fjones/.rvm/bin:ARCHFLAGS=-arch x86_64:/opt/local/bin:/opt/local...

Discrete Derivative in SQL

I've got sensor data in a table in the form: Time Value 10 100 20 200 36 330 46 440 I'd like to pull the change in values for each time period. Ideally, I'd like to get: Starttime Endtime Change 10 20 100 20 36 130 36 46 110 My SQL skills are pretty rudim...

Error restoring postgres database backup

Hi everyone. I've setup a system to automatically download and store a db dump from my Heroku deployed rails app. Everything is working great but when I download the dump and restore it to my local postgres server then try and run my local app off that restored database I get this error ActiveRecord::StatementInvalid in HomeController#i...

move a function to another schema

it is possible to move a table from one schema to another: update table my_table set schema different_schema; however, i cannot find the equivalent feature for moving a function from one schema to another. how can i do this? (version 8.3+) ...

Postgres function(via npgsql) call to ExecuteNonQuery returns -1 as result for rows affected

I have a simple function that just inserts the parameter values provided to it into columns in a table. When I run the function via the ExecuteNonQuery() method on the command object I always get -1, even if the insert took place. If i run the same query as a Text command it gives be the correct result of 1. I'm new to postgresql/npgs...

Building a massively scalable and secure social network on top of Eureka Streams?

http://en.wikipedia.org/wiki/Eureka_Streams http://www.eurekastreams.org/ Eureka Streams uses a shared nothing architecture. It uses Memcached, Apache Maven, PostgreSQL and Hibernate. It uses Shindig for OpenSocial. It makes use of Java Message Service (JMS), Java Persistence API (JPA), Lucene and Google Web Toolkit (GWT). It ma...

How do I implement full text search in Chinese on PostgreSQL?

The title says it all. This question has been asked before: http://stackoverflow.com/questions/2495997/postgresql-full-text-search-in-postgresql-japanese-chinese-arabic but there are no answers for Chinese as far as I can see. I took a look at the OpenOffice wiki, and it doesn't have a dictionary for Chinese. Edit: As we are already ...

eliminate duplicate array values in postgres

I have an array of type bigint,how con i remove the duplicate values in that array. ex: array[1234,5343,6353,1234,1234] I should get array[1234,5343,6353,] I tested out the example SELECT uniq(sort('{1,2,3,2,1}'::int[])) in the postgres manual but it is not working. ...

(Fluent)NHibernate and PostgreSQL 9

We currently have a FNH - MySQL 5.1 DAL in our .Net LOB app. Some recent tests we did showed that PostgreSQL does perform faster than MySQL, and we believe the table partitioning feature in PostgreSQL will be very important with a table in our database we foresee to grow into 100 million rows and more (in production). Has anyone upgrad...

Shebang for psql

Hello I'm trying to write Postgresql script(s) but having a problem with shebang line #! /usr/bin/psql [ psql_args_here ] -f select now(); This gives me error as if I just entered psql without any arguments in command line. How do I do it right? Thanks. ...

Doing pg_dump while still many active transaction.

Dear fellow developers, As subjects, what will happen to the backup file meanwhile there is still many active transaction to our database. Does it export realtime or just partially backups ? thanks in advance for any lights. ...