postgresql-8.1

sql sliding window - finding max value over interval

空扰寡人 提交于 2019-12-19 03:56:50
问题 i have a sliding window problem. specifically, i do not know where my window should start and where it should end. i do know the size of my interval/window. i need to find the start/end of the window that delivers the best (or worst, depending on how you look at it) case scenario. here is an example dataset: value | tstamp 100 | 2013-02-20 00:01:00 200 | 2013-02-20 00:02:00 300 | 2013-02-20 00:03:00 400 | 2013-02-20 00:04:00 500 | 2013-02-20 00:05:00 600 | 2013-02-20 00:06:00 500 | 2013-02-20

Check for complete duplicate rows in a large table

这一生的挚爱 提交于 2019-12-12 09:56:45
问题 My original question with all the relevant context can be found here: Adding a multi-column primary key to a table with 40 million records I have a table with 40 million rows and no primary key. Before I add the primary key, I would like to check if the table has any duplicate entries. When I say duplicate entries, I don't just mean duplicate on particular columns. I mean duplicates on entire rows. I was told in my last question that I can do an EXISTS query to determine duplicates. How would

Sanitize input to a column in postgres

≯℡__Kan透↙ 提交于 2019-12-12 00:46:49
问题 So, I think this should be fairly simple, but the documentation makes it seem somewhat more complicated. I've written an SQL function in PostgreSQL (8.1, for now) which does some cleanup on some string input. For what it's worth, the string is an LDAP distinguished name, and I want there to consistently be no spaces after the commas - and the function is clean_dn(), which returns the cleaned DN. I want to do the same thing to force all input to another couple of columns to lower case, etc -

Give all the permissions to a user on a DB

假装没事ソ 提交于 2019-11-28 15:07:16
I would like to give an user all the permissions on a database without making it an admin. The reason why I want to do that is that at the moment DEV and PROD are different DBs on the same cluster so I don't want a user to be able to change production objects but it must be able to change objects on DEV. I tried: grant ALL on database MY_DB to group MY_GROUP; but it doesn't seem to give any permission. Then I tried: grant all privileges on schema MY_SCHEMA to group MY_GROUP; and it seems to give me permission to create objects but not to query\delete objects on that schema that belong to other

How to use an ALIAS in a PostgreSQL ORDER BY clause?

独自空忆成欢 提交于 2019-11-26 21:39:10
问题 I have the following query: select title, ( stock_one + stock_two ) as global_stock from product order by global_stock = 0, title; Running it in PostgreSQL 8.1.23 i get this error: Query failed: ERROR: column "global_stock" does not exist Anybody can help me to put it to work? I need the availale items first, after them the unnavailable items. Many thanks! 回答1: You can always ORDER BY this way: select title, ( stock_one + stock_two ) as global_stock from product order by 2, 1 or wrap it in