postgresql

Can't connect to my AWS Database Instance | psql: could not connect to server: Operation timed out

泄露秘密 提交于 2021-02-18 17:08:17
问题 I created a postgres DB instance on AWS RDS. I am trying to connect this DB instance to my django zappa app so I can perform AWS Lambda functions. I've added a new security group to my DB instance so I can allow my django app to connect to it: My DB details show that the new security group is active: However when I try to connect to it, either by running psql --host="*************.us-east-2.rds.amazonaws.com" --port="5432" --username="*********" --password --dbname="*****" via my terminal, or

What is the correct way to use distinct on (Postgres) with SqlAlchemy?

点点圈 提交于 2021-02-18 16:56:03
问题 I want to get all the columns of a table with max(timestamp) and group by name. What i have tried so far is: normal_query ="Select max(timestamp) as time from table" event_list = normal_query \ .distinct(Table.name)\ .filter_by(**filter_by_query) \ .filter(*queries) \ .group_by(*group_by_fields) \ .order_by('').all() the query i get : SELECT DISTINCT ON (schema.table.name) , max(timestamp).... this query basically returns two columns with name and timestamp. whereas, the query i want : SELECT

What is the correct way to use distinct on (Postgres) with SqlAlchemy?

↘锁芯ラ 提交于 2021-02-18 16:55:28
问题 I want to get all the columns of a table with max(timestamp) and group by name. What i have tried so far is: normal_query ="Select max(timestamp) as time from table" event_list = normal_query \ .distinct(Table.name)\ .filter_by(**filter_by_query) \ .filter(*queries) \ .group_by(*group_by_fields) \ .order_by('').all() the query i get : SELECT DISTINCT ON (schema.table.name) , max(timestamp).... this query basically returns two columns with name and timestamp. whereas, the query i want : SELECT

【笔记】.NET开发环境下使用PostgreSQL+Oracle_fdw 实现两个数据库之间数据交互操作(一)

会有一股神秘感。 提交于 2021-02-18 15:26:55
一 前言 以往公司开发的地理信息系统数据都是存储在oracle中,然而在地图数据的分析和计算中一直存在不小的问题,所以今次我们尝试使用PostgreSQL+PostGIS来解决这一问题。 本篇笔记的目的就是记录在研究这一开发路径期间的“学习的内容”、“遇到的问题和解决过程”以及“简单的实践内容”以备忘。 笔记中可能会出现部分术语概念不准确,还请您能耐心指正或者忽略,反正这是为了我自己能看懂的笔记,你爱看不看。 二 安装 1.环境 Windows7 64位操作系统(公司工作的台式机,探索阶段暂时使用,以后可能会转到Windows系统的服务器上去)。 已安装了Oracle 11g客户端,这里将不在介绍oracle的安装。 2.步骤 基本还是准寻下一步原则,第二步注意一下语言的选择。 SQL安装完毕后自动弹出Stack Builder引导安装PostGIS等其他扩展。 我这里只选择了自己需要的 PostGIS 版本进行了安装。 详细可以参考同事整理的安装文档: https://www.jianshu.com/p/3b1a4cd8e72e 三 遇到的第一个问题 前一天用着好好的数据库,第二天服务就死活链接不上了,而且在pgAdime里没有报任何错误,就很奇怪。 在尝试了修改配置文件、分析服务管理器启动产生的日志等最终还是没有奏效,索性 卸载干净重新安装 ,居然就好了。。。

Migrating an Oracle MERGE statement to a PostgreSQL UPSERT statement

社会主义新天地 提交于 2021-02-18 15:22:42
问题 Can you please help me converting the following Oracle MERGE statement into a valid UPSERT statement for use in a PostgreSQL 9.3 database? MERGE INTO my_table a USING (SELECT v_c1 key, v_c2 AS pkey, v_c3 AS wcount, v_c4 AS dcount FROM DUAL) b ON ( a.key = b.key AND a.pkey = b.pkey WHEN MATCHED THEN UPDATE SET wcount = b.wcount, dcount = b.dcount WHEN NOT MATCHED THEN INSERT (key, pkey, wcount, dcount) VALUES(b.key,b.pkey,b.wcount,b.dcount); 回答1: I don't think there's UPSERT statement in

Add auto increment column to existing table ordered by date

狂风中的少年 提交于 2021-02-18 11:57:08
问题 I have an existing table named "tickets" in database with columns: id (string, Primary Key, contains UUID like e6c49164-545a-43a1-845f-73c5163962f2) date (biginteger, stores epoch) status (string) I need to add new auto increment column ticket_id but the values to be generated should be according to "date" column value. I tried this: ALTER TABLE "tickets" ADD COLUMN "ticket_id" SERIAL; The problem is, it is generating "ticket_id" values in some weird order, looks like it is based on "id"

Add auto increment column to existing table ordered by date

给你一囗甜甜゛ 提交于 2021-02-18 11:57:07
问题 I have an existing table named "tickets" in database with columns: id (string, Primary Key, contains UUID like e6c49164-545a-43a1-845f-73c5163962f2) date (biginteger, stores epoch) status (string) I need to add new auto increment column ticket_id but the values to be generated should be according to "date" column value. I tried this: ALTER TABLE "tickets" ADD COLUMN "ticket_id" SERIAL; The problem is, it is generating "ticket_id" values in some weird order, looks like it is based on "id"

create column for auto-date in postgresql

回眸只為那壹抹淺笑 提交于 2021-02-18 11:56:10
问题 I know that to create a column in mysql is like this 'date' timestamp not null default CURRENT_TIMESTAMP, how to postgresql? 回答1: It's the same, you just have to fix the identifier quoting to use SQL standard "identifer quoting" : "date" timestamp not null default CURRENT_TIMESTAMP, but really, you should not use "date" as an identifier. 来源: https://stackoverflow.com/questions/23518399/create-column-for-auto-date-in-postgresql

Find gaps of a sequence in SQL without creating additional tables

老子叫甜甜 提交于 2021-02-18 11:29:14
问题 I have a table invoices with a field invoice_number . This is what happens when i execute select invoice_number from invoice : invoice_number -------------- 1 2 3 5 6 10 11 I want a SQL that gives me the following result: gap_start | gap_end 4 | 4 7 | 9 How can i write a SQL to perform such query? I am using PostgreSQL. 回答1: With modern SQL, this can easily be done using window functions: select invoice_number + 1 as gap_start, next_nr - 1 as gap_end from ( select invoice_number, lead(invoice

How to set some context variable for a user/connection

僤鯓⒐⒋嵵緔 提交于 2021-02-18 11:24:27
问题 I currently use Firebird SQL as the db backend of my shareware, would like to support also PG 9.3+. In FB I use set/get_context to do this: set-context get-context e.g. I would do this after a user logs in: select rdb$set_context('USER_SESSION', 'LANGUAGE_ID', %s) \ from rdb$database" % appobj.loggedInUser.language.id In some of my views I would then use: ... AND t.fk_language_id=rdb$get_context('USER_SESSION', 'LANGUAGE_ID') I searched through PG doc and did some googling but didn't find a