postgresql

Postgresql query involving three tables

Hi there. I have three tables, say: (1) Name: Groups Columns: gid, groupname (2) Name: Profiles Columns: profileid, profname (3) Name: GroupsProfiles Columns: gid, profileid - corresponds to the columns in the previous tables Now, say I have an array of profileid's, I would like to construct a query which finds the corresponding ...

Refactoring SQL

I must connect from my Rails app to a remote database on a Java application. I have a query like this: find_by_sql("select c_templateid, c_templateinfoid, c_startdate, c_enddate, c_active, campaign, shortcode, prefix, c_descriptivename, c_description, c_templatename from (active_services aser join activity a on aser.c_primaryprefixid ...

PostgreSQL Index Usage Analysis

Is there a tool or method to analyze Postgres, and determine what missing indexes should be created, and which unused indexes should be removed? I have a little experience doing this with the "profiler" tool for SQLServer, but I'm not aware of a similar tool included with Postgres. ...

Choose test database?

I'm trying to run ./manage.py test But it tells me Got an error creating the test database: permission denied to create database Obviously it doesn't have permission to create the database, but I'm on a shared server, so there's not much I can do about that. I can create a new database through the control panel but I don't think...

Django PostgreSQL -- Drop all tables?

Here's how I can do it when MySQL is the backend, cursor.execute('show tables') rows = cursor.fetchall() for row in rows: cursor.execute('drop table %s; ' % row[0]) But how can I do it when postgresql is the backend? ...

Intimation from PSQL trigger

In my program, I am accessing Postgresql database. I don't want to watch database regularly, So When ever the specified table get changed by various actions ( insert, update, delete ), I need to get some signal or message to my program, So I have an idea to use Triggers, But I don't know how to send signal or API or message to my prog...

How can I send some http request from postgresql function or trigger

I need to send data via http protocol (GET or POST request) from the function or trigger. Is it possible? ...

Storing "likes" of an item in a database?

I'm running a Rails app on Postgres through Heroku. I'd like to implement similar to Facebook "likes" on my site for various items, such as user comments. What's the smartest way to store these in my database that will be efficient and fast? The obvious one is just to have a like join table between users and items, something like this:...

Drop all tables in postgresql?

How can I delete all tables in postgresql, working from the command line? I don't want to drop the database itself - just all tables and all the data in them. Thanks. ...

How can I find shp2pgsql?

I'm working on a Debian machine with postgresql installed. I need to find shp2pgsql (a utility that converts shapefiles into SQL, as the name suggests). I've seem suggestions that it's located in the bin directory of postgresql, however I don't know where to find this. I can't locate shp2pgsql through a simple find (probably much too si...

Pgagent install on windows

I've looked at the documentation online but i cant find the 'pgagent.sql' script anywhere on my system. These are the instructions i'm following here. Can i download it from anywhere else? ...

Associating Postgres Connections with Java code

I'm trying to track down leaky connections. (In particular, I'm noticing connections staying open past the closure of the last DataSource, using C3P0 for connection pooling. I suspect a bug but want to ensure I'm not just being stupid first.) Is there a good way to associate open connections from the Postgres view postgres=# select ...

Quoting column names with NHibernate and PostgreSQL

I have started to use NHibernate 3.0 and PostgreSQL for a small project, so far the ride has been a little rough due to the NHibernate site being down and I'm sure this answer is on their website somewhere. I have a database that has these two columns(of course there is more in the real table): int ID String Feature now I'm using a F...

which database to use in Scala (and examples needed)

I am new to Scala. Which database connectivity is best supported in Scala? I am also looking for complete examples to access a database (authenticate, connect, query, extract result) I have a table MyTable with two columns (Value1, Value2) in a database MyDB, which I need to access. I have been thinking of postgresql, so some example...

Username and password for postgresql?

I have installed postgresql in ubuntu. But i need to know the username and password for it? If i have to set it, how do i do that? Thanks! ...

Database flexibility and privacy, hidden structure, software compatibility and 'public' permissions

Hi everyone, I'm one of those that recently decided to migrate from MySQL to PostgreSQL and with it a lot of old habits are being torn apart. However there is functionality from MySQL I would like to preserve in PostgreSQL. So... topics: User should have ability to create tables under a restricted namespace. Tables of one user shoul...

storing occurrences for reporting

What is the best way to store occurrences of an event in a database so you can quickly pull reports on it? ie (total number of occurrences, number of occurrences between date range). right now I have two database tables, one which holds all individual timestamps of the event - so I can query on a date range, and one which holds a tota...

SQL: Select records where ALL joined records satisfy some condition

How can I write an SQL query that returns a record only if ALL of the associated records in a joined table satisfy some condition. For example, if A has many B, I want to SELECT * FROM A WHERE all related B's for a given A have B.some_val > value I know this is probably a pretty basic question, so thanks for any help. Also, if it makes...

Creating Stored Procedures with SQLAlchemy

Hi, I am writing a python script to create the postgres database using SQLAlchemy. I also want to create Stored Procedures by same way. I checked the SQL Alchemy Documentations but was not able to find whether I can create stored procedure using it or not. Is it Possible to do so? any Tutorials/Examples would help. i found some examples...

Postgresql Slow on custom function, php but fast if directly input on psql using text search with gin index

I have 3 tables Person, Names, and Notes. Each person has multiple name and has optional notes. I have full text search on some columns on names and notes (see below), they are working perfectly if the word i search with is in the result set or is in the db, this is for custom function,php, and psql. The problem now is that when the word...