postgresql-9.2

PostgreSQL - show data of previous year + current year's week

白昼怎懂夜的黑 提交于 2020-01-24 20:13:31
问题 I need to make a column that would show previous year's profit till given year's week. So it would split current year in weeks and it would show what is the profit for given week. To make it more clear let say previous year profit was 1000. This year's first week profit is 100, second week's 200, thirds, week -100 (was loss) and so on. So it should look like this: week1|week2|week3| 1100 |1300 |1200 | What I tried was: SELECT CASE when f1.year = DATE_PART('year', now()) THEN f1.week END as

Months between two dates function

孤者浪人 提交于 2020-01-21 06:32:06
问题 In oracle i can find out no:of months between using MONTHS_BETWEEN function. In postgres i am using extract function for this. eg.like select extract(year from age(current_date, '2012-12-09')) * 12 + extract(month from age(current_date, '2012-12-09')) Is there any other ways(built in functions) in postgres?? 回答1: This is easy to re-implement in PostgreSQL just using SQL functions to tidy up what you've already got: create function months_of(interval) returns int strict immutable language sql

How to insert data into table using stored procedures in postgresql

允我心安 提交于 2020-01-20 20:28:53
问题 CREATE TABLE app_for_leave ( sno integer NOT NULL, eid integer, ename varchar(20), sd date, ed date, sid integer, status boolean DEFAULT false, CONSTRAINT pk_snoa PRIMARY KEY (sno) ); Basic Insertion is :: INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status) VALUES(1,101,'2013-04-04','2013-04-04',2,'f' ); ... INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status) VALUES (?, ?, ?, ?, ?, ?); My Requirement:: How to insert data into a table using stored procedures ? 回答1: PostgreSQL didn't

How to parameterize an ALTER ROLE statement in Postgresql?

梦想的初衷 提交于 2020-01-14 22:40:47
问题 I'm trying to make a PHP interface to my PSQL database, and I would like a few local users registered on PSQL to log into my DB. I would first create each username for each user, with a generic password like 'Password123', and then the user could latter change his/her password. To do that, I thought of using a simple PHP form: <form action="" method="post"> <table> <tr> <td> User: </td> <td> <input type="text" name="user" /> </td> </tr> <tr> <td> Old password: </td> <td> <input type="password

Getting Postgresql Running In Mac: Database “postgres” does not exist [closed]

时光毁灭记忆、已成空白 提交于 2020-01-14 07:55:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . I followed these instructions to get postgresql running on mac. Note that I am using Homebrew to install, and the current version installable through brew is 9.2.1, so I changed the version numbers in the instructions here: http://rails3hub.blogspot.com/2012/02/install-postgresql-9-on-os-x.html Everything went

unresolved dependency for postgresql 9.2 jar in play framework

爱⌒轻易说出口 提交于 2020-01-13 08:19:31
问题 I am using postgresql 9.2 with play framework 2.1 I downloaded the driver here: http://jdbc.postgresql.org/download.html (JDBC4 Postgresql Driver, Version 9.2-1002) My project/Build.scala file is as follows: import sbt._ import Keys._ import play.Project._ object ApplicationBuild extends Build { val appName = "myApp" val appVersion = "0.1" val appDependencies = Seq( "postgresql" % "postgresql" % "9.2-1002.jdbc4") val main = play.Project(appName, appVersion, appDependencies) } I have placed

Airflow psycopg2.OperationalError: FATAL: sorry, too many clients already

无人久伴 提交于 2020-01-13 02:54:41
问题 I have a four node clustered Airflow environment that's been working fine for me for a few months now. ec2-instances Server 1: Webserver, Scheduler, Redis Queue, PostgreSQL Database Server 2: Webserver Server 3: Worker Server 4: Worker Recently I've been working on a more complex DAG that has a few dozen tasks in it compared to my relatively small ones I was working on beforehand. I'm not sure if that's why I'm just now seeing this error pop up or what but I'll sporadically get this error: On

Airflow psycopg2.OperationalError: FATAL: sorry, too many clients already

你离开我真会死。 提交于 2020-01-13 02:54:08
问题 I have a four node clustered Airflow environment that's been working fine for me for a few months now. ec2-instances Server 1: Webserver, Scheduler, Redis Queue, PostgreSQL Database Server 2: Webserver Server 3: Worker Server 4: Worker Recently I've been working on a more complex DAG that has a few dozen tasks in it compared to my relatively small ones I was working on beforehand. I'm not sure if that's why I'm just now seeing this error pop up or what but I'll sporadically get this error: On

Unicorn do not close DB connections

人走茶凉 提交于 2020-01-13 00:52:08
问题 I am using rails 3.2 + unicorn + postgres DB and i have a question - how does unicorn handle DB connections ? How I understand: unicorn master process forks X child process. each child process setup DB connection– close in before_fork, establish connection in after_fork. we use connection per process(if we use rails DB connection pooling, we create Y(from database.yml) DB connections per process) - i.e. If process is working(It always works until we not kill it) we keep connection opened and

What is the good approach to check an existance of unique values in database table by SqlAlchemy in python2.7

試著忘記壹切 提交于 2020-01-07 03:07:29
问题 I use session.merge in SqlAlchemy to insert data to the table with UniqueConstraint , which is common for several columns, for example, my ORM class has the following: UniqueConstraint("attr_1", "attr_2", "attr_3", name="attributes_uix") Should I use filter or filter_by with _and to check, if data, which I'm going to insert will violate this unique constraint, or is it the proper way to catch IntegrityError by try - except construction? 回答1: No an sql-alchemy expert but have struggled with