postgresql

Postgres UPSERT (INSERT or UPDATE) only if value is different

I'm updating a Postgres 8.4 database (from C# code) and the basic task is simple enough: either UPDATE an existing row or INSERT a new one if one doesn't exist yet. Normally I would do this: UPDATE my_table SET value1 = :newvalue1, ..., updated_time = now(), updated_username = 'evgeny' WHERE criteria1 = :criteria1 AND criteria2 = :crite...

Converting String (in Eastern Daylight Time format) to Date in SQL

Please I need help on how to convert this string [ Fri Jun 19 10:45:39 EDT 2009 ] that is in EDT date format back to Date in SQL (Am using Postgres). I want to be able to have something like this 19-06-2009 Thanks ...

Connect to PostgreSQL asp

Dear All, Can you help me to solve how to connect to PostgreSQL by using asp below : <%@ LANGUAGE=VBScript%> <% Set Baglanti = Server.CreateObject("ADODB.Connection") DbDriver ="driver={PostgreSQL}; server=localhost; PORT=5432; database=everyday; uid=postgres; pwd=123" Baglanti.Open DbDriver response.write("Test Success") %> And Th...

PostgreSQL query & table optimization

Hi All, I have a table I'm working on that has around 3 million tuples. It doesn't change too often (a few updates or inserts per week) and is read a lot. (Please don't comment on the varchar of length 1. I know, I know). Column | Type | Modifiers -------------+--------...

Where Postgres database files are saved in ubuntu?

How can I find where Postgres 8.x database files are saved in Ubuntu 10.04 file system? ...

Proper way to call a database function from Django?

Hi, i'm triyng to make a full text search with postgresql and django So I've created a function search_client(text) which returns a list of clients. To call it from the DB i use something like this: SELECT * FROM search_client('something') and i'm not really sure how to call it from django. i know i could do something like cursor = c...

Indexing Null Values in PostgreSQL

I have a query of the form: select m.id from mytable m left outer join othertable o on o.m_id = m.id and o.col1 is not null and o.col2 is not null and o.col3 is not null where o.id is null The query returns a few hundred records, although the tables have millions of rows, and it takes forever to run (around an hour). When I check...

Proper way to retrive sequence int after entity save with hibernate and postgresql?

... right now, this is how I'm getting the id from save(entity) method: Serializable save = hibernateTemplate.save(article); return Integer.valueOf(save.toString()); Being a complete noob to hibernate, I just wonder if this is the proper way to do it? I'll appreciate any advice. Grateful in advance :-) ...

How to define an operator alias in PostgreSQL?

Is there an easy way to define an operator alias for the = operator in PostgreSQL? How is that solved for the != and <> operator? Only the <> operator seems to be in pg_operators. Is the != operator hard-coded? This is needed for an application which uses a self-defined operator. In most environments this operator should act like a =, ...

Block SELECT until results available

I'm trying to write a PHP script for 'long-polling', returning data when new rows are added to a (Postgres) database table. Is there any way to get a SELECT query to return only when it would return results, blocking otherwise? Or should I use another signaling mechanism, outside of the database? ...

PSQL row update using NEW statment

Hello, since it is possible to do: INSERT INTO some_table VALUES (NEW.*) in pl/pgsql can we do something similar but for UPDATE clause using NEW ? I mean i want to update some row using values from NEW object. Thanks in advance. ...

How to get ERD diagram for an existing Database?

i have a DB in PostgreSQl i want to get its erd how can i do so thanx in advance ...

postgresql full text search query to django ORM

Hi, I was following the documentation on FullTextSearch in postgresql. I've created a tsvector column and added the information i needed, and finally i've created an index. Now, to do the search i have to execute a query like this SELECT *, ts_rank_cd(textsearchable_index_col, query) AS rank FROM client, plainto_tsquery('famille age')...

Databases allow bad foreign keys from Rails Fixtures

Hi, I am using Rails Fixtures to load some test data to my database and accidentally I introduced a foreign key out of range. To my surprise, the database accepted it despite having referential integrity constraints (that work). I tried with PostgreSQL and with MySQL InnoDB and both allowed. Example: Having in the database "Flavour...

Django: What are the best practices to migrate a project from sqlite to PosgreSQL

I need to migrate a complex project from sqlite to PostgreSQL. A lot of people seems to have problem with foreign keys, data truncature and so on... Is there a full automated utility ? Do I need to check some data or schema before the migration ? Edit : I tried django-command-extensions DumpScript but it doesn't run on my 2GB RAM PC...

Any spatial index support in the standard PostgreSQL installation?

I'm new to PostgreSQL. For the default install of PostgreSQL (no extension like PostGIS), if there's geographic fields defined in my table, then what kinds of index does PostgreSQL support? I didn't find any information on the spatial index in the manual. ...

field appears null or empty sting but I can not select it

select * from ss.mailer_data where id = 249122 and address_3 like'%%' will not hit on address_3. I've tried changing the last line to and address_3 is null and address_3 = '' and address_3 = ' ' I tried using char_length, ascii functions and they return nothing for that filed value. Anyone have any ideas? ...

SQL select by a given time past the hour

Simple question (I hope): I have a simple two column table, a measurement and the time the measurement was taken. How can I select all of the measurements taken at 30 minutes past the hour? Although these measurements are supposed to be made at a regular interval (every 15 minutes in this case), there are often gaps in the data. Sampl...

How should I configure Amazon EC2 to perform parallelizable data-intensive calculations?

I have a computational intensive project that is highly parallelizable: basically, I have a function that I need to run on each observation in a large table (Postgresql). The function itself is a stored python procedure. Amazon EC2 seems like an excellent fit for the project. My question is this: Should I make a custom image (AMI)...

Simplify complex union all in PostgreSQL

I have very complex query in PostgreSQL that unions several tables, that all have common set of fields we want to union. currently we're pregenerating this query. I have seen solution to this using UNPIVOT and I'm wondering if it's possible to do this in PostgreSQL flavour of SQL. What I have is something like SELECT a,b,c FROM a UNION...