12
votes
4answers
389 views

Finding person with most medals in Olympics database

I have an Olympics database from each Olympic year and I want to find the person that has won the most medals. The main problem is that I'm basically querying the same sub-query twice in ...
7
votes
2answers
40 views

Revision 2 - Step 1: PsychoProductions management tool project

I have been told by DBA.SE people that this was off-topic for DBA.SE and should be on CR.SE instead. So... here I submit this database schema design for my trusted fellow CRitters to review! This is ...
21
votes
2answers
2k views

Tired of FizzBuzz yet?

There have been many FizzBuzz questions lately, and here is one more! Granted, it is pretty straightforward to do FizzBuzz with SQL using calculations. So instead, I'm going to do a FizzBuzz which ...
6
votes
1answer
63 views

Is there a way to optimize this aggregate postgreSQL statement by using CASE?

I have a working SQL statement which shows the following: Player Champion Role Total Kill/Death Ratio Total Kill+Assist/Death Ratio Total Win % Difference between Ratio from one month ago Difference ...
9
votes
1answer
74 views

Tic-tac-toe in SQL with optimal AI

The simplest introduction to this code is to play it! Here's an SQL Fiddle. However, to enjoy it fully, you'll need a more interactive environment, like the psql ...
5
votes
1answer
87 views

Optimize postgres function

This function code works very slowly. How can I speed it up? ...
5
votes
1answer
73 views

Low performance of PL/pgSQL function

I have an unstable PL/pgSQL function: ...
5
votes
2answers
158 views

How to properly call an “upsert” using parameterized raw SQL to Postgresql in ActiveRecord?

I need to call an upsert to my Category table in PostgreSQL. My current solution uses the exec_query API in ActiveRecord, using ...
4
votes
2answers
374 views

SQL query where id=… or id=… or id=… etc

I haven't had much experience with postgresql (none) and I am wondering/hoping that there is a better way for me to do this query. ...
2
votes
2answers
67 views
6
votes
1answer
176 views

Help optimizing this query with multiple where exists

In the application I'm building, the user is able to define 'types' where each 'type' has a set of 'attributes'. The user is able to create instances of products by defining a value for each ...
3
votes
1answer
1k views

Get all recursive dependencies of a single database object

I've written a SELECT statement that creates a List of all objects that depend on a single object, so that if I wanted to DROP that object I could DROP all referenced objects first without using ...
6
votes
3answers
1k views

SQL: Search for a keyword in several columns of a table

I want to perform a search in several columns of a table. I use the following query: ...
1
vote
1answer
79 views

Automating the install of postgresql from Shell

When my debian server deploys it can run a shell script so I wanted to make one to install postgreSQL, create a role, create two databases and then import a schema into one. Can anyone please look ...
2
votes
1answer
91 views

Postgres 9.x Joining on Overlaping Date & Time Range

I have several tables that have a TIMESTAMP WITH TIME ZONE column along with some additional information. I need to be able to join these tables such that all of ...
2
votes
1answer
112 views

Summing different tables values limiting the results

I have two tables (a and b) which have both one date field of type ...
3
votes
2answers
737 views

PostgreSQL simple query with repeated function calls

I have PostgreSQL 9.1.1 running in a shared hosting environment and I'm running this query: ...
1
vote
2answers
175 views

First Database Schema - How did I do?

I would really like some advice from any DB gurus who have a few minutes free. After doing some reading and playing with sqlfiddle over the weekend I have constructed this postgresql schema and it is ...
6
votes
2answers
771 views

SQL: Extracting nodes from a graph database

I guess I'm one of these people who are more at home in C#,C++, Python, etc; and only use SQL to do simple INSERTs and SELECTs, so apologies if this is too simple. I'm also new to Postgres and ...