postgresql

Foreign key refering to primary keys across multiple tables?

hi , i have three tables say city,state and road 1) city -> city_id(PK),name 2) state-> Stt_id(PK),name 3) Road-> Edge_id(PK), Admin_id(FK) where Admin_id refers to city_id and Stt_id both. This is done because the tables are too huge. say city_id contains 1,2,3 and Stt_id contains 4,5,6 now if i am inserting 1,2,3,4,5,6 in admin...

How UPDATE and SELECT at the same time

I need to update some rows of the tables and then display these rows. Is there a way to do this with one single query and avoid this 2 query ? : UPDATE table SET foo=1 WHERE boo=2 SELECT * from table WHERE ( foo=1 ) AND ( boo=2 ) ...

postgresql weighted average?

say I have a postgresql table with the following values: id | value ---------- 1 | 4 2 | 8 3 | 100 4 | 5 5 | 7 If I use postgresql to calculate the average, it gives me an average of 24.8 because the high value of 100 has great impact on the calculation. While in fact I would like to find an average somewhere around 6 and elimina...

Postgres error with Sinatra/Haml/DataMapper on Heroku

I'm trying to move a simple Sinatra app over to Heroku. Migration of the Ruby app code and existing MySQL database using Taps went smoothly, but I'm getting the following Postgres error: PostgresError - ERROR: operator does not exist: text = integer LINE 1: ...d_at", "post_id" FROM "comments" WHERE ("post_id" IN (4, 17,... ...

How to get min/max of two integers in Postgres/SQL?

How do I find the maximum (or minimum) of two integers in Postgres/SQL? One of the integers is not a column value. I will give an example scenario: I would like to subtract an integer from a column (in all rows), but the result should not be less than zero. So, to begin with, I have: UPDATE my_table SET my_column = my_column - 10; B...

High-quality ERD generator for PostgresQL under Linux?

Background MySQL Workbench can produce appealing and high-quality ERDs such as: Research What PostgreSQL ERD tools are available that meet the requirements? The following are unsuitable: dbVisualizer - Yellow squares. AquaFold - Yellow squares. SQL Developer - Coloured squares. Dia - Coloured squares. SQL Power Architect - Black a...

postgres syntax question for OR?

The first one below works, but, just wanted to see if there's a better way... If I'm trying to find all records that start with 'C' with either a flag of 2 or a status of 9, do I need to incorporate the 'C' criteria twice? i.e., "SELECT * FROM mytable WHERE name like 'C%' AND flag = 2 OR name like 'C%' AND status = 9" Or, is ther...

postgres counting one record twice if it meets certain criteria

I thought that the query below would naturally do what I explain, but apparently not... My table looks like this: id | name | g | partner | g2 1 | John | M | Sam | M 2 | Devon | M | Mike | M 3 | Kurt | M | Susan | F 4 | Stacy | F | Bob | M 5 | Rosa | F | Rita | F I'm trying to get the id where either the g or g2 value equals 'M'......

Are there any issues with MySQL's i18n(indic language) support ?

Hi All, We're evaluating MySQL and PostgreSQL for building our indic language(using utf-8 encoding) web application which will use MySQL or PostgreSQL. One of my colleagues mentioned that MySQL had issues with i18n. I mostly come from the Oracle world and although I've played a lil with MySQL, I don't know enough to know that there are...

PotgreSQL 2D array to rows

Hello, I am new to PostgreSQL array's. I am trying to a write a procedure to convert array-into-rows, and wanted following output: alphabet | number ---------+---------- A | 10 B | 10 C | 6 D | 9 E | 3 from following: id | alphabe...

Which .NET ORM has best support for PostgresSQL database

I'm interested to find out which ORM has best support for Postgres SQL database? Does any mapper have, both, LINQ support and ability to generate model from database? ...

rake test not copying development postgres db with sequences

I am trying to develop a rails application on postgresql using a sequence to increment a field instead of a default ruby approach based on validates_uniqueness_of. This has proved challenging for a number of reasons: 1. This is a migration of an existing table, not a new table or column 2. Using parameter :default => "nextval('seq')" di...

psql: FATAL: Ident authentication failed for user "postgres"

I have installed PostgreSQL and pgAdminIII on my Ubuntu Karmic box. I am able to use pgAdminIII successfully (i.e. connect/log on), however when I try to login to the server using the same username/pwd on the command line (using psql), I get the error: psql: FATAL: Ident authentication failed for user "postgres" Does anyone now how t...

PHPpgAdmin: How delete rows without using SQL

In PHPmyAdmin I can delete rows without using SQL. Is there a way to do this in PHPpgAdmin ? ...

Heroku: Postgres type operator error after migrating DB from MySQL

This is a follow-up to a question I'd asked earlier which phrased this as more of a programming problem than a database problem. http://stackoverflow.com/questions/2935985/postgres-error-with-sinatra-haml-datamapper-on-heroku I believe the problem has been isolated to the storage of the ID column in Heroku's Postgres database after run...

Postgresql function for last inserted id

I am looking for function in postgres that returns last inserted id into table. In MS SQL there is SCOPE_IDENTITY(). Is something same in PostgreSQL? Please, do not advise use something like this: select max(id) from table ...

How add a Primary Key autoincremented on my existing table ?

I have a table with some datas. Is there a way to add a PK without erase the table ? ...

postgresql multiple insert with select query

Hi guys, i need to perform a insert query for multiple rows whereby the first column is a numeric and identical value and the second values are queried from another table. something like insert into table (33, select col2 from another_table); can this be accomplished with a single statement? ...

Calculate year for end date: PostgreSQL

Background Users can pick dates as shown in the following screen shot: Any starting month/day and ending month/day combinations are valid, such as: Mar 22 to Jun 22 Dec 1 to Feb 28 The second combination is difficult (I call it the "tricky date scenario") because the year for the ending month/day should come after the year for th...

Convert Mysql query in Postgresql query

Is there an utility to convert mysql query in postgresql query ? ...