postgresql

Getting the last element of a Postgres array, declaratively

How to obtain the last element of the array in Postgres? I need to do it declaratively as I want to use it as a ORDER BY criteria. I wouldn't want to create a special PGSQL function for it, the less changes to the database the better in this case. In fact, what I want to do is to sort by the last word of a specific column containing mu...

PostgreSQL: How do I set the search_path at the user level?

I want to set the default search_path to something other than the "public" schema. But I only want to do this for a particular user. How can I accomplish this? ...

SQL return ORDER BY result as an array

Is it possible to return groups as an associative array? I'd like to know if a pure SQL solution is possible. Note that I release that I could be making things more complex unnecessarily but this is mainly to give me an idea of the power of SQL. My problem: I have a list of words in the database that should be sorted alphabetically and ...

How do I use ST_Contains in following case?

I have two tables. First with points, and second with polygons. I need to find out which points are in required polygon according to the attribute gid. Using query: SELECT table1.* FROM table1, table2 WHERE table2.gid=1 AND ST_Contains(table2.geom2, table1.geom1); What I get is empty table (only columns without data)... Tnx ...

Can not find Driver when using generic database bundle

I have a project that is build up from several OSGi bundles. One of them is a generic Database bundle that defines a DataSource that can be used throughout the project. The spring bean definition of this service is: <osgi:service interface="javax.sql.DataSource"> <bean class="org.postgresql.ds.PGPoolingDataSource"> <property...

PostgreSQL-Server doesn´t start

Hello, I would like to use PostgreSQL locally on my computer and have installed it. I use Windows 7. I am not able to start the PostgreSQL-Server. When using the "Start Server"-program, I get the following output in the dos command window: Start DoCmd(net start postgresql-8.4)... System error 2 (my translation) System cannot find the...

Postgres' text column doesn't like my zlib compressed data.

Is there a better data type to be using to store a zlib compressed string in Postgresql? ...

Debugging SQL in PGAdmin3 when sql contains variables

In SQL Server I could copy sql code out of an application and paste it into SSMS, declare & assign vars that exist in the sql and run.. yay great debugging scenario. e.g. (please note I am rusty and syntax may be incorrect) declare @x as varchar(10) set @x = 'abc' select * from sometable where somefield = @x I want to do something si...

relating data stored in NoSQL DB to data stored in SQL DB

Whats the best way to use a SQL DB along side a NoSQL DB? I want to keep my users and other data in postgres but have some data that would be better suited for a NoSQL DB like redis. I see a lot of talk about switching to NoSQL but little talk on integrating it with existing systems. I think it would be foolish to throw the baby ou...

Importing fixtures with foreign keys and SQLAlchemy?

I've been experimenting with using fixture to load test data sets into my Pylons / PostgreSQL app. This works great except that it fails to properly create foreign keys if they reference an auto increment id field. My fixture looks like this: class AuthorsData(DataSet): class frank_herbert: first_name = "Frank" la...

trigger didn't fired by using copy from command

I have populate a table using the copy from command which in turn will create record in summary table. While after the copy command successfully run, I can not see any record in the summary table. Anyone can shed some light on me? Pls find the table as well as the store procedure below:- CREATE TABLE apache_log ( log_name chara...

How many of you have gone from MySQL to Postgresql? Was it worth it?

I'm thinking about moving from MySQL to Postgres for Rails development and I just want to hear what other developers that made the move have to say about it. I'm looking for personal experiences, not a Mysql v Postgres shootout, just the pros and cons that you yourself have arrived at. Stuff that folks might not necessarily think. Fe...

how to change postgresql listening port in windows?

hi guys, How do i change the default listening port 5432 of postgresql to another number? Another question, What steps do i have do to allow remote r/w access to the database using python pyscopg2? ...

How to find the first and last occurrences of a specific character inside a string in PostgreSQL

I want to find the first and the last occurrences of a specific character inside a string. As an example, consider a string named "2010-####-3434", and suppose the character to be searched for is "#". The first occurrence of hash inside the string is at 6-th position, and the last occurrence is at 9-th position. ...

Calculating and saving space in Postgresql

I have a table in Pg like so CREATE TABLE t ( a BIGSERIAL NOT NULL, -- 8 b b SMALLINT, -- 2 b c SMALLINT, -- 2 b d REAL, -- 4 b e REAL, -- 4 b f REAL, -- 4 b g INTE...

foreign key constraints on primary key columns - issues ?

What are the pros/cons from a performance/indexing/data management perspective of creating a one-to-one relationship between tables using the primary key on the child as foreign key, versus a pure surrogate primary key on the child? The first approach seems to reduce redundancy and nicely constrains the one-to-one implicitly, while the...

Database query optimization

Ok my Giant friends once again I seek a little space in your shoulders :P Here is the issue, I have a python script that is fixing some database issues but it is taking way too long, the main update statement is this: cursor.execute("UPDATE jiveuser SET username = '%s' WHERE userid = %d" % (newName,userId)) That is getting called ab...

PostgreSQL: How to index all foreign keys?

I am working with a large PostgreSQL database, and I am trying to tune it to get more performance. Our queries and updates seem to be doing a lot of lookups using foreign keys. What I would like is a relatively simple way to add Indexes to all of our foreign keys without having to go through every table (~140) and doing it manually. ...

finding MAX(db_timestamp) query

I have BIG table with multiple indexes in postgres. It has indexes on db_timestamp, id, username. I want to find the MAX timestamp for particular username. The problem is the simple query like SELECT MAX(db_timestamp) FROM Foo WHERE username = 'foo' takes so much time because of the huge table size( we are talking 450GB table with o...

Getting Hibernate to generate indexes on foreign keys

I am using Hibernate 3.3.2 in a fairly large project with PostgreSQL 8.4 using the PostgreSQLDialect. The way we have our relationships set up, we end up doing a lot of searching on the Foreign Key attributes of our tables. For performance reasons, I would like to have Hibernate add Indexes to the all of the foreign key columns when ...