Re: formal SQL typing rules

From: Brian Inglis <Brian.Inglis_at_SystematicSW.Invalid>
Date: Mon, 28 Mar 2005 21:02:09 GMT
Message-ID: <>

On Sat, 26 Mar 2005 17:22:50 -0500 in alt.comp.databases, Jean Morissette <> wrote:

>I want to build a simple SQL compiler and I would like to know if a
>formal specification of the type system used in SQL has been written
>somewhere? I have read the SQL99 ISO spec, but they don't talk about typing
>Currently, I'm trying to figure myself these typing rules and I would like
>to have your comments...
>First, I have defined some types of SQL by the following grammar:
> t ::= int | float | bool | char | string
> | t x ... x t -> t
> | bag(t) | set(t) | list(t)
>Next, I have defined some rules for deriving the type of a query:
>Informally, the type of the result of
> SELECT column_1,...,column_n FROM table_list WHERE predicate
>must be
> bag(tuple(t1,...,tn))
>where 't1' is the type of 'column_1' and 'tn' is the 'type of column_n'.
>Also, informally, the type of column_1
> ... WHERE column_1 IN subquery
>must be
> tuple(t1)
>if the type of subquery is
> bag(tuple(t1)).
>If these two rules are exacts, what should be the type of 'column1' in this
> ... WHERE column_1 > 666
>Here, the type of 'column_1' is 'int' or 'float'. Note that 'column_1' type
>cannot be equal to 'tuple(int)' or 'tuple(float)' like it was in the
>previous rule. So, it seems to me that the type of an expression is
>context dependant. Am I right?
>Thank for your comment

[sorry, gave you a bum steer to a.c.d, meant c.d.t, f-ups set]

Thanks. Take care, Brian Inglis 	Calgary, Alberta, Canada 	(Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
    fake address		use address above to reply
Received on Mon Mar 28 2005 - 23:02:09 CEST

Original text of this message