postgresql-9.1

if a non-correlated subquery is repeated at several places in the query, can it be cached and the result reused?

守給你的承諾、 提交于 2019-12-05 08:29:08
If I have a query like SELECT date_trunc('day', assigndate)e, count(CASE WHEN a.assigneeid = 65548 AND a.assigneeid IN (SELECT userid FROM groupmembers WHERE groupid = 65553) THEN 1 ELSE NULL END) assigned, count(CASE WHEN a.assigneeid = 65548 AND a.completedtime IS NOT NULL AND a.assigneeid IN (SELECT userid FROM groupmembers WHERE groupid = 65553) THEN 1 ELSE NULL END) completed FROM ASSIGNMENT a WHERE assigndate > CURRENT_TIMESTAMP - interval '20 days' GROUP BY date_trunc('day',assigndate); The subquery in question is SELECT userid FROM groupmembers WHERE groupid = 65553 then since the

WHERE NOT EXISTS in PostgreSQL gives syntax error

a 夏天 提交于 2019-12-05 07:23:51
When trying to use the WHERE NOT EXISTS clause to prevent adding a row with a duplicate value in the column age , I get the error syntax error at or near "WHERE" . Why did it throw a syntax error? I'm using Postgresql 9.1. SQL INSERT INTO live.users ("website", "age") values ('abc', '123') WHERE NOT EXISTS (SELECT age FROM live.users WHERE age = 123); Error ERROR: syntax error at or near "WHERE" LINE 6: WHERE NOT EXISTS (SELECT age FROM live.users W... Do instead: INSERT INTO live.users ("website", "age") SELECT 'abc', 123 WHERE NOT EXISTS (SELECT age FROM live.users WHERE age = 123); INSERT

Postgresql k-nearest neighbor (KNN) on multidimensional cube

谁说胖子不能爱 提交于 2019-12-05 07:11:26
I have a cube that has 8 dimensions. I want to do nearest neighbor matching. I'm totally new to postgresql. I read that 9.1 supports nearest neighbor matching on multidimensions. I'd really appreciate if someone could give a complete example: How to create a table with the 8D cube ? Sample Insert Lookup - exact matching Lookup - nearest neighbor matching Sample Data: For simplicity sake, we can assume that all the values range from 0-100. Point1: (1,1,1,1, 1,1,1,1) Point2: (2,2,2,2, 2,2,2,2) Look up value: (1,1,1,1, 1,1,1,2) This should match against Point1 and not Point2. Refs: What's_new_in

pg_dump on Database throwing error 'out of shared memory'

会有一股神秘感。 提交于 2019-12-05 06:09:16
Getting problem when taking backup on database contains around 50 schema with each schema having around 100 tables. pg_dump throwing below error suggesting that to increase max_locks_per_transaction . pg_dump: WARNING: out of shared memory pg_dump: SQL command failed pg_dump: Error message from server: ERROR: out of shared memory HINT: You might need to increase max_locks_per_transaction. pg_dump: The command was: SELECT tableoid, oid, prsname, prsnamespace, prsstart::oid, prstoken::oid, prsend::oid, prsheadline::oid, prslextype::oid FROM pg_ts_parser An updated of max_locks_per_transaction to

Moving postgresql data cluster

我的梦境 提交于 2019-12-05 05:39:53
Our postgres data folder was installed on a drive with very limited space. I'm now trying to move it over to a newly mounted drive (more space). I've followed several blog posts and they all say... stop service copy data cluster update postgresql-9.1 file (PGDATA=) restart service The service starts but when I go to connect, it gives me "could not connect to server: Connection refused" I tried telnet-ing to port 5432 and nothing. Here is the link to what I've been trying: http://www-01.ibm.com/support/docview.wss?uid=swg21324272 Thanks everyone for your help. Looks like the problem was with

Error “invalid byte sequence” while restoring PostgreSQL database

孤街醉人 提交于 2019-12-05 03:44:23
问题 Earlier today, I was trying to restore my PostgreSQL (8.1.22) database from production using pgAdmin III. However, after the restoration procedure finished, it started throwing errors like: WARNING: errors ignored on restore: 4 Also, upon investigation I found that out of all the tables 3 tables hadn't been restored (contained 0 rows). When I checked the log, I found the follwoing error near the 3 tables: pg_restore: [archiver (db)] Error from TOC entry 5390; 0 442375 TABLE DATA tablename

Java queries against PGPool II cause “unnamed prepared statement does not exist” errors

不打扰是莪最后的温柔 提交于 2019-12-05 00:15:24
I have a Java app that uses a Postgres database and I'm trying to introduce PGPool in order to scale up my database. I'm running into a problem where Postgres throws the following error: unnamed prepared statement does not exist . After cranking up the logging on Postgres I see the following stuff happening for every select statement my app executes: EDTLOG: 00000: duration: 7.585 ms parse <unnamed>: "my select statement here" EDTLOG: 00000: duration: 0.088 ms bind <unnamed>: "my select statement here" EDTLOG: 00000: duration: 79.014 ms execute <unnamed>: "my select statement here" But

How to allow only one row for a table?

£可爱£侵袭症+ 提交于 2019-12-05 00:09:37
I have one table in which I would like only one entry . So if someone is trying to insert another row it shouldn't be allowed, only after someone deleted the previously existing row. How do I set a rule for a table like this? Erwin Brandstetter A UNIQUE constraint allows multiple rows with NULL values, because two NULL values are never considered to be the same. Similar considerations apply to CHECK constraints. They allow the expression to be TRUE or NULL (just not FALSE ). Again, NULL values get past the check. To rule that out, the column must be defined NOT NULL . Or make it the PRIMARY

How much cost check constraints in Postgres 9.x?

最后都变了- 提交于 2019-12-04 19:45:54
I'd like to know if there are some benchmark to compare how much cost insert some check constraints on a table of 60 columns where on 20 i'd like to insert a constraints of NotEmpty and on 6 rows NotNull. My case is that i have on my table Empty values and Null values (that in my case means always "no data"). I'd like to unify that data values with just one. That's why I'm thinking to insert NotEmpty constraints on columns, because as i have read null value are not heavy (in byte size) as like empty values (and respect his real meaning). But from other side NotNull Constraint are more deep

Set Order By to ignore punctuation on a per-column basis

丶灬走出姿态 提交于 2019-12-04 19:22:56
Is it possible to order the results of a PostgreSQL query by a title field that contains characters like [](),; etc but do so ignoring these punctuation characters and sorting only by the text characters? I've read articles on changing the database collation or locale but have not found any clear instructions on how to do this on an existing database an on a per-column basis. Is this even possible? If you want to have this ordering in one particular query you can ORDER BY regexp_replace(title, '[^a-zA-Z]', '', 'g') It will delete all non A-Z from sting and order by resulting field. Erwin