postgresql

Constraint name update in PostgreSQL

Is it possible to change the constraint name in Postgres? I have a PK added with: ALTER TABLE contractor_contractor ADD CONSTRAINT commerce_contractor_pkey PRIMARY KEY(id); And I want to to have different name for it, to be consistent with the rest of the system. Shall I delete the existing PK constraint and create a new one? Or is th...

How do you select Arcs inside a boundary in PostGIS?

I'm searching an answer for this question and all I found on http://postgis.refractions.net/documentation/manual-1.3/ch04.html#id2572194 is SELECT road_id, road_name FROM roads WHERE roads_geom && GeomFromText('POLYGON((...))',-1); should I put the boundary vertexes in this SQL replacing the '...' ? ...

Is there a postgres fuzzy match faster than pg_trgm?

I have a Postgres table with about 5 million records and I want to find the closest match to an input key. I tried using trigrams with the pg_trgm module, but it took roughly 5 seconds per query, which is too slow for my needs. Is there a faster way to do fuzzy match within Postgres? ...

Checking database for NULL boolean value

I have a field in a table that is boolean, a range of records have no value (not true or false). How do I write my SQL statement to find these? I have tried the following SQL statements without success: 1) SELECT * FROM table WHERE field = NULL 2) SELECT * FROM table WHERE field != TRUE AND field != FALSE Any help would be greatly ap...

Unique Constraint with conditions in MYSQL

In postgres we have a constraint defined that essentially allows us to limit the number of entries in a table with a certain value to one. We created this constraint: create unique index list$default$uk on list_group(visitor_uid) where list_type = 'default'; Which means that the unique constraint is only applied when the list_type='de...

PostgreSQL: Select a single-row x amount of times

A single row in a table has a column with an integer value >= 1 and must be selected however many times the column says. So if the column had '2', I'd like the select query to return the single-row 2 times. How can this be accomplished? ...

Sharing transaction scope between threads in python/django? (PostgreSQL)

Is there any way to share same transaction between two threads in a django-based code? The problem is that I have 1.1's TestCase (those that wrap individual tests into transactions) that are intended to test code that is running in a different thread [a sort of asynchronous testing]. So these test create some data that is intended to be...

hibernate mapping for postgresql "timestamp without time zone"?

I'm trying to map java.util.Date to postgresql timestamp without time zone type. I'm using a custom sql-insert statement (because the table is partitioned and postgresql won't return number of rows updated on a normal insert), and I keep getting an error saying the function does not exist. I suspect this is due to a problem mapping the...

how to automatically determine which tables need a vacuum / reindex in postgresql

i've written a maintenance script for our database and would like to run that script on whichever tables most need vacuuming/reindexing during our down time each day. is there any way to determine that within postgres? i would classify tables needing attention like this: tables that need vacuuming tables that need reindexing (we find ...

postgres daily query analysis tool

does anyone know of a postgres view / function / tool that could report on the slowest and most often used slower queries? i think this would be so useful for all sysadmins. thanks! ...

what is a good way to horizontal shard in postgresql

Hey guys what is a good way to horizontal shard in postgresql 1. pgpool 2 2. gridsql which is a better way to use sharding also is it possible to paritition without changing client code It would be great if some one can share a simple tutorial or cookbook example of how to setup and use sharding ...

MySQL - Geo-Spatial Object.

I've been working in Postgis for point in poly's and i have this function: select * from table_name where st_contains(column, st_setsrid(st_makepoint(-92.095109, 46.804100),4326)); the column is a multipoly(((points))) I'm trying to find a way to do a similar exercise with MySQL, and wondered if there were similar functions to do so. ...

Integer out of range on Postgres DB

Simple rails app using Postgres DB, getting 'integer out of range' error when trying to insert 2176968859. Should be an easy fix to the migrations, but I'm not sure. Right now I've got... create_table :targets do |t| t.integer :tid ... ...

Which ruby ORM framework to use in a standalone ruby app?

I would like to use postgresql with foreign keys to define relationships in data so that other platforms/apps would also be able to easily use the same database. Having some kind of ruby DSL to define database schema with migration support would also be great. Which framework would you recommend for me? Is there some kind of framework f...

Qt to Postgresql - Native Driver (QPSQL) Compilation

hello, it's been two days, i've checked every solution online i could find but still no help. here's the thing: my os is Windows 7 RC 64 bit. i have Qt 4.5.1 development environment and PostgreSQL 8.3 development libraries (installed via PostgrePlus one-click installer). so i have some dll's and header files, but no "libpq.lib". so acc...

Why are batch inserts/updates faster? How do batch updates work?

Why are batch inserts faster? Is it because the connection and setup overhead for inserting a single row is the same for a set of rows? What other factors make batch inserts faster? How do batch updates work? Assuming the table has no uniqueness constraints, insert statements don't really have any effect on other insert statements in th...

How can I use an index on a partitioned table in postgresql 8.3.7

I have situation, where running a query that filters by an indexed column in a partitioned table, performs a full table scan. Apparently , this is a known issue in postgresql, and it's explained in detail here. Is there a more elegant way around this other than performing a query on each partition, and then performing a UNION on all of...

PostgreSQL -> Oracle replication

I'm looking for a tool to export data from a PostgreSQL DB to an Oracle data warehouse. I'm really looking for a heterogenous DB replication tool, rather than an export->convert->import solution. Continuent Tungsten Replicator looks like it would do the job, but PostgreSQL support won't be ready for another couple months. Are there an...

XAResource.end called without calling start

Saw this in our logs on an internal test cluster: "java.lang.RuntimeException: Got exception during XAResource.end : org.postgresql.xa.PGXAException: tried to call end without corresponding start call" I've had some previous issues with getting XA transactions running smoothly under Glassfish 2.1 in a clustered deployment. Those arose...

how to emulate "insert ignore" and "on duplicate key update" (sql merge) with postgresql ?

what's the best way to emulate "insert ignore" and "on duplicate key update" with postgresql ? ...