postgresql

Firing Postgres triggers on different table columns

CONTENT_TABLE id | author | timestamp | title | description ----+-----------------+-----------+----------------+---------------------- (0 rows) SEARCH_TABLE id | content_type_id | object_id | tsvector_title | tsvector_description ----+-----------------+-----------+----------------+---------------------- (0 rows) I have to fire a tri...

Postgres update rule returning number of rows affected

I have a view table which is a union of two separate tables (say Table _A and Table _B). I need to be able to update a row in the view table, and it seems the way to do this was through a 'view rule'. All entries in the view table have separate id's, so an id that exists in table _A won't exist in table _B. I created the following rul...

What should a Django user know when moving from MySQL to PostgreSQL?

Most of my experience with Django thus far has been with MySQL and mysqldb. For a new app I'm writing, I'm dipping my toe in the PostgreSQL water, now that I have seen the light. While writing a data import script, I stumbled upon an issue with the default autocommit behavior. I would guess there are other "gotchas" that might crop up...

PostgreSQL + PostGis + GDAL/Proj/Geos Amazon EC2 image

Does anybody have/know any amazon EC2 AMI that has PostgreSQL/PostGIS/GDAL/Proj/Geos installed? ...

Is SQL server the best DB for Storing and comparing images in database for a small ecommerce application.

I have been trying to create a small e-commerce web based application using MS Dot Net framework. The application will let the user allow to store the image of their product that they want to sell or purchase, then they will have the option to upload the image of a particular product and compare that image with the similar images in the ...

How to return a record from function, executed by INSERT/UPDATE rule (trigger)?

Do the following scheme for my database: create sequence data_sequence; create table data_table { id integer primary key; field varchar(100); }; create view data_view as select id, field from data_table; create function data_insert(_new data_view) returns data_view as $$declare _id integer; _result data_view%rowtype; ...

database row/ record pointers

Hi I don't know the correct words for what I'm trying to find out about and as such having a hard time googling. I want to know whether its possible with databases (technology independent but would be interested to hear whether its possible with Oracle, MySQL and Postgres) to point to specific rows instead of executing my query again. ...

"date_part('epoch', now() at time zone 'UTC')" not the same time as "now() at time zone 'UTC'" in postgresql

I'm writing a web based front end to a database (PHP/Postgresql) in which I need to store various dates/times. The times are meant to be always be entered on the client side in the local time, and displayed in the local time too. For storage purposes, I store all dates/times as integers (UNIX timestamps) and normalised to UTC. One partic...

PostgreSQL + Rails citext

I am trying to move to heroku which uses PostgreSQL 8.4 which has a citext column type which is nice since the app was written for MySQL. Is there any way to use :citext with rails (so that if the migrations are run on MySQL the citext would just use string/text? I found this ticket, but it seems like it isn't going to be a part of rai...

How to optimize this SQL query for a rectangular region?

I'm trying to optimize the following query, but it's not clear to me what index or indexes would be best. I'm storing tiles in a two-dimensional plane and querying for rectangular regions of that plane. The table has, for the purposes of this question, the following columns: id: a primary key integer world_id: an integer foreign key wh...

SQL indexing on varchar

I have a table whose columns are varchar(50) and a float. I need to (very quickly) look get the float associated with a given string. Even with indexing, this is rather slow. I know, however, that each string is associated with an integer, which I know at the time of lookup, so that each string maps to a unique integer, but each integer...

How to write my own global lock / unlock functions for PostgreSQL

I have postgresql (in perlu) function getTravelTime(integer, timestamp), which tries to select data for specified ID and timestamp. If there are no data or if data is old, it downloads them from external server (downloading time ~300ms). Multiple process use this database and this function. There is an error when two process do not fin...

Way to view Rails Migration output

Is there an easy way to see the actual SQL generated by a rails migration? I have a situation where a migration to change a column type worked on my local development machine by partially failed on the production server. My postgreSQL versions are different between local and production (7 on production, 8 on local) so I'm hoping by lo...

Strange problem with ActiveRecord summing grouped values

I'm working on a timesheet system (thrilling, I know) and am having difficulty using ActiveRecord to total the time spent working on particular projects on each day. I have a TimeBooking model: t.references :assignment, :null => false # (Combination of employee and project) t.date :date, :null => false t.integer :durat...

How to save an order (permutation) in an sql db

I have a tree structure in an sql table like so: CREATE TABLE containers ( container_id serial NOT NULL PRIMARY KEY, parent integer REFERENCES containers (container_id)) Now i want to define an ordering between nodes with the same parent. I Have thought of adding a node_index column, to ORDER BY, but that seem suboptimal, since that...

Security benefits from a second opinion, are there flaws in my plan to hash & salt user passwords via postgresql?

Here is my plan, and goals: Overall Goals: Security with a certain amount of simplicity & database-to-database transferrability, 'cause I'm no expert and could mess it up and I don't want to have to ask a lot of users to reset their passwords. Easy to wipe the passwords for publishing a "wiped" databased of test data. (e.g. I'd like t...

PostgreSQL subselect problem

When I try to do the select statement, I always get the following error: ERROR: more than one row returned by a subquery used as an expression Only if there's only one result, it works. Why and how to fix? SELECT name from person p where id = ( select prs from leader where age(leader.lastcourse) > '1 year'); ...

I don't find the sql request

Hi everybody, Here it's my problem I've a list of the following measure : src1 dst2 24th december 2009 src1 dst3 22th december 2009 src1 dst2 18th december 2009 I would like to have just the latest measures with a sql request -> 2 first lines in my case because the pairs(src and dst) aren't the same. I try to use DISTIN...

Order by in Postgresql to sort IP address ?

Hi, I've another question I wish to sort a list of IP address. Are there any functions in Postgresql to use with the order by like INET_ATON in MySql ? My current IP is on string format. Thx. Narglix ...

How can I hash passwords in postgresql?

I need to hash some passwords with salt on postgresql, and I haven't been able to find any relevant documentation on how to get that done. So how can I hash passwords (with some salts) in postgresql? ...