postgresql

How to connect to my Heroku PostgreSQL database from Java

♀尐吖头ヾ 提交于 2021-02-08 09:07:15
问题 I have a Heroku PostgreSQL database to which I can't connect from Java. I have tried different methods but without success. Below is my Java code: import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class MainConfig { public static void main(String[] args) { try{ dataSource(); System.out.println("conected"); } catch(Exception ex){ ex.printStackTrace(); } } public static Connection dataSource() throws URISyntaxException, SQLException { String

django how to define models for existing many to many tables in postgresql database

江枫思渺然 提交于 2021-02-08 08:51:51
问题 I have an existing PostgreSQL database with a many to many relationship, it is handled through a join table as below. I'm looking to apply the ManyToMany Field type, does this bypass this join/intermediate table? How do I correctly configure it in my models.py? I'd rather keep the intermediate table. # models.py class Sample(models.Model): sample_id = models.AutoField(primary_key=True) ... class JoinSampleContainer(models.Model): id = models.AutoField(primary_key=True) container_id = models

Total Number of Records per Week

萝らか妹 提交于 2021-02-08 08:16:01
问题 I have a Postgres 9.1 database. I am trying to generate the number of records per week (for a given date range) and compare it to the previous year. I have the following code used to generate the series: select generate_series('2013-01-01', '2013-01-31', '7 day'::interval) as series However, I am not sure how to join the counted records to the dates generated. So, using the following records as an example: Pt_ID exam_date ====== ========= 1 2012-01-02 2 2012-01-02 3 2012-01-08 4 2012-01-08 1

Making `group by` result in multiple columns

ぃ、小莉子 提交于 2021-02-08 08:00:32
问题 I have a ( Postgres ) query with a usual group by clause: select extract(year from a.created) as Year,a.testscoreid, b.irt_tlevel, count(a.*) as Questions from asmt.testscores a join asmt.questions b on a.questionid = b.questionid where a.answered = True group by Year,a.testscoreid, b.irt_tlevel order by Year desc, a.testscoreid The column b.irt_tlevel has values low , medium and high , all these results are in a row-format, for example: Year TestScoreId Irt_tlevel Questions 2015 1 Low 2 2015

getIndexInfo returning wrong unique columns for composite primary keys

為{幸葍}努か 提交于 2021-02-08 08:00:14
问题 I am working with JDBC and I have created a simple table using postgresql: create table bank ( bank_id int, bank_name varchar(40), bank_address varchar(80), user_id int, user_first_name varchar(40), user_surname varchar(40), user_phone varchar(12), primary key(bank_id, user_id) ); The problem is that when I check whether bank_id is unique, I get true (when I was expecting false, ofc). Here is the code for my function that checks whether a column in a table is unique: private static boolean

Making `group by` result in multiple columns

亡梦爱人 提交于 2021-02-08 07:59:30
问题 I have a ( Postgres ) query with a usual group by clause: select extract(year from a.created) as Year,a.testscoreid, b.irt_tlevel, count(a.*) as Questions from asmt.testscores a join asmt.questions b on a.questionid = b.questionid where a.answered = True group by Year,a.testscoreid, b.irt_tlevel order by Year desc, a.testscoreid The column b.irt_tlevel has values low , medium and high , all these results are in a row-format, for example: Year TestScoreId Irt_tlevel Questions 2015 1 Low 2 2015

Python form drop down options populated by sql

走远了吗. 提交于 2021-02-08 07:56:37
问题 This is my first post. I am fairly new to programming. I am attempting to build a html form in Python which contains a drop down. The drop down options, I currently have hard coded, but want to populate the options from sql, so that it will be dynamically changing if the database is updated for the options. I also must mention that this drop down is being used as a search/filter for a data table which is also populated from the database. Please help with any suggestions. Hard Coded dropdown:

How to extract median value?

梦想与她 提交于 2021-02-08 07:40:22
问题 I need to get median value in column "median". Any ideas, please? SELECT MIN(score) min, CAST(AVG(score) AS float) median, MAX(score) max FROM result JOIN student ON student.id = result.student_id 回答1: I think the simplest method is PERCENTILE_CONT() or PERCENTILE_DISC() : SELECT MIN(score) as min_score, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY score) as median_score, MAX(score) max_score FROM result r JOIN student s ON s.id = r.student_id; This assumes (reasonably) that score is numeric.

When connecting to multiple databases, do I need multiple SQLAlchemy Metadata, Base, or Session objects?

青春壹個敷衍的年華 提交于 2021-02-08 07:33:30
问题 I'm writing a SQLAlchemy app that needs to connect to a PostgreSQL database and a MySQL database. Basically I'm loading the data from an existing MySQL database, doing some transforms on it, and then saving it in PostgreSQL. I am managing the PostgreSQL schema using SQLAlchemy's declarative base . The MySQL database already exists, and I am accessing the schema via SQLAlchemy's reflection. Both have very different schemas. I know I need dedicated engines for each database, but I'm unclear on

How I search datasets by multiple tags using CKAN API?

末鹿安然 提交于 2021-02-08 07:25:41
问题 I'm using CKAN portal with API version "ckan_version": "2.5.x" I have few tags and I need to send using API these tags and I need to return a list of matching entries of packages or resources. Is possible to use do use package_search endpoint to search for packages with all given tags, but it works as "AND" operator, and that I need is a "OR" operator. e.g.: http://demo.ckan.org/api/3/action/package_search?fq=tags:contabilidade-social <-- return 11 packages that contains 'contabilidade-social