postgresql

Generate series of months for every row in Oracle

安稳与你 提交于 2021-02-10 23:47:10
问题 I am porting PostgreSQL select statement to Oracle. I cannot figure out how to re-write the following into Oracle syntax: select id, generate_series(date_trunc('month', st_date), en_date,'1 month')::date as dist_date from tst I have a basic idea how I can generate range of months in Oracle, but I think different approach is neeeded as I don't see a way how to plug the following into my sql: select add_months(trunc(sysdate, 'month'), level) from dual connect by level <= months_between(sysdate,

Locking and concurrent executions of a stored procedure

那年仲夏 提交于 2021-02-10 22:40:54
问题 I have a stored procedure that is executed by remote clients on an ongoing basis. From reading the docs I am under the impression that with the proper locking techniques I shouldn't need to externally manage these clients and I would be free to have them run as often and as concurrently as they like. This procedure updates and inserts to multiple tables. A skeleton outline of the procedure is below: LOCK TABLE table1 IN EXCLUSIVE MODE; LOOP UPDATE table1 SET "var1"="var1"+1, WHERE "var2"=var2

Locking and concurrent executions of a stored procedure

半腔热情 提交于 2021-02-10 22:40:30
问题 I have a stored procedure that is executed by remote clients on an ongoing basis. From reading the docs I am under the impression that with the proper locking techniques I shouldn't need to externally manage these clients and I would be free to have them run as often and as concurrently as they like. This procedure updates and inserts to multiple tables. A skeleton outline of the procedure is below: LOCK TABLE table1 IN EXCLUSIVE MODE; LOOP UPDATE table1 SET "var1"="var1"+1, WHERE "var2"=var2

How to search an enum in list of strings by postgresql query?

末鹿安然 提交于 2021-02-10 22:31:53
问题 Consider a SQL Statement: select * from table where status in <statuses> Where status is an enum: CREATE TYPE statusType AS ENUM ( 'enum1', 'enum2'; In Java I have a list of the enums in string representation: List<String> list = new ArrayList<>(); list.add("enum1"); list.add("enum2"); I then try to build and execute the query using SqlStatement: handle.createQuery("select * from table where status in <statuses>") .bindList("statuses", statuses) .map(Mapper.instance) .list()); I keep getting

How to search an enum in list of strings by postgresql query?

笑着哭i 提交于 2021-02-10 22:28:47
问题 Consider a SQL Statement: select * from table where status in <statuses> Where status is an enum: CREATE TYPE statusType AS ENUM ( 'enum1', 'enum2'; In Java I have a list of the enums in string representation: List<String> list = new ArrayList<>(); list.add("enum1"); list.add("enum2"); I then try to build and execute the query using SqlStatement: handle.createQuery("select * from table where status in <statuses>") .bindList("statuses", statuses) .map(Mapper.instance) .list()); I keep getting

Node.js - PostgreSQL (pg) : Client has already been connected. You cannot reuse a client

左心房为你撑大大i 提交于 2021-02-10 22:17:38
问题 I am just trying to write simple register/login system. I am trying to find if username exists. Here is the steps : Go localhost:3000/users/register page Fill in all fields and click register button Checking my command line if username exists it should print it with console.log Everything works fine until now. When I go back to the register page, I fill in all fields again and click register button. Then it throws it in command line : Error: Client has already been connected. You cannot reuse

search for cross-field duplicates in postgresql

混江龙づ霸主 提交于 2021-02-10 21:34:11
问题 I have a table of contacts. The table contains a mobile_phone column as well as a home_phone column. I'd like to fetch all duplicate contacts where a duplicate is two contacts sharing a phone number. If contact A's mobile_phone matches contact B's home_phone, this is also a duplicate. Here is an example of three contacts that should match. contact_id|mobile_phone|home_phone|other columns such as email.......|... ------------------------------------------------------------------------- 111

search for cross-field duplicates in postgresql

梦想与她 提交于 2021-02-10 21:21:53
问题 I have a table of contacts. The table contains a mobile_phone column as well as a home_phone column. I'd like to fetch all duplicate contacts where a duplicate is two contacts sharing a phone number. If contact A's mobile_phone matches contact B's home_phone, this is also a duplicate. Here is an example of three contacts that should match. contact_id|mobile_phone|home_phone|other columns such as email.......|... ------------------------------------------------------------------------- 111

search for cross-field duplicates in postgresql

泪湿孤枕 提交于 2021-02-10 21:21:13
问题 I have a table of contacts. The table contains a mobile_phone column as well as a home_phone column. I'd like to fetch all duplicate contacts where a duplicate is two contacts sharing a phone number. If contact A's mobile_phone matches contact B's home_phone, this is also a duplicate. Here is an example of three contacts that should match. contact_id|mobile_phone|home_phone|other columns such as email.......|... ------------------------------------------------------------------------- 111

postgres crosstab, ERROR: The provided SQL must return 3 columns

时间秒杀一切 提交于 2021-02-10 20:52:43
问题 Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | 18-05 | MAY | 35 name1 | 18-06 | JUN | -102 name2 | 18-06 | JUN | -32 name3 | 18-06 | JUN | -75 name1 | 18-09 | AVG | -135 name2 | 18-09 | AVG | -52 name3 | 18-09 | AVG | -17 expected output: qmonth2 | name1 | name2 | name3 --------+-------+-------+------- MAY | -166 | -86 | 35 JUN |