[Haskell-beginners] Ranges and List Comprehensions in SQL

Toby Thain toby at telegraphics.com.au
Fri Sep 3 12:09:01 EDT 2010


On 3-Sep-10, at 11:43 AM, Brent Yorgey wrote:

> On Fri, Sep 03, 2010 at 11:21:27AM -0400, Tom Murphy wrote:
> ...
>> The record would actually be coming from an SQL database.
>> I would like to be able to store a large list in SQL records,  
>> without having
>> to store every element.
>
> I see.  So the question seems more about database design than about
> Haskell.  Toby has suggested a more relational way to model the data,
> but his solution does end up storing every element.  But you could do
> something more like
>
>  CREATE TABLE tv_show (
>        id INTEGER NOT NULL, -- etc
>        title VARCHAR(80),
>        PRIMARY KEY (id)
>  );
>  CREATE TABLE episode_ranges (
>        tv_show_id INTEGER NOT NULL,
>        start_episode INTEGER,
> 	end_episode INTEGER,
>        PRIMARY KEY (tv_show_id, start_episode)
>  );

This is a possible alternative, but you would need something like a  
CHECK constraint as well, for overlapping ranges. The primary key  
definition above isn't doing much for integrity.

I see no downside whatsoever to "storing every element". It's what an  
RDBMS does: manage relations.

--Toby

>
> Or something like that (it's been a while since I've used SQL).  The
> data would then be more like
>
>  tv_show (30, "The Simpsons")
>  episode_ranges (30,1,4), (30,14,14), (30,18,21), (30,23,25)
>
> -Brent
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list